### Prompt

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

Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of two types:

  1. Increase all elements from li to ri by di. In other words, perform assignments aj = aj + di for all j that meet the inequation li ≤ j ≤ ri.
  2. Find the maximum of elements from li to ri. That is, calculate the value <image>.

Sadly, Levko has recently lost his array. Fortunately, Levko has records of all operations he has performed on array a. Help Levko, given the operation records, find at least one suitable array. The results of all operations for the given array must coincide with the record results. Levko clearly remembers that all numbers in his array didn't exceed 109 in their absolute value, so he asks you to find such an array.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 5000) — the size of the array and the number of operations in Levko's records, correspondingly.

Next m lines describe the operations, the i-th line describes the i-th operation. The first integer in the i-th line is integer ti (1 ≤ ti ≤ 2) that describes the operation type. If ti = 1, then it is followed by three integers li, ri and di (1 ≤ li ≤ ri ≤ n,  - 104 ≤ di ≤ 104) — the description of the operation of the first type. If ti = 2, then it is followed by three integers li, ri and mi (1 ≤ li ≤ ri ≤ n,  - 5·107 ≤ mi ≤ 5·107) — the description of the operation of the second type.

The operations are given in the order Levko performed them on his array.

Output

In the first line print "YES" (without the quotes), if the solution exists and "NO" (without the quotes) otherwise.

If the solution exists, then on the second line print n integers a1, a2, ... , an (|ai| ≤ 109) — the recovered array.

Examples

Input

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

Output

YES
4 7 4 7

Input

4 5
1 2 3 1
2 1 2 8
2 3 4 7
1 1 3 3
2 3 4 13

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
int n, m, a[10000], sum[10000], op[10000], l[10000], r[10000], num[10000],
    b[10000];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) a[i] = 999999999;
  memset(sum, 0, sizeof(sum));
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &op[i], &l[i], &r[i], &num[i]);
    if (op[i] == 1) {
      for (int j = l[i]; j <= r[i]; j++) sum[j] += num[i];
    } else {
      for (int j = l[i]; j <= r[i]; j++)
        if (a[j] + sum[j] > num[i]) a[j] = num[i] - sum[j];
    }
  }
  memcpy(b, a, sizeof(a));
  for (int i = 1; i <= m; i++) {
    if (op[i] == 1) {
      for (int j = l[i]; j <= r[i]; j++) b[j] += num[i];
    } else {
      int m = -0x3f3f3f3f;
      for (int j = l[i]; j <= r[i]; j++) m = max(m, b[j]);
      if (m != num[i]) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  cout << a[1];
  for (int i = 2; i <= n; i++) cout << " " << a[i];
  cout << endl;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Being tired of participating in too many Codeforces rounds, Gildong decided to take some rest in a park. He sat down on a bench, and soon he found two rabbits hopping around. One of the rabbits was taller than the other.

He noticed that the two rabbits were hopping towards each other. The positions of the two rabbits can be represented as integer coordinates on a horizontal line. The taller rabbit is currently on position x, and the shorter rabbit is currently on position y (x < y). Every second, each rabbit hops to another position. The taller rabbit hops to the positive direction by a, and the shorter rabbit hops to the negative direction by b.

<image>

For example, let's say x=0, y=10, a=2, and b=3. At the 1-st second, each rabbit will be at position 2 and 7. At the 2-nd second, both rabbits will be at position 4.

Gildong is now wondering: Will the two rabbits be at the same position at the same moment? If so, how long will it take? Let's find a moment in time (in seconds) after which the rabbits will be at the same point.

Input

Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000).

Each test case contains exactly one line. The line consists of four integers x, y, a, b (0 ≤ x < y ≤ 10^9, 1 ≤ a,b ≤ 10^9) — the current position of the taller rabbit, the current position of the shorter rabbit, the hopping distance of the taller rabbit, and the hopping distance of the shorter rabbit, respectively.

Output

For each test case, print the single integer: number of seconds the two rabbits will take to be at the same position.

If the two rabbits will never be at the same position simultaneously, print -1.

Example

Input

5
0 10 2 3
0 10 3 3
900000000 1000000000 1 9999999
1 2 1 1
1 3 1 1

Output

2
-1
10
-1
1

Note

The first case is explained in the description.

In the second case, each rabbit will be at position 3 and 7 respectively at the 1-st second. But in the 2-nd second they will be at 6 and 4 respectively, and we can see that they will never be at the same position since the distance between the two rabbits will only increase afterward.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int x, y, a, b, n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d%d%d", &x, &y, &a, &b);
    y -= x, a += b;
    printf("%d\n", y % a == 0 ? y / a : -1);
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

The only difference between easy and hard versions is constraints.

You are given n segments on the coordinate axis OX. Segments can intersect, lie inside each other and even coincide. The i-th segment is [l_i; r_i] (l_i ≤ r_i) and it covers all integer points j such that l_i ≤ j ≤ r_i.

The integer point is called bad if it is covered by strictly more than k segments.

Your task is to remove the minimum number of segments so that there are no bad points at all.

Input

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 200) — the number of segments and the maximum number of segments by which each integer point can be covered.

The next n lines contain segments. The i-th line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 200) — the endpoints of the i-th segment.

Output

In the first line print one integer m (0 ≤ m ≤ n) — the minimum number of segments you need to remove so that there are no bad points.

In the second line print m distinct integers p_1, p_2, ..., p_m (1 ≤ p_i ≤ n) — indices of segments you remove in any order. If there are multiple answers, you can print any of them.

Examples

Input

7 2
11 11
9 11
7 8
8 9
7 8
9 11
7 9

Output

3
1 4 7

Input

5 1
29 30
30 30
29 29
28 30
30 30

Output

3
1 2 4

Input

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

Output

4
1 3 5 6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 10;
int l[maxn], r[maxn];
int n, k;
vector<int> node[maxn];
set<pair<int, int> > s;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> l[i] >> r[i];
    node[l[i]].push_back(i);
    node[r[i] + 1].push_back(-i);
  }
  vector<int> ans;
  for (int i = 1; i <= 2e5; i++) {
    for (int j = 0; j < node[i].size(); j++) {
      int u = node[i][j];
      if (u > 0) {
        s.insert(make_pair(r[u], u));
      } else
        s.erase(make_pair(r[-u], -u));
    }
    while (s.size() > k) {
      set<pair<int, int> >::iterator it = s.end();
      --it;
      ans.push_back(it->second);
      s.erase(*it);
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << abs(ans[i]) << " ";
  }
  cout << endl;
  return 0;
}

```


### Prompt

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

You are given a grid with n rows and m columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number k > 0 written on it, then exactly k of its neighboring cells have a number greater than 0 written on them. Note that if the number in the cell is 0, there is no such restriction on neighboring cells.

You are allowed to take any number in the grid and increase it by 1. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.

Two cells are considered to be neighboring if they have a common edge.

Input

The input consists of multiple test cases. The first line contains an integer t (1 ≤ t ≤ 5000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers n and m (2 ≤ n, m ≤ 300) — the number of rows and columns, respectively.

The following n lines contain m integers each, the j-th element in the i-th line a_{i, j} is the number written in the j-th cell of the i-th row (0 ≤ a_{i, j} ≤ 10^9).

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

Output

If it is impossible to obtain a good grid, print a single line containing "NO".

Otherwise, print a single line containing "YES", followed by n lines each containing m integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero).

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

Example

Input

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

Output

YES
0 0 0 0
0 1 1 0
0 0 0 0
NO
YES
0 0
0 0
NO
YES
0 1 0 0
1 4 2 1
0 2 0 0
1 3 1 0

Note

In the first test case, we can obtain the resulting grid by increasing the number in row 2, column 3 once. Both of the cells that contain 1 have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid

$$$0\;1\;0\;0 0\;2\;1\;0 0\;0\;0\;0$$$

All of them are accepted as valid answers.

In the second test case, it is impossible to make the grid good.

In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};
int n, m;
bool is_corr(int a, int b) { return a >= 0 && a < n && b >= 0 && b < m; }
signed main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    bool pos = true;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        int a;
        cin >> a;
        int b = 0;
        for (int ii = 0; ii < 4; ++ii) {
          if (is_corr(i + dx[ii], j + dy[ii])) {
            ++b;
          }
        }
        if (b < a) {
          pos = false;
        }
      }
    }
    if (pos) {
      cout << "YES\n";
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
          int b = 0;
          for (int ii = 0; ii < 4; ++ii) {
            if (is_corr(i + dx[ii], j + dy[ii])) {
              ++b;
            }
          }
          cout << b << " ";
        }
        cout << "\n";
      }
    } else {
      cout << "NO\n";
    }
  }
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs ai minutes to read the i-th book.

Valera decided to choose an arbitrary book with number i and read the books one by one, starting from this book. In other words, he will first read book number i, then book number i + 1, then book number i + 2 and so on. He continues the process until he either runs out of the free time or finishes reading the n-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it.

Print the maximum number of books Valera can read.

Input

The first line contains two integers n and t (1 ≤ n ≤ 105; 1 ≤ t ≤ 109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 104), where number ai shows the number of minutes that the boy needs to read the i-th book.

Output

Print a single integer — the maximum number of books Valera can read.

Examples

Input

4 5
3 1 2 1

Output

3

Input

3 3
2 2 3

Output

1

### Response

```cpp
#include <bits/stdc++.h>
long long a[100010];
int main() {
  long long n, m;
  scanf("%I64d%I64d", &n, &m);
  long long resu = 0;
  long long time = 0;
  long long i;
  long long cnt;
  a[0] = 0;
  cnt = 1;
  for (i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    time += a[i];
    while (cnt <= i && time > m) {
      time -= a[cnt];
      cnt++;
    }
    if (i - cnt + 1 > resu) resu = i - cnt + 1;
  }
  printf("%I64d\n", resu);
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.

Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!

Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.

Input

The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).

Output

Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.

Examples

Input

5 1 3 4

Output

800

Input

1 1 1 1

Output

256

Note

In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.

In the second sample, the optimal answer is to create on integer 256, thus the answer is 256.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  long long f = min(a, min(c, d));
  long long k = min(a, b);
  int ans1 = 0, ans2 = 0;
  ans1 = f * 256 + min(a - f, b) * 32;
  ans2 = min(a, b) * 32 + min(a - k, min(c, d)) * 256;
  cout << max(ans1, ans2);
}

```


### Prompt

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

Revised

The current era, Heisei, will end on April 30, 2019, and a new era will begin the next day. The day after the last day of Heisei will be May 1, the first year of the new era.

In the system developed by the ACM-ICPC OB / OG Association (Japanese Alumni Group; JAG), the date uses the Japanese calendar (the Japanese calendar that expresses the year by the era name and the number of years following it). It is saved in the database in the format of "d days". Since this storage format cannot be changed, JAG saves the date expressed in the Japanese calendar in the database assuming that the era name does not change, and converts the date to the format using the correct era name at the time of output. It was to be.

Your job is to write a program that converts the dates stored in the JAG database to dates using the Heisei or new era. Since the new era has not been announced yet, we will use "?" To represent it.

Input

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

> g y m d

g is a character string representing the era name, and g = HEISEI holds. y, m, and d are integers that represent the year, month, and day, respectively. 1 ≤ y ≤ 100, 1 ≤ m ≤ 12, 1 ≤ d ≤ 31 holds.

Dates that do not exist in the Japanese calendar, such as February 30, are not given as a dataset. When converted correctly as the Japanese calendar, the date on which the era before Heisei must be used is not given as a data set.

The end of the input is represented by a line consisting of only one'#'. The number of datasets does not exceed 100.

Output

For each data set, separate the converted era, year, month, and day with a space and output it on one line. If the converted era is "Heisei", use "HEISEI" as the era, and if it is a new era, use "?".

Normally, the first year of the era is written as the first year, but in the output of this problem, ignore this rule and output 1 as the year.

Sample Input

HEISEI 1 1 8
HEISEI 31 4 30
HEISEI 31 5 1
HEISEI 99 12 31
HEISEI 38 8 30
HEISEI 98 2 22
HEISEI 2 3 26
HEISEI 28 4 23

Output for the Sample Input

HEISEI 1 1 8
HEISEI 31 4 30
? 1 5 1
? 69 12 31
? 8 8 30
? 68 2 22
HEISEI 2 3 26
HEISEI 28 4 23

Example

Input

HEISEI 1 1 8
HEISEI 31 4 30
HEISEI 31 5 1
HEISEI 99 12 31
HEISEI 38 8 30
HEISEI 98 2 22
HEISEI 2 3 26
HEISEI 28 4 23
#

Output

HEISEI 1 1 8
HEISEI 31 4 30
? 1 5 1
? 69 12 31
? 8 8 30
? 68 2 22
HEISEI 2 3 26
HEISEI 28 4 23

### Response

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

int main(){
  while(true){
    string g;
    int y, m, d;
    cin>>g;

    if(g == "#") break;

    cin>>y>>m>>d;
    if(y<=30) cout<<g<<" "<<y<<" "<<m<<" "<<d<<endl;
    else if(y == 31)cout<<(m<=4?g:"?")<<" "<<(m<=4?y:y-30)<<" "<<m<<" "<<d<<endl;
    else  cout<<"? "<<y-30<<" "<<m<<" "<<d<<endl;
  }
  return 0;
}

```


### Prompt

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

Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.

The i-th dish (1 \leq i \leq N) he ate was Dish A_i.

When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.

Additionally, when he eats Dish i+1 just after eating Dish i (1 \leq i \leq N - 1), he gains C_i more satisfaction points.

Find the sum of the satisfaction points he gained.

Constraints

* All values in input are integers.
* 2 \leq N \leq 20
* 1 \leq A_i \leq N
* A_1, A_2, ..., A_N are all different.
* 1 \leq B_i \leq 50
* 1 \leq C_i \leq 50

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N
B_1 B_2 ... B_N
C_1 C_2 ... C_{N-1}

Output

Print the sum of the satisfaction points Takahashi gained, as an integer.

Examples

Input

3
3 1 2
2 5 4
3 6

Output

14

Input

4
2 3 4 1
13 5 8 24
45 9 15

Output

74

Input

2
1 2
50 50
50

Output

150

### Response

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

int main()
{
	int n,i,j;
	cin>>n;
	int a[n+1],b[n+1],c[n];
	for(i=1;i<n+1;i++)
		cin>>a[i];
	for(i=1;i<n+1;i++)
		cin>>b[i];
	for(i=1;i<n;i++)
		cin>>c[i];
	int ans=0;
	for(i=1;i<n+1;i++)
	{
		j=a[i];
		ans+=b[j];
		if(i-1>=0 && a[i-1]+1==a[i])
			ans+=c[j-1];
	}
	cout<<ans;
	return 0;
}
```


### Prompt

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

I am a pipe tie craftsman. As long as you get the joints and pipes that connect the pipes, you can connect any pipe. Every day, my master gives me pipes and joints, which I connect and give to my master. But if you have too many pipes, you can't connect them all in one day. Even in such a case, the master smiles and gives me a salary.

By the way, I noticed something strange at one point. Often, the salary is higher when all the pipes are not connected than when they are all connected. It's so weird that one day when my boss came, I secretly saw a memo that describes how to calculate my salary. Then, how

"The salary is paid by" the number of pipes x the total length of pipes ". However, if they are connected by a joint and become one, it is regarded as one pipe. "

It was written. Now I understand why the salary may be cheaper if you connect them all. For example, as shown in the figure below, if you connect all three pipes of length 1 and two joints of length 2 to make one pipe of length 1 + 2 + 1 + 2 + 1 = 7, 1 × (7) ) = 7. However, if you use only one joint and make two pipes with a length of 1 + 2 + 1 = 4 and a pipe with a length of 1, 2 × (4 + 1) = 10, so you will get more salary than connecting all of them. ..

<image>

I don't know why my boss decides my salary this way, but I know how I can get more salary!

Now, create a program that calculates the maximum amount of salary you can get given the number of pipes.

input

The input consists of multiple datasets. The end of the input is indicated by a single zero line. Each dataset is given in the following format.

n
p1 ... pn
j1 ... jn-1

The number of pipes n (2 ≤ n ≤ 65000) is given in the first line. The second line consists of n integers separated by a single space. pi (1 ≤ pi ≤ 1000) indicates the length of the i-th pipe. The third line consists of n-1 integers separated by one space. ji (1 ≤ ji ≤ 1000) indicates the length of the i-th joint.

The i-th joint can connect only the i-th and i + 1-th pipes. The length of the connected pipe is pi + ji + pi + 1.

The number of datasets does not exceed 100.

output

For each dataset, print the maximum amount of salary you can get on one line. For datasets given as input, the output value must always fall within the range of 32-bit unsigned integers.

Example

Input

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

Output

12
48
76

### Response

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

int main(void)
{
	int n,i,p,j[65000];
	unsigned int a,b,c,x;
	while(1){
		a=0;
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			scanf("%d",&p); a+=p;
		}
		for(i=0;i<n-1;i++) scanf("%d",&j[i]);
		sort(j,j+n-1,greater<int>());
		x=n*a; b=a;
		for(i=0;i<n-1;i++){
			b+=j[i];
			c=(n-(i+1))*b;
			if(c>x) x=c;
		}
		printf("%u\n",x);
	}
	return 0;
}
```


### Prompt

Construct a Cpp code solution to the problem outlined:

You have 4 bags A, B, C and D each of which includes N coins (there are totally 4N coins). Values of the coins in each bag are ai, bi, ci and di respectively.

Find the number of combinations that result when you choose one coin from each bag (totally 4 coins) in such a way that the total value of the coins is V. You should distinguish the coins in a bag.

Constraints

* 1 ≤ N ≤ 1000
* 1 ≤ ai, bi, ci, di ≤ 1016
* 1 ≤ V ≤ 1016
* All input values are given in integers

Input

The input is given in the following format.

N V
a1 a2 ... aN
b1 b2 ... bN
c1 c2 ... cN
d1 d2 ... dN

Output

Print the number of combinations in a line.

Examples

Input

3 14
3 1 2
4 8 2
1 2 3
7 3 2

Output

9

Input

5 4
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1

Output

625

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool chmax(ll& a, ll b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans, s;
int main() {
    cin >> n >> m;
    vl A, B, C, D, X, Y;
    rep(i, n) {
        cin >> x;
        A.push_back(x);
    }
    rep(i, n) {
        cin >> x;
        B.push_back(x);
    }
    rep(i, n) {
        cin >> x;
        C.push_back(x);
    }
    rep(i, n) {
        cin >> x;
        D.push_back(x);
    }
    rep(i, n) {
        rep(j, n) {
            X.push_back(A[i] + B[j]);
            Y.push_back(C[i] + D[j]);
        }
    }

    sort(all(X));
    sort(all(Y));

    rep(i,X.size()){
        ans += upper_bound(all(Y), m - X[i]) - lower_bound(all(Y), m - X[i]);
    }

    cout << ans << endl;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Edo has got a collection of n refrigerator magnets!

He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door must be rectangle, and both the length and the width of the door must be positive integers.

Edo figured out how he wants to place the magnets on the refrigerator. He introduced a system of coordinates on the plane, where each magnet is represented as a rectangle with sides parallel to the coordinate axes.

Now he wants to remove no more than k magnets (he may choose to keep all of them) and attach all remaining magnets to the refrigerator door, and the area of the door should be as small as possible. A magnet is considered to be attached to the refrigerator door if its center lies on the door or on its boundary. The relative positions of all the remaining magnets must correspond to the plan.

Let us explain the last two sentences. Let's suppose we want to hang two magnets on the refrigerator. If the magnet in the plan has coordinates of the lower left corner (x1, y1) and the upper right corner (x2, y2), then its center is located at (<image>, <image>) (may not be integers). By saying the relative position should correspond to the plan we mean that the only available operation is translation, i.e. the vector connecting the centers of two magnets in the original plan, must be equal to the vector connecting the centers of these two magnets on the refrigerator.

The sides of the refrigerator door must also be parallel to coordinate axes.

Input

The first line contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ min(10, n - 1)) — the number of magnets that Edo has and the maximum number of magnets Edo may not place on the refrigerator.

Next n lines describe the initial plan of placing magnets. Each line contains four integers x1, y1, x2, y2 (1 ≤ x1 < x2 ≤ 109, 1 ≤ y1 < y2 ≤ 109) — the coordinates of the lower left and upper right corners of the current magnet. The magnets can partially overlap or even fully coincide.

Output

Print a single integer — the minimum area of the door of refrigerator, which can be used to place at least n - k magnets, preserving the relative positions.

Examples

Input

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

Output

1

Input

4 1
1 1 2 2
1 9 2 10
9 9 10 10
9 1 10 2

Output

64

Input

3 0
1 1 2 2
1 1 1000000000 1000000000
1 3 8 12

Output

249999999000000001

Note

In the first test sample it is optimal to remove either the first or the third magnet. If we remove the first magnet, the centers of two others will lie at points (2.5, 2.5) and (3.5, 3.5). Thus, it is enough to buy a fridge with door width 1 and door height 1, the area of the door also equals one, correspondingly.

In the second test sample it doesn't matter which magnet to remove, the answer will not change — we need a fridge with door width 8 and door height 8.

In the third sample you cannot remove anything as k = 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k, x, y, del[100005];
int stax[15], stay[15], staX[15], staY[15];
long long ans = 1e18;
struct data {
  int x, y, id;
} a[100005], b[100005], c[100005], d[100005];
bool cmpx(data a, data b) { return a.x < b.x; }
bool cmpy(data a, data b) { return a.y < b.y; }
bool cmpX(data a, data b) { return a.x > b.x; }
bool cmpY(data a, data b) { return a.y > b.y; }
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d%d", &a[i].x, &a[i].y, &x, &y);
    a[i].x += x;
    a[i].y += y;
    a[i].id = i;
    d[i] = c[i] = b[i] = a[i];
  }
  sort(a + 1, a + n + 1, cmpx);
  sort(b + 1, b + n + 1, cmpy);
  sort(c + 1, c + n + 1, cmpX);
  sort(d + 1, d + n + 1, cmpY);
  for (int totx = 0, lax = 1; totx <= k; totx++) {
    for (int toty = 0, lay = 1; totx + toty <= k; toty++) {
      for (int totX = 0, laX = 1; totx + toty + totX <= k; totX++) {
        int totY = 0;
        for (int i = 1; i <= n && totx + toty + totX + totY < k; i++)
          if (!del[d[i].id]) {
            del[d[i].id] = 1;
            staY[++totY] = d[i].id;
          }
        int x = 1, y = 1, X = 1, Y = 1;
        for (; del[a[x].id]; x++)
          ;
        for (; del[b[y].id]; y++)
          ;
        for (; del[c[X].id]; X++)
          ;
        for (; del[d[Y].id]; Y++)
          ;
        ans = min(ans, 1ll * max(1, (c[X].x - a[x].x + 1) / 2) *
                           max((d[Y].y - b[y].y + 1) / 2, 1));
        for (; totY; totY--) del[staY[totY]] = 0;
        if (totx + toty + totX == k) {
          for (; totX; totX--) del[staX[totX]] = 0;
          break;
        }
        for (; laX <= n && del[c[laX].id];) laX++;
        if (laX > n) {
          for (; totX; totX--) del[staX[totX]] = 0;
          break;
        }
        del[c[laX].id] = 1;
        staX[totX + 1] = c[laX].id;
      }
      if (totx + toty == k) {
        for (; toty; toty--) del[stay[toty]] = 0;
        break;
      }
      for (; lay <= n && del[b[lay].id];) lay++;
      if (lay > n) {
        for (; toty; toty--) del[stay[toty]] = 0;
        break;
      }
      del[b[lay].id] = 1;
      stay[toty + 1] = b[lay].id;
    }
    for (; lax <= n && del[a[lax].id];) lax++;
    if (lax > n) break;
    del[a[lax].id] = 1;
  }
  printf("%lld\n", ans);
}

```


### Prompt

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

Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle.

More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied.

Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways).

Input

A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three.

Output

Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7.

Examples

Input

1

Output

20

Input

2

Output

680

Note

20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)(1e9 + 7);
const int MAX_N = 100010;
long long dp[MAX_N] = {0, 20};
void init() {
  long long tmp = 1;
  for (int i = 2; i < MAX_N; i++) {
    tmp = tmp * 27 % mod;
    dp[i] = (tmp * 20 % mod + 7 * dp[i - 1]) % mod;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  init();
  while (~scanf("%d", &n)) {
    printf("%I64d\n", dp[n]);
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the number of variants of group composition to evaluate.

Input

The only line of the input contains one integer n (7 ≤ n ≤ 777) — the number of potential employees that sent resumes.

Output

Output one integer — the number of different variants of group composition.

Examples

Input

7

Output

29

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> p;
bool is_prime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
unsigned long long get(int n, int k) {
  vector<int> cnt((int)(p).size(), 0);
  for (int i = 2; i <= n; i++) {
    int x = i;
    for (int j = 0; j < (int)(p).size(); j++) {
      while (x % p[j] == 0) {
        x /= p[j];
        cnt[j]++;
      }
    }
  }
  for (int i = 2; i <= k; i++) {
    int x = i;
    for (int j = 0; j < (int)(p).size(); j++) {
      while (x % p[j] == 0) {
        x /= p[j];
        cnt[j]--;
      }
    }
  }
  for (int i = 2; i <= n - k; i++) {
    int x = i;
    for (int j = 0; j < (int)(p).size(); j++) {
      while (x % p[j] == 0) {
        x /= p[j];
        cnt[j]--;
      }
    }
  }
  unsigned long long res = 1;
  for (int i = 0; i < (int)(p).size(); i++) {
    for (int j = 1; j <= cnt[i]; j++) {
      res *= p[i];
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  for (int i = 2; i <= 1000; i++) {
    if (is_prime(i)) {
      p.push_back(i);
    }
  }
  int n;
  cin >> n;
  unsigned long long res = 0;
  for (int k = 5; k <= 7; k++) {
    res += get(n, k);
  }
  cout << res << "\n";
  return 0;
}

```


### Prompt

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

You work as a system administrator in a dormitory, which has n rooms one after another along a straight hallway. Rooms are numbered from 1 to n.

You have to connect all n rooms to the Internet.

You can connect each room to the Internet directly, the cost of such connection for the i-th room is i coins.

Some rooms also have a spot for a router. The cost of placing a router in the i-th room is also i coins. You cannot place a router in a room which does not have a spot for it. When you place a router in the room i, you connect all rooms with the numbers from max(1,~i - k) to min(n,~i + k) inclusive to the Internet, where k is the range of router. The value of k is the same for all routers.

Calculate the minimum total cost of connecting all n rooms to the Internet. You can assume that the number of rooms which have a spot for a router is not greater than the number of routers you have.

Input

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 2 ⋅ 10^5) — the number of rooms and the range of each router.

The second line of the input contains one string s of length n, consisting only of zeros and ones. If the i-th character of the string equals to '1' then there is a spot for a router in the i-th room. If the i-th character of the string equals to '0' then you cannot place a router in the i-th room.

Output

Print one integer — the minimum total cost of connecting all n rooms to the Internet.

Examples

Input

5 2
00100

Output

3

Input

6 1
000000

Output

21

Input

4 1
0011

Output

4

Input

12 6
000010000100

Output

15

Note

In the first example it is enough to place the router in the room 3, then all rooms will be connected to the Internet. The total cost of connection is 3.

In the second example you can place routers nowhere, so you need to connect all rooms directly. Thus, the total cost of connection of all rooms is 1 + 2 + 3 + 4 + 5 + 6 = 21.

In the third example you need to connect the room 1 directly and place the router in the room 3. Thus, the total cost of connection of all rooms is 1 + 3 = 4.

In the fourth example you need to place routers in rooms 5 and 10. Then all rooms will be connected to the Internet. The total cost of connection is 5 + 10 = 15.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const long long inf = 1e11;
const long long mod = 1e9 + 7;
class segment_Tree_min {
  class node {
   public:
    int l, r;
    long long lazy;
    long long min;
  };
  void pushdown(int root) {
    if (tree[root].lazy) {
      tree[root << 1].min = tree[root].lazy;
      tree[root << 1 | 1].min = tree[root].lazy;
      tree[root << 1].lazy = tree[root].lazy;
      tree[root << 1 | 1].lazy = tree[root].lazy;
      tree[root].lazy = 0;
    }
  }
  void pushup(int root) {
    tree[root].min = min(tree[root << 1].min, tree[root << 1 | 1].min);
  }
  int n;
  vector<node> tree;

 public:
  vector<long long> array;
  segment_Tree_min(int _n) : n(_n), tree((_n + 1) << 2), array(_n + 1){};
  void build(int l, int r, int root = 1) {
    tree[root].l = l;
    tree[root].r = r;
    tree[root].lazy = 0;
    if (l == r) {
      tree[root].min = inf;
      return;
    }
    int mid = (l + r) >> 1;
    build(l, mid, root << 1);
    build(mid + 1, r, root << 1 | 1);
    pushup(root);
  }
  void updata(int l, int r, long long val, int root = 1) {
    if (l <= tree[root].l && r >= tree[root].r) {
      tree[root].min = val;
      tree[root].lazy = val;
      return;
    }
    pushdown(root);
    int mid = (tree[root].l + tree[root].r) >> 1;
    if (l <= mid) updata(l, r, val, root << 1);
    if (r > mid) updata(l, r, val, root << 1 | 1);
    pushup(root);
  }
  long long query(int l, int r, int root = 1) {
    if (l <= tree[root].l && r >= tree[root].r) {
      return tree[root].min;
    }
    pushdown(root);
    int mid = (tree[root].l + tree[root].r) >> 1;
    long long Min = inf;
    if (l <= mid) {
      Min = min(query(l, r, root << 1), Min);
    }
    if (r > mid) {
      Min = min(query(l, r, root << 1 | 1), Min);
    }
    return Min;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  segment_Tree_min T(n), T1(n);
  T.build(1, n);
  T1.build(1, n);
  vector<vector<long long>> dp(n + 1, vector<long long>(2, inf));
  dp[0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    dp[i][0] = min(dp[i - 1][0] + i, T1.query(max(1, i - k), i - 1));
    if (s[i - 1] == '1') {
      if (i - k - 1 <= 0) {
        dp[i][1] = 0;
      } else {
        dp[i][1] = min(T.query(i - k - 1, i - 1), T1.query(i - k - 1, i - 1));
      }
      dp[i][1] += i;
    }
    T.updata(i, i, dp[i][0]);
    T1.updata(i, i, dp[i][1]);
  }
  cout << min(dp[n][0], dp[n][1]) << endl;
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.

You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.

You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.

You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.

Input

The first line contains two integers, n and m (1 ≤ n ≤ 3000, 1 ≤ m ≤ 3000) — the number of words in the professor's lecture and the number of words in each of these languages.

The following m lines contain the words. The i-th line contains two strings ai, bi meaning that the word ai belongs to the first language, the word bi belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.

The next line contains n space-separated strings c1, c2, ..., cn — the text of the lecture. It is guaranteed that each of the strings ci belongs to the set of strings {a1, a2, ... am}.

All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.

Output

Output exactly n words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.

Examples

Input

4 3
codeforces codesecrof
contest round
letter message
codeforces contest letter contest

Output

codeforces round letter round

Input

5 3
joll wuqrd
euzf un
hbnyiyc rsoqqveh
hbnyiyc joll joll euzf joll

Output

hbnyiyc joll joll un joll

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int main() {
  long long tcase, i, j;
  tcase = 1;
  while (tcase--) {
    int n, m;
    cin >> n >> m;
    map<string, string> M;
    string a, b, cs;
    for (int i = 0; i < m; i++) {
      cin >> a >> b;
      if (M.find(a) == M.end()) {
        if (a.length() == b.length()) {
          M[a] = a;
          M[b] = a;
        } else if (a.length() > b.length()) {
          M[a] = b;
          M[b] = b;
        } else {
          M[a] = a;
          M[b] = a;
        }
      }
    }
    string s;
    vector<string> vs;
    for (int i = 0; i < n; i++) {
      cin >> s;
      vs.push_back(M[s]);
    }
    for (auto u : vs) cout << u << " ";
  }
  return 0;
}

```


### Prompt

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

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

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

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

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

You can already start working today.

Constraints

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

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

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

Examples

Input

3 4
4 3
4 1
2 2

Output

5

Input

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

Output

10

Input

1 1
2 1

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;

int main(){
  int n,m; cin>>n>>m;
  vector<vector<int>> job(100001);
  priority_queue<int> pq;
  for(int i=0;i<n;i++){
    int a,b; cin>>a>>b;
    job[a].push_back(b);
  }
  long long ans=0;
  for(int i=1;i<=m;i++){
    for(int j=0;j<job[i].size();j++){
      pq.push(job[i][j]);
    }
    if(!pq.empty()){
      ans+=pq.top(); pq.pop();
    }
  }
  cout<<ans<<endl;
}
```


### Prompt

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

Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).

They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.

The success of the operation relies on the number of pairs (i, j) (1 ≤ i < j ≤ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.

Input

The first line of the input contains the single integer n (1 ≤ n ≤ 200 000) — the number of watchmen.

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

Some positions may coincide.

Output

Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.

Examples

Input

3
1 1
7 5
1 5

Output

2

Input

6
0 0
0 1
0 2
-1 1
0 1
1 1

Output

11

Note

In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int ans = 0;
  map<long long int, long long int> map1, map2;
  map<pair<long long int, long long int>, long long int> map3;
  for (long long int i = 0; i < n; i++) {
    long long int a, b;
    cin >> a >> b;
    ans += map1[a];
    ans += map2[b];
    ans -= map3[{a, b}];
    map1[a]++;
    map2[b]++;
    map3[{a, b}]++;
  }
  cout << ans << endl;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

problem

JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center.

JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equal to 1 and less than or equal to d -1. D2, ..., dn are all different. Bake and deliver pizza at the shortest store.

The location of the delivery destination is represented by an integer k that is greater than or equal to 0 and less than or equal to d -1. This means that the distance from the head office S1 to the delivery destination in the clockwise direction is k meters. Pizza delivery is done along the loop line and no other road is allowed. However, the loop line may move clockwise or counterclockwise.

For example, if the location of the store and the location of the delivery destination are as shown in the figure below (this example corresponds to Example 1 of "I / O example").

<image>

The store closest to the delivery destination 1 is S2, so the delivery is from store S2. At this time, the distance traveled from the store is 1. Also, the store closest to delivery destination 2 is S1 (main store), so store S1 (main store). ) To deliver to home. At this time, the distance traveled from the store is 2.

Total length of the loop line d, Number of JOI pizza stores n, Number of orders m, N --1 integer representing a location other than the main store d2, ..., dn, Integer k1, .. representing the location of the delivery destination Given ., km, create a program to find the sum of all orders for each order by the distance traveled during delivery (ie, the distance from the nearest store to the delivery destination).

input

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

The first line is a positive integer d (2 ≤ d ≤ 1000000000 = 109) that represents the total length of the loop line, the second line is a positive integer n (2 ≤ n ≤ 100000) that represents the number of stores, and the third line is A positive integer m (1 ≤ m ≤ 10000) is written to represent the number of orders. The n --1 lines after the 4th line are integers d2, d3, ..., dn that represent the location of stores other than the main store. (1 ≤ di ≤ d -1) is written in this order, and the integers k1, k2, ..., km (0 ≤ ki ≤ d) representing the delivery destination location are in the m lines after the n + 3rd line. --1) are written in this order.

Of the scoring data, for 40% of the points, n ≤ 10000 is satisfied. For 40% of the points, the total distance traveled and the value of d are both 1000000 or less. In the scoring data, the total distance traveled is 1000000000 = 109 or less.

When d is 0, it indicates the end of input. The number of data sets does not exceed 10.

output

For each data set, one integer representing the total distance traveled during delivery is output on one line.

Examples

Input

8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
11
8
0

Output

3
3

Input

None

Output

None

### Response

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

using namespace std;

int main(void){
	int d;
	int n,m;
	int a,b;
	long long int ans=0;
	while(1){
		cin >> d;
		if(d==0)break;
		ans=0;
		vector<int> data;
		data.push_back(0);
		cin >> n;
		cin >> m;
		for(a=0;a<n-1;a++){
			scanf("%d",&b);
			data.push_back(b);
		}
		data.push_back(d);
		sort(data.begin(),data.end());
		for(a=0;a<m;a++){
			cin >> b;
			int w=abs(b-*(lower_bound(data.begin(),data.end(),b)-1));
			w=min(w,abs(b-*lower_bound(data.begin(),data.end(),b)));
			ans+=w;
		}
		cout << ans << endl;
	}
	return 0;
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.

In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 × 2 square, such that from the four letters of this square you can make word "face".

You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.

Input

The first line contains two space-separated integers, n and m (1 ≤ n, m ≤ 50) — the height and the width of the image, respectively.

Next n lines define the image. Each line contains m lowercase Latin letters.

Output

In the single line print the number of faces on the image.

Examples

Input

4 4
xxxx
xfax
xcex
xxxx

Output

1

Input

4 2
xx
cf
ae
xx

Output

1

Input

2 3
fac
cef

Output

2

Input

1 4
face

Output

0

Note

In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:

<image>

In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.

In the third sample two faces are shown:

<image>

In the fourth sample the image has no faces on it.

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
char s[55][55];
int main() {
  int T, i, j, k, n, m;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%s", s[i]);
  int ans = 0;
  for (i = 0; i < n - 1; i++)
    for (j = 0; j < m - 1; j++) {
      int v[4] = {0};
      for (int l = 0; l < 2; l++)
        for (int r = 0; r < 2; r++) {
          if (s[i + l][j + r] == 'f') v[0]++;
          if (s[i + l][j + r] == 'a') v[1]++;
          if (s[i + l][j + r] == 'c') v[2]++;
          if (s[i + l][j + r] == 'e') v[3]++;
        }
      if (v[0] && v[1] && v[2] && v[3]) ans++;
    }
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.

Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya.

Input

The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.

Next follows number n (1 ≤ n ≤ 90) — the number of fouls.

Each of the following n lines contains information about a foul in the following form:

  * first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs;
  * then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player;
  * then goes the player's number m (1 ≤ m ≤ 99);
  * then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given.

The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute.

Output

For each event when a player received his first red card in a chronological order print a string containing the following information:

  * The name of the team to which the player belongs;
  * the player's number in his team;
  * the minute when he received the card.

If no player received a card, then you do not need to print anything.

It is possible case that the program will not print anything to the output (if there were no red cards).

Examples

Input

MC
CSKA
9
28 a 3 y
62 h 25 y
66 h 42 y
70 h 25 y
77 a 4 y
79 a 25 y
82 h 42 r
89 h 16 y
90 a 13 r

Output

MC 25 70
MC 42 82
CSKA 13 90

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
string n[2];
int r[2][MAXN], f[2][MAXN], m, t, p;
char pt, ct;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n[0] >> n[1] >> m;
  for (int i = 0; i < m; ++i) {
    cin >> t >> pt >> p >> ct;
    int idx = pt == 'h' ? 0 : 1;
    f[idx][p] += ct == 'y' ? 1 : 2;
    if (r[idx][p] == 0 && f[idx][p] > 1) {
      r[idx][p] = 1;
      cout << n[idx] << " " << p << " " << t << endl;
    }
  }
  return 0;
}

```


### Prompt

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

Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them.

Consider two dices. When thrown each dice shows some integer from 1 to n inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and different dices may have different probability distributions.

We throw both dices simultaneously and then calculate values max(a, b) and min(a, b), where a is equal to the outcome of the first dice, while b is equal to the outcome of the second dice. You don't know the probability distributions for particular values on each dice, but you know the probability distributions for max(a, b) and min(a, b). That is, for each x from 1 to n you know the probability that max(a, b) would be equal to x and the probability that min(a, b) would be equal to x. Find any valid probability distribution for values on the dices. It's guaranteed that the input data is consistent, that is, at least one solution exists.

Input

First line contains the integer n (1 ≤ n ≤ 100 000) — the number of different values for both dices.

Second line contains an array consisting of n real values with up to 8 digits after the decimal point — probability distribution for max(a, b), the i-th of these values equals to the probability that max(a, b) = i. It's guaranteed that the sum of these values for one dice is 1. The third line contains the description of the distribution min(a, b) in the same format.

Output

Output two descriptions of the probability distribution for a on the first line and for b on the second line.

The answer will be considered correct if each value of max(a, b) and min(a, b) probability distribution values does not differ by more than 10 - 6 from ones given in input. Also, probabilities should be non-negative and their sums should differ from 1 by no more than 10 - 6.

Examples

Input

2
0.25 0.75
0.75 0.25

Output

0.5 0.5
0.5 0.5

Input

3
0.125 0.25 0.625
0.625 0.25 0.125

Output

0.25 0.25 0.5
0.5 0.25 0.25

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
double mx[100005], mn[100005], sum1[100005], sum2[100005];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return x * f;
}
inline void print(int x) {
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) scanf("%lf", &mx[i]), mx[i] += mx[i - 1];
  for (int i = 1; i <= n; i++) scanf("%lf", &mn[i]);
  for (int i = n - 1; i; i--) mn[i] += mn[i + 1];
  for (int i = 1; i <= n; i++) {
    double x = 1 + mx[i] - mn[i + 1], y = sqrt(max(x * x - 4 * mx[i], 0.0));
    sum1[i] = (x + y) * 0.5, sum2[i] = (x - y) * 0.5;
  }
  for (int i = n; i; i--) sum1[i] -= sum1[i - 1], sum2[i] -= sum2[i - 1];
  for (int i = 1; i <= n; i++) printf("%lf ", sum1[i]);
  puts("");
  for (int i = 1; i <= n; i++) printf("%lf ", sum2[i]);
  puts("");
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

problem

You are in charge of quality control at a machine manufacturing plant. This machine requires a power supply, a motor, and a cable as parts. The manufacturing plant has a power supply, b motors, and c cables, numbered from 1 to a, a + 1 to a + b, and a + b + 1 to a + b + c, respectively. attached. The trouble is that some parts may be out of order. I want to know which parts are out of order and which parts are normal in the factory.

Therefore, the factory inspected the parts by the following method. Bring the power supply, motor, and cable one by one, connect them, and try to operate them. At this time, if all three parts are normal, it operates correctly and is recognized as "passed". If any of the three parts is out of order, it will not operate properly and will be recognized as "failed". (Since the machines made in the factory are so precise, it does not happen that the broken parts are mixed and operate correctly by accident.)

You will be given a list of test results. Each line in the list of test results shows the numbers of the power supply, motor, and cable used for the test, and whether the test passed or failed.

Given a list of inspection results, all parts are either faulty or normal from the inspection results, some are definitely faulty, some are definitely normal. Create a program to classify parts that are not decided.

input

The input consists of multiple datasets. The format of each data set is as follows. The input ends on a line containing three zeros.

Three integers are written on the first line, separated by blanks, and represent the number of power supplies a, the number of motors b, and the number of cables c in order.

One integer is written on the second line, and the number of tests N included in the list of test results is written.

The next N lines represent a list of test results. On each line, four integers i, j, k, r are written with one blank as a delimiter, and the result of inspection by connecting the power supply i, the motor j, and the cable k is "pass" (r = 1). (When) or "Fail" (when r = 0).

a, b, c, N satisfy 1 ≤ a, b, c ≤ 100, 1 ≤ N ≤ 1000.

The number of datasets does not exceed 5.

output

Output in the following format for each data set. The output of each dataset consists of lines a + b + c.

Line i (1 ≤ i ≤ a + b + c):

* If the inspection result shows that the part i is out of order, 0 is output.
* If the inspection result shows that the part i is normal, 1 is output.
* Output 2 if the inspection result does not determine whether part i is defective or normal.

Examples

Input

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

Output

2
1
1
0
1
0

Input

None

Output

None

### Response

```cpp
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int a,b,c,N,d,e,f,r,p[301];
struct test{int x,y,z,w;};
test t[1000];

int main(){
	while(cin>>a>>b>>c){
		if(a+b+c==0)return 0;
		for(int i=1;i<=a+b+c;i++)p[i]=2;
		cin>>N;
		for(int i=0;i<N;i++){
			cin>>d>>e>>f>>r;
			t[i].x=d;t[i].y=e;t[i].z=f;t[i].w=r;
		}
		for(int i=0;i<N;i++)if(t[i].w==1){
			p[t[i].x]=1;p[t[i].y]=1;p[t[i].z]=1;
		}
		for(int i=0;i<N;i++)if(t[i].w==0){
			if(p[t[i].x]==1&&p[t[i].y]==1)p[t[i].z]=0;
			if(p[t[i].y]==1&&p[t[i].z]==1)p[t[i].x]=0;
			if(p[t[i].z]==1&&p[t[i].x]==1)p[t[i].y]=0;
		}
		for(int i=1;i<=a+b+c;i++)cout<<p[i]<<endl;
	}
}
```


### Prompt

Please create a solution in cpp to the following problem:

Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.

The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.

Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.

Output

Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).

Examples

Input

2
><
1 2

Output

FINITE

Input

3
>><
2 1 1

Output

INFINITE

Note

In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.

Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(const T& x) {
  return x * x;
}
template <class T>
inline void updMin(T& a, const T& b) {
  if (b < a) a = b;
}
template <class T>
inline void updMax(T& a, const T& b) {
  if (b > a) a = b;
}
const int maxn = 200000;
int n;
char s[maxn];
int a[maxn];
int used[maxn];
int main() {
  scanf("%d", &n);
  scanf("%s", s);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int p = 0;
  while (p >= 0 && p < n && !used[p]) {
    used[p] = 1;
    p += a[p] * (s[p] == '>' ? 1 : -1);
  }
  if (p < 0 || p >= n) {
    puts("FINITE");
  } else {
    puts("INFINITE");
  }
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Kuroni is very angry at the other setters for using him as a theme! As a punishment, he forced them to solve the following problem:

You have an array a consisting of n positive integers. An operation consists of choosing an element and either adding 1 to it or subtracting 1 from it, such that the element remains positive. We say the array is good if the greatest common divisor of all its elements is not 1. Find the minimum number of operations needed to make the array good.

Unable to match Kuroni's intellect, the setters failed to solve the problem. Help them escape from Kuroni's punishment!

Input

The first line contains an integer n (2 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in the array.

The second line contains n integers a_1, a_2, ..., a_n. (1 ≤ a_i ≤ 10^{12}) — the elements of the array.

Output

Print a single integer — the minimum number of operations required to make the array good.

Examples

Input

3
6 2 4

Output

0

Input

5
9 8 7 3 1

Output

4

Note

In the first example, the first array is already good, since the greatest common divisor of all the elements is 2.

In the second example, we may apply the following operations:

  1. Add 1 to the second element, making it equal to 9.
  2. Subtract 1 from the third element, making it equal to 6.
  3. Add 1 to the fifth element, making it equal to 2.
  4. Add 1 to the fifth element again, making it equal to 3.

The greatest common divisor of all elements will then be equal to 3, so the array will be good. It can be shown that no sequence of three or less operations can make the array good.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize( \
    "Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math")
using namespace std;
const int N = 2e5 + 5, M = 1e6 + 5;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
bitset<M> vis;
void Sieve() {
  vis.set();
  vis[0] = vis[1] = false;
  for (int i = 4; i < M; i += 2) vis[i] = false;
  for (int i = 3; i < M / i; i += 2) {
    if (!vis[i]) continue;
    for (int j = i * i; j < M; j += i + i) vis[j] = false;
  }
}
vector<long long> primes;
void Gen() {
  for (int i = 2; i < M; ++i)
    if (vis[i]) primes.emplace_back(i);
}
int n;
long long a[N];
long long solve(long long p) {
  long long ret = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] < p) {
      ret += (p - a[i]);
      continue;
    }
    long long rem = a[i] % p;
    ret += min(rem, p - rem);
  }
  return ret;
}
vector<long long> pr;
void fact(long long x) {
  int idx = 0, sz = primes.size();
  while (x > 1 && idx < sz && x >= primes[idx] * primes[idx]) {
    while (x % primes[idx] == 0) x /= primes[idx], pr.emplace_back(primes[idx]);
    ++idx;
  }
  if (x > 1) pr.emplace_back(x);
}
int main() {
  Sieve(), Gen();
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%lld", a + i);
  shuffle(a, a + n, mt);
  for (int i = 0; i < 7; ++i) fact(a[i]), fact(a[i] - 1), fact(a[i] + 1);
  sort(pr.begin(), pr.end());
  pr.resize(unique(pr.begin(), pr.end()) - pr.begin());
  long long mn = n;
  for (auto p : pr) mn = min(mn, solve(p));
  printf("%lld\n", mn);
}

```


### Prompt

Please formulate a cpp solution to the following problem:

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

There is a city in which Dixit lives. In the city, there are n houses. There is  exactly one directed road between every pair of houses. For example, consider two houses A and B, then there is a directed road either from A to B or from B to A but not both. The number of roads leading to the i-th house is k_i.

Two houses A and B are bi-reachable if A is reachable from B and B is reachable from A. We say that house B is reachable from house A when there is a path from house A to house B.

Dixit wants to buy two houses in the city, that is, one for living and one for studying. Of course, he would like to travel from one house to another. So, he wants to find a pair of bi-reachable houses A and B. Among all such pairs, he wants to choose one with the maximum value of |k_A - k_B|, where k_i is the number of roads leading to the house i. If more than one optimal pair exists, any of them is suitable.

Since Dixit is busy preparing CodeCraft, can you help him find the desired pair of houses, or tell him that no such houses exist?

In the problem input, you are not given the direction of each road. You are given — for each house — only the number of incoming roads to that house (k_i).

You are allowed to ask only one type of query from the judge: give two houses A and B, and the judge answers whether B is reachable from A. There is no upper limit on the number of queries. But, you cannot ask more queries after the judge answers "Yes" to any of your queries. Also, you cannot ask the same query twice.

Once you have exhausted all your queries (or the judge responds "Yes" to any of your queries), your program must output its guess for the two houses and quit.

See the Interaction section below for more details.

Input

The first line contains a single integer n (3 ≤ n ≤ 500) denoting the number of houses in the city. The next line contains n space-separated integers k_1, k_2, ..., k_n (0 ≤ k_i ≤ n - 1), the i-th of them represents the number of incoming roads to the i-th house.

Interaction

To ask a query, print "? A B" (1 ≤ A,B ≤ N, A≠ B). The judge will respond "Yes" if house B is reachable from house A, or "No" otherwise.

To output the final answer, print "! A B", where A and B are bi-reachable with the maximum possible value of |k_A - k_B|. If there does not exist such pair of houses A and B, output "! 0 0".

After outputting the final answer, your program must terminate immediately, otherwise you will receive Wrong Answer verdict.

You cannot ask the same query twice. There is no upper limit to the number of queries you ask, but, you cannot ask more queries after the judge answers "Yes" to any of your queries. Your program must now output the final answer ("! A B" or "! 0 0") and terminate.

If you ask a query in incorrect format or repeat a previous query, you will get Wrong Answer verdict.

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

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

Examples

Input

3
1 1 1
Yes

Output

? 1 2
! 1 2

Input

4
1 2 0 3
No
No
No
No
No
No

Output

? 2 1
? 1 3
? 4 1
? 2 3
? 4 2
? 4 3
! 0 0

Note

In the first sample input, we are given a city of three houses with one incoming road each. The user program asks one query: "? 1 2": asking whether we can reach from house 1 to house 2. The judge responds with "Yes". The user program now concludes that this is sufficient information to determine the correct answer. So, it outputs "! 1 2" and quits.

In the second sample input, the user program queries for six different pairs of houses, and finally answers "! 0 0" as it is convinced that no two houses as desired in the question exist in this city.

### Response

```cpp
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#include <memory>
using namespace std;
#define sf(a) scanf("%d",&a)
#define pf(a) printf("%d",a)
#define ford(i,a,n) for(i=a;i<=n;i++)
#define forb(i,n,a) for(i=n;i>=a;i--)
#define mst(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define pb push_back
#define ddd cout<<"ddd"<<endl
#define maxn 500010
#define inf 0x7fffffff
const ll mod=1e9+7;
struct point{
	int x,y;
	int res;
}k[maxn];
int cmp(point a,point b)
{
	if(a.res==b.res)
	{
		if(a.x>b.x)
		return a.y>b.y;
		return a.x>b.x;
	}
	return a.res>b.res;
}
int a[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	//ddd;
	int n;
	cin>>n;
	int i,j;
	int amount=0;
	ford(i,1,n)
	{
		cin>>a[i];
	}
	ford(i,1,n)
	ford(j,i+1,n)
	{
		k[++amount].x=i;
		k[amount].y=j;
		k[amount].res=abs(a[i]-a[j]);
		if(a[i]<a[j])
		swap(k[amount].x,k[amount].y);
	}
	sort(k+1,k+amount+1,cmp);
	ford(i,1,amount)
	{
		cout<<"? "<<k[i].x<<" "<<k[i].y<<endl;
		cout.flush();
		string op;
		cin>>op;
		if(op=="Yes")
		{
			cout<<"! "<<k[i].x<<" "<<k[i].y;
			return 0;
		}
	}
	cout<<"! 0 0";
}
```


### Prompt

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

There is a chain consisting of multiple circles on a plane. The first (last) circle of the chain only intersects with the next (previous) circle, and each intermediate circle intersects only with the two neighboring circles.

Your task is to find the shortest path that satisfies the following conditions.

* The path connects the centers of the first circle and the last circle.
* The path is confined in the chain, that is, all the points on the path are located within or on at least one of the circles.

Figure E-1 shows an example of such a chain and the corresponding shortest path.

<image>

Figure E-1: An example chain and the corresponding shortest path

Input

The input consists of multiple datasets. Each dataset represents the shape of a chain in the following format.

> n
>  x1 y1 r1
>  x2 y2 r2
>  ...
>  xn yn rn
>

The first line of a dataset contains an integer n (3 ≤ n ≤ 100) representing the number of the circles. Each of the following n lines contains three integers separated by a single space. (xi, yi) and ri represent the center position and the radius of the i-th circle Ci. You can assume that 0 ≤ xi ≤ 1000, 0 ≤ yi ≤ 1000, and 1 ≤ ri ≤ 25.

You can assume that Ci and Ci+1 (1 ≤ i ≤ n−1) intersect at two separate points. When j ≥ i+2, Ci and Cj are apart and either of them does not contain the other. In addition, you can assume that any circle does not contain the center of any other circle.

The end of the input is indicated by a line containing a zero.

Figure E-1 corresponds to the first dataset of Sample Input below. Figure E-2 shows the shortest paths for the subsequent datasets of Sample Input.

<image>

Figure E-2: Example chains and the corresponding shortest paths

Output

For each dataset, output a single line containing the length of the shortest chain-confined path between the centers of the first circle and the last circle. The value should not have an error greater than 0.001. No extra characters should appear in the output.

Sample Input

10
802 0 10
814 0 4
820 1 4
826 1 4
832 3 5
838 5 5
845 7 3
849 10 3
853 14 4
857 18 3
3
0 0 5
8 0 5
8 8 5
3
0 0 5
7 3 6
16 0 5
9
0 3 5
8 0 8
19 2 8
23 14 6
23 21 6
23 28 6
19 40 8
8 42 8
0 39 5
11
0 0 5
8 0 5
18 8 10
8 16 5
0 16 5
0 24 5
3 32 5
10 32 5
17 28 8
27 25 3
30 18 5
0

Output for the Sample Input

58.953437
11.414214
16.0
61.874812
63.195179

Example

Input

10
802 0 10
814 0 4
820 1 4
826 1 4
832 3 5
838 5 5
845 7 3
849 10 3
853 14 4
857 18 3
3
0 0 5
8 0 5
8 8 5
3
0 0 5
7 3 6
16 0 5
9
0 3 5
8 0 8
19 2 8
23 14 6
23 21 6
23 28 6
19 40 8
8 42 8
0 39 5
11
0 0 5
8 0 5
18 8 10
8 16 5
0 16 5
0 24 5
3 32 5
10 32 5
17 28 8
27 25 3
30 18 5
0

Output

58.953437
11.414214
16.0
61.874812
63.195179

### Response

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

// 2D geometry basic //
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
#define X real
#define Y imag
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};
typedef vector<P> G;
struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
};
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

// UVA 453 (Intersecting Circles)
pair<P, P> circle_circle_intersect(const P& c1, const double& r1, const P& c2, const double& r2) {
  P A = conj(c2-c1), B = (r2*r2-r1*r1-(c2-c1)*conj(c2-c1)), C = r1*r1*(c2-c1);
  P D = B*B-4.0*A*C;
  P z1 = (-B+sqrt(D))/(2.0*A)+c1, z2 = (-B-sqrt(D))/(2.0*A)+c1;
  return pair<P, P>(z1, z2);
}

//////////
// data //
//////////

struct E{
  int n1,n2;
  double l;
};
bool operator<(E a,E b){
  return a.l>b.l;
}
vector<C> in;
vector<vector<P>> node;
vector<vector<vector<E>>> edge;

void init(){
  in.clear();
  node.clear();
  edge.clear();
}

bool input(){
  int n;
  cin>>n;
  if(n==0)return false;
  for(int i=0;i<n;i++){
    double x,y,r;
    cin>>x>>y>>r;
    in.push_back(C(P(x,y),r));
  }
  return true;
}

double dist(int a,int b,int n,int m){
  const P tmp = node[a][b]-node[n][m];
  return sqrt(tmp.X()*tmp.X() + tmp.Y()*tmp.Y());
}
bool valid(int a,int b,int n,int m){
  P vec = node[n][m] - node[a][b];
  for(int i=a+1;i<n;i++){
    int tmpa = ccw(node[a][b],node[n][m],node[i][0]);
    int tmpb = ccw(node[a][b],node[n][m],node[i][1]);
    if(!(abs(tmpa)==1 && tmpa==(-1*tmpb))){
      return false;
    }
  }
  return true;
}
void set_edge(int n,int m){
  for(int i=0;i<n;i++){
    for(int j=0;j<node[i].size();j++){
      if(valid(i,j,n,m)){
        edge[i][j].push_back(E{n,m,dist(i,j,n,m)});
      }
    }
  }
}

void make_g(){
  //make_node;
  node.resize(in.size()+1);
  node[0].push_back(in[0].p);
  for(int i=1;i<in.size();i++){
    auto tmp = circle_circle_intersect(in[i-1].p,in[i-1].r,in[i].p,in[i].r);
    node[i].push_back(tmp.first);
    node[i].push_back(tmp.second);
  }
  node[in.size()].push_back(in[in.size()-1].p);
  //meke_edge
  edge.resize(node.size());
  for(int i=0;i<node.size();i++){
    edge[i].resize(node[i].size());
    for(int j=0;j<node[i].size();j++){
      set_edge(i,j);
    }
  }

  for(int i=0;i<edge.size();i++){
    for(int j=0;j<edge[i].size();j++){
      //cerr<<"node:"<<i<<","<<j<<endl;
      for(int k=0;k<edge[i][j].size();k++){
        //cerr<<"  "<<edge[i][j][k].n1<<","<<edge[i][j][k].n2<<" "<<edge[i][j][k].l<<endl;
      }
    }
  }
}

double solve_dist(){
  priority_queue<E> q;
  q.push(E{0,0,0});
  vector<vector<double>> dp(node.size());
  for(int i=0;i<dp.size();i++){
    dp[i] = vector<double>(node[i].size(),-1);
  }
  while(!q.empty()){
    E now = q.top();q.pop();
    if(dp[now.n1][now.n2]!=-1)continue;
    dp[now.n1][now.n2] = now.l;
    const auto e = edge[now.n1][now.n2];
    for(int i=0;i<e.size();i++){
      q.push(E{e[i].n1,e[i].n2,now.l+e[i].l});
    }
  }
  for(int i=0;i<dp.size();i++){
    for(int j=0;j<dp[i].size();j++){
      //cerr<<"("<<i<<","<<j<<")::"<<dp[i][j]<<endl;
    }
  }
  return dp[node.size()-1][node[node.size()-1].size()-1];
}

long double solve(){
  make_g();
  return solve_dist();
}

int main(){
  while(init(),input()){
    cout<<fixed<<setprecision(10)<<solve()<<endl;
  }
}
```


### Prompt

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

On the Berland Dependence Day it was decided to organize a great marathon. Berland consists of n cities, some of which are linked by two-way roads. Each road has a certain length. The cities are numbered from 1 to n. It is known that one can get from any city to any other one by the roads.

n runners take part in the competition, one from each city. But Berland runners are talkative by nature and that's why the juries took measures to avoid large crowds of marathon participants. The jury decided that every runner should start the marathon from their hometown. Before the start every sportsman will get a piece of paper containing the name of the city where the sportsman's finishing line is. The finish is chosen randomly for every sportsman but it can't coincide with the sportsman's starting point. Several sportsmen are allowed to finish in one and the same city. All the sportsmen start simultaneously and everyone runs the shortest route from the starting point to the finishing one. All the sportsmen run at one speed which equals to 1.

After the competition a follow-up table of the results will be composed where the sportsmen will be sorted according to the nondecrease of time they spent to cover the distance. The first g sportsmen in the table will get golden medals, the next s sportsmen will get silver medals and the rest will get bronze medals. Besides, if two or more sportsmen spend the same amount of time to cover the distance, they are sorted according to the number of the city where a sportsman started to run in the ascending order. That means no two sportsmen share one and the same place.

According to the rules of the competition the number of gold medals g must satisfy the inequation g1 ≤ g ≤ g2, where g1 and g2 are values formed historically. In a similar way, the number of silver medals s must satisfy the inequation s1 ≤ s ≤ s2, where s1 and s2 are also values formed historically.

At present, before the start of the competition, the destination points of every sportsman are unknown. However, the press demands details and that's why you are given the task of counting the number of the ways to distribute the medals. Two ways to distribute the medals are considered different if at least one sportsman could have received during those distributions different kinds of medals.

Input

The first input line contains given integers n and m (3 ≤ n ≤ 50, n - 1 ≤ m ≤ 1000), where n is the number of Berland towns and m is the number of roads.

Next in m lines road descriptions are given as groups of three integers v, u, c, which are the numbers of linked towns and its length (1 ≤ v, u ≤ n, v ≠ u, 1 ≤ c ≤ 1000). Every pair of cities have no more than one road between them.

The last line contains integers g1, g2, s1, s2 (1 ≤ g1 ≤ g2, 1 ≤ s1 ≤ s2, g2 + s2 < n). The input data numbers, located on one line, are space-separated.

Output

Print the single number — the number of ways to distribute the medals. It is guaranteed that the number fits in the standard 64-bit signed data type.

Examples

Input

3 2
1 2 1
2 3 1
1 1 1 1

Output

3

Input

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

Output

19

Input

3 3
1 2 2
2 3 1
3 1 2
1 1 1 1

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 100000;
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int> > G(n, vector<int>(n, INF));
  for (int i = 0; i < n; ++i) G[i][i] = 0;
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    G[a][b] = c;
    G[b][a] = c;
  }
  int g1, g2, s1, s2;
  cin >> g1 >> g2 >> s1 >> s2;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      for (int k = 0; k < n; ++k) G[j][k] = min(G[j][k], G[j][i] + G[i][k]);
  vector<int> mini(n, INF), maxi(n, -INF);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (j != i) {
        mini[i] = min(mini[i], G[i][j]);
        maxi[i] = max(maxi[i], G[i][j]);
      }
    }
  }
  long long odp = 0;
  for (int g = 0; g < n; ++g) {
    for (int b = 0; b < n; ++b) {
      if (mini[g] < maxi[b] || (mini[g] == maxi[b] && g < b)) {
        vector<bool> srodek(n, false);
        for (int s = 0; s < n; ++s)
          if (s != g && s != b)
            for (int i = 0; i < n; ++i)
              if (i != s &&
                  (G[s][i] > mini[g] || (G[s][i] == mini[g] && s > g)) &&
                  (G[s][i] < maxi[b] || (G[s][i] == maxi[b] && s < b)))
                srodek[s] = true;
        long long dp[50][51][51];
        for (int i = 0; i < 50; ++i)
          for (int j = 0; j < 51; ++j)
            for (int k = 0; k < 51; ++k) dp[i][j][k] = 0;
        if (0 != b && (mini[0] < mini[g] || (mini[0] == mini[g] && 0 <= g)))
          dp[0][1][0] = 1;
        if (0 != b && 0 != g && srodek[0]) dp[0][0][0] = 1;
        if (0 != g && (maxi[0] > maxi[b] || (maxi[0] == maxi[b] && 0 >= b)))
          dp[0][0][1] = 1;
        for (int i = 0; i < n - 1; ++i) {
          for (int j = 0; j <= i + 1; ++j) {
            for (int k = 0; k <= i + 1; ++k) {
              if (i + 1 != b && (mini[i + 1] < mini[g] ||
                                 (mini[i + 1] == mini[g] && i + 1 <= g)))
                dp[i + 1][j + 1][k] += dp[i][j][k];
              if (i + 1 != b && i + 1 != b && srodek[i + 1])
                dp[i + 1][j][k] += dp[i][j][k];
              if (i + 1 != g && (maxi[i + 1] > maxi[b] ||
                                 (maxi[i + 1] == maxi[b] && i + 1 >= b)))
                dp[i + 1][j][k + 1] += dp[i][j][k];
            }
          }
        }
        for (int i = g1; i <= g2; ++i)
          for (int j = s1; j <= s2; ++j) odp += dp[n - 1][i][n - i - j];
      }
    }
  }
  cout << odp;
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Write a program which calculates the area and circumference of a circle for given radius r.

Constraints

* 0 < r < 10000

Input

A real number r is given.

Output

Print the area and circumference of the circle in a line. Put a single space between them. The output should not contain an absolute error greater than 10-5.

Examples

Input

2

Output

12.566371 12.566371

Input

3

Output

28.274334 18.849556

### Response

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

int main(){
double a;
cin>>a;
cout<<fixed<<a*a*3.141592653589<<' '<<a*2*3.141592653589<<'\n';
return 0;
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

N people are waiting in a single line in front of the Takahashi Store. The cash on hand of the i-th person from the front of the line is a positive integer A_i.

Mr. Takahashi, the shop owner, has decided on the following scheme: He picks a product, sets a positive integer P indicating its price, and shows this product to customers in order, starting from the front of the line. This step is repeated as described below.

At each step, when a product is shown to a customer, if price P is equal to or less than the cash held by that customer at the time, the customer buys the product and Mr. Takahashi ends the current step. That is, the cash held by the first customer in line with cash equal to or greater than P decreases by P, and the next step begins.

Mr. Takahashi can set the value of positive integer P independently at each step.

He would like to sell as many products as possible. However, if a customer were to end up with 0 cash on hand after a purchase, that person would not have the fare to go home. Customers not being able to go home would be a problem for Mr. Takahashi, so he does not want anyone to end up with 0 cash.

Help out Mr. Takahashi by writing a program that determines the maximum number of products he can sell, when the initial cash in possession of each customer is given.

Constraints

* 1 ≦ | N | ≦ 100000
* 1 ≦ A_i ≦ 10^9(1 ≦ i ≦ N)
* All inputs are integers.

Input

Inputs are provided from Standard Inputs in the following form.

N
A_1
:
A_N

Output

Output an integer representing the maximum number of products Mr. Takahashi can sell.

Examples

Input

3
3
2
5

Output

3

Input

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

Output

18

### Response

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

int main(void){
	long i,n,min=1,ans=0,a;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a;
		if(a==min){
			min++;
			continue;
		}
		ans+=(a-1)/min;
if(i==0) min++;
	}
	cout << ans;
	return 0;
}
```


### Prompt

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

Petya has n integers: 1, 2, 3, ..., n. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.

Help Petya to split the integers. Each of n integers should be exactly in one group.

Input

The first line contains a single integer n (2 ≤ n ≤ 60 000) — the number of integers Petya has.

Output

Print the smallest possible absolute difference in the first line.

In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.

Examples

Input

4

Output

0
2 1 4

Input

2

Output

1
1 1

Note

In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.

In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, j, k, l, sum = 0, t;
  cin >> n;
  sum = (n * (n + 1)) / 2;
  t = ceil(n / 2.0);
  if (sum % 2 == 0) {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }
  long long int cnt = 0, p = 1, fc = 0;
  vector<long long int> v;
  for (i = n - 1; i > 0; i--) {
    if (cnt < 2 && p == 1) {
      cnt++;
      v.push_back(i);
      fc++;
    } else if (cnt == 2 && p == 1) {
      cnt = 0;
      p = 0;
    }
    if (cnt < 2 && p == 0) {
      cnt++;
      if (cnt == 2) {
        cnt = 0;
        p = 1;
      }
    }
  }
  cout << fc << " ";
  for (i = 0; i < fc; i++) {
    cout << v[i] << " ";
  }
}

```


### Prompt

Create a solution in Cpp for the following problem:

Phoenix is playing with a new puzzle, which consists of n identical puzzle pieces. Each puzzle piece is a right isosceles triangle as shown below.

<image> A puzzle piece

The goal of the puzzle is to create a square using the n pieces. He is allowed to rotate and move the pieces around, but none of them can overlap and all n pieces must be used (of course, the square shouldn't contain any holes as well). Can he do it?

Input

The input consists of multiple test cases. The first line contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases.

The first line of each test case contains an integer n (1 ≤ n ≤ 10^9) — the number of puzzle pieces.

Output

For each test case, if Phoenix can create a square with the n puzzle pieces, print YES. Otherwise, print NO.

Example

Input

3
2
4
6

Output

YES
YES
NO

Note

For n=2, Phoenix can create a square like this:

<image>

For n=4, Phoenix can create a square like this:

<image>

For n=6, it is impossible for Phoenix to create a square.

### Response

```cpp
#include<iostream>
#include <math.h>
using namespace std;
 bool issquare(long int num)
 {
     long int sqrtnum=sqrt(num);
     if(num==(sqrtnum*sqrtnum))
     {
         return true;
     }
     else{
         return false;
     }
 }
 int main()
{
int t;
cin>>t;

for(int i=0;i<t;i++)
{
    int flag=0;
    long int n;
cin>>n;
if(n%2==0)
{
    long int k=n/2;
    if(issquare(k))
        flag=1;
}
if(flag==0)
{
    if(n%4==0)
    {
        long int l=n/4;
        if(issquare(l))
        flag=1;
    }
}
if(flag==1)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}
```


### Prompt

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

You are given a permutation of integers from 1 to n. Exactly once you apply the following operation to this permutation: pick a random segment and shuffle its elements. Formally:

  1. Pick a random segment (continuous subsequence) from l to r. All <image> segments are equiprobable.
  2. Let k = r - l + 1, i.e. the length of the chosen segment. Pick a random permutation of integers from 1 to k, p1, p2, ..., pk. All k! permutation are equiprobable.
  3. This permutation is applied to elements of the chosen segment, i.e. permutation a1, a2, ..., al - 1, al, al + 1, ..., ar - 1, ar, ar + 1, ..., an is transformed to a1, a2, ..., al - 1, al - 1 + p1, al - 1 + p2, ..., al - 1 + pk - 1, al - 1 + pk, ar + 1, ..., an.

Inversion if a pair of elements (not necessary neighbouring) with the wrong relative order. In other words, the number of inversion is equal to the number of pairs (i, j) such that i < j and ai > aj. Find the expected number of inversions after we apply exactly one operation mentioned above.

Input

The first line contains a single integer n (1 ≤ n ≤ 100 000) — the length of the permutation.

The second line contains n distinct integers from 1 to n — elements of the permutation.

Output

Print one real value — the expected number of inversions. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 9.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.

Example

Input

3
2 3 1

Output

1.916666666666666666666666666667

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 5;
int a[maxn];
long long tree[maxn];
int n;
void add(int x, int y) {
  for (int i = x; i <= n; i += (i & (-i))) tree[i] += y;
}
long long get(int x) {
  long long ret = 0;
  for (int i = x; i; i -= i & (-i)) ret += tree[i];
  return ret;
}
int main() {
  scanf("%d", &n);
  double ans = 0;
  double tmp = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    long long cnt = (i - get(a[i]));
    ans += cnt;
    add(a[i], 1);
    long long l = i + 1;
    tmp += (l * (l - 1) * (n - l + 1) / 4.0);
  }
  for (int i = 1; i <= n; i++) tree[i] = 0;
  for (int i = 0; i < n; i++) {
    long long cnt = get(n) - get(a[i]);
    tmp -= cnt * (n - i);
    add(a[i], i + 1);
  }
  tmp = tmp / (1.0 * n * (n + 1) / 2);
  printf("%.11lf\n", ans + tmp);
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

The Little Elephant loves strings very much.

He has an array a from n strings, consisting of lowercase English letters. Let's number the elements of the array from 1 to n, then let's denote the element number i as ai. For each string ai (1 ≤ i ≤ n) the Little Elephant wants to find the number of pairs of integers l and r (1 ≤ l ≤ r ≤ |ai|) such that substring ai[l... r] is a substring to at least k strings from array a (including the i-th string).

Help the Little Elephant solve this problem.

If you are not familiar with the basic notation in string problems, you can find the corresponding definitions in the notes.

Input

The first line contains two space-separated integers — n and k (1 ≤ n, k ≤ 105). Next n lines contain array a. The i-th line contains a non-empty string ai, consisting of lowercase English letter. The total length of all strings ai does not exceed 105.

Output

On a single line print n space-separated integers — the i-th number is the answer for string ai.

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

Examples

Input

3 1
abc
a
ab

Output

6 1 3

Input

7 4
rubik
furik
abab
baba
aaabbbababa
abababababa
zero

Output

1 0 9 9 21 30 0

Note

Let's assume that you are given string a = a1a2... a|a|, then let's denote the string's length as |a| and the string's i-th character as ai.

A substring a[l... r] (1 ≤ l ≤ r ≤ |a|) of string a is string alal + 1... ar.

String a is a substring of string b, if there exists such pair of integers l and r (1 ≤ l ≤ r ≤ |b|), that b[l... r] = a.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n, m, K, lg[maxn], sa[maxn], st[maxn], ed[maxn], bel[maxn], num[maxn],
    cnt[maxn];
int tmp[maxn], rk[maxn], ht[maxn], a[maxn], buc[maxn], fir[maxn], sec[maxn],
    f[maxn][20];
char str[maxn], s[maxn];
void build_sa(int n) {
  copy(s + 1, s + n + 1, num + 1);
  sort(num + 1, num + n + 1);
  int *end = unique(num + 1, num + n + 1);
  for (int i = 1; i <= n; i++) a[i] = lower_bound(num + 1, end, s[i]) - num;
  memset(buc, 0, sizeof(buc));
  for (int i = 1; i <= n; i++) buc[a[i]]++;
  for (int i = 1; i <= n; i++) buc[i] += buc[i - 1];
  for (int i = 1; i <= n; i++) rk[i] = buc[a[i] - 1] + 1;
  for (int k = 1; k <= n; k <<= 1) {
    for (int i = 1; i <= n; i++) fir[i] = rk[i];
    for (int i = 1; i <= n; i++) sec[i] = i + k > n ? 0 : rk[i + k];
    memset(buc, 0, sizeof(buc));
    for (int i = 1; i <= n; i++) buc[sec[i]]++;
    for (int i = 1; i <= n; i++) buc[i] += buc[i - 1];
    for (int i = 1; i <= n; i++) tmp[n - --buc[sec[i]]] = i;
    memset(buc, 0, sizeof(buc));
    for (int i = 1; i <= n; i++) buc[fir[i]]++;
    for (int i = 1; i <= n; i++) buc[i] += buc[i - 1];
    for (int i = 1; i <= n; i++) sa[buc[fir[tmp[i]]]--] = tmp[i];
    bool unique = true;
    rk[sa[1]] = 1;
    for (int i = 1; i <= n; i++) {
      rk[sa[i]] = rk[sa[i - 1]];
      if (fir[sa[i]] == fir[sa[i - 1]] && sec[sa[i]] == sec[sa[i - 1]])
        unique = false;
      else
        rk[sa[i]]++;
    }
    if (unique) break;
  }
  for (int i = 1, k = 0; i <= n; i++) {
    if (k) k--;
    int j = sa[rk[i] - 1];
    while (i + k <= n && j + k <= n && a[i + k] == a[j + k]) k++;
    ht[rk[i]] = k;
  }
  for (int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;
  for (int i = 1; i <= n; i++) f[i][0] = ht[i];
  for (int j = 1; j <= lg[n]; j++) {
    for (int i = 1; i + (1 << j) - 1 <= n; i++) {
      f[i][j] = min(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
    }
  }
}
int lcp(int x, int y) {
  int k = lg[y - x + 1];
  return min(f[x][k], f[y - (1 << k) + 1][k]);
}
bool check(int x, int y) {
  int p, q, l, r;
  if (ht[x + 1] < y)
    q = x;
  else {
    l = x + 1, r = m;
    while (l <= r) {
      int mid = (l + r) >> 1;
      lcp(x + 1, mid) >= y ? l = mid + 1 : r = mid - 1;
    }
    q = r;
  }
  if (ht[x] < y)
    p = x;
  else {
    l = 1, r = x - 1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      lcp(mid + 1, x) >= y ? r = mid - 1 : l = mid + 1;
    }
    p = l;
  }
  return num[q] >= p;
}
int main() {
  scanf("%d %d", &n, &K);
  for (int i = 1; i <= n; i++) {
    scanf("%s", str), st[i] = m + 1;
    for (int j = 0; str[j]; j++) bel[++m] = i, s[m] = str[j];
    ed[i] = m, s[++m] = ' ';
  }
  build_sa(m);
  memset(num, 0, sizeof(num));
  for (int i = 1, j = 0, k = 1; i <= m; i++) {
    if (!bel[sa[i]]) continue;
    if (!cnt[bel[sa[i]]]++) j++;
    if (j >= K) {
      for (; j - (cnt[bel[sa[k]]] == 1) >= K; j -= !--(cnt[bel[sa[k++]]]))
        ;
      num[i] = k;
    }
  }
  for (int i = 1; i <= n; i++) {
    long long ans = 0;
    for (int j = st[i], k = 0; j <= ed[i]; j++) {
      for (k ? k-- : 0; k <= ed[i] - j && check(rk[j], k + 1); k++)
        ;
      ans += k;
    }
    printf("%lld ", ans);
  }
  return 0;
}

```