### Prompt

Develop a solution in Cpp to the problem described below:

Zibi is a competitive programming coach. There are n competitors who want to be prepared well. The training contests are quite unusual – there are two people in a team, two problems, and each competitor will code exactly one of them. Of course, people in one team will code different problems.

Rules of scoring also aren't typical. The first problem is always an implementation problem: you have to implement some well-known algorithm very fast and the time of your typing is rated. The second one is an awful geometry task and you just have to get it accepted in reasonable time. Here the length and difficulty of your code are important. After that, Zibi will give some penalty points (possibly negative) for each solution and the final score of the team is the sum of them (the less the score is, the better).

We know that the i-th competitor will always have score x_i when he codes the first task and y_i when he codes the second task. We can assume, that all competitors know each other's skills and during the contest distribute the problems in the way that minimizes their final score. Remember that each person codes exactly one problem in a contest.

Zibi wants all competitors to write a contest with each other. However, there are m pairs of people who really don't like to cooperate and they definitely won't write a contest together. Still, the coach is going to conduct trainings for all possible pairs of people, such that the people in pair don't hate each other. The coach is interested for each participant, what will be his or her sum of scores of all teams he trained in?

Input

The first line contains two integers n and m (2 ≤ n ≤ 300 000, 0 ≤ m ≤ 300 000) — the number of participants and the number of pairs of people who will not write a contest together.

Each of the next n lines contains two integers x_i and y_i (-10^9 ≤ x_i, y_i ≤ 10^9) — the scores which will the i-th competitor get on the first problem and on the second problem. It is guaranteed that there are no two people having both x_i and y_i same.

Each of the next m lines contain two integers u_i and v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i) — indices of people who don't want to write a contest in one team. Each unordered pair of indices will appear at most once.

Output

Output n integers — the sum of scores for all participants in the same order as they appear in the input.

Examples

Input

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

Output

3 0 3

Input

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

Output

0 0 0

Input

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

Output

4 14 4 16 10

Note

In the first example, there will be only one team consisting of persons 1 and 3. The optimal strategy for them is to assign the first task to the 3-rd person and the second task to the 1-st person, this will lead to score equal to 1 + 2 = 3.

In the second example, nobody likes anyone, so there won't be any trainings. It seems that Zibi won't be titled coach in that case...

### Response

```cpp
#include <bits/stdc++.h>
const long long inf = 0x3f3f3f3f3f3f3f3LL;
const long long mod = (long long)1e9 + 7;
using namespace std;
template <class T, class T2>
void smin(T& a, T2 val) {
  if (a > val) a = val;
}
template <class T, class T2>
void smax(T& a, T2 val) {
  if (a < val) a = val;
}
const long long N = 5 * (long long)1e5 + 10;
long long n, x[N], y[N], m;
vector<long long> v[N];
vector<long long> p;
long long pref_x[N], suff_y[N], ans[N];
vector<array<long long, 2>> edge;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (long long i = 1; i <= n; ++i) {
    cin >> x[i] >> y[i];
    p.push_back(i);
  }
  for (long long i = 0; i < m; ++i) {
    long long x, y;
    cin >> x >> y;
    edge.push_back({x, y});
  }
  sort(p.begin(), p.end(),
       [&](long long i, long long j) { return x[i] - y[i] < x[j] - y[j]; });
  for (long long i = 1; i <= n; ++i) {
    pref_x[i] = pref_x[i - 1];
    long long idx = p[i - 1];
    pref_x[i] += x[idx];
  }
  for (long long i = n; i >= 1; --i) {
    suff_y[i] = suff_y[i + 1];
    long long idx = p[i - 1];
    suff_y[i] += y[idx];
  }
  for (long long i = 1; i <= n; ++i) {
    long long idx = p[i - 1];
    ans[idx] = suff_y[i + 1] + x[idx] * (n - i);
    ans[idx] += pref_x[i - 1] + y[idx] * (i - 1);
  }
  for (auto& it : edge) {
    long long idx1 = it[0], idx2 = it[1];
    long long minn = min(x[idx1] + y[idx2], x[idx2] + y[idx1]);
    ans[idx1] -= minn;
    ans[idx2] -= minn;
  }
  for (long long i = 1; i <= n; ++i) {
    cout << ans[i] << " ";
  }
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem.

You are given a binary table of size n × m. This table consists of symbols 0 and 1.

You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0).

Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations.

It can be proved that it is always possible.

Input

The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases.

The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100).

Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table.

It is guaranteed that the sum of nm for all test cases does not exceed 20000.

Output

For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations.

In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square.

Example

Input

5
2 2
10
11
3 3
011
101
110
4 4
1111
0110
0110
1111
5 5
01011
11001
00010
11011
10000
2 3
011
101

Output

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

Note

In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0.

In the second test case:

  * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be:

    011
    001
    000

  * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be:

    000
    000
    000

In the fifth test case:

  * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be:

    010
    110

  * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be:

    000
    000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void start() {}
vector<pair<long long, long long>> v, v1;
void one(char x, char y, char z, char w, long long i, long long j) {
  if (x == '1') {
    v.push_back({i + 1, j + 1});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 2});
    v.push_back({i + 1, j + 1});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 1, j + 1});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 2, j + 2});
  } else if (y == '1') {
    v.push_back({i + 1, j + 1});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 2});
    v.push_back({i + 1, j + 1});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 2, j + 2});
  } else if (z == '1') {
    v.push_back({i + 1, j + 1});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 2, j + 2});
    v.push_back({i + 1, j + 1});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 2, j + 2});
  } else {
    v.push_back({i + 1, j + 1});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 2, j + 2});
    v.push_back({i + 2, j + 2});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 1, j + 1});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 2});
  }
}
void two(char x, char y, char z, char w, long long i, long long j) {
  if (x == '1' && y == '1') {
    v.push_back({i + 2, j + 2});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 1, j + 1});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 2, j + 2});
  } else if (x == '1' && z == '1') {
    v.push_back({i + 2, j + 2});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 1, j + 1});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 2});
  } else if (x == '1' && w == '1') {
    v.push_back({i + 2, j + 2});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 1, j + 1});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 1, j + 2});
  } else if (y == '1' && z == '1') {
    v.push_back({i + 2, j + 2});
    v.push_back({i + 1, j + 1});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 1, j + 1});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 2});
  } else if (y == '1' && w == '1') {
    v.push_back({i + 2, j + 2});
    v.push_back({i + 1, j + 1});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 1, j + 1});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 1, j + 2});
  } else if (z == '1' && w == '1') {
    v.push_back({i + 2, j + 2});
    v.push_back({i + 1, j + 1});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 1, j + 1});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 1, j + 2});
  }
}
void three(char x, char y, char z, char w, long long i, long long j) {
  if (x == '0') {
    v.push_back({i + 2, j + 2});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 1, j + 2});
  } else if (y == '0') {
    v.push_back({i + 2, j + 2});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 1, j + 1});
  } else if (z == '0') {
    v.push_back({i + 2, j + 2});
    v.push_back({i + 1, j + 1});
    v.push_back({i + 1, j + 2});
  } else if (w == '0') {
    v.push_back({i + 1, j + 1});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 1, j + 2});
  }
}
void four(char x, char y, char z, char w, long long i, long long j) {
  v.push_back({i + 2, j + 2});
  v.push_back({i + 2, j + 1});
  v.push_back({i + 1, j + 2});
  one('1', '0', '0', '0', i, j);
}
void fn(char x, char y, char z, char w, long long i, long long j) {
  long long cal = (x - '0') + (y - '0') + (z - '0') + (w - '0');
  if (cal == 0) return;
  if (cal == 1) one(x, y, z, w, i, j);
  if (cal == 2) two(x, y, z, w, i, j);
  if (cal == 3) three(x, y, z, w, i, j);
  if (cal == 4) four(x, y, z, w, i, j);
}
void fn1(char x, char y, long long i, long long j) {
  if (x == '1' && y == '1') {
    v.push_back({i + 1, j + 1});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 2});
  } else if (x == '0' && y == '1') {
    v.push_back({i + 2, j + 1});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 2});
  } else if (x == '1' && y == '0') {
    v.push_back({i + 1, j + 1});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 2, j + 2});
  } else
    return;
}
void fn2(char x, char y, long long i, long long j) {
  if (x == '1' && y == '1') {
    v.push_back({i + 1, j + 1});
    v.push_back({i + 2, j + 1});
    v.push_back({i + 2, j + 2});
  } else if (x == '0' && y == '1') {
    v.push_back({i + 2, j + 1});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 2});
  } else if (x == '1' && y == '0') {
    v.push_back({i + 1, j + 1});
    v.push_back({i + 1, j + 2});
    v.push_back({i + 2, j + 2});
  } else
    return;
}
char up(char x) {
  if (x == '0')
    return '1';
  else
    return '0';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    v.clear();
    v1.clear();
    long long n, m;
    cin >> n >> m;
    string s[n], s1[n], s2[n];
    long long c = 0;
    for (long long i = 0; i < n; i++) {
      cin >> s[i];
    }
    for (long long i = 0; i < n - 2; i++) {
      for (long long j = 0; j < m; j++) {
        if (s[i][j] == '1') {
          if (j == m - 1) {
            v.push_back({i + 1, j + 1});
            v.push_back({i + 2, j});
            v.push_back({i + 2, j + 1});
            s[i][j] = up(s[i][j]);
            s[i + 1][j - 1] = up(s[i + 1][j - 1]);
            s[i + 1][j] = up(s[i + 1][j]);
            continue;
          }
          if (s[i][j] == '0' && s[i][j + 1] == '0') {
            continue;
          } else if (s[i][j] == '1' && s[i][j + 1] == '1') {
            s[i + 1][j + 1] = up(s[i + 1][j + 1]);
          } else {
            s[i + 1][j] = up(s[i + 1][j]);
            s[i + 1][j + 1] = up(s[i + 1][j + 1]);
          }
          fn1(s[i][j], s[i][j + 1], i, j);
          s[i][j] = '0';
          s[i][j + 1] = '0';
        }
      }
    }
    for (long long j = 0; j < m - 1; j++) {
      if (s[n - 2][j] == '0' && s[n - 1][j] == '0') {
        continue;
      } else if (s[n - 2][j] == '1' && s[n - 1][j] == '1') {
        s[n - 1][j + 1] = (((s[n - 1][j + 1] - '0') ^ 1) + '0');
      } else {
        s[n - 2][j + 1] = (((s[n - 2][j + 1] - '0') ^ 1) + '0');
        s[n - 1][j + 1] = (((s[n - 1][j + 1] - '0') ^ 1) + '0');
      }
      fn2(s[n - 2][j], s[n - 1][j], n - 2, j);
      s[n - 2][j] = '0';
      s[n - 1][j] = '0';
    }
    fn(s[n - 2][m - 2], s[n - 2][m - 1], s[n - 1][m - 2], s[n - 1][m - 1],
       n - 2, m - 2);
    cout << v.size() / 3 << endl;
    for (long long i = 0; i < v.size(); i += 3)
      cout << v[i].first << ' ' << v[i].second << ' ' << v[i + 1].first << ' '
           << v[i + 1].second << ' ' << v[i + 2].first << ' ' << v[i + 2].second
           << endl;
  }
}

```


### Prompt

Please create a solution in CPP to the following problem:

You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.

We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.

The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.

Given the list of points, print the indices of the good points in ascending order.

Input

The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.

The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.

Output

First, print a single integer k — the number of good points.

Then, print k integers, each on their own line — the indices of the good points in ascending order.

Examples

Input

6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1

Output

1
1

Input

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

Output

0

Note

In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.

In the second sample, along the cd plane, we can see the points look as follows:

<image>

We can see that all angles here are acute, so no points are good.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a[12][6], ans[12], cnt;
bool check(int x, int p, int q) {
  int tot = 0;
  for (int i = 1; i <= 5; i++)
    tot = tot + (a[p][i] - a[x][i]) * (a[q][i] - a[x][i]);
  if (tot <= 0)
    return 1;
  else
    return 0;
}
int main() {
  cin >> n;
  if (n > 32) {
    cout << 0;
    return 0;
  };
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 5; j++) cin >> a[i][j];
  for (int k = 1; k <= n; k++) {
    bool flag = 0;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        if (i == j || j == k || i == k || flag) continue;
        if (!check(k, i, j)) flag = 1;
      }
    if (!flag) {
      cnt++;
      ans[cnt] = k;
    }
  }
  cout << cnt << endl;
  for (int i = 1; i <= cnt; i++) cout << ans[i] << endl;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.

<image>

There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.

Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.

Input

The first line of input contains integer n (1 ≤ n ≤ 105), the number of days.

In the next n lines, i-th line contains two integers ai and pi (1 ≤ ai, pi ≤ 100), the amount of meat Duff needs and the cost of meat in that day.

Output

Print the minimum money needed to keep Duff happy for n days, in one line.

Examples

Input

3
1 3
2 2
3 1

Output

10

Input

3
1 3
2 1
3 2

Output

8

Note

In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.

In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[100002], p[100002];
int main() {
  ios_base::sync_with_stdio(false);
  int n, mincost = 100000;
  long long int cost = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cin >> p[i];
  }
  for (int i = 0; i < n; i++) {
    if (p[i] < mincost) {
      mincost = p[i];
    }
    cost = cost + (a[i] * mincost);
  }
  cout << cost;
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied:

* The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.

Find all favorite numbers and print the sum of those.

Constraints

* All values in input are integers.
* 1 \leq N \leq 10^{12}

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Examples

Input

8

Output

10

Input

1000000000000

Output

2499686339916

### Response

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

int main()
{
long long N;
cin>>N;
long long ans=0;
for(long long i=2;i*i<=N;i++)
{
	if(N%i==0)
	{

		if(N/(i-1)==N%(i-1))ans+=i-1;

		if(N/((N/i)-1)==N%((N/i)-1))ans+=N/i-1;
		}
	}
	if(N!=2)
	ans+=N-1;
	cout<<ans;
}

```


### Prompt

Generate a cpp solution to the following problem:

Nearly each project of the F company has a whole team of developers working on it. They often are in different rooms of the office in different cities and even countries. To keep in touch and track the results of the project, the F company conducts shared online meetings in a Spyke chat.

One day the director of the F company got hold of the records of a part of an online meeting of one successful team. The director watched the record and wanted to talk to the team leader. But how can he tell who the leader is? The director logically supposed that the leader is the person who is present at any conversation during a chat meeting. In other words, if at some moment of time at least one person is present on the meeting, then the leader is present on the meeting.

You are the assistant director. Given the 'user logged on'/'user logged off' messages of the meeting in the chronological order, help the director determine who can be the leader. Note that the director has the record of only a continuous part of the meeting (probably, it's not the whole meeting).

Input

The first line contains integers n and m (1 ≤ n, m ≤ 105) — the number of team participants and the number of messages. Each of the next m lines contains a message in the format:

  * '+ id': the record means that the person with number id (1 ≤ id ≤ n) has logged on to the meeting.
  * '- id': the record means that the person with number id (1 ≤ id ≤ n) has logged off from the meeting.

Assume that all the people of the team are numbered from 1 to n and the messages are given in the chronological order. It is guaranteed that the given sequence is the correct record of a continuous part of the meeting. It is guaranteed that no two log on/log off events occurred simultaneously.

Output

In the first line print integer k (0 ≤ k ≤ n) — how many people can be leaders. In the next line, print k integers in the increasing order — the numbers of the people who can be leaders.

If the data is such that no member of the team can be a leader, print a single number 0.

Examples

Input

5 4
+ 1
+ 2
- 2
- 1

Output

4
1 3 4 5

Input

3 2
+ 1
- 2

Output

1
3

Input

2 4
+ 1
- 1
+ 2
- 2

Output

0

Input

5 6
+ 1
- 1
- 3
+ 3
+ 4
- 4

Output

3
2 3 5

Input

2 4
+ 1
- 2
+ 2
- 1

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
set<int> tp;
vector<pair<char, int> > vec;
set<int> s;
int n, m;
int find(int index) {
  for (vector<pair<char, int> >::iterator itr = vec.begin(); itr != vec.end();
       itr++) {
    if (itr->first == '-')
      tp.erase(itr->second);
    else
      tp.insert(itr->second);
    if (tp.size() > 0 && tp.find(index) == tp.end()) {
      return 0;
    }
  }
  return 1;
}
int main() {
  cin >> n >> m;
  int tmp;
  char ch;
  int vis[n + 1];
  int new_i = -1;
  for (int i = 0; i <= n; i++) vis[i] = 0;
  for (int i = 0; i < m; i++) {
    cin >> ch >> tmp;
    if (ch == '-' && vis[tmp] == 0) {
      new_i = i;
      tp.insert(tmp);
    }
    vis[tmp] = 1;
    vec.push_back(make_pair(ch, tmp));
  }
  for (int i = 1; i <= n; i++)
    if (vis[i] == 0) s.insert(i);
  if (new_i < 0) {
    if (find(vec[0].second)) s.insert(vec[0].second);
  } else {
    if (find(vec[new_i].second)) s.insert(vec[new_i].second);
  }
  cout << s.size() << endl;
  if (s.size()) {
    for (set<int>::iterator itr = s.begin(); itr != s.end(); itr++)
      cout << *itr << " ";
    cout << endl;
  }
  return 0;
}

```


### Prompt

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

Aka Beko, trying to escape from 40 bandits, got lost in the city of A. Aka Beko wants to go to City B, where the new hideout is, but the map has been stolen by a bandit.

Kobborg, one of the thieves, sympathized with Aka Beko and felt sorry for him. So I secretly told Aka Beko, "I want to help you go to City B, but I want to give you direct directions because I have to keep out of my friends, but I can't tell you. I can answer. "

When Kobborg receives the question "How about the route XX?" From Aka Beko, he answers Yes if it is the route from City A to City B, otherwise. Check the directions according to the map below.

<image>

Each city is connected by a one-way street, and each road has a number 0 or 1. Aka Beko specifies directions by a sequence of numbers. For example, 0100 is the route from City A to City B via City X, Z, and W. If you choose a route that is not on the map, you will get lost in the desert and never reach City B. Aka Beko doesn't know the name of the city in which she is, so she just needs to reach City B when she finishes following the directions.

Kobborg secretly hired you to create a program to answer questions from Aka Beko. If you enter a question from Aka Beko, write a program that outputs Yes if it is the route from City A to City B, otherwise it outputs No.

input

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

p

A sequence of numbers 0, 1 indicating directions is given on one line. p is a string that does not exceed 100 characters.

The number of datasets does not exceed 100.

output

Print Yes or No on one line for each dataset.

Example

Input

0100
0101
10100
01000
0101011
0011
011111
#

Output

Yes
No
Yes
No
Yes
No
Yes

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int serch(int go,int now)
{
    int direction[6][2]={{1,2},{-1,3},{1,-1},{4,5},{5,2},{2,1}};
    if(now==-1)return -1;
    return direction[now][go];
}
int main()
{
    string str;
    while(cin>>str&&str!="#"){
        int now=0;
        for(int i=0;i<str.size();i++)now=serch(str[i]-'0',now);
        if(now==5)cout<<"Yes\n";
        else cout<<"No\n";
    }
}
```


### Prompt

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

This is an interactive problem.

You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to x.

More formally, there is a singly liked list built on an array of n elements. Element with index i contains two integers: valuei is the integer value in this element, and nexti that is the index of the next element of the singly linked list (or -1, if the current element is the last). The list is sorted, i.e. if nexti ≠ - 1, then valuenexti > valuei.

You are given the number of elements in the list n, the index of the first element start, and the integer x.

You can make up to 2000 queries of the following two types:

  * ? i (1 ≤ i ≤ n) — ask the values valuei and nexti,
  * ! ans — give the answer for the problem: the minimum integer, greater than or equal to x, or ! -1, if there are no such integers. Your program should terminate after this query.

Write a program that solves this problem.

Input

The first line contains three integers n, start, x (1 ≤ n ≤ 50000, 1 ≤ start ≤ n, 0 ≤ x ≤ 109) — the number of elements in the list, the index of the first element and the integer x.

Output

To print the answer for the problem, print ! ans, where ans is the minimum integer in the list greater than or equal to x, or -1, if there is no such integer.

Interaction

To make a query of the first type, print ? i (1 ≤ i ≤ n), where i is the index of element you want to know information about.

After each query of type ? read two integers valuei and nexti (0 ≤ valuei ≤ 109,  - 1 ≤ nexti ≤ n, nexti ≠ 0).

It is guaranteed that if nexti ≠ - 1, then valuenexti > valuei, and that the array values give a valid singly linked list with start being the first element.

Note that you can't ask more than 1999 queries of the type ?.

If nexti = - 1 and valuei = - 1, then it means that you asked more queries than allowed, or asked an invalid query. Your program should immediately terminate (for example, by calling exit(0)). You will receive "Wrong Answer", it means that you asked more queries than allowed, or asked an invalid query. If you ignore this, you can get other verdicts since your program will continue to read from a closed stream.

Your solution will get "Idleness Limit Exceeded", if you don't print anything or forget to flush the output, including the final answer.

To flush you can use (just after printing a query and line end):

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

Hacks format

For hacks, use the following format:

In the first line print three integers n, start, x (1 ≤ n ≤ 50000, 1 ≤ start ≤ n, 0 ≤ x ≤ 109).

In the next n lines print the description of the elements of the list: in the i-th line print two integers valuei and nexti (0 ≤ valuei ≤ 109,  - 1 ≤ nexti ≤ n, nexti ≠ 0).

The printed structure should be a valid singly linked list. In particular, it should be possible to reach all elements from start by following links nexti, and the last element end should have -1 in the nextend.

Example

Input

5 3 80
97 -1
58 5
16 2
81 1
79 4

Output

? 1
? 2
? 3
? 4
? 5
! 81

Note

You can read more about singly linked list by the following link: <https://en.wikipedia.org/wiki/Linked_list#Singly_linked_list>

The illustration for the first sample case. Start and finish elements are marked dark. <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
static inline void canhazfast() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
  T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
  while (b) {
    T q = a / b;
    a %= b;
    swap(a, b);
    x0 -= q * x1;
    swap(x0, x1);
    y0 -= q * y1;
    swap(y0, y1);
  }
  x = x0;
  y = y0;
  return a;
}
static inline int ctz(unsigned x) { return __builtin_ctz(x); }
static inline int ctzll(unsigned long long x) { return __builtin_ctzll(x); }
static inline int clz(unsigned x) { return __builtin_clz(x); }
static inline int clzll(unsigned long long x) { return __builtin_clzll(x); }
static inline int popcnt(unsigned x) { return __builtin_popcount(x); }
static inline int popcntll(unsigned long long x) {
  return __builtin_popcountll(x);
}
static inline int bsr(unsigned x) { return 31 ^ clz(x); }
static inline int bsrll(unsigned long long x) { return 63 ^ clzll(x); }
int val[65536], nxt[65536];
bool vis[65536], in[65536];
int q = 1999;
void query(int i) {
  assert(i > 0);
  if (vis[i]) return;
  cout << "? " << i << endl;
  cin >> val[i] >> nxt[i];
  if (nxt[i] == -1 && val[i] == -1) exit(0);
  vis[i] = true;
  --q;
  if (nxt[i] > 0) in[nxt[i]] = true;
}
void answer(int y) {
  cout << "! " << y << endl;
  exit(0);
}
int main() {
  canhazfast();
  int n, start, x, i;
  int ans = 1234567890;
  mt19937_64 rng(time(nullptr));
  vector<int> ids;
  cin >> n >> start >> x;
  i = start;
  ids.resize(n);
  iota((ids).begin(), (ids).end(), 1);
  shuffle((ids).begin(), (ids).end(), rng);
  while (i > 0 && q > 1000 && !ids.empty()) {
    query(i);
    if (val[i] >= x) break;
    int j = ids.back();
    ids.pop_back();
    query(j);
    if (val[j] >= x)
      ans = min(ans, val[j]);
    else if (val[i] < val[j])
      i = j;
  }
  while (i > 0) {
    query(i);
    if (val[i] >= x) answer(val[i]);
    i = nxt[i];
  }
  answer(-1);
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.

Let volume vj of barrel j be equal to the length of the minimal stave in it.

<image>

You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.

Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.

Input

The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105, 1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).

The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.

Output

Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.

Examples

Input

4 2 1
2 2 1 2 3 2 2 3

Output

7

Input

2 1 0
10 10

Output

20

Input

1 2 1
5 2

Output

2

Input

3 2 1
1 2 3 4 5 6

Output

0

Note

In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].

In the second example you can form the following barrels: [10], [10].

In the third example you can form the following barrels: [2, 5].

In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 20;
int n, k, l, a[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k >> l;
  for (int i = 0; i < n * k; i++) cin >> a[i];
  sort(a, a + n * k);
  long long ans = 0;
  for (int i = 0; i < n * k; i += k) {
    if (a[i] - a[0] <= l) {
      ans += a[i];
    } else {
      int r = n - i / k;
      for (int j = i - 1; j >= 0 && r > 0; j--) {
        if ((j % k) && a[j] - a[0] <= l) {
          ans += a[j];
          r--;
        }
      }
      if (r > 0) ans = 0;
      break;
    }
  }
  cout << ans;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

One day as Petya and his friend Vasya were having one of their numerous trips, they decided to visit a museum castle. The museum has a specific shape: it consists of n rooms connected with m corridors so that one can access any room from any other one.

After the two friends had a little walk around the museum, they decided to split and watch the pieces of art each of them found interesting. They agreed to meet in one of the rooms at six p.m. However, they forgot one quite essential thing: they didn't specify the place to meet and when the time came, they started to rush about the museum looking for each other (they couldn't call each other as roaming made a call's cost skyrocket).

Yet, even despite the whole rush, they couldn't get enough of the pieces of art, that's why each of them has the following strategy: each minute he make a decision where to go — with probability pi he doesn't move to any other place during this minute (i.e. he stays in the room). With probability 1 - pi he equiprobably choose one of the adjacent rooms and went there along the corridor. Here i is the ordinal number of the current room. Building was expensive in ancient times, that's why each corridor connected two different rooms, and any two rooms had no more than one corridor between them.

The boys act simultaneously. As the corridors are dark, it is impossible to meet there; however, one can walk along the corridors in both directions (besides, the two boys can be going through the same corridor simultaneously without meeting). The boys act like that until they meet each other. More formally, the two friends meet when at some moment of time both of them decided to appear in the same room.

For each room find the probability that the boys will meet there considering that at 6 p.m. they are positioned in rooms a and b correspondingly.

Input

The first line contains four integers: n (1 ≤ n ≤ 22), representing the numbers of rooms; m <image>, representing the number of corridors; a, b (1 ≤ a, b ≤ n), representing the numbers of Petya's and Vasya's starting rooms correspondingly.

Next m lines contain pairs of numbers — the numbers of rooms connected by a corridor. Next n lines contain probabilities pi (0.01 ≤ pi ≤ 0.99) with the accuracy of up to four digits after the decimal point — the probability to stay in room i.

It is guaranteed that every room can be reached from every other room by corridors.

Output

In the only line print n space-separated numbers, the i-th number should represent the probability that the friends meet in the i-th room with absolute or relative error of no more than 10 - 6.

Examples

Input

2 1 1 2
1 2
0.5
0.5

Output

0.5000000000 0.5000000000

Input

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

Output

0.3333333333 0.3333333333 0.1666666667 0.1666666667

Note

In the first sample the museum is symmetric. That means the probabilities to meet in rooms 1 and 2 are equal. And their sum equals to one. So, each probability equals 0.5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, stateCnt;
vector<vector<int> > g;
vector<double> stayP;
double prob[300][300], buf[300][300];
int state[30][30];
int getState(int a, int b) {
  if (a > b) swap(a, b);
  return state[a][b];
}
void mult() {
  memset(buf, 0, sizeof(buf));
  for (int i = 0; i < stateCnt; i++)
    for (int j = 0; j < stateCnt; j++)
      for (int k = 0; k < stateCnt; k++) buf[i][j] += prob[i][k] * prob[k][j];
  memcpy(prob, buf, sizeof(buf));
}
void clean() {
  for (int i = 0; i < stateCnt; i++)
    for (int j = 0; j < stateCnt; j++)
      if (prob[i][j] < 1e-10) prob[i][j] = 0;
}
int main() {
  cin >> n >> m >> a >> b;
  stateCnt = 0;
  for (int i = 0; i < n; i++)
    for (int j = i; j < n; j++) {
      state[i][j] = stateCnt;
      stateCnt++;
    }
  a--, b--;
  g.resize(n);
  stayP.resize(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 0; i < n; i++) cin >> stayP[i];
  for (int i = 0; i < n; i++)
    for (int j = i; j < n; j++) {
      if (i == j)
        prob[getState(i, j)][getState(i, j)] = 1;
      else {
        prob[getState(i, j)][getState(i, j)] = stayP[i] * stayP[j];
        double ta = (1 - stayP[i]) / (int)((g[i]).size());
        double tb = (1 - stayP[j]) / (int)((g[j]).size());
        for (int b = 0; b < (int)((g[j]).size()); b++) {
          int tob = g[j][b];
          prob[getState(i, j)][getState(i, tob)] += stayP[i] * tb;
        }
        for (int a = 0; a < (int)((g[i]).size()); a++) {
          int toa = g[i][a];
          prob[getState(i, j)][getState(toa, j)] += ta * stayP[j];
        }
        for (int a = 0; a < (int)((g[i]).size()); a++)
          for (int b = 0; b < (int)((g[j]).size()); b++) {
            int toa = g[i][a];
            int tob = g[j][b];
            prob[getState(i, j)][getState(toa, tob)] += ta * tb;
          }
      }
    }
  for (int i = 0; i < 50; i++) {
    mult();
    clean();
  }
  int t = getState(a, b);
  cout.precision(9);
  for (int i = 0; i < n; i++) cout << prob[t][getState(i, i)] << ' ';
}

```


### Prompt

Please create a solution in CPP to the following problem:

Find places where a string P is found within a text T. Print all indices of T where P found. The indices of T start with 0.

Constraints

* 1 ≤ length of T ≤ 1000
* 1 ≤ length of P ≤ 1000
* The input consists of alphabetical characters and digits

Input

In the first line, a text T is given. In the second line, a string P is given.

Examples

Input

aabaaa
aa

Output

0
3
4

Input

xyzz
yz

Output

1

Input

abc
xyz

Output

### Response

```cpp
#include <iostream>
#include <string>
using namespace std;
int main() {
  string T, P;
  int p = 0;
  cin >> T >> P;
  while(p < int(T.length() - P.length() + 1)) {
	if(p == (int)T.find(P,p)) {
	  cout << (int)T.find(P, p) << endl;
	}
	p++;
  }
  return 0;
}
```


### Prompt

Generate a cpp solution to the following problem:

Omkar has a pie tray with k (2 ≤ k ≤ 20) spots. Each spot in the tray contains either a chocolate pie or a pumpkin pie. However, Omkar does not like the way that the pies are currently arranged, and has another ideal arrangement that he would prefer instead.

To assist Omkar, n elves have gathered in a line to swap the pies in Omkar's tray. The j-th elf from the left is able to swap the pies at positions a_j and b_j in the tray.

In order to get as close to his ideal arrangement as possible, Omkar may choose a contiguous subsegment of the elves and then pass his pie tray through the subsegment starting from the left. However, since the elves have gone to so much effort to gather in a line, they request that Omkar's chosen segment contain at least m (1 ≤ m ≤ n) elves.

Formally, Omkar may choose two integers l and r satisfying 1 ≤ l ≤ r ≤ n and r - l + 1 ≥ m so that first the pies in positions a_l and b_l will be swapped, then the pies in positions a_{l + 1} and b_{l + 1} will be swapped, etc. until finally the pies in positions a_r and b_r are swapped.

Help Omkar choose a segment of elves such that the amount of positions in Omkar's final arrangement that contain the same type of pie as in his ideal arrangement is the maximum possible. Note that since Omkar has a big imagination, it might be that the amounts of each type of pie in his original arrangement and in his ideal arrangement do not match.

Input

The first line contains three integers n, m, and k (1 ≤ m ≤ n ≤ 10^6 and 2 ≤ k ≤ 20) — the number of elves, the minimum subsegment length, and the number of spots in Omkar's tray respectively.

The second and third lines each contain a string of length k consisting of 0s and 1s that represent initial arrangement of pies and ideal arrangement of pies; the j-th character in each string is equal to 0 if the j-th spot in the arrangement contains a chocolate pie and is equal to 1 if the j-th spot in the arrangement contains a pumpkin pie. It is not guaranteed that the two strings have the same amount of 0s or the same amount of 1s.

n lines follow. The j-th of these lines contains two integers a_j and b_j (1 ≤ a_j, b_j ≤ k, a_j ≠ b_j) which indicate that the j-th elf from the left can swap the pies at positions a_j and b_j in the tray.

Output

Output two lines.

The first line should contain a single integer s (0 ≤ s ≤ k) equal to the amount of positions that contain the same type of pie in Omkar's final arrangement and in Omkar's ideal arrangement; s should be the maximum possible.

The second line should contain two integers l and r satisfying 1 ≤ l ≤ r ≤ n and r - l + 1 ≥ m, indicating that Omkar should pass his tray through the subsegment l, l + 1, ..., r to achieve a final arrangement with s positions having the same type of pie as his ideal arrangement.

If there are multiple answers you may output any of them.

Examples

Input

4 2 5
11000
00011
1 3
3 5
4 2
3 4

Output

5
1 3

Input

4 3 5
11000
00011
1 3
1 5
2 4
1 5

Output

3
1 4

Note

In the first test case, the swaps will go like this:

  * Swap 1 and 3: 11000 becomes 01100
  * Swap 3 and 5: 01100 becomes 01001
  * Swap 4 and 2: 01001 becomes 00011

The final arrangement is the same as the ideal arrangement 00011, so there are 5 positions with the same type of pie, which is optimal.

In the second test case, the swaps will go like this:

  * Swap 1 and 3: 11000 becomes 01100
  * Swap 1 and 5: 01100 becomes 01100
  * Swap 4 and 2: 01100 becomes 00110
  * Swap 1 and 5: 00110 becomes 00110

The final arrangement has 3 positions with the same type of pie as the ideal arrangement 00011, those being positions 1, 2, and 4. In this case the subsegment of elves (l, r) = (2, 3) is more optimal, but that subsegment is only length 2 and therefore does not satisfy the constraint that the subsegment be of length at least m = 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
string s;
string ss;
int aa[21];
int bb[21];
int pre3[1 << 10];
pair<int, int> dp[1100][1100];
void add(int i, int j) {
  int xx = (i - (i & (1023))) / 1024;
  for (int ii = 0; ii < (1 << 10); ii++) {
    int mm = pre3[((i & 1023) ^ ii)];
    if (dp[ii][xx].first == -1) {
      dp[ii][xx] = {mm, j + 1};
    }
    if (mm < dp[ii][xx].first) {
      dp[ii][xx] = {mm, j + 1};
    }
  }
}
pair<int, int> it[1000001];
int pre[1000001];
int pre2[1000001];
int vis[1000001];
int vis2[1000001];
int vis3[1 << 20];
int cur[21];
int ans = -1;
pair<int, int> cot;
void remin(int ac, pair<int, int> dd) {
  if (ac > ans) {
    ans = ac;
    cot = dd;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m >> k;
  cin >> s;
  cin >> ss;
  for (int i = 0; i < k; i++) {
    aa[i] = s[i] - '0';
    bb[i] = ss[i] - '0';
  }
  for (int i = 0; i < n; i++) {
    cin >> it[i].first >> it[i].second;
    it[i].first--;
    it[i].second--;
  }
  for (int i = 0; i < k; i++) {
    cur[i] = i;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      if (aa[j] == 1) {
        pre[i] += (1 << cur[j]);
      }
    }
    swap(cur[it[i].first], cur[it[i].second]);
  }
  for (int i = 0; i < k; i++) {
    cur[i] = i;
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (bb[j] == 1) {
        pre2[i] += (1 << cur[j]);
      }
    }
    if (i == n) {
      break;
    }
    swap(cur[it[i].first], cur[it[i].second]);
  }
  long long yy = 0;
  for (int i = n; i >= 0; i--) {
    if (vis3[pre2[i]]) {
      continue;
    }
    vis3[pre2[i]] = 1;
    vis[i] = 1;
    yy += 1;
  }
  assert(yy <= 200000);
  for (int i = 0; i < (1 << 20); i++) {
    vis3[i] = 0;
  }
  for (int i = 0; i < (1 << 10); i++) {
    pre3[i] = __builtin_popcount(i);
  }
  for (int i = 0; i < n; i++) {
    if (vis3[pre[i]]) {
      continue;
    }
    vis3[pre[i]] = 1;
    vis2[i] = 1;
  }
  for (int i = 0; i < (1 << 10); i++) {
    for (int ii = 0; ii < (1 << 10); ii++) {
      dp[i][ii] = {-1, -1};
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i >= m) {
      if (vis2[i - m]) {
        add(pre[i - m], i - m);
      }
    }
    if (vis[i]) {
      int pp = (pre2[i] & (1023));
      int qq = (pre2[i] - pp) / 1024;
      for (int j = 0; j < (1 << 10); j++) {
        if (dp[pp][j].first > -1) {
          int cost = k - dp[pp][j].first;
          cost -= pre3[j ^ qq];
          remin(cost, {dp[pp][j].second, i});
        }
      }
    }
  }
  cout << ans << endl;
  cout << cot.first << " " << cot.second << endl;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

This problem consists of three subproblems: for solving subproblem C1 you will receive 4 points, for solving subproblem C2 you will receive 4 points, and for solving subproblem C3 you will receive 8 points.

Manao decided to pursue a fighter's career. He decided to begin with an ongoing tournament. Before Manao joined, there were n contestants in the tournament, numbered from 1 to n. Each of them had already obtained some amount of tournament points, namely the i-th fighter had pi points.

Manao is going to engage in a single fight against each contestant. Each of Manao's fights ends in either a win or a loss. A win grants Manao one point, and a loss grants Manao's opponent one point. For each i, Manao estimated the amount of effort ei he needs to invest to win against the i-th contestant. Losing a fight costs no effort.

After Manao finishes all of his fights, the ranklist will be determined, with 1 being the best rank and n + 1 being the worst. The contestants will be ranked in descending order of their tournament points. The contestants with the same number of points as Manao will be ranked better than him if they won the match against him and worse otherwise. The exact mechanism of breaking ties for other fighters is not relevant here.

Manao's objective is to have rank k or better. Determine the minimum total amount of effort he needs to invest in order to fulfill this goal, if it is possible.

Input

The first line contains a pair of integers n and k (1 ≤ k ≤ n + 1). The i-th of the following n lines contains two integers separated by a single space — pi and ei (0 ≤ pi, ei ≤ 200000).

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

  * In subproblem C1 (4 points), the constraint 1 ≤ n ≤ 15 will hold.
  * In subproblem C2 (4 points), the constraint 1 ≤ n ≤ 100 will hold.
  * In subproblem C3 (8 points), the constraint 1 ≤ n ≤ 200000 will hold.

Output

Print a single number in a single line — the minimum amount of effort Manao needs to use to rank in the top k. If no amount of effort can earn Manao such a rank, output number -1.

Examples

Input

3 2
1 1
1 4
2 2

Output

3

Input

2 1
3 2
4 0

Output

-1

Input

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

Output

12

Note

Consider the first test case. At the time when Manao joins the tournament, there are three fighters. The first of them has 1 tournament point and the victory against him requires 1 unit of effort. The second contestant also has 1 tournament point, but Manao needs 4 units of effort to defeat him. The third contestant has 2 points and victory against him costs Manao 2 units of effort. Manao's goal is top be in top 2. The optimal decision is to win against fighters 1 and 3, after which Manao, fighter 2, and fighter 3 will all have 2 points. Manao will rank better than fighter 3 and worse than fighter 2, thus finishing in second place.

Consider the second test case. Even if Manao wins against both opponents, he will still rank third.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int MOD = 1000000007;
struct Node {
  int p, e;
  void input() { scanf("%d %d", &p, &e); }
  bool operator<(const Node &n) const { return p > n.p; }
} a[N];
int n, k;
int main() {
  scanf("%d %d", &n, &k);
  k--;
  for (int i = 0; i < n; i++) {
    a[i].input();
  }
  long long ans = 1LL << 60;
  sort(a, a + n);
  for (int d = -2; d < 3; d++) {
    int score = a[k].p + d, before = 0;
    long long ret = 0;
    priority_queue<int, vector<int>, less<int> > large;
    priority_queue<int, vector<int>, greater<int> > small;
    for (int i = 0; i < n; i++) {
      if (a[i].p <= score && a[i].p >= score - 1) {
        large.push(a[i].e);
      } else {
        if (a[i].p > score) before++;
        small.push(a[i].e);
      }
    }
    if (before > k) continue;
    while (!large.empty()) {
      if (before < k) {
        small.push(large.top());
        before++;
      } else {
        score--;
        ret += large.top();
      }
      large.pop();
    }
    while (score > 0 && !small.empty()) {
      ret += small.top();
      small.pop();
      score--;
    }
    if (score <= 0) ans = min(ans, ret);
  }
  if (ans == 1LL << 60) ans = -1;
  printf("%I64d\n", ans);
  return 0;
}

```


### Prompt

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

Drazil is playing a math game with Varda.

Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>.

First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:

1. x doesn't contain neither digit 0 nor digit 1.

2. <image> = <image>.

Help friends find such number.

Input

The first line contains an integer n (1 ≤ n ≤ 15) — the number of digits in a.

The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.

Output

Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.

Examples

Input

4
1234

Output

33222

Input

3
555

Output

555

Note

In the first case, <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 6e5 + 5;
const long long mod = 10000000000000007;
const long long nary = 9;
long long a;
int ans[100], n;
int main() {
  while (scanf("%d%I64d", &n, &a) != EOF) {
    n = 0;
    while (a > 0) {
      int d = (int)(a % 10);
      a /= (long long)10;
      if (d == 9) {
        d -= 2;
        ans[++n] = 3;
        ans[++n] = 3;
        ans[++n] = 2;
      }
      if (d == 8) {
        d--;
        ans[++n] = 2;
        ans[++n] = 2;
        ans[++n] = 2;
      }
      if (d == 6) {
        d--;
        ans[++n] = 3;
      }
      if (d == 4) {
        d--;
        ans[++n] = 2;
        ans[++n] = 2;
      }
      if (d > 1) ans[++n] = d;
    }
    sort(ans + 1, ans + n + 1);
    for (int i = n; i > 0; i--) printf("%d", ans[i]);
    printf("\n");
  }
  return 0;
}

```


### Prompt

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

Stick n circular stickers with a radius of 1 on a square origami paper with a side length of 10. The stickers can be stacked. Create a program that reads the coordinates of the position where the stickers are to be attached and outputs the number of stickers at the place where the stickers overlap most on the origami paper (assuming that even one sticker "overlaps"). ..

Gives the x and y coordinates with the lower left corner of the origami as the origin. Let's put the sticker with these x and y as the center of the circle. The center of the circle never goes out of the origami. Also, multiple stickers will not be attached at the same coordinates.

Hint

It is a figure with a sticker attached as shown in the input example. The circle represents the sticker, and the number represents the number of lines in the input example. At point (2.3, 4.6), the four stickers on the second, third, sixth, and tenth lines of the input example overlap.

<image>

The distance between the centers of 6 and 9 is 2.01293, so the seals do not overlap. The distance between the centers of 1 and 12 is 1.98231, so the seals overlap.

When two circles are in contact (when the distance between the centers is 2), they are assumed to overlap.

Input

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

n
x1, y1
x2, y2
::
xn, yn

The first line gives the number of stickers n (0 ≤ 100). The next n lines give the center coordinates of each seal. xi and yi represent the x and y coordinates of the center of the i-th sticker. Each value is given as a real number, including up to 6 digits after the decimal point.

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

Output

For each data set, output the number of stickers (integer) at the place where the stickers overlap most on the origami paper.

Example

Input

15
3.14979,8.51743
2.39506,3.84915
2.68432,5.39095
5.61904,9.16332
7.85653,4.75593
2.84021,5.41511
1.79500,8.59211
7.55389,8.17604
4.70665,4.66125
1.63470,4.42538
7.34959,4.61981
5.09003,8.11122
5.24373,1.30066
0.13517,1.83659
7.57313,1.58150
0

Output

4

### Response

```cpp
#include<iostream>
#include<cfloat>
#include<cassert>
#include<cmath>
#include<vector>
#include<algorithm>
#include<stdio.h>
using namespace std;

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS )
#define dle(a, b) (equals(a, b) || a < b )
static const double PI = acos(-1);

class Point{
public:
  double x, y;

  Point ( double x = 0, double y = 0): x(x), y(y){}

  Point operator + ( Point p ){ return Point(x + p.x, y + p.y); }
  Point operator - ( Point p ){ return Point(x - p.x, y - p.y); }
  Point operator * ( double a ){ return Point(x*a, y*a); }
  Point operator / ( double a ){ return Point(x/a, y/a); }

  double abs() { return sqrt(norm());}

  double norm() { return x*x + y*y; }

  void rotate(double s,Point g = Point(0.0,0.0)){
    x=x-g.x;
    y=y-g.y;
    double nx=x*cos(s)-y*sin(s);
    double ny=x*sin(s)+y*cos(s);
    x=nx+g.x;
    y=ny+g.y;
  }

  bool operator < ( const Point &p ) const {
    return x != p.x ? x < p.x : y < p.y;
  }

  bool operator == ( const Point &p ) const {
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};
typedef Point Vector;
double getDistance(Point a,Point b){
  return sqrt(pow(a.x-b.x,2.0)+pow(a.y-b.y,2.0));
}

//PerfectCircle
class Circle{
public:
  Point o;
  double r;

  Circle ( Point o = Point(0.0,0.0), double r = 0.0): o(o), r(r){}

  double area() { return r*r*PI; }

};

int getCrossState(Circle a,Circle b){

  double x=getDistance(a.o,b.o);
  if(x+b.r < a.r)return 2;
  else if(x+a.r<b.r)return -2;
  else if(x<=a.r+b.r)return 1;
  else return 0;

}

vector<Point> getCrossPoints(Circle a,Circle b){

  vector<Point> res;
  if(getCrossState(a,b)!=1){
    return res;
  }

  double n = getDistance(a.o,b.o);
  double rate = b.r/(a.r+b.r);

  n*=rate;

  double h = sqrt(abs(b.r * b.r - n*n));

  //cout<<a.o.y<<" "<<b.o.y<<endl;
  Point g = b.o+((a.o-b.o)*rate);

  //cout<<g.x<<' '<<g.y<<endl;
  Vector gb = b.o-g;

  gb.rotate( PI/2.0);

  res.push_back(g + gb*(h/gb.abs()));

  if(abs(h)<EPS)return res;
  gb.rotate(PI);
  res.push_back(g + gb*(h/gb.abs()));

  return res;
}

int main(){
  Circle t[100];
  vector <Point> crosspoints,tmp;
  int n,cnt,ans;
  char ch;
  while(cin>>n){
    if(n==0)break;
    crosspoints.clear();
    tmp.clear();

    for(int i=0;i<n;i++){
      cin>>t[i].o.x>>ch>>t[i].o.y;
      t[i].r=1.0;
      for(int j=i-1;j>=0;j--){
	tmp=getCrossPoints(t[i],t[j]);
	for(int k=0;k<(int)tmp.size();k++){
	  if(tmp[k].x<0.0||tmp[k].y<0.0)continue;
	  if(tmp[k].x>10.0||tmp[k].y>10.0)continue;
	  crosspoints.push_back(tmp[k]);
      }//k
    }//j
  }//i

  crosspoints.push_back(Point(0.0,0.0));
  crosspoints.push_back(Point(10.0,0.0));
  crosspoints.push_back(Point(0.0,10.0));
  crosspoints.push_back(Point(10.0,10.0));

  ans=0;
    for(int i=0;i<(int)crosspoints.size();i++){
      //cout<<crosspoints[i].x<<" "<<crosspoints[i].y<<endl;
      cnt=0;
      for(int j=0;j<n;j++){
	if(getDistance(crosspoints[i],t[j].o)<=t[j].r+EPS)cnt++;
      }
      ans=max(ans,cnt);
    }

    cout<<ans<<endl;
  }//while
  return 0;
}
```


### Prompt

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

Professor GukiZ has two arrays of integers, a and b. Professor wants to make the sum of the elements in the array a sa as close as possible to the sum of the elements in the array b sb. So he wants to minimize the value v = |sa - sb|.

In one operation professor can swap some element from the array a and some element from the array b. For example if the array a is [5, 1, 3, 2, 4] and the array b is [3, 3, 2] professor can swap the element 5 from the array a and the element 2 from the array b and get the new array a [2, 1, 3, 2, 4] and the new array b [3, 3, 5].

Professor doesn't want to make more than two swaps. Find the minimal value v and some sequence of no more than two swaps that will lead to the such value v. Professor makes swaps one by one, each new swap he makes with the new arrays a and b.

Input

The first line contains integer n (1 ≤ n ≤ 2000) — the number of elements in the array a.

The second line contains n integers ai ( - 109 ≤ ai ≤ 109) — the elements of the array a.

The third line contains integer m (1 ≤ m ≤ 2000) — the number of elements in the array b.

The fourth line contains m integers bj ( - 109 ≤ bj ≤ 109) — the elements of the array b.

Output

In the first line print the minimal value v = |sa - sb| that can be got with no more than two swaps.

The second line should contain the number of swaps k (0 ≤ k ≤ 2).

Each of the next k lines should contain two integers xp, yp (1 ≤ xp ≤ n, 1 ≤ yp ≤ m) — the index of the element in the array a and the index of the element in the array b in the p-th swap.

If there are several optimal solutions print any of them. Print the swaps in order the professor did them.

Examples

Input

5
5 4 3 2 1
4
1 1 1 1

Output

1
2
1 1
4 2

Input

5
1 2 3 4 5
1
15

Output

0
0

Input

5
1 2 3 4 5
4
1 2 3 4

Output

1
1
3 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long A[3000], B[3000];
vector<long long> VA, VB;
unordered_map<long long, pair<int, int> > MA, MB;
int X1, Y1, X2, Y2;
long long diff = 0;
long long mindiff;
long long sa = 0, sb = 0;
long long t = 0;
void check(int j, int i) {
  diff = llabs(sa - sb - VA[i] + VB[j]);
  if (diff < mindiff) {
    mindiff = diff;
    X1 = MA[VA[i]].first;
    X2 = MA[VA[i]].second;
    Y1 = (MB[VB[j]]).first;
    Y2 = MB[VB[j]].second;
  }
}
int main(int argc, const char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, i, j;
  cin >> n;
  for (i = 0; i < n; i++) cin >> A[i];
  cin >> m;
  for (j = 0; j < m; j++) cin >> B[j];
  sa = accumulate(A, A + n, 0LL);
  sb = accumulate(B, B + m, 0LL);
  if (sa == sb) {
    cout << "0\n0";
    return 0;
  }
  mindiff = llabs(sa - sb);
  X1 = -1;
  Y1 = -1;
  X2 = -1;
  Y2 = -1;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      diff = llabs(sa - sb - 2 * A[i] + 2 * B[j]);
      if (diff < mindiff) {
        mindiff = diff;
        X1 = i;
        Y1 = j;
      }
    }
  }
  for (i = 0; i < n; i++)
    for (j = i + 1; j < n; j++) {
      VA.push_back(2LL * (A[i] + A[j]));
      MA[2LL * (A[i] + A[j])] = pair<int, int>(i, j);
    }
  for (i = 0; i < m; i++)
    for (j = i + 1; j < m; j++) {
      VB.push_back(2LL * (B[i] + B[j]));
      MB[2LL * (B[i] + B[j])] = pair<int, int>(i, j);
    }
  sort(VA.begin(), VA.end());
  sort(VB.begin(), VB.end());
  for (i = 0; i < VB.size(); i++) {
    t = sa - sb + VB[i];
    int pos = (int)(lower_bound(VA.begin(), VA.end(), t) - VA.begin());
    if (pos == VA.size()) {
      if (pos == 0)
        continue;
      else
        check(i, pos - 1);
    } else if (pos == 0) {
      if (pos == VA.size() - 1)
        check(i, pos);
      else {
        check(i, pos);
        check(i, pos + 1);
      }
    } else if (pos == VA.size() - 1) {
      if (pos == 0)
        check(i, pos);
      else {
        check(i, pos);
        check(i, pos - 1);
      }
    } else {
      check(i, pos);
      check(i, pos + 1);
      check(i, pos - 1);
    }
  }
  if (X1 == -1 && Y1 == -1) {
    cout << mindiff << "\n0\n";
  } else if (X2 == -1 && Y2 == -1) {
    cout << mindiff << "\n";
    cout << 1 << "\n";
    cout << X1 + 1 << " " << Y1 + 1;
  } else {
    cout << mindiff << "\n";
    cout << 2 << "\n";
    cout << X1 + 1 << " " << Y1 + 1 << "\n";
    cout << X2 + 1 << " " << Y2 + 1;
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Phoenix has a string s consisting of lowercase Latin letters. He wants to distribute all the letters of his string into k non-empty strings a_1, a_2, ..., a_k such that every letter of s goes to exactly one of the strings a_i. The strings a_i do not need to be substrings of s. Phoenix can distribute letters of s and rearrange the letters within each string a_i however he wants.

For example, if s =  baba and k=2, Phoenix may distribute the letters of his string in many ways, such as:

  * ba and ba
  * a and abb
  * ab and ab
  * aa and bb

But these ways are invalid:

  * baa and ba
  * b and ba
  * baba and empty string (a_i should be non-empty)

Phoenix wants to distribute the letters of his string s into k strings a_1, a_2, ..., a_k to minimize the lexicographically maximum string among them, i. e. minimize max(a_1, a_2, ..., a_k). Help him find the optimal distribution and print the minimal possible value of max(a_1, a_2, ..., a_k).

String x is lexicographically less than string y if either x is a prefix of y and x ≠ y, or there exists an index i (1 ≤ i ≤ min(|x|, |y|)) such that x_i < y_i and for every j (1 ≤ j < i) x_j = y_j. Here |x| denotes the length of the string x.

Input

The input consists of multiple test cases. The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases. Each test case consists of two lines.

The first line of each test case consists of two integers n and k (1 ≤ k ≤ n ≤ 10^5) — the length of string s and the number of non-empty strings, into which Phoenix wants to distribute letters of s, respectively.

The second line of each test case contains a string s of length n consisting only of lowercase Latin letters.

It is guaranteed that the sum of n over all test cases is ≤ 10^5.

Output

Print t answers — one per test case. The i-th answer should be the minimal possible value of max(a_1, a_2, ..., a_k) in the i-th test case.

Example

Input

6
4 2
baba
5 2
baacb
5 3
baacb
5 3
aaaaa
6 4
aaxxzz
7 1
phoenix

Output

ab
abbc
b
aa
x
ehinopx

Note

In the first test case, one optimal solution is to distribute baba into ab and ab.

In the second test case, one optimal solution is to distribute baacb into abbc and a.

In the third test case, one optimal solution is to distribute baacb into ac, ab, and b.

In the fourth test case, one optimal solution is to distribute aaaaa into aa, aa, and a.

In the fifth test case, one optimal solution is to distribute aaxxzz into az, az, x, and x.

In the sixth test case, one optimal solution is to distribute phoenix into ehinopx.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t, n, k;
  cin >> t;
  while (t--) {
    string s;
    set<char> st;
    cin >> n >> k >> s;
    sort(s.begin(), s.end());
    vector<string> si(k);
    long long first_count = (upper_bound(s.begin(), s.end(), s[0]) - s.begin());
    if (k == 1) {
      cout << s << '\n';
    } else if (k > first_count) {
      cout << s[k - 1] << '\n';
    } else {
      for (long long i = k; i < n; i++) {
        st.insert(s[i]);
      }
      long long dist = st.size();
      if (dist == 1) {
        string ans;
        long long ind = 0;
        while (ind < n) {
          ans += s[ind];
          ind += k;
        }
        cout << ans << '\n';
      } else {
        string ans;
        ans += s[0];
        for (long long i = k; i < n; i++) {
          ans += s[i];
        }
        cout << ans << '\n';
      }
    }
  }
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Example

Input

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

Output

1 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
vector<P1>edge[10005];
int par[505],ran[505];
void init(){ for(int i=0;i<505;i++) par[i] = i; }
int find(int x){ if(x == par[x]) return x; else return par[x] = find(par[x]); }
void unite(int x,int y){
	x = find(x); y = find(y); if(x==y) return;
	if(ran[x] < ran[y]) par[x] = y;
	else{
		par[y] = x;
		if(ran[x] == ran[y]) ran[x]++;
	}
}
bool same(int x,int y){ return find(x)==find(y); }
vector<P>G[505];
int cnt[505];
bool used[505];
int dep[505];
vector<P>H[505];

int cnty;
ll sum;

void dfs(int v,int u,int d){
	if(used[v]) return;
	dep[v] = d; used[v] = 1;
	for(int i=0;i<G[v].size();i++){
		int to = G[v][i].fi;
		if(to ==  u) continue;
		if(!used[to]){
			H[v].pb(G[v][i]);
			dfs(to,v,d+1);
			//cout<<v<<" "<<to<<endl;
		}
		else{
			if(dep[v] > dep[to]){
				cnt[v]++;
				cnt[to]--;
			}
			else{
				cnt[v]--;
				cnt[to]++;
			}
			//cout<<v<<"a "<<to<<endl;
		}
	}
}
int dfs2(int v,int u,int add){
	int x = cnt[v];
	for(int i=0;i<H[v].size();i++){
		int to = H[v][i].fi;
		int nm = H[v][i].sc;
		int ret = dfs2(to,v,add);
		if(ret == 0){
			cnty++;
			sum+=add;
		}
		x += ret;
	}
	return x;
}
int main(){
	cin>>n>>m;
	rep(i,m){
		int a,b,d; cin>>a>>b>>d;
		edge[d].pb(mp(i,mp(a,b)));
	}
	init();
	rep(i,10005){
		rep(i,505){
			G[i].clear();
			H[i].clear();
		}
		rep(j,edge[i].size()){
			int a = edge[i][j].sc.fi;
			int b = edge[i][j].sc.sc;
			a = find(a);
			b = find(b);
			if(a != b){
				G[a].pb(mp(b,edge[i][j].fi));
				G[b].pb(mp(a,edge[i][j].fi));
			}
		}
		memset(used,0,sizeof(used));
		memset(cnt,0,sizeof(cnt));
		rep(j,505){
			if(used[j]) continue;
			dfs(j,-1,0);
			dfs2(j,0,i);
		}
		rep(j,edge[i].size()){
			int a = edge[i][j].sc.fi;
			int b = edge[i][j].sc.sc;
			unite(a,b);
		}
	}
	cout<<cnty<<" "<<sum<<endl;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Little Alyona is celebrating Happy Birthday! Her mother has an array of n flowers. Each flower has some mood, the mood of i-th flower is ai. The mood can be positive, zero or negative.

Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose several of the subarrays suggested by her mother. After that, each of the flowers will add to the girl's happiness its mood multiplied by the number of chosen subarrays the flower is in.

For example, consider the case when the mother has 5 flowers, and their moods are equal to 1, - 2, 1, 3, - 4. Suppose the mother suggested subarrays (1, - 2), (3, - 4), (1, 3), (1, - 2, 1, 3). Then if the girl chooses the third and the fourth subarrays then:

  * the first flower adds 1·1 = 1 to the girl's happiness, because he is in one of chosen subarrays,
  * the second flower adds ( - 2)·1 = - 2, because he is in one of chosen subarrays,
  * the third flower adds 1·2 = 2, because he is in two of chosen subarrays,
  * the fourth flower adds 3·2 = 6, because he is in two of chosen subarrays,
  * the fifth flower adds ( - 4)·0 = 0, because he is in no chosen subarrays.

Thus, in total 1 + ( - 2) + 2 + 6 + 0 = 7 is added to the girl's happiness. Alyona wants to choose such subarrays from those suggested by the mother that the value added to her happiness would be as large as possible. Help her do this!

Alyona can choose any number of the subarrays, even 0 or all suggested by her mother.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of flowers and the number of subarrays suggested by the mother.

The second line contains the flowers moods — n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100).

The next m lines contain the description of the subarrays suggested by the mother. The i-th of these lines contain two integers li and ri (1 ≤ li ≤ ri ≤ n) denoting the subarray a[li], a[li + 1], ..., a[ri].

Each subarray can encounter more than once.

Output

Print single integer — the maximum possible value added to the Alyona's happiness.

Examples

Input

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

Output

7

Input

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

Output

16

Input

2 2
-1 -2
1 1
1 2

Output

0

Note

The first example is the situation described in the statements.

In the second example Alyona should choose all subarrays.

The third example has answer 0 because Alyona can choose none of the subarrays.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MX = 3e5 + 9;
const long double eps = -0.00000001;
const long long mod = 1e9 + 7;
int a[MX], l[MX], r[MX];
int main() {
  long long n, m, ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i];
  }
  for (int i = 0; i < m; i++) {
    long long c = 0;
    for (int j = l[i]; j <= r[i]; j++) {
      c += a[j];
    }
    if (c >= 0) {
      ans += c;
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

You have a password which you often type — a string s of length n. Every character of this string is one of the first m lowercase Latin letters.

Since you spend a lot of time typing it, you want to buy a new keyboard.

A keyboard is a permutation of the first m Latin letters. For example, if m = 3, then there are six possible keyboards: abc, acb, bac, bca, cab and cba.

Since you type your password with one finger, you need to spend time moving your finger from one password character to the next. The time to move from character s_i to character s_{i+1} is equal to the distance between these characters on keyboard. The total time you have to spend typing the password with a keyboard is called the slowness of this keyboard.

More formaly, the slowness of keyboard is equal to ∑_{i=2}^{n} |pos_{s_{i-1}} - pos_{s_i} |, where pos_x is position of letter x in keyboard.

For example, if s is aacabc and the keyboard is bac, then the total time of typing this password is |pos_a - pos_a| + |pos_a - pos_c| + |pos_c - pos_a| + |pos_a - pos_b| + |pos_b - pos_c| = |2 - 2| + |2 - 3| + |3 - 2| + |2 - 1| + |1 - 3| = 0 + 1 + 1 + 1 + 2 = 5.

Before buying a new keyboard you want to know the minimum possible slowness that the keyboard can have.

Input

The first line contains two integers n and m (1 ≤ n ≤ 10^5, 1 ≤ m ≤ 20).

The second line contains the string s consisting of n characters. Each character is one of the first m Latin letters (lowercase).

Output

Print one integer – the minimum slowness a keyboard can have.

Examples

Input

6 3
aacabc

Output

5

Input

6 4
aaaaaa

Output

0

Input

15 4
abacabadabacaba

Output

16

Note

The first test case is considered in the statement.

In the second test case the slowness of any keyboard is 0.

In the third test case one of the most suitable keyboards is bacd.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const int N = 1e5 + 7, M = 20;
int n, m, cnt[M][M];
int pos[(1 << M) + 7], f[(1 << M) + 7], g[M][(1 << M) + 7], h[(1 << M) + 7];
char s[N];
int main() {
  n = read(), m = read();
  scanf("%s", s + 1);
  for (int i = 1; i < n; i++)
    cnt[s[i] - 'a'][s[i + 1] - 'a']++, cnt[s[i + 1] - 'a'][s[i] - 'a']++;
  for (int i = 0; i < m; i++) pos[1 << i] = i;
  memset(f, 0x3f, sizeof(f));
  int mx = (1 << m) - 1;
  f[0] = 0;
  for (int p = 0; p < m; p++)
    for (int o = 1; o < mx; o++) {
      if (o & (1 << p)) continue;
      g[p][o] = g[p][o - (o & -o)] + cnt[p][pos[o & -o]];
    }
  for (int o = 0; o < mx; o++)
    for (int p = 0; p < m; p++)
      if (o & (1 << p)) h[o] += g[p][mx ^ o];
  for (int o = 0; o < mx; o++)
    for (int p = 0; p < m; p++) {
      if (o & (1 << p)) continue;
      f[o ^ (1 << p)] = min(f[o ^ (1 << p)], f[o] + h[o]);
    }
  printf("%d\n", f[mx]);
  return 0;
}

```


### Prompt

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

Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to be the number of integer points in the segment [l, r] with l ≤ r (say that <image>). You are given two integers n and k and n closed intervals [li, ri] on OX axis and you have to find:

<image>

In other words, you should find the sum of the number of integer points in the intersection of any k of the segments.

As the answer may be very large, output it modulo 1000000007 (109 + 7).

Mike can't solve this problem so he needs your help. You will help him, won't you?

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 200 000) — the number of segments and the number of segments in intersection groups respectively.

Then n lines follow, the i-th line contains two integers li, ri ( - 109 ≤ li ≤ ri ≤ 109), describing i-th segment bounds.

Output

Print one integer number — the answer to Mike's problem modulo 1000000007 (109 + 7) in the only line.

Examples

Input

3 2
1 2
1 3
2 3

Output

5

Input

3 3
1 3
1 3
1 3

Output

3

Input

3 1
1 2
2 3
3 4

Output

6

Note

In the first example:

<image>;

<image>;

<image>.

So the answer is 2 + 1 + 2 = 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, INV = 1e9 + 5, MAX = 2 * 1e5;
vector<pair<long long, long long> > vec;
long long N, K, total = 0, fac[200010], inv_fac[200010];
long long fastPow(long long N, long long X) {
  if (X == 0) return 1;
  if (X == 1) return N;
  long long temp = fastPow(N, X / 2);
  if (X % 2 == 0)
    return temp * temp % MOD;
  else
    return temp * temp % MOD * N % MOD;
}
void factorial() {
  fac[0] = 1;
  for (long long i = 1; i <= MAX; i++) fac[i] = i * fac[i - 1] % MOD;
}
void inverse_fac() {
  for (long long i = 0; i <= MAX; i++) {
    inv_fac[i] = fastPow(fac[i], INV);
  }
}
long long C(long long n, long long k) {
  return fac[n] * inv_fac[k] % MOD * inv_fac[n - k] % MOD;
}
void LineSweep() {
  long long cnt = 0, prev = 0;
  for (pair<long long, long long> &a : vec) {
    if (cnt >= K) total = (total + C(cnt, K) * (a.first - prev) % MOD) % MOD;
    cnt += a.second;
    prev = a.first;
  }
  cout << total << '\n';
}
void Solve() {
  cin >> N >> K;
  for (long long i = 0; i < N; i++) {
    long long st, fin;
    cin >> st >> fin;
    vec.push_back({st, 1});
    vec.push_back({fin + 1, -1});
  }
  sort(vec.begin(), vec.end());
  factorial();
  inverse_fac();
  LineSweep();
}
int main() { Solve(); }

```


### Prompt

Develop a solution in CPP to the problem described below:

You are given a directed weighted graph with n nodes and 2n - 2 edges. The nodes are labeled from 1 to n, while the edges are labeled from 1 to 2n - 2. The graph's edges can be split into two parts.

  * The first n - 1 edges will form a rooted spanning tree, with node 1 as the root. All these edges will point away from the root.
  * The last n - 1 edges will be from node i to node 1, for all 2 ≤ i ≤ n.

You are given q queries. There are two types of queries

  * 1 i w: Change the weight of the i-th edge to w
  * 2 u v: Print the length of the shortest path between nodes u to v

Given these queries, print the shortest path lengths.

Input

The first line of input will contain two integers n, q (2 ≤ n, q ≤ 200 000), the number of nodes, and the number of queries, respectively.

The next 2n - 2 integers will contain 3 integers ai, bi, ci, denoting a directed edge from node ai to node bi with weight ci.

The first n - 1 of these lines will describe a rooted spanning tree pointing away from node 1, while the last n - 1 of these lines will have bi = 1.

More specifically,

  * The edges (a1, b1), (a2, b2), ... (an - 1, bn - 1) will describe a rooted spanning tree pointing away from node 1.
  * bj = 1 for n ≤ j ≤ 2n - 2.
  * an, an + 1, ..., a2n - 2 will be distinct and between 2 and n.

The next q lines will contain 3 integers, describing a query in the format described in the statement.

All edge weights will be between 1 and 106.

Output

For each type 2 query, print the length of the shortest path in its own line.

Example

Input

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

Output

0
1
4
8
100
132
10

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> e[200005];
int u[400005], v[400005], w[400005];
int l[200005], r[200005], t;
long long d0[200005], tmh[200005];
void dfs(int x, long long d) {
  l[x] = ++t;
  d0[x] = d;
  for (int eid : e[x]) {
    dfs(v[eid], d + w[eid]);
  }
  r[x] = t;
}
const int MAXN = 262144;
struct tree {
  long long mn[2 * MAXN], lazy[2 * MAXN];
  void init() {
    for (int i = MAXN - 1; i >= 1; i--) {
      mn[i] = min(mn[2 * i], mn[2 * i + 1]);
    }
  }
  void push(int x) {
    if (x < MAXN) {
      lazy[2 * x] += lazy[x];
      lazy[2 * x + 1] += lazy[x];
    }
    mn[x] += lazy[x];
    lazy[x] = 0;
  }
  void add(int l, int r, long long val, int node = 1, int nl = 1,
           int nr = MAXN) {
    push(node);
    if (r < nl || nr < l) {
      return;
    }
    if (l <= nl && nr <= r) {
      lazy[node] += val;
      push(node);
      return;
    }
    int nm = (nl + nr) >> 1;
    add(l, r, val, 2 * node, nl, nm);
    add(l, r, val, 2 * node + 1, nm + 1, nr);
    mn[node] = min(mn[2 * node], mn[2 * node + 1]);
  }
  long long get(int l, int r, int node = 1, int nl = 1, int nr = MAXN) {
    push(node);
    if (r < nl || nr < l) {
      return 1e18;
    }
    if (l <= nl && nr <= r) {
      return mn[node];
    }
    int nm = (nl + nr) >> 1;
    return min(get(l, r, 2 * node, nl, nm),
               get(l, r, 2 * node + 1, nm + 1, nr));
  }
};
tree drvo_dubina, drvo_takemehome;
void update_w(int eid, int nuw) {
  int delta = nuw - w[eid];
  w[eid] += delta;
  if (eid < n) {
    drvo_dubina.add(l[v[eid]], r[v[eid]], delta);
    drvo_takemehome.add(l[v[eid]], r[v[eid]], delta);
  } else {
    drvo_takemehome.add(l[u[eid]], l[u[eid]], delta);
  }
}
long long find_len(int a, int b) {
  if (l[a] <= l[b] && r[b] <= r[a]) {
    return drvo_dubina.get(l[b], l[b]) - drvo_dubina.get(l[a], l[a]);
  } else {
    return drvo_takemehome.get(l[a], r[a]) - drvo_dubina.get(l[a], l[a]) +
           find_len(1, b);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  int q;
  cin >> n >> q;
  for (int i = 1; i <= 2 * n - 2; i++) {
    cin >> u[i] >> v[i] >> w[i];
    if (i < n) {
      e[u[i]].push_back(i);
    } else {
      tmh[u[i]] = w[i];
    }
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    drvo_dubina.add(l[i], l[i], d0[i]);
  }
  for (int i = 1; i <= n; i++) {
    drvo_takemehome.add(l[i], l[i], d0[i] + tmh[i]);
  }
  while (q--) {
    int t, x, y;
    cin >> t >> x >> y;
    if (t == 1) {
      update_w(x, y);
    } else {
      cout << find_len(x, y) << '\n';
    }
  }
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Johnny is at a carnival which has n raffles. Raffle i has a prize with value pi. Each participant can put tickets in whichever raffles they choose (they may have more than one ticket in a single raffle). At the end of the carnival, one ticket is selected at random from each raffle, and the owner of the ticket wins the associated prize. A single person can win multiple prizes from different raffles.

However, county rules prevent any one participant from owning more than half the tickets in a single raffle, i.e. putting more tickets in the raffle than all the other participants combined. To help combat this (and possibly win some prizes), the organizers started by placing a single ticket in each raffle, which they will never remove.

Johnny bought t tickets and is wondering where to place them. Currently, there are a total of li tickets in the i-th raffle. He watches as other participants place tickets and modify their decisions and, at every moment in time, wants to know how much he can possibly earn. Find the maximum possible expected value of Johnny's winnings at each moment if he distributes his tickets optimally. Johnny may redistribute all of his tickets arbitrarily between each update, but he may not place more than t tickets total or have more tickets in a single raffle than all other participants combined.

Input

The first line contains two integers n, t, and q (1 ≤ n, t, q ≤ 200 000) — the number of raffles, the number of tickets Johnny has, and the total number of updates, respectively.

The second line contains n space-separated integers pi (1 ≤ pi ≤ 1000) — the value of the i-th prize.

The third line contains n space-separated integers li (1 ≤ li ≤ 1000) — the number of tickets initially in the i-th raffle.

The last q lines contain the descriptions of the updates. Each description contains two integers tk, rk (1 ≤ tk ≤ 2, 1 ≤ rk ≤ n) — the type of the update and the raffle number. An update of type 1 represents another participant adding a ticket to raffle rk. An update of type 2 represents another participant removing a ticket from raffle rk.

It is guaranteed that, after each update, each raffle has at least 1 ticket (not including Johnny's) in it.

Output

Print q lines, each containing a single real number — the maximum expected value of Johnny's winnings after the k-th update. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

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>.

Examples

Input

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

Output

1.666666667
1.333333333
2.000000000

Input

3 20 5
6 8 10
6 6 6
1 1
1 2
1 3
2 3
2 3

Output

12.000000000
12.000000000
11.769230769
12.000000000
12.000000000

Note

In the first case, Johnny only has one ticket to distribute. The prizes are worth 4 and 5, and the raffles initially have 1 and 2 tickets, respectively. After the first update, each raffle has 2 tickets, so Johnny has expected value <image> of winning by placing his ticket into the second raffle. The second update adds a ticket to the second raffle, so Johnny can win <image> in the first raffle. After the final update, Johnny keeps his ticket in the first raffle and wins <image>.

In the second case, Johnny has more tickets than he is allowed to spend. In particular, after the first update, there are 7, 6, and 6 tickets in each raffle, respectively, so Johnny can only put in 19 tickets, winning each prize with probability <image>. Also, note that after the last two updates, Johnny must remove a ticket from the last raffle in order to stay under <image> the tickets in the third raffle.

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int MAXN = 1 << 18;
const int MOD = 1;
long long gcd(long long a, long long b) {
  a = abs(a), b = abs(b);
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
double d(long long a, long long b) { return a * 1.0 / b; }
int n, t, q;
int ct;
int p[MAXN], l[MAXN];
long long cnt[MAXN];
double ans;
double ifAdd[MAXN], ifDel[MAXN];
set<pair<double, int> > stAdd, stDel;
void setIfAdd(int id) {
  if (cnt[id] == l[id])
    ifAdd[id] = -10000;
  else
    ifAdd[id] = d(p[id] * (cnt[id] + 1), cnt[id] + 1 + l[id]) -
                d(p[id] * cnt[id], cnt[id] + l[id]);
}
void setIfDel(int id) {
  if (cnt[id] == 0)
    ifDel[id] = 10000;
  else
    ifDel[id] = d(p[id] * cnt[id], cnt[id] + l[id]) -
                d(p[id] * (cnt[id] - 1), cnt[id] + l[id] - 1);
}
double getExp(int id) { return cnt[id] * p[id] * 1.0 / (l[id] + cnt[id]); }
void addTicket(int id) {
  stAdd.erase(make_pair(ifAdd[id], id));
  stDel.erase(make_pair(ifDel[id], id));
  ans -= getExp(id);
  cnt[id]++, ct++;
  setIfAdd(id);
  setIfDel(id);
  ans += getExp(id);
  stAdd.insert(make_pair(ifAdd[id], id));
  stDel.insert(make_pair(ifDel[id], id));
}
void delTicket(int id) {
  stAdd.erase(make_pair(ifAdd[id], id));
  stDel.erase(make_pair(ifDel[id], id));
  ans -= getExp(id);
  cnt[id]--, ct--;
  setIfAdd(id);
  setIfDel(id);
  ans += getExp(id);
  stAdd.insert(make_pair(ifAdd[id], id));
  stDel.insert(make_pair(ifDel[id], id));
}
void init() {
  stAdd.clear();
  stDel.clear();
  ans = 0;
  ct = 0;
  for (int i = 0; i < n; i++) {
    cnt[i] = 0;
    setIfAdd(i);
    setIfDel(i);
    stAdd.insert(make_pair(ifAdd[i], i));
    stDel.insert(make_pair(ifDel[i], i));
  }
  for (int i = 0; i < t; i++) {
    int id = stAdd.rbegin()->second;
    if (!(d(0, 1) < stAdd.rbegin()->first)) continue;
    addTicket(id);
  }
}
void fix(int id) {
  stAdd.erase(make_pair(ifAdd[id], id));
  stDel.erase(make_pair(ifDel[id], id));
  if (cnt[id] > l[id]) cnt[id]--, ct--;
  while (ct < t && cnt[id] < l[id]) cnt[id]++, ct++;
  while (!stAdd.empty()) {
    setIfAdd(id);
    setIfDel(id);
    if (ifDel[id] < stAdd.rbegin()->first) {
      int nid = stAdd.rbegin()->second;
      addTicket(nid);
      cnt[id]--;
      ct--;
    } else
      break;
  }
  while (!stDel.empty()) {
    setIfAdd(id);
    setIfDel(id);
    if (stDel.begin()->first < ifAdd[id]) {
      int nid = stDel.begin()->second;
      delTicket(nid);
      cnt[id]++;
      ct++;
    } else
      break;
  }
  while (ct < t) {
    if (d(0, 1) < stAdd.rbegin()->first) {
      addTicket(stAdd.rbegin()->second);
    } else
      break;
  }
  setIfAdd(id);
  setIfDel(id);
  stAdd.insert(make_pair(ifAdd[id], id));
  stDel.insert(make_pair(ifDel[id], id));
}
int main() {
  while (scanf("%d%d%d", &n, &t, &q) == 3) {
    for (int i = 0; i < n; i++) scanf("%d", &p[i]);
    for (int i = 0; i < n; i++) scanf("%d", &l[i]);
    init();
    for (int i = 0; i < q; i++) {
      int t, id;
      scanf("%d%d", &t, &id);
      --id;
      ans -= getExp(id);
      if (t == 1) {
        l[id]++;
      }
      if (t == 2) {
        l[id]--;
      }
      fix(id);
      ans += getExp(id);
      printf("%.15f\n", ans);
    }
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Abendsen assigned a mission to Juliana. In this mission, Juliana has a rooted tree with n vertices. Vertex number 1 is the root of this tree. Each vertex can be either black or white. At first, all vertices are white. Juliana is asked to process q queries. Each query is one of three types:

  1. If vertex v is white, mark it as black; otherwise, perform this operation on all direct sons of v instead.
  2. Mark all vertices in the subtree of v (including v) as white.
  3. Find the color of the i-th vertex.

<image> An example of operation "1 1" (corresponds to the first example test). The vertices 1 and 2 are already black, so the operation goes to their sons instead.

Can you help Juliana to process all these queries?

Input

The first line contains two integers n and q (2≤ n≤ 10^5, 1≤ q≤ 10^5) — the number of vertices and the number of queries.

The second line contains n-1 integers p_2, p_3, …, p_n (1≤ p_i<i), where p_i means that there is an edge between vertices i and p_i.

Each of the next q lines contains two integers t_i and v_i (1≤ t_i≤ 3, 1≤ v_i≤ n) — the type of the i-th query and the vertex of the i-th query.

It is guaranteed that the given graph is a tree.

Output

For each query of type 3, print "black" if the vertex is black; otherwise, print "white".

Examples

Input

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

Output

black
white
black
white
black
white

Input

8 11
1 1 2 3 3 6 6
1 1
1 1
1 3
3 2
3 4
3 6
3 7
2 3
1 6
3 7
3 6

Output

black
white
black
white
white
black

Note

The first example is shown on the picture below.

<image>

The second example is shown on the picture below.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
int n, q;
vector<int> adj[N];
int in[N], out[N];
int sz[N], head[N], par[N];
int timer;
void dfs(int u) {
  sz[u] = 1;
  for (auto& v : adj[u]) {
    par[v] = u;
    dfs(v);
    sz[u] += sz[v];
    if (sz[v] > sz[adj[u][0]]) swap(v, adj[u][0]);
  }
}
void dfsHLD(int u) {
  in[u] = ++timer;
  if (adj[u].size()) {
    head[adj[u][0]] = head[u];
    dfsHLD(adj[u][0]);
  }
  for (auto v : adj[u])
    if (v != adj[u][0]) {
      head[v] = v;
      dfsHLD(v);
    }
  out[u] = timer;
}
int lz[N << 2];
struct node {
  int sum, mx;
  node(int sum = -n * 2, int mx = -n * 2) : sum(sum), mx(mx) {}
} tree[N << 2];
node merge(node L, node R) {
  if (L.sum == -n * 2) return R;
  if (R.sum == -n * 2) return L;
  return node(L.sum + R.sum, max(R.mx, L.mx + R.sum));
}
void build(int o, int s, int e) {
  if (s == e) {
    tree[o] = node(-1, -1);
  } else {
    int md = (s + e) >> 1;
    build(o << 1, s, md);
    build(o << 1 | 1, md + 1, e);
    tree[o] = merge(tree[o << 1], tree[o << 1 | 1]);
  }
}
void push(int o, int s, int e) {
  if (!lz[o]) return;
  tree[o] = node(-(e - s + 1), -1);
  if (s != e) {
    lz[o << 1] = lz[o << 1 | 1] = 1;
  }
  lz[o] = 0;
}
void upd(int o, int s, int e, int l, int r) {
  push(o, s, e);
  if (r < s || e < l) return;
  if (l <= s && e <= r) {
    lz[o] = 1;
    push(o, s, e);
  } else {
    int md = (s + e) >> 1;
    upd(o << 1, s, md, l, r);
    upd(o << 1 | 1, md + 1, e, l, r);
    tree[o] = merge(tree[o << 1], tree[o << 1 | 1]);
  }
}
void updIdx(int o, int s, int e, int idx, int v) {
  push(o, s, e);
  if (idx < s || e < idx) return;
  if (s == e) {
    tree[o].sum += v;
    tree[o].mx += v;
    return;
  }
  int md = (s + e) >> 1;
  updIdx(o << 1, s, md, idx, v);
  updIdx(o << 1 | 1, md + 1, e, idx, v);
  tree[o] = merge(tree[o << 1], tree[o << 1 | 1]);
}
node qry(int o, int s, int e, int l, int r) {
  push(o, s, e);
  if (r < s || e < l) return node();
  if (l <= s && e <= r) {
    return tree[o];
  }
  int md = (s + e) >> 1;
  return merge(qry(o << 1, s, md, l, r), qry(o << 1 | 1, md + 1, e, l, r));
}
node get(int u) {
  node ret = node();
  while (head[u] != 1) {
    ret = merge(qry(1, 1, n, in[head[u]], in[u]), ret);
    u = par[head[u]];
  }
  ret = merge(qry(1, 1, n, 1, in[u]), ret);
  return ret;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 2; i <= n; i++) {
    int p;
    scanf("%d", &p);
    adj[p].push_back(i);
  }
  dfs(1);
  head[1] = 1;
  dfsHLD(1);
  build(1, 1, n);
  while (q--) {
    int tp, u;
    scanf("%d%d", &tp, &u);
    if (tp == 1) {
      updIdx(1, 1, n, in[u], 1);
    } else if (tp == 2) {
      upd(1, 1, n, in[u], out[u]);
      node cur = get(u);
      if (cur.mx >= 0) {
        updIdx(1, 1, n, in[u], -cur.mx - 1);
      }
    } else {
      node cur = get(u);
      puts(cur.mx < 0 ? "white" : "black");
    }
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

A duck hunter is doing his favorite thing, hunting. He lives in a two dimensional world and is located at point (0, 0). As he doesn't like walking for his prey, he prefers to shoot only vertically up (because in this case, the ducks fall straight into his hands). The hunter doesn't reload the gun immediately — r or more seconds must pass between the shots. When the hunter shoots up, the bullet immediately hits all the ducks who are directly above the hunter.

In a two dimensional world each duck is a horizontal segment that moves horizontally in the negative direction of the Ox axis at the speed 1 length unit per second. For each duck we know the values hi and ti — the x-coordinates of its head (the left end of the segment) and its tail (the right end of the segment) at time 0. The height where the duck is flying isn't important as the gun shoots vertically up to the infinite height and hits all the ducks on its way.

<image> The figure to the first sample.

What maximum number of ducks can the hunter shoot? The duck is considered shot by the hunter if at the moment of the shot at least one of its point intersects the Oy axis. After the hunter shoots the duck, it falls and it can't be shot anymore. The hunter cannot make shots before the moment of time 0.

Input

The first line of the input contains integers n, r (1 ≤ n ≤ 200 000, 1 ≤ r ≤ 109) — the number of ducks and the minimum time in seconds between the shots.

Then n lines follow, each of them contains two integers hi, ti ( - 109 ≤ hi < ti ≤ 109) — the x-coordinate of the head and tail of the i-th duck at the moment 0.

Output

Print a single integer — the maximum number of ducks that can be shot by the hunter.

Examples

Input

3 3
-3 0
1 3
-1 2

Output

3

Input

4 5
-1 1
2 4
5 9
6 8

Output

3

Note

In the first sample the hunter must shoot at time 0, this shot kills ducks 1 and 3. Then the hunter needs to reload the gun and shoot again at time 3. His second shot hits the tail of duck 2.

In the second sample the hunter can make shots at times 0 and 6 to hit three ducks.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
struct Node {
  int mx, add;
  Node *ch[2];
  Node() {}
  Node(int mx, int add) : mx(mx), add(add) { ch[0] = ch[1] = NULL; }
};
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
    pq;
int query(Node *rt, int ql, int qr, int l = 0, int r = inf) {
  if (!rt || ql > qr) return 0;
  if (ql <= l && r <= qr) return rt->mx;
  int ret = 0, mid = l + r >> 1;
  if (ql <= mid) ret = max(ret, query(rt->ch[0], ql, qr, l, mid));
  if (qr > mid) ret = max(ret, query(rt->ch[1], ql, qr, mid + 1, r));
  return ret + rt->add;
}
void up(Node *rt) {
  rt->mx =
      max((rt->ch[0] ? rt->ch[0]->mx : 0), (rt->ch[1] ? rt->ch[1]->mx : 0)) +
      rt->add;
}
void modify(Node *&rt, int ql, int v, int l = 0, int r = inf) {
  if (!rt) rt = new Node(0, 0);
  if (l == r) {
    rt->mx = v;
  } else {
    int mid = l + r >> 1;
    if (ql <= mid)
      modify(rt->ch[0], ql, v, l, mid);
    else
      modify(rt->ch[1], ql, v, mid + 1, r);
    up(rt);
  }
}
void insert(Node *&rt, int ql, int qr, int l = 0, int r = inf) {
  if (!rt) rt = new Node(0, 0);
  if (ql <= l && r <= qr) {
    rt->mx++;
    rt->add++;
  } else {
    int mid = l + r >> 1;
    if (ql <= mid) {
      insert(rt->ch[0], ql, qr, l, mid);
    }
    if (qr > mid) {
      insert(rt->ch[1], ql, qr, mid + 1, r);
    }
    up(rt);
  }
}
int main() {
  Node *rt = new Node(0, 0);
  int n, k, l, r;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &l, &r);
    l = max(0, l);
    if (r >= 0) {
      pq.push({r, l});
      pq.push({l, -2});
    }
  }
  int pre = -1, preValue = 0;
  while (!pq.empty()) {
    int l = pq.top().second, r = pq.top().first;
    pq.pop();
    if (l < 0) {
      if (pre == r) continue;
      int v = query(rt, 0, r - k);
      if (l == -2 || v > preValue) {
        modify(rt, r, v);
        pre = r;
        preValue = v;
        if (r + k <= inf) {
          pq.push({r + k, -1});
        }
      }
    } else {
      insert(rt, l, r);
    }
  }
  printf("%d\n", rt->mx);
  return 0;
}

```