### Prompt

Generate a CPP solution to the following problem:

An n × n square matrix is special, if:

  * it is binary, that is, each cell contains either a 0, or a 1;
  * the number of ones in each row and column equals 2.

You are given n and the first m rows of the matrix. Print the number of special n × n matrices, such that the first m rows coincide with the given ones.

As the required value can be rather large, print the remainder after dividing the value by the given number mod.

Input

The first line of the input contains three integers n, m, mod (2 ≤ n ≤ 500, 0 ≤ m ≤ n, 2 ≤ mod ≤ 109). Then m lines follow, each of them contains n characters — the first rows of the required special matrices. Each of these lines contains exactly two characters '1', the rest characters are '0'. Each column of the given m × n table contains at most two numbers one.

Output

Print the remainder after dividing the required value by number mod.

Examples

Input

3 1 1000
011

Output

2

Input

4 4 100500
0110
1010
0101
1001

Output

1

Note

For the first test the required matrices are:

    011
    101
    110

    011
    110
    101

In the second test the required matrix is already fully given, so the answer is 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long inf = 2147383647;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
inline long long gcd(long long a, long long b) {
  a = ((a) < 0 ? -(a) : (a));
  b = ((b) < 0 ? -(b) : (b));
  while (b) {
    a = a % b;
    swap(a, b);
  }
  return a;
}
int ext_gcd(int a, int b, int& x, int& y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  int x1, y1;
  int d = ext_gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
inline long long modInv(int a, int m) {
  int x, y;
  ext_gcd(a, m, x, y);
  return x;
}
inline long long power(long long a, long long p) {
  long long res = 1, x = a;
  while (p) {
    if (p & 1) res = (res * x);
    x = (x * x);
    p >>= 1;
  }
  return res;
}
inline long long bigmod(long long a, long long p, long long m) {
  long long res = 1, x = a % m;
  while (p) {
    if (p & 1) res = (res * x) % m;
    x = (x * x) % m;
    p >>= 1;
  }
  return res;
}
int n, m, mod;
char buf[1010][1010];
long long memo[510][510];
long long dp(int row, int zero, int one) {
  if (row == n) {
    if (zero == 0 && one == 0)
      return 1;
    else
      return 0;
  }
  if (memo[zero][one] != -1) return memo[zero][one];
  long long res = 0;
  if (zero >= 2) {
    res += ((zero * (zero - 1)) / 2) * dp(row + 1, zero - 2, one + 2);
    res %= mod;
  }
  if (zero && one) {
    res += zero * one * dp(row + 1, zero - 1, one);
    res %= mod;
  }
  if (one >= 2) {
    res += ((one * (one - 1)) / 2) * dp(row + 1, zero, one - 2);
    res %= mod;
  }
  memo[zero][one] = res;
  return res;
}
int main() {
  memset(memo, -1, sizeof(memo));
  scanf("%d %d %d", &n, &m, &mod);
  int zero = 0, one = 0;
  for (int i = (0); i <= (m - 1); ++i) {
    for (int j = (0); j <= (n - 1); ++j) {
      scanf(" %c", &buf[i][j]);
    }
  }
  for (int i = (0); i <= (n - 1); ++i) {
    int bit = 0;
    for (int j = (0); j <= (m - 1); ++j) {
      if (buf[j][i] == '1') bit++;
    }
    if (bit == 0)
      zero++;
    else if (bit == 1)
      one++;
  }
  long long res = dp(m, zero, one);
  printf("%I64d\n", res);
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.

First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.

Note that to display number 0 section of the watches is required to have at least one place.

Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.

Input

The first line of the input contains two integers, given in the decimal notation, n and m (1 ≤ n, m ≤ 109) — the number of hours in one day and the number of minutes in one hour, respectively.

Output

Print one integer in decimal notation — the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.

Examples

Input

2 3

Output

4

Input

8 2

Output

5

Note

In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).

In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int ans;
int cnt1, cnt2;
int vis[10];
int n, m;
int getNum(int x) {
  int cnt = 1;
  while (x >= 7) {
    x /= 7;
    cnt++;
  }
  return cnt;
}
void dfs(int d, int sum) {
  if (d > cnt1 + cnt2) return;
  if (d <= cnt1 && sum >= n) return;
  if (d > cnt1 && sum >= m) return;
  if (d == cnt1 + cnt2) {
    ans++;
    return;
  }
  for (int i = 0; i < 7; i++) {
    if (!vis[i]) {
      vis[i] = 1;
      if (d == cnt1)
        dfs(d + 1, i);
      else
        dfs(d + 1, sum * 7 + i);
      vis[i] = 0;
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  cnt1 = getNum(n - 1), cnt2 = getNum(m - 1);
  if (n == 1) cnt1 = 1;
  if (m == 1) cnt2 = 1;
  if (cnt1 + cnt2 > 7)
    printf("0\n");
  else {
    dfs(0, 0);
    printf("%d\n", ans);
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths a, b, and c. Now he needs to find out some possible integer length d of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to a, b, c, and d. Help Yura, find any possible length of the fourth side.

A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.

Input

The first line contains a single integer t — the number of test cases (1 ≤ t ≤ 1000). The next t lines describe the test cases.

Each line contains three integers a, b, and c — the lengths of the three fence segments (1 ≤ a, b, c ≤ 10^9).

Output

For each test case print a single integer d — the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.

Example

Input

2
1 2 3
12 34 56

Output

4
42

Note

We can build a quadrilateral with sides 1, 2, 3, 4.

We can build a quadrilateral with sides 12, 34, 56, 42.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    vector<long long int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    cout << a[2] << endl;
  }
}

```


### Prompt

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

You are given an array a_1, a_2, ... , a_n. Array is good if for each pair of indexes i < j the condition j - a_j ≠ i - a_i holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitrarily (leaving the initial order is also an option).

For example, if a = [1, 1, 3, 5], then shuffled arrays [1, 3, 5, 1], [3, 5, 1, 1] and [5, 3, 1, 1] are good, but shuffled arrays [3, 1, 5, 1], [1, 1, 3, 5] and [1, 1, 5, 3] aren't.

It's guaranteed that it's always possible to shuffle an array to meet this condition.

Input

The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases.

The first line of each test case contains one integer n (1 ≤ n ≤ 100) — the length of array a.

The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≤ a_i ≤ 100).

Output

For each test case print the shuffled version of the array a which is good.

Example

Input

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

Output

7
1 5 1 3
2 4 6 1 3 5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[105];
int main() {
  int T, n, i, j;
  cin >> T;
  while (T--) {
    cin >> n;
    for (i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    for (i = n - 1; i >= 0; --i) cout << a[i] << " ";
    cout << endl;
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original problem is in the following paragraph.

People don't use cash as often as they used to. Having a credit card solves some of the hassles of cash, such as having to receive change when you can't form the exact amount of money needed to purchase an item. Typically cashiers will give you as few coins as possible in change, but they don't have to. For example, if your change is 30 cents, a cashier could give you a 5 cent piece and a 25 cent piece, or they could give you three 10 cent pieces, or ten 1 cent pieces, two 5 cent pieces, and one 10 cent piece. Altogether there are 18 different ways to make 30 cents using only 1 cent pieces, 5 cent pieces, 10 cent pieces, and 25 cent pieces. Two ways are considered different if they contain a different number of at least one type of coin. Given the denominations of the coins and an amount of change to be made, how many different ways are there to make change?

As we mentioned before, we lost all the test cases for this problem, so we're actually going to give you the number of ways, and want you to produce a test case for which the number of ways is the given number. There could be many ways to achieve this (we guarantee there's always at least one), so you can print any, as long as it meets the constraints described below.

Input

Input will consist of a single integer A (1 ≤ A ≤ 105), the desired number of ways.

Output

In the first line print integers N and M (1 ≤ N ≤ 106, 1 ≤ M ≤ 10), the amount of change to be made, and the number of denominations, respectively.

Then print M integers D1, D2, ..., DM (1 ≤ Di ≤ 106), the denominations of the coins. All denominations must be distinct: for any i ≠ j we must have Di ≠ Dj.

If there are multiple tests, print any of them. You can print denominations in atbitrary order.

Examples

Input

18

Output

30 4
1 5 10 25

Input

3

Output

20 2
5 2

Input

314

Output

183 4
6 5 2 139

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int res = n * 5 - 5;
  if (res == 0) res = 1;
  cout << res << ' ' << 2 << "\n";
  cout << 1 << ' ' << 5;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases:

  1. They are equal.
  2. If we split string a into two halves of the same size a1 and a2, and string b into two halves of the same size b1 and b2, then one of the following is correct:
    1. a1 is equivalent to b1, and a2 is equivalent to b2
    2. a1 is equivalent to b2, and a2 is equivalent to b1

As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent.

Gerald has already completed this home task. Now it's your turn!

Input

The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200 000 and consists of lowercase English letters. The strings have the same length.

Output

Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.

Examples

Input

aaba
abaa

Output

YES

Input

aabb
abab

Output

NO

Note

In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".

In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa".

### Response

```cpp
#include <bits/stdc++.h>
const int INF = 2000000000;
const long long LLINF = 9000000000000000000LL;
const long double LDINF = 1e300;
using namespace std;
void lexosort(string& a, int s, int l) {
  if (l % 2 == 1) return;
  lexosort(a, s, l / 2);
  lexosort(a, s + l / 2, l / 2);
  bool swap = true;
  for (int i = 0; i < l / 2; ++i) {
    if (a[s + i] < a[s + i + l / 2]) {
      swap = false;
      break;
    }
    if (a[s + i] > a[s + i + l / 2]) {
      swap = true;
      break;
    }
  }
  if (swap) {
    for (int i = 0; i < l / 2; ++i) {
      char tmp = a[s + i];
      a[s + i] = a[s + i + l / 2];
      a[s + i + l / 2] = tmp;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string a, b;
  cin >> a >> b;
  lexosort(a, 0, a.length());
  lexosort(b, 0, b.length());
  cout << (a == b ? "YES" : "NO") << endl;
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

The Berland Forest can be represented as an infinite cell plane. Every cell contains a tree. That is, contained before the recent events.

A destructive fire raged through the Forest, and several trees were damaged by it. Precisely speaking, you have a n × m rectangle map which represents the damaged part of the Forest. The damaged trees were marked as "X" while the remaining ones were marked as ".". You are sure that all burnt trees are shown on the map. All the trees outside the map are undamaged.

The firemen quickly extinguished the fire, and now they are investigating the cause of it. The main version is that there was an arson: at some moment of time (let's consider it as 0) some trees were set on fire. At the beginning of minute 0, only the trees that were set on fire initially were burning. At the end of each minute, the fire spread from every burning tree to each of 8 neighboring trees. At the beginning of minute T, the fire was extinguished.

The firemen want to find the arsonists as quickly as possible. The problem is, they know neither the value of T (how long the fire has been raging) nor the coordinates of the trees that were initially set on fire. They want you to find the maximum value of T (to know how far could the arsonists escape) and a possible set of trees that could be initially set on fire.

Note that you'd like to maximize value T but the set of trees can be arbitrary.

Input

The first line contains two integer n and m (1 ≤ n, m ≤ 10^6, 1 ≤ n ⋅ m ≤ 10^6) — the sizes of the map.

Next n lines contain the map. The i-th line corresponds to the i-th row of the map and contains m-character string. The j-th character of the i-th string is "X" if the corresponding tree is burnt and "." otherwise.

It's guaranteed that the map contains at least one "X".

Output

In the first line print the single integer T — the maximum time the Forest was on fire. In the next n lines print the certificate: the map (n × m rectangle) where the trees that were set on fire are marked as "X" and all other trees are marked as ".".

Examples

Input

3 6
XXXXXX
XXXXXX
XXXXXX

Output

1
......
.X.XX.
......

Input

10 10
.XXXXXX...
.XXXXXX...
.XXXXXX...
.XXXXXX...
.XXXXXXXX.
...XXXXXX.
...XXXXXX.
...XXXXXX.
...XXXXXX.
..........

Output

2
..........
..........
...XX.....
..........
..........
..........
.....XX...
..........
..........
..........

Input

4 5
X....
..XXX
..XXX
..XXX

Output

0
X....
..XXX
..XXX
..XXX

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline const T read1() {
  T m = 0;
  char k = getchar();
  while (('0' > k || k > '9') && (k != '-')) k = getchar();
  const bool f = (k == '-' ? 1 : 0);
  if (f) k = getchar();
  while ('0' <= k && k <= '9')
    m = (m << 3) + (m << 1) + (k ^ 48), k = getchar();
  return f ? -m : m;
}
int s, m, **a, t;
char **str;
bool **vis, **h;
queue<pair<int, int> > q;
bool judge(int n) {
  while (!q.empty()) q.pop();
  int len = n << 1 | 1, op = 0;
  for (int i = 1; i <= s; ++i)
    for (int j = 1; j <= m; ++j) vis[i][j] = h[i][j];
  for (int i = 1; i <= s - len + 1; ++i)
    for (int j = 1; j <= m - len + 1; ++j)
      if (!(a[i + len - 1][j + len - 1] - a[i - 1][j + len - 1] -
            a[i + len - 1][j - 1] + a[i - 1][j - 1]))
        q.push(make_pair(i + n, j + n)), ++op, vis[i + n][j + n] = 1;
  for (int i = 1; i <= n; ++i) {
    int k = q.size();
    while (k--) {
      int x = q.front().first, y = q.front().second;
      q.pop();
      for (int tx = -1; tx <= 1; ++tx)
        for (int ty = -1; ty <= 1; ++ty)
          if (x + tx && x + tx <= s && y + ty && y + ty <= m &&
              !vis[x + tx][y + ty]) {
            vis[x + tx][y + ty] = 1;
            q.push(make_pair(x + tx, y + ty));
            ++op;
          }
    }
  }
  return op == t;
}
int main() {
  s = read1<int>(), m = read1<int>();
  str = new char *[s + 5];
  a = new int *[s + 5];
  vis = new bool *[s + 5];
  h = new bool *[s + 5];
  a[0] = new int[m + 5]();
  vis[0] = new bool[m + 5]();
  h[0] = new bool[m + 5]();
  for (int i = 1; i <= s; ++i) {
    str[i] = new char[m + 5];
    vis[i] = new bool[m + 5]();
    h[i] = new bool[m + 5]();
    a[i] = new int[m + 5]();
    scanf("%s", str[i] + 1);
    for (int j = 1; j <= m; ++j)
      a[i][j] = a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1] +
                (h[i][j] = str[i][j] == '.'),
      t += str[i][j] == 'X';
  }
  int l = 1, r = min(s, m) - 1 >> 1, ans = 0, mid;
  while (l <= r) judge(mid = l + r >> 1) ? ans = mid, l = mid + 1 : r = mid - 1;
  printf("%d\n", ans);
  for (int i = 1; i <= s; ++i)
    for (int j = 1; j <= m; ++j) vis[i][j] = 0;
  int len = ans << 1 | 1;
  for (int i = 1; i <= s - len + 1; ++i)
    for (int j = 1; j <= m - len + 1; ++j)
      if (!(a[i + len - 1][j + len - 1] - a[i - 1][j + len - 1] -
            a[i + len - 1][j - 1] + a[i - 1][j - 1]))
        vis[i + ans][j + ans] = 1;
  for (int i = 1; i <= s; ++i, putchar('\n'))
    for (int j = 1; j <= m; ++j) putchar(vis[i][j] ? 'X' : '.');
  return 0;
}

```


### Prompt

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

There are n people in a row. The height of the i-th person is a_i. You can choose any subset of these people and try to arrange them into a balanced circle.

A balanced circle is such an order of people that the difference between heights of any adjacent people is no more than 1. For example, let heights of chosen people be [a_{i_1}, a_{i_2}, ..., a_{i_k}], where k is the number of people you choose. Then the condition |a_{i_j} - a_{i_{j + 1}}| ≤ 1 should be satisfied for all j from 1 to k-1 and the condition |a_{i_1} - a_{i_k}| ≤ 1 should be also satisfied. |x| means the absolute value of x. It is obvious that the circle consisting of one person is balanced.

Your task is to choose the maximum number of people and construct a balanced circle consisting of all chosen people. It is obvious that the circle consisting of one person is balanced so the answer always exists.

Input

The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of people.

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 2 ⋅ 10^5), where a_i is the height of the i-th person.

Output

In the first line of the output print k — the number of people in the maximum balanced circle.

In the second line print k integers res_1, res_2, ..., res_k, where res_j is the height of the j-th person in the maximum balanced circle. The condition |res_{j} - res_{j + 1}| ≤ 1 should be satisfied for all j from 1 to k-1 and the condition |res_{1} - res_{k}| ≤ 1 should be also satisfied.

Examples

Input

7
4 3 5 1 2 2 1

Output

5
2 1 1 2 3

Input

5
3 7 5 1 5

Output

2
5 5

Input

3
5 1 4

Output

2
4 5

Input

7
2 2 3 2 1 2 2

Output

7
1 2 2 2 2 3 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> v(n + 1, 0), freq(200001 + 1, 0), one(200001 + 1, 0),
      two(200001 + 1, 0), f(200001 + 1, 0);
  for (unsigned long long i = 1; i < n + 1; i++) cin >> v[i], freq[v[i]]++;
  f = freq;
  for (int i = 1; i < 200001; i++) {
    one[i] += one[i - 1];
    two[i] += two[i - 1];
    if (freq[i])
      one[i]++;
    else
      one[i] = 0;
    if (freq[i] > 1)
      two[i]++;
    else
      two[i] = 0;
  }
  for (unsigned long long i = 1; i < 200001; i++) freq[i] += freq[i - 1];
  long long mx, r, l;
  mx = 0;
  r = 0;
  l = 0;
  for (int i = 1; i < 200001; i++) {
    int maybe = freq[i + 1];
    if (i - two[i] - 1 >= 0) maybe -= freq[i - two[i] - 1];
    if (maybe > mx) {
      mx = maybe;
      r = i + (one[i + 1] != 0);
      l = i - two[i] + 1 - (one[i - two[i]] != 0);
    }
  }
  cout << mx << endl;
  for (int i = l; i <= r; i++) {
    for (int j = 0; j < f[i] - 1; j++) cout << i << " ";
  }
  for (int i = r; i >= l; i--) {
    cout << i << " ";
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Little girl Susie went shopping with her mom and she wondered how to improve service quality.

There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed.

Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue.

Input

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

The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces.

Output

Print a single number — the maximum number of not disappointed people in the queue.

Examples

Input

5
15 2 1 5 3

Output

4

Note

Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  ;
  int t;
  cin >> t;
  long long arr[t], ar[t];
  for (int i = 0; i < t; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + t);
  int cnt = 1;
  long long tmp;
  ar[0] = arr[0];
  int j = 1;
  for (int i = 1; i < t; i++) {
    if (arr[i] >= ar[j - 1]) {
      tmp = ar[j - 1] + arr[i];
      cnt++;
      ar[j] = tmp;
      j++;
    }
  }
  cout << cnt << endl;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1, p2, ..., pn.

We'll call position i (1 ≤ i ≤ n) in permutation p1, p2, ..., pn good, if |p[i] - i| = 1. Count the number of permutations of size n with exactly k good positions. Print the answer modulo 1000000007 (109 + 7).

Input

The single line contains two space-separated integers n and k (1 ≤ n ≤ 1000, 0 ≤ k ≤ n).

Output

Print the number of permutations of length n with exactly k good positions modulo 1000000007 (109 + 7).

Examples

Input

1 0

Output

1

Input

2 1

Output

0

Input

3 2

Output

4

Input

4 1

Output

6

Input

7 4

Output

328

Note

The only permutation of size 1 has 0 good positions.

Permutation (1, 2) has 0 good positions, and permutation (2, 1) has 2 positions.

Permutations of size 3:

  1. (1, 2, 3) — 0 positions
  2. <image> — 2 positions
  3. <image> — 2 positions
  4. <image> — 2 positions
  5. <image> — 2 positions
  6. (3, 2, 1) — 0 positions

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
const long long mo = 1000000007;
int n, m;
long long f[maxn], g[maxn], c[maxn][maxn], dp[maxn][maxn][2][2];
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    memset(g, 0, sizeof(g));
    memset(f, 0, sizeof(f));
    memset(c, 0, sizeof(c));
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i <= n; ++i) dp[i][0][0][0] = 1;
    f[0] = 1;
    for (int i = 1; i <= n; ++i) f[i] = f[i - 1] * i % mo;
    for (int i = 0; i <= n; ++i) c[i][0] = c[i][i] = 1;
    for (int i = 0; i <= n; ++i)
      for (int j = 1; j < n; ++j)
        c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mo;
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= i; ++j) {
        if (i > 1)
          dp[i][j][0][0] = (dp[i - 1][j][0][0] + dp[i - 1][j][1][0] +
                            dp[i - 1][j - 1][0][0]) %
                           mo;
        dp[i][j][1][0] =
            (dp[i - 1][j][0][1] + dp[i - 1][j][1][1] + dp[i - 1][j - 1][0][1]) %
            mo;
        if (i < n) {
          dp[i][j][0][1] =
              (dp[i - 1][j - 1][0][0] + dp[i - 1][j - 1][1][0]) % mo;
          dp[i][j][1][1] =
              (dp[i - 1][j - 1][0][1] + dp[i - 1][j - 1][1][1]) % mo;
        }
      }
    for (int i = 0; i <= n; ++i)
      g[i] =
          (dp[n][i][0][0] + dp[n][i][0][1] + dp[n][i][1][0] + dp[n][i][1][1]) *
          f[n - i] % mo;
    long long ans = 0;
    for (int i = 0; i <= n - m; ++i)
      ans = (ans + c[m + i][m] * g[m + i] * (i & 1 ? -1 : 1) + mo) % mo;
    printf("%I64d\n", ans);
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Example

Input

ACM

Output

0

### Response

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

string S;
int idx;
int N, M;
string alphas;
int curr;

bool try_consume(char c) {
  if(S[idx] != c) return false;
  idx ++;
  return true;
}

int E();

int convert(string const& b) {
  int n = b.size();
  int ret = 0;
  for(int i=0; i<n; i++) {
    ret *= 2;
    assert(isdigit(b[i]));
    ret += b[i] - '0';
  }
  return ret;
}

string B() {
  string ret;
  while(1) {
    if(S[idx] == '0') ret += '0';
    else if(S[idx] == '1') ret += '1';
    else break;
    idx++;
  }
  return ret;
}

int Nu() {
  if(try_consume('0')) return 0;
  if(!try_consume('1')) return -inf;
  return convert("1" + B());
}

int F() {
  if(try_consume('-')) {
    int f = F();
    if(f == -inf) return -inf;
    return -f;
  }
  else if(try_consume('(')) {
    int r = E();
    if(!try_consume(')')) return -inf;
    return r;
  }
  else {
    return Nu();
  }
}

int T() {
  int num1 = F();
  if(num1 == -inf) return -inf;
  while(try_consume('*')) {
    int num2 = F();
    if(num2 == -inf) return -inf;
    num1 *= num2;
  }
  return num1;
}

int E() {
  int term1 = T();
  if(term1 == -inf) return -inf;
  while(1) {
    bool cont = 0;
    while(try_consume('+')) {
      cont = 1;
      int term2 = T();
      if(term2 == -inf) return -inf;
      term1 += term2;
    }
    while(try_consume('-')) {
      cont = 1;
      int term2 = T();
      if(term2 == -inf) return -inf;
      term1 -= term2;
    }
    if(!cont) break;
  }
  return term1;
}

bool Q() {
  int expr1 = E();
  if(expr1 == -inf) return false;
  if(!try_consume('=')) return false;
  int expr2 = E();
  if(expr2 == -inf) return false;
  return expr1 == expr2 && idx == N;
}

int main() {

  string T = "01+-*()=";
  sort(T.begin(), T.end());
  string RS; cin >> RS;
  N = RS.size();
  for(auto c: RS) if(isalpha(c)) alphas.push_back(c);
  sort(alphas.begin(), alphas.end());
  alphas.erase(unique(alphas.begin(), alphas.end()), alphas.end());
  M = alphas.size();

  if(M > T.size()) {
    cout << 0 << endl;
    return 0;
  }

  int ans = 0;
  set<string> st;
  do {
    S = RS;
    rep(i, N) {
      if(isalpha(S[i])) S[i] = T[alphas.find(S[i])];
    }
    if(!st.count(S)) {
      st.insert(S);
      idx = curr = 0;
      ans += Q();
    }
  } while(next_permutation(T.begin(), T.end()));

  cout << ans << endl;

  return 0;
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

It is dark times in Berland. Berlyand opposition, funded from a neighboring state, has organized a demonstration in Berland capital Bertown. Through the work of intelligence we know that the demonstrations are planned to last for k days.

Fortunately, Berland has a special police unit, which can save the country. It has exactly n soldiers numbered from 1 to n. Berland general, the commander of the detachment, must schedule the detachment's work in these difficult k days. In each of these days, the general must send a certain number of police officers to disperse riots. Since the detachment is large and the general is not very smart, he can only select a set of all soldiers numbered from l to r, inclusive, where l and r are selected arbitrarily.

Now the general has exactly two problems. First, he cannot send the same group twice — then soldiers get bored and they rebel. Second, not all soldiers are equally reliable. Every soldier has a reliability of ai. The reliability of the detachment is counted as the sum of reliabilities of soldiers in it. The reliability of a single soldier can be negative, then when you include him in the detachment, he will only spoil things. The general is distinguished by his great greed and shortsightedness, so each day he sends to the dissolution the most reliable group of soldiers possible (that is, of all the groups that have not been sent yet).

The Berland Government has decided to know what would be the minimum reliability of the detachment, sent to disperse the demonstrations during these k days. The general himself can not cope with such a difficult task. Help him to not embarrass himself in front of his superiors!

Input

The first line contains two integers n and k <image> — the number of soldiers in the detachment and the number of times somebody goes on duty.

The second line contains n space-separated integers ai, their absolute value doesn't exceed 109 — the soldiers' reliabilities.

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

Output

Print a single number — the sought minimum reliability of the groups that go on duty during these k days.

Examples

Input

3 4
1 4 2

Output

4

Input

4 6
2 -1 2 -1

Output

1

Input

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

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
struct Poi {
  long long x;
  int y;
  bool operator<(const Poi& i) const {
    if (x == i.x) return y < i.y;
    return x < i.x;
  }
} s[maxn];
int N, d[maxn], te, a[maxn];
int lowbit(int x) { return x & (-x); }
void ser(int v) {
  for (int i = v; i; i -= lowbit(i)) te += d[i];
}
void inser(int v) {
  for (int i = v; i <= N; i += lowbit(i)) ++d[i];
}
long long calc(long long limit) {
  memset(d, 0, sizeof(d));
  int t(1);
  long long ans(0);
  for (int i = 1; i <= N; ++i) {
    while (t <= N && s[i].x - s[t].x >= limit) inser(s[t++].y);
    te = 0;
    if (s[i].y != 1) ser(s[i].y - 1);
    ans += te;
  }
  return ans;
}
int main() {
  long long K;
  cin >> N >> K;
  ++N;
  for (int i = 2; i <= N; ++i) scanf("%d", &a[i]);
  s[1].x = 0;
  for (int i = 1; i <= N; ++i) s[i].x = s[i - 1].x + a[i];
  for (int i = 1; i <= N; ++i) s[i].y = i;
  sort(s + 1, s + 1 + N);
  long long l = 0, r = 0;
  for (int i = 1; i <= N; ++i) (a[i] < 0) ? l += a[i] : r += a[i];
  long long mid = (l + r) >> 1, ans(-1);
  for (; l <= r; mid = (l + r) >> 1)
    if (calc(mid) >= K)
      l = mid + 1, ans = mid;
    else
      r = mid - 1;
  cout << ans << endl;
}

```


### Prompt

Please create a solution in CPP to the following problem:

T is playing a game with his friend, HL.

There are n piles of stones, the i-th pile initially has a_i stones.

T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in the previous turn (the pile that was chosen by the other player, or if the current turn is the first turn then the player can choose any non-empty pile). The player who cannot choose a pile in his turn loses, and the game ends.

Assuming both players play optimally, given the starting configuration of t games, determine the winner of each game.

Input

The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of games. The description of the games follows. Each description contains two lines:

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of piles.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100).

Output

For each game, print on a single line the name of the winner, "T" or "HL" (without quotes)

Example

Input

2
1
2
2
1 1

Output

T
HL

Note

In the first game, T removes a single stone from the only pile in his first turn. After that, although the pile still contains 1 stone, HL cannot choose from this pile because it has been chosen by T in the previous turn. Therefore, T is the winner.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mxx = 1e5 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    int a[n];
    int sum = 0, mx = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum += a[i];
      mx = max(mx, a[i]);
    }
    if (n == 1) {
      cout << "T"
           << "\n";
    } else if (n == 2) {
      if (a[0] == a[1])
        cout << "HL\n";
      else
        cout << "T\n";
    } else {
      if (mx > sum - mx || sum % 2)
        cout << "T\n";
      else
        cout << "HL\n";
    }
  }
}

```


### Prompt

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

You still have partial information about the score during the historic football match. You are given a set of pairs (a_i, b_i), indicating that at some point during the match the score was "a_i: b_i". It is known that if the current score is «x:y», then after the goal it will change to "x+1:y" or "x:y+1". What is the largest number of times a draw could appear on the scoreboard?

The pairs "a_i:b_i" are given in chronological order (time increases), but you are given score only for some moments of time. The last pair corresponds to the end of the match.

Input

The first line contains a single integer n (1 ≤ n ≤ 10000) — the number of known moments in the match.

Each of the next n lines contains integers a_i and b_i (0 ≤ a_i, b_i ≤ 10^9), denoting the score of the match at that moment (that is, the number of goals by the first team and the number of goals by the second team).

All moments are given in chronological order, that is, sequences x_i and y_j are non-decreasing. The last score denotes the final result of the match.

Output

Print the maximum number of moments of time, during which the score was a draw. The starting moment of the match (with a score 0:0) is also counted.

Examples

Input

3
2 0
3 1
3 4

Output

2

Input

3
0 0
0 0
0 0

Output

1

Input

1
5 4

Output

5

Note

In the example one of the possible score sequences leading to the maximum number of draws is as follows: 0:0, 1:0, 2:0, 2:1, 3:1, 3:2, 3:3, 3:4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n;
pair<int, int> a[10005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  long long ans = 1;
  long long xx = 0, yy = 0;
  for (int i = 0; i < n; ++i) {
    long long x, y;
    cin >> x >> y;
    long long mx = max(xx, yy);
    long long mn = min(x, y);
    if (mn >= mx) ans += mn - mx + (xx != yy);
    xx = x;
    yy = y;
  }
  cout << ans;
  return 0;
}

```


### Prompt

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

We have N gemstones labeled 1 through N.

You can perform the following operation any number of times (possibly zero).

* Select a positive integer x, and smash all the gems labeled with multiples of x.

Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan). However, a_i may be negative, in which case you will be charged money.

By optimally performing the operation, how much yen can you earn?

Constraints

* All input values are integers.
* 1 \leq N \leq 100
* |a_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the maximum amount of money that can be earned.

Examples

Input

6
1 2 -6 4 5 3

Output

12

Input

6
100 -100 -100 -100 100 -100

Output

200

Input

5
-1 -2 -3 -4 -5

Output

0

Input

2
-1000 100000

Output

99000

### Response

```cpp
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

struct edge {
	int to; // 行き先
	ll cap; // 容量
	int rev; // 逆辺
	edge() {}
	edge(int to, ll cap, int rev) :to(to), cap(cap), rev(rev) {}
};

vector<vector<edge>> G; // グラフの隣接リスト表現
vector<int> used; // DFSですでに調べたらフラグ

				  // fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(int from, int to, ll cap) {
	G[from].push_back(edge(to, cap, G[to].size()));
	G[to].push_back(edge(from, 0, G[from].size() - 1));
}

// 増加パスをDFSで探す
ll dfs(int v, int t, ll f) {
	if (v == t) return f;
	used[v] = true;
	for (int i = 0; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (!used[e.to] && e.cap > 0) {
			ll d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

// sからtへの最大流を求める
ll max_flow(int s, int t) {
	ll flow = 0;
	for (;;) {
		fill(used.begin(), used.end(), 0);
		ll f = dfs(s, t, INF);
		if (f == 0) return flow;
		flow += f;
	}
}

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N; cin >> N;
	G.resize(N + 2); used.resize(N + 2);

	ll Sum = 0;
	for (int i = 1; i <= N;i++) {
		ll a; cin >> a;
		for (int j = 2 * i; j <= N; j += i) add_edge(i, j, LINF);
		if (a > 0) {
			Sum += a;
			add_edge(i, N + 1, a);
		}
		else {
			add_edge(0, i, -a);
		}
	}
	cout << Sum - max_flow(0, N + 1) << endl;
	return 0;
}
```


### Prompt

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

problem

Five students, Taro, Jiro, Saburo, Shiro, and Hanako, participated in the JOI High School class.

In this class, a final exam was conducted. All five people took the final exam. For students with a final exam score of 40 or higher, the final exam score was used as is. All students with a final exam score of less than 40 received supplementary lessons and scored 40 points.

Create a program that calculates the average score of the five students' grades given the final exam scores of the five students.

Example

Input

10
65
100
30
95

Output

68

### Response

```cpp
#include <iostream>

using namespace std;

int main(){
    int s=0;
    int n=5;
    while(n--){
        int t; cin>>t;
        s+=max(t,40);
    }
    cout<<s/5<<endl;
}
```


### Prompt

Please formulate a CPP solution to the following problem:

There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:

  * alloc n — to allocate n bytes of the memory and return the allocated block's identifier x;
  * erase x — to erase the block with the identifier x;
  * defragment — to defragment the free memory, bringing all the blocks as close to the beginning of the memory as possible and preserving their respective order;

The memory model in this case is very simple. It is a sequence of m bytes, numbered for convenience from the first to the m-th.

The first operation alloc n takes as the only parameter the size of the memory block that is to be allocated. While processing this operation, a free block of n successive bytes is being allocated in the memory. If the amount of such blocks is more than one, the block closest to the beginning of the memory (i.e. to the first byte) is prefered. All these bytes are marked as not free, and the memory manager returns a 32-bit integer numerical token that is the identifier of this block. If it is impossible to allocate a free block of this size, the function returns NULL.

The second operation erase x takes as its parameter the identifier of some block. This operation frees the system memory, marking the bytes of this block as free for further use. In the case when this identifier does not point to the previously allocated block, which has not been erased yet, the function returns ILLEGAL_ERASE_ARGUMENT.

The last operation defragment does not have any arguments and simply brings the occupied memory sections closer to the beginning of the memory without changing their respective order.

In the current implementation you are to use successive integers, starting with 1, as identifiers. Each successful alloc operation procession should return following number. Unsuccessful alloc operations do not affect numeration.

You are to write the implementation of the memory manager. You should output the returned value for each alloc command. You should also output ILLEGAL_ERASE_ARGUMENT for all the failed erase commands.

Input

The first line of the input data contains two positive integers t and m (1 ≤ t ≤ 100;1 ≤ m ≤ 100), where t — the amount of operations given to the memory manager for processing, and m — the available memory size in bytes. Then there follow t lines where the operations themselves are given. The first operation is alloc n (1 ≤ n ≤ 100), where n is an integer. The second one is erase x, where x is an arbitrary 32-bit integer numerical token. The third operation is defragment.

Output

Output the sequence of lines. Each line should contain either the result of alloc operation procession , or ILLEGAL_ERASE_ARGUMENT as a result of failed erase operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of alloc operation should return integers, starting with 1, as the identifiers of the allocated blocks.

Examples

Input

6 10
alloc 5
alloc 3
erase 1
alloc 6
defragment
alloc 6

Output

1
2
NULL
3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long m, t, M[110];
long long id = 1;
void alc(long long n) {
  for (long long i = 1; i <= m - n + 1; i++) {
    long long j;
    for (j = i; j < i + n; j++)
      if (M[j]) break;
    if (j < i + n) continue;
    for (j = i; j < i + n; j++) M[j] = id;
    cout << id++ << '\n';
    return;
  }
  cout << "NULL\n";
}
void ers(long long n) {
  long long cnt = 0;
  for (long long i = 1; i <= 100; i++)
    if (M[i] == n && M[i] >= 1 && M[i] <= 100) M[i] = 0, cnt++;
  if (!cnt) cout << "ILLEGAL_ERASE_ARGUMENT\n";
}
void frg() {
  vector<long long> v;
  for (long long i = 1; i <= 100; i++)
    if (M[i]) v.push_back(M[i]);
  memset(M, 0, sizeof(M));
  long long L = v.size();
  for (long long i = 1; i <= L; i++) M[i] = v[i - 1];
}
int main() {
  cin >> t >> m;
  while (t--) {
    string s;
    cin >> s;
    if (s == "alloc") {
      long long x;
      cin >> x;
      alc(x);
    }
    if (s == "erase") {
      long long x;
      cin >> x;
      ers(x);
    }
    if (s == "defragment") {
      frg();
    }
  }
  return 0;
}

```


### Prompt

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

Today is tuesday, that means there is a dispute in JOHNNY SOLVING team again: they try to understand who is Johnny and who is Solving. That's why guys asked Umnik to help them. Umnik gave guys a connected graph with n vertices without loops and multiedges, such that a degree of any vertex is at least 3, and also he gave a number 1 ≤ k ≤ n. Because Johnny is not too smart, he promised to find a simple path with length at least n/k in the graph. In reply, Solving promised to find k simple by vertices cycles with representatives, such that:

  * Length of each cycle is at least 3.
  * Length of each cycle is not divisible by 3.
  * In each cycle must be a representative - vertex, which belongs only to this cycle among all printed cycles.

You need to help guys resolve the dispute, for that you need to find a solution for Johnny: a simple path with length at least n/k (n is not necessarily divided by k), or solution for Solving: k cycles that satisfy all the conditions above. If there is no any solution - print -1.

Input

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

Next m lines describe edges of the graph in format v, u (1 ≤ v, u ≤ n). It's guaranteed that v ≠ u and all m pairs are distinct.

It's guaranteed that a degree of each vertex is at least 3.

Output

Print PATH in the first line, if you solve problem for Johnny. In the second line print the number of vertices in the path c (c ≥ n/k). And in the third line print vertices describing the path in route order.

Print CYCLES in the first line, if you solve problem for Solving. In the following lines describe exactly k cycles in the following format: in the first line print the size of the cycle c (c ≥ 3). In the second line print the cycle in route order. Also, the first vertex in the cycle must be a representative.

Print -1 if there is no any solution. The total amount of printed numbers in the output must be at most 10^6. It's guaranteed, that if exists any solution then there is a correct output satisfies this restriction.

Examples

Input

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

Output

PATH
4
1 2 3 4

Input

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

Output

CYCLES
4
4 1 2 3
4
7 1 5 6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
int n, k, m, a, b, u;
int t[N];
vector<int> v1[N];
vector<int> v[N];
vector<int> w[N];
bool odw[N];
int o[N];
int xd = -1;
int dd;
int dist[N];
vector<int> leafs;
void dfs1(int a, int d, int oj) {
  odw[a] = true;
  for (int i = 0; i < v1[a].size(); i++) {
    u = v1[a][i];
    if (!odw[u]) {
      o[u] = a;
      v[a].push_back(u);
      dfs1(u, d + 1, a);
    } else {
      if (u != a) w[u].push_back(a);
    }
  }
  if (d >= n / k + int(n % k == 0) && xd == -1) {
    xd = a;
    dd = d;
  }
}
void dfs(int a) {
  for (int i = 0; i < v[a].size(); i++) {
    u = v[a][i];
    dist[u] = dist[a] + 1;
    dfs(u);
  }
  if (v[a].size() == 0) leafs.push_back(a);
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    v1[a].push_back(b);
    v1[b].push_back(a);
  }
  dfs1(1, 1, -1);
  if (xd != -1) {
    cout << "PATH\n";
    cout << dd << "\n";
    vector<int> ans;
    while (xd != 1) {
      ans.push_back(xd);
      xd = o[xd];
    }
    cout << 1 << " ";
    for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i] << " ";
    return 0;
  }
  dfs(1);
  dist[1] = 0;
  cout << "CYCLES\n";
  for (int id = 0; id < k; id++) {
    int l = leafs[id], x = w[l][0], y = w[l][1];
    if ((dist[l] - dist[x] + 1) % 3 != 0) {
      cout << dist[l] - dist[x] + 1 << "\n";
      while (l != x) {
        cout << l << " ";
        l = o[l];
      }
      cout << x << "\n";
    } else if ((dist[l] - dist[y] + 1) % 3 != 0) {
      cout << dist[l] - dist[y] + 1 << "\n";
      while (l != y) {
        cout << l << " ";
        l = o[l];
      }
      cout << y << "\n";
    } else {
      if (dist[x] < dist[y]) swap(x, y);
      cout << dist[x] - dist[y] + 2 << "\n";
      cout << l << " ";
      while (x != y) {
        cout << x << " ";
        x = o[x];
      }
      cout << y << "\n";
    }
  }
}

```


### Prompt

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

One night, having had a hard day at work, Petya saw a nightmare. There was a binary search tree in the dream. But it was not the actual tree that scared Petya. The horrifying thing was that Petya couldn't search for elements in this tree. Petya tried many times to choose key and look for it in the tree, and each time he arrived at a wrong place. Petya has been racking his brains for long, choosing keys many times, but the result was no better. But the moment before Petya would start to despair, he had an epiphany: every time he was looking for keys, the tree didn't have the key, and occured exactly one mistake. "That's not a problem!", thought Petya. "Why not count the expectation value of an element, which is found when I search for the key". The moment he was about to do just that, however, Petya suddenly woke up.

Thus, you are given a binary search tree, that is a tree containing some number written in the node. This number is called the node key. The number of children of every node of the tree is equal either to 0 or to 2. The nodes that have 0 children are called leaves and the nodes that have 2 children, are called inner. An inner node has the left child, that is the child whose key is less than the current node's key, and the right child, whose key is more than the current node's key. Also, a key of any node is strictly larger than all the keys of the left subtree of the node and strictly smaller than all the keys of the right subtree of the node.

Also you are given a set of search keys, all of which are distinct and differ from the node keys contained in the tree. For each key from the set its search in the tree is realised. The search is arranged like this: initially we are located in the tree root, if the key of the current node is larger that our search key, then we move to the left child of the node, otherwise we go to the right child of the node and the process is repeated. As it is guaranteed that the search key is not contained in the tree, the search will always finish in some leaf. The key lying in the leaf is declared the search result.

It is known for sure that during the search we make a mistake in comparing exactly once, that is we go the wrong way, but we won't make any mistakes later. All possible mistakes are equiprobable, that is we should consider all such searches where exactly one mistake occurs. Your task is to find the expectation (the average value) of the search result for every search key, considering that exactly one mistake occurs in the search. That is, for a set of paths containing exactly one mistake in the given key search, you should count the average value of keys containing in the leaves of those paths.

Input

The first line contains an odd integer n (3 ≤ n < 105), which represents the number of tree nodes. Next n lines contain node descriptions. The (i + 1)-th line contains two space-separated integers. The first number is the number of parent of the i-st node and the second number is the key lying in the i-th node. The next line contains an integer k (1 ≤ k ≤ 105), which represents the number of keys for which you should count the average value of search results containing one mistake. Next k lines contain the actual keys, one key per line.

All node keys and all search keys are positive integers, not exceeding 109. All n + k keys are distinct.

All nodes are numbered from 1 to n. For the tree root "-1" (without the quote) will be given instead of the parent's node number. It is guaranteed that the correct binary search tree is given. For each node except for the root, it could be determined according to its key whether it is the left child or the right one.

Output

Print k real numbers which are the expectations of answers for the keys specified in the input. The answer should differ from the correct one with the measure of absolute or relative error not exceeding 10 - 9.

Examples

Input

7
-1 8
1 4
1 12
2 2
2 6
3 10
3 14
1
1

Output

8.0000000000

Input

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

Output

7.0000000000
7.0000000000
7.0000000000
3.0000000000
3.0000000000
3.0000000000

Note

In the first sample the search of key 1 with one error results in two paths in the trees: (1, 2, 5) and (1, 3, 6), in parentheses are listed numbers of nodes from the root to a leaf. The keys in the leaves of those paths are equal to 6 and 10 correspondingly, that's why the answer is equal to 8.

### Response

```cpp
#include <bits/stdc++.h>
void intIntSort(int d[], int m[], int s) {
  int i = -1, j = s, k, t;
  if (s <= 1) return;
  k = (d[0] + d[s - 1]) / 2;
  for (;;) {
    while (d[++i] < k)
      ;
    while (d[--j] > k)
      ;
    if (i >= j) break;
    t = d[i];
    d[i] = d[j];
    d[j] = t;
    t = m[i];
    m[i] = m[j];
    m[j] = t;
  }
  intIntSort(d, m, i);
  intIntSort(d + j + 1, m + j + 1, s - j - 1);
}
int n, qs;
int q[200000], q_ind[200000];
int root;
int left[200000], right[200000], up[200000], num[200000];
double sum[200000], per[200000];
int mi[200000], mx[200000];
int mx_node[200000], mn_node[200000];
int res_size;
double res[200000];
void pre_cal(int node) {
  if (left[node] == -1) {
    mx_node[node] = mn_node[node] = num[node];
    return;
  }
  pre_cal(left[node]);
  pre_cal(right[node]);
  mn_node[node] = mn_node[left[node]];
  mx_node[node] = mx_node[right[node]];
}
void solve(int node) {
  int i, j, k;
  int nx;
  if (left[node] == -1) {
    while (res_size < qs && mi[node] <= q[res_size] &&
           q[res_size] <= mx[node]) {
      res[q_ind[res_size]] = sum[node] / per[node];
      res_size++;
    }
    return;
  }
  nx = left[node];
  mi[nx] = mi[node];
  mx[nx] = num[node] - 1;
  sum[nx] = sum[node] + mn_node[right[node]];
  per[nx] = per[node] + 1;
  solve(nx);
  nx = right[node];
  mi[nx] = num[node] + 1;
  mx[nx] = mx[node];
  sum[nx] = sum[node] + mx_node[left[node]];
  per[nx] = per[node] + 1;
  solve(nx);
}
int main() {
  int i, j, k, l, m;
  while (scanf("%d", &n) == 1) {
    for (i = 0; i < n; i++) scanf("%d%d", up + i, num + i), up[i]--;
    scanf("%d", &qs);
    for (i = 0; i < qs; i++) scanf("%d", q + i);
    for (i = 0; i < n; i++) left[i] = right[i] = -1;
    for (i = 0; i < n; i++) {
      if (up[i] < 0) {
        root = i;
        continue;
      }
      if (num[i] < num[up[i]]) left[up[i]] = i;
      if (num[i] > num[up[i]]) right[up[i]] = i;
    }
    for (i = 0; i < qs; i++) q_ind[i] = i;
    intIntSort(q, q_ind, qs);
    pre_cal(root);
    res_size = 0;
    mi[root] = -2000000000;
    mx[root] = 2000000000;
    solve(root);
    for (i = 0; i < qs; i++) printf("%.10f\n", res[i]);
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.

Recently, she was presented with an array a of the size of 10^9 elements that is filled as follows:

  * a_1 = -1
  * a_2 = 2
  * a_3 = -3
  * a_4 = 4
  * a_5 = -5
  * And so on ...

That is, the value of the i-th element of the array a is calculated using the formula a_i = i ⋅ (-1)^i.

She immediately came up with q queries on this array. Each query is described with two numbers: l and r. The answer to a query is the sum of all the elements of the array at positions from l to r inclusive.

Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.

Help her find the answers!

Input

The first line contains a single integer q (1 ≤ q ≤ 10^3) — the number of the queries.

Each of the next q lines contains two integers l and r (1 ≤ l ≤ r ≤ 10^9) — the descriptions of the queries.

Output

Print q lines, each containing one number — the answer to the query.

Example

Input

5
1 3
2 5
5 5
4 4
2 3

Output

-2
-2
-5
4
-1

Note

In the first query, you need to find the sum of the elements of the array from position 1 to position 3. The sum is equal to a_1 + a_2 + a_3 = -1 + 2 -3 = -2.

In the second query, you need to find the sum of the elements of the array from position 2 to position 5. The sum is equal to a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2.

In the third query, you need to find the sum of the elements of the array from position 5 to position 5. The sum is equal to a_5 = -5.

In the fourth query, you need to find the sum of the elements of the array from position 4 to position 4. The sum is equal to a_4 = 4.

In the fifth query, you need to find the sum of the elements of the array from position 2 to position 3. The sum is equal to a_2 + a_3 = 2 - 3 = -1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    long long int l, r, sum1, sum2, x1, y1, x2, y2;
    cin >> l >> r;
    x1 = r / 2;
    x1 = x1 * (x1 + 1);
    x2 = (l - 1) / 2;
    x2 = x2 * (x2 + 1);
    sum1 = x1 - x2;
    r = ceil(r / 2.0);
    y1 = pow(r, 2);
    l = ceil((l - 1) / 2.0);
    y2 = pow(l, 2);
    sum2 = (y1 - y2) * -1;
    cout << sum1 + sum2 << endl;
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Bajtek, known for his unusual gifts, recently got an integer array x_0, x_1, …, x_{k-1}.

Unfortunately, after a huge array-party with his extraordinary friends, he realized that he'd lost it. After hours spent on searching for a new toy, Bajtek found on the arrays producer's website another array a of length n + 1. As a formal description of a says, a_0 = 0 and for all other i (1 ≤ i ≤ n) a_i = x_{(i-1)mod k} + a_{i-1}, where p mod q denotes the remainder of division p by q.

For example, if the x = [1, 2, 3] and n = 5, then:

  * a_0 = 0,
  * a_1 = x_{0mod 3}+a_0=x_0+0=1,
  * a_2 = x_{1mod 3}+a_1=x_1+1=3,
  * a_3 = x_{2mod 3}+a_2=x_2+3=6,
  * a_4 = x_{3mod 3}+a_3=x_0+6=7,
  * a_5 = x_{4mod 3}+a_4=x_1+7=9.

So, if the x = [1, 2, 3] and n = 5, then a = [0, 1, 3, 6, 7, 9].

Now the boy hopes that he will be able to restore x from a! Knowing that 1 ≤ k ≤ n, help him and find all possible values of k — possible lengths of the lost array.

Input

The first line contains exactly one integer n (1 ≤ n ≤ 1000) — the length of the array a, excluding the element a_0.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^6).

Note that a_0 is always 0 and is not given in the input.

Output

The first line of the output should contain one integer l denoting the number of correct lengths of the lost array.

The second line of the output should contain l integers — possible lengths of the lost array in increasing order.

Examples

Input

5
1 2 3 4 5

Output

5
1 2 3 4 5

Input

5
1 3 5 6 8

Output

2
3 5

Input

3
1 5 3

Output

1
3

Note

In the first example, any k is suitable, since a is an arithmetic progression.

Possible arrays x:

  * [1]
  * [1, 1]
  * [1, 1, 1]
  * [1, 1, 1, 1]
  * [1, 1, 1, 1, 1]

In the second example, Bajtek's array can have three or five elements.

Possible arrays x:

  * [1, 2, 2]
  * [1, 2, 2, 1, 2]

For example, k = 4 is bad, since it leads to 6 + x_0 = 8 and 0 + x_0 = 1, which is an obvious contradiction.

In the third example, only k = n is good.

Array [1, 4, -2] satisfies the requirements.

Note that x_i may be negative.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int N = 200005;
const double PI = 4 * atan(1);
const long long MAX = 9223372036854775807;
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, 1, -1, -1};
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
bool issquare(long long w) { return trunc(sqrt(w)) * trunc(sqrt(w)) == w; }
bool isprime(long long u) {
  for (long long i = 2; i <= (int)sqrt(u); i++) {
    if (u % i == 0) return 0;
  }
  return 1;
}
long long mod(long long to_mod, long long MOD) {
  to_mod %= MOD;
  while (to_mod < 0) to_mod += MOD;
  return to_mod % MOD;
}
long long moduloMultiplication(long long a, long long b, long long mod) {
  long long res = 0;
  a %= mod;
  while (b) {
    if (b & 1) res = (res + a) % mod;
    a = (2 * a) % mod;
    b >>= 1;
  }
  return res;
}
long long power(long long x, long long y) {
  long long res = 1;
  x = x;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long n, m, x, y, k, z, w, l, r, ans, res;
long long a[1005];
long long b[1005];
vector<long long> v;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  a[0] = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i + 1];
  }
  for (int i = 1; i <= n; i++) {
    b[i - 1] = a[i] - a[i - 1];
    bool cond = true;
    for (int j = 1; j <= n; j++) {
      if (a[j] != b[(j - 1) % i] + a[j - 1]) {
        cond = false;
      }
    }
    if (cond) v.push_back(i);
  }
  cout << v.size() << endl;
  for (auto t : v) {
    cout << t << " ";
  }
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You are given an array a of n positive integers.

You can use the following operation as many times as you like: select any integer 1 ≤ k ≤ n and do one of two things:

  * decrement by one k of the first elements of the array.
  * decrement by one k of the last elements of the array.

For example, if n=5 and a=[3,2,2,1,4], then you can apply one of the following operations to it (not all possible options are listed below):

  * decrement from the first two elements of the array. After this operation a=[2, 1, 2, 1, 4];
  * decrement from the last three elements of the array. After this operation a=[3, 2, 1, 0, 3];
  * decrement from the first five elements of the array. After this operation a=[2, 1, 1, 0, 3];

Determine if it is possible to make all the elements of the array equal to zero by applying a certain number of operations.

Input

The first line contains one positive integer t (1 ≤ t ≤ 30000) — the number of test cases. Then t test cases follow.

Each test case begins with a line containing one integer n (1 ≤ n ≤ 30000) — the number of elements in the array.

The second line of each test case contains n integers a_1 … a_n (1 ≤ a_i ≤ 10^6).

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

Output

For each test case, output on a separate line:

  * YES, if it is possible to make all elements of the array equal to zero by applying a certain number of operations.
  * NO, otherwise.

The letters in the words YES and NO can be outputed in any case.

Example

Input

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

Output

YES
YES
NO
YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int oo = 1e9 + 7;
const ll mod = 1e9 + 7, maxn = 2e5 + 100, maxm = 1e5 + 100;
const double PI = acos(-1);
string solve() {
  int n, c = 0;
  cin >> n;
  vector<int> mn(n, 0), vs(n);
  for (int i = 0; i < n; i++) {
    cin >> vs[i];
  }
  for (int i = 1; i < n; i++) {
    vs[i] -= c;
    if (vs[i] > vs[i - 1]) c += (vs[i] - vs[i - 1]), vs[i] = vs[i - 1];
    if (vs[i] < 0) return "NO";
  }
  return "YES";
}
int main() {
  ios_base::sync_with_stdio(false);
  int tt;
  cin >> tt;
  while (tt--) {
    cout << solve() << endl;
  }
  return 0;
}

```


### Prompt

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

Find the sum of weights of edges of the Minimum Spanning Tree for a given weighted undirected graph G = (V, E).

Constraints

* 1 ≤ |V| ≤ 10,000
* 0 ≤ |E| ≤ 100,000
* 0 ≤ wi ≤ 10,000
* The graph is connected
* There are no parallel edges
* There are no self-loops

Input

|V| |E|
s0 t0 w0
s1 t1 w1
:
s|E|-1 t|E|-1 w|E|-1

, where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively.

si and ti represent source and target verticess of i-th edge (undirected) and wi represents the weight of the i-th edge.

Output

Print the sum of the weights of the Minimum Spanning Tree.

Examples

Input

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

Output

3

Input

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

Output

5

### Response

```cpp
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

const int maxn = 200000 + 5;

struct node {
	int x;
	int y;
	int v;
}r[maxn];

int n,m;
int f[maxn];

bool cmp(node a,node b){
	return a.v < b.v;
}

int find(int x){
	if(f[x] == x)return x;
	else return f[x] = find(f[x]);
}

int Kruskal(){
	int ans = 0;
	for(int i = 1;i <= n; i++)f[i] = i;
	sort(r+1,r+m+1,cmp);
	for(int i = 1;i <= m; i++){
		int x = find(r[i].x),y = find(r[i].y);
		if(x != y){
			ans += r[i].v;
			f[x] = y;
		}
	}
	return ans;
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= m; i++)scanf("%d%d%d",&r[i].x,&r[i].y,&r[i].v);
	int ans = Kruskal();
	printf("%d\n",ans);
}
```


### Prompt

Create a solution in CPP for the following problem:

Description

KMC sells CDs every year at a coterie spot sale called Comic Market. F was supposed to sell CDs at the comic market, but due to the popularity of F, the KMC sales floor was flooded with people, and the calculation of change could not keep up. So F decided to write a program that would output the change as soon as he entered the amount.

KMC prepares only 100-yen coins, 500-yen coins, and 1000-yen coins as change. You can think of these coins and bills as infinite. Choose change so that the number of coins and bills is minimized. Also, the price of CDs sold by KMC is a multiple of 100, and the amount paid by the purchaser is also a multiple of 100.

Input

The input consists of multiple test cases.

Each test case consists of two positive integers A and B. A is the price of the CD and B is the amount paid by the purchaser. A and B are multiples of 100 and do not exceed 100000000. Also, A ≤ B.

The input ends with 0 0.

Output

For each test case, the number and number of 100-yen coins, 500-yen coins, and 1000-yen coins that should be presented as change are output in this order in one line. Insert a space between each number.

Example

Input

500 1000
100 10000
400 700
600 5000
10000 10000
0 0

Output

0 1 0
4 1 9
3 0 0
4 0 4
0 0 0

### Response

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

int main(){
	while(1){
		int a,b;
		cin >> a >> b;
		if(a==0 && b==0) break;

		int rem = b-a;
		int ans[3] = {};
		ans[2] = rem/1000;
		rem %= 1000;
		ans[1] = rem/500;
		rem %= 500;
		ans[0] = rem/100;
		cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
	}
	return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.

City i is established in year Y_i and belongs to Prefecture P_i.

You can assume that there are no multiple cities that are established in the same year.

It is decided to allocate a 12-digit ID number to each city.

If City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.

Here, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.

Find the ID numbers for all the cities.

Note that there can be a prefecture with no cities.

Constraints

* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^5
* 1 \leq P_i \leq N
* 1 \leq Y_i \leq 10^9
* Y_i are all different.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
P_1 Y_1
:
P_M Y_M

Output

Print the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).

Examples

Input

2 3
1 32
2 63
1 12

Output

000001000002
000002000001
000001000001

Input

2 3
2 55
2 77
2 99

Output

000002000001
000002000002
000002000003

### Response

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> pref(N + 1);
  vector<int> p(M);
  vector<int> y(M);
  for (int i = 0; i < M; ++i) {
    cin >> p[i] >> y[i];
    pref[p[i]].push_back(y[i]);
  }
  for (int i = 0; i < N + 1; ++i) {
    sort(pref[i].begin(), pref[i].end());
  }
  for (int i = 0; i < M; ++i) {
    int l = p[i];
    int r = lower_bound(pref[p[i]].begin(), pref[p[i]].end(), y[i]) - pref[p[i]].begin() + 1;
    printf("%06d%06d\n", l, r);
  }
}
```


### Prompt

Please create a solution in cpp to the following problem:

This is an interactive problem.

The judge has a hidden rooted full binary tree with n leaves. A full binary tree is one where every node has either 0 or 2 children. The nodes with 0 children are called the leaves of the tree. Since this is a full binary tree, there are exactly 2n - 1 nodes in the tree. The leaves of the judge's tree has labels from 1 to n. You would like to reconstruct a tree that is isomorphic to the judge's tree. To do this, you can ask some questions.

A question consists of printing the label of three distinct leaves a1, a2, a3. Let the depth of a node be the shortest distance from the node to the root of the tree. Let LCA(a, b) denote the node with maximum depth that is a common ancestor of the nodes a and b.

Consider X = LCA(a1, a2), Y = LCA(a2, a3), Z = LCA(a3, a1). The judge will tell you which one of X, Y, Z has the maximum depth. Note, this pair is uniquely determined since the tree is a binary tree; there can't be any ties.

More specifically, if X (or Y, Z respectively) maximizes the depth, the judge will respond with the string "X" (or "Y", "Z" respectively).

You may only ask at most 10·n questions.

Input

The first line of input will contain a single integer n (3 ≤ n ≤ 1 000) — the number of leaves in the tree.

Output

To print the final answer, print out the string "-1" on its own line. Then, the next line should contain 2n - 1 integers. The i-th integer should be the parent of the i-th node, or -1, if it is the root.

Your answer will be judged correct if your output is isomorphic to the judge's tree. In particular, the labels of the leaves do not need to be labeled from 1 to n. Here, isomorphic means that there exists a permutation π such that node i is the parent of node j in the judge tree if and only node π(i) is the parent of node π(j) in your tree.

Interaction

To ask a question, print out three distinct integers a1, a2, a3. These integers should be between 1 and n, inclusive.

The judge will respond with a single character, either "X", "Y", "Z".

If the string is "X" (or "Y", "Z" respectively), that means the pair (a1, a2) (or (a2, a3), (a3, a1) respectively) has the deepest LCA among the three pairs.

You may only ask a question at most 10·n times, otherwise, you will get Wrong Answer.

When you are ready to answer, print out a single integer "-1" on its own line. The next line should contain 2n - 1 integers. The i-th integer should be the parent of the i-th node, or -1, if it is the root. Do not forget to flush the final answer as well. Printing the answer does not count as asking a question.

You will get Wrong Answer verdict if

  * Your question or answers are not in the format described in this statement.
  * You ask strictly more than 10·n questions.
  * Your question contains duplicate indices.
  * Your final answer is not isomorphic to the judge tree.

You will get Idleness Limit Exceeded if you don't print anything or if you forget to flush the output, including for the final answer (more info about flushing output below).

To flush you can use (just after printing an integer and end-of-line):

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

If at any moment your program reads -1 as an answer, it should immediately exit normally (for example, by calling exit(0)). You will get Wrong Answer in this case, it means that you made more queries than allowed, or made an invalid query. If you ignore this, you can get other verdicts since your program will continue to read from a closed stream.

Hacking To hack someone, use the following format

    n
    p_1 p_2 ... p_{2n-1}

This denotes a tree where the parent of the i-th node is pi (pi = - 1 or n < pi ≤ 2n - 1). If pi is equal to -1, then node i is the root. This input must describe a valid full rooted binary tree.

Of course, contestant programs will not be able to see this input.

Example

Input

5
X
Z
Y
Y
X

Output

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

Note

For the first sample, the judge has the hidden tree:

<image>

Here is a more readable format of the interaction:

<image> The last line can also be 8 6 9 8 9 7 -1 6 7.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1000 + 5;
int N, sz;
int leftSon[2 * NMAX];
int rightSon[2 * NMAX];
int father[2 * NMAX];
pair<int, int> queryPair[2 * NMAX];
string askDir(int node, int searched) {
  cout << queryPair[node].first << ' ' << queryPair[node].second << ' '
       << searched << endl;
  char ans;
  cin >> ans;
  if (ans == 'X')
    return "UP";
  else if (ans == 'Z')
    return "LEFT";
  else
    return "RIGHT";
}
bool vis[2 * NMAX];
int szs[2 * NMAX];
void computeSzs(int node, int f) {
  szs[node] = 1;
  for (auto it : {leftSon[node], rightSon[node], father[node]})
    if (it && it != f && !vis[it]) {
      computeSzs(it, node);
      szs[node] += szs[it];
    }
}
int getCentroid(int node, int f, int atMost) {
  for (auto it : {leftSon[node], rightSon[node], father[node]})
    if (it && it != f && !vis[it] && szs[it] > atMost)
      return getCentroid(it, node, atMost);
  if (node <= N) {
    for (auto it : {leftSon[node], rightSon[node], father[node]})
      if (it && it != f && !vis[it]) return getCentroid(it, node, atMost);
    return -1;
  } else
    return node;
}
void insertOnEdge(int node, int searched) {
  if (father[node] == 0) {
    ++sz;
    leftSon[sz] = node;
    father[node] = sz;
    rightSon[sz] = searched;
    queryPair[sz] = {queryPair[node].first, searched};
    father[searched] = sz;
  } else if (node == leftSon[father[node]]) {
    node = father[node];
    ++sz;
    leftSon[sz] = leftSon[node];
    father[leftSon[node]] = sz;
    leftSon[node] = sz;
    father[sz] = node;
    rightSon[sz] = searched;
    queryPair[sz] = {queryPair[leftSon[sz]].first, searched};
    father[searched] = sz;
  } else {
    node = father[node];
    ++sz;
    rightSon[sz] = rightSon[node];
    father[rightSon[node]] = sz;
    rightSon[node] = sz;
    father[sz] = node;
    leftSon[sz] = searched;
    queryPair[sz] = {searched, queryPair[rightSon[sz]].second};
    father[searched] = sz;
  }
}
void findAndUpdate(int node, int searched) {
  computeSzs(node, 0);
  int cent = getCentroid(node, 0, szs[node] / 2);
  if (cent == -1) {
    insertOnEdge(node, searched);
    return;
  }
  node = cent;
  vis[node] = true;
  string ask = askDir(node, searched);
  if (ask == "UP") {
    if (!vis[father[node]] && father[node])
      findAndUpdate(father[node], searched);
    else
      insertOnEdge(node, searched);
  } else if (ask == "LEFT") {
    if (!vis[leftSon[node]])
      findAndUpdate(leftSon[node], searched);
    else
      insertOnEdge(leftSon[node], searched);
  } else {
    if (!vis[rightSon[node]])
      findAndUpdate(rightSon[node], searched);
    else
      insertOnEdge(rightSon[node], searched);
  }
}
int main() {
  cin >> N;
  sz = N + 1;
  leftSon[sz] = 1;
  rightSon[sz] = 2;
  father[1] = father[2] = sz;
  queryPair[sz] = {1, 2};
  for (int i = 1; i <= N; ++i) queryPair[i] = {i, i};
  for (int i = 3; i <= N; ++i) {
    memset(vis, 0, sizeof vis);
    findAndUpdate(sz, i);
  }
  cout << "-1" << endl;
  for (int i = 1; i <= sz; ++i)
    if (father[i] == 0) father[i] = -1;
  for (int i = 1; i <= sz; ++i) cout << father[i] << " \n"[i == sz];
  cout.flush();
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

You have N items that you want to put them into a knapsack. Item i has value vi and weight wi.

You want to find a subset of items to put such that:

* The total value of the items is as large as possible.
* The items have combined weight at most W, that is capacity of the knapsack.

Find the maximum total value of items in the knapsack.

Constraints

* 1 ≤ N ≤ 40
* 1 ≤ vi ≤ 1015
* 1 ≤ wi ≤ 1015
* 1 ≤ W ≤ 1015

Input

N W
v1 w1
v2 w2
:
vN wN

The first line consists of the integers N and W. In the following N lines, the value and weight of the i-th item are given.

Output

Print the maximum total values of the items in a line.

Examples

Input

4 5
4 2
5 2
2 1
8 3

Output

13

Input

2 20
5 9
4 10

Output

9

### Response

```cpp
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;
typedef pair<ll,ll>pl;

const int MAX_N = 40;

ll v[MAX_N];
ll w[MAX_N];
vector<pl> x,y;

void solve(int s,int t,vector<pl> &x)
{
	int z = t-s;
	rep(i,1<<z){
		pl p = pl(0,0);
		rep(j,z){
			if(i&(1<<j)){
				p.first += w[s+j];
				p.second += v[s+j];
			}
		}
		x.push_back(p);
	}
}

int main()
{
	int n;
	ll lm;
	cin >> n >> lm;
	rep(i,n){
		cin >> v[i] >> w[i];
	}
	solve(0,n/2,x);
	solve(n/2,n,y);
	sort(x.begin(),x.end());
	sort(y.begin(),y.end());
	ll t=0;
	ll maxv = -(1LL<<60);
	ll ans = 0;
	for(int i=x.size()-1;i>=0;i--){
		while(t < y.size() && x[i].first+y[t].first <= lm){
			maxv = max(maxv,y[t].second);
			t++;
		}
		ans = max(ans,maxv+x[i].second);
	}
	cout << ans << endl;
	return 0;
}
```


### Prompt

Create a solution in cpp for the following problem:

Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.

Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.

Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.

Input

The first line contains integer n (1 ≤ n ≤ 1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.

Output

On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.

Examples

Input

4
4 1 2 10

Output

12 5

Input

7
1 2 3 4 5 6 7

Output

16 12

Note

In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, f = 0, l = 0;
  vector<int> card;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    card.push_back(x);
  }
  for (int i = 0; i < n; ++i) {
    if (card.size() == 1) card.push_back(0);
    if (i % 2 == 1)
      f += (card[0] > card[card.size() - 1] ? card[0] : card[card.size() - 1]);
    else
      l += (card[0] > card[card.size() - 1] ? card[0] : card[card.size() - 1]);
    if (card[0] > card[card.size() - 1] && card.size() != 0)
      for (int j = 0; j < card.size() - 1; ++j) card[j] = card[j + 1];
    card.pop_back();
  }
  cout << l << " " << f;
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

John Doe has recently found a "Free Market" in his city — that is the place where you can exchange some of your possessions for other things for free.

John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that each item is one of a kind and that means that you cannot exchange set {a, b} for set {v, a}. However, you can always exchange set x for any set y, unless there is item p, such that p occurs in x and p occurs in y.

For each item, John knows its value ci. John's sense of justice doesn't let him exchange a set of items x for a set of items y, if s(x) + d < s(y) (s(x) is the total price of items in the set x).

During one day John can exchange only one set of items for something else. Initially, he has no items. John wants to get a set of items with the maximum total price. Find the cost of such set and the minimum number of days John can get it in.

Input

The first line contains two space-separated integers n, d (1 ≤ n ≤ 50, 1 ≤ d ≤ 104) — the number of items on the market and John's sense of justice value, correspondingly. The second line contains n space-separated integers ci (1 ≤ ci ≤ 104).

Output

Print two space-separated integers: the maximum possible price in the set of items John can get and the minimum number of days needed to get such set.

Examples

Input

3 2
1 3 10

Output

4 3

Input

3 5
1 2 3

Output

6 2

Input

10 10000
10000 9999 1 10000 10000 10000 1 2 3 4

Output

50010 6

Note

In the first sample John can act like this:

  * Take the first item (1 - 0 ≤ 2).
  * Exchange the first item for the second one (3 - 1 ≤ 2).
  * Take the first item (1 - 0 ≤ 2).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bitset<500005> dp;
int N, D, ans, i, j, x, d, s = 1;
int main() {
  dp[0] = 1;
  for (scanf("%d%d", &N, &D), i = 0; i < N; i++) {
    scanf("%d", &x);
    for (j = 500000; j >= x; j--) dp[j] = (dp[j] || dp[j - x]);
  }
  while (s) {
    for (s = 0, i = min(ans + D, 500000); i > ans; i--) {
      if (dp[i]) {
        s = i - ans;
        break;
      }
    }
    ans += s;
    d++;
  }
  printf("%d %d\n", ans, d - 1);
  return 0;
}

```


### Prompt

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

Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" — you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored adventure stories that featured lasers and robots.

Today Petya is watching a shocking blockbuster about the Martians called "R2:D2". What can "R2:D2" possibly mean? It might be the Martian time represented in the Martian numeral system. Petya knows that time on Mars is counted just like on the Earth (that is, there are 24 hours and each hour has 60 minutes). The time is written as "a:b", where the string a stands for the number of hours (from 0 to 23 inclusive), and string b stands for the number of minutes (from 0 to 59 inclusive). The only thing Petya doesn't know is in what numeral system the Martian time is written.

Your task is to print the radixes of all numeral system which can contain the time "a:b".

Input

The first line contains a single string as "a:b" (without the quotes). There a is a non-empty string, consisting of numbers and uppercase Latin letters. String a shows the number of hours. String b is a non-empty string that consists of numbers and uppercase Latin letters. String b shows the number of minutes. The lengths of strings a and b are from 1 to 5 characters, inclusive. Please note that strings a and b can have leading zeroes that do not influence the result in any way (for example, string "008:1" in decimal notation denotes correctly written time).

We consider characters 0, 1, ..., 9 as denoting the corresponding digits of the number's representation in some numeral system, and characters A, B, ..., Z correspond to numbers 10, 11, ..., 35.

Output

Print the radixes of the numeral systems that can represent the time "a:b" in the increasing order. Separate the numbers with spaces or line breaks. If there is no numeral system that can represent time "a:b", print the single integer 0. If there are infinitely many numeral systems that can represent the time "a:b", print the single integer -1.

Note that on Mars any positional numeral systems with positive radix strictly larger than one are possible.

Examples

Input

11:20

Output

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

Input

2A:13

Output

0

Input

000B:00001

Output

-1

Note

Let's consider the first sample. String "11:20" can be perceived, for example, as time 4:6, represented in the ternary numeral system or as time 17:32 in hexadecimal system.

Let's consider the second sample test. String "2A:13" can't be perceived as correct time in any notation. For example, let's take the base-11 numeral notation. There the given string represents time 32:14 that isn't a correct time.

Let's consider the third sample. String "000B:00001" can be perceived as a correct time in the infinite number of numeral systems. If you need an example, you can take any numeral system with radix no less than 12.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool zero(double x) { return x > -1e-6 && x < 1e-6; }
char s1[10], s2[10];
int val[256], len1, len2;
void init() {
  int i;
  for (i = 0; i <= 9; ++i) val[i + '0'] = i;
  for (i = 'A'; i <= 'Z'; ++i) val[i] = i - 'A' + 10;
}
bool flag;
bool check(int k) {
  int i, ex, v1 = 0, v2 = 0;
  for (i = len1 - 1; i >= 0; --i) {
    if (val[s1[i]] >= k) return false;
  }
  for (i = len2 - 1; i >= 0; --i) {
    if (val[s2[i]] >= k) return false;
  }
  ex = 1;
  for (i = len1 - 1; i >= 0; --i) {
    v1 += ex * val[s1[i]];
    ex *= k;
  }
  ex = 1;
  for (i = len2 - 1; i >= 0; --i) {
    v2 += ex * val[s2[i]];
    ex *= k;
  }
  if (v1 < 0 || v1 > 23) return false;
  if (v2 < 0 || v2 > 59) return false;
  if (v1 == val[s1[len1 - 1]] && v2 == val[s2[len2 - 1]]) flag = 1;
  return true;
}
int stat[100], top;
char ss[100];
int main() {
  int i, j, ans = 0;
  scanf("%s", ss);
  for (i = j = 0; ss[i] != ':'; ++i) s1[j++] = ss[i];
  s1[j] = '\0';
  j = 0;
  for (++i; ss[i]; ++i) s2[j++] = ss[i];
  s2[j] = '\0';
  len1 = strlen(s1);
  len2 = strlen(s2);
  init();
  top = 0;
  flag = 0;
  for (i = 2; i < 70; ++i) {
    if (check(i)) {
      stat[top++] = i;
    }
  }
  if (flag)
    printf("-1\n");
  else if (top == 0)
    printf("0\n");
  else {
    for (i = 0; i < top; ++i) {
      if (i) printf(" ");
      printf("%d", stat[i]);
    }
    printf("\n");
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Authors guessed an array a consisting of n integers; each integer is not less than 2 and not greater than 2 ⋅ 10^5. You don't know the array a, but you know the array b which is formed from it with the following sequence of operations:

  1. Firstly, let the array b be equal to the array a;
  2. Secondly, for each i from 1 to n:
    * if a_i is a prime number, then one integer p_{a_i} is appended to array b, where p is an infinite sequence of prime numbers (2, 3, 5, ...);
    * otherwise (if a_i is not a prime number), the greatest divisor of a_i which is not equal to a_i is appended to b;
  3. Then the obtained array of length 2n is shuffled and given to you in the input.

Here p_{a_i} means the a_i-th prime number. The first prime p_1 = 2, the second one is p_2 = 3, and so on.

Your task is to recover any suitable array a that forms the given array b. It is guaranteed that the answer exists (so the array b is obtained from some suitable array a). If there are multiple answers, you can print any.

Input

The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a.

The second line of the input contains 2n integers b_1, b_2, ..., b_{2n} (2 ≤ b_i ≤ 2750131), where b_i is the i-th element of b. 2750131 is the 199999-th prime number.

Output

In the only line of the output print n integers a_1, a_2, ..., a_n (2 ≤ a_i ≤ 2 ⋅ 10^5) in any order — the array a from which the array b can be obtained using the sequence of moves given in the problem statement. If there are multiple answers, you can print any.

Examples

Input

3
3 5 2 3 2 4

Output

3 4 2

Input

1
2750131 199999

Output

199999

Input

1
3 6

Output

6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int v = 2750200, fact, save[2750200], mark[2750200];
vector<int> prime, ans, pr, nonpr;
bool a[2750200], flag;
void sieve() {
  int i, t, j, n, m, k = 0;
  m = sqrt(v);
  prime.push_back(2);
  k = 1;
  a[0] = 1;
  a[1] = 1;
  a[2] = 0;
  for (i = 4; i < v; i += 2) {
    a[i] = 1;
  }
  for (i = 3; i < v; i += 2) {
    if (a[i] == 0) {
      prime.push_back(i);
      k++;
      if (i <= m) {
        for (j = i * i; j <= v; j += 2 * i) {
          a[j] = 1;
        }
      }
    }
  }
}
void precal() {
  memset(save, 0, sizeof save);
  ;
  for (int i = 0; i < prime.size(); i++) {
    int x = prime[i];
    if (x <= prime.size()) {
      x = prime[x - 1];
      save[x] = prime[i];
    }
  }
}
int largestfact(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return n / i;
    }
  }
  return 1;
}
int main() {
  sieve();
  precal();
  memset(mark, 0, sizeof mark);
  ;
  int n, x;
  scanf("%d", &n);
  for (int i = 0; i < 2 * n; i++) {
    scanf("%d", &x);
    if (a[x])
      nonpr.push_back(x);
    else
      pr.push_back(x);
    mark[x]++;
  }
  sort(nonpr.rbegin(), nonpr.rend());
  for (int i = 0; i < nonpr.size(); i++) {
    x = nonpr[i];
    if (!mark[x]) continue;
    x = largestfact(nonpr[i]);
    if (!mark[x]) continue;
    if (mark[x]) {
      ans.push_back(nonpr[i]);
      mark[x]--;
      mark[nonpr[i]]--;
    }
  }
  sort(pr.rbegin(), pr.rend());
  for (int i = 0; i < pr.size(); i++) {
    x = pr[i];
    if (!mark[x]) {
      continue;
    }
    x = save[pr[i]];
    ans.push_back(x);
    mark[x]--;
    mark[pr[i]]--;
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i];
    if (i < ans.size() - 1)
      cout << ' ';
    else
      cout << endl;
  };
  return 0;
}

```


### Prompt

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

Valera's finally decided to go on holiday! He packed up and headed for a ski resort.

Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has n objects (we will consider the objects indexed in some way by integers from 1 to n), each object is either a hotel or a mountain.

Valera has also found out that the ski resort had multiple ski tracks. Specifically, for each object v, the resort has at most one object u, such that there is a ski track built from object u to object v. We also know that no hotel has got a ski track leading from the hotel to some object.

Valera is afraid of getting lost on the resort. So he wants you to come up with a path he would walk along. The path must consist of objects v1, v2, ..., vk (k ≥ 1) and meet the following conditions:

  1. Objects with numbers v1, v2, ..., vk - 1 are mountains and the object with number vk is the hotel.
  2. For any integer i (1 ≤ i < k), there is exactly one ski track leading from object vi. This track goes to object vi + 1.
  3. The path contains as many objects as possible (k is maximal).

Help Valera. Find such path that meets all the criteria of our hero!

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of objects.

The second line contains n space-separated integers type1, type2, ..., typen — the types of the objects. If typei equals zero, then the i-th object is the mountain. If typei equals one, then the i-th object is the hotel. It is guaranteed that at least one object is a hotel.

The third line of the input contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ n) — the description of the ski tracks. If number ai equals zero, then there is no such object v, that has a ski track built from v to i. If number ai doesn't equal zero, that means that there is a track built from object ai to object i.

Output

In the first line print k — the maximum possible path length for Valera. In the second line print k integers v1, v2, ..., vk — the path. If there are multiple solutions, you can print any of them.

Examples

Input

5
0 0 0 0 1
0 1 2 3 4

Output

5
1 2 3 4 5

Input

5
0 0 1 0 1
0 1 2 2 4

Output

2
4 5

Input

4
1 0 0 0
2 3 4 2

Output

1
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int Mod = 998244353;
int dcmp(double x) {
  if (fabs(x) <= 1e-9) return 0;
  return x < 0 ? -1 : 1;
}
struct Point {
  double x, y;
  double ang;
  Point() {}
  Point(double x, double y) : x(x), y(y) {}
  Point operator-(const Point &a) const { return Point(x - a.x, y - a.y); }
  Point operator+(const Point &a) const { return Point(x + a.x, y + a.y); }
  Point operator*(const double &a) const { return Point(x * a, y * a); }
  bool operator<(const Point &a) const {
    if (dcmp(ang) == 0) return (x * x + y * y) <= a.x * a.x + a.y * a.y;
    return ang < a.ang;
  }
  bool operator==(const Point &a) const { return x == a.x && y == a.y; }
};
struct cycle {
  Point p;
  long long r;
  cycle() {}
  cycle(Point p, long long r) : p(p), r(r) {}
};
Point Rotate(Point v, double ang) {
  return Point(v.x * cos(ang) - v.y * sin(ang),
               v.x * sin(ang) + v.y * cos(ang));
}
double Dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
double dis(Point a) { return sqrt(Dot(a, a)); }
double Cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
int f[200005], s[200005];
int dp[200005], v, n, cut[200005];
int dfs(int now) {
  if (!now) return 0;
  if (f[now] == now) return 0;
  if (dp[now] != -1) return dp[now];
  if (s[now]) return dp[now] = 0;
  if (cut[now] != 1) return dp[now] = 0;
  return dp[now] = dfs(f[now]) + 1;
}
void rdfs(int now) {
  if (!now) return;
  if (s[now]) return;
  if (cut[now] != 1) return;
  if (f[now]) rdfs(f[now]);
  cout << now << " ";
}
void solve() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  memset(dp, -1, sizeof(dp));
  memset(cut, 0, sizeof(cut));
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) {
    cin >> v;
    f[i] = v, cut[v]++;
  }
  int ans = 0, id = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i]) {
      int cnt = dfs(f[i]) + 1;
      if (cnt >= ans) ans = cnt, id = i;
    }
  }
  cout << ans << endl;
  rdfs(f[id]);
  cout << id << endl;
}
int main() {
  int t = 1;
  for (int i = 1; i <= t; i++) solve();
  return 0;
}

```