### Prompt

Develop a solution in CPP to the problem described below:

Owl Sonya decided to become a partymaker. To train for this role she gather all her owl friends in the country house. There are m chairs located in a circle and consequently numbered with integers from 1 to m. Thus, chairs i and i + 1 are neighbouring for all i from 1 to m - 1. Chairs 1 and m are also neighbouring. Some chairs are occupied by her friends. There are n friends in total. No two friends occupy the same chair. Rules are the following:

  1. Each participant removes from the game the chair he is currently sitting on.
  2. Each of the participants choose a direction that she will follow: clockwise (indices increase, from m goes to 1) and counter-clockwise (indices decrease, from 1 goes to m). This direction may coincide or be different for any pair of owls.
  3. Each turn all guests move one step in the chosen directions. If some guest move to the position with a chair there, he removes this chair from the game.
  4. Game ends if there are no more chairs left in the game.

Owls are very busy and want to get rid of the game as soon as possible. They cooperate to pick the direction. Your goal is to find the minimum number o moves required to finish the game.

Input

The first line of the input contains a single integer m (1 ≤ m ≤ 109) — the length of the circle.

The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of friends.

Last line contains an increasing sequence of n integers ai (1 ≤ ai ≤ m) — initial positions of all owls.

Output

Print the minimum number of move required to finish the game. Note, that 0 also may be an answer.

Examples

Input

6
3
1 3 5

Output

1

Input

6
2
1 6

Output

2

Input

406
6
1 2 3 204 205 206

Output

100

Note

In the first sample, it's possible if all owls will move clockwise, i.e. in the direction of increasing indices.

In the sample, first owl has to move clockwise, while the second — counterclockwise.

In the third sample, the first and the fourth owls should move counterclockwise, while the third and the sixth — clockwise. The second and the firth may move in any direction.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int m, n;
int a[maxn], b[maxn];
int f[maxn];
bool check(int len) {
  f[1] = b[1];
  bool ok = true;
  for (int i = 2; i <= n; i++) {
    if (f[i - 1] + len + 1 >= b[i])
      f[i] = max(b[i], f[i - 1]);
    else {
      ok = false;
      break;
    }
    if (f[i - 1] >= b[i] - 1) f[i] = max(f[i], b[i] + len);
    if (i > 2 && f[i - 2] + len + 1 >= b[i]) f[i] = max(f[i], b[i - 1] + len);
  }
  if (ok && f[n] + len >= m) return true;
  ok = true;
  f[2] = max(b[2], b[1] + len);
  for (int i = 3; i <= n; i++) {
    if (f[i - 1] + len + 1 >= b[i])
      f[i] = max(b[i], f[i - 1]);
    else {
      ok = false;
      break;
    }
    if (f[i - 1] >= b[i] - 1) f[i] = max(f[i], b[i] + len);
    if (f[i - 2] + len + 1 >= b[i]) f[i] = max(f[i], b[i - 1] + len);
  }
  if (ok && f[n] + max(0, len - (b[2] - 1)) >= m) return true;
  return false;
}
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  if (n == 1) {
    printf("%d\n", m - 1);
    return 0;
  }
  int pos = 1, best = a[1] - 1 + m - a[n];
  for (int i = 2; i <= n; i++)
    if (a[i] - a[i - 1] - 1 > best) best = a[i] - a[i - 1] - 1, pos = i;
  int t = a[pos] - 1;
  for (int i = 1; i <= n; i++) {
    a[i] = a[i] - t;
    if (a[i] <= 0) a[i] += m;
  }
  for (int i = pos; i <= n; i++) b[i - pos + 1] = a[i];
  for (int i = 1; i < pos; i++) b[n - pos + 1 + i] = a[i];
  int L = (best + 1) / 2, R = best - 1, M;
  while (L <= R) {
    M = (L + R) >> 1;
    if (check(M))
      R = M - 1;
    else
      L = M + 1;
  }
  printf("%d\n", R + 1);
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.

Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:

  1. Take the leftmost item with the left hand and spend wi · l energy units (wi is a weight of the leftmost item, l is some parameter). If the previous action was the same (left-hand), then the robot spends extra Ql energy units;
  2. Take the rightmost item with the right hand and spend wj · r energy units (wj is a weight of the rightmost item, r is some parameter). If the previous action was the same (right-hand), then the robot spends extra Qr energy units;

Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.

Input

The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104).

The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100).

Output

In the single line print a single number — the answer to the problem.

Examples

Input

3 4 4 19 1
42 3 99

Output

576

Input

4 7 2 3 9
1 2 3 4

Output

34

Note

Consider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units.

The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, l, r, ql, qr, w[100100], mn, looper, accum = 0, currAccum = 0;
  cin >> n >> l >> r >> ql >> qr;
  for (int i = 0; i < n; ++i) {
    cin >> w[i];
    accum += w[i];
  }
  mn = accum * r;
  mn += (n - 1) * qr;
  for (int i = 1; i <= n; ++i) {
    currAccum += w[i - 1];
    looper = currAccum * l + (accum - currAccum) * r;
    if (i >= n - i) {
      long long toMult = i - (n - i) - 1;
      toMult = (toMult > 0) ? toMult : 0;
      looper += toMult * ql;
    } else {
      long long toMult = (n - i) - i - 1;
      toMult = (toMult > 0) ? toMult : 0;
      looper += toMult * qr;
    }
    mn = min(mn, looper);
  }
  cout << mn << endl;
  return 0;
}

```


### Prompt

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

Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of n small Latin letters; the task was to learn the way the letters that the string contains are written. However, as Gerald is too lazy, he has no desire whatsoever to learn those letters. That's why he decided to lose some part of the string (not necessarily a connected part). The lost part can consist of any number of segments of any length, at any distance from each other. However, Gerald knows that if he loses more than k characters, it will be very suspicious.

Find the least number of distinct characters that can remain in the string after no more than k characters are deleted. You also have to find any possible way to delete the characters.

Input

The first input data line contains a string whose length is equal to n (1 ≤ n ≤ 105). The string consists of lowercase Latin letters. The second line contains the number k (0 ≤ k ≤ 105).

Output

Print on the first line the only number m — the least possible number of different characters that could remain in the given string after it loses no more than k characters.

Print on the second line the string that Gerald can get after some characters are lost. The string should have exactly m distinct characters. The final string should be the subsequence of the initial string. If Gerald can get several different strings with exactly m distinct characters, print any of them.

Examples

Input

aaaaa
4

Output

1
aaaaa

Input

abacaba
4

Output

1
aaaa

Input

abcdefgh
10

Output

0

Note

In the first sample the string consists of five identical letters but you are only allowed to delete 4 of them so that there was at least one letter left. Thus, the right answer is 1 and any string consisting of characters "a" from 1 to 5 in length.

In the second sample you are allowed to delete 4 characters. You cannot delete all the characters, because the string has length equal to 7. However, you can delete all characters apart from "a" (as they are no more than four), which will result in the "aaaa" string.

In the third sample you are given a line whose length is equal to 8, and k = 10, so that the whole line can be deleted. The correct answer is 0 and an empty string.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
const int INF = int(1e9);
set<char> st;
int cnt[N], k, n;
char s[N], m[N];
int main() {
  gets(s);
  cin >> k;
  n = strlen(s);
  for (int i = 0; i < n; ++i) cnt[int(s[i])]++;
  while (k) {
    int Min = INF, q;
    for (int ch = 'a'; ch <= 'z'; ++ch)
      if (cnt[ch] > 0) {
        if (cnt[ch] < Min) {
          Min = cnt[ch];
          q = char(ch);
        }
      }
    if (Min <= k) {
      cnt[q] -= Min;
      m[q] = true;
      k -= Min;
    } else
      break;
  }
  for (int k = 0; k < n; ++k)
    if (m[int(s[k])] == 0) st.insert(s[k]);
  cout << st.size() << '\n';
  for (int tt = 0; tt < n; ++tt)
    if (m[int(s[tt])] == 0) cout << s[tt];
  cout << '\n';
}

```


### Prompt

Create a solution in cpp for the following problem:

A professor invented Cookie Breeding Machine for his students who like cookies very much.

When one cookie with the taste of x is put into the machine and a non-negative integer y less than or equal to 127 is input on the machine, it consumes the cookie and generates two cookies with the taste of y and (x XOR y).

Here, XOR represents Bitwise Exclusive OR.

At first, there is only one cookie and the taste of it is D .

Find the maximum value of the sum of the taste of the exactly N cookies generated after the following operation is conducted N-1 times.

1. Put one of the cookies into the machine.
2. Input a non-negative integer less than or equal to 127 on the machine.

Constraints

* 1 \leq T \leq 1000
* 1 \leq N_t \leq 1000 (1 \leq t \leq T)
* 1 \leq D_t \leq 127 (1 \leq t \leq T)

Input

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

T
N_1 D_1
:
N_T D_T

The input consists of multiple test cases. An Integer T that represents the number of test cases is given on line 1.
Each test case is given on the next T lines.
In the t-th test case ( 1 \leq t \leq T ), N_t that represents the number of cookies generated through the operations and D_t that represents the taste of the initial cookie are given separated by space.

Output

For each test case, print the maximum value of the sum of the taste of the N cookies generated through the operations on one line.

Example

Input

3
3 1
4 108
1 10

Output

255
400
10

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int T;cin>>T;
while(T--){
int N,D;
cin>>N>>D;
int res=127*(N-1);
if(N%2)res+=D;
else res+=127-D;
cout<<res<<endl;
}
return 0;
}
```


### Prompt

Construct a Cpp code solution to the problem outlined:

The only difference between easy and hard versions are constraints on n and k.

You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most k most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals 0).

Each conversation is between you and some of your friends. There is at most one conversation with any of your friends. So each conversation is uniquely defined by your friend.

You (suddenly!) have the ability to see the future. You know that during the day you will receive n messages, the i-th message will be received from the friend with ID id_i (1 ≤ id_i ≤ 10^9).

If you receive a message from id_i in the conversation which is currently displayed on the smartphone then nothing happens: the conversations of the screen do not change and do not change their order, you read the message and continue waiting for new messages.

Otherwise (i.e. if there is no conversation with id_i on the screen):

  * Firstly, if the number of conversations displayed on the screen is k, the last conversation (which has the position k) is removed from the screen.
  * Now the number of conversations on the screen is guaranteed to be less than k and the conversation with the friend id_i is not displayed on the screen.
  * The conversation with the friend id_i appears on the first (the topmost) position on the screen and all the other displayed conversations are shifted one position down.

Your task is to find the list of conversations (in the order they are displayed on the screen) after processing all n messages.

Input

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 2 ⋅ 10^5) — the number of messages and the number of conversations your smartphone can show.

The second line of the input contains n integers id_1, id_2, ..., id_n (1 ≤ id_i ≤ 10^9), where id_i is the ID of the friend which sends you the i-th message.

Output

In the first line of the output print one integer m (1 ≤ m ≤ min(n, k)) — the number of conversations shown after receiving all n messages.

In the second line print m integers ids_1, ids_2, ..., ids_m, where ids_i should be equal to the ID of the friend corresponding to the conversation displayed on the position i after receiving all n messages.

Examples

Input

7 2
1 2 3 2 1 3 2

Output

2
2 1

Input

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

Output

3
1 3 2

Note

In the first example the list of conversations will change in the following way (in order from the first to last message):

  * [];
  * [1];
  * [2, 1];
  * [3, 2];
  * [3, 2];
  * [1, 3];
  * [1, 3];
  * [2, 1].

In the second example the list of conversations will change in the following way:

  * [];
  * [2];
  * [3, 2];
  * [3, 2];
  * [1, 3, 2];
  * and then the list will not change till the end.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t = 1;
  while (t--) {
    int n, k, x, y;
    cin >> n >> k;
    multiset<int> s;
    deque<int> q;
    while (n--) {
      cin >> x;
      if (s.count(x)) continue;
      if (q.size() == k) {
        y = q.front();
        q.pop_front();
        if (s.count(y)) s.erase(s.find(y));
      }
      q.push_back(x);
      s.insert(x);
    }
    cout << q.size() << "\n";
    while (!q.empty()) {
      cout << q.back() << " ";
      q.pop_back();
    }
  }
  return 0;
}

```


### Prompt

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

Nikolay has only recently started in competitive programming, but already qualified to the finals of one prestigious olympiad. There going to be n participants, one of whom is Nikolay. Like any good olympiad, it consists of two rounds. Tired of the traditional rules, in which the participant who solved the largest number of problems wins, the organizers came up with different rules.

Suppose in the first round participant A took x-th place and in the second round — y-th place. Then the total score of the participant A is sum x + y. The overall place of the participant A is the number of participants (including A) having their total score less than or equal to the total score of A. Note, that some participants may end up having a common overall place. It is also important to note, that in both the first and the second round there were no two participants tying at a common place. In other words, for every i from 1 to n exactly one participant took i-th place in first round and exactly one participant took i-th place in second round.

Right after the end of the Olympiad, Nikolay was informed that he got x-th place in first round and y-th place in the second round. Nikolay doesn't know the results of other participants, yet he wonders what is the minimum and maximum place he can take, if we consider the most favorable and unfavorable outcome for him. Please help Nikolay to find the answer to this question.

Input

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

Each of the following t lines contains integers n, x, y (1 ≤ n ≤ 10^9, 1 ≤ x, y ≤ n) — the number of participants in the olympiad, the place that Nikolay took in the first round and the place that Nikolay took in the second round.

Output

Print two integers — the minimum and maximum possible overall place Nikolay could take.

Examples

Input

1
5 1 3

Output

1 3

Input

1
6 3 4

Output

2 6

Note

Explanation for the first example:

Suppose there were 5 participants A-E. Let's denote Nikolay as A. The the most favorable results for Nikolay could look as follows:

<image>

However, the results of the Olympiad could also look like this:

<image>

In the first case Nikolay would have taken first place, and in the second — third place.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a, b;
    cin >> a >> b;
    if (a + b <= n) {
      cout << 1 << " " << a + b - 1;
    } else {
      int v = (a + b - n) + 1;
      if (v >= n) v = n;
      cout << v << " " << n;
    }
    cout << endl;
  }
}

```


### Prompt

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

Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.

Dr. Evil is interested in sets, He has a set of n integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly x. the MEX of a set of integers is the minimum non-negative integer that doesn't exist in it. For example, the MEX of the set {0, 2, 4} is 1 and the MEX of the set {1, 2, 3} is 0 .

Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil?

Input

The first line contains two integers n and x (1 ≤ n ≤ 100, 0 ≤ x ≤ 100) — the size of the set Dr. Evil owns, and the desired MEX.

The second line contains n distinct non-negative integers not exceeding 100 that represent the set.

Output

The only line should contain one integer — the minimal number of operations Dr. Evil should perform.

Examples

Input

5 3
0 4 5 6 7

Output

2

Input

1 0
0

Output

1

Input

5 0
1 2 3 4 5

Output

0

Note

For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.

For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.

In the third test case the set is already evil.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, n, t, x;
  int ans = 0;
  cin >> n >> x;
  int a[1000000];
  for (i = 0; i < n; i++) cin >> a[i];
  int add = 0;
  for (i = 0; i < n; i++) {
    if (a[i] < x) ans++;
    if (a[i] == x) add++;
  }
  cout << x - ans + add << endl;
  return 0;
}

```


### Prompt

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

Reordering the Documents

Susan is good at arranging her dining table for convenience, but not her office desk.

Susan has just finished the paperwork on a set of documents, which are still piled on her desk. They have serial numbers and were stacked in order when her boss brought them in. The ordering, however, is not perfect now, as she has been too lazy to put the documents slid out of the pile back to their proper positions. Hearing that she has finished, the boss wants her to return the documents immediately in the document box he is sending her. The documents should be stowed in the box, of course, in the order of their serial numbers.

The desk has room just enough for two more document piles where Susan plans to make two temporary piles. All the documents in the current pile are to be moved one by one from the top to either of the two temporary piles. As making these piles too tall in haste would make them tumble, not too many documents should be placed on them. After moving all the documents to the temporary piles and receiving the document box, documents in the two piles will be moved from their tops, one by one, into the box. Documents should be in reverse order of their serial numbers in the two piles to allow moving them to the box in order.

For example, assume that the pile has six documents #1, #3, #4, #2, #6, and #5, in this order from the top, and that the temporary piles can have no more than three documents. Then, she can form two temporary piles, one with documents #6, #4, and #3, from the top, and the other with #5, #2, and #1 (Figure E.1). Both of the temporary piles are reversely ordered. Then, comparing the serial numbers of documents on top of the two temporary piles, one with the larger number (#6, in this case) is to be removed and stowed into the document box first. Repeating this, all the documents will be perfectly ordered in the document box.

<image>
Figure E.1. Making two temporary piles

Susan is wondering whether the plan is actually feasible with the documents in the current pile and, if so, how many different ways of stacking them to two temporary piles would do. You are asked to help Susan by writing a program to compute the number of different ways, which should be zero if the plan is not feasible.

As each of the documents in the pile can be moved to either of the two temporary piles, for $n$ documents, there are $2^n$ different choice combinations in total, but some of them may disturb the reverse order of the temporary piles and are thus inappropriate.

The example described above corresponds to the first case of the sample input. In this case, the last two documents, #5 and #6, can be swapped their destinations. Also, exchanging the roles of two temporary piles totally will be OK. As any other move sequences would make one of the piles higher than three and/or make them out of order, the total number of different ways of stacking documents to temporary piles in this example is $2 \times 2 = 4$.

Input

The input consists of a single test case of the following format.

$n$ $m$
$s_1$ ...  $s_n$

Here, $n$ is the number of documents in the pile ($1 \leq n \leq 5000$), and $m$ is the number of documents that can be stacked in one temporary pile without committing risks of making it tumble down ($n/2 \leq m \leq n$). Numbers $s_1$ through $s_n$ are the serial numbers of the documents in the document pile, from its top to its bottom. It is guaranteed that all the numbers $1$ through $n$ appear exactly once.

Output

Output a single integer in a line which is the number of ways to form two temporary piles suited for the objective. When no choice will do, the number of ways is $0$, of course.

If the number of possible ways is greater than or equal to $10^9 + 7$, output the number of ways modulo $10^9 + 7$.

Sample Input 1

6 3
1 3 4 2 6 5

Sample Output 1

4

Sample Input 2

6 6
1 3 4 2 6 5

Sample Output 2

8

Sample Input 3

4 4
4 3 1 2

Sample Output 3

0

Example

Input

6 3
1 3 4 2 6 5

Output

4

### Response

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

struct BipartiteGraph {
	struct Edge {
		const int from;
		const int to;
		Edge(const int from, const int to) :
			from(from),
			to(to)
			{}
	};
	const int V;
	vector<vector<Edge>> G;
	vector<int> color;
	BipartiteGraph(const int V) :
		V(V),
		G(vector<vector<Edge>>(V, vector<Edge>())),
		color(vector<int>(V, -1))
		{}
	void addEdge(const int from, const int to) {
		G[from].emplace_back(from, to);
		G[to].emplace_back(to, from);
	}
	bool dfs(const int from, const int col) {
		color[from] = col;
		bool ret = true;
		for(Edge e : G[from]) {
			if(color[e.to] == -1) {
				ret &= dfs(e.to, col ^ 1);
			}
			if(color[e.to] == col) {
				return false;
			}
		}
		return ret;
	}
	int bipart() {
		if(not dfs(0, 0)) throw "NOT Bipartite Graph";
		int ret = 0;
		for(int i : color) ret += i;
		return ret;
	}
};

struct UnionFind {
	const int V;
	// par[x] := xのroot
	vector<int> par;
	// sz[x] := xを含む集合のサイズ
	vector<int> sz;
	UnionFind(const int V) :
		V(V),
		par(vector<int>(V)),
		sz(vector<int>(V, 1))
		{
			for(int i = 0; i < V; ++i) par[i] = i;
		}
	bool unite(int x, int y) {
		x = root(x), y = root(y);
		if(same(x, y)) return false;
		if(y < x) swap(x, y);
		par[y] = x;
		sz[x] += sz[y];
		return true;
	}
	int root(int x) {
		if(par[x] == x) return x;
		return (par[x] = root(par[x]));
	}
	bool same(int x, int y) {
		return (root(x) == root(y));
	}
	int size(int x) {
		return sz[root(x)];
	}
};

int dp[5010][5010];
int main() {
	const int MOD = 1e9 + 7;
	int n, m; cin >> n >> m;
	int a[n];
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		--a[i];
	}
	UnionFind uf(n);
	for(int i = 0; i < n; ++i) {
		for(int j = i + 1; j < n; ++j) {
			if(a[i] > a[j]) uf.unite(i, j);
		}
	}
	vector<int> edge[n];
	for(int i = 0; i < n; ++i) {
		edge[uf.root(i)].push_back(i);
	}
	vector<int> color[2];
	for(int i = 0; i < n; ++i) {
		int nn = edge[i].size();
		if(nn == 0) continue;
		BipartiteGraph bg(nn);
		for(int j = 0; j < nn; ++j) {
			for(int k = j + 1; k < nn; ++k) {
				if(a[edge[i][j]] > a[edge[i][k]]) {
					bg.addEdge(j, k);
				}
			}
		}
		try {
			int x = bg.bipart();
			color[0].push_back(x);
			color[1].push_back(nn - x);
		}
		catch(...) {
			cout << 0 << endl;
			return 0;
		}
	}
	int sz = color[0].size();
	dp[0][0] = 1;
	for(int i = 1; i <= sz; ++i) {
		for(int j = 0; j <= n; ++j) {
			for(int k = 0; k < 2; ++k) {
				if(j - color[k][i - 1] >= 0) {
					dp[i][j] += dp[i - 1][j - color[k][i - 1]];
				}
				dp[i][j] %= MOD;
			}
		}
	}
	int ans = 0;
	for(int j = 0; j <= n; ++j) {
		if(max(j, n - j) > m) continue;
		ans += dp[sz][j];
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 ≤ i ≤ n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.

Help Kefa cope with this task!

Input

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

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print a single integer — the length of the maximum non-decreasing subsegment of sequence a.

Examples

Input

6
2 2 1 3 4 1

Output

3

Input

3
2 2 9

Output

3

Note

In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.

In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n + 1], d[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  d[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (a[i] >= a[i - 1])
      d[i] = d[i - 1] + 1;
    else
      d[i] = 1;
  }
  int max = 0;
  for (int i = 1; i <= n; i++)
    if (d[i] > max) max = d[i];
  cout << max;
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Input

The input contains a single integer a (1 ≤ a ≤ 40).

Output

Output a single string.

Examples

Input

2

Output

Adams

Input

8

Output

Van Buren

Input

29

Output

Harding

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[105] = {0,   1,  1, 1, 2,  1, 2,  1, 5,  2, 2,  1, 5,  1, 2, 1,
                   14,  1,  5, 1, 5,  2, 2,  1, 15, 2, 2,  5, 4,  1, 4, 1,
                   51,  1,  2, 1, 14, 1, 2,  2, 14, 1, 6,  1, 4,  2, 2, 1,
                   52,  2,  5, 1, 5,  1, 15, 2, 13, 2, 2,  1, 13, 1, 2, 4,
                   267, 1,  4, 1, 5,  1, 4,  1, 50, 1, 2,  3, 4,  1, 6, 1,
                   52,  15, 2, 1, 15, 1, 2,  1, 12, 1, 10, 1, 4,  2};
  cin >> n;
  cout << a[n];
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Alice and Bonnie are sisters, but they don't like each other very much. So when some old family photos were found in the attic, they started to argue about who should receive which photos. In the end, they decided that they would take turns picking photos. Alice goes first.

There are n stacks of photos. Each stack contains exactly two photos. In each turn, a player may take only a photo from the top of one of the stacks.

Each photo is described by two non-negative integers a and b, indicating that it is worth a units of happiness to Alice and b units of happiness to Bonnie. Values of a and b might differ for different photos.

It's allowed to pass instead of taking a photo. The game ends when all photos are taken or both players pass consecutively.

The players don't act to maximize their own happiness. Instead, each player acts to maximize the amount by which her happiness exceeds her sister's. Assuming both players play optimal, find the difference between Alice's and Bonnie's happiness. That is, if there's a perfectly-played game such that Alice has x happiness and Bonnie has y happiness at the end, you should print x - y.

Input

The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the number of two-photo stacks. Then follow n lines, each describing one of the stacks. A stack is described by four space-separated non-negative integers a1, b1, a2 and b2, each not exceeding 109. a1 and b1 describe the top photo in the stack, while a2 and b2 describe the bottom photo in the stack.

Output

Output a single integer: the difference between Alice's and Bonnie's happiness if both play optimally.

Examples

Input

2
12 3 4 7
1 15 9 1

Output

1

Input

2
5 4 8 8
4 12 14 0

Output

4

Input

1
0 10 0 10

Output

-10

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct data {
  int a, b;
  friend bool operator<(data a, data b) { return a.a + a.b < b.a + b.b; }
} p[200005];
int main() {
  int n, l = 0;
  long long ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int a1, a2, b1, b2;
    scanf("%d%d%d%d", &a1, &b1, &a2, &b2);
    if (a1 <= b2 && b1 <= a2) continue;
    if (a1 + b1 < a2 + b2) {
      if (a1 <= b2) {
        ans += a2 - b1;
      } else
        ans += a1 - b2;
    } else {
      p[++l] = (data){a1, b1};
      p[++l] = (data){a2, b2};
    }
  }
  sort(p + 1, p + l + 1);
  for (int i = 1; i <= l; i++) {
    if (i % 2 == 0)
      ans += p[i].a;
    else
      ans -= p[i].b;
  }
  printf("%I64d\n", ans);
  return 0;
}

```


### Prompt

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

Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwise traversal.

Alex had very nice test for this problem, but is somehow happened that the last line of the input was lost and now he has only three out of four points of the original parallelogram. He remembers that test was so good that he asks you to restore it given only these three points.

Input

The input consists of three lines, each containing a pair of integer coordinates xi and yi ( - 1000 ≤ xi, yi ≤ 1000). It's guaranteed that these three points do not lie on the same line and no two of them coincide.

Output

First print integer k — the number of ways to add one new integer point such that the obtained set defines some parallelogram of positive area. There is no requirement for the points to be arranged in any special order (like traversal), they just define the set of vertices.

Then print k lines, each containing a pair of integer — possible coordinates of the fourth point.

Example

Input

0 0
1 0
0 1

Output

3
1 -1
-1 1
1 1

Note

If you need clarification of what parallelogram is, please check Wikipedia page:

https://en.wikipedia.org/wiki/Parallelogram

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  int n, a, i, k, x[100], y[100];
  for (i = 0; i < 3; i++) {
    cin >> x[i] >> y[i];
  }
  cout << "3" << endl;
  cout << x[2] - x[1] + x[0] << " " << y[0] + y[2] - y[1] << endl;
  cout << x[1] + x[0] - x[2] << " " << y[1] + y[0] - y[2] << endl;
  cout << x[2] + x[1] - x[0] << " " << y[2] + y[1] - y[0] << endl;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together.

Given an integer N, determine whether N can be represented as the product of two integers between 1 and 9. If it can, print `Yes`; if it cannot, print `No`.

Constraints

* 1 \leq N \leq 100
* N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If N can be represented as the product of two integers between 1 and 9 (inclusive), print `Yes`; if it cannot, print `No`.

Examples

Input

10

Output

Yes

Input

50

Output

No

Input

81

Output

Yes

### Response

```cpp
#include<iostream>
using namespace std;
int n;
bool b[101];
int main()
{
	cin>>n;
	for(int i=1;i<=9;i++)
		for(int j=i;j<=9;j++)
			b[i*j]=1;
	if(b[n])cout<<"Yes";
	else cout<<"No";
	return 0;
}
```


### Prompt

Please formulate a Cpp solution to the following problem:

Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations:

* $add(s, t, x)$ : add $x$ to $a_s, a_{s+1}, ..., a_t$.
* $find(s, t)$ : report the minimum value in $a_s, a_{s+1}, ..., a_t$.

Note that the initial values of $a_i ( i = 0, 1, ..., n-1 )$ are 0.

Constraints

* $1 ≤ n ≤ 100000$
* $1 ≤ q ≤ 100000$
* $0 ≤ s ≤ t < n$
* $-1000 ≤ x ≤ 1000$

Input

$n$ $q$
$query_1$
$query_2$
:
$query_q$

In the first line, $n$ (the number of elements in $A$) and $q$ (the number of queries) are given. Then, $i$th query $query_i$ is given in the following format:

0 $s$ $t$ $x$

or

1 $s$ $t$

The first digit represents the type of the query. '0' denotes $add(s, t, x)$ and '1' denotes $find(s, t)$.

Output

For each $find$ query, print the minimum value.

Example

Input

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

Output

-2
0
1
-1

### Response

```cpp
#include<iostream>
using namespace std;
#include<vector>
#include<functional>
template<typename T>
struct lazysegtree{
	function<T(T,T)>calcfn,lazycalcfn;
	function<T(T,T,unsigned int)>updatefn;
	int n;
	T defvalue,lazydefvalue;
	vector<T>dat,lazy;
	vector<bool>lazyflag;
	lazysegtree(int n_=0,T defvalue_=0,
		function<T(T,T)>calcfn_=[](T a,T b){return a+b;},
		function<T(T,T)>lazycalcfn_=[](T a,T b){return a+b;},
		function<T(T,T,unsigned int)>updatefn_=[](T a,T b,unsigned int width){return a+b*width;},
		T lazydefvalue_=0
	):defvalue(defvalue_),lazydefvalue(lazydefvalue_),
		calcfn(calcfn_),lazycalcfn(lazycalcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
		lazy.assign(2*n-1,lazydefvalue);
		lazyflag.assign(2*n-1,false);
	}
	void copy(vector<T>v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
	}
	void eval(int i,int l,int r)
	{
		if(lazyflag[i])
		{
			dat[i]=updatefn(dat[i],lazy[i],r-l);
			if(r-l>1)
			{
				lazy[2*i+1]=lazycalcfn(lazy[2*i+1],lazy[i]);
				lazy[2*i+2]=lazycalcfn(lazy[2*i+2],lazy[i]);
				lazyflag[2*i+1]=lazyflag[2*i+2]=true;
			}
			lazy[i]=lazydefvalue;
			lazyflag[i]=false;
		}
	}
	void update(int a,int b,T x,int k=0,int l=0,int r=-1)
	{
		if(r<0)r=n;
		eval(k,l,r);
		if(b<=l||r<=a)return;
		else if(a<=l&&r<=b)
		{
			lazy[k]=lazycalcfn(lazy[k],x);
			lazyflag[k]=true;
			eval(k,l,r);
		}
		else
		{
			update(a,b,x,2*k+1,l,(l+r)/2);
			update(a,b,x,2*k+2,(l+r)/2,r);
			dat[k]=calcfn(dat[2*k+1],dat[2*k+2]);
		}
	}
	T query(int a,int b,int k=0,int l=0,int r=-1)
	{
		if(r<0)r=n;
		eval(k,l,r);
		if(b<=l||r<=a)return defvalue;
		else if(a<=l&&r<=b)return dat[k];
		else return calcfn(
			query(a,b,2*k+1,l,(l+r)/2),
			query(a,b,2*k+2,(l+r)/2,r)
		);
	}
};
int n,q;
int main()
{
	cin>>n>>q;
	lazysegtree<int>P(n,(1LL<<31)-1,[](int a,int b){return a<b?a:b;},[](int a,int b){return a+b;},[](int a,int b,int width){return a+b;});
	vector<int>a(n,0);
	P.copy(a);
	for(int i=0;i<q;i++)
	{
		int c;cin>>c;
		if(c)
		{
			int s,t;cin>>s>>t;
			cout<<P.query(s,t+1)<<endl;
		}
		else
		{
			int s,t,x;cin>>s>>t>>x;
			P.update(s,t+1,x);
		}
	}
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

There are two rectangles. The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B. The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D.

Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.

Constraints

* All input values are integers.
* 1≤A≤10^4
* 1≤B≤10^4
* 1≤C≤10^4
* 1≤D≤10^4

Input

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

A B C D

Output

Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.

Examples

Input

3 5 2 7

Output

15

Input

100 600 200 300

Output

60000

### Response

```cpp
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    (a*b)>(c*d)?cout<<a*b<<endl:cout<<c*d<<endl;
}

```


### Prompt

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

A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap.

Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has its price, represented by an integer number of rubles. Gerald wants to buy three clothing items so that they matched each other. Besides, he wants to spend as little money as possible. Find the least possible sum he can spend.

Input

The first input file line contains integers n and m — the total number of clothing items in the shop and the total number of matching pairs of clothing items (<image>).

Next line contains n integers ai (1 ≤ ai ≤ 106) — the prices of the clothing items in rubles.

Next m lines each contain a pair of space-separated integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi). Each such pair of numbers means that the ui-th and the vi-th clothing items match each other. It is guaranteed that in each pair ui and vi are distinct and all the unordered pairs (ui, vi) are different.

Output

Print the only number — the least possible sum in rubles that Gerald will have to pay in the shop. If the shop has no three clothing items that would match each other, print "-1" (without the quotes).

Examples

Input

3 3
1 2 3
1 2
2 3
3 1

Output

6

Input

3 2
2 3 4
2 3
2 1

Output

-1

Input

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

Output

-1

Note

In the first test there only are three pieces of clothing and they all match each other. Thus, there is only one way — to buy the 3 pieces of clothing; in this case he spends 6 roubles.

The second test only has three pieces of clothing as well, yet Gerald can't buy them because the first piece of clothing does not match the third one. Thus, there are no three matching pieces of clothing. The answer is -1.

In the third example there are 4 pieces of clothing, but Gerald can't buy any 3 of them simultaneously. The answer is -1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
const double EPS = 1e-9;
const int MAXN = 100;
bool e[MAXN][MAXN];
int c[MAXN];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &c[i]);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[x - 1][y - 1] = e[y - 1][x - 1] = true;
  }
  int mi = INF;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      for (int k = j + 1; k < n; k++)
        if (e[i][j] && e[i][k] && e[j][k] && c[i] + c[j] + c[k] < mi)
          mi = c[i] + c[j] + c[k];
  if (mi == INF) mi = -1;
  printf("%d\n", mi);
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

There are n districts in the town, the i-th district belongs to the a_i-th bandit gang. Initially, no districts are connected to each other.

You are the mayor of the city and want to build n-1 two-way roads to connect all districts (two districts can be connected directly or through other connected districts).

If two districts belonging to the same gang are connected directly with a road, this gang will revolt.

You don't want this so your task is to build n-1 two-way roads in such a way that all districts are reachable from each other (possibly, using intermediate districts) and each pair of directly connected districts belong to different gangs, or determine that it is impossible to build n-1 roads to satisfy all the conditions.

You have to answer t independent test cases.

Input

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

The first line of the test case contains one integer n (2 ≤ n ≤ 5000) — the number of districts. The second line of the test case contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9), where a_i is the gang the i-th district belongs to.

It is guaranteed that the sum of n does not exceed 5000 (∑ n ≤ 5000).

Output

For each test case, print:

  * NO on the only line if it is impossible to connect all districts satisfying the conditions from the problem statement.
  * YES on the first line and n-1 roads on the next n-1 lines. Each road should be presented as a pair of integers x_i and y_i (1 ≤ x_i, y_i ≤ n; x_i ≠ y_i), where x_i and y_i are two districts the i-th road connects.

For each road i, the condition a[x_i] ≠ a[y_i] should be satisfied. Also, all districts should be reachable from each other (possibly, using intermediate districts).

Example

Input

4
5
1 2 2 1 3
3
1 1 1
4
1 1000 101 1000
4
1 2 3 4

Output

YES
1 3
3 5
5 4
1 2
NO
YES
1 2
2 3
3 4
YES
1 2
1 3
1 4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
    }
    long long idx = -1;
    vector<pair<long long, long long>> res;
    for (long long i = 0; i < n; i++) {
      if (a[i] != a[0]) {
        idx = i;
        res.push_back({1, i + 1});
      }
    }
    if (idx == -1) {
      cout << "No" << endl;
      continue;
    }
    for (long long i = 1; i < n; i++) {
      if (a[i] == a[0]) {
        res.push_back({idx + 1, i + 1});
      }
    }
    cout << "Yes" << endl;
    for (auto x : res) {
      cout << x.first << " " << x.second << endl;
    }
  }
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

You are a student of University of Aizu. And you work part-time at a restaurant.

Staffs of the restaurant are well trained to be delighted to provide more delicious products faster.

The speed providing products particularly depends on skill of the staff. So, the manager of the restaurant want to know how long it takes to provide products.

Though some restaurants employ a system which calculates how long it takes to provide products automatically, the restaurant where you work employs a system which calculates it manually.

You, a student of University of Aizu, want to write a program to calculate it, and you hope that your program makes the task easier. You are given the checks in a day. If the length of time it takes to provide the products of a check is shorter than or equal to 8 minutes, it is "ok" check. Write a program to output the ratio of "ok" checks to the total in percentage.

Hint

If you want to read three integers in the following format,
integer:integer(space)integer
you can read them by scanf("%d%*c%d%d",&a;, &b;, &c;); in C.

Input

The input consists of multiple datasets. The last dataset is followed by a line containing a single zero. You don't have to process this data. The first line of each dataset contains a single integer n.

n (0 < n  ≤ 100) is the number of checks. Each of following  n  lines gives the details of a check in the following format.

hh:mm MM

hh:mm is the clock time to print the check. MM is minute of the clock time to provide products. The clock time is expressed according to the 24 hour clock.
For example, "eleven one PM" is expressed by "23:01".
You can assume that the all of products are provided within fifteen minutes. The restaurant is open from AM 11:00 to AM 02:00. After AM 02:00, no check is printed. Also at AM 02:00, no check is printed.

Output

Your program has to print in the following format for each dataset.

lunch L
dinner D
midnight M

L  is ratio of "ok" check printed to the total in lunch time.  D  is ratio of "ok" check printed to the total in dinner time.  M  is ratio of "ok" check printed to the total in midnight time. You can truncate digits number after the decimal point of the ratio on the percentage. Lunch, dinner, and midnight times are defined as follows:

Lunch time is 11:00 ~ 14:59.
Dinner time is 18:00 ~ 20:59.
Midnight time is 21:00 ~ 01:59.

If a check is not printed in the three range of time, you don't have to process it. If no check is in the range of time, you should print "no guest".

Example

Input

5
12:57 59
20:12 15
12:19 21
18:52 03
16:09 14
0

Output

lunch 100
dinner 50
midnight no guest

### Response

```cpp
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <complex>
using namespace std;

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

#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T> void preview(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}

const int INF = 100000000;
const double PI = acos(-1.0), EPS = 1e-10;

int main() {
	for(int n; scanf(" %d", &n), n;) {
		int sums[3] = {0};
		int ok[3] = {0};
		rep(i,n) {
			int hh, mm, cc;
			scanf(" %d:%d %d", &hh, &mm, &cc);
			if(cc < mm) {
				cc = cc + 60 - mm;
			} else {
				cc = cc - mm;
			}

			if(11 <= hh && hh < 15) {
				sums[0]++;
				if(cc <= 8) ok[0]++;
			} else if(18 <= hh && hh < 21) {
				sums[1]++;
				if(cc <= 8) ok[1]++;
			} else if(hh < 2 || 21 <= hh) {
				sums[2]++;
				if(cc <= 8) ok[2]++;
			}
		}
		cout << "lunch ";
		if(sums[0]) cout << ok[0] * 100 / sums[0] << endl;
		else cout << "no guest" << endl;
		cout << "dinner ";
		if(sums[1]) cout << ok[1] * 100 / sums[1] << endl;
		else cout << "no guest" << endl;
		cout << "midnight ";
		if(sums[2]) cout << ok[2] * 100 / sums[2] << endl;
		else cout << "no guest" << endl;
	}
	return 0;
}
```


### Prompt

Construct a cpp code solution to the problem outlined:

Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a number k and an array a containing n numbers. Find out how many k-good numbers are in a (count each number every time it occurs in array a).

Input

The first line contains integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 9). The i-th of the following n lines contains integer ai without leading zeroes (1 ≤ ai ≤ 109).

Output

Print a single integer — the number of k-good numbers in a.

Examples

Input

10 6
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560
1234560

Output

10

Input

2 1
1
10

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  istream& in(std::cin);
  ostream& out(std::cout);
  ios_base::sync_with_stdio(false);
  in.tie(NULL);
  int n, k, nt = 0;
  in >> n >> k;
  int a[10];
  while (n--) {
    memset(a, 0, sizeof(a));
    int t = 0;
    string s;
    in >> s;
    for (int i = 0; i < (int)s.length(); ++i) a[(s[i] - '0')]++;
    for (int i = 0; i < 10; ++i) {
      if (a[i] > 0 && i <= k) ++t;
    }
    if (t == k + 1) ++nt;
  }
  out << nt << '\n';
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Even the most successful company can go through a crisis period when you have to make a hard decision — to restructure, discard and merge departments, fire employees and do other unpleasant stuff. Let's consider the following model of a company.

There are n people working for the Large Software Company. Each person belongs to some department. Initially, each person works on his own project in his own department (thus, each company initially consists of n departments, one person in each).

However, harsh times have come to the company and the management had to hire a crisis manager who would rebuild the working process in order to boost efficiency. Let's use team(person) to represent a team where person person works. A crisis manager can make decisions of two types:

  1. Merge departments team(x) and team(y) into one large department containing all the employees of team(x) and team(y), where x and y (1 ≤ x, y ≤ n) — are numbers of two of some company employees. If team(x) matches team(y), then nothing happens.
  2. Merge departments team(x), team(x + 1), ..., team(y), where x and y (1 ≤ x ≤ y ≤ n) — the numbers of some two employees of the company.

At that the crisis manager can sometimes wonder whether employees x and y (1 ≤ x, y ≤ n) work at the same department.

Help the crisis manager and answer all of his queries.

Input

The first line of the input contains two integers n and q (1 ≤ n ≤ 200 000, 1 ≤ q ≤ 500 000) — the number of the employees of the company and the number of queries the crisis manager has.

Next q lines contain the queries of the crisis manager. Each query looks like type x y, where <image>. If type = 1 or type = 2, then the query represents the decision of a crisis manager about merging departments of the first and second types respectively. If type = 3, then your task is to determine whether employees x and y work at the same department. Note that x can be equal to y in the query of any type.

Output

For each question of type 3 print "YES" or "NO" (without the quotes), depending on whether the corresponding people work in the same department.

Examples

Input

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

Output

NO
YES
YES

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int fa[300010], nxt[300010];
int find(int x) {
  if (fa[x] != x) fa[x] = find(fa[x]);
  return fa[x];
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) fa[i] = i, nxt[i] = i + 1;
  while (m--) {
    int op, a, b;
    scanf("%d%d%d", &op, &a, &b);
    if (a > b) swap(a, b);
    if (op == 1) {
      int u = find(a), v = find(b);
      if (u == v) continue;
      fa[u] = v;
    } else if (op == 2) {
      for (int i = a, j = nxt[i]; j <= b; i = j, j = nxt[i]) {
        int u = find(i), v = find(j);
        nxt[i] = nxt[j];
        if (u == v) continue;
        fa[u] = v;
      }
    } else {
      if (find(a) == find(b))
        puts("YES");
      else
        puts("NO");
    }
  }
  return 0;
}

```


### Prompt

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

Arthur and Alexander are number busters. Today they've got a competition.

Arthur took a group of four integers a, b, w, x (0 ≤ b < w, 0 < x < w) and Alexander took integer с. Arthur and Alexander use distinct approaches to number bustings. Alexander is just a regular guy. Each second, he subtracts one from his number. In other words, he performs the assignment: c = c - 1. Arthur is a sophisticated guy. Each second Arthur performs a complex operation, described as follows: if b ≥ x, perform the assignment b = b - x, if b < x, then perform two consecutive assignments a = a - 1; b = w - (x - b).

You've got numbers a, b, w, x, c. Determine when Alexander gets ahead of Arthur if both guys start performing the operations at the same time. Assume that Alexander got ahead of Arthur if c ≤ a.

Input

The first line contains integers a, b, w, x, c (1 ≤ a ≤ 2·109, 1 ≤ w ≤ 1000, 0 ≤ b < w, 0 < x < w, 1 ≤ c ≤ 2·109).

Output

Print a single integer — the minimum time in seconds Alexander needs to get ahead of Arthur. You can prove that the described situation always occurs within the problem's limits.

Examples

Input

4 2 3 1 6

Output

2

Input

4 2 3 1 7

Output

4

Input

1 2 3 2 6

Output

13

Input

1 1 2 1 1

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b) {
  long long res = 1;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a;
    a = a * a;
  }
  return res;
}
int N, K;
long long a, b, w, x, C;
int in[2222];
int curMX;
bool check(long long mid) {
  a -= (b + mid * x) / w;
  C -= mid;
  if (C <= a) return 1;
  return 0;
}
long long _a, _b, _w, _x, _C;
int main() {
  cin >> _a >> _b >> _w >> _x >> _C;
  if (_C <= _a) {
    cout << 0 << endl;
    return 0;
  }
  long long low = -1, high = 200000000000001;
  while (low + 1 < high) {
    long long mid = (low + high) / 2;
    a = _a, b = _b, w = _w, x = _x, C = _C;
    b = w - b - 1;
    if (check(mid)) {
      high = mid;
    } else
      low = mid;
  }
  cout << high << endl;
  return 0;
}

```


### Prompt

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

One day two students, Grisha and Diana, found themselves in the university chemistry lab. In the lab the students found n test tubes with mercury numbered from 1 to n and decided to conduct an experiment.

The experiment consists of q steps. On each step, one of the following actions occurs:

  1. Diana pours all the contents from tube number pi and then pours there exactly xi liters of mercury.
  2. Let's consider all the ways to add vi liters of water into the tubes; for each way let's count the volume of liquid (water and mercury) in the tube with water with maximum amount of liquid; finally let's find the minimum among counted maximums. That is the number the students want to count. At that, the students don't actually pour the mercury. They perform calculations without changing the contents of the tubes.

Unfortunately, the calculations proved to be too complex and the students asked you to help them. Help them conduct the described experiment.

Input

The first line contains two integers n and q (1 ≤ n, q ≤ 105) — the number of tubes ans the number of experiment steps. The next line contains n space-separated integers: h1, h2, ..., hn (0 ≤ hi ≤ 109), where hi is the volume of mercury in the і-th tube at the beginning of the experiment.

The next q lines contain the game actions in the following format:

  * A line of form "1 pi xi" means an action of the first type (1 ≤ pi ≤ n; 0 ≤ xi ≤ 109).
  * A line of form "2 vi" means an action of the second type (1 ≤ vi ≤ 1015).

It is guaranteed that there is at least one action of the second type. It is guaranteed that all numbers that describe the experiment are integers.

Output

For each action of the second type print the calculated value. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4.

Examples

Input

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

Output

1.50000
1.66667

Input

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

Output

1.66667
1.00000
2.33333
2.66667

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
class fenwick {
 public:
  long long int F[300000];
  fenwick() { memset(F, 0, sizeof F); }
  void update(int x, long long int val) {
    while (x <= 250000) {
      F[x] += val;
      x += x & -x;
    }
  }
  long long int query(int x) {
    long long int res = 0;
    while (x) {
      res += F[x];
      x -= x & -x;
    }
    return res;
  }
} A, S;
int n, m;
long long int arr[200000];
map<long long int, int> yer;
pair<long long int, pair<long long int, long long int> > q[200000];
int f(double x) {
  x -= 1e-8;
  x = ceil(x);
  return yer.lower_bound((long long int)x)->second;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", arr + i);
    yer[arr[i]] = 1;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%lld", &q[i].first);
    if (q[i].first == 1) {
      scanf("%lld %lld", &q[i].second.first, &q[i].second.second);
      yer[q[i].second.second] = 1;
    } else
      scanf("%lld", &q[i].second.first);
  }
  int ind = 0;
  for (typeof(yer.begin()) it = yer.begin(); it != yer.end(); it++)
    it->second = ++ind;
  yer[1e18] = ++ind;
  for (int i = 1; i <= n; i++)
    A.update(f(arr[i]), arr[i]), S.update(f(arr[i]), 1);
  for (int i = 1; i <= m; i++) {
    if (q[i].first == 1) {
      A.update(f(arr[q[i].second.first]), -arr[q[i].second.first]),
          S.update(f(arr[q[i].second.first]), -1);
      arr[q[i].second.first] = q[i].second.second;
      A.update(f(arr[q[i].second.first]), arr[q[i].second.first]),
          S.update(f(arr[q[i].second.first]), 1);
    } else {
      double bas = 0.0, son = 1e18, orta;
      for (int iteration = 1; iteration <= 200; iteration++) {
        orta = (bas + son) / 2;
        if (orta * S.query(f(orta) - 1) - A.query(f(orta) - 1) >=
            q[i].second.first)
          son = orta;
        else
          bas = orta;
      }
      printf("%.12lf\n", bas);
    }
  }
}

```


### Prompt

Create a solution in Cpp for the following problem:

Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!

Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly k times more than the previous one. The value of k (k > 1) is a secret integer known only to them. It is also known that each thief's bag can carry at most n chocolates (if they intend to take more, the deal is cancelled) and that there were exactly four thieves involved.

Sadly, only the thieves know the value of n, but rumours say that the numbers of ways they could have taken the chocolates (for a fixed n, but not fixed k) is m. Two ways are considered different if one of the thieves (they should be numbered in the order they take chocolates) took different number of chocolates in them.

Mike want to track the thieves down, so he wants to know what their bags are and value of n will help him in that. Please find the smallest possible value of n or tell him that the rumors are false and there is no such n.

Input

The single line of input contains the integer m (1 ≤ m ≤ 1015) — the number of ways the thieves might steal the chocolates, as rumours say.

Output

Print the only integer n — the maximum amount of chocolates that thieves' bags can carry. If there are more than one n satisfying the rumors, print the smallest one.

If there is no such n for a false-rumoured m, print  - 1.

Examples

Input

1

Output

8

Input

8

Output

54

Input

10

Output

-1

Note

In the first sample case the smallest n that leads to exactly one way of stealing chocolates is n = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).

In the second sample case the smallest n that leads to exactly 8 ways is n = 54 with the possibilities: (1, 2, 4, 8), (1, 3, 9, 27), (2, 4, 8, 16), (2, 6, 18, 54), (3, 6, 12, 24), (4, 8, 16, 32), (5, 10, 20, 40), (6, 12, 24, 48).

There is no n leading to exactly 10 ways of stealing chocolates in the third sample case.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long m;
  cin >> m;
  long long low = 0LL;
  long long high = 1000000000000000000LL;
  long long ans = -1;
  while (low <= high) {
    long long mid = (low + high) / 2;
    long long re = 0LL;
    for (long long i = 2; i * i * i <= mid; i++) {
      re += mid / (i * i * i);
    }
    if (re < m) {
      low = mid + 1;
    } else {
      ans = mid;
      high = mid - 1;
    }
  }
  long long re = 0;
  for (long long i = 2; i * i * i <= ans; i++) {
    re += ans / (i * i * i);
  }
  if (re == m) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

<image>

Input

The input contains a single integer a (0 ≤ a ≤ 15).

Output

Output a single integer.

Example

Input

3

Output

13

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a, k1, k2, k3, k4;
int main() {
  scanf("%d", &a);
  k4 = a % 2;
  a /= 2;
  k3 = a % 2;
  a /= 2;
  k2 = a % 2;
  a /= 2;
  k1 = a;
  k1 = 1 - k1;
  if (k1) k2 = 1 - k2;
  if (k1 && k2) k3 = 1 - k3;
  if (k1 && k2 && k3) k4 = 1 - k4;
  printf("%d\n", k4 + 2 * k3 + 4 * k2 + 8 * k1);
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

For a positive integer n, we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by rev(n). For example, rev(123) = 321 and rev(4000) = 4.

You are given a positive integer D. How many positive integers N satisfy rev(N) = N + D?

Constraints

* D is an integer.
* 1 ≤ D < 10^9

Input

Input is given from Standard Input in the following format:

D

Output

Print the number of the positive integers N such that rev(N) = N + D.

Examples

Input

63

Output

2

Input

75

Output

0

Input

864197532

Output

1920

### Response

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using db = double;
#define pb push_back

ll d;
ll ans = 0;
ll p[19];
#define dig(x, i) ((x) / p[i] % 10)

map<int,int> pm, pf;

void dfs(ll s, int n, int i, ll mul) {
	if (i * 2 + 1 == n) {
		ans += !s * mul * 10;
		return;
	}
	if (i < n / 2) {
		ans += !s * mul;
		return;
	}
	if (i < 19 && abs(s) > p[i + 1])
		return;
	for (auto j : (i == n - 1 ? pf : pm)) if (i <= 17 || j.first == 0)
		dfs(s - j.first * (p[i] - p[n - 1 - i]), n, i - 1, mul * j.second);
}

int main() {
	cin >> d;

	for (int i = 0; i <= 9; ++i)
		for (int j = 0; j <= 9; ++j) {
			++pm[i - j];
			if (i)
				++pf[i - j];
		}

	p[0] = 1;
	for (int i = 1; i < 19; ++i)
		p[i] = p[i - 1] * 10;

	for (int i = 2; i <= 24; ++i)
		dfs(-d, i, i - 1, 1);

	cout << ans << endl;

	return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Eugene likes working with arrays. And today he needs your help in solving one challenging task.

An array c is a subarray of an array b if c can be obtained from b by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

Let's call a nonempty array good if for every nonempty subarray of this array, sum of the elements of this subarray is nonzero. For example, array [-1, 2, -3] is good, as all arrays [-1], [-1, 2], [-1, 2, -3], [2], [2, -3], [-3] have nonzero sums of elements. However, array [-1, 2, -1, -3] isn't good, as his subarray [-1, 2, -1] has sum of elements equal to 0.

Help Eugene to calculate the number of nonempty good subarrays of a given array a.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 2 × 10^5) — the length of array a.

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

Output

Output a single integer — the number of good subarrays of a.

Examples

Input

3
1 2 -3

Output

5

Input

3
41 -41 41

Output

3

Note

In the first sample, the following subarrays are good: [1], [1, 2], [2], [2, -3], [-3]. However, the subarray [1, 2, -3] isn't good, as its subarray [1, 2, -3] has sum of elements equal to 0.

In the second sample, three subarrays of size 1 are the only good subarrays. At the same time, the subarray [41, -41, 41] isn't good, as its subarray [41, -41] has sum of elements equal to 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[200009], b[200009], z[200009];
long long sum[200009];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), sum[i] = sum[i - 1] + a[i];
  map<long long, int> mp;
  long long ans = 0;
  int l = 0;
  mp[0] = 1;
  for (int i = 1; i <= n; i++) {
    while (mp[sum[i]]) mp[sum[l++]]--;
    mp[sum[i]]++;
    ans += (i - l);
  }
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Being bored of exploring the Moon over and over again Wall-B decided to explore something he is made of — binary numbers. He took a binary number and decided to count how many times different substrings of length two appeared. He stored those values in c_{00}, c_{01}, c_{10} and c_{11}, representing how many times substrings 00, 01, 10 and 11 appear in the number respectively. For example:

10111100 → c_{00} = 1, \ c_{01} = 1,\ c_{10} = 2,\ c_{11} = 3

10000 → c_{00} = 3,\ c_{01} = 0,\ c_{10} = 1,\ c_{11} = 0

10101001 → c_{00} = 1,\ c_{01} = 3,\ c_{10} = 3,\ c_{11} = 0

1 → c_{00} = 0,\ c_{01} = 0,\ c_{10} = 0,\ c_{11} = 0

Wall-B noticed that there can be multiple binary numbers satisfying the same c_{00}, c_{01}, c_{10} and c_{11} constraints. Because of that he wanted to count how many binary numbers satisfy the constraints c_{xy} given the interval [A, B]. Unfortunately, his processing power wasn't strong enough to handle large intervals he was curious about. Can you help him? Since this number can be large print it modulo 10^9 + 7.

Input

First two lines contain two positive binary numbers A and B (1 ≤ A ≤ B < 2^{100 000}), representing the start and the end of the interval respectively. Binary numbers A and B have no leading zeroes.

Next four lines contain decimal numbers c_{00}, c_{01}, c_{10} and c_{11} (0 ≤ c_{00}, c_{01}, c_{10}, c_{11} ≤ 100 000) representing the count of two-digit substrings 00, 01, 10 and 11 respectively.

Output

Output one integer number representing how many binary numbers in the interval [A, B] satisfy the constraints mod 10^9 + 7.

Examples

Input

10
1001
0
0
1
1

Output

1

Input

10
10001
1
2
3
4

Output

0

Note

Example 1: The binary numbers in the interval [10,1001] are 10,11,100,101,110,111,1000,1001. Only number 110 satisfies the constraints: c_{00} = 0, c_{01} = 0, c_{10} = 1, c_{11} = 1.

Example 2: No number in the interval satisfies the constraints

### 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 = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 1000000007) {
  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 = 1000000007) {
  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; }
char a[100035], b[100035];
int c[5];
int fac[100035], inv[100035];
void initfac(int n) {
  fac[0] = inv[0] = 1;
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    fac[i] = (long long)fac[i - 1] * i % 1000000007;
    inv[i] = fastPow(fac[i], 1000000007 - 2);
  }
}
int C(int n, int m) {
  if (n < m) return 0;
  return (long long)fac[n] * inv[m] % 1000000007 * inv[n - m] % 1000000007;
}
int cal(int len, int st) {
  int all = c[0] + c[1] + c[2] + c[3];
  if (len - 1 != all) return 0;
  if (abs(c[1] - c[2]) > 1) return 0;
  int tmp = 0;
  if (c[1] == c[2]) {
    if (c[1] == 0) {
      if (c[0] == 0 && st == 1) return 1;
      if (c[3] == 0 && st == 0) return 1;
      return 0;
    }
    int ones = c[2] + 1;
    if (st == 1)
      addmod(tmp, (long long)C(c[3] + ones - 1, ones - 1) *
                      C(c[0] + ones - 2, ones - 2) % 1000000007);
    if (st == 0)
      addmod(tmp, (long long)C(c[0] + ones - 1, ones - 1) *
                      C(c[3] + ones - 2, ones - 2) % 1000000007);
  } else {
    if (c[1] + 1 == c[2]) {
      if (st != 1) return 0;
    } else {
      assert(c[2] + 1 == c[1]);
      if (st != 0) return 0;
    }
    int ones = max(c[1], c[2]);
    addmod(tmp, (long long)C(c[3] + ones - 1, ones - 1) *
                    C(c[0] + ones - 1, ones - 1) % 1000000007);
  }
  return tmp;
}
int N;
int dfs(char* s, int i, bool hd, int pre) {
  if (i > N) return 0;
  int len = N - i + 1;
  int tmp = 0;
  int num = s[i] - '0';
  if (num == 1) {
    if (hd) {
      c[pre * 2 + 1]--;
      addmod(tmp, dfs(s, i + 1, 1, 1));
      c[pre * 2 + 1]++;
    } else {
      addmod(tmp, dfs(s, i + 1, 1, 1));
    }
    if (hd) {
      c[pre * 2]--;
      addmod(tmp, cal(len, 0));
      c[pre * 2]++;
    } else {
      int all = c[0] + c[1] + c[2] + c[3];
      if (all + 1 < len) addmod(tmp, cal(all + 1, 1));
    }
  } else {
    if (hd) {
      c[pre * 2]--;
      addmod(tmp, dfs(s, i + 1, 1, 0));
      c[pre * 2]++;
    } else
      addmod(tmp, dfs(s, i + 1, 0, 0));
  }
  return tmp;
}
void fmain(int tid) {
  scanf("%s%s", a + 1, b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  for (int(i) = 0; (i) < (int)(4); (i)++) scanf("%d", c + i);
  initfac(m + 5);
  N = n;
  int A = dfs(a, 1, 0, 0);
  int pos = m;
  while (pos && b[pos] == '1') pos--;
  if (pos == 0) {
    b[0] = '0';
    for (int(i) = 1; (i) <= (int)(m); (i)++) b[i + 1] = '1';
    m++;
  } else {
    b[pos] = '1';
    for (int i = pos + 1; i <= n; i++) b[i] = '0';
  }
  N = m;
  int B = dfs(b, 1, 0, 0);
  addmod(B, 1000000007 - A);
  printf("%d\n", B);
}
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:

Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.

There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer takes a special basket, where he puts exactly qi items he buys. Under the terms of the discount system, in addition to the items in the cart the customer can receive at most two items from the supermarket for free. The number of the "free items" (0, 1 or 2) to give is selected by the customer. The only condition imposed on the selected "free items" is as follows: each of them mustn't be more expensive than the cheapest item out of the qi items in the cart.

Maxim now needs to buy n items in the shop. Count the minimum sum of money that Maxim needs to buy them, if he use the discount system optimally well.

Please assume that the supermarket has enough carts for any actions. Maxim can use the same discount multiple times. Of course, Maxim can buy items without any discounts.

Input

The first line contains integer m (1 ≤ m ≤ 105) — the number of discount types. The second line contains m integers: q1, q2, ..., qm (1 ≤ qi ≤ 105).

The third line contains integer n (1 ≤ n ≤ 105) — the number of items Maxim needs. The fourth line contains n integers: a1, a2, ..., an (1 ≤ ai ≤ 104) — the items' prices.

The numbers in the lines are separated by single spaces.

Output

In a single line print a single integer — the answer to the problem.

Examples

Input

1
2
4
50 50 100 100

Output

200

Input

2
2 3
5
50 50 50 50 50

Output

150

Input

1
1
7
1 1 1 1 1 1 1

Output

3

Note

In the first sample Maxim needs to buy two items that cost 100 and get a discount for two free items that cost 50. In that case, Maxim is going to pay 200.

In the second sample the best strategy for Maxim is to buy 3 items and get 2 items for free using the discount. In that case, Maxim is going to pay 150.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long a[N];
long long b[N];
long long res = 0;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> m;
  long long c;
  for (long long i = 1; i <= m; i++) {
    cin >> b[i];
  }
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  sort(b + 1, b + m + 1);
  long long cnt = 0;
  long long num = b[1];
  for (long long i = n; i >= 1;) {
    cnt++;
    res += a[i];
    if (cnt == num) {
      cnt = 0;
      i -= 2;
    }
    i--;
  }
  cout << res << endl;
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

You're given a tree with n vertices.

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

Input

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

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

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

Output

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

Examples

Input

4
2 4
4 1
3 1

Output

1

Input

3
1 2
1 3

Output

-1

Input

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

Output

4

Input

2
1 2

Output

0

Note

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
std::vector<int> g[100005];
int subt[100005];
bool vis[100005];
int n, cnt;
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first == b.first) return a.second > b.second;
  return a.first < b.first;
}
void dfs(int u, int p) {
  subt[u] = 1;
  vis[u] = 1;
  for (auto v : g[u]) {
    if (!vis[v]) {
      dfs(v, u);
      if (subt[v] % 2 == 0 && (n - subt[v]) % 2 == 0)
        cnt++, n - subt[v];
      else
        subt[u] += subt[v];
    }
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, 0);
  if (n % 2 != 0 && cnt == 0) {
    cout << -1;
    return 0;
  } else
    cout << cnt;
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.

For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:

  1. He looks through all the coins from left to right;
  2. If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.

Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.

Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.

The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.

Input

The first line contains single integer n (1 ≤ n ≤ 300 000) — number of coins that Sasha puts behind Dima.

Second line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n) — positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p1, then coin located at position p2 and so on. Coins are numbered from left to right.

Output

Print n + 1 numbers a0, a1, ..., an, where a0 is a hardness of ordering at the beginning, a1 is a hardness of ordering after the first replacement and so on.

Examples

Input

4
1 3 4 2

Output

1 2 3 2 1

Input

8
6 8 3 4 7 2 1 5

Output

1 2 2 3 4 3 4 5 1

Note

Let's denote as O coin out of circulation, and as X — coin is circulation.

At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.

After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.

XOOO →  OOOX

After replacement of the third coin, Dima's actions look this way:

XOXO →  OXOX →  OOXX

After replacement of the fourth coin, Dima's actions look this way:

XOXX →  OXXX

Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, ar[300005], temp, right_id;
  memset(ar, 0, sizeof(ar));
  scanf("%d", &n);
  right_id = n;
  printf("1 ");
  for (i = 1; i <= n; i++) {
    scanf("%d", &temp);
    ar[temp] = 1;
    while (ar[right_id]) right_id--;
    printf("%d ", i - n + right_id + 1);
  }
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

You are given a bracket sequence s (not necessarily a regular one). A bracket sequence is a string containing only characters '(' and ')'.

A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.

Your problem is to calculate the number of regular bracket sequences of length 2n containing the given bracket sequence s as a substring (consecutive sequence of characters) modulo 10^9+7 (1000000007).

Input

The first line of the input contains one integer n (1 ≤ n ≤ 100) — the half-length of the resulting regular bracket sequences (the resulting sequences must have length equal to 2n).

The second line of the input contains one string s (1 ≤ |s| ≤ 200) — the string s that should be a substring in each of the resulting regular bracket sequences (|s| is the length of s).

Output

Print only one integer — the number of regular bracket sequences containing the given bracket sequence s as a substring. Since this number can be huge, print it modulo 10^9+7 (1000000007).

Examples

Input

5
()))()

Output

5

Input

3
(()

Output

4

Input

2
(((

Output

0

Note

All regular bracket sequences satisfying the conditions above for the first example:

  * "(((()))())";
  * "((()()))()";
  * "((()))()()";
  * "(()(()))()";
  * "()((()))()".

All regular bracket sequences satisfying the conditions above for the second example:

  * "((()))";
  * "(()())";
  * "(())()";
  * "()(())".

And there is no regular bracket sequences of length 4 containing "(((" as a substring in the third example.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
long long DP[202][402][402];
string s;
int n;
long long POS[402];
long long solve(int pf, int pos, int deg) {
  if (DP[pf][pos][deg] != -1) return DP[pf][pos][deg];
  if (deg < 0) return 0;
  if (pos >= 2 * n) return (pf >= s.size() && deg == 0 ? 1 : 0);
  if (pf >= s.size()) {
    return DP[pf][pos][deg] =
               (solve(pf, pos + 1, deg + 1) + solve(pf, pos + 1, deg - 1)) % M;
  } else {
    long long ats = 0;
    if (s[pf] == '(') {
      ats = (ats + solve(pf + 1, pos + 1, deg + 1) +
             solve(POS[pf], pos + 1, deg - 1)) %
            M;
    } else {
      ats = (ats + solve(POS[pf], pos + 1, deg + 1) +
             solve(pf + 1, pos + 1, deg - 1)) %
            M;
    }
    return DP[pf][pos][deg] = ats;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> s;
  for (int i = 0; i < 202; i++)
    for (int j = 0; j < 402; j++)
      for (int k = 0; k < 402; k++) DP[i][j][k] = -1;
  for (int i = 1; i < s.size(); i++) {
    for (int j = 0; j <= i; j++) {
      string z = s.substr(j, i - j) + (s[i] == '(' ? ")" : "(");
      if (s.find(z) == 0) {
        POS[i] = z.size();
        break;
      }
    }
  }
  cout << solve(0, 0, 0);
}

```


### Prompt

Generate a cpp solution to the following problem:

There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i.

The N ants have just started walking. For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2. Every ant walks at a constant speed of 1 per second. Sometimes, two ants bump into each other. Each of these two ants will then turn around and start walking in the opposite direction.

For each ant, find its position after T seconds.

Constraints

* All input values are integers.
* 1 \leq N \leq 10^5
* 1 \leq L \leq 10^9
* 1 \leq T \leq 10^9
* 0 \leq X_1 < X_2 < ... < X_N \leq L - 1
* 1 \leq W_i \leq 2

Input

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

N L T
X_1 W_1
X_2 W_2
:
X_N W_N

Output

Print N lines. The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive.

Examples

Input

3 8 3
0 1
3 2
6 1

Output

1
3
0

Input

4 20 9
7 2
9 1
12 1
18 1

Output

7
18
18
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, l, t;
#define LL long long
const int N = 200000;
int xi[N], dir[N], xx[N];
int main()
{
//    freopen("input.txt","r",stdin);
	cin >> n >> l >> t;
    LL c = 0;
    for (int i = 0; i < n; ++ i)
    {
        cin >> xi[i] >> dir[i];
        if (dir[i] == 2) dir[i] = -1;
        int nx = xi[i] + t * dir[i];
        c += (nx > 0? nx / l: (nx - l + 1) / l);
        xx[i] = (nx % l + l) % l;
    }
    sort(xx, xx + n);
    for (int i = 0; i < n; ++ i)
        cout << xx[((i + c) % n + n) % n] << "\n";
}
```


### Prompt

Create a solution in Cpp for the following problem:

In the Isle of Guernsey there are n different types of coins. For each i (1 ≤ i ≤ n), coin of type i is worth ai cents. It is possible that ai = aj for some i and j (i ≠ j).

Bessie has some set of these coins totaling t cents. She tells Jessie q pairs of integers. For each i (1 ≤ i ≤ q), the pair bi, ci tells Jessie that Bessie has a strictly greater number of coins of type bi than coins of type ci. It is known that all bi are distinct and all ci are distinct.

Help Jessie find the number of possible combinations of coins Bessie could have. Two combinations are considered different if there is some i (1 ≤ i ≤ n), such that the number of coins Bessie has of type i is different in the two combinations. Since the answer can be very large, output it modulo 1000000007 (109 + 7).

If there are no possible combinations of coins totaling t cents that satisfy Bessie's conditions, output 0.

Input

The first line contains three space-separated integers, n, q and t (1 ≤ n ≤ 300; 0 ≤ q ≤ n; 1 ≤ t ≤ 105). The second line contains n space separated integers, a1, a2, ..., an (1 ≤ ai ≤ 105). The next q lines each contain two distinct space-separated integers, bi and ci (1 ≤ bi, ci ≤ n; bi ≠ ci).

It's guaranteed that all bi are distinct and all ci are distinct.

Output

A single integer, the number of valid coin combinations that Bessie could have, modulo 1000000007 (109 + 7).

Examples

Input

4 2 17
3 1 2 5
4 2
3 4

Output

3

Input

3 2 6
3 1 1
1 2
2 3

Output

0

Input

3 2 10
1 2 3
1 2
2 1

Output

0

Note

For the first sample, the following 3 combinations give a total of 17 cents and satisfy the given conditions: {0 of type 1, 1 of type 2, 3 of type 3, 2 of type 4}, {0, 0, 6, 1}, {2, 0, 3, 1}.

No other combinations exist. Note that even though 4 occurs in both bi and ci,  the problem conditions are still satisfied because all bi are distinct and all ci are distinct.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, q, t;
  cin >> n >> q >> t;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> nxt(n + 1, -1);
  vector<int> source(n + 1, 1);
  for (int i = 0; i < q; i++) {
    int u, v;
    cin >> u >> v;
    source[u] = 0;
    nxt[v] = u;
  }
  vector<long long> cost(n + 1, 0);
  vector<int> vis(n + 1, 0);
  for (int u = 1; u <= n; u++) {
    if (source[u] == 0) continue;
    vector<int> dag;
    int cur = u;
    while (cur != -1) {
      vis[cur] = 1;
      dag.push_back(cur);
      cur = nxt[cur];
    }
    long long sum = 0;
    for (int j = int(dag.size()) - 1; j >= 0; j--) {
      sum += a[dag[j]];
      cost[dag[j]] = sum;
      if (j != 0) t -= sum;
    }
  }
  if (t < 0 or accumulate(begin(vis), end(vis), 0) != n) {
    cout << 0 << '\n';
    return (0);
  }
  vector<int> dp(t + 1, 0);
  const int mod = 1e9 + 7;
  dp[0] = 1;
  for (int u = 1; u <= n; u++) {
    long long add = cost[u];
    for (long long z = 0; z + add <= t; z++) {
      dp[z + add] += dp[z];
      if (dp[z + add] >= mod) dp[z + add] -= mod;
    }
  }
  cout << dp[t] << '\n';
  return (0);
}

```


### Prompt

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

Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.

However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:

  1. one resistor;
  2. an element and one resistor plugged in sequence;
  3. an element and one resistor plugged in parallel.

<image>

With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals <image>. In this case Re equals the resistance of the element being connected.

Mike needs to assemble an element with a resistance equal to the fraction <image>. Determine the smallest possible number of resistors he needs to make such an element.

Input

The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction <image> is irreducible. It is guaranteed that a solution always exists.

Output

Print a single number — the answer to the problem.

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

Examples

Input

1 1

Output

1

Input

3 2

Output

3

Input

199 200

Output

200

Note

In the first sample, one resistor is enough.

In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <image>. We cannot make this element using two resistors.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b;
  cin >> a >> b;
  long long int ans = 0;
  while (true) {
    if (a == 1 || b == 1) {
      cout << ans + max(a, b);
      return 0;
    }
    if (a > b) {
      ans += (a / b);
      a = a - ((a / b) * b);
    }
    if (a == 1) {
      cout << ans + b;
      return 0;
    }
    if (b > a) {
      ans += (b / a);
      b = b - ((b / a) * a);
    }
    if (b == 1) {
      cout << ans + a;
      return 0;
    }
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

There are n water tanks in a row, i-th of them contains a_i liters of water. The tanks are numbered from 1 to n from left to right.

You can perform the following operation: choose some subsegment [l, r] (1≤ l ≤ r ≤ n), and redistribute water in tanks l, l+1, ..., r evenly. In other words, replace each of a_l, a_{l+1}, ..., a_r by \frac{a_l + a_{l+1} + ... + a_r}{r-l+1}. For example, if for volumes [1, 3, 6, 7] you choose l = 2, r = 3, new volumes of water will be [1, 4.5, 4.5, 7]. You can perform this operation any number of times.

What is the lexicographically smallest sequence of volumes of water that you can achieve?

As a reminder:

A sequence a is lexicographically smaller than a sequence b of the same length if and only if the following holds: in the first (leftmost) position where a and b differ, the sequence a has a smaller element than the corresponding element in b.

Input

The first line contains an integer n (1 ≤ n ≤ 10^6) — the number of water tanks.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6) — initial volumes of water in the water tanks, in liters.

Because of large input, reading input as doubles is not recommended.

Output

Print the lexicographically smallest sequence you can get. In the i-th line print the final volume of water in the i-th tank.

Your answer is considered correct if the absolute or relative error of each a_i does not exceed 10^{-9}.

Formally, let your answer be a_1, a_2, ..., a_n, and the jury's answer be b_1, b_2, ..., b_n. Your answer is accepted if and only if \frac{|a_i - b_i|}{max{(1, |b_i|)}} ≤ 10^{-9} for each i.

Examples

Input

4
7 5 5 7

Output

5.666666667
5.666666667
5.666666667
7.000000000

Input

5
7 8 8 10 12

Output

7.000000000
8.000000000
8.000000000
10.000000000
12.000000000

Input

10
3 9 5 5 1 7 5 3 8 7

Output

3.000000000
5.000000000
5.000000000
5.000000000
5.000000000
5.000000000
5.000000000
5.000000000
7.500000000
7.500000000

Note

In the first sample, you can get the sequence by applying the operation for subsegment [1, 3].

In the second sample, you can't get any lexicographically smaller sequence.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename elemType>
inline void Read(elemType &T) {
  elemType X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  T = (w ? -X : X);
}
struct Node {
  long long Len, Sum;
  double Ave;
};
stack<Node> S;
vector<double> Ans;
int N;
inline void Push(long long x) {
  Node Cur;
  Cur.Sum = x;
  Cur.Len = 1;
  Cur.Ave = x;
  while (!S.empty()) {
    double CurAve =
        (double)(S.top().Sum + Cur.Sum) / (double)(S.top().Len + Cur.Len);
    if (CurAve > S.top().Ave) break;
    Cur.Sum += S.top().Sum;
    Cur.Len += S.top().Len;
    Cur.Ave = CurAve;
    S.pop();
  }
  S.push(Cur);
}
int main() {
  Read(N);
  for (register int i = 1; i <= N; ++i) {
    long long x;
    Read(x);
    Push(x);
  }
  while (!S.empty()) {
    for (register int i = 1; i <= S.top().Len; ++i) Ans.push_back(S.top().Ave);
    S.pop();
  }
  for (register int i = Ans.size() - 1; i >= 0; --i) printf("%.9f\n", Ans[i]);
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Bearland is a dangerous place. Limak can’t travel on foot. Instead, he has k magic teleportation stones. Each stone can be used at most once. The i-th stone allows to teleport to a point (axi, ayi). Limak can use stones in any order.

There are n monsters in Bearland. The i-th of them stands at (mxi, myi).

The given k + n points are pairwise distinct.

After each teleportation, Limak can shoot an arrow in some direction. An arrow will hit the first monster in the chosen direction. Then, both an arrow and a monster disappear. It’s dangerous to stay in one place for long, so Limak can shoot only one arrow from one place.

A monster should be afraid if it’s possible that Limak will hit it. How many monsters should be afraid of Limak?

Input

The first line of the input contains two integers k and n (1 ≤ k ≤ 7, 1 ≤ n ≤ 1000) — the number of stones and the number of monsters.

The i-th of following k lines contains two integers axi and ayi ( - 109 ≤ axi, ayi ≤ 109) — coordinates to which Limak can teleport using the i-th stone.

The i-th of last n lines contains two integers mxi and myi ( - 109 ≤ mxi, myi ≤ 109) — coordinates of the i-th monster.

The given k + n points are pairwise distinct.

Output

Print the number of monsters which should be afraid of Limak.

Examples

Input

2 4
-2 -1
4 5
4 2
2 1
4 -1
1 -1

Output

3

Input

3 8
10 20
0 0
20 40
300 600
30 60
170 340
50 100
28 56
90 180
-4 -8
-1 -2

Output

5

Note

In the first sample, there are two stones and four monsters. Stones allow to teleport to points ( - 2, - 1) and (4, 5), marked blue in the drawing below. Monsters are at (4, 2), (2, 1), (4, - 1) and (1, - 1), marked red. A monster at (4, - 1) shouldn't be afraid because it's impossible that Limak will hit it with an arrow. Other three monsters can be hit and thus the answer is 3.

<image>

In the second sample, five monsters should be afraid. Safe monsters are those at (300, 600), (170, 340) and (90, 180).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[10], b[1010];
vector<int> e[10][1010], tmp;
int k, n, p[10], pos;
bool vis[1010], ok[1010];
bool check(pair<int, int> x, pair<int, int> y, pair<int, int> z) {
  if (x.first < min(y.first, z.first) || x.first > max(y.first, z.first))
    return false;
  if (x.second < min(y.second, z.second) || x.second > max(y.second, z.second))
    return false;
  return 1ll * (y.second - x.second) * (z.first - x.first) ==
         1ll * (z.second - x.second) * (y.first - x.first);
}
bool dfs(int x) {
  if (pos > k) return false;
  for (int y : e[p[pos]][x]) {
    if (!vis[y]) {
      ++pos;
      if (!dfs(y)) return false;
    }
  }
  tmp.push_back(x), vis[x] = true;
  return true;
}
int main() {
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= k; i++) scanf("%d%d", &a[i].first, &a[i].second);
  for (int i = 1; i <= n; i++) scanf("%d%d", &b[i].first, &b[i].second);
  for (int i = 1; i <= k; i++)
    for (int j = 1; j <= n; j++) {
      for (int l = 1; l <= n; l++) {
        if (j == l) continue;
        if (check(b[l], a[i], b[j])) e[i][j].push_back(l);
        if ((int)e[i][j].size() == k) break;
      }
    }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) p[j] = j;
    do {
      while (!tmp.empty()) vis[tmp.back()] = 0, tmp.pop_back();
      pos = 1;
      if (dfs(i)) {
        res++;
        break;
      }
    } while (next_permutation(p + 1, p + k + 1));
  }
  printf("%d\n", res);
  return 0;
}

```


### Prompt

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

You want to go on a trip with a friend. However, friends who have a habit of spending money cannot easily save travel expenses. I don't know when my friends will go on a trip if they continue their current lives. So, if you want to travel early, you decide to create a program to help your friends save in a planned manner.

If you have a friend's pocket money of M yen and the money you spend in that month is N yen, you will save (M --N) yen in that month. Create a program that inputs the monthly income and expenditure information M and N and outputs the number of months it takes for the savings amount to reach the travel cost L. However, if your savings do not reach your travel expenses after 12 months, print NA.

Input

A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:

L
M1 N1
M2 N2
::
M12 N12

The first line gives the travel cost L (1 ≤ L ≤ 1000000, integer). The next 12 lines are given the balance information for the i month, Mi, Ni (0 ≤ Mi, Ni ≤ 100000, Ni ≤ Mi, integer).

The number of datasets does not exceed 1000.

Output

For each input dataset, print the number of months it takes for your savings to reach your travel costs on a single line.

Example

Input

10000
5000 3150
5000 5000
0 0
5000 1050
5000 3980
5000 210
5000 5000
5000 5000
0 0
5000 2100
5000 2100
5000 2100
29170
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 70831
0

Output

6
NA

### Response

```cpp
#include <stdio.h>
int l, m, n;
int main() {
	while (true) {
		scanf("%d", &l);
		if (l == 0) break;
		bool flag = false;
		for (int i = 0; i < 12; i++) {
			scanf("%d%d", &m, &n);
			l -= (m - n);
			if (l <= 0 && !flag) {
				printf("%d\n", i + 1); flag = true;
			}
		}
		if (!flag) printf("NA\n");
	}
	return 0;
}
```