### Prompt

Develop a solution in cpp to the problem described below:

When the river brought Gerda to the house of the Old Lady who Knew Magic, this lady decided to make Gerda her daughter. She wants Gerda to forget about Kay, so she puts all the roses from the garden underground.

Mole, who lives in this garden, now can watch the roses without going up to the surface. Typical mole is blind, but this mole was granted as special vision by the Old Lady. He can watch any underground objects on any distance, even through the obstacles and other objects. However, the quality of the picture depends on the Manhattan distance to object being observed.

Mole wants to find an optimal point to watch roses, that is such point with integer coordinates that the maximum Manhattan distance to the rose is minimum possible.

As usual, he asks you to help.

Manhattan distance between points (x1, y1, z1) and (x2, y2, z2) is defined as |x1 - x2| + |y1 - y2| + |z1 - z2|.

Input

The first line of the input contains an integer t t (1 ≤ t ≤ 100 000) — the number of test cases. Then follow exactly t blocks, each containing the description of exactly one test.

The first line of each block contains an integer ni (1 ≤ ni ≤ 100 000) — the number of roses in the test. Then follow ni lines, containing three integers each — the coordinates of the corresponding rose. Note that two or more roses may share the same position.

It's guaranteed that the sum of all ni doesn't exceed 100 000 and all coordinates are not greater than 1018 by their absolute value.

Output

For each of t test cases print three integers — the coordinates of the optimal point to watch roses. If there are many optimal answers, print any of them.

The coordinates of the optimal point may coincide with the coordinates of any rose.

Examples

Input

1
5
0 0 4
0 0 -4
0 4 0
4 0 0
1 1 1

Output

0 0 0

Input

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

Output

3 5 9
3 5 9

Note

In the first sample, the maximum Manhattan distance from the point to the rose is equal to 4.

In the second sample, the maximum possible distance is 0. Note that the positions of the roses may coincide with each other and with the position of the optimal point.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double PI = 4 * atan(1);
int T, N;
long long X[100013], Y[100013], Z[100013];
long long xmi, xma, ymi, yma, zmi, zma, smi, sma;
long long ansx, ansy, ansz;
inline bool is(long long x, int p) { return (((x % 2) + 2) % 2) == p; }
bool go(long long d) {
  xmi = -8.1e18, xma = 8.1e18, ymi = -8.1e18, yma = 8.1e18, zmi = -8.1e18,
  zma = 8.1e18, smi = -8.1e18, sma = 8.1e18;
  for (int i = 0; i < N; i++) {
    xmi = max(xmi, Y[i] + Z[i] - X[i] - d);
    xma = min(xma, Y[i] + Z[i] - X[i] + d);
    ymi = max(ymi, -Y[i] + Z[i] + X[i] - d);
    yma = min(yma, -Y[i] + Z[i] + X[i] + d);
    zmi = max(zmi, Y[i] - Z[i] + X[i] - d);
    zma = min(zma, Y[i] - Z[i] + X[i] + d);
    smi = max(smi, Y[i] + Z[i] + X[i] - d);
    sma = min(sma, Y[i] + Z[i] + X[i] + d);
  }
  if (smi > sma || xmi > xma || ymi > yma || zmi > zma) return false;
  for (int p = 0; p < 2; p++) {
    if (smi == sma && is(smi, !p) || xmi == xma && is(xmi, !p) ||
        ymi == yma && is(ymi, !p) || zmi == zma && is(zmi, !p))
      continue;
    long long qmi = 0;
    qmi += (is(xmi, p) ? xmi : xmi + 1);
    qmi += (is(ymi, p) ? ymi : ymi + 1);
    qmi += (is(zmi, p) ? zmi : zmi + 1);
    long long qma = 0;
    qma += (is(xma, p) ? xma : xma - 1);
    qma += (is(yma, p) ? yma : yma - 1);
    qma += (is(zma, p) ? zma : zma - 1);
    if (qmi <= qma && qmi <= sma && qma >= smi) {
      if (qmi >= smi) {
        ansx = (is(xmi, p) ? xmi : xmi + 1);
        ansy = (is(ymi, p) ? ymi : ymi + 1);
        ansz = (is(zmi, p) ? zmi : zmi + 1);
      } else if (qma <= sma) {
        ansx = (is(xma, p) ? xma : xma - 1);
        ansy = (is(yma, p) ? yma : yma - 1);
        ansz = (is(zma, p) ? zma : zma - 1);
      } else {
        xmi += is(xmi, !p);
        xma -= is(xma, !p);
        ymi += is(ymi, !p);
        yma -= is(yma, !p);
        zmi += is(zmi, !p);
        zma -= is(zma, !p);
        smi += is(smi, !p);
        sma -= is(sma, !p);
        if (xma + ymi + zmi < smi) {
          if (xma + yma + zmi < smi) {
            ansx = xma;
            ansy = yma;
            ansz = smi - ansx - ansy;
          } else {
            ansx = xma;
            ansz = zmi;
            ansy = smi - ansx - ansz;
          }
        } else {
          ansy = ymi;
          ansz = zmi;
          ansx = smi - ymi - zmi;
        }
      }
      return true;
    }
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> T;
  while (T--) {
    cin >> N;
    for (int i = 0; i < N; i++) {
      cin >> X[i] >> Y[i] >> Z[i];
    }
    long long lo = 0;
    long long hi = 3.1e18;
    while (lo != hi) {
      long long mid = (lo + hi) / 2;
      if (go(mid)) {
        hi = mid;
      } else {
        lo = mid + 1;
      }
    }
    go(lo);
    cout << (ansy + ansz) / 2 << ' ' << (ansx + ansz) / 2 << ' '
         << (ansx + ansy) / 2 << '\n';
  }
  cout.flush();
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

At an arcade, Takahashi is playing a game called RPS Battle, which is played as follows:

* The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)
* Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):
* R points for winning with Rock;
* S points for winning with Scissors;
* P points for winning with Paper.
* However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)

Before the start of the game, the machine decides the hand it will play in each round. With supernatural power, Takahashi managed to read all of those hands.

The information Takahashi obtained is given as a string T. If the i-th character of T (1 \leq i \leq N) is `r`, the machine will play Rock in the i-th round. Similarly, `p` and `s` stand for Paper and Scissors, respectively.

What is the maximum total score earned in the game by adequately choosing the hand to play in each round?

Constraints

* 2 \leq N \leq 10^5
* 1 \leq K \leq N-1
* 1 \leq R,S,P \leq 10^4
* N,K,R,S, and P are all integers.
* |T| = N
* T consists of `r`, `p`, and `s`.

Input

Input is given from Standard Input in the following format:

N K
R S P
T

Output

Print the maximum total score earned in the game.

Examples

Input

5 2
8 7 6
rsrpr

Output

27

Input

7 1
100 10 1
ssssppr

Output

211

Input

30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr

Output

4996

### Response

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

int main()
{
    int N, K, R, S, P; string T;
    cin >> N >> K >> R >> S >> P >> T;

    long sum = 0;
    bool isLose[100010] = { false };
    for (int i = 1; i <= N; i++) {
        if (isLose[i]) continue;

        int next = i + K;
        if (next <= N && T[i-1] == T[next-1]) isLose[next] = true;

        if (T[i-1] == 'r') sum += P;
        else if (T[i-1] == 's') sum += R;
        else sum += S;
    }

    cout << sum << endl;

    return 0;
}
```


### Prompt

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

Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game.

Initially, Bob chooses integer m, bit depth of the game, which means that all numbers in the game will consist of m bits. Then he asks Peter to choose some m-bit number. After that, Bob computes the values of n variables. Each variable is assigned either a constant m-bit number or result of bitwise operation. Operands of the operation may be either variables defined before, or the number, chosen by Peter. After that, Peter's score equals to the sum of all variable values.

Bob wants to know, what number Peter needs to choose to get the minimum possible score, and what number he needs to choose to get the maximum possible score. In both cases, if there are several ways to get the same score, find the minimum number, which he can choose.

Input

The first line contains two integers n and m, the number of variables and bit depth, respectively (1 ≤ n ≤ 5000; 1 ≤ m ≤ 1000).

The following n lines contain descriptions of the variables. Each line describes exactly one variable. Description has the following format: name of a new variable, space, sign ":=", space, followed by one of:

  1. Binary number of exactly m bits.
  2. The first operand, space, bitwise operation ("AND", "OR" or "XOR"), space, the second operand. Each operand is either the name of variable defined before or symbol '?', indicating the number chosen by Peter.

Variable names are strings consisting of lowercase Latin letters with length at most 10. All variable names are different.

Output

In the first line output the minimum number that should be chosen by Peter, to make the sum of all variable values minimum possible, in the second line output the minimum number that should be chosen by Peter, to make the sum of all variable values maximum possible. Both numbers should be printed as m-bit binary numbers.

Examples

Input

3 3
a := 101
b := 011
c := ? XOR b

Output

011
100

Input

5 1
a := 1
bb := 0
cx := ? OR a
d := ? XOR ?
e := d AND bb

Output

0
0

Note

In the first sample if Peter chooses a number 0112, then a = 1012, b = 0112, c = 0002, the sum of their values is 8. If he chooses the number 1002, then a = 1012, b = 0112, c = 1112, the sum of their values is 15.

For the second test, the minimum and maximum sum of variables a, bb, cx, d and e is 2, and this sum doesn't depend on the number chosen by Peter, so the minimum Peter can choose is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxN = 5005;
struct Node {
  int x, y, op;
} a[maxN + 1];
int n, m;
int c1, c2;
int val[maxN + 1];
string b[maxN + 1], r1, r2;
map<string, int> id;
pair<int, int> num[maxN + 1];
inline int calc(int k, int v) {
  val[0] = v;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    int op = num[i].first, id = num[i].second;
    if (!op) {
      int x = val[a[id].x], y = val[a[id].y];
      if (a[id].op == 0) val[i] = x | y;
      if (a[id].op == 1) val[i] = x & y;
      if (a[id].op == 2) val[i] = x ^ y;
    } else
      val[i] = b[id][m - k] - '0';
    sum += val[i];
  }
  return sum;
}
int main() {
  cin >> n >> m;
  m--;
  string s = "?";
  id[s] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    id[s] = i;
    cin >> s >> s;
    if (s[0] == '0' || s[0] == '1') {
      c2++;
      b[c2] = s;
      num[i] = make_pair(1, c2);
    } else {
      c1++;
      a[c1].x = id[s];
      cin >> s;
      if (s == "OR") a[c1].op = 0;
      if (s == "AND") a[c1].op = 1;
      if (s == "XOR") a[c1].op = 2;
      cin >> s;
      a[c1].y = id[s];
      num[i] = make_pair(0, c1);
    }
  }
  for (int i = m; i >= 0; i--) {
    int x = calc(i, 0), y = calc(i, 1);
    if (x <= y)
      r1 += '0';
    else
      r1 += '1';
    if (x >= y)
      r2 += '0';
    else
      r2 += '1';
  }
  cout << r1 << endl;
  cout << r2 << endl;
  return 0;
}

```


### Prompt

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

n children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation a1, a2, ..., an of length n. It is an integer sequence such that each integer from 1 to n appears exactly once in it.

The game consists of m steps. On each step the current leader with index i counts out ai people in clockwise order, starting from the next person. The last one to be pointed at by the leader becomes the new leader.

You are given numbers l1, l2, ..., lm — indices of leaders in the beginning of each step. Child with number l1 is the first leader in the game.

Write a program which will restore a possible permutation a1, a2, ..., an. If there are multiple solutions then print any of them. If there is no solution then print -1.

Input

The first line contains two integer numbers n, m (1 ≤ n, m ≤ 100).

The second line contains m integer numbers l1, l2, ..., lm (1 ≤ li ≤ n) — indices of leaders in the beginning of each step.

Output

Print such permutation of n numbers a1, a2, ..., an that leaders in the game will be exactly l1, l2, ..., lm if all the rules are followed. If there are multiple solutions print any of them.

If there is no permutation which satisfies all described conditions print -1.

Examples

Input

4 5
2 3 1 4 4

Output

3 1 2 4

Input

3 3
3 1 2

Output

-1

Note

Let's follow leadership in the first example:

  * Child 2 starts.
  * Leadership goes from 2 to 2 + a2 = 3.
  * Leadership goes from 3 to 3 + a3 = 5. As it's greater than 4, it's going in a circle to 1.
  * Leadership goes from 1 to 1 + a1 = 4.
  * Leadership goes from 4 to 4 + a4 = 8. Thus in circle it still remains at 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int n, m, a[102], pos = 1, t[102], l[102], ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(a, -1, sizeof a);
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> l[i];
  for (int i = 1; i < m; i++) {
    if (l[i] > l[i - 1])
      ans = l[i] - l[i - 1];
    else
      ans = n - (l[i - 1] - l[i]);
    if (a[l[i - 1]] != -1 && a[l[i - 1]] != ans) {
      cout << -1 << "\n";
      return 0;
    }
    a[l[i - 1]] = ans;
  }
  for (int i = 1; i <= n; i++) t[a[i]]++;
  for (int i = 1; i <= n; i++) {
    while (t[pos] != 0) pos++;
    if (a[i] == -1) a[i] = pos, pos++;
    if (t[i] > 1) {
      cout << -1 << "\n";
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) cout << a[i] << " ";
  cout << "\n";
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.

Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?

Constraints

* 1 ≤ X ≤ 9
* X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

If Takahashi's growth will be celebrated, print `YES`; if it will not, print `NO`.

Examples

Input

5

Output

YES

Input

6

Output

NO

### Response

```cpp
#include<cstdio>
int main() {
int x;
scanf("%d",&x);
if(x==7||x==5||x==3) puts("YES");
else puts("NO");
}
```


### Prompt

Generate a cpp solution to the following problem:

After getting kicked out of her reporting job for not knowing the alphabet, Bessie has decided to attend school at the Fillet and Eggs Eater Academy. She has been making good progress with her studies and now knows the first k English letters.

Each morning, Bessie travels to school along a sidewalk consisting of m + n tiles. In order to help Bessie review, Mr. Moozing has labeled each of the first m sidewalk tiles with one of the first k lowercase English letters, spelling out a string t. Mr. Moozing, impressed by Bessie's extensive knowledge of farm animals, plans to let her finish labeling the last n tiles of the sidewalk by herself.

Consider the resulting string s (|s| = m + n) consisting of letters labeled on tiles in order from home to school. For any sequence of indices p1 < p2 < ... < pq we can define subsequence of the string s as string sp1sp2... spq. Two subsequences are considered to be distinct if they differ as strings. Bessie wants to label the remaining part of the sidewalk such that the number of distinct subsequences of tiles is maximum possible. However, since Bessie hasn't even finished learning the alphabet, she needs your help!

Note that empty subsequence also counts.

Input

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

The second line contains a string t (|t| = m, 1 ≤ m ≤ 1 000 000) consisting of only first k lowercase English letters.

Output

Determine the maximum number of distinct subsequences Bessie can form after labeling the last n sidewalk tiles each with one of the first k lowercase English letters. Since this number can be rather large, you should print it modulo 109 + 7.

Please note, that you are not asked to maximize the remainder modulo 109 + 7! The goal is to maximize the initial value and then print the remainder.

Examples

Input

1 3
ac

Output

8

Input

0 2
aaba

Output

10

Note

In the first sample, the optimal labeling gives 8 different subsequences: "" (the empty string), "a", "c", "b", "ac", "ab", "cb", and "acb".

<image>

In the second sample, the entire sidewalk is already labeled. The are 10 possible different subsequences: "" (the empty string), "a", "b", "aa", "ab", "ba", "aaa", "aab", "aba", and "aaba". Note that some strings, including "aa", can be obtained with multiple sequences of tiles, but are only counted once.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int modx = 1e9 + 7;
long long f[2000010];
char s[1000010];
int pos[200];
int i, j, k, n, m, len, x, p;
int main() {
  scanf("%d%d", &n, &m);
  scanf("%s", s + 1);
  len = strlen(s + 1);
  f[0] = 1;
  for (i = 1; i <= len; i++) {
    if (pos[s[i]] == 0)
      f[i] = (f[i - 1] * 2) % modx;
    else
      f[i] = (f[i - 1] * 2 - f[pos[s[i]] - 1] + modx) % modx;
    pos[s[i]] = i;
  }
  for (i = len + 1; i <= len + n; i++) {
    f[i] = (f[i - 1] * 2) % modx;
    x = 0;
    p = i;
    for (j = 'a'; j < 'a' + m; j++)
      if (pos[j] < p) {
        p = pos[j];
        x = j;
      }
    if (p > 0) f[i] -= f[p - 1];
    f[i] = (f[i] + modx) % modx;
    pos[x] = i;
  }
  printf("%I64d\n", f[len + n] % modx);
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

In some other world, today is the day before Christmas Eve.

Mr. Takaha is buying N items at a department store. The regular price of the i-th item (1 \leq i \leq N) is p_i yen (the currency of Japan).

He has a discount coupon, and can buy one item with the highest price for half the regular price. The remaining N-1 items cost their regular prices. What is the total amount he will pay?

Constraints

* 2 \leq N \leq 10
* 100 \leq p_i \leq 10000
* p_i is an even number.

Input

Input is given from Standard Input in the following format:

N
p_1
p_2
:
p_N

Output

Print the total amount Mr. Takaha will pay.

Examples

Input

3
4980
7980
6980

Output

15950

Input

4
4320
4320
4320
4320

Output

15120

### Response

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

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

	int sum = 0, max = 0, tmp;
	for (int i = 0; i < N; ++i)
	{
		cin >> tmp;
		sum += tmp;
		if (tmp > max) max = tmp;
	}

	cout << sum - max / 2;
}
```


### Prompt

Develop a solution in CPP to the problem described below:

N cells are arranged in a row. Some of them may contain tokens. You are given a string s that consists of `0`s and `1`s. If the i-th character of s is `1`, the i-th cell (from left) contains a token. Otherwise, it doesn't contain a token.

Snuke wants to perform the following operation as many times as possible. In each operation, he chooses three consecutive cells. Let's call the cells X, Y, Z from left to right. In order for the operation to be valid, both X and Z must contain tokens and Y must not contain a token. Then, he removes these two tokens and puts a new token on Y.

How many operations can he perform if he performs operations in the optimal way?

Constraints

* 1 \leq N \leq 500,000
* |s| = N
* Each character in s is either `0` or `1`.

Input

Input is given from Standard Input in the following format:

N
s

Output

Print the answer.

Examples

Input

7
1010101

Output

2

Input

50
10101000010011011110001001111110000101010111100110

Output

10

### Response

```cpp
#include <bits/stdc++.h>
#define ll long long
#define mk make_pair
using namespace std;
const int inf = 1e9;
const int N = 5e5 + 5;
char s[N];
int n, cnt, dp[N], pre[N];
int main() {
	scanf("%d", &n);
	scanf("%s", s + 1);
	for (int i = 1; i <= n; i++) dp[i] = inf;
	for (int i = 1, p = 0; i <= n; i++) {
		if (s[i] == '1') cnt++;
		if (s[i] == '0') p = i;
		pre[i] = p;
	}
	for (int i = 1; i <= n; i++) {
		if (s[i] == '0') dp[i] = dp[i - 1];
		if (s[i] == '1') {
			dp[i] = dp[i - 1] + 1;
			if (s[i - 1] == '0' && i > 1) {
				dp[i] = min(dp[i], dp[pre[i - 2]] + 1);
				dp[i] = min(dp[i], dp[pre[i - 2] + 1] + 1);
			}
			if (pre[i] && s[pre[i] - 1] == '1')
				dp[i] = min(dp[i], dp[pre[i] - 2] + 1);
		}
	}
	cout << cnt - dp[n];
}
```


### Prompt

Develop a solution in CPP to the problem described below:

Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com).

It is known that a proper email address contains only such symbols as . @ and lower-case Latin letters, doesn't start with and doesn't end with a dot. Also, a proper email address doesn't start with and doesn't end with an at sign. Moreover, an email address contains exactly one such symbol as @, yet may contain any number (possible, zero) of dots.

You have to carry out a series of replacements so that the length of the result was as short as possible and it was a proper email address. If the lengths are equal, you should print the lexicographically minimal result.

Overall, two variants of replacement are possible: dot can be replaced by a dot, at can be replaced by an at.

Input

The first line contains the email address description. It is guaranteed that that is a proper email address with all the dots replaced by dot an the at signs replaced by at. The line is not empty and its length does not exceed 100 symbols.

Output

Print the shortest email address, from which the given line could be made by the described above replacements. If there are several solutions to that problem, print the lexicographically minimal one (the lexicographical comparison of the lines are implemented with an operator < in modern programming languages).

In the ASCII table the symbols go in this order: . @ ab...z

Examples

Input

vasyaatgmaildotcom

Output

vasya@gmail.com

Input

dotdotdotatdotdotat

Output

dot..@..at

Input

aatt

Output

a@t

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string w, s;
  cin >> w;
  char l, ll;
  cout << w[0];
  int a, d;
  bool b = true;
  a = d = 0;
  for (int i = 1; i < w.length(); i++) {
    if (w[i] == 'd') {
      if (i + 3 != w.length()) {
        s = w.substr(i, 3);
        if (s.compare("dot") == 0) {
          i = i + 2;
          cout << '.';
        } else {
          cout << 'd';
        }
      } else {
        cout << 'd';
      }
    } else if (b && w[i] == 'a') {
      s = w.substr(i, 2);
      if (s == "at") {
        i += 1;
        cout << '@';
        b = false;
      } else {
        cout << 'a';
      }
    } else {
      cout << w[i];
    }
  }
}

```


### Prompt

Create a solution in cpp for the following problem:

In order to pass the entrance examination tomorrow, Taro has to study for T more hours.

Fortunately, he can leap to World B where time passes X times as fast as it does in our world (World A).

While (X \times t) hours pass in World B, t hours pass in World A.

How many hours will pass in World A while Taro studies for T hours in World B?

Constraints

* All values in input are integers.
* 1 \leq T \leq 100
* 1 \leq X \leq 100

Input

Input is given from Standard Input in the following format:

T X

Output

Print the number of hours that will pass in World A.

The output will be regarded as correct when its absolute or relative error from the judge's output is at most 10^{-3}.

Examples

Input

8 3

Output

2.6666666667

Input

99 1

Output

99.0000000000

Input

1 100

Output

0.0100000000

### Response

```cpp
#include<stdio.h>
int main()
{
	float t,x;
	scanf("%d %d",&t,&x);
	printf("%f\n",t/x);
	return 0;
}

```


### Prompt

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

Roma is playing a new expansion for his favorite game World of Darkraft. He made a new character and is going for his first grind.

Roma has a choice to buy exactly one of n different weapons and exactly one of m different armor sets. Weapon i has attack modifier a_i and is worth ca_i coins, and armor set j has defense modifier b_j and is worth cb_j coins.

After choosing his equipment Roma can proceed to defeat some monsters. There are p monsters he can try to defeat. Monster k has defense x_k, attack y_k and possesses z_k coins. Roma can defeat a monster if his weapon's attack modifier is larger than the monster's defense, and his armor set's defense modifier is larger than the monster's attack. That is, a monster k can be defeated with a weapon i and an armor set j if a_i > x_k and b_j > y_k. After defeating the monster, Roma takes all the coins from them. During the grind, Roma can defeat as many monsters as he likes. Monsters do not respawn, thus each monster can be defeated at most one.

Thanks to Roma's excessive donations, we can assume that he has an infinite amount of in-game currency and can afford any of the weapons and armor sets. Still, he wants to maximize the profit of the grind. The profit is defined as the total coins obtained from all defeated monsters minus the cost of his equipment. Note that Roma must purchase a weapon and an armor set even if he can not cover their cost with obtained coins.

Help Roma find the maximum profit of the grind.

Input

The first line contains three integers n, m, and p (1 ≤ n, m, p ≤ 2 ⋅ 10^5) — the number of available weapons, armor sets and monsters respectively.

The following n lines describe available weapons. The i-th of these lines contains two integers a_i and ca_i (1 ≤ a_i ≤ 10^6, 1 ≤ ca_i ≤ 10^9) — the attack modifier and the cost of the weapon i.

The following m lines describe available armor sets. The j-th of these lines contains two integers b_j and cb_j (1 ≤ b_j ≤ 10^6, 1 ≤ cb_j ≤ 10^9) — the defense modifier and the cost of the armor set j.

The following p lines describe monsters. The k-th of these lines contains three integers x_k, y_k, z_k (1 ≤ x_k, y_k ≤ 10^6, 1 ≤ z_k ≤ 10^3) — defense, attack and the number of coins of the monster k.

Output

Print a single integer — the maximum profit of the grind.

Example

Input

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

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct T {
  long long x, y, z;
  bool operator<(const T &q) const {
    if (x != q.x) return x < q.x;
    if (y != q.y) return y < q.y;
    return z < q.z;
  }
  bool operator>(const T &q) const {
    if (x != q.x) return x > q.x;
    if (y != q.y) return y > q.y;
    return z > q.z;
  }
};
struct SEG {
  long long seg[1 << 19], la[1 << 19];
  void ini(void) {
    for (int i = 0; i < 1 << 19; i++) seg[i] = -100000000000000000, la[i] = 0;
  }
  void up(int a, long long x) {
    a += (1 << 18) - 1;
    seg[a] = max(seg[a], x);
    while (a > 0) {
      a = (a - 1) / 2;
      seg[a] = max(seg[a * 2 + 1], seg[a * 2 + 2]);
    }
  }
  void lazy(int k, int r, int l) {
    seg[k] += la[k];
    if (l - r > 0) {
      la[k * 2 + 1] += la[k];
      la[k * 2 + 2] += la[k];
    }
    la[k] = 0;
  }
  void add(int a, int b, int r, int l, int k, long long p) {
    lazy(k, r, l);
    if (a > l || b < r) return;
    if (a <= r && l <= b) {
      la[k] += p;
      lazy(k, r, l);
      return;
    }
    add(a, b, r, (r + l - 1) / 2, k * 2 + 1, p);
    add(a, b, (r + l + 1) / 2, l, k * 2 + 2, p);
    seg[k] = max(seg[k * 2 + 1], seg[k * 2 + 2]);
  }
  long long sm(void) {
    lazy(0, 0, (1 << 18) - 1);
    return seg[0];
  }
};
long long n, m, p, ans = -100000000000000000;
pair<long long, long long> a[200005], b[200005];
T c[200005];
vector<long long> cm;
SEG seg;
int main(void) {
  scanf("%lld%lld%lld", &n, &m, &p);
  for (int i = 0; i < n; i++) scanf("%lld%lld", &a[i].first, &a[i].second);
  for (int i = 0; i < m; i++) scanf("%lld%lld", &b[i].first, &b[i].second);
  for (int i = 0; i < p; i++) scanf("%lld%lld%lld", &c[i].x, &c[i].y, &c[i].z);
  sort(a, a + n);
  sort(b, b + m);
  sort(c, c + p);
  for (int i = 0; i < m; i++) {
    cm.push_back(b[i].first);
  }
  sort(cm.begin(), cm.end());
  seg.ini();
  for (int i = 0; i < m; i++) seg.up(i, -b[i].second);
  int t = 0;
  for (int i = 0; i < n; i++) {
    while (t < p && c[t].x < a[i].first) {
      if (cm.back() > c[t].y)
        seg.add(upper_bound(cm.begin(), cm.end(), c[t].y) - cm.begin(), m - 1,
                0, (1 << 18) - 1, 0, c[t].z);
      t++;
    }
    ans = max(ans, seg.sm() - a[i].second);
  }
  printf("%lld\n", ans);
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: <image>.

The lucky number of the sequence of distinct positive integers x1, x2, ..., xk (k > 1) is the number that is equal to the bitwise excluding OR of the maximum element of the sequence and the second maximum element of the sequence.

You've got a sequence of distinct positive integers s1, s2, ..., sn (n > 1). Let's denote sequence sl, sl + 1, ..., sr as s[l..r] (1 ≤ l < r ≤ n). Your task is to find the maximum number among all lucky numbers of sequences s[l..r].

Note that as all numbers in sequence s are distinct, all the given definitions make sence.

Input

The first line contains integer n (1 < n ≤ 105). The second line contains n distinct integers s1, s2, ..., sn (1 ≤ si ≤ 109).

Output

Print a single integer — the maximum lucky number among all lucky numbers of sequences s[l..r].

Examples

Input

5
5 2 1 4 3

Output

7

Input

5
9 8 3 5 7

Output

15

Note

For the first sample you can choose s[4..5] = {4, 3} and its lucky number is (4 xor 3) = 7. You can also choose s[1..2].

For the second sample you must choose s[2..5] = {8, 3, 5, 7}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long arr[100005], nxt[100005];
long long n;
void nxt_greater() {
  stack<long long> s;
  s.push(0);
  for (long long i = 1; i < n; i++) {
    while (!s.empty() && arr[s.top()] < arr[i]) {
      nxt[s.top()] = i;
      s.pop();
    }
    s.push(i);
  }
  while (!s.empty()) {
    nxt[s.top()] = -1;
    s.pop();
  }
}
int main() {
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> arr[i];
  nxt_greater();
  long long max_xor = 0;
  for (long long i = 0; i < n; i++) {
    if (nxt[i] >= 0) {
      max_xor = max(max_xor, arr[i] ^ arr[nxt[i]]);
    }
  }
  reverse(arr, arr + n);
  nxt_greater();
  for (long long i = 0; i < n; i++) {
    if (nxt[i] >= 0) {
      max_xor = max(max_xor, arr[i] ^ arr[nxt[i]]);
    }
  }
  cout << max_xor << endl;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Joisino has a lot of red and blue bricks and a large box. She will build a tower of these bricks in the following manner.

First, she will pick a total of N bricks and put them into the box. Here, there may be any number of bricks of each color in the box, as long as there are N bricks in total. Particularly, there may be zero red bricks or zero blue bricks. Then, she will repeat an operation M times, which consists of the following three steps:

* Take out an arbitrary brick from the box.
* Put one red brick and one blue brick into the box.
* Take out another arbitrary brick from the box.

After the M operations, Joisino will build a tower by stacking the 2 \times M bricks removed from the box, in the order they are taken out. She is interested in the following question: how many different sequences of colors of these 2 \times M bricks are possible? Write a program to find the answer. Since it can be extremely large, print the count modulo 10^9+7.

Constraints

* 1 \leq N \leq 3000
* 1 \leq M \leq 3000

Input

Input is given from Standard Input in the following format:

N M

Output

Print the count of the different possible sequences of colors of 2 \times M bricks that will be stacked, modulo 10^9+7.

Examples

Input

2 3

Output

56

Input

1000 10

Output

1048576

Input

1000 3000

Output

693347555

### Response

```cpp
#include<bits/stdc++.h>
#define L long long
using namespace std;
const int q=1000000007;
int n,m,f[3010][3010][2],p;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k;
	scanf("%d%d",&n,&m);
	n--;
	m--;
	for(i=1;i<=n;i++)
	  f[0][i][0]=1;
	f[0][0][1]=1;
	for(i=1;i<=m;i++)
	  {
	   for(j=0;j<=n;j++)
	     for(k=0;k<=1;k++)
	       f[i][j][k]=(f[i-1][j][k]*2ll+f[i-1][j+1][k]+(j?f[i-1][j-1][k]:0))%q;
	   f[i][0][1]=(f[i][0][1]+f[i][0][0])%q;
	   f[i][0][0]=0;
      }
	for(i=0;i<=n;i++)
	  p=(p+f[m][i][1])%q;
	p=p*4ll%q;
	printf("%d\n",p);
	return 0;
}

```


### Prompt

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

In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads.

In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simultaneously for one day. Both brigades repair one road for the whole day and cannot take part in repairing other roads on that day. But the repair brigade can do nothing on that day.

Determine the minimum number of days needed to repair all the roads. The brigades cannot change the cities where they initially are.

Input

The first line of the input contains a positive integer n (2 ≤ n ≤ 200 000) — the number of cities in Berland.

Each of the next n - 1 lines contains two numbers ui, vi, meaning that the i-th road connects city ui and city vi (1 ≤ ui, vi ≤ n, ui ≠ vi).

Output

First print number k — the minimum number of days needed to repair all the roads in Berland.

In next k lines print the description of the roads that should be repaired on each of the k days. On the i-th line print first number di — the number of roads that should be repaired on the i-th day, and then di space-separated integers — the numbers of the roads that should be repaired on the i-th day. The roads are numbered according to the order in the input, starting from one.

If there are multiple variants, you can print any of them.

Examples

Input

4
1 2
3 4
3 2

Output

2
2 2 1
1 3

Input

6
3 4
5 4
3 2
1 3
4 6

Output

3
1 1
2 2 3
2 4 5

Note

In the first sample you can repair all the roads in two days, for example, if you repair roads 1 and 2 on the first day and road 3 — on the second day.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000;
int n, x;
bool was[maxn];
vector<pair<int, int> > g[maxn];
vector<int> ans[maxn];
void dfs(int u, int c) {
  was[u] = true;
  int cur_c = 0;
  for (int i = 0; i < int(g[u].size()); i++) {
    int v = g[u][i].first;
    int id = g[u][i].second;
    if (was[v]) continue;
    if (cur_c == c) {
      cur_c++;
    }
    ans[cur_c].push_back(id);
    dfs(v, cur_c);
    cur_c++;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    g[u].push_back(make_pair(v, i));
    g[v].push_back(make_pair(u, i));
  }
  x = 0;
  int x_id = -1;
  for (int i = 0; i < n; i++) {
    was[i] = false;
    if (int(g[i].size()) > x) {
      x = g[i].size();
      x_id = i;
    }
  }
  dfs(x_id, -1);
  printf("%d\n", x);
  for (int i = 0; i < x; i++) {
    printf("%d", int(ans[i].size()));
    for (int j = 0; j < int(ans[i].size()); j++) {
      printf(" %d", ans[i][j] + 1);
    }
    printf("\n");
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 × 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone — neither any other statues, nor Anna, nor Maria.

Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is — to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.

At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.

Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.

Input

You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one — for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S".

It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S".

Output

If Maria wins, print string "WIN". If the statues win, print string "LOSE".

Examples

Input

.......A
........
........
........
........
........
........
M.......

Output

WIN

Input

.......A
........
........
........
........
........
SS......
M.......

Output

LOSE

Input

.......A
........
........
........
........
.S......
S.......
MS......

Output

LOSE

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool valid(int r, int c) { return min(r, c) >= 0 && max(r, c) < 8; }
int main() {
  ios::sync_with_stdio(0);
  vector<string> A(8);
  for (auto& s : A) cin >> s;
  vector<vector<string>> G(9);
  G[0] = A;
  for (int i = 1; i < 9; i++) {
    G[i] = G[i - 1];
    for (int r = 7; r >= 0; r--)
      for (int c = 0; c < 8; c++)
        if (G[i][r][c] == 'S') {
          G[i][r][c] = '.';
          if (r + 1 < 8) G[i][r + 1][c] = 'S';
        }
  }
  int R[11][11][11] = {};
  int dr[] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
  int dc[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
  queue<vector<int>> q;
  q.push({0, 7, 0});
  while (!q.empty()) {
    int g = q.front()[0];
    int r = q.front()[1];
    int c = q.front()[2];
    q.pop();
    if (g == 8) return cout << "WIN\n", 0;
    for (int k = 0; k < 9; k++)
      if (valid(r + dr[k], c + dc[k]) &&
          G[g + 1][r + dr[k]][c + dc[k]] != 'S' &&
          G[g][r + dr[k]][c + dc[k]] != 'S' && !R[g + 1][r + dr[k]][c + dc[k]])
        R[g + 1][r + dr[k]][c + dc[k]] = 1,
                                q.push({g + 1, r + dr[k], c + dc[k]});
  }
  cout << "LOSE\n";
}

```


### Prompt

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

You are given a sequence of n positive integers d1, d2, ..., dn (d1 < d2 < ... < dn). Your task is to construct an undirected graph such that:

  * there are exactly dn + 1 vertices;
  * there are no self-loops;
  * there are no multiple edges;
  * there are no more than 106 edges;
  * its degree set is equal to d.

Vertices should be numbered 1 through (dn + 1).

Degree sequence is an array a with length equal to the number of vertices in a graph such that ai is the number of vertices adjacent to i-th vertex.

Degree set is a sorted in increasing order sequence of all distinct values from the degree sequence.

It is guaranteed that there exists such a graph that all the conditions hold, and it contains no more than 106 edges.

Print the resulting graph.

Input

The first line contains one integer n (1 ≤ n ≤ 300) — the size of the degree set.

The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 1000, d1 < d2 < ... < dn) — the degree set.

Output

In the first line print one integer m (1 ≤ m ≤ 106) — the number of edges in the resulting graph. It is guaranteed that there exists such a graph that all the conditions hold and it contains no more than 106 edges.

Each of the next m lines should contain two integers vi and ui (1 ≤ vi, ui ≤ dn + 1) — the description of the i-th edge.

Examples

Input

3
2 3 4

Output

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

Input

3
1 2 3

Output

4
1 2
1 3
1 4
2 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int M = 1024;
int save[M];
int main(void) {
  int n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> save[i];
  int vecs = save[n] + 1;
  int r = n, l = 1, ready = 0;
  for (int vec = 1; vec < vecs; vec++) {
    if (save[l] <= ready)
      l++, r--;
    else if (ready + vecs - vec == save[r])
      ready++, ans += vecs - vec;
  }
  printf("%d\n", ans);
  r = n, l = 1, ready = 0;
  for (int vec = 1; vec < vecs; vec++) {
    if (save[l] <= ready)
      l++, r--;
    else if (ready + vecs - vec == save[r]) {
      for (int j = vec + 1; j <= vecs; j++) printf("%d %d\n", vec, j);
      ready++;
      ans += vecs - vec;
    }
  }
  return 0;
}

```


### Prompt

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

This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You may also refer to the guide on interactive problems: <https://codeforces.com/blog/entry/45307>.

The jury guessed some array a consisting of 6 integers. There are 6 special numbers — 4, 8, 15, 16, 23, 42 — and each of these numbers occurs in a exactly once (so, a is some permutation of these numbers).

You don't know anything about their order, but you are allowed to ask up to 4 queries. In each query, you may choose two indices i and j (1 ≤ i, j ≤ 6, i and j are not necessarily distinct), and you will get the value of a_i ⋅ a_j in return.

Can you guess the array a?

The array a is fixed beforehand in each test, the interaction program doesn't try to adapt to your queries.

Interaction

Before submitting the answer, you may ask up to 4 queries. To ask a query, print one line in the following format: ? i j, where i and j should be two integers such that 1 ≤ i, j ≤ 6. The line should be ended with a line break character. After submitting a query, flush the output and read the answer to your query — one line containing one integer a_i ⋅ a_j. If you submit an incorrect query (or ask more than 4 queries), the answer to it will be one string 0. After receiving such an answer, your program should terminate immediately — otherwise you may receive verdict "Runtime error", "Time limit exceeded" or some other verdict instead of "Wrong answer".

To give the answer, your program should print one line ! a_1 a_2 a_3 a_4 a_5 a_6 with a line break in the end. After that, it should flush the output and terminate gracefully.

Example

Input

16
64
345
672

Output

? 1 1
? 2 2
? 3 5
? 4 6
! 4 8 15 16 23 42

Note

If you want to submit a hack for this problem, your test should contain exactly six space-separated integers a_1, a_2, ..., a_6. Each of 6 special numbers should occur exactly once in the test. The test should be ended with a line break character.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF_LL = 1e18 + 7;
const int INF_int = 1e9 + 7;
const int maxn = 123;
const int N = 3e5 + 1;
int32_t main() {
  cout << fixed << setprecision(15);
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  vector<long long> a(100);
  long long x = 0;
  for (int i = 16256; i < 16356; ++i) a[i - 16256] = i;
  cout << "? ";
  for (int i = 0; i < 100; ++i) cout << a[i] << ' ';
  cout << '\n' << flush;
  int temp, temp2 = 16256;
  cin >> temp;
  temp = ~temp;
  temp &= temp2;
  x |= temp;
  x << 7;
  for (int i = 0; i < 100; ++i) a[i] = 127 + 128 * i;
  cout << "? ";
  for (int i = 0; i < 100; ++i) cout << a[i] << ' ';
  cout << '\n' << flush;
  cin >> temp;
  temp = ~temp;
  temp2 = 127;
  temp = temp2 & temp;
  x |= temp;
  cout << "! " << x << '\n' << flush;
}

```


### Prompt

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

Barney was hanging out with Nora for a while and now he thinks he may have feelings for her. Barney wants to send her a cheesy text message and wants to make her as happy as possible.

<image>

Initially, happiness level of Nora is 0. Nora loves some pickup lines like "I'm falling for you" and stuff. Totally, she knows n pickup lines, each consisting only of lowercase English letters, also some of them may be equal (in writing, but different in pronouncing or meaning though). Every time Nora sees i-th pickup line as a consecutive subsequence of Barney's text message her happiness level increases by ai. These substrings may overlap, for example, Nora will see the pickup line aa twice and the pickup line ab once in text message aaab.

Due to texting app limits, Barney's text may have up to l characters.

Barney asked you to help him make Nora as much happy as possible, it's gonna be legen...

Input

The first line of input contains two integers n and l (1 ≤ n ≤ 200, 1 ≤ l ≤ 1014) — the number of pickup lines and the maximum length of Barney's text.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100), meaning that Nora's happiness level increases by ai after every time seeing i-th pickup line.

The next n lines contain the pickup lines. i-th of them contains a single string si consisting of only English lowercase letter. Summary length of all pickup lines does not exceed 200.

All strings are not empty.

Output

Print the only integer — the maximum possible value of Nora's happiness level after reading Barney's text.

Examples

Input

3 6
3 2 1
heart
earth
art

Output

6

Input

3 6
3 2 8
heart
earth
art

Output

16

Note

An optimal answer for the first sample case is hearth containing each pickup line exactly once.

An optimal answer for the second sample case is artart.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 210;
struct matrix {
  long long A[N][N];
  matrix() { memset(A, 0xcf, sizeof(A)); }
} G, dp;
long long n;
long long m;
long long a[N], sum[N], ans;
long long ch[N][26], fail[N], tot = 1;
char s[N];
queue<long long> q;
matrix Mul(matrix X, matrix Y) {
  matrix Z;
  for (long long i = 1; i <= tot; i++) {
    for (long long j = 1; j <= tot; j++) {
      for (long long k = 1; k <= tot; k++) {
        Z.A[i][j] = max(Z.A[i][j], X.A[i][k] + Y.A[k][j]);
      }
    }
  }
  return Z;
}
matrix ksm(matrix X, long long y) {
  matrix Z;
  for (long long i = 1; i <= tot; i++) Z.A[i][i] = 0;
  while (y) {
    if (y & 1) Z = Mul(Z, X);
    X = Mul(X, X);
    y >>= 1;
  }
  return Z;
}
int main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (long long i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    long long p = 1;
    long long len = strlen(s + 1);
    for (long long j = 1; j <= len; j++) {
      if (!ch[p][s[j] - 'a']) ch[p][s[j] - 'a'] = ++tot;
      p = ch[p][s[j] - 'a'];
    }
    sum[p] += a[i];
  }
  for (long long i = 0; i < 26; i++) ch[0][i] = 1;
  fail[1] = 0;
  q.push(1);
  while (!q.empty()) {
    long long p = q.front();
    q.pop();
    sum[p] += sum[fail[p]];
    for (long long i = 0; i < 26; i++) {
      if (ch[p][i]) {
        fail[ch[p][i]] = ch[fail[p]][i];
        q.push(ch[p][i]);
      } else {
        ch[p][i] = ch[fail[p]][i];
      }
    }
  }
  for (long long i = 1; i <= tot; i++) {
    for (long long c = 0; c < 26; c++) {
      long long j = ch[i][c];
      G.A[i][j] = sum[j];
    }
  }
  G = ksm(G, m);
  dp.A[1][1] = 0;
  dp = Mul(dp, G);
  for (long long i = 1; i <= tot; i++) ans = max(ans, dp.A[1][i]);
  cout << ans;
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.

Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough.

Right now there are A yellow and B blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls.

Input

The first line features two integers A and B (0 ≤ A, B ≤ 109), denoting the number of yellow and blue crystals respectively at Grisha's disposal.

The next line contains three integers x, y and z (0 ≤ x, y, z ≤ 109) — the respective amounts of yellow, green and blue balls to be obtained.

Output

Print a single integer — the minimum number of crystals that Grisha should acquire in addition.

Examples

Input

4 3
2 1 1

Output

2

Input

3 9
1 1 3

Output

1

Input

12345678 87654321
43043751 1000000000 53798715

Output

2147483648

Note

In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, x, y, z, c = 0, ye = 0, bl = 0;
  scanf("%lld%lld%lld%lld%lld", &n, &m, &x, &y, &z);
  ye += 2 * x;
  ye += y;
  bl += y;
  bl += 3 * z;
  if (ye > n) c += ye - n;
  if (bl > m) c += bl - m;
  cout << c << endl;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Steve Rogers is fascinated with new vibranium shields S.H.I.E.L.D gave him. They're all uncolored. There are n shields in total, the i-th shield is located at point (xi, yi) of the coordinate plane. It's possible that two or more shields share the same location.

Steve wants to paint all these shields. He paints each shield in either red or blue. Painting a shield in red costs r dollars while painting it in blue costs b dollars.

Additionally, there are m constraints Steve wants to be satisfied. The i-th constraint is provided by three integers ti, li and di:

  * If ti = 1, then the absolute difference between the number of red and blue shields on line x = li should not exceed di.
  * If ti = 2, then the absolute difference between the number of red and blue shields on line y = li should not exceed di.

Steve gave you the task of finding the painting that satisfies all the condition and the total cost is minimum.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100 000) — the number of shields and the number of constraints respectively.

The second line contains two integers r and b (1 ≤ r, b ≤ 109).

The next n lines contain the shields coordinates. The i-th of these lines contains two integers xi and yi (1 ≤ xi, yi ≤ 109).

The next m lines contain the constrains. The j-th of these lines contains three integers tj, lj and dj (1 ≤ tj ≤ 2, 1 ≤ lj ≤ 109, 0 ≤ dj ≤ n).

Output

If satisfying all the constraints is impossible print -1 in first and only line of the output.

Otherwise, print the minimum total cost in the first line of output. In the second line print a string of length n consisting of letters 'r' and 'b' only. The i-th character should be 'r' if the i-th shield should be painted red in the optimal answer and 'b' if it should be painted blue. The cost of painting shields in these colors should be equal the minimum cost you printed on the first line.

If there exist more than one optimal solution, print any of them.

Examples

Input

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

Output

25
rbrbb

Input

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

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 11;
int n, m, R, B;
int bx[N], by[N];
int totx, toty;
int upx[N], upy[N], lowx[N], lowy[N];
int S = 200000 + 1, T = 200000 + 2, s = 200000 + 3, t = 200000 + 4;
int du[N];
int head[N], nex[N * 6], to[N * 6], wei[N * 6], size = 1;
int dis[N], dl[N], cur[N];
int Sx[N], Sy[N];
struct node {
  int x, y;
} sd[N];
void add(int x, int y, int z) {
  to[++size] = y;
  nex[size] = head[x];
  head[x] = size;
  wei[size] = z;
  to[++size] = x;
  nex[size] = head[y];
  head[y] = size;
  wei[size] = 0;
}
bool bfs(int s, int t) {
  int hd = 0, tl = 1;
  dl[1] = s;
  memset(dis, -1, sizeof(dis));
  dis[s] = 0;
  while (hd < tl) {
    int u = dl[++hd];
    for (int i = head[u]; i; i = nex[i]) {
      int v = to[i];
      if (dis[v] != -1 || wei[i] <= 0) continue;
      dis[v] = dis[u] + 1;
      dl[++tl] = v;
    }
  }
  return dis[t] != -1;
}
int dfs(int u, int w, int t) {
  if (u == t || w == 0) return w;
  int s = 0;
  for (int &i = cur[u]; i; i = nex[i]) {
    int v = to[i];
    if (wei[i] <= 0 || dis[v] != dis[u] + 1) continue;
    int add = dfs(v, min(w, wei[i]), t);
    if (add > 0) {
      s += add;
      wei[i] -= add;
      wei[i ^ 1] += add;
      w -= add;
      if (!w) break;
    }
  }
  return s;
}
int dinic(int s, int t) {
  int ans = 0;
  while (bfs(s, t)) {
    memcpy(cur, head, sizeof(head));
    int add;
    do {
      add = dfs(s, 1e9, t);
      ans += add * (add > 0);
    } while (add > 0);
  }
  return ans;
}
int main() {
  cin >> n >> m >> R >> B;
  bool fl = 0;
  if (R < B) swap(R, B), fl = 1;
  int x, y;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    sd[i].x = x, sd[i].y = y;
    bx[++totx] = x;
    by[++toty] = y;
  }
  sort(bx + 1, bx + 1 + totx);
  sort(by + 1, by + 1 + toty);
  totx = unique(bx + 1, bx + 1 + totx) - (bx + 1);
  toty = unique(by + 1, by + 1 + toty) - (by + 1);
  for (int i = 1; i <= n; i++) {
    sd[i].x = lower_bound(bx + 1, bx + 1 + totx, sd[i].x) - bx;
    sd[i].y = lower_bound(by + 1, by + 1 + toty, sd[i].y) - by;
    Sx[sd[i].x]++;
    Sy[sd[i].y]++;
    add(sd[i].x, sd[i].y + totx, 1);
  }
  for (int i = 1; i <= totx; i++) upx[i] = Sx[i];
  for (int i = 1; i <= toty; i++) upy[i] = Sy[i];
  int typ, l, d;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &typ, &l, &d);
    if (typ == 1) {
      x = lower_bound(bx + 1, bx + 1 + totx, l) - bx;
      if (bx[x] != l) continue;
      lowx[x] = max(lowx[x], (Sx[x] - d + 1) / 2);
      upx[x] = min(upx[x], (Sx[x] + d) / 2);
      if (lowx[x] > upx[x]) {
        puts("-1");
        return 0;
      }
    }
    if (typ == 2) {
      y = lower_bound(by + 1, by + 1 + toty, l) - by;
      if (by[y] != l) continue;
      lowy[y] = max(lowy[y], (Sy[y] - d + 1) / 2);
      upy[y] = min(upy[y], (Sy[y] + d) / 2);
      if (lowy[y] > upy[y]) {
        puts("-1");
        return 0;
      }
    }
  }
  for (int i = 1; i <= totx; i++) {
    add(S, i, upx[i] - lowx[i]);
    du[S] -= lowx[i];
    du[i] += lowx[i];
  }
  for (int i = 1; i <= toty; i++) {
    add(i + totx, T, upy[i] - lowy[i]);
    du[i + totx] -= lowy[i];
    du[T] += lowy[i];
  }
  int s0 = 0;
  for (int i = 1; i <= T; i++) {
    if (!du[i]) continue;
    if (du[i] < 0) add(i, t, -du[i]);
    if (du[i] > 0) add(s, i, du[i]), s0 += du[i];
  }
  add(T, S, 1e9);
  int tim = dinic(s, t);
  if (tim != s0) {
    puts("-1");
    return 0;
  }
  tim = dinic(S, T);
  long long ans = 1LL * R * n - 1LL * tim * (R - B);
  printf("%lld\n", ans);
  for (int i = 1; i <= n; i++) {
    if (wei[i * 2] == 0) {
      printf("%c", fl == 1 ? 'r' : 'b');
    } else
      printf("%c", fl == 1 ? 'b' : 'r');
  }
  puts("");
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

You are a car race organizer and would like to arrange some races in Linear Kingdom.

Linear Kingdom has n consecutive roads spanning from left to right. The roads are numbered from 1 to n from left to right, thus the roads follow in the order of their numbers' increasing. There will be several races that may be held on these roads. Each race will use a consecutive subset of these roads. Also, each race will pay some amount of money to you if this race is held. No races overlap in time, so some roads can be used in several races.

Unfortunately, some of the roads are in a bad condition and they need repair. Each road has repair costs associated with it, you are required to pay this cost to repair the road. A race can only take place if all the roads used in the race are renovated. Your task is to repair such roads (possibly all or none) that will maximize your profit. Your profit is defined as the total money you get from the races that are held minus the total money you spent to repair the roads. Note that you may decide not to repair any road and gain zero profit.

Print the maximum profit you can gain.

Input

The first line contains two single-space separated integers, n and m (1 ≤ n, m ≤ 2·105), denoting the number of roads and the number of races, respectively.

Then n lines follow, each line will contain a single non-negative integer not exceeding 109 denoting the cost to repair a road. The costs are given in order from road 1 to road n.

Finally, m lines follow. Each line is single-space-separated triplets of integers. Each triplet will be given as lb, ub, and p (1 ≤ lb ≤ ub ≤ n, 1 ≤ p ≤ 109), which means that the race these three integers describe will use all the roads from lb to ub, inclusive, and if it's held you get p.

Output

Print a single integer denoting the maximum possible profit you can gain.

Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is recommended to use cin, cout stream (also you may use %I64d specificator).

Examples

Input

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

Output

4

Input

2 1
0
3
1 2 5

Output

2

Input

3 1
10
10
10
1 3 10

Output

0

Note

In the first sample the optimal solution is to repair roads 1, 2, 3, and 7. Three races will take place which nets you 15. The road repair costs 11, hence your profit is 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int SN = 1 << 19;
int n, m;
int arr[N];
long long dp[N];
vector<pair<int, int> > v[N];
int l, r, x;
long long segtree[SN];
long long lazy[SN];
void push(int l, int r, int node) {
  segtree[node] += lazy[node];
  if (l != r) {
    lazy[node + node] += lazy[node];
    lazy[node + node + 1] += lazy[node];
  }
  lazy[node] = 0;
}
void update(int l, int r, int node, int ql, int qr, long long val) {
  push(l, r, node);
  if (l > qr || r < ql) {
    return;
  }
  if (l >= ql && r <= qr) {
    lazy[node] = val;
    push(l, r, node);
    return;
  }
  int mid = l + r >> 1;
  update(l, mid, node + node, ql, qr, val);
  update(mid + 1, r, node + node + 1, ql, qr, val);
  segtree[node] = max(segtree[node + node], segtree[node + node + 1]);
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", arr + i);
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d %d", &l, &r, &x);
    v[l].emplace_back(make_pair(r, x));
  }
  dp[n + 1] = 0;
  for (int i = n; i >= 1; --i) {
    for (auto it : v[i]) {
      update(1, n, 1, it.first, n, it.second);
    }
    update(1, n, 1, i, n, -arr[i]);
    update(1, n, 1, i, i, dp[i + 1]);
    dp[i] = max(dp[i + 1], segtree[1]);
  }
  printf("%lld\n", dp[1]);
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country.

Here are some interesting facts about XXX:

  1. XXX consists of n cities, k of whose (just imagine!) are capital cities.
  2. All of cities in the country are beautiful, but each is beautiful in its own way. Beauty value of i-th city equals to ci.
  3. All the cities are consecutively connected by the roads, including 1-st and n-th city, forming a cyclic route 1 — 2 — ... — n — 1. Formally, for every 1 ≤ i < n there is a road between i-th and i + 1-th city, and another one between 1-st and n-th city.
  4. Each capital city is connected with each other city directly by the roads. Formally, if city x is a capital city, then for every 1 ≤ i ≤ n, i ≠ x, there is a road between cities x and i.
  5. There is at most one road between any two cities.
  6. Price of passing a road directly depends on beauty values of cities it connects. Thus if there is a road between cities i and j, price of passing it equals ci·cj.

Mishka started to gather her things for a trip, but didn't still decide which route to follow and thus she asked you to help her determine summary price of passing each of the roads in XXX. Formally, for every pair of cities a and b (a < b), such that there is a road between a and b you are to find sum of products ca·cb. Will you help her?

Input

The first line of the input contains two integers n and k (3 ≤ n ≤ 100 000, 1 ≤ k ≤ n) — the number of cities in XXX and the number of capital cities among them.

The second line of the input contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 10 000) — beauty values of the cities.

The third line of the input contains k distinct integers id1, id2, ..., idk (1 ≤ idi ≤ n) — indices of capital cities. Indices are given in ascending order.

Output

Print the only integer — summary price of passing each of the roads in XXX.

Examples

Input

4 1
2 3 1 2
3

Output

17

Input

5 2
3 5 2 2 4
1 4

Output

71

Note

This image describes first sample case:

<image>

It is easy to see that summary price is equal to 17.

This image describes second sample case:

<image>

It is easy to see that summary price is equal to 71.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100001;
int c[MAX_N];
int n;
int prev(int i) {
  if (i > 1) {
    return i - 1;
  }
  return n;
}
int next(int i) {
  if (i < n) {
    return i + 1;
  }
  return 1;
}
int main() {
  int k;
  cin >> n >> k;
  long long ts = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> c[i];
    ts += c[i];
  }
  set<int> sc;
  long long cs = 0;
  for (int i = 0; i < k; ++i) {
    int t;
    cin >> t;
    sc.insert(t);
    cs += c[t];
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (sc.find(i) != sc.end()) {
      ans += (ts - c[i]) * c[i];
    } else {
      ans += cs * c[i];
      if (sc.find(prev(i)) == sc.end()) {
        ans += c[prev(i)] * c[i];
      }
      if (sc.find(next(i)) == sc.end()) {
        ans += c[next(i)] * c[i];
      }
    }
  }
  cout << ans / 2;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Alice has got addicted to a game called Sirtet recently.

In Sirtet, player is given an n × m grid. Initially a_{i,j} cubes are stacked up in the cell (i,j). Two cells are called adjacent if they share a side. Player can perform the following operations:

  * stack up one cube in two adjacent cells;
  * stack up two cubes in one cell.

Cubes mentioned above are identical in height.

Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation.

<image>

Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations.

Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that

  * L ≤ a_{i,j} ≤ R for all 1 ≤ i ≤ n, 1 ≤ j ≤ m;
  * player can reach the goal using above operations.

Please help Alice with it. Notice that the answer might be large, please output the desired value modulo 998,244,353.

Input

The only line contains four integers n, m, L and R (1≤ n,m,L,R ≤ 10^9, L ≤ R, n ⋅ m ≥ 2).

Output

Output one integer, representing the desired answer modulo 998,244,353.

Examples

Input

2 2 1 1

Output

1

Input

1 2 1 2

Output

2

Note

In the first sample, the only initial grid that satisfies the requirements is a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1. Thus the answer should be 1.

In the second sample, initial grids that satisfy the requirements are a_{1,1}=a_{1,2}=1 and a_{1,1}=a_{1,2}=2. Thus the answer should be 2.

### Response

```cpp
#include <bits/stdc++.h>
const int moder = 998244353;
struct matrix {
  const static int N = 2;
  int a[N][N]{};
  int *operator[](const int &n) { return a[n]; }
  matrix operator*(const matrix &m) const {
    matrix ret;
    for (int k = 0; k < N; ++k) {
      for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
          ret[i][j] = (ret[i][j] + 1ll * a[i][k] * m.a[k][j]) % moder;
        }
      }
    }
    return ret;
  }
};
using ll = long long;
matrix powermod(matrix a, ll exp) {
  matrix ret;
  ret[0][0] = ret[1][1] = 1;
  for (; exp > 0; exp >>= 1) {
    if (exp & 1) {
      ret = ret * a;
    }
    a = a * a;
  }
  return ret;
}
int main() {
  int n, m, l, r;
  scanf("%d%d%d%d", &n, &m, &l, &r);
  int zero = r / 2 - (l - 1) / 2;
  int one = r - l + 1 - zero;
  matrix trans;
  trans[0][0] = trans[1][1] = zero;
  trans[0][1] = trans[1][0] = one;
  trans = powermod(trans, 1ll * n * m);
  if (1ll * n * m % 2 != 0) {
    printf("%d\n", (trans[0][0] + trans[1][0]) % moder);
  } else {
    printf("%d\n", trans[0][0]);
  }
  return 0;
}

```


### Prompt

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

Slime has a sequence of positive integers a_1, a_2, …, a_n.

In one operation Orac can choose an arbitrary subsegment [l … r] of this sequence and replace all values a_l, a_{l + 1}, …, a_r to the value of median of \\{a_l, a_{l + 1}, …, a_r\}.

In this problem, for the integer multiset s, the median of s is equal to the ⌊ (|s|+1)/(2)⌋-th smallest number in it. For example, the median of \{1,4,4,6,5\} is 4, and the median of \{1,7,5,8\} is 5.

Slime wants Orac to make a_1 = a_2 = … = a_n = k using these operations.

Orac thinks that it is impossible, and he does not want to waste his time, so he decided to ask you if it is possible to satisfy the Slime's requirement, he may ask you these questions several times.

Input

The first line of the input is a single integer t: the number of queries.

The first line of each query contains two integers n\ (1≤ n≤ 100 000) and k\ (1≤ k≤ 10^9), the second line contains n positive integers a_1,a_2,...,a_n\ (1≤ a_i≤ 10^9)

The total sum of n is at most 100 000.

Output

The output should contain t lines. The i-th line should be equal to 'yes' if it is possible to make all integers k in some number of operations or 'no', otherwise. You can print each letter in lowercase or uppercase.

Example

Input

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

Output

no
yes
yes
no
yes

Note

In the first query, Orac can't turn all elements into 3.

In the second query, a_1=6 is already satisfied.

In the third query, Orac can select the complete array and turn all elements into 2.

In the fourth query, Orac can't turn all elements into 3.

In the fifth query, Orac can select [1,6] at first and then select [2,10].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, inf = 1e9 + 7;
const int N = 1e5 + 5, M = 1e7 + 5;
int n, k;
int a[N];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      if (x < k) a[i] = 0;
      if (x == k) a[i] = 1;
      if (x > k) a[i] = 2;
    }
    bool ck = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] == 1) {
        ck = 1;
        break;
      }
    }
    if (!ck) {
      cout << "NO" << '\n';
      continue;
    }
    if (n == 1) {
      cout << "YES" << '\n';
      continue;
    }
    ck = 0;
    for (int i = 1; i < n; i++) {
      if (a[i] > 0 && a[i + 1] > 0) {
        ck = 1;
        break;
      }
    }
    for (int i = 1; i < n - 1; i++) {
      if (a[i] > 0 && a[i + 2] > 0) {
        ck = 1;
        break;
      }
    }
    if (!ck) {
      cout << "NO" << '\n';
      continue;
    }
    cout << "YES" << '\n';
  }
}

```


### Prompt

Generate a Cpp solution to the following problem:

a is an array of n positive integers, all of which are not greater than n.

You have to process q queries to this array. Each query is represented by two numbers p and k. Several operations are performed in each query; each operation changes p to p + ap + k. There operations are applied until p becomes greater than n. The answer to the query is the number of performed operations.

Input

The first line contains one integer n (1 ≤ n ≤ 100000).

The second line contains n integers — elements of a (1 ≤ ai ≤ n for each i from 1 to n).

The third line containts one integer q (1 ≤ q ≤ 100000).

Then q lines follow. Each line contains the values of p and k for corresponding query (1 ≤ p, k ≤ n).

Output

Print q integers, ith integer must be equal to the answer to ith query.

Example

Input

3
1 1 1
3
1 1
2 1
3 1

Output

2
1
1

Note

Consider first example:

In first query after first operation p = 3, after second operation p = 5.

In next two queries p is greater than n after the first operation.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1E5 + 5;
int n, q, a[maxN], f[400][maxN];
void prep() {
  memset(f, 0, sizeof f);
  for (int k = 1; k <= sqrt(n) + 10; ++k)
    for (int p = n; p > 0; --p) {
      f[k][p] = 1;
      if (p + a[p] + k <= n) f[k][p] += f[k][p + a[p] + k];
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  prep();
  scanf("%d", &q);
  while (q--) {
    int p, k;
    scanf("%d%d", &p, &k);
    if (k > sqrt(n) + 10) {
      int ans = 0;
      while (p <= n) ++ans, p += a[p] + k;
      printf("%d\n", ans);
    } else
      printf("%d\n", f[k][p]);
  }
  return 0;
}

```


### Prompt

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

Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly 1 problem, during the second day — exactly 2 problems, during the third day — exactly 3 problems, and so on. During the k-th day he should solve k problems.

Polycarp has a list of n contests, the i-th contest consists of a_i problems. During each day Polycarp has to choose exactly one of the contests he didn't solve yet and solve it. He solves exactly k problems from this contest. Other problems are discarded from it. If there are no contests consisting of at least k problems that Polycarp didn't solve yet during the k-th day, then Polycarp stops his training.

How many days Polycarp can train if he chooses the contests optimally?

Input

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

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 2 ⋅ 10^5) — the number of problems in the i-th contest.

Output

Print one integer — the maximum number of days Polycarp can train if he chooses the contests optimally.

Examples

Input

4
3 1 4 1

Output

3

Input

3
1 1 1

Output

1

Input

5
1 1 1 2 2

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main() {
  int n;
  scanf("%d", &n);
  int i, j;
  int sum = 0;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (i = 1, j = 1; i <= n;) {
    if (a[i] >= j) {
      sum++;
      i++;
      j++;
    } else {
      i++;
    }
  }
  cout << sum << endl;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Polycarp analyzes the prices of the new berPhone. At his disposal are the prices for n last days: a_1, a_2, ..., a_n, where a_i is the price of berPhone on the day i.

Polycarp considers the price on the day i to be bad if later (that is, a day with a greater number) berPhone was sold at a lower price. For example, if n=6 and a=[3, 9, 4, 6, 7, 5], then the number of days with a bad price is 3 — these are days 2 (a_2=9), 4 (a_4=6) and 5 (a_5=7).

Print the number of days with a bad price.

You have to answer t independent data sets.

Input

The first line contains an integer t (1 ≤ t ≤ 10000) — the number of sets of input data in the test. Input data sets must be processed independently, one after another.

Each input data set consists of two lines. The first line contains an integer n (1 ≤ n ≤ 150000) — the number of days. The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^6), where a_i is the price on the i-th day.

It is guaranteed that the sum of n over all data sets in the test does not exceed 150000.

Output

Print t integers, the j-th of which should be equal to the number of days with a bad price in the j-th input data set.

Example

Input

5
6
3 9 4 6 7 5
1
1000000
2
2 1
10
31 41 59 26 53 58 97 93 23 84
7
3 2 1 2 3 4 5

Output

3
0
1
8
2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[150005];
int main() {
  int T, n;
  cin >> T;
  while (T--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    if (n == 1) {
      puts("0");
      continue;
    }
    int c = 0, m = a[n - 1];
    for (int i = n - 2; i >= 0; i--) {
      if (a[i] > m) c++;
      m = min(a[i], m);
    }
    cout << c << endl;
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Today the North Pole hosts an Olympiad in a sport called... toy igloo skyscrapers' building!

There are n walruses taking part in the contest. Each walrus is given a unique number from 1 to n. After start each walrus begins to build his own igloo skyscraper. Initially, at the moment of time equal to 0, the height of the skyscraper i-th walrus is equal to ai. Each minute the i-th walrus finishes building bi floors.

The journalists that are reporting from the spot where the Olympiad is taking place, make q queries to the organizers. Each query is characterized by a group of three numbers li, ri, ti. The organizers respond to each query with a number x, such that:

1. Number x lies on the interval from li to ri inclusive (li ≤ x ≤ ri).

2. The skyscraper of the walrus number x possesses the maximum height among the skyscrapers of all walruses from the interval [li, ri] at the moment of time ti.

For each journalists' query print the number of the walrus x that meets the above-given criteria. If there are several possible answers, print any of them.

Input

The first line contains numbers n and q (1 ≤ n, q ≤ 105). Next n lines contain pairs of numbers ai, bi (1 ≤ ai, bi ≤ 109). Then follow q queries i the following format li, ri, ti, one per each line (1 ≤ li ≤ ri ≤ n, 0 ≤ ti ≤ 106). All input numbers are integers.

Output

For each journalists' query print the number of the walrus x that meets the criteria, given in the statement. Print one number per line.

Examples

Input

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

Output

5
2
1
5

Input

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

Output

3
3
3
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10, SQRT = 350;
template <class T>
void setmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}
struct line {
  long long m, b;
  int id;
  void read(int i) {
    cin >> b >> m;
    id = i;
  }
  long long val(long long x) const { return m * x + b; }
  bool operator<(const line &a) const {
    if (m != a.m) {
      return m < a.m;
    }
    return b < a.b;
  }
};
struct query {
  int l, r;
  long long t;
  int id;
  void read(int i) {
    cin >> l >> r >> t;
    l--;
    id = i;
  }
  bool operator<(const query &a) const { return t < a.t; }
};
int N, Q;
line lines[MAXN];
vector<line> blocks[MAXN / SQRT + 1];
int bptr[MAXN / SQRT + 1];
query queries[MAXN];
int ans[MAXN];
void add_seg(vector<line> &v, line t) {
  while (v.size() >= 2) {
    line b = v.back(), a = v[v.size() - 2];
    if ((b.b - a.b) * (t.m - a.m) <= (t.b - a.b) * (b.m - a.m)) {
      v.pop_back();
    } else {
      break;
    }
  }
  v.push_back(t);
}
int main() {
  cin >> N >> Q;
  for (int i = 0; i < N; i++) {
    lines[i].read(i);
    blocks[i / SQRT].push_back(lines[i]);
  }
  for (int i = 0; i < Q; i++) {
    queries[i].read(i);
  }
  for (int i = 0; i <= N / SQRT; i++) {
    sort(blocks[i].begin(), blocks[i].end());
    vector<line> v;
    for (int j = 0, siz = blocks[i].size(); j < siz; j++) {
      add_seg(v, blocks[i][j]);
    }
    blocks[i] = v;
  }
  sort(queries, queries + Q);
  for (int i = 0; i < Q; i++) {
    int a = queries[i].l, b = queries[i].r;
    long long t = queries[i].t;
    pair<long long, int> res(-1, -1);
    if (b / SQRT - a / SQRT <= 1) {
      for (int j = a; j < b; j++) {
        setmax(res, make_pair(lines[j].val(t), j));
      }
    } else {
      int ptr = a;
      for (; ptr % SQRT; ptr++) {
        setmax(res, make_pair(lines[ptr].val(t), ptr));
      }
      for (; ptr / SQRT < b / SQRT; ptr += SQRT) {
        int c = ptr / SQRT;
        int &b = bptr[c];
        while (b + 1 < blocks[c].size() &&
               blocks[c][b + 1].val(t) >= blocks[c][b].val(t)) {
          b++;
        }
        setmax(res, make_pair(blocks[c][b].val(t), blocks[c][b].id));
      }
      for (; ptr < b; ptr++) {
        setmax(res, make_pair(lines[ptr].val(t), ptr));
      }
    }
    ans[queries[i].id] = res.second;
  }
  for (int i = 0; i < Q; i++) {
    cout << ans[i] + 1 << '\n';
  }
}

```


### Prompt

Please create a solution in cpp to the following problem:

Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.

There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index k such that Mr. Black can exit the house after opening the first k doors.

We have to note that Mr. Black opened each door at most once, and in the end all doors became open.

Input

The first line contains integer n (2 ≤ n ≤ 200 000) — the number of doors.

The next line contains n integers: the sequence in which Mr. Black opened the doors. The i-th of these integers is equal to 0 in case the i-th opened door is located in the left exit, and it is equal to 1 in case it is in the right exit.

It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit.

Output

Print the smallest integer k such that after Mr. Black opened the first k doors, he was able to exit the house.

Examples

Input

5
0 0 1 0 0

Output

3

Input

4
1 0 0 1

Output

3

Note

In the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.

When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.

In the second example when the first two doors were opened, there was open closed door in each of the exit.

With three doors opened Mr. Black was able to use the left exit.

### Response

```cpp
#include <bits/stdc++.h>
int c[300002], k0, k1;
using namespace std;
int main() {
  int n, x;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (x == 1) {
      k1 = i;
    } else
      k0 = i;
  }
  cout << min(k1, k0);
}

```


### Prompt

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

DZY loves Fast Fourier Transformation, and he enjoys using it.

Fast Fourier Transformation is an algorithm used to calculate convolution. Specifically, if a, b and c are sequences with length n, which are indexed from 0 to n - 1, and

<image>

We can calculate c fast using Fast Fourier Transformation.

DZY made a little change on this formula. Now

<image>

To make things easier, a is a permutation of integers from 1 to n, and b is a sequence only containing 0 and 1. Given a and b, DZY needs your help to calculate c.

Because he is naughty, DZY provides a special way to get a and b. What you need is only three integers n, d, x. After getting them, use the code below to generate a and b.

    //x is 64-bit variable;
    function getNextX() {
        x = (x * 37 + 10007) % 1000000007;
        return x;
    }
    function initAB() {
        for(i = 0; i < n; i = i + 1){
            a[i] = i + 1;
        }
        for(i = 0; i < n; i = i + 1){
            swap(a[i], a[getNextX() % (i + 1)]);
        }
        for(i = 0; i < n; i = i + 1){
            if (i < d)
                b[i] = 1;
            else
                b[i] = 0;
        }
        for(i = 0; i < n; i = i + 1){
            swap(b[i], b[getNextX() % (i + 1)]);
        }
    }

Operation x % y denotes remainder after division x by y. Function swap(x, y) swaps two values x and y.

Input

The only line of input contains three space-separated integers n, d, x (1 ≤ d ≤ n ≤ 100000; 0 ≤ x ≤ 1000000006). Because DZY is naughty, x can't be equal to 27777500.

Output

Output n lines, the i-th line should contain an integer ci - 1.

Examples

Input

3 1 1

Output

1
3
2

Input

5 4 2

Output

2
2
4
5
5

Input

5 4 3

Output

5
5
5
5
4

Note

In the first sample, a is [1 3 2], b is [1 0 0], so c0 = max(1·1) = 1, c1 = max(1·0, 3·1) = 3, c2 = max(1·0, 3·0, 2·1) = 2.

In the second sample, a is [2 1 4 5 3], b is [1 1 1 0 1].

In the third sample, a is [5 2 1 4 3], b is [1 1 1 1 0].

### Response

```cpp
#include <bits/stdc++.h>
const int maxn = 100010;
using namespace std;
int n, d, a[maxn], b[maxn], c[maxn], s[50], bb[maxn], num;
long long x;
long long getNextX() {
  x = (x * 37 + 10007) % 1000000007;
  return x;
}
void init() {
  long long i;
  for (i = 0; i < n; i++) {
    a[i] = i + 1;
  }
  for (i = 0; i < n; i++) {
    swap(a[i], a[getNextX() % (i + 1)]);
  }
  for (i = 0; i < n; i++) {
    if (i < d)
      b[i] = 1;
    else
      b[i] = 0;
  }
  for (i = 0; i < n; i++) {
    swap(b[i], b[getNextX() % (i + 1)]);
  }
}
int main() {
  int i, j, k;
  scanf("%d%d%I64d", &n, &d, &x);
  init();
  for (i = 0; i < n; i++)
    if (b[i]) bb[num++] = i;
  if (n < 50 + 20) {
    for (i = 0; i < n; i++) {
      for (j = 0, k = 0; j < num && bb[j] <= i; j++) k = max(k, a[i - bb[j]]);
      printf("%d\n", k);
    }
  } else {
    for (i = 0; i < n; i++)
      if (n - a[i] <= 50) s[n - a[i]] = i;
    for (i = 0; i < n; i++) {
      for (j = 0; j <= 50; j++)
        if (s[j] <= i && b[i - s[j]]) {
          printf("%d\n", n - j);
          break;
        }
      if (j <= 50) continue;
      for (j = 0, k = 0; j < num && bb[j] <= i; j++) k = max(k, a[i - bb[j]]);
      printf("%d\n", k);
    }
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Amugae has a hotel consisting of 10 rooms. The rooms are numbered from 0 to 9 from left to right.

The hotel has two entrances — one from the left end, and another from the right end. When a customer arrives to the hotel through the left entrance, they are assigned to an empty room closest to the left entrance. Similarly, when a customer arrives at the hotel through the right entrance, they are assigned to an empty room closest to the right entrance.

One day, Amugae lost the room assignment list. Thankfully Amugae's memory is perfect, and he remembers all of the customers: when a customer arrived, from which entrance, and when they left the hotel. Initially the hotel was empty. Write a program that recovers the room assignment list from Amugae's memory.

Input

The first line consists of an integer n (1 ≤ n ≤ 10^5), the number of events in Amugae's memory.

The second line consists of a string of length n describing the events in chronological order. Each character represents:

  * 'L': A customer arrives from the left entrance.
  * 'R': A customer arrives from the right entrance.
  * '0', '1', ..., '9': The customer in room x (0, 1, ..., 9 respectively) leaves.

It is guaranteed that there is at least one empty room when a customer arrives, and there is a customer in the room x when x (0, 1, ..., 9) is given. Also, all the rooms are initially empty.

Output

In the only line, output the hotel room's assignment status, from room 0 to room 9. Represent an empty room as '0', and an occupied room as '1', without spaces.

Examples

Input

8
LLRL1RL1

Output

1010000011

Input

9
L0L0LLRR9

Output

1100000010

Note

In the first example, hotel room's assignment status after each action is as follows.

  * First of all, all rooms are empty. Assignment status is 0000000000.
  * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000.
  * L: one more customer from the left entrance. Assignment status is 1100000000.
  * R: one more customer from the right entrance. Assignment status is 1100000001.
  * L: one more customer from the left entrance. Assignment status is 1110000001.
  * 1: the customer in room 1 leaves. Assignment status is 1010000001.
  * R: one more customer from the right entrance. Assignment status is 1010000011.
  * L: one more customer from the left entrance. Assignment status is 1110000011.
  * 1: the customer in room 1 leaves. Assignment status is 1010000011.

So after all, hotel room's final assignment status is 1010000011.

In the second example, hotel room's assignment status after each action is as follows.

  * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000.
  * 0: the customer in room 0 leaves. Assignment status is 0000000000.
  * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000 again.
  * 0: the customer in room 0 leaves. Assignment status is 0000000000.
  * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000.
  * L: one more customer from the left entrance. Assignment status is 1100000000.
  * R: one more customer from the right entrance. Assignment status is 1100000001.
  * R: one more customer from the right entrance. Assignment status is 1100000011.
  * 9: the customer in room 9 leaves. Assignment status is 1100000010.

So after all, hotel room's final assignment status is 1100000010.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int a[10] = {};
  for (int i = 0; i < n; i++) {
    if (s[i] == 'L') {
      for (int j = 0; j <= 9; j++) {
        if (a[j] == 0) {
          a[j] = 1;
          break;
        }
      }
    } else if (s[i] == 'R') {
      for (int j = 9; j >= 0; j--) {
        if (a[j] == 0) {
          a[j] = 1;
          break;
        }
      }
    } else {
      int x = s[i] - '0';
      a[x] = 0;
    }
  }
  for (int i = 0; i <= 9; i++) cout << a[i];
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Sereja has m non-empty sets of integers A1, A2, ..., Am. What a lucky coincidence! The given sets are a partition of the set of all integers from 1 to n. In other words, for any integer v (1 ≤ v ≤ n) there is exactly one set At such that <image>. Also Sereja has integer d.

Sereja decided to choose some sets from the sets he has. Let's suppose that i1, i2, ..., ik (1 ≤ i1 < i2 < ... < ik ≤ m) are indexes of the chosen sets. Then let's define an array of integers b, sorted in ascending order, as a union of the chosen sets, that is, <image>. We'll represent the element with number j in this array (in ascending order) as bj. Sereja considers his choice of sets correct, if the following conditions are met:

b1 ≤ d; bi + 1 - bi ≤ d (1 ≤ i < |b|); n - d + 1 ≤ b|b|.

Sereja wants to know what is the minimum number of sets (k) that he can choose so that his choice will be correct. Help him with that.

Input

The first line contains integers n, m, d (1 ≤ d ≤ n ≤ 105, 1 ≤ m ≤ 20). The next m lines contain sets. The first number in the i-th line is si (1 ≤ si ≤ n). This number denotes the size of the i-th set. Then the line contains si distinct integers from 1 to n — set Ai.

It is guaranteed that the sets form partition of all integers from 1 to n.

Output

In a single line print the answer to the problem — the minimum value k at the right choice.

Examples

Input

3 2 2
1 2
2 1 3

Output

1

Input

5 1 1
5 4 5 3 2 1

Output

1

Input

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

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, M = 20;
int n, m, d, a[N], cnt[M];
bool bad[1 << M];
int main() {
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 0; i < m; i++) {
    int w;
    scanf("%d", &w);
    while (w--) {
      int x;
      scanf("%d", &x);
      a[x] = i;
    }
  }
  for (int i = 1; i < d; i++) cnt[a[i]]++;
  for (int i = 1; i + d - 1 <= n; i++) {
    cnt[a[i + d - 1]]++;
    int now = 0;
    for (int j = 0; j < m; j++)
      if (!cnt[j]) now |= 1 << j;
    bad[now] = 1;
    cnt[a[i]]--;
  }
  int k = m;
  for (int s = 1 << m; s--;) {
    int c = 0;
    for (int j = 0; j < m; j++) c += s >> j & 1, bad[s] |= bad[s | 1 << j];
    if (!bad[s] && c < k) k = c;
  }
  printf("%d\n", k);
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Nikita has a stack. A stack in this problem is a data structure that supports two operations. Operation push(x) puts an integer x on the top of the stack, and operation pop() deletes the top integer from the stack, i. e. the last added. If the stack is empty, then the operation pop() does nothing.

Nikita made m operations with the stack but forgot them. Now Nikita wants to remember them. He remembers them one by one, on the i-th step he remembers an operation he made pi-th. In other words, he remembers the operations in order of some permutation p1, p2, ..., pm. After each step Nikita wants to know what is the integer on the top of the stack after performing the operations he have already remembered, in the corresponding order. Help him!

Input

The first line contains the integer m (1 ≤ m ≤ 105) — the number of operations Nikita made.

The next m lines contain the operations Nikita remembers. The i-th line starts with two integers pi and ti (1 ≤ pi ≤ m, ti = 0 or ti = 1) — the index of operation he remembers on the step i, and the type of the operation. ti equals 0, if the operation is pop(), and 1, is the operation is push(x). If the operation is push(x), the line also contains the integer xi (1 ≤ xi ≤ 106) — the integer added to the stack.

It is guaranteed that each integer from 1 to m is present exactly once among integers pi.

Output

Print m integers. The integer i should equal the number on the top of the stack after performing all the operations Nikita remembered on the steps from 1 to i. If the stack is empty after performing all these operations, print -1.

Examples

Input

2
2 1 2
1 0

Output

2
2

Input

3
1 1 2
2 1 3
3 0

Output

2
3
2

Input

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

Output

-1
-1
-1
-1
2

Note

In the first example, after Nikita remembers the operation on the first step, the operation push(2) is the only operation, so the answer is 2. After he remembers the operation pop() which was done before push(2), answer stays the same.

In the second example, the operations are push(2), push(3) and pop(). Nikita remembers them in the order they were performed.

In the third example Nikita remembers the operations in the reversed order.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int tree[maxn << 2];
int add[maxn << 2];
int x[maxn];
void push_down(int now) {
  tree[(now << 1)] += add[now];
  tree[((now << 1) | 1)] += add[now];
  add[(now << 1)] += add[now];
  add[((now << 1) | 1)] += add[now];
  add[now] = 0;
}
void maintain(int now) {
  tree[now] = max(tree[(now << 1)], tree[((now << 1) | 1)]);
}
void Add(int l, int r, int now, int ql, int qr, int val) {
  if (ql <= l && r <= qr) {
    tree[now] += val;
    add[now] += val;
    return;
  }
  if (r < ql || l > qr) return;
  int m = l + (r - l) / 2;
  push_down(now);
  Add(l, m, (now << 1), ql, qr, val);
  Add(m + 1, r, ((now << 1) | 1), ql, qr, val);
  maintain(now);
}
int qry(int l, int r, int now) {
  if (l == r) return x[l];
  push_down(now);
  int m = l + (r - l) / 2;
  if (tree[((now << 1) | 1)] > 0)
    return qry(m + 1, r, ((now << 1) | 1));
  else if (tree[(now << 1)] > 0)
    return qry(l, m, (now << 1));
  else
    return -1;
}
int main() {
  int m, a, b;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &a, &b);
    if (b)
      scanf("%d", x + a), Add(1, m, 1, 1, a, 1);
    else
      x[a] = -1, Add(1, m, 1, 1, a, -1);
    printf("%d\n", qry(1, m, 1));
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator?".

The hotel's elevator moves between floors according to one never changing scheme. Initially (at the moment of time 0) the elevator is located on the 1-st floor, then it moves to the 2-nd floor, then — to the 3-rd floor and so on until it reaches the m-th floor. After that the elevator moves to floor m - 1, then to floor m - 2, and so on until it reaches the first floor. This process is repeated infinitely. We know that the elevator has infinite capacity; we also know that on every floor people get on the elevator immediately. Moving between the floors takes a unit of time.

For each of the n participant you are given si, which represents the floor where the i-th participant starts, fi, which represents the floor the i-th participant wants to reach, and ti, which represents the time when the i-th participant starts on the floor si.

For each participant print the minimum time of his/her arrival to the floor fi.

If the elevator stops on the floor si at the time ti, then the i-th participant can enter the elevator immediately. If the participant starts on the floor si and that's the floor he wanted to reach initially (si = fi), then the time of arrival to the floor fi for this participant is considered equal to ti.

Input

The first line contains two space-separated integers n and m (1 ≤ n ≤ 105, 2 ≤ m ≤ 108).

Next n lines contain information about the participants in the form of three space-separated integers si fi ti (1 ≤ si, fi ≤ m, 0 ≤ ti ≤ 108), described in the problem statement.

Output

Print n lines each containing one integer — the time of the arrival for each participant to the required floor.

Examples

Input

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

Output

9
1
0
7
10
7
5

Input

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

Output

12
10
10
8
7

Note

Let's consider the first sample. The first participant starts at floor s = 2 by the time equal to t = 3. To get to the floor f = 4, he has to wait until the time equals 7, that's the time when the elevator will go upwards for the second time. Then the first participant should get on the elevator and go two floors up. In this case the first participant gets to the floor f at time equal to 9. The second participant starts at the time t = 0 on the floor s = 1, enters the elevator immediately, and arrives to the floor f = 2. The third participant doesn't wait for the elevator, because he needs to arrive to the same floor where he starts.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m) {
    int period = 2 * m - 2;
    for (int(i) = 0; (i) < (n); (i)++) {
      int s, f, t;
      cin >> s >> f >> t;
      s--;
      f--;
      int res = 0;
      if (s == f)
        res = t;
      else {
        int p = t / period;
        int offset = t % period;
        if (f > s) {
          bool before = false;
          if (offset <= s) before = true;
          if (before)
            res = p * period + f;
          else
            res = (p + 1) * period + f;
        } else if (s > f) {
          bool before = false;
          if (offset < m || (offset >= m && (period - offset) >= s))
            before = true;
          if (before)
            res = p * period + period - f;
          else
            res = (p + 1) * period + period - f;
        }
      }
      cout << res << endl;
    }
  }
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Write a program which reads an integer n and prints the number of prime numbers which are less than or equal to n. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.

Input

Input consists of several datasets. Each dataset has an integer n (1 ≤ n ≤ 999,999) in a line.

The number of datasets is less than or equal to 30.

Output

For each dataset, prints the number of prime numbers.

Example

Input

10
3
11

Output

4
2
5

### Response

```cpp
#include<cstdio>
using namespace std;
#define max 1000000
bool p[max];
int main(){
    p[1] = true;
    for(int i = 2; i * i < max; i++){
		if(p[i]) continue;
		for(int j = i * i; j < max; j+=i) p[j] = true;
	}
    int n;
    while(~scanf("%d",&n)){
		int ans = 0;
		for(int i = 1; i <= n; i++){
			if(!p[i])ans++;
		}
		printf("%d\n",ans);
	}
    return 0;
}
```