### Prompt

Please formulate a CPP solution to the following problem:

You play the game with your friend. The description of this game is listed below.

Your friend creates n distinct strings of the same length m and tells you all the strings. Then he randomly chooses one of them. He chooses strings equiprobably, i.e. the probability of choosing each of the n strings equals <image>. You want to guess which string was chosen by your friend.

In order to guess what string your friend has chosen, you are allowed to ask him questions. Each question has the following form: «What character stands on position pos in the string you have chosen?» A string is considered guessed when the answers to the given questions uniquely identify the string. After the string is guessed, you stop asking questions.

You do not have a particular strategy, so as each question you equiprobably ask about a position that hasn't been yet mentioned. Your task is to determine the expected number of questions needed to guess the string chosen by your friend.

Input

The first line contains a single integer n (1 ≤ n ≤ 50) — the number of strings your friend came up with.

The next n lines contain the strings that your friend has created. It is guaranteed that all the strings are distinct and only consist of large and small English letters. Besides, the lengths of all strings are the same and are between 1 to 20 inclusive.

Output

Print the single number — the expected value. Your answer will be considered correct if its absolute or relative error doesn't exceed 10 - 9.

Examples

Input

2
aab
aac

Output

2.000000000000000

Input

3
aaA
aBa
Caa

Output

1.666666666666667

Input

3
aca
vac
wqq

Output

1.000000000000000

Note

In the first sample the strings only differ in the character in the third position. So only the following situations are possible:

  * you guess the string in one question. The event's probability is <image>;
  * you guess the string in two questions. The event's probability is <image> · <image> = <image> (as in this case the first question should ask about the position that is other than the third one);
  * you guess the string in three questions. The event's probability is <image> · <image> · <image> = <image>;

Thus, the expected value is equal to <image>

In the second sample we need at most two questions as any pair of questions uniquely identifies the string. So the expected number of questions is <image>.

In the third sample whatever position we ask about in the first question, we immediately identify the string.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, lim, num[2000001];
long long f[2000001];
char s[51][21];
double g[2000001], ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  m = strlen(s[1] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      int tmp = 0;
      for (int k = 1; k <= m; k++)
        if (s[i][k] == s[j][k]) tmp |= 1 << (k - 1);
      f[tmp] |= 1ll << (i - 1);
      f[tmp] |= 1ll << (j - 1);
    }
  lim = (1 << m) - 1;
  for (int i = m - 1; i >= 0; i--)
    for (int j = 0; j <= lim; j++)
      if (j & (1 << i)) f[j - (1 << i)] |= f[j];
  g[0] = 1;
  for (int i = 0; i <= lim; i++) num[i] = num[i / 2] + (i & 1);
  for (int i = 0; i <= lim; i++) {
    for (int j = 0; j < m; j++)
      if (i & (1 << j)) g[i] += g[i - (1 << j)] / (num[lim & (~i)] + 1);
    for (int j = 0; j <= n; j++)
      if (f[i] & (1ll << j)) ans += g[i];
  }
  printf("%.9lf\n", ans / n);
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too.

An ant stands at the root of some tree. He sees that there are n vertexes in the tree, and they are connected by n - 1 edges so that there is a path between any pair of vertexes. A leaf is a distinct from root vertex, which is connected with exactly one other vertex.

The ant wants to visit every vertex in the tree and return to the root, passing every edge twice. In addition, he wants to visit the leaves in a specific order. You are to find some possible route of the ant.

Input

The first line contains integer n (3 ≤ n ≤ 300) — amount of vertexes in the tree. Next n - 1 lines describe edges. Each edge is described with two integers — indexes of vertexes which it connects. Each edge can be passed in any direction. Vertexes are numbered starting from 1. The root of the tree has number 1. The last line contains k integers, where k is amount of leaves in the tree. These numbers describe the order in which the leaves should be visited. It is guaranteed that each leaf appears in this order exactly once.

Output

If the required route doesn't exist, output -1. Otherwise, output 2n - 1 numbers, describing the route. Every time the ant comes to a vertex, output it's index.

Examples

Input

3
1 2
2 3
3

Output

1 2 3 2 1

Input

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

Output

1 2 4 5 4 6 4 2 1 3 1

Input

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

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
vector<int> gr[N], temp, ar, ans;
int n, u, v, io[N], hash[N], cnt[N], k;
bool flag;
void pb(vector<int>* fi, vector<int> se) {
  for (int i = 0; i < se.size(); i++) (*fi).push_back(se[i]);
}
bool dfs(int node, int come, int tar) {
  if (node == tar) {
    flag = true;
    return true;
  }
  for (int i = 0; i < gr[node].size(); i++) {
    if (flag == true) break;
    if (gr[node][i] != come) {
      bool def = dfs(gr[node][i], node, tar);
      if (def) {
        temp.push_back(gr[node][i]);
        break;
      }
    }
  }
  return flag;
}
void alloc() {
  dfs(ar.back(), -1, 1);
  reverse(temp.begin(), temp.end());
  pb(&ans, temp);
  flag = false;
  temp.clear();
  dfs(1, -1, ar[0]);
  temp.push_back(1);
  reverse(ans.begin(), ans.end());
  pb(&ans, temp);
  reverse(ans.begin(), ans.end());
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    gr[u].push_back(v);
    gr[v].push_back(u);
    io[v]++, io[u]++;
  }
  for (int i = 2; i <= n; i++)
    if (io[i] == 1) k++;
  for (int i = 1; i <= k; i++) {
    cin >> u;
    ar.push_back(u);
  }
  for (int i = 1; i < ar.size(); i++, flag = false, temp.clear()) {
    dfs(ar[i - 1], -1, ar[i]);
    reverse(temp.begin(), temp.end());
    for (int i = 0; i < temp.size(); i++) ans.push_back(temp[i]);
  }
  alloc();
  if (ans.size() != n * 2 - 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  return 0;
}

```


### Prompt

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

In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions).

A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen.

Write a program that, when S is given, prints the price of the corresponding bowl of ramen.

Constraints

* S is a string of length 3.
* Each character in S is `o` or `x`.

Input

Input is given from Standard Input in the following format:

S

Output

Print the price of the bowl of ramen corresponding to S.

Examples

Input

oxo

Output

900

Input

ooo

Output

1000

Input

xxx

Output

700

### Response

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

int main() {
  string s;
  cin>>s;
  int a=0;
  for(int i=0;i<3;i++){
    if(s[i]=='o')a++;
  }
  cout<<700+a*100<<endl;
}
```


### Prompt

Generate a CPP solution to the following problem:

This problem differs from the next problem only in constraints.

Petya decided to visit Byteland during the summer holidays. It turned out that the history of this country is quite unusual.

Initially, there were n different countries on the land that is now Berland. Each country had its own territory that was represented as a rectangle on the map. The sides of the rectangle were parallel to the axes, and the corners were located at points with integer coordinates. Territories of no two countries intersected, but it was possible that some territories touched each other. As time passed, sometimes two countries merged into one. It only happened if the union of their territories was also a rectangle. In the end only one country remained — Byteland.

Initially, each country had a rectangular castle inside its territory. Its sides were parallel to the axes and its corners had integer coordinates. Some castles might touch the border of the corresponding country and sides or other castles. Miraculously, after all the unions the castles are still intact. Unfortunately, their locations are the only information we have to restore the initial territories of the countries.

<image> The possible formation of Byteland. The castles are shown in blue.

Petya wonders why no information about the initial countries remained. He suspected that the whole story is a fake. You were recommended to him as a smart person. Please check whether or not there exists a possible set of initial territories that could make the story true.

Input

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

Each of the next n lines contains four integers a_i, b_i, c_i, d_i (0 ≤ a_i < c_i ≤ 10^9, 0 ≤ b_i < d_i ≤ 10^9) — the coordinates of the i-th castle, where (a_i, b_i) are the coordinates of the lower left corner and (c_i, d_i) are the coordinates of the upper right corner.

It is guaranteed, that no two castles intersect, however, they may touch.

Output

If there exists a possible set of territories that satisfies the story, print "YES", otherwise print "NO".

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

Examples

Input

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

Output

YES

Input

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

Output

NO

Note

The castles in the first and second examples are shown on the pictures below.

<image> <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct area {
  int u, d, l, r;
};
int n;
bool cmp_x(const area& x, const area& y) { return x.l < y.l; }
bool cmp_y(const area& x, const area& y) { return x.u < y.u; }
pair<vector<area>, vector<area> > split(vector<area>& ar) {
  vector<area> l, r;
  if (ar.size() == 1) return make_pair(l, r);
  sort(ar.begin(), ar.end(), cmp_x);
  int maxR = ar.begin()->r;
  for (register int i = 1; i < ar.size(); i++)
    if (maxR <= ar[i].l) {
      l = vector<area>(ar.begin(), ar.begin() + i);
      r = vector<area>(ar.begin() + i, ar.end());
      return pair<vector<area>, vector<area> >(l, r);
    } else {
      maxR = max(maxR, ar[i].r);
    }
  sort(ar.begin(), ar.end(), cmp_y);
  int maxD = ar.begin()->d;
  for (register int i = 1; i < ar.size(); i++)
    if (maxD <= ar[i].u) {
      l = vector<area>(ar.begin(), ar.begin() + i);
      r = vector<area>(ar.begin() + i, ar.end());
      return pair<vector<area>, vector<area> >(l, r);
    } else {
      maxD = max(maxD, ar[i].d);
    }
  cout << "NO" << endl;
  exit(0);
}
void put_ar(area& x) {
  cout << x.l << ' ' << x.u << ' ' << x.r << ' ' << x.d << endl;
}
void put_al(vector<area>& x) {
  cout << "---------" << endl;
  for (vector<area>::iterator it = x.begin(); it != x.end(); it++) put_ar(*it);
  cout << "---------" << endl;
}
signed main() {
  vector<area> dat;
  cin >> n;
  for (register int i = 1; i <= n; i++) {
    area ar;
    cin >> ar.l >> ar.u >> ar.r >> ar.d;
    dat.push_back(ar);
  }
  queue<vector<area> > que;
  que.push(dat);
  while (!que.empty()) {
    pair<vector<area>, vector<area> > get = split(que.front());
    que.pop();
    if (get.first.empty() && get.second.empty()) continue;
    que.push(get.first);
    que.push(get.second);
  }
  cout << "YES" << endl;
  return 0;
}

```


### Prompt

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

Takahashi is locked within a building.

This building consists of H×W rooms, arranged in H rows and W columns. We will denote the room at the i-th row and j-th column as (i,j). The state of this room is represented by a character A_{i,j}. If A_{i,j}= `#`, the room is locked and cannot be entered; if A_{i,j}= `.`, the room is not locked and can be freely entered. Takahashi is currently at the room where A_{i,j}= `S`, which can also be freely entered.

Each room in the 1-st row, 1-st column, H-th row or W-th column, has an exit. Each of the other rooms (i,j) is connected to four rooms: (i-1,j), (i+1,j), (i,j-1) and (i,j+1).

Takahashi will use his magic to get out of the building. In one cast, he can do the following:

* Move to an adjacent room at most K times, possibly zero. Here, locked rooms cannot be entered.
* Then, select and unlock at most K locked rooms, possibly zero. Those rooms will remain unlocked from then on.

His objective is to reach a room with an exit. Find the minimum necessary number of casts to do so.

It is guaranteed that Takahashi is initially at a room without an exit.

Constraints

* 3 ≤ H ≤ 800
* 3 ≤ W ≤ 800
* 1 ≤ K ≤ H×W
* Each A_{i,j} is `#` , `.` or `S`.
* There uniquely exists (i,j) such that A_{i,j}= `S`, and it satisfies 2 ≤ i ≤ H-1 and 2 ≤ j ≤ W-1.

Input

Input is given from Standard Input in the following format:

H W K
A_{1,1}A_{1,2}...A_{1,W}
:
A_{H,1}A_{H,2}...A_{H,W}

Output

Print the minimum necessary number of casts.

Examples

Input

3 3 3
#.#
#S.
###

Output

1

Input

3 3 3
.#
S.

Output

1

Input

3 3 3

S#

Output

2

Input

7 7 2

...##
S###
.#.##
.###

Output

2

### Response

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

int n,m,k,x,y;
char c[1000][1000];
bool vis[1000][1000];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};

int main()
{
	cin>>n>>m>>k;
	for(int i=0;i<n;i++){
	    scanf("%s",&c[i]);
	    for(int j=0;j<m;j++) if(c[i][j]=='S') x=i,y=j;
    }
    int ans=min(min(x,y),min(n-x-1,m-y-1));
    vis[x][y]=true;
    if(ans%k==0) ans=ans/k;
    else ans=ans/k+1;
    int minv=ans+1;
    queue<pair<int,pair<int,int> > > q;
    q.push(make_pair(0,make_pair(x,y)));
    while(!q.empty())
    {
    	pair<int,pair<int,int> > t=q.front();q.pop();
    	if(t.first>=k) continue;
		for(int w=0;w<4;w++){
			int nx=t.second.first+dx[w],ny=t.second.second+dy[w];
			if(nx<0||ny<0||nx>=n||ny>=m) continue;
			if(c[nx][ny]=='#') continue;
			if(vis[nx][ny]) continue;
			vis[nx][ny]=true;
			int res=min(min(nx,ny),min(n-nx-1,m-ny-1));
			if(res%k==0) res=res/k;
			else res=res/k+1;
			minv=min(minv,res+1);
			q.push(make_pair(t.first+1,make_pair(nx,ny)));
		}
	}
	cout<<minv<<endl;
	return 0;
}
/*
7 7 1
######.
#####..
####..#
###..##
##..###
#S.####
..#####

HAHA!
*/
```


### Prompt

Construct a CPP code solution to the problem outlined:

There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`.

You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing.

The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.

Constraints

* 2 \leq N \leq 3 \times 10^5
* |S| = N
* S_i is `E` or `W`.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the minimum number of people who have to change their directions.

Examples

Input

5
WEEWW

Output

1

Input

12
WEWEWEEEWWWE

Output

4

Input

8
WWWWWEEE

Output

3

### Response

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

int main(){
  int n, mn = 0, t = 0, u = 0;
  string s;
  cin >> n >> s;
  for(int i = 1; i < n; i++){
    t += (s[i-1] == 'W') + (s[i] == 'W') - 1;
    u += (s[i] == 'E');
    mn = min(mn, t);
  }
  printf("%d\n", u+mn);
}
```


### Prompt

Develop a solution in CPP to the problem described below:

The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. As one of them loses, his place is taken by the next randomly chosen Sith who didn't fight before. Does it need to be said that each battle in the Sith Tournament ends with a death of one of opponents? The Tournament ends when the only Sith remains alive.

Jedi Ivan accidentally appeared in the list of the participants in the Sith Tournament. However, his skills in the Light Side of the Force are so strong so he can influence the choice of participants either who start the Tournament or who take the loser's place after each battle. Of course, he won't miss his chance to take advantage of it. Help him to calculate the probability of his victory.

Input

The first line contains a single integer n (1 ≤ n ≤ 18) — the number of participants of the Sith Tournament.

Each of the next n lines contains n real numbers, which form a matrix pij (0 ≤ pij ≤ 1). Each its element pij is the probability that the i-th participant defeats the j-th in a duel.

The elements on the main diagonal pii are equal to zero. For all different i, j the equality pij + pji = 1 holds. All probabilities are given with no more than six decimal places.

Jedi Ivan is the number 1 in the list of the participants.

Output

Output a real number — the probability that Jedi Ivan will stay alive after the Tournament. Absolute or relative error of the answer must not exceed 10 - 6.

Examples

Input

3
0.0 0.5 0.8
0.5 0.0 0.4
0.2 0.6 0.0

Output

0.680000000000000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long sign = 1;
  long long x = 0;
  char ch;
  while (!isdigit(ch = getchar()))
    if (ch == '-') sign = -1;
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * sign;
}
inline void write(long long k) {
  if (k < 0) putchar('-'), k *= -1;
  char ch[20];
  int num = 0;
  while (k) ch[++num] = k % 10, k /= 10;
  if (num == 0) ch[++num] = 0;
  while (num) putchar(ch[num--] + '0');
  putchar('\n');
}
const int N = 18;
int n, best[N];
double p[N][N], dp[N][N];
bool used[N];
int main() {
  n = read();
  for (register long long i = (0); i < (n); i++)
    for (register long long j = (0); j < (n); j++) scanf("%lf", &p[i][j]);
  dp[0][0] = 1;
  used[0] = true;
  for (register long long i = (1); i < (n); i++) {
    for (register long long j = (1); j < (n); j++)
      if (!used[j]) {
        dp[i][j] = dp[i - 1][best[i - 1]] * p[best[i - 1]][j] +
                   dp[i - 1][j] * p[j][best[i - 1]];
        if (dp[i][best[i]] < dp[i][j]) best[i] = j;
      }
    used[best[i]] = true;
  }
  printf("%.15lf", dp[n - 1][best[n - 1]]);
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

You are given an array a of length 2^n. You should process q queries on it. Each query has one of the following 4 types:

  1. Replace(x, k) — change a_x to k;
  2. Reverse(k) — reverse each subarray [(i-1) ⋅ 2^k+1, i ⋅ 2^k] for all i (i ≥ 1);
  3. Swap(k) — swap subarrays [(2i-2) ⋅ 2^k+1, (2i-1) ⋅ 2^k] and [(2i-1) ⋅ 2^k+1, 2i ⋅ 2^k] for all i (i ≥ 1);
  4. Sum(l, r) — print the sum of the elements of subarray [l, r].

Write a program that can quickly process given queries.

Input

The first line contains two integers n, q (0 ≤ n ≤ 18; 1 ≤ q ≤ 10^5) — the length of array a and the number of queries.

The second line contains 2^n integers a_1, a_2, …, a_{2^n} (0 ≤ a_i ≤ 10^9).

Next q lines contains queries — one per line. Each query has one of 4 types:

  * "1 x k" (1 ≤ x ≤ 2^n; 0 ≤ k ≤ 10^9) — Replace(x, k);
  * "2 k" (0 ≤ k ≤ n) — Reverse(k);
  * "3 k" (0 ≤ k < n) — Swap(k);
  * "4 l r" (1 ≤ l ≤ r ≤ 2^n) — Sum(l, r).

It is guaranteed that there is at least one Sum query.

Output

Print the answer for each Sum query.

Examples

Input

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

Output

24

Input

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

Output

29
22
1

Note

In the first sample, initially, the array a is equal to \{7,4,9,9\}.

After processing the first query. the array a becomes \{7,8,9,9\}.

After processing the second query, the array a_i becomes \{9,9,7,8\}

Therefore, the answer to the third query is 9+7+8=24.

In the second sample, initially, the array a is equal to \{7,0,8,8,7,1,5,2\}. What happens next is:

  1. Sum(3, 7) → 8 + 8 + 7 + 1 + 5 = 29;
  2. Reverse(1) → \{0,7,8,8,1,7,2,5\};
  3. Swap(2) → \{1,7,2,5,0,7,8,8\};
  4. Sum(1, 6) → 1 + 7 + 2 + 5 + 0 + 7 = 22;
  5. Reverse(3) → \{8,8,7,0,5,2,7,1\};
  6. Replace(5, 16) → \{8,8,7,0,16,2,7,1\};
  7. Sum(8, 8) → 1;
  8. Swap(0) → \{8,8,0,7,2,16,1,7\}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxN = 1 << 19;
int n, q, mask = 0, k, l, r, x;
ll seg[maxN];
void update(int node) {
  if (node == 0) return;
  seg[node] = seg[node << 1] + seg[(node << 1) + 1];
  update(node / 2);
}
ll query(int node, int level, int left, int right) {
  ll ans = 0;
  if (right - left + 1 == (1 << level)) return seg[node];
  int mid = (1 << level);
  mid = (left / mid) * mid + (mid >> 1);
  int sw = (1 << (level - 1));
  if (right < mid) {
    if (mask & (1 << level)) {
      ans += query(2 * node + 1, level - 1, left + sw, right + sw);
    } else
      ans += query(2 * node, level - 1, left, right);
  } else if (left >= mid) {
    if (mask & (1 << level)) {
      ans += query(2 * node, level - 1, left - sw, right - sw);
    } else
      ans += query(2 * node + 1, level - 1, left, right);
  } else {
    if (mask & (1 << level)) {
      ans += query(2 * node, level - 1, mid - sw, right - sw);
      ans += query(2 * node + 1, level - 1, left + sw, mid + sw - 1);
    } else {
      ans += query(2 * node, level - 1, left, mid - 1);
      ans += query(2 * node + 1, level - 1, mid, right);
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> q;
  for (int i = (1 << n); i < (1 << (n + 1)); ++i) cin >> seg[i];
  for (int i = (1 << n) - 1; i > 0; --i) {
    seg[i] = seg[i << 1] + seg[(i << 1) + 1];
  }
  for (int i = 0; i < q; ++i) {
    int type;
    cin >> type;
    if (type == 1) {
      cin >> x >> k;
      --x;
      x ^= (mask >> 1);
      seg[(1 << n) + x] = k;
      update(((1 << n) + x) / 2);
    }
    if (type == 2) {
      cin >> k;
      mask ^= ((1 << (k + 1)) - 1);
    }
    if (type == 3) {
      cin >> k;
      mask ^= (1 << (k + 1));
    }
    if (type == 4) {
      cin >> l >> r;
      --l, --r;
      cout << query(1, n, l, r) << endl;
    }
  }
  return 0;
}

```


### Prompt

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

Petya has an array a consisting of n integers. He has learned partial sums recently, and now he can calculate the sum of elements on any segment of the array really fast. The segment is a non-empty sequence of elements standing one next to another in the array.

Now he wonders what is the number of segments in his array with the sum less than t. Help Petya to calculate this number.

More formally, you are required to calculate the number of pairs l, r (l ≤ r) such that a_l + a_{l+1} + ... + a_{r-1} + a_r < t.

Input

The first line contains two integers n and t (1 ≤ n ≤ 200 000, |t| ≤ 2⋅10^{14}).

The second line contains a sequence of integers a_1, a_2, ..., a_n (|a_{i}| ≤ 10^{9}) — the description of Petya's array. Note that there might be negative, zero and positive elements.

Output

Print the number of segments in Petya's array with the sum of elements less than t.

Examples

Input

5 4
5 -1 3 4 -1

Output

5

Input

3 0
-1 2 -3

Output

4

Input

4 -1
-2 1 -2 3

Output

3

Note

In the first example the following segments have sum less than 4:

  * [2, 2], sum of elements is -1
  * [2, 3], sum of elements is 2
  * [3, 3], sum of elements is 3
  * [4, 5], sum of elements is 3
  * [5, 5], sum of elements is -1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long t, sum[(200000 + 1000)], refun[(200000 + 1000)], fin, now;
int n, QAQ[(200000 + 1000)], QvQ[(200000 + 1000)];
int lowbit(int x) { return ((x) & (-(x))); }
void Update(int x) {
  for (int i = x; i <= refun[0]; i += lowbit(i)) ++QvQ[i];
}
int Query(int x) {
  int fin = 0;
  for (int i = x; i; i -= lowbit(i)) fin += QvQ[i];
  return fin;
}
int main() {
  cin >> n >> t;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &QAQ[i]);
    sum[i] = sum[i - 1] + QAQ[i];
    refun[++refun[0]] = sum[i];
  }
  refun[++refun[0]] = 0;
  sort(refun + 1, refun + refun[0] + 1);
  refun[0] = unique(refun + 1, refun + refun[0] + 1) - refun - 1;
  for (int i = 1; i <= refun[0]; i++)
    if (!refun[i]) now = i;
  Update(now);
  for (int i = 1; i <= n; i++)
    sum[i] = lower_bound(refun + 1, refun + refun[0] + 1, sum[i]) - refun;
  for (int i = 1; i <= n; i++) {
    long long maxn =
        upper_bound(refun + 1, refun + refun[0] + 1, refun[sum[i]] - t) -
        refun - 1;
    fin += i - Query(maxn);
    Update(sum[i]);
  }
  cout << fin;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

A TV program called "Saizo" is popular in a certain country. In this program, participants challenge field athletics and get a prize if they successfully capture it.

Field athletics are made by arranging blocks of different heights in a row, and how to climb up and down the steps is important for capture (Fig. 1). Your friend who will be attending this show wants you to write a program that calculates the maximum steps you have to climb and the maximum steps you have to descend given a field athletic structure. I asked you, a great programmer.

Example of athletic structure (first dataset of input example).
---
Figure 1: Example of athletic structure (first dataset of input example).

Input

The number of datasets t (0 <t ≤ 100) is given on the first line of the input. This line is followed by t datasets.

The first line of the dataset is the number of blocks that make up the field athletics n (2 ≤ n ≤ 100). In the second line, n integers indicating the height of the block from the start to the goal are given in order. The first corresponds to the start and the nth corresponds to the goal. These integers are separated by a single space character. The height h of each block satisfies 0 <h ≤ 1000.

Output

For each dataset, output the maximum step size you must climb and the maximum step size you must descend on a single line, separated by a single space character. If there is no step to climb or step to descend, the maximum corresponding step size shall be 0.

Example

Input

5
5
10 70 30 50 90
2
20 100
2
100 30
3
50 50 50
7
123 45 678 901 234 567 890

Output

60 40
80 0
0 70
0 0
633 667

### Response

```cpp

#include<iostream>
using namespace std;

int main()
{
  int t,n,h,preH;
  int max,min;
  cin>>t;
  while(cin>>n){
    cin>>preH;
    max=0;
    min=0;
    while(--n>0){
      cin>>h;
      if(max<h-preH)max=h-preH;
      if(h-preH<min)min=h-preH;
      preH=h;
    }
    cout<<max<<" "<<-min<<endl;
  }
}
```


### Prompt

Please create a solution in CPP to the following problem:

Today Pari gave Arya a cool graph problem. Arya wrote a non-optimal solution for it, because he believes in his ability to optimize non-optimal solutions. In addition to being non-optimal, his code was buggy and he tried a lot to optimize it, so the code also became dirty! He keeps getting Time Limit Exceeds and he is disappointed. Suddenly a bright idea came to his mind!

Here is how his dirty code looks like:

    dfs(v)
    {
         set count[v] = count[v] + 1
         if(count[v] < 1000)
         {
              foreach u in neighbors[v]
              {
                   if(visited[u] is equal to false)
                   {
                        dfs(u)
                   }
                   break
              }
         }
         set visited[v] = true
    }

    main()
    {
         input the digraph()
         TOF()
         foreach 1<=i<=n
         {
              set count[i] = 0 , visited[i] = false
         }
         foreach 1 <= v <= n
         {
              if(visited[v] is equal to false)
              {
                   dfs(v)
              }
         }
         ... // And do something cool and magical but we can't tell you what!
    }

He asks you to write the TOF function in order to optimize the running time of the code with minimizing the number of calls of the dfs function. The input is a directed graph and in the TOF function you have to rearrange the edges of the graph in the list neighbors for each vertex. The number of calls of dfs function depends on the arrangement of neighbors of each vertex.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 5000) — the number of vertices and then number of directed edges in the input graph.

Each of the next m lines contains a pair of integers ui and vi (1 ≤ ui, vi ≤ n), meaning there is a directed <image> edge in the input graph.

You may assume that the graph won't contain any self-loops and there is at most one edge between any unordered pair of vertices.

Output

Print a single integer — the minimum possible number of dfs calls that can be achieved with permuting the edges.

Examples

Input

3 3
1 2
2 3
3 1

Output

2998

Input

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

Output

3001

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 5010, INF = 100000000;
vector<int> adj[N][2], cmp[N], vc;
queue<int> q;
int d[N][N], comp[N], c;
bool mark[N], notsink[N], a[N][N], er[N];
void BFS(int s, int f) {
  q.push(s);
  d[s][s] = 0;
  mark[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v : adj[u][f]) {
      if (!mark[v]) {
        q.push(v);
        mark[v] = 1;
        d[s][v] = d[s][u] + 1;
        if (!f) {
          er[v] = 1;
        }
      }
    }
  }
  return;
}
void DFS1(int v) {
  mark[v] = 1;
  for (int u : adj[v][1]) {
    if (!mark[u] && !er[u]) {
      DFS1(u);
    }
  }
  vc.push_back(v);
}
void DFS2(int v, int c) {
  mark[v] = 1;
  comp[v] = c;
  cmp[c].push_back(v);
  for (int u : adj[v][1]) {
    if (!mark[u] && !er[u]) {
      DFS2(u, c);
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m, t(0), ret(0), u, v;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    adj[--u][1].push_back(--v);
    adj[v][0].push_back(u);
    a[u][v] = 1;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      d[i][j] = INF;
    }
    if (adj[i][1].empty()) {
      er[i] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (er[i]) {
      BFS(i, 0);
      memset(mark, 0, sizeof mark);
    }
  }
  for (int i = 0; i < n; i++) {
    if (!mark[i] && !er[i]) {
      BFS(i, 1);
      memset(mark, 0, sizeof mark);
    }
  }
  for (int i = 0; i < n; i++) {
    if (!mark[i] && !er[i]) {
      DFS1(i);
    }
  }
  reverse(vc.begin(), vc.end());
  memset(mark, 0, sizeof mark);
  for (int u : vc) {
    if (!mark[u]) {
      DFS2(u, c);
      c++;
    }
  }
  for (int i = 0; i < n; i++) {
    if (er[i]) {
      continue;
    }
    for (int u : adj[i][1]) {
      if (!er[u] && comp[i] != comp[u]) {
        notsink[comp[i]] = 1;
      }
    }
  }
  for (int i = 0; i < c; i++) {
    if (notsink[i]) {
      continue;
    }
    int mn = INF;
    for (int u : cmp[i]) {
      for (int v : cmp[i]) {
        if (u != v && a[v][u]) {
          mn = min(mn, d[u][v] + 1);
        }
      }
    }
    if (mn != INF) {
      t += mn;
      ret += mn * 999 + 1;
    }
  }
  cout << ret + n - t << endl;
  return 0;
}

```


### Prompt

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

Emuskald was hired to design an artificial waterfall according to the latest trends in landscape architecture. A modern artificial waterfall consists of multiple horizontal panels affixed to a wide flat wall. The water flows down the top of the wall from panel to panel until it reaches the bottom of the wall.

The wall has height t and has n panels on the wall. Each panel is a horizontal segment at height hi which begins at li and ends at ri. The i-th panel connects the points (li, hi) and (ri, hi) of the plane. The top of the wall can be considered a panel connecting the points ( - 109, t) and (109, t). Similarly, the bottom of the wall can be considered a panel connecting the points ( - 109, 0) and (109, 0). No two panels share a common point.

Emuskald knows that for the waterfall to be aesthetically pleasing, it can flow from panel i to panel j (<image>) only if the following conditions hold:

  1. max(li, lj) < min(ri, rj) (horizontal projections of the panels overlap);
  2. hj < hi (panel j is below panel i);
  3. there is no such panel k (hj < hk < hi) that the first two conditions hold for the pairs (i, k) and (k, j).

Then the flow for <image> is equal to min(ri, rj) - max(li, lj), the length of their horizontal projection overlap.

Emuskald has decided that in his waterfall the water will flow in a single path from top to bottom. If water flows to a panel (except the bottom of the wall), the water will fall further to exactly one lower panel. The total amount of water flow in the waterfall is then defined as the minimum horizontal projection overlap between two consecutive panels in the path of the waterfall. Formally:

  1. the waterfall consists of a single path of panels <image>;
  2. the flow of the waterfall is the minimum flow in the path <image>.

To make a truly great waterfall Emuskald must maximize this water flow, but there are too many panels and he is having a hard time planning his creation. Below is an example of a waterfall Emuskald wants:

<image>

Help Emuskald maintain his reputation and find the value of the maximum possible water flow.

Input

The first line of input contains two space-separated integers n and t (1 ≤ n ≤ 105, 2 ≤ t ≤ 109), the number of the panels excluding the top and the bottom panels, and the height of the wall. Each of the n following lines contain three space-separated integers hi, li and ri (0 < hi < t,  - 109 ≤ li < ri ≤ 109), the height, left and right ends of the i-th panel segment.

It is guaranteed that no two segments share a common point.

Output

Output a single integer — the maximum possible amount of water flow in the desired waterfall.

Examples

Input

5 6
4 1 6
3 2 7
5 9 11
3 10 15
1 13 16

Output

4

Input

6 5
4 2 8
3 1 2
2 2 3
2 6 12
1 0 7
1 8 11

Output

2

Note

The first test case corresponds to the picture.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005, inf = 1000000000;
int n, m, i, j;
struct data {
  int h, l, r;
  bool operator<(const data& t) const { return h < t.h; }
} d[maxn];
int Hs[maxn], dp[maxn], tot;
int mark[maxn << 2];
int ll, rr, nam;
void calc() {
  if (nam == -1) return;
  if (min(d[i].r, d[nam].r) - max(d[i].l, d[nam].l) > Hs[rr] - Hs[ll - 1])
    return;
  dp[i] = max(dp[i], min(dp[nam], Hs[rr] - Hs[ll - 1]));
}
void cal(int x, int l, int r, int L, int R) {
  if (~mark[x]) {
    if (mark[x] != nam) {
      calc();
      nam = mark[x];
      ll = L;
    }
    rr = R;
    return;
  }
  int mid = (l + r) >> 1;
  if (R <= mid)
    cal(x << 1, l, mid, L, R);
  else if (L > mid)
    cal(x << 1 | 1, mid + 1, r, L, R);
  else
    cal(x << 1, l, mid, L, mid), cal(x << 1 | 1, mid + 1, r, mid + 1, R);
}
void upd(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    mark[x] = i;
    return;
  }
  if (mark[x] != -1) {
    mark[x << 1] = mark[x << 1 | 1] = mark[x];
    mark[x] = -1;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) upd(x << 1, l, mid, L, R);
  if (R > mid) upd(x << 1 | 1, mid + 1, r, L, R);
}
void build(int x, int l, int r) {
  if (l == r) return;
  mark[x] = -1;
  int mid = (l + r) >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    scanf("%d%d%d", &d[i].h, &d[i].l, &d[i].r), Hs[++tot] = d[i].l,
                                                Hs[++tot] = d[i].r;
  Hs[++tot] = inf;
  Hs[++tot] = -inf;
  sort(Hs + 1, Hs + tot + 1), tot = unique(Hs + 1, Hs + tot + 1) - Hs - 1;
  sort(d + 1, d + n + 1);
  d[0].l = d[n + 1].l = -inf;
  d[0].r = d[n + 1].r = inf;
  dp[0] = 2 * inf;
  build(1, 1, n);
  for (i = 1; i <= n + 1; i++) {
    int l = lower_bound(Hs + 1, Hs + tot + 1, d[i].l) - Hs + 1;
    int r = lower_bound(Hs + 1, Hs + tot + 1, d[i].r) - Hs;
    nam = -1;
    cal(1, 1, tot, l, r);
    calc();
    upd(1, 1, tot, l, r);
  }
  printf("%d\n", dp[n + 1]);
  return 0;
}

```


### Prompt

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

The sequence of integer pairs (a1, b1), (a2, b2), ..., (ak, bk) is beautiful, if the following statements are fulfilled:

  * 1 ≤ a1 ≤ b1 < a2 ≤ b2 < ... < ak ≤ bk ≤ n, where n is a given positive integer;
  * all numbers b1 - a1, b2 - a2, ..., bk - ak are distinct.

For the given number n find the number of beautiful sequences of length k. As the answer can be rather large, print the remainder after dividing it by 1000000007 (109 + 7).

Input

The first line contains integer t (1 ≤ t ≤ 2·105) — the number of the test data.

Each of the next t lines contains two integers n and k (1 ≤ k ≤ n ≤ 1000).

Output

For each test from the input print the answer to the problem modulo 1000000007 (109 + 7). Print the answers to the tests in the order in which the tests are given in the input.

Examples

Input

6
1 1
2 1
2 2
3 1
3 2
3 3

Output

1
3
0
6
2
0

Note

In the first test sample there is exactly one beautiful sequence: (1, 1).

In the second test sample, the following sequences are beautiful:

  * (1, 1);
  * (1, 2);
  * (2, 2).

In the fourth test sample, the following sequences are beautiful:

  * (1, 1);
  * (1, 2);
  * (1, 3);
  * (2, 2);
  * (2, 3);
  * (3, 3).

In the fifth test sample, the following sequences are beautiful:

  * (1, 1), (2, 3);
  * (1, 2), (3, 3).

In the third and sixth samples, there are no beautiful sequences.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[50][1010][1010];
long long fc[1010];
long long c1[1010][1010];
long long pw(long long x, long long p) {
  if (p == 0) return 1;
  long long z = pw(x, p / 2);
  z *= z;
  z %= 1000000007;
  if (p % 2 == 0) return z;
  z *= x;
  z %= 1000000007;
  return z;
}
long long inv(long long x) { return pw(x, 1000000007 - 2); }
long long c(long long x, long long y) {
  if (x < y) swap(x, y);
  if (c1[x][y] != -1) return c1[x][y];
  long long r = fc[y] * fc[x - y];
  r %= 1000000007;
  r = inv(r) * fc[x];
  r %= 1000000007;
  return c1[x][y] = r;
}
int main() {
  memset(c1, -1, sizeof(c1));
  fc[0] = 1;
  for (int i = 1; i < 1010; i++) {
    fc[i] = fc[i - 1] * i;
    fc[i] %= 1000000007;
  }
  for (int i = 0; i < 1010; i++) dp[0][0][i] = 1;
  for (int k = 1; k < 50; k++) {
    for (int i = 1; i < 1010; i++) {
      long long r1 = 0;
      int j = 1;
      for (int pr = 1; pr < 1010; pr++) {
        long long r = 0;
        if (j < pr && i - (j - 1) >= 0) {
          r1 += dp[k - 1][i - (j - 1)][j];
          r1 %= 1000000007;
          j++;
        }
        r += r1;
        r %= 1000000007;
        dp[k][i][pr] = r;
      }
    }
  }
  int t;
  cin >> t;
  int n, k;
  while (t--) {
    scanf("%d%d", &n, &k);
    long long res = 0;
    for (int i = n - (k * (k + 1) / 2); i >= 0; i--) {
      long long r1 = dp[k][n - (i)][1009] * c(i + k, i);
      r1 %= 1000000007;
      r1 *= fc[k];
      r1 %= 1000000007;
      res += r1;
      res %= 1000000007;
    }
    printf("%I64d\n", res);
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:

  * Four sticks represent the animal's legs, these sticks should have the same length.
  * Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.

Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.

Input

The single line contains six space-separated integers li (1 ≤ li ≤ 9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.

Output

If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).

Examples

Input

4 2 5 4 4 4

Output

Bear

Input

4 4 5 4 4 5

Output

Elephant

Input

1 2 3 4 5 6

Output

Alien

Note

If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  const int n = 10;
  int a[n] = {0}, i;
  bool flag = false;
  for (i = 0; i < 6; i++) {
    int x;
    cin >> x;
    a[x]++;
    if (a[x] == 4) flag = true;
  }
  if (!flag)
    cout << "Alien\n";
  else {
    bool flag1 = false;
    for (i = 1; i < n; i++) {
      if (a[i] == 1) {
        flag1 = true;
      }
    }
    if (flag1)
      cout << "Bear\n";
    else
      cout << "Elephant\n";
  }
}

```


### Prompt

Please create a solution in CPP to the following problem:

Amr loves Geometry. One day he came up with a very interesting problem.

Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y').

In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.

Help Amr to achieve his goal in minimum number of steps.

Input

Input consists of 5 space-separated integers r, x, y, x' y' (1 ≤ r ≤ 105,  - 105 ≤ x, y, x', y' ≤ 105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.

Output

Output a single integer — minimum number of steps required to move the center of the circle to the destination point.

Examples

Input

2 0 0 0 4

Output

1

Input

1 1 1 4 4

Output

3

Input

4 5 6 5 6

Output

0

Note

In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  long long r, first, second, a, b;
  cin >> r >> first >> second >> a >> b;
  cout << ceil((sqrt((first - a) * (first - a) + (second - b) * (second - b)) /
                (r * 2.0)))
       << "\n";
}

```


### Prompt

Develop a solution in cpp to the problem described below:

A tree is a connected undirected graph consisting of n vertices and n - 1 edges. Vertices are numbered 1 through n.

Limak is a little polar bear and Radewoosh is his evil enemy. Limak once had a tree but Radewoosh stolen it. Bear is very sad now because he doesn't remember much about the tree — he can tell you only three values n, d and h:

  * The tree had exactly n vertices.
  * The tree had diameter d. In other words, d was the biggest distance between two vertices.
  * Limak also remembers that he once rooted the tree in vertex 1 and after that its height was h. In other words, h was the biggest distance between vertex 1 and some other vertex.

The distance between two vertices of the tree is the number of edges on the simple path between them.

Help Limak to restore his tree. Check whether there exists a tree satisfying the given conditions. Find any such tree and print its edges in any order. It's also possible that Limak made a mistake and there is no suitable tree – in this case print "-1".

Input

The first line contains three integers n, d and h (2 ≤ n ≤ 100 000, 1 ≤ h ≤ d ≤ n - 1) — the number of vertices, diameter, and height after rooting in vertex 1, respectively.

Output

If there is no tree matching what Limak remembers, print the only line with "-1" (without the quotes).

Otherwise, describe any tree matching Limak's description. Print n - 1 lines, each with two space-separated integers – indices of vertices connected by an edge. If there are many valid trees, print any of them. You can print edges in any order.

Examples

Input

5 3 2

Output

1 2
1 3
3 4
3 5

Input

8 5 2

Output

-1

Input

8 4 2

Output

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

Note

Below you can see trees printed to the output in the first sample and the third sample.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d, h;
  cin >> n >> d >> h;
  if (d > h * 2) {
    cout << "-1";
    return 0;
  }
  if (d == 1 && h == 1 && n > 2) {
    cout << "-1";
    return 0;
  }
  if (d == h) {
    int prev = 1;
    for (int i = 2; i <= h + 1; i++) {
      printf("%d %d\n", prev, i);
      prev = i;
    }
    for (int i = h + 2; i <= n; i++) printf("2 %d\n", i);
    return 0;
  }
  int prev = 1;
  for (int i = 2; i <= h + 1; i++) {
    printf("%d %d\n", prev, i);
    prev = i;
  }
  prev = 1;
  for (int i = h + 2; i <= d + 1; i++) {
    printf("%d %d\n", prev, i);
    prev = i;
  }
  for (int i = d + 2; i <= n; i++) printf("1 %d\n", i);
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white.

We will repeatedly perform the following operation until all the squares are black:

* Every white square that shares a side with a black square, becomes black.

Find the number of operations that will be performed. The initial grid has at least one black square.

Constraints

* 1 \leq H,W \leq 1000
* A_{ij} is `#` or `.`.
* The given grid has at least one black square.

Input

Input is given from Standard Input in the following format:

H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}

Output

Print the number of operations that will be performed.

Examples

Input

3 3
...
.#.
...

Output

2

Input

6 6
..#..#
......
..#..
......
.#....
....#.

Output

3

### Response

```cpp
#include<bits/stdc++.h>
#define int long long
using namespace std;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
signed main(){
  int H,W;
  cin>>H>>W;
  vector<string> A(H);
  for(string &S:A)
    cin>>S;
  vector<vector<bool>> B(H,vector<bool>(W,true));
  queue<pair<pair<int,int>,int>> C;
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
      if(A[i][j]=='#'){
        C.push({{i,j},0});
        B[i][j]=false;
      }
  int ans=0;
  while(!C.empty()){
    pair<pair<int,int>,int> p=C.front();
    C.pop();
    ans=max(ans,p.second);
    for(int i=0;i<4;i++){
      int x=p.first.first+dx[i],y=p.first.second+dy[i];
      if(0<=x && x<H && 0<=y && y<W && B[x][y]){
        C.push({{x,y},p.second+1});
        B[x][y]=false;
      }
    }
  }
  cout<<ans<<endl;
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

Find places where a string P is found within a text T. Print all indices of T where P found. The indices of T start with 0.

Constraints

* 1 ≤ length of T ≤ 1000
* 1 ≤ length of P ≤ 1000
* The input consists of alphabetical characters and digits

Input

In the first line, a text T is given. In the second line, a string P is given.

Examples

Input

aabaaa
aa

Output

0
3
4

Input

xyzz
yz

Output

1

Input

abc
xyz

Output

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string T, P;
    cin >> T >> P;
    for (int ti = 0; ti <= (int)(T.size() - P.size()); ti++) {
        int tmp = 0;
        for (int si = 0; si < (ll)P.size(); si++) {
            if (T[ti + si] == P[si]) {
                tmp++;
            }
        }
        // cout << ti << endl;
        if (tmp == (ll)P.size()) {
            cout << ti << endl;
        }
    }
    return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

There is a directed graph with N vertices numbered 1 to N and M edges. The i-th edge is directed from Vertex A_i to Vertex B_i, and there are C_i coins placed along that edge. Additionally, there is a button on Vertex N.

We will play a game on this graph. You start the game on Vertex 1 with zero coins, and head for Vertex N by traversing the edges while collecting coins. It takes one minute to traverse an edge, and you can collect the coins placed along the edge each time you traverse it. As usual in games, even if you traverse an edge once and collect the coins, the same number of coins will reappear next time you traverse that edge, which you can collect again.

When you reach Vertex N, you can end the game by pressing the button. (You can also choose to leave Vertex N without pressing the button and continue traveling.) However, when you end the game, you will be asked to pay T \times P coins, where T is the number of minutes elapsed since the start of the game. If you have less than T \times P coins, you will have to pay all of your coins instead.

Your score will be the number of coins you have after this payment. Determine if there exists a maximum value of the score that can be obtained. If the answer is yes, find that maximum value.

Constraints

* 2 \leq N \leq 2500
* 1 \leq M \leq 5000
* 1 \leq A_i, B_i \leq N
* 1 \leq C_i \leq 10^5
* 0 \leq P \leq 10^5
* All values in input are integers.
* Vertex N can be reached from Vertex 1.

Input

Input is given from Standard Input in the following format:

N M P
A_1 B_1 C_1
:
A_M B_M C_M

Output

If there exists a maximum value of the score that can be obtained, print that maximum value; otherwise, print `-1`.

Examples

Input

3 3 10
1 2 20
2 3 30
1 3 45

Output

35

Input

2 2 10
1 2 100
2 2 100

Output

-1

Input

4 5 10
1 2 1
1 4 1
3 4 1
2 2 100
3 3 100

Output

0

### Response

```cpp
#include<cstdio>
const int N = 5e3+5;
struct Edge{
    int u,v,c;
};
Edge e[N];
int start[N];
int end[N];
int d[N];

int max(int a,int b){ return a>b?a:b; }

int main(){
    int n,m,p;
    scanf("%d%d%d",&n,&m,&p);
    for(int i = 0; i < m; i++){
        scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].c);
        e[i].c -= p;
    }
    d[1] = 0;
    start[1] = 1, end[n] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(end[e[j].v]) end[e[j].u] = 1;
            if(start[e[j].u]){
                if(!start[e[j].v]){
                     start[e[j].v] = 1;
                     d[e[j].v] = d[e[j].u]+e[j].c;
                }
                else d[e[j].v] = max(d[e[j].v],d[e[j].u]+e[j].c);
            }
        }
    }
    int ok = 1;
    for(int i = 0; i < m; i++){
        //存在可达终点的正环才行
        if(d[e[i].v]<d[e[i].u]+e[i].c && end[e[i].v] && start[e[i].u]){
            ok = 0;
            break;
        }
    }
    if(ok && start[n]) printf("%d\n",max(0,d[n]));
    else printf("-1\n");
    return 0;
}
```


### Prompt

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

We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime.

You are given Q queries.

In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.

Constraints

* 1≤Q≤10^5
* 1≤l_i≤r_i≤10^5
* l_i and r_i are odd.
* All input values are integers.

Input

Input is given from Standard Input in the following format:

Q
l_1 r_1
:
l_Q r_Q

Output

Print Q lines. The i-th line (1≤i≤Q) should contain the response to the i-th query.

Examples

Input

1
3 7

Output

2

Input

4
13 13
7 11
7 11
2017 2017

Output

1
0
0
1

Input

6
1 53
13 91
37 55
19 51
73 91
13 49

Output

4
4
1
1
1
2

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<bool> p(100000,1);
  for(int i=2;i<p.size();i++){
    if(!p.at(i))
      continue;
    for(int j=2;i*j<p.size();j++)
      p.at(i*j)=0;
  }
  vector<bool> sp(100000,0);
  for(int i=3;i<p.size();i++)
    sp.at(i)=(p.at(i)&&p.at((i+1)/2));
  vector<int> c(100001,0);
  for(int i=3;i<p.size();i++)
    c.at(i+1)=c.at(i)+(sp.at(i)?1:0);
  int q;
  cin>>q;
  for(int _=0;_<q;_++){
    int l,r;
    cin>>l>>r;
    cout<<c.at(r+1)-c.at(l)<<endl;
  }
}
```


### Prompt

Create a solution in CPP for the following problem:

Formula 1 officials decided to introduce new competition. Cars are replaced by space ships and number of points awarded can differ per race.

Given the current ranking in the competition and points distribution for the next race, your task is to calculate the best possible ranking for a given astronaut after the next race. It's guaranteed that given astronaut will have unique number of points before the race.

Input

The first line contains two integer numbers N (1 ≤ N ≤ 200000) representing number of F1 astronauts, and current position of astronaut D (1 ≤ D ≤ N) you want to calculate best ranking for (no other competitor will have the same number of points before the race).

The second line contains N integer numbers S_k (0 ≤ S_k ≤ 10^8, k=1...N), separated by a single space, representing current ranking of astronauts. Points are sorted in non-increasing order.

The third line contains N integer numbers P_k (0 ≤ P_k ≤ 10^8, k=1...N), separated by a single space, representing point awards for the next race. Points are sorted in non-increasing order, so winner of the race gets the maximum number of points.

Output

Output contains one integer number — the best possible ranking for astronaut after the race. If multiple astronauts have the same score after the race, they all share the best ranking.

Example

Input

4 3
50 30 20 10
15 10 7 3

Output

2

Note

If the third ranked astronaut wins the race, he will have 35 points. He cannot take the leading position, but he can overtake the second position if the second ranked astronaut finishes the race at the last position.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int n, d;
int rnk[200010], pts[200010];
int main() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> rnk[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> pts[i];
  }
  int ult = 0, a = d - 2, b = 1;
  while (a >= 0 && b < n) {
    if (rnk[d - 1] + pts[0] >= rnk[a] + pts[b]) {
      ult++;
      a--;
      b++;
    } else {
      b++;
    }
  }
  cout << d - ult << endl;
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.

One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.

In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The i-th digit of the answer is 1 if and only if the i-th digit of the two given numbers differ. In the other case the i-th digit of the answer is 0.

Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.

Now you are going to take part in Shapur's contest. See if you are faster and more accurate.

Input

There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.

Output

Write one line — the corresponding answer. Do not omit the leading 0s.

Examples

Input

1010100
0100101

Output

1110001

Input

000
111

Output

111

Input

1110
1010

Output

0100

Input

01110
01100

Output

00010

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string str1, str2;
  cin >> str1 >> str2;
  int len = str1.length();
  int str3[len], i;
  for (i = 0; i < len; i++) {
    if (str1[i] == str2[i]) {
      str3[i] = 0;
    } else
      str3[i] = 1;
  }
  for (i = 0; i < len; i++) cout << str3[i];
  return 0;
}

```


### Prompt

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

In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.

A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.

You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.

Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so.

Input

The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively.

Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v).

You may assume that there is at most one railway connecting any two towns.

Output

Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output  - 1.

Examples

Input

4 2
1 3
3 4

Output

2

Input

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

Output

-1

Input

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

Output

3

Note

In the first sample, the train can take the route <image> and the bus can take the route <image>. Note that they can arrive at town 4 at the same time.

In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 50000;
int e[400][400];
int n, m;
int d[400][2];
int add[400][2];
void Dijkstra(int x) {
  auto lam = [=](pair<int, int> a, pair<int, int> b) {
    if (d[a.first][a.second] == d[b.first][b.second])
      return (a.first == b.first ? a.second < b.second : a.first < b.first);
    else
      return d[a.first][a.second] < d[b.first][b.second];
  };
  set<pair<int, int>, decltype(lam)> s(lam);
  d[x][0] = d[x][1] = 0;
  s.insert({x, 0});
  s.insert({x, 1});
  add[x][0] = add[x][1] = 1;
  while (s.size()) {
    pair<int, int> y;
    y = *s.begin();
    add[y.first][y.second] = 2;
    s.erase(s.begin());
    for (int i = 0; i < n; i++) {
      if (i == y.first) continue;
      if (e[y.first][i] != y.second) continue;
      int t = i;
      if (add[t][y.second] == 0) {
        if (d[y.first][y.second] + 1 == d[t][!y.second])
          d[t][y.second] = min(d[y.first][y.second] + 3, d[t][y.second]);
        else
          d[t][y.second] = d[y.first][y.second] + 1;
        s.insert({t, y.second});
        add[t][y.second] = 1;
      } else if (add[t][y.second] == 2)
        continue;
      else if (d[y.first][y.second] + 1 < d[t][y.second]) {
        s.erase(s.find({t, y.second}));
        if (d[y.first][y.second] + 1 == d[t][!y.second])
          d[t][y.second] = min(d[y.first][y.second] + 3, d[t][y.second]);
        else
          d[t][y.second] = d[y.first][y.second] + 1;
        s.insert({t, y.second});
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    e[u][v] = 1;
    e[v][u] = 1;
  }
  for (int i = 0; i < n; i++) d[i][0] = d[i][1] = INF;
  Dijkstra(0);
  int x = max(d[n - 1][0], d[n - 1][1]);
  if (x == INF)
    cout << "-1";
  else
    cout << x;
  return 0;
}

```


### Prompt

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

Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.

In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to k. The worst mark is 1, the best is k. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8.

For instance, if Noora has marks [8, 9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8, 8, 9], Noora will have graduation certificate with 8.

To graduate with «A» certificate, Noora has to have mark k.

Noora got n marks in register this year. However, she is afraid that her marks are not enough to get final mark k. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to k. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to k.

Input

The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100) denoting the number of marks, received by Noora and the value of highest possible mark.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ k) denoting marks received by Noora before Leha's hack.

Output

Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to k.

Examples

Input

2 10
8 9

Output

4

Input

3 5
4 4 4

Output

3

Note

Consider the first example testcase.

Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <image>. Consequently, new final mark is 10. Less number of marks won't fix the situation.

In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int root(int arr[], int i) {
  while (arr[i] != i) {
    arr[i] = arr[arr[i]];
    i = arr[i];
  }
  return i;
}
void Union(int arr[], int Size[], int a, int b) {
  int rootA = root(arr, a);
  int rootB = root(arr, b);
  if (Size[rootA] < Size[rootB]) {
    arr[rootA] = arr[rootB];
    Size[rootB] += Size[rootA];
  } else {
    arr[rootB] = arr[rootA];
    Size[rootA] += Size[rootB];
  }
}
bool findRoot(int a, int b, int arr[]) {
  if (root(arr, a) == root(arr, b))
    return true;
  else
    return false;
}
vector<vector<int> > adj(105);
bool nCyc = false;
int vis[55][55];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int a, b, c, cnt = 0, c2 = 0;
int dp[105][105];
string s1, s2;
int solve(int i, int val) { return 0; }
int freq[1000005], check[1000005];
int main() {
  int n, k;
  double sum = 0.0;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i], sum += arr[i];
  if (round((sum / (double)n)) == k)
    cout << 0;
  else {
    for (int i = 1; i < 1000000; i++) {
      double nSum = round((sum + (double)i * k));
      nSum /= (double)n + i;
      if (round(nSum) == k) {
        cout << i;
        return 0;
      }
    }
  }
  return 0;
}

```


### Prompt

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

Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).

Consider a sequence A satisfying the following conditions:

* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.

Let us define a score of this sequence as follows:

* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)

Find the maximum possible score of A.

Constraints

* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )

Input

Input is given from Standard Input in the following format:

N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q

Output

Print the maximum possible score of A.

Examples

Input

3 4 3
1 3 3 100
1 2 2 10
2 3 2 10

Output

110

Input

4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328

Output

357500

Input

10 10 1
1 10 9 1

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n,m,q;
vector <int> a,b,c,d;
int ans;
void dfs(vector <int> A)
{
	if(A.size()==n+1)
	{
		int now=0;
		for(int i=0;i<q;i++)
		{
			if(A[b[i]]-A[a[i]]==c[i])
			now+=d[i];
		}
		ans=max(ans,now);
		return;
	}
	A.push_back(A.back());
	while(A.back()<=m)
	{
		dfs(A);
		A.back()++;
	}
}
int main()
{
	cin>>n>>m>>q;
	a=b=c=d=vector<int>(q);
	for(int i=0;i<q;i++)
	{
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	}
	dfs(vector<int>(1,1));
	cout<<ans<<" ";
	return 0;
}

```


### Prompt

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

A cheetah and a cheater are going to play the game of Nim. In this game they use N piles of stones. Initially the i-th pile contains a_i stones. The players take turns alternately, and the cheetah plays first. In each turn, the player chooses one of the piles, and takes one or more stones from the pile. The player who can't make a move loses.

However, before the game starts, the cheater wants to cheat a bit to make sure that he can win regardless of the moves by the cheetah. From each pile, the cheater takes zero or one stone and eats it before the game. In case there are multiple ways to guarantee his winning, he wants to minimize the number of stones he eats.

Compute the number of stones the cheater will eat. In case there is no way for the cheater to win the game even with the cheating, print `-1` instead.

Constraints

* 1 ≤ N ≤ 10^5
* 2 ≤ a_i ≤ 10^9

Input

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

N
a_1
:
a_N

Output

Print the answer.

Examples

Input

3
2
3
4

Output

3

Input

3
100
100
100

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

int main(){
    int N,total=0;cin>>N;
    vector<int> A(N),B(31,0);
    for(int i=0;i<N;i++){
        cin>>A[i];
        for(int j=0;j<31;j++){
            if(A[i]&(1<<j)){ B[j]++;
            break;
            }
        }
        total=total^A[i];
    }

    int ans=0;

    for(int j=30;j>=0;j--){
        if(total&(1<<j)){
            if(B[j]){
                ans++;
                total=(total^(1<<j))^((1<<j)-1);
            }else ans-=1000;
        }
    }

    if(ans>=0) cout<<ans<<endl;
    else cout<<-1<<endl;
}
```


### Prompt

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

You are given a rectangular parallelepiped with sides of positive integer lengths A, B and C.

Find the number of different groups of three integers (a, b, c) such that 1≤ a≤ b≤ c and parallelepiped A× B× C can be paved with parallelepipeds a× b× c. Note, that all small parallelepipeds have to be rotated in the same direction.

For example, parallelepiped 1× 5× 6 can be divided into parallelepipeds 1× 3× 5, but can not be divided into parallelepipeds 1× 2× 3.

Input

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

Each of the next t lines contains three integers A, B and C (1 ≤ A, B, C ≤ 10^5) — the sizes of the parallelepiped.

Output

For each test case, print the number of different groups of three points that satisfy all given conditions.

Example

Input

4
1 1 1
1 6 1
2 2 2
100 100 100

Output

1
4
4
165

Note

In the first test case, rectangular parallelepiped (1, 1, 1) can be only divided into rectangular parallelepiped with sizes (1, 1, 1).

In the second test case, rectangular parallelepiped (1, 6, 1) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 1, 3) and (1, 1, 6).

In the third test case, rectangular parallelepiped (2, 2, 2) can be divided into rectangular parallelepipeds with sizes (1, 1, 1), (1, 1, 2), (1, 2, 2) and (2, 2, 2).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 100010, M = 1024;
int t, a, b, c, ans = 0, i, j, k, arr[N], tmp1, tmp2, tmp3, dp[8][8][8], cur[8],
                idx, l;
vector<int> divv[N];
bool A, B, C, can[8][8][8];
int main() {
  int mx = 0;
  for (int i = 1; i < N; i++) {
    for (int j = i; j < N; j += i) divv[j].push_back(i);
  }
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      for (int k = 0; k < 8; k++) {
        vector<int> v;
        v.push_back(i);
        v.push_back(j);
        v.push_back(k);
        sort(v.begin(), v.end());
        do {
          if (((v[0] & 1) == 1) && ((v[1] & 2) == 2) && ((v[2] & 4) == 4))
            can[i][j][k] = true;
        } while (next_permutation(v.begin(), v.end()));
      }
    }
  }
  cin >> t;
  while (t--) {
    scanf("%d%d%d", &a, &b, &c);
    idx = i = j = k = 0;
    while (i < (int)divv[a].size() || j < (int)divv[b].size() ||
           k < (int)divv[c].size()) {
      tmp1 = tmp2 = tmp3 = 2000000000;
      if (i < (int)divv[a].size()) tmp1 = divv[a][i];
      if (j < (int)divv[b].size()) tmp2 = divv[b][j];
      if (k < (int)divv[c].size()) tmp3 = divv[c][k];
      if (tmp1 <= tmp2 && tmp1 <= tmp3) {
        if (idx == 0 || arr[idx - 1] < tmp1) arr[idx++] = tmp1;
        i++;
      } else if (tmp2 <= tmp3) {
        if (idx == 0 || arr[idx - 1] < tmp2) arr[idx++] = tmp2;
        j++;
      } else {
        if (idx == 0 || arr[idx - 1] < tmp3) arr[idx++] = tmp3;
        k++;
      }
    }
    memset(cur, 0, sizeof(cur));
    for (i = 0; i < idx; i++) {
      l = 0;
      if (a % arr[i] == 0) l |= 1;
      if (b % arr[i] == 0) l |= 2;
      if (c % arr[i] == 0) l |= 4;
      cur[l]++;
    }
    ans = 0;
    for (int i = 0; i < 8; i++) {
      for (int j = i; j < 8; j++) {
        for (int k = j; k < 8; k++) {
          if (!can[i][j][k]) continue;
          if (i == j && i == k) {
            ans += cur[i] * (cur[i] + 1) * (cur[i] + 2) / 6;
            continue;
          }
          if (i == j && i != k) {
            ans += cur[i] * (cur[i] + 1) / 2 * cur[k];
            continue;
          }
          if (i == k && j != i) {
            ans += cur[i] * (cur[i] + 1) / 2 * cur[j];
            continue;
          }
          if (j == k && i != j) {
            ans += cur[j] * (cur[j] + 1) / 2 * cur[i];
            continue;
          }
          ans += cur[i] * cur[j] * cur[k];
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

There are N oases on a number line. The coordinate of the i-th oases from the left is x_i.

Camel hopes to visit all these oases. Initially, the volume of the hump on his back is V. When the volume of the hump is v, water of volume at most v can be stored. Water is only supplied at oases. He can get as much water as he can store at a oasis, and the same oasis can be used any number of times.

Camel can travel on the line by either walking or jumping:

* Walking over a distance of d costs water of volume d from the hump. A walk that leads to a negative amount of stored water cannot be done.
* Let v be the amount of water stored at the moment. When v>0, Camel can jump to any point on the line of his choice. After this move, the volume of the hump becomes v/2 (rounded down to the nearest integer), and the amount of stored water becomes 0.

For each of the oases, determine whether it is possible to start from that oasis and visit all the oases.

Constraints

* 2 ≤ N,V ≤ 2 × 10^5
* -10^9 ≤ x_1 < x_2 < ... < x_N ≤ 10^9
* V and x_i are all integers.

Input

Input is given from Standard Input in the following format:

N V
x_1 x_2 ... x_{N}

Output

Print N lines. The i-th line should contain `Possible` if it is possible to start from the i-th oasis and visit all the oases, and `Impossible` otherwise.

Examples

Input

3 2
1 3 6

Output

Possible
Possible
Possible

Input

7 2
-10 -4 -2 0 2 4 10

Output

Impossible
Possible
Possible
Possible
Possible
Possible
Impossible

Input

16 19
-49 -48 -33 -30 -21 -14 0 15 19 23 44 52 80 81 82 84

Output

Possible
Possible
Possible
Possible
Possible
Possible
Possible
Possible
Possible
Possible
Possible
Possible
Impossible
Impossible
Impossible
Impossible

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int read(){
	int x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)&&ch!='-')
		ch=getchar();
	if (ch=='-')
		f=-1,ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f;
}
const int N=1050005;
int n,v;
int x[N];
int R[20][N],L[20][N],mR[N],mL[N];
int Max[N];
int main(){
	n=read(),v=read();
	for (int i=1;i<=n;i++)
		x[i]=read();
	int d;
	for (d=0;d<20;d++){
		int k=v>>d;
		for (int i=1,j;i<=n;i=j+1){
			for (j=i;j<n&&x[j+1]-x[j]<=k;j++);
			for (int k=i;k<=j;k++)
				L[d][k]=i,R[d][k]=j;
		}
		if (k==0)
			break;
	}
	for (int i=0;i<=d;i++)
		R[i][n+1]=n,L[i][0]=1;
	for (int i=0;i<(1<<d);i++)
		mR[i]=0,mL[i]=n+1;
	for (int i=1;i<(1<<d);i++)
		for (int j=0;j<d;j++)
			if (i>>j&1){
				mR[i]=max(mR[i],R[j+1][mR[i^(1<<j)]+1]);
				mL[i]=min(mL[i],L[j+1][mL[i^(1<<j)]-1]);
			}
	int base=(1<<d)-1;
	memset(Max,-1,sizeof Max);
	for (int i=0;i<(1<<d);i++){
		int x=i,y=i^base;
		Max[mL[x]]=max(Max[mL[x]],mR[y]);
	}
	for (int i=2;i<=n+1;i++)
		Max[i]=max(Max[i],Max[i-1]);
	for (int i=1;i<=n;i++){
		int l=L[0][i],r=R[0][i];
		puts(Max[r+1]>=l-1?"Possible":"Impossible");
	}
	return 0;
}
```


### Prompt

Construct a cpp code solution to the problem outlined:

If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.

<image>

However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat.

<image>

You have met a cat. Can you figure out whether it's normal or grumpy?

Interaction

This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9.

In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase.

Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out.

Note

Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string normal_responses[5] = {"great", "cool", "don't think so", "not bad",
                                "don't touch me"};
  for (int i = 0; i < 10; i++) {
    cout << i << "\n";
    cout << flush;
    string s;
    getline(cin, s);
    bool normal = false;
    for (string r : normal_responses) {
      if (r == s || r + "!" == s) {
        normal = true;
      }
    }
    if (normal) {
      cout << "normal\n";
      return 0;
    } else if (s != "no") {
      cout << "grumpy\n";
      return 0;
    }
  }
  cout << "fuck\n";
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Graph constructive problems are back! This time the graph you are asked to build should match the following properties.

The graph is connected if and only if there exists a path between every pair of vertices.

The diameter (aka "longest shortest path") of a connected undirected graph is the maximum number of edges in the shortest path between any pair of its vertices.

The degree of a vertex is the number of edges incident to it.

Given a sequence of n integers a_1, a_2, ..., a_n construct a connected undirected graph of n vertices such that:

  * the graph contains no self-loops and no multiple edges;
  * the degree d_i of the i-th vertex doesn't exceed a_i (i.e. d_i ≤ a_i);
  * the diameter of the graph is maximum possible.

Output the resulting graph or report that no solution exists.

Input

The first line contains a single integer n (3 ≤ n ≤ 500) — the number of vertices in the graph.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n - 1) — the upper limits to vertex degrees.

Output

Print "NO" if no graph can be constructed under the given conditions.

Otherwise print "YES" and the diameter of the resulting graph in the first line.

The second line should contain a single integer m — the number of edges in the resulting graph.

The i-th of the next m lines should contain two integers v_i, u_i (1 ≤ v_i, u_i ≤ n, v_i ≠ u_i) — the description of the i-th edge. The graph should contain no multiple edges — for each pair (x, y) you output, you should output no more pairs (x, y) or (y, x).

Examples

Input

3
2 2 2

Output

YES 2
2
1 2
2 3

Input

5
1 4 1 1 1

Output

YES 2
4
1 2
3 2
4 2
5 2

Input

3
1 1 1

Output

NO

Note

Here are the graphs for the first two example cases. Both have diameter of 2.

<image> d_1 = 1 ≤ a_1 = 2

d_2 = 2 ≤ a_2 = 2

d_3 = 1 ≤ a_3 = 2

<image> d_1 = 1 ≤ a_1 = 1

d_2 = 4 ≤ a_2 = 4

d_3 = 1 ≤ a_3 = 1

d_4 = 1 ≤ a_4 = 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long t, n, i, j, k, x, y, z, l, r, mid, ans, mod = 1e9 + 7, g, m;
long long b[400005], c[400005];
char ch;
string s, st;
vector<pair<long long, long long> > u;
struct num {
  long long x, y;
} a[200005];
bool srt(num a, num b) { return a.x > b.x; }
int main() {
  ios::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i].x, a[i].y = i + 1;
  sort(a, a + n, srt);
  for (i = 1; i < n && a[0].x; i++)
    if (a[i].x > 1)
      u.push_back({i, i - 1}), a[i].x--, a[i - 1].x--;
    else if (j == 0)
      u.push_back({i, i - 1}), a[i].x--, a[i - 1].x--, j++;
    else if (j == 1)
      u.push_back({i, 0}), a[i].x--, a[0].x--, j++;
    else
      break;
  z = i - 1;
  if (z == 1) z++;
  for (i; i < n; i++) {
    for (j = 0; j < i && a[i].x; j++)
      if (a[j].x) u.push_back({j, i}), a[i].x--, a[j].x--;
    if (a[i].x) return cout << "NO", 0;
  }
  cout << "YES " << z << "\n" << n - 1 << "\n";
  for (auto i : u) cout << a[i.first].y << " " << a[i.second].y << "\n";
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Vasya has recently finished writing a book. Now he faces the problem of giving it the title. Vasya wants the title to be vague and mysterious for his book to be noticeable among others. That's why the title should be represented by a single word containing at least once each of the first k Latin letters and not containing any other ones. Also, the title should be a palindrome, that is it should be read similarly from the left to the right and from the right to the left.

Vasya has already composed the approximate variant of the title. You are given the title template s consisting of lowercase Latin letters and question marks. Your task is to replace all the question marks by lowercase Latin letters so that the resulting word satisfies the requirements, described above. Each question mark should be replaced by exactly one letter, it is not allowed to delete characters or add new ones to the template. If there are several suitable titles, choose the first in the alphabetical order, for Vasya's book to appear as early as possible in all the catalogues.

Input

The first line contains an integer k (1 ≤ k ≤ 26) which is the number of allowed alphabet letters. The second line contains s which is the given template. In s only the first k lowercase letters of Latin alphabet and question marks can be present, the length of s is from 1 to 100 characters inclusively.

Output

If there is no solution, print IMPOSSIBLE. Otherwise, a single line should contain the required title, satisfying the given template. The title should be a palindrome and it can only contain the first k letters of the Latin alphabet. At that, each of those k letters must be present at least once. If there are several suitable titles, print the lexicographically minimal one.

The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if exists such an i (1 ≤ i ≤ |s|), that ai < bi, and for any j (1 ≤ j < i) aj = bj. |s| stands for the length of the given template.

Examples

Input

3
a?c

Output

IMPOSSIBLE

Input

2
a??a

Output

abba

Input

2
?b?a

Output

abba

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int k;
string s;
set<char> st;
int main() {
  cin >> k >> s;
  for (int i = 0; i < k; i++) st.insert('a' + i);
  for (int i = 0; i < s.size(); i++)
    if (st.find(s[i]) != st.end()) st.erase(s[i]);
  int Have = 0;
  for (int i = 0; i < (s.size() + 1) / 2; i++) {
    if (s[i] == '?' && s[s.size() - i - 1] == '?') Have++;
  }
  bool check = true;
  for (int i = 0; i < (s.size() + 1) / 2; i++) {
    if (s[i] == '?' && s[s.size() - i - 1] == '?') {
      if (Have - st.size() > 0)
        s[i] = 'a', s[s.size() - i - 1] = 'a';
      else
        s[i] = *st.begin(), s[s.size() - i - 1] = *st.begin(),
        st.erase(st.begin());
      Have--;
    } else if (s[i] != '?' && s[s.size() - i - 1] != '?') {
      if (s[i] != s[s.size() - i - 1]) check = false;
    } else {
      if (s[i] == '?')
        s[i] = s[s.size() - i - 1];
      else
        s[s.size() - i - 1] = s[i];
    }
  }
  if (st.size() || !check)
    cout << "IMPOSSIBLE";
  else
    cout << s;
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Given a sequence of integers a1, ..., an and q queries x1, ..., xq on it. For each query xi you have to count the number of pairs (l, r) such that 1 ≤ l ≤ r ≤ n and gcd(al, al + 1, ..., ar) = xi.

<image> is a greatest common divisor of v1, v2, ..., vn, that is equal to a largest positive integer that divides all vi.

Input

The first line of the input contains integer n, (1 ≤ n ≤ 105), denoting the length of the sequence. The next line contains n space separated integers a1, ..., an, (1 ≤ ai ≤ 109).

The third line of the input contains integer q, (1 ≤ q ≤ 3 × 105), denoting the number of queries. Then follows q lines, each contain an integer xi, (1 ≤ xi ≤ 109).

Output

For each query print the result in a separate line.

Examples

Input

3
2 6 3
5
1
2
3
4
6

Output

1
2
2
0
1

Input

7
10 20 3 15 1000 60 16
10
1
2
3
4
5
6
10
20
60
1000

Output

14
0
2
2
2
0
2
2
1
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
using vi = vector<int>;
using vi64 = vector<int64>;
using mii = map<int, int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vpii = vector<pii>;
const int inf = 2e9 + 517;
const int mod = 1e9 + 7;
const char nwl = '\n';
const char tab = '\t';
const char space = ' ';
const int mxx = 1e5 + 543;
int64 sumV(vi &v) {
  int64 s = 0;
  for (int x : v) {
    s += (int64)x;
  }
  return s;
}
int gcd(int a, int b) {
  if (!b) return a;
  return gcd(b, a % b);
}
bool powerOf2(int n) {
  if (n & (n - 1)) return 0;
  return 1;
}
int arr[mxx], dp[26][mxx];
int fun(int a, int b) { return gcd(a, b); }
void buildtable(int n) {
  for (int i = 0; i < n; i++) {
    dp[0][i] = arr[i];
  }
  int k = log2(n);
  for (int i = 1; i <= k; i++) {
    int p = pow(2, i - 1);
    for (int j = 0; j < n; j++) {
      if (j + p * 2 <= n) {
        dp[i][j] = fun(dp[i - 1][j], dp[i - 1][j + p]);
      } else {
        break;
      }
    }
  }
}
int getbw_l_r(int l, int r) {
  if (l == r) return arr[l];
  int p = (r - l + 1);
  int c = log2(p);
  p = 1 << c;
  return fun(dp[c][l], dp[c][r - p + 1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  buildtable(n);
  map<int, int64> res;
  for (int i = 0; i < n; i++) {
    int cur = arr[i];
    int last = i;
    while (last < n) {
      int low = last;
      int up = n - 1;
      while (low < up) {
        int m = (up - low + 1) / 2;
        m += low;
        int u = getbw_l_r(i, m);
        if (u == cur)
          low = m;
        else
          up = m - 1;
      }
      res[cur] += (int64)(low - last + 1);
      last = low + 1;
      cur = getbw_l_r(i, last);
    }
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int x;
    cin >> x;
    cout << res[x] << nwl;
  }
  return 0;
}

```


### Prompt

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

As the boat drifts down the river, a wood full of blossoms shows up on the riverfront.

"I've been here once," Mino exclaims with delight, "it's breathtakingly amazing."

"What is it like?"

"Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?"

There are four kinds of flowers in the wood, Amaranths, Begonias, Centaureas and Dianthuses.

The wood can be represented by a rectangular grid of n rows and m columns. In each cell of the grid, there is exactly one type of flowers.

According to Mino, the numbers of connected components formed by each kind of flowers are a, b, c and d respectively. Two cells are considered in the same connected component if and only if a path exists between them that moves between cells sharing common edges and passes only through cells containing the same flowers.

You are to help Kanno depict such a grid of flowers, with n and m arbitrarily chosen under the constraints given below. It can be shown that at least one solution exists under the constraints of this problem.

Note that you can choose arbitrary n and m under the constraints below, they are not given in the input.

Input

The first and only line of input contains four space-separated integers a, b, c and d (1 ≤ a, b, c, d ≤ 100) — the required number of connected components of Amaranths, Begonias, Centaureas and Dianthuses, respectively.

Output

In the first line, output two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and the number of columns in the grid respectively.

Then output n lines each consisting of m consecutive English letters, representing one row of the grid. Each letter should be among 'A', 'B', 'C' and 'D', representing Amaranths, Begonias, Centaureas and Dianthuses, respectively.

In case there are multiple solutions, print any. You can output each letter in either case (upper or lower).

Examples

Input

5 3 2 1

Output

4 7
DDDDDDD
DABACAD
DBABACD
DDDDDDD

Input

50 50 1 1

Output

4 50
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
ABABABABABABABABABABABABABABABABABABABABABABABABAB
BABABABABABABABABABABABABABABABABABABABABABABABABA
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD

Input

1 6 4 5

Output

7 7
DDDDDDD
DDDBDBD
DDCDCDD
DBDADBD
DDCDCDD
DBDBDDD
DDDDDDD

Note

In the first example, each cell of Amaranths, Begonias and Centaureas forms a connected component, while all the Dianthuses form one.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string mat[55];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cin.tie(0), cout.tie(0),
      cout.precision(15);
  int a, b, c, d;
  for (int i = int(0); i < int(50); i++) {
    for (int j = int(0); j < int(50); j++) {
      mat[i] += " ";
    }
  }
  while (cin >> a >> b >> c >> d) {
    pair<int, char> arr[] = {pair<int, char>(a, 'A'), pair<int, char>(b, 'B'),
                             pair<int, char>(c, 'C'), pair<int, char>(d, 'D')};
    sort(arr, arr + 4);
    for (int i = int(0); i < int(50); i++) {
      for (int j = int(0); j < int(50); j++) {
        mat[i][j] = arr[0].second;
      }
    }
    int x = 0;
    if (arr[0].first != 1) {
      bool v = 1;
      int w = 1;
      arr[1].first--;
      for (int i = 0; v && i < 50; i += 2) {
        for (int j = 0; v && j < 50; j += 2) {
          mat[i][j + 1] = arr[1].second;
          mat[i + 1][j] = arr[1].second;
          mat[i + 1][j + 1] = arr[1].second;
          arr[0].first--;
          if (arr[0].first == 2) {
            x = i + 3;
            v = 0;
          }
        }
        if (!v) break;
      }
      arr[1].first--;
      arr[0].first--;
      for (int i = int(0); i < int(50); i++) {
        mat[x][i] = arr[1].second;
      }
    }
    x += 2;
    for (int i = x, k = 1; k < 4 && i < 50; i += 2) {
      for (int j = 0; k < 4 && j < 50; j += 2) {
        while (k < 4 && arr[k].first == 0) k++;
        if (k == 4) continue;
        arr[k].first--;
        mat[i][j] = arr[k].second;
      }
    }
    cout << "50 50" << endl;
    for (int i = int(0); i < int(50); i++) {
      for (int j = int(0); j < int(50); j++) {
        cout << mat[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

```


### Prompt

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

Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.

Recently, she was presented with an array a of the size of 10^9 elements that is filled as follows:

  * a_1 = -1
  * a_2 = 2
  * a_3 = -3
  * a_4 = 4
  * a_5 = -5
  * And so on ...

That is, the value of the i-th element of the array a is calculated using the formula a_i = i ⋅ (-1)^i.

She immediately came up with q queries on this array. Each query is described with two numbers: l and r. The answer to a query is the sum of all the elements of the array at positions from l to r inclusive.

Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.

Help her find the answers!

Input

The first line contains a single integer q (1 ≤ q ≤ 10^3) — the number of the queries.

Each of the next q lines contains two integers l and r (1 ≤ l ≤ r ≤ 10^9) — the descriptions of the queries.

Output

Print q lines, each containing one number — the answer to the query.

Example

Input

5
1 3
2 5
5 5
4 4
2 3

Output

-2
-2
-5
4
-1

Note

In the first query, you need to find the sum of the elements of the array from position 1 to position 3. The sum is equal to a_1 + a_2 + a_3 = -1 + 2 -3 = -2.

In the second query, you need to find the sum of the elements of the array from position 2 to position 5. The sum is equal to a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2.

In the third query, you need to find the sum of the elements of the array from position 5 to position 5. The sum is equal to a_5 = -5.

In the fourth query, you need to find the sum of the elements of the array from position 4 to position 4. The sum is equal to a_4 = 4.

In the fifth query, you need to find the sum of the elements of the array from position 2 to position 3. The sum is equal to a_2 + a_3 = 2 - 3 = -1.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    long long l, r;
    scanf("%lld%lld", &l, &r);
    long long answer = 0;
    if (l % 2 == 1) {
      long long n;
      if (r % 2 == 1) {
        n = (r - l + 2) / 2;
      } else {
        n = (r - 1 - l + 2) / 2;
      }
      if (n > 0) {
        answer -= n * (2 * l + 2 * (n - 1)) / 2;
      }
    } else {
      int n;
      if (r % 2 == 1) {
        n = (r - (l + 1) + 2) / 2;
      } else {
        n = (r - 1 - (l + 1) + 2) / 2;
      }
      if (n > 0) {
        answer -= n * (2 * (l + 1) + 2 * (n - 1)) / 2;
      }
    }
    if (l % 2 == 0) {
      int n;
      if (r % 2 == 0) {
        n = (r - l + 2) / 2;
      } else {
        n = (r - 1 - l + 2) / 2;
      }
      if (n > 0) {
        answer += n * (2 * l + 2 * (n - 1)) / 2;
      }
    } else {
      int n;
      if (r % 2 == 0) {
        n = (r - (l + 1) + 2) / 2;
      } else {
        n = (r - 1 - (l + 1) + 2) / 2;
      }
      if (n > 0) {
        answer += n * (2 * (l + 1) + 2 * (n - 1)) / 2;
      }
    }
    printf("%lld\n", answer);
  }
}

```


### Prompt

Please formulate a cpp solution to the following problem:

This is an easier version of the next problem. The difference is only in constraints.

You are given a rectangular n × m matrix a. In one move you can choose any column and cyclically shift elements in this column. You can perform this operation as many times as you want (possibly zero). You can perform this operation to a column multiple times.

After you are done with cyclical shifts, you compute for every row the maximal value in it. Suppose that for i-th row it is equal r_i. What is the maximal possible value of r_1+r_2+…+r_n?

Input

The first line contains an integer t (1 ≤ t ≤ 40), the number of test cases in the input.

The first line of each test case contains integers n and m (1 ≤ n ≤ 4, 1 ≤ m ≤ 100) — the number of rows and the number of columns in the given matrix a.

Each of the following n lines contains m integers, the elements of a (1 ≤ a_{i, j} ≤ 10^5).

Output

Print t integers: answers for all test cases in the order they are given in the input.

Example

Input

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

Output

12
29

Note

In the first test case, you can shift the third column down by one, this way there will be r_1 = 5 and r_2 = 7.

In the second case you can don't rotate anything at all, this way there will be r_1 = r_2 = 10 and r_3 = 9.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
struct col {
  int row[15], maxe;
};
col cols[2010];
int dp[15][1 << 15], sum[15][1 << 15];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) cin >> cols[j].row[i];
    }
    for (int i = 0; i < m; ++i)
      cols[i].maxe = *max_element(cols[i].row, cols[i].row + n);
    sort(cols, cols + m, [&](col i, col j) { return i.maxe > j.maxe; });
    memset(sum, 0, sizeof sum);
    for (int i = 0; i < min(n, m); i++) {
      for (int choose = 1; choose < (1 << n); choose++) {
        for (int shift = 0; shift < n; shift++) {
          int mask = choose << shift;
          mask |= mask >> n;
          int cur = 0;
          for (int j = 0; j < n; j++) {
            if (mask >> j & 1) {
              cur += cols[i].row[j];
            }
          }
          sum[i][choose] = max(sum[i][choose], cur);
        }
      }
    }
    memset(dp, 0, sizeof dp);
    for (int choose = 1; choose < (1 << n); choose++) {
      dp[0][choose] = sum[0][choose];
    }
    for (int i = 1; i < min(n, m); i++) {
      for (int choose = 0; choose < (1 << n); choose++) {
        dp[i][choose] = dp[i - 1][choose];
        for (int cur = choose; cur; cur = (cur - 1) & choose) {
          dp[i][choose] =
              max(dp[i - 1][choose ^ cur] + sum[i][cur], dp[i][choose]);
        }
      }
    }
    cout << dp[min(n, m) - 1][(1 << n) - 1] << endl;
  }
  return 0;
}

```