### Prompt

Develop a solution in Cpp to the problem described below:

One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple.

Vasya noticed that the yard is a rectangular n × m field. The squares have coordinates (x, y) (1 ≤ x ≤ n, 1 ≤ y ≤ m), where x is the index of the row and y is the index of the column.

Initially Vasya stands in the square with coordinates (xc, yc). To play, he has got a list of k vectors (dxi, dyi) of non-zero length. The game goes like this. The boy considers all vectors in the order from 1 to k, and consecutively chooses each vector as the current one. After the boy has chosen a current vector, he makes the maximally possible number of valid steps in the vector's direction (it is possible that he makes zero steps).

A step is defined as one movement from the square where the boy is standing now, in the direction of the current vector. That is, if Vasya is positioned in square (x, y), and the current vector is (dx, dy), one step moves Vasya to square (x + dx, y + dy). A step is considered valid, if the boy does not go out of the yard if he performs the step.

Vasya stepped on and on, on and on until he ran out of vectors in his list. Ha had been stepping for so long that he completely forgot how many steps he had made. Help the boy and count how many steps he had made.

Input

The first input line contains two integers n and m (1 ≤ n, m ≤ 109) — the yard's sizes. The second line contains integers xc and yc — the initial square's coordinates (1 ≤ xc ≤ n, 1 ≤ yc ≤ m).

The third line contains an integer k (1 ≤ k ≤ 104) — the number of vectors. Then follow k lines, each of them contains two integers dxi and dyi (|dxi|, |dyi| ≤ 109, |dx| + |dy| ≥ 1).

Output

Print the single number — the number of steps Vasya had made.

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

Examples

Input

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

Output

4

Input

10 10
1 2
1
-1 0

Output

0

Note

In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0, - 2) and he ends up in square (4, 2). Overall, Vasya makes 4 steps.

In the second sample Vasya is initially positioned in square (1, 2) and makes 0 steps by vector ( - 1, 0), as the square with coordinates (0, 2) is located outside the yard.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
T power(T N, T P) {
  return (P == 0) ? 1 : N * power(N, P - 1);
}
template <class T>
bool inside(T a, T b, T c) {
  return (b >= a && b <= c);
}
const long long INF64 = (long long)1E16;
int distsq2d(int x1, int y1, int x2, int y2) {
  return sqr(x1 - x2) + sqr(y1 - y2);
}
double dist2d(double x1, double y1, double x2, double y2) {
  return sqrt(sqr(x1 - x2) + sqr(y1 - y2));
}
double dist3d(double x1, double y1, double z1, double x2, double y2,
              double z2) {
  return sqrt(sqr(x1 - x2) + sqr(y1 - y2) + sqr(z1 - z2));
}
long long toInt64(string s) {
  long long r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
double LOG(long long N, long long B) { return (log10l(N)) / (log10l(B)); }
string itoa(long long a) {
  if (a == 0) return "0";
  string ret;
  for (long long i = a; i > 0; i = i / 10) ret.push_back((i % 10) + 48);
  reverse(ret.begin(), ret.end());
  return ret;
}
vector<string> token(string a, string b) {
  const char *q = a.c_str();
  while (count(b.begin(), b.end(), *q)) q++;
  vector<string> oot;
  while (*q) {
    const char *e = q;
    while (*e && !count(b.begin(), b.end(), *e)) e++;
    oot.push_back(string(q, e));
    q = e;
    while (count(b.begin(), b.end(), *q)) q++;
  }
  return oot;
}
int isvowel(char s) {
  s = tolower(s);
  if (s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u') return 1;
  return 0;
}
int isupper(char s) {
  if (s >= 'A' and s <= 'Z') return 1;
  return 0;
}
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
int check(int N, int pos) { return (N & (1 << pos)); }
int toggle(int N, int pos) {
  if (check(N, pos)) return N = reset(N, pos);
  return N = Set(N, pos);
}
void pbit(int N) {
  printf("(");
  for (int i = 10; i >= 0; i--) {
    bool x = check(N, i);
    cout << x;
  }
  puts(")");
}
int fx[] = {0, 1, 0, -1};
int fy[] = {1, 0, -1, 0};
int v[10003][4];
long long abs2(long long n) {
  if (n < 0) n *= -1;
  return n;
}
int main() {
  long long r, c;
  long long x, y;
  long long k;
  cin >> r >> c >> x >> y >> k;
  long long ans = 0;
  for (int i = 1; i <= k; i++) {
    long long vx, vy, dx, dy, st;
    if (vx == 0 and vy == 0) continue;
    cin >> vx >> vy;
    if (vx < 0)
      dx = 1;
    else
      dx = r;
    if (vy < 0)
      dy = 1;
    else
      dy = c;
    if (vx == 0)
      st = abs2(dy - y) / abs2(vy);
    else if (vy == 0)
      st = abs2(dx - x) / abs2(vx);
    else
      st = min(abs2(dx - x) / abs2(vx), abs2(dy - y) / abs2(vy));
    st = abs2(st);
    x += st * vx;
    y += st * vy;
    ans += st;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Hands that shed innocent blood!

There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person kills the j-th person if and only if j < i and j ≥ i - Li.

You are given lengths of the claws. You need to find the total number of alive people after the bell rings.

Input

The first line contains one integer n (1 ≤ n ≤ 106) — the number of guilty people.

Second line contains n space-separated integers L1, L2, ..., Ln (0 ≤ Li ≤ 109), where Li is the length of the i-th person's claw.

Output

Print one integer — the total number of alive people after the bell rings.

Examples

Input

4
0 1 0 10

Output

1

Input

2
0 0

Output

2

Input

10
1 1 3 0 0 0 2 1 0 3

Output

3

Note

In first sample the last person kills everyone in front of him.

### Response

```cpp
#include <bits/stdc++.h>
const int N = 1e6 + 1;
const long long inf = (long long)1e18 + 1;
using namespace std;
long long n;
int a[N];
long long s[N], l, r;
long long ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  reverse(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    if (a[i] > 0) {
      l = i + 1;
      r = i + a[i];
    }
    r = min(n, r);
    if (l <= r) {
      s[l]++;
      s[r + 1]--;
    }
  }
  for (int i = 1; i <= n; i++) {
    s[i] += s[i - 1];
    if (s[i] == 0) {
      ans++;
    }
  }
  cout << ans;
  exit(0);
}

```


### Prompt

Develop a solution in cpp to the problem described below:

You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.

Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?

Input

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

Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).

It is guaranteed that p / q is an irreducible fraction.

Hacks. For hacks, an additional constraint of t ≤ 5 must be met.

Output

For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.

Example

Input

4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1

Output

4
10
0
-1

Note

In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.

In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.

In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.

In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long x, y, p, q;
    cin >> x >> y >> p >> q;
    if (p == q) {
      if (x == y)
        cout << "0\n";
      else
        cout << "-1\n";
      continue;
    }
    long long l = 1ll, r = 1000000000ll, m;
    while (l != r) {
      m = (l + r) / 2ll;
      if (((q * m - y) >= (p * m - x)) && ((q * m) >= y) && ((p * m) >= x))
        r = m;
      else
        l = m + 1;
    }
    if (!(((q * r - y) >= (p * r - x)) && ((q * r) >= y) && ((p * r) >= x))) {
      cout << -1 << '\n';
      continue;
    }
    cout << q * r - y << '\n';
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

You are planning to build housing on a street. There are n spots available on the street on which you can build a house. The spots are labeled from 1 to n from left to right. In each spot, you can build a house with an integer height between 0 and h.

In each spot, if a house has height a, you will gain a^2 dollars from it.

The city has m zoning restrictions. The i-th restriction says that the tallest house from spots l_i to r_i (inclusive) must be at most x_i.

You would like to build houses to maximize your profit. Determine the maximum profit possible.

Input

The first line contains three integers n, h, and m (1 ≤ n,h,m ≤ 50) — the number of spots, the maximum height, and the number of restrictions.

Each of the next m lines contains three integers l_i, r_i, and x_i (1 ≤ l_i ≤ r_i ≤ n, 0 ≤ x_i ≤ h) — left and right limits (inclusive) of the i-th restriction and the maximum possible height in that range.

Output

Print a single integer, the maximum profit you can make.

Examples

Input

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

Output

14

Input

4 10 2
2 3 8
3 4 7

Output

262

Note

In the first example, there are 3 houses, the maximum height of a house is 3, and there are 3 restrictions. The first restriction says the tallest house between 1 and 1 must be at most 1. The second restriction says the tallest house between 2 and 2 must be at most 3. The third restriction says the tallest house between 3 and 3 must be at most 2.

In this case, it is optimal to build houses with heights [1, 3, 2]. This fits within all the restrictions. The total profit in this case is 1^2 + 3^2 + 2^2 = 14.

In the second example, there are 4 houses, the maximum height of a house is 10, and there are 2 restrictions. The first restriction says the tallest house from 2 to 3 must be at most 8. The second restriction says the tallest house from 3 to 4 must be at most 7.

In this case, it's optimal to build houses with heights [10, 8, 7, 7]. We get a profit of 10^2+8^2+7^2+7^2 = 262. Note that there are two restrictions on house 3 and both of them must be satisfied. Also, note that even though there isn't any explicit restrictions on house 1, we must still limit its height to be at most 10 (h=10).

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long double E = 1e-8;
mt19937_64 rnd(time(0));
long long p1 = 31, p2 = 29, p3 = 7, p4 = rnd() % 100 + 1, md1 = MOD,
          md2 = 998244353, md3 = 998244357, md4 = rnd() % 1000000000;
long long n, m, k, h, T, x[300001], c[300001], dp[51][51][51], pen[55];
pair<long long, long long> a[300001];
long long tt[300001];
long long binpow(long long h, long long r, long long md = MOD) {
  long long l = 1;
  while (r) {
    if (r & 1) l *= h, l %= md;
    h *= h;
    h %= md;
    r /= 2;
  }
  return l;
}
long long gcd(long long x, long long y) {
  if (x < y) swap(x, y);
  while (x && y) {
    x %= y;
    swap(x, y);
  }
  return x + y;
}
struct dsu {
  long long d[200001];
  void make_set(int h) { d[h] = h; }
  long long find_set(int h) {
    if (h == d[h])
      return h;
    else
      return d[h] = find_set(d[h]);
  }
  void unite_sets(int x, int y) {
    x = find_set(x);
    y = find_set(y);
    if (x < y) swap(x, y);
    d[x] = y;
  }
};
int main() {
  cin >> n >> h >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i].first >> a[i].second >> x[i] >> c[i];
  }
  for (int q = 1; q <= n; q++)
    for (int i = 1; i <= n - q + 1; i++) {
      long long j = i + q - 1;
      for (int mid = i; mid <= j; mid++) {
        for (int ht = 0; ht <= h; ht++) pen[ht] = 0;
        for (int u = 1; u <= m; u++)
          if (a[u].first >= i && a[u].first <= mid && a[u].second >= mid &&
              a[u].second <= j)
            pen[x[u] + 1] += c[u];
        long long mxl = 0, mxr = 0;
        for (int ht = 0; ht <= h; ht++) {
          mxl = max(mxl, dp[i][mid - 1][ht]);
          mxr = max(mxr, dp[mid + 1][j][ht]);
          dp[i][j][ht] = max(mxr + mxl + ht * ht - pen[ht], dp[i][j][ht]);
          pen[ht + 1] += pen[ht];
        }
      }
    }
  long long ans = 0;
  for (int i = 0; i <= h; i++) ans = max(ans, dp[1][n][i]);
  cout << ans << "\n";
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Emuskald considers himself a master of flow algorithms. Now he has completed his most ingenious program yet — it calculates the maximum flow in an undirected graph. The graph consists of n vertices and m edges. Vertices are numbered from 1 to n. Vertices 1 and n being the source and the sink respectively.

However, his max-flow algorithm seems to have a little flaw — it only finds the flow volume for each edge, but not its direction. Help him find for each edge the direction of the flow through this edges. Note, that the resulting flow should be correct maximum flow.

More formally. You are given an undirected graph. For each it's undirected edge (ai, bi) you are given the flow volume ci. You should direct all edges in such way that the following conditions hold:

  1. for each vertex v (1 < v < n), sum of ci of incoming edges is equal to the sum of ci of outcoming edges;
  2. vertex with number 1 has no incoming edges;
  3. the obtained directed graph does not have cycles.

Input

The first line of input contains two space-separated integers n and m (2 ≤ n ≤ 2·105, n - 1 ≤ m ≤ 2·105), the number of vertices and edges in the graph. The following m lines contain three space-separated integers ai, bi and ci (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ ci ≤ 104), which means that there is an undirected edge from ai to bi with flow volume ci.

It is guaranteed that there are no two edges connecting the same vertices; the given graph is connected; a solution always exists.

Output

Output m lines, each containing one integer di, which should be 0 if the direction of the i-th edge is ai → bi (the flow goes from vertex ai to vertex bi) and should be 1 otherwise. The edges are numbered from 1 to m in the order they are given in the input.

If there are several solutions you can print any of them.

Examples

Input

3 3
3 2 10
1 2 10
3 1 5

Output

1
0
1

Input

4 5
1 2 10
1 3 10
2 3 5
4 2 15
3 4 5

Output

0
0
1
1
0

Note

In the first test case, 10 flow units pass through path <image>, and 5 flow units pass directly from source to sink: <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct edge {
  int a, b, c;
  edge(int _a = 0, int _b = 0, int _c = 0) : a(_a), b(_b), c(_c) {}
  int operator<(const edge &e) const {
    if (a == e.a) {
      return b < e.b;
    }
    return a < e.a;
  }
};
const int MAXN = 200000;
vector<edge> ve[MAXN + 10];
int S[MAXN + 10], in[MAXN + 10], U[MAXN + 10];
int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<edge> E;
  set<edge> res;
  for (int i = 0; i < (m); ++i) {
    edge tmp;
    scanf("%d%d%d", &tmp.a, &tmp.b, &tmp.c);
    --tmp.a;
    --tmp.b;
    E.push_back(tmp);
    ve[tmp.a].push_back(tmp);
    swap(tmp.a, tmp.b);
    ve[tmp.a].push_back(tmp);
  }
  for (int i = 0; i < (n); ++i) {
    for (__typeof((ve[i]).begin()) it = (ve[i]).begin(); it != (ve[i]).end();
         ++it) {
      S[i] += it->c;
    }
  }
  queue<int> Q;
  Q.push(0);
  while (!Q.empty()) {
    int v = Q.front();
    U[v] = 1;
    Q.pop();
    for (__typeof((ve[v]).begin()) it = (ve[v]).begin(); it != (ve[v]).end();
         ++it) {
      int w = it->b;
      if (U[w]) {
        continue;
      }
      res.insert(*it);
      in[w] += it->c;
      if (in[w] * 2 == S[w] && w != n - 1) {
        Q.push(w);
      }
    }
  }
  for (__typeof((E).begin()) it = (E).begin(); it != (E).end(); ++it) {
    if (res.find(*it) != res.end()) {
      puts("0");
    } else {
      puts("1");
    }
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Polycarp is playing a new computer game. This game has n stones in a row. The stone on the position i has integer power a_i. The powers of all stones are distinct.

Each turn Polycarp can destroy either stone on the first position or stone on the last position (in other words, either the leftmost or the rightmost stone). When Polycarp destroys the stone it does not exist any more.

Now, Polycarp wants two achievements. He gets them if he destroys the stone with the least power and the stone with the greatest power. Help Polycarp find out what is the minimum number of moves he should make in order to achieve his goal.

For example, if n = 5 and a = [1, 5, 4, 3, 2], then Polycarp could make the following moves:

  * Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
  * Destroy the rightmost stone. After this move a = [5, 4, 3];
  * Destroy the leftmost stone. After this move a = [4, 3]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.

Please note that in the example above, you can complete the game in two steps. For example:

  * Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
  * Destroy the leftmost stone. After this move a = [4, 3, 2]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.

Input

The first line contains an integer t (1 ≤ t ≤ 100). Then t test cases follow.

The first line of each test case contains one integer n (2 ≤ n ≤ 100) — the number of stones.

The second line contains n distinct integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n) — the power of the stones.

Output

For each test case, output the minimum number of moves required to destroy the stones with the greatest and the lowest power.

Example

Input

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

Output

2
4
5
3
2

### Response

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

signed main(){

	int tt;
	cin>>tt;
	while(tt--){

		int n;
		cin>>n;
		int arr[n+1];
		int l,r;
		int minx=INT_MAX,maxn=INT_MIN;
		for(int i=1;i<=n;i++){
			cin>>arr[i];

		   if(arr[i]<minx){
		   	l=i;
		   	minx=arr[i];
		   }
		   if(arr[i]>maxn){
		   	r=i;
		   	maxn=arr[i];
		   }

		}

 int m1=n+1-abs(r-l);

 int m2=max(l,r);
 int m3=n+1-min(l,r);

 cout<<min(m1,min(m2,m3))<<endl;

	}

	return 0;
}
```


### Prompt

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

You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic check.

Web-developers of the company Q assume that a password is complex enough, if it meets all of the following conditions:

  * the password length is at least 5 characters;
  * the password contains at least one large English letter;
  * the password contains at least one small English letter;
  * the password contains at least one digit.

You are given a password. Please implement the automatic check of its complexity for company Q.

Input

The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_".

Output

If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes).

Examples

Input

abacaba

Output

Too weak

Input

X12345

Output

Too weak

Input

CONTEST_is_STARTED!!11

Output

Correct

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int check1 = 0, check2 = 0, check3 = 0, check4 = 0, check5 = 0;
  if (s.size() >= 5) check1 = 1;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] >= 65 && s[i] <= 90) check2 = 1;
    if (s[i] >= 97 && s[i] <= 122) check3 = 1;
    if (s[i] >= 48 && s[i] <= 57) check4 = 1;
  }
  if (check1 == 1 && check2 == 1 && check3 == 1 && check4 == 1)
    cout << "Correct";
  else
    cout << "Too weak";
}

```


### Prompt

Create a solution in cpp for the following problem:

There is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of these vertices and edges has a specified weight. Vertex i has a weight of X_i; Edge i has a weight of Y_i and connects Vertex A_i and B_i.

We would like to remove zero or more edges so that the following condition is satisfied:

* For each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge.

Find the minimum number of edges that need to be removed.

Constraints

* 1 \leq N \leq 10^5
* N-1 \leq M \leq 10^5
* 1 \leq X_i \leq 10^9
* 1 \leq A_i < B_i \leq N
* 1 \leq Y_i \leq 10^9
* (A_i,B_i) \neq (A_j,B_j) (i \neq j)
* The given graph is connected.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
X_1 X_2 ... X_N
A_1 B_1 Y_1
A_2 B_2 Y_2
:
A_M B_M Y_M

Output

Find the minimum number of edges that need to be removed.

Examples

Input

4 4
2 3 5 7
1 2 7
1 3 9
2 3 12
3 4 18

Output

2

Input

6 10
4 4 1 1 1 7
3 5 19
2 5 20
4 5 8
1 6 16
2 3 9
3 6 16
3 4 1
2 6 20
2 4 19
1 2 9

Output

4

Input

10 9
81 16 73 7 2 61 86 38 90 28
6 8 725
3 10 12
1 4 558
4 9 615
5 6 942
8 9 918
2 7 720
4 7 292
7 10 414

Output

8

### Response

```cpp
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 100100;
struct edges
{
	int to, next;
	long long len;
}edge[maxn << 1];
int point[maxn] = {0}, te = 1;
void add(int a, int b, int c)
{
	te ++;
	edge[te].to = b;
	edge[te].next = point[a];
	edge[te].len = c;
	point[a] = te;
}
int n, m;
long long v[maxn];
struct E2
{
	int a, b;
	long long c;
	bool operator<(const E2 &a) const
	{
		return c < a.c;
	}
}ea[maxn];
int par[maxn];
long long sum[maxn] = {0};
bool con[maxn] = {0};
int getr(int x)
{
	if(x == par[x])
		return x;
	return par[x] = getr(par[x]);
}
void merge(int ra, int rb)
{
	if(ra == rb)
		return ;
	par[ra] = rb;
	sum[rb] += sum[ra];
}
bool flag[maxn] = {0};
void dfs(int now, long long mx)
{
	for(int e = point[now]; e; e = edge[e].next)
		if(!flag[e / 2] && edge[e].len <= mx)
		{
			//cout << now << " " << edge[e].to << " " << edge[e].len << endl;
			flag[e / 2] = 1;
			dfs(edge[e].to, mx);
		}
}
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
		cin >> v[i];
	for(int i = 1; i <= m; i ++)
		cin >> ea[i].a >> ea[i].b >> ea[i].c;
	sort(ea + 1, ea + m + 1);
	for(int i = 1; i <= n; i ++)
	{
		par[i] = i;
		sum[i] = v[i];
	}
	for(int i = 1; i <= m; i ++)
	{
		int ra = getr(ea[i].a), rb = getr(ea[i].b);
		merge(ra, rb);
		if(ea[i].c <= sum[rb])
		{
			con[i] = 1;
			//cout << i << " " << ea[i].a << " " << ea[i].b << " " << ea[i].c << endl;
		}
		add(ea[i].a, ea[i].b, ea[i].c);
		add(ea[i].b, ea[i].a, ea[i].c);
	}
	for(int i = m; i >= 1; i --)
		if(!flag[i] && con[i])
		{
			//cout << i << " " << ea[i].a << " " << ea[i].b << " " << ea[i].c << " ------------------------- " << endl;
			dfs(ea[i].a, ea[i].c);
		}
	int ans = 0;
	for(int i = 1; i <= m; i ++)
		if(!flag[i] && !con[i])
			ans ++;
	cout << ans << endl;
	return 0;
}
```


### Prompt

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

There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.

Constraints

* 1≤N≤10^5
* 1≤a_i,b_i≤10^5
* 1≤K≤b_1…+…b_n
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
a_1 b_1
:
a_N b_N

Output

Print the K-th smallest integer in the array after the N operations.

Examples

Input

3 4
1 1
2 2
3 3

Output

3

Input

10 500000
1 100000
1 100000
1 100000
1 100000
1 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000

Output

1

### Response

```cpp
#include <iostream>
#include <map>

int main()
{
	long long n, k;
	std::cin >> n >> k;

	std::map<long long, long long> m;

	for (int i = 0; i < n; i++) {
		long long a, b;
		std::cin >> a >> b;

		m[a] += b;
	}

	for (auto it : m) {
		k -= it.second;
		if (k <= 0) {
			std::cout << it.first << std::endl;
			break;
		}
	}
	return 0;
}
```


### Prompt

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

There is a square field of size n × n in which two cells are marked. These cells can be in the same row or column.

You are to mark two more cells so that they are the corners of a rectangle with sides parallel to the coordinate axes.

For example, if n=4 and a rectangular field looks like this (there are asterisks in the marked cells):

$$$ \begin{matrix} . & . & * & . \\\ . & . & . & . \\\ * & . & . & . \\\ . & . & . & . \\\ \end{matrix} $$$

Then you can mark two more cells as follows

$$$ \begin{matrix} * & . & * & . \\\ . & . & . & . \\\ * & . & * & . \\\ . & . & . & . \\\ \end{matrix} $$$

If there are several possible solutions, then print any of them.

Input

The first line contains a single integer t (1 ≤ t ≤ 400). Then t test cases follow.

The first row of each test case contains a single integer n (2 ≤ n ≤ 400) — the number of rows and columns in the table.

The following n lines each contain n characters '.' or '*' denoting empty and marked cells, respectively.

It is guaranteed that the sums of n for all test cases do not exceed 400.

It is guaranteed that there are exactly two asterisks on the field. They can be in the same row/column.

It is guaranteed that the solution exists.

Output

For each test case, output n rows of n characters — a field with four asterisks marked corresponding to the statements. If there multiple correct answers, print any of them.

Example

Input

6
4
..*.
....
*...
....
2
*.
.*
2
.*
.*
3
*.*
...
...
5
.....
..*..
.....
.*...
.....
4
....
....
*...
*...

Output

*.*.
....
*.*.
....
**
**
**
**
*.*
*.*
...
.....
.**..
.....
.**..
.....
....
....
**..
**..

### Response

```cpp
#include <iostream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <climits>
#define Buff std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll long long
#define inf LONG_LONG_MAX
#define Inf INT_MAX
#define endl "\n"

using namespace std;

const int Maxn = 1e3 + 10;
const ll Mod = 1e9 + 7;

int t, n;
char bd[Maxn][Maxn];
bool firPos1;
int posX1, posX2, posX3, posX4;
int posY1, posY2, posY3, posY4;
int dis;

void work()
{
    firPos1 = false;
    cin >> n;
    for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
    {
        cin >> bd[i][j];
        if (bd[i][j] == '*')
        {
            if (firPos1 == false)
            {
                posX1 = i;
                posY1 = j;
                firPos1 = true;
            }else
            {
                posX2 = i;
                posY2 = j;
            }
        }
    }
    if (posX2 == posX1)
    {
        dis = 1;
        if (posX1 - dis >= 1)
        {
            posX3 = posX1 - dis;
            posX4 = posX1 - dis;
            posY3 = posY1;
            posY4 = posY2;
        }else
        {
            posX3 = posX1 + dis;
            posX4 = posX1 + dis;
            posY3 = posY1;
            posY4 = posY2;
        }
    }else
    if (posY2 == posY1)
    {
        dis = 1;
        if (posY1 - dis >= 1)
        {
            posY3 = posY1 - dis;
            posY4 = posY1 - dis;
            posX3 = posX1;
            posX4 = posX2;
        }else
        {
            posY3 = posY1 + dis;
            posY4 = posY1 + dis;
            posX3 = posX1;
            posX4 = posX2;
        }
    }else
    {
        int minx = min(posX1,posX2);
        int maxx = max(posX1,posX2);
        int miny = min(posY1,posY2);
        int maxy = max(posY1,posY2);
        posX1 = minx;
        posY1 = miny;
        posX2 = minx;
        posY2 = maxy;
        posX3 = maxx;
        posY3 = miny;
        posX4 = maxx;
        posY4 = maxy;
    }
    bd[posX1][posY1] = '*';
    bd[posX2][posY2] = '*';
    bd[posX3][posY3] = '*';
    bd[posX4][posY4] = '*';
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
            cout << bd[i][j];
        cout << endl;
    }
}

int main()
{
    Buff;
    cin >> t;
    while (t--)
        work();
    return 0;
}
```


### Prompt

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

problem

Once upon a time there were settlements and many people lived there. People built buildings of various shapes and sizes. But those buildings have already been lost, only the literature and the pillars found in the ruins. Was a clue to the location of the building.

There is a description of the temple in the literature. The temple was exactly square when viewed from above, and there were pillars at its four corners. It is unknown which direction the temple was facing. Also, on the sides and inside. I don't know if there were any pillars. Archaeologists believed that among the pillars found in the ruins, the one with the largest square area must be the temple.

Since the coordinates of the position of the pillar are given, find the square with the largest area among the four pillars and write a program to output the area. Note that the sides of the square are not always parallel to the coordinate axes. Be careful.

input

The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing one zero.

On the first line, the number n of pillars found in the ruins is written.

In each of the n lines from the 2nd line to the n + 1st line, the x and y coordinates of the column are written separated by blanks.

A pillar never appears more than once.

n is an integer that satisfies 1 ≤ n ≤ 3000, and the x and y coordinates of the column are integers greater than or equal to 0 and less than or equal to 5000.

Of the scoring data, 30% of the points satisfy 1 ≤ n ≤ 100, and 60% of the points satisfy 1 ≤ n ≤ 500.

The number of datasets does not exceed 10.

output

Outputs one integer for each dataset. If there is a square with four columns, it outputs the area of the largest of those squares, and if no such square exists. Output 0.

Examples

Input

10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
0

Output

10
10

Input

None

Output

None

### Response

```cpp
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;

struct P{
	int x,y;
	P(int x_, int y_){
		x = x_; y = y_;
	}
	P(){}
};
bool exist[5001][5001];
int x[3001], y[3001];

int main(){
	int n;
	while( cin >> n , n ){
		for(int i=0 ; i < 5001 ; i++ ){
			for(int j=0 ; j < 5001 ; j++ ){
				exist[i][j] = false;
			}
		}
		for(int i=0 ; i < n ; i++ ){
			cin >> x[i] >> y[i];
			exist[y[i]][x[i]] = true;
		}
		int ans = 0;
		for(int i=0 ; i < n ; i++ ){
			for(int j=i+1 ; j < n ; j++ ){
				P p1 = P( x[i] , y[i] );
				P p2 = P( x[j] , y[j] );
				int dx = abs(p1.x - p2.x);
				int dy = abs(p1.y - p2.y);
				P p3( p2.x - dy , p2.y + dx );
				P p4( p1.x - dy , p1.y + dx );
				if( p3.x < 0 || p3.x > 5000 || p3.y < 0 || p3.y > 5000 ) continue;
				if( p4.x < 0 || p4.x > 5000 || p4.y < 0 || p4.y > 5000 ) continue;
				if( exist[p3.y][p3.x] && exist[p4.y][p4.x] ){
					ans = max( ans , dx*dx + dy*dy );
				}
				p3 = P( p1.x + dy , p1.y - dx );
				p4 = P( p2.x + dy , p2.y - dx );
				if( p3.x < 0 || p3.x > 5000 || p3.y < 0 || p3.y > 5000 ) continue;
				if( p4.x < 0 || p4.x > 5000 || p4.y < 0 || p4.y > 5000 ) continue;
				if( exist[p3.y][p3.x] && exist[p4.y][p4.x] ){
					ans = max( ans , dx*dx + dy*dy );
				}
			}
		}
		cout << ans << endl;
	}
}
```


### Prompt

Develop a solution in cpp to the problem described below:

Let's consider a table consisting of n rows and n columns. The cell located at the intersection of i-th row and j-th column contains number i × j. The rows and columns are numbered starting from 1.

You are given a positive integer x. Your task is to count the number of cells in a table that contain number x.

Input

The single line contains numbers n and x (1 ≤ n ≤ 105, 1 ≤ x ≤ 109) — the size of the table and the number that we are looking for in the table.

Output

Print a single number: the number of times x occurs in the table.

Examples

Input

10 5

Output

2

Input

6 12

Output

4

Input

5 13

Output

0

Note

A table for the second sample test is given below. The occurrences of number 12 are marked bold.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long int n, m, i = 0, a, counter = 0;
  cin >> n >> m;
  for (i = n; i >= 1; --i) {
    if (m % i == 0) break;
  }
  a = m / i;
  if (a <= n) {
    for (int j = a; j <= i; ++j) {
      if (m % j == 0) counter++;
    }
  }
  cout << counter;
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.

Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.

Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.

Input

A single line contains integer n (1 ≤ n ≤ 2000) — the number of buttons the lock has.

Output

In a single line print the number of times Manao has to push a button in the worst-case scenario.

Examples

Input

2

Output

3

Input

3

Output

7

Note

Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, t = 0;
  cin >> n;
  if (n == 1) {
    cout << "1";
    return 0;
  }
  for (int i = 2; i < n; i++) t += 1 + i * (n - i);
  cout << t + n + 1;
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

You are given $n$ packages of $w_i$ kg from a belt conveyor in order ($i = 0, 1, ... n-1$). You should load all packages onto $k$ trucks which have the common maximum load $P$. Each truck can load consecutive packages (more than or equals to zero) from the belt conveyor unless the total weights of the packages in the sequence does not exceed the maximum load $P$.

Write a program which reads $n$, $k$ and $w_i$, and reports the minimum value of the maximum load $P$ to load all packages from the belt conveyor.

Constraints

* $1 \leq n \leq 100,000$
* $1 \leq k \leq 100,000$
* $1 \leq w_i \leq 10,000$

Input

In the first line, two integers $n$ and $k$ are given separated by a space character. In the following $n$ lines, $w_i$ are given respectively.

Output

Print the minimum value of $P$ in a line.

Examples

Input

5 3
8
1
7
3
9

Output

10

Input

4 2
1
2
2
6

Output

6

### Response

```cpp
#include <iostream>
using namespace std;
#define MAX 100000
typedef long long ll;

int n,k;
ll T[MAX];
int check(ll p)
{
	int i = 0;
	for (int j = 0; j < k; ++j)
	{
		ll s = 0;
		while(s+T[i] <= p)
		{
			s+=T[i];
			i++;
			if(i==n) return i;
		}
	}
	return i;
}
int slove()
{
	ll left = 0;
	ll right = 100000 * 10000;
	while(left < right)
	{
		ll mid = left+(right-left)/2;
		int v = check(mid);
		if(v >= n) right = mid;
		else left = mid+1;
	}
	return right;
}

int main(int argc, char const *argv[])
{
	cin>>n>>k;
	for (int i = 0; i < n; ++i)
	{
		cin>>T[i];
	}
	ll ans = slove();
	cout<<ans<<endl;
	return 0;
}
```


### Prompt

Please create a solution in Cpp to the following problem:

You are given a connected undirected simple graph, which has N vertices and M edges. The vertices are numbered 1 through N, and the edges are numbered 1 through M. Edge i connects vertices A_i and B_i. Your task is to find a path that satisfies the following conditions:

* The path traverses two or more vertices.
* The path does not traverse the same vertex more than once.
* A vertex directly connected to at least one of the endpoints of the path, is always contained in the path.

It can be proved that such a path always exists. Also, if there are more than one solution, any of them will be accepted.

Constraints

* 2 \leq N \leq 10^5
* 1 \leq M \leq 10^5
* 1 \leq A_i < B_i \leq N
* The given graph is connected and simple (that is, for every pair of vertices, there is at most one edge that directly connects them).

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
:
A_M B_M

Output

Find one path that satisfies the conditions, and print it in the following format. In the first line, print the count of the vertices contained in the path. In the second line, print a space-separated list of the indices of the vertices, in order of appearance in the path.

Examples

Input

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

Output

4
2 3 1 4

Input

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

Output

7
1 2 3 4 5 6 7

### Response

```cpp
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
typedef long long ll;
const long long llinf=LLONG_MAX;
const int inf=LONG_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
int n,m,i,x,y,viz[nmax];
vector<int>a[nmax],ans;
void dfs(int x)
{
	if(!viz[x])ans.pb(x);
	viz[x]=1;
	for(i=0;i<a[x].size();i++)
	 if(!viz[a[x][i]])
	 {
	 	dfs(a[x][i]);
	 	break;
	 }
}
int main()
{
	//freopen("sol.in","r",stdin);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>m;
	while(m--)
	{
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	dfs(1);
	reverse(ans.begin(),ans.end());
	dfs(1);
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)cout<<ans[i]<<" ";cout<<endl;
	return 0;
}
```


### Prompt

Create a solution in CPP for the following problem:

Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.

One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.

Input

The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.

Output

Output the least super lucky number that is more than or equal to n.

Examples

Input

4500

Output

4747

Input

47

Output

47

### Response

```cpp
#include <bits/stdc++.h>
const int maxn = 1e5 + 10;
using namespace std;
char str[maxn], ans[maxn];
int n, a[maxn];
bool dfs(int pos, int cnt4, int cnt7, bool flag) {
  if (pos == n) return true;
  if (flag) {
    for (int i = 1; i <= cnt4; i++) ans[pos++] = '4';
    for (int i = 1; i <= cnt7; i++) ans[pos++] = '7';
    return true;
  }
  if (a[pos] <= 4 && cnt4) {
    if (dfs(pos + 1, cnt4 - 1, cnt7, a[pos] < 4)) {
      ans[pos] = '4';
      return true;
    }
  }
  if (a[pos] <= 7 && cnt7) {
    if (dfs(pos + 1, cnt4, cnt7 - 1, a[pos] < 7)) {
      ans[pos] = '7';
      return true;
    }
  }
  return false;
}
int main() {
  scanf("%s", str);
  n = strlen(str);
  for (int i = 0; i < n; i++) a[i] = str[i] - '0';
  if (n & 1) {
    int temp = (n + 1) / 2;
    for (int i = 1; i <= temp; i++) cout << 4;
    for (int i = 1; i <= temp; i++) cout << 7;
    return 0;
  } else if (!dfs(0, n / 2, n / 2, 0)) {
    int temp = (n + 2) / 2;
    for (int i = 1; i <= temp; i++) cout << 4;
    for (int i = 1; i <= temp; i++) cout << 7;
    return 0;
  }
  for (int i = 0; i < n; i++) printf("%c", ans[i]);
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?

Input

The first line contains integer n (3 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the i-th number in the list is the number of rounds the i-th person wants to play.

Output

In a single line print a single integer — the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.

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

Examples

Input

3
3 2 2

Output

4

Input

4
2 2 2 2

Output

3

Note

You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, i, a[120000], sm, b, ans;
int main() {
  while (scanf("%I64d", &n) == 1) {
    for (i = 0; i < n; i++) scanf("%I64d", &a[i]);
    sort(a, a + n);
    sm = 0;
    for (i = 1; i < n - 1; i++) sm += (a[n - 1] - a[i]);
    if (sm >= a[0])
      printf("%I64d\n", a[n - 1]);
    else {
      ans = a[0];
      b = a[0] - sm;
      ans += b / (n - 1);
      if (b % (n - 1) == 0)
        ans += a[n - 1] - a[0];
      else
        ans += (a[n - 1] - a[0]) + 1;
      printf("%I64d\n", ans);
    }
  }
  return 0;
}

```


### Prompt

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

You are given an integer array a_1, a_2, …, a_n.

The array b is called to be a subsequence of a if it is possible to remove some elements from a to get b.

Array b_1, b_2, …, b_k is called to be good if it is not empty and for every i (1 ≤ i ≤ k) b_i is divisible by i.

Find the number of good subsequences in a modulo 10^9 + 7.

Two subsequences are considered different if index sets of numbers included in them are different. That is, the values of the elements do not matter in the comparison of subsequences. In particular, the array a has exactly 2^n - 1 different subsequences (excluding an empty subsequence).

Input

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

The next line contains integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^6).

Output

Print exactly one integer — the number of good subsequences taken modulo 10^9 + 7.

Examples

Input

2
1 2

Output

3

Input

5
2 2 1 22 14

Output

13

Note

In the first example, all three non-empty possible subsequences are good: \{1\}, \{1, 2\}, \{2\}

In the second example, the possible good subsequences are: \{2\}, \{2, 2\}, \{2, 22\}, \{2, 14\}, \{2\}, \{2, 22\}, \{2, 14\}, \{1\}, \{1, 22\}, \{1, 14\}, \{22\}, \{22, 14\}, \{14\}.

Note, that some subsequences are listed more than once, since they occur in the original array multiple times.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void SolveA() {
  int n, S;
  cin >> n >> S;
  cout << (S + n - 1) / n;
}
void SolveB() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  size_t n, m;
  cin >> n >> m;
  vector<long long> v(n);
  for (size_t i = 0; i < n; ++i) cin >> v[i];
  make_heap(v.begin(), v.end());
  sort_heap(v.begin(), v.end());
  reverse(v.begin(), v.end());
  long long covered = 1;
  long long y = v[0] - 1;
  for (size_t i = 1; i < n; ++i) {
    if (y > v[i]) y = v[i];
    if (y > 0) {
      ++covered;
      --y;
    }
  }
  long long sum = 0;
  for (size_t i = 0; i < n; ++i) sum += v[i];
  long long kept = v[0] + n - covered;
  cout << sum - kept;
}
void SolveC() {
  const long long MOD = 1000000007;
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  size_t n;
  cin >> n;
  vector<int_least32_t> a(n);
  vector<pair<int_least32_t, int_least32_t> > v;
  vector<int> minDiv(1000001, 0);
  for (int i = 2; i <= 1000000; ++i)
    if (minDiv[i] == 0)
      for (int tmp = 2 * i; tmp <= 1000000; tmp += i) minDiv[tmp] = i;
  vector<int_least32_t> oldDivs, newDivs;
  vector<size_t> nextPos(1000001, 0);
  for (size_t i = 0; i < n; ++i) {
    int_least32_t x;
    cin >> x;
    a[i] = x;
    oldDivs.clear();
    oldDivs.push_back(1);
    while (x > 1) {
      int_least32_t p = (minDiv[x] == 0) ? x : minDiv[x];
      size_t cnt = 0;
      while (minDiv[x] == p || x == p) {
        ++cnt;
        x /= p;
      }
      newDivs.clear();
      for (size_t j = 0; j < oldDivs.size(); ++j) {
        int_least32_t v = oldDivs[j];
        newDivs.push_back(v);
        for (size_t k = 0; k < cnt; ++k) {
          v *= p;
          newDivs.push_back(v);
        }
      }
      oldDivs.swap(newDivs);
    }
    for (size_t j = 0; j < oldDivs.size(); ++j) ++nextPos[oldDivs[j]];
  }
  size_t totalCount = 0;
  for (size_t i = 1; i <= 1000000; ++i) {
    size_t tmp = totalCount + nextPos[i];
    nextPos[i] = totalCount;
    totalCount = tmp;
  }
  v.resize(totalCount);
  for (size_t i = 0; i < n; ++i) {
    int_least32_t x = a[i];
    oldDivs.clear();
    oldDivs.push_back(1);
    while (x > 1) {
      int_least32_t p = (minDiv[x] == 0) ? x : minDiv[x];
      size_t cnt = 0;
      while (minDiv[x] == p || x == p) {
        ++cnt;
        x /= p;
      }
      newDivs.clear();
      for (size_t j = 0; j < oldDivs.size(); ++j) {
        int_least32_t v = oldDivs[j];
        newDivs.push_back(v);
        for (size_t k = 0; k < cnt; ++k) {
          v *= p;
          newDivs.push_back(v);
        }
      }
      oldDivs.swap(newDivs);
    }
    for (size_t j = 0; j < oldDivs.size(); ++j)
      v[nextPos[oldDivs[j]]++] = make_pair(oldDivs[j], i);
  }
  long long ans = n;
  vector<int_least32_t> prevPos, curPos;
  vector<long long> prevVal, curVal;
  for (size_t i = 0; i < n; ++i) {
    prevPos.push_back(i);
    prevVal.push_back(1);
  }
  size_t iCur = n;
  for (int_least32_t div = 2; div <= 1000000; ++div) {
    curPos.clear();
    curVal.clear();
    long long curSum = 0;
    size_t iNextPrev = 0;
    for (; iCur < v.size() && v[iCur].first == div; ++iCur) {
      while (iNextPrev < prevPos.size() &&
             prevPos[iNextPrev] < v[iCur].second) {
        curSum += prevVal[iNextPrev];
        ++iNextPrev;
      }
      curPos.push_back(v[iCur].second);
      curVal.push_back(curSum % MOD);
    }
    for (size_t i = 0; i < curVal.size(); ++i) ans += curVal[i];
    ans = ans % MOD;
    if (curPos.empty()) break;
    curVal.swap(prevVal);
    curPos.swap(prevPos);
  }
  cout << ans;
}
void SolveD() {}
void SolveE() {}
int main() {
  SolveC();
  return 0;
}

```


### Prompt

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

Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?

Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs to him as they all looked the same!

The storehouse is represented as matrix n × m. Every sofa takes two neighbouring by some side cells. No cell is covered by more than one sofa. There can be empty cells.

Sofa A is standing to the left of sofa B if there exist two such cells a and b that xa < xb, a is covered by A and b is covered by B. Sofa A is standing to the top of sofa B if there exist two such cells a and b that ya < yb, a is covered by A and b is covered by B. Right and bottom conditions are declared the same way.

Note that in all conditions A ≠ B. Also some sofa A can be both to the top of another sofa B and to the bottom of it. The same is for left and right conditions.

The note also stated that there are cntl sofas to the left of Grandpa Maks's sofa, cntr — to the right, cntt — to the top and cntb — to the bottom.

Grandpa Maks asks you to help him to identify his sofa. It is guaranteed that there is no more than one sofa of given conditions.

Output the number of Grandpa Maks's sofa. If there is no such sofa that all the conditions are met for it then output -1.

Input

The first line contains one integer number d (1 ≤ d ≤ 105) — the number of sofas in the storehouse.

The second line contains two integer numbers n, m (1 ≤ n, m ≤ 105) — the size of the storehouse.

Next d lines contains four integer numbers x1, y1, x2, y2 (1 ≤ x1, x2 ≤ n, 1 ≤ y1, y2 ≤ m) — coordinates of the i-th sofa. It is guaranteed that cells (x1, y1) and (x2, y2) have common side, (x1, y1)  ≠  (x2, y2) and no cell is covered by more than one sofa.

The last line contains four integer numbers cntl, cntr, cntt, cntb (0 ≤ cntl, cntr, cntt, cntb ≤ d - 1).

Output

Print the number of the sofa for which all the conditions are met. Sofas are numbered 1 through d as given in input. If there is no such sofa then print -1.

Examples

Input

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

Output

1

Input

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

Output

2

Input

2
2 2
2 1 1 1
1 2 2 2
1 0 0 0

Output

-1

Note

Let's consider the second example.

  * The first sofa has 0 to its left, 2 sofas to its right ((1, 1) is to the left of both (5, 5) and (5, 4)), 0 to its top and 2 to its bottom (both 2nd and 3rd sofas are below).
  * The second sofa has cntl = 2, cntr = 1, cntt = 2 and cntb = 0.
  * The third sofa has cntl = 2, cntr = 1, cntt = 1 and cntb = 1.

So the second one corresponds to the given conditions.

In the third example

  * The first sofa has cntl = 1, cntr = 1, cntt = 0 and cntb = 1.
  * The second sofa has cntl = 1, cntr = 1, cntt = 1 and cntb = 0.

And there is no sofa with the set (1, 0, 0, 0) so the answer is -1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int D, N, M, cnt[4];
int mp[100005][4];
vector<pair<pair<int, int>, pair<int, int> > > pos;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> D >> N >> M;
  int x1, y1, x2, y2;
  for (int i = 1; i <= D; i++) {
    cin >> x1 >> y1 >> x2 >> y2;
    pos.push_back(make_pair(make_pair(x1, y1), make_pair(x2, y2)));
    mp[min(x1, x2)][0]++;
    mp[max(x1, x2)][1]++;
    mp[min(y1, y2)][2]++;
    mp[max(y1, y2)][3]++;
  }
  for (int i = 0; i <= 3; i++) cin >> cnt[i];
  for (int i = 1; i <= N; i++) mp[i][0] += mp[i - 1][0];
  for (int i = N - 1; i >= 0; i--) mp[i][1] += mp[i + 1][1];
  for (int i = 1; i <= M; i++) mp[i][2] += mp[i - 1][2];
  for (int i = M - 1; i >= 0; i--) mp[i][3] += mp[i + 1][3];
  int c[4];
  for (int i = 0; i <= D - 1; i++) {
    x1 = pos[i].first.first, y1 = pos[i].first.second, x2 = pos[i].second.first,
    y2 = pos[i].second.second;
    c[0] = mp[max(x1, x2) - 1][0];
    c[1] = mp[min(x1, x2) + 1][1];
    if (x1 != x2) c[0]--, c[1]--;
    c[2] = mp[max(y1, y2) - 1][2];
    c[3] = mp[min(y1, y2) + 1][3];
    if (y1 != y2) c[2]--, c[3]--;
    bool first = false;
    for (int j = 0; j <= 3; j++) {
      if (c[j] != cnt[j]) first = true;
    }
    if (first) continue;
    cout << i + 1 << '\n';
    return 0;
  }
  cout << -1 << '\n';
  return 0;
}

```


### Prompt

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

If the girl doesn't go to Denis, then Denis will go to the girl. Using this rule, the young man left home, bought flowers and went to Nastya.

On the way from Denis's house to the girl's house is a road of n lines. This road can't be always crossed in one green light. Foreseeing this, the good mayor decided to place safety islands in some parts of the road. Each safety island is located after a line, as well as at the beginning and at the end of the road. Pedestrians can relax on them, gain strength and wait for a green light.

Denis came to the edge of the road exactly at the moment when the green light turned on. The boy knows that the traffic light first lights up g seconds green, and then r seconds red, then again g seconds green and so on.

Formally, the road can be represented as a segment [0, n]. Initially, Denis is at point 0. His task is to get to point n in the shortest possible time.

He knows many different integers d_1, d_2, …, d_m, where 0 ≤ d_i ≤ n — are the coordinates of points, in which the safety islands are located. Only at one of these points, the boy can be at a time when the red light is on.

Unfortunately, Denis isn't always able to control himself because of the excitement, so some restrictions are imposed:

  * He must always move while the green light is on because it's difficult to stand when so beautiful girl is waiting for you. Denis can change his position by ± 1 in 1 second. While doing so, he must always stay inside the segment [0, n].
  * He can change his direction only on the safety islands (because it is safe). This means that if in the previous second the boy changed his position by +1 and he walked on a safety island, then he can change his position by ± 1. Otherwise, he can change his position only by +1. Similarly, if in the previous second he changed his position by -1, on a safety island he can change position by ± 1, and at any other point by -1.
  * At the moment when the red light is on, the boy must be on one of the safety islands. He can continue moving in any direction when the green light is on.

Denis has crossed the road as soon as his coordinate becomes equal to n.

This task was not so simple, because it's possible that it is impossible to cross the road. Since Denis has all thoughts about his love, he couldn't solve this problem and asked us to help him. Find the minimal possible time for which he can cross the road according to these rules, or find that it is impossible to do.

Input

The first line contains two integers n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ min(n + 1, 10^4)) — road width and the number of safety islands.

The second line contains m distinct integers d_1, d_2, …, d_m (0 ≤ d_i ≤ n) — the points where the safety islands are located. It is guaranteed that there are 0 and n among them.

The third line contains two integers g, r (1 ≤ g, r ≤ 1000) — the time that the green light stays on and the time that the red light stays on.

Output

Output a single integer — the minimum time for which Denis can cross the road with obeying all the rules.

If it is impossible to cross the road output -1.

Examples

Input

15 5
0 3 7 14 15
11 11

Output

45

Input

13 4
0 3 7 13
9 9

Output

-1

Note

In the first test, the optimal route is:

  * for the first green light, go to 7 and return to 3. In this case, we will change the direction of movement at the point 7, which is allowed, since there is a safety island at this point. In the end, we will be at the point of 3, where there is also a safety island. The next 11 seconds we have to wait for the red light.
  * for the second green light reaches 14. Wait for the red light again.
  * for 1 second go to 15. As a result, Denis is at the end of the road.

In total, 45 seconds are obtained.

In the second test, it is impossible to cross the road according to all the rules.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int m;
int g, r;
int bfs(vector<long long> &a) {
  vector<vector<int>> dp(10010, vector<int>(2010, -1));
  deque<pair<int, int>> q;
  q.push_front({0, 0});
  dp[0][0] = 0;
  int ret = 1e9;
  while (!q.empty()) {
    auto nw = q.front();
    q.pop_front();
    int position = nw.first;
    int time = nw.second;
    if (position == m - 1) {
      ret = min(ret, dp[position][time]);
      continue;
    }
    int new_position = position + 1;
    int new_time = time + a[new_position] - a[position];
    if (new_time == g && dp[new_position][0] == -1) {
      q.push_back({new_position, 0});
      dp[new_position][0] = dp[position][time] + a[new_position] - a[position] +
                            r * (new_position != m - 1);
    }
    if (new_time < g && dp[new_position][new_time] == -1) {
      q.push_front({new_position, new_time});
      dp[new_position][new_time] =
          dp[position][time] + a[new_position] - a[position];
    }
    new_position = position - 1;
    new_time = (position == 0) ? 1e9 : time + a[position] - a[new_position];
    if (new_time == g && dp[new_position][0] == -1) {
      q.push_back({new_position, 0});
      dp[new_position][0] =
          dp[position][time] + a[position] - a[new_position] + r;
    }
    if (new_time < g && dp[new_position][new_time] == -1) {
      q.push_front({new_position, new_time});
      dp[new_position][new_time] =
          dp[position][time] + a[position] - a[new_position];
    }
  }
  if (ret == 1e9) ret = -1;
  return ret;
}
int main() {
  int n;
  cin >> n >> m;
  vector<long long> a(m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &a[i]);
  }
  sort(a.begin(), a.end());
  cin >> g >> r;
  printf("%d\n", bfs(a));
  return 0;
}

```


### Prompt

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

Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parallel to one of the coordinate axes, which connects the edges of the bar. More formally, each break goes along the line x = xc or y = yc, where xc and yc are integers. It should divide one part of the bar into two non-empty parts. After Bob breaks some part into two parts, he breaks the resulting parts separately and independently from each other. Also he doesn't move the parts of the bar. Bob made n breaks and wrote them down in his notebook in arbitrary order. At the end he got n + 1 parts. Now he wants to calculate their areas. Bob is lazy, so he asks you to do this task.

Input

The first line contains 3 integers W, H and n (1 ≤ W, H, n ≤ 100) — width of the bar, height of the bar and amount of breaks. Each of the following n lines contains four integers xi, 1, yi, 1, xi, 2, yi, 2 — coordinates of the endpoints of the i-th break (0 ≤ xi, 1 ≤ xi, 2 ≤ W, 0 ≤ yi, 1 ≤ yi, 2 ≤ H, or xi, 1 = xi, 2, or yi, 1 = yi, 2). Breaks are given in arbitrary order.

It is guaranteed that the set of breaks is correct, i.e. there is some order of the given breaks that each next break divides exactly one part of the bar into two non-empty parts.

Output

Output n + 1 numbers — areas of the resulting parts in the increasing order.

Examples

Input

2 2 2
1 0 1 2
0 1 1 1

Output

1 1 2

Input

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

Output

1 1 1 1

Input

2 4 2
0 1 2 1
0 3 2 3

Output

2 2 4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000;
const int INF = 1000000001;
int H, W, n;
struct coor {
  int x1, x2, y1, y2;
  coor() {}
  coor(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
  int area() const { return (x2 - x1) * (y2 - y1); }
};
vector<coor> V, cuts;
void solve() {
  for (__typeof((cuts).begin()) cut = (cuts).begin(); cut != (cuts).end();
       ++cut)
    for (__typeof((V).begin()) v = (V).begin(); v != (V).end(); ++v)
      if (cut->y1 == cut->y2 && v->x1 == cut->x1 && v->x2 == cut->x2 &&
          v->y1 < cut->y1 && cut->y2 < v->y2) {
        int i = v - V.begin();
        V.push_back(coor(v->x1, cut->y1, v->x2, v->y2));
        V[i].y2 = cut->y2;
        cuts.erase(cut);
        return;
      } else if (cut->x1 == cut->x2 && cut->y1 == v->y1 && cut->y2 == v->y2 &&
                 v->x1 < cut->x1 && cut->x2 < v->x2) {
        int i = v - V.begin();
        V.push_back(coor(cut->x1, cut->y1, v->x2, v->y2));
        V[i].x2 = cut->x2;
        cuts.erase(cut);
        return;
      }
}
int main(int argc, char *argv[]) {
  scanf("%d %d %d", &W, &H, &n);
  V.push_back(coor(0, 0, W, H));
  while (n--) {
    int x1, x2, y1, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    cuts.push_back(coor(x1, y1, x2, y2));
  }
  while (!cuts.empty()) solve();
  vector<int> ans;
  for (__typeof((V).begin()) it = (V).begin(); it != (V).end(); ++it)
    ans.push_back(it->area());
  sort((ans).begin(), (ans).end());
  for (__typeof((ans).begin()) i = (ans).begin(); i != (ans).end(); ++i)
    printf("%d ", *i);
  printf("\n");
  return 0;
}

```


### Prompt

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

Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.

The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.

And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:

  * if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
  * if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
  * if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
  * The length of the safe code coincides with the length of the hint.

For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".

After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.

At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...

Input

The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.

The input limits for scoring 30 points are (subproblem A1):

  * 1 ≤ |s| ≤ 5.

The input limits for scoring 100 points are (subproblems A1+A2):

  * 1 ≤ |s| ≤ 105.

Here |s| means the length of string s.

Output

Print the number of codes that match the given hint.

Examples

Input

AJ

Output

81

Input

1?AA

Output

100

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  char c;
  char zeroalpha = 'Z';
  bool alphafirst = false;
  int counter = 9;
  int qn = 0;
  int used[10];
  int i = 0;
  long long ans = 1;
  int total;
  double power;
  char first;
  memset(used, 0, sizeof(used));
  cin >> c;
  if (c == '?' || isalpha(c)) {
    ans = 9;
    zeroalpha = c;
  }
  first = c;
  if (cin.peek() == '\n') {
    if (c == '?' || isalpha(c)) {
      cout << "9" << endl;
      return 0;
    } else {
      cout << "1" << endl;
      return 0;
    }
  }
  do {
    cin >> c;
    if (c == '?') {
      qn++;
    } else if (isalpha(c) && c != zeroalpha) {
      used[(static_cast<int>(c)) - 65] = 1;
    }
  } while (cin.peek() != '\n');
  static_cast<double>(qn);
  if (qn != 0) {
    total = accumulate(used, used + 10, 0);
    if (isalpha(first)) {
      counter = 9;
    } else {
      counter = 10;
    }
    for (i = 0; i < total; i++) {
      ans *= counter;
      counter--;
    }
    ans *= (long long)pow(10.0, qn);
  } else {
    total = accumulate(used, used + 10, 0);
    if (isalpha(first)) {
      counter = 9;
    } else {
      counter = 10;
    }
    for (i = 0; i < total; i++) {
      ans *= counter;
      counter--;
    }
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

There is a rectangular grid of size n × m. Each cell of the grid is colored black ('0') or white ('1'). The color of the cell (i, j) is c_{i, j}. You are also given a map of directions: for each cell, there is a direction s_{i, j} which is one of the four characters 'U', 'R', 'D' and 'L'.

  * If s_{i, j} is 'U' then there is a transition from the cell (i, j) to the cell (i - 1, j);
  * if s_{i, j} is 'R' then there is a transition from the cell (i, j) to the cell (i, j + 1);
  * if s_{i, j} is 'D' then there is a transition from the cell (i, j) to the cell (i + 1, j);
  * if s_{i, j} is 'L' then there is a transition from the cell (i, j) to the cell (i, j - 1).

It is guaranteed that the top row doesn't contain characters 'U', the bottom row doesn't contain characters 'D', the leftmost column doesn't contain characters 'L' and the rightmost column doesn't contain characters 'R'.

You want to place some robots in this field (at most one robot in a cell). The following conditions should be satisfied.

  * Firstly, each robot should move every time (i.e. it cannot skip the move). During one move each robot goes to the adjacent cell depending on the current direction.
  * Secondly, you have to place robots in such a way that there is no move before which two different robots occupy the same cell (it also means that you cannot place two robots in the same cell). I.e. if the grid is "RL" (one row, two columns, colors does not matter there) then you can place two robots in cells (1, 1) and (1, 2), but if the grid is "RLL" then you cannot place robots in cells (1, 1) and (1, 3) because during the first second both robots will occupy the cell (1, 2).

The robots make an infinite number of moves.

Your task is to place the maximum number of robots to satisfy all the conditions described above and among all such ways, you have to choose one where the number of black cells occupied by robots before all movements is the maximum possible. Note that you can place robots only before all movements.

You have to answer t independent test cases.

Input

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

The first line of the test case contains two integers n and m (1 < nm ≤ 10^6) — the number of rows and the number of columns correspondingly.

The next n lines contain m characters each, where the j-th character of the i-th line is c_{i, j} (c_{i, j} is either '0' if the cell (i, j) is black or '1' if the cell (i, j) is white).

The next n lines also contain m characters each, where the j-th character of the i-th line is s_{i, j} (s_{i, j} is 'U', 'R', 'D' or 'L' and describes the direction of the cell (i, j)).

It is guaranteed that the sum of the sizes of fields does not exceed 10^6 (∑ nm ≤ 10^6).

Output

For each test case, print two integers — the maximum number of robots you can place to satisfy all the conditions described in the problem statement and the maximum number of black cells occupied by robots before all movements if the number of robots placed is maximized. Note that you can place robots only before all movements.

Example

Input

3
1 2
01
RL
3 3
001
101
110
RLL
DLD
ULL
3 3
000
000
000
RRD
RLD
ULL

Output

2 1
4 3
2 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
const long long MOD = 1e9 + 7;
const long long INF = 0x3f3f3f3f;
long long read() {
  long long x = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - 48;
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return x * f;
}
int N, M;
bool black[MAXN];
char mp[MAXN];
int val[MAXN];
int nxt[MAXN][30];
char goes[10] = "LURD";
int change[10];
int ans1, ans2;
int id(int i, int j) { return i * M + j; }
void init() {
  for (int i = N * M; i >= 0; i--) {
    val[i] = 0;
  }
  change[0] = -1;
  change[1] = -M;
  change[2] = 1;
  change[3] = M;
  ans1 = ans2 = 0;
  for (int i = N * M - 1; i >= 0; i--) {
    for (int j = 0; j < 4; j++) {
      if (mp[i] == goes[j]) {
        nxt[i][0] = i + change[j];
        break;
      }
    }
  }
}
void solve() {
  int x, y;
  int now;
  scanf("%d%d", &N, &M);
  getchar();
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      black[id(i, j)] = (getchar() == '0');
    }
    getchar();
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      mp[id(i, j)] = getchar();
    }
    getchar();
  }
  init();
  for (int j = 0; j < 20; j++) {
    for (int i = N * M - 1; i >= 0; i--) {
      nxt[i][j + 1] = nxt[nxt[i][j]][j];
    }
  }
  for (int i = N * M - 1; i >= 0; i--) {
    val[nxt[i][20]] |= 2 | black[i];
  }
  for (int i = N * M - 1; i >= 0; i--) {
    ans1 += (bool)val[i];
    ans2 += (val[i] & 1);
  }
  printf("%d %d\n", ans1, ans2);
}
int main() {
  int T;
  T = 1;
  scanf("%d", &T);
  while (T--) {
    solve();
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

You have N items that you want to put them into a knapsack. Item i has value vi, weight wi and limitation mi.

You want to find a subset of items to put such that:

* The total value of the items is as large as possible.
* The items have combined weight at most W, that is capacity of the knapsack.
* You can select at most mi items for ith item.

Find the maximum total value of items in the knapsack.

Constraints

* 1 ≤ N ≤ 100
* 1 ≤ vi ≤ 1,000
* 1 ≤ wi ≤ 1,000
* 1 ≤ mi ≤ 10,000
* 1 ≤ W ≤ 10,000

Input

N W
v1 w1 m1
v2 w2 m2
:
vN wN mN

The first line consists of the integers N and W. In the following N lines, the value, weight and limitation of the i-th item are given.

Output

Print the maximum total values of the items in a line.

Examples

Input

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

Output

12

Input

2 100
1 1 100
2 1 50

Output

150

### Response

```cpp
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;

signed main() {
	int N, W; cin >> N >> W;
	vector<int>v, w; v.push_back(0), w.push_back(0);
	rep(i, 0, N) {
		int a, b, m; cin >> a >> b >> m;

		for (int x = 1; x <= m; x++) {
			v.push_back(x*a);
			w.push_back(x*b);
			m -= x;
		}
		if (m > 0) v.push_back(m*a), w.push_back(m*b);

	}

	vector<int>dp(W + 1, 0);
	rep(i, 1, v.size())rrep(j, w[i], W + 1) {
		dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
	}
	cout << dp[W] << endl;

	return 0;
}
```


### Prompt

Develop a solution in cpp to the problem described below:

There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates.

You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads.

Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?

Constraints

* 2 ≤ N ≤ 10^5
* 0 ≤ x_i,y_i ≤ 10^9
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
:
x_N y_N

Output

Print the minimum necessary amount of money in order to build roads so that it will be possible to travel between every pair of towns by traversing roads.

Examples

Input

3
1 5
3 9
7 8

Output

3

Input

6
8 3
4 9
12 19
18 1
13 5
7 6

Output

8

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
template<typename T>vector<T>&operator<<(vector<T>&v,const T t){v.push_back(t);return v;}
template<typename T,typename U>istream&operator>>(istream&s,pair<T,U>&p){return s>>p.first>>p.second;}
template<typename T,typename U>ostream&operator<<(ostream&s,const pair<T,U>p){return s<<p.first<<" "<<p.second;}
#define all(x) x.begin(),x.end()
typedef pair<int,int>pii;

int p[100000];
int uni(int i){
	return p[i]!=i?p[i]=uni(p[i]):i;
}

pair<int,pii>dist(pii v,pii u){
	return {abs(v.first-u.first),{v.second,u.second}};
}

int N;
vector<pii>xi,yi;
vector<pair<int,pii>>E;

int main(){
	cin>>N;
	for(int i=0;i<N;++i){
		int x,y;
		cin>>x>>y;
		xi<<(pii){x,i};
		yi<<(pii){y,i};
		p[i]=i;
	}
	sort(all(xi));
	sort(all(yi));
	for(int i=0;i<N-1;++i){
		E<<dist(xi[i],xi[i+1])<<dist(yi[i],yi[i+1]);
	}
	sort(all(E));
	long long a=0;
	for(auto e:E){
		int x=uni(e.second.first);
		int y=uni(e.second.second);
		if(x!=y){
			p[x]=y;
			a+=e.first;
		}
	}
	cout<<a;
}

```


### Prompt

Generate a CPP solution to the following problem:

This problem consists of two subproblems: for solving subproblem D1 you will receive 3 points, and for solving subproblem D2 you will receive 16 points.

Manao is the chief architect involved in planning a new supercollider. He has to identify a plot of land where the largest possible supercollider can be built. The supercollider he is building requires four-way orthogonal collisions of particles traveling at the same speed, so it will consist of four accelerating chambers and be shaped like a plus sign (i.e., +). Each of the four accelerating chambers must be the same length and must be aligned with the Earth's magnetic field (parallel or orthogonal) to minimize interference.

The accelerating chambers need to be laid down across long flat stretches of land to keep costs under control. Thus, Manao has already commissioned a topographical study that has identified all possible maximal length tracts of land available for building accelerating chambers that are either parallel or orthogonal to the Earth's magnetic field. To build the largest possible supercollider, Manao must identify the largest symmetric plus shape from among these candidate tracts. That is, he must find the two tracts of land that form an axis-aligned plus shape with the largest distance from the center of the plus to the tip of the shortest of the four arms of the plus. Note that the collider need not use the entire length of the tracts identified (see the example in the notes).

Input

The first line of the input will contain two single-space-separated integers n, the number of north-south tracts and m, the number of west-east tracts.

Each of the n lines following the first describes a north-south tract. Each such tract is described by three single-space-separated integers xi, yi, li representing the vertical line segment from (xi, yi) to (xi, yi + li).

Similarly, after the n lines describing north-south tracts follow m similar lines describing the west-east tracts. Each such tract is described by three single-space-separated integers xi, yi, li representing the horizontal line segment from (xi, yi) to (xi + li, yi).

All xi and yi are between -100000000 and 100000000, inclusive. All li are between 1 and 100000000, inclusive. No pair of horizontal segments will touch or intersect, and no pair of vertical segments will touch or intersect.

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

  * In subproblem D1 (3 points), n and m will be between 1 and 1000, inclusive.
  * In subproblem D2 (16 points), n and m will be between 1 and 50000, inclusive.

Output

Print one line containing a single integer, the size of the largest supercollider that can be built on one north-south tract and one west-east tract. The size of the supercollider is defined to be the length of one of the four accelerating chambers. In other words, the size of the resulting supercollider is defined to be the distance from the intersection of the two line segments to the closest endpoint of either of the two segments. If no pair of north-south and west-east tracts intersects, it is not possible to build a supercollider and the program should report a maximum size of zero.

Examples

Input

1 2
4 0 9
1 1 8
1 2 7

Output

2

Note

Consider the example. There is one vertical line segment from (4, 0) to (4, 9) and two horizontal line segments: from (1, 1) to (9, 1) and from (1, 2) to (8, 2). The largest plus shape that can be found among these segments is formed from the only vertical segment and the second of horizontal segments, and is centered at (4, 2).

The program should output 2 because the closest end point of those segments to the center is (4, 0), which is distance 2 from the center point of (4, 2). The collider will be formed by the line segments from (2, 2) to (6, 2) and from (4, 0) to (4, 4).

### Response

```cpp
#include <bits/stdc++.h>
long long a11[1010], b11[1010], b12[1010];
long long a21[1010], b21[1010], b22[1010];
long long min(long long a, long long b) {
  if (a < b) {
    return a;
  }
  return b;
}
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  }
  return b;
}
int main(void) {
  int n, m, i, j;
  long long ans, temp;
  while (scanf("%d %d", &n, &m) != EOF) {
    ans = 0;
    for (i = 1; i <= n; i++) {
      scanf("%I64d %I64d %I64d", &a11[i], &b11[i], &b12[i]);
      b12[i] += b11[i];
    }
    for (i = 1; i <= m; i++) {
      scanf("%I64d %I64d %I64d", &b21[i], &a21[i], &b22[i]);
      b22[i] += b21[i];
    }
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= m; j++) {
        temp = 2000000000;
        temp *= 100000;
        if (a21[j] >= b11[i] && a21[j] <= b12[i] && a11[i] >= b21[j] &&
            a11[i] <= b22[j]) {
          temp = min(temp, a21[j] - b11[i]);
          temp = min(temp, b12[i] - a21[j]);
          temp = min(temp, a11[i] - b21[j]);
          temp = min(temp, b22[j] - a11[i]);
          ans = max(temp, ans);
        }
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.

We assume that Bajtek can only heap up snow drifts at integer coordinates.

Input

The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift.

Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.

Output

Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.

Examples

Input

2
2 1
1 2

Output

1

Input

2
2 1
4 1

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100010;
pair<int, int> a[MAX_N];
vector<int> adj[MAX_N];
bool visit[MAX_N];
int par[MAX_N];
int Height[MAX_N];
void dfs(int root) {
  visit[root] = 1;
  for (int i = 0; i < adj[root].size(); i++) {
    if (visit[adj[root][i]] == 0) {
      par[adj[root][i]] = root;
      Height[adj[root][i]] = Height[root] + 1;
      dfs(adj[root][i]);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = 1; j < n; j++) {
      if (a[i].first == a[j].first || a[i].second == a[j].second) {
        adj[i].push_back(j);
        adj[j].push_back(i);
      }
    }
  }
  int ans = 0;
  while (true) {
    bool flag = 0;
    for (int i = 0; i < n; i++) {
      if (visit[i] == 0) {
        dfs(i);
        ans++;
        flag = 1;
      }
    }
    if (flag == 0) {
      break;
    }
  }
  cout << ans - 1;
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Bankopolis is an incredible city in which all the n crossroads are located on a straight line and numbered from 1 to n along it. On each crossroad there is a bank office.

The crossroads are connected with m oriented bicycle lanes (the i-th lane goes from crossroad ui to crossroad vi), the difficulty of each of the lanes is known.

Oleg the bank client wants to gift happiness and joy to the bank employees. He wants to visit exactly k offices, in each of them he wants to gift presents to the employees.

The problem is that Oleg don't want to see the reaction on his gifts, so he can't use a bicycle lane which passes near the office in which he has already presented his gifts (formally, the i-th lane passes near the office on the x-th crossroad if and only if min(ui, vi) < x < max(ui, vi))). Of course, in each of the offices Oleg can present gifts exactly once. Oleg is going to use exactly k - 1 bicycle lane to move between offices. Oleg can start his path from any office and finish it in any office.

Oleg wants to choose such a path among possible ones that the total difficulty of the lanes he will use is minimum possible. Find this minimum possible total difficulty.

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 80) — the number of crossroads (and offices) and the number of offices Oleg wants to visit.

The second line contains single integer m (0 ≤ m ≤ 2000) — the number of bicycle lanes in Bankopolis.

The next m lines contain information about the lanes.

The i-th of these lines contains three integers ui, vi and ci (1 ≤ ui, vi ≤ n, 1 ≤ ci ≤ 1000), denoting the crossroads connected by the i-th road and its difficulty.

Output

In the only line print the minimum possible total difficulty of the lanes in a valid path, or -1 if there are no valid paths.

Examples

Input

7 4
4
1 6 2
6 2 2
2 4 2
2 7 1

Output

6

Input

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

Output

3

Note

In the first example Oleg visiting banks by path 1 → 6 → 2 → 4.

Path 1 → 6 → 2 → 7 with smaller difficulity is incorrect because crossroad 2 → 7 passes near already visited office on the crossroad 6.

In the second example Oleg can visit banks by path 4 → 1 → 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void rd(int &x) { scanf("%d", &x); }
void rd(int &x, int &y) { scanf("%d%d", &x, &y); }
void rd(int &x, int &y, int &z) { scanf("%d%d%d", &x, &y, &z); }
void rd(int &x, int &y, int &z, int &s) { scanf("%d%d%d%d", &x, &y, &z, &s); }
struct debugger {
  template <class T>
  debugger &operator,(const T &v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
void debugv(vector<long long> vec) {
  cerr << "printing vector:: ";
  for (int i = 0; i < (vec.size()); i++) {
    cout << vec[i] << " ";
  }
  cerr << endl;
}
void debugs(set<long long> s) {
  cerr << "printing set:: ";
  for (auto it = s.begin(); it != s.end(); it++) {
    cout << (*it) << " ";
  }
  cerr << endl;
}
int n, k, m, dis[81][81];
int dp[81][81][81][81];
int back(long long l, long long r, long long cur, long long p) {
  if (p == k) return 0;
  int &x = dp[l][r][cur][p];
  if (x != -1) return x;
  int ret = 1e8 + 5;
  for (int i = l; i <= r; i++) {
    if (i != cur && dis[cur][i] < 1e8 + 5) {
      if (i < cur)
        ret = min(ret, back(l, cur - 1, i, p + 1) + dis[cur][i]);
      else
        ret = min(ret, back(cur + 1, r, i, p + 1) + dis[cur][i]);
    }
  }
  return x = ret;
}
int main() {
  rd(n, k, m);
  for (int i = 1; i <= (n); i++) {
    for (int w = 1; w <= (n); w++) dis[i][w] = 1e8 + 5;
  }
  for (int i = 1; i <= (m); i++) {
    int u, v, c;
    rd(u, v, c);
    dis[u][v] = min(dis[u][v], c);
  }
  memset((dp), -1, sizeof((dp)));
  int ans = 1e8 + 5;
  for (int i = 1; i <= (n); i++) {
    ans = min(ans, back(1, n, i, 1));
  }
  if (ans == 1e8 + 5) ans = -1;
  printf("%d", ans);
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.

For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.

Write a program that will print the name of a man who will drink the n-th can.

Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.

Input

The input data consist of a single integer n (1 ≤ n ≤ 109).

It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.

Output

Print the single line — the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.

Examples

Input

1

Output

Sheldon

Input

6

Output

Sheldon

Input

1802

Output

Penny

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string names[] = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"};
  int n, base = 5;
  cin >> n;
  while (n > base) {
    n -= base;
    base *= 2;
  }
  if (n <= base / 5 * 1)
    cout << names[0] << endl;
  else if (n <= base / 5 * 2)
    cout << names[1] << endl;
  else if (n <= base / 5 * 3)
    cout << names[2] << endl;
  else if (n <= base / 5 * 4)
    cout << names[3] << endl;
  else
    cout << names[4] << endl;
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

An oriented weighted forest is an acyclic weighted digraph in which from each vertex at most one edge goes.

The root of vertex v of an oriented weighted forest is a vertex from which no edge goes and which can be reached from vertex v moving along the edges of the weighted oriented forest. We denote the root of vertex v as root(v).

The depth of vertex v is the sum of weights of paths passing from the vertex v to its root. Let's denote the depth of the vertex v as depth(v).

Let's consider the process of constructing a weighted directed forest. Initially, the forest does not contain vertices. Vertices are added sequentially one by one. Overall, there are n performed operations of adding. The i-th (i > 0) adding operation is described by a set of numbers (k, v1, x1, v2, x2, ... , vk, xk) and means that we should add vertex number i and k edges to the graph: an edge from vertex root(v1) to vertex i with weight depth(v1) + x1, an edge from vertex root(v2) to vertex i with weight depth(v2) + x2 and so on. If k = 0, then only vertex i is added to the graph, there are no added edges.

Your task is like this: given the operations of adding vertices, calculate the sum of the weights of all edges of the forest, resulting after the application of all defined operations, modulo 1000000007 (109 + 7).

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of operations of adding a vertex.

Next n lines contain descriptions of the operations, the i-th line contains the description of the operation of adding the i-th vertex in the following format: the first number of a line is an integer k (0 ≤ k ≤ i - 1), then follow 2k space-separated integers: v1, x1, v2, x2, ... , vk, xk (1 ≤ vj ≤ i - 1, |xj| ≤ 109).

The operations are given in the order, in which they should be applied to the graph. It is guaranteed that sum k of all operations does not exceed 105, also that applying operations of adding vertexes does not result in loops and multiple edges.

Output

Print a single number — the sum of weights of all edges of the resulting graph modulo 1000000007 (109 + 7).

Examples

Input

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

Output

30

Input

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

Output

9

Note

Conside the first sample:

  1. Vertex 1 is added. k = 0, thus no edges are added.
  2. Vertex 2 is added. k = 0, thus no edges are added.
  3. Vertex 3 is added. k = 1. v1 = 2, x1 = 1. Edge from vertex root(2) = 2 to vertex 3 with weight depth(2) + x1 = 0 + 1 = 1 is added.
  4. Vertex 4 is added. k = 2. v1 = 1, x1 = 5. Edge from vertex root(1) = 1 to vertex 4 with weight depth(1) + x1 = 0 + 5 = 5 is added. v2 = 2, x2 = 2. Edge from vertex root(2) = 3 to vertex 4 with weight depth(2) + x1 = 1 + 2 = 3 is added.
  5. Vertex 5 is added. k = 1. v1 = 1, x1 = 2. Edge from vertex root(1) = 4 to vertex 5 with weight depth(1) + x1 = 5 + 2 = 7 is added.
  6. Vertex 6 is added. k = 1. v1 = 3, x1 = 4. Edge from vertex root(3) = 5 to vertex 6 with weight depth(3) + x1 = 10 + 4 = 14 is added.

The resulting graph is shown on the pictore below: <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
const long long MOD = 1e9 + 7;
long long par[N], w[N], n, ans;
long long Find(long long v) {
  if (v == par[v]) return v;
  long long x = par[v];
  par[v] = Find(par[v]);
  w[v] += w[x];
  w[v] %= MOD;
  return par[v];
}
void merge(long long v, long long u, long long nw) {
  long long root = Find(v);
  ans += w[v] + nw;
  ans %= MOD;
  w[root] = w[v] + nw;
  w[root] %= MOD;
  par[root] = u;
}
int main(int argc, const char* argv[]) {
  for (int i = 0; i < N; i++) par[i] = i;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long k;
    cin >> k;
    for (int j = 1; j <= k; j++) {
      long long v, weight;
      cin >> v >> weight;
      merge(v, i, weight);
    }
  }
  cout << (ans + 2 * MOD) % MOD;
  return 0;
}

```


### Prompt

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

All cinema halls in Berland are rectangles with K rows of K seats each, and K is an odd number. Rows and seats are numbered from 1 to K. For safety reasons people, who come to the box office to buy tickets, are not allowed to choose seats themselves. Formerly the choice was made by a cashier, but now this is the responsibility of a special seating program. It was found out that the large majority of Berland's inhabitants go to the cinema in order to watch a movie, that's why they want to sit as close to the hall center as possible. Moreover, a company of M people, who come to watch a movie, want necessarily to occupy M successive seats in one row. Let's formulate the algorithm, according to which the program chooses seats and sells tickets. As the request for M seats comes, the program should determine the row number x and the segment [yl, yr] of the seats numbers in this row, where yr - yl + 1 = M. From all such possible variants as a final result the program should choose the one with the minimum function value of total seats remoteness from the center. Say, <image> — the row and the seat numbers of the most "central" seat. Then the function value of seats remoteness from the hall center is <image>. If the amount of minimum function values is more than one, the program should choose the one that is closer to the screen (i.e. the row number x is lower). If the variants are still multiple, it should choose the one with the minimum yl. If you did not get yet, your task is to simulate the work of this program.

Input

The first line contains two integers N and K (1 ≤ N ≤ 1000, 1 ≤ K ≤ 99) — the amount of requests and the hall size respectively. The second line contains N space-separated integers Mi from the range [1, K] — requests to the program.

Output

Output N lines. In the i-th line output «-1» (without quotes), if it is impossible to find Mi successive seats in one row, otherwise output three numbers x, yl, yr. Separate the numbers with a space.

Examples

Input

2 1
1 1

Output

1 1 1
-1

Input

4 3
1 2 3 1

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mk = 101;
int q, k;
int su[mk][mk], sv[mk][mk];
int xc, yc;
int main() {
  q = ({
    int t;
    scanf("%d", &t);
    t;
  }),
  k = ({
    int t;
    scanf("%d", &t);
    t;
  });
  xc = (k + 1) / 2, yc = (k + 1) / 2;
  for (int i = 1; i < k + 1; i++)
    for (int j = 1; j < k + 1; j++)
      su[i][j] = j, sv[i][j] = sv[i][j - 1] + abs(i - xc) + abs(j - yc);
  for (int qu = 0; qu < q; qu++) {
    int m = ({
      int t;
      scanf("%d", &t);
      t;
    });
    int ansv = (int)1e9, ansx = -1, ansyl = -1, ansyr = -1;
    for (int x = 1; x < k + 1; x++)
      for (int yl = 1; yl < k + 1; yl++) {
        int yr = yl + m - 1;
        if (yr > k) break;
        if (su[x][yr] - su[x][yl - 1] != m) continue;
        int v = sv[x][yr] - sv[x][yl - 1];
        if (v < ansv) {
          ansv = v, ansx = x, ansyl = yl, ansyr = yr;
        }
      }
    if (ansx == -1) {
      printf("-1\n");
      continue;
    }
    printf("%d %d %d\n", ansx, ansyl, ansyr);
    int x = ansx;
    for (int j = ansyl; j < ansyr + 1; j++)
      su[x][j] = su[x][j - 1], sv[x][j] = sv[x][j - 1];
    for (int j = ansyr + 1; j < k + 1; j++)
      su[x][j] -= m, sv[x][j] = sv[x][j - 1] + abs(x - xc) + abs(j - yc);
  }
  return 0;
}

```