### Prompt

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

Valera has array a, consisting of n integers a0, a1, ..., an - 1, and function f(x), taking an integer from 0 to 2n - 1 as its single argument. Value f(x) is calculated by formula <image>, where value bit(i) equals one if the binary representation of number x contains a 1 on the i-th position, and zero otherwise.

For example, if n = 4 and x = 11 (11 = 20 + 21 + 23), then f(x) = a0 + a1 + a3.

Help Valera find the maximum of function f(x) among all x, for which an inequality holds: 0 ≤ x ≤ m.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of array elements. The next line contains n space-separated integers a0, a1, ..., an - 1 (0 ≤ ai ≤ 104) — elements of array a.

The third line contains a sequence of digits zero and one without spaces s0s1... sn - 1 — the binary representation of number m. Number m equals <image>.

Output

Print a single integer — the maximum value of function f(x) for all <image>.

Examples

Input

2
3 8
10

Output

3

Input

5
17 0 10 2 1
11010

Output

27

Note

In the first test case m = 20 = 1, f(0) = 0, f(1) = a0 = 3.

In the second sample m = 20 + 21 + 23 = 11, the maximum value of function equals f(5) = a0 + a2 = 17 + 10 = 27.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(int a, int b) { return a / gcd(a, b) * b; }
int num[N], s[N];
char b[N];
int main() {
  int n;
  cin >> n;
  int i, j;
  for (i = 0; i < n; ++i) {
    cin >> num[i];
    if (i == 0)
      s[i] = num[i];
    else
      s[i] = s[i - 1] + num[i];
  }
  cin >> b;
  int ans = -1, sum = 0;
  for (i = n - 1; i >= 0; --i) {
    if (b[i] == '1') {
      ans = max(ans, sum + (i == 0 ? 0 : s[i - 1]));
      sum += num[i];
    }
  }
  cout << max(ans, sum) << endl;
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (xi, yi).

They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula <image>.

The success of the operation relies on the number of pairs (i, j) (1 ≤ i < j ≤ n), such that the distance between watchman i and watchmen j calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.

Input

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

Each of the following n lines contains two integers xi and yi (|xi|, |yi| ≤ 109).

Some positions may coincide.

Output

Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.

Examples

Input

3
1 1
7 5
1 5

Output

2

Input

6
0 0
0 1
0 2
-1 1
0 1
1 1

Output

11

Note

In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <image> for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long fp(long long n, long long p) {
  if (p == 0) return 1;
  if (p == 1) return n;
  long long res;
  res = fp(n, p / 2);
  res = (res * res);
  if (p % 2) res = (res * n);
  return res;
}
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first != b.first)
    return (a.first < b.first);
  else
    return (a.second < b.second);
}
bool comp2(pair<long long, long long> a, pair<long long, long long> b) {
  return (a.second < b.second);
}
long long n, m, a, b, ans = 0;
pair<long long, long long> arr[200001];
int main() {
  ios::sync_with_stdio(0);
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i].first >> arr[i].second;
  }
  sort(arr, arr + n, comp2);
  a = 0;
  while (a < n) {
    long long l = a, cur = arr[a].second;
    while (a < n) {
      if (arr[a].second == cur)
        a++;
      else
        break;
    }
    long long t = a - l;
    ans += t * (t - 1) / 2;
  }
  sort(arr, arr + n, comp);
  a = 0;
  while (a < n) {
    long long l = a, cur = arr[a].first;
    while (a < n) {
      if (arr[a].first == cur)
        a++;
      else
        break;
    }
    long long t = a - l;
    ans += t * (t - 1) / 2;
  }
  a = 0;
  while (a < n) {
    int l = a, cux = arr[a].first, cuy = arr[a].second;
    while (a < n) {
      if (cux == arr[a].first && cuy == arr[a].second)
        a++;
      else
        break;
    }
    long long q = a - l;
    ans -= q * (q - 1) / 2;
  }
  cout << ans << '\n';
  return 0;
}

```


### Prompt

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

There is a flat island whose shape is a perfect square. On this island, there are three habitants whose names are IC, PC, and ACM Every day, one jewel is dropped from the heaven. Just as the jewel touches the ground, IC, PC, and ACM leave their houses simultaneously, run with the same speed, and then a person who first touched the jewel can get the jewel. Hence, the person whose house is nearest to the location of the jewel is the winner of that day.

They always have a quarrel with each other, and therefore their houses are located at distinct places. The locations of their houses are fixed. This jewel falls at a random point on the island, that is, all points on the island have even chance.

When three are two or more persons whose houses are simultaneously nearest, the last person in the order of

IC, PC, ACM

obtains the jewel.

Our interest is to know the probability for IC to get the jewel under this situation.

Input

The input describes one problem instance per line. Each line contains the x- and y-coordinates of IC's home, those of PC's, and those of ACM's in this order. Note that the houses of IC, PC and ACM are located at distinct places. The end of the input is indicated by a line with six zeros.

The coordinates of the whole island are given by (0, 10000) × (0, 10000) and coordinates of houses are given in integer numbers between 1 and 9999, inclusive. It should be noted that the locations of the jewels are arbitrary places on the island and their coordinate values are not necessarily integers.

Output

For each input line, your program should output its sequence number starting from 1, and the probability for the instance. The computed probability values should have errors less than 10-5.

The sequence number and the probability should be printed on the same line. The two numbers should be separated by a space.

Example

Input

2000 2000 8000 8000 9000 9500
2500 2500 7500 2500 2500 7500
0 0 0 0 0 0

Output

1 0.50000
2 0.25000

### Response

```cpp
#include<iostream>
#include<cfloat>
#include<cassert>
#include<cmath>
#include<vector>

using namespace std;

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS )
#define dle(a, b) (equals(a, b) || a < b )
static const double PI = acos(-1);

class Point{
    public:
    double x, y;

    Point ( double x = 0, double y = 0): x(x), y(y){}

    Point operator + ( Point p ){ return Point(x + p.x, y + p.y); }
    Point operator - ( Point p ){ return Point(x - p.x, y - p.y); }
    Point operator * ( double a ){ return Point(x*a, y*a); }
    Point operator / ( double a ){ return Point(x/a, y/a); }

    double abs() { return sqrt(norm());}
    double norm() { return x*x + y*y; }

    bool operator < ( const Point &p ) const {
	return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == ( const Point &p ) const {
	return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
    }
};

typedef Point Vector;

class Segment{
    public:
    Point p1, p2;
    Segment(Point s = Point(), Point t = Point()): p1(s), p2(t){}
};

typedef Segment Line;

typedef vector<Point> Polygon;

double norm( Vector a ){ return a.x*a.x + a.y*a.y; }
double abs( Vector a ){ return sqrt(norm(a)); }
Point polar( double a, double r ){ return Point(cos(r)*a, sin(r)*a);}
double getDistance( Vector a, Vector b ){ return abs(a - b); }
double dot( Vector a, Vector b ){ return a.x*b.x + a.y*b.y; }
double cross( Vector a, Vector b ){ return a.x*b.y - a.y*b.x; }

double arg(Vector p){
    return atan2(p.y, p.x);
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw( Point p0, Point p1, Point p2 ){
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if ( cross(a, b) > EPS ) return COUNTER_CLOCKWISE;
    if ( cross(a, b) < -EPS ) return CLOCKWISE;
    if ( dot(a, b) < -EPS ) return ONLINE_BACK;
    if ( norm(a) < norm(b) ) return ONLINE_FRONT;
    return ON_SEGMENT;
}

Point getCrossPointLines( Line s1, Line s2){
    Vector a = s1.p2 - s1.p1;
    Vector base = s2.p2 - s2.p1;
    return s1.p1 + a * cross(base, s2.p1 - s1.p1)/cross(base, a);
}

double getAngleTheta(Point p){
    double polar = atan2(p.y, p.x);
    double rad = (dle(0, polar))? polar : 2*acos(-1)+polar;
    return rad*180.0/acos(-1);
}

double getAngle(Point p){
    double polar = atan2(p.y, p.x);
    return (dle(0, polar))? polar : 2*acos(-1)+polar;
}

Polygon cutPolygon( Polygon P, Line l ){
    Polygon u;
    for ( int i = 0; i < P.size(); i++ ){
	Point a = P[i], b = P[(i+1)%P.size()];
	if ( ccw(l.p1, l.p2, a) != CLOCKWISE ) u.push_back(a);
	if ( ccw(l.p1, l.p2, a) * ccw(l.p1, l.p2, b) == -1 ){
	    u.push_back(getCrossPointLines(Segment(a, b), l));
	}
    }
    return u;
}

Line getCutLine( Point p1, Point p2 ){
    Vector v = p2 - p1;
    v = polar(abs(v), arg(v)+PI/2.0);
    double dx = (p2.x + p1.x)/2.0;
    double dy = (p2.y + p1.y)/2.0;
    return Line(Point(dx, dy), Point(v.x+dx, v.y+dy));
}

double getArea(Polygon p){
    double sum = 0.0;
    for(int i = 0; i < p.size(); i++){
	sum += cross(p[i], p[(i+1)%p.size()]);
    }
    return abs(sum/2);
}

int main(){
    double x1, y1, x2, y2, x3, y3;
    Point P[3];
    Polygon B;
    int tcase = 1;
    while(1){
	cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
	if ( x1 == 0 && y1 == 0 && x2 == 0 && y2 == 0 && x3 == 0 && y3 == 0 ) break;
	P[0] = Point(x1, y1);
	P[1] = Point(x2, y2);
	P[2] = Point(x3, y3);
	B.clear();
	B.push_back(Point(0, 0));
	B.push_back(Point(10000, 0));
	B.push_back(Point(10000, 10000));
	B.push_back(Point(0, 10000));

	B = cutPolygon(B, getCutLine(P[0], P[1]));
	B = cutPolygon(B, getCutLine(P[0], P[2]));

	printf("%d %.12lf\n", tcase++, getArea(B)/(100000000));

    }
    return 0;
}
```


### Prompt

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

It has been noted that if some ants are put in the junctions of the graphene integer lattice then they will act in the following fashion: every minute at each junction (x, y) containing at least four ants a group of four ants will be formed, and these four ants will scatter to the neighbouring junctions (x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1) — one ant in each direction. No other ant movements will happen. Ants never interfere with each other.

Scientists have put a colony of n ants into the junction (0, 0) and now they wish to know how many ants will there be at some given junctions, when the movement of the ants stops.

Input

First input line contains integers n (0 ≤ n ≤ 30000) and t (1 ≤ t ≤ 50000), where n is the number of ants in the colony and t is the number of queries. Each of the next t lines contains coordinates of a query junction: integers xi, yi ( - 109 ≤ xi, yi ≤ 109). Queries may coincide.

It is guaranteed that there will be a certain moment of time when no possible movements can happen (in other words, the process will eventually end).

Output

Print t integers, one per line — the number of ants at the corresponding junctions when the movement of the ants stops.

Examples

Input

1 3
0 1
0 0
0 -1

Output

0
1
0

Input

6 5
0 -2
0 -1
0 0
0 1
0 2

Output

0
1
2
1
0

Note

In the first sample the colony consists of the one ant, so nothing happens at all.

In the second sample the colony consists of 6 ants. At the first minute 4 ants scatter from (0, 0) to the neighbouring junctions. After that the process stops.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000, mi = 500;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int n, m, v[maxn][maxn];
void dfs(const int x, const int y) {
  int w = v[x][y] >> 2;
  v[x][y] &= 3;
  if (w == 0) return;
  for (int i = 0; i < 4; ++i) {
    int a = x + dx[i];
    int b = y + dy[i];
    v[a][b] += w;
    if (v[a][b] >= 4) dfs(a, b);
  }
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    v[mi][mi] = n;
    dfs(mi, mi);
    int x, y;
    for (int i = 0; i < m; ++i) {
      scanf("%d%d", &x, &y);
      x += mi;
      y += mi;
      if (x >= 0 && x < maxn && y >= 0 && y < maxn)
        printf("%d\n", v[x][y]);
      else
        printf("0\n");
    }
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Vasya has a pile, that consists of some number of stones. n times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile.

You are given n operations which Vasya has made. Find the minimal possible number of stones that can be in the pile after making these operations.

Input

The first line contains one positive integer n — the number of operations, that have been made by Vasya (1 ≤ n ≤ 100).

The next line contains the string s, consisting of n symbols, equal to "-" (without quotes) or "+" (without quotes). If Vasya took the stone on i-th operation, s_i is equal to "-" (without quotes), if added, s_i is equal to "+" (without quotes).

Output

Print one integer — the minimal possible number of stones that can be in the pile after these n operations.

Examples

Input

3
---

Output

0

Input

4
++++

Output

4

Input

2
-+

Output

1

Input

5
++-++

Output

3

Note

In the first test, if Vasya had 3 stones in the pile at the beginning, after making operations the number of stones will be equal to 0. It is impossible to have less number of piles, so the answer is 0. Please notice, that the number of stones at the beginning can't be less, than 3, because in this case, Vasya won't be able to take a stone on some operation (the pile will be empty).

In the second test, if Vasya had 0 stones in the pile at the beginning, after making operations the number of stones will be equal to 4. It is impossible to have less number of piles because after making 4 operations the number of stones in the pile increases on 4 stones. So, the answer is 4.

In the third test, if Vasya had 1 stone in the pile at the beginning, after making operations the number of stones will be equal to 1. It can be proved, that it is impossible to have less number of stones after making the operations.

In the fourth test, if Vasya had 0 stones in the pile at the beginning, after making operations the number of stones will be equal to 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> s;
  int m = 0;
  int a = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '+')
      m++;
    else
      m--;
    a = max(a, m);
  }
  cout << a;
  return 0;
}

```


### Prompt

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

Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.

Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.

What is the maximum number of apples he can collect?

Input

The first line contains one number n (1 ≤ n ≤ 100), the number of apple trees in Lala Land.

The following n lines contains two integers each xi, ai ( - 105 ≤ xi ≤ 105, xi ≠ 0, 1 ≤ ai ≤ 105), representing the position of the i-th tree and number of apples on it.

It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.

Output

Output the maximum number of apples Amr can collect.

Examples

Input

2
-1 5
1 5

Output

10

Input

3
-2 2
1 4
-1 3

Output

9

Input

3
1 9
3 5
7 10

Output

9

Note

In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.

In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.

In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int getint() {
  int t = 0, flag = 1;
  char c = getchar();
  while (c < '0' || c > '9' || c == '-') {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') t = t * 10 + c - '0', c = getchar();
  return t * flag;
}
int GCD(int m, int n) { return !m ? n : GCD(n % m, m); }
template <typename T>
string to_string(T value) {
  ostringstream os;
  os << value;
  return os.str();
}
long long MultMod(long long a, long long b, long long MOD) {
  a %= MOD;
  b %= MOD;
  long long ret = 0;
  while (b) {
    if (b & 1) {
      ret += a;
      if (ret >= MOD) ret -= MOD;
    }
    a = a << 1;
    if (a >= MOD) a -= MOD;
    b = b >> 1;
  }
  return ret;
}
int x, a, n, t, m;
vector<pair<int, int> > vp, vn;
int main() {
  while (cin >> n) {
    vp.clear(), vn.clear();
    for (int i = 0; i < n; i++) {
      cin >> x >> a;
      if (x > 0)
        vp.push_back({x, a});
      else
        vn.push_back({-x, a});
    }
    sort(vp.begin(), vp.end());
    sort(vn.begin(), vn.end());
    int ans = 0;
    if (vp.size() == vn.size()) {
      for (int i = 0; i < vp.size(); i++) ans += vp[i].second + vn[i].second;
    } else {
      int minsize = min(vp.size(), vn.size());
      for (int i = 0; i < minsize; i++) ans += vp[i].second + vn[i].second;
      if (vp.size() > vn.size())
        ans += vp[minsize].second;
      else
        ans += vn[minsize].second;
    }
    cout << ans << endl;
  }
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

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

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

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

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

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

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

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

Input

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

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

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

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

Output

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

Examples

Input

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

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

Output

AE somewhere

Input

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

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

Output

AE in line 3

Input

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

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

Output

Unhandled Exception

Note

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

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, l1, c1 = 0, k;
  string z[100010], z1 = "", z2 = "", z3 = "";
  bool v;
  cin >> n;
  cin.ignore();
  for (int i = 0; i < n; i++) getline(cin, z[i]);
  for (int i = 0; i < n; i++) {
    l1 = z[i].length();
    for (int j = 0; j <= l1 - 3; j++)
      if (z[i][j] == 't' && z[i][j + 1] == 'r' && z[i][j + 2] == 'y')
        c1++;
      else if (z[i][j] >= 'a' && z[i][j] <= 'z')
        break;
    for (int j = 0; j <= l1 - 5; j++)
      if (z[i][j] == 'c' && z[i][j + 1] == 'a' && z[i][j + 2] == 't' &&
          z[i][j + 3] == 'c' && z[i][j + 4] == 'h')
        c1--;
      else if (z[i][j] >= 'a' && z[i][j] <= 'z')
        break;
    v = false;
    for (int j = 0; j <= l1 - 5; j++) {
      if (z[i][j] == 't' && z[i][j + 1] == 'h' && z[i][j + 2] == 'r' &&
          z[i][j + 3] == 'o' && z[i][j + 4] == 'w') {
        k = j + 5;
        z1 = "";
        while (!((z[i][k] >= 'a' && z[i][k] <= 'z') ||
                 (z[i][k] >= 'A' && z[i][k] <= 'Z')))
          k++;
        while (((z[i][k] >= 'a' && z[i][k] <= 'z') ||
                (z[i][k] >= 'A' && z[i][k] <= 'Z'))) {
          z1 += z[i][k];
          k++;
        }
        k = i + 1;
        v = true;
        break;
      } else if (z[i][j] >= 'a' && z[i][j] <= 'z')
        break;
    }
    if (v) break;
  }
  v = false;
  c1 = 0;
  int f = 0;
  for (int i = k; i < n; i++) {
    for (int j = 0; j <= l1 - 3; j++)
      if (z[i][j] == 't' && z[i][j + 1] == 'r' && z[i][j + 2] == 'y')
        c1++;
      else if (z[i][j] >= 'a' && z[i][j] <= 'z')
        break;
    for (int j = 0; j <= l1 - 5; j++)
      if (z[i][j] == 'c' && z[i][j + 1] == 'a' && z[i][j + 2] == 't' &&
          z[i][j + 3] == 'c' && z[i][j + 4] == 'h') {
        if (c1 == 0) {
          f = j + 5;
          while (z[i][f] == '(' || z[i][f] == ' ') f++;
          z2 = "";
          while (z[i][f] != ' ' && z[i][f] != ',') {
            z2 += z[i][f];
            f++;
          }
          if (z1 == z2) {
            v = true;
            while (z[i][f] != '"') f++;
            f++;
            z3 = "";
            while (z[i][f] != '"') {
              z3 += z[i][f];
              f++;
            }
            break;
          }
        } else
          c1--;
      } else if (z[i][j] >= 'a' && z[i][j] <= 'z')
        break;
    if (v) {
      cout << z3;
      return 0;
    }
  }
  cout << "Unhandled Exception";
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:

  * Include a person to the chat ('Add' command).
  * Remove a person from the chat ('Remove' command).
  * Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command).

Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.

Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.

As Polycarp has no time, he is asking for your help in solving this problem.

Input

Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:

  * +<name> for 'Add' command.
  * -<name> for 'Remove' command.
  * <sender_name>:<message_text> for 'Send' command.

<name> and <sender_name> is a non-empty sequence of Latin letters and digits. <message_text> can contain letters, digits and spaces, but can't start or end with a space. <message_text> can be an empty line.

It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc.

All names are case-sensitive.

Output

Print a single number — answer to the problem.

Examples

Input

+Mike
Mike:hello
+Kate
+Dmitry
-Dmitry
Kate:hi
-Kate

Output

9

Input

+Mike
-Mike
+Mike
Mike:Hi   I am here
-Mike
+Kate
-Kate

Output

14

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string com;
  map<string, bool> mp;
  int ans = 0;
  while (getline(cin, com)) {
    if (com[0] == '+') {
      com.erase(com.begin(), com.begin() + 1);
      mp[com] = 1;
    } else if (com[0] == '-') {
      com.erase(com.begin(), com.begin() + 1);
      mp[com] = 0;
    } else {
      int len = com.size() - com.find(':') - 1, cnt = 0;
      for (map<string, bool>::iterator it = mp.begin(); it != mp.end(); it++) {
        if (it->second) cnt++;
      }
      ans += cnt * len;
    }
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

For a dictionary $M$ that stores elements formed by a pair of a string key and an integer value, perform a sequence of the following operations. Note that multiple elements can have equivalent keys.

* insert($key$, $x$): Insert an element formed by a pair of $key$ and $x$ to $M$.
* get($key$): Print all values with the specified $key$.
* delete($key$): Delete all elements with the specified $key$.
* dump($L$, $R$): Print all elements formed by a pair of the key and the value such that the key is greater than or equal to $L$ and less than or equal to $R$ in lexicographic order.

Constraints

* $1 \leq q \leq 200,000$
* $1 \leq x \leq 1,000,000,000$
* $1 \leq $ length of $key$ $ \leq 20$
* $key$ consists of lower-case letters
* $L \leq R$ in lexicographic order
* The total number of elements printed by get operations does not exceed $500,000$
* The total number of elements printed by dump operations does not exceed $500,000$

Input

The input is given in the following format.

$q$
$query_1$
$query_2$
:
$query_q$

Each query $query_i$ is given by

0 $key$ $x$

or

1 $key$

or

2 $key$

or

3 $L$ $R$

where the first digits 0, 1, 2 and 3 represent insert, get, delete and dump operations.

Output

For each get operation, print the corresponding values in the order of insertions.
For each dump operation, print the corresponding elements formed by a pair of the key and the value. For the dump operation, print the elements in ascending order of the keys, in case of a tie, in the order of insertions.

Example

Input

10
0 blue 6
0 red 1
0 blue 4
0 white 5
1 red
1 blue
2 red
1 black
1 red
3 w z

Output

1
6
4
white 5

### Response

```cpp
#include <iostream>
#include <map>
#include <set>
#include <string>
#define int long long
using namespace std;
multimap<string, int>m;
set<string>s;
signed main() {
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		int p; string k, l, r;
		cin >> p;
		if (p == 0) {
			cin >> k >> p;
			s.insert(k); m.insert(make_pair(k, p));
		}
		else if (p == 1) {
			cin >> k;
			for (auto i = m.lower_bound(k); i != m.upper_bound(k); i++)	cout << i -> second << endl;

		}
		else if (p == 2) {
			cin >> k;
			s.erase(k);
			m.erase(m.equal_range(k).first, m.equal_range(k).second);
		}
		else {
			cin >> l >> r;
			for (auto i = m.lower_bound(l); i != m.upper_bound(r); i++)cout << i -> first << ' ' << i -> second << endl;
		}
	}
}

```


### Prompt

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

Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.

Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy:

  * Each piece should contain at least l numbers.
  * The difference between the maximal and the minimal number on the piece should be at most s.

Please help Alexandra to find the minimal number of pieces meeting the condition above.

Input

The first line contains three space-separated integers n, s, l (1 ≤ n ≤ 105, 0 ≤ s ≤ 109, 1 ≤ l ≤ 105).

The second line contains n integers ai separated by spaces ( - 109 ≤ ai ≤ 109).

Output

Output the minimal number of strip pieces.

If there are no ways to split the strip, output -1.

Examples

Input

7 2 2
1 3 1 2 4 1 2

Output

3

Input

7 2 2
1 100 1 100 1 100 1

Output

-1

Note

For the first sample, we can split the strip into 3 pieces: [1, 3, 1], [2, 4], [1, 2].

For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = int(1e5) + 100;
int lmin, lmax, rmin, rmax, stmin[maxn], stmax[maxn], posmin[maxn],
    posmax[maxn], f[maxn];
int n, s, l;
void ad(int i, int x) {
  while (rmin > lmin && stmin[rmin - 1] >= x) rmin--;
  rmin++;
  stmin[rmin - 1] = x;
  posmin[rmin - 1] = i;
  while (rmax > lmax && stmax[rmax - 1] <= x) rmax--;
  rmax++;
  stmax[rmax - 1] = x;
  posmax[rmax - 1] = i;
}
void update(int &v, int i) {
  while ((stmax[lmax] - stmin[lmin] > s || f[v - 1] == -1) && (v <= i)) {
    v++;
    if (posmax[lmax] < v) lmax++;
    if (posmin[lmin] < v) lmin++;
  }
}
int main() {
  cin >> n >> s >> l;
  int v = 1;
  for (int i = 1; i <= n; i++) f[i] = -1;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    ad(i, x);
    update(v, i);
    if (i - v + 1 >= l) f[i] = f[v - 1] + 1;
  }
  cout << f[n];
}

```


### Prompt

Develop a solution in CPP to the problem described below:

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

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

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

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

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

Input

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

Output

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

Examples

Input

aba

Output

aba

Input

ab

Output

aabaa

Note

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = INT_MAX;
const long long int infl = LLONG_MAX;
int main() {
  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  string s;
  cin >> s;
  cout << s;
  int n = s.length();
  for (int i = n - 1; i >= 0; i--) {
    cout << s[i];
  }
  cout << endl;
  return 0;
}

```


### Prompt

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

Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from 1 to n and then 3n times takes a random pair of different elements and swaps them. Alex envies Petr and tries to imitate him in all kind of things. Alex has also come up with a problem about random permutation. He generates a random permutation just like Petr but swaps elements 7n+1 times instead of 3n times. Because it is more random, OK?!

You somehow get a test from one of these problems and now you want to know from which one.

Input

In the first line of input there is one integer n (10^{3} ≤ n ≤ 10^{6}).

In the second line there are n distinct integers between 1 and n — the permutation of size n from the test.

It is guaranteed that all tests except for sample are generated this way: First we choose n — the size of the permutation. Then we randomly choose a method to generate a permutation — the one of Petr or the one of Alex. Then we generate a permutation using chosen method.

Output

If the test is generated via Petr's method print "Petr" (without quotes). If the test is generated via Alex's method print "Um_nik" (without quotes).

Example

Input

5
2 4 5 1 3

Output

Petr

Note

Please note that the sample is not a valid test (because of limitations for n) and is given only to illustrate input/output format. Your program still has to print correct answer to this test to get AC.

Due to randomness of input hacks in this problem are forbidden.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[1000006];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n; i++) {
      if (a[i] == i) continue;
      while (a[i] != i) {
        cnt++;
        swap(a[i], a[a[i]]);
      }
    }
    if ((cnt % 2) == (n % 2))
      puts("Petr");
    else
      puts("Um_nik");
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out a survey to the engineering team asking each engineer the number of the desk they currently sit at, and the number of the desk they would like to sit at (which may be the same as their current desk). Each engineer must either remain where they sit, or move to the desired seat they indicated in the survey. No two engineers currently sit at the same desk, nor may any two engineers sit at the same desk in the new seating arrangement.

How many seating arrangements can you create that meet the specified requirements? The answer may be very large, so compute it modulo 1000000007 = 109 + 7.

Input

Input will begin with a line containing N (1 ≤ N ≤ 100000), the number of engineers.

N lines follow, each containing exactly two integers. The i-th line contains the number of the current desk of the i-th engineer and the number of the desk the i-th engineer wants to move to. Desks are numbered from 1 to 2·N. It is guaranteed that no two engineers sit at the same desk.

Output

Print the number of possible assignments, modulo 1000000007 = 109 + 7.

Examples

Input

4
1 5
5 2
3 7
7 3

Output

6

Input

5
1 10
2 10
3 10
4 10
5 5

Output

5

Note

These are the possible assignments for the first example:

  * 1 5 3 7
  * 1 2 3 7
  * 5 2 3 7
  * 1 5 7 3
  * 1 2 7 3
  * 5 2 7 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
template <typename T>
inline void Max(T &a, T &b) {
  if (a < b) a = b;
}
template <typename T>
inline void Min(T &a, T &b) {
  if (a > b) a = b;
}
const double pi = (double)acos(-1.0);
const double eps = (double)1e-10;
const int INF = (int)0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 10;
const int MAXM = (int)1e5 + 10;
int n;
int p[MAXN];
int cnt[MAXN];
int mark[MAXN];
int Find(int x) { return x == p[x] ? x : p[x] = Find(p[x]); }
void work() {
  scanf("%d", &n);
  for (int i = 1; i <= n * 2; i++) p[i] = i;
  for (int i = 1; i <= n; i++) {
    int x, y, u, v;
    u = read();
    v = read();
    x = Find(u);
    y = Find(v);
    if (u == v) {
      mark[x] = 1;
    } else if (x == y) {
      mark[x] = 2;
    } else {
      p[x] = y;
    }
  }
  for (int i = 1; i <= n * 2; i++) {
    if (mark[i] == 1) mark[Find(i)] = cnt[Find(i)] = 1;
    if (mark[i] == 2) mark[Find(i)] = cnt[Find(i)] = 2;
  }
  for (int i = 1; i <= 2 * n; i++) {
    int x = Find(i);
    if (mark[x]) continue;
    cnt[x]++;
  }
  long long ans = 1;
  for (int i = 1; i <= n * 2; i++)
    if (p[i] == i) {
      ans = ans * cnt[i] % MOD;
    }
  printf("%I64d\n", ans);
}
int main() {
  work();
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node.

Let's index all the nodes of the tree such that

  * The root is number 1
  * Each internal node i (i ≤ 2h - 1 - 1) will have a left child with index = 2i and a right child with index = 2i + 1

The level of a node is defined as 1 for a root, or 1 + level of parent of the node otherwise. The vertices of the level h are called leaves. The exit to the maze is located at some leaf node n, the player doesn't know where the exit is so he has to guess his way out!

In the new version of the game the player is allowed to ask questions on the format "Does the ancestor(exit, i) node number belong to the range [L, R]?". Here ancestor(v, i) is the ancestor of a node v that located in the level i. The game will answer with "Yes" or "No" only. The game is designed such that it doesn't always answer correctly, and sometimes it cheats to confuse the player!.

Amr asked a lot of questions and got confused by all these answers, so he asked you to help him. Given the questions and its answers, can you identify whether the game is telling contradictory information or not? If the information is not contradictory and the exit node can be determined uniquely, output its number. If the information is not contradictory, but the exit node isn't defined uniquely, output that the number of questions is not sufficient. Otherwise output that the information is contradictory.

Input

The first line contains two integers h, q (1 ≤ h ≤ 50, 0 ≤ q ≤ 105), the height of the tree and the number of questions respectively.

The next q lines will contain four integers each i, L, R, ans (1 ≤ i ≤ h, 2i - 1 ≤ L ≤ R ≤ 2i - 1, <image>), representing a question as described in the statement with its answer (ans = 1 if the answer is "Yes" and ans = 0 if the answer is "No").

Output

If the information provided by the game is contradictory output "Game cheated!" without the quotes.

Else if you can uniquely identify the exit to the maze output its index.

Otherwise output "Data not sufficient!" without the quotes.

Examples

Input

3 1
3 4 6 0

Output

7

Input

4 3
4 10 14 1
3 6 6 0
2 3 3 1

Output

14

Input

4 2
3 4 6 1
4 12 15 1

Output

Data not sufficient!

Input

4 2
3 4 5 1
2 3 3 1

Output

Game cheated!

Note

Node u is an ancestor of node v if and only if

  * u is the same node as v,
  * u is the parent of node v,
  * or u is an ancestor of the parent of node v.

In the first sample test there are 4 leaf nodes 4, 5, 6, 7. The first question says that the node isn't in the range [4, 6] so the exit is node number 7.

In the second sample test there are 8 leaf nodes. After the first question the exit is in the range [10, 14]. After the second and the third questions only node number 14 is correct. Check the picture below to fully understand.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long h, q, a, l1, r1, x, f[51], M, lm, rm, s, lh, rh, mm;
pair<long long, long long> t, k[100010], t1;
vector<pair<long long, long long> > w, la;
int main() {
  cin >> h >> q;
  f[0] = 1;
  for (long long i = 1; i <= h; i++) {
    f[i] = f[i - 1] * 2;
  }
  M = f[h] + 1;
  lm = f[h - 1];
  rm = f[h] - 1;
  s = 0;
  for (long long i = 1; i <= q; i++) {
    cin >> a >> l1 >> r1 >> x;
    long long ll, rr;
    ll = l1 * f[h - a];
    rr = ll + (r1 - l1 + 1) * f[h - a] - 1;
    if ((ll > rm || rr < lm) && x == 1) {
      cout << "Game cheated!";
      return 0;
    }
    if (x == 1) {
      lm = max(ll, lm);
      rm = min(rm, rr);
    }
    if (x == 0) {
      s++;
      k[s] = make_pair(ll, rr);
    }
  }
  lh = lm;
  rh = rm;
  for (long long i = 1; i <= s; i++) {
    w.push_back(make_pair(k[i].first, -1 * i));
    w.push_back(make_pair(k[i].second, i));
    if (k[i].first < lm && k[i].second > rm) {
      cout << "Game cheated!";
      return 0;
    }
  }
  long long cd = lm, cc = rm, s1 = 0, s2 = 0, e = -1;
  mm = 0;
  if (!w.empty()) {
    sort(w.begin(), w.end());
    la.push_back(make_pair(lm - 1, 1));
    la.push_back(make_pair(rm + 1, -1));
    for (long long i = 0; i <= w.size() - 1; i++) {
      if (w[i].second < 0) {
        e = k[-1 * w[i].second].second;
        if (w[i].first >= lm && w[i].first <= rm)
          la.push_back(make_pair(w[i].first, -1));
        while (true) {
          if (w[i].first == e && w[i].second > 0) break;
          i++;
          if (w[i].second < 0) {
            long long kx = k[-1 * w[i].second].second;
            if (kx <= rm) e = max(e, kx);
          }
        }
        if (e >= lm && e <= rm) la.push_back(make_pair(e, 1));
      }
    }
    sort(la.begin(), la.end());
    for (long long i = 1; i < la.size(); i++) {
      if (la[i].second == -1 && la[i - 1].second == 1) {
        if (la[i].first - 1 >= la[i - 1].first + 1) {
          cd = la[i - 1].first + 1;
          cc = la[i].first - 1;
          mm += cc - cd + 1;
        }
      }
    }
  } else {
    mm += cc - cd + 1;
  }
  if (mm == 0)
    cout << "Game cheated!";
  else if (mm > 1)
    cout << "Data not sufficient!";
  else
    cout << cd;
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor.

At each cycle each core of the processor gets one instruction: either do nothing, or the number of the memory cell (the core will write an information to the cell). After receiving the command, the core executes it immediately. Sometimes it happens that at one cycle, multiple cores try to write the information into a single cell. Unfortunately, the developers did not foresee the possibility of resolving conflicts between cores, so in this case there is a deadlock: all these cores and the corresponding memory cell are locked forever. Each of the locked cores ignores all further commands, and no core in the future will be able to record an information into the locked cell. If any of the cores tries to write an information into some locked cell, it is immediately locked.

The development team wants to explore the deadlock situation. Therefore, they need a program that will simulate the processor for a given set of instructions for each core within m cycles . You're lucky, this interesting work is entrusted to you. According to the instructions, during the m cycles define for each core the number of the cycle, during which it will become locked. It is believed that initially all cores and all memory cells are not locked.

Input

The first line contains three integers n, m, k (1 ≤ n, m, k ≤ 100). Then follow n lines describing instructions. The i-th line contains m integers: xi1, xi2, ..., xim (0 ≤ xij ≤ k), where xij is the instruction that must be executed by the i-th core at the j-th cycle. If xij equals 0, then the corresponding instruction is «do nothing». But if xij is a number from 1 to k, then the corresponding instruction is «write information to the memory cell number xij».

We assume that the cores are numbered from 1 to n, the work cycles are numbered from 1 to m and the memory cells are numbered from 1 to k.

Output

Print n lines. In the i-th line print integer ti. This number should be equal to 0 if the i-th core won't be locked, or it should be equal to the number of the cycle when this core will be locked.

Examples

Input

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

Output

1
1
3
0

Input

3 2 2
1 2
1 2
2 2

Output

1
1
0

Input

1 1 1
0

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int ta[1000], ya[1000], t[1000], n, m, k, a[1000][1000];
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int i = 0; i <= k; i++) {
      t[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
      if (ya[i] == 0) {
        if (ta[a[i][j]] == 0) {
          t[a[i][j]]++;
        } else {
          ya[i] = j;
        }
      }
    }
    for (int i = 1; i <= k; i++) {
      if (t[i] > 1) {
        ta[i] = 1;
        for (int l = 1; l <= n; l++) {
          if (a[l][j] == i && ya[l] == 0) {
            ya[l] = j;
          }
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << ya[i] << endl;
  }
  return 0;
}

```


### Prompt

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

At school Vasya got an impressive list of summer reading books. Unlike other modern schoolchildren, Vasya loves reading, so he read some book each day of the summer.

As Vasya was reading books, he was making notes in the Reader's Diary. Each day he wrote the orderal number of the book he was reading. The books in the list are numbered starting from 1 and Vasya was reading them in the order they go in the list. Vasya never reads a new book until he finishes reading the previous one. Unfortunately, Vasya wasn't accurate and some days he forgot to note the number of the book and the notes for those days remained empty.

As Vasya knows that the literature teacher will want to check the Reader's Diary, so he needs to restore the lost records. Help him do it and fill all the blanks. Vasya is sure that he spends at least two and at most five days for each book. Vasya finished reading all the books he had started. Assume that the reading list contained many books. So many, in fact, that it is impossible to read all of them in a summer. If there are multiple valid ways to restore the diary records, Vasya prefers the one that shows the maximum number of read books.

Input

The first line contains integer n — the number of summer days (2 ≤ n ≤ 2·105). The second line contains n integers a1, a2, ... an — the records in the diary in the order they were written (0 ≤ ai ≤ 105). If Vasya forgot to write the number of the book on the i-th day, then ai equals 0.

Output

If it is impossible to correctly fill the blanks in the diary (the diary may contain mistakes initially), print "-1".

Otherwise, print in the first line the maximum number of books Vasya could have read in the summer if we stick to the diary. In the second line print n integers — the diary with correctly inserted records. If there are multiple optimal solutions, you can print any of them.

Examples

Input

7
0 1 0 0 0 3 0

Output

3
1 1 2 2 3 3 3

Input

8
0 0 0 0 0 0 0 0

Output

4
1 1 2 2 3 3 4 4

Input

4
0 0 1 0

Output

1
1 1 1 1

Input

4
0 0 0 3

Output

-1

### 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;
}
int ok(int l, int r, int a, int b) {
  if (l > r) {
    if ((a + 1) == b) return 1;
    return 0;
  }
  int gap = r - l + 1;
  int lage = b - a - 1;
  if (5 * lage < gap) return 0;
  if ((2 * lage) > gap) return 0;
  return 1;
}
int a[400007];
int n;
int dp[400007][7];
int P[400007];
int N[400007];
int ar[400007];
int lol(int p, int pv) {
  if (p == (n + 1)) {
    int vl = a[P[p]];
    int lstend = P[p] + ar[P[p]] + pv;
    if (P[p] == 0) lstend++;
    int gap = p - lstend;
    if (gap == 1) return -2000000000;
    return vl + (gap / 2);
  }
  int &res = dp[p][pv];
  if (res != -1) return res;
  res = -2000000000;
  int lstend = P[p] + ar[P[p]] + pv;
  if (P[p] == 0) lstend++;
  for (int bac = 0; bac < 5; bac++) {
    for (int fr = 0; fr < 5; fr++) {
      if ((bac + fr + 1) > 5) continue;
      if ((bac + fr + 1) < 2) continue;
      if ((p - bac) < lstend) continue;
      if ((p + fr) >= N[p]) continue;
      if ((p + fr) < (p + ar[p] - 1)) continue;
      int tp = ok(lstend, p - bac - 1, a[P[p]], a[p]);
      if (tp) {
        res = max(res, lol(N[p], (p + fr - (p + ar[p] - 1))));
      }
    }
  }
  return res;
}
void Fill(int l, int r, int st, int ed) {
  if (l > r) return;
  int gap = r - l + 1;
  int vl = ed - st + 1;
  int mid = gap / vl;
  int rm = gap % vl;
  for (int i = l; i <= r; i += mid) {
    for (int j = i; j < i + mid; j++) {
      a[j] = st;
    }
    if (rm) {
      rm--;
      a[i + mid] = st;
      i++;
    }
    st++;
  }
}
void path(int p, int pv) {
  if (p == (n + 1)) {
    int vl = a[P[p]];
    int lstend = P[p] + ar[P[p]] + pv;
    if (P[p] == 0) lstend++;
    int gap = p - lstend;
    Fill(lstend, p - 1, vl + 1, vl + (gap / 2));
    return;
  }
  int res = lol(p, pv);
  int lstend = P[p] + ar[P[p]] + pv;
  if (P[p] == 0) lstend++;
  int f = 0;
  for (int bac = 0; bac < 5; bac++) {
    for (int fr = 0; fr < 5; fr++) {
      if ((bac + fr + 1) > 5) continue;
      if ((bac + fr + 1) < 2) continue;
      if ((p - bac) < lstend) continue;
      if ((p + fr) >= N[p]) continue;
      if ((p + fr) < (p + ar[p] - 1)) continue;
      int tp = ok(lstend, p - bac - 1, a[P[p]], a[p]);
      if (tp) {
        int kk = lol(N[p], (p + fr - (p + ar[p] - 1)));
        if (kk == res) {
          f = 1;
          for (int i = p; i >= p - bac; i--) a[i] = a[p];
          for (int i = p; i <= p + fr; i++) a[i] = a[p];
          Fill(lstend, p - bac - 1, a[P[p]] + 1, a[p] - 1);
          path(N[p], (p + fr - (p + ar[p] - 1)));
          break;
        }
      }
    }
    if (f) break;
  }
  return;
}
int Nxt(int p) {
  int tot = 0;
  while (a[p] == a[p + tot]) {
    tot++;
  }
  return tot;
}
int Next(int p) {
  int tot = 0;
  while ((p + tot) <= n && (a[p] == a[p + tot] || !a[p + tot])) {
    tot++;
  }
  return p + tot;
}
int main() {
  n = in<int>();
  for (int i = 1; i < n + 1; i++) {
    a[i] = in<int>();
  }
  int pv = -1;
  int lst = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i]) {
      if (a[i] == pv) {
        for (int j = lst + 1; j < i + 1; j++) a[j] = a[i];
      }
      lst = i;
      pv = a[i];
    }
  }
  int f = 0;
  int fs = -1;
  for (int i = 1; i <= n;) {
    if (a[i]) {
      int tp = Nxt(i);
      if (tp > 5) {
        printf("-1\n");
        exit(0);
      }
      int tp1 = tp;
      ar[i] = tp;
      tp = Next(i);
      N[i] = tp;
      P[tp] = i;
      f = 1;
      if (fs == -1) {
        fs = i;
      }
      i += tp1;
    } else
      i++;
  }
  if (fs == -1) fs = n + 1;
  memset(dp, -1, sizeof(dp));
  int ans = lol(fs, 0);
  if (ans <= -2000000000) ans = -1;
  cout << ans << endl;
  if (ans == -1) exit(0);
  path(fs, 0);
  for (int i = 1; i < n + 1; i++) {
    printf("%d ", a[i]);
  }
  return 0;
}

```


### Prompt

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

There are n segments [l_i, r_i] for 1 ≤ i ≤ n. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.

To optimize testing process you will be given multitest.

Input

The first line contains one integer T (1 ≤ T ≤ 50000) — the number of queries. Each query contains description of the set of segments. Queries are independent.

First line of each query contains single integer n (2 ≤ n ≤ 10^5) — number of segments. It is guaranteed that ∑{n} over all queries does not exceed 10^5.

The next n lines contains two integers l_i, r_i per line (1 ≤ l_i ≤ r_i ≤ 2 ⋅ 10^5) — the i-th segment.

Output

For each query print n integers t_1, t_2, ..., t_n (t_i ∈ \{1, 2\}) — for each segment (in the same order as in the input) t_i equals 1 if the i-th segment will belongs to the first group and 2 otherwise.

If there are multiple answers, you can print any of them. If there is no answer, print -1.

Example

Input

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

Output

2 1
-1
1 1 2

Note

In the first query the first and the second segments should be in different groups, but exact numbers don't matter.

In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is -1.

In the third query we can distribute segments in any way that makes groups non-empty, so any answer of 6 possible is correct.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  unsigned long long t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    map<int, vector<int>> mp;
    vector<pair<int, pair<int, int>>> vv;
    vector<int> ans(n, 0);
    for (unsigned long long i = 0; i < n; i++) {
      int l, r;
      cin >> l >> r;
      vv.push_back({l, {r, i}});
    }
    sort(vv.begin(), vv.end());
    for (unsigned long long i = 0; i < n; i++) {
      int l = vv[i].first, r = vv[i].second.first;
      int idx = vv[i].second.second;
      mp[l].push_back(idx);
      mp[r + 1].push_back(-1);
    }
    int cn = 0;
    int change = 1;
    int once = 0;
    for (auto i : mp) {
      for (auto j : i.second) {
        if (j == -1)
          cn--;
        else
          ans[j] = change, once = 1, cn++;
        if (once == 1 && cn == 0) change = 2;
      }
    }
    int theek = 0;
    for (unsigned long long i = 0; i < n; i++) {
      if (ans[i] == 2) theek++;
    }
    if (theek == 0) {
      cout << -1 << endl;
    } else {
      for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
      cout << endl;
    }
  }
  return 0;
}

```


### Prompt

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

Qingshan and Daniel are going to play a card game. But it will be so boring if only two persons play this. So they will make n robots in total to play this game automatically. Robots made by Qingshan belong to the team 1, and robots made by Daniel belong to the team 2. Robot i belongs to team t_i. Before the game starts, a_i cards are given for robot i.

The rules for this card game are simple:

  * Before the start, the robots are arranged in a circle in the order or their indices. The robots will discard cards in some order, in each step one robot discards a single card. When the game starts, robot 1 will discard one of its cards. After that, robots will follow the following rules:
  * If robot i discards the card last, the nearest robot whose team is opposite from i's will discard the card next. In another word j will discard a card right after i, if and only if among all j that satisfy t_i≠ t_j, dist(i,j) (definition is below) is minimum.
  * The robot who has no cards should quit the game immediately. This robot won't be considered in the next steps.
  * When no robot can discard the card next, the game ends.

We define the distance from robot x to robot y as dist(x,y)=(y-x+n)mod n. It is similar to the oriented distance on the circle.

For example, when n=5, the distance from 1 to 3 is dist(1,3)=(3-1+5)mod 5=2, the distance from 3 to 1 is dist(3,1)=(1-3+5)mod 5 =3.

Later, Qingshan finds out that it will take so much time to see how robots play. She wants to know the result as quickly as possible. You, as Qingshan's fan, are asked to calculate an array [ans_1,ans_2,…,ans_n] — ans_i is equal to the number of cards, that i-th robot will discard during the game. You need to hurry!

To avoid the large size of the input, the team and the number of cards of each robot will be generated in your code with some auxiliary arrays.

Input

The first line contains one integer n (1 ≤ n ≤ 5⋅ 10^6) — the number of robots playing this game.

The second line contains one integer m (1 ≤ m ≤ min(n,200 000)).

Each of the next m line contains four integers p_i, k_i, b_i, w_i (1 ≤ p_i ≤ n, 1 ≤ k_i ≤ 10^9+7, 0 ≤ b_i ,w_i< k_i). It's guaranteed that p_m=n and p_{j-1}<p_{j} (2 ≤ j ≤ m).

Arrays a_j and t_j should be generated by the following pseudo code:

    seed = 0
    base = 0

    function rnd():
    	ret = seed
    	seed = (seed * base + 233) mod 1000000007
    	return ret

    p[0] = 0
    for i = 1 to m:
    	seed = b[i]
    	base = w[i]
    	for j = p[i - 1] + 1 to p[i]:
    		t[j] = (rnd() mod 2) + 1
    		a[j] = (rnd() mod k[i]) + 1

Output

Print a single integer \left( ∏_{i=1}^{n} ((ans_i ⊕ i^2)+1)\right) mod 10^9+7, where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).

Examples

Input

3
3
1 5 2 3
2 7 1 2
3 2 1 1

Output

100

Input

5000000
2
1919810 998244353 114514 19260817
5000000 233333333 623532 7175

Output

800210675

Input

1
1
1 1 0 0

Output

1

Note

In the first test case a=[5,5,1] and t=[1,2,2].

The robot 1 discards the card first.

Then robot 2 discards the card next. Robot 3 doesn't discard the card next because dist(1,2)<dist(1,3).

Then robot 1 discards the card next. Robot 3 doesn't discard the card next because t_2=t_3.

If we write down the index of the robot who discards a card in time order, it will be the sequence [1,2,1,2,1,2,1,2]. So robots 1, 2 and 3 discard 5, 5 and 0 cards, respectively. And the answer is (((5 ⊕ 1^2)+1)×((5 ⊕ 2^2)+1)×((0 ⊕ 3^2)+1)) mod 10^9+7=(5× 2 × 10)mod 10^9+7=100.

### Response

```cpp
#include<iostream>
#include<cstring>
#include<cstdio>
#include<climits>
#include<algorithm>
#include<queue>
#include<vector>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
#define mod 1000000007
#define LL long long
using namespace std;
inline int read(){
	int f=1,ans=0; char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return f*ans;
}
const int MAXN=5e6+11;
const int MAXM=2e5+11;
int col[MAXN],ret,seed,base,A[MAXN],B[MAXN],N,M,p[MAXM],k[MAXM],b[MAXM],w[MAXM];
int rnd(){
	ret=seed,seed=(LL)((LL)seed*base+233)%mod; return ret;
}
signed main(){
	//freopen("A.in","r",stdin);
	N=read(),M=read(); for(int i=1;i<=M;i++) p[i]=read(),k[i]=read(),b[i]=read(),w[i]=read();
	p[0]=0; for(int i=1;i<=M;i++){seed=b[i],base=w[i];for(int j=p[i-1]+1;j<=p[i];j++) col[j]=(rnd()%2)+1,B[j]=A[j]=(rnd()%k[i])+1;}
	int res1=0,res2=0;
	for(int i=1;i<=N;i++) if(col[i]==1) res1+=A[i];else res2+=A[i];
	int ps=0; if(res1!=res2){
		if(res1<res2) ps=1; else ps=2;
	}else ps=col[1];
	int be=0,res=(ps==1)?res1:res2;
	//for(int i=1;i<=N;i++) cerr<<col[i]<<" ";cerr<<endl;
	//for(int i=1;i<=N;i++) cerr<<A[i]<<" ";cerr<<endl;
	int cnt=0;
	if(col[1]==ps) be=1;
	else {A[1]--; for(int i=1;i<=N;i++) if(col[i]==ps){be=i;break;}}
	//for(int i=1;i<=N;i++) cerr<<A[i]<<" ";cerr<<endl;
	while(res||cnt){
		if(A[be]){
			if(col[be]==ps){cnt+=A[be];res-=A[be];A[be]=0;}
			else{
				int w=min(A[be],cnt); A[be]-=w;
				cnt-=w;
			}
		} be++; if(be==N+1) be=1;
	}
	LL Ans=1;
	//for(int i=1;i<=N;i++) cerr<<B[i]-A[i]<<" ";cerr<<"\n";
	for(int i=1;i<=N;i++) Ans*=(LL)((LL)((B[i]-A[i])^(LL)(i*i))+1)%mod,Ans%=mod;
	printf("%lld\n",Ans); return 0;
}
```


### Prompt

Create a solution in Cpp for the following problem:

Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula:

\\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\]

where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$ respectively.

Note

解説

Constraints

* $1 \leq n, m, l \leq 100$
* $0 \leq a_{ij}, b_{ij} \leq 10000$

Input

In the first line, three integers $n$, $m$ and $l$ are given separated by space characters

In the following lines, the $n \times m$ matrix $A$ and the $m \times l$ matrix $B$ are given.

Output

Print elements of the $n \times l$ matrix $C$ ($c_{ij}$). Print a single space character between adjacent elements.

Example

Input

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

Output

1 8 5
0 9 6
4 23 14

### Response

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

int main()
{
	int n = 0, m = 0, l = 0, a[100][100] = { 0 }, b[100][100] = { 0 };

	cin >> n >> m >> l;

	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++)
			cin >> a[i][j];
	}

	for (int i = 0; i < m; i++) {
		for (int j = 0; j < l; j++)
			cin >> b[i][j];
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			long t = 0;
			if (j > 0)
				cout << " ";
			for (int k = 0; k < m; k++)
				t += a[i][k] * b[k][j];
			cout << t;
		}
		cout << endl;
	}

    return 0;
}
```


### Prompt

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

Carol is currently curling.

She has n disks each with radius r on the 2D plane.

Initially she has all these disks above the line y = 10100.

She then will slide the disks towards the line y = 0 one by one in order from 1 to n.

When she slides the i-th disk, she will place its center at the point (xi, 10100). She will then push it so the disk’s y coordinate continuously decreases, and x coordinate stays constant. The disk stops once it touches the line y = 0 or it touches any previous disk. Note that once a disk stops moving, it will not move again, even if hit by another disk.

Compute the y-coordinates of centers of all the disks after all disks have been pushed.

Input

The first line will contain two integers n and r (1 ≤ n, r ≤ 1 000), the number of disks, and the radius of the disks, respectively.

The next line will contain n integers x1, x2, ..., xn (1 ≤ xi ≤ 1 000) — the x-coordinates of the disks.

Output

Print a single line with n numbers. The i-th number denotes the y-coordinate of the center of the i-th disk. The output will be accepted if it has absolute or relative error at most 10 - 6.

Namely, let's assume that your answer for a particular value of a coordinate is a and the answer of the jury is b. The checker program will consider your answer correct if <image> for all coordinates.

Example

Input

6 2
5 5 6 8 3 12

Output

2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613

Note

The final positions of the disks will look as follows:

<image>

In particular, note the position of the last disk.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  double r;
  cin >> n >> r;
  vector<double> x(n);
  for (int i = 0; i < (int)(n); ++i) cin >> x[i];
  vector<double> y(n, 0);
  for (int i = 0; i < (int)(n); ++i) {
    y[i] = r;
    for (int j = 0; j < (int)(i); ++j) {
      if (abs(x[i] - x[j]) - 0.000000000001 < 2.0 * r) {
        y[i] = max(y[i], y[j] + sqrt(4.0 * r * r -
                                     abs(x[i] - x[j]) * abs(x[i] - x[j])));
      }
    }
  }
  for (int i = 0; i < (int)(n); ++i) {
    if (i) printf(" ");
    printf("%.9f", y[i]);
  }
  printf("\n");
}

```


### Prompt

Please create a solution in CPP to the following problem:

Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property:

  * consider all pairs of numbers x, y (x ≠ y), such that number x occurs in the array a and number y occurs in the array a;
  * for each pair x, y must exist some position j (1 ≤ j < n), such that at least one of the two conditions are met, either aj = x, aj + 1 = y, or aj = y, aj + 1 = x.

Sereja wants to build a beautiful array a, consisting of n integers. But not everything is so easy, Sereja's friend Dima has m coupons, each contains two integers qi, wi. Coupon i costs wi and allows you to use as many numbers qi as you want when constructing the array a. Values qi are distinct. Sereja has no coupons, so Dima and Sereja have made the following deal. Dima builds some beautiful array a of n elements. After that he takes wi rubles from Sereja for each qi, which occurs in the array a. Sereja believed his friend and agreed to the contract, and now he is wondering, what is the maximum amount of money he can pay.

Help Sereja, find the maximum amount of money he can pay to Dima.

Input

The first line contains two integers n and m (1 ≤ n ≤ 2·106, 1 ≤ m ≤ 105). Next m lines contain pairs of integers. The i-th line contains numbers qi, wi (1 ≤ qi, wi ≤ 105).

It is guaranteed that all qi are distinct.

Output

In a single line print maximum amount of money (in rubles) Sereja can pay.

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

Examples

Input

5 2
1 2
2 3

Output

5

Input

100 3
1 2
2 1
3 1

Output

4

Input

1 2
1 1
2 100

Output

100

Note

In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test.

In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
long long cont(long long n) {
  long long ans = (n - 1);
  ans = ans * (n / 2);
  ans += ((n + 1) / 2);
  return ans;
}
long long solve(long long aval, long long mx) {
  long long lo = 1, hi = mx;
  for (long long i = mx; i >= 1; i--)
    if (cont(i) <= aval) return i;
  return lo;
}
vector<long long> tp;
int main() {
  ios_base::sync_with_stdio(0);
  long long aval, m;
  cin >> aval >> m;
  tp.resize(m);
  int a;
  for (int i = 0; i < m; i++) {
    cin >> a >> tp[i];
  }
  sort(tp.begin(), tp.end());
  reverse(tp.begin(), tp.end());
  long long can = solve(aval, m);
  long long ans = 0;
  for (int i = 0; i < can; i++) ans += tp[i];
  cout << ans << endl;
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).

There are n members, numbered 1 through n. m pairs of members are friends. Of course, a member can't be a friend with themselves.

Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z.

For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well.

Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes.

Input

The first line of the input contain two integers n and m (3 ≤ n ≤ 150 000, <image>) — the number of members and the number of pairs of members that are friends.

The i-th of the next m lines contains two distinct integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi). Members ai and bi are friends with each other. No pair of members will appear more than once in the input.

Output

If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).

Examples

Input

4 3
1 3
3 4
1 4

Output

YES

Input

4 4
3 1
2 3
3 4
1 2

Output

NO

Input

10 4
4 3
5 10
8 9
1 2

Output

YES

Input

3 2
1 2
2 3

Output

NO

Note

The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.

<image>

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, ”/ STACK : 38777216“
using namespace std;
const int N = 150005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
int n, m;
long long q, M;
vector<int> g[N];
bool used[N];
void dfs(int v) {
  q++;
  used[v] = true;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (used[to]) continue;
    dfs(to);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (used[i]) continue;
    q = 0;
    dfs(i);
    M += (q * (q - 1)) / (2ll);
  }
  if (M == (long long)m)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits.

Input

The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups.

Output

Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any.

Examples

Input

6
549871

Output

54-98-71

Input

7
1198733

Output

11-987-33

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j;
  char str[105];
  cin >> n;
  cin >> str;
  i = 0;
  while (i < n - 1) {
    if ((n - 1) - (i) == 2) {
      cout << str[i] << str[i + 1] << str[i + 2];
      i = i + 3;
    } else {
      cout << str[i] << str[i + 1];
      i = i + 2;
    }
    if (i < n - 1) cout << "-";
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

When he's not training for IOI, Little Alawn enjoys playing with puzzles of various types to stimulate his brain. Today, he's playing with a puzzle that consists of a 2 × n grid where each row is a permutation of the numbers 1,2,3,…,n.

The goal of Little Alawn's puzzle is to make sure no numbers on the same column or row are the same (we'll call this state of the puzzle as solved), and to achieve this he is able to swap the numbers in any column. However, after solving the puzzle many times, Little Alawn got bored and began wondering about the number of possible solved configurations of the puzzle he could achieve from an initial solved configuration only by swapping numbers in a column.

Unfortunately, Little Alawn got stuck while trying to solve this harder problem, so he was wondering if you could help him with it. Find the answer modulo 10^9+7.

Input

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

The first line of each test case contains a single integer n (2 ≤ n ≤ 4 ⋅ 10^5).

The next two lines of each test case describe the initial state of the puzzle grid. Each line will be a permutation of the numbers 1,2,3,…,n and the numbers in each column and row will be pairwise distinct.

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

Output

For each test case output a single integer, the number of possible solved configurations of the puzzle Little Alawn can achieve from an initial solved configuration only by swapping numbers in a column. As the answer can be very large, please output it modulo 10^9+7.

The answer for each test case should be on a separate line.

Example

Input

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

Output

2
8

Note

The two possible puzzle configurations for example 1 are:

  * [1,4,2,3] in the first row and [3,2,1,4] in the second;
  * [3,2,1,4] in the first row and [1,4,2,3] in the second.

### Response

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

#define peace ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define endl "\n"
#define fl(i,a,b) for(int i=a;i<b;i++)
#define rfl(i,a,b) for(int i=a;i>b;i--)
#define cases() ll t;cin>>t; while(t--)
#define sz(x) ((ll)(x).size())
#define all(v) v.begin(),v.end()
#define get(a,n) fl(i,0,n)  cin>>a[i];
#define pr(a,n,st) fl(i,st,n) cout<<a[i]<<" ";  cout<<endl;
#define prt(a,n,m) fl(i,0,n) fl(j,0,m) cout<<a[i][j]<<" \n"[j==m-1];
#define pb push_back
#define ff first
#define ss second
#define nl cout<<endl;
typedef pair<int,int>pairs;
#define de(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const int MOD=1e9+7, N=4e5+5, B = 32;

ll modExp(ll b, ll p) {
      ll res = 1;
      while(p > 0) {
            if(p & 1) res = (res * b) % MOD;
            b = (b * b) % MOD, p >>= 1;
      }
      return res;
}

int par[N], rk[N];

void init(int v)  {
      par[v] = v;
      rk[v] = 1;
}

int find(int v)   {
      return v == par[v] ? v : par[v] = find(par[v]);
}

void join(int u, int v) {
      u = find(u), v = find(v);
      if(u != v)  {
            if(rk[u] < rk[v]) swap(u, v);
            par[v] = u;
            rk[u] += rk[v];
      }
}

void solve()      {
      int n;      cin >> n;
      fl(i, 1, n + 1) init(i);
      int a[2][n];
      fl(i, 0, 2) {
            fl(j, 0, n) {
                  cin >> a[i][j];
            }
      }
      fl(i, 0, n) {
            join(a[0][i], a[1][i]);
      }
      set<int> st;
      fl(i, 0, n) {
            st.insert(find(a[0][i]));
      }
      cout << modExp(2ll, sz(st)) << endl;
}

int main()  {
      peace;
      #ifndef ONLINE_JUDGE
      freopen("inputf.in", "r", stdin);  freopen("outputf.in", "w", stdout);
      #endif
      cases()
            solve();
}
```


### Prompt

Develop a solution in CPP to the problem described below:

It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.

The bus stop queue has n groups of people. The i-th group from the beginning has ai people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most m people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue.

Your task is to determine how many buses is needed to transport all n groups to the dacha countryside.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100). The next line contains n integers: a1, a2, ..., an (1 ≤ ai ≤ m).

Output

Print a single integer — the number of buses that is needed to transport all n groups to the dacha countryside.

Examples

Input

4 3
2 3 2 1

Output

3

Input

3 4
1 2 1

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void cp() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  cp();
  long long n;
  cin >> n;
  ;
  long long m;
  cin >> m;
  ;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long ans = 1;
  long long ca = 0;
  for (long long i = 0; i < n; i++) {
    ca += (a[i]);
    if (ca > m) {
      ca = a[i];
      ans++;
    }
  }
  cout << ans << endl;
}

```


### Prompt

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

You are given the array of integer numbers a0, a1, ..., an - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.

Input

The first line contains integer n (1 ≤ n ≤ 2·105) — length of the array a. The second line contains integer elements of the array separated by single spaces ( - 109 ≤ ai ≤ 109).

Output

Print the sequence d0, d1, ..., dn - 1, where di is the difference of indices between i and nearest j such that aj = 0. It is possible that i = j.

Examples

Input

9
2 1 0 3 0 0 3 2 4

Output

2 1 0 1 0 0 1 2 3

Input

5
0 1 2 3 4

Output

0 1 2 3 4

Input

7
5 6 0 1 -2 3 4

Output

2 1 0 1 2 3 4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> zeroes;
int binarySearch(int p, int low, int high) {
  int ans = INT_MAX;
  while (low <= high) {
    int mid = (low + high) >> 1;
    ans = min(ans, abs(p - zeroes[mid]));
    if (zeroes[mid] > p) {
      high = mid - 1;
    } else if (zeroes[mid] < p) {
      low = mid + 1;
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<long long int> v(n), result(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    if (v[i] == 0) {
      zeroes.emplace_back(i);
      result[i] = 0;
    } else {
      result[i] = -1;
    }
  }
  sort((zeroes).begin(), (zeroes).end());
  int len = (int)zeroes.size();
  for (int i = 0; i < n; i++) {
    if (result[i] == -1) {
      result[i] = binarySearch(i, 0, len - 1);
    }
  }
  for (int x : result) {
    cout << x << " ";
  }
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell <image>. The following condition is satisfied for the vector: <image>, where <image> is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.

Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.

Input

The first line contains integers n, m, dx, dy(1 ≤ n ≤ 106, 1 ≤ m ≤ 105, 1 ≤ dx, dy ≤ n) — the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers xi, yi (0 ≤ xi, yi ≤ n - 1) — the coordinates of apples. One cell may contain multiple apple trees.

Output

Print two space-separated numbers — the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.

Examples

Input

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

Output

1 3

Input

2 3 1 1
0 0
0 1
1 1

Output

0 0

Note

In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)

In the second sample: (0, 0) - (1, 1) - (0, 0)

### Response

```cpp
#include <bits/stdc++.h>
long long n, m, dx, dy, ansx, ansy, x, y, z, sum[1000010], f[1000010], tmp, ti,
    i, ans;
int main() {
  scanf("%lld%lld%lld%lld", &n, &m, &dx, &dy);
  do {
    f[tmp] = ti;
    tmp = (tmp + dx) % n;
    ti++;
  } while (tmp);
  for (i = 1; i <= m; i++) {
    scanf("%lld%lld", &x, &y);
    z = (y - f[x] * dy) % n + n;
    sum[z % n]++;
    if (sum[z % n] > ans) {
      ans = sum[z % n];
      ansx = x;
      ansy = y;
    }
  }
  printf("%lld %lld", ansx, ansy);
}

```


### Prompt

Please create a solution in CPP to the following problem:

Example

Input

anagram
grandmother

Output

4

### Response

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

int main() {
    string s, t;
    cin >> s >> t;

    vector<vector<short> > vec(t.size() + 1, vector<short>(26));
    for (int i = 1; i <= t.size(); i++) {
        vec[i][t[i-1] - 'a']++;

        for (int j = 0; j < 26; j++) {
            vec[i][j] += vec[i-1][j];
        }
    }

    vector<vector<short> > v(s.size() + 1, vector<short>(26));
    for (int i = 1; i <= s.size(); i++) {
        v[i][s[i-1] - 'a']++;

        for (int j = 0; j < 26; j++) {
            v[i][j] += v[i-1][j];
        }
    }

    for (int i = s.size(); i > 0; i--) {
        set<vector<short>> sv;
        for (int j = 0; j + i < vec.size(); j++) {
            vector<short> sub(26);
            for (int k = 0; k < 26; k++) {
                sub[k] += vec[i + j][k] - vec[j][k];
            }

            sv.insert(sub);
        }

        for (int j = 0; j + i < v.size(); j++) {
            vector<short> sub(26);
            for (int k = 0; k < 26; k++) {
                sub[k] = v[i + j][k] - v[j][k];
            }

            if (sv.find(sub) != sv.end()) {
                cout << i << endl;
                return 0;
            }
        }
    }

    cout << 0 << endl;

    return 0;
}
```


### Prompt

Create a solution in cpp for 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;
int main() {
  int arr[3] = {0};
  string str;
  for (int i = 0; i < 3; i++) {
    cin >> str;
    if (str[1] == '>')
      arr[str[0] - 'A']++;
    else
      arr[str[2] - 'A']++;
  }
  if (arr[0] == 3 || arr[1] == 3 || arr[2] == 3 ||
      (arr[0] == 1 && arr[1] == 1 && arr[2] == 1))
    cout << "Impossible\n";
  else {
    if (arr[0] == 0)
      cout << "A";
    else if (arr[1] == 0)
      cout << "B";
    else if (arr[2] == 0)
      cout << "C";
    if (arr[0] == 1)
      cout << "A";
    else if (arr[1] == 1)
      cout << "B";
    else if (arr[2] == 1)
      cout << "C";
    if (arr[0] == 2)
      cout << "A";
    else if (arr[1] == 2)
      cout << "B";
    else if (arr[2] == 2)
      cout << "C";
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Treeland is a country in which there are n towns connected by n - 1 two-way road such that it's possible to get from any town to any other town.

In Treeland there are 2k universities which are located in different towns.

Recently, the president signed the decree to connect universities by high-speed network.The Ministry of Education understood the decree in its own way and decided that it was enough to connect each university with another one by using a cable. Formally, the decree will be done!

To have the maximum sum in the budget, the Ministry decided to divide universities into pairs so that the total length of the required cable will be maximum. In other words, the total distance between universities in k pairs should be as large as possible.

Help the Ministry to find the maximum total distance. Of course, each university should be present in only one pair. Consider that all roads have the same length which is equal to 1.

Input

The first line of the input contains two integers n and k (2 ≤ n ≤ 200 000, 1 ≤ k ≤ n / 2) — the number of towns in Treeland and the number of university pairs. Consider that towns are numbered from 1 to n.

The second line contains 2k distinct integers u1, u2, ..., u2k (1 ≤ ui ≤ n) — indices of towns in which universities are located.

The next n - 1 line contains the description of roads. Each line contains the pair of integers xj and yj (1 ≤ xj, yj ≤ n), which means that the j-th road connects towns xj and yj. All of them are two-way roads. You can move from any town to any other using only these roads.

Output

Print the maximum possible sum of distances in the division of universities into k pairs.

Examples

Input

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

Output

6

Input

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

Output

9

Note

The figure below shows one of possible division into pairs in the first test. If you connect universities number 1 and 6 (marked in red) and universities number 2 and 5 (marked in blue) by using the cable, the total distance will equal 6 which will be the maximum sum in this example.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 100 * 10 * 3 + 10;
bool mark[MAXN], mark2[MAXN];
long long n, k;
long long ans = 0, dp[MAXN];
vector<int> a[MAXN];
void dfs(int v) {
  mark2[v] = 1;
  for (int i = 0; i < a[v].size(); i++) {
    if (mark2[a[v][i]] == false) {
      dfs(a[v][i]);
      dp[v] += dp[a[v][i]];
      ans += min(dp[a[v][i]], 2 * k - dp[a[v][i]]);
    }
  }
  if (mark[v]) dp[v]++;
}
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  int x, y;
  cin >> n >> k;
  for (int i = 0; i < 2 * k; i++) cin >> x, mark[x] = 1;
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  dfs(1);
  cout << ans << endl;
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:

You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.

Input

The first line contains an integer n (1 ≤ n ≤ 105). Each of the following n lines contain two space-separated integers xi and yi (1 ≤ xi ≤ 105, 0 ≤ yi ≤ i - 1, where i is the query's ordinal number; the numeration starts with 1).

If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration.

Output

For each query print the answer on a single line: the number of positive integers k such that <image>

Examples

Input

6
4 0
3 1
5 2
6 2
18 4
10000 3

Output

3
1
1
2
2
22

Note

Let's write out the divisors that give answers for the first 5 queries:

1) 1, 2, 4

2) 3

3) 5

4) 2, 6

5) 9, 18

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<long long> fact(10, 1);
long long gcd(long long n1, long long n2) {
  long long maxm = max(n1, n2);
  long long minm = min(n1, n2);
  if ((maxm % minm) == 0)
    return minm;
  else
    return gcd(minm, maxm % minm);
}
long long power(long long x, long long y) {
  long long temp;
  if (y == 0) return 1;
  temp = power(x, y / 2) % 1000000007;
  if (y % 2 == 0)
    return temp * temp % 1000000007;
  else
    return (x * temp % 1000000007) * temp % 1000000007;
}
long long ifact(long long k) {
  return power(fact[k], 1000000007 - 2) % 1000000007;
}
long long ncr(long long n, long long r) {
  if (n < r) return 0;
  long long num = 1;
  long long den = 1;
  long long g;
  for (long long i = 1; i < r + 1; i++) {
    num = num * (n - i + 1);
    den = den * (i);
    g = gcd(num, den);
    num = num / g;
    den = den / g;
  }
  return num;
}
vector<long long> factors(100001, -1);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    long long n, x, y;
    cin >> n;
    for (long long i = 0; i < n; i++) {
      long long ans = 0;
      cin >> x >> y;
      for (long long j = 1; j < sqrt(x); j++) {
        if (x % j == 0) {
          if (factors[j] == -1 || factors[j] < i - y) ans++;
          factors[j] = i;
          if (factors[x / j] == -1 || factors[x / j] < i - y) ans++;
          factors[x / j] = i;
        }
      }
      long long sq = sqrt(x);
      if (sq * sq == x) {
        if (factors[sq] == -1 || factors[sq] < i - y) ans++;
        factors[sq] = i;
      }
      cout << ans << endl;
    }
  }
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

There are N barbecue restaurants along a street. The restaurants are numbered 1 through N from west to east, and the distance between restaurant i and restaurant i+1 is A_i.

Joisino has M tickets, numbered 1 through M. Every barbecue restaurant offers barbecue meals in exchange for these tickets. Restaurant i offers a meal of deliciousness B_{i,j} in exchange for ticket j. Each ticket can only be used once, but any number of tickets can be used at a restaurant.

Joisino wants to have M barbecue meals by starting from a restaurant of her choice, then repeatedly traveling to another barbecue restaurant and using unused tickets at the restaurant at her current location. Her eventual happiness is calculated by the following formula: "(The total deliciousness of the meals eaten) - (The total distance traveled)". Find her maximum possible eventual happiness.

Constraints

* All input values are integers.
* 2≤N≤5×10^3
* 1≤M≤200
* 1≤A_i≤10^9
* 1≤B_{i,j}≤10^9

Input

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

N M
A_1 A_2 ... A_{N-1}
B_{1,1} B_{1,2} ... B_{1,M}
B_{2,1} B_{2,2} ... B_{2,M}
:
B_{N,1} B_{N,2} ... B_{N,M}

Output

Print Joisino's maximum possible eventual happiness.

Examples

Input

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

Output

11

Input

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

Output

20

### Response

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

using namespace std;
typedef long long ll;

char gc(){
	static const int L=(1<<19)+1;
	static char ibuf[L],*iS,*iT;
	if(iS==iT){
		iT=(iS=ibuf)+fread(ibuf,1,L,stdin);
		return iS==iT?EOF:*iS++;
	}
	return*iS++;
}
template<class I>void gi(I&x){
	static char c;static int f;
	for(f=1,c=gc();c<'0'||c>'9';c=gc())if(c=='-')f=-1;
	for(x=0;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=f;
}

const int N=5005,M=205,K=13;
const ll inf=1e14;
int n,m,st[K][N][M],lg2[N];
ll D[N],ans;

inline void Max(int*a,int*b,int*c){for(int i=1;i<=m;i++)c[i]=max(a[i],b[i]);}
inline ll Sum(int*a,int*b){ll s=0;for(int i=1;i<=m;i++)s+=max(a[i],b[i]);return s;}
inline ll Get(int l,int r){int t=lg2[r-l+1];return Sum(st[t][l],st[t][r-(1<<t)+1]);}

void solve(int l,int r,int s,int t){
	if(l>r)return;
	int m=(l+r)>>1;
	ll best=-inf;int p;
	for(int i=s;i<=m&&i<=t;i++){
		ll cur=Get(i,m)-D[m]+D[i];
		if(cur>best)best=cur,p=i;
	}
	ans=max(ans,best);
	solve(l,m-1,s,p),solve(m+1,r,p,t);
}

int main(){
	gi(n),gi(m);
	for(int i=2;i<=n;i++)gi(D[i]),D[i]+=D[i-1];
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)gi(st[0][i][j]);
	for(int i=2;i<=n;i++)lg2[i]=lg2[i-1]+!(i&(i-1));
	for(int i=1,l=2;l<=n;i++,l<<=1)for(int j=1;j+l-1<=n;j++)Max(st[i-1][j],st[i-1][j+(l>>1)],st[i][j]);
	solve(1,n,1,n);
	printf("%lld\n",ans);
	return 0;
}
```


### Prompt

Generate a cpp solution to the following problem:

A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.

The tournament takes place in the following way (below, m is the number of the participants of the current round):

  * let k be the maximal power of the number 2 such that k ≤ m,
  * k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly,
  * when only one participant remains, the tournament finishes.

Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.

Find the number of bottles and towels needed for the tournament.

Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).

Input

The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.

Output

Print two integers x and y — the number of bottles and towels need for the tournament.

Examples

Input

5 2 3

Output

20 15

Input

8 2 4

Output

35 32

Note

In the first example will be three rounds:

  1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge),
  2. in the second round will be only one match, so we need another 5 bottles of water,
  3. in the third round will also be only one match, so we need another 5 bottles of water.

So in total we need 20 bottles of water.

In the second example no participant will move on to some round directly.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long M = 3e5 + 7, N = 500, mod = 1000000007;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  {
    long long n, a, b;
    cin >> n >> a >> b;
    long long ans1 = 0, ans2 = n * b;
    while (n > 1) {
      long long lim = 0;
      for (long long i = 1; i <= n; i *= 2) {
        if (i > n) break;
        lim = i;
      }
      long long ex = n - lim;
      ans1 += (lim * a) + lim / 2;
      n = lim / 2 + ex;
    }
    cout << ans1 << " " << ans2 << '\n';
  }
  return 0;
}

```