### Prompt

In cpp, your task is to solve the following problem:

The only difference between easy and hard versions is the maximum value of n.

You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.

The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).

For example:

  * 30 is a good number: 30 = 3^3 + 3^1,
  * 1 is a good number: 1 = 3^0,
  * 12 is a good number: 12 = 3^2 + 3^1,
  * but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
  * 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
  * 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).

Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.

For the given positive integer n find such smallest m (n ≤ m) that m is a good number.

You have to answer q independent queries.

Input

The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. Then q queries follow.

The only line of the query contains one integer n (1 ≤ n ≤ 10^4).

Output

For each query, print such smallest integer m (where n ≤ m) that m is a good number.

Example

Input

7
1
2
6
13
14
3620
10000

Output

1
3
9
13
27
6561
19683

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long f(long long n) {
  long long p = 0;
  while (n > 2) {
    p++;
    n /= 3;
  }
  return p;
}
long long f1(long long n) {
  long long a = 1, p = f(n);
  for (long long i = 0; i < p; i++) a = a * 3;
  if ((2 * n) > (3 * a))
    return 3 * a;
  else if (n == 0)
    return 0;
  return a + f1(n - a);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a = 1, n, p;
    cin >> n;
    p = f1(n);
    cout << p << endl;
  }
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

From beginning till end, this message has been waiting to be conveyed.

For a given unordered multiset of n lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation n - 1 times:

  * Remove any two elements s and t from the set, and add their concatenation s + t to the set.

The cost of such operation is defined to be <image>, where f(s, c) denotes the number of times character c appears in string s.

Given a non-negative integer k, construct any valid non-empty set of no more than 100 000 letters, such that the minimum accumulative cost of the whole process is exactly k. It can be shown that a solution always exists.

Input

The first and only line of input contains a non-negative integer k (0 ≤ k ≤ 100 000) — the required minimum cost.

Output

Output a non-empty string of no more than 100 000 lowercase English letters — any multiset satisfying the requirements, concatenated to be a string.

Note that the printed string doesn't need to be the final concatenated string. It only needs to represent an unordered multiset of letters.

Examples

Input

12

Output

abababab

Input

3

Output

codeforces

Note

For the multiset {'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b'}, one of the ways to complete the process is as follows:

  * {"ab", "a", "b", "a", "b", "a", "b"}, with a cost of 0;
  * {"aba", "b", "a", "b", "a", "b"}, with a cost of 1;
  * {"abab", "a", "b", "a", "b"}, with a cost of 1;
  * {"abab", "ab", "a", "b"}, with a cost of 0;
  * {"abab", "aba", "b"}, with a cost of 1;
  * {"abab", "abab"}, with a cost of 1;
  * {"abababab"}, with a cost of 8.

The total cost is 12, and it can be proved to be the minimum cost of the process.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e3 + 10;
const long long INF = 1e8;
const long long MOD = 1e9 + 7;
int main() {
  int n, i, j, k, l, p, q, x, y;
  vector<int> a, c;
  for (i = 1; i <= 500; i++) {
    a.push_back((i * (i + 1)) / 2);
    c.push_back(i + 1);
  }
  cin >> n;
  if (n == 0) {
    cout << 'a';
    return 0;
  }
  vector<char> b;
  i = 0;
  while (n) {
    l = lower_bound(a.begin(), a.end(), n) - a.begin();
    k = a[l];
    if (n != k) {
      p = c[l - 1];
      k = a[l - 1];
      for (j = 0; j < p; j++) b.push_back(char(97 + i));
      n = n - k;
    } else {
      p = c[l];
      for (j = 0; j < p; j++) b.push_back(char(97 + i));
      n = n - k;
    }
    i++;
  }
  for (auto t : b) cout << t;
}

```


### Prompt

Your challenge is to write a cpp solution to the following problem:

Andrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends Andrew multiple queries of type "di → ti", that means "replace all digits di in string s with substrings equal to ti". For example, if s = 123123, then query "2 → 00" transforms s to 10031003, and query "3 → " ("replace 3 by an empty string") transforms it to s = 1212. After all the queries Eugene asks Andrew to find the remainder after division of number with decimal representation equal to s by 1000000007 (109 + 7). When you represent s as a decimal number, please ignore the leading zeroes; also if s is an empty string, then it's assumed that the number equals to zero.

Andrew got tired of processing Eugene's requests manually and he asked you to write a program for that. Help him!

Input

The first line contains string s (1 ≤ |s| ≤ 105), consisting of digits — the string before processing all the requests.

The second line contains a single integer n (0 ≤ n ≤ 105) — the number of queries.

The next n lines contain the descriptions of the queries. The i-th query is described by string "di->ti", where di is exactly one digit (from 0 to 9), ti is a string consisting of digits (ti can be an empty string). The sum of lengths of ti for all queries doesn't exceed 105. The queries are written in the order in which they need to be performed.

Output

Print a single integer — remainder of division of the resulting number by 1000000007 (109 + 7).

Examples

Input

123123
1
2->00

Output

10031003

Input

123123
1
3->

Output

1212

Input

222
2
2->0
0->7

Output

777

Input

1000000008
0

Output

1

Note

Note that the leading zeroes are not removed from string s after the replacement (you can see it in the third sample).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char t;
int n, mod = 1e9 + 7;
pair<int, int> val[10];
string s;
pair<char, string> que[100005];
pair<int, int> calc(string x) {
  int v = 0, p = 1;
  for (int i = 0; i < x.size(); ++i) {
    int y = x[i] - '0';
    v = (1LL * val[y].second * v + val[y].first) % mod;
    p = (1LL * p * val[y].second) % mod;
  }
  return make_pair(v, p);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> s >> n;
  for (int i = 0; i < n; ++i) {
    cin >> que[i].first >> que[i].second;
    que[i].second = que[i].second.substr(2, que[i].second.size() - 2);
  }
  for (int i = 0; i < 10; ++i) {
    val[i].first = i;
    val[i].second = 10;
  }
  for (int i = n - 1; i >= 0; --i)
    val[que[i].first - '0'] = calc(que[i].second);
  cout << calc(s).first << '\n';
}

```


### Prompt

Please create a solution in Cpp to the following problem:

We have a string S consisting of lowercase English letters.

If the length of S is at most K, print S without change.

If the length of S exceeds K, extract the first K characters in S, append `...` to the end of them, and print the result.

Constraints

* K is an integer between 1 and 100 (inclusive).
* S is a string consisting of lowercase English letters.
* The length of S is between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

K
S

Output

Print a string as stated in Problem Statement.

Examples

Input

7
nikoandsolstice

Output

nikoand...

Input

40
ferelibenterhominesidquodvoluntcredunt

Output

ferelibenterhominesidquodvoluntcredunt

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int k;
	cin>>k>>s;

	if(s.size()>k){
	    cout<<s.substr(0,k)<<"..."<<endl;
	}else{
	    cout<<s<<endl;
	}
}

```


### Prompt

Create a solution in CPP for the following problem:

You are given an integer N. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and N, inclusive; there will be <image> of them.

You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis.

Find the minimal number of layers you have to use for the given N.

Input

The only input line contains a single integer N (1 ≤ N ≤ 100).

Output

Output a single integer - the minimal number of layers required to draw the segments for the given N.

Examples

Input

2

Output

2

Input

3

Output

4

Input

4

Output

6

Note

As an example, here are the segments and their optimal arrangement into layers for N = 4.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  cout << n * (n + 1) / 2 - (n * n) / 4 << endl;
  return 0;
}

```


### Prompt

Your task is to create a Cpp solution to the following problem:

Given is a string S consisting of `L` and `R`.

Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left.

The character written on the leftmost square is always `R`, and the character written on the rightmost square is always `L`.

Initially, one child is standing on each square.

Each child will perform the move below 10^{100} times:

* Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right.

Find the number of children standing on each square after the children performed the moves.

Constraints

* S is a string of length between 2 and 10^5 (inclusive).
* Each character of S is `L` or `R`.
* The first and last characters of S are `R` and `L`, respectively.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of children standing on each square after the children performed the moves, in order from left to right.

Examples

Input

RRLRL

Output

0 1 2 1 1

Input

RRLLLLRLRRLL

Output

0 3 3 0 0 0 1 1 0 2 2 0

Input

RRRLLRLLRRRLLLLL

Output

0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
#define M 100005
char dr[M];
int ans[M];
int main(){
	scanf("%s",dr+1);
	int n=strlen(dr+1);
	for(int i=n,pr;i>=1;--i){
		if(dr[i]=='L')pr=i;
		else ans[pr-((pr-i)&1)]++;
	}
	for(int i=1,pr;i<=n;++i){
		if(dr[i]=='R')pr=i;
		else ans[pr+((i-pr)&1)]++;
	}
	for(int i=1;i<=n;++i)printf("%d ",ans[i]);
}
```


### Prompt

Your task is to create a Cpp solution to the following problem:

Find the least common multiple (LCM) of given n integers.

Constraints

* 2 ≤ n ≤ 10
* 1 ≤ ai ≤ 1000
* Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1

Input

n
a1 a2 ... an

n is given in the first line. Then, n integers are given in the second line.

Output

Print the least common multiple of the given integers in a line.

Examples

Input

3
3 4 6

Output

12

Input

4
1 2 3 5

Output

30

### Response

```cpp
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int LCM(int m, int n) {
	int x = m*n;
	while (m%n != 0) {
		int temp = m%n;
		m = n; n = temp;
	}
	return x / n;
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> v(n);
	for (int i = 0;i < n; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end(), greater<int>());

	int Ans = v[0];
	for (int i = 1; i < n; i++) {
		Ans = LCM(Ans, v[i]);
	}
	cout << Ans << endl;
}
```


### Prompt

In cpp, your task is to solve the following problem:

Vasya has two arrays A and B of lengths n and m, respectively.

He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the array [1, 10, 100, 1000, 10000] Vasya can obtain array [1, 1110, 10000], and from array [1, 2, 3] Vasya can obtain array [6].

Two arrays A and B are considered equal if and only if they have the same length and for each valid i A_i = B_i.

Vasya wants to perform some of these operations on array A, some on array B, in such a way that arrays A and B become equal. Moreover, the lengths of the resulting arrays should be maximal possible.

Help Vasya to determine the maximum length of the arrays that he can achieve or output that it is impossible to make arrays A and B equal.

Input

The first line contains a single integer n~(1 ≤ n ≤ 3 ⋅ 10^5) — the length of the first array.

The second line contains n integers a_1, a_2, ⋅⋅⋅, a_n~(1 ≤ a_i ≤ 10^9) — elements of the array A.

The third line contains a single integer m~(1 ≤ m ≤ 3 ⋅ 10^5) — the length of the second array.

The fourth line contains m integers b_1, b_2, ⋅⋅⋅, b_m~(1 ≤ b_i ≤ 10^9) - elements of the array B.

Output

Print a single integer — the maximum length of the resulting arrays after some operations were performed on arrays A and B in such a way that they became equal.

If there is no way to make array equal, print "-1".

Examples

Input

5
11 2 3 5 7
4
11 7 3 7

Output

3

Input

2
1 2
1
100

Output

-1

Input

3
1 2 3
3
1 2 3

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n;
  vector<int> A(n);
  vector<long long> Asum(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &A[i]);
    if (i == 0)
      Asum[i] = A[i];
    else
      Asum[i] = Asum[i - 1] + A[i];
  }
  cin >> m;
  vector<int> B(m);
  vector<long long> Bsum(m);
  for (int i = 0; i < m; ++i) {
    scanf("%d", &B[i]);
    if (i == 0)
      Bsum[i] = B[i];
    else
      Bsum[i] = Bsum[i - 1] + B[i];
  }
  if (Asum[n - 1] != Bsum[m - 1]) {
    cout << "-1";
    return 0;
  }
  int i = 0, j = 0;
  int ans = 0;
  while (i < n || j < m) {
    if (Asum[i] < Bsum[j]) ++i;
    if (Asum[i] > Bsum[j]) ++j;
    if (Asum[i] == Bsum[j]) {
      ++ans;
      ++i;
      ++j;
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

You are given a deck of n cards numbered from 1 to n (not necessarily in this order in the deck). You have to sort the deck by repeating the following operation.

  * Choose 2 ≤ k ≤ n and split the deck in k nonempty contiguous parts D_1, D_2,..., D_k (D_1 contains the first |D_1| cards of the deck, D_2 contains the following |D_2| cards and so on). Then reverse the order of the parts, transforming the deck into D_k, D_{k-1}, ..., D_2, D_1 (so, the first |D_k| cards of the new deck are D_k, the following |D_{k-1}| cards are D_{k-1} and so on). The internal order of each packet of cards D_i is unchanged by the operation.

You have to obtain a sorted deck (i.e., a deck where the first card is 1, the second is 2 and so on) performing at most n operations. It can be proven that it is always possible to sort the deck performing at most n operations.

Examples of operation: The following are three examples of valid operations (on three decks with different sizes).

  * If the deck is [3 6 2 1 4 5 7] (so 3 is the first card and 7 is the last card), we may apply the operation with k=4 and D_1=[3 6], D_2=[2 1 4], D_3=[5], D_4=[7]. Doing so, the deck becomes [7 5 2 1 4 3 6].
  * If the deck is [3 1 2], we may apply the operation with k=3 and D_1=[3], D_2=[1], D_3=[2]. Doing so, the deck becomes [2 1 3].
  * If the deck is [5 1 2 4 3 6], we may apply the operation with k=2 and D_1=[5 1], D_2=[2 4 3 6]. Doing so, the deck becomes [2 4 3 6 5 1].

Input

The first line of the input contains one integer n (1≤ n≤ 52) — the number of cards in the deck.

The second line contains n integers c_1, c_2, ..., c_n — the cards in the deck. The first card is c_1, the second is c_2 and so on.

It is guaranteed that for all i=1,...,n there is exactly one j∈\{1,...,n\} such that c_j = i.

Output

On the first line, print the number q of operations you perform (it must hold 0≤ q≤ n).

Then, print q lines, each describing one operation.

To describe an operation, print on a single line the number k of parts you are going to split the deck in, followed by the size of the k parts: |D_1|, |D_2|, ... , |D_k|.

It must hold 2≤ k≤ n, and |D_i|≥ 1 for all i=1,...,k, and |D_1|+|D_2|+⋅⋅⋅ + |D_k| = n.

It can be proven that it is always possible to sort the deck performing at most n operations. If there are several ways to sort the deck you can output any of them.

Examples

Input

4
3 1 2 4

Output

2
3 1 2 1
2 1 3

Input

6
6 5 4 3 2 1

Output

1
6 1 1 1 1 1 1

Input

1
1

Output

0

Note

Explanation of the first testcase: Initially the deck is [3 1 2 4].

  * The first operation splits the deck as [(3) (1 2) (4)] and then transforms it into [4 1 2 3].
  * The second operation splits the deck as [(4) (1 2 3)] and then transforms it into [1 2 3 4].

Explanation of the second testcase: Initially the deck is [6 5 4 3 2 1].

  * The first (and only) operation splits the deck as [(6) (5) (4) (3) (2) (1)] and then transforms it into [1 2 3 4 5 6].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 10, inf = 2e9 + 10, mod = 1e9 + 7, inv2 = (mod + 1) / 2;
int n, c[55], pos[55], c1[55];
void f(int l, int r, int num) {
  for (int i = l; i <= r; ++i) {
    int t = c[i];
    c1[i + num] = t;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> c[i];
    c1[i] = c[i];
    pos[c[i]] = i;
  }
  int flag = n & 1;
  vector<vector<int>> res;
  for (int i = 1; i <= n; ++i) {
    int id = pos[i];
    vector<int> ans;
    if (flag == 0) {
      for (int j = i - 1; j > 0; --j) {
        ans.push_back(1);
        c1[n - j + 1] = j;
      }
      f(i, id, n - i - id + 1);
      f(id + 1, n, -id);
      if (id - i + 1) ans.push_back(id - i + 1);
      if (n - id) ans.push_back(n - id);
      if (ans.size() > 1) {
        res.push_back(ans);
      }
    } else {
      f(id, n - i + 1, i - id);
      f(1, id - 1, n - id + 1);
      if (id - 1) ans.push_back(id - 1);
      if (n - i - id + 2) ans.push_back(n - i - id + 2);
      for (int j = i - 1; j > 0; --j) {
        ans.push_back(1);
        c1[j] = j;
      }
      if (ans.size() > 1) {
        res.push_back(ans);
      }
    }
    for (int j = 1; j <= n; ++j) {
      c[j] = c1[j];
      pos[c[j]] = j;
    }
    flag ^= 1;
  }
  cout << res.size() << '\n';
  for (auto x : res) {
    cout << x.size() << ' ';
    for (int i = 0; i < x.size(); ++i) cout << x[i] << " \n"[i == x.size() - 1];
  }
}

```


### Prompt

Your challenge is to write a cpp solution to the following problem:

You are given an array a consisting of n integers. You have to process q queries to this array; each query is given as four numbers l, r, x and y, denoting that for every i such that l ≤ i ≤ r and ai = x you have to set ai equal to y.

Print the array after all queries are processed.

Input

The first line contains one integer n (1 ≤ n ≤ 200000) — the size of array a.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the elements of array a.

The third line contains one integer q (1 ≤ q ≤ 200000) — the number of queries you have to process.

Then q lines follow. i-th line contains four integers l, r, x and y denoting i-th query (1 ≤ l ≤ r ≤ n, 1 ≤ x, y ≤ 100).

Output

Print n integers — elements of array a after all changes are made.

Example

Input

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

Output

5 2 5 4 5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
class Segm_Tree {
 public:
  Segm_Tree() {
    cin >> n;
    val.resize(n + 1);
    tree.resize(n << 2);
    lazy.resize(n << 2);
    for (auto &x : tree) {
      x.resize(101);
      for (int i = 1; i <= 100; ++i) {
        x[i] = i;
      }
    }
    for (int i = 1; i <= n; ++i) {
      cin >> val[i];
    }
  }
  void Solve() {
    int q, l, r, x, y;
    cin >> q;
    while (q--) {
      cin >> l >> r >> x >> y;
      Update(l, r, x, y, 1, n, 1);
    }
    Finish(1, n, 1);
  }

 private:
  int n, q;
  vector<int> val;
  vector<bool> lazy;
  vector<vector<int> > tree;
  void Propagate(int cur_node) {
    int left = cur_node << 1;
    int right = left | 1;
    for (int i = 1; i <= 100; ++i) {
      tree[left][i] = tree[cur_node][tree[left][i]];
      tree[right][i] = tree[cur_node][tree[right][i]];
    }
    for (int i = 1; i <= 100; ++i) {
      tree[cur_node][i] = i;
    }
    lazy[left] = true;
    lazy[right] = true;
    lazy[cur_node] = false;
  }
  void Update(int l, int r, int x, int y, int st, int dr, int cur_node) {
    if (l <= st and dr <= r) {
      for (int i = 1; i <= 100; ++i) {
        if (tree[cur_node][i] == x) {
          tree[cur_node][i] = y;
        }
      }
      lazy[cur_node] = true;
      if (st != dr and lazy[cur_node]) {
        Propagate(cur_node);
      }
      return;
    }
    if (lazy[cur_node]) {
      Propagate(cur_node);
    }
    int mid = (st + dr) >> 1;
    int left = cur_node << 1;
    int right = left | 1;
    if (l <= mid) {
      Update(l, r, x, y, st, mid, left);
    }
    if (mid + 1 <= r) {
      Update(l, r, x, y, mid + 1, dr, right);
    }
  }
  void Finish(int st, int dr, int cur_node) {
    if (st == dr) {
      cout << tree[cur_node][val[st]] << ' ';
      return;
    }
    if (lazy[cur_node]) {
      Propagate(cur_node);
    }
    int mid = (st + dr) >> 1;
    int left = cur_node << 1;
    int right = left | 1;
    Finish(st, mid, left);
    Finish(mid + 1, dr, right);
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  Segm_Tree T;
  T.Solve();
}

```


### Prompt

Please provide a CPP coded solution to the problem described below:

Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.

Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.

Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all <image>, and h(g(x)) = f(x) for all <image>, or determine that finding these is impossible.

Input

The first line contains an integer n (1 ≤ n ≤ 105).

The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).

Output

If there is no answer, print one integer -1.

Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m).

If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.

Examples

Input

3
1 2 3

Output

3
1 2 3
1 2 3

Input

3
2 2 2

Output

1
1 1 1
2

Input

2
2 1

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
const int maxn = 100100;
int n, m;
int a[maxn + 5];
int b[maxn + 5];
int c[maxn + 5];
int id[maxn + 5];
int main() {
  scanf("%d", &n);
  memset(id, -1, sizeof id);
  memset(c, -1, sizeof c);
  m = 0;
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) {
    scanf("%d", a + i), --a[i];
    if (!~id[a[i]]) id[a[i]] = m++;
    b[i] = id[a[i]];
    if (a[i] == i) c[id[a[i]]] = i;
  }
  for (int i = (0), i_end_ = (m); i < i_end_; ++i)
    if (!~c[i]) {
      printf("-1\n");
      return 0;
    }
  for (int i = (0), i_end_ = (m); i < i_end_; ++i) assert(b[c[i]] == i);
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) assert(c[b[i]] == a[i]);
  printf("%d\n", m);
  for (int i = (0), i_end_ = (n); i < i_end_; ++i) printf("%d ", b[i] + 1);
  printf("\n");
  for (int i = (0), i_end_ = (m); i < i_end_; ++i) printf("%d ", c[i] + 1);
  printf("\n");
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

You have a knapsack with the capacity of W. There are also n items, the i-th one has weight w_i.

You want to put some of these items into the knapsack in such a way that their total weight C is at least half of its size, but (obviously) does not exceed it. Formally, C should satisfy: ⌈ W/2⌉ ≤ C ≤ W.

Output the list of items you will put into the knapsack or determine that fulfilling the conditions is impossible.

If there are several possible lists of items satisfying the conditions, you can output any. Note that you don't have to maximize the sum of weights of items in the knapsack.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). Description of the test cases follows.

The first line of each test case contains integers n and W (1 ≤ n ≤ 200 000, 1≤ W ≤ 10^{18}).

The second line of each test case contains n integers w_1, w_2, ..., w_n (1 ≤ w_i ≤ 10^9) — weights of the items.

The sum of n over all test cases does not exceed 200 000.

Output

For each test case, if there is no solution, print a single integer -1.

If there exists a solution consisting of m items, print m in the first line of the output and m integers j_1, j_2, ..., j_m (1 ≤ j_i ≤ n, all j_i are distinct) in the second line of the output — indices of the items you would like to pack into the knapsack.

If there are several possible lists of items satisfying the conditions, you can output any. Note that you don't have to maximize the sum of weights items in the knapsack.

Example

Input

3
1 3
3
6 2
19 8 19 69 9 4
7 12
1 1 1 17 1 1 1

Output

1
1
-1
6
1 2 3 5 6 7

Note

In the first test case, you can take the item of weight 3 and fill the knapsack just right.

In the second test case, all the items are larger than the knapsack's capacity. Therefore, the answer is -1.

In the third test case, you fill the knapsack exactly in half.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int T, n;
long long W;
pair<long long, int> w[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  for (cin >> T; T--;) {
    vector<int> id;
    cin >> n >> W;
    long long x = W;
    for (int i = 1; i <= n; ++i) cin >> w[i].first, w[i].second = i;
    sort(w + 1, w + n + 1, greater<pair<int, int> >());
    for (int i = 1; i <= n; ++i)
      if (w[i].first <= x) x -= w[i].first, id.push_back(w[i].second);
    if (W - x < (W + 1) / 2)
      cout << "-1\n";
    else {
      cout << id.size() << '\n';
      for (int i : id) cout << i << ' ';
      cout << '\n';
    }
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results.

A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has n records in total.

In order to determine a player's category consider the best result obtained by the player and the best results of other players. The player belongs to category:

  * "noob" — if more than 50% of players have better results;
  * "random" — if his result is not worse than the result that 50% of players have, but more than 20% of players have better results;
  * "average" — if his result is not worse than the result that 80% of players have, but more than 10% of players have better results;
  * "hardcore" — if his result is not worse than the result that 90% of players have, but more than 1% of players have better results;
  * "pro" — if his result is not worse than the result that 99% of players have.

When the percentage is calculated the player himself is taken into account. That means that if two players played the game and the first one gained 100 points and the second one 1000 points, then the first player's result is not worse than the result that 50% of players have, and the second one is not worse than the result that 100% of players have.

Vasya gave you the last year Plane of Tanks results. Help Vasya determine each player's category.

Input

The first line contains the only integer number n (1 ≤ n ≤ 1000) — a number of records with the players' results.

Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. The name consists of lowercase Latin letters only. It is guaranteed that any two different players have different names. The amount of points, obtained by the player for the round, is a non-negative integer number and does not exceed 1000.

Output

Print on the first line the number m — the number of players, who participated in one round at least.

Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). The name of each player should be printed only once. Player names with respective categories can be printed in an arbitrary order.

Examples

Input

5
vasya 100
vasya 200
artem 100
kolya 200
igor 250

Output

4
artem noob
igor pro
kolya random
vasya random

Input

3
vasya 200
kolya 1000
vasya 1000

Output

2
kolya pro
vasya pro

Note

In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has best result not worse than the result that 100% of players have (all other players and himself), so he belongs to category "pro".

In the second example both players have the same amount of points, so they have results not worse than 100% players have, so they belong to category "pro".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<string, int> a, pair<string, int> b) {
  return a.second < b.second;
}
struct category {
  string name;
  string cate;
};
int main() {
  map<string, int> score;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string name;
    int scr;
    cin >> name >> scr;
    score[name] = max(score[name], scr);
  }
  vector<pair<string, int> > sorted;
  for (map<string, int>::iterator i = score.begin(); i != score.end(); i++)
    sorted.push_back(make_pair(i->first, i->second));
  sort(sorted.begin(), sorted.end(), cmp);
  int playernum = sorted.size();
  category ans[1001];
  int curscore = -1, betternum = -1;
  for (int i = playernum - 1; i >= 0; i--) {
    if (sorted[i].second != curscore) {
      curscore = sorted[i].second;
      betternum = playernum - i - 1;
    }
    ans[i].name = sorted[i].first;
    double ratio = (double)((double)betternum / (double)playernum);
    if (ratio > 0.5) {
      ans[i].cate = "noob";
      continue;
    }
    if (ratio > 0.2) {
      ans[i].cate = "random";
      continue;
    }
    if (ratio > 0.1) {
      ans[i].cate = "average";
      continue;
    }
    if (ratio > 0.01) {
      ans[i].cate = "hardcore";
      continue;
    }
    ans[i].cate = "pro";
  }
  cout << playernum << endl;
  for (int i = 0; i < playernum; i++)
    cout << ans[i].name << " " << ans[i].cate << endl;
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

There is a string S of length N consisting of characters `0` and `1`. You will perform the following operation for each i = 1, 2, ..., m:

* Arbitrarily permute the characters within the substring of S starting at the l_i-th character from the left and extending through the r_i-th character.

Here, the sequence l_i is non-decreasing.

How many values are possible for S after the M operations, modulo 1000000007(= 10^9+7)?

Constraints

* 2≦N≦3000
* 1≦M≦3000
* S consists of characters `0` and `1`.
* The length of S equals N.
* 1≦l_i < r_i≦N
* l_i ≦ l_{i+1}

Input

The input is given from Standard Input in the following format:

N M
S
l_1 r_1
:
l_M r_M

Output

Print the number of the possible values for S after the M operations, modulo 1000000007.

Examples

Input

5 2
01001
2 4
3 5

Output

6

Input

9 3
110111110
1 4
4 6
6 9

Output

26

Input

11 6
00101000110
2 4
2 3
4 7
5 6
6 10
10 11

Output

143

### Response

```cpp
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n, m;
string s;

int cnt[3005];
int mx[3005], mn[3005];
int dp[3005][3005];
signed main()
{
	cin>>n>>m>>s;
	for(int i=1; i<=n; i++)
	{
		cnt[i]=cnt[i-1]+(s[i-1]=='1');
		mx[i]=cnt[i], mn[i]=cnt[i];
	}
	for(int i=1; i<=m; i++)
	{
		int l, r;
		cin>>l>>r;

		int lol=mn[r]-mn[l-1], lel=mx[r]-mx[l-1];

		for(int j=l; j<=r; j++)
		{
			mn[j]=min(mn[j], mn[l-1]+max(0ll, lol-(r-j)));
			mx[j]=max(mx[j], mx[l-1]+min(j-l+1, lel));
		}
	}
	// for(int i=1; i<=n; i++)
	// {
	// 	cout<<mx[i]<<" "<<mn[i]<<endl;
	// }
	dp[0][0]=1;
	for(int i=1; i<=n; i++)
	{
		for(int j=mn[i]; j<=mx[i]; j++)
		{
			if(j>0)
			{
				dp[i][j]=dp[i-1][j-1]+dp[i-1][j];
			}
			else
			{
				dp[i][j]=dp[i-1][j];
			}
			dp[i][j]%=1000000007;
		}
	}
	cout<<dp[n][cnt[n]];
}
```


### Prompt

Please formulate a CPP solution to the following problem:

A and B are preparing themselves for programming contests.

After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes.

A likes lowercase letters of the Latin alphabet. He has assigned to each letter a number that shows how much he likes that letter (he has assigned negative numbers to the letters he dislikes).

B likes substrings. He especially likes the ones that start and end with the same letter (their length must exceed one).

Also, A and B have a string s. Now they are trying to find out how many substrings t of a string s are interesting to B (that is, t starts and ends with the same letter and its length is larger than one), and also the sum of values of all letters (assigned by A), except for the first and the last one is equal to zero.

Naturally, A and B have quickly found the number of substrings t that are interesting to them. Can you do it?

Input

The first line contains 26 integers xa, xb, ..., xz ( - 105 ≤ xi ≤ 105) — the value assigned to letters a, b, c, ..., z respectively.

The second line contains string s of length between 1 and 105 characters, consisting of Lating lowercase letters— the string for which you need to calculate the answer.

Output

Print the answer to the problem.

Examples

Input

1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
xabcab

Output

2

Input

1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
aaa

Output

2

Note

In the first sample test strings satisfying the condition above are abca and bcab.

In the second sample test strings satisfying the condition above are two occurences of aa.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
const double EPS = 1e-7;
int N;
int v[256];
long long t[100010];
string s;
vector<int> pos[256];
map<long long, int> sum;
int main() {
  ios::sync_with_stdio(false);
  for (int i = 0; i < (26); ++i) {
    int x;
    cin >> x;
    v['a' + i] = x;
  }
  cin >> s;
  N = s.length();
  long long sol = 0;
  for (int c = 'a'; c <= 'z'; ++c) {
    sum.clear();
    for (int i = 1; i <= (N); ++i) {
      t[i] = v[s[i - 1]];
      t[i] += t[i - 1];
      if (s[i - 1] == c) {
        sol += sum[t[i - 1]];
        sum[t[i]]++;
      }
    }
  }
  cout << sol << endl;
  return 0;
}

```


### Prompt

Your task is to create a CPP solution to the following problem:

Alice and Bob are decorating a Christmas Tree.

Alice wants only 3 types of ornaments to be used on the Christmas Tree: yellow, blue and red. They have y yellow ornaments, b blue ornaments and r red ornaments.

In Bob's opinion, a Christmas Tree will be beautiful if:

  * the number of blue ornaments used is greater by exactly 1 than the number of yellow ornaments, and
  * the number of red ornaments used is greater by exactly 1 than the number of blue ornaments.

That is, if they have 8 yellow ornaments, 13 blue ornaments and 9 red ornaments, we can choose 4 yellow, 5 blue and 6 red ornaments (5=4+1 and 6=5+1).

Alice wants to choose as many ornaments as possible, but she also wants the Christmas Tree to be beautiful according to Bob's opinion.

In the example two paragraphs above, we would choose 7 yellow, 8 blue and 9 red ornaments. If we do it, we will use 7+8+9=24 ornaments. That is the maximum number.

Since Alice and Bob are busy with preparing food to the New Year's Eve, they are asking you to find out the maximum number of ornaments that can be used in their beautiful Christmas Tree!

It is guaranteed that it is possible to choose at least 6 (1+2+3=6) ornaments.

Input

The only line contains three integers y, b, r (1 ≤ y ≤ 100, 2 ≤ b ≤ 100, 3 ≤ r ≤ 100) — the number of yellow, blue and red ornaments.

It is guaranteed that it is possible to choose at least 6 (1+2+3=6) ornaments.

Output

Print one number — the maximum number of ornaments that can be used.

Examples

Input

8 13 9

Output

24

Input

13 3 6

Output

9

Note

In the first example, the answer is 7+8+9=24.

In the second example, the answer is 2+3+4=9.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long y, b, r, a, c;
  cin >> y >> b >> r;
  a = r;
  while (1) {
    if (a - 1 <= b && a - 2 <= y) {
      cout << a + a - 1 + a - 2 << endl;
      return 0;
    }
    a--;
  }
}

```


### Prompt

Generate a Cpp solution to the following problem:

This is an interactive problem.

Note: the XOR-sum of an array a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) is defined as a_1 ⊕ a_2 ⊕ … ⊕ a_n, where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).

Little Dormi received an array of n integers a_1, a_2, …, a_n for Christmas. However, while playing with it over the winter break, he accidentally dropped it into his XOR machine, and the array got lost.

The XOR machine is currently configured with a query size of k (which you cannot change), and allows you to perform the following type of query: by giving the machine k distinct indices x_1, x_2, …, x_k, it will output a_{x_1} ⊕ a_{x_2} ⊕ … ⊕ a_{x_k}.

As Little Dormi's older brother, you would like to help him recover the XOR-sum of his array a_1, a_2, …, a_n by querying the XOR machine.

Little Dormi isn't very patient, so to be as fast as possible, you must query the XOR machine the minimum number of times to find the XOR-sum of his array. Formally, let d be the minimum number of queries needed to find the XOR-sum of any array of length n with a query size of k. Your program will be accepted if you find the correct XOR-sum in at most d queries.

Lastly, you also noticed that with certain configurations of the machine k and values of n, it may not be possible to recover the XOR-sum of Little Dormi's lost array. If that is the case, you should report it as well.

The array a_1, a_2, …, a_n is fixed before you start querying the XOR machine and does not change with the queries.

Input

The only line of input contains the integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n), the length of the lost array and the configured query size of the XOR machine.

Elements of the original array satisfy 1 ≤ a_i ≤ 10^9.

It can be proven that that if it is possible to recover the XOR sum under the given constraints, it can be done in at most 500 queries. That is, d ≤ 500.

After taking n and k, begin interaction.

Output

If it is impossible to recover the XOR-sum of the array, output -1 immediately after taking n and k. Do not begin interaction.

Otherwise, when your program finds the XOR-sum of the lost array a_1, a_2, …, a_n, report the answer in the following format: "! x", where x is the XOR sum of the array a_1, a_2, …, a_n, and terminate your program normally immediately after flushing the output stream.

Note that answering does not count as a query.

Interaction

Each query is made in the format "? b", where b is an array of exactly k distinct integers from 1 to n denoting the indices of the elements in the lost array that you want to query the XOR sum of.

You will then receive an integer x, the XOR sum of the queried elements. It can be proven that 0 ≤ x ≤ 2 ⋅ 10^9 will always be true.

After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

  * fflush(stdout) or cout.flush() in C++;
  * System.out.flush() in Java;
  * flush(output) in Pascal;
  * stdout.flush() in Python;
  * see documentation for other languages.

If at any point you make an invalid query or try to make more than 500 queries (which is the hard limit), the interaction will terminate immediately and give you a Wrong Answer verdict. Note that if you exceed d queries, the interaction will continue normally unless you also exceed the 500 query hard limit, though you will still receive a Wrong Answer verdict either way.

Hacks

To hack a solution, use the following format.

The first line contains the integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n).

The second line contains the the array a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9).

Examples

Input

5 3

4

0

1

Output

? 1 2 3

? 2 3 5

? 4 1 5

! 7

Input

3 2

Output

-1

Note

In the first example interaction, the array a_1, a_2, …, a_n is 2, 1, 7, 5, 6 and its XOR-sum is 7.

The first query made asks for indices 1,2,3, so the response is a_1 ⊕ a_2 ⊕ a_3 = 2 ⊕ 1 ⊕ 7 = 4.

The second query made asks for indices 2,3,5, so the response is a_2 ⊕ a_3 ⊕ a_5 = 1 ⊕ 7 ⊕ 6 = 0.

The third query made asks for indices 4,1,5, so the response is a_4 ⊕ a_1 ⊕ a_5 = 5 ⊕ 2 ⊕ 6 = 1. Note that the indices may be output in any order.

Additionally, even though three queries were made in the example interaction, it is just meant to demonstrate the interaction format and does not necessarily represent an optimal strategy.

In the second example interaction, there is no way to recover the XOR-sum of Little Dormi's array no matter what is queried, so the program immediately outputs -1 and exits.

### Response

```cpp
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops","omit-frame-pointer","inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma,tune=native")
#pragma GCC option("arch=native","no-zero-upper") //Enable AVX

#include <bits/stdc++.h>
#define db(x) cout << (x) << '\n';
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<ld,ll> pdi;
typedef pair<ld,ld> pdd;
typedef pair<ld,pdd> pdp;
typedef pair<string,ll> psi;
typedef pair<ll,string> pls;
typedef pair<string,string> pss;
typedef pair<ll,pii> pip;
typedef pair<pii,pii> ppp;
typedef complex<ll> point;
typedef vector<point> polygon;
typedef pair<point,int> ppi;
#define prec(n) cout.precision(n); cout<<fixed
const ll mod=(1e9+7);
const ld eps=(1e-9);
const ll oo=(ll)(1e18+5);
#define pi acos(-1)
#define MAXN (ll)(5e5+5)

int ask(vector<int> v)
{
    cout << "?";
    for(auto u : v)
        cout << ' ' << u+1;
    cout << '\n';
    cout.flush();
    int ans;
    cin >> ans;
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n,k;
    cin >> n >> k;
    for(int i=1;i<=500;i++)
        if(k*i>=n && ((k*i)-n)%2==0)
        {
            int fal=((k*i)-n)/2;
            vector<int> f(n);
            for(int j=0;j<n;j++)
            {
                f[j]=1;
                ll v=min((i-1)/2,fal);
                fal-=v;
                f[j]+=2*v;
            }
            if(fal)
                continue;
            vector<vector<int>> ps(i);
            int act=0;
            for(int j=0;j<n;j++)
                for(int l=0;l<f[j];l++)
                {
                    ps[act].push_back(j);
                    act=(act+1)%i;
                }

            ll ans=0;
            for(auto vv : ps)
                ans^=ask(vv);
            cout << "! " << ans << '\n';
            cout.flush();
            return 0;
        }
    cout << -1 << '\n';
    cout.flush();

    return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

User ainta has a stack of n red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack.

  * While the top ball inside the stack is red, pop the ball from the top of the stack.
  * Then replace the blue ball on the top with a red ball.
  * And finally push some blue balls to the stack until the stack has total of n balls inside.

If there are no blue balls inside the stack, ainta can't apply this operation. Given the initial state of the stack, ainta wants to know the maximum number of operations he can repeatedly apply.

Input

The first line contains an integer n (1 ≤ n ≤ 50) — the number of balls inside the stack.

The second line contains a string s (|s| = n) describing the initial state of the stack. The i-th character of the string s denotes the color of the i-th ball (we'll number the balls from top to bottom of the stack). If the character is "R", the color is red. If the character is "B", the color is blue.

Output

Print the maximum number of operations ainta can repeatedly apply.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

3
RBR

Output

2

Input

4
RBBR

Output

6

Input

5
RBBRR

Output

6

Note

The first example is depicted below.

The explanation how user ainta applies the first operation. He pops out one red ball, changes the color of the ball in the middle from blue to red, and pushes one blue ball.

<image>

The explanation how user ainta applies the second operation. He will not pop out red balls, he simply changes the color of the ball on the top from blue to red.

<image>

From now on, ainta can't apply any operation because there are no blue balls inside the stack. ainta applied two operations, so the answer is 2.

The second example is depicted below. The blue arrow denotes a single operation.

<image>

### Response

```cpp
#include <bits/stdc++.h>
int main(void) {
  int i, n;
  char a[51];
  long long int sum = 0;
  long long int over = 1;
  scanf("%d %s", &n, a);
  for (i = 0; i < n; i++, over *= 2)
    if (a[i] == 'B') sum += over;
  printf("%I64d", sum);
  return 0;
}

```


### Prompt

In CPP, your task is to solve the following problem:

You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.

Input

The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge.

It is possible that the graph has loops and multiple edges between pair of vertices.

Output

Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.

Examples

Input

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

Output

1 4 3 5

Input

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

Output

1 4 3 5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e5;
vector<pair<int, int>> adj[mxN + 1];
int par[mxN + 1];
long long int dist[mxN + 1];
void dijkstra(int s) {
  for (int i = 1; i <= mxN; i++) dist[i] = 1e18, par[i] = -1;
  dist[s] = 0;
  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                 greater<pair<long long, int>>>
      mpq;
  mpq.push({dist[s], s});
  while (!mpq.empty()) {
    int p = mpq.top().second;
    long long int d = mpq.top().first;
    mpq.pop();
    for (auto edge : adj[p]) {
      int ch = edge.first, w = edge.second;
      if (d + w < dist[ch]) {
        dist[ch] = d + w;
        par[ch] = p;
        mpq.push({dist[ch], ch});
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b, w;
    cin >> a >> b >> w;
    adj[a].push_back({b, w});
    adj[b].push_back({a, w});
  }
  dijkstra(1);
  if (par[n] == -1) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> ans;
  int t = n;
  while (1) {
    ans.push_back(t);
    t = par[t];
    if (t < 0) break;
  }
  for (int i = ans.size() - 1; i >= 0; i--) {
    cout << ans[i] << " ";
  }
  cout << endl;
}

```


### Prompt

Your challenge is to write a cpp solution to the following problem:

Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.

The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)

Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?

Constraints

* 101 \le X \le 10^{18}
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

X

Output

Print the number of years it takes for Takahashi's balance to reach X yen or above for the first time.

Examples

Input

103

Output

3

Input

1000000000000000000

Output

3760

Input

1333333333

Output

1706

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x,ans=100,i;
int main()
{
	cin>>x;
	while(ans<x)
	{
		i++;
		ans=ans*1.01;
	}
	cout<<i;
    return 0;
}
```


### Prompt

Please formulate a CPP solution to the following problem:

One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units.

In order for production to work, it is needed to deploy two services S_1 and S_2 to process incoming requests using the servers of the department. Processing of incoming requests of service S_i takes x_i resource units.

The described situation happens in an advanced company, that is why each service may be deployed using not only one server, but several servers simultaneously. If service S_i is deployed using k_i servers, then the load is divided equally between these servers and each server requires only x_i / k_i (that may be a fractional number) resource units.

Each server may be left unused at all, or be used for deploying exactly one of the services (but not for two of them simultaneously). The service should not use more resources than the server provides.

Determine if it is possible to deploy both services using the given servers, and if yes, determine which servers should be used for deploying each of the services.

Input

The first line contains three integers n, x_1, x_2 (2 ≤ n ≤ 300 000, 1 ≤ x_1, x_2 ≤ 10^9) — the number of servers that the department may use, and resource units requirements for each of the services.

The second line contains n space-separated integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^9) — the number of resource units provided by each of the servers.

Output

If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).

Otherwise print the word "Yes" (without the quotes).

In the second line print two integers k_1 and k_2 (1 ≤ k_1, k_2 ≤ n) — the number of servers used for each of the services.

In the third line print k_1 integers, the indices of the servers that will be used for the first service.

In the fourth line print k_2 integers, the indices of the servers that will be used for the second service.

No index may appear twice among the indices you print in the last two lines. If there are several possible answers, it is allowed to print any of them.

Examples

Input

6 8 16
3 5 2 9 8 7

Output

Yes
3 2
1 2 6
5 4

Input

4 20 32
21 11 11 12

Output

Yes
1 3
1
2 3 4

Input

4 11 32
5 5 16 16

Output

No

Input

5 12 20
7 8 4 11 9

Output

No

Note

In the first sample test each of the servers 1, 2 and 6 will will provide 8 / 3 = 2.(6) resource units and each of the servers 5, 4 will provide 16 / 2 = 8 resource units.

In the second sample test the first server will provide 20 resource units and each of the remaining servers will provide 32 / 3 = 10.(6) resource units.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 323456;
int n, x1, x2;
pair<int, int> a[N];
void go(int start1, bool sw) {
  int k1 = (x1 + a[start1].first - 1) / a[start1].first;
  int start2 = start1 + k1;
  if (start2 >= n) {
    return;
  }
  if ((long long)(n - start2) * a[start2].first < x2) {
    return;
  }
  vector<int> v1, v2;
  for (int i = start1; i < start2; i++) {
    v1.push_back(a[i].second);
  }
  int k2 = 0;
  for (int i = start2; i < n; i++) {
    k2++;
    v2.push_back(a[i].second);
  }
  if (sw) {
    swap(k1, k2);
    swap(v1, v2);
  }
  printf("Yes\n");
  printf("%d %d\n", k1, k2);
  for (int x : v1) {
    printf("%d ", x + 1);
  }
  printf("\n");
  for (int x : v2) {
    printf("%d ", x + 1);
  }
  printf("\n");
  exit(0);
}
int main() {
  scanf("%d%d%d", &n, &x1, &x2);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i].first);
    a[i].second = i;
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    go(i, false);
    swap(x1, x2);
    go(i, true);
    swap(x1, x2);
  }
  puts("No");
  return 0;
}

```


### Prompt

Your task is to create a Cpp solution to the following problem:

Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.

Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier — a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.

Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.

Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers.

Input

The first line contains two integers: x (1 ≤ x ≤ 4000) — the round Sereja is taking part in today, and k (0 ≤ k < 4000) — the number of rounds he took part in.

Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num2 num1" (where num2 is the identifier of this Div2 round, num1 is the identifier of the Div1 round). It is guaranteed that num1 - num2 = 1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x.

Output

Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.

Examples

Input

3 2
2 1
2 2

Output

0 0

Input

9 3
1 2 3
2 8
1 4 5

Output

2 3

Input

10 0

Output

5 9

Note

In the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round.

The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, k, i;
  cin >> x >> k;
  if (k == 0) {
    cout << x / 2 << " " << x - 1 << endl;
    return 0;
  }
  int *d1 = new int[x + 1];
  int *d2 = new int[x + 1];
  for (i = 0; i < x; i++) d1[i] = d2[i] = 0;
  int a, b, c;
  for (i = 0; i < k; i++) {
    cin >> a;
    if (a == 1) {
      cin >> b >> c;
      d2[b] = 1;
      d1[c] = 1;
      d1[b] = 1;
      d2[c] = 1;
    } else {
      cin >> b;
      d2[b] = 1;
      d1[b + 1] = 1;
      d1[b] = 1;
    }
  }
  c = 0;
  for (i = 1; i < x - 1; i++) {
    if (d2[i] == 0 && d1[i + 1] == 0) {
      c++;
      i++;
    }
  }
  int mini = 0, maxi = 0;
  for (i = 1; i < x; i++) {
    if (d2[i] == 0) maxi++;
  }
  mini = maxi - c;
  cout << mini << " " << maxi << endl;
  return 0;
}

```


### Prompt

Your challenge is to write a CPP solution to the following problem:

Vasya participates in a ski race along the X axis. The start is at point 0, and the finish is at L, that is, at a distance L meters from the start in the positive direction of the axis. Vasya has been training so hard that he can run one meter in exactly one second.

Besides, there are n take-off ramps on the track, each ramp is characterized by four numbers:

  * xi represents the ramp's coordinate
  * di represents from how many meters Vasya will land if he goes down this ramp
  * ti represents the flight time in seconds
  * pi is the number, indicating for how many meters Vasya should gather speed to get ready and fly off the ramp. As Vasya gathers speed, he should ski on the snow (that is, he should not be flying), but his speed still equals one meter per second.

Vasya is allowed to move in any direction on the X axis, but he is prohibited to cross the start line, that is go to the negative semiaxis. Vasya himself chooses which take-off ramps he will use and in what order, that is, he is not obliged to take off from all the ramps he encounters. Specifically, Vasya can skip the ramp. It is guaranteed that xi + di ≤ L, that is, Vasya cannot cross the finish line in flight.

Vasya can jump from the ramp only in the positive direction of X axis. More formally, when using the i-th ramp, Vasya starts gathering speed at point xi - pi, jumps at point xi, and lands at point xi + di. He cannot use the ramp in opposite direction.

Your task is to find the minimum time that Vasya will spend to cover the distance.

Input

The first line contains two integers n and L (0 ≤ n ≤ 105, 1 ≤ L ≤ 109). Then n lines contain the descriptions of the ramps, each description is on a single line. Each description is a group of four non-negative integers xi, di, ti, pi (0 ≤ xi ≤ L, 1 ≤ di, ti, pi ≤ 109, xi + di ≤ L).

Output

Print in the first line the minimum time in seconds Vasya needs to complete the track. Print in the second line k — the number of take-off ramps that Vasya needs to use, and print on the third line of output k numbers the number the take-off ramps Vasya used in the order in which he used them. Print each number exactly once, separate the numbers with a space. The ramps are numbered starting from 1 in the order in which they are given in the input.

Examples

Input

2 20
5 10 5 5
4 16 1 7

Output

15
1
1

Input

2 20
9 8 12 6
15 5 1 1

Output

16
1
2

Note

In the first sample, Vasya cannot use ramp 2, because then he will need to gather speed starting from point -3, which is not permitted by the statement. The optimal option is using ramp 1, the resulting time is: moving to the point of gathering speed + gathering speed until reaching the takeoff ramp + flight time + moving to the finish line = 0 + 5 + 5 + 5 = 15.

In the second sample using ramp 1 is not optimal for Vasya as t1 > d1. The optimal option is using ramp 2, the resulting time is: moving to the point of gathering speed + gathering speed until reaching the takeoff ramp + flight time + moving to the finish line = 14 + 1 + 1 + 0 = 16.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, from[100001];
long long l;
struct t {
  long long pos, time;
  int id;
  bool operator()(t a, t b) {
    if (a.pos < b.pos) return true;
    if (a.pos > b.pos) return false;
    return (a.id < b.id);
  }
};
struct t2 {
  long long x, p, t, d;
  int id;
};
vector<t2> a;
bool comp(t2 a, t2 b) { return a.x - a.p < b.x - b.p; }
int main() {
  scanf("%d %I64d", &n, &l);
  for (long long i = 1; i <= n; i++) {
    t2 track;
    cin >> track.x >> track.d >> track.t >> track.p;
    track.id = i;
    a.push_back(track);
  }
  sort(a.begin(), a.end(), comp);
  multiset<t, t> my_set;
  for (int i = 0; i < a.size(); i++) {
    if (a[i].x - a[i].p >= 0) {
      t new_t;
      new_t.pos = a[i].x - a[i].p;
      new_t.id = a[i].id;
      multiset<t, t>::iterator it = my_set.upper_bound(new_t);
      long long time_need = a[i].x;
      if (it != my_set.end()) {
        if ((*it).pos <= a[i].x) {
          if ((*it).pos - new_t.pos + a[i].p + (*it).time < time_need) {
            time_need = (*it).pos - new_t.pos + a[i].p + (*it).time;
            from[new_t.id] = (*it).id;
          }
        } else {
          if ((*it).pos - a[i].x + 2LL * a[i].p + (*it).time < time_need) {
            time_need = (*it).pos - a[i].x + 2LL * a[i].p + (*it).time;
            from[new_t.id] = (*it).id;
          }
        }
      }
      if (my_set.size() > 0) --it;
      if (it != my_set.end()) {
        if (time_need > (*it).time - (*it).pos + a[i].x) {
          time_need = (*it).time - (*it).pos + a[i].x;
          from[new_t.id] = (*it).id;
        }
      }
      new_t.pos = a[i].x + a[i].d;
      new_t.time = time_need + a[i].t;
      it = my_set.insert(new_t);
      multiset<t, t>::iterator it2;
      bool bad = false;
      for (; 1;) {
        it2 = my_set.upper_bound(*it);
        if (it2 != my_set.end() &&
            (*it).time + (*it2).pos - (*it).pos <= (*it2).time) {
          my_set.erase(it2);
        } else if (it2 != my_set.end() &&
                   (*it2).time + (*it2).pos - (*it).pos <= (*it).time) {
          bad = true;
          my_set.erase(it);
          break;
        } else
          break;
      }
      if (!bad) {
        for (; 1;) {
          it2 = my_set.find(*it);
          it2--;
          if (it2 != my_set.end() &&
              (*it).time + (*it).pos - (*it2).pos <= (*it2).time) {
            my_set.erase(it2);
          } else if (it2 != my_set.end() &&
                     (*it2).time + (*it).pos - (*it2).pos <= (*it).time) {
            my_set.erase(it);
            break;
          } else
            break;
        }
      }
    }
  }
  long long need_time = l;
  int st_p = 0;
  vector<int> ans;
  for (multiset<t, t>::iterator it = my_set.begin(); it != my_set.end(); ++it) {
    if ((*it).time + (l - (*it).pos) < need_time) {
      need_time = (*it).time + (l - (*it).pos);
      st_p = (*it).id;
    }
  }
  if (need_time == l) {
    printf("%I64d\n0", need_time);
    return 0;
  }
  while (st_p != 0) {
    ans.push_back(st_p);
    st_p = from[st_p];
  }
  printf("%I64d\n%d\n", need_time, ans.size());
  for (int i = ans.size() - 1; i >= 0; i--) {
    printf("%d ", ans[i]);
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Mishka got an integer array a of length n as a birthday present (what a surprise!).

Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps:

  * Replace each occurrence of 1 in the array a with 2;
  * Replace each occurrence of 2 in the array a with 1;
  * Replace each occurrence of 3 in the array a with 4;
  * Replace each occurrence of 4 in the array a with 3;
  * Replace each occurrence of 5 in the array a with 6;
  * Replace each occurrence of 6 in the array a with 5;
  * ...
  * Replace each occurrence of 10^9 - 1 in the array a with 10^9;
  * Replace each occurrence of 10^9 in the array a with 10^9 - 1.

Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i - 1, 2i) for each i ∈\{1, 2, …, 5 ⋅ 10^8\} as described above.

For example, for the array a = [1, 2, 4, 5, 10], the following sequence of arrays represents the algorithm:

[1, 2, 4, 5, 10] → (replace all occurrences of 1 with 2) → [2, 2, 4, 5, 10] → (replace all occurrences of 2 with 1) → [1, 1, 4, 5, 10] → (replace all occurrences of 3 with 4) → [1, 1, 4, 5, 10] → (replace all occurrences of 4 with 3) → [1, 1, 3, 5, 10] → (replace all occurrences of 5 with 6) → [1, 1, 3, 6, 10] → (replace all occurrences of 6 with 5) → [1, 1, 3, 5, 10] → ... → [1, 1, 3, 5, 10] → (replace all occurrences of 10 with 9) → [1, 1, 3, 5, 9]. The later steps of the algorithm do not change the array.

Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it.

Input

The first line of the input contains one integer number n (1 ≤ n ≤ 1000) — the number of elements in Mishka's birthday present (surprisingly, an array).

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the elements of the array.

Output

Print n integers — b_1, b_2, ..., b_n, where b_i is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array.

Examples

Input

5
1 2 4 5 10

Output

1 1 3 5 9

Input

10
10000 10 50605065 1 5 89 5 999999999 60506056 1000000000

Output

9999 9 50605065 1 5 89 5 999999999 60506055 999999999

Note

The first example is described in the problem statement.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
long long powmod(long long a, long long b, long long MOD) {
  long long ans = 1;
  while (b) {
    if (b % 2) ans = ans * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return ans;
}
long long a[1111];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    if (a[i] % 2 == 0) a[i]--;
    cout << a[i] << ' ';
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

You are given an array a_1, a_2, ... , a_n and two integers m and k.

You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r.

The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to ∑_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) ⌉, where ⌈ x ⌉ is the least integer greater than or equal to x.

The cost of empty subarray is equal to zero.

For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are:

  * a_3 ... a_3: 15 - k ⌈ 1/3 ⌉ = 15 - 10 = 5;
  * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 ⌉ = 12 - 10 = 2;
  * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 ⌉ = 16 - 10 = 6;
  * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 ⌉ = 24 - 20 = 4;
  * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 ⌉ = 27 - 20 = 7.

Your task is to find the maximum cost of some subarray (possibly empty) of array a.

Input

The first line contains three integers n, m, and k (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 10, 1 ≤ k ≤ 10^9).

The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≤ a_i ≤ 10^9).

Output

Print the maximum cost of some subarray of array a.

Examples

Input

7 3 10
2 -4 15 -3 4 8 3

Output

7

Input

5 2 1000
-13 -4 -9 -20 -11

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-10, inf = 1e50;
const int mod = 1e9 + 7, N = 3e5 + 5;
int n, m, k, a[N];
long long ans;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  ans = 0;
  for (int first = 1; first <= min(n, m); ++first) {
    long long cur = 0;
    for (int i = first; i <= n; i += m) {
      cur -= k;
      for (int j = i; j < i + m && j <= n; ++j)
        cur += a[j], ans = max(ans, cur);
      if (cur < 0) cur = 0;
      ans = max(ans, cur);
    }
  }
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

Your challenge is to write a Cpp solution to the following problem:

You are given a following process.

There is a platform with n columns. 1 × 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.

When all of the n columns have at least one square in them, the bottom row is being removed. You will receive 1 point for this, and all the squares left will fall down one row.

You task is to calculate the amount of points you will receive.

Input

The first line of input contain 2 integer numbers n and m (1 ≤ n, m ≤ 1000) — the length of the platform and the number of the squares.

The next line contain m integer numbers c_1, c_2, ..., c_m (1 ≤ c_i ≤ n) — column in which i-th square will appear.

Output

Print one integer — the amount of points you will receive.

Example

Input

3 9
1 1 2 2 2 3 1 2 3

Output

2

Note

In the sample case the answer will be equal to 2 because after the appearing of 6-th square will be removed one row (counts of the squares on the platform will look like [2~ 3~ 1], and after removing one row will be [1~ 2~ 0]).

After the appearing of 9-th square counts will be [2~ 3~ 1], and after removing one row it will look like [1~ 2~ 0].

So the answer will be equal to 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-12;
const int inf = 2000000000;
long long int MOD = 1000000007;
int MOD1 = 1000000007;
int MOD2 = 1000000009;
inline bool checkBit(long long int n, long long int i) {
  return n & (1LL << i);
}
inline long long int setBit(long long int n, long long int i) {
  return n | (1LL << i);
  ;
}
inline long long int resetBit(long long int n, long long int i) {
  return n & (~(1LL << i));
}
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline bool isLeapYear(long long int year) {
  return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
inline void normal(long long int &a) {
  a %= MOD;
  (a < 0) && (a += MOD);
}
inline long long int modMul(long long int a, long long int b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a * b) % MOD;
}
inline long long int modAdd(long long int a, long long int b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a + b) % MOD;
}
inline long long int modSub(long long int a, long long int b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline long long int modPow(long long int b, long long int p) {
  long long int r = 1LL;
  while (p) {
    if (p & 1) r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1LL;
  }
  return r;
}
inline long long int modDiv(long long int a, long long int b) {
  return modMul(a, modPow(b, MOD - 2));
}
bool comp(const pair<long long int, pair<long long int, long long int> > &p1,
          const pair<long long int, pair<long long int, long long int> > &p2) {
  return p1.first > p2.first;
}
bool comp1(const pair<long long int, long long int> &p1,
           const pair<long long int, long long int> &p2) {
  if (p1.first == p2.first) {
    return p1.second > p2.second;
  }
  return p1.first < p2.first;
}
long long int converter(string a) {
  long long int i, mul = 1, r, t, ans = 0LL;
  if (a.length() == 0) return 0;
  for (i = a.length() - 1; i >= 0; i--) {
    t = a[i] - '0';
    r = t % 10;
    ans += (mul * r);
    mul = mul * 10;
  }
  return ans;
}
int msb(unsigned x) {
  union {
    double a;
    int b[2];
  };
  a = x;
  return (b[1] >> 20) - 1023;
}
int ptr[1005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m, i, x, ans = 0, j;
  cin >> n >> m;
  for (i = 1; i <= m; ++i) {
    cin >> x;
    ptr[x]++;
    int cnt = 0;
    for (j = 1; j <= n; ++j) {
      if (ptr[j] > 0) ++cnt;
    }
    if (cnt == n) {
      ++ans;
      for (j = 1; j <= n; ++j) {
        ptr[j]--;
        ptr[j] = max(0, ptr[j]);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

In this problem you have to implement an algorithm to defragment your hard disk. The hard disk consists of a sequence of clusters, numbered by integers from 1 to n. The disk has m recorded files, the i-th file occupies clusters with numbers ai, 1, ai, 2, ..., ai, ni. These clusters are not necessarily located consecutively on the disk, but the order in which they are given corresponds to their sequence in the file (cluster ai, 1 contains the first fragment of the i-th file, cluster ai, 2 has the second fragment, etc.). Also the disc must have one or several clusters which are free from files.

You are permitted to perform operations of copying the contents of cluster number i to cluster number j (i and j must be different). Moreover, if the cluster number j used to keep some information, it is lost forever. Clusters are not cleaned, but after the defragmentation is complete, some of them are simply declared unusable (although they may possibly still contain some fragments of files).

Your task is to use a sequence of copy operations to ensure that each file occupies a contiguous area of memory. Each file should occupy a consecutive cluster section, the files must follow one after another from the beginning of the hard disk. After defragmentation all free (unused) clusters should be at the end of the hard disk. After defragmenting files can be placed in an arbitrary order. Clusters of each file should go consecutively from first to last. See explanatory examples in the notes.

Print the sequence of operations leading to the disk defragmentation. Note that you do not have to minimize the number of operations, but it should not exceed 2n.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 200) — the number of clusters and the number of files, correspondingly. Next m lines contain descriptions of the files. The first number in the line is ni (ni ≥ 1), the number of clusters occupied by the i-th file. Then follow ni numbers ai, 1, ai, 2, ..., ai, ni (1 ≤ ai, j ≤ n). It is guaranteed that each cluster number occurs not more than once and <image>, that is, there exists at least one unused cluster. Numbers on each line are separated by spaces.

Output

In the first line print a single integer k (0 ≤ k ≤ 2n) — the number of operations needed to defragment the disk. Next k lines should contain the operations' descriptions as "i j" (copy the contents of the cluster number i to the cluster number j).

Examples

Input

7 2
2 1 2
3 3 4 5

Output

0

Input

7 2
2 1 3
3 2 4 5

Output

3
2 6
3 2
6 3

Note

Let's say that a disk consists of 8 clusters and contains two files. The first file occupies two clusters and the second file occupies three clusters. Let's look at examples of correct and incorrect positions of files after defragmentation.

<image>

Example 2: each file must occupy a contiguous area of memory.

Example 3: the order of files to each other is not important, at first the second file can be written, and then — the first one.

Example 4: violating the order of file fragments to each other is not allowed.

Example 5: unused clusters should be located at the end, and in this example the unused clusters are 3, 7, 8.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n + 1);
  long long id = 1;
  for (long long i = 0; i < m; i++) {
    long long x, c;
    cin >> x;
    for (long long j = 0; j < x; j++) cin >> c, a[c] = id++;
  }
  vector<pair<long long, long long> > ans;
  for (long long i = 1; i < id; i++) {
    long long free = find(a.begin() + 1, a.end(), 0) - a.begin();
    long long cur = find(a.begin() + 1, a.end(), i) - a.begin();
    long long next = i;
    if (cur == next) continue;
    if (next != free) ans.emplace_back(next, free);
    ans.emplace_back(cur, next);
    a[cur] = 0;
    a[free] = a[next];
    a[next] = next;
  }
  cout << (long long)ans.size() << endl;
  for (auto i : ans) cout << i.first << " " << i.second << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, n groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. It has turned out that it is impossible to hold all lessons, because for some groups periods of their lessons intersect. If at some moment of time one groups finishes it's lesson, and the other group starts the lesson, their lessons don't intersect.

The dean wants to cancel the lesson in one group so that no two time periods of lessons of the remaining groups intersect. You are to find all ways to do that.

Input

The first line contains integer n (1 ≤ n ≤ 5000) — amount of groups, which have lessons in the room 31. Then n lines follow, each of them contains two integers li ri (1 ≤ li < ri ≤ 106) — starting and finishing times of lesson of the i-th group. It is possible that initially no two lessons intersect (see sample 1).

Output

Output integer k — amount of ways to cancel the lesson in exactly one group so that no two time periods of lessons of the remaining groups intersect. In the second line output k numbers — indexes of groups, where it is possible to cancel the lesson. Groups are numbered starting from 1 in the order that they were given in the input. Output the numbers in increasing order.

Examples

Input

3
3 10
20 30
1 3

Output

3
1 2 3

Input

4
3 10
20 30
1 3
1 39

Output

1
4

Input

3
1 5
2 6
3 7

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 20;
vector<pair<int, int>> ve;
int n, num, numof;
set<int> gr;
vector<int> ans;
bool fo;
bool intr(int l1, int r1, int l2, int r2) {
  if (l1 > l2 && l1 < r2) return true;
  if (r1 > l2 && r1 < r2) return true;
  if (l1 == l2 && r1 <= r2) return true;
  if (r1 == r2 && l1 > l2) return true;
  if (l1 <= l2 && r1 > l2 && r1 < r2) return true;
  if (l1 <= l2 && r1 > l2 && r1 > r2) return true;
  return false;
}
vector<vector<int>> in(5010);
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    ve.push_back(make_pair(l, r));
  }
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (intr(ve[i].first, ve[i].second, ve[j].first, ve[j].second)) {
        in[i].push_back(j);
        in[j].push_back(i);
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    bool ok = true;
    for (int j = 0; j < n; ++j) {
      if (i == j) continue;
      if (in[j].size() == 1) {
        if (in[j][0] != i) {
          ok = false;
          break;
        }
      } else if (in[j].size() > 1) {
        ok = false;
        break;
      }
    }
    if (ok) ans.push_back(i);
  }
  cout << ans.size() << endl;
  for (auto x : ans) printf("%d ", x + 1);
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.

For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.

Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.

Katya had no problems with completing this task. Will you do the same?

Input

The only line of the input contains single integer n (1 ≤ n ≤ 109) — the length of some side of a right triangle.

Output

Print two integers m and k (1 ≤ m, k ≤ 1018), such that n, m and k form a Pythagorean triple, in the only line.

In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.

Examples

Input

3

Output

4 5

Input

6

Output

8 10

Input

1

Output

-1

Input

17

Output

144 145

Input

67

Output

2244 2245

Note

<image>

Illustration for the first sample.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long a, b, c, p, q;
  cin >> a;
  if (a == 1 || a == 2) {
    cout << -1;
    return 0;
  }
  if (a % 2 == 1) {
    b = (a * a - 1) / 2;
    c = b + 1;
  } else {
    p = a / 2;
    q = 1;
    b = p * p - q * q;
    c = p * p + q * q;
  }
  if (b > 1000000000000000000 || c > 1000000000000000000) cout << 5 / 0;
  cout << b << " " << c;
  return 0;
}

```


### Prompt

Your task is to create a cpp solution to the following problem:

The plans for HC2 are rather far-fetched: we are just over 500 000 days away from HC2 3387, for example, and accordingly we are planning to have a couple hundred thousand problems in that edition (we hope that programming contests will become wildly more popular). The marmots need to get to work, and they could use a good plan...

Input

Same as the medium version, but the limits have changed: 1 ≤ k ≤ n ≤ 500 000.

Output

Same as the medium version.

Example

Input

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

Output

32

### Response

```cpp
#include <bits/stdc++.h>
inline long long rd() {
  long long _x = 0;
  int _ch = getchar(), _f = 1;
  for (; !isdigit(_ch) && (_ch != '-') && (_ch != EOF); _ch = getchar())
    ;
  if (_ch == '-') {
    _f = 0;
    _ch = getchar();
  }
  for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch - '0';
  return _f ? _x : -_x;
}
void write(long long _x) {
  if (_x >= 10)
    write(_x / 10), putchar(_x % 10 + '0');
  else
    putchar(_x + '0');
}
inline void wrt(long long _x, char _p) {
  if (_x < 0) putchar('-'), _x = -_x;
  write(_x);
  if (_p) putchar(_p);
}
int k, n;
int a[500005], b[500005];
std::pair<int, long long> check(int x) {
  long long ans = 0;
  int tot = 0;
  std::priority_queue<std::pair<int, bool>, std::vector<std::pair<int, bool>>,
                      std::greater<std::pair<int, bool>>>
      que;
  for (int i = 1; i <= n; i++) {
    que.push({a[i], 1});
    int now = b[i] - x;
    if (now + que.top().first < 0) {
      ans += now + que.top().first;
      tot += que.top().second;
      que.pop();
      que.push({-now, 0});
    }
  }
  return {tot, 1ll * tot * x + ans};
}
int main() {
  n = rd(), k = rd();
  for (int i = 1; i <= n; i++) a[i] = rd();
  for (int i = 1; i <= n; i++) b[i] = rd();
  int l = 0, r = 2e9;
  while (l <= r) {
    int mid = ((long long)l + r) >> 1;
    int sum = check(mid).first;
    if (sum == k) {
      wrt(check(mid).second, '\n');
      return 0;
    }
    if (sum < k)
      l = mid + 1;
    else
      r = mid - 1;
  }
}

```


### Prompt

Please provide a cpp coded solution to the problem described below:

There are N slimes lining up in a row. Initially, the i-th slime from the left has a size of a_i.

Taro is trying to combine all the slimes into a larger slime. He will perform the following operation repeatedly until there is only one slime:

* Choose two adjacent slimes, and combine them into a new slime. The new slime has a size of x + y, where x and y are the sizes of the slimes before combining them. Here, a cost of x + y is incurred. The positional relationship of the slimes does not change while combining slimes.

Find the minimum possible total cost incurred.

Constraints

* All values in input are integers.
* 2 \leq N \leq 400
* 1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_N

Output

Print the minimum possible total cost incurred.

Examples

Input

4
10 20 30 40

Output

190

Input

5
10 10 10 10 10

Output

120

Input

3
1000000000 1000000000 1000000000

Output

5000000000

Input

6
7 6 8 6 1 1

Output

68

### Response

```cpp
#include <bits/stdc++.h>

using namespace std;

const int N = 405;
const long long INF = 9e18 + 5;

int n; long long a[N], sum[N], f[N][N];

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i]; sum[i] = a[i] + sum[i - 1];
  }
  for (int l = n; l > 0; --l) {
    for (int r = l + 1; r <= n; ++r) {
      f[l][r] = INF;
      for (int mid = l; mid < r; ++mid) {
        f[l][r] = min(f[l][r], sum[r] - sum[l - 1] + f[l][mid] + f[mid + 1][r]);
      }
    }
  }
  cout << f[1][n] << endl;
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Heidi the Cow is aghast: cracks in the northern Wall? Zombies gathering outside, forming groups, preparing their assault? This must not happen! Quickly, she fetches her HC2 (Handbook of Crazy Constructions) and looks for the right chapter:

How to build a wall:

  1. Take a set of bricks.
  2. Select one of the possible wall designs. Computing the number of possible designs is left as an exercise to the reader.
  3. Place bricks on top of each other, according to the chosen design.

This seems easy enough. But Heidi is a Coding Cow, not a Constructing Cow. Her mind keeps coming back to point 2b. Despite the imminent danger of a zombie onslaught, she wonders just how many possible walls she could build with up to n bricks.

A wall is a set of wall segments as defined in the easy version. How many different walls can be constructed such that the wall consists of at least 1 and at most n bricks? Two walls are different if there exist a column c and a row r such that one wall has a brick in this spot, and the other does not.

Along with n, you will be given C, the width of the wall (as defined in the easy version). Return the number of different walls modulo 106 + 3.

Input

The first line contains two space-separated integers n and C, 1 ≤ n ≤ 500000, 1 ≤ C ≤ 200000.

Output

Print the number of different walls that Heidi could build, modulo 106 + 3.

Examples

Input

5 1

Output

5

Input

2 2

Output

5

Input

3 2

Output

9

Input

11 5

Output

4367

Input

37 63

Output

230574

Note

The number 106 + 3 is prime.

In the second sample case, the five walls are:

                B        B
    B., .B, BB, B., and .B

In the third sample case, the nine walls are the five as in the second sample case and in addition the following four:

    B    B
    B    B  B        B
    B., .B, BB, and BB

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 8e5 + 5, MOD = 1e6 + 3;
int fact[N], invfact[N];
int mul(int a, int b, int m) { return (1LL * (a % m) * (b % m)) % m; }
int add(int a, int b, int m) { return (1LL * (a % m) + (b % m)) % m; }
int powMOD(int x, int n, int m = MOD) {
  if (!n) return 1;
  int ret = 1;
  if (n & 1)
    ret = mul(x, powMOD(x, n - 1, m), m);
  else {
    int y = powMOD(x, n / 2, m);
    ret = mul(y, y, m);
  }
  return ret;
}
int nCr(int n, int r) {
  if (r < 0 || r > n) return 0;
  return mul(mul(fact[n], invfact[r], MOD), invfact[n - r], MOD);
}
void pre() {
  fact[0] = invfact[0] = 1;
  for (int i = 1; i < N; ++i) fact[i] = mul(i % MOD, fact[i - 1], MOD);
  invfact[N - 1] = powMOD(fact[N - 1], MOD - 2, MOD);
  for (int i = N - 2; ~i; --i)
    invfact[i] = mul(invfact[i + 1], (i + 1) % MOD, MOD);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, c;
  cin >> n >> c;
  pre();
  int ans = nCr(n + c, c) - 1 + MOD;
  if (ans >= MOD) ans -= MOD;
  cout << ans << "\n";
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

You are given a string s of length n. Each character is either one of the first k lowercase Latin letters or a question mark.

You are asked to replace every question mark with one of the first k lowercase Latin letters in such a way that the following value is maximized.

Let f_i be the maximum length substring of string s, which consists entirely of the i-th Latin letter. A substring of a string is a contiguous subsequence of that string. If the i-th letter doesn't appear in a string, then f_i is equal to 0.

The value of a string s is the minimum value among f_i for all i from 1 to k.

What is the maximum value the string can have?

Input

The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 17) — the length of the string and the number of first Latin letters used.

The second line contains a string s, consisting of n characters. Each character is either one of the first k lowercase Latin letters or a question mark.

Output

Print a single integer — the maximum value of the string after every question mark is replaced with one of the first k lowercase Latin letters.

Examples

Input

10 2
a??ab????b

Output

4

Input

9 4
?????????

Output

2

Input

2 3
??

Output

0

Input

15 3
??b?babbc??b?aa

Output

3

Input

4 4
cabd

Output

1

Note

In the first example the question marks can be replaced in the following way: "aaaababbbb". f_1 = 4, f_2 = 4, thus the answer is 4. Replacing it like this is also possible: "aaaabbbbbb". That way f_1 = 4, f_2 = 6, however, the minimum of them is still 4.

In the second example one of the possible strings is "aabbccdda".

In the third example at least one letter won't appear in the string, thus, the minimum of values f_i is always 0.

### Response

```cpp
#include <bits/stdc++.h>

using namespace std;
int n,k,l,r,m,i,j,l1,l2,x,b[20][200004],mask[140004];
char c,s[200004];
int main()
{
    scanf ("%d %d", &n, &k);
    scanf ("%s", &s);
    l=0;
    r=n;
    while (l<=r)
    {
        m=(l+r)/2;
        for (i=0;i<k;i++)
            for (j=0;j<=n;j++)
                b[i][j]=n;
        for (i=0;i<(1<<k);i++)
            mask[i]=n;
        mask[0]=-1;
        c=' ';
        l1=-1;
        l2=-1;
        for (i=0;i<n;i++)
        {
            if (s[i]=='?')
            {
                if ((l1+m)<=i)
                {
                    for (j=0;j<k;j++)
                        b[j][i]=i;
                }
                else if ((l2+m)<=i)
                    b[c-'a'][i]=i;
            }
            else
            {
                if (s[i]==c)
                {
                    if ((l2+m)<=i)
                        b[s[i]-'a'][i]=i;
                    l1=i;
                }
                else
                {
                    if ((l1+m)<=i)
                        b[s[i]-'a'][i]=i;
                    l2=l1;
                    l1=i;
                    c=s[i];
                }
            }
        }
        for (i=0;i<k;i++)
            for (j=(n-1);j>=0;j--)
                b[i][j]=min(b[i][j],b[i][j+1]);
        for (i=1;i<(1<<k);i++)
        {
            for (j=0;j<k;j++)
            {
                if ((i&(1<<j))!=0)
                {
                    x=mask[i-(1<<j)]+m;
                    if (x<=n)
                        mask[i]=min(mask[i],b[j][x]);
                }
            }
        }
        if (mask[(1<<k)-1]<n)
            l=m+1;
        else
            r=m-1;
    }
    printf ("%d\n", r);
    return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Cirno has prepared n arrays of length n each. Each array is a permutation of n integers from 1 to n. These arrays are special: for all 1 ≤ i ≤ n, if we take the i-th element of each array and form another array of length n with these elements, the resultant array is also a permutation of n integers from 1 to n. In the other words, if you put these n arrays under each other to form a matrix with n rows and n columns, this matrix is a [Latin square](https://en.wikipedia.org/wiki/Latin_square).

Afterwards, Cirno added additional n arrays, each array is a permutation of n integers from 1 to n. For all 1 ≤ i ≤ n, there exists at least one position 1 ≤ k ≤ n, such that for the i-th array and the (n + i)-th array, the k-th element of both arrays is the same. Notice that the arrays indexed from n + 1 to 2n don't have to form a Latin square.

Also, Cirno made sure that for all 2n arrays, no two arrays are completely equal, i. e. for all pair of indices 1 ≤ i < j ≤ 2n, there exists at least one position 1 ≤ k ≤ n, such that the k-th elements of the i-th and j-th array are different.

Finally, Cirno arbitrarily changed the order of 2n arrays.

AquaMoon calls a subset of all 2n arrays of size n good if these arrays from a Latin square.

AquaMoon wants to know how many good subsets exist. Because this number may be particularly large, find it modulo 998 244 353. Also, she wants to find any good subset. Can you help her?

Input

The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases.

The first line of each test case contains a single integer n (5 ≤ n ≤ 500).

Then 2n lines followed. The i-th of these lines contains n integers, representing the i-th array.

It is guaranteed, that the sum of n over all test cases does not exceed 500.

Output

For each test case print two lines.

In the first line, print the number of good subsets by modulo 998 244 353.

In the second line, print n indices from 1 to 2n — indices of the n arrays that form a good subset (you can print them in any order). If there are several possible answers — print any of them.

Example

Input

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

Output

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

Note

In the first test case, the number of good subsets is 1. The only such subset is the set of arrays with indices 1, 2, 3, 4, 5, 6, 7.

In the second test case, the number of good subsets is 2. They are 1, 3, 5, 6, 10 or 2, 4, 7, 8, 9.

### Response

```cpp
#include<iostream>
#include <vector>
using namespace std;
const int maxn=500;
const long long mod=998244353;
int n,x,y,s,t;
int a[maxn*2+5][maxn+5],b[maxn+5][maxn+5],f[maxn+5];
vector <pair<int,int>> v;
vector <int> c[maxn+5][maxn+5];
int main(){
    int T; cin>>T;
    while (T--){
        cin>>n;
        for (int i=1;i<=n;i++){
            for (int j=1;j<=n;j++){
                b[i][j]=0;
                c[i][j].clear();
            }
        }
        for (int i=1;i<=n*2;i++){
            f[i]=0;
            for (int j=1;j<=n;j++){
                cin>>a[i][j];
                b[j][a[i][j]]++;
                c[j][a[i][j]].push_back(i);
            }
        }
        int top=0,tail=0;
        int cnt=0,idx=1;
        long long ans=1;
        v.clear();
        for (int i=1;i<=n;i++){
            for (int j=1;j<=n;j++){
                if (b[i][j]==1){
                    tail++;
                    v.push_back(make_pair(i,j));
                }
            }
        }
        while(cnt<n){
            if (top<tail){
                x=v[top].first;
                y=v[top].second;
                if (b[x][y]!=1){
                    top++;
                    continue;
                }
                for (int i=0;i<c[x][y].size();i++){
                    if (f[c[x][y][i]]==0){
                        t=c[x][y][i];
                        break;
                    }
                }
            }
            else{
                while(f[idx]!=0)
                    idx++;
                t=idx;
                ans=ans*2%mod;
            }
            f[t]=1;
            cnt++;
            for (int i=1;i<=n;i++)
                b[i][a[t][i]]=0;
            for (int i=1;i<=n;i++){
                for (int j=0;j<c[i][a[t][i]].size();j++){
                    s=c[i][a[t][i]][j];
                    if(f[s]==0){
                        f[s]=2;
                        for (int k=1;k<=n;k++){
                            b[k][a[s][k]]--;
                            if(b[k][a[s][k]]==1){
                                tail++;
                                v.push_back(make_pair(k,a[s][k]));
                            }
                        }
                    }
                }
            }
            top++;
        }
        s=0;
        cout<<ans<<endl;
        for (int i=1;i<=n*2;i++){
            if (f[i]==1){
                s++;
                if (s<n) cout<<i<<' '; else cout<<i<<endl;
            }
        }
    }
}

```