A. EhAb AnD gCd

You are given a positive integer xx. Find any such 22 positive integers aa and bb such that GCD(a,b)+LCM(a,b)=xGCD(a,b)+LCM(a,b)=x.
As a reminder, GCD(a,b)GCD(a,b) is the greatest integer that divides both aa and bb. Similarly, LCM(a,b)LCM(a,b) is the smallest integer such that both aa and bb divide it.
It’s guaranteed that the solution always exists. If there are several such pairs (a,b)(a,b), you can output any of them.

Input

The first line contains a single integer t(1t100)t (1≤t≤100) — the number of testcases.
Each testcase consists of one line containing a single integer, x(2x109)x (2≤x≤10^9).

Output

For each testcase, output a pair of positive integers aa and bb (1a,b109)(1≤a,b≤10^9) such that GCD(a,b)+LCM(a,b)=xGCD(a,b)+LCM(a,b)=x. It’s guaranteed that the solution always exists. If there are several such pairs (a,b)(a,b), you can output any of them.

Example

input

2
2
14

output

1 1
6 4

Note

In the first testcase of the sample, GCD(1,1)+LCM(1,1)=1+1=2GCD(1,1)+LCM(1,1)=1+1=2.
In the second testcase of the sample, GCD(6,4)+LCM(6,4)=2+12=14GCD(6,4)+LCM(6,4)=2+12=14.

Translation

给一个数xx,任意输出一个数对(a,b)(a,b),满足GCD(a,b)+LCM(a,b)=xGCD(a,b)+LCM(a,b)=x

Idea

如官方题解所说:“11 and n1n-1 always work.”

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream>
using namespace std;
void solve()
{
int n;
cin>>n;
cout<<1<<' '<<n-1<<endl;
}
int main()
{
int t;
cin>>t;
while(t--) solve();
return 0;
}

Postscript

有时候只需要灵机一动。

B. CopyCopyCopyCopyCopy

Ehab has an array aa of length nn. He has just enough free time to make a new array consisting of nn copies of the old array, written back-to-back. What will be the length of the new array’s longest increasing subsequence?
A sequence aa is a subsequence of an array bb if aa can be obtained from bb by deletion of several (possibly, zero or all) elements. The longest increasing subsequence of an array is the longest subsequence such that its elements are ordered in strictly increasing order.

Input

The first line contains an integer tt — the number of test cases you need to solve. The description of the test cases follows.
The first line of each test case contains an integer nn (1n105)(1≤n≤10^5) — the number of elements in the array aa.
The second line contains n space-separated integers a1,a2,,ana_1, a_2,\dots, a_n$ (1≤a_i≤10^9)$ — the elements of the array aa.
The sum of nn across the test cases doesn’t exceed 10510^5.

Output

For each testcase, output the length of the longest increasing subsequence of a if you concatenate it to itself nn times.

Example

input

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

output

3
5

Note

In the first sample, the new array is [3,2,1,3,2,1,3,2,1][3,2,1,3,2,1,3,2,1]. The longest increasing subsequence is marked in bold.
In the second sample, the longest increasing subsequence will be [1,3,4,5,9][1,3,4,5,9].

Translation

给一个数列{an}\{a_n\},将该数列复制n1n-1次,依次拼接到{an}\{a_n\}的尾部。得到新数列{an×n}\{a_{n\times n}\},问{an×n}\{a_{n\times n}\}最长严格上升子序列的长度。

Idea

观察样例,能够猜到答案就是数列{an}\{a_n\}中数字的种类数dd
下面给出证明:
将这dd个不重复的数字从大到小排序,我们可以从原数列中拿出第一个,从第一个复制数列中拿出第二个……从第d1d-1个复制数列中拿出第dd个。由于dnd\leqslant n恒成立,必能找到一个长度为dd的严格上升子序列。假设存在比dd更长的严格上升子序列,那么原数列中数字的种类数大于dd,矛盾。所以答案就是原数列中数字的种类数,证毕。
代码实现就是用STLSTL中的setset存一下。

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
#include<set>
using namespace std;
void solve()
{
int n;
cin>>n;
set<int>ex;
int i;
for(i=1;i<=n;i++)
{
int temp;
cin>>temp;
ex.insert(temp);
}
cout<<ex.size()<<endl;
}
int main()
{
int t;
cin>>t;
while(t--) solve();
return 0;
}

Postscript

大胆假设,小心求证。

C. Ehab and Path-etic MEXs

You are given a tree consisting of nn nodes. You want to write some labels on the tree’s edges such that the following conditions hold:

  • Every label is an integer between 00 and n2n−2 inclusive.
  • All the written labels are distinct.
  • The largest value among MEX(u,v)MEX(u,v) over all pairs of nodes (u,v)(u,v) is as small as possible.

Here, MEX(u,v)MEX(u,v) denotes the smallest non-negative integer that isn’t written on any edge on the unique simple path from node uu to node vv.

Input

The first line contains the integer nn (2n105)(2≤n≤10^5) — the number of nodes in the tree.
Each of the next n1n−1 lines contains two space-separated integers uu and vv (1u,vn)(1≤u,v≤n) that mean there’s an edge between nodes uu and vv. It’s guaranteed that the given graph is a tree.

Output

Output n1n−1 integers. The ithi^{th} of them will be the number written on the ithi^{th} edge (in the input order).

Examples

input

3
1 2
1 3

output

0
1

input

6
1 2
1 3
2 4
2 5
5 6

output

0
3
2
4
1

Note

The tree from the second sample:

Translation

给一棵nn个顶点的树,将树的边从00n2n-2编号,使得任意两点(u,v)(u,v)MEX(u,v)MEX(u,v)最大值尽可能小。
MEX(u,v)MEX(u,v)(u,v)(u,v)之间的简单路径上不存在的最小非负边权。

Idea

先来理解一下MEX(u,v)MEX(u,v)。样例中MEX(1,5)=1,MEX(1,4)=0,MEX(1,6)=2MEX(1,5)=1,MEX(1,4)=0,MEX(1,6)=2
可以观察到,如果这棵树是一条链,那么无论怎么排,整条链的MEXMEX都为n1n-1;对于一颗正常的树,无论怎样给边赋值,总会有一条简单路径存在两条边权为0011的边;因此,我们的目标是使MEX(u,v)(u,v[1,n])MEX(u,v)(u,v\in [1,n])的最大值为22
对于一棵正常树,如果存在某一个节点度数大于等于33,选择其中三条边编号0,1,20,1,2。这样其他的路径一定不会同时经过0,1,20,1,2。而无论怎么排列,一定无法避免其中会有一条路径同时经过0,10,1。所以所有路径的MEXMEX的最大值一定为22;剩余的边随便排就可以了。

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
const int N=200005;
vector<int>G[N];//存图
map<pair<int,int>,int>id;//记录每一条边的编号
int ans[N];//存答案
void solve()
{
int n;
cin>>n;
memset(ans,-1,sizeof(ans));//初始化
int i;
for(i=1;i<=n-1;i++)
{
int u,v;
cin>>u>>v;
G[u].push_back(v);
G[v].push_back(u);
id[make_pair(u,v)]=i;//设置编号
}
int start=0;
for(i=1;i<=n;i++)
{
if(G[i].size()>=3)//找到度数大于等于3的点
{
int j;
for(j=0;j<G[i].size();j++)
{
//赋值0,1,2,多出来的点随意赋值
if(id.find(make_pair(i,G[i][j]))==id.end())
{
ans[id[make_pair(G[i][j],i)]]=j;
}
else ans[id[make_pair(i,G[i][j])]]=j;
}
start=G[i].size();//记录剩余的可使用数字
break;
}
}
for(i=1;i<=n-1;i++)
{
if(ans[i]==-1)//还未更新则赋值
{
ans[i]=start;
start++;
}
}
//输出
for(i=1;i<=n-1;i++) cout<<ans[i]<<endl;
}
int main()
{
solve();
return 0;
}

Postscript

思维题,多想,多看,多写,多画。

D. Ehab the Xorcist

Given 22 integers uu and vv, find the shortest array such that bitwise-xor of its elements is uu, and the sum of its elements is vv.

Input

The only line contains 22 integers uu and vv (0u,v1018)(0≤u,v≤10^{18}).

Output

If there’s no array that satisfies the condition, print “-1”. Otherwise:
The first line should contain one integer, nn, representing the length of the desired array. The next line should contain nn positive integers, the array itself. If there are multiple possible answers, print any.

Examples

input

2 4

output

2
3 1

input

1 3

output

3
1 1 1

input

8 5

output

-1

input

0 0

output

0

Note

In the first sample, 31=23⊕1=2 and 3+1=43+1=4. There is no valid array of smaller length.
Notice that in the fourth sample the array is empty.

Translation

给两个整数u,vu,v,找到一个最短的非负整数数列,使得数列的异或和为uu,加法和为vv
vv拆分,v=u+vu2+vu2v=u+\frac {v-u}{2}+ \frac {v-u}{2}。可以看到,当u>vu>v,无解;当u,vu,v奇偶性不同,无解。如果有解,当u=vu=v,时,我们需要特判一下;当uvu\ne v,一定可以找到一个含三个元素的数列[u,vu2,vu2]\left[u,\frac {v-u}{2},\frac {v-u}{2}\right],若满足u(vu2)=u+vu2u\oplus \left (\frac{v-u}{2} \right)=u+\frac{v-u}{2},则[u(vu2)](vu2)=(u+vu2)(vu2)\left[u\oplus \left (\frac{v-u}{2} \right)\right]\oplus\left(\frac{v-u}{2}\right)=\left(u+\frac{v-u}{2}\right)\oplus\left(\frac{v-u}{2}\right),则构造出了两个元素的数列[v+u2,vu2]\left[\frac{v+u}{2},\frac{v-u}{2}\right]

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<iostream>
using namespace std;
void solve()
{
long long u,v;
cin>>u>>v;
if(u>v) cout<<-1;
else if((u+v)&1) cout<<-1;
else
{
if(u==v)
{
if(!u) cout<<0;
else cout<<1<<endl<<u;
}
else
{
//可合并(加法和异或的效果相同)
if((u^(v-u>>1))==(v-u>>1)+u) cout<<2<<endl<<(v+u>>1)<<' '<<(v-u>>1);
//不可合并
else cout<<3<<endl<<u<<' '<<(v-u>>1)<<' '<<(v-u>>1);
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}

Postscript

需要灵机一动。注意不要爆int。