### Prompt

Generate a CPP solution to the following problem:

Consider the following game for two players. There is one white token and some number of black tokens. Each token is placed on a plane in a point with integer coordinates x and y.

The players take turn making moves, white starts. On each turn, a player moves all tokens of their color by 1 to up, down, left or right. Black player can choose directions for each token independently.

After a turn of the white player the white token can not be in a point where a black token is located. There are no other constraints on locations of the tokens: positions of black tokens can coincide, after a turn of the black player and initially the white token can be in the same point with some black point. If at some moment the white player can't make a move, he loses. If the white player makes 10100500 moves, he wins.

You are to solve the following problem. You are given initial positions of all black tokens. It is guaranteed that initially all these positions are distinct. In how many places can the white token be located initially so that if both players play optimally, the black player wins?

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of black points.

The (i + 1)-th line contains two integers xi, yi ( - 105 ≤ xi, yi, ≤ 105) — the coordinates of the point where the i-th black token is initially located.

It is guaranteed that initial positions of black tokens are distinct.

Output

Print the number of points where the white token can be located initially, such that if both players play optimally, the black player wins.

Examples

Input

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

Output

4

Input

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

Output

2

Input

16
2 1
1 2
-1 1
0 1
0 0
1 1
2 -1
2 0
1 0
-1 -1
1 -1
2 2
0 -1
-1 0
0 2
-1 2

Output

4

Note

In the first and second examples initial positions of black tokens are shown with black points, possible positions of the white token (such that the black player wins) are shown with white points.

The first example: <image>

The second example: <image>

In the third example the white tokens should be located in the inner square 2 × 2, to make the black player win. <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read(T &x) {
  char c = getchar();
  bool f = 0;
  x = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f) x = -x;
  return x;
}
template <typename T, typename... Args>
inline void read(T &x, Args &...args) {
  read(x);
  read(args...);
}
template <typename T>
inline void write(T x) {
  if (x < 0)
    putchar('-'), write(-x);
  else {
    if (x > 9) write(x / 10);
    putchar('0' + x % 10);
  }
}
int N;
struct Z {
  int x, y;
} A[100005];
long long proc() {
  vector<Z> arr;
  for (int i = 1; i <= N; i++)
    if (A[i].x + A[i].y & 1) arr.push_back({A[i].x + A[i].y, A[i].x - A[i].y});
  sort((arr).begin(), (arr).end(),
       [](const Z &a, const Z &b) { return a.x < b.x; });
  int n = ((int)(arr).size());
  struct RANGE {
    int la, lb;
    int ra, rb;
  };
  vector<RANGE> box(n);
  int mn = 2e9, mx = -2e9;
  for (int i = 0; i < n; i++) {
    mn = min(mn, arr[i].y);
    mx = max(mx, arr[i].y);
    box[i].la = mn, box[i].lb = mx;
  }
  mn = 2e9, mx = -2e9;
  for (int i = n; i--;) {
    mn = min(mn, arr[i].y);
    mx = max(mx, arr[i].y);
    if (i > 0) box[i - 1].ra = mn, box[i - 1].rb = mx;
  }
  long long ret = 0;
  for (int i = 0; i + 1 < n; i++) {
    int l = max(box[i].la, box[i].ra);
    int r = min(box[i].lb, box[i].rb);
    if (l >= r) continue;
    ret += (long long)(r - l >> 1) * (arr[i + 1].x - arr[i].x >> 1);
  }
  return ret;
}
int main() {
  read(N);
  for (int i = 1; i <= N; i++) read(A[i].x, A[i].y);
  long long ans = proc();
  for (int i = 1; i <= N; i++) A[i].x++;
  ans += proc();
  write(ans);
  puts("");
}

```


### Prompt

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

Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n. The cost of the i-th stone is vi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:

  1. She will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her <image>.
  2. Let ui be the cost of the i-th cheapest stone (the cost that will be on the i-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, l and r (1 ≤ l ≤ r ≤ n), and you should tell her <image>.

For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.

Input

The first line contains an integer n (1 ≤ n ≤ 105). The second line contains n integers: v1, v2, ..., vn (1 ≤ vi ≤ 109) — costs of the stones.

The third line contains an integer m (1 ≤ m ≤ 105) — the number of Kuriyama Mirai's questions. Then follow m lines, each line contains three integers type, l and r (1 ≤ l ≤ r ≤ n; 1 ≤ type ≤ 2), describing a question. If type equal to 1, then you should output the answer for the first question, else you should output the answer for the second one.

Output

Print m lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.

Examples

Input

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

Output

24
9
28

Input

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

Output

10
15
5
15
5
5
2
12
3
5

Note

Please note that the answers to the questions may overflow 32-bit integer type.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void a15hx() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<long long int> arr1(n), T(n + 1), S(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> arr1[i];
    T[i + 1] = T[i] + arr1[i];
  }
  sort(arr1.begin(), arr1.end());
  for (int i = 0; i < n; i++) {
    S[i + 1] = S[i] + arr1[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int t, l, r;
    cin >> t >> l >> r;
    if (t == 1) {
      cout << T[r] - T[l - 1] << "\n";
    } else {
      cout << S[r] - S[l - 1] << "\n";
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  a15hx();
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

We have a connected undirected graph with N vertices and M edges. Edge i in this graph (1 \leq i \leq M) connects Vertex U_i and Vertex V_i bidirectionally. We are additionally given N integers D_1, D_2, ..., D_N.

Determine whether the conditions below can be satisfied by assigning a color - white or black - to each vertex and an integer weight between 1 and 10^9 (inclusive) to each edge in this graph. If the answer is yes, find one such assignment of colors and integers, too.

* There is at least one vertex assigned white and at least one vertex assigned black.
* For each vertex v (1 \leq v \leq N), the following holds.
* The minimum cost to travel from Vertex v to a vertex whose color assigned is different from that of Vertex v by traversing the edges is equal to D_v.

Here, the cost of traversing the edges is the sum of the weights of the edges traversed.

Constraints

* 2 \leq N \leq 100,000
* 1 \leq M \leq 200,000
* 1 \leq D_i \leq 10^9
* 1 \leq U_i, V_i \leq N
* The given graph is connected and has no self-loops or multiple edges.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
D_1 D_2 ... D_N
U_1 V_1
U_2 V_2
\vdots
U_M V_M

Output

If there is no assignment satisfying the conditions, print a single line containing `-1`.

If such an assignment exists, print one such assignment in the following format:

S
C_1
C_2
\vdots
C_M

Here,

* the first line should contain the string S of length N. Its i-th character (1 \leq i \leq N) should be `W` if Vertex i is assigned white and `B` if it is assigned black.
* The (i + 1)-th line (1 \leq i \leq M) should contain the integer weight C_i assigned to Edge i.

Examples

Input

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

Output

BWWBB
4
3
1
5
2

Input

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

Output

-1

Input

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

Output

BBBW
1
1
1
2
1
1

### Response

```cpp
#include<bits/stdc++.h>
#define LL long long
#define uLL unsigned long long

using namespace std;
const int N=2e5+10,inf=1e9;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
int to[N<<1],nt[N<<1],hd[N],tot=1;
void adde(int x,int y)
{
    ++tot,to[tot]=y,nt[tot]=hd[x],hd[x]=tot;
    ++tot,to[tot]=x,nt[tot]=hd[y],hd[y]=tot;
}
char co[2]={'W','B'};
int n,m,a[N],sq[N],a1[N],a2[N];
bool cmp(int aa,int bb){return a[aa]<a[bb];}

int main()
{
//orz itst
    n=rd(),m=rd();
    for(int i=1;i<=n;++i) a[i]=rd();
    for(int i=1;i<=m;++i) adde(rd(),rd());
    for(int i=1;i<=max(n,m);++i) a1[i]=-1,a2[i]=inf+1;
    for(int i=1;i<=n;++i) sq[i]=i;
    sort(sq+1,sq+n+1,cmp);
    for(int i=1;i<=n;++i)
    {
	int x=sq[i];
	for(int j=hd[x];j;j=nt[j])
	{
	    int y=to[j];
	    if(a[y]>a[x]||((~a1[x])&&(~a1[y]))) continue;
	    if(a[x]==a[y])
	    {
		a2[j>>1]=a[x];
		if(a1[x]<0)
		{
		    if(a1[y]<0) a1[y]=0;
		    a1[x]=a1[y]^1;
		}
		else a1[y]=a1[x]^1;
	    }
	    else if(~a1[y])
		a2[j>>1]=a[x]-a[y],a1[x]=a1[y];
	}
    }
    for(int i=1;i<=n;++i)
	if(a1[i]<0){puts("-1");return 0;}
    for(int i=1;i<=n;++i) putchar(co[a1[i]]);
    puts("");
    for(int i=1;i<=m;++i) printf("%d\n",min(a2[i],inf));
    return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th.

The score of a participant is the product of his/her ranks in the two contests.

Process the following Q queries:

* In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.

Constraints

* 1 \leq Q \leq 100
* 1\leq A_i,B_i\leq 10^9(1\leq i\leq Q)
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

Q
A_1 B_1
:
A_Q B_Q

Output

For each query, print the maximum possible number of participants whose scores are smaller than Takahashi's.

Example

Input

8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323

Output

1
12
4
11
14
57
31
671644785

### Response

```cpp
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
  int q;
  cin>>q;
  for(int i=0; i<q; i++)
  {
      ll a,b,c,mem;
      cin>>a>>b;
      c=ll(a*b);
      mem=sqrt(c);
      if(mem*mem==a*b)
      {
         if(a==b) cout<<(mem-1)*2<<endl;
         else if(a!=b) cout<<(mem-1)*2-1<<endl;
      }
      else if(mem*mem!=a*b)
      {
         if(mem*(mem+1)>=a*b) cout<<(mem-1)*2+1-1<<endl;
		 else if(mem*(mem+1)<a*b) cout<<mem*2-1<<endl;
      }
  }
  return 0;
}
```


### Prompt

Develop a solution in CPP to the problem described below:

Today is tuesday, that means there is a dispute in JOHNNY SOLVING team again: they try to understand who is Johnny and who is Solving. That's why guys asked Umnik to help them. Umnik gave guys a connected graph with n vertices without loops and multiedges, such that a degree of any vertex is at least 3, and also he gave a number 1 ≤ k ≤ n. Because Johnny is not too smart, he promised to find a simple path with length at least n/k in the graph. In reply, Solving promised to find k simple by vertices cycles with representatives, such that:

  * Length of each cycle is at least 3.
  * Length of each cycle is not divisible by 3.
  * In each cycle must be a representative - vertex, which belongs only to this cycle among all printed cycles.

You need to help guys resolve the dispute, for that you need to find a solution for Johnny: a simple path with length at least n/k (n is not necessarily divided by k), or solution for Solving: k cycles that satisfy all the conditions above. If there is no any solution - print -1.

Input

The first line contains three integers n, m and k (1 ≤ k ≤ n ≤ 2.5 ⋅ 10^5, 1 ≤ m ≤ 5 ⋅ 10^5)

Next m lines describe edges of the graph in format v, u (1 ≤ v, u ≤ n). It's guaranteed that v ≠ u and all m pairs are distinct.

It's guaranteed that a degree of each vertex is at least 3.

Output

Print PATH in the first line, if you solve problem for Johnny. In the second line print the number of vertices in the path c (c ≥ n/k). And in the third line print vertices describing the path in route order.

Print CYCLES in the first line, if you solve problem for Solving. In the following lines describe exactly k cycles in the following format: in the first line print the size of the cycle c (c ≥ 3). In the second line print the cycle in route order. Also, the first vertex in the cycle must be a representative.

Print -1 if there is no any solution. The total amount of printed numbers in the output must be at most 10^6. It's guaranteed, that if exists any solution then there is a correct output satisfies this restriction.

Examples

Input

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

Output

PATH
4
1 2 3 4

Input

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

Output

CYCLES
4
4 1 2 3
4
7 1 5 6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  vector<int> deep(n + 1);
  vector<vector<int>> E(n + 1);
  int u, v;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    E[u].push_back(v);
    E[v].push_back(u);
  }
  bool flag = false;
  vector<bool> vis(n + 1);
  fill(vis.begin(), vis.end(), false);
  vector<int> a(n + 1);
  function<void(int)> path_dfs;
  path_dfs = [&](int now) {
    vis[now] = true;
    a[deep[now]] = now;
    if (deep[now] == n / k) {
      flag = true;
      printf("PATH\n%d\n", deep[now] + 1);
      for (int i = 0; i <= deep[now]; i++) printf("%d ", a[i]);
      printf("\n");
      return;
    }
    for (auto it : E[now]) {
      if (vis[it]) continue;
      deep[it] = deep[now] + 1;
      path_dfs(it);
      if (flag) return;
    }
  };
  deep[1] = 0;
  path_dfs(1);
  if (flag) return 0;
  fill(vis.begin(), vis.end(), false);
  function<void(int, int)> dfs;
  dfs = [&](int now, int fa) {
    vis[now] = true;
    a[deep[now]] = now;
    int cnt = 0;
    for (auto it : E[now]) {
      if (vis[it]) continue;
      cnt++;
      dfs(it, now);
      if (k == 0) return;
    }
    if (cnt) return;
    k--;
    sort(E[now].begin(), E[now].end(),
         [&](const int& a, const int& b) { return deep[a] > deep[b]; });
    int u = 0, v = 0;
    for (auto it : E[now]) {
      if (it == fa) continue;
      if (!u)
        u = it;
      else {
        v = it;
        break;
      }
    }
    if ((deep[now] - deep[u] + 1) % 3) {
      printf("%d\n", deep[now] - deep[u] + 1);
      printf("%d ", now);
      for (int i = deep[u]; i < deep[now]; i++) printf("%d ", a[i]);
    } else if ((deep[now] - deep[v] + 1) % 3) {
      printf("%d\n", deep[now] - deep[v] + 1);
      printf("%d ", now);
      for (int i = deep[v]; i < deep[now]; i++) printf("%d ", a[i]);
    } else {
      printf("%d\n", deep[u] - deep[v] + 2);
      printf("%d ", now);
      for (int i = deep[v]; i <= deep[u]; i++) printf("%d ", a[i]);
    }
    printf("\n");
  };
  printf("CYCLES\n");
  dfs(1, 0);
  return 0;
}

```


### Prompt

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

A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.

The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to n clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if n = 5, then after the third throw the child number 2 has the ball again. Overall, n - 1 throws are made, and the game ends.

The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw.

Input

The first line contains integer n (2 ≤ n ≤ 100) which indicates the number of kids in the circle.

Output

In the single line print n - 1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.

Examples

Input

10

Output

2 4 7 1 6 2 9 7 6

Input

3

Output

2 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int tab[1001];
int temp[1001];
int main() {
  int n;
  cin >> n;
  int temp = 2;
  cout << 2 << " ";
  for (long long i = 2; i < n; i++) {
    temp += i;
    if (temp > n) {
      cout << temp - n << " ";
      temp -= n;
    } else
      cout << temp << " ";
  }
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You are given a sequence a1, a2, ..., an consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order.

Sorting integers in a subsequence is a process such that the numbers included in a subsequence are ordered in increasing order, and the numbers which are not included in a subsequence don't change their places.

Every element of the sequence must appear in exactly one subsequence.

Input

The first line of input data contains integer n (1 ≤ n ≤ 105) — the length of the sequence.

The second line of input data contains n different integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the elements of the sequence. It is guaranteed that all elements of the sequence are distinct.

Output

In the first line print the maximum number of subsequences k, which the original sequence can be split into while fulfilling the requirements.

In the next k lines print the description of subsequences in the following format: the number of elements in subsequence ci (0 < ci ≤ n), then ci integers l1, l2, ..., lci (1 ≤ lj ≤ n) — indices of these elements in the original sequence.

Indices could be printed in any order. Every index from 1 to n must appear in output exactly once.

If there are several possible answers, print any of them.

Examples

Input

6
3 2 1 6 5 4

Output

4
2 1 3
1 2
2 4 6
1 5

Input

6
83 -75 -49 11 37 62

Output

1
6 1 2 3 4 5 6

Note

In the first sample output:

After sorting the first subsequence we will get sequence 1 2 3 6 5 4.

Sorting the second subsequence changes nothing.

After sorting the third subsequence we will get sequence 1 2 3 4 5 6.

Sorting the last subsequence changes nothing.

### Response

```cpp
#include <bits/stdc++.h>
const double PI = acos(-1);
using namespace std;
const int MAX = 1 << 20;
int A[MAX], B[MAX], n;
vector<vector<int> > ans;
int vis[MAX];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n); i++) scanf("%d", A + i);
  copy(A, A + n, B);
  sort(B, B + n);
  int m = unique(B, B + n) - B;
  for (int i = 0; i < (n); i++) A[i] = lower_bound(B, B + m, A[i]) - B;
  for (int i = 0; i < (n); i++)
    if (!vis[i]) {
      int cur = i;
      vector<int> aux;
      while (!vis[cur]) {
        vis[cur] = 1;
        aux.push_back(cur + 1);
        cur = A[cur];
      }
      ans.push_back(aux);
    }
  printf("%d\n", ((int)ans.size()));
  for (auto V : ans) {
    printf("%d", ((int)V.size()));
    for (int x : V) printf(" %d", x);
    puts("");
  }
  return 0;
}

```


### Prompt

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

Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from 1 to n. We say that this permutation maps value 1 into the value p1, value 2 into the value p2 and so on.

Kyota Ootori has just learned about cyclic representation of a permutation. A cycle is a sequence of numbers such that each element of this sequence is being mapped into the next element of this sequence (and the last element of the cycle is being mapped into the first element of the cycle). The cyclic representation is a representation of p as a collection of cycles forming p. For example, permutation p = [4, 1, 6, 2, 5, 3] has a cyclic representation that looks like (142)(36)(5) because 1 is replaced by 4, 4 is replaced by 2, 2 is replaced by 1, 3 and 6 are swapped, and 5 remains in place.

Permutation may have several cyclic representations, so Kyoya defines the standard cyclic representation of a permutation as follows. First, reorder the elements within each cycle so the largest element is first. Then, reorder all of the cycles so they are sorted by their first element. For our example above, the standard cyclic representation of [4, 1, 6, 2, 5, 3] is (421)(5)(63).

Now, Kyoya notices that if we drop the parenthesis in the standard cyclic representation, we get another permutation! For instance, [4, 1, 6, 2, 5, 3] will become [4, 2, 1, 5, 6, 3].

Kyoya notices that some permutations don't change after applying operation described above at all. He wrote all permutations of length n that do not change in a list in lexicographic order. Unfortunately, his friend Tamaki Suoh lost this list. Kyoya wishes to reproduce the list and he needs your help. Given the integers n and k, print the permutation that was k-th on Kyoya's list.

Input

The first line will contain two integers n, k (1 ≤ n ≤ 50, 1 ≤ k ≤ min{1018, l} where l is the length of the Kyoya's list).

Output

Print n space-separated integers, representing the permutation that is the answer for the question.

Examples

Input

4 3

Output

1 3 2 4

Input

10 1

Output

1 2 3 4 5 6 7 8 9 10

Note

The standard cycle representation is (1)(32)(4), which after removing parenthesis gives us the original permutation. The first permutation on the list would be [1, 2, 3, 4], while the second permutation would be [1, 2, 4, 3].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int inf = 1000000000000000001;
long long int fib[51];
int N;
int change[50];
int res[51];
long long int K, M;
long long int mmn(long long int a, long long int b) { return a < b ? a : b; }
void calc_fib() {
  fib[0] = 1;
  fib[1] = 2;
  fib[2] = 3;
  for (int i = 3; i <= 50; i++) fib[i] = mmn(inf, fib[i - 1] + fib[i - 2]);
}
long long int get_fib(int i) {
  if (i < 0) return 1;
  return fib[i];
}
long long int swap(int i, int j) {
  int tp = res[i];
  res[i] = res[j];
  res[j] = tp;
}
int main() {
  calc_fib();
  scanf("%d %lld ", &N, &K);
  for (int i = N; i >= 1; i--) {
    res[i] = N - i + 1;
  }
  int pos = N - 1;
  long long int M = K;
  while (M > 0) {
    int pos = 0;
    while (get_fib(pos) < M) pos++;
    change[pos] = 1;
    M -= get_fib(pos - 1);
  }
  for (int i = N - 1; i >= 1; i--) {
    if (change[i] == 1) {
      swap(i + 1, i);
    }
  }
  for (int i = N; i >= 2; i--) {
    printf("%d ", res[i]);
  }
  printf("%d\n", res[1]);
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

problem

Santa Claus came from the sky to JOI town this year as well. Since every house in JOI has children, this Santa Claus must give out presents to every house in JOI. However, this year the reindeer I am carrying is a little deaf and I can only get off the top of the building, so it seems that I have to devise a little route to distribute gifts to all the houses.

JOI Town is divided into north, south, east and west, and each section is a house, a church, or a vacant lot. There is only one church in JOI town. According to the following rules, Santa Claus and reindeer depart from the church, give out one gift to every house, and then return to the church.

* This year's reindeer is a little deaf, so it can only fly straight in either the north, south, east, or west, and cannot change direction in the air.
* You can pass freely over the house where you haven't handed out the presents yet. You can get off at a house that hasn't given out presents yet. Whenever I get home, I give out presents and then take off in either direction of north, south, east or west.
* At the house in JOI town, I spend Christmas night without the fireplace until Santa Claus arrives, but after Santa Claus takes off, I turn on the fireplace. When you turn on the fireplace, smoke comes out of the chimney, so you can't pass over the house where you've finished giving out presents.
* You can pass freely over the church. However, since worship is held in the church, you cannot go down to the church until you have distributed all the presents.
* You can pass freely over the vacant lot, but you cannot get off at the vacant lot.

Create a program that asks how many directions Santa Claus and reindeer can give gifts to, given the structure of the town as input.

input

The input consists of multiple datasets. Each dataset is given in the following format.

Each dataset has n + 1 rows. On the first line, the integer m (1 ≤ m ≤ 10) and the integer n (1 ≤ n ≤ 10) are written separated by a space. In each line from the 2nd line to the n + 1th line, m of 0, 1, or 2 are written, separated by a blank, and each represents the state of each section. If we write the i-th section from the north and the j-th section from the west as (i, j) (1 ≤ i ≤ n, 1 ≤ j ≤ m), the j-th value on the i + 1 line is If the lot (i, j) is a vacant lot, it will be 0, if it is a house, it will be 1, and if it is a church, it will be 2. The number of churches is 1, and the number of houses is 1 or more and 23 or less. However, in the input data for scoring, the number of directions to be distributed does not exceed 2000000.

When both m and n are 0, it indicates the end of input. The number of data sets does not exceed 5.

Input / output example

Input example

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

Output example

2
6

<image>

Figure: All 6 directions to the second input example (numbers indicate the order of distribution)

The above question sentences and the data used for the automatic referee are the question sentences created and published by the Japan Committee for Information Olympics and the test data for scoring.

output

For each dataset, an integer indicating how many directions to distribute gifts is output on one line.

Example

Input

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

Output

2
6

### Response

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

int H[10][10];
int m, n;
int I, J;

int solve(int i, int j, int k) {
	if (!k) {
		if (i == I || j == J)return 1;
		else return 0;
	}
	int res = 0;
	for (int t = 1; i + t < n; t++) {
		if (H[i + t][j] == 1) {
			H[i + t][j] = 0;
			res += solve(i + t, j, k - 1);
			H[i + t][j] = 1;
			break;
		}
	}
	for (int t = 1; i - t >= 0; t++) {
		if (H[i - t][j] == 1) {
			H[i - t][j] = 0;
			res += solve(i - t, j, k - 1);
			H[i - t][j] = 1;
			break;
		}
	}
	for (int t = 1; j + t < m; j++) {
		if (H[i][j + t] == 1) {
			H[i][j + t] = 0;
			res += solve(i, j + t, k - 1);
			H[i][j + t] = 1;
			break;
		}
	}
	for (int t = 1; j - t >= 0; t++) {
		if (H[i][j - t] == 1) {
			H[i][j - t] = 0;
			res += solve(i, j - t, k - 1);
			H[i][j - t] = 1;
			break;
		}
	}
	return res;
}
int main() {
	while (scanf("%d%d", &m, &n), m) {
		int cnt = 0;
		rep(i, n) {
			rep(j, m) {
				scanf("%d", &H[i][j]);
				if (H[i][j] == 1)cnt++;
				if (H[i][j] == 2) { I = i; J = j; }
			}
		}
		printf("%d\n", solve(I, J, cnt));
	}
	return 0;
}
```


### Prompt

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

Your program fails again. This time it gets "Wrong answer on test 233"

.

This is the easier version of the problem. In this version 1 ≤ n ≤ 2000. You can hack this problem only if you solve and lock both problems.

The problem is about a test containing n one-choice-questions. Each of the questions contains k options, and only one of them is correct. The answer to the i-th question is h_{i}, and if your answer of the question i is h_{i}, you earn 1 point, otherwise, you earn 0 points for this question. The values h_1, h_2, ..., h_n are known to you in this problem.

However, you have a mistake in your program. It moves the answer clockwise! Consider all the n answers are written in a circle. Due to the mistake in your program, they are shifted by one cyclically.

Formally, the mistake moves the answer for the question i to the question i mod n + 1. So it moves the answer for the question 1 to question 2, the answer for the question 2 to the question 3, ..., the answer for the question n to the question 1.

We call all the n answers together an answer suit. There are k^n possible answer suits in total.

You're wondering, how many answer suits satisfy the following condition: after moving clockwise by 1, the total number of points of the new answer suit is strictly larger than the number of points of the old one. You need to find the answer modulo 998 244 353.

For example, if n = 5, and your answer suit is a=[1,2,3,4,5], it will submitted as a'=[5,1,2,3,4] because of a mistake. If the correct answer suit is h=[5,2,2,3,4], the answer suit a earns 1 point and the answer suite a' earns 4 points. Since 4 > 1, the answer suit a=[1,2,3,4,5] should be counted.

Input

The first line contains two integers n, k (1 ≤ n ≤ 2000, 1 ≤ k ≤ 10^9) — the number of questions and the number of possible answers to each question.

The following line contains n integers h_1, h_2, ..., h_n, (1 ≤ h_{i} ≤ k) — answers to the questions.

Output

Output one integer: the number of answers suits satisfying the given condition, modulo 998 244 353.

Examples

Input

3 3
1 3 1

Output

9

Input

5 5
1 1 4 2 2

Output

1000

Note

For the first example, valid answer suits are [2,1,1], [2,1,2], [2,1,3], [3,1,1], [3,1,2], [3,1,3], [3,2,1], [3,2,2], [3,2,3].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long M = 998244353;
const int N = 2001;
int n;
long long k;
long long h[N];
int diff = 0;
long long dp[N][2 * N];
long long res = 0;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> h[i];
  for (int i = 0; i < n; i++)
    if (h[i] != h[(i - 1 + n) % n]) diff++;
  dp[0][diff] = 1;
  for (int i = 1; i <= diff; i++) {
    for (int j = 0; j <= 2 * diff; j++) {
      dp[i][j] += dp[i - 1][j - 1] + dp[i - 1][j + 1] + dp[i - 1][j] * (k - 2);
      dp[i][j] %= M;
    }
  }
  for (int i = 1; i <= diff; i++) {
    res += dp[diff][i + diff];
    res %= M;
  }
  for (int i = diff + 1; i <= n; i++) {
    res *= k;
    res %= M;
  }
  cout << res << endl;
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Find the number of the possible tuples of sequences (A_0,A_1,...,A_N) that satisfy all of the following conditions, modulo M:

* For every i (0\leq i\leq N), A_i is a sequence of length i consisting of integers between 1 and K (inclusive);
* For every i (1\leq i\leq N), A_{i-1} is a subsequence of A_i, that is, there exists 1\leq x_i\leq i such that the removal of the x_i-th element of A_i would result in a sequence equal to A_{i-1};
* For every i (1\leq i\leq N), A_i is lexicographically larger than A_{i-1}.

Constraints

* 1 \leq N,K \leq 300
* 2 \leq M \leq 10^9
* N, K and M are integers.

Input

Input is given from Standard Input in the following format:

N K M

Output

Print the number of the possible tuples of sequences (A_0,A_1,...,A_N), modulo M.

Examples

Input

2 2 100

Output

5

Input

4 3 999999999

Output

358

Input

150 150 998244353

Output

186248260

### Response

```cpp
/*
读题不规范，爆零两行泪。
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
const int N=300,M=300;
int n,m,mod;
int comb[N+1][N+1];
int dp[N+1][M+2];
int Sum[N+1][M+2];
int main(){
	cin>>n>>m>>mod;
	comb[0][0]=1;
	for(int i=1;i<=n;i++)for(int j=0;j<=i;j++)comb[i][j]=((j?comb[i-1][j-1]:0)+(j<i?comb[i-1][j]:0))%mod;
	for(int i=1;i<=m+1;i++)Sum[0][i]=(Sum[0][i-1]+(dp[0][i]=1))%mod;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			for(int k=1;k<=i;k++)(dp[i][j]+=1ll*dp[i-k][j]*comb[i-1][k-1]%mod*(Sum[k-1][m+1]-Sum[k-1][j])%mod)%=mod;
			Sum[i][j]=(Sum[i][j-1]+dp[i][j])%mod;
//			printf("dp[%d][%d]=%d\n",i,j,dp[i][j]);
		}
		Sum[i][m+1]=Sum[i][m];
	}
	cout<<(dp[n][1]+mod)%mod;
	return 0;
}
```


### Prompt

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

JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way.

First, he splits the Banh-mi into n parts, places them on a row and numbers them from 1 through n. For each part i, he defines the deliciousness of the part as x_i ∈ \{0, 1\}. JATC's going to eat those parts one by one. At each step, he chooses arbitrary remaining part and eats it. Suppose that part is the i-th part then his enjoyment of the Banh-mi will increase by x_i and the deliciousness of all the remaining parts will also increase by x_i. The initial enjoyment of JATC is equal to 0.

For example, suppose the deliciousness of 3 parts are [0, 1, 0]. If JATC eats the second part then his enjoyment will become 1 and the deliciousness of remaining parts will become [1, \\_, 1]. Next, if he eats the first part then his enjoyment will become 2 and the remaining parts will become [\\_, \\_, 2]. After eating the last part, JATC's enjoyment will become 4.

However, JATC doesn't want to eat all the parts but to save some for later. He gives you q queries, each of them consisting of two integers l_i and r_i. For each query, you have to let him know what is the maximum enjoyment he can get if he eats all the parts with indices in the range [l_i, r_i] in some order.

All the queries are independent of each other. Since the answer to the query could be very large, print it modulo 10^9+7.

Input

The first line contains two integers n and q (1 ≤ n, q ≤ 100 000).

The second line contains a string of n characters, each character is either '0' or '1'. The i-th character defines the deliciousness of the i-th part.

Each of the following q lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the segment of the corresponding query.

Output

Print q lines, where i-th of them contains a single integer — the answer to the i-th query modulo 10^9 + 7.

Examples

Input

4 2
1011
1 4
3 4

Output

14
3

Input

3 2
111
1 2
3 3

Output

3
1

Note

In the first example:

  * For query 1: One of the best ways for JATC to eats those parts is in this order: 1, 4, 3, 2.
  * For query 2: Both 3, 4 and 4, 3 ordering give the same answer.

In the second example, any order of eating parts leads to the same answer.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int M1 = 1000000007;
const int M2 = 998244353;
const int N = 100005;
int ones[N];
template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
long long int GPmodM(long long int a, long long int r, long long int n) {
  return (a * (modpow(r, n, M1) - 1) * modpow(r - 1, M1 - 2, M1)) % M1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, m, q, a, b, temp;
  cin >> n >> q;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      ones[i + 1] = ones[i] + 1;
    } else {
      ones[i + 1] = ones[i];
    }
  }
  for (int i = 0; i < q; i++) {
    cin >> a >> b;
    int length = b - a + 1;
    int one = ones[b] - ones[a - 1];
    int zero = length - one;
    if (zero == length) {
      cout << 0 << "\n";
    } else {
      long long int ans = modpow(2 * 1LL, 1LL * one, M1) - 1;
      ans += GPmodM(ans, 1LL * 2, zero);
      cout << ans % M1 << "\n";
    }
  }
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Gildong is playing a video game called Block Adventure. In Block Adventure, there are n columns of blocks in a row, and the columns are numbered from 1 to n. All blocks have equal heights. The height of the i-th column is represented as h_i, which is the number of blocks stacked in the i-th column.

Gildong plays the game as a character that can stand only on the top of the columns. At the beginning, the character is standing on the top of the 1-st column. The goal of the game is to move the character to the top of the n-th column.

The character also has a bag that can hold infinitely many blocks. When the character is on the top of the i-th column, Gildong can take one of the following three actions as many times as he wants:

  * if there is at least one block on the column, remove one block from the top of the i-th column and put it in the bag;
  * if there is at least one block in the bag, take one block out of the bag and place it on the top of the i-th column;
  * if i < n and |h_i - h_{i+1}| ≤ k, move the character to the top of the i+1-st column. k is a non-negative integer given at the beginning of the game. Note that it is only possible to move to the next column.

In actions of the first two types the character remains in the i-th column, and the value h_i changes.

The character initially has m blocks in the bag. Gildong wants to know if it is possible to win the game. Help Gildong find the answer to his question.

Input

Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000). Description of the test cases follows.

The first line of each test case contains three integers n, m, and k (1 ≤ n ≤ 100, 0 ≤ m ≤ 10^6, 0 ≤ k ≤ 10^6) — the number of columns in the game, the number of blocks in the character's bag at the beginning, and the non-negative integer k described in the statement.

The second line of each test case contains n integers. The i-th integer is h_i (0 ≤ h_i ≤ 10^6), the initial height of the i-th column.

Output

For each test case, print "YES" if it is possible to win the game. Otherwise, print "NO".

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

Example

Input

5
3 0 1
4 3 5
3 1 2
1 4 7
4 10 0
10 20 10 20
2 5 5
0 11
1 9 9
99

Output

YES
NO
YES
NO
YES

Note

In the first case, Gildong can take one block from the 1-st column, move to the 2-nd column, put the block on the 2-nd column, then move to the 3-rd column.

In the second case, Gildong has to put the block in his bag on the 1-st column to get to the 2-nd column. But it is impossible to get to the 3-rd column because |h_2 - h_3| = 3 > k and there is no way to decrease the gap.

In the fifth case, the character is already on the n-th column from the start so the game is won instantly.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> h(n);
  for (int& i : h) cin >> i;
  for (int i = 0; i < n - 1; ++i) {
    m += h[i] - max(0, h[i + 1] - k);
    if (m < 0) {
      cout << "NO" << '\n';
      return;
    }
  }
  cout << "YES" << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).

Input

The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100.

Output

Output one number — length of the longest substring that can be met in the string at least twice.

Examples

Input

abcd

Output

0

Input

ababa

Output

3

Input

zzz

Output

2

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  char str[101];
  char buf[101];
  gets(str);
  int len = strlen(str);
  int i, j, flag = 0;
  for (i = len - 1; i > 0; --i) {
    j = 0;
    while (i <= len - j - 1) {
      memset(buf, 0, 101);
      strncpy(buf, str + j, i);
      if (strstr(str + j + 1, buf) != NULL) {
        flag = 1;
        break;
      }
      j++;
    }
    if (flag) break;
  }
  printf("%d", i);
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

You are given an array with n integers ai and m queries. Each query is described by two integers (lj, rj).

Let's define the function <image>. The function is defined for only u ≤ v.

For each query print the maximal value of the function f(ax, ay) over all lj ≤ x, y ≤ rj, ax ≤ ay.

Input

The first line contains two integers n, m (1 ≤ n ≤ 5·104, 1 ≤ m ≤ 5·103) — the size of the array and the number of the queries.

The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.

Each of the next m lines contains two integers lj, rj (1 ≤ lj ≤ rj ≤ n) – the parameters of the j-th query.

Output

For each query print the value aj on a separate line — the maximal value of the function f(ax, ay) over all lj ≤ x, y ≤ rj, ax ≤ ay.

Examples

Input

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

Output

7
7
7

Input

1 1
1
1 1

Output

1

Input

6 20
10 21312 2314 214 1 322
1 1
1 2
1 3
1 4
1 5
1 6
2 2
2 3
2 4
2 5
2 6
3 4
3 5
3 6
4 4
4 5
4 6
5 5
5 6
6 6

Output

10
21313
21313
21313
21313
21313
21312
21313
21313
21313
21313
2314
2315
2315
214
215
323
1
323
322

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int quick_pow(int a, int b, int MOD) {
  a %= MOD;
  int res = 1;
  while (b) {
    if (b & 1) res = (res * a) % MOD;
    b /= 2;
    a = (a * a) % MOD;
  }
  return res;
}
const int maxn = 50000 + 10;
int a[maxn], b[maxn], res[maxn], x[maxn], y[maxn], sum[1000005], f[1000005];
int main() {
  int i, j, n, m;
  sum[0] = 0;
  for (i = 1; i <= 1000000; i++) sum[i] = (sum[i - 1] ^ i);
  while (scanf("%d%d", &n, &m) != EOF) {
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      f[i] = sum[a[i]];
    }
    for (i = 1; i <= m; i++) {
      scanf("%d%d", &x[i], &y[i]);
      res[i] = -1;
    }
    for (i = 1; i <= n; i++) {
      b[i - 1] = 0;
      for (j = i; j <= n; j++) {
        b[j] = max(b[j - 1], f[i] ^ f[j] ^ (a[i] < a[j] ? a[i] : a[j]));
      }
      for (j = 1; j <= m; j++) {
        if (x[j] <= i && y[j] >= i) {
          res[j] = max(res[j], b[y[j]]);
        }
      }
    }
    for (i = 1; i <= m; i++) printf("%d\n", res[i]);
  }
  return 0;
}

```


### Prompt

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

Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score.

Codeforces scores are computed as follows: If the maximum point value of a problem is x, and Kevin submitted correctly at minute m but made w wrong submissions, then his score on that problem is <image>. His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack.

All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer.

Input

The first line of the input contains five space-separated integers m1, m2, m3, m4, m5, where mi (0 ≤ mi ≤ 119) is the time of Kevin's last submission for problem i. His last submission is always correct and gets accepted.

The second line contains five space-separated integers w1, w2, w3, w4, w5, where wi (0 ≤ wi ≤ 10) is Kevin's number of wrong submissions on problem i.

The last line contains two space-separated integers hs and hu (0 ≤ hs, hu ≤ 20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively.

Output

Print a single integer, the value of Kevin's final score.

Examples

Input

20 40 60 80 100
0 1 2 3 4
1 0

Output

4900

Input

119 119 119 119 119
0 0 0 0 0
10 0

Output

4930

Note

In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <image> of the points on each problem. So his score from solving problems is <image>. Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930.

### Response

```cpp
#include <bits/stdc++.h>
namespace chtholly {
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar()) f ^= c == '-';
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ '0');
  return f ? x : -x;
}
template <typename mitsuha>
inline bool read(mitsuha &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c) && ~c; c = getchar()) f ^= c == '-';
  if (!~c) return 0;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ '0');
  return x = f ? x : -x, 1;
}
template <typename mitsuha>
inline int write(mitsuha x) {
  if (!x) return 0 & putchar(48);
  if (x < 0) x = -x, putchar('-');
  int bit[20], i, p = 0;
  for (; x; x /= 10) bit[++p] = x % 10;
  for (i = p; i; --i) putchar(bit[i] + 48);
  return 0;
}
inline char fuhao() {
  char c = getchar();
  for (; isspace(c); c = getchar())
    ;
  return c;
}
}  // namespace chtholly
using namespace chtholly;
using namespace std;
int suan(int x, int m, int w) {
  return max(x * 3 / 10, x - x * m / 250 - 50 * w);
}
int main() {
  int m1, m2, m3, m4, m5;
  cin >> m1 >> m2 >> m3 >> m4 >> m5;
  int w1, w2, w3, w4, w5, ans = 0;
  cin >> w1 >> w2 >> w3 >> w4 >> w5;
  ans += suan(500, m1, w1) + suan(1000, m2, w2) + suan(1500, m3, w3) +
         suan(2000, m4, w4) + suan(2500, m5, w5);
  int hs, hu;
  cin >> hs >> hu;
  cout << ans + hs * 100 - hu * 50;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Tavas lives in Kansas. Kansas has n cities numbered from 1 to n connected with m bidirectional roads. We can travel from any city to any other city via these roads. Kansas is as strange as Tavas. So there may be a road between a city and itself or more than one road between two cities.

Tavas invented a game and called it "Dashti". He wants to play Dashti with his girlfriends, Nafas.

In this game, they assign an arbitrary integer value to each city of Kansas. The value of i-th city equals to pi.

During the game, Tavas is in city s and Nafas is in city t. They play in turn and Tavas goes first. A player in his/her turn, must choose a non-negative integer x and his/her score increases by the sum of values of all cities with (shortest) distance no more than x from his/her city. Each city may be used once, or in the other words, after first time a player gets score from a city, city score becomes zero.

There is an additional rule: the player must choose x such that he/she gets the point of at least one city that was not used before. Note that city may initially have value 0, such city isn't considered as been used at the beginning of the game, i. e. each player may use it to fullfill this rule.

The game ends when nobody can make a move.

A player's score is the sum of the points he/she earned during the game. The winner is the player with greater score, or there is a draw if players score the same value. Both players start game with zero points.

<image>

If Tavas wins, he'll break his girlfriend's heart, and if Nafas wins, Tavas will cry. But if their scores are equal, they'll be happy and Tavas will give Nafas flowers.

They're not too emotional after all, so they'll play optimally. Your task is to tell Tavas what's going to happen after the game ends.

Input

The first line of input contains two integers n and m (2 ≤ n ≤ 2000, n - 1 ≤ m ≤ 105).

The second line of input contains two integers s and t (1 ≤ s, t ≤ n, s ≠ t).

The next line contains n integers p1, p2, ..., pn separated by spaces (|pi| ≤ 109).

The next m lines contain the roads. Each line contains three integers v, u, w and it means that there's an road with length w between cities v and u (1 ≤ u, v ≤ n and 0 ≤ w ≤ 109). The road may lead from the city to itself, there may be several roads between each pair of cities.

Output

If Tavas wins, print "Break a heart". If Nafas wins print "Cry" and if nobody wins (i. e. the game ended with draw) print "Flowers".

Examples

Input

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

Output

Cry

Input

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

Output

Break a heart

Input

2 1
1 2
-5 -5
1 2 10

Output

Flowers

### Response

```cpp
#include <bits/stdc++.h>
int h[2010], nxt[2 * 101000], to[2 * 101000], cost[2 * 101000], K = 0;
long long v[2010][2010][2], f[2010][2010][2];
int w[2010];
long long d[2][2010];
bool used[2010];
long long b[2][2010];
int n, m, s, t;
void ins(int u, int v, int c) {
  nxt[++K] = h[u];
  h[u] = K;
  to[K] = v;
  cost[K] = c;
}
void dij(long long *d, int S) {
  memset(used, 0, sizeof(used));
  d[S] = 0;
  for (int T = 1; T <= n; T++) {
    int u = 0;
    for (int i = 1; i <= n; i++)
      if (!used[i] && (u == 0 || d[i] < d[u])) u = i;
    used[u] = 1;
    for (int i = h[u]; i; i = nxt[i])
      d[to[i]] = std::min(d[to[i]], d[u] + cost[i]);
  }
}
int main() {
  memset(d, 0x3f, sizeof(d));
  memset(v, 0x3f, sizeof(v));
  long long inf = v[0][0][0];
  memset(f, 0, sizeof(f));
  scanf("%d%d%d%d", &n, &m, &s, &t);
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    ins(u, v, w);
    ins(v, u, w);
  }
  dij(d[0], s);
  dij(d[1], t);
  memcpy(b, d, sizeof(d));
  int N[2];
  for (int i = 0; i < 2; i++) {
    std::sort(b[i] + 1, b[i] + n + 1);
    N[i] = std::unique(b[i] + 1, b[i] + n + 1) - b[i] - 1;
    for (int j = 1; j <= n; j++)
      d[i][j] = std::lower_bound(b[i] + 1, b[i] + N[i] + 1, d[i][j]) - b[i];
  }
  for (int j = 0; j <= N[1]; j++)
    for (int i = 1; i <= n; i++) {
      if (d[1][i] > j) {
        if (v[d[0][i]][j][0] == inf) v[d[0][i]][j][0] = 0;
        v[d[0][i]][j][0] += w[i];
      }
    }
  for (int j = 0; j <= N[0]; j++)
    for (int i = 1; i <= n; i++) {
      if (d[0][i] > j) {
        if (v[j][d[1][i]][1] == inf) v[j][d[1][i]][1] = 0;
        v[j][d[1][i]][1] += w[i];
      }
    }
  for (int i = N[0]; i >= 0; i--)
    for (int j = N[1]; j >= 0; j--) {
      if (v[i + 1][j][0] == inf)
        f[i][j][0] = f[i + 1][j][0];
      else
        f[i][j][0] = std::max(f[i + 1][j][0], f[i + 1][j][1]) + v[i + 1][j][0];
      if (v[i][j + 1][1] == inf)
        f[i][j][1] = f[i][j + 1][1];
      else
        f[i][j][1] = std::min(f[i][j + 1][1], f[i][j + 1][0]) - v[i][j + 1][1];
    }
  if (f[0][0][0] > 0) puts("Break a heart");
  if (f[0][0][0] == 0) puts("Flowers");
  if (f[0][0][0] < 0) puts("Cry");
}

```


### Prompt

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

Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.

What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.

Input

The input contains three positive integer numbers in the first line: n, m and a (1 ≤ n, m, a ≤ 109).

Output

Write the needed number of flagstones.

Examples

Input

6 6 4

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, a;
  cin >> n >> m >> a;
  long long x = ceil((double)n / a), y = ceil((double)m / a);
  cout << x * y << endl;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.

New parliament assembly hall is a rectangle consisting of a × b chairs — a rows of b chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall

We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.

Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.

Input

The first line of the input contains three integers n, a and b (1 ≤ n ≤ 10 000, 1 ≤ a, b ≤ 100) — the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.

Output

If there is no way to assigns seats to parliamentarians in a proper way print -1.

Otherwise print the solution in a lines, each containing b integers. The j-th integer of the i-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.

Examples

Input

3 2 2

Output

0 3
1 2

Input

8 4 3

Output

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

Input

10 2 2

Output

-1

Note

In the first sample there are many other possible solutions. For example,

    3 2
    0 1

and

    2 1
    3 0

The following assignment

    3 2
    1 0

is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1000;
int w[1005][1005], n, m, ans, tot, a, b;
void pdo() {
  for (int i = 1; i <= a; i++) {
    for (int j = 1; j <= b; j++) {
      tot++;
      if (tot > n) break;
      w[i][j] = tot;
    }
    if (tot > n) break;
  }
  for (int i = 1; i <= a; i++) {
    if (i % 2 == 0) {
      for (int j = 1; j <= b; j++) printf("%d ", w[i][b + 1 - j]);
    } else {
      for (int j = 1; j <= b; j++) {
        printf("%d ", w[i][j]);
      }
    }
    printf("\n");
  }
}
int main() {
  scanf("%d %d %d", &n, &a, &b);
  if (n <= a * b)
    pdo();
  else
    printf("-1\n");
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy's clothes.

Ten minutes before her leave she realized that it would be also useful to prepare instruction of which particular clothes to wear on each of the days she will be absent. Arseniy's family is a bit weird so all the clothes is enumerated. For example, each of Arseniy's n socks is assigned a unique integer from 1 to n. Thus, the only thing his mother had to do was to write down two integers li and ri for each of the days — the indices of socks to wear on the day i (obviously, li stands for the left foot and ri for the right). Each sock is painted in one of k colors.

When mother already left Arseniy noticed that according to instruction he would wear the socks of different colors on some days. Of course, that is a terrible mistake cause by a rush. Arseniy is a smart boy, and, by some magical coincidence, he posses k jars with the paint — one for each of k colors.

Arseniy wants to repaint some of the socks in such a way, that for each of m days he can follow the mother's instructions and wear the socks of the same color. As he is going to be very busy these days he will have no time to change the colors of any socks so he has to finalize the colors now.

The new computer game Bota-3 was just realised and Arseniy can't wait to play it. What is the minimum number of socks that need their color to be changed in order to make it possible to follow mother's instructions and wear the socks of the same color during each of m days.

Input

The first line of input contains three integers n, m and k (2 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000, 1 ≤ k ≤ 200 000) — the number of socks, the number of days and the number of available colors respectively.

The second line contain n integers c1, c2, ..., cn (1 ≤ ci ≤ k) — current colors of Arseniy's socks.

Each of the following m lines contains two integers li and ri (1 ≤ li, ri ≤ n, li ≠ ri) — indices of socks which Arseniy should wear during the i-th day.

Output

Print one integer — the minimum number of socks that should have their colors changed in order to be able to obey the instructions and not make people laugh from watching the socks of different colors.

Examples

Input

3 2 3
1 2 3
1 2
2 3

Output

2

Input

3 2 2
1 1 2
1 2
2 1

Output

0

Note

In the first sample, Arseniy can repaint the first and the third socks to the second color.

In the second sample, there is no need to change any colors.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, k;
int c[N];
map<int, int> cnt;
vector<int> adj[N];
int mark[N];
void dfs(int u) {
  mark[u] = 1;
  cnt[c[u]]++;
  for (auto v : adj[u])
    if (!mark[v]) dfs(v);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (int i = 1; i <= m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    adj[l].push_back(r);
    adj[r].push_back(l);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (mark[i]) continue;
    dfs(i);
    int chd = 0, mx = 0;
    for (auto j : cnt) chd += j.second, mx = max(mx, j.second);
    ans += chd - mx;
    cnt.clear();
  }
  printf("%d", ans);
}

```


### Prompt

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

Coloring of the vertices of a tree G is called a good coloring when, for every pair of two vertices u and v painted in the same color, picking u as the root and picking v as the root would result in isomorphic rooted trees.

Also, the colorfulness of G is defined as the minimum possible number of different colors used in a good coloring of G.

You are given a tree with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. We will construct a new tree T by repeating the following operation on this tree some number of times:

* Add a new vertex to the tree by connecting it to one of the vertices in the current tree with an edge.

Find the minimum possible colorfulness of T. Additionally, print the minimum number of leaves (vertices with degree 1) in a tree T that achieves the minimum colorfulness.

Constraints

* 2 \leq N \leq 100
* 1 \leq a_i,b_i \leq N(1\leq i\leq N-1)
* The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
:
a_{N-1} b_{N-1}

Output

Print two integers with a space in between. First, print the minimum possible colorfulness of a tree T that can be constructed. Second, print the minimum number of leaves in a tree that achieves it.

It can be shown that, under the constraints of this problem, the values that should be printed fit into 64-bit signed integers.

Examples

Input

5
1 2
2 3
3 4
3 5

Output

2 4

Input

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

Output

3 4

Input

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

Output

4 6

Input

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

Output

4 12

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
#define llong long long
#define pii pair<int,llong>
#define fi first
#define se second
int n;
int ed[110][2];
struct data{
    int to,nxt;
}mp[220];
int head[110],cnt;
void link(int x,int y)
{
    mp[++cnt].to=y;
    mp[cnt].nxt=head[x];
    head[x]=cnt;
}

int md[110];
int dep[110];
queue<int>q;
pii solve(int x,int y)
{
    pii res;res.fi=res.se=0;
    memset(dep,0,sizeof(dep));
    memset(md,0,sizeof(md));
    q.push(x);dep[x]=1;
    if(y)q.push(y),dep[y]=1;
    int u,v,d;
    while(!q.empty())
    {
        u=q.front();q.pop();
        res.fi=max(res.fi,dep[u]);
        d=0;
        for(int i=head[u];i;i=mp[i].nxt)
            if(!dep[mp[i].to])
            {
                v=mp[i].to;
                dep[v]=dep[u]+1;
                q.push(v);
                d++;
            }
        md[dep[u]]=max(md[dep[u]],d);
    }
    res.se=y?2:1;
    for(int i=1;md[i];++i) res.se*=md[i];
    return res;
}
pii ans;
int main()
{
    scanf("%d",&n);
    int xx,yy;
    for(int i=1;i<n;++i)
    {
        scanf("%d%d",&xx,&yy);
        link(xx,yy);link(yy,xx);
        ed[i][0]=xx;ed[i][1]=yy;
    }
    ans.fi=22832737;ans.se=23721837;
    for(int i=1;i<=n;++i)
        ans=min(ans,solve(i,0));
    for(int i=1;i<n;++i)
        ans=min(ans,solve(ed[i][0],ed[i][1]));
    printf("%d %lld\n",ans.fi,ans.se);
    return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Sereja has a bracket sequence s1, s2, ..., sn, or, in other words, a string s of length n, consisting of characters "(" and ")".

Sereja needs to answer m queries, each of them is described by two integers li, ri (1 ≤ li ≤ ri ≤ n). The answer to the i-th query is the length of the maximum correct bracket subsequence of sequence sli, sli + 1, ..., sri. Help Sereja answer all queries.

You can find the definitions for a subsequence and a correct bracket sequence in the notes.

Input

The first line contains a sequence of characters s1, s2, ..., sn (1 ≤ n ≤ 106) without any spaces. Each character is either a "(" or a ")". The second line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains a pair of integers. The i-th line contains integers li, ri (1 ≤ li ≤ ri ≤ n) — the description of the i-th query.

Output

Print the answer to each question on a single line. Print the answers in the order they go in the input.

Examples

Input

())(())(())(
7
1 1
2 3
1 2
1 12
8 12
5 11
2 10

Output

0
0
2
10
4
6
6

Note

A subsequence of length |x| of string s = s1s2... s|s| (where |s| is the length of string s) is string x = sk1sk2... sk|x| (1 ≤ k1 < k2 < ... < k|x| ≤ |s|).

A correct bracket sequence is a bracket sequence that can be transformed into a correct aryphmetic expression by inserting characters "1" and "+" between the characters of the string. For example, bracket sequences "()()", "(())" are correct (the resulting expressions "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.

For the third query required sequence will be «()».

For the fourth query required sequence will be «()(())(())».

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
inline int input() {
  int ret = 0;
  bool isN = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ret = ret * 10 + c - '0';
    c = getchar();
  }
  return ret;
}
inline void output(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  int len = 0, data[11];
  while (x) {
    data[len++] = x % 10;
    x /= 10;
  }
  if (!len) data[len++] = 0;
  while (len--) putchar(data[len] + 48);
  putchar('\n');
}
const int N = (int)(1e6) + 5;
int n, open[2 * N], good[N];
char s[N];
int Query(int l, int r) {
  int res = N;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if ((l & 1) == 1) res = min(res, open[l++]);
    if ((r & 1) == 1) res = min(res, open[--r]);
  }
  return res;
}
int main() {
  scanf("%s", s);
  n = strlen(s) + 1;
  int op = 0, go = 0;
  for (int i = 1; i < n; i++) {
    if (s[i - 1] == '(') {
      op++;
    } else {
      if (op > 0) {
        op--;
        go++;
      }
    }
    open[i + n] = op;
    good[i] = go;
  }
  for (int i = n - 1; i > 0; --i) open[i] = min(open[i << 1], open[i << 1 | 1]);
  int m = input();
  for (int i = 0; i < m; i++) {
    int l = input();
    int r = input();
    output(2 * (good[r] - good[l - 1] -
                max(0, (open[n + l - 1] - Query(l, r + 1)))));
  }
  return 0;
}

```


### Prompt

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

Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.

Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").

Galya has already made k shots, all of them were misses.

Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.

It is guaranteed that there is at least one valid ships placement.

Input

The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.

The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.

Output

In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.

In the second line print the cells Galya should shoot at.

Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.

If there are multiple answers, you can print any of them.

Examples

Input

5 1 2 1
00100

Output

2
4 2

Input

13 3 2 3
1000000010001

Output

2
7 11

Note

There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > r;
vector<int> p, ans;
char s[200005];
int main() {
  int n, a, b, k;
  scanf("%d %d %d %d %s", &n, &a, &b, &k, s);
  int pre = 0;
  for (int(i) = (0); (i) <= (n - 1); (i)++)
    if (s[i] == '1') r.push_back(pair<int, int>(pre, i - 1)), pre = i + 1;
  if (pre != n) r.push_back(pair<int, int>(pre, n - 1));
  for (int(i) = (0); (i) <= (r.size() - 1); (i)++)
    for (int j = r[i].first + b - 1; j <= r[i].second; j += b) p.push_back(j);
  for (int(i) = (0); (i) <= (p.size() - a); (i)++) ans.push_back(p[i]);
  printf("%d\n", (int)ans.size());
  for (auto o : ans) printf("%d ", o + 1);
  putchar(10);
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Evlampiy was gifted a rooted tree. The vertices of the tree are numbered from 1 to n. Each of its vertices also has an integer a_i written on it. For each vertex i, Evlampiy calculated c_i — the number of vertices j in the subtree of vertex i, such that a_j < a_i.

<image>Illustration for the second example, the first integer is a_i and the integer in parentheses is c_i

After the new year, Evlampiy could not remember what his gift was! He remembers the tree and the values of c_i, but he completely forgot which integers a_i were written on the vertices.

Help him to restore initial integers!

Input

The first line contains an integer n (1 ≤ n ≤ 2000) — the number of vertices in the tree.

The next n lines contain descriptions of vertices: the i-th line contains two integers p_i and c_i (0 ≤ p_i ≤ n; 0 ≤ c_i ≤ n-1), where p_i is the parent of vertex i or 0 if vertex i is root, and c_i is the number of vertices j in the subtree of vertex i, such that a_j < a_i.

It is guaranteed that the values of p_i describe a rooted tree with n vertices.

Output

If a solution exists, in the first line print "YES", and in the second line output n integers a_i (1 ≤ a_i ≤ {10}^{9}). If there are several solutions, output any of them. One can prove that if there is a solution, then there is also a solution in which all a_i are between 1 and 10^9.

If there are no solutions, print "NO".

Examples

Input

3
2 0
0 2
2 0

Output

YES
1 2 1

Input

5
0 1
1 3
2 1
3 0
2 0

Output

YES
2 3 2 1 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mx = 105;
const long long maxn = 1e5 + 1;
const long long mod = 1000000007;
vector<long long> ans;
vector<vector<int>> adj;
vector<long long> c;
bool pos;
vector<long long> dfs(long long v, long long p) {
  long long i, j, k;
  vector<long long> te;
  for (i = 0; i < (int)adj[v].size(); i++) {
    if (adj[v][i] != p) {
      vector<long long> te1 = dfs(adj[v][i], v);
      te.insert(te.begin(), te1.begin(), te1.end());
    }
  }
  if (c[v] > (int)te.size()) {
    cout << "NO\n";
    exit(0);
  }
  te.insert(te.begin() + c[v], v);
  return te;
}
void solve() {
  long long n, i, j, k, p;
  cin >> n;
  pos = true;
  adj.clear();
  adj.resize(n + 1);
  c.clear();
  c.resize(n + 1);
  long long r;
  for (i = 1; i <= n; i++) {
    cin >> p >> c[i];
    if (p != 0) {
      adj[i].push_back(p);
      adj[p].push_back(i);
    } else {
      r = i;
    }
  }
  long long res[n + 1];
  ans = dfs(r, -1);
  if (pos) {
    for (i = 0; i < n; i++) {
      res[ans[i]] = i + 1;
    }
    cout << "YES\n";
    for (i = 1; i <= n; i++) cout << res[i] << " ";
    cout << "\n";
  } else {
    cout << "NO\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  long long n, i, j, k;
  while (t--) {
    solve();
  }
}

```


### Prompt

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

Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all.

Suppose the kid who recieves the minimum number of candies has a candies and the kid who recieves the maximum number of candies has b candies. Then Santa will be satisfied, if the both conditions are met at the same time:

  * b - a ≤ 1 (it means b = a or b = a + 1);
  * the number of kids who has a+1 candies (note that a+1 not necessarily equals b) does not exceed ⌊k/2⌋ (less than or equal to ⌊k/2⌋).

⌊k/2⌋ is k divided by 2 and rounded down to the nearest integer. For example, if k=5 then ⌊k/2⌋=⌊5/2⌋=2.

Your task is to find the maximum number of candies Santa can give to kids so that he will be satisfied.

You have to answer t independent test cases.

Input

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

The next t lines describe test cases. The i-th test case contains two integers n and k (1 ≤ n, k ≤ 10^9) — the number of candies and the number of kids.

Output

For each test case print the answer on it — the maximum number of candies Santa can give to kids so that he will be satisfied.

Example

Input

5
5 2
19 4
12 7
6 2
100000 50010

Output

5
18
10
6
75015

Note

In the first test case, Santa can give 3 and 2 candies to kids. There a=2, b=3,a+1=3.

In the second test case, Santa can give 5, 5, 4 and 4 candies. There a=4,b=5,a+1=5. The answer cannot be greater because then the number of kids with 5 candies will be 3.

In the third test case, Santa can distribute candies in the following way: [1, 2, 2, 1, 1, 2, 1]. There a=1,b=2,a+1=2. He cannot distribute two remaining candies in a way to be satisfied.

In the fourth test case, Santa can distribute candies in the following way: [3, 3]. There a=3, b=3, a+1=4. Santa distributed all 6 candies.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long temp = k;
    long long ans = (n / k) * k;
    n -= (n / k) * k;
    ans += min(k / 2, n);
    cout << ans << '\n';
  }
}

```


### Prompt

Please create a solution in CPP to the following problem:

Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs a points and Vasya solved the problem that costs b points. Besides, Misha submitted the problem c minutes after the contest started and Vasya submitted the problem d minutes after the contest started. As you know, on Codeforces the cost of a problem reduces as a round continues. That is, if you submit a problem that costs p points t minutes after the contest started, you get <image> points.

Misha and Vasya are having an argument trying to find out who got more points. Help them to find out the truth.

Input

The first line contains four integers a, b, c, d (250 ≤ a, b ≤ 3500, 0 ≤ c, d ≤ 180).

It is guaranteed that numbers a and b are divisible by 250 (just like on any real Codeforces round).

Output

Output on a single line:

"Misha" (without the quotes), if Misha got more points than Vasya.

"Vasya" (without the quotes), if Vasya got more points than Misha.

"Tie" (without the quotes), if both of them got the same number of points.

Examples

Input

500 1000 20 30

Output

Vasya

Input

1000 1000 1 1

Output

Tie

Input

1500 1000 176 177

Output

Misha

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  double a, b, c, d;
  while (cin >> a >> b >> c >> d) {
    double a1 = max((3 * a) / 10, a - (a / 250) * c);
    double b1 = max((3 * b) / 10, b - (b / 250) * d);
    if (a1 > b1) {
      cout << "Misha" << endl;
    } else if (a1 < b1) {
      cout << "Vasya" << endl;
    } else {
      cout << "Tie" << endl;
    }
  }
  return 0;
}

```


### Prompt

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

All modern mobile applications are divided into free and paid. Even a single application developers often release two versions: a paid version without ads and a free version with ads.

<image>

Suppose that a paid version of the app costs p (p is an integer) rubles, and the free version of the application contains c ad banners. Each user can be described by two integers: ai — the number of rubles this user is willing to pay for the paid version of the application, and bi — the number of banners he is willing to tolerate in the free version.

The behavior of each member shall be considered strictly deterministic:

  * if for user i, value bi is at least c, then he uses the free version,
  * otherwise, if value ai is at least p, then he buys the paid version without advertising,
  * otherwise the user simply does not use the application.

Each user of the free version brings the profit of c × w rubles. Each user of the paid version brings the profit of p rubles.

Your task is to help the application developers to select the optimal parameters p and c. Namely, knowing all the characteristics of users, for each value of c from 0 to (max bi) + 1 you need to determine the maximum profit from the application and the corresponding parameter p.

Input

The first line contains two integers n and w (1 ≤ n ≤ 105; 1 ≤ w ≤ 105) — the number of users and the profit from a single banner. Each of the next n lines contains two integers ai and bi (0 ≤ ai, bi ≤ 105) — the characteristics of the i-th user.

Output

Print (max bi) + 2 lines, in the i-th line print two integers: pay — the maximum gained profit at c = i - 1, p (0 ≤ p ≤ 109) — the corresponding optimal app cost. If there are multiple optimal solutions, print any of them.

Examples

Input

2 1
2 0
0 2

Output

0 3
3 2
4 2
2 2

Input

3 1
3 1
2 2
1 3

Output

0 4
3 4
7 3
7 2
4 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[1 << 16], *S, *T;
  if (S == T) {
    T = (S = buf) + fread(buf, 1, 1 << 16, stdin);
    if (T == S) return EOF;
  }
  return *S++;
}
inline int read() {
  int x = 0, f = 1;
  char ch = gc();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = gc();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = gc();
  return x * f;
}
int n, w, mxb, mxa, bel[100010], nn, cnt[350], q[350][350], qh[350], qt[350];
long long d[100010];
struct data {
  int a, b;
  friend bool operator<(data a, data b) { return a.b < b.b; }
} A[100010];
inline double slope(int i, int j) { return (d[i] - d[j]) * 1.0 / (j - i); }
inline void gao(int i, int x) {
  while (qh[i] < qt[i] && slope(q[i][qh[i]], q[i][qh[i] + 1]) <= x) ++qh[i];
}
inline void rebuild(int id, int l, int r) {
  qh[id] = 1;
  qt[id] = 0;
  for (int i = l; i <= r; ++i) {
    while (qh[id] < qt[id] &&
           slope(q[id][qt[id]], i) < slope(q[id][qt[id] - 1], q[id][qt[id]]))
      --qt[id];
    q[id][++qt[id]] = i;
  }
  gao(id, 0);
}
inline void add(int x) {
  if (!x) return;
  for (int i = 1; i < bel[x]; ++i) gao(i, ++cnt[i]);
  int l = (bel[x] - 1) * nn + 1, r = min(bel[x] * nn, mxa), id = bel[x];
  for (int i = l; i <= r; ++i) d[i] += (long long)cnt[id] * i;
  for (int i = l; i <= x; ++i) d[i] += i;
  cnt[id] = 0;
  rebuild(id, l, r);
}
int main() {
  n = read();
  w = read();
  for (int i = 1; i <= n; ++i)
    A[i].a = read(), A[i].b = read(), mxb = max(mxb, A[i].b),
    mxa = max(mxa, A[i].a);
  sort(A + 1, A + n + 1);
  int now = 1;
  nn = sqrt(mxa);
  for (int i = 1; i <= mxa; ++i) bel[i] = (i - 1) / nn + 1;
  int tot = bel[mxa];
  for (int i = 1; i <= tot; ++i) qh[i] = 1, q[i][++qt[i]] = min(i * nn, mxa);
  int flag = 0;
  for (int c = 0; c <= mxb + 1; ++c) {
    while (now <= n && A[now].b < c) add(A[now].a), ++now;
    long long ans = 0;
    int ans1 = 0;
    for (int i = 1; i <= tot; ++i) {
      int x = q[i][qh[i]];
      if (d[x] + (long long)x * cnt[i] > ans)
        ans = d[x] + (long long)x * cnt[i], ans1 = x;
    }
    printf("%I64d %d\n", ans + (long long)w * c * (n - now + 1), ans1);
    if (c == 1) flag = ans + (long long)w * c * (n - now + 1);
  }
  return 0;
}

```


### Prompt

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

Petya has come to the math exam and wants to solve as many problems as possible. He prepared and carefully studied the rules by which the exam passes.

The exam consists of n problems that can be solved in T minutes. Thus, the exam begins at time 0 and ends at time T. Petya can leave the exam at any integer time from 0 to T, inclusive.

All problems are divided into two types:

  * easy problems — Petya takes exactly a minutes to solve any easy problem;
  * hard problems — Petya takes exactly b minutes (b > a) to solve any hard problem.

Thus, if Petya starts solving an easy problem at time x, then it will be solved at time x+a. Similarly, if at a time x Petya starts to solve a hard problem, then it will be solved at time x+b.

For every problem, Petya knows if it is easy or hard. Also, for each problem is determined time t_i (0 ≤ t_i ≤ T) at which it will become mandatory (required). If Petya leaves the exam at time s and there is such a problem i that t_i ≤ s and he didn't solve it, then he will receive 0 points for the whole exam. Otherwise (i.e if he has solved all such problems for which t_i ≤ s) he will receive a number of points equal to the number of solved problems. Note that leaving at time s Petya can have both "mandatory" and "non-mandatory" problems solved.

For example, if n=2, T=5, a=2, b=3, the first problem is hard and t_1=3 and the second problem is easy and t_2=2. Then:

  * if he leaves at time s=0, then he will receive 0 points since he will not have time to solve any problems;
  * if he leaves at time s=1, he will receive 0 points since he will not have time to solve any problems;
  * if he leaves at time s=2, then he can get a 1 point by solving the problem with the number 2 (it must be solved in the range from 0 to 2);
  * if he leaves at time s=3, then he will receive 0 points since at this moment both problems will be mandatory, but he will not be able to solve both of them;
  * if he leaves at time s=4, then he will receive 0 points since at this moment both problems will be mandatory, but he will not be able to solve both of them;
  * if he leaves at time s=5, then he can get 2 points by solving all problems.

Thus, the answer to this test is 2.

Help Petya to determine the maximal number of points that he can receive, before leaving the exam.

Input

The first line contains the integer m (1 ≤ m ≤ 10^4) — the number of test cases in the test.

The next lines contain a description of m test cases.

The first line of each test case contains four integers n, T, a, b (2 ≤ n ≤ 2⋅10^5, 1 ≤ T ≤ 10^9, 1 ≤ a < b ≤ 10^9) — the number of problems, minutes given for the exam and the time to solve an easy and hard problem, respectively.

The second line of each test case contains n numbers 0 or 1, separated by single space: the i-th number means the type of the i-th problem. A value of 0 means that the problem is easy, and a value of 1 that the problem is hard.

The third line of each test case contains n integers t_i (0 ≤ t_i ≤ T), where the i-th number means the time at which the i-th problem will become mandatory.

It is guaranteed that the sum of n for all test cases does not exceed 2⋅10^5.

Output

Print the answers to m test cases. For each set, print a single integer — maximal number of points that he can receive, before leaving the exam.

Example

Input

10
3 5 1 3
0 0 1
2 1 4
2 5 2 3
1 0
3 2
1 20 2 4
0
16
6 20 2 5
1 1 0 1 0 0
0 8 2 9 11 6
4 16 3 6
1 0 1 1
8 3 5 6
6 20 3 6
0 1 0 0 1 0
20 11 3 20 16 17
7 17 1 6
1 1 0 1 0 0 0
1 7 0 11 10 15 10
6 17 2 6
0 0 1 0 0 1
7 6 3 7 10 12
5 17 2 5
1 1 1 1 0
17 11 10 6 4
1 1 1 2
0
1

Output

3
2
1
0
1
4
0
1
2
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int m;
  int count[200005][2];
  cin >> m;
  while (m--) {
    int n, a, b;
    long long T;
    cin >> n >> T >> a >> b;
    vector<pair<int, int> > problems(n + 1);
    for (int i = 1; i <= n; i++) {
      cin >> problems[i].second;
    }
    for (int i = 1; i <= n; i++) {
      cin >> problems[i].first;
    }
    sort(problems.begin(), problems.end());
    count[0][0] = 0;
    count[0][1] = 0;
    for (int i = 1; i <= n; i++) {
      count[i][problems[i].second] = count[i - 1][problems[i].second] + 1;
      count[i][problems[i].second ^ 1] = count[i - 1][problems[i].second ^ 1];
    }
    long long curr = 0;
    int res = 0;
    for (int i = 1; i <= n; i++) {
      long long spare = problems[i].first - 1 - curr;
      curr += problems[i].second ? b : a;
      if (spare < 0) continue;
      int res1 = i - 1;
      if (spare)
        for (int type = 0; type <= 1; type++) {
          long long currCount = count[n][type] - count[i - 1][type];
          long long solvable = min(spare / (type ? b : a), currCount);
          res1 += solvable;
          spare -= solvable * (type ? b : a);
        }
      res = max(res, res1);
    }
    if (T >= curr)
      cout << n << '\n';
    else
      cout << res << '\n';
  }
}

```


### Prompt

Please formulate a CPP solution to the following problem:

For an array b of length m we define the function f as

 f(b) = \begin{cases} b[1] &   if  m = 1 \\\ f(b[1] ⊕ b[2],b[2] ⊕ b[3],...,b[m-1] ⊕ b[m]) &   otherwise, \end{cases}

where ⊕ is [bitwise exclusive OR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).

For example, f(1,2,4,8)=f(1⊕2,2⊕4,4⊕8)=f(3,6,12)=f(3⊕6,6⊕12)=f(5,10)=f(5⊕10)=f(15)=15

You are given an array a and a few queries. Each query is represented as two integers l and r. The answer is the maximum value of f on all continuous subsegments of the array a_l, a_{l+1}, …, a_r.

Input

The first line contains a single integer n (1 ≤ n ≤ 5000) — the length of a.

The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^{30}-1) — the elements of the array.

The third line contains a single integer q (1 ≤ q ≤ 100 000) — the number of queries.

Each of the next q lines contains a query represented as two integers l, r (1 ≤ l ≤ r ≤ n).

Output

Print q lines — the answers for the queries.

Examples

Input

3
8 4 1
2
2 3
1 2

Output

5
12

Input

6
1 2 4 8 16 32
4
1 6
2 5
3 4
1 2

Output

60
30
12
3

Note

In first sample in both queries the maximum value of the function is reached on the subsegment that is equal to the whole segment.

In second sample, optimal segment for first query are [3,6], for second query — [2,5], for third — [3,4], for fourth — [1,2].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct IO {
  char buf[(1 << 20)], *p1, *p2;
  char pbuf[(1 << 20)], *pp;
  IO() : p1(buf), p2(buf), pp(pbuf) {}
  inline char gc() {
    return getchar();
    if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, (1 << 20), stdin);
    return p1 == p2 ? ' ' : *p1++;
  }
  inline bool blank(char ch) {
    return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
  }
  template <class T>
  inline void read(T &x) {
    register double tmp = 1;
    register bool sign = 0;
    x = 0;
    register char ch = gc();
    for (; !(ch >= '0' && ch <= '9'); ch = gc())
      if (ch == '-') sign = 1;
    for (; (ch >= '0' && ch <= '9'); ch = gc()) x = x * 10 + (ch - '0');
    if (ch == '.')
      for (ch = gc(); (ch >= '0' && ch <= '9'); ch = gc())
        tmp /= 10.0, x += tmp * (ch - '0');
    if (sign) x = -x;
  }
  inline void read(char *s) {
    register char ch = gc();
    for (; blank(ch); ch = gc())
      ;
    for (; !blank(ch); ch = gc()) *s++ = ch;
    *s = 0;
  }
  inline void read(char &c) {
    for (c = gc(); blank(c); c = gc())
      ;
  }
  template <class t>
  inline void write(t x) {
    if (x < 0)
      putchar('-'), write(-x);
    else {
      if (x > 9) write(x / 10);
      putchar('0' + x % 10);
    }
  }
} io;
const int mod = 1e9 + 7;
const int mo = 998244353;
const int N = 5005;
int n, m, a[N], f[N][N];
int main() {
  io.read(n);
  for (int i = (1); i <= (n); i++) io.read(a[i]), f[1][i] = a[i];
  for (int i = (2); i <= (n); i++)
    for (int j = (i); j <= (n); j++) f[i][j] = f[i - 1][j] ^ f[i - 1][j - 1];
  for (int i = (1); i <= (n); i++)
    for (int j = (i); j <= (n); j++)
      f[i][j] = max(max(f[i - 1][j], f[i - 1][j - 1]), f[i][j]);
  io.read(m);
  for (; m--;) {
    int l, r;
    io.read(l), io.read(r);
    io.write(f[r - l + 1][r]), puts("");
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.

The world can be modeled as an undirected graph with n nodes and m edges. k of the nodes are home to the governments of the k countries that make up the world.

There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.

Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add.

Input

The first line of input will contain three integers n, m and k (1 ≤ n ≤ 1 000, 0 ≤ m ≤ 100 000, 1 ≤ k ≤ n) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government.

The next line of input will contain k integers c1, c2, ..., ck (1 ≤ ci ≤ n). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world.

The following m lines of input will contain two integers ui and vi (1 ≤ ui, vi ≤ n). This denotes an undirected edge between nodes ui and vi.

It is guaranteed that the graph described by the input is stable.

Output

Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable.

Examples

Input

4 1 2
1 3
1 2

Output

2

Input

3 3 1
2
1 2
1 3
2 3

Output

0

Note

For the first sample test, the graph looks like this:

<image> Vertices 1 and 3 are special. The optimal solution is to connect vertex 4 to vertices 1 and 2. This adds a total of 2 edges. We cannot add any more edges, since vertices 1 and 3 cannot have any path between them.

For the second sample test, the graph looks like this:

<image> We cannot add any more edges to this graph. Note that we are not allowed to add self-loops, and the graph must be simple.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 10;
long long n, m, k, ans, tmp, sum, SIZ, MX;
long long a[N], comp[N], yal[N], sz[N];
vector<long long> nei[N];
vector<pair<long long, long long> > y;
bool mark[N], khas[N];
void read_input() {
  cin >> n >> m >> k;
  for (long long i = 0; i < k; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    y.push_back({u, v});
    nei[u].push_back(v);
    nei[v].push_back(u);
  }
}
void dfs(long long v) {
  sz[tmp]++;
  mark[v] = true;
  comp[v] = tmp;
  khas[v] = true;
  for (long long u : nei[v]) {
    if (!mark[u]) {
      dfs(u);
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  read_input();
  for (long long i = 0; i < k; i++) {
    tmp++;
    dfs(a[i]);
  }
  for (long long i = 0; i < y.size(); i++) {
    long long u = y[i].first;
    long long v = y[i].second;
    if (khas[u]) {
      yal[comp[u]]++;
    } else {
      sum++;
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (!khas[i]) {
      SIZ++;
    }
  }
  for (long long i = 1; i <= tmp; i++) {
    if (sz[i] > sz[MX]) {
      MX = i;
    }
  }
  for (long long i = 1; i <= tmp; i++) {
    long long yy = sz[i] * (sz[i] - 1) / 2;
    ans += yy - yal[i];
  }
  long long zz = SIZ * (SIZ - 1) / 2;
  ans += zz - sum;
  ans += sz[MX] * SIZ;
  cout << ans;
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai.

<image>

We decided to conduct a dating survey of visitors to Tsuruga Castle to use as a reference for future public relations activities in Aizuwakamatsu City. Please create a program that inputs the age of visitors and outputs the number of people by age group below.

Category | Age
--- | ---
Under 10 years old | 0 ~ 9
Teens | 10 ~ 19
20s | 20 ~ 29
30s | 30 ~ 39
40s | 40 ~ 49
50s | 50 ~ 59
Over 60 years old | 60 ~

Input

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

n
a1
a2
::
an

The first line gives the number of visitors n (1 ≤ n ≤ 1000000), and the following n lines give the age of the i-th visitor ai (0 ≤ ai ≤ 120).

Output

The number of people is output in the following format for each data set.

Line 1: Number of people under 10
Line 2: Number of teens
Line 3: Number of people in their 20s
Line 4: Number of people in their 30s
Line 5: Number of people in their 40s
Line 6: Number of people in their 50s
Line 7: Number of people over 60

Example

Input

8
71
34
65
11
41
39
6
5
4
67
81
78
65
0

Output

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

### Response

```cpp
#include <iostream>
int main(){int n,x,i;while(std::cin>>n,n){int dat[7]={};for(i=0;i<n;std::cin>>x,x=x/10>6?60:x,dat[x/10]++,i++);for(i=0;i<7;std::cout<<dat[i]<<'\n',i++);}}
```


### Prompt

Create a solution in cpp for the following problem:

You are given a bipartite graph: the first part of this graph contains n_1 vertices, the second part contains n_2 vertices, and there are m edges. The graph can contain multiple edges.

Initially, each edge is colorless. For each edge, you may either leave it uncolored (it is free), paint it red (it costs r coins) or paint it blue (it costs b coins). No edge can be painted red and blue simultaneously.

There are three types of vertices in this graph — colorless, red and blue. Colored vertices impose additional constraints on edges' colours:

  * for each red vertex, the number of red edges indicent to it should be strictly greater than the number of blue edges incident to it;
  * for each blue vertex, the number of blue edges indicent to it should be strictly greater than the number of red edges incident to it.

Colorless vertices impose no additional constraints.

Your goal is to paint some (possibly none) edges so that all constraints are met, and among all ways to do so, you should choose the one with minimum total cost.

Input

The first line contains five integers n_1, n_2, m, r and b (1 ≤ n_1, n_2, m, r, b ≤ 200) — the number of vertices in the first part, the number of vertices in the second part, the number of edges, the amount of coins you have to pay to paint an edge red, and the amount of coins you have to pay to paint an edge blue, respectively.

The second line contains one string consisting of n_1 characters. Each character is either U, R or B. If the i-th character is U, then the i-th vertex of the first part is uncolored; R corresponds to a red vertex, and B corresponds to a blue vertex.

The third line contains one string consisting of n_2 characters. Each character is either U, R or B. This string represents the colors of vertices of the second part in the same way.

Then m lines follow, the i-th line contains two integers u_i and v_i (1 ≤ u_i ≤ n_1, 1 ≤ v_i ≤ n_2) denoting an edge connecting the vertex u_i from the first part and the vertex v_i from the second part.

The graph may contain multiple edges.

Output

If there is no coloring that meets all the constraints, print one integer -1.

Otherwise, print an integer c denoting the total cost of coloring, and a string consisting of m characters. The i-th character should be U if the i-th edge should be left uncolored, R if the i-th edge should be painted red, or B if the i-th edge should be painted blue. If there are multiple colorings with minimum possible cost, print any of them.

Examples

Input

3 2 6 10 15
RRB
UB
3 2
2 2
1 2
1 1
2 1
1 1

Output

35
BUURRU

Input

3 1 3 4 5
RRR
B
2 1
1 1
3 1

Output

-1

Input

3 1 3 4 5
URU
B
2 1
1 1
3 1

Output

14
RBB

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int hed[1010], dis[1010], mn[1010], pre[1010], bh[1010], tot = 1, s, t, mxfl,
                                                         mincost;
bool in[1010];
struct edg {
  int to, nxt, f, v;
} e[2010000];
void add(int x, int y, int f, int v) {
  e[++tot] = (edg){y, hed[x], f, v};
  hed[x] = tot;
  e[++tot] = (edg){x, hed[y], 0, -v};
  hed[y] = tot;
}
void dfs(int x) {
  e[bh[x]].f -= mn[t];
  e[bh[x] ^ 1].f += mn[t];
  if (pre[x] != s) dfs(pre[x]);
}
queue<int> q;
bool spfa() {
  for (int i = 1; i <= t + 2; i++) dis[i] = 2e9;
  dis[s] = 0;
  mn[s] = 2e9;
  q.push(s);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    in[x] = 0;
    for (int i = hed[x]; i; i = e[i].nxt) {
      int to = e[i].to;
      if (dis[to] > dis[x] + e[i].v && e[i].f > 0) {
        dis[to] = dis[x] + e[i].v;
        mn[to] = min(mn[x], e[i].f);
        pre[to] = x;
        bh[to] = i;
        if (!in[to]) q.push(to), in[to] = 1;
      }
    }
  }
  if (dis[t] == 2e9) return 0;
  dfs(t);
  return 1;
}
void ek() {
  mxfl = 0;
  mincost = 0;
  while (spfa()) {
    mincost += dis[t] * mn[t];
    mxfl += mn[t];
  }
}
int n, m, k, a, b, S, T, ss, tt, x, y, d[1010], ans, sum;
void add1(int x, int y, int f, int v) {
  ans += v;
  d[x]--;
  d[y]++;
  add(x, y, f, v);
}
char ch1[1010], ch2[1010];
int main() {
  scanf("%d%d%d%d%d", &n, &m, &k, &a, &b);
  scanf("%s%s", ch1 + 1, ch2 + 1);
  S = n + m + 1, T = n + m + 2;
  ss = T + 1;
  tt = ss + 1;
  for (int i = 1; i <= k; i++) {
    scanf("%d%d", &x, &y);
    add(x, y + n, 1, a), add(y + n, x, 1, b);
  }
  for (int i = 1; i <= n; i++)
    if (ch1[i] == 'R')
      add1(ss, i, k, 0);
    else if (ch1[i] == 'B')
      add1(i, tt, k, 0);
    else
      add(ss, i, k, 0), add(i, tt, k, 0);
  for (int i = 1; i <= m; i++)
    if (ch2[i] == 'B')
      add1(ss, i + n, k, 0);
    else if (ch2[i] == 'R')
      add1(i + n, tt, k, 0);
    else
      add(ss, i + n, k, 0), add(i + n, tt, k, 0);
  add(tt, ss, 2e9, 0);
  for (int i = 1; i <= n + m + 4; i++)
    if (d[i] > 0)
      add(S, i, d[i], 0), sum += d[i];
    else if (d[i] < 0)
      add(i, T, -d[i], 0);
  s = S, t = T;
  ek();
  if (mxfl != sum) {
    printf("-1");
    return 0;
  }
  printf("%d\n", ans + mincost);
  for (int i = 0; i < k; i++) {
    if (!e[i * 4 + 2].f)
      printf("R");
    else if (!e[i * 4 + 4].f)
      printf("B");
    else
      printf("U");
  }
  return 0;
}

```