### Prompt

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

All Berland residents are waiting for an unprecedented tour of wizard in his Blue Helicopter over the cities of Berland!

It is well-known that there are n cities in Berland, some pairs of which are connected by bidirectional roads. Each pair of cities is connected by no more than one road. It is not guaranteed that the road network is connected, i.e. it is possible that you can't reach some city from some other.

The tour will contain several episodes. In each of the episodes:

  * the wizard will disembark at some city x from the Helicopter;
  * he will give a performance and show a movie for free at the city x;
  * he will drive to some neighboring city y using a road;
  * he will give a performance and show a movie for free at the city y;
  * he will drive to some neighboring to y city z;
  * he will give a performance and show a movie for free at the city z;
  * he will embark the Helicopter and fly away from the city z.

It is known that the wizard doesn't like to use roads, so he agrees to use each road at most once (regardless of direction). In other words, for road between a and b he only can drive once from a to b, or drive once from b to a, or do not use this road at all.

The wizards wants to plan as many episodes as possible without violation the above rules. Help the wizard!

Please note that the wizard can visit the same city multiple times, the restriction is on roads only.

Input

The first line contains two integers n, m (1 ≤ n ≤ 2·105, 0 ≤ m ≤ 2·105) — the number of cities and the number of roads in Berland, respectively.

The roads description follow, one in each line. Each description is a pair of two integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi), where ai and bi are the ids of the cities connected by the i-th road. It is guaranteed that there are no two roads connecting the same pair of cities. Every road is bidirectional. The cities are numbered from 1 to n.

It is possible that the road network in Berland is not connected.

Output

In the first line print w — the maximum possible number of episodes. The next w lines should contain the episodes in format x, y, z — the three integers denoting the ids of the cities in the order of the wizard's visits.

Examples

Input

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

Output

2
1 4 2
4 3 2

Input

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

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mxN = 2e5 + 5;
struct itsuki {
  int a, b, c;
};
int n, m;
vector<int> adj[mxN];
vector<itsuki> ans;
bool vis[mxN];
bool dfs(int u, int p) {
  vis[u] = 1;
  vector<int> miku;
  for (int &v : adj[u]) {
    if (v == p) continue;
    if (vis[v]) {
      if (u < v) miku.push_back(v);
    } else {
      if (dfs(v, u)) miku.push_back(v);
    }
  }
  for (int i = 0; i < miku.size() / 2; i++) {
    ans.push_back({miku[i * 2], u, miku[i * 2 + 1]});
  }
  if (miku.size() % 2 == 0) return 1;
  if (p != -1) {
    ans.push_back({p, u, miku[miku.size() - 1]});
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i, -1);
  cout << ans.size() << '\n';
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].a << ' ' << ans[i].b << ' ' << ans[i].c << '\n';
  }
}

```


### Prompt

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

Little Petya likes positive integers a lot. Recently his mom has presented him a positive integer a. There's only one thing Petya likes more than numbers: playing with little Masha. It turned out that Masha already has a positive integer b. Petya decided to turn his number a into the number b consecutively performing the operations of the following two types:

  1. Subtract 1 from his number.
  2. Choose any integer x from 2 to k, inclusive. Then subtract number (a mod x) from his number a. Operation a mod x means taking the remainder from division of number a by number x.

Petya performs one operation per second. Each time he chooses an operation to perform during the current move, no matter what kind of operations he has performed by that moment. In particular, this implies that he can perform the same operation any number of times in a row.

Now he wonders in what minimum number of seconds he could transform his number a into number b. Please note that numbers x in the operations of the second type are selected anew each time, independently of each other.

Input

The only line contains three integers a, b (1 ≤ b ≤ a ≤ 1018) and k (2 ≤ k ≤ 15).

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

Output

Print a single integer — the required minimum number of seconds needed to transform number a into number b.

Examples

Input

10 1 4

Output

6

Input

6 3 10

Output

2

Input

1000000000000000000 1 3

Output

666666666666666667

Note

In the first sample the sequence of numbers that Petya gets as he tries to obtain number b is as follows: 10  →  8  →  6  →  4  →  3  →  2  →  1.

In the second sample one of the possible sequences is as follows: 6  →  4  →  3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void err(istringstream *iss) {}
template <typename T, typename... Args>
void err(istringstream *iss, const T &varVal, const Args &...args) {
  string varName;
  *iss >> varName;
  if (varName.back() == ',') varName.back() = ' ';
  cout << varName << " = " << varVal << "; ", err(iss, args...);
}
int n, m, K, T, Q, cn;
int lcm[] = {0,   1,    2,    6,     12,    60,     60,     420,
             840, 2520, 2520, 27720, 27720, 360360, 360360, 360360};
long long a, b;
long long func(long long hi, long long lo) {
  long long ret = 0;
  while (hi > lo) {
    long long mx = 1;
    for (int i = 2; i <= K; i++) {
      if (hi % i <= hi - lo) mx = max(mx, hi % i);
    }
    hi -= mx;
    ret++;
  }
  return ret;
}
int main() {
  cin.tie(NULL);
  scanf("%lld%lld%d", &a, &b, &K);
  int l = lcm[K];
  long long x = ((b - 1) / l + 1) * l, y = a / l * l;
  printf("%lld\n", a - b <= l ? func(a, b)
                              : func(x, b) + (y / l - x / l) * func(x + l, x) +
                                    func(a, y));
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.

Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.

Input

The first line contains a single integer n (1 ≤ n ≤ 100), the number of pairs of people.

The second line contains 2n integers a_1, a_2, ..., a_{2n}. For each i with 1 ≤ i ≤ n, i appears exactly twice. If a_j = a_k = i, that means that the j-th and k-th people in the line form a couple.

Output

Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.

Examples

Input

4
1 1 2 3 3 2 4 4

Output

2

Input

3
1 1 2 2 3 3

Output

0

Input

3
3 1 2 3 1 2

Output

3

Note

In the first sample case, we can transform 1 1 2 3 3 2 4 4 → 1 1 2 3 2 3 4 4 → 1 1 2 2 3 3 4 4 in two steps. Note that the sequence 1 1 2 3 3 2 4 4 → 1 1 3 2 3 2 4 4 → 1 1 3 3 2 2 4 4 also works in the same number of steps.

The second sample case already satisfies the constraints; therefore we need 0 swaps.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
const int32_t M = 998244353;
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(2 * n);
  for (long long i = 0; i < (long long)2 * n; ++i) cin >> a[i];
  vector<long long> vis(2 * n);
  long long ans = 0;
  for (long long i = 0; i < (long long)2 * n; ++i) {
    if (!vis[a[i]]) {
      long long cnt = 0;
      for (long long j = i + 1; j < 2 * n; j++) {
        if (a[j] == a[i]) break;
        if (!vis[a[j]]) cnt++;
      }
      vis[a[i]] = 1;
      ans += cnt;
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  long long a = 1;
  while (t--) {
    solve();
    a += 1;
  }
}

```


### Prompt

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

There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to -100, while the second group is positioned in such a way that they all have integer y-coordinates, and their x-coordinate is equal to 100.

Each spaceship in both groups will simultaneously shoot two laser shots (infinite ray that destroys any spaceship it touches), one towards each of the small spaceships, all at the same time. The small spaceships will be able to avoid all the laser shots, and now want to position themselves at some locations with x=0 (with not necessarily integer y-coordinates), such that the rays shot at them would destroy as many of the enemy spaceships as possible. Find the largest numbers of spaceships that can be destroyed this way, assuming that the enemy spaceships can't avoid laser shots.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 60), the number of enemy spaceships with x = -100 and the number of enemy spaceships with x = 100, respectively.

The second line contains n integers y_{1,1}, y_{1,2}, …, y_{1,n} (|y_{1,i}| ≤ 10 000) — the y-coordinates of the spaceships in the first group.

The third line contains m integers y_{2,1}, y_{2,2}, …, y_{2,m} (|y_{2,i}| ≤ 10 000) — the y-coordinates of the spaceships in the second group.

The y coordinates are not guaranteed to be unique, even within a group.

Output

Print a single integer – the largest number of enemy spaceships that can be destroyed.

Examples

Input

3 9
1 2 3
1 2 3 7 8 9 11 12 13

Output

9

Input

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

Output

10

Note

In the first example the first spaceship can be positioned at (0, 2), and the second – at (0, 7). This way all the enemy spaceships in the first group and 6 out of 9 spaceships in the second group will be destroyed.

In the second example the first spaceship can be positioned at (0, 3), and the second can be positioned anywhere, it will be sufficient to destroy all the enemy spaceships.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int maxn = 40000 + 11;
int N, M, T, a[maxn], b[maxn], ca[maxn], cb[maxn];
bitset<62> vis1, vis2, mska[maxn], mskb[maxn];
vector<int> v;
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= N; i++) a[i] = 2 * (a[i] + 10000);
  for (int i = 1; i <= M; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= M; i++) b[i] = 2 * (b[i] + 10000);
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      mska[(a[i] + b[j]) / 2][i] = 1;
      mskb[(a[i] + b[j]) / 2][j] = 1;
      v.push_back((a[i] + b[j]) / 2);
    }
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  T = v.size();
  int ans = 0;
  for (int i = 0; i < T; i++) {
    for (int j = i; j < T; j++) {
      ans = max(ans, int((mska[v[i]] | mska[v[j]]).count() +
                         (mskb[v[i]] | mskb[v[j]]).count()));
    }
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once.

Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome.

You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of genome fragments.

Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one.

It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings.

Output

In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them.

Examples

Input

3
bcd
ab
cdef

Output

abcdef

Input

4
x
y
z
w

Output

xyzw

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct slovo {
  char sl[30];
  int dlina;
};
int tabl[26][3];
int main() {
  std::ios::sync_with_stdio(false);
  slovo mas[105];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> mas[i].sl;
    mas[i].dlina = strlen(mas[i].sl);
  }
  for (int i = 0; i < 26; i++) {
    tabl[i][0] = -1;
    tabl[i][2] = -1;
    tabl[i][1] = 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < mas[i].dlina - 1; j++) {
      tabl[int(mas[i].sl[j]) - 97][1] = int(mas[i].sl[j]);
      tabl[int(mas[i].sl[j]) - 97][2] = int(mas[i].sl[j + 1]) - 97;
      tabl[int(mas[i].sl[j + 1]) - 97][1] = int(mas[i].sl[j + 1]);
      tabl[int(mas[i].sl[j + 1]) - 97][0] = int(mas[i].sl[j] - 97);
    }
    if (mas[i].dlina == 1) {
      tabl[int(mas[i].sl[0]) - 97][1] = int(mas[i].sl[0]);
    } else if (mas[i].dlina > 1) {
      tabl[int(mas[i].sl[mas[i].dlina - 1]) - 97][0] =
          int(mas[i].sl[mas[i].dlina - 2]) - 97;
    }
  }
  int ful = 0;
  for (int i = 0; i < 26; i++)
    if (tabl[i][1] != 0) ful++;
  int ful2 = 0;
  for (int i = 0; i < 26; i++)
    if (tabl[i][1] != 0 && tabl[i][0] != -1 && tabl[i][1] != -1) ful2++;
  if (ful == ful2) {
    int st = -1;
    for (int i = 0; i < 26; i++)
      if (tabl[i][0] != -1 && tabl[i][2] != -1) {
        st = i;
        break;
      }
    if (st != -1) {
      int i = st;
      while (tabl[i][2] != -1) {
        if (tabl[i][1] >= 97) cout << char(tabl[i][1]);
        st = tabl[i][2];
        tabl[i][0] = -1;
        tabl[i][1] = 0;
        tabl[i][2] = -1;
        i = st;
      }
    }
  }
  int fl = 1;
  while (fl != 2) {
    int st = -1;
    for (int i = 0; i < 26; i++)
      if (tabl[i][0] == -1 && tabl[i][2] != -1) {
        st = i;
        break;
      }
    if (st == -1) fl = 2;
    if (st != -1) {
      int i = st;
      int vivod_posl = -1;
      while (tabl[i][2] != -1) {
        cout << char(tabl[i][1]);
        st = tabl[i][2];
        tabl[i][0] = -1;
        tabl[i][1] = 0;
        tabl[i][2] = -1;
        i = st;
        vivod_posl = 1;
      }
      if (vivod_posl == 1) {
        cout << char(tabl[i][1]);
        tabl[i][0] = -1;
        tabl[i][1] = 0;
        tabl[i][2] = -1;
      }
    }
  }
  for (int i = 0; i < 26; i++)
    if (tabl[i][1] != 0) {
      cout << char(tabl[i][1]);
      tabl[i][0] = -1;
      tabl[i][1] = 0;
      tabl[i][2] = -1;
    }
  return 0;
}

```


### Prompt

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

Problem statement

Meatishi can increase or decrease the number of fingers.
There are n buns in front of Nikunishi-kun.
Meatishi is trying to count the number of steamed buns by breaking his finger.
There are only two shapes that Nishikun's fingers can take, whether they are broken or not.
Nikunishi understands binary numbers.
Nikunishi-kun can count numbers by associating each finger with a binary digit.
Nikunishi doesn't understand the logarithm.
Find the minimum number of fingers needed to count the buns instead of Nishikun.

input

n

Constraint

* An integer
* 0 ≤ n ≤ 1018

output

Print the answer on one line, and print a newline at the end.

sample

Sample input 1

0

Sample output 1

0

Sample input 2

Four

Sample output 2

3

Sample input 3

31

Sample output 3

Five

Sample input 4

36028797018963968

Sample output 4

56

Example

Input

0

Output

0

### Response

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=1;i<n;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) REP(i,v.size())cout<<#v<<"["<<i<<"]: "<<v[i]<<endl
#define ALL(a) (a).begin(),(a).end()

int main(){
  ll n;
  cin >> n;
  int result = 0;
  while(n){
    n/=2;
    ++result;
  }
  cout << result << endl;
  return 0;
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

Bob watches TV every day. He always sets the volume of his TV to b. However, today he is angry to find out someone has changed the volume to a. Of course, Bob has a remote control that can change the volume.

There are six buttons (-5, -2, -1, +1, +2, +5) on the control, which in one press can either increase or decrease the current volume by 1, 2, or 5. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than 0.

As Bob is so angry, he wants to change the volume to b using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given a and b, finds the minimum number of presses to change the TV volume from a to b.

Input

Each test contains multiple test cases. The first line contains the number of test cases T (1 ≤ T ≤ 1 000). Then the descriptions of the test cases follow.

Each test case consists of one line containing two integers a and b (0 ≤ a, b ≤ 10^{9}) — the current volume and Bob's desired volume, respectively.

Output

For each test case, output a single integer — the minimum number of presses to change the TV volume from a to b. If Bob does not need to change the volume (i.e. a=b), then print 0.

Example

Input

3
4 0
5 14
3 9

Output

2
3
2

Note

In the first example, Bob can press the -2 button twice to reach 0. Note that Bob can not press -5 when the volume is 4 since it will make the volume negative.

In the second example, one of the optimal ways for Bob is to press the +5 twice, then press -1 once.

In the last example, Bob can press the +5 once, then press +1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  long long pos_a = 1, pos_b = 7;
  cin >> t;
  while (t--) {
    long long a, b;
    long long cnt = 0;
    long long x;
    cin >> a >> b;
    if (a == b)
      cout << "0" << endl;
    else {
      cnt = abs(a - b) / 5;
      x = abs(a - b) % 5;
      if (x == 0)
        cout << cnt << endl;
      else if (x == 1 || x == 2)
        cout << cnt + 1 << endl;
      else if (x == 3 || x == 4)
        cout << cnt + 2 << endl;
    }
  }
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

There are n Christmas trees on an infinite number line. The i-th tree grows at the position x_i. All x_i are guaranteed to be distinct.

Each integer point can be either occupied by the Christmas tree, by the human or not occupied at all. Non-integer points cannot be occupied by anything.

There are m people who want to celebrate Christmas. Let y_1, y_2, ..., y_m be the positions of people (note that all values x_1, x_2, ..., x_n, y_1, y_2, ..., y_m should be distinct and all y_j should be integer). You want to find such an arrangement of people that the value ∑_{j=1}^{m}min_{i=1}^{n}|x_i - y_j| is the minimum possible (in other words, the sum of distances to the nearest Christmas tree for all people should be minimized).

In other words, let d_j be the distance from the j-th human to the nearest Christmas tree (d_j = min_{i=1}^{n} |y_j - x_i|). Then you need to choose such positions y_1, y_2, ..., y_m that ∑_{j=1}^{m} d_j is the minimum possible.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the number of Christmas trees and the number of people.

The second line of the input contains n integers x_1, x_2, ..., x_n (-10^9 ≤ x_i ≤ 10^9), where x_i is the position of the i-th Christmas tree. It is guaranteed that all x_i are distinct.

Output

In the first line print one integer res — the minimum possible value of ∑_{j=1}^{m}min_{i=1}^{n}|x_i - y_j| (in other words, the sum of distances to the nearest Christmas tree for all people).

In the second line print m integers y_1, y_2, ..., y_m (-2 ⋅ 10^9 ≤ y_j ≤ 2 ⋅ 10^9), where y_j is the position of the j-th human. All y_j should be distinct and all values x_1, x_2, ..., x_n, y_1, y_2, ..., y_m should be distinct.

If there are multiple answers, print any of them.

Examples

Input

2 6
1 5

Output

8
-1 2 6 4 0 3

Input

3 5
0 3 1

Output

7
5 -2 4 -1 2

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> t(n);
  map<int, bool> vis;
  vector<int> ans;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> t[i];
    vis[t[i]] = 1;
  }
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      q;
  for (int i = 0; i < n; i++) {
    q.push({1, t[i] + 1}), q.push({1, t[i] - 1});
  }
  sort(t.begin(), t.end());
  while (m) {
    auto x = q.top();
    q.pop();
    if (vis[x.second]) continue;
    m--;
    vis[x.second] = 1;
    sum += x.first;
    ans.push_back(x.second);
    int cur = x.second;
    for (auto nx : {cur - 1, cur + 1}) {
      if (vis[nx]) continue;
      auto it = lower_bound(t.begin(), t.end(), nx);
      int mn = 2e9 + 1;
      if (it == t.end()) {
        mn = min(mn, nx - t.back());
      } else {
        mn = min(mn, abs(nx - *it));
        if (it != t.begin()) {
          it--;
          mn = min(mn, abs(nx - *it));
        }
      }
      q.push({mn, nx});
    }
  }
  cout << sum << "\n";
  for (auto x : ans) cout << x << " ";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
}

```


### Prompt

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

Today is Matvey's birthday. He never knows what to ask as a present so friends gave him a string s of length n. This string consists of only first eight English letters: 'a', 'b', ..., 'h'.

First question that comes to mind is: who might ever need some string? Matvey is a special boy so he instantly found what to do with this string. He used it to build an undirected graph where vertices correspond to position in the string and there is an edge between distinct positions a and b (1 ≤ a, b ≤ n) if at least one of the following conditions hold:

  1. a and b are neighbouring, i.e. |a - b| = 1.
  2. Positions a and b contain equal characters, i.e. sa = sb.

Then Matvey decided to find the diameter of this graph. Diameter is a maximum distance (length of the shortest path) among all pairs of vertices. Also, Matvey wants to find the number of pairs of vertices such that the distance between them is equal to the diameter of the graph. As he is very cool and experienced programmer he managed to solve this problem very fast. Will you do the same?

Input

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

The second line contains the string s itself. It's guaranteed that s consists of only first eight letters of English alphabet.

Output

Print two integers — the diameter of the graph and the number of pairs of positions with the distance equal to the diameter.

Examples

Input

3
abc

Output

2 1

Input

7
aaabaaa

Output

2 4

Note

Consider the second sample.

The maximum distance is 2. It's obtained for pairs (1, 4), (2, 4), (4, 6) and (4, 7).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int sp = (2 * 8 - 1);
const int lim = (1 << 8);
int n, i, j;
char s[100011];
vector<int> wh_col[8];
bool color_used[8];
queue<int> Q;
int dist[100011][8];
int dist_col[8][8];
int mask[100011];
int enabled[8][1 << 8];
int l, r;
long long best, cnt;
void compute_dist(int col) {
  int i;
  memset(color_used, 0, sizeof(color_used));
  while (!Q.empty()) Q.pop();
  for (i = 1; i <= n; i++) dist[i][col] = 10000000;
  for (auto e : wh_col[col]) dist[e][col] = 0, Q.push(e);
  while (!Q.empty()) {
    int node = Q.front();
    Q.pop();
    if (dist[node - 1][col] > dist[node][col] + 1) {
      dist[node - 1][col] = dist[node][col] + 1;
      Q.push(node - 1);
    }
    if (dist[node + 1][col] > dist[node][col] + 1) {
      dist[node + 1][col] = dist[node][col] + 1;
      Q.push(node + 1);
    }
    if (!color_used[s[node] - 'a']) {
      color_used[s[node] - 'a'] = true;
      for (auto e : wh_col[s[node] - 'a']) {
        if (dist[e][col] > dist[node][col] + 1) {
          dist[e][col] = dist[node][col] + 1;
          Q.push(e);
        }
      }
    }
  }
}
void compute_dist_col() {
  int i, j, k;
  for (i = 0; i < 8; i++)
    for (j = 0; j < 8; j++) dist_col[i][j] = (i == j ? 0 : 10000000);
  for (i = 1; i <= n; i++)
    for (j = 0; j < 8; j++)
      for (k = 0; k < 8; k++)
        dist_col[j][k] = min(dist_col[j][k], dist[i][j] + dist[i][k]);
}
void compute_mask() {
  int i, j;
  for (i = 1; i <= n; i++) {
    for (j = 0; j < 8; j++) {
      int dif = dist[i][j] - dist_col[s[i] - 'a'][j];
      if (dif > 1) cerr << "error";
      if (dif == 1) mask[i] |= 1 << j;
    }
  }
}
int get_dist(int a, int b) {
  if (a > b) swap(a, b);
  int ans = b - a;
  for (int e = 0; e < 8; e++) ans = min(ans, dist[a][e] + 1 + dist[b][e]);
  return ans;
}
void update_sol(int val, long long how_many) {
  if (how_many == 0) return;
  if (val > best) best = val, cnt = 0;
  if (val == best) cnt += how_many;
}
void go_to_color(int node, int col, int msk) {
  int best = 10000000;
  if (enabled[col][msk] == 0) return;
  for (int e = 0; e < 8; e++) {
    int aux_best = dist[node][e] + 1 + dist_col[col][e] + ((msk >> e) & 1);
    best = min(best, aux_best);
  }
  if (best >= 10000000) return;
  update_sol(best, enabled[col][msk]);
}
int main() {
  scanf("%d\n%s", &n, s + 1);
  for (i = 1; i <= n; i++) wh_col[s[i] - 'a'].push_back(i);
  for (i = 0; i < 8; i++) compute_dist(i);
  compute_dist_col();
  compute_mask();
  l = 1;
  r = min(n, sp + 1);
  for (i = sp + 2; i <= n; i++) enabled[s[i] - 'a'][mask[i]]++;
  for (i = 1; i <= n; i++) {
    if (l < i - sp && l < i) {
      enabled[s[l] - 'a'][mask[l]]++;
      l++;
    }
    if (r < i + sp && r < n) {
      r++;
      enabled[s[r] - 'a'][mask[r]]--;
    }
    for (j = l; j <= r; j++) update_sol(get_dist(i, j), 1);
    for (j = 0; j < 8; j++)
      for (int conf = 0; conf < lim; conf++) go_to_color(i, j, conf);
  }
  printf("%lld %lld", best, cnt / 2);
  return 0;
}

```


### Prompt

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

You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).

Input

The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100.

Output

Output one number — length of the longest substring that can be met in the string at least twice.

Examples

Input

abcd

Output

0

Input

ababa

Output

3

Input

zzz

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
map<string, int>::iterator it;
int main() {
  string s;
  cin >> s;
  int i, len, ans = 0, x = 0, j;
  len = s.length();
  for (i = 0; i < len; i++) {
    for (j = 1; j < len - i + 1; j++) {
      m[s.substr(i, j)]++;
    }
  }
  len = 0;
  for (it = m.begin(); it != m.end(); it++) {
    s = it->first;
    x = it->second;
    if (s.length() > len && x >= 2) {
      len = s.length();
      ans = len;
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Let S(n) denote the sum of the digits in the decimal notation of n. For example, S(123) = 1 + 2 + 3 = 6.

We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds.

Given an integer K, list the K smallest Snuke numbers.

Constraints

* 1 \leq K
* The K-th smallest Snuke number is not greater than 10^{15}.

Input

Input is given from Standard Input in the following format:

K

Output

Print K lines. The i-th line should contain the i-th smallest Snuke number.

Example

Input

10

Output

1
2
3
4
5
6
7
8
9
19

### Response

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

ll sum(ll n) {
    ll sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main() {
    ll k;
    cin >> k;
    ll ans = 1, toAdd = 1;
    while (k--) {
        cout << ans << endl;
        if (sum(ans + toAdd) * (ans + toAdd * 10) < sum(ans + toAdd * 10) * (ans + toAdd))
            toAdd *= 10;
        ans += toAdd;
    }
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

[INSPION FullBand Master - INSPION](https://www.youtube.com/watch?v=kwsciXm_7sA)

[INSPION - IOLITE-SUNSTONE](https://www.youtube.com/watch?v=kwsciXm_7sA)

On another floor of the A.R.C. Markland-N, the young man Simon "Xenon" Jackson, takes a break after finishing his project early (as always). Having a lot of free time, he decides to put on his legendary hacker "X" instinct and fight against the gangs of the cyber world.

His target is a network of n small gangs. This network contains exactly n - 1 direct links, each of them connecting two gangs together. The links are placed in such a way that every pair of gangs is connected through a sequence of direct links.

By mining data, Xenon figured out that the gangs used a form of cross-encryption to avoid being busted: every link was assigned an integer from 0 to n - 2 such that all assigned integers are distinct and every integer was assigned to some link. If an intruder tries to access the encrypted data, they will have to surpass S password layers, with S being defined by the following formula:

$$$S = ∑_{1 ≤ u < v ≤ n} mex(u, v)$$$

Here, mex(u, v) denotes the smallest non-negative integer that does not appear on any link on the unique simple path from gang u to gang v.

Xenon doesn't know the way the integers are assigned, but it's not a problem. He decides to let his AI's instances try all the passwords on his behalf, but before that, he needs to know the maximum possible value of S, so that the AIs can be deployed efficiently.

Now, Xenon is out to write the AI scripts, and he is expected to finish them in two hours. Can you find the maximum possible S before he returns?

Input

The first line contains an integer n (2 ≤ n ≤ 3000), the number of gangs in the network.

Each of the next n - 1 lines contains integers u_i and v_i (1 ≤ u_i, v_i ≤ n; u_i ≠ v_i), indicating there's a direct link between gangs u_i and v_i.

It's guaranteed that links are placed in such a way that each pair of gangs will be connected by exactly one simple path.

Output

Print the maximum possible value of S — the number of password layers in the gangs' network.

Examples

Input

3
1 2
2 3

Output

3

Input

5
1 2
1 3
1 4
3 5

Output

10

Note

In the first example, one can achieve the maximum S with the following assignment:

<image>

With this assignment, mex(1, 2) = 0, mex(1, 3) = 2 and mex(2, 3) = 1. Therefore, S = 0 + 2 + 1 = 3.

In the second example, one can achieve the maximum S with the following assignment:

<image>

With this assignment, all non-zero mex value are listed below:

  * mex(1, 3) = 1
  * mex(1, 5) = 2
  * mex(2, 3) = 1
  * mex(2, 5) = 2
  * mex(3, 4) = 1
  * mex(4, 5) = 3

Therefore, S = 1 + 2 + 1 + 2 + 1 + 3 = 10.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int c = 3002;
int n, dist[c][c], k[c][c], rf[c], f[c];
long long dp[c][c], maxi;
bool v[c];
vector<int> sz[c];
vector<pair<int, int> > d[c];
void dfs(int a) {
  v[a] = 1, rf[a] = 1;
  for (int i = 0; i < sz[a].size(); i++) {
    int x = sz[a][i];
    if (!v[x]) {
      for (int i = 1; i <= n; i++)
        if (dist[a][i]) dist[x][i] = dist[a][i] + 1;
      f[x] = a, dfs(x), rf[a] += rf[x];
      for (int i = 1; i <= n; i++)
        if (dist[x][i] && !dist[a][i]) dist[a][i] = dist[x][i] + 1;
      dist[a][x] = 1;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    sz[a].push_back(b), sz[b].push_back(a);
  }
  dfs(1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (i != j && !dist[i][j]) dist[i][j] = dist[j][i];
  for (int i = 1; i <= n; i++) dist[i][0] = c, dist[0][i] = c;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int mini = min(rf[i], rf[j]), x = dist[i][j];
      int a = rf[i], b = rf[j];
      if (dist[f[i]][j] > x)
        for (int p = 0; p < sz[i].size(); p++) {
          int q = sz[i][p];
          if (dist[q][j] < x) a = n - rf[q];
        }
      if (dist[f[j]][i] > x)
        for (int p = 0; p < sz[j].size(); p++) {
          int q = sz[j][p];
          if (dist[i][q] < x) b = n - rf[q];
        }
      k[i][j] = a * b;
      d[x].push_back({i, j});
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < d[i].size(); j++) {
      int a = d[i][j].first, b = d[i][j].second;
      dp[a][b] += k[a][b], maxi = max(maxi, dp[a][b]);
      for (int i = 0; i < sz[a].size(); i++) {
        int x = sz[a][i];
        dp[x][b] = max(dp[x][b], dp[a][b]);
      }
      for (int i = 0; i < sz[b].size(); i++) {
        int x = sz[b][i];
        dp[a][x] = max(dp[a][x], dp[a][b]);
      }
    }
  cout << maxi << "\n";
  return 0;
}

```


### Prompt

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

Consider writing each of the integers from 1 to N \times M in a grid with N rows and M columns, without duplicates. Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions:

* The largest among the values in the i-th row (1 \leq i \leq N) is A_i.
* The largest among the values in the j-th column (1 \leq j \leq M) is B_j.

For him, find the number of ways to write the numbers under these conditions, modulo 10^9 + 7.

Constraints

* 1 \leq N \leq 1000
* 1 \leq M \leq 1000
* 1 \leq A_i \leq N \times M
* 1 \leq B_j \leq N \times M
* A_i and B_j are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 A_2 ... A_{N}
B_1 B_2 ... B_{M}

Output

Print the number of ways to write the numbers under the conditions, modulo 10^9 + 7.

Examples

Input

2 2
4 3
3 4

Output

2

Input

3 3
5 9 7
3 6 9

Output

0

Input

2 2
4 4
4 4

Output

0

Input

14 13
158 167 181 147 178 151 179 182 176 169 180 129 175 168
181 150 178 179 167 180 176 169 182 177 175 159 173

Output

343772227

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,m,r[2201],c[2201],rslot[2201],cslot[2201];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>r[i];
	for(int i=1;i<=m;i++)cin>>c[i];
	sort(r+1,r+1+n);
	sort(c+1,c+1+m);
	int p1=n,p2=m;
	long long ans=1;
	for(int i=n*m,full=0;i;i--,full++)
		if(r[p1]==i&&c[p2]==i)p1--,p2--;
		else if(r[p1]==i)
		{
			p1--;
			ans=ans*(m-p2)%mod;
		}
		else if(c[p2]==i)
		{
			p2--;
			ans=ans*(n-p1)%mod;
		}
		else ans=ans*((n-p1)*(m-p2)-full)%mod;
	cout<<ans<<'\n';
}

```


### Prompt

Create a solution in CPP for the following problem:

Polycarp has a favorite sequence a[1 ... n] consisting of n integers. He wrote it out on the whiteboard as follows:

  * he wrote the number a_1 to the left side (at the beginning of the whiteboard);
  * he wrote the number a_2 to the right side (at the end of the whiteboard);
  * then as far to the left as possible (but to the right from a_1), he wrote the number a_3;
  * then as far to the right as possible (but to the left from a_2), he wrote the number a_4;
  * Polycarp continued to act as well, until he wrote out the entire sequence on the whiteboard.

<image> The beginning of the result looks like this (of course, if n ≥ 4).

For example, if n=7 and a=[3, 1, 4, 1, 5, 9, 2], then Polycarp will write a sequence on the whiteboard [3, 4, 5, 2, 9, 1, 1].

You saw the sequence written on the whiteboard and now you want to restore Polycarp's favorite sequence.

Input

The first line contains a single positive integer t (1 ≤ t ≤ 300) — the number of test cases in the test. Then t test cases follow.

The first line of each test case contains an integer n (1 ≤ n ≤ 300) — the length of the sequence written on the whiteboard.

The next line contains n integers b_1, b_2,…, b_n (1 ≤ b_i ≤ 10^9) — the sequence written on the whiteboard.

Output

Output t answers to the test cases. Each answer — is a sequence a that Polycarp wrote out on the whiteboard.

Example

Input

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

Output

3 1 4 1 5 9 2
9 1 2 7
8 2 4 4 3 9 1 7 2 8 7
42
11 7
1 1 1 1 1 1 1 1

Note

In the first test case, the sequence a matches the sequence from the statement. The whiteboard states after each step look like this:

[3] ⇒ [3, 1] ⇒ [3, 4, 1] ⇒ [3, 4, 1, 1] ⇒ [3, 4, 5, 1, 1] ⇒ [3, 4, 5, 9, 1, 1] ⇒ [3, 4, 5, 2, 9, 1, 1].

### Response

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

int main()
{
	int t, n, x, y, ch, old[300], gold[300];
	for (int i = 0; i < 300; i++)
	{
		gold[i] = 0;
		old[i] = 0;
	}
	cin >> t;
	for (int i = 1; i <= t; i++)
	{
		cin >> n;
		for (int p = 0; p < n; p++)
			cin >> old[p];
		x = 0;
		y = n - 1;
		ch = 1;
		while (ch != n + 1)
		{
			if (ch % 2 != 0)
			{
				gold[ch - 1] = old[x];
				x++;
			}
			else
			{
				gold[ch - 1] = old[y];
				y--;
			}
			ch++;
		}
		for (int p = 0; p < n; p++)
			cout << gold[p] << " ";
		cout << endl;
	}
}

```


### Prompt

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

Vasya has written some permutation p_1, p_2, …, p_n of integers from 1 to n, so for all 1 ≤ i ≤ n it is true that 1 ≤ p_i ≤ n and all p_1, p_2, …, p_n are different. After that he wrote n numbers next_1, next_2, …, next_n. The number next_i is equal to the minimal index i < j ≤ n, such that p_j > p_i. If there is no such j let's let's define as next_i = n + 1.

In the evening Vasya went home from school and due to rain, his notebook got wet. Now it is impossible to read some written numbers. Permutation and some values next_i are completely lost! If for some i the value next_i is lost, let's say that next_i = -1.

You are given numbers next_1, next_2, …, next_n (maybe some of them are equal to -1). Help Vasya to find such permutation p_1, p_2, …, p_n of integers from 1 to n, that he can write it to the notebook and all numbers next_i, which are not equal to -1, will be correct.

Input

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

Next 2 ⋅ t lines contains the description of test cases,two lines for each. The first line contains one integer n — the length of the permutation, written by Vasya (1 ≤ n ≤ 500 000). The second line contains n integers next_1, next_2, …, next_n, separated by spaces (next_i = -1 or i < next_i ≤ n + 1).

It is guaranteed, that the sum of n in all test cases doesn't exceed 500 000.

In hacks you can only use one test case, so T = 1.

Output

Print T lines, in i-th of them answer to the i-th test case.

If there is no such permutations p_1, p_2, …, p_n of integers from 1 to n, that Vasya could write, print the only number -1.

In the other case print n different integers p_1, p_2, …, p_n, separated by spaces (1 ≤ p_i ≤ n). All defined values of next_i which are not equal to -1 should be computed correctly p_1, p_2, …, p_n using defenition given in the statement of the problem. If there exists more than one solution you can find any of them.

Example

Input

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

Output

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

Note

In the first test case for permutation p = [1, 2, 3] Vasya should write next = [2, 3, 4], because each number in permutation is less than next. It's easy to see, that it is the only satisfying permutation.

In the third test case, any permutation can be the answer because all numbers next_i are lost.

In the fourth test case, there is no satisfying permutation, so the answer is -1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
constexpr int MAX_N = 524288;
int T;
int n;
array<int, 2 * MAX_N> segment;
array<int, MAX_N> nextPos;
array<int, MAX_N> answer;
vector<int> stck;
void update(int pos, int val) {
  int i = MAX_N + pos;
  segment[i] = val;
  i /= 2;
  while (i > 0) segment[i] = segment[2 * i] + segment[2 * i + 1], i /= 2;
}
void reset() {
  for (int i = 0; i < n; ++i) update(i, 0);
  for (int i = 0; i < n; ++i) nextPos[i] = 0;
  for (int i = 0; i < n; ++i) answer[i] = 0;
  stck.clear();
}
int getSum(int meFrom, int meTo, int from, int to, int pos) {
  if (from >= to) return 0;
  if (meTo <= from) return 0;
  if (to <= meFrom) return 0;
  if (from <= meFrom && meTo <= to) return segment[pos];
  int mid = (meFrom + meTo) / 2;
  return getSum(meFrom, mid, from, to, 2 * pos) +
         getSum(mid, meTo, from, to, 2 * pos + 1);
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> T;
  for (int testCase = 1; testCase <= T; ++testCase) {
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> nextPos[i];
    for (int i = 0; i < n; ++i)
      if (nextPos[i] == -1)
        nextPos[i] = i + 1;
      else
        nextPos[i] -= 1;
    bool ok = true;
    int val = n;
    for (int i = 0; i < n && ok; ++i)
      if (answer[i] == 0) {
        int nextIdx = nextPos[i];
        stck.push_back(i);
        update(i, 1);
        if (getSum(0, MAX_N, stck.back() + 1, nextIdx, 1) != 0) ok = false;
        while (nextIdx != n && answer[nextIdx] == 0 && ok) {
          stck.push_back(nextIdx);
          update(nextIdx, 1);
          nextIdx = nextPos[nextIdx];
          if (getSum(0, MAX_N, stck.back() + 1, nextIdx, 1) != 0) ok = false;
        }
        while (!stck.empty() && ok)
          answer[stck.back()] = val, val -= 1, stck.pop_back();
      }
    if (ok) {
      for (int i = 0; i < n; ++i) cout << answer[i] << ' ';
      cout << '\n';
    } else
      cout << -1 << endl;
    reset();
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Alice, Bob and Charlie are playing Card Game for Three, as below:

* At first, each of the three players has a deck consisting of some number of cards. Alice's deck has N cards, Bob's deck has M cards, and Charlie's deck has K cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged.
* The players take turns. Alice goes first.
* If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.)
* If the current player's deck is empty, the game ends and the current player wins the game.

There are 3^{N+M+K} possible patters of the three player's initial decks. Among these patterns, how many will lead to Alice's victory?

Since the answer can be large, print the count modulo 1\,000\,000\,007 (=10^9+7).

Constraints

* 1 \leq N \leq 3×10^5
* 1 \leq M \leq 3×10^5
* 1 \leq K \leq 3×10^5

Input

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

N M K

Output

Print the answer modulo 1\,000\,000\,007 (=10^9+7).

Examples

Input

1 1 1

Output

17

Input

4 2 2

Output

1227

Input

1000 1000 1000

Output

261790852

### Response

```cpp
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
const int MAXN = 9e5 + 10 , MOD = 1e9 + 7;
int fac[MAXN] , ifac[MAXN] , f3[MAXN];
void init(){
	fac[0] = fac[1] = 1;
	for(int i = 2 ; i < MAXN ; ++ i)
		fac[i] = 1ll * fac[i - 1] * i % MOD;
	ifac[0] = ifac[1] = 1;
	for(int i = 2 ; i < MAXN ; ++ i)
		ifac[i] = MOD - 1ll * ifac[MOD % i] * (MOD / i) % MOD;
	for(int i = 2 ; i < MAXN ; ++ i)
		ifac[i] = 1ll * ifac[i - 1] * ifac[i] % MOD;
	f3[0] = 1;
	for(int i = 1 ; i < MAXN ; ++ i)
		f3[i] = 1ll * f3[i - 1] * 3 % MOD;
}

int C(int a , int b){
	if(b < 0 || b > a) return 0;
	return 1ll * fac[a] * ifac[b] % MOD * ifac[a - b] % MOD;
}
int n , m , k;
int main(){
	init();
	cin >> n >> m >> k;
	int ans = 0 , last = 1 , st = 0 , ed = 0;
	for(int i = 0 ; i <= m + k ; ++ i){
		ans = (ans + 1ll * last * f3[m + k - i] % MOD * C(n + i - 1 , n - 1)) % MOD;
		last = 2ll * last % MOD;
		last = (last + C(i , st - 1)) % MOD;
		last = (last + MOD - C(i , ed)) % MOD;
		if(i - st >= m){
			last = (last + MOD - C(i + 1 , st)) % MOD;
			st ++;
		}
		if(ed < k){
			ed ++;
			last = (last + C(i + 1 , ed)) % MOD;
		}
		if(st > ed) break;
	}
	cout << ans << endl;
	return 0;
}
```


### Prompt

Please formulate a cpp solution to the following problem:

Scores of Final Examination

I am a junior high school teacher. The final examination has just finished, and I have all the students' scores of all the subjects. I want to know the highest total score among the students, but it is not an easy task as the student scores are listed separately for each subject. I would like to ask you, an excellent programmer, to help me by writing a program that finds the total score of a student with the highest total score.

Input

The input consists of multiple datasets, each in the following format.

> n m
>  p1,1 p1,2 … p1,n
>  p2,1 p2,2 … p2,n
>  …
>  pm,1 pm,2 … pm,n
>

The first line of a dataset has two integers n and m. n is the number of students (1 ≤ n ≤ 1000). m is the number of subjects (1 ≤ m ≤ 50). Each of the following m lines gives n students' scores of a subject. pj,k is an integer representing the k-th student's score of the subject j (1 ≤ j ≤ m and 1 ≤ k ≤ n). It satisfies 0 ≤ pj,k ≤ 1000.

The end of the input is indicated by a line containing two zeros. The number of datasets does not exceed 100.

Output

For each dataset, output the total score of a student with the highest total score. The total score sk of the student k is defined by sk = p1,k + … + pm,k.

Sample Input

5 2
10 20 30 40 50
15 25 35 45 55
6 3
10 20 30 15 25 35
21 34 11 52 20 18
31 15 42 10 21 19
4 2
0 0 0 0
0 0 0 0
0 0

Output for the Sample Input

105
83
0

Example

Input

5 2
10 20 30 40 50
15 25 35 45 55
6 3
10 20 30 15 25 35
21 34 11 52 20 18
31 15 42 10 21 19
4 2
0 0 0 0
0 0 0 0
0 0

Output

105
83
0

### Response

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

typedef long long ll;
#define ALL(a) a, a+sizeof(a)/sizeof(a[0])
#define all(a) a.begin(),a.end()
#define MOD 1000000007
using namespace std;
ll gcd(ll n, ll m) {
	if (m == 0) return n;
	return gcd(m, n % m);
}
ll lcm(ll n, ll m) {return m / gcd(n, m) * n;}

int main(void) {
	int n,m,tmp;
	while (1) {
		cin >> n >> m;
		if (n == 0 && m == 0) break;
		vector<int> point(n);
		for (int i = 0; i < n; i++) point[i] = 0;
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				cin >> tmp;
				point[j] += tmp;
			}
		}
		cout << *max_element(all(point)) << "\n";
	}
	return 0;
}

```


### Prompt

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

The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.

<image>

The event coordinator has a list of k participants who should be picked up at the airport. When a participant gets on the bus, he will sit in the last row with an empty seat. If there is more than one empty seat in that row, he will take the leftmost one.

In order to keep track of the people who are on the bus, the event coordinator needs a figure showing which seats are going to be taken by k participants. Your task is to draw the figure representing occupied seats.

Input

The only line of input contains integer k, (0 ≤ k ≤ 34), denoting the number of participants.

Output

Print the figure of a bus with k passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six lines. Do not output extra space or other characters.

Examples

Input

9

Output

+------------------------+
|O.O.O.#.#.#.#.#.#.#.#.|D|)
|O.O.O.#.#.#.#.#.#.#.#.|.|
|O.......................|
|O.O.#.#.#.#.#.#.#.#.#.|.|)
+------------------------+

Input

20

Output

+------------------------+
|O.O.O.O.O.O.O.#.#.#.#.|D|)
|O.O.O.O.O.O.#.#.#.#.#.|.|
|O.......................|
|O.O.O.O.O.O.#.#.#.#.#.|.|)
+------------------------+

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string a[6] = {"+------------------------+",  "|#.#.#.#.#.#.#.#.#.#.#.|D|)",
                 "|#.#.#.#.#.#.#.#.#.#.#.|.|",  "|#.......................|",
                 "|#.#.#.#.#.#.#.#.#.#.#.|.|)", "+------------------------+"};
  switch (n) {
    case 34:
      a[4][21] = 'O';
    case 33:
      a[2][21] = 'O';
    case 32:
      a[1][21] = 'O';
    case 31:
      a[4][19] = 'O';
    case 30:
      a[2][19] = 'O';
    case 29:
      a[1][19] = 'O';
    case 28:
      a[4][17] = 'O';
    case 27:
      a[2][17] = 'O';
    case 26:
      a[1][17] = 'O';
    case 25:
      a[4][15] = 'O';
    case 24:
      a[2][15] = 'O';
    case 23:
      a[1][15] = 'O';
    case 22:
      a[4][13] = 'O';
    case 21:
      a[2][13] = 'O';
    case 20:
      a[1][13] = 'O';
    case 19:
      a[4][11] = 'O';
    case 18:
      a[2][11] = 'O';
    case 17:
      a[1][11] = 'O';
    case 16:
      a[4][9] = 'O';
    case 15:
      a[2][9] = 'O';
    case 14:
      a[1][9] = 'O';
    case 13:
      a[4][7] = 'O';
    case 12:
      a[2][7] = 'O';
    case 11:
      a[1][7] = 'O';
    case 10:
      a[4][5] = 'O';
    case 9:
      a[2][5] = 'O';
    case 8:
      a[1][5] = 'O';
    case 7:
      a[4][3] = 'O';
    case 6:
      a[2][3] = 'O';
    case 5:
      a[1][3] = 'O';
    case 4:
      a[4][1] = 'O';
    case 3:
      a[3][1] = 'O';
    case 2:
      a[2][1] = 'O';
    case 1:
      a[1][1] = 'O';
  }
  for (n = 0; n < 6; n++) cout << a[n] << endl;
  return 0;
}

```


### Prompt

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

Vitya loves programming and problem solving, but sometimes, to distract himself a little, he plays computer games. Once he found a new interesting game about tanks, and he liked it so much that he went through almost all levels in one day. Remained only the last level, which was too tricky. Then Vitya remembered that he is a programmer, and wrote a program that helped him to pass this difficult level. Try do the same.

The game is organized as follows. There is a long road, two cells wide and n cells long. Some cells have obstacles. You control a tank that occupies one cell. Initially, the tank is located before the start of the road, in a cell with coordinates (0, 1). Your task is to move the tank to the end of the road, to the cell (n + 1, 1) or (n + 1, 2).

<image>

Every second the tank moves one cell to the right: the coordinate x is increased by one. When you press the up or down arrow keys, the tank instantly changes the lane, that is, the y coordinate. When you press the spacebar, the tank shoots, and the nearest obstacle along the lane in which the tank rides is instantly destroyed. In order to load a gun, the tank needs t seconds. Initially, the gun is not loaded, that means, the first shot can be made only after t seconds after the tank starts to move.

If at some point the tank is in the same cell with an obstacle not yet destroyed, it burns out. If you press the arrow exactly at the moment when the tank moves forward, the tank will first move forward, and then change the lane, so it will not be possible to move diagonally.

Your task is to find out whether it is possible to pass the level, and if possible, to find the order of actions the player need to make.

Input

The first line contains four integers n, m1, m2 and t, the length of the field, the number of obstacles in the first lane, the number of obstacles in the second lane and the number of tank steps before reloading, respectively (1 ≤ n ≤ 109; 0 ≤ m1, m2 ≤ n; 0 ≤ m1 + m2 ≤ 106; 1 ≤ t ≤ n).

The next two lines contain a description of the obstacles. The first of these lines contains m1 numbers xi — the obstacle coordinates in the first lane (1 ≤ xi ≤ n; xi < xi + 1). The y coordinate for all these obstacles will be 1.

The second line contains m2 numbers describing the obstacles of the second lane in the same format. The y coordinate of all these obstacles will be 2.

Output

In the first line print «Yes», if it is possible to pass the level, or «No», otherwise.

If it is possible, then in the second line print the number of times the tank moves from one lane to another, and in the next line print the coordinates of the transitions, one number per transition: the coordinate x (0 ≤ x ≤ n + 1). All transition coordinates coordinates must be distinct and should be output in strictly increasing order.The number of transitions should not exceed 2·106. If the tank can pass the level, then it can do it using no more than 2·106 transitions.

In the fourth line print the number of shots that the tank makes during the movement, in the following lines print two numbers, x and y coordinates of the point (1 ≤ x ≤ n, 1 ≤ y ≤ 2), from which the tank fired a shot, the number of shots must not exceed m1 + m2. Shots must be output in the order in which they are fired.

If there are several solutions, output any one.

Examples

Input

6 2 3 2
2 6
3 5 6

Output

Yes
2
0 3
2
2 2
4 1

Input

1 1 1 1
1
1

Output

No

Input

9 5 2 5
1 2 7 8 9
4 6

Output

Yes
4
0 3 5 10
1
5 2

Note

Picture for the first sample test.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
  int n, m1, m2, t;
  scanf("%d%d%d%d", &n, &m1, &m2, &t);
  map<int, int> has;
  map<int, int> change[2], change2[2];
  map<int, long long> tab[2];
  for (int i = 0; i < m1; ++i) {
    int x;
    scanf("%d", &x);
    has[x] |= 1;
  }
  for (int i = 0; i < m2; ++i) {
    int x;
    scanf("%d", &x);
    has[x] |= 2;
  }
  long long f = 0, g = INF;
  long long px = -1;
  for (auto e : has) {
    long long x = e.first;
    int typ = e.second;
    if (x > px + 1) {
      long long tf = f, tg = g;
      long long v = max(px + 1 - t, tg);
      if (v < f) {
        f = v;
        change2[0][x] = px + 1;
      }
      v = max(px + 1 - t, tf);
      if (v < g) {
        g = v;
        change2[1][x] = px + 1;
      }
    }
    if (typ == 1) {
      if (f + t < x)
        f += t;
      else
        f = INF;
      long long v = max(x - t, f);
      if (v < g) {
        g = v;
        change[1][x] = x;
      }
    } else if (typ == 2) {
      if (g + t < x)
        g += t;
      else
        g = INF;
      long long v = max(x - t, g);
      if (v < f) {
        f = v;
        change[0][x] = x;
      }
    } else {
      if (f + t < x)
        f += t;
      else
        f = INF;
      if (g + t < x)
        g += t;
      else
        g = INF;
    }
    tab[0][x] = f;
    tab[1][x] = g;
    px = x;
  }
  const long long SINF = (1LL << 40);
  if (f > SINF && g > SINF)
    printf("No\n");
  else {
    int lane = (g <= SINF);
    vector<int> transits;
    vector<pair<int, int>> shots;
    for (auto it = has.rbegin(); it != has.rend(); ++it) {
      long long x = it->first;
      int typ = it->second;
      if (change[lane][x]) {
        transits.push_back(x);
        lane = 1 - lane;
      }
      if (typ & (1 << lane)) {
        shots.push_back({tab[lane][x], lane + 1});
      }
      if (change2[lane].count(x)) {
        transits.push_back(change2[lane][x]);
        lane = 1 - lane;
      }
    }
    reverse(shots.begin(), shots.end());
    reverse(transits.begin(), transits.end());
    printf("Yes\n");
    printf("%d\n", transits.size());
    for (int x : transits) printf("%d ", x);
    printf("\n");
    printf("%d\n", shots.size());
    for (auto x : shots) printf("%d %d\n", x.first, x.second);
  }
}

```


### Prompt

Create a solution in CPP for the following problem:

Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time the date changes, this string changes as follows:

* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.

For example, if S is `1324`, it becomes `1333224444` the next day, and it becomes `133333333322224444444444444444` the day after next. You are interested in what the string looks like after 5 \times 10^{15} days. What is the K-th character from the left in the string after 5 \times 10^{15} days?

Constraints

* S is a string of length between 1 and 100 (inclusive).
* K is an integer between 1 and 10^{18} (inclusive).
* The length of the string after 5 \times 10^{15} days is at least K.

Input

Input is given from Standard Input in the following format:

S
K

Output

Print the K-th character from the left in Mr. Infinity's string after 5 \times 10^{15} days.

Examples

Input

1214
4

Output

2

Input

3
157

Output

3

Input

299792458
9460730472580800

Output

2

### Response

```cpp
#include <iostream>
#include <string>
using namespace std;
int main(){long long K,an=0;string S;cin >> S >> K;while (an<K-1&&S.at(an) == '1'){an++;}cout << S.at(an) << endl;}
```


### Prompt

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

Breaking Good is a new video game which a lot of gamers want to have. There is a certain level in the game that is really difficult even for experienced gamers.

Walter William, the main character of the game, wants to join a gang called Los Hermanos (The Brothers). The gang controls the whole country which consists of n cities with m bidirectional roads connecting them. There is no road is connecting a city to itself and for any two cities there is at most one road between them. The country is connected, in the other words, it is possible to reach any city from any other city using the given roads.

The roads aren't all working. There are some roads which need some more work to be performed to be completely functioning.

The gang is going to rob a bank! The bank is located in city 1. As usual, the hardest part is to escape to their headquarters where the police can't get them. The gang's headquarters is in city n. To gain the gang's trust, Walter is in charge of this operation, so he came up with a smart plan.

First of all the path which they are going to use on their way back from city 1 to their headquarters n must be as short as possible, since it is important to finish operation as fast as possible.

Then, gang has to blow up all other roads in country that don't lay on this path, in order to prevent any police reinforcements. In case of non-working road, they don't have to blow up it as it is already malfunctional.

If the chosen path has some roads that doesn't work they'll have to repair those roads before the operation.

Walter discovered that there was a lot of paths that satisfied the condition of being shortest possible so he decided to choose among them a path that minimizes the total number of affected roads (both roads that have to be blown up and roads to be repaired).

Can you help Walter complete his task and gain the gang's trust?

Input

The first line of input contains two integers n, m (2 ≤ n ≤ 105, <image>), the number of cities and number of roads respectively.

In following m lines there are descriptions of roads. Each description consists of three integers x, y, z (1 ≤ x, y ≤ n, <image>) meaning that there is a road connecting cities number x and y. If z = 1, this road is working, otherwise it is not.

Output

In the first line output one integer k, the minimum possible number of roads affected by gang.

In the following k lines output three integers describing roads that should be affected. Each line should contain three integers x, y, z (1 ≤ x, y ≤ n, <image>), cities connected by a road and the new state of a road. z = 1 indicates that the road between cities x and y should be repaired and z = 0 means that road should be blown up.

You may output roads in any order. Each affected road should appear exactly once. You may output cities connected by a single road in any order. If you output a road, it's original state should be different from z.

After performing all operations accroding to your plan, there should remain working only roads lying on some certain shortest past between city 1 and n.

If there are multiple optimal answers output any.

Examples

Input

2 1
1 2 0

Output

1
1 2 1

Input

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

Output

3
1 2 0
1 3 1
2 3 0

Input

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

Output

3
2 3 0
1 5 0
6 8 1

Note

In the first test the only path is 1 - 2

In the second test the only shortest path is 1 - 3 - 4

In the third test there are multiple shortest paths but the optimal is 1 - 4 - 6 - 8

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int oo = 1000000009;
const double eps = 1e-9;
const int mod = 1000000007;
int parents[100001], child[100001], cnt[100001], dst[100001];
bool visited[100001];
vector<pair<int, int> > edge[100001];
void bfs() {
  int temp, ver, pos;
  queue<int> mq;
  mq.push(1);
  for (int i = 2; i < 100001 + 1; ++i) cnt[i] = 1e9;
  visited[1] = true;
  while (!mq.empty()) {
    temp = mq.front();
    mq.pop();
    for (int i = 0; i < edge[temp].size(); ++i) {
      ver = edge[temp][i].first;
      pos = edge[temp][i].second;
      if (!visited[ver]) {
        dst[ver] = 1 + dst[temp];
        cnt[ver] = (1 - pos) + cnt[temp];
        mq.push(ver);
        visited[ver] = true;
      }
      if (dst[ver] >= 1 + dst[temp] && cnt[ver] >= cnt[temp] + !pos) {
        cnt[ver] = cnt[temp] + !pos;
        parents[ver] = temp;
      }
    }
  }
}
int main() {
  int n, m, a, b, c, z, o;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &a, &b, &c);
    edge[a].push_back(make_pair(b, c));
    edge[b].push_back(make_pair(a, c));
    if (c)
      ++o;
    else
      ++z;
  }
  bfs();
  int papa = n, ver, pos;
  cout << (o + 2 * cnt[papa] - dst[papa]) << "\n";
  while (parents[papa] != 0) {
    child[parents[papa]] = papa;
    papa = parents[papa];
  }
  for (int i = 1; i < n + 1; ++i) {
    for (int j = 0; j < edge[i].size(); ++j) {
      ver = edge[i][j].first;
      pos = edge[i][j].second;
      if (ver > i) {
        if ((child[i] == ver || child[ver] == i) && pos == 0)
          printf("%d %d 1\n", i, ver);
        else if (child[i] != ver && child[ver] != i && pos == 1)
          printf("%d %d 0\n", i, ver);
      }
    }
  }
}

```


### Prompt

Please create a solution in CPP to the following problem:

There are n glasses on the table numbered 1, …, n. The glass i can hold up to a_i units of water, and currently contains b_i units of water.

You would like to choose k glasses and collect as much water in them as possible. To that effect you can pour water from one glass to another as many times as you like. However, because of the glasses' awkward shape (and totally unrelated to your natural clumsiness), each time you try to transfer any amount of water, half of the amount is spilled on the floor.

Formally, suppose a glass i currently contains c_i units of water, and a glass j contains c_j units of water. Suppose you try to transfer x units from glass i to glass j (naturally, x can not exceed c_i). Then, x / 2 units is spilled on the floor. After the transfer is done, the glass i will contain c_i - x units, and the glass j will contain min(a_j, c_j + x / 2) units (excess water that doesn't fit in the glass is also spilled).

Each time you transfer water, you can arbitrarlly choose from which glass i to which glass j to pour, and also the amount x transferred can be any positive real number.

For each k = 1, …, n, determine the largest possible total amount of water that can be collected in arbitrarily chosen k glasses after transferring water between glasses zero or more times.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of glasses.

The following n lines describe the glasses. The i-th of these lines contains two integers a_i and b_i (0 ≤ b_i ≤ a_i ≤ 100, a_i > 0) — capacity, and water amount currently contained for the glass i, respectively.

Output

Print n real numbers — the largest amount of water that can be collected in 1, …, n glasses respectively. Your answer will be accepted if each number is within 10^{-9} absolute or relative tolerance of the precise answer.

Example

Input

3
6 5
6 5
10 2

Output

7.0000000000 11.0000000000 12.0000000000

Note

In the sample case, you can act as follows:

  * for k = 1, transfer water from the first two glasses to the third one, spilling (5 + 5) / 2 = 5 units and securing 2 + (5 + 5) / 2 = 7 units;
  * for k = 2, transfer water from the third glass to any of the first two, spilling 2 / 2 = 1 unit and securing 5 + 5 + 2 / 2 = 11 units;
  * for k = 3, do nothing. All 5 + 5 + 2 = 12 units are secured.

### Response

```cpp
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast")
using namespace std;
using ll = int64_t;
using ar2 = array<int, 2>;
template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using max_heap = priority_queue<T>;

const int thicc = 1e9 + 10, smol = -thicc;
const ll rilly_thicc = 1e18 + 10, rilly_smol = -rilly_thicc;
const int maxn = 2e2 + 10;
int a[maxn], b[maxn], dp[maxn][maxn * maxn];
int n;

void solve() {
  scanf("%d", &n);
  int sum = 0;
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]), a[i] *= 2, scanf("%d", &b[i]), b[i] *= 2, sum += b[i];
  int total = accumulate(a, a + n, 0);
  memset(dp, 0x80, sizeof(dp));
  dp[0][0] = 0;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = n; j >= 1; j--) {
      for (int k = total; k >= a[i]; --k) {
        dp[j][k] = max(dp[j][k], dp[j - 1][k - a[i]] + b[i]);
      }
    }
  }
  // for (int i = 1; i <= 60; ++i) {
  //   printf("%2d ", i);
  // }
  // puts("");
  // for (int j = 1; j <= n; ++j) {
  //   for (int k = 1; k <= 60; ++k) {
  //     printf("%2d ", dp[j][k] < 0 ? -1 : dp[j][k]);
  //   }
  //   puts("");
  // }
  // puts("");
  // printf("%d\n", dp[1][200]);
  for (int j = 1; j <= n; ++j) {
    int ans = 0;
    for (int k = 0; k <= total; ++k) {
      if (dp[j][k] >= 0) ans = max(ans, min(k, sum / 2 + dp[j][k] / 2));
    }
    printf("%.3f ", ans / 2.);
  }
}

int main() {
  int tc = 1;
  // scanf("%d", &tc);

  for (int i = 1; i <= tc; ++i) {
    // printf("Case #%d: ", i);
    solve();
  }
}
```


### Prompt

Please formulate a cpp solution to the following problem:

curtain

Summer is coming soon. You decide to redecorate your room for the summer. It is expected that the sun will be very strong this summer, and it will be a difficult season for you who are not good at dazzling. So you thought about installing a curtain on the window of the room to adjust the brightness of the room.

The curtain to be attached is rectangular and is attached so that the sides are perpendicular to or parallel to the ground. Also, the windows in your room have a very special shape and are represented by N-sided polygons where each side is parallel or perpendicular to the ground. Therefore, it is difficult to determine the area of a window that is not covered by the curtain when the curtain is attached. In order to adjust the brightness of the room, it is important to know how much the window can cover when deciding where to install the curtain. So you decided to create a program to find the area of a window that is not covered by a curtain, given the location and shape of the window and curtain.

As an example, consider the following method of installing windows and curtains. In this case, the area of the window not hidden by the curtain is 8. This example corresponds to the third case of sample input.

<image>

Input

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

> N
> x1 y1
>::
>::
> xN yN
> a1 b1
> a2 b2
> a3 b3
> a4 b4

The first line is given the integer N, which represents the number of vertices the window has (4 ≤ N ≤ 100). The following N lines are given the integer xi representing the x-coordinates of the different vertices of the window and the integer yi representing the y-coordinate (-20,000 ≤ xi, yi ≤ 20,000, 1 ≤ i ≤ N). Here, the positive direction of the y-axis is the direction rotated 90 degrees counterclockwise from the positive direction of the x-axis. In addition, the next four lines are given the integer aj, which represents the x-coordinate of the different vertices of the curtain, and the integer bj, which represents the y-coordinate (-20,000 ≤ aj, bj ≤ 20,000, 1 ≤ j ≤ 4). The vertices of both windows and curtains are given in counterclockwise order. In addition, the figures representing windows and curtains are figures without self-intersection.

The end of the input is indicated by a single 0 line.

Output

For each dataset, output the area of the window not covered by the curtain on one line. However, note that the area is always an integer value.

Sample Input

Four
0 0
10 0
10 10
0 10
0 0
5 0
5 10
0 10
6
0 0
10 0
10 5
5 5
5 10
0 10
2 0
8 0
8 10
2 10
12
1 1
13
-13
-1 1
-3 1
-3 -1
-1 -1
-13
13
1 -1
3 -1
3 1
twenty two
-twenty two
-twenty two
twenty two
Four
20000 20000
-20000 20000
-20000 -20000
20000 -20000
1000 1000
-1000 1000
-1000 -1000
1000 -1000
Four
1000 1000
-1000 1000
-1000 -1000
1000 -1000
20000 20000
-20000 20000
-20000 -20000
20000 -20000
Four
0 0
10 0
10 10
0 10
20 0
30 0
30 10
20 10
0

Output for Sample Input

50
30
8
1596000000
0
100

Example

Input

4
0 0
10 0
10 10
0 10
0 0
5 0
5 10
0 10
6
0 0
10 0
10 5
5 5
5 10
0 10
2 0
8 0
8 10
2 10
12
1 1
1 3
-1 3
-1 1
-3 1
-3 -1
-1 -1
-1 -3
1 -3
1 -1
3 -1
3 1
2 2
-2 2
-2 -2
2 -2
4
20000 20000
-20000 20000
-20000 -20000
20000 -20000
1000 1000
-1000 1000
-1000 -1000
1000 -1000
4
1000 1000
-1000 1000
-1000 -1000
1000 -1000
20000 20000
-20000 20000
-20000 -20000
20000 -20000
4
0 0
10 0
10 10
0 10
20 0
30 0
30 10
20 10
0

Output

50
30
8
1596000000
0
100

### Response

```cpp
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

int main(){
    ll n;
    while(cin>>n){
        if(n==0){break;}
    vector<pll> A(n);
    const ll C=30000;
    for(auto &I:A){cin>>I.F>>I.S; I.S+=C;}
    vector<pair<pair<ll,ll>,pll>> B;
    for(int i=1;i<=n;i++){
        if(A[i%n].F==A[i-1].F){
            if(A[i-1].S<A[i%n].S){B.push_back({{A[i%n].F,3},{A[i-1].S,A[i%n].S}});}
            else{B.push_back({{A[i%n].F,2},{A[i%n].S,A[i-1].S}});}
        }
    }
    vector<pll> S(4);
    for(auto &I:S){cin>>I.F>>I.S; I.S+=C;}
    for(int i=1;i<=4;i++){
        if(S[i%4].F==S[i-1].F){
            if(S[i-1].S<S[i%4].S){B.push_back({{S[i%4].F,1},{S[i-1].S,S[i%4].S}});}
            else{B.push_back({{S[i%4].F,0},{S[i%4].S,S[i-1].S}});}
        }
    }
    sort(B.begin(),B.end());
    vector<bool> in(2*C,false);
    vector<bool> sq(2*C,false);
    ll bef=-E;
    ll ans=0;
    for(auto &I:B){
        for(int i=0;i<2*C;i++){
            if(in[i] && !sq[i]){ans+=I.F.F-bef;}
        }
        if(I.F.S>>1&1){
            for(ll i=I.S.F;i<I.S.S;i++){in[i]=!in[i];}
        }
        else{
            for(ll i=I.S.F;i<I.S.S;i++){sq[i]=!sq[i];}
        }
        bef=I.F.F;
        //cout<<bef<<" "<<ans<<endl;
    }
    cout<<ans<<endl;
    }

    return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Problem

Yamano Mifune Gakuen's 1st grade G group is a class where female students carrying misfortune gather. They face various challenges every day with the goal of being happy.

In their class, they can take practical happiness courses as part of the test of happiness.
From Monday to Friday, there are classes from 1st to Nth, and there are M courses that can be taken.

Subject i starts from the ai period of the day of the week di (di = 0, 1, 2, 3, 4 corresponds to Monday, Tuesday, Wednesday, Thursday, and Friday, respectively), and is performed in consecutive ki frames. The degree of happiness obtained when taking the course is ti.

Each student is free to choose up to L subjects so that they do not overlap each other. How do you choose the subject to get the highest level of happiness? Please find the maximum value of happiness that can be obtained from the information of the given subject.

Constraints

* 2 ≤ N ≤ 8
* 0 ≤ M ≤ 300
* 0 ≤ L ≤ min (N × 5, M)
* 0 ≤ di ≤ 4
* 1 ≤ ai ≤ N
* 1 ≤ ki
* ai + ki --1 ≤ N
* 1 ≤ ti ≤ 100

Input

The input is given in the following format.

N M L
d1 a1 k1 t1
d2 a2 k2 t2
...
dM aM kM tM

The first line is given three integers N, M, L separated by blanks.
The four integers di, ai, ki, and ti are given on the 2nd to M + 1th lines, separated by blanks.

Output

Output the maximum value of the sum of happiness on one line.

Examples

Input

3 7 3
0 1 1 1
0 1 1 2
1 1 3 4
1 1 1 1
1 2 1 2
2 1 1 3
2 2 2 1

Output

9

Input

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

Output

13

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

// i????????????????????????,j????§????????????£???
int dp[50][50]={};

int main()
{
    int n,m,l;
    cin >>n >>m >>l;

    vector<int> s(m),g(m),w(m);
    rep(i,m)
    {
        int d,a,k;
        cin >>d >>a >>k >>w[i];

        s[i] = d*n+a-1;
        g[i] = s[i]+k;
    }

    rep(i,5*n)rep(j,l)rep(k,m)
    {
        if(i<=s[k]) dp[g[k]][j+1] = max(dp[g[k]][j+1], dp[i][j]+w[k]);
    }

    int ans = 0;
    rep(i,50)rep(j,l+1) ans = max(ans,dp[i][j]);
    cout << ans << endl;
    return 0;
}
```


### Prompt

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

There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too.

Each shark will grow some number of flowers si. For i-th shark value si is random integer equiprobably chosen in range from li to ri. Wet Shark has it's favourite prime number p, and he really likes it! If for any pair of neighbouring sharks i and j the product si·sj is divisible by p, then Wet Shark becomes happy and gives 1000 dollars to each of these sharks.

At the end of the day sharks sum all the money Wet Shark granted to them. Find the expectation of this value.

Input

The first line of the input contains two space-separated integers n and p (3 ≤ n ≤ 100 000, 2 ≤ p ≤ 109) — the number of sharks and Wet Shark's favourite prime number. It is guaranteed that p is prime.

The i-th of the following n lines contains information about i-th shark — two space-separated integers li and ri (1 ≤ li ≤ ri ≤ 109), the range of flowers shark i can produce. Remember that si is chosen equiprobably among all integers from li to ri, inclusive.

Output

Print a single real number — the expected number of dollars that the sharks receive in total. You 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

3 2
1 2
420 421
420420 420421

Output

4500.0

Input

3 5
1 4
2 3
11 14

Output

0.0

Note

A prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime.

Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities of flowers (s0, s1, s2) each shark grows:

  1. (1, 420, 420420): note that s0·s1 = 420, s1·s2 = 176576400, and s2·s0 = 420420. For each pair, 1000 dollars will be awarded to each shark. Therefore, each shark will be awarded 2000 dollars, for a total of 6000 dollars.
  2. (1, 420, 420421): now, the product s2·s0 is not divisible by 2. Therefore, sharks s0 and s2 will receive 1000 dollars, while shark s1 will receive 2000. The total is 4000.
  3. (1, 421, 420420): total is 4000
  4. (1, 421, 420421): total is 0.
  5. (2, 420, 420420): total is 6000.
  6. (2, 420, 420421): total is 6000.
  7. (2, 421, 420420): total is 6000.
  8. (2, 421, 420421): total is 4000.

The expected value is <image>.

In the second sample, no combination of quantities will garner the sharks any money.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > vec;
double func(pair<int, int> x, pair<int, int> y, int p) {
  long long total =
      (long long)(x.second - x.first + 1) * (long long)(y.second - y.first + 1);
  long long fav = 0;
  long long divU = x.second / p;
  long long divL = (x.first - 1) / p;
  fav = (divU - divL) * (long long)(y.second - y.first + 1);
  long long rem = (long long)(x.second - x.first + 1) - (divU - divL);
  divU = y.second / p;
  divL = (y.first - 1) / p;
  long long fav2 = (divU - divL) * (long long)rem;
  double inFav = fav + fav2;
  return (2000.0 * inFav) / (double)total;
}
int main() {
  int n, p;
  scanf("%d %d", &n, &p);
  for (int i = 0, l, r; i < n; i++) {
    scanf("%d %d", &l, &r);
    vec.push_back(make_pair(l, r));
  }
  vec.push_back(*vec.begin());
  double ans = 0;
  for (int i = 0; i < n; i++) ans += func(vec[i], vec[i + 1], p);
  printf("%.10lf\n", ans);
  return 0;
}

```


### Prompt

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

Vasya is reading a e-book. The file of the book consists of n pages, numbered from 1 to n. The screen is currently displaying the contents of page x, and Vasya wants to read the page y. There are two buttons on the book which allow Vasya to scroll d pages forwards or backwards (but he cannot scroll outside the book). For example, if the book consists of 10 pages, and d = 3, then from the first page Vasya can scroll to the first or to the fourth page by pressing one of the buttons; from the second page — to the first or to the fifth; from the sixth page — to the third or to the ninth; from the eighth — to the fifth or to the tenth.

Help Vasya to calculate the minimum number of times he needs to press a button to move to page y.

Input

The first line contains one integer t (1 ≤ t ≤ 10^3) — the number of testcases.

Each testcase is denoted by a line containing four integers n, x, y, d (1≤ n, d ≤ 10^9, 1 ≤ x, y ≤ n) — the number of pages, the starting page, the desired page, and the number of pages scrolled by pressing one button, respectively.

Output

Print one line for each test.

If Vasya can move from page x to page y, print the minimum number of times he needs to press a button to do it. Otherwise print -1.

Example

Input

3
10 4 5 2
5 1 3 4
20 4 19 3

Output

4
-1
5

Note

In the first test case the optimal sequence is: 4 → 2 → 1 → 3 → 5.

In the second test case it is possible to get to pages 1 and 5.

In the third test case the optimal sequence is: 4 → 7 → 10 → 13 → 16 → 19.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long Read() {
  long long 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 * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long m, x, y, n;
long long abss(long long a) { return a >= 0 ? a : -a; }
long long minn(long long a, long long b) { return a > b ? b : a; }
int main() {
  long long T = Read(), ans;
  for (int i = 1; i <= T; i++) {
    m = Read(), x = Read(), y = Read(), n = Read();
    ans = 1e9 + 7;
    if (abss(x - y) % n == 0) {
      cout << abss(x - y) / n << endl;
      ans = 0;
    } else {
      if (abss(1 - y) % n == 0)
        ans = (abss(x - 1) + n - 1) / n + abss(y - 1) / n;
      if (abss(m - y) % n == 0)
        ans = minn(ans, (abss(m - x) + n - 1) / n + abss(y - m) / n);
      if (ans == 1e9 + 7)
        cout << "-1" << endl;
      else
        cout << ans << endl;
    }
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Ali is Hamed's little brother and tomorrow is his birthday. Hamed wants his brother to earn his gift so he gave him a hard programming problem and told him if he can successfully solve it, he'll get him a brand new laptop. Ali is not yet a very talented programmer like Hamed and although he usually doesn't cheat but this time is an exception. It's about a brand new laptop. So he decided to secretly seek help from you. Please solve this problem for Ali.

An n-vertex weighted rooted tree is given. Vertex number 1 is a root of the tree. We define d(u, v) as the sum of edges weights on the shortest path between vertices u and v. Specifically we define d(u, u) = 0. Also let's define S(v) for each vertex v as a set containing all vertices u such that d(1, u) = d(1, v) + d(v, u). Function f(u, v) is then defined using the following formula:

<image>

The goal is to calculate f(u, v) for each of the q given pair of vertices. As the answer can be rather large it's enough to print it modulo 109 + 7.

Input

In the first line of input an integer n (1 ≤ n ≤ 105), number of vertices of the tree is given.

In each of the next n - 1 lines three space-separated integers ai, bi, ci (1 ≤ ai, bi ≤ n, 1 ≤ ci ≤ 109) are given indicating an edge between ai and bi with weight equal to ci.

In the next line an integer q (1 ≤ q ≤ 105), number of vertex pairs, is given.

In each of the next q lines two space-separated integers ui, vi (1 ≤ ui, vi ≤ n) are given meaning that you must calculate f(ui, vi).

It is guaranteed that the given edges form a tree.

Output

Output q lines. In the i-th line print the value of f(ui, vi) modulo 109 + 7.

Examples

Input

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

Output

10
1000000005
1000000002
23
1000000002

Input

8
1 2 100
1 3 20
2 4 2
2 5 1
3 6 1
3 7 2
6 8 5
6
1 8
2 3
5 8
2 6
4 7
6 1

Output

999968753
49796
999961271
999991235
999958569
45130

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10, mod = 1e9 + 7, lg = 16 + 2;
long long n, q, par[N][lg], sumup[N][lg], tvin[N][lg], sumin[N][lg],
    cntin[N][lg], sumst[N], tvst[N], cntst[N], updtv[N], updsum[N], updcnt[N],
    h[N];
vector<pair<long long, long long> > gr[N];
long long mrg(long long ftv, long long fsum, long long fcnt, long long add) {
  return 1ll *
         (1ll * ftv + 1ll * fsum * add % mod * 2 % mod +
          1ll * add * add % mod * fcnt % mod) %
         mod;
}
void getSt(long long v, long long par = -1) {
  for (auto p : gr[v]) {
    long long u = p.first, w = p.second;
    if (u != par) {
      getSt(u, v);
      updtv[u] = mrg(tvst[u], sumst[u], cntst[u], w),
      tvst[v] = (tvst[v] + updtv[u]) % mod;
      updsum[u] = (1ll * cntst[u] * w % mod + sumst[u]) % mod,
      sumst[v] = (sumst[v] + updsum[u]) % mod;
      updcnt[u] = cntst[u], cntst[v] = cntst[v] + updcnt[u];
    }
  }
  cntst[v]++;
}
void getPr(long long v, long long parent = -1, long long wb = -1) {
  if (parent != -1) {
    h[v] = h[parent] + 1;
    par[v][0] = parent, sumup[v][0] = wb;
    for (long long i = 1; i < lg - 1; i++)
      par[v][i] = par[par[v][i - 1]][i - 1],
      sumup[v][i] = (sumup[v][i - 1] + sumup[par[v][i - 1]][i - 1]) % mod;
    cntin[v][0] = cntst[parent] - updcnt[v],
    sumin[v][0] = (sumst[parent] - updsum[v] + mod) % mod;
    tvin[v][0] = mrg((tvst[parent] - updtv[v] + mod) % mod, sumin[v][0],
                     cntin[v][0], wb);
    sumin[v][0] = (sumin[v][0] + 1ll * cntin[v][0] * wb % mod) % mod;
    for (long long i = 1; i < lg - 1; i++) {
      cntin[v][i] = (cntin[v][i - 1] + cntin[par[v][i - 1]][i - 1]) % mod;
      sumin[v][i] = ((sumin[v][i - 1] + 1ll * sumup[v][i - 1] *
                                            cntin[par[v][i - 1]][i - 1] % mod) %
                         mod +
                     sumin[par[v][i - 1]][i - 1] % mod) %
                    mod;
      tvin[v][i] = (tvin[v][i - 1] +
                    mrg(tvin[par[v][i - 1]][i - 1], sumin[par[v][i - 1]][i - 1],
                        cntin[par[v][i - 1]][i - 1], sumup[v][i - 1])) %
                   mod;
    }
  }
  for (auto p : gr[v]) {
    long long u = p.first, w = p.second;
    if (u != parent) getPr(u, v, w);
  }
}
bool isAnc(long long v, long long u) {
  long long diff = h[v] - h[u];
  if (diff <= 0) return false;
  for (long long i = 0; i < lg - 1; i++)
    if (((diff >> i) & 1)) v = par[v][i];
  if (v == u) return true;
  return false;
}
long long AnsAnc(long long v, long long u) {
  long long pst = tvst[v], rtr = 0, sumrn = 0;
  long long diff = h[v] - h[u];
  for (long long i = lg - 1; i >= 0; i--) {
    if (((diff >> i) & 1)) {
      rtr = (rtr + mrg(tvin[v][i], sumin[v][i], cntin[v][i], sumrn)) % mod;
      sumrn = (sumrn + sumup[v][i]) % mod;
      v = par[v][i];
    }
  }
  return (rtr + pst) % mod;
}
long long getSum(long long v, long long u) {
  if (h[u] > h[v]) swap(u, v);
  long long diff = h[v] - h[u], rtr = 0;
  for (long long i = 0; i < lg - 1; i++) {
    if (((diff >> i) & 1)) rtr = (rtr + sumup[v][i]) % mod, v = par[v][i];
  }
  if (v == u) return rtr;
  for (long long i = lg - 1; i >= 0; i--) {
    if (par[v][i] != par[u][i]) {
      rtr = ((rtr + sumup[v][i]) % mod + sumup[u][i]) % mod;
      v = par[v][i], u = par[u][i];
    }
  }
  rtr = ((rtr + sumup[v][0]) % mod + sumup[u][0]) % mod;
  return rtr;
}
long long AnsN(long long v, long long u) {
  long long sum = getSum(v, u);
  return mrg(tvst[u], sumst[u], cntst[u], sum);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    long long x, y, w;
    cin >> x >> y >> w;
    x--, y--;
    gr[x].push_back({y, w});
    gr[y].push_back({x, w});
  }
  getSt(0);
  getPr(0);
  cin >> q;
  while (q--) {
    long long x, y;
    cin >> x >> y;
    x--, y--;
    long long rtr;
    if (isAnc(x, y))
      rtr = AnsAnc(x, y);
    else
      rtr = AnsN(x, y);
    long long mn = AnsAnc(x, 0);
    rtr = ((rtr * 2 - mn) % mod + mod) % mod;
    cout << rtr << "\n";
  }
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the i-th vertex gets color ci.

Now it's time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes some vertex in hands, while all the other vertices move down so that the tree becomes rooted at the chosen vertex. After that Timofey brings the tree to a trash can.

Timofey doesn't like it when many colors are mixing together. A subtree annoys him if there are vertices of different color in it. Timofey wants to find a vertex which he should take in hands so that there are no subtrees that annoy him. He doesn't consider the whole tree as a subtree since he can't see the color of the root vertex.

A subtree of some vertex is a subgraph containing that vertex and all its descendants.

Your task is to determine if there is a vertex, taking which in hands Timofey wouldn't be annoyed.

Input

The first line contains single integer n (2 ≤ n ≤ 105) — the number of vertices in the tree.

Each of the next n - 1 lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v), denoting there is an edge between vertices u and v. It is guaranteed that the given graph is a tree.

The next line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 105), denoting the colors of the vertices.

Output

Print "NO" in a single line, if Timofey can't take the tree in such a way that it doesn't annoy him.

Otherwise print "YES" in the first line. In the second line print the index of the vertex which Timofey should take in hands. If there are multiple answers, print any of them.

Examples

Input

4
1 2
2 3
3 4
1 2 1 1

Output

YES
2

Input

3
1 2
2 3
1 2 3

Output

YES
2

Input

4
1 2
2 3
3 4
1 2 1 2

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int common(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first || a.first == b.second) return a.first;
  if (a.second == b.first || a.second == b.second) return a.second;
  return -1;
}
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > data(n - 1);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    data[i] = make_pair(a, b);
  }
  int col[n];
  for (int i = 0; i < n; i++) cin >> col[i];
  pair<int, int> p1, p2;
  int status = 0;
  int cand;
  for (int i = 0; i < n - 1; i++) {
    if (col[data[i].first] != col[data[i].second]) {
      if (status == 0) {
        p1 = data[i];
        status = 1;
      } else if (status == 1) {
        p2 = data[i];
        status = 2;
        cand = common(p1, p2);
        if (cand == -1) {
          cout << "NO" << endl;
          return 0;
        }
      } else {
        if (data[i].first != cand && data[i].second != cand) {
          cout << "NO" << endl;
          return 0;
        }
      }
    }
  }
  cout << "YES" << endl;
  if (status == 0)
    cout << "1" << endl;
  else if (status == 1)
    cout << p1.first + 1 << endl;
  else
    cout << cand + 1 << endl;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.

Your task is the following: for every k ∈ [1..n], calculate the number of points with integer coordinates such that the number of segments that cover these points equals k. A segment with endpoints l_i and r_i covers point x if and only if l_i ≤ x ≤ r_i.

Input

The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments.

The next n lines contain segments. The i-th line contains a pair of integers l_i, r_i (0 ≤ l_i ≤ r_i ≤ 10^{18}) — the endpoints of the i-th segment.

Output

Print n space separated integers cnt_1, cnt_2, ..., cnt_n, where cnt_i is equal to the number of points such that the number of segments that cover these points equals to i.

Examples

Input

3
0 3
1 3
3 8

Output

6 2 1

Input

3
1 3
2 4
5 7

Output

5 2 0

Note

The picture describing the first example:

<image>

Points with coordinates [0, 4, 5, 6, 7, 8] are covered by one segment, points [1, 2] are covered by two segments and point [3] is covered by three segments.

The picture describing the second example:

<image>

Points [1, 4, 5, 6, 7] are covered by one segment, points [2, 3] are covered by two segments and there are no points covered by three segments.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
long long tot[200010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<long long, int> > v;
  for (int i = 0; i < n; i++) {
    long long l, r;
    cin >> l >> r;
    v.push_back({l, -1});
    v.push_back({r + 1, 1});
  }
  sort(v.begin(), v.end());
  long long open = 0;
  long long last = v[0].first;
  for (int i = 0; i < v.size();) {
    long long pos = v[i].first;
    tot[open] += pos - last;
    while (i < v.size() && v[i].first == pos) {
      open -= v[i].second;
      i++;
    }
    last = pos;
  }
  for (int i = 1; i <= n; i++) cout << tot[i] << " ";
  cout << '\n';
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to n.

It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti — the moment in seconds in which the task will come, ki — the number of servers needed to perform it, and di — the time needed to perform this task in seconds. All ti are distinct.

To perform the i-th task you need ki servers which are unoccupied in the second ti. After the servers begin to perform the task, each of them will be busy over the next di seconds. Thus, they will be busy in seconds ti, ti + 1, ..., ti + di - 1. For performing the task, ki servers with the smallest ids will be chosen from all the unoccupied servers. If in the second ti there are not enough unoccupied servers, the task is ignored.

Write the program that determines which tasks will be performed and which will be ignored.

Input

The first line contains two positive integers n and q (1 ≤ n ≤ 100, 1 ≤ q ≤ 105) — the number of servers and the number of tasks.

Next q lines contains three integers each, the i-th line contains integers ti, ki and di (1 ≤ ti ≤ 106, 1 ≤ ki ≤ n, 1 ≤ di ≤ 1000) — the moment in seconds in which the i-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds.

Output

Print q lines. If the i-th task will be performed by the servers, print in the i-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1.

Examples

Input

4 3
1 3 2
2 2 1
3 4 3

Output

6
-1
10

Input

3 2
3 2 3
5 1 2

Output

3
3

Input

8 6
1 3 20
4 2 1
6 5 5
10 1 1
15 3 6
21 8 8

Output

6
9
30
-1
15
36

Note

In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10).

In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n >> q;
  int arr[n + 1], indic[n + 1];
  memset(arr, -1, sizeof(arr));
  for (int x = 0; x < q; x++) {
    int t, k, d;
    cin >> t >> k >> d;
    int count = 0, sum = 0, p;
    bool cond = false;
    for (int i = 1; i <= n; i++) {
      if (count == k) {
        cond = true;
        break;
      }
      if (arr[i] == -1 || arr[i] <= t) {
        arr[i] = t + d;
        sum += i;
        indic[i] = x;
        count++;
        p = i;
      }
    }
    if (count == k) cond = true;
    if (!cond) {
      for (int i = 1; i <= n; i++) {
        if (indic[i] == x) {
          arr[i] = -1;
          indic[i] = -1;
        }
      }
      cout << -1 << endl;
    }
    if (cond) cout << sum << endl;
  }
}

```