### Prompt

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

Ataru Oafoot of Aizu Gakuen University High School decided to play with a slot machine.

When you insert a medal on this machine, three reels will start spinning and each reel will stop automatically. In a normal game (normal game), 3 medals are inserted, and when the symbols are aligned, the following medals are obtained according to the symbols.

<image>

A special service will be started depending on how the patterns are aligned. A big bonus starts when you have 3 of 7 symbols, and you can play 5 bonus games. Also, when you have 3 BAR symbols, the regular bonus will start and you can play 3 bonus games.

If you have 3 star symbols, the free game will start and you will not be able to get medals, but you can start the next game without inserting medals.

During the bonus game, if you insert 2 medals per game, you will automatically get 3 grape patterns and 15 medals.

Oafoot started playing on the machine with 100 medals. After playing for a while, it ended in a normal game. How many medals did you have left?

Create a program that inputs play information and outputs the number of medals left at hand. The play information is given as the number of big bonuses b, the number of regular bonuses r, the number of grapes aligned during a normal game g, the number of cherries aligned c, the number of stars aligned s, and the total number of games t.

Note that t includes the number of bonus games. Also, medals will not disappear in the middle of the game.

Input

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

b r g c s t

b, r, g, c, and s are integers greater than or equal to 0 and less than 200, and t is an integer less than or equal to 1000.

The number of datasets does not exceed 120.

Output

For each input dataset, the number of medals remaining at hand is output on one line.

Example

Input

3 2 30 3 26 226
9 0 18 3 20 118
5 5 12 2 15 203
7 4 19 2 22 197
7 4 24 4 17 209
0 0 0 0 0 0

Output

127
793
414
629
617

### Response

```cpp
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int b,r,g,c,s,t;
	while(1){
		cin>>b>>r>>g>>c>>s>>t;
		if(b==0 && r==0 && g==0 && c==0 && s==0 && t==0) break;
		o(100+15*(b+r)+7*g+2*c+13*(5*b+3*r)-3*(t-5*b-3*r-s));
	}
}
```


### Prompt

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

Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.

Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.

Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), and if k = 2, they do not rhyme (ommit ≠ ermit).

Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines):

  * Clerihew (aabb);
  * Alternating (abab);
  * Enclosed (abba).

If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented by aaaa).

If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem is aaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme.

Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task.

Input

The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104.

If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1, 2, 3, 4; the second one contains lines number 5, 6, 7, 8; and so on.

Output

Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.

Examples

Input

1 1
day
may
sun
fun

Output

aabb

Input

1 1
day
may
gray
way

Output

aaaa

Input

2 1
a
a
a
a
a
a
e
e

Output

aabb

Input

2 1
day
may
sun
fun
test
hill
fest
thrill

Output

NO

Note

In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, vector<T> t) {
  s << "{";
  for (int i = 0; i < t.size(); i++)
    s << t[i] << (i == t.size() - 1 ? "" : ",");
  return s << "}" << endl;
}
map<string, int> ile;
int vow[300];
int cnt(string g) {
  int w = 0;
  for (int i = 0; i < g.size(); i++) w += vow[g[i]];
  return w;
}
int main() {
  ios_base::sync_with_stdio(0);
  vow['e'] = 1;
  vow['i'] = 1;
  vow['o'] = 1;
  vow['u'] = 1;
  vow['a'] = 1;
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    string s[4];
    for (int j = 0; j < 4; j++) cin >> s[j];
    int sam[4];
    for (int j = 0; j < 4; j++) sam[j] = cnt(s[j]);
    bool ok = 1;
    for (int j = 0; j < 4; j++) {
      if (sam[j] < k) ok = 0;
    }
    if (!ok) break;
    for (int j = 0; j < 4; j++) {
      int z = s[j].size();
      int mam = 0;
      while (mam < k) {
        z--;
        mam += vow[s[j][z]];
      }
      s[j] = s[j].substr(z);
    }
    if (s[0] == s[1] && s[2] == s[3]) ile["aabb"]++;
    if (s[0] == s[3] && s[2] == s[1]) ile["abba"]++;
    if (s[0] == s[2] && s[1] == s[3]) ile["abab"]++;
    if (s[0] == s[1] && s[2] == s[3] && s[2] == s[1]) ile["aaaa"]++;
  }
  if (ile["aaaa"] == n) {
    cout << "aaaa";
    return 0;
  }
  for (typeof(ile.begin()) i = ile.begin(); i != ile.end(); i++) {
    if (i->second == n) {
      cout << i->first;
      return 0;
    }
  }
  cout << "NO";
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

There is a game called Sim Forest 2013. In this game, the player can become a forest god and raise forest animals.

Animals hatch from eggs and breed. When certain conditions are met, eggs are mutated with a certain probability to give birth to new races of animals.

There is an animal encyclopedia in this game, and when you get a new kind of animal, it will be recorded in the animal dictionary.

Mori is an enthusiastic player of Sim Forest 2013. His animal dictionary is complete when the remaining one race is filled.

Mori decided to obtain this remaining one race by mutation from the egg.

The game progress is as follows.

* N eggs will appear at the beginning of the stage.
* N eggs hatch s minutes after the start of the stage.
* Each egg has a 1 / p chance of targeting on a specific day of the week and within a specific time zone during the entire period * from appearance to hatching * (including the time of appearance and the moment of hatching). Mutates in animals.
* The stage ends t minutes after the start of the stage, and the same stage starts immediately after that (starts with n eggs. The elapsed time is not reset).
* The stage is repeated m times in a row.

This game meets the following specifications.

* Animals born from eggs do not lay eggs.
* Eggs hatch only once per stage, s minutes after the start of the stage.
* Mr. Sori can set the start day and start time of the first stage as desired. (The start time of the second and subsequent stages will be immediately after the end of the previous stage)
* One of {all days, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday} is given as a mutable day.
* One of {all time zones, morning, night} is given as a mutable time zone.

Inputs are s, n, t, mutable day / time zone, p, m. Find the probability when you set the start day and start time of the first stage so that the probability of mutation occurring by the end of all stages is maximized.

Input

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

s n t weekday time p m

Each dataset shows the time it takes for an egg to hatch from the start of the stage s, the number of eggs that appear at the start of the stage n, the time it takes to finish one stage t, the mutable day weekday, the mutable Time zone time, reciprocal of mutation probability p (mutation probability is 1 / p), total number of stages m.

The input satisfies the following constraints.

* 0 <s <= 500
* 0 <n <= 100
* s <t <= 1000
* weekday ∈ {All, Sun, Mon, Tue, Wed, Thu, Fri, Sat}
* All means all days of the week
* time ∈ {All, Day, Night}
* All means [0: 00 ~ 24: 00), Day means [6: 00 ~ 18: 00), and Night means [18: 00 ~ 6: 00).
* 1 <= p <= 99999
* 1 <= m <= 100

The end of the input is given on the following line.

0 0 0 None None 0 0

Output

For each dataset, output the probability when the start day and start time of the first stage is set so that the probability of mutation occurring by the end of all stages is maximized. The error in the answer must not exceed 0.00000001 (10-8). Any number of digits after the decimal point may be output as long as the precision conditions are met.

Sample Input

1 1 3 All All 1 1
2 37 5 All Night 150 1
16 2 20 All Day 5 10
1 14 15 Mon All 20000 100
0 0 0 None None 0 0

Output for Sample Input

1.0000000000
0.2192439716
0.9884707850
0.0649933899

Example

Input

1 1 3 All All 1 1
2 37 5 All Night 150 1
16 2 20 All Day 5 10
1 14 15 Mon All 20000 100
0 0 0 None None 0 0

Output

1.0000000000
0.2192439716
0.9884707850
0.0649933899

### Response

```cpp
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

static const double EPS = 1e-8;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

const static char weekdays[][4] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
const static char times[][6] = {"Day","Night"};

const char* compute_weekday(int minutes){
  int tmp = (minutes / (60 * 24)) % 7;
  return weekdays[tmp];
}

const char* compute_time_band(int minutes){
  int idx = 0;
  int tmp = minutes % (60 * 24);
  if(tmp >= 6 * 60
     && tmp < 18 * 60){
    idx = 0;
  }
  else{
    idx = 1;
  }
  return times[idx];
}

int main(){
  int wait_hatch;
  int num_of_egg;
  int stage_life;
  char mutation_weekday[4];
  char mutation_time_band[6];
  int inv_mutation_prob;
  int total_stages;
  double probs[101];
  while(~scanf("%d %d %d %s %s %d %d",
               &wait_hatch,
               &num_of_egg,
               &stage_life,
               mutation_weekday,
               mutation_time_band,
               &inv_mutation_prob,
               &total_stages)){

    if(total_stages == 0) break;

    probs[0] = 1.0;
    for(int i=0;i<num_of_egg;i++){
      probs[i+1] = probs[i] * (1.0 - 1.0/inv_mutation_prob);
    }

    double res = 0.0;
    for(int start=0; start < 60 * 24 * 7;start++){
      int init_start = start;
      double prob = 1.0;

      for(int round = 0; round < total_stages; round++){
        int time = init_start + wait_hatch;

        if(strcmp(mutation_weekday,"All") != 0
           && strcmp(compute_weekday(time),mutation_weekday) != 0){
          init_start += stage_life;
          continue;
        }

        if(strcmp(mutation_time_band,"All") != 0
           && strcmp(compute_time_band(time),mutation_time_band) != 0){
          init_start += stage_life;
          continue;
        }

        if(strcmp(mutation_weekday,"All") != 0
           && strcmp(compute_weekday(init_start),compute_weekday(time)) != 0){
          init_start += stage_life;
          continue;
        }
        if(strcmp(mutation_time_band,"All") != 0
           && strcmp(compute_time_band(init_start),compute_time_band(time)) != 0){
          init_start += stage_life;
          continue;
        }

        prob *= probs[num_of_egg];
        init_start += stage_life;
      }
      res = max(res,1.0-prob);
    }
    printf("%.10f\n",res);
  }
}
```


### Prompt

Please create a solution in Cpp to the following problem:

IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids — one triangular, one quadrangular and one pentagonal.

The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.

<image>

Input

The only line of the input contains three integers l3, l4, l5 (1 ≤ l3, l4, l5 ≤ 1000) — the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.

Output

Output one number — the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.

Examples

Input

2 5 3

Output

38.546168065709

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  double x, y, z;
  scanf("%lf%lf%lf", &x, &y, &z);
  double s = atan2(0, -1);
  double ans1 = 0;
  double ans2 = 0;
  double ans3 = 0;
  double k1 = x / 2 / sin(s / 3);
  double h1 = sqrt(x * x - k1 * k1);
  ans1 = k1 * x * sin(s / 6) * h1 / 2;
  double k2 = y / 2 / sin(s / 4);
  double h2 = sqrt(y * y - k2 * k2);
  ans2 = y * k2 * sin(s / 4) * 2 * h2 / 3;
  double k3 = z / 2 / sin(s / 5);
  double h3 = sqrt(z * z - k3 * k3);
  ans3 = 5 * z * k3 * sin(s / 5 * 3 / 2) * h3 / 6;
  printf("%.10lf\n", ans1 + ans2 + ans3);
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

You have a grid with n rows and n columns. Each cell is either empty (denoted by '.') or blocked (denoted by 'X').

Two empty cells are directly connected if they share a side. Two cells (r1, c1) (located in the row r1 and column c1) and (r2, c2) are connected if there exists a sequence of empty cells that starts with (r1, c1), finishes with (r2, c2), and any two consecutive cells in this sequence are directly connected. A connected component is a set of empty cells such that any two cells in the component are connected, and there is no cell in this set that is connected to some cell not in this set.

Your friend Limak is a big grizzly bear. He is able to destroy any obstacles in some range. More precisely, you can choose a square of size k × k in the grid and Limak will transform all blocked cells there to empty ones. However, you can ask Limak to help only once.

The chosen square must be completely inside the grid. It's possible that Limak won't change anything because all cells are empty anyway.

You like big connected components. After Limak helps you, what is the maximum possible size of the biggest connected component in the grid?

Input

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 500) — the size of the grid and Limak's range, respectively.

Each of the next n lines contains a string with n characters, denoting the i-th row of the grid. Each character is '.' or 'X', denoting an empty cell or a blocked one, respectively.

Output

Print the maximum possible size (the number of cells) of the biggest connected component, after using Limak's help.

Examples

Input

5 2
..XXX
XX.XX
X.XXX
X...X
XXXX.

Output

10

Input

5 3
.....
.XXX.
.XXX.
.XXX.
.....

Output

25

Note

In the first sample, you can choose a square of size 2 × 2. It's optimal to choose a square in the red frame on the left drawing below. Then, you will get a connected component with 10 cells, marked blue in the right drawing.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const vector<int> dx = {1, -1, 0, 0};
const vector<int> dy = {0, 0, 1, -1};
int n, k;
vector<string> a;
vector<vector<int>> num;
vector<int> sz;
inline bool ok(int x, int y) { return 0 <= min(x, y) && max(x, y) < n; }
void dfs(int x, int y, vector<pair<int, int>> &comp) {
  num[x][y] = 0;
  comp.emplace_back(x, y);
  for (int d = 0; d < 4; d++) {
    int xx = x + dx[d];
    int yy = y + dy[d];
    if (ok(xx, yy) && num[xx][yy] == -1 && a[xx][yy] == '.') dfs(xx, yy, comp);
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> k;
  a.resize(n);
  for (auto &x : a) cin >> x;
  num.resize(n, vector<int>(n, -1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (num[i][j] != -1 || a[i][j] == 'X') continue;
      vector<pair<int, int>> comp;
      dfs(i, j, comp);
      for (auto [x, y] : comp) num[x][y] = sz.size();
      sz.push_back(comp.size());
    }
  }
  vector<vector<int>> pref(n + 1, vector<int>(n + 1, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      pref[i + 1][j + 1] =
          pref[i + 1][j] + pref[i][j + 1] - pref[i][j] + (a[i][j] == '.');
  }
  auto get = [&](int x1, int y1, int x2, int y2) {
    return pref[x2 + 1][y2 + 1] - pref[x2 + 1][y1] - pref[x1][y2 + 1] +
           pref[x1][y1];
  };
  int ans = (sz.size() ? *max_element(sz.begin(), sz.end()) : 0);
  for (int i = 0; i + k <= n; i++) {
    vector<int> cnt(sz.size(), 0);
    int now = k * k;
    for (int j = 0; j < k && i; j++) {
      if (a[i - 1][j] == 'X') continue;
      if (!cnt[num[i - 1][j]]) now += sz[num[i - 1][j]];
      cnt[num[i - 1][j]]++;
    }
    for (int j = 0; j < k && i + k != n; j++) {
      if (a[i + k][j] == 'X') continue;
      if (!cnt[num[i + k][j]]) now += sz[num[i + k][j]];
      cnt[num[i + k][j]]++;
    }
    for (int j = i; j < i + k && k != n; j++) {
      if (a[j][k] == 'X') continue;
      if (!cnt[num[j][k]]) now += sz[num[j][k]];
      cnt[num[j][k]]++;
    }
    for (int x = i; x < i + k; x++) {
      for (int y = 0; y < k; y++) {
        if (a[x][y] == 'X') continue;
        if (!cnt[num[x][y]]) now += sz[num[x][y]];
        cnt[num[x][y]]++;
      }
    }
    ans = max(ans, now - get(i, 0, i + k - 1, k - 1));
    for (int j = 1; j + k <= n; j++) {
      for (int x = i; x < i + k && j > 1; x++) {
        if (a[x][j - 2] == 'X') continue;
        cnt[num[x][j - 2]]--;
        if (!cnt[num[x][j - 2]]) now -= sz[num[x][j - 2]];
      }
      for (int x = i; x < i + k && j + k < n; x++) {
        if (a[x][j + k] == 'X') continue;
        if (!cnt[num[x][j + k]]) now += sz[num[x][j + k]];
        cnt[num[x][j + k]]++;
      }
      if (i) {
        if (a[i - 1][j - 1] == '.') {
          cnt[num[i - 1][j - 1]]--;
          if (!cnt[num[i - 1][j - 1]]) now -= sz[num[i - 1][j - 1]];
        }
        if (a[i - 1][j + k - 1] == '.') {
          if (!cnt[num[i - 1][j + k - 1]]) now += sz[num[i - 1][j + k - 1]];
          cnt[num[i - 1][j + k - 1]]++;
        }
      }
      if (i + k < n) {
        if (a[i + k][j - 1] == '.') {
          cnt[num[i + k][j - 1]]--;
          if (!cnt[num[i + k][j - 1]]) now -= sz[num[i + k][j - 1]];
        }
        if (a[i + k][j + k - 1] == '.') {
          if (!cnt[num[i + k][j + k - 1]]) now += sz[num[i + k][j + k - 1]];
          cnt[num[i + k][j + k - 1]]++;
        }
      }
      ans = max(ans, now - get(i, j, i + k - 1, j + k - 1));
    }
  }
  cout << ans << '\n';
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

In this problem you will meet the simplified model of game King of Thieves.

In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.

<image>

An interesting feature of the game is that you can design your own levels that will be available to other players. Let's consider the following simple design of a level.

A dungeon consists of n segments located at a same vertical level, each segment is either a platform that character can stand on, or a pit with a trap that makes player lose if he falls into it. All segments have the same length, platforms on the scheme of the level are represented as '*' and pits are represented as '.'.

One of things that affects speedrun characteristics of the level is a possibility to perform a series of consecutive jumps of the same length. More formally, when the character is on the platform number i1, he can make a sequence of jumps through the platforms i1 < i2 < ... < ik, if i2 - i1 = i3 - i2 = ... = ik - ik - 1. Of course, all segments i1, i2, ... ik should be exactly the platforms, not pits.

Let's call a level to be good if you can perform a sequence of four jumps of the same length or in the other words there must be a sequence i1, i2, ..., i5, consisting of five platforms so that the intervals between consecutive platforms are of the same length. Given the scheme of the level, check if it is good.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of segments on the level.

Next line contains the scheme of the level represented as a string of n characters '*' and '.'.

Output

If the level is good, print the word "yes" (without the quotes), otherwise print the word "no" (without the quotes).

Examples

Input

16
.**.*..*.***.**.

Output

yes

Input

11
.*.*...*.*.

Output

no

Note

In the first sample test you may perform a sequence of jumps through platforms 2, 5, 8, 11, 14.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  cout.sync_with_stdio(false);
  int x;
  cin >> x;
  string path;
  cin >> path;
  for (int i = 0; i < path.length(); i++) {
    if (path[i] == '.') continue;
    for (int j = 1; j <= path.length() / 4; j++) {
      int count = 0;
      for (int k = i + j; k < path.length(); k += j) {
        if (path[k] == '*')
          count++;
        else
          break;
      }
      if (count >= 4) {
        cout << "yes";
        return 0;
      }
    }
  }
  cout << "no";
}

```


### Prompt

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

Unary is a minimalistic Brainfuck dialect in which programs are written using only one token.

Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following algorithm. First, replace each command with a corresponding binary code, using the following conversion table:

  * ">"  →  1000,
  * "<"  →  1001,
  * "+"  →  1010,
  * "-"  →  1011,
  * "."  →  1100,
  * ","  →  1101,
  * "["  →  1110,
  * "]"  →  1111.

Next, concatenate the resulting binary codes into one binary number in the same order as in the program. Finally, write this number using unary numeral system — this is the Unary program equivalent to the original Brainfuck one.

You are given a Brainfuck program. Your task is to calculate the size of the equivalent Unary program, and print it modulo 1000003 (106 + 3).

Input

The input will consist of a single line p which gives a Brainfuck program. String p will contain between 1 and 100 characters, inclusive. Each character of p will be "+", "-", "[", "]", "<", ">", "." or ",".

Output

Output the size of the equivalent Unary program modulo 1000003 (106 + 3).

Examples

Input

,.

Output

220

Input

++++[>,.<-]

Output

61425

Note

To write a number n in unary numeral system, one simply has to write 1 n times. For example, 5 written in unary system will be 11111.

In the first example replacing Brainfuck commands with binary code will give us 1101 1100. After we concatenate the codes, we'll get 11011100 in binary system, or 220 in decimal. That's exactly the number of tokens in the equivalent Unary program.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e6 + 3;
long long power(int n) {
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    ans = ((ans % MOD) * 2) % MOD;
  }
  return (ans % MOD);
}
int main() {
  map<char, string> mp;
  mp['>'] = "1000";
  mp['<'] = "1001";
  mp['+'] = "1010";
  mp['-'] = "1011";
  mp['.'] = "1100";
  mp[','] = "1101";
  mp['['] = "1110";
  mp[']'] = "1111";
  string t;
  cin >> t;
  string an = "";
  for (int i = 0; i < t.size(); i++) {
    an += mp[t[i]];
  }
  long long a = 0;
  for (int i = 0; i < an.size(); i++) {
    if (an[i] == '1') {
      a = (a % MOD + (power(an.size() - 1 - i))) % MOD;
    }
  }
  cout << a << endl;
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n.

A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem.

Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros.

In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below.

For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$

Formally,

  * if p ≥ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q;
  * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q.

Mishanya gives you an array consisting of n integers a_i, your task is to help students to calculate ∑_{i = 1}^{n}∑_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the elements of the array.

Output

Print the answer modulo 998 244 353.

Examples

Input

3
12 3 45

Output

12330

Input

2
123 456

Output

1115598

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = (int)1e6 + 5, p = 998244353;
int A[MAX], len[MAX], dig[13];
int e10[] = {1,         10,        100,       1000,      10000,
             100000,    1000000,   10000000,  100000000, 1755647,
             17556470,  175564700, 757402647, 586315999, 871938225,
             733427426, 346563789, 470904831, 716070898, 172998509};
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    for (int i = 0; i < n; i++) scanf("%d", &A[i]);
    for (int i = 0; i < 13; i++) dig[i] = 0;
    int gg = 0;
    for (int i = 0; i < n; i++) {
      int x = A[i], count = 0;
      while (x > 0) {
        int add = (x % 10ll) * (e10[2 * count] + e10[2 * count + 1]) % p;
        gg = (gg + add) % p;
        x /= 10;
        count++;
      }
      len[i] = count;
      dig[count]++;
    }
    for (int i = 10; i >= 0; i--) dig[i] += dig[i + 1];
    for (int i = 0; i < n; i++) {
      int x = A[i], count = 1, ex = 1;
      while (x > 0) {
        int add = (x % 10ll) * (dig[count] - 1ll) * e10[ex] % p;
        gg = (gg + add) % p;
        add = (x % 10ll) * (dig[count - 1] - 1ll) * e10[ex - 1] % p;
        gg = (gg + add) % p;
        for (int j = 1; j < count; j++) {
          add = (x % 10ll) * (dig[j] - dig[j + 1]) * e10[count + j - 1] % p;
          if (j < count - 1) add = (add + add) % p;
          gg = (gg + add) % p;
        }
        x /= 10;
        count++;
        ex += 2;
      }
    }
    printf("%d\n", gg);
  }
  return 0;
}

```


### Prompt

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

Tomash keeps wandering off and getting lost while he is walking along the streets of Berland. It's no surprise! In his home town, for any pair of intersections there is exactly one way to walk from one intersection to the other one. The capital of Berland is very different!

Tomash has noticed that even simple cases of ambiguity confuse him. So, when he sees a group of four distinct intersections a, b, c and d, such that there are two paths from a to c — one through b and the other one through d, he calls the group a "damn rhombus". Note that pairs (a, b), (b, c), (a, d), (d, c) should be directly connected by the roads. Schematically, a damn rhombus is shown on the figure below:

<image>

Other roads between any of the intersections don't make the rhombus any more appealing to Tomash, so the four intersections remain a "damn rhombus" for him.

Given that the capital of Berland has n intersections and m roads and all roads are unidirectional and are known in advance, find the number of "damn rhombi" in the city.

When rhombi are compared, the order of intersections b and d doesn't matter.

Input

The first line of the input contains a pair of integers n, m (1 ≤ n ≤ 3000, 0 ≤ m ≤ 30000) — the number of intersections and roads, respectively. Next m lines list the roads, one per line. Each of the roads is given by a pair of integers ai, bi (1 ≤ ai, bi ≤ n;ai ≠ bi) — the number of the intersection it goes out from and the number of the intersection it leads to. Between a pair of intersections there is at most one road in each of the two directions.

It is not guaranteed that you can get from any intersection to any other one.

Output

Print the required number of "damn rhombi".

Examples

Input

5 4
1 2
2 3
1 4
4 3

Output

1

Input

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

Output

12

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4096;
const long long INF = 1e15 + 7;
int n, m;
vector<int> g[maxn];
int d[maxn];
int dfs(int x, int depth, int root) {
  if (depth == 2) return d[x]++;
  int ans = 0;
  for (int i = int(0); i <= int(g[x].size() - 1); ++i)
    if (g[x][i] != root) ans += dfs(g[x][i], depth + 1, root);
  return ans;
}
int calc(int x) {
  int ans = 0;
  for (int i = int(1); i <= int(n); ++i) d[i] = 0;
  return dfs(x, 0, x);
}
long long ans;
int a, b;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = int(1); i <= int(m); ++i) {
    scanf("%d %d", &a, &b);
    g[a].push_back(b);
  }
  for (int i = int(1); i <= int(n); ++i) ans += calc(i);
  printf("%I64d", ans);
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

You have to restore the wall. The wall consists of N pillars of bricks, the height of the i-th pillar is initially equal to h_{i}, the height is measured in number of bricks. After the restoration all the N pillars should have equal heights.

You are allowed the following operations:

  * put a brick on top of one pillar, the cost of this operation is A;
  * remove a brick from the top of one non-empty pillar, the cost of this operation is R;
  * move a brick from the top of one non-empty pillar to the top of another pillar, the cost of this operation is M.

You cannot create additional pillars or ignore some of pre-existing pillars even if their height becomes 0.

What is the minimal total cost of restoration, in other words, what is the minimal total cost to make all the pillars of equal height?

Input

The first line of input contains four integers N, A, R, M (1 ≤ N ≤ 10^{5}, 0 ≤ A, R, M ≤ 10^{4}) — the number of pillars and the costs of operations.

The second line contains N integers h_{i} (0 ≤ h_{i} ≤ 10^{9}) — initial heights of pillars.

Output

Print one integer — the minimal cost of restoration.

Examples

Input

3 1 100 100
1 3 8

Output

12

Input

3 100 1 100
1 3 8

Output

9

Input

3 100 100 1
1 3 8

Output

4

Input

5 1 2 4
5 5 3 6 5

Output

4

Input

5 1 2 2
5 5 3 6 5

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int findCost(int arr[], int n, int a, int r, int m, int k) {
  long long int extra = 0, cost = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] >= k) {
      extra += (arr[i] - k);
    } else {
      long long int diff = k - arr[i];
      long long int toUse = min(diff, extra);
      long long int op1 = diff * a + toUse * r;
      long long int op2 = toUse * m + max(0LL, diff - toUse) * a;
      if (op1 < op2) {
        cost += op1;
      } else {
        cost += op2;
      }
      extra -= toUse;
    }
  }
  cost += extra * r;
  return cost;
}
long long int restorerDistance(int arr[], int n, int a, int r, int m) {
  sort(arr, arr + n, greater<int>());
  long long int start = 0, end = INT_MAX, ans = 1e18;
  while (start <= end) {
    long long int midLeft = start + (end - start) / 3,
                  midRight = end - (end - start) / 3;
    long long int costLeft = findCost(arr, n, a, r, m, midLeft),
                  costRight = findCost(arr, n, a, r, m, midRight);
    ans = min(ans, min(costLeft, costRight));
    if (costLeft < costRight)
      end = midRight - 1;
    else
      start = midLeft + 1;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, a, r, m;
  cin >> n >> a >> r >> m;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  long long int ans = restorerDistance(arr, n, a, r, m);
  cout << ans;
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You are given three integers n, k, m and m conditions (l_1, r_1, x_1), (l_2, r_2, x_2), ..., (l_m, r_m, x_m).

Calculate the number of distinct arrays a, consisting of n integers such that:

  * 0 ≤ a_i < 2^k for each 1 ≤ i ≤ n;
  * bitwise AND of numbers a[l_i] \& a[l_i + 1] \& ... \& a[r_i] = x_i for each 1 ≤ i ≤ m.

Two arrays a and b are considered different if there exists such a position i that a_i ≠ b_i.

The number can be pretty large so print it modulo 998244353.

Input

The first line contains three integers n, k and m (1 ≤ n ≤ 5 ⋅ 10^5, 1 ≤ k ≤ 30, 0 ≤ m ≤ 5 ⋅ 10^5) — the length of the array a, the value such that all numbers in a should be smaller than 2^k and the number of conditions, respectively.

Each of the next m lines contains the description of a condition l_i, r_i and x_i (1 ≤ l_i ≤ r_i ≤ n, 0 ≤ x_i < 2^k) — the borders of the condition segment and the required bitwise AND value on it.

Output

Print a single integer — the number of distinct arrays a that satisfy all the above conditions modulo 998244353.

Examples

Input

4 3 2
1 3 3
3 4 6

Output

3

Input

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

Output

33

Note

You can recall what is a bitwise AND operation [here](https://en.wikipedia.org/wiki/Bitwise_operation#AND).

In the first example, the answer is the following arrays: [3, 3, 7, 6], [3, 7, 7, 6] and [7, 3, 7, 6].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
const int mod = 998244353;
int n, k, m, l[N], r[N], x[N], dp[N], c[N], lmx[N];
int solve(int b) {
  for (int i = 1; i <= n + 1; ++i) lmx[i] = 0, c[i] = 0, dp[i] = 0;
  for (int i = 1; i <= m; ++i) {
    if (x[i] >> b & 1)
      ++c[l[i]], --c[r[i] + 1];
    else
      lmx[r[i] + 1] = max(lmx[r[i] + 1], l[i]);
  }
  for (int i = 1; i <= n + 1; ++i)
    lmx[i] = max(lmx[i], lmx[i - 1]), c[i] += c[i - 1];
  int sdp = 1, j = 0;
  dp[0] = 1;
  for (int i = 1; i <= n + 1; ++i) {
    if (c[i] > 0) {
      dp[i] = 0;
      continue;
    }
    while (j < lmx[i]) sdp = (sdp - dp[j++] + mod) % mod;
    dp[i] = sdp;
    sdp = (sdp + dp[i]) % mod;
  }
  return dp[n + 1];
}
int main() {
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 1; i <= m; ++i) scanf("%d%d%d", &l[i], &r[i], &x[i]);
  int ans = 1;
  for (int i = 0; i < k; ++i) ans = 1ll * ans * solve(i) % mod;
  cout << ans << '\n';
  return 0;
}

```


### Prompt

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

You are given a rectangular field of n × m cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they share a side.

Let's call a connected component any non-extendible set of cells such that any two of them are connected by the path of adjacent cells. It is a typical well-known definition of a connected component.

For each impassable cell (x, y) imagine that it is an empty cell (all other cells remain unchanged) and find the size (the number of cells) of the connected component which contains (x, y). You should do it for each impassable cell independently.

The answer should be printed as a matrix with n rows and m columns. The j-th symbol of the i-th row should be "." if the cell is empty at the start. Otherwise the j-th symbol of the i-th row should contain the only digit —- the answer modulo 10. The matrix should be printed without any spaces.

To make your output faster it is recommended to build the output as an array of n strings having length m and print it as a sequence of lines. It will be much faster than writing character-by-character.

As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the field.

Each of the next n lines contains m symbols: "." for empty cells, "*" for impassable cells.

Output

Print the answer as a matrix as described above. See the examples to precise the format of the output.

Examples

Input

3 3
*.*
.*.
*.*

Output

3.3
.5.
3.3

Input

4 5
**..*
..***
.*.*.
*.*.*

Output

46..3
..732
.6.4.
5.4.3

Note

In first example, if we imagine that the central cell is empty then it will be included to component of size 5 (cross). If any of the corner cell will be empty then it will be included to component of size 3 (corner).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, g[1005][1005], c[1005][1005], ch[1005][1005], ans[1005][1005],
    k = 1, dix[4] = {0, 0, 1, -1}, diy[4] = {1, -1, 0, 0};
char tb[1005][1005];
int main() {
  int co;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", tb[i]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (tb[i][j] == '.' && !ch[i][j]) {
        co = 0;
        queue<pair<int, int>> q;
        q.push(make_pair(i, j));
        while (!q.empty()) {
          int x = q.front().first, y = q.front().second;
          q.pop();
          if (ch[x][y]) continue;
          co++;
          ch[x][y] = 1;
          g[x][y] = k;
          for (int z = 0; z < 4; z++) {
            int a = x + dix[z], b = y + diy[z];
            if ((a >= 0 && a < n) && (b >= 0 && b < m))
              if (tb[a][b] == '.' && !ch[a][b]) q.push(make_pair(a, b));
          }
        }
        k++;
        q.push(make_pair(i, j));
        while (!q.empty()) {
          int x = q.front().first, y = q.front().second;
          q.pop();
          if (c[x][y] > 0) continue;
          c[x][y] = co;
          for (int z = 0; z < 4; z++) {
            int a = x + dix[z], b = y + diy[z];
            if ((a >= 0 && a < n) && (b >= 0 && b < m))
              if (tb[a][b] == '.' && c[a][b] == 0) q.push(make_pair(a, b));
          }
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (tb[i][j] == '.')
        ans[i][j] = '.';
      else {
        int k = 1;
        set<int> s;
        for (int z = 0; z < 4; z++) {
          int x = i + dix[z], y = j + diy[z];
          if ((x >= 0 && x < n) && (y >= 0 && y < m))
            if (tb[x][y] == '.' && s.count(g[x][y]) == 0) {
              k += c[x][y];
              s.insert(g[x][y]);
            }
        }
        s.clear();
        k %= 10;
        ans[i][j] = k + '0';
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) printf("%c", ans[i][j]);
    printf("\n");
  }
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.

A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring t of the string s.

Prefix supposed that the substring t is the beginning of the string s; Suffix supposed that the substring t should be the end of the string s; and Obelix supposed that t should be located somewhere inside the string s, that is, t is neither its beginning, nor its end.

Asterix chose the substring t so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring t aloud, the temple doors opened.

You know the string s. Find the substring t or determine that such substring does not exist and all that's been written above is just a nice legend.

Input

You are given the string s whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.

Output

Print the string t. If a suitable t string does not exist, then print "Just a legend" without the quotes.

Examples

Input

fixprefixsuffix

Output

fix

Input

abcdabc

Output

Just a legend

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000 + 10;
int l[N];
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = ((int)(s).size());
  l[0] = -1;
  for (int i = (1); i <= (n); i++) {
    l[i] = l[i - 1];
    while (l[i] != -1 && s[i - 1] != s[l[i]]) l[i] = l[l[i]];
    l[i]++;
  }
  if (l[n] == 0) {
    cout << "Just a legend\n";
    return 0;
  }
  for (int i = (0); i <= (n - 1); i++)
    if (l[i] == l[n]) {
      for (int j = (0); j <= (l[i] - 1); j++) cout << s[j];
      cout << '\n';
      return 0;
    }
  if (l[l[n]] == 0) {
    cout << "Just a legend\n";
    return 0;
  }
  for (int i = (0); i <= (n - 1); i++)
    if (l[i] == l[l[n]]) {
      for (int j = (0); j <= (l[l[n]] - 1); j++) cout << s[j];
      cout << '\n';
      return 0;
    }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

There are n cards (n is even) in the deck. Each card has a positive integer written on it. n / 2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.

Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible.

Input

The first line of the input contains integer n (2 ≤ n ≤ 100) — the number of cards in the deck. It is guaranteed that n is even.

The second line contains the sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is equal to the number written on the i-th card.

Output

Print n / 2 pairs of integers, the i-th pair denote the cards that should be given to the i-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.

It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them.

Examples

Input

6
1 5 7 4 4 3

Output

1 3
6 2
4 5

Input

4
10 10 10 10

Output

1 2
3 4

Note

In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.

In the second sample, all values ai are equal. Thus, any distribution is acceptable.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(NULL);
  ios_base ::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<int, int> > ve;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    ve.push_back(make_pair(t, i + 1));
  }
  sort(ve.begin(), ve.end());
  for (int i = 0; i < n / 2; ++i) {
    cout << ve[i].second << " " << ve[n - 1 - i].second << "\n";
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noticed that the flowers stopped growing. The beaver thinks it is bad manners to present little flowers. So he decided to come up with some solutions.

There are m days left to the birthday. The height of the i-th flower (assume that the flowers in the row are numbered from 1 to n from left to right) is equal to ai at the moment. At each of the remaining m days the beaver can take a special watering and water w contiguous flowers (he can do that only once at a day). At that each watered flower grows by one height unit on that day. The beaver wants the height of the smallest flower be as large as possible in the end. What maximum height of the smallest flower can he get?

Input

The first line contains space-separated integers n, m and w (1 ≤ w ≤ n ≤ 105; 1 ≤ m ≤ 105). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print a single integer — the maximum final height of the smallest flower.

Examples

Input

6 2 3
2 2 2 2 1 1

Output

2

Input

2 5 1
5 8

Output

9

Note

In the first sample beaver can water the last 3 flowers at the first day. On the next day he may not to water flowers at all. In the end he will get the following heights: [2, 2, 2, 3, 2, 2]. The smallest flower has height equal to 2. It's impossible to get height 3 in this test.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long N, M, w, a[100007], st[400007], lazy[400007], b[100007];
void build(int l, int r, int p) {
  if (l == r) {
    st[p] = b[l];
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, p * 2);
  build(mid + 1, r, p * 2 + 1);
  st[p] = min(st[p * 2], st[p * 2 + 1]);
}
void push_lazy(int l, int r, int p) {
  if (lazy[p] == 0) return;
  st[p] += lazy[p];
  if (l != r) {
    lazy[p * 2] += lazy[p];
    lazy[p * 2 + 1] += lazy[p];
  } else
    b[l] += lazy[p];
  lazy[p] = 0;
}
void update_lazy(int l, int r, int p, int i, int j, long long val) {
  push_lazy(l, r, p);
  if (i > r || j < l) return;
  if (i <= l && j >= r) {
    st[p] += val;
    if (l == r)
      b[l] += val;
    else {
      lazy[p * 2] += val;
      lazy[p * 2 + 1] += val;
    }
    lazy[p] = 0;
    return;
  }
  int mid = (l + r) / 2;
  update_lazy(l, mid, p * 2, i, j, val);
  update_lazy(mid + 1, r, p * 2 + 1, i, j, val);
  st[p] = min(st[p * 2], st[p * 2 + 1]);
}
bool check(long long mid) {
  memset(lazy, 0, sizeof lazy);
  for (int i = 0; i < N; i++) b[i] = a[i];
  build(0, N - 1, 1);
  long long times = 0;
  for (int i = 0; i < N; i++) {
    update_lazy(0, N - 1, 1, i, i, 0);
    if (b[i] < mid) {
      long long val = mid - b[i];
      times += val;
      update_lazy(0, N - 1, 1, i, i + w - 1, val);
    }
  }
  return times <= M;
}
long long BS() {
  long long first = 0, last = 1e9 + 1e5 + 7, mid, ans = -1;
  while (first <= last) {
    mid = (first + last) / 2;
    if (check(mid)) {
      ans = mid;
      first = mid + 1;
    } else
      last = mid - 1;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> M >> w;
  for (int i = 0; i < N; i++) cin >> a[i];
  cout << BS();
  return 0;
}

```


### Prompt

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

Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:

Given two binary numbers a and b of length n. How many different ways of swapping two digits in a (only in a, not b) so that bitwise OR of these two numbers will be changed? In other words, let c be the bitwise OR of a and b, you need to find the number of ways of swapping two bits in a so that bitwise OR will not be equal to c.

Note that binary numbers can contain leading zeros so that length of each number is exactly n.

[Bitwise OR](https://en.wikipedia.org/wiki/Bitwise_operation#OR) is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, 01010_2 OR 10011_2 = 11011_2.

Well, to your surprise, you are not Rudolf, and you don't need to help him… You are the security staff! Please find the number of ways of swapping two bits in a so that bitwise OR will be changed.

Input

The first line contains one integer n (2≤ n≤ 10^5) — the number of bits in each number.

The second line contains a binary number a of length n.

The third line contains a binary number b of length n.

Output

Print the number of ways to swap two bits in a so that bitwise OR will be changed.

Examples

Input

5
01011
11001

Output

4

Input

6
011000
010011

Output

6

Note

In the first sample, you can swap bits that have indexes (1, 4), (2, 3), (3, 4), and (3, 5).

In the second example, you can swap bits that have indexes (1, 2), (1, 3), (2, 4), (3, 4), (3, 5), and (3, 6).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, a[100005], b[100005], rec[100005];
  cin >> n;
  string s1, s2;
  cin >> s1 >> s2;
  long long int n0 = 0, n1 = 0, n2 = 0, n3 = 0;
  for (i = 0; i < n; i++) {
    if (s1[i] == '0')
      a[i] = 0;
    else
      a[i] = 1;
  }
  for (i = 0; i < n; i++) {
    if (s2[i] == '0')
      b[i] = 0;
    else
      b[i] = 1;
  }
  for (i = 0; i < n; i++) {
    if (a[i] == b[i] && a[i] == 0)
      n0++;
    else if (a[i] == b[i] && a[i] == 1)
      n3++;
    else if (a[i] == 1 && b[i] == 0)
      n2++;
    else
      n1++;
  }
  long long int ans = 0;
  ans = (n0 * n2) + (n0 * n3);
  ans += (n1 * n2);
  cout << ans << endl;
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are n gems in the Shuseki Islands in total, and the i-th gem is located on island pi.

Mr. Kitayuta has just arrived at island 0. With his great jumping ability, he will repeatedly perform jumps between islands to the east according to the following process:

  * First, he will jump from island 0 to island d.
  * After that, he will continue jumping according to the following rule. Let l be the length of the previous jump, that is, if his previous jump was from island prev to island cur, let l = cur - prev. He will perform a jump of length l - 1, l or l + 1 to the east. That is, he will jump to island (cur + l - 1), (cur + l) or (cur + l + 1) (if they exist). The length of a jump must be positive, that is, he cannot perform a jump of length 0 when l = 1. If there is no valid destination, he will stop jumping.

Mr. Kitayuta will collect the gems on the islands visited during the process. Find the maximum number of gems that he can collect.

Input

The first line of the input contains two space-separated integers n and d (1 ≤ n, d ≤ 30000), denoting the number of the gems in the Shuseki Islands and the length of the Mr. Kitayuta's first jump, respectively.

The next n lines describe the location of the gems. The i-th of them (1 ≤ i ≤ n) contains a integer pi (d ≤ p1 ≤ p2 ≤ ... ≤ pn ≤ 30000), denoting the number of the island that contains the i-th gem.

Output

Print the maximum number of gems that Mr. Kitayuta can collect.

Examples

Input

4 10
10
21
27
27

Output

3

Input

8 8
9
19
28
36
45
55
66
78

Output

6

Input

13 7
8
8
9
16
17
17
18
21
23
24
24
26
30

Output

4

Note

In the first sample, the optimal route is 0  →  10 (+1 gem)  →  19  →  27 (+2 gems)  → ...

In the second sample, the optimal route is 0  →  8  →  15  →  21 →  28 (+1 gem)  →  36 (+1 gem)  →  45 (+1 gem)  →  55 (+1 gem)  →  66 (+1 gem)  →  78 (+1 gem)  → ...

In the third sample, the optimal route is 0  →  7  →  13  →  18 (+1 gem)  →  24 (+2 gems)  →  30 (+1 gem)  → ...

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, d, tr[30003], a, dp[500][30003], calc[500][30003];
int solve(int dis, int cur) {
  int jj = dis - d + 250;
  if (cur > 30000) return 0;
  if (calc[jj][cur]) return dp[jj][cur];
  calc[jj][cur] = 1;
  int res = tr[cur];
  int mx = max(solve(dis, cur + dis), solve(dis + 1, cur + dis + 1));
  if (dis > 1) mx = max(mx, solve(dis - 1, cur + dis - 1));
  res += mx;
  return dp[jj][cur] = res;
}
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    tr[a]++;
  }
  printf("%d\n", solve(d, d));
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.

These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed.

Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke.

Input

The first line of the input contains integer n (1 ≤ n ≤ 200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive.

We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user.

Output

Print a single integer — the maximum length of a repost chain.

Examples

Input

5
tourist reposted Polycarp
Petr reposted Tourist
WJMZBMR reposted Petr
sdya reposted wjmzbmr
vepifanov reposted sdya

Output

6

Input

6
Mike reposted Polycarp
Max reposted Polycarp
EveryOne reposted Polycarp
111 reposted Polycarp
VkCup reposted Polycarp
Codeforces reposted Polycarp

Output

2

Input

1
SoMeStRaNgEgUe reposted PoLyCaRp

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int M = 1e9 + 7, N = 1e5 + 1;
vector<int> v[N];
map<string, int> m;
int visited[N] = {0};
int level[N] = {0}, ans = 0;
void bfs(int node) {
  queue<int> q;
  visited[node] = 1;
  q.push(node);
  level[node] = 1;
  while (!q.empty()) {
    int y = q.front();
    visited[y] = 1;
    q.pop();
    for (auto x : v[y]) {
      if (!visited[x]) {
        q.push(x);
        level[x] = level[y] + 1;
      }
    }
  }
}
int main() {
  long long int n;
  cin >> n;
  int j = 1;
  m["polycarp"] = j++;
  for (int i = 1; i <= n; i++) {
    string a, b, c;
    cin >> a >> b >> c;
    for (int i = 0; i < a.size(); i++) a[i] = tolower(a[i]);
    for (int i = 0; i < c.size(); i++) c[i] = tolower(c[i]);
    m.insert({a, j++});
    m.insert({c, j++});
    v[m[c]].push_back(m[a]);
    v[m[a]].push_back(m[c]);
  }
  bfs(1);
  for (int i = 1; i <= j; i++) {
    ans = max(ans, level[i]);
  }
  cout << ans;
  return 0;
}

```


### Prompt

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

Ivan has number b. He is sorting through the numbers a from 1 to 10^{18}, and for every a writes ([a,    b])/(a) on blackboard. Here [a,    b] stands for least common multiple of a and b. Ivan is very lazy, that's why this task bored him soon. But he is interested in how many different numbers he would write on the board if he would finish the task. Help him to find the quantity of different numbers he would write on the board.

Input

The only line contains one integer — b (1 ≤ b ≤ 10^{10}).

Output

Print one number — answer for the problem.

Examples

Input

1

Output

1

Input

2

Output

2

Note

In the first example [a,    1] = a, therefore ([a,    b])/(a) is always equal to 1.

In the second example [a,    2] can be equal to a or 2 ⋅ a depending on parity of a. ([a,    b])/(a) can be equal to 1 and 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, c, q;
int main() {
  cin >> n;
  q = 2;
  c = 2;
  if (n == 1) {
    cout << 1;
    return 0;
  }
  while (q * q < n) {
    if (n % q == 0) c += 2;
    q++;
  }
  if (q * q == n) c++;
  cout << c;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

At many competitions that have a word «cup» in its official name the winner is presented with an actual cup. This time the organizers of one unusual programming competition have decided to please the winner even more and to add a nameplate to the cup with the handle of the winner.

The nameplate is to be rectangular and the text on it will be printed as a table of several rows and columns. Having some measurements done, the organizers have found out that the number a of rows cannot be greater than 5 while the number b of columns cannot exceed 20. Every cell of the table will contain either an asterisk («*») or a letter of user's handle.

Furthermore, the organizers want the rows of the table to be uniform, which means that the number of asterisks used in different rows should differ by at most one (i.e. you can't have two asterisks in the first row and none in the second). The main goal, however, is to obtain the winner's handle precisely when reading the table from top to bottom and from left to right in every row (skipping asterisks).

The organizers want for the nameplate to have as few rows as possible and among all valid tables with the minimum number of rows they want to choose the one that has the minimum number of columns.

The winner is not yet determined so your task is to write a program that, given a certain handle, generates the necessary table.

Input

The only line contains one string s (1 ≤ |s| ≤ 100), comprised of uppercase and lowercase Latin letters, — the handle of the winner.

Output

In the first line output the minimum number a of rows in the table and the minimum number b of columns in an optimal table with rows.

The following a lines should contain b characters each — any valid table.

Examples

Input

tourist

Output

1 7
tourist

Input

MyNameIsLifeIAmForeverByYourSideMyNameIsLife

Output

3 15
MyNameIsLifeIAm
ForeverByYourSi
deMyNameIsL*ife

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  string str;
  cin >> str;
  for (int64_t h = 1; h <= 5; ++h) {
    int64_t len = str.size() / h;
    if (str.size() % h) ++len;
    if (len > 20) continue;
    int64_t idx = 0;
    cout << h << ' ' << len << endl;
    for (int64_t i = 0; i < h; ++i) {
      for (int64_t j = 0; j < len - 1; ++j) {
        cout << str[idx];
        ++idx;
      }
      if (i < str.size() % h || str.size() % h == 0) {
        cout << str[idx];
        ++idx;
      } else
        cout << '*';
      cout << endl;
    }
    return 0;
  }
}

```


### Prompt

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

You are given a string s consisting of n lowercase Latin letters. n is even.

For each position i (1 ≤ i ≤ n) in string s you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.

For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.

That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' → 'd', 'o' → 'p', 'd' → 'e', 'e' → 'd', 'f' → 'e', 'o' → 'p', 'r' → 'q', 'c' → 'b', 'e' → 'f', 's' → 't').

String s is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.

Your goal is to check if it's possible to make string s a palindrome by applying the aforementioned changes to every position. Print "YES" if string s can be transformed to a palindrome and "NO" otherwise.

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

Input

The first line contains a single integer T (1 ≤ T ≤ 50) — the number of strings in a testcase.

Then 2T lines follow — lines (2i - 1) and 2i of them describe the i-th string. The first line of the pair contains a single integer n (2 ≤ n ≤ 100, n is even) — the length of the corresponding string. The second line of the pair contains a string s, consisting of n lowercase Latin letters.

Output

Print T lines. The i-th line should contain the answer to the i-th string of the input. Print "YES" if it's possible to make the i-th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise.

Example

Input

5
6
abccba
2
cf
4
adfa
8
abaazaba
2
ml

Output

YES
NO
YES
NO
NO

Note

The first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.

The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.

The third string can be changed to "beeb" which is a palindrome.

The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int t, n, i, dis;
  cin >> t;
  while (t--) {
    cin >> n >> s;
    string a, b;
    int flag = 0;
    for (i = 0; i < n / 2; i++) a += s[i];
    for (i = n / 2; i < n; i++) b += s[i];
    reverse(b.begin(), b.end());
    for (i = 0; i < n / 2; i++) {
      dis = abs(a[i] - b[i]);
      if (dis == 1 || dis > 2) {
        flag = 1;
        break;
      }
    }
    if (flag == 0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

```


### Prompt

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

The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of n and get last two digits of the number. Yes, of course, n can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions."

Could you pass the interview in the machine vision company in IT City?

Input

The only line of the input contains a single integer n (2 ≤ n ≤ 2·1018) — the power in which you need to raise number 5.

Output

Output the last two digits of 5n without spaces between them.

Examples

Input

2

Output

25

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  cout << 25 << endl;
  return 0;
}

```


### Prompt

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

Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n.

Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, that is, a teleportation pipe from city x to city y cannot be used to travel from city y to city x. The transportation within each city is extremely developed, therefore if a pipe from city x to city y and a pipe from city y to city z are both constructed, people will be able to travel from city x to city z instantly.

Mr. Kitayuta is also involved in national politics. He considers that the transportation between the m pairs of city (ai, bi) (1 ≤ i ≤ m) is important. He is planning to construct teleportation pipes so that for each important pair (ai, bi), it will be possible to travel from city ai to city bi by using one or more teleportation pipes (but not necessarily from city bi to city ai). Find the minimum number of teleportation pipes that need to be constructed. So far, no teleportation pipe has been constructed, and there is no other effective transportation between cities.

Input

The first line contains two space-separated integers n and m (2 ≤ n ≤ 105, 1 ≤ m ≤ 105), denoting the number of the cities in Shuseki Kingdom and the number of the important pairs, respectively.

The following m lines describe the important pairs. The i-th of them (1 ≤ i ≤ m) contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), denoting that it must be possible to travel from city ai to city bi by using one or more teleportation pipes (but not necessarily from city bi to city ai). It is guaranteed that all pairs (ai, bi) are distinct.

Output

Print the minimum required number of teleportation pipes to fulfill Mr. Kitayuta's purpose.

Examples

Input

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

Output

3

Input

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

Output

4

Note

For the first sample, one of the optimal ways to construct pipes is shown in the image below:

<image>

For the second sample, one of the optimal ways is shown below:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
namespace zzc {
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - 48;
    ch = getchar();
  }
  return x * f;
}
const int maxn = 1e5 + 5;
int head[maxn], rd[maxn], fa[maxn];
int n, cnt = 0, m, ans;
bool vis[maxn], ins[maxn], dsu[maxn];
queue<int> q;
struct edge {
  int to, nxt;
} e[maxn];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void add(int u, int v) {
  e[++cnt].to = v;
  e[cnt].nxt = head[u];
  head[u] = cnt;
  rd[v]++;
}
void work() {
  int a, b;
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    a = read();
    b = read();
    add(a, b);
    if (!vis[a]) {
      vis[a] = true;
      ans++;
    }
    if (!vis[b]) {
      vis[b] = true;
      ans++;
    }
    int fx = find(a);
    int fy = find(b);
    if (fx != fy) fa[fy] = fx;
  }
  for (int i = 1; i <= n; i++)
    if (!rd[i]) q.push(i), ins[i] = true;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].to;
      if (--rd[v] == 0) q.push(v), ins[v] = true;
    }
  }
  for (int i = 1; i <= n; i++)
    if (vis[i] && !ins[i] && !dsu[find(i)]) dsu[find(i)] = true;
  for (int i = 1; i <= n; i++)
    if (vis[i] && find(i) == i && !dsu[i]) ans--;
  printf("%d\n", ans);
}
}  // namespace zzc
int main() {
  zzc::work();
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn't always work properly. It works only if the product of integers in each row and each column equals to k, where k is either 1 or -1.

Now Ralph wants you to figure out the number of ways to put numbers in each block in such a way that the magic field works properly. Two ways are considered different if and only if there exists at least one block where the numbers in the first way and in the second way are different. You are asked to output the answer modulo 1000000007 = 109 + 7.

Note that there is no range of the numbers to put in the blocks, but we can prove that the answer is not infinity.

Input

The only line contains three integers n, m and k (1 ≤ n, m ≤ 1018, k is either 1 or -1).

Output

Print a single number denoting the answer modulo 1000000007.

Examples

Input

1 1 -1

Output

1

Input

1 3 1

Output

1

Input

3 3 -1

Output

16

Note

In the first example the only way is to put -1 into the only block.

In the second example the only way is to put 1 into every block.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
long long a, b, c;
int g[N][N];
int solve(int x) {
  if (x == a) {
    int can = 1;
    for (int x = 0, qwe = a; x < qwe; x++) {
      int tmp = 1;
      for (int y = 0, qwe = b; y < qwe; y++) tmp *= g[x][y];
      can &= tmp == c;
    }
    for (int y = 0, qwe = b; y < qwe; y++) {
      int tmp = 1;
      for (int x = 0, qwe = a; x < qwe; x++) tmp *= g[x][y];
      can &= tmp == c;
    }
    return can;
  } else {
    int tmp = 0;
    for (int m = 0, qwe = 1 << b; m < qwe; m++) {
      for (int y = 0, qwe = b; y < qwe; y++) g[x][y] = m & (1 << y) ? 1 : -1;
      tmp += solve(x + 1);
    }
    return tmp;
  }
}
const long long m = 1e9 + 7;
long long fe(long long b, long long e) {
  long long r = 1;
  while (e)
    if (e & 1)
      r = (r * b) % m, e--;
    else
      b = (b * b) % m, e /= 2;
  return r;
}
int main() {
  cin >> a >> b >> c;
  if (a > b) swap(a, b);
  long long tmp = fe(2, a - 1);
  tmp = fe(tmp, b - 1);
  if (c == -1) {
    if (a % 2 == b % 2)
      cout << tmp << endl;
    else
      cout << "0\n";
  } else {
    cout << tmp << endl;
  }
}

```


### Prompt

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

You are given an array a consisting of n integers.

Your task is to determine if a has some subsequence of length at least 3 that is a palindrome.

Recall that an array b is called a subsequence of the array a if b can be obtained by removing some (possibly, zero) elements from a (not necessarily consecutive) without changing the order of remaining elements. For example, [2], [1, 2, 1, 3] and [2, 3] are subsequences of [1, 2, 1, 3], but [1, 1, 2] and [4] are not.

Also, recall that a palindrome is an array that reads the same backward as forward. In other words, the array a of length n is the palindrome if a_i = a_{n - i - 1} for all i from 1 to n. For example, arrays [1234], [1, 2, 1], [1, 3, 2, 2, 3, 1] and [10, 100, 10] are palindromes, but arrays [1, 2] and [1, 2, 3, 1] are not.

You have to answer t independent test cases.

Input

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

Next 2t lines describe test cases. The first line of the test case contains one integer n (3 ≤ n ≤ 5000) — the length of a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n), where a_i is the i-th element of a.

It is guaranteed that the sum of n over all test cases does not exceed 5000 (∑ n ≤ 5000).

Output

For each test case, print the answer — "YES" (without quotes) if a has some subsequence of length at least 3 that is a palindrome and "NO" otherwise.

Example

Input

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

Output

YES
YES
NO
YES
NO

Note

In the first test case of the example, the array a has a subsequence [1, 2, 1] which is a palindrome.

In the second test case of the example, the array a has two subsequences of length 3 which are palindromes: [2, 3, 2] and [2, 2, 2].

In the third test case of the example, the array a has no subsequences of length at least 3 which are palindromes.

In the fourth test case of the example, the array a has one subsequence of length 4 which is a palindrome: [1, 2, 2, 1] (and has two subsequences of length 3 which are palindromes: both are [1, 2, 1]).

In the fifth test case of the example, the array a has no subsequences of length at least 3 which are palindromes.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int fun(vector<int> &v, int x, vector<vector<int> > &fq) {
  int i, j, k, n = v.size(), mx = 0, cnt = 0;
  i = 0;
  j = n - 1;
  while (true) {
    while (i < n && v[i] != x) i++;
    while (j >= 0 && v[j] != x) j--;
    if (i >= j) return max(mx, 1);
    cnt++;
    for (k = 1; k < 201; k++) {
      mx = max(mx, (2 * cnt) + fq[j - 1][k] - fq[i][k]);
    }
    i++;
    j--;
  }
  return mx;
}
void solve() {
  int i, j, k, n;
  cin >> n;
  vector<int> v(n);
  for (auto &i : v) cin >> i;
  ;
  vector<vector<int> > fq(n, vector<int>(201, 0));
  fq[0][v[0]]++;
  for (i = 1; i < n; i++) {
    for (j = 1; j < 201; j++) {
      fq[i][j] = fq[i - 1][j] + (j == v[i]);
    }
  }
  int mx = -10;
  for (i = 1; i < 201; i++) mx = max(mx, fun(v, i, fq));
  cout << mx << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

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

You're given an array a of n integers, such that a_1 + a_2 + ⋅⋅⋅ + a_n = 0.

In one operation, you can choose two different indices i and j (1 ≤ i, j ≤ n), decrement a_i by one and increment a_j by one. If i < j this operation is free, otherwise it costs one coin.

How many coins do you have to spend in order to make all elements equal to 0?

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 5000). Description of the test cases follows.

The first line of each test case contains an integer n (1 ≤ n ≤ 10^5) — the number of elements.

The next line contains n integers a_1, …, a_n (-10^9 ≤ a_i ≤ 10^9). It is given that ∑_{i=1}^n a_i = 0.

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

Output

For each test case, print the minimum number of coins we have to spend in order to make all elements equal to 0.

Example

Input

7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0

Output

3
0
4
1
8
3000000000
0

Note

Possible strategy for the first test case:

  * Do (i=2, j=3) three times (free), a = [-3, 2, 0, 1].
  * Do (i=2, j=1) two times (pay two coins), a = [-1, 0, 0, 1].
  * Do (i=4, j=1) one time (pay one coin), a = [0, 0, 0, 0].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(char c) { return to_string(string(1, c)); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
void solve(const int &test_id) {
  int n;
  long long c = 0;
  cin >> n;
  vector<long long> x(n);
  for (auto &e : x) cin >> e;
  for (int i = 0; i < n; i++) {
    if (x[i] > 0)
      c += x[i];
    else
      c -= min(c, -x[i]);
  }
  cout << c << endl;
}
void solve_cases() {
  int test_cases = 1;
  cin >> test_cases;
  for (int i = 1; i <= test_cases; i++) solve(i);
}
void fast_io() {
  ios::sync_with_stdio(false);
  srand(time(NULL));
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(15);
  cerr << fixed << setprecision(15);
}
int main() {
  fast_io();
  solve_cases();
  return EXIT_SUCCESS;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

After lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page.

Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number k as the first page which was not read (i.e. she read all pages from the 1-st to the (k-1)-th).

The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle).

Input

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

There are n lines then. The i-th of these lines contains two integers l_i, r_i separated by space (l_1 = 1, l_i ≤ r_i) — numbers of the first and the last pages of the i-th chapter. It's guaranteed that l_{i+1} = r_i + 1 for all 1 ≤ i ≤ n-1, and also that every chapter contains at most 100 pages.

The (n+2)-th line contains a single integer k (1 ≤ k ≤ r_n) — the index of the marked page.

Output

Print a single integer — the number of chapters which has not been completely read so far.

Examples

Input

3
1 3
4 7
8 11
2

Output

3

Input

3
1 4
5 9
10 12
9

Output

2

Input

1
1 7
4

Output

1

Note

In the first example the book contains 11 pages and 3 chapters — [1;3], [4;7] and [8;11]. Nastya marked the 2-nd page, so she finished in the middle of the 1-st chapter. So, all chapters has not been read so far, so the answer is 3.

The book in the second example contains 12 pages and 3 chapters too, but Nastya finished reading in the middle of the 2-nd chapter, so that the answer is 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2;
const long long int MOD = 1e9 + 7;
bool comp(const pair<long long int, long long int> &p1,
          const pair<long long int, long long int> &p2) {
  long long int x = abs(p1.first - p1.second);
  long long int y = abs(p2.first - p2.second);
  if (x > y)
    return true;
  else
    return false;
}
void Solve() {
  long long int n, k;
  cin >> n;
  vector<pair<long long int, long long int> > v;
  for (long long int i = 0; i < n; i++) {
    long long int a, b;
    cin >> a >> b;
    v.push_back({a, b});
  }
  cin >> k;
  sort(v.begin(), v.end());
  long long int ans = n;
  for (long long int i = 0; i < n; i++) {
    pair<long long int, long long int> p = v[i];
    if (p.first == k || p.second == k) break;
    if (k >= p.first && k <= p.second)
      break;
    else
      ans--;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  ;
  int T = 1;
  while (T--) {
    Solve();
  }
  return 0;
}

```


### Prompt

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

Vasya is developing his own programming language VPL (Vasya Programming Language). Right now he is busy making the system of exceptions. He thinks that the system of exceptions must function like that.

The exceptions are processed by try-catch-blocks. There are two operators that work with the blocks:

  1. The try operator. It opens a new try-catch-block.
  2. The catch(<exception_type>, <message>) operator. It closes the try-catch-block that was started last and haven't yet been closed. This block can be activated only via exception of type <exception_type>. When we activate this block, the screen displays the <message>. If at the given moment there is no open try-catch-block, then we can't use the catch operator.

The exceptions can occur in the program in only one case: when we use the throw operator. The throw(<exception_type>) operator creates the exception of the given type.

Let's suggest that as a result of using some throw operator the program created an exception of type a. In this case a try-catch-block is activated, such that this block's try operator was described in the program earlier than the used throw operator. Also, this block's catch operator was given an exception type a as a parameter and this block's catch operator is described later that the used throw operator. If there are several such try-catch-blocks, then the system activates the block whose catch operator occurs earlier than others. If no try-catch-block was activated, then the screen displays message "Unhandled Exception".

To test the system, Vasya wrote a program that contains only try, catch and throw operators, one line contains no more than one operator, the whole program contains exactly one throw operator.

Your task is: given a program in VPL, determine, what message will be displayed on the screen.

Input

The first line contains a single integer: n (1 ≤ n ≤ 105) the number of lines in the program. Next n lines contain the program in language VPL. Each line contains no more than one operator. It means that input file can contain empty lines and lines, consisting only of spaces.

The program contains only operators try, catch and throw. It is guaranteed that the program is correct. It means that each started try-catch-block was closed, the catch operators aren't used unless there is an open try-catch-block. The program has exactly one throw operator. The program may have spaces at the beginning of a line, at the end of a line, before and after a bracket, a comma or a quote mark.

The exception type is a nonempty string, that consists only of upper and lower case english letters. The length of the string does not exceed 20 symbols. Message is a nonempty string, that consists only of upper and lower case english letters, digits and spaces. Message is surrounded with quote marks. Quote marks shouldn't be printed. The length of the string does not exceed 20 symbols.

Length of any line in the input file does not exceed 50 symbols.

Output

Print the message the screen will show after the given program is executed.

Examples

Input

8
try
    try
        throw ( AE )
    catch ( BE, "BE in line 3")

    try
    catch(AE, "AE in line 5")
catch(AE,"AE somewhere")

Output

AE somewhere

Input

8
try
    try
        throw ( AE )
    catch ( AE, "AE in line 3")

    try
    catch(BE, "BE in line 5")
catch(AE,"AE somewhere")

Output

AE in line 3

Input

8
try
    try
        throw ( CE )
    catch ( BE, "BE in line 3")

    try
    catch(AE, "AE in line 5")
catch(AE,"AE somewhere")

Output

Unhandled Exception

Note

In the first sample there are 2 try-catch-blocks such that try operator is described earlier than throw operator and catch operator is described later than throw operator: try-catch(BE,"BE in line 3") and try-catch(AE,"AE somewhere"). Exception type is AE, so the second block will be activated, because operator catch(AE,"AE somewhere") has exception type AE as parameter and operator catch(BE,"BE in line 3") has exception type BE.

In the second sample there are 2 try-catch-blocks such that try operator is described earlier than throw operator and catch operator is described later than throw operator: try-catch(AE,"AE in line 3") and try-catch(AE,"AE somewhere"). Exception type is AE, so both blocks can be activated, but only the first one will be activated, because operator catch(AE,"AE in line 3") is described earlier than catch(AE,"AE somewhere")

In the third sample there is no blocks that can be activated by an exception of type CE.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, pnt;
vector<pair<int, pair<string, string> > > op;
char line[64];
bool isEmpty() {
  for (int i = 0; i < m; i++) {
    if (isalpha(line[i])) return false;
  }
  return true;
}
void getToken1(char *token) {
  int length = 0;
  for (; !isalpha(line[pnt]); pnt++)
    ;
  for (; isalpha(line[pnt]); token[length++] = line[pnt++])
    ;
  token[length] = '\0';
}
void getToken2(char *token) {
  int length = 0;
  for (; line[pnt] != '\"'; pnt++)
    ;
  pnt++;
  for (; line[pnt] != '\"'; token[length++] = line[pnt++])
    ;
  token[length] = '\0';
}
stack<int> s;
int main() {
  scanf("%d", &n);
  gets(line);
  for (int i = 0; i < n; i++) {
    gets(line);
    m = strlen(line);
    if (isEmpty()) continue;
    pnt = 0;
    char token[64];
    getToken1(token);
    if (token[1] == 'r') {
      op.push_back(make_pair(0, make_pair("", "")));
    } else if (token[1] == 'h') {
      getToken1(token);
      op.push_back(make_pair(1, make_pair(token, "")));
    } else {
      char token2[64];
      getToken1(token);
      getToken2(token2);
      op.push_back(make_pair(2, make_pair(token, token2)));
    }
  }
  bool found = false;
  string throwException;
  n = op.size();
  for (int i = 0; i < n; i++) {
    if (op[i].first == 0) {
      s.push(0);
    } else if (op[i].first == 1) {
      throwException = op[i].second.first;
      s.push(1);
    } else {
      if (s.top() == 0) {
        s.pop();
      } else if (op[i].second.first == throwException) {
        found = true;
        puts(op[i].second.second.c_str());
        break;
      } else {
        s.pop();
        if (s.empty()) {
          break;
        }
        s.pop();
        s.push(1);
      }
    }
  }
  if (!found) {
    puts("Unhandled Exception");
  }
  return 0;
}

```


### Prompt

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

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

Input

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

Output

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

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

Examples

Input

3
3 2 2

Output

4

Input

4
2 2 2 2

Output

3

Note

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

### Response

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

```


### Prompt

Create a solution in cpp for the following problem:

The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.

Find any longest k-good segment.

As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

Input

The first line contains two integers n, k (1 ≤ k ≤ n ≤ 5·105) — the number of elements in a and the parameter k.

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

Output

Print two integers l, r (1 ≤ l ≤ r ≤ n) — the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.

Examples

Input

5 5
1 2 3 4 5

Output

1 5

Input

9 3
6 5 1 2 3 2 1 4 5

Output

3 7

Input

3 1
1 2 3

Output

1 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  long long a[n], i, m = 0, s = 0, e, len = 0, start, end;
  for (i = 0; i < n; i++) cin >> a[i];
  map<long long, long long> mp;
  for (e = 0; e < n; e++) {
    mp[a[e]]++;
    while (mp.size() > k && s < n) {
      mp[a[s]]--;
      if (mp[a[s]] <= 0) {
        mp.erase(a[s]);
      }
      s++;
    }
    len = e - s + 1;
    if (len > m) {
      m = len;
      start = s;
      end = e;
    }
  }
  cout << start + 1 << " " << end + 1 << "\n";
}

```


### Prompt

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

It is a balmy spring afternoon, and Farmer John's n cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through n, are arranged so that the i-th cow occupies the i-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his k minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute.

Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the k minutes that they have. We denote as pi the label of the cow in the i-th stall. The messiness of an arrangement of cows is defined as the number of pairs (i, j) such that i < j and pi > pj.

Input

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100 000) — the number of cows and the length of Farmer John's nap, respectively.

Output

Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than k swaps.

Examples

Input

5 2

Output

10

Input

1 10

Output

0

Note

In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10.

In the second sample, there is only one cow, so the maximum possible messiness is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 212345, LG = 21, mod = 1000000007;
const double eps = 1e-3, pi = acos(-1.0);
char s[5], t[5], a[3];
int main() {
  long long n, k;
  scanf("%lld", &n), scanf("%lld", &k);
  if (n / 2 > k) {
    printf("%lld\n", k * (2 * k - 1) + (n - 2 * k) * 2 * k);
  } else {
    printf("%lld\n", (n * (n - 1)) / 2);
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Two best friends Serozha and Gena play a game.

Initially there is one pile consisting of n stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles consisting of a1 > a2 > ... > ak > 0 stones. The piles should meet the condition a1 - a2 = a2 - a3 = ... = ak - 1 - ak = 1. Naturally, the number of piles k should be no less than two.

The friends play in turns. The player who cannot make a move loses. Serozha makes the first move. Who will win if both players play in the optimal way?

Input

The single line contains a single integer n (1 ≤ n ≤ 105).

Output

If Serozha wins, print k, which represents the minimal number of piles into which he can split the initial one during the first move in order to win the game.

If Gena wins, print "-1" (without the quotes).

Examples

Input

3

Output

2

Input

6

Output

-1

Input

100

Output

8

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, a, k, ans = N, gx, xr[N];
bool win = 0, vis[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    k = 2;
    memset(vis, 0, sizeof vis);
    while ((2 * i + k - k * k) >= 1) {
      if ((2 * i + k - k * k) % (2 * k)) {
        k++;
        continue;
      }
      a = (2 * i + k - k * k) / (2 * k);
      vis[xr[a + k - 1] ^ xr[a - 1]] = true;
      if ((xr[a + k - 1] ^ xr[a - 1]) == 0 && i == n) ans = min(ans, k);
      k++;
    }
    for (int j = 0; j < N; j++)
      if (!vis[j]) {
        gx = j;
        break;
      }
    xr[i] = xr[i - 1] ^ gx;
  }
  cout << ((xr[n] ^ xr[n - 1]) == 0 ? -1 : ans);
  return 0;
}

```


### Prompt

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

This problem is same as the next one, but has smaller constraints.

Aki is playing a new video game. In the video game, he will control Neko, the giant cat, to fly between planets in the Catniverse.

There are n planets in the Catniverse, numbered from 1 to n. At the beginning of the game, Aki chooses the planet where Neko is initially located. Then Aki performs k - 1 moves, where in each move Neko is moved from the current planet x to some other planet y such that:

  * Planet y is not visited yet.
  * 1 ≤ y ≤ x + m (where m is a fixed constant given in the input)

This way, Neko will visit exactly k different planets. Two ways of visiting planets are called different if there is some index i such that the i-th planet visited in the first way is different from the i-th planet visited in the second way.

What is the total number of ways to visit k planets this way? Since the answer can be quite large, print it modulo 10^9 + 7.

Input

The only line contains three integers n, k and m (1 ≤ n ≤ 10^5, 1 ≤ k ≤ min(n, 12), 1 ≤ m ≤ 4) — the number of planets in the Catniverse, the number of planets Neko needs to visit and the said constant m.

Output

Print exactly one integer — the number of different ways Neko can visit exactly k planets. Since the answer can be quite large, print it modulo 10^9 + 7.

Examples

Input

3 3 1

Output

4

Input

4 2 1

Output

9

Input

5 5 4

Output

120

Input

100 1 2

Output

100

Note

In the first example, there are 4 ways Neko can visit all the planets:

  * 1 → 2 → 3
  * 2 → 3 → 1
  * 3 → 1 → 2
  * 3 → 2 → 1

In the second example, there are 9 ways Neko can visit exactly 2 planets:

  * 1 → 2
  * 2 → 1
  * 2 → 3
  * 3 → 1
  * 3 → 2
  * 3 → 4
  * 4 → 1
  * 4 → 2
  * 4 → 3

In the third example, with m = 4, Neko can visit all the planets in any order, so there are 5! = 120 ways Neko can visit all the planets.

In the fourth example, Neko only visit exactly 1 planet (which is also the planet he initially located), and there are 100 ways to choose the starting planet for Neko.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 210;
const long long mod = 1e9 + 7;
struct matrix {
  int n, m;
  long long arr[N][N];
  matrix(int _n = N - 1, int _m = N - 1, int v = 0) {
    n = _n;
    m = _m;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        arr[i][j] = v;
      }
    }
  }
  matrix operator*(matrix b) {
    matrix c(n, b.m, 0);
    for (int i = 1; i <= n; i++) {
      for (int k = 1; k <= b.n; k++) {
        for (int j = 1; j <= b.m; j++) {
          c.arr[i][j] += arr[i][k] * b.arr[k][j] % mod;
          c.arr[i][j] %= mod;
        }
      }
    }
    return c;
  }
  matrix pow(long long k) {
    matrix a(n, n);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        a.arr[i][j] = arr[i][j];
      }
    }
    matrix b(n, n, 0);
    for (int i = 1; i <= n; i++) b.arr[i][i] = 1;
    while (k) {
      if (k & 1) b = b * a;
      a = a * a;
      k >>= 1;
    }
    return b;
  }
};
int cnt[N], rec[15][20];
matrix A, R;
int main() {
  long long n, ans;
  int k, m, tot, state;
  scanf("%I64d %d %d", &n, &k, &m);
  for (int i = 0; i < (1 << m); i++) cnt[i] = __builtin_popcount(i);
  tot = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j < (1 << m); j++) {
      rec[i][j] = ++tot;
    }
  }
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j < (1 << m); j++) {
      state = (j << 1) & ((1 << m) - 1);
      A.arr[rec[i][j]][rec[i][state]]++;
      if (i < k) A.arr[rec[i][j]][rec[i + 1][state | 1]] += cnt[j] + 1;
    }
  }
  R = A.pow(n);
  ans = 0;
  for (int i = 0; i < (1 << m); i++) {
    ans += R.arr[1][rec[k][i]];
    ans %= mod;
  }
  printf("%I64d\n", ans);
  return 0;
}

```