### Prompt

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

You are organizing a cycling race on the streets of the city. The city contains n junctions, some pairs of them are connected by roads; on each road you can move in any direction. No two roads connect the same pair of intersections, and no road connects the intersection with itself.

You want the race to be open to both professional athletes and beginner cyclists, and that's why you will organize the race in three nominations: easy, moderate and difficult; each participant will choose the more suitable nomination. For each nomination you must choose the route — the chain of junctions, consecutively connected by roads. Routes must meet the following conditions:

  * all three routes should start at the same intersection, and finish at the same intersection (place of start and finish can't be the same);
  * to avoid collisions, no two routes can have common junctions (except for the common start and finish), and can not go along the same road (irrespective of the driving direction on the road for those two routes);
  * no route must pass twice through the same intersection or visit the same road twice (irrespective of the driving direction on the road for the first and second time of visit).

Preparing for the competition is about to begin, and you need to determine the routes of the race as quickly as possible. The length of the routes is not important, it is only important that all the given requirements were met.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of intersections and roads, respectively.

The following m lines contain two integers — the numbers of the intersections connected by a road (the intersections are numbered starting with 1). It is guaranteed that each pair of intersections is connected by no more than one road, and no road connects the intersection to itself.

Please note that it is not guaranteed that you can get from any junction to any other one by using the roads.

Output

If it is possible to create the routes, in the first line print "YES". In the next three lines print the descriptions of each of the three routes in the format "l p1 ... pl", where l is the number of intersections in the route, and p1, ..., pl are their numbers in the order they follow. The routes must meet all the requirements specified in the statement.

If it is impossible to make the routes in accordance with the requirements, print NO.

Examples

Input

4 4
1 2
2 3
3 4
4 1

Output

NO

Input

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

Output

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

### Response

```cpp
#include <bits/stdc++.h>
const int MN = 200005;
int N, M;
std::vector<int> G[MN];
int faz[MN * 2], cnt;
std::vector<int> V[MN];
std::vector<std::pair<int, int> > E[MN];
int deg[MN];
int stk[MN], tp;
int dfn[MN], low[MN], dfc;
void Tarjan(int u) {
  low[u] = dfn[u] = ++dfc;
  stk[++tp] = u;
  for (auto v : G[u]) {
    if (!dfn[v]) {
      Tarjan(v);
      low[u] = std::min(low[u], low[v]);
      if (low[v] == dfn[u]) {
        ++cnt;
        for (int x = 0; x != v; --tp)
          faz[x = stk[tp]] = cnt, V[cnt - N].push_back(x);
        faz[cnt] = u;
        V[cnt - N].push_back(u);
      }
    } else
      low[u] = std::min(low[u], dfn[v]);
  }
}
int key[MN], vis[MN];
int DFS(int u, int f) {
  stk[++tp] = u;
  if (f && key[u]) return 1;
  if (vis[u]) return --tp, 0;
  vis[u] = 1;
  for (auto v : G[u])
    if (v != f && DFS(v, u)) return 1;
  return --tp, 0;
}
int main() {
  scanf("%d%d", &N, &M), cnt = N;
  for (int i = 1, x, y; i <= M; ++i)
    scanf("%d%d", &x, &y), G[x].push_back(y), G[y].push_back(x);
  for (int u = 1; u <= N; ++u)
    if (!dfn[u]) Tarjan(u), --tp;
  for (int u = 1; u <= N; ++u)
    for (auto v : G[u])
      if (v > u) {
        int b = faz[u] == faz[v] ? faz[u] : faz[faz[u]] == v ? faz[u] : faz[v];
        E[b - N].push_back({u, v});
      }
  for (int u = 1; u <= N; ++u) G[u].clear();
  cnt -= N;
  for (int i = 1; i <= cnt; ++i) {
    if (V[i].size() >= E[i].size()) continue;
    for (auto e : E[i]) {
      int u = e.first, v = e.second;
      G[u].push_back(v), G[v].push_back(u);
      ++deg[u], ++deg[v];
    }
    int p = 0;
    for (auto u : V[i])
      if (deg[u] >= 3) p = u;
    key[p] = 1, DFS(p, 0), key[p] = 0;
    static int Ans[MN];
    int len = tp;
    for (int j = 1; j <= tp; ++j) Ans[j] = stk[j];
    for (int j = 2; j < len; ++j) key[Ans[j]] = 1;
    for (auto u : V[i]) vis[u] = 0;
    stk[tp = 1] = p, vis[p] = 1;
    for (auto v : G[p])
      if (v != Ans[2] && v != Ans[len - 1] && DFS(v, p)) break;
    auto Print = [&](int *a, int x) {
      int c = 1;
      while (a[c] != x) ++c;
      printf("%d", c);
      for (int i = 1; i <= c; ++i) printf(" %d", a[i]);
      putchar('\n');
    };
    puts("YES");
    Print(stk, stk[tp]);
    Print(Ans, stk[tp]);
    std::reverse(Ans + 1, Ans + len + 1);
    Print(Ans, stk[tp]);
    return 0;
  }
  puts("NO");
  return 0;
}

```


### Prompt

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

Consider the following arithmetic progression with n terms:

* x, x + d, x + 2d, \ldots, x + (n-1)d

What is the product of all terms in this sequence? Compute the answer modulo 1\ 000\ 003.

You are given Q queries of this form. In the i-th query, compute the answer in case x = x_i, d = d_i, n = n_i.

Constraints

* 1 \leq Q \leq 10^5
* 0 \leq x_i, d_i \leq 1\ 000\ 002
* 1 \leq n_i \leq 10^9
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

Q
x_1 d_1 n_1
:
x_Q d_Q n_Q

Output

Print Q lines.

In the i-th line, print the answer for the i-th query.

Example

Input

2
7 2 4
12345 67890 2019

Output

9009
916936

### Response

```cpp
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<iomanip>
#include<utility>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define fi first
#define sec second
#define mp make_pair
#define pb push_back
#define rep(a,b,c) for(ll a=1;a<=b;a+=c)
#define repp(a,b,c,d) for(int a=b;a<=c;a+=d)

const double PI=acos(-1);
const double EPS=1e-12;
const ll MOD=1e6+3;
const int INF=1<<30;

using namespace std;

ll fact[3000005];

void pre(){
	fact[0]=1;
	rep(i,3000000,1){
		fact[i]=fact[i-1]*i;
		fact[i]%=MOD;
	}
}

ll fast(ll a,ll b){
	if(b==0)return 1;
	ll temp=fast(a,b/2);
	temp*=temp;
	temp%=MOD;
	if(b%2==1)temp*=a;
	return temp%MOD;
}

ll gamma(ll a){
	return fact[a-1];
}

int main(){
	ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	pre();
	int in;
	ll a,d,n,res;
	cin>>in;
	rep(i,in,1){
		cin>>a>>d>>n;
		res=fast(d,n);
		if(d==0){
			cout<<fast(a,n)<<endl;
			continue;
		}
		if(n>=MOD){
			cout<<0<<endl;
		}
		else{
			res*=gamma((a*fast(d,MOD-2)%MOD)+n);
			res%=MOD;
			res*=fast(gamma((a*fast(d,MOD-2))%MOD),MOD-2);
			res%=MOD;
			cout<<res<<endl;
		}
	}
	return 0;
}

```


### Prompt

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

Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.

Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.

Input

The first line contains integer q (1 ≤ q ≤ 1000), the number of handle change requests.

Next q lines contain the descriptions of the requests, one per line.

Each query consists of two non-empty strings old and new, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings old and new are distinct. The lengths of the strings do not exceed 20.

The requests are given chronologically. In other words, by the moment of a query there is a single person with handle old, and handle new is not used and has not been used by anyone.

Output

In the first line output the integer n — the number of users that changed their handles at least once.

In the next n lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, old and new, separated by a space, meaning that before the user had handle old, and after all the requests are completed, his handle is new. You may output lines in any order.

Each user who changes the handle must occur exactly once in this description.

Examples

Input

5
Misha ILoveCodeforces
Vasya Petrov
Petrov VasyaPetrov123
ILoveCodeforces MikeMirzayanov
Petya Ivanov

Output

3
Petya Ivanov
Misha MikeMirzayanov
Vasya VasyaPetrov123

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, k;
  string x, y;
  vector<pair<string, string> > v;
  cin >> t;
  while (t--) {
    k = 0;
    cin >> x >> y;
    for (int i = 0; i < v.size(); i++) {
      if (x == v[i].second) {
        v[i].second = y;
        k = 1;
        break;
      }
    }
    if (k == 0) {
      v.push_back(make_pair(x, y));
    }
  }
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i].first << " " << v[i].second << endl;
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

One must train much to do well on wizardry contests. So, there are numerous wizardry schools and magic fees.

One of such magic schools consists of n tours. A winner of each tour gets a huge prize. The school is organised quite far away, so one will have to take all the prizes home in one go. And the bags that you've brought with you have space for no more than k huge prizes.

Besides the fact that you want to take all the prizes home, you also want to perform well. You will consider your performance good if you win at least l tours.

In fact, years of organizing contests proved to the organizers that transporting huge prizes is an issue for the participants. Alas, no one has ever invented a spell that would shrink the prizes... So, here's the solution: for some tours the winner gets a bag instead of a huge prize. Each bag is characterized by number ai — the number of huge prizes that will fit into it.

You already know the subject of all tours, so you can estimate the probability pi of winning the i-th tour. You cannot skip the tour under any circumstances.

Find the probability that you will perform well on the contest and will be able to take all won prizes home (that is, that you will be able to fit all the huge prizes that you won into the bags that you either won or brought from home).

Input

The first line contains three integers n, l, k (1 ≤ n ≤ 200, 0 ≤ l, k ≤ 200) — the number of tours, the minimum number of tours to win, and the number of prizes that you can fit in the bags brought from home, correspondingly.

The second line contains n space-separated integers, pi (0 ≤ pi ≤ 100) — the probability to win the i-th tour, in percents.

The third line contains n space-separated integers, ai (1 ≤ ai ≤ 200) — the capacity of the bag that will be awarded to you for winning the i-th tour, or else -1, if the prize for the i-th tour is a huge prize and not a bag.

Output

Print a single real number — the answer to the problem. The answer will be accepted if the absolute or relative error does not exceed 10 - 6.

Examples

Input

3 1 0
10 20 30
-1 -1 2

Output

0.300000000000

Input

1 1 1
100
123

Output

1.000000000000

Note

In the first sample we need either win no tour or win the third one. If we win nothing we wouldn't perform well. So, we must to win the third tour. Other conditions will be satisfied in this case. Probability of wining the third tour is 0.3.

In the second sample we win the only tour with probability 1.0, and go back home with bag for it.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
double dp[210][210][420];
int main() {
  int n, l, k;
  cin >> n >> l >> k;
  int a[n];
  double p[n];
  for (int i = 0; i < int(n); i++) {
    int x;
    cin >> x;
    p[i] = x / 100.0;
  }
  for (int i = 0; i < int(n); i++) cin >> a[i];
  dp[0][0][k + 203] = 1;
  for (int i = 0; i < int(n); i++) {
    for (int m = 0; m < int(410 + 1); m++) {
      for (int j = 0; j < int(201); j++) {
        if (m + a[i] >= 0) {
          dp[i + 1][j + 1][min(410, m + a[i])] += dp[i][j][m] * p[i];
        }
        dp[i + 1][j][m] += dp[i][j][m] * (1 - p[i]);
      }
    }
  }
  double ans = 0;
  for (int m = 203; m <= 410; m++)
    for (int j = l; j <= 200; j++) {
      ans += dp[n][j][m];
    }
  printf("%.20f\n", ans);
  return 0;
}

```


### Prompt

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

Given are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller?

Constraints

* 1 \leq a \leq 9
* 1 \leq b \leq 9
* a and b are integers.

Input

Input is given from Standard Input in the following format:

a b

Output

Print the lexicographically smaller of the two strings. (If the two strings are equal, print one of them.)

Examples

Input

4 3

Output

3333

Input

7 7

Output

7777777

### Response

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

int a,b;

int main()
{
    cin>>a>>b;
    for (int i=0; i<max(a,b); i++) cout<<min(a,b);
    cout<<endl;
    return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

There are n stone quarries in Petrograd.

Each quarry owns mi dumpers (1 ≤ i ≤ n). It is known that the first dumper of the i-th quarry has xi stones in it, the second dumper has xi + 1 stones in it, the third has xi + 2, and the mi-th dumper (the last for the i-th quarry) has xi + mi - 1 stones in it.

Two oligarchs play a well-known game Nim. Players take turns removing stones from dumpers. On each turn, a player can select any dumper and remove any non-zero amount of stones from it. The player who cannot take a stone loses.

Your task is to find out which oligarch will win, provided that both of them play optimally. The oligarchs asked you not to reveal their names. So, let's call the one who takes the first stone «tolik» and the other one «bolik».

Input

The first line of the input contains one integer number n (1 ≤ n ≤ 105) — the amount of quarries. Then there follow n lines, each of them contains two space-separated integers xi and mi (1 ≤ xi, mi ≤ 1016) — the amount of stones in the first dumper of the i-th quarry and the number of dumpers at the i-th quarry.

Output

Output «tolik» if the oligarch who takes a stone first wins, and «bolik» otherwise.

Examples

Input

2
2 1
3 2

Output

tolik

Input

4
1 1
1 1
1 1
1 1

Output

bolik

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long xs(long long to) {
  to++;
  long long num = 0;
  for (long long i = 1; (1 > 54 ? -1 : 1) * i <= (1 > 54 ? -1 : 1) * 54;
       i += (1 > 54 ? -1 : 1))
    num += ((long long)1 << (i - 1)) *
           ((to / ((long long)1 << i) * ((long long)1 << (i - 1)) +
             max((to % ((long long)1 << i)) - ((long long)1 << (i - 1)),
                 (long long)0)) %
            (long long)2);
  return num;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, tot = 0;
  cin >> n;
  while (n--) {
    long long x, m;
    cin >> x >> m;
    tot ^= (xs(x + m - 1) ^ xs(x - 1));
  }
  cout << (tot ? "tolik" : "bolik") << "\n";
  return 0;
}

```


### Prompt

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

There are two buttons, one of size A and one of size B.

When you press a button of size X, you get X coins and the size of that button decreases by 1.

You will press a button twice. Here, you can press the same button twice, or press both buttons once.

At most how many coins can you get?

Constraints

* All values in input are integers.
* 3 \leq A, B \leq 20

Input

Input is given from Standard Input in the following format:

A B

Output

Print the maximum number of coins you can get.

Examples

Input

5 3

Output

9

Input

3 4

Output

7

Input

6 6

Output

12

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	printf("%d",max(a+b,max(a,b)*2-1));
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

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

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

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

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

Input

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

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

Output

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

Examples

Input

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

Output

2
4
7

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a, b, goal[100000], stanj[100000], bio[100000];
vector<int> g[100000], solution;
int kor;
void dfs(int x, int promp, int promn, int dub) {
  int f = 0;
  if (bio[x]) return;
  bio[x] = 1;
  if (promp % 2 == 1 && dub % 2 == 0) {
    if (stanj[x] == 1) {
      stanj[x] = 0;
    } else {
      if (stanj[x] == 0) {
        stanj[x] = 1;
      }
    }
    f = 1;
  }
  if (promn % 2 == 1 && dub % 2 == 1) {
    if (stanj[x] == 1) {
      stanj[x] = 0;
    } else {
      if (stanj[x] == 0) {
        stanj[x] = 1;
      }
    }
    f = 1;
  }
  if (stanj[x] != goal[x]) {
    if (stanj[x] == 1) {
      stanj[x] = 0;
    } else {
      if (stanj[x] == 0) {
        stanj[x] = 1;
      }
    }
    if (dub % 2 == 0) {
      promp++;
    } else {
      promn++;
    }
    solution.push_back(x);
    kor++;
    f = 1;
  }
  dub++;
  for (int i = 0; i < g[x].size(); i++) dfs(g[x][i], promp, promn, dub);
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    a--;
    b--;
    g[b].push_back(a);
    g[a].push_back(b);
  }
  for (int i = 0; i < n; i++) cin >> stanj[i];
  for (int i = 0; i < n; i++) cin >> goal[i];
  dfs(0, 0, 0, 0);
  cout << kor << endl;
  for (int i = 0; i < solution.size(); i++) {
    cout << solution[i] + 1 << endl;
  }
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher suspected that Amr is sleeping and asked him a question to make sure he wasn't.

First he gave Amr two positive integers n and k. Then he asked Amr, how many integer numbers x > 0 exist such that:

  * Decimal representation of x (without leading zeroes) consists of exactly n digits;
  * There exists some integer y > 0 such that:
    * <image>;
    * decimal representation of y is a suffix of decimal representation of x.

As the answer to this question may be pretty huge the teacher asked Amr to output only its remainder modulo a number m.

Can you help Amr escape this embarrassing situation?

Input

Input consists of three integers n, k, m (1 ≤ n ≤ 1000, 1 ≤ k ≤ 100, 1 ≤ m ≤ 109).

Output

Print the required number modulo m.

Examples

Input

1 2 1000

Output

4

Input

2 2 1000

Output

45

Input

5 3 1103

Output

590

Note

A suffix of a string S is a non-empty string that can be obtained by removing some number (possibly, zero) of first characters from S.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, ans;
long long dp[1100][110];
int main() {
  cin >> n >> k >> m;
  for (int i = 1; i < 10; i++) dp[1][i % k]++;
  long long f = 1;
  for (int i = 1; i < n; i++) {
    f = f * 10 % k;
    for (int j = 0; j < k; j++) {
      int add = j == 0 ? 1 : dp[i][j];
      for (int p = 1; p < 10; p++) {
        dp[i + 1][(j + p * f) % k] += add;
        dp[i + 1][(j + p * f) % k] %= m;
      }
    }
    for (int j = 1; j < k; j++) {
      dp[i + 1][j] += dp[i][j];
      dp[i + 1][j] %= m;
    }
  }
  ans = dp[n][0] % m;
  f = 9;
  for (int i = n - 1; i > 0; i--) {
    ans += dp[i][0] * f % m;
    ans %= m;
    f = f * 10 % m;
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once.

The appointed Judge was the most experienced member — Pavel. But since he was the wisest of all, he soon got bored of the game and fell asleep. Waking up, he discovered that the tournament is over and the teams want to know the results of all the matches.

Pavel didn't want anyone to discover about him sleeping and not keeping an eye on the results, so he decided to recover the results of all games. To do this, he asked all the teams and learned that the real winner was friendship, that is, each team beat the other teams exactly k times. Help Pavel come up with chronology of the tournir that meets all the conditions, or otherwise report that there is no such table.

Input

The first line contains two integers — n and k (1 ≤ n, k ≤ 1000).

Output

In the first line print an integer m — number of the played games. The following m lines should contain the information about all the matches, one match per line. The i-th line should contain two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi). The numbers ai and bi mean, that in the i-th match the team with number ai won against the team with number bi. You can assume, that the teams are numbered from 1 to n.

If a tournir that meets the conditions of the problem does not exist, then print -1.

Examples

Input

3 1

Output

3
1 2
2 3
3 1

### Response

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

```


### Prompt

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

Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first shop and a d2 meter long road between his house and the second shop. Also, there is a road of length d3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house.

<image>

Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.

Input

The first line of the input contains three integers d1, d2, d3 (1 ≤ d1, d2, d3 ≤ 108) — the lengths of the paths.

  * d1 is the length of the path connecting Patrick's house and the first shop;
  * d2 is the length of the path connecting Patrick's house and the second shop;
  * d3 is the length of the path connecting both shops.

Output

Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.

Examples

Input

10 20 30

Output

60

Input

1 1 5

Output

4

Note

The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <image> first shop <image> second shop <image> house.

In the second sample one of the optimal routes is: house <image> first shop <image> house <image> second shop <image> house.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  long long int d1, d2, d3, min = 100000000000000, ans;
  scanf("%lld %lld %lld", &d1, &d2, &d3);
  ans = 2 * d1 + 2 * d2;
  if (ans < min) min = ans;
  ans = d1 + d2 + d3;
  if (ans < min) min = ans;
  ans = 2 * d1 + 2 * d3;
  if (ans < min) min = ans;
  ans = 2 * d2 + 2 * d3;
  if (ans < min) min = ans;
  printf("%lld\n", min);
  return 0;
}

```


### Prompt

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

Ujan needs some rest from cleaning, so he started playing with infinite sequences. He has two integers n and k. He creates an infinite sequence s by repeating the following steps.

  1. Find k smallest distinct positive integers that are not in s. Let's call them u_{1}, u_{2}, …, u_{k} from the smallest to the largest.
  2. Append u_{1}, u_{2}, …, u_{k} and ∑_{i=1}^{k} u_{i} to s in this order.
  3. Go back to the first step.

Ujan will stop procrastinating when he writes the number n in the sequence s. Help him find the index of n in s. In other words, find the integer x such that s_{x} = n. It's possible to prove that all positive integers are included in s only once.

Input

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

Each of the following t lines contains two integers n and k (1 ≤ n ≤ 10^{18}, 2 ≤ k ≤ 10^{6}), the number to be found in the sequence s and the parameter used to create the sequence s.

Output

In each of the t lines, output the answer for the corresponding test case.

Example

Input

2
10 2
40 5

Output

11
12

Note

In the first sample, s = (1, 2, 3, 4, 5, 9, 6, 7, 13, 8, 10, 18, …). 10 is the 11-th number here, so the answer is 11.

In the second sample, s = (1, 2, 3, 4, 5, 15, 6, 7, 8, 9, 10, 40, …).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
template <class T>
inline void umin(T &x, T y) {
  x = x < y ? x : y;
}
template <class T>
inline void umax(T &x, T y) {
  x = x > y ? x : y;
}
inline unsigned int R() {
  static unsigned int seed = 416;
  return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;
}
long long n, k;
long long getblock(long long n) { return (n - 1) / (k * k + 1); }
long long getend(long long i, long long t) {
  return i * (k * k + 1) + t * k + k;
}
long long getans(long long x) {
  if (!x) return k * (k + 1) / 2;
  long long i = x / k, t = x % k;
  long long pos = getans(i);
  long long off = max(min(getend(i, t) - pos + 1, k), 0LL);
  return (i * k + t) * (k * k + 1) - t + k * (k + 1) / 2 + off;
}
long long getcnt(long long x) { return x + (x - 1) / k; }
int main() {
  int T;
  read(T);
  while (T--) {
    read(n);
    read(k);
    long long x = getblock(n);
    long long pos = getans(x);
    long long res;
    if (pos == n)
      res = (x / k * k + x % k + 1) * (k + 1);
    else
      res = x * k * (k + 1) + getcnt(n - x * (k * k + 1) - (pos < n));
    printf("%lld\n", res);
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbers from 1 to 3n, and all the teams possess numbers from 1 to n. The splitting of students into teams is performed in the following manner: while there are people who are not part of a team, a person with the best total score is chosen among them (the captain of a new team), this person chooses for himself two teammates from those who is left according to his list of priorities. The list of every person's priorities is represented as a permutation from the rest of 3n - 1 students who attend the centre, besides himself.

You are given the results of personal training sessions which are a permutation of numbers from 1 to 3n, where the i-th number is the number of student who has won the i-th place. No two students share a place. You are also given the arrangement of the already formed teams in the order in which they has been created. Your task is to determine the list of priorities for the student number k. If there are several priority lists, choose the lexicographically minimal one.

Input

The first line contains an integer n (1 ≤ n ≤ 105) which is the number of resulting teams. The second line contains 3n space-separated integers from 1 to 3n which are the results of personal training sessions. It is guaranteed that every student appears in the results exactly once.

Then follow n lines each containing three integers from 1 to 3n — each line describes the members of a given team. The members of one team can be listed in any order, but the teams themselves are listed in the order in which they were created. It is guaranteed that the arrangement is correct, that is that every student is a member of exactly one team and those teams could really be created from the given results using the method described above.

The last line contains number k (1 ≤ k ≤ 3n) which is the number of a student for who the list of priorities should be found.

Output

Print 3n - 1 numbers — the lexicographically smallest list of priorities for the student number k.

The lexicographical comparison is performed by the standard < operator in modern programming languages. The list a is lexicographically less that the list b if exists such an i (1 ≤ i ≤ 3n), that ai < bi, and for any j (1 ≤ j < i) aj = bj. Note, that the list 1 9 10 is lexicographically less than the list 1 10 9. That is, the comparison of lists is different from the comparison of lines.

Examples

Input

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

Output

2 3 5 6 9 1 7 8

Input

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

Output

1 2 3 4 5 6 7 9

Input

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

Output

5 6 1 2 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> vf, vc, vl;
unordered_map<int, int[3]> m;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
    pq;
int t[300005], d[300005], win[100005];
int main() {
  int n, k, a, b, c, p;
  cin >> n;
  for (int i = 0; i < 3 * n; i++)
    cin >> t[i], d[t[i]] = -1, pq.push(make_pair(i, t[i]));
  for (int i = 0; i < n; i++) {
    win[i] = pq.top().second;
    for (int j = 0; j < 3; j++) cin >> m[i][j], d[m[i][j]] = i;
    while (!pq.empty() && d[pq.top().second] != -1) pq.pop();
  }
  cin >> k;
  if (win[d[k]] != k) {
    for (int i = 1; i <= 3 * n; i++)
      if (i != k) cout << i << " ";
    return 0;
  }
  for (int i = 0; i < d[k]; i++)
    for (int j = 0; j < 3; j++) vf.push_back(m[i][j]);
  for (int j = 0; j < 3; j++)
    if (m[d[k]][j] != k) vc.push_back(m[d[k]][j]);
  for (int i = d[k] + 1; i < n; i++)
    for (int j = 0; j < 3; j++) vl.push_back(m[i][j]);
  sort(vf.begin(), vf.end());
  sort(vc.begin(), vc.end());
  sort(vl.begin(), vl.end());
  p = 0;
  for (int i = 0; i < vc.size(); i++) {
    while (p < vf.size() && vf[p] < vc[i]) cout << vf[p++] << " ";
    cout << vc[i] << " ";
  }
  for (int i = 0; i < vl.size(); i++) {
    while (p < vf.size() && vf[p] < vl[i]) cout << vf[p++] << " ";
    cout << vl[i] << " ";
  }
  while (p != vf.size()) cout << vf[p++] << " ";
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Arpa is researching the Mexican wave.

There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0.

  * At time 1, the first spectator stands.
  * At time 2, the second spectator stands.
  * ...
  * At time k, the k-th spectator stands.
  * At time k + 1, the (k + 1)-th spectator stands and the first spectator sits.
  * At time k + 2, the (k + 2)-th spectator stands and the second spectator sits.
  * ...
  * At time n, the n-th spectator stands and the (n - k)-th spectator sits.
  * At time n + 1, the (n + 1 - k)-th spectator sits.
  * ...
  * At time n + k, the n-th spectator sits.

Arpa wants to know how many spectators are standing at time t.

Input

The first line contains three integers n, k, t (1 ≤ n ≤ 109, 1 ≤ k ≤ n, 1 ≤ t < n + k).

Output

Print single integer: how many spectators are standing at time t.

Examples

Input

10 5 3

Output

3

Input

10 5 7

Output

5

Input

10 5 12

Output

3

Note

In the following a sitting spectator is represented as -, a standing spectator is represented as ^.

  * At t = 0  ---------- <image> number of standing spectators = 0.
  * At t = 1  ^--------- <image> number of standing spectators = 1.
  * At t = 2  ^^-------- <image> number of standing spectators = 2.
  * At t = 3  ^^^------- <image> number of standing spectators = 3.
  * At t = 4  ^^^^------ <image> number of standing spectators = 4.
  * At t = 5  ^^^^^----- <image> number of standing spectators = 5.
  * At t = 6  -^^^^^---- <image> number of standing spectators = 5.
  * At t = 7  --^^^^^--- <image> number of standing spectators = 5.
  * At t = 8  ---^^^^^-- <image> number of standing spectators = 5.
  * At t = 9  ----^^^^^- <image> number of standing spectators = 5.
  * At t = 10 -----^^^^^ <image> number of standing spectators = 5.
  * At t = 11 ------^^^^ <image> number of standing spectators = 4.
  * At t = 12 -------^^^ <image> number of standing spectators = 3.
  * At t = 13 --------^^ <image> number of standing spectators = 2.
  * At t = 14 ---------^ <image> number of standing spectators = 1.
  * At t = 15 ---------- <image> number of standing spectators = 0.

### Response

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

```


### Prompt

Create a solution in cpp for the following problem:

International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition.

For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995.

You are given a list of abbreviations. For each of them determine the year it stands for.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process.

Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits.

Output

For each abbreviation given in the input, find the year of the corresponding Olympiad.

Examples

Input

5
IAO'15
IAO'2015
IAO'1
IAO'9
IAO'0

Output

2015
12015
1991
1989
1990

Input

4
IAO'9
IAO'99
IAO'999
IAO'9999

Output

1989
1999
2999
9999

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T BigMod(T b, T p, T m) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    T s = BigMod(b, p / 2, m);
    return ((s % m) * (s % m)) % m;
  }
  return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;
}
template <typename T>
T ModInv(T b, T m) {
  return BigMod(b, m - 2, m);
}
template <typename T>
T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / __gcd(a, b));
}
double DEG(double x) { return (180.0 * x) / (2.0 * acos(0.0)); }
double RAD(double x) { return (x * (double)2.0 * acos(0.0)) / (180.0); }
int main() {
  char s[20];
  int tc, l;
  long long int res, pw;
  scanf("%d", &tc);
  while (tc--) {
    scanf("\nIAO'%s", s);
    l = strlen(s);
    res = 1988;
    pw = 1;
    for (int i = l - 1; i >= 0; i--) {
      int p = atoi(s + i);
      res += pw;
      while (res % (pw * 10) != p) {
        res += pw;
      }
      pw *= 10ll;
    }
    printf("%lld\n", res);
  }
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):

  * point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
  * point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
  * point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
  * point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y

We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.

Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.

Input

The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.

Output

Print the only number — the number of supercentral points of the given set.

Examples

Input

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

Output

2

Input

5
0 0
0 1
1 0
0 -1
-1 0

Output

1

Note

In the first sample the supercentral points are only points (1, 1) and (1, 2).

In the second sample there is one supercental point — point (0, 0).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  long long int a[n], b[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  long long int co = 0, r = 0, l = 0, u = 0, d = 0;
  for (long long int i = 0; i < n; i++) {
    r = 0, u = 0, l = 0, d = 0;
    for (long long int j = 0; j < n; j++) {
      if (a[i] == a[j] && b[i] > b[j]) {
        r++;
      } else if (a[i] == a[j] && b[i] < b[j]) {
        l++;
      }
      if (a[i] > a[j] && b[i] == b[j]) {
        d++;
      } else if (a[i] < a[j] && b[i] == b[j]) {
        u++;
      }
      if (l >= 1 && r >= 1 && d >= 1 && u >= 1) {
        co += 1;
        break;
      }
    }
  }
  cout << co << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

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

Given are two sequences a=\\{a_0,\ldots,a_{N-1}\\} and b=\\{b_0,\ldots,b_{N-1}\\} of N non-negative integers each.

Snuke will choose an integer k such that 0 \leq k < N and an integer x not less than 0, to make a new sequence of length N, a'=\\{a_0',\ldots,a_{N-1}'\\}, as follows:

* a_i'= a_{i+k \mod N}\ XOR \ x

Find all pairs (k,x) such that a' will be equal to b.

What is \mbox{ XOR }?

The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:

* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.

For example, 3 \mbox{ XOR } 5 = 6. (In base two: 011 \mbox{ XOR } 101 = 110.)

Constraints

* 1 \leq N \leq 2 \times 10^5
* 0 \leq a_i,b_i < 2^{30}
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
a_0 a_1 ... a_{N-1}
b_0 b_1 ... b_{N-1}

Output

Print all pairs (k, x) such that a' and b will be equal, using one line for each pair, in ascending order of k (ascending order of x for pairs with the same k).

If there are no such pairs, the output should be empty.

Examples

Input

3
0 2 1
1 2 3

Output

1 3

Input

5
0 0 0 0 0
2 2 2 2 2

Output

0 2
1 2
2 2
3 2
4 2

Input

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

Output

2 2
5 5

Input

2
1 2
0 0

Output

### Response

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

vector<int> Z_Algorithm(vector<int> &s) {
    vector<int> ret(s.size());
    for (int i = 1, j = 0; i < s.size(); i++) {
        if (i + ret[i-j] < j + ret[j]) {
            ret[i] = ret[i-j];
        } else {
            int k = max(0, j + ret[j] - i);
            while (i+k < s.size() && s[k] == s[i+k]) k++;
            ret[i] = k; j = i;
        }
    }
    ret[0] = s.size();
    return ret;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n), b(n), c(3*n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) {
        c[i] = b[i] ^ b[(i+1) % n];
        c[i+n] = c[i+n*2] = a[i] ^ a[(i+1) % n];
    }
    auto ret = Z_Algorithm(c);
    for (int k = 0; k < n; k++) {
        if (ret[n+k] >= n) {
            cout << k << " " << (b[0] ^ a[k]) << "\n";
        }
    }
    return 0;
}
```


### Prompt

Create a solution in CPP for the following problem:

Caracal is fighting with a monster.

The health of the monster is H.

Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:

* If the monster's health is 1, it drops to 0.
* If the monster's health, X, is greater than 1, that monster disappears. Then, two new monsters appear, each with the health of \lfloor X/2 \rfloor.

(\lfloor r \rfloor denotes the greatest integer not exceeding r.)

Caracal wins when the healths of all existing monsters become 0 or below.

Find the minimum number of attacks Caracal needs to make before winning.

Constraints

* 1 \leq H \leq 10^{12}
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

H

Output

Find the minimum number of attacks Caracal needs to make before winning.

Examples

Input

2

Output

3

Input

4

Output

7

Input

1000000000000

Output

1099511627775

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int  main()
  {
  long long n;
  cin>>n;
  long long ans=1;
  while(n!=1)
    {
    n/=2;
    ans=ans*2+1;
    }
  cout<<ans;
  }

```


### Prompt

Please formulate a cpp solution to the following problem:

At one point, there was a president who traveled around Japan to do business. One day he got a mysterious ticket. If you use the ticket, the train fare will be free regardless of the distance to the destination. However, when moving from the current station to the adjacent station is counted as one step, if the number of steps to move is not exactly equal to the number written on the ticket, an additional fee will be charged. It is forbidden to move around a section immediately, but it is permissible to go through a station or section that you have already visited multiple times. For example, you cannot move to station 1, station 2, or station 1, but there is no problem with moving to station 1, station 2, station 3, station 1, or station 2. Also, if you finally arrive at your destination, you may go through the starting point and destination as many times as you like.

The president immediately decided to use this ticket to go to his next destination. However, since the route map is complicated, the route cannot be easily determined. Your job is to write a program on behalf of the president to determine if you can reach your destination for free.

Stations are numbered from 1 to N, with the departure station being 1 and the destination station being N. The route map is given by the row of sections connecting the two stations. The section can pass in either direction. It is guaranteed that there is no section connecting the same stations and that there is at most one section connecting a pair of stations.

Input

The input consists of multiple datasets.

Each dataset is given in the following format.

N M Z
s1 d1
s2 d2
...
sM dM

N is the total number of stations, M is the total number of sections, and Z is the number of steps written on the ticket. si and di (1 ≤ i ≤ M) are integers representing station numbers, indicating that there is an interval between station si and station di, respectively.

N, M, Z are positive integers and satisfy the following conditions: 2 ≤ N ≤ 50, 1 ≤ M ≤ 50, 0 <Z <231.

After the last dataset, there is a line that says "` 0 0 0 `".

The number of datasets does not exceed 30.

Output

For each dataset, output a one-line string containing only "` yes` "if the destination can be reached with just the number of steps written on the ticket, or" `no`" if not. ..

Example

Input

2 1 1
1 2
2 1 2
1 2
3 1 2
1 2
8 8 5778
1 2
2 3
2 4
3 5
5 6
6 7
7 8
4 8
8 8 5777
1 2
2 3
2 4
3 5
5 6
6 7
7 8
4 8
0 0 0

Output

yes
no
no
yes
no

### Response

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

using namespace std;

// typedef long long ll;
typedef int ll;
#define MAX INT_MAX
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

typedef vector<ll> vec;
typedef vector<vec> mat;
#define CREATE_MATRIX(n,m) vector<vec>(n,vec(m,0ll))

mat mul(mat &a,mat &b,ll md=MAX,ll clamp=MAX){
  if(a.size()==0 || b.size()==0) assert(false&&"ERROR: ????????????????????????????????????");
  // a(n*l) * b(l*m)
  int n = a.size();
  int l = a[0].size();
  int m = b[0].size();
  if(b.size()!=l) assert(false&&"ERROR: ????????????????????????????????????");
  mat ret = CREATE_MATRIX(n,m);
  REP(i,n)REP(j,m){
    REP(k,l){
      ret[i][j] += a[i][k] * b[k][j] % md;
      if(ret[i][j]>=clamp-1)break;
      ret[i][j] %= md;
    }
    ret[i][j] %= clamp;
  }
  return ret;
}

void out_mat(mat a){
  REP(i,a.size()){
    REP(j,a[i].size())cout<<a[i][j]<<" ";
    cout<<endl;
  }
}
void out_vec(mat v){
  assert(v[0].size()==1);
  REP(i,v.size())cout<<v[i][0]<<" ";
  cout<<endl;
}

int main(){
  // verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2107
  while(true){
    int n,m;
    ll z;
    cin>>n>>m>>z;
    if(!n && !m && !z)break;
    vector<pii> es(m);
    REP(i,m){
      int x,y;
      cin>>x>>y;
      es[i].first = x-1;
      es[i].second = y-1;
    }
    mat M = CREATE_MATRIX(2*m,2*m);
    REP(i,m)REP(j,m){
      if(i==j)continue;
      if(es[i].second == es[j].first) M[j][i] = M[m+i][m+j] = 1;
      if(es[i].first == es[j].second) M[i][j] = M[m+j][m+i] = 1;
      if(es[i].first == es[j].first) M[j][m+i] = M[i][m+j] = 1;
      if(es[i].second == es[j].second) M[m+j][i] = M[m+i][j] = 1;
    }
    mat X = CREATE_MATRIX(2*m,1);
    REP(i,m)if(es[i].first == 0)X[i][0]=1;
    REP(i,m)if(es[i].second == 0)X[m+i][0]=1;
    --z;
    mat ans = CREATE_MATRIX(2*m,2*m);
    REP(i,2*m)ans[i][i] = 1;
    while(z){
      if(z&1) ans = mul(ans,M,MAX,2);
      M = mul(M,M,MAX,2);
      z>>=1;
    }
    ans = mul(ans,X,MAX,2);
    bool flag = false;
    REP(i,m){
      if(es[i].second == n-1 && ans[i][0]>=1){
        flag = true;
        break;
      }else if(es[i].first == n-1 && ans[i+m][0]>=1){
        flag = true;
        break;
      }
    }
    if(flag)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}
```


### Prompt

Develop a solution in cpp to the problem described below:

Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.

Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.

Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same?

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of participants Anton has outscored in this contest .

The next n lines describe participants results: the i-th of them consists of a participant handle namei and two integers beforei and afteri ( - 4000 ≤ beforei, afteri ≤ 4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters.

It is guaranteed that all handles are distinct.

Output

Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.

Examples

Input

3
Burunduk1 2526 2537
BudAlNik 2084 2214
subscriber 2833 2749

Output

YES

Input

3
Applejack 2400 2400
Fluttershy 2390 2431
Pinkie_Pie -2500 -2450

Output

NO

Note

In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.

In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
unsigned long long int MOD = 1000000007;
unsigned long long int B = 13331;
bool cmp(const int &a, const int &b) { return a < b; }
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
unsigned long long int int_mod(unsigned long long int a) {
  return (a + MOD) % MOD;
}
unsigned long long int power_expo(unsigned long long int a,
                                  unsigned long long int b) {
  unsigned long long int t;
  if (b == 0) return 1;
  if (b == 1) return int_mod(a);
  t = power_expo(a, b / 2);
  return b % 2 == 0 ? int_mod(t * t) : int_mod(int_mod(t * t) * a);
}
int main() {
  int i, j, k;
  int n;
  cin >> n;
  string s[105];
  int flag = 0;
  for (i = 0; i < n; i++) {
    cin >> s[i];
    int a, b;
    cin >> a >> b;
    if (a >= 2400 && b >= 2400 && b > a) flag = 1;
  }
  if (flag)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

You have a set of n weights. You know that their masses are a_1, a_2, ..., a_n grams, but you don't know which of them has which mass. You can't distinguish the weights.

However, your friend does know the mass of each weight. You can ask your friend to give you exactly k weights with the total mass m (both parameters k and m are chosen by you), and your friend will point to any valid subset of weights, if it is possible.

You are allowed to make this query only once. Find the maximum possible number of weights you can reveal after this query.

Input

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

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 100) — the masses of the weights.

Output

Print the maximum number of weights you can learn the masses for after making a single query.

Examples

Input

4
1 4 2 2

Output

2

Input

6
1 2 4 4 4 9

Output

2

Note

In the first example we can ask for a subset of two weights with total mass being equal to 4, and the only option is to get \{2, 2\}.

Another way to obtain the same result is to ask for a subset of two weights with the total mass of 5 and get \{1, 4\}. It is easy to see that the two remaining weights have mass of 2 grams each.

In the second example we can ask for a subset of two weights with total mass being 8, and the only answer is \{4, 4\}. We can prove it is not possible to learn masses for three weights in one query, but we won't put the proof here.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int num[110], a[110];
long long ch[12000][3];
int main() {
  int n, ans = 0, i, j, k, l;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  k = 0;
  for (i = 1; i <= n; i++) {
    if (!num[a[i]]) k++;
    num[a[i]]++;
  }
  if (k == 2) {
    printf("%d", n);
    return 0;
  }
  ch[0][0] = 1;
  for (i = 1; i <= 100; i++) {
    for (j = 1; j <= num[i]; j++) {
      for (k = 10000; k >= 1; k--) {
        ch[k][0] = 0;
        ch[k][1] = 0;
      }
      for (l = 1; l <= n; l++) {
        for (k = 10000; k >= 0; k--) {
          if (a[l] == i) continue;
          if ((ch[k][0] & ((long long)1 << 50)) != 0) {
            ch[k + a[l]][0] |= ((ch[k][0] - ((long long)1 << 50)) << 1);
            ch[k + a[l]][1] |= ((ch[k][1] << 1) + 1);
          } else {
            ch[k + a[l]][0] |= (ch[k][0] << 1);
            ch[k + a[l]][1] |= (ch[k][1] << 1);
          }
        }
      }
      for (l = 1; l <= j - 1; l++) {
        for (k = 10000; k >= 0; k--) {
          if ((ch[k][0] & ((long long)1 << 50)) != 0) {
            ch[k + i][0] |= ((ch[k][0] - ((long long)1 << 50)) << 1);
            ch[k + i][1] |= ((ch[k][1] << 1) + 1);
          } else {
            ch[k + i][0] |= (ch[k][0] << 1);
            ch[k + i][1] |= (ch[k][1] << 1);
          }
        }
      }
      if (j <= 50 && (ch[i * j][0] & ((long long)1 << j)) == 0)
        ans = max(ans, j);
      else if (j > 50 && (ch[i * j][1] & ((long long)1 << (j - 51))) == 0)
        ans = max(ans, j);
    }
  }
  printf("%d", ans);
  return 0;
}

```


### Prompt

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

Enter a positive integer n of 4,000 or less, with a pair of integers a, b, c, d in the range 0-1000.

a + b + c + d = n

Create a program that outputs the number of combinations that satisfy the conditions.

Input

Given multiple datasets. Each dataset is given n on one row. Please process until the end of the input.

The number of datasets does not exceed 50.

Output

For each data set, output the number of combinations of a, b, c, and d on one line.

Example

Input

2
3
35

Output

10
20
8436

### Response

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

int main() {
    unordered_map<int, int> dict1;
    for(int a = 0; a <= 1000; a++) {
        for(int b = 0; b <= 1000; b++) {
            dict1[a + b]++;
        }
    }
    unordered_map<int, int> dict2;
    for(int c = 0; c <= 1000; c++) {
        for(int d = 0; d <= 1000; d++) {
            dict2[c + d]++;
        }
    }
    for(int N; cin >> N; ) {
        int ans = 0;
        for(auto it : dict1) {
            if(dict2.count(N - it.first)) {
                ans += dict1[N - it.first] * it.second;
            }
        }
        cout << ans << endl;
    }
}
```


### Prompt

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

This is the easy version of the problem. The difference between the versions is in the number of possible operations that can be made. You can make hacks if and only if you solved both versions of the problem.

You are given a binary table of size n × m. This table consists of symbols 0 and 1.

You can make such operation: select 3 different cells that belong to one 2 × 2 square and change the symbols in these cells (change 0 to 1 and 1 to 0).

Your task is to make all symbols in the table equal to 0. You are allowed to make at most 3nm operations. You don't need to minimize the number of operations.

It can be proved that it is always possible.

Input

The first line contains a single integer t (1 ≤ t ≤ 5000) — the number of test cases. The next lines contain descriptions of test cases.

The first line of the description of each test case contains two integers n, m (2 ≤ n, m ≤ 100).

Each of the next n lines contains a binary string of length m, describing the symbols of the next row of the table.

It is guaranteed that the sum of nm for all test cases does not exceed 20000.

Output

For each test case print the integer k (0 ≤ k ≤ 3nm) — the number of operations.

In the each of the next k lines print 6 integers x_1, y_1, x_2, y_2, x_3, y_3 (1 ≤ x_1, x_2, x_3 ≤ n, 1 ≤ y_1, y_2, y_3 ≤ m) describing the next operation. This operation will be made with three cells (x_1, y_1), (x_2, y_2), (x_3, y_3). These three cells should be different. These three cells should belong into some 2 × 2 square.

Example

Input

5
2 2
10
11
3 3
011
101
110
4 4
1111
0110
0110
1111
5 5
01011
11001
00010
11011
10000
2 3
011
101

Output

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

Note

In the first test case, it is possible to make only one operation with cells (1, 1), (2, 1), (2, 2). After that, all symbols will be equal to 0.

In the second test case:

  * operation with cells (2, 1), (3, 1), (3, 2). After it the table will be:

    011
    001
    000

  * operation with cells (1, 2), (1, 3), (2, 3). After it the table will be:

    000
    000
    000

In the fifth test case:

  * operation with cells (1, 3), (2, 2), (2, 3). After it the table will be:

    010
    110

  * operation with cells (1, 2), (2, 1), (2, 2). After it the table will be:

    000
    000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 10;
string s[N];
int n, m;
int a[N][N];
struct node {
  int a, b, c, d, e, f;
};
vector<node> v;
void work() {
  cin >> n >> m;
  for (int i = 0; i <= n - 1; i++) cin >> s[i];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) a[i][j] = s[i - 1][j - 1] - '0';
  v.clear();
  if (n & 1) {
    for (int i = 1; i <= m; i++)
      if (a[n][i]) {
        if (i == 1) {
          a[n - 1][i] ^= 1;
          a[n - 1][i + 1] ^= 1;
          v.push_back({n, i, n - 1, i, n - 1, i + 1});
        } else {
          a[n - 1][i] ^= 1;
          a[n - 1][i - 1] ^= 1;
          v.push_back({n, i, n - 1, i, n - 1, i - 1});
        }
      }
    --n;
  }
  if (m & 1) {
    for (int i = 1; i <= n; i++)
      if (a[i][m]) {
        if (i == 1) {
          a[i][m - 1] ^= 1;
          a[i + 1][m - 1] ^= 1;
          v.push_back({i, m, i, m - 1, i + 1, m - 1});
        } else {
          a[i][m - 1] ^= 1;
          a[i - 1][m - 1] ^= 1;
          v.push_back({i, m, i, m - 1, i - 1, m - 1});
        }
      }
    --m;
  }
  for (int i = 1; i <= n; i += 2)
    for (int j = 1; j <= m; j += 2) {
      int A = 0, b = 0, c = 0, d = 0;
      if (a[i][j]) b ^= 1, c ^= 1, d ^= 1;
      if (a[i][j + 1]) A ^= 1, c ^= 1, d ^= 1;
      if (a[i + 1][j]) A ^= 1, b ^= 1, d ^= 1;
      if (a[i + 1][j + 1]) A ^= 1, b ^= 1, c ^= 1;
      if (A) v.push_back({i, j + 1, i + 1, j, i + 1, j + 1});
      if (b) v.push_back({i, j, i + 1, j, i + 1, j + 1});
      if (c) v.push_back({i, j, i, j + 1, i + 1, j + 1});
      if (d) v.push_back({i, j, i, j + 1, i + 1, j});
    }
  cout << v.size() << endl;
  for (auto v1 : v) {
    cout << v1.a << " " << v1.b << " ";
    cout << v1.c << " " << v1.d << " ";
    cout << v1.e << " " << v1.f << '\n';
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) work();
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.

In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies.

All elements are enumerated with integers. The ChemForces company has discovered n distinct chemical elements with indices a_1, a_2, …, a_n, and will get an income of x_i Berland rubles if the i-th element from this list is in the set of this company.

The TopChemist company discovered m distinct chemical elements with indices b_1, b_2, …, b_m, and it will get an income of y_j Berland rubles for including the j-th element from this list to its set.

In other words, the first company can present any subset of elements from \\{a_1, a_2, …, a_n\} (possibly empty subset), the second company can present any subset of elements from \\{b_1, b_2, …, b_m\} (possibly empty subset). There shouldn't be equal elements in the subsets.

Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible.

Input

The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of elements discovered by ChemForces.

The i-th of the next n lines contains two integers a_i and x_i (1 ≤ a_i ≤ 10^9, 1 ≤ x_i ≤ 10^9) — the index of the i-th element and the income of its usage on the exhibition. It is guaranteed that all a_i are distinct.

The next line contains a single integer m (1 ≤ m ≤ 10^5) — the number of chemicals invented by TopChemist.

The j-th of the next m lines contains two integers b_j and y_j, (1 ≤ b_j ≤ 10^9, 1 ≤ y_j ≤ 10^9) — the index of the j-th element and the income of its usage on the exhibition. It is guaranteed that all b_j are distinct.

Output

Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets.

Examples

Input

3
1 2
7 2
3 10
4
1 4
2 4
3 4
4 4

Output

24

Input

1
1000000000 239
3
14 15
92 65
35 89

Output

408

Note

In the first example ChemForces can choose the set (3, 7), while TopChemist can choose (1, 2, 4). This way the total income is (10 + 2) + (4 + 4 + 4) = 24.

In the second example ChemForces can choose the only element 10^9, while TopChemist can choose (14, 92, 35). This way the total income is (239) + (15 + 65 + 89) = 408.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct node {
  long long pos, x;
} p[222222];
bool cmp(node a, node b) {
  if (a.pos != b.pos) {
    return a.pos < b.pos;
  }
  return a.x > b.x;
}
int main() {
  int n, m;
  int num = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", &p[num].pos, &p[num].x);
    num++;
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%lld %lld", &p[num].pos, &p[num].x);
    num++;
  }
  sort(p, p + num, cmp);
  long long sum = 0;
  int i = 0;
  while (i < num) {
    long long now = p[i].pos;
    sum += p[i].x;
    while (p[i].pos == now && i < num) {
      i++;
    }
    if (i >= num) {
      break;
    }
  }
  printf("%lld\n", sum);
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time the date changes, this string changes as follows:

* Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555`, `6` becomes `666666`, `7` becomes `7777777`, `8` becomes `88888888` and `9` becomes `999999999`. `1` remains as `1`.

For example, if S is `1324`, it becomes `1333224444` the next day, and it becomes `133333333322224444444444444444` the day after next. You are interested in what the string looks like after 5 \times 10^{15} days. What is the K-th character from the left in the string after 5 \times 10^{15} days?

Constraints

* S is a string of length between 1 and 100 (inclusive).
* K is an integer between 1 and 10^{18} (inclusive).
* The length of the string after 5 \times 10^{15} days is at least K.

Input

Input is given from Standard Input in the following format:

S
K

Output

Print the K-th character from the left in Mr. Infinity's string after 5 \times 10^{15} days.

Examples

Input

1214
4

Output

2

Input

3
157

Output

3

Input

299792458
9460730472580800

Output

2

### Response

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

int main() {
  string S;
  long N,a=0;
  cin>>S>>N;
  for(long long i=0;i<N;i++){
    if(S.at(i)!='1'){
      cout<<S.at(i);
      a=1;
      break;
    }
  }
  if(a==0){
    cout<<'1';
  }

}

```


### Prompt

Create a solution in Cpp for the following problem:

Piegirl has found a monster and a book about monsters and pies. When she is reading the book, she found out that there are n types of monsters, each with an ID between 1 and n. If you feed a pie to a monster, the monster will split into some number of monsters (possibly zero), and at least one colorful diamond. Monsters may be able to split in multiple ways.

At the begining Piegirl has exactly one monster. She begins by feeding the monster a pie. She continues feeding pies to monsters until no more monsters are left. Then she collects all the diamonds that were created.

You will be given a list of split rules describing the way in which the various monsters can split. Every monster can split in at least one way, and if a monster can split in multiple ways then each time when it splits Piegirl can choose the way it splits.

For each monster, determine the smallest and the largest number of diamonds Piegirl can possibly collect, if initially she has a single instance of that monster. Piegirl has an unlimited supply of pies.

Input

The first line contains two integers: m and n (1 ≤ m, n ≤ 105), the number of possible splits and the number of different monster types. Each of the following m lines contains a split rule. Each split rule starts with an integer (a monster ID) mi (1 ≤ mi ≤ n), and a positive integer li indicating the number of monsters and diamonds the current monster can split into. This is followed by li integers, with positive integers representing a monster ID and -1 representing a diamond.

Each monster will have at least one split rule. Each split rule will have at least one diamond. The sum of li across all split rules will be at most 105.

Output

For each monster, in order of their IDs, print a line with two integers: the smallest and the largest number of diamonds that can possibly be collected by starting with that monster. If Piegirl cannot possibly end up in a state without monsters, print -1 for both smallest and the largest value. If she can collect an arbitrarily large number of diamonds, print -2 as the largest number of diamonds.

If any number in output exceeds 314000000 (but is finite), print 314000000 instead of that number.

Examples

Input

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

Output

2 -2
3 4
2 2
-1 -1

Input

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

Output

-1 -1
2 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T0, typename T1>
bool chkmin(T0 &a, const T1 &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T0, typename T1>
bool chkmax(T0 &a, const T1 &b) {
  return a < b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f, Max_val = 314000000;
const int maxn = 100000, maxm = 100000;
int deg[maxn + 5];
pair<pair<int, int>, int> all[maxm + 5];
int tmp[maxm + 5] = {0};
vector<int> yyt[maxn + 5];
bool vis[maxn + 5] = {0};
int Min[maxn + 5];
int Max[maxn + 5];
vector<int> zzj[maxm + 5];
vector<int> owaski[maxn + 5];
int find(const int &first) {
  if (vis[first]) return -2;
  if (Max[first]) return Max[first];
  vis[first] = 1;
  Max[first] = -2;
  for (int i = (0), _end_ = ((int((owaski[first]).size()))); i != _end_; ++i) {
    const int &second = owaski[first][i];
    int tmp = ::tmp[second];
    for (int j = (0), _end_ = ((int((zzj[second]).size()))); j != _end_; ++j) {
      const int &k = zzj[second][j];
      int tmp0 = find(k);
      if (tmp0 == -1)
        goto yyt;
      else if (tmp0 == -2)
        tmp = -2;
      else if (tmp != -2)
        chkmin(tmp += tmp0, Max_val);
    }
    if (tmp == -2) {
      Max[first] = -2;
      vis[first] = 0;
      return Max[first];
    }
    Max[first] = max(Max[first], tmp);
  yyt:;
  }
  vis[first] = 0;
  return Max[first];
}
int m, n;
int main() {
  memset(Min, oo, sizeof Min);
  scanf("%d%d", &m, &n);
  for (int i = (0), _end_ = (m); i != _end_; ++i) {
    scanf("%d", &all[i].first.first), --all[i].first.first;
    static int nn;
    scanf("%d", &nn);
    all[i].first.second = tmp[i] = 0;
    owaski[all[i].first.first].push_back(i);
    for (int j = (0), _end_ = (nn); j != _end_; ++j) {
      static int first;
      scanf("%d", &first);
      if (first == -1)
        ++all[i].first.second, ++tmp[i];
      else
        --first, ++all[i].second, yyt[first].push_back(i),
            zzj[i].push_back(first);
    }
  }
  for (int i = (0), _end_ = (m); i != _end_; ++i)
    if (!all[i].second) chkmin(Min[all[i].first.first], all[i].first.second);
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  for (int i = (0), _end_ = (n); i != _end_; ++i)
    if (Min[i] < oo) q.push(make_pair(Min[i], i));
  while (!q.empty()) {
    int first = q.top().second;
    q.pop();
    if (vis[first]) continue;
    vis[first] = 1;
    for (int i = (0), _end_ = ((int((yyt[first]).size()))); i != _end_; ++i) {
      const int &second = yyt[first][i];
      all[second].first.second =
          min(all[second].first.second + Min[first], Max_val);
      if (!--all[second].second &&
          chkmin(Min[all[second].first.first], all[second].first.second))
        q.push(
            make_pair(Min[all[second].first.first], all[second].first.first));
    }
  }
  memset(vis, 0, sizeof vis);
  memset(Max, 0, sizeof Max);
  for (int i = (0), _end_ = (n); i != _end_; ++i)
    if (Min[i] == oo) Min[i] = Max[i] = -1;
  for (int i = (0), _end_ = (n); i != _end_; ++i) {
    find(i);
    printf("%d %d\n", Min[i], Max[i]);
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

When Valera was playing football on a stadium, it suddenly began to rain. Valera hid in the corridor under the grandstand not to get wet. However, the desire to play was so great that he decided to train his hitting the ball right in this corridor. Valera went back far enough, put the ball and hit it. The ball bounced off the walls, the ceiling and the floor corridor and finally hit the exit door. As the ball was wet, it left a spot on the door. Now Valera wants to know the coordinates for this spot.

Let's describe the event more formally. The ball will be considered a point in space. The door of the corridor will be considered a rectangle located on plane xOz, such that the lower left corner of the door is located at point (0, 0, 0), and the upper right corner is located at point (a, 0, b) . The corridor will be considered as a rectangular parallelepiped, infinite in the direction of increasing coordinates of y. In this corridor the floor will be considered as plane xOy, and the ceiling as plane, parallel to xOy and passing through point (a, 0, b). We will also assume that one of the walls is plane yOz, and the other wall is plane, parallel to yOz and passing through point (a, 0, b).

We'll say that the ball hit the door when its coordinate y was equal to 0. Thus the coordinates of the spot are point (x0, 0, z0), where 0 ≤ x0 ≤ a, 0 ≤ z0 ≤ b. To hit the ball, Valera steps away from the door at distance m and puts the ball in the center of the corridor at point <image>. After the hit the ball flies at speed (vx, vy, vz). This means that if the ball has coordinates (x, y, z), then after one second it will have coordinates (x + vx, y + vy, z + vz).

See image in notes for clarification.

When the ball collides with the ceiling, the floor or a wall of the corridor, it bounces off in accordance with the laws of reflection (the angle of incidence equals the angle of reflection). In the problem we consider the ideal physical model, so we can assume that there is no air resistance, friction force, or any loss of energy.

Input

The first line contains three space-separated integers a, b, m (1 ≤ a, b, m ≤ 100). The first two integers specify point (a, 0, b), through which the ceiling and one of the corridor walls pass. The third integer is the distance at which Valera went away from the door.

The second line has three space-separated integers vx, vy, vz (|vx|, |vy|, |vz| ≤ 100, vy < 0, vz ≥ 0) — the speed of the ball after the hit.

It is guaranteed that the ball hits the door.

Output

Print two real numbers x0, z0 — the x and z coordinates of point (x0, 0, z0), at which the ball hits the exit door. The answer will be considered correct, if its absolute or relative error does not exceed 10  - 6.

Examples

Input

7 2 11
3 -11 2

Output

6.5000000000 2.0000000000

Input

7 2 11
4 -3 3

Output

4.1666666667 1.0000000000

Note

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long double a, b, m;
  cin >> a >> b >> m;
  long double vx, vy, vz;
  cin >> vx >> vy >> vz;
  long double x = a / 2;
  long double z = 0;
  long double t = -m / vy;
  if (vx > 0) {
    x = x + (t * vx);
    while (x > 2 * a) x -= 2 * a;
  } else {
    long double temp = t * vx;
    temp = abs(temp);
    x = abs(temp - x);
    while (x > 2 * a) x -= 2 * a;
  }
  z = abs(t * vz);
  while (z > 2 * b) z -= 2 * b;
  if (x > a) x = abs(2 * a - x);
  if (z > b) z = abs(2 * b - z);
  cout << fixed << setprecision(12) << endl;
  cout << x << " " << z << endl;
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird functional equation and needs your help. For two fixed integers k and p, where p is an odd prime number, the functional equation states that

<image>

for some function <image>. (This equation should hold for any integer x in the range 0 to p - 1, inclusive.)

It turns out that f can actually be many different functions. Instead of finding a solution, Kevin wants you to count the number of distinct functions f that satisfy this equation. Since the answer may be very large, you should print your result modulo 109 + 7.

Input

The input consists of two space-separated integers p and k (3 ≤ p ≤ 1 000 000, 0 ≤ k ≤ p - 1) on a single line. It is guaranteed that p is an odd prime number.

Output

Print a single integer, the number of distinct functions f modulo 109 + 7.

Examples

Input

3 2

Output

3

Input

5 4

Output

25

Note

In the first sample, p = 3 and k = 2. The following functions work:

  1. f(0) = 0, f(1) = 1, f(2) = 2.
  2. f(0) = 0, f(1) = 2, f(2) = 1.
  3. f(0) = f(1) = f(2) = 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 1;
inline long long input(void) {
  char t;
  long long x = 0;
  int neg = 0;
  t = getchar();
  while ((t < 48 || t > 57) && t != '-') t = getchar();
  if (t == '-') {
    neg = 1;
    t = getchar();
  }
  while (t >= 48 && t <= 57) {
    x = (x << 3) + (x << 1) + t - 48;
    t = getchar();
  }
  if (neg) x = -x;
  return x;
}
inline void output(long long x) {
  char a[20];
  int i = 0, j;
  a[0] = '0';
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x == 0) putchar('0');
  while (x) {
    a[i++] = x % 10 + 48;
    x /= 10;
  }
  for (j = i - 1; j >= 0; j--) {
    putchar(a[j]);
  }
  putchar('\n');
}
long long vis[1000010];
int main() {
  long long n, p, cycles = 0, ans = 1;
  n = input();
  p = input();
  if (p == 0)
    cycles = n - 1;
  else if (p == 1)
    cycles = n;
  else {
    for (int i = 1; i < n; ++i) {
      if (!vis[i]) {
        while (!vis[i]) {
          vis[i] = 1;
          i = (p * i) % n;
        }
        cycles++;
      }
    }
  }
  for (int i = 0; i < cycles; ++i) ans = (n * ans) % 1000000007;
  output(ans);
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

You invited n guests to dinner! You plan to arrange one or more circles of chairs. Each chair is going to be either occupied by one guest, or be empty. You can make any number of circles.

Your guests happen to be a little bit shy, so the i-th guest wants to have a least l_i free chairs to the left of his chair, and at least r_i free chairs to the right. The "left" and "right" directions are chosen assuming all guests are going to be seated towards the center of the circle. Note that when a guest is the only one in his circle, the l_i chairs to his left and r_i chairs to his right may overlap.

What is smallest total number of chairs you have to use?

Input

First line contains one integer n — number of guests, (1 ⩽ n ⩽ 10^5).

Next n lines contain n pairs of space-separated integers l_i and r_i (0 ⩽ l_i, r_i ⩽ 10^9).

Output

Output a single integer — the smallest number of chairs you have to use.

Examples

Input

3
1 1
1 1
1 1

Output

6

Input

4
1 2
2 1
3 5
5 3

Output

15

Input

1
5 6

Output

7

Note

In the second sample the only optimal answer is to use two circles: a circle with 5 chairs accomodating guests 1 and 2, and another one with 10 chairs accomodationg guests 3 and 4.

In the third sample, you have only one circle with one person. The guest should have at least five free chairs to his left, and at least six free chairs to his right to the next person, which is in this case the guest herself. So, overall number of chairs should be at least 6+1=7.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long ct = n;
  long long l[n], r[n];
  for (int i = 0; i < n; i++) cin >> l[i] >> r[i];
  sort(l, l + n);
  sort(r, r + n);
  for (int i = 0; i < n; i++) ct += max(l[i], r[i]);
  cout << ct;
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

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

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

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

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

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

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

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

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

Input

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

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

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

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

Output

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

Examples

Input

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

Output

YES

Input

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

Output

NO

Note

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int nmax = 200009;
priority_queue<pair<int, int> > Q;
char s[2][nmax];
int F[2][nmax];
void go(int v, int w, int t) {
  if (v > 0 && (F[w][v] == -1 || t < F[w][v]) && s[w][v] != 'X') {
    if (t < v) {
      F[w][v] = t;
      Q.push(make_pair(-t, (v << 1) + w));
    }
  }
}
int n, k;
int main() {
  scanf("%d %d", &n, &k);
  scanf("%s", &s[0][1]);
  scanf("%s", &s[1][1]);
  memset(F, -1, sizeof(F));
  F[0][1] = 0;
  Q.push(make_pair(0, 1 << 1));
  bool ok = false;
  while (!Q.empty()) {
    int v = Q.top().second;
    int w = v & 1;
    v >>= 1;
    int d = -Q.top().first;
    Q.pop();
    if (v > n) {
      ok = true;
      break;
    }
    if (d == F[w][v]) {
      go(v + 1, w, d + 1);
      go(v - 1, w, d + 1);
      go(v + k, 1 - w, d + 1);
    }
  }
  if (ok)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Sereja is interested in intervals of numbers, so he has prepared a problem about intervals for you. An interval of numbers is a pair of integers [l, r] (1 ≤ l ≤ r ≤ m). Interval [l1, r1] belongs to interval [l2, r2] if the following condition is met: l2 ≤ l1 ≤ r1 ≤ r2.

Sereja wants to write out a sequence of n intervals [l1, r1], [l2, r2], ..., [ln, rn] on a piece of paper. At that, no interval in the sequence can belong to some other interval of the sequence. Also, Sereja loves number x very much and he wants some (at least one) interval in the sequence to have li = x. Sereja wonders, how many distinct ways to write such intervals are there?

Help Sereja and find the required number of ways modulo 1000000007 (109 + 7).

Two ways are considered distinct if there is such j (1 ≤ j ≤ n), that the j-th intervals in two corresponding sequences are not equal.

Input

The first line contains integers n, m, x (1 ≤ n·m ≤ 100000, 1 ≤ x ≤ m) — the number of segments in the sequence, the constraints on the numbers in segments and Sereja's favourite number.

Output

In a single line print the answer modulo 1000000007 (109 + 7).

Examples

Input

1 1 1

Output

1

Input

3 5 1

Output

240

Input

2 3 3

Output

6

Note

In third example next sequences will be correct: {[1, 1], [3, 3]}, {[1, 2], [3, 3]}, {[2, 2], [3, 3]}, {[3, 3], [1, 1]}, {[3, 3], [2, 2]}, {[3, 3], [1, 2]}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
vector<vector<vector<long long>>> dp;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, x;
  cin >> n >> m >> x;
  if (n > m) {
    cout << 0;
    return 0;
  }
  dp.resize(m + 1);
  for (long long i = 0; i <= m; i++) {
    dp[i].resize(n + 2);
    for (long long j = 0; j <= n + 1; j++) dp[i][j].resize(n + 2);
  }
  dp[0][0][0] = 1;
  for (long long i = 1; i <= m; i++) {
    if (i < x) dp[i][0][0] = 1;
    for (long long j = 1; j <= n; j++) {
      for (long long k = 0; k <= n; k++) {
        dp[i][j][k] = dp[i - 1][j - 1][k];
        if (k) dp[i][j][k] += dp[i - 1][j - 1][k - 1];
        dp[i][j][k] %= mod;
        if (i != x) {
          dp[i][j][k] += dp[i - 1][j][k];
          dp[i][j][k] += dp[i - 1][j][k + 1];
          dp[i][j][k] %= mod;
        }
      }
    }
  }
  long long ans = dp[m][n][0];
  for (long long i = 1; i <= n; i++) ans = ans * i % mod;
  cout << ans;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

You are given n points on a plane. All points are different.

Find the number of different groups of three points (A, B, C) such that point B is the middle of segment AC.

The groups of three points are considered unordered, that is, if point B is the middle of segment AC, then groups (A, B, C) and (C, B, A) are considered the same.

Input

The first line contains a single integer n (3 ≤ n ≤ 3000) — the number of points.

Next n lines contain the points. The i-th line contains coordinates of the i-th point: two space-separated integers xi, yi ( - 1000 ≤ xi, yi ≤ 1000).

It is guaranteed that all given points are different.

Output

Print the single number — the answer to the problem.

Examples

Input

3
1 1
2 2
3 3

Output

1

Input

3
0 0
-1 0
0 1

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > a(n, make_pair(1000, 1000));
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a[i].first += x;
    a[i].second += y;
  }
  vector<vector<bool> > vis(2001, vector<bool>(2001));
  for (int i = 0; i < 2001; i++)
    for (int j = 0; j < 2001; j++) vis[i][j] = false;
  for (int i = 0; i < n; i++) {
    vis[a[i].first][a[i].second] = true;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j > i; j--) {
      float x = (a[i].first + a[j].first) / (float)2;
      float y = (a[i].second + a[j].second) / (float)2;
      if ((x == (int)x) && (y == (int)y) && vis[x][y]) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Japan achieved the second straight victory in the national baseball competition WBC !! A baseball tournament was held at Aizu Gakuen High School as baseball became more popular. In this tournament, a round-robin league match will be held and the ranking will be decided in the following ways.

1. The team with the most wins is ranked high
2. If the number of wins is the same, the team with the fewest losses will be ranked higher.

Create a program that inputs the results of each team and outputs the team names in order from the top team. If there are teams with the same rank, output them in the order of input. However, the number of teams n is an integer from 2 to 10 and the team name t is a single-byte alphabetic character. , 2 for a draw. Also, the team name shall be unique.

Input

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

n
score1
score2
::
scoren

The number of teams n (2 ≤ n ≤ 10) is given on the first line, and the scorei of the i-th team is given on the following n lines. Each grade is given in the following format.

t r1 r2 ... rn−1

The team name t (one-character half-width alphabetic character) and the result ri (0, 1, or 2) for each match of t are given separated by blanks.

The number of datasets does not exceed 50.

Output

For each dataset, the team name is output in order from the top team.

Example

Input

6
A 1 0 0 2 0
B 0 0 1 1 0
C 1 1 1 1 1
D 1 0 0 1 2
E 2 0 0 0 0
F 1 1 0 2 1
4
g 1 1 1
h 0 1 2
w 0 0 0
b 0 2 1
0

Output

E
A
B
D
F
C
w
h
b
g

### Response

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

struct record
{
    char t;
    int w, l;
};

void sort( record* a, int n )
{
    for( int i = 0; i < n; i++ )
        for( int j = n - 1; j >= i + 1; j-- )
            if( a[j].w > a[j-1].w )
            {
                record temp = a[j];
                a[j] = a[j-1];
                a[j-1] = temp;
            }
    for( int i = 0; i < n; i++ )
        for( int j = n - 1; j >= i + 1; j-- )
            if( a[j].w == a[j-1].w && a[j].l < a[j-1].l )
            {
                record temp = a[j];
                a[j] = a[j-1];
                a[j-1] = temp;
            }
}

int main()
{
    int n;
    char d;
    record team[10];

    while( cin >> n )
    {
        if( n == 0 )
            break;

        for( int i = 0; i < n; i++ )
        {
            cin >> d;
            team[i].t = d;

            int a = 0, b = 0;
            for( int j = 0; j < n - 1; j++ )
            {
                cin >> d;
                if( d == '0' )
                    a++;
                else if( d == '1' )
                    b++;
                else if( d == '2' );
                else;
            }
            team[i].w = a;
            team[i].l = b;
        }

        sort( team, n );

        for( int i = 0; i < n; i++ )
            cout << team[i].t << endl;
    }

    return 0;
}

```


### Prompt

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

You are given an integer n and an integer k.

In one step you can do one of the following moves:

  * decrease n by 1;
  * divide n by k if n is divisible by k.

For example, if n = 27 and k = 3 you can do the following steps: 27 → 26 → 25 → 24 → 8 → 7 → 6 → 2 → 1 → 0.

You are asked to calculate the minimum number of steps to reach 0 from n.

Input

The first line contains one integer t (1 ≤ t ≤ 100) — the number of queries.

The only line of each query contains two integers n and k (1 ≤ n ≤ 10^{18}, 2 ≤ k ≤ 10^{18}).

Output

For each query print the minimum number of steps to reach 0 from n in single line.

Example

Input

2
59 3
1000000000000000000 10

Output

8
19

Note

Steps for the first test case are: 59 → 58 → 57 → 19 → 18 → 6 → 2 → 1 → 0.

In the second test case you have to divide n by k 18 times and then decrease n by 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long count = 0;
    while (n) {
      if (n % k == 0) {
        n = n / k;
        count++;
      } else {
        count += n % k;
        n = n - n % k;
      }
    }
    cout << count << endl;
  }
}

```


### Prompt

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

Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not.

You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R.

Each testcase contains several segments, for each of them you are required to solve the problem separately.

Input

The first line contains a single integer T (1 ≤ T ≤ 10^4) — the number of segments in a testcase.

Each of the next T lines contains two integers L_i and R_i (1 ≤ L_i ≤ R_i ≤ 10^{18}).

Output

Print T lines — the i-th line should contain the number of classy integers on a segment [L_i; R_i].

Example

Input

4
1 1000
1024 1024
65536 65536
999999 1000001

Output

1000
1
0
2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int sum() { return 0; }
template <typename T, typename... Args>
T sum(T a, Args... args) {
  return a + sum(args...);
}
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
const long long int N = 200005;
vector<long long int> ans = {INF};
void precal(long long int pos, long long int c, long long int num) {
  if (pos == 18) {
    ans.push_back(num);
    return;
  }
  precal(pos + 1, c, num * 10);
  if (c < 3) {
    for (long long int i = 1; i <= 9; i++) {
      precal(pos + 1, c + 1, num * 10 + i);
    }
  }
}
void solve() {
  long long int l, r;
  cin >> l >> r;
  cout << upper_bound(ans.begin(), ans.end(), r) -
              lower_bound(ans.begin(), ans.end(), l)
       << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  precal(0, 0, 0);
  sort(ans.begin(), ans.end());
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}

```


### Prompt

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

New Year is getting near. So it's time to change handles on codeforces. Mishka wants to change his handle but in such a way that people would not forget who he is.

To make it work, he only allowed to change letters case. More formally, during one handle change he can choose any segment of his handle [i; i + l - 1] and apply tolower or toupper to all letters of his handle on this segment (more fomally, replace all uppercase letters with corresponding lowercase or vice versa). The length l is fixed for all changes.

Because it is not allowed to change codeforces handle too often, Mishka can perform at most k such operations. What is the minimum value of min(lower, upper) (where lower is the number of lowercase letters, and upper is the number of uppercase letters) can be obtained after optimal sequence of changes?

Input

The first line of the input contains three integers n, k and l (1 ≤ n, k, l ≤ 10^6, l ≤ n) — the length of Mishka's handle, the number of changes and the length of the segment.

The second line of the input contains one string s, consisting of n lowercase and uppercase Latin letters — Mishka's handle.

Output

Print one integer — the minimum value of min(lower, upper) after that Mishka change his handle at most k times in a way described in the problem statement.

Examples

Input

7 1 4
PikMike

Output

0

Input

15 2 2
AaAaAAaaAAAAaaA

Output

2

Input

14 2 6
aBcdEFGHIJklMn

Output

0

Input

9 2 2
aAaAAAaaA

Output

1

### Response

```cpp
#include <bits/stdc++.h>
int n, k, l;
std::vector<int> pref;
std::vector<int> A;
inline int sum(int a, int b) { return pref[b + 1] - pref[a]; }
std::pair<long long, int> withcost(int cost) {
  std::vector<std::pair<long long, int> > dp(n + 1);
  for (int i = (1); i < (n + 1); ++i) {
    int b = std::max(0, i - l);
    dp[i] =
        std::min(std::make_pair(dp[b].first + cost, dp[b].second + 1),
                 std::make_pair(dp[i - 1].first + A[i - 1], dp[i - 1].second));
  }
  return dp[n];
}
int aaa(int cost) { return withcost(cost).first - 1ll * k * cost; }
int solve() {
  int left = 0;
  int right = 1000000000;
  while (left < right) {
    int cost = (left + right) / 2;
    auto xd = withcost(cost);
    if (xd.second > k)
      left = cost + 1;
    else
      right = cost;
  }
  return aaa(left);
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  std::cin >> n >> k >> l;
  std::string s;
  std::cin >> s;
  A.resize(n);
  pref.resize(n + 1);
  for (int i = 0; i < ((int)(s).size()); ++i)
    if (s[i] < 'a') A[i] = 1;
  for (int i = 0; i < (n); ++i) pref[i + 1] = pref[i] + A[i];
  int ans = solve();
  for (int i = 0; i < (n); ++i) A[i] = 1 - A[i];
  for (int i = 0; i < (n); ++i) pref[i + 1] = pref[i] + A[i];
  ans = std::min(solve(), ans);
  std::cout << ans << "\n";
  return 0;
}

```