### Prompt

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

Long long ago, there lived a wizard who invented a lot of "magical patterns." In a room where one of his magical patterns is drawn on the floor, anyone can use magic by casting magic spells! The set of spells usable in the room depends on the drawn magical pattern. Your task is to compute, for each given magical pattern, the most powerful spell enabled by the pattern.

A spell is a string of lowercase letters. Among the spells, lexicographically earlier one is more powerful. Note that a string w is defined to be lexicographically earlier than a string u when w has smaller letter in the order a<b<...<z on the first position at which they differ, or w is a prefix of u. For instance, "abcd" is earlier than "abe" because 'c' < 'e', and "abe" is earlier than "abef" because the former is a prefix of the latter.

A magical pattern is a diagram consisting of uniquely numbered nodes and arrows connecting them. Each arrow is associated with its label, a lowercase string. There are two special nodes in a pattern, called the star node and the gold node. A spell becomes usable by a magical pattern if and only if the spell emerges as a sequential concatenation of the labels of a path from the star to the gold along the arrows.

The next figure shows an example of a pattern with four nodes and seven arrows.

picture: sample dataset 1

The node 0 is the star node and 2 is the gold node. One example of the spells that become usable by this magical pattern is "abracadabra", because it appears in the path

0 --"abra"--> 1 --"cada"--> 3 --"bra"--> 2.

Another example is "oilcadabraketdadabra", obtained from the path

0 --"oil"--> 1 --"cada"--> 3 --"bra"--> 2 --"ket"--> 3 --"da"--> 3 --"da"--> 3 --"bra"--> 2.

The spell "abracadabra" is more powerful than "oilcadabraketdadabra" because it is lexicographically earlier. In fact, no other spell enabled by the magical pattern is more powerful than "abracadabra". Thus "abracadabra" is the answer you have to compute.

When you cannot determine the most powerful spell, please answer "NO". There are two such cases. One is the case when no path exists from the star node to the gold node. The other case is when for every usable spell there always exist more powerful spells. The situation is exemplified in the following figure: "ab" is more powerful than "b", and "aab" is more powerful than "ab", and so on. For any spell, by prepending "a", we obtain a lexicographically earlier (hence more powerful) spell.

picture: sample dataset 2

Input

The input consists of at most 150 datasets. Each dataset is formatted as follows.

> n a s g
>  x1 y1 lab1
>  x2 y2 lab2
>  ...
>  xa ya laba
>

The first line of a dataset contains four integers. n is the number of the nodes, and a is the number of the arrows. The numbers s and g indicate the star node and the gold node, respectively. Then a lines describing the arrows follow. Each line consists of two integers and one string. The line "xi yi labi" represents an arrow from the node xi to the node yi with the associated label labi . Values in the dataset satisfy: 2 ≤ n ≤ 40, 0 ≤ a ≤ 400, 0 ≤ s, g, xi , yi < n , s ≠g, and labi is a string of 1 to 6 lowercase letters. Be careful that there may be self-connecting arrows (i.e., xi = yi ), and multiple arrows connecting the same pair of nodes (i.e., xi = xj and yi = yj for some i ≠ j ).

The end of the input is indicated by a line containing four zeros.

Output

For each dataset, output a line containing the most powerful spell for the magical pattern. If there does not exist such a spell, output "NO" (without quotes). Each line should not have any other characters.

Sample Input

4 7 0 2
0 1 abra
0 1 oil
2 0 ket
1 3 cada
3 3 da
3 2 bra
2 3 ket
2 2 0 1
0 0 a
0 1 b
5 6 3 0
3 1 op
3 2 op
3 4 opq
1 0 st
2 0 qr
4 0 r
2 1 0 1
1 1 loooop
0 0 0 0

Output for the Sample Input

abracadabra
NO
opqr
NO

Example

Input

4 7 0 2
0 1 abra
0 1 oil
2 0 ket
1 3 cada
3 3 da
3 2 bra
2 3 ket
2 2 0 1
0 0 a
0 1 b
5 6 3 0
3 1 op
3 2 op
3 4 opq
1 0 st
2 0 qr
4 0 r
2 1 0 1
1 1 loooop
0 0 0 0

Output

abracadabra
NO
opqr
NO

### Response

```cpp
#include <iostream>
#include <cstring>
#include <string>

using namespace std;

int u[400],v[400];
string w[400];

int main(){
    ios::sync_with_stdio(0);

    int n,m,s,e;
    char str[7];
    string dist[40];
    bool visited[40],change,inf;

    while(true){
        cin >> n >> m >> s >> e;

        if(n == 0) break;

        for(int i = 0;i < m;++i)
            cin >> u[i] >> v[i] >> w[i];

        memset(visited,0,sizeof visited);

        dist[e] = "";
        visited[e] = true;
        change = true;
        inf = false;

        for(int it = 0;it <= 6*n && change && !inf;++it){
            change = false;

            for(int i = 0;i < m;++i){
                if(visited[ v[i] ]){
                    string aux = w[i] + dist[ v[i] ];

                    if(!visited[ u[i] ] || aux < dist[ u[i] ]){
                        dist[ u[i] ] = aux;
                        change = true;
                        if(it >= n - 1 && u[i] == s) inf = true;
                    }

                    visited[ u[i] ] = true;
                }
            }
        }

        if(inf || !visited[s]) cout << "NO\n";
        else cout << dist[s].c_str() << '\n';
    }

    return 0;
}
```


### Prompt

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

There is an N-car train.

You are given an integer i. Find the value of j such that the following statement is true: "the i-th car from the front of the train is the j-th car from the back."

Constraints

* 1 \leq N \leq 100
* 1 \leq i \leq N

Input

Input is given from Standard Input in the following format:

N i

Output

Print the answer.

Examples

Input

4 2

Output

3

Input

1 1

Output

1

Input

15 11

Output

5

### Response

```cpp
#include<iostream>
using namespace std;
int main(){
  int A,B;
  cin >> A >> B;
  cout << A-B+1 << endl;
}
```


### Prompt

Generate a Cpp solution to the following problem:

As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, he asked each one: "Which one committed the crime?". Suspect number i answered either "The crime was committed by suspect number ai", or "Suspect number ai didn't commit the crime". Also, the suspect could say so about himself (ai = i).

Sherlock Holmes understood for sure that exactly m answers were the truth and all other answers were a lie. Now help him understand this: which suspect lied and which one told the truth?

Input

The first line contains two integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ n) — the total number of suspects and the number of suspects who told the truth. Next n lines contain the suspects' answers. The i-th line contains either "+ai" (without the quotes), if the suspect number i says that the crime was committed by suspect number ai, or "-ai" (without the quotes), if the suspect number i says that the suspect number ai didn't commit the crime (ai is an integer, 1 ≤ ai ≤ n).

It is guaranteed that at least one suspect exists, such that if he committed the crime, then exactly m people told the truth.

Output

Print n lines. Line number i should contain "Truth" if suspect number i has told the truth for sure. Print "Lie" if the suspect number i lied for sure and print "Not defined" if he could lie and could tell the truth, too, depending on who committed the crime.

Examples

Input

1 1
+1

Output

Truth

Input

3 2
-1
-2
-3

Output

Not defined
Not defined
Not defined

Input

4 1
+2
-3
+4
-1

Output

Lie
Not defined
Lie
Not defined

Note

The first sample has the single person and he confesses to the crime, and Sherlock Holmes knows that one person is telling the truth. That means that this person is telling the truth.

In the second sample there are three suspects and each one denies his guilt. Sherlock Holmes knows that only two of them are telling the truth. Any one of them can be the criminal, so we don't know for any of them, whether this person is telling the truth or not.

In the third sample the second and the fourth suspect defend the first and the third one. But only one is telling the truth, thus, the first or the third one is the criminal. Both of them can be criminals, so the second and the fourth one can either be lying or telling the truth. The first and the third one are lying for sure as they are blaming the second and the fourth one.

### Response

```cpp
#include <bits/stdc++.h>
int ins[100010] = {0}, ok[100010] = {0}, cnt = 0;
int n, m;
char ch;
int x;
int sum = 0, a[100010] = {0}, b[100010] = {0};
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    getchar();
    ch = getchar();
    scanf("%d", &x);
    if (ch == '+') {
      a[x]++;
      ins[i] = x;
    } else {
      b[x]++;
      ins[i] = -x;
      sum++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] + sum - b[i] == m) {
      ok[i] = 1;
      cnt++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (ins[i] > 0) {
      if (ok[ins[i]] && cnt == 1) {
        printf("Truth\n");
      } else if (!ok[ins[i]]) {
        printf("Lie\n");
      } else {
        printf("Not defined\n");
      }
    } else {
      if (!ok[-ins[i]]) {
        printf("Truth\n");
      } else if (ok[-ins[i]] && cnt == 1) {
        printf("Lie\n");
      } else {
        printf("Not defined\n");
      }
    }
  }
}

```


### Prompt

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

An online contest will soon be held on ForceCoders, a large competitive programming platform. The authors have prepared n problems; and since the platform is very popular, 998244351 coder from all over the world is going to solve them.

For each problem, the authors estimated the number of people who would solve it: for the i-th problem, the number of accepted solutions will be between l_i and r_i, inclusive.

The creator of ForceCoders uses different criteria to determine if the contest is good or bad. One of these criteria is the number of inversions in the problem order. An inversion is a pair of problems (x, y) such that x is located earlier in the contest (x < y), but the number of accepted solutions for y is strictly greater.

Obviously, both the creator of ForceCoders and the authors of the contest want the contest to be good. Now they want to calculate the probability that there will be no inversions in the problem order, assuming that for each problem i, any integral number of accepted solutions for it (between l_i and r_i) is equally probable, and all these numbers are independent.

Input

The first line contains one integer n (2 ≤ n ≤ 50) — the number of problems in the contest.

Then n lines follow, the i-th line contains two integers l_i and r_i (0 ≤ l_i ≤ r_i ≤ 998244351) — the minimum and maximum number of accepted solutions for the i-th problem, respectively.

Output

The probability that there will be no inversions in the contest can be expressed as an irreducible fraction x/y, where y is coprime with 998244353. Print one integer — the value of xy^{-1}, taken modulo 998244353, where y^{-1} is an integer such that yy^{-1} ≡ 1 (mod 998244353).

Examples

Input

3
1 2
1 2
1 2

Output

499122177

Input

2
42 1337
13 420

Output

578894053

Input

2
1 1
0 0

Output

1

Input

2
1 1
1 1

Output

1

Note

The real answer in the first test is 1/2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353l;
const int N = 60;
long long f[N][N * 4][N];
int l[N], r[N], d[N * 2], ni[N];
int n;
vector<pair<int, int> > w;
unordered_map<int, int> g[N];
long long get(long long n, long long k) {
  if (g[k].find(n) != g[k].end()) return g[k][n];
  long long v = 1;
  for (int i = 1; i <= k; i++) v = v * (n + i - 1) % mod * ni[i] % mod;
  g[k][n] = v;
  return v;
}
long long calc(long long x, long long y) {
  long long z = 1;
  while (y) {
    if (y & 1) z = z * x % mod;
    x = x * x % mod, y /= 2;
  }
  return z;
}
int main() {
  scanf("%d", &n);
  long long all = 1;
  for (int i = 1; i <= n; i++) ni[i] = calc(i, mod - 2);
  for (int i = 1; i <= n; i++) scanf("%d %d", &l[n - i + 1], &r[n - i + 1]);
  for (int i = 1; i <= n; i++)
    d[i] = l[i], d[i + n] = r[i], all = (all * (r[i] - l[i] + 1)) % mod;
  sort(d + 1, d + n + n + 1);
  d[0] = -1;
  int tot = 0;
  for (int i = 1; i <= n + n; i++)
    if (d[i] != d[tot]) d[++tot] = d[i];
  for (int i = 0; i <= tot; i++) {
    w.push_back(make_pair(d[i], d[i]));
    if (i != tot && d[i] + 1 <= d[i + 1] - 1)
      w.push_back(make_pair(d[i] + 1, d[i + 1] - 1));
  }
  f[0][0][1] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < w.size(); j++)
      for (int k = 1; k <= i; k++)
        if (f[i - 1][j][k])
          for (int x = j; x < w.size(); x++)
            if (l[i] <= w[x].first && w[x].second <= r[i]) {
              if (x == j)
                f[i][j][k + 1] = (f[i][j][k + 1] + f[i - 1][j][k]) % mod;
              else
                f[i][x][1] =
                    (f[i][x][1] +
                     f[i - 1][j][k] * get(w[j].second - w[j].first + 1, k)) %
                    mod;
            }
  long long ans = 0;
  for (int j = 0; j < w.size(); j++)
    for (int k = 1; k <= n; k++)
      ans = (ans + f[n][j][k] * get(w[j].second - w[j].first + 1, k)) % mod;
  printf("%lld\n", ans * calc(all, mod - 2) % mod);
  return 0;
}

```


### Prompt

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

This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`.

So he has decided to make a program that puts the single space he omitted.

You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s.

Constraints

* s contains exactly 12 letters.
* All letters in s are uppercase English letters.

Input

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

s

Output

Print the string putting a single space between the first 4 letters and last 8 letters in the string s. Put a line break at the end.

Examples

Input

CODEFESTIVAL

Output

CODE FESTIVAL

Input

POSTGRADUATE

Output

POST GRADUATE

Input

ABCDEFGHIJKL

Output

ABCD EFGHIJKL

### Response

```cpp
#include<iostream>
std::string s;
int main(){
  std::cin>>s;s.insert(4," ");
  std::cout<<s<<'\n';
}

```


### Prompt

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

At the pancake shop you work for, pancake dough is lined up in a row on an elongated iron plate and baked. Pancakes can be completed by turning them over with a spatula several times. How many times you turn it over to complete it depends on the pancake.

Since the spatula is large, two adjacent pancakes will be turned over at the same time. At this time, the positions of these two sheets do not switch. However, not only can you flip both ends together with the pancake next to you, but you can also flip just one. After turning over all the pancakes more than the required number of times, remove them all at once from the iron plate and you're done.

I don't want to flip the pancakes too much, as turning them over more than necessary will make them harder. So you wanted to find a way to minimize the total number of times each pancake was flipped over by the time it was all finished.

When each pancake is given the number of pancakes on the iron plate and how many times it must be turned over before it is completed, the number of times each pancake is turned over before it is completed (manipulate the spatula). Create a program that calculates the minimum sum of (not the number of times).

Input

The input is given in the following format.

N
p1 p2 ... pN

The number of pancakes N (3 ≤ N ≤ 5000) is given on the first line. The second line gives the number of flips pi (0 ≤ pi ≤ 3) required to complete each pancake.

Output

Output the minimum value of the total number of times each pancake is turned inside out on one line until all are completed.

Examples

Input

3
1 2 1

Output

4

Input

3
0 3 0

Output

6

### Response

```cpp
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
long long dp[200000] = {};
int main() {
	int n;
	cin >> n;
	vector<long long> input;
	long long ans = LONG_INF;
	REP(i, n) {
		long long a;
		cin >> a;
		input.push_back(a);
	}
	REP(tea, 2) {
		for (int q = 0; q < 4; ++q) {
			for (int i = 0; i < input.size(); ++i) {
				dp[i] = input[i];
			}
			long long geko = q;
			dp[0] -= geko;
			for (int i = 0; i < input.size()-1; ++i) {
				while (dp[i] > 0) {
					dp[i]--;
					dp[i + 1]--;
					geko += 2;
				}
			}
			ans = min(ans, geko + max(dp[input.size() - 1], 0LL));
		}
		reverse(input.begin(), input.end());
	}
	cout << ans << endl;
	return 0;
}

```


### Prompt

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

Vova's house is an array consisting of n elements (yeah, this is the first problem, I think, where someone lives in the array). There are heaters in some positions of the array. The i-th element of the array is 1 if there is a heater in the position i, otherwise the i-th element of the array is 0.

Each heater has a value r (r is the same for all heaters). This value means that the heater at the position pos can warm up all the elements in range [pos - r + 1; pos + r - 1].

Vova likes to walk through his house while he thinks, and he hates cold positions of his house. Vova wants to switch some of his heaters on in such a way that each element of his house will be warmed up by at least one heater.

Vova's target is to warm up the whole house (all the elements of the array), i.e. if n = 6, r = 2 and heaters are at positions 2 and 5, then Vova can warm up the whole house if he switches all the heaters in the house on (then the first 3 elements will be warmed up by the first heater and the last 3 elements will be warmed up by the second heater).

Initially, all the heaters are off.

But from the other hand, Vova didn't like to pay much for the electricity. So he wants to switch the minimum number of heaters on in such a way that each element of his house is warmed up by at least one heater.

Your task is to find this number of heaters or say that it is impossible to warm up the whole house.

Input

The first line of the input contains two integers n and r (1 ≤ n, r ≤ 1000) — the number of elements in the array and the value of heaters.

The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 1) — the Vova's house description.

Output

Print one integer — the minimum number of heaters needed to warm up the whole house or -1 if it is impossible to do it.

Examples

Input

6 2
0 1 1 0 0 1

Output

3

Input

5 3
1 0 0 0 1

Output

2

Input

5 10
0 0 0 0 0

Output

-1

Input

10 3
0 0 1 1 0 1 0 0 0 1

Output

3

Note

In the first example the heater at the position 2 warms up elements [1; 3], the heater at the position 3 warms up elements [2, 4] and the heater at the position 6 warms up elements [5; 6] so the answer is 3.

In the second example the heater at the position 1 warms up elements [1; 3] and the heater at the position 5 warms up elements [3; 5] so the answer is 2.

In the third example there are no heaters so the answer is -1.

In the fourth example the heater at the position 3 warms up elements [1; 5], the heater at the position 6 warms up elements [4; 8] and the heater at the position 10 warms up elements [8; 10] so the answer is 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int lst[N];
char lol[N], a[N];
int main() {
  int n, r;
  cin >> n >> r;
  for (int i = 0; i < n; ++i) cin >> a[i], lst[i] = -1;
  if (a[0] == '1') lst[0] = 0;
  for (int i = 1; i < n; ++i) {
    lst[i] = lst[i - 1];
    if (a[i] == '1') lst[i] = i;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (lol[i]) continue;
    int j = min(n - 1, i + r - 1);
    j = lst[j];
    if (j == -1) {
      cout << -1;
      exit(0);
    }
    for (int k = max(0, j - r + 1); k <= min(n - 1, j + r - 1); ++k) lol[k] = 1;
    ++ans;
  }
  for (int i = 0; i < n; ++i)
    if (!lol[i]) {
      cout << -1;
      exit(0);
    }
  cout << ans;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?

Input

The first line contains integer n (3 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the i-th number in the list is the number of rounds the i-th person wants to play.

Output

In a single line print a single integer — the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

3
3 2 2

Output

4

Input

4
2 2 2 2

Output

3

Note

You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long a[n], i;
  long long sum = 0, maxi = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    maxi = max(maxi, a[i]);
  }
  long long ans = sum / (n - 1);
  if (sum % (n - 1) != 0) ans++;
  ans = max(ans, maxi);
  cout << ans << '\n';
}

```


### Prompt

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

When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.

Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number k. Moreover, petricium la petricium stands for number k2, petricium la petricium la petricium stands for k3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.

Petya's invention brought on a challenge that needed to be solved quickly: does some number l belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.

Input

The first input line contains integer number k, the second line contains integer number l (2 ≤ k, l ≤ 231 - 1).

Output

You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number l.

Examples

Input

5
25

Output

YES
1

Input

3
8

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, s, dem = 0;
  scanf("%lld%lld", &n, &k);
  s = n;
  while (n < k) {
    n *= s;
    dem++;
  }
  if (n == k) {
    printf("YES\n");
    printf("%lld", dem);
  } else {
    printf("NO");
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are n planes on Earth, numbered from 1 to n, and the plane with number i likes the plane with number fi, where 1 ≤ fi ≤ n and fi ≠ i.

We call a love triangle a situation in which plane A likes plane B, plane B likes plane C and plane C likes plane A. Find out if there is any love triangle on Earth.

Input

The first line contains a single integer n (2 ≤ n ≤ 5000) — the number of planes.

The second line contains n integers f1, f2, ..., fn (1 ≤ fi ≤ n, fi ≠ i), meaning that the i-th plane likes the fi-th.

Output

Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».

You can output any letter in lower case or in upper case.

Examples

Input

5
2 4 5 1 3

Output

YES

Input

5
5 5 5 5 1

Output

NO

Note

In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.

In second example there are no love triangles.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void Start_Crushing() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
vector<int> love;
int nextLove(int plane) { return love[plane]; }
void solve() {
  int n;
  cin >> n;
  love.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> love[i];
  }
  for (int i = 1; i <= n; i++) {
    if (i == nextLove(nextLove(nextLove(i)))) {
      cout << "yes";
      return;
    }
  }
  cout << "no";
}
int main() {
  Start_Crushing();
  int t = 1;
  while (t--) {
    solve();
    if (!t) break;
    cout << "\n";
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

You are given a complete undirected graph with n vertices. A number ai is assigned to each vertex, and the weight of an edge between vertices i and j is equal to ai xor aj.

Calculate the weight of the minimum spanning tree in this graph.

Input

The first line contains n (1 ≤ n ≤ 200000) — the number of vertices in the graph.

The second line contains n integers a1, a2, ..., an (0 ≤ ai < 230) — the numbers assigned to the vertices.

Output

Print one number — the weight of the minimum spanning tree in the graph.

Examples

Input

5
1 2 3 4 5

Output

8

Input

4
1 2 3 4

Output

8

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, a[N];
int root = 0, ch[N * 40][2], L[N * 40], R[N * 40], tot = 0;
inline int Min(int x, int y) { return x < y ? x : y; }
inline int Max(int x, int y) { return x > y ? x : y; }
void insert(int &u, int id, int d) {
  if (!u) u = ++tot;
  L[u] = Min(L[u], id), R[u] = Max(R[u], id);
  if (d < 0) return;
  insert(ch[u][(a[id] >> d) & 1], id, d - 1);
}
int qry(int u, int x, int d) {
  if (d < 0) return 0;
  int c = (x >> d) & 1;
  if (ch[u][c]) return qry(ch[u][c], x, d - 1);
  return qry(ch[u][c ^ 1], x, d - 1) + (1 << d);
}
long long dfs(int u, int d) {
  if (d < 0) return 0;
  if (R[ch[u][0]] && R[ch[u][1]]) {
    int mn = 0x3f3f3f3f;
    for (int i = L[ch[u][0]]; i <= R[ch[u][0]]; i++)
      mn = Min(mn, qry(ch[u][1], a[i], d - 1));
    return dfs(ch[u][0], d - 1) + dfs(ch[u][1], d - 1) + mn + (1ll << d);
  }
  if (R[ch[u][0]]) return dfs(ch[u][0], d - 1);
  if (R[ch[u][1]]) return dfs(ch[u][1], d - 1);
  return 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  memset(L, 0x3f3f3f3f, sizeof(L));
  for (int i = 1; i <= n; i++) insert(root, i, 30);
  printf("%lld\n", dfs(root, 30));
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

DZY owns 2m islands near his home, numbered from 1 to 2m. He loves building bridges to connect the islands. Every bridge he builds takes one day's time to walk across.

DZY has a strange rule of building the bridges. For every pair of islands u, v (u ≠ v), he has built 2k different bridges connecting them, where <image> (a|b means b is divisible by a). These bridges are bidirectional.

Also, DZY has built some bridges connecting his home with the islands. Specifically, there are ai different bridges from his home to the i-th island. These are one-way bridges, so after he leaves his home he will never come back.

DZY decides to go to the islands for sightseeing. At first he is at home. He chooses and walks across one of the bridges connecting with his home, and arrives at some island. After that, he will spend t day(s) on the islands. Each day, he can choose to stay and rest, or to walk to another island across the bridge. It is allowed to stay at an island for more than one day. It's also allowed to cross one bridge more than once.

Suppose that right after the t-th day DZY stands at the i-th island. Let ans[i] be the number of ways for DZY to reach the i-th island after t-th day. Your task is to calculate ans[i] for each i modulo 1051131.

Input

To avoid huge input, we use the following way to generate the array a. You are given the first s elements of array: a1, a2, ..., as. All the other elements should be calculated by formula: ai = (101·ai - s + 10007) mod 1051131 (s < i ≤ 2m).

The first line contains three integers m, t, s (1 ≤ m ≤ 25; 1 ≤ t ≤ 1018; 1 ≤ s ≤ min(2m, 105)).

The second line contains s integers a1, a2, ..., as (1 ≤ ai ≤ 106).

Output

To avoid huge output, you only need to output xor-sum of all the answers for all i modulo 1051131 (1 ≤ i ≤ 2m), i.e. (ans[1] mod 1051131) xor (ans[2] mod 1051131) xor... xor (ans[n] mod 1051131).

Examples

Input

2 1 4
1 1 1 2

Output

1

Input

3 5 6
389094 705719 547193 653800 947499 17024

Output

556970

Note

In the first sample, ans = [6, 7, 6, 6].

If he wants to be at island 1 after one day, he has 6 different ways:

  1. home —> 1 -(stay)-> 1
  2. home —> 2 —> 1
  3. home —> 3 —> 1
  4. home —> 3 —> 1 (note that there are two different bridges between 1 and 3)
  5. home —> 4 —> 1
  6. home —> 4 —> 1 (note that there are two different bridges from home to 4)

In the second sample, (a1, a2, a3, a4, a5, a6, a7, a8) = (389094, 705719, 547193, 653800, 947499, 17024, 416654, 861849), ans = [235771, 712729, 433182, 745954, 139255, 935785, 620229, 644335].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1051131, iv2 = (mod + 1) / 2;
inline int add(int a, int b) {
  if ((a += b) >= mod) a -= mod;
  return a;
}
inline int dec(int a, int b) {
  if ((a -= b) < 0) a += mod;
  return a;
}
inline int mult(int a, int b) {
  long long t = 1ll * a * b;
  if (t >= mod) t %= mod;
  return t;
}
inline int power(int a, long long b) {
  int out = 1;
  while (b) {
    if (b & 1) out = mult(out, a);
    a = mult(a, a);
    b >>= 1;
  }
  return out;
}
int m, s;
long long t;
int pw2;
vector<int> a;
vector<int> solve(vector<int> &a, int len, int p, int q) {
  if (len == 0) return vector<int>({mult(a[0], power(add(p, q), t))});
  vector<int> ta(1 << (len - 1));
  for (int i = 0; i < (1 << (len - 1)); i++)
    ta[i] = add(a[i], a[i + (1 << (len - 1))]);
  int r = dec(mult((((1 << (len - 1)) - 1) % mod), p), q);
  auto cur = solve(ta, len - 1, add(p, p), add(r, add(q, q)));
  cur.insert(cur.end(), cur.begin(), cur.end());
  int ir = power(dec(0, r), t);
  for (int i = 0; i < (1 << (len - 1)); i++) {
    int vl = mult(dec(a[i], a[i + (1 << (len - 1))]), ir);
    cur[i] = add(cur[i], vl);
    cur[i + (1 << (len - 1))] = dec(cur[i + (1 << (len - 1))], vl);
  }
  for (int i = 0; i < (1 << len); i++) cur[i] = mult(cur[i], iv2);
  return cur;
}
int main() {
  scanf("%d%lld%d", &m, &t, &s);
  pw2 = power(2, t);
  a.resize((1 << m) + 1);
  for (int i = 1; i <= s; i++) scanf("%d", &a[i]);
  for (int i = s + 1; i <= (1 << m); i++)
    a[i] = add(mult(101, a[i - s]), 10007);
  a[0] = a[1 << m];
  a.pop_back();
  auto ans = solve(a, m, 1, 0);
  int res = 0;
  for (int i = 0; i < (1 << m); i++) res ^= ans[i];
  printf("%d\n", res);
  return 0;
}

```


### Prompt

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

Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string.

More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print  - 1.

Input

The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n).

The second line contains string s1 of length n, consisting of lowercase English letters.

The third line contain string s2 of length n, consisting of lowercase English letters.

Output

Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.

Examples

Input

3 2
abc
xyc

Output

ayd

Input

1 0
c
b

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T distsqr(T x, T y, T a, T b) {
  return sqr(x - a) + sqr(y - b);
}
double cosine_angle(double a, double b, double c) {
  return (double)(sqr(a) + sqr(b) - sqr(c)) / ((double)2.0 * a * b);
}
template <class T>
T Maximum(T a, T b) {
  return a > b ? a : b;
}
template <class T>
T Minimum(T a, T b) {
  return a < b ? a : b;
}
template <class T>
T GCD(T a, T b) {
  if (!b) return a;
  return GCD(b, a % b);
}
template <class T>
void SWAP(T &a, T &b) {
  T temp = a;
  a = b;
  b = temp;
  return;
}
template <class T>
T BigMod(T a, T n, T mod) {
  if (!n) return (T)1 % mod;
  long long int power = BigMod(a, n >> 1, mod);
  power %= mod;
  power *= power;
  power %= mod;
  if (n & 1) power *= a % mod, power %= mod;
  return power;
}
template <class T>
T ExtendedEuclid(T a, T b, T c) {
  if (!a) return 0;
  return (b * ExtendedEuclid(b % a, a, -c) + c) / a;
}
template <class T>
T ModInverse(T a, T m) {
  return ((ExtendedEuclid(a, m, (T)GCD(a, m))) % (m) + (m)) % (m);
}
char str[3][100010];
int n;
int main() {
  int i, n, t, r, l[2], temp;
  scanf("%d %d", &n, &t);
  scanf("%s %s", str[0], str[1]);
  for (i = 0, r = n - t; i < n; i++) {
    if (r) {
      if (str[0][i] == str[1][i]) str[2][i] = str[0][i], r--;
    }
  }
  for (i = 0, l[0] = l[1] = r; i < n; i++) {
    if (!str[2][i]) {
      if (l[0] > 0 || l[1] > 0) {
        if (l[0] < l[1])
          str[2][i] = str[1][i], l[1]--;
        else {
          str[2][i] = str[0][i];
          l[0]--;
        }
      } else {
        temp = (str[1][i] - 'a' + 1) % 26 + 'a';
        if (temp != (int)str[0][i])
          str[2][i] = temp;
        else
          str[2][i] = ((str[1][i] - 'a' - 1) % (26) + (26)) % (26) + 'a';
      }
    }
  }
  if (!l[0] && !l[1])
    printf("%s\n", str[2]);
  else
    printf("%d", -1);
  return 0;
}

```


### Prompt

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

There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests.

A result of the elimination stage is the total score in two contests, but, unfortunately, the jury lost the final standings and has only standings for the first and for the second contest separately.

In each contest, the participants are ranked by their point score in non-increasing order. When two participants have a tie (earned the same score), they are ranked by their passport number (in accordance with local regulations, all passport numbers are distinct).

In the first contest, the participant on the 100-th place scored a points. Also, the jury checked all participants from the 1-st to the 100-th place (inclusive) in the first contest and found out that all of them have at least b points in the second contest.

Similarly, for the second contest, the participant on the 100-th place has c points. And the jury checked that all the participants from the 1-st to the 100-th place (inclusive) have at least d points in the first contest.

After two contests, all participants are ranked by their total score in two contests in non-increasing order. When participants have the same total score, tie-breaking with passport numbers is used. The cutoff score to qualify to the final stage is the total score of the participant on the 100-th place.

Given integers a, b, c, d, please help the jury determine the smallest possible value of the cutoff score.

Input

You need to process t test cases.

The first line contains an integer t (1 ≤ t ≤ 3025) — the number of test cases. Then descriptions of t test cases follow.

The first line of each test case contains four integers a, b, c, d (0 ≤ a,\,b,\,c,\,d ≤ 9; d ≤ a; b ≤ c).

One can show that for any test case satisfying the constraints above, there is at least one olympiad scenario possible.

Output

For each test case print a single integer — the smallest possible cutoff score in some olympiad scenario satisfying the given information.

Example

Input

2
1 2 2 1
4 8 9 2

Output

3
12

Note

For the first test case, consider the following olympiad scenario: there are 101 participants in the elimination stage, each having 1 point for the first contest and 2 points for the second contest. Hence the total score of the participant on the 100-th place is 3.

For the second test case, consider the following olympiad scenario:

  * there are 50 participants with points 5 and 9 for the first and second contest respectively;
  * 50 participants with points 4 and 8 for the first and second contest respectively;
  * and 50 participants with points 2 and 9 for the first and second contest respectively.

Hence the total point score of the participant on the 100-th place is 12.

### Response

```cpp
#include <bits/stdc++.h>
int t, a, b, c, d;
inline int max(int a, int b) { return a > b ? a : b; }
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    printf("%d\n", max(a + b, c + d));
  }
  return 0;
}

```


### Prompt

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

Petya loves computer games. Finally a game that he's been waiting for so long came out!

The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values of <image> for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.

At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.

Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.

Input

The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal.

The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-th skill of the character.

Output

The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units.

Examples

Input

2 4
7 9

Output

2

Input

3 8
17 15 19

Output

5

Input

2 2
99 100

Output

20

Note

In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to  lfloor frac{100}{10} rfloor + lfloor frac{100}{10} rfloor = 10 + 10 =  20.

In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is <image>.

In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to <image>.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int sum = 0, count[10];
  memset(count, 0, sizeof(int) * 10);
  while (n--) {
    int m;
    scanf("%d", &m);
    sum += m / 10;
    if (m % 10 != 0) count[m % 10]++;
    count[0] += (100 - m) / 10;
  }
  int cur = 10 - 1;
  while (k >= (10 - cur) && cur >= 0) {
    while (count[cur] <= 0 && cur >= 0) cur--;
    if (k >= (10 - cur) && cur >= 0) {
      count[cur]--;
      sum++;
      k -= 10 - cur;
    }
  }
  printf("%d", sum);
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Do you know the famous series of children's books named "Where's Wally"? Each of the books contains a variety of pictures of hundreds of people. Readers are challenged to find a person called Wally in the crowd.

We can consider "Where's Wally" as a kind of pattern matching of two-dimensional graphical images. Wally's figure is to be looked for in the picture. It would be interesting to write a computer program to solve "Where's Wally", but this is not an easy task since Wally in the pictures may be slightly different in his appearances. We give up the idea, and make the problem much easier to solve. You are requested to solve an easier version of the graphical pattern matching problem.

An image and a pattern are given. Both are rectangular matrices of bits (in fact, the pattern is always square-shaped). 0 means white, and 1 black. The problem here is to count the number of occurrences of the pattern in the image, i.e. the number of squares in the image exactly matching the pattern. Patterns appearing rotated by any multiples of 90 degrees and/or turned over forming a mirror image should also be taken into account.

Input

The input is a sequence of datasets each in the following format.

w h p
image data
pattern data

The first line of a dataset consists of three positive integers w, h and p. w is the width of the image and h is the height of the image. Both are counted in numbers of bits. p is the width and height of the pattern. The pattern is always square-shaped. You may assume 1 ≤ w ≤ 1000, 1 ≤ h ≤ 1000, and 1 ≤ p ≤ 100.

The following h lines give the image. Each line consists of ⌈w/6⌉ (which is equal to &⌊(w+5)/6⌋) characters, and corresponds to a horizontal line of the image. Each of these characters represents six bits on the image line, from left to right, in a variant of the BASE64 encoding format. The encoding rule is given in the following table. The most significant bit of the value in the table corresponds to the leftmost bit in the image. The last character may also represent a few bits beyond the width of the image; these bits should be ignored.

character| value (six bits)
---|---
A-Z| 0-25
a-z| 26-51
0-9| 52-61
+| 62
/| 63

The last p lines give the pattern. Each line consists of ⌈p/6⌉ characters, and is encoded in the same way as the image.

A line containing three zeros indicates the end of the input. The total size of the input does not exceed two megabytes.

Output

For each dataset in the input, one line containing the number of matched squares in the image should be output. An output line should not contain extra characters.

Two or more matching squares may be mutually overlapping. In such a case, they are counted separately. On the other hand, a single square is never counted twice or more, even if it matches both the original pattern and its rotation, for example.

Example

Input

48 3 3
gAY4I4wA
gIIgIIgg
w4IAYAg4
g
g
w
153 3 3
kkkkkkkkkkkkkkkkkkkkkkkkkg
SSSSSSSSSSSSSSSSSSSSSSSSSQ
JJJJJJJJJJJJJJJJJJJJJJJJJI
g
Q
I
1 1 2
A
A
A
384 3 2
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
BCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/A
CDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/AB
A
A
0 0 0

Output

8
51
0
98

### Response

```cpp
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

const ull B1 = 9973;
const ull B2 = MOD;

int W,H,P;
ull bin_table[64][6],image_table[1000][1000],pattern_table[8][1000][1000],hash_table[1000][1000],tmp[1000][1000];
char buf[1000];
map<ull,bool> MAP;

int getNUM(char ch){

	if(ch >= 'A' && ch <= 'Z'){
		return ch-'A';
	}else if(ch >= 'a' && ch <= 'z'){
		return ch-'a'+26;
	}else if(ch >= '0' && ch <= '9'){
		return ch-'0'+52;
	}else if(ch == '+'){
		return 62;
	}else{
		return 63;
	}
}

void compute_hash(ull a[1000][1000], int n, int m){

	ull t1 = 1;
	for(int j = 0; j < P; j++)t1 *= B1;

	for(int i = 0; i < n; i++){
		ull e = 0;
		for(int j = 0; j < P; j++)e = e*B1+a[i][j];

		for(int j = 0; j+P <= m; j++){
			tmp[i][j] = e;
			if(j+P < m)e = e*B1-t1*a[i][j]+a[i][j+P];
		}
	}

	ull t2 = 1;
	for(int i = 0; i < P; i++)t2 *= B2;

	for(int j = 0; j+P <= m; j++){
		ull e = 0;
		for(int i = 0; i < P; i++)e = e*B2 + tmp[i][j];

		for(int i = 0; i+P <= n; i++){
			hash_table[i][j] = e;
			if(i+P < n)e = e*B2-t2*tmp[i][j]+tmp[i+P][j];
		}
	}
}

void func(){

	MAP.clear();

	int col;

	for(int row = 0; row < H; row++){
		scanf("%s",buf);
		col = 0;
		for(int num = 0; num < (W+5)/6; num++){
			for(int i = 0; i < 6; i++){
				image_table[row][col++] = bin_table[getNUM(buf[num])][5-i];
			}
		}
	}

	for(int row = 0; row < P; row++){
		scanf("%s",buf);
		col = 0;
		for(int num = 0; num < (P+5)/6; num++){
			for(int i = 0; i < 6; i++){
				pattern_table[0][row][col++] = bin_table[getNUM(buf[num])][5-i];
			}
		}
	}

	for(int i = 1; i <= 3; i++){
		for(int row = 0; row < P; row++){
			for(int col = 0; col < P; col++){
				pattern_table[i][col][(P-1)-row] = pattern_table[i-1][row][col];
			}
		}
	}

	for(int i = 0; i <= 3; i++){
		for(int row = 0; row < P; row++){
			for(int col = 0; col < P; col++){
				pattern_table[4+i][row][(P-1)-col] = pattern_table[i][row][col];
			}
		}
	}

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

		compute_hash(pattern_table[i],P,P);

		auto at = MAP.find(hash_table[0][0]);
		if(at != MAP.end())continue;

		MAP[hash_table[0][0]] = true;
	}

	int ans = 0;
	compute_hash(image_table,H,W);
	for(int row = 0; row+P <= H; row++){
		for(int col = 0; col+P <= W; col++){

			auto at = MAP.find(hash_table[row][col]);
			if(at != MAP.end())ans++;
		}
	}

	printf("%d\n",ans);
}

void make_bin_table(){

	for(int num = 0; num <= 63; num++){
		for(int loop = 0; loop < 6; loop++){
			if(num & (1 << loop)){
				bin_table[num][loop] = 1;
			}else{
				bin_table[num][loop] = 0;
			}
		}
	}
}

int main(){

	make_bin_table();

	while(true){
		scanf("%d %d %d",&W,&H,&P);
		if(W == 0 && H == 0 && P == 0)break;

		func();
	}

	return 0;
}

```


### Prompt

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

Takahashi has a string S consisting of lowercase English letters.

Starting with this string, he will produce a new one in the procedure given as follows.

The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following:

* If T_i = 1: reverse the string S.

* If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.

* If F_i = 1 : Add C_i to the beginning of the string S.
* If F_i = 2 : Add C_i to the end of the string S.

Help Takahashi by finding the final string that results from the procedure.

Constraints

* 1 \leq |S| \leq 10^5
* S consists of lowercase English letters.
* 1 \leq Q \leq 2 \times 10^5
* T_i = 1 or 2.
* F_i = 1 or 2, if provided.
* C_i is a lowercase English letter, if provided.

Input

Input is given from Standard Input in the following format:

S
Q
Query_1
:
Query_Q

In the 3-rd through the (Q+2)-th lines, Query_i is one of the following:

1

which means T_i = 1, and:

2 F_i C_i

which means T_i = 2.

Output

Print the resulting string.

Examples

Input

a
4
2 1 p
1
2 2 c
1

Output

cpa

Input

a
6
2 2 a
2 1 b
1
2 2 c
1
1

Output

aabc

Input

y
1
2 1 x

Output

xy

### Response

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

int main() {

	string s;
	cin >> s;
	deque <char> a;
	bool parity=0;
	int q;
	cin >> q;
	for(auto i : s) a.push_front(i);
	for(int i=0; i<q; i++){
		int t;
		cin >> t;
		if(t==1) parity ^=1;
		if(t==2){
			int f;
			char c;
			cin >> f >> c;
			if(f==1 ^ parity) a.push_back(c);
			else a.push_front(c);
		}
	}
	if(parity) for(auto i=a.begin(); i!=a.end(); i++) cout << *i;
	else for(auto i=a.rbegin(); i!=a.rend(); i++) cout << *i;
	cout << endl;
}
```


### Prompt

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

Petya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note that the positions are indexed but the glasses are not.

First Petya puts a marble under the glass in position s. Then he performs some (possibly zero) shuffling operations. One shuffling operation means moving the glass from the first position to position p1, the glass from the second position to position p2 and so on. That is, a glass goes from position i to position pi. Consider all glasses are moving simultaneously during one shuffling operation. When the glasses are shuffled, the marble doesn't travel from one glass to another: it moves together with the glass it was initially been put in.

After all shuffling operations Petya shows Vasya that the ball has moved to position t. Vasya's task is to say what minimum number of shuffling operations Petya has performed or determine that Petya has made a mistake and the marble could not have got from position s to position t.

Input

The first line contains three integers: n, s, t (1 ≤ n ≤ 105; 1 ≤ s, t ≤ n) — the number of glasses, the ball's initial and final position. The second line contains n space-separated integers: p1, p2, ..., pn (1 ≤ pi ≤ n) — the shuffling operation parameters. It is guaranteed that all pi's are distinct.

Note that s can equal t.

Output

If the marble can move from position s to position t, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position t. If it is impossible, print number -1.

Examples

Input

4 2 1
2 3 4 1

Output

3

Input

4 3 3
4 1 3 2

Output

0

Input

4 3 4
1 2 3 4

Output

-1

Input

3 1 3
2 1 3

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, count = 0, s, t, temp, flag = 0, p;
  cin >> n;
  long long a[n];
  cin >> s >> t;
  p = s;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  temp = a[t - 1];
  if (s == t)
    cout << "0" << endl;
  else {
    while (1) {
      i = a[s - 1];
      if (a[i - 1] == temp) {
        if (count == 0 && s == t)
          cout << "0" << endl;
        else
          cout << count + 1 << endl;
        break;
      } else if (a[s - 1] == s || a[s - 1] == p) {
        flag = 1;
        break;
      }
      s = i;
      count++;
    }
    if (flag == 1) cout << "-1" << endl;
  }
}

```


### Prompt

Please create a solution in CPP to the following problem:

Input

The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").

Output

Output a single integer.

Examples

Input

A221033

Output

21

Input

A223635

Output

22

Input

A232726

Output

23

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char a[7];
int res = 1;
int main(int argc, char* argv[]) {
  scanf("%s", &a);
  for (int i = 1; i < 7; i++)
    if (a[i] == '1')
      res += 10;
    else
      res += a[i] - '0';
  printf("%d\n", res);
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).

You have m different coupons that allow you to buy chocolate bars. i-th coupon allows you to buy q_i chocolate bars while you have to pay only for the q_i - 1 most expensive ones (so, the cheapest bar of those q_i bars is for free).

You can use only one coupon; if you use coupon i, you have to choose q_i bars and buy them using the coupon, and buy all the remaining n - q_i bars without any discounts.

To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.

Input

The first line contains one integer n (2 ≤ n ≤ 3 ⋅ 10^5) — the number of chocolate bars in the shop.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is the cost of i-th chocolate bar.

The third line contains one integer m (1 ≤ m ≤ n - 1) — the number of coupons you have.

The fourth line contains m integers q_1, q_2, ..., q_m (2 ≤ q_i ≤ n), where q_i is the number of chocolate bars you have to buy using i-th coupon so that the least expensive of them will be for free. All values of q_i are pairwise distinct.

Output

Print m integers, i-th of them should be the minimum amount of money you have to pay if you buy q_i bars with i-th coupon, and all the remaining bars one by one for their full price.

Example

Input

7
7 1 3 1 4 10 8
2
3 4

Output

27
30

Note

Consider the first example.

If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.

If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int p, n, l, i;
  cin >> n;
  long long int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> l;
  long long int k[l];
  sort(a, a + n);
  for (i = 1; i < n; i++) a[i] = a[i] + a[i - 1];
  a[-1] = 0;
  for (i = 0; i < l; i++) {
    cin >> p;
    cout << (a[n - 1] - a[n - p] + a[n - p - 1]) << endl;
  }
}

```


### Prompt

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

Sereja has two sequences a and b and number p. Sequence a consists of n integers a1, a2, ..., an. Similarly, sequence b consists of m integers b1, b2, ..., bm. As usual, Sereja studies the sequences he has. Today he wants to find the number of positions q (q + (m - 1)·p ≤ n; q ≥ 1), such that sequence b can be obtained from sequence aq, aq + p, aq + 2p, ..., aq + (m - 1)p by rearranging elements.

Sereja needs to rush to the gym, so he asked to find all the described positions of q.

Input

The first line contains three integers n, m and p (1 ≤ n, m ≤ 2·105, 1 ≤ p ≤ 2·105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). The next line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 109).

Output

In the first line print the number of valid qs. In the second line, print the valid values in the increasing order.

Examples

Input

5 3 1
1 2 3 2 1
1 2 3

Output

2
1 3

Input

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

Output

2
1 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int N = 200020;
int n, m, p;
int a[N], b[N];
int aCnt[N], bCnt[N];
map<int, int> M;
int id;
vector<int> ans;
int main() {
  cin >> n >> m >> p;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  M.clear();
  id = 0;
  sort(b + 1, b + 1 + m);
  for (int i = 1; i <= m; i++)
    if (!M[b[i]]) M[b[i]] = ++id;
  for (int i = 1; i <= m; i++) bCnt[M[b[i]]]++;
  ans.clear();
  for (int i = 1; i <= p; i++) {
    if (i + (long long)(m - 1) * p > n) break;
    int all = id, flag = 0;
    memset(aCnt, 0, sizeof(aCnt));
    for (int k = i; k <= n; k += p) {
      int v = a[k];
      if (M.find(v) == M.end())
        ++flag;
      else {
        int tmp = M[v];
        aCnt[tmp]++;
        if (aCnt[tmp] == bCnt[tmp])
          all--;
        else if (aCnt[tmp] == bCnt[tmp] + 1)
          all++;
      }
      if (!all && !flag) ans.push_back(k - (m - 1) * p);
      if (k >= i + (m - 1) * p) {
        v = a[k - (m - 1) * p];
        if (M.find(v) == M.end())
          --flag;
        else {
          int tmp = M[v];
          aCnt[tmp]--;
          if (aCnt[tmp] == bCnt[tmp])
            all--;
          else if (aCnt[tmp] == bCnt[tmp] - 1)
            all++;
        }
      }
    }
  }
  int sz = (int)ans.size();
  cout << sz << endl;
  sort(ans.begin(), ans.end());
  for (int i = 0; i < sz; i++) cout << ans[i] << " ";
  if (sz) cout << endl;
}

```


### Prompt

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

Jack loved his house very much, because his lovely cats take a nap on the wall of his house almost every day. Jack loved cats very much.

Jack decided to keep an observation diary of the cats as a free study during the summer vacation. After observing for a while, he noticed an interesting feature of the cats.

The fence has a width of W [scale], and the cats take a nap side by side. Since each cat has a different body size, the width required for a nap is also different. I came to take a nap. Cats take a nap there if they have a place to sleep. However, if there are multiple such places, they take a nap on the left side, and if there is not enough width, they give up and go home. Take a nap for a while. When the nap cat gets up, it jumps off the wall and goes somewhere.

Jack observed the cats and wrote down their behavior in a notebook. However, it is very difficult to compile this record because so many cats were taking a nap. Writing a program, the cats Help me find a place to take a nap.

Input

The input file contains multiple datasets. The first line of each dataset contains two integers, each representing the width W of the fence and the number of lines Q that follow.

The following Q line is given the observation record of the cat. Each line follows one of the following formats.

s [id] [w]

w [id]

The former is a cat's sleep record, which indicates that the cat came to take a nap. Id is an integer that represents the cat's name, and w is the width [scale] that the cat needs to take a nap.

The latter is a wakeup record of the cat, indicating that a cat with the name id has occurred.

This record is given in chronological order.

No cat will take a nap more than once. Also, Jack's record shall be consistent. That is, if a cat can take a nap against a cat's sleep record, then Only if the cat's wakeup record is given (on a later line).

You can assume that W, Q ≤ 100.

When both W and Q are 0, it indicates the end of input. Do not output to this dataset.

Output

Output one line each time a sleep record of input is given. This line must contain a number that indicates the position of the cat if it can take a nap. The cat starts at the left edge of the wall and is b [scale. ] To b + w [shaku], output b. If the cat could not take a nap, output "impossible".

Print "END" at the end of the dataset.

Example

Input

4 6
s 0 2
s 1 3
s 2 1
w 0
s 3 3
s 4 2
3 3
s 0 1
s 1 1
s 2 1
0 0

Output

0
impossible
2
impossible
0
END
0
1
2
END

### Response

```cpp
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int w, q;
        cin >> w >> q;
        if(w == 0)
            return 0;

        vector<int> wall(w, -1);
        for(int i=0; i<q; ++i){
            char c;
            int id;
            cin >> c >> id;
            if(c == 's'){
                int size;
                cin >> size;
                bool ok = false;
                for(int i=0; i<w-size+1; ++i){
                    int j;
                    for(j=0; j<size; ++j){
                        if(wall[i+j] != -1){
                            i += j;
                            break;
                        }
                    }
                    if(j == size){
                        for(j=0; j<size; ++j)
                            wall[i+j] = id;
                        cout << i << endl;
                        ok = true;
                        break;
                    }
                }
                if(!ok)
                    cout << "impossible" << endl;
            }else{
                for(int i=0; i<w; ++i){
                    if(wall[i] == id)
                        wall[i] = -1;
                }
            }
        }

        cout << "END" << endl;
    }
}
```


### Prompt

Create a solution in cpp for the following problem:

Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1 ≤ pi ≤ n).

Little penguin Polo loves walking around this village. The walk looks like that. First he stands by a house number x. Then he goes to the house whose number is written on the plaque of house x (that is, to house px), then he goes to the house whose number is written on the plaque of house px (that is, to house ppx), and so on.

We know that:

  1. When the penguin starts walking from any house indexed from 1 to k, inclusive, he can walk to house number 1.
  2. When the penguin starts walking from any house indexed from k + 1 to n, inclusive, he definitely cannot walk to house number 1.
  3. When the penguin starts walking from house number 1, he can get back to house number 1 after some non-zero number of walks from a house to a house.

You need to find the number of ways you may write the numbers on the houses' plaques so as to fulfill the three above described conditions. Print the remainder after dividing this number by 1000000007 (109 + 7).

Input

The single line contains two space-separated integers n and k (1 ≤ n ≤ 1000, 1 ≤ k ≤ min(8, n)) — the number of the houses and the number k from the statement.

Output

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

Examples

Input

5 2

Output

54

Input

7 4

Output

1728

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const int MaxN = 100005;
const int Mod = 1000000007;
long long mypow(long long x, int n) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) ans = ans * x % Mod;
    x = x * x % Mod;
    n >>= 1;
  }
  return ans;
}
int main() {
  int n, k;
  while (2 == scanf("%d%d", &n, &k)) {
    long long ans = mypow(n - k, n - k);
    ans = ans * mypow(k, k - 1) % Mod;
    cout << ans << endl;
  }
  return 0;
}

```


### Prompt

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

One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!

Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.

In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals n, then the player wins, otherwise the player loses.

The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals n.

Input

The only line contains n (1 ≤ n ≤ 25) — the required sum of points.

Output

Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.

Examples

Input

12

Output

4

Input

20

Output

15

Input

10

Output

0

Note

In the first sample only four two's of different suits can earn the required sum of points.

In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.

In the third sample there is no card, that would add a zero to the current ten points.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int n;
  while (~scanf("%d", &n)) {
    if (n <= 10 || n > 21)
      printf("0\n");
    else if (n == 20)
      printf("15\n");
    else
      printf("4\n");
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Limak is a big polar bear. He prepared n problems for an algorithmic contest. The i-th problem has initial score pi. Also, testers said that it takes ti minutes to solve the i-th problem. Problems aren't necessarily sorted by difficulty and maybe harder problems have smaller initial score but it's too late to change it — Limak has already announced initial scores for problems. Though it's still possible to adjust the speed of losing points, denoted by c in this statement.

Let T denote the total number of minutes needed to solve all problems (so, T = t1 + t2 + ... + tn). The contest will last exactly T minutes. So it's just enough to solve all problems.

Points given for solving a problem decrease linearly. Solving the i-th problem after x minutes gives exactly <image> points, where <image> is some real constant that Limak must choose.

Let's assume that c is fixed. During a contest a participant chooses some order in which he or she solves problems. There are n! possible orders and each of them gives some total number of points, not necessarily integer. We say that an order is optimal if it gives the maximum number of points. In other words, the total number of points given by this order is greater or equal than the number of points given by any other order. It's obvious that there is at least one optimal order. However, there may be more than one optimal order.

Limak assumes that every participant will properly estimate ti at the very beginning and will choose some optimal order. He also assumes that testers correctly predicted time needed to solve each problem.

For two distinct problems i and j such that pi < pj Limak wouldn't be happy to see a participant with strictly more points for problem i than for problem j. He calls such a situation a paradox.

It's not hard to prove that there will be no paradox for c = 0. The situation may be worse for bigger c. What is the maximum real value c (remember that <image>) for which there is no paradox possible, that is, there will be no paradox for any optimal order of solving problems?

It can be proved that the answer (the maximum c as described) always exists.

Input

The first line contains one integer n (2 ≤ n ≤ 150 000) — the number of problems.

The second line contains n integers p1, p2, ..., pn (1 ≤ pi ≤ 108) — initial scores.

The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 108) where ti is the number of minutes needed to solve the i-th problem.

Output

Print one real value on a single line — the maximum value of c that <image> and there is no optimal order with a paradox. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct if <image>.

Examples

Input

3
4 3 10
1 1 8

Output

0.62500000000

Input

4
7 20 15 10
7 20 15 10

Output

0.31901840491

Input

2
10 20
10 1

Output

1.00000000000

Note

In the first sample, there are 3 problems. The first is (4, 1) (initial score is 4 and required time is 1 minute), the second problem is (3, 1) and the third one is (10, 8). The total time is T = 1 + 1 + 8 = 10.

Let's show that there is a paradox for c = 0.7. Solving problems in order 1, 2, 3 turns out to give the best total score, equal to the sum of:

  1. solved 1 minute after the start: <image>
  2. solved 2 minutes after the start: <image>
  3. solved 10 minutes after the start: <image>

So, this order gives 3.72 + 2.58 + 3 = 9.3 points in total and this is the only optimal order (you can calculate total scores for other 5 possible orders too see that they are lower). You should check points for problems 1 and 3 to see a paradox. There is 4 < 10 but 3.72 > 3. It turns out that there is no paradox for c = 0.625 but there is a paradox for any bigger c.

In the second sample, all 24 orders are optimal.

In the third sample, even for c = 1 there is no paradox.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int res = 0, flag = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    res = res * 10 + ch - '0';
    ch = getchar();
  }
  return res * flag;
}
struct test {
  int p, t, sp;
  int l, r;
  double val;
} x[150001];
int n, lst = 1, tp[150001];
long long T[150001];
double l, r = 1.0, mid, ans, maxx[150001];
inline bool cmp(test x1, test x2) { return x1.val > x2.val; }
inline bool cmp2(test x1, test x2) { return x1.p < x2.p; }
inline void update(int x, double v) {
  for (; x <= tp[0]; x += ((x) & (-(x)))) maxx[x] = max(maxx[x], v);
}
inline double query(int x) {
  double res = 0;
  for (; x; x -= ((x) & (-(x)))) res = max(res, maxx[x]);
  return res;
}
bool check(double c) {
  for (register int i = 1; i <= tp[0]; ++i) maxx[i] = 0.0;
  for (register int i = 1; i <= n; ++i) {
    if (query(x[i].sp - 1) >
        1.0 * x[i].p * (1.0 - c * ((double)T[x[i].r]) / ((double)T[n])))
      return 0;
    update(x[i].sp,
           1.0 * x[i].p *
               (1.0 - c * ((double)T[x[i].l - 1] + x[i].t) / ((double)T[n])));
  }
  return 1;
}
int main() {
  n = read();
  for (register int i = 1; i <= n; ++i) tp[i] = x[i].p = read();
  for (register int i = 1; i <= n; ++i) {
    x[i].t = read();
    x[i].val = 1.0 * (double)x[i].p / (double)x[i].t;
  }
  sort(x + 1, x + n + 1, cmp);
  sort(tp + 1, tp + n + 1);
  tp[0] = unique(tp + 1, tp + n + 1) - tp - 1;
  for (register int i = 1; i <= n; ++i) {
    T[i] = T[i - 1] + x[i].t;
    x[i].sp = lower_bound(tp + 1, tp + tp[0] + 1, x[i].p) - tp;
  }
  for (register int i = 2; i <= n; ++i)
    if (x[i].val != x[i - 1].val) {
      for (register int j = lst; j < i; ++j) {
        x[j].l = lst;
        x[j].r = i - 1;
      }
      lst = i;
    }
  for (register int i = lst; i <= n; ++i) {
    x[i].l = lst;
    x[i].r = n;
  }
  sort(x + 1, x + n + 1, cmp2);
  while (r - l > (1e-7)) {
    mid = (l + r) / 2.0;
    if (check(mid))
      l = ans = mid;
    else
      r = mid;
  }
  printf("%.7lf\n", ans);
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Once upon a time, there was a traveler.

He plans to travel using stagecoaches (horse wagons). His starting point and destination are fixed, but he cannot determine his route. Your job in this problem is to write a program which determines the route for him.

There are several cities in the country, and a road network connecting them. If there is a road between two cities, one can travel by a stagecoach from one of them to the other. A coach ticket is needed for a coach ride. The number of horses is specified in each of the tickets. Of course, with more horses, the coach runs faster.

At the starting point, the traveler has a number of coach tickets. By considering these tickets and the information on the road network, you should find the best possible route that takes him to the destination in the shortest time. The usage of coach tickets should be taken into account.

The following conditions are assumed.

* A coach ride takes the traveler from one city to another directly connected by a road. In other words, on each arrival to a city, he must change the coach.
* Only one ticket can be used for a coach ride between two cities directly connected by a road.
* Each ticket can be used only once.
* The time needed for a coach ride is the distance between two cities divided by the number of horses.
* The time needed for the coach change should be ignored.

Input

The input consists of multiple datasets, each in the following format. The last dataset is followed by a line containing five zeros (separated by a space).

> n m p a b
>  t1 t2 ... tn
>  x1 y1 z1
>  x2 y2 z2
>  ...
>  xp yp zp
>

Every input item in a dataset is a non-negative integer. If a line contains two or more input items, they are separated by a space.

n is the number of coach tickets. You can assume that the number of tickets is between 1 and 8. m is the number of cities in the network. You can assume that the number of cities is between 2 and 30. p is the number of roads between cities, which may be zero.

a is the city index of the starting city. b is the city index of the destination city. a is not equal to b. You can assume that all city indices in a dataset (including the above two) are between 1 and m.

The second line of a dataset gives the details of coach tickets. ti is the number of horses specified in the i-th coach ticket (1<=i<=n). You can assume that the number of horses is between 1 and 10.

The following p lines give the details of roads between cities. The i-th road connects two cities with city indices xi and yi, and has a distance zi (1<=i<=p). You can assume that the distance is between 1 and 100.

No two roads connect the same pair of cities. A road never connects a city with itself. Each road can be traveled in both directions.

Output

For each dataset in the input, one line should be output as specified below. An output line should not contain extra characters such as spaces.

If the traveler can reach the destination, the time needed for the best route (a route with the shortest time) should be printed. The answer should not have an error greater than 0.001. You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied.

If the traveler cannot reach the destination, the string "`Impossible`" should be printed. One cannot reach the destination either when there are no routes leading to the destination, or when the number of tickets is not sufficient. Note that the first letter of "`Impossible`" is in uppercase, while the other letters are in lowercase.

Example

Input

3 4 3 1 4
3 1 2
1 2 10
2 3 30
3 4 20
2 4 4 2 1
3 1
2 3 3
1 3 3
4 1 2
4 2 5
2 4 3 4 1
5 5
1 2 10
2 3 10
3 4 10
1 2 0 1 2
1
8 5 10 1 5
2 7 1 8 4 5 6 3
1 2 5
2 3 4
3 4 7
4 5 3
1 3 25
2 4 23
3 5 22
1 4 45
2 5 51
1 5 99
0 0 0 0 0

Output

30.000
3.667
Impossible
Impossible
2.856

### Response

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

int main()
{
  int n, m, p, s, g;
  int t[8], edge[30][30];
  double dp[1 << 8][30];
  const double INF = 1e8;

  while(scanf("%d %d %d %d %d", &n, &m, &p, &s, &g), n){
    fill_n( *edge, 30 * 30, -1);
    fill_n( *dp, (1 << 8) * 30, INF);
    s--, g--;

    for(int i = 0; i < n; i++){
      scanf("%d", &t[i]);
    }

    for(int i = 0; i < p; i++){
      int a, b, c;
      scanf("%d %d %d", &a, &b, &c);
      a--, b--;
      edge[a][b] = c;
      edge[b][a] = c;
    }

    for(int i = 0; i < 1 << n; i++){
      dp[i][s] = 0.0;
    }

    double ret = INF;
    for(int i = (1 << n) - 1; i >= 0; i--){ //今のチケット
      ret = min( ret, dp[i][g]);
      for(int j = 0; j < m; j++){ //今の街
        if(dp[i][j] != INF){
          for(int k = 0; k < n; k++){ //使うチケット
            if(i >> k & 1){
              for(int l = 0; l < m; l++){ //次の街
                if(edge[j][l] != -1){
                  dp[i & ~(1 << k)][l] = min( dp[i & ~(1 << k)][l], dp[i][j] + (double)edge[j][l] / t[k]);
                }
              }
            }
          }
        }
      }
    }
    if(ret == INF) puts("Impossible");
    else printf("%.8f\n", ret);
  }
  return 0;
}
```


### Prompt

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

A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B if at least one of the following is true:

  * Employee A is the immediate manager of employee B
  * Employee B has an immediate manager employee C such that employee A is the superior of employee C.

The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager.

Today the company is going to arrange a party. This involves dividing all n employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees A and B such that A is the superior of B.

What is the minimum number of groups that must be formed?

Input

The first line contains integer n (1 ≤ n ≤ 2000) — the number of employees.

The next n lines contain the integers pi (1 ≤ pi ≤ n or pi = -1). Every pi denotes the immediate manager for the i-th employee. If pi is -1, that means that the i-th employee does not have an immediate manager.

It is guaranteed, that no employee will be the immediate manager of him/herself (pi ≠ i). Also, there will be no managerial cycles.

Output

Print a single integer denoting the minimum number of groups that will be formed in the party.

Examples

Input

5
-1
1
2
1
-1

Output

3

Note

For the first example, three groups are sufficient, for example:

  * Employee 1
  * Employees 2 and 4
  * Employees 3 and 5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 150, M = 150, OO = 0x3f3f3f3f;
int n, arr[2005], temp, ans;
void DFS(int u) {
  temp++;
  if (arr[u] == -1) return;
  DFS(arr[u]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", arr + i);
  }
  for (int i = 1; i <= n; ++i) {
    temp = 0;
    DFS(i);
    ans = max(ans, temp);
  }
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

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

Recently, Norge found a string s = s_1 s_2 … s_n consisting of n lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string s. Yes, all (n (n + 1))/(2) of them!

A substring of s is a non-empty string x = s[a … b] = s_{a} s_{a + 1} … s_{b} (1 ≤ a ≤ b ≤ n). For example, "auto" and "ton" are substrings of "automaton".

Shortly after the start of the exercise, Norge realized that his keyboard was broken, namely, he could use only k Latin letters c_1, c_2, …, c_k out of 26.

After that, Norge became interested in how many substrings of the string s he could still type using his broken keyboard. Help him to find this number.

Input

The first line contains two space-separated integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 26) — the length of the string s and the number of Latin letters still available on the keyboard.

The second line contains the string s consisting of exactly n lowercase Latin letters.

The third line contains k space-separated distinct lowercase Latin letters c_1, c_2, …, c_k — the letters still available on the keyboard.

Output

Print a single number — the number of substrings of s that can be typed using only available letters c_1, c_2, …, c_k.

Examples

Input

7 2
abacaba
a b

Output

12

Input

10 3
sadfaasdda
f a d

Output

21

Input

7 1
aaaaaaa
b

Output

0

Note

In the first example Norge can print substrings s[1…2], s[2…3], s[1…3], s[1…1], s[2…2], s[3…3], s[5…6], s[6…7], s[5…7], s[5…5], s[6…6], s[7…7].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  string s, c;
  cin >> s;
  vector<int> v(26, 0);
  for (int i = 0; i < k; i++) {
    cin >> c;
    int idx = (int)(c[0] - 'a');
    v[idx] = 1;
  }
  long long ans = 0;
  long long prev = -1;
  for (long long i = 0; i < n; i++) {
    if (!v[s[i] - 'a']) {
      ans += (i - prev - 1) * (i - prev) / 2;
      prev = i;
    }
  }
  ans += (n - prev - 1) * (n - prev) / 2;
  cout << ans << endl;
}

```


### Prompt

Create a solution in Cpp for the following problem:

We all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name s can transform to another superhero with name t if s can be made equal to t by changing any vowel in s to any other vowel and any consonant in s to any other consonant. Multiple changes can be made.

In this problem, we consider the letters 'a', 'e', 'i', 'o' and 'u' to be vowels and all the other letters to be consonants.

Given the names of two superheroes, determine if the superhero with name s can be transformed to the Superhero with name t.

Input

The first line contains the string s having length between 1 and 1000, inclusive.

The second line contains the string t having length between 1 and 1000, inclusive.

Both strings s and t are guaranteed to be different and consist of lowercase English letters only.

Output

Output "Yes" (without quotes) if the superhero with name s can be transformed to the superhero with name t and "No" (without quotes) otherwise.

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

Examples

Input

a
u

Output

Yes

Input

abc
ukm

Output

Yes

Input

akm
ua

Output

No

Note

In the first sample, since both 'a' and 'u' are vowels, it is possible to convert string s to t.

In the third sample, 'k' is a consonant, whereas 'a' is a vowel, so it is not possible to convert string s to t.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  long long int n, m;
  n = s.length();
  m = t.length();
  long long int i, j, s1 = 0, s2 = 0, t1 = 0, t2 = 0;
  if (n != m) {
    cout << "No";
    exit(0);
  }
  for (i = 0; i < n; i++) {
    if (((s[i] == 'a' || s[i] == 'e' || s[i] == 'o' || s[i] == 'u' ||
          s[i] == 'i') &&
         (t[i] == 'a' || t[i] == 'e' || t[i] == 'o' || t[i] == 'u' ||
          t[i] == 'i')) ||
        ((s[i] != 'a' && s[i] != 'e' && s[i] != 'o' && s[i] != 'u' &&
          s[i] != 'i') &&
         (t[i] != 'a' && t[i] != 'e' && t[i] != 'o' && t[i] != 'u' &&
          t[i] != 'i')))
      continue;
    else {
      cout << "No";
      exit(0);
    }
  }
  cout << "Yes";
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Let's analyze a program written on some strange programming language. The variables in this language have names consisting of 1 to 4 characters, and each character is a lowercase or an uppercase Latin letter, or a digit. There is an extra constraint that the first character should not be a digit.

There are four types of operations in the program, each denoted by one of the characters: $, ^, # or &.

Each line of the program has one of the following formats:

  * <lvalue>=<rvalue>, where <lvalue> and <rvalue> are valid variable names;
  * <lvalue>=<arg1><op><arg2>, where <lvalue>, <arg1> and <arg2> are valid variable names, and <op> is an operation character.

The program is executed line-by-line, and the result of execution is stored in a variable having the name res. If res is never assigned in the program, then the result will be equal to the value of res before running the program.

Two programs are called equivalent if no matter which operations do characters $, ^, # and & denote (but, obviously, performing the same operation on the same arguments gives the same result) and which values do variables have before execution of program, the value of res after running the first program is equal to the value of res after running the second program (the programs are executed independently).

You are given a program consisting of n lines. Your task is to write a program consisting of minimum possible number of lines that is equivalent to the program you are given.

Input

The first line contains one integer n (1 ≤ n ≤ 1000) — the number of lines in the program.

Then n lines follow — the program itself. Each line corresponds to the format described in the statement and has no extra whitespaces.

Output

In the first line print k — the minimum number of lines in the equivalent program.

Then print k lines without any whitespaces — an equivalent program having exactly k lines, in the same format it is described in the statement.

Examples

Input

4
c=aa#bb
d12=c
res=c^d12
tmp=aa$c

Output

2
aaaa=aa#bb
res=aaaa^aaaa

Input

2
max=aaaa$bbbb
min=bbbb^aaaa

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
using pii = pair<int, int>;
using vi = vector<int>;
using ll = long long;
const int N = 3e3;
int nxt = 0, rval;
vector<string> res;
map<string, int> num;
string val[N], back[N];
map<string, string> pro;
const string op = "$^#&";
void split(const string &s, string &l, string &r, string &o, bool &f) {
  for (int i = int(0); i < int(int((s).size())); i++)
    for (int j = int(0); j < int(4); j++)
      if (s[i] == op[j])
        o = op[j], l = s.substr(0, i), r = s.substr(i + 1), f = 0;
}
string process(int x) {
  string s = val[x];
  if (pro.count(s)) return pro[s];
  string l, r, o;
  bool f = 1;
  split(s, l, r, o, f);
  if (f) {
    if (to_string(x) == s) {
      r = pro[s] = back[x];
      if (x == rval) res.emplace_back("res=" + r);
      return r;
    }
    if (x == rval) rval = stoi(s);
    return pro[s] = process(stoi(s));
  }
  string proc = process(stoi(l)) + o + process(stoi(r));
  bool done = pro.count(proc);
  r = done ? pro[proc] : pro[proc] = "a" + to_string(nxt++);
  if (!done) res.emplace_back((x == rval ? "res" : r) + "=" + proc);
  return pro[s] = r;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  string t[n];
  for (int i = int(0); i < int(n); i++) cin >> t[i];
  for (int i = int(0); i < int(n); i++) {
    int x = int(t[i].find('=')), ne, nl, nr;
    string var = t[i].substr(0, x), exp = t[i].substr(x + 1), l, r, o;
    bool f = 1;
    split(exp, l, r, o, f);
    if (f) {
      if (!num.count(exp))
        ne = num[exp] = nxt++, val[ne] = to_string(ne), back[ne] = exp;
      val[num[var] = nxt++] = to_string(num[exp]);
    } else {
      if (!num.count(l))
        nl = num[l] = nxt++, val[nl] = to_string(nl), back[nl] = l;
      if (!num.count(r))
        nr = num[r] = nxt++, val[nr] = to_string(nr), back[nr] = r;
      val[num[var] = nxt++] = to_string(num[l]) + o + to_string(num[r]);
    }
  }
  if (!num.count("res")) return cout << "0\n", 0;
  nxt = 0, rval = num["res"], process(rval);
  int sz = int((res).size());
  if (sz == 1 && res[0] == "res=res") return cout << "0\n", 0;
  cout << sz << '\n';
  for (int j = int(0); j < int(sz); j++) cout << res[j] << '\n';
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

The Little Elephant has two permutations a and b of length n, consisting of numbers from 1 to n, inclusive. Let's denote the i-th (1 ≤ i ≤ n) element of the permutation a as ai, the j-th (1 ≤ j ≤ n) element of the permutation b — as bj.

The distance between permutations a and b is the minimum absolute value of the difference between the positions of the occurrences of some number in a and in b. More formally, it's such minimum |i - j|, that ai = bj.

A cyclic shift number i (1 ≤ i ≤ n) of permutation b consisting from n elements is a permutation bibi + 1... bnb1b2... bi - 1. Overall a permutation has n cyclic shifts.

The Little Elephant wonders, for all cyclic shifts of permutation b, what is the distance between the cyclic shift and permutation a?

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the size of the permutations. The second line contains permutation a as n distinct numbers from 1 to n, inclusive. The numbers are separated with single spaces. The third line contains permutation b in the same format.

Output

In n lines print n integers — the answers for cyclic shifts. Print the answers to the shifts in the order of the shifts' numeration in permutation b, that is, first for the 1-st cyclic shift, then for the 2-nd, and so on.

Examples

Input

2
1 2
2 1

Output

1
0

Input

4
2 1 3 4
3 4 2 1

Output

2
1
0
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int gdzie[200005];
int mini[200005];
vector<int> pra[200005];
vector<int> lew[200005];
int odp[200005];
vector<pair<int, int> > stos;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i <= n - 1; i++) {
    cin >> a[i];
    a[i]--;
    gdzie[a[i]] = i;
    odp[i] = 200005;
  }
  int l;
  int x;
  for (int i = 0; i <= n - 1; i++) {
    cin >> l;
    l--;
    if (gdzie[l] < i) {
      x = n + gdzie[l] - i;
      pra[x].push_back(n - 1 - gdzie[l]);
      lew[x + n].push_back(gdzie[l]);
    } else {
      x = gdzie[l] - i;
      pra[x].push_back(n - 1 - gdzie[l]);
      lew[x + n].push_back(gdzie[l]);
    }
  }
  int maxi;
  int cos;
  for (int i = 0; i < 2 * n; i++) {
    maxi = -1;
    for (int j = 0; j < pra[i].size(); j++) {
      maxi = max(maxi, pra[i][j]);
    }
    if (maxi >= 0) {
      stos.push_back(make_pair(i, maxi));
    }
    while (stos.size() &&
           stos[stos.size() - 1].first + stos[stos.size() - 1].second < i) {
      stos.pop_back();
    }
    cos = i;
    if (cos >= n) {
      cos -= n;
    }
    if (stos.size()) {
      odp[cos] = min(odp[cos], i - stos[stos.size() - 1].first);
    }
  }
  stos.clear();
  for (int i = 2 * n - 1; i >= 0; i--) {
    maxi = -1;
    for (int j = 0; j < lew[i].size(); j++) {
      maxi = max(maxi, lew[i][j]);
    }
    if (maxi >= 0) {
      stos.push_back(make_pair(i, maxi));
    }
    while (stos.size() &&
           stos[stos.size() - 1].first - stos[stos.size() - 1].second > i) {
      stos.pop_back();
    }
    cos = i;
    if (cos >= n) {
      cos -= n;
    }
    if (stos.size()) {
      odp[cos] = min(odp[cos], stos[stos.size() - 1].first - i);
    }
  }
  cout << odp[0] << endl;
  for (int i = 1; i <= n - 1; i++) {
    cout << odp[n - i] << endl;
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.

Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).

Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.

The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.

Input

The first line contains three integers n, x0 и y0 (1 ≤ n ≤ 1000,  - 104 ≤ x0, y0 ≤ 104) — the number of stormtroopers on the battle field and the coordinates of your gun.

Next n lines contain two integers each xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.

Output

Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.

Examples

Input

4 0 0
1 1
2 2
2 0
-1 -1

Output

2

Input

2 1 2
1 1
1 0

Output

1

Note

Explanation to the first and second samples from the statement, respectively:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
  double v;
  node() {
    x = y = 0;
    v = -99999999;
  }
};
bool cmp(node a, node b) {
  if (a.x != b.x) return a.x < b.x;
  return a.y < b.y;
}
int cacu(int a, int b) {
  int temp;
  while (a != 0) {
    temp = b % a;
    b = a;
    a = temp;
  }
  return b;
}
int main() {
  int i, j, k;
  node a[1005];
  int x, y, x0, y0;
  int n;
  int zui;
  scanf("%d%d%d", &n, &x, &y);
  for (i = 0; i < n; i++) {
    scanf("%d%d", &x0, &y0);
    a[i].x = x0 - x;
    a[i].y = y0 - y;
    if (a[i].x == 0 && a[i].y == 0) {
      for (j = 0; j < i; j++) {
        if (a[j].x || a[j].y) {
          a[i].x = a[j].x;
          a[i].y = a[j].y;
          break;
        }
      }
    } else {
      if (a[i].x == 0) a[i].y = 1;
      if (a[i].y == 0) a[i].x = 1;
    }
    if (a[i].x && a[i].y) {
      zui = cacu(a[i].x, a[i].y);
      a[i].x = a[i].x / zui;
      a[i].y = a[i].y / zui;
    }
  }
  for (i = 0; i < n; i++) {
    if (a[i].x == 0 && a[i].y == 0) {
      for (j = 0; j < n; j++) {
        if (a[j].x || a[j].y) {
          a[i].x = a[j].x;
          a[i].y = a[j].y;
          break;
        }
      }
    }
  }
  sort(a, a + n, cmp);
  int count = 1;
  for (i = 0; i < n - 1; i++) {
    if (a[i].x != a[i + 1].x || a[i].y != a[i + 1].y) {
      count++;
    }
  }
  printf("%d\n", count);
}

```


### Prompt

Create a solution in Cpp for the following problem:

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

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

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

Input

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

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

Output

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

Examples

Input

5 4
5 -1 3 4 -1

Output

5

Input

3 0
-1 2 -3

Output

4

Input

4 -1
-2 1 -2 3

Output

3

Note

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, t;
long long solve(vector<long long> cis) {
  if (cis.size() == 0) return 0;
  if (cis.size() == 1) return cis[0] < t ? 1 : 0;
  if (cis.size() == 2) {
    return (cis[0] < t ? 1 : 0) + (cis[0] + cis[1] < t ? 1 : 0) +
           (cis[1] < t ? 1 : 0);
  }
  vector<long long> le, ri;
  long long mid = cis.size() / 2;
  vector<long long> ple, pri;
  long long ss = 0, ssb = 0;
  for (long long(a) = 0; (a) < (cis.size()); (a)++) {
    if (a < mid) le.push_back(cis[a]);
    if (a > mid) ri.push_back(cis[a]);
    ss += cis[a];
    if (a >= mid) pri.push_back(ss);
  }
  for (int a = cis.size() - 1; a >= 0; a--) {
    ssb += cis[a];
    if (a <= mid) ple.push_back(ssb);
  }
  sort(pri.begin(), pri.end());
  sort(ple.begin(), ple.end());
  long long i = 0, j = pri.size() - 1;
  long long sol = 0;
  while (i < ple.size() && j >= 0) {
    while (ple[i] + pri[j] >= t + ss && j >= 0) j--;
    if (ple[i] + pri[j] < t + ss && j >= 0) {
      sol += j + 1;
    }
    i++;
  }
  long long left = solve(le);
  long long right = solve(ri);
  return sol + left + right;
}
int main() {
  cin >> n >> t;
  vector<long long> cis;
  for (long long(a) = 0; (a) < (n); (a)++) {
    long long pr;
    cin >> pr;
    cis.push_back(pr);
  }
  printf("%lli\n", solve(cis));
  return 0;
}

```