JerryL/AlgoSimBench huggingface dataset:
453_D. Little Pony and Elements of Harmony

The Elements of Harmony are six supernatural artifacts representing subjective aspects of harmony. They are arguably the most powerful force in Equestria. The inside of Elements of Harmony can be seen as a complete graph with n vertices labeled from 0 to n - 1, where n is a power of two, equal to 2m.

<image>

The energy in Elements of Harmony is in constant movement. According to the ancient book, the energy of vertex u in time i (ei[u]) equals to: 

<image>

Here b[] is the transformation coefficient — an array of m + 1 integers and f(u, v) is the number of ones in the binary representation of number (u xor v).

Given the transformation coefficient and the energy distribution at time 0 (e0[]). Help Twilight Sparkle predict the energy distribution at time t (et[]). The answer can be quite large, so output it modulo p.

Input

The first line contains three integers m, t and p (1 ≤ m ≤ 20; 0 ≤ t ≤ 1018; 2 ≤ p ≤ 109). The following line contains n (n = 2m) integers e0[i] (1 ≤ e0[i] ≤ 109; 0 ≤ i < n). The next line contains m + 1 integers b[i] (0 ≤ b[i] ≤ 109; 0 ≤ i ≤ m).

Output

Output n lines, the i-th line must contain a single integer et[i] modulo p.

Examples

Input

2 2 10000
4 1 2 3
0 1 0


Output

14
6
6
14

Example input:
2 2 10000
4 1 2 3
0 1 0


Example output:
14
6
6
14


Tags: dp
matrices
Difficulty rating: 3000

Solution:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 1 << 22;
ll e[N], b[N], d[N];
ll t, p, n;
ll mul(ll a, ll b) { return (a * b - ll(ld(a) * b / p) * p) % p; }
void tf(ll *x, int l, int r, int n) {
  if (l == r) return;
  int m = (l + r) / 2;
  ll a, b;
  tf(x, l, m, n >> 1);
  tf(x, m + 1, r, n >> 1);
  for (int i = l; i <= m; i++) {
    a = x[i], b = x[i + (r - l + 1) / 2];
    x[i] = (a + b) % p, x[i + (r - l + 1) / 2] = (a - b + p) % p;
  }
}
int main() {
  int m;
  scanf("%d%I64d%I64d", &m, &t, &p);
  n = 1 << m;
  p *= n;
  for (int i = 0; i < n; i++) scanf("%I64d", &e[i]);
  for (int i = 0; i <= m; i++) scanf("%I64d", &b[i]);
  for (int i = 1; i < n; i++) d[i] = d[i >> 1] + (i & 1);
  for (int i = 0; i < n; i++) d[i] = b[d[i]];
  tf(e, 0, n - 1, n);
  tf(d, 0, n - 1, n);
  while (t) {
    if (t & 1)
      for (int i = 0; i < n; i++) e[i] = mul(e[i], d[i]);
    for (int i = 0; i < n; i++) d[i] = mul(d[i], d[i]);
    t >>= 1;
  }
  tf(e, 0, n - 1, n);
  for (int i = 0; i < n; i++) printf("%I64d\n", e[i] >> m);
  return 0;
}
559_D. Randomizer

Gerald got tired of playing board games with the usual six-sided die, and he bought a toy called Randomizer. It functions as follows.

A Randomizer has its own coordinate plane on which a strictly convex polygon is painted, the polygon is called a basic polygon. If you shake a Randomizer, it draws some nondegenerate (i.e. having a non-zero area) convex polygon with vertices at some vertices of the basic polygon. The result of the roll (more precisely, the result of the shaking) is considered to be the number of points with integer coordinates, which were strictly inside (the points on the border are not considered) the selected polygon. Now Gerald is wondering: what is the expected result of shaking the Randomizer?

During the shaking the Randomizer considers all the possible non-degenerate convex polygons with vertices at the vertices of the basic polygon. Let's assume that there are k versions of the polygons. Then the Randomizer chooses each of them with probability <image>.

Input

The first line of the input contains a single integer n (3 ≤ n ≤ 100 000) — the number of vertices of the basic polygon. 

Next n lines contain the coordinates of the vertices of the basic polygon. The i-th of these lines contain two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — the coordinates of the i-th vertex of the polygon. The vertices are given in the counter-clockwise order.

Output

Print the sought expected value with absolute or relative error at most 10 - 9.

Examples

Input

4
0 0
2 0
2 2
0 2


Output

0.2


Input

5
0 0
2 0
2 2
1 3
0 2


Output

0.8125

Note

A polygon is called strictly convex if it is convex and no its vertices lie on the same line.

Let's assume that a random variable takes values x1, ..., xn with probabilities p1, ..., pn, correspondingly. Then the expected value of this variable equals to <image>.

Example input:
4
0 0
2 0
2 2
0 2

5
0 0
2 0
2 2
1 3
0 2


Example output:
0.200000000000

0.812500000000


Tags: combinatorics
geometry
probabilities
Difficulty rating: 2800

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
double ans, pos[N];
int n, x[N], y[N];
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &x[i], &y[i]);
  pos[0] = 1;
  for (int i = 1; i < N; i++) pos[i] = pos[i - 1] * 0.5;
  for (int i = 1; i <= n; i++) {
    int j = i % n + 1, t = 100, k = 2;
    for (; j != i && t; t--, j = j % n + 1, k++)
      ans += (pos[k] - pos[n]) * (1.0 * x[i] * y[j] - 1.0 * x[j] * y[i] -
                                  gcd(abs(x[i] - x[j]), abs(y[i] - y[j])));
  }
  ans = ans * 0.5 / (1 - pos[n] * (1 + n + 1.0 * n * (n - 1) / 2));
  printf("%.10lf\n", ans + 1);
}
498_E. Stairs and Lines

You are given a figure on a grid representing stairs consisting of 7 steps. The width of the stair on height i is wi squares. Formally, the figure is created by consecutively joining rectangles of size wi × i so that the wi sides lie on one straight line. Thus, for example, if all wi = 1, the figure will look like that (different colors represent different rectangles):

<image>

And if w = {5, 1, 0, 3, 0, 0, 1}, then it looks like that:

<image>

Find the number of ways to color some borders of the figure's inner squares so that no square had all four borders colored. The borders of the squares lying on the border of the figure should be considered painted. The ways that differ with the figure's rotation should be considered distinct. 

Input

The single line of the input contains 7 numbers w1, w2, ..., w7 (0 ≤ wi ≤ 105). It is guaranteed that at least one of the wi's isn't equal to zero.

Output

In the single line of the output display a single number — the answer to the problem modulo 109 + 7.

Examples

Input

0 1 0 0 0 0 0


Output

1


Input

0 2 0 0 0 0 0


Output

7


Input

1 1 1 0 0 0 0


Output

9


Input

5 1 0 3 0 0 1


Output

411199181

Note

All the possible ways of painting the third sample are given below:

<image>

Example input:
1 1 1 0 0 0 0

5 1 0 3 0 0 1

0 2 0 0 0 0 0

0 1 0 0 0 0 0


Example output:
9

411199181

7

1


Tags: dp
matrices
Difficulty rating: 2700

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 7, M = (int)1e9 + 7;
long long a[N][N], b[N][N], c[N][N];
int S;
void mul(long long x[N][N], long long y[N][N]) {
  for (int i = 0; i < S; ++i)
    for (int j = 0; j < S; ++j) {
      c[i][j] = 0ll;
      for (int k = 0; k < S; ++k) (c[i][j] += x[i][k] * y[k][j]) %= M;
    }
  memcpy(x, c, sizeof(c));
}
int main() {
  for (int i = 0; i < (1 << 7); ++i) a[i][i] = 1;
  for (int h = 1, w; h <= 7; ++h) {
    S = 1 << h;
    scanf("%d", &w);
    for (int i = 0; i < S; ++i)
      for (int j = 0; j < S; ++j) {
        b[i][j] = 0;
        for (int k = 0; k < (S >> 1); ++k)
          if ((i | j | k | (k << 1)) == S - 1) ++b[i][j];
      }
    for (; w; w >>= 1) {
      if (w & 1) mul(a, b);
      mul(b, b);
    }
  }
  printf("%d\n", a[0][0]);
  return 0;
}
633_A. Ebony and Ivory

Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.

For every bullet that hits the shield, Ebony deals a units of damage while Ivory deals b units of damage. In order to break the shield Dante has to deal exactly c units of damage. Find out if this is possible.

Input

The first line of the input contains three integers a, b, c (1 ≤ a, b ≤ 100, 1 ≤ c ≤ 10 000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively.

Output

Print "Yes" (without quotes) if Dante can deal exactly c damage to the shield and "No" (without quotes) otherwise.

Examples

Input

4 6 15


Output

No


Input

3 2 7


Output

Yes


Input

6 11 6


Output

Yes

Note

In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage. 

Example input:
6 11 6

3 2 7

4 6 15


Example output:
YES
YES
NO

Tags: brute force
math
number theory
Difficulty rating: 1100

Solution:
a,b,c=map(int,input().split())
i=0
s='NO'
while i<=c:s=s if(c-i)%b else 'YES';i+=a
print(s)
199_A. Hexadecimal's theorem

Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.

Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.

So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...

If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.

Input

The input contains of a single integer n (0 ≤ n < 109) — the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.

Output

Output three required numbers: a, b and c. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.

If there are multiple answers, print any of them.

Examples

Input

3


Output

1 1 1


Input

13


Output

2 3 8

Example input:
3

13


Example output:
0 0 3

0 0 13


Tags: brute force
constructive algorithms
implementation
number theory
Difficulty rating: 900

Solution:
print 0,0,input()
217_B. Blackboard Fibonacci

Fibonacci numbers are the sequence of integers: f0 = 0, f1 = 1, f2 = 1, f3 = 2, f4 = 3, f5 = 5, ..., fn = fn - 2 + fn - 1. So every next number is the sum of the previous two.

Bajtek has developed a nice way to compute Fibonacci numbers on a blackboard. First, he writes a 0. Then, below it, he writes a 1. Then he performs the following two operations:

  * operation "T": replace the top number with the sum of both numbers; 
  * operation "B": replace the bottom number with the sum of both numbers. 



If he performs n operations, starting with "T" and then choosing operations alternately (so that the sequence of operations looks like "TBTBTBTB..."), the last number written will be equal to fn + 1.

Unfortunately, Bajtek sometimes makes mistakes and repeats an operation two or more times in a row. For example, if Bajtek wanted to compute f7, then he would want to do n = 6 operations: "TBTBTB". If he instead performs the sequence of operations "TTTBBT", then he will have made 3 mistakes, and he will incorrectly compute that the seventh Fibonacci number is 10. The number of mistakes in the sequence of operations is the number of neighbouring equal operations («TT» or «BB»).

You are given the number n of operations that Bajtek has made in an attempt to compute fn + 1 and the number r that is the result of his computations (that is last written number). Find the minimum possible number of mistakes that Bajtek must have made and any possible sequence of n operations resulting in r with that number of mistakes.

Assume that Bajtek always correctly starts with operation "T".

Input

The first line contains the integers n and r (1 ≤ n, r ≤ 106).

Output

The first line of the output should contain one number — the minimum possible number of mistakes made by Bajtek. The second line should contain n characters, starting with "T", describing one possible sequence of operations with that number of mistakes. Each character must be either "T" or "B".

If the required sequence doesn't exist, output "IMPOSSIBLE" (without quotes).

Examples

Input

6 10


Output

2
TBBTTB


Input

4 5


Output

0
TBTB


Input

2 1


Output

IMPOSSIBLE

Example input:
6 10

2 1

4 5


Example output:
2
TBBTTB
IMPOSSIBLE

0
TBTB

Tags: brute force
math
Difficulty rating: 2100

Solution:
#include <bits/stdc++.h>
using namespace std;
int n, r, A = 999999;
char s[1000003], t[1000003];
void go(int a, int b) {
  int nw = 0;
  for (int i = n - 1; i >= 0; i--)
    if (a && b && nw < A) {
      if (a >= b)
        s[i] = 'T', a -= b;
      else
        s[i] = 'B', b -= a;
      nw += s[i] == s[i + 1];
    } else
      return;
  if (!a && b == 1 && s[0] == 'T') {
    A = nw;
    for (int i = 0; i < n; i++) t[i] = s[i];
  }
}
int main() {
  cin >> n >> r;
  for (int i = 1; i <= r; i++) go(r, i), go(i, r);
  if (A != 999999)
    cout << A << endl << t;
  else
    puts("IMPOSSIBLE");
}
717_A. Festival Organization

The Prodiggers are quite a cool band and for this reason, they have been the surprise guest at the ENTER festival for the past 80 years. At the beginning of their careers, they weren’t so successful, so they had to spend time digging channels to earn money; hence the name. Anyway, they like to tour a lot and have surprising amounts of energy to do extremely long tours. However, they hate spending two consecutive days without having a concert, so they would like to avoid it.

A tour is defined by a sequence of concerts and days-off. You need to count in how many ways The Prodiggers can select k different tours of the same length between l and r.

For example if k = 2, l = 1 and r = 2, if we define concert day as {1} and day-off as {0}, here are all possible tours: {0}, {1}, {00}, {01}, {10}, {11}. But tour 00 can not be selected because it has 2 days-off in a row. Now, we need to count in how many ways we can select k = 2 tours of the same length in range [1;2]. Here they are: {0,1}; {01,10}; {01,11}; {10,11}.

Since their schedule is quite busy, they want you to tell them in how many ways can do that, modulo 1 000 000 007 (109 + 7).

Input

The first line of the input contains three integers k, l and r (1 ≤ k ≤ 200, 1 ≤ l ≤ r ≤ 1018).

Output

Output a single number: the number of ways to select k different tours of the same length, modulo 1 000 000 007.

Example

Input

1 1 2


Output

5

Example input:
1 1 2


Example output:
5


Tags: math
number theory
Difficulty rating: 2900

Solution:
#include <bits/stdc++.h>
long long inv(int a, int p = 1000000007) {
  return a == 1 ? 1 : (1 + p * (a - inv(p % a, a))) / a % p;
}
struct num {
  int a, b;
  num(int a = 0, int b = 0) {
    this->a = a;
    this->b = b;
  }
  num operator+(num x) {
    return num((a + x.a) % 1000000007, (b + x.b) % 1000000007);
  }
  num operator-(num x) {
    return num((a - x.a + 1000000007) % 1000000007,
               (b - x.b + 1000000007) % 1000000007);
  }
  num operator*(num x) {
    return num((1ll * a * x.a + 5ll * b * x.b) % 1000000007,
               (1ll * a * x.b + 1ll * b * x.a) % 1000000007);
  }
};
num pow(num a, long long n, bool t = 0) {
  num p = 1, s = 0;
  int i = 0;
  while (n >> i) i++;
  while (i--) {
    s = s * (p + 1), p = p * p;
    if (n >> i & 1) s = s + p, p = p * a;
  }
  return t ? s : p;
}
long long a[210], C[210];
num pA[210], pB[210];
int main() {
  int k;
  long long l, r;
  std::cin >> k >> l >> r;
  *pA = *pB = *a = *C = 1;
  for (int i = 1; i <= k; (*a *= 1000000007 + 2 - ++i) %= 1000000007) {
    for (int j = i; j; j--)
      a[j] = (a[j - 1] + a[j] * (1000000007 - i + 1)) % 1000000007;
    pA[i] = pow(num(inv(2), inv(2)), i);
    pB[i] = pow(num(inv(2), 1000000007 - inv(2)), i);
  }
  num S = 0, c = *a, x;
  for (int i = 0; i <= k; i++, c = pow(num(0, inv(5)), i) * a[i]) {
    for (int j = i; j >= 0; j--) {
      x = (pow(pA[j] * pB[i - j], r + 3, 1) -
           pow(pA[j] * pB[i - j], l + 2, 1)) *
          (j ? (C[j] += C[j - 1]) %= 1000000007 : 1) * c;
      i - j& 1 ? S = S - x : S = S + x;
    }
  }
  for (int i = 1; i <= k; i++) S = S * inv(i);
  std::cout << S.a << '\n';
}
896_D. Nephren Runs a Cinema

Lakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema.

<image>

However, one day, the No. 68 Cinema runs out of changes (they don't have 50-yuan notes currently), but Nephren still wants to start their business. (Assume that yuan is a kind of currency in Regulu Ere.)

There are three types of customers: some of them bring exactly a 50-yuan note; some of them bring a 100-yuan note and Nephren needs to give a 50-yuan note back to him/her; some of them bring VIP cards so that they don't need to pay for the ticket.

Now n customers are waiting outside in queue. Nephren wants to know how many possible queues are there that they are able to run smoothly (i.e. every customer can receive his/her change), and that the number of 50-yuan notes they have after selling tickets to all these customers is between l and r, inclusive. Two queues are considered different if there exists a customer whose type is different in two queues. As the number can be large, please output the answer modulo p.

Input

One line containing four integers n (1 ≤ n ≤ 105), p (1 ≤ p ≤ 2·109), l and r (0 ≤ l ≤ r ≤ n). 

Output

One line indicating the answer modulo p.

Examples

Input

4 97 2 3


Output

13


Input

4 100 0 4


Output

35

Note

We use A, B and C to indicate customers with 50-yuan notes, customers with 100-yuan notes and customers with VIP cards respectively.

For the first sample, the different possible queues that there are 2 50-yuan notes left are AAAB, AABA, ABAA, AACC, ACAC, ACCA, CAAC, CACA and CCAA, and the different possible queues that there are 3 50-yuan notes left are AAAC, AACA, ACAA and CAAA. So there are 13 different queues satisfying the first sample. Similarly, there are 35 different queues satisfying the second sample.

Example input:
4 100 0 4

4 97 2 3


Example output:
35
13

Tags: chinese remainder theorem
combinatorics
math
number theory
Difficulty rating: 2900

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long d[11], iv[N], ad[11][N], f[N];
int t, p;
long long qp(long long a, int b) {
  long long r = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1) r = r * a % p;
  return r;
}
long long c(int n, int m) {
  if (m < 0) return 0;
  long long r = f[n] * iv[m] % p * iv[n - m] % p;
  for (int i = 1; i <= t; ++i)
    r = r * qp(d[i], ad[i][n] - ad[i][m] - ad[i][n - m]) % p;
  return r;
}
int main() {
  int n, l, r, i, j, x, ph;
  long long ans = 0;
  scanf("%d%d%d%d", &n, &p, &l, &r), x = ph = p;
  for (i = 2; i * i <= x; ++i)
    if (!(x % i)) {
      ph = ph / i * (i - 1), d[++t] = i;
      do x /= i;
      while (!(x % i));
    }
  if (x > 1) d[++t] = x, ph = ph / x * (x - 1);
  f[0] = f[1] = iv[0] = iv[1] = 1, --ph;
  for (i = 2; i <= n; ++i) {
    for (x = i, j = 1; j <= t; ++j) {
      ad[j][i] = ad[j][i - 1];
      while (!(x % d[j])) x /= d[j], ++ad[j][i];
    }
    f[i] = f[i - 1] * x % p, iv[i] = qp(f[i], ph);
  }
  for (i = n - l; ~i; --i)
    ans = (ans + (c(n - i, (n - i - l) >> 1) - c(n - i, (n - i - r - 1) >> 1)) *
                     c(n, i)) %
          p;
  printf("%d", (ans + p) % p);
  return 0;
}
687_B. Remainders Game

Today Pari and Arya are playing a game called Remainders.

Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value <image>. There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya <image> if Arya wants. Given k and the ancient values, tell us if Arya has a winning strategy independent of value of x or not. Formally, is it true that Arya can understand the value <image> for any positive integer x?

Note, that <image> means the remainder of x after dividing it by y.

Input

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 1 000 000) — the number of ancient integers and value k that is chosen by Pari.

The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 1 000 000).

Output

Print "Yes" (without quotes) if Arya has a winning strategy independent of value of x, or "No" (without quotes) otherwise.

Examples

Input

4 5
2 3 5 12


Output

Yes


Input

2 7
2 3


Output

No

Note

In the first sample, Arya can understand <image> because 5 is one of the ancient numbers.

In the second sample, Arya can't be sure what <image> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7.

Example input:
2 7
2 3

4 5
2 3 5 12


Example output:
NO

YES


Tags: chinese remainder theorem
math
number theory
Difficulty rating: 1800

Solution:
R=lambda:map(int,raw_input().split())
def gcd(a,b):
  return gcd(b,a%b) if b else a
n,k=R()
t=1
for c in R():
  x=gcd(k,c)
  t=t/gcd(t,x)*x
print 'Yes' if t==k else 'No'
475_D. CGCDSSQ

Given a sequence of integers a1, ..., an and q queries x1, ..., xq on it. For each query xi you have to count the number of pairs (l, r) such that 1 ≤ l ≤ r ≤ n and gcd(al, al + 1, ..., ar) = xi.

<image> is a greatest common divisor of v1, v2, ..., vn, that is equal to a largest positive integer that divides all vi.

Input

The first line of the input contains integer n, (1 ≤ n ≤ 105), denoting the length of the sequence. The next line contains n space separated integers a1, ..., an, (1 ≤ ai ≤ 109).

The third line of the input contains integer q, (1 ≤ q ≤ 3 × 105), denoting the number of queries. Then follows q lines, each contain an integer xi, (1 ≤ xi ≤ 109).

Output

For each query print the result in a separate line.

Examples

Input

3
2 6 3
5
1
2
3
4
6


Output

1
2
2
0
1


Input

7
10 20 3 15 1000 60 16
10
1
2
3
4
5
6
10
20
60
1000


Output

14
0
2
2
2
0
2
2
1
1

Example input:
7
10 20 3 15 1000 60 16
10
1
2
3
4
5
6
10
20
60
1000

3
2 6 3
5
1
2
3
4
6


Example output:
                                                              14
                                                               0
                                                               2
                                                               2
                                                               2
                                                               0
                                                               2
                                                               2
                                                               1
                                                               1

                                                               1
                                                               2
                                                               2
                                                               0
                                                               1


Tags: brute force
data structures
math
Difficulty rating: 2000

Solution:
from sys import stdin
import math
from collections import defaultdict

input = stdin.readline

# n, k = map(int, input().split(" "))
# l = list(map(int, input().split(" ")))

n = int(input())
l = list(map(int, input().split(" ")))


d = defaultdict(int)
g = defaultdict(int)
d[l[0]] = 1
g[l[0]] = 1
for i in range(1, n):
    t = defaultdict(int)
    t[l[i]] = 1
    g[l[i]]+=1
    for k, v in d.items():
        gcd = math.gcd(k, l[i])
        t[gcd] += v
        g[gcd] += v
    d = t

for i in range(int(input())):
    a = g[int(input())]
    print(a)