### Prompt

Please create a solution in cpp to the following problem:

You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.

The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.

Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c).

You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this?

Input

The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description.

Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice).

The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked.

The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one.

Output

If you can reach the destination, print 'YES', otherwise print 'NO'.

Examples

Input

4 6
X...XX
...XX.
.X..X.
......
1 6
2 2

Output

YES

Input

5 4
.X..
...X
X.X.
....
.XX.
5 3
1 1

Output

NO

Input

4 7
..X.XX.
.XX..X.
X...X..
X......
2 2
1 6

Output

YES

Note

In the first sample test one possible path is:

<image>

After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
char str[505][505];
int d[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
bool vis[505][505];
int px, py, qx, qy;
pair<int, int> q[1000001], pre[505][505];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", str[i]);
  scanf("%d %d", &px, &py);
  scanf("%d %d", &qx, &qy);
  --px, --qx, --py, --qy;
  int h = 0, t = 1;
  q[t] = make_pair(px, py);
  while (h < t) {
    pair<int, int> k = q[++h];
    for (int i = 0; i < 4; i++) {
      int tmpx = k.first + d[i][0];
      int tmpy = k.second + d[i][1];
      if (tmpx < 0 || tmpx >= n || tmpy < 0 || tmpy >= m) continue;
      if (str[tmpx][tmpy] == 'X' && (tmpx != qx || tmpy != qy)) continue;
      if (vis[tmpx][tmpy]) continue;
      q[++t] = make_pair(tmpx, tmpy);
      pre[tmpx][tmpy] = k;
      vis[tmpx][tmpy] = true;
    }
  }
  if (!vis[qx][qy])
    printf("NO\n");
  else {
    if (str[qx][qy] == 'X') {
      printf("YES\n");
      return 0;
    }
    for (int i = qx, j = qy; i != px || j != py;) {
      if (i != qx || j != qy) str[i][j] = 'X';
      pair<int, int> tmp = pre[i][j];
      i = tmp.first, j = tmp.second;
    }
    memset(vis, false, sizeof(vis));
    int h = 0, t = 1;
    q[t] = make_pair(qx, qy);
    while (h < t) {
      pair<int, int> k = q[++h];
      for (int i = 0; i < 4; i++) {
        int tmpx = k.first + d[i][0];
        int tmpy = k.second + d[i][1];
        if (tmpx < 0 || tmpx >= n || tmpy < 0 || tmpy >= m) continue;
        if (str[tmpx][tmpy] == 'X') continue;
        if (vis[tmpx][tmpy]) continue;
        q[++t] = make_pair(tmpx, tmpy);
        pre[tmpx][tmpy] = k;
        vis[tmpx][tmpy] = true;
      }
    }
    if (vis[qx][qy])
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}

```


### Prompt

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

Polycarp's phone book contains n phone numbers, each of them is described by s_i — the number itself and m_i — the number of times Polycarp dials it in daily.

Polycarp has just bought a brand new phone with an amazing speed dial feature! More precisely, k buttons on it can have a number assigned to it (not necessary from the phone book). To enter some number Polycarp can press one of these k buttons and then finish the number using usual digit buttons (entering a number with only digit buttons is also possible).

Speed dial button can only be used when no digits are entered. No button can have its number reassigned.

What is the minimal total number of digit number presses Polycarp can achieve after he assigns numbers to speed dial buttons and enters each of the numbers from his phone book the given number of times in an optimal way?

Input

The first line contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ 10) — the amount of numbers in Polycarp's phone book and the number of speed dial buttons his new phone has.

The i-th of the next n lines contain a string s_i and an integer m_i (1 ≤ m_i ≤ 500), where s_i is a non-empty string of digits from 0 to 9 inclusive (the i-th number), and m_i is the amount of times it will be dialed, respectively.

It is guaranteed that the total length of all phone numbers will not exceed 500.

Output

Print a single integer — the minimal total number of digit number presses Polycarp can achieve after he assigns numbers to speed dial buttons and enters each of the numbers from his phone book the given number of times in an optimal way.

Examples

Input

3 1
0001 5
001 4
01 1

Output

14

Input

3 1
0001 5
001 6
01 1

Output

18

Note

The only speed dial button in the first example should have "0001" on it. The total number of digit button presses will be 0 ⋅ 5 for the first number + 3 ⋅ 4 for the second + 2 ⋅ 1 for the third. 14 in total.

The only speed dial button in the second example should have "00" on it. The total number of digit button presses will be 2 ⋅ 5 for the first number + 1 ⋅ 6 for the second + 2 ⋅ 1 for the third. 18 in total.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
int tr[535][12], cnt = 1, K;
int dp[535], f[535][535][12], val[535];
char ins[535];
void dfs(int x) {
  for (int(j) = 0; (j) < (int)(10); (j)++)
    if (tr[x][j]) {
      int v = tr[x][j];
      dfs(v);
      for (int d = 0; d <= dp[x]; d++) {
        for (int i = K; i >= 0; i--) {
          int tmp = (1 << 30);
          for (int j = 0; j <= i; j++) {
            mintt(tmp, f[x][d][j] + f[v][d + 1][i - j]);
          }
          f[x][d][i] = tmp;
        }
      }
    }
  for (int d = 0; d <= dp[x]; d++) {
    for (int i = K; i >= 0; i--) {
      f[x][d][i] += d * val[x];
    }
  }
  for (int d = 0; d <= dp[x]; d++) {
    for (int i = K; i >= 1; i--) {
      mintt(f[x][d][i], f[x][0][i - 1]);
    }
  }
}
void fmain(int tid) {
  scanf("%d%d", &n, &K);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    scanf("%s%d", ins + 1, &m);
    int rt = 1;
    int l = strlen(ins + 1);
    for (int(j) = 1; (j) <= (int)(l); (j)++) {
      int c = ins[j] - '0';
      if (tr[rt][c] == 0) {
        tr[rt][c] = ++cnt;
        dp[cnt] = dp[rt] + 1;
      }
      rt = tr[rt][c];
    }
    val[rt] += m;
  }
  dfs(1);
  printf("%d\n", f[1][0][K]);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

You are given a permutation p_1, p_2, ... , p_n (an array where each integer from 1 to n appears exactly once). The weight of the i-th element of this permutation is a_i.

At first, you separate your permutation into two non-empty sets — prefix and suffix. More formally, the first set contains elements p_1, p_2, ... , p_k, the second — p_{k+1}, p_{k+2}, ... , p_n, where 1 ≤ k < n.

After that, you may move elements between sets. The operation you are allowed to do is to choose some element of the first set and move it to the second set, or vice versa (move from the second set to the first). You have to pay a_i dollars to move the element p_i.

Your goal is to make it so that each element of the first set is less than each element of the second set. Note that if one of the sets is empty, this condition is met.

For example, if p = [3, 1, 2] and a = [7, 1, 4], then the optimal strategy is: separate p into two parts [3, 1] and [2] and then move the 2-element into first set (it costs 4). And if p = [3, 5, 1, 6, 2, 4], a = [9, 1, 9, 9, 1, 9], then the optimal strategy is: separate p into two parts [3, 5, 1] and [6, 2, 4], and then move the 2-element into first set (it costs 1), and 5-element into second set (it also costs 1).

Calculate the minimum number of dollars you have to spend.

Input

The first line contains one integer n (2 ≤ n ≤ 2 ⋅ 10^5) — the length of permutation.

The second line contains n integers p_1, p_2, ... , p_n (1 ≤ p_i ≤ n). It's guaranteed that this sequence contains each element from 1 to n exactly once.

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

Output

Print one integer — the minimum number of dollars you have to spend.

Examples

Input

3
3 1 2
7 1 4

Output

4

Input

4
2 4 1 3
5 9 8 3

Output

3

Input

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

Output

2

### Response

```cpp
#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
using namespace std;
const long long N = 3e5 + 5;
const long long mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
long long test = 1, n, a[N], ind[N], pre[N], b[N];
long long tree[4 * N + 8], lazy[4 * N + 8];
void build(int node, int start, int end) {
  if (start == end) {
    tree[node] = pre[start];
  } else {
    int mid = (start + end) / 2;
    build(2 * node, start, mid);
    build(2 * node + 1, mid + 1, end);
    tree[node] = min(tree[2 * node], tree[2 * node + 1]);
  }
}
void pushlazy(int start, int end, int node, long long val) {
  tree[node] += val;
  if (start != end) {
    lazy[node * 2] += val;
    lazy[node * 2 + 1] += val;
  }
  lazy[node] = 0;
}
void update(int node, int start, int end, int l, int r, long long val) {
  pushlazy(start, end, node, lazy[node]);
  if (start > end or start > r or end < l) return;
  if (start >= l and end <= r) {
    pushlazy(start, end, node, val);
    return;
  }
  int mid = (start + end) / 2;
  update(node * 2, start, mid, l, r, val);
  update(node * 2 + 1, mid + 1, end, l, r, val);
  tree[node] = min(tree[node * 2], tree[node * 2 + 1]);
}
long long query(int node, int start, int end, int l, int r) {
  if (start > end or start > r or end < l) return +INF;
  pushlazy(start, end, node, lazy[node]);
  if (l <= start and end <= r) return tree[node];
  int mid = (start + end) / 2;
  long long p1 = query(2 * node, start, mid, l, r);
  long long p2 = query(2 * node + 1, mid + 1, end, l, r);
  return min(p1, p2);
}
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> b[i], ind[b[i]] = i;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + a[ind[i]];
  long long ans = a[1];
  build(1, 1, n);
  for (int i = 1; i < n; i++) {
    update(1, 1, n, b[i], n, -a[i]);
    update(1, 1, n, 1, b[i] - 1, +a[i]);
    ans = min(ans, query(1, 1, n, 1, n));
  }
  cout << ans << " "
       << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout << setprecision(10);
  ;
  for (int i = 1; i <= test; i++) {
    solve();
  }
}

```


### Prompt

Create a solution in Cpp for the following problem:

There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order.

You can perform the following operation on this integer sequence any number of times:

Operation: Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1.

Let B_1, B_2, ..., B_N be the integer sequence after your operations.

Find the maximum possible value of B_1 + B_2 + ... + B_N.

Constraints

* All values in input are integers.
* 2 \leq N \leq 10^5
* -10^9 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible value of B_1 + B_2 + ... + B_N.

Examples

Input

3
-10 5 -4

Output

19

Input

5
10 -4 -8 -11 3

Output

30

Input

11
-1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000

Output

10000000000

### Response

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

int main() {
  int N;
  cin >> N;
  int cnt = 0, mi = 1e9+1;
  long long sum = 0;
  for (int i = 0, a; i < N && cin >> a; i++) {
    if (a < 0) cnt++;
    mi = min(mi, abs(a));
    sum += abs(a);
  }
  cout << ((cnt % 2) ? sum - mi * 2 : sum) << "\n";
}
```


### Prompt

Generate a CPP solution to the following problem:

There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N, and for each i (1 \leq i \leq M), the i-th directed edge goes from Vertex x_i to y_i. G does not contain directed cycles.

Find the length of the longest directed path in G. Here, the length of a directed path is the number of edges in it.

Constraints

* All values in input are integers.
* 2 \leq N \leq 10^5
* 1 \leq M \leq 10^5
* 1 \leq x_i, y_i \leq N
* All pairs (x_i, y_i) are distinct.
* G does not contain directed cycles.

Input

Input is given from Standard Input in the following format:

N M
x_1 y_1
x_2 y_2
:
x_M y_M

Output

Print the length of the longest directed path in G.

Examples

Input

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

Output

3

Input

6 3
2 3
4 5
5 6

Output

2

Input

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

Output

3

### Response

```cpp
#include <iostream>
#include <vector>
using namespace std;
vector <int> v[100005];
int dp[100005];
int dfs(int node){
	if(dp[node]!=0){
		return dp[node];
	}
	int maxn=0;
	for(auto a:v[node])
		maxn=max(maxn,dfs(a));
	return dp[node]=maxn+1;
}
int main() {
	// your code goes here
	int n,m;
	cin >>n>>m;
	for(int i=1;i<m+1;i++){
		int a,b;
		cin >>a>>b;
		v[a].push_back(b);
	}
	int maxd=0;
	for(int i=1;i<=n;i++){
		if(dp[i]==0){
			dfs(i);
		}
		maxd=max(maxd,dp[i]);
	}
	cout<<maxd-1;
	return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Constanze is the smartest girl in her village but she has bad eyesight.

One day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece of paper. For example, if you pronounce 'c', 'o', 'd', and 'e' in that order, then the machine will inscribe "code" onto the paper. Thanks to this machine, she can finally write messages without using her glasses.

However, her dumb friend Akko decided to play a prank on her. Akko tinkered with the machine so that if you pronounce 'w', it will inscribe "uu" instead of "w", and if you pronounce 'm', it will inscribe "nn" instead of "m"! Since Constanze had bad eyesight, she was not able to realize what Akko did.

The rest of the letters behave the same as before: if you pronounce any letter besides 'w' and 'm', the machine will just inscribe it onto a piece of paper.

The next day, I received a letter in my mailbox. I can't understand it so I think it's either just some gibberish from Akko, or Constanze made it using her machine. But since I know what Akko did, I can just list down all possible strings that Constanze's machine would have turned into the message I got and see if anything makes sense.

But I need to know how much paper I will need, and that's why I'm asking you for help. Tell me the number of strings that Constanze's machine would've turned into the message I got.

But since this number can be quite large, tell me instead its remainder when divided by 10^9+7.

If there are no strings that Constanze's machine would've turned into the message I got, then print 0.

Input

Input consists of a single line containing a string s (1 ≤ |s| ≤ 10^5) — the received message. s contains only lowercase Latin letters.

Output

Print a single integer — the number of strings that Constanze's machine would've turned into the message s, modulo 10^9+7.

Examples

Input

ouuokarinn

Output

4

Input

banana

Output

1

Input

nnn

Output

3

Input

amanda

Output

0

Note

For the first example, the candidate strings are the following: "ouuokarinn", "ouuokarim", "owokarim", and "owokarinn".

For the second example, there is only one: "banana".

For the third example, the candidate strings are the following: "nm", "mn" and "nnn".

For the last example, there are no candidate strings that the machine can turn into "amanda", since the machine won't inscribe 'm'.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
signed main() {
  string s;
  cin >> s;
  vector<long long> lst;
  long long cnt1 = 1, cnt2 = 1;
  if (s[0] == 'w' || s[0] == 'm') {
    cout << 0;
    return 0;
  }
  for (long long i = 1; i < s.size(); i++) {
    if (s[i] == 'w' || s[i] == 'm') {
      cout << 0;
      return 0;
    }
    if (s[i] == s[i - 1] && s[i] == 'u') {
      cnt1++;
      if (cnt2 != 1) {
        lst.push_back(cnt2);
        cnt2 = 1;
      }
    } else if (s[i] == s[i - 1] && s[i] == 'n') {
      cnt2++;
      if (cnt1 != 1) {
        lst.push_back(cnt1);
        cnt1 = 1;
      }
    } else {
      if (cnt2 != 1) {
        lst.push_back(cnt2);
        cnt2 = 1;
      }
      if (cnt1 != 1) {
        lst.push_back(cnt1);
        cnt1 = 1;
      }
    }
  }
  if (cnt2 != 1) {
    lst.push_back(cnt2);
    cnt2 = 1;
  }
  if (cnt1 != 1) {
    lst.push_back(cnt1);
    cnt1 = 1;
  }
  sort(lst.begin(), lst.end());
  long long ans = 1;
  long long a = 1, b = 2, c = 3, i = 0, cur = 3;
  while (i != lst.size()) {
    if (lst[i] == 2) {
      ans *= 2;
      ans %= 1000000007;
      i++;
    } else if (lst[i] == 1)
      i++;
    else {
      while (cur != lst[i]) {
        a = b;
        b = c;
        c = a + b;
        c %= 1000000007;
        cur++;
      }
      ans *= c;
      ans %= 1000000007;
      i++;
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Harry, upon inquiring Helena Ravenclaw's ghost, came to know that she told Tom Riddle or You-know-who about Rowena Ravenclaw's diadem and that he stole it from her.

Harry thought that Riddle would have assumed that he was the only one to discover the Room of Requirement and thus, would have hidden it there. So Harry is trying to get inside the Room of Requirement to destroy the diadem as he knows that it is a horcrux.

But he has to answer a puzzle in order to enter the room. He is given n objects, numbered from 1 to n. Some of the objects have a parent object, that has a lesser number. Formally, object i may have a parent object parenti such that parenti < i.

There is also a type associated with each parent relation, it can be either of type 1 or type 2. Type 1 relation means that the child object is like a special case of the parent object. Type 2 relation means that the second object is always a part of the first object and all its special cases.

Note that if an object b is a special case of object a, and c is a special case of object b, then c is considered to be a special case of object a as well. The same holds for parts: if object b is a part of a, and object c is a part of b, then we say that object c is a part of a. Also note, that if object b is a part of a, and object c is a special case of a, then b is a part of c as well.

An object is considered to be neither a part of itself nor a special case of itself.

Now, Harry has to answer two type of queries:

  * 1 u v: he needs to tell if object v is a special case of object u.
  * 2 u v: he needs to tell if object v is a part of object u.

Input

First line of input contains the number n (1 ≤ n ≤ 105), the number of objects.

Next n lines contain two integer parenti and typei ( - 1 ≤ parenti < i parenti ≠ 0,  - 1 ≤ typei ≤ 1), implying that the i-th object has the parent parenti. (If typei = 0, this implies that the object i is a special case of object parenti. If typei = 1, this implies that the object i is a part of object parenti). In case the i-th object has no parent, both parenti and typei are -1.

Next line contains an integer q (1 ≤ q ≤ 105), the number of queries.

Next q lines each represent a query having three space separated integers typei, ui, vi (1 ≤ typei ≤ 2, 1 ≤ u, v ≤ n).

Output

Output will contain q lines, each containing the answer for the corresponding query as "YES" (affirmative) or "NO" (without quotes).

You can output each letter in any case (upper or lower).

Examples

Input

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

Output

YES
NO

Input

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

Output

YES
NO

Note

In test case 1, as object 2 is a special case of object 1 and object 3 is a special case of object 2, this makes object 3 a special case of object 1.

In test case 2, as object 2 is a special case of object 1 and object 1 has object 3, this will mean that object 2 will also have object 3. This is because when a general case (object 1) has object 3, its special case (object 2) will definitely have object 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 3;
int n, q, p, ttype, height[maxn], first[maxn], t[8 * maxn], u, v;
vector<int> euler, roots;
vector<int> adjs[maxn], sc_adjs[maxn], pa_adjs[maxn];
bool vis[maxn], compovis[maxn];
int cnt, compo_id[maxn], sc_compoid[maxn], pa_compoid[maxn];
void build(int v, int tl, int tr) {
  if (tl == tr)
    t[v] = euler[tl];
  else {
    int tm = (tl + tr) / 2;
    build(2 * v, tl, tm);
    build(2 * v + 1, tm + 1, tr);
    int l = t[2 * v], r = t[2 * v + 1];
    t[v] = (height[l] <= height[r]) ? l : r;
  }
}
void dfs(int u, int h) {
  vis[u] = 1;
  first[u] = euler.size();
  height[u] = h;
  compo_id[u] = cnt;
  euler.push_back(u);
  for (int v : adjs[u])
    if (!vis[v]) {
      dfs(v, h + 1);
      euler.push_back(u);
    }
}
void sc_component(int u) {
  compovis[u] = 1;
  sc_compoid[u] = cnt;
  for (int v : sc_adjs[u])
    if (!compovis[v]) sc_component(v);
}
void pa_component(int u) {
  compovis[u] = 1;
  pa_compoid[u] = cnt;
  for (int v : pa_adjs[u])
    if (!compovis[v]) pa_component(v);
}
int query(int v, int tl, int tr, int l, int r) {
  if (l > r) return -1;
  if (tl == l && tr == r) return t[v];
  int tm = (tl + tr) / 2;
  int p1 = query(2 * v, tl, tm, l, min(tm, r));
  int p2 = query(2 * v + 1, tm + 1, tr, max(tm + 1, l), r);
  if (p1 == -1) return p2;
  if (p2 == -1) return p1;
  return (height[p1] <= height[p2]) ? p1 : p2;
}
int lca(int u, int v) {
  if (first[u] > first[v]) swap(u, v);
  return query(1, 0, euler.size() - 1, first[u], first[v]);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &p, &ttype);
    if (p == -1 && ttype == -1)
      roots.push_back(i);
    else {
      p--;
      adjs[p].push_back(i);
      if (ttype == 0)
        sc_adjs[p].push_back(i);
      else if (ttype == 1)
        pa_adjs[p].push_back(i);
    }
  }
  for (int root : roots) cnt++, dfs(root, 0);
  build(1, 0, euler.size() - 1);
  cnt = 0;
  for (int i = 0; i < n; i++)
    if (!compovis[i]) cnt++, sc_component(i);
  cnt = 0;
  fill_n(compovis, n, 0);
  for (int i = 0; i < n; i++)
    if (!compovis[i]) cnt++, pa_component(i);
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d %d", &ttype, &u, &v);
    u--, v--;
    if (u == v) {
      cout << "NO" << endl;
      continue;
    }
    int p = lca(u, v);
    if (ttype == 1) {
      if (p == u && sc_compoid[u] == sc_compoid[v]) {
        cout << "YES" << endl;
        continue;
      }
    } else {
      if (p != v && sc_compoid[p] == sc_compoid[u] &&
          pa_compoid[p] == pa_compoid[v]) {
        cout << "YES" << endl;
        continue;
      }
    }
    cout << "NO" << endl;
  }
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

You are given three strings s, t and p consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.

During each operation you choose any character from p, erase it from p and insert it into string s (you may insert this character anywhere you want: in the beginning of s, in the end or between any two consecutive characters).

For example, if p is aba, and s is de, then the following outcomes are possible (the character we erase from p and insert into s is highlighted):

  * aba → ba, de → ade;
  * aba → ba, de → dae;
  * aba → ba, de → dea;
  * aba → aa, de → bde;
  * aba → aa, de → dbe;
  * aba → aa, de → deb;
  * aba → ab, de → ade;
  * aba → ab, de → dae;
  * aba → ab, de → dea;

Your goal is to perform several (maybe zero) operations so that s becomes equal to t. Please determine whether it is possible.

Note that you have to answer q independent queries.

Input

The first line contains one integer q (1 ≤ q ≤ 100) — the number of queries. Each query is represented by three consecutive lines.

The first line of each query contains the string s (1 ≤ |s| ≤ 100) consisting of lowercase Latin letters.

The second line of each query contains the string t (1 ≤ |t| ≤ 100) consisting of lowercase Latin letters.

The third line of each query contains the string p (1 ≤ |p| ≤ 100) consisting of lowercase Latin letters.

Output

For each query print YES if it is possible to make s equal to t, and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

Example

Input

4
ab
acxb
cax
a
aaaa
aaabbcc
a
aaaa
aabbcc
ab
baaa
aaaaa

Output

YES
YES
NO
NO

Note

In the first test case there is the following sequence of operation:

  1. s =  ab, t =  acxb, p =  cax;
  2. s =  acb, t =  acxb, p =  ax;
  3. s =  acxb, t =  acxb, p =  a.

In the second test case there is the following sequence of operation:

  1. s =  a, t =  aaaa, p =  aaabbcc;
  2. s =  aa, t =  aaaa, p =  aabbcc;
  3. s =  aaa, t =  aaaa, p =  abbcc;
  4. s =  aaaa, t =  aaaa, p =  bbcc.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
const int M = 21;
const long long mod = 1e9 + 7;
const long long MOD = 998244353;
const long double eps = 0.000000001;
const int P = 1336;
const long long inf = 1e17;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
int x[N], y[N], z[N];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  int q;
  cin >> q;
  for (int l = 0; l < q; l++) {
    string a, b, p;
    cin >> a >> b >> p;
    int n = a.size();
    int m = b.size();
    if (n > m) {
      cout << "NO" << '\n';
      continue;
    }
    int j = 0;
    for (int i = 0; i < m; i++) {
      if (j < n && b[i] == a[j]) j++;
    }
    if (j != n) {
      cout << "NO" << '\n';
      continue;
    }
    for (int i = 0; i < 26; i++) {
      x[i] = 0;
      y[i] = 0;
      z[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      int c = int(a[i] - 'a');
      x[c]++;
    }
    for (int i = 0; i < m; i++) {
      int c = int(b[i] - 'a');
      y[c]++;
    }
    for (int i = 0; i < p.size(); i++) {
      int c = int(p[i] - 'a');
      z[c]++;
    }
    bool f = 1;
    for (int i = 0; i < 26; i++) {
      if (x[i] + z[i] < y[i]) {
        f = 0;
        break;
      }
    }
    if (f)
      cout << "YES" << '\n';
    else
      cout << "NO" << '\n';
  }
}

```


### Prompt

Please formulate a CPP solution to the following problem:

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

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

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

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

Input

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

Output

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

Examples

Input

aaba
abaa

Output

YES

Input

aabb
abab

Output

NO

Note

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double Pi = 2.0 * acos(0.0);
const double Ex = 2.7182818284;
const int Mod = 1e9 + 7;
const int oo = 2e9 + 1e8;
int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dj[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dik[] = {-1, -1, 1, 1, -2, -2, 2, 2};
int djk[] = {2, -2, 2, -2, 1, -1, 1, -1};
long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }
long long getInt() {
  long long ret;
  char tmpc;
  bool sign = 0;
  while (tmpc = getchar()) {
    if (tmpc < '0' || tmpc > '9')
      sign = (tmpc == '-');
    else
      break;
  }
  ret = tmpc - '0';
  while (tmpc = getchar(), tmpc >= '0' && tmpc <= '9')
    ret = ret * 10 + tmpc - '0';
  if (sign) ret *= -1;
  return ret;
}
string x, y;
int n;
string solvex(int l, int r) {
  if ((r - l) & 1) return x.substr(l, r - l);
  string a, b;
  a = solvex(l, (l + r) >> 1);
  b = solvex((l + r) >> 1, r);
  if (a > b) swap(a, b);
  return a + b;
}
string solvey(int l, int r) {
  if ((r - l) & 1) return y.substr(l, r - l);
  string a, b;
  a = solvey(l, (l + r) >> 1);
  b = solvey((l + r) >> 1, r);
  if (a > b) swap(a, b);
  return a + b;
}
int main() {
  cin >> x >> y;
  n = (int)x.size();
  if (n & 1) {
    if (x == y)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
    return 0;
  }
  if (solvex(0, n) == solvey(0, n))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

```


### Prompt

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

The legend of the foundation of Vectorland talks of two integers x and y. Centuries ago, the array king placed two markers at points |x| and |y| on the number line and conquered all the land in between (including the endpoints), which he declared to be Arrayland. Many years later, the vector king placed markers at points |x - y| and |x + y| and conquered all the land in between (including the endpoints), which he declared to be Vectorland. He did so in such a way that the land of Arrayland was completely inside (including the endpoints) the land of Vectorland.

Here |z| denotes the absolute value of z.

Now, Jose is stuck on a question of his history exam: "What are the values of x and y?" Jose doesn't know the answer, but he believes he has narrowed the possible answers down to n integers a_1, a_2, ..., a_n. Now, he wants to know the number of unordered pairs formed by two different elements from these n integers such that the legend could be true if x and y were equal to these two values. Note that it is possible that Jose is wrong, and that no pairs could possibly make the legend true.

Input

The first line contains a single integer n (2 ≤ n ≤ 2 ⋅ 10^5) — the number of choices.

The second line contains n pairwise distinct integers a_1, a_2, ..., a_n (-10^9 ≤ a_i ≤ 10^9) — the choices Jose is considering.

Output

Print a single integer number — the number of unordered pairs \\{x, y\} formed by different numbers from Jose's choices that could make the legend true.

Examples

Input

3
2 5 -3

Output

2

Input

2
3 6

Output

1

Note

Consider the first sample. For the pair \{2, 5\}, the situation looks as follows, with the Arrayland markers at |2| = 2 and |5| = 5, while the Vectorland markers are located at |2 - 5| = 3 and |2 + 5| = 7:

<image>

The legend is not true in this case, because the interval [2, 3] is not conquered by Vectorland. For the pair \{5, -3\} the situation looks as follows, with Arrayland consisting of the interval [3, 5] and Vectorland consisting of the interval [2, 8]:

<image>

As Vectorland completely contains Arrayland, the legend is true. It can also be shown that the legend is true for the pair \{2, -3\}, for a total of two pairs.

In the second sample, the only pair is \{3, 6\}, and the situation looks as follows:

<image>

Note that even though Arrayland and Vectorland share 3 as endpoint, we still consider Arrayland to be completely inside of Vectorland.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long a[200005];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", a + i);
    a[i] = abs(a[i]);
  }
  sort(a, a + n);
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    int pos = upper_bound(a + i + 1, a + n, 2 * a[i]) - a - 1;
    ans += (pos - i);
  }
  printf("%lld\n", ans);
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Innocentius has a problem — his computer monitor has broken. Now some of the pixels are "dead", that is, they are always black. As consequence, Innocentius can't play the usual computer games. He is recently playing the following game with his younger brother Polycarpus.

Innocentius is touch-typing a program that paints a white square one-pixel wide frame on the black screen. As the monitor is broken, some pixels that should be white remain black. Polycarpus should look at what the program displayed on the screen and guess the position and size of the frame Innocentius has painted. Polycarpus doesn't like the game but Innocentius persuaded brother to play as "the game is good for the imagination and attention".

Help Polycarpus, automatize his part in the gaming process. Write the code that finds such possible square frame that:

  * the frame's width is 1 pixel,
  * the frame doesn't go beyond the borders of the screen,
  * all white pixels of the monitor are located on the frame,
  * of all frames that satisfy the previous three conditions, the required frame must have the smallest size.

Formally, a square frame is represented by such pixels of the solid square, that are on the square's border, that is, are not fully surrounded by the other pixels of the square. For example, if the frame's size is d = 3, then it consists of 8 pixels, if its size is d = 2, then it contains 4 pixels and if d = 1, then the frame is reduced to a single pixel.

Input

The first line contains the resolution of the monitor as a pair of integers n, m (1 ≤ n, m ≤ 2000). The next n lines contain exactly m characters each — the state of the monitor pixels at the moment of the game. Character "." (period, ASCII code 46) corresponds to the black pixel, and character "w" (lowercase English letter w) corresponds to the white pixel. It is guaranteed that at least one pixel of the monitor is white.

Output

Print the monitor screen. Represent the sought frame by characters "+" (the "plus" character). The pixels that has become white during the game mustn't be changed. Print them as "w". If there are multiple possible ways to position the frame of the minimum size, print any of them.

If the required frame doesn't exist, then print a single line containing number -1.

Examples

Input

4 8
..w..w..
........
........
..w..w..

Output

..w++w..
..+..+..
..+..+..
..w++w..

Input

5 6
......
.w....
......
..w...
......

Output

......
+w+...
+.+...
++w...
......

Input

2 4
....
.w..

Output

....
.w..

Input

2 6
w..w.w
...w..

Output

-1

Note

In the first sample the required size of the optimal frame equals 4. In the second sample the size of the optimal frame equals 3. In the third sample, the size of the optimal frame is 1. In the fourth sample, the required frame doesn't exist.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
char grid[2005][2005];
int cnt, sv[2005][2005];
set<int> row;
set<int> col;
int get(int i, int j, int x, int y) {
  return sv[x][y] - sv[x][j - 1] - sv[i - 1][y] + sv[i - 1][j - 1];
}
bool chk(int x, int y, int limit) {
  if (x + limit > n || y + limit > m) return 0;
  if (limit == 0) return cnt == 1 && grid[x][y] == 'w';
  int bl_x = x + limit;
  int bl_y = y + limit;
  int t = get(x, y + 1, x, bl_y);
  int b = get(bl_x, y, bl_x, bl_y - 1);
  int l = get(x, y, bl_x - 1, y);
  int r = get(x + 1, bl_y, bl_x, bl_y);
  return t + b + l + r == cnt;
}
int x, y;
int tst_row() {
  int lft = *row.begin();
  int rt = *(--row.end());
  int ans = rt - lft;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (chk(i, j, ans)) {
        x = i, y = j;
        return ans;
      }
  return INT_MAX;
}
int tst_col() {
  int lft = *col.begin();
  int rt = *(--col.end());
  int ans = rt - lft;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (chk(i, j, ans)) {
        x = i, y = j;
        return ans;
      }
  return INT_MAX;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf(" %c", &grid[i][j]);
      if (grid[i][j] == 'w') sv[i][j] = 1, cnt++;
      sv[i][j] += sv[i - 1][j] + sv[i][j - 1] - sv[i - 1][j - 1];
      if (grid[i][j] == 'w') row.insert(i), col.insert(j);
    }
  }
  int ans = INT_MAX;
  ans = min(ans, tst_row());
  ans = min(ans, tst_col());
  if (ans == INT_MAX) return puts("-1");
  for (int i = y; i <= y + ans; i++)
    if (grid[x][i] != 'w') grid[x][i] = '+';
  for (int i = y; i <= y + ans; i++)
    if (grid[x + ans][i] != 'w') grid[x + ans][i] = '+';
  for (int i = x; i <= x + ans; i++)
    if (grid[i][y] != 'w') grid[i][y] = '+';
  for (int i = x; i <= x + ans; i++)
    if (grid[i][y + ans] != 'w') grid[i][y + ans] = '+';
  for (int i = 1; i <= n; i++, puts(""))
    for (int j = 1; j <= m; j++) putchar(grid[i][j]);
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

We ask you to select some number of positive integers, and calculate the sum of them.

It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.

Your objective is to make the sum congruent to C modulo B. Determine whether this is possible.

If the objective is achievable, print `YES`. Otherwise, print `NO`.

Constraints

* 1 ≤ A ≤ 100
* 1 ≤ B ≤ 100
* 0 ≤ C < B

Input

Input is given from Standard Input in the following format:

A B C

Output

Print `YES` or `NO`.

Examples

Input

7 5 1

Output

YES

Input

2 2 1

Output

NO

Input

1 100 97

Output

YES

Input

40 98 58

Output

YES

Input

77 42 36

Output

NO

### Response

```cpp
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  bool ans=false;
  for(int i=1;i<=b;i++){
    if(a*i%b==c) ans=true;
  }
  cout<<(ans?"YES":"NO");

}

```


### Prompt

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

Alice and Bob are playing a game. They have a tree consisting of n vertices. Initially, Bob has k chips, the i-th chip is located in the vertex a_i (all these vertices are unique). Before the game starts, Alice will place a chip into one of the vertices of the tree.

The game consists of turns. Each turn, the following events happen (sequentially, exactly in the following order):

  1. Alice either moves her chip to an adjacent vertex or doesn't move it;
  2. for each Bob's chip, he either moves it to an adjacent vertex or doesn't move it. Note that this choice is done independently for each chip.

The game ends when Alice's chip shares the same vertex with one (or multiple) of Bob's chips. Note that Bob's chips may share the same vertex, even though they are in different vertices at the beginning of the game.

Alice wants to maximize the number of turns, Bob wants to minimize it. If the game ends in the middle of some turn (Alice moves her chip to a vertex that contains one or multiple Bob's chips), this turn is counted.

For each vertex, calculate the number of turns the game will last if Alice places her chip in that vertex.

Input

The first line contains one integer n (2 ≤ n ≤ 2 ⋅ 10^5) — the number of vertices in the tree.

Then n - 1 lines follow, each line contains two integers u_i, v_i (1 ≤ u_i, v_i ≤ n; u_i ≠ v_i) that denote the endpoints of an edge. These edges form a tree.

The next line contains one integer k (1 ≤ k ≤ n - 1) — the number of Bob's chips.

The last line contains k integers a_1, a_2, ..., a_k (1 ≤ a_i ≤ n; a_i ≠ a_j if i ≠ j) — the vertices where the Bob's chips are initially placed.

Output

Print n integers. The i-th of them should be equal to the number of turns the game will last if Alice initially places her chip in the vertex i. If one of Bob's chips is already placed in vertex i, then the answer for vertex i is 0.

Examples

Input

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

Output

2 1 2 0 0

Input

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

Output

3 0 0 3 1 2 3 0

Input

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

Output

0 2 2 2 2 0 2 2 0 0

### Response

```cpp
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
#define MAXN 200006
//#define int long long
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all(x) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
typedef long long ll;
int n , m;
int A[MAXN];

vi G[MAXN];

int d[MAXN] , idx[MAXN] , pr[MAXN] , as[MAXN];

void dfs( int u , int f , int rem , int ds ) {
	if( rem <= pr[u] ) return;
	pr[u] = max( pr[u] , rem );
	as[u] = max( as[u] , ds );
	if( rem == 0 ) return;
	for( int v : G[u] ) if( v != f ) {
		dfs( v , u , rem - 1 , ds );
	}
}

void solve() {
	cin >> n;
	rep( i , 2 , n ) {
		int u , v;
		scanf("%d%d",&u,&v);
		G[u].pb( v ) , G[v].pb( u );
	}
	cin >> m;
	queue<int> Q;
	memset( d , -1 , sizeof d );
	rep( i , 1 , m ) {
		int s;
		scanf("%d",&s);
		Q.push( s );
		d[s] = 0;
	}
	while( !Q.empty() ) {
		int u = Q.front(); Q.pop();
		for( int v : G[u] ) if( d[v] == -1 ) {
			d[v] = d[u] + 1; Q.push( v );
		}
	}
	memset( pr , -1 , sizeof pr );
	rep( i , 1 , n ) idx[i] = i;
	sort( idx + 1 , idx + 1 + n , []( int a , int b ) { return d[a] > d[b]; } );
	rep( i , 1 , n ) if( d[idx[i]] ) {
		int u = idx[i];
		dfs( u , u , d[u] - 1 , d[u] );
	}
	rep( i , 1 , n ) printf("%d ",as[i]);
}

signed main() {
//    int T;cin >> T;while( T-- ) solve();
    solve();
}

```


### Prompt

Develop a solution in cpp to the problem described below:

There are n positive integers written on the blackboard. Also, a positive number k ≥ 2 is chosen, and none of the numbers on the blackboard are divisible by k. In one operation, you can choose any two integers x and y, erase them and write one extra number f(x + y), where f(x) is equal to x if x is not divisible by k, otherwise f(x) = f(x / k).

In the end, there will be a single number of the blackboard. Is it possible to make the final number equal to 1? If so, restore any sequence of operations to do so.

Input

The first line contains two integers n and k — the initial number of integers on the blackboard, and the chosen number (2 ≤ n ≤ 16, 2 ≤ k ≤ 2000).

The second line contains n positive integers a_1, …, a_n initially written on the blackboard. It is guaranteed that none of the numbers a_i is divisible by k, and the sum of all a_i does not exceed 2000.

Output

If it is impossible to obtain 1 as the final number, print "NO" in the only line.

Otherwise, print "YES" on the first line, followed by n - 1 lines describing operations. The i-th of these lines has to contain two integers x_i and y_i to be erased and replaced with f(x_i + y_i) on the i-th operation. If there are several suitable ways, output any of them.

Examples

Input

2 2
1 1

Output

YES
1 1

Input

4 3
7 8 13 23

Output

YES
23 13
8 7
5 4

Input

3 4
1 2 3

Output

NO

Note

In the second sample case:

  * f(8 + 7) = f(15) = f(5) = 5;
  * f(23 + 13) = f(36) = f(12) = f(4) = 4;
  * f(5 + 4) = f(9) = f(3) = f(1) = 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[16];
bitset<2001> dp[1 << 16];
int ans[16];
int findAns(int m, int num, int n, int k) {
  if (m == 0)
    return 0;
  else if (((num * k) <= 2000) && dp[m][num * k]) {
    int i;
    for (i = 0; i < n; i++) {
      if (m & (1 << i)) ans[i]++;
    }
    findAns(m, num * k, n, k);
    return 0;
  }
  int i;
  for (i = 0; i < n; i++) {
    if ((m & (1 << i)) && (num >= a[i]) && dp[m ^ (1 << i)][num - a[i]]) {
      findAns(m ^ (1 << i), num - a[i], n, k);
      return 0;
    }
  }
  return 0;
}
priority_queue<pair<int, int> > H;
int main() {
  int i;
  int n, k;
  scanf("%d %d", &n, &k);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  int j;
  dp[0][0] = 1;
  for (i = 1; i < (1 << n); i++) {
    for (j = 0; j < n; j++) {
      if (i & (1 << j)) dp[i] |= dp[i ^ (1 << j)] << a[j];
    }
    for (j = 2000 / k; j >= 0; j--) {
      if (dp[i][j * k]) dp[i][j] = 1;
    }
  }
  if (dp[(1 << n) - 1][1]) {
    printf("YES\n");
    findAns((1 << n) - 1, 1, n, k);
    for (i = 0; i < n; i++) H.push(make_pair(ans[i], a[i]));
    for (i = 0; i < n - 1; i++) {
      pair<int, int> a = H.top();
      H.pop();
      pair<int, int> b = H.top();
      H.pop();
      printf("%d %d\n", a.second, b.second);
      int s = a.second + b.second;
      while ((s % k) == 0) s /= k, a.first--;
      H.push(make_pair(a.first, s));
    }
  } else
    printf("NO\n");
  return 0;
}

```


### Prompt

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

At a break Vanya came to the class and saw an array of n k-bit integers a_1, a_2, …, a_n on the board. An integer x is called a k-bit integer if 0 ≤ x ≤ 2^k - 1.

Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anything, Vanya allowed himself to make only one type of changes: choose an index of the array i (1 ≤ i ≤ n) and replace the number a_i with the number \overline{a_i}. We define \overline{x} for a k-bit integer x as the k-bit integer such that all its k bits differ from the corresponding bits of x.

Vanya does not like the number 0. Therefore, he likes such segments [l, r] (1 ≤ l ≤ r ≤ n) such that a_l ⊕ a_{l+1} ⊕ … ⊕ a_r ≠ 0, where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Determine the maximum number of segments he likes Vanya can get applying zero or more operations described above.

Input

The first line of the input contains two integers n and k (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 30).

The next line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 2^k - 1), separated by spaces — the array of k-bit integers.

Output

Print one integer — the maximum possible number of segments with XOR not equal to 0 that can be obtained by making several (possibly 0) operations described in the statement.

Examples

Input

3 2
1 3 0

Output

5

Input

6 3
1 4 4 7 3 4

Output

19

Note

In the first example if Vasya does not perform any operations, he gets an array that has 5 segments that Vanya likes. If he performs the operation with i = 2, he gets an array [1, 0, 0], because \overline{3} = 0 when k = 2. This array has 3 segments that Vanya likes. Also, to get an array with 5 segments that Vanya likes, he can perform two operations with i = 3 and with i = 2. He then gets an array [1, 0, 3]. It can be proven that he can't obtain 6 or more segments that he likes.

In the second example, to get 19 segments that Vanya likes, he can perform 4 operations with i = 3, i = 4, i = 5, i = 6 and get an array [1, 4, 3, 0, 4, 3].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = (int)2e5 + 5;
int A[MAX_N];
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    A[i] ^= A[i - 1];
  }
  int X = (1 << K) - 1;
  map<int, int> mp;
  for (int i = 0; i <= N; i++) {
    mp[min(A[i], X - A[i])]++;
  }
  long long ans = 1LL * N * (N + 1) / 2;
  for (auto p : mp) {
    long long v = p.second / 2;
    ans -= v * (v - 1) / 2 + (p.second - v) * (p.second - v - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer is too old for the new game and needs to be updated.

There are n video cards in the shop, the power of the i-th video card is equal to integer value ai. As Vlad wants to be sure the new game will work he wants to buy not one, but several video cards and unite their powers using the cutting-edge technology. To use this technology one of the cards is chosen as the leading one and other video cards are attached to it as secondary. For this new technology to work it's required that the power of each of the secondary video cards is divisible by the power of the leading video card. In order to achieve that the power of any secondary video card can be reduced to any integer value less or equal than the current power. However, the power of the leading video card should remain unchanged, i.e. it can't be reduced.

Vlad has an infinite amount of money so he can buy any set of video cards. Help him determine which video cards he should buy such that after picking the leading video card and may be reducing some powers of others to make them work together he will get the maximum total value of video power.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of video cards in the shop.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 200 000) — powers of video cards.

Output

The only line of the output should contain one integer value — the maximum possible total power of video cards working together.

Examples

Input

4
3 2 15 9

Output

27

Input

4
8 2 2 7

Output

18

Note

In the first sample, it would be optimal to buy video cards with powers 3, 15 and 9. The video card with power 3 should be chosen as the leading one and all other video cards will be compatible with it. Thus, the total power would be 3 + 15 + 9 = 27. If he buys all the video cards and pick the one with the power 2 as the leading, the powers of all other video cards should be reduced by 1, thus the total power would be 2 + 2 + 14 + 8 = 26, that is less than 27. Please note, that it's not allowed to reduce the power of the leading video card, i.e. one can't get the total power 3 + 1 + 15 + 9 = 28.

In the second sample, the optimal answer is to buy all video cards and pick the one with the power 2 as the leading. The video card with the power 7 needs it power to be reduced down to 6. The total power would be 8 + 2 + 2 + 6 = 18.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
long long POW(long long a, long long b, long long MMM = MOD) {
  long long ret = 1;
  for (; b; b >>= 1, a = (a * a) % MMM)
    if (b & 1) ret = (ret * a) % MMM;
  return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
  if (a == 0 || b == 0) return a + b;
  return a * (b / gcd(a, b));
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int ddx[] = {0, 0, 1, 1, 1, -1, -1, -1}, ddy[] = {1, -1, 1, 0, -1, 1, 0, -1};
int cnt[200001], sum[400001];
int main() {
  int n;
  scanf("%d", &n);
  for (int(i) = (1); (i) <= (n); (i) += (1)) {
    int x;
    scanf("%d", &x);
    cnt[x]++;
  }
  for (int(i) = (1); (i) <= (200000); (i) += (1)) sum[i] = sum[i - 1] + cnt[i];
  for (int(i) = (200001); (i) <= (400000); (i) += (1)) sum[i] = sum[200000];
  long long ans = 0;
  for (int(i) = (1); (i) <= (200000); (i) += (1)) {
    if (!cnt[i]) continue;
    long long t = 0;
    for (int(j) = (i); (j) <= (200000); (j) += (i)) {
      t += 1LL * j * (sum[j + i - 1] - sum[j - 1]);
    }
    ans = max(ans, t);
  }
  printf("%lld", ans);
}

```


### Prompt

Please create a solution in CPP to the following problem:

Ruritania is a country with a very badly maintained road network, which is not exactly good news for lorry drivers that constantly have to do deliveries. In fact, when roads are maintained, they become one-way. It turns out that it is sometimes impossible to get from one town to another in a legal way – however, we know that all towns are reachable, though illegally!

Fortunately for us, the police tend to be very corrupt and they will allow a lorry driver to break the rules and drive in the wrong direction provided they receive ‘a small gift’. There is one patrol car for every road and they will request 1000 Ruritanian dinars when a driver drives in the wrong direction. However, being greedy, every time a patrol car notices the same driver breaking the rule, they will charge double the amount of money they requested the previous time on that particular road.

Borna is a lorry driver that managed to figure out this bribing pattern. As part of his job, he has to make K stops in some towns all over Ruritania and he has to make these stops in a certain order. There are N towns (enumerated from 1 to N) in Ruritania and Borna’s initial location is the capital city i.e. town 1. He happens to know which ones out of the N - 1 roads in Ruritania are currently unidirectional, but he is unable to compute the least amount of money he needs to prepare for bribing the police. Help Borna by providing him with an answer and you will be richly rewarded.

Input

The first line contains N, the number of towns in Ruritania. The following N - 1 lines contain information regarding individual roads between towns. A road is represented by a tuple of integers (a,b,x), which are separated with a single whitespace character. The numbers a and b represent the cities connected by this particular road, and x is either 0 or 1: 0 means that the road is bidirectional, 1 means that only the a → b direction is legal. The next line contains K, the number of stops Borna has to make. The final line of input contains K positive integers s1, …, sK: the towns Borna has to visit.

  * 1 ≤ N ≤ 105
  * 1 ≤ K ≤ 106
  * 1 ≤ a, b ≤ N for all roads
  * <image> for all roads
  * 1 ≤ si ≤ N for all 1 ≤ i ≤ K

Output

The output should contain a single number: the least amount of thousands of Ruritanian dinars Borna should allocate for bribes, modulo 109 + 7.

Examples

Input

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

Output

4

Note

Borna first takes the route 1 → 5 and has to pay 1000 dinars. After that, he takes the route 5 → 1 → 2 → 3 → 4 and pays nothing this time. However, when he has to return via 4 → 3 → 2 → 1 → 5, he needs to prepare 3000 (1000+2000) dinars. Afterwards, getting to 2 via 5 → 1 → 2 will cost him nothing. Finally, he doesn't even have to leave town 2 to get to 2, so there is no need to prepare any additional bribe money. Hence he has to prepare 4000 dinars in total.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class C>
void mini(C& a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C& a4, C b4) {
  a4 = max(a4, b4);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> pair) {
  return out << "(" << pair.first << ", " << pair.second << ")";
}
template <class A, class B, class C>
struct Triple {
  A first;
  B second;
  C third;
  bool operator<(const Triple& t) const {
    if (first != t.first) return first < t.first;
    if (second != t.second) return second < t.second;
    return third < t.third;
  }
};
template <class T>
void ResizeVec(T&, vector<long long>) {}
template <class T>
void ResizeVec(vector<T>& vec, vector<long long> sz) {
  vec.resize(sz[0]);
  sz.erase(sz.begin());
  if (sz.empty()) {
    return;
  }
  for (T& v : vec) {
    ResizeVec(v, sz);
  }
}
template <class A, class B, class C>
ostream& operator<<(ostream& out, Triple<A, B, C> t) {
  return out << "(" << t.first << ", " << t.second << ", " << t.third << ")";
}
const long long N = 1e6 + 5;
long long pots[N + 5];
const long long P = 1e9 + 7;
vector<Triple<long long, long long, long long> > slo[N];
long long sz[N];
long long dfsSz(long long v) {
  sz[v] = 1;
  for (auto e : slo[v]) {
    long long nei = e.first;
    if (sz[nei]) {
      continue;
    }
    sz[v] += dfsSz(nei);
  }
  return sz[v];
}
long long n, k;
long long begs[N], endss[N];
long long res;
vector<long long> occ[N];
bool cur[N][22];
vector<long long> coll[22];
void Add(long long x, long long v, long long log) {
  if (cur[x + 1][log]) {
    begs[v]--;
  } else {
    if (x + 1 <= k) {
      endss[v]++;
    }
  }
  if (cur[x - 1][log]) {
    endss[v]--;
  } else {
    if (x > 1) {
      begs[v]++;
    }
  }
  coll[log].push_back(x);
  cur[x][log] = 1;
}
void DfsDp(long long v, long long par, long long log) {
  if (0) cout << "From " << par << " to " << v << endl;
  long long larg_sz = -1;
  long long wh = -1;
  for (auto e : slo[v]) {
    long long nei = e.first;
    if (nei == par) {
      continue;
    }
    if (sz[nei] > larg_sz) {
      wh = nei;
      larg_sz = sz[nei];
    }
  }
  if (wh != -1) {
    DfsDp(wh, v, log);
    begs[v] = begs[wh];
    endss[v] = endss[wh];
  }
  for (auto x : occ[v]) {
    Add(x, v, log);
  }
  for (auto e : slo[v]) {
    long long nei = e.first;
    if (nei == par || nei == wh) {
      continue;
    }
    DfsDp(nei, v, log + 1);
    for (auto x : coll[log + 1]) {
      Add(x, v, log);
      cur[x][log + 1] = 0;
    }
    coll[log + 1].clear();
  }
  for (auto e : slo[v]) {
    long long nei = e.first;
    if (nei == par || e.second == 0) {
      continue;
    }
    if (e.third == 0) {
      res += pots[begs[nei]];
      if (0) cout << "Add 2^" << begs[nei] << " " << v << " " << nei << endl;
    } else {
      res += pots[endss[nei]];
      if (0) cout << "Add 2^" << endss[nei] << " " << v << " " << nei << endl;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  if (0) cout << fixed << setprecision(10);
  cin.tie(0);
  double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  pots[0] = 1;
  for (long long i = (1); i <= (N); ++i) {
    pots[i] = 2 * pots[i - 1] % P;
  }
  cin >> n;
  res = P;
  for (long long i = (1); i <= (n - 1); ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    ;
    slo[a].push_back({b, c, 1});
    slo[b].push_back({a, c, c ^ 1});
    if (0) cout << a << "<->" << b << endl;
    res -= c;
  }
  cin >> k;
  occ[1].push_back(1);
  for (long long i = (1); i <= (k); ++i) {
    long long c;
    cin >> c;
    ;
    occ[c].push_back(i + 1);
  }
  k++;
  dfsSz(1);
  DfsDp(1, -1, 0);
  cout << res % P << endl;
  return 0;
}

```


### Prompt

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

We often have to copy large volumes of information. Such operation can take up many computer resources. Therefore, in this problem you are advised to come up with a way to copy some part of a number array into another one, quickly.

More formally, you've got two arrays of integers a1, a2, ..., an and b1, b2, ..., bn of length n. Also, you've got m queries of two types:

  1. Copy the subsegment of array a of length k, starting from position x, into array b, starting from position y, that is, execute by + q = ax + q for all integer q (0 ≤ q < k). The given operation is correct — both subsegments do not touch unexistent elements.
  2. Determine the value in position x of array b, that is, find value bx.

For each query of the second type print the result — the value of the corresponding element of array b.

Input

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of elements in the arrays and the number of queries, correspondingly. The second line contains an array of integers a1, a2, ..., an (|ai| ≤ 109). The third line contains an array of integers b1, b2, ..., bn (|bi| ≤ 109).

Next m lines contain the descriptions of the queries. The i-th line first contains integer ti — the type of the i-th query (1 ≤ ti ≤ 2). If ti = 1, then the i-th query means the copying operation. If ti = 2, then the i-th query means taking the value in array b. If ti = 1, then the query type is followed by three integers xi, yi, ki (1 ≤ xi, yi, ki ≤ n) — the parameters of the copying query. If ti = 2, then the query type is followed by integer xi (1 ≤ xi ≤ n) — the position in array b.

All numbers in the lines are separated with single spaces. It is guaranteed that all the queries are correct, that is, the copying borders fit into the borders of arrays a and b.

Output

For each second type query print the result on a single line.

Examples

Input

5 10
1 2 0 -1 3
3 1 5 -2 0
2 5
1 3 3 3
2 5
2 4
2 1
1 2 1 4
2 1
2 4
1 4 2 1
2 2

Output

0
3
-1
3
2
3
-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int N = 1, n, m, i, j, x, y, k, type, L, R;
int a[400005], b[400005];
int diff[400005];
int tree[800005];
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) cin >> b[i];
  while (N <= n) N <<= 1;
  for (i = 1; i <= m; i++) {
    cin >> type;
    if (!(type - 1)) {
      cin >> x >> y >> k;
      diff[i] = x - y;
      for (L = N + y, R = N + y + k - 1; L <= R;
           L = (L + 1) >> 1, R = (R - 1) >> 1)
        tree[L] = tree[R] = i;
    } else {
      cin >> x;
      int t(0);
      for (j = N + x; j; j >>= 1) {
        if (t < tree[j]) t = tree[j];
      }
      if (!t)
        cout << b[x] << "\n";
      else
        cout << a[x + diff[t]] << "\n";
    }
  }
}

```


### Prompt

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

Tonight, in your favourite cinema they are giving the movie Joker and all seats are occupied. In the cinema there are N rows with N seats each, forming an N\times N square. We denote with 1, 2,\dots, N the viewers in the first row (from left to right); with N+1, \dots, 2N the viewers in the second row (from left to right); and so on until the last row, whose viewers are denoted by N^2-N+1,\dots, N^2.

At the end of the movie, the viewers go out of the cinema in a certain order: the i-th viewer leaving her seat is the one denoted by the number P_i. The viewer P_{i+1} waits until viewer P_i has left the cinema before leaving her seat. To exit from the cinema, a viewer must move from seat to seat until she exits the square of seats (any side of the square is a valid exit). A viewer can move from a seat to one of its 4 adjacent seats (same row or same column). While leaving the cinema, it might be that a certain viewer x goes through a seat currently occupied by viewer y; in that case viewer y will hate viewer x forever. Each viewer chooses the way that minimizes the number of viewers that will hate her forever.

Compute the number of pairs of viewers (x, y) such that y will hate x forever.

Constraints

* 2 \le N \le 500
* The sequence P_1, P_2, \dots, P_{N^2} is a permutation of \\{1, 2, \dots, N^2\\}.

Input

The input is given from Standard Input in the format

N
P_1 P_2 \cdots P_{N^2}

Output

If ans is the number of pairs of viewers described in the statement, you should print on Standard Output

ans

Output

If ans is the number of pairs of viewers described in the statement, you should print on Standard Output

ans

Examples

Input

3
1 3 7 9 5 4 8 6 2

Output

1

Input

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

Output

3

Input

6
11 21 35 22 7 36 27 34 8 20 15 13 16 1 24 3 2 17 26 9 18 32 31 23 19 14 4 25 10 29 28 33 12 6 5 30

Output

11

### Response

```cpp
#include <iostream>

using namespace std;

int n;
int r[555][555];
int z[555][555];
int p[555*555];

void dfs(int y, int x, int c, int f) {
	if (y < 1 || x < 1 || y > n || x > n) return;
	if (f && r[y][x] <= c) return;
	r[y][x] = c;
	dfs(y-1,x,r[y][x]+z[y][x],1);
	dfs(y+1,x,r[y][x]+z[y][x],1);
	dfs(y,x-1,r[y][x]+z[y][x],1);
	dfs(y,x+1,r[y][x]+z[y][x],1);
}

int main() {
	cin >> n;
	for (int i = 1; i <= n*n; i++) cin >> p[i];
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			int m1 = min(i-1,n-i);
			int m2 = min(j-1,n-j);
			r[i][j] = min(m1,m2);
			z[i][j] = 1;
		}
	}
	int t = 0;
	for (int i = 1; i <= n*n; i++) {
		int y = (p[i]-1)/n+1;
		int x = (p[i]-1)%n+1;
		t += r[y][x];
		z[y][x] = 0;
		dfs(y,x,r[y][x],0);
	}
	cout << t << "\n";
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Artem is building a new robot. He has a matrix a consisting of n rows and m columns. The cell located on the i-th row from the top and the j-th column from the left has a value a_{i,j} written in it.

If two adjacent cells contain the same value, the robot will break. A matrix is called good if no two adjacent cells contain the same value, where two cells are called adjacent if they share a side.

Artem wants to increment the values in some cells by one to make a good.

More formally, find a good matrix b that satisfies the following condition —

  * For all valid (i,j), either b_{i,j} = a_{i,j} or b_{i,j} = a_{i,j}+1.

For the constraints of this problem, it can be shown that such a matrix b always exists. If there are several such tables, you can output any of them. Please note that you do not have to minimize the number of increments.

Input

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

The first line of each test case contains two integers n, m (1 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of rows and columns, respectively.

The following n lines each contain m integers. The j-th integer in the i-th line is a_{i,j} (1 ≤ a_{i,j} ≤ 10^9).

Output

For each case, output n lines each containing m integers. The j-th integer in the i-th line is b_{i,j}.

Example

Input

3
3 2
1 2
4 5
7 8
2 2
1 1
3 3
2 2
1 3
2 2

Output

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

Note

In all the cases, you can verify that no two adjacent cells have the same value and that b is the same as a with some values incremented by one.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y) {
  long long int res = 1;
  x = x % ((long long int)1 << (long long int)32);
  while (y > 0) {
    if (y & 1) res = (res * x) % ((long long int)1 << (long long int)32);
    y = y >> 1;
    x = (x * x) % ((long long int)1 << (long long int)32);
  }
  return res;
}
int main() {
  long long int t;
  scanf("%lld", &t);
  while (t--) {
    long long int i, j, k, n, m, a[101][101];
    scanf("%lld", &n);
    scanf("%lld", &m);
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) scanf("%lld", &a[i][j]);
    }
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (i % 2) {
          if (j % 2 && a[i][j] % 2) a[i][j]++;
          if (j % 2 == 0 && a[i][j] % 2 == 0) a[i][j]++;
        } else {
          if (j % 2 && a[i][j] % 2 == 0) a[i][j]++;
          if (j % 2 == 0 && a[i][j] % 2) a[i][j]++;
        }
      }
    }
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) cout << a[i][j] << " ";
      cout << endl;
    }
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Consider a sequence of n numbers using integers from 0 to 9 k1, k2, ..., kn. Read the positive integers n and s,

k1 + 2 x k2 + 3 x k3 + ... + n x kn = s

Create a program that outputs how many rows of n numbers such as. However, the same number does not appear more than once in one "n sequence of numbers".

Input

The input consists of multiple datasets. For each dataset, n (1 ≤ n ≤ 10) and s (0 ≤ s ≤ 10,000) are given on one line, separated by blanks.

The number of datasets does not exceed 100.

Output

For each dataset, print the number of combinations in which the sum of n integers is s on one line.

Example

Input

3 10
3 1

Output

8
0

### Response

```cpp
#include <bits/stdc++.h>
#define range(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
int n, s;
vector<int> used(10);
int memo[11][1000];
int sum;
void dfs(int d){
    memo[d][sum]++;
    if(d == 10) return;

    rep(i, 10){
        if(used[i]) continue;

        used[i] = true;
        sum += (d + 1) * i;

        dfs(d + 1);

        used[i] = false;
        sum -= (d + 1) * i;
    }
}

int main(void){
    dfs(0);
    while(cin >> n >> s){
        if(s >= 1000) cout << 0 << endl;
        else         cout << memo[n][s] << endl;
    }

	return 0;
}
```


### Prompt

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

Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`.

When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases.

Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds.

Now, he goes through the following process:

* Submit the code.
* Wait until the code finishes execution on all the cases.
* If the code fails to correctly solve some of the M cases, submit it again.
* Repeat until the code correctly solve all the cases in one submission.

Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).

Constraints

* All input values are integers.
* 1 \leq N \leq 100
* 1 \leq M \leq {\rm min}(N, 5)

Input

Input is given from Standard Input in the following format:

N M

Output

Print X, the expected value of the total execution time of the code, as an integer. It can be proved that, under the constraints in this problem, X is an integer not exceeding 10^9.

Examples

Input

1 1

Output

3800

Input

10 2

Output

18400

Input

100 5

Output

608000

### Response

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

int main()
{
  int N, M;
  cin >> N >> M;
  cout << (100 * (N - M) + 1900 * M) * pow(2, M) << endl;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above.

The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner?

Constraints

* -40 \leq X \leq 40
* X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print `Yes` if you will turn on the air conditioner; print `No` otherwise.

Examples

Input

25

Output

No

Input

30

Output

Yes

### Response

```cpp
#include<iostream>
using namespace std;
int main()
{
  int x;
  cin>>x;
  cout<<(x>=30?"Yes":"No");
  return 0;
}
```


### Prompt

Construct a cpp code solution to the problem outlined:

Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.

As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tournament (it was a weekend, after all). Now you are really curious about the results of the tournament. This time the tournament in Berland went as follows:

  * There are n knights participating in the tournament. Each knight was assigned his unique number — an integer from 1 to n.
  * The tournament consisted of m fights, in the i-th fight the knights that were still in the game with numbers at least li and at most ri have fought for the right to continue taking part in the tournament.
  * After the i-th fight among all participants of the fight only one knight won — the knight number xi, he continued participating in the tournament. Other knights left the tournament.
  * The winner of the last (the m-th) fight (the knight number xm) became the winner of the tournament.

You fished out all the information about the fights from your friends. Now for each knight you want to know the name of the knight he was conquered by. We think that the knight number b was conquered by the knight number a, if there was a fight with both of these knights present and the winner was the knight number a.

Write the code that calculates for each knight, the name of the knight that beat him.

Input

The first line contains two integers n, m (2 ≤ n ≤ 3·105; 1 ≤ m ≤ 3·105) — the number of knights and the number of fights. Each of the following m lines contains three integers li, ri, xi (1 ≤ li < ri ≤ n; li ≤ xi ≤ ri) — the description of the i-th fight.

It is guaranteed that the input is correct and matches the problem statement. It is guaranteed that at least two knights took part in each battle.

Output

Print n integers. If the i-th knight lost, then the i-th number should equal the number of the knight that beat the knight number i. If the i-th knight is the winner, then the i-th number must equal 0.

Examples

Input

4 3
1 2 1
1 3 3
1 4 4

Output

3 1 4 0

Input

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

Output

0 8 4 6 4 8 6 1

Note

Consider the first test case. Knights 1 and 2 fought the first fight and knight 1 won. Knights 1 and 3 fought the second fight and knight 3 won. The last fight was between knights 3 and 4, knight 4 won.

### Response

```cpp
#include <bits/stdc++.h>
#pragma optimize("O3")
int sol[300000];
int er[300000];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  int n, m, i, j;
  std::cin >> n >> m;
  int l, r, x;
  std::set<int> mp;
  for (i = 1; i <= n; ++i) {
    mp.insert(i);
  }
  std::set<int>::iterator it;
  for (i = 1; i <= m; ++i) {
    std::cin >> l >> r >> x;
    it = mp.lower_bound(l);
    er[0] = 0;
    int c;
    while (it != mp.end()) {
      c = *it;
      if (c > r) {
        break;
      }
      if (c >= l) {
        if (c != x) {
          sol[c] = x;
          er[++er[0]] = c;
        }
      }
      ++it;
    }
    for (j = 1; j <= er[0]; ++j) {
      mp.erase(er[j]);
    }
  }
  for (i = 1; i <= n; ++i) {
    std::cout << sol[i] << ' ';
  }
}

```


### Prompt

Develop a solution in CPP to the problem described below:

On a number axis directed from the left rightwards, n marbles with coordinates x1, x2, ..., xn are situated. Let's assume that the sizes of the marbles are infinitely small, that is in this task each of them is assumed to be a material point. You can stick pins in some of them and the cost of sticking in the marble number i is equal to ci, number ci may be negative. After you choose and stick the pins you need, the marbles will start to roll left according to the rule: if a marble has a pin stuck in it, then the marble doesn't move, otherwise the marble rolls all the way up to the next marble which has a pin stuck in it and stops moving there. If there is no pinned marble on the left to the given unpinned one, it is concluded that the marble rolls to the left to infinity and you will pay an infinitely large fine for it. If no marble rolled infinitely to the left, then the fine will consist of two summands:

  * the sum of the costs of stuck pins;
  * the sum of the lengths of the paths of each of the marbles, that is the sum of absolute values of differences between their initial and final positions.

Your task is to choose and pin some marbles in the way that will make the fine for you to pay as little as possible.

Input

The first input line contains an integer n (1 ≤ n ≤ 3000) which is the number of marbles. The next n lines contain the descriptions of the marbles in pairs of integers xi, ci ( - 109 ≤ xi, ci ≤ 109). The numbers are space-separated. Each description is given on a separate line. No two marbles have identical initial positions.

Output

Output the single number — the least fine you will have to pay.

Examples

Input

3
2 3
3 4
1 2

Output

5

Input

4
1 7
3 1
5 10
6 1

Output

11

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 3005;
struct Data {
  long long x, c;
  bool operator<(const Data &other) const { return x < other.x; }
} a[N];
long long dp[N][2], dist[N][N], pref[N][N];
signed main() {
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) scanf("%lld %lld", &a[i].x, &a[i].c);
  sort(a + 1, a + n + 1);
  for (long long i = 1; i <= n; i++) {
    for (long long j = i; j <= n; j++) {
      dist[i][j] = a[j].x - a[i].x;
      if (j == i)
        pref[i][j] = dist[i][j];
      else
        pref[i][j] = pref[i][j - 1] + dist[i][j];
    }
  }
  memset(dp, 0x3f, sizeof(dp));
  dp[1][1] = a[1].c;
  for (long long i = 2; i <= n; i++) {
    for (long long j = 0; j < 2; j++) {
      if (j == 1)
        dp[i][j] = min(dp[i][j], min(dp[i - 1][0], dp[i - 1][1]) + a[i].c);
      else {
        for (long long k = 1; k < i; k++) {
          if (dp[k][1] < 1e18) {
            dp[i][j] = min(dp[i][j], dp[k][1] + pref[k][i]);
          }
        }
      }
    }
  }
  printf("%lld", min(dp[n][0], dp[n][1]));
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

In Takahashi Kingdom, which once existed, there are N cities, and some pairs of cities are connected bidirectionally by roads. The following are known about the road network:

* People traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary.
* Different roads may have had different lengths, but all the lengths were positive integers.

Snuke the archeologist found a table with N rows and N columns, A, in the ruin of Takahashi Kingdom. He thought that it represented the shortest distances between the cities along the roads in the kingdom.

Determine whether there exists a road network such that for each u and v, the integer A_{u, v} at the u-th row and v-th column of A is equal to the length of the shortest path from City u to City v. If such a network exist, find the shortest possible total length of the roads.

Constraints

* 1 \leq N \leq 300
* If i ≠ j, 1 \leq A_{i, j} = A_{j, i} \leq 10^9.
* A_{i, i} = 0

Inputs

Input is given from Standard Input in the following format:

N
A_{1, 1} A_{1, 2} ... A_{1, N}
A_{2, 1} A_{2, 2} ... A_{2, N}
...
A_{N, 1} A_{N, 2} ... A_{N, N}

Outputs

If there exists no network that satisfies the condition, print `-1`. If it exists, print the shortest possible total length of the roads.

Examples

Input

3
0 1 3
1 0 2
3 2 0

Output

3

Input

3
0 1 3
1 0 1
3 1 0

Output

-1

Input

5
0 21 18 11 28
21 0 13 10 26
18 13 0 23 13
11 10 23 0 17
28 26 13 17 0

Output

82

Input

3
0 1000000000 1000000000
1000000000 0 1000000000
1000000000 1000000000 0

Output

3000000000

### Response

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

int main() {
	int N;
	cin >> N;
	long long ans = 0;
	vector<vector<int>> data(N, vector<int>(N));
	vector<vector<int>> bdata(N, vector<int>(N,false));
	for (int i = 0;i<N;++i) {
		for (int j = 0;j<N;++j) {
			cin >> data[i][j];
		}
	}
	for (int i = 0;i<N;++i) {
		for (int j = 0;j<N;++j) {
			for (int k = 0;k<N;++k) {
				if (i == j || i==k || j == k) {
					continue;
				}
				if (data[i][k] > data[i][j] + data[j][k]) {
					cout << -1 << endl;
					return 0;
				}
				if (data[i][k] == data[i][j] + data[j][k]) {
					bdata[i][k] = true;
				}
			}
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= i; j++) {
			if (bdata[i][j] == false) {
				ans += data[i][j];
			}

		}
	}
	cout << ans<<endl;
	return 0;
}
```


### Prompt

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

Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.

The game is played on a tree having n nodes, numbered from 1 to n. Each node i has an initial value initi, which is either 0 or 1. The root of the tree is node 1.

One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node x. Right after someone has picked node x, the value of node x flips, the values of sons of x remain the same, the values of sons of sons of x flips, the values of sons of sons of sons of x remain the same and so on.

The goal of the game is to get each node i to have value goali, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.

Input

The first line contains an integer n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n; ui ≠ vi) meaning there is an edge between nodes ui and vi.

The next line contains n integer numbers, the i-th of them corresponds to initi (initi is either 0 or 1). The following line also contains n integer numbers, the i-th number corresponds to goali (goali is either 0 or 1).

Output

In the first line output an integer number cnt, representing the minimal number of operations you perform. Each of the next cnt lines should contain an integer xi, representing that you pick a node xi.

Examples

Input

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

Output

2
4
7

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
struct Edge {
  int v, next;
} edge[N * 2];
int head[N], cnt, turn[N], a[N], vis[N], ans;
void addedge(int u, int v) {
  edge[cnt].v = v;
  edge[cnt].next = head[u];
  head[u] = cnt++;
}
void init() {
  memset(head, -1, sizeof(head));
  memset(vis, 0, sizeof(vis));
  cnt = 0;
  ans = 0;
}
void dfs(int u, int x1, int x2) {
  if (vis[u]) return;
  vis[u] = 1;
  a[u] = a[u] ^ x1;
  if (a[u]) {
    turn[ans++] = u;
    x1 ^= 1;
    a[u] = 0;
  }
  for (int i = head[u]; i + 1; i = edge[i].next) {
    int v = edge[i].v;
    dfs(v, x2, x1);
  }
  return;
}
int main() {
  int n;
  cin >> n;
  int t = n;
  int u, v;
  init();
  while (--t) {
    cin >> u >> v;
    addedge(u, v);
    addedge(v, u);
  }
  for (int i = 1; i <= n; i++) cin >> a[i];
  int x;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a[i] ^= x;
  }
  dfs(1, 0, 0);
  cout << ans << endl;
  for (int i = 0; i < ans; i++) cout << turn[i] << endl;
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once.

The appointed Judge was the most experienced member — Pavel. But since he was the wisest of all, he soon got bored of the game and fell asleep. Waking up, he discovered that the tournament is over and the teams want to know the results of all the matches.

Pavel didn't want anyone to discover about him sleeping and not keeping an eye on the results, so he decided to recover the results of all games. To do this, he asked all the teams and learned that the real winner was friendship, that is, each team beat the other teams exactly k times. Help Pavel come up with chronology of the tournir that meets all the conditions, or otherwise report that there is no such table.

Input

The first line contains two integers — n and k (1 ≤ n, k ≤ 1000).

Output

In the first line print an integer m — number of the played games. The following m lines should contain the information about all the matches, one match per line. The i-th line should contain two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi). The numbers ai and bi mean, that in the i-th match the team with number ai won against the team with number bi. You can assume, that the teams are numbered from 1 to n.

If a tournir that meets the conditions of the problem does not exist, then print -1.

Examples

Input

3 1

Output

3
1 2
2 3
3 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  if (k * 2 >= n)
    printf("-1\n");
  else {
    printf("%d\n", n * k);
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < k; ++j) printf("%d %d\n", i + 1, (i + j + 1) % n + 1);
  }
}

```


### Prompt

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

We have a secret array. You don't know this array and you have to restore it. However, you know some facts about this array:

  * The array consists of n distinct positive (greater than 0) integers.
  * The array contains two elements x and y (these elements are known for you) such that x < y.
  * If you sort the array in increasing order (such that a_1 < a_2 < … < a_n), differences between all adjacent (consecutive) elements are equal (i.e. a_2 - a_1 = a_3 - a_2 = … = a_n - a_{n-1}).

It can be proven that such an array always exists under the constraints given below.

Among all possible arrays that satisfy the given conditions, we ask you to restore one which has the minimum possible maximum element. In other words, you have to minimize max(a_1, a_2, ..., a_n).

You have to answer t independent test cases.

Input

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

The only line of the test case contains three integers n, x and y (2 ≤ n ≤ 50; 1 ≤ x < y ≤ 50) — the length of the array and two elements that are present in the array, respectively.

Output

For each test case, print the answer: n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is the i-th element of the required array. If there are several answers, you can print any (it also means that the order of elements doesn't matter).

It can be proven that such an array always exists under the given constraints.

Example

Input

5
2 1 49
5 20 50
6 20 50
5 3 8
9 13 22

Output

1 49
20 40 30 50 10
26 32 20 38 44 50
8 23 18 13 3
1 10 13 4 19 22 25 16 7

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
  long long res = 1;
  long long hell = 1e9 + 7;
  while (y > 0) {
    if (y & 1) res = (res * x) % hell;
    y = y >> 1;
    x = (x * x) % hell;
  }
  return res;
}
long long sod(long long n) {
  long long sum = 0;
  while (n > 0) {
    sum = sum + n % 10;
    n = n / 10;
  }
  return sum;
}
long long a[105], dp[55][10005], pd[55][10005], hell = 5000;
void solve() {
  long long n, sum = 0;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  pd[0][hell] = 1;
  for (long long qc = 1; qc <= n; qc++) {
    long long val = a[qc];
    for (long long i = 0; i <= n / 2; i++) {
      for (long long j = 0; j <= 2 * hell; j++) {
        if (!pd[i][j]) continue;
        long long nj = j - val;
        if (nj >= 0) dp[i][nj] = 1;
      }
    }
    for (long long i = 0; i <= n / 2; i++) {
      for (long long j = 0; j <= 2 * hell; j++) {
        if (!pd[i][j]) continue;
        long long nj = j + val;
        if (nj <= 2 * hell) dp[i + 1][nj] = 1;
      }
    }
    for (long long i = 0; i <= n / 2; i++) {
      for (long long j = 0; j <= 2 * hell; j++) {
        pd[i][j] = dp[i][j];
        dp[i][j] = 0;
      }
    }
  }
  long long lo = 2 * hell;
  for (long long i = 0; i <= 2 * hell; i++) {
    if (pd[n / 2][i]) lo = min(lo, abs(i - hell));
  }
  cout << (sum - lo) / 2 << " " << (sum + lo) / 2;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long mx = 1e18;
    long long n, x, y;
    cin >> n >> x >> y;
    vector<long long> v1(n);
    long long d = y - x;
    for (long long i = 1; i < x + 1; i++) {
      long long d = abs(i - y);
      for (long long j = 1; j < d + 1; j++) {
        if (d % j == 0) {
          long long no = d / j + 1;
          if (no <= n) {
            long long lr = y + (n - no) * j;
            if (lr < mx) {
              int f = 0;
              vector<long long> v2(n);
              for (long long k = 0; k < n; k++) {
                v2[k] = i + k * j;
                if (v2[k] == x) {
                  f = 1;
                }
              }
              if (f == 1 && lr < mx) {
                mx = lr, v1 = v2;
              }
            }
          }
        }
      }
    }
    for (long long i = 0; i < n; i++) cout << v1[i] << " ";
    cout << "\n";
  }
}

```


### Prompt

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

There are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \leq i \leq R) and the j-th column (1 \leq j \leq C). The i-th item is at (r_i, c_i) and has the value v_i.

Takahashi will begin at (1, 1), the start, and get to (R, C), the goal. When he is at (i, j), he can move to (i + 1, j) or (i, j + 1) (but cannot move to a non-existent square).

He can pick up items on the squares he visits, including the start and the goal, but at most three for each row. It is allowed to ignore the item on a square he visits.

Find the maximum possible sum of the values of items he picks up.

Constraints

* 1 \leq R, C \leq 3000
* 1 \leq K \leq \min(2 \times 10^5, R \times C)
* 1 \leq r_i \leq R
* 1 \leq c_i \leq C
* (r_i, c_i) \neq (r_j, c_j) (i \neq j)
* 1 \leq v_i \leq 10^9
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

R C K
r_1 c_1 v_1
r_2 c_2 v_2
:
r_K c_K v_K

Output

Print the maximum possible sum of the values of items Takahashi picks up.

Examples

Input

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

Output

8

Input

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

Output

29

Input

4 5 10
2 5 12
1 5 12
2 3 15
1 2 20
1 1 28
2 4 26
3 2 27
4 5 21
3 5 10
1 3 10

Output

142

### Response

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

using ll = long long;

ll dp[3003][3003][5];
ll item[3003][3003];

void chmax(ll &a, ll b) {
	a = max(a, b);
}

int main() {
	int R, C, K;
	cin >> R >> C >> K;
	for (int i = 0; i < K; i++) {
		int r, c, v;
		cin >> r >> c >> v;
		item[r - 1][c - 1] = v;
	}

	for (int i = 0; i <= R; i++) {
		for (int j = 0; j <= C; j++) {
			for (int k = 2; k >= 0; k--) {
				chmax(dp[i][j][k + 1], dp[i][j][k] + item[i][j]);
			}
			for (int k = 0; k <= 3; k++) {
				chmax(dp[i + 1][j][0], dp[i][j][k]);
				chmax(dp[i][j + 1][k], dp[i][j][k]);
			}
		}
	}

	ll ans = -1;
	for (int i = 0; i <= 3; i++) {
		ans = max(ans, dp[R][C][i]);
	}

	cout << ans << endl;
	return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions:

  1. The coordinates of each point in the set are integers.
  2. For any two points from the set, the distance between them is a non-integer.

Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n; 0 ≤ y ≤ m; x + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points.

Input

The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100).

Output

In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set.

If there are several optimal solutions, you may print any of them.

Examples

Input

2 2

Output

3
0 1
1 2
2 0

Input

4 3

Output

4
0 3
2 1
3 0
4 2

Note

Consider the first sample. The distance between points (0, 1) and (1, 2) equals <image>, between (0, 1) and (2, 0) — <image>, between (1, 2) and (2, 0) — <image>. Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, mn;
  scanf("%d %d", &n, &m);
  mn = min(n, m);
  printf("%d\n", mn + 1);
  for (int i = 0; i <= mn; i++) {
    printf("%d %d\n", mn - i, i);
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).

Consider a sequence A satisfying the following conditions:

* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.

Let us define a score of this sequence as follows:

* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)

Find the maximum possible score of A.

Constraints

* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )

Input

Input is given from Standard Input in the following format:

N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q

Output

Print the maximum possible score of A.

Examples

Input

3 4 3
1 3 3 100
1 2 2 10
2 3 2 10

Output

110

Input

4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328

Output

357500

Input

10 10 1
1 10 9 1

Output

1

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
const int N=50+5;
int n,m,q,a[N],b[N],c[N],d[N],t[N],ans=-1;
void dfs(int cur,int pre)
{
    if(cur==n+1){
        int tot=0;
        for(int i=1;i<=q;i++)if(t[b[i]]-t[a[i]]==c[i])tot+=d[i];
        ans=max(ans,tot);
        return ;
    }
    for(int i=pre;i<=m;i++){t[cur]=i;dfs(cur+1,i);}
}
int main()
{
    cin>>n>>m>>q;
    for(int i=1;i<=q;i++)cin>>a[i]>>b[i]>>c[i]>>d[i];
    dfs(1,1);
    cout<<ans<<endl;
    return 0;
}
```


### Prompt

Create a solution in CPP for the following problem:

Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi.

How many ways are there to choose K consecutive integers?

Constraints

* All values in input are integers.
* 1 \leq K \leq N \leq 50

Input

Input is given from Standard Input in the following format:

N K

Output

Print the answer.

Examples

Input

3 2

Output

2

Input

13 3

Output

11

### Response

```cpp
#include<iostream>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	cout<<n-m+1<<endl;
	return 0;
}
```


### Prompt

Please create a solution in cpp to the following problem:

You are given two strings s and t. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by 1. You can't choose a string if it is empty.

For example:

  * by applying a move to the string "where", the result is the string "here",
  * by applying a move to the string "a", the result is an empty string "".

You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings.

Write a program that finds the minimum number of moves to make two given strings s and t equal.

Input

The first line of the input contains s. In the second line of the input contains t. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and 2⋅10^5, inclusive.

Output

Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.

Examples

Input

test
west

Output

2

Input

codeforces
yes

Output

9

Input

test
yes

Output

7

Input

b
ab

Output

1

Note

In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".

In the second example, the move should be applied to the string "codeforces" 8 times. As a result, the string becomes "codeforces" → "es". The move should be applied to the string "yes" once. The result is the same string "yes" → "es".

In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty.

In the fourth example, the first character of the second string should be deleted.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
class TC {
 public:
  void solve() {
    string s1, s2;
    cin >> s1 >> s2;
    long long i, j, ans;
    bool flag = false;
    for (i = s1.size() - 1, j = s2.size() - 1; i >= 0, j >= 0; i--, j--) {
      if (s1[i] != s2[j]) {
        ans = i + 1 + j + 1;
        flag = true;
        break;
      }
    }
    if (flag)
      cout << ans << "\n";
    else if (i >= 0)
      cout << i + 1 << "\n";
    else if (j >= 0)
      cout << j + 1 << "\n";
    else
      cout << "0"
           << "\n";
  }
};
int32_t main() {
  (ios::sync_with_stdio(false), cin.tie(NULL));
  double start = clock();
  TC tc;
  tc.solve();
  cerr << "[*] Time: " << (clock() - start) * 1.0 / CLOCKS_PER_SEC
       << std::setprecision(3) << " s"
       << "\n";
  return 0;
}

```