### Prompt

Please create a solution in cpp to the following problem:

One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first.

<image>

There are n books standing in a row on the shelf, the i-th book has color a_i.

You'd like to rearrange the books to make the shelf look beautiful. The shelf is considered beautiful if all books of the same color are next to each other.

In one operation you can take one book from any position on the shelf and move it to the right end of the shelf.

What is the minimum number of operations you need to make the shelf beautiful?

Input

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

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — the book colors.

Output

Output the minimum number of operations to make the shelf beautiful.

Examples

Input

5
1 2 2 1 3

Output

2

Input

5
1 2 2 1 1

Output

1

Note

In the first example, we have the bookshelf [1, 2, 2, 1, 3] and can, for example:

  1. take a book on position 4 and move to the right end: we'll get [1, 2, 2, 3, 1];
  2. take a book on position 1 and move to the right end: we'll get [2, 2, 3, 1, 1].

In the second example, we can move the first book to the end of the bookshelf and get [2,2,1,1,1].

### Response

```cpp
// -- //
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 5e5+228;
ll a[N], dp[N], l[N], r[N], af[N];
signed main(){
	cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    ll n;
    cin >> n;
    for(ll i = 0;i<n;i++) cin >> a[i];
    for(ll i = n-1;i>=0;i--) l[a[i]]=i;
    for(ll i = 0;i<n;i++) r[a[i]]=i;
    for(ll i = n-1;i>=0;i--){
        af[a[i]]++;
        dp[i]=dp[i+1];
        if(i==l[a[i]]) dp[i]=max(dp[i], (r[a[i]]+1<n?dp[r[a[i]]+1]:0)+af[a[i]]);
        else dp[i]=max(dp[i], af[a[i]]);
    }
    cout<<n-dp[0];
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries:

  1. Add a positive integer to S, the newly added integer is not less than any number in it.
  2. Find a subset s of the set S such that the value <image> is maximum possible. Here max(s) means maximum value of elements in s, <image> — the average value of numbers in s. Output this maximum possible value of <image>.

Input

The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries.

Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given.

It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes.

Output

Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line.

Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6.

Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.

Examples

Input

6
1 3
2
1 4
2
1 8
2

Output

0.0000000000
0.5000000000
3.0000000000

Input

4
1 1
1 4
1 5
2

Output

2.0000000000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 5e5 + 10;
long long a[N], pre[N];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long q;
  cin >> q;
  long long n = 0;
  while (q--) {
    long long t;
    cin >> t;
    if (t == 1) {
      long long x;
      cin >> x;
      a[++n] = x;
      pre[n] = pre[n - 1] + x;
    } else {
      if (n == 1) {
        cout << 0 << "\n";
        continue;
      }
      long long lo = 1;
      long long hi = n - 1;
      while (hi - lo > 1) {
        long long m1 = (2 * lo + hi) / 3;
        long long m2 = (lo + 2 * hi) / 3;
        double k = (double)(pre[m1] + a[n]) / (m1 + 1);
        double k1 = (double)(pre[m2] + a[n]) / (m2 + 1);
        if (k > k1) {
          lo = m1 + 1;
        } else {
          hi = m2 - 1;
        }
      }
      double mn = 1e18;
      for (long long i = lo; i <= hi; i++) {
        if (mn > (double)(pre[i] + a[n]) / (i + 1)) {
          mn = (double)(pre[i] + a[n]) / (i + 1);
        }
      }
      cout << fixed << setprecision(10) << (double)(a[n] - mn) << "\n";
    }
  }
}

```


### Prompt

Please formulate a cpp solution to the following problem:

As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.

You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last n days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last n days, or not.

Input

The first line of input contains single integer n (2 ≤ n ≤ 100) — the number of days.

The second line contains a string of length n consisting of only capital 'S' and 'F' letters. If the i-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.

Output

Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.

You can print each letter in any case (upper or lower).

Examples

Input

4
FSSF

Output

NO

Input

2
SF

Output

YES

Input

10
FFFFFFFFFF

Output

NO

Input

10
SSFFSFFSFF

Output

YES

Note

In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".

In the second example you just flew from Seattle to San Francisco, so the answer is "YES".

In the third example you stayed the whole period in San Francisco, so the answer is "NO".

In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
char a[105];
int main() {
  scanf("%d%s", &n, a + 1);
  int sf = 0, fs = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] == 'S' && a[i + 1] == 'F') sf++;
    if (a[i] == 'F' && a[i + 1] == 'S') fs++;
  }
  printf(sf > fs ? "YES\n" : "NO\n");
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password".

Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" — thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address.

Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits.

Help Igor K. restore his ISQ account by the encrypted password and encryption specification.

Input

The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.

Output

Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.

Examples

Input

01001100100101100000010110001001011001000101100110010110100001011010100101101100
0100110000
0100110010
0101100000
0101100010
0101100100
0101100110
0101101000
0101101010
0101101100
0101101110

Output

12345678

Input

10101101111001000010100100011010101101110010110111011000100011011110010110001000
1001000010
1101111001
1001000110
1010110111
0010110111
1101001101
1011000001
1110010101
1011011000
0110001000

Output

30234919

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
bool is_vowel(char c) {
  c = tolower(c);
  return c == 'a' || c == 'e' || c == 'o' || c == 'i' || c == 'u' || c == 'y';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string base;
  cin >> base;
  string nums[10];
  for (int i = 0; i < 10; i++) cin >> nums[i];
  for (int i = 0; i < 80; i += 10) {
    for (int j = 0; j < 10; j++) {
      if (nums[j] == base.substr(i, 10)) cout << j;
    }
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Convexity of a set of points on the plane is the size of the largest subset of points that form a convex polygon. Your task is to build a set of n points with the convexity of exactly m. Your set of points should not contain three points that lie on a straight line.

Input

The single line contains two integers n and m (3 ≤ m ≤ 100, m ≤ n ≤ 2m).

Output

If there is no solution, print "-1". Otherwise, print n pairs of integers — the coordinates of points of any set with the convexity of m. The coordinates shouldn't exceed 108 in their absolute value.

Examples

Input

4 3

Output

0 0
3 0
0 3
1 1

Input

6 3

Output

-1

Input

6 6

Output

10 0
-10 0
10 1
9 1
9 -1
0 -2

Input

7 4

Output

176166 6377
709276 539564
654734 174109
910147 434207
790497 366519
606663 21061
859328 886001

### Response

```cpp
#include <bits/stdc++.h>
int main(void) {
  int i, j, k, n, m;
  while (scanf("%d%d", &n, &m) != EOF) {
    if (3 == m) {
      if (3 == n)
        printf("0 0\n0 1\n1 0\n");
      else if (4 == n)
        printf("0 0\n3 0\n0 3\n1 1\n");
      else
        printf("-1\n");
      continue;
    } else {
      j = 1;
      k = 1;
      printf("%d %d\n", -1, 0);
      for (i = 2; i <= m; i++) printf("%d %d\n", j++, k), k += i;
      j = 1000000;
      for (i = 1; i <= n - m; i++) printf("%d %d\n", j, k--), j += i;
    }
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

A flea is sitting at one of the n hassocks, arranged in a circle, at the moment. After minute number k the flea jumps through k - 1 hassoсks (clockwise). For example, after the first minute the flea jumps to the neighboring hassock. You should answer: will the flea visit all the hassocks or not. We assume that flea has infinitely much time for this jumping.

Input

The only line contains single integer: 1 ≤ n ≤ 1000 — number of hassocks.

Output

Output "YES" if all the hassocks will be visited and "NO" otherwise.

Examples

Input

1

Output

YES

Input

3

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int vis[n];
  memset(vis, 0, sizeof(vis));
  vis[0] = 1;
  int x = 0, k = 1;
  int f_cnt = 0;
  int all = 1;
  while (f_cnt < 1000000) {
    x += k;
    x %= n;
    if (vis[x]) {
      f_cnt++;
      k++;
    } else {
      vis[x] = 1;
      k++;
      f_cnt = 0;
      all++;
    }
    if (all == n) break;
  }
  if (f_cnt == 1000000) {
    cout << "NO\n";
  } else {
    cout << "YES\n";
  }
}

```


### Prompt

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

Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is.

You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.

Constraints

* 2 ≦ |s| ≦ 10^5
* s consists of lowercase letters.

Input

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

s

Output

If there exists no unbalanced substring of s, print `-1 -1`.

If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print `a b`. If there exists more than one such substring, any of them will be accepted.

Examples

Input

needed

Output

2 5

Input

atcoder

Output

-1 -1

### Response

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

int main()
{
	string str;
	cin>>str;
	for(int i=1;i<str.size();i++)
	{
		if(str[i]==str[i-1])
		{
			cout<<i<<" "<<i+1<<endl;
			return 0;
		}
	}
	for(int i=2;i<str.size();i++)
	{
		if(str[i]==str[i-2])
		{
			cout<<i-1<<" "<<i+1<<endl;
			return 0;
		}
	}
	cout<<"-1 -1"<<endl;
	return 0;
}
```


### Prompt

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

You have an integer n. Let's define following tree generation as McDic's generation:

  1. Make a complete and full binary tree of 2^{n} - 1 vertices. Complete and full binary tree means a tree that exactly one vertex is a root, all leaves have the same depth (distance from the root), and all non-leaf nodes have exactly two child nodes.
  2. Select a non-root vertex v from that binary tree.
  3. Remove v from tree and make new edges between v's parent and v's direct children. If v has no children, then no new edges will be made.

You have a tree. Determine if this tree can be made by McDic's generation. If yes, then find the parent vertex of removed vertex in tree.

Input

The first line contains integer n (2 ≤ n ≤ 17).

The i-th of the next 2^{n} - 3 lines contains two integers a_{i} and b_{i} (1 ≤ a_{i} < b_{i} ≤ 2^{n} - 2) — meaning there is an edge between a_{i} and b_{i}. It is guaranteed that the given edges form a tree.

Output

Print two lines.

In the first line, print a single integer — the number of answers. If given tree cannot be made by McDic's generation, then print 0.

In the second line, print all possible answers in ascending order, separated by spaces. If the given tree cannot be made by McDic's generation, then don't print anything.

Examples

Input

4
1 2
1 3
2 4
2 5
3 6
3 13
3 14
4 7
4 8
5 9
5 10
6 11
6 12

Output

1
3

Input

2
1 2

Output

2
1 2

Input

3
1 2
2 3
3 4
4 5
5 6

Output

0

Note

In the first example, 3 is the only possible answer.

<image>

In the second example, there are 2 possible answers.

<image>

In the third example, the tree can't be generated by McDic's generation.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline long long readll() {
  long long f = 1, x = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int MAXN = 1e6 + 5;
vector<int> G[MAXN];
int n, m, f[MAXN], sz[MAXN], root;
void getroot(int u, int fa) {
  sz[u] = 1;
  f[u] = 0;
  for (int i = 0; i < (int)G[u].size(); ++i) {
    int v = G[u][i];
    if (v == fa) continue;
    getroot(v, u);
    sz[u] += sz[v];
    f[u] = max(f[u], sz[v]);
  }
  f[u] = max(f[u], n - sz[u]);
  root = f[u] < f[root] ? u : root;
}
int mis, b, mst, dep[MAXN], dfn[MAXN], ofn[MAXN], cnt;
vector<int> le;
void dfs(int u, int fa) {
  dfn[u] = ++cnt;
  dep[u] = dep[fa] + 1;
  int ss = G[u].size() - (fa != 0);
  if (!ss) le.push_back(u);
  if (ss > 3) {
    b = 1;
    return;
  }
  if (mis && (ss == 1 || ss == 3)) {
    b = 1;
    return;
  }
  if (ss == 1 || ss == 3) mis = u, mst = ss;
  for (int i = 0; i < (int)G[u].size(); ++i) {
    int v = G[u][i];
    if (v == fa) continue;
    dfs(v, u);
    if (b) return;
  }
  ofn[u] = cnt;
}
int check(int rt) {
  mis = b = mst = 0;
  le.clear();
  cnt = 0;
  dfs(rt, 0);
  if (b || !mis) return 0;
  if (le.size() > (1 << (m - 1)) || le.size() < (1 << (m - 1)) - 1) return 0;
  if (mst == 1 && le.size() != (1 << (m - 1)) - 1) return 0;
  if (mst == 3 && le.size() == (1 << (m - 1)) - 1) return 0;
  int mx = 0, mn = n + 1;
  for (int i = 0; i < (int)le.size(); ++i)
    mx = max(mx, dep[le[i]]), mn = min(mn, dep[le[i]]);
  if (mx - mn > 1) return 0;
  if (mx != mn && (mn != m - 1 || mx != m)) return 0;
  if (mn == mx) {
    if (mst != 1) return 0;
  } else {
    for (int i = 0; i < (int)le.size(); ++i) {
      if (dep[le[i]] == mn) {
        if (dfn[le[i]] > ofn[mis] || dfn[le[i]] < dfn[mis]) return 0;
      }
    }
  }
  return mis;
}
int main() {
  m = read();
  n = (1 << m) - 2;
  for (int i = 1; i < n; ++i) {
    int u = read(), v = read();
    G[u].push_back(v);
    G[v].push_back(u);
  }
  f[0] = n;
  getroot(1, 0);
  vector<int> ans;
  int t;
  if (t = check(root)) ans.push_back(t);
  for (int i = 0; i < (int)G[root].size(); ++i) {
    int v = G[root][i];
    if (t = check(v)) ans.push_back(t);
    for (int j = 0; j < (int)G[v].size(); ++j) {
      if (G[v][j] != root) {
        if (t = check(G[v][j])) ans.push_back(t);
      }
    }
  }
  cout << ans.size() << endl;
  if (!ans.size()) return 0;
  sort(ans.begin(), ans.end());
  ans.erase(unique(ans.begin(), ans.end()), ans.end());
  for (int i = 0; i < (int)ans.size(); ++i) cout << ans[i] << " ";
  cout << endl;
  return 0;
}

```


### Prompt

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

Yaroslav is playing a game called "Time". The game has a timer showing the lifespan he's got left. As soon as the timer shows 0, Yaroslav's character dies and the game ends. Also, the game has n clock stations, station number i is at point (xi, yi) of the plane. As the player visits station number i, he increases the current time on his timer by ai. The stations are for one-time use only, so if the player visits some station another time, the time on his timer won't grow.

A player spends d·dist time units to move between stations, where dist is the distance the player has covered and d is some constant. The distance between stations i and j is determined as |xi - xj| + |yi - yj|.

Initially, the player is at station number 1, and the player has strictly more than zero and strictly less than one units of time. At station number 1 one unit of money can increase the time on the timer by one time unit (you can buy only integer number of time units).

Now Yaroslav is wondering, how much money he needs to get to station n. Help Yaroslav. Consider the time to buy and to increase the timer value negligibly small.

Input

The first line contains integers n and d (3 ≤ n ≤ 100, 103 ≤ d ≤ 105) — the number of stations and the constant from the statement.

The second line contains n - 2 integers: a2, a3, ..., an - 1 (1 ≤ ai ≤ 103). The next n lines contain the coordinates of the stations. The i-th of them contains two integers xi, yi (-100 ≤ xi, yi ≤ 100).

It is guaranteed that no two stations are located at the same point.

Output

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

Examples

Input

3 1000
1000
0 0
0 1
0 3

Output

2000

Input

3 1000
1000
1 0
1 1
1 2

Output

1000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[100001], x[100001], y[100001], dp[1001][1001];
int main() {
  int n, d, i, j, k;
  cin >> n >> d;
  for (i = 2; i <= n - 1; i++) cin >> a[i];
  for (i = 1; i <= n; i++) {
    cin >> x[i];
    cin >> y[i];
  }
  a[n] = 0;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      if (i == j)
        dp[i][j] = 0;
      else {
        dp[i][j] = d * (abs(x[i] - x[j]) + abs(y[i] - y[j])) - a[i];
      }
    }
  }
  for (k = 1; k <= n; k++) {
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= n; j++) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
    }
  }
  cout << dp[1][n];
  return 0;
}

```


### Prompt

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

You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room.

For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left.

Assume that initially no person lives in the building.

Constraints

* No incorrect building, floor and room numbers are given.
* 0 ≤ the number of tenants during the management ≤ 9

Input

In the first line, the number of notices n is given. In the following n lines, a set of four integers b, f, r and v which represents ith notice is given in a line.

Output

For each building, print the information of 1st, 2nd and 3rd floor in this order. For each floor information, print the number of tenants of 1st, 2nd, .. and 10th room in this order. Print a single space character before the number of tenants. Print "####################" (20 '#') between buildings.

Example

Input

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

Output

0 0 8 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
####################
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
####################
 0 0 0 0 0 0 0 0 0 0
 0 7 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
####################
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 1 0 0

### Response

```cpp
#include <iostream>
using namespace std;
int a[4][3][10] = {0};
int main(){
	int n, b, f, r, v;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		a[b-1][f-1][r-1] += v;
	}
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 10; k++){
				cout << " " << a[i][j][k];
			}
			cout << endl;
		}
		if (i < 3){
			cout << "####################" << endl;
		}
	}
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

This problem consists of three subproblems: for solving subproblem F1 you will receive 8 points, for solving subproblem F2 you will receive 15 points, and for solving subproblem F3 you will receive 10 points.

Manao has developed a model to predict the stock price of a company over the next n days and wants to design a profit-maximizing trading algorithm to make use of these predictions. Unfortunately, Manao's trading account has the following restrictions:

  * It only allows owning either zero or one shares of stock at a time;
  * It only allows buying or selling a share of this stock once per day;
  * It allows a maximum of k buy orders over the next n days;

For the purposes of this problem, we define a trade to a be the act of buying one share of stock on day i, then holding the stock until some day j > i at which point the share is sold. To restate the above constraints, Manao is permitted to make at most k non-overlapping trades during the course of an n-day trading period for which Manao's model has predictions about the stock price.

Even though these restrictions limit the amount of profit Manao can make compared to what would be achievable with an unlimited number of trades or the ability to hold more than one share at a time, Manao still has the potential to make a lot of money because Manao's model perfectly predicts the daily price of the stock. For example, using this model, Manao could wait until the price is low, then buy one share and hold until the price reaches a high value, then sell for a profit, and repeat this process up to k times until n days have passed.

Nevertheless, Manao is not satisfied by having a merely good trading algorithm, and wants to develop an optimal strategy for trading subject to these constraints. Help Manao achieve this goal by writing a program that will determine when to buy and sell stock to achieve the greatest possible profit during the n-day trading period subject to the above constraints.

Input

The first line contains two integers n and k, separated by a single space, with <image>. The i-th of the following n lines contains a single integer pi (0 ≤ pi ≤ 1012), where pi represents the price at which someone can either buy or sell one share of stock on day i.

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

  * In subproblem F1 (8 points), n will be between 1 and 3000, inclusive.
  * In subproblem F2 (15 points), n will be between 1 and 100000, inclusive.
  * In subproblem F3 (10 points), n will be between 1 and 4000000, inclusive.

Output

For this problem, the program will only report the amount of the optimal profit, rather than a list of trades that can achieve this profit.

Therefore, the program should print one line containing a single integer, the maximum profit Manao can achieve over the next n days with the constraints of starting with no shares on the first day of trading, always owning either zero or one shares of stock, and buying at most k shares over the course of the n-day trading period.

Examples

Input

10 2
2
7
3
9
8
7
9
7
1
9

Output

15

Input

10 5
2
7
3
9
8
7
9
7
1
9

Output

21

Note

In the first example, the best trade overall is to buy at a price of 1 on day 9 and sell at a price of 9 on day 10 and the second best trade overall is to buy at a price of 2 on day 1 and sell at a price of 9 on day 4. Since these two trades do not overlap, both can be made and the profit is the sum of the profits of the two trades. Thus the trade strategy looks like this:

    2    | 7    | 3    | 9    | 8    | 7    | 9    | 7    | 1    | 9
    buy  |      |      | sell |      |      |      |      | buy  | sell

The total profit is then (9 - 2) + (9 - 1) = 15.

In the second example, even though Manao is allowed up to 5 trades there are only 4 profitable trades available. Making a fifth trade would cost Manao money so he only makes the following 4:

    2    | 7    | 3    | 9    | 8    | 7    | 9    | 7    | 1    | 9
    buy  | sell | buy  | sell |      | buy  | sell |      | buy  | sell

The total profit is then (7 - 2) + (9 - 3) + (9 - 7) + (9 - 1) = 21.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, oo = inf;
inline long long read() {
  register long long x = 0;
  char f = 0;
  register char c = getchar();
  for (; !isdigit(c); c = getchar()) f |= (c == '-');
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  return f ? -x : x;
}
inline void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
inline void writeln(long long x, char c, long long y) {
  write(x);
  putchar(c);
  writeln(y);
}
inline void writeln(long long x, char c, long long y, char d, long long z) {
  write(x);
  putchar(c);
  write(y);
  putchar(d);
  writeln(z);
}
const int maxn = 4e6 + 233;
int n, k, m;
long long a[maxn], b[maxn];
long long sl[maxn], sr[maxn];
int tl, tr;
int main() {
  n = read(), k = read();
  for (register int i = (1); i <= (n); ++i) a[i] = read();
  tl = tr = 0;
  for (int i = 1, j; i < n; i = j + 1) {
    for (j = i; j <= n && a[j + 1] > a[j]; ++j)
      ;
    if (i == j) continue;
    assert(i < j);
    while (tl && sl[tl] > a[i]) b[++m] = sr[tr--] - sl[tl--];
    sl[++tl] = a[i];
    while (tr && sr[tr] < a[j]) b[++m] = sr[tr--] - sl[tl--];
    sr[++tr] = a[j];
  }
  while (tr) b[++m] = sr[tr--] - sl[tl--];
  k = min(k, m);
  nth_element(b + 1, b + k, b + 1 + m, greater<long long>());
  long long ans = 0;
  for (register int i = (1); i <= (k); ++i) ans += b[i];
  writeln(ans);
  return 0;
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.

The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.

Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:

  * climb one area up;
  * climb one area down;
  * jump to the opposite wall. That gets the ninja to the area that is exactly k meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area x of one wall, then after the jump he is located at area x + k of the other wall.

If at some point of time the ninja tries to get to an area with a number larger than n, then we can assume that the ninja got out of the canyon.

The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.

The level is considered completed if the ninja manages to get out of the canyon.

After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question.

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 105) — the height of the canyon and the height of ninja's jump, correspondingly.

The second line contains the description of the left wall — a string with the length of n characters. The i-th character represents the state of the i-th wall area: character "X" represents a dangerous area and character "-" represents a safe area.

The third line describes the right wall in the same format.

It is guaranteed that the first area of the left wall is not dangerous.

Output

Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes).

Examples

Input

7 3
---X--X
-X--XX-

Output

YES

Input

6 2
--X-X-
X--XX-

Output

NO

Note

In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.

In the second sample there's no way the ninja can get out of the canyon.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long n, k;
string s[2];
map<pair<long long, long long>, long long> dis, vis;
long long bfs() {
  queue<pair<long long, long long> > q;
  q.push(make_pair(0LL, 0LL));
  dis[make_pair(0LL, 0LL)] = 0;
  vis[make_pair(0LL, 0LL)] = 1;
  pair<long long, long long> p;
  while (!q.empty()) {
    p = q.front();
    q.pop();
    if (!vis[make_pair(p.first, p.second + 1)] &&
        s[p.first][p.second + 1] == '-' && dis[p] + 1 <= p.second + 1) {
      q.push(make_pair(p.first, p.second + 1));
      vis[make_pair(p.first, p.second + 1)] = 1;
      dis[make_pair(p.first, p.second + 1)] = dis[p] + 1;
      if (p.second + 1 >= n) return cout << "YES", 0;
    }
    if (p.second - 1 >= 0 && !vis[make_pair(p.first, p.second - 1)] &&
        s[p.first][p.second - 1] == '-' && dis[p] + 1 <= p.second - 1) {
      q.push(make_pair(p.first, p.second - 1));
      vis[make_pair(p.first, p.second - 1)] = 1;
      dis[make_pair(p.first, p.second - 1)] = dis[p] + 1;
      if (p.second - 1 >= n) return cout << "YES", 0;
    }
    if (!vis[make_pair(abs(p.first - 1), p.second + k)] &&
        s[abs(p.first - 1)][p.second + k] == '-' &&
        dis[p] + 1 <= p.second + k) {
      q.push(make_pair(abs(p.first - 1), p.second + k));
      vis[make_pair(abs(p.first - 1), p.second + k)] = 1;
      dis[make_pair(abs(p.first - 1), p.second + k)] = dis[p] + 1;
      if (p.second + k >= n) return cout << "YES", 0;
    }
  }
  return cout << "NO", 0;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  cin >> s[0] >> s[1];
  for (long long i = 0; i < 100002; i++) {
    s[0] += '-';
    s[1] += '-';
  }
  bfs();
}

```


### Prompt

Create a solution in CPP for the following problem:

On vacations n pupils decided to go on excursion and gather all together. They need to overcome the path with the length l meters. Each of the pupils will go with the speed equal to v1. To get to the excursion quickly, it was decided to rent a bus, which has seats for k people (it means that it can't fit more than k people at the same time) and the speed equal to v2. In order to avoid seasick, each of the pupils want to get into the bus no more than once.

Determine the minimum time required for all n pupils to reach the place of excursion. Consider that the embarkation and disembarkation of passengers, as well as the reversal of the bus, take place immediately and this time can be neglected.

Input

The first line of the input contains five positive integers n, l, v1, v2 and k (1 ≤ n ≤ 10 000, 1 ≤ l ≤ 109, 1 ≤ v1 < v2 ≤ 109, 1 ≤ k ≤ n) — the number of pupils, the distance from meeting to the place of excursion, the speed of each pupil, the speed of bus and the number of seats in the bus.

Output

Print the real number — the minimum time in which all pupils can reach the place of excursion. Your answer will be considered correct if its absolute or relative error won't exceed 10 - 6.

Examples

Input

5 10 1 2 5

Output

5.0000000000

Input

3 6 1 2 1

Output

4.7142857143

Note

In the first sample we should immediately put all five pupils to the bus. The speed of the bus equals 2 and the distance is equal to 10, so the pupils will reach the place of excursion in time 10 / 2 = 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long L, v1, v2, R, N, K, A, B;
  cin >> N >> L >> v1 >> v2 >> K;
  R = (N - 1) / K;
  A = 2 * R * v2 + v1 + v2, B = 2 * R * v1 + v1 + v2;
  double answer = static_cast<double>(A * 1.0) / B;
  answer *= (L / (v2 * 1.0));
  cout << setiosflags(ios::showpoint) << setiosflags(ios::fixed)
       << setprecision(10) << answer << endl;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last.

Now Polycarp wants to publish exactly k (1 ≤ k ≤ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then:

  * s_1+s_2+...+s_k=n (s_i>0),
  * the first post contains the videos: 1, 2, ..., s_1;
  * the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2;
  * the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3;
  * ...
  * the k-th post contains videos: n-s_k+1,n-s_k+2,...,n.

Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.

Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above.

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^4), where a_i is the duration of the i-th video.

Output

If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).

If there is no solution, print a single line "No".

Examples

Input

6 3
3 3 1 4 1 6

Output

Yes
2 3 1

Input

3 3
1 1 1

Output

Yes
1 1 1

Input

3 3
1 1 2

Output

No

Input

3 1
1 10 100

Output

Yes
3

### Response

```cpp
#include <bits/stdc++.h>
const int maxn = 1e5 + 1;
int num[maxn];
int jilu[maxn];
int main() {
  int n, k;
  int a;
  scanf("%d %d", &n, &k);
  scanf("%d", &a);
  num[1] = a;
  for (int i = 2; i <= n; ++i) {
    scanf("%d", &a);
    num[i] = num[i - 1] + a;
  }
  int d = num[n] / k;
  int p = num[n] % k;
  if (!p) {
    int cnt = 1;
    int pre = 0;
    for (int i = 1; i <= n; ++i) {
      if (num[i] == d * cnt) {
        jilu[cnt] = i - pre;
        pre = i;
        cnt++;
      }
    }
    if ((cnt - 1) != k)
      puts("No");
    else {
      puts("Yes");
      for (int i = 1; i < cnt; i++) printf("%d ", jilu[i]);
      puts("");
    }
  } else
    puts("No\n");
  return 0;
}

```


### Prompt

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

In the city of Nevermore, there are 10^8 streets and 10^8 avenues, both numbered from 0 to 10^8-1. All streets run straight from west to east, and all avenues run straight from south to north. The distance between neighboring streets and between neighboring avenues is exactly 100 meters.

Every street intersects every avenue. Every intersection can be described by pair (x, y), where x is avenue ID and y is street ID.

There are N fountains in the city, situated at intersections (X_i, Y_i). Unlike normal intersections, there's a circle with radius 10 meters centered at the intersection, and there are no road parts inside this circle.

The picture below shows an example of how a part of the city with roads and fountains may look like.

1f931bf0c98ec6f07e612b0282cdb094.png

City governors don't like encountering more than one fountain while moving along the same road. Therefore, every street contains at most one fountain on it, as well as every avenue.

Citizens can move along streets, avenues and fountain perimeters. What is the shortest distance one needs to cover in order to get from intersection (x_1, y_1) to intersection (x_2, y_2)?

Constraints

* 0 \leq x_1, y_1, x_2, y_2 < 10^8
* 1 \leq N \leq 200,000
* 0 \leq X_i, Y_i < 10^8
* X_i \neq X_j for i \neq j
* Y_i \neq Y_j for i \neq j
* Intersections (x_1, y_1) and (x_2, y_2) are different and don't contain fountains.
* All input values are integers.

Input

Input is given from Standard Input in the following format:

x_1 y_1 x_2 y_2
N
X_1 Y_1
X_2 Y_2
:
X_N Y_N

Output

Print the shortest possible distance one needs to cover in order to get from intersection (x_1, y_1) to intersection (x_2, y_2), in meters. Your answer will be considered correct if its absolute or relative error doesn't exceed 10^{-11}.

Examples

Input

1 1 6 5
3
3 2
5 3
2 4

Output

891.415926535897938

Input

3 5 6 4
3
3 2
5 3
2 4

Output

400.000000000000000

Input

4 2 2 2
3
3 2
5 3
2 4

Output

211.415926535897938

### Response

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

//#define double long double

const int MAXN = 2E5 + 10;
const double PI = atan((double)1.0) * 4;

int n, lis[MAXN];

vector<pair<int, int> > fount;

int main() {
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(0);
	int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2 >> n;
	if (x1 > x2) swap(x1, x2), swap(y1, y2);
	bool flip = false;
	if (y1 > y2) {
		flip = true;
		y1 = 1E9 - y1, y2 = 1E9 - y2;
	}
	for (int i = 1; i <= n; i++) {
		int x, y; cin >> x >> y;
		if (flip) y = 1E9 - y;
		if (x1 <= x && x <= x2 && y1 <= y && y <= y2) fount.push_back({ x, y });
	}
	sort(fount.begin(), fount.end());
	int ans = 0;
	for (int i = 0; i < (int)fount.size(); i++) {
		int p = lower_bound(lis, lis + ans, fount[i].second) - lis;
		if (p == ans) lis[ans++] = fount[i].second;
		else lis[p] = fount[i].second;
	}
	double gridAns = 100.0 * (x2 - x1 + y2 - y1);
	if (ans == min(x2 - x1, y2 - y1) + 1) {
		gridAns -= 20 - 10 * PI;
		ans--;
	}
	cout << fixed << setprecision(15) << gridAns - ans * (20 - 5 * PI) << '\n';
}

```


### Prompt

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

We have a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and b_i. For each k=1, ..., N, solve the problem below:

* Consider writing a number on each vertex in the tree in the following manner:
* First, write 1 on Vertex k.
* Then, for each of the numbers 2, ..., N in this order, write the number on the vertex chosen as follows:
* Choose a vertex that still does not have a number written on it and is adjacent to a vertex with a number already written on it. If there are multiple such vertices, choose one of them at random.
* Find the number of ways in which we can write the numbers on the vertices, modulo (10^9+7).

Constraints

* 2 \leq N \leq 2 \times 10^5
* 1 \leq a_i,b_i \leq N
* The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
:
a_{N-1} b_{N-1}

Output

For each k=1, 2, ..., N in this order, print a line containing the answer to the problem.

Examples

Input

3
1 2
1 3

Output

2
1
1

Input

2
1 2

Output

1
1

Input

5
1 2
2 3
3 4
3 5

Output

2
8
12
3
3

Input

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

Output

40
280
840
120
120
504
72
72

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
const ll mod=1e9+7;
vector<int>g[N];
int n,x,y;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
ll p[N],s[N],f[N];

void dfs(int u){
    s[u]=1;
    f[u]=1;
    for(auto v:g[u]){
        if(!s[v]){
            dfs(v);
            s[u]+=s[v];
            p[v]=u;
            f[u]=f[u]*f[v]%mod;
        }
    }
    f[u]=f[u]*s[u]%mod;
}

void calculate(int u){
    for(auto v:g[u]){
        if(v!=p[u]){
            f[v]=f[u]*(n-s[v])%mod*power(s[v],mod-2)%mod;
            calculate(v);
        }
    }
}

int main()
{
    cin>>n;
    for(int i=0;i<n-1;i++){
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    ll S=1;
    for(int i=1;i<=n;i++) S=S*i%mod;
    dfs(1);
    calculate(1);
    for(int i=1;i<=n;i++)
        cout<<S*power(f[i],mod-2)%mod<<endl;
    return 0;
}

```


### Prompt

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

There is a trampoline park with n trampolines in a line. The i-th of which has strength S_i.

Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice.

If at the moment Pekora jumps on trampoline i, the trampoline will launch her to position i + S_i, and S_i will become equal to max(S_i-1,1). In other words, S_i will decrease by 1, except of the case S_i=1, when S_i will remain equal to 1.

If there is no trampoline in position i + S_i, then this pass is over. Otherwise, Pekora will continue the pass by jumping from the trampoline at position i + S_i by the same rule as above.

Pekora can't stop jumping during the pass until she lands at the position larger than n (in which there is no trampoline). Poor Pekora!

Pekora is a naughty rabbit and wants to ruin the trampoline park by reducing all S_i to 1. What is the minimum number of passes she needs to reduce all S_i to 1?

Input

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

The first line of each test case contains a single integer n (1 ≤ n ≤ 5000) — the number of trampolines.

The second line of each test case contains n integers S_1, S_2, ..., S_n (1 ≤ S_i ≤ 10^9), where S_i is the strength of the i-th trampoline.

It's guaranteed that the sum of n over all test cases doesn't exceed 5000.

Output

For each test case, output a single integer — the minimum number of passes Pekora needs to do to reduce all S_i to 1.

Example

Input

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

Output

4
3
0

Note

For the first test case, here is an optimal series of passes Pekora can take. (The bolded numbers are the positions that Pekora jumps into during these passes.)

  * [1,4,2,2,2,2,2]
  * [1,4,1,2,1,2,1]
  * [1,3,1,2,1,1,1]
  * [1,2,1,2,1,1,1]

For the second test case, the optimal series of passes is show below.

  * [2,3]
  * [1,3]
  * [1,2]

For the third test case, all S_i are already equal to 1.

### Response

```cpp
//shitty code dont judge
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
#include <bitset>
#include <math.h>
#include <stdlib.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e9
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())

int tr[5005];
ll pek[5005], kount;

void solve(){
    memset(tr, 0, sizeof tr);
    memset(pek, 0, sizeof pek);
    kount = 0;

    int n;
    cin>>n;

    for(int i = 0; i < n; i++){
        cin>>tr[i];
    }

    for(int i = 0; i < n; i++){
        if(tr[i] == 1 && i < n-1){
            pek[i+1] += pek[i];
            continue;
        }

        if(tr[i] > pek[i] + 1){
            kount += tr[i] - pek[i] - 1;
        }
        else{
            pek[i+1] += pek[i] - tr[i] + 1;
        }

        for(int j = 2; j <= tr[i] && (i + j) < n; j++){
            pek[i + j]++;
        }
    }

    cout<<kount<<ln;
}
int main()
{

    ll t;
    cin >> t;
    for(int it=1;it<=t;it++) {
     //cout << "Case #" << it+1 << ": ";
        solve();
    }
    return 0;
}
```


### Prompt

Develop a solution in CPP to the problem described below:

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

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

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

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

<image>

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

Input

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

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

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

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

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

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

<image>

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

Output

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

Sample Input

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

Output for the Sample Input

58.953437
11.414214
16.0
61.874812
63.195179

Example

Input

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

Output

58.953437
11.414214
16.0
61.874812
63.195179

### Response

```cpp
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
using namespace std;
#define EPS 1e-10
#define INF 1e9

double add(double a,double b){
	if(fabs(a+b)<EPS*(fabs(a)+fabs(b)))return 0;
	return a+b;
}

class P{
public:
	double x,y,r;
	P(){}
	P(double xx,double yy,double rr){
		x=xx;
		y=yy;
		r=rr;
	}
	P operator +(P p){
		return P(add(x,p.x),add(y,p.y),r);
	}
	P operator -(P p){
		return P(add(x,-p.x),add(y,-p.y),r);
	}
	P operator *(double d){
		return P(x*d,y*d,r);
	}
	P operator /(double d){
		return P(x/d,y/d,r);
	}
	double dot(P p){
		return add(x*p.x,y*p.y);
	}
	double det(P p){
		return add(x*p.y,-y*p.x);
	}
};

bool on_seg(P p1,P p2,P q){
	return (p1-q).det(p2-q)==0 && (p1-q).dot(p2-q)<=0;
}

P intersection(P p1,P p2,P q1,P q2){
	return p1+(p2-p1)*((q2-q1).det(q1-p1)/(q2-q1).det(p2-p1));
}

class node{
public:
	double cost;
	int v,v2;
	node(){}
	node(double cc,int vv,int vv2){
		cost=cc;
		v=vv;
		v2=vv2;
	}
	bool operator<(const node& n1)const{
		return cost>n1.cost;
	}
};

int n;
P p[105];
P data[105][2];
double dp[105][2];

double dijk(){
	for(int i=0;i<=n;i++){
		dp[i][0]=dp[i][1]=INF;
	}
	priority_queue<node> que;
	que.push(node(0.0,0,0));
	dp[0][0]=0.0;
	while(que.size()){
		node q=que.top();
		que.pop();
		if(dp[q.v][q.v2]<q.cost)continue;
		for(int next=q.v;next<=n;next++){
			for(int j=0;j<2;j++){
				if((next==n+1 || next==0) && j==1)continue;
				bool flag=true;
				for(int k=q.v+1;k<next;k++){
					if((data[q.v][q.v2]-data[k][0]).det(data[next][j]-data[k][1])==0){
						if(!(on_seg(data[q.v][q.v2],data[k][0],data[next][j])
						  || on_seg(data[q.v][q.v2],data[k][0],data[k][1])
						  || on_seg(data[next][j],data[k][1],data[next][j])
						  || on_seg(data[next][j],data[k][1],data[k][0])))flag=false;
					}else{
						P r=intersection(data[q.v][q.v2],data[next][j],data[k][0],data[k][1]);
						if(!(on_seg(data[k][0],data[k][1],r) && on_seg(data[q.v][q.v2],data[next][j],r)))flag=false;
					}
				}
				if(flag){
					P len=data[next][j]-data[q.v][q.v2];
					double len2=sqrt(add((len.x*len.x),(len.y*len.y)));
					if(add(dp[q.v][q.v2],len2)<dp[next][j]){
						dp[next][j]=add(dp[q.v][q.v2],len2);
						que.push(node(dp[next][j],next,j));
					}
				}
			}
		}
	}
	return dp[n][0];
}

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			scanf("%lf %lf %lf",&p[i].x,&p[i].y,&p[i].r);
		}
		data[0][0]=p[0];
		data[n][0]=p[n-1];
		for(int i=0;i<n-1;i++){
			P pp=p[i+1]-p[i];
			double len=add(pp.x*pp.x,pp.y*pp.y);
			double d=(add(p[i].r*p[i].r,-p[i+1].r*p[i+1].r)+len)/(2*sqrt(len));
			double c=sqrt(add(p[i].r*p[i].r,-d*d));
			double ang=atan2(pp.y,pp.x);
			double ang2=atan2(c,d);
			data[i+1][0]=p[i]+P(p[i].r*cos(add(ang,ang2)),p[i].r*sin(add(ang,ang2)),0);
			data[i+1][1]=p[i]+P(p[i].r*cos(add(ang,-ang2)),p[i].r*sin(add(ang,-ang2)),0);
		}
		printf("%.4f\n",dijk());
	}
	return 0;
}
```


### Prompt

Please formulate a cpp solution to the following problem:

Rational numbers are numbers represented by ratios of two integers. For a prime number p, one of the elementary theorems in the number theory is that there is no rational number equal to √p. Such numbers are called irrational numbers. It is also known that there are rational numbers arbitrarily close to √p

Now, given a positive integer n, we define a set Qn of all rational numbers whose elements are represented by ratios of two positive integers both of which are less than or equal to n. For example, Q4 is a set of 11 rational numbers {1/1, 1/2, 1/3, 1/4, 2/1, 2/3, 3/1, 3/2, 3/4, 4/1, 4/3}. 2/2, 2/4, 3/3, 4/2 and 4/4 are not included here because they are equal to 1/1, 1/2, 1/1, 2/1 and 1/1, respectively.

Your job is to write a program that reads two integers p and n and reports two rational numbers x / y and u / v, where u / v < √p < x / y and there are no other elements of Qn between u/v and x/y. When n is greater than √p, such a pair of rational numbers always exists.

Input

The input consists of lines each of which contains two positive integers, a prime number p and an integer n in the following format.

p n

They are separated by a space character. You can assume that p and n are less than 10000, and that n is greater than √p. The end of the input is indicated by a line consisting of two zeros.

Output

For each input line, your program should output a line consisting of the two rational numbers x / y and u / v (x / y > u / v) separated by a space character in the following format.

x/y u/v

They should be irreducible. For example, 6/14 and 15/3 are not accepted. They should be reduced to 3/7 and 5/1, respectively.

Example

Input

2 5
3 10
5 100
0 0

Output

3/2 4/3
7/4 5/3
85/38 38/17

### Response

```cpp
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

int L;
vector<pair<int, int> > R;

double sp;

void sternBrocot(int x=0, int y=1, int z=1, int w=0){
    if ( w > 0 && y > 0&& !(1.0*x/y < sp && sp < 1.0*z/w) ) return;
    int num = x+z;
    int den = y+w;
    if ( num > L || den > L) return;
    sternBrocot(x, y, num, den);
    R.push_back(make_pair(num, den));
    sternBrocot(num, den, z, w);
}

int main(){
    int p, n;
    while( cin >> p >> n && p && n ){
	L = n;
	R.clear();
	sp = sqrt(p);
	sternBrocot();
	pair<int, int> r1, r2;
	for ( int i = 0; i < R.size()-1; i++ ){
	    r1 = R[i];
	    r2 = R[i+1];
	    if ( 1.0*r1.first/r1.second < sp &&
		 sp < 1.0*r2.first/r2.second ){
		cout << r2.first << "/" << r2.second << " ";
		cout << r1.first << "/" << r1.second << endl;
	    }
	}
    }
}
```


### Prompt

Create a solution in cpp for the following problem:

Little girl Susie accidentally found her elder brother's notebook. She has many things to do, more important than solving problems, but she found this problem too interesting, so she wanted to know its solution and decided to ask you about it. So, the problem statement is as follows.

Let's assume that we are given a connected weighted undirected graph G = (V, E) (here V is the set of vertices, E is the set of edges). The shortest-path tree from vertex u is such graph G1 = (V, E1) that is a tree with the set of edges E1 that is the subset of the set of edges of the initial graph E, and the lengths of the shortest paths from u to any vertex to G and to G1 are the same.

You are given a connected weighted undirected graph G and vertex u. Your task is to find the shortest-path tree of the given graph from vertex u, the total weight of whose edges is minimum possible.

Input

The first line contains two numbers, n and m (1 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) — the number of vertices and edges of the graph, respectively.

Next m lines contain three integers each, representing an edge — ui, vi, wi — the numbers of vertices connected by an edge and the weight of the edge (ui ≠ vi, 1 ≤ wi ≤ 109). It is guaranteed that graph is connected and that there is no more than one edge between any pair of vertices.

The last line of the input contains integer u (1 ≤ u ≤ n) — the number of the start vertex.

Output

In the first line print the minimum total weight of the edges of the tree.

In the next line print the indices of the edges that are included in the tree, separated by spaces. The edges are numbered starting from 1 in the order they follow in the input. You may print the numbers of the edges in any order.

If there are multiple answers, print any of them.

Examples

Input

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

Output

2
1 2

Input

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

Output

4
2 3 4

Note

In the first sample there are two possible shortest path trees:

  * with edges 1 – 3 and 2 – 3 (the total weight is 3);
  * with edges 1 – 2 and 2 – 3 (the total weight is 2);

And, for example, a tree with edges 1 – 2 and 1 – 3 won't be a shortest path tree for vertex 3, because the distance from vertex 3 to vertex 2 in this tree equals 3, and in the original graph it is 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct node {
  long long from;
  long long to;
  long long next;
  long long val;
} edge[350010 << 1];
long long n, m, cnt, src, ans;
long long head[350010], visit[350010], dis[350010], pre[350010];
void init() {
  memset(head, -1, sizeof(head));
  cnt = 0;
}
void addedge(long long from, long long to, long long val) {
  edge[++cnt].from = from;
  edge[cnt].to = to;
  edge[cnt].val = val;
  edge[cnt].next = head[from];
  head[from] = cnt;
}
void SPFA() {
  memset(dis, 0x3f3f3f3f, sizeof(dis));
  memset(visit, 0, sizeof(visit));
  visit[src] = 1;
  dis[src] = 0;
  queue<int> Q;
  Q.push(src);
  while (!Q.empty()) {
    long long u = Q.front();
    Q.pop();
    visit[u] = 0;
    for (long long i = head[u]; i != -1; i = edge[i].next) {
      long long v = edge[i].to;
      if (dis[v] > dis[u] + edge[i].val) {
        dis[v] = dis[u] + edge[i].val;
        pre[v] = i;
        if (!visit[v]) {
          visit[v] = 1;
          Q.push(v);
        }
      } else if (dis[v] == dis[u] + edge[i].val &&
                 edge[i].val < edge[pre[v]].val) {
        pre[v] = i;
      }
    }
  }
}
int main() {
  init();
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= m; i++) {
    long long a, b, c;
    scanf("%lld%lld%lld", &a, &b, &c);
    addedge(a, b, c);
    addedge(b, a, c);
  }
  scanf("%lld", &src);
  SPFA();
  for (long long i = 1; i <= n; i++) {
    if (pre[i]) ans += (edge[pre[i]].val);
  }
  printf("%lld\n", ans);
  for (long long i = 1; i <= n; i++) {
    if (pre[i]) printf("%lld ", (pre[i] + 1) / 2);
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

In an English class Nick had nothing to do at all, and remembered about wonderful strings called palindromes. We should remind you that a string is called a palindrome if it can be read the same way both from left to right and from right to left. Here are examples of such strings: «eye», «pop», «level», «aba», «deed», «racecar», «rotor», «madam».

Nick started to look carefully for all palindromes in the text that they were reading in the class. For each occurrence of each palindrome in the text he wrote a pair — the position of the beginning and the position of the ending of this occurrence in the text. Nick called each occurrence of each palindrome he found in the text subpalindrome. When he found all the subpalindromes, he decided to find out how many different pairs among these subpalindromes cross. Two subpalindromes cross if they cover common positions in the text. No palindrome can cross itself.

Let's look at the actions, performed by Nick, by the example of text «babb». At first he wrote out all subpalindromes:

• «b» — 1..1 • «bab» — 1..3 • «a» — 2..2 • «b» — 3..3 • «bb» — 3..4 • «b» — 4..4

Then Nick counted the amount of different pairs among these subpalindromes that cross. These pairs were six:

1. 1..1 cross with 1..3 2. 1..3 cross with 2..2 3. 1..3 cross with 3..3 4. 1..3 cross with 3..4 5. 3..3 cross with 3..4 6. 3..4 cross with 4..4

Since it's very exhausting to perform all the described actions manually, Nick asked you to help him and write a program that can find out the amount of different subpalindrome pairs that cross. Two subpalindrome pairs are regarded as different if one of the pairs contains a subpalindrome that the other does not.

Input

The first input line contains integer n (1 ≤ n ≤ 2·106) — length of the text. The following line contains n lower-case Latin letters (from a to z).

Output

In the only line output the amount of different pairs of two subpalindromes that cross each other. Output the answer modulo 51123987.

Examples

Input

4
babb

Output

6

Input

2
aa

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 4e6 + 5000, mod = 51123987;
int hw[N], n, l[N], r[N];
char st[N];
void solve() {
  st[0] = 1;
  int nn = n * 2 - 1;
  for (int i = nn; i >= 1; i--) st[i] = (i & 1) ? st[(i >> 1) + 1] : '#';
  int mx = 0, mid = 0;
  long long cnt = 0;
  for (int i = 1; i <= nn; i++) {
    hw[i] = i <= mx ? min(hw[2 * mid - i], mx - i + 1) : 1;
    for (; i + hw[i] <= nn && i - hw[i] >= 1 && st[i + hw[i]] == st[i - hw[i]];
         hw[i]++)
      ;
    if (i + hw[i] - 1 > mx) mx = i + hw[i] - 1, mid = i;
    r[i]++, r[i + hw[i]]--;
    l[i - hw[i] + 1]++, l[i + 1]--;
    cnt += (hw[i] + (i & 1)) >> 1;
  }
  cnt %= mod;
  for (int i = 1; i <= nn + 1; i++) l[i] += l[i - 1], r[i] += r[i - 1];
  for (int i = nn; i >= 1; i--)
    if (st[i] != '#')
      l[i] = (l[i] + l[i + 1]) % mod;
    else
      l[i] = l[i + 1];
  long long ans = (cnt * (cnt - 1) >> 1) % mod;
  for (int i = 1; i < nn; i += 2) ans = (ans - 1ll * r[i] * l[i + 1]) % mod;
  cout << (ans + mod) % mod << endl;
}
int main() {
  scanf("%d", &n);
  scanf("%s", st + 1);
  solve();
}

```


### Prompt

Create a solution in CPP for the following problem:

The Smart Beaver from ABBYY has once again surprised us! He has developed a new calculating device, which he called the "Beaver's Calculator 1.0". It is very peculiar and it is planned to be used in a variety of scientific problems.

To test it, the Smart Beaver invited n scientists, numbered from 1 to n. The i-th scientist brought ki calculating problems for the device developed by the Smart Beaver from ABBYY. The problems of the i-th scientist are numbered from 1 to ki, and they must be calculated sequentially in the described order, since calculating each problem heavily depends on the results of calculating of the previous ones.

Each problem of each of the n scientists is described by one integer ai, j, where i (1 ≤ i ≤ n) is the number of the scientist, j (1 ≤ j ≤ ki) is the number of the problem, and ai, j is the number of resource units the calculating device needs to solve this problem.

The calculating device that is developed by the Smart Beaver is pretty unusual. It solves problems sequentially, one after another. After some problem is solved and before the next one is considered, the calculating device allocates or frees resources.

The most expensive operation for the calculating device is freeing resources, which works much slower than allocating them. It is therefore desirable that each next problem for the calculating device requires no less resources than the previous one.

You are given the information about the problems the scientists offered for the testing. You need to arrange these problems in such an order that the number of adjacent "bad" pairs of problems in this list is minimum possible. We will call two consecutive problems in this list a "bad pair" if the problem that is performed first requires more resources than the one that goes after it. Do not forget that the problems of the same scientist must be solved in a fixed order.

Input

The first line contains integer n — the number of scientists. To lessen the size of the input, each of the next n lines contains five integers ki, ai, 1, xi, yi, mi (0 ≤ ai, 1 < mi ≤ 109, 1 ≤ xi, yi ≤ 109) — the number of problems of the i-th scientist, the resources the first problem requires and three parameters that generate the subsequent values of ai, j. For all j from 2 to ki, inclusive, you should calculate value ai, j by formula ai, j = (ai, j - 1 * xi + yi) mod mi, where a mod b is the operation of taking the remainder of division of number a by number b.

To get the full points for the first group of tests it is sufficient to solve the problem with n = 2, 1 ≤ ki ≤ 2000.

To get the full points for the second group of tests it is sufficient to solve the problem with n = 2, 1 ≤ ki ≤ 200000.

To get the full points for the third group of tests it is sufficient to solve the problem with 1 ≤ n ≤ 5000, 1 ≤ ki ≤ 5000.

Output

On the first line print a single number — the number of "bad" pairs in the optimal order.

If the total number of problems does not exceed 200000, also print <image> lines — the optimal order of the problems. On each of these lines print two integers separated by a single space — the required number of resources for the problem and the number of the scientist who offered this problem, respectively. The scientists are numbered from 1 to n in the order of input.

Examples

Input

2
2 1 1 1 10
2 3 1 1 10

Output

0
1 1
2 1
3 2
4 2

Input

2
3 10 2 3 1000
3 100 1 999 1000

Output

2
10 1
23 1
49 1
100 2
99 2
98 2

Note

In the first sample n = 2, k1 = 2, a1, 1 = 1, a1, 2 = 2, k2 = 2, a2, 1 = 3, a2, 2 = 4. We've got two scientists, each of them has two calculating problems. The problems of the first scientist require 1 and 2 resource units, the problems of the second one require 3 and 4 resource units. Let's list all possible variants of the calculating order (each problem is characterized only by the number of resource units it requires): (1, 2, 3, 4), (1, 3, 2, 4), (3, 1, 2, 4), (1, 3, 4, 2), (3, 4, 1, 2), (3, 1, 4, 2).

Sequence of problems (1, 3, 2, 4) has one "bad" pair (3 and 2), (3, 1, 4, 2) has two "bad" pairs (3 and 1, 4 and 2), and (1, 2, 3, 4) has no "bad" pairs.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
struct Node {
  int id, cost, cnt;
  Node(int _i, int _cost, int _cnt) {
    id = _i;
    cost = _cost;
    cnt = _cnt;
  }
  bool operator<(const Node &n) const {
    if (cnt != n.cnt)
      return cnt < n.cnt;
    else
      return cost < n.cost;
  }
};
vector<Node> ans;
int main() {
  int ret = 0, n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int k, v, x, y, m, pre = -1, idx = 1;
    scanf("%d %d %d %d %d", &k, &v, &x, &y, &m);
    for (int j = 0; j < k; j++) {
      if (v < pre) idx++;
      if (ans.size() <= 200000) ans.push_back(Node(i + 1, v, idx));
      pre = v;
      v = (v * 1LL * x + y) % m;
    }
    ret = max(ret, idx - 1);
  }
  printf("%d\n", ret);
  if (ans.size() <= 200000) {
    sort(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++) {
      printf("%d %d\n", ans[i].cost, ans[i].id);
    }
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

We have a string S of length N consisting of `R`, `G`, and `B`.

Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions:

* S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k.
* j - i \neq k - j.

Constraints

* 1 \leq N \leq 4000
* S is a string of length N consisting of `R`, `G`, and `B`.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of triplets in question.

Examples

Input

4
RRGB

Output

1

Input

39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB

Output

1800

### Response

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

int main() {
	int n;
	long ans;
	string s;
	cin >> n >> s;
	vector<int> r,g,b;
	for(int i = 0; i<s.size();i++){
		if(s[i] == 'R')r.push_back(i);
		else if(s[i] == 'G')g.push_back(i);
		else b.push_back(i);
	}
	ans = r.size() * g.size() * b.size();

	for(int i = 1; i<= s.size() / 2;i++){
		for(int j = i; j<s.size() - i;j++){
			if(s[j - i] !=s[j] && s[j - i] !=s[j + i] && s[j] !=s[j + i])ans--;
		}
	}
	cout << ans << endl;
 }

```


### Prompt

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

Baby Ehab is known for his love for a certain operation. He has an array a of length n, and he decided to keep doing the following operation on it:

  * he picks 2 adjacent elements; he then removes them and places a single integer in their place: their [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Note that the length of the array decreases by one.

Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least 2 elements remaining.

Input

The first line contains an integer t (1 ≤ t ≤ 15) — the number of test cases you need to solve.

The first line of each test case contains an integers n (2 ≤ n ≤ 2000) — the number of elements in the array a.

The second line contains n space-separated integers a_1, a_2, …, a_{n} (0 ≤ a_i < 2^{30}) — the elements of the array a.

Output

If Baby Ehab can make all elements equal while leaving at least 2 elements standing, print "YES". Otherwise, print "NO".

Example

Input

2
3
0 2 2
4
2 3 1 10

Output

YES
NO

Note

In the first sample, he can remove the first 2 elements, 0 and 2, and replace them by 0 ⊕ 2=2. The array will be [2,2], so all the elements are equal.

In the second sample, there's no way to make all the elements equal.

### Response

```cpp
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;
int n, t, a[N];
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> t;
    while(t--) {
        cin >> n;
        for(int i = 0;i < n;i++)
            cin >> a[i];
        int xr = 0;
        bool yes = false;
        for(int i = 0;i < n;i++) {
            xr ^= a[i];
            int xr1 = 0, cnt = 1;
            for(int j = i + 1;j < n;j++) {
                xr1 ^= a[j];
                if(xr1 == xr)
                    cnt++, xr1 = 0;
            }
            if(xr1 == 0 && cnt >= 2)
                yes = true;
        }
        yes ? cout << "YES\n" : cout << "NO\n";
    }
    return 0;
}
```


### Prompt

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

Little X has solved the #P-complete problem in polynomial time recently. So he gives this task to you.

There is a special n × n matrix A, you should calculate its permanent modulo 1000000007 (109 + 7). The special property of matrix A is almost all its elements equal to 1. Only k elements have specified value.

You can find the definition of permanent at the link: https://en.wikipedia.org/wiki/Permanent

Input

The first line contains two space-separated integers n, k (1 ≤ n ≤ 105; 1 ≤ k ≤ 50).

The next k lines contain the description of the matrix. The i-th line contains three space-separated integers xi, yi, wi (1 ≤ xi, yi ≤ n; 0 ≤ wi ≤ 109). These numbers denote that Axi, yi = wi. All the elements of the matrix except of the given elements are equal to 1.

It's guaranteed that all the positions (xi, yi) are distinct.

Output

Print the permanent of the matrix modulo 1000000007 (109 + 7).

Examples

Input

3 1
1 1 2

Output

8

Input

10 10
3 3 367056794
6 2 124561273
1 3 46718146
6 9 415916869
10 5 985968336
3 1 526792265
1 4 386357058
10 4 349304187
2 7 102032499
3 6 502679075

Output

233333333

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n, k;
vector<int> x, y;
const int MOD = 1000000007;
map<long long, int> dp[55][55];
vector<pair<int, int> > g[55];
int fac[100000 + 20];
long long have[55];
int main() {
  scanf("%d%d", &n, &k);
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % MOD;
  vector<pair<pair<int, int>, int> > e;
  for (int i = 1; i <= k; ++i) {
    int xi, yi, wi;
    scanf("%d%d%d", &xi, &yi, &wi);
    x.push_back(xi);
    y.push_back(yi);
    e.push_back(make_pair(make_pair(xi, yi), wi - 1));
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  for (auto& it : e) {
    it.first.first =
        lower_bound(x.begin(), x.end(), it.first.first) - x.begin();
    it.first.second =
        lower_bound(y.begin(), y.end(), it.first.second) - y.begin();
    g[it.first.first].push_back({it.first.second, it.second});
  }
  int sz = x.size();
  for (int i = sz - 1; i >= 0; --i) {
    have[i] = have[i + 1];
    for (auto it : g[i]) have[i] |= 1ll << it.first;
  }
  dp[0][0][0] = 1;
  for (int i = 0; i <= sz - 1; ++i) {
    for (int j = 0; j <= sz; ++j) {
      for (auto sta = dp[i][j].begin(); sta != dp[i][j].end(); sta++) {
        dp[i + 1][j][sta->first & (have[i + 1])] += sta->second;
        if (dp[i + 1][j][sta->first & (have[i + 1])] >= MOD)
          dp[i + 1][j][sta->first & (have[i + 1])] -= MOD;
        for (auto it : g[i]) {
          int nex = it.first;
          int w = it.second;
          if (((sta->first) >> nex) & 1)
            ;
          else
            (dp[i + 1][j + 1][(sta->first | 1ll << nex) & (have[i + 1])] +=
             1ll * sta->second * w % MOD) %= MOD;
        }
      }
    }
  }
  int rest = 0;
  for (int i = 0; i <= sz; ++i) {
    (rest += 1ll * fac[n - i] * dp[sz][i][0] % MOD) %= MOD;
  }
  cout << rest << endl;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

RJ Freight, a Japanese railroad company for freight operations has recently constructed exchange lines at Hazawa, Yokohama. The layout of the lines is shown in Figure B-1.

<image>
Figure B-1: Layout of the exchange lines

A freight train consists of 2 to 72 freight cars. There are 26 types of freight cars, which are denoted by 26 lowercase letters from "a" to "z". The cars of the same type are indistinguishable from each other, and each car's direction doesn't matter either. Thus, a string of lowercase letters of length 2 to 72 is sufficient to completely express the configuration of a train.

Upon arrival at the exchange lines, a train is divided into two sub-trains at an arbitrary position (prior to entering the storage lines). Each of the sub-trains may have its direction reversed (using the reversal line). Finally, the two sub-trains are connected in either order to form the final configuration. Note that the reversal operation is optional for each of the sub-trains.

For example, if the arrival configuration is "abcd", the train is split into two sub-trains of either 3:1, 2:2 or 1:3 cars. For each of the splitting, possible final configurations are as follows ("+" indicates final concatenation position):

[3:1]
abc+d  cba+d  d+abc  d+cba
[2:2]
ab+cd  ab+dc  ba+cd  ba+dc  cd+ab  cd+ba  dc+ab  dc+ba
[1:3]
a+bcd  a+dcb  bcd+a  dcb+a

Excluding duplicates, 12 distinct configurations are possible.

Given an arrival configuration, answer the number of distinct configurations which can be constructed using the exchange lines described above.

Input

The entire input looks like the following.

> the number of datasets = m
>  1st dataset
>  2nd dataset
>  ...
>  m-th dataset
>

Each dataset represents an arriving train, and is a string of 2 to 72 lowercase letters in an input line.

Output

For each dataset, output the number of possible train configurations in a line. No other characters should appear in the output.

Example

Input

4
aa
abba
abcd
abcde

Output

1
6
12
18

### Response

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

int main()
{
  int n,i;
  string s,head,tail;
  set<string> list;
  cin>>n;
  while(n-->0){
    cin>>s;
    list.clear();
    for(i=1;i<s.size();i++){
      head=s.substr(0,i);
      tail=s.substr(i);
      list.insert(head+tail);
      list.insert(tail+head);
      reverse(head.begin(),head.end());
      list.insert(head+tail);
      list.insert(tail+head);
      reverse(tail.begin(),tail.end());
      list.insert(head+tail);
      list.insert(tail+head);
      reverse(head.begin(),head.end());
      list.insert(head+tail);
      list.insert(tail+head);
    }
    cout<<list.size()<<endl;
  }
}
```


### Prompt

Please create a solution in cpp to the following problem:

Mayor of city S just hates trees and lawns. They take so much space and there could be a road on the place they occupy!

The Mayor thinks that one of the main city streets could be considerably widened on account of lawn nobody needs anyway. Moreover, that might help reduce the car jams which happen from time to time on the street.

The street is split into n equal length parts from left to right, the i-th part is characterized by two integers: width of road si and width of lawn gi.

<image>

For each of n parts the Mayor should decide the size of lawn to demolish. For the i-th part he can reduce lawn width by integer xi (0 ≤ xi ≤ gi). After it new road width of the i-th part will be equal to s'i = si + xi and new lawn width will be equal to g'i = gi - xi.

On the one hand, the Mayor wants to demolish as much lawn as possible (and replace it with road). On the other hand, he does not want to create a rapid widening or narrowing of the road, which would lead to car accidents. To avoid that, the Mayor decided that width of the road for consecutive parts should differ by at most 1, i.e. for each i (1 ≤ i < n) the inequation |s'i + 1 - s'i| ≤ 1 should hold. Initially this condition might not be true.

You need to find the the total width of lawns the Mayor will destroy according to his plan.

Input

The first line contains integer n (1 ≤ n ≤ 2·105) — number of parts of the street.

Each of the following n lines contains two integers si, gi (1 ≤ si ≤ 106, 0 ≤ gi ≤ 106) — current width of road and width of the lawn on the i-th part of the street.

Output

In the first line print the total width of lawns which will be removed.

In the second line print n integers s'1, s'2, ..., s'n (si ≤ s'i ≤ si + gi) — new widths of the road starting from the first part and to the last.

If there is no solution, print the only integer -1 in the first line.

Examples

Input

3
4 5
4 5
4 10

Output

16
9 9 10

Input

4
1 100
100 1
1 100
100 1

Output

202
101 101 101 101

Input

3
1 1
100 100
1 1

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int s[N], g[N], f[N];
int n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i] >> g[i], f[i] = s[i] + g[i];
  for (int i = 1; i < n; i++) f[i] = min(f[i], f[i - 1] + 1);
  for (int i = n - 2; i >= 0; i--) f[i] = min(f[i + 1] + 1, f[i]);
  for (int i = 0; i < n; i++)
    if (f[i] < s[i]) return puts("-1");
  long long ans = 0;
  for (int i = 0; i < n; i++) ans += f[i] - s[i];
  cout << ans << '\n';
  for (int i = 0; i < n; i++) cout << f[i] << (i + 1 == n ? '\n' : ' ');
  return 0;
}

```


### Prompt

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

Lakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema.

<image>

However, one day, the No. 68 Cinema runs out of changes (they don't have 50-yuan notes currently), but Nephren still wants to start their business. (Assume that yuan is a kind of currency in Regulu Ere.)

There are three types of customers: some of them bring exactly a 50-yuan note; some of them bring a 100-yuan note and Nephren needs to give a 50-yuan note back to him/her; some of them bring VIP cards so that they don't need to pay for the ticket.

Now n customers are waiting outside in queue. Nephren wants to know how many possible queues are there that they are able to run smoothly (i.e. every customer can receive his/her change), and that the number of 50-yuan notes they have after selling tickets to all these customers is between l and r, inclusive. Two queues are considered different if there exists a customer whose type is different in two queues. As the number can be large, please output the answer modulo p.

Input

One line containing four integers n (1 ≤ n ≤ 105), p (1 ≤ p ≤ 2·109), l and r (0 ≤ l ≤ r ≤ n).

Output

One line indicating the answer modulo p.

Examples

Input

4 97 2 3

Output

13

Input

4 100 0 4

Output

35

Note

We use A, B and C to indicate customers with 50-yuan notes, customers with 100-yuan notes and customers with VIP cards respectively.

For the first sample, the different possible queues that there are 2 50-yuan notes left are AAAB, AABA, ABAA, AACC, ACAC, ACCA, CAAC, CACA and CCAA, and the different possible queues that there are 3 50-yuan notes left are AAAC, AACA, ACAA and CAAA. So there are 13 different queues satisfying the first sample. Similarly, there are 35 different queues satisfying the second sample.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long expo(long long base, long long exponent, long long mod) {
  long long ans = 1;
  while (exponent != 0) {
    if (exponent & 1) ans = (1LL * ans * base) % mod;
    base = (1LL * base * base) % mod;
    exponent >>= 1;
  }
  return ans % mod;
}
long long euclid(long long a, long long b, long long &first,
                 long long &second) {
  if (b) {
    long long d = euclid(b, a % b, second, first);
    return second -= a / b * first, d;
  }
  return first = 1, second = 0, a;
}
long long chinese(long long a, long long m, long long b, long long n) {
  long long first, second;
  euclid(m, n, first, second);
  long long ret = a * (second + m) % m * n + b * (first + n) % n * m;
  if (ret >= m * n) ret -= m * n;
  return ret;
}
vector<pair<long long, long long> > fac;
long long f[20][200005];
long long powers[20][200005];
long long inv[20][200005];
long long mod[20];
long long modpows[20][50];
long long C(long long n, long long r) {
  if (n < 0 or r < 0 or n < r) return 0;
  long long ans = 0, currem = 1;
  for (long long i = 0; i < (long long)fac.size(); i++) {
    long long s = powers[i][n] - powers[i][r] - powers[i][n - r];
    long long rem = f[i][n] * inv[i][r] % mod[i];
    rem = rem * inv[i][n - r] % mod[i];
    if (s >= fac[i].second)
      rem = 0;
    else
      rem = rem * modpows[i][s] % mod[i];
    ans = chinese(ans, currem, rem, mod[i]);
    currem *= mod[i];
  }
  return ans;
}
long long n, p, l, r;
void pre() {
  for (long long i = 2; i * i <= p; i++) {
    if (p % i == 0) {
      long long cnt = 0;
      while (p % i == 0) {
        cnt++;
        p /= i;
      }
      fac.push_back({i, cnt});
    }
  }
  if (p > 1) fac.push_back({p, 1});
  for (long long i = 0; i < (long long)fac.size(); i++) {
    modpows[i][0] = 1;
    for (long long j = 1; j < fac[i].second + 1; j++)
      modpows[i][j] = modpows[i][j - 1] * fac[i].first;
  }
  for (long long i = 0; i < (long long)fac.size(); i++) {
    mod[i] = modpows[i][fac[i].second];
    f[i][0] = 1;
    for (long long j = 1; j < 2 * n + 1; j++) {
      long long d = j;
      powers[i][j] = powers[i][j - 1];
      while (d % fac[i].first == 0) d /= fac[i].first, powers[i][j]++;
      f[i][j] = f[i][j - 1] * d % mod[i];
    }
    inv[i][2 * n] = expo(
        f[i][2 * n], (mod[i] / fac[i].first) * (fac[i].first - 1) - 1, mod[i]);
    for (long long j = 2 * n - 1; j >= 0; j--) {
      long long d = (j + 1);
      while (d % fac[i].first == 0) d /= fac[i].first;
      inv[i][j] = inv[i][j + 1] * d % mod[i];
    }
  }
}
void solve() {
  cin >> n >> p >> l >> r;
  long long P = p, ans = 0;
  pre();
  for (long long i = l; i < n + 1; i++)
    ans =
        (ans + C(n, i) * (C(i, (i - l) / 2) - C(i, (i - r + 1) / 2 - 1) + P)) %
        P;
  cout << ans << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Mr. A, who will graduate next spring, decided to move when he got a job. The company that finds a job has offices in several towns, and the offices that go to work differ depending on the day. So Mr. A decided to live in a town where he had a short time to go to any office.

So you decided to find the most convenient town to live in to help Mr. A.

<image>

Towns are numbered starting with 0 and there is a road between towns. Commuting time is fixed for each road. If Mr. A lives in a town, the commuting time to the office in his town is 0. At this time, consider the total commuting time to all towns. For example, if the layout of towns and roads is as shown in the figure above and Mr. A lives in town 1, the commuting time to each town will be

Town 0 to 80
0 to town 1
Up to town 2 20
Up to town 3 70
Town 4 to 90

And the sum is 260.

Enter the number of roads and information on all roads, calculate the total commuting time when living in each town, and output the number of the town that minimizes it and the total commuting time at that time. Create a program. However, if there are multiple towns with the smallest total commuting time, please output the number of the smallest town and the total commuting time at that time. The total number of towns is 10 or less, the total number of roads is 45 or less, all roads can move in both directions, and commuting time does not change depending on the direction. We also assume that there are routes from any town to all other towns.

Input

A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:

n
a1 b1 c1
a2 b2 c2
::
an bn cn

The number of roads n (1 ≤ n ≤ 45) is given on the first line. The following n lines give information on the i-th way. ai, bi (0 ≤ ai, bi ≤ 9) is the number of the town to which the i-th road connects, and ci (0 ≤ ci ≤ 100) is the commute time for that road.

Output

For each data set, the town number that minimizes the total commuting time and the total commuting time at that time are output on one line separated by blanks.

Example

Input

6
0 1 80
1 2 20
0 2 60
2 3 50
3 4 60
1 4 90
2
0 1 1
1 2 1
0

Output

2 240
1 2

### Response

```cpp
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 1 << 25;
int wf[10][10];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	while(cin >> n, n) {
		for(int i = 0; i < 10; i++) {
			for(int j = 0; j < 10; j++) {
				wf[i][j] = (i == j) ? 0 : INF;
			}
		}

		bool use[10] = { false };
		for(int i = 0; i < n; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			wf[a][b] = wf[b][a] = c;
			use[a] = use[b] = true;
		}

		for(int k = 0; k < 10; k++) {
			for(int i = 0; i < 10; i++) {
				for(int j = 0; j < 10; j++) {
					wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);
				}
			}
		}

		int mi = -1, m = INF;
		for(int i = 0; i < 10; i++) {
			if(!use[i]) continue;
			int sum = 0;
			for(int j = 0; j < 10; j++) {
				if(use[j]) sum += wf[i][j];
			}
			if(sum < m) {
				mi = i;
				m = sum;
			}
		}

		cout << mi << " " << m << endl;
	}
}
```


### Prompt

Please create a solution in CPP to the following problem:

There are b blocks of digits. Each one consisting of the same n digits, which are given to you in the input. Wet Shark must choose exactly one digit from each block and concatenate all of those digits together to form one large integer. For example, if he chooses digit 1 from the first block and digit 2 from the second block, he gets the integer 12.

Wet Shark then takes this number modulo x. Please, tell him how many ways he can choose one digit from each block so that he gets exactly k as the final result. As this number may be too large, print it modulo 109 + 7.

Note, that the number of ways to choose some digit in the block is equal to the number of it's occurrences. For example, there are 3 ways to choose digit 5 from block 3 5 6 7 8 9 5 1 1 1 1 5.

Input

The first line of the input contains four space-separated integers, n, b, k and x (2 ≤ n ≤ 50 000, 1 ≤ b ≤ 109, 0 ≤ k < x ≤ 100, x ≥ 2) — the number of digits in one block, the number of blocks, interesting remainder modulo x and modulo x itself.

The next line contains n space separated integers ai (1 ≤ ai ≤ 9), that give the digits contained in each block.

Output

Print the number of ways to pick exactly one digit from each blocks, such that the resulting integer equals k modulo x.

Examples

Input

12 1 5 10
3 5 6 7 8 9 5 1 1 1 1 5

Output

3

Input

3 2 1 2
6 2 2

Output

0

Input

3 2 1 2
3 1 2

Output

6

Note

In the second sample possible integers are 22, 26, 62 and 66. None of them gives the remainder 1 modulo 2.

In the third sample integers 11, 13, 21, 23, 31 and 33 have remainder 1 modulo 2. There is exactly one way to obtain each of these integers, so the total answer is 6.

### Response

```cpp
#include <bits/stdc++.h>
const int N = 201000;
using namespace std;
int n, b, k, x;
vector<vector<long long> > v;
int cnt[N];
vector<vector<long long> > mult(vector<vector<long long> > a,
                                vector<vector<long long> > b) {
  vector<vector<long long> > res;
  res = a;
  for (int i = 0; i < res.size(); i++) {
    for (int j = 0; j < res.size(); j++) {
      res[i][j] = 0;
    }
  }
  for (int i = 0; i < a.size(); i++) {
    for (int k = 0; k < res.size(); k++) {
      for (int j = 0; j < res.size(); j++) {
        res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % 1000000007;
      }
    }
  }
  return res;
}
vector<vector<long long> > pw(vector<vector<long long> > a, long long b) {
  if (b == 1) return a;
  if (b % 2) return mult(a, pw(a, b - 1));
  return pw(mult(a, a), b / 2);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> b >> k >> x;
  for (int i = 1; i <= n; i++) {
    int val;
    cin >> val;
    cnt[val]++;
  }
  v.resize(x);
  for (int i = 0; i < v.size(); i++) {
    v[i].resize(x);
    for (int j = 0; j < v[i].size(); j++) {
      v[i][j] = 0;
    }
  }
  for (int i = 0; i < v.size(); i++) {
    for (int ad = 0; ad < 10; ad++) {
      v[i][(i * 10 + ad) % x] += cnt[ad];
    }
  }
  v = pw(v, b);
  cout << v[0][k] << endl;
  cin.get();
  cin.get();
  return 0;
}

```


### Prompt

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

Oleg's favorite subjects are History and Math, and his favorite branch of mathematics is division.

To improve his division skills, Oleg came up with t pairs of integers p_i and q_i and for each pair decided to find the greatest integer x_i, such that:

  * p_i is divisible by x_i;
  * x_i is not divisible by q_i.

Oleg is really good at division and managed to find all the answers quickly, how about you?

Input

The first line contains an integer t (1 ≤ t ≤ 50) — the number of pairs.

Each of the following t lines contains two integers p_i and q_i (1 ≤ p_i ≤ 10^{18}; 2 ≤ q_i ≤ 10^{9}) — the i-th pair of integers.

Output

Print t integers: the i-th integer is the largest x_i such that p_i is divisible by x_i, but x_i is not divisible by q_i.

One can show that there is always at least one value of x_i satisfying the divisibility conditions for the given constraints.

Example

Input

3
10 4
12 6
179 822

Output

10
4
179

Note

For the first pair, where p_1 = 10 and q_1 = 4, the answer is x_1 = 10, since it is the greatest divisor of 10 and 10 is not divisible by 4.

For the second pair, where p_2 = 12 and q_2 = 6, note that

  * 12 is not a valid x_2, since 12 is divisible by q_2 = 6;
  * 6 is not valid x_2 as well: 6 is also divisible by q_2 = 6.

The next available divisor of p_2 = 12 is 4, which is the answer, since 4 is not divisible by 6.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MX = 1e9;
bool is_prime(ll x) {
  if (x < 2) return false;
  if (x == 2) return true;
  for (ll i = 2; i * i <= x; ++i) {
    if (x % i == 0) return false;
  }
  return true;
}
vector<ll> f(ll x) {
  vector<ll> res;
  for (ll i = 1; i * i <= x; ++i) {
    if (x % i == 0) {
      res.push_back(i);
      ll j = x / i;
      if (x % j == 0 && j != i) {
        res.push_back(j);
      }
    }
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    ll p, q;
    cin >> p >> q;
    if (p < q || p % q != 0) {
      cout << p << '\n';
      continue;
    }
    if (p <= MX) {
      auto d = f(p);
      ll res = 1;
      for (ll x : d) {
        if (x % q != 0) res = max(res, x);
      }
      cout << res << '\n';
    } else {
      ll res = p;
      while (res % q == 0) res /= q;
      for (ll i = 1; i <= 1e5; ++i) {
        if (p % i == 0) {
          if (i % q != 0) {
            res = max(i, res);
          }
          ll x = p;
          while (i > 1 && x > 0) {
            if (p % x == 0 && x % q != 0) {
              res = max(x, res);
            }
            x /= i;
          }
        }
      }
      cout << res << '\n';
    }
  }
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 × 8 table. A field is represented by a pair of integers (r, c) — the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules:

  * A rook moves any number of fields horizontally or vertically.
  * A bishop moves any number of fields diagonally.
  * A king moves one field in any direction — horizontally, vertically or diagonally.

<image> The pieces move like that

Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem.

Input

The input contains four integers r1, c1, r2, c2 (1 ≤ r1, c1, r2, c2 ≤ 8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one.

You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8.

Output

Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number.

Examples

Input

4 3 1 6

Output

2 1 3

Input

5 5 5 6

Output

1 0 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  int x, y, vx, vy;
  cin >> x >> y >> vx >> vy;
  if ((x != vx) && (y != vy))
    cout << 2 << ' ';
  else
    cout << 1 << ' ';
  if ((vx + vy) % 2 == (x + y) % 2) {
    if (abs(x - vx) == abs(y - vy))
      cout << 1 << ' ';
    else
      cout << 2 << ' ';
  } else
    cout << 0 << ' ';
  if (abs(y - vy) < abs(x - vx))
    cout << abs(x - vx) << ' ';
  else
    cout << abs(y - vy) << ' ';
}

```