JerryL/AlgoSimBench huggingface dataset:
p03465 AtCoder Grand Contest 020 - Median Sum

You are given N integers A_1, A_2, ..., A_N.

Consider the sums of all non-empty subsequences of A. There are 2^N - 1 such sums, an odd number.

Let the list of these sums in non-decreasing order be S_1, S_2, ..., S_{2^N - 1}.

Find the median of this list, S_{2^{N-1}}.

Constraints

* 1 \leq N \leq 2000
* 1 \leq A_i \leq 2000
* All input values are integers.

Input

Input is given from Standard Input in the following format:


N
A_1 A_2 ... A_N


Output

Print the median of the sorted list of the sums of all non-empty subsequences of A.

Examples

Input

3
1 2 1


Output

2


Input

1
58


Output

58

Example input:
3
1 2 1
1
58

Example output:
2
58

Difficulty rating: 0

Solution:
_,a=open(0)
*a,=map(int,a.split())
d=1
for i in a:d|=d<<i
s=0--sum(a)//2
print(bin(d)[~s::-1].find('1')+s)
p02942 AtCoder Grand Contest 037 - Sorting a Grid

We have a grid with N rows and M columns of squares. Each integer from 1 to NM is written in this grid once. The number written in the square at the i-th row from the top and the j-th column from the left is A_{ij}.

You need to rearrange these numbers as follows:

1. First, for each of the N rows, rearrange the numbers written in it as you like.
2. Second, for each of the M columns, rearrange the numbers written in it as you like.
3. Finally, for each of the N rows, rearrange the numbers written in it as you like.



After rearranging the numbers, you want the number written in the square at the i-th row from the top and the j-th column from the left to be M\times (i-1)+j. Construct one such way to rearrange the numbers. The constraints guarantee that it is always possible to achieve the objective.

Constraints

* 1 \leq N,M \leq 100
* 1 \leq A_{ij} \leq NM
* A_{ij} are distinct.

Input

Input is given from Standard Input in the following format:


N M
A_{11} A_{12} ... A_{1M}
:
A_{N1} A_{N2} ... A_{NM}


Output

Print one way to rearrange the numbers in the following format:


B_{11} B_{12} ... B_{1M}
:
B_{N1} B_{N2} ... B_{NM}
C_{11} C_{12} ... C_{1M}
:
C_{N1} C_{N2} ... C_{NM}


Here B_{ij} is the number written in the square at the i-th row from the top and the j-th column from the left after Step 1, and C_{ij} is the number written in that square after Step 2.

Examples

Input

3 2
2 6
4 3
1 5


Output

2 6
4 3
5 1
2 1
4 3
5 6


Input

3 4
1 4 7 10
2 5 8 11
3 6 9 12


Output

1 4 7 10
5 8 11 2
9 12 3 6
1 4 3 2
5 8 7 6
9 12 11 10

Example input:
3 2
2 6
4 3
1 5
3 4
1 4 7 10
2 5 8 11
3 6 9 12

Example output:
2 6
4 3
5 1
2 1
4 3
5 6
1 4 7 10
5 8 11 2
9 12 3 6
1 4 3 2
5 8 7 6
9 12 11 10

Difficulty rating: 0

Solution:
#include<bits/stdc++.h>
using namespace std;
const int MX = 105;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, m, a, pr[MX], w, b[MX][MX];
set<int> st[MX];
bool used[MX];
bool dfs(int v){
	used[v] = true;
	for(int it: st[v]) if((w = pr[it/m]) < 0 || (!used[w] && dfs(w))){
		pr[it/m] = v;
		return true;
	}
	return false;
}
int main(){
	scanf("%d%d", &n, &m);
	rep(i,n) rep(j,m){
		scanf("%d", &a);
		st[i].insert(a-1);
	}
	rep(i,m){
		fill(pr, pr+n, -1);
		rep(j,n){
			fill(used,used+n,0);
			dfs(j);
		}
		rep(j,n){
			w = pr[j];
			auto it = st[w].lower_bound(j*m);
			b[i][w] = *it;
			st[w].erase(it);
		}
	}
	rep(i,n) rep(j,m) printf("%d%c", b[j][i]+1, j<m-1?' ':'\n');
	rep(i,m) sort(b[i],b[i]+n);
	rep(i,n) rep(j,m) printf("%d%c", b[j][i]+1, j<m-1?' ':'\n');
}
p02590 AtCoder Grand Contest 047 - Product Modulo

Let’s take a prime P = 200\,003. You are given N integers A_1, A_2, \ldots, A_N. Find the sum of ((A_i \cdot A_j) \bmod P) over all N \cdot (N-1) / 2 unordered pairs of elements (i < j).

Please note that the sum isn't computed modulo P.

Constraints

* 2 \leq N \leq 200\,000
* 0 \leq A_i < P = 200\,003
* All values in input are integers.

Input

Input is given from Standard Input in the following format.


N
A_1 A_2 \cdots A_N


Output

Print one integer — the sum over ((A_i \cdot A_j) \bmod P).

Examples

Input

4
2019 0 2020 200002


Output

474287


Input

5
1 1 2 2 100000


Output

600013

Example input:
4
2019 0 2020 200002
5
1 1 2 2 100000

Example output:
474287
600013

Difficulty rating: 0

Solution:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using cmp=complex<double>;
const ll P=200003;
const int lg=19,N=1<<lg;
int n,vl[1<<18],rev[N];
ll ans,cnt[1<<18],rans;
cmp a[N],w[lg][N];
basic_string<int> v;
ll po(ll a,ll b,ll c){ll r=1;for(;b;b/=2,a=a*a%c)if(b&1)r=r*a%c;return r;}
void FFT(cmp*a){
	for(int i=0;i<N;i++)if(i<rev[i])swap(a[i],a[rev[i]]);
	for(int i=0;i<lg;i++)
		for(int j=0;j<N;j++)if(j>>i&1){
			cmp l=a[j^1<<i],r=a[j]*w[i][j&(1<<i)-1];
			a[j^1<<i]=l+r,a[j]=l-r;
		}
}
int main(){
	scanf("%d",&n);
	for(int j=0;j<P-1;j++)vl[po(2,j,P)]=j;
	for(int i=1;i<=n;i++){
		int x;scanf("%d",&x);
		if(x)a[vl[x]]+=1.;
		ans-=1ll*x*x%P;
	}
	for(int i=0;i<N;i++)rev[i]=rev[i/2]/2|i%2<<lg-1;
	for(int i=0;i<lg;i++)
		for(int j=0;j<(1<<i);j++)w[i][j]=exp(acos(-1)*j/(1<<i)*cmp{0.,1.});
	FFT(a);
	for(int i=0;i<N;i++)a[i]=conj(a[i]*a[i]);
	FFT(a);double rv=1./N;
	for(int i=0;i<N;i++)
		cnt[i%(P-1)]+=ll(a[i].real()*rv+.5);
	for(int i=0;i<P-1;i++)
		rans+=cnt[i]*po(2,i,P);
	printf("%lld\n",(rans+ans)/2);
	return 0;
}
p03421 AtCoder Regular Contest 091 - LISDL

Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions:

* The length of its longest increasing subsequence is A.
* The length of its longest decreasing subsequence is B.



If it exists, construct one such sequence.

Constraints

* 1 \leq N,A,B \leq 3\times 10^5
* All input values are integers.

Input

Input is given from Standard Input in the following format:


N A B


Output

If there are no sequences that satisfy the conditions, print `-1`.

Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed.

Examples

Input

5 3 2


Output

2 4 1 5 3


Input

7 7 1


Output

1 2 3 4 5 6 7


Input

300000 300000 300000


Output

-1

Example input:
7 7 1
300000 300000 300000
5 3 2

Example output:
1 2 3 4 5 6 7
-1
2 4 1 5 3

Difficulty rating: 0

Solution:
r,p=range,print
n,a,b=map(int,input().split())
if a+b>n+1or a*b<n:exit(p(-1))
l=[[]for i in r(b-1)]+[list(r(1,a+1))]
for i in r(a,n):l[-2-(i-a)%(b-1)]+=[i+1]
for i in l:p(*i,end=" ")
A String Game

All submissions for this problem are available.
Teddy and Tracy like to play a game based on strings. The game is as follows. Initially, Tracy writes a long random string on a whiteboard. Then, each player starting with Teddy makes turn alternately. Each turn, the player must erase a contiguous substring that exists in the dictionary. The dictionary consists of N words.
Of course, the player that can't erase any substring in his turn loses the game, and the other player is declared the winner.
Note that after a substring R is erased, the remaining substring becomes separated, i.e. they cannot erase a word that occurs partially to the left of R and partially to the right of R.
Determine the winner of the game, assuming that both players play optimally.
Input
The first line contains a single integer T, the number of test cases. T test cases follow. The first line of each testcase contains a string S, the string Tracy writes on the whiteboard. The next line contains a single integer N. N lines follow. The i-th line contains a single string wi, the i-th word in the dictionary.
Output
For each test case, output a single line containing the name of the winner of the game.
Example

Input:
3
codechef
2
code
chef
foo
1
bar
mississippi
4
ssissi
mippi
mi
ppi

Output:
Tracy
Tracy
Teddy
Constraints

1 <= T <= 5
1 <= N <= 30
1 <= |S| <= 30
1 <= |wi| <= 30
S and wi contain only characters 'a'-'z'

Example input:

Example output:


Solution:

    #include <cstdio>
    #include <cstring>
    
    int main(int argc, char *argv[]) {
    	int t;
    	scanf("%d",&t);
    	while(t--) {
    		int i, j, d, p, n; char word[50]={0x00},dictionary[50][50];
    		scanf("%s %d",word,&n);
    		int len=strlen(word),dlen[50],grundy[50][50];
    		for(i=0;i<n;scanf("%s",dictionary[i]),dlen[i]=strlen(dictionary[i++]));
    		for(i=0;i<len;grundy[i][i]=0,++i);
    		for(j=1;j<=len;++j) {
    			for(i=0;i+j<=len;++i) {
    				int mex[50]={0};
    				for(d=0;d<n;++d) {
    					for(p=i;p+dlen[d]<=i+j;++p) {
    						if(!(memcmp(dictionary[d],word+p,dlen[d]))) {
    							mex[grundy[i][p]^grundy[p+dlen[d]][i+j]]=1;
    						}
    					}
    				} grundy[i][i+j]=0;while(mex[grundy[i][i+j]])grundy[i][i+j]++;
    			}
    		} puts(grundy[0][len]?"Teddy":"Tracy");
    	} return(0);
    }
Block Game

All submissions for this problem are available.
In the magic land, there is a smart but naughty boy Crane.
Crane has n houses, and n friends (both numbered from 1 to n).
Crane's mother has scheduled a plan for all his friends
such that each friend visits each house of Crane exactly once
at a different time, i.e.,
there is at most one friend in any house at any time.
But like Crane all his friends are also naughty.
Therefore his mother wants to lock away each of his friends in distinct houses.
What she'll do is to choose a distinct house for each friend. As that friend visits
that house, he'll be locked in that house.  That is, Crane's mother wants to find a
sequence block such that
the i-th friend will be locked in block[i]-th house
once he visits that house. As she wants to ensure that there is at maximum one
person in each house, she must choose the sequence block such
that if friend A visits house H at time T, and he is locked away in the house, then no other friends visit house H
after time T. 
Help Crane's mother to find such a sequence block. 
Input
First line contains a single integer n (1 ≤ n
≤ 100), indicating the number of friends and houses.
Then n lines follow, with each line containing n positive integers.
The j-th integer in i-th line indicates the time when the i-th friend will visit the j-th house. All times will fit in signed 32-bit integer.
Output
If there exists a sequence block that satisfies the constraints, then output block[1] block[2] ... block[n] in one line, separated by a single space.
Otherwise if there is no such sequence, output -1 in one line.
If there are multiple answers, then anyone will do.
Example

Input:
3
1 2 3
4 5 6
7 8 9

Output:
3 2 1

Example input:

Example output:


Solution:

    #include<bits/stdc++.h>
    #define X first
    #define Y second
    using namespace std;
    int hsh[135][135],adj[135][135],M[135],W[135];
    vector<pair<int,int> > v[135];
    queue<int> q;
    int main()
    {
        int i,j,k,n,mc,mn,ck,m,w;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            q.emplace(i);
            for(j=1;j<=n;j++)
            {
                scanf("%d",&adj[i][j]);
                v[i].emplace_back(-adj[i][j],j);
            }
            sort(v[i].begin(),v[i].end());
        }
        while(!q.empty())
        {
            m=q.front();q.pop();
            if(v[m].empty())continue;
            w=v[m][v[m].size()-1].Y;
            v[m].pop_back();
            if(W[w]==0)
                W[w]=m,M[m]=w;
            else if(adj[m][w]>adj[W[w]][w])
            {
                M[W[w]]=0;
                q.emplace(W[w]);
                M[m]=w;
                W[w]=m;
            }
            else
                q.emplace(m);
        }
        for(i=1;i<=n;i++)
            printf("%d ",M[i]);
    }
Count Relations

All submissions for this problem are available.
Let A be a set of the first N positive integers :A={1,2,3,4.........N}

Let B be the set containing all the subsets of A.
Professor Eric is a mathematician who defined two kind of relations R1 and R2 on set B.

The relations are defined as follows:
R1={ (x,y) : x and y belong to B and x is not a subset of y and y is not a subset of x and the intersection of x and y is equal to empty set }
R2={ (x,y) : x and y belong to B and x is not a subset of y and y is not a subset of x and the intersection of x and y is not equal to empty set }
Now  given the number N,Professor Eric wants to know how many relations of kind R1 and R2 exists.Help him. 
 NOTE : (x,y) is the same as (y,x) ,i.e the pairs are unordered.
Input format:
The first line contains the number of test cases T.Each of the test case is denoted by a single integer N.
Output format:
Output T lines, one for each test case,containing  two integers denoting the number of relations of kind R1 and R2 respectively, modulo 100000007.
Example

Sample Input:
3
1
2
3
Sample Output:
0 0
1 0
6 3
Constraints:
1 <= T <= 1000
1 <= N <= 10^18
Explanation:
Let A={1,2}
Then B={Phi,{1},{2},{1,2}}
Phi=Empty Set
So R1=Either {({1},{2})} or {({2},{1})}
and R2=No relation exists
So,there is 1 relation of kind R1 and 0 relation of kind R2.

Example input:

Example output:


Solution:

    #include<stdio.h>
    long long int m = 100000007;
    
    long long int modulo(long long int b, long long int e, long long int mod)
    {
    	long long int ans = 1;
    	while(e > 0)
    	{
    		if(e & 1) ans = (ans*b) % mod;
    		b = (b*b) % mod;
    		e = e >> 1;
    	}
    	return ans;
    }
    
    int main()
    {
    	long long int t , n, a1, a2;
    	scanf("%lld", &t);
    	while(t--)
    	{
    		scanf("%lld", &n);
    		a1 = ((modulo(3, n, 2*m) + 1) / 2) - modulo(2, n, m);
    		a2 = ((2 * modulo(4, n-1, m)) - modulo(3, n, m) + m) % m;
    		a2 = (a2 + modulo(2, n-1, m) + modulo(2, n, m) - ((modulo(3, n, 2*m) + 1) / 2) + m) % m;
    		a1 = (a1 + m) % m;
    		printf("%lld %lld\n",a1,a2);
    	}
    	return 0;
    }
D-Power Permutations

All submissions for this problem are available.

Let N be a positive integer and S = {1, 2, 3, ..., N}. For a given positive integer d the function f : S --> S is called d-power permutation if there exists a bijection g : S --> S such that g ( g ( ... g ( x ) ... ) ) = f(x) for each x from S , where g is repeated exactly d times.


You are given some bijection f : S --> S and a positive integer D. You need to find the number of those d <= D such that f is d-power permutation.
Input
 The first line contains a single positive integer T <= 10, the number of test cases. T test cases follow. The first line of each test case contains two positive integers N and D, where N <= 700 and D <= 1018. The second line contains N space-separated integers. ith number in the second line is the value f(i). It is guaranteed that f is bijection from S onto S.
Output
 For each test case, output a single line containing the answer for the corresponding test case.
Example

Input:
2
3 6
1 2 3
5 10
2 1 4 5 3

Output:
6
3
Explanation
In the second case the appropriate values of d is 1, 5 and 7.

Example input:

Example output:


Solution:

    #include <stdio.h>
     
    #define N 1010
     
    int q, kv, cur, kp, j, qq, n, i, ii, len, ni, ok;
    int min_[N], pr[N], p[N], cnt[N], v[N];
    long long ans, md;
     
    void rec(int vv, int z, long long w)
    {
    if(vv==kv+1)
    	{
    	ans+=z*(md/w);
    	return;
    	}
    rec(vv+1,z,w);
    if(w<=md/v[vv]) rec(vv+1,-z,w*v[vv]);
    }
     
    main()
    {
    int fall;
     
    for(kp=!(i=2); i<=700; i++)
    	{
    	for(ok=!!(j=2); j<i; j++)
    		if(!(i%j)) ok=0;
    	if(ok) pr[++kp]=i;
    	}
    for(scanf("%d",&fall); fall--&&scanf("%d %lld",&n,&md); ans=0,rec(1,1,1),printf("%lld\n",ans))
    	{
    	for(i=1; i<=n; scanf("%d",&p[i++]));
    	for(i=1; i<=n; cnt[i++]=0);
    	for(i=1; i<=n; i++)
    		if(p[i])
    			{
    			for(ii=i,len=0; p[ii]; len++,ni=p[ii],p[ii]=0,ii=ni);
    			cnt[len]++;
    			}
    	for(q=1; q<=kp; min_[q++]=1000);
    	for(len=1; len<=n; len++)
    		if(cnt[len]>0)
    			for(q=1; q<=kp; q++)
    				if(!(len%pr[q]))
    					{
    					for(cur=1,ii=cnt[len]; !(ii%pr[q]); ii/=pr[q],cur++);
    					if(cur<min_[q]) min_[q]=cur; 
    					}
    	for(i=!(kv=0); i<=kp; i++)
    		if(min_[i]<1000)
    			for(j=!(v[++kv]=1); ++j<=min_[i]; v[kv]*=pr[i]);
    	}
    return 0;
    }
Floor Division Game

Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Henry and Derek are waiting on a room, eager to join the Snackdown 2016 Qualifier Round. They decide to pass the time by playing a game.  
In this game's setup, they write N positive integers on a blackboard. Then the players take turns, starting with Henry. In a turn, a player selects one of the integers, divides it by 2, 3, 4, 5 or 6, and then takes the floor to make it an integer again. If the integer becomes 0, it is erased from the board. The player who makes the last move wins.  
Henry and Derek are very competitive, so aside from wanting to win Snackdown, they also want to win this game. Assuming they play with the optimal strategy, your task is to predict who wins the game.  
Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of integers they wrote on the board. The second line contains N space-separated integers A1, A2, ..., AN denoting the integers themselves.
Output
For each test case, output a single line containing either “Henry” or “Derek” (without quotes), denoting the winner of the game.
Constraints

1 ≤ T ≤ 1000
1 ≤ N ≤ 100
1 ≤ Ai ≤ 1018

Example
Input:
2
2
3 4
3
1 3 5


Output:
Henry
Derek

Explanation
Example case 1. In this test case, the numbers on the board are [3,4]. Henry can win by selecting 4 and then dividing it by 2. The integers on the board are now [3,2]. Derek now has a couple of choices:

Derek can divide 2 by 3, 4, 5 or 6, making it 0 and removing it. Now only one integer remains on the board, 3, and Henry can just divide it by 6 to finish, and win, the game.
Derek can divide 3 by 4, 5 or 6, making it 0 and removing it. Now only one integer remains on the board, 2, and Henry can just divide it by 6 to finish, and win, the game.
Derek can divide 2 by 2. Now the integers are [1,3]. Henry can respond by dividing 3 by 3. The integers are now [1,1]. Now Derek has no choice but to divide 1 by 2, 3, 4, 5 or 6 and remove it (because it becomes 0). Henry can respond by dividing the remaining 1 by 2 to finish, and win, the game.
Derek can divide 3 by 2 or 3. Now the integers are [1,2]. Henry can respond by dividing 2 by 2. The integers are now [1,1]. This leads to a situation as in the previous case and Henry wins.

Example input:

Example output:


Solution:

    #include <bits/stdc++.h>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    ll G(ll x)
    {
    	if (!x) return 0;
    	if (x<6) return x/2+1;
    	return G(x/12);
    }
    int main()
    {
    	//Sprague-Grundy theorem: G(x)=G(x/12) with x>=6
    	int nTest;
    	scanf("%d",&nTest);
    	while (nTest--)
    	{
    		int n;
    		ll x,res=0;
    		scanf("%d",&n);
    		while (n--) scanf("%lld",&x),res^=G(x);
    		puts(res?"Henry":"Derek");
    	}
    }
1028_B. Unnatural Conditions

Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that 

  * s(a) ≥ n, 
  * s(b) ≥ n, 
  * s(a + b) ≤ m. 

Input

The only line of input contain two integers n and m (1 ≤ n, m ≤ 1129).

Output

Print two lines, one for decimal representation of a and one for decimal representation of b. Both numbers must not contain leading zeros and must have length no more than 2230.

Examples

Input

6 5


Output

6 
7


Input

8 16


Output

35 
53

Note

In the first sample, we have n = 6 and m = 5. One valid solution is a = 6, b = 7. Indeed, we have s(a) = 6 ≥ n and s(b) = 7 ≥ n, and also s(a + b) = s(13) = 4 ≤ m.

Example input:
8 16

6 5


Example output:
11111111
88888889
111111
888889

Tags: constructive algorithms
math
Difficulty rating: 1200

Solution:
print("4"*998+"5\n"+"5"*999)
1036_C. Classy Numbers

Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not.

You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R.

Each testcase contains several segments, for each of them you are required to solve the problem separately.

Input

The first line contains a single integer T (1 ≤ T ≤ 10^4) — the number of segments in a testcase.

Each of the next T lines contains two integers L_i and R_i (1 ≤ L_i ≤ R_i ≤ 10^{18}).

Output

Print T lines — the i-th line should contain the number of classy integers on a segment [L_i; R_i].

Example

Input

4
1 1000
1024 1024
65536 65536
999999 1000001


Output

1000
1
0
2

Example input:
4
1 1000
1024 1024
65536 65536
999999 1000001


Example output:
                                                            1000
                                                               1
                                                               0
                                                               2


Tags: combinatorics
dp
Difficulty rating: 1900

Solution:
#include <bits/stdc++.h>
using namespace std;
int f(long long n, int k) {
  if (k == 0 || n == 0) return 0;
  if (n < 10) return n;
  return 9 + f(n / 10, k) + (9 - n % 10) * f(n / 10 - 1, k - 1) +
         n % 10 * f(n / 10, k - 1);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long l, r;
    cin >> l >> r, cout << f(r, 3) - f(l - 1, 3) << "\n";
  }
}
1036_F. Relatively Prime Powers

Consider some positive integer x. Its prime factorization will be of form x = 2^{k_1} ⋅ 3^{k_2} ⋅ 5^{k_3} ⋅ ...

Let's call x elegant if the greatest common divisor of the sequence k_1, k_2, ... is equal to 1. For example, numbers 5 = 5^1, 12 = 2^2 ⋅ 3, 72 = 2^3 ⋅ 3^2 are elegant and numbers 8 = 2^3 (GCD = 3), 2500 = 2^2 ⋅ 5^4 (GCD = 2) are not.

Count the number of elegant integers from 2 to n.

Each testcase contains several values of n, for each of them you are required to solve the problem separately.

Input

The first line contains a single integer T (1 ≤ T ≤ 10^5) — the number of values of n in the testcase.

Each of the next T lines contains a single integer n_i (2 ≤ n_i ≤ 10^{18}).

Output

Print T lines — the i-th line should contain the number of elegant numbers from 2 to n_i.

Example

Input

4
4
2
72
10


Output

2
1
61
6

Note

Here is the list of non-elegant numbers up to 10:

  * 4 = 2^2, GCD = 2; 
  * 8 = 2^3, GCD = 3; 
  * 9 = 3^2, GCD = 2. 



The rest have GCD = 1.

Example input:
4
4
2
72
10


Example output:
                                                               2
                                                               1
                                                              61
                                                               6


Tags: combinatorics
math
number theory
Difficulty rating: 2400

Solution:
#include <bits/stdc++.h>
using namespace std;
int T, mu[99];
long long n, ans;
long long gen(long long n, long long k) {
  long long t = powl(n, 1. / k) - 0.5;
  return t + (powl(t + 1, k) - 0.5 <= n);
}
int main() {
  for (int i = 2; i < 60; ++i) {
    mu[i] = -1 - mu[i];
    for (int j = i + i; j < 60; j += i) mu[j] += mu[i];
  }
  for (cin >> T; T--;) {
    cin >> n;
    ans = n - 1;
    for (int i = 2; i < 60; ++i) ans += mu[i] * (gen(n, i) - 1);
    cout << ans << endl;
  }
}