### Prompt

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

In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.
The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).

Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:

* C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.
* Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."

This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.

Constraints

* N is an integer between 1 and 100 (inclusive).
* x_i and y_i are integers between 0 and 100 (inclusive).
* h_i is an integer between 0 and 10^9 (inclusive).
* The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.
* The center coordinates and the height of the pyramid can be uniquely identified.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

Output

Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.

Examples

Input

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

Output

2 2 6

Input

2
0 0 100
1 1 98

Output

0 0 100

Input

3
99 1 191
100 1 192
99 0 192

Output

100 0 193

### Response

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

int main(){
  ll n;
  cin>>n;
  ll X[n], Y[n], H[n];
  vector<tuple<ll, ll, ll>> vec(n);

  tuple<ll, ll, ll> g = make_tuple(-1, -1, -1);
  for(ll i=0;i<n;i++){
    cin>>X[i] >>Y[i] >>H[i];
    if(H[i]>0)g = make_tuple(X[i], Y[i], H[i]);
  }

  for(ll x=0;x<=100;x++)for(ll y=0;y<=100;y++){
    ll h = max(get<2>(g) + abs(get<0>(g) - x) + abs(get<1>(g) - y), 0ll);
    bool ok = true;
    for(ll i=0;i<n;i++){
      ll hi = max(h - abs(X[i]-x) - abs(Y[i]-y), 0ll);
      if(H[i]!=hi)ok=false;
    }
    if(ok){
      cout<<x<<" "<<y<<" "<<h<<endl;
      return 0;
    }
  }
}
```


### Prompt

Construct a Cpp code solution to the problem outlined:

You are given a graph with 3 ⋅ n vertices and m edges. You are to find a matching of n edges, or an independent set of n vertices.

A set of edges is called a matching if no two edges share an endpoint.

A set of vertices is called an independent set if no two vertices are connected with an edge.

Input

The first line contains a single integer T ≥ 1 — the number of graphs you need to process. The description of T graphs follows.

The first line of description of a single graph contains two integers n and m, where 3 ⋅ n is the number of vertices, and m is the number of edges in the graph (1 ≤ n ≤ 10^{5}, 0 ≤ m ≤ 5 ⋅ 10^{5}).

Each of the next m lines contains two integers v_i and u_i (1 ≤ v_i, u_i ≤ 3 ⋅ n), meaning that there is an edge between vertices v_i and u_i.

It is guaranteed that there are no self-loops and no multiple edges in the graph.

It is guaranteed that the sum of all n over all graphs in a single test does not exceed 10^{5}, and the sum of all m over all graphs in a single test does not exceed 5 ⋅ 10^{5}.

Output

Print your answer for each of the T graphs. Output your answer for a single graph in the following format.

If you found a matching of size n, on the first line print "Matching" (without quotes), and on the second line print n integers — the indices of the edges in the matching. The edges are numbered from 1 to m in the input order.

If you found an independent set of size n, on the first line print "IndSet" (without quotes), and on the second line print n integers — the indices of the vertices in the independent set.

If there is no matching and no independent set of the specified size, print "Impossible" (without quotes).

You can print edges and vertices in any order.

If there are several solutions, print any. In particular, if there are both a matching of size n, and an independent set of size n, then you should print exactly one of such matchings or exactly one of such independent sets.

Example

Input

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

Output

Matching
2
IndSet
1
IndSet
2 4
Matching
1 15

Note

The first two graphs are same, and there are both a matching of size 1 and an independent set of size 1. Any of these matchings and independent sets is a correct answer.

The third graph does not have a matching of size 2, however, there is an independent set of size 2. Moreover, there is an independent set of size 5: 2 3 4 5 6. However such answer is not correct, because you are asked to find an independent set (or matching) of size exactly n.

The fourth graph does not have an independent set of size 2, but there is a matching of size 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    vector<long long> vis(3 * n + 1);
    vector<long long> mat;
    vector<long long> st;
    for (long long i = 0; i < m; i++) {
      long long u, v;
      cin >> u >> v;
      if (!vis[u] && !vis[v]) {
        vis[u]++, vis[v]++;
        mat.push_back(i + 1);
      }
    }
    for (long long i = 1; i < 3 * n + 1; i++) {
      if (!vis[i]) st.push_back(i);
    }
    if (mat.size() >= n) {
      cout << "Matching\n";
      for (long long i = 0; i < n; i++) cout << mat[i] << " ";
    } else if (st.size() >= n) {
      cout << "IndSet\n";
      for (long long i = 0; i < n; i++) cout << st[i] << " ";
    } else {
      cout << "Impossible";
    }
    cout << "\n";
  }
  return 0;
}

```


### Prompt

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

Quick sort is based on the Divide-and-conquer approach. In QuickSort(A, p, r), first, a procedure Partition(A, p, r) divides an array A[p..r] into two subarrays A[p..q-1] and A[q+1..r] such that each element of A[p..q-1] is less than or equal to A[q], which is, inturn, less than or equal to each element of A[q+1..r]. It also computes the index q.

In the conquer processes, the two subarrays A[p..q-1] and A[q+1..r] are sorted by recursive calls of QuickSort(A, p, q-1) and QuickSort(A, q+1, r).

Your task is to read a sequence A and perform the Partition based on the following pseudocode:

Partition(A, p, r)
1 x = A[r]
2 i = p-1
3 for j = p to r-1
4     do if A[j] <= x
5        then i = i+1
6            exchange A[i] and A[j]
7 exchange A[i+1] and A[r]
8 return i+1

Note that, in this algorithm, Partition always selects an element A[r] as a pivot element around which to partition the array A[p..r].

Constraints

* 1 ≤ n ≤ 100,000
* 0 ≤ Ai ≤ 100,000

Input

The first line of the input includes an integer n, the number of elements in the sequence A.

In the second line, Ai (i = 1,2,...,n), elements of the sequence are given separated by space characters.

Output

Print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character. The element which is selected as the pivot of the partition should be indicated by [  ].

Example

Input

12
13 19 9 5 12 8 7 4 21 2 6 11

Output

9 5 8 7 4 2 6 [11] 21 13 19 12

### Response

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

int partition(int A[],int p,int r){
  int x = A[r];
  int i = p-1;
  for(int j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      swap(A[j],A[i]);
    }
  }
  swap(A[i+1],A[r]);
  return i+1;
}

int main(){
  int n;cin>>n;
  int A[n];
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  int pibot = partition(A,0,n-1);
  for(int i=0;i<n;i++){
    if(i) printf(" ");
    if(i==pibot){
      printf("[%d]",A[i]);
    }else{
      printf("%d",A[i]);
    }
  }
  printf("\n");
}
```


### Prompt

Generate a cpp solution to the following problem:

Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of the problem before the contest. Because he wants to make sure Iahub will be the one qualified, he tells Iahub the following task.

You're given an (1-based) array a with n elements. Let's define function f(i, j) (1 ≤ i, j ≤ n) as (i - j)2 + g(i, j)2. Function g is calculated by the following pseudo-code:

    int g(int i, int j) {
        int sum = 0;
        for (int k = min(i, j) + 1; k <= max(i, j); k = k + 1)
            sum = sum + a[k];
        return sum;
    }

Find a value mini ≠ j f(i, j).

Probably by now Iahub already figured out the solution to this problem. Can you?

Input

The first line of input contains a single integer n (2 ≤ n ≤ 100000). Next line contains n integers a[1], a[2], ..., a[n] ( - 104 ≤ a[i] ≤ 104).

Output

Output a single integer — the value of mini ≠ j f(i, j).

Examples

Input

4
1 0 0 -1

Output

1

Input

2
1 -1

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
struct Point {
  int x;
  int y;
  void CO() { cout << x << ' ' << y << endl; }
};
Point T[100100], tg[100100];
int n;
long long res;
bool cmp(Point a, Point b) { return (a.y < b.y); }
long long Dis(Point a, Point b) {
  return ((long long)a.x - b.x) * (a.x - b.x) +
         ((long long)a.y - b.y) * (a.y - b.y);
}
void Cal(int left, int right) {
  if (left == right) return;
  int mid = (left + right) / 2;
  Cal(left, mid);
  Cal(mid + 1, right);
  int dem = 0, i = left, j = mid + 1;
  while (i <= mid && j <= right)
    if (T[i].x < T[j].x)
      tg[++dem] = T[i++];
    else
      tg[++dem] = T[j++];
  while (i <= mid) tg[++dem] = T[i++];
  while (j <= right) tg[++dem] = T[j++];
  for (int u = left; u <= right; u++) T[u] = tg[u - left + 1];
  for (int u = left; u <= right; u++)
    for (int v = max(left, u - 5); v <= u - 1; v++) {
      res = min(res, Dis(T[u], T[v]));
    }
}
int main() {
  scanf("%d", &n);
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    sum += x;
    T[i].x = i;
    T[i].y = sum;
  }
  res = 2000000000000000000;
  sort(T + 1, T + n + 1, cmp);
  Cal(1, n);
  cout << res;
  return 0;
}

```


### Prompt

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

You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Constraints

* 1\leq A\leq B\leq 10^{18}
* 1\leq C,D\leq 10^9
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Examples

Input

4 9 2 3

Output

2

Input

10 40 6 8

Output

23

Input

314159265358979323 846264338327950288 419716939 937510582

Output

532105071133627368

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int g(int c,int d){
  if(c>d)
    return g(d,c);
  if(c==0)
    return d;
  return g(d%c,c);
}
int main(){
  int64_t a,b,c,d;
  cin>>a>>b>>c>>d;
  a--;
  int64_t l=c*d/g(c,d);
  cout<<(b-b/c-b/d+b/l)-(a-a/c-a/d+a/l)<<endl;
}
```


### Prompt

Please formulate a cpp solution to the following problem:

The Smart Beaver from ABBYY was offered a job of a screenwriter for the ongoing TV series. In particular, he needs to automate the hard decision: which main characters will get married by the end of the series.

There are n single men and n single women among the main characters. An opinion poll showed that viewers like several couples, and a marriage of any of them will make the audience happy. The Smart Beaver formalized this fact as k triples of numbers (h, w, r), where h is the index of the man, w is the index of the woman, and r is the measure of the audience's delight in case of the marriage of this couple. The same poll showed that the marriage of any other couple will leave the audience indifferent, so the screenwriters decided not to include any such marriages in the plot.

The script allows you to arrange several marriages between the heroes or not to arrange marriages at all. A subset of some of the k marriages is considered acceptable if each man and each woman is involved in at most one marriage of the subset (the series won't allow any divorces). The value of the acceptable set of marriages is the total delight the spectators will get from the marriages included in this set.

Obviously, there is a finite number of acceptable sets, and they all describe some variants of the script. The screenwriters do not want to choose a set with maximum value — it would make the plot too predictable. So the Smart Beaver offers the following option: sort all the acceptable sets in increasing order of value and choose the t-th set from the sorted list. Thus, t = 1 corresponds to a plot without marriages, t = 2 — to a single marriage resulting in minimal delight for the audience, and so on.

Help the Beaver to implement the algorithm for selecting the desired set.

Input

The first input line contains integers n, k and t (1 ≤ k ≤ min(100, n2), 1 ≤ t ≤ 2·105), separated by single spaces. Next k lines contain triples of integers (h, w, r) (1 ≤ h, w ≤ n; 1 ≤ r ≤ 1000), separated by single spaces, which describe the possible marriages. It is guaranteed that the input data is correct: t doesn't exceed the total number of acceptable sets, and each pair (h, w) is present in at most one triple.

The input limitations for getting 30 points are:

  * 1 ≤ n ≤ 5

The input limitations for getting 100 points are:

  * 1 ≤ n ≤ 20

Output

Print a single number — the value of the t-th acceptable variant.

Examples

Input

2 4 3
1 1 1
1 2 2
2 1 3
2 2 7

Output

2

Input

2 4 7
1 1 1
1 2 2
2 1 3
2 2 7

Output

8

Note

The figure shows 7 acceptable sets of marriages that exist in the first sample.

<image>

### Response

```cpp
#include <bits/stdc++.h>
int value[21][21];
int yes[21][21];
int hash[21];
int seq[1 << 21], tot = 0;
int N, M, K;
void dfs(int x, int count) {
  int i, j;
  if (x <= N) {
    dfs(x + 1, count);
    for (i = 1; i <= N; ++i)
      if (hash[i] == 0 && yes[x][i] == 1) {
        hash[i] = 1;
        dfs(x + 1, count + value[x][i]);
        hash[i] = 0;
      }
  } else {
    seq[++tot] = count;
  }
}
int main() {
  int i, j, sc, sv, t;
  scanf("%d%d%d", &N, &M, &K);
  for (i = 1; i <= M; ++i) {
    scanf("%d%d%d", &sc, &sv, &t);
    value[sc][sv] = t;
    yes[sc][sv] = 1;
  }
  dfs(1, 0);
  std::sort(seq + 1, seq + tot + 1);
  printf("%d\n", seq[K]);
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Find the number of integers between 1 and K (inclusive) satisfying the following condition, modulo 10^9 + 7:

* The sum of the digits in base ten is a multiple of D.

Constraints

* All values in input are integers.
* 1 \leq K < 10^{10000}
* 1 \leq D \leq 100

Input

Input is given from Standard Input in the following format:

K
D

Output

Print the number of integers satisfying the condition, modulo 10^9 + 7.

Examples

Input

30
4

Output

6

Input

1000000009
1

Output

2

Input

98765432109876543210
58

Output

635270834

### Response

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

const long long mo=1000000000+7;

std::string K;
int D;
long long dp[2][100][10001];//1:strict

int main(){
  std::cin >> K;
  std::cin >> D;
  dp[1][0][0]=1;
  for(int i=0;i<(int)(K.length());++i){
    for(int k=0;k<D;++k){
      for(int j=0;j<=9;++j){
	int nk=(j+k)%D;
	dp[0][nk][i+1]+=dp[0][k][i];
	dp[0][nk][i+1]%=mo;
      }
      for(int j=0;j<(int)(K[i]-'0');++j){
	int nk=(j+k)%D;
	dp[0][nk][i+1]+=dp[1][k][i];
	dp[0][nk][i+1]%=mo;
      }
      int nk=(k+(int)(K[i]-'0'))%D;
      dp[1][nk][i+1]+=dp[1][k][i];
      dp[1][nk][i+1]%=mo;
    }
  }
  std::cout<<(dp[0][0][(int)(K.length())]+dp[1][0][(int)(K.length())]+mo-1)%mo<<std::endl;
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Arcady is a copywriter. His today's task is to type up an already well-designed story using his favorite text editor.

Arcady types words, punctuation signs and spaces one after another. Each letter and each sign (including line feed) requires one keyboard click in order to be printed. Moreover, when Arcady has a non-empty prefix of some word on the screen, the editor proposes a possible autocompletion for this word, more precisely one of the already printed words such that its prefix matches the currently printed prefix if this word is unique. For example, if Arcady has already printed «codeforces», «coding» and «codeforces» once again, then there will be no autocompletion attempt for «cod», but if he proceeds with «code», the editor will propose «codeforces».

With a single click Arcady can follow the editor's proposal, i.e. to transform the current prefix to it. Note that no additional symbols are printed after the autocompletion (no spaces, line feeds, etc). What is the minimum number of keyboard clicks Arcady has to perform to print the entire text, if he is not allowed to move the cursor or erase the already printed symbols?

A word here is a contiguous sequence of latin letters bordered by spaces, punctuation signs and line/text beginnings/ends. Arcady uses only lowercase letters. For example, there are 20 words in «it's well-known that tic-tac-toe is a paper-and-pencil game for two players, x and o.».

Input

The only line contains Arcady's text, consisting only of lowercase latin letters, spaces, line feeds and the following punctuation signs: «.», «,», «?», «!», «'» and «-». The total amount of symbols doesn't exceed 3·105. It's guaranteed that all lines are non-empty.

Output

Print a single integer — the minimum number of clicks.

Examples

Input

snow affects sports such as skiing, snowboarding, and snowmachine travel.
snowboarding is a recreational activity and olympic and paralympic sport.

Output

141

Input

'co-co-co, codeforces?!'

Output

25

Input

thun-thun-thunder, thunder, thunder
thunder, thun-, thunder
thun-thun-thunder, thunder
thunder, feel the thunder
lightning then the thunder
thunder, feel the thunder
lightning then the thunder
thunder, thunder

Output

183

Note

In sample case one it's optimal to use autocompletion for the first instance of «snowboarding» after typing up «sn» and for the second instance of «snowboarding» after typing up «snowb». This will save 7 clicks.

In sample case two it doesn't matter whether to use autocompletion or not.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct nd {
  int nx[26];
  int p;
  int c;
  bool t;
  nd(int pp = 0) {
    for (int i = 0; i < 26; i++) {
      nx[i] = -1;
    }
    c = 0;
    t = 0;
    p = pp;
  }
};
vector<nd> s;
int main() {
  cin >> noskipws;
  char a;
  int t = 0;
  int ans = 0;
  bool f = 0;
  int fb = 0;
  s.push_back(nd(-1));
  s[0].p = -1;
  while (cin >> a) {
    ans++;
    if (a < 'a' || a > 'z') {
      if (s[t].t == 0) {
        s[t].t = 1;
        while (t != -1) {
          s[t].c++;
          t = s[t].p;
        }
      }
      t = 0;
      f = 0;
    } else {
      a -= 'a';
      if (s[t].nx[a] == -1) {
        s[t].nx[a] = (int)s.size();
        s.push_back(nd(t));
      }
      t = s[t].nx[a];
      if (f && s[t].c == 1) {
        fb++;
      }
      if (s[t].c == 1 && !f) {
        f = 1;
        fb = 0;
      }
      if (f && s[t].t == 1 && fb > 0) {
        ans -= fb - 1;
        f = 0;
        fb = 0;
      }
    }
  }
  cout << ans << '\n';
}

```


### Prompt

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

Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal".

The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal.

Input

The first line contains two space-separated integers a and b (1 ≤ a, b ≤ 109).

Output

If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0.

Examples

Input

15 20

Output

3

Input

14 8

Output

-1

Input

6 6

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int a2 = 0, a3 = 0, a5 = 0, b2 = 0, b3 = 0, b5 = 0;
  while (a % 2 == 0 || a % 3 == 0 || a % 5 == 0) {
    if (a % 2 == 0) a2++, a /= 2;
    if (a % 3 == 0) a3++, a /= 3;
    if (a % 5 == 0) a5++, a /= 5;
  }
  while (b % 2 == 0 || b % 3 == 0 || b % 5 == 0) {
    if (b % 2 == 0) b2++, b /= 2;
    if (b % 3 == 0) b3++, b /= 3;
    if (b % 5 == 0) b5++, b /= 5;
  }
  if (a != b)
    cout << -1;
  else
    cout << abs(a2 - b2) + abs(a3 - b3) + abs(a5 - b5);
  return 0;
}

```


### Prompt

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

You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character.

Let's introduce several definitions:

  * A substring s[i..j] (1 ≤ i ≤ j ≤ |s|) of string s is string sisi + 1...sj.
  * The prefix of string s of length l (1 ≤ l ≤ |s|) is string s[1..l].
  * The suffix of string s of length l (1 ≤ l ≤ |s|) is string s[|s| - l + 1..|s|].

Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.

Input

The single line contains a sequence of characters s1s2...s|s| (1 ≤ |s| ≤ 105) — string s. The string only consists of uppercase English letters.

Output

In the first line, print integer k (0 ≤ k ≤ |s|) — the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers li ci. Numbers li ci mean that the prefix of the length li matches the suffix of length li and occurs in string s as a substring ci times. Print pairs li ci in the order of increasing li.

Examples

Input

ABACABA

Output

3
1 4
3 2
7 1

Input

AAA

Output

3
1 3
2 2
3 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
const int INF = 1e9 + 7;
vector<int> Z;
string T;
void zeta(string &U) {
  Z = vector<int>(T.size(), 0);
  for (int i = 1, l = 0, r = 0; i < U.size(); i++) {
    if (i <= r) Z[i] = min(Z[i - l], r - i + 1);
    for (; i + Z[i] < U.size() && U[Z[i]] == U[i + Z[i]]; Z[i]++)
      ;
    if (r < i + Z[i] - 1) l = i, r = i + Z[i] - 1;
  }
  Z[0] = T.size();
}
int cnt[N];
bool isPreff[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> T;
  zeta(T);
  int n = T.size();
  for (int i = 0; i < n; i++) {
    if (i + Z[i] == n) {
      isPreff[Z[i]] = true;
    }
    cnt[1]++;
    cnt[Z[i] + 1]--;
  }
  int sum = 0;
  vector<pair<int, int> > ans;
  for (int i = 1; i <= n; i++) {
    sum += cnt[i];
    if (!isPreff[i]) continue;
    ans.push_back({i, sum});
  }
  cout << ans.size() << '\n';
  for (pair<int, int> p : ans) {
    cout << p.first << ' ' << p.second << '\n';
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Mislove had an array a_1, a_2, ⋅⋅⋅, a_n of n positive integers, but he has lost it. He only remembers the following facts about it:

  * The number of different numbers in the array is not less than l and is not greater than r;
  * For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(2) in the array.

For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2 = 8.

According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.

Input

The only input line contains three integers n, l and r (1 ≤ n ≤ 1 000, 1 ≤ l ≤ r ≤ min(n, 20)) — an array's size, the minimal number and the maximal number of distinct elements in an array.

Output

Output two numbers — the minimal and the maximal possible sums of all elements in an array.

Examples

Input

4 2 2

Output

5 7

Input

5 1 5

Output

5 31

Note

In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.

In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16].

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int n, l, r, s, c = 1, min = 0, max = 1, i;
  scanf("%d%d%d", &n, &l, &r);
  s = l - 1;
  for (i = 1; i <= s; i++) {
    c *= 2;
    min += c;
  }
  min += (n - s);
  c = 1;
  for (i = 1; i < r; i++) {
    c *= 2;
    max += c;
  }
  for (i = 1; i <= n - r; i++) {
    max += c;
  }
  printf("%d ", min);
  printf("%d\n", max);
}

```


### Prompt

Please create a solution in cpp to the following problem:

The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.

UCDHP stores some secret information about meteors as an n × m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:

  * The query to swap two table rows;
  * The query to swap two table columns;
  * The query to obtain a secret number in a particular table cell.

As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.

Input

The first line contains three space-separated integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 500000) — the number of table columns and rows and the number of queries, correspondingly.

Next n lines contain m space-separated numbers each — the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 ≤ p ≤ 106.

Next k lines contain queries in the format "si xi yi", where si is one of the characters "с", "r" or "g", and xi, yi are two integers.

  * If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 ≤ x, y ≤ m, x ≠ y);
  * If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 ≤ x, y ≤ n, x ≠ y);
  * If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 ≤ x ≤ n, 1 ≤ y ≤ m).

The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns — from left to right from 1 to m.

Output

For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.

Examples

Input

3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2

Output

8
9
6

Input

2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3

Output

5

Note

Let's see how the table changes in the second test case.

After the first operation is fulfilled, the table looks like that:

2 1 4

1 3 5

After the second operation is fulfilled, the table looks like that:

1 3 5

2 1 4

So the answer to the third query (the number located in the first row and in the third column) will be 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[1005][1005];
int h[1005];
int l[1005];
int main() {
  int n, m, i, j, k, p, q, t;
  char str[3], cc;
  while (scanf("%d%d%d", &n, &m, &k) != EOF) {
    for (i = 1; i <= n; i++)
      for (j = 1; j <= m; j++) scanf("%d", &a[i][j]);
    for (i = 1; i <= n; i++) h[i] = i;
    for (j = 1; j <= m; j++) l[j] = j;
    cc = getchar();
    for (i = 0; i < k; i++) {
      scanf("%s", &str);
      scanf("%d%d", &p, &q);
      cc = getchar();
      if (str[0] == 'g') printf("%d\n", a[h[p]][l[q]]);
      if (p == q) continue;
      if (str[0] == 'r') {
        t = h[p];
        h[p] = h[q];
        h[q] = t;
      } else if (str[0] == 'c') {
        t = l[p];
        l[p] = l[q];
        l[q] = t;
      }
    }
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Alice and Bob are playing a game on a line with n cells. There are n cells labeled from 1 through n. For each i from 1 to n-1, cells i and i+1 are adjacent.

Alice initially has a token on some cell on the line, and Bob tries to guess where it is.

Bob guesses a sequence of line cell numbers x_1, x_2, …, x_k in order. In the i-th question, Bob asks Alice if her token is currently on cell x_i. That is, Alice can answer either "YES" or "NO" to each Bob's question.

At most one time in this process, before or after answering a question, Alice is allowed to move her token from her current cell to some adjacent cell. Alice acted in such a way that she was able to answer "NO" to all of Bob's questions.

Note that Alice can even move her token before answering the first question or after answering the last question. Alice can also choose to not move at all.

You are given n and Bob's questions x_1, …, x_k. You would like to count the number of scenarios that let Alice answer "NO" to all of Bob's questions.

Let (a,b) denote a scenario where Alice starts at cell a and ends at cell b. Two scenarios (a_i, b_i) and (a_j, b_j) are different if a_i ≠ a_j or b_i ≠ b_j.

Input

The first line contains two integers n and k (1 ≤ n,k ≤ 10^5) — the number of cells and the number of questions Bob asked.

The second line contains k integers x_1, x_2, …, x_k (1 ≤ x_i ≤ n) — Bob's questions.

Output

Print a single integer, the number of scenarios that let Alice answer "NO" to all of Bob's questions.

Examples

Input

5 3
5 1 4

Output

9

Input

4 8
1 2 3 4 4 3 2 1

Output

0

Input

100000 1
42

Output

299997

Note

The notation (i,j) denotes a scenario where Alice starts at cell i and ends at cell j.

In the first example, the valid scenarios are (1, 2), (2, 1), (2, 2), (2, 3), (3, 2), (3, 3), (3, 4), (4, 3), (4, 5). For example, (3,4) is valid since Alice can start at cell 3, stay there for the first three questions, then move to cell 4 after the last question.

(4,5) is valid since Alice can start at cell 4, stay there for the first question, the move to cell 5 for the next two questions. Note that (4,5) is only counted once, even though there are different questions that Alice can choose to do the move, but remember, we only count each pair of starting and ending positions once.

In the second example, Alice has no valid scenarios.

In the last example, all (i,j) where |i-j| ≤ 1 except for (42, 42) are valid scenarios.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int INF = 0x3f3f3f3f;
int a[100100];
int id[100010];
int vis[100010];
int ans1[100100];
int ans2[100100];
int main() {
  long long n, k, kk = 0;
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d", &id[i]);
    if (a[id[i]] == 0) a[id[i]] = 1, kk++;
  }
  long long ans = n + (n - 1) * 2;
  ans -= kk;
  for (int i = 1; i <= k; i++) {
    if (vis[id[i] + 1] == 1 && id[i] + 1 <= n) ans1[id[i] + 1] = 1;
    if (vis[id[i] - 1] == 1 && id[i] - 1 >= 1) ans2[id[i] - 1] = 1;
    vis[id[i]] = 1;
  }
  for (int i = 1; i <= n; i++)
    if (ans1[i] == 1) ans--;
  for (int i = 1; i <= n; i++)
    if (ans2[i] == 1) ans--;
  printf("%lld\n", ans);
}

```


### Prompt

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

Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight <image> (where <image> is the [bitwise-xor operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)). Can you find the weight of the minimum spanning tree of that graph?

You can read about complete graphs in <https://en.wikipedia.org/wiki/Complete_graph>

You can read about the minimum spanning tree in <https://en.wikipedia.org/wiki/Minimum_spanning_tree>

The weight of the minimum spanning tree is the sum of the weights on the edges included in it.

Input

The only line contains an integer n (2 ≤ n ≤ 1012), the number of vertices in the graph.

Output

The only line contains an integer x, the weight of the graph's minimum spanning tree.

Example

Input

4

Output

4

Note

In the first sample: <image> The weight of the minimum spanning tree is 1+2+1=4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int64_t n;
  cin >> n;
  n--;
  auto f = [&](int64_t x) { return (n - x) / (x << 1) + 1; };
  int64_t res = 0;
  for (int64_t i = 1; i <= n; i <<= 1) {
    res += (f(i) * i);
  }
  cout << res << '\n';
}

```


### Prompt

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

Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.

Printer works with a rectangular sheet of paper of size n × m. Consider the list as a table consisting of n rows and m columns. Rows are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m. Initially, all cells are painted in color 0.

Your program has to support two operations:

  1. Paint all cells in row ri in color ai;
  2. Paint all cells in column ci in color ai.

If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.

Your program has to print the resulting table after k operation.

Input

The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 5000, n·m ≤ 100 000, 1 ≤ k ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.

Each of the next k lines contains the description of exactly one query:

  * 1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
  * 2 ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.

Output

Print n lines containing m integers each — the resulting table after all operations are applied.

Examples

Input

3 3 3
1 1 3
2 2 1
1 2 2

Output

3 1 3
2 2 2
0 1 0

Input

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

Output

1 1 1
1 0 1
1 1 1
1 0 1
1 1 1

Note

The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, m, k, i, j, par;
  long long int a;
  int ch;
  cin >> n >> m >> k;
  long int R[n], R1[n], C[m], C1[m];
  for (i = 0; i < n; i++) {
    R[i] = R1[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    C[i] = C1[i] = 0;
  }
  for (int i = 0; i < k; i++) {
    cin >> ch >> par >> a;
    if (ch == 1) {
      R[par - 1] = a;
      R1[par - 1] = i;
    } else {
      C[par - 1] = a;
      C1[par - 1] = i;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (C[j] == 0) {
        cout << R[i] << " ";
      } else if (R[i] == 0) {
        cout << C[j] << " ";
      } else {
        if (C1[j] > R1[i]) {
          cout << C[j] << " ";
        } else {
          cout << R[i] << " ";
        }
      }
    }
    cout << "\n";
  }
  return 0;
}

```


### Prompt

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

Example

Input

anagram
grandmother

Output

4

### Response

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

typedef array<int, 26> Vec;

char buf[114514];
int cnt[2][114514][26];
string S[2];
vector<int> appear[2][26];

int main() {
  scanf("%s", buf);
  S[0] = buf;
  scanf("%s", buf);
  S[1] = buf;

  for (int k=0; k<2; k++) {
    for (int i=0; i<S[k].size(); i++) {
      appear[k][S[k][i]-'a'].emplace_back(i);
      if (i > 0) {
        for (int j=0; j<26; j++) {
          cnt[k][i][j] = cnt[k][i-1][j];
        }
      }
      cnt[k][i][S[k][i]-'a']++;
    }
  }

  int t = (int)min(S[0].size(), S[1].size());
  for (int k=t; k>=1; k--) {
    vector<Vec> vs;
    for (int i=0; i+k<=S[0].size(); i++) {
      Vec v;
      for (int j=0; j<26; j++) {
        v[j] = cnt[0][i+k-1][j];
        if (i > 0) v[j] -= cnt[0][i-1][j];
      }
      vs.emplace_back(v);
    }
    sort(vs.begin(), vs.end());

    for (int i=0; i+k<=S[1].size(); i++) {
      Vec v;
      for (int j=0; j<26; j++) {
        v[j] = cnt[1][i+k-1][j];
        if (i > 0) v[j] -= cnt[1][i-1][j];
      }

      if (binary_search(vs.begin(), vs.end(), v)) {
        printf("%d\n", k);
        return 0;
      }
    }
  }
  puts("0");
}

```


### Prompt

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

You are given an array of n elements, you must make it a co-prime array in as few moves as possible.

In each move you can insert any positive integral number you want not greater than 109 in any place in the array.

An array is co-prime if any two adjacent numbers of it are co-prime.

In the number theory, two integers a and b are said to be co-prime if the only positive integer that divides both of them is 1.

Input

The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array.

The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.

Output

Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime.

The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array a by adding k elements to it.

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

Example

Input

3
2 7 28

Output

1
2 7 9 28

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int GCD(int x, int y) { return (!x) ? y : GCD(y % x, x); }
int a[1004], N, i, c;
int main() {
  for (scanf("%d", &N), i = 1; i <= N; i++) scanf("%d", &a[i]);
  for (i = 1; i <= N - 1; i++) {
    if (GCD(a[i], a[i + 1]) != 1) c++;
  }
  for (printf("%d\n%d ", c, a[1]), i = 1; i <= N - 1; i++) {
    if (GCD(a[i], a[i + 1]) != 1)
      printf("1 %d ", a[i + 1]);
    else
      printf("%d ", a[i + 1]);
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

A ball will bounce along a number line, making N + 1 bounces. It will make the first bounce at coordinate D_1 = 0, and the i-th bounce (2 \leq i \leq N+1) at coordinate D_i = D_{i-1} + L_{i-1}.

How many times will the ball make a bounce where the coordinate is at most X?

Constraints

* 1 \leq N \leq 100
* 1 \leq L_i \leq 100
* 1 \leq X \leq 10000
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X
L_1 L_2 ... L_{N-1} L_N

Output

Print the number of times the ball will make a bounce where the coordinate is at most X.

Examples

Input

3 6
3 4 5

Output

2

Input

4 9
3 3 3 3

Output

4

### Response

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

int main(){
  int N,X,D=0,cnt = 0;
  cin >> N >> X;
  int l[N];
  for(int i=0;i<N;i++){
    cin >> l[i];
    D = D + l[i];
    if(D<=X)
      cnt++;
  }
  cout << cnt+1 << endl;
}

```


### Prompt

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

The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. n best participants from the country have participated in it. The tournament consists of games, each of them is a match between two participants. n·(n - 1) / 2 games were played during the tournament, and each participant had a match with each other participant.

The rules of the game are quite simple — the participant who falls asleep first wins. The secretary made a record of each game in the form «xi yi», where xi and yi are the numbers of participants. The first number in each pair is a winner (i.e. xi is a winner and yi is a loser). There is no draws.

Recently researches form the «Institute Of Sleep» have found that every person is characterized by a value pj — the speed of falling asleep. The person who has lower speed wins. Every person has its own value pj, constant during the life.

It is known that all participants of the tournament have distinct speeds of falling asleep. Also it was found that the secretary made records about all the games except one. You are to find the result of the missing game.

Input

The first line contains one integer n (3 ≤ n ≤ 50) — the number of participants. The following n·(n - 1) / 2 - 1 lines contain the results of the games. Each game is described in a single line by two integers xi, yi (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi и yi are the numbers of the opponents in this game. It is known that during the tournament each of the n participants played n - 1 games, one game with each other participant.

Output

Output two integers x and y — the missing record. If there are several solutions, output any of them.

Examples

Input

4
4 2
4 1
2 3
2 1
3 1

Output

4 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int apa[51], arr[51], n, x, y, xx, yy;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n * (n - 1) / 2) - 1; i++) {
    scanf("%d %d", &x, &y);
    arr[x]++;
    apa[x]++;
    apa[y]++;
  }
  for (int i = 1; i <= n; i++)
    if (apa[i] != n - 1) {
      if (xx == 0)
        xx = i;
      else
        yy = i;
    }
  if (arr[xx] > arr[yy])
    printf("%d %d", xx, yy);
  else
    printf("%d %d", yy, xx);
}

```


### Prompt

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

There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.

For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.

The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.

There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?

Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.

For example, the following pairs of words denote the same name:

  * "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
  * "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".

For a given list of words, find the minimal number of groups where the words in each group denote the same name.

Input

The first line contains integer number n (2 ≤ n ≤ 400) — number of the words in the list.

The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.

Output

Print the minimal number of groups where the words in each group denote the same name.

Examples

Input

10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon

Output

4

Input

9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi

Output

5

Input

2
alex
alex

Output

1

Note

There are four groups of words in the first example. Words in each group denote same name:

  1. "mihail", "mikhail"
  2. "oolyana", "ulyana"
  3. "kooooper", "koouper"
  4. "hoon", "khun", "kkkhoon"

There are five groups of words in the second example. Words in each group denote same name:

  1. "hariton", "kkkhariton", "khariton"
  2. "hkariton"
  3. "buoi", "boooi", "boui"
  4. "bui"
  5. "boi"

In the third example the words are equal, so they denote the same name.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int k, n, m, x, ans;
int a[N];
string second, r;
map<string, int> vis1, vis2;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    char e[50];
    scanf("%s", e);
    r = second = e;
    while (second.find("kh") != -1) {
      x = second.find("kh");
      second.erase(second.begin() + x);
    }
    r = second;
    while (second.find("oo") != -1) {
      x = second.find("oo");
      second[x] = 'u';
      second.erase(second.begin() + x + 1);
    }
    while (r.find("u") != -1) {
      x = r.find("u");
      r[x] = 'o';
      r.insert(r.begin() + x, 'o');
    }
    vis1[second] = 1;
    vis2[r] = 1;
  }
  printf("%d\n", min(vis1.size(), vis2.size()));
  return 0;
}

```


### Prompt

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

Problem statement

A programming contest will be held in the Russian Federation. The contest has N questions and has M participants. Question i has a score a_i, and it is known that participant j's ability is b_j. For problem i and participant j, participant j can always solve problem i if a_i ≤ b_j and only then. The score of a participant through the contest is the sum of the scores of the problems that the person was able to solve. Participant j also sets a target score c_j for this contest.

Determine if each participant can score more than the target score.

input

The input is given in the following format.

N
a_ {0} a_ {1} a_ {2}… a_ {N−1}
M
b_ {0} b_ {1} b_ {2}… b_ {M−1}
c_ {0} c_ {1} c_ {2}… c_ {M−1}

Constraint

* All inputs are integers
* 1 \ ≤ N \ ≤ 300 \,000
* 1 \ ≤ M \ ≤ 300 \,000
* 0 \ ≤ a_ {i} \ ≤ 1 \, 000 \,000
* 0 \ ≤ b_ {i} \ ≤ 1 \, 000 \,000
* 0 \ ≤ c_ {i} \ ≤ ∑a_k

output

Print the answer on line M. On the i-line, output `Yes` if the participant i-1 can get more points than the target score, and` No` if not.

sample

Sample input 1

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

Sample output 1

Yes
Yes
Yes
Yes
Yes
No
No

The points obtained by each participant are as follows.

* Participant 0: 1 + 1 = 2
* Participant 1: 1 + 2 + 1 + 3 = 7
* Participant 2: 1 + 2 + 1 + 3 + 4 = 11
* Participant 3: 1 + 2 + 1 + 3 + 4 + 5 = 16
* Participant 4: 1 + 2 + 1 + 3 = 7
* Participant 5: 1 + 1 = 2
* Participants 6: 0

Sample input 2

8
1 1 2 3 3 4 6 100
Four
1 3 4 99
1 10 15 120

Sample output 2

Yes
Yes
No
No

Example

Input

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

Output

Yes
Yes
Yes
Yes
Yes
No
No

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
//#define ll ll
signed main(){
    ll n; cin >> n;
    vector<ll>v(n);
    for(auto && itr : v){
        cin >> itr;
    }
    ll m; cin >> m;
    vector<ll>u(m);
    for(auto && itr : u){
        cin >> itr;
    }
    vector<ll>c(m);
    for(auto && itr : c){
        cin >> itr;
    }
    sort(v.begin(),v.end());
    vector<ll>sum = v;
    for(ll i = 1;  i < n;i++){
        sum[i]+=sum[i-1];
    }
    for(ll i = 0;  i < u.size(); i++){
        ll idx = (ll)(lower_bound(v.begin(), v.end(),u[i]+1) - v.begin());
        if((sum[idx-1] >= c[i] and idx )or c[i] == 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Takahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who is in charge of making the scoreboard, is struggling to write the program that manages the players' scores in a game, which proceeds as follows.

A game is played by N players, numbered 1 to N. At the beginning of a game, each player has K points.

When a player correctly answers a question, each of the other N-1 players receives minus one (-1) point. There is no other factor that affects the players' scores.

At the end of a game, the players with 0 points or lower are eliminated, and the remaining players survive.

In the last game, the players gave a total of Q correct answers, the i-th of which was given by Player A_i. For Kizahashi, write a program that determines whether each of the N players survived this game.

Constraints

* All values in input are integers.
* 2 \leq N \leq 10^5
* 1 \leq K \leq 10^9
* 1 \leq Q \leq 10^5
* 1 \leq A_i \leq N\ (1 \leq i \leq Q)

Input

Input is given from Standard Input in the following format:

N K Q
A_1
A_2
.
.
.
A_Q

Output

Print N lines. The i-th line should contain `Yes` if Player i survived the game, and `No` otherwise.

Examples

Input

6 3 4
3
1
3
2

Output

No
No
Yes
No
No
No

Input

6 5 4
3
1
3
2

Output

Yes
Yes
Yes
Yes
Yes
Yes

Input

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

Output

No
No
No
No
Yes
No
No
No
Yes
No

### Response

```cpp
#include <cstdio>
int a[100005];
int main()
{
 int n,k,q;
 scanf("%d%d%d",&n,&k,&q);
 for(int i=1;i<=q;i++)
 {
  int x;
  scanf("%d",&x);
  a[x]++;
 }
 for(int i=1;i<=n;i++)
  puts(k-q+a[i]>0?"Yes":"No");
 return 0;
}
```


### Prompt

Please create a solution in cpp to the following problem:

Let us define the FizzBuzz sequence a_1,a_2,... as follows:

* If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}.
* If the above does not hold but 3 divides i, a_i=\mbox{Fizz}.
* If none of the above holds but 5 divides i, a_i=\mbox{Buzz}.
* If none of the above holds, a_i=i.

Find the sum of all numbers among the first N terms of the FizzBuzz sequence.

Constraints

* 1 \leq N \leq 10^6

Input

Input is given from Standard Input in the following format:

N

Output

Print the sum of all numbers among the first N terms of the FizzBuzz sequence.

Examples

Input

15

Output

60

Input

1000000

Output

266666333332

### Response

```cpp
#include<iostream>
using namespace std;
int n;
long long ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		if(i%3!=0&&i%5!=0)ans+=i;
	cout<<ans;
}
```


### Prompt

Please create a solution in cpp to the following problem:

Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes.

More formally, you are given an odd numer n. Find a set of numbers pi (1 ≤ i ≤ k), such that

  1. 1 ≤ k ≤ 3
  2. pi is a prime
  3. <image>

The numbers pi do not necessarily have to be distinct. It is guaranteed that at least one possible solution exists.

Input

The single line contains an odd number n (3 ≤ n < 109).

Output

In the first line print k (1 ≤ k ≤ 3), showing how many numbers are in the representation you found.

In the second line print numbers pi in any order. If there are multiple possible solutions, you can print any of them.

Examples

Input

27

Output

3
5 11 11

Note

A prime is an integer strictly larger than one that is divisible only by one and by itself.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool p(int n) {
  if (n <= 1) return false;
  for (long long i = 2; i <= sqrt(n); i++)
    if (n % i == 0) return false;
  return true;
}
int main() {
  long long s, n, j, o = 0, a[3] = {};
  cin >> n;
  j = n;
  for (long long i = 0; i < 300; i++) {
    if (p(j)) break;
    j--;
  }
  a[0] = j;
  j = n - j;
  for (long long i = 2; i <= j; i++) {
    if (p(i)) {
      a[1] = i;
      if (p(j - i)) {
        a[2] = j - i;
        break;
      }
    }
  }
  for (long long i = 0; i < 3; i++)
    if (a[i]) o++;
  cout << o;
  cout << endl;
  for (long long i = 0; i < o; i++) {
    cout << a[i];
    cout << " ";
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

problem

You are looking for a constellation in a picture of the starry sky. The photo always contains exactly one figure with the same shape, orientation, and size as the constellation you are looking for. However, there is a possibility that extra stars are shown in the photograph other than the stars that make up the constellation.

For example, the constellations in Figure 1 are included in the photo in Figure 2 (circled). If you translate the coordinates of a star in a given constellation by 2 in the x direction and −3 in the y direction, it will be the position in the photo.

Given the shape of the constellation you want to look for and the position of the star in the picture, write a program that answers the amount to translate to convert the coordinates of the constellation to the coordinates in the picture.

<image> | <image>
--- | ---
Figure 1: The constellation you want to find | Figure 2: Photograph of the starry sky

input

The input consists of multiple datasets. Each dataset is given in the following format.

The first line of the input contains the number of stars m that make up the constellation you want to find. In the following m line, the integers indicating the x and y coordinates of the m stars that make up the constellation you want to search for are written separated by blanks. The number n of stars in the photo is written on the m + 2 line. In the following n lines, the integers indicating the x and y coordinates of the n stars in the photo are written separated by blanks.

The positions of the m stars that make up the constellation are all different. Also, the positions of the n stars in the picture are all different. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of a star are all 0 or more and 1000000 or less.

When m is 0, it indicates the end of input. The number of datasets does not exceed 5.

output

The output of each dataset consists of one line, with two integers separated by blanks. These show how much the coordinates of the constellation you want to find should be translated to become the coordinates in the photo. The first integer is the amount to translate in the x direction, and the second integer is the amount to translate in the y direction.

Examples

Input

5
8 5
6 4
4 3
7 10
0 10
10
10 5
2 7
9 7
8 10
10 2
1 2
8 1
6 7
6 0
0 9
5
904207 809784
845370 244806
499091 59863
638406 182509
435076 362268
10
757559 866424
114810 239537
519926 989458
461089 424480
674361 448440
81851 150384
459107 795405
299682 6700
254125 362183
50795 541942
0

Output

2 -3
-384281 179674

Input

None

Output

None

### Response

```cpp
#include<cstdio>
#include<set>
#include<map>
using namespace std;

int main(){
  while(1){
    int m, n ;
    int seiza[200][2], stars[1000][2];
    set< pair<int, int> > starset;
    scanf("%d", &m);
    if(m == 0){
      return 0;
    }
    for(int i = 0;i < m;i++){
      int xi, yi;
      scanf("%d%d", &xi, &yi);
      seiza[i][0] = xi;
      seiza[i][1] = yi;
    }
    scanf("%d", &n);
    for(int i = 0;i < n;i++){
      int xi, yi;
      scanf("%d%d", &xi, &yi);
      stars[i][0] = xi;
      stars[i][1] = yi;
      starset.insert(make_pair(xi, yi));
    }
    for(int i = 0;i < n;i++){
      int xdis = stars[i][0] - seiza[0][0];
      int ydis = stars[i][1] - seiza[0][1];
      int j;
      for(j = 1;j < m;j++){
	if(starset.find(make_pair(seiza[j][0] + xdis, seiza[j][1] + ydis)) == starset.end()){
	  break;
	}
      }
      if(j == m){
	printf("%d %d\n", xdis, ydis);
	break;
      }
    }
  }
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

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

A tree is a connected undirected graph with n-1 edges.

You are given m queries. The i-th query consists of the set of k_i distinct vertices v_i[1], v_i[2], ..., v_i[k_i]. Your task is to say if there is a path from the root to some vertex u such that each of the given k vertices is either belongs to this path or has the distance 1 to some vertex of this path.

Input

The first line of the input contains two integers n and m (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ m ≤ 2 ⋅ 10^5) — the number of vertices in the tree and the number of queries.

Each of the next n-1 lines describes an edge of the tree. Edge i is denoted by two integers u_i and v_i, the labels of vertices it connects (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i).

It is guaranteed that the given edges form a tree.

The next m lines describe queries. The i-th line describes the i-th query and starts with the integer k_i (1 ≤ k_i ≤ n) — the number of vertices in the current query. Then k_i integers follow: v_i[1], v_i[2], ..., v_i[k_i] (1 ≤ v_i[j] ≤ n), where v_i[j] is the j-th vertex of the i-th query.

It is guaranteed that all vertices in a single query are distinct.

It is guaranteed that the sum of k_i does not exceed 2 ⋅ 10^5 (∑_{i=1}^{m} k_i ≤ 2 ⋅ 10^5).

Output

For each query, print the answer — "YES", if there is a path from the root to some vertex u such that each of the given k vertices is either belongs to this path or has the distance 1 to some vertex of this path and "NO" otherwise.

Example

Input

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

Output

YES
YES
YES
YES
NO
NO

Note

The picture corresponding to the example:

<image>

Consider the queries.

The first query is [3, 8, 9, 10]. The answer is "YES" as you can choose the path from the root 1 to the vertex u=10. Then vertices [3, 9, 10] belong to the path from 1 to 10 and the vertex 8 has distance 1 to the vertex 7 which also belongs to this path.

The second query is [2, 4, 6]. The answer is "YES" as you can choose the path to the vertex u=2. Then the vertex 4 has distance 1 to the vertex 1 which belongs to this path and the vertex 6 has distance 1 to the vertex 2 which belongs to this path.

The third query is [2, 1, 5]. The answer is "YES" as you can choose the path to the vertex u=5 and all vertices of the query belong to this path.

The fourth query is [4, 8, 2]. The answer is "YES" as you can choose the path to the vertex u=9 so vertices 2 and 4 both have distance 1 to the vertex 1 which belongs to this path and the vertex 8 has distance 1 to the vertex 7 which belongs to this path.

The fifth and the sixth queries both have answer "NO" because you cannot choose suitable vertex u.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void print(vector<long long> a) {
  for (long long i = 1; i < a.size(); i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
void printPair(vector<pair<long long, long long>> a) {
  for (long long i = 1; i < a.size(); i++) {
    cout << a[i].first << "--" << a[i].second << endl;
  }
}
void dfsUtil(long long *time, vector<long long> graph[], vector<bool> &check,
             long long vertex, long long depth, vector<long long> &depthList,
             vector<long long> &parentList,
             vector<pair<long long, long long>> &timeList) {
  long long i;
  check[vertex] = true;
  depthList[vertex] = depth;
  timeList[vertex].first = *time;
  for (i = 0; i < graph[vertex].size(); i++) {
    if (check[graph[vertex][i]] == false) {
      *time = *time + 1;
      parentList[graph[vertex][i]] = vertex;
      dfsUtil(time, graph, check, graph[vertex][i], depthList[vertex] + 1,
              depthList, parentList, timeList);
    }
  }
  *time = *time + 1;
  timeList[vertex].second = *time;
}
void DFS(vector<long long> graph[], long long totalVertices,
         vector<long long> &depthList, vector<long long> &parentList,
         vector<pair<long long, long long>> &timeList) {
  long long depth = 1;
  long long time = 0;
  vector<bool> check(totalVertices, false);
  dfsUtil(&time, graph, check, 1, depth, depthList, parentList, timeList);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, q;
  cin >> n >> q;
  vector<long long> graph[n + 1];
  for (long long i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  vector<long long> parentList(n + 1, 0);
  vector<long long> depthList(n + 1, 0);
  vector<pair<long long, long long>> timeList(n + 1, make_pair(-1, -1));
  parentList[1] = 1;
  DFS(graph, n + 1, depthList, parentList, timeList);
  while (q--) {
    long long x;
    cin >> x;
    vector<long long> storeVertex;
    long long maxDepthVertex = -1;
    long long depthMax = INT_MIN;
    while (x--) {
      long long a;
      cin >> a;
      storeVertex.push_back(a);
      if (depthList[a] > depthMax) {
        maxDepthVertex = a;
        depthMax = depthList[a];
      }
    }
    long long time1 = 0;
    long long time2 = timeList[maxDepthVertex].second;
    long long check = 1;
    for (long long i = 0; i < storeVertex.size(); i++) {
      if ((timeList[storeVertex[i]].first <= time2 &&
           timeList[storeVertex[i]].second >= time2) ||
          (timeList[parentList[storeVertex[i]]].first <= time2 &&
           timeList[parentList[storeVertex[i]]].second >= time2)) {
        check = 1;
      } else {
        check = 0;
        break;
      }
    }
    if (check == 1)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

One day in the IT lesson Anna and Maria learned about the lexicographic order.

String x is lexicographically less than string y, if either x is a prefix of y (and x ≠ y), or there exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi, and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of the string a. The lexicographic comparison of strings is implemented by operator < in modern programming languages.

The teacher gave Anna and Maria homework. She gave them a string of length n. They should write out all substrings of the given string, including the whole initial string, and the equal substrings (for example, one should write out the following substrings from the string "aab": "a", "a", "aa", "ab", "aab", "b"). The resulting strings should be sorted in the lexicographical order. The cunning teacher doesn't want to check all these strings. That's why she said to find only the k-th string from the list. Help Anna and Maria do the homework.

Input

The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 105. The second line contains the only integer k (1 ≤ k ≤ 105).

Output

Print the string Anna and Maria need — the k-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than k, print a string saying "No such line." (without the quotes).

Examples

Input

aa
2

Output

a

Input

abc
5

Output

bc

Input

abab
7

Output

b

Note

In the second sample before string "bc" follow strings "a", "ab", "abc", "b".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
multiset<pair<string, int> > mul;
int main() {
  string ss;
  int k;
  cin >> ss >> k;
  for (int i = 0; i < ss.size(); i++) {
    string temp;
    temp += ss[i];
    mul.insert({temp, i});
  }
  long long n = ss.size();
  if (2 * k > n * (n + 1)) {
    cout << "No such line." << endl;
  } else {
    pair<string, int> p, ans;
    while (k--) {
      ans = p = *mul.begin();
      mul.erase(mul.begin());
      if (p.second + 1 < n) {
        p.first += ss[p.second + 1];
        p.second += 1;
        mul.insert(p);
      }
    }
    cout << ans.first << endl;
  }
  return 0;
}

```


### Prompt

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

Lee is used to finish his stories in a stylish way, this time he barely failed it, but Ice Bear came and helped him. Lee is so grateful for it, so he decided to show Ice Bear his new game called "Critic"...

The game is a one versus one game. It has t rounds, each round has two integers s_i and e_i (which are determined and are known before the game begins, s_i and e_i may differ from round to round). The integer s_i is written on the board at the beginning of the corresponding round.

The players will take turns. Each player will erase the number on the board (let's say it was a) and will choose to write either 2 ⋅ a or a + 1 instead. Whoever writes a number strictly greater than e_i loses that round and the other one wins that round.

Now Lee wants to play "Critic" against Ice Bear, for each round he has chosen the round's s_i and e_i in advance. Lee will start the first round, the loser of each round will start the next round.

The winner of the last round is the winner of the game, and the loser of the last round is the loser of the game.

Determine if Lee can be the winner independent of Ice Bear's moves or not. Also, determine if Lee can be the loser independent of Ice Bear's moves or not.

Input

The first line contains the integer t (1 ≤ t ≤ 10^5) — the number of rounds the game has.

Then t lines follow, each contains two integers s_i and e_i (1 ≤ s_i ≤ e_i ≤ 10^{18}) — the i-th round's information.

The rounds are played in the same order as given in input, s_i and e_i for all rounds are known to everyone before the game starts.

Output

Print two integers.

The first one should be 1 if Lee can be the winner independent of Ice Bear's moves, and 0 otherwise.

The second one should be 1 if Lee can be the loser independent of Ice Bear's moves, and 0 otherwise.

Examples

Input

3
5 8
1 4
3 10

Output

1 1

Input

4
1 2
2 3
3 4
4 5

Output

0 0

Input

1
1 1

Output

0 1

Input

2
1 9
4 5

Output

0 0

Input

2
1 2
2 8

Output

1 0

Input

6
216986951114298167 235031205335543871
148302405431848579 455670351549314242
506251128322958430 575521452907339082
1 768614336404564650
189336074809158272 622104412002885672
588320087414024192 662540324268197150

Output

1 0

Note

Remember, whoever writes an integer greater than e_i loses.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline long long solve_win(long long from, long long to) {
  if (from > to) {
    return 1;
  }
  for (;;) {
    long long nto = to / 2;
    if ((to & 1) || from > nto) {
      return (to - from) & 1;
    }
    long long nto2 = nto / 2 + 1;
    if (from >= nto2) {
      return 1;
    }
    to = nto2 - 1;
  }
}
inline long long solve_lose(long long from, long long to) {
  if (from > to) {
    return 0;
  }
  if (from * 2 > to) {
    return 1;
  }
  return solve_win(from, to / 2);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long T;
  cin >> T;
  vector<vector<long long>> can_second(T, vector<long long>(2)),
      can_first(T, vector<long long>(2));
  long long ptr = 0;
  for (long long iter = 0; iter < T; iter++) {
    long long from, to;
    cin >> from >> to;
    can_first[iter][0] = solve_win(from, to);
    can_first[iter][1] = solve_lose(from, to);
    if (solve_win(from * 2ll, to) && solve_win(from + 1, to)) {
      can_second[iter][0] = 1;
    }
    if (solve_lose(from * 2ll, to) && solve_lose(from + 1, to)) {
      can_second[iter][1] = 1;
    }
  }
  vector<bool> can(2, false);
  can[0] = true;
  for (long long iter = 0; iter < T; iter++) {
    vector<bool> ncan(2, false);
    if (can[0]) {
      if (can_first[iter][0]) {
        ncan[1] = true;
      }
      if (can_first[iter][1]) {
        ncan[0] = true;
      }
    }
    if (can[1]) {
      if (can_second[iter][0]) {
        ncan[1] = true;
      }
      if (can_second[iter][1]) {
        ncan[0] = true;
      }
    }
    can = ncan;
  }
  cout << can[1] << ' ' << can[0] << '\n';
}

```


### Prompt

Create a solution in cpp for the following problem:

The only difference between easy and hard versions is constraints.

There are n kids, each of them is reading a unique book. At the end of any day, the i-th kid will give his book to the p_i-th kid (in case of i = p_i the kid will give his book to himself). It is guaranteed that all values of p_i are distinct integers from 1 to n (i.e. p is a permutation). The sequence p doesn't change from day to day, it is fixed.

For example, if n=6 and p=[4, 6, 1, 3, 5, 2] then at the end of the first day the book of the 1-st kid will belong to the 4-th kid, the 2-nd kid will belong to the 6-th kid and so on. At the end of the second day the book of the 1-st kid will belong to the 3-th kid, the 2-nd kid will belong to the 2-th kid and so on.

Your task is to determine the number of the day the book of the i-th child is returned back to him for the first time for every i from 1 to n.

Consider the following example: p = [5, 1, 2, 4, 3]. The book of the 1-st kid will be passed to the following kids:

  * after the 1-st day it will belong to the 5-th kid,
  * after the 2-nd day it will belong to the 3-rd kid,
  * after the 3-rd day it will belong to the 2-nd kid,
  * after the 4-th day it will belong to the 1-st kid.

So after the fourth day, the book of the first kid will return to its owner. The book of the fourth kid will return to him for the first time after exactly one day.

You have to answer q independent queries.

Input

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

The first line of the query contains one integer n (1 ≤ n ≤ 200) — the number of kids in the query. The second line of the query contains n integers p_1, p_2, ..., p_n (1 ≤ p_i ≤ n, all p_i are distinct, i.e. p is a permutation), where p_i is the kid which will get the book of the i-th kid.

Output

For each query, print the answer on it: n integers a_1, a_2, ..., a_n, where a_i is the number of the day the book of the i-th child is returned back to him for the first time in this query.

Example

Input

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

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int p[maxn];
int a[maxn];
int n;
bool vis[maxn];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
    for (int i = 1; i <= n; i++) {
      if (vis[i]) continue;
      vis[i] = true;
      int t = p[i];
      int cnt = 1;
      while (t != i) {
        vis[t] = true;
        t = p[t];
        cnt++;
      }
      t = p[i];
      a[i] = cnt;
      while (t != i) {
        a[t] = cnt;
        t = p[t];
      }
    }
    for (int i = 1; i <= n; i++) {
      printf("%d ", a[i]);
    }
    printf("\n");
  }
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

New AtCoder City has an infinite grid of streets, as follows:

* At the center of the city stands a clock tower. Let (0, 0) be the coordinates of this point.
* A straight street, which we will call East-West Main Street, runs east-west and passes the clock tower. It corresponds to the x-axis in the two-dimensional coordinate plane.
* There are also other infinitely many streets parallel to East-West Main Street, with a distance of 1 between them. They correspond to the lines \ldots, y = -2, y = -1, y = 1, y = 2, \ldots in the two-dimensional coordinate plane.
* A straight street, which we will call North-South Main Street, runs north-south and passes the clock tower. It corresponds to the y-axis in the two-dimensional coordinate plane.
* There are also other infinitely many streets parallel to North-South Main Street, with a distance of 1 between them. They correspond to the lines \ldots, x = -2, x = -1, x = 1, x = 2, \ldots in the two-dimensional coordinate plane.

There are N residential areas in New AtCoder City. The i-th area is located at the intersection with the coordinates (X_i, Y_i) and has a population of P_i. Each citizen in the city lives in one of these areas.

The city currently has only two railroads, stretching infinitely, one along East-West Main Street and the other along North-South Main Street.
M-kun, the mayor, thinks that they are not enough for the commuters, so he decides to choose K streets and build a railroad stretching infinitely along each of those streets.

Let the walking distance of each citizen be the distance from his/her residential area to the nearest railroad.
M-kun wants to build railroads so that the sum of the walking distances of all citizens, S, is minimized.

For each K = 0, 1, 2, \dots, N, what is the minimum possible value of S after building railroads?

Constraints

* 1 \leq N \leq 15
* -10 \ 000 \leq X_i \leq 10 \ 000
* -10 \ 000 \leq Y_i \leq 10 \ 000
* 1 \leq P_i \leq 1 \ 000 \ 000
* The locations of the N residential areas, (X_i, Y_i), are all distinct.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X_1 Y_1 P_1
X_2 Y_2 P_2
:  :  :
X_N Y_N P_N

Output

Print the answer in N+1 lines.
The i-th line (i = 1, \ldots, N+1) should contain the minimum possible value of S after building railroads for the case K = i-1.

Examples

Input

3
1 2 300
3 3 600
1 4 800

Output

2900
900
0
0

Input

5
3 5 400
5 3 700
5 5 1000
5 7 700
7 5 400

Output

13800
1600
0
0
0
0

Input

6
2 5 1000
5 2 1100
5 5 1700
-2 -5 900
-5 -2 600
-5 -5 2200

Output

26700
13900
3200
1200
0
0
0

Input

8
2 2 286017
3 1 262355
2 -2 213815
1 -3 224435
-2 -2 136860
-3 -1 239338
-2 2 217647
-1 3 141903

Output

2576709
1569381
868031
605676
366338
141903
0
0
0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
#define PB push_back
#define MP make_pair
const int maxn = 200009;
const int MOD = 1e9 + 7;
int64_t X[1<<15][15],Y[1<<15][15];
int64_t AX[15],AY[15],AP[15],ans[16];
int main(){
#ifdef LOCAL
  freopen(".a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0);
  int n;cin>>n;
  for(int i=0;i<n;++i)cin>>AX[i]>>AY[i]>>AP[i];
  for(int i=0;i<(1<<n);++i){
    for(int j=0;j<n;++j){
      X[i][j]=abs(AX[j]);
      for(int k=0;k<n;++k)if(i>>k&1)X[i][j]=min(X[i][j],abs(AX[k]-AX[j]));
      Y[i][j]=abs(AY[j]);
      for(int k=0;k<n;++k)if(i>>k&1)Y[i][j]=min(Y[i][j],abs(AY[k]-AY[j]));
    }
  }
  for(int i=0;i<=n;++i)ans[i]=1e18;
  for(int i=0;i<(1<<n);++i){
    int c=__builtin_popcount(i);
    for(int j=i;;j=(j-1)&i){
      int64_t tmp=0;
      for(int a=0;a<n;++a){
        tmp+=min(X[j][a],Y[j^i][a])*AP[a];
      }
      ans[c]=min(ans[c],tmp);
      if(j==0)break;
    }
  }
  for(int i=0;i<=n;++i)cout<<ans[i]<<'\n';

  return 0;
}
//2020.07.25 21:54:09

```


### Prompt

Generate a cpp solution to the following problem:

There are n balls. They are arranged in a row. Each ball has a color (for convenience an integer) and an integer value. The color of the i-th ball is ci and the value of the i-th ball is vi.

Squirrel Liss chooses some balls and makes a new sequence without changing the relative order of the balls. She wants to maximize the value of this sequence.

The value of the sequence is defined as the sum of following values for each ball (where a and b are given constants):

  * If the ball is not in the beginning of the sequence and the color of the ball is same as previous ball's color, add (the value of the ball)  ×  a.
  * Otherwise, add (the value of the ball)  ×  b.

You are given q queries. Each query contains two integers ai and bi. For each query find the maximal value of the sequence she can make when a = ai and b = bi.

Note that the new sequence can be empty, and the value of an empty sequence is defined as zero.

Input

The first line contains two integers n and q (1 ≤ n ≤ 105; 1 ≤ q ≤ 500). The second line contains n integers: v1, v2, ..., vn (|vi| ≤ 105). The third line contains n integers: c1, c2, ..., cn (1 ≤ ci ≤ n).

The following q lines contain the values of the constants a and b for queries. The i-th of these lines contains two integers ai and bi (|ai|, |bi| ≤ 105).

In each line integers are separated by single spaces.

Output

For each query, output a line containing an integer — the answer to the query. The i-th line contains the answer to the i-th query in the input order.

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

Examples

Input

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

Output

20
9
4

Input

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

Output

5

Note

In the first example, to achieve the maximal value:

  * In the first query, you should select 1st, 3rd, and 4th ball.
  * In the second query, you should select 3rd, 4th, 5th and 6th ball.
  * In the third query, you should select 2nd and 4th ball.

Note that there may be other ways to achieve the maximal value.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
set<pair<long long, long long> > s;
long long dp[200005], val[200005], a, b, tmp, ans, mx[200005];
pair<long long, long long> ls[5];
int v[200005], pre[200005], cur, n, q, cl[200005], now;
long long gt(int c) {
  long long res = -(long long)1e18;
  for (int i = 0; i < now; i++)
    if (ls[i].first != c) res = max(res, ls[i].second);
  return res;
}
void ins(pair<long long, long long> P) {
  for (int i = 0; i < now; i++)
    if (ls[i].first == P.first) {
      ls[i].second = max(ls[i].second, P.second);
      return;
    }
  if (now < 2)
    ls[now++] = P;
  else {
    if (ls[1].second < ls[0].second) swap(ls[0], ls[1]);
    if (ls[0].second < P.second) ls[0] = P;
  }
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%lld", &val[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &cl[i]);
  v[0] = 200005;
  dp[0] = 0;
  while (q--) {
    scanf("%lld%lld", &a, &b);
    for (int i = 1; i <= n; i++) mx[i] = -(long long)1e18;
    now = 1;
    ls[0] = make_pair(-1, 0);
    ans = 0LL;
    for (int i = 1; i <= n; i++) {
      tmp = gt(cl[i]);
      if (mx[cl[i]] == -(long long)1e18) {
        dp[i] = tmp + val[i] * b;
        ins(make_pair(cl[i], dp[i]));
      } else {
        if (mx[cl[i]] + val[i] * a > tmp + val[i] * b)
          dp[i] = mx[cl[i]] + val[i] * a;
        else
          dp[i] = tmp + val[i] * b;
        ins(make_pair(cl[i], dp[i]));
      }
      mx[cl[i]] = max(mx[cl[i]], dp[i]);
      ans = max(ans, dp[i]);
    }
    printf("%lld\n", ans);
  }
}

```


### Prompt

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

Johnny has recently found an ancient, broken computer. The machine has only one register, which allows one to put in there one variable. Then in one operation, you can shift its bits left or right by at most three positions. The right shift is forbidden if it cuts off some ones. So, in fact, in one operation, you can multiply or divide your number by 2, 4 or 8, and division is only allowed if the number is divisible by the chosen divisor.

Formally, if the register contains a positive integer x, in one operation it can be replaced by one of the following:

  * x ⋅ 2
  * x ⋅ 4
  * x ⋅ 8
  * x / 2, if x is divisible by 2
  * x / 4, if x is divisible by 4
  * x / 8, if x is divisible by 8

For example, if x = 6, in one operation it can be replaced by 12, 24, 48 or 3. Value 6 isn't divisible by 4 or 8, so there're only four variants of replacement.

Now Johnny wonders how many operations he needs to perform if he puts a in the register and wants to get b at the end.

Input

The input consists of multiple test cases. The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases. The following t lines contain a description of test cases.

The first and only line in each test case contains integers a and b (1 ≤ a, b ≤ 10^{18}) — the initial and target value of the variable, respectively.

Output

Output t lines, each line should contain one integer denoting the minimum number of operations Johnny needs to perform. If Johnny cannot get b at the end, then write -1.

Example

Input

10
10 5
11 44
17 21
1 1
96 3
2 128
1001 1100611139403776
1000000000000000000 1000000000000000000
7 1
10 8

Output

1
1
-1
0
2
2
14
0
-1
-1

Note

In the first test case, Johnny can reach 5 from 10 by using the shift to the right by one (i.e. divide by 2).

In the second test case, Johnny can reach 44 from 11 by using the shift to the left by two (i.e. multiply by 4).

In the third test case, it is impossible for Johnny to reach 21 from 17.

In the fourth test case, initial and target values are equal, so Johnny has to do 0 operations.

In the fifth test case, Johnny can reach 3 from 96 by using two shifts to the right: one by 2, and another by 3 (i.e. divide by 4 and by 8).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    long long a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    int ans = 0;
    while (a < b) {
      if (a * 8 <= b)
        a *= 8;
      else if (a * 4 <= b)
        a *= 4;
      else
        a *= 2;
      ans++;
    }
    if (a == b)
      cout << ans << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

It is known that passages in Singer house are complex and intertwined. Let's define a Singer k-house as a graph built by the following process: take complete binary tree of height k and add edges from each vertex to all its successors, if they are not yet present.

<image> Singer 4-house

Count the number of non-empty paths in Singer k-house which do not pass the same vertex twice. Two paths are distinct if the sets or the orders of visited vertices are different. Since the answer can be large, output it modulo 109 + 7.

Input

The only line contains single integer k (1 ≤ k ≤ 400).

Output

Print single integer — the answer for the task modulo 109 + 7.

Examples

Input

2

Output

9

Input

3

Output

245

Input

20

Output

550384565

Note

There are 9 paths in the first example (the vertices are numbered on the picture below): 1, 2, 3, 1-2, 2-1, 1-3, 3-1, 2-1-3, 3-1-2.

<image> Singer 2-house

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long dp[400 + 5][400 + 5];
void init() {
  memset(dp, 0, sizeof(dp));
  dp[1][1] = dp[1][0] = 1;
  for (int i = 2; i <= 400; i++)
    for (int j = 0; j <= 400; j++)
      for (int k = 0; k + j <= 400; k++) {
        long long temp = (dp[i - 1][j] * dp[i - 1][k]) % 1000000007;
        dp[i][j + k] = (dp[i][j + k] + temp) % 1000000007;
        dp[i][j + k - 1] =
            (dp[i][j + k - 1] + temp * (k + j) * (k + j - 1)) % 1000000007;
        dp[i][j + k + 1] = (dp[i][j + k + 1] + temp) % 1000000007;
        dp[i][j + k] = (dp[i][j + k] + (temp * (k + j) * 2)) % 1000000007;
      }
}
int main() {
  init();
  int n;
  while (~scanf("%d", &n)) {
    printf("%lld\n", dp[n][1]);
  }
  return 0;
}

```


### Prompt

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

You're given a tree with n vertices.

Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size.

Input

The first line contains an integer n (1 ≤ n ≤ 10^5) denoting the size of the tree.

The next n - 1 lines contain two integers u, v (1 ≤ u, v ≤ n) each, describing the vertices connected by the i-th edge.

It's guaranteed that the given edges form a tree.

Output

Output a single integer k — the maximum number of edges that can be removed to leave all connected components with even size, or -1 if it is impossible to remove edges in order to satisfy this property.

Examples

Input

4
2 4
4 1
3 1

Output

1

Input

3
1 2
1 3

Output

-1

Input

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

Output

4

Input

2
1 2

Output

0

Note

In the first example you can remove the edge between vertices 1 and 4. The graph after that will have two connected components with two vertices in each.

In the second example you can't remove edges in such a way that all components have even number of vertices, so the answer is -1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int Z = (int)3e3 + 111;
const int N = (int)3e5 + 111;
const int INF = (int)1e9 + 111;
const int MOD = (int)1e9 + 7;
vector<int> g[N];
bool used[N];
int cnt[N], ans;
int dfs(int v) {
  used[v] = 1;
  for (int to : g[v])
    if (!used[to])
      if (!dfs(to)) cnt[v] = 1 - cnt[v];
  return cnt[v];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0, x, y; i < n - 1; i++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  if (n % 2) {
    cout << -1;
    return 0;
  }
  dfs(1);
  for (int i = 1; i <= n; i++) ans += cnt[i];
  cout << --ans;
  return 0;
}

```


### Prompt

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

You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.

Input

The first line contains integer n (1 ≤ n ≤ 3·105) — the number of points on the line.

The second line contains n integers xi ( - 109 ≤ xi ≤ 109) — the coordinates of the given n points.

Output

Print the only integer x — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.

Example

Input

4
1 2 3 4

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  sort(arr.begin(), arr.end());
  cout << arr[(n - 1) / 2] << endl;
  return 0;
}

```


### Prompt

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

The Smart Beaver has recently designed and built an innovative nanotechnologic all-purpose beaver mass shaving machine, "Beavershave 5000". Beavershave 5000 can shave beavers by families! How does it work? Very easily!

There are n beavers, each of them has a unique id from 1 to n. Consider a permutation a1, a2, ..., an of n these beavers. Beavershave 5000 needs one session to shave beavers with ids from x to y (inclusive) if and only if there are such indices i1 < i2 < ... < ik, that ai1 = x, ai2 = x + 1, ..., aik - 1 = y - 1, aik = y. And that is really convenient. For example, it needs one session to shave a permutation of beavers 1, 2, 3, ..., n.

If we can't shave beavers from x to y in one session, then we can split these beavers into groups [x, p1], [p1 + 1, p2], ..., [pm + 1, y] (x ≤ p1 < p2 < ... < pm < y), in such a way that the machine can shave beavers in each group in one session. But then Beavershave 5000 needs m + 1 working sessions to shave beavers from x to y.

All beavers are restless and they keep trying to swap. So if we consider the problem more formally, we can consider queries of two types:

  * what is the minimum number of sessions that Beavershave 5000 needs to shave beavers with ids from x to y, inclusive?
  * two beavers on positions x and y (the beavers ax and ay) swapped.

You can assume that any beaver can be shaved any number of times.

Input

The first line contains integer n — the total number of beavers, 2 ≤ n. The second line contains n space-separated integers — the initial beaver permutation.

The third line contains integer q — the number of queries, 1 ≤ q ≤ 105. The next q lines contain the queries. Each query i looks as pi xi yi, where pi is the query type (1 is to shave beavers from xi to yi, inclusive, 2 is to swap beavers on positions xi and yi). All queries meet the condition: 1 ≤ xi < yi ≤ n.

  * to get 30 points, you need to solve the problem with constraints: n ≤ 100 (subproblem B1);
  * to get 100 points, you need to solve the problem with constraints: n ≤ 3·105 (subproblems B1+B2).

Note that the number of queries q is limited 1 ≤ q ≤ 105 in both subproblem B1 and subproblem B2.

Output

For each query with pi = 1, print the minimum number of Beavershave 5000 sessions.

Examples

Input

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

Output

2
1
3
5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int A[300010];
int I[300010];
void TheSolution(istream& input, ostream& output) {
  int n, m, a, b, t;
  input >> n;
  for (int i = 1; i < n + 1; ++i) {
    input >> A[i];
    I[A[i]] = i;
  }
  input >> m;
  for (int i = 0; i < m; ++i) {
    input >> t >> a >> b;
    if (t == 1) {
      int cnt = 1;
      for (int j = a; j < b; ++j) {
        if (I[j + 1] < I[j]) cnt++;
      }
      output << cnt << "\n";
    } else {
      swap(I[A[a]], I[A[b]]);
      swap(A[a], A[b]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  TheSolution(cin, cout);
  return 0;
}

```


### Prompt

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

Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.

Constraints

* 1 \leq X \leq 10^9
* X is an integer.
* There exists a pair of integers (A, B) satisfying the condition in Problem Statement.

Input

Input is given from Standard Input in the following format:

X

Output

Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them.

A B

Output

Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them.

A B

Examples

Input

33

Output

2 -1

Input

1

Output

0 -1

### Response

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

int main(){
  int x;
  cin>>x;

  for(int i=-119;i<119;i++){
    for(int j=-119;j<119;j++){
      if(x==i*i*i*i*i-j*j*j*j*j){
        cout<<i<<endl;
        cout<<j<<endl;
        return 0;
      }
    }
  }
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

There is a robot on a coordinate plane. Initially, the robot is located at the point (0, 0). Its path is described as a string s of length n consisting of characters 'L', 'R', 'U', 'D'.

Each of these characters corresponds to some move:

  * 'L' (left): means that the robot moves from the point (x, y) to the point (x - 1, y);
  * 'R' (right): means that the robot moves from the point (x, y) to the point (x + 1, y);
  * 'U' (up): means that the robot moves from the point (x, y) to the point (x, y + 1);
  * 'D' (down): means that the robot moves from the point (x, y) to the point (x, y - 1).

The company that created this robot asked you to optimize the path of the robot somehow. To do this, you can remove any non-empty substring of the path. But this company doesn't want their customers to notice the change in the robot behavior. It means that if before the optimization the robot ended its path at the point (x_e, y_e), then after optimization (i.e. removing some single substring from s) the robot also ends its path at the point (x_e, y_e).

This optimization is a low-budget project so you need to remove the shortest possible non-empty substring to optimize the robot's path such that the endpoint of his path doesn't change. It is possible that you can't optimize the path. Also, it is possible that after the optimization the target path is an empty string (i.e. deleted substring is the whole string s).

Recall that the substring of s is such string that can be obtained from s by removing some amount of characters (possibly, zero) from the prefix and some amount of characters (possibly, zero) from the suffix. For example, the substrings of "LURLLR" are "LU", "LR", "LURLLR", "URL", but not "RR" and "UL".

You have to answer t independent test cases.

Input

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

The next 2t lines describe test cases. Each test case is given on two lines. The first line of the test case contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the robot's path. The second line of the test case contains one string s consisting of n characters 'L', 'R', 'U', 'D' — the robot's path.

It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5 (∑ n ≤ 2 ⋅ 10^5).

Output

For each test case, print the answer on it. If you cannot remove such non-empty substring that the endpoint of the robot's path doesn't change, print -1. Otherwise, print two integers l and r such that 1 ≤ l ≤ r ≤ n — endpoints of the substring you remove. The value r-l+1 should be minimum possible. If there are several answers, print any of them.

Example

Input

4
4
LRUD
4
LURD
5
RRUDU
5
LLDDR

Output

1 2
1 4
3 4
-1

### Response

```cpp
#include <bits/stdc++.h>
const long long MAX_SIZE = 2005;
using namespace std;
int main() {
  long long i, j, k, t, n, x, y;
  string a, s;
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> s;
    k = 100000007;
    long long ans1 = 100000007, ans2 = 100000007;
    map<long long, map<long long, long long> > m;
    x = y = 0;
    m[0][0] = 1;
    for (i = 0; i < n; i++) {
      if (s[i] == 'L')
        x--;
      else if (s[i] == 'R')
        x++;
      else if (s[i] == 'U')
        y++;
      else
        y--;
      if (m[x][y] == 0) {
        m[x][y] = i + 2;
        continue;
      }
      j = i + 2 - m[x][y];
      if (j < k) {
        k = j;
        ans1 = m[x][y];
        ans2 = i + 2;
      }
      m[x][y] = i + 2;
    }
    if (ans1 == 100000007)
      cout << "-1\n";
    else
      cout << ans1 << " " << --ans2 << "\n";
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).

<image>

Alice and Bob play dice. Alice has built a tower from n dice. We know that in this tower the adjacent dice contact with faces with distinct numbers. Bob wants to uniquely identify the numbers written on the faces of all dice, from which the tower is built. Unfortunately, Bob is looking at the tower from the face, and so he does not see all the numbers on the faces. Bob sees the number on the top of the tower and the numbers on the two adjacent sides (on the right side of the picture shown what Bob sees).

Help Bob, tell whether it is possible to uniquely identify the numbers on the faces of all the dice in the tower, or not.

Input

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

The second line contains an integer x (1 ≤ x ≤ 6) — the number Bob sees at the top of the tower. Next n lines contain two space-separated integers each: the i-th line contains numbers ai, bi (1 ≤ ai, bi ≤ 6; ai ≠ bi) — the numbers Bob sees on the two sidelong faces of the i-th dice in the tower.

Consider the dice in the tower indexed from top to bottom from 1 to n. That is, the topmost dice has index 1 (the dice whose top face Bob can see). It is guaranteed that it is possible to make a dice tower that will look as described in the input.

Output

Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes).

Examples

Input

3
6
3 2
5 4
2 4

Output

YES

Input

3
3
2 6
4 1
5 3

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
int n;
int top;
int a[199], b[199];
void suru() {
  scanf("%d", &n);
  scanf("%d", &top);
  for (int i = 0; i < n; i++) scanf("%d %d", a + i, b + i);
}
int c[10];
void truli() {
  int flag = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= 6; j++) c[j] = 0;
    c[a[i]]++;
    c[b[i]]++;
    c[7 - a[i]]++;
    c[7 - b[i]]++;
    int ff = 1, da = -1, db = -1;
    for (int j = 1; j <= 6; j++) {
      if (c[j] == 0) {
        if (da == -1)
          da = j;
        else
          db = j;
      }
    }
    if (da == top) std::swap(da, db);
    if (db != top) {
      flag = 0;
      break;
    } else
      top = db;
  }
  if (flag)
    puts("YES");
  else
    puts("NO");
}
void sutru() {}
int main() {
  suru();
  truli();
  sutru();
  return 0;
}

```