### Prompt

Create a solution in Cpp for the following problem:

Lenny had an n × m matrix of positive integers. He loved the matrix so much, because each row of the matrix was sorted in non-decreasing order. For the same reason he calls such matrices of integers lovely.

One day when Lenny was at school his little brother was playing with Lenny's matrix in his room. He erased some of the entries of the matrix and changed the order of some of its columns. When Lenny got back home he was very upset. Now Lenny wants to recover his matrix.

Help him to find an order for the columns of the matrix so that it's possible to fill in the erased entries of the matrix to achieve a lovely matrix again. Note, that you can fill the erased entries of the matrix with any integers.

Input

The first line of the input contains two positive integers n and m (1 ≤ n·m ≤ 105). Each of the next n lines contains m space-separated integers representing the matrix. An integer -1 shows an erased entry of the matrix. All other integers (each of them is between 0 and 109 inclusive) represent filled entries.

Output

If there exists no possible reordering of the columns print -1. Otherwise the output should contain m integers p1, p2, ..., pm showing the sought permutation of columns. So, the first column of the lovely matrix will be p1-th column of the initial matrix, the second column of the lovely matrix will be p2-th column of the initial matrix and so on.

Examples

Input

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

Output

3 1 2

Input

2 3
1 2 2
2 5 4

Output

1 3 2

Input

2 3
1 2 3
3 2 1

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
namespace IO {
const int MAXIOSIZE = 1 << 24 | 1;
unsigned char buf[MAXIOSIZE], *p1, *p2;
template <typename T>
void read(T& x) {
  x = 0;
  char ch =
      (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 24, stdin), p1 == p2)
           ? EOF
           : *p1++);
  bool flg = false;
  for (; ch < '0' || '9' < ch;
       ch = (p1 == p2 &&
                     (p2 = (p1 = buf) + fread(buf, 1, 1 << 24, stdin), p1 == p2)
                 ? EOF
                 : *p1++))
    if (ch == '-') flg |= true;
  for (; '0' <= ch && ch <= '9';
       ch = (p1 == p2 &&
                     (p2 = (p1 = buf) + fread(buf, 1, 1 << 24, stdin), p1 == p2)
                 ? EOF
                 : *p1++))
    x = x * 10 + ch - '0';
  flg ? x = -x : 0;
}
template <typename T>
void out(const T& x) {
  if (x > 9) out(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
inline void write(const T& x, const char& ed = ' ') {
  if (x < 0)
    putchar('-'), out(-x);
  else
    out(x);
  putchar(ed);
}
}  // namespace IO
const int MAXNM = 4e5 + 10;
int n, m, cnt[MAXNM], deg[MAXNM], vis[MAXNM], v_cnt;
vector<int> E[MAXNM], table;
int main() {
  IO::read(n), IO::read(m);
  vector<vector<int> > val(n + 1);
  for (int i = (1), iend = (n); i <= iend; ++i) val[i].resize(m + 1);
  for (int i = (1), iend = (n); i <= iend; ++i) {
    for (int j = (1), jend = (m); j <= jend; ++j) {
      IO::read(val[i][j]);
      if (val[i][j] != -1) table.push_back(val[i][j]);
    }
  }
  sort(table.begin(), table.end());
  table.resize(unique(table.begin(), table.end()) - table.begin());
  for (int i = (1), iend = (n); i <= iend; ++i)
    for (int j = (1), jend = (m); j <= jend; ++j)
      if (val[i][j] != -1)
        val[i][j] = lower_bound(table.begin(), table.end(), val[i][j]) -
                    table.begin() + 1;
  v_cnt = m;
  for (int i = (1), iend = (n); i <= iend; ++i) {
    map<int, int> mp;
    int mxval = 0;
    vector<int> cur;
    for (int j = (1), jend = (m); j <= jend; ++j) {
      if (val[i][j] == -1 || mp.count(val[i][j])) continue;
      mxval = max(mxval, val[i][j]);
      mp[val[i][j]] = ++v_cnt;
    }
    for (int j = (1), jend = (m); j <= jend; ++j) {
      if (val[i][j] == -1) continue;
      cur.push_back(val[i][j]);
    }
    sort(cur.begin(), cur.end());
    cur.resize(unique(cur.begin(), cur.end()) - cur.begin());
    for (int j = (1), jend = (m); j <= jend; ++j) {
      if (val[i][j] == -1 || val[i][j] == mxval) continue;
      auto p = upper_bound(cur.begin(), cur.end(), val[i][j]);
      E[j].push_back(mp[*p]);
      deg[mp[*p]]++;
    }
    for (int j = (1), jend = (m); j <= jend; ++j) {
      if (val[i][j] == -1) continue;
      E[mp[val[i][j]]].push_back(j), deg[j]++;
    }
  }
  vector<int> ans;
  queue<int> q;
  for (int i = (1), iend = (v_cnt); i <= iend; ++i) {
    if (deg[i] == 0) q.push(i), vis[i] = true;
  }
  while (!q.empty()) {
    int u;
    ans.push_back(u = q.front()), q.pop();
    for (int v : E[u]) {
      if (vis[v]) continue;
      deg[v]--;
      if (!vis[v] && deg[v] == 0) q.push(v), vis[v] = true;
    }
  }
  vector<int> debug;
  for (int u : ans)
    if (1 <= u && u <= m) debug.push_back(u);
  if (debug.size() < m) return puts("-1"), 0;
  for (int ccc : debug) IO::write(ccc);
  return 0;
}

```


### Prompt

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

Write a program which prints small/large/equal relation of given two integers a and b.

Constraints

* -1000 ≤ a, b ≤ 1000

Input

Two integers a and b separated by a single space are given in a line.

Output

For given two integers a and b, print

a < b

if a is less than b,

a > b

if a is greater than b, and

a == b

if a equals to b.

Examples

Input

1 2

Output

a

Input

4 3

Output

a > b

Input

5 5

Output

a == b

### Response

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

```


### Prompt

Generate a CPP solution to the following problem:

Ringo has an undirected graph G with N vertices numbered 1,2,...,N and M edges numbered 1,2,...,M. Edge i connects Vertex a_{i} and b_{i} and has a length of w_i.

Now, he is in the middle of painting these N vertices in K colors numbered 1,2,...,K. Vertex i is already painted in Color c_i, except when c_i = 0, in which case Vertex i is not yet painted.

After he paints each vertex that is not yet painted in one of the K colors, he will give G to Snuke.

Based on G, Snuke will make another undirected graph G' with K vertices numbered 1,2,...,K and M edges. Initially, there is no edge in G'. The i-th edge will be added as follows:

* Let x and y be the colors of the two vertices connected by Edge i in G.
* Add an edge of length w_i connecting Vertex x and y in G'.

What is the minimum possible sum of the lengths of the edges in the minimum spanning tree of G'? If G' will not be connected regardless of how Ringo paints the vertices, print -1.

Constraints

* 1 \leq N,M \leq 10^{5}
* 1 \leq K \leq N
* 0 \leq c_i \leq K
* 1 \leq a_i,b_i \leq N
* 1 \leq w_i \leq 10^{9}
* The given graph may NOT be simple or connected.
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N M K
c_1 c_2 ... c_{N}
a_1 b_1 w_1
:
a_M b_M w_M

Output

Print the answer.

Examples

Input

4 3 3
1 0 1 2
1 2 10
2 3 20
2 4 50

Output

60

Input

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

Output

-1

Input

9 12 9
1 2 3 4 5 6 7 8 9
6 9 9
8 9 6
6 7 85
9 5 545631016
2 1 321545
1 6 33562944
7 3 84946329
9 7 15926167
4 7 53386480
5 8 70476
4 6 4549
4 8 8

Output

118901402

Input

18 37 12
5 0 4 10 8 7 2 10 6 0 9 12 12 11 11 11 0 1
17 1 1
11 16 7575
11 15 9
10 10 289938980
5 10 17376
18 4 1866625
8 11 959154208
18 13 200
16 13 2
2 7 982223
12 12 9331
13 12 8861390
14 13 743
2 10 162440
2 4 981849
7 9 1
14 17 2800
2 7 7225452
3 7 85
5 17 4
2 13 1
10 3 45
1 15 973
14 7 56553306
16 17 70476
7 18 9
9 13 27911
18 14 7788322
11 11 8925
9 13 654295
2 10 9
10 1 545631016
3 4 5
17 12 1929
2 11 57
1 5 4
1 17 7807368

Output

171

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod

class UnionFind
{
public:
    vector<int> par;
    vector<int> sz;

    UnionFind(int N){
        par = vector<int>(N);
        REP(i, N) par[i] = i;
        sz = vector<int>(N, 1);
    }

    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;

        if(sz[x] < sz[y]) swap(x, y);

        par[y] = x;
        sz[x] += sz[y];
    }

    bool is_union(int x, int y){
        x = find(x);
        y = find(y);
        return x == y;
    }

    int union_size(int x){
        return sz[find(x)];
    }

};

signed main(){

    int N, M, K; cin >> N >> M >> K;
    vec c(N); readv_m1(c);
    int K0 = K;
    REP(i, N) if(c[i] == -1) c[i] = K0++;

    vec a(M), b(M), w(M);
    vector<PiP> p(M);
    REP(i, M){
        cin >> a[i] >> b[i] >> w[i];
        a[i]--; b[i]--;
        p[i] = PiP(w[i], Pii(a[i], b[i]));
    }
    Sort(p);

    if(K == 1){
        cout << 0 << endl;
        return 0;
    }

    int ans = -1, tmp = 0;
    int t = 0;
    UnionFind UF(K0);
    REP(i, M){
        if(!UF.is_union(c[p[i].s.f], c[p[i].s.s])){
            t++;
            tmp += p[i].f;
            UF.unite(c[p[i].s.f], c[p[i].s.s]);
        }
        if(t >= K - 1){
            ans = tmp;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

```


### Prompt

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

Anu has created her own function f: f(x, y) = (x | y) - y where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR). For example, f(11, 6) = (11|6) - 6 = 15 - 6 = 9. It can be proved that for any nonnegative numbers x and y value of f(x, y) is also nonnegative.

She would like to research more about this function and has created multiple problems for herself. But she isn't able to solve all of them and needs your help. Here is one of these problems.

A value of an array [a_1, a_2, ..., a_n] is defined as f(f(... f(f(a_1, a_2), a_3), ... a_{n-1}), a_n) (see notes). You are given an array with not necessarily distinct elements. How should you reorder its elements so that the value of the array is maximal possible?

Input

The first line contains a single integer n (1 ≤ n ≤ 10^5).

The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9). Elements of the array are not guaranteed to be different.

Output

Output n integers, the reordering of the array with maximum value. If there are multiple answers, print any.

Examples

Input

4
4 0 11 6

Output

11 6 4 0

Input

1
13

Output

13

Note

In the first testcase, value of the array [11, 6, 4, 0] is f(f(f(11, 6), 4), 0) = f(f(9, 4), 0) = f(9, 0) = 9.

[11, 4, 0, 6] is also a valid answer.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int cnt[33];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    for (int b = 30; b >= 0; b--) {
      if ((a[i] >> b) & 1) {
        cnt[b]++;
      }
    }
  }
  int bst_b = 30;
  while (bst_b >= 0 && cnt[bst_b] != 1) {
    bst_b--;
  }
  if (bst_b != -1) {
    for (int i = 1; i <= n; i++) {
      if ((a[i] >> bst_b) & 1) {
        swap(a[i], a[1]);
        break;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    printf("%d ", a[i]);
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Adieu l'ami.

Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around the abandoned Eikou Cram School building, Oshino's makeshift residence.

The space is represented by a rectangular grid of n × m cells, arranged into n rows and m columns. The c-th cell in the r-th row is denoted by (r, c).

Oshino places and removes barriers around rectangular areas of cells. Specifically, an action denoted by "1 r1 c1 r2 c2" means Oshino's placing barriers around a rectangle with two corners being (r1, c1) and (r2, c2) and sides parallel to squares sides. Similarly, "2 r1 c1 r2 c2" means Oshino's removing barriers around the rectangle. Oshino ensures that no barriers staying on the ground share any common points, nor do they intersect with boundaries of the n × m area.

Sometimes Koyomi tries to walk from one cell to another carefully without striding over barriers, in order to avoid damaging various items on the ground. "3 r1 c1 r2 c2" means that Koyomi tries to walk from (r1, c1) to (r2, c2) without crossing barriers.

And you're here to tell Koyomi the feasibility of each of his attempts.

Input

The first line of input contains three space-separated integers n, m and q (1 ≤ n, m ≤ 2 500, 1 ≤ q ≤ 100 000) — the number of rows and columns in the grid, and the total number of Oshino and Koyomi's actions, respectively.

The following q lines each describes an action, containing five space-separated integers t, r1, c1, r2, c2 (1 ≤ t ≤ 3, 1 ≤ r1, r2 ≤ n, 1 ≤ c1, c2 ≤ m) — the type and two coordinates of an action. Additionally, the following holds depending on the value of t:

  * If t = 1: 2 ≤ r1 ≤ r2 ≤ n - 1, 2 ≤ c1 ≤ c2 ≤ m - 1;
  * If t = 2: 2 ≤ r1 ≤ r2 ≤ n - 1, 2 ≤ c1 ≤ c2 ≤ m - 1, the specified group of barriers exist on the ground before the removal.
  * If t = 3: no extra restrictions.

Output

For each of Koyomi's attempts (actions with t = 3), output one line — containing "Yes" (without quotes) if it's feasible, and "No" (without quotes) otherwise.

Examples

Input

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

Output

No
Yes

Input

2500 2500 8
1 549 1279 1263 2189
1 303 795 1888 2432
1 2227 622 2418 1161
3 771 2492 1335 1433
1 2017 2100 2408 2160
3 48 60 798 729
1 347 708 1868 792
3 1940 2080 377 1546

Output

No
Yes
No

Note

For the first example, the situations of Koyomi's actions are illustrated below.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2510;
int n, m, q, vc;
long long fw[N][N];
map<pair<pair<int, int>, pair<int, int> >, long long> hsh;
int lowBit(int k);
void change(int x, int y, long long v);
long long query(int x, int y);
int main() {
  srand(time(NULL));
  scanf("%d%d%d", &n, &m, &q);
  while (q--) {
    int opt, x1, y1, x2, y2;
    scanf("%d%d%d%d%d", &opt, &x1, &y1, &x2, &y2);
    if (opt == 1 || opt == 2) {
      long long v = (rand() << 16) | rand() | ((long long)rand() << 32) |
                    ((long long)rand() << 48);
      if (opt == 1)
        hsh[make_pair(make_pair(x1, y1), make_pair(x2, y2))] = v;
      else
        v = hsh[make_pair(make_pair(x1, y1), make_pair(x2, y2))];
      change(x1, y1, v);
      change(x1, y2 + 1, v);
      change(x2 + 1, y1, v);
      change(x2 + 1, y2 + 1, v);
    } else {
      puts(query(x1, y1) == query(x2, y2) ? "Yes" : "No");
    }
  }
  return 0;
}
int lowBit(int k) { return k & -k; }
void change(int x, int y, long long v) {
  for (int i = x; i <= n; i += lowBit(i))
    for (int j = y; j <= m; j += lowBit(j)) fw[i][j] ^= v;
}
long long query(int x, int y) {
  int ret = 0;
  for (int i = x; i; i -= lowBit(i))
    for (int j = y; j; j -= lowBit(j)) ret ^= fw[i][j];
  return ret;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like.

Constraints

* 2 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print the maximum possible sum of the absolute differences between the adjacent elements after arranging the given integers in a row in any order you like.

Examples

Input

5
6
8
1
2
3

Output

21

Input

6
3
1
4
1
5
9

Output

25

Input

3
5
5
1

Output

8

### Response

```cpp
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
int main(){
  int n;
  cin>>n;
  vector<int> a(n+1,0);
  vector<int> ans(n+1,0);
  rep1(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  ll sum=0;
  if(n%2==0){
    int k=n/2;
    rep(i,k){
      sum+=a[n-i]*2;
      sum-=a[i+1]*2;
    }
    sum-=a[k+1];
    sum+=a[k];
  }
  else{
    int k=n/2;
    ll buf1=0;
    ll buf2=0;
    rep(i,k){
      buf1+=a[n-i]*2;
      buf1-=a[i+1]*2;
      buf2+=a[n-i]*2;
      buf2-=a[i+1]*2;
    }
    buf1+=a[n-k];
    buf1-=a[n-k+1];
    buf2-=a[n-k];
    buf2+=a[n-k-1];
    sum=buf1;
    if(buf1<buf2)sum=buf2;
  }
  cout<<sum<<endl;
  return 0;
}

```


### Prompt

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

This is an easier version of the next problem. In this version, q = 0.

A sequence of integers is called nice if its elements are arranged in blocks like in [3, 3, 3, 4, 1, 1]. Formally, if two elements are equal, everything in between must also be equal.

Let's define difficulty of a sequence as a minimum possible number of elements to change to get a nice sequence. However, if you change at least one element of value x to value y, you must also change all other elements of value x into y as well. For example, for [3, 3, 1, 3, 2, 1, 2] it isn't allowed to change first 1 to 3 and second 1 to 2. You need to leave 1's untouched or change them to the same value.

You are given a sequence of integers a_1, a_2, …, a_n and q updates.

Each update is of form "i x" — change a_i to x. Updates are not independent (the change stays for the future).

Print the difficulty of the initial sequence and of the sequence after every update.

Input

The first line contains integers n and q (1 ≤ n ≤ 200 000, q = 0), the length of the sequence and the number of the updates.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 200 000), the initial sequence.

Each of the following q lines contains integers i_t and x_t (1 ≤ i_t ≤ n, 1 ≤ x_t ≤ 200 000), the position and the new value for this position.

Output

Print q+1 integers, the answer for the initial sequence and the answer after every update.

Examples

Input

5 0
3 7 3 7 3

Output

2

Input

10 0
1 2 1 2 3 1 1 1 50 1

Output

4

Input

6 0
6 6 3 3 4 4

Output

0

Input

7 0
3 3 1 3 2 1 2

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct Tree {
  int mn, mx;
  int val;
  int premx;
  int sufmx;
} T[800010];
int lazy[800010];
Tree operator+(const Tree& A, const Tree& B) {
  Tree ans;
  ans.mn = min(A.mn, B.mn);
  ans.mx = max(A.mx, B.mx);
  if (A.mn == ans.mn) {
    if (B.mn == ans.mn) {
      ans.val = A.val + B.val + max(A.sufmx, B.premx);
      ans.premx = A.premx;
      ans.sufmx = B.sufmx;
    } else {
      ans.val = A.val;
      ans.premx = A.premx;
      ans.sufmx = max(A.sufmx, B.mx);
    }
  } else {
    ans.val = B.val;
    ans.premx = max(A.mx, B.premx);
    ans.sufmx = B.sufmx;
  }
  return ans;
}
void update(int root) {
  T[root] = T[root << 1] + T[root << 1 | 1];
  return;
}
void pushdown(int root) {
  lazy[root << 1] += lazy[root];
  lazy[root << 1 | 1] += lazy[root];
  T[root << 1].mn += lazy[root];
  T[root << 1 | 1].mn += lazy[root];
  lazy[root] = 0;
  return;
}
void build(int root, int l, int r) {
  if (l == r) {
    T[root].mn = -l;
    T[root].mx = 0;
    T[root].premx = 0;
    T[root].sufmx = 0;
    T[root].val = 0;
    return;
  }
  int mid = (l + r) >> 1;
  build(root << 1, l, mid);
  build(root << 1 | 1, mid + 1, r);
  update(root);
  return;
}
void add(int root, int l, int r, int x, int y, int ad) {
  if (x <= l && r <= y) {
    lazy[root] += ad;
    T[root].mn += ad;
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(root);
  if (x <= mid) add(root << 1, l, mid, x, y, ad);
  if (y > mid) add(root << 1 | 1, mid + 1, r, x, y, ad);
  update(root);
  return;
}
void change(int root, int l, int r, int x, int y) {
  if (l == r) {
    T[root].mx = y;
    T[root].premx = y;
    T[root].sufmx = 0;
    T[root].val = 0;
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(root);
  if (x <= mid)
    change(root << 1, l, mid, x, y);
  else
    change(root << 1 | 1, mid + 1, r, x, y);
  update(root);
  return;
}
set<int> S[200010];
int n, q, M;
void Add(int x, int pos) {
  if (S[x].size() == 0)
    M++;
  else {
    int num = *(S[x].begin());
    int cnt = S[x].size();
    add(1, 1, n, num, n, -cnt);
    change(1, 1, n, num, 0);
  }
  S[x].insert(pos);
  int num = *(S[x].begin());
  int cnt = S[x].size();
  add(1, 1, n, num, n, cnt);
  change(1, 1, n, num, cnt);
  return;
}
void Del(int x, int pos) {
  int num = *(S[x].begin());
  int cnt = S[x].size();
  add(1, 1, n, num, n, -cnt);
  change(1, 1, n, num, 0);
  S[x].erase(pos);
  if (S[x].size() == 0)
    M--;
  else {
    num = *(S[x].begin());
    cnt = S[x].size();
    add(1, 1, n, num, n, cnt);
    change(1, 1, n, num, cnt);
  }
  return;
}
int a[200010];
int main() {
  scanf("%d %d", &n, &q);
  build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    Add(a[i], i);
  }
  printf("%d\n", n - T[1].val - T[1].premx);
  for (int i = 1; i <= q; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    Del(a[x], x);
    a[x] = y;
    Add(a[x], x);
    printf("%d\n", n - T[1].val - T[1].premx);
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Guy-Manuel and Thomas are going to build a polygon spaceship.

You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of the translation:

<image>

Define T as a set of points which is the union of all P(x,y) such that the origin (0,0) lies in P(x,y) (both strictly inside and on the boundary). There is also an equivalent definition: a point (x,y) lies in T only if there are two points A,B in P such that \overrightarrow {AB} = \overrightarrow {(x,y)}. One can prove T is a polygon too. For example, if P is a regular triangle then T is a regular hexagon. At the picture below P is drawn in black and some P(x,y) which contain the origin are drawn in colored:

<image>

The spaceship has the best aerodynamic performance if P and T are similar. Your task is to check whether the polygons P and T are [similar](https://tinyurl.com/vp5m7vl).

Input

The first line of input will contain a single integer n (3 ≤ n ≤ 10^5) — the number of points.

The i-th of the next n lines contains two integers x_i, y_i (|x_i|, |y_i| ≤ 10^9), denoting the coordinates of the i-th vertex.

It is guaranteed that these points are listed in counterclockwise order and these points form a strictly convex polygon.

Output

Output "YES" in a separate line, if P and T are similar. Otherwise, output "NO" in a separate line. You can print each letter in any case (upper or lower).

Examples

Input

4
1 0
4 1
3 4
0 3

Output

YES

Input

3
100 86
50 0
150 0

Output

nO

Input

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

Output

YES

Note

The following image shows the first sample: both P and T are squares. The second sample was shown in the statements.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const double eps = 1e-10;
const int maxn = 1e5 + 10;
pair<long long, long long> p[2 * maxn];
pair<long long, long long> ans, t;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i].first >> p[i].second;
    p[i].first *= 2;
    p[i].second *= 2;
  }
  if (n & 1) {
    printf("NO\n");
    return 0;
  }
  long long tt = n >> 1;
  t = make_pair((p[1 + tt].first + p[1].first) / 2,
                (p[1 + tt].second + p[1].second) / 2);
  for (int i = 1; i <= n / 2; i++) {
    ans = make_pair((p[i + tt].first + p[i].first) / 2,
                    (p[i + tt].second + p[i].second) / 2);
    if (t.first != ans.first || t.second != ans.second) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}

```


### Prompt

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

You are given an array a consisting of n integers (it is guaranteed that n is even, i.e. divisible by 2). All a_i does not exceed some integer k.

Your task is to replace the minimum number of elements (replacement is the following operation: choose some index i from 1 to n and replace a_i with some integer in range [1; k]) to satisfy the following conditions:

  * after all replacements, all a_i are positive integers not greater than k;
  * for all i from 1 to n/2 the following equation is true: a_i + a_{n - i + 1} = x, where x should be the same for all n/2 pairs of elements.

You have to answer t independent test cases.

Input

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

The first line of the test case contains two integers n and k (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 2 ⋅ 10^5) — the length of a and the maximum possible value of some a_i correspondingly. It is guratanteed that n is even (i.e. divisible by 2). The second line of the test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ k), where a_i is the i-th element of a.

It is guaranteed that the sum of n (as well as the sum of k) over all test cases does not exceed 2 ⋅ 10^5 (∑ n ≤ 2 ⋅ 10^5, ∑ k ≤ 2 ⋅ 10^5).

Output

For each test case, print the answer — the minimum number of elements you have to replace in a to satisfy the conditions from the problem statement.

Example

Input

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

Output

0
1
4
2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 10;
const int M = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int a[N], d[N * 2];
void solve() {
  int n, k;
  cin >> n >> k;
  for (long long i = 0; i < 2 * k + 10; i++) d[i] = 0;
  for (long long i = 1; i < n + 1; i++) cin >> a[i];
  int Min = 1e9 + 7, Max = 0;
  for (long long i = 1; i < n / 2 + 1; i++) {
    int sum = a[i] + a[n - i + 1];
    Min = min(a[i], a[n - i + 1]);
    Max = max(a[i], a[n - i + 1]);
    d[2] += 2;
    d[Min + 1]--;
    d[Max + k + 1]++;
    d[sum]--;
    d[sum + 1]++;
  }
  int ans = d[2];
  for (long long i = 3; i < 2 * k + 1; i++) {
    d[i] += d[i - 1];
    ans = min(ans, d[i]);
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

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

Given are a positive integer N and a string S of length N consisting of lowercase English letters.

Determine whether the string is a concatenation of two copies of some string. That is, determine whether there is a string T such that S = T + T.

Constraints

* 1 \leq N \leq 100
* S consists of lowercase English letters.
* |S| = N

Input

Input is given from Standard Input in the following format:

N
S

Output

If S is a concatenation of two copies of some string, print `Yes`; otherwise, print `No`.

Examples

Input

6
abcabc

Output

Yes

Input

6
abcadc

Output

No

Input

1
z

Output

No

### Response

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

int main() {
  int N;
  string S;

  cin >> N >> S;

  string T = S.substr(0, S.size() / 2);

  if (S == T + T) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }

  return 0;
}
```


### Prompt

Generate a cpp solution to the following problem:

In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.

For example, for n = 4 the sum is equal to  - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively.

Calculate the answer for t values of n.

Input

The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed.

Each of next t lines contains a single integer n (1 ≤ n ≤ 109).

Output

Print the requested sum for each of t integers n given in the input.

Examples

Input

2
4
1000000000

Output

-4
499999998352516354

Note

The answer for the first sample is explained in the statement.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    cout << n * (n + 1) / 2 - 2 * ((1 << ((int)log2(n) + 1)) - 1) << endl;
  }
}

```


### Prompt

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

Peterson loves to learn new languages, but his favorite hobby is making new ones. Language is a set of words, and word is a sequence of lowercase Latin letters.

Peterson makes new language every morning. It is difficult task to store the whole language, so Peterson have invented new data structure for storing his languages which is called broom. Broom is rooted tree with edges marked with letters. Initially broom is represented by the only vertex — the root of the broom. When Peterson wants to add new word to the language he stands at the root and processes the letters of new word one by one. Consider that Peterson stands at the vertex u. If there is an edge from u marked with current letter, Peterson goes through this edge. Otherwise Peterson adds new edge from u to the new vertex v, marks it with the current letter and goes through the new edge. Size of broom is the number of vertices in it.

In the evening after working day Peterson can't understand the language he made this morning. It is too difficult for bored Peterson and he tries to make it simpler. Simplification of the language is the process of erasing some letters from some words of this language. Formally, Peterson takes some positive integer p and erases p-th letter from all the words of this language having length at least p. Letters in words are indexed starting by 1. Peterson considers that simplification should change at least one word, i.e. there has to be at least one word of length at least p. Peterson tries to make his language as simple as possible, so he wants to choose p such that the size of the broom for his simplified language is as small as possible.

Peterson is pretty annoyed with this task so he asks you for help. Write a program to find the smallest possible size of the broom and integer p.

Input

The first line of input contains integer n (2 ≤ n ≤ 3·105) — the size of the broom.

Next n - 1 lines describe the broom: i-th of them contains integers ui, vi and letter xi — describing the edge from ui to vi marked with letter xi.

Vertices are numbered from 1 to n. All xi are lowercase latin letters. Vertex 1 is the root of the broom.

Edges describe correct broom which is made from Peterson's language.

Output

The first line of output should contain the minimum possible size of the broom after its simplification. The second line of output should contain integer p to choose. If there are several suitable p values, print the smallest one.

Examples

Input

5
1 2 c
2 3 a
3 4 t
2 5 t

Output

3
2

Input

16
1 2 o
2 3 f
1 4 p
4 5 i
5 6 e
6 7 c
7 8 e
4 9 r
9 10 e
10 11 t
11 12 t
12 13 y
10 14 f
14 15 i
15 16 x

Output

12
2

Note

<image>

Broom from the second sample test can be built using language "piece", "of", "pie", "pretty", "prefix". Its simplification with p = 2 obtains the language of words "pece", "o", "pe", "petty", "pefix". This language gives us the broom with minimum possible size.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long COEF = 29;
const long long COEF1 = 29;
const long long COEF2 = 29;
const long long MODULO1 = 1000000007;
const long long MODULO2 = 1000000009;
const int N = 300007;
long long COEF_INV1, COEF_INV2;
long long powMod(long long x, long long y, long long MODULO) {
  long long z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = z * x % MODULO;
    x = x * x % MODULO;
  }
  return z;
}
long long inv1(long long x) { return powMod(x, MODULO1 - 2, MODULO1); }
long long inv2(long long x) { return powMod(x, MODULO2 - 2, MODULO2); }
struct Set {
  set<pair<long long, long long>> values;
  long long coef1, coefInv1, delta1;
  long long coef2, coefInv2, delta2;
  Set() {
    coef1 = coefInv1 = 1;
    coef2 = coefInv2 = 1;
    delta1 = delta2 = 0;
  }
  void addBack(int c) {
    coef1 = coef1 * COEF % MODULO1;
    coefInv1 = coefInv1 * COEF_INV1 % MODULO1;
    delta1 = (delta1 * COEF1 + c) % MODULO1;
    coef2 = coef2 * COEF % MODULO2;
    coefInv2 = coefInv2 * COEF_INV2 % MODULO2;
    delta2 = (delta2 * COEF2 + c) % MODULO2;
  }
  void addInto(pair<long long, long long> value) {
    long long norm1 = (value.first - delta1) * coefInv1 % MODULO1;
    if (norm1 < 0) {
      norm1 += MODULO1;
    }
    long long norm2 = (value.second - delta2) * coefInv2 % MODULO2;
    if (norm2 < 0) {
      norm2 += MODULO2;
    }
    values.insert(make_pair(norm1, norm2));
  }
  bool contains(pair<long long, long long> value) {
    long long norm1 = (value.first - delta1) * coefInv1 % MODULO1;
    if (norm1 < 0) {
      norm1 += MODULO1;
    }
    long long norm2 = (value.second - delta2) * coefInv2 % MODULO2;
    if (norm2 < 0) {
      norm2 += MODULO2;
    }
    return values.find(make_pair(norm1, norm2)) != values.end();
  }
} nodes[N];
int root[N];
vector<pair<int, int>> edge[N];
int mergeSets(int u, int v) {
  if (nodes[u].values.size() < nodes[v].values.size()) {
    swap(u, v);
  }
  for (__typeof(nodes[v].values.begin()) it = nodes[v].values.begin();
       it != nodes[v].values.end(); it++) {
    long long norm1 = (it->first * nodes[v].coef1 + nodes[v].delta1) % MODULO1;
    long long norm2 = (it->second * nodes[v].coef2 + nodes[v].delta2) % MODULO2;
    nodes[u].addInto(make_pair(norm1, norm2));
  }
  return u;
}
int answers[N];
set<pair<long long, long long>> addition;
void dfs(int x, int fa, int level) {
  root[x] = x;
  nodes[x].values.insert(make_pair(0LL, 0LL));
  vector<pair<int, int>> children;
  for (__typeof(edge[x].begin()) it = edge[x].begin(); it != edge[x].end();
       it++) {
    if (it->first == fa) {
      continue;
    }
    children.push_back(make_pair(it->first, it->second));
    dfs(it->first, x, level + 1);
  }
  sort(children.begin(), children.end(),
       [&](pair<int, int> a, pair<int, int> b) {
         return nodes[root[a.first]].values.size() >
                nodes[root[b.first]].values.size();
       });
  if (children.size() > 0) {
    int step = 1;
    addition.clear();
    auto& firstChildSet = nodes[root[children[0].first]];
    for (int i = 1; i < children.size(); ++i) {
      int v = root[children[i].first];
      for (__typeof(nodes[v].values.begin()) it = nodes[v].values.begin();
           it != nodes[v].values.end(); it++) {
        long long norm1 =
            (it->first * nodes[v].coef1 + nodes[v].delta1) % MODULO1;
        long long norm2 =
            (it->second * nodes[v].coef2 + nodes[v].delta2) % MODULO2;
        if (addition.find(make_pair(norm1, norm2)) == addition.end() &&
            !firstChildSet.contains(make_pair(norm1, norm2))) {
          addition.insert(make_pair(norm1, norm2));
        } else {
          ++step;
        }
      }
    }
    answers[level] += step;
    for (auto child : children) {
      nodes[root[child.first]].addBack(child.second);
      root[x] = mergeSets(root[x], root[child.first]);
    }
  }
}
int main() {
  COEF_INV1 = inv1(COEF);
  COEF_INV2 = inv2(COEF);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    static char ch[10];
    scanf("%d%d%s", &u, &v, ch);
    --u;
    --v;
    edge[u].push_back(make_pair(v, ch[0] - 'a' + 1));
    edge[v].push_back(make_pair(u, ch[0] - 'a' + 1));
  }
  dfs(0, -1, 0);
  int answer = -1;
  int answerAt = -1;
  for (int i = 0; i < n + 1; i++) {
    if (answer == -1 || answers[i] > answer) {
      answer = answers[i];
      answerAt = i;
    }
  }
  cout << n - answer << endl << 1 + answerAt << endl;
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Given is a directed graph G with N vertices and M edges.
The vertices are numbered 1 to N, and the i-th edge is directed from Vertex A_i to Vertex B_i.
It is guaranteed that the graph contains no self-loops or multiple edges.

Determine whether there exists an induced subgraph (see Notes) of G such that the in-degree and out-degree of every vertex are both 1. If the answer is yes, show one such subgraph.
Here the null graph is not considered as a subgraph.

Constraints

* 1 \leq N \leq 1000
* 0 \leq M \leq 2000
* 1 \leq A_i,B_i \leq N
* A_i \neq B_i
* All pairs (A_i, B_i) are distinct.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
:
A_M B_M

Output

If there is no induced subgraph of G that satisfies the condition, print `-1`. Otherwise, print an induced subgraph of G that satisfies the condition, in the following format:

K
v_1
v_2
:
v_K

This represents the induced subgraph of G with K vertices whose vertex set is \\{v_1, v_2, \ldots, v_K\\}. (The order of v_1, v_2, \ldots, v_K does not matter.) If there are multiple subgraphs of G that satisfy the condition, printing any of them is accepted.

Examples

Input

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

Output

3
1
2
4

Input

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

Output

-1

Input

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

Output

4
2
3
4
5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN=2010;
int n,m,x,y,eg,len,pa,pb,hd[2][MAXN],ver[2][MAXN*2],nx[2][MAXN*2],vis[MAXN],dis[MAXN],las[MAXN];
void add_edge (int t,int x,int y) {
	ver[t][++eg]=y;
	nx[t][eg]=hd[t][x];
	hd[t][x]=eg;
	return;
}
void dij (int x) {
	memset(dis,0x3f,sizeof(dis));
	memset(vis,0,sizeof(vis));
	memset(las,0,sizeof(las));
	dis[x]=0,vis[x]=1;
	queue <int> q;
	q.push(x);
	while (!q.empty()) {
		int a=q.front();
		q.pop();
		for (int i=hd[0][a];i;i=nx[0][i]) {
			if (!vis[ver[0][i]]) {
				dis[ver[0][i]]=dis[a]+1,las[ver[0][i]]=a;
				vis[ver[0][i]]=1;
				q.push(ver[0][i]);
			}
		}
	}
	return;
}
int main () {
	scanf("%d%d",&n,&m);
	len=n+1;
	for (int i=1;i<=m;i++) {
		scanf("%d%d",&x,&y);
		add_edge(0,x,y),add_edge(1,y,x);
	}
	for (int i=1;i<=n;i++) {
		dij(i);
		for (int j=hd[1][i];j;j=nx[1][j]) {
			if (dis[ver[1][j]]+1<len) {
				len=dis[ver[1][j]]+1,pa=i,pb=ver[1][j];
			}
		}
	}
	if (len==n+1) {
		printf("-1\n");
	}
	else {
		dij(pa);
		printf("%d\n%d\n",len,pa);
		while (pb!=pa) {
			printf("%d\n",pb);
			pb=las[pb];
		}
	}
	return 0;
}
```


### Prompt

Develop a solution in cpp to the problem described below:

You are given an integer sequence a of length N. How many permutations p of the integers 1 through N satisfy the following condition?

* For each 1 ≤ i ≤ N, at least one of the following holds: p_i = a_i and p_{p_i} = a_i.

Find the count modulo 10^9 + 7.

Constraints

* 1 ≤ N ≤ 10^5
* a_i is an integer.
* 1 ≤ a_i ≤ N

Input

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

N
a_1 a_2 ... a_N

Output

Print the number of the permutations p that satisfy the condition, modulo 10^9 + 7.

Examples

Input

3
1 2 3

Output

4

Input

2
1 1

Output

1

Input

3
2 1 1

Output

2

Input

3
1 1 1

Output

0

Input

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

Output

6

### Response

```cpp
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
int inn[1000100],a[1000100],num[1000100],wei[1000100],mp[1000100],f[1000100];
bool vis[1000100];
int work(int l,int n)
{
	f[0]=1;f[1]=1+(l&1)-(l==1);
	for (int i=2;i<=n;i++)
		f[i]=((1+(l&1)-(l==1))*f[i-1]+(long long)l*(i-1)%mo*f[i-2])%mo;
	return f[n];
}
int main()
{
	//freopen("in.txt","r",stdin);
	int n;scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);inn[a[i]]++;
		if (inn[a[i]]>2) {printf("0\n");return 0;}
	}
	for (int i=1;i<=n;i++) if (!inn[i])
	{
		int js=0,now=i;
		while (inn[now]!=2) {vis[now]=true;now=a[now];js++;}
		num[now]=js;//cerr<<now<<' '<<js<<endl;
	}
	int ans=1;
	for (int i=1;i<=n;i++) if (!vis[i])
	{
		int len=0,now=i;
		while (!vis[now]) {wei[++len]=now;vis[now]=true;now=a[now];}//cerr<<len<<endl;
		if (i!=now) {printf("0\n");return 0;}
		int lst=1;for (int j=1;j<=len;j++) if (num[wei[j]]) lst=j-len;cerr<<lst<<endl;
		if (lst==1) {mp[len]++;continue;}
		for (int j=1;j<=len;j++) if (num[wei[j]])
		{
			if (j-lst>num[wei[j]]) ans=ans*2%mo;
			if (j-lst<num[wei[j]]) {printf("0\n");return 0;}
			lst=j;
		}
	}
	for (int i=1;i<=n;i++) if (mp[i]) ans=(long long)ans*work(i,mp[i])%mo;
	printf("%d\n",ans);
}
```


### Prompt

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

You are given an array of n integer numbers a0, a1, ..., an - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.

Input

The first line contains positive integer n (2 ≤ n ≤ 105) — size of the given array. The second line contains n integers a0, a1, ..., an - 1 (1 ≤ ai ≤ 109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times.

Output

Print the only number — distance between two nearest minimums in the array.

Examples

Input

2
3 3

Output

1

Input

3
5 6 5

Output

2

Input

9
2 1 3 5 4 1 2 3 1

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a, b = 1, ans = 0x7fffffff, seg[100010], n;
vector<int> g;
int main() {
  cin >> n;
  a = n, b = 1;
  for (int i = 1; i <= n; i++) cin >> seg[i];
  for (int i = 1; i <= n; i++) {
    if (seg[i] < ans) ans = seg[i];
  }
  for (int i = 1; i <= n; i++) {
    if (seg[i] == ans) {
      g.push_back(i);
    }
  }
  ans = 0x7fffffff;
  for (int i = 1; i < g.size(); i++) {
    ans = min(ans, g[i] - g[i - 1]);
  }
  cout << ans;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Create a program that inputs the vertex information of two polygons inscribed in one circle and outputs the magnitude relationship of their areas.

Assume that each vertex of the X-side is numbered counterclockwise from 1 to X (the figure shows an example when X = 4). However, the given polygon assumes that the center of the circle is contained inside, and the data on the position of vertex i is the angle v (1 ≤ v <180) of the central angle measured counterclockwise from vertex i to vertex i + 1. Integer). Regarding the magnitude relationship to be output, 1 (half-width number) when the area of the first polygon is large, 2 (half-width number) when the area of the second polygon is large, and when the areas are the same, Please output 0 (half-width number).

<image>

Input

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

m
v1
v2
::
vm −1
n
v1
v2
::
vn − 1

The first line gives the number of vertices of the first polygon m (3 ≤ m ≤ 50), and the following m − 1 line gives the information vi (1 ≤ vi <180) of the vertices i of the first polygon. ..

The following line gives the number of vertices n (3 ≤ n ≤ 50) of the second polygon, and the following n − 1 line gives the information vi (1 ≤ vi <180) for the vertices i of the second polygon.

The number of datasets does not exceed 200.

Output

Outputs the magnitude relationship (half-width numbers) for each data set on one line.

Example

Input

4
30
125
75
4
30
125
75
5
30
125
75
65
4
30
125
75
4
30
125
75
6
30
50
50
25
75
0

Output

0
1
2

### Response

```cpp
#include <iostream>
#include <complex>
#include <math.h>
#include <vector>
#include <stdio.h>

/*   #include <complex>
complex p(0.0, 0.0);   // 初期化
    // 演算  p + q, p - q, p * 2.0
    // リテラル  complex(1.0, 1.0)
    // リテラル(極座標)  polar(r, a)  長さr, x軸となす角a
	// なす角  angle(p)  pとx軸のなす角
	// なす角  angle(p / q)  pとqのなす角
p.real() = 2.0;
p.imag() = 1.0;   // x, y座標

    // 長さ  abs(p), norm(p)
	// ベクトル回転  p * polar(1.0, M_PI / 2)
*/

using namespace std;

typedef complex<double> Point;    // 座標型

// 座標ソート
bool xycomp(const Point &a, const Point &b){
	if(a.real() != b.real())
		return a.real() < b.real();
	return a.imag() < b.imag();
}

// 偏角と長さでソート
bool argcomp(const Point &a, const Point &b){
	double aa = arg(a) < 0.0 ? 2 * M_PI - arg(a) : arg(a);
	double bb = arg(b) < 0.0 ? 2 * M_PI - arg(b) : arg(b);
	if(aa != bb)
		return aa < bb;
	return abs(a) < abs(b);
}

double dot(Point a, Point b){     // 内積
	return real(conj(a) * b);
}

double cross(Point a, Point b){   // 外積  |a||b|sinθ
	return imag(conj(a) * b);
}

// 三角形の面積  ||v||u|sinθ/ 2| = abs(cross(v, u) / 2)

    // 多角形の面積
double area(vector<Point> poly){    //poly[] 多角形の頂点
	int n = poly.size();
	double a = 0.0;

	for(int i = 0; i < n; i++){

		a += cross(poly[i], poly[(i + 1)%n]) / 2;
	}

	return abs(a);
}

/*   // 多角形の外接円
Point circumcircle(Point poly[]){
	Point c = Point(0.0, 0.0);
	double ratio = 0.5;

	for(int k = 0; k = 100; k++){
		for(int i = 0; i < 100; i++){
			Point p = ;// 一番離れている点
			c += (p - c) * ratio;
		}
		ratio *= 0.5;
	}
	return c;
}
*/

int main(){
	while(1){
		int m;
		cin >> m;
		if(m == 0)
			break;

		vector<int> v1(m);
		for(int i = 0; i < m-1; i++)
			cin >> v1[i];

		int n;
		cin >> n;

		vector<int> v2(n);
		for(int i = 0; i < n-1; i++)
			cin >> v2[i];

		vector<Point> p1(m);

		p1[0] = Point(1.0, 0);

		for(int i = 1, j =0; i < m; i++){
			j += v1[i - 1];
			p1[i] = polar(1.0, j * M_PI / 180);
		}

		double s1 = area(p1);

		vector<Point> p2(n);

		p2[0] = Point(1.0, 0);

		for(int i = 1, j =0; i < n; i++){
			j += v2[i - 1];
			p2[i] = polar(1.0, j * M_PI / 180);
		}

		double s2 = area(p2);

		if(s1 == s2)
			puts("0");
		else if(s1 > s2)
			puts("1");
		else
			puts("2");
	}

	return 0;
}
```


### Prompt

Construct a cpp code solution to the problem outlined:

We have a grid with N rows and M columns of squares. Initially, all the squares are white.

There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attached to a column is pressed, the colors of all the squares in that column are inverted.

Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.

Constraints

* 1 \leq N,M \leq 1000
* 0 \leq K \leq NM

Input

Input is given from Standard Input in the following format:

N M K

Output

If Takahashi can have exactly K black squares in the grid, print `Yes`; otherwise, print `No`.

Examples

Input

2 2 2

Output

Yes

Input

2 2 1

Output

No

Input

3 5 8

Output

Yes

Input

7 9 20

Output

No

### Response

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int h,w,k; scanf("%d%d%d",&h,&w,&k);
	rep(i,h+1) rep(j,w+1) if(i*(w-j)+j*(h-i)==k) return puts("Yes"),0;
	puts("No");
	return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

BerDonalds, a well-known fast food restaurant, is going to open a cafe in Bertown. The important thing is to choose the new restaurant's location so that it would be easy to get there. The Bertown road system is represented by n junctions, connected by m bidirectional roads. For each road we know its length. We also know that we can get from any junction to any other one, moving along the roads.

Your task is to find such location of the restaurant, that the shortest distance along the roads from the cafe to the farthest junction would be minimum. Note that the restaurant can be located not only on the junction, but at any point of any road.

Input

The first line contains two integers n and m (<image>) — the number of junctions and the number of roads, correspondingly. Then m lines follow, describing all Bertown roads. Each road is described by three integers ai, bi, wi (1 ≤ ai, bi ≤ n, ai ≠ bi; 1 ≤ wi ≤ 105), where ai and bi are the numbers of the junctions, connected by the i-th road, and wi is the length of the i-th road.

It is guaranteed that each road connects two distinct junctions, there is at most one road between any two junctions, and you can get from any junction to any other one.

Output

Print a single real number — the shortest distance from the optimal restaurant location to the farthest junction. The answer will be considered correct, if its absolute or relative error doesn't exceed 10 - 9.

Examples

Input

2 1
1 2 1

Output

0.50

Input

3 3
1 2 1
2 3 1
1 3 1

Output

1.00

Input

3 2
1 2 100
2 3 1

Output

50.50

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = 205;
const double oo = 1e99;
int N, M;
pair<int, int> E[MAX * MAX];
double mat[MAX][MAX], adj[MAX][MAX];
pair<double, double> R[MAX];
void init() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)
      if (i != j) adj[i][j] = mat[i][j] = oo;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    cin >> mat[E[i].first = a][E[i].second = b];
    mat[b][a] = mat[a][b];
    adj[b][a] = adj[a][b] = mat[a][b];
  }
  for (int k = 1; k <= N; k++)
    for (int i = 1; i <= N; i++)
      for (int j = 1; j <= N; j++)
        mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
}
double process(int u, int v) {
  double ans = oo;
  double d = adj[u][v];
  for (int w = 1; w <= N; w++) {
    R[w] = make_pair(-mat[u][w], mat[v][w] + d);
  }
  sort(R + 1, R + N + 1);
  double m0 = -oo, md = -oo, my = -oo;
  for (int i = 1; i <= N; i++) {
    if (i > 1 && R[i].second > my) {
      double x = (my + R[i].first) / 2;
      double y = x - R[i].first;
      ans = min(ans, y);
    }
    m0 = max(m0, -R[i].first);
    md = max(md, R[i].second - d);
    my = max(my, R[i].second);
  }
  ans = min(ans, m0);
  ans = min(ans, md);
  return ans;
}
int main() {
  init();
  double ans = oo;
  for (int i = 0; i < M; i++) {
    double tmp = process(E[i].first, E[i].second);
    ans = min(ans, tmp);
  }
  printf("%.2f\n", ans + 1 - 1);
  return 0;
}

```


### Prompt

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

Alice and Bob are well-known for sending messages to each other. This time you have a rooted tree with Bob standing in the root node and copies of Alice standing in each of the other vertices. The root node has number 0, the rest are numbered 1 through n.

At some moments of time some copies of Alice want to send a message to Bob and receive an answer. We will call this copy the initiator. The process of sending a message contains several steps:

  * The initiator sends the message to the person standing in the parent node and begins waiting for the answer.
  * When some copy of Alice receives a message from some of her children nodes, she sends the message to the person standing in the parent node and begins waiting for the answer.
  * When Bob receives a message from some of his child nodes, he immediately sends the answer to the child node where the message came from.
  * When some copy of Alice (except for initiator) receives an answer she is waiting for, she immediately sends it to the child vertex where the message came from.
  * When the initiator receives the answer she is waiting for, she doesn't send it to anybody.
  * There is a special case: a copy of Alice can't wait for two answers at the same time, so if some copy of Alice receives a message from her child node while she already waits for some answer, she rejects the message and sends a message saying this back to the child node where the message came from. Then the copy of Alice in the child vertex processes this answer as if it was from Bob.
  * The process of sending a message to a parent node or to a child node is instant but a receiver (a parent or a child) gets a message after 1 second.

If some copy of Alice receives several messages from child nodes at the same moment while she isn't waiting for an answer, she processes the message from the initiator with the smallest number and rejects all the rest. If some copy of Alice receives messages from children nodes and also receives the answer she is waiting for at the same instant, then Alice first processes the answer, then immediately continue as normal with the incoming messages.

You are given the moments of time when some copy of Alice becomes the initiator and sends a message to Bob. For each message, find the moment of time when the answer (either from Bob or some copy of Alice) will be received by the initiator.

You can assume that if Alice wants to send a message (i.e. become the initiator) while waiting for some answer, she immediately rejects the message and receives an answer from herself in no time.

Input

The first line of input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of nodes with Alices and the number of messages.

Second line contains n integers p1, p2, ..., pn (0 ≤ pi < i). The integer pi is the number of the parent node of node i.

The next m lines describe the messages. The i-th of them contains two integers xi and ti (1 ≤ xi ≤ n, 1 ≤ ti ≤ 109) — the number of the vertex of the initiator of the i-th message and the time of the initiation (in seconds). The messages are given in order of increasing initiation time (i.e. ti + 1 ≥ ti holds for 1 ≤ i < m). The pairs (xi, ti) are distinct.

Output

Print m integers — the i-th of them is the moment of time when the answer for the i-th message will be received by the initiator.

Examples

Input

6 3
0 1 2 3 2 5
4 6
6 9
5 11

Output

14 13 11

Input

3 2
0 1 1
2 1
3 1

Output

5 3

Input

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

Output

7 6 11

Note

In the first example the first message is initiated at the moment 6, reaches Bob at the moment 10, and the answer reaches the initiator at the moment 14. The second message reaches vertex 2 at the moment 11. At this moment the copy of Alice in this vertex is still waiting for the answer for the first message, so she rejects the second message. The answer reaches the initiator at the moment 13. The third message is not sent at all, because at the moment 11 Alice in vertex 5 is waiting for the answer for the second message.

In the second example the first message reaches Bob, the second is rejected by Alice in vertex 1. This is because the message with smaller initiator number has the priority.

In the third example the first and the third messages reach Bob, while the second message is rejected by Alice in vertex 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int head[200010], nxt[200010], a[200010], edge, dep[200010], size[200010],
    son[200010], mx_dep[800010];
int now, id[200010], top[200010], mx[800010], x[200010], y[200010], res[200010],
    yuan[200010], tag[800010], n;
int father[200010], que[200010];
int read() {
  int tmp = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    tmp = tmp * 10 + c - '0';
    c = getchar();
  }
  return tmp;
}
bool cmp(int a, int b) {
  int t1 = y[a] + dep[x[a]], t2 = y[b] + dep[x[b]];
  if (t1 == t2)
    return x[a] < x[b];
  else
    return t1 < t2;
}
void create(int u, int v) {
  edge++;
  a[edge] = v;
  nxt[edge] = head[u];
  head[u] = edge;
}
void dfs(int u) {
  size[u] = 1;
  int mx = 0;
  for (int i = head[u]; i; i = nxt[i]) {
    int v = a[i];
    dep[v] = dep[u] + 1;
    dfs(v);
    size[u] += size[v];
    if (size[v] > mx) {
      mx = size[v];
      son[u] = v;
    }
  }
}
void connect(int u, int ancient) {
  top[u] = ancient;
  id[u] = ++now;
  yuan[now] = u;
  if (son[u]) connect(son[u], ancient);
  for (int i = head[u]; i; i = nxt[i]) {
    int v = a[i];
    if (v != son[u]) connect(v, v);
  }
}
void build(int now, int l, int r) {
  tag[now] = 2000000000;
  if (l == r) {
    mx_dep[now] = dep[yuan[l]];
    if (l == 1)
      mx[now] = 2147483647;
    else
      mx[now] = dep[yuan[l]];
    return;
  }
  int mid = (l + r) / 2;
  build(now * 2, l, mid);
  build(now * 2 + 1, mid + 1, r);
  mx[now] = max(mx[now * 2], mx[now * 2 + 1]);
  mx_dep[now] = max(mx_dep[now * 2], mx_dep[now * 2 + 1]);
}
void pushdown(int now) {
  if (tag[now] != 2000000000) {
    int x = tag[now];
    tag[now] = 2000000000;
    tag[now * 2] = tag[now * 2 + 1] = x;
    mx[now * 2] = x + 2 * mx_dep[now * 2];
    mx[now * 2 + 1] = x + 2 * mx_dep[now * 2 + 1];
  }
}
int query(int now, int l, int r, int left, int right, int x) {
  if (l != r)
    pushdown(now);
  else if (mx[now] >= x)
    return yuan[l];
  else
    return -1;
  int mid = (l + r) / 2;
  if (l == left && r == right) {
    if (mx[now] < x) return -1;
    int tmp = query(now * 2 + 1, mid + 1, r, mid + 1, r, x);
    if (tmp != -1) return tmp;
    tmp = query(now * 2, l, mid, l, mid, x);
    return tmp;
  }
  int tmp = -1;
  if (right >= mid + 1)
    tmp = query(now * 2 + 1, mid + 1, r, max(left, mid + 1), right, x);
  if (tmp != -1) return tmp;
  if (left <= mid) tmp = query(now * 2, l, mid, left, min(right, mid), x);
  return tmp;
}
void modify(int now, int l, int r, int left, int right, int x) {
  if (l == left && r == right) {
    tag[now] = x;
    mx[now] = x + 2 * mx_dep[now];
    return;
  }
  pushdown(now);
  int mid = (l + r) / 2;
  if (left <= mid) modify(now * 2, l, mid, left, min(right, mid), x);
  if (right >= mid + 1)
    modify(now * 2 + 1, mid + 1, r, max(left, mid + 1), right, x);
  mx[now] = max(mx[now * 2], mx[now * 2 + 1]);
}
int get_node(int x, int t) {
  int val = t + dep[x];
  while (true) {
    int tmp = query(1, 1, n + 1, id[top[x]], id[x], val);
    if (tmp != -1) return tmp;
    x = father[top[x]];
  }
}
int solve(int x, int t) {
  int tmp = get_node(x, t), ans = t + 2 * (dep[x] - dep[tmp]), val;
  val = ans - 1 - dep[x];
  while (top[x] != top[tmp]) {
    modify(1, 1, n + 1, id[top[x]], id[x], val);
    x = father[top[x]];
  }
  if (x != tmp) modify(1, 1, n + 1, id[tmp] + 1, id[x], val);
  return ans;
}
int main() {
  n = read();
  int m = read();
  for (int i = 1; i <= n; i++) {
    int x = read();
    father[i] = x;
    create(x, i);
  }
  dep[0] = 1;
  dfs(0);
  connect(0, 0);
  build(1, 1, n + 1);
  for (int i = 1; i <= m; i++) {
    x[i] = read();
    y[i] = read();
    que[i] = i;
  }
  sort(que + 1, que + m + 1, cmp);
  for (int i = 1; i <= m; i++) res[que[i]] = solve(x[que[i]], y[que[i]]);
  for (int i = 1; i <= m; i++) printf("%d ", res[i]);
  puts("");
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

C: Acrophobia

Yayoi Takasugi is a super-selling idol. There is one thing she is not good at. It's a high place ... She is extremely afraid of heights. This time, due to the producer's inadequacy, she decided to take on the following challenges on a variety show.

This location will be held in a room in a ninja mansion. The floor of this room is lined with square tiles, and some tiles have fallen out to form holes. If you fall through this hole, you will find yourself in a pond a few meters below. Yayoi's challenge is to start from the designated place in this room, collect all the scrolls placed in the room, and bring them to the goal point.

Yayoi can move in the room according to the following rules.

* When moving from one tile to the next, you can only move to the top, bottom, left, and right tiles.
* If it is not close to the hole, it will take 1 second to move to the next tile.
* If you get close to the hole, Yayoi will be scared and it will take time to move as shown in Fig. C-1. For example, it takes 3 seconds to move from [2] [2] to [1] [2] as shown by the arrow in the figure.
* If there are multiple holes nearby, you will be afraid of the nearest hole.
* The time it takes to take a scroll can be assumed to be 0.

<image>
---
Figure C-1: Travel time near the hole

Yayoi wants to finish this challenge as soon as possible. Your job is to help Yayoi write a program that asks for the shortest time to complete this challenge.

Input

The floor information of the ninja mansion is given.

First, W and H, which represent the size of the room, are entered on the first line, separated by spaces (2 <= W, H <= 100). A W character string is input to each of the following H lines. There are the following types of characters that represent floor information.

*'.': Walkable floor
* '#' : hole
*'S': Where Yayoi stands at the start
*'G': Yayoi's place to reach
*'M': Where the scroll is located

'S',' G'and'M' are walking floors. There is exactly one'S'and one'G'in the room, respectively. You may pass the goal without all the scrolls. There are a minimum of 1'M'and a maximum of 5'M'in the room.

Output

Collect all the scrolls and output the shortest time to reach the goal from the start on one line. You can always assume that the input data has such a route.
Output a line break at the end of the line.

Sample Input 1

3 4
S.M
...
...
M.G

Sample Output 1

9

Sample Input 2

4 4
S..M
....
... #
..G

Sample Output 2

18

Sample Input 3

11 7
M ......... M
...........
... #. S. # ...
...........
... #. G. # ...
...........
M ......... M

Sample Output 3

62

Example

Input

3 4
S.M
...
...
M.G

Output

9

### Response

```cpp
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};

struct State {
	int x, y, c;
	State(int _x, int _y, int _c) : x(_x), y(_y), c(_c) {}
};

bool operator > (const State& a, const State& b) { return a.c > b.c; }

int W, H;
string grid[110];

int sx, sy, gx, gy;
PArray mvec;
int c_grid[110][110];

int cost[110][110];

int cost_bet(int stx, int sty, int glx, int gly) {
	for_(i,0,110) fill(cost[i], cost[i] + 110, iINF);
	priority_queue< State, vector< State >, greater< State> > q;
	q.push(State(stx, sty, 0));
	cost[sty][stx] = 0;

	while (!q.empty()) {
		State s = q.top(); q.pop();

		if (cost[s.y][s.x] < s.c) continue;

		if (s.x == glx && s.y == gly) return s.c;

		for_(d,0,4) {
			int nx = s.x + DX[d], ny = s.y + DY[d];
			if (!in_range(nx, ny, W, H)) continue;
			if (grid[ny][nx] == '#') continue;

			int adc = c_grid[s.y][s.x];
			if (cost[ny][nx] > s.c + adc) {
				cost[ny][nx] = s.c + adc;
				q.push(State(nx, ny, s.c + adc));
			}
		}
	}

	return cost[gly][glx];
}

void calc_cost(int hx, int hy) {
	for_(y,0,H) for_(x,0,W) {
		int v = 4 - max( abs(hx - x), abs(hy - y) );
		v = max(v, 1);
		c_grid[y][x] = max(c_grid[y][x], v);
	}
}

int poyo[10][10];

void solve() {
	for_(y,0,H) for_(x,0,W) c_grid[y][x] = 1;

	mvec.clear();
	for_(y,0,H) for_(x,0,W) {
		if (grid[y][x] == '#') calc_cost(x, y);
		if (grid[y][x] == 'M') mvec.push_back(pii(x, y));
		if (grid[y][x] == 'S') sx = x, sy = y;
		if (grid[y][x] == 'G') gx = x, gy = y;
	}

	int SS = 5, GG = 6;

	int m_size = size_of(mvec);
	for_(i,0,m_size) {
		pii p = mvec[i];

		poyo[SS][i] = cost_bet(sx, sy, p.first, p.second);
		poyo[i][GG] = cost_bet(p.first, p.second, gx, gy);

		for_(j,0,m_size) {
			pii pp = mvec[j];
			poyo[i][j] = cost_bet(p.first, p.second, pp.first, pp.second);
		}
	}

	vector< int > perm(m_size, 0);
	for_(i,0,m_size) perm[i] = i;

	int ans = iINF;

	do {
		int pans = poyo[SS][ perm[0] ] + poyo[ perm[m_size - 1] ][GG];
		for_(i,0,m_size - 1) pans += poyo[ perm[i] ][ perm[i + 1] ];
		ans = min(ans, pans);
	} while (next_permutation(allof(perm)));

	cout << ans << endl;
}

int main() {
	cin >> W >> H;

	for_(i,0,H) cin >> grid[i];

	solve();
	return 0;
}
```


### Prompt

Please create a solution in CPP to the following problem:

Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.

The girl finds an important permutation for the research. The permutation contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n). She replaces some of permutation elements with -1 value as a revenge.

When Iahub finds out his important permutation is broken, he tries to recover it. The only thing he remembers about the permutation is it didn't have any fixed point. A fixed point for a permutation is an element ak which has value equal to k (ak = k). Your job is to proof to Iahub that trying to recover it is not a good idea. Output the number of permutations which could be originally Iahub's important permutation, modulo 1000000007 (109 + 7).

Input

The first line contains integer n (2 ≤ n ≤ 2000). On the second line, there are n integers, representing Iahub's important permutation after Iahubina replaces some values with -1.

It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers -1 and each positive number occurs in the sequence at most once. It's guaranteed that there is at least one suitable permutation.

Output

Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109 + 7).

Examples

Input

5
-1 -1 4 3 -1

Output

2

Note

For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
bool use[2010];
long long fact[5010];
long long c[2010][2010];
int a[2010];
int main() {
  int n;
  cin >> n;
  int p = 0, k = 0;
  for (int i = 0; i < int(n); i++) {
    cin >> a[i];
    if (a[i] >= 0) use[a[i] - 1] = true;
  }
  for (int i = 0; i < int(n); i++) {
    if (a[i] == -1) {
      p++;
      if (!use[i]) {
        k++;
      }
    }
  }
  fact[0] = 1;
  for (int i = 1; i < 5010; ++i) fact[i] = (fact[i - 1] * i) % mod;
  for (int i = 0; i < int(2010); i++) c[i][0] = 1;
  for (int i = 1; i < 2010; ++i)
    for (int j = 1; j <= i; ++j)
      c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
  long long ans = fact[p];
  for (int i = 1; i <= k; ++i) {
    ans -= (fact[p - i] * c[k][i] * ((i & 1) ? (1) : (-1))) % mod;
    ans += mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Taro is addicted to a novel. The novel has n volumes in total, and each volume has a different thickness. Taro likes this novel so much that he wants to buy a bookshelf dedicated to it. However, if you put a large bookshelf in the room, it will be quite small, so you have to devise to make the width of the bookshelf as small as possible. When I measured the height from the floor to the ceiling, I found that an m-level bookshelf could be placed. So, how can we divide the n volumes of novels to minimize the width of the bookshelf in m columns? Taro is particular about it, and the novels to be stored in each column must be arranged in the order of the volume numbers. ..

Enter the number of bookshelves, the number of volumes of the novel, and the thickness of each book as input, and create a program to find the width of the bookshelf that has the smallest width that can accommodate all volumes in order from one volume. However, the size of the bookshelf frame is not included in the width.

<image>

Input

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

m n
w1
w2
::
wn

The first line gives m (1 ≤ m ≤ 20) the number of bookshelves that can be placed in the room and n (1 ≤ n ≤ 100) the number of volumes in the novel. The next n lines are given the integer wi (1 ≤ wi ≤ 1000000), which represents the thickness of the book in Volume i.

However, the width of the bookshelf shall not exceed 1500000.

The number of datasets does not exceed 50.

Output

Outputs the minimum bookshelf width for each dataset on one line.

Example

Input

3 9
500
300
800
200
100
600
900
700
400
4 3
1000
1000
1000
0 0

Output

1800
1000

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int books[1005],m,c,ri,le,mid,ans,sum[205],n;
bool flag=false;

int main(){
    while(1){
        cin >> m >> n;
        if(n==0&&m==0)break;
        for(int i=0;i<n;i++){
                cin >> books[i];
                ri+=books[i];
        }
        mid=ri/2;
        le=0;

        for(int i=0;i<1000;i++){
            for(int j=0;j<m;j++){
                for(;;){
                    if(c==n){
                        flag=true;
                        break;
                    }
                    if(sum[j]+books[c]>mid)break;
                    else sum[j]+=books[c];
                    c++;
                    }
                }

                if(flag==true){
                    ri=mid;
                    mid=ri/2;
                }else{
                    le=mid;
                    mid=(le+ri)/2;
                }
                flag=false;
                c=0;
                for(int o=0;o<n+1;o++)sum[o]=0;
            }
            cout << ri << endl;
            ri=0,le=0,mid=0;
            for(int i=0;i<1000;i++)books[i]=0;
    }

 return 0;
}
```


### Prompt

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

Generalized leap year

Normally, whether or not the year x is a leap year is defined as follows.

1. If x is a multiple of 400, it is a leap year.
2. Otherwise, if x is a multiple of 100, it is not a leap year.
3. Otherwise, if x is a multiple of 4, it is a leap year.
4. If not, it is not a leap year.

This can be generalized as follows. For a sequence A1, ..., An, we define whether the year x is a "generalized leap year" as follows.

1. For the smallest i (1 ≤ i ≤ n) such that x is a multiple of Ai, if i is odd, it is a generalized leap year, and if it is even, it is not a generalized leap year.
2. When such i does not exist, it is not a generalized leap year if n is odd, but a generalized leap year if n is even.

For example, when A = [400, 100, 4], the generalized leap year for A is equivalent to a normal leap year.

Given the sequence A1, ..., An and the positive integers l, r. Answer the number of positive integers x such that l ≤ x ≤ r such that year x is a generalized leap year for A.

Input

The input consists of up to 50 datasets. Each dataset is represented in the following format.

> n l r A1 A2 ... An

The integer n satisfies 1 ≤ n ≤ 50. The integers l and r satisfy 1 ≤ l ≤ r ≤ 4000. For each i, the integer Ai satisfies 1 ≤ Ai ≤ 4000.

The end of the input is represented by a line of three zeros.

Output

Print the answer in one line for each dataset.

Sample Input

3 1988 2014
400
100
Four
1 1000 1999
1
2 1111 3333
2
2
6 2000 3000
Five
7
11
9
3
13
0 0 0

Output for the Sample Input

7
1000
2223
785

Example

Input

3 1988 2014
400
100
4
1 1000 1999
1
2 1111 3333
2
2
6 2000 3000
5
7
11
9
3
13
0 0 0

Output

7
1000
2223
785

### Response

```cpp
#include<bits/stdc++.h>
#define rep(i,n) for(int i=1; i<=n; i++)
using namespace std;
int main(){
  int n,l,r;
  while(cin >> n >> l >> r,n){
    int count=0;
    int a[51];
    a[0] = 0;
    rep(i,n) cin >> a[i];
    for(int x=l; x<=r; x++){
      bool flag=false;
      rep(i,n){
        if(x%a[i] == 0){
          flag = true;
          if(i%2 != 0) {
            count++;
          }
          break;
        }
      }
      if(flag == false && n%2 == 0) count++;
    }
    cout << count << endl;
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to win the championship may be different for each contestant. The structure of the tournament is formally described at the end of this statement.

After each match, there were always one winner and one loser. The last contestant standing was declared the champion.

<image>

Figure: an example of a tournament

For convenience, the contestants were numbered 1 through N. The contestant numbered 1 was the champion, and the contestant numbered i(2 ≦ i ≦ N) was defeated in a match against the contestant numbered a_i.

We will define the depth of the tournament as the maximum number of the matches that must be played in order to win the championship over all the contestants.

Find the minimum possible depth of the tournament.

The formal description of the structure of the tournament is as follows. In the i-th match, one of the following played against each other:

* Two predetermined contestants
* One predetermined contestant and the winner of the j-th match, where j(j<i) was predetermined
* The winner of the j-th match and the winner of the k-th match, where j and k (j,k<i, j ≠ k) were predetermined

Such structure is valid structure of the tournament, if and only if no contestant who has already been defeated in a match will never play in a match, regardless of the outcome of the matches.

Constraints

* 2 ≦ N ≦ 10^5
* 1 ≦ a_i ≦ N(2 ≦ i ≦ N)
* It is guaranteed that the input is consistent (that is, there exists at least one tournament that matches the given information).

Input

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

N
a_2
:
a_N

Output

Print the minimum possible depth of the tournament.

Examples

Input

5
1
1
2
4

Output

3

Input

7
1
2
1
3
1
4

Output

3

Input

4
4
4
1

Output

3

### Response

```cpp
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cassert>

using namespace std;

const int N = 1e5 + 7;

int n;
vector<int> sons[N];

int dfs(int u) {
	vector<int> tmp;
	for (int v : sons[u]) {
		tmp.push_back(dfs(v));
	}
	sort(tmp.begin(), tmp.end());
	int ret = 0;
	for (int i = 0; i < tmp.size(); i++) {
		ret = max(ret, tmp[i] + (int)tmp.size() - i);
	}
	return ret;
}

int main() {
	scanf("%d", &n);
	for (int i = 2; i <= n; i++) {
		int fat;
		scanf("%d", &fat);
		sons[fat].push_back(i);
	}
	cout << dfs(1) << endl;
}

```


### Prompt

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

Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)?

Input

The first line of the input contains two integers s and x (2 ≤ s ≤ 1012, 0 ≤ x ≤ 1012), the sum and bitwise xor of the pair of positive integers, respectively.

Output

Print a single integer, the number of solutions to the given conditions. If no solutions exist, print 0.

Examples

Input

9 5

Output

4

Input

3 3

Output

2

Input

5 2

Output

0

Note

In the first sample, we have the following solutions: (2, 7), (3, 6), (6, 3), (7, 2).

In the second sample, the only solutions are (1, 2) and (2, 1).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 20, inf = 2e9 + 20, mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  long long a, x;
  cin >> a >> x;
  int flag = -2 * (a == x);
  a -= x;
  if (a & 1) return cout << 0 << endl, 0;
  a >>= 1;
  long long ans = 1;
  while (a || x) {
    if (a & 1) {
      if (x & 1) return cout << 0 << endl, 0;
    } else {
      if (x & 1) ans *= 2;
    }
    a >>= 1;
    x >>= 1;
  }
  ans += flag;
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

Joisino is working as a receptionist at a theater.

The theater has 100000 seats, numbered from 1 to 100000.

According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).

How many people are sitting at the theater now?

Constraints

* 1≤N≤1000
* 1≤l_i≤r_i≤100000
* No seat is occupied by more than one person.
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N
l_1 r_1
:
l_N r_N

Output

Print the number of people sitting at the theater.

Examples

Input

1
24 30

Output

7

Input

2
6 8
3 3

Output

4

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
long long a,b,s,n,i;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a>>b;
		s+=b-a+1;
	}
	cout<<s;
	return 0;
}
```


### Prompt

Create a solution in cpp for the following problem:

You are given a rectangle grid. That grid's size is n × m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates — a pair of integers (x, y) (0 ≤ x ≤ n, 0 ≤ y ≤ m).

Your task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it contains the given point (x, y), and its length-width ratio is exactly (a, b). In other words the following conditions must hold: 0 ≤ x1 ≤ x ≤ x2 ≤ n, 0 ≤ y1 ≤ y ≤ y2 ≤ m, <image>.

The sides of this sub-rectangle should be parallel to the axes. And values x1, y1, x2, y2 should be integers.

<image>

If there are multiple solutions, find the rectangle which is closest to (x, y). Here "closest" means the Euclid distance between (x, y) and the center of the rectangle is as small as possible. If there are still multiple solutions, find the lexicographically minimum one. Here "lexicographically minimum" means that we should consider the sub-rectangle as sequence of integers (x1, y1, x2, y2), so we can choose the lexicographically minimum one.

Input

The first line contains six integers n, m, x, y, a, b (1 ≤ n, m ≤ 109, 0 ≤ x ≤ n, 0 ≤ y ≤ m, 1 ≤ a ≤ n, 1 ≤ b ≤ m).

Output

Print four integers x1, y1, x2, y2, which represent the founded sub-rectangle whose left-bottom point is (x1, y1) and right-up point is (x2, y2).

Examples

Input

9 9 5 5 2 1

Output

1 3 9 7

Input

100 100 52 50 46 56

Output

17 8 86 92

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
ifstream Cin("input.txt");
ofstream Cout("output.txt");
const long long MOD = 1000000007;
long long nod(long long x, long long y) {
  while (x && y)
    if (x > y)
      x %= y;
    else
      y %= x;
  return x + y;
}
int main() {
  long long n, m, x, y, a, b, st, x1, y1, x2, y2;
  cin >> n >> m >> x >> y >> a >> b;
  st = nod(a, b);
  a /= st;
  b /= st;
  st = min(n / a, m / b);
  a = st * a;
  b = st * b;
  x1 = min(n - a, max(0LL, x - (a + 1) / 2));
  y1 = min(m - b, max(0LL, y - (b + 1) / 2));
  cout << x1 << " " << y1 << " " << x1 + a << " " << y1 + b << endl;
}

```


### Prompt

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

Flatland is inhabited by pixels of three colors: red, green and blue. We know that if two pixels of different colors meet in a violent fight, only one of them survives the fight (that is, the total number of pixels decreases by one). Besides, if pixels of colors x and y (x ≠ y) meet in a violent fight, then the pixel that survives the fight immediately changes its color to z (z ≠ x; z ≠ y). Pixels of the same color are friends, so they don't fight.

The King of Flatland knows that his land will be peaceful and prosperous when the pixels are of the same color. For each of the three colors you know the number of pixels of this color that inhabit Flatland. Help the king and determine whether fights can bring peace and prosperity to the country and if it is possible, find the minimum number of fights needed to make the land peaceful and prosperous.

Input

The first line contains three space-separated integers a, b and c (0 ≤ a, b, c ≤ 231; a + b + c > 0) — the number of red, green and blue pixels, correspondingly.

Output

Print a single number — the minimum number of pixel fights before the country becomes peaceful and prosperous. If making the country peaceful and prosperous is impossible, print -1.

Examples

Input

1 1 1

Output

1

Input

3 1 0

Output

3

Note

In the first test sample the country needs only one fight to achieve peace and prosperity. Besides, it can be any fight whatsoever. For example, let's assume that the green and the blue pixels fight, then the surviving pixel will be red. As a result, after the fight there are two red pixels. There won't be other pixels.

In the second sample the following sequence of fights is possible: red and blue, green and red, red and blue. As a result, after all fights there is one green pixel left.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long a, b, c;
long long res;
int main() {
  cin >> a >> b >> c;
  res = a + b + c - 1ll;
  if (a % 2ll == b % 2ll) res = min(res, max(a, b));
  if (a % 2ll == c % 2ll) res = min(res, max(a, c));
  if (b % 2ll == c % 2ll) res = min(res, max(b, c));
  cout << res << endl;
  return 0;
}

```


### Prompt

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

An bydrocarbon is an organic compound which contains only carbons and hydrogens. An isomer is a compound that has the same number of carbons but different structures. Heptane, for example, is a hydrocarbon with 7 carbons. It has nine isomers. The structural formula of three are shown in Figure 1. Carbons are represented by the letter C, and bonds between carbons are represented by a straight line. In all figures, hydrogens are not represented for simplicity. Each carbon can be connected to a maximum of 4 carbons.

<image>
---
Figure 1: These three examples of isomers of heptane have the same number of carbons but different structures.
---

Let define a chain in an isomer as a sequence of connected carbons without branches. An isomer can have many chains of the same length. Figure 2 shows the longest chain of carbons for each of the represented isomer. Note that there can be many instances of longest chain in an isomer.

<image>
---
Figure 2: The figures shows one instance of longest chain of carbons in each isomer. The first and the second isomers show longest chains of 5 carbons. The longest chain in the third isomer has 4 carbons.
---

Your task is to identify the number of carbons of the largest possible carbon compound whose longest carbon chain has n (1 ≤ n ≤ 30) carbons.

Input

Each input contains a list of number of carbons, i.e. the length of a carbon chain.

The number of input lines is less than or equal to 30.

Output

For each number n in input, identify the number of carbons of the largest possible carbon compound whose longest carbon chain has n carbons.

Example

Input

1
4

Output

1
8

### Response

```cpp
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>

using namespace std;

int main()
{
	int n;
	while (scanf("%d", &n) != EOF)
	{
		if (n & 1)
			printf("%d\n", 2*(int)pow(3., n/2)-1);
		else
			printf("%d\n", (int)pow(3., n/2)-1);
	}

	return 0;
}
```


### Prompt

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

In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest.

Vova and Lesha are friends. They often meet at Vova's place and compete against each other in a computer game named The Ancient Papyri: Swordsink. Vova always chooses a warrior as his fighter and Leshac chooses an archer. After that they should choose initial positions for their characters and start the fight. A warrior is good at melee combat, so Vova will try to make the distance between fighters as small as possible. An archer prefers to keep the enemy at a distance, so Lesha will try to make the initial distance as large as possible.

There are n (n is always even) possible starting positions for characters marked along the Ox axis. The positions are given by their distinct coordinates x1, x2, ..., xn, two characters cannot end up at the same position.

Vova and Lesha take turns banning available positions, Vova moves first. During each turn one of the guys bans exactly one of the remaining positions. Banned positions cannot be used by both Vova and Lesha. They continue to make moves until there are only two possible positions remaining (thus, the total number of moves will be n - 2). After that Vova's character takes the position with the lesser coordinate and Lesha's character takes the position with the bigger coordinate and the guys start fighting.

Vova and Lesha are already tired by the game of choosing positions, as they need to play it before every fight, so they asked you (the developer of the The Ancient Papyri: Swordsink) to write a module that would automatically determine the distance at which the warrior and the archer will start fighting if both Vova and Lesha play optimally.

Input

The first line on the input contains a single integer n (2 ≤ n ≤ 200 000, n is even) — the number of positions available initially. The second line contains n distinct integers x1, x2, ..., xn (0 ≤ xi ≤ 109), giving the coordinates of the corresponding positions.

Output

Print the distance between the warrior and the archer at the beginning of the fight, provided that both Vova and Lesha play optimally.

Examples

Input

6
0 1 3 7 15 31

Output

7

Input

2
73 37

Output

36

Note

In the first sample one of the optimum behavior of the players looks like that:

  1. Vova bans the position at coordinate 15;
  2. Lesha bans the position at coordinate 3;
  3. Vova bans the position at coordinate 31;
  4. Lesha bans the position at coordinate 1.

After these actions only positions 0 and 7 will remain, and the distance between them is equal to 7.

In the second sample there are only two possible positions, so there will be no bans.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, ar[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &ar[i]);
  sort(ar, ar + n);
  int ans = 1e9;
  for (int i = 0; i < n / 2; i++) ans = min(ans, ar[i + n / 2] - ar[i]);
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

There are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs.

Takahashi says: "there are X animals in total in the garden, and they have Y legs in total." Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct.

Constraints

* 1 \leq X \leq 100
* 1 \leq Y \leq 100
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y

Output

If there is a combination of numbers of cranes and turtles in which the statement is correct, print `Yes`; otherwise, print `No`.

Examples

Input

3 8

Output

Yes

Input

2 100

Output

No

Input

1 2

Output

Yes

### Response

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

int main()
{
	int x, y;
	cin >> x >> y;
	if (2 * x <= y && y <= 4 * x && y % 2 == 0)
		cout << "Yes";
	else
		cout << "No";
}
```


### Prompt

Generate a cpp solution to the following problem:

Koto Municipal Subway

Koto Municipal Subway

Koto City is a famous city whose roads are in a grid pattern, as shown in the figure below. The roads extending from north to south and the roads extending from east to west are lined up at intervals of 1 km each. Let Koto station at the southwestern intersection of Koto city be (0, 0), and mark x km east and y km north from it as (x, y) (0 ≤ x, y). ).

<image>

In anticipation of an increase in tourists due to the Olympic Games to be held five years later, the city has decided to build a new subway line starting from Koto station. Currently, we are planning to lay a rail to Shin-Koto station, which will be newly constructed as the next station after Koto station. The rail will be laid straight from Koto station to Shin-Koto station. Therefore, when the location of Shin-Koto station is (x, y), the length of the rail is √ (x2 + y2). The cost of laying the rail is the same as the length of the laid rail. Even if the rail length is a decimal number such as 1.5km, the cost is also 1.5.

The location (x, y) of Shin-Koto station has not been decided yet, and we plan to make it a location that meets the following conditions.

* It is an intersection. That is, x and y are integers, respectively.
* The shortest distance walked along the road from Koto station is exactly D. That is, x + y = D is satisfied.

Among the above two conditions, select the location of Shin-Koto station so that the difference between the rail budget E and the rail cost set by the city | √ (x2 + y2) --E | is minimized. Here, | A | represents the absolute value of A. Your job is to create a program that outputs the difference between the cost and budget for laying rails when the Shin-Koto station was constructed as described above.

Input

The input consists of multiple data sets, and the number of data sets contained in one input is 100 or less. The format of each data set is as follows.

> D E

D (1 ≤ D ≤ 100) is an integer that represents the shortest distance when walking along the road from Koto station to Shin-Koto station. E (1 ≤ E ≤ 100) is an integer representing the budget for rail construction.

The end of the input is indicated by a line of two zeros separated by a blank.

Output

For each data set, output the difference between the cost and budget when laying the rail so as to satisfy the problem condition in one line. The answer must have an absolute error greater than 10-3. Note that if you do not output a line break at the end of each line, or if you output unnecessary characters, it will be judged as an incorrect answer.

Sample Input

twenty one
7 5
7 6
7 7
76 5
8 41
0 0

Output for Sample Input

0.4142135624
0
0.0827625303
0
48.7401153702
33

Hint

In the first data set, as shown in the figure below, an intersection 2 km along the road from Koto station is a candidate for a place to build Shin-Koto station.

<image>

When Shin-Koto station is constructed at each intersection, the difference between the cost for laying the rail and budget 1 is as follows.

* (2, 0): | √ (22 + 02) --1 | = 1.0
* (1, 1): | √ (12 + 12) --1 | = 0.4142135623 ...
* (0, 2): | √ (02 + 22) --1 | = 1.0

Therefore, the difference between the cost and the budget is minimized when the construction is done in (1, 1).

Example

Input

2 1
7 5
7 6
7 7
76 5
8 41
0 0

Output

0.4142135624
0
0.0827625303
0
48.7401153702
33

### Response

```cpp
#include<cstdio>
#include<cmath>

using namespace std;
int main(void) {
    while(1) {
        int d,e;
        scanf("%d%d",&d,&e);
        if(!d) break;
        double res=10000.;
        for(int i=0; i<d; i++)
            if(abs(sqrt(i*i + (d-i)*(d-i)) - e) < res)
                res = abs(sqrt(i*i + (d-i)*(d-i)) - e);
        printf("%f\n",res);
    }
}
```


### Prompt

Please formulate a Cpp solution to the following problem:

You are given an infinite periodic array a0, a1, ..., an - 1, ... with the period of length n. Formally, <image>. A periodic subarray (l, s) (0 ≤ l < n, 1 ≤ s < n) of array a is an infinite periodic array with a period of length s that is a subsegment of array a, starting with position l.

A periodic subarray (l, s) is superior, if when attaching it to the array a, starting from index l, any element of the subarray is larger than or equal to the corresponding element of array a. An example of attaching is given on the figure (top — infinite array a, bottom — its periodic subarray (l, s)):

<image>

Find the number of distinct pairs (l, s), corresponding to the superior periodic arrays.

Input

The first line contains number n (1 ≤ n ≤ 2·105). The second line contains n numbers a0, a1, ..., an - 1 (1 ≤ ai ≤ 106), separated by a space.

Output

Print a single integer — the sought number of pairs.

Examples

Input

4
7 1 2 3

Output

2

Input

2
2 1

Output

1

Input

3
1 1 1

Output

6

Note

In the first sample the superior subarrays are (0, 1) and (3, 2).

Subarray (0, 1) is superior, as a0 ≥ a0, a0 ≥ a1, a0 ≥ a2, a0 ≥ a3, a0 ≥ a0, ...

Subarray (3, 2) is superior a3 ≥ a3, a0 ≥ a0, a3 ≥ a1, a0 ≥ a2, a3 ≥ a3, ...

In the third sample any pair of (l, s) corresponds to a superior subarray as all the elements of an array are distinct.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 1000 + 10;
int a[MAXN], n, c[MAXN], gg[MAXN];
bool u[MAXN];
int inc(int v) { return (v + 1 == n) ? 0 : (v + 1); }
int GCD(int a, int b) { return b == 0 ? a : GCD(b, a % b); }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) gg[i] = GCD(i, n);
  long long res = 0;
  for (int g = 1; g < n; g++) {
    if (n % g != 0) continue;
    for (int i = 0; i < n; i++) u[i] = false, c[i] = 0;
    for (int i = 0; i < g; i++) {
      int mx = -1;
      for (int j = i; j < n; j += g) mx = max(mx, a[j]);
      for (int j = i; j < n; j += g)
        if (a[j] == mx) u[j] = true;
    }
    bool any = false;
    for (int l = 0; l < n;) {
      int r = inc(l);
      if (u[l]) {
        l++;
        continue;
      }
      any = true;
      int len = 0;
      while (u[r]) len++, r = inc(r);
      for (int i = 1; i <= len; i++) c[i] += len - i + 1;
      if (r <= l) break;
      l = r;
    }
    if (!any)
      for (int i = 1; i <= n; i++) c[i] += n;
    for (int i = 1; i <= n; i++)
      if (gg[i] == g) res += c[i];
  }
  printf("%lld\n", res);
  return 0;
}

```


### Prompt

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

You are given an array a consisting of n positive integers.

Initially, you have an integer x = 0. During one move, you can do one of the following two operations:

  1. Choose exactly one i from 1 to n and increase a_i by x (a_i := a_i + x), then increase x by 1 (x := x + 1).
  2. Just increase x by 1 (x := x + 1).

The first operation can be applied no more than once to each i from 1 to n.

Your task is to find the minimum number of moves required to obtain such an array that each its element is divisible by k (the value k is given).

You have to answer t independent test cases.

Input

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

The first line of the test case contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 10^9) — the length of a and the required divisior. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is the i-th element of a.

It is guaranteed that the sum of n does not exceed 2 ⋅ 10^5 (∑ n ≤ 2 ⋅ 10^5).

Output

For each test case, print the answer — the minimum number of moves required to obtain such an array that each its element is divisible by k.

Example

Input

5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8

Output

6
18
0
227
8

Note

Consider the first test case of the example:

  1. x=0, a = [1, 2, 1, 3]. Just increase x;
  2. x=1, a = [1, 2, 1, 3]. Add x to the second element and increase x;
  3. x=2, a = [1, 3, 1, 3]. Add x to the third element and increase x;
  4. x=3, a = [1, 3, 3, 3]. Add x to the fourth element and increase x;
  5. x=4, a = [1, 3, 3, 6]. Just increase x;
  6. x=5, a = [1, 3, 3, 6]. Add x to the first element and increase x;
  7. x=6, a = [6, 3, 3, 6]. We obtained the required array.

Note that you can't add x to the same element more than once.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long maxsize = 100000 + 9;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    long long i, j, k, m, n, c = 0;
    map<long long, long long> mp;
    mp.clear();
    cin >> n >> k;
    for (i = 0; i < n; i++) {
      cin >> j;
      m = (k - j % k) % k;
      if (m == 0) continue;
      c = max(c, mp[m] * k + m);
      mp[m]++;
    }
    if (!c) {
      cout << 0 << '\n';
    } else {
      cout << c + 1 << '\n';
    }
  }
}

```