{"raw_statement":[{"iden":"statement","content":"De Prezer loves movies and series. He has watched the Troy for like 100 times and also he is a big fan of Supernatural series.So, he did some researches and found a cursed object which had n lights on it and initially all of them were turned off.Because of his love to the Troy, he called that object Troy.\n\nHe looked and saw a note on it in Khikulish (language of people of Khikuland): \"Ma in hame rah umadim, hala migi ... ? ... Mage man De Prezer am k mikhay mano ... ? .... Man se sale ... To boro .... beshur manam miram ... o mishuram\". \n\nHe doesn't know Khikulish, so just ignored the note and tested the Troy.\n\nHe realized that the light number i stays turned on for exactly ai seconds, and then it turns itself off (if it is turned on, in time t, in time t + ai - 1 it will be turned on, but on time t + ai it won't be) and the next light will be turned on (if i < n, next light is the light number i + 1, otherwise it is light with number 1).\n\nFor example if n = 2 and we turn on the first light in time 0, it will be turned on in hole interval [0, a1) and in hole interval [a1, a1 + a2) the second light will be turned on and so on. \n\nIn time 0 he turns on the light number 1.\n\nDe Prezer also loves query.So he gives you q queries.In each query he will give you integer t (the time a revengeful ghost attacked him) and you should print the number of the light that is turned on, in time t.\n\nThe first line of input contains two integers n and q.\n\nThe second line contains n space separated integers, a1, a2, ..., an .\n\nThe next q lines, each line contains a single integer t .\n\n1 ≤ n, q ≤ 105\n\n1 ≤ ai ≤ 109\n\n1 ≤ t ≤ 1018\n\nFor each query, print the answer in one line.\n\n"},{"iden":"input","content":"The first line of input contains two integers n and q.The second line contains n space separated integers, a1, a2, ..., an .The next q lines, each line contains a single integer t .1 ≤ n, q ≤ 1051 ≤ ai ≤ 1091 ≤ t ≤ 1018"},{"iden":"output","content":"For each query, print the answer in one line."},{"iden":"examples","content":"Input5 71 2 3 4 51237141516Output2234512"}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be an input integer with $ 1 \\leq n \\leq 10^{1000} $.  \nLet $ h = 31 $ be the holy number.\n\n**Constraints**  \n$ n $ is given as a decimal string of up to 1001 digits.\n\n**Objective**  \nAccept $ n $ if and only if $ 31 \\mid n $, i.e., $ n \\equiv 0 \\pmod{31} $.","simple_statement":"Given an array of n numbers (each ≤ 60), and m queries. For each query with number x, compute the LCM of x consecutive elements starting from the first position, then the second, and so on — but wait, no.\n\nActually: For each query x, you must compute the LCM of every contiguous subarray of length x, and output the LCM of the first such subarray? No.\n\nWait — re-read:\n\n> In each query, he gives you number x and you should print the following number: LCM(a_i, a_{i+1}, ..., a_{i+x-1})\n\nBut it doesn’t say which i. It just says “the following number”. That’s ambiguous.\n\nBut looking at the sample structure and constraints, and typical CF problems — it’s likely: for each query x, compute the LCM of the first x elements: LCM(a1, a2, ..., ax)\n\nBut that would be too easy and not match m up to 1e6.\n\nAlternative: for each query x, compute the LCM of every contiguous subarray of length x, and sum them? But output says “print the following number”, singular.\n\nWait — original says:\n\n> print the following number: LCM(ai, ai+1, ..., ai+x−1)\n\nIt doesn’t specify i. That’s a problem.\n\nBut looking at constraints: n ≤ 20000, m ≤ 1e6, ai ≤ 60 — and LCM of small numbers.\n\nTypical problem: For each query x, compute the LCM of the contiguous subarray starting at position 1 with length x? But then why m up to 1e6?\n\nAnother common version: For each query x, output the LCM of all contiguous subarrays of length x? But that would be a list, not a single number.\n\nWait — maybe it’s: for each query x, output the LCM of the entire array? No, x is given.\n\nI think the intended meaning is:\n\nFor each query x, compute LCM(a_1, a_2, ..., a_x) — the LCM of the first x elements.\n\nBut then why say “ai, ai+1, ..., ai+x−1” with i unspecified?\n\nPerhaps it’s a typo, and it should be: for each query x, compute LCM(a_1, a_2, ..., a_x)\n\nThat’s the only way this makes sense with the constraints and output format.\n\nBecause if you had to compute LCM for every starting position i for each query x, that would be O(n) per query → 1e6 * 2e4 = 20e9 operations — too slow.\n\nBut ai ≤ 60 — LCM of numbers ≤60 can be precomputed, and LCM changes rarely.\n\nActually, LCM of a sequence of numbers ≤60 can only take a limited number of distinct values.\n\nSo maybe: Precompute LCM for all prefixes.\n\nThen for each query x, output LCM(a1 to ax)\n\nThat matches: “LCM(ai, ai+1, ..., ai+x−1)” — if i=1 always.\n\nI think that’s the intended meaning.\n\nIn many problems, when they say “for query x, compute LCM of first x elements”, they write it that way.\n\nSo I’ll assume: for each query x, compute LCM of the first x elements of the array.\n\nPrint LCM(a1, a2, ..., ax) mod (10^9+7)\n\nNote: LCM can be huge, but since ai ≤ 60, the LCM of any prefix is bounded by LCM(1..60) which is around 10^25, so we can compute it with big integers or mod? But mod 10^9+7 — but LCM is not linear, so we can’t mod during LCM.\n\nSo we compute LCM as integer, and only mod at output? But LCM(1..60) is about 10^25, which fits in Python int, but in C++ we need __int128 or handle carefully.\n\nBut problem says “print modulo 10^9+7”, so we compute LCM as big integer, then mod at end.\n\nBut LCM(a,b) = a*b / GCD(a,b) — we can compute step by step.\n\nSince n ≤ 20000, and each LCM computation is fast (numbers ≤60), we can precompute all prefix LCMs for x from 1 to n.\n\nThen for each query, just output precomputed[x].\n\nThat’s O(n) precomputation, O(1) per query.\n\nPerfect.\n\nSo simplified statement:\n\nYou are given an array of n integers (each between 1 and 60). For each of m queries, you are given x, and you must output the LCM of the first x numbers in the array, modulo 10^9+7.","has_page_source":false}