### Prompt

Create a solution in cpp for the following problem:

Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote out n numbers on a single line. After that, Vasya began to write out different ways to put pluses ("+") in the line between certain digits in the line so that the result was a correct arithmetic expression; formally, no two pluses in such a partition can stand together (between any two adjacent pluses there must be at least one digit), and no plus can stand at the beginning or the end of a line. For example, in the string 100500, ways 100500 (add no pluses), 1+00+500 or 10050+0 are correct, and ways 100++500, +1+0+0+5+0+0 or 100500+ are incorrect.

The lesson was long, and Vasya has written all the correct ways to place exactly k pluses in a string of digits. At this point, he got caught having fun by a teacher and he was given the task to calculate the sum of all the resulting arithmetic expressions by the end of the lesson (when calculating the value of an expression the leading zeros should be ignored). As the answer can be large, Vasya is allowed to get only its remainder modulo 109 + 7. Help him!

Input

The first line contains two integers, n and k (0 ≤ k < n ≤ 105).

The second line contains a string consisting of n digits.

Output

Print the answer to the problem modulo 109 + 7.

Examples

Input

3 1
108

Output

27

Input

3 2
108

Output

9

Note

In the first sample the result equals (1 + 08) + (10 + 8) = 27.

In the second sample the result equals 1 + 0 + 8 = 9.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int mod = 1000000007;
char s[N];
long long fact[N];
long long fpow(long long a, long long b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  if (b & 1) return a * fpow(a * a % mod, b / 2) % mod;
  return fpow(a * a % mod, b / 2);
}
long long combination(long long n, long long m) {
  if (n < m) return 0;
  if (n == m || m == 0) return 1;
  return fact[n] * fpow(fact[m], mod - 2) % mod * fpow(fact[n - m], mod - 2) %
         mod;
}
int main() {
  int n, k;
  fact[0] = 1;
  for (int i = 1; i < N; i++) fact[i] = fact[i - 1] * i % mod;
  long long ans = 0;
  scanf("%d%d", &n, &k);
  scanf("%s", s + 1);
  long long pre = 0;
  for (int i = n; i >= 1; i--) {
    long long x = s[i] - '0';
    int len = n - i + 1;
    ans = (ans + combination(n - len, k) * fpow(10, len - 1) % mod * x) % mod;
    if (len >= 2)
      pre = (pre + combination(n - 1 - (len - 1), k - 1) * fpow(10, len - 2)) %
            mod;
    ans = (ans + pre * x) % mod;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

You can obtain profits from foreign exchange margin transactions. For example, if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) × 1000 = 8000 yen.

Write a program which reads values of a currency $R_t$ at a certain time $t$ ($t = 0, 1, 2, ... n-1$), and reports the maximum value of $R_j - R_i$ where $j > i$ .

Constraints

* $2 \leq n \leq 200,000$
* $1 \leq R_t \leq 10^9$

Input

The first line contains an integer $n$. In the following $n$ lines, $R_t$ ($t = 0, 1, 2, ... n-1$) are given in order.

Output

Print the maximum value in a line.

Examples

Input

6
5
3
1
3
4
3

Output

3

Input

3
4
3
2

Output

-1

### Response

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

int main(){
	int n,num[200000];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>num[i];
	}
	int maxn = -2000000000,minn = num[0];
	for(int j=1;j<n;j++){
		maxn = max(maxn,num[j]-minn);
		minn = min(minn,num[j]);
	}
		cout<<maxn<<endl;
	return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Bearland is a dangerous place. Limak can’t travel on foot. Instead, he has k magic teleportation stones. Each stone can be used at most once. The i-th stone allows to teleport to a point (axi, ayi). Limak can use stones in any order.

There are n monsters in Bearland. The i-th of them stands at (mxi, myi).

The given k + n points are pairwise distinct.

After each teleportation, Limak can shoot an arrow in some direction. An arrow will hit the first monster in the chosen direction. Then, both an arrow and a monster disappear. It’s dangerous to stay in one place for long, so Limak can shoot only one arrow from one place.

A monster should be afraid if it’s possible that Limak will hit it. How many monsters should be afraid of Limak?

Input

The first line of the input contains two integers k and n (1 ≤ k ≤ 7, 1 ≤ n ≤ 1000) — the number of stones and the number of monsters.

The i-th of following k lines contains two integers axi and ayi ( - 109 ≤ axi, ayi ≤ 109) — coordinates to which Limak can teleport using the i-th stone.

The i-th of last n lines contains two integers mxi and myi ( - 109 ≤ mxi, myi ≤ 109) — coordinates of the i-th monster.

The given k + n points are pairwise distinct.

Output

Print the number of monsters which should be afraid of Limak.

Examples

Input

2 4
-2 -1
4 5
4 2
2 1
4 -1
1 -1

Output

3

Input

3 8
10 20
0 0
20 40
300 600
30 60
170 340
50 100
28 56
90 180
-4 -8
-1 -2

Output

5

Note

In the first sample, there are two stones and four monsters. Stones allow to teleport to points ( - 2, - 1) and (4, 5), marked blue in the drawing below. Monsters are at (4, 2), (2, 1), (4, - 1) and (1, - 1), marked red. A monster at (4, - 1) shouldn't be afraid because it's impossible that Limak will hit it with an arrow. Other three monsters can be hit and thus the answer is 3.

<image>

In the second sample, five monsters should be afraid. Safe monsters are those at (300, 600), (170, 340) and (90, 180).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct Point {
  long long x, y;
  Point(long long x, long long y) : x(x), y(y) {}
  Point() : x(0), y(0) {}
};
Point pos[7];
Point targets[1010];
vector<int> in[7][1010];
int match[7];
int N, K;
void read(int n, Point *p) {
  for (int i = 0; i < n; ++i) {
    cin >> p[i].x >> p[i].y;
  }
}
bool dfs(const vector<int> &v, int mask);
bool dfs_kill(const vector<int> &v, int i, vector<int> &nv, int mask) {
  if (i == v.size()) {
    set<int> unv(nv.begin(), nv.end());
    for (int j = 0; j < K; ++j) {
      if (match[j] != -1 && unv.count(match[j])) {
        unv.erase(match[j]);
      }
    }
    return dfs(vector<int>(unv.begin(), unv.end()), mask);
  }
  for (int j = 0; j < K; ++j) {
    if (mask >> j & 1) {
      if (in[j][v[i]].size() > __builtin_popcount(mask) - 1) {
        continue;
      }
      match[j] = v[i];
      for (int k = 0; k < in[j][v[i]].size(); ++k) {
        nv.emplace_back(in[j][v[i]][k]);
      }
      if (dfs_kill(v, i + 1, nv, mask & ~(1 << j))) {
        return true;
      }
      for (int k = 0; k < in[j][v[i]].size(); ++k) {
        nv.pop_back();
      }
      match[j] = -1;
    }
  }
  return false;
}
bool dfs(const vector<int> &v, int mask) {
  if (__builtin_popcount(mask) < v.size()) return false;
  if (v.size() == 0) {
    return true;
  }
  vector<int> nv;
  if (dfs_kill(v, 0, nv, mask)) return true;
  return false;
}
inline Point operator-(const Point &a, const Point &b) {
  return Point(a.x - b.x, a.y - b.y);
}
inline long long det(const Point &a, const Point &b) {
  return a.x * b.y - a.y * b.x;
}
inline long long dot(const Point &a, const Point &b) {
  return a.x * b.x + a.y * b.y;
}
inline bool online(const Point &p, const Point &a, const Point &b) {
  return det(b - a, p - a) == 0 && dot(a - p, b - p) < 0;
}
int main() {
  while (cin >> K >> N) {
    read(K, pos);
    read(N, targets);
    for (int i = 0; i < K; ++i) {
      for (int j = 0; j < N; ++j) {
        in[i][j].clear();
        for (int k = 0; k < N; ++k)
          if (k != j && online(targets[k], pos[i], targets[j])) {
            in[i][j].emplace_back(k);
          }
      }
    }
    int res = 0;
    for (int i = 0; i < N; ++i) {
      memset(match, -1, sizeof match);
      if (dfs(vector<int>(1, i), (1 << K) - 1)) {
        res++;
      }
    }
    cout << res << endl;
  }
}

```


### Prompt

Please create a solution in Cpp to the following problem:

AtCoDeer is thinking of painting an infinite two-dimensional grid in a checked pattern of side K. Here, a checked pattern of side K is a pattern where each square is painted black or white so that each connected component of each color is a K × K square. Below is an example of a checked pattern of side 3:

cba927b2484fad94fb5ff7473e9aadef.png

AtCoDeer has N desires. The i-th desire is represented by x_i, y_i and c_i. If c_i is `B`, it means that he wants to paint the square (x_i,y_i) black; if c_i is `W`, he wants to paint the square (x_i,y_i) white. At most how many desires can he satisfy at the same time?

Constraints

* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 1000
* 0 ≤ x_i ≤ 10^9
* 0 ≤ y_i ≤ 10^9
* If i ≠ j, then (x_i,y_i) ≠ (x_j,y_j).
* c_i is `B` or `W`.
* N, K, x_i and y_i are integers.

Input

Input is given from Standard Input in the following format:

N K
x_1 y_1 c_1
x_2 y_2 c_2
:
x_N y_N c_N

Output

Print the maximum number of desires that can be satisfied at the same time.

Examples

Input

4 3
0 1 W
1 2 W
5 3 B
5 4 B

Output

4

Input

2 1000
0 0 B
0 1 W

Output

2

Input

6 2
1 2 B
2 1 W
2 2 B
1 0 B
0 6 W
4 5 W

Output

4

### Response

```cpp
#include<cstdio>
#include<algorithm>
#include<cstring>
const int MAXN = 100000;
const int MAXK = 1000;
int x[MAXN + 5], y[MAXN + 5], c[MAXN + 5];
int y1[10 * MAXK + 5];
int main()
{
	int N,K,Max=0,cnt = 0;
	scanf("%d%d",&N,&K);
	for(int i=1;i<=N;i++)
	{
		char ch;
		scanf("%d%d %c",&x[i],&y[i],&ch);
		x[i]%=(2*K);
		y[i]%=(2*K);
		if(ch=='W' ) c[i] = 1;
		else c[i]=0;
	}
	for(int i=0;i<=K;i++) {
		cnt = 0;
		memset(y1,0,sizeof(y1));
		for(int j=1;j<=N;j++) {
			bool p = ( i <= x[j] && x[j] < i+K );
			bool q = ( 0 <= y[j] && y[j] < K );
			if( p ^ q == c[j] )
			{
				cnt++;
				y1[y[j]] ++;
			}
			else
			{
				y1[y[j]] --;
			}
		}
		for(int j=0;j<=K;j++)
		{
			Max=std::max(Max,std::max(cnt,N-cnt));
			if( j != K )
				cnt = cnt - y1[j] - y1[K+j];
		}
	}
	printf("%d\n",Max);
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes.

They took n prizes for the contestants and wrote on each of them a unique id (integer from 1 to n). A gift i is characterized by integer ai — pleasantness of the gift. The pleasantness of the gift can be positive, negative or zero. Sponsors placed the gift 1 on the top of the tree. All the other gifts hung on a rope tied to some other gift so that each gift hung on the first gift, possibly with a sequence of ropes and another gifts. Formally, the gifts formed a rooted tree with n vertices.

The prize-giving procedure goes in the following way: the participants come to the tree one after another, choose any of the remaining gifts and cut the rope this prize hang on. Note that all the ropes which were used to hang other prizes on the chosen one are not cut. So the contestant gets the chosen gift as well as the all the gifts that hang on it, possibly with a sequence of ropes and another gifts.

Our friends, Chloe and Vladik, shared the first place on the olympiad and they will choose prizes at the same time! To keep themselves from fighting, they decided to choose two different gifts so that the sets of the gifts that hang on them with a sequence of ropes and another gifts don't intersect. In other words, there shouldn't be any gift that hang both on the gift chosen by Chloe and on the gift chosen by Vladik. From all of the possible variants they will choose such pair of prizes that the sum of pleasantness of all the gifts that they will take after cutting the ropes is as large as possible.

Print the maximum sum of pleasantness that Vladik and Chloe can get. If it is impossible for them to choose the gifts without fighting, print Impossible.

Input

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

The next line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the pleasantness of the gifts.

The next (n - 1) lines contain two numbers each. The i-th of these lines contains integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the description of the tree's edges. It means that gifts with numbers ui and vi are connected to each other with a rope. The gifts' ids in the description of the ropes can be given in arbirtary order: vi hangs on ui or ui hangs on vi.

It is guaranteed that all the gifts hang on the first gift, possibly with a sequence of ropes and another gifts.

Output

If it is possible for Chloe and Vladik to choose prizes without fighting, print single integer — the maximum possible sum of pleasantness they can get together.

Otherwise print Impossible.

Examples

Input

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

Output

25

Input

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

Output

2

Input

1
-1

Output

Impossible

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200000, MAX_VAL = 1000000000;
const long long INF = (long long)(MAX_N) * (long long)(MAX_VAL) + 1ll;
struct Vertex {
  int a;
  long long s, maxim, ans;
  list<int> edge;
};
int n, a[MAX_N + 1];
Vertex vertexs[MAX_N + 1];
void DFS(int v, int p = 0) {
  vertexs[v].s = vertexs[v].a;
  vertexs[v].maxim = -INF;
  vertexs[v].ans = -INF;
  long long ans1 = -2 * INF, ans2 = -2 * INF;
  for (auto i : vertexs[v].edge) {
    if (i != p) {
      DFS(i, v);
      vertexs[v].s += vertexs[i].s;
      vertexs[v].maxim = max(vertexs[v].maxim, vertexs[i].maxim);
      vertexs[v].ans = max(vertexs[v].ans, vertexs[i].ans);
      ans2 = max(ans2, vertexs[i].maxim);
      if (ans2 > ans1) {
        swap(ans1, ans2);
      }
    }
  }
  vertexs[v].maxim = max(vertexs[v].maxim, vertexs[v].s);
  vertexs[v].ans = max(vertexs[v].ans, ans1 + ans2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    vertexs[i].a = a[i];
  }
  int u, v;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    vertexs[u].edge.push_back(v);
    vertexs[v].edge.push_back(u);
  }
  DFS(1);
  if (vertexs[1].ans > -INF) {
    cout << vertexs[1].ans << endl;
  } else {
    cout << "Impossible" << endl;
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters + and 1 into this sequence. For example, sequences (())(), () and (()(())) are regular, while )(, (() and (()))( are not. Let's call a regular bracket sequence "RBS".

You are given a sequence s of n characters (, ), and/or ?. There is exactly one character ( and exactly one character ) in this sequence.

You have to replace every character ? with either ) or ( (different characters ? can be replaced with different brackets). You cannot reorder the characters, remove them, insert other characters, and each ? must be replaced.

Determine if it is possible to obtain an RBS after these replacements.

Input

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

Each test case consists of one line containing s (2 ≤ |s| ≤ 100) — a sequence of characters (, ), and/or ?. There is exactly one character ( and exactly one character ) in this sequence.

Output

For each test case, print YES if it is possible to obtain a regular bracket sequence, or NO otherwise}.

You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).

Example

Input

5
()
(?)
(??)
??()
)?(?

Output

YES
NO
YES
YES
NO

Note

In the first test case, the sequence is already an RBS.

In the third test case, you can obtain an RBS as follows: ()() or (()).

In the fourth test case, you can obtain an RBS as follows: ()().

### Response

```cpp
#include<bits/stdc++.h>
#define maxe    1000000000
#define MOD   1000000007
#define hurry   ios_base::sync_with_stdio(false);cin.tie(NULL);
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//data type
#define ll long long int
#define ull unsigned long long int
#define ld               long double
#define bigint            int64_t

#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
//set
#define si             set<int>
#define spl            set< pair<ll,ll> >
#define spi            set< pair<int,int> >
#define spp            set< pair<pair<ll,ll>,ll> >

//pair
#define pll             pair<ll,ll>
#define pi              pai<int,int>

 //vector
#define  vvi            vector< vector<int> > v;
#define  vi             vector<int> v;
#define  vpii           vector< pair<int,int> >
#define vpl             vector< pair<ll,ll> >
#define all(v)          v.begin(),v.end()
#define MINIMUM(a)      *min_element(a.begin(), a.end())
#define MAXIMUM(a)      *max_element(a.begin(), a.end())
#define                  pb push_back
#define mp               make_pair

#define sz(a)            sizeof(a)
#define forn(i,n)        for(ll (i) = 0 ; (i) < (n) ; ++(i))
#define for1(i,n)        for(ll (i) = 1 ; (i) <= (n) ; ++(i))
using namespace std;

#define ps(y,x) fixed<<setprecision(y)<<x;
#define F first
#define S second
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define FORD(i,a,b) for(int i=a;i>=b;--i)
#define REP(i,n) FOR(i,0,(int)n-1)

#define FOREACH_FN(v, fn) for_each(ALL(v), myobject);

#define SORT(a) sort(a.begin(),a.end())
#define RSORT(a) sort(a.rbegin(),a.rend())
#define REV(a) reverse(a.begin(),a.end())
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

/// Trace
#define trace1(a)               cerr << #a << ": " << a << endl;
#define trace2(a,b)             cerr << #a << ": " << a << " | " << #b << ": " << b << endl;
#define trace3(a,b,c)           cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << endl;
#define trace4(a,b,c,d)         cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a,b,c,d,e)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a,b,c,d,e,f)     cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
 #define deb(x)           cout << #x << "=" << x << endl;

#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

#define W(t)              while(t--)
#define forn(i,n)         for(ll (i) = 0 ; (i) < (n) ; ++(i))
#define for1(i,n)         for(ll (i) = 1 ; (i) <= (n) ; ++(i))
#define forr(i,n)         for(ll (i) = (n)-1 ; (i)>=0 ; --(i))
#define forab(i,a,b,c)    for(ll (i) = a ; (i) <= (b) ; (i)+=(c))
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define mp                make_pair
#define pb                push_back
int READ_INT(){int temp;cin>>temp;return temp;}      // read an int
ll READ_LONG(){ll temp;cin>>temp;return temp;}      // read a long long
string READ_STRING(){string temp;cin>>temp;return temp;}      // read a string

///templates///////

const long  double p = 3.14159265358979323846;
const long long INF=3e+5;
const int N =2e+5;
#define mod 998244353;
long long int inverse(long long int i){
    if(i==1) return 1;
    return (MOD - ((MOD/i)*inverse(MOD%i))%MOD+MOD)%MOD;
}
ll POW(ll a,ll b)
{
    if(b==0) return 1;
    if(b==1) return a%MOD;
    ll temp=POW(a,b/2);
    if(b%2==0) return (temp*temp)%MOD;
    else return (((temp*temp)%MOD)*a)%MOD;
}

/*vector<int> isprime(N,1);
vector<int> primes;

void seive()
{
for (int i = 2; i <= N; i++) {
    if (isprime[i] && (long long)i * i <= N) {
        for (int j = i * i; j <= N; j += i)
            isprime[j] = 0;
    }
}

for(int i=2;i<=N;i++)
{
    if(isprime[i])
        primes.pb(i);
}
}*/

// Returns factorial of n

void bootcoder()
{

//check N (space)
// check integer overflow
// check corner cases

string s;

cin>>s;

int n=s.length();

if(s[0]==')' || s[n-1]=='(' || (n-2)&1)
  cout<<"NO";
else
  cout<<"YES";

cout<<"\n";
}

int main()

{
hurry;
#ifndef ONLINE_JUDGE
 freopen("inputs.txt", "r",stdin);
 freopen("oss.txt","w",stdout);
#endif
int test;

cin>>test;

//test=1;
W(test)
{

bootcoder();
}
}

```


### Prompt

Develop a solution in cpp to the problem described below:

It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be transferred from one accumulator to the other. Every time x units of energy are transferred (x is not necessarily an integer) k percent of it is lost. That is, if x units were transferred from one accumulator to the other, amount of energy in the first one decreased by x units and in other increased by <image> units.

Your task is to help Petya find what maximum equal amount of energy can be stored in each accumulator after the transfers.

Input

First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers.

Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).

Output

Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy.

The absolute or relative error in the answer should not exceed 10 - 6.

Examples

Input

3 50
4 2 1

Output

2.000000000

Input

2 90
1 11

Output

1.909090909

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int v[n];
  for (int i = 0; i < n; ++i) scanf("%d", &v[i]);
  double l = 0.0, e = 1000.0;
  double m;
  for (int itr = 0; itr < 500; itr++) {
    m = (l + e) / 2.0;
    double x = 0.0, y = 0.0;
    for (int i = 0; i < n; ++i) {
      if (v[i] < m)
        x += (m - v[i]);
      else
        y += (v[i] - m);
    }
    if (y - y * k / 100 >= x)
      l = m;
    else
      e = m;
  }
  printf("%.7lf\n", m);
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

You are given a tree consisting of n vertices, and m simple vertex paths. Your task is to find how many pairs of those paths intersect at exactly one vertex. More formally you have to find the number of pairs (i, j) (1 ≤ i < j ≤ m) such that path_i and path_j have exactly one vertex in common.

Input

First line contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5).

Next n - 1 lines describe the tree. Each line contains two integers u and v (1 ≤ u, v ≤ n) describing an edge between vertices u and v.

Next line contains a single integer m (1 ≤ m ≤ 3 ⋅ 10^5).

Next m lines describe paths. Each line describes a path by it's two endpoints u and v (1 ≤ u, v ≤ n). The given path is all the vertices on the shortest path from u to v (including u and v).

Output

Output a single integer — the number of pairs of paths that intersect at exactly one vertex.

Examples

Input

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

Output

2

Input

1
3
1 1
1 1
1 1

Output

3

Input

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

Output

7

Note

<image>

The tree in the first example and paths look like this. Pairs (1,4) and (3,4) intersect at one vertex.

In the second example all three paths contain the same single vertex, so all pairs (1, 2), (1, 3) and (2, 3) intersect at one vertex.

The third example is the same as the first example with two additional paths. Pairs (1,4), (1,5), (2,5), (3,4), (3,5), (3,6) and (5,6) intersect at one vertex.

### Response

```cpp
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<random>
#include<ctime>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<unordered_map>
#include<map>
#include<bitset>
#include<stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=6e5+5,M=1e3+5;
const ll INF=1e18+5;
inline ll read()
{
	ll sum=0,fh=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')fh=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		sum=sum*10+c-'0';
		c=getchar();
	}
	return sum*fh;
}
inline int read2()
{
	char c=getchar();
	while(c!='a'&&c!='b'&&c!='c'&&c!='?')c=getchar();
	return c=='?'?0:c-'a'+1;
}
inline int read3()
{
	char c=getchar();
	while(c<'a'||c>'z')
	{
		c=getchar();
	}
	return c-'a';
}
inline void write(ll x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}

/*namespace INPUT_SPACE{
    const int BS=(1<<24)+5;char Buffer[BS],*HD,*TL;
    char gc() { if(HD==TL) TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);return (HD==TL)?EOF:*HD++; }
    inline ull read()
    {
        ull x,ch;while(((ch=gc())<'0'||ch>'9'));
        x=ch^'0';
        while((ch=gc())>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^'0');
        return x;
    }
}using INPUT_SPACE::read;
char sws[30000011],tt[21];int ssl,ttl;
inline int write(int x)
{
    if(!x) sws[++ssl]='0';for(ttl=0;x;x/=10) tt[++ttl]=char(x%10+'0');
    for(;ttl;ttl--) sws[++ssl]=tt[ttl];return sws[++ssl]='\n';
}*/

inline int gcd(int x,int y)
{
	return y==0?x:gcd(y,x%y);
}
inline ll ab(ll x)
{
	return x<0?-x:x;
}
inline ll fpow(ll qwe,ll asd,ll zxc)
{
	if(asd<0)return 0;
	ll a=qwe,b=1,c=asd;
	while(c)
	{
		if(c&1)b=b*a%zxc;
		a=a*a%zxc;
		c>>=1;
	}
	return b;
}

int n,m;
struct miaow2
{
	int son[2];
	int fa,qfa;
	int fz;
	int sz,sum;
}t[N];
#define ls(x) t[x].son[0]
#define rs(x) t[x].son[1]
#define son(x,k) t[x].son[k]
#define fa(x) t[x].fa
#define qfa(x) t[x].qfa
#define fz(x) t[x].fz
#define sz(x) t[x].sz
#define sum(x) t[x].sum
inline int fx(int x)
{
	if(!fa(x))return -1;
	return rs(fa(x))==x;
}
inline void upd(int x)
{
	sum(x)=sz(x)+(ls(x)?sum(ls(x)):0)+(rs(x)?sum(rs(x)):0);
}
inline void pd(int x)
{
	if(!fz(x))return;
	swap(ls(x),rs(x));
	fz(x)=0;
	if(ls(x))fz(ls(x))^=1;
	if(rs(x))fz(rs(x))^=1;
}
inline void rot(int x)
{
	if(!fa(x))return;
	int y=fa(x),k=fx(x);
	if(fa(y))
	{
		fa(x)=fa(y);
		son(fa(y),fx(y))=x;
	}
	else swap(qfa(x),qfa(y)),fa(x)=0;
	fa(y)=x;
	if(son(x,k^1))fa(son(x,k^1))=y;
	son(y,k)=son(x,k^1);
	son(x,k^1)=y;
	upd(y);
	upd(x);
}
inline void pd2(int x)
{
	if(fa(x))pd2(fa(x));
	pd(x);
}
inline void splay(int x)
{
	pd2(x);
	if(!fa(x))return;
	int y=fa(x);
	while(y)
	{
		if(!fa(y))
		{
			rot(x);
			return;
		}
		int z=fa(y);
		if(fx(x)==fx(y))rot(y);
		else rot(x);
		rot(x);
		y=fa(x);
	}
}
inline void access(int x)
{
	splay(x);
	if(rs(x))
	{
		qfa(rs(x))=x;
		fa(rs(x))=0;
		rs(x)=0;
		upd(x);
	}
	int y=qfa(x);
	while(y)
	{
		splay(y);
		//cout<<y<<"."<<fz(y)<<endl;
		if(rs(y))
		{
			qfa(rs(y))=y;
			fa(rs(y))=0;
			rs(y)=0;
		}
		rs(y)=x;
		fa(x)=y;
		qfa(x)=0;
		x=y;
		y=qfa(x);
	}
}

inline void sc()
{
	for(int i=1;i<=n;++i)
	{
		cout<<i<<" ls:"<<ls(i)<<" rs:"<<rs(i)<<" fa:"<<fa(i)<<" qfa:"<<qfa(i)<<" sz:"<<sz(i)<<" sum:"<<sum(i)<<" fz:"<<fz(i)<<endl;
	}
	cout<<endl;
}

inline int hg(int x)
{
	access(x);
	//sc();
	splay(x);
	fz(x)=1;
}
inline int lctcx(int l,int r)
{
	//cout<<"cx:"<<l<<" "<<r<<endl;
	//sc();
	hg(l);
	//sc();
	access(r);
	splay(r);
	//cout<<"cx:"<<ls(r)<<" "<<rs(r)<<" "<<ls(rs(r))<<" "<<rs(rs(r))<<endl;
	//sc();
	return sum(r);
}
inline void lctxg(int x,int y)
{
	hg(x);
	sz(x)+=y;
	upd(x);
}

#define pi pair<ll,ll>
struct miaow
{
	int f,t,l;
	ll c;
	miaow(int f=0,int t=0,ll c=0,int l=0):f(f),t(t),c(c),l(l){}
}imap[N*2+5];
int str[N*2+5]={0},cou=2;
inline void jb(int f,int t,ll c=0)
{
	//cout<<f<<" "<<t<<" "<<c<<endl;
	imap[cou]=miaow(f,t,c,str[f]);str[f]=cou++;
	imap[cou]=miaow(t,f,c,str[t]);str[t]=cou++;
}
//ll a[N];
int dfn[N],dfnl[N],dfnr[N],dfncou=0,dep[N];
pi sx[N];
inline void dfs(int o,int fa,int d)
{
	sx[o]=pi(-d,o);
	dep[o]=d;
	dfn[++dfncou]=o;
	dfnl[o]=dfncou;
	for(int i=str[o];i;i=imap[i].l)
	{
		int tt=imap[i].t;
		if(tt==fa)continue;
		qfa(tt)=o;
		dfs(tt,o,d+1);
		dfn[++dfncou]=o;
	}
	dfnr[o]=dfncou;
	return;
}
struct meow
{
	int imi,l,r;
	meow(int imii=0,int ll=0,int rr=0)
	{
		imi=imii,l=ll,r=rr;
	}
};
inline meow meg(meow& qwe,meow& asd)
{
	if(qwe.imi<asd.imi)return qwe;
	if(qwe.imi>asd.imi)return asd;
	return meow(qwe.imi,min(qwe.l,asd.l),max(qwe.r,asd.r));
}
struct nya
{
	int l,r;
	meow imx;
}tt[N*4+5];
#define l(x) tt[x].l
#define r(x) tt[x].r
#define imx(x) tt[x].imx
#define lss(x) (x*2)
#define rss(x) (x*2+1)
inline void tcsh(int l,int r,int o)
{
	l(o)=l,r(o)=r;
	if(l==r)
	{
		imx(o)=meow(dep[dfn[l]],l,r);
		return;
	}
	int mid=(l+r)>>1;
	tcsh(l,mid,lss(o)),tcsh(mid+1,r,rss(o));
	imx(o)=meg(imx(lss(o)),imx(rss(o)));
}
inline meow cx(int l,int r,int o)
{
	//cout<<l<<" "<<r<<" "<<o<<endl;
	if(l<=l(o)&&r>=r(o))return imx(o);
	meow qwe(1e9,0,0),asd(1e9,0,0);
	int mid=(l(o)+r(o))>>1;
	if(l<=mid)qwe=cx(l,min(mid,r),lss(o));
	if(r>mid)asd=cx(max(mid+1,l),r,rss(o));
	return meg(qwe,asd);
}
/*inline void xg(int l,int r,int o,int x)
{
	if(l>r)return;
	if(l<=l(o)&&r>=r(o))
	{
		bj(o)+=x;
		imx(o)+=x;
		return;
	}
	int mid=(l(o)+r(o))>>1;
	if(l<=mid)xg(l,min(mid,r),ls(o),x);
	if(r>mid)xg(max(l,mid+1),r,rs(o),x);
	if(imx(ls(o))>imx(rs(o)))imx(o)=imx(ls(o))+bj(o),sum(o)=sum(ls(o));
	else if(imx(ls(o))<imx(rs(o)))imx(o)=imx(rs(o))+bj(o),sum(o)=sum(rs(o));
	else imx(o)=imx(ls(o))+bj(o),sum(o)=sum(ls(o))+sum(rs(o));
}*/
/*inline void xg(int k,int o,int x)
{
	//if(l>r)return;
	if(l(o)==r(o))
	{
		mat(o,0,0)=0;
		mat(o,0,1)=x;
		mat(o,1,0)=-x;
		mat(o,1,1)=0;
		return;
		return;
	}
	int mid=(l(o)+r(o))>>1;
	if(k<=mid)xg(k,ls(o),x);
	else xg(k,rs(o),x);
	upd(o);
}*/
/*inline int cx(int k,int o)
{
	if(l(o)==r(o))return imx(o);
	int x=imx(o),mid=(l(o)+r(o))>>1;
	if(k<=mid)return min(x,cx(k,ls(o)));
	else return min(x,cx(k,rs(o)));
}*/

struct meow2
{
	int l,r,lca,lcal,lcar;
	meow2(int ll=0,int rr=0,int lca=0,int lcal=0,int lcar=0):lca(lca),lcal(lcal),lcar(lcar)
	{
		l=ll,r=rr;
	}
};
vector<meow2> dcz[N];
int djs[N];
map<pi,int> djs2;
ll ans;
inline void csh()
{
	n=read();//,m=read();
	//cout<<"?"<<endl;
	for(int i=1;i<n;++i)
	{
		int f=read(),t=read();
		jb(f,t);
	}
	//cout<<"?"<<endl;
	dfs(1,0,1);
	//cout<<"?"<<endl;
	sort(sx+1,sx+n+1);
	//cout<<"?"<<endl;
	tcsh(1,dfncou,1);
	//cout<<"?"<<endl;
	//for(int i=1;i<=dfncou;++i)cout<<dfn[i]<<" ";cout<<endl;
	//for(int i=1;i<=n;++i)cout<<i<<" "<<dfnl[i]<<" "<<dfnr[i]<<endl;
	m=read();
	for(int i=1;i<=m;++i)
	{
		//cout<<"?"<<i<<endl;
		int l=read(),r=read();
		if(l==r)
		{
			//cout<<"!1"<<endl;
			dcz[l].push_back(meow2(l,r,l));
			//cout<<l<<" "<<r<<" "<<l<<" "<<"0 0"<<endl;
			continue;
		}
		if(dfnl[l]>dfnl[r])swap(l,r);
		if(dfnl[l]<dfnl[r]&&dfnr[l]>dfnr[r])
		{
			//cout<<"!2"<<endl;
			meow qwe=cx(dfnr[r],dfnr[l],1);
			dcz[l].push_back(meow2(l,r,l,0,dfn[qwe.l-1]));
			//cout<<l<<" "<<r<<" "<<l<<" "<<"0 "<<dfn[qwe.l-1]<<endl;
		}
		else
		{
			//cout<<"!3"<<" "<<dfnr[l]<<" "<<dfnl[r]<<endl;
			meow qwe=cx(dfnr[l],dfnl[r],1);
			//cout<<"!3"<<" "<<dfnr[l]<<" "<<dfnl[r]<<endl;
			//cout<<qwe.l<<" "<<qwe.r<<" "<<qwe.imi<<endl;
			dcz[dfn[qwe.l]].push_back(meow2(l,r,dfn[qwe.l],dfn[qwe.l-1],dfn[qwe.r+1]));
			//cout<<l<<" "<<r<<" "<<dfn[qwe.l]<<" "<<dfn[qwe.l-1]<<" "<<dfn[qwe.r+1]<<endl;
		}
	}
}
inline void solve()
{
	for(int i=1;i<=n;++i)
	{
		int o=sx[i].second;
		//cout<<"!"<<o<<endl;
		int js=0;
		for(int j=0;j<dcz[o].size();++j)
		{
			int l=dcz[o][j].l,r=dcz[o][j].r,lcal=dcz[o][j].lcal,lcar=dcz[o][j].lcar;
			//cout<<l<<" "<<r<<" "<<lcal<<" "<<lcar<<endl;
			if(l==r)
			{
				ans+=js;
				js+=1;
			}
			else if(l==o)
			{
				ans+=js-djs[lcar];
				ans+=lctcx(l,r);
				js+=1;
				djs[lcar]+=1;
			}
			else
			{
				//cout<<"?1 "<<ans<<endl;
				ans+=js-djs[lcal]-djs[lcar]+djs2[pi(lcal,lcar)];
				//cout<<"?2 "<<ans<<endl;
				ans+=lctcx(l,r);
				//cout<<"?3 "<<ans<<endl;
				js+=1;
				djs[lcal]+=1,djs[lcar]+=1;
				djs2[pi(lcal,lcar)]+=1;
			}
		}
		for(int j=0;j<dcz[o].size();++j)
		{
			int l=dcz[o][j].l,r=dcz[o][j].r,lcal=dcz[o][j].lcal,lcar=dcz[o][j].lcar;
			if(l==r)
			{
				lctxg(l,1);
			}
			else if(l==o)
			{
				lctxg(l,1);
				lctxg(lcar,-1);
			}
			else
			{
				lctxg(o,1);
				lctxg(lcal,-1);
				lctxg(lcar,-1);
			}
		}
	}
}
int main()
{
	//freopen("qwq.txt","r",stdin);
	//freopen("qaq.txt","w",stdout);
	csh();
	solve();
	cout<<ans<<endl;
	return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Dr. Asimov, a robotics researcher, loves to research, but hates houseworks and his house were really dirty. So, he has developed a cleaning robot.

As shown in the following figure, his house has 9 rooms, where each room is identified by an alphabet:

<image>

The robot he developed operates as follows:

* If the battery runs down, the robot stops.
* If not so, the robot chooses a direction from four cardinal points with the equal probability, and moves to the room in that direction. Then, the robot clean the room and consumes 1 point of the battery.
* However, if there is no room in that direction, the robot does not move and remains the same room. In addition, there is a junk room in the house where the robot can not enter, and the robot also remains when it tries to enter the junk room. The robot also consumes 1 point of the battery when it remains the same place.

A battery charger for the robot is in a room. It would be convenient for Dr. Asimov if the robot stops at the battery room when its battery run down.

Your task is to write a program which computes the probability of the robot stopping at the battery room.

Constraints

* Judge data includes at most 100 data sets.
* n ≤ 15
* s, t, b are distinct.

Input

The input consists of several datasets. Each dataset consists of:

n
s t b

n is an integer that indicates the initial battery point. s, t, b are alphabets respectively represent the room where the robot is initially, the battery room, and the junk room.

The input ends with a dataset which consists of single 0 for n. Your program should not output for this dataset.

Output

For each dataset, print the probability as a floating point number in a line. The answer may not have an error greater than 0.000001.

Example

Input

1
E A C
1
E B C
2
E A B
0

Output

0.00000000
0.25000000
0.06250000

### Response

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

int main(){
    double dp[3][3][16];//[x][y][n]
    char s,t,b;
    int n;
    int dx[]={-1,0,1,0};
    int dy[]={0,1,0,-1};
    cout.precision(8);
    cout << fixed;
    while(cin>>n,n){
        fill(dp[0][0],dp[3][0],0);
        cin>>s>>t>>b;
        s-='A';
        t-='A';
        b-='A';
        dp[s%3][s/3][n]=1;
        for(;n>0;n--){
            for(int x=0;x<3;x++){
                for(int y=0;y<3;y++){
                    for(int i=0;i<4;i++){
                        if((0<=x+dx[i]&&x+dx[i]<3)&&(0<=y+dy[i]&&y+dy[i]<3)&&!((x+dx[i])==(b%3)&&(y+dy[i])==(b/3))){
                            dp[x+dx[i]][y+dy[i]][n-1]+=dp[x][y][n]/4;
                        }else{
                            dp[x][y][n-1]+=dp[x][y][n]/4;
                        }
                    }
                }
            }
        }
        cout << dp[t%3][t/3][0] << endl;
    }
    return 0;
}
```


### Prompt

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

There are many caves deep in mountains found in the countryside. In legend, each cave has a treasure hidden within the farthest room from the cave's entrance. The Shogun has ordered his Samurais to explore these caves with Karakuri dolls (robots) and to find all treasures. These robots move in the caves and log relative distances and directions between rooms.

Each room in a cave is mapped to a point on an integer grid (x, y >= 0). For each cave, the robot always starts from its entrance, runs along the grid and returns to the entrance (which also serves as the exit). The treasure in each cave is hidden in the farthest room from the entrance, using Euclid distance for measurement, i.e. the distance of the room at point (x, y) from the entrance (0, 0) is defined as the square root of (x*x+y*y). If more than one room has the same farthest distance from the entrance, the treasure is hidden in the room having the greatest value of x. While the robot explores a cave, it records how it has moved. Each time it takes a new direction at a room, it notes the difference (dx, dy) from the last time it changed its direction. For example, suppose the robot is currently in the room at point (2, 4). If it moves to room (6, 4), the robot records (4, 0), i.e. dx=6-2 and dy=4-4. The first data is defined as the difference from the entrance. The following figure shows rooms in the first cave of the Sample Input. In the figure, the farthest room is the square root of 61 distant from the entrance.
<image>

Based on the records that the robots bring back, your job is to determine the rooms where treasures are hidden.

Input

In the first line of the input, an integer N showing the number of caves in the input is given. Integers dxi and dyi are i-th data showing the differences between rooms. Note that since the robot moves along the grid, either dxi or dyi is zero. An integer pair dxi = dyi = 0 signals the end of one cave's data which means the robot finished the exploration for the cave and returned back to the entrance. The coordinates are limited to (0,0)-(1000,1000).

Output

Print the position (x, y) of the treasure room on a line for each cave.

Example

Input

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

Output

6 5
1 0
2 1

### Response

```cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n;
	cin>>n;
	rep(i,n){
		int dx,dy;
		int x=0,y=0;
		int mx=0,my=0,ma=0;
		while(cin>>dx>>dy,dx||dy){
			x+=dx;
			y+=dy;
			if(x*x+y*y>ma){
				mx=x;my=y;
				ma=x*x+y*y;
			}else if(x*x+y*y==ma){
				if(mx<x){
					mx=x;my=y;
				}
			}
		}
		cout<<mx<<" "<<my<<endl;
	}
}
```


### Prompt

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

There is an array a of 2^{30} integers, indexed from 0 to 2^{30}-1. Initially, you know that 0 ≤ a_i < 2^{30} (0 ≤ i < 2^{30}), but you do not know any of the values. Your task is to process queries of two types:

  * 1 l r x: You are informed that the bitwise xor of the subarray [l, r] (ends inclusive) is equal to x. That is, a_l ⊕ a_{l+1} ⊕ … ⊕ a_{r-1} ⊕ a_r = x, where ⊕ is the bitwise xor operator. In some cases, the received update contradicts past updates. In this case, you should ignore the contradicting update (the current update).
  * 2 l r: You are asked to output the bitwise xor of the subarray [l, r] (ends inclusive). If it is still impossible to know this value, considering all past updates, then output -1.

Note that the queries are encoded. That is, you need to write an online solution.

Input

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

Each of the next q lines describes a query. It contains one integer t (1 ≤ t ≤ 2) — the type of query.

The given queries will be encoded in the following way: let last be the answer to the last query of the second type that you have answered (initially, last = 0). If the last answer was -1, set last = 1.

  * If t = 1, three integers follow, l', r', and x' (0 ≤ l', r', x' < 2^{30}), meaning that you got an update. First, do the following: l = l' ⊕ last, r = r' ⊕ last, x = x' ⊕ last

and, if l > r, swap l and r.

This means you got an update that the bitwise xor of the subarray [l, r] is equal to x (notice that you need to ignore updates that contradict previous updates).

  * If t = 2, two integers follow, l' and r' (0 ≤ l', r' < 2^{30}), meaning that you got a query. First, do the following: l = l' ⊕ last, r = r' ⊕ last

and, if l > r, swap l and r.

For the given query, you need to print the bitwise xor of the subarray [l, r]. If it is impossible to know, print -1. Don't forget to change the value of last.

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

Output

After every query of the second type, output the bitwise xor of the given subarray or -1 if it is still impossible to know.

Examples

Input

12
2 1 2
2 1 1073741822
1 0 3 4
2 0 0
2 3 3
2 0 3
1 6 7 3
2 4 4
1 0 2 1
2 0 0
2 4 4
2 0 0

Output

-1
-1
-1
-1
5
-1
6
3
5

Input

4
1 5 5 9
1 6 6 5
1 6 5 10
2 6 5

Output

12

Note

In the first example, the real queries (without being encoded) are:

  * 12
  * 2 1 2
  * 2 0 1073741823
  * 1 1 2 5
  * 2 1 1
  * 2 2 2
  * 2 1 2
  * 1 2 3 6
  * 2 1 1
  * 1 1 3 0
  * 2 1 1
  * 2 2 2
  * 2 3 3

  * The answers for the first two queries are -1 because we don't have any such information on the array initially.
  * The first update tells us a_1 ⊕ a_2 = 5. Note that we still can't be certain about the values a_1 or a_2 independently (for example, it could be that a_1 = 1, a_2 = 4, and also a_1 = 3, a_2 = 6).
  * After we receive all three updates, we have enough information to deduce a_1, a_2, a_3 independently.

In the second example, notice that after the first two updates we already know that a_5 ⊕ a_6 = 12, so the third update is contradicting, and we ignore it.

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename T>
constexpr long long infValue =
    std::is_same<T, int>::value ? 2000100007 : 8600000000000000007ll;
template <typename T>
constexpr long long maxValue =
    std::is_same<T, int>::value ? 1000000007 : 1000000000000000001ll;
const long long INF = infValue<long long>;
const long long MOD = 998244353ll;
const double EPS = 1e-6;
const long long MAX = maxValue<long long>;
using pr = pair<long long, long long>;
vector<long long> g[601000];
map<long long, long long> v;
long long lv = 1;
long long p[601000], s[601000], vp[601000];
void make_set(long long v) {
  p[v] = v;
  s[v] = 1;
  vp[v] = 0;
}
long long find_set(long long v) {
  if (p[v] == v) return v;
  long long sp = p[v];
  p[v] = find_set(p[v]);
  vp[v] ^= vp[sp];
  return p[v];
}
void merge_set(long long vs, long long us, long long x) {
  long long u = find_set(us);
  long long v = find_set(vs);
  if (v != u) {
    if (s[v] > s[u]) swap(v, u), swap(vs, us);
    p[u] = v;
    s[v] += s[u];
    vp[u] = vp[us] ^ x ^ vp[vs];
  }
}
void add(long long l, long long r, long long x) { merge_set(l, r, x); }
long long query(long long l, long long r) {
  long long lp = find_set(l);
  long long rp = find_set(r);
  if (lp != rp) return -1;
  return vp[l] ^ vp[r];
}
long long q, last;
long long l, r, x;
int main(void) {
  scanf("%d", &q);
  while (q--) {
    long long t = 0;
    scanf("%d", &t);
    scanf("%lld %lld", &l, &r), l ^= last, r ^= last;
    if (l > r) swap(l, r);
    if (v.count(l) == 0) make_set(lv), v[l] = lv++;
    if (v.count(r) == 0) make_set(lv), v[r] = lv++;
    if (v.count(++r) == 0) make_set(lv), v[r] = lv++;
    l = v[l], r = v[r];
    if (t == 1) {
      scanf("%lld", &x), x ^= last;
      if (query(l, r) == -1) add(l, r, x);
    } else {
      long long q = query(l, r);
      if (q >= 0)
        last = q;
      else
        last = 1;
      printf("%lld\n", q);
    }
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Nowadays it is becoming increasingly difficult to park a car in cities successfully. Let's imagine a segment of a street as long as L meters along which a parking lot is located. Drivers should park their cars strictly parallel to the pavement on the right side of the street (remember that in the country the authors of the tasks come from the driving is right side!). Every driver when parking wants to leave for themselves some extra space to move their car freely, that's why a driver is looking for a place where the distance between his car and the one behind his will be no less than b meters and the distance between his car and the one in front of his will be no less than f meters (if there's no car behind then the car can be parked at the parking lot segment edge; the same is true for the case when there're no cars parked in front of the car). Let's introduce an axis of coordinates along the pavement. Let the parking lot begin at point 0 and end at point L. The drivers drive in the direction of the coordinates' increasing and look for the earliest place (with the smallest possible coordinate) where they can park the car. In case there's no such place, the driver drives on searching for his perfect peaceful haven. Sometimes some cars leave the street and free some space for parking. Considering that there never are two moving cars on a street at a time write a program that can use the data on the drivers, entering the street hoping to park there and the drivers leaving it, to model the process and determine a parking lot space for each car.

Input

The first line contains three integers L, b и f (10 ≤ L ≤ 100000, 1 ≤ b, f ≤ 100). The second line contains an integer n (1 ≤ n ≤ 100) that indicates the number of requests the program has got. Every request is described on a single line and is given by two numbers. The first number represents the request type. If the request type is equal to 1, then in that case the second number indicates the length of a car (in meters) that enters the street looking for a place to park. And if the request type is equal to 2, then the second number identifies the number of such a request (starting with 1) that the car whose arrival to the parking lot was described by a request with this number, leaves the parking lot. It is guaranteed that that car was parked at the moment the request of the 2 type was made. The lengths of cars are integers from 1 to 1000.

Output

For every request of the 1 type print number -1 on the single line if the corresponding car couldn't find place to park along the street. Otherwise, print a single number equal to the distance between the back of the car in its parked position and the beginning of the parking lot zone.

Examples

Input

30 1 2
6
1 5
1 4
1 5
2 2
1 5
1 4

Output

0
6
11
17
23

Input

30 1 1
6
1 5
1 4
1 5
2 2
1 5
1 4

Output

0
6
11
17
6

Input

10 1 1
1
1 12

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30, maxn = 100000 + 1000;
int n, m, b, f, a, type, cnt = 0, ans[maxn], ansr[maxn];
struct node {
  int v, vl, vr, len;
  node() {}
  node(int _v, int _vl, int _vr, int _len) {
    v = _v, vl = _vl, vr = _vr, len = _len;
  }
  node operator+(const node &A) {
    node ret;
    ret.v = max(v, A.v);
    ret.v = max(ret.v, vr + A.vl);
    ret.vl = vl, ret.vr = A.vr;
    if (vl == len) ret.vl += A.vl;
    if (A.vr == A.len) ret.vr += vr;
    ret.len = len + A.len;
    return ret;
  }
};
struct Segment_Tree {
  int tot, root, tree[maxn << 1][2], lazy[maxn << 1];
  node val[maxn << 1];
  void clear() { tot = tree[0][0] = tree[0][1] = 0; }
  Segment_Tree() { clear(); }
  void update(int o) { val[o] = val[tree[o][0]] + val[tree[o][1]]; }
  void build(int &o, int l, int r) {
    o = ++tot, lazy[o] = -1;
    if (l == r) {
      val[o] = node(1, 1, 1, 1);
      return;
    }
    int mid = (l + r) >> 1;
    build(tree[o][0], l, mid);
    build(tree[o][1], mid + 1, r);
    update(o);
  }
  void Setlazy(int o, int v) {
    val[o].v = val[o].vl = val[o].vr = val[o].len * v;
    lazy[o] = v;
  }
  void Lazydown(int o) {
    if (lazy[o] != -1) {
      Setlazy(tree[o][0], lazy[o]);
      Setlazy(tree[o][1], lazy[o]);
      lazy[o] = -1;
    }
  }
  void Update(int o, int l, int r, int L, int R, int v) {
    if (L <= l && R >= r) {
      Setlazy(o, v);
      return;
    }
    int mid = (l + r) >> 1;
    Lazydown(o);
    if (mid >= L) Update(tree[o][0], l, mid, L, R, v);
    if (mid < R) Update(tree[o][1], mid + 1, r, L, R, v);
    update(o);
  }
  int Query(int o, int l, int r, int v) {
    int mid = (l + r) >> 1;
    if (val[o].vl >= v) return l;
    Lazydown(o);
    if (val[tree[o][0]].v >= v) return Query(tree[o][0], l, mid, v);
    if (val[tree[o][0]].vr + val[tree[o][1]].vl >= v)
      return mid - val[tree[o][0]].vr + 1;
    return Query(tree[o][1], mid + 1, r, v);
  }
} tree;
void Init() {
  scanf("%d%d%d", &n, &b, &f);
  tree.build(tree.root, -b, n + f - 1);
}
void Solve() {
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &type, &a);
    cnt++;
    if (type == 1) {
      if (tree.val[tree.root].v < a + b + f) {
        printf("-1\n");
        continue;
      }
      ans[cnt] = tree.Query(tree.root, -b, n + f - 1, a + b + f) + b;
      tree.Update(tree.root, -b, n + f - 1, ans[cnt], ans[cnt] + a - 1, 0);
      printf("%d\n", ans[cnt]);
      ansr[cnt] = ans[cnt] + a - 1;
    } else
      tree.Update(tree.root, -b, n + f - 1, ans[a], ansr[a], 1);
  }
}
int main() {
  Init();
  Solve();
  return 0;
}

```


### Prompt

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

Let's call an array a consisting of n positive (greater than 0) integers beautiful if the following condition is held for every i from 1 to n: either a_i = 1, or at least one of the numbers a_i - 1 and a_i - 2 exists in the array as well.

For example:

  * the array [5, 3, 1] is beautiful: for a_1, the number a_1 - 2 = 3 exists in the array; for a_2, the number a_2 - 2 = 1 exists in the array; for a_3, the condition a_3 = 1 holds;
  * the array [1, 2, 2, 2, 2] is beautiful: for a_1, the condition a_1 = 1 holds; for every other number a_i, the number a_i - 1 = 1 exists in the array;
  * the array [1, 4] is not beautiful: for a_2, neither a_2 - 2 = 2 nor a_2 - 1 = 3 exists in the array, and a_2 ≠ 1;
  * the array [2] is not beautiful: for a_1, neither a_1 - 1 = 1 nor a_1 - 2 = 0 exists in the array, and a_1 ≠ 1;
  * the array [2, 1, 3] is beautiful: for a_1, the number a_1 - 1 = 1 exists in the array; for a_2, the condition a_2 = 1 holds; for a_3, the number a_3 - 2 = 1 exists in the array.

You are given a positive integer s. Find the minimum possible size of a beautiful array with the sum of elements equal to s.

Input

The first line contains one integer t (1 ≤ t ≤ 5000) — the number of test cases.

Then t lines follow, the i-th line contains one integer s (1 ≤ s ≤ 5000) for the i-th test case.

Output

Print t integers, the i-th integer should be the answer for the i-th testcase: the minimum possible size of a beautiful array with the sum of elements equal to s.

Example

Input

4
1
8
7
42

Output

1
3
3
7

Note

Consider the example test:

  1. in the first test case, the array [1] meets all conditions;
  2. in the second test case, the array [3, 4, 1] meets all conditions;
  3. in the third test case, the array [1, 2, 4] meets all conditions;
  4. in the fourth test case, the array [1, 4, 6, 8, 10, 2, 11] meets all conditions.

### Response

```cpp
// Start Time:
#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define ss                second
#define MX                1000000
#define ll                long long
#define pb                push_back
#define pi                acos(-1.0)
#define PQ                priority_queue
#define mod               1000000007
#define eps               1/1000000000
#define pii               pair<int,int>
#define pll               pair<ll,ll>
#define endl              "\n"
#define Fast              ios::sync_with_stdio(0) //cin.tie(0); cout.tie(0)
#define bug(a)            cout<<#a<<":"<<a<<endl
#define TC(tc)            cout<<"Case "<<tc++<<": "
#define all(x)            (x).begin(),(x).end()
#define allr(x)           (x).rbegin(),(x).rend()
#define Mul(a,b)          (a%mod * b%mod)%mod
#define Add(a,b)          (a%mod + b%mod)%mod
#define mem(a,b)          memset(a, b, sizeof(a))
#define double_print(x,a) cout<<fixed<<setprecision(x)<<a<<endl
ll tc=1;

int main()
{
    Fast;

    ll t;
    cin>>t;
    while(t--)
    {
        ll s;
        cin>>s;
        ll sum=1;
        ll cnt=1;
        ll val=1;
        while(sum<s)
        {
            val+=2;
            sum+=val;
            cnt++;
        }

        cout<<cnt<<endl;
    }

    return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

There are n cities and m two-way roads in Berland, each road connecting two distinct cities.

Recently the Berland government has made a tough decision to transfer ownership of the roads to private companies. In total, there are 100500 private companies in Berland, numbered by integers from 1 to 100500. After the privatization, every road should belong to exactly one company.

The anti-monopoly committee demands that after the privatization each company can own at most two roads. The urbanists of Berland also stated their opinion: each city should be adjacent to the roads owned by at most k companies.

Help the government to distribute the roads between the companies so that both conditions are satisfied. That is, each company gets at most two roads, and each city has roads of at most k distinct companies adjacent to it.

Input

Input contains one or several test cases. The first line contains an integer t (1 ≤ t ≤ 300) — the number of test cases in the input. Solve test cases separately, test cases are completely independent and do not affect each other.

The following lines describe the test cases. Each case starts with a line consisting of three space-separated integers n, m and k (2 ≤ n ≤ 600, 1 ≤ m ≤ 600, 1 ≤ k ≤ n - 1) — the number of cities, the number of roads and the maximum diversity of the roads adjacent to a city.

Then m lines follow, each having a pair of space-separated integers a_i, b_i (1 ≤ a_i, b_i ≤ n; a_i ≠ b_i). It means that the i-th road connects cities a_i and b_i. All roads are two-way. There is at most one road between a pair of the cities.

The sum of n values for all test cases doesn't exceed 600. The sum of m values for all test cases doesn't exceed 600.

Output

Print t lines: the i-th line should contain the answer for the i-th test case. For a test case, print a sequence of integers c_1, c_2, ..., c_m separated by space, where c_i (1 ≤ c_i ≤ 100500) is the company which owns the i-th road in your plan. If there are multiple solutions, output any of them. If there is no solution for a test case, print c_1=c_2=…=c_m=0.

Example

Input

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

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const signed long long llf = (signed long long)(~0ull >> 1);
const signed int inf = (signed)(~0u >> 1);
template <typename T>
T __abs(T x) {
  return (x < 0) ? (-x) : (x);
}
template <typename T>
void pfill(T* pst, const T* ped, T val) {
  for (; pst != ped; *(pst++) = val)
    ;
}
template <typename T>
void pcopy(T* pst, const T* ped, T* pv) {
  for (; pst != ped; *(pst++) = *(pv++))
    ;
}
typedef class Edge {
 public:
  int ed, nx, cap, f;
  Edge() {}
  Edge(int ed, int nx, int cap, int f) : ed(ed), nx(nx), cap(cap), f(f) {}
} Edge;
typedef class MapManager {
 public:
  int* h;
  vector<Edge> es;
  MapManager() {}
  MapManager(int n) {
    h = new int[(n + 1)];
    pfill(h, h + n + 1, -1);
  }
  void addEdge(int u, int v, int cap, int f) {
    es.push_back(Edge(v, h[u], cap, f));
    h[u] = (signed)es.size() - 1;
  }
  void addArc(int u, int v, int cap) {
    addEdge(u, v, cap, 0);
    addEdge(v, u, cap, cap);
  }
  Edge& operator[](int p) { return es[p]; }
  void clear() {
    delete[] h;
    es.clear();
  }
} MapManager;
const int N = 605;
int n, m, K;
int s = 0, t;
int mxcap;
int deg[N];
MapManager g;
inline void init() {
  scanf("%d%d%d", &n, &m, &K);
  pfill(deg, deg + n + 1, 0);
  g = MapManager(n + m + 1);
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d%d", &u, &v);
    deg[u]++, deg[v]++;
    g.addArc(0, i, 1);
    g.addArc(i, u + m, 1);
    g.addArc(i, v + m, 1);
  }
  t = n + m + 1, mxcap = 0;
  for (int i = 1; i <= n; i++)
    if (deg[i] > K) g.addArc(i + m, t, (deg[i] - K) << 1), mxcap += deg[i] - K;
  mxcap <<= 1;
}
int cur[N << 1], _div[N << 1];
int dfs(int p, int mf) {
  if (p == t || !mf) return mf;
  int f, flow = 0;
  for (int &i = cur[p], e; ~i; i = g[i].nx) {
    e = g[i].ed;
    if (g[i].f < g[i].cap && _div[e] == _div[p] + 1 &&
        (f = dfs(e, min(mf, g[i].cap - g[i].f))) > 0) {
      g[i].f += f;
      g[i ^ 1].f -= f;
      mf -= f;
      flow += f;
      if (!mf) break;
    }
  }
  return flow;
}
queue<int> que;
bool bfs() {
  pfill(_div, _div + t + 1, -1);
  _div[s] = 0;
  que.push(s);
  while (!que.empty()) {
    int e = que.front();
    que.pop();
    for (int i = g.h[e], eu; ~i; i = g[i].nx) {
      eu = g[i].ed;
      if (g[i].cap == g[i].f) continue;
      if (~_div[eu]) continue;
      _div[eu] = _div[e] + 1;
      que.push(eu);
    }
  }
  return _div[t] != -1;
}
int dinic() {
  int rt = 0;
  while (bfs()) {
    pcopy(cur, cur + t + 1, g.h);
    rt += dfs(s, inf);
  }
  return rt;
}
int lab[N];
vector<int> mat[N];
inline void solve() {
  int flow = dinic(), used = 0;
  if (flow != mxcap) {
    for (int i = 1; i <= m; i++) printf("0 ");
    putchar('\n');
    return;
  }
  for (int i = 1; i <= n; i++) mat[i].clear();
  for (int i = 1; i <= m; i++)
    for (int j = g.h[i]; ~j; j = g[j].nx)
      if (g[j].cap == g[j].f && g[j].ed > m) {
        mat[g[j].ed - m].push_back(i);
        break;
      }
  pfill(lab + 1, lab + m + 1, 0);
  for (int i = 1, a, b; i <= n; i++)
    while (!mat[i].empty()) {
      a = mat[i].back();
      mat[i].pop_back();
      b = mat[i].back();
      mat[i].pop_back();
      lab[a] = lab[b] = ++used;
    }
  for (int i = 1; i <= m; i++) {
    if (!lab[i]) lab[i] = ++used;
    printf("%d ", lab[i]);
  }
  putchar('\n');
}
inline void clear() { g.clear(); }
int T;
int main() {
  scanf("%d", &T);
  while (T--) {
    init();
    solve();
    clear();
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

You are given three integers x, y and n. Your task is to find the maximum integer k such that 0 ≤ k ≤ n that k mod x = y, where mod is modulo operation. Many programming languages use percent operator % to implement it.

In other words, with given x, y and n you need to find the maximum possible integer from 0 to n that has the remainder y modulo x.

You have to answer t independent test cases. It is guaranteed that such k exists for each test case.

Input

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

The only line of the test case contains three integers x, y and n (2 ≤ x ≤ 10^9;~ 0 ≤ y < x;~ y ≤ n ≤ 10^9).

It can be shown that such k always exists under the given constraints.

Output

For each test case, print the answer — maximum non-negative integer k such that 0 ≤ k ≤ n and k mod x = y. It is guaranteed that the answer always exists.

Example

Input

7
7 5 12345
5 0 4
10 5 15
17 8 54321
499999993 9 1000000000
10 5 187
2 0 999999999

Output

12339
0
15
54306
999999995
185
999999998

Note

In the first test case of the example, the answer is 12339 = 7 ⋅ 1762 + 5 (thus, 12339 mod 7 = 5). It is obvious that there is no greater integer not exceeding 12345 which has the remainder 5 modulo 7.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  int t;
  cin >> t;
  while (t--) {
    int n, x, y;
    cin >> x >> y >> n;
    int r1, r2;
    r1 = n / x;
    r2 = r1 - 1;
    int res1 = (r1 * x) + y;
    int res2 = (r2 * x + y);
    if (res1 <= n)
      cout << (r1 * x) + y << '\n';
    else if (res2 <= n)
      cout << (r2 * x) + y << '\n';
  }
}

```


### Prompt

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

You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly k\ \% magic essence and (100 - k)\ \% water.

In one step, you can pour either one liter of magic essence or one liter of water into the cauldron. What is the minimum number of steps to brew a potion? You don't care about the total volume of the potion, only about the ratio between magic essence and water in it.

A small reminder: if you pour e liters of essence and w liters of water (e + w > 0) into the cauldron, then it contains (e)/(e + w) ⋅ 100\ \% (without rounding) magic essence and (w)/(e + w) ⋅ 100\ \% water.

Input

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

The first and only line of each test case contains a single integer k (1 ≤ k ≤ 100) — the percentage of essence in a good potion.

Output

For each test case, print the minimum number of steps to brew a good potion. It can be proved that it's always possible to achieve it in a finite number of steps.

Example

Input

3
3
100
25

Output

100
1
4

Note

In the first test case, you should pour 3 liters of magic essence and 97 liters of water into the cauldron to get a potion with 3\ \% of magic essence.

In the second test case, you can pour only 1 liter of essence to get a potion with 100\ \% of magic essence.

In the third test case, you can pour 1 liter of magic essence and 3 liters of water.

### Response

```cpp
#include <stdio.h>
#include <iostream>

using namespace std;

int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int main() {
    int t, k;
    cin >> t;
    for(int i = 0; i < t; i++){
        cin >> k;
        int e = 100 - k;
        int gcd_n = gcd(e, k);
        cout << 100/gcd_n << endl;
    }
    return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal!

He decided to visit all n cities of Persia to find the best available mountain, but after the recent war he was too tired and didn't want to traverse a lot. So he wanted to visit each of these n cities at least once with smallest possible traverse. Persian cities are connected with bidirectional roads. You can go from any city to any other one using these roads and there is a unique path between each two cities.

All cities are numbered 1 to n. Shapur is currently in the city 1 and he wants to visit all other cities with minimum possible traverse. He can finish his travels in any city.

Help Shapur find how much He should travel.

Input

First line contains a single natural number n (1 ≤ n ≤ 105) — the amount of cities.

Next n - 1 lines contain 3 integer numbers each xi, yi and wi (1 ≤ xi, yi ≤ n, 0 ≤ wi ≤ 2 × 104). xi and yi are two ends of a road and wi is the length of that road.

Output

A single integer number, the minimal length of Shapur's travel.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).

Examples

Input

3
1 2 3
2 3 4

Output

7

Input

3
1 2 3
1 3 3

Output

9

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long SET(long long N, long long pos) {
  return N = N | ((long long)1 << pos);
}
long long RESET(long long N, long long pos) {
  return N = N & ~((long long)1 << pos);
}
bool CHECK(long long N, long long pos) {
  return (bool)(N & ((long long)1 << pos));
}
template <typename T>
inline T __lcm(T a, T b) {
  return (a * b) / __gcd(a, b);
}
struct node {
  long long i, x, y;
};
long long dx[] = {0, 1, 0, -1, -1, 1, -1, 1};
long long dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
long long dist[1000000];
vector<pair<long long, long long> > adj[1000000];
void dijkstra(long long source) {
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      pq;
  pq.push(make_pair(0, source));
  dist[source] = 0;
  while (!pq.empty()) {
    long long u = pq.top().second;
    pq.pop();
    for (long long i = 0; i < adj[u].size(); i++) {
      long long v = adj[u][i].first;
      long long weight = adj[u][i].second;
      if (dist[v] > dist[u] + weight) {
        dist[v] = dist[u] + weight;
        pq.push(make_pair(dist[v], v));
      }
    }
  }
}
void solve() {
  long long n;
  cin >> n;
  long long ans = 0;
  for (long long i = 0; i <= n; i++) {
    dist[i] = 10000000000;
  }
  for (long long i = 0; i < n - 1; i++) {
    long long x, y, w;
    cin >> x >> y >> w;
    ans += 2 * w;
    adj[x].push_back({y, w});
    adj[y].push_back({x, w});
  }
  dijkstra(1);
  long long maxi = 0;
  for (long long i = 1; i <= n; i++) {
    maxi = max(maxi, dist[i]);
  }
  ans -= maxi;
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

It's a beautiful April day and Wallace is playing football with his friends. But his friends do not know that Wallace actually stayed home with Gromit and sent them his robotic self instead. Robo-Wallace has several advantages over the other guys. For example, he can hit the ball directly to the specified point. And yet, the notion of a giveaway is foreign to him. The combination of these features makes the Robo-Wallace the perfect footballer — as soon as the ball gets to him, he can just aim and hit the goal. He followed this tactics in the first half of the match, but he hit the goal rarely. The opposing team has a very good goalkeeper who catches most of the balls that fly directly into the goal. But Robo-Wallace is a quick thinker, he realized that he can cheat the goalkeeper. After all, they are playing in a football box with solid walls. Robo-Wallace can kick the ball to the other side, then the goalkeeper will not try to catch the ball. Then, if the ball bounces off the wall and flies into the goal, the goal will at last be scored.

Your task is to help Robo-Wallace to detect a spot on the wall of the football box, to which the robot should kick the ball, so that the ball bounces once and only once off this wall and goes straight to the goal. In the first half of the match Robo-Wallace got a ball in the head and was severely hit. As a result, some of the schemes have been damaged. Because of the damage, Robo-Wallace can only aim to his right wall (Robo-Wallace is standing with his face to the opposing team's goal).

The football box is rectangular. Let's introduce a two-dimensional coordinate system so that point (0, 0) lies in the lower left corner of the field, if you look at the box above. Robo-Wallace is playing for the team, whose goal is to the right. It is an improvised football field, so the gate of Robo-Wallace's rivals may be not in the middle of the left wall.

<image>

In the given coordinate system you are given:

  * y1, y2 — the y-coordinates of the side pillars of the goalposts of robo-Wallace's opponents;
  * yw — the y-coordinate of the wall to which Robo-Wallace is aiming;
  * xb, yb — the coordinates of the ball's position when it is hit;
  * r — the radius of the ball.

A goal is scored when the center of the ball crosses the OY axis in the given coordinate system between (0, y1) and (0, y2). The ball moves along a straight line. The ball's hit on the wall is perfectly elastic (the ball does not shrink from the hit), the angle of incidence equals the angle of reflection. If the ball bounces off the wall not to the goal, that is, if it hits the other wall or the goal post, then the opposing team catches the ball and Robo-Wallace starts looking for miscalculation and gets dysfunctional. Such an outcome, if possible, should be avoided. We assume that the ball touches an object, if the distance from the center of the ball to the object is no greater than the ball radius r.

Input

The first and the single line contains integers y1, y2, yw, xb, yb, r (1 ≤ y1, y2, yw, xb, yb ≤ 106; y1 < y2 < yw; yb + r < yw; 2·r < y2 - y1).

It is guaranteed that the ball is positioned correctly in the field, doesn't cross any wall, doesn't touch the wall that Robo-Wallace is aiming at. The goal posts can't be located in the field corners.

Output

If Robo-Wallace can't score a goal in the described manner, print "-1" (without the quotes). Otherwise, print a single number xw — the abscissa of his point of aiming.

If there are multiple points of aiming, print the abscissa of any of them. When checking the correctness of the answer, all comparisons are made with the permissible absolute error, equal to 10 - 8.

It is recommended to print as many characters after the decimal point as possible.

Examples

Input

4 10 13 10 3 1

Output

4.3750000000

Input

1 4 6 2 2 1

Output

-1

Input

3 10 15 17 9 2

Output

11.3333333333

Note

Note that in the first and third samples other correct values of abscissa xw are also possible.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int mod = (int)1e9 + 7;
const long double INF = (long double)(1e3);
const int N = 100005;
const double PI = acos(-1.0);
const double eps = 1e-9;
int main() {
  double vamdlsfmvldf, y2, yw, xb, yb, r;
  while (cin >> vamdlsfmvldf >> y2 >> yw >> xb >> yb >> r) {
    double yr = yw - r;
    double my1 = yr + (yr - vamdlsfmvldf);
    double my2 = yr + (yr - y2);
    double aim_y = my1 - r;
    double inc_y = (aim_y - yb) / xb;
    double xw = (aim_y - yr) / inc_y;
    double a = PI / 2 - atan2(aim_y - yb, xb);
    double d = r / sin(a);
    if (aim_y - d < my2)
      puts("-1");
    else
      printf("%.10f\n", xw);
  }
}

```


### Prompt

Please create a solution in CPP to the following problem:

Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance?

Input

The first and only line of input contains a single integer n (1 ≤ n ≤ 10^9).

Output

Output the minimum number of bills that Allen could receive.

Examples

Input

125

Output

3

Input

43

Output

5

Input

1000000000

Output

10000000

Note

In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills.

In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills.

In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  int arr[5];
  arr[0] = 1;
  arr[1] = 5;
  arr[2] = 10;
  arr[3] = 20;
  arr[4] = 100;
  long long int i = 4;
  long long int val = 0;
  while (n != 0) {
    val += n / arr[i];
    n = n % arr[i];
    i -= 1;
  }
  cout << val;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

There is a river of width n. The left bank of the river is cell 0 and the right bank is cell n + 1 (more formally, the river can be represented as a sequence of n + 2 cells numbered from 0 to n + 1). There are also m wooden platforms on a river, the i-th platform has length c_i (so the i-th platform takes c_i consecutive cells of the river). It is guaranteed that the sum of lengths of platforms does not exceed n.

You are standing at 0 and want to reach n+1 somehow. If you are standing at the position x, you can jump to any position in the range [x + 1; x + d]. However you don't really like the water so you can jump only to such cells that belong to some wooden platform. For example, if d=1, you can jump only to the next position (if it belongs to the wooden platform). You can assume that cells 0 and n+1 belong to wooden platforms.

You want to know if it is possible to reach n+1 from 0 if you can move any platform to the left or to the right arbitrary number of times (possibly, zero) as long as they do not intersect each other (but two platforms can touch each other). It also means that you cannot change the relative order of platforms.

Note that you should move platforms until you start jumping (in other words, you first move the platforms and then start jumping).

For example, if n=7, m=3, d=2 and c = [1, 2, 1], then one of the ways to reach 8 from 0 is follow:

<image> The first example: n=7.

Input

The first line of the input contains three integers n, m and d (1 ≤ n, m, d ≤ 1000, m ≤ n) — the width of the river, the number of platforms and the maximum distance of your jump, correspondingly.

The second line of the input contains m integers c_1, c_2, ..., c_m (1 ≤ c_i ≤ n, ∑_{i=1}^{m} c_i ≤ n), where c_i is the length of the i-th platform.

Output

If it is impossible to reach n+1 from 0, print NO in the first line. Otherwise, print YES in the first line and the array a of length n in the second line — the sequence of river cells (excluding cell 0 and cell n + 1).

If the cell i does not belong to any platform, a_i should be 0. Otherwise, it should be equal to the index of the platform (1-indexed, platforms are numbered from 1 to m in order of input) to which the cell i belongs.

Note that all a_i equal to 1 should form a contiguous subsegment of the array a of length c_1, all a_i equal to 2 should form a contiguous subsegment of the array a of length c_2, ..., all a_i equal to m should form a contiguous subsegment of the array a of length c_m. The leftmost position of 2 in a should be greater than the rightmost position of 1, the leftmost position of 3 in a should be greater than the rightmost position of 2, ..., the leftmost position of m in a should be greater than the rightmost position of m-1.

See example outputs for better understanding.

Examples

Input

7 3 2
1 2 1

Output

YES
0 1 0 2 2 0 3

Input

10 1 11
1

Output

YES
0 0 0 0 0 0 0 0 0 1

Input

10 1 5
2

Output

YES
0 0 0 0 1 1 0 0 0 0

Note

Consider the first example: the answer is [0, 1, 0, 2, 2, 0, 3]. The sequence of jumps you perform is 0 → 2 → 4 → 5 → 7 → 8.

Consider the second example: it does not matter how to place the platform because you always can jump from 0 to 11.

Consider the third example: the answer is [0, 0, 0, 0, 1, 1, 0, 0, 0, 0]. The sequence of jumps you perform is 0 → 5 → 6 → 11.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const long long N = 3e5 + 7;
long long n, m, d;
long long arr[N], plank[N], pos[N], st[N];
void solve() {
  cin >> n >> m >> d;
  for (long long i = 0; i < m; i++) cin >> plank[i];
  for (long long i = 0; i < m; i++) {
    long long x = plank[i];
    if (i != 0)
      pos[i] = pos[i - 1] + x;
    else
      pos[i] = x;
    st[i] = pos[i] - plank[i] + 1;
  }
  pos[m] = n + 1;
  st[m] = n + 1;
  for (long long i = m - 1; i >= 0; i--) {
    if (st[i + 1] - d > pos[i]) {
      long long x = (st[i + 1] - d);
      pos[i] = x;
      st[i] = pos[i] - plank[i] + 1;
    }
  }
  for (long long i = 0; i < m; i++)
    for (long long j = st[i]; j < pos[i] + 1; j++) arr[j] = i + 1;
  if (st[0] > d)
    cout << "NO";
  else {
    cout << "YES" << '\n';
    for (long long i = 1; i < n + 1; i++) cout << arr[i] << " ";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
}

```


### Prompt

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

You are given a permutation p of numbers 1, 2, ..., n. Let's define f(p) as the following sum:

<image>

Find the lexicographically m-th permutation of length n in the set of permutations having the maximum possible value of f(p).

Input

The single line of input contains two integers n and m (1 ≤ m ≤ cntn), where cntn is the number of permutations of length n with maximum possible value of f(p).

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

  * In subproblem B1 (3 points), the constraint 1 ≤ n ≤ 8 will hold.
  * In subproblem B2 (4 points), the constraint 1 ≤ n ≤ 50 will hold.

Output

Output n number forming the required permutation.

Examples

Input

2 2

Output

2 1

Input

3 2

Output

1 3 2

Note

In the first example, both permutations of numbers {1, 2} yield maximum possible f(p) which is equal to 4. Among them, (2, 1) comes second in lexicographical order.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAXN = 100;
long long pd[MAXN];
long long perm[MAXN];
int main() {
  long long n, m;
  pd[1] = 1;
  for (int i = 2; i < 60; ++i) pd[i] = pd[i - 1] * 2;
  while (cin >> n >> m) {
    long long a = 0, b = n - 1;
    m--;
    for (int i = 0; i < n; ++i) {
      long long x = b - a;
      if (pd[x] > m) {
        perm[a++] = i + 1;
      } else {
        perm[b--] = i + 1;
        m -= pd[x];
      }
    }
    for (int i = 0; i < n; ++i) {
      cout << perm[i] << " ";
    }
    cout << endl;
  }
}

```


### Prompt

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

Input

The only line of input contains three integers a1, a2, a3 (1 ≤ a1, a2, a3 ≤ 20), separated by spaces.

Output

Output a single integer.

Examples

Input

2 3 2

Output

5

Input

13 14 1

Output

14

Input

14 5 9

Output

464

Input

17 18 3

Output

53

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int a, b, c, n;
  scanf("%d%d%d", &a, &b, &n);
  for (int i = 0; i < n; i++) {
    c = a + b;
    a = b;
    b = c;
  }
  printf("%d\n", a);
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 × 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below:

<image>

In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed.

Input

The first two lines of the input consist of a 2 × 2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2 × 2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position.

Output

Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes).

Examples

Input

AB
XC
XB
AC

Output

YES

Input

AB
XC
AC
BX

Output

NO

Note

The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.

In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all...

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 2e9 + 1;
const double eps = 1e-9;
const int N = 1e5 + 5;
map<string, int> mp;
void fnd(string s) {
  if (mp.count(s)) return;
  mp[s] = 1;
  string t1, t2;
  for (int i = 0; i < 4; ++i) {
    if (s[i] == 'X') {
      swap(s[i], s[(i + 1) % 4]);
      t1 = s;
      swap(s[i], s[(i + 1) % 4]);
      swap(s[i], s[(i + 3) % 4]);
      t2 = s;
      swap(s[i], s[(i + 3) % 4]);
      fnd(t1);
      fnd(t2);
    }
  }
}
string s1, s2;
string t1, t2;
int main() {
  cin >> s1 >> s2 >> t1 >> t2;
  reverse(s2.begin(), s2.end());
  reverse(t2.begin(), t2.end());
  s1 += s2;
  fnd(s1);
  t1 += t2;
  if (mp.count(t1)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You may also refer to the guide on interactive problems: <https://codeforces.com/blog/entry/45307>.

The jury guessed some array a consisting of 6 integers. There are 6 special numbers — 4, 8, 15, 16, 23, 42 — and each of these numbers occurs in a exactly once (so, a is some permutation of these numbers).

You don't know anything about their order, but you are allowed to ask up to 4 queries. In each query, you may choose two indices i and j (1 ≤ i, j ≤ 6, i and j are not necessarily distinct), and you will get the value of a_i ⋅ a_j in return.

Can you guess the array a?

The array a is fixed beforehand in each test, the interaction program doesn't try to adapt to your queries.

Interaction

Before submitting the answer, you may ask up to 4 queries. To ask a query, print one line in the following format: ? i j, where i and j should be two integers such that 1 ≤ i, j ≤ 6. The line should be ended with a line break character. After submitting a query, flush the output and read the answer to your query — one line containing one integer a_i ⋅ a_j. If you submit an incorrect query (or ask more than 4 queries), the answer to it will be one string 0. After receiving such an answer, your program should terminate immediately — otherwise you may receive verdict "Runtime error", "Time limit exceeded" or some other verdict instead of "Wrong answer".

To give the answer, your program should print one line ! a_1 a_2 a_3 a_4 a_5 a_6 with a line break in the end. After that, it should flush the output and terminate gracefully.

Example

Input

16
64
345
672

Output

? 1 1
? 2 2
? 3 5
? 4 6
! 4 8 15 16 23 42

Note

If you want to submit a hack for this problem, your test should contain exactly six space-separated integers a_1, a_2, ..., a_6. Each of 6 special numbers should occur exactly once in the test. The test should be ended with a line break character.

### Response

```cpp
#include <bits/stdc++.h>
const int N = 5e3;
using namespace std;
long long x, y, pre, suc;
int main() {
  for (int i = 0; i < 7; i++) suc |= (1 << i);
  for (int i = 7; i < 14; i++) pre |= (1 << i);
  cout << "?";
  for (int i = 0; i < 100; i++) cout << " " << i;
  cout << "\n";
  cin >> x;
  x &= pre;
  fflush(stdout);
  cout << "?";
  for (int i = 1; i <= 100; i++) cout << " " << (i << 7);
  cout << "\n";
  cin >> y;
  y &= suc;
  fflush(stdout);
  cout << "! " << (x ^ y);
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

A number is called 2050-number if it is 2050, 20500, ..., (2050 ⋅ 10^k for integer k ≥ 0).

Given a number n, you are asked to represent n as the sum of some (not necessarily distinct) 2050-numbers. Compute the minimum number of 2050-numbers required for that.

Input

The first line contains a single integer T (1≤ T≤ 1 000) denoting the number of test cases.

The only line of each test case contains a single integer n (1≤ n≤ 10^{18}) denoting the number to be represented.

Output

For each test case, output the minimum number of 2050-numbers in one line.

If n cannot be represented as the sum of 2050-numbers, output -1 instead.

Example

Input

6
205
2050
4100
20500
22550
25308639900

Output

-1
1
2
1
2
36

Note

In the third case, 4100 = 2050 + 2050.

In the fifth case, 22550 = 20500 + 2050.

### Response

```cpp
/*
    author:  Maksim1744
    created: 23.04.2021 17:35:34
*/

#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

#define mp   make_pair
#define pb   push_back
#define eb   emplace_back

#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

template<typename T>             vector<T>& operator--            (vector<T> &v){for (auto& i : v) --i;            return  v;}
template<typename T>             vector<T>& operator++            (vector<T> &v){for (auto& i : v) ++i;            return  v;}
template<typename T>             istream& operator>>(istream& is,  vector<T> &v){for (auto& i : v) is >> i;        return is;}
template<typename T>             ostream& operator<<(ostream& os,  vector<T>  v){for (auto& i : v) os << i << ' '; return os;}
template<typename T, typename U> pair<T,U>& operator--           (pair<T, U> &p){--p.first; --p.second;            return  p;}
template<typename T, typename U> pair<T,U>& operator++           (pair<T, U> &p){++p.first; ++p.second;            return  p;}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U> &p){is >> p.first >> p.second;        return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U>  p){os << p.first << ' ' << p.second; return os;}
template<typename T, typename U> pair<T,U> operator-(pair<T,U> a, pair<T,U> b){return mp(a.first-b.first, a.second-b.second);}
template<typename T, typename U> pair<T,U> operator+(pair<T,U> a, pair<T,U> b){return mp(a.first+b.first, a.second+b.second);}
template<typename T, typename U> void umin(T& a, U b){if (a > b) a = b;}
template<typename T, typename U> void umax(T& a, U b){if (a < b) a = b;}

#ifdef HOME
#define SHOW_COLORS
#include "C:/C++ libs/print.cpp"
#else
#define show(...) void(0)
#define mclock    void(0)
#define shows     void(0)
#define debug  if (false)
#endif

void test_case(int test) {
    ll n;
    cin >> n;
    int k = 2050;
    if (n % k != 0) {
        cout << -1 << '\n';
        return;
    }
    n /= k;
    int s = 0;
    while (n) {
        s += n % 10;
        n /= 10;
    }
    cout << s << '\n';
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int T;
    cin >> T;
    for (int test = 1; test <= T; ++test) {
        test_case(test);
    }

    return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.

For each opponent Arya knows his schedule — whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.

Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.

Input

The first line of the input contains two integers n and d (1 ≤ n, d ≤ 100) — the number of opponents and the number of days, respectively.

The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.

Output

Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents.

Examples

Input

2 2
10
00

Output

2

Input

4 1
0100

Output

1

Input

4 5
1101
1111
0110
1011
1111

Output

2

Note

In the first and the second samples, Arya will beat all present opponents each of the d days.

In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, i, j, k, l, m, n, p, q;
  long long a, b, c, d;
  string s, s1, ans;
  while (cin >> n >> m) {
    ans = "";
    for (i = 0; i < n; i++) ans += '1';
    long long rem = 0;
    long long cnt = 0;
    for (i = 0; i < m; i++) {
      cin >> s;
      if (s != ans) {
        cnt++;
      } else {
        rem = max(rem, cnt);
        cnt = 0;
      }
    }
    cout << max(rem, cnt) << endl;
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that

1. 1 ≤ i, j ≤ N

2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th.

Input

The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105.

Output

Print a single number which represents the number of pairs i and j with the needed property. Pairs (x, y) and (y, x) should be considered different, i.e. the ordered pairs count.

Examples

Input

great10

Output

7

Input

aaaaaaaaaa

Output

100

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[100005];
  int a[100]{}, n;
  long long x = 0;
  scanf("%s", s), n = strlen(s);
  for (int i = 0; i < n; i++) a[s[i] - '0']++;
  for (int i = 0; i < 100; i++) x += 1LL * a[i] * a[i];
  printf("%I64d\n", x);
  return 0;
}

```


### Prompt

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

Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.

Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year bi inclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event j includes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.

Input

The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.

Output

Print the only integer — the answer to the problem.

Examples

Input

5
1 10
2 9
3 8
4 7
5 6

Output

4

Input

5
1 100
2 50
51 99
52 98
10 60

Output

4

Input

1
1 1000000000

Output

0

Note

In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first.

In the second example all events except the first one are contained in the first.

In the third example only one event, so the answer is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
pair<long long int, long long int> a[100001];
long long int u[100001 + 1];
int FIND(int x) {
  if (u[x] != u[u[x]]) u[x] = FIND(u[x]);
  return u[x];
}
bool UNION(int x, int y) {
  int px = FIND(x), py = FIND(y);
  if (px == py) return false;
  u[px] = py;
  return true;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;
  long long int x, y;
  cin >> n;
  for (int i = 0; i < n; i++) {
    u[i] = i;
    cin >> x >> y;
    a[i].first = x;
    a[i].second = y;
  }
  sort(a, a + n);
  int cnt = 0;
  for (int i = 1; i < n; i++) {
    if (a[i].second < a[FIND(i - 1)].second) UNION(i, i - 1);
  }
  unordered_set<int> hs;
  for (int i = 0; i < n; i++) {
    int curr = u[i];
    if (hs.find(curr) != hs.end()) cnt++;
    hs.insert(curr);
  }
  cout << cnt;
  return 0;
}

```


### Prompt

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

Problem

A graph is given in which N vertices, each numbered from 1 to N, are connected by N-1 undirected edges. For each vertex, output the shortest number of steps to start from that vertex and visit all vertices.

However, one step is to follow one side from one vertex and move to another vertex.

Constraints

* 2 ≤ N ≤ 105
* 1 ≤ ui, vi ≤ N (1 ≤ i ≤ N-1)
* ui ≠ vi
* The graph given is concatenated

Input

The input is given in the following format.

N
u1 v1
..
..
..
uN−1 vN−1

The first line is given one integer N.
In the following N-1 line, the integers ui and vi representing the vertex numbers at both ends of the i-th side are given on the i-th line, separated by blanks.

Output

Output the shortest number of steps to visit all vertices starting from vertex i on the i-th line from vertex 1 to vertex N.

Examples

Input

2
1 2

Output

1
1

Input

6
1 2
1 3
3 4
3 5
5 6

Output

7
6
8
7
7
6

### Response

```cpp
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

#define int long long

vector<int>v[200009];
int dp[300003];
int ans[300003];
int n , mod=1000000007  , m ;

void dfs( int now , int pre ) {
  dp[now] = 0;
  r(i,v[now].size()){
    int nex = v[now][i];
    if( pre == nex )continue;
    dfs( nex , now );
    dp[now] = max( dp[now] , dp[nex] + 1 ) % mod;
  }
}

void dfs2( int now , int pre , int x ) {

  ans[now] = max( dp[now] , x) % mod;

  vector<int> l , r;
  int N = v[now].size() + 1;

  l.push_back( 0 );

  r( i , v[now].size() ){
    int nex = v[now][i];
    int w = nex==pre ? x : dp[nex]+1 ;
    l.push_back( w );
    r.push_back( w );
  }

  r.push_back( 0 );

  for( int i = 1 ; i < N ; i++ ){
    l[i] = max( l[i] , l[i-1] ) % mod;
  }

  for( int i = N-2 ; i >= 0 ; i-- ){
    r[i] = max( r[i] , r[i+1] );
  }

  for( int i = 0 ; i < v[now].size() ; i++ ){
    if( v[now][i] == pre )continue;
    dfs2( v[now][i] , now ,  max(l[i],r[i+1])+1 );
  }

}

signed main(){
  cin>>n;

  r(i,n-1){
    int a,b;
    cin>>a>>b;a--;b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }

  dfs(0,0);
  dfs2(0,0,0);

  r(i,n) cout<<(n-1)*2-ans[i]<<endl;
}

```