### Prompt

Please formulate a cpp solution to the following problem:

Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same length such that:

  * b is lexicographically greater than or equal to a.
  * bi ≥ 2.
  * b is pairwise coprime: for every 1 ≤ i < j ≤ n, bi and bj are coprime, i. e. GCD(bi, bj) = 1, where GCD(w, z) is the greatest common divisor of w and z.

Ehab wants to choose a special array so he wants the lexicographically minimal array between all the variants. Can you find it?

An array x is lexicographically greater than an array y if there exists an index i such than xi > yi and xj = yj for all 1 ≤ j < i. An array x is equal to an array y if xi = yi for all 1 ≤ i ≤ n.

Input

The first line contains an integer n (1 ≤ n ≤ 105), the number of elements in a and b.

The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 105), the elements of a.

Output

Output n space-separated integers, the i-th of them representing bi.

Examples

Input

5
2 3 5 4 13

Output

2 3 5 7 11

Input

3
10 3 7

Output

10 3 7

Note

Note that in the second sample, the array is already pairwise coprime so we printed it.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mxP = 3e6;
vector<bool> pos(mxP, 1);
void ridPrime(int p) {
  for (int i = p; i < mxP; i += p) {
    pos[i] = 0;
  }
}
void doStuff(int x) {
  set<int> p_f;
  for (int i = 2; i * i <= x;) {
    if (x % i == 0) {
      x /= i;
      p_f.insert(i);
    } else
      ++i;
  }
  if (x > 1) p_f.insert(x);
  for (const int &i : p_f) {
    ridPrime(i);
  }
}
int n, l = 2;
bool g = 0;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0, a; i < n; ++i) {
    cin >> a;
    if (!g && pos[a]) {
      cout << a << ' ';
      doStuff(a);
    } else if (!g) {
      g = 1;
      while (pos[a] == 0) ++a;
      cout << a << ' ';
      doStuff(a);
    } else {
      assert(l < mxP);
      while (pos[l] == 0) ++l;
      cout << l << ' ';
      doStuff(l);
      continue;
    }
  }
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 ≤ li ≤ ri ≤ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.

Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 ≤ xi ≤ yi ≤ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.

Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.

Input

The first line contains integers n, m, k (1 ≤ n, m, k ≤ 105). The second line contains n integers: a1, a2, ..., an (0 ≤ ai ≤ 105) — the initial array.

Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 ≤ li ≤ ri ≤ n), (0 ≤ di ≤ 105).

Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 ≤ xi ≤ yi ≤ m).

The numbers in the lines are separated by single spaces.

Output

On a single line print n integers a1, a2, ..., an — the array after executing all the queries. Separate the printed numbers by spaces.

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

Examples

Input

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

Output

9 18 17

Input

1 1 1
1
1 1 1
1 1

Output

2

Input

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

Output

5 18 31 20

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long datas[200000];
long long kl[200000][3] = {0};
long long pl[200000] = {0};
long long cl[200000] = {0};
long long m, n, k;
int main() {
  ios::sync_with_stdio(false);
  cin >> m >> n >> k;
  long long a, b;
  for (long long i = 0; i < m; i++) {
    cin >> datas[i];
  }
  for (long long i = 0; i < n; i++) {
    cin >> kl[i][0] >> kl[i][1] >> kl[i][2];
  }
  for (long long i = 0; i < k; i++) {
    cin >> a >> b;
    pl[a - 1]++;
    pl[b]--;
  }
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    sum += pl[i];
    kl[i][2] *= sum;
  }
  for (long long i = 0; i < n; i++) {
    cl[kl[i][0] - 1] += kl[i][2];
    cl[kl[i][1]] -= kl[i][2];
  }
  sum = 0;
  for (long long i = 0; i < m; i++) {
    sum += cl[i];
    if (i + 1 == m)
      cout << sum + datas[i] << endl;
    else
      cout << sum + datas[i] << ' ';
  }
  return 0;
}

```


### Prompt

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

Takahashi's office has N rooms. Each room has an ID from 1 to N. There are also N-1 corridors, and the i-th corridor connects Room a_i and Room b_i. It is known that we can travel between any two rooms using only these corridors.

Takahashi has got lost in one of the rooms. Let this room be r. He decides to get back to his room, Room 1, by repeatedly traveling in the following manner:

* Travel to the room with the smallest ID among the rooms that are adjacent to the rooms already visited, but not visited yet.

Let c_r be the number of travels required to get back to Room 1. Find all of c_2,c_3,...,c_N. Note that, no matter how many corridors he passes through in a travel, it still counts as one travel.

Constraints

* 2 \leq N \leq 2\times 10^5
* 1 \leq a_i,b_i \leq N
* a_i \neq b_i
* The graph given as input is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
:
a_{N-1} b_{N-1}

Output

Print c_r for each r, in the following format:

c_2 c_3 ... c_N

Output

Print c_r for each r, in the following format:

c_2 c_3 ... c_N

Examples

Input

6
1 5
5 6
6 2
6 3
6 4

Output

5 5 5 1 5

Input

6
1 2
2 3
3 4
4 5
5 6

Output

1 2 3 4 5

Input

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

Output

7 5 3 1 3 4 7 4 5

### Response

```cpp
#include <map>
#include <cstdio>
using namespace std;

const int MAXN = 2e5 + 5;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

template<typename _T>
_T MAX( const _T a, const _T b )
{
	return a > b ? a : b;
}

struct edge
{
	int to, nxt;
}Graph[MAXN << 1];

map<int, int> q[MAXN];

int mx[MAXN], c[MAXN];
int head[MAXN];
int N, cnt;

void addEdge( const int from, const int to )
{
	Graph[++ cnt].to = to, Graph[cnt].nxt = head[from];
	head[from] = cnt;
}

int Q( const int u, const int fa, const int val )
{
	if( q[u][val] ) return q[u][val];
	q[u][val] = 1;
	for( int i = head[u], v ; i ; i = Graph[i].nxt )
		if( ( v = Graph[i].to ) ^ fa && v < val )
			q[u][val] += Q( v, u, val );
	return q[u][val];
}

void DFS( const int u, const int fa )
{
	mx[u] = MAX( u, mx[fa] );
	for( int i = head[u], v ; i ; i = Graph[i].nxt )
		if( ( v = Graph[i].to ) ^ fa )
		{
			if( mx[u] == u )
			{
				c[v] = c[u] + Q( v, u, mx[u] );
				if( v < mx[fa] ) c[v] -= Q( v, u, mx[fa] );
			}
			else
			{
				if( v < mx[u] ) c[v] = c[u];
				else c[v] = c[u] + Q( v, u, mx[u] );
			}
			DFS( v, u );
		}
}

int main()
{
	read( N );
	for( int i = 1, a, b ; i < N ; i ++ )
		read( a ), read( b ), addEdge( a, b ), addEdge( b, a );
	DFS( 1, 0 );
	for( int i = 2 ; i <= N ; i ++ ) write( c[i] ), putchar( i == N ? '\n' : ' ' );
	return 0;
}
```


### Prompt

Generate a Cpp solution to the following problem:

You are playing a video game and you have just reached the bonus level, where the only possible goal is to score as many points as possible. Being a perfectionist, you've decided that you won't leave this level until you've gained the maximum possible number of points there.

The bonus level consists of n small platforms placed in a line and numbered from 1 to n from left to right and (n - 1) bridges connecting adjacent platforms. The bridges between the platforms are very fragile, and for each bridge the number of times one can pass this bridge from one of its ends to the other before it collapses forever is known in advance.

The player's actions are as follows. First, he selects one of the platforms to be the starting position for his hero. After that the player can freely move the hero across the platforms moving by the undestroyed bridges. As soon as the hero finds himself on a platform with no undestroyed bridge attached to it, the level is automatically ended. The number of points scored by the player at the end of the level is calculated as the number of transitions made by the hero between the platforms. Note that if the hero started moving by a certain bridge, he has to continue moving in the same direction until he is on a platform.

Find how many points you need to score to be sure that nobody will beat your record, and move to the next level with a quiet heart.

Input

The first line contains a single integer n (2 ≤ n ≤ 105) — the number of platforms on the bonus level. The second line contains (n - 1) integers ai (1 ≤ ai ≤ 109, 1 ≤ i < n) — the number of transitions from one end to the other that the bridge between platforms i and i + 1 can bear.

Output

Print a single integer — the maximum number of points a player can get on the bonus level.

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

Examples

Input

5
2 1 2 1

Output

5

Note

One possibility of getting 5 points in the sample is starting from platform 3 and consequently moving to platforms 4, 3, 2, 1 and 2. After that the only undestroyed bridge is the bridge between platforms 4 and 5, but this bridge is too far from platform 2 where the hero is located now.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, ma, a[100100], dp1[100100], dp2[100100], dp3[100100], dp4[100100];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n - 1; i++) cin >> a[i];
  for (int i = 1; i <= n - 1; i++) {
    dp2[i] = ((a[i] % 2 == 0) ? a[i] : (a[i] - 1)) + dp2[i - 1];
    if (a[i] == 1) dp2[i] = 0;
    dp1[i] = max(dp2[i], dp1[i - 1] + ((a[i] & 1) ? a[i] : (a[i] - 1)));
  }
  for (int i = n - 2; i >= 1; i--) {
    dp4[i] = ((a[i + 1] % 2 == 0) ? a[i + 1] : (a[i + 1] - 1)) + dp4[i + 1];
    if (a[i + 1] == 1) dp4[i] = 0;
    dp3[i] =
        max(dp4[i], dp3[i + 1] + ((a[i + 1] & 1) ? a[i + 1] : (a[i + 1] - 1)));
  }
  for (int i = 1; i <= n - 1; i++)
    ma = max(ma, max(dp2[i] + dp3[i], dp1[i] + dp4[i]));
  cout << ma;
  return -0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

There are n children, who study at the school №41. It is well-known that they are good mathematicians. Once at a break, they arranged a challenge for themselves. All children arranged in a row and turned heads either to the left or to the right.

Children can do the following: in one second several pairs of neighboring children who are looking at each other can simultaneously turn the head in the opposite direction. For instance, the one who was looking at the right neighbor turns left and vice versa for the second child. Moreover, every second at least one pair of neighboring children performs such action. They are going to finish when there is no pair of neighboring children who are looking at each other.

You are given the number n, the initial arrangement of children and the number k. You have to find a way for the children to act if they want to finish the process in exactly k seconds. More formally, for each of the k moves, you need to output the numbers of the children who turn left during this move.

For instance, for the configuration shown below and k = 2 children can do the following steps:

<image> At the beginning, two pairs make move: (1, 2) and (3, 4). After that, we receive the following configuration:  <image> At the second move pair (2, 3) makes the move. The final configuration is reached. Good job.  <image>

It is guaranteed that if the solution exists, it takes not more than n^2 "headturns".

Input

The first line of input contains two integers n and k (2 ≤ n ≤ 3000, 1 ≤ k ≤ 3000000) — the number of children and required number of moves.

The next line contains a string of length n and consists only of characters L and R, where L means that the child looks to the left and R means that the child looks to the right.

Output

If there is no solution, print a single line with number -1.

Otherwise, output k lines. Each line has to start with a number n_i (1≤ n_i ≤ n/2) — the number of pairs of children, who turn at this move. After that print n_i distinct integers — the numbers of the children who will turn left during this move.

After performing all "headturns", there can't be a pair of two neighboring children looking at each other.

If there are many solutions, print any of them.

Examples

Input

2 1
RL

Output

1 1

Input

2 1
LR

Output

-1

Input

4 2
RLRL

Output

2 1 3
1 2

Note

The first sample contains a pair of children who look at each other. After one move, they can finish the process.

In the second sample, children can't make any move. As a result, they can't end in k>0 moves.

The third configuration is described in the statement.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i, cnt = 0;
  string s;
  cin >> n >> k >> s;
  vector<vector<int>> a;
  while (1) {
    vector<int> temp;
    for (i = 0; i < n - 1; i++) {
      if (s[i] > s[i + 1]) {
        temp.push_back(i);
        cnt++;
      }
    }
    if (temp.empty()) break;
    for (int j : temp) {
      swap(s[j], s[j + 1]);
    }
    a.push_back(temp);
  }
  if (k < a.size() || k > cnt) {
    cout << -1;
  } else {
    for (vector<int> &d : a) {
      while (d.size() > 1 && k > a.size()) {
        cout << "1 " << d.back() + 1 << "\n";
        d.pop_back();
        k--;
      }
      cout << d.size();
      for (int j = 0; j < d.size(); j++) {
        cout << " " << d[j] + 1;
      }
      cout << "\n";
    }
  }
  return 0;
}

```


### Prompt

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

You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.

Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in circles muttering about how useless her sweetheart is. During that time Dima has time to peacefully complete k - 1 tasks. Then Inna returns and tells Dima off for the next task he does in her presence and goes to another room again. It continues until Dima is through with his tasks.

Overall, Dima has n tasks to do, each task has a unique number from 1 to n. Dima loves order, so he does tasks consecutively, starting from some task. For example, if Dima has 6 tasks to do in total, then, if he starts from the 5-th task, the order is like that: first Dima does the 5-th task, then the 6-th one, then the 1-st one, then the 2-nd one, then the 3-rd one, then the 4-th one.

Inna tells Dima off (only lovingly and appropriately!) so often and systematically that he's very well learned the power with which she tells him off for each task. Help Dima choose the first task so that in total he gets told off with as little power as possible.

Input

The first line of the input contains two integers n, k (1 ≤ k ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103), where ai is the power Inna tells Dima off with if she is present in the room while he is doing the i-th task.

It is guaranteed that n is divisible by k.

Output

In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do.

Examples

Input

6 2
3 2 1 6 5 4

Output

1

Input

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

Output

3

Note

Explanation of the first example.

If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as k = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If Dima started from the second task, for example, then Inna would tell him off for tasks 2, 4 and 6 with power 2 + 6 + 4 = 12.

Explanation of the second example.

In the second example k = 5, thus, Dima manages to complete 4 tasks in-between the telling off sessions. Thus, Inna tells Dima off for tasks number 1 and 6 (if he starts from 1 or 6), 2 and 7 (if he starts from 2 or 7) and so on. The optimal answer is to start from task 3 or 8, 3 has a smaller number, so the answer is 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, task[100100];
  while (scanf("%d%d", &n, &k) != EOF) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &task[i]);
    }
    int min = 0x7fffffff, minpos = -1;
    for (int i = 0; i < k; i++) {
      int sum = task[i];
      int j = (i + k) % n;
      while (i != j) {
        sum += task[j];
        j = (j + k) % n;
      }
      if (sum < min) {
        min = sum;
        minpos = i;
      }
    }
    cout << minpos + 1 << endl;
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Xenia likes puzzles very much. She is especially fond of the puzzles that consist of domino pieces. Look at the picture that shows one of such puzzles.

<image>

A puzzle is a 3 × n table with forbidden cells (black squares) containing dominoes (colored rectangles on the picture). A puzzle is called correct if it meets the following conditions:

  * each domino occupies exactly two non-forbidden cells of the table;
  * no two dominoes occupy the same table cell;
  * exactly one non-forbidden cell of the table is unoccupied by any domino (it is marked by a circle in the picture).

To solve the puzzle, you need multiple steps to transport an empty cell from the starting position to some specified position. A move is transporting a domino to the empty cell, provided that the puzzle stays correct. The horizontal dominoes can be moved only horizontally, and vertical dominoes can be moved only vertically. You can't rotate dominoes. The picture shows a probable move.

Xenia has a 3 × n table with forbidden cells and a cell marked with a circle. Also, Xenia has very many identical dominoes. Now Xenia is wondering, how many distinct correct puzzles she can make if she puts dominoes on the existing table. Also, Xenia wants the circle-marked cell to be empty in the resulting puzzle. The puzzle must contain at least one move.

Help Xenia, count the described number of puzzles. As the described number can be rather large, print the remainder after dividing it by 1000000007 (109 + 7).

Input

The first line contains integer n (3 ≤ n ≤ 104) — the puzzle's size. Each of the following three lines contains n characters — the description of the table. The j-th character of the i-th line equals "X" if the corresponding cell is forbidden; it equals ".", if the corresponding cell is non-forbidden and "O", if the corresponding cell is marked with a circle.

It is guaranteed that exactly one cell in the table is marked with a circle. It is guaranteed that all cells of a given table having at least one common point with the marked cell is non-forbidden.

Output

Print a single number — the answer to the problem modulo 1000000007 (109 + 7).

Examples

Input

5
....X
.O...
...X.

Output

1

Input

5
.....
.O...
.....

Output

2

Input

3
...
...
..O

Output

4

Note

Two puzzles are considered distinct if there is a pair of cells that contain one domino in one puzzle and do not contain it in the other one.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T min(T &a, T &b) {
  return a < b ? a : b;
}
template <class T>
inline T max(T &a, T &b) {
  return a > b ? a : b;
}
template <class T>
void read(T &x) {
  char ch;
  while ((ch = getchar()) && !isdigit(ch))
    ;
  x = ch - '0';
  while ((ch = getchar()) && isdigit(ch)) x = x * 10 + ch - '0';
}
struct point {
  int x, y;
  point() {}
  point(int _x, int _y) : x(_x), y(_y) {}
};
const int N = 11000, Mod = 1000000007;
int dp[N][8], n, dt[4][N], Ox, Oy, ans, ty[10];
char s[N];
int get() {
  memset(dp, 0, sizeof(dp));
  ;
  dp[0][7] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 7; j++)
      for (int k = 0; k <= 7; k++) {
        int flag = 0;
        for (int l = 0; l <= 2; l++)
          if (!(j & (1 << l)) && (!(k & (1 << l)) || dt[l + 1][i])) flag = 1;
        for (int l = 0; l <= 2; l++)
          if (dt[l + 1][i] && !(k & (1 << l))) flag = 1;
        for (int l = 0; l <= 2; l++)
          if (!dt[l + 1][i] && (j & (1 << l)) && (k & (1 << l))) flag = 1;
        if (flag) continue;
        dp[i][k] = (dp[i][k] + dp[i - 1][j]) % Mod;
      }
    if (dt[1][i] == 0 && dt[2][i] == 0) dp[i][3] = (dp[i][3] + dp[i][0]) % Mod;
    if (dt[2][i] == 0 && dt[3][i] == 0) dp[i][6] = (dp[i][6] + dp[i][0]) % Mod;
    if (dt[1][i] == 0 && dt[2][i] == 0) dp[i][7] = (dp[i][7] + dp[i][4]) % Mod;
    if (dt[2][i] == 0 && dt[3][i] == 0) dp[i][7] = (dp[i][7] + dp[i][1]) % Mod;
  }
  return dp[n][7];
}
void work(int ty) {
  if (ty == 0)
    dt[Ox][Oy - 1] ^= 1, dt[Ox][Oy - 2] ^= 1;
  else if (ty == 1)
    dt[Ox][Oy + 1] ^= 1, dt[Ox][Oy + 2] ^= 1;
  else if (ty == 2)
    dt[Ox + 1][Oy] ^= 1, dt[Ox + 2][Oy] ^= 1;
  else
    dt[Ox - 1][Oy] ^= 1, dt[Ox - 2][Oy] ^= 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 3; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= n; j++) {
      if (s[j] != '.') dt[i][j] = 1;
      if (s[j] == 'O') Ox = i, Oy = j;
    }
  }
  if (Oy > 2 && !dt[Ox][Oy - 1] && !dt[Ox][Oy - 2]) {
    work(0);
    ans = (ans + get()) % Mod;
    work(0);
    ty[0] = 1;
  }
  if (Oy + 2 <= n && !dt[Ox][Oy + 1] && !dt[Ox][Oy + 2]) {
    work(1);
    ans = (ans + get()) % Mod;
    work(1);
    ty[1] = 1;
  }
  if (Ox == 1 && !dt[Ox + 1][Oy] && !dt[Ox + 2][Oy]) {
    work(2);
    ans = (ans + get()) % Mod;
    work(2);
    ty[2] = 1;
  }
  if (Ox == 3 && !dt[Ox - 1][Oy] && !dt[Ox - 2][Oy]) {
    work(3);
    ans = (ans + get()) % Mod;
    work(3);
    ty[3] = 1;
  }
  for (int i = 0; i <= 3; i++)
    for (int j = i + 1; j <= 3; j++)
      if (ty[i] && ty[j]) {
        work(i);
        work(j);
        ans = (ans - get()) % Mod;
        work(i);
        work(j);
      }
  for (int i = 0; i <= 3; i++)
    for (int j = i + 1; j <= 3; j++)
      for (int k = j + 1; k <= 3; k++)
        if (ty[i] && ty[j] && ty[k]) {
          work(i);
          work(j);
          work(k);
          ans = (ans + get()) % Mod;
          work(i);
          work(j);
          work(k);
        }
  printf("%d\n", (ans + Mod) % Mod);
}

```


### Prompt

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

Takeshi, who loves hot springs, is planning a trip to a hot spring resort on his next long vacation. I would like to travel by connecting to a long-distance bus and reach my destination with as little money as possible. Takeshi, who has savings but is unwilling to pay, decided to consult with his grandfather. The grandfather, who was impressed by the plan, gave Takeshi a special ticket.

The ticket was that you could ride two consecutive sections of a long-distance bus only once for free. Depending on how you use it, you can expect a considerable reduction in travel costs, but you need to make a solid plan in order to achieve a greater effect.

A total of n departure points, destinations, and relay points, and m lines connecting the two points are given. Each point is assigned a number from 1 to n. The starting point is 1 and the destination is n. Route information is represented by the two points a and b that connect the route and its fare c. Due to the special ticket validity, you can pass two consecutive lines from any point at no charge. However, passing through the destination on the way does not mean that you have reached the destination.

Create a program that outputs the minimum fare by inputting the total number of departure points, destinations, and relay points n, the number of routes m, and the information of each route. However, there must always be a route from the origin to the destination.

input

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

n m
a1 b1 c1
a2 b2 c2
::
am bm cm

The first line gives the total number of origins, destinations, and transit points n (2 ≤ n ≤ 100) and the number of routes m (1 ≤ m ≤ 300). The following m lines give information for each line ai, bi, ci (1 ≤ ci ≤ 1000).

The number of datasets does not exceed 40.

output

Prints the minimum charge on one line for each input dataset.

Example

Input

2 1
1 2 5
3 2
1 2 5
2 3 5
6 9
1 2 7
1 3 9
1 5 14
2 3 10
2 4 15
3 4 11
3 5 2
4 5 9
4 6 8
0 0

Output

5
0
7

### Response

```cpp
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
typedef pair<pii,int>piii;
int main(){
    int n,m;
    while(cin>>n>>m,n+m){
        vvi hoge(n+1,vi(n+1,INF));
        //edge[index]=(distance,next_vertex)
        vector<vector<pii>>edge(n,vector<pii>());
        vector<vector<pii>>temp(n,vector<pii>());
        rep(i,m){
            int a,b,c; cin>>a>>b>>c;
            --a,--b;
            edge[a].push_back(pii(b,c));
            edge[b].push_back(pii(a,c));
        }
        vvi d(3,vi(n,INF));
        d[0][0]=0;
        priority_queue<piii,vector<piii>,greater<piii>>que;
        que.push(piii(pii(0,0),0));

        while(!que.empty()){
            piii now=que.top();que.pop();
        //cout<<now.first.first<<" "<<now.first.second<<" "<<now.second<<endl;
            for(int i=0; i<edge[now.second].size();i++){
                pii next=edge[now.second][i];
                if(now.first.second==0){
                    if(now.first.second==0&&d[0][next.first]>d[0][now.second]+next.second){
                        que.push(piii(pii(d[0][now.second]+next.second,0),next.first));
                        d[0][next.first]=d[0][now.second]+next.second;
                    }
                    if(now.first.second==0&&d[1][next.first]>d[0][now.second]){
                        d[1][next.first]=d[0][now.second];
                        que.push(piii(pii(now.first.first,1),next.first));
                    }
                }else if(now.first.second==1){
                    if(d[2][next.first]>d[1][now.second]){
                        que.push(piii(pii(d[1][now.second],2),next.first));
                        d[2][next.first]=d[1][now.second];
                    }
                }else if(now.first.second==2&&d[2][next.first]>d[2][now.second]+next.second){
                    d[2][next.first]=d[2][now.second]+next.second;
                    que.push(piii(pii(now.first.first+next.second,2),next.first));
                }
            }
        }
        cout<<min(d[0][n-1],d[2][n-1])<<endl;
    }
}
```


### Prompt

Please create a solution in cpp to the following problem:

Osaki

Osaki

English text is not available in this practice contest.

The Yamanote Line is a circular railway line laid in the 23 wards of Tokyo. The total route distance is 34.5km, and one lap takes about one hour. There are 29 stations in total. The line color is Uguisu color. The peak congestion rate exceeds 200%, making it one of the busiest railway lines in Japan. One train runs every three minutes during the busiest hours, and people who come to Tokyo for the first time are amazed at the sight.

Mr. Tetsuko loves the Yamanote Line and loves genuine railways. One day, she came up with the following question while reading her favorite book, the JR timetable. "How many vehicles are used a day on the Yamanote Line?"

She tried to figure out the minimum number of vehicles required for operation from the timetable. However, the number of trains was so large that she couldn't count it by herself. So she turned to you, a good programmer, for help.

Your job is to write a program to find the minimum number of cars required to operate the Yamanote Line from a given timetable. Since the Yamanote Line is a circular line, the timetable is often written with "Osaki Station" as the starting and ending stations for convenience. Therefore, only the departure and arrival times of each train at Osaki Station are recorded in the timetable given by her.

Although this cannot happen on the actual Yamanote Line, in order to simplify the situation setting, we will consider that the train can depart from Osaki Station immediately after it arrives at Osaki Station. In addition, there are cases where the time taken by Mr. Tetsuko is incorrect, or the train added by Mr. Tetsuko's delusion is mixed in the timetable, but you can not see them, so to the last The number must be calculated for the time as written.

If you write a program that works, she may invite you to a date on the train. However, it is up to you to accept or decline the invitation.

Input

The input consists of multiple datasets. Each dataset has the following format.

> n
> hh: mm: ss hh: mm: ss
> hh: mm: ss hh: mm: ss
> ...
> hh: mm: ss hh: mm: ss

The integer n in the first line is the number of trains included in the timetable. This value is guaranteed not to exceed 10,000. The departure time and arrival time of each train at Osaki Station are given in this order on the n lines from the 2nd line to the n + 1st line, and the departure time and arrival time are separated by a single space. Each time is expressed in the format hh: mm: ss, where hh is the hour, mm is the minute, and ss is the second. The range of each value is 0 ≤ hh <24, 0 ≤ mm <60, 0 ≤ ss <60. All of these numbers are prefixed with 0s as needed to be two digits.

Trains that run across 24:00 at night are not included. Therefore, the departure time is always before the arrival time.

The end of input is indicated by n = 0. It is not included in the dataset.

Output

For each dataset, output the minimum number of vehicles required on one line.

Sample Input

3
05:47:15 09:54:40
12:12:59 12:13:00
16:30:20 21:18:53
6
00:00:00 03:00:00
01:00:00 03:00:00
02:00:00 03:00:00
03:00:00 04:00:00
03:00:00 05:00:00
03:00:00 06:00:00
0

Output for the Sample Input

1
3

Example

Input

3
05:47:15 09:54:40
12:12:59 12:13:00
16:30:20 21:18:53
6
00:00:00 03:00:00
01:00:00 03:00:00
02:00:00 03:00:00
03:00:00 04:00:00
03:00:00 05:00:00
03:00:00 06:00:00
0

Output

1
3

### Response

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

typedef pair<long long, long long> P;
void solve(int n){
	vector<int> v;
	vector<P> w;
	for(int i=0; i<n; ++i){
		int a, b, h, m, s;
		scanf("%d:%d:%d", &h, &m, &s);
		a = 3600*h + 60*m + s;
		scanf("%d:%d:%d", &h, &m, &s);
		b = 3600*h + 60*m + s;
		w.push_back(P(a, b));
	}
	sort(w.begin(), w.end());
	for(int i=0; i<n; ++i){
		int a = w[i].first;
		int b = w[i].second;
		bool f = false;
		for(int j=0; j<v.size(); ++j)
			if(v[j] <= a){
				v[j] = b;
				f = true;
				break;
			}
		if(!f) v.push_back(b);
		sort(v.begin(), v.end());
	}
	cout << v.size() << "\n";
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int n;
		cin >> n;
		if(n == 0) return 0;
		solve(n);
	}
}

```


### Prompt

Generate a Cpp solution to the following problem:

Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node.

Let's index all the leaf nodes from the left to the right from 1 to 2h. The exit is located at some node n where 1 ≤ n ≤ 2h, the player doesn't know where the exit is so he has to guess his way out!

Amr follows simple algorithm to choose the path. Let's consider infinite command string "LRLRLRLRL..." (consisting of alternating characters 'L' and 'R'). Amr sequentially executes the characters of the string using following rules:

  * Character 'L' means "go to the left child of the current node";
  * Character 'R' means "go to the right child of the current node";
  * If the destination node is already visited, Amr skips current command, otherwise he moves to the destination node;
  * If Amr skipped two consecutive commands, he goes back to the parent of the current node before executing next command;
  * If he reached a leaf node that is not the exit, he returns to the parent of the current node;
  * If he reaches an exit, the game is finished.

Now Amr wonders, if he follows this algorithm, how many nodes he is going to visit before reaching the exit?

Input

Input consists of two integers h, n (1 ≤ h ≤ 50, 1 ≤ n ≤ 2h).

Output

Output a single integer representing the number of nodes (excluding the exit node) Amr is going to visit before reaching the exit by following this algorithm.

Examples

Input

1 2

Output

2

Input

2 3

Output

5

Input

3 6

Output

10

Input

10 1024

Output

2046

Note

A perfect binary tree of height h is a binary tree consisting of h + 1 levels. Level 0 consists of a single node called root, level h consists of 2h nodes called leaves. Each node that is not a leaf has exactly two children, left and right one.

Following picture illustrates the sample test number 3. Nodes are labeled according to the order of visit.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
int main() {
  long long h, n;
  cin >> h >> n;
  long long t = 1;
  for (int i = 0; i < h; i++) t *= 2;
  long long ans = 0;
  int hehe = 1;
  for (int i = 0; i < h; i++) {
    t /= 2;
    if (n > t) {
      if (hehe == 1)
        ans += t * 2;
      else
        ans++;
      n -= t, hehe = 1;
    } else {
      if (hehe == 0)
        ans += t * 2;
      else
        ans++;
      hehe = 0;
    }
  }
  cout << ans << endl;
  ;
  return 0;
}

```


### Prompt

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

You are given a positive integer n greater or equal to 2. For every pair of integers a and b (2 ≤ |a|, |b| ≤ n), you can transform a into b if and only if there exists an integer x such that 1 < |x| and (a ⋅ x = b or b ⋅ x = a), where |x| denotes the absolute value of x.

After such a transformation, your score increases by |x| points and you are not allowed to transform a into b nor b into a anymore.

Initially, you have a score of 0. You can start at any integer and transform it as many times as you like. What is the maximum score you can achieve?

Input

A single line contains a single integer n (2 ≤ n ≤ 100 000) — the given integer described above.

Output

Print an only integer — the maximum score that can be achieved with the transformations. If it is not possible to perform even a single transformation for all possible starting integers, print 0.

Examples

Input

4

Output

8

Input

6

Output

28

Input

2

Output

0

Note

In the first example, the transformations are 2 → 4 → (-2) → (-4) → 2.

In the third example, it is impossible to perform even a single transformation.

### Response

```cpp
#include <bits/stdc++.h>
int main(void) {
  int n;
  scanf("%d", &n);
  long long int ans = 0;
  for (int i = 2; i <= n; i++) {
    for (int j = 2; i * j <= n; j++) {
      ans += j;
    }
  }
  printf("%lld\n", 4 * ans);
}

```


### Prompt

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

In Japan, temperature is usually expressed using the Celsius (℃) scale. In America, they used the Fahrenheit (℉) scale instead. $20$ degrees Celsius is roughly equal to $68$ degrees Fahrenheit. A phrase such as "Today’s temperature is $68$ degrees" is commonly encountered while you are in America.

A value in Fahrenheit can be converted to Celsius by first subtracting $32$ and then multiplying by $\frac{5}{9}$. A simplified method may be used to produce a rough estimate: first subtract $30$ and then divide by $2$. Using the latter method, $68$ Fahrenheit is converted to $19$ Centigrade, i.e., $\frac{(68-30)}{2}$.

Make a program to convert Fahrenheit to Celsius using the simplified method: $C = \frac{F - 30}{2}$.

Input

The input is given in the following format.

$F$

The input line provides a temperature in Fahrenheit $F$ ($30 \leq F \leq 100$), which is an integer divisible by $2$.

Output

Output the converted Celsius temperature in a line.

Examples

Input

68

Output

19

Input

50

Output

10

### Response

```cpp
#include<iostream>
using namespace std;
int main(){
  int f,c;
  cin >> f;
  c = (f-30)/2;
  cout << c << endl;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

A tree is an undirected graph with exactly one simple path between each pair of vertices. We call a set of simple paths k-valid if each vertex of the tree belongs to no more than one of these paths (including endpoints) and each path consists of exactly k vertices.

You are given a tree with n vertices. For each k from 1 to n inclusive find what is the maximum possible size of a k-valid set of simple paths.

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vertices in the tree.

Then following n - 1 lines describe the tree, each of them contains two integers v, u (1 ≤ v, u ≤ n) — endpoints of the corresponding edge.

It is guaranteed, that the given graph is a tree.

Output

Output n numbers, the i-th of which is the maximum possible number of paths in an i-valid set of paths.

Examples

Input

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

Output

7
3
2
1
1
1
1

Input

6
1 2
2 3
2 4
1 5
5 6

Output

6
2
2
1
1
0

Note

One way to achieve the optimal number of paths for the second sample is illustrated in the following picture:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = ' ';
  while (!isdigit(ch)) {
    ch = getchar();
    if (ch == '-') f = -1;
  }
  while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return x * f;
}
int n, ans, tot, h[100003];
vector<int> g[100003];
struct AB {
  int a, b, n;
} d[100003];
void charu(int a, int b) {
  d[++tot].a = a, d[tot].b = b, d[tot].n = h[a], h[a] = tot;
}
int dfs(int u, int num) {
  int first = 0, second = 0;
  for (int k = h[u]; k; k = d[k].n) {
    int v = d[k].b;
    int tmp = dfs(v, num);
    if (tmp > first)
      second = first, first = tmp;
    else if (tmp > second)
      second = tmp;
  }
  if (first + second + 1 >= num) {
    ans++;
    return 0;
  }
  return first + 1;
}
void dfs1(int u, int fa) {
  for (int v : g[u]) {
    if (v == fa) continue;
    charu(u, v);
    dfs1(v, u);
  }
}
int solve(int num) {
  ans = 0;
  dfs(1, num);
  return ans;
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a = read(), b = read();
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs1(1, 0);
  int p = sqrt(n * (log(n) / log(2)));
  ;
  cout << n << endl;
  for (int i = 2; i <= p; i++) {
    printf("%d\n", solve(i));
  }
  int di = solve(p), las = p;
  for (int i = di; i >= 0; i--) {
    if (solve(las + 1) != i) continue;
    int l = las + 1, r = n, mid;
    while (l < r) {
      mid = (l + r + 1) >> 1;
      if (solve(mid) == i)
        l = mid;
      else
        r = mid - 1;
    }
    for (int j = las + 1; j <= r; j++) printf("%d\n", i);
    las = r;
  }
}

```


### Prompt

Please create a solution in cpp to the following problem:

In BerSoft n programmers work, the programmer i is characterized by a skill r_i.

A programmer a can be a mentor of a programmer b if and only if the skill of the programmer a is strictly greater than the skill of the programmer b (r_a > r_b) and programmers a and b are not in a quarrel.

You are given the skills of each programmers and a list of k pairs of the programmers, which are in a quarrel (pairs are unordered). For each programmer i, find the number of programmers, for which the programmer i can be a mentor.

Input

The first line contains two integers n and k (2 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ min(2 ⋅ 10^5, (n ⋅ (n - 1))/(2))) — total number of programmers and number of pairs of programmers which are in a quarrel.

The second line contains a sequence of integers r_1, r_2, ..., r_n (1 ≤ r_i ≤ 10^{9}), where r_i equals to the skill of the i-th programmer.

Each of the following k lines contains two distinct integers x, y (1 ≤ x, y ≤ n, x ≠ y) — pair of programmers in a quarrel. The pairs are unordered, it means that if x is in a quarrel with y then y is in a quarrel with x. Guaranteed, that for each pair (x, y) there are no other pairs (x, y) and (y, x) in the input.

Output

Print n integers, the i-th number should be equal to the number of programmers, for which the i-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input.

Examples

Input

4 2
10 4 10 15
1 2
4 3

Output

0 0 1 2

Input

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

Output

5 4 0 5 3 3 9 0 2 5

Note

In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can be a mentor of the second programmer. The fourth programmer can be a mentor of the first and of the second programmers. He can not be a mentor of the third programmer, because they are in a quarrel.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 5;
vector<int> mp;
int a[MAX_N], ans[MAX_N];
int main() {
  int n, m, x, y;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    mp.push_back(a[i]);
  }
  sort(mp.begin(), mp.end());
  for (int i = 1; i <= n; i++) {
    ans[i] = lower_bound(mp.begin(), mp.end(), a[i]) - mp.begin();
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    if (a[x] > a[y]) ans[x]--;
    if (a[x] < a[y]) ans[y]--;
  }
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}

```


### Prompt

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

The letters shop showcase is a string s, consisting of n lowercase Latin letters. As the name tells, letters are sold in the shop.

Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string s.

There are m friends, the i-th of them is named t_i. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount.

  * For example, for s="arrayhead" and t_i="arya" 5 letters have to be bought ("arrayhead").
  * For example, for s="arrayhead" and t_i="harry" 6 letters have to be bought ("arrayhead").
  * For example, for s="arrayhead" and t_i="ray" 5 letters have to be bought ("arrayhead").
  * For example, for s="arrayhead" and t_i="r" 2 letters have to be bought ("arrayhead").
  * For example, for s="arrayhead" and t_i="areahydra" all 9 letters have to be bought ("arrayhead").

It is guaranteed that every friend can construct her/his name using the letters from the string s.

Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.

Input

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

The second line contains string s, consisting of exactly n lowercase Latin letters.

The third line contains one integer m (1 ≤ m ≤ 5 ⋅ 10^4) — the number of friends.

The i-th of the next m lines contains t_i (1 ≤ |t_i| ≤ 2 ⋅ 10^5) — the name of the i-th friend.

It is guaranteed that ∑ _{i=1}^m |t_i| ≤ 2 ⋅ 10^5.

Output

For each friend print the length of the shortest prefix of letters from s s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount.

It is guaranteed that every friend can construct her/his name using the letters from the string s.

Example

Input

9
arrayhead
5
arya
harry
ray
r
areahydra

Output

5
6
5
2
9

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool comp(vector<int> &k, vector<int> &kek) {
  for (int i = 0; i < 26; i++) {
    if (kek[i] < k[i]) return 0;
  }
  return 1;
}
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<int> > kek(n + 1, vector<int>(26));
  for (int i = 1; i <= n; i++) {
    kek[i] = kek[i - 1];
    kek[i][s[i - 1] - 'a']++;
  }
  int t;
  cin >> t;
  string tt;
  while (t--) {
    cin >> tt;
    vector<int> k(26);
    for (auto &i : tt) k[i - 'a']++;
    int l = 1, r = n;
    while (l < r) {
      int mid = (l + r) >> 1;
      if (comp(k, kek[mid])) {
        r = mid;
      } else
        l = mid + 1;
    }
    cout << r << '\n';
  }
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Recently Lynyrd and Skynyrd went to a shop where Lynyrd bought a permutation p of length n, and Skynyrd bought an array a of length m, consisting of integers from 1 to n.

Lynyrd and Skynyrd became bored, so they asked you q queries, each of which has the following form: "does the subsegment of a from the l-th to the r-th positions, inclusive, have a subsequence that is a cyclic shift of p?" Please answer the queries.

A permutation of length n is a sequence of n integers such that each integer from 1 to n appears exactly once in it.

A cyclic shift of a permutation (p_1, p_2, …, p_n) is a permutation (p_i, p_{i + 1}, …, p_{n}, p_1, p_2, …, p_{i - 1}) for some i from 1 to n. For example, a permutation (2, 1, 3) has three distinct cyclic shifts: (2, 1, 3), (1, 3, 2), (3, 2, 1).

A subsequence of a subsegment of array a from the l-th to the r-th positions, inclusive, is a sequence a_{i_1}, a_{i_2}, …, a_{i_k} for some i_1, i_2, …, i_k such that l ≤ i_1 < i_2 < … < i_k ≤ r.

Input

The first line contains three integers n, m, q (1 ≤ n, m, q ≤ 2 ⋅ 10^5) — the length of the permutation p, the length of the array a and the number of queries.

The next line contains n integers from 1 to n, where the i-th of them is the i-th element of the permutation. Each integer from 1 to n appears exactly once.

The next line contains m integers from 1 to n, the i-th of them is the i-th element of the array a.

The next q lines describe queries. The i-th of these lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ m), meaning that the i-th query is about the subsegment of the array from the l_i-th to the r_i-th positions, inclusive.

Output

Print a single string of length q, consisting of 0 and 1, the digit on the i-th positions should be 1, if the subsegment of array a from the l_i-th to the r_i-th positions, inclusive, contains a subsequence that is a cyclic shift of p, and 0 otherwise.

Examples

Input

3 6 3
2 1 3
1 2 3 1 2 3
1 5
2 6
3 5

Output

110

Input

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

Output

010

Note

In the first example the segment from the 1-st to the 5-th positions is 1, 2, 3, 1, 2. There is a subsequence 1, 3, 2 that is a cyclic shift of the permutation. The subsegment from the 2-nd to the 6-th positions also contains a subsequence 2, 1, 3 that is equal to the permutation. The subsegment from the 3-rd to the 5-th positions is 3, 1, 2, there is only one subsequence of length 3 (3, 1, 2), but it is not a cyclic shift of the permutation.

In the second example the possible cyclic shifts are 1, 2 and 2, 1. The subsegment from the 1-st to the 2-nd positions is 1, 1, its subsequences are not cyclic shifts of the permutation. The subsegment from the 2-nd to the 3-rd positions is 1, 2, it coincides with the permutation. The subsegment from the 3 to the 4 positions is 2, 2, its subsequences are not cyclic shifts of the permutation.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 15;
const int M = 18;
int in[N];
int lastInd[N], len[N];
int per[N], perInd[N];
int jump[N][M];
int minDist[N];
int seg[N * 4];
void init(int pos, int l, int r) {
  if (l == r) {
    seg[pos] = minDist[l];
    return;
  }
  int mid = (l + r) / 2;
  init(pos * 2, l, mid);
  init(pos * 2 + 1, mid + 1, r);
  seg[pos] = min(seg[pos * 2], seg[pos * 2 + 1]);
}
int query(int pos, int l, int r, int ql, int qr) {
  if (r < ql || qr < l) {
    return 1e9;
  }
  if (ql <= l && r <= qr) {
    return seg[pos];
  }
  int mid = (l + r) / 2;
  return min(query(pos * 2, l, mid, ql, qr),
             query(pos * 2 + 1, mid + 1, r, ql, qr));
}
void solve() {
  int n, m, q;
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &per[i]);
    perInd[per[i]] = i;
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d", &in[i]);
  }
  memset(lastInd, -1, sizeof(lastInd));
  for (int i = m; i >= 1; --i) {
    minDist[i] = 1e9;
    int curPerInd = perInd[in[i]];
    int nextInd = curPerInd + 1;
    if (nextInd > n) {
      nextInd -= n;
    }
    nextInd = lastInd[per[nextInd]];
    if (nextInd == -1) {
      len[i] = 1;
    } else {
      len[i] = min(n, len[nextInd] + 1);
      jump[i][0] = nextInd;
      for (int j = 1; j < M; ++j) {
        jump[i][j] = jump[jump[i][j - 1]][j - 1];
      }
    }
    if (len[i] == n) {
      int cur = i, d = n - 1;
      for (int j = 0; j < M; ++j) {
        if (d & (1 << j)) {
          cur = jump[cur][j];
        }
      }
      minDist[i] = cur;
    }
    lastInd[in[i]] = i;
  }
  init(1, 1, m);
  for (int i = 0; i < q; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    int q = query(1, 1, m, l, r);
    if (q <= r) {
      printf("1");
    } else {
      printf("0");
    }
  }
  cout << endl;
}
int main() { solve(); }

```


### Prompt

Generate a cpp solution to the following problem:

Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one.

Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime.

You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l ≤ a < b < c ≤ r.

More specifically, you need to find three numbers (a, b, c), such that l ≤ a < b < c ≤ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.

Input

The single line contains two positive space-separated integers l, r (1 ≤ l ≤ r ≤ 1018; r - l ≤ 50).

Output

Print three positive space-separated integers a, b, c — three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.

If the counterexample does not exist, print the single number -1.

Examples

Input

2 4

Output

2 3 4

Input

10 11

Output

-1

Input

900000000000000009 900000000000000029

Output

900000000000000009 900000000000000010 900000000000000021

Note

In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.

In the second sample you cannot form a group of three distinct integers, so the answer is -1.

In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int cp(long long a, long long b) {
  if (gcd(a, b) == 1) return 1;
  return 0;
}
int main() {
  long long l, r, t, i, j, a, b, c, n, m, k;
  cin >> l >> r;
  n = 0;
  for (i = l; i <= r; ++i) {
    for (j = i + 1; j <= r; ++j) {
      for (k = j + 1; k <= r; ++k) {
        if (cp(i, k) == 0 && cp(i, j) == 1 && cp(j, k) == 1) {
          n = 1;
          break;
        }
      }
      if (n == 1) break;
    }
    if (n == 1) break;
  }
  if (n == 1)
    cout << i << ' ' << j << ' ' << k;
  else
    cout << "-1";
  return 0;
}

```


### Prompt

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

There are an integer sequence A_1,...,A_N consisting of N terms, and N buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i terms from the first through the i-th are all incremented by 1.

There is also another integer sequence B_1,...,B_N. Takahashi will push the buttons some number of times so that for every i, A_i will be a multiple of B_i.

Find the minimum number of times Takahashi will press the buttons.

Constraints

* All input values are integers.
* 1 ≦ N ≦ 10^5
* 0 ≦ A_i ≦ 10^9(1 ≦ i ≦ N)
* 1 ≦ B_i ≦ 10^9(1 ≦ i ≦ N)

Input

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

N
A_1 B_1
:
A_N B_N

Output

Print an integer representing the minimum number of times Takahashi will press the buttons.

Examples

Input

3
3 5
2 7
9 4

Output

7

Input

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

Output

22

### Response

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

int main(){
    int N;
    cin >> N;
    long A[N], B[N];
    for(int i = 0; i < N; i++){
        cin >> A[i] >> B[i];
    }
    long plus = 0;
    for(int i = N - 1; i >= 0; i--){
        plus += B[i] - (A[i] + plus + B[i] - 1) % B[i] - 1;
    }
    cout << plus << endl;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

There are lots of theories concerning the origin of moon craters. Most scientists stick to the meteorite theory, which says that the craters were formed as a result of celestial bodies colliding with the Moon. The other version is that the craters were parts of volcanoes.

An extraterrestrial intelligence research specialist professor Okulov (the namesake of the Okulov, the author of famous textbooks on programming) put forward an alternate hypothesis. Guess what kind of a hypothesis it was –– sure, the one including extraterrestrial mind involvement. Now the professor is looking for proofs of his hypothesis.

Professor has data from the moon robot that moves linearly in one direction along the Moon surface. The moon craters are circular in form with integer-valued radii. The moon robot records only the craters whose centers lay on his path and sends to the Earth the information on the distance from the centers of the craters to the initial point of its path and on the radii of the craters.

According to the theory of professor Okulov two craters made by an extraterrestrial intelligence for the aims yet unknown either are fully enclosed one in the other or do not intersect at all. Internal or external tangency is acceptable. However the experimental data from the moon robot do not confirm this theory! Nevertheless, professor Okulov is hopeful. He perfectly understands that to create any logical theory one has to ignore some data that are wrong due to faulty measuring (or skillful disguise by the extraterrestrial intelligence that will be sooner or later found by professor Okulov!) That’s why Okulov wants to choose among the available crater descriptions the largest set that would satisfy his theory.

Input

The first line has an integer n (1 ≤ n ≤ 2000) — the number of discovered craters. The next n lines contain crater descriptions in the "ci ri" format, where ci is the coordinate of the center of the crater on the moon robot’s path, ri is the radius of the crater. All the numbers ci and ri are positive integers not exceeding 109. No two craters coincide.

Output

In the first line output the number of craters in the required largest set. In the next line output space-separated numbers of craters that this set consists of. The craters are numbered from 1 to n in the order in which they were given in the input data. The numbers may be output in any order. If the result is not unique, output any.

Examples

Input

4
1 1
2 2
4 1
5 1

Output

3
1 2 4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
const int INF = 2000000000;
struct Tpair {
  int rad, c;
  int l() { return c - rad; }
  int r() { return c + rad; }
} P[maxn];
int n;
void init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &P[i].c, &P[i].rad);
}
int ord[maxn];
int a[maxn];
vector<int> ans[maxn];
bool cmp1(int a, int b) { return P[a].rad < P[b].rad; }
bool cmp2(int a, int b) {
  return P[a].r() < P[b].r() || (P[a].r() == P[b].r() && P[a].l() > P[b].l());
}
int cur[maxn];
int f[maxn], lat[maxn], best[maxn];
void work() {
  P[0].c = 0, P[0].rad = INF;
  for (int i = 0; i <= n; i++) ord[i] = a[i] = i;
  sort(ord, ord + n + 1, cmp1);
  sort(a, a + n + 1, cmp2);
  for (int i = 0; i <= n; i++) {
    int u = ord[i], cs = 0;
    for (int j = 0; j <= n; j++)
      if (a[j] != u && P[a[j]].l() >= P[u].l() && P[a[j]].r() <= P[u].r())
        cur[cs++] = a[j];
    ans[u].push_back(u);
    if (cs) {
      for (int j = 0; j < cs; j++) {
        int v = cur[j];
        if (!j || P[cur[0]].r() > P[v].l()) {
          f[j] = ans[v].size();
          lat[j] = -1;
        } else {
          int L = 0, R = j - 1;
          while (L < R) {
            int mid = (L + R + 1) >> 1;
            if (P[cur[mid]].r() <= P[v].l())
              L = mid;
            else
              R = mid - 1;
          }
          lat[j] = L;
          f[j] = ans[v].size() + f[best[lat[j]]];
        }
        if (j && f[best[j - 1]] > f[j])
          best[j] = best[j - 1];
        else
          best[j] = j;
      }
      for (int t = cs - 1; t != -1; t = lat[t]) {
        t = best[t];
        int v = cur[t];
        for (int i = 0; i < ans[v].size(); i++) ans[u].push_back(ans[v][i]);
      }
    }
  }
}
void print() {
  printf("%d\n", ans[0].size() - 1);
  for (int i = 1; i < ans[0].size(); i++) printf("%d ", ans[0][i]);
  printf("\n");
}
int main() {
  init();
  work();
  print();
  return 0;
}

```


### Prompt

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

The DNA sequence for every living creature in Berland can be represented as a non-empty line consisting of lowercase Latin letters. Berland scientists found out that all the creatures evolve by stages. During one stage exactly one symbol of the DNA line is replaced by exactly two other ones. At that overall there are n permissible substitutions. The substitution ai->bici means that any one symbol ai can be replaced with two symbols bici. Every substitution could happen an unlimited number of times.

They say that two creatures with DNA sequences s1 and s2 can have a common ancestor if there exists such a DNA sequence s3 that throughout evolution it can result in s1 and s2, perhaps after a different number of stages. Your task is to find out by the given s1 and s2 whether the creatures possessing such DNA sequences can have a common ancestor. If the answer is positive, you have to find the length of the shortest sequence of the common ancestor’s DNA.

Input

The first line contains a non-empty DNA sequence s1, the second line contains a non-empty DNA sequence s2. The lengths of these lines do not exceed 50, the lines contain only lowercase Latin letters. The third line contains an integer n (0 ≤ n ≤ 50) — the number of permissible substitutions. Then follow n lines each of which describes a substitution in the format ai->bici. The characters ai, bi, and ci are lowercase Latin letters. Lines s1 and s2 can coincide, the list of substitutions can contain similar substitutions.

Output

If s1 and s2 cannot have a common ancestor, print -1. Otherwise print the length of the shortest sequence s3, from which s1 and s2 could have evolved.

Examples

Input

ababa
aba
2
c->ba
c->cc

Output

2

Input

ababa
aba
7
c->ba
c->cc
e->ab
z->ea
b->ba
d->dd
d->ab

Output

1

Input

ababa
aba
1
c->ba

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
map<pair<char, char>, char> hash;
char c, x, y, s1[101], s2[101];
int f[101][101];
int a[61][61], b[61][61];
vector<pair<char, char> > p[31];
int n;
int main() {
  scanf("%s%s%d", s1, s2, &n);
  int l1 = strlen(s1);
  int l2 = strlen(s2);
  for (int i = 1; i <= n; i++) {
    getchar();
    c = getchar();
    getchar();
    getchar();
    x = getchar();
    y = getchar();
    p[c - 'a'].push_back(pair<char, char>(x - 'a', y - 'a'));
  }
  for (int i = 0; i <= l1 - 1; i++) a[i + 1][i + 1] = 1 << s1[i] - 'a';
  for (int i = 0; i <= l2 - 1; i++) b[i + 1][i + 1] = 1 << s2[i] - 'a';
  for (int len = 1; len <= l1; len++)
    for (int i = 1; i <= l1 - len + 1; i++) {
      int j = i + len - 1;
      for (int k = 0; k <= 25; k++)
        for (int is = 0; is < p[k].size(); is++) {
          for (int t = i; t <= j - 1; t++)
            if ((a[i][t] & 1 << p[k][is].first) &&
                (a[t + 1][j] & 1 << p[k][is].second)) {
              a[i][j] |= 1 << k;
              break;
            }
          if (a[i][j] & 1 << k) break;
        }
    }
  for (int len = 1; len <= l2; len++)
    for (int i = 1; i <= l2 - len + 1; i++) {
      int j = i + len - 1;
      for (int k = 0; k <= 25; k++)
        for (int is = 0; is < p[k].size(); is++) {
          for (int t = i; t <= j - 1; t++)
            if ((b[i][t] & 1 << p[k][is].first) &&
                (b[t + 1][j] & 1 << p[k][is].second)) {
              b[i][j] |= 1 << k;
              break;
            }
          if (b[i][j] & 1 << k) break;
        }
    }
  memset(f, 120, sizeof(f));
  f[0][0] = 0;
  for (int i = 1; i <= l1; i++)
    for (int j = 1; j <= l2; j++)
      for (int i1 = 0; i1 <= i - 1; i1++)
        for (int j1 = 0; j1 <= j - 1; j1++)
          if ((a[i1 + 1][i] & b[j1 + 1][j]) != 0)
            f[i][j] = min(f[i][j], f[i1][j1] + 1);
  printf("%d\n", f[l1][l2] < 100 ? f[l1][l2] : -1);
  fclose(stdin);
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem.

A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for quick filling of a field part with identical enemy units. This action will look like following: a game designer will select a rectangular area on the map, and each cell whose center belongs to the selected rectangle will be filled with the enemy unit.

More formally, if a game designer selected cells having coordinates (x1, y1) and (x2, y2), where x1 ≤ x2 and y1 ≤ y2, then all cells having center coordinates (x, y) such that x1 ≤ x ≤ x2 and y1 ≤ y ≤ y2 will be filled. Orthogonal coordinates system is set up so that one of cell sides is parallel to OX axis, all hexagon centers have integer coordinates and for each integer x there are cells having center with such x coordinate and for each integer y there are cells having center with such y coordinate. It is guaranteed that difference x2 - x1 is divisible by 2.

Working on the problem Petya decided that before painting selected units he wants to output number of units that will be painted on the map.

Help him implement counting of these units before painting.

<image>

Input

The only line of input contains four integers x1, y1, x2, y2 ( - 109 ≤ x1 ≤ x2 ≤ 109, - 109 ≤ y1 ≤ y2 ≤ 109) — the coordinates of the centers of two cells.

Output

Output one integer — the number of cells to be filled.

Examples

Input

1 1 5 5

Output

13

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  cout << (x2 - x1) / 2LL * (y2 - y1 + 1) + (y2 - y1 + 2 - ((x1 ^ x2) & 1)) / 2
       << endl;
  return 0;
}

```


### Prompt

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

You are given an undirected graph where each edge has one of two colors: black or red.

Your task is to assign a real number to each node so that:

  * for each black edge the sum of values at its endpoints is 1;
  * for each red edge the sum of values at its endpoints is 2;
  * the sum of the absolute values of all assigned numbers is the smallest possible.

Otherwise, if it is not possible, report that there is no feasible assignment of the numbers.

Input

The first line contains two integers N (1 ≤ N ≤ 100 000) and M (0 ≤ M ≤ 200 000): the number of nodes and the number of edges, respectively. The nodes are numbered by consecutive integers: 1, 2, …, N.

The next M lines describe the edges. Each line contains three integers a, b and c denoting that there is an edge between nodes a and b (1 ≤ a, b ≤ N) with color c (1 denotes black, 2 denotes red).

Output

If there is a solution, the first line should contain the word "YES" and the second line should contain N space-separated numbers. For each i (1 ≤ i ≤ N), the i-th number should be the number assigned to the node i.

Output should be such that:

  * the sum of the numbers at the endpoints of each edge differs from the precise value by less than 10^{-6};
  * the sum of the absolute values of all assigned numbers differs from the smallest possible by less than 10^{-6}.

If there are several valid solutions, output any of them.

If there is no solution, the only line should contain the word "NO".

Scoring

Subtasks:

  1. (5 points) N ≤ 5, M ≤ 14
  2. (12 points) N ≤ 100
  3. (17 points) N ≤ 1000
  4. (24 points) N ≤ 10 000
  5. (42 points) No further constraints

Examples

Input

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

Output

YES
0.5 0.5 1.5 -0.5

Input

2 1
1 2 1

Output

YES
0.3 0.7

Input

3 2
1 2 2
2 3 2

Output

YES
0 2 0

Input

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

Output

NO

Note

Note that in the second example the solution is not unique.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int N, M;
  cin >> N >> M;
  vector<vector<pair<int, int>>> adj(N);
  for (int i = 0; i < M; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    u--, v--;
    adj[u].emplace_back(v, 2 * c);
    adj[v].emplace_back(u, 2 * c);
  }
  const int UNDET = 1e9;
  vector<int> ans(N, UNDET);
  vector<set<pair<int, int>>> state(N);
  vector<int> trial(N, UNDET);
  for (int i = 0; i < N; i++) {
    if (ans[i] != UNDET) {
      continue;
    }
    static queue<int> q;
    static vector<int> vis;
    q.emplace(i);
    state[i].insert({1, 0});
    while (!q.empty()) {
      int u = q.front();
      vis.emplace_back(u);
      q.pop();
      for (auto e : adj[u]) {
        int v = e.first;
        int c = e.second;
        for (auto it : state[u]) {
          if (state[v].count({-it.first, c - it.second}) == 0) {
            state[v].insert({-it.first, c - it.second});
            q.emplace(v);
          }
        }
        if (state[v].size() > 2) {
          cout << "NO\n";
          return 0;
        }
      }
    }
    int x = UNDET;
    for (auto u : vis) {
      if (state[u].size() == 1) {
        continue;
      }
      int a = begin(state[u])->first;
      int b = begin(state[u])->second;
      int c = next(begin(state[u]))->first;
      int d = next(begin(state[u]))->second;
      if (a == c && b != d) {
        cout << "NO\n";
        return 0;
      }
      x = (d - b) / (a - c);
      break;
    }
    if (x != UNDET) {
      for (auto u : vis) {
        ans[u] = begin(state[u])->first * x + begin(state[u])->second;
      }
      for (auto u : vis) {
        for (auto e : adj[u]) {
          int v = e.first;
          int c = e.second;
          if (ans[u] + ans[v] != c) {
            cout << "NO\n";
            return 0;
          }
        }
      }
    } else {
      auto FindCost = [&](int st) {
        for (auto u : vis) {
          trial[u] = UNDET;
        }
        trial[i] = st;
        long long cur = 0;
        bool can = true;
        for (auto u : vis) {
          if (!can) {
            break;
          }
          cur += max(trial[u], -trial[u]);
          for (auto e : adj[u]) {
            int v = e.first;
            int c = e.second;
            if (trial[v] == UNDET) {
              trial[v] = c - trial[u];
            }
            if (trial[u] + trial[v] != c) {
              can = false;
              break;
            }
          }
        }
        return can ? cur : UNDET;
      };
      int lo = -1e7, hi = 1e7;
      while (lo < hi) {
        int md = (lo + hi) >> 1;
        if (FindCost(md) < FindCost(md + 1)) {
          hi = md;
        } else {
          lo = md + 1;
        }
      }
      FindCost(lo);
      for (auto u : vis) {
        ans[u] = trial[u];
      }
    }
    vis.clear();
    if (ans[i] == UNDET) {
      break;
    }
  }
  if (count(begin(ans), end(ans), UNDET) > 0) {
    cout << "NO\n";
  } else {
    cout << "YES\n";
    for (int i = 0; i < N; i++) {
      cout << (double)ans[i] / 2 << " ";
    }
    cout << "\n";
  }
  return 0;
}

```


### Prompt

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

Everyone knows what the Fibonacci sequence is. This sequence can be defined by the recurrence relation:

F1 = 1, F2 = 2, Fi = Fi - 1 + Fi - 2 (i > 2).

We'll define a new number sequence Ai(k) by the formula:

Ai(k) = Fi × ik (i ≥ 1).

In this problem, your task is to calculate the following sum: A1(k) + A2(k) + ... + An(k). The answer can be very large, so print it modulo 1000000007 (109 + 7).

Input

The first line contains two space-separated integers n, k (1 ≤ n ≤ 1017; 1 ≤ k ≤ 40).

Output

Print a single integer — the sum of the first n elements of the sequence Ai(k) modulo 1000000007 (109 + 7).

Examples

Input

1 1

Output

1

Input

4 1

Output

34

Input

5 2

Output

316

Input

7 4

Output

73825

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n;
int k, C[50][50], pw[50], p1[50], p2[50];
pair<int, int> fib(long long x) {
  if (!x) return make_pair(1, 1);
  pair<int, int> ff;
  if (x % 2) {
    ff = fib((x - 1) / 2);
    return make_pair(
        (int)(1LL * ff.first * (2ll * ff.second - ff.first) % 1000000007),
        (int)(1LL * ff.first * ff.first % 1000000007 +
              1ll * ff.second * ff.second % 1000000007) %
            1000000007);
  } else {
    ff = fib((x - 2) / 2);
    return make_pair(
        (int)(1LL * ff.first * ff.first % 1000000007 +
              1ll * ff.second * ff.second % 1000000007) %
            1000000007,
        (int)(1LL * ff.second * (ff.second + 2ll * ff.first) % 1000000007));
  }
}
int calc(long long n, int k) {
  int ans[50], f2 = fib(n + 2).first, f1 = fib(n + 1).first;
  ans[0] = (f2 - 2) % 1000000007;
  for (int i = 1; i <= k; i++) {
    ans[i] = (pw[i + 1] - (1ll * p2[i] * f2) % 1000000007) % 1000000007;
    for (int j = 1; j <= i; j++) {
      ans[i] += (1ll * C[i][j] *
                 ((1ll * ans[i - j] * (pw[j] + 1)) % 1000000007 +
                  (1ll * p1[i - j] * f1) % 1000000007 - 1)) %
                1000000007;
      ans[i] %= 1000000007;
    }
    ans[i] = (-ans[i]) % 1000000007;
  }
  return (ans[k] + 1000000007) % 1000000007;
}
int main() {
  scanf("%I64d %d", &n, &k);
  for (int i = 0; i < 50; i++) C[i][0] = 1, C[i][i] = 1;
  for (int i = 1; i < 50; i++) {
    for (int j = 1; j < i; j++) {
      C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
      C[i][j] %= 1000000007;
    }
  }
  for (int i = 0; i < 50; i++) {
    if (i == 0)
      pw[0] = 1, p1[0] = 1, p2[0] = 1;
    else
      pw[i] = (2ll * pw[i - 1]) % 1000000007,
      p1[i] = (1ll * p1[i - 1] * (n % 1000000007 + 1)) % 1000000007,
      p2[i] = (1ll * p2[i - 1] * (n % 1000000007 + 2)) % 1000000007;
  }
  printf("%d\n", calc(n, k));
}

```


### Prompt

Create a solution in Cpp for the following problem:

In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges.

Input

The first input line contains one number T — amount of tests. The description of each test starts with a natural number N — amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi — amount of apples and oranges in the i-th box (0 ≤ ai, oi ≤ 109). The sum of N in all the tests in the input doesn't exceed 105. All the input numbers are integer.

Output

For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers — indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with one space.

Examples

Input

2
2
10 15
5 7
20 18
1
0 0

Output

YES
1 3
YES
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " , ";
  __f(comma + 1, args...);
}
const int N = 1e5 + 5;
const int inf = 1e9;
const long long INF = 1e18;
std::mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct data {
  long long int a, o, id;
  data() : a(0), o(0), id(0) {}
  data(long long int a, long long int o, long long int id)
      : a(a), o(o), id(0) {}
} A[2 * N];
int main(int argc, char const* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  srand(time(0));
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long long int x = 0, y = 0;
    for (int i = 1; i <= 2 * n - 1; i++) {
      cin >> A[i].a >> A[i].o;
      A[i].id = i;
      x += A[i].a, y += A[i].o;
    }
    bool f = false;
    for (int i = 1; i <= 700; i++) {
      shuffle(A + 1, A + 2 * n, rng);
      long long int cx = 0, cy = 0;
      vector<int> V;
      for (int j = 1; j <= n; j++) {
        cx += A[j].a, cy += A[j].o;
        V.push_back(A[j].id);
      }
      if (2 * cx >= x && 2 * cy >= y) {
        cout << "YES"
             << "\n";
        sort(V.begin(), V.end());
        for (auto it : V) cout << it << " ";
        cout << "\n";
        f = true;
        break;
      }
    }
    if (!f)
      cout << "NO"
           << "\n";
  }
  return 0;
}

```


### Prompt

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

In the Main Berland Bank n people stand in a queue at the cashier, everyone knows his/her height hi, and the heights of the other people in the queue. Each of them keeps in mind number ai — how many people who are taller than him/her and stand in queue in front of him.

After a while the cashier has a lunch break and the people in the queue seat on the chairs in the waiting room in a random order.

When the lunch break was over, it turned out that nobody can remember the exact order of the people in the queue, but everyone remembers his number ai.

Your task is to restore the order in which the people stood in the queue if it is possible. There may be several acceptable orders, but you need to find any of them. Also, you need to print a possible set of numbers hi — the heights of people in the queue, so that the numbers ai are correct.

Input

The first input line contains integer n — the number of people in the queue (1 ≤ n ≤ 3000). Then n lines contain descriptions of the people as "namei ai" (one description on one line), where namei is a non-empty string consisting of lowercase Latin letters whose length does not exceed 10 characters (the i-th person's name), ai is an integer (0 ≤ ai ≤ n - 1), that represents the number of people who are higher and stand in the queue in front of person i. It is guaranteed that all names are different.

Output

If there's no acceptable order of the people in the queue, print the single line containing "-1" without the quotes. Otherwise, print in n lines the people as "namei hi", where hi is the integer from 1 to 109 (inclusive), the possible height of a man whose name is namei. Print the people in the order in which they stand in the queue, starting from the head of the queue and moving to its tail. Numbers hi are not necessarily unique.

Examples

Input

4
a 0
b 2
c 0
d 0

Output

a 150
c 170
d 180
b 160

Input

4
vasya 0
petya 1
manya 3
dunay 3

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793;
const int mod = 1e9 + 7;
int CASE = 1;
const int mxn = 1e3;
const long long infll = 1e18;
const int infi = 1e9;
bool prime(long long n) {
  if (n <= 1) return false;
  if (n == 2 or n == 3) return true;
  if (n % 2 == 0 or n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i += 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long __gcd(long long a, long long b) { return !b ? a : __gcd(b, a % b); }
long long power(long long a, long long b, long long MOD) {
  long long x = a, res = 1, p = b;
  while (p > 0) {
    if (p & 1) res *= x;
    x *= x;
    p >>= 1;
    x %= MOD, res %= MOD;
  }
  return res;
}
void solve() {
  int n;
  cin >> n;
  vector<pair<string, int>> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
  sort(v.begin(), v.end(), [](pair<string, int> a, pair<string, int> b) {
    return a.second < b.second;
  });
  for (long long i = 0; i < n; i++) {
    if (v[i].second > i) {
      cout << -1;
      return;
    }
  }
  vector<pair<string, int>> ans;
  for (long long i = 0; i < n; i++) {
    pair<string, int> p = make_pair(v[i].first, 100000 - i);
    ans.insert(ans.begin() + v[i].second, p);
  }
  for (auto x : ans) cout << x.first << ' ' << x.second << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Input Format

N K
a_1 a_2 a_3 ... a_N

Output Format

Print the minimum cost in one line. In the end put a line break.

Constraints

* 1 ≤ K ≤ N ≤ 15
* 1 ≤ a_i ≤ 10^9

Scoring

Subtask 1 [120 points]

* N = K

Subtask 2 [90 points]

* N ≤ 5
* a_i ≤ 7

Subtask 3 [140 points]

* There are no additional constraints.

Output Format

Print the minimum cost in one line. In the end put a line break.

Constraints

* 1 ≤ K ≤ N ≤ 15
* 1 ≤ a_i ≤ 10^9

Scoring

Subtask 1 [120 points]

* N = K

Subtask 2 [90 points]

* N ≤ 5
* a_i ≤ 7

Subtask 3 [140 points]

* There are no additional constraints.

Input Format

N K
a_1 a_2 a_3 ... a_N

Example

Input

5 5
3949 3774 3598 3469 3424

Output

1541

### Response

```cpp
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

const ll INF = 1LL << 60;

int main() {
	int n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	ll ans = INF;
	rep(bit, (1 << n)) {
		vector<int> s;
		rep(i, n) {
			if (bit & (1 << i)) {
				s.push_back(i);
			}
		}
		if (s.size() < k) continue;
		vector<ll> t(n);
		rep(i, s.size()) {
			int u = s[i];
			rep(j, u) {
				if (a[j] + t[j] >= a[u] + t[u]) {
					t[u] = a[j] + t[j] - a[u] + 1;
				}
			}
		}
		ll mn = 0;
		rep(i, n) mn += t[i];
		ans = min(ans, mn);
	}
	cout << ans << endl;
	return 0;
}
```


### Prompt

Create a solution in Cpp for the following problem:

You are given a tree (connected graph without cycles) consisting of n vertices. The tree is unrooted — it is just a connected undirected graph without cycles.

In one move, you can choose exactly k leaves (leaf is such a vertex that is connected to only one another vertex) connected to the same vertex and remove them with edges incident to them. I.e. you choose such leaves u_1, u_2, ..., u_k that there are edges (u_1, v), (u_2, v), ..., (u_k, v) and remove these leaves and these edges.

Your task is to find the maximum number of moves you can perform if you remove leaves optimally.

You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.

The first line of the test case contains two integers n and k (2 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k < n) — the number of vertices in the tree and the number of leaves you remove in one move, respectively. The next n-1 lines describe edges. The i-th edge is represented as two integers x_i and y_i (1 ≤ x_i, y_i ≤ n), where x_i and y_i are vertices the i-th edge connects. It is guaranteed that the given set of edges forms a tree.

It is guaranteed that the sum of n does not exceed 2 ⋅ 10^5 (∑ n ≤ 2 ⋅ 10^5).

Output

For each test case, print the answer — the maximum number of moves you can perform if you remove leaves optimally.

Example

Input

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

Output

2
3
3
4

Note

The picture corresponding to the first test case of the example:

<image>

There you can remove vertices 2, 5 and 3 during the first move and vertices 1, 7 and 4 during the second move.

The picture corresponding to the second test case of the example:

<image>

There you can remove vertices 7, 8 and 9 during the first move, then vertices 5, 6 and 10 during the second move and vertices 1, 3 and 4 during the third move.

The picture corresponding to the third test case of the example:

<image>

There you can remove vertices 5 and 7 during the first move, then vertices 2 and 4 during the second move and vertices 1 and 6 during the third move.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k, ans;
vector<set<int>> g;
vector<set<int>> leaves;
struct comp {
  bool operator()(int a, int b) const {
    if (leaves[a].size() == leaves[b].size()) return a < b;
    return leaves[a].size() > leaves[b].size();
  }
};
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    g = leaves = vector<set<int>>(n);
    for (int i = 0; i < n - 1; ++i) {
      int x, y;
      cin >> x >> y;
      --x, --y;
      g[x].insert(y);
      g[y].insert(x);
    }
    for (int i = 0; i < n; ++i) {
      if (g[i].size() == 1) {
        leaves[*g[i].begin()].insert(i);
      }
    }
    set<int, comp> st;
    for (int i = 0; i < n; ++i) {
      st.insert(i);
    }
    int ans = 0;
    while (true) {
      int v = *st.begin();
      if (int(leaves[v].size()) < k) break;
      for (int i = 0; i < k; ++i) {
        int leaf = *leaves[v].begin();
        g[leaf].erase(v);
        g[v].erase(leaf);
        st.erase(v);
        st.erase(leaf);
        leaves[v].erase(leaf);
        if (leaves[leaf].count(v)) leaves[leaf].erase(v);
        if (g[v].size() == 1) {
          int to = *g[v].begin();
          st.erase(to);
          leaves[to].insert(v);
          st.insert(to);
        }
        st.insert(v);
        st.insert(leaf);
      }
      ans += 1;
    }
    cout << ans << endl;
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

N problems have been chosen by the judges, now it's time to assign scores to them!

Problem i must get an integer score A_i between 1 and N, inclusive. The problems have already been sorted by difficulty: A_1 \le A_2 \le \ldots \le A_N must hold. Different problems can have the same score, though.

Being an ICPC fan, you want contestants who solve more problems to be ranked higher. That's why, for any k (1 \le k \le N-1), you want the sum of scores of any k problems to be strictly less than the sum of scores of any k+1 problems.

How many ways to assign scores do you have? Find this number modulo the given prime M.

Constraints

* 2 \leq N \leq 5000
* 9 \times 10^8 < M < 10^9
* M is a prime.
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of ways to assign scores to the problems, modulo M.

Examples

Input

2 998244353

Output

3

Input

3 998244353

Output

7

Input

6 966666661

Output

66

Input

96 925309799

Output

83779

### Response

```cpp
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
ll ans=0,f[1000010];
int n,mod,c[1000010];
int main(){
	scanf("%d%d",&n,&mod);
	if(n&1){
		for(register int i=2,j=0;j<n/2;i++,j++)c[i]=j;
		for(register int i=n,j=1;j<=n/2;i--,j++)c[i]=j;
	}
	else{
		for(register int i=2,j=0;j<=(n-1)/2;i++,j++)c[i]=j;
		for(register int i=n,j=1;j<=(n-1)/2;i--,j++)c[i]=j;
	}
	f[0]=1;
	for(register int i=2;i<=n;i++){
		c[i]++;
		for(register int j=c[i];j<n;j++){
			f[j]=(f[j]+f[j-c[i]])%mod;
		}
	}
	//for(register int i=0;i<n;i++)cout<<"f["<<i<<"]="<<f[i]<<endl;
	for(register int i=0;i<n;i++)ans=(ans+f[i]*(n-i))%mod;
	printf("%lld",ans);
	return 0;
}
```


### Prompt

Construct a Cpp code solution to the problem outlined:

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

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

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

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

Input

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

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

Output

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

Examples

Input

4 2 17
3 1 2 5
4 2
3 4

Output

3

Input

3 2 6
3 1 1
1 2
2 3

Output

0

Input

3 2 10
1 2 3
1 2
2 1

Output

0

Note

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int max(int a, int b) { return a > b ? a : b; }
inline int min(int a, int b) { return a < b ? a : b; }
inline int gcd(int a, int b) {
  if (a % b)
    return gcd(b, a % b);
  else
    return b;
}
inline int lcm(int a, int b) { return (a * (b / gcd(a, b))); }
inline int And(int mask, int bit) { return mask & (1 << bit); }
inline int Or(int mask, int bit) { return mask | (1 << bit); }
inline int Xor(int mask, int bit) { return mask & (~(1 << bit)); }
int a[333], deg[333], mark[333];
int n, q, u, v, x, y;
bool circle;
vector<int> adj[333], topo;
long long dp[333][100111], w[333], t;
void dfs(int u) {
  if (mark[u]) return;
  mark[u] = 1;
  w[u] = a[u];
  for (int i = 0; i < adj[u].size(); i++) {
    dfs(adj[u][i]);
    w[u] += w[adj[u][i]];
  }
  topo.push_back(w[u]);
}
int main() {
  scanf("%d %d %I64d", &n, &q, &t);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    deg[i] = mark[i] = 0;
  }
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", &u, &v);
    adj[v].push_back(u);
    deg[u]++;
  }
  circle = false;
  for (int i = 1; i <= n; i++)
    if (deg[i] == 0) {
      x = topo.size();
      dfs(i);
      y = topo.size();
      for (int i = x; i < y - 1; i++) t -= topo[i];
      if (t < 0) {
        circle = true;
        break;
      }
    }
  for (int i = 1; i <= n; i++)
    if (mark[i] == 0) {
      circle = true;
      break;
    }
  if (circle)
    puts("0");
  else {
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++)
      for (int j = 0; j <= t; j++) {
        dp[i][j] = dp[i - 1][j];
        if (j >= topo[i - 1]) dp[i][j] += dp[i][j - topo[i - 1]];
        dp[i][j] %= 1000000007;
      }
    printf("%I64d\n", dp[n][t]);
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Takahashi has N days of summer vacation.

His teacher gave him M summer assignments. It will take A_i days for him to do the i-th assignment.

He cannot do multiple assignments on the same day, or hang out on a day he does an assignment.

What is the maximum number of days Takahashi can hang out during the vacation if he finishes all the assignments during this vacation?

If Takahashi cannot finish all the assignments during the vacation, print `-1` instead.

Constraints

* 1 \leq N \leq 10^6
* 1 \leq M \leq 10^4
* 1 \leq A_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N M
A_1 ... A_M

Output

Print the maximum number of days Takahashi can hang out during the vacation, or `-1`.

Examples

Input

41 2
5 6

Output

30

Input

10 2
5 6

Output

-1

Input

11 2
5 6

Output

0

Input

314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3

Output

9

### Response

```cpp
#include<iostream>
using namespace std;
int main(){
int n,m,x;
long int sum=0;
cin>>n>>m;
while(m--){
    cin>>x;
    sum+=x;
}
if(n>=sum) cout<<n-sum;
else cout<<-1;
return 0;}

```


### Prompt

Please create a solution in cpp to the following problem:

Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply this time machine to a well-known data structure: multiset.

Artem wants to create a basic multiset of integers. He wants these structure to support operations of three types:

  1. Add integer to the multiset. Note that the difference between set and multiset is that multiset may store several instances of one integer.
  2. Remove integer from the multiset. Only one instance of this integer is removed. Artem doesn't want to handle any exceptions, so he assumes that every time remove operation is called, that integer is presented in the multiset.
  3. Count the number of instances of the given integer that are stored in the multiset.

But what about time machine? Artem doesn't simply apply operations to the multiset one by one, he now travels to different moments of time and apply his operation there. Consider the following example.

  * First Artem adds integer 5 to the multiset at the 1-st moment of time.
  * Then Artem adds integer 3 to the multiset at the moment 5.
  * Then Artem asks how many 5 are there in the multiset at moment 6. The answer is 1.
  * Then Artem returns back in time and asks how many integers 3 are there in the set at moment 4. Since 3 was added only at moment 5, the number of integers 3 at moment 4 equals to 0.
  * Then Artem goes back in time again and removes 5 from the multiset at moment 3.
  * Finally Artyom asks at moment 7 how many integers 5 are there in the set. The result is 0, since we have removed 5 at the moment 3.

Note that Artem dislikes exceptions so much that he assures that after each change he makes all delete operations are applied only to element that is present in the multiset. The answer to the query of the third type is computed at the moment Artem makes the corresponding query and are not affected in any way by future changes he makes.

Help Artem implement time travellers multiset.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of Artem's queries.

Then follow n lines with queries descriptions. Each of them contains three integers ai, ti and xi (1 ≤ ai ≤ 3, 1 ≤ ti, xi ≤ 109) — type of the query, moment of time Artem travels to in order to execute this query and the value of the query itself, respectively. It's guaranteed that all moments of time are distinct and that after each operation is applied all operations of the first and second types are consistent.

Output

For each ask operation output the number of instances of integer being queried at the given moment of time.

Examples

Input

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

Output

1
2
1

Input

3
1 1 1
2 2 1
3 3 1

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
map<int, map<int, int> > bit;
void u(int t, int x) {
  while (t <= 1e9) {
    bit[t][x]++;
    t += (t & -t);
  }
}
void d(int t, int x) {
  while (t <= 1e9) {
    bit[t][x]--;
    t += t & -t;
  }
}
void cnt(int t, int x) {
  int ans = 0;
  while (t > 0) {
    ans += bit[t][x];
    t -= t & -t;
  }
  cout << ans << endl;
}
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, t, c;
    cin >> a >> t >> c;
    if (a == 1) {
      u(t, c);
    } else if (a == 2) {
      d(t, c);
    } else {
      cnt(t, c);
    }
  }
}
int main() {
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}

```


### Prompt

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

You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?

Constraints

* 1 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* Each A_i is an integer.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible number of subarrays after division of A.

Examples

Input

6
1 2 3 2 2 1

Output

2

Input

9
1 2 1 2 1 2 1 2 1

Output

5

Input

7
1 2 3 2 1 999999999 1000000000

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];
  }

  int ans = 0;
  for (int i = 0; i < N; i++){
    while (i+1 <= N && A[i] == A[i+1]) i++;

    if (A[i] > A[i+1]) {
      while (i+1 <= N && A[i] >= A[i+1]) i++;
    } else {
      while (i+1 <= N && A[i] <= A[i+1]) i++;
    }
    ans++;
  }
  cout << ans << endl;
}
```