### Prompt

Please formulate a Cpp solution to the following problem:

Alice and Bob are playing a game. The game involves splitting up game pieces into two teams. There are n pieces, and the i-th piece has a strength pi.

The way to split up game pieces is split into several steps:

  1. First, Alice will split the pieces into two different groups A and B. This can be seen as writing the assignment of teams of a piece in an n character string, where each character is A or B.
  2. Bob will then choose an arbitrary prefix or suffix of the string, and flip each character in that suffix (i.e. change A to B and B to A). He can do this step at most once.
  3. Alice will get all the pieces marked A and Bob will get all the pieces marked B.

The strength of a player is then the sum of strengths of the pieces in the group.

Given Alice's initial split into two teams, help Bob determine an optimal strategy. Return the maximum strength he can achieve.

Input

The first line contains integer n (1 ≤ n ≤ 5·105) — the number of game pieces.

The second line contains n integers pi (1 ≤ pi ≤ 109) — the strength of the i-th piece.

The third line contains n characters A or B — the assignment of teams after the first step (after Alice's step).

Output

Print the only integer a — the maximum strength Bob can achieve.

Examples

Input

5
1 2 3 4 5
ABABA

Output

11

Input

5
1 2 3 4 5
AAAAA

Output

15

Input

1
1
B

Output

1

Note

In the first sample Bob should flip the suffix of length one.

In the second sample Bob should flip the prefix or the suffix (here it is the same) of length 5.

In the third sample Bob should do nothing.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
map<string, int> mapik;
vector<string> vect;
int _tempik = 0;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  string s;
  cin >> s;
  vector<pair<long long, long long>> sum(n + 1);
  vector<pair<long long, long long>> obr(n + 1);
  sum[0] = make_pair(0, 0);
  obr[0] = make_pair(0, 0);
  for (int i = 0; i < n; i++) {
    sum[i + 1] = sum[i];
    obr[i + 1] = obr[i];
    if (s[i] == 'A') {
      sum[i + 1].first += a[i];
    } else {
      sum[i + 1].second += a[i];
    }
    if (s[n - 1 - i] == 'A') {
      obr[i + 1].first += a[n - 1 - i];
    } else {
      obr[i + 1].second += a[n - 1 - i];
    }
  }
  pair<long long, long long> res = sum[n];
  long long ans = res.second;
  for (int i = 1; i <= n; i++) {
    pair<long long, long long> curres = res;
    curres = make_pair(res.first - sum[i].first + sum[i].second,
                       res.second - sum[i].second + sum[i].first);
    ans = max(curres.second, ans);
    curres = res;
    curres = make_pair(res.first - obr[i].first + obr[i].second,
                       res.second - obr[i].second + obr[i].first);
    ans = max(curres.second, ans);
  }
  cout << ans;
  return 0;
}

```


### Prompt

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

Taro is addicted to a novel. The novel has n volumes in total, and each volume has a different thickness. Taro likes this novel so much that he wants to buy a bookshelf dedicated to it. However, if you put a large bookshelf in the room, it will be quite small, so you have to devise to make the width of the bookshelf as small as possible. When I measured the height from the floor to the ceiling, I found that an m-level bookshelf could be placed. So, how can we divide the n volumes of novels to minimize the width of the bookshelf in m columns? Taro is particular about it, and the novels to be stored in each column must be arranged in the order of the volume numbers. ..

Enter the number of bookshelves, the number of volumes of the novel, and the thickness of each book as input, and create a program to find the width of the bookshelf that has the smallest width that can accommodate all volumes in order from one volume. However, the size of the bookshelf frame is not included in the width.

<image>

Input

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

m n
w1
w2
::
wn

The first line gives m (1 ≤ m ≤ 20) the number of bookshelves that can be placed in the room and n (1 ≤ n ≤ 100) the number of volumes in the novel. The next n lines are given the integer wi (1 ≤ wi ≤ 1000000), which represents the thickness of the book in Volume i.

However, the width of the bookshelf shall not exceed 1500000.

The number of datasets does not exceed 50.

Output

Outputs the minimum bookshelf width for each dataset on one line.

Example

Input

3 9
500
300
800
200
100
600
900
700
400
4 3
1000
1000
1000
0 0

Output

1800
1000

### Response

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

int n, m, max_a;
int a[100];

bool check(int k) {
	int num = 1, sum = 0;
	for(int i = 0; i < n; i++) {
		sum += a[i];
		if(sum > k) {
			num++;
			sum = a[i];
		}
	}
	return num <= m;
}

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

	while(cin >> m >> n, m) {
		for(int i = 0; i < n; i++) {
			cin >> a[i];
		}
		max_a = *max_element(a, a + n);

		int ng = max_a - 1, ok = max_a * n;
		while(abs(ng - ok) > 1) {
			int mid = (ng + ok) / 2;
			if(check(mid)) ok = mid;
			else ng = mid;
		}

		cout << ok << endl;
	}
}
```


### Prompt

Generate a cpp solution to the following problem:

<image>

My grandmother uses a balance. The balance will balance if you place the same size on both of the two dishes, otherwise it will tilt to the heavier side. The weights of the 10 weights are 1g, 2g, 4g, 8g, 16g, 32g, 64g, 128g, 256g, 512g in order of lightness.

My grandmother says, "Weigh up to about 1 kg in grams." "Then, try to weigh the juice here," and my grandmother put the juice on the left plate and the 8g, 64g, and 128g weights on the right plate to balance. Then he answered, "The total weight is 200g, so the juice is 200g. How is it correct?"

Since the weight of the item to be placed on the left plate is given, create a program that outputs the weight to be placed on the right plate in order of lightness when balancing with the item of the weight given by the balance. However, the weight of the item to be weighed shall be less than or equal to the total weight of all weights (= 1023g).

Hint

The weight of the weight is 2 to the nth power (n = 0, 1, .... 9) g.

Input

Given multiple datasets. For each dataset, the weight of the item to be placed on the left plate is given in one line. Please process until the end of the input. The number of datasets does not exceed 50.

Output

For each data set, separate the weights (ascending order) to be placed on the right plate with one blank and output them on one line.

Example

Input

5
7
127

Output

1 4
1 2 4
1 2 4 8 16 32 64

### Response

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

int main()
{
	int w;

	while (cin >> w) {
		int i = 0;
		bool f = 0;
		while ((1 << i) <= w) {
			if ((1 << i) & w) {
				if (f)
					cout << " ";
				else
					f = 1;

				cout << (1 << i);
			}

			i++;
		}

		cout << endl;
	}

	return 0;
}

```


### Prompt

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

Andrewid the Android is a galaxy-known detective. Now he does not investigate any case and is eating chocolate out of boredom.

A bar of chocolate can be presented as an n × n table, where each cell represents one piece of chocolate. The columns of the table are numbered from 1 to n from left to right and the rows are numbered from top to bottom. Let's call the anti-diagonal to be a diagonal that goes the lower left corner to the upper right corner of the table. First Andrewid eats all the pieces lying below the anti-diagonal. Then he performs the following q actions with the remaining triangular part: first, he chooses a piece on the anti-diagonal and either direction 'up' or 'left', and then he begins to eat all the pieces starting from the selected cell, moving in the selected direction until he reaches the already eaten piece or chocolate bar edge.

After each action, he wants to know how many pieces he ate as a result of this action.

Input

The first line contains integers n (1 ≤ n ≤ 109) and q (1 ≤ q ≤ 2·105) — the size of the chocolate bar and the number of actions.

Next q lines contain the descriptions of the actions: the i-th of them contains numbers xi and yi (1 ≤ xi, yi ≤ n, xi + yi = n + 1) — the numbers of the column and row of the chosen cell and the character that represents the direction (L — left, U — up).

Output

Print q lines, the i-th of them should contain the number of eaten pieces as a result of the i-th action.

Examples

Input

6 5
3 4 U
6 1 L
2 5 L
1 6 U
4 3 U

Output

4
3
2
1
2

Input

10 6
2 9 U
10 1 U
1 10 U
8 3 L
10 1 L
6 5 U

Output

9
1
10
6
0
2

Note

Pictures to the sample tests:

<image>

The pieces that were eaten in the same action are painted the same color. The pieces lying on the anti-diagonal contain the numbers of the action as a result of which these pieces were eaten.

In the second sample test the Andrewid tries to start eating chocolate for the second time during his fifth action, starting from the cell at the intersection of the 10-th column and the 1-st row, but this cell is already empty, so he does not eat anything.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
set<pair<int, int> > s;
set<pair<int, int> >::iterator it;
int n, m;
int x[maxn];
int y[maxn];
char c[maxn];
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    s.clear();
    memset(x, 0, sizeof(x));
    memset(y, 0, sizeof(y));
    memset(c, 0, sizeof(c));
    s.insert(make_pair(0, 0));
    s.insert(make_pair(n + 1, m + 1));
    for (int i = 1; i <= m; i++) {
      scanf("%d %d %c", &x[i], &y[i], &c[i]);
      if (c[i] == 'U') {
        it = s.lower_bound(make_pair(x[i], -1));
        if (it->first == x[i])
          printf("0\n");
        else {
          s.insert(make_pair(x[i], i));
          printf("%d\n", y[i] - y[it->second]);
          y[i] = y[it->second];
        }
      } else {
        it = s.upper_bound(make_pair(x[i], m + 1));
        it--;
        if (it->first == x[i])
          printf("0\n");
        else {
          s.insert(make_pair(x[i], i));
          printf("%d\n", x[i] - x[it->second]);
          x[i] = x[it->second];
        }
      }
    }
  }
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from 1 to n. We say that this permutation maps value 1 into the value p1, value 2 into the value p2 and so on.

Kyota Ootori has just learned about cyclic representation of a permutation. A cycle is a sequence of numbers such that each element of this sequence is being mapped into the next element of this sequence (and the last element of the cycle is being mapped into the first element of the cycle). The cyclic representation is a representation of p as a collection of cycles forming p. For example, permutation p = [4, 1, 6, 2, 5, 3] has a cyclic representation that looks like (142)(36)(5) because 1 is replaced by 4, 4 is replaced by 2, 2 is replaced by 1, 3 and 6 are swapped, and 5 remains in place.

Permutation may have several cyclic representations, so Kyoya defines the standard cyclic representation of a permutation as follows. First, reorder the elements within each cycle so the largest element is first. Then, reorder all of the cycles so they are sorted by their first element. For our example above, the standard cyclic representation of [4, 1, 6, 2, 5, 3] is (421)(5)(63).

Now, Kyoya notices that if we drop the parenthesis in the standard cyclic representation, we get another permutation! For instance, [4, 1, 6, 2, 5, 3] will become [4, 2, 1, 5, 6, 3].

Kyoya notices that some permutations don't change after applying operation described above at all. He wrote all permutations of length n that do not change in a list in lexicographic order. Unfortunately, his friend Tamaki Suoh lost this list. Kyoya wishes to reproduce the list and he needs your help. Given the integers n and k, print the permutation that was k-th on Kyoya's list.

Input

The first line will contain two integers n, k (1 ≤ n ≤ 50, 1 ≤ k ≤ min{1018, l} where l is the length of the Kyoya's list).

Output

Print n space-separated integers, representing the permutation that is the answer for the question.

Examples

Input

4 3

Output

1 3 2 4

Input

10 1

Output

1 2 3 4 5 6 7 8 9 10

Note

The standard cycle representation is (1)(32)(4), which after removing parenthesis gives us the original permutation. The first permutation on the list would be [1, 2, 3, 4], while the second permutation would be [1, 2, 4, 3].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, k, f[60];
void fib(int x) {
  f[0] = 0, f[1] = 1;
  for (int i = 2; i < x + 2; i++) f[i] = f[i - 1] + f[i - 2];
}
int main() {
  cin >> n >> k;
  fib(n);
  for (int i = 0; i < n; i++) {
    if (f[n - i] < k) {
      k -= f[n - i];
      cout << i + 2 << " " << i + 1 << " ";
      i++;
    } else
      cout << i + 1 << " ";
    ;
  }
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Taro is playing with a puzzle that places numbers 1-9 in 9x9 squares. In this puzzle, you have to arrange the numbers according to the following rules.

* One number appears exactly once in the same column
* A number appears exactly once on the same line
* In each of the 3x3 ranges separated by double lines, a number appears exactly once.

For example, Figure 1 below is one arrangement that meets such a rule. However, Taro often creates an arrangement that violates the rules, as shown in Figure 2. The "2" appears twice in the leftmost column, the "1" never appears, the "1" appears twice in the second column from the left, and the "2" never appears. ..

<image> | <image>
--- | ---
Figure 1 | Figure 2

To help Taro, write a program that reads the arrangement of numbers, checks if the arrangement meets the rules, and outputs the location if it violates the rules. Please display * (half-width asterisk) before the number that is incorrect (appears more than once) according to the three rules, and blank before the number that is not incorrect.

Input

Given multiple datasets. The first row gives the number of datasets n (n ≤ 20). Each dataset is given a 9-character, 9-line numeric string that indicates the state of the puzzle.

Output

Output the following for each dataset.

Given number, * (half-width asterisk) and blank. Add * before the wrong number and a half-width space before the wrong number.

Insert a blank line between the datasets.

Example

Input

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

Output

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

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

### Response

```cpp
#include<cstdio>
using namespace std;
int main(){
  int n,m[9][9];
  char c[9][9];
  scanf("%d",&n);
  for(int i=0;i<n;i++){

    for(int j=0;j<9;j++){
      for(int k=0;k<9;k++){
	scanf("%d",&m[j][k]);
	c[j][k] = ' ';
      }
    }
    int dx[9] = {0,1,2,0,1,2,0,1,2};
    int dy[9] = {0,0,0,1,1,1,2,2,2};
    for(int l=0;l<9;l++){
      for(int j=0;j<8;j++){
	for(int k = j+1;k<9;k++){
	  if(m[l][j] == m[l][k]){
	    c[l][j] = '*';
	    c[l][k] = '*';
	  }
	  if(m[j][l] == m[k][l]){
	    c[j][l] = '*';
	    c[k][l] = '*';
	  }
	}
      }
    }

    for(int j=0;j<=6;j+=3){
      for(int k=0;k<=6;k+=3){
	for(int l=0;l<8;l++){
	  for(int o=l+1;o<9;o++){
	    if(m[j+ dy[l]][k+ dx[l]] == m[j+ dy[o]][k+ dx[o]]){
	      c[j+ dy[l]][k+ dx[l]] = '*';
	      c[j+ dy[o]][k+ dx[o]] = '*';
	    }
	  }
	}
      }
    }

    for(int j=0;j<9;j++){
      for(int k=0;k<9;k++){
	printf("%c%d",c[j][k],m[j][k]);
      }
      putchar('\n');
    }
    if(i != n-1) putchar('\n');
  }
  return (0);
}
```


### Prompt

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

Alice and Bob are going to celebrate Christmas by playing a game with a tree of presents. The tree has n nodes (numbered 1 to n, with some node r as its root). There are a_i presents are hanging from the i-th node.

Before beginning the game, a special integer k is chosen. The game proceeds as follows:

  * Alice begins the game, with moves alternating each turn;
  * in any move, the current player may choose some node (for example, i) which has depth at least k. Then, the player picks some positive number of presents hanging from that node, let's call it m (1 ≤ m ≤ a_i);
  * the player then places these m presents on the k-th ancestor (let's call it j) of the i-th node (the k-th ancestor of vertex i is a vertex j such that i is a descendant of j, and the difference between the depth of j and the depth of i is exactly k). Now, the number of presents of the i-th node (a_i) is decreased by m, and, correspondingly, a_j is increased by m;
  * Alice and Bob both play optimally. The player unable to make a move loses the game.

For each possible root of the tree, find who among Alice or Bob wins the game.

Note: The depth of a node i in a tree with root r is defined as the number of edges on the simple path from node r to node i. The depth of root r itself is zero.

Input

The first line contains two space-separated integers n and k (3 ≤ n ≤ 10^5, 1 ≤ k ≤ 20).

The next n-1 lines each contain two integers x and y (1 ≤ x, y ≤ n, x ≠ y), denoting an undirected edge between the two nodes x and y. These edges form a tree of n nodes.

The next line contains n space-separated integers denoting the array a (0 ≤ a_i ≤ 10^9).

Output

Output n integers, where the i-th integer is 1 if Alice wins the game when the tree is rooted at node i, or 0 otherwise.

Example

Input

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

Output

1 0 0 1 1

Note

Let us calculate the answer for sample input with root node as 1 and as 2.

Root node 1

Alice always wins in this case. One possible gameplay between Alice and Bob is:

  * Alice moves one present from node 4 to node 3.
  * Bob moves four presents from node 5 to node 2.
  * Alice moves four presents from node 2 to node 1.
  * Bob moves three presents from node 2 to node 1.
  * Alice moves three presents from node 3 to node 1.
  * Bob moves three presents from node 4 to node 3.
  * Alice moves three presents from node 3 to node 1.

Bob is now unable to make a move and hence loses.

Root node 2

Bob always wins in this case. One such gameplay is:

  * Alice moves four presents from node 4 to node 3.
  * Bob moves four presents from node 5 to node 2.
  * Alice moves six presents from node 3 to node 1.
  * Bob moves six presents from node 1 to node 2.

Alice is now unable to make a move and hence loses.

### Response

```cpp
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

const int N = 100200;
const int K = 42;
int n, k;
vector<int> g[N];
int a[N];
int b[N][K];
int c[N][K];
int ans[N];

void dfs1(int v, int par) {
	b[v][0] ^= a[v];
	for (int u : g[v]) {
		if (u == par) continue;
		dfs1(u, v);
		for (int i = 0; i < k; i++)
			b[v][(i + 1) % k] ^= b[u][i];
	}
}
void dfs2(int v, int par) {
	for (int i = k / 2; i < k; i++)
		ans[v] ^= b[v][i] ^ c[v][i];
	for (int u : g[v]) {
		if (u == par) continue;
		for (int i = 0; i < k; i++) {
			int x = b[v][i] ^ c[v][i];
			x ^= b[u][(i + k - 1) % k];
			c[u][(i + 1) % k] ^= x;
		}
		dfs2(u, v);
	}
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d", &n, &k);
	k *= 2;
	for (int i = 1; i < n; i++) {
		int v, u;
		scanf("%d%d", &v, &u);
		v--;u--;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	dfs1(0, -1);
	dfs2(0, -1);
	for (int i = 0; i < n; i++)
		printf("%d ", min(1, ans[i]));
	printf("\n");

	return 0;
}

```


### Prompt

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

A little boy Petya dreams of growing up and becoming the Head Berland Plumber. He is thinking of the problems he will have to solve in the future. Unfortunately, Petya is too inexperienced, so you are about to solve one of such problems for Petya, the one he's the most interested in.

The Berland capital has n water tanks numbered from 1 to n. These tanks are connected by unidirectional pipes in some manner. Any pair of water tanks is connected by at most one pipe in each direction. Each pipe has a strictly positive integer width. Width determines the number of liters of water per a unit of time this pipe can transport. The water goes to the city from the main water tank (its number is 1). The water must go through some pipe path and get to the sewer tank with cleaning system (its number is n).

Petya wants to increase the width of some subset of pipes by at most k units in total so that the width of each pipe remains integer. Help him determine the maximum amount of water that can be transmitted per a unit of time from the main tank to the sewer tank after such operation is completed.

Input

The first line contains two space-separated integers n and k (2 ≤ n ≤ 50, 0 ≤ k ≤ 1000). Then follow n lines, each line contains n integers separated by single spaces. The i + 1-th row and j-th column contain number cij — the width of the pipe that goes from tank i to tank j (0 ≤ cij ≤ 106, cii = 0). If cij = 0, then there is no pipe from tank i to tank j.

Output

Print a single integer — the maximum amount of water that can be transmitted from the main tank to the sewer tank per a unit of time.

Examples

Input

5 7
0 1 0 2 0
0 0 4 10 0
0 0 0 0 5
0 0 0 0 10
0 0 0 0 0

Output

10

Input

5 10
0 1 0 0 0
0 0 2 0 0
0 0 0 3 0
0 0 0 0 4
100 0 0 0 0

Output

5

Note

In the first test Petya can increase width of the pipe that goes from the 1st to the 2nd water tank by 7 units.

In the second test Petya can increase width of the pipe that goes from the 1st to the 2nd water tank by 4 units, from the 2nd to the 3rd water tank by 3 units, from the 3rd to the 4th water tank by 2 units and from the 4th to 5th water tank by 1 unit.

### Response

```cpp
#include <bits/stdc++.h>
template <typename T>
inline void tension(T &a, const T &b) {
  if (a > b) a = b;
}
template <typename T>
inline bool tensionv(T &a, const T &b) {
  return a > b ? a = b, true : false;
}
inline unsigned int getuint() {
  char w = getchar();
  while (w < '0' || '9' < w) w = getchar();
  unsigned int ans = 0;
  for (; '0' <= w && w <= '9'; w = getchar()) ans = ans * 10 + w - '0';
  return ans;
}
int V, S, T;
const int MAXV = 233333, MAXE = 233333;
struct Edge {
  int t, next, cap, v;
} G[MAXE];
int head[MAXV], e = 1;
inline void add_double_edge(int x, int y, int z, int v) {
  G[++e].t = y, G[e].next = head[x], head[x] = e;
  G[e].cap = z, G[e].v = v;
  G[++e].t = x, G[e].next = head[y], head[y] = e;
  G[e].cap = 0, G[e].v = -v;
}
struct ZKW_Min_Cost_Flow {
  int dist[MAXV], inq[MAXV];
  std::pair<int, int> heap[MAXE];
  int heap_size;
  void SPFA() {
    memset(dist + 1, 0x3f, sizeof(*dist) * V),
        heap[heap_size++] = std::make_pair(-(dist[T] = 0), T),
        std::push_heap(heap, heap + heap_size);
    for (int d, x; heap_size;) {
      d = -heap->first, x = heap->second,
      std::pop_heap(heap, heap + heap_size--);
      if (d != dist[x]) continue;
      for (int i = head[x]; i; i = G[i].next)
        if (G[i ^ 1].cap && tensionv(dist[G[i].t], dist[x] - G[i].v))
          heap[heap_size++] = std::make_pair(-dist[G[i].t], G[i].t),
          std::push_heap(heap, heap + heap_size);
    }
  }
  int dfs(int x, int aug0) {
    if (x == T) return aug0;
    inq[x] = 1;
    int aug = aug0;
    for (int i = head[x]; i; i = G[i].next)
      if (!inq[G[i].t] && G[i].cap && dist[x] == dist[G[i].t] + G[i].v) {
        int flow = dfs(G[i].t, std::min(aug, G[i].cap));
        if (flow) {
          G[i].cap -= flow, G[i ^ 1].cap += flow, aug -= flow;
          if (!aug) break;
        }
      }
    return aug0 - aug;
  }
  bool modify_label() {
    int t = 0x3f3f3f3f;
    for (int x = 1; x <= V; x++)
      if (inq[x])
        for (int i = head[x]; i; i = G[i].next)
          if (!inq[G[i].t] && G[i].cap)
            tension(t, dist[G[i].t] + G[i].v - dist[x]);
    if (t == 0x3f3f3f3f) return false;
    for (int i = 1; i <= V; i++)
      if (inq[i]) dist[i] += t;
    return true;
  }
  int min_cost_flow(int limit) {
    SPFA();
    int ans = 0;
    for (int now = limit; dist[S] <= now;) {
      for (int t; dist[S] <= now;) {
        memset(inq + 1, 0, sizeof(*inq) * V);
        if (t = dfs(S, dist[S] ? now / dist[S] : 0x3f3f3f3f))
          ans += t, now -= dist[S] * t;
        else
          break;
      }
      if (!modify_label()) break;
    }
    return ans;
  }
} ZKW_MCF;
int main() {
  int n = getuint(), m = getuint();
  V = n, S = 1, T = n;
  for (int x, i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (x = getuint())
        add_double_edge(i, j, x, 0), add_double_edge(i, j, 0x3f3f3f3f, 1);
  printf("%d\n", ZKW_MCF.min_cost_flow(m));
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Vasya got really tired of these credits (from problem F) and now wants to earn the money himself! He decided to make a contest to gain a profit.

Vasya has n problems to choose from. They are numbered from 1 to n. The difficulty of the i-th problem is d_i. Moreover, the problems are given in the increasing order by their difficulties. The difficulties of all tasks are pairwise distinct. In order to add the i-th problem to the contest you need to pay c_i burles to its author. For each problem in the contest Vasya gets a burles.

In order to create a contest he needs to choose a consecutive subsegment of tasks.

So the total earnings for the contest are calculated as follows:

  * if Vasya takes problem i to the contest, he needs to pay c_i to its author;
  * for each problem in the contest Vasya gets a burles;
  * let gap(l, r) = max_{l ≤ i < r} (d_{i + 1} - d_i)^2. If Vasya takes all the tasks with indices from l to r to the contest, he also needs to pay gap(l, r). If l = r then gap(l, r) = 0.

Calculate the maximum profit that Vasya can earn by taking a consecutive segment of tasks.

Input

The first line contains two integers n and a (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ a ≤ 10^9) — the number of proposed tasks and the profit for a single problem, respectively.

Each of the next n lines contains two integers d_i and c_i (1 ≤ d_i, c_i ≤ 10^9, d_i < d_{i+1}).

Output

Print one integer — maximum amount of burles Vasya can earn.

Examples

Input

5 10
1 15
5 3
6 11
7 2
11 22

Output

13

Input

3 5
1 8
2 19
3 11

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V) os << vv << ",";
  return os << "]";
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << '\n';
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
const int N = 3e5 + 7;
const long long INF = 1e18 + 700;
int n, nge[N];
long long a, d[N], c[N], e[N];
long long t[4 * N], lazy[4 * N];
void push(int v) {
  t[v * 2] += lazy[v];
  lazy[v * 2] += lazy[v];
  t[v * 2 + 1] += lazy[v];
  lazy[v * 2 + 1] += lazy[v];
  lazy[v] = 0;
}
void update(int v, int tl, int tr, int l, int r, long long addend) {
  if (l > r) return;
  if (l == tl && tr == r) {
    t[v] += addend;
    lazy[v] += addend;
  } else {
    push(v);
    int tm = (tl + tr) / 2;
    update(v * 2, tl, tm, l, min(r, tm), addend);
    update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, addend);
    t[v] = max(t[v * 2], t[v * 2 + 1]);
  }
}
long long query(int v, int tl, int tr, int l, int r) {
  if (l > r) return -INF;
  if (l <= tl && tr <= r) return t[v];
  push(v);
  int tm = (tl + tr) / 2;
  return max(query(v * 2, tl, tm, l, min(r, tm)),
             query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
void add(int l, int r, long long val) { update(1, 0, n, l, r, val); }
long long query(int l, int r) { return query(1, 0, n, l, r); }
void calc_nge() {
  stack<int> st;
  e[n] = 1e18 + 700;
  for (int i = 1; i <= n; i++) {
    while (!st.empty() && e[st.top()] <= e[i]) {
      nge[st.top()] = i;
      st.pop();
    }
    st.push(i);
  }
  assert(st.size() == 1);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> a;
  for (int i = 1; i <= n; i++) cin >> d[i] >> c[i];
  for (int i = 1; i <= n; i++) add(i, n, a - c[i]);
  for (int i = 1; i <= n - 1; i++) e[i] = (d[i + 1] - d[i]) * (d[i + 1] - d[i]);
  calc_nge();
  int last = n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int cur = i;
    if (i != n) {
      while (cur != last) {
        add(cur + 1, nge[cur], -e[cur]);
        cur = nge[cur];
      }
    }
    long long c_ans = query(i, n);
    ans = max(ans, c_ans);
    if (i < n) {
      add(i + 1, n, c[i] - a);
      add(i + 1, nge[i], e[i]);
      last = nge[i];
    }
  }
  cout << ans << '\n';
  return 0;
}

```


### Prompt

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

In problems on strings one often has to find a string with some particular properties. The problem authors were reluctant to waste time on thinking of a name for some string so they called it good. A string is good if it doesn't have palindrome substrings longer than or equal to d.

You are given string s, consisting only of lowercase English letters. Find a good string t with length |s|, consisting of lowercase English letters, which is lexicographically larger than s. Of all such strings string t must be lexicographically minimum.

We will call a non-empty string s[a ... b] = sasa + 1... sb (1 ≤ a ≤ b ≤ |s|) a substring of string s = s1s2... s|s|.

A non-empty string s = s1s2... sn is called a palindrome if for all i from 1 to n the following fulfills: si = sn - i + 1. In other words, palindrome read the same in both directions.

String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or there exists such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. Characters in such strings are compared like their ASCII codes.

Input

The first line contains integer d (1 ≤ d ≤ |s|).

The second line contains a non-empty string s, its length is no more than 4·105 characters. The string consists of lowercase English letters.

Output

Print the good string that lexicographically follows s, has the same length and consists of only lowercase English letters. If such string does not exist, print "Impossible" (without the quotes).

Examples

Input

3
aaaaaaa

Output

aabbcaa

Input

3
zzyzzzz

Output

Impossible

Input

4
abbabbbabbb

Output

abbbcaaabab

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 400019, K = 26, mod = 1e9 + 7, base = 911;
string s;
int ls1[N], fen1[N], ls2[N], fen2[N];
int n, d, inv, po[N], poi[N];
void upd(int p, int val, int *f, int *l) {
  val = (val + mod - l[p]) % mod;
  l[p] += val;
  l[p] %= mod;
  for (p++; p < N; p += p & -p) f[p] += val, f[p] %= mod;
  return;
}
int get(int p, int *f) {
  int ret = 0;
  for (; p > 0; p -= p & -p) ret = (ret + f[p]) % mod;
  return ret;
}
int inc(int p) {
  int flg = 0;
  for (int i = p - 1; i >= 0; i--) {
    if (s[i] != 'z') {
      s[i]++;
      long long vl1 = 1LL * s[i] * po[n - i - 1];
      vl1 %= mod;
      upd(i, vl1, fen1, ls1);
      long long vl2 = 1LL * s[i] * po[i];
      vl2 %= mod;
      upd(i, vl2, fen2, ls2);
      return i + 1;
      break;
    } else {
      s[i] = 'a';
      long long vl1 = 1LL * s[i] * po[n - i - 1];
      vl1 %= mod;
      upd(i, vl1, fen1, ls1);
      long long vl2 = 1ll * s[i] * po[i];
      vl2 %= mod;
      upd(i, vl2, fen2, ls2);
    }
  }
  if (!flg) {
    cout << "Impossible\n";
    exit(0);
  }
  return flg;
}
int le_ri(int l, int r) {
  long long ret = get(r, fen1) + mod - get(l, fen1);
  ret %= mod;
  ret *= poi[n - r];
  ret %= mod;
  return ret;
}
int ri_le(int l, int r) {
  long long ret = get(r, fen2) + mod - get(l, fen2);
  ret %= mod;
  ret *= poi[l];
  ret %= mod;
  return ret;
}
int power(int a, int b) {
  if (b == 0) return 1;
  long long ret = power(a, b / 2);
  ret *= ret;
  ret %= mod;
  if (b & 1) ret *= a, ret %= mod;
  return ret;
}
bool check(int len) {
  if (len >= d)
    if (le_ri(len - d, len) == ri_le(len - d, len)) return false;
  if (len >= d + 1)
    if (le_ri(len - d - 1, len) == ri_le(len - d - 1, len)) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> d;
  cin >> s;
  n = s.size();
  inv = power(base, mod - 2);
  po[0] = poi[0] = 1;
  for (int i = 1; i <= n; i++)
    po[i] = (1LL * po[i - 1] * base) % mod,
    poi[i] = (1LL * poi[i - 1] * inv) % mod;
  for (int i = 0; i < n; i++) {
    long long vl1 = 1LL * s[i] * po[n - i - 1];
    vl1 %= mod;
    upd(i, vl1, fen1, ls1);
    long long vl2 = 1LL * s[i] * po[i];
    vl2 %= mod;
    upd(i, vl2, fen2, ls2);
  }
  inc(n);
  int id = -1;
  for (int i = 1; i <= n; i++) {
    int len = i;
    if (!check(i)) {
      while (true) {
        int c = inc(len);
        bool flg = true;
        int b = len;
        for (int k = len; k >= c; k--)
          if (!check(k)) flg = false, b = k;
        len = b;
        if (flg) break;
      }
      id = len;
      break;
    }
  }
  if (id == -1) return cout << s << endl, 0;
  for (int i = id; i < n; i++) {
    for (int k = 'a'; k < 'd'; k++) {
      s[i] = k;
      long long vl1 = 1LL * s[i] * po[n - i - 1];
      vl1 %= mod;
      upd(i, vl1, fen1, ls1);
      long long vl2 = 1LL * s[i] * po[i];
      vl2 %= mod;
      upd(i, vl2, fen2, ls2);
      if (check(i + 1)) break;
    }
  }
  cout << s << endl;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:

You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.

Input

The first line contains an integer n (1 ≤ n ≤ 105). Each of the following n lines contain two space-separated integers xi and yi (1 ≤ xi ≤ 105, 0 ≤ yi ≤ i - 1, where i is the query's ordinal number; the numeration starts with 1).

If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration.

Output

For each query print the answer on a single line: the number of positive integers k such that <image>

Examples

Input

6
4 0
3 1
5 2
6 2
18 4
10000 3

Output

3
1
1
2
2
22

Note

Let's write out the divisors that give answers for the first 5 queries:

1) 1, 2, 4

2) 3

3) 5

4) 2, 6

5) 9, 18

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class Ty, class Tx>
Ty cast(const Tx &x) {
  Ty y;
  stringstream ss("");
  ss << x;
  ss.seekg(0);
  ss >> y;
  return y;
}
int last[100005];
int main() {
  int n, i, j, x, y, z;
  for ((i) = 0; (i) < (100005); (i)++) last[i] = -1;
  cin >> n;
  for ((i) = 0; (i) < (n); (i)++) {
    cin >> x >> y;
    z = 0;
    for (j = 1; j * j <= x; j++)
      if (x % j == 0) {
        if (last[j] < 0 || i - last[j] > y) z++;
        last[j] = i;
        if (j * j != x)
          if (last[x / j] < 0 || i - last[x / j] > y) z++;
        last[x / j] = i;
      }
    cout << z << endl;
  }
  return 0;
}

```


### Prompt

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

You are given a string s, consisting of lowercase English letters, and the integer m.

One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves.

Then one uses the chosen symbols to form a new string. All symbols from the chosen position should be used, but we are allowed to rearrange them in any order.

Formally, we choose a subsequence of indices 1 ≤ i1 < i2 < ... < it ≤ |s|. The selected sequence must meet the following condition: for every j such that 1 ≤ j ≤ |s| - m + 1, there must be at least one selected index that belongs to the segment [j, j + m - 1], i.e. there should exist a k from 1 to t, such that j ≤ ik ≤ j + m - 1.

Then we take any permutation p of the selected indices and form a new string sip1sip2... sipt.

Find the lexicographically smallest string, that can be obtained using this procedure.

Input

The first line of the input contains a single integer m (1 ≤ m ≤ 100 000).

The second line contains the string s consisting of lowercase English letters. It is guaranteed that this string is non-empty and its length doesn't exceed 100 000. It is also guaranteed that the number m doesn't exceed the length of the string s.

Output

Print the single line containing the lexicographically smallest string, that can be obtained using the procedure described above.

Examples

Input

3
cbabc

Output

a

Input

2
abcab

Output

aab

Input

3
bcabcbaccba

Output

aaabb

Note

In the first sample, one can choose the subsequence {3} and form a string "a".

In the second sample, one can choose the subsequence {1, 2, 4} (symbols on this positions are 'a', 'b' and 'a') and rearrange the chosen symbols to form a string "aab".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, INF = 0x3f3f3f3f;
char s[N];
struct node {
  int pos, x;
} tree[N << 2];
vector<char> v;
int cnt[30];
void pushUp(int t) {
  if (tree[t << 1].x < tree[t << 1 | 1].x) {
    tree[t].x = tree[t << 1].x;
    tree[t].pos = tree[t << 1].pos;
  } else {
    tree[t].x = tree[t << 1 | 1].x;
    tree[t].pos = tree[t << 1 | 1].pos;
  }
}
void update(int t, int L, int R, int x, int v) {
  if (L == R && L == x) {
    tree[t].x = v;
    tree[t].pos = x;
    return;
  }
  int mid = (L + R) >> 1;
  if (x <= mid)
    update(t << 1, L, mid, x, v);
  else
    update(t << 1 | 1, mid + 1, R, x, v);
  pushUp(t);
}
int main() {
  int m, i;
  scanf("%d%s", &m, s);
  memset(tree, 0x3f, sizeof tree);
  int n = strlen(s), pos = -INF, mins = 26;
  for (i = 0; i < min(m - 1, n); ++i) {
    update(1, 1, n, i + 1, s[i] - 'a');
    cnt[s[i] - 'a']++;
  }
  for (i = m - 1; i < n; ++i) {
    cnt[s[i] - 'a']++;
    update(1, 1, n, i + 1, s[i] - 'a');
    if (i - m >= 0) update(1, 1, n, i - m + 1, INF);
    if (pos >= i - m + 1 && pos <= i) continue;
    pos = tree[1].pos - 1;
    v.push_back(s[pos]);
  }
  sort(v.begin(), v.end());
  i = 0;
  char ans;
  while (v[v.size() - 1] - 'a' > i) {
    ans = 'a' + i;
    for (int j = 0; j < cnt[i]; ++j) cout << ans;
    ++i;
  }
  for (i = 0; i < v.size() - 1; ++i)
    if (v[i] == v[v.size() - 1]) break;
  while (i < v.size()) {
    cout << v[i];
    ++i;
  }
  printf("\n");
}

```


### Prompt

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

Fibonacci numbers are the sequence of integers: f0 = 0, f1 = 1, f2 = 1, f3 = 2, f4 = 3, f5 = 5, ..., fn = fn - 2 + fn - 1. So every next number is the sum of the previous two.

Bajtek has developed a nice way to compute Fibonacci numbers on a blackboard. First, he writes a 0. Then, below it, he writes a 1. Then he performs the following two operations:

  * operation "T": replace the top number with the sum of both numbers;
  * operation "B": replace the bottom number with the sum of both numbers.

If he performs n operations, starting with "T" and then choosing operations alternately (so that the sequence of operations looks like "TBTBTBTB..."), the last number written will be equal to fn + 1.

Unfortunately, Bajtek sometimes makes mistakes and repeats an operation two or more times in a row. For example, if Bajtek wanted to compute f7, then he would want to do n = 6 operations: "TBTBTB". If he instead performs the sequence of operations "TTTBBT", then he will have made 3 mistakes, and he will incorrectly compute that the seventh Fibonacci number is 10. The number of mistakes in the sequence of operations is the number of neighbouring equal operations («TT» or «BB»).

You are given the number n of operations that Bajtek has made in an attempt to compute fn + 1 and the number r that is the result of his computations (that is last written number). Find the minimum possible number of mistakes that Bajtek must have made and any possible sequence of n operations resulting in r with that number of mistakes.

Assume that Bajtek always correctly starts with operation "T".

Input

The first line contains the integers n and r (1 ≤ n, r ≤ 106).

Output

The first line of the output should contain one number — the minimum possible number of mistakes made by Bajtek. The second line should contain n characters, starting with "T", describing one possible sequence of operations with that number of mistakes. Each character must be either "T" or "B".

If the required sequence doesn't exist, output "IMPOSSIBLE" (without quotes).

Examples

Input

6 10

Output

2
TBBTTB

Input

4 5

Output

0
TBTB

Input

2 1

Output

IMPOSSIBLE

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int f(int x, int y, int n) {
  int rr = 0;
  for (; n >= 3; --n) {
    if (y <= 0) return INF;
    if (y >= x - y) {
      int t = y;
      y = x - t;
      x = t;
    } else {
      x = x - y;
      ++rr;
    }
  }
  if (x != 2 || y != 1) return INF;
  return rr;
}
string g(int x, int y, int n) {
  int nn = n;
  vector<int> rr;
  for (; n >= 3; --n) {
    if (y >= x - y) {
      int t = y;
      y = x - t;
      x = t;
    } else {
      x = x - y;
      rr.push_back(n);
    }
  }
  reverse(rr.begin(), rr.end());
  rr.push_back(-1);
  string s = "TB";
  int p = 0;
  for (int i = 3; i <= nn; ++i) {
    if (rr[p] == i) {
      ++p;
      s += s[s.length() - 1] == 'T' ? 'T' : 'B';
    } else {
      s += s[s.length() - 1] == 'T' ? 'B' : 'T';
    }
  }
  return s;
}
int main() {
  int n, r;
  cin >> n >> r;
  if (n <= 3) {
    if (n == r) {
      cout << 0 << endl;
      cout << string("TBT").substr(0, n) << endl;
    } else {
      cout << "IMPOSSIBLE" << endl;
    }
    return 0;
  }
  if (r < n) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  int ans = INF;
  int ii = -1;
  for (int i = 1; i < r; ++i) {
    int rr = f(r, i, n);
    if (rr < ans) {
      ans = rr;
      ii = i;
    }
  }
  if (ans == INF) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << ans << endl;
    cout << g(r, ii, n) << endl;
  }
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Codeforces is a wonderful platform and one its feature shows how much someone contributes to the community. Every registered user has contribution — an integer number, not necessarily positive. There are n registered users and the i-th of them has contribution ti.

Limak is a little polar bear and he's new into competitive programming. He doesn't even have an account in Codeforces but he is able to upvote existing blogs and comments. We assume that every registered user has infinitely many blogs and comments.

  * Limak can spend b minutes to read one blog and upvote it. Author's contribution will be increased by 5.
  * Limak can spend c minutes to read one comment and upvote it. Author's contribution will be increased by 1.

Note that it's possible that Limak reads blogs faster than comments.

Limak likes ties. He thinks it would be awesome to see a tie between at least k registered users. To make it happen he is going to spend some time on reading and upvoting. After that, there should exist an integer value x that at least k registered users have contribution exactly x.

How much time does Limak need to achieve his goal?

Input

The first line contains four integers n, k, b and c (2 ≤ k ≤ n ≤ 200 000, 1 ≤ b, c ≤ 1000) — the number of registered users, the required minimum number of users with the same contribution, time needed to read and upvote a blog, and time needed to read and upvote a comment, respectively.

The second line contains n integers t1, t2, ..., tn (|ti| ≤ 109) where ti denotes contribution of the i-th registered user.

Output

Print the minimum number of minutes Limak will spend to get a tie between at least k registered users.

Examples

Input

4 3 100 30
12 2 6 1

Output

220

Input

4 3 30 100
12 2 6 1

Output

190

Input

6 2 987 789
-8 42 -4 -65 -8 -8

Output

0

Note

In the first sample, there are 4 registered users and Limak wants a tie between at least 3 of them. Limak should behave as follows.

  * He spends 100 minutes to read one blog of the 4-th user and increase his contribution from 1 to 6.
  * Then he spends 4·30 = 120 minutes to read four comments of the 2-nd user and increase his contribution from 2 to 6 (four times it was increaded by 1).

In the given scenario, Limak spends 100 + 4·30 = 220 minutes and after that each of users 2, 3, 4 has contribution 6.

In the second sample, Limak needs 30 minutes to read a blog and 100 minutes to read a comment. This time he can get 3 users with contribution equal to 12 by spending 100 + 3·30 = 190 minutes:

  * Spend 2·30 = 60 minutes to read two blogs of the 1-st user to increase his contribution from 2 to 12.
  * Spend 30 + 100 minutes to read one blog and one comment of the 3-rd user. His contribution will change from 6 to 6 + 5 + 1 = 12.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct sth {
  long long v, c;
} m[5][200010], h[5][200010];
long long n, k, b, c, tmp, xl;
long long minh = 9223372036854775807, tc;
long long v[200010];
long long pre[200010];
long long ma[5], l[5], Cos[5];
bool cmp2(sth x, sth y) {
  return x.c + (ma[xl] - x.v) / 5 * b < y.c + (ma[xl] - y.v) / 5 * b;
}
int main() {
  scanf("%I64d%I64d%I64d%I64d", &n, &k, &b, &c);
  for (int i = 1; i <= n; i++) scanf("%I64d", &v[i]);
  sort(v + 1, v + 1 + n);
  for (int i = 1; i <= n; i++) {
    tmp = (v[i] % 5 + 5) % 5;
    tc = 0;
    m[tmp][i].v = v[i];
    m[tmp][i].c = 0;
    for (int j = 1; j <= 4; j++) {
      tmp = (tmp + 1) % 5;
      tc += c;
      m[tmp][i].v = v[i] + j;
      m[tmp][i].c = tc;
    }
  }
  for (int i = 1; i <= n; i++) {
    pre[i] = pre[i - 1] + v[i];
    if (i >= k) {
      tc = v[i] * k - (pre[i] - pre[i - k]);
      minh = min(tc * c, minh);
    }
  }
  for (int j = 0; j <= 4; j++) {
    ma[j] = m[j][1].v;
    for (int i = 1; i <= k; i++) {
      Cos[j] += l[j] * ((m[j][i].v - ma[j]) / 5 * b) + m[j][i].c;
      ma[j] = max(ma[j], m[j][i].v);
      l[j]++;
      h[j][l[j]] = m[j][i];
      xl = j;
      push_heap(h[j] + 1, h[j] + l[j] + 1, cmp2);
    }
    minh = min(minh, Cos[j]);
  }
  for (int j = 0; j <= 4; j++)
    for (int i = k + 1; i <= n; i++) {
      xl = j;
      pop_heap(h[j] + 1, h[j] + l[j] + 1, cmp2);
      Cos[j] -= (ma[j] - h[j][k].v) / 5 * b + h[j][k].c;
      Cos[j] += (k - 1) * ((m[j][i].v - ma[j]) / 5 * b) + m[j][i].c;
      ma[j] = max(ma[j], m[j][i].v);
      h[j][k] = m[j][i];
      push_heap(h[j] + 1, h[j] + k + 1, cmp2);
      minh = min(minh, Cos[j]);
    }
  printf("%I64d", minh);
  return 0;
}

```


### Prompt

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

A tourist wants to visit country Zeydabad for Zbazi (a local game in Zeydabad).

The country Zeydabad is a rectangular table consisting of n rows and m columns. Each cell on the country is either 'z' or '.'.

The tourist knows this country is named Zeydabad because there are lots of ''Z-pattern"s in the country. A ''Z-pattern" is a square which anti-diagonal is completely filled with 'z' and its upper and lower rows are also completely filled with 'z'. All other cells of a square can be arbitrary.

<image>

Note that a ''Z-pattern" can consist of only one cell (see the examples).

So he wants to count the number of ''Z-pattern"s in the country (a necessary skill for Zbazi).

Now your task is to help tourist with counting number of ''Z-pattern"s.

As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

Input

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

Each of the next n lines contains m characters 'z' or '.' — the description of Zeydabad.

Output

Print the only integer a — the number of ''Z-pattern"s in Zeydabad.

Examples

Input

4 4
zzzz
zzz.
.z..
zzzz

Output

16

Input

1 4
z.z.

Output

2

Input

2 2
zz
zz

Output

5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, tl[3010][3010], tz[3010][3010], tr[3010][3010], z[3010][3010],
    t[3010];
long long r, bit[3010];
vector<int> del[3010];
char c;
long long getsum(int index) {
  long long sum = 0;
  while (index) {
    sum += bit[index];
    index -= index & (-index);
  }
  return sum;
}
void update(int index, long long val) {
  while (index <= n) {
    bit[index] += val;
    index += index & (-index);
  }
  return;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf(" %c", &c);
      if (c == 'z') tl[i][j] = 1 + tl[i][j - 1];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m; j > 0; j--) {
      if (tl[i][j]) {
        tr[i][j] = 1 + tr[i][j + 1];
        tz[i][j] = 1 + tz[i - 1][j + 1];
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j <= i; j++) {
      del[j].clear();
      t[j] = 0;
      bit[j] = 0;
    }
    for (int j = 1; i - j >= 0 && j <= n; j++) {
      update(j, 1);
      del[j + tl[j][i - j + 1]].push_back(j);
      t[j + tl[j][i - j + 1]]++;
      for (int k = 0; k < t[j]; k++) update(del[j][k], -1);
      r += getsum(j);
      r -= getsum(j - min(tr[j][i - j + 1], tz[j][i - j + 1]));
    }
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      del[j].clear();
      t[j] = 0;
      bit[j] = 0;
    }
    for (int j = 1; i + j - 1 <= n && j <= m; j++) {
      update(j, 1);
      del[j + tl[i + j - 1][m - j + 1]].push_back(j);
      t[j + tl[i + j - 1][m - j + 1]]++;
      for (int k = 0; k < t[j]; k++) update(del[j][k], -1);
      r += getsum(j);
      r -= getsum(j - min(tr[i + j - 1][m - j + 1], tz[i + j - 1][m - j + 1]));
    }
  }
  printf("%lld\n", r);
  return 0;
}

```


### Prompt

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

Smart Beaver recently got interested in a new word game. The point is as follows: count the number of distinct good substrings of some string s. To determine if a string is good or not the game uses rules. Overall there are n rules. Each rule is described by a group of three (p, l, r), where p is a string and l and r (l ≤ r) are integers. We’ll say that string t complies with rule (p, l, r), if the number of occurrences of string t in string p lies between l and r, inclusive. For example, string "ab", complies with rules ("ab", 1, 2) and ("aab", 0, 1), but does not comply with rules ("cd", 1, 2) and ("abab", 0, 1).

A substring s[l... r] (1 ≤ l ≤ r ≤ |s|) of string s = s1s2... s|s| (|s| is a length of s) is string slsl + 1... sr.

Consider a number of occurrences  of string t in string p as a number of pairs of integers l, r (1 ≤ l ≤ r ≤ |p|) such that p[l... r] = t.

We’ll say that string t is good if it complies with all n rules. Smart Beaver asks you to help him to write a program that can calculate the number of distinct good substrings of string s. Two substrings s[x... y] and s[z... w] are cosidered to be distinct iff s[x... y] ≠ s[z... w].

Input

The first line contains string s. The second line contains integer n. Next n lines contain the rules, one per line. Each of these lines contains a string and two integers pi, li, ri, separated by single spaces (0 ≤ li ≤ ri ≤ |pi|). It is guaranteed that all the given strings are non-empty and only contain lowercase English letters.

The input limits for scoring 30 points are (subproblem G1):

  * 0 ≤ n ≤ 10.
  * The length of string s and the maximum length of string p is  ≤ 200.

The input limits for scoring 70 points are (subproblems G1+G2):

  * 0 ≤ n ≤ 10.
  * The length of string s and the maximum length of string p is  ≤ 2000.

The input limits for scoring 100 points are (subproblems G1+G2+G3):

  * 0 ≤ n ≤ 10.
  * The length of string s and the maximum length of string p is  ≤ 50000.

Output

Print a single integer — the number of good substrings of string s.

Examples

Input

aaab
2
aa 0 0
aab 1 1

Output

3

Input

ltntlnen
3
n 0 0
ttlneenl 1 4
lelllt 1 1

Output

2

Input

a
0

Output

1

Note

There are three good substrings in the first sample test: «aab», «ab» and «b».

In the second test only substrings «e» and «t» are good.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1200005;
int n;
int ch[N][26], prt[N], len[N], Right[N][11];
int rt, Lst, pool = 0;
int newnode(int l) {
  int nx = ++pool;
  len[nx] = l;
  return nx;
}
char s[11][50050];
int L[20], R[20];
vector<int> T[N << 1];
void DFS(int u) {
  for (auto v : T[u]) {
    DFS(v);
    for (int i = 0; i <= n; ++i) Right[u][i] += Right[v][i];
  }
}
void ins(int w) {
  int p = Lst, nx = newnode(len[p] + 1);
  Lst = nx;
  for (; p && !ch[p][w]; p = prt[p]) ch[p][w] = nx;
  if (!p)
    prt[nx] = rt;
  else {
    int q = ch[p][w];
    if (len[q] == len[p] + 1)
      prt[nx] = q;
    else {
      int newq = newnode(len[p] + 1);
      for (int i = 0; i < 26; ++i) ch[newq][i] = ch[q][i];
      prt[newq] = prt[q];
      prt[q] = prt[nx] = newq;
      for (; p && ch[p][w] == q; p = prt[p]) ch[p][w] = newq;
    }
  }
}
int main() {
  scanf("%s%d", s[0], &n);
  for (int i = 1; i <= n; ++i) scanf("%s%d%d", s[i], &L[i], &R[i]);
  rt = Lst = newnode(0);
  for (int i = 0; i <= n; ++i) {
    Lst = rt;
    int l = strlen(s[i]);
    for (int j = 0; j < l; ++j) ins(s[i][j] - 'a'), Right[Lst][i]++;
  }
  for (int i = 2; i <= pool; ++i) T[prt[i]].push_back(i);
  DFS(rt);
  long long S = 0;
  for (int u = 2; u <= pool; ++u)
    if (Right[u][0]) {
      bool flag = 1;
      for (int i = 1; i <= n; ++i)
        if (Right[u][i] < L[i] || R[i] < Right[u][i]) {
          flag = 0;
          break;
        }
      if (flag) S += len[u] - len[prt[u]];
    }
  cout << S << '\n';
  return 0;
}

```


### Prompt

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

Let us consider the following operations on a string consisting of `A` and `B`:

1. Select a character in a string. If it is `A`, replace it with `BB`. If it is `B`, replace with `AA`.
2. Select a substring that is equal to either `AAA` or `BBB`, and delete it from the string.

For example, if the first operation is performed on `ABA` and the first character is selected, the string becomes `BBBA`. If the second operation is performed on `BBBAAAA` and the fourth through sixth characters are selected, the string becomes `BBBA`.

These operations can be performed any number of times, in any order.

You are given two string S and T, and q queries a_i, b_i, c_i, d_i. For each query, determine whether S_{a_i} S_{{a_i}+1} ... S_{b_i}, a substring of S, can be made into T_{c_i} T_{{c_i}+1} ... T_{d_i}, a substring of T.

Constraints

* 1 \leq |S|, |T| \leq 10^5
* S and T consist of letters `A` and `B`.
* 1 \leq q \leq 10^5
* 1 \leq a_i \leq b_i \leq |S|
* 1 \leq c_i \leq d_i \leq |T|

Input

Input is given from Standard Input in the following format:

S
T
q
a_1 b_1 c_1 d_1
...
a_q b_q c_q d_q

Output

Print q lines. The i-th line should contain the response to the i-th query. If S_{a_i} S_{{a_i}+1} ... S_{b_i} can be made into T_{c_i} T_{{c_i}+1} ... T_{d_i}, print `YES`. Otherwise, print `NO`.

Examples

Input

BBBAAAABA
BBBBA
4
7 9 2 5
7 9 1 4
1 7 2 5
1 7 2 4

Output

YES
NO
YES
NO

Input

AAAAABBBBAAABBBBAAAA
BBBBAAABBBBBBAAAAABB
10
2 15 2 13
2 13 6 16
1 13 2 20
4 20 3 20
1 18 9 19
2 14 1 11
3 20 3 15
6 16 1 17
4 18 8 20
7 20 3 14

Output

YES
YES
YES
YES
YES
YES
NO
NO
NO
NO

### Response

```cpp
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int r1[101010], r2[101010];
int main()
{
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++)r1[i + 1] = r1[i] + (s[i] - 'A' + 1);
	for (int i = 0; i < t.size(); i++)r2[i + 1] = r2[i] + (t[i] - 'A' + 1);
	int query;
	scanf("%d", &query);
	for (int i = 0; i < query; i++)
	{
		int za, zb, zc, zd;
		scanf("%d%d%d%d", &za, &zb, &zc, &zd);
		if ((r1[zb] - r1[za - 1]) % 3 == (r2[zd] - r2[zc - 1]) % 3)printf("YES\n");
		else printf("NO\n");
	}
}
```


### Prompt

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

Example

Input

acmicpc
tsukuba

Output

No

### Response

```cpp
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    string s, t;
    cin >> s >> t;
    string s1, s2;
    for (int i = 0; i < s.size(); ++i) {
        if(i&1) s1 += s[i];
        else s2 += s[i];
    }
    s1 += '?', s2 += '?';
    int cnt = 0;
    for (char i : t) {
        if(s1[cnt] == i) cnt++;
    }
    if(cnt+1 == s1.size()) {
        puts("Yes");
        return -0;
    }
    cnt = 0;
    for (char i : t) {
        if(s2[cnt] == i) cnt++;
    }
    if(cnt+1 == s2.size()) {
        puts("Yes");
        return -0;
    }
    puts("No");
    return 0;
}

```


### Prompt

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

There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0), (W,0), (W,H), and (0,H). You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum.

Constraints

* 1 \leq W,H \leq 10^9
* 0\leq x\leq W
* 0\leq y\leq H
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

W H x y

Output

Print the maximum possible area of the part whose area is not larger than that of the other, followed by `1` if there are multiple ways to cut the rectangle and achieve that maximum, and `0` otherwise.

The area printed will be judged correct when its absolute or relative error is at most 10^{-9}.

Examples

Input

2 3 1 2

Output

3.000000 0

Input

2 2 1 1

Output

2.000000 1

### Response

```cpp
#include<iostream>
using namespace std;
int main(){
  int W, H, x, y;
  cin >> W >> H >> x >> y;
  int f = (x*2==W && y*2==H)?1:0;
  cout << 0.5*W*H << " " << f << endl;
  return 0;
}
```


### Prompt

Please create a solution in CPP to the following problem:

There is a grid of squares with H+1 horizontal rows and W vertical columns.

You will start at one of the squares in the top row and repeat moving one square right or down. However, for each integer i from 1 through H, you cannot move down from the A_i-th, (A_i + 1)-th, \ldots, B_i-th squares from the left in the i-th row from the top.

For each integer k from 1 through H, find the minimum number of moves needed to reach one of the squares in the (k+1)-th row from the top. (The starting square can be chosen individually for each case.) If, starting from any square in the top row, none of the squares in the (k+1)-th row can be reached, print `-1` instead.

Constraints

* 1 \leq H,W \leq 2\times 10^5
* 1 \leq A_i \leq B_i \leq W

Input

Input is given from Standard Input in the following format:

H W
A_1 B_1
A_2 B_2
:
A_H B_H

Output

Print H lines. The i-th line should contain the answer for the case k=i.

Example

Input

4 4
2 4
1 1
2 3
2 4

Output

1
3
6
-1

### Response

```cpp
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int H,W; cin >> H >> W;

    map<int,int> mp;
    multiset<int> st;
    rep(i,W) mp[i] = i;
    rep(i,W) st.insert(0);

    rep(i,H) {
        int l,r; cin >> l >> r;
        --l;
        auto itr = mp.lower_bound(l);
        int rr = -1;
        while (itr != mp.end() && itr->first <= r){
            rr = max(rr,itr->second);
            int v = (*itr).first - (*itr).second;
            st.erase(st.find(v));
            mp.erase(itr++);
        }
        if (rr != -1 && r < W) {
            mp[r] = rr;
            st.insert(r - rr);
        }
        int ans = -1;
        if ((int)st.size() > 0) {
            ans = *st.begin() + i + 1;
        }
        cout << ans << '\n';
    }
    return 0;
}
```


### Prompt

Please create a solution in CPP to the following problem:

There are n piles of pebbles on the table, the i-th pile contains ai pebbles. Your task is to paint each pebble using one of the k given colors so that for each color c and any two piles i and j the difference between the number of pebbles of color c in pile i and number of pebbles of color c in pile j is at most one.

In other words, let's say that bi, c is the number of pebbles of color c in the i-th pile. Then for any 1 ≤ c ≤ k, 1 ≤ i, j ≤ n the following condition must be satisfied |bi, c - bj, c| ≤ 1. It isn't necessary to use all k colors: if color c hasn't been used in pile i, then bi, c is considered to be zero.

Input

The first line of the input contains positive integers n and k (1 ≤ n, k ≤ 100), separated by a space — the number of piles and the number of colors respectively.

The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 100) denoting number of pebbles in each of the piles.

Output

If there is no way to paint the pebbles satisfying the given condition, output "NO" (without quotes) .

Otherwise in the first line output "YES" (without quotes). Then n lines should follow, the i-th of them should contain ai space-separated integers. j-th (1 ≤ j ≤ ai) of these integers should be equal to the color of the j-th pebble in the i-th pile. If there are several possible answers, you may output any of them.

Examples

Input

4 4
1 2 3 4

Output

YES
1
1 4
1 2 4
1 2 3 4

Input

5 2
3 2 4 1 3

Output

NO

Input

5 4
3 2 4 3 5

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void HoH() {
  ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0),
      cout.tie(0);
}
int main() {
  HoH();
  int n, k;
  cin >> n >> k;
  int m = INT_MIN, s = INT_MAX;
  int x;
  int a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    m = max(m, a[i]), s = min(s, a[i]);
  }
  if (k + s >= m) {
    cout << "YES" << endl;
    for (int i = 0; i < n; ++i) {
      for (int j = 1; j <= s; j++) {
        if (j % k == 0) {
          cout << k << " ";
        } else if (j % k != 0) {
          cout << (j % (k)) << " ";
        } else
          cout << j << " ";
      }
      for (int j = 1; j <= a[i] - s; j++) {
        if (j % k == 0) {
          cout << k << " ";
        } else if (j % k != 0) {
          cout << (j % (k)) << " ";
        } else
          cout << j << " ";
      }
      cout << endl;
    }
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same line — the positions (x-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than r from this tower.

Your task is to find minimal r that each city has been provided by cellular network, i.e. for each city there is at least one cellular tower at the distance which is no more than r.

If r = 0 then a tower provides cellular network only for the point where it is located. One tower can provide cellular network for any number of cities, but all these cities must be at the distance which is no more than r from this tower.

Input

The first line contains two positive integers n and m (1 ≤ n, m ≤ 105) — the number of cities and the number of cellular towers.

The second line contains a sequence of n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the coordinates of cities. It is allowed that there are any number of cities in the same point. All coordinates ai are given in non-decreasing order.

The third line contains a sequence of m integers b1, b2, ..., bm ( - 109 ≤ bj ≤ 109) — the coordinates of cellular towers. It is allowed that there are any number of towers in the same point. All coordinates bj are given in non-decreasing order.

Output

Print minimal r so that each city will be covered by cellular network.

Examples

Input

3 2
-2 2 4
-3 0

Output

4

Input

5 3
1 5 10 14 17
4 11 15

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 1;
int n, m;
long long Q[MAX_N], C[MAX_N];
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 0; i < n; i++) scanf("%I64d", C + i);
    for (int i = 0; i < m; i++) scanf("%I64d", Q + i);
    long long x, ans = 0;
    for (int i = 0; i < n; i++) {
      x = C[i];
      int d = lower_bound(Q, Q + m, x) - Q;
      d = d == m ? (m - 1) : d;
      long long dis = min(abs(Q[d] - x), abs(Q[(d - 1) < 0 ? 0 : (d - 1)] - x));
      if (dis > ans) ans = dis;
    }
    printf("%I64d\n", ans);
  }
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.

You will now successively do the following Q operations:

* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.

For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Constraints

* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}

Input

Input is given from Standard Input in the following format:

N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}

Output

Print Q integers S_{i} to Standard Output in the following format:

S_{1}
S_{2}
\vdots
S_{Q}

Note that S_{i} may not fit into a 32-bit integer.

Examples

Input

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

Output

11
12
16

Input

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

Output

8
4
4

Input

2
1 2
3
1 100
2 100
100 1000

Output

102
200
2000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
vector<int> a(100010);
ll sum;
int main(){
  int n;cin>>n;
  for(int i=0;i<n;++i){
    int x;cin>>x;
    sum+=x;
    a[x]++;
  }

  int q;cin>>q;
  for(int i=0;i<q;++i){
    int b,c;cin>>b>>c;
    a[c]+=a[b];
    ll sa=c*a[b]-b*a[b];
    sum+=sa;
    a[b]=0;
    cout<<sum<<endl;
  }
}

```


### Prompt

Create a solution in Cpp for the following problem:

A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times bigger than kayaks (and occupy the space of 2 cubic metres).

Each waterborne vehicle has a particular carrying capacity, and it should be noted that waterborne vehicles that look the same can have different carrying capacities. Knowing the truck body volume and the list of waterborne vehicles in the boat depot (for each one its type and carrying capacity are known), find out such set of vehicles that can be taken in the lorry, and that has the maximum total carrying capacity. The truck body volume of the lorry can be used effectively, that is to say you can always put into the lorry a waterborne vehicle that occupies the space not exceeding the free space left in the truck body.

Input

The first line contains a pair of integer numbers n and v (1 ≤ n ≤ 105; 1 ≤ v ≤ 109), where n is the number of waterborne vehicles in the boat depot, and v is the truck body volume of the lorry in cubic metres. The following n lines contain the information about the waterborne vehicles, that is a pair of numbers ti, pi (1 ≤ ti ≤ 2; 1 ≤ pi ≤ 104), where ti is the vehicle type (1 – a kayak, 2 – a catamaran), and pi is its carrying capacity. The waterborne vehicles are enumerated in order of their appearance in the input file.

Output

In the first line print the maximum possible carrying capacity of the set. In the second line print a string consisting of the numbers of the vehicles that make the optimal set. If the answer is not unique, print any of them.

Examples

Input

3 2
1 2
2 7
1 3

Output

7
2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct node {
  int flag, v;
  int q;
} a[100000 + 10];
bool cmp(node a, node b) {
  if (a.flag != b.flag) return a.flag < b.flag;
  if (a.flag == 1) return a.v < b.v;
  return a.v > b.v;
}
int main() {
  int n, v;
  cin >> n >> v;
  for (int i = 0; i < n; i++) {
    cin >> a[i].flag >> a[i].v;
    a[i].q = i + 1;
  }
  sort(a, a + n, cmp);
  long long sum = 0;
  long long v1 = 0;
  int j = 0;
  int i = 0;
  for (; i < n; i++) {
    sum += a[i].v;
    v1 += a[i].flag;
    if (v1 > v) {
      if (v1 == v + 1) {
        if (a[j].flag == 2) {
          sum -= a[i].v;
          i--;
          break;
        }
        if (a[i].v <= a[j].v) {
          sum -= a[i].v;
          i--;
          break;
        }
        sum -= a[j].v;
        v1 -= a[j].flag;
        j++;
      } else {
        if (a[j].flag == 2) {
          sum -= a[i].v;
          i--;
          break;
        } else if (a[j].flag == 1 && a[j + 1].flag == 1) {
          if (a[j].v + a[j + 1].v < a[i].v) {
            sum -= a[j].v;
            sum -= a[j + 1].v;
            j++;
            j++;
          } else {
            sum -= a[i].v;
            i--;
            break;
          }
        } else
          break;
      }
    }
  }
  if (i == n) i--;
  cout << sum << endl;
  for (int k = j; k <= i; k++) cout << a[k].q << " ";
  cout << endl;
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

There are N cities in Republic of AtCoder. The size of the i-th city is A_{i}. Takahashi would like to build N-1 bidirectional roads connecting two cities so that any city can be reached from any other city by using these roads.

Assume that the cost of building a road connecting the i-th city and the j-th city is |i-j| \times D + A_{i} + A_{j}. For Takahashi, find the minimum possible total cost to achieve the objective.

Constraints

* 1 \leq N \leq 2 \times 10^5
* 1 \leq D \leq 10^9
* 1 \leq A_{i} \leq 10^9
* A_{i} and D are integers.

Input

Input is given from Standard Input in the following format:

N D
A_1 A_2 ... A_N

Output

Print the minimum possible total cost.

Examples

Input

3 1
1 100 1

Output

106

Input

3 1000
1 100 1

Output

2202

Input

6 14
25 171 7 1 17 162

Output

497

Input

12 5
43 94 27 3 69 99 56 25 8 15 46 8

Output

658

### Response

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

using namespace std;

using ll = long long;
using P = pair<int, int>;
using E = pair<ll, P>;

const ll INF = 1LL << 60;

int n;
ll D;
ll a[200005];
vector< E > edges;

void solve(int L, int R) {
    if (R - L <= 1) return;
    int mid = (R + L) / 2;

    ll lval = INF;
    int lidx = -1;
    for (int i = L; i < mid; i++) {
        ll tmp = a[i] - D * i;
        if (lval > tmp) {
            lidx = i;
            lval = tmp;
        }
    }

    ll rval = INF;
    int ridx = -1;
    for (int i = mid; i < R; i++) {
        ll tmp = a[i] + D * i;
        if (rval > tmp) {
            ridx = i;
            rval = tmp;
        }
    }

    for (int i = L; i < mid; i++) {
        edges.emplace_back(a[i] + a[ridx] + D * (ridx - i), P(i, ridx));
    }

    for (int i = mid; i < R; i++) {
        edges.emplace_back(a[i] + a[lidx] + D * (i - lidx), P(lidx, i));
    }

    solve(L, mid);
    solve(mid, R);
}

struct UnionFind {
    //各要素が属する集合の代表(根)を管理する
    //もし、要素xが根であればdata[x]は負の値を取り、-data[x]はxが属する集合の大きさに等しい
    vector<int> data;

    UnionFind(int sz) : data(sz, -1) {}

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        bool is_union = (x != y);
        if (is_union) {
            if (data[x] > data[y]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return is_union;
    }

    int find(int x) {
        if (data[x] < 0) { //要素xが根である
            return x;
        } else {
            data[x] = find(data[x]); //data[x]がxの属する集合の根でない場合、根になるよう更新される
            return data[x];
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return -data[find(x)];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> D;
    for (int i = 0; i < n; i++) cin >> a[i];
    solve(0, n);

    sort(edges.begin(), edges.end());
    UnionFind uf(n);
    ll ans = 0;
    for (E& e : edges) {
        ll cost = e.first;
        int u = e.second.first, v = e.second.second;
        if (!uf.same(u, v)) {
            uf.unite(u, v);
            ans += cost;
        }
    }
    cout << ans << endl;
    return 0;
}
```


### Prompt

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

The Kingdom of Aqua Canora Mystica is a very affluent and peaceful country, but around the kingdom, there are many evil monsters that kill people. So the king gave an order to you to kill the master monster.

You came to the dungeon where the monster lived. The dungeon consists of a grid of square cells. You explored the dungeon moving up, down, left and right. You finally found, fought against, and killed the monster.

Now, you are going to get out of the dungeon and return home. However, you found strange carpets and big rocks are placed in the dungeon, which were not there until you killed the monster. They are caused by the final magic the monster cast just before its death! Every rock occupies one whole cell, and you cannot go through that cell. Also, each carpet covers exactly one cell. Each rock is labeled by an uppercase letter and each carpet by a lowercase. Some of the rocks and carpets may have the same label.

While going around in the dungeon, you observed the following behaviors. When you enter into the cell covered by a carpet, all the rocks labeled with the corresponding letter (e.g., the rocks with ‘A’ for the carpets with ‘a’) disappear. After the disappearance, you can enter the cells where the rocks disappeared, but if you enter the same carpet cell again or another carpet cell with the same label, the rocks revive and prevent your entrance again. After the revival, you have to move on the corresponding carpet cell again in order to have those rocks disappear again.

Can you exit from the dungeon? If you can, how quickly can you exit? Your task is to write a program that determines whether you can exit the dungeon, and computes the minimum required time.

Input

The input consists of some data sets.

Each data set begins with a line containing two integers, W and H (3 ≤ W, H ≤ 30). In each of the following H lines, there are W characters, describing the map of the dungeon as W × H grid of square cells. Each character is one of the following:

* ‘@’ denoting your current position,
* ‘<’ denoting the exit of the dungeon,
* A lowercase letter denoting a cell covered by a carpet with the label of that letter,
* An uppercase letter denoting a cell occupied by a rock with the label of that letter,
* ‘#’ denoting a wall, and
* ‘.’ denoting an empty cell.

Every dungeon is surrounded by wall cells (‘#’), and has exactly one ‘@’ cell and one ‘<’ cell. There can be up to eight distinct uppercase labels for the rocks and eight distinct lowercase labels for the carpets.

You can move to one of adjacent cells (up, down, left, or right) in one second. You cannot move to wall cells or the rock cells.

A line containing two zeros indicates the end of the input, and should not be processed.

Output

For each data set, output the minimum time required to move from the ‘@’ cell to the ‘<’ cell, in seconds, in one line. If you cannot exit, output -1.

Examples

Input

8 3
########
#<A.@.a#
########
8 3
########
#<AaAa@#
########
8 4
########
#<EeEe@#
#FG.e#.#
########
8 8
########
#mmm@ZZ#
#mAAAbZ#
#mABBBZ#
#mABCCd#
#aABCDD#
#ZZcCD<#
########
0 0

Output

7
-1
7
27

Input

8 3

<A.@.a#

8 3

<AaAa@#

8 4

<EeEe@#
FG.e#.#

8 8

mmm@ZZ#
mAAAbZ#
mABBBZ#
mABCCd#
aABCDD#
ZZcCD<#

0 0

Output

7
-1
7
27

### Response

```cpp
#include<iostream>
#include<queue>
#include<cctype>
#include<map>

using namespace std;

struct S{
  int y,x,t,b;
};

int main(){
  for(int W,H;cin>>W>>H,W;){
    char g[30][31];
    map<char,int> m;
    queue<S> que;
    for(int i=0;i<H;i++){
      cin>>g[i];
      for(int j=0;j<W;j++){
	if(g[i][j]=='@'){
	  que.push({i,j,0,0});
	}else if(islower(g[i][j])){
	  if(!m.count(g[i][j])){
	    int s=m.size();
	    m[g[i][j]]=s;
	  }
	}
      }
    }
    bool p[30][30][1<<8]={};
    while(!que.empty()){
      S cs=que.front();
      if(g[cs.y][cs.x]=='<')break;
      que.pop();
      if(p[cs.y][cs.x][cs.b]++)continue;
      for(int i=0;i<4;i++){
	int ny=cs.y+(~i&i-1);
	int nx=cs.x+(i?2-i:0);
	char c=g[cs.y][cs.x];
	if(c!='#'&&!(isupper(c)&&(!m.count(tolower(c))||!(cs.b>>m[tolower(c)]&1)))){
	  int nb=cs.b;
	  if(islower(c)){
	    nb^=1<<m[c];
	  }
	  que.push({ny,nx,cs.t+1,nb});
	}
      }
    }
    cout<<(que.empty()?-1:que.front().t)<<endl;
  }
}
```


### Prompt

Create a solution in cpp for the following problem:

An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi.

Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?

Constraints

* 1 ≤ N ≤ 100
* 1 ≤ d_i ≤ 100
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N
d_1
:
d_N

Output

Print the maximum number of layers in a kagami mochi that can be made.

Examples

Input

4
10
8
8
6

Output

3

Input

3
15
15
15

Output

1

Input

7
50
30
50
100
50
80
30

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n,a,s[1000],b[1000];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
		b[s[i]]=1;
	}
	for(int i=1;i<=100;i++)  a+=b[i];
	cout<<a;
	return 0;
}
```


### Prompt

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

You are given two binary strings a and b of the same length. You can perform the following two operations on the string a:

  * Swap any two bits at indices i and j respectively (1 ≤ i, j ≤ n), the cost of this operation is |i - j|, that is, the absolute difference between i and j.
  * Select any arbitrary index i (1 ≤ i ≤ n) and flip (change 0 to 1 or 1 to 0) the bit at this index. The cost of this operation is 1.

Find the minimum cost to make the string a equal to b. It is not allowed to modify string b.

Input

The first line contains a single integer n (1 ≤ n ≤ 10^6) — the length of the strings a and b.

The second and third lines contain strings a and b respectively.

Both strings a and b have length n and contain only '0' and '1'.

Output

Output the minimum cost to make the string a equal to b.

Examples

Input

3
100
001

Output

2

Input

4
0101
0011

Output

1

Note

In the first example, one of the optimal solutions is to flip index 1 and index 3, the string a changes in the following way: "100" → "000" → "001". The cost is 1 + 1 = 2.

The other optimal solution is to swap bits and indices 1 and 3, the string a changes then "100" → "001", the cost is also |1 - 3| = 2.

In the second example, the optimal solution is to swap bits at indices 2 and 3, the string a changes as "0101" → "0011". The cost is |2 - 3| = 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using iii = tuple<ll, ll, ll>;
using matrix = vector<vector<ll>>;
using arr = vector<ll>;
using vs = vector<string>;
using pv = vector<ii>;
using umap = unordered_map<ll, ll>;
void showArr(arr a) {
  for (auto i : a) cout << i << " ";
  cout << endl;
}
ll dx[] = {-1, 1, -1, 1, 0, 0, -1, 1};
ll dy[] = {-1, 1, 0, 0, -1, 1, 1, -1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(25);
  ll n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  ll cost = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      if (i + 1 < n and a[i + 1] == b[i] and b[i + 1] == a[i]) {
        swap(a[i], a[i + 1]);
        cost++;
      } else {
        cost++;
        a[i] = b[i];
      }
    }
  }
  cout << cost << endl;
  return 0;
}

```


### Prompt

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

You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1.

You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0 to 1 or 1 to 0. It is possible that after some operation you can obtain a number with leading zeroes, but it does not matter for this problem.

You are also given two integers 0 ≤ y < x < n. Your task is to calculate the minimum number of operations you should perform to obtain the number that has remainder 10^y modulo 10^x. In other words, the obtained number should have remainder 10^y when divided by 10^x.

Input

The first line of the input contains three integers n, x, y (0 ≤ y < x < n ≤ 2 ⋅ 10^5) — the length of the number and the integers x and y, respectively.

The second line of the input contains one decimal number consisting of n digits, each digit of this number is either 0 or 1. It is guaranteed that the first digit of the number is 1.

Output

Print one integer — the minimum number of operations you should perform to obtain the number having remainder 10^y modulo 10^x. In other words, the obtained number should have remainder 10^y when divided by 10^x.

Examples

Input

11 5 2
11010100101

Output

1

Input

11 5 1
11010100101

Output

3

Note

In the first example the number will be 11010100100 after performing one operation. It has remainder 100 modulo 100000.

In the second example the number will be 11010100010 after performing three operations. It has remainder 10 modulo 100000.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, x, y;
  string second;
  cin >> n >> x >> y >> second;
  int ans = 0;
  for (int i = n - x; i < n; ++i) {
    if (i == n - y - 1)
      ans += (second[i] != '1');
    else
      ans += second[i] != '0';
  }
  cout << ans << "\n";
  return 0;
}

```


### Prompt

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

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

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

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

Input

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

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

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

Output

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

Example

Input

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

Output

7
1 5 1 3
2 4 6 1 3 5

### Response

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

```


### Prompt

Develop a solution in Cpp to the problem described below:

Little Petya likes numbers a lot. Recently his mother has presented him a collection of n non-negative integers. There's only one thing Petya likes more than numbers: playing with little Masha. He immediately decided to give a part of his new collection to her. To make the game even more interesting, Petya decided to give Masha such collection of numbers for which the following conditions fulfill:

  * Let's introduce x1 to denote the xor of all numbers Petya has got left; and let's introduce x2 to denote the xor of all numbers he gave to Masha. Value (x1 + x2) must be as large as possible.
  * If there are multiple ways to divide the collection so that the previous condition fulfilled, then Petya minimizes the value x1.

The xor operation is a bitwise excluding "OR", that is denoted as "xor" in the Pascal language and "^" in C/C++/Java.

Help Petya divide the collection as described above. If there are multiple suitable ways to divide it, find any of them. Please note that after Petya gives a part of his numbers to Masha, he may have no numbers left. The reverse situation is also possible, when Petya gives nothing to Masha. In both cases we must assume that the xor of an empty set of numbers equals 0.

Input

The first line contains integer n (1 ≤ n ≤ 105), showing how many numbers Petya's mother gave him. The second line contains the actual space-separated numbers. They are all integer, non-negative and do not exceed 1018.

Output

Print n space-separated integers, the i-th of them should equal either 1, if Petya keeps the number that follows i-th in his collection, or it should equal 2, if Petya gives the corresponding number to Masha. The numbers are indexed in the order in which they are given in the input.

Examples

Input

6
1 2 3 4 5 6

Output

2 2 2 2 2 2

Input

3
1000000000000 1000000000000 1000000000000

Output

2 2 2

Input

8
1 1 2 2 3 3 4 4

Output

1 2 1 2 2 2 1 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
bitset<N> b[65];
int n, m, q[65], ans[N];
long long a[N], s;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", a + i);
    s ^= a[i];
  }
  for (int j = 0; j < 2; ++j) {
    for (int k = 63; k >= 0; --k) {
      if ((s >> k & 1) == j) {
        for (int i = 1; i <= n; ++i) b[m][i] = a[i] >> k & 1;
        b[m][0] = j ^ 1;
        for (int i = 0; i < m; ++i)
          if (b[m][q[i]]) b[m] ^= b[i];
        q[m] = n + 1;
        for (int i = 1; i <= n; ++i)
          if (b[m][i]) {
            q[m] = i;
            break;
          }
        if (q[m] > n) continue;
        for (int i = 0; i < m; ++i)
          if (b[i][q[m]]) b[i] ^= b[m];
        ++m;
      }
    }
  }
  for (int i = 0; i < m; ++i) ans[q[i]] = b[i][0];
  for (int i = 1; i <= n; ++i) printf("%d ", 2 - ans[i]);
}

```


### Prompt

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

This is an output-only problem. You shouldn't read anything from the input.

In short, your task is to simulate multiplication by using only comparison (x < y) and addition (x + y). There is no input in this problem, you just print a sequence of operations.

Imagine that there is a big array a[0], a[1], ..., a[N-1] of length N. The first two values are initially two non-negative integers A and B (which are unknown to you), the other elements are zeros. Your goal is to get the product A \cdot B in a[2] at the end.

You are allowed operations of two types, with the following format (where 0 \leq i, j, k < N):

* `+ i j k` — applies operation a[k] = a[i] + a[j].
* `< i j k` — applies operation a[k] = a[i] < a[j]. That is, if a[i] < a[j] then a[k] becomes 1, otherwise it becomes 0.

You can use at most Q operations. Elements of a can't exceed V. Indices (i, j, k) don't have to be distinct. It's allowed to modify any element of the array (including the first two). The actual checker simulates the process for multiple pairs (A, B) within a single test. Each time, the checker chooses values A and B, creates the array a = [A, B, 0, 0, \ldots, 0], applies all your operations and ensures that a[2] = A \cdot B.

Constraints

* 0 \leq A, B \leq 10^9
* N = Q = 200\,000
* V = 10^{19} = 10\,000\,000\,000\,000\,000\,000

Input

The Standard Input is empty.

Output

In the first line, print the number of operations. Each operation should then be printed in a single line of format `+ i j k` or `< i j k`.

Example

Input

Output

### Response

```cpp
#if 1
#ifdef LOCAL
#define _GLIBCXX_DEBUG 1
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)

typedef string str;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define ts to_string
str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) { stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) { str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) { str res = ""; F0R(i,SZ) res += char('0'+b[i]); return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { bool fst = 1; str res = "{"; for (const auto& x: v) {if (!fst) res += ", ";	fst = 0; res += ts(x);}	res += "}"; return res;}
template<class A, class B> str ts(pair<A,B> p) {return "("+ts(p.f)+", "+ts(p.s)+")"; }

template<class A> void pr(A x) { cout << ts(x); }
template<class H, class... T> void pr(const H& h, const T&... t) { pr(h); pr(t...); }
void ps() { pr("\n"); }
template<class H, class... T> void ps(const H& h, const T&... t) { pr(h); if (sizeof...(t)) pr(" "); ps(t...); }

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {cerr << ts(h); if (sizeof...(t)) cerr << ", ";	DBG(t...); }
#endif

int unused = 1000;
int zero = 199999;
int one = 3;

vector< pair<char, pair<int, pair<int, int> > > > ops;

void compare(int dest, int i, int j) {
    ops.push_back({'<', {i, {j,dest}}});
    // cout << "< " << dest << ' ' << i << ' ' << j << '\n';
}

void add(int dest, int i, int j) {
    ops.push_back({'+', {i, {j,dest}}});
    // cout << "+ " << dest << ' ' << i << ' ' << j << '\n';
}

void do_the_and(int dest, int i, int j) {
    int temp1 = unused++;
    int temp2 = unused++;
    compare(temp1, i, one);
    compare(temp2, j, one);
    add(temp2, temp1, temp2);
    compare(dest, temp2, one);
}

int pow2(int v) {
    return 3+v;
}

void convert(int src, int start) {
    int curval = unused++;

    for (int p = 30; p >= 0; p--) {
        int dest = start + p;

        int temp1 = unused++;
        int temp2 = unused++;
        add(temp1, curval, pow2(p));
        compare(dest, temp1, src);

        add(temp2, dest, zero);
        for (int j = 0; j < p; j++) {
            add(temp2,temp2,temp2);
        }
        add(curval,curval,temp2);
    }
}

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

    compare(3, 3, 0);
    for (int i = 4; i < 35; i++) {
        add(i, i-1, i-1);
    }

    add(0, 0, one);
    add(1, 1, one);

    convert(0, 100000);
    convert(1, 110000);

    for (int fin = 60; fin >= 0; fin--) {
        add(2, 2, 2);
        for (int p1 = 30; p1 >= 0; p1--) {
            for (int p2 = 30; p2 >= 0; p2--) if (p1+p2 == fin) {
                int idx1 = 100000 + p1;
                int idx2 = 110000 + p2;

                int nloc = unused++;
                do_the_and(nloc, idx1, idx2);
                add(2, 2, nloc);
            }
        }
    }

    // cout << unused << endl;
    cout << sz(ops) << '\n';
    for (int i = 0; i < sz(ops); i++) {
        cout << ops[i].first << ' ' << ops[i].second.first << ' ' << ops[i].second.second.first << ' ' << ops[i].second.second.second << '\n';
    }

    return 0;
}
```


### Prompt

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

As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers.

<image>

Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip.

Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him.

Input

The first line of input contains two integers n and m (1 ≤ n, m ≤ 1000).

The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≤ |name| ≤ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct.

The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≤ |command| ≤ 10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers.

Output

Print m lines, the commands in the configuration file after Dustin did his task.

Examples

Input

2 2
main 192.168.0.2
replica 192.168.0.1
block 192.168.0.1;
proxy 192.168.0.2;

Output

block 192.168.0.1; #replica
proxy 192.168.0.2; #main

Input

3 5
google 8.8.8.8
codeforces 212.193.33.27
server 138.197.64.57
redirect 138.197.64.57;
block 8.8.8.8;
cf 212.193.33.27;
unblock 8.8.8.8;
check 138.197.64.57;

Output

redirect 138.197.64.57; #server
block 8.8.8.8; #google
cf 212.193.33.27; #codeforces
unblock 8.8.8.8; #google
check 138.197.64.57; #server

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, mp;
  cin >> n >> mp;
  map<string, string> m;
  while (n--) {
    string name, ip;
    cin >> name >> ip;
    m.insert(make_pair(ip, name));
  }
  while (mp--) {
    string com, ip1, ans;
    map<string, string>::iterator it;
    cin >> com >> ip1;
    string ip2 = ip1.substr(0, ip1.length() - 1);
    for (it = m.begin(); it != m.end(); it++) {
      string s = it->first;
      if (s == ip2) {
        ans = it->second;
        break;
      }
    }
    cout << com << " " << ip1 << " #" << ans << endl;
  }
}

```