### Prompt

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

Vasya lives in a strange world. The year has n months and the i-th month has ai days. Vasya got a New Year present — the clock that shows not only the time, but also the date.

The clock's face can display any number from 1 to d. It is guaranteed that ai ≤ d for all i from 1 to n. The clock does not keep information about the current month, so when a new day comes, it simply increases the current day number by one. The clock cannot display number d + 1, so after day number d it shows day 1 (the current day counter resets). The mechanism of the clock allows you to increase the day number by one manually. When you execute this operation, day d is also followed by day 1.

Vasya begins each day checking the day number on the clock. If the day number on the clock does not match the actual day number in the current month, then Vasya manually increases it by one. Vasya is persistent and repeats this operation until the day number on the clock matches the actual number of the current day in the current month.

A year passed and Vasya wonders how many times he manually increased the day number by one, from the first day of the first month to the last day of the n-th month inclusive, considering that on the first day of the first month the clock display showed day 1.

Input

The first line contains the single number d — the maximum number of the day that Vasya's clock can show (1 ≤ d ≤ 106).

The second line contains a single integer n — the number of months in the year (1 ≤ n ≤ 2000).

The third line contains n space-separated integers: ai (1 ≤ ai ≤ d) — the number of days in each month in the order in which they follow, starting from the first one.

Output

Print a single number — the number of times Vasya manually increased the day number by one throughout the last year.

Examples

Input

4
2
2 2

Output

2

Input

5
3
3 4 3

Output

3

Input

31
12
31 28 31 30 31 30 31 31 30 31 30 31

Output

7

Note

In the first sample the situation is like this:

  * Day 1. Month 1. The clock shows 1. Vasya changes nothing.
  * Day 2. Month 1. The clock shows 2. Vasya changes nothing.
  * Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by 1 manually. After that the clock shows 1.
  * Day 2. Month 2. The clock shows 2. Vasya changes nothing.

In total, Vasya manually changed the day number by 1 exactly 2 times.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const long long INFL = LLONG_MAX;
int D, N, a;
long long ans;
int main() {
  ios_base::sync_with_stdio(0);
  cout.precision(15);
  cin >> D >> N;
  for (int(i) = 1; (i) <= (N - 1); (i)++) {
    cin >> a;
    ans += (D - a);
  }
  cin >> a;
  cout << ans << '\n';
}

```


### Prompt

Generate a CPP solution to the following problem:

One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks.

According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.

Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.

Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.

Can you help him?

Input

The single line of the input contains two positive integers a and b (1 ≤ a, b ≤ 100) — the number of red and blue socks that Vasya's got.

Output

Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.

Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.

Examples

Input

3 1

Output

1 1

Input

2 3

Output

2 0

Input

7 3

Output

3 2

Note

In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int a, b, x, z;
  scanf("%d %d", &a, &b);
  z = abs(a - b) / 2;
  if (a < b) {
    x = a;
  } else
    x = b;
  printf("%d %d", x, z);
  return 0;
}

```


### Prompt

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

We'll call string s[a, b] = sasa + 1... sb (1 ≤ a ≤ b ≤ |s|) a substring of string s = s1s2... s|s|, where |s| is the length of string s.

The trace of a non-empty string t is a set of characters that the string consists of. For example, the trace of string "aab" equals {'a', 'b'}.

Let's consider an arbitrary string s and the set of its substrings with trace equal to C. We will denote the number of substrings from this set that are maximal by inclusion by r(C, s). Substring s[a, b] of length n = b - a + 1 belonging to some set is called maximal by inclusion, if there is no substring s[x, y] in this set with length greater than n, such that 1 ≤ x ≤ a ≤ b ≤ y ≤ |s|. Two substrings of string s are considered different even if they are equal but they are located at different positions of s.

Polycarpus got a challenging practical task on a stringology exam. He must do the following: given string s and non-empty sets of characters C1, C2, ..., Cm, find r(Ci, s) for each set Ci. Help Polycarpus to solve the problem as he really doesn't want to be expelled from the university and go to the army!

Input

The first line contains a non-empty string s (1 ≤ |s| ≤ 106).

The second line contains a single integer m (1 ≤ m ≤ 104). Next m lines contain descriptions of sets Ci. The i-th line contains string ci such that its trace equals Ci. It is guaranteed that all characters of each string ci are different.

Note that Ci are not necessarily different. All given strings consist of lowercase English letters.

Output

Print m integers — the i-th integer must equal r(Ci, s).

Examples

Input

aaaaa
2
a
a

Output

1
1

Input

abacaba
3
ac
ba
a

Output

1
2
4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char input[1000010];
unsigned char ans[3 * (1 << 26) + 10];
int dp[2][28];
void add_count(int i) {
  if (ans[3 * i] == 255) {
    ans[3 * i] = 0;
    if (ans[3 * i + 1] == 255) {
      ans[3 * i + 1] = 0;
      ans[3 * i + 2]++;
    } else {
      ans[3 * i + 1]++;
    }
  } else {
    ans[3 * i]++;
  }
}
int get_count(int i) {
  int n = ans[3 * i + 2];
  n *= 256;
  n += ans[3 * i + 1];
  n *= 256;
  n += ans[3 * i];
  return n;
}
int main() {
  int L;
  scanf("%s", input);
  for (L = 0; input[L]; ++L) input[L] -= 'a';
  bool write = 0, read = 1;
  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 28; ++j) dp[i][j] = -1;
  dp[0][0] = 0;
  for (int i = 0; i < L; ++i) {
    if (i && input[i] == input[i - 1]) continue;
    write ^= 1;
    read ^= 1;
    for (int j = 0; j < 27; ++j) dp[write][j] = -1;
    dp[write][0] = 0;
    for (int j = 0; j < 27; ++j) {
      if (dp[read][j] == -1) continue;
      if (dp[read][j] & (1 << input[i])) {
        dp[write][j] = dp[read][j];
      } else {
        add_count(dp[read][j]);
        dp[write][j + 1] = dp[read][j] | (1 << input[i]);
      }
    }
  }
  write ^= 1;
  read ^= 1;
  for (int j = 0; j < 27; ++j) {
    add_count(dp[read][j]);
  }
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    char query[100];
    scanf("%s", query);
    int q = 0;
    for (int i = 0; query[i]; ++i) q |= (1 << (query[i] - 'a'));
    printf("%d\n", get_count(q));
  }
}

```


### Prompt

Generate a cpp solution to the following problem:

The only difference between easy and hard versions is constraints.

The BerTV channel every day broadcasts one episode of one of the k TV shows. You know the schedule for the next n days: a sequence of integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ k), where a_i is the show, the episode of which will be shown in i-th day.

The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.

How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows d (1 ≤ d ≤ n) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of d consecutive days in which all episodes belong to the purchased shows.

Input

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

The first line of each test case contains three integers n, k and d (1 ≤ n ≤ 100, 1 ≤ k ≤ 100, 1 ≤ d ≤ n). The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ k), where a_i is the show that is broadcasted on the i-th day.

It is guaranteed that the sum of the values of n for all test cases in the input does not exceed 100.

Output

Print t integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for d consecutive days. Please note that it is permissible that you will be able to watch more than d days in a row.

Example

Input

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

Output

2
1
4
5

Note

In the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show 1 and on show 2. So the answer is two.

In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.

In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.

In the fourth test case, you can buy subscriptions to shows 3,5,7,8,9, and you will be able to watch shows for the last eight days.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k, c;
    cin >> n >> k >> c;
    long long int a[n + 1];
    for (long long int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    long long int mn, d = 0;
    map<long long int, long long int> mp;
    for (long long int i = 1; i <= c; i++) {
      if (!mp[a[i]]) d++;
      mp[a[i]]++;
    }
    mn = d;
    for (long long int i = 2; i <= n - c + 1; i++) {
      mp[a[i - 1]]--;
      if (!mp[a[i - 1]]) d--;
      if (!mp[a[i + c - 1]]) d++;
      mp[a[i + c - 1]]++;
      mn = min(mn, d);
    }
    cout << mn << "\n";
  }
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.

The preliminary stage consists of several rounds, which will take place as follows:

* All the N contestants will participate in the first round.
* When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:
* The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.
For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).
When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.
* The preliminary stage ends when 9 or fewer contestants remain.

Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.

Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.

Constraints

* 1 \leq M \leq 200000
* 0 \leq d_i \leq 9
* d_1 \neq 0
* d_i \neq d_{i+1}
* c_i \geq 1
* 2 \leq c_1 + \ldots + c_M \leq 10^{15}

Input

Input is given from Standard Input in the following format:

M
d_1 c_1
d_2 c_2
:
d_M c_M

Output

Print the maximum possible number of rounds in the preliminary stage.

Examples

Input

2
2 2
9 1

Output

3

Input

3
1 1
0 8
7 1

Output

9

### Response

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

using namespace std;

int main(void){
    long long s = 0;
    long long a = 0;
    int M;
    cin >> M;
    for(int i = 0; i < M; i++){
        long long d, c;
        cin >> d >> c;
        s += d * c;
        a += c;
    }
    if(s % 9 == 0) s--;
    cout << a + s / 9 - 1 << endl;
    return 0;
}

```


### Prompt

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

Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.

During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?

Input

The first line contains a single integer n (2 ≤ n ≤ 100) — the number of stops Arkady saw.

The next n lines describe the stops. Each of them starts with a single integer r (1 ≤ r ≤ 100) — the number of tram lines that stop there. r distinct integers follow, each one between 1 and 100, inclusive, — the line numbers. They can be in arbitrary order.

It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.

Output

Print all tram lines that Arkady could be in, in arbitrary order.

Examples

Input

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

Output

1 4

Input

5
1 1
10 10 9 8 7 100 5 4 3 99 1
5 1 2 3 4 5
5 4 1 3 2 5
4 10 1 5 3

Output

1

Note

Consider the first example. Arkady woke up three times. The first time he saw a stop with lines 1, 4, 6. The second time he saw a stop with lines 1, 4. The third time he saw a stop with lines 10, 5, 6, 4 and 1. He can be in a tram of one of two lines: 1 or 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<int> res;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int r;
    vector<int> postaje;
    scanf("%d", &r);
    for (int j = 0; j < r; j++) {
      int a;
      scanf("%d", &a);
      postaje.push_back(a);
    }
    sort(postaje.begin(), postaje.end());
    if (i == 0)
      res = postaje;
    else {
      vector<int> temp(110);
      set_intersection(res.begin(), res.end(), postaje.begin(), postaje.end(),
                       temp.begin());
      res = temp;
    }
  }
  for (int i : res)
    if (i != 0) printf("%d ", i);
  putchar('\n');
  return 0;
}

```


### Prompt

Please create a solution in Cpp to 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, k, ans, i, a[3000], b[3000], t[3000];
void get(int v, int h) {
  if (v * 2 >= m) {
    k++;
    t[k] = h;
    return;
  }
  get(v * 2, h + a[v * 2]);
  get(v * 2 + 1, h + a[v * 2 + 1]);
}
int main() {
  cin >> n;
  m = 1 << (n + 1);
  for (i = 2; i < m; ++i) cin >> a[i];
  get(1, 0);
  while (k > 1) {
    n = k;
    k = 0;
    for (i = 1; i <= n; i += 2)
      ans += abs(t[i] - t[i + 1]), k++, b[k] = max(t[i], t[i + 1]);
    for (i = 1; i <= k; ++i) t[i] = b[i];
  }
  cout << ans;
}

```


### Prompt

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

We all know the problem about the number of ways one can tile a 2 × n field by 1 × 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes.

You are given a 4 × n rectangular field, that is the field that contains four lines and n columns. You have to find for it any tiling by 1 × 2 dominoes such that each of the n - 1 potential vertical cuts along the grid lines intersects at least one domino, splitting it in two. No two dominoes in the sought tiling should overlap, each square of the field should be covered by exactly one domino. It is allowed to rotate the dominoes, that is, you can use 2 × 1 as well as 1 × 2 dominoes.

Write a program that finds an arbitrary sought tiling.

Input

The input contains one positive integer n (1 ≤ n ≤ 100) — the number of the field's columns.

Output

If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing n characters each — that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a color. Different dominoes can be painted the same color, but dominoes of the same color should not be side-neighbouring. To indicate colors you should use lowercase Latin letters. Print any of the acceptable ways of tiling.

Examples

Input

4

Output

yyzz
bccd
bxxd
yyaa

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char mp[105][105];
void paint(long long int x, long long int y, long long int xx,
           long long int yy) {
  mp[x][y] = mp[xx][yy] = (x % 5) * 5 + y % 5 + 'a';
}
int main() {
  long long int n;
  cin >> n;
  if (n % 2) {
    for (long long int i = 0; i < ((long long int)(n / 2)); i++)
      for (long long int j = 0; j < ((long long int)(2)); j++)
        paint(j, i * 2, j, i * 2 + 1);
    for (long long int i = 0; i < ((long long int)(n / 2)); i++)
      for (long long int j = 0; j < ((long long int)(2)); j++)
        paint(j + 2, i * 2 + 1, j + 2, i * 2 + 2);
    paint(0, n - 1, 1, n - 1);
    paint(2, 0, 3, 0);
  } else {
    for (long long int i = 0; i < ((long long int)(n / 2)); i++)
      for (long long int j = 0; j < ((long long int)(4)); j++)
        if (j == 0 || j == 3) paint(j, i * 2, j, i * 2 + 1);
    for (long long int i = 0; i < ((long long int)(n / 2 - 1)); i++)
      for (long long int j = 0; j < ((long long int)(2)); j++)
        paint(j + 1, i * 2 + 1, j + 1, i * 2 + 2);
    paint(1, 0, 2, 0);
    paint(1, n - 1, 2, n - 1);
  }
  for (long long int i = 0; i < ((long long int)(4)); i++) {
    for (long long int j = 0; j < ((long long int)(n)); j++) cout << mp[i][j];
    cout << endl;
  }
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Given is a positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N?

Constraints

* 2 \leq N \leq 10^6
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Examples

Input

3

Output

3

Input

100

Output

473

Input

1000000

Output

13969985

### Response

```cpp
#include<iostream>
using namespace std;
int main(){
    int N,ans=0;
    cin >> N;
    for(int i=1;i<=N;i++){
        ans+=N/i;
        if(N%i==0)ans--;
    }cout<<ans;
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

Simon has a rectangular table consisting of n rows and m columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the x-th row and the y-th column as a pair of numbers (x, y). The table corners are cells: (1, 1), (n, 1), (1, m), (n, m).

Simon thinks that some cells in this table are good. Besides, it's known that no good cell is the corner of the table.

Initially, all cells of the table are colorless. Simon wants to color all cells of his table. In one move, he can choose any good cell of table (x1, y1), an arbitrary corner of the table (x2, y2) and color all cells of the table (p, q), which meet both inequations: min(x1, x2) ≤ p ≤ max(x1, x2), min(y1, y2) ≤ q ≤ max(y1, y2).

Help Simon! Find the minimum number of operations needed to color all cells of the table. Note that you can color one cell multiple times.

Input

The first line contains exactly two integers n, m (3 ≤ n, m ≤ 50).

Next n lines contain the description of the table cells. Specifically, the i-th line contains m space-separated integers ai1, ai2, ..., aim. If aij equals zero, then cell (i, j) isn't good. Otherwise aij equals one. It is guaranteed that at least one cell is good. It is guaranteed that no good cell is a corner.

Output

Print a single number — the minimum number of operations Simon needs to carry out his idea.

Examples

Input

3 3
0 0 0
0 1 0
0 0 0

Output

4

Input

4 3
0 0 0
0 0 1
1 0 0
0 0 0

Output

2

Note

In the first sample, the sequence of operations can be like this:

<image>

  * For the first time you need to choose cell (2, 2) and corner (1, 1).
  * For the second time you need to choose cell (2, 2) and corner (3, 3).
  * For the third time you need to choose cell (2, 2) and corner (3, 1).
  * For the fourth time you need to choose cell (2, 2) and corner (1, 3).

In the second sample the sequence of operations can be like this:

<image>

  * For the first time you need to choose cell (3, 1) and corner (4, 3).
  * For the second time you need to choose cell (2, 3) and corner (1, 1).

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int n, m, x;
  int zhong = 0, bian = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &x);
      if (x == 1) {
        if (i == 1 || j == 1 || i == n || j == m) {
          bian = 1;
        } else {
          zhong = 1;
        }
      }
    }
  }
  if (bian == 1) {
    printf("2\n");
    return 0;
  }
  if (zhong == 1) {
    printf("4\n");
    return 0;
  }
  printf("0\n");
  return 0;
}

```


### Prompt

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

It is well known that Berland has n cities, which form the Silver ring — cities i and i + 1 (1 ≤ i < n) are connected by a road, as well as the cities n and 1. The goverment have decided to build m new roads. The list of the roads to build was prepared. Each road will connect two cities. Each road should be a curve which lies inside or outside the ring. New roads will have no common points with the ring (except the endpoints of the road).

Now the designers of the constructing plan wonder if it is possible to build the roads in such a way that no two roads intersect (note that the roads may intersect at their endpoints). If it is possible to do, which roads should be inside the ring, and which should be outside?

Input

The first line contains two integers n and m (4 ≤ n ≤ 100, 1 ≤ m ≤ 100). Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi). No two cities will be connected by more than one road in the list. The list will not contain the roads which exist in the Silver ring.

Output

If it is impossible to build the roads in such a way that no two roads intersect, output Impossible. Otherwise print m characters. i-th character should be i, if the road should be inside the ring, and o if the road should be outside the ring. If there are several solutions, output any of them.

Examples

Input

4 2
1 3
2 4

Output

io

Input

6 3
1 3
3 5
5 1

Output

ooo

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int n, m;
pair<int, int> arr[N];
vector<int> g[N];
int col[N];
bool vis[N];
bool flag = true;
bool intersects(pair<int, int> a, pair<int, int> b) {
  if (a.first > a.second) swap(a.first, a.second);
  if (b.first > b.second) swap(b.first, b.second);
  if (a.first >= b.second or a.second <= b.first) return false;
  if (a.first == b.first || a.first == b.second || a.second == b.first ||
      a.second == b.second)
    return false;
  if (a.first < b.first && b.second < a.second) return false;
  if (b.first < a.first && a.second < b.second) return false;
  return true;
}
void dfs(int u, int c) {
  vis[u] = true;
  col[u] = c;
  for (auto to : g[u]) {
    if (vis[to]) {
      if (col[to] == c) flag = false;
      continue;
    }
    dfs(to, 1 - c);
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  int i, j;
  for (i = 0; 0 < m ? i < m : i > m; 0 < m ? i += 1 : i -= 1) {
    cin >> arr[i].first >> arr[i].second;
  }
  for (i = 0; 0 < m ? i < m : i > m; 0 < m ? i += 1 : i -= 1) {
    for (j = i + 1; i + 1 < m ? j < m : j > m; i + 1 < m ? j += 1 : j -= 1) {
      if (intersects(arr[i], arr[j])) {
        g[i].push_back(j);
        g[j].push_back(i);
      }
    }
  }
  for (i = 0; 0 < m ? i < m : i > m; 0 < m ? i += 1 : i -= 1) {
    if (!vis[i]) {
      dfs(i, 1);
    }
  }
  if (!flag) {
    cout << "Impossible" << endl;
    return 0;
  }
  for (i = 0; 0 < m ? i < m : i > m; 0 < m ? i += 1 : i -= 1) {
    if (col[i] == 1)
      cout << "i";
    else
      cout << "o";
  }
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Some company is going to hold a fair in Byteland. There are n towns in Byteland and m two-way roads between towns. Of course, you can reach any town from any other town using roads.

There are k types of goods produced in Byteland and every town produces only one type. To hold a fair you have to bring at least s different types of goods. It costs d(u,v) coins to bring goods from town u to town v where d(u,v) is the length of the shortest path from u to v. Length of a path is the number of roads in this path.

The organizers will cover all travel expenses but they can choose the towns to bring goods from. Now they want to calculate minimum expenses to hold a fair in each of n towns.

Input

There are 4 integers n, m, k, s in the first line of input (1 ≤ n ≤ 10^{5}, 0 ≤ m ≤ 10^{5}, 1 ≤ s ≤ k ≤ min(n, 100)) — the number of towns, the number of roads, the number of different types of goods, the number of different types of goods necessary to hold a fair.

In the next line there are n integers a_1, a_2, …, a_n (1 ≤ a_{i} ≤ k), where a_i is the type of goods produced in the i-th town. It is guaranteed that all integers between 1 and k occur at least once among integers a_{i}.

In the next m lines roads are described. Each road is described by two integers u v (1 ≤ u, v ≤ n, u ≠ v) — the towns connected by this road. It is guaranteed that there is no more than one road between every two towns. It is guaranteed that you can go from any town to any other town via roads.

Output

Print n numbers, the i-th of them is the minimum number of coins you need to spend on travel expenses to hold a fair in town i. Separate numbers with spaces.

Examples

Input

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

Output

2 2 2 2 3

Input

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

Output

1 1 1 2 2 1 1

Note

Let's look at the first sample.

To hold a fair in town 1 you can bring goods from towns 1 (0 coins), 2 (1 coin) and 4 (1 coin). Total numbers of coins is 2.

Town 2: Goods from towns 2 (0), 1 (1), 3 (1). Sum equals 2.

Town 3: Goods from towns 3 (0), 2 (1), 4 (1). Sum equals 2.

Town 4: Goods from towns 4 (0), 1 (1), 5 (1). Sum equals 2.

Town 5: Goods from towns 5 (0), 4 (1), 3 (2). Sum equals 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1000000007;
constexpr int mod1 = 998244353;
vector<int> dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0};
bool inside(int y, int x, int h, int w) {
  if (y < h && y >= 0 && x < w && x >= 0) return true;
  return false;
}
const int inf = 1000000000;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, k, s;
  cin >> n >> m >> k >> s;
  vector<vector<int>> a(k);
  for (int i = 0; i < (n); ++i) {
    int t;
    cin >> t;
    t--;
    a.at(t).push_back(i);
  }
  vector<vector<int>> g(n, vector<int>());
  for (int i = 0; i < (m); ++i) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  vector<vector<int>> ans(n, vector<int>(k));
  vector<int> dist(n);
  queue<int> q;
  for (int i = 0; i < (k); ++i) {
    for (int j = 0; j < (n); ++j) dist.at(j) = inf;
    for (int j = 0; j < (a.at(i).size()); ++j) {
      dist.at(a[i][j]) = 0;
      q.push(a[i][j]);
    }
    while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (int j = 0; j < (g.at(cur).size()); ++j) {
        int next = g[cur][j];
        if (dist[next] > dist[cur] + 1) {
          dist[next] = dist[cur] + 1;
          q.push(next);
        }
      }
    }
    for (int j = 0; j < (n); ++j) {
      ans[j][i] = dist[j];
    }
  }
  for (int i = 0; i < (n); ++i) {
    int sum = 0;
    sort(ans[i].begin(), ans[i].end());
    for (int j = 0; j < (s); ++j) sum += ans[i][j];
    if (i == n - 1)
      cout << sum << endl;
    else
      cout << sum << " ";
  }
}

```


### Prompt

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

Allen and Bessie are playing a simple number game. They both know a function f: \{0, 1\}^n → R, i. e. the function takes n binary arguments and returns a real value. At the start of the game, the variables x_1, x_2, ..., x_n are all set to -1. Each round, with equal probability, one of Allen or Bessie gets to make a move. A move consists of picking an i such that x_i = -1 and either setting x_i → 0 or x_i → 1.

After n rounds all variables are set, and the game value resolves to f(x_1, x_2, ..., x_n). Allen wants to maximize the game value, and Bessie wants to minimize it.

Your goal is to help Allen and Bessie find the expected game value! They will play r+1 times though, so between each game, exactly one value of f changes. In other words, between rounds i and i+1 for 1 ≤ i ≤ r, f(z_1, ..., z_n) → g_i for some (z_1, ..., z_n) ∈ \{0, 1\}^n. You are to find the expected game value in the beginning and after each change.

Input

The first line contains two integers n and r (1 ≤ n ≤ 18, 0 ≤ r ≤ 2^{18}).

The next line contains 2^n integers c_0, c_1, ..., c_{2^n-1} (0 ≤ c_i ≤ 10^9), denoting the initial values of f. More specifically, f(x_0, x_1, ..., x_{n-1}) = c_x, if x = \overline{x_{n-1} … x_0} in binary.

Each of the next r lines contains two integers z and g (0 ≤ z ≤ 2^n - 1, 0 ≤ g ≤ 10^9). If z = \overline{z_{n-1} ... z_0} in binary, then this means to set f(z_0, ..., z_{n-1}) → g.

Output

Print r+1 lines, the i-th of which denotes the value of the game f during the i-th round. Your answer must have absolute or relative error within 10^{-6}.

Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if \frac{|a - b|}{max{(1, |b|)}} ≤ 10^{-6}.

Examples

Input

2 2
0 1 2 3
2 5
0 4

Output

1.500000
2.250000
3.250000

Input

1 0
2 3

Output

2.500000

Input

2 0
1 1 1 1

Output

1.000000

Note

Consider the second test case. If Allen goes first, he will set x_1 → 1, so the final value will be 3. If Bessie goes first, then she will set x_1 → 0 so the final value will be 2. Thus the answer is 2.5.

In the third test case, the game value will always be 1 regardless of Allen and Bessie's play.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 19;
int read() {
  int s = 0;
  char c = getchar(), lc = '+';
  while (c < '0' || '9' < c) lc = c, c = getchar();
  while ('0' <= c && c <= '9') s = s * 10 + c - '0', c = getchar();
  return lc == '-' ? -s : s;
}
void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x < 10)
    putchar(x + '0');
  else {
    write(x / 10);
    putchar(x % 10 + '0');
  }
}
void print(int x, char c = '\n') {
  write(x);
  putchar(c);
}
int a[N];
double sum = 0;
signed main() {
  int n = read(), m = read();
  for (int i = 0; i < (1 << n); i++) sum += a[i] = read();
  printf("%.8lf\n", sum / (1 << n));
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    sum -= a[x];
    sum += a[x] = y;
    printf("%.8lf\n", sum / (1 << n));
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

You are given an integer k and a tree T with n nodes (n is even).

Let dist(u, v) be the number of edges on the shortest path from node u to node v in T.

Let us define a undirected weighted complete graph G = (V, E) as following:

  * V = \\{x ∣ 1 ≤ x ≤ n \} i.e. the set of integers from 1 to n
  * E = \{(u, v, w) ∣ 1 ≤ u, v ≤ n, u ≠ v, w = dist(u, v) \} i.e. there is an edge between every pair of distinct nodes, the weight being the distance between their respective nodes in T

Your task is simple, find a perfect matching in G with total edge weight k (1 ≤ k ≤ n^2).

Input

The first line of input contains two integers n, k (2 ≤ n ≤ 100 000, n is even, 1 ≤ k ≤ n^2): number of nodes and the total edge weight of the perfect matching you need to find.

The i-th of the following n - 1 lines contains two integers v_i, u_i (1 ≤ v_i, u_i ≤ n) denoting an edge between v_i and u_i in T. It is guaranteed that the given graph is a tree.

Output

If there are no matchings that satisfy the above condition, output "NO" (without quotes) on a single line.

Otherwise, you should output "YES" (without quotes) on the first line of output.

You should then output n/2 lines, the i-th line containing p_i, q_i (1 ≤ p_i, q_i ≤ n): the i-th pair of the matching.

Examples

Input

4 2
1 2
2 3
3 4

Output

YES
2 1
3 4

Input

4 4
1 2
2 3
3 4

Output

YES
3 1
2 4

Note

A tree is a connected acyclic undirected graph.

A matching is set of pairwise non-adjacent edges, none of which are loops; that is, no two edges share a common vertex.

A perfect matching is a matching which matches all vertices of the graph; that is, every vertex of the graph is incident to exactly one edge of the matching.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const unsigned gen_seed =
    std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937_64 gen(gen_seed);
std::vector<std::vector<int> > g;
int n, l;
std::vector<int> tin, tout;
int timer;
vector<vector<int> > up;
std::vector<int> lev;
void dfs(int v, int p, int curl) {
  lev[v] = curl;
  tin[v] = ++timer;
  up[v][0] = p;
  for (int i = 1; i <= l; ++i) up[v][i] = up[up[v][i - 1]][i - 1];
  for (size_t i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (to != p) dfs(to, v, curl + 1);
  }
  tout[v] = ++timer;
}
std::vector<int> maj;
std::vector<int> st;
int go(int v, int p) {
  st[v] = 1;
  for (auto u : g[v]) {
    if (u == p) continue;
    st[v] += go(u, v);
  }
  for (auto u : g[v]) {
    if (st[u] * 2 >= n) maj[v] = u;
  }
  return st[v];
}
bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }
int lca(int a, int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (int i = l; i >= 0; --i)
    if (!upper(up[a][i], b)) a = up[a][i];
  return up[a][0];
}
int dist(int a, int b) {
  int c = lca(a, b);
  return lev[a] + lev[b] - 2 * lev[c];
}
std::vector<int> getpath(int a, int b) {
  int c = lca(a, b);
  std::vector<int> ret;
  std::vector<int> rev;
  while (a != c) {
    ret.push_back(a);
    a = up[a][0];
  }
  while (b != c) {
    rev.push_back(b);
    b = up[b][0];
  }
  reverse((rev).begin(), (rev).end());
  ret.push_back(c);
  for (auto x : rev) ret.push_back(x);
  return ret;
}
long long todist(std::vector<int>& x) {
  long long ret = 0;
  for (int i = 0; i < n; i++)
    if (x[i] > i) ret += dist(x[i], i);
  return ret;
}
std::vector<std::pair<int, int> > prmin;
int greed(int v, int p) {
  std::vector<int> stray;
  for (auto u : g[v]) {
    if (u == p) continue;
    int ret = greed(u, v);
    if (ret != -1) stray.push_back(ret);
  }
  stray.push_back(v);
  while (stray.size() >= 2) {
    int p = stray.size();
    prmin.push_back(make_pair(stray[p - 1], stray[p - 2]));
    stray.pop_back();
    stray.pop_back();
  }
  int ret = -1;
  if (stray.size() == 1) ret = stray[0];
  return ret;
}
std::vector<int> tomin;
int main() {
  long long k;
  scanf("%d %lld", &n, &k);
  l = 1;
  while ((1 << l) <= n) ++l;
  tin.resize(n), tout.resize(n), up.resize(n);
  for (int i = 0; i < n; ++i) up[i].resize(l + 1);
  lev.resize(n);
  st = std::vector<int>(n, 0);
  g.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  if (n == 2) {
    if (k != 1)
      cout << "NO\n";
    else {
      cout << "YES\n";
      cout << "1 2\n";
    }
    exit(0);
  }
  for (int i = 0; i < n; i++) maj.push_back(i);
  go(0, 0);
  int root = 0;
  while (maj[root] != root) root = maj[root];
  dfs(root, root, 0);
  long long mx = 0;
  for (int i = 0; i < n; i++) mx += lev[i];
  std::vector<std::pair<int, int> > ord;
  for (int i = 0; i < n; i++) ord.push_back(make_pair(tin[i], i));
  sort((ord).begin(), (ord).end());
  std::vector<std::pair<int, int> > prmax;
  for (int i = 0; i < n / 2; i++)
    prmax.push_back(make_pair(ord[i].second, ord[i + n / 2].second));
  greed(root, root);
  long long mn = 0;
  for (int i = 0; i < n / 2; i++) {
    mn += dist(prmin[i].first, prmin[i].second);
  }
  std::vector<int> tomax(n);
  tomin.resize(n);
  for (int i = 0; i < n / 2; i++) {
    tomin[prmin[i].first] = prmin[i].second;
    tomin[prmin[i].second] = prmin[i].first;
    tomax[prmax[i].first] = prmax[i].second;
    tomax[prmax[i].second] = prmax[i].first;
  }
  if (k % 2 != mn % 2 || k < mn || k > mx) {
    cout << "NO\n";
    exit(0);
  }
  int eq = 0;
  while (1) {
    if (eq == n) break;
    if (tomin[eq] == tomax[eq]) {
      eq++;
      continue;
    }
    int cp = tomin[tomax[eq]];
    int neq = tomin[eq];
    int xeq = tomax[eq];
    if (mn == k) break;
    swap(tomin[cp], tomin[eq]);
    swap(tomin[xeq], tomin[neq]);
    long long md =
        mn - dist(eq, neq) - dist(xeq, cp) + dist(eq, xeq) + dist(cp, neq);
    if (md == k)
      break;
    else if (md < k) {
      eq++;
      mn = md;
      continue;
    } else {
      swap(tomin[cp], tomin[eq]);
      swap(tomin[xeq], tomin[neq]);
      std::vector<int> path = getpath(eq, cp);
      for (auto x : path) {
        if (x == tomin[eq]) {
          eq = tomin[eq];
          path = getpath(eq, cp);
          break;
        }
      }
      int q = path.size();
      for (int i = 0; i < q - 1; i++) {
        int a = path[i];
        int b = path[i + 1];
        int ca = tomin[a];
        int cb = tomin[b];
        swap(tomin[a], tomin[b]);
        swap(tomin[ca], tomin[cb]);
        if (ca != b)
          mn += dist(a, cb) + dist(b, ca) - dist(a, ca) - dist(b, cb);
        if (mn == k) {
          printf("YES\n");
          for (int i = 0; i < n; i++) {
            if (tomin[i] > i) printf("%d %d\n", i + 1, tomin[i] + 1);
          }
          exit(0);
        }
      }
      for (int i = q - 3; i >= 0; i--) {
        int a = path[i];
        int b = path[i + 1];
        int ca = tomin[a];
        int cb = tomin[b];
        swap(tomin[a], tomin[b]);
        swap(tomin[ca], tomin[cb]);
        if (ca != b)
          mn += dist(a, cb) + dist(b, ca) - dist(a, ca) - dist(b, cb);
        if (mn == k) {
          printf("YES\n");
          for (int i = 0; i < n; i++) {
            if (tomin[i] > i) printf("%d %d\n", i + 1, tomin[i] + 1);
          }
          exit(0);
        }
      }
      printf("NO\n");
      exit(0);
    }
  }
  printf("YES\n");
  for (int i = 0; i < n; i++) {
    if (tomin[i] > i) printf("%d %d\n", i + 1, tomin[i] + 1);
  }
}

```


### Prompt

Create a solution in CPP for the following problem:

Draw a rectangle which has a height of H cm and a width of W cm. Draw a 1-cm square by single '#'.

Constraints

* 1 ≤ H ≤ 300
* 1 ≤ W ≤ 300

Input

The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space.

The input ends with two 0 (when both H and W are zero).

Output

For each dataset, print the rectangle made of H × W '#'.

Print a blank line after each dataset.

Example

Input

3 4
5 6
2 2
0 0

Output

####
####
####

######
######
######
######
######

##
##

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int h,w;
while(1){

cin >>h>>w;

if(h==0&&w==0){
break;
}

else{

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

for(int  j=0;j<w;j++){

cout <<"#";

}
cout <<endl;

}

cout <<endl;

}

}

}

```


### Prompt

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

You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved.

The square still has a rectangular shape of n × m meters. However, the picture is about to get more complicated now. Let a_{i,j} be the j-th square in the i-th row of the pavement.

You are given the picture of the squares:

  * if a_{i,j} =  "*", then the j-th square in the i-th row should be black;
  * if a_{i,j} =  ".", then the j-th square in the i-th row should be white.

The black squares are paved already. You have to pave the white squares. There are two options for pavement tiles:

  * 1 × 1 tiles — each tile costs x burles and covers exactly 1 square;
  * 1 × 2 tiles — each tile costs y burles and covers exactly 2 adjacent squares of the same row. Note that you are not allowed to rotate these tiles or cut them into 1 × 1 tiles.

You should cover all the white squares, no two tiles should overlap and no black squares should be covered by tiles.

What is the smallest total price of the tiles needed to cover all the white squares?

Input

The first line contains a single integer t (1 ≤ t ≤ 500) — the number of testcases. Then the description of t testcases follow.

The first line of each testcase contains four integers n, m, x and y (1 ≤ n ≤ 100; 1 ≤ m ≤ 1000; 1 ≤ x, y ≤ 1000) — the size of the Theatre square, the price of the 1 × 1 tile and the price of the 1 × 2 tile.

Each of the next n lines contains m characters. The j-th character in the i-th line is a_{i,j}. If a_{i,j} =  "*", then the j-th square in the i-th row should be black, and if a_{i,j} =  ".", then the j-th square in the i-th row should be white.

It's guaranteed that the sum of n × m over all testcases doesn't exceed 10^5.

Output

For each testcase print a single integer — the smallest total price of the tiles needed to cover all the white squares in burles.

Example

Input

4
1 1 10 1
.
1 2 10 1
..
2 1 10 1
.
.
3 3 3 7
..*
*..
.*.

Output

10
1
20
18

Note

In the first testcase you are required to use a single 1 × 1 tile, even though 1 × 2 tile is cheaper. So the total price is 10 burles.

In the second testcase you can either use two 1 × 1 tiles and spend 20 burles or use a single 1 × 2 tile and spend 1 burle. The second option is cheaper, thus the answer is 1.

The third testcase shows that you can't rotate 1 × 2 tiles. You still have to use two 1 × 1 tiles for the total price of 20.

In the fourth testcase the cheapest way is to use 1 × 1 tiles everywhere. The total cost is 6 ⋅ 3 = 18.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
  if (b == 0) return 1;
  if (b == 1)
    return a;
  else {
    long long t = power(a, b / 2);
    if (b % 2 == 0)
      return ((t % 1000000007) * (t % 1000000007)) % 1000000007;
    else
      return ((((t % 1000000007) * (t % 1000000007)) % 1000000007) *
              ((a % 1000000007) % 1000000007)) %
             1000000007;
  }
}
void solve() {
  long long n, m, x, y, c = 0, co = 0, ans, i, j;
  cin >> n >> m >> x >> y;
  char s[n + 1][m + 1];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> s[i][j];
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (j == m - 1) {
        if (s[i][j] == '.') c += x;
      } else {
        if (s[i][j] == '.' && s[i][j + 1] == '.') {
          c += y;
          j++;
        } else if (s[i][j] == '.' && s[i][j + 1] != '.')
          c += x;
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (s[i][j] == '.') co++;
    }
  }
  co = co * x;
  ans = min(c, co);
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

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

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

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

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

Input

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

Output

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

Examples

Input

12

Output

4

Input

20

Output

15

Input

10

Output

0

Note

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

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  n -= 10;
  if (n <= 0) {
    cout << 0;
  } else {
    if (n == 10)
      cout << 15;
    else if (n <= 11)
      cout << 4;
    else
      cout << 0;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(9);
  solve();
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

There are N children, numbered 1, 2, ..., N.

Snuke has decided to distribute x sweets among them. He needs to give out all the x sweets, but some of the children may get zero sweets.

For each i (1 \leq i \leq N), Child i will be happy if he/she gets exactly a_i sweets. Snuke is trying to maximize the number of happy children by optimally distributing the sweets. Find the maximum possible number of happy children.

Constraints

* All values in input are integers.
* 2 \leq N \leq 100
* 1 \leq x \leq 10^9
* 1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N x
a_1 a_2 ... a_N

Output

Print the maximum possible number of happy children.

Examples

Input

3 70
20 30 10

Output

2

Input

3 10
20 30 10

Output

1

Input

4 1111
1 10 100 1000

Output

4

Input

2 10
20 20

Output

0

### Response

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

```


### Prompt

Develop a solution in Cpp to the problem described below:

One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of n lines of code. Vasya is already exhausted, so he works like that: first he writes v lines of code, drinks a cup of tea, then he writes as much as <image> lines, drinks another cup of tea, then he writes <image> lines and so on: <image>, <image>, <image>, ...

The expression <image> is regarded as the integral part from dividing number a by number b.

The moment the current value <image> equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished.

Vasya is wondering, what minimum allowable value v can take to let him write not less than n lines of code before he falls asleep.

Input

The input consists of two integers n and k, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1 ≤ n ≤ 109, 2 ≤ k ≤ 10.

Output

Print the only integer — the minimum value of v that lets Vasya write the program in one night.

Examples

Input

7 2

Output

4

Input

59 9

Output

54

Note

In the first sample the answer is v = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task.

In the second sample the answer is v = 54. Vasya writes the code in the following portions: 54, 6. The total sum is 54 + 6 = 60, that's even more than n = 59.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, a, k, b, c, n, t, m, p, q, d, e, f, y, g, z, h, r, l, x,
      o;
  long double aa, bb, ee, dd, ff, kk, gg;
  vector<long long int> v, s, vv;
  map<long long int, vector<long long int> > me;
  map<long long int, long long int> sa, ta, pa, ma;
  priority_queue<long long int, vector<long long int>, greater<long long int> >
      aq, tq, pq;
  string st, et, ft, pt, ct;
  deque<long long int> de, pe, ne;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  l = 1;
  r = n * 2;
  while (l < r) {
    c = (l + r) / 2;
    a = c;
    d = 0;
    while (c) {
      d = d + c;
      c = c / k;
    }
    if (d < n)
      l = a + 1;
    else
      r = a;
  }
  cout << l << endl;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Borya has recently found a big electronic display. The computer that manages the display stores some integer number. The number has n decimal digits, the display shows the encoded version of the number, where each digit is shown using some lowercase letter of the English alphabet.

There is a legend near the display, that describes how the number is encoded. For each digit position i and each digit j the character c is known, that encodes this digit at this position. Different digits can have the same code characters.

Each second the number is increased by 1. And one second after a moment when the number reaches the value that is represented as n 9-s in decimal notation, the loud beep sounds.

Andrew knows the number that is stored in the computer. Now he wants to know how many seconds must pass until Borya can definitely tell what was the original number encoded by the display. Assume that Borya can precisely measure time, and that the encoded number will first be increased exactly one second after Borya started watching at the display.

Input

Input data contains multiple test cases. The first line of input contains t (1 ≤ t ≤ 100) — the number of test cases.

Each test case is described as follows. The first line of the description contains n (1 ≤ n ≤ 18) — the number of digits in the number. The second line contains n decimal digits without spaces (but possibly with leading zeroes) — the number initially stored in the display computer. The following n lines contain 10 characters each. The j-th character of the i-th of these lines is the code character for a digit j - 1 in position i, most significant digit positions are described first.

Output

For each test case print an integer: the number of seconds until Borya definitely knows what was the initial number stored on the display of the computer. Do not print leading zeroes.

Example

Input

3
2
42
abcdefghij
jihgfedcba
2
42
aaaaaaaaaa
aaaaaaaaaa
1
2
abcdabcdff

Output

0
58
2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;
const int g[2] = {23, 37};
char s[maxn][maxn];
long long pw[maxn];
int n;
int cas;
bool equal(long long a, long long b) {
  for (int i = 0; i < n; i++, a /= 10, b /= 10)
    if (s[i][a % 10] != s[i][b % 10]) return 0;
  return 1;
}
long long calc(int bit, long long a, long long b) {
  if (a > b) swap(a, b);
  long long ans = pw[n] - b;
  if (!equal(a, b)) return 0;
  for (int i = bit; i < n; i++) {
    long long cur = b / (pw[i]) * pw[i];
    long long jump = pw[i];
    for (int j = 1; j < 10; j++) {
      cur += jump;
      long long step = cur - b;
      if (step >= ans) break;
      long long ano = a + step;
      if (!equal(ano, cur)) {
        ans = min(ans, step);
        break;
      }
    }
  }
  return ans;
}
void work() {
  ++cas;
  static char st[maxn];
  scanf("%d", &n);
  scanf("%s", st);
  reverse(st, st + n);
  long long v = 0, up = 1;
  pw[0] = 1;
  for (int i = 1; i <= n; i++) pw[i] = pw[i - 1] * 10;
  for (int i = 0; i < n; i++) v = v + (st[i] - 48) * pw[i];
  long long ans = 0;
  for (int i = n - 1; i >= 0; i--) scanf("%s", s[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 10; j++)
      if (j != st[i] - 48)
        ans = max(ans, calc(i, v, v - (st[i] - 48) * pw[i] + j * pw[i]));
  printf("%lld\n", ans);
}
int main() {
  int t;
  scanf("%d", &t);
  for (; t; t--) work();
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

A competitive eater, Alice is scheduling some practices for an eating contest on a magical calendar. The calendar is unusual because a week contains not necessarily 7 days!

In detail, she can choose any integer k which satisfies 1 ≤ k ≤ r, and set k days as the number of days in a week.

Alice is going to paint some n consecutive days on this calendar. On this calendar, dates are written from the left cell to the right cell in a week. If a date reaches the last day of a week, the next day's cell is the leftmost cell in the next (under) row.

She wants to make all of the painted cells to be connected by side. It means, that for any two painted cells there should exist at least one sequence of painted cells, started in one of these cells, and ended in another, such that any two consecutive cells in this sequence are connected by side.

Alice is considering the shape of the painted cells. Two shapes are the same if there exists a way to make them exactly overlapped using only parallel moves, parallel to the calendar's sides.

For example, in the picture, a week has 4 days and Alice paints 5 consecutive days. [1] and [2] are different shapes, but [1] and [3] are equal shapes.

<image>

Alice wants to know how many possible shapes exists if she set how many days a week has and choose consecutive n days and paints them in calendar started in one of the days of the week. As was said before, she considers only shapes, there all cells are connected by side.

Input

The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Next t lines contain descriptions of test cases.

For each test case, the only line contains two integers n, r (1 ≤ n ≤ 10^9, 1 ≤ r ≤ 10^9).

Output

For each test case, print a single integer — the answer to the problem.

Please note, that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language.

Example

Input

5
3 4
3 2
3 1
13 7
1010000 9999999

Output

4
3
1
28
510049495001

Note

In the first test case, Alice can set 1,2,3 or 4 days as the number of days in a week.

There are 6 possible paintings shown in the picture, but there are only 4 different shapes. So, the answer is 4. Notice that the last example in the picture is an invalid painting because all cells are not connected by sides.

<image>

In the last test case, be careful with the overflow issue, described in the output format.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 10;
const long long INF = 1e9 + 10;
const long long MOD = 1e9 + 7;
void solve() {
  long long n, r;
  cin >> n >> r;
  if (n > r)
    cout << r * (r + 1) / 2 << '\n';
  else
    cout << n * (n - 1) / 2 + 1 << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

We will buy a product for N yen (the currency of Japan) at a shop.

If we use only 1000-yen bills to pay the price, how much change will we receive?

Assume we use the minimum number of bills required.

Constraints

* 1 \leq N \leq 10000
* N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the amount of change as an integer.

Examples

Input

1900

Output

100

Input

3000

Output

0

### Response

```cpp
#include <iostream>
using namespace std;
int main()
{
	int N;
	cin >> N;
	cout << (10000 - N) % 1000;
}
```


### Prompt

Please formulate a cpp solution to the following problem:

Given are N integers A_1,\ldots,A_N.

We will choose exactly K of these elements. Find the maximum possible product of the chosen elements.

Then, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).

Constraints

* 1 \leq K \leq N \leq 2\times 10^5
* |A_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

N K
A_1 \ldots A_N

Output

Print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).

Examples

Input

4 2
1 2 -3 -4

Output

12

Input

4 3
-1 -2 -3 -4

Output

1000000001

Input

2 1
-1 1000000000

Output

1000000000

Input

10 10
1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1

Output

999983200

### Response

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

using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll A[300001];
int main()
{
    ll n,k;
    cin>>n>>k;

    for(int i=0; i<n; i++)
        cin>>A[i];
    sort(A,A+n);
    ll ans=1,sign=0;
    int l=0,r=n-1;
    if(k%2)
    {
        ans=A[r];
        r--;
        --k;
        if(ans<0)
            sign=1;
    }
    while(k)
    {
        ll x=A[l]*A[l+1],y=A[r]*A[r-1];
        if(sign)
        {
            if(x<y)
            {
                ans=x%mod*ans%mod;
                l+=2;
            }
            else
            {
                ans=y%mod*ans%mod;
                r-=2;
            }
        }
        else
        {
            if(x>y)
            {
                ans=x%mod*ans%mod;
                l+=2;
            }
            else
            {
                ans=y%mod*ans%mod;
                r-=2;
            }
        }
        k-=2;
    }
    cout<<(ans+mod)%mod<<endl;
    return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.

Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya.

Input

The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.

Next follows number n (1 ≤ n ≤ 90) — the number of fouls.

Each of the following n lines contains information about a foul in the following form:

  * first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs;
  * then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player;
  * then goes the player's number m (1 ≤ m ≤ 99);
  * then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given.

The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute.

Output

For each event when a player received his first red card in a chronological order print a string containing the following information:

  * The name of the team to which the player belongs;
  * the player's number in his team;
  * the minute when he received the card.

If no player received a card, then you do not need to print anything.

It is possible case that the program will not print anything to the output (if there were no red cards).

Examples

Input

MC
CSKA
9
28 a 3 y
62 h 25 y
66 h 42 y
70 h 25 y
77 a 4 y
79 a 25 y
82 h 42 r
89 h 16 y
90 a 13 r

Output

MC 25 70
MC 42 82
CSKA 13 90

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  string s[2];
  cin >> s[0] >> s[1];
  int t;
  cin >> t;
  int a[2][100] = {0};
  while (t--) {
    int min;
    string wh;
    int num;
    string get;
    cin >> min >> wh >> num >> get;
    int p = wh == "a" ? 1 : 0;
    if (get == "y") {
      a[p][num]++;
      if (a[p][num] == 2) {
        cout << s[p] << " " << num << " " << min << endl;
      }
    } else {
      if (a[p][num] < 2) {
        a[p][num] = 2;
        cout << s[p] << " " << num << " " << min << endl;
      }
    }
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

There are n seats in the train's car and there is exactly one passenger occupying every seat. The seats are numbered from 1 to n from left to right. The trip is long, so each passenger will become hungry at some moment of time and will go to take boiled water for his noodles. The person at seat i (1 ≤ i ≤ n) will decide to go for boiled water at minute t_i.

Tank with a boiled water is located to the left of the 1-st seat. In case too many passengers will go for boiled water simultaneously, they will form a queue, since there can be only one passenger using the tank at each particular moment of time. Each passenger uses the tank for exactly p minutes. We assume that the time it takes passengers to go from their seat to the tank is negligibly small.

Nobody likes to stand in a queue. So when the passenger occupying the i-th seat wants to go for a boiled water, he will first take a look on all seats from 1 to i - 1. In case at least one of those seats is empty, he assumes that those people are standing in a queue right now, so he would be better seating for the time being. However, at the very first moment he observes that all seats with numbers smaller than i are busy, he will go to the tank.

There is an unspoken rule, that in case at some moment several people can go to the tank, than only the leftmost of them (that is, seating on the seat with smallest number) will go to the tank, while all others will wait for the next moment.

Your goal is to find for each passenger, when he will receive the boiled water for his noodles.

Input

The first line contains integers n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 10^9) — the number of people and the amount of time one person uses the tank.

The second line contains n integers t_1, t_2, ..., t_n (0 ≤ t_i ≤ 10^9) — the moments when the corresponding passenger will go for the boiled water.

Output

Print n integers, where i-th of them is the time moment the passenger on i-th seat will receive his boiled water.

Example

Input

5 314
0 310 942 628 0

Output

314 628 1256 942 1570

Note

Consider the example.

At the 0-th minute there were two passengers willing to go for a water, passenger 1 and 5, so the first passenger has gone first, and returned at the 314-th minute. At this moment the passenger 2 was already willing to go for the water, so the passenger 2 has gone next, and so on. In the end, 5-th passenger was last to receive the boiled water.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int n, p, pos, t[maxn], vis[maxn];
long long tim, ans[maxn];
queue<int> pre;
priority_queue<int, vector<int>, greater<int> > pp;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    q;
inline void Update(int x, int d) {
  for (; x <= n; x = x + (x & -x)) vis[x] = vis[x] + d;
}
inline int Query(int x) {
  for (int res = 0;; res = res + vis[x], x = x - (x & -x))
    if (x == 0) return res;
}
int main(int argc, char const *argv[]) {
  scanf("%d%d", &n, &p);
  for (int i = 1; i <= n; ++i) scanf("%d", t + i), q.push(make_pair(t[i], i));
  tim = q.top().first, pos = 0;
  while (!q.empty() || !pre.empty() || !pp.empty()) {
    while (!q.empty() && tim > q.top().first) {
      if (!pp.empty() && pp.top() < q.top().second && Query(pp.top()) == 0)
        pre.push(pp.top()), Update(pp.top(), 1), pp.pop();
      if (Query(q.top().second) == 0)
        pre.push(q.top().second), Update(q.top().second, 1), q.pop();
      else
        pp.push(q.top().second), q.pop();
    }
    if (pos) Update(pos, -1);
    while (!q.empty() && tim == q.top().first) {
      if (!pp.empty() && pp.top() < q.top().second && Query(pp.top()) == 0)
        pre.push(pp.top()), Update(pp.top(), 1), pp.pop();
      if (Query(q.top().second) == 0)
        pre.push(q.top().second), Update(q.top().second, 1), q.pop();
      else
        pp.push(q.top().second), q.pop();
    }
    if (!pp.empty() && Query(pp.top()) == 0)
      pre.push(pp.top()), Update(pp.top(), 1), pp.pop();
    if (pre.empty())
      tim = q.top().first, pos = 0;
    else
      tim = tim + p, ans[pos = pre.front()] = tim, pre.pop();
  }
  for (int i = 1; i <= n; ++i) printf("%I64d ", ans[i]);
  return 0;
}

```


### Prompt

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

Polycarp loves ciphers. He has invented his own cipher called Right-Left.

Right-Left cipher is used for strings. To encrypt the string s=s_{1}s_{2} ... s_{n} Polycarp uses the following algorithm:

  * he writes down s_1,
  * he appends the current word with s_2 (i.e. writes down s_2 to the right of the current result),
  * he prepends the current word with s_3 (i.e. writes down s_3 to the left of the current result),
  * he appends the current word with s_4 (i.e. writes down s_4 to the right of the current result),
  * he prepends the current word with s_5 (i.e. writes down s_5 to the left of the current result),
  * and so on for each position until the end of s.

For example, if s="techno" the process is: "t" → "te" → "cte" → "cteh" → "ncteh" → "ncteho". So the encrypted s="techno" is "ncteho".

Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.

Input

The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.

Output

Print such string s that after encryption it equals t.

Examples

Input

ncteho

Output

techno

Input

erfdcoeocs

Output

codeforces

Input

z

Output

z

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string t;
  cin >> t;
  int l = (t.length() + 1) / 2;
  int r = l + 1;
  l--;
  r--;
  bool f = true;
  while (l >= 0 || r < t.length()) {
    if (f)
      cout << t[l--];
    else
      cout << t[r++];
    f = !f;
  }
  char I;
  cin >> I;
  return 0;
}

```


### Prompt

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

You are given a string t consisting of n lowercase Latin letters and an integer number k.

Let's define a substring of some string s with indices from l to r as s[l ... r].

Your task is to construct such string s of minimum possible length that there are exactly k positions i such that s[i ... i + n - 1] = t. In other words, your task is to construct such string s of minimum possible length that there are exactly k substrings of s equal to t.

It is guaranteed that the answer is always unique.

Input

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 50) — the length of the string t and the number of substrings.

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

Output

Print such string s of minimum possible length that there are exactly k substrings of s equal to t.

It is guaranteed that the answer is always unique.

Examples

Input

3 4
aba

Output

ababababa

Input

3 2
cat

Output

catcat

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string s;
int f() {
  int len = s.size();
  for (int i = 1; i < len; ++i) {
    if (s.substr(i) == s.substr(0, len - i)) return len - i;
  }
  return 0;
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  cin >> s;
  int len = f();
  cout << s;
  for (int i = 1; i < k; ++i) cout << s.substr(len);
  cout << "\n";
  return 0;
}

```


### Prompt

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

You want to perform the combo on your opponent in one popular fighting game. The combo is the string s consisting of n lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in s. I.e. if s="abca" then you have to press 'a', then 'b', 'c' and 'a' again.

You know that you will spend m wrong tries to perform the combo and during the i-th try you will make a mistake right after p_i-th button (1 ≤ p_i < n) (i.e. you will press first p_i buttons right and start performing the combo from the beginning). It is guaranteed that during the m+1-th try you press all buttons right and finally perform the combo.

I.e. if s="abca", m=2 and p = [1, 3] then the sequence of pressed buttons will be 'a' (here you're making a mistake and start performing the combo from the beginning), 'a', 'b', 'c', (here you're making a mistake and start performing the combo from the beginning), 'a' (note that at this point you will not perform the combo because of the mistake), 'b', 'c', 'a'.

Your task is to calculate for each button (letter) the number of times you'll press it.

You have to answer t independent test cases.

Input

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

Then t test cases follow.

The first line of each test case contains two integers n and m (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ m ≤ 2 ⋅ 10^5) — the length of s and the number of tries correspondingly.

The second line of each test case contains the string s consisting of n lowercase Latin letters.

The third line of each test case contains m integers p_1, p_2, ..., p_m (1 ≤ p_i < n) — the number of characters pressed right during the i-th try.

It is guaranteed that the sum of n and the sum of m both does not exceed 2 ⋅ 10^5 (∑ n ≤ 2 ⋅ 10^5, ∑ m ≤ 2 ⋅ 10^5).

It is guaranteed that the answer for each letter does not exceed 2 ⋅ 10^9.

Output

For each test case, print the answer — 26 integers: the number of times you press the button 'a', the number of times you press the button 'b', ..., the number of times you press the button 'z'.

Example

Input

3
4 2
abca
1 3
10 5
codeforces
2 8 3 2 9
26 10
qwertyuioplkjhgfdsazxcvbnm
20 10 1 2 3 5 10 5 9 4

Output

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

Note

The first test case is described in the problem statement. Wrong tries are "a", "abc" and the final try is "abca". The number of times you press 'a' is 4, 'b' is 2 and 'c' is 2.

In the second test case, there are five wrong tries: "co", "codeforc", "cod", "co", "codeforce" and the final try is "codeforces". The number of times you press 'c' is 9, 'd' is 4, 'e' is 5, 'f' is 3, 'o' is 9, 'r' is 3 and 's' is 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int b[200005];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int m, n;
    cin >> n >> m;
    string s;
    cin >> s;
    long long a[30] = {0};
    memset(b, 0, sizeof(b));
    for (int i = 0; i < m; i++) cin >> b[i];
    sort(b, b + m);
    int x = 0;
    for (int i = 0; i < n; i++) {
      while (i + 1 > b[x] && b[x] != 0) x++;
      a[s[i] - 'a'] += m + 1 - x;
    }
    for (int i = 0; i < 26; i++) cout << a[i] << ' ';
    cout << endl;
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Akari has n kinds of flowers, one of each kind.

She is going to choose one or more of these flowers to make a bouquet.

However, she hates two numbers a and b, so the number of flowers in the bouquet cannot be a or b.

How many different bouquets are there that Akari can make?

Find the count modulo (10^9 + 7).

Here, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet.

Constraints

* All values in input are integers.
* 2 \leq n \leq 10^9
* 1 \leq a < b \leq \textrm{min}(n, 2 \times 10^5)

Input

Input is given from Standard Input in the following format:

n a b

Output

Print the number of bouquets that Akari can make, modulo (10^9 + 7). (If there are no such bouquets, print `0`.)

Examples

Input

4 1 3

Output

7

Input

1000000000 141421 173205

Output

34076506

### Response

```cpp
#include <bits/stdc++.h>
#define N 100005
#define ll long long
using namespace std;
ifstream in("in.txt");
const ll M=1000000007;
ll fortza(ll x, ll i){
    if(i==1){
        return x;
    }
    ll t=fortza(x,i/2);
    t=(t*t)%M;
    if(i&1){
        t=(t*x)%M;
    }
    return t;
}
int main(){
    ll n, a, b, x=1, t;
    cin>>n>>a>>b;
    for(ll i=1; i<=a; ++i){
        x=x*((n-i+1)*fortza(i, M-2)%M)%M;
    }
    t=(fortza(2, n)-1-x+M)%M;
    for(ll i=a+1; i<=b; ++i){
        x=x*((n-i+1)*fortza(i, M-2)%M)%M;
    }
    cout<<(t-x+M)%M;
    return 0;
}
```


### Prompt

Develop a solution in cpp to the problem described below:

This problem is interactive.

You should guess hidden number x which is between 1 and M = 10004205361450474, inclusive.

You could use up to 5 queries.

In each query, you can output an increasing sequence of k ≤ x integers, each between 1 and M, inclusive, and you will obtain one of the following as an answer:

  * either the hidden number belongs to your query sequence, in this case you immediately win;
  * or you will be given where the hidden number is located with respect to your query sequence, that is, either it is less than all numbers from the sequence, greater than all numbers from the sequence, or you will be given such an i that the hidden number x is between the i-th and the (i+1)-st numbers of your sequence.

See the interaction section for clarity.

Be aware that the interactor is adaptive, i.e. the hidden number can depend on queries the solution makes. However, it is guaranteed that for any solution the interactor works non-distinguishable from the situation when the hidden number is fixed beforehand.

Hacks are allowed only with fixed hidden number. A hack is represented by a single integer between 1 and M. In all pretests the hidden number is fixed as well.

Interaction

You can make up to 5 queries. To make a query print a number k (1 ≤ k ≤ 10^4) and then an increasing sequence t_0 < t_1 < … < t_{k-1} of k numbers, each between 1 and M, inclusive. If k > x, you lose.

You get one integer as a response.

  * If it is -2, it means you made an invalid query or you lost. Exit immediately after receiving -2 and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
  * If it is -1, you guessed the number and should terminate too.
  * Otherwise you get a number i between 0 and k, inclusive, denoting where the hidden number is, with respect to the printed numbers. If i = 0, then x < t_0. If i = k, then t_{k-1} < x. Otherwise t_{i-1} < x < t_i.

After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:

  * fflush(stdout) or cout.flush() in C++;
  * System.out.flush() in Java;
  * flush(output) in Pascal;
  * stdout.flush() in Python;
  * see documentation for other languages.

Example

Input

2

0

-1

Output

2 2 3

2 20 30

3 5 7 9

Note

In the first example the number 5 is hidden.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long LIM = 10004205361450474;
const int K = 10000;
long long cnt = 0;
pair<long long, long long> query(vector<long long> V) {
  cnt++;
  assert(cnt <= 5);
  assert(V[0] >= (long long)V.size() - 2);
  assert(V.size() <= K + 2);
  printf("%d ", (int)V.size() - 2);
  for (int i = (1); i < ((int)V.size() - 1); i++) printf("%lld ", V[i]);
  printf("\n");
  fflush(stdout);
  int ind;
  scanf("%d", &ind);
  if (ind == -1) exit(0);
  if (ind == 0) return pair<long long, long long>(V[0], V[1] - 1);
  if (ind == (int)V.size() - 2)
    return pair<long long, long long>(V[V.size() - 2] + 1, V.back());
  return pair<long long, long long>(V[ind] + 1, V[ind + 1] - 1);
}
long long what_next[6][K + 1];
long long kolko_vel[6];
long long get_what(int step, long long val) {
  assert(step < 5);
  if (val < K) return what_next[step][val] - 1;
  if (val >= LIM) return LIM;
  return val + kolko_vel[step] - 1;
}
void calc() {
  kolko_vel[1] = K;
  for (int i = (2); i < (6); i++) kolko_vel[i] = (K + 1) * kolko_vel[i - 1] + K;
  for (int i = (1); i < (K + 1); i++) what_next[1][i] = 2 * i;
  for (int step = (2); step < (6); step++) {
    for (int i = (1); i < (K + 1); i++) {
      int kolko = min(i, K);
      long long nxt = get_what(step - 1, i) + 1;
      for (int j = (0); j < (kolko); j++) nxt = get_what(step - 1, nxt + 1) + 1;
      what_next[step][i] = nxt;
    }
  }
}
long long find_prev(int steps, long long val) {
  long long lo = 1, hi = val;
  for (; lo < hi;) {
    long long mid = (lo + hi) / 2;
    if (get_what(steps, mid) >= val)
      hi = mid;
    else
      lo = mid + 1;
  }
  return lo;
}
void go(long long lo, long long hi, int steps) {
  if (steps == 1) {
    assert(lo + min((long long)K, lo) - 1 >= hi);
    vector<long long> T = {lo};
    for (long long i = lo; i <= hi; i++) T.push_back(i);
    T.push_back(hi);
    query(T);
    assert(0);
  }
  vector<long long> T;
  for (long long tmp = hi; (long long)T.size() < min((long long)K, lo);) {
    long long nov = max(1ll, find_prev(steps - 1, tmp) - 1);
    T.push_back(nov);
    tmp = nov - 1;
  }
  reverse(T.begin(), T.end());
  T.insert(T.begin(), lo);
  T.push_back(hi);
  pair<long long, long long> dalje = query(T);
  go(dalje.first, dalje.second, steps - 1);
}
int main() {
  calc();
  go(1, LIM, 5);
  return 0;
}

```


### Prompt

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

The supercomputer system L in the PCK Research Institute performs a variety of calculations upon request from external institutes, companies, universities and other entities. To use the L system, you have to reserve operation time by specifying the start and end time. No two reservation periods are allowed to overlap each other.

Write a program to report if a new reservation overlaps with any of the existing reservations. Note that the coincidence of start and end times is not considered to constitute an overlap. All the temporal data is given as the elapsed time from the moment at which the L system starts operation.

Input

The input is given in the following format.

a b
N
s_1 f_1
s_2 f_2
:
s_N f_N

The first line provides new reservation information, i.e., the start time a and end time b (0 ≤ a < b ≤ 1000) in integers. The second line specifies the number of existing reservations N (0 ≤ N ≤ 100). Subsequent N lines provide temporal information for the i-th reservation: start time s_i and end time f_i (0 ≤ s_i < f_i ≤ 1000) in integers. No two existing reservations overlap.

Output

Output "1" if the new reservation temporally overlaps with any of the existing ones, or "0" otherwise.

Examples

Input

5 7
3
1 4
4 5
7 10

Output

0

Input

3 7
3
7 10
1 4
4 5

Output

1

### Response

```cpp
#include<stdio.h>
int main(void)
{
	int a,b,n,s[100],f[100],i,j,flg;
	scanf("%d %d",&a,&b);
	scanf("%d",&n);
	flg=0;
	for(i=0;i<n;i++)	scanf("%d %d",&s[i],&f[i]);
	for(i=0;i<n;i++){
		if(a>s[i]&&a<f[i])	flg=1;
		if(b>s[i]&&b<f[i])	flg=1;
		if(a<s[i]&&b>f[i])	flg=1;
		if(a==s[i]&&b==f[i])	flg=1;
	}
	if(flg==0)	printf("0\n");
	else	printf("1\n");
	return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

To get on the Shinkansen, you need two tickets, a "ticket" and a "limited express ticket". These are separate tickets because some of the routes may not use the Shinkansen, but for routes that use only the Shinkansen, one ticket can be used as both a ticket and a limited express ticket. It may also be issued.

Automatic ticket gates must read these tickets and open the gate only when the correct ticket is inserted. Create a program that determines whether one "ticket" and one "limited express ticket" or both, or one "boarding / limited express ticket" has been inserted, and determines whether the door of the automatic ticket gate is open or closed. please do it.

input

The input is given in the following format.

b1 b2 b3

The input consists of one line and contains three integers separated by one space. b1 indicates the state in which the "ticket" is inserted, b2 indicates the state in which the "limited express ticket" is inserted, and b3 indicates the state in which the "boarding / limited express ticket" is inserted. The turned-in state is represented by 0 or 1, where 0 indicates a non-charged state, and 1 indicates a loaded state. However, the combination of expected input states is limited to the following cases.

Input | Input state | Door operation for input
--- | --- | ---
1 0 0 | Insert only "ticket" | Close
0 1 0 | Only "Limited Express Ticket" is introduced | Close
1 1 0 | Introducing "tickets" and "express tickets" | Open
0 0 1 | Introducing "Boarding / Limited Express Tickets" | Open
0 0 0 | No input | Close

output

Outputs Open or Close, which indicates the opening and closing of the automatic ticket gate, on one line.

Example

Input

0 0 1

Output

Open

### Response

```cpp
#include <iostream>
using namespace std;
int main(void){
 int a,b,c;
 cin >> a >> b >> c;
  if(a == 1 && b == 1 && c == 0){
   cout << "Open" << endl;
  }
  else if(a == 0 && b == 0 && c == 1){
   cout << "Open" << endl;
  }
  else {
   cout << "Close" << endl;
  }
}

```


### Prompt

Create a solution in CPP for the following problem:

You are given two strings s and t consisting of lowercase Latin letters. The length of t is 2 (i.e. this string consists only of two characters).

In one move, you can choose any character of s and replace it with any lowercase Latin letter. More formally, you choose some i and replace s_i (the character at the position i) with some character from 'a' to 'z'.

You want to do no more than k replacements in such a way that maximizes the number of occurrences of t in s as a subsequence.

Recall that a subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements.

Input

The first line of the input contains two integers n and k (2 ≤ n ≤ 200; 0 ≤ k ≤ n) — the length of s and the maximum number of moves you can make. The second line of the input contains the string s consisting of n lowercase Latin letters. The third line of the input contains the string t consisting of two lowercase Latin letters.

Output

Print one integer — the maximum possible number of occurrences of t in s as a subsequence if you replace no more than k characters in s optimally.

Examples

Input

4 2
bbaa
ab

Output

3

Input

7 3
asddsaf
sd

Output

10

Input

15 6
qwertyhgfdsazxc
qa

Output

16

Input

7 2
abacaba
aa

Output

15

Note

In the first example, you can obtain the string "abab" replacing s_1 with 'a' and s_4 with 'b'. Then the answer is 3.

In the second example, you can obtain the string "ssddsdd" and get the answer 10.

In the fourth example, you can obtain the string "aaacaaa" and get the answer 15.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
  int n, k;
  string s, t;
  cin >> n >> k >> s >> t;
  vector<vector<vector<int>>> dp(
      n + 1, vector<vector<int>>(n + 1, vector<int>(n + 1, -INF)));
  dp[0][0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int ck = 0; ck <= k; ++ck) {
      for (int cnt0 = 0; cnt0 <= n; ++cnt0) {
        if (dp[i][ck][cnt0] == -INF) continue;
        int e0 = s[i] == t[0];
        int e1 = s[i] == t[1];
        int e01 = t[0] == t[1];
        dp[i + 1][ck][cnt0 + e0] =
            max(dp[i + 1][ck][cnt0 + e0], dp[i][ck][cnt0] + (e1 ? cnt0 : 0));
        if (ck < k) {
          dp[i + 1][ck + 1][cnt0 + 1] = max(dp[i + 1][ck + 1][cnt0 + 1],
                                            dp[i][ck][cnt0] + (e01 ? cnt0 : 0));
          dp[i + 1][ck + 1][cnt0 + e01] =
              max(dp[i + 1][ck + 1][cnt0 + e01], dp[i][ck][cnt0] + cnt0);
        }
      }
    }
  }
  int ans = 0;
  for (int ck = 0; ck <= k; ++ck) {
    for (int cnt0 = 0; cnt0 <= n; ++cnt0) {
      ans = max(ans, dp[n][ck][cnt0]);
    }
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

There are a number of ways to shuffle a deck of cards. Hanafuda shuffling for Japanese card game 'Hanafuda' is one such example. The following is how to perform Hanafuda shuffling.

There is a deck of n cards. Starting from the p-th card from the top of the deck, c cards are pulled out and put on the top of the deck, as shown in Figure 1. This operation, called a cutting operation, is repeated.

Write a program that simulates Hanafuda shuffling and answers which card will be finally placed on the top of the deck.

<image>
---
Figure 1: Cutting operation

Input

The input consists of multiple data sets. Each data set starts with a line containing two positive integers n (1 <= n <= 50) and r (1 <= r <= 50); n and r are the number of cards in the deck and the number of cutting operations, respectively.

There are r more lines in the data set, each of which represents a cutting operation. These cutting operations are performed in the listed order. Each line contains two positive integers p and c (p + c <= n + 1). Starting from the p-th card from the top of the deck, c cards should be pulled out and put on the top.

The end of the input is indicated by a line which contains two zeros.

Each input line contains exactly two integers separated by a space character. There are no other characters in the line.

Output

For each data set in the input, your program should write the number of the top card after the shuffle. Assume that at the beginning the cards are numbered from 1 to n, from the bottom to the top. Each number should be written in a separate line without any superfluous characters such as leading or following spaces.

Example

Input

5 2
3 1
3 1
10 3
1 10
10 1
8 3
0 0

Output

4
4

### Response

```cpp
#include<stdio.h>

int main(void)
{
  int i,j;
  int n,r;
  int p,c;
  int h[50],tmp[50];

  while(1){
      scanf("%d %d",&n,&r);
      if(!n && !r){break;}

      for(i=0;i<n;i++)h[i] = n-i;

      for(i=0;i<r;i++){
	scanf("%d %d",&p,&c);
	p--;
	for(j=0;j<c;j++)tmp[j] = h[j+p];

	for(j=p-1;j>=0;j--)h[j+c] = h[j];

	for(j=0;j<c;j++)h[j] = tmp[j];
      }

      printf("%d\n",h[0]);
    }
  return 0;
}
```


### Prompt

Develop a solution in CPP to the problem described below:

The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row.

Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all the houses with larger numbers. In other words, a house is luxurious if the number of floors in it is strictly greater than in all the houses, which are located to the right from it. In this task it is assumed that the heights of floors in the houses are the same.

The new architect is interested in n questions, i-th of them is about the following: "how many floors should be added to the i-th house to make it luxurious?" (for all i from 1 to n, inclusive). You need to help him cope with this task.

Note that all these questions are independent from each other — the answer to the question for house i does not affect other answers (i.e., the floors to the houses are not actually added).

Input

The first line of the input contains a single number n (1 ≤ n ≤ 105) — the number of houses in the capital of Berland.

The second line contains n space-separated positive integers hi (1 ≤ hi ≤ 109), where hi equals the number of floors in the i-th house.

Output

Print n integers a1, a2, ..., an, where number ai is the number of floors that need to be added to the house number i to make it luxurious. If the house is already luxurious and nothing needs to be added to it, then ai should be equal to zero.

All houses are numbered from left to right, starting from one.

Examples

Input

5
1 2 3 1 2

Output

3 2 0 2 0

Input

4
3 2 1 4

Output

2 3 4 0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, i, a[100005], r[100005], m;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  r[n] = 0;
  for (i = n - 1; i >= 1; i--) {
    m = max(m, a[i + 1]);
    r[i] = m;
  }
  for (i = 1; i <= n; i++) {
    if (r[i] >= a[i]) {
      cout << r[i] - a[i] + 1 << " ";
    } else {
      cout << "0 ";
    }
  }
  return 0;
}

```


### Prompt

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

Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number!

The only thing Mrs. Smith remembered was that any permutation of n can be a secret phone number. Only those permutations that minimize secret value might be the phone of her husband.

The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.

The secret value of a phone number is defined as the sum of the length of the longest increasing subsequence (LIS) and length of the longest decreasing subsequence (LDS).

A subsequence a_{i_1}, a_{i_2}, …, a_{i_k} where 1≤ i_1 < i_2 < … < i_k≤ n is called increasing if a_{i_1} < a_{i_2} < a_{i_3} < … < a_{i_k}. If a_{i_1} > a_{i_2} > a_{i_3} > … > a_{i_k}, a subsequence is called decreasing. An increasing/decreasing subsequence is called longest if it has maximum length among all increasing/decreasing subsequences.

For example, if there is a permutation [6, 4, 1, 7, 2, 3, 5], LIS of this permutation will be [1, 2, 3, 5], so the length of LIS is equal to 4. LDS can be [6, 4, 1], [6, 4, 2], or [6, 4, 3], so the length of LDS is 3.

Note, the lengths of LIS and LDS can be different.

So please help Mrs. Smith to find a permutation that gives a minimum sum of lengths of LIS and LDS.

Input

The only line contains one integer n (1 ≤ n ≤ 10^5) — the length of permutation that you need to build.

Output

Print a permutation that gives a minimum sum of lengths of LIS and LDS.

If there are multiple answers, print any.

Examples

Input

4

Output

3 4 1 2

Input

2

Output

2 1

Note

In the first sample, you can build a permutation [3, 4, 1, 2]. LIS is [3, 4] (or [1, 2]), so the length of LIS is equal to 2. LDS can be ony of [3, 1], [4, 2], [3, 2], or [4, 1]. The length of LDS is also equal to 2. The sum is equal to 4. Note that [3, 4, 1, 2] is not the only permutation that is valid.

In the second sample, you can build a permutation [2, 1]. LIS is [1] (or [2]), so the length of LIS is equal to 1. LDS is [2, 1], so the length of LDS is equal to 2. The sum is equal to 3. Note that permutation [1, 2] is also valid.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int count = n;
  int L = sqrt(n);
  int block = n / L;
  vector<int> ar(n, 0);
  int i;
  for (i = 0; i < block; i++) {
    for (int j = L - 1; j >= 0; j--) {
      ar[L * i + j] = count;
      count--;
    }
  }
  if (count > 0) {
    for (i = n - 1; i > 0 && count > 0; i--) {
      ar[i] = count;
      count--;
    }
  }
  for (i = 0; i < n; i++) cout << ar[i] << " ";
  cout << "\n";
  return 0;
}

```


### Prompt

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

For a given prime integer p and integers α, A calculate the number of pairs of integers (n, k), such that 0 ≤ k ≤ n ≤ A and <image> is divisible by pα.

As the answer can be rather large, print the remainder of the answer moduly 109 + 7.

Let us remind you that <image> is the number of ways k objects can be chosen from the set of n objects.

Input

The first line contains two integers, p and α (1 ≤ p, α ≤ 109, p is prime).

The second line contains the decimal record of integer A (0 ≤ A < 101000) without leading zeroes.

Output

In the single line print the answer to the problem.

Examples

Input

2 2
7

Output

3

Input

3 1
9

Output

17

Input

3 3
9

Output

0

Input

2 4
5000

Output

8576851

Note

In the first sample three binominal coefficients divisible by 4 are <image>, <image> and <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char buf[1 << 23 | 1], *p1 = buf, *p2 = buf;
int (*GC)() = getchar;
inline int gc() {
  return (p1 == p2 &&
                  (p2 = (p1 = buf) + fread(buf, 1, 1 << 23, stdin), p1 == p2)
              ? EOF
              : *p1++);
}
template <typename T>
void read(T &x) {
  x = 0;
  bool f = 0;
  char ch = GC();
  while (!isdigit(ch)) {
    if (ch == '-') f = 1;
    ch = GC();
  }
  while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = GC();
  if (f) x = -x;
}
void fileopen() {}
int const P = 1e9 + 7;
void update(int &x, long long y) { x = (x + y) % P; }
int f[3330][3330][2][2];
long long A[3330];
int main() {
  fileopen();
  int p, k;
  read(p), read(k);
  if (k > 3325) {
    puts("0");
    return 0;
  }
  char ch = gc();
  while (!isdigit(ch)) ch = gc();
  while (isdigit(ch)) {
    for (int i = 0; i <= 3325; i++) A[i] *= 10;
    A[0] += ch - '0';
    for (int i = 0; i <= 3325; i++)
      if (A[i] >= p) A[i + 1] += A[i] / p, A[i] %= p;
    ch = gc();
  }
  f[3325][0][0][0] = 1;
  for (int i = 3325; i >= 1; i--)
    for (int j = 0; j <= 3325 - i; j++) {
      update(f[i - 1][j][0][0], 1ll * (A[i - 1] + 1) * f[i][j][0][0]);
      update(f[i - 1][j][1][0],
             1ll * (A[i - 1] + 1) * A[i - 1] / 2 % P * f[i][j][0][0]);
      update(f[i - 1][j + 1][0][1], 1ll * A[i - 1] * f[i][j][0][0]);
      update(f[i - 1][j + 1][1][1],
             1ll * (A[i - 1] - 1) * A[i - 1] / 2 % P * f[i][j][0][0]);
      update(f[i - 1][j][0][0], 1ll * (p - A[i - 1] - 1) * f[i][j][0][1]);
      update(f[i - 1][j][1][0],
             1ll * A[i - 1] * (2 * p - A[i - 1] - 1) / 2 % P * f[i][j][0][1]);
      update(f[i - 1][j + 1][0][1], 1ll * (p - A[i - 1]) * f[i][j][0][1]);
      update(f[i - 1][j + 1][1][1],
             1ll * A[i - 1] * (2 * p + 1 - A[i - 1]) / 2 % P * f[i][j][0][1]);
      update(f[i - 1][j][1][0], 1ll * p * (p + 1) / 2 % P * f[i][j][1][0]);
      update(f[i - 1][j + 1][1][1], 1ll * p * (p - 1) / 2 % P * f[i][j][1][0]);
      update(f[i - 1][j][1][0], 1ll * p * (p - 1) / 2 % P * f[i][j][1][1]);
      update(f[i - 1][j + 1][1][1], 1ll * p * (p + 1) / 2 % P * f[i][j][1][1]);
    }
  long long res = 0;
  for (int i = k; i <= 3325; i++)
    res = (res + f[0][i][0][0] + f[0][i][1][0]) % P;
  printf("%lld", res);
  return 0;
}

```