### Prompt

Create a solution in cpp for the following problem:

Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1.

There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points.

Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one.

Input

The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively.

The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i.

It is guaranteed that no segments coincide.

Output

Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks).

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

Examples

Input

12 6
1 3
3 7
5 7
7 11
9 11
11 3

Output

Yes

Input

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

Output

Yes

Input

10 3
1 2
3 2
7 2

Output

No

Input

10 2
1 6
2 7

Output

Yes

Note

The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long n, long long m) { return m == 0 ? n : gcd(m, n % m); }
long long lcm(long long n, long long m) { return (m * n) / gcd(n, m); }
void print(std::vector<long long>& ar) {
  for (auto& a : (ar)) {
    cout << (a) << ' ';
  };
}
long long dx[] = {1, 0};
long long dy[] = {0, 1};
const long long INF = 1e18;
long long const N = 2e5 + 10;
long long const M = 210;
double const PI = acos(-1);
long long const MOD = 998244353;
vector<long long> factor[N + 10];
long long sum = 0;
void sieve() {
  for (long long i = 1; i <= N; i++) {
    for (long long j = i; j <= N; j += i) {
      factor[j].push_back(i);
      sum++;
    }
  }
}
long long n, m;
vector<long long> store[N];
void calc(vector<long long>& temp) {
  sort((temp.begin()), (temp.end()));
  temp.push_back(temp.front() + n);
  for (long long i = 1; i < temp.size(); i++) {
    temp[i - 1] = temp[i] - temp[i - 1];
  }
  temp.pop_back();
}
bool period(vector<long long>& temp, long long p) {
  for (long long i = 0; i < temp.size(); i += p) {
    for (long long j = i; j < i + p; j++) {
      if (temp[j] != temp[j % p]) return false;
    }
  }
  return true;
}
long long find_period(vector<long long>& temp) {
  vector<long long> fact = factor[(long long)temp.size()];
  for (long long c : fact) {
    if (period(temp, c)) {
      long long sum = 0;
      for (long long i = 0; i < c; i++) sum += temp[i];
      return sum;
    }
  }
  return n;
}
set<pair<long long, long long> > S;
vector<pair<long long, long long> > num;
int32_t main() {
  sieve();
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    num.push_back({a, b});
    S.insert({a, b});
  }
  factor[n].pop_back();
  for (auto c : factor[n]) {
    bool flag = true;
    for (long long i = 0; i < num.size(); i++) {
      long long a = num[i].first + c;
      a = a > n ? a - n : a;
      long long b = num[i].second + c;
      b = b > n ? b - n : b;
      if (S.find({a, b}) == S.end() && S.find({b, a}) == S.end()) {
        flag = false;
        break;
      }
    }
    if (flag) {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
}

```


### Prompt

Generate a CPP solution to the following problem:

Smart Beaver recently got interested in a new word game. The point is as follows: count the number of distinct good substrings of some string s. To determine if a string is good or not the game uses rules. Overall there are n rules. Each rule is described by a group of three (p, l, r), where p is a string and l and r (l ≤ r) are integers. We’ll say that string t complies with rule (p, l, r), if the number of occurrences of string t in string p lies between l and r, inclusive. For example, string "ab", complies with rules ("ab", 1, 2) and ("aab", 0, 1), but does not comply with rules ("cd", 1, 2) and ("abab", 0, 1).

A substring s[l... r] (1 ≤ l ≤ r ≤ |s|) of string s = s1s2... s|s| (|s| is a length of s) is string slsl + 1... sr.

Consider a number of occurrences  of string t in string p as a number of pairs of integers l, r (1 ≤ l ≤ r ≤ |p|) such that p[l... r] = t.

We’ll say that string t is good if it complies with all n rules. Smart Beaver asks you to help him to write a program that can calculate the number of distinct good substrings of string s. Two substrings s[x... y] and s[z... w] are cosidered to be distinct iff s[x... y] ≠ s[z... w].

Input

The first line contains string s. The second line contains integer n. Next n lines contain the rules, one per line. Each of these lines contains a string and two integers pi, li, ri, separated by single spaces (0 ≤ li ≤ ri ≤ |pi|). It is guaranteed that all the given strings are non-empty and only contain lowercase English letters.

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

  * 0 ≤ n ≤ 10.
  * The length of string s and the maximum length of string p is  ≤ 200.

The input limits for scoring 70 points are (subproblems G1+G2):

  * 0 ≤ n ≤ 10.
  * The length of string s and the maximum length of string p is  ≤ 2000.

The input limits for scoring 100 points are (subproblems G1+G2+G3):

  * 0 ≤ n ≤ 10.
  * The length of string s and the maximum length of string p is  ≤ 50000.

Output

Print a single integer — the number of good substrings of string s.

Examples

Input

aaab
2
aa 0 0
aab 1 1

Output

3

Input

ltntlnen
3
n 0 0
ttlneenl 1 4
lelllt 1 1

Output

2

Input

a
0

Output

1

Note

There are three good substrings in the first sample test: «aab», «ab» and «b».

In the second test only substrings «e» and «t» are good.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
namespace sam {
const int N = 1200010, M = 26;
int tr[N][M], pr[N], ln[N], nw = 1;
int add(int c, int lst) {
  if (tr[lst][c] && ln[tr[lst][c]] == ln[lst] + 1) return tr[lst][c];
  int p = lst, np = ++nw;
  ln[np] = ln[p] + 1;
  for (; p && !tr[p][c]; p = pr[p]) tr[p][c] = np;
  if (!p)
    pr[np] = 1;
  else {
    int q = tr[p][c];
    if (ln[p] + 1 == ln[q])
      pr[np] = q;
    else {
      int nq = ++nw;
      ln[nq] = ln[p] + 1;
      pr[nq] = pr[q];
      copy(tr[q], tr[q] + M, tr[nq]);
      pr[q] = pr[np] = nq;
      for (; p && tr[p][c] == q; p = pr[p]) tr[p][c] = nq;
    }
  }
  return np;
}
}  // namespace sam
int cnt[1200010][11];
using namespace sam;
int lft[11], rght[11], n;
char tmp[50010];
bool cmp(int x, int y) { return ln[x] > ln[y]; }
int main() {
  scanf("%s", tmp + 1);
  for (int u = 1, i = 1; tmp[i]; ++i) {
    u = add(tmp[i] - 'a', u);
    ++cnt[u][0];
  }
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s%d%d", tmp + 1, &lft[i], &rght[i]);
    for (int u = 1, j = 1; tmp[j]; ++j) {
      u = add(tmp[j] - 'a', u);
      ++cnt[u][i];
    }
  }
  static int tmp[600010 * 2];
  for (int i = 1; i <= nw; ++i) tmp[i] = i;
  sort(tmp + 1, tmp + nw + 1, cmp);
  for (int i = 1; i <= nw; ++i) {
    int u = tmp[i];
    for (int j = 0; j <= n; ++j) cnt[pr[u]][j] += cnt[u][j];
  }
  long long ans = 0;
  for (int i = 1; i <= nw; ++i) {
    int flg = 1;
    for (int j = 1; j <= n; ++j)
      if (cnt[i][j] >= lft[j] && cnt[i][j] <= rght[j]) {
      } else
        flg = 0;
    if (flg && cnt[i][0]) ans += ln[i] - ln[pr[i]];
  }
  printf("%I64d\n", ans);
  return 0;
}

```


### Prompt

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

There are N squares in a row, numbered 1 through N from left to right. Snuke and Rng are playing a board game using these squares, described below:

1. First, Snuke writes an integer into each square.
2. Each of the two players possesses one piece. Snuke places his piece onto square 1, and Rng places his onto square 2.
3. The player whose piece is to the left of the opponent's, moves his piece. The destination must be a square to the right of the square where the piece is currently placed, and must not be a square where the opponent's piece is placed.
4. Repeat step 3. When the pieces cannot be moved any more, the game ends.
5. The score of each player is calculated as the sum of the integers written in the squares where the player has placed his piece before the end of the game.

Snuke has already written an integer A_i into square i (1≦i≦N-1), but not into square N yet. He has decided to calculate for each of M integers X_1,X_2,...,X_M, if he writes it into square N and the game is played, what the value "(Snuke's score) - (Rng's score)" will be. Here, it is assumed that each player moves his piece to maximize the value "(the player's score) - (the opponent's score)".

Constraints

* 3≦N≦200,000
* 0≦A_i≦10^6
* The sum of all A_i is at most 10^6.
* 1≦M≦200,000
* 0≦X_i≦10^9

Input

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

N
A_1 A_2 ... A_{N-1}
M
X_1
X_2
:
X_M

Output

For each of the M integers X_1, ..., X_M, print the value "(Snuke's score) - (Rng's score)" if it is written into square N, one per line.

Examples

Input

5
2 7 1 8
1
2

Output

0

Input

9
2 0 1 6 1 1 2 6
5
2016
1
1
2
6

Output

2001
6
6
7
7

### Response

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct UnionFindTree{
    vector<int>par,sz;
    UnionFindTree(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool areSame(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

int N;
int A[222222];
int X[222222];
int dp[222222];
int ans[1000001];
signed main(){
    cin>>N;
    rep(i,N-1)cin>>A[i];

    int M;cin>>M;
    rep(i,M)cin>>X[i];

    UnionFindTree uf(1000001);
    deque<int>dp(1000001);
    rep(i,1000001)dp[i]=i;
    for(int i=N-2;i>=2;i--){
        vint v;
        rep(j,A[i]){
            v.pb(dp.front());
            dp.pop_front();
            dp.push_back(-1);
        }
        rep(j,A[i]){
            if(v[j]!=-1&&dp[A[i]-j]!=-1)uf.unite(v[j],dp[A[i]-j]);
            if(v[j]!=-1)dp[A[i]-j]=v[j];
        }
    }
    rep(i,1000001)if(dp[i]!=-1)ans[uf.find(dp[i])]=i;
    rep(i,1000001)ans[i]=ans[uf.find(i)];

    int sum=0;
    for(int i=2;i<N-1;i++)sum+=A[i];

    rep(i,M){
        int tmp;
        if(X[i]>1000000)tmp=X[i]-sum;
        else tmp=ans[X[i]];
        cout<<tmp+A[0]-A[1]<<endl;
    }
    return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that.

Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them.

The English alphabet vowels are: A, E, I, O, U, Y

The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z

Input

The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter.

Output

Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".

Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters.

Examples

Input

Is it a melon?

Output

NO

Input

Is it an apple?

Output

YES

Input

  Is     it a banana ?

Output

YES

Input

Is   it an apple  and a  banana   simultaneouSLY?

Output

YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool isVowel(char c) {
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') {
    return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  getline(cin, s);
  for (int i = s.length() - 2; i >= 0; i--) {
    if (s[i] != ' ' && s[i] != '?') {
      s[i] = tolower(s[i]);
      if (isVowel(s[i])) {
        cout << "YES\n";
      } else {
        cout << "NO\n";
      }
      break;
    }
  }
  return 0;
}

```


### Prompt

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

You are given a sequence of n integers a1, a2, ..., an.

Determine a real number x such that the weakness of the sequence a1 - x, a2 - x, ..., an - x is as small as possible.

The weakness of a sequence is defined as the maximum value of the poorness over all segments (contiguous subsequences) of a sequence.

The poorness of a segment is defined as the absolute value of sum of the elements of segment.

Input

The first line contains one integer n (1 ≤ n ≤ 200 000), the length of a sequence.

The second line contains n integers a1, a2, ..., an (|ai| ≤ 10 000).

Output

Output a real number denoting the minimum possible weakness of a1 - x, a2 - x, ..., an - x. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.

Examples

Input

3
1 2 3

Output

1.000000000000000

Input

4
1 2 3 4

Output

2.000000000000000

Input

10
1 10 2 9 3 8 4 7 5 6

Output

4.500000000000000

Note

For the first case, the optimal value of x is 2 so the sequence becomes  - 1, 0, 1 and the max poorness occurs at the segment "-1" or segment "1". The poorness value (answer) equals to 1 in this case.

For the second sample the optimal value of x is 2.5 so the sequence becomes  - 1.5, - 0.5, 0.5, 1.5 and the max poorness occurs on segment "-1.5 -0.5" or "0.5 1.5". The poorness value (answer) equals to 2 in this case.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n;
long double a[1005000], b[1005000], c[1005000];
long double cal(long double k) {
  for (int i = 1; i <= n; i++) b[i] = a[i] - k, c[i] = -b[i];
  long double ans, sumb, sumc;
  ans = 0, sumb = 0, sumc = 0;
  for (int i = 1; i <= n; i++) {
    sumb += b[i];
    sumc += c[i];
    if (sumb < 0) sumb = 0;
    if (sumc < 0) sumc = 0;
    if (ans < sumb) ans = sumb;
    if (ans < sumc) ans = sumc;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  long double l = -1e5, r = 1e5;
  while (r - l > 1e-15) {
    long double m1 = l + (r - l) / 3;
    long double m2 = r - (r - l) / 3;
    long double f1 = cal(m1);
    long double f2 = cal(m2);
    if (f1 >= f2)
      l = m1;
    else
      r = m2;
  }
  cout << fixed << setprecision(20) << cal(l);
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials.

He considers a polynomial valid if its degree is n and its coefficients are integers not exceeding k by the absolute value. More formally:

Let a0, a1, ..., an denote the coefficients, so <image>. Then, a polynomial P(x) is valid if all the following conditions are satisfied:

  * ai is integer for every i;
  * |ai| ≤ k for every i;
  * an ≠ 0.

Limak has recently got a valid polynomial P with coefficients a0, a1, a2, ..., an. He noticed that P(2) ≠ 0 and he wants to change it. He is going to change one coefficient to get a valid polynomial Q of degree n that Q(2) = 0. Count the number of ways to do so. You should count two ways as a distinct if coefficients of target polynoms differ.

Input

The first line contains two integers n and k (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 109) — the degree of the polynomial and the limit for absolute values of coefficients.

The second line contains n + 1 integers a0, a1, ..., an (|ai| ≤ k, an ≠ 0) — describing a valid polynomial <image>. It's guaranteed that P(2) ≠ 0.

Output

Print the number of ways to change one coefficient to get a valid polynomial Q that Q(2) = 0.

Examples

Input

3 1000000000
10 -9 -3 5

Output

3

Input

3 12
10 -9 -3 5

Output

2

Input

2 20
14 -7 19

Output

0

Note

In the first sample, we are given a polynomial P(x) = 10 - 9x - 3x2 + 5x3.

Limak can change one coefficient in three ways:

  1. He can set a0 = - 10. Then he would get Q(x) = - 10 - 9x - 3x2 + 5x3 and indeed Q(2) = - 10 - 18 - 12 + 40 = 0.
  2. Or he can set a2 = - 8. Then Q(x) = 10 - 9x - 8x2 + 5x3 and indeed Q(2) = 10 - 18 - 32 + 40 = 0.
  3. Or he can set a1 = - 19. Then Q(x) = 10 - 19x - 3x2 + 5x3 and indeed Q(2) = 10 - 38 - 12 + 40 = 0.

In the second sample, we are given the same polynomial. This time though, k is equal to 12 instead of 109. Two first of ways listed above are still valid but in the third way we would get |a1| > k what is not allowed. Thus, the answer is 2 this time.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long b[200005], a[200005];
string s, p;
int main() {
  ios_base::sync_with_stdio(false);
  long long i, j, k, l, m, x, y, r, n, t;
  cin >> n >> k;
  for (i = 0; i <= n; i++) {
    cin >> a[i];
  }
  b[n] = a[n];
  for (i = 0; i < n; i++) {
    long long temp = (a[i] + b[i]);
    b[i + 1] += (temp / 2ll);
    b[i] = temp % 2ll;
  }
  long long flag = 0;
  for (i = 0; i <= n; i++) {
    if (b[i]) {
      flag = i;
      break;
    }
  }
  long long res = 0;
  long long cnt = 0;
  for (i = n; i >= 0; i--) {
    res = res * 2ll + b[i];
    if (res > 1000000000000000000ll || res < -1000000000000000000ll) break;
    if (i <= flag) {
      long long ans = a[i] - res;
      if (ans >= -k && ans <= k) {
        if (ans != 0 || i != n) cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

You are given a tree with n vertices. You are allowed to modify the structure of the tree through the following multi-step operation:

  1. Choose three vertices a, b, and c such that b is adjacent to both a and c.
  2. For every vertex d other than b that is adjacent to a, remove the edge connecting d and a and add the edge connecting d and c.
  3. Delete the edge connecting a and b and add the edge connecting a and c.

As an example, consider the following tree:

<image>

The following diagram illustrates the sequence of steps that happen when we apply an operation to vertices 2, 4, and 5:

<image>

It can be proven that after each operation, the resulting graph is still a tree.

Find the minimum number of operations that must be performed to transform the tree into a star. A star is a tree with one vertex of degree n - 1, called its center, and n - 1 vertices of degree 1.

Input

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

The i-th of the following n - 1 lines contains two integers u_i and v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i) denoting that there exists an edge connecting vertices u_i and v_i. It is guaranteed that the given edges form a tree.

Output

Print a single integer — the minimum number of operations needed to transform the tree into a star.

It can be proven that under the given constraints, it is always possible to transform the tree into a star using at most 10^{18} operations.

Examples

Input

6
4 5
2 6
3 2
1 2
2 4

Output

1

Input

4
2 4
4 1
3 4

Output

0

Note

The first test case corresponds to the tree shown in the statement. As we have seen before, we can transform the tree into a star with center at vertex 5 by applying a single operation to vertices 2, 4, and 5.

In the second test case, the given tree is already a star with the center at vertex 4, so no operations have to be performed.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > a;
vector<int> depths;
vector<int> mark;
int ans = 1e9;
void dfs(int s, int p) {
  mark[s] = 1;
  int sum = 0;
  for (int i = 0; i < a[s].size(); i++) {
    if (mark[a[s][i]] == 0) {
      dfs(a[s][i], s);
    }
  }
  for (int i = 0; i < a[s].size(); i++) {
    int v = a[s][i];
    if (v != p) {
      for (int j = 0; j < a[v].size(); j++) {
        if (a[v][j] != s) {
          sum += (1 + depths[a[v][j]]);
        }
      }
    }
  }
  depths[s] = sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int i, j, n, k;
  cin >> n;
  a.assign(n + 1, vector<int>());
  for (i = 0; i < n - 1; i++) {
    cin >> j >> k;
    a[j].push_back(k);
    a[k].push_back(j);
  }
  depths.assign(n + 1, 0);
  mark.assign(n + 1, 0);
  dfs(1, -1);
  ans = min(ans, depths[1]);
  int childSum = 0;
  for (int i = 0; i < a[1].size(); i++) childSum += (1 + depths[a[1][i]]);
  childSum--;
  ans = min(ans, childSum);
  cout << ans << endl;
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Little Petya loves counting. He wants to count the number of ways to paint a rectangular checkered board of size n × m (n rows, m columns) in k colors. Besides, the coloring should have the following property: for any vertical line that passes along the grid lines and divides the board in two non-empty parts the number of distinct colors in both these parts should be the same. Help Petya to count these colorings.

Input

The first line contains space-separated integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 106) — the board's vertical and horizontal sizes and the number of colors respectively.

Output

Print the answer to the problem. As the answer can be quite a large number, you should print it modulo 109 + 7 (1000000007).

Examples

Input

2 2 1

Output

1

Input

2 2 2

Output

8

Input

3 2 2

Output

40

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long inf = 0xc0c0c0c0c0c0c0c0;
const double pi = acos(-1);
const long long MAX = 1e3 + 7;
const long long mod = 1e9 + 7;
long long dp[MAX][MAX];
long long fact[MAX * MAX];
int N, M, K;
void add(long long &a, long long b) { a = (a + b) % mod; }
long long qpow(long long b, int p) {
  long long res = 1;
  while (p) {
    if (p & 1) res = res * b % mod;
    b = b * b % mod;
    p >>= 1;
  }
  return res;
}
long long C(long long b, long long s) {
  return fact[b] * qpow(fact[b - s] * fact[s] % mod, mod - 2) % mod;
}
void init() {
  fact[0] = 1;
  for (long long i = 1; i < MAX * MAX; i++) fact[i] = fact[i - 1] * i % mod;
}
int main() {
  init();
  scanf("%d%d%d", &M, &N, &K);
  if (N == 1) {
    printf("%lld\n", qpow(K, M));
    return 0;
  }
  dp[1][1] = 1;
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= i; j++) {
      add(dp[i + 1][j], dp[i][j] * j % mod);
      add(dp[i + 1][j + 1], dp[i][j]);
    }
  }
  int tool = (N - 2) * M;
  long long ans = 0;
  for (int j = 0; j <= K; j++) {
    long long temp = C(K, j) * qpow(j, tool) % mod;
    temp = temp * fact[K - j] % mod;
    long long t = 0;
    for (int i = 0; (i << 1) <= (K - j); i++) {
      if (i + j > M || i * 2 + j > K) break;
      long long q =
          dp[M][i + j] * fact[i + j] % mod * qpow(fact[i], mod - 2) % mod;
      add(t, q * q % mod * qpow(fact[K - 2 * i - j], mod - 2));
    }
    add(ans, temp * t % mod);
  }
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

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

Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.

In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).

Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.

The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.

The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.

The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.

The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.

It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.

Output

Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.

If there are several possible answers print any of them.

Examples

Input

3
2 3 2
2
3 2
2 3

Output

2

Input

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

Output

1

Note

In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.

In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long INF = 1e9 + 5;
const long long mod = 1e9 + 7;
const double pi = 3.1415926536;
map<int, int> cnt;
pair<int, int> maxi;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  int n, m;
  cin >> n;
  int sc, audio[m + 5], subtitles;
  for (int i = 0; i < n; i++) {
    cin >> sc;
    cnt[sc]++;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> audio[i];
  }
  int idx = 1;
  for (int i = 0; i < m; i++) {
    cin >> subtitles;
    pair<int, int> ans = make_pair(cnt[audio[i]], cnt[subtitles]);
    if (ans > maxi) {
      idx = i + 1;
      maxi = ans;
    }
  }
  cout << idx << endl;
  return 0;
}

```


### Prompt

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

<image>

As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.

A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-dimensional objects through three-dimensional objects by using his magnificent sculptures. And his new project is connected with this. Cicasso wants to make a coat for the haters of anticubism. To do this, he wants to create a sculpture depicting a well-known geometric primitive — convex polygon.

Cicasso prepared for this a few blanks, which are rods with integer lengths, and now he wants to bring them together. The i-th rod is a segment of length li.

The sculptor plans to make a convex polygon with a nonzero area, using all rods he has as its sides. Each rod should be used as a side to its full length. It is forbidden to cut, break or bend rods. However, two sides may form a straight angle <image>.

Cicasso knows that it is impossible to make a convex polygon with a nonzero area out of the rods with the lengths which he had chosen. Cicasso does not want to leave the unused rods, so the sculptor decides to make another rod-blank with an integer length so that his problem is solvable. Of course, he wants to make it as short as possible, because the materials are expensive, and it is improper deed to spend money for nothing.

Help sculptor!

Input

The first line contains an integer n (3 ≤ n ≤ 105) — a number of rod-blanks.

The second line contains n integers li (1 ≤ li ≤ 109) — lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with n vertices and nonzero area using the rods Cicasso already has.

Output

Print the only integer z — the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (n + 1) vertices and nonzero area from all of the rods.

Examples

Input

3
1 2 1

Output

1

Input

5
20 4 3 2 1

Output

11

Note

In the first example triangle with sides {1 + 1 = 2, 2, 1} can be formed from a set of lengths {1, 1, 1, 2}.

In the second example you can make a triangle with lengths {20, 11, 4 + 3 + 2 + 1 = 10}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 200010;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
bool cmp(long long x, long long y) { return x > y; }
int main() {
  long long a, b, c[MAXN], ans;
  int n;
  while (cin >> n) {
    a = 0;
    b = 0;
    for (int i = 0; i < n; i++) {
      cin >> c[i];
    }
    sort(c, c + n, cmp);
    for (int i = 0; i < n; i++) {
      if (a <= b)
        a += c[i];
      else
        b += c[i];
    }
    ans = abs(a - b) + 1;
    cout << ans << endl;
  }
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.

The game is played on a tree having n nodes, numbered from 1 to n. Each node i has an initial value initi, which is either 0 or 1. The root of the tree is node 1.

One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node x. Right after someone has picked node x, the value of node x flips, the values of sons of x remain the same, the values of sons of sons of x flips, the values of sons of sons of sons of x remain the same and so on.

The goal of the game is to get each node i to have value goali, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.

Input

The first line contains an integer n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n; ui ≠ vi) meaning there is an edge between nodes ui and vi.

The next line contains n integer numbers, the i-th of them corresponds to initi (initi is either 0 or 1). The following line also contains n integer numbers, the i-th number corresponds to goali (goali is either 0 or 1).

Output

In the first line output an integer number cnt, representing the minimal number of operations you perform. Each of the next cnt lines should contain an integer xi, representing that you pick a node xi.

Examples

Input

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

Output

2
4
7

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int ar[100005], fr[100005];
vector<vector<int>> adj(100005);
int OO = INT32_MAX;
int odd = 0, even = 0;
vector<int> res;
int cnt = 0;
int vis[100005];
void dfs(int s, int lvl, int odd, int even) {
  int od = 0, ev = 0;
  if (lvl % 2 == 0) {
    if (even) {
      ar[s - 1]++;
      ar[s - 1] %= 2;
    }
  } else {
    if (odd) {
      ar[s - 1]++;
      ar[s - 1] %= 2;
    }
  }
  if (ar[s - 1] != fr[s - 1]) {
    res.push_back(s);
    cnt++;
    if (lvl % 2 == 0) {
      ev++;
    } else {
      od++;
    }
  }
  vis[s] = 1;
  for (int i = 0; i < adj[s].size(); i++) {
    int child = adj[s][i];
    if (!vis[child]) dfs(child, lvl + 1, (odd + od) % 2, (even + ev) % 2);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    cin >> v >> u;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> fr[i];
  }
  dfs(1, 1, 0, 0);
  cout << cnt << endl;
  for (int i = 0; i < cnt; i++) {
    cout << res[i] << endl;
  }
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Two countries, Country A and Country B, are at war. As a soldier in Country A, you will lead n soldiers to occupy the territory of Country B.

The territory of Country B is represented by a two-dimensional grid. The first place you occupy is a square on the 2D grid. Each of the soldiers you lead has h_i health. Each soldier can spend 1 health to move. Assuming that the current cell is (a, b), the movement destination is the four directions (a + 1, b), (a-1, b), (a, b + 1), (a, b-1). It is possible to choose. Soldiers will not be able to move from there when their health reaches zero. Any square passed by one or more soldiers can be occupied.

Your job is to find out how many squares you can occupy at most.
However, the size of this two-dimensional grid should be infinitely wide.

Input

The input is given in the following format.

n
h1
..
..
..
hn

Input meets the following constraints
1 ≤ n ≤ 500
1 ≤ hi ≤ 10,000,000

Output

Output the answer value on one line

Examples

Input

2
5
5

Output

11

Input

10
10
10
10
10
10
10
10
10
10
10

Output

93

Input

5
1
2
3
4
5

Output

15

### Response

```cpp
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

static const double EPS = 1e-8;

static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){
  int n;
  while(~scanf("%d",&n)){
    vector<ll> h;
    for(int i=0;i<n;i++){
      ll hit_point;
      scanf("%ld",&hit_point);
      h.push_back(hit_point);
    }
    sort(h.begin(),h.end(),greater<ll>());
    ll res = 1;

    for(int i=0;i<h.size();i++){
      res += (h[i] - i/4 >= 0 ? h[i] - i/4 : 0);
    }

    printf("%ld\n",res);
  }
}
```


### Prompt

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

Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm  ×  h mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how.

In order not to waste time, he decided to practice the technique of carving. To do this, he makes vertical and horizontal cuts through the entire sheet. This process results in making smaller rectangular fragments of glass. Leonid does not move the newly made glass fragments. In particular, a cut divides each fragment of glass that it goes through into smaller fragments.

After each cut Leonid tries to determine what area the largest of the currently available glass fragments has. Since there appear more and more fragments, this question takes him more and more time and distracts him from the fascinating process.

Leonid offers to divide the labor — he will cut glass, and you will calculate the area of the maximum fragment after each cut. Do you agree?

Input

The first line contains three integers w, h, n (2 ≤ w, h ≤ 200 000, 1 ≤ n ≤ 200 000).

Next n lines contain the descriptions of the cuts. Each description has the form H y or V x. In the first case Leonid makes the horizontal cut at the distance y millimeters (1 ≤ y ≤ h - 1) from the lower edge of the original sheet of glass. In the second case Leonid makes a vertical cut at distance x (1 ≤ x ≤ w - 1) millimeters from the left edge of the original sheet of glass. It is guaranteed that Leonid won't make two identical cuts.

Output

After each cut print on a single line the area of the maximum available glass fragment in mm2.

Examples

Input

4 3 4
H 2
V 2
V 3
V 1

Output

8
4
4
2

Input

7 6 5
H 4
V 3
V 5
H 2
V 1

Output

28
16
12
6
4

Note

Picture for the first sample test:

<image> Picture for the second sample test:  <image>

### Response

```cpp
#include <bits/stdc++.h>
inline int scan() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void Out(int a) {
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  if (a >= 10) Out(a / 10);
  putchar(a % 10 + '0');
}
using namespace std;
int wmm[200005];
int hmm[200005];
int main() {
  int w, h, n;
  cin >> w >> h >> n;
  set<int> w1;
  set<int> h1;
  set<int> wm;
  wm.insert(w);
  wmm[w]++;
  set<int> hm;
  hm.insert(h);
  hmm[h]++;
  w1.insert(w);
  w1.insert(0);
  h1.insert(h);
  h1.insert(0);
  while (n--) {
    char ch;
    int a;
    cin >> ch >> a;
    if (ch == 'V') {
      set<int>::iterator it;
      it = w1.lower_bound(a);
      if (*it == a) continue;
      int maxs = *it;
      *it--;
      int mins = *it;
      wmm[maxs - mins]--;
      if (wmm[maxs - mins] == 0) wm.erase(maxs - mins);
      wmm[maxs - a]++;
      wm.insert(maxs - a);
      wmm[a - mins]++;
      wm.insert(a - mins);
      w1.insert(a);
    } else {
      set<int>::iterator it;
      it = h1.lower_bound(a);
      if (*it == a) continue;
      int maxs = *it;
      *it--;
      int mins = *it;
      hmm[maxs - mins]--;
      if (hmm[maxs - mins] == 0) hm.erase(maxs - mins);
      hmm[maxs - a]++;
      hm.insert(maxs - a);
      hmm[a - mins]++;
      hm.insert(a - mins);
      h1.insert(a);
    }
    set<int>::iterator it1 = wm.end();
    *it1--;
    long long Max1 = *it1;
    set<int>::iterator it2 = hm.end();
    *it2--;
    long long Max2 = *it2;
    long long ans = Max1 * Max2;
    cout << ans << endl;
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Cosmic market, commonly known as Kozumike, is the largest coterie spot sale in the universe. Doujin lovers of all genres gather at Kozumike. In recent years, the number of visitors to Kozumike has been increasing. If everyone can enter from the beginning, it will be very crowded and dangerous, so admission is restricted immediately after the opening. Only a certain number of people can enter at the same time as the opening. Others have to wait for a while before entering.

However, if you decide to enter the venue on a first-come, first-served basis, some people will line up all night from the day before. Many of Kozumike's participants are minors, and there are security issues, so it is not very good to decide on a first-come, first-served basis. For that reason, Kozumike can play some kind of game among the participants, and the person who survives the game gets the right to enter first. To be fair, we use highly random games every year.

I plan to participate in Kozumike again this time. I have a douujinshi that I really want to get at this Kozumike. A doujinshi distributed by a popular circle, which deals with the magical girl anime that became a hot topic this spring. However, this circle is very popular and its distribution ends immediately every time. It would be almost impossible to get it if you couldn't enter at the same time as the opening. Of course, there is no doubt that it will be available at douujin shops at a later date. But I can't put up with it until then. I have to get it on the day of Kozumike with any hand. Unfortunately, I've never been the first to enter Kozumike.

According to Kozumike's catalog, this time we will select the first person to enter in the following games. First, the first r × c of the participants sit in any of the seats arranged like the r × c grid. You can choose the location on a first-come, first-served basis, so there are many options if you go early. The game starts when r × c people sit down. In this game, all people in a seat in a row (row) are instructed to sit or stand a certain number of times. If a person who is already seated is instructed to sit down, just wait. The same is true for those who are standing up. The column (row) to which this instruction is issued and the content of the instruction are randomly determined by roulette. Only those who stand up after a certain number of instructions will be able to enter the venue first. Participants are not informed of the number of instructions, so they do not know when the game will end. So at some point neither standing nor sitting knows if they can enter first. That's why the catalog emphasizes that you can enjoy the thrill.

At 1:00 pm the day before Kozumike, I got all the data about this year's game. According to the information I got, the number of times this instruction, q, has already been decided. On the contrary, all the instructions for q times have already been decided. It is said that it has a high degree of randomness, but that was a lie. I don't know why it was decided in advance. But this information seems to me a godsend.

If the game is played according to this data, you will know all the seating locations where you can enter first. In the worst case, let's say all the participants except me had this information. Even in such a case, you should know the number of arrivals at the latest to enter the venue first. However, it seems impossible to analyze this instruction by hand from now on because it is too much. No matter how hard I try, I can't make it in time for Kozumike.

So I decided to leave this calculation to you. You often participate in programming contests and you should be good at writing math programs like this. Of course I wouldn't ask you to do it for free. According to the catalog, this year's Kozumike will be attended by a circle that publishes a doujinshi about programming contests. If I can enter at the same time as the opening, I will get the douujinshi as a reward and give it to you. Well, I'll take a nap for about 5 hours from now on. In the meantime, I believe you will give me an answer.

Input

The input consists of multiple cases. Each case is given in the following format.

r c q
A0 B0 order0
A1 B1 order1
..
..
..
Aq-1 Bq-1 orderq-1

When Ai = 0, the orderi instruction is executed for the Bi line.
When Ai = 1, the orderi instruction is executed for the Bi column.
When orderi = 0, all people in the specified row or column are seated.
When orderi = 1, make everyone stand in the specified row or column.

The end of the input is given by r = 0 c = 0 q = 0.

The input value satisfies the following conditions.
1 ≤ r ≤ 50,000
1 ≤ c ≤ 50,000
1 ≤ q ≤ 50,000
orderi = 0 or 1
When Ai = 0
0 ≤ Bi <r
When Ai = 1
0 ≤ Bi <c

The number of test cases does not exceed 100

Output

In the worst case, print out in one line how many times you should arrive to get the right to enter the venue first.

Example

Input

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

Output

4
13
8

### Response

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

int main(){
  int r,c,q,a[50000],b[50000],o[50000];
  int nr,nc;
  bool row[50000],col[50000];
  long long int ans;

  while(1){
    cin >> r >> c >> q;
    if(!r && !c && !q)break;

    for(int i=0;i<r;i++)row[i] = false;
    for(int i=0;i<c;i++)col[i] = false;

    ans = nr = nc = 0;
    for(int i=0;i<q;i++)cin >> a[i] >> b[i] >> o[i];

    for(int i=q-1;i>=0;i--){
      if(a[i]){
	if(!col[b[i]]){
	  if(o[i])ans += r-nr;
	  col[b[i]] = true;
	  nc++;
	}
      }else{
	if(!row[b[i]]){
	  if(o[i])ans += c-nc;
	  row[b[i]] = true;
	  nr++;
	}
      }
    }
    cout << ans << endl;
  }
}
```


### Prompt

Please create a solution in Cpp to the following problem:

You are given an array a_1, a_2, ... , a_n and two integers m and k.

You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r.

The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to ∑_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) ⌉, where ⌈ x ⌉ is the least integer greater than or equal to x.

The cost of empty subarray is equal to zero.

For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are:

  * a_3 ... a_3: 15 - k ⌈ 1/3 ⌉ = 15 - 10 = 5;
  * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 ⌉ = 12 - 10 = 2;
  * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 ⌉ = 16 - 10 = 6;
  * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 ⌉ = 24 - 20 = 4;
  * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 ⌉ = 27 - 20 = 7.

Your task is to find the maximum cost of some subarray (possibly empty) of array a.

Input

The first line contains three integers n, m, and k (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 10, 1 ≤ k ≤ 10^9).

The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≤ a_i ≤ 10^9).

Output

Print the maximum cost of some subarray of array a.

Examples

Input

7 3 10
2 -4 15 -3 4 8 3

Output

7

Input

5 2 1000
-13 -4 -9 -20 -11

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mxm = 12;
long long dp[mxm];
void solve() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  long long s = 0, ans = 0;
  for (int rem = 1; rem < m; ++rem) dp[rem] = (long long)1e15;
  for (int i = 1, x, q, r; i <= n; ++i) {
    scanf("%d", &x);
    q = i / m, r = i % m, s += x;
    for (int rem = 0; rem < m; ++rem)
      ans = max(ans, s - 1LL * q * k - dp[rem] - (r > rem) * k);
    dp[r] = min(dp[r], s - 1LL * q * k);
  }
  printf("%lld\n", ans);
}
int main() {
  int tc = 1;
  while (tc--) solve();
}

```


### Prompt

Please create a solution in Cpp to the following problem:

You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: for example, the string s=";;" contains three empty words separated by ';'.

You should find all words in the given string that are nonnegative INTEGER numbers without leading zeroes and build by them new string a. String a should contain all words that are numbers separating them by ',' (the order of numbers should remain the same as in the string s). By all other words you should build string b in the same way (the order of numbers should remain the same as in the string s).

Here strings "101", "0" are INTEGER numbers, but "01" and "1.0" are not.

For example, for the string aba,123;1a;0 the string a would be equal to "123,0" and string b would be equal to "aba,1a".

Input

The only line of input contains the string s (1 ≤ |s| ≤ 105). The string contains only symbols '.' (ASCII 46), ',' (ASCII 44), ';' (ASCII 59), digits, lowercase and uppercase latin letters.

Output

Print the string a to the first line and string b to the second line. Each string should be surrounded by quotes (ASCII 34).

If there are no words that are numbers print dash (ASCII 45) on the first line. If all words are numbers print dash on the second line.

Examples

Input

aba,123;1a;0

Output

"123,0"
"aba,1a"

Input

1;;01,a0,

Output

"1"
",01,a0,"

Input

1

Output

"1"
-

Input

a

Output

-
"a"

Note

In the second example the string s contains five words: "1", "", "01", "a0", "".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, a, b, ta, t, tb;
  bool flag1, flag2, flag0;
  int l1, i, x;
  while (cin >> s) {
    l1 = s.size();
    flag1 = flag2 = flag0 = 0;
    for (i = 0; i < l1; i++) {
      if (s[i] == ',' || s[i] == ';') {
        if ((flag2 == 0 || flag2 == 1) && flag1 == 0) {
          b += ",";
          if (tb.size() == 0) {
            tb = b;
          } else {
            tb += b;
          }
          b.clear();
          flag2 = flag0 = 0;
          continue;
        } else if (flag1 == 1 && flag2 == 0) {
          a += ",";
          if (ta.size() == 0) {
            ta = a;
          } else {
            ta += a;
          }
          a.clear();
          flag1 = 0;
          continue;
        }
      }
      if (s[i] >= '0' && s[i] <= '9' && flag0 == 0 && flag2 == 0) {
        if (a.size() == 0) {
          a = " ";
          a[0] = s[i];
          flag1 = 1;
        } else if (a[0] == '0') {
          t = " ";
          t[0] = s[i];
          a += t;
          b += a;
          a.clear();
          flag0 = 1;
          flag1 = 0;
        } else {
          t = " ";
          t[0] = s[i];
          a += t;
          flag1 = 1;
        }
      } else {
        if (s[i - 1] >= '0' && s[i - 1] <= '9' && flag1 == 1) {
          b += a;
          a.clear();
          flag1 = 0;
        }
        t = " ";
        t[0] = s[i];
        b += t;
        flag2 = 1;
      }
    }
    if (a.size() != 0) {
      if (ta.size() == 0)
        ta = a;
      else
        ta += a;
    } else if (b.size() != 0) {
      if (tb.size() == 0)
        tb = b;
      else
        tb += b;
    }
    if (ta.size() == 0)
      printf("-\n");
    else {
      x = ta.size() - 1;
      if (ta[x] == ',') ta.erase(ta.begin() + x);
      cout << "\"" << ta << "\"\n";
    }
    if (tb.size() == 0) {
      if (s[l1 - 1] == ',' || s[l1 - 1] == ';')
        printf("\"\"\n");
      else
        printf("-\n");
    } else {
      x = tb.size() - 1;
      if (tb[x] == ',' && (s[l1 - 1] != ',' && s[l1 - 1] != ';'))
        tb.erase(tb.begin() + x);
      cout << "\"" << tb << "\"\n";
    }
    ta.clear();
    tb.clear();
    a.clear();
    b.clear();
    t.clear();
  }
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Nezzar loves the game osu!.

osu! is played on beatmaps, which can be seen as an array consisting of distinct points on a plane. A beatmap is called nice if for any three consecutive points A,B,C listed in order, the angle between these three points, centered at B, is strictly less than 90 degrees.

<image> Points A,B,C on the left have angle less than 90 degrees, so they can be three consecutive points of a nice beatmap; Points A',B',C' on the right have angle greater or equal to 90 degrees, so they cannot be three consecutive points of a nice beatmap.

Now Nezzar has a beatmap of n distinct points A_1,A_2,…,A_n. Nezzar would like to reorder these n points so that the resulting beatmap is nice.

Formally, you are required to find a permutation p_1,p_2,…,p_n of integers from 1 to n, such that beatmap A_{p_1},A_{p_2},…,A_{p_n} is nice. If it is impossible, you should determine it.

Input

The first line contains a single integer n (3 ≤ n ≤ 5000).

Then n lines follow, i-th of them contains two integers x_i, y_i (-10^9 ≤ x_i, y_i ≤ 10^9) — coordinates of point A_i.

It is guaranteed that all points are distinct.

Output

If there is no solution, print -1.

Otherwise, print n integers, representing a valid permutation p.

If there are multiple possible answers, you can print any.

Example

Input

5
0 0
5 0
4 2
2 1
3 0

Output

1 2 5 3 4

Note

Here is the illustration for the first test:

<image>

Please note that the angle between A_1, A_2 and A_5, centered at A_2, is treated as 0 degrees. However, angle between A_1, A_5 and A_2, centered at A_5, is treated as 180 degrees.

### Response

```cpp
//#pragma GCC optimize ("O2")
//#pragma GCC optimize ("Ofast")
// <IN THE NAME OF GOD>
// this is mamad
#include <bits/stdc++.h>
using namespace std;
typedef pair <int64_t, int64_t> pii;
#define debug "ahhh shit\n"

template <typename Head>
inline void dout(Head in) {
  cerr << in << '\n';
}

int main() {
  ios::sync_with_stdio(false), cin.tie(NULL);
  int n;
  cin >> n;
  vector <pii> v(n);
  for (pii &e: v)
    cin >> e.first >> e.second;
  function <int64_t (pii, pii)> dis = [](pii P1, pii P2) {
    return (P1.first - P2.first) * (P1.first - P2.first) + (P1.second - P2.second) * (P1.second - P2.second);
  };
  vector <bool> mark(n);
  mark[0] = true;
  vector <int> ans;
  ans.emplace_back(0);
  int prev = 0;
  for (int i = 0; i < n - 1; i++) {
    int idx = prev;
    for (int j = 0; j < n; j++) {
      if (dis(v[prev], v[idx]) < dis(v[prev], v[j]) and !mark[j]) {
        idx = j;
      }
    }
    mark[idx] = true;
    ans.emplace_back(idx);
    prev = idx;
  }
  for (int &e: ans)
    e++;
  for (int e: ans)
    cout << e << ' ';
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Hanh is a famous biologist. He loves growing trees and doing experiments on his own garden.

One day, he got a tree consisting of n vertices. Vertices are numbered from 1 to n. A tree with n vertices is an undirected connected graph with n-1 edges. Initially, Hanh sets the value of every vertex to 0.

Now, Hanh performs q operations, each is either of the following types:

  * Type 1: Hanh selects a vertex v and an integer d. Then he chooses some vertex r uniformly at random, lists all vertices u such that the path from r to u passes through v. Hanh then increases the value of all such vertices u by d.
  * Type 2: Hanh selects a vertex v and calculates the expected value of v.

Since Hanh is good at biology but not math, he needs your help on these operations.

Input

The first line contains two integers n and q (1 ≤ n, q ≤ 150 000) — the number of vertices on Hanh's tree and the number of operations he performs.

Each of the next n - 1 lines contains two integers u and v (1 ≤ u, v ≤ n), denoting that there is an edge connecting two vertices u and v. It is guaranteed that these n - 1 edges form a tree.

Each of the last q lines describes an operation in either formats:

  * 1 v d (1 ≤ v ≤ n, 0 ≤ d ≤ 10^7), representing a first-type operation.
  * 2 v (1 ≤ v ≤ n), representing a second-type operation.

It is guaranteed that there is at least one query of the second type.

Output

For each operation of the second type, write the expected value on a single line.

Let M = 998244353, it can be shown that the expected value can be expressed as an irreducible fraction p/q, where p and q are integers and q not ≡ 0 \pmod{M}. Output the integer equal to p ⋅ q^{-1} mod M. In other words, output such an integer x that 0 ≤ x < M and x ⋅ q ≡ p \pmod{M}.

Example

Input

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

Output

1
199648871
399297742
199648871
199648871
598946614
199648873
2
2
2

Note

The image below shows the tree in the example:

<image>

For the first query, where v = 1 and d = 1:

  * If r = 1, the values of all vertices get increased.
  * If r = 2, the values of vertices 1 and 3 get increased.
  * If r = 3, the values of vertices 1, 2, 4 and 5 get increased.
  * If r = 4, the values of vertices 1 and 3 get increased.
  * If r = 5, the values of vertices 1 and 3 get increased.

Hence, the expected values of all vertices after this query are (1, 0.4, 0.8, 0.4, 0.4).

For the second query, where v = 2 and d = 2:

  * If r = 1, the values of vertices 2, 4 and 5 get increased.
  * If r = 2, the values of all vertices get increased.
  * If r = 3, the values of vertices 2, 4 and 5 get increased.
  * If r = 4, the values of vertices 1, 2, 3 and 5 get increased.
  * If r = 5, the values of vertices 1, 2, 3 and 4 get increased.

Hence, the expected values of all vertices after this query are (2.2, 2.4, 2, 2, 2).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void ckmin(T &a, U b) {
  if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
  if (a < b) a = b;
}
long long expo(long long a, long long e) {
  if (e == 0) return 1;
  long long res = expo(a * a % 998244353, e >> 1);
  if (e & 1) {
    res *= a;
    res %= 998244353;
  }
  return res;
}
int N, Q, T;
long long iN;
vector<int> edge[500013];
int parent[500013], st[500013], ft[500013], depth[500013], subtree[500013],
    ancestor[20][500013];
long long upd[500013], dp[500013];
long long stor[500013];
vector<pair<long long, long long> > upds;
vector<int> ord;
void dfs(int u, int p) {
  st[u] = ft[u] = T;
  subtree[u] = 1;
  T++;
  for (int v : edge[u]) {
    if (v == p) continue;
    parent[v] = u;
    depth[v] = depth[u] + 1;
    dfs(v, u);
    ft[u] = ft[v];
    subtree[u] += subtree[v];
  }
  ord.push_back(u);
}
int kth(int u, int k) {
  for (auto i = (18) - 1; i >= (0); i--) {
    if (k & (1 << i)) {
      u = ancestor[i][u];
    }
  }
  return u;
}
bool insubt(int u, int v) {
  if (u == N) return true;
  return (st[u] <= st[v] && st[v] <= ft[u]);
}
long long get(long long u, long long v) {
  if (u == v) return 0;
  if (insubt(u, v)) {
    int w = kth(v, depth[v] - depth[u] - 1);
    return subtree[w];
  }
  return N - subtree[u];
}
void rebuild() {
  for (auto p : upds) {
    upd[p.first] += p.second;
  }
  for (auto i = (0); i < (N); i++) {
    if (upd[i] == 0) continue;
    upd[i] %= 998244353;
    stor[0] += subtree[i] * upd[i];
    stor[0] %= 998244353;
    stor[i] += (N - subtree[i]) * upd[i];
    stor[i] %= 998244353;
    for (int v : edge[i]) {
      if (v == parent[i]) continue;
      stor[v] -= subtree[v] * upd[i];
      stor[v] %= 998244353;
    }
  }
  for (auto i = (N)-1; i >= (0); i--) {
    int u = ord[i];
    for (int v : edge[u]) {
      if (v == parent[u]) continue;
      stor[v] += stor[u];
      if (stor[v] >= 998244353) stor[v] -= 998244353;
    }
  }
  for (auto i = (0); i < (N); i++) {
    dp[i] += stor[i];
    dp[i] %= 998244353;
    if (dp[i] < 0) dp[i] += 998244353;
    upd[i] = 0;
    stor[i] = 0;
  }
  upds.clear();
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(12);
  cerr << fixed << setprecision(4);
  cin >> N >> Q;
  for (auto i = (0); i < (N - 1); i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  iN = expo(N, 998244353 - 2);
  dfs(0, N);
  for (auto i = (0); i < (20); i++) {
    ancestor[i][N] = N;
  }
  for (auto i = (0); i < (N); i++) {
    ancestor[0][i] = parent[i];
  }
  for (auto i = (1); i < (20); i++) {
    for (auto j = (0); j < (N); j++) {
      ancestor[i][j] = ancestor[i - 1][ancestor[i - 1][j]];
    }
  }
  for (auto i = (0); i < (Q); i++) {
    int qid, u;
    cin >> qid >> u;
    u--;
    if (i % 241 == 0) {
      rebuild();
    }
    if (qid == 2) {
      long long ans = dp[u];
      for (pair<long long, long long> p : upds) {
        ans += (N - get(p.first, u)) * p.second;
        ans %= 998244353;
      }
      cout << ans << '\n';
    }
    if (qid == 1) {
      long long v;
      cin >> v;
      v *= iN;
      v %= 998244353;
      upds.push_back({u, v});
    }
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.

Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:

* Extension Magic: Consumes 1 MP (magic point). Choose one bamboo and increase its length by 1.
* Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1.
* Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.)

At least how much MP is needed to achieve the objective?

Constraints

* 3 \leq N \leq 8
* 1 \leq C < B < A \leq 1000
* 1 \leq l_i \leq 1000
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N A B C
l_1
l_2
:
l_N

Output

Print the minimum amount of MP needed to achieve the objective.

Examples

Input

5 100 90 80
98
40
30
21
80

Output

23

Input

8 100 90 80
100
100
90
90
90
80
80
80

Output

0

Input

8 1000 800 100
300
333
400
444
500
555
600
666

Output

243

### Response

```cpp
#include <iostream>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int n,l[10],ans=1000000000,i;
int x[4],X[4];
int main(){
    cin>>n>>X[1]>>X[2]>>X[3];
    for(i=0;i<n;i++) cin>>l[i];
    for(i=0;i<1<<(2*n);i++){
        int tmp=0;
        for(int j=0;j<4;j++)x[j]=0;
        for(int j=0;j<2*n;j+=2){
            x[(i>>j)&3]+=l[j/2];
            if((i>>j)&3)tmp+=10;
        }
        if(!(x[1]&&x[2]&&x[3])) continue;
        for(int j=1;j<4;j++)tmp+=abs(X[j]-x[j]);
        ans=min(ans,tmp-30);
    }
    cout<<ans<<endl;
    return 0;
}
```


### Prompt

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

One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.

Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.

As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.

Print the minimum size of each made photo in pixels.

Input

The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends.

Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.

Output

Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.

Examples

Input

3
1 10
5 5
10 1

Output

75 110 60

Input

3
2 1
1 2
2 1

Output

6 4 6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long K = 1;
int main() {
  int W = 0, H1 = 0, H2 = 0, n, i;
  vector<pair<int, int> > v;
  cin >> n;
  v.resize(n);
  for (i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
    W += v[i].first;
    if (v[i].second >= H1) {
      H2 = H1;
      H1 = v[i].second;
    } else if (v[i].second > H2) {
      H2 = v[i].second;
    }
  }
  for (i = 0; i < n; i++) {
    if (v[i].second == H1)
      cout << (W - v[i].first) * H2 << ' ';
    else
      cout << (W - v[i].first) * H1 << ' ';
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Salem gave you n sticks with integer positive lengths a_1, a_2, …, a_n.

For every stick, you can change its length to any other positive integer length (that is, either shrink or stretch it). The cost of changing the stick's length from a to b is |a - b|, where |x| means the absolute value of x.

A stick length a_i is called almost good for some integer t if |a_i - t| ≤ 1.

Salem asks you to change the lengths of some sticks (possibly all or none), such that all sticks' lengths are almost good for some positive integer t and the total cost of changing is minimum possible. The value of t is not fixed in advance and you can choose it as any positive integer.

As an answer, print the value of t and the minimum cost. If there are multiple optimal choices for t, print any of them.

Input

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

The second line contains n integers a_i (1 ≤ a_i ≤ 100) — the lengths of the sticks.

Output

Print the value of t and the minimum possible cost. If there are multiple optimal choices for t, print any of them.

Examples

Input

3
10 1 4

Output

3 7

Input

5
1 1 2 2 3

Output

2 0

Note

In the first example, we can change 1 into 2 and 10 into 4 with cost |1 - 2| + |10 - 4| = 1 + 6 = 7 and the resulting lengths [2, 4, 4] are almost good for t = 3.

In the second example, the sticks lengths are already almost good for t = 2, so we don't have to do anything.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long solve() {
  long long n, a, m = INT_MAX, s;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (long long i = 1; i < 101; i++) {
    a = 0;
    for (long long j = 0; j < n; j++) {
      if (arr[j] > i)
        a = a + arr[j] - i - 1;
      else if (arr[j] < i)
        a = a + i - arr[j] - 1;
    }
    if (a < m) {
      m = a;
      s = i;
    }
  }
  cout << s << " " << m;
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.

Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence.

Here, the distance between two points s and t on a number line is represented by |s-t|.

Constraints

* 1 \leq x \leq 1000
* 1 \leq a \leq 1000
* 1 \leq b \leq 1000
* x, a and b are pairwise distinct.
* The distances between Snuke's residence and stores A and B are different.

Input

Input is given from Standard Input in the following format:

x a b

Output

If store A is closer, print `A`; if store B is closer, print `B`.

Examples

Input

5 2 7

Output

B

Input

1 999 1000

Output

A

### Response

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

int main() {
  int x, a, b;
  std::cin >> x >> a >> b;
  std::cout << (std::abs(a - x) < std::abs(b - x) ? "A\n" : "B\n");
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.

The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.

Input

The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups.

The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.

Output

Print the maximum number of teams of three people the coach can form.

Examples

Input

4
1 1 2 1

Output

1

Input

2
2 2

Output

0

Input

7
2 2 2 1 1 1 1

Output

3

Input

3
1 1 1

Output

1

Note

In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.

In the second example he can't make a single team.

In the third example the coach can form three teams. For example, he can do this in the following way:

  * The first group (of two people) and the seventh group (of one person),
  * The second group (of two people) and the sixth group (of one person),
  * The third group (of two people) and the fourth group (of one person).

### Response

```cpp
#include <bits/stdc++.h>
int n;
int book[3];
int main() {
  while (~scanf("%d", &n)) {
    int x;
    memset(book, 0, sizeof(book));
    for (int i = 0; i < n; i++) {
      scanf("%d", &x);
      book[x]++;
    }
    if (book[1] == 0 && book[2])
      printf("0\n");
    else if (book[1] && book[2] == 0)
      printf("%d\n", book[1] / 3);
    else {
      if (book[2] < book[1])
        printf("%d\n", book[2] + (book[1] - book[2]) / 3);
      else if (book[2] >= book[1])
        printf("%d\n", book[1]);
    }
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Two people play the following string game. Initially the players have got some string s. The players move in turns, the player who cannot make a move loses.

Before the game began, the string is written on a piece of paper, one letter per cell.

<image> An example of the initial situation at s = "abacaba"

A player's move is the sequence of actions:

  1. The player chooses one of the available pieces of paper with some string written on it. Let's denote it is t. Note that initially, only one piece of paper is available.
  2. The player chooses in the string t = t1t2... t|t| character in position i (1 ≤ i ≤ |t|) such that for some positive integer l (0 < i - l; i + l ≤ |t|) the following equations hold: ti - 1 = ti + 1, ti - 2 = ti + 2, ..., ti - l = ti + l.
  3. Player cuts the cell with the chosen character. As a result of the operation, he gets three new pieces of paper, the first one will contain string t1t2... ti - 1, the second one will contain a string consisting of a single character ti, the third one contains string ti + 1ti + 2... t|t|.

<image> An example of making action (i = 4) with string s = «abacaba»

Your task is to determine the winner provided that both players play optimally well. If the first player wins, find the position of character that is optimal to cut in his first move. If there are multiple positions, print the minimal possible one.

Input

The first line contains string s (1 ≤ |s| ≤ 5000). It is guaranteed that string s only contains lowercase English letters.

Output

If the second player wins, print in the single line "Second" (without the quotes). Otherwise, print in the first line "First" (without the quotes), and in the second line print the minimal possible winning move — integer i (1 ≤ i ≤ |s|).

Examples

Input

abacaba

Output

First
2

Input

abcde

Output

Second

Note

In the first sample the first player has multiple winning moves. But the minimum one is to cut the character in position 2.

In the second sample the first player has no available moves.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, num;
int sg[5010], f[5010];
char p[5010];
inline int mex() {
  int i;
  for (i = 0; f[i] == num; i++)
    ;
  return i;
}
inline int S(int x) { return x < 0 ? 0 : sg[x]; }
inline void prepare() {
  int i, j;
  for (i = 1; i <= n; i++) {
    num++;
    for (j = 1; j <= i; j++) f[S(j - 2) ^ S(i - j - 1)] = num;
    sg[i] = mex();
  }
}
inline void work(int x) {
  int i, an = 0, j;
  for (i = 2; i < x - 1;) {
    for (; i < x - 1 && p[i - 1] != p[i + 1]; i++)
      ;
    if (i == x - 1) break;
    for (j = i; j < x - 1 && p[j - 1] == p[j + 1]; j++)
      ;
    an ^= sg[j - i];
    i = j;
  }
  for (i = x + 2; i < n;) {
    for (; i < n && p[i - 1] != p[i + 1]; i++)
      ;
    if (i == n) break;
    for (j = i; j < n && p[j - 1] == p[j + 1]; j++)
      ;
    an ^= sg[j - i];
    i = j;
  }
  if (!an) {
    printf("First\n%d\n", x);
    exit(0);
  }
}
int main() {
  scanf("%s", p + 1);
  n = strlen(p + 1);
  prepare();
  for (i = 2; i <= n - 1; i++)
    if (p[i - 1] == p[i + 1]) work(i);
  printf("Second\n");
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Little Paul wants to learn how to play piano. He already has a melody he wants to start with. For simplicity he represented this melody as a sequence a_1, a_2, …, a_n of key numbers: the more a number is, the closer it is to the right end of the piano keyboard.

Paul is very clever and knows that the essential thing is to properly assign fingers to notes he's going to play. If he chooses an inconvenient fingering, he will then waste a lot of time trying to learn how to play the melody by these fingers and he will probably not succeed.

Let's denote the fingers of hand by numbers from 1 to 5. We call a fingering any sequence b_1, …, b_n of fingers numbers. A fingering is convenient if for all 1≤ i ≤ n - 1 the following holds:

  * if a_i < a_{i+1} then b_i < b_{i+1}, because otherwise Paul needs to take his hand off the keyboard to play the (i+1)-st note;
  * if a_i > a_{i+1} then b_i > b_{i+1}, because of the same;
  * if a_i = a_{i+1} then b_i≠ b_{i+1}, because using the same finger twice in a row is dumb. Please note that there is ≠, not = between b_i and b_{i+1}.

Please provide any convenient fingering or find out that there is none.

Input

The first line contains a single integer n (1 ≤ n ≤ 10^5) denoting the number of notes.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 2⋅10^5) denoting the positions of notes on the keyboard.

Output

If there is no convenient fingering, print -1. Otherwise, print n numbers b_1, b_2, …, b_n, each from 1 to 5, denoting a convenient fingering, separated by spaces.

Examples

Input

5
1 1 4 2 2

Output

1 4 5 4 5

Input

7
1 5 7 8 10 3 1

Output

1 2 3 4 5 4 3

Input

19
3 3 7 9 8 8 8 8 7 7 7 7 5 3 3 3 3 8 8

Output

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

Note

The third sample test is kinda "Non stop" song by Reflex.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int max_n = 1e5 + 100;
int n;
int a[max_n];
int b[max_n];
int res[max_n];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 2; i <= n; ++i) {
    if (a[i] > a[i - 1])
      b[i - 1] = b[i] = 1;
    else if (a[i] < a[i - 1])
      b[i - 1] = b[i] = -1;
  }
  b[0] = -b[1];
  for (int i = 1; i <= n; ++i) {
    if (b[i] == 1) {
      if (b[i - 1] == 1)
        a[i - 1] == a[i] ? res[i] = 1 : res[i] = res[i - 1] + 1;
      else if (b[i - 1] == -1) {
        if (a[i - 1] == a[i])
          res[i - 1] == 1 ? res[i] = 2 : res[i] = 1;
        else
          res[i] = 1;
      } else
        res[i] = 1;
      if (res[i] > 5) {
        printf("-1");
        return 0;
      }
    } else if (b[i] == -1) {
      if (b[i - 1] == -1)
        a[i - 1] == a[i] ? res[i] = 5 : res[i] = res[i - 1] - 1;
      else if (b[i - 1] == 1) {
        if (a[i - 1] == a[i])
          res[i - 1] == 5 ? res[i] = 4 : res[i] = 5;
        else
          res[i] = 5;
      } else
        res[i] = 5;
      if (res[i] < 1) {
        printf("-1");
        return 0;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (b[i] == 0) {
      for (int j = 1; j <= 5; ++j)
        if (j != res[i - 1] && j != res[i + 1]) res[i] = j;
    }
  }
  for (int i = 1; i <= n; ++i) printf("%d ", res[i]);
}

```


### Prompt

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

Takahashi the Jumbo will practice golf.

His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive).

If he can achieve the objective, print `OK`; if he cannot, print `NG`.

Constraints

* All values in input are integers.
* 1 \leq A \leq B \leq 1000
* 1 \leq K \leq 1000

Input

Input is given from Standard Input in the following format:

K
A B

Output

If he can achieve the objective, print `OK`; if he cannot, print `NG`.

Examples

Input

7
500 600

Output

OK

Input

4
5 7

Output

NG

Input

1
11 11

Output

OK

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int k,a,b;
  cin >> k >> a >>b;
  if((b/k)*k >= a && (b/k)*k<=b)	cout <<"OK";
  else	cout << "NG";
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A = [a1, a2, ..., an] and B = [b1, b2, ..., bn] of length n each which he uses to ask people some quite peculiar questions.

To test you on how good are you at spotting inequality in life, he wants you to find an "unfair" subset of the original sequence. To be more precise, he wants you to select k numbers P = [p1, p2, ..., pk] such that 1 ≤ pi ≤ n for 1 ≤ i ≤ k and elements in P are distinct. Sequence P will represent indices of elements that you'll select from both sequences. He calls such a subset P "unfair" if and only if the following conditions are satisfied: 2·(ap1 + ... + apk) is greater than the sum of all elements from sequence A, and 2·(bp1 + ... + bpk) is greater than the sum of all elements from the sequence B. Also, k should be smaller or equal to <image> because it will be to easy to find sequence P if he allowed you to select too many elements!

Mike guarantees you that a solution will always exist given the conditions described above, so please help him satisfy his curiosity!

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of elements in the sequences.

On the second line there are n space-separated integers a1, ..., an (1 ≤ ai ≤ 109) — elements of sequence A.

On the third line there are also n space-separated integers b1, ..., bn (1 ≤ bi ≤ 109) — elements of sequence B.

Output

On the first line output an integer k which represents the size of the found subset. k should be less or equal to <image>.

On the next line print k integers p1, p2, ..., pk (1 ≤ pi ≤ n) — the elements of sequence P. You can print the numbers in any order you want. Elements in sequence P should be distinct.

Example

Input

5
8 7 4 8 3
4 2 5 3 7

Output

3
1 4 5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100007;
const int oo = 0x3f3f3f3f;
const long long loo = 4223372036854775807ll;
const long long mod = 1e9 + 7;
struct Fuck {
  int num;
  int k;
  Fuck() {}
  Fuck(int _a, int _b) {
    num = _a;
    k = _b;
  }
  bool operator<(const Fuck &t) const { return num > t.num; }
} f[MAXN];
int b[MAXN];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;
  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      cin >> f[i].num;
      f[i].k = i + 1;
    }
    for (int i = 1; i <= n; i++) {
      cin >> b[i];
    }
    sort(f, f + n);
    vector<int> vec;
    vec.push_back(f[0].k);
    for (int i = 1; i < n; i += 2) {
      if (n % 2 == 0 && i == n - 1) {
        vec.push_back(f[i].k);
        continue;
      }
      if (b[f[i].k] > b[f[i + 1].k])
        vec.push_back(f[i].k);
      else
        vec.push_back(f[i + 1].k);
    }
    cout << vec.size() << endl;
    for (int i = 0; i < vec.size(); i++) {
      cout << vec[i];
      if (i == vec.size() - 1)
        cout << '\n';
      else
        cout << ' ';
    }
  }
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number.

For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't.

Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7).

A number's length is the number of digits in its decimal representation without leading zeroes.

Input

The first line contains three integers: a, b, n (1 ≤ a < b ≤ 9, 1 ≤ n ≤ 106).

Output

Print a single integer — the answer to the problem modulo 1000000007 (109 + 7).

Examples

Input

1 3 3

Output

1

Input

2 3 10

Output

165

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long fact[1000010];
long long m = 1e9 + 7;
long long me(long long a, long long b, long long m) {
  long long ans = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      ans = (ans % m * a % m) % m;
    }
    a = (a * a) % m;
    b /= 2;
  }
  return ans % m;
}
bool check(long long x, long long a, long long b) {
  while (x > 0) {
    int dg = x % 10;
    if (dg != a && dg != b) return false;
    x /= 10;
  }
  return true;
}
long long ncr(long long n, long long r) {
  long long fn = fact[n];
  long long tf = fact[r] * fact[n - r];
  tf = tf % m;
  tf = me(tf, m - 2, m);
  fn = (tf % m * fn % m) % m;
  return fn % m;
}
int main() {
  fact[0] = 1;
  for (long long i = 1; i <= 1000001; i++) {
    fact[i] = (fact[i - 1] * i) % m;
  }
  int n, a, b;
  cin >> a >> b >> n;
  if (a == b) {
    if (check(n * a, a, b)) {
      cout << "1\n";
    } else
      cout << "0\n";
    return 0;
  }
  long long ans = 0;
  for (long long i = 0; i <= n; i++) {
    long long tmp = i * a + (n - i) * b;
    if (check(tmp, a, b)) {
      ans += ncr(n, i);
      ans %= m;
    }
  }
  cout << ans << "\n";
  return 0;
}

```


### Prompt

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

There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs.

Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines.

You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other.

Input

The first line contains a single integer n (2 ≤ n ≤ 109) — the number of shovels in Polycarp's shop.

Output

Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines.

Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways.

It is guaranteed that for every n ≤ 109 the answer doesn't exceed 2·109.

Examples

Input

7

Output

3

Input

14

Output

9

Input

50

Output

1

Note

In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose:

  * 2 and 7;
  * 3 and 6;
  * 4 and 5.

In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp:

  * 1 and 8;
  * 2 and 7;
  * 3 and 6;
  * 4 and 5;
  * 5 and 14;
  * 6 and 13;
  * 7 and 12;
  * 8 and 11;
  * 9 and 10.

In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n;
long long cur = 0;
long long cate(long long s) {
  long long ma = min(s - 1, n);
  long long mi = (s + 2) / 2;
  if (mi <= ma) {
    return ma - mi + 1;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  while (10 * cur + 9 <= 2 * n - 1) {
    cur = 10 * cur + 9;
  }
  long long add = cur + 1;
  long long ans = 0;
  for (long long i = 1; i <= 9; i++) {
    ans += cate(cur);
    cur += add;
  }
  cout << ans << "\n";
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

In programming, hexadecimal notation is often used.

In hexadecimal notation, besides the ten digits 0, 1, ..., 9, the six letters `A`, `B`, `C`, `D`, `E` and `F` are used to represent the values 10, 11, 12, 13, 14 and 15, respectively.

In this problem, you are given two letters X and Y. Each X and Y is `A`, `B`, `C`, `D`, `E` or `F`.

When X and Y are seen as hexadecimal numbers, which is larger?

Constraints

* Each X and Y is `A`, `B`, `C`, `D`, `E` or `F`.

Input

Input is given from Standard Input in the following format:

X Y

Output

If X is smaller, print `<`; if Y is smaller, print `>`; if they are equal, print `=`.

Examples

Input

A B

Output

<

Input

E C

Output

>

Input

F F

Output

=

### Response

```cpp
#include <stdio.h>
int main(){
    char a,b;scanf("%c %c",&a,&b);
    if(a>b) putchar('>');else if(a<b) putchar('<');else putchar('=');return putchar('\n'),0;
}
```


### Prompt

Create a solution in CPP for the following problem:

Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal a instant damage to him, and then heal that enemy b health points at the end of every second, for exactly c seconds, starting one second after the ability is used. That means that if the ability is used at time t, the enemy's health decreases by a at time t, and then increases by b at time points t + 1, t + 2, ..., t + c due to this ability.

The ability has a cooldown of d seconds, i. e. if Meka-Naruto uses it at time moment t, next time he can use it is the time t + d. Please note that he can only use the ability at integer points in time, so all changes to the enemy's health also occur at integer times only.

The effects from different uses of the ability may stack with each other; that is, the enemy which is currently under k spells gets k⋅ b amount of heal this time. Also, if several health changes occur at the same moment, they are all counted at once.

Now Meka-Naruto wonders if he can kill the enemy by just using the ability each time he can (that is, every d seconds). The enemy is killed if their health points become 0 or less. Assume that the enemy's health is not affected in any way other than by Meka-Naruto's character ability. What is the maximal number of health points the enemy can have so that Meka-Naruto is able to kill them?

Input

The first line contains an integer t (1≤ t≤ 10^5) standing for the number of testcases.

Each test case is described with one line containing four numbers a, b, c and d (1≤ a, b, c, d≤ 10^6) denoting the amount of instant damage, the amount of heal per second, the number of heals and the ability cooldown, respectively.

Output

For each testcase in a separate line print -1 if the skill can kill an enemy hero with an arbitrary number of health points, otherwise print the maximal number of health points of the enemy that can be killed.

Example

Input

7
1 1 1 1
2 2 2 2
1 2 3 4
4 3 2 1
228 21 11 3
239 21 11 3
1000000 1 1000000 1

Output

1
2
1
5
534
-1
500000500000

Note

In the first test case of the example each unit of damage is cancelled in a second, so Meka-Naruto cannot deal more than 1 damage.

In the fourth test case of the example the enemy gets:

  * 4 damage (1-st spell cast) at time 0;
  * 4 damage (2-nd spell cast) and 3 heal (1-st spell cast) at time 1 (the total of 5 damage to the initial health);
  * 4 damage (3-nd spell cast) and 6 heal (1-st and 2-nd spell casts) at time 2 (the total of 3 damage to the initial health);
  * and so on.

One can prove that there is no time where the enemy gets the total of 6 damage or more, so the answer is 5. Please note how the health is recalculated: for example, 8-health enemy would not die at time 1, as if we first subtracted 4 damage from his health and then considered him dead, before adding 3 heal.

In the sixth test case an arbitrarily healthy enemy can be killed in a sufficient amount of time.

In the seventh test case the answer does not fit into a 32-bit integer type.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long f(long long a, long long b, long long c, long long x) {
  return (a * x * x + b * x + c);
}
long long BF(long long a, long long b, long long c, int left, int right) {
  long long tmp;
  while (left <= right) {
    int mid = (left + right) / 2;
    if (f(a, b, c, mid) > f(a, b, c, mid + 1)) {
      tmp = f(a, b, c, mid);
      right = mid - 1;
    } else
      left = mid + 1;
  }
  return tmp;
}
int main() {
  int t;
  long long a, b, c, d;
  long long res;
  scanf("%d", &t);
  for (int test = 1; test <= t; test++) {
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    long long vt1 = a - b * c;
    if (vt1 > 0)
      res = -1;
    else {
      int tmp = c / d;
      res = BF(-d * b, -d * b + 2 * a, 2 * a, 0, tmp) / 2;
    }
    cout << res << endl;
  }
  return 0;
}

```


### Prompt

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

A and B are preparing themselves for programming contests.

After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes.

A likes lowercase letters of the Latin alphabet. He has assigned to each letter a number that shows how much he likes that letter (he has assigned negative numbers to the letters he dislikes).

B likes substrings. He especially likes the ones that start and end with the same letter (their length must exceed one).

Also, A and B have a string s. Now they are trying to find out how many substrings t of a string s are interesting to B (that is, t starts and ends with the same letter and its length is larger than one), and also the sum of values of all letters (assigned by A), except for the first and the last one is equal to zero.

Naturally, A and B have quickly found the number of substrings t that are interesting to them. Can you do it?

Input

The first line contains 26 integers xa, xb, ..., xz ( - 105 ≤ xi ≤ 105) — the value assigned to letters a, b, c, ..., z respectively.

The second line contains string s of length between 1 and 105 characters, consisting of Lating lowercase letters— the string for which you need to calculate the answer.

Output

Print the answer to the problem.

Examples

Input

1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
xabcab

Output

2

Input

1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
aaa

Output

2

Note

In the first sample test strings satisfying the condition above are abca and bcab.

In the second sample test strings satisfying the condition above are two occurences of aa.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, len, alpha[26];
  for (i = 0; i < 26; i++) cin >> alpha[i];
  long long ans = 0, sum = 0;
  string str;
  cin >> str;
  len = str.length();
  map<long long, long long> m[26];
  for (i = 0; i < len; i++) {
    int x = str[i] - 'a';
    ans += m[x][sum];
    m[x][sum += alpha[x]]++;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly k of the nodes should be exit-nodes, that means that each of them should be connected to exactly one other node of the network, while all other nodes should be connected to at least two nodes in order to increase the system stability.

Arkady wants to make the system as fast as possible, so he wants to minimize the maximum distance between two exit-nodes. The distance between two nodes is the number of wires a package needs to go through between those two nodes.

Help Arkady to find such a way to build the network that the distance between the two most distant exit-nodes is as small as possible.

Input

The first line contains two integers n and k (3 ≤ n ≤ 2·105, 2 ≤ k ≤ n - 1) — the total number of nodes and the number of exit-nodes.

Note that it is always possible to build at least one network with n nodes and k exit-nodes within the given constraints.

Output

In the first line print the minimum possible distance between the two most distant exit-nodes. In each of the next n - 1 lines print two integers: the ids of the nodes connected by a wire. The description of each wire should be printed exactly once. You can print wires and wires' ends in arbitrary order. The nodes should be numbered from 1 to n. Exit-nodes can have any ids.

If there are multiple answers, print any of them.

Examples

Input

3 2

Output

2
1 2
2 3

Input

5 3

Output

3
1 2
2 3
3 4
3 5

Note

In the first example the only network is shown on the left picture.

In the second example one of optimal networks is shown on the right picture.

Exit-nodes are highlighted.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  long long val = (n - k);
  val--;
  long long val1 = val / k;
  long long val2 = val % k;
  long long ans = 0;
  ans += 2 * (val1 + 1);
  if (val2) {
    if (val2 == 1) {
      ans++;
    } else {
      ans += 2;
    }
  }
  cout << ans << '\n';
  long long l = 2;
  long long r;
  long long j;
  for (long long i = 0; i < val2; i++) {
    cout << 1 << " " << l << '\n';
    for (j = l; j < l + val1 + 1; j++) {
      cout << j << " " << j + 1 << '\n';
      r = j + 1;
    }
    l = j + 1;
  }
  for (long long i = 0; i < k - val2; i++) {
    cout << 1 << " " << l << '\n';
    for (j = l; j < l + val1; j++) {
      cout << j << " " << j + 1 << '\n';
    }
    l = j + 1;
  }
  return 0;
}

```