JerryL/AlgoSimBench huggingface dataset:
1526_D. Kill Anton

After rejecting 10^{100} data structure problems, Errorgorn is very angry at Anton and decided to kill him.

Anton's DNA can be represented as a string a which only contains the characters "ANTON" (there are only 4 distinct characters). 

Errorgorn can change Anton's DNA into string b which must be a permutation of a. However, Anton's body can defend against this attack. In 1 second, his body can swap 2 adjacent characters of his DNA to transform it back to a. Anton's body is smart and will use the minimum number of moves.

To maximize the chance of Anton dying, Errorgorn wants to change Anton's DNA the string that maximizes the time for Anton's body to revert his DNA. But since Errorgorn is busy making more data structure problems, he needs your help to find the best string B. Can you help him?

Input

The first line of input contains a single integer t (1 ≤ t ≤ 100000) — the number of testcases.

The first and only line of each testcase contains 1 string a (1 ≤ |a| ≤ 100000). a consists of only the characters "A", "N", "O" and "T".

It is guaranteed that the sum of |a| over all testcases does not exceed 100000.

Output

For each testcase, print a single string, b. If there are multiple answers, you can output any one of them. b must be a permutation of the string a.

Example

Input


4
ANTON
NAAN
AAAAAA
OAANTTON


Output


NNOTA
AANN
AAAAAA
TNNTAOOA

Note

For the first testcase, it takes 7 seconds for Anton's body to transform NNOTA to ANTON: 

NNOTA → NNOAT → NNAOT → NANOT → NANTO → ANNTO → ANTNO → ANTON. 

Note that you cannot output strings such as AANTON, ANTONTRYGUB, AAAAA and anton as it is not a permutation of ANTON.

For the second testcase, it takes 2 seconds for Anton's body to transform AANN to NAAN. Note that other strings such as NNAA and ANNA will also be accepted.

Example input:
4
ANTON
NAAN
AAAAAA
OAANTTON


Example output:

NNOTA
AANN
AAAAAA
TNNTAOOA


Tags: brute force
constructive algorithms
data structures
math
strings
Difficulty rating: 2200

Solution:
import itertools
m={"A":0,"N":1,"O":2,"T":3};st="ANOT"
for _ in range(int(input())):
	s=input();arr=[m[ch] for ch in s];cnt=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]];cnt1=[0,0,0,0];val=-1;best=[]
	for i in arr:
		for j in range(4):cnt[j][i]+=cnt1[j]
		cnt1[i]+=1
	for perm in itertools.permutations([0,1,2,3]):
		curr=sum([cnt[perm[j]][perm[i]] for i in range(4) for j in range(i+1,4)])
		if (curr>val):val=curr;best=perm
	for i in range(4):
		for j in range(cnt1[best[i]]): print(st[best[i]],end="")
	print()
1527_D. MEX Tree

You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node labels in the shortest path from u to v (including end points) is k.

The MEX of a sequence of integers is the smallest non-negative integer that does not belong to the sequence.

Input

The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases. 

The first line of each test case contains a single integer n (2 ≤ n ≤ 2 ⋅ 10^{5}).

The next n-1 lines of each test case describe the tree that has to be constructed. These lines contain two integers u and v (0 ≤ u,v ≤ n-1) denoting an edge between u and v (u ≠ v).

It is guaranteed that the given edges form a tree.

It is also guaranteed that the sum of n for all test cases does not exceed 2 ⋅ 10^{5}.

Output

For each test case, print n+1 integers: the number of paths in the tree, such that the MEX of all the node labels in that path is k for each k from 0 to n.

Example

Input


2
4
0 1
0 2
2 3
2
1 0


Output


1 2 1 1 1 
0 0 1 

Note

  1. In example case 1, <image>
    * For k = 0, there is 1 path that is from 2 to 3 as MEX([2, 3]) = 0. 
    * For k = 1, there are 2 paths that is from 0 to 2 as MEX([0, 2]) = 1 and 0 to 3 as MEX([0, 2, 3]) = 1. 
    * For k = 2, there is 1 path that is from 0 to 1 as MEX([0, 1]) = 2. 
    * For k = 3, there is 1 path that is from 1 to 2 as MEX([1, 0, 2]) = 3 
    * For k = 4, there is 1 path that is from 1 to 3 as MEX([1, 0, 2, 3]) = 4. 
  2. In example case 2, <image>
    * For k = 0, there are no such paths. 
    * For k = 1, there are no such paths. 
    * For k = 2, there is 1 path that is from 0 to 1 as MEX([0, 1]) = 2. 

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


Example output:

1 2 1 1 1 
0 0 1 


Tags: combinatorics
dfs and similar
implementation
math
trees
Difficulty rating: 2400

Solution:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5+10;
const ll mod = 998244353;
int n;
int h[N],e[2*N],ne[2*N],idx,f[N],c[N];
ll size[N],ans[N];
void add(int a,int b)
{
	e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
void dfs(int u) 
{
	size[u]=1;
	for(int i=h[u];i!=-1;i=ne[i])
	{
		int v=e[i];
		if(f[u]==v) continue;
		f[v]=u;
		dfs(v);
		size[u]+=size[v];
	}
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		memset(h,-1,sizeof(h));
		idx=0;
		scanf("%d",&n);
		int a,b;
		for(int i=1;i<n;i++)
		{
			scanf("%d%d",&a,&b);
			add(a,b),add(b,a);//连边 
		}
		dfs(0);//以 0为根，求得子树的顶点数 size 
		ans[0]=1LL*n*(n-1)/2;//所有路径 
		ll sum=1;
		for(int i=h[0];i!=-1;i=ne[i])
		{
			int v=e[i];
			ans[1]+=sum*size[v];//ans[1]是包含0的所有路径 
			sum+=size[v];
		}
		a=0,b=0,c[0]=1;
		int p,x;
		for(int i=1;i<n;i++)
		{
			if(!c[i])
			{
				x=p=i;
				while(!c[x]) c[x]=1,p=x,x=f[x];
				if(x==a)
				{
					size[a]-=size[p];
					a=i;
				}
				else if(x==b)
				{
					size[b]-=size[p];
					b=i;
				}
				else break;
			}
			ans[i+1]=size[a]*size[b];
		}
		for(int i=0;i<=n;i++)
		{
			printf("%lld ",ans[i]-ans[i+1]);
		}
		printf("\n");
		for(int i=0;i<=n;i++)
		{
			size[i]=ans[i]=f[i]=c[i]=0;
		}
	} 
	return 0;
}
1555_E. Boring Segments

You are given n segments on a number line, numbered from 1 to n. The i-th segments covers all integer points from l_i to r_i and has a value w_i.

You are asked to select a subset of these segments (possibly, all of them). Once the subset is selected, it's possible to travel between two integer points if there exists a selected segment that covers both of them. A subset is good if it's possible to reach point m starting from point 1 in arbitrary number of moves.

The cost of the subset is the difference between the maximum and the minimum values of segments in it. Find the minimum cost of a good subset.

In every test there exists at least one good subset.

Input

The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5; 2 ≤ m ≤ 10^6) — the number of segments and the number of integer points.

Each of the next n lines contains three integers l_i, r_i and w_i (1 ≤ l_i < r_i ≤ m; 1 ≤ w_i ≤ 10^6) — the description of the i-th segment.

In every test there exists at least one good subset.

Output

Print a single integer — the minimum cost of a good subset.

Examples

Input


5 12
1 5 5
3 4 10
4 10 6
11 12 5
10 12 3


Output


3


Input


1 10
1 10 23


Output


0

Example input:
1 10
1 10 23

5 12
1 5 5
3 4 10
4 10 6
11 12 5
10 12 3


Example output:
0

3


Tags: data structures
sortings
trees
two pointers
Difficulty rating: 2100

Solution:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int seg[maxn << 2], laz[maxn << 2], ord[maxn], le[maxn], ri[maxn], we[maxn];
int n, m;
void add(int val, int st, int en, int l = 0, int r = m, int id = 1) {
  if (st >= r or en <= l) return;
  if (st <= l and r <= en) {
    seg[id] += val;
    laz[id] += val;
    return;
  }
  int mid = (l + r) >> 1;
  add(val, st, en, l, mid, id << 1 | 0);
  add(val, st, en, mid, r, id << 1 | 1);
  seg[id] = min(seg[id << 1 | 0], seg[id << 1 | 1]) + laz[id];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  m--;
  for (int i = 0; i < n; i++) {
    cin >> le[i] >> ri[i] >> we[i];
    le[i]--, ri[i]--;
  }
  iota(ord, ord + n, 0);
  sort(ord, ord + n, [](int i, int j) -> bool { return we[i] < we[j]; });
  int ans = 1e6;
  int ptr = 0;
  for (int i = 0; i < n; i++) {
    add(+1, le[ord[i]], ri[ord[i]]);
    while (seg[1] > 0 and ptr <= i) {
      add(-1, le[ord[ptr]], ri[ord[ptr]]);
      ptr++;
    }
    if (ptr - 1 >= 0) (ans) = min((ans), (we[ord[i]] - we[ord[ptr - 1]]));
  }
  cout << ans << '\n';
  return 0;
}
1559_D1. Mocha and Diana (Easy Version)

This is the easy version of the problem. The only difference between the two versions is the constraint on n. You can make hacks only if all versions of the problem are solved.

A forest is an undirected graph without cycles (not necessarily connected).

Mocha and Diana are friends in Zhijiang, both of them have a forest with nodes numbered from 1 to n, and they would like to add edges to their forests such that: 

  * After adding edges, both of their graphs are still forests. 
  * They add the same edges. That is, if an edge (u, v) is added to Mocha's forest, then an edge (u, v) is added to Diana's forest, and vice versa. 



Mocha and Diana want to know the maximum number of edges they can add, and which edges to add.

Input

The first line contains three integers n, m_1 and m_2 (1 ≤ n ≤ 1000, 0 ≤ m_1, m_2 < n) — the number of nodes and the number of initial edges in Mocha's forest and Diana's forest.

Each of the next m_1 lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the edges in Mocha's forest.

Each of the next m_2 lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the edges in Diana's forest.

Output

The first line contains only one integer h, the maximum number of edges Mocha and Diana can add (in each forest).

Each of the next h lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the edge you add each time.

If there are multiple correct answers, you can print any one of them.

Examples

Input


3 2 2
1 2
2 3
1 2
1 3


Output


0


Input


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


Output


1
2 4


Input


8 1 2
1 7
2 6
1 5


Output


5
5 2
2 3
3 4
4 7
6 8

Note

In the first example, we cannot add any edge.

In the second example, the initial forests are as follows.

<image>

We can add an edge (2, 4).

<image>

Example input:
8 1 2
1 7
2 6
1 5

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

3 2 2
1 2
2 3
1 2
1 3


Example output:
5
1 2
1 3
1 4
1 8
5 7

1
1 5

0


Tags: brute force
constructive algorithms
dsu
graphs
greedy
trees
Difficulty rating: 1400

Solution:
def getp(p, v):
	if p[v] == v:return v
	p[v] = getp(p, p[v]);return p[v]
def solve():
	n, m1, m2 = map(int, input().split());p1 = list(range(n + 1));p2 = list(range(n + 1));r = []
	for i in range(m1):u, v = map(int, input().split());u = getp(p1, u);v = getp(p1, v);p1[u] = v
	for i in range(m2):u, v = map(int, input().split());u = getp(p2, u);v = getp(p2, v);p2[u] = v
	for i in range(1, n + 1):
		for j in range(1, i):
			u = getp(p1, i);v = getp(p1, j)
			if u != v:
				x = getp(p2, i);y = getp(p2, j)
				if x != y:p1[u] = v;p2[x] = y;r.append((i, j))
	print(len(r))
	for u, v in r:print(u, v)
solve()
1561_D2. Up the Strip

Note that the memory limit in this problem is lower than in others.

You have a vertical strip with n cells, numbered consecutively from 1 to n from top to bottom.

You also have a token that is initially placed in cell n. You will move the token up until it arrives at cell 1.

Let the token be in cell x > 1 at some moment. One shift of the token can have either of the following kinds: 

  * Subtraction: you choose an integer y between 1 and x-1, inclusive, and move the token from cell x to cell x - y. 
  * Floored division: you choose an integer z between 2 and x, inclusive, and move the token from cell x to cell ⌊ x/z ⌋ (x divided by z rounded down). 



Find the number of ways to move the token from cell n to cell 1 using one or more shifts, and print it modulo m. Note that if there are several ways to move the token from one cell to another in one shift, all these ways are considered distinct (check example explanation for a better understanding).

Input

The only line contains two integers n and m (2 ≤ n ≤ 4 ⋅ 10^6; 10^8 < m < 10^9; m is a prime number) — the length of the strip and the modulo.

Output

Print the number of ways to move the token from cell n to cell 1, modulo m.

Examples

Input


3 998244353


Output


5


Input


5 998244353


Output


25


Input


42 998244353


Output


793019428


Input


787788 100000007


Output


94810539

Note

In the first test, there are three ways to move the token from cell 3 to cell 1 in one shift: using subtraction of y = 2, or using division by z = 2 or z = 3.

There are also two ways to move the token from cell 3 to cell 1 via cell 2: first subtract y = 1, and then either subtract y = 1 again or divide by z = 2.

Therefore, there are five ways in total.

Example input:
3 998244353

42 998244353

787788 100000007

5 998244353


Example output:
5
793019428
94810539
25

Tags: brute force
dp
math
number theory
Difficulty rating: 1900

Solution:
n, m = map(int, input().split())
c = [0]*n + [1] + [0]*n
for i in range(n-1, 0, -1):
    c[i] = 2*c[i+1] % m
    for j in range(2, n//i + 1):
        c[i] = (c[i] + c[i*j] - c[(i+1)*j]) % m

print((c[1] - c[2]) % m)
1603_F. October 18, 2017

It was October 18, 2017. Shohag, a melancholic soul, made a strong determination that he will pursue Competitive Programming seriously, by heart, because he found it fascinating. Fast forward to 4 years, he is happy that he took this road. He is now creating a contest on Codeforces. He found an astounding problem but has no idea how to solve this. Help him to solve the final problem of the round.

You are given three integers n, k and x. Find the number, modulo 998 244 353, of integer sequences a_1, a_2, …, a_n such that the following conditions are satisfied: 

  * 0 ≤ a_i < 2^k for each integer i from 1 to n. 
  * There is no non-empty subsequence in a such that the [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of the elements of the subsequence is x. 



A sequence b is a subsequence of a sequence c if b can be obtained from c by deletion of several (possibly, zero or all) elements.

Input

The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.

The first and only line of each test case contains three space-separated integers n, k, and x (1 ≤ n ≤ 10^9, 0 ≤ k ≤ 10^7, 0 ≤ x < 2^{\operatorname{min}(20, k)}).

It is guaranteed that the sum of k over all test cases does not exceed 5 ⋅ 10^7.

Output

For each test case, print a single integer — the answer to the problem.

Example

Input


6
2 2 0
2 1 1
3 2 3
69 69 69
2017 10 18
5 7 0


Output


6
1
15
699496932
892852568
713939942

Note

In the first test case, the valid sequences are [1, 2], [1, 3], [2, 1], [2, 3], [3, 1] and [3, 2].

In the second test case, the only valid sequence is [0, 0].

Example input:
6
2 2 0
2 1 1
3 2 3
69 69 69
2017 10 18
5 7 0


Example output:
6
1
15
699496932
892852568
713939942


Tags: combinatorics
dp
implementation
math
Difficulty rating: 2700

Solution:
#include <bits/stdc++.h>
const long long MOD = 998244353;
int T, n, k, x, pow2[10000005], pw[10000005], ans;
int power(int A, int B) {
  int res = 1;
  while (B) {
    if (B & 1) res = 1ll * res * A % MOD;
    B >>= 1;
    A = 1ll * A * A % MOD;
  }
  return res;
}
signed main() {
  std::ios::sync_with_stdio(false);
  pow2[0] = pw[0] = 1;
  for (int i = 1; i <= 10000000; ++i) pow2[i] = pow2[i - 1] * 2 % MOD;
  std::cin >> T;
  while (T--) {
    std::cin >> n >> k >> x;
    if (x == 0) {
      ans = 1;
      if (n > k)
        ans = 0;
      else
        for (int i = 0; i != n; ++i)
          ans = ans * (pow2[k] - pow2[i] + MOD) % MOD;
      std::cout << ans << std::endl;
    } else {
      ans = 0;
      pw[1] = power(2, n);
      for (int i = 1; i <= k; ++i) pw[i] = 1ll * pw[i - 1] * pw[1] % MOD;
      for (int i = 1, sum = 1; i <= k; ++i) {
        ans = (ans + (i & 1 ? 1 : MOD - 1) * pw[k - i] % MOD * sum % MOD *
                         pow2[k - i]) %
              MOD;
        sum = sum * (pow2[k - i] - 1ll) % MOD;
      }
      std::cout << ans << std::endl;
    }
  }
  return 0;
}
1613_F. Tree Coloring

You are given a rooted tree consisting of n vertices numbered from 1 to n. The root of the tree is the vertex 1.

You have to color all vertices of the tree into n colors (also numbered from 1 to n) so that there is exactly one vertex for each color. Let c_i be the color of vertex i, and p_i be the parent of vertex i in the rooted tree. The coloring is considered beautiful if there is no vertex k (k > 1) such that c_k = c_{p_k} - 1, i. e. no vertex such that its color is less than the color of its parent by exactly 1.

Calculate the number of beautiful colorings, and print it modulo 998244353.

Input

The first line contains one integer n (2 ≤ n ≤ 250000) — the number of vertices in the tree.

Then n-1 lines follow, the i-th line contains two integers x_i and y_i (1 ≤ x_i, y_i ≤ n; x_i ≠ y_i) denoting an edge between the vertex x_i and the vertex y_i. These edges form a tree.

Output

Print one integer — the number of beautiful colorings, taken modulo 998244353.

Examples

Input


5
1 2
3 2
4 2
2 5


Output


42


Input


5
1 2
2 3
3 4
4 5


Output


53


Input


20
20 19
20 4
12 4
5 8
1 2
20 7
3 10
7 18
11 8
9 10
17 10
1 15
11 16
14 11
18 10
10 1
14 2
13 17
20 6


Output


955085064

Example input:
5
1 2
2 3
3 4
4 5

20
20 19
20 4
12 4
5 8
1 2
20 7
3 10
7 18
11 8
9 10
17 10
1 15
11 16
14 11
18 10
10 1
14 2
13 17
20 6

5
1 2
3 2
4 2
2 5


Example output:
53
955085064
42

Tags: combinatorics
divide and conquer
fft
Difficulty rating: 2600

Solution:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2.5e5 + 5, P = 998244353;
int n, d[N], lim, bit, rev[1 << 18];
ll Pow(ll a, int n, ll r = 1) {
  for (; n; n >>= 1, a = a * a % P)
    if (n & 1) r = r * a % P;
  return r;
}
void NTT(vector<ll>& a, int t) {
  if (t) reverse(a.begin() + 1, a.end());
  for (int i = (0), ie = (lim); i < ie; i++)
    if (rev[i] < i) swap(a[i], a[rev[i]]);
  for (int i = 1; i < lim; i <<= 1) {
    ll wn = Pow(3, P / 2 / i);
    for (int j = 0; j < lim; j += i << 1) {
      ll w = 1;
      for (int k = (j), ke = (j + i); k < ke; k++) {
        ll &x = a[k], y = a[k + i] * w % P;
        a[k + i] = (x - y) % P, (x += y) %= P, w = w * wn % P;
      }
    }
  }
  ll inv = Pow(lim, P - 2);
  if (t)
    for (int i = (0), ie = (lim); i < ie; i++) (a[i] *= inv) %= P;
}
vector<ll> solve(int l, int r) {
  if (l == r) {
    vector<ll> res(2);
    res[0] = 1, res[1] = d[l];
    return res;
  }
  int mid = l + r >> 1;
  auto &&L = solve(l, mid), &&R = solve(mid + 1, r);
  for (lim = 1, bit = -1; lim <= r - l + 1; lim <<= 1, bit++)
    ;
  for (int i = (1), ie = (lim); i < ie; i++)
    rev[i] = rev[i >> 1] >> 1 | (i & 1) << bit;
  L.resize(lim), R.resize(lim);
  NTT(L, 0), NTT(R, 0);
  for (int i = (0), ie = (lim); i < ie; i++) (L[i] *= R[i]) %= P;
  NTT(L, 1);
  return L;
}
int main() {
  cin >> n;
  int u, v;
  for (int i = (2); i <= (n); i++)
    d[i]--, scanf("%d%d", &u, &v), d[u]++, d[v]++;
  auto&& res = solve(1, n);
  ll ans = 0, fac = 1;
  for (int i = (1); i <= (n); i++)
    (fac *= i) %= P, (ans += (n - i & 1 ? -1 : 1) * fac * res[n - i]) %= P;
  cout << (ans + P) % P;
}
1620_G. Subsequences Galore

For a sequence of strings [t_1, t_2, ..., t_m], let's define the function f([t_1, t_2, ..., t_m]) as the number of different strings (including the empty string) that are subsequences of at least one string t_i. f([]) = 0 (i. e. the number of such strings for an empty sequence is 0).

You are given a sequence of strings [s_1, s_2, ..., s_n]. Every string in this sequence consists of lowercase Latin letters and is sorted (i. e., each string begins with several (maybe zero) characters a, then several (maybe zero) characters b, ..., ends with several (maybe zero) characters z).

For each of 2^n subsequences of [s_1, s_2, ..., s_n], calculate the value of the function f modulo 998244353.

Input

The first line contains one integer n (1 ≤ n ≤ 23) — the number of strings.

Then n lines follow. The i-th line contains the string s_i (1 ≤ |s_i| ≤ 2 ⋅ 10^4), consisting of lowercase Latin letters. Each string s_i is sorted.

Output

Since printing up to 2^{23} integers would be really slow, you should do the following:

For each of the 2^n subsequences (which we denote as [s_{i_1}, s_{i_2}, ..., s_{i_k}]), calculate f([s_{i_1}, s_{i_2}, ..., s_{i_k}]), take it modulo 998244353, then multiply it by k ⋅ (i_1 + i_2 + ... + i_k). Print the XOR of all 2^n integers you get.

The indices i_1, i_2, ..., i_k in the description of each subsequences are 1-indexed (i. e. are from 1 to n).

Examples

Input


3
a
b
c


Output


92


Input


2
aa
a


Output


21


Input


2
a
a


Output


10


Input


2
abcd
aabb


Output


124


Input


3
ddd
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaabbbbbbbbbbbcccccccccccciiiiiiiiiiiiiiiiiiiiiiooooooooooqqqqqqqqqqqqqqqqqqvvvvvzzzzzzzzzzzz


Output


15706243380

Example input:
2
a
a

3
ddd
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaabbbbbbbbbbbcccccccccccciiiiiiiiiiiiiiiiiiiiiiooooooooooqqqqqqqqqqqqqqqqqqvvvvvzzzzzzzzzzzz

2
aa
a

3
a
b
c

2
abcd
aabb


Example output:
10
15706243380
21
92
124

Tags: bitmasks
combinatorics
dp
Difficulty rating: 2400

Solution:
#include <bits/stdc++.h>
using namespace std;
int n;
char s[20010];
int cnt[25][30];
long long f[1 << 23];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    for (int j = 0; s[j]; j++) cnt[i][s[j] - 'a']++;
  }
  for (int i = 1; i < (1 << n); i++) {
    f[i] = 1;
    for (int j = 0; j < 26; j++) {
      int mn = 1e9;
      for (int k = 0; k < n; k++)
        if (i >> k & 1) mn = min(mn, cnt[k][j]);
      f[i] = f[i] * (mn + 1) % 998244353;
    }
    f[i] = -f[i];
    for (int j = 0; j < n; j++)
      if (i >> j & 1) f[i] = -f[i];
    f[i] = (f[i] + 998244353) % 998244353;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < (1 << n); j++)
      if (j >> i & 1) f[j] = (f[j] + f[j ^ (1 << i)]) % 998244353;
  long long ans = 0;
  for (int i = 1; i < (1 << n); i++) {
    int x = 0, y = 0;
    for (int j = 0; j < n; j++)
      if (i >> j & 1) x++, y += j + 1;
    ans ^= f[i] * x * y;
  }
  printf("%lld\n", ans);
  return 0;
}
1622_F. Quadratic Set

Let's call a set of positive integers a_1, a_2, ..., a_k quadratic if the product of the factorials of its elements is a square of an integer, i. e. ∏_{i=1}^{k} a_i! = m^2, for some integer m.

You are given a positive integer n.

Your task is to find a quadratic subset of a set 1, 2, ..., n of maximum size. If there are multiple answers, print any of them.

Input

A single line contains a single integer n (1 ≤ n ≤ 10^6).

Output

In the first line, print a single integer — the size of the maximum subset. In the second line, print the subset itself in an arbitrary order.

Examples

Input


1


Output


1
1 


Input


4


Output


3
1 3 4 


Input


7


Output


4
1 4 5 6 


Input


9


Output


7
1 2 4 5 6 7 9 

Example input:
9

7

1

4


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

Tags: constructive algorithms
hashing
math
number theory
Difficulty rating: 2900

Solution:
def T(n):
    return int(n**0.5)**2 == n

def solve(n):
    if n % 4 == 0: return [n//2]
    if n == 1: return []
    if n % 4 == 1: return [n//2, n]
    if n % 4 == 2:
        if T(n + 2): return [n//2 + 1]
        if T(n * (n//2 - 1)): return [n//2 - 2]
        return [n//2, 2]
    else:
        if T(n + 1): return [n//2 + 1, n]
        if T(2*(n//2)*(n//2 - 1)): return [n, n//2 - 2]
        if T((n//2-1) * n): return [n//2 - 2, n-2]
        return [2, n//2, n]

if __name__ == '__main__':
    n = int(input())
    arr = solve(n)
    ans = [i for i in range(1, n+1) if i not in arr]
    print(len(ans))
    print(" ".join(str(i) for i in ans))