### Prompt

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

A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed).

Let's consider empty cells are denoted by '.', then the following figures are stars:

<image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3.

You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes.

In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars.

Input

The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid.

The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only.

Output

If it is impossible to draw the given grid using stars only, print "-1".

Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid.

Examples

Input

6 8
....*...
...**...
..*****.
...**...
....*...
........

Output

3
3 4 1
3 5 2
3 5 1

Input

5 5
.*...
****.
.****
..**.
.....

Output

3
2 2 1
3 3 1
3 4 1

Input

5 5
.*...
***..
.*...
.*...
.....

Output

-1

Input

3 3
*.*
.*.
*.*

Output

-1

Note

In the first example the output

    2
    3 4 1
    3 5 2

is also correct.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int leftRight[1005][1005], topDown[1005][1005];
int rightLeft[1005][1005], bottomUp[1005][1005];
int leftRightSum[1005][1005], topDownSum[1005][1005];
string grid[1005];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> grid[i];
  for (int i = 0; i < n; i++) {
    int left = -1;
    for (int j = 0; j < m; j++) {
      if (grid[i][j] == '*')
        leftRight[i][j] = left;
      else
        left = j;
    }
  }
  for (int i = 0; i < n; i++) {
    int right = m;
    for (int j = m - 1; j >= 0; j--) {
      if (grid[i][j] == '*')
        rightLeft[i][j] = right;
      else
        right = j;
    }
  }
  for (int i = 0; i < m; i++) {
    int top = -1;
    for (int j = 0; j < n; j++) {
      if (grid[j][i] == '*')
        topDown[j][i] = top;
      else
        top = j;
    }
  }
  for (int i = 0; i < m; i++) {
    int bottom = n;
    for (int j = n - 1; j >= 0; j--) {
      if (grid[j][i] == '*')
        bottomUp[j][i] = bottom;
      else
        bottom = j;
    }
  }
  vector<int> is, js, sij;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] == '*') {
        int a = i - topDown[i][j] - 1;
        int b = bottomUp[i][j] - i - 1;
        int c = j - leftRight[i][j] - 1;
        int d = rightLeft[i][j] - j - 1;
        int sizeij = min(a, min(b, min(c, d)));
        if (sizeij > 0) {
          leftRightSum[i][j - sizeij] += 1;
          leftRightSum[i][j + sizeij + 1] -= 1;
          topDownSum[i - sizeij][j] += 1;
          topDownSum[i + sizeij + 1][j] -= 1;
          is.push_back(i + 1);
          js.push_back(j + 1);
          sij.push_back(sizeij);
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (j > 0)
        leftRightSum[i][j] = leftRightSum[i][j] + leftRightSum[i][j - 1];
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      if (i > 0) topDownSum[i][j] = topDownSum[i][j] + topDownSum[i - 1][j];
    }
  }
  bool isPossible = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] == '*') {
        if (topDownSum[i][j] < 1 && leftRightSum[i][j] < 1) isPossible = false;
      } else {
        if (topDownSum[i][j] != 0 || leftRightSum[i][j] != 0)
          isPossible = false;
      }
    }
  }
  if (isPossible) {
    cout << is.size() << "\n";
    for (int i = 0; i < is.size(); i++) {
      cout << is[i] << " " << js[i] << " " << sij[i] << "\n";
    }
  } else {
    cout << "-1\n";
  }
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Lena is a programmer. She got a task to solve at work.

There is an empty set of pairs of integers and n queries to process. Each query is one of three types:

  1. Add a pair (a, b) to the set.
  2. Remove a pair added in the query number i. All queries are numbered with integers from 1 to n.
  3. For a given integer q find the maximal value x·q + y over all pairs (x, y) from the set.

Help Lena to process the queries.

Input

The first line of input contains integer n (1 ≤ n ≤ 3·105) — the number of queries.

Each of the next n lines starts with integer t (1 ≤ t ≤ 3) — the type of the query.

A pair of integers a and b ( - 109 ≤ a, b ≤ 109) follows in the query of the first type.

An integer i (1 ≤ i ≤ n) follows in the query of the second type. It is guaranteed that i is less than the number of the query, the query number i has the first type and the pair from the i-th query is not already removed.

An integer q ( - 109 ≤ q ≤ 109) follows in the query of the third type.

Output

For the queries of the third type print on a separate line the desired maximal value of x·q + y.

If there are no pairs in the set print "EMPTY SET".

Example

Input

7
3 1
1 2 3
3 1
1 -1 100
3 1
2 4
3 1

Output

EMPTY SET
5
99
5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T in() {
  char ch;
  T n = 0;
  bool ng = false;
  while (1) {
    ch = getchar();
    if (ch == '-') {
      ng = true;
      ch = getchar();
      break;
    }
    if (ch >= '0' && ch <= '9') break;
  }
  while (1) {
    n = n * 10 + (ch - '0');
    ch = getchar();
    if (ch < '0' || ch > '9') break;
  }
  return (ng ? -n : n);
}
template <typename T>
inline T POW(T B, T P) {
  if (P == 0) return 1;
  if (P & 1)
    return B * POW(B, P - 1);
  else
    return (POW(B, P / 2) * POW(B, P / 2));
}
template <typename T>
inline T Gcd(T a, T b) {
  if (a < 0) return Gcd(-a, b);
  if (b < 0) return Gcd(a, -b);
  return (b == 0) ? a : Gcd(b, a % b);
}
template <typename T>
inline T Lcm(T a, T b) {
  if (a < 0) return Lcm(-a, b);
  if (b < 0) return Lcm(a, -b);
  return a * (b / Gcd(a, b));
}
long long Bigmod(long long base, long long power, long long MOD) {
  long long ret = 1;
  while (power) {
    if (power & 1) ret = (ret * base) % MOD;
    base = (base * base) % MOD;
    power >>= 1;
  }
  return ret;
}
bool isVowel(char ch) {
  ch = toupper(ch);
  if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
    return true;
  return false;
}
template <typename T>
long long int isLeft(T a, T b, T c) {
  return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y);
}
long long ModInverse(long long number, long long MOD) {
  return Bigmod(number, MOD - 2, MOD);
}
bool isConst(char ch) {
  if (isalpha(ch) && !isVowel(ch)) return true;
  return false;
}
int toInt(string s) {
  int sm;
  stringstream second(s);
  second >> sm;
  return sm;
}
struct line {
  long long a, b;
  double xleft;
  bool type;
  line(long long _a, long long _b) {
    a = _a;
    b = _b;
    type = 0;
  }
  bool operator<(const line &other) const {
    if (other.type) {
      return xleft < other.xleft;
    }
    return a > other.a;
  }
};
double meet(line x, line y) { return 1.0 * (y.b - x.b) / (x.a - y.a); }
struct cht {
  set<line> hull;
  cht() { hull.clear(); }
  bool hasleft(set<line>::iterator node) { return node != hull.begin(); }
  bool hasright(set<line>::iterator node) { return node != prev(hull.end()); }
  void updateborder(set<line>::iterator node) {
    if (hasright(node)) {
      line temp = *next(node);
      hull.erase(temp);
      temp.xleft = meet(*node, temp);
      hull.insert(temp);
    }
    if (hasleft(node)) {
      line temp = *node;
      temp.xleft = meet(*prev(node), temp);
      hull.erase(node);
      hull.insert(temp);
    } else {
      line temp = *node;
      hull.erase(node);
      temp.xleft = -2000000000000000000LL;
      hull.insert(temp);
    }
  }
  bool useless(line left, line middle, line right) {
    double x = meet(left, right);
    double y = x * middle.a + middle.b;
    double ly = left.a * x + left.b;
    return y > ly;
  }
  bool useless(set<line>::iterator node) {
    if (hasleft(node) && hasright(node)) {
      return useless(*prev(node), *node, *next(node));
    }
    return 0;
  }
  void addline(long long m, long long c) {
    line temp = line(m, c);
    auto it = hull.lower_bound(temp);
    if (it != hull.end() && it->a == m) {
      if (it->b > c) {
        hull.erase(it);
      } else {
        return;
      }
    }
    hull.insert(temp);
    it = hull.find(temp);
    if (useless(it)) {
      hull.erase(it);
      return;
    }
    while (hasleft(it) && useless(prev(it))) {
      hull.erase(prev(it));
    }
    while (hasright(it) && useless(next(it))) {
      hull.erase(next(it));
    }
    updateborder(it);
  }
  long long getbest(long long x) {
    if (hull.empty()) {
      return 2000000000000000000LL;
    }
    line query(0, 0);
    query.xleft = x;
    query.type = 1;
    auto it = hull.lower_bound(query);
    it = prev(it);
    return it->a * x + it->b;
  }
};
cht Tree[300007 * 4];
long long int m, c;
void Upd(int id, int l, int r, int st, int ed) {
  if (st <= l && ed >= r) {
    Tree[id].addline(m, c);
    return;
  }
  int mid = (l + r) / 2;
  int lft = 2 * id;
  int rgt = lft + 1;
  if (ed <= mid)
    Upd(lft, l, mid, st, ed);
  else if (st > mid)
    Upd(rgt, mid + 1, r, st, ed);
  else {
    Upd(lft, l, mid, st, ed);
    Upd(rgt, mid + 1, r, st, ed);
  }
}
long long int ans;
long long int P;
void Qry(int id, int l, int r, int p) {
  ans = max(ans, Tree[id].getbest(P) * -1);
  if (l == r) {
    return;
  }
  int mid = (l + r) / 2;
  int lft = 2 * id;
  int rgt = lft + 1;
  if (p <= mid)
    Qry(lft, l, mid, p);
  else
    Qry(rgt, mid + 1, r, p);
}
int ar[300007];
int X[300007];
int Y[300007];
int Tp[300007];
int br[300007];
int main() {
  int n;
  n = in<int>();
  for (int i = 1; i < n + 1; i++) {
    Tp[i] = in<int>(), ar[i] = in<int>();
    if (Tp[i] == 1) {
      br[i] = in<int>();
      Y[i] = n;
    } else if (Tp[i] == 2) {
      Y[ar[i]] = i;
    }
  }
  for (int i = 1; i < n + 1; i++) {
    if (Tp[i] == 1) {
      m = -ar[i], c = -br[i];
      Upd(1, 1, n, i, Y[i]);
    } else if (Tp[i] == 3) {
      P = ar[i];
      ans = -2000000000000000000LL;
      Qry(1, 1, n, i);
      if (ans == -2000000000000000000LL)
        printf("EMPTY SET\n");
      else
        printf("%lld\n", ans);
    }
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.

City i is established in year Y_i and belongs to Prefecture P_i.

You can assume that there are no multiple cities that are established in the same year.

It is decided to allocate a 12-digit ID number to each city.

If City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.

Here, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.

Find the ID numbers for all the cities.

Note that there can be a prefecture with no cities.

Constraints

* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^5
* 1 \leq P_i \leq N
* 1 \leq Y_i \leq 10^9
* Y_i are all different.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
P_1 Y_1
:
P_M Y_M

Output

Print the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).

Examples

Input

2 3
1 32
2 63
1 12

Output

000001000002
000002000001
000001000001

Input

2 3
2 55
2 77
2 99

Output

000002000001
000002000002
000002000003

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int n,m;
int p[100005];
int y[100005];
vector<int>v[100005];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&p[i],&y[i]);
		v[p[i]].push_back(y[i]);
	}
	for(int i=1;i<=n;i++) sort(v[i].begin(),v[i].end());
	for(int i=1;i<=m;i++){
		printf("%06d",p[i]);
		int k=lower_bound(v[p[i]].begin(),v[p[i]].end(),y[i])-v[p[i]].begin()+1;
		printf("%06d\n",k);
	}
	return 0;
}
```


### Prompt

Please create a solution in CPP to the following problem:

Takahashi, who is A years old, is riding a Ferris wheel.

It costs B yen (B is an even number) to ride the Ferris wheel if you are 13 years old or older, but children between 6 and 12 years old (inclusive) can ride it for half the cost, and children who are 5 years old or younger are free of charge. (Yen is the currency of Japan.)

Find the cost of the Ferris wheel for Takahashi.

Constraints

* 0 ≤ A ≤ 100
* 2 ≤ B ≤ 1000
* B is an even number.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the cost of the Ferris wheel for Takahashi.

Examples

Input

30 100

Output

100

Input

12 100

Output

50

Input

0 100

Output

0

### Response

```cpp
#include <stdio.h>

int main(){
	int a, b;
	scanf("%d %d", &a, &b);
	if(a>=13) printf("%d", b);
	else if(a>=6) printf("%d", b/2);
	else printf("0");
}
```


### Prompt

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

You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.

Constraints

* s_1, s_2 and s_3 are composed of lowercase English letters.
* 1 ≤ |s_i| ≤ 10 (1≤i≤3)

Input

Input is given from Standard Input in the following format:

s_1 s_2 s_3

Output

Print the answer.

Examples

Input

atcoder beginner contest

Output

ABC

Input

resident register number

Output

RRN

Input

k nearest neighbor

Output

KNN

Input

async layered coding

Output

ALC

### Response

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

string s,ans;

int main(){
  for(int i=0;i<3;i++){
    cin>>s;
    ans+=(s[0]-32);
  }
  cout<<ans;
}
```


### Prompt

Develop a solution in cpp to the problem described below:

Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine.

For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine and three 300mg weights on the opposite side (Figure 1). Although she could put four 300mg weights on the medicine side and two 700mg weights on the other (Figure 2), she would not choose this solution because it is less convenient to use more weights.

You are asked to help her by calculating how many weights are required.

<image>

Figure 1: To measure 200mg of aspirin using three 300mg weights and one 700mg weight

<image>

Figure 2: To measure 200mg of aspirin using four 300mg weights and two 700mg weights

Input

The input is a sequence of datasets. A dataset is a line containing three positive integers a, b, and d separated by a space. The following relations hold: a ≠ b, a ≤ 10000, b ≤ 10000, and d ≤ 50000. You may assume that it is possible to measure d mg using a combination of a mg and b mg weights. In other words, you need not consider “no solution” cases.

The end of the input is indicated by a line containing three zeros separated by a space. It is not a dataset.

Output

The output should be composed of lines, each corresponding to an input dataset (a, b, d). An output line should contain two nonnegative integers x and y separated by a space. They should satisfy the following three conditions.

* You can measure d mg using x many a mg weights and y many b mg weights.
* The total number of weights (x + y) is the smallest among those pairs of nonnegative integers satisfying the previous condition.
* The total mass of weights (ax + by) is the smallest among those pairs of nonnegative integers satisfying the previous two conditions.

No extra characters (e.g. extra spaces) should appear in the output.

Example

Input

700 300 200
500 200 300
500 200 500
275 110 330
275 110 385
648 375 4002
3 1 10000
0 0 0

Output

1 3
1 1
1 0
0 3
1 1
49 74
3333 1

### Response

```cpp
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

pair<pair<lint, lint>, lint> ext_gcd(lint a, lint b){
    if(b == 0) return {{1, 0}, a};
    else if(a < b){
        auto p = ext_gcd(b, a);
        return {{p.fi.se, p.fi.fi}, p.se};
    }
    else{
        auto p = ext_gcd(b, a%b);
        lint s = p.fi.fi, t = p.fi.se;
        return {{t, s - a/b * t}, p.se};
    }
}

int main(){
    using pll = pair<lint, lint>;
    lint a, b, d;
    while(scanf("%lld%lld%lld", &a, &b, &d) && a){
        lint s, t, g;
        auto p = ext_gcd(a, b);
        tie(s, t) = p.fi; g = p.se;
        s *= d / g; t *= d / g;
        pair<pll, pll> ans = {{INF, INF}, {INF, INF}};
        lint A = a / g, B = b / g;
        lint L = min(-1.0*s/B, 1.0*t/A), R = max(-1.0*s/B, 1.0*t/A);
        For(k, L-5, R+5){
            lint x = abs(B*k + s), y = abs(-A*k + t);
            chmin(ans, {{x+y, a*x+b*y}, {x, y}});
        }
        printf("%lld %lld\n", ans.se.fi, ans.se.se);
    }
}

```


### Prompt

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

Array of integers is unimodal, if:

  * it is strictly increasing in the beginning;
  * after that it is constant;
  * after that it is strictly decreasing.

The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.

For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6].

Write a program that checks if an array is unimodal.

Input

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

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000) — the elements of the array.

Output

Print "YES" if the given array is unimodal. Otherwise, print "NO".

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

Examples

Input

6
1 5 5 5 4 2

Output

YES

Input

5
10 20 30 20 10

Output

YES

Input

4
1 2 1 2

Output

NO

Input

7
3 3 3 3 3 3 3

Output

YES

Note

In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int flag;
int a[200];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (i == 1) continue;
    if (a[i] > a[i - 1]) {
      if (flag == 2 || flag == 3) {
        printf("NO");
        return 0;
      }
      flag = 1;
    }
    if (a[i] == a[i - 1]) {
      if (flag == 3) {
        printf("NO");
        return 0;
      }
      flag = 2;
    }
    if (a[i] < a[i - 1]) {
      flag = 3;
    }
  }
  printf("YES");
  return 0;
}

```


### Prompt

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

Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.

A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:

  * Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).
  * For any two indices i and j (i < j), aj must not be divisible by ai.

Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.

Input

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

Output

Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1.

If there are multiple solutions you can output any one.

Examples

Input

3

Output

2 9 15

Input

5

Output

11 14 20 27 31

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cout << i + n << " ";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int test = 1;
  while (test--) {
    solve();
  }
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

You are given a sequence of n integers a1, a2, ..., an.

Determine a real number x such that the weakness of the sequence a1 - x, a2 - x, ..., an - x is as small as possible.

The weakness of a sequence is defined as the maximum value of the poorness over all segments (contiguous subsequences) of a sequence.

The poorness of a segment is defined as the absolute value of sum of the elements of segment.

Input

The first line contains one integer n (1 ≤ n ≤ 200 000), the length of a sequence.

The second line contains n integers a1, a2, ..., an (|ai| ≤ 10 000).

Output

Output a real number denoting the minimum possible weakness of a1 - x, a2 - x, ..., an - x. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.

Examples

Input

3
1 2 3

Output

1.000000000000000

Input

4
1 2 3 4

Output

2.000000000000000

Input

10
1 10 2 9 3 8 4 7 5 6

Output

4.500000000000000

Note

For the first case, the optimal value of x is 2 so the sequence becomes  - 1, 0, 1 and the max poorness occurs at the segment "-1" or segment "1". The poorness value (answer) equals to 1 in this case.

For the second sample the optimal value of x is 2.5 so the sequence becomes  - 1.5, - 0.5, 0.5, 1.5 and the max poorness occurs on segment "-1.5 -0.5" or "0.5 1.5". The poorness value (answer) equals to 2 in this case.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class C>
constexpr int sz(const C &c) {
  return int(c.size());
}
using ll = long long;
using ld = long double;
constexpr const char nl = '\n', sp = ' ';
template <class T, class F, class Cmp = less<T>>
T tsearch(T lo, T hi, F f, int iters, Cmp cmp = less<T>()) {
  for (int it = 0; it < iters; it++) {
    T m1 = lo + (hi - lo) / 3, m2 = hi - (hi - lo) / 3;
    if (cmp(f(m1), f(m2)))
      lo = m1;
    else
      hi = m2;
  }
  return lo + (hi - lo) / 2;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  vector<ld> A(N);
  for (auto &&a : A) cin >> a;
  auto f = [&](ld x) {
    ld ret = 0, cur = 0;
    for (auto &&a : A) {
      cur += a - x;
      if (cur < 0) cur = 0;
      if (ret < cur) ret = cur;
    }
    cur = 0;
    for (auto &&a : A) {
      cur -= a - x;
      if (cur < 0) cur = 0;
      if (ret < cur) ret = cur;
    }
    return ret;
  };
  cout << fixed << setprecision(9)
       << f(tsearch(ld(-3e4), ld(3e4), f, 300, greater<ld>())) << nl;
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from i to j in non-decreasing order if k = 1 or in non-increasing order if k = 0.

Output the final string after applying the queries.

Input

The first line will contain two integers n, q (1 ≤ n ≤ 105, 0 ≤ q ≤ 50 000), the length of the string and the number of queries respectively.

Next line contains a string S itself. It contains only lowercase English letters.

Next q lines will contain three integers each i, j, k (1 ≤ i ≤ j ≤ n, <image>).

Output

Output one line, the string S after applying the queries.

Examples

Input

10 5
abacdabcda
7 10 0
5 8 1
1 4 0
3 6 0
7 10 1

Output

cbcaaaabdd

Input

10 1
agjucbvdfk
1 10 1

Output

abcdfgjkuv

Note

First sample test explanation:

<image>

<image>

<image>

<image>

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
const int INF = 0x3f3f3f3f, N = 1e5 + 5;
const ll LINF = 1e18 + 5;
int n, q;
char s[N];
struct seg {
  int l, r, cnt[26], tag[26];
} t[N << 2];
void pushup(int p) {
  for (int i = 0; i < 26; i++)
    t[p].cnt[i] = t[p << 1].cnt[i] + t[p << 1 | 1].cnt[i];
}
void pushdown(int p, int z) {
  int &x = t[p].tag[z];
  int l = t[p].l, r = t[p].r, mid = (l + r) >> 1;
  t[p << 1].tag[z] = t[p << 1 | 1].tag[z] = x;
  if (!x)
    t[p << 1].cnt[z] = t[p << 1 | 1].cnt[z] = 0;
  else
    t[p << 1].cnt[z] = mid - l + 1, t[p << 1 | 1].cnt[z] = r - mid;
  x = -1;
}
void build(int p, int l, int r) {
  t[p].l = l, t[p].r = r;
  for (int i = 0; i < 26; i++) t[p].cnt[i] = 0, t[p].tag[i] = -1;
  if (l == r) {
    t[p].cnt[s[l] - 'a'] = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  pushup(p);
}
int query(int p, int x, int y, int z) {
  int l = t[p].l, r = t[p].r;
  if (l >= x && r <= y) return t[p].cnt[z];
  if (~t[p].tag[z]) pushdown(p, z);
  int mid = (l + r) >> 1, ans = 0;
  if (x <= mid) ans += query(p << 1, x, y, z);
  if (y > mid) ans += query(p << 1 | 1, x, y, z);
  return ans;
}
void modify(int p, int x, int y, int z) {
  int l = t[p].l, r = t[p].r;
  if (l >= x && r <= y) {
    for (int i = 0; i < 26; i++) {
      if (i == z) {
        if (t[p].cnt[i] != r - l + 1) {
          t[p].cnt[i] = r - l + 1;
          t[p].tag[i] = 1;
        }
      } else {
        if (t[p].cnt[i] != 0) {
          t[p].cnt[i] = 0;
          t[p].tag[i] = 0;
        }
      }
    }
    return;
  }
  for (int i = 0; i < 26; i++)
    if (~t[p].tag[i]) pushdown(p, i);
  int mid = (l + r) >> 1;
  if (x <= mid) modify(p << 1, x, y, z);
  if (y > mid) modify(p << 1 | 1, x, y, z);
  pushup(p);
}
void update(int p) {
  int l = t[p].l, r = t[p].r;
  if (l == r) {
    for (int i = 0; i < 26; i++)
      if (t[p].cnt[i]) s[l] = 'a' + i;
    return;
  }
  for (int i = 0; i < 26; i++)
    if (~t[p].tag[i]) pushdown(p, i);
  update(p << 1);
  update(p << 1 | 1);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> q;
  cin >> (s + 1);
  build(1, 1, n);
  for (int i = 1; i <= q; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    vector<int> cnt(26);
    for (int j = 0; j < 26; j++) cnt[j] = query(1, x, y, j);
    int l = x;
    if (z) {
      for (int idx = 0; idx < 26; idx++) {
        if (!cnt[idx]) continue;
        int r = l + cnt[idx] - 1;
        modify(1, l, r, idx);
        l = r + 1;
      }
    } else {
      for (int idx = 25; idx >= 0; idx--) {
        if (!cnt[idx]) continue;
        int r = l + cnt[idx] - 1;
        modify(1, l, r, idx);
        l = r + 1;
      }
    }
  }
  update(1);
  cout << (s + 1);
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

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

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

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

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

Input

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

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

Output

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

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

Examples

Input

5
1 2 3 1 2

Output

3 2 0 2 0

Input

4
3 2 1 4

Output

2 3 4 0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> h, s;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  h.resize(n);
  for (int i = 0; i < n; ++i) cin >> h[i];
  s = h;
  for (int i = (int)s.size() - 2; i >= 0; --i) s[i] = max(s[i], s[i + 1]);
  for (int i = 0; i < (int)s.size(); ++i) {
    if (i + 1 == (int)s.size()) {
      cout << 0 << endl;
    } else if (s[i + 1] >= h[i]) {
      cout << s[i + 1] - h[i] + 1 << ' ';
    } else {
      cout << 0 << ' ';
    }
  }
  return 0;
}

```


### Prompt

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

We have a square grid with N rows and M columns. Takahashi will write an integer in each of the squares, as follows:

* First, write 0 in every square.
* For each i=1,2,...,N, choose an integer k_i (0\leq k_i\leq M), and add 1 to each of the leftmost k_i squares in the i-th row.
* For each j=1,2,...,M, choose an integer l_j (0\leq l_j\leq N), and add 1 to each of the topmost l_j squares in the j-th column.

Now we have a grid where each square contains 0, 1, or 2. Find the number of different grids that can be made this way, modulo 998244353. We consider two grids different when there exists a square with different integers.

Constraints

* 1 \leq N,M \leq 5\times 10^5
* N and M are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of different grids that can be made, modulo 998244353.

Examples

Input

1 2

Output

8

Input

2 3

Output

234

Input

10 7

Output

995651918

Input

314159 265358

Output

70273732

### Response

```cpp
#pragma GCC optimize(2,3,"Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
namespace fast_io
{
	char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0,ny;
	in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
	in int read()
	{
		int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;Bi=1;if(nc<0)return nc;
		x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*ny;
	}
	in db gf() {int a=read(),y=ny,b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi)*y:a);}
	in int gs(char *s) {char c,*t=s;while(c=gc(),c<32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
	in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
	in void flush() {if(C>1<<22) ot();}
	template <typename T>
	in void write(T x,char t)
	{
		int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
		if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
	}
	in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
};
using namespace fast_io;
const int N=5e5+5,p=998244353;
int n,m,mx,mn,ans,cm[N],cn[N],fac[N],inv[N];
in void M(int &x) {x-=p;x+=x>>31&p;}
in int qpow(int a,int b) {int c=1;for(;b;b>>=1,a=1ll*a*a%p)if(b&1)c=1ll*a*c%p;return c;}
in int c(int n,int m) {return 1ll*fac[n]*inv[m]%p*inv[n-m]%p;}
int main()
{
	n=read(),m=read();mx=max(n,m);mn=min(n,m);
	fac[0]=cm[0]=cn[0]=1;for(int i=1;i<=mx;i++) fac[i]=1ll*fac[i-1]*i%p;
	inv[mx]=qpow(fac[mx],p-2);for(int i=mx-1;~i;i--) inv[i]=inv[i+1]*(i+1ll)%p;
	for(int i=1;i<=n;i++) cm[i]=cm[i-1]*(m+1ll)%p;
	for(int i=1;i<=m;i++) cn[i]=cn[i-1]*(n+1ll)%p;
	for(int i=0;i<=mn;i++)
	{
		int res=1ll*c(n,i)*c(m,i)%p*fac[i]%p*cm[n-i]%p*cn[m-i]%p;
		M(ans+=(i&1)?p-res:res);
	}
	write(ans,'\n');
	return ot(),0;
}
//Author: disangan233
```


### Prompt

Please create a solution in cpp to the following problem:

Problem Statement

Fox Ciel is practicing miniature golf, a golf game played with a putter club only. For improving golf skills, she believes it is important how well she bounces the ball against walls.

The field of miniature golf is in a two-dimensional plane and surrounded by $N$ walls forming a convex polygon. At first, the ball is placed at $(s_x, s_y)$ inside the field. The ball is small enough to be regarded as a point.

Ciel can shoot the ball to any direction and stop the ball whenever she wants. The ball will move in a straight line. When the ball hits the wall, it rebounds like mirror reflection (i.e. incidence angle equals reflection angle).

For practice, Ciel decided to make a single shot under the following conditions:

* The ball hits each wall of the field exactly once.

* The ball does NOT hit the corner of the field.

Count the number of possible orders in which the ball hits the walls.

Input

The input contains several datasets. The number of datasets does not exceed $100$. Each dataset is in the following format.

> $N$
> $s_x$ $s_y$
> $x_1$ $y_1$
> :
> :
> $x_N$ $y_N$

The first line contains an integer $N$ ($3 \leq N \leq 8$). The next line contains two integers $s_x$ and $s_y$ ($-50 \leq s_x, s_y \leq 50$), which describe the coordinates of the initial position of the ball. Each of the following $N$ lines contains two integers $x_i$ and $y_i$ ($-50 \leq x_i, y_i \leq 50$), which describe the coordinates of each corner of the field. The corners are given in counterclockwise order. You may assume given initial position $(s_x, s_y)$ is inside the field and the field is convex.

It is guaranteed that there exists a shoot direction for each valid order of the walls that satisfies the following condition: distance between the ball and the corners of the field $(x_i, y_i)$ is always greater than $10^{-6}$ until the ball hits the last wall.

The last dataset is followed by a line containing a single zero.

Output

For each dataset in the input, print the number of valid orders of the walls in a line.

Sample Input

4
0 0
-10 -10
10 -10
10 10
-10 10
0

Output for the Sample Input

8

Example

Input

4
0 0
-10 -10
10 -10
10 10
-10 10
0

Output

8

### Response

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

using ld = double;
using point = std::complex<ld>;
using polygon = std::vector<point>;

struct line {
    line() : a(0, 0), b(0, 0) {}
    line(point a_, point b_) : a(a_), b(b_) {}
    point a, b;
};

ld dot(point const& a, point const& b) {
    return std::real(std::conj(a) * b);
}
ld cross(point const& a, point const& b) {
    return std::imag(std::conj(a) * b);
}

point proj(line const& l, point const& p) {
    ld t = dot(p - l.a, l.a - l.b) / std::norm(l.a - l.b);
    return l.a + t * (l.a - l.b);
}

point reflect(line const& l, point const& p) {
    return p + (proj(l, p) - p) * 2.0;
}

point read_point() {
    ld x, y; cin >> x >> y;
    return point{x, y};
}

int main() {
    int n;
    while(cin >> n, n) {
        const auto sp = read_point();
        polygon ps;
        for(int i = 0; i < n; ++i) {
            ps.emplace_back(read_point());
        }

        vector<int> ord(n);
        iota(begin(ord), end(ord), 0);
        int ans = 0;
        do {
            auto ts = ps;
            vector<point> lvs, rvs;
            for(auto i : ord) {
                const auto a = ts[i], b = ts[(i + 1) % n];
                lvs.push_back(a + (b - a) / abs(b - a) * 1e-6 - sp);
                rvs.push_back(b + (a - b) / abs(b - a) * 1e-6 - sp);
                if(cross(rvs.back(), lvs.back()) < 0) swap(lvs.back(), rvs.back());
                for(int j = 0; j < n; ++j) {
                    if(j == i || (i + 1) % n == j) continue;
                    ts[j] = reflect(line{a, b}, ts[j]);
                }
            }
            auto lv = lvs[0], rv = rvs[0];
            bool check = true;
            for(int i = 1; i < n; ++i) {
                if(cross(lv, lvs[i]) <= 0) swap(lv, lvs[i]);
                if(cross(rv, rvs[i]) >= 0) swap(rv, rvs[i]);
                check &= cross(rv, lv) >= 0;
            }
            ans += check;
        } while(next_permutation(begin(ord), end(ord)));

        cout << ans << endl;
    }
}

```


### Prompt

Develop a solution in cpp to the problem described below:

The main street of Berland is a straight line with n houses built along it (n is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to n - 1 in the order from the beginning of the street to the end (in the picture: from left to right). The houses with even numbers are at the other side of the street and are numbered from 2 to n in the order from the end of the street to its beginning (in the picture: from right to left). The corresponding houses with even and odd numbers are strictly opposite each other, that is, house 1 is opposite house n, house 3 is opposite house n - 2, house 5 is opposite house n - 4 and so on.

<image>

Vasya needs to get to house number a as quickly as possible. He starts driving from the beginning of the street and drives his car to house a. To get from the beginning of the street to houses number 1 and n, he spends exactly 1 second. He also spends exactly one second to drive the distance between two neighbouring houses. Vasya can park at any side of the road, so the distance between the beginning of the street at the houses that stand opposite one another should be considered the same.

Your task is: find the minimum time Vasya needs to reach house a.

Input

The first line of the input contains two integers, n and a (1 ≤ a ≤ n ≤ 100 000) — the number of houses on the street and the number of the house that Vasya needs to reach, correspondingly. It is guaranteed that number n is even.

Output

Print a single integer — the minimum time Vasya needs to get from the beginning of the street to house a.

Examples

Input

4 2

Output

2

Input

8 5

Output

3

Note

In the first sample there are only four houses on the street, two houses at each side. House 2 will be the last at Vasya's right.

The second sample corresponds to picture with n = 8. House 5 is the one before last at Vasya's left.

### Response

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

```


### Prompt

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

You are given an array of n integer numbers a0, a1, ..., an - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.

Input

The first line contains positive integer n (2 ≤ n ≤ 105) — size of the given array. The second line contains n integers a0, a1, ..., an - 1 (1 ≤ ai ≤ 109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times.

Output

Print the only number — distance between two nearest minimums in the array.

Examples

Input

2
3 3

Output

1

Input

3
5 6 5

Output

2

Input

9
2 1 3 5 4 1 2 3 1

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[100020];
int main(void) {
  int n;
  int i;
  int o;
  vector<int> v;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  v.clear();
  for (i = 2, v.push_back(1), o = n; i <= n; i++) {
    if (a[i] == a[v.at(0)]) {
      o = min(o, i - v.at(v.size() - 1));
      v.push_back(i);
    }
    if (a[i] < a[v.at(0)]) {
      v.clear();
      v.push_back(i);
      o = n;
    }
  }
  printf("%d\n", o);
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

You have n gifts and you want to give all of them to children. Of course, you don't want to offend anyone, so all gifts should be equal between each other. The i-th gift consists of a_i candies and b_i oranges.

During one move, you can choose some gift 1 ≤ i ≤ n and do one of the following operations:

  * eat exactly one candy from this gift (decrease a_i by one);
  * eat exactly one orange from this gift (decrease b_i by one);
  * eat exactly one candy and exactly one orange from this gift (decrease both a_i and b_i by one).

Of course, you can not eat a candy or orange if it's not present in the gift (so neither a_i nor b_i can become less than zero).

As said above, all gifts should be equal. This means that after some sequence of moves the following two conditions should be satisfied: a_1 = a_2 = ... = a_n and b_1 = b_2 = ... = b_n (and a_i equals b_i is not necessary).

Your task is to find the minimum number of moves required to equalize all the given gifts.

You have to answer t independent test cases.

Input

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

The first line of the test case contains one integer n (1 ≤ n ≤ 50) — the number of gifts. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is the number of candies in the i-th gift. The third line of the test case contains n integers b_1, b_2, ..., b_n (1 ≤ b_i ≤ 10^9), where b_i is the number of oranges in the i-th gift.

Output

For each test case, print one integer: the minimum number of moves required to equalize all the given gifts.

Example

Input

5
3
3 5 6
3 2 3
5
1 2 3 4 5
5 4 3 2 1
3
1 1 1
2 2 2
6
1 1000000000 1000000000 1000000000 1000000000 1000000000
1 1 1 1 1 1
3
10 12 8
7 5 4

Output

6
16
0
4999999995
7

Note

In the first test case of the example, we can perform the following sequence of moves:

  * choose the first gift and eat one orange from it, so a = [3, 5, 6] and b = [2, 2, 3];
  * choose the second gift and eat one candy from it, so a = [3, 4, 6] and b = [2, 2, 3];
  * choose the second gift and eat one candy from it, so a = [3, 3, 6] and b = [2, 2, 3];
  * choose the third gift and eat one candy and one orange from it, so a = [3, 3, 5] and b = [2, 2, 2];
  * choose the third gift and eat one candy from it, so a = [3, 3, 4] and b = [2, 2, 2];
  * choose the third gift and eat one candy from it, so a = [3, 3, 3] and b = [2, 2, 2].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool isprime(long long int x) {
  if (x <= 1) {
    return false;
  }
  if (x <= 3) {
    return true;
  }
  for (long long int i = 5; i < sqrt(x); i += 6) {
    if (x % i == 0 || x % (i + 2) == 0) {
      return false;
    }
  }
  return true;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / (gcd(a, b));
}
void swap(int& a, int& b) {
  a = a ^ b;
  b = a ^ b;
  a = a ^ b;
}
bool isPowerOfTwo(long long int n) {
  if (n == 0) return false;
  return (ceil(log2(n)) == floor(log2(n)));
}
long long int getcl(long long int a, long long int b) {
  return (a + b - 1) / b;
}
long long int min_of_3(long long int a, long long int b, long long int c) {
  a = min(a, b);
  c = min(a, c);
  return c;
}
long long int powMod(long long int x, long long int y,
                     long long int p = 1000000007) {
  long long int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
inline void solve() {
  long long int n, c = 0;
  cin >> n;
  vector<long long int> a(n), b(n);
  for (auto& i : a) cin >> i;
  for (auto& i : b) cin >> i;
  long long int amin = *min_element(a.begin(), a.end());
  long long int bmin = *min_element(b.begin(), b.end());
  for (int i = 0; i < n; ++i) {
    c += max(a[i] - amin, b[i] - bmin);
  }
  cout << c << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thus, Sereja orders a number of pizzas so they can eat right after the end of the competition.

Teams plan to train for n times during n consecutive days. During the training session Sereja orders exactly one pizza for each team that is present this day. He already knows that there will be ai teams on the i-th day.

There are two types of discounts in Sereja's favourite pizzeria. The first discount works if one buys two pizzas at one day, while the second is a coupon that allows to buy one pizza during two consecutive days (two pizzas in total).

As Sereja orders really a lot of pizza at this place, he is the golden client and can use the unlimited number of discounts and coupons of any type at any days.

Sereja wants to order exactly ai pizzas on the i-th day while using only discounts and coupons. Note, that he will never buy more pizzas than he need for this particular day. Help him determine, whether he can buy the proper amount of pizzas each day if he is allowed to use only coupons and discounts. Note, that it's also prohibited to have any active coupons after the end of the day n.

Input

The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions.

The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days.

Output

If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes).

Examples

Input

4
1 2 1 2

Output

YES

Input

3
1 0 1

Output

NO

Note

In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample.

In the second sample, Sereja can't use neither the coupon nor the discount without ordering an extra pizza. Note, that it's possible that there will be no teams attending the training sessions on some days.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) {
    a[i] %= 2;
    if (a[i]) {
      if (a[i + 1])
        a[i + 1]--;
      else {
        printf("NO\n");
        return 0;
      }
    }
  }
  printf("YES\n");
  return 0;
}

```


### Prompt

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

After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks.

An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.

In the grid shown below, n = 3 and m = 3. There are n + m = 6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are n·m = 9 intersection points, numbered from 1 to 9.

<image>

The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move).

Assume that both players play optimally. Who will win the game?

Input

The first line of input contains two space-separated integers, n and m (1 ≤ n, m ≤ 100).

Output

Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game.

Examples

Input

2 2

Output

Malvika

Input

2 3

Output

Malvika

Input

3 3

Output

Akshat

Note

Explanation of the first sample:

The grid has four intersection points, numbered from 1 to 4.

<image>

If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this.

<image>

Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty.

In the empty grid, Akshat cannot make any move, hence he will lose.

Since all 4 intersection points of the grid are equivalent, Akshat will lose no matter which one he picks.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int c = 0;
  int a;
  for (int i = 1; i <= n; i++) {
    a = (n - i) * (m - i);
    c++;
    if (a == 0) break;
  }
  if (c % 2 == 0)
    cout << "Malvika";
  else
    cout << "Akshat";
}

```


### Prompt

Please create a solution in cpp to the following problem:

Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the n books should be assigned with a number from 1 to n. Naturally, distinct books should be assigned distinct numbers.

Vanya wants to know how many digits he will have to write down as he labels the books.

Input

The first line contains integer n (1 ≤ n ≤ 109) — the number of books in the library.

Output

Print the number of digits needed to number all the books.

Examples

Input

13

Output

17

Input

4

Output

4

Note

Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.

Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, nn, c = 0;
  long long res = 0, nins = 9;
  cin >> n;
  nn = n;
  while (nn) {
    c++, nn /= 10;
    if (nn) res += nins * c, nins *= 10;
  }
  if (c == 1)
    cout << n;
  else {
    res += (n - (int)(pow(10, c - 1) + 1e-9) + 1LL) * c;
    cout << res;
  }
}

```


### Prompt

Generate a Cpp solution to the following problem:

Find the sum of the weights of edges of the Minimum-Cost Arborescence with the root r for a given weighted directed graph G = (V, E).

Constraints

* 1 ≤ |V| ≤ 100
* 0 ≤ |E| ≤ 1,000
* 0 ≤ wi ≤ 10,000
* G has arborescence(s) with the root r

Input

|V| |E| r
s0 t0 w0
s1 t1 w1
:
s|E|-1 t|E|-1 w|E|-1

, where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. r is the root of the Minimum-Cost Arborescence.

si and ti represent source and target verticess of i-th directed edge. wi represents the weight of the i-th directed edge.

Output

Print the sum of the weights the Minimum-Cost Arborescence.

Examples

Input

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

Output

6

Input

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

Output

11

### Response

```cpp
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

// 最小全域有向木 O(EV)
// 0-index
// 例外判定のために Edge[0] => {-1,-1,-1} が必須なため　辺のindexは 1-index
const int MAXV = 10010;
const int MAXE = 10010;
const int MAXW = 2147483647;
struct Edge {
    int u, v, c;
    Edge(int x = -1, int y = 0, int z = 0) : u(x), v(y), c(z) {}
};
int V, E, root;
Edge edges[MAXE];
inline void addEdge(int u, int v, int c){ edges[++E] = Edge(u, v, c);}
bool con[MAXV];
int mnInW[MAXV], prv[MAXV], cyc[MAXV], vis[MAXV];
inline int DMST() {
    fill(con, con + V, 0);
    int r1 = 0, r2 = 0;
    while (true) {
        fill(mnInW, mnInW + V, MAXW);
        fill(prv, prv + V, -1);
        for (int i = 1; i <= E; i++) {
            int u = edges[i].u, v = edges[i].v, c = edges[i].c;
            if (u != v && v != root && c < mnInW[v]){mnInW[v] = c; prv[v] = u;}
        }
        fill(vis, vis + V, -1);
        fill(cyc, cyc + V, -1);
        r1 = 0;
        bool jf = false;
        for (int i = 0; i < V; i++) {
            if (con[i]) continue;
            if (prv[i] == -1 && i != root) {
                return -1;
            }
            if (prv[i] >= 0) r1 += mnInW[i];
            int s;
            for (s = i; s != -1 && vis[s] == -1; s = prv[s]) vis[s] = i;
            if (s >= 0 && vis[s] == i) {
                // get a cycle
                jf = true; int v = s;
                do { cyc[v] = s; con[v] = true; r2 += mnInW[v]; v = prv[v];
                } while (v != s);
                con[s] = false;
            }
        }
        if (!jf) break;
        for (int i = 1; i <= E; i++) {
            int &u = edges[i].u;
            int &v = edges[i].v;
            if (cyc[v] >= 0) edges[i].c -= mnInW[edges[i].v];
            if (cyc[u] >= 0) edges[i].u = cyc[edges[i].u];
            if (cyc[v] >= 0) edges[i].v = cyc[edges[i].v];
            if (u == v){ edges[i--] = edges[E--]; }
        }
    }
    return r1 + r2;
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int e;
    cin >> V >> e >> root;
    for(int i = 0; i < e;i++) {
        int a, b, c;
        cin >> a >> b >> c;
        addEdge(a, b, c);
    }
    cout << DMST() << endl;

    return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal.

Input

The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A<B.

Output

It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.

Examples

Input

A>B
C<B
A>C

Output

CBA

Input

A<B
B>C
C>A

Output

ACB

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  string a, b, c;
  cin >> a >> b >> c;
  long long ar[3] = {0};
  if (a[1] == '>')
    ar[a[0] - 'A']++;
  else
    ar[a[2] - 'A']++;
  if (b[1] == '>')
    ar[b[0] - 'A']++;
  else
    ar[b[2] - 'A']++;
  if (c[1] == '>')
    ar[c[0] - 'A']++;
  else
    ar[c[2] - 'A']++;
  if (ar[0] == ar[1]) {
    cout << "Impossible";
    return;
  }
  vector<pair<long long, char> > v;
  v.push_back({ar[0], 'A'});
  v.push_back({ar[1], 'B'});
  v.push_back({ar[2], 'C'});
  sort(v.begin(), v.end());
  for (int i = 0; i < 3; i++) cout << v[i].second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
}

```


### Prompt

Generate a Cpp solution to the following problem:

A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare.

The fare is constructed in the following manner. There are three types of tickets:

  1. a ticket for one trip costs 20 byteland rubles,
  2. a ticket for 90 minutes costs 50 byteland rubles,
  3. a ticket for one day (1440 minutes) costs 120 byteland rubles.

Note that a ticket for x minutes activated at time t can be used for trips started in time range from t to t + x - 1, inclusive. Assume that all trips take exactly one minute.

To simplify the choice for the passenger, the system automatically chooses the optimal tickets. After each trip starts, the system analyses all the previous trips and the current trip and chooses a set of tickets for these trips with a minimum total cost. Let the minimum total cost of tickets to cover all trips from the first to the current is a, and the total sum charged before is b. Then the system charges the passenger the sum a - b.

You have to write a program that, for given trips made by a passenger, calculates the sum the passenger is charged after each trip.

Input

The first line of input contains integer number n (1 ≤ n ≤ 105) — the number of trips made by passenger.

Each of the following n lines contains the time of trip ti (0 ≤ ti ≤ 109), measured in minutes from the time of starting the system. All ti are different, given in ascending order, i. e. ti + 1 > ti holds for all 1 ≤ i < n.

Output

Output n integers. For each trip, print the sum the passenger is charged after it.

Examples

Input

3
10
20
30

Output

20
20
10

Input

10
13
45
46
60
103
115
126
150
256
516

Output

20
20
10
0
20
0
0
20
20
10

Note

In the first example, the system works as follows: for the first and second trips it is cheaper to pay for two one-trip tickets, so each time 20 rubles is charged, after the third trip the system understands that it would be cheaper to buy a ticket for 90 minutes. This ticket costs 50 rubles, and the passenger had already paid 40 rubles, so it is necessary to charge 10 rubles only.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, t;
  cin >> n;
  long long spent90 = 0, spent1440 = 0;
  bool flag90 = false, flag1440 = false;
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      pq90, pq1440;
  for (long long i = 0; i < n; i++) {
    cin >> t;
    if (spent90 == 50 && t - pq90.top().first < 90 ||
        spent1440 == 120 && t - pq1440.top().first < 1440)
      cout << 0 << endl;
    else {
      while (!pq1440.empty() && t - pq1440.top().first >= 1440) {
        spent1440 -= pq1440.top().second;
        pq1440.pop();
      }
      while (!pq90.empty() && t - pq90.top().first >= 90) {
        spent90 -= pq90.top().second;
        pq90.pop();
      }
      long long pay = min(120 - spent1440, min(50 - spent90, 20LL));
      spent90 += pay;
      spent1440 += pay;
      pq90.push(make_pair(t, pay));
      pq1440.push(make_pair(t, pay));
      cout << pay << endl;
    }
  }
  return 0;
}

```


### Prompt

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

You are given a polynomial of degree N with integer coefficients: f(x)=a_Nx^N+a_{N-1}x^{N-1}+...+a_0. Find all prime numbers p that divide f(x) for every integer x.

Constraints

* 0 \leq N \leq 10^4
* |a_i| \leq 10^9(0\leq i\leq N)
* a_N \neq 0
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
a_N
:
a_0

Output

Print all prime numbers p that divide f(x) for every integer x, in ascending order.

Examples

Input

2
7
-7
14

Output

2
7

Input

3
1
4
1
5

Output

Input

0
998244353

Output

998244353

### Response

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

#define N 10010
int n, a[N], b[N];
bool isprime(int x) {
	for (int i = 2; 1ll * i * i <= x; ++i) {
		if (x % i == 0) {
			return false;
		}
	}
	return true;
}
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
bool ok(int p) {
	if (a[0] % p) {
		return false;
	}
	for (int i = 0; i <= n - 1; ++i) {
		b[i] = a[i + 1];
	}
	for (int i = n; i >= p - 1; --i) {
		(b[i - (p - 1)] += b[i]) %= p;
		b[i] = 0;
	}
	for (int i = 0; i <= n - 1; ++i) {
		if (b[i] % p) {
			return false;
		}
	}
	return true;
}

int main() {
	while (scanf("%d", &n) != EOF) {
		int G = 0;
		for (int i = 0; i <= n; ++i) {
			scanf("%d", a + i);
			G = gcd(G, abs(a[i]));
		}
		reverse(a, a + 1 + n);
		vector <int> res;
		for (int i = 2; 1ll * i * i <= G; ++i) {
			if (G % i == 0) {
				res.push_back(i);
				while (G % i == 0) {
					G /= i;
				}
			}
		}
		if (G > 1) {
			res.push_back(G);
		}
		for (int i = 2; i <= n; ++i) {
			if (isprime(i) && ok(i)) {
				res.push_back(i);
			}
		}
		sort(res.begin(), res.end());
		res.erase(unique(res.begin(), res.end()), res.end());
		for (auto it : res) {
			printf("%d\n", it);
		}
	//	puts("------------");
	}
	return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Vova's house is an array consisting of n elements (yeah, this is the first problem, I think, where someone lives in the array). There are heaters in some positions of the array. The i-th element of the array is 1 if there is a heater in the position i, otherwise the i-th element of the array is 0.

Each heater has a value r (r is the same for all heaters). This value means that the heater at the position pos can warm up all the elements in range [pos - r + 1; pos + r - 1].

Vova likes to walk through his house while he thinks, and he hates cold positions of his house. Vova wants to switch some of his heaters on in such a way that each element of his house will be warmed up by at least one heater.

Vova's target is to warm up the whole house (all the elements of the array), i.e. if n = 6, r = 2 and heaters are at positions 2 and 5, then Vova can warm up the whole house if he switches all the heaters in the house on (then the first 3 elements will be warmed up by the first heater and the last 3 elements will be warmed up by the second heater).

Initially, all the heaters are off.

But from the other hand, Vova didn't like to pay much for the electricity. So he wants to switch the minimum number of heaters on in such a way that each element of his house is warmed up by at least one heater.

Your task is to find this number of heaters or say that it is impossible to warm up the whole house.

Input

The first line of the input contains two integers n and r (1 ≤ n, r ≤ 1000) — the number of elements in the array and the value of heaters.

The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 1) — the Vova's house description.

Output

Print one integer — the minimum number of heaters needed to warm up the whole house or -1 if it is impossible to do it.

Examples

Input

6 2
0 1 1 0 0 1

Output

3

Input

5 3
1 0 0 0 1

Output

2

Input

5 10
0 0 0 0 0

Output

-1

Input

10 3
0 0 1 1 0 1 0 0 0 1

Output

3

Note

In the first example the heater at the position 2 warms up elements [1; 3], the heater at the position 3 warms up elements [2, 4] and the heater at the position 6 warms up elements [5; 6] so the answer is 3.

In the second example the heater at the position 1 warms up elements [1; 3] and the heater at the position 5 warms up elements [3; 5] so the answer is 2.

In the third example there are no heaters so the answer is -1.

In the fourth example the heater at the position 3 warms up elements [1; 5], the heater at the position 6 warms up elements [4; 8] and the heater at the position 10 warms up elements [8; 10] so the answer is 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[1100], n, r;
  cin >> n >> r;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int ultimul = 0;
  int cnt = 0;
  while (ultimul < n) {
    int pos = 0;
    for (int i = n; i > max(0, ultimul - (r - 1)); i--)
      if (a[i] && i - r <= ultimul) {
        pos = i;
        break;
      }
    if (!pos) {
      cout << "-1";
      return 0;
    }
    cnt++;
    ultimul = pos + r - 1;
  }
  cout << cnt;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.

Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought n packets with inflatable balloons, where i-th of them has exactly a_i balloons inside.

They want to divide the balloons among themselves. In addition, there are several conditions to hold:

  * Do not rip the packets (both Grigory and Andrew should get unbroken packets);
  * Distribute all packets (every packet should be given to someone);
  * Give both Grigory and Andrew at least one packet;
  * To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.

Help them to divide the balloons or determine that it's impossible under these conditions.

Input

The first line of input contains a single integer n (1 ≤ n ≤ 10) — the number of packets with balloons.

The second line contains n integers: a_1, a_2, …, a_n (1 ≤ a_i ≤ 1000) — the number of balloons inside the corresponding packet.

Output

If it's impossible to divide the balloons satisfying the conditions above, print -1.

Otherwise, print an integer k — the number of packets to give to Grigory followed by k distinct integers from 1 to n — the indices of those. The order of packets doesn't matter.

If there are multiple ways to divide balloons, output any of them.

Examples

Input

3
1 2 1

Output

2
1 2

Input

2
5 5

Output

-1

Input

1
10

Output

-1

Note

In the first test Grigory gets 3 balloons in total while Andrey gets 1.

In the second test there's only one way to divide the packets which leads to equal numbers of balloons.

In the third test one of the boys won't get a packet at all.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int const N = 1e6 + 100;
long long int const LINF = numeric_limits<long long int>::max();
int const INF = numeric_limits<int>::max();
int const BN = 31;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int pow_mod(long long int a, long long int e, long long int m) {
  long long int res = 1;
  while (e) {
    if (e & 1) res = res * a % m;
    a = a * a % m;
    e >>= 1;
  }
  return res;
}
long long int inv_mod(long long int b, long long int m) {
  b %= m;
  long long int x = 0, y = 1, r, q, a = m;
  while (b) {
    q = a / b;
    r = a % b;
    a = b;
    b = r;
    r = x;
    x = y;
    y = r - q * y;
  }
  x += m;
  return x % m;
}
int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  if (n == 1)
    cout << -1 << endl;
  else if (n == 2) {
    if (arr[0] == arr[1])
      cout << -1 << endl;
    else
      cout << 1 << endl << 1 << endl;
  } else {
    int idx = 0, m = 10000;
    for (int i = 0; i < n; i++) {
      if (arr[i] < m) {
        idx = i + 1;
        m = arr[i];
      }
    }
    cout << 1 << endl << idx << endl;
  }
}

```


### Prompt

Please formulate a cpp solution to the following problem:

The employees of the F company have lots of ways to entertain themselves. Today they invited a famous magician who shows a trick with plastic cups and a marble.

The point is to trick the spectator's attention. Initially, the spectator stands in front of a line of n plastic cups. Then the magician places a small marble under one cup and shuffles the cups. Then the spectator should guess which cup hides the marble.

But the head coder of the F company isn't easy to trick. When he saw the performance, he noticed several important facts:

  * each cup contains a mark — a number from 1 to n; all marks on the cups are distinct;
  * the magician shuffles the cups in m operations, each operation looks like that: take a cup marked xi, sitting at position yi in the row of cups (the positions are numbered from left to right, starting from 1) and shift it to the very beginning of the cup row (on the first position).

When the head coder came home after work he wanted to re-do the trick. Unfortunately, he didn't remember the starting or the final position of the cups. He only remembered which operations the magician performed. Help the coder: given the operations in the order they were made find at least one initial permutation of the cups that can go through the described operations in the given order. Otherwise, state that such permutation doesn't exist.

Input

The first line contains integers n and m (1 ≤ n, m ≤ 106). Each of the next m lines contains a couple of integers. The i-th line contains integers xi, yi (1 ≤ xi, yi ≤ n) — the description of the i-th operation of the magician. Note that the operations are given in the order in which the magician made them and the coder wants to make them in the same order.

Output

If the described permutation doesn't exist (the programmer remembered wrong operations), print -1. Otherwise, print n distinct integers, each from 1 to n: the i-th number should represent the mark on the cup that initially is in the row in position i.

If there are multiple correct answers, you should print the lexicographically minimum one.

Examples

Input

2 1
2 1

Output

2 1

Input

3 2
1 2
1 1

Output

2 1 3

Input

3 3
1 3
2 3
1 3

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& x) {
  bool fu = 0;
  char c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') fu = 1, c = getchar();
  for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0';
  if (fu) x = -x;
};
template <class T>
inline void read(T& x, T& y) {
  read(x);
  read(y);
}
template <class T>
inline void read(T& x, T& y, T& z) {
  read(x);
  read(y);
  read(z);
}
inline char getc() {
  char c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  return c;
}
const int N = 8000010;
int n, m, i, j, k, l, r, p, d, zz;
int s[N], key[N], a[N], w[N];
void upd(int i) { s[i] = s[i * 2] + s[i * 2 + 1]; }
int get(int i, int x, int y, int k) {
  if (x == y) return d = key[i], x;
  if (k <= s[i * 2])
    return get(i * 2, x, (x + y) / 2, k);
  else
    return get(i * 2 + 1, (x + y) / 2 + 1, y, k - s[i * 2]);
}
void bui(int i, int x, int y) {
  if (x != y) {
    bui(i * 2, x, (x + y) / 2);
    bui(i * 2 + 1, (x + y) / 2 + 1, y);
    upd(i);
  } else
    s[i] = (x > m);
}
void ins(int i, int x, int y, int d, bool ki) {
  if (x == y) {
    if (ki) {
      key[i] = zz, s[i] = 1;
      w[zz] = d;
    } else
      s[i] = 0;
    return;
  }
  if (d <= (x + y) / 2)
    ins(i * 2, x, (x + y) / 2, d, ki);
  else
    ins(i * 2 + 1, (x + y) / 2 + 1, y, d, ki);
  upd(i);
}
bool have[N];
int main() {
  read(n, m);
  bui(1, 1, n + m);
  memset(w, -1, sizeof(w));
  int x, y;
  l = m;
  for (int t = (1); t <= (m); t++) {
    read(x, y);
    zz = x;
    have[x] = 1;
    p = get(1, 1, n + m, y);
    if (w[x] != -1 && w[x] != p) {
      printf("-1\n");
      return 0;
    }
    if (p > m) a[p - m] = x;
    if (d > 0 && x != d) {
      printf("-1\n");
      return 0;
    }
    ins(1, 1, n + m, p, 0);
    l--;
    ins(1, 1, n + m, l, 1);
  }
  j = 1;
  for (i = 1; i <= n; i++)
    if (a[i] == 0) {
      for (; j <= n && have[j]; j++)
        ;
      a[i] = j++;
    }
  for (i = 1; i <= n; i++) printf("%d%s", a[i], i == n ? "\n" : " ");
  scanf("\n");
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Phoenix has a string s consisting of lowercase Latin letters. He wants to distribute all the letters of his string into k non-empty strings a_1, a_2, ..., a_k such that every letter of s goes to exactly one of the strings a_i. The strings a_i do not need to be substrings of s. Phoenix can distribute letters of s and rearrange the letters within each string a_i however he wants.

For example, if s =  baba and k=2, Phoenix may distribute the letters of his string in many ways, such as:

  * ba and ba
  * a and abb
  * ab and ab
  * aa and bb

But these ways are invalid:

  * baa and ba
  * b and ba
  * baba and empty string (a_i should be non-empty)

Phoenix wants to distribute the letters of his string s into k strings a_1, a_2, ..., a_k to minimize the lexicographically maximum string among them, i. e. minimize max(a_1, a_2, ..., a_k). Help him find the optimal distribution and print the minimal possible value of max(a_1, a_2, ..., a_k).

String x is lexicographically less than string y if either x is a prefix of y and x ≠ y, or there exists an index i (1 ≤ i ≤ min(|x|, |y|)) such that x_i < y_i and for every j (1 ≤ j < i) x_j = y_j. Here |x| denotes the length of the string x.

Input

The input consists of multiple test cases. The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases. Each test case consists of two lines.

The first line of each test case consists of two integers n and k (1 ≤ k ≤ n ≤ 10^5) — the length of string s and the number of non-empty strings, into which Phoenix wants to distribute letters of s, respectively.

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

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

Output

Print t answers — one per test case. The i-th answer should be the minimal possible value of max(a_1, a_2, ..., a_k) in the i-th test case.

Example

Input

6
4 2
baba
5 2
baacb
5 3
baacb
5 3
aaaaa
6 4
aaxxzz
7 1
phoenix

Output

ab
abbc
b
aa
x
ehinopx

Note

In the first test case, one optimal solution is to distribute baba into ab and ab.

In the second test case, one optimal solution is to distribute baacb into abbc and a.

In the third test case, one optimal solution is to distribute baacb into ac, ab, and b.

In the fourth test case, one optimal solution is to distribute aaaaa into aa, aa, and a.

In the fifth test case, one optimal solution is to distribute aaxxzz into az, az, x, and x.

In the sixth test case, one optimal solution is to distribute phoenix into ehinopx.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  if (s[0] != s[k - 1]) {
    cout << s[k - 1] << endl;
    return;
  }
  cout << s[0];
  if (s[k] != s[n - 1]) {
    for (int i = k; i < n; i++) cout << s[i];
  } else {
    for (int i = 0; i < (n - 1) / k; i++) cout << s[n - 1];
  }
  cout << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}

```


### Prompt

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

Dreamoon likes strings. Today he created a game about strings:

String s_1, s_2, …, s_n is beautiful if and only if for each 1 ≤ i < n, s_i ≠ s_{i+1}.

Initially, Dreamoon has a string a. In each step Dreamoon can choose a beautiful substring of a and remove it. Then he should concatenate the remaining characters (in the same order).

Dreamoon wants to use the smallest number of steps to make a empty. Please help Dreamoon, and print any sequence of the smallest number of steps to make a empty.

Input

The first line contains an integer t (1 ≤ t ≤ 200 000), denoting the number of test cases in the input.

For each test case, there's one line with a non-empty string of lowercase Latin letters a.

The total sum of lengths of strings in all test cases is at most 200 000.

Output

For each test case, in the first line, you should print m: the smallest number of steps to make a empty. Each of the following m lines should contain two integers l_i, r_i (1 ≤ l_i ≤ r_i ≤ |a|), denoting, that the i-th step is removing the characters from index l_i to r_i in the current string. (indices are numbered starting from 1).

Note that after the deletion of the substring, indices of remaining characters may change, and r_i should be at most the current length of a.

If there are several possible solutions, you can print any.

Example

Input

4
aabbcc
aaabbb
aaa
abacad

Output

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

### Response

```cpp
#include <bits/stdc++.h>
const int N = 1000005;
int T, n, s[N], cnum[N], a[N];
char S[N];
inline int Max(const int p, const int q) { return p > q ? p : q; }
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%s", S + 1), n = strlen(S + 1);
    register int i, j, k, pos, top = 0, mx = 0, tot = 0;
    for (i = 0; i < 26; ++i) cnum[i] = 0;
    for (i = 1; i <= n; ++i) S[i] -= 'a';
    for (i = 2; i <= n; ++i)
      cnum[S[i]] += (S[i] == S[i - 1]), tot += (S[i] == S[i - 1]);
    for (i = 0; i < 26; ++i) mx = (cnum[i] > mx ? cnum[i] : mx);
    printf("%d\n", Max(mx, tot + 1 >> 1) + 1);
    for (i = top = 0, j = 1; j <= n; ++j) {
      a[++i] = S[j];
      if (i == 1 || a[i] != a[i - 1]) continue;
      if ((!top) || a[i] == a[s[top]]) {
        s[++top] = i;
        continue;
      }
      for (k = pos = 0; k < 26; ++k) pos = (cnum[k] > cnum[pos] ? k : pos);
      ((cnum[pos] << 1) < tot || pos == a[i] || pos == a[s[top]]) ? --tot,
          --cnum[a[i]], --tot, --cnum[a[s[top]]],
          printf("%d %d\n", s[top], i - 1), a[s[top]] = a[i],
                                            i = s[top--] : s[++top] = i;
    }
    for (j = i; i; --i)
      if (i == 1 || a[i] == a[i - 1]) printf("%d %d\n", i, j), j = i - 1;
  }
  return 0;
}

```


### Prompt

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

You are given an array a of n integers.

You want to make all elements of a equal to zero by doing the following operation exactly three times:

  * Select a segment, for each number in this segment we can add a multiple of len to it, where len is the length of this segment (added integers can be different).

It can be proven that it is always possible to make all elements of a equal to zero.

Input

The first line contains one integer n (1 ≤ n ≤ 100 000): the number of elements of the array.

The second line contains n elements of an array a separated by spaces: a_1, a_2, ..., a_n (-10^9 ≤ a_i ≤ 10^9).

Output

The output should contain six lines representing three operations.

For each operation, print two lines:

  * The first line contains two integers l, r (1 ≤ l ≤ r ≤ n): the bounds of the selected segment.

  * The second line contains r-l+1 integers b_l, b_{l+1}, ..., b_r (-10^{18} ≤ b_i ≤ 10^{18}): the numbers to add to a_l, a_{l+1}, …, a_r, respectively; b_i should be divisible by r - l + 1.

Example

Input

4
1 3 2 4

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long int> a(n + 1);
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (n == 1) {
    cout << "1 1\n0\n1 1\n0\n1 1\n" << (-1) * a[1] << "\n";
  } else {
    cout << "1 1\n" << (-1) * a[1] << "\n";
    cout << "1 " << n << "\n";
    for (long long int i = 1; i <= n; i++) {
      cout << (i == 1 ? 0 : (-n) * a[i]) << " ";
    }
    cout << "\n";
    cout << "2 " << n << "\n";
    for (long long int i = 2; i <= n; i++) {
      cout << (n - 1) * a[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.

Seating in the class looks like a rectangle, where n rows with m pupils in each.

The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd row, ..., the n - 1-st row, the n-th row, the n - 1-st row, ..., the 2-nd row, the 1-st row, the 2-nd row, ...

The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd pupil, ..., the m-th pupil.

During the lesson the teacher managed to ask exactly k questions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values:

  1. the maximum number of questions a particular pupil is asked,
  2. the minimum number of questions a particular pupil is asked,
  3. how many times the teacher asked Sergei.

If there is only one row in the class, then the teacher always asks children from this row.

Input

The first and the only line contains five integers n, m, k, x and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 1018, 1 ≤ x ≤ n, 1 ≤ y ≤ m).

Output

Print three integers:

  1. the maximum number of questions a particular pupil is asked,
  2. the minimum number of questions a particular pupil is asked,
  3. how many times the teacher asked Sergei.

Examples

Input

1 3 8 1 1

Output

3 2 3

Input

4 2 9 4 2

Output

2 1 1

Input

5 5 25 4 3

Output

1 1 1

Input

100 100 1000000000000000000 100 100

Output

101010101010101 50505050505051 50505050505051

Note

The order of asking pupils in the first test:

  1. the pupil from the first row who seats at the first table, it means it is Sergei;
  2. the pupil from the first row who seats at the second table;
  3. the pupil from the first row who seats at the third table;
  4. the pupil from the first row who seats at the first table, it means it is Sergei;
  5. the pupil from the first row who seats at the second table;
  6. the pupil from the first row who seats at the third table;
  7. the pupil from the first row who seats at the first table, it means it is Sergei;
  8. the pupil from the first row who seats at the second table;

The order of asking pupils in the second test:

  1. the pupil from the first row who seats at the first table;
  2. the pupil from the first row who seats at the second table;
  3. the pupil from the second row who seats at the first table;
  4. the pupil from the second row who seats at the second table;
  5. the pupil from the third row who seats at the first table;
  6. the pupil from the third row who seats at the second table;
  7. the pupil from the fourth row who seats at the first table;
  8. the pupil from the fourth row who seats at the second table, it means it is Sergei;
  9. the pupil from the third row who seats at the first table;

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long max(long long x, long long y) {
  if (x > y) return x;
  return y;
}
long long min(long long x, long long y) {
  if (x < y) return x;
  return y;
}
long long n, m, k, x, y;
long long a[101][101] = {0};
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> k >> x >> y;
  long long cycle_length;
  if (n < 2)
    cycle_length = m * n;
  else
    cycle_length = 2 * m * (n - 1);
  long long cycles = k / cycle_length;
  long long k1 = k - (max(0, cycles)) * cycle_length;
  for (long long i = 1; i <= n && k1 > 0; i++)
    for (long long j = 1; j <= m && k1 > 0; j++) {
      k1--;
      a[i][j]++;
    }
  for (long long i = n - 1; i >= 1 && k1 > 0; i--)
    for (long long j = 1; j <= m && k1 > 0; j++) {
      k1--;
      a[i][j]++;
    }
  long long minel = (long long)(1e9), maxel1 = 0, maxel2 = 0;
  for (long long j = 1; j <= m; j++) {
    minel = min(minel, min(a[1][j], a[n][j]));
    maxel2 = max(maxel2, max(a[1][j], a[n][j]));
  }
  if (n > 2)
    for (long long i = 2; i <= n - 1; i++)
      for (long long j = 1; j <= m; j++) maxel1 = max(maxel1, a[i][j]);
  else
    for (long long i = 1; i <= n; i++)
      for (long long j = 1; j <= m; j++) maxel1 = max(maxel1, a[i][j]);
  long long max_ask, min_ask, ask_me;
  min_ask = minel + cycles;
  ask_me = a[x][y] + cycles;
  if (n <= 2)
    max_ask = maxel2 + cycles;
  else
    max_ask = max(maxel2 + cycles, maxel1 + 2 * cycles);
  if (x != 1 && x != n) ask_me += cycles;
  cout << max_ask << " " << min_ask << " " << ask_me << endl;
  return 0;
}

```


### Prompt

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

Today the kindergarten has a new group of n kids who need to be seated at the dinner table. The chairs at the table are numbered from 1 to 4n. Two kids can't sit on the same chair. It is known that two kids who sit on chairs with numbers a and b (a ≠ b) will indulge if:

  1. gcd(a, b) = 1 or,
  2. a divides b or b divides a.

gcd(a, b) — the maximum number x such that a is divisible by x and b is divisible by x.

For example, if n=3 and the kids sit on chairs with numbers 2, 3, 4, then they will indulge since 4 is divided by 2 and gcd(2, 3) = 1. If kids sit on chairs with numbers 4, 6, 10, then they will not indulge.

The teacher really doesn't want the mess at the table, so she wants to seat the kids so there are no 2 of the kid that can indulge. More formally, she wants no pair of chairs a and b that the kids occupy to fulfill the condition above.

Since the teacher is very busy with the entertainment of the kids, she asked you to solve this problem.

Input

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

Each test case consists of one line containing an integer n (1 ≤ n ≤ 100) — the number of kids.

Output

Output t lines, which contain n distinct integers from 1 to 4n — the numbers of chairs that the kids should occupy in the corresponding test case. If there are multiple answers, print any of them. You can print n numbers in any order.

Example

Input

3
2
3
4

Output

6 4
4 6 10
14 10 12 8

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using vi = vector<long long>;
using ii = pair<long long, long long>;
using vii = vector<ii>;
constexpr long long INF = 1e18;
constexpr long long MIN_INF = -1e18;
;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a = 4 * n;
    for (long long i = 0; i < n; i++) {
      cout << a << " ";
      a -= 2;
    }
    cout << "\n";
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Taro is planning a long trip by train during the summer vacation. However, in order for Taro, who is a high school student, to travel as far as possible during the summer vacation, which has only one month, he cannot make a good plan unless he finds the cheapest and the fastest way. Let's create a program to help Taro's plan so that he can enjoy a wonderful trip.

<image>

Create a program that outputs the minimum amount or the shortest time in response to inquiries by inputting track information and the number of stations.

Input

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

n m
a1 b1 cost1 time1
a2 b2 cost2 time2
::
an bn costn timen
k
p1 q1 r1
p2 q2 r2
::
pk qk rk

The first line gives the number of track information n (1 ≤ n ≤ 3000) and the number of stations m (1 ≤ m ≤ 100).

The following n lines give information on the i-th line. As information on each line, the numbers ai, bi (1 ≤ ai, bi ≤ m) of the two stations connecting the lines, the toll costi (1 ≤ costi ≤ 1000), and the travel time timei (1 ≤ timei ≤ 1000) are given. I will. However, each station shall be numbered in order from 1 to m. If ai and bi are connected by railroad tracks, both ai to bi and bi to ai can be moved at the same rate and time.

The following line is given the number of queries k (1 ≤ k ≤ 200). The next k line is given the i-th query. For each query, the departure station pi, the arrival station qi, and the type of value to output ri (0 or 1) are given. Inquiries must have a route.

The number of datasets does not exceed 50.

Output

Outputs the minimum amount or minimum time on one line for each data set. When ri is 0, the minimum amount is output, and when ri is 1, the minimum time is output.

Example

Input

6 5
1 2 200 10
1 4 400 15
1 3 250 25
2 4 100 10
4 5 150 20
3 5 300 20
2
1 5 0
1 5 1
0 0

Output

450
35

### Response

```cpp
// 2013/11/25 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

const int INF = 1000000000;

int main()
{
	while(true){
		int n, m;
		cin >> n >> m;

		if(n==0&&m==0)
			break;

		int C[100][100];
		int T[100][100];
		for(int i=0; i<m; i++){
			for(int j=0; j<m; j++){
				if(i==j){
					C[i][j] = T[i][j] = 0;
				}
				else{
					C[i][j] = T[i][j] = INF;
				}
			}
		}

		for(int i=0; i<n; i++){
			int a, b, c, t;
			cin >> a >> b >> c >> t;

			C[a-1][b-1] = C[b-1][a-1] = c;
			T[a-1][b-1] = T[b-1][a-1] = t;
		}

		for(int k=0; k<m; k++){
			for(int i=0; i<m; i++){
				for(int j=0; j<m; j++){
					C[i][j] = min(C[i][j], C[i][k]+C[k][j]);
					T[i][j] = min(T[i][j], T[i][k]+T[k][j]);
				}
			}
		}

		int k;
		cin >> k;

		for(int i=0; i<k; i++){
			int p, q, r;
			cin >> p >> q >> r;

			if(r==0){
				cout << C[p-1][q-1] << endl;
			}
			else{
				cout << T[p-1][q-1] << endl;
			}
		}
	}

	return 0;
}
```


### Prompt

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

Igor likes hexadecimal notation and considers positive integer in the hexadecimal notation interesting if each digit and each letter in it appears no more than t times. For example, if t = 3, then integers 13a13322, aaa, abcdef0123456789 are interesting, but numbers aaaa, abababab and 1000000 are not interesting.

Your task is to find the k-th smallest interesting for Igor integer in the hexadecimal notation. The integer should not contain leading zeros.

Input

The first line contains the two integers k and t (1 ≤ k ≤ 2·109, 1 ≤ t ≤ 10) — the number of the required integer and the maximum number of times some integer or letter can appear in interesting integer.

It can be shown that the answer always exists for such constraints.

Output

Print in the hexadecimal notation the only integer that is the k-th smallest interesting integer for Igor.

Examples

Input

17 1

Output

12

Input

1000000 2

Output

fca2c

Note

The first 20 interesting integers if t = 1: 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, 10, 12, 13, 14, 15. So the answer for the first example equals 12.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int64_t comb[100][100];
string hx = "0123456789abcdef";
string toHex(int64_t n) {
  string res;
  while (n > 0) {
    res += hx[n % 16];
    n /= 16;
  }
  reverse(res.begin(), res.end());
  return res;
}
vector<int> counter(int64_t n) {
  vector<int> cnt(16);
  while (n > 0) {
    cnt[n % 16]++;
    n /= 16;
  }
  return cnt;
}
int main() {
  int n, t;
  cin >> n >> t;
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j <= i; j++) {
      if (i == j || j == 0) {
        comb[i][j] = 1;
      } else {
        comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
      }
    }
  }
  if (t == 1) {
    for (int i = 1;; i++) {
      int64_t P = 15;
      for (int j = 1; j < i; j++) {
        P *= 16 - j;
      }
      if (n > P) {
        n -= P;
      } else {
        string ans;
        P /= 15;
        int fst = 1;
        string ls = "0123456789abcdef";
        while (n > P) {
          fst++;
          n -= P;
        }
        ans += ls[fst];
        ls.erase(fst, 1);
        for (int j = 1; j < i; j++) {
          P /= 16 - j;
          int snd = 0;
          while (n > P) {
            snd++;
            n -= P;
          }
          ans += ls[snd];
          ls.erase(snd, 1);
        }
        cout << ans << endl;
        return 0;
      }
    }
  } else {
    for (int i = 1; i < 16 * 16 * 16 * 16; i++) {
      auto cnt = counter(i);
      if (*max_element(cnt.begin(), cnt.end()) <= t) {
        n--;
        if (n == 0) {
          cout << toHex(i) << endl;
          return 0;
        }
      }
    }
    for (int64_t pre = 1;; pre++) {
      static int64_t dp0[5];
      static int64_t dp1[5];
      memset(dp0, 0, sizeof(dp0));
      vector<int> cnt = counter(pre);
      if (*max_element(cnt.begin(), cnt.end()) > t) {
        continue;
      }
      dp0[0] = 1;
      for (int i = 0; i < 16; i++) {
        memcpy(dp1, dp0, sizeof(dp1));
        for (int j = 0; j < 4; j++) {
          for (int k = 1; k + cnt[i] <= t && j + k <= 4; k++) {
            dp1[j + k] += dp0[j] * comb[j + k][j];
            dp1[j + k] = min(dp1[j + k], (int64_t)1e10);
          }
        }
        swap(dp0, dp1);
      }
      if (n > dp0[4]) {
        n -= dp0[4];
      } else {
        for (int i = 0; i < 16 * 16 * 16 * 16; i++) {
          auto cnt = counter((pre << 16) + i);
          if (*max_element(cnt.begin(), cnt.end()) <= t) {
            n--;
            if (n == 0) {
              cout << toHex((pre << 16) + i) << endl;
              return 0;
            }
          }
        }
      }
    }
  }
}

```


### Prompt

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

In this problem, a n × m rectangular matrix a is called increasing if, for each row of i, when go from left to right, the values strictly increase (that is, a_{i,1}<a_{i,2}<...<a_{i,m}) and for each column j, when go from top to bottom, the values strictly increase (that is, a_{1,j}<a_{2,j}<...<a_{n,j}).

In a given matrix of non-negative integers, it is necessary to replace each value of 0 with some positive integer so that the resulting matrix is increasing and the sum of its elements is maximum, or find that it is impossible.

It is guaranteed that in a given value matrix all values of 0 are contained only in internal cells (that is, not in the first or last row and not in the first or last column).

Input

The first line contains integers n and m (3 ≤ n, m ≤ 500) — the number of rows and columns in the given matrix a.

The following lines contain m each of non-negative integers — the values in the corresponding row of the given matrix: a_{i,1}, a_{i,2}, ..., a_{i,m} (0 ≤ a_{i,j} ≤ 8000).

It is guaranteed that for all a_{i,j}=0, 1 < i < n and 1 < j < m are true.

Output

If it is possible to replace all zeros with positive numbers so that the matrix is increasing, print the maximum possible sum of matrix elements. Otherwise, print -1.

Examples

Input

4 5
1 3 5 6 7
3 0 7 0 9
5 0 0 0 10
8 9 10 11 12

Output

144

Input

3 3
1 2 3
2 0 4
4 5 6

Output

30

Input

3 3
1 2 3
3 0 4
4 5 6

Output

-1

Input

3 3
1 2 3
2 3 4
3 4 2

Output

-1

Note

In the first example, the resulting matrix is as follows:

    1 3 5 6 7
    3 6 7 8 9
    5 7 8 9 10
    8 9 10 11 12

In the second example, the value 3 must be put in the middle cell.

In the third example, the desired resultant matrix does not exist.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, vis[505][505], sum;
int main() {
  memset(vis, 8001, sizeof(vis));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &vis[i][j]);
  for (int i = n; i; i--)
    for (int j = m; j; j--) {
      if (vis[i][j] == 0) vis[i][j] = min(vis[i + 1][j], vis[i][j + 1]) - 1;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (vis[i][j] >= min(vis[i + 1][j], vis[i][j + 1])) {
        puts("-1");
        return 0;
      } else
        sum += vis[i][j];
    }
  printf("%d\n", sum);
  return 0;
}

```