### Prompt

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

Oscolcovo city has a campus consisting of n student dormitories, n universities and n military offices. Initially, the i-th dormitory belongs to the i-th university and is assigned to the i-th military office.

Life goes on and the campus is continuously going through some changes. The changes can be of four types:

  1. University aj merges with university bj. After that all the dormitories that belonged to university bj are assigned to to university aj, and university bj disappears.
  2. Military office cj merges with military office dj. After that all the dormitories that were assigned to military office dj, are assigned to military office cj, and military office dj disappears.
  3. Students of university xj move in dormitories. Lets kxj is the number of dormitories that belong to this university at the time when the students move in. Then the number of students in each dormitory of university xj increases by kxj (note that the more dormitories belong to the university, the more students move in each dormitory of the university).
  4. Military office number yj conducts raids on all the dormitories assigned to it and takes all students from there.

Thus, at each moment of time each dormitory is assigned to exactly one university and one military office. Initially, all the dormitory are empty.

Your task is to process the changes that take place in the campus and answer the queries, how many people currently live in dormitory qj.

Input

The first line contains two integers, n and m (1 ≤ n, m ≤ 5·105) — the number of dormitories and the number of queries, respectively.

Next m lines contain the queries, each of them is given in one of the following formats:

  * «U aj bj» — merging universities;
  * «M cj dj» — merging military offices;
  * «A xj» — students of university xj moving in the dormitories;
  * «Z yj» — a raid in military office yj;
  * «Q qj» — a query asking the number of people in dormitory qj.

All the numbers in the queries are positive integers and do not exceed n. It is guaranteed that at the moment of the query the universities and military offices, that are present in the query, exist.

Output

In the i-th line print the answer to the i-th query asking the number of people in the dormitory.

Examples

Input

2 7
A 1
Q 1
U 1 2
A 1
Z 1
Q 1
Q 2

Output

1
0
2

Input

5 12
U 1 2
M 4 5
A 1
Q 1
A 3
A 4
Q 3
Q 4
Z 4
Q 4
A 5
Q 5

Output

2
1
1
0
1

Note

Consider the first sample test:

  * In the first query university 1 owns only dormitory 1, so after the query dormitory 1 will have 1 student.
  * After the third query university 1 owns dormitories 1 and 2.
  * The fourth query increases by 2 the number of students living in dormitories 1 and 2 that belong to university number 1. After that 3 students live in the first dormitory and 2 students live in the second dormitory.
  * At the fifth query the number of students living in dormitory 1, assigned to the military office 1, becomes zero.

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:128000000")
using namespace std;
void solve();
void precalc();
clock_t start;
bool doing = true;
int main() {
  int t = 1;
  cout.sync_with_stdio(0);
  cin.tie(0);
  precalc();
  cout.precision(10);
  cout << fixed;
  start = clock();
  int testNum = 1;
  while (t--) {
    solve();
  }
  return 0;
}
void precalc() {}
int binpow(int q, int w, int mod) {
  if (!w) return 1;
  if (w & 1) return q * 1LL * binpow(q, w - 1, mod) % mod;
  return binpow(q * 1LL * q % mod, w / 2, mod);
}
int gcd(int q, int w) {
  while (w) {
    q %= w;
    swap(q, w);
  }
  return q;
}
struct _node;
typedef _node* node;
struct _node {
  int cnt, prior;
  _node* l;
  _node* r;
  _node* p;
  long long val;
  long long add;
  int lastNull;
  int lastNullToPush;
  _node() : val(0), add(0), lastNull(0), lastNullToPush(0) {
    prior = (rand() << 16) | rand();
    cnt = 1;
    l = nullptr;
    r = nullptr;
    p = nullptr;
  }
  inline void push() {
    if (l) {
      l->add += add;
      l->lastNullToPush = max(l->lastNullToPush, lastNullToPush);
    }
    if (r) {
      r->add += add;
      r->lastNullToPush = max(r->lastNullToPush, lastNullToPush);
    }
    lastNull = max(lastNull, lastNullToPush);
    val += add;
    add = 0;
    lastNullToPush = 0;
  }
  inline void recalc() {
    p = nullptr;
    cnt = 1 + Cnt(l) + Cnt(r);
    if (l) {
      l->p = this;
    }
    if (r) {
      r->p = this;
    }
  }
  static int Cnt(_node* v) {
    if (!v) return 0;
    return v->cnt;
  }
  node merge(node l, node r) {
    if (!l) return r;
    if (!r) return l;
    if (l->prior < r->prior) {
      l->push();
      l->r = merge(l->r, r);
      l->recalc();
      return l;
    } else {
      r->push();
      r->l = merge(l, r->l);
      r->recalc();
      return r;
    }
  }
  inline void split(node v, int key, node& l, node& r) {
    l = r = nullptr;
    if (!v) return;
    v->push();
    int cur = Cnt(v->l);
    if (cur < key) {
      l = v;
      split(l->r, key - cur - 1, l->r, r);
      l->recalc();
    } else {
      r = v;
      split(r->l, key, l, r->l);
      r->recalc();
    }
  }
  node push_back(node other) { return merge(this, other); }
  int getLastZero(node v) {
    int res = v->lastNull;
    while (v) {
      res = max(res, v->lastNullToPush);
      v = v->p;
    }
    return res;
  }
  long long getActualVal(_node* v) {
    long long res = v->val;
    while (v) {
      res += v->add;
      v = v->p;
    }
    return res;
  }
};
enum { UNI_MERGE = 0, WAR_MERGE = 1, UNI_ADD = 2, WAR_ZERO = 3, QUERY = 4 };
struct Query {
  int type;
  int q, w;
  int num;
  void scan() {
    char c;
    cin >> c;
    switch (c) {
      case 'U':
        type = UNI_MERGE;
        cin >> q >> w;
        --q;
        --w;
        break;
      case 'M':
        type = WAR_MERGE;
        cin >> q >> w;
        --q;
        --w;
        break;
      case 'A':
        type = UNI_ADD;
        cin >> q;
        --q;
        break;
      case 'Z':
        type = WAR_ZERO;
        cin >> q;
        --q;
        break;
      case 'Q':
        type = QUERY;
        cin >> q;
        --q;
        break;
      default:
        assert(false);
    }
  }
};
vector<int> dsu[2];
int findSet(int id, int v) {
  if (dsu[id][v] == v) {
    return v;
  }
  return dsu[id][v] = findSet(id, dsu[id][v]);
}
void merge(int id, int q, int w) { dsu[id][w] = q; }
void solve() {
  int n, Q;
  cin >> n >> Q;
  vector<Query> ask;
  vector<vector<pair<int, int>>> askNum(Q);
  for (int i = 0; i < Q; ++i) {
    Query cur;
    cur.scan();
    cur.num = i;
    if (cur.type == QUERY) {
      askNum[i].push_back(make_pair(cur.q, i));
    }
    ask.push_back(cur);
  }
  vector<long long> res(Q, 0);
  for (int dom = 1; dom >= -1; dom -= 2) {
    vector<int> sizes(n, 1);
    vector<node> uni(n), war(n);
    vector<node> uniRoots(n), warRoots(n);
    for (int i = 0; i < n; ++i) {
      uni[i] = new _node();
      war[i] = new _node();
      uniRoots[i] = uni[i];
      warRoots[i] = war[i];
    }
    for (int w = 0; w < 2; ++w) {
      dsu[w].resize(n);
      for (int i = 0; i < n; ++i) {
        dsu[w][i] = i;
      }
    }
    for (int i = 0; i < Q; ++i) {
      for (auto item : askNum[i]) {
        int id = item.first;
        long long curRes = uni[id]->getActualVal(uni[id]);
        res[item.second] += dom * curRes;
      }
      askNum[i].clear();
      auto& curAsk = ask[i];
      if (curAsk.type == QUERY) {
        int id = curAsk.q;
        int lastZero = war[id]->getLastZero(war[id]);
        askNum[lastZero].push_back(make_pair(id, i));
      }
      if (curAsk.type == UNI_MERGE) {
        uniRoots[curAsk.q] = uniRoots[curAsk.q]->push_back(uniRoots[curAsk.w]);
        sizes[curAsk.q] += sizes[curAsk.w];
        merge(0, curAsk.q, curAsk.w);
      }
      if (curAsk.type == WAR_MERGE) {
        warRoots[curAsk.q] = warRoots[curAsk.q]->push_back(warRoots[curAsk.w]);
        merge(1, curAsk.q, curAsk.w);
      }
      if (curAsk.type == UNI_ADD) {
        uniRoots[curAsk.q]->add += sizes[curAsk.q];
      }
      if (curAsk.type == WAR_ZERO) {
        warRoots[curAsk.q]->lastNullToPush = i;
      }
    }
  }
  for (int i = 0; i < Q; ++i) {
    if (ask[i].type == QUERY) {
      cout << res[i] << "\n";
    }
  }
}

```


### Prompt

Generate a cpp solution to the following problem:

You are working for an amusement park as an operator of an obakeyashiki, or a haunted house, in which guests walk through narrow and dark corridors. The house is proud of their lively ghosts, which are actually robots remotely controlled by the operator, hiding here and there in the corridors. One morning, you found that the ghosts are not in the positions where they are supposed to be. Ah, yesterday was Halloween. Believe or not, paranormal spirits have moved them around the corridors in the night. You have to move them into their right positions before guests come. Your manager is eager to know how long it takes to restore the ghosts.

In this problem, you are asked to write a program that, given a floor map of a house, finds the smallest number of steps to move all ghosts to the positions where they are supposed to be.

A floor consists of a matrix of square cells. A cell is either a wall cell where ghosts cannot move into or a corridor cell where they can.

At each step, you can move any number of ghosts simultaneously. Every ghost can either stay in the current cell, or move to one of the corridor cells in its 4-neighborhood (i.e. immediately left, right, up or down), if the ghosts satisfy the following conditions:

1. No more than one ghost occupies one position at the end of the step.
2. No pair of ghosts exchange their positions one another in the step.

For example, suppose ghosts are located as shown in the following (partial) map, where a sharp sign ('#) represents a wall cell and 'a', 'b', and 'c' ghosts.

ab#
c##

The following four maps show the only possible positions of the ghosts after one step.

ab#      a b#     acb#     ab #
c##      #c##     # ##     #c##

Input

The input consists of at most 10 datasets, each of which represents a floor map of a house. The format of a dataset is as follows.

w h n
c11c12...c1w
c21c22...c2w
. . ..       .
..           .
.
..           .
ch1ch2...chw

w, h and n in the first line are integers, separated by a space. w and h are the floor width and height of the house, respectively. n is the number of ghosts. They satisfy the following constraints.

4 ≤ w ≤ 16

4 ≤ h ≤ 16

1 ≤ n ≤ 3

Subsequent h lines of w characters are the floor map. Each of cij is either:

* a '#' representing a wall cell,
* a lowercase letter representing a corridor cell which is the initial position of a ghost,
* an uppercase letter representing a corridor cell which is the position where the ghost corresponding to its lowercase letter is supposed to be, or
* a space representing a corridor cell that is none of the above.

In each map, each of the first n letters from a and the first n letters from A appears once and only once. Outermost cells of a map are walls; i.e. all characters of the first and last lines are sharps; and the first and last characters on each line are also sharps. All corridor cells in a map are connected; i.e. given a corridor cell, you can reach any other corridor cell by following corridor cells in the 4-neighborhoods. Similarly, all wall cells are connected. Any 2 × 2 area on any map has at least one sharp. You can assume that every map has a sequence of moves of ghosts that restores all ghosts to the positions where they are supposed to be.

The last dataset is followed by a line containing three zeros separated by a space.

Output

For each dataset in the input, one line containing the smallest number of steps to restore ghosts into the positions where they are supposed to be should be output. An output line should not contain extra characters such as spaces.

Examples

Input

5 5 2
#####
#A#B#
#   #
#b#a#
#####
16 4 3
################
## ########## ##
#    ABCcba    #
################
16 16 3
################
### ##    #   ##
##  #  ##   # c#
#  ## ########b#
# ##  # #   #  #
#  # ##   # # ##
##  a#  # # #  #
### ## #### ## #
##   #   #  #  #
#  ##### # ## ##
####   #B# #   #
##  C#   #   ###
#  # # ####### #
# ######  A##  #
#        #    ##
################
0 0 0

Output

7
36
77

Input

5 5 2

A#B#

b#a#

16 4 3

ABCcba    #

16 16 3

c#
b#

a#  # # #  #

B# #   #
C#   #   ###

A##  #

0 0 0

Output

7
36
77

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,-1,0,1};

struct State{
    int pa,pb,pc;
};

const int N = 16*16;
const int INF = 19191919;
int dp[N][N][N];

int solve(int w, int h, int n){
    cin.ignore();
    vector<string> f(h);
    rep(i,h) getline(cin, f[i]);

    auto cv = [&](pi p){
        return p.fi*w+p.se;
    };

    int sa=0,sb=0,sc=0,ga=0,gb=0,gc=0;
    rep(i,h)rep(j,w){
        if(f[i][j]=='a') sa = cv({i,j});
        if(f[i][j]=='b') sb = cv({i,j});
        if(f[i][j]=='c') sc = cv({i,j});
        if(f[i][j]=='A') ga = cv({i,j});
        if(f[i][j]=='B') gb = cv({i,j});
        if(f[i][j]=='C') gc = cv({i,j});
    }

    auto cand = [&](int p){
        int y = p/w, x = p%w;

        vector<int> ret;
        ret.pb(p);

        rep(d,4){
            int ny = y+dy[d], nx = x+dx[d];
            if(0<=ny && ny<h && 0<=nx && nx<w && f[ny][nx]!='#') ret.pb(cv({ny,nx}));
        }
        return ret;
    };

    rep(i,N)rep(j,N)rep(k,N) dp[i][j][k] = INF;
    dp[sa][sb][sc] = 0;
    queue<State> que;
    que.push({sa,sb,sc});
    while(!que.empty()){
        State now = que.front();
        que.pop();

        vector<int> da = cand(now.pa), db = cand(now.pb), dc = cand(now.pc);

        for(int A:da)for(int B:db)for(int C:dc){
            if(B != 0){
                if(B == A) continue;
                if(now.pa == B && now.pb == A) continue;
            }
            if(C != 0){
                if(C == A || C == B) continue;
                if(now.pa == C && now.pc == A) continue;
                if(now.pb == C && now.pc == B) continue;
            }

            if(dp[A][B][C] > dp[now.pa][now.pb][now.pc]+1){
                dp[A][B][C] = dp[now.pa][now.pb][now.pc]+1;
                if(A==ga && B==gb && C==gc) return dp[A][B][C];
                que.push({A,B,C});
            }
        }
    }
    assert(false);
}

int main(){
    int w,h,n;
    while(cin >>w >>h >>n,w){
        cout << solve(w,h,n) << endl;
    }
    return 0;
}

```


### Prompt

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

Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and L, and they move towards each other with speed v1 and v2, respectively. Luke has width d and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive.

Input

The first line of the input contains four integers d, L, v1, v2 (1 ≤ d, L, v1, v2 ≤ 10 000, d < L) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively.

Output

Print a single real value — the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

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

Examples

Input

2 6 2 2

Output

1.00000000000000000000

Input

1 9 1 2

Output

2.66666666666666650000

Note

In the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed.

In the second sample he needs to occupy the position <image>. In this case both presses move to his edges at the same time.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d;
  double ans;
  cin >> a >> b >> c >> d;
  a = b - a;
  c = c + d;
  ans = double(a) / double(c);
  printf("%lf\n", ans);
  return 0;
}

```


### Prompt

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

The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).

The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.

A person can move from one cell to another if those cells are not occupied by hotels and share a side.

Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?

Input

The first line of input contain two integers, n and k (3 ≤ n ≤ 99, 0 ≤ k ≤ 2×(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.

Output

Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".

If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.

Examples

Input

7 2

Output

YES
.......
.#.....
.#.....
.......

Input

5 3

Output

YES
.....
.###.
.....
.....

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i, j;
  cin >> n >> k;
  char a[4][n];
  for (i = 0; i < 4; i++) {
    for (j = 0; j < n; j++) a[i][j] = '.';
  }
  int t = n / 2, b = n / 2;
  i = t;
  j = b;
  if (k % 2 == 1) {
    int flag = 0;
    i = t - 1;
    j = t + 1;
    while (k - 2 >= 0 && i >= 1 && j < n - 1) {
      if (flag == 0) {
        a[1][i] = '#';
        a[1][j] = '#';
        k -= 2;
        flag = 1;
      } else {
        a[2][i] = '#';
        a[2][j] = '#';
        k -= 2;
        i--;
        j++;
        flag = 0;
      }
    }
    a[1][n / 2] = '#';
  } else {
    i = 1;
    while (k - 2 >= 0) {
      a[1][i] = '#';
      a[2][i] = '#';
      i++;
      k = k - 2;
    }
  }
  cout << "YES\n";
  for (i = 0; i < 4; i++) {
    for (j = 0; j < n; j++) cout << a[i][j];
    cout << "\n";
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

You are given an integer number n. The following algorithm is applied to it:

  1. if n = 0, then end algorithm;
  2. find the smallest prime divisor d of n;
  3. subtract d from n and go to step 1.

Determine the number of subtrations the algorithm will make.

Input

The only line contains a single integer n (2 ≤ n ≤ 10^{10}).

Output

Print a single integer — the number of subtractions the algorithm will make.

Examples

Input

5

Output

1

Input

4

Output

2

Note

In the first example 5 is the smallest prime divisor, thus it gets subtracted right away to make a 0.

In the second example 2 is the smallest prime divisor at both steps.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long check(long long val) {
  for (long long i = 2; i * i <= val; i++) {
    if (val % i == 0) return 0;
  }
  return 1;
}
int main() {
  long long t = 1;
  while (t--) {
    long long n;
    cin >> n;
    if (check(n)) {
      cout << 1 << endl;
      continue;
    }
    long long ans = 0;
    for (long long i = 2; i * i <= n; i++) {
      if (n % i == 0) {
        ans++;
        n -= i;
        break;
      }
    }
    ans += n / 2;
    cout << ans << endl;
  }
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.

Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.

The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.

Each customer is characterized by three values: t_i — the time (in minutes) when the i-th customer visits the restaurant, l_i — the lower bound of their preferred temperature range, and h_i — the upper bound of their preferred temperature range.

A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the i-th customer is satisfied if and only if the temperature is between l_i and h_i (inclusive) in the t_i-th minute.

Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.

Input

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

The first line of each test case contains two integers n and m (1 ≤ n ≤ 100, -10^9 ≤ m ≤ 10^9), where n is the number of reserved customers and m is the initial temperature of the restaurant.

Next, n lines follow. The i-th line of them contains three integers t_i, l_i, and h_i (1 ≤ t_i ≤ 10^9, -10^9 ≤ l_i ≤ h_i ≤ 10^9), where t_i is the time when the i-th customer visits, l_i is the lower bound of their preferred temperature range, and h_i is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.

The customers are given in non-decreasing order of their visit time, and the current time is 0.

Output

For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".

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

Example

Input

4
3 0
5 1 2
7 3 5
10 -1 0
2 12
5 7 10
10 16 20
3 -100
100 0 0
100 -50 50
200 100 100
1 100
99 -100 0

Output

YES
NO
YES
NO

Note

In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:

  * At 0-th minute, change the state to heating (the temperature is 0).
  * At 2-nd minute, change the state to off (the temperature is 2).
  * At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
  * At 6-th minute, change the state to off (the temperature is 3).
  * At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
  * At 10-th minute, the temperature will be 0, which satisfies the last customer.

In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.

In the second and the fourth case, Gildong has to make at least one customer unsatisfied.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int M = 1e9 + 7;
const int INF = 0x3f3f3f3f;
struct node {
  long long t, l, r;
} s[110];
int main() {
  ios::sync_with_stdio(0);
  int q;
  cin >> q;
  while (q--) {
    int n, m;
    cin >> n >> m;
    bool flag = 0;
    long long minx = m, maxn = m;
    s[0].t = 0;
    for (int i = 1; i <= n; i++) {
      cin >> s[i].t >> s[i].l >> s[i].r;
      long long time = s[i].t - s[i - 1].t;
      if ((minx - time) > s[i].r || (maxn + time) < s[i].l) flag = 1;
      minx = max(minx - time, s[i].l);
      maxn = min(maxn + time, s[i].r);
    }
    if (flag)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

This is the easy version of the problem. The difference between the versions is that the easy version has no swap operations. You can make hacks only if all versions of the problem are solved.

Pikachu is a cute and friendly pokémon living in the wild pikachu herd.

But it has become known recently that infamous team R wanted to steal all these pokémon! Pokémon trainer Andrew decided to help Pikachu to build a pokémon army to resist.

First, Andrew counted all the pokémon — there were exactly n pikachu. The strength of the i-th pokémon is equal to a_i, and all these numbers are distinct.

As an army, Andrew can choose any non-empty subsequence of pokemons. In other words, Andrew chooses some array b from k indices such that 1 ≤ b_1 < b_2 < ... < b_k ≤ n, and his army will consist of pokémons with forces a_{b_1}, a_{b_2}, ..., a_{b_k}.

The strength of the army is equal to the alternating sum of elements of the subsequence; that is, a_{b_1} - a_{b_2} + a_{b_3} - a_{b_4} + ....

Andrew is experimenting with pokémon order. He performs q operations. In i-th operation Andrew swaps l_i-th and r_i-th pokémon.

Note: q=0 in this version of the task.

Andrew wants to know the maximal stregth of the army he can achieve with the initial pokémon placement. He also needs to know the maximal strength after each operation.

Help Andrew and the pokémon, or team R will realize their tricky plan!

Input

Each test contains multiple test cases.

The first line contains one positive integer t (1 ≤ t ≤ 10^3) denoting the number of test cases. Description of the test cases follows.

The first line of each test case contains two integers n and q (1 ≤ n ≤ 3 ⋅ 10^5, q = 0) denoting the number of pokémon and number of operations respectively.

The second line contains n distinct positive integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) denoting the strengths of the pokémon.

i-th of the last q lines contains two positive integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) denoting the indices of pokémon that were swapped in the i-th operation.

It is guaranteed that the sum of n over all test cases does not exceed 3 ⋅ 10^5, and the sum of q over all test cases does not exceed 3 ⋅ 10^5.

Output

For each test case, print q+1 integers: the maximal strength of army before the swaps and after each swap.

Example

Input

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

Output

3
2
9

Note

In third test case we can build an army in such way: [1 2 5 4 3 6 7], its strength will be 5−3+7=9.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const long long inf = 1e18;
struct node {
  long long v[2][2];
  void init(int x) {
    v[0][0] = x;
    v[1][1] = -x;
    v[0][1] = v[1][0] = -1e18;
  }
  long long get() {
    long long w = -inf;
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++) w = max(w, v[i][j]);
    return w;
  }
} f[N * 4];
int a[N];
int n, m, T;
void upd(int s) {
  f[s].v[0][0] = f[s].v[0][1] = f[s].v[1][0] = f[s].v[1][1] = -inf;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++) {
      f[s].v[i][j] =
          max(f[s].v[i][j], max(f[s + s].v[i][j], f[s + s + 1].v[i][j]));
      for (int k = 0; k < 2; k++)
        f[s].v[i][k] =
            max(f[s].v[i][k], f[s + s].v[i][j] + f[s + s + 1].v[j ^ 1][k]);
    }
}
void build(int l, int r, int s) {
  if (l == r) {
    f[s].init(a[l]);
    return;
  }
  build(l, (l + r) / 2, s + s);
  build((l + r) / 2 + 1, r, s + s + 1);
  upd(s);
}
void change(int l, int r, int s, int ll) {
  if (l == r) {
    f[s].init(a[l]);
    return;
  }
  if ((l + r) / 2 >= ll)
    change(l, (l + r) / 2, s + s, ll);
  else
    change((l + r) / 2 + 1, r, s + s + 1, ll);
  upd(s);
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    build(1, n, 1);
    printf("%lld\n", f[1].get());
    while (m--) {
      int x, y;
      scanf("%d %d", &x, &y);
      swap(a[x], a[y]);
      change(1, n, 1, x);
      change(1, n, 1, y);
      printf("%lld\n", f[1].get());
    }
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

You are given three integers A, B and C.

Determine if there exists an equilateral triangle whose sides have lengths A, B and C.

Constraints

* All values in input are integers.
* 1 \leq A,B,C \leq 100

Input

Input is given from Standard Input in the following format:

A B C

Output

If there exists an equilateral triangle whose sides have lengths A, B and C, print `Yes`; otherwise, print `No`.

Examples

Input

2 2 2

Output

Yes

Input

3 4 5

Output

No

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  cout << (a == b && b == c ? "Yes" : "No");
}
```


### Prompt

Develop a solution in CPP to the problem described below:

Two beavers, Timur and Marsel, play the following game.

There are n logs, each of exactly m meters in length. The beavers move in turns. For each move a beaver chooses a log and gnaws it into some number (more than one) of equal parts, the length of each one is expressed by an integer and is no less than k meters. Each resulting part is also a log which can be gnawed in future by any beaver. The beaver that can't make a move loses. Thus, the other beaver wins.

Timur makes the first move. The players play in the optimal way. Determine the winner.

Input

The first line contains three integers n, m, k (1 ≤ n, m, k ≤ 109).

Output

Print "Timur", if Timur wins, or "Marsel", if Marsel wins. You should print everything without the quotes.

Examples

Input

1 15 4

Output

Timur

Input

4 9 5

Output

Marsel

Note

In the first sample the beavers only have one log, of 15 meters in length. Timur moves first. The only move he can do is to split the log into 3 parts each 5 meters in length. Then Marsel moves but he can't split any of the resulting logs, as k = 4. Thus, the winner is Timur.

In the second example the beavers have 4 logs 9 meters in length. Timur can't split any of them, so that the resulting parts possessed the length of not less than 5 meters, that's why he loses instantly.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
vector<long long> d;
set<long long> lol;
bool ban;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= sqrt(m); ++i)
    if (m % i == 0) d.push_back(i);
  for (int i = 0; i < (int)d.size(); ++i) {
    lol.insert(d[i]);
    lol.insert(m / d[i]);
  }
  d.clear();
  for (set<long long>::iterator it = lol.begin(); it != lol.end(); ++it) {
    d.push_back(*it);
  }
  for (int i = 0; i < (int)d.size(); ++i) {
    if (d[i] >= k && m / d[i] > 1) ban = true;
  }
  if (ban == true) {
    if (n % 2 == 0)
      cout << "Marsel\n";
    else
      cout << "Timur\n";
  } else
    cout << "Marsel\n";
  return 0;
}

```


### Prompt

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

Kostya is a progamer specializing in the discipline of Dota 2. Valve Corporation, the developer of this game, has recently released a new patch which turned the balance of the game upside down. Kostya, as the captain of the team, realizes that the greatest responsibility lies on him, so he wants to resort to the analysis of innovations patch from the mathematical point of view to choose the best heroes for his team in every game.

A Dota 2 match involves two teams, each of them must choose some heroes that the players of the team are going to play for, and it is forbidden to choose the same hero several times, even in different teams. In large electronic sports competitions where Kostya's team is going to participate, the matches are held in the Captains Mode. In this mode the captains select the heroes by making one of two possible actions in a certain, predetermined order: pick or ban.

  * To pick a hero for the team. After the captain picks, the picked hero goes to his team (later one of a team members will play it) and can no longer be selected by any of the teams.
  * To ban a hero. After the ban the hero is not sent to any of the teams, but it still can no longer be selected by any of the teams.

The team captain may miss a pick or a ban. If he misses a pick, a random hero is added to his team from those that were available at that moment, and if he misses a ban, no hero is banned, as if there was no ban.

Kostya has already identified the strength of all the heroes based on the new patch fixes. Of course, Kostya knows the order of picks and bans. The strength of a team is the sum of the strengths of the team's heroes and both teams that participate in the match seek to maximize the difference in strengths in their favor. Help Kostya determine what team, the first one or the second one, has advantage in the match, and how large the advantage is.

Input

The first line contains a single integer n (2 ≤ n ≤ 100) — the number of heroes in Dota 2.

The second line contains n integers s1, s2, ..., sn (1 ≤ si ≤ 106) — the strengths of all the heroes.

The third line contains a single integer m (2 ≤ m ≤ min(n, 20)) — the number of actions the captains of the team must perform.

Next m lines look like "action team", where action is the needed action: a pick (represented as a "p") or a ban (represented as a "b"), and team is the number of the team that needs to perform the action (number 1 or 2).

It is guaranteed that each team makes at least one pick. Besides, each team has the same number of picks and the same number of bans.

Output

Print a single integer — the difference between the strength of the first team and the strength of the second team if the captains of both teams will act optimally well.

Examples

Input

2
2 1
2
p 1
p 2

Output

1

Input

6
6 4 5 4 5 5
4
b 2
p 1
b 1
p 2

Output

0

Input

4
1 2 3 4
4
p 2
b 2
p 1
b 1

Output

-2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[20][1 << 20];
bool isVisit[20][1 << 20];
int data[100], n;
int m, query[20][2];
vector<int> subsets[1 << 20];
int getAns(int ind, int left) {
  int &ret = dp[ind][left];
  if (isVisit[ind][left]) return ret;
  isVisit[ind][left] = true;
  if (ind == m - 1) {
    if (query[ind][0] == 0)
      ret = data[subsets[left][0]];
    else
      ret = 0;
  } else {
    ret = -999999999;
    int flag = 1;
    if (query[ind][1] != query[ind + 1][1]) flag = -1;
    for (int i = 0; i < subsets[left].size(); i++) {
      int bit = subsets[left][i];
      int val = getAns(ind + 1, left ^ (1 << bit)) * flag;
      if (query[ind][0] == 0) val += data[bit];
      ret = max(ret, val);
    }
  }
  return ret;
}
int main(void) {
  for (int i = 0; i < (1 << 20); i++)
    for (int j = 0; j < 20; j++)
      if (i & (1 << j)) subsets[i].push_back(j);
  memset(dp, -1, sizeof(dp));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", data + i);
  sort(data, data + n);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    char temp[2];
    scanf("%s %d", temp, query[i] + 1);
    if (temp[0] == 'p')
      query[i][0] = 0;
    else
      query[i][0] = 1;
  }
  for (int i = 0; i < m; i++) data[i] = data[n - m + i];
  int val = getAns(0, (1 << m) - 1);
  if (query[0][1] == 2) val *= -1;
  printf("%d\n", val);
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.

You will now successively do the following Q operations:

* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.

For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.

Constraints

* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}

Input

Input is given from Standard Input in the following format:

N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}

Output

Print Q integers S_{i} to Standard Output in the following format:

S_{1}
S_{2}
\vdots
S_{Q}

Note that S_{i} may not fit into a 32-bit integer.

Examples

Input

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

Output

11
12
16

Input

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

Output

8
4
4

Input

2
1 2
3
1 100
2 100
100 1000

Output

102
200
2000

### Response

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

int main(){
	int N; cin>>N;
	map<int, int> C;
	long long s = 0;
	while(N--){
		int a; cin>>a;
		C[a]++;
		s += a;
	}
	int Q; cin>>Q;
	while(Q--){
		int b, c; cin>>b>>c;
		s += (c - b) * C[b];
		C[c] += C[b];
		C[b] = 0;
		cout<< s << endl;
	}
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Factorize a given integer n.

Constraints

* 2 ≤ n ≤ 109

Input

n

An integer n is given in a line.

Output

Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor.

Examples

Input

12

Output

12: 2 2 3

Input

126

Output

126: 2 3 3 7

### Response

```cpp
#include<iostream>
#include<cmath>

using namespace std;

int main(){

	int n;

	cin>>n;
	cout<<n<<":";
	for(int i=2;i<=sqrt((double)n);){
		if(n%i==0){
			cout<<" "<<i;
			n/=i;
		}
		else i++;
	}
	if(n!=0) cout<<" "<<n;
	cout<<endl;
}
```


### Prompt

Please create a solution in cpp to the following problem:

Polycarpus enjoys studying Berland hieroglyphs. Once Polycarp got hold of two ancient Berland pictures, on each of which was drawn a circle of hieroglyphs. We know that no hieroglyph occurs twice in either the first or the second circle (but in can occur once in each of them).

Polycarpus wants to save these pictures on his laptop, but the problem is, laptops do not allow to write hieroglyphs circles. So Polycarp had to break each circle and write down all of its hieroglyphs in a clockwise order in one line. A line obtained from the first circle will be called a, and the line obtained from the second one will be called b.

There are quite many ways to break hieroglyphic circles, so Polycarpus chooses the method, that makes the length of the largest substring of string a, which occurs as a subsequence in string b, maximum.

Help Polycarpus — find the maximum possible length of the desired substring (subsequence) if the first and the second circles are broken optimally.

The length of string s is the number of characters in it. If we denote the length of string s as |s|, we can write the string as s = s1s2... s|s|.

A substring of s is a non-empty string x = s[a... b] = sasa + 1... sb (1 ≤ a ≤ b ≤ |s|). For example, "code" and "force" are substrings of "codeforces", while "coders" is not.

A subsequence of s is a non-empty string y = s[p1p2... p|y|] = sp1sp2... sp|y| (1 ≤ p1 < p2 < ... < p|y| ≤ |s|). For example, "coders" is a subsequence of "codeforces".

Input

The first line contains two integers la and lb (1 ≤ la, lb ≤ 1000000) — the number of hieroglyphs in the first and second circles, respectively.

Below, due to difficulties with encoding of Berland hieroglyphs, they are given as integers from 1 to 106.

The second line contains la integers — the hieroglyphs in the first picture, in the clockwise order, starting with one of them.

The third line contains lb integers — the hieroglyphs in the second picture, in the clockwise order, starting with one of them.

It is guaranteed that the first circle doesn't contain a hieroglyph, which occurs twice. The second circle also has this property.

Output

Print a single number — the maximum length of the common substring and subsequence. If at any way of breaking the circles it does not exist, print 0.

Examples

Input

5 4
1 2 3 4 5
1 3 5 6

Output

2

Input

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

Output

3

Input

3 3
1 2 3
3 2 1

Output

2

Note

In the first test Polycarpus picks a string that consists of hieroglyphs 5 and 1, and in the second sample — from hieroglyphs 1, 3 and 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int wei[2100000], dl[2100000], x[2100000], y[2100000];
int n, m, i, ans, j, l, r;
bool can(int a) {
  if (i == j) return true;
  if (wei[dl[j]] > wei[dl[i]]) {
    if (a > wei[dl[j]] || a < wei[dl[i]]) return true;
    return false;
  }
  if (a > wei[dl[j]] && a < wei[dl[i]]) return true;
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &x[i]);
  for (i = n + 1; i < 2 * n; i++) x[i] = x[i - n];
  for (i = 1; i <= m; i++) scanf("%d", &y[i]), wei[y[i]] = i;
  l = 1;
  while (l <= n) {
    while (l <= n && wei[x[l]] == 0) l++;
    if (l > n) break;
    i = 1;
    j = 1;
    ans = max(ans, 1);
    dl[1] = x[l];
    r = l + 1;
    while (r < 2 * n && wei[x[r]] != 0) {
      if (can(wei[x[r]])) {
        dl[++j] = x[r];
        r++;
        ans = max(ans, j - i + 1);
        continue;
      }
      while (!can(wei[x[r]])) i++;
    }
    l = r;
  }
  printf("%d\n", ans);
}

```


### Prompt

Please create a solution in cpp to the following problem:

Alice has a string consisting of characters 'A', 'B' and 'C'. Bob can use the following transitions on any substring of our string in any order any number of times:

  * A <image> BC
  * B <image> AC
  * C <image> AB
  * AAA <image> empty string

Note that a substring is one or more consecutive characters. For given queries, determine whether it is possible to obtain the target string from source.

Input

The first line contains a string S (1 ≤ |S| ≤ 105). The second line contains a string T (1 ≤ |T| ≤ 105), each of these strings consists only of uppercase English letters 'A', 'B' and 'C'.

The third line contains the number of queries Q (1 ≤ Q ≤ 105).

The following Q lines describe queries. The i-th of these lines contains four space separated integers ai, bi, ci, di. These represent the i-th query: is it possible to create T[ci..di] from S[ai..bi] by applying the above transitions finite amount of times?

Here, U[x..y] is a substring of U that begins at index x (indexed from 1) and ends at index y. In particular, U[1..|U|] is the whole string U.

It is guaranteed that 1 ≤ a ≤ b ≤ |S| and 1 ≤ c ≤ d ≤ |T|.

Output

Print a string of Q characters, where the i-th character is '1' if the answer to the i-th query is positive, and '0' otherwise.

Example

Input

AABCCBAAB
ABCB
5
1 3 1 2
2 2 2 4
7 9 1 1
3 4 2 3
4 5 1 3

Output

10011

Note

In the first query we can achieve the result, for instance, by using transitions <image>.

The third query asks for changing AAB to A — but in this case we are not able to get rid of the character 'B'.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  string t;
  cin >> s >> t;
  for (long long i = 0; i < s.size(); i++) {
    if (s[i] == 'C') s[i] = 'B';
  }
  for (long long i = 0; i < t.size(); i++) {
    if (t[i] == 'C') t[i] = 'B';
  }
  long long n = s.size(), m = t.size();
  long long prefs[n + 1], preft[m + 1];
  prefs[0] = 0, preft[0] = 0;
  for (long long i = 0; i < n; i++) {
    prefs[i + 1] = prefs[i] + (s[i] == 'B');
  }
  for (long long i = 0; i < m; i++) {
    preft[i + 1] = preft[i] + (t[i] == 'B');
  }
  long long ls[n + 1], lt[m + 1];
  ls[0] = 0, lt[0] = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'B')
      ls[i + 1] = 0;
    else
      ls[i + 1] = ls[i] + 1;
  }
  for (long long i = 0; i < m; i++) {
    if (t[i] == 'B')
      lt[i + 1] = 0;
    else
      lt[i + 1] = lt[i] + 1;
  }
  long long q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    a--, b--, c--, d--;
    long long F = prefs[b + 1] - prefs[a];
    long long S = preft[d + 1] - preft[c];
    if (F % 2 != S % 2) {
      cout << 0;
      continue;
    }
    if (F > S) {
      cout << 0;
      continue;
    }
    long long A = ls[b + 1], B = lt[d + 1];
    A = min(A, b - a + 1);
    B = min(B, d - c + 1);
    if (A < B) {
      cout << 0;
      continue;
    }
    if (F == 0) {
      if (S != 0) {
        if (A == B)
          cout << 0;
        else
          cout << 1;
      } else {
        if (A % 3 == B % 3)
          cout << 1;
        else
          cout << 0;
      }
      continue;
    } else if (A % 3 == B % 3)
      cout << 1;
    else {
      F += 2;
      if (F > S)
        cout << 0;
      else
        cout << 1;
    }
  }
  return 0;
}

```


### Prompt

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

Bertown is a city with n buildings in a straight line.

The city's security service discovered that some buildings were mined. A map was compiled, which is a string of length n, where the i-th character is "1" if there is a mine under the building number i and "0" otherwise.

Bertown's best sapper knows how to activate mines so that the buildings above them are not damaged. When a mine under the building numbered x is activated, it explodes and activates two adjacent mines under the buildings numbered x-1 and x+1 (if there were no mines under the building, then nothing happens). Thus, it is enough to activate any one mine on a continuous segment of mines to activate all the mines of this segment. For manual activation of one mine, the sapper takes a coins. He can repeat this operation as many times as you want.

Also, a sapper can place a mine under a building if it wasn't there. For such an operation, he takes b coins. He can also repeat this operation as many times as you want.

The sapper can carry out operations in any order.

You want to blow up all the mines in the city to make it safe. Find the minimum number of coins that the sapper will have to pay so that after his actions there are no mines left in the city.

Input

The first line contains one positive integer t (1 ≤ t ≤ 10^5) — the number of test cases. Then t test cases follow.

Each test case begins with a line containing two integers a and b (1 ≤ a, b ≤ 1000) — the cost of activating and placing one mine, respectively.

The next line contains a map of mines in the city — a string consisting of zeros and ones.

The sum of the string lengths for all test cases does not exceed 10^5.

Output

For each test case, output one integer — the minimum number of coins that the sapper will have to pay.

Example

Input

2
1 1
01000010
5 1
01101110

Output

2
6

Note

In the second test case, if we place a mine under the fourth building and then activate it, then all mines on the field are activated. The cost of such operations is six, b=1 coin for placing a mine and a=5 coins for activating.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a, b;
string s;
long long int dp[100001][2];
long long int fun(long long int n, long long int k) {
  if (n < 0) return (k ? a : 0);
  if (dp[n][k] != -1) return dp[n][k];
  long long int ans;
  if (k) {
    if (s[n] == '1')
      ans = fun(n - 1, 1);
    else
      ans = min(a + fun(n - 1, 0), b + fun(n - 1, 1));
  } else {
    if (s[n] == '1')
      ans = fun(n - 1, 1);
    else
      ans = fun(n - 1, 0);
  }
  return dp[n][k] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    cin >> a >> b;
    cin >> s;
    long long int m = s.length();
    for (long long int i = 0; i < m; i++) dp[i][0] = dp[i][1] = -1;
    long long int res = fun(m - 1, 0);
    cout << res << "\n";
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Little Petya likes permutations a lot. Recently his mom has presented him permutation q1, q2, ..., qn of length n.

A permutation a of length n is a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ n), all integers there are distinct.

There is only one thing Petya likes more than permutations: playing with little Masha. As it turns out, Masha also has a permutation of length n. Petya decided to get the same permutation, whatever the cost may be. For that, he devised a game with the following rules:

  * Before the beginning of the game Petya writes permutation 1, 2, ..., n on the blackboard. After that Petya makes exactly k moves, which are described below.
  * During a move Petya tosses a coin. If the coin shows heads, he performs point 1, if the coin shows tails, he performs point 2.
    1. Let's assume that the board contains permutation p1, p2, ..., pn at the given moment. Then Petya removes the written permutation p from the board and writes another one instead: pq1, pq2, ..., pqn. In other words, Petya applies permutation q (which he has got from his mother) to permutation p.
    2. All actions are similar to point 1, except that Petya writes permutation t on the board, such that: tqi = pi for all i from 1 to n. In other words, Petya applies a permutation that is inverse to q to permutation p.

We know that after the k-th move the board contained Masha's permutation s1, s2, ..., sn. Besides, we know that throughout the game process Masha's permutation never occurred on the board before the k-th move. Note that the game has exactly k moves, that is, throughout the game the coin was tossed exactly k times.

Your task is to determine whether the described situation is possible or else state that Petya was mistaken somewhere. See samples and notes to them for a better understanding.

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 100). The second line contains n space-separated integers q1, q2, ..., qn (1 ≤ qi ≤ n) — the permutation that Petya's got as a present. The third line contains Masha's permutation s, in the similar format.

It is guaranteed that the given sequences q and s are correct permutations.

Output

If the situation that is described in the statement is possible, print "YES" (without the quotes), otherwise print "NO" (without the quotes).

Examples

Input

4 1
2 3 4 1
1 2 3 4

Output

NO

Input

4 1
4 3 1 2
3 4 2 1

Output

YES

Input

4 3
4 3 1 2
3 4 2 1

Output

YES

Input

4 2
4 3 1 2
2 1 4 3

Output

YES

Input

4 1
4 3 1 2
2 1 4 3

Output

NO

Note

In the first sample Masha's permutation coincides with the permutation that was written on the board before the beginning of the game. Consequently, that violates the condition that Masha's permutation never occurred on the board before k moves were performed.

In the second sample the described situation is possible, in case if after we toss a coin, we get tails.

In the third sample the possible coin tossing sequence is: heads-tails-tails.

In the fourth sample the possible coin tossing sequence is: heads-heads.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k;
set<vector<int> > f, to;
vector<int> x, y, aim, ss;
int q[110];
int main() {
  cin >> n >> k;
  x.resize(n);
  y.resize(n);
  aim.resize(n);
  ss.resize(n);
  for (int i = 0; i < n; i++) cin >> q[i], q[i]--;
  for (int i = 0; i < n; i++) cin >> aim[i], aim[i]--, ss[i] = i;
  f.insert(ss);
  if (f.count(aim)) {
    puts("NO");
    return 0;
  }
  for (int i = 1; i <= k; i++) {
    to.clear();
    for (set<vector<int> >::iterator j = f.begin(); j != f.end(); j++) {
      for (int t = 0; t < n; t++) {
        x[t] = (*j)[q[t]];
        y[q[t]] = (*j)[t];
      }
      to.insert(x);
      to.insert(y);
    }
    f = to;
    f.erase(ss);
  }
  if (to.count(aim))
    puts("YES");
  else
    puts("NO");
}

```


### Prompt

Develop a solution in cpp to the problem described below:

In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.

Lesha knows that today he can study for at most a hours, and he will have b hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number k in k hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.

Thus, the student has to fully read several lecture notes today, spending at most a hours in total, and fully read several lecture notes tomorrow, spending at most b hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and which — in the second?

Input

The only line of input contains two integers a and b (0 ≤ a, b ≤ 10^{9}) — the number of hours Lesha has today and the number of hours Lesha has tomorrow.

Output

In the first line print a single integer n (0 ≤ n ≤ a) — the number of lecture notes Lesha has to read in the first day. In the second line print n distinct integers p_1, p_2, …, p_n (1 ≤ p_i ≤ a), the sum of all p_i should not exceed a.

In the third line print a single integer m (0 ≤ m ≤ b) — the number of lecture notes Lesha has to read in the second day. In the fourth line print m distinct integers q_1, q_2, …, q_m (1 ≤ q_i ≤ b), the sum of all q_i should not exceed b.

All integers p_i and q_i should be distinct. The sum n + m should be largest possible.

Examples

Input

3 3

Output

1
3
2
2 1

Input

9 12

Output

2
3 6
4
1 2 4 5

Note

In the first example Lesha can read the third note in 3 hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending 3 hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.

In the second example Lesha should read the third and the sixth notes in the first day, spending 9 hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending 12 hours in total.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int inf = 1000000000;
const int maxn = 300005;
const int maxa = 300005;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  if (b < 0) return -1;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int INF = 10000000;
clock_t start, finish;
long long pre[maxn];
bool vis[maxn];
int main() {
  int n, m, t;
  for (long long i = 0; i < maxn; i++) pre[i] = i * (i + 1) / 2;
  cin >> n >> m;
  for (int i = 0; i < maxn; i++) {
    if (pre[i] > n + m) {
      break;
    }
    t = i;
  }
  int now = t;
  vector<int> vec;
  while (n) {
    int h = min(now, n);
    n -= h;
    vec.push_back(h);
    vis[h] = true;
    now = h - 1;
    if (now == 0) break;
  }
  cout << vec.size() << endl;
  for (auto k : vec) cout << k << " ";
  cout << endl;
  vec.clear();
  for (int i = 1; i <= t; i++)
    if (!vis[i]) vec.push_back(i);
  cout << vec.size() << endl;
  for (auto k : vec) cout << k << " ";
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

You are given an integer sequence of length N, a_1,a_2,...,a_N.

For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing.

After these operations, you select an integer X and count the number of i such that a_i=X.

Maximize this count by making optimal choices.

Constraints

* 1≤N≤10^5
* 0≤a_i<10^5 (1≤i≤N)
* a_i is an integer.

Input

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

N
a_1 a_2 .. a_N

Output

Print the maximum possible number of i such that a_i=X.

Examples

Input

7
3 1 4 1 5 9 2

Output

4

Input

10
0 1 2 3 4 5 6 7 8 9

Output

3

Input

1
99999

Output

1

### Response

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

const int N = 100010;

int n;
int cnt[N];

int main(){
	scanf("%d", &n);
	for (int i = 0, x; i < n; ++ i){
		scanf("%d", &x);
		++ cnt[x];
	}
	int ans = 0;
	for (int i = 1; i < N - 1; ++ i){
		ans = std::max(ans, cnt[i - 1] + cnt[i] + cnt[i + 1]);
	}
	return printf("%d\n", ans), 0;
}
```


### Prompt

Generate a Cpp solution to the following problem:

Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer n and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer a and subtract it from n such that:

  * 1 ≤ a ≤ n.
  * If it's Mahmoud's turn, a has to be even, but if it's Ehab's turn, a has to be odd.

If the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally?

Input

The only line contains an integer n (1 ≤ n ≤ 109), the number at the beginning of the game.

Output

Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise.

Examples

Input

1

Output

Ehab

Input

2

Output

Mahmoud

Note

In the first sample, Mahmoud can't choose any integer a initially because there is no positive even integer less than or equal to 1 so Ehab wins.

In the second sample, Mahmoud has to choose a = 2 and subtract it from n. It's Ehab's turn and n = 0. There is no positive odd integer less than or equal to 0 so Mahmoud wins.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n % 2 == 0)
    cout << "Mahmoud";
  else
    cout << "Ehab";
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

You are given n numbers a_1, a_2, …, a_n. Is it possible to arrange them in a circle in such a way that every number is strictly less than the sum of its neighbors?

For example, for the array [1, 4, 5, 6, 7, 8], the arrangement on the left is valid, while arrangement on the right is not, as 5≥ 4 + 1 and 8> 1 + 6.

<image>

Input

The first line contains a single integer n (3≤ n ≤ 10^5) — the number of numbers.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) — the numbers. The given numbers are not necessarily distinct (i.e. duplicates are allowed).

Output

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

If there is a solution, output "YES" in the first line. In the second line output n numbers — elements of the array in the order they will stay in the circle. The first and the last element you output are considered neighbors in the circle. If there are multiple solutions, output any of them. You can print the circle starting with any element.

Examples

Input

3
2 4 3

Output

YES
4 2 3

Input

5
1 2 3 4 4

Output

YES
4 4 2 1 3

Input

3
13 8 5

Output

NO

Input

4
1 10 100 1000

Output

NO

Note

One of the possible arrangements is shown in the first example:

4< 2 + 3;

2 < 4 + 3;

3< 4 + 2.

One of the possible arrangements is shown in the second example.

No matter how we arrange 13, 8, 5 in a circle in the third example, 13 will have 8 and 5 as neighbors, but 13≥ 8 + 5.

There is no solution in the fourth example.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void swap(int *a, int *b) {
  int t = *a;
  *a = *b;
  *b = t;
}
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  if (arr[n - 1] >= arr[n - 2] + arr[0]) {
    swap(&arr[n - 1], &arr[n - 2]);
    int i = n - 2;
    while (i > 0 && (arr[i] >= (arr[i - 1] + arr[i + 1]))) {
      swap(&arr[i], &arr[i - 1]);
      i--;
    }
    if (i == 0 && arr[0] >= (arr[1] + arr[n - 1])) {
      cout << "NO";
      return 0;
    }
  }
  if (arr[0] >= (arr[n - 1] + arr[1])) {
    cout << "NO";
    return 0;
  }
  cout << "YES\n";
  for (int i = 0; i < n; i++) cout << arr[i] << " ";
}

```


### Prompt

Please formulate a CPP solution to the following problem:

N problems have been chosen by the judges, now it's time to assign scores to them!

Problem i must get an integer score A_i between 1 and N, inclusive. The problems have already been sorted by difficulty: A_1 \le A_2 \le \ldots \le A_N must hold. Different problems can have the same score, though.

Being an ICPC fan, you want contestants who solve more problems to be ranked higher. That's why, for any k (1 \le k \le N-1), you want the sum of scores of any k problems to be strictly less than the sum of scores of any k+1 problems.

How many ways to assign scores do you have? Find this number modulo the given prime M.

Constraints

* 2 \leq N \leq 5000
* 9 \times 10^8 < M < 10^9
* M is a prime.
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of ways to assign scores to the problems, modulo M.

Examples

Input

2 998244353

Output

3

Input

3 998244353

Output

7

Input

6 966666661

Output

66

Input

96 925309799

Output

83779

### Response

```cpp
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

int main()
{
  ll n, m;
  cin >> n >> m;

  vector<ll> coef(n - 1);
  coef[0] = 1;
  int l = 1, r = n - 2;
  while (l <= r) {
    coef[l] = coef[l - 1] + 1;
    coef[r] = coef[l];
    l++;
    r--;
  }

  vector<vector<ll>> dp(n, vector<ll>(n));

  dp[0][0] = 1;
  for (int count = 1; count <= n - 1; ++count) {
    for (int prevValue = 0; prevValue < n; ++prevValue) {
      for (int curValue = 0; curValue < n; ++curValue) {
        int newValue = prevValue + coef[count - 1] * curValue;
        if (newValue >= n) {
          break;
        }
        dp[count][newValue] += dp[count - 1][prevValue];
      }
    }
    for (int value = 0; value < n; ++value) {
      dp[count][value] %= m;
    }
  }

  ll result = 0;
  for (int value = 0; value < n; ++value) {
    result += (n - value) * dp[n - 1][value];
    result %= m;
  }

  cout << result << endl;

  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

We start with a permutation a_1, a_2, …, a_n and with an empty array b. We apply the following operation k times.

On the i-th iteration, we select an index t_i (1 ≤ t_i ≤ n-i+1), remove a_{t_i} from the array, and append one of the numbers a_{t_i-1} or a_{t_i+1} (if t_i-1 or t_i+1 are within the array bounds) to the right end of the array b. Then we move elements a_{t_i+1}, …, a_n to the left in order to fill in the empty space.

You are given the initial permutation a_1, a_2, …, a_n and the resulting array b_1, b_2, …, b_k. All elements of an array b are distinct. Calculate the number of possible sequences of indices t_1, t_2, …, t_k modulo 998 244 353.

Input

Each test contains multiple test cases. The first line contains an integer t (1 ≤ t ≤ 100 000), denoting the number of test cases, followed by a description of the test cases.

The first line of each test case contains two integers n, k (1 ≤ k < n ≤ 200 000): sizes of arrays a and b.

The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n): elements of a. All elements of a are distinct.

The third line of each test case contains k integers b_1, b_2, …, b_k (1 ≤ b_i ≤ n): elements of b. All elements of b are distinct.

The sum of all n among all test cases is guaranteed to not exceed 200 000.

Output

For each test case print one integer: the number of possible sequences modulo 998 244 353.

Example

Input

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

Output

2
0
4

Note

\require{cancel}

Let's denote as a_1 a_2 … \cancel{a_i} \underline{a_{i+1}} … a_n → a_1 a_2 … a_{i-1} a_{i+1} … a_{n-1} an operation over an element with index i: removal of element a_i from array a and appending element a_{i+1} to array b.

In the first example test, the following two options can be used to produce the given array b:

  * 1 2 \underline{3} \cancel{4} 5 → 1 \underline{2} \cancel{3} 5 → 1 \cancel{2} \underline{5} → 1 2; (t_1, t_2, t_3) = (4, 3, 2);
  * 1 2 \underline{3} \cancel{4} 5 → \cancel{1} \underline{2} 3 5 → 2 \cancel{3} \underline{5} → 1 5; (t_1, t_2, t_3) = (4, 1, 2).

In the second example test, it is impossible to achieve the given array no matter the operations used. That's because, on the first application, we removed the element next to 4, namely number 3, which means that it couldn't be added to array b on the second step.

In the third example test, there are four options to achieve the given array b:

  * 1 4 \cancel{7} \underline{3} 6 2 5 → 1 4 3 \cancel{6} \underline{2} 5 → \cancel{1} \underline{4} 3 2 5 → 4 3 \cancel{2} \underline{5} → 4 3 5;
  * 1 4 \cancel{7} \underline{3} 6 2 5 → 1 4 3 \cancel{6} \underline{2} 5 → 1 \underline{4} \cancel{3} 2 5 → 1 4 \cancel{2} \underline{5} → 1 4 5;
  * 1 4 7 \underline{3} \cancel{6} 2 5 → 1 4 7 \cancel{3} \underline{2} 5 → \cancel{1} \underline{4} 7 2 5 → 4 7 \cancel{2} \underline{5} → 4 7 5;
  * 1 4 7 \underline{3} \cancel{6} 2 5 → 1 4 7 \cancel{3} \underline{2} 5 → 1 \underline{4} \cancel{7} 2 5 → 1 4 \cancel{2} \underline{5} → 1 4 5;

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct B {
  int val, pos;
};
bool comp(B c, B d) { return ((c.pos) < (d.pos)); }
long long MOD = 998244353;
int main() {
  int t;
  cin >> t;
  map<int, int> mp;
  while (t--) {
    int n, k;
    scanf("%d%d", &n, &k);
    int a;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a);
      mp[a] = i;
    }
    long long res = 1;
    B b[200042];
    int q[200042];
    bool right[200042] = {false};
    bool left[200042] = {false};
    int right1[200042];
    int left1[200042];
    b[0].val = 0;
    b[0].pos = 0;
    b[k + 1].val = 0;
    b[k + 1].pos = n + 1;
    for (int i = 1; i <= k; i++) {
      scanf("%d", &b[i].val);
      b[i].pos = mp[b[i].val];
      q[i] = b[i].val;
    }
    sort(b, b + k + 2, comp);
    for (int i = 1; i <= k; i++) {
      if (b[i].pos != (b[i - 1].pos + 1)) left[b[i].pos] = true;
      if ((b[i].pos + 1) != (b[i + 1].pos)) right[b[i].pos] = true;
      left1[b[i].pos] = b[i - 1].pos;
      right1[b[i].pos] = b[i + 1].pos;
    }
    for (int i = 1; i <= k; i++) {
      if ((!left[mp[q[i]]]) && ((!right[mp[q[i]]]))) {
        res = 0;
        break;
      } else {
        if (left[mp[q[i]]] && right[mp[q[i]]]) {
          res = res * 2;
          res = res % (MOD);
        }
        right[left1[mp[q[i]]]] = true;
        left[right1[mp[q[i]]]] = true;
      }
    }
    printf("%ld\n", res);
  }
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Gildong recently learned how to find the [longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) (LIS) in O(nlog{n}) time for a sequence of length n. He wants to test himself if he can implement it correctly, but he couldn't find any online judges that would do it (even though there are actually many of them). So instead he's going to make a quiz for you about making permutations of n distinct integers between 1 and n, inclusive, to test his code with your output.

The quiz is as follows.

Gildong provides a string of length n-1, consisting of characters '<' and '>' only. The i-th (1-indexed) character is the comparison result between the i-th element and the i+1-st element of the sequence. If the i-th character of the string is '<', then the i-th element of the sequence is less than the i+1-st element. If the i-th character of the string is '>', then the i-th element of the sequence is greater than the i+1-st element.

He wants you to find two possible sequences (not necessarily distinct) consisting of n distinct integers between 1 and n, inclusive, each satisfying the comparison results, where the length of the LIS of the first sequence is minimum possible, and the length of the LIS of the second sequence is maximum possible.

Input

Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4).

Each test case contains exactly one line, consisting of an integer and a string consisting of characters '<' and '>' only. The integer is n (2 ≤ n ≤ 2 ⋅ 10^5), the length of the permutation you need to find. The string is the comparison results explained in the description. The length of the string is n-1.

It is guaranteed that the sum of all n in all test cases doesn't exceed 2 ⋅ 10^5.

Output

For each test case, print two lines with n integers each. The first line is the sequence with the minimum length of the LIS, and the second line is the sequence with the maximum length of the LIS. If there are multiple answers, print any one of them. Each sequence should contain all integers between 1 and n, inclusive, and should satisfy the comparison results.

It can be shown that at least one answer always exists.

Example

Input

3
3 <<
7 >><>><
5 >>><

Output

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

Note

In the first case, 1 2 3 is the only possible answer.

In the second case, the shortest length of the LIS is 2, and the longest length of the LIS is 3. In the example of the maximum LIS sequence, 4 '3' 1 7 '5' 2 '6' can be one of the possible LIS.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200000;
int ans[MAX_N + 5];
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    int n, i, j;
    string s;
    cin >> n >> s;
    int num = n, last = 0;
    for (i = 0; i < n; i++) {
      if (i == n - 1 || s[i] == '>') {
        for (j = i; j >= last; j--) ans[j] = num--;
        last = i + 1;
      }
    }
    for (i = 0; i < n; i++) cout << ans[i] << (i == n - 1 ? '\n' : ' ');
    num = 1, last = 0;
    for (i = 0; i < n; i++) {
      if (i == n - 1 || s[i] == '<') {
        for (j = i; j >= last; j--) ans[j] = num++;
        last = i + 1;
      }
    }
    for (i = 0; i < n; i++) cout << ans[i] << (i == n - 1 ? '\n' : ' ');
  }
}

```


### Prompt

Create a solution in Cpp for the following problem:

You are given a string s and should process m queries. Each query is described by two 1-based indices li, ri and integer ki. It means that you should cyclically shift the substring s[li... ri] ki times. The queries should be processed one after another in the order they are given.

One operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right.

For example, if the string s is abacaba and the query is l1 = 3, r1 = 6, k1 = 1 then the answer is abbacaa. If after that we would process the query l2 = 1, r2 = 4, k2 = 2 then we would get the string baabcaa.

Input

The first line of the input contains the string s (1 ≤ |s| ≤ 10 000) in its initial state, where |s| stands for the length of s. It contains only lowercase English letters.

Second line contains a single integer m (1 ≤ m ≤ 300) — the number of queries.

The i-th of the next m lines contains three integers li, ri and ki (1 ≤ li ≤ ri ≤ |s|, 1 ≤ ki ≤ 1 000 000) — the description of the i-th query.

Output

Print the resulting string s after processing all m queries.

Examples

Input

abacaba
2
3 6 1
1 4 2

Output

baabcaa

Note

The sample is described in problem statement.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 10;
const int INF = (int)1e9;
const int mod = (int)1e9 + 7;
const long long LLINF = (long long)1e18;
string s;
int main() {
  cin >> s;
  int m;
  cin >> m;
  while (m--) {
    int l, r, k;
    cin >> l >> r >> k;
    --l;
    --r;
    k %= (r - l + 1);
    string t = s.substr(0, l) + s.substr(r - k + 1, k) +
               s.substr(l, r - l + 1 - k) + s.substr(r + 1, s.size() - r);
    s = t;
  }
  cout << s;
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

King of Berland Berl IV has recently died. Hail Berl V! As a sign of the highest achievements of the deceased king the new king decided to build a mausoleum with Berl IV's body on the main square of the capital.

The mausoleum will be constructed from 2n blocks, each of them has the shape of a cuboid. Each block has the bottom base of a 1 × 1 meter square. Among the blocks, exactly two of them have the height of one meter, exactly two have the height of two meters, ..., exactly two have the height of n meters.

The blocks are arranged in a row without spacing one after the other. Of course, not every arrangement of blocks has the form of a mausoleum. In order to make the given arrangement in the form of the mausoleum, it is necessary that when you pass along the mausoleum, from one end to the other, the heights of the blocks first were non-decreasing (i.e., increasing or remained the same), and then — non-increasing (decrease or remained unchanged). It is possible that any of these two areas will be omitted. For example, the following sequences of block height meet this requirement:

  * [1, 2, 2, 3, 4, 4, 3, 1];
  * [1, 1];
  * [2, 2, 1, 1];
  * [1, 2, 3, 3, 2, 1].

Suddenly, k more requirements appeared. Each of the requirements has the form: "h[xi] signi h[yi]", where h[t] is the height of the t-th block, and a signi is one of the five possible signs: '=' (equals), '<' (less than), '>' (more than), '<=' (less than or equals), '>=' (more than or equals). Thus, each of the k additional requirements is given by a pair of indexes xi, yi (1 ≤ xi, yi ≤ 2n) and sign signi.

Find the number of possible ways to rearrange the blocks so that both the requirement about the shape of the mausoleum (see paragraph 3) and the k additional requirements were met.

Input

The first line of the input contains integers n and k (1 ≤ n ≤ 35, 0 ≤ k ≤ 100) — the number of pairs of blocks and the number of additional requirements.

Next k lines contain listed additional requirements, one per line in the format "xi signi yi" (1 ≤ xi, yi ≤ 2n), and the sign is on of the list of the five possible signs.

Output

Print the sought number of ways.

Examples

Input

3 0

Output

9

Input

3 1
2 > 3

Output

1

Input

4 1
3 = 6

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int _ = 105;
inline int read() {
  char ch = '!';
  int z = 1, num = 0;
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') z = -1, ch = getchar();
  while (ch <= '9' && ch >= '0')
    num = (num << 3) + (num << 1) + ch - '0', ch = getchar();
  return z * num;
}
long long n, k, f[_][_];
vector<int> dy[_], ly[_], ld[_];
void init() {
  n = read();
  k = read();
  char s[10];
  int x, y;
  while (k--) {
    scanf("%d%s%d", &x, s, &y);
    if (s[0] == '=')
      dy[x].push_back(y), dy[y].push_back(x);
    else {
      if (s[0] == '<') swap(x, y);
      if (s[1] == '=')
        ly[x].push_back(y);
      else
        ld[x].push_back(y);
    }
  }
}
bool check(int a, int b, int l, int r) {
  for (int i = 0; i < ld[a].size(); ++i)
    if ((ld[a][i] >= l && ld[a][i] <= r) || ld[a][i] == b) return 0;
  for (int i = 0; i < ly[a].size(); ++i)
    if (ly[a][i] >= l && ly[a][i] <= r) return 0;
  for (int i = 0; i < dy[a].size(); ++i)
    if (dy[a][i] >= l && dy[a][i] <= r) return 0;
  return 1;
}
bool pd(int l, int r, int a, int b) {
  return check(l, r, a, b) && check(r, l, a, b);
}
int main() {
  init();
  int m = n << 1;
  for (int i = 1; i < m; ++i)
    if (pd(i, i + 1, 0, 0)) f[i][i + 1] = 1;
  for (int len = 2; len <= m; len += 2) {
    for (int l = 1; l + len - 1 <= m; ++l) {
      int r = l + len - 1;
      if (pd(l, r, l + 1, r - 1)) f[l][r] += f[l + 1][r - 1];
      if (pd(l, l + 1, l + 2, r)) f[l][r] += f[l + 2][r];
      if (pd(r - 1, r, l, r - 2)) f[l][r] += f[l][r - 2];
    }
  }
  printf("%lld\n", f[1][m]);
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

This is an interactive problem.

Jury has hidden a permutation p of integers from 0 to n - 1. You know only the length n. Remind that in permutation all integers are distinct.

Let b be the inverse permutation for p, i.e. pbi = i for all i. The only thing you can do is to ask xor of elements pi and bj, printing two indices i and j (not necessarily distinct). As a result of the query with indices i and j you'll get the value <image>, where <image> denotes the xor operation. You can find the description of xor operation in notes.

Note that some permutations can remain indistinguishable from the hidden one, even if you make all possible n2 queries. You have to compute the number of permutations indistinguishable from the hidden one, and print one of such permutations, making no more than 2n queries.

The hidden permutation does not depend on your queries.

Input

The first line contains single integer n (1 ≤ n ≤ 5000) — the length of the hidden permutation. You should read this integer first.

Output

When your program is ready to print the answer, print three lines.

In the first line print "!".

In the second line print single integer answers_cnt — the number of permutations indistinguishable from the hidden one, including the hidden one.

In the third line print n integers p0, p1, ..., pn - 1 (0 ≤ pi < n, all pi should be distinct) — one of the permutations indistinguishable from the hidden one.

Your program should terminate after printing the answer.

Interaction

To ask about xor of two elements, print a string "? i j", where i and j — are integers from 0 to n - 1 — the index of the permutation element and the index of the inverse permutation element you want to know the xor-sum for. After that print a line break and make flush operation.

After printing the query your program should read single integer — the value of <image>.

For a permutation of length n your program should make no more than 2n queries about xor-sum. Note that printing answer doesn't count as a query. Note that you can't ask more than 2n questions. If you ask more than 2n questions or at least one incorrect question, your solution will get "Wrong answer".

If at some moment your program reads -1 as an answer, it should immediately exit (for example, by calling exit(0)). You will get "Wrong answer" in this case, it means that you asked more than 2n questions, or asked an invalid question. If you ignore this, you can get other verdicts since your program will continue to read from a closed stream.

Your solution will get "Idleness Limit Exceeded", if you don't print anything or forget to flush the output, including for the final answer .

To flush you can use (just after printing line break):

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

Hacking

For hacking use the following format:

n

p0 p1 ... pn - 1

Contestant programs will not be able to see this input.

Examples

Input

3
0
0
3
2
3
2

Output

? 0 0
? 1 1
? 1 2
? 0 2
? 2 1
? 2 0
!
1
0 1 2

Input

4
2
3
2
0
2
3
2
0

Output

? 0 1
? 1 2
? 2 3
? 3 3
? 3 2
? 2 1
? 1 0
? 0 0
!
2
3 1 2 0

Note

xor operation, or bitwise exclusive OR, is an operation performed over two integers, in which the i-th digit in binary representation of the result is equal to 1 if and only if exactly one of the two integers has the i-th digit in binary representation equal to 1. For more information, see [here](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).

In the first example p = [0, 1, 2], thus b = [0, 1, 2], the values <image> are correct for the given i, j. There are no other permutations that give the same answers for the given queries.

The answers for the queries are:

  * <image>,
  * <image>,
  * <image>,
  * <image>,
  * <image>,
  * <image>.

In the second example p = [3, 1, 2, 0], and b = [3, 1, 2, 0], the values <image> match for all pairs i, j. But there is one more suitable permutation p = [0, 2, 1, 3], b = [0, 2, 1, 3] that matches all n2 possible queries as well. All other permutations do not match even the shown queries.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long readi() {
  long long input = 0;
  char c = ' ';
  while (c < '-') {
    c = getchar();
  }
  bool negative = false;
  if (c == '-') {
    negative = true;
    c = getchar();
  }
  while (c >= '0') {
    input = 10 * input + (c - '0');
    c = getchar();
  }
  if (negative) {
    input = -input;
  }
  return input;
}
void printi(long long output) {
  if (output == 0) {
    putchar('0');
    return;
  }
  if (output < 0) {
    putchar('-');
    output = -output;
  }
  int aout[20];
  int ilen = 0;
  while (output) {
    aout[ilen] = ((output % 10));
    output /= 10;
    ilen++;
  }
  for (int i = ilen - 1; i >= 0; i--) {
    putchar(aout[i] + '0');
  }
  return;
}
string reads() {
  string input = "";
  char c = ' ';
  while (c <= ' ') {
    c = getchar();
  }
  while (c > ' ') {
    input += c;
    c = getchar();
  }
  return input;
}
void prints(string output) {
  for (int i = 0; i < output.length(); i++) {
    putchar(output[i]);
  }
  return;
}
int N;
int val[5010], pos[5010];
int tval[5010], tpos[5010];
int can[5010];
int ans;
int query(int x, int y) {
  int input;
  cout << "? " << x << ' ' << y << '\n';
  fflush(stdout);
  cin >> input;
  if (input == -1) {
    exit(0);
  }
  return input;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  srand(time(NULL));
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin >> N;
  for (int i = 0; i < N; i++) {
    val[i] = query(i, 0);
  }
  for (int i = 0; i < N; i++) {
    pos[i] = query(0, i);
  }
  for (int i = 0; i < N; i++) {
    bool flag = true;
    for (int j = 0; j < N; j++) {
      tval[j] = (i xor val[j]);
      if (tval[j] >= N) {
        flag = false;
      }
    }
    if (!flag) {
      continue;
    }
    for (int j = 0; j < N; j++) {
      tpos[tval[j]] = j;
    }
    for (int j = 0; j < N; j++) {
      if ((tpos[0] xor tval[j]) != val[j]) {
        flag = false;
      }
      if ((tpos[j] xor tval[0]) != pos[j]) {
        flag = false;
      }
    }
    if (!flag) {
      continue;
    }
    if (flag) {
      ans++;
      for (int j = 0; j < N; j++) {
        can[j] = tval[j];
      }
    }
  }
  cout << "! " << ans << '\n' << can[0];
  for (int i = 1; i < N; i++) {
    cout << ' ' << can[i];
  }
  cout << '\n';
  return 0;
}

```


### Prompt

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

Furik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his problems, the one Furik gave to Rubik. And Rubik asks you to solve it.

There is integer n and array a, consisting of ten integers, indexed by numbers from 0 to 9. Your task is to count the number of positive integers with the following properties:

  * the number's length does not exceed n;
  * the number doesn't have leading zeroes;
  * digit i (0 ≤ i ≤ 9) occurs in the number at least a[i] times.

Input

The first line contains integer n (1 ≤ n ≤ 100). The next line contains 10 integers a[0], a[1], ..., a[9] (0 ≤ a[i] ≤ 100) — elements of array a. The numbers are separated by spaces.

Output

On a single line print the remainder of dividing the answer to the problem by 1000000007 (109 + 7).

Examples

Input

1
0 0 0 0 0 0 0 0 0 1

Output

1

Input

2
1 1 0 0 0 0 0 0 0 0

Output

1

Input

3
1 1 0 0 0 0 0 0 0 0

Output

36

Note

In the first sample number 9 meets the requirements.

In the second sample number 10 meets the requirements.

In the third sample numbers 10, 110, 210, 120, 103 meet the requirements. There are other suitable numbers, 36 in total.

### Response

```cpp
#include <bits/stdc++.h>
const int N = 110;
const int inf = 0x3f3f3f3f;
const long long mod = 1000000007ll;
using namespace std;
int n, a[110];
long long c[N][110];
void init() {
  c[0][0] = 1;
  for (int i = 1; i <= 100; i++) {
    c[i][0] = 1;
    for (int j = 1; j <= 100; j++)
      c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
  }
}
long long dp[11][N];
long long solve(int n, int a[]) {
  init();
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j <= n; j++) {
      if (dp[i][j] == 0) continue;
      for (int k = a[i + 1]; k + j <= n; k++)
        dp[i + 1][j + k] = (dp[i][j] * c[j + k][k] + dp[i + 1][j + k]) % mod;
    }
  }
  return dp[10][n];
}
int main() {
  int sum = 0;
  scanf("%d", &n);
  for (int i = 1; i <= 10; i++) scanf("%d", &a[i]), sum += a[i];
  long long ret = 0;
  for (int k = max(1, sum); k <= n; k++) {
    if (k == 1) {
      if (sum == 1)
        ret++;
      else
        ret += 9;
      continue;
    }
    for (int i = 2; i <= 10; i++) {
      int f = 1;
      if (a[i] == 0) f = 0;
      a[i] -= f;
      ret += solve(k - 1, a);
      ret %= mod;
      a[i] += f;
    }
  }
  cout << (ret % mod) << endl;
  return 0;
}

```


### Prompt

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

You are developing a robot that processes strings. When the robot is given a string t consisting of lowercase English letters, it processes the string by following the procedure below:

1. Let i be the smallest index such that t_i = t_{i + 1}. If such an index does not exist, terminate the procedure.
2. If t_i is `z`, remove t_i and t_{i + 1} from t. Otherwise, let c be the next letter of t_i in the English alphabet, and replace t_i and t_{i + 1} together with c, reducing the length of t by 1.
3. Go back to step 1.

For example, when the robot is given the string `axxxxza`, it will be processed as follows: `axxxxza` → `ayxxza` → `ayyza` → `azza` → `aa` → `b`.

You are given a string s consisting of lowercase English letters. Answer Q queries. The i-th query is as follows:

* Assume that the robot is given a substring of s that runs from the l_i-th character and up to the r_i-th character (inclusive). Will the string be empty after processing?

Constraints

* 1 ≤ |s| ≤ 5 × 10^5
* s consists of lowercase English letters.
* 1 ≤ Q ≤ 10^5
* 1 ≤ l_i ≤ r_i ≤ |s|

Input

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

s
Q
l_1 r_1
l_2 r_2
:
l_Q r_Q

Output

Print Q lines. The i-th line should contain the answer to the i-th query: `Yes` or `No`.

Examples

Input

axxxxza
2
1 7
2 6

Output

No
Yes

Input

aabcdefghijklmnopqrstuvwxyz
1
1 27

Output

Yes

Input

yzyyyzyzyyyz
8
1 6
7 12
1 12
6 11
1 1
1 3
4 9
3 8

Output

Yes
Yes
Yes
Yes
No
No
No
No

### Response

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

int main()
{
  static char s[500010];
  scanf("%s",s);
  int n=strlen(s);
  static int T[500010][30],S[500010][30];
  for(int i=0;i<=n;i++){
    for(int c=0;c<=26;c++){
      T[i][c]=-1;
    }
  }
  for(int c=0;c<26;c++){
    S[n][c]=-1;
  }
  for(int i=n-1;i>=0;i--){
    int p=s[i]-'a';
    T[i][p]=i+1;
    for(int c=p;c+1<=26&&S[T[i][c]][c]!=-1&&T[S[T[i][c]][c]][c]!=-1;c++){
      T[i][c+1]=T[S[T[i][c]][c]][c];
    }
    for(int c=0;c<p;c++){
      S[i][c]=(T[i][26]==-1?-1:S[T[i][26]][c]);
    }
    for(int c=p;c<26;c++){
      S[i][c]=i;
    }
  }
  static int db[500010][19];
  for(int i=0;i<=n;i++){
    for(int k=0;k<19;k++){
      db[i][k]=-1;
    }
  }
  for(int i=n;i>=0;i--){
    db[i][0]=T[i][26];
    int k=0;
    while(db[i][k]!=-1){
      //printf("%d %d %d\n",i,k,db[i][k]);
      db[i][k+1]=db[db[i][k]][k];
      k++;
    }
  }
  int q;
  scanf("%d",&q);
  while(q--){
    int l,r;
    scanf("%d%d",&l,&r);
    l--;
    while(l<r){
      int k=18;
      while(k>=0&&!(db[l][k]!=-1&&db[l][k]<=r)){
	k--;
      }
      //printf("%d %d\n",l,k);
      if(k==-1){
	break;
      }
      l=db[l][k];
    }
    puts(l==r?"Yes":"No");
  }
  return 0;
}

```


### Prompt

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

Boboniu gives you

  * r red balls,
  * g green balls,
  * b blue balls,
  * w white balls.

He allows you to do the following operation as many times as you want:

  * Pick a red ball, a green ball, and a blue ball and then change their color to white.

You should answer if it's possible to arrange all the balls into a palindrome after several (possibly zero) number of described operations.

Input

The first line contains one integer T (1≤ T≤ 100) denoting the number of test cases.

For each of the next T cases, the first line contains four integers r, g, b and w (0≤ r,g,b,w≤ 10^9).

Output

For each test case, print "Yes" if it's possible to arrange all the balls into a palindrome after doing several (possibly zero) number of described operations. Otherwise, print "No".

Example

Input

4
0 1 1 1
8 1 9 3
0 0 0 0
1000000000 1000000000 1000000000 1000000000

Output

No
Yes
Yes
Yes

Note

In the first test case, you're not able to do any operation and you can never arrange three balls of distinct colors into a palindrome.

In the second test case, after doing one operation, changing (8,1,9,3) to (7,0,8,6), one of those possible palindromes may be "rrrwwwbbbbrbbbbwwwrrr".

A palindrome is a word, phrase, or sequence that reads the same backwards as forwards. For example, "rggbwbggr", "b", "gg" are palindromes while "rgbb", "gbbgr" are not. Notice that an empty word, phrase, or sequence is palindrome.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 2e9 + 7, MOD2 = 998244353;
const int N = 2e5 + 2, MAXN = 50002;
const double eps = 2e-7;
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  long long f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f *= -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 20 + ch - 48;
    ch = getchar();
  }
  x *= f;
}
void solve() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int cnt = 0;
  if (a % 2) cnt++;
  if (b % 2) cnt++;
  if (c % 2) cnt++;
  if (d % 2) cnt++;
  if (cnt <= 1) {
    puts("Yes");
    return;
  }
  int q = min(a, min(b, c));
  q = min(q, 1);
  a -= q;
  b -= q;
  c -= q;
  d += 3 * q;
  cnt = 0;
  if (a % 2) cnt++;
  if (b % 2) cnt++;
  if (c % 2) cnt++;
  if (d % 2) cnt++;
  if (cnt <= 1) {
    puts("Yes");
  } else
    puts("No");
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

problem

At the JOI pasta shop, the recommended pasta for lunch and the set menu of freshly squeezed juice are popular. When ordering this set menu, choose one from each of the three pasta and two juices of the day. The price is the total price of pasta and juice minus 50 yen.

Given the price of pasta and juice for a day, create a program to find the minimum price for the set menu for that day.

output

Output the minimum price of the set menu for the day in one line.

Example

Input

800
700
900
198
330

Output

848

### Response

```cpp
#include<stdio.h>

int main(void)
{
	int a,b,i,x=-50;
	scanf("%d",&a);
	for(i=0;i<2;i++)
	{
		scanf("%d",&b);
		if(b<a)
			a=b;
	}
	x+=a;
	scanf("%d\n%d",&a,&b);
	if(b<a)
		printf("%d\n",x+=b);
	else
		printf("%d\n",x+=a);

  return 0;
}
```


### Prompt

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

You are given a tree (a connected undirected graph without cycles) of n vertices. Each of the n - 1 edges of the tree is colored in either black or red.

You are also given an integer k. Consider sequences of k vertices. Let's call a sequence [a_1, a_2, …, a_k] good if it satisfies the following criterion:

  * We will walk a path (possibly visiting same edge/vertex multiple times) on the tree, starting from a_1 and ending at a_k.
  * Start at a_1, then go to a_2 using the shortest path between a_1 and a_2, then go to a_3 in a similar way, and so on, until you travel the shortest path between a_{k-1} and a_k.
  * If you walked over at least one black edge during this process, then the sequence is good.

<image>

Consider the tree on the picture. If k=3 then the following sequences are good: [1, 4, 7], [5, 5, 3] and [2, 3, 7]. The following sequences are not good: [1, 4, 6], [5, 5, 5], [3, 7, 3].

There are n^k sequences of vertices, count how many of them are good. Since this number can be quite large, print it modulo 10^9+7.

Input

The first line contains two integers n and k (2 ≤ n ≤ 10^5, 2 ≤ k ≤ 100), the size of the tree and the length of the vertex sequence.

Each of the next n - 1 lines contains three integers u_i, v_i and x_i (1 ≤ u_i, v_i ≤ n, x_i ∈ \{0, 1\}), where u_i and v_i denote the endpoints of the corresponding edge and x_i is the color of this edge (0 denotes red edge and 1 denotes black edge).

Output

Print the number of good sequences modulo 10^9 + 7.

Examples

Input

4 4
1 2 1
2 3 1
3 4 1

Output

252

Input

4 6
1 2 0
1 3 0
1 4 0

Output

0

Input

3 5
1 2 1
2 3 0

Output

210

Note

In the first example, all sequences (4^4) of length 4 except the following are good:

  * [1, 1, 1, 1]
  * [2, 2, 2, 2]
  * [3, 3, 3, 3]
  * [4, 4, 4, 4]

In the second example, all edges are red, hence there aren't any good sequences.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 7;
long long MOD = 1000000007;
string yes = "YES\n";
string no = "NO\n";
bool visited[MAX];
long long n, k;
long long pow(long long a, long long b, long long m) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans;
}
void dfs(long long i, vector<long long> a[], long long &size) {
  visited[i] = true;
  size++;
  for (auto itr = a[i].begin(); itr != a[i].end(); itr++) {
    if (!visited[*itr]) dfs(*itr, a, size);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  vector<long long> a[n];
  for (long long i = 0; i < n - 1; i++) {
    long long u, v, x;
    cin >> u >> v >> x;
    u--;
    v--;
    if (!x) {
      a[u].push_back(v);
      a[v].push_back(u);
    }
  }
  long long ans = 0;
  memset(visited, false, sizeof(visited));
  for (long long i = 0; i < n; i++) {
    if (!visited[i]) {
      long long size = 0;
      dfs(i, a, size);
      ans += pow(size, k, MOD);
      ans = ans % MOD;
    }
  }
  ans = (pow(n, k, MOD) - ans) % MOD;
  if (ans < 0) ans = (MOD + ans) % MOD;
  cout << ans << "\n";
}

```


### Prompt

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

You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right.

To cyclically shift a table row one cell to the right means to move the value of each cell, except for the last one, to the right neighboring cell, and to move the value of the last cell to the first cell. A cyclical shift of a row to the left is performed similarly, but in the other direction. For example, if we cyclically shift a row "00110" one cell to the right, we get a row "00011", but if we shift a row "00110" one cell to the left, we get a row "01100".

Determine the minimum number of moves needed to make some table column consist only of numbers 1.

Input

The first line contains two space-separated integers: n (1 ≤ n ≤ 100) — the number of rows in the table and m (1 ≤ m ≤ 104) — the number of columns in the table. Then n lines follow, each of them contains m characters "0" or "1": the j-th character of the i-th line describes the contents of the cell in the i-th row and in the j-th column of the table.

It is guaranteed that the description of the table contains no other characters besides "0" and "1".

Output

Print a single number: the minimum number of moves needed to get only numbers 1 in some column of the table. If this is impossible, print -1.

Examples

Input

3 6
101010
000100
100000

Output

3

Input

2 3
111
000

Output

-1

Note

In the first sample one way to achieve the goal with the least number of moves is as follows: cyclically shift the second row to the right once, then shift the third row to the left twice. Then the table column before the last one will contain only 1s.

In the second sample one can't shift the rows to get a column containing only 1s.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  char a[n + 1][m + 2];
  int left[n + 1][m + 1], right[n + 1][m + 1];
  for (int i = 1; i <= n; i++) scanf("%s", a[i]);
  int found = 1;
  for (int i = 1; i <= n; i++) {
    int first = -1, last = -1;
    bool firsttime = true;
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '1' && firsttime) {
        first = j;
        firsttime = false;
      }
      if (a[i][j] == '1') last = j;
    }
    if (first == -1) {
      found = -1;
      break;
    }
    if (a[i][0] == '0')
      left[i][0] = m - last;
    else
      left[i][0] = 0;
    if (a[i][m - 1] == '0')
      right[i][m - 1] = first + 1;
    else
      right[i][m - 1] = 0;
    for (int j = 1; j < m; j++) {
      if (a[i][j] == '0')
        left[i][j] = left[i][j - 1] + 1;
      else
        left[i][j] = 0;
    }
    for (int j = m - 2; j >= 0; j--) {
      if (a[i][j] == '0')
        right[i][j] = right[i][j + 1] + 1;
      else
        right[i][j] = 0;
    }
  }
  if (found == -1) {
    printf("-1\n");
  } else {
    int min = INT_MAX;
    for (int i = 0; i < m; i++) {
      int count = 0;
      for (int j = 1; j <= n; j++) {
        if (left[j][i] < right[j][i])
          count += left[j][i];
        else
          count += right[j][i];
      }
      if (min > count) min = count;
    }
    printf("%d\n", min);
  }
  return 0;
}

```