### Prompt

Construct a cpp code solution to the problem outlined:

Welcome! Everything is fine.

You have arrived in The Medium Place, the place between The Good Place and The Bad Place. You are assigned a task that will either make people happier or torture them for eternity.

You have a list of k pairs of people who have arrived in a new inhabited neighborhood. You need to assign each of the 2k people into one of the 2k houses. Each person will be the resident of exactly one house, and each house will have exactly one resident.

Of course, in the neighborhood, it is possible to visit friends. There are 2k - 1 roads, each of which connects two houses. It takes some time to traverse a road. We will specify the amount of time it takes in the input. The neighborhood is designed in such a way that from anyone's house, there is exactly one sequence of distinct roads you can take to any other house. In other words, the graph with the houses as vertices and the roads as edges is a tree.

The truth is, these k pairs of people are actually soulmates. We index them from 1 to k. We denote by f(i) the amount of time it takes for the i-th pair of soulmates to go to each other's houses.

As we have said before, you will need to assign each of the 2k people into one of the 2k houses. You have two missions, one from the entities in The Good Place and one from the entities of The Bad Place. Here they are:

  * The first mission, from The Good Place, is to assign the people into the houses such that the sum of f(i) over all pairs i is minimized. Let's define this minimized sum as G. This makes sure that soulmates can easily and efficiently visit each other;
  * The second mission, from The Bad Place, is to assign the people into the houses such that the sum of f(i) over all pairs i is maximized. Let's define this maximized sum as B. This makes sure that soulmates will have a difficult time to visit each other.

What are the values of G and B?

Input

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

The first line of each test case contains a single integer k denoting the number of pairs of people (1 ≤ k ≤ 10^5). The next 2k - 1 lines describe the roads; the i-th of them contains three space-separated integers a_i, b_i, t_i which means that the i-th road connects the a_i-th and b_i-th houses with a road that takes t_i units of time to traverse (1 ≤ a_i, b_i ≤ 2k, a_i ≠ b_i, 1 ≤ t_i ≤ 10^6). It is guaranteed that the given roads define a tree structure.

It is guaranteed that the sum of the k in a single file is at most 3 ⋅ 10^5.

Output

For each test case, output a single line containing two space-separated integers G and B.

Example

Input

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

Output

15 33
6 6

Note

For the sample test case, we have a minimum sum equal to G = 15. One way this can be achieved is with the following assignment:

  * The first pair of people get assigned to houses 5 and 6, giving us f(1) = 5;
  * The second pair of people get assigned to houses 1 and 4, giving us f(2) = 6;
  * The third pair of people get assigned to houses 3 and 2, giving us f(3) = 4.

Note that the sum of the f(i) is 5 + 6 + 4 = 15.

We also have a maximum sum equal to B = 33. One way this can be achieved is with the following assignment:

  * The first pair of people get assigned to houses 1 and 4, giving us f(1) = 6;
  * The second pair of people get assigned to houses 6 and 2, giving us f(2) = 14;
  * The third pair of people get assigned to houses 3 and 5, giving us f(3) = 13.

Note that the sum of the f(i) is 6 + 14 + 13 = 33.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n;
struct Edge {
  long long to, nxt, w;
} e[300005 << 1];
long long head[300005], tot;
void add(long long u, long long v, long long w) {
  e[tot].to = v;
  e[tot].w = w;
  e[tot].nxt = head[u];
  head[u] = tot++;
}
long long size[300005], val[300005];
void getsize(int u, int fa) {
  size[u] = 1;
  for (int i = head[u]; i != -1; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa) continue;
    val[v] = e[i].w;
    getsize(v, u);
    size[u] += size[v];
  }
}
long long ans1, ans2;
void dfs1(int u, int fa) {
  if (size[u] % 2) ans1 += val[u];
  for (int i = head[u]; i != -1; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa) continue;
    dfs1(v, u);
  }
}
void dfs2(int u, int fa) {
  long long tmp = min(size[u], n - size[u]);
  ans2 += tmp * val[u];
  for (int i = head[u]; i != -1; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa) continue;
    dfs2(v, u);
  }
}
void init() {
  memset(head, -1, sizeof head);
  tot = 0;
  ans1 = ans2 = 0;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    init();
    scanf("%d", &n);
    n <<= 1;
    for (int i = 1; i <= n - 1; i++) {
      long long u, v, w;
      scanf("%lld%lld%lld", &u, &v, &w);
      add(u, v, w);
      add(v, u, w);
    }
    getsize(1, 1);
    dfs1(1, 1);
    dfs2(1, 1);
    cout << ans1 << " " << ans2 << '\n';
  }
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

This morning, Roman woke up and opened the browser with n opened tabs numbered from 1 to n. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.

He decided to accomplish this by closing every k-th (2 ≤ k ≤ n - 1) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be b) and then close all tabs with numbers c = b + i ⋅ k that satisfy the following condition: 1 ≤ c ≤ n and i is an integer (it may be positive, negative or zero).

For example, if k = 3, n = 14 and Roman chooses b = 8, then he will close tabs with numbers 2, 5, 8, 11 and 14.

After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it e) and the amount of remaining social network tabs (s). Help Roman to calculate the maximal absolute value of the difference of those values |e - s| so that it would be easy to decide what to do next.

Input

The first line contains two integers n and k (2 ≤ k < n ≤ 100) — the amount of tabs opened currently and the distance between the tabs closed.

The second line consists of n integers, each of them equal either to 1 or to -1. The i-th integer denotes the type of the i-th tab: if it is equal to 1, this tab contains information for the test, and if it is equal to -1, it's a social network tab.

Output

Output a single integer — the maximum absolute difference between the amounts of remaining tabs of different types |e - s|.

Examples

Input

4 2
1 1 -1 1

Output

2

Input

14 3
-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1

Output

9

Note

In the first example we can choose b = 1 or b = 3. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, e = 2 and s = 0 and |e - s| = 2.

In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, x, dem = 0, dem1 = 0, a[150], out = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 1)
      dem++;
    else
      dem1++;
  }
  for (int i = 0; i < k; i++) {
    int x = dem, y = dem1;
    for (int j = i; j <= n; j += k) {
      if (a[j] == 1) x--;
      if (a[j] == -1) y--;
    }
    out = max(out, abs(x - y));
  }
  cout << out;
}

```


### Prompt

Create a solution in Cpp for the following problem:

One day a well-known sponsor of a well-known contest decided to give every participant of the contest a T-shirt as a present. A natural problem occurred: on the one hand, it is not clear how many T-shirts of what sizes should be ordered, and on the other hand, one doesn't want to order too many T-shirts (and we do not exactly paper the walls with the oversupply). After considerable brain racking and some pre-estimating, the sponsor representatives ordered a certain number of T-shirts of sizes S, M, L, XL and XXL. The T-shirts turned out to bring good luck, that's why on the contest day there built up a line of K participants willing to get one. Every contestant is characterized by his/her desired T-shirt size (so it happens that for all the participants it is also one of the sizes S, M, L, XL and XXL). The participants come up to get a T-shirt one by one and try to choose the most suitable one, choosing it like this. If there is still a T-shirt of the optimal size left, that he/she takes it without further ado. Otherwise the contestant would prefer to choose a T-shirt with the size as close to the optimal one as possible (the distance between neighboring sizes is considered equal to one). If the variant of choice is not unique, the contestant will take a T-shirt of a bigger size (in case he/she grows more). For example, for a person whose optimal size is L the preference list looks like this: L, XL, M, XXL, S. Using the data on how many T-shirts of every size had been ordered by the organizers, on the size of contestants in the line determine who got a T-shirt of what size.

Input

The first line contains five non-negative integers NS, NM, NL, NXL, NXXL not exceeding 1000 which represent the number of T-shirts of the corresponding sizes. The second line contains an integer K (1 ≤ K ≤ 1000) which represents the number of participants. The next K lines contain the optimal T-shirt sizes for the contestants. The sizes are given in the order in which the participants stand in the line. It is guaranteed that NS + NM + NL + NXL + NXXL ≥ K.

Output

For each contestant, print a line containing the size of the T-shirt he/she got.

Examples

Input

1 0 2 0 1
3
XL
XXL
M

Output

XXL
L
L

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[5];
  for (int i = 0; i < 5; ++i) cin >> a[i];
  int count;
  cin >> count;
  string tmp;
  string prS;
  for (int i = 0; i < count; ++i) {
    cin >> tmp;
    int size;
    if (tmp == "S" || tmp == "s")
      size = 0;
    else if (tmp == "M" || tmp == "m")
      size = 1;
    else if (tmp == "L" || tmp == "l")
      size = 2;
    else if (tmp == "XL" || tmp == "xl")
      size = 3;
    else
      size = 4;
    int pSize;
    if (a[size] > 0) {
      a[size]--;
      pSize = size;
    } else
      for (int k = 1; k < 5; ++k) {
        if (size + k < 5 && a[size + k] > 0) {
          a[size + k]--;
          pSize = size + k;
          break;
        } else if (size - k >= 0 && a[size - k] > 0) {
          a[size - k]--;
          pSize = size - k;
          break;
        }
      }
    if (pSize == 0)
      prS += "S\n";
    else if (pSize == 1)
      prS += "M\n";
    else if (pSize == 2)
      prS += "L\n";
    else if (pSize == 3)
      prS += "XL\n";
    else if (pSize == 4)
      prS += "XXL\n";
  }
  cout << prS;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

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

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

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

Input

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

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

Output

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

Examples

Input

5 4
5 -1 3 4 -1

Output

5

Input

3 0
-1 2 -3

Output

4

Input

4 -1
-2 1 -2 3

Output

3

Note

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  char c = getchar();
  bool f = 0;
  for (; c > '9' || c < '0'; f = c == '-', c = getchar())
    ;
  for (; c >= '0' && c <= '9'; x = (x << 1) + (x << 3) + c - '0', c = getchar())
    ;
  return f ? -x : x;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + 48);
}
const int N = 200000 + 10;
long long has[N], sum[N], a[N], t, ans;
int n, c[N];
void modify(int x, int v) {
  for (; x <= *has; x += x & -x) c[x] += v;
}
int query(int x) {
  int res = 0;
  for (; x; x -= x & -x) res += c[x];
  return res;
}
int solve(long long x) {
  if (has[1] >= x) return 0;
  int pos =
      has[*has] < x ? *has : lower_bound(has + 1, has + *has + 1, x) - has - 1;
  return query(pos);
}
int main() {
  n = read(), t = read();
  for (int i = 1; i <= n; ++i) {
    a[i] = read();
    sum[i] = sum[i - 1] + a[i];
    has[i] = sum[i];
  }
  sort(has + 1, has + n + 1);
  *has = unique(has + 1, has + n + 1) - has - 1;
  for (int i = 1; i <= n; ++i) {
    int x = lower_bound(has + 1, has + *has + 1, sum[i]) - has;
    modify(x, 1);
  }
  for (int i = 0; i < n; ++i) {
    ans += solve(t + sum[i]);
    int x = lower_bound(has + 1, has + *has + 1, sum[i + 1]) - has;
    modify(x, -1);
  }
  write(ans);
  puts("");
}

```


### Prompt

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

Write a program of the Bubble Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:

BubbleSort(A)
1 for i = 0 to A.length-1
2     for j = A.length-1 downto i+1
3         if A[j] < A[j-1]
4             swap A[j] and A[j-1]

Note that, indices for array elements are based on 0-origin.

Your program should also print the number of swap operations defined in line 4 of the pseudocode.

Constraints

1 ≤ N ≤ 100

Input

The first line of the input includes an integer N, the number of elements in the sequence.

In the second line, N elements of the sequence are given separated by spaces characters.

Output

The output consists of 2 lines.

In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character.

In the second line, please print the number of swap operations.

Examples

Input

5
5 3 2 4 1

Output

1 2 3 4 5
8

Input

6
5 2 4 6 1 3

Output

1 2 3 4 5 6
9

### Response

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

void bubblesort(int A[100], int N){
  int cnt=0;

  for(int i=0;i<N;i++){
    for(int j=N-1;j>i;j--){
      if(A[j]<A[j-1]){
        swap(A[j],A[j-1]);
        cnt++;}
    }
}
  for(int k=0;k<N-1;k++)cout <<A[k]<<" ";
  cout <<A[N-1]<<endl;
cout <<cnt<<endl;}

int main(){
  int N,A[100];
  cin>>N;
  for(int i=0;i<N;i++)cin>>A[i];
  bubblesort(A,N);
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

Valera is a coder. Recently he wrote a funny program. The pseudo code for this program is given below:

    //input: integers x, k, p
    a = x;
    for(step = 1; step <= k; step = step + 1){
        rnd = [random integer from 1 to 100];
        if(rnd <= p)
            a = a * 2;
        else
            a = a + 1;
    }

    s = 0;

    while(remainder after dividing a by 2 equals 0){
        a = a / 2;
        s = s + 1;
    }

Now Valera wonders: given the values x, k and p, what is the expected value of the resulting number s?

Input

The first line of the input contains three integers x, k, p (1 ≤ x ≤ 109; 1 ≤ k ≤ 200; 0 ≤ p ≤ 100).

Output

Print the required expected value. Your answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.

Examples

Input

1 1 50

Output

1.0000000000000

Input

5 3 0

Output

3.0000000000000

Input

5 3 25

Output

1.9218750000000

Note

If the concept of expected value is new to you, you can read about it by the link:

http://en.wikipedia.org/wiki/Expected_value

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double eps(1e-8);
int x, k, p;
double dp[2][210];
int main() {
  scanf("%d %d %d", &x, &k, &p);
  double P = p / 100.;
  for (int i = 0; i <= k + 1; i++) {
    int tmp = x + i;
    while (!(tmp & 1)) tmp >>= 1, dp[0][i] += 1.;
  }
  int now = 0;
  for (int i = 0; i < k; i++) {
    memset(dp[now ^ 1], 0, sizeof(dp[now ^ 1]));
    for (int j = 0; j <= k; j++) {
      dp[now ^ 1][j << 1] += (dp[now][j] + 1) * P;
      dp[now ^ 1][j] += dp[now][j + 1] * (1 - P);
    }
    now ^= 1;
  }
  printf("%.10f\n", dp[now][0]);
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.

<image>

Polina came up with a new game called "Hyperset". In her game, there are n cards with k features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k = 4.

Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.

Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.

Input

The first line of each test contains two integers n and k (1 ≤ n ≤ 1500, 1 ≤ k ≤ 30) — number of cards and number of features.

Each of the following n lines contains a card description: a string consisting of k letters "S", "E", "T". The i-th character of this string decribes the i-th feature of that card. All cards are distinct.

Output

Output a single integer — the number of ways to choose three cards that form a set.

Examples

Input

3 3
SET
ETS
TSE

Output

1

Input

3 4
SETE
ETSE
TSES

Output

0

Input

5 4
SETT
TEST
EEET
ESTE
STES

Output

2

Note

In the third example test, these two triples of cards are sets:

  1. "SETT", "TEST", "EEET"
  2. "TEST", "ESTE", "STES"

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<string> str(1500);
map<string, int> mp;
map<string, int>::iterator it;
string word;
void call(string ff, string ss, long long sz) {
  for (long long i = 0; i < sz; i++) {
    if (ff[i] == ss[i])
      word += ff[i];
    else
      word += 'S' + 'E' + 'T' - ff[i] - ss[i];
  }
}
int main() {
  long long n, i, j, k, cnt;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> str[i];
    mp.insert({str[i], 0});
  }
  for (i = 0, cnt = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      if (i != j) {
        call(str[i], str[j], k);
        it = mp.find(word);
        if (it != mp.end()) cnt++;
        word.clear();
      }
    }
  }
  cout << cnt / 3 << endl;
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Jeff loves regular bracket sequences.

Today Jeff is going to take a piece of paper and write out the regular bracket sequence, consisting of nm brackets. Let's number all brackets of this sequence from 0 to nm - 1 from left to right. Jeff knows that he is going to spend ai mod n liters of ink on the i-th bracket of the sequence if he paints it opened and bi mod n liters if he paints it closed.

You've got sequences a, b and numbers n, m. What minimum amount of ink will Jeff need to paint a regular bracket sequence of length nm?

Operation x mod y means taking the remainder after dividing number x by number y.

Input

The first line contains two integers n and m (1 ≤ n ≤ 20; 1 ≤ m ≤ 107; m is even). The next line contains n integers: a0, a1, ..., an - 1 (1 ≤ ai ≤ 10). The next line contains n integers: b0, b1, ..., bn - 1 (1 ≤ bi ≤ 10). The numbers are separated by spaces.

Output

In a single line print the answer to the problem — the minimum required amount of ink in liters.

Examples

Input

2 6
1 2
2 1

Output

12

Input

1 10000000
2
3

Output

25000000

Note

In the first test the optimal sequence is: ()()()()()(), the required number of ink liters is 12.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
int n, m;
long long a[25], b[25];
long long A[25][25], B[25][25], f[25][25];
void init(long long a[25][25]) {
  memset(a, 0x3f, sizeof(A));
  for (int i = 0; i <= n; i++) a[i][i] = 0;
}
void mul(long long a[][25], long long b[][25], long long c[][25]) {
  static long long tmp[25][25];
  memset(tmp, 0x3f, sizeof(A));
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++)
      for (int k = 0; k <= n; k++)
        tmp[i][j] = min(tmp[i][j], a[i][k] + b[k][j]);
  memcpy(c, tmp, sizeof(tmp));
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  init(A), init(f);
  for (int k = 1; k <= n; k++) {
    init(B);
    for (int i = 0; i <= n; i++)
      for (int j = 0; j <= n; j++)
        i + 1 == j   ? B[j][i] = a[k]
        : j + 1 == i ? B[j][i] = b[k]
                     : B[j][i] = INF;
    mul(B, A, A);
  }
  for (; m; m >>= 1, mul(A, A, A))
    if (m & 1) mul(f, A, f);
  cout << f[0][0] << endl;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

You are a student looking for a job. Today you had an employment examination for an IT company. They asked you to write an efficient program to perform several operations. First, they showed you an N \times N square matrix and a list of operations. All operations but one modify the matrix, and the last operation outputs the character in a specified cell. Please remember that you need to output the final matrix after you finish all the operations.

Followings are the detail of the operations:

WR r c v
(Write operation) write a integer v into the cell (r,c) (1 \leq v \leq 1,000,000)
CP r1 c1 r2 c2
(Copy operation) copy a character in the cell (r1,c1) into the cell (r2,c2)
SR r1 r2
(Swap Row operation) swap the r1-th row and r2-th row
SC c1 c2
(Swap Column operation) swap the c1-th column and c2-th column
RL
(Rotate Left operation) rotate the whole matrix in counter-clockwise direction by 90 degrees
RR
(Rotate Right operation) rotate the whole matrix in clockwise direction by 90 degrees
RH
(Reflect Horizontal operation) reverse the order of the rows
RV
(Reflect Vertical operation) reverse the order of the columns

Input

First line of each testcase contains nine integers. First two integers in the line, N and Q, indicate the size of matrix and the number of queries, respectively (1 \leq N,Q \leq 40,000). Next three integers, A B, and C, are coefficients to calculate values in initial matrix (1 \leq A,B,C \leq 1,000,000), and they are used as follows: A_{r,c} = (r * A + c * B) mod C where r and c are row and column indices, respectively (1\leq r,c\leq N). Last four integers, D, E, F, and G, are coefficients to compute the final hash value mentioned in the next section (1 \leq D \leq E \leq N, 1 \leq F \leq G \leq N, E - D \leq 1,000, G - F \leq 1,000). Each of next Q lines contains one operation in the format as described above.

Output

Output a hash value h computed from the final matrix B by using following pseudo source code.

h <- 314159265
for r = D...E
for c = F...G
h <- (31 * h + B_{r,c}) mod 1,000,000,007

where "<-" is a destructive assignment operator, "for i = S...T" indicates a loop for i from S to T (both inclusive), and "mod" is a remainder operation.

Examples

Input

2 1 3 6 12 1 2 1 2
WR 1 1 1

Output

676573821

Input

2 1 3 6 12 1 2 1 2
RL

Output

676636559

Input

2 1 3 6 12 1 2 1 2
RH

Output

676547189

Input

39989 6 999983 999979 999961 1 1000 1 1000
SR 1 39989
SC 1 39989
RL
RH
RR
RV

Output

458797120

### Response

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

using ll = long long;
using pii = pair<int, int>;

constexpr int mod = 1e9 + 7;

constexpr int rev_tbl[2][4][2] = { // [mir][rot][row/col]
    {{0, 0}, {1, 0}, {1, 1}, {0, 1}},
    {{0, 1}, {1, 1}, {1, 0}, {0, 0}}
};

int main() {
    ll n, q, A, B, C, D, E, F, G;
    cin >> n >> q >> A >> B >> C >> D >> E >> F >> G;

    vector<string> op(q);
    vector<int> w(q), x(q), y(q), z(q);
    for(int i = 0; i < q; ++i) {
        cin >> op[i];
        if(op[i] == "WR") cin >> w[i] >> x[i] >> y[i];
        else if(op[i] == "CP") cin >> w[i] >> x[i] >> y[i] >> z[i];
        else if(op[i] == "SR") cin >> w[i] >> x[i];
        else if(op[i] == "SC") cin >> w[i] >> x[i];
    }

    int mir = 0, rot = 0;
    vector<int> ridx(n), cidx(n);
    iota(begin(ridx), end(ridx), 1);
    iota(begin(cidx), end(cidx), 1);
    auto get_r_idx = [&] (int r) -> int& {
        const int i = (rev_tbl[mir][rot][0] ? n - r : r - 1);
        return rot & 1 ? cidx[i] : ridx[i];
    };
    auto get_c_idx = [&] (int c) -> int& {
        const int i = (rev_tbl[mir][rot][1] ? n - c : c - 1);
        return rot & 1 ? ridx[i] : cidx[i];
    };
    auto get_orig_pos = [&] (int r, int c) {
        if(rot & 1) return make_pair(get_c_idx(c), get_r_idx(r));
        else        return make_pair(get_r_idx(r), get_c_idx(c));
    };
    map<pii, int> v;
    for(int i = 0; i < q; ++i) {
        if(op[i] == "WR") {
            int r, c; tie(r, c) = get_orig_pos(w[i], x[i]);
            v[{r, c}] = y[i];
        } else if(op[i] == "CP") {
            int r1, c1, r2, c2;
            tie(r1, c1) = get_orig_pos(w[i], x[i]);
            tie(r2, c2) = get_orig_pos(y[i], z[i]);
            if(v.count({r1, c1})) {
                v[{r2, c2}] = v[{r1, c1}];
            } else {
                v[{r2, c2}] = (r1 * A + c1 * B) % C;
            }
        } else if(op[i] == "SR") {
            swap(get_r_idx(w[i]), get_r_idx(x[i]));
        } else if(op[i] == "SC") {
            swap(get_c_idx(w[i]), get_c_idx(x[i]));
        } else if(op[i] == "RL") {
            if(mir) rot = (rot + 3) % 4;
            else    rot = (rot + 1) % 4;
        } else if(op[i] == "RR") {
            if(mir) rot = (rot + 1) % 4;
            else    rot = (rot + 3) % 4;
        } else if(op[i] == "RH") {
            mir = !mir;
            rot = (rot + 2) % 4;
        } else if(op[i] == "RV") {
            mir = !mir;
        }
    }

    ll h = 314159265;
    for(int r = D; r <= E; ++r) {
        for(int c = F; c <= G; ++c) {
            int rr, cc; tie(rr, cc) = get_orig_pos(r, c);
            const ll val = v.count({rr, cc}) ? v[{rr, cc}] : (rr * A + cc * B) % C;
            h = (h * 31 + val) % mod;
        }
    }
    cout << h << endl;
}

```


### Prompt

Generate a cpp solution to the following problem:

You are involved in the development of a certain game. The game is for players to explore randomly generated dungeons. As a specification of the game, I want to show the player the danger level of the dungeon in advance and select whether to search for the generated dungeon or to regenerate a new dungeon.

There are n rooms in the dungeon generated by this game, and they are numbered from 0 to n-1. The rooms are connected by a passage. There are a total of n-1 passages connecting rooms. The passage can go in either direction. In addition, a distance is set between the rooms. In the generated dungeon, it is possible to go from one room to all other rooms via several passages. Then, when the player plays the game, two different rooms are selected as the start point and the goal point.

You decide to decide how to evaluate the risk in order to evaluate the dungeon. First, the risk level when moving from one room to another is set to the value of the most costly passage among the passages used to move between rooms in the shortest time. Then, we decided to set the risk level of the dungeon as the sum of the risk levels when moving between a pair of rooms where i <j.

A randomly generated dungeon is given as input. First, calculate the risk of moving for all room pairs where i <j. Then output the sum as the answer to the problem.

Input

The input is given in the following format.

n
a1 b1 c1
..
..
..
an-1 bn-1 cn-1

ai bi ci means that the distance of the passage connecting the rooms ai and bi is ci.

Input meets the following constraints
2 ≤ n ≤ 200,000
0 ≤ ai, bi <n
0 ≤ ci ≤ 100,000

Output

Print the answer value on one line

Examples

Input

4
0 1 3
1 2 5
1 3 2

Output

23

Input

6
0 2 5
2 1 1
2 3 10
3 5 4
3 4 2

Output

111

### Response

```cpp
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
using namespace std;
class QuickUnionFind {
private:
	int size_; std::vector<int> g; std::vector<std::vector<int> > v;
public:
	QuickUnionFind() : size_(0), g(std::vector<int>()), v(std::vector<std::vector<int> >()) {};
	QuickUnionFind(int size__) : size_(size__) {
		g.resize(size_); v.resize(size_);
		for (int i = 0; i < size_; i++) g[i] = i, v[i] = { i };
	};
	int size() { return size_; }
	int root(int x) { return g[x]; }
	int size(int x) { return v[x].size(); }
	bool same(int x, int y) { return g[x] == g[y]; }
	void unite(int x, int y) {
		x = g[x], y = g[y];
		if (x == y) return;
		if (v[x].size() < v[y].size()) std::swap(x, y);
		v[x].insert(v[x].end(), v[y].begin(), v[y].end());
		for (auto &e : v[y]) g[e] = x;
		v[y].clear();
	}
	std::vector<int> connected(int x) { return v[g[x]]; }
	bool operator==(const QuickUnionFind& u) { return g == u.g; }
	bool operator!=(const QuickUnionFind& u) { return g != u.g; }
};
long long n, a[2000000], b[200000], c[200000], ret;
vector<tuple<int, int, int>>tup;
int main() {
	cin >> n; for (int i = 0; i < n - 1; i++) { cin >> a[i] >> b[i] >> c[i]; tup.push_back(make_tuple(c[i], a[i], b[i])); }
	sort(tup.begin(), tup.end()); QuickUnionFind UF(n);
	for (int i = 0; i < tup.size(); i++) {
		long long a1 = get<0>(tup[i]), a2 = get<1>(tup[i]), a3 = get<2>(tup[i]);
		ret += 1LL * a1*UF.size(UF.root(a2))*UF.size(UF.root(a3)); UF.unite(a2, a3);
	}
	cout << ret << endl;
	return 0;
}
```


### Prompt

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

N persons are standing in a row. The height of the i-th person from the front is A_i.

We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:

Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool.

Find the minimum total height of the stools needed to meet this goal.

Constraints

* 1 \leq N \leq 2\times 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

Print the minimum total height of the stools needed to meet the goal.

Examples

Input

5
2 1 5 4 3

Output

4

Input

5
3 3 3 3 3

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,n,maxL=0; cin>>n>>maxL;
  long long sum=0;
  for(int i=0;i<n-1;i++){
    cin>>a;
    if(maxL>a) sum+=maxL-a;
    else maxL=a;
  }
  cout<<sum;
}
```


### Prompt

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

Mike is trying rock climbing but he is awful at it.

There are n holds on the wall, i-th hold is at height ai off the ground. Besides, let the sequence ai increase, that is, ai < ai + 1 for all i from 1 to n - 1; we will call such sequence a track. Mike thinks that the track a1, ..., an has difficulty <image>. In other words, difficulty equals the maximum distance between two holds that are adjacent in height.

Today Mike decided to cover the track with holds hanging on heights a1, ..., an. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1, 2, 3, 4, 5) and remove the third element from it, we obtain the sequence (1, 2, 4, 5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.

Help Mike determine the minimum difficulty of the track after removing one hold.

Input

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

The next line contains n space-separated integers ai (1 ≤ ai ≤ 1000), where ai is the height where the hold number i hangs. The sequence ai is increasing (i.e. each element except for the first one is strictly larger than the previous one).

Output

Print a single number — the minimum difficulty of the track after removing a single hold.

Examples

Input

3
1 4 6

Output

5

Input

5
1 2 3 4 5

Output

2

Input

5
1 2 3 7 8

Output

4

Note

In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.

In the second test after removing every hold the difficulty equals 2.

In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int n, k;
map<int, int> m;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int maxx = 0, ans = 1e8;
  for (int i = 1; i < n - 1; i++) {
    maxx = 0;
    for (int j = 1; j < n; j++) {
      if (j == i) {
        j++;
        maxx = max(maxx, v[j] - v[j - 2]);
      } else {
        maxx = max(maxx, v[j] - v[j - 1]);
      }
    }
    ans = min(ans, maxx);
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?

There are n students living in a building, and for each of them the favorite drink a_i is known. So you know n integers a_1, a_2, ..., a_n, where a_i (1 ≤ a_i ≤ k) is the type of the favorite drink of the i-th student. The drink types are numbered from 1 to k.

There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are k types of drink sets, the j-th type contains two portions of the drink j. The available number of sets of each of the k types is infinite.

You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly ⌈ n/2 ⌉, where ⌈ x ⌉ is x rounded up.

After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if n is odd then one portion will remain unused and the students' teacher will drink it.

What is the maximum number of students that can get their favorite drink if ⌈ n/2 ⌉ sets will be chosen optimally and students will distribute portions between themselves optimally?

Input

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 1 000) — the number of students in the building and the number of different drinks.

The next n lines contain student's favorite drinks. The i-th line contains a single integer from 1 to k — the type of the favorite drink of the i-th student.

Output

Print exactly one integer — the maximum number of students that can get a favorite drink.

Examples

Input

5 3
1
3
1
1
2

Output

4

Input

10 3
2
1
3
2
3
3
1
3
1
2

Output

9

Note

In the first example, students could choose three sets with drinks 1, 1 and 2 (so they will have two sets with two drinks of the type 1 each and one set with two drinks of the type 2, so portions will be 1, 1, 1, 1, 2, 2). This way all students except the second one will get their favorite drinks.

Another possible answer is sets with drinks 1, 2 and 3. In this case the portions will be 1, 1, 2, 2, 3, 3. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with a_i = 1 (i.e. the first, the third or the fourth).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a, b, c, l, r, x[2000000], y, z, man, mix, d[2000000], ans, ans1;
vector<long long> v1, v;
int main() {
  cin >> a >> b;
  for (int i = 0; i < a; i++) {
    cin >> d[i];
    x[d[i]]++;
  }
  ans1 = (a + 1) / 2;
  for (int i = 1; i <= b; i++) {
    if (x[i] % 2 == 0) {
      ans += x[i];
      ans1 -= x[i] / 2;
    }
  }
  for (int i = 1; i <= b; i++) {
    if (x[i] % 2 == 1) {
      ans1 -= x[i] / 2;
      ans += x[i] - 1;
    }
  }
  cout << ans + ans1;
}

```


### Prompt

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

Nastya likes reading and even spends whole days in a library sometimes. Today she found a chronicle of Byteland in the library, and it stated that there lived shamans long time ago. It is known that at every moment there was exactly one shaman in Byteland, and there were n shamans in total enumerated with integers from 1 to n in the order they lived. Also, each shaman had a magic power which can now be expressed as an integer.

The chronicle includes a list of powers of the n shamans. Also, some shamans can be king-shamans, if they gathered all the power of their predecessors, i.e. their power is exactly the sum of powers of all previous shamans. Nastya is interested in whether there was at least one king-shaman in Byteland.

Unfortunately many of the powers are unreadable in the list, so Nastya is doing the following:

  * Initially she supposes some power for each shaman.
  * After that she changes the power of some shaman q times (the shamans can differ) and after that wants to check if there is at least one king-shaman in the list. If yes, she wants to know the index of any king-shaman.

Unfortunately the list is too large and Nastya wants you to help her.

Input

The first line contains two integers n and q (1 ≤ n, q ≤ 2·105).

The second line contains n integers a1, ..., an (0 ≤ ai ≤ 109), where ai is the magic power of the i-th shaman.

After that q lines follow, the i-th of them contains two integers pi and xi (1 ≤ pi ≤ n, 0 ≤ xi ≤ 109) that mean that the new power of the pi-th shaman is xi.

Output

Print q lines, the i-th of them should contain  - 1, if after the i-th change there are no shaman-kings, and otherwise a single integer j, where j is an index of some king-shaman after the i-th change.

If there are multiple king-shamans after each change, print the index of any of them.

Examples

Input

2 1
1 3
1 2

Output

-1

Input

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

Output

3
2
-1
3

Input

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

Output

1
-1
9
-1
4
-1
1

Note

In the first example powers of shamans after the first change are equal to (2, 3). The answer equals  - 1, because the sum of powers of shamans before the first shaman is equal to 0, and before the second is equal to 2.

In the second example after the first change the powers are equal to (1, 2, 3). The answer is equal to 3, because the power of the third shaman is equal to 3, and the sum of powers of the first and the second shaman is also 1 + 2 = 3. After the second change the powers become equal to (2, 2, 3), where the answer equals 2. After the third change the powers become equal to (2, 4, 3), where the answer equals  - 1. After the fourth change the powers become equal to (2, 4, 6), where the answer equals 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
template <typename T>
void ckmin(T& a, const T& b) {
  a = min(a, b);
}
template <typename T>
void ckmax(T& a, const T& b) {
  a = max(a, b);
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
struct binary_indexed_tree {
  int S;
  vector<T> table;
  binary_indexed_tree<T>(int _S = 0) : S(_S) { table.resize(S + 1); }
  void add(int i, T v) {
    for (i++; i <= S; i += i & -i) table[i] = table[i] + v;
  }
  T sum(int i) const {
    T res = T();
    for (; i; i -= i & -i) res = res + table[i];
    return res;
  }
  T sum(int l, int r) const { return sum(r) - sum(l); }
  int lower_bound(const function<bool(T)>& comp) const {
    int inx = 0;
    T cur = T();
    for (int i = 31 - __builtin_clz(S); i >= 0; i--) {
      int nxt = inx + (1 << i);
      if (nxt <= S && !comp(cur + table[nxt])) {
        inx = nxt;
        cur = cur + table[nxt];
      }
    }
    return inx < S ? inx + 1 : -1;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int N, Q;
  cin >> N >> Q;
  binary_indexed_tree<ll> sh(N);
  vi pow(N);
  for (int i = 0; i < N; i++) {
    cin >> pow[i];
    sh.add(i, pow[i]);
  }
  for (int q = 0, i, v; q < Q; q++) {
    cin >> i >> v;
    --i;
    sh.add(i, v - pow[i]);
    pow[i] = v;
    int used = 1;
    ll sum = sh.sum(used);
    while (true) {
      if (2 * pow[used - 1] == sum) {
        cout << used << "\n";
        break;
      }
      int jump = sh.lower_bound([&sum](ll tot) { return tot >= 2 * sum; });
      if (jump == -1) {
        cout << "-1\n";
        break;
      }
      used = jump;
      sum = sh.sum(used);
    }
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For example, if n = 6 then Funt has to pay 3 burles, while for n = 25 he needs to pay 5 and if n = 2 he pays only 1 burle.

As mr. Funt is a very opportunistic person he wants to cheat a bit. In particular, he wants to split the initial n in several parts n1 + n2 + ... + nk = n (here k is arbitrary, even k = 1 is allowed) and pay the taxes for each part separately. He can't make some part equal to 1 because it will reveal him. So, the condition ni ≥ 2 should hold for all i from 1 to k.

Ostap Bender wonders, how many money Funt has to pay (i.e. minimal) if he chooses and optimal way to split n in parts.

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 2·109) — the total year income of mr. Funt.

Output

Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax.

Examples

Input

4

Output

2

Input

27

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool check(long long n) {
  bool is = true;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      is = false;
      break;
    }
  }
  return is;
}
int main() {
  long long n;
  scanf("%I64d", &n);
  bool is = check(n);
  int ans;
  if (is)
    ans = 1;
  else {
    if (n % 2 == 0)
      ans = 2;
    else {
      ans = 3;
      if (check(n - 2)) ans = 2;
    }
  }
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

You are given an array a, consisting of n integers.

Each position i (1 ≤ i ≤ n) of the array is either locked or unlocked. You can take the values on the unlocked positions, rearrange them in any order and place them back into the unlocked positions. You are not allowed to remove any values, add the new ones or rearrange the values on the locked positions. You are allowed to leave the values in the same order as they were.

For example, let a = [-1, 1, \underline{3}, 2, \underline{-2}, 1, -4, \underline{0}], the underlined positions are locked. You can obtain the following arrays:

  * [-1, 1, \underline{3}, 2, \underline{-2}, 1, -4, \underline{0}];
  * [-4, -1, \underline{3}, 2, \underline{-2}, 1, 1, \underline{0}];
  * [1, -1, \underline{3}, 2, \underline{-2}, 1, -4, \underline{0}];
  * [1, 2, \underline{3}, -1, \underline{-2}, -4, 1, \underline{0}];
  * and some others.

Let p be a sequence of prefix sums of the array a after the rearrangement. So p_1 = a_1, p_2 = a_1 + a_2, p_3 = a_1 + a_2 + a_3, ..., p_n = a_1 + a_2 + ... + a_n.

Let k be the maximum j (1 ≤ j ≤ n) such that p_j < 0. If there are no j such that p_j < 0, then k = 0.

Your goal is to rearrange the values in such a way that k is minimum possible.

Output the array a after the rearrangement such that the value k for it is minimum possible. If there are multiple answers then print any of them.

Input

The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases.

Then t testcases follow.

The first line of each testcase contains a single integer n (1 ≤ n ≤ 100) — the number of elements in the array a.

The second line of each testcase contains n integers a_1, a_2, ..., a_n (-10^5 ≤ a_i ≤ 10^5) — the initial array a.

The third line of each testcase contains n integers l_1, l_2, ..., l_n (0 ≤ l_i ≤ 1), where l_i = 0 means that the position i is unlocked and l_i = 1 means that the position i is locked.

Output

Print n integers — the array a after the rearrangement. Value k (the maximum j such that p_j < 0 (or 0 if there are no such j)) should be minimum possible. For each locked position the printed value should be equal to the initial one. The values on the unlocked positions should be an arrangement of the initial ones.

If there are multiple answers then print any of them.

Example

Input

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

Output

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

Note

In the first testcase you can rearrange all values however you want but any arrangement will result in k = 0. For example, for an arrangement [1, 2, 3], p=[1, 3, 6], so there are no j such that p_j < 0. Thus, k = 0.

In the second testcase you are not allowed to rearrange any elements. Thus, the printed array should be exactly the same as the initial one.

In the third testcase the prefix sums for the printed array are p = [-8, -14, -13, -9, -5, 2, 0]. The maximum j is 5, thus k = 5. There are no arrangements such that k < 5.

In the fourth testcase p = [-4, -4, -3, 3, 6].

In the fifth testcase p = [-1, 3, 10, 2, 12, 11].

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long power(long long base, long long exp);
void solve() {
  long long n;
  cin >> n;
  vector<long long> arr(n, 0);
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  vector<long long> temp(n, 0);
  for (long long i = 0; i < n; i++) {
    cin >> temp[i];
  }
  vector<long long> z;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    if (temp[i] == 0) {
      z.push_back(arr[i]);
    }
  }
  sort((z).begin(), (z).end(), greater<long long>());
  long long x = 0;
  for (long long i = 0; i < n; i++) {
    if (temp[i] == 0) {
      arr[i] = z[x++];
    }
  }
  for (long long i = 0; i < n; i++) cout << arr[i] << " ";
  cout << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
long long power(long long base, long long exp) {
  base %= 1000000007;
  long long result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((long long)result * base) % 1000000007;
    base = ((long long)base * base) % 1000000007;
    exp >>= 1;
  }
  return result;
}

```


### Prompt

Generate a CPP solution to the following problem:

Pasha has a wooden stick of some positive integer length n. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be n.

Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.

Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer x, such that the number of parts of length x in the first way differ from the number of parts of length x in the second way.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 2·109) — the length of Pasha's stick.

Output

The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.

Examples

Input

6

Output

1

Input

20

Output

4

Note

There is only one way to divide the stick in the first sample {1, 1, 2, 2}.

Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n & 1) {
    cout << "0";
    return 0;
  }
  n >>= 1;
  int x = (n >> 1);
  if ((n & 1) == 0) --x;
  cout << x;
  return 0;
}

```


### Prompt

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

Bike is a smart boy who loves math very much. He invented a number called "Rotatable Number" inspired by 142857.

As you can see, 142857 is a magic number because any of its rotatings can be got by multiplying that number by 1, 2, ..., 6 (numbers from one to number's length). Rotating a number means putting its last several digit into first. For example, by rotating number 12345 you can obtain any numbers: 12345, 51234, 45123, 34512, 23451. It's worth mentioning that leading-zeroes are allowed. So both 4500123 and 0123450 can be obtained by rotating 0012345. You can see why 142857 satisfies the condition. All of the 6 equations are under base 10.

  * 142857·1 = 142857;
  * 142857·2 = 285714;
  * 142857·3 = 428571;
  * 142857·4 = 571428;
  * 142857·5 = 714285;
  * 142857·6 = 857142.

Now, Bike has a problem. He extends "Rotatable Number" under any base b. As is mentioned above, 142857 is a "Rotatable Number" under base 10. Another example is 0011 under base 2. All of the 4 equations are under base 2.

  * 0011·1 = 0011;
  * 0011·10 = 0110;
  * 0011·11 = 1001;
  * 0011·100 = 1100.

So, he wants to find the largest b (1 < b < x) so that there is a positive "Rotatable Number" (leading-zeroes allowed) of length n under base b.

Note that any time you multiply a rotatable number by numbers from 1 to its length you should get a rotating of that number.

Input

The only line contains two space-separated integers n, x (1 ≤ n ≤ 5·106, 2 ≤ x ≤ 109).

Output

Print a single integer — the largest b you found. If no such b exists, print -1 instead.

Examples

Input

6 11

Output

10

Input

5 8

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
const int N = 5e6 + 6;
int n, x, a[N], len;
inline int pow(int x, int k, int mod) {
  long long res = 1, r = x % mod;
  for (; k; k >>= 1, r = r * r % mod)
    if (k & 1) res = res * r % mod;
  return res;
}
int main() {
  scanf("%d%d", &n, &x);
  if (n == 1 && x <= 2) {
    puts("-1");
    return 0;
  }
  for (int i = 2; i * i <= n + 1; ++i)
    if ((n + 1) % i == 0) {
      puts("-1");
      return 0;
    }
  for (int i = 1; i * i <= n; ++i)
    if (n % i == 0) a[++len] = i, a[++len] = n / i;
  if (a[len] == a[len - 1]) --len;
  for (int i = x - 1; i >= 1; --i) {
    bool flag = true;
    for (int k = 1; k <= len; ++k)
      if (a[k] != n && pow(i, a[k], n + 1) == 1) {
        flag = false;
        break;
      }
    if (flag) {
      printf("%d\n", i);
      return 0;
    }
  }
  puts("-1");
  return 0;
}

```


### Prompt

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

Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.

Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.

Input

The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.

Output

In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.

Examples

Input

3
1 2 3

Output

1 3

Input

4
6 5 6 7

Output

2 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int max, n, l, s, N, i;
  int a[1001];
  cin >> N;
  max = -1;
  s = 0;
  for (i = 1; i <= 1000; i++) {
    a[i] = 0;
  }
  for (i = 1; i <= N; i++) {
    cin >> l;
    a[l]++;
    if (a[l] > max) max = a[l];
  }
  for (i = 1; i <= 1000; i++) {
    if (a[i] != 0) s++;
  }
  cout << max << " " << s;
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.

<image>

The park consists of 2n + 1 - 1 squares connected by roads so that the scheme of the park is a full binary tree of depth n. More formally, the entrance to the park is located at the square 1. The exits out of the park are located at squares 2n, 2n + 1, ..., 2n + 1 - 1 and these exits lead straight to the Om Nom friends' houses. From each square i (2 ≤ i < 2n + 1) there is a road to the square <image>. Thus, it is possible to go from the park entrance to each of the exits by walking along exactly n roads.

<image> To light the path roads in the evening, the park keeper installed street lights along each road. The road that leads from square i to square <image> has ai lights.

Om Nom loves counting lights on the way to his friend. Om Nom is afraid of spiders who live in the park, so he doesn't like to walk along roads that are not enough lit. What he wants is that the way to any of his friends should have in total the same number of lights. That will make him feel safe.

He asked you to help him install additional lights. Determine what minimum number of lights it is needed to additionally place on the park roads so that a path from the entrance to any exit of the park contains the same number of street lights. You may add an arbitrary number of street lights to each of the roads.

Input

The first line contains integer n (1 ≤ n ≤ 10) — the number of roads on the path from the entrance to any exit.

The next line contains 2n + 1 - 2 numbers a2, a3, ... a2n + 1 - 1 — the initial numbers of street lights on each road of the park. Here ai is the number of street lights on the road between squares i and <image>. All numbers ai are positive integers, not exceeding 100.

Output

Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe.

Examples

Input

2
1 2 3 4 5 6

Output

5

Note

Picture for the sample test. Green color denotes the additional street lights.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m = 0, k, ans = 0, a[1000000], b[1000000], x, y, z = 1, MAX, MIN;
string str, str1, str2;
char C;
bool flag = false;
int main() {
  cin >> n;
  k = pow(2, float(n - 1));
  n = pow(2, (float)(n + 1)) - 1;
  for (int i = 2; i <= n; i++) {
    cin >> a[i];
  }
  n--;
  for (int i = n; i >= 2; i -= 2) {
    a[i / 2] += max(a[i], a[i + 1]), ans += (abs(a[i] - a[i + 1]));
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

You are given a string A. Find a string B, where B is a palindrome and A is a subsequence of B.

A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequence of "contest".

A palindrome is a string that reads the same forward or backward.

The length of string B should be at most 104. It is guaranteed that there always exists such string.

You do not need to find the shortest answer, the only restriction is that the length of string B should not exceed 104.

Input

First line contains a string A (1 ≤ |A| ≤ 103) consisting of lowercase Latin letters, where |A| is a length of A.

Output

Output single line containing B consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string B should not exceed 104. If there are many possible B, print any of them.

Examples

Input

aba

Output

aba

Input

ab

Output

aabaa

Note

In the first example, "aba" is a subsequence of "aba" which is a palindrome.

In the second example, "ab" is a subsequence of "aabaa" which is a palindrome.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  cout << a;
  int n = a.size();
  for (int i = n - 1; i >= 0; i--) {
    cout << a[i];
  }
}

```


### Prompt

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

You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied:

For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more than by 1.

For example, choose n = 3. On the left you can see an example of a valid arrangement: 1 + 4 + 5 = 10, 4 + 5 + 2 = 11, 5 + 2 + 3 = 10, 2 + 3 + 6 = 11, 3 + 6 + 1 = 10, 6 + 1 + 4 = 11, any two numbers differ by at most 1. On the right you can see an invalid arrangement: for example, 5 + 1 + 6 = 12, and 3 + 2 + 4 = 9, 9 and 12 differ more than by 1.

<image>

Input

The first and the only line contain one integer n (1 ≤ n ≤ 10^5).

Output

If there is no solution, output "NO" in the first line.

If there is a solution, output "YES" in the first line. In the second line output 2n numbers — numbers from 1 to 2n in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them.

Examples

Input

3

Output

YES
1 4 5 2 3 6

Input

4

Output

NO

Note

Example from the statement is shown for the first example.

It can be proved that there is no solution in the second example.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > vp;
vector<long long> v;
set<long long> st;
long long ara[500005];
map<long long, long long> mp;
long long Set(long long N, long long pos) { return N = N | (1LL << pos); }
long long reset(long long N, long long pos) { return N = N & ~(1LL << pos); }
bool check(long long N, long long pos) { return (bool)(N & (1LL << pos)); }
vector<long long> e, o;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, i, j, p;
  cin >> n;
  if (n % 2 == 0)
    cout << "NO\n";
  else {
    cout << "YES\n";
    p = 1;
    for (i = 0; i < 2 * n; i += 2) {
      ara[i] = p;
      p += 2;
    }
    p = 2;
    for (i = n; i < 2 * n; i += 2) {
      ara[i] = p;
      p += 2;
    }
    for (i = 1; i < n; i += 2) {
      ara[i] = p;
      p += 2;
    }
    for (i = 0; i < 2 * n; i++) cout << ara[i] << " ";
    cout << '\n';
  }
}

```


### Prompt

Please create a solution in CPP to the following problem:

There is an infinite 2-dimensional grid. The robot stands in cell (0, 0) and wants to reach cell (x, y). Here is a list of possible commands the robot can execute:

  * move north from cell (i, j) to (i, j + 1);
  * move east from cell (i, j) to (i + 1, j);
  * move south from cell (i, j) to (i, j - 1);
  * move west from cell (i, j) to (i - 1, j);
  * stay in cell (i, j).

The robot wants to reach cell (x, y) in as few commands as possible. However, he can't execute the same command two or more times in a row.

What is the minimum number of commands required to reach (x, y) from (0, 0)?

Input

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

Each of the next t lines contains two integers x and y (0 ≤ x, y ≤ 10^4) — the destination coordinates of the robot.

Output

For each testcase print a single integer — the minimum number of commands required for the robot to reach (x, y) from (0, 0) if no command is allowed to be executed two or more times in a row.

Example

Input

5
5 5
3 4
7 1
0 0
2 0

Output

10
7
13
0
3

Note

The explanations for the example test:

We use characters N, E, S, W and 0 to denote going north, going east, going south, going west and staying in the current cell, respectively.

In the first test case, the robot can use the following sequence: NENENENENE.

In the second test case, the robot can use the following sequence: NENENEN.

In the third test case, the robot can use the following sequence: ESENENE0ENESE.

In the fourth test case, the robot doesn't need to go anywhere at all.

In the fifth test case, the robot can use the following sequence: E0E.

### Response

```cpp
#pragma GCC optimize("Ofast")   //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  endl           "\n"
#define  pb             push_back
#define  sym(s)         s="#"+s+"#";
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  debv(a)        for(auto it: a)cout<<it<<" ";cout<<endl;
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());

typedef  long long             ll;
typedef  unsigned long long    ull;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   N  =  3e+5+7;

vll adj[N];ll vis[N]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll x,y;
//<<-----Implement Functions Here---->>//

//<<-----Start of Main--------------->>//
void MAIN(){
        cin>>x>>y;if(x>y)swap(x,y);
        if(x==y)cout<<2*x<<endl;
        else cout<<2*y-1<<endl;
}

int main(){
    fastio;randomINIT;

    cin>>t;
    while(t--){
        MAIN();
    }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}
```


### Prompt

Generate a Cpp solution to the following problem:

Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.

Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.

Given the name of the contest, print the abbreviation of the name.

Constraints

* The length of s is between 1 and 100, inclusive.
* The first character in s is an uppercase English letter.
* The second and subsequent characters in s are lowercase English letters.

Input

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

AtCoder s Contest

Output

Print the abbreviation of the name of the contest.

Examples

Input

AtCoder Beginner Contest

Output

ABC

Input

AtCoder Snuke Contest

Output

ASC

Input

AtCoder X Contest

Output

AXC

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
string a;
int main(){
cin>>a>>a;
cout<<'A'<<a[0]<<'C'<<endl;
}
```


### Prompt

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

Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.

There are n stages available. The rocket must contain exactly k of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.

For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' — 26 tons.

Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once.

Input

The first line of input contains two integers — n and k (1 ≤ k ≤ n ≤ 50) – the number of available stages and the number of stages to use in the rocket.

The second line contains string s, which consists of exactly n lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once.

Output

Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.

Examples

Input

5 3
xyabd

Output

29

Input

7 4
problem

Output

34

Input

2 2
ab

Output

-1

Input

12 1
abaabbaaabbb

Output

1

Note

In the first example, the following rockets satisfy the condition:

  * "adx" (weight is 1+4+24=29);
  * "ady" (weight is 1+4+25=30);
  * "bdx" (weight is 2+4+24=30);
  * "bdy" (weight is 2+4+25=31).

Rocket "adx" has the minimal weight, so the answer is 29.

In the second example, target rocket is "belo". Its weight is 2+5+12+15=34.

In the third example, n=k=2, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<int> arr;
  for (int i = 0; i < n; i++) {
    int temp = s[i] - 96;
    arr.push_back(temp);
  }
  sort(arr.begin(), arr.end());
  int ctr = 1;
  int sum = arr[0];
  int t = 0;
  for (int i = 1; i < n && ctr < k; i++) {
    if (arr[i] - arr[t] >= 2) {
      ctr++;
      sum += arr[i];
      t = i;
    }
  }
  if (ctr != k)
    cout << "-1";
  else
    cout << sum;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

This is an interactive problem.

You are the head coach of a chess club. The club has 2n players, each player has some strength which can be represented by a number, and all those numbers are distinct. The strengths of the players are not known to you.

You need to select n players who would represent your club in the upcoming championship. Naturally, you want to select n players with the highest strengths.

You can organize matches between the players to do that. In every match, you pick two players, they play some games, and you learn which one of the two has higher strength. You can wait for the outcome of a match before deciding who will participate in the next one.

However, you do not want to know exactly how those n players compare between themselves, as that would make the championship itself less intriguing. More formally, you must reach a state where there is exactly one way to choose n players with the highest strengths that is consistent with the outcomes of the matches you organized, but there must be at least two possible orderings of those n players by strength that are consistent with the outcomes of the matches you organized.

Interaction

Your program has to process multiple test cases in one run. First, it should read the integer t (t ≥ 1) — the number of test cases. Then, it should process the test cases one by one.

In each test case, your program should start by reading the integer n (3 ≤ n ≤ 100) — the number of players to select out of 2n players. The sum of squares of the values of n over all test cases does not exceed 10 000.

Then your program can organize matches zero or more times. To organize a match, your program should print a match description formatted as ? i j — a question mark followed by two distinct numbers of players participating in the match. The players are numbered from 1 to 2n, inclusive. Remember to flush the output after printing the match description. Then your program should read the match outcome — it will be either the greater-than character (>), if the first player in the match description has higher strength, or the less-than character (<), if the second player in the match description has higher strength.

Your program can organize at most 4n^2 matches. After it is done organizing matches, it should print the exclamation mark (!) and continue to the next test case, or exit gracefully if this was the last test case. Remember to flush the output after printing the exclamation mark.

There must be exactly one way to choose n players with the highest strength that is consistent with the outcomes of the matches you organized, but there must be at least two possible orderings of those n players by their strength that are consistent with the outcomes of the matches you organized.

The judging program picks some distinct numbers as the strengths of all players before your program starts organizing matches and uses them to answer the requests.

Example

Input

2
3

>

<

>

<

>

>

3

<

<

<

>

>

Output

? 1 3

? 4 2

? 4 5

? 6 5

? 3 4

? 5 6

!

? 3 4

? 4 2

? 5 3

? 6 4

? 3 1

!

Note

In the example, the players in the first test case are sorted by strength in decreasing order. From the matches in the example output, we can deduce that players 1, 2, and 3 have the highest strength, but we do not know how the player 1 compares to the player 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int, int>;
using vpii = std::vector<pii>;
struct Jury {
  vi perm;
  vpii edges;
  int getN() { return ((int)(perm).size() - 1) / 2; }
  Jury(int n) : perm(1 + 2 * n, 0) {
    for (int i = 1; i <= 2 * n; i++) perm[i] = i;
  }
  char ask(int a, int b) {
    if (perm[a] < perm[b]) {
      edges.emplace_back(a, b);
      return '<';
    }
    assert(perm[a] > perm[b]);
    edges.emplace_back(b, a);
    return '>';
  }
  bool next() {
    edges.clear();
    return std::next_permutation(perm.begin() + 1, perm.end());
  }
  bool check() {
    int n = ((int)(perm).size() - 1) / 2;
    vi a{0}, ind{0};
    for (int i = n + 1; i <= 2 * n; i++) {
      a.push_back(i);
    }
    for (int i = 1; i <= 2 * n; i++) {
      if (perm[i] > n) ind.push_back(i);
    }
    std::sort((a).begin(), (a).end());
    vvi answers;
    vi backup = perm;
    do {
      vi save = perm;
      for (int i = 1; i <= n; i++) {
        perm[ind[i]] = a[i];
      }
      bool ok = true;
      for (auto &[a, b] : edges) {
        ok &= perm[a] < perm[b];
      }
      if (ok) {
        answers.push_back(perm);
      }
      perm = save;
    } while (std::next_permutation(a.begin() + 1, a.end()));
    perm = backup;
    if ((int)(answers).size() == 1) {
      std::cout << "Wrong Answer on testcase";
      for (int i = 1; i <= 2 * n; i++) {
        std::cout << ' ' << perm[i];
      }
      std::cout << std::endl;
      std::cout << "order of indexes";
      for (int i = 1; i <= n; i++) {
        std::cout << ' ' << ind[i];
      }
      std::cout << " is strictly defined!" << std::endl;
      std::cout << "you determined that these condition holds:" << std::endl;
      perm = answers.back();
      for (auto &[a, b] : edges) {
        std::cout << a << '<' << b << "( means p[" << a << "]=" << perm[a]
                  << " < "
                  << "p[" << b << "] = " << perm[b] << std::endl;
      }
      return false;
    } else {
      assert((int)(answers).size() > 1);
      for (int i = 1; i <= 2 * n; i++) {
        if (i > 1) std::cout << ' ';
        std::cout << perm[i];
      }
      std::cout << ": OK" << std::endl;
      return true;
    }
  }
} jury(3);
bool test;
int getN() {
  if (test) return jury.getN();
  int n;
  cin >> n;
  return n;
}
char ask(int a, int b) {
  if (test) return jury.ask(a, b);
  cout << "? " << a << ' ' << b << endl;
  char res;
  cin >> res;
  return res;
}
void checkAnsw() {
  if (test) {
    if (jury.check()) {
      if (!jury.next()) {
        std::exit(0);
      }
    } else {
      getchar();
      getchar();
      std::exit(0);
    }
  } else
    cout << '!' << endl;
}
void bfs(vector<vector<int>> &g, vector<pii> &arr, int start, int less_ind) {
  int n = g.size();
  queue<int> q;
  q.push(start);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    if (!g[cur][less_ind]) {
      ++arr[cur].first;
      ++arr[less_ind].second;
      g[less_ind][cur] = -1;
      g[cur][less_ind] = 1;
      for (int i = 0; i < n; ++i)
        if (g[cur][i] == -1) q.push(i);
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  test = false;
  int t;
  if (test)
    t = 2e9;
  else
    cin >> t;
  while (t--) {
    int hn = getN();
    int n = hn << 1;
    vector<vector<int>> g(n, vector<int>(n));
    vector<pii> arr;
    vector<int> losers;
    arr.reserve(n);
    losers.reserve(hn);
    for (int i = 1; i < n; i += 2) {
      pii a = {1, 0}, b = {1, 0};
      char res = ask(i, i + 1);
      if (res == '<') {
        losers.push_back(i);
        ++b.first;
        ++a.second;
        g[i - 1][i] = -1;
        g[i][i - 1] = 1;
      } else {
        losers.push_back(i + 1);
        ++a.first;
        ++b.second;
        g[i][i - 1] = -1;
        g[i - 1][i] = 1;
      }
      arr.push_back(a);
      arr.push_back(b);
    }
    for (int i = 0; i < hn; ++i)
      for (int j = i + 1; j < hn; ++j) {
        int ind = losers[i];
        int jnd = losers[j];
        if (!g[ind - 1][jnd - 1]) {
          char res = ask(ind, jnd);
          int less_ind = ind - 1, start = jnd - 1;
          if (res == '>') swap(less_ind, start);
          bfs(g, arr, start, less_ind);
        }
      }
    int found = 0;
    while (found < hn) {
      pii mina = {2e9, 2e9}, minb = {2e9, 2e9};
      int mini = -1, minj = -1;
      for (int i = 0; i < n; ++i) {
        if (arr[i] < mina) {
          swap(mina, minb);
          swap(mini, minj);
          mina = arr[i];
          mini = i;
        } else if (arr[i] < minb) {
          minb = arr[i];
          minj = i;
        }
      }
      if (mina.first < minb.first) {
        arr[mini] = {2e9, 2e9};
        ++found;
      } else {
        char res = ask(mini + 1, minj + 1);
        int less_ind = mini, start = minj;
        if (res == '>') swap(less_ind, start);
        bfs(g, arr, start, less_ind);
      }
    }
    checkAnsw();
  }
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.

Let's assume that S(n) is the sum of digits of number n, for example, S(4098) = 4 + 0 + 9 + 8 = 21. Then the digital root of number n equals to:

  1. dr(n) = S(n), if S(n) < 10;
  2. dr(n) = dr( S(n) ), if S(n) ≥ 10.

For example, dr(4098) = dr(21) = 3.

Vasya is afraid of large numbers, so the numbers he works with are at most 101000. For all such numbers, he has proved that dr(n) = S( S( S( S(n) ) ) ) (n ≤ 101000).

Now Vasya wants to quickly find numbers with the given digital root. The problem is, he hasn't learned how to do that and he asked you to help him. You task is, given numbers k and d, find the number consisting of exactly k digits (the leading zeroes are not allowed), with digital root equal to d, or else state that such number does not exist.

Input

The first line contains two integers k and d (1 ≤ k ≤ 1000; 0 ≤ d ≤ 9).

Output

In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist.

The chosen number must consist of exactly k digits. We assume that number 0 doesn't contain any leading zeroes.

Examples

Input

4 4

Output

5881

Input

5 1

Output

36172

Input

1 0

Output

0

Note

For the first test sample dr(5881) = dr(22) = 4.

For the second test sample dr(36172) = dr(19) = dr(10) = 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, d;
  cin >> k >> d;
  if (d == 0 && k != 1)
    cout << "No solution";
  else {
    cout << d;
    for (int i = 0; i < k - 1; i++) cout << "0";
  }
  return 0;
}

```


### Prompt

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

Yet another education system reform has been carried out in Berland recently. The innovations are as follows:

An academic year now consists of n days. Each day pupils study exactly one of m subjects, besides, each subject is studied for no more than one day. After the lessons of the i-th subject pupils get the home task that contains no less than ai and no more than bi exercises. Besides, each subject has a special attribute, the complexity (ci). A school can make its own timetable, considering the following conditions are satisfied:

  * the timetable should contain the subjects in the order of the complexity's strict increasing;
  * each day, except for the first one, the task should contain either k times more exercises, or more by k compared to the previous day (more formally: let's call the number of home task exercises in the i-th day as xi, then for each i (1 < i ≤ n): either xi = k + xi - 1 or xi = k·xi - 1 must be true);
  * the total number of exercises in all home tasks should be maximal possible.

All limitations are separately set for each school.

It turned out that in many cases ai and bi reach 1016 (however, as the Berland Minister of Education is famous for his love to half-measures, the value of bi - ai doesn't exceed 100). That also happened in the Berland School №256. Nevertheless, you as the school's principal still have to work out the timetable for the next academic year...

Input

The first line contains three integers n, m, k (1 ≤ n ≤ m ≤ 50, 1 ≤ k ≤ 100) which represent the number of days in an academic year, the number of subjects and the k parameter correspondingly. Each of the following m lines contains the description of a subject as three integers ai, bi, ci (1 ≤ ai ≤ bi ≤ 1016, bi - ai ≤ 100, 1 ≤ ci ≤ 100) — two limitations to the number of exercises on the i-th subject and the complexity of the i-th subject, correspondingly. Distinct subjects can have the same complexity. The subjects are numbered with integers from 1 to m.

Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin stream or the %I64d specificator.

Output

If no valid solution exists, print the single word "NO" (without the quotes). Otherwise, the first line should contain the word "YES" (without the quotes) and the next n lines should contain any timetable that satisfies all the conditions. The i + 1-th line should contain two positive integers: the number of the subject to study on the i-th day and the number of home task exercises given for this subject. The timetable should contain exactly n subjects.

Examples

Input

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

Output

YES
2 8
3 10
4 20
5 40

Input

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

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
void Open() {}
long long n, m, k;
long long dp[55][55][55][110];
struct info {
  long long a, b, c, id;
  bool operator<(const info& o) const { return c < o.c; }
} sub[110];
int paidx[110][110][110][3];
long long pat[110][110];
long long ansidx[110];
long long anst[110];
int main() {
  Open();
  memset(paidx, -1, sizeof paidx);
  scanf("%I64d%I64d%I64d", &n, &m, &k);
  for (long long i = 0; i < m; i++)
    scanf("%I64d%I64d%I64d", &sub[(i)].a, &sub[(i)].b, &sub[(i)].c),
        sub[(i)].b -= sub[(i)].a, sub[(i)].id = i;
  sort(sub, sub + m);
  for (long long i = 0; i <= sub[(0)].b; i++) dp[0][1][0][i] = i + sub[(0)].a;
  for (long long i = 1; i < m; i++)
    for (long long j = 1; j <= min(i + 1, n); j++) {
      for (long long s = j - 1; s < i; s++)
        for (long long t = 0; t <= sub[(s)].b; t++)
          dp[i][j][s][t] = dp[i - 1][j][s][t];
      if (j == 1) {
        for (long long t = 0; t <= sub[(i)].b; t++)
          dp[i][j][i][t] = t + sub[(i)].a;
        continue;
      }
      for (long long t = 0; t <= sub[(i)].b; t++)
        for (long long s = j - 2; s < i; s++) {
          if (sub[(s)].c >= sub[(i)].c) continue;
          if (sub[(i)].a + t - sub[(s)].a - k >= 0 &&
              sub[(i)].a + t - sub[(s)].a - k <= sub[(s)].b &&
              dp[i][j][i][t] <
                  dp[i - 1][j - 1][s][sub[(i)].a + t - sub[(s)].a - k] +
                      sub[(i)].a + t &&
              dp[i - 1][j - 1][s][sub[(i)].a + t - sub[(s)].a - k] != 0) {
            dp[i][j][i][t] =
                dp[i - 1][j - 1][s][sub[(i)].a + t - sub[(s)].a - k] +
                sub[(i)].a + t;
            paidx[i][j][t][0] = j - 1;
            paidx[i][j][t][1] = s;
            paidx[i][j][t][2] = sub[(i)].a + t - sub[(s)].a - k;
          }
          if ((sub[(i)].a + t) % k == 0 &&
              (sub[(i)].a + t) / k - sub[(s)].a >= 0 &&
              (sub[(i)].a + t) / k - sub[(s)].a <= sub[(s)].b &&
              dp[i][j][i][t] <
                  dp[i - 1][j - 1][s][(sub[(i)].a + t) / k - sub[(s)].a] +
                      sub[(i)].a + t &&
              dp[i - 1][j - 1][s][(sub[(i)].a + t) / k - sub[(s)].a] != 0) {
            dp[i][j][i][t] =
                dp[i - 1][j - 1][s][(sub[(i)].a + t) / k - sub[(s)].a] +
                sub[(i)].a + t;
            paidx[i][j][t][0] = j - 1;
            paidx[i][j][t][1] = s;
            paidx[i][j][t][2] = (sub[(i)].a + t) / k - sub[(s)].a;
          }
        }
    }
  long long ans = 0;
  long long tmp = n, preidx, preans;
  pair<long long, long long> pre;
  for (long long i = 0; i < m; i++)
    for (long long j = 0; j <= sub[(i)].b; j++)
      if (ans < dp[m - 1][n][i][j])
        ans = dp[m - 1][n][i][j], pre = pair<long long, long long>(i, j),
        preidx = n, preans = j + sub[(i)].a;
  if (ans == 0) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  while (pre != pair<long long, long long>(-1, -1)) {
    ansidx[--tmp] = pre.first;
    anst[tmp] = pre.second + sub[(pre.first)].a;
    pair<long long, long long> pretmp = pre;
    int tmppreidx = preidx;
    preidx = paidx[pretmp.first][tmppreidx][pretmp.second][0];
    pre.first = paidx[pretmp.first][tmppreidx][pretmp.second][1];
    pre.second = paidx[pretmp.first][tmppreidx][pretmp.second][2];
  }
  for (long long i = 0; i < n; i++)
    printf("%I64d %I64d\n", sub[(ansidx[i])].id + 1, anst[i]);
  return 0;
}

```


### Prompt

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

Curry making

As the ACM-ICPC domestic qualifying is approaching, you who wanted to put more effort into practice decided to participate in a competitive programming camp held at a friend's house. Participants decided to prepare their own meals.

On the first night of the training camp, the participants finished the day's practice and began preparing dinner. Not only in competitive programming, but also in self-catering, you are often said to be a "professional", and you have spared time because you have finished making the menu for your charge in a blink of an eye. Therefore, I decided to help other people make curry.

Now, there is a curry made by mixing R0 [g] roux with W0 [L] water. There is one type of roux used this time, and each roux is R [g]. Ru has a sufficient stockpile. When you use this roux, you think that the curry with a concentration of C [g / L] is the most delicious, so add some roux and water to this curry appropriately to make the concentration C [g / L]. I want to. Here, the concentration of curry in which roux R0 [g] is dissolved in water W0 [L] is R0 / W0 [g / L], and X roux of R [g] and water Y [L] are added to this curry. ] Is added, the concentration becomes (R0 + XR) / (W0 + Y) [g / L]. Although there are a lot of roux, you thought that it was not good to use too much, so you decided to make a curry with a concentration of C [g / L] by reducing the number of roux to be added as much as possible.

When making a curry with a concentration of C [g / L] by properly adding either roux, water, or both to a curry with a concentration of R0 / W0 [g / L], the number of roux X to be added Find the minimum value.

However, please note the following points regarding the curry making this time.

* Number of roux to be added The value of X must be an integer greater than or equal to 0. In other words, it is not possible to add only 1/3 of the roux.
* The value of the volume Y of water to be added can be a real number greater than or equal to 0, and does not have to be an integer.
* In some cases, it is possible to make curry with a concentration of C without adding either roux, water, or both.
* Since a sufficient amount of roux and water is secured, it is good that the situation that the curry with concentration C cannot be made due to lack of roux and water does not occur.

Input

The input consists of multiple datasets. Each dataset consists of one line and is expressed in the following format.

> R0 W0 C R

Here, R0, W0, C, and R are the mass of roux already dissolved in the curry that is being made [g], the volume of water contained in the curry [L], and the concentration of the curry you want to make [g / L]. , Represents the mass [g] per roux. All of these values are integers between 1 and 100. The end of the input is indicated by a line of four zeros separated by blanks.

Output

For each dataset, one line is the minimum number of roux that needs to be added to make a curry with a concentration of C from a fake curry that is a mixture of W0 [L] water and R0 [g] roux. To output. Do not output the amount of water to add.

Note that due to input constraints, the minimum number of roux that is the answer for each dataset is guaranteed to be within the range represented by a 32-bit signed integer.

Sample Input

10 5 3 4
2 5 2 3
91 13 7 62
10 1 3 5
20 100 2 20
2 14 7 1
0 0 0 0

Output for Sample Input

2
3
0
0
9
96

Example

Input

10 5 3 4
2 5 2 3
91 13 7 62
10 1 3 5
20 100 2 20
2 14 7 1
0 0 0 0

Output

2
3
0
0
9
96

### Response

```cpp
#include <iostream>
#define llint long long

using namespace std;

llint r0, w0, c, r;

int main(void)
{
  while(1){
    cin >> r0 >> w0 >> c >> r;
    if(r0 == 0 && w0 == 0 && c == 0 && r == 0) break;
    if(c*w0-r0+r-1 <= 0) cout << 0 << endl;
    else cout << (c*w0-r0+r-1)/r << endl;
  }
  return 0;
}

```


### Prompt

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

Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has?

Please help Haruhi solve this problem.

Input

The first line of input will be a single string s (1 ≤ |s| ≤ 20). String s consists only of lowercase English letters.

Output

Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.

Examples

Input

a

Output

51

Input

hi

Output

76

Note

In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
#pragma comment(linker, "/STACK:268435456")
#pragma warning(disable : 4996)
  int n, i, j, a[1111];
  char c[28];
  string s, d, e;
  map<string, int> m;
  scanf("%d", &n);
  gets(c);
  gets(c);
  s = c;
  for (i = 0; i < s.length(); i++) {
    for (j = 0; j <= i; j++) {
      d.push_back(s[j]);
    }
    for (j = int('a'); j <= int('z'); j++) {
      e += d;
      e.push_back(char(j));
      for (int k = i + 1; k < s.length(); k++) e.push_back(s[k]);
      m[e] = 1;
      e.clear();
    }
    d.clear();
  }
  for (j = int('a'); j <= int('z'); j++) {
    e.push_back(char(j));
    e += s;
    m[e] = 1;
    e.clear();
  }
  printf("%d", m.size());
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

A frog is about to return to the burrow. The burrow is D centimeters ahead of the frog, and the frog goes straight toward the burrow. There are only two actions that a frog can do:

* Large jump (go forward L centimeters)
* Small jump (go 1 cm forward)

The frog aims to just land in the burrow without jumping over it.

Create a program that asks how many times a frog needs to jump to return to its burrow.

Input

The input is given in the following format.

DL

The input is one line, given the distance D (1 ≤ D ≤ 10000) to the burrow and the distance L (2 ≤ L ≤ 10000) for the frog to travel on a large jump.

Output

Print on one line how many times the frog needs to jump.

Examples

Input

10 5

Output

2

Input

7 4

Output

4

### Response

```cpp
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int d,l;
    cin>>d>>l;
    cout<<d/l+d%l<<endl;
}

```


### Prompt

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

In the game Lizard Era: Beginning the protagonist will travel with three companions: Lynn, Meliana and Worrigan. Overall the game has n mandatory quests. To perform each of them, you need to take exactly two companions.

The attitude of each of the companions to the hero is an integer. Initially, the attitude of each of them to the hero of neutral and equal to 0. As the hero completes quests, he makes actions that change the attitude of the companions, whom he took to perform this task, in positive or negative direction.

Tell us what companions the hero needs to choose to make their attitude equal after completing all the quests. If this can be done in several ways, choose the one in which the value of resulting attitude is greatest possible.

Input

The first line contains positive integer n (1 ≤ n ≤ 25) — the number of important tasks.

Next n lines contain the descriptions of the tasks — the i-th line contains three integers li, mi, wi — the values by which the attitude of Lynn, Meliana and Worrigan respectively will change towards the hero if the hero takes them on the i-th task. All the numbers in the input are integers and do not exceed 107 in absolute value.

Output

If there is no solution, print in the first line "Impossible".

Otherwise, print n lines, two characters is each line — in the i-th line print the first letters of the companions' names that hero should take to complete the i-th task ('L' for Lynn, 'M' for Meliana, 'W' for Worrigan). Print the letters in any order, if there are multiple solutions, print any of them.

Examples

Input

3
1 0 0
0 1 0
0 0 1

Output

LM
MW
MW

Input

7
0 8 9
5 9 -2
6 -8 -7
9 4 5
-4 -9 9
-4 5 2
-6 8 -7

Output

LM
MW
LM
LW
MW
LM
LW

Input

2
1 0 0
1 1 0

Output

Impossible

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;
const int maxhfsize = 1600000;
struct Result {
  int d[2];
  int mask;
};
inline bool operator<(const Result& a, const Result& b) {
  return a.d[0] == b.d[0] ? a.d[1] < b.d[1] : a.d[0] < b.d[0];
}
inline bool operator==(const Result& a, const Result& b) {
  return a.d[0] == b.d[0] && a.d[1] == b.d[1];
}
int deltas[maxn][3];
int firstSize, secondSize;
Result firstHalf[maxhfsize], secondHalf[maxhfsize];
void makeHalf(Result* out, int& sz, int begin, int end) {
  int k = end - begin;
  int maxMask = 1;
  for (int i = 0; i < k; ++i) maxMask *= 3;
  sz = 0;
  for (int mask = 0; mask < maxMask; ++mask) {
    Result& here = out[sz++];
    here.mask = mask;
    int t = mask;
    for (int i = begin; i < end; ++i) {
      int bit = t % 3;
      t /= 3;
      if (bit != 0) {
        here.d[0] -= deltas[i][0];
        here.d[1] -= deltas[i][0];
      }
      if (bit != 1) here.d[0] += deltas[i][1];
      if (bit != 2) here.d[1] += deltas[i][2];
    }
  }
  sort(out, out + sz);
  sz = unique(out, out + sz) - out;
}
int n;
int score(int begin, int end, int mask) {
  int ret = 0;
  for (int i = begin; i < end; ++i) {
    int bit = mask % 3;
    mask /= 3;
    if (bit) ret += deltas[i][0];
  }
  return ret;
}
void out(int begin, int end, int mask) {
  int sum[3] = {0, 0, 0};
  for (int i = begin; i < end; ++i) {
    int bit = mask % 3;
    mask /= 3;
    for (int j = 0; j < 3; ++j)
      if (j != bit) {
        sum[j] += deltas[i][j];
        cout << "LMW"[j];
      }
    cout << '\n';
  }
  42;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 3; ++j) cin >> deltas[i][j];
  int pivot = n / 2;
  makeHalf(firstHalf, firstSize, 0, pivot);
  makeHalf(secondHalf, secondSize, pivot, n);
  int notMuch = -100000000;
  int ansF = -1, ansS = -1, ans = notMuch;
  for (int i = 0; i < secondSize; ++i) {
    Result a = secondHalf[i];
    Result need;
    need.d[0] = -a.d[0];
    need.d[1] = -a.d[1];
    int fst = -1;
    if (pivot != 0 || need.d[0] || need.d[1]) {
      auto it = lower_bound(firstHalf, firstHalf + firstSize, need);
      if (it == firstHalf + firstSize || !(*it == need)) continue;
      fst = it->mask;
    }
    int here = score(0, pivot, fst) + score(pivot, n, a.mask);
    if (here > ans) {
      ans = here;
      ansF = fst;
      ansS = a.mask;
    }
  }
  if (ans == notMuch)
    cout << "Impossible\n";
  else {
    out(0, pivot, ansF);
    out(pivot, n, ansS);
  }
  42;
  return 0;
}

```