### Prompt

Create a solution in cpp for the following problem:

Ayoub had an array a of integers of size n and this array had two interesting properties:

  * All the integers in the array were between l and r (inclusive).
  * The sum of all the elements was divisible by 3.

Unfortunately, Ayoub has lost his array, but he remembers the size of the array n and the numbers l and r, so he asked you to find the number of ways to restore the array.

Since the answer could be very large, print it modulo 10^9 + 7 (i.e. the remainder when dividing by 10^9 + 7). In case there are no satisfying arrays (Ayoub has a wrong memory), print 0.

Input

The first and only line contains three integers n, l and r (1 ≤ n ≤ 2 ⋅ 10^5 , 1 ≤ l ≤ r ≤ 10^9) — the size of the lost array and the range of numbers in the array.

Output

Print the remainder when dividing by 10^9 + 7 the number of ways to restore the array.

Examples

Input

2 1 3

Output

3

Input

3 2 2

Output

1

Input

9 9 99

Output

711426616

Note

In the first example, the possible arrays are : [1,2], [2,1], [3, 3].

In the second example, the only possible array is [2, 2, 2].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long dp[200005][3], a[3], n, l, r;
long long cal(long long mx, long long rem) {
  if (mx < rem) return 0;
  long long dif = mx - rem;
  dif /= 3;
  return dif + 1;
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  cin >> n >> l >> r;
  for (int i = 0; i < 3; ++i) {
    a[i] = (cal(r, i) - cal(l - 1, i) + 1000000007ll) % 1000000007ll;
  }
  dp[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < 3; ++k) {
        dp[i][(j + k) % 3] =
            (dp[i][(j + k) % 3] + (a[k] * dp[i - 1][j]) % 1000000007ll) %
            1000000007ll;
      }
    }
  }
  cout << dp[n][0] << '\n';
  return 0;
}

```


### Prompt

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

As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered from 1 to n. You can get from one city to another moving along the roads.

The «Two Paths» company, where Bob's brother works, has won a tender to repair two paths in Flatland. A path is a sequence of different cities, connected sequentially by roads. The company is allowed to choose by itself the paths to repair. The only condition they have to meet is that the two paths shouldn't cross (i.e. shouldn't have common cities).

It is known that the profit, the «Two Paths» company will get, equals the product of the lengths of the two paths. Let's consider the length of each road equals 1, and the length of a path equals the amount of roads in it. Find the maximum possible profit for the company.

Input

The first line contains an integer n (2 ≤ n ≤ 200), where n is the amount of cities in the country. The following n - 1 lines contain the information about the roads. Each line contains a pair of numbers of the cities, connected by the road ai, bi (1 ≤ ai, bi ≤ n).

Output

Output the maximum possible profit.

Examples

Input

4
1 2
2 3
3 4

Output

1

Input

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

Output

0

Input

6
1 2
2 3
2 4
5 4
6 4

Output

4

### Response

```cpp
#include <bits/stdc++.h>
void recorrido();
int trabajo(int k, int fa);
int sin_u[212];
int sin_f[212];
int aux[212];
int map[212][212];
int dob[212][212];
int dob_f[212][2];
int n;
int main() {
  int i, o, j, p = 0;
  recorrido();
  for (i = 1; i <= n; ++i) {
    for (o = 0; o < 212; ++o) {
      aux[o] = 0;
      sin_f[o] = 0;
      sin_u[o] = 0;
      dob_f[o][0] = 0;
      dob_f[o][1] = 0;
      for (j = 0; j < 212; ++j) dob[o][j] = 0;
    }
    o = trabajo(i, 0);
    if (o > p) p = o;
  }
  printf("%d\n", p);
  return 0;
}
void recorrido() {
  int i;
  int x, y;
  scanf("%d", &n);
  for (i = 1; i < n; ++i) {
    scanf("%d %d", &x, &y);
    map[x][y] = 1;
    map[y][x] = 1;
  }
}
int trabajo(int k, int fa) {
  int i, o, p, j;
  int a[212];
  int x, y;
  aux[k] = 1;
  a[0] = 0;
  for (i = 1; i <= n; ++i) {
    if (aux[i] == 0 && map[k][i] == 1) {
      trabajo(i, k);
      a[++a[0]] = i;
    }
  }
  if (a[0] == 0) {
    for (i = 1; i < 212; ++i) dob[k][i] = -1;
    return 0;
  }
  for (i = 1; i <= a[0]; ++i)
    if (sin_u[a[i]] > sin_u[k]) sin_u[k] = sin_u[a[i]];
  ++sin_u[k];
  if (a[0] >= 2) {
    p = -1;
    for (i = 1; i <= a[0]; ++i)
      if (sin_u[a[i]] > p) {
        x = i;
        p = sin_u[a[i]];
      }
    p = -1;
    for (i = 1; i <= a[0]; ++i)
      if (sin_u[a[i]] > p && i != x) {
        y = i;
        p = sin_u[a[i]];
      }
    sin_f[k] = sin_u[a[x]] + sin_u[a[y]] + 2;
  }
  for (i = 1; i <= a[0]; ++i)
    if (sin_f[a[i]] > sin_f[k]) sin_f[k] = sin_f[a[i]];
  if (sin_u[k] > sin_f[k]) sin_f[k] = sin_u[k];
  for (i = 0; i < 212; ++i) dob[k][i] = -1;
  for (i = 1; i <= a[0]; ++i)
    if (dob[k][0] < sin_f[a[i]]) dob[k][0] = sin_f[a[i]];
  for (i = 1; i <= a[0]; ++i)
    for (j = 0; dob[a[i]][j] != -1; ++j)
      if (dob[k][j + 1] < dob[a[i]][j]) dob[k][j + 1] = dob[a[i]][j];
  for (i = 1; i <= a[0]; ++i)
    for (j = 1; j <= a[0]; ++j)
      if (i != j) {
        x = sin_u[a[i]] + 1;
        y = sin_f[a[j]];
        for (o = x; o >= 1; --o)
          if (dob[k][o] < y) {
            dob[k][o] = y;
          }
      }
  for (i = 1; i <= a[0]; ++i)
    for (j = 1; j <= a[0]; ++j)
      if (i != j) {
        for (o = 0; dob[a[i]][o] != -1; ++o) {
          x = sin_u[a[j]] + 2 + o;
          y = dob[a[i]][o];
          if (x * y > dob_f[k][0] * dob_f[k][1]) {
            dob_f[k][0] = x;
            dob_f[k][1] = y;
          }
        }
        if (sin_f[a[i]] * sin_f[a[j]] > dob_f[k][0] * dob_f[k][1]) {
          dob_f[k][0] = sin_f[a[i]];
          dob_f[k][1] = sin_f[a[j]];
        }
      }
  for (i = 1; i <= a[0]; ++i) {
    if (dob_f[a[i]][0] * dob_f[a[i]][1] > dob_f[k][0] * dob_f[k][1]) {
      dob_f[k][0] = dob_f[a[i]][0];
      dob_f[k][1] = dob_f[a[i]][1];
    }
  }
  for (i = 0; dob[k][i] != -1; ++i) {
    if (dob[k][i] * i > dob_f[k][0] * dob_f[k][1]) {
      dob_f[k][0] = dob[k][i];
      dob_f[k][1] = i;
    }
  }
  return (dob_f[k][0] * dob_f[k][1]);
}

```


### Prompt

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

There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.

You can take and complete at most one of these jobs in a day.

However, you cannot retake a job that you have already done.

Find the maximum total reward that you can earn no later than M days from today.

You can already start working today.

Constraints

* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^5
* 1 \leq A_i \leq 10^5
* 1 \leq B_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print the maximum total reward that you can earn no later than M days from today.

Examples

Input

3 4
4 3
4 1
2 2

Output

5

Input

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

Output

10

Input

1 1
2 1

Output

0

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
#define M 100005
int a[M],b[M];
vector<int>d[M];
priority_queue<int>q;
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%d%d",&a[i],&b[i]);
	for(int i=1;i<=n;++i)d[a[i]].push_back(b[i]);
	int ans=0;
	for(int i=1;i<=m;++i){
		for(int j=0;j<(int)d[i].size();++j)q.push(d[i][j]);
		if(!q.empty())ans+=q.top(),q.pop();
	}
	printf("%d",ans);
}
```


### Prompt

Create a solution in CPP for the following problem:

A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≤ l ≤ r ≤ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0.

The expression <image> means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal — as "xor".

In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9).

Input

The only line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105).

Output

Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output.

Examples

Input

3 2

Output

6

Note

Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000009;
long long pot(int m) {
  long long res = 1;
  long long dois = 2;
  while (m) {
    if (m & 1) res *= dois, res %= MOD;
    dois *= dois;
    dois %= MOD;
    m >>= 1;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  long long t = pot(m);
  long long ans = 1LL;
  for (int i = 0; i < n; ++i) {
    long long m = (t - i - 1 + MOD) % MOD;
    ans *= m;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

One day, Okazaki Tomoya has bought a tree for Furukawa Nagisa's birthday. The tree is so strange that every node of the tree has a value. The value of the i-th node is vi. Now Furukawa Nagisa and Okazaki Tomoya want to play a game on the tree.

Let (s, e) be the path from node s to node e, we can write down the sequence of the values of nodes on path (s, e), and denote this sequence as S(s, e). We define the value of the sequence G(S(s, e)) as follows. Suppose that the sequence is z0, z1...zl - 1, where l is the length of the sequence. We define G(S(s, e)) = z0 × k0 + z1 × k1 + ... + zl - 1 × kl - 1. If the path (s, e) satisfies <image>, then the path (s, e) belongs to Furukawa Nagisa, otherwise it belongs to Okazaki Tomoya.

Calculating who has more paths is too easy, so they want to play something more difficult. Furukawa Nagisa thinks that if paths (p1, p2) and (p2, p3) belong to her, then path (p1, p3) belongs to her as well. Also, she thinks that if paths (p1, p2) and (p2, p3) belong to Okazaki Tomoya, then path (p1, p3) belongs to Okazaki Tomoya as well. But in fact, this conclusion isn't always right. So now Furukawa Nagisa wants to know how many triplets (p1, p2, p3) are correct for the conclusion, and this is your task.

Input

The first line contains four integers n, y, k and x (1 ≤ n ≤ 105; 2 ≤ y ≤ 109; 1 ≤ k < y; 0 ≤ x < y) — n being the number of nodes on the tree. It is guaranteed that y is a prime number.

The second line contains n integers, the i-th integer is vi (0 ≤ vi < y).

Then follow n - 1 lines, each line contains two integers, denoting an edge of the tree. The nodes of the tree are numbered from 1 to n.

Output

Output a single integer — the number of triplets that are correct for Furukawa Nagisa's conclusion.

Examples

Input

1 2 1 0
1

Output

1

Input

3 5 2 1
4 3 1
1 2
2 3

Output

14

Input

8 13 8 12
0 12 7 4 12 0 8 12
1 8
8 4
4 6
6 2
2 3
8 5
2 7

Output

341

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int gi() {
  int x = 0, w = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') w = 0, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return w ? x : -x;
}
const int N = 1e5 + 5;
int n, mod, k, x, pw[N], ipw[N], a[N], to[N << 1], nxt[N << 1], head[N], cnt;
int sz[N], w[N], root, sum, vis[N], val1[N], val2[N], in[N], out[N];
map<int, int> M1, M2;
int fastpow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) res = 1ll * res * a % mod;
    a = 1ll * a * a % mod;
    b >>= 1;
  }
  return res;
}
void getroot(int u, int f) {
  sz[u] = 1;
  w[u] = 0;
  for (int e = head[u]; e; e = nxt[e])
    if (to[e] != f && !vis[to[e]]) {
      getroot(to[e], u);
      sz[u] += sz[to[e]];
      w[u] = max(w[u], sz[to[e]]);
    }
  w[u] = max(w[u], sum - sz[u]);
  if (w[u] < w[root]) root = u;
}
void dfs1(int u, int f, int d) {
  ++M1[1ll * (x - val1[u] + mod) * ipw[d + 1] % mod];
  ++M2[val2[u]];
  for (int e = head[u]; e; e = nxt[e])
    if (to[e] != f && !vis[to[e]]) {
      val1[to[e]] = (1ll * val1[u] * k + a[to[e]]) % mod;
      val2[to[e]] = (val2[u] + 1ll * pw[d] * a[to[e]]) % mod;
      dfs1(to[e], u, d + 1);
    }
}
void dfs2(int u, int f, int d, int op) {
  out[u] += op * M2[1ll * (x - val1[u] + mod) * ipw[d + 1] % mod];
  in[u] += op * M1[val2[u]];
  for (int e = head[u]; e; e = nxt[e])
    if (to[e] != f && !vis[to[e]]) dfs2(to[e], u, d + 1, op);
}
void calc(int u, int d, int op, int s1, int s2) {
  M1.clear();
  M2.clear();
  val1[u] = s1;
  val2[u] = s2;
  dfs1(u, 0, d);
  dfs2(u, 0, d, op);
}
void solve(int u) {
  vis[u] = 1;
  calc(u, 0, 1, a[u], 0);
  for (int e = head[u]; e; e = nxt[e])
    if (!vis[to[e]]) {
      calc(to[e], 1, -1, (1ll * a[u] * k + a[to[e]]) % mod, a[to[e]]);
      getroot(to[e], 0);
      root = 0;
      sum = sz[to[e]];
      getroot(to[e], 0);
      solve(root);
    }
}
int main() {
  n = gi();
  mod = gi();
  k = gi();
  x = gi();
  for (int i = pw[0] = ipw[0] = 1, inv = fastpow(k, mod - 2); i <= n; ++i)
    pw[i] = 1ll * pw[i - 1] * k % mod, ipw[i] = 1ll * ipw[i - 1] * inv % mod;
  for (int i = 1; i <= n; ++i) a[i] = gi();
  for (int i = 1; i < n; ++i) {
    int u = gi(), v = gi();
    to[++cnt] = v;
    nxt[cnt] = head[u];
    head[u] = cnt;
    to[++cnt] = u;
    nxt[cnt] = head[v];
    head[v] = cnt;
  }
  sum = w[0] = n;
  getroot(1, 0);
  solve(root);
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += 1ll * in[i] * (n - out[i]) + 1ll * out[i] * (n - in[i]) +
           2ll * in[i] * (n - in[i]) + 2ll * out[i] * (n - out[i]);
  }
  printf("%I64d\n", 1ll * n * n * n - ans / 2);
  return 0;
}

```


### Prompt

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

Print the K-th element of the following sequence of length 32:

1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51

Constraints

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

Input

Input is given from Standard Input in the following format:

K

Output

Print the K-th element.

Examples

Input

6

Output

2

Input

27

Output

5

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{

 int a[33]={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
  int k;
  cin>>k;
  cout<<a[k-1]<<endl;
}
```


### Prompt

Please create a solution in cpp to the following problem:

Shrek and the Donkey (as you can guess, they also live in the far away kingdom) decided to play a card game called YAGame. The rules are very simple: initially Shrek holds m cards and the Donkey holds n cards (the players do not see each other's cards), and one more card lies on the table face down so that both players cannot see it as well. Thus, at the beginning of the game there are overall m + n + 1 cards. Besides, the players know which cards the pack of cards consists of and their own cards (but they do not know which card lies on the table and which ones the other player has). The players move in turn and Shrek starts. During a move a player can:

  * Try to guess which card is lying on the table. If he guesses correctly, the game ends and he wins. If his guess is wrong, the game also ends but this time the other player wins.
  * Name any card from the pack. If the other player has such card, he must show it and put it aside (so that this card is no longer used in the game). If the other player doesn't have such card, he says about that.

Recently Donkey started taking some yellow pills and winning over Shrek. Now Shrek wants to evaluate his chances to win if he too starts taking the pills.

Help Shrek assuming the pills are good in quality and that both players using them start playing in the optimal manner.

Input

The first line contains space-separated integers m and n (0 ≤ m, n ≤ 1000).

Output

Print space-separated probabilities that Shrek wins and Donkey wins correspondingly; the absolute error should not exceed 10 - 9.

Examples

Input

0 3

Output

0.25 0.75

Input

1 0

Output

1 0

Input

1 1

Output

0.5 0.5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int X = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') X = X * 10 + c - '0', c = getchar();
  return X * w;
}
const int N = 1000 + 10;
int n, m;
double dp[N][N];
inline double dfs(int n, int m) {
  if (!n) return 1.0 / (m + 1);
  if (!m) return 1.0;
  if (dp[n][m]) return dp[n][m];
  double A = 1.0 * m / (m + 1) * (1.0 - dfs(m - 1, n)), B = 1.0;
  double C = 1.0 / (m + 1) + A, D = 1.0 - dfs(m, n - 1);
  double P = (D - B) / (A - B - C + D);
  return dp[n][m] = P * A + (1 - P) * B;
}
int main() {
  n = read(), m = read();
  printf("%.10lf %.10lf\n", dfs(n, m), 1 - dfs(n, m));
  return 0;
}

```


### Prompt

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

There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn. The Old Peykan wants to travel from city c1 to cn using roads. There are (n - 1) one way roads, the i-th road goes from city ci to city ci + 1 and is di kilometers long.

The Old Peykan travels 1 kilometer in 1 hour and consumes 1 liter of fuel during this time.

Each city ci (except for the last city cn) has a supply of si liters of fuel which immediately transfers to the Old Peykan if it passes the city or stays in it. This supply refreshes instantly k hours after it transfers. The Old Peykan can stay in a city for a while and fill its fuel tank many times.

Initially (at time zero) the Old Peykan is at city c1 and s1 liters of fuel is transferred to it's empty tank from c1's supply. The Old Peykan's fuel tank capacity is unlimited. Old Peykan can not continue its travel if its tank is emptied strictly between two cities.

Find the minimum time the Old Peykan needs to reach city cn.

Input

The first line of the input contains two space-separated integers m and k (1 ≤ m, k ≤ 1000). The value m specifies the number of roads between cities which is equal to n - 1.

The next line contains m space-separated integers d1, d2, ..., dm (1 ≤ di ≤ 1000) and the following line contains m space-separated integers s1, s2, ..., sm (1 ≤ si ≤ 1000).

Output

In the only line of the output print a single integer — the minimum time required for The Old Peykan to reach city cn from city c1.

Examples

Input

4 6
1 2 5 2
2 3 3 4

Output

10

Input

2 3
5 6
5 5

Output

14

Note

In the second sample above, the Old Peykan stays in c1 for 3 hours.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int city[1000 + 10];
int fuel[1000 + 10];
int time(int m, int k) {
  int ans = 0;
  int temp = 0;
  int maxfuel = 0;
  int i;
  for (i = 0; i < m; i++) {
    temp += fuel[i];
    if (fuel[i] > maxfuel) {
      maxfuel = fuel[i];
    }
    while (temp < city[i + 1]) {
      temp += maxfuel;
      ans += k;
    }
    temp -= city[i + 1];
    ans += city[i + 1];
  }
  return ans;
}
int main() {
  int m, k;
  int i;
  while (scanf("%d%d", &m, &k) != EOF) {
    for (i = 1; i <= m; i++) {
      scanf("%d", &city[i]);
    }
    for (i = 0; i < m; i++) {
      scanf("%d", &fuel[i]);
    }
    printf("%d\n", time(m, k));
  }
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

This problem consists of three subproblems: for solving subproblem F1 you will receive 8 points, for solving subproblem F2 you will receive 15 points, and for solving subproblem F3 you will receive 10 points.

Manao has developed a model to predict the stock price of a company over the next n days and wants to design a profit-maximizing trading algorithm to make use of these predictions. Unfortunately, Manao's trading account has the following restrictions:

  * It only allows owning either zero or one shares of stock at a time;
  * It only allows buying or selling a share of this stock once per day;
  * It allows a maximum of k buy orders over the next n days;

For the purposes of this problem, we define a trade to a be the act of buying one share of stock on day i, then holding the stock until some day j > i at which point the share is sold. To restate the above constraints, Manao is permitted to make at most k non-overlapping trades during the course of an n-day trading period for which Manao's model has predictions about the stock price.

Even though these restrictions limit the amount of profit Manao can make compared to what would be achievable with an unlimited number of trades or the ability to hold more than one share at a time, Manao still has the potential to make a lot of money because Manao's model perfectly predicts the daily price of the stock. For example, using this model, Manao could wait until the price is low, then buy one share and hold until the price reaches a high value, then sell for a profit, and repeat this process up to k times until n days have passed.

Nevertheless, Manao is not satisfied by having a merely good trading algorithm, and wants to develop an optimal strategy for trading subject to these constraints. Help Manao achieve this goal by writing a program that will determine when to buy and sell stock to achieve the greatest possible profit during the n-day trading period subject to the above constraints.

Input

The first line contains two integers n and k, separated by a single space, with <image>. The i-th of the following n lines contains a single integer pi (0 ≤ pi ≤ 1012), where pi represents the price at which someone can either buy or sell one share of stock on day i.

The problem consists of three subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.

  * In subproblem F1 (8 points), n will be between 1 and 3000, inclusive.
  * In subproblem F2 (15 points), n will be between 1 and 100000, inclusive.
  * In subproblem F3 (10 points), n will be between 1 and 4000000, inclusive.

Output

For this problem, the program will only report the amount of the optimal profit, rather than a list of trades that can achieve this profit.

Therefore, the program should print one line containing a single integer, the maximum profit Manao can achieve over the next n days with the constraints of starting with no shares on the first day of trading, always owning either zero or one shares of stock, and buying at most k shares over the course of the n-day trading period.

Examples

Input

10 2
2
7
3
9
8
7
9
7
1
9

Output

15

Input

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

Output

21

Note

In the first example, the best trade overall is to buy at a price of 1 on day 9 and sell at a price of 9 on day 10 and the second best trade overall is to buy at a price of 2 on day 1 and sell at a price of 9 on day 4. Since these two trades do not overlap, both can be made and the profit is the sum of the profits of the two trades. Thus the trade strategy looks like this:

    2    | 7    | 3    | 9    | 8    | 7    | 9    | 7    | 1    | 9
    buy  |      |      | sell |      |      |      |      | buy  | sell

The total profit is then (9 - 2) + (9 - 1) = 15.

In the second example, even though Manao is allowed up to 5 trades there are only 4 profitable trades available. Making a fifth trade would cost Manao money so he only makes the following 4:

    2    | 7    | 3    | 9    | 8    | 7    | 9    | 7    | 1    | 9
    buy  | sell | buy  | sell |      | buy  | sell |      | buy  | sell

The total profit is then (7 - 2) + (9 - 3) + (9 - 7) + (9 - 1) = 21.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k, cnt = 0;
long long a[4000000];
int nx[4000000], pr[4000000];
struct Cmp {
  bool operator()(const int &lhs, const int &rhs) const {
    long long lval = abs(a[nx[lhs]] - a[lhs]);
    long long rval = abs(a[nx[rhs]] - a[rhs]);
    if (lval != rval) return lval < rval;
    return lhs < rhs;
  }
};
set<int, Cmp> se;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < (int)(n); ++i) {
    long long x;
    scanf("%I64d", &x);
    if ((cnt == 1 && x <= a[0]) ||
        (cnt > 1 &&
         (x == a[cnt - 1] || (x > a[cnt - 1] && a[cnt - 1] > a[cnt - 2]) ||
          (x < a[cnt - 1] && a[cnt - 1] < a[cnt - 2]))))
      --cnt;
    a[cnt++] = x;
  }
  if (cnt & 1) --cnt;
  long long ans = 0;
  for (int i = 0; i < cnt; i += 2) ans += a[i + 1] - a[i];
  for (int i = 0; i < (int)(cnt); ++i) {
    nx[i] = i + 1;
    pr[i] = i - 1;
  }
  nx[cnt - 1] = -1;
  pr[0] = -1;
  for (int i = 0; i < (int)(cnt - 1); ++i) se.insert(i);
  k = cnt / 2 - k;
  for (int kk = 0; kk < (int)(k); ++kk) {
    int ind = *se.begin();
    if (pr[ind] != -1) se.erase(pr[ind]);
    se.erase(ind);
    se.erase(nx[ind]);
    ans -= abs(a[nx[ind]] - a[ind]);
    if (pr[ind] == -1) {
      if (nx[nx[ind]] != -1) {
        pr[nx[nx[ind]]] = -1;
      }
    } else {
      nx[pr[ind]] = nx[nx[ind]];
      if (nx[nx[ind]] != -1) {
        pr[nx[nx[ind]]] = pr[ind];
        se.insert(pr[ind]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right.

Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the note to one of his neighbours in the row. In other words, if this spy's number is x, he can pass the note to another spy, either x - 1 or x + 1 (if x = 1 or x = n, then the spy has only one neighbour). Also during a step the spy can keep a note and not pass it to anyone.

But nothing is that easy. During m steps Xenia watches some spies attentively. Specifically, during step ti (steps are numbered from 1) Xenia watches spies numbers li, li + 1, li + 2, ..., ri (1 ≤ li ≤ ri ≤ n). Of course, if during some step a spy is watched, he can't do anything: neither give the note nor take it from some other spy. Otherwise, Xenia reveals the spies' cunning plot. Nevertheless, if the spy at the current step keeps the note, Xenia sees nothing suspicious even if she watches him.

You've got s and f. Also, you have the steps during which Xenia watches spies and which spies she is going to watch during each step. Find the best way the spies should act in order to pass the note from spy s to spy f as quickly as possible (in the minimum number of steps).

Input

The first line contains four integers n, m, s and f (1 ≤ n, m ≤ 105; 1 ≤ s, f ≤ n; s ≠ f; n ≥ 2). Each of the following m lines contains three integers ti, li, ri (1 ≤ ti ≤ 109, 1 ≤ li ≤ ri ≤ n). It is guaranteed that t1 < t2 < t3 < ... < tm.

Output

Print k characters in a line: the i-th character in the line must represent the spies' actions on step i. If on step i the spy with the note must pass the note to the spy with a lesser number, the i-th character should equal "L". If on step i the spy with the note must pass it to the spy with a larger number, the i-th character must equal "R". If the spy must keep the note at the i-th step, the i-th character must equal "X".

As a result of applying the printed sequence of actions spy s must pass the note to spy f. The number of printed characters k must be as small as possible. Xenia must not catch the spies passing the note.

If there are miltiple optimal solutions, you can print any of them. It is guaranteed that the answer exists.

Examples

Input

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

Output

XXRR

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, m, st, ed, tem, p, pt;
long long stp;
bool seeked;
string ch;
struct node {
  long long t, l, r;
} a[200000];
bool cmp(node aa, node bb) { return aa.t < bb.t; }
long long i;
int main() {
  cin >> n >> m >> st >> ed;
  if (st > ed) {
    ch = "L";
    stp = -1;
  } else {
    ch = "R";
    stp = 1;
  }
  if (st == ed) {
    return 0;
  }
  for (i = 0; i < m; i++) {
    cin >> a[i].t >> a[i].l >> a[i].r;
  }
  tem = st;
  p = 0;
  pt = 1;
  while (tem != ed) {
    seeked = false;
    while (a[p].t <= pt && p <= m) {
      if ((a[p].l <= tem && a[p].r >= tem) ||
          (a[p].l <= tem + stp && a[p].r >= tem + stp))
        seeked = true;
      p++;
    }
    pt++;
    if (seeked) {
      cout << "X";
    } else {
      cout << ch;
      tem += stp;
    }
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

There is a stack of N cards, each of which has a non-negative integer written on it. The integer written on the i-th card from the top is A_i.

Snuke will repeat the following operation until two cards remain:

* Choose three consecutive cards from the stack.
* Eat the middle card of the three.
* For each of the other two cards, replace the integer written on it by the sum of that integer and the integer written on the card eaten.
* Return the two cards to the original position in the stack, without swapping them.

Find the minimum possible sum of the integers written on the last two cards remaining.

Constraints

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

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible sum of the integers written on the last two cards remaining.

Examples

Input

4
3 1 4 2

Output

16

Input

6
5 2 4 1 6 9

Output

51

Input

10
3 1 4 1 5 9 2 6 5 3

Output

115

### Response

```cpp
#include<cstdio>
#define M 131072
#define N 20
inline long long min(long long x,long long y){return x<y?x:y;}
int e[M],n;long long f[M][N][N],g[M],h[M];bool c[M][N][N];
long long dfs(int u,int v,int w)
{
    if(v+1==w)return 0ll;
    if(c[u][v][w])return f[u][v][w];
    c[u][v][w]=true,f[u][v][w]=0x7fffffffffffffffll;
    for(int i=v+1;i<w;i++)f[u][v][w]=min(f[u][v][w],dfs(u<<1,v,i)+dfs(u<<1|1,i,w)+e[i]*(g[u]+h[u]));
    return f[u][v][w];
}
int main()
{
    scanf("%d",&n),g[1]=h[1]=1;
    for(int i=1;i<=n;i++)scanf("%d",e+i);
    for(int i=1;i<1<<n-2;i++)g[i<<1]=g[i],h[i<<1]=g[i<<1|1]=g[i]+h[i],h[i<<1|1]=h[i];
    return 0&(printf("%lld\n",e[1]+e[n]+dfs(1,1,n)));
}
```


### Prompt

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

Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.

A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (u, v) that belongs to the graph, u and v belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below.

Dr. Evil gave Mahmoud and Ehab a tree consisting of n nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add?

A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same .

Input

The first line of input contains an integer n — the number of nodes in the tree (1 ≤ n ≤ 105).

The next n - 1 lines contain integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the description of the edges of the tree.

It's guaranteed that the given graph is a tree.

Output

Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions.

Examples

Input

3
1 2
1 3

Output

0

Input

5
1 2
2 3
3 4
4 5

Output

2

Note

Tree definition: https://en.wikipedia.org/wiki/Tree_(graph_theory)

Bipartite graph definition: <https://en.wikipedia.org/wiki/Bipartite_graph>

In the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0.

In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int vis[100005] = {0}, col[100005];
vector<long long int> a[100005];
void dfs(long long node, long long par) {
  vis[node] = 1;
  col[node] = 3 - col[par];
  for (auto i : a[node])
    if (!vis[i]) dfs(i, node);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long int n;
    cin >> n;
    long long int m = n - 1;
    while (m--) {
      long long int n1, n2;
      cin >> n1 >> n2;
      a[n1].push_back(n2);
      a[n2].push_back(n1);
    }
    col[0] = 2;
    dfs(1, 0);
    long long int cnt1 = 0, cnt2 = 0;
    for (long long int i = 1; i <= n; i++) {
      if (col[i] == 2) {
        cnt2++;
      } else {
        cnt1++;
      }
    }
    cout << cnt1 * cnt2 - n + 1;
  }
  return 0;
}

```


### Prompt

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

A penguin Rocher has n sticks. He has exactly one stick with length i for all 1 ≤ i ≤ n.

He can connect some sticks. If he connects two sticks that have lengths a and b, he gets one stick with length a + b. Two sticks, that were used in the operation disappear from his set and the new connected stick appears in his set and can be used for the next connections.

He wants to create the maximum number of sticks that have the same length. It is not necessary to make all sticks have the same length, some sticks can have the other length. How many sticks with the equal length he can create?

Input

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

For each test case, the only line contains a single integer n (1 ≤ n ≤ 10^{9}).

Output

For each test case, print a single integer — the answer to the problem.

Example

Input

4
1
2
3
4

Output

1
1
2
2

Note

In the third case, he can connect two sticks with lengths 1 and 2 and he will get one stick with length 3. So, he will have two sticks with lengths 3.

In the fourth case, he can connect two sticks with lengths 1 and 3 and he will get one stick with length 4. After that, he will have three sticks with lengths \{2, 4, 4\}, so two sticks have the same length, and one stick has the other length.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long ans = (ceil(double(n) / (double)2));
    cout << ans << endl;
  }
}

```


### Prompt

Please create a solution in CPP to the following problem:

Welcome to PC Koshien, players. This year marks the 10th anniversary of Computer Koshien, but the number of questions and the total score will vary from year to year. Scores are set for each question according to the difficulty level. When the number of questions is 10 and the score of each question is given, create a program that outputs the total of them.

input

The input is given in the following format.

s1
s2
..
..
s10

The input consists of 10 lines, and the i line is given the integer si (0 ≤ si ≤ 100) representing the score of problem i.

output

Output the total score on one line.

Example

Input

1
2
3
4
5
6
7
8
9
10

Output

55

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int sum=0;
  for(int i=0;i<10;i++){
    int a;
    cin>>a;
    sum+=a;
  }
  cout<<sum<<'\n';
  return(0);
}

```


### Prompt

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

For given $n$ segments which are parallel to X-axis or Y-axis, find the number of intersections of them.

Constraints

* $1 \leq n \leq 100,000$
* $ -1,000,000,000 \leq x_1, y_1, x_2, y_2 \leq 1,000,000,000$
* Two parallel segments never overlap or touch.
* The number of intersections $\leq 1,000,000$

Input

In the first line, the number of segments $n$ is given. In the following $n$ lines, the $i$-th segment is given by coordinates of its end points in the following format:

$x_1 \; y_1 \; x_2 \; y_2$

The coordinates are given in integers.

Output

Print the number of intersections in a line.

Example

Input

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

Output

3

### Response

```cpp
//#include "inspect.hpp"
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(){
	vector<pair<int,pair<int,int>>> vx,vy;
	int i=0,r=0,n,x1,y1,x2,y2;
	for(scanf("%d",&n);i<n;i++){
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		if(x1>x2)swap(x1,x2);
		if(y1>y2)swap(y1,y2);
		if(x1==x2)vy.emplace_back(make_pair(x1,make_pair(y1,y2)));
		else vx.emplace_back(make_pair(y1,make_pair(x1,x2)));
	}
	//sort(vx.begin(),vx.end());
	sort(vy.begin(),vy.end());
	for(auto &e:vx){
		auto it1=lower_bound(vy.begin(),vy.end(),make_pair(e.second.first,make_pair(-2000000000,-2000000000)));
		auto it2=lower_bound(vy.begin(),vy.end(),make_pair(e.second.second+1,make_pair(-2000000000,-2000000000)));

		for(;it1!=it2;++it1){
			auto &f=*it1;
			if(f.second.first<=e.first&&e.first<=f.second.second)r++;
		}
	}
	printf("%d\n",r);
}
```


### Prompt

Generate a cpp solution to the following problem:

You are given a string s consisting of exactly n characters, and each character is either '0', '1' or '2'. Such strings are called ternary strings.

Your task is to replace minimum number of characters in this string with other characters to obtain a balanced ternary string (balanced ternary string is a ternary string such that the number of characters '0' in this string is equal to the number of characters '1', and the number of characters '1' (and '0' obviously) is equal to the number of characters '2').

Among all possible balanced ternary strings you have to obtain the lexicographically (alphabetically) smallest.

Note that you can neither remove characters from the string nor add characters to the string. Also note that you can replace the given characters only with characters '0', '1' and '2'.

It is guaranteed that the answer exists.

Input

The first line of the input contains one integer n (3 ≤ n ≤ 3 ⋅ 10^5, n is divisible by 3) — the number of characters in s.

The second line contains the string s consisting of exactly n characters '0', '1' and '2'.

Output

Print one string — the lexicographically (alphabetically) smallest balanced ternary string which can be obtained from the given one with minimum number of replacements.

Because n is divisible by 3 it is obvious that the answer exists. And it is obvious that there is only one possible answer.

Examples

Input

3
121

Output

021

Input

6
000000

Output

001122

Input

6
211200

Output

211200

Input

6
120110

Output

120120

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int Month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int A[3];
int B[5000 + 10];
map<pair<int, int>, int> M;
void omae_wa_mou_shindeiru() {
  int n;
  cin >> n;
  string st;
  cin >> st;
  for (int i = 0; i < n; ++i) {
    A[st[i] - '0']++;
  }
  if (A[0] > n / 3) {
    int cnt = n / 3 + 1;
    for (int i = 0; i < n; ++i) {
      if (A[0] == n / 3) {
        break;
      }
      if (st[i] == '0') --cnt;
      if (cnt > 0) continue;
      if (st[i] == '0') {
        if (A[1] < n / 3) {
          st[i] = '1';
          --A[0];
          ++A[1];
          continue;
        }
        if (A[2] < n / 3) {
          st[i] = '2';
          --A[0];
          ++A[2];
        }
      }
    }
  }
  if (A[1] > n / 3) {
    int cnt = n / 3 + 1;
    for (int i = 0; i < n; ++i) {
      if (A[1] == n / 3) break;
      if (st[i] == '1') {
        if (A[0] < n / 3) {
          st[i] = '0';
          --A[1];
          ++A[0];
        }
      }
      if (st[i] == '1') --cnt;
      if (cnt > 0) continue;
      if (st[i] == '1') {
        if (A[2] < n / 3) {
          st[i] = '2';
          --A[1];
          ++A[2];
        }
      }
    }
  }
  if (A[2] > n / 3) {
    for (int i = 0; i < n; ++i) {
      if (A[2] == n / 3) break;
      if (st[i] == '2') {
        if (A[0] < n / 3) {
          st[i] = '0';
          --A[2];
          ++A[0];
          continue;
        }
        if (A[1] < n / 3) {
          st[i] = '1';
          --A[2];
          ++A[1];
        }
      }
    }
  }
  cout << st;
}
int main() {
  ios_base::sync_with_stdio(false);
  ;
  int t = 1;
  while (t--) {
    omae_wa_mou_shindeiru();
    if (t) cout << "\n";
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

An n × n square matrix is special, if:

  * it is binary, that is, each cell contains either a 0, or a 1;
  * the number of ones in each row and column equals 2.

You are given n and the first m rows of the matrix. Print the number of special n × n matrices, such that the first m rows coincide with the given ones.

As the required value can be rather large, print the remainder after dividing the value by the given number mod.

Input

The first line of the input contains three integers n, m, mod (2 ≤ n ≤ 500, 0 ≤ m ≤ n, 2 ≤ mod ≤ 109). Then m lines follow, each of them contains n characters — the first rows of the required special matrices. Each of these lines contains exactly two characters '1', the rest characters are '0'. Each column of the given m × n table contains at most two numbers one.

Output

Print the remainder after dividing the required value by number mod.

Examples

Input

3 1 1000
011

Output

2

Input

4 4 100500
0110
1010
0101
1001

Output

1

Note

For the first test the required matrices are:

    011
    101
    110

    011
    110
    101

In the second test the required matrix is already fully given, so the answer is 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 510;
int n, m, mod;
int ct[MAX_N];
long long dp[MAX_N][MAX_N];
long long dfs(int one, int two) {
  long long &ref = dp[one][two];
  if (ref != -1) return ref;
  if (one == 0 && two == 0) return ref = 1;
  long long r = 0;
  if (one >= 2) {
    r = (r + (one * (one - 1) / 2) % mod * dfs(one - 2, two)) % mod;
  }
  if (two >= 2) {
    r = (r + (two * (two - 1) / 2) % mod * dfs(one + 2, two - 2)) % mod;
  }
  if (one >= 1 && two >= 1) {
    r = (r + one * two % mod * dfs(one - 1 + 1, two - 1)) % mod;
  }
  return ref = r;
}
int main() {
  cin >> n >> m >> mod;
  int s = 0;
  for (int i = 0; i < n; i++) {
    ct[i] = 2;
    s += 2;
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      char c;
      cin >> c;
      if (c == '1') {
        ct[j]--;
        s -= 1;
      }
    }
  }
  int L = n - m;
  if (s != 2 * L) {
    cout << 0 << endl;
    return 0;
  } else {
    bool ok = true;
    int one = 0, two = 0;
    for (int i = 0; i < n; i++) {
      if (ct[i] == 1) {
        one++;
      } else if (ct[i] == 2) {
        two++;
      } else if (ct[i] == 0) {
      } else {
        ok = false;
      }
    }
    if (!ok) {
      cout << 0 << endl;
      return 0;
    }
    memset(dp, -1, sizeof(dp));
    cout << dfs(one, two) << endl;
  }
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?

Input

The first input line contains integer n (1 ≤ n ≤ 105) — amount of squares in the stripe. The second line contains n space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.

Output

Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.

Examples

Input

9
1 5 -6 7 9 -16 0 -2 2

Output

3

Input

3
1 1 1

Output

0

Input

2
0 0

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, num[100005], qzh[100005], fa = 0;
int main() {
  cin >> n;
  cin >> num[0];
  qzh[0] = num[0];
  for (int i = 1; i < n; ++i) {
    cin >> num[i];
    qzh[i] = qzh[i - 1] + num[i];
  }
  for (int i = 0; i < n - 1; ++i) {
    int left = qzh[i];
    int right = qzh[n - 1] - left;
    if (left == right) ++fa;
  }
  cout << fa << endl;
  return 0;
}

```


### Prompt

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

Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:

SelectionSort(A)
1 for i = 0 to A.length-1
2     mini = i
3     for j = i to A.length-1
4         if A[j] < A[mini]
5             mini = j
6     swap A[i] and A[mini]

Note that, indices for array elements are based on 0-origin.

Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.

Constraints

1 ≤ N ≤ 100

Input

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

In the second line, N elements of the sequence are given separated by space characters.

Output

The output consists of 2 lines.

In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character.

In the second line, please print the number of swap operations.

Examples

Input

6
5 6 4 2 1 3

Output

1 2 3 4 5 6
4

Input

6
5 2 4 6 1 3

Output

1 2 3 4 5 6
3

### Response

```cpp
#include<iostream>
#include<cmath>
using namespace std;
int a[100],n,t;
void xzsort(int n)
{
	int i,j,minn,mini;
	for(i=0;i<n-1;i++)
	{
		mini=i;
		minn=a[i];
		for(j=i+1;j<n;j++)
		{
			if(a[j]<minn)
			{
				minn=a[j];
				mini=j;
			}
		}
		if(i!=mini)
		{
		t++;
		swap(a[i],a[mini]);
		}
	}
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	cin>>a[i];
	xzsort(n);
	for(int i=0;i<n-1;i++)
	cout<<a[i]<<" ";
	cout<<a[n-1]<<endl;
	cout<<t<<endl;
	return 0;
 }

```


### Prompt

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

You have a computer literacy course in your university. In the computer system, the login/logout records of all PCs in a day are stored in a file. Although students may use two or more PCs at a time, no one can log in to a PC which has been logged in by someone who has not logged out of that PC yet.

You are asked to write a program that calculates the total time of a student that he/she used at least one PC in a given time period (probably in a laboratory class) based on the records in the file.

The following are example login/logout records.

* The student 1 logged in to the PC 1 at 12:55
* The student 2 logged in to the PC 4 at 13:00
* The student 1 logged in to the PC 2 at 13:10
* The student 1 logged out of the PC 2 at 13:20
* The student 1 logged in to the PC 3 at 13:30
* The student 1 logged out of the PC 1 at 13:40
* The student 1 logged out of the PC 3 at 13:45
* The student 1 logged in to the PC 1 at 14:20
* The student 2 logged out of the PC 4 at 14:30
* The student 1 logged out of the PC 1 at 14:40

For a query such as "Give usage of the student 1 between 13:00 and 14:30", your program should answer "55 minutes", that is, the sum of 45 minutes from 13:00 to 13:45 and 10 minutes from 14:20 to 14:30, as depicted in the following figure.

<image>

Input

The input is a sequence of a number of datasets. The end of the input is indicated by a line containing two zeros separated by a space. The number of datasets never exceeds 10.

Each dataset is formatted as follows.

> N M
>  r
>  record1
>  ...
>  recordr
>  q
>  query1
>  ...
>  queryq
>

The numbers N  and M  in the first line are the numbers of PCs and the students, respectively. r  is the number of records. q  is the number of queries. These four are integers satisfying the following.

> 1 ≤ N  ≤ 1000, 1 ≤ M  ≤ 10000, 2 ≤ r  ≤ 1000, 1 ≤ q  ≤ 50

Each record consists of four integers, delimited by a space, as follows.

> t  n  m  s

s  is 0 or 1. If s  is 1, this line means that the student m  logged in to the PC n  at time t . If s  is 0, it means that the student m  logged out of the PC n  at time t . The time is expressed as elapsed minutes from 0:00 of the day. t , n  and m  satisfy the following.

> 540 ≤ t  ≤ 1260, 1 ≤ n  ≤ N , 1 ≤ m  ≤ M

You may assume the following about the records.
* Records are stored in ascending order of time t.
* No two records for the same PC has the same time t.
* No PCs are being logged in before the time of the first record nor after that of the last record in the file.
* Login and logout records for one PC appear alternatingly, and each of the login-logout record pairs is for the same student.

Each query consists of three integers delimited by a space, as follows.

> ts  te  m

It represents "Usage of the student m  between ts  and te ". ts , te  and m  satisfy the following.

> 540 ≤ ts  < te  ≤ 1260, 1 ≤ m  ≤ M

Output

For each query, print a line having a decimal integer indicating the time of usage in minutes. Output lines should not have any character other than this number.

Example

Input

4 2
10
775 1 1 1
780 4 2 1
790 2 1 1
800 2 1 0
810 3 1 1
820 1 1 0
825 3 1 0
860 1 1 1
870 4 2 0
880 1 1 0
1
780 870 1
13 15
12
540 12 13 1
600 12 13 0
650 13 15 1
660 12 15 1
665 11 13 1
670 13 15 0
675 11 13 0
680 12 15 0
1000 11 14 1
1060 12 14 1
1060 11 14 0
1080 12 14 0
3
540 700 13
600 1000 15
1000 1200 11
1 1
2
600 1 1 1
700 1 1 0
5
540 600 1
550 650 1
610 620 1
650 750 1
700 800 1
0 0

Output

55
70
30
0
0
50
10
50
0

### Response

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

using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))

using vi = vector<int>;
using mvi = map<int,vi>;

int main()
{
  int n,m;
  while(cin >> n >> m,n+m){
    mvi mv;
    int r;
    cin >> r;
    REP(i,r){
      int t,_n,_m,s;
      cin >> t >> _n >> _m >> s;
      if(s){
        if(mv.find(_m) == mv.end()){
          mv[_m].resize(1300,0);
        }
        mv[_m][t]++;
      }else{
        mv[_m][t]--;
      }
  }
    for(auto it = mv.begin();it != mv.end();++it){
      REP(i,1300-1){
        it->second[i+1] += it->second[i];
      }
    }
    int q;
    cin >>q;
    REP(i,q){
      int t1,t2,_m;
      cin >> t1 >> t2 >> _m;
      int ans = 0;
      if(mv.find(_m)!=mv.end()){
        auto mc = mv[_m];
        for(int i = t1;i < t2;++i){
          if(mc[i]>0){
            ans++;
          }
        }
      }
      cout << ans << endl;
    }
  }
}
```


### Prompt

Generate a CPP solution to the following problem:

«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.

You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.

Input

The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.

Output

Output the required default value for the next test index.

Examples

Input

3
1 7 2

Output

3

### Response

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

```


### Prompt

Please create a solution in Cpp to the following problem:

For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations.

Max is a young biologist. For n days he watched a specific shark, and now he knows the distance the shark traveled in each of the days. All the distances are distinct. Max wants to know now how many locations the shark visited. He assumed there is such an integer k that if the shark in some day traveled the distance strictly less than k, then it didn't change the location; otherwise, if in one day the shark traveled the distance greater than or equal to k; then it was changing a location in that day. Note that it is possible that the shark changed a location for several consecutive days, in each of them the shark traveled the distance at least k.

The shark never returned to the same location after it has moved from it. Thus, in the sequence of n days we can find consecutive nonempty segments when the shark traveled the distance less than k in each of the days: each such segment corresponds to one location. Max wants to choose such k that the lengths of all such segments are equal.

Find such integer k, that the number of locations is as large as possible. If there are several such k, print the smallest one.

Input

The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of days.

The second line contains n distinct positive integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) — the distance traveled in each of the day.

Output

Print a single integer k, such that

  1. the shark was in each location the same number of days,
  2. the number of locations is maximum possible satisfying the first condition,
  3. k is smallest possible satisfying the first and second conditions.

Examples

Input

8
1 2 7 3 4 8 5 6

Output

7

Input

6
25 1 2 3 14 36

Output

2

Note

In the first example the shark travels inside a location on days 1 and 2 (first location), then on 4-th and 5-th days (second location), then on 7-th and 8-th days (third location). There are three locations in total.

In the second example the shark only moves inside a location on the 2-nd day, so there is only one location.

### Response

```cpp
#include <bits/stdc++.h>
#pragma warning(disable : 4018)
using namespace std;
const int Inf = (int)1e9 + 7;
namespace {
const int N = (int)1e5 + 7;
int n;
int a[N];
int dsu[N], rnk[N], sz[N];
int make(int x) {
  dsu[x] = x;
  rnk[x] = 0;
  sz[x] = 1;
  return dsu[x];
}
int find(int x) {
  if (dsu[x] == -1) return -1;
  if (x == dsu[x]) return x;
  return find(dsu[x]);
}
void unite(int x, int y) {
  int xset = find(x);
  int yset = find(y);
  if (xset == yset) return;
  if (rnk[xset] < rnk[yset]) {
    dsu[xset] = yset;
    sz[yset] += sz[xset];
  } else if (rnk[xset] > rnk[yset]) {
    dsu[yset] = xset;
    sz[xset] += sz[yset];
  } else {
    dsu[yset] = xset;
    sz[xset] += sz[yset];
    ++rnk[xset];
  }
}
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> b(n);
  for (int i = 0; i < n; i++) b[i] = a[i];
  sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  for (int i = 0; i < n; i++)
    a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
  memset(dsu, -1, sizeof(dsu));
  multiset<int> ms;
  vector<int> p(n);
  for (int i = 0; i < n; i++) p[a[i]] = i;
  int lmax = -1;
  int maxi = -1;
  for (int x = 0; x < n; x++) {
    int xset = make(x);
    ms.insert(1);
    int pos = p[x];
    int lef = p[x] - 1;
    int rig = p[x] + 1;
    if (lef >= 0) {
      int lset = find(a[lef]);
      if (lset != -1) {
        ms.erase(sz[xset]);
        ms.erase(sz[lset]);
        ms.insert(sz[lset] + sz[xset]);
        unite(xset, lset);
      }
    }
    if (rig < n) {
      int xset = find(a[pos]);
      int rset = find(a[rig]);
      if (rset != -1) {
        ms.erase(sz[xset]);
        ms.erase(sz[rset]);
        ms.insert(sz[xset] + sz[rset]);
        unite(xset, rset);
      }
    }
    if (*ms.begin() == *prev(ms.end())) {
      int lnow = ms.size();
      if (lnow > lmax) {
        lmax = lnow;
        maxi = b[x] + 1;
      }
    }
  }
  cout << maxi << "\n";
}
}  // namespace
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(9);
  cout << fixed;
  solve();
  return 0;
}

```


### Prompt

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

The athletics competition 200M semi-final three races were held. Eight players (24 players in total) will participate in each group. A total of eight players, including the top two players in each group and the top two players from all the players in each group who are third or lower, will advance to the final.

Create a program that inputs the player numbers and times and outputs the numbers and times of the eight finalists.

Input

The input is given in the following format:

p1 t1
p2 t2
::
p24 t24

Lines 1-8, 1st set player number pi (integer, 1 ≤ pi ≤ 10000) and time ti (real number measured to 1/100, 1 ≤ ti ≤ 100), lines 9-16 Is given the player number pi and time ti of the second group, and the player number pi and time ti of the third group on the 17th to 24th lines. It is assumed that there are no players with the same player number or the same time.

Output

In the following order, please output the player numbers and times of the finalists on one line, separated by blanks.

1st place player in the 1st group
2nd place player in the 1st group
1st place player in the 2nd group
2nd place player in the 2nd group
1st place player in the 3rd group
Second place player in the third group
The player with the fastest time among the players who are 3rd or lower in each group
The player with the second fastest time among the players who are third or lower in each group

Example

Input

18 25.46
16 26.23
3 23.00
10 24.79
5 22.88
11 23.87
19 23.90
1 25.11
23 23.88
4 23.46
7 24.12
12 22.91
13 21.99
14 22.86
21 23.12
9 24.09
17 22.51
22 23.49
6 23.02
20 22.23
24 21.89
15 24.14
8 23.77
2 23.42

Output

5 22.88
3 23.00
13 21.99
14 22.86
24 21.89
20 22.23
17 22.51
12 22.91

### Response

```cpp
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef pair<double, int> P;

void solve()
{
	vector<P> second;
	vector<P> a(8);
	vector<P> b(8);
	vector<P> c(8);
	for(int i = 0; i < 8; ++i)
	{
		cin >> a[i].second >> a[i].first;
	}
	for(int i = 0; i < 8; ++i)
	{
		cin >> b[i].second >> b[i].first;
	}
	for(int i = 0; i < 8; ++i)
	{
		cin >> c[i].second >> c[i].first;
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	second.push_back(a[2]);
	second.push_back(a[3]);
	second.push_back(b[2]);
	second.push_back(b[3]);
	second.push_back(c[2]);
	second.push_back(c[3]);
	sort(second.begin(), second.end());
	cout << a[0].second << " " << a[0].first << endl;
	cout << a[1].second << " " << a[1].first << endl;
	cout << b[0].second << " " << b[0].first << endl;
	cout << b[1].second << " " << b[1].first << endl;
	cout << c[0].second << " " << c[0].first << endl;
	cout << c[1].second << " " << c[1].first << endl;
	cout << second[0].second << " " << second[0].first << endl;
	cout << second[1].second << " " << second[1].first << endl;
}

int main()
{
	solve();
	return(0);
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

You are given one integer n (n > 1).

Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (n = 3 but there is 4 in the array).

Your task is to find a permutation p of length n that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied).

You have to answer t independent test cases.

If there are several answers, you can print any. It can be proven that the answer exists for each n > 1.

Input

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

The only line of the test case contains one integer n (2 ≤ n ≤ 100) — the length of the permutation you have to find.

Output

For each test case, print n distinct integers p_1, p_2, …, p_n — a permutation that there is no index i (1 ≤ i ≤ n) such that p_i = i (so, for all i from 1 to n the condition p_i ≠ i should be satisfied).

If there are several answers, you can print any. It can be proven that the answer exists for each n > 1.

Example

Input

2
2
5

Output

2 1
2 1 5 3 4

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;

int main(){
    // freopen("in.txt","r",stdin);
    // ios::sync_with_stdio(false);
    int t;
    int n;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=2;i<=n;++i)
            printf("%d ",i);
        printf("1\n");
    }

    return 0;
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

VK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects a_i publications.

The latest A/B test suggests that users are reading recommended publications more actively if each category has a different number of publications within daily recommendations. The targeted algorithm can find a single interesting publication of i-th category within t_i seconds.

What is the minimum total time necessary to add publications to the result of batch algorithm execution, so all categories have a different number of publications? You can't remove publications recommended by the batch algorithm.

Input

The first line of input consists of single integer n — the number of news categories (1 ≤ n ≤ 200 000).

The second line of input consists of n integers a_i — the number of publications of i-th category selected by the batch algorithm (1 ≤ a_i ≤ 10^9).

The third line of input consists of n integers t_i — time it takes for targeted algorithm to find one new publication of category i (1 ≤ t_i ≤ 10^5).

Output

Print one integer — the minimal required time for the targeted algorithm to get rid of categories with the same size.

Examples

Input

5
3 7 9 7 8
5 2 5 7 5

Output

6

Input

5
1 2 3 4 5
1 1 1 1 1

Output

0

Note

In the first example, it is possible to find three publications of the second type, which will take 6 seconds.

In the second example, all news categories contain a different number of publications.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long res[300000];
int cd;
map<long long, long long> ok;
pair<long long, long long> a[300000];
priority_queue<long long> pq;
int main() {
  int t = 1;
  while (t--) {
    cin >> cd;
    for (int i = 1; i <= cd; i++) {
      cin >> a[i].first;
      ok[a[i].first] = 1;
    }
    for (int i = 1; i <= cd; i++) {
      cin >> a[i].second;
    }
    sort(a + 1, a + 1 + cd);
    cd++;
    a[cd].first = 1e17;
    long long kq = 0;
    long long cur = 0;
    int i = 1;
    while (i < cd) {
      pq.push(a[i].second);
      cur += a[i].second;
      while (a[i + 1].first == a[i].first) {
        i++;
        pq.push(a[i].second);
        cur += a[i].second;
      }
      cur -= pq.top();
      pq.pop();
      for (long long e = a[i].first + 1; e <= 1000000000000; e++) {
        if (pq.size() == 0) {
          break;
        }
        kq += cur;
        if (ok[e] == 1) {
          break;
        }
        cur -= pq.top();
        pq.pop();
      }
      i++;
    }
    cout << kq << '\n';
  }
}

```


### Prompt

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

Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there.

If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi. He also remembered that each of his friends received exactly one gift.

Now Petya wants to know for each friend i the number of a friend who has given him a gift.

Input

The first line contains one integer n (1 ≤ n ≤ 100) — the quantity of friends Petya invited to the party. The second line contains n space-separated integers: the i-th number is pi — the number of a friend who gave a gift to friend number i. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.

Output

Print n space-separated integers: the i-th number should equal the number of the friend who gave a gift to friend number i.

Examples

Input

4
2 3 4 1

Output

4 1 2 3

Input

3
1 3 2

Output

1 3 2

Input

2
1 2

Output

1 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int frinds[n];
  for (int i = 0; i < n; i++) {
    cin >> frinds[i];
  }
  int x[n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i + 1 == frinds[j]) x[i] = j + 1;
    }
  }
  for (int i = 0; i < n; i++) cout << x[i] << " ";
}

```


### Prompt

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

Even if the world is full of counterfeits, I still regard it as wonderful.

Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.

The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a! = 1 × 2 × ... × a. Specifically, 0! = 1.

Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, <image>. Note that when b ≥ a this value is always integer.

As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.

Input

The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).

Output

Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.

Examples

Input

2 4

Output

2

Input

0 10

Output

0

Input

107 109

Output

2

Note

In the first example, the last digit of <image> is 2;

In the second example, the last digit of <image> is 0;

In the third example, the last digit of <image> is 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, m = 1;
  cin >> a >> b;
  if (b - a >= 5) {
    cout << 0;
    return 0;
  }
  for (long long i = a + 1; i <= b; i++) {
    m = ((i % 10) * (m % 10)) % 10;
  }
  cout << m;
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You work in a big office. It is a 9 floor building with an elevator that can accommodate up to 4 people. It is your responsibility to manage this elevator.

Today you are late, so there are queues on some floors already. For each person you know the floor where he currently is and the floor he wants to reach. Also, you know the order in which people came to the elevator.

According to the company's rules, if an employee comes to the elevator earlier than another one, he has to enter the elevator earlier too (even if these employees stay on different floors). Note that the employees are allowed to leave the elevator in arbitrary order.

The elevator has two commands:

  * Go up or down one floor. The movement takes 1 second.
  * Open the doors on the current floor. During this operation all the employees who have reached their destination get out of the elevator. Then all the employees on the floor get in the elevator in the order they are queued up while it doesn't contradict the company's rules and there is enough space in the elevator. Each employee spends 1 second to get inside and outside the elevator.

Initially the elevator is empty and is located on the floor 1.

You are interested what is the minimum possible time you need to spend to deliver all the employees to their destination. It is not necessary to return the elevator to the floor 1.

Input

The first line contains an integer n (1 ≤ n ≤ 2000) — the number of employees.

The i-th of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 9, ai ≠ bi) — the floor on which an employee initially is, and the floor he wants to reach.

The employees are given in the order they came to the elevator.

Output

Print a single integer — the minimal possible time in seconds.

Examples

Input

2
3 5
5 3

Output

10

Input

2
5 3
3 5

Output

12

Note

Explaination for the first sample <image> t = 0

<image> t = 2

<image> t = 3

<image> t = 5

<image> t = 6

<image> t = 7

<image> t = 9

<image> t = 10

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 21474836;
const int maxn = 2005;
const int F = 10;
map<string, int> d[maxn][10];
int start[maxn], dest[maxn];
int n;
int dp(int i, int j, string s) {
  if (d[i][j].count(s)) return d[i][j][s];
  d[i][j][s] = inf;
  string os = s;
  for (int k = 0; k < 4; k++) {
    int flo = s[k] - '0';
    if (flo == j) s[k] = '0';
  }
  int pos = i + 1;
  for (int k = 0; k < 4; k++) {
    int flo = s[k] - '0';
    if (pos <= n && flo == 0 && start[pos] == j) s[k] = '0' + dest[pos], ++pos;
  }
  if (i == n && s == (string) "0000") {
    return d[i][j][os] = 0;
  }
  sort(s.begin(), s.end());
  for (int k = 3; k >= 0; k--) {
    if (s[k] - '0' != 0)
      d[i][j][os] =
          min(d[i][j][os], dp(pos - 1, s[k] - '0', s) + abs(j - (s[k] - '0')));
    else if (pos - 1 < n) {
      d[i][j][os] =
          min(d[i][j][os], dp(pos - 1, start[pos], s) + abs(j - start[pos]));
      break;
    }
  }
  return d[i][j][os];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &start[i], &dest[i]);
  }
  cout << dp(0, 1, "0000") + 2 * n;
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

One tradition of ACM-ICPC contests is that a team gets a balloon for every solved problem. We assume that the submission time doesn't matter and teams are sorted only by the number of balloons they have. It means that one's place is equal to the number of teams with more balloons, increased by 1. For example, if there are seven teams with more balloons, you get the eight place. Ties are allowed.

You should know that it's important to eat before a contest. If the number of balloons of a team is greater than the weight of this team, the team starts to float in the air together with their workstation. They eventually touch the ceiling, what is strictly forbidden by the rules. The team is then disqualified and isn't considered in the standings.

A contest has just finished. There are n teams, numbered 1 through n. The i-th team has ti balloons and weight wi. It's guaranteed that ti doesn't exceed wi so nobody floats initially.

Limak is a member of the first team. He doesn't like cheating and he would never steal balloons from other teams. Instead, he can give his balloons away to other teams, possibly making them float. Limak can give away zero or more balloons of his team. Obviously, he can't give away more balloons than his team initially has.

What is the best place Limak can get?

Input

The first line of the standard input contains one integer n (2 ≤ n ≤ 300 000) — the number of teams.

The i-th of n following lines contains two integers ti and wi (0 ≤ ti ≤ wi ≤ 1018) — respectively the number of balloons and the weight of the i-th team. Limak is a member of the first team.

Output

Print one integer denoting the best place Limak can get.

Examples

Input

8
20 1000
32 37
40 1000
45 50
16 16
16 16
14 1000
2 1000

Output

3

Input

7
4 4
4 4
4 4
4 4
4 4
4 4
5 5

Output

2

Input

7
14000000003 1000000000000000000
81000000000 88000000000
5000000000 7000000000
15000000000 39000000000
46000000000 51000000000
0 1000000000
0 0

Output

2

Note

In the first sample, Limak has 20 balloons initially. There are three teams with more balloons (32, 40 and 45 balloons), so Limak has the fourth place initially. One optimal strategy is:

  1. Limak gives 6 balloons away to a team with 32 balloons and weight 37, which is just enough to make them fly. Unfortunately, Limak has only 14 balloons now and he would get the fifth place.
  2. Limak gives 6 balloons away to a team with 45 balloons. Now they have 51 balloons and weight 50 so they fly and get disqualified.
  3. Limak gives 1 balloon to each of two teams with 16 balloons initially.
  4. Limak has 20 - 6 - 6 - 1 - 1 = 6 balloons.
  5. There are three other teams left and their numbers of balloons are 40, 14 and 2.
  6. Limak gets the third place because there are two teams with more balloons.

In the second sample, Limak has the second place and he can't improve it.

In the third sample, Limak has just enough balloons to get rid of teams 2, 3 and 5 (the teams with 81 000 000 000, 5 000 000 000 and 46 000 000 000 balloons respectively). With zero balloons left, he will get the second place (ex-aequo with team 6 and team 7).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct S {
  long long t, w;
} s[300009];
bool comp(S a, S b) { return a.t > b.t; }
int main() {
  int n;
  scanf("%d", &n);
  n--;
  long long c, tmp;
  scanf("%lld %lld", &c, &tmp);
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", &s[i].t, &s[i].w);
  }
  sort(s, s + n, comp);
  int ans = n + 1;
  int j = 0;
  multiset<long long> S;
  while (true) {
    while (j < n && s[j].t > c) {
      S.insert(s[j].w - s[j].t + 1);
      j++;
    }
    ans = min(ans, (int)S.size() + 1);
    if (S.empty() || *S.begin() > c) {
      break;
    }
    c -= *S.begin();
    S.erase(S.begin());
  }
  printf("%d", ans);
}

```


### Prompt

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

Given an integer x. Your task is to find out how many positive integers n (1 ≤ n ≤ x) satisfy $$$n ⋅ a^n ≡ b   (mod\;p), where a, b, p$$$ are all known constants.

Input

The only line contains four integers a,b,p,x (2 ≤ p ≤ 10^6+3, 1 ≤ a,b < p, 1 ≤ x ≤ 10^{12}). It is guaranteed that p is a prime.

Output

Print a single integer: the number of possible answers n.

Examples

Input

2 3 5 8

Output

2

Input

4 6 7 13

Output

1

Input

233 233 10007 1

Output

1

Note

In the first sample, we can see that n=2 and n=8 are possible answers.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 1000;
long long a, b, p, x;
long long qpow(long long x, long long y, long long MOD) {
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % MOD;
    x = (x * x) % MOD;
    y = y >> 1;
  }
  return res;
}
int main() {
  scanf("%lld%lld%lld%lld", &a, &b, &p, &x);
  long long ans = 0;
  for (long long i = 1; i < p; i++) {
    long long tp = qpow(a, i, p);
    long long invt = qpow(tp, p - 2, p);
    long long invp = qpow(p - 1, p - 2, p);
    long long y = ((b * invt - i + p) % p * invp) % p;
    long long ty = (x - i) / (p - 1);
    if (i + y * (p - 1) > x) continue;
    long long anst = (ty - y) / p + 1;
    ans = ans + anst;
  }
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

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

Write a program which computes the digit number of sum of two integers a and b.

Constraints

* 0 ≤ a, b ≤ 1,000,000
* The number of datasets ≤ 200

Input

There are several test cases. Each test case consists of two non-negative integers a and b which are separeted by a space in a line. The input terminates with EOF.

Output

Print the number of digits of a + b for each data set.

Example

Input

5 7
1 99
1000 999

Output

2
3
4

### Response

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

int main(){
int a,b;
while(cin >>a>>b){
a = a + b;
int c = 0;
while(a > 0){
a = a / 10;
c++;
}
cout << c << endl;
}
return 0;
}
```


### Prompt

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

PMP is getting a warrior. He is practicing a lot, but the results are not acceptable yet. This time instead of programming contests, he decided to compete in a car racing to increase the spirit of victory. He decides to choose a competition that also exhibits algorithmic features.

AlgoRace is a special league of car racing where different teams compete in a country of n cities. Cities are numbered 1 through n. Every two distinct cities in the country are connected with one bidirectional road. Each competing team should introduce one driver and a set of cars.

The competition is held in r rounds. In i-th round, drivers will start at city si and finish at city ti. Drivers are allowed to change their cars at most ki times. Changing cars can take place in any city in no time. One car can be used multiple times in one round, but total number of changes should not exceed ki. Drivers can freely choose their path to destination.

PMP has prepared m type of purpose-built cars. Beside for PMP’s driving skills, depending on properties of the car and the road, a car traverses each road in each direction in different times.

PMP Warriors wants to devise best strategies of choosing car and roads in each round to maximize the chance of winning the cup. For each round they want to find the minimum time required to finish it.

Input

The first line contains three space-separated integers n, m, r (2 ≤ n ≤ 60, 1 ≤ m ≤ 60, 1 ≤ r ≤ 105) — the number of cities, the number of different types of cars and the number of rounds in the competition, correspondingly.

Next m sets of n × n matrices of integers between 0 to 106 (inclusive) will follow — describing the time one car requires to traverse different roads. The k-th integer in j-th line of the i-th set is the time that i-th car requires to traverse the road from j-th city to k-th city. These matrices are not necessarily symmetric, but their diagonal is always zero.

Next r lines contain description of the rounds. The i-th of these lines contains space-separated integers si, ti, ki (1 ≤ si, ti ≤ n, si ≠ ti, 0 ≤ ki ≤ 1000) — the number of starting city, finishing city and the number of possible car changes in i-th round, correspondingly.

Output

For each round you should print the minimum required time to complete the round in a single line.

Examples

Input

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

Output

3
4
3

Input

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

Output

4
5
3

Note

In the first sample, in all rounds PMP goes from city #1 to city #2, then city #3 and finally city #4. But the sequences of types of the cars he uses are (1, 2, 1) in the first round and (1, 2, 2) in the second round. In the third round, although he can change his car three times, he uses the same strategy as the first round which only needs two car changes.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 70 + 20, N2 = 1e4 + 10, MOD = 1e9 + 7, MAX_CHAR = 26;
int n, m, r, sp[N][N][N], sptemp[N][N];
int main() {
  scanf("%d%d%d", &n, &m, &r);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      for (int k = 0; k < N; k++) sp[i][j][k] = 1e9;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        scanf("%d", &sptemp[j][k]);
      }
    }
    for (int mid = 0; mid < n; mid++) {
      for (int fr = 0; fr < n; fr++) {
        for (int to = 0; to < n; to++) {
          sptemp[fr][to] =
              min(sptemp[fr][mid] + sptemp[mid][to], sptemp[fr][to]);
          sp[fr][to][1] = min(sptemp[fr][to], sp[fr][to][1]);
        }
      }
    }
  }
  for (int kk = 2; kk < N; kk++) {
    for (int mm = 0; mm < n; mm++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          sp[i][j][kk] = min(sp[i][j][kk], sp[i][mm][kk - 1] + sp[mm][j][1]);
        }
      }
    }
  }
  while (r--) {
    int a, b, km;
    scanf("%d%d%d", &a, &b, &km);
    a--, b--, km++;
    km = min(60, km);
    printf("%d\n", sp[a][b][km]);
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

At the Byteland State University marks are strings of the same length. Mark x is considered better than y if string y is lexicographically smaller than x.

Recently at the BSU was an important test work on which Vasya recived the mark a. It is very hard for the teacher to remember the exact mark of every student, but he knows the mark b, such that every student recieved mark strictly smaller than b.

Vasya isn't satisfied with his mark so he decided to improve it. He can swap characters in the string corresponding to his mark as many times as he like. Now he want to know only the number of different ways to improve his mark so that his teacher didn't notice something suspicious.

More formally: you are given two strings a, b of the same length and you need to figure out the number of different strings c such that:

1) c can be obtained from a by swapping some characters, in other words c is a permutation of a.

2) String a is lexicographically smaller than c.

3) String c is lexicographically smaller than b.

For two strings x and y of the same length it is true that x is lexicographically smaller than y if there exists such i, that x1 = y1, x2 = y2, ..., xi - 1 = yi - 1, xi < yi.

Since the answer can be very large, you need to find answer modulo 109 + 7.

Input

First line contains string a, second line contains string b. Strings a, b consist of lowercase English letters. Their lengths are equal and don't exceed 106.

It is guaranteed that a is lexicographically smaller than b.

Output

Print one integer — the number of different strings satisfying the condition of the problem modulo 109 + 7.

Examples

Input

abc
ddd

Output

5

Input

abcdef
abcdeg

Output

0

Input

abacaba
ubuduba

Output

64

Note

In first sample from string abc can be obtained strings acb, bac, bca, cab, cba, all of them are larger than abc, but smaller than ddd. So the answer is 5.

In second sample any string obtained from abcdef is larger than abcdeg. So the answer is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int ans[2];
int cnt[26];
int cnt2[26];
long long fact[1000003];
string s1, s2, t;
long long calcPow(long long x, long long y) {
  if (!y) return 1;
  long long tmp = calcPow(x, y / 2);
  tmp = (tmp * tmp) % 1000000007;
  if (y & 1) tmp = (tmp * x) % 1000000007;
  return tmp;
}
void f(int ind, int kd, long long q) {
  if (ind == n) {
    ans[kd] = (ans[kd] + 1) % 1000000007;
    return;
  }
  int val = t[ind] - 'a';
  for (int i = 0; i < val; i++)
    if (cnt[i]) {
      long long add = (q * cnt[i]) % 1000000007;
      add = (add * fact[n - ind - 1]) % 1000000007;
      ans[kd] = (ans[kd] + add) % 1000000007;
    }
  if (cnt[val]) {
    long long c = cnt[val];
    cnt[val]--;
    f(ind + 1, kd, (q * c) % 1000000007);
    cnt[val]++;
  }
}
int main() {
  cin >> s1 >> s2;
  n = s1.length();
  for (int i = 0; i < n; i++) cnt[s1[i] - 'a']++;
  for (int i = 0; i < n; i++) cnt2[s2[i] - 'a']++;
  bool same = true;
  for (int i = 0; i < 26; i++)
    if (cnt[i] != cnt2[i]) same = false;
  fact[0] = 1;
  for (int i = 1; i <= n; i++) fact[i] = (fact[i - 1] * i) % 1000000007;
  long long q = 1;
  for (int i = 0; i < 26; i++) q = (q * fact[cnt[i]]) % 1000000007;
  q = calcPow(q, 1000000007 - 2);
  t = s1;
  f(0, 0, q);
  t = s2;
  f(0, 1, q);
  int res = (ans[1] - ans[0] + 1000000007) % 1000000007;
  res = (res - same + 1000000007) % 1000000007;
  printf("%d\n", res);
}

```


### Prompt

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

This is the hard version of the problem. The only difference is that here 2≤ k≤ 100. You can make hacks only if both the versions of the problem are solved.

This is an interactive problem!

Every decimal number has a base k equivalent. The individual digits of a base k number are called k-its. Let's define the k-itwise XOR of two k-its a and b as (a + b)mod k.

The k-itwise XOR of two base k numbers is equal to the new number formed by taking the k-itwise XOR of their corresponding k-its. The k-itwise XOR of two decimal numbers a and b is denoted by a⊕_{k} b and is equal to the decimal representation of the k-itwise XOR of the base k representations of a and b. All further numbers used in the statement below are in decimal unless specified.

You have hacked the criminal database of Rockport Police Department (RPD), also known as the Rap Sheet. But in order to access it, you require a password. You don't know it, but you are quite sure that it lies between 0 and n-1 inclusive. So, you have decided to guess it. Luckily, you can try at most n times without being blocked by the system. But the system is adaptive. Each time you make an incorrect guess, it changes the password. Specifically, if the password before the guess was x, and you guess a different number y, then the system changes the password to a number z such that x⊕_{k} z=y. Guess the password and break into the system.

Input

The first line of input contains a single integer t (1≤ t≤ 10 000) denoting the number of test cases. t test cases follow.

The first line of each test case contains two integers n (1≤ n≤ 2⋅ 10^5) and k (2≤ k≤ 100).

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

Interaction

For each test case, first read two integers n and k. Then you may ask up to n queries.

For each query, print a single integer y (0≤ y≤ 2⋅ 10^7). Let the current password be x. After that, read an integer r.

If x=y, you will read r=1 and the test case is solved. You must then continue solving the remaining test cases.

Else, you will read r=0. At this moment the password is changed to a number z such that x⊕_{k} z=y.

After printing a query, do not forget to output the end of line and flush the output. Otherwise, you will get the Idleness limit exceeded verdict.

To do this, use:

  * fflush(stdout) or cout.flush() in C++;
  * System.out.flush() in Java;
  * flush(output) in Pascal;
  * stdout.flush() in Python;
  * see documentation for other languages.

If you ask an invalid query or exceed n queries, you will read r=-1 and you will receive the Wrong Answer verdict. Make sure to exit immediately to avoid unexpected verdicts.

Note that the interactor is adaptive. That is, the original password is not fixed in the beginning and may depend on your queries. But it is guaranteed that at any moment there is at least one initial password such that all the answers to the queries are consistent.

Hacks:

To use hacks, use the following format of tests:

The first line should contain a single integer t (1≤ t≤ 10 000) — the number of test cases.

The first and only line of each test case should contain two integers n (1≤ n≤ 2⋅ 10^5) and k (2≤ k≤ 100) denoting the number of queries and the base respectively. The optimal original password is automatically decided by the adaptive interactor.

You must ensure that the sum of n over all test cases does not exceed 2⋅ 10^5.

Example

Input

2
5 2

0

0

1
5 3

0

0

1

Output

3

4

5

1

4

6

Note

Test Case 1:

In this case, the hidden password is 2.

The first query is 3. It is not equal to the current password. So, 0 is returned, and the password is changed to 1 since 2⊕_2 1=3.

The second query is 4. It is not equal to the current password. So, 0 is returned, and the password is changed to 5 since 1⊕_2 5=4.

The third query is 5. It is equal to the current password. So, 1 is returned, and the job is done.

Test Case 2:

In this case, the hidden password is 3.

The first query is 1. It is not equal to the current password. So, 0 is returned, and the password is changed to 7 since 3⊕_3 7=1. [3=(10)_3, 7=(21)_3, 1=(01)_3 and (10)_3⊕_3 (21)_3 = (01)_3].

The second query is 4. It is not equal to the current password. So, 0 is returned, and the password is changed to 6 since 7⊕_3 6=4. [7=(21)_3, 6=(20)_3, 4=(11)_3 and (21)_3⊕_3 (20)_3 = (11)_3].

The third query is 6. It is equal to the current password. So, 1 is returned, and the job is done.

Note that these initial passwords are taken just for the sake of explanation. In reality, the grader might behave differently because it is adaptive.

### Response

```cpp
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define X first
#define Y second
#define nl '\n'
#define AC return 0
#define pb(a) push_back(a)
#define mst(a,b) memset(a, b, sizeof a)
#define rep(i,n) for(int i = 0; (i)<(n); i++)
#define rep1(i,n) for(int i = 1; (i)<=(n); i++)
#define scd(a) scanf("%lld", &a)
#define scdd(a,b) scanf("%lld%lld", &a, &b)
#define scs(s) scanf("%s", s)
//#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18;
const int N = 1e6+10, M = 2e6+10, mod = 1e9+7, inf = 0x3f3f3f3f;

// ll kXor(ll num1, ll num2, ll k)	//无进位加法
// {
// 	ll pw = 1, ans = 0;
// 	while(num1 || num2)
// 	{
// 		ans += (num1 % k + num2 % k) % k * pw;
// 		num1 /= k;
// 		num2 /= k;
// 		pw *= k;
// 	}
// }

ll kXor(ll num1, ll num2, ll k)	//无进位减法
{
	ll pw = 1, ans = 0;
	while(num1 || num2)
	{
		ans += (num1 % k - num2 % k + k) % k * pw;
		num1 /= k;
		num2 /= k;
		pw *= k;
	}
	return ans;
}

int main()
{
	IOS;
	int _;
	cin>>_;
	// _ = 1;
	while(_--)
	{
		ll n, k, r;
		cin>>n>>k;
		rep(i, n)
		{
			if(i == 0)
				cout<<0<<nl;
			else if(i & 1)
				cout<<kXor(i - 1, i, k)<<nl;
			else
				cout<<kXor(i, i - 1, k)<<nl;
			cout.flush();
			cin>>r;
			if(r == 1)
				break;
		}
	}

	AC;
}

```


### Prompt

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

The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help.

A message is a sequence of n integers a1, a2, ..., an. Encryption uses a key which is a sequence of m integers b1, b2, ..., bm (m ≤ n). All numbers from the message and from the key belong to the interval from 0 to c - 1, inclusive, and all the calculations are performed modulo c.

Encryption is performed in n - m + 1 steps. On the first step we add to each number a1, a2, ..., am a corresponding number b1, b2, ..., bm. On the second step we add to each number a2, a3, ..., am + 1 (changed on the previous step) a corresponding number b1, b2, ..., bm. And so on: on step number i we add to each number ai, ai + 1, ..., ai + m - 1 a corresponding number b1, b2, ..., bm. The result of the encryption is the sequence a1, a2, ..., an after n - m + 1 steps.

Help the Beaver to write a program that will encrypt messages in the described manner.

Input

The first input line contains three integers n, m and c, separated by single spaces.

The second input line contains n integers ai (0 ≤ ai < c), separated by single spaces — the original message.

The third input line contains m integers bi (0 ≤ bi < c), separated by single spaces — the encryption key.

The input limitations for getting 30 points are:

  * 1 ≤ m ≤ n ≤ 103
  * 1 ≤ c ≤ 103

The input limitations for getting 100 points are:

  * 1 ≤ m ≤ n ≤ 105
  * 1 ≤ c ≤ 103

Output

Print n space-separated integers — the result of encrypting the original message.

Examples

Input

4 3 2
1 1 1 1
1 1 1

Output

0 1 1 0

Input

3 1 5
1 2 3
4

Output

0 1 2

Note

In the first sample the encryption is performed in two steps: after the first step a = (0, 0, 0, 1) (remember that the calculations are performed modulo 2), after the second step a = (0, 1, 1, 0), and that is the answer.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int num1[100010];
int num2[100010];
int n, m, c;
int find(int i, int j) {
  if (i < 0) return num2[j];
  return num2[j] - num2[i];
}
int main() {
  cin >> n >> m >> c;
  for (int i = 0; i < n; i++) scanf("%d", num1 + i);
  for (int i = 0; i < m; i++) scanf("%d", num2 + i);
  for (int i = m; i < n; i++) num2[i] = 0;
  for (int i = 1; i < n; i++) num2[i] += num2[i - 1];
  for (int i = 0; i < n; i++) {
    num1[i] += find(i - (n - m + 1), i);
    num1[i] %= c;
  }
  for (int i = 0; i < n; i++) {
    cout << num1[i] << " ";
  }
  cout << "\n";
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.

In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.

It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.

Input

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

Each of the next n lines contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109).

It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.

Output

Print three distinct integers on a single line — the indices of the three points that form a triangle that satisfies the conditions stated in the problem.

If there are multiple possible answers, you may print any of them.

Examples

Input

3
0 1
1 0
1 1

Output

1 2 3

Input

5
0 0
0 2
2 0
2 2
1 1

Output

1 3 5

Note

In the first sample, we can print the three indices in any order.

In the second sample, we have the following picture.

<image>

Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct pos {
  int x, y, z;
  inline bool operator<(const pos t) const {
    if (x != t.x)
      return x < t.x;
    else
      return y < t.y;
  }
} g[120000];
int i, n;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d%d", &g[i].x, &g[i].y), g[i].z = i;
  sort(g + 1, g + n + 1), printf("%d %d ", g[1].z, g[2].z);
  for (i = 3;
       (g[i].x == g[1].x) || (1LL * (g[i].y - g[1].y) * (g[2].x - g[1].x) ==
                              1LL * (g[i].x - g[1].x) * (g[2].y - g[1].y));
       i++)
    ;
  printf("%d", g[i].z);
  return 0;
}

```