### Prompt

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

Rebel spy Heidi has just obtained the plans for the Death Star from the Empire and, now on her way to safety, she is trying to break the encryption of the plans (of course they are encrypted – the Empire may be evil, but it is not stupid!). The encryption has several levels of security, and here is how the first one looks.

Heidi is presented with a screen that shows her a sequence of integers A and a positive integer p. She knows that the encryption code is a single number S, which is defined as follows:

Define the score of X to be the sum of the elements of X modulo p.

Heidi is given a sequence A that consists of N integers, and also given an integer p. She needs to split A into 2 parts such that:

  * Each part contains at least 1 element of A, and each part consists of contiguous elements of A.
  * The two parts do not overlap.
  * The total sum S of the scores of those two parts is maximized. This is the encryption code.

Output the sum S, which is the encryption code.

Input

The first line of the input contains two space-separated integer N and p (2 ≤ N ≤ 100 000, 2 ≤ p ≤ 10 000) – the number of elements in A, and the modulo for computing scores, respectively.

The second line contains N space-separated integers which are the elements of A. Each integer is from the interval [1, 1 000 000].

Output

Output the number S as described in the problem statement.

Examples

Input

4 10
3 4 7 2

Output

16

Input

10 12
16 3 24 13 9 8 7 5 12 12

Output

13

Note

In the first example, the score is maximized if the input sequence is split into two parts as (3, 4), (7, 2). It gives the total score of <image>.

In the second example, the score is maximized if the first part consists of the first three elements, and the second part consists of the rest. Then, the score is <image>.

### Response

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

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

One day Petya was delivered a string s, containing only digits. He needs to find a string that

  * represents a lucky number without leading zeroes,
  * is not empty,
  * is contained in s as a substring the maximum number of times.

Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.

Input

The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.

Output

In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).

Examples

Input

047

Output

4

Input

16

Output

-1

Input

472747

Output

7

Note

The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi and for any j (1 ≤ j < i) xj = yj. Here |a| denotes the length of string a.

In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".

In the second sample s has no substrings which are lucky numbers.

In the third sample the three conditions are only fulfilled for string "7".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int sz, cntr, max = 0;
  set<string> s;
  string str, tmp, ans;
  cin >> str;
  sz = str.size();
  if (count(str.begin(), str.end(), '4') + count(str.begin(), str.end(), '7') ==
      0) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < sz; i++) {
    for (int j = 1; j <= sz - i; j++) {
      tmp = str.substr(i, j);
      if (count(tmp.begin(), tmp.end(), '4') +
              count(tmp.begin(), tmp.end(), '7') ==
          j)
        s.insert(tmp);
      else
        break;
    }
  }
  for (set<string>::iterator it = s.begin(); it != s.end(); it++) {
    tmp = *it;
    cntr = 0;
    for (int i = 0; i <= (int)str.size() - tmp.size(); i++) {
      cntr += (str.substr(i, tmp.size()) == tmp);
    }
    if (cntr > max) {
      max = cntr;
      ans = tmp;
    } else if (cntr == max && tmp < ans) {
      ans = tmp;
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Compute A \times B.

Constraints

* 1 \leq A \leq 100
* 1 \leq B \leq 100
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the value A \times B as an integer.

Examples

Input

2 5

Output

10

Input

100 100

Output

10000

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y;
  cin>>x>>y;
  cout<<(x*y)<<endl;
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

A revolution took place on the Buka Island. New government replaced the old one. The new government includes n parties and each of them is entitled to some part of the island according to their contribution to the revolution. However, they can't divide the island.

The island can be conventionally represented as two rectangles a × b and c × d unit squares in size correspondingly. The rectangles are located close to each other. At that, one of the sides with the length of a and one of the sides with the length of c lie on one line. You can see this in more details on the picture.

<image>

The i-th party is entitled to a part of the island equal to xi unit squares. Every such part should fully cover several squares of the island (it is not allowed to cover the squares partially) and be a connected figure. A "connected figure" presupposes that from any square of this party one can move to any other square of the same party moving through edge-adjacent squares also belonging to that party.

Your task is to divide the island between parties.

Input

The first line contains 5 space-separated integers — a, b, c, d and n (1 ≤ a, b, c, d ≤ 50, b ≠ d, 1 ≤ n ≤ 26). The second line contains n space-separated numbers. The i-th of them is equal to number xi (1 ≤ xi ≤ a × b + c × d). It is guaranteed that <image>.

Output

If dividing the island between parties in the required manner is impossible, print "NO" (without the quotes). Otherwise, print "YES" (also without the quotes) and, starting from the next line, print max(b, d) lines each containing a + c characters. To mark what square should belong to what party, use lowercase Latin letters. For the party that is first in order in the input data, use "a", for the second one use "b" and so on. Use "." for the squares that belong to the sea. The first symbol of the second line of the output data should correspond to the square that belongs to the rectangle a × b. The last symbol of the second line should correspond to the square that belongs to the rectangle c × d.

If there are several solutions output any.

Examples

Input

3 4 2 2 3
5 8 3

Output

YES
aaabb
aabbb
cbb..
ccb..

Input

3 2 1 4 4
1 2 3 4

Output

YES
abbd
cccd
...d
...d

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:32000000")
using namespace std;
const double pi = 3.1415926535897932384626433832795;
template <class T>
inline T Sqr(const T &x) {
  return x * x;
}
template <class T>
inline T Abs(const T &x) {
  return x >= 0 ? x : -x;
}
int a, b, c, d, n, m;
int N;
char res[105][105];
int x[105];
void solve() {
  scanf("%d%d", &a, &b);
  scanf("%d%d", &c, &d);
  scanf("%d", &N);
  n = max(b, d);
  m = a + c;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) res[i][j] = '.';
  vector<pair<int, int> > pt;
  bool inv = a % 2 == 1;
  for (int i = 0; i < m; i++) {
    int h = i < a ? b : d;
    for (int j = 0; j < h; j++) pt.push_back(make_pair(inv ? h - j - 1 : j, i));
    inv = !inv;
  }
  int t = 0;
  for (int i = 0; i < N; i++) scanf("%d", &x[i]);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < x[i]; j++) {
      res[pt[t].first][pt[t].second] = 'a' + i;
      t++;
    }
  printf("YES\n");
  for (int i = 0; i < n; i++) printf("%s\n", res[i]);
}
int main() {
  solve();
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

A thief sneaked into a museum with a lot of treasures with only one large furoshiki. There are many things I want to steal, but the weight that the furoshiki can withstand is limited, and if it exceeds this, the furoshiki will tear. Therefore, the thief must consider a combination of treasures that will not break the prepared furoshiki and will be the most valuable.

The weight W that the bath room can withstand, and the value and weight of each treasure in the museum are read, and the total value of the treasure is the maximum when the total value does not exceed W. Create a program that outputs the total weight. However, if there are multiple combinations that maximize the sum of values, the one with the smallest sum of weights will be output.

Input

Given multiple datasets. Each dataset is given in the following format:

W
N
v1, w1
v2, w2
::
vN, wN

The first line gives the integer W (W ≤ 1,000), which represents the weight that the furoshiki can bear, and the second line gives the number of treasures N (1 ≤ N ≤ 1,000). The next N lines are given a set of the integer vi (0 ≤ vi ≤ 10,000) representing the value of the i-th treasure and the integer wi (0 ≤ wi ≤ W) representing its weight.

When W is 0, it is the last input. The number of datasets does not exceed 50.

Output

Output as follows for each data set.

Case dataset number:
Sum of the value of the treasure in the furoshiki
Sum of the weight of the treasure at that time

Example

Input

50
5
60,10
100,20
120,30
210,45
10,4
50
5
60,10
100,20
120,30
210,45
10,4
0

Output

Case 1:
220
49
Case 2:
220
49

### Response

```cpp
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void)
{
	int c = 1, W;

	while(cin >> W, W) {
		int n, mx = 0, w[1000], d[1000];
		long dp[1001] = {0};
		cin >> n;
		for(int i = 0; i < n; i++)
			scanf("%d,%d", &d[i], &w[i]);
		for(int i = 1; i <= W; i++)
			dp[i] = -1;

		for(int i = 0; i < n; i++) {
			for(int j = W - w[i]; j >= 0; j--) {
				if(dp[j] >= 0 && j + w[i] <= W) {
					dp[j + w[i]] = ((dp[j + w[i]] > dp[j] + d[i]) ? dp[j + w[i]] : (dp[j] + d[i]));
				}
			}
		}

		for(int i = 0; i <= W; i++)
			if(dp[i] > dp[mx]) mx = i;

		cout << "Case " << c++ << ":" << endl;
		cout << dp[mx] << endl;
		cout << mx << endl;
	}

	return 0;
}
```


### Prompt

Create a solution in cpp for the following problem:

A game is played on a strip consisting of N cells consecutively numbered from 1 to N.

Alice has her token on cell A. Borys has his token on a different cell B.

Players take turns, Alice moves first. The moving player must shift his or her token from its current cell X to the neighboring cell on the left, cell X-1, or on the right, cell X+1. Note that it's disallowed to move the token outside the strip or to the cell with the other player's token. In one turn, the token of the moving player must be shifted exactly once.

The player who can't make a move loses, and the other player wins.

Both players want to win. Who wins if they play optimally?

Constraints

* 2 \leq N \leq 100
* 1 \leq A < B \leq N
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print `Alice` if Alice wins, `Borys` if Borys wins, and `Draw` if nobody wins.

Examples

Input

5 2 4

Output

Alice

Input

2 1 2

Output

Borys

Input

58 23 42

Output

Borys

### Response

```cpp
#include <iostream>
using namespace std;
int main()
{
	int n,a,b;
	while(cin>>n>>a>>b){
		int m=b-a-1;
		cout<<(m%2==0?"Borys":"Alice")<<endl;
	}
	return 0;
}
```


### Prompt

Generate a CPP solution to the following problem:

Sasha grew up and went to first grade. To celebrate this event her mother bought her a multiplication table M with n rows and n columns such that M_{ij}=a_i ⋅ a_j where a_1, ..., a_n is some sequence of positive integers.

Of course, the girl decided to take it to school with her. But while she was having lunch, hooligan Grisha erased numbers on the main diagonal and threw away the array a_1, ..., a_n. Help Sasha restore the array!

Input

The first line contains a single integer n (3 ⩽ n ⩽ 10^3), the size of the table.

The next n lines contain n integers each. The j-th number of the i-th line contains the number M_{ij} (1 ≤ M_{ij} ≤ 10^9). The table has zeroes on the main diagonal, that is, M_{ii}=0.

Output

In a single line print n integers, the original array a_1, ..., a_n (1 ≤ a_i ≤ 10^9). It is guaranteed that an answer exists. If there are multiple answers, print any.

Examples

Input

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

Output

2 2 3 1 2

Input

3
0 99990000 99970002
99990000 0 99980000
99970002 99980000 0

Output

9999 10000 9998

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &item) {
  out << '(' << item.first << ", " << item.second << ')';
  return out;
}
const int N = 1010;
int a[N][N];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) cin >> a[i][j];
  for (int i = 1; i <= n; ++i) {
    int j = (i + 1 > n ? 1 : i + 1);
    int k = (j + 1 > n ? 1 : j + 1);
    cout << int(round(sqrt(1LL * a[i][j] * a[i][k] / a[j][k]))) << ' ';
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

You are given an array a, consisting of n integers.

Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the unlocked positions. You are not allowed to remove any values, add the new ones or rearrange the values on the locked positions. You are allowed to leave the values in the same order as they were.

For example, let a = [-1, 1, \underline{3}, 2, \underline{-2}, 1, -4, \underline{0}], the underlined positions are locked. You can obtain the following arrays:

  * [-1, 1, \underline{3}, 2, \underline{-2}, 1, -4, \underline{0}];
  * [-4, -1, \underline{3}, 2, \underline{-2}, 1, 1, \underline{0}];
  * [1, -1, \underline{3}, 2, \underline{-2}, 1, -4, \underline{0}];
  * [1, 2, \underline{3}, -1, \underline{-2}, -4, 1, \underline{0}];
  * and some others.

Let p be a sequence of prefix sums of the array a after the rearrangement. So p_1 = a_1, p_2 = a_1 + a_2, p_3 = a_1 + a_2 + a_3, ..., p_n = a_1 + a_2 + ... + a_n.

Let k be the maximum j (1 ≤ j ≤ n) such that p_j < 0. If there are no j such that p_j < 0, then k = 0.

Your goal is to rearrange the values in such a way that k is minimum possible.

Output the array a after the rearrangement such that the value k for it is minimum possible. If there are multiple answers then print any of them.

Input

The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases.

Then t testcases follow.

The first line of each testcase contains a single integer n (1 ≤ n ≤ 100) — the number of elements in the array a.

The second line of each testcase contains n integers a_1, a_2, ..., a_n (-10^5 ≤ a_i ≤ 10^5) — the initial array a.

The third line of each testcase contains n integers l_1, l_2, ..., l_n (0 ≤ l_i ≤ 1), where l_i = 0 means that the position i is unlocked and l_i = 1 means that the position i is locked.

Output

Print n integers — the array a after the rearrangement. Value k (the maximum j such that p_j < 0 (or 0 if there are no such j)) should be minimum possible. For each locked position the printed value should be equal to the initial one. The values on the unlocked positions should be an arrangement of the initial ones.

If there are multiple answers then print any of them.

Example

Input

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

Output

1 2 3
2 -3 4 -1
-8 -6 1 4 4 7 -2
-4 0 1 6 3
-1 4 7 -8 10 -1

Note

In the first testcase you can rearrange all values however you want but any arrangement will result in k = 0. For example, for an arrangement [1, 2, 3], p=[1, 3, 6], so there are no j such that p_j < 0. Thus, k = 0.

In the second testcase you are not allowed to rearrange any elements. Thus, the printed array should be exactly the same as the initial one.

In the third testcase the prefix sums for the printed array are p = [-8, -14, -13, -9, -5, 2, 0]. The maximum j is 5, thus k = 5. There are no arrangements such that k < 5.

In the fourth testcase p = [-4, -4, -3, 3, 6].

In the fifth testcase p = [-1, 3, 10, 2, 12, 11].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    bool ind[n];
    for (int i = 0; i < n; i++) {
      cin >> ind[i];
    }
    vector<int> v;
    for (int i = 0; i < n; i++) {
      if (!ind[i]) {
        v.push_back(arr[i]);
      }
    }
    sort(v.begin(), v.end());
    int ei = v.size() - 1;
    for (int i = 0; i < n; i++) {
      if (!ind[i]) {
        arr[i] = v[ei];
        ei--;
      }
      cout << arr[i] << " ";
    }
    cout << endl;
  }
}

```


### Prompt

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

The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s.

Igor is at the point x1. He should reach the point x2. Igor passes 1 meter per t2 seconds.

Your task is to determine the minimum time Igor needs to get from the point x1 to the point x2, if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1.

Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 1 meter per t2 seconds). He can also stand at some point for some time.

Input

The first line contains three integers s, x1 and x2 (2 ≤ s ≤ 1000, 0 ≤ x1, x2 ≤ s, x1 ≠ x2) — the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.

The second line contains two integers t1 and t2 (1 ≤ t1, t2 ≤ 1000) — the time in seconds in which the tram passes 1 meter and the time in seconds in which Igor passes 1 meter.

The third line contains two integers p and d (1 ≤ p ≤ s - 1, d is either 1 or <image>) — the position of the tram in the moment Igor came to the point x1 and the direction of the tram at this moment. If <image>, the tram goes in the direction from the point s to the point 0. If d = 1, the tram goes in the direction from the point 0 to the point s.

Output

Print the minimum time in seconds which Igor needs to get from the point x1 to the point x2.

Examples

Input

4 2 4
3 4
1 1

Output

8

Input

5 4 0
1 2
3 1

Output

7

Note

In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 2 meters and it takes 8 seconds in total, because he passes 1 meter per 4 seconds.

In the second example Igor can, for example, go towards the point x2 and get to the point 1 in 6 seconds (because he has to pass 3 meters, but he passes 1 meters per 2 seconds). At that moment the tram will be at the point 1, so Igor can enter the tram and pass 1 meter in 1 second. Thus, Igor will reach the point x2 in 7 seconds in total.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int p, d, s, x1, x2, t1, t2, ans = INT_MAX;
  cin >> s >> x1 >> x2;
  cin >> t1 >> t2;
  cin >> p >> d;
  if (t1 >= t2) {
    printf("%d", (abs(x1 - x2) * t2));
    return 0;
  }
  ans = (abs(x1 - x2) * t2);
  int onbus = 0, ans2 = 0;
  while (1) {
    if (p == x1) {
      onbus = 1;
    }
    ans2 += t1;
    p += d;
    if (p < 0) {
      d = -d;
      p = 1;
    } else if (p > s) {
      p = s - 1;
      d = -d;
    }
    if (onbus && p == x2) {
      break;
    }
  }
  printf("%d", min(ans, ans2));
  return 0;
}

```


### Prompt

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

One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other.

Help Timofey to color his rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color, or determine that it is impossible.

Two rectangles intersect if their intersection has positive area. Two rectangles touch by sides if there is a pair of sides such that their intersection has non-zero length

<image> The picture corresponds to the first example

Input

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

n lines follow. The i-th of these lines contains four integers x1, y1, x2 and y2 ( - 109 ≤ x1 < x2 ≤ 109,  - 109 ≤ y1 < y2 ≤ 109), that means that points (x1, y1) and (x2, y2) are the coordinates of two opposite corners of the i-th rectangle.

It is guaranteed, that all sides of the rectangles have odd lengths and rectangles don't intersect each other.

Output

Print "NO" in the only line if it is impossible to color the rectangles in 4 different colors in such a way that every two rectangles touching each other by side would have different color.

Otherwise, print "YES" in the first line. Then print n lines, in the i-th of them print single integer ci (1 ≤ ci ≤ 4) — the color of i-th rectangle.

Example

Input

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

Output

YES
1
2
2
3
2
2
4
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x1, y1, x2, y2;
  scanf("%d", &n);
  puts("YES");
  while (n--) {
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    x1 = abs(x1);
    y1 = abs(y1);
    if (x1 % 2 == 1 && y1 % 2 == 1)
      puts("1");
    else if (x1 % 2 == 0 && y1 % 2 == 1)
      puts("2");
    else if (x1 % 2 == 1 && y1 % 2 == 0)
      puts("3");
    else
      puts("4");
  }
  return 0;
}

```


### Prompt

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

The only difference between easy and hard versions is constraints.

A session has begun at Beland State University. Many students are taking exams.

Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:

  * The i-th student randomly chooses a ticket.
  * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
  * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.

Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.

The duration of the whole exam for all students is M minutes (max t_i ≤ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.

For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.

For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.

Input

The first line of the input contains two integers n and M (1 ≤ n ≤ 100, 1 ≤ M ≤ 100) — the number of students and the total duration of the exam in minutes, respectively.

The second line of the input contains n integers t_i (1 ≤ t_i ≤ 100) — time in minutes that i-th student spends to answer to a ticket.

It's guaranteed that all values of t_i are not greater than M.

Output

Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.

Examples

Input

7 15
1 2 3 4 5 6 7

Output

0 0 0 0 0 2 3

Input

5 100
80 40 40 40 60

Output

0 1 1 2 3

Note

The explanation for the example 1.

Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.

In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).

In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, j = 0;
  cin >> n >> m;
  int sum = 0, arr[n], stu[n];
  for (int i = 0; i < n; i++) {
    int count = 0;
    cin >> arr[i];
    sum = sum + arr[i];
    stu[i] = arr[i];
    if (sum <= m) {
      cout << count << " ";
    } else {
      sort(stu, stu + i);
      j = i - 1;
      int sum1 = sum;
      while (sum1 > m) {
        sum1 = sum1 - stu[j];
        j--;
        count++;
      }
      j = i;
      cout << count << " ";
    }
  }
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

You have an array of positive integers a[1], a[2], ..., a[n] and a set of bad prime numbers b1, b2, ..., bm. The prime numbers that do not occur in the set b are considered good. The beauty of array a is the sum <image>, where function f(s) is determined as follows:

  * f(1) = 0;
  * Let's assume that p is the minimum prime divisor of s. If p is a good prime, then <image>, otherwise <image>.

You are allowed to perform an arbitrary (probably zero) number of operations to improve array a. The operation of improvement is the following sequence of actions:

  * Choose some number r (1 ≤ r ≤ n) and calculate the value g = GCD(a[1], a[2], ..., a[r]).
  * Apply the assignments: <image>, <image>, ..., <image>.

What is the maximum beauty of the array you can get?

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 5000) showing how many numbers are in the array and how many bad prime numbers there are.

The second line contains n space-separated integers a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109) — array a. The third line contains m space-separated integers b1, b2, ..., bm (2 ≤ b1 < b2 < ... < bm ≤ 109) — the set of bad prime numbers.

Output

Print a single integer — the answer to the problem.

Examples

Input

5 2
4 20 34 10 10
2 5

Output

-2

Input

4 5
2 4 8 16
3 5 7 11 17

Output

10

Note

Note that the answer to the problem can be negative.

The GCD(x1, x2, ..., xk) is the maximum positive integer that divides each xi.

### Response

```cpp
#include <bits/stdc++.h>
int dpg[5005], num[5005], dive[5005], prime[5005], n, m;
int gcd(int a, int b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a > b ? b : a; }
int judge(int x) {
  int i, j, sum;
  sum = 0;
  for (i = 1; i <= m; i++) {
    if (x % prime[i] == 0) {
      while (x % prime[i] == 0) {
        x /= prime[i];
        sum--;
      }
    }
  }
  for (i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      while (x % i == 0) {
        x /= i;
        sum++;
      }
    }
  }
  if (x > 1) {
    sum++;
  }
  return sum;
}
int main() {
  int i, j, k, l, add, re;
  while (scanf("%d%d", &n, &m) != EOF) {
    for (i = 1; i <= n; i++) {
      scanf("%d", &num[i]);
      if (i == 1)
        dpg[i] = num[i];
      else
        dpg[i] = gcd(max(dpg[i - 1], num[i]), min(dpg[i - 1], num[i]));
    }
    for (i = 1; i <= m; i++) scanf("%d", &prime[i]);
    dive[n + 1] = 1;
    add = 0;
    for (i = 1, re = 0; i <= n; i++) re += judge(num[i]);
    for (i = n; i > 0; i--) {
      if (judge(dpg[i] / dive[i + 1]) < 0) {
        dive[i] = dpg[i];
        add -= (judge(dpg[i]));
      } else {
        dive[i] = dive[i + 1];
        add -= (judge(dive[i + 1]));
      }
    }
    printf("%d\n", re + add);
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Problem

Neat lives on the world line for a total of 360 days until the 30th of every month for 1 year and 12 months. In that world, N consecutive holidays with the same schedule were applied to people all over the world every year. Consecutive holidays i are consecutive Vi days starting from Mi month Di day.

NEET is NEET, so he is closed every day regardless of consecutive holidays. One day NEET decided to go out unusually, but I hate crowds, so I don't want to go out as much as possible on busy days due to the effects of consecutive holidays. Therefore, Neat is trying to find the day with the least congestion by calculating the congestion degree of each day by the following method.

* The number that represents the degree of influence of a date x by the holiday i is Si if the date x is included in the holiday i, otherwise max (0, Si − min (from x). The number of days until the first day of consecutive holidays i, the number of days from the last day of consecutive holidays i to x)))
* The degree of congestion on a certain date x is the degree of influence that is most affected by N consecutive holidays.

Please output the lowest degree of congestion in the year. However, consecutive holidays i may span years. In addition, the dates of consecutive holidays may overlap.

Constraints

The input satisfies the following conditions.

* 1 ≤ N ≤ 100
* 1 ≤ Mi ≤ 12
* 1 ≤ Di ≤ 30
* 1 ≤ Vi, Si ≤ 360

Input

The input is given in the following format.

N
M1 D1 V1 S1
M2 D2 V2 S2
...
MN DN VN SN

The integer N is given on the first line.
The integers Mi, Di, Vi, Si are given on the 2nd to N + 1th lines separated by blanks. (1 ≤ i ≤ N)

Output

Outputs the least congestion level on one line.

Examples

Input

1
1 1 359 1

Output

0

Input

2
2 4 25 306
1 9 7 321

Output

158

Input

8
2 9 297 297
8 6 359 211
8 16 28 288
7 9 113 143
3 18 315 190
10 18 277 300
9 5 276 88
3 5 322 40

Output

297

### Response

```cpp
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI crowd(360);
  REP(diesirae, 0, n) {
    int m, d, v, s;
    cin >> m >> d >> v >> s;
    int dat = 30 * (m - 1) + d - 1;
    VI eff(360, 0);
    REP(i, 0, v) {
      eff[(dat + i) % 360] = s;
    }
    REP(i, 0, s) {
      int &r = eff[(dat - i + 360 + 359) % 360];
      r = max(r, s - i - 1);
    }
    REP(i, 0, s) {
      int &r = eff[(dat + v + i + 360) % 360];
      r = max(r, s - i - 1);
    }
    REP(i, 0, 360) {
      crowd[i] = max(crowd[i], eff[i]);
    }
  }
  int mi = 10000;
  REP(i, 0, 360) {
    mi = min(mi, crowd[i]);
  }
  cout << mi << endl;
}
```


### Prompt

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

An agent called Cypher is decrypting a message, that contains a [composite number](https://en.wikipedia.org/wiki/Composite_number) n. All divisors of n, which are greater than 1, are placed in a circle. Cypher can choose the initial order of numbers in the circle.

In one move Cypher can choose two adjacent numbers in a circle and insert their [least common multiple](https://en.wikipedia.org/wiki/Least_common_multiple) between them. He can do that move as many times as needed.

A message is decrypted, if every two adjacent numbers are not coprime. Note that for such constraints it's always possible to decrypt the message.

Find the minimal number of moves that Cypher should do to decrypt the message, and show the initial order of numbers in the circle for that.

Input

The first line contains an integer t (1 ≤ t ≤ 100) — the number of test cases. Next t lines describe each test case.

In a single line of each test case description, there is a single composite number n (4 ≤ n ≤ 10^9) — the number from the message.

It's guaranteed that the total number of divisors of n for all test cases does not exceed 2 ⋅ 10^5.

Output

For each test case in the first line output the initial order of divisors, which are greater than 1, in the circle. In the second line output, the minimal number of moves needed to decrypt the message.

If there are different possible orders with a correct answer, print any of them.

Example

Input

3
6
4
30

Output

2 3 6
1
2 4
0
2 30 6 3 15 5 10
0

Note

In the first test case 6 has three divisors, which are greater than 1: 2, 3, 6. Regardless of the initial order, numbers 2 and 3 are adjacent, so it's needed to place their least common multiple between them. After that the circle becomes 2, 6, 3, 6, and every two adjacent numbers are not coprime.

In the second test case 4 has two divisors greater than 1: 2, 4, and they are not coprime, so any initial order is correct, and it's not needed to place any least common multiples.

In the third test case all divisors of 30 greater than 1 can be placed in some order so that there are no two adjacent numbers that are coprime.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int solve();
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cout << solve() << endl;
  }
}
int print_divisors(vector<pair<int, int>> pf, int cur, int curDivisor, int skip,
                   int n) {
  if (cur == pf.size()) {
    if (curDivisor != n) {
      cout << curDivisor << " ";
      return 1;
    }
    return 0;
  }
  if (cur == skip) {
    return print_divisors(pf, cur + 1, curDivisor, skip, n);
  }
  int ret = 0;
  for (int i = 0; i <= pf[cur].second; ++i) {
    ret += print_divisors(pf, cur + 1, curDivisor, skip, n);
    curDivisor *= pf[cur].first;
  }
  return ret;
}
int solve() {
  int n;
  cin >> n;
  vector<pair<int, int>> pf;
  int p = 2;
  int n0 = n;
  while (p <= sqrt(n)) {
    int f = 0;
    while (n0 % p == 0) {
      n0 /= p;
      f++;
    }
    if (f > 0) {
      pf.push_back(pair<int, int>(p, f));
    }
    p++;
  }
  if (n0 > 1) {
    pf.push_back(pair<int, int>(n0, 1));
  }
  if (pf.size() == 1) {
    long long cur = pf[0].first;
    for (int i = 0; i < pf[0].second; i++) {
      cout << cur << " ";
      cur *= pf[0].first;
    }
    cout << endl;
    return 0;
  }
  int ret = 0;
  for (int i = 0; i < pf.size(); i++) {
    pf[i].second -= 1;
    print_divisors(pf, i, pf[i].first, i + 1, n);
    pf[i].second += 1;
    if (i != pf.size() - 1) {
      pf[i].second--;
      pf[i + 1].second--;
      int num =
          print_divisors(pf, i, pf[i].first * pf[i + 1].first, pf.size(), n);
      pf[i].second++;
      pf[i + 1].second++;
      if (num == 0) {
        ret++;
      }
    }
  }
  cout << n << endl;
  return ret;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout at the cell of gym in the i-th line and the j-th column.

Iahub starts with workout located at line 1 and column 1. He needs to finish with workout a[n][m]. After finishing workout a[i][j], he can go to workout a[i + 1][j] or a[i][j + 1]. Similarly, Iahubina starts with workout a[n][1] and she needs to finish with workout a[1][m]. After finishing workout from cell a[i][j], she goes to either a[i][j + 1] or a[i - 1][j].

There is one additional condition for their training. They have to meet in exactly one cell of gym. At that cell, none of them will work out. They will talk about fast exponentiation (pretty odd small talk) and then both of them will move to the next workout.

If a workout was done by either Iahub or Iahubina, it counts as total gain. Please plan a workout for Iahub and Iahubina such as total gain to be as big as possible. Note, that Iahub and Iahubina can perform workouts with different speed, so the number of cells that they use to reach meet cell may differs.

Input

The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000). Each of the next n lines contains m integers: j-th number from i-th line denotes element a[i][j] (0 ≤ a[i][j] ≤ 105).

Output

The output contains a single number — the maximum total gain possible.

Examples

Input

3 3
100 100 100
100 1 100
100 100 100

Output

800

Note

Iahub will choose exercises a[1][1] → a[1][2] → a[2][2] → a[3][2] → a[3][3]. Iahubina will choose exercises a[3][1] → a[2][1] → a[2][2] → a[2][3] → a[1][3].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a, b, c;
long long uu[1003][1003];
long long ru[1003][1003];
long long rr[1003][1003];
long long ur[1003][1003];
long long m[1003][1003];
int main() {
  cin >> a >> b;
  for (int i = 1; i <= a; ++i)
    for (int q = 1; q <= b; ++q) cin >> m[i][q];
  for (int i = 1; i <= a; ++i)
    for (int q = 1; q <= b; ++q)
      uu[i][q] = max(uu[i - 1][q], uu[i][q - 1]) + m[i][q];
  for (int i = a; i >= 1; --i)
    for (int q = 1; q <= b; ++q)
      ru[i][q] = max(ru[i + 1][q], ru[i][q - 1]) + m[i][q];
  for (int i = 1; i <= a; ++i)
    for (int q = b; q >= 1; --q)
      ur[i][q] = max(ur[i - 1][q], ur[i][q + 1]) + m[i][q];
  for (int i = a; i >= 1; --i)
    for (int q = b; q >= 1; --q)
      rr[i][q] = max(rr[i + 1][q], rr[i][q + 1]) + m[i][q];
  long long max_ = -1;
  for (int i = 2; i < a; ++i)
    for (int q = 2; q < b; ++q) {
      long long tmp = uu[i - 1][q] + rr[i + 1][q] + ur[i][q + 1] + ru[i][q - 1];
      max_ = max(max_, tmp);
      tmp = uu[i][q - 1] + rr[i][q + 1] + ur[i - 1][q] + ru[i + 1][q];
      max_ = max(max_, tmp);
    }
  cout << max_;
  return 0;
}

```


### Prompt

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

problem

Hanako is playing with n (4 ≤ n ≤ 10) cards side by side. Each card has one integer between 1 and 99. Hanako chose k cards (2 ≤ k ≤ 4) from these cards and arranged them in a horizontal row to make an integer. How many kinds of integers can Hanako make in total?

For example, consider that you are given five cards of 1, 2, 3, 13, 21 and choose three of them to make an integer. By arranging 2, 1, and 13 in this order, we can make an integer 2113. Also, by arranging 21, 1, and 3 in this order, the same integer 2113 can be created. In this way, the same integer may be created from a combination of different cards.

Given the integers written on n cards, create a program to find the number of integers that can be created by selecting k cards from them and arranging them in a horizontal row.

input

The input consists of multiple datasets. Each dataset is given in the following format.

Each dataset consists of 2 + n rows. The number of cards n (4 ≤ n ≤ 10) is written on the first line, and the number of cards to be selected k (2 ≤ k ≤ 4) is written on the second line. On the 2 + i line (1 ≤ i ≤ n), the integer from 1 to 99 written on the i-th card is written.

When both n and k are 0, it indicates the end of input. The number of data sets does not exceed 5.

output

For each data set, the number of integers that Hanako can create is output on one line.

Examples

Input

4
2
1
2
12
1
6
3
72
2
12
7
2
1
0
0

Output

7
68

Input

None

Output

None

### Response

```cpp
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
using namespace std;

int n,k;
string a[11];
char t[5];
set<string> ss;
string s;

int main()
{
	while(scanf(" %d%d",&n,&k),n|k){
		ss.clear();
		for(int i = 0; i < n; ++i){
			scanf(" %s ",t);
			a[i] = t;
		}
		sort(a,a+n);
		do{
			s.clear();
			for (int i = 0; i < k; ++i){
				s += a[i];
			}
			ss.insert(s);
		}while(next_permutation(a,a+n));
		printf("%d\n",(int)ss.size());
	}
}
```


### Prompt

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

A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski junctions, numbered from 1 to n. Initially the junctions aren't connected in any way.

In the constructing process m bidirectional ski roads will be built. The roads are built one after another: first the road number 1 will be built, then the road number 2, and so on. The i-th road connects the junctions with numbers ai and bi.

Track is the route with the following properties:

  * The route is closed, that is, it begins and ends in one and the same junction.
  * The route contains at least one road.
  * The route doesn't go on one road more than once, however it can visit any junction any number of times.

Let's consider the ski base as a non-empty set of roads that can be divided into one or more tracks so that exactly one track went along each road of the chosen set. Besides, each track can consist only of roads from the chosen set. Ski base doesn't have to be connected.

Two ski bases are considered different if they consist of different road sets.

After building each new road the Walrusland government wants to know the number of variants of choosing a ski base based on some subset of the already built roads. The government asks you to help them solve the given problem.

Input

The first line contains two integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105). They represent the number of junctions and the number of roads correspondingly. Then on m lines follows the description of the roads in the order in which they were built. Each road is described by a pair of integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the numbers of the connected junctions. There could be more than one road between a pair of junctions.

Output

Print m lines: the i-th line should represent the number of ways to build a ski base after the end of construction of the road number i. The numbers should be printed modulo 1000000009 (109 + 9).

Examples

Input

3 4
1 3
2 3
1 2
1 2

Output

0
0
1
3

Note

Let us have 3 junctions and 4 roads between the junctions have already been built (as after building all the roads in the sample): 1 and 3, 2 and 3, 2 roads between junctions 1 and 2. The land lot for the construction will look like this:

<image>

The land lot for the construction will look in the following way:

<image>

We can choose a subset of roads in three ways:

<image>

In the first and the second ways you can choose one path, for example, 1 - 2 - 3 - 1. In the first case you can choose one path 1 - 2 - 1.

### Response

```cpp
#include <bits/stdc++.h>
int father[100010];
void makeSet() {
  for (int i = 0; i < 100010; i++) father[i] = i;
}
int findSet(int x) {
  if (x != father[x]) father[x] = findSet(father[x]);
  return father[x];
}
int main() {
  int n, m;
  int x, y;
  long long ans;
  while (~scanf("%d%d", &n, &m)) {
    makeSet();
    ans = 0;
    while (m--) {
      scanf("%d%d", &x, &y);
      x = findSet(x);
      y = findSet(y);
      if (x == y)
        ans += ans + 1;
      else
        father[x] = y;
      if (ans >= 1000000009) ans -= 1000000009;
      printf("%I64d\n", ans);
    }
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

We have N weights indexed 1 to N. The mass of the weight indexed i is W_i.

We will divide these weights into two groups: the weights with indices not greater than T, and those with indices greater than T, for some integer 1 \leq T < N. Let S_1 be the sum of the masses of the weights in the former group, and S_2 be the sum of the masses of the weights in the latter group.

Consider all possible such divisions and find the minimum possible absolute difference of S_1 and S_2.

Constraints

* 2 \leq N \leq 100
* 1 \leq W_i \leq 100
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
W_1 W_2 ... W_{N-1} W_N

Output

Print the minimum possible absolute difference of S_1 and S_2.

Examples

Input

3
1 2 3

Output

0

Input

4
1 3 1 1

Output

2

Input

8
27 23 76 2 3 5 62 52

Output

2

### Response

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

using namespace std;

int n,ans = 99999999;
int f[105],sum[105];

int main(){
	cin >> n;
	for(int i = 1; i <= n; ++i){
		int a;cin >> a;
		sum[i] = sum[i - 1] + a;
	}
	for(int i = 1; i <= n; ++i)
		ans = min(ans,abs(sum[i] - (sum[n] - sum[i])));
	cout << ans << endl;
	return 0;
}
```


### Prompt

Create a solution in CPP for the following problem:

The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.

He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.

To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.

How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.

Constraints

* 1 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9(1\leq i\leq N)
* 1 \leq B_i \leq 10^9(1\leq i\leq N)
* 1 \leq C_i \leq 10^9(1\leq i\leq N)
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N

Output

Print the number of different altars that Ringo can build.

Examples

Input

2
1 5
2 4
3 6

Output

3

Input

3
1 1 1
2 2 2
3 3 3

Output

27

Input

6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288

Output

87

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	long long n, arr[2][100001], cnt = 0, dp[2][100001], pre;
	bool f = 0;
	cin >> n;
	for(int i=0; i<n; i++) cin >> arr[!f][i];
	sort(arr[!f], arr[!f] + n);
	fill(dp[!f], dp[!f] + n, 1);
	for(int k=0; k<2; k++){
		for(int i=0; i<n; i++) cin >> arr[f][i];
		sort(arr[f], arr[f] + n);
		cnt = pre = 0;
		for(int i=0; i<n; i++){
			while(cnt < n && arr[!f][cnt] < arr[f][i]) pre += dp[!f][cnt++];
			dp[f][i] = pre;
		}
		f = !f;
	}
	pre = 0;
	for(int i=0; i<n; i++) pre += dp[!f][i];
	cout << pre;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer a > 1 such that a2 is a divisor of x.

<image>

Malek has a number store! In his store, he has only divisors of positive integer n (and he has all of them). As a birthday present, Malek wants to give her a lovely number from his store. He wants this number to be as big as possible.

Malek always had issues in math, so he asked for your help. Please tell him what is the biggest lovely number in his store.

Input

The first and only line of input contains one integer, n (1 ≤ n ≤ 1012).

Output

Print the answer in one line.

Examples

Input

10

Output

10

Input

12

Output

6

Note

In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely.

In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 22, so 12 is not lovely, while 6 is indeed lovely.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int t = 1;
set<ll> primeFactors(ll n) {
  set<ll> s;
  while (n % 2 == 0) {
    s.insert(2);
    n = n / 2;
  }
  for (ll i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      s.insert(i);
      n = n / i;
    }
  }
  if (n > 2) s.insert(n);
  return s;
}
void solve() {
  ll n;
  cin >> n;
  set<ll> s = primeFactors(n);
  ll ans = 1;
  for (ll i : s) {
    ans *= i;
  }
  cout << ans << "\n";
}
int main() {
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Your task is to implement a double linked list.

Write a program which performs the following operations:

* insert x: insert an element with key x into the front of the list.
* delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything.
* deleteFirst: delete the first element from the list.
* deleteLast: delete the last element from the list.

Notes

Template in C -->

Constraints

* The number of operations ≤ 2,000,000
* The number of delete operations ≤ 20
* 0 ≤ value of a key ≤ 109
* The number of elements in the list does not exceed 106
* For a delete, deleteFirst or deleteLast operation, there is at least one element in the list.

Input

The input is given in the following format:

n
command1
command2
...
commandn

In the first line, the number of operations n is given. In the following n lines, the above mentioned operations are given in the following format:

* insert x
* delete x
* deleteFirst
* deleteLast

Output

Print all the element (key) in the list after the given operations. Two consequtive keys should be separated by a single space.

Examples

Input

7
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5

Output

6 1 2

Input

9
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5
deleteFirst
deleteLast

Output

1

### Response

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

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

  deque<int> d;
  string cmd;
  while (cin >> cmd)
  {
    if (cmd == "deleteFirst")
    {
      d.pop_front();
    }
    else if (cmd == "deleteLast")
    {
      d.pop_back();
    }
    else
    {
      int x;
      cin >> x;

      if (cmd == "insert")
      {
        d.push_front(x);
      }
      else if (cmd == "delete")
      {
        auto res = find(d.begin(), d.end(), x);
        if (res != d.end())
        {
          d.erase(res);
        }
      }
    }
  }

  for (int i = 0; i < d.size(); i++)
    cout << (i ? " " : "") << d[i];
  cout << "\n";
}

```


### Prompt

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

Polycarp studies at the university in the group which consists of n students (including himself). All they are registrated in the social net "TheContacnt!".

Not all students are equally sociable. About each student you know the value ai — the maximum number of messages which the i-th student is agree to send per day. The student can't send messages to himself.

In early morning Polycarp knew important news that the programming credit will be tomorrow. For this reason it is necessary to urgently inform all groupmates about this news using private messages.

Your task is to make a plan of using private messages, so that:

  * the student i sends no more than ai messages (for all i from 1 to n);
  * all students knew the news about the credit (initially only Polycarp knew it);
  * the student can inform the other student only if he knows it himself.

Let's consider that all students are numerated by distinct numbers from 1 to n, and Polycarp always has the number 1.

In that task you shouldn't minimize the number of messages, the moment of time, when all knew about credit or some other parameters. Find any way how to use private messages which satisfies requirements above.

Input

The first line contains the positive integer n (2 ≤ n ≤ 100) — the number of students.

The second line contains the sequence a1, a2, ..., an (0 ≤ ai ≤ 100), where ai equals to the maximum number of messages which can the i-th student agree to send. Consider that Polycarp always has the number 1.

Output

Print -1 to the first line if it is impossible to inform all students about credit.

Otherwise, in the first line print the integer k — the number of messages which will be sent. In each of the next k lines print two distinct integers f and t, meaning that the student number f sent the message with news to the student number t. All messages should be printed in chronological order. It means that the student, who is sending the message, must already know this news. It is assumed that students can receive repeated messages with news of the credit.

If there are several answers, it is acceptable to print any of them.

Examples

Input

4
1 2 1 0

Output

3
1 2
2 4
2 3

Input

6
2 0 1 3 2 0

Output

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

Input

3
0 2 2

Output

-1

Note

In the first test Polycarp (the student number 1) can send the message to the student number 2, who after that can send the message to students number 3 and 4. Thus, all students knew about the credit.

### Response

```cpp
#include <bits/stdc++.h>
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long long MXLL = 4611686018427387903;
const int Sz = 1110111;
using namespace std;
inline void Read_rap() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
}
int n;
pair<int, int> a[Sz];
vector<pair<int, int> > ans;
int main() {
  Read_rap();
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a + 2, a + n + 1);
  reverse(a + 2, a + n + 1);
  int ptr = 2;
  for (int i = 1; i <= n; i++) {
    if (ptr <= i) {
      cout << -1;
      return 0;
    }
    for (; ptr <= n && a[i].first; ptr++, a[i].first--) {
      ans.push_back(make_pair(a[i].second, a[ptr].second));
    }
  }
  cout << (int)(ans.size()) << endl;
  for (auto i : ans) cout << i.first << ' ' << i.second << endl;
  return 0;
}

```


### Prompt

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

Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set.

Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4.

Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w1, w2,..., wn, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to wi, that is s(xi, yi) = yi - xi = wi.

Now Wilbur asks you to help him with this challenge.

Input

The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with.

Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input.

The last line of the input contains n integers. The i-th of them is wi ( - 100 000 ≤ wi ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering.

Output

If there exists an aesthetically pleasant numbering of points in the set, such that s(xi, yi) = yi - xi = wi, then print "YES" on the first line of the output. Otherwise, print "NO".

If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them.

Examples

Input

5
2 0
0 0
1 0
1 1
0 1
0 -1 -2 1 0

Output

YES
0 0
1 0
2 0
0 1
1 1

Input

3
1 0
0 0
2 0
0 1 2

Output

NO

Note

In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and yi - xi = wi.

In the second sample, the special values of the points in the set are 0,  - 1, and  - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not exist.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int x[2 * 100010], y[2 * 100010];
int X, Y;
int ansx[100010], ansy[100010];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    X = max(X, a);
    Y = max(Y, b);
  }
  for (int i = 0; i <= X + 1; i++) x[100010 - i] = i;
  for (int i = 0; i <= Y + 1; i++) y[100010 + i] = i;
  for (int i = 0; i < n; i++) {
    int w;
    cin >> w;
    ansx[i] = x[100010 + w]++;
    ansy[i] = y[100010 + w]++;
    if (y[100010 + w + 1] < y[100010 + w] ||
        x[100010 + w - 1] < x[100010 + w]) {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
  for (int i = 0; i < n; i++) {
    cout << ansx[i] << ' ' << ansy[i] << '\n';
  }
}

```


### Prompt

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

In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string s1, consisting of exactly nine digits and representing a number that does not exceed a. After that second player looks at s1 and writes a string s2, consisting of exactly nine digits and representing a number that does not exceed b. Here a and b are some given constants, s1 and s2 are chosen by the players. The strings are allowed to contain leading zeroes.

If a number obtained by the concatenation (joining together) of strings s1 and s2 is divisible by mod, then the second player wins. Otherwise the first player wins. You are given numbers a, b, mod. Your task is to determine who wins if both players play in the optimal manner. If the first player wins, you are also required to find the lexicographically minimum winning move.

Input

The first line contains three integers a, b, mod (0 ≤ a, b ≤ 109, 1 ≤ mod ≤ 107).

Output

If the first player wins, print "1" and the lexicographically minimum string s1 he has to write to win. If the second player wins, print the single number "2".

Examples

Input

1 10 7

Output

2

Input

4 0 9

Output

1 000000001

Note

The lexical comparison of strings is performed by the < operator in modern programming languages. String x is lexicographically less than string y if exists such i (1 ≤ i ≤ 9), that xi < yi, and for any j (1 ≤ j < i) xj = yj. These strings always have length 9.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char A[15], B[15], C[15];
long long D[20];
int main() {
  int i, j, k;
  D[0] = 1;
  for (i = 1; i < 20; i++) D[i] = D[i - 1] * 10;
  long long a, b, mod, s, p;
  cin >> a >> b >> mod;
  long long t = min(a, mod);
  for (i = 0; i <= t; i++) {
    s = (long long)i * D[9];
    p = s / mod;
    if (s % mod) p++;
    p *= mod;
    if (p > s + b) {
      break;
    }
  }
  if ((long long)i > t) {
    printf("2\n");
  } else {
    k = i;
    for (i = 0; i < 9; i++) C[i] = (k % D[9 - i]) / D[8 - i] + '0';
    C[9] = '\0';
    printf("1 %s\n", C);
  }
}

```


### Prompt

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

Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy.

We'll consider the table rows numbered from top to bottom from 1 to n, and the columns — numbered from left to right from 1 to n. Initially there is exactly one switched on cell with coordinates (x, y) (x is the row number, y is the column number), and all other cells are switched off. Then each second we switch on the cells that are off but have the side-adjacent cells that are on.

For a cell with coordinates (x, y) the side-adjacent cells are cells with coordinates (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1).

In how many seconds will Mr. Bender get happy?

Input

The first line contains four space-separated integers n, x, y, c (1 ≤ n, c ≤ 109; 1 ≤ x, y ≤ n; c ≤ n2).

Output

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

Examples

Input

6 4 3 1

Output

0

Input

9 3 8 10

Output

2

Note

Initially the first test has one painted cell, so the answer is 0. In the second test all events will go as is shown on the figure. <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int fun(long long int n) { return n * n; }
long long int sum(long long int w, long long int h, long long int l) {
  long long int n = w + h - l;
  if (n > 0) return ((1 + n) * n) / 2;
  return 0;
}
long long int cal(long long int n, long long int x, long long int y,
                  long long int t) {
  long long int ans = t * t + (t + 1) * (t + 1);
  long long int u = t - (x - 1);
  long long int d = t - (n - x);
  long long int l = t - (y - 1);
  long long int r = t - (n - y);
  if (u > 0) ans -= fun(u);
  if (d > 0) ans -= fun(d);
  if (l > 0) ans -= fun(l);
  if (r > 0) ans -= fun(r);
  if (u > 0 && l > 0) ans += sum(u, l, t + 1);
  if (d > 0 && l > 0) ans += sum(d, l, t + 1);
  if (u > 0 && r > 0) ans += sum(u, r, t + 1);
  if (d > 0 && r > 0) ans += sum(d, r, t + 1);
  return ans;
}
long long int bsearc(long long int n, long long int x, long long int y,
                     long long int c) {
  long long int l = 0, h = 2 * n + 1, m;
  while (l < h) {
    m = (l + h) / 2;
    if (cal(n, x, y, m) < c)
      l = m + 1;
    else
      h = m;
  }
  return l;
}
int main() {
  long long int n, x, y, c;
  cin >> n >> x >> y >> c;
  cout << bsearc(n, x, y, c) << "\n";
  return 0;
}

```


### Prompt

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

The cool breeze blows gently, the flowing water ripples steadily.

"Flowing and passing like this, the water isn't gone ultimately; Waxing and waning like that, the moon doesn't shrink or grow eventually."

"Everything is transient in a way and perennial in another."

Kanno doesn't seem to make much sense out of Mino's isolated words, but maybe it's time that they enjoy the gentle breeze and the night sky — the inexhaustible gifts from nature.

Gazing into the sky of stars, Kanno indulges in a night's tranquil dreams.

There is a set S of n points on a coordinate plane.

Kanno starts from a point P that can be chosen on the plane. P is not added to S if it doesn't belong to S. Then the following sequence of operations (altogether called a move) is repeated several times, in the given order:

  1. Choose a line l such that it passes through at least two elements in S and passes through Kanno's current position. If there are multiple such lines, one is chosen equiprobably.
  2. Move to one of the points that belong to S and lie on l. The destination is chosen equiprobably among all possible ones, including Kanno's current position (if it does belong to S).

There are q queries each consisting of two integers (t_i, m_i). For each query, you're to help Kanno maximize the probability of the stopping position being the t_i-th element in S after m_i moves with a proper selection of P, and output this maximum probability. Note that according to rule 1, P should belong to at least one line that passes through at least two points from S.

Input

The first line contains a positive integer n (2 ≤ n ≤ 200) — the number of points in S.

The i-th of the following n lines contains two space-separated integers x_i and y_i (-10^4 ≤ x_i, y_i ≤ 10^4) — the coordinates of the i-th point in S. The input guarantees that for all 1 ≤ i < j ≤ n, (x_i, y_i) ≠ (x_j, y_j) holds.

The next line contains a positive integer q (1 ≤ q ≤ 200) — the number of queries.

Each of the following q lines contains two space-separated integers t and m (1 ≤ t_i ≤ n, 1 ≤ m_i ≤ 10^4) — the index of the target point and the number of moves, respectively.

Output

Output q lines each containing a decimal number — the i-th among them denotes the maximum probability of staying on the t_i-th point after m_i steps, with a proper choice of starting position P.

Your answer will be considered correct if each number in your output differs from the corresponding one in jury's answer by at most 10^{-6}.

Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if |a - b| ≤ 10^{-6}.

Example

Input

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

Output

0.50000000000000000000
0.50000000000000000000
0.33333333333333331483
0.50000000000000000000
0.50000000000000000000
0.18518518518518517491
0.15226337448559670862
0.14494741655235482414
0.14332164812274550414
0.14296036624949901017

Note

The points in S and possible candidates for line l are depicted in the following figure.

<image>

For the first query, when P = (-1, -3), l is uniquely determined to be 3x = y, and thus Kanno will move to (0, 0) with a probability of \frac 1 2.

For the third query, when P = (2, 2), l is chosen equiprobably between x + y = 4 and x = y. Kanno will then move to the other four points with a probability of \frac 1 2 ⋅ \frac 1 3 = \frac 1 6 each, or stay at (2, 2) with a probability of \frac 1 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#pragma optimize("-O3")
int n;
int x[250];
int y[250];
bool vis[250];
vector<vector<vector<int>>> v;
double dp[201][201][21];
bool first(int x1, int y1, int x2, int y2, int x3, int y3) {
  if ((y2 - y1) * (x3 - x1) == (y3 - y1) * (x2 - x1)) {
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(20);
  cin >> n;
  v.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      vis[j] = 0;
    }
    vis[i] = 1;
    for (int j = 0; j < n; j++) {
      if (vis[j] == 1) {
        continue;
      }
      vis[j] = 1;
      vector<int> vec;
      vec.push_back(j);
      vec.push_back(i);
      for (int k = 0; k < n; k++) {
        if (vis[k]) {
          continue;
        }
        if (first(x[i], y[i], x[j], y[j], x[k], y[k])) {
          vec.push_back(k);
          vis[k] = 1;
        }
      }
      v[i].push_back(vec);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j][0] = 0;
    }
    dp[i][i][0] = 1;
    for (int it = 1; it <= 20; it++) {
      for (int j = 0; j < n; j++) {
        int sz = v[j].size();
        for (int k = 0; k < v[j].size(); k++) {
          int sz2 = v[j][k].size();
          for (auto u : v[j][k]) {
            dp[i][u][it] += (((dp[i][j][it - 1]) / sz) / sz2);
          }
        }
      }
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int t, m;
    cin >> t >> m;
    t--;
    m = min(m, 20);
    double maxi = 0;
    for (int i = 0; i < n; i++) {
      maxi = max(maxi, dp[i][t][m]);
    }
    for (int i = 0; i < n; i++) {
      for (auto u : v[i]) {
        double val = 0;
        int sz = u.size();
        for (auto u2 : u) {
          val += dp[u2][t][m - 1];
        }
        val = val / sz;
        maxi = max(maxi, val);
      }
    }
    cout << setprecision(20) << maxi << '\n';
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation.

Right now the situation in Berland is dismal — their both cities are surrounded! The armies of flatlanders stand on the borders of circles, the circles' centers are in the surrounded cities. At any moment all points of the flatland ring can begin to move quickly in the direction of the city — that's the strategy the flatlanders usually follow when they besiege cities.

The berlanders are sure that they can repel the enemy's attack if they learn the exact time the attack starts. For that they need to construct a radar that would register any movement at the distance of at most r from it. Thus, we can install a radar at such point, that at least one point of the enemy ring will be in its detecting range (that is, at a distance of at most r). Then the radar can immediately inform about the enemy's attack.

Due to the newest technologies, we can place a radar at any point without any problems. But the problem is that the berlanders have the time to make only one radar. Besides, the larger the detection radius (r) is, the more the radar costs.

That's why Vasya's task (that is, your task) is to find the minimum possible detection radius for the radar. In other words, your task is to find the minimum radius r (r ≥ 0) such, that a radar with radius r can be installed at some point and it can register the start of the movements of both flatland rings from that point.

In this problem you can consider the cities as material points, the attacking enemy rings - as circles with centers in the cities, the radar's detection range — as a disk (including the border) with the center at the point where the radar is placed.

Input

The input files consist of two lines. Each line represents the city and the flatland ring that surrounds it as three space-separated integers xi, yi, ri (|xi|, |yi| ≤ 104; 1 ≤ ri ≤ 104) — the city's coordinates and the distance from the city to the flatlanders, correspondingly.

It is guaranteed that the cities are located at different points.

Output

Print a single real number — the minimum detection radius of the described radar. The answer is considered correct if the absolute or relative error does not exceed 10 - 6.

Examples

Input

0 0 1
6 0 3

Output

1.000000000000000

Input

-10 10 3
10 -10 3

Output

11.142135623730951

Note

The figure below shows the answer to the first sample. In this sample the best decision is to put the radar at point with coordinates (2, 0).

<image>

The figure below shows the answer for the second sample. In this sample the best decision is to put the radar at point with coordinates (0, 0).

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct Circle {
  int x, y, r;
};
double dist(const Circle &a, const Circle &b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
int main() {
  Circle f, s;
  cin >> f.x >> f.y >> f.r;
  cin >> s.x >> s.y >> s.r;
  double ans = dist(f, s);
  if (ans + min(f.r, s.r) < max(f.r, s.r)) {
    ans = (max(f.r, s.r) - ans - min(f.r, s.r)) / 2;
  } else if (ans > (f.r + s.r)) {
    ans = (ans - f.r - s.r) / 2;
  } else
    ans = 0;
  printf("%.16lf\n", ans);
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they form a regular n-gon. They are numbered in clockwise order with numbers from 1 to n.

The site of the University has already conducted a voting that estimated each sculpture's characteristic of ti — the degree of the sculpture's attractiveness. The values of ti can be positive, negative or zero.

When the university rector came to evaluate the work, he said that this might be not the perfect arrangement. He suggested to melt some of the sculptures so that:

  * the remaining sculptures form a regular polygon (the number of vertices should be between 3 and n),
  * the sum of the ti values of the remaining sculptures is maximized.

Help the Vice Rector to analyze the criticism — find the maximum value of ti sum which can be obtained in this way. It is allowed not to melt any sculptures at all. The sculptures can not be moved.

Input

The first input line contains an integer n (3 ≤ n ≤ 20000) — the initial number of sculptures. The second line contains a sequence of integers t1, t2, ..., tn, ti — the degree of the i-th sculpture's attractiveness ( - 1000 ≤ ti ≤ 1000). The numbers on the line are separated by spaces.

Output

Print the required maximum sum of the sculptures' attractiveness.

Examples

Input

8
1 2 -3 4 -5 5 2 3

Output

14

Input

6
1 -2 3 -4 5 -6

Output

9

Input

6
1 2 3 4 5 6

Output

21

Note

In the first sample it is best to leave every second sculpture, that is, leave sculptures with attractivenesses: 2, 4, 5 и 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, t[20000];
int main() {
  cin >> n;
  int i, j, k = 1, sum, max_sum = INT_MIN;
  for (int i = 0; i < n; ++i) {
    cin >> t[i];
  }
  while (1) {
    if (n / k < 3) {
      break;
    }
    if (n % k == 0) {
      for (int i = 0; i < k; ++i) {
        sum = 0;
        j = i;
        do {
          sum += t[j];
          j = (j + k) % n;
        } while (j != i);
        if (sum > max_sum) {
          max_sum = sum;
        }
      }
    }
    ++k;
  }
  cout << max_sum;
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or edges.

Input

The first line of input contains two integers n and m (1 ≤ n ≤ 19, 0 ≤ m) – respectively the number of vertices and edges of the graph. Each of the subsequent m lines contains two integers a and b, (1 ≤ a, b ≤ n, a ≠ b) indicating that vertices a and b are connected by an undirected edge. There is no more than one edge connecting any pair of vertices.

Output

Output the number of cycles in the given graph.

Examples

Input

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

Output

7

Note

The example graph is a clique and contains four cycles of length 3 and three cycles of length 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long dp[19][524288], t[524288];
int edge[19][19];
int main() {
  int n, m, x, y;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &x, &y);
    edge[x - 1][y - 1] = 1;
    edge[y - 1][x - 1] = 1;
  }
  long long ans = 0;
  for (int i = 1; i < (1 << n); i++) {
    int start = 0, count = 0;
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        start = j;
        count++;
      }
    }
    if (count == 1) {
      dp[start][i] = 1;
      continue;
    }
    for (int j = 0; j <= start; j++) {
      for (int k = 0; k < start; k++) {
        if (!edge[j][k]) continue;
        if ((i & (1 << j)) == 0) continue;
        if ((i & (1 << k)) == 0) continue;
        dp[k][i] += dp[j][i ^ (1 << k)];
      }
    }
    if (count >= 3) {
      for (int j = 0; j < start; j++) {
        if (edge[start][j]) {
          ans += dp[j][i];
        }
      }
    }
  }
  printf("%I64d\n", ans / 2);
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

You are given an array a with n distinct integers. Construct an array b by permuting a such that for every non-empty subset of indices S = {x1, x2, ..., xk} (1 ≤ xi ≤ n, 0 < k < n) the sums of elements on that positions in a and b are different, i. e.

<image>

Input

The first line contains one integer n (1 ≤ n ≤ 22) — the size of the array.

The second line contains n space-separated distinct integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the elements of the array.

Output

If there is no such array b, print -1.

Otherwise in the only line print n space-separated integers b1, b2, ..., bn. Note that b must be a permutation of a.

If there are multiple answers, print any of them.

Examples

Input

2
1 2

Output

2 1

Input

4
1000 100 10 1

Output

100 1 1000 10

Note

An array x is a permutation of y, if we can shuffle elements of y such that it will coincide with x.

Note that the empty subset and the subset containing all indices are not counted.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int MM = 998244353;
const long double PI = acos(-1);
long long power(long long b, long long e, long long m) {
  if (e == 0) return 1;
  if (e & 1) return b * power(b * b % m, e / 2, m) % m;
  return power(b * b % m, e / 2, m);
}
long long power(long long b, long long e) {
  if (e == 0) return 1;
  if (e & 1) return b * power(b * b, e / 2);
  return power(b * b, e / 2);
}
template <typename T, typename U>
static inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T &x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << '(' << p.first << "," << p.second << ')';
}
int _runtimeTerror_() {
  int n;
  cin >> n;
  vector<int> v(n), w;
  map<int, int> idx;
  for (int i = 0; i < n; ++i) cin >> v[i];
  w = v;
  sort(w.begin(), w.end());
  for (int i = 0; i < n; ++i) idx[w[i]] = i;
  vector<int> ans(n);
  for (int i = 0; i < n; ++i) {
    int u = idx[v[i]];
    ans[i] = w[(u + 1) % n];
    cout << ans[i] << " ";
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) _runtimeTerror_();
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencies.

Rubik has 3 computers, on which he can play this game. All computers are located in different houses. Besides, it has turned out that each part of the game can be completed only on one of these computers. Let's number the computers with integers from 1 to 3. Rubik can perform the following actions:

  * Complete some part of the game on some computer. Rubik spends exactly 1 hour on completing any part on any computer.
  * Move from the 1-st computer to the 2-nd one. Rubik spends exactly 1 hour on that.
  * Move from the 1-st computer to the 3-rd one. Rubik spends exactly 2 hours on that.
  * Move from the 2-nd computer to the 1-st one. Rubik spends exactly 2 hours on that.
  * Move from the 2-nd computer to the 3-rd one. Rubik spends exactly 1 hour on that.
  * Move from the 3-rd computer to the 1-st one. Rubik spends exactly 1 hour on that.
  * Move from the 3-rd computer to the 2-nd one. Rubik spends exactly 2 hours on that.

Help Rubik to find the minimum number of hours he will need to complete all parts of the game. Initially Rubik can be located at the computer he considers necessary.

Input

The first line contains integer n (1 ≤ n ≤ 200) — the number of game parts. The next line contains n integers, the i-th integer — ci (1 ≤ ci ≤ 3) represents the number of the computer, on which you can complete the game part number i.

Next n lines contain descriptions of game parts. The i-th line first contains integer ki (0 ≤ ki ≤ n - 1), then ki distinct integers ai, j (1 ≤ ai, j ≤ n; ai, j ≠ i) — the numbers of parts to complete before part i.

Numbers on all lines are separated by single spaces. You can assume that the parts of the game are numbered from 1 to n in some way. It is guaranteed that there are no cyclic dependencies between the parts of the game.

Output

On a single line print the answer to the problem.

Examples

Input

1
1
0

Output

1

Input

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

Output

7

Note

Note to the second sample: before the beginning of the game the best strategy is to stand by the third computer. First we complete part 5. Then we go to the 1-st computer and complete parts 3 and 4. Then we go to the 2-nd computer and complete parts 1 and 2. In total we get 1+1+2+1+2, which equals 7 hours.

### Response

```cpp
#include <bits/stdc++.h>
const int kMAX = 10000000;
using namespace std;
int roadMap(int src, int dest) {
  if ((src == 1 && dest == 2) || (src == 2 && dest == 3) ||
      (src == 3 && dest == 1))
    return 1;
  else if ((src == 1 && dest == 3) || (src == 2 && dest == 1) ||
           (src == 3 && dest == 2))
    return 2;
  return 0;
}
int processForStart(const vector<vector<int> >& graph, const vector<int>& comp,
                    int start, int n) {
  list<int> processed;
  vector<int> unprocessed;
  for (int i = 0; i < n; ++i) unprocessed.push_back(i);
  vector<int> weights;
  for (int i = 0; i < n; ++i) weights.push_back(kMAX);
  weights[start] = 0;
  while (unprocessed.size() != 0) {
    weights[start]++;
    processed.push_back(start);
    vector<int>::iterator it =
        find(unprocessed.begin(), unprocessed.end(), start);
    if (it != unprocessed.end()) unprocessed.erase(it);
    if (unprocessed.size() == 0) break;
    int startComp = comp[start];
    int bestMove = -1;
    int bestResult = kMAX;
    for (int i = 0; i < unprocessed.size(); ++i) {
      int currComp = comp[unprocessed[i]];
      int canMove = 1;
      for (int k = 0; k < graph[unprocessed[i]].size(); ++k) {
        if (processed.end() == find(processed.begin(), processed.end(),
                                    graph[unprocessed[i]][k])) {
          canMove = 0;
          break;
        }
      }
      int newWeight = weights[start] + roadMap(startComp, currComp);
      if (canMove) {
        if (newWeight < bestResult) {
          bestResult = newWeight;
          bestMove = unprocessed[i];
        }
      }
    }
    weights[bestMove] = bestResult;
    start = bestMove;
  }
  int result = *max_element(weights.begin(), weights.end());
  return result;
}
int main() {
  int n;
  cin >> n;
  vector<int> comp;
  for (int i = 0; i < n; ++i) {
    int tmp;
    cin >> tmp;
    comp.push_back(tmp);
  }
  vector<vector<int> > graph;
  vector<int> starts;
  for (int i = 0; i < n; ++i) {
    int tmp;
    cin >> tmp;
    vector<int> needGames;
    if (0 == tmp) starts.push_back(i);
    for (int j = 0; j < tmp; ++j) {
      int tmp2;
      cin >> tmp2;
      needGames.push_back(tmp2 - 1);
    }
    graph.push_back(needGames);
  }
  int bestRes = kMAX;
  for (int i = 0; i < starts.size(); ++i) {
    int res = processForStart(graph, comp, starts[i], n);
    if (res < bestRes) {
      bestRes = res;
    }
  }
  cout << bestRes;
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

A little girl loves problems on trees very much. Here's one of them.

A tree is an undirected connected graph, not containing cycles. The degree of node x in the tree is the number of nodes y of the tree, such that each of them is connected with node x by some edge of the tree.

Let's consider a tree that consists of n nodes. We'll consider the tree's nodes indexed from 1 to n. The cosidered tree has the following property: each node except for node number 1 has the degree of at most 2.

Initially, each node of the tree contains number 0. Your task is to quickly process the requests of two types:

  * Request of form: 0 v x d. In reply to the request you should add x to all numbers that are written in the nodes that are located at the distance of at most d from node v. The distance between two nodes is the number of edges on the shortest path between them.
  * Request of form: 1 v. In reply to the request you should print the current number that is written in node v.

Input

The first line contains integers n (2 ≤ n ≤ 105) and q (1 ≤ q ≤ 105) — the number of tree nodes and the number of requests, correspondingly.

Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi), that show that there is an edge between nodes ui and vi. Each edge's description occurs in the input exactly once. It is guaranteed that the given graph is a tree that has the property that is described in the statement.

Next q lines describe the requests.

  * The request to add has the following format: 0 v x d (1 ≤ v ≤ n, 1 ≤ x ≤ 104, 1 ≤ d < n).
  * The request to print the node value has the following format: 1 v (1 ≤ v ≤ n).

The numbers in the lines are separated by single spaces.

Output

For each request to print the node value print an integer — the reply to the request.

Examples

Input

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

Output

9
9
6

Input

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

Output

11
17
11
16
17
11

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
vector<int> a[maxn];
int h[maxn];
int sub[maxn];
int en[maxn];
int val[4 * maxn];
vector<int> valc[maxn];
void dfs(int x, int par, int su) {
  sub[x] = su;
  for (int i = 0; i < a[x].size(); i++) {
    int u = a[x][i];
    if (u == par) continue;
    h[u] = h[x] + 1;
    if (x == 1) {
      dfs(u, x, i + 1);
      continue;
    }
    dfs(u, x, su);
  }
  if (a[x].size() == 1 and x != 1) en[su] = h[x];
  return;
}
void add(int id, int L, int R, int l, int r, int ty, int x) {
  if (l == L and r == R) {
    valc[ty][id] += x;
    return;
  }
  int mid = (L + R) >> 1;
  if (l < mid) add(id * 2 + 0, L, mid, l, min(r, mid), ty, x);
  if (r > mid) add(id * 2 + 1, mid, R, max(l, mid), r, ty, x);
  return;
}
void add2(int id, int L, int R, int l, int r, int x) {
  if (l == L and r == R) {
    val[id] += x;
    return;
  }
  int mid = (L + R) >> 1;
  if (l < mid) add2(id * 2 + 0, L, mid, l, min(r, mid), x);
  if (r > mid) add2(id * 2 + 1, mid, R, max(l, mid), r, x);
  return;
}
int get(int id, int L, int R, int idx, int ty) {
  int ret = valc[ty][id];
  if (L + 1 == R) return ret;
  int mid = (L + R) >> 1;
  if (idx < mid)
    ret += get(id * 2 + 0, L, mid, idx, ty);
  else
    ret += get(id * 2 + 1, mid, R, idx, ty);
  return ret;
}
int get1(int id, int L, int R, int idx) {
  int ret = val[id];
  if (L + 1 == R) return ret;
  int mid = (L + R) >> 1;
  if (idx < mid)
    ret += get1(id * 2 + 0, L, mid, idx);
  else
    ret += get1(id * 2 + 1, mid, R, idx);
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  dfs(1, 0, 0);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= 10 * en[i]; j++) valc[i].push_back(0);
  for (int i = 1; i <= q; i++) {
    int ty, u, d, ki;
    cin >> ty >> u;
    if (ty == 0) {
      cin >> ki >> d;
      int su = sub[u];
      int tem = d - h[u];
      if (d >= h[u]) {
        if (u != 1 and tem < en[su])
          add(1, 1, en[su] + 1, tem + 1, min(en[su], h[u] + d) + 1, su, ki);
        add2(1, 1, n + 1, 1, tem + 2, ki);
      } else {
        add(1, 1, en[su] + 1, h[u] - d, min(en[su], h[u] + d) + 1, su, ki);
        continue;
      }
    } else if (ty == 1) {
      int su = sub[u];
      int ans = 0;
      if (u != 1) ans += get(1, 1, en[su] + 1, h[u], su);
      ans += get1(1, 1, n + 1, h[u] + 1);
      cout << ans << endl;
    }
  }
  return 0;
}

```


### Prompt

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

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

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

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

Input

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

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

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

Output

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

Examples

Input

5
3 7 9 7 8
5 2 5 7 5

Output

6

Input

5
1 2 3 4 5
1 1 1 1 1

Output

0

Note

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
long long powm(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  gcd(b, a % b);
}
void solve() {
  long long n;
  cin >> n;
  long long a[n + 1], t[n + 1];
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<pair<long long, long long> > v;
  for (long long i = 1; i <= n; i++) {
    cin >> t[i];
    v.push_back({a[i], -t[i]});
  }
  sort(v.begin(), v.end());
  priority_queue<long long> q;
  for (long long i = 0; i < n; i++) {
    v[i].second *= -1;
  }
  long long sum = 0, ans = 0, d = 200005;
  for (long long i = 1; i < n; i++) {
    if (v[i].first == v[i - 1].first) {
      long long temp = v[i].second;
      q.push(temp);
      ans += temp;
      sum += temp;
    } else {
      if (v[i].first > v[i - 1].first) {
        long long diff = v[i].first - v[i - 1].first;
        diff -= 1;
        while (diff && q.size()) {
          long long temp = q.top();
          q.pop();
          sum -= temp;
          ans += sum;
          diff--;
        }
        q.push(v[i].second);
        sum += v[i].second;
        diff = 1;
        while (diff && q.size()) {
          long long temp = q.top();
          q.pop();
          sum -= temp;
          ans += sum;
          diff--;
        }
      }
    }
  }
  while (d && q.size()) {
    long long temp = q.top();
    q.pop();
    sum -= temp;
    ans += sum;
    d--;
  }
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.

There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of trees.

Next n lines contain pairs of integers xi, hi (1 ≤ xi, hi ≤ 109) — the coordinate and the height of the і-th tree.

The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate.

Output

Print a single number — the maximum number of trees that you can cut down by the given rules.

Examples

Input

5
1 2
2 1
5 10
10 9
19 1

Output

3

Input

5
1 2
2 1
5 10
10 9
20 1

Output

4

Note

In the first sample you can fell the trees like that:

  * fell the 1-st tree to the left — now it occupies segment [ - 1;1]
  * fell the 2-nd tree to the right — now it occupies segment [2;3]
  * leave the 3-rd tree — it occupies point 5
  * leave the 4-th tree — it occupies point 10
  * fell the 5-th tree to the right — now it occupies segment [19;20]

In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
pair<int, int> arr[100009];
int main() {
  int a, san = 0, last = 0;
  cin >> a;
  for (int i = 0; i < a; i++) cin >> arr[i].first >> arr[i].second;
  for (int i = 0; i < a; i++) {
    if (i == 0 or i == a - 1) {
      if (i == 0)
        last = arr[i].first, san++;
      else if (i == a - 1 and arr[i].first > last)
        san++;
    } else {
      if (arr[i].first - arr[i].second > last and
          arr[i - 1].first < arr[i].first - arr[i].second) {
        san++;
        last = arr[i].first;
      } else if (arr[i].first + arr[i].second < arr[i + 1].first and
                 arr[i].first > last) {
        san++;
        last = arr[i].first + arr[i].second;
      }
    }
  }
  cout << san << endl;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

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

BubbleSort(A)
1 for i = 0 to A.length-1
2     for j = A.length-1 downto i+1
3         if A[j] < A[j-1]
4             swap A[j] and A[j-1]

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

Your program should also print the number of swap operations defined in line 4 of the pseudocode.

Constraints

1 ≤ N ≤ 100

Input

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

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

Output

The output consists of 2 lines.

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

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

Examples

Input

5
5 3 2 4 1

Output

1 2 3 4 5
8

Input

6
5 2 4 6 1 3

Output

1 2 3 4 5 6
9

### Response

```cpp
#include<bits/stdc++.h>
#define s scanf("%d",
int n,r,i,j,a[100];
int main(){
s&n);
for(;i<n;s&a[i++]));
for(i=0;i<n;i++){
for(j=0;j<i;){
if(a[i]<a[j++])r++;
}
}
std::sort(a,a+n);
for(i=0;i<n;printf("%d",a[i++]))if(i)printf(" ");
printf("\n%d\n",r);
}
```