### Prompt

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

Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 through n and n - 1 roads between them. Cities and roads of USC form a rooted tree (Barney's not sure why it is rooted). Root of the tree is the city number 1. Thus if one will start his journey from city 1, he can visit any city he wants by following roads.

<image>

Some girl has stolen Barney's heart, and Barney wants to find her. He starts looking for in the root of the tree and (since he is Barney Stinson not a random guy), he uses a random DFS to search in the cities. A pseudo code of this algorithm is as follows:

    let starting_time be an array of length n
    current_time = 0
    dfs(v):
    	current_time = current_time + 1
    	starting_time[v] = current_time
    	shuffle children[v] randomly (each permutation with equal possibility)
    	// children[v] is vector of children cities of city v
    	for u in children[v]:
    		dfs(u)

As told before, Barney will start his journey in the root of the tree (equivalent to call dfs(1)).

Now Barney needs to pack a backpack and so he wants to know more about his upcoming journey: for every city i, Barney wants to know the expected value of starting_time[i]. He's a friend of Jon Snow and knows nothing, that's why he asked for your help.

Input

The first line of input contains a single integer n (1 ≤ n ≤ 105) — the number of cities in USC.

The second line contains n - 1 integers p2, p3, ..., pn (1 ≤ pi < i), where pi is the number of the parent city of city number i in the tree, meaning there is a road between cities numbered pi and i in USC.

Output

In the first and only line of output print n numbers, where i-th number is the expected value of starting_time[i].

Your answer for each city will be considered correct if its absolute or relative error does not exceed 10 - 6.

Examples

Input

7
1 2 1 1 4 4

Output

1.0 4.0 5.0 3.5 4.5 5.0 5.0

Input

12
1 1 2 2 4 4 3 3 1 10 8

Output

1.0 5.0 5.5 6.5 7.5 8.0 8.0 7.0 7.5 6.5 7.5 8.0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &x) {
  T ans = 0;
  short f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    ans = (ans << 1) + (ans << 3) + (ch ^ 48);
    ch = getchar();
  }
  x = ans * f;
}
int n;
int siz[100010];
double f[100010];
int x;
int head[100010], Next[100010 << 1], ver[100010 << 1], tot;
void add(int x, int y) {
  ver[++tot] = y;
  Next[tot] = head[x];
  head[x] = tot;
}
void dfs(int x, int fa) {
  siz[x] = 1;
  for (int i = head[x]; i; i = Next[i]) {
    int y = ver[i];
    if (y == fa) continue;
    dfs(y, x);
    siz[x] += siz[y];
  }
}
void DFS(int x, int fa) {
  for (int i = head[x]; i; i = Next[i]) {
    int y = ver[i];
    if (y == fa) continue;
    f[y] = f[x] + 1 + (siz[x] - siz[y] - 1) / 2.0;
    DFS(y, x);
  }
}
signed main() {
  read(n);
  for (int i = 2; i <= n; i++) read(x), add(i, x), add(x, i);
  dfs(1, -1);
  f[1] = 1;
  DFS(1, -1);
  for (int i = 1; i <= n; i++) printf("%.1lf ", f[i]);
}

```


### Prompt

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

Japanese video game company has developed the music video game called Step Step Evolution. The gameplay of Step Step Evolution is very simple. Players stand on the dance platform, and step on panels on it according to a sequence of arrows shown in the front screen.

There are eight types of direction arrows in the Step Step Evolution: UP, UPPER RIGHT, RIGHT, LOWER RIGHT, DOWN, LOWER LEFT, LEFT, and UPPER LEFT. These direction arrows will scroll upward from the bottom of the screen. When the direction arrow overlaps the stationary arrow nearby the top, then the player must step on the corresponding arrow panel on the dance platform. The figure below shows how the dance platform looks like.

<image>

Figure 1: the dance platform for Step Step Evolution

In the game, you have to obey the following rule:

* Except for the beginning of the play, you must not press the arrow panel which is not correspond to the edit data.
* The foot must stay upon the panel where it presses last time, and will not be moved until it’s going to press the next arrow panel.
* The left foot must not step on the panel which locates at right to the panel on which the right foot rests. Conversely, the right foot must not step on the panel which locates at left to the panel on which the left foot rests.

As for the third condition, the following figure shows the examples of the valid and invalid footsteps.

<image>

Figure 2: the examples of valid and invalid footsteps

The first one (left foot for LEFT, right foot for DOWN) and the second one (left foot for LOWER LEFT, right foot for UPPER LEFT) are valid footstep. The last one (left foot for RIGHT, right foot for DOWN) is invalid footstep.

Note that, at the beginning of the play, the left foot and right foot can be placed anywhere at the arrow panel. Also, you can start first step with left foot or right foot, whichever you want.

To play this game in a beautiful way, the play style called “ Natural footstep style” is commonly known among talented players. “Natural footstep style” is the style in which players make steps by the left foot and the right foot in turn. However, when a sequence of arrows is difficult, players are sometimes forced to violate this style.

Now, your friend has created an edit data (the original sequence of direction arrows to be pushed) for you. You are interested in how many times you have to violate “Natural footstep style” when you optimally played with this edit data. In other words, what is the minimum number of times you have to step on two consecutive arrows using the same foot?

Input

The input consists of several detasets. Each dataset is specified by one line containing a sequence of direction arrows. Directions are described by numbers from 1 to 9, except for 5. The figure below shows the correspondence between numbers and directions.

You may assume that the length of the sequence is between 1 and 100000, inclusive. Also, arrows of the same direction won’t appear consecutively in the line. The end of the input is indicated by a single “#”.

<image>

Figure 3: the correspondence of the numbers to the direction arrows

Output

For each dataset, output how many times you have to violate “Natural footstep style” when you play optimally in one line.

Examples

Input

1
12
123
369
6748
4247219123
1232123212321232
#

Output

0
0
1
0
1
2
7

Input

1
12
123
369
6748
4247219123
1232123212321232

Output

0
0
1
0
1
2
7

### Response

```cpp
///
// File:  2254.cpp
// Author: ymiyamoto
//
// Created on Fri Dec 29 11:08:05 2017
//

#include <cstdint>
#include <iostream>
#include <string>

using namespace std;
enum turn_t {
  Left,
  Right,
};

uint32_t violates(string arrows, turn_t start)
{
  uint32_t left;
  uint32_t right;
  if (start == Left) {
    right = (arrows[0] - '0' + 2) % 3;
  } else {
    left = (arrows[0] - '0' + 2) % 3;
  }
  turn_t turn = start;

  uint32_t count = 0;
  for (uint32_t i = 1; i < arrows.size(); i++) {
    uint32_t arrow = (arrows[i] - '0' + 2) % 3;
    if (turn == Left) {
      if (arrow <= right) {
        left = arrow;
        turn = Right;
      } else {
        right = arrow;
        turn = Left;
        count++;
      }
    } else {
      if (left <= arrow) {
        right = arrow;
        turn = Left;
      } else {
        left = arrow;
        turn = Right;
        count++;
      }
    }
  }

  return count;
}

int32_t main()
{
  while (true) {
    string arrows;
    cin >> arrows;
    if (arrows[0] == '#') break;

    if (arrows.size() <= 2) {
      cout << 0 << endl;
      continue;
    }

    cout << min(violates(arrows, Left), violates(arrows, Right)) << endl;
  }
  return 0;
}
```


### Prompt

Please formulate a Cpp solution to the following problem:

In Japan, temperature is usually expressed using the Celsius (℃) scale. In America, they used the Fahrenheit (℉) scale instead. $20$ degrees Celsius is roughly equal to $68$ degrees Fahrenheit. A phrase such as "Today’s temperature is $68$ degrees" is commonly encountered while you are in America.

A value in Fahrenheit can be converted to Celsius by first subtracting $32$ and then multiplying by $\frac{5}{9}$. A simplified method may be used to produce a rough estimate: first subtract $30$ and then divide by $2$. Using the latter method, $68$ Fahrenheit is converted to $19$ Centigrade, i.e., $\frac{(68-30)}{2}$.

Make a program to convert Fahrenheit to Celsius using the simplified method: $C = \frac{F - 30}{2}$.

Input

The input is given in the following format.

$F$

The input line provides a temperature in Fahrenheit $F$ ($30 \leq F \leq 100$), which is an integer divisible by $2$.

Output

Output the converted Celsius temperature in a line.

Examples

Input

68

Output

19

Input

50

Output

10

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin >> a;
    cout << (a-30)/2 << endl;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Let \mathrm{popcount}(n) be the number of `1`s in the binary representation of n. For example, \mathrm{popcount}(3) = 2, \mathrm{popcount}(7) = 3, and \mathrm{popcount}(0) = 0.

Let f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: "replace n with the remainder when n is divided by \mathrm{popcount}(n)." (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.)

For example, when n=7, it becomes 0 after two operations, as follows:

* \mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1.
* \mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0.

You are given an integer X with N digits in binary. For each integer i such that 1 \leq i \leq N, let X_i be what X becomes when the i-th bit from the top is inverted. Find f(X_1), f(X_2), \ldots, f(X_N).

Constraints

* 1 \leq N \leq 2 \times 10^5
* X is an integer with N digits in binary, possibly with leading zeros.

Input

Input is given from Standard Input in the following format:

N
X

Output

Print N lines. The i-th line should contain the value f(X_i).

Examples

Input

3
011

Output

2
1
1

Input

23
00110111001011011001110

Output

2
1
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+100;

ll qpow(ll x,ll n,int mod)
{
    ll sum=1;
    while(n){
        if(n&1) sum=sum*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return sum;
}

int ans(int x)
{
    if(x==0) return 0;
    int kk=__builtin_popcount(x);
    return 1+ans(x%kk);
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    string s;cin>>s;
    int one=0;
    for(int i=0;i<n;i++){
        if(s[i]=='1') one++;
    }
    int p1=0,p2=0;
    for(int i=0;i<n;i++){
        if(one!=1){
            p1=(p1*2+s[i]-'0')%(one-1);
        }
        p2=(p2*2+s[i]-'0')%(one+1);
    }
    for(int i=0;i<n;i++){
        if((s[i]=='1'&&one==1)){
            cout<<0<<endl;
        }
        else if(s[i]=='1'){
            cout<<1+ans((p1-qpow(2,n-i-1,one-1)+(one-1))%(one-1))<<endl;
        }
        else if(s[i]=='0'){
            cout<<1+ans((p2+qpow(2,n-i-1,one+1)+(one+1))%(one+1))<<endl;
        }
    }
    return 0;
}
```


### Prompt

Please create a solution in CPP to the following problem:

There are a total of W x H squares, with H rows vertically and W columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and outputs the maximum rectangular area consisting of only the unmarked squares.

The input data consists of one line of W characters, given H lines. For example, the following data is given.

.. *.... **.
..........
** .... ***.
.... * .....
.. * .......
... ** .....
. *. * ......
..........
.. **......
. * .. * .....

One line of input data represents the square of one line. Of the character strings in the input data,. (Period) indicates unmarked squares, and * (asterisk) indicates marked squares. The input data string does not contain any characters other than periods, asterisks, and line breaks.

In the above example, the rectangle indicated by 0 in the figure below is the largest.

.. *.... **.
..........
** .... ***.
.... * 00000
.. * ..00000
... ** 00000
. *. *. 00000
..... 00000
.. **. 00000
. * .. * 00000

Therefore, if you output 35, the answer will be correct. If all the squares are marked, output 0.

Input

Given multiple datasets. Each dataset starts with a line of H and W separated by spaces, followed by an H x W rectangle. Both H and W shall be 500 or less.

The input ends with a line containing two 0s. The number of datasets does not exceed 20.

Output

For each dataset, output the area of the largest rectangle on one line.

Example

Input

10 10
...*....**
..........
**....**..
........*.
..*.......
**........
.*........
..........
....*..***
.*....*...
10 10
..*....*..
.*.*...*..
*****..*..
*...*..*..
*...*..*..
..........
****.*...*
..*..*...*
.*...*...*
****..***.
2 3
...
...
0 0

Output

28
12
6

### Response

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

int getS(vector<int>&H){
    int N=H.size();
    vector<int>L(N),R(N);
    stack<int>S;
    for(int i=0;i<N;i++){
        while(!S.empty()&&H[i]<=H[S.top()])S.pop();
        L[i]=S.empty()?0:(S.top()+1);
        S.push(i);
    }
    S=stack<int>();
    for(int i=N-1;i>=0;i--){
        while(!S.empty()&&H[i]<=H[S.top()])S.pop();
        R[i]=S.empty()?N:S.top();
        S.push(i);
    }
    int ma=0;
    for(int i=0;i<N;i++)ma=max(ma,(R[i]-L[i])*H[i]);
    return ma;
}

int H,W;
vector<int>V[500];
void solve(){
    fill_n(V,H,vector<int>(W,0));
    int ma=0;
    for(int i=0;i<H;i++){
        char fld[510];
        cin>>fld;
        for(int j=0;j<W;j++){
            if(fld[j]=='*')continue;
            V[i][j]=(i?V[i-1][j]:0)+1;
        }
        ma=max(ma,getS(V[i]));
    }
    cout<<ma<<endl;
}
signed main(){
    while(cin>>H>>W,H||W)solve();
    return 0;
}
```


### Prompt

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

Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with n vertexes. Each its edge has unit length. You should calculate the number of shortest paths between vertex 1 and vertex 2."

Same with some writers, she wants to make an example with some certain output: for example, her birthday or the number of her boyfriend. Can you help her to make a test case with answer equal exactly to k?

Input

The first line contains a single integer k (1 ≤ k ≤ 109).

Output

You should output a graph G with n vertexes (2 ≤ n ≤ 1000). There must be exactly k shortest paths between vertex 1 and vertex 2 of the graph.

The first line must contain an integer n. Then adjacency matrix G with n rows and n columns must follow. Each element of the matrix must be 'N' or 'Y'. If Gij is 'Y', then graph G has a edge connecting vertex i and vertex j. Consider the graph vertexes are numbered from 1 to n.

The graph must be undirected and simple: Gii = 'N' and Gij = Gji must hold. And there must be at least one path between vertex 1 and vertex 2. It's guaranteed that the answer exists. If there multiple correct answers, you can output any of them.

Examples

Input

2

Output

4
NNYY
NNYY
YYNN
YYNN

Input

9

Output

8
NNYYYNNN
NNNNNYYY
YNNNNYYY
YNNNNYYY
YNNNNYYY
NYYYYNNN
NYYYYNNN
NYYYYNNN

Input

1

Output

2
NY
YN

Note

In first example, there are 2 shortest paths: 1-3-2 and 1-4-2.

In second example, there are 9 shortest paths: 1-3-6-2, 1-3-7-2, 1-3-8-2, 1-4-6-2, 1-4-7-2, 1-4-8-2, 1-5-6-2, 1-5-7-2, 1-5-8-2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool check(long long n, long long pos) { return n & (1LL << pos); }
long long Set(long long n, long long pos) { return n = n | (1LL << pos); }
char grid[1003][1003];
void conn(long long i, long long j) {
  grid[i][j] = 'Y';
  grid[j][i] = 'Y';
}
long long point[100];
int main() {
  long long i, j, k, l, m, n, o, r, q;
  long long testcase;
  long long input, flag, tag, ans;
  while (cin >> k) {
    for (i = 1; i <= 1000; i++)
      for (j = 1; j <= 1000; j++) grid[i][j] = 'N';
    long long mxbit = 0;
    for (i = 0; i <= 30; i++) point[i] = 0;
    conn(1, 3);
    long long node = 2;
    for (i = 30; i >= 0; i--) {
      if (check(k, i) == 0) continue;
      mxbit = max(mxbit, i);
      node++;
      if (i == mxbit) {
        for (j = 0; j < i; j++) {
          conn(node, node + 1);
          conn(node, node + 2);
          conn(node + 2, node + 3);
          conn(node + 1, node + 3);
          point[j] = node + 1;
          node += 3;
        }
        conn(node, 2);
      } else {
        conn(node, point[i]);
        for (j = i + 1; j < mxbit; j++) {
          conn(node, node + 1);
          conn(node + 1, node + 2);
          node += 2;
        }
        conn(node, 2);
      }
    }
    assert(1 <= node && node <= 875);
    cout << node << "\n";
    for (i = 1; i <= node; i++) {
      for (j = 1; j <= node; j++) {
        printf("%c", grid[i][j]);
      }
      printf("\n");
    }
  }
}

```


### Prompt

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

Hibiki and Dita are in love with each other, but belong to communities that are in a long lasting conflict. Hibiki is deeply concerned with the state of affairs, and wants to figure out if his relationship with Dita is an act of love or an act of treason.

<image>

Hibiki prepared several binary features his decision will depend on, and built a three layer logical circuit on top of them, each layer consisting of one or more [logic gates](https://en.wikipedia.org/wiki/Logic_gate). Each gate in the circuit is either "or", "and", "nor" (not or) or "nand" (not and). Each gate in the first layer is connected to exactly two features. Each gate in the second layer is connected to exactly two gates in the first layer. The third layer has only one "or" gate, which is connected to all the gates in the second layer (in other words, the entire circuit produces 1 if and only if at least one gate in the second layer produces 1).

The problem is, Hibiki knows very well that when the person is in love, his ability to think logically degrades drastically. In particular, it is well known that when a person in love evaluates a logical circuit in his mind, every gate evaluates to a value that is the opposite of what it was supposed to evaluate to. For example, "or" gates return 1 if and only if both inputs are zero, "t{nand}" gates produce 1 if and only if both inputs are one etc.

In particular, the "or" gate in the last layer also produces opposite results, and as such if Hibiki is in love, the entire circuit produces 1 if and only if all the gates on the second layer produced 0.

Hibiki can’t allow love to affect his decision. He wants to know what is the smallest number of gates that needs to be removed from the second layer so that the output of the circuit for all possible inputs doesn't depend on whether Hibiki is in love or not.

Input

The first line contains three integers n, m, k (2 ≤ n, m ≤ 50; 1 ≤ k ≤ 50) — the number of input features, the number of gates in the first layer, and the number of gates in the second layer correspondingly.

The second line contains m pairs of strings separated by spaces describing the first layer. The first string in each pair describes the gate ("and", "or", "nand" or "nor"), and the second string describes the two input features the gate is connected two as a string consisting of exactly n characters, with exactly two characters (that correspond to the input features the gate is connected to) equal to 'x' and the remaining characters equal to ".'.

The third line contains k pairs of strings separated by spaces describing the second layer in the same format, where the strings that describe the input parameters have length m and correspond to the gates of the first layer.

Output

Print the number of gates that need to be removed from the second layer so that the output of the remaining circuit doesn't depend on whether Hibiki is in love or not.

If no matter how many gates are removed the output of the circuit continues to depend on Hibiki's feelings, print -1.

Examples

Input

2 2 2
and xx nand xx
and xx or xx

Output

1

Input

3 2 2
and xx. nor .xx
and xx nor xx

Output

-1

Input

4 4 5
nor x..x and ..xx and xx.. nand xx..
nand ..xx nor ..xx and xx.. nor ..xx or ..xx

Output

2

Note

In the first example the two gates in the first layer are connected to the same inputs, but first computes "and" while second computes "nand", and as such their output is always different no matter what the input is and whether Hibiki is in love or not. The second layer has "or" and "and" gates both connected to the two gates in the first layer. If Hibiki is not in love, the "and" gate will produce 0 and the "or" gate will produce 1 no matter what input features are equal to, with the final "or" gate in the third layer always producing the final answer of 1. If Hibiki is in love, "and" gate in the second layer will produce 1 and "or" gate will produce 0 no matter what the input is, with the final "or" gate in the third layer producing the final answer of 0. Thus, if both gates in the second layer are kept, the output of the circuit does depend on whether Hibiki is in love. If any of the two gates in the second layer is dropped, the output of the circuit will no longer depend on whether Hibiki is in love or not, and hence the answer is 1.

In the second example no matter what gates are left in the second layer, the output of the circuit will depend on whether Hibiki is in love or not.

In the third example if Hibiki keeps second, third and fourth gates in the second layer, the circuit will not depend on whether Hibiki is in love or not. Alternatively, he can keep the first and the last gates. The former requires removing two gates, the latter requires removing three gates, so the former is better, and the answer is 2.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
const int AND = 0, OR = 1, NAND = 2, NOR = 3;
const int nax = 1005;
struct S {
  int type;
  S zmien() {
    S he;
    he.type = type ^ 1;
    return he;
  }
  void read() {
    static char sl[10];
    scanf("%s", sl);
    string s = string(sl);
    if (s == "and")
      type = AND;
    else if (s == "or")
      type = OR;
    else if (s == "nand")
      type = NAND;
    else if (s == "nor")
      type = NOR;
    else {
      cout << "unknown type: " << s << endl;
      assert(false);
    }
  }
  bool operator()(bool a, bool b) {
    if (type == AND) return a & b;
    if (type == OR) return a | b;
    if (type == NAND) return !(a & b);
    if (type == NOR) return !(a | b);
    assert(false);
  }
};
void read(pair<S, pair<int, int>>& p) {
  p.first.read();
  static char sl[105];
  scanf("%s", sl);
  int n = strlen(sl);
  vector<int> w;
  for (int i = 0; i < n; ++i)
    if (sl[i] == 'x') w.push_back(i);
  assert((int)w.size() == 2);
  p.second = {w[0], w[1]};
}
vector<int> w[nax];
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  vector<pair<S, pair<int, int>>> one(m), two(k);
  for (int i = 0; i < m; ++i) read(one[i]);
  for (int i = 0; i < k; ++i) read(two[i]);
  const int M = 40 * 1000;
  vector<pair<vector<bool>, vector<bool>>> pre(M);
  for (auto& p : pre) {
    vector<bool> a(n), b(m), c(k), d(k);
    for (int i = 0; i < n; ++i) a[i] = rand() % 2;
    for (int i = 0; i < m; ++i)
      b[i] = one[i].first(a[one[i].second.first], a[one[i].second.second]);
    for (int i = 0; i < k; ++i)
      c[i] = two[i].first(b[two[i].second.first], b[two[i].second.second]);
    for (int i = 0; i < k; ++i)
      d[i] =
          two[i].first.zmien()(b[two[i].second.first], b[two[i].second.second]);
    p = {c, d};
  }
  vector<bool> maybe(k, true);
  for (auto& p : pre) {
    auto& c = p.first;
    auto& d = p.second;
    debug() << " ["
            << "c"
               ": "
            << (c) << "] ";
    for (int i = 0; i < k; ++i)
      if (c[i] & d[i]) maybe[i] = false;
    bool any = false;
    for (int i = 0; i < k; ++i)
      if (maybe[i])
        if (c[i] | d[i]) any = true;
    if (!any) {
      puts("-1");
      return 0;
    }
  }
  vector<vector<bool>> e(k, vector<bool>(k));
  for (auto& p : pre) {
    auto& c = p.first;
    auto& d = p.second;
    debug() << " ["
            << "c"
               ": "
            << (c) << "] ";
    debug() << " ["
            << "d"
               ": "
            << (d) << "] ";
    debug();
    for (int i = 0; i < k; ++i)
      if (maybe[i])
        for (int j = i + 1; j < k; ++j)
          if (maybe[j])
            if ((c[i] & d[j]) | (c[j] & d[i])) e[i][j] = e[j][i] = true;
  }
  for (int i = 0; i < k; ++i)
    for (int j = i + 1; j < k; ++j)
      if (e[i][j]) {
        w[i].push_back(j);
        w[j].push_back(i);
      }
  int answer = 0;
  for (int i = 0; i < k; ++i)
    if (!maybe[i]) ++answer;
  vector<bool> vis(k);
  vector<pair<vector<int>, vector<int>>> they;
  vector<bool> taken(k);
  for (int i = 0; i < k; ++i)
    if (maybe[i] && !vis[i]) {
      vector<int> A, B;
      vector<int> kol{i};
      vector<int> dist(k);
      vis[i] = true;
      for (int j = 0; j < (int)kol.size(); ++j) {
        int a = kol[j];
        if (dist[a] % 2)
          A.push_back(a);
        else
          B.push_back(a);
        for (int b : w[a])
          if (!vis[b]) {
            vis[b] = true;
            dist[b] = dist[a] + 1;
            kol.push_back(b);
          }
      }
      if (A.size() < B.size()) swap(A, B);
      they.push_back({A, B});
      for (int x : A) taken[x] = true;
      answer += (int)B.size();
    }
  bool yeah = true;
  for (auto& p : pre) {
    auto& c = p.first;
    auto& d = p.second;
    bool any = false;
    for (int i = 0; i < k; ++i)
      if (taken[i])
        if (c[i] | d[i]) any = true;
    if (!any) {
      yeah = false;
      break;
    }
  }
  if (!yeah)
    for (pair<vector<int>, vector<int>> p : they) {
      int by = 1000000;
      auto memo = taken;
      for (int x : p.first) {
        assert(taken[x]);
        taken[x] = false;
      }
      for (int x : p.second) {
        assert(!taken[x]);
        taken[x] = true;
      }
      bool tu = true;
      for (auto& p : pre) {
        auto& c = p.first;
        auto& d = p.second;
        bool any = false;
        for (int i = 0; i < k; ++i)
          if (taken[i])
            if (c[i] | d[i]) any = true;
        if (!any) {
          tu = false;
          break;
        }
      }
      if (tu)
        by = min(by, (int)abs(int(p.first.size()) - int(p.second.size())));
      taken = memo;
      answer += by;
    }
  printf("%d\n", answer);
  return 0;
  for (int mask = 0; mask < (1 << k); ++mask) {
    bool ok = true;
    for (int i = 0; i < k; ++i)
      if (mask & (1 << i))
        if (!maybe[i]) ok = false;
    if (!ok) continue;
    for (int rep = 0; rep < 200; ++rep) {
      vector<bool> a(n), b(m), c(k), d(k);
      for (int i = 0; i < n; ++i) a[i] = rand() % 2;
      for (int i = 0; i < m; ++i)
        b[i] = one[i].first(a[one[i].second.first], a[one[i].second.second]);
      for (int i = 0; i < k; ++i)
        c[i] = two[i].first(b[two[i].second.first], b[two[i].second.second]);
      for (int i = 0; i < k; ++i)
        d[i] = two[i].first.zmien()(b[two[i].second.first],
                                    b[two[i].second.second]);
      bool raz = false, dwa = false;
      for (int i = 0; i < k; ++i)
        if (mask & (1 << i)) {
          if (c[i]) raz = true;
          if (d[i]) dwa = true;
        }
      if (raz && dwa) ok = false;
      if (!raz && !dwa) ok = false;
      if (!ok) break;
    }
    if (ok) answer = max(answer, __builtin_popcount(mask));
  }
  assert(answer != -1);
  printf("%d\n", k - answer);
}

```


### Prompt

Generate a Cpp solution to the following problem:

Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x_1,y_1) to the point (x_2,y_2).

He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will pull the box to where he is standing before moving out of the way in the same direction by 1 unit.

<image>

For example, if the box is at the point (1,2) and Wabbit is standing at the point (2,2), he can pull the box right by 1 unit, with the box ending up at the point (2,2) and Wabbit ending at the point (3,2).

Also, Wabbit can move 1 unit to the right, left, up, or down without pulling the box. In this case, it is not necessary for him to be in exactly 1 unit away from the box. If he wants to pull the box again, he must return to a point next to the box. Also, Wabbit can't move to the point where the box is located.

Wabbit can start at any point. It takes 1 second to travel 1 unit right, left, up, or down, regardless of whether he pulls the box while moving.

Determine the minimum amount of time he needs to move the box from (x_1,y_1) to (x_2,y_2). Note that the point where Wabbit ends up at does not matter.

Input

Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 1000): the number of test cases. The description of the test cases follows.

Each of the next t lines contains four space-separated integers x_1, y_1, x_2, y_2 (1 ≤ x_1, y_1, x_2, y_2 ≤ 10^9), describing the next test case.

Output

For each test case, print a single integer: the minimum time in seconds Wabbit needs to bring the box from (x_1,y_1) to (x_2,y_2).

Example

Input

2
1 2 2 2
1 1 2 2

Output

1
4

Note

In the first test case, the starting and the ending points of the box are (1,2) and (2,2) respectively. This is the same as the picture in the statement. Wabbit needs only 1 second to move as shown in the picture in the statement.

In the second test case, Wabbit can start at the point (2,1). He pulls the box to (2,1) while moving to (3,1). He then moves to (3,2) and then to (2,2) without pulling the box. Then, he pulls the box to (2,2) while moving to (2,3). It takes 4 seconds.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  if (x1 == x2) {
    cout << abs(y1 - y2) << "\n";
  } else if (y1 == y2) {
    cout << abs(x1 - x2) << "\n";
  } else {
    long long int vt = abs(y1 - y2);
    long long int hz = abs(x1 - x2);
    long long int ans = 0;
    if (vt > hz) {
      ans += vt;
      ans += hz - 1;
      ans += 3;
    } else {
      ans += hz;
      ans += vt - 1;
      ans += 3;
    }
    cout << ans << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int testcases;
  cin >> testcases;
  while (testcases--) {
    solve();
  }
  return 0;
}

```


### Prompt

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

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

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

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

Input

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

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

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

Output

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

Examples

Input

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

Output

144

Input

3 3
1 2 3
2 0 4
4 5 6

Output

30

Input

3 3
1 2 3
3 0 4
4 5 6

Output

-1

Input

3 3
1 2 3
2 3 4
3 4 2

Output

-1

Note

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

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

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793238460;
const long long mod = 1e9 + 7;
void FAST() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
bool comp(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.second);
}
int main() {
  FAST();
  int n, m;
  cin >> n >> m;
  vector<vector<int> > a(n, vector<int>(m, 0));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> a[i][j];
  for (int i = n - 1; i >= 0; i--) {
    for (int j = m - 1; j >= 0; j--) {
      if (a[i][j] == 0) a[i][j] = min(a[i + 1][j] - 1, a[i][j + 1] - 1);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < m; j++) {
      if (a[i][j] <= a[i][j - 1]) {
        cout << -1 << '\n';
        return 0;
      }
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 1; i < n; i++) {
      if (a[i][j] <= a[i - 1][j]) {
        cout << -1 << '\n';
        return 0;
      }
    }
  }
  int sum = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) sum += a[i][j];
  cout << sum << '\n';
  return 0;
}

```


### Prompt

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

Ujan decided to make a new wooden roof for the house. He has n rectangular planks numbered from 1 to n. The i-th plank has size a_i × 1 (that is, the width is 1 and the height is a_i).

Now, Ujan wants to make a square roof. He will first choose some of the planks and place them side by side in some order. Then he will glue together all of these planks by their vertical sides. Finally, he will cut out a square from the resulting shape in such a way that the sides of the square are horizontal and vertical.

For example, if Ujan had planks with lengths 4, 3, 1, 4 and 5, he could choose planks with lengths 4, 3 and 5. Then he can cut out a 3 × 3 square, which is the maximum possible. Note that this is not the only way he can obtain a 3 × 3 square.

<image>

What is the maximum side length of the square Ujan can get?

Input

The first line of input contains a single integer k (1 ≤ k ≤ 10), the number of test cases in the input.

For each test case, the first line contains a single integer n (1 ≤ n ≤ 1 000), the number of planks Ujan has in store. The next line contains n integers a_1, …, a_n (1 ≤ a_i ≤ n), the lengths of the planks.

Output

For each of the test cases, output a single integer, the maximum possible side length of the square.

Example

Input

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

Output

3
4
1
3

Note

The first sample corresponds to the example in the statement.

In the second sample, gluing all 4 planks will result in a 4 × 4 square.

In the third sample, the maximum possible square is 1 × 1 and can be taken simply as any of the planks.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int m = 0;
    for (int i = 0; i < n; i++) m = max(min(a[i], i + 1), m);
    cout << min(m, n) << endl;
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

In some country live wizards. They like to make weird bets.

Two wizards draw an acyclic directed graph with n vertices and m edges (the graph's vertices are numbered from 1 to n). A source is a vertex with no incoming edges, and a sink is the vertex with no outgoing edges. Note that a vertex could be the sink and the source simultaneously. In the wizards' graph the number of the sinks and the sources is the same.

Wizards numbered the sources in the order of increasing numbers of the vertices from 1 to k. The sinks are numbered from 1 to k in the similar way.

To make a bet, they, as are real wizards, cast a spell, which selects a set of k paths from all sources to the sinks in such a way that no two paths intersect at the vertices. In this case, each sink has exactly one path going to it from exactly one source. Let's suppose that the i-th sink has a path going to it from the ai's source. Then let's call pair (i, j) an inversion if i < j and ai > aj. If the number of inversions among all possible pairs (i, j), such that (1 ≤ i < j ≤ k), is even, then the first wizard wins (the second one gives him one magic coin). Otherwise, the second wizard wins (he gets one magic coin from the first one).

Our wizards are captured with feverish excitement, so they kept choosing new paths again and again for so long that eventually they have chosen every possible set of paths for exactly once. The two sets of non-intersecting pathes are considered to be different, if and only if there is an edge, which lies at some path in one set and doesn't lie at any path of another set. To check their notes, they asked you to count the total winnings of the first player for all possible sets of paths modulo a prime number p.

Input

The first line contains three space-separated integers n, m, p (1 ≤ n ≤ 600, 0 ≤ m ≤ 105, 2 ≤ p ≤ 109 + 7). It is guaranteed that p is prime number.

Next m lines contain edges of the graph. Each line contains a pair of space-separated integers, ai bi — an edge from vertex ai to vertex bi. It is guaranteed that the graph is acyclic and that the graph contains the same number of sources and sinks. Please note that the graph can have multiple edges.

Output

Print the answer to the problem — the total winnings of the first player modulo a prime number p. Please note that the winnings may be negative, but the modulo residue must be non-negative (see the sample).

Examples

Input

4 2 1000003
1 3
2 4

Output

1

Input

4 2 1000003
4 1
3 2

Output

1000002

Input

4 4 1000003
2 1
2 4
3 1
3 4

Output

0

Input

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

Output

0

Input

5 2 1000003
5 1
3 4

Output

1

Note

In the first sample, there is exactly one set of paths — <image>. The number of inversions is 0, which is an even number. Therefore, the first wizard gets 1 coin.

In the second sample there is exactly one set of paths — <image>. There is exactly one inversion. Therefore, the first wizard gets -1 coin. <image>.

In the third sample, there are two sets of paths, which are counted with opposite signs.

In the fourth sample there are no set of paths at all.

In the fifth sample, there are three sources — the vertices with the numbers (2, 3, 5) and three sinks — the vertices with numbers (1, 2, 4). For a single set of paths <image> are 2 inversions, that is, their number is even.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 600;
int n, m, x, y, p, cnt;
int Ind[MAXN + 5], Outd[MAXN + 5];
int s[MAXN + 5][MAXN + 5];
int tmp[MAXN + 5], f[MAXN + 5][MAXN + 5];
vector<int> Graph[MAXN + 5];
vector<int> S, T;
int Mo(long long x) { return (x % p + p) % p; }
void print(int x = 0) {
  if (x) printf("%d\n", x);
  for (int i = 1; i <= cnt; i++) {
    for (int j = 1; j <= cnt; j++) printf("%d ", f[i][j]);
    printf("\n");
  }
  printf("\n");
}
int Gauss() {
  int Sign = 1;
  for (int i = 1; i <= cnt; i++) {
    for (int j = i + 1; j <= cnt; j++) {
      int A = f[i][i], B = f[j][i];
      while (B) {
        int t = A / B;
        A %= B;
        swap(A, B);
        for (int k = i; k <= n; k++)
          f[i][k] = Mo(1ll * f[i][k] - 1ll * t * f[j][k]);
        swap(f[i], f[j]);
        Sign *= -1;
      }
    }
    if (!f[i][i]) return 0;
  }
  int Ans = 1;
  for (int i = 1; i <= cnt; i++) Ans = (1ll * Ans * f[i][i]) % p;
  return Mo(1ll * Ans * Sign);
}
bool vis[MAXN + 5];
void dfs(int u) {
  vis[u] = 1;
  if (!Outd[u]) s[u][u] = 1;
  for (int i = 0; i < Graph[u].size(); i++) {
    int v = Graph[u][i];
    if (!vis[v]) dfs(v);
    for (int j = 0; j < T.size(); j++)
      s[u][T[j]] = Mo(1ll * s[u][T[j]] + s[v][T[j]]);
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &p);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    Graph[x].push_back(y);
    Outd[x]++, Ind[y]++;
  }
  for (int i = 1; i <= n; i++) {
    if (!Ind[i]) S.push_back(i);
    if (!Outd[i]) T.push_back(i);
  }
  for (int i = 1; i <= n; i++)
    if (!Ind[i]) dfs(i);
  for (int i = 0; i < S.size(); i++)
    for (int j = 0; j < T.size(); j++) f[i + 1][j + 1] = s[S[i]][T[j]];
  cnt = S.size();
  printf("%d", Gauss());
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Joker returns to Gotham City to execute another evil plan. In Gotham City, there are N street junctions (numbered from 1 to N) and M streets (numbered from 1 to M). Each street connects two distinct junctions, and two junctions are connected by at most one street.

For his evil plan, Joker needs to use an odd number of streets that together form a cycle. That is, for a junction S and an even positive integer k, there is a sequence of junctions S, s_1, …, s_k, S such that there are streets connecting (a) S and s_1, (b) s_k and S, and (c) s_{i-1} and s_i for each i = 2, …, k.

However, the police are controlling the streets of Gotham City. On each day i, they monitor a different subset of all streets with consecutive numbers j: l_i ≤ j ≤ r_i. These monitored streets cannot be a part of Joker's plan, of course. Unfortunately for the police, Joker has spies within the Gotham City Police Department; they tell him which streets are monitored on which day. Now Joker wants to find out, for some given number of days, whether he can execute his evil plan. On such a day there must be a cycle of streets, consisting of an odd number of streets which are not monitored on that day.

Input

The first line of the input contains three integers N, M, and Q (1 ≤ N, M, Q ≤ 200 000): the number of junctions, the number of streets, and the number of days to be investigated. The following M lines describe the streets. The j-th of these lines (1 ≤ j ≤ M) contains two junction numbers u and v (u ≠ v), saying that street j connects these two junctions. It is guaranteed that any two junctions are connected by at most one street. The following Q lines contain two integers l_i and r_i, saying that all streets j with l_i ≤ j ≤ r_i are checked by the police on day i (1 ≤ i ≤ Q).

Output

Your output is to contain Q lines. Line i (1 ≤ i ≤ Q) contains "YES" if Joker can execute his plan on day i, or "NO" otherwise.

Scoring

Subtasks:

  1. (6 points) 1 ≤ N, M, Q ≤ 200
  2. (8 points) 1 ≤ N, M, Q ≤ 2 000
  3. (25 points) l_i = 1 for i = 1, …, Q
  4. (10 points) l_i ≤ 200 for i = 1, …, Q
  5. (22 points) Q ≤ 2 000
  6. (29 points) No further constraints

Example

Input

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

Output

NO
YES

Note

The graph in the example test:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct DSU {
  vector<int> rank, link;
  vector<int> stk, chkp;
  DSU(int n) : rank(2 * n, 0), link(2 * n, -1) {}
  int find(int x) {
    while (link[x] != -1) x = link[x];
    return x;
  }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) return;
    if (rank[a] > rank[b]) swap(a, b);
    stk.push_back(a);
    link[a] = b;
    rank[b] += (rank[a] == rank[b]);
  }
  bool Try(int a, int b) {
    if (find(2 * a + 1) == find(2 * b + 1)) return false;
    return true;
  }
  void Unite(int a, int b) {
    chkp.push_back(stk.size());
    unite(2 * a, 2 * b + 1);
    unite(2 * a + 1, 2 * b);
    assert(find(2 * a) != find(2 * a + 1));
  }
  void Undo() {
    for (int i = chkp.back(); i < (int)stk.size(); ++i) link[stk[i]] = -1;
    stk.resize(chkp.back());
    chkp.pop_back();
  }
};
struct Upd {
  int type, a, b;
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m, q;
  cin >> n >> m >> q;
  vector<pair<int, int>> edges;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    edges.emplace_back(a - 1, b - 1);
  }
  DSU dsu(n);
  vector<Upd> upds, tmp[2];
  auto pop = [&]() {
    if (upds.back().type == 1) {
      while (upds.size()) {
        auto upd = upds.back();
        upds.pop_back();
        dsu.Undo();
        tmp[upd.type].push_back(upd);
        if (tmp[0].size() == tmp[1].size()) break;
      }
      if (tmp[0].empty()) {
        assert(upds.empty());
        for (auto& upd : tmp[1]) {
          upd.type = 0;
          dsu.Unite(upd.a, upd.b);
        }
        swap(tmp[1], upds);
      } else {
        reverse(tmp[0].begin(), tmp[0].end());
        reverse(tmp[1].begin(), tmp[1].end());
        for (int z = 1; z >= 0; --z) {
          for (auto upd : tmp[z]) {
            dsu.Unite(upd.a, upd.b);
            upds.push_back(upd);
          }
        }
        tmp[0].clear();
        tmp[1].clear();
      }
    }
    assert(upds.back().type == 0);
    upds.pop_back();
    dsu.Undo();
  };
  auto push = [&](int a, int b) {
    upds.push_back(Upd{1, a, b});
    dsu.Unite(a, b);
  };
  vector<int> dp(2 * m);
  int lbound = 0;
  for (int i = 0; i < 2 * m; ++i) {
    auto [a, b] = edges[i % m];
    while (!dsu.Try(a, b)) {
      pop();
      ++lbound;
    }
    push(a, b);
    dp[i] = lbound;
  }
  for (int i = 0; i < q; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    if (dp[a + m - 1] <= b + 1)
      cout << "NO\n";
    else
      cout << "YES\n";
  }
}

```


### Prompt

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

The last stage of Football World Cup is played using the play-off system.

There are n teams left in this stage, they are enumerated from 1 to n. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the fourth, the fifth — with the sixth, and so on. It is guaranteed that in each round there is even number of teams. The winner of each game advances to the next round, the loser is eliminated from the tournament, there are no draws. In the last round there is the only game with two remaining teams: the round is called the Final, the winner is called the champion, and the tournament is over.

Arkady wants his two favorite teams to play in the Final. Unfortunately, the team ids are already determined, and it may happen that it is impossible for teams to meet in the Final, because they are to meet in some earlier stage, if they are strong enough. Determine, in which round the teams with ids a and b can meet.

Input

The only line contains three integers n, a and b (2 ≤ n ≤ 256, 1 ≤ a, b ≤ n) — the total number of teams, and the ids of the teams that Arkady is interested in.

It is guaranteed that n is such that in each round an even number of team advance, and that a and b are not equal.

Output

In the only line print "Final!" (without quotes), if teams a and b can meet in the Final.

Otherwise, print a single integer — the number of the round in which teams a and b can meet. The round are enumerated from 1.

Examples

Input

4 1 2

Output

1

Input

8 2 6

Output

Final!

Input

8 7 5

Output

2

Note

In the first example teams 1 and 2 meet in the first round.

In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.

In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the first round.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, a, b;
  cin >> n >> a >> b;
  int level = 0;
  while (a != b) {
    a = (a + 1) / 2;
    b = (b + 1) / 2;
    level++;
  }
  if ((1 << level) == n)
    cout << "Final!" << endl;
  else
    cout << level << endl;
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Little Chris is participating in a graph cutting contest. He's a pro. The time has come to test his skills to the fullest.

Chris is given a simple undirected connected graph with n vertices (numbered from 1 to n) and m edges. The problem is to cut it into edge-distinct paths of length 2. Formally, Chris has to partition all edges of the graph into pairs in such a way that the edges in a single pair are adjacent and each edge must be contained in exactly one pair.

For example, the figure shows a way Chris can cut a graph. The first sample test contains the description of this graph.

<image>

You are given a chance to compete with Chris. Find a way to cut the given graph or determine that it is impossible!

Input

The first line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105), the number of vertices and the number of edges in the graph. The next m lines contain the description of the graph's edges. The i-th line contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi), the numbers of the vertices connected by the i-th edge. It is guaranteed that the given graph is simple (without self-loops and multi-edges) and connected.

Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.

Output

If it is possible to cut the given graph into edge-distinct paths of length 2, output <image> lines. In the i-th line print three space-separated integers xi, yi and zi, the description of the i-th path. The graph should contain this path, i.e., the graph should contain edges (xi, yi) and (yi, zi). Each edge should appear in exactly one path of length 2. If there are multiple solutions, output any of them.

If it is impossible to cut the given graph, print "No solution" (without quotes).

Examples

Input

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

Output

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

Input

3 3
1 2
2 3
3 1

Output

No solution

Input

3 2
1 2
2 3

Output

1 2 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct node {
  int x, y, z;
  node(int x, int y, int z) : x(x), y(y), z(z) {}
};
vector<int> adj[N];
vector<node> ans;
int vis[N];
int tot;
int dfs(int u, int fa) {
  vis[u] = ++tot;
  int a = 0;
  int s = adj[u].size();
  for (int i = 0; i < s; i++) {
    int v = adj[u][i];
    if (v == fa) continue;
    if (!vis[v]) {
      if (dfs(v, u)) continue;
      if (!a)
        a = v;
      else {
        ans.push_back(node(v, u, a));
        a = 0;
      }
    } else if (vis[v] < vis[u]) {
      if (!a)
        a = v;
      else {
        ans.push_back(node(v, u, a));
        a = 0;
      }
    }
  }
  if (a) {
    ans.push_back(node(a, u, fa));
    return 1;
  }
  return 0;
}
int main() {
  int n, m, u, v, i, j;
  while (~scanf("%d%d", &n, &m)) {
    for (i = 0; i < m; i++) {
      scanf("%d%d", &u, &v);
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    if (m & 1) {
      printf("No solution\n");
      continue;
    }
    tot = 0;
    dfs(1, -1);
    int k = ans.size();
    for (i = 0; i < k; i++) {
      node tmp = ans[i];
      printf("%d %d %d\n", tmp.x, tmp.y, tmp.z);
    }
  }
  return 0;
}

```


### Prompt

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

Compute A \times B, truncate its fractional part, and print the result as an integer.

Constraints

* 0 \leq A \leq 10^{15}
* 0 \leq B < 10
* A is an integer.
* B is a number with two digits after the decimal point.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the answer as an integer.

Examples

Input

198 1.10

Output

217

Input

1 0.01

Output

0

Input

1000000000000000 9.99

Output

9990000000000000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long double A,B;
  long long S=0;
  cin >> A>>B;
  S=A*B;
  cout << S << endl;
}
```


### Prompt

Please create a solution in Cpp to the following problem:

Polycarpus has a finite sequence of opening and closing brackets. In order not to fall asleep in a lecture, Polycarpus is having fun with his sequence. He is able to perform two operations:

  * adding any bracket in any position (in the beginning, the end, or between any two existing brackets);
  * cyclic shift — moving the last bracket from the end of the sequence to the beginning.

Polycarpus can apply any number of operations to his sequence and adding a cyclic shift in any order. As a result, he wants to get the correct bracket sequence of the minimum possible length. If there are several such sequences, Polycarpus is interested in the lexicographically smallest one. Help him find such a sequence.

Acorrect bracket sequence is a sequence of opening and closing brackets, from which you can get a correct arithmetic expression by adding characters "1" and "+" . Each opening bracket must correspond to a closed one. For example, the sequences "(())()", "()", "(()(()))" are correct and ")(", "(()" and "(()))(" are not.

The sequence a1 a2... an is lexicographically smaller than sequence b1 b2... bn, if there is such number i from 1 to n, thatak = bk for 1 ≤ k < i and ai < bi. Consider that "("  < ")".

Input

The first line contains Polycarpus's sequence consisting of characters "(" and ")". The length of a line is from 1 to 1 000 000.

Output

Print a correct bracket sequence of the minimum length that Polycarpus can obtain by his operations. If there are multiple such sequences, print the lexicographically minimum one.

Examples

Input

()(())

Output

(())()

Input

()(

Output

(())

Note

The sequence in the first example is already correct, but to get the lexicographically minimum answer, you need to perform four cyclic shift operations. In the second example you need to add a closing parenthesis between the second and third brackets and make a cyclic shift. You can first make the shift, and then add the bracket at the end.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, s[2000100];
bool vis[2000100];
char t[2000100];
int sa[2000100], rnk[2000100], tmp[2000100], cnt[2000100];
void build(char *s) {
  int n = strlen(s) + 1, m = 256;
  int *x = rnk, *y = tmp, *z;
  for (int i = 0; i < m; i++) cnt[i] = 0;
  for (int i = 0; i < n; i++) cnt[x[i] = s[i]]++;
  for (int i = 1; i < m; i++) cnt[i] += cnt[i - 1];
  for (int i = n - 1; i >= 0; i--) sa[--cnt[x[i]]] = i;
  for (int j = 1, p = 1; p < n; j <<= 1, m = p) {
    p = 0;
    for (int i = n - j; i < n; i++) y[p++] = i;
    for (int i = 0; i < n; i++)
      if (sa[i] >= j) y[p++] = sa[i] - j;
    for (int i = 0; i < m; i++) cnt[i] = 0;
    for (int i = 0; i < n; i++) cnt[x[i]]++;
    for (int i = 1; i < m; i++) cnt[i] += cnt[i - 1];
    for (int i = n - 1; i >= 0; i--) sa[--cnt[x[y[i]]]] = y[i];
    z = x, x = y, y = z;
    x[sa[0]] = 0, p = 1;
    for (int i = 1; i < n; i++)
      x[sa[i]] = (y[sa[i]] == y[sa[i - 1]] && y[sa[i] + j] == y[sa[i - 1] + j])
                     ? p - 1
                     : p++;
  }
  for (int i = 0; i < n; i++) rnk[sa[i]] = i;
}
int main() {
  scanf("%s", t + 1);
  n = strlen(t + 1);
  int mn = 0;
  for (int i = 1; i <= n; i++) {
    s[i] = s[i - 1];
    if (t[i] == '(')
      s[i]++;
    else
      s[i]--;
    mn = min(mn, s[i]);
  }
  for (int i = 1; i <= n; i++) t[n + i] = t[i], s[i + n] = s[i] + s[n];
  int dn = 0;
  if (s[n] < 0) dn = -s[n];
  build(t + 1);
  multiset<int> S;
  for (int i = n + 1; i <= 2 * n; i++) S.insert(s[i]);
  int k, p = 1e9;
  for (int i = n; i >= 0; i--) {
    int t = *S.begin();
    S.erase(S.find(s[i + n]));
    if (t - s[i] + dn >= 0) {
      if (rnk[i] < p) p = rnk[i], k = i + 1;
    }
    S.insert(s[i]);
  }
  int sum = s[n];
  if (sum < 0)
    for (int i = sum; i < 0; i++) putchar('(');
  for (int i = 0; i < n; i++) putchar(t[k + i]);
  if (sum > 0)
    for (int i = 0; i < sum; i++) putchar(')');
  return 0;
}

```


### Prompt

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

There is a robot staying at X=0 on the Ox axis. He has to walk to X=n. You are controlling this robot and controlling how he goes. The robot has a battery and an accumulator with a solar panel.

The i-th segment of the path (from X=i-1 to X=i) can be exposed to sunlight or not. The array s denotes which segments are exposed to sunlight: if segment i is exposed, then s_i = 1, otherwise s_i = 0.

The robot has one battery of capacity b and one accumulator of capacity a. For each segment, you should choose which type of energy storage robot will use to go to the next point (it can be either battery or accumulator). If the robot goes using the battery, the current charge of the battery is decreased by one (the robot can't use the battery if its charge is zero). And if the robot goes using the accumulator, the current charge of the accumulator is decreased by one (and the robot also can't use the accumulator if its charge is zero).

If the current segment is exposed to sunlight and the robot goes through it using the battery, the charge of the accumulator increases by one (of course, its charge can't become higher than it's maximum capacity).

If accumulator is used to pass some segment, its charge decreases by 1 no matter if the segment is exposed or not.

You understand that it is not always possible to walk to X=n. You want your robot to go as far as possible. Find the maximum number of segments of distance the robot can pass if you control him optimally.

Input

The first line of the input contains three integers n, b, a (1 ≤ n, b, a ≤ 2 ⋅ 10^5) — the robot's destination point, the battery capacity and the accumulator capacity, respectively.

The second line of the input contains n integers s_1, s_2, ..., s_n (0 ≤ s_i ≤ 1), where s_i is 1 if the i-th segment of distance is exposed to sunlight, and 0 otherwise.

Output

Print one integer — the maximum number of segments the robot can pass if you control him optimally.

Examples

Input

5 2 1
0 1 0 1 0

Output

5

Input

6 2 1
1 0 0 1 0 1

Output

3

Note

In the first example the robot can go through the first segment using the accumulator, and charge levels become b=2 and a=0. The second segment can be passed using the battery, and charge levels become b=1 and a=1. The third segment can be passed using the accumulator, and charge levels become b=1 and a=0. The fourth segment can be passed using the battery, and charge levels become b=0 and a=1. And the fifth segment can be passed using the accumulator.

In the second example the robot can go through the maximum number of segments using battery two times and accumulator one time in any order.

### Response

```cpp
#include <bits/stdc++.h>
int n, b, a;
std::vector<int> A;
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  std::cin >> n >> b >> a;
  A.resize(n);
  for (int i = 0; i < (n); ++i) std::cin >> A[i];
  int ca = a;
  for (int i = 0; i < (n); ++i) {
    if (ca == 0 && b == 0) {
      std::cout << i << "\n";
      return 0;
    }
    if (A[i] == 1) {
      if (b > 0 && ca < a)
        b--, ca++;
      else
        ca--;
    } else {
      if (ca > 0)
        ca--;
      else
        b--;
    }
  }
  std::cout << n;
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Vasya has a non-negative integer n. He wants to round it to nearest integer, which ends up with 0. If n already ends up with 0, Vasya considers it already rounded.

For example, if n = 4722 answer is 4720. If n = 5 Vasya can round it to 0 or to 10. Both ways are correct.

For given n find out to which integer will Vasya round it.

Input

The first line contains single integer n (0 ≤ n ≤ 109) — number that Vasya has.

Output

Print result of rounding n. Pay attention that in some cases answer isn't unique. In that case print any correct answer.

Examples

Input

5

Output

0

Input

113

Output

110

Input

1000000000

Output

1000000000

Input

5432359

Output

5432360

Note

In the first example n = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[15];
  int b = 0;
  memset(a, 0, sizeof(a));
  scanf("%s", a);
  int lo = strlen(a);
  if (a[lo - 1] > '5') {
    if (lo > 1)
      a[lo - 2]++;
    else {
      b = 1;
    }
  }
  a[lo - 1] = '0';
  for (int i = lo; i >= 0; i--) {
    if (a[i] > '9') {
      if (i == 0) {
        b = 1;
        a[0] -= 10;
        break;
      }
      a[i - 1]++;
      a[i] -= 10;
    }
  }
  if (b) printf("%d", b);
  printf("%s", a);
  return 0;
}

```


### Prompt

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

The only difference between easy and hard versions is the maximum value of n.

You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n.

The positive integer is called good if it can be represented as a sum of distinct powers of 3 (i.e. no duplicates of powers of 3 are allowed).

For example:

  * 30 is a good number: 30 = 3^3 + 3^1,
  * 1 is a good number: 1 = 3^0,
  * 12 is a good number: 12 = 3^2 + 3^1,
  * but 2 is not a good number: you can't represent it as a sum of distinct powers of 3 (2 = 3^0 + 3^0),
  * 19 is not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representations 19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0 are invalid),
  * 20 is also not a good number: you can't represent it as a sum of distinct powers of 3 (for example, the representation 20 = 3^2 + 3^2 + 3^0 + 3^0 is invalid).

Note, that there exist other representations of 19 and 20 as sums of powers of 3 but none of them consists of distinct powers of 3.

For the given positive integer n find such smallest m (n ≤ m) that m is a good number.

You have to answer q independent queries.

Input

The first line of the input contains one integer q (1 ≤ q ≤ 500) — the number of queries. Then q queries follow.

The only line of the query contains one integer n (1 ≤ n ≤ 10^4).

Output

For each query, print such smallest integer m (where n ≤ m) that m is a good number.

Example

Input

7
1
2
6
13
14
3620
10000

Output

1
3
9
13
27
6561
19683

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long p[50];
  p[0] = 1;
  long long cumsum[50];
  cumsum[0] = 1;
  for (long long i = 1; i <= 38; i++) {
    p[i] = p[i - 1] * 3;
    cumsum[i] = cumsum[i - 1] + p[i];
  }
  long long t;
  scanf("%lld", &t);
  while (t--) {
    long long n;
    scanf("%lld", &n);
    long long ans = 0;
    long long x = n;
    for (long long i = 38; i >= 1; i--) {
      if (cumsum[i - 1] >= x) continue;
      x = x - p[i];
      ans = ans + p[i];
    }
    if (x > 0) {
      ans++;
    }
    cout << ans << "\n";
  }
}

```


### Prompt

Create a solution in CPP for the following problem:

The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of r1 cm, inner radius of r2 cm, (0 < r2 < r1) made of metal with density p1 g/cm3. The second part is an inner disk with radius r2 cm, it is made of metal with density p2 g/cm3. The disk is nested inside the ring.

The Olympic jury decided that r1 will take one of possible values of x1, x2, ..., xn. It is up to jury to decide which particular value r1 will take. Similarly, the Olympic jury decided that p1 will take one of possible value of y1, y2, ..., ym, and p2 will take a value from list z1, z2, ..., zk.

According to most ancient traditions the ratio between the outer ring mass mout and the inner disk mass min must equal <image>, where A, B are constants taken from ancient books. Now, to start making medals, the jury needs to take values for r1, p1, p2 and calculate the suitable value of r2.

The jury wants to choose the value that would maximize radius r2. Help the jury find the sought value of r2. Value r2 doesn't have to be an integer.

Medal has a uniform thickness throughout the area, the thickness of the inner disk is the same as the thickness of the outer ring.

Input

The first input line contains an integer n and a sequence of integers x1, x2, ..., xn. The second input line contains an integer m and a sequence of integers y1, y2, ..., ym. The third input line contains an integer k and a sequence of integers z1, z2, ..., zk. The last line contains two integers A and B.

All numbers given in the input are positive and do not exceed 5000. Each of the three sequences contains distinct numbers. The numbers in the lines are separated by spaces.

Output

Print a single real number — the sought value r2 with absolute or relative error of at most 10 - 6. It is guaranteed that the solution that meets the problem requirements exists.

Examples

Input

3 1 2 3
1 2
3 3 2 1
1 2

Output

2.683281573000

Input

4 2 3 6 4
2 1 2
3 10 6 8
2 1

Output

2.267786838055

Note

In the first sample the jury should choose the following values: r1 = 3, p1 = 2, p2 = 1.

### Response

```cpp
#include <bits/stdc++.h>
const int MAXN = 5050;
int n, m, k;
int x[MAXN];
int y[MAXN];
int z[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &x[i]);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) scanf("%d", &y[i]);
  scanf("%d", &k);
  for (int i = 0; i < k; i++) scanf("%d", &z[i]);
  int A, B;
  scanf("%d%d", &A, &B);
  int r1 = x[0];
  for (int i = 1; i < n; i++)
    if (x[i] > r1) r1 = x[i];
  double r2 = 0;
  for (int i = 0; i < m; i++)
    for (int j = 0; j < k; j++)
      if (double((double)r1 * (double)r1 * (double)B * (double)y[i]) /
              double((double)A * (double)z[j] + (double)B * (double)y[i]) >
          r2)
        r2 = double((double)r1 * (double)r1 * (double)B * (double)y[i]) /
             double((double)A * (double)z[j] + (double)B * (double)y[i]);
  printf("%.8lf\n", sqrt(r2));
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Given a positive integer m, we say that a sequence x_1, x_2, ..., x_n of positive integers is m-cute if for every index i such that 2 ≤ i ≤ n it holds that x_i = x_{i - 1} + x_{i - 2} + ... + x_1 + r_i for some positive integer r_i satisfying 1 ≤ r_i ≤ m.

You will be given q queries consisting of three positive integers a, b and m. For each query you must determine whether or not there exists an m-cute sequence whose first term is a and whose last term is b. If such a sequence exists, you must additionally find an example of it.

Input

The first line contains an integer number q (1 ≤ q ≤ 10^3) — the number of queries.

Each of the following q lines contains three integers a, b, and m (1 ≤ a, b, m ≤ 10^{14}, a ≤ b), describing a single query.

Output

For each query, if no m-cute sequence whose first term is a and whose last term is b exists, print -1.

Otherwise print an integer k (1 ≤ k ≤ 50), followed by k integers x_1, x_2, ..., x_k (1 ≤ x_i ≤ 10^{14}). These integers must satisfy x_1 = a, x_k = b, and that the sequence x_1, x_2, ..., x_k is m-cute.

It can be shown that under the problem constraints, for each query either no m-cute sequence exists, or there exists one with at most 50 terms.

If there are multiple possible sequences, you may print any of them.

Example

Input

2
5 26 2
3 9 1

Output

4 5 6 13 26
-1

Note

Consider the sample. In the first query, the sequence 5, 6, 13, 26 is valid since 6 = 5 + \bf{\color{blue} 1}, 13 = 6 + 5 + {\bf\color{blue} 2} and 26 = 13 + 6 + 5 + {\bf\color{blue} 2} have the bold values all between 1 and 2, so the sequence is 2-cute. Other valid sequences, such as 5, 7, 13, 26 are also accepted.

In the second query, the only possible 1-cute sequence starting at 3 is 3, 4, 8, 16, ..., which does not contain 9.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int sz = 60;
long long pow2[sz];
void solve(long long a, long long b, long long m) {
  int maxn = 55;
  for (int q = maxn; q > 0; q--) {
    long long cur = 0;
    vector<long long> r(q, 1);
    r[0] = a;
    vector<long long> coef(q, 1);
    for (int i = 0; i < q - 1; i++) {
      coef[i] = pow2[q - i - 2];
    }
    for (int i = 0; i < q; i++) {
      cur += coef[i] * r[i];
      if (coef[i] * r[i] < 0) {
        cur = -1;
        break;
      }
    }
    if (cur > b || cur < 0) continue;
    for (int i = 1; i < q; i++) {
      long long left = 1;
      long long right = m;
      long long mid;
      while (left <= right) {
        mid = (left + right) / 2;
        if (cur + (mid - 1) * coef[i] <= b && cur + (mid - 1) * coef[i] > 0) {
          r[i] = mid;
          left = mid + 1;
        } else {
          right = mid - 1;
        }
      }
      cur += (r[i] - 1) * coef[i];
    }
    if (cur == b) {
      cout << q << " ";
      long long sum = 0;
      for (int i = 0; i < q; i++) {
        long long pre = sum;
        sum += r[i];
        cout << sum << " ";
        sum += pre;
      }
      cout << "\n";
      return;
    }
  }
  cout << "-1\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int q;
  cin >> q;
  pow2[0] = 1;
  for (int i = 1; i < sz; i++) {
    pow2[i] = pow2[i - 1] * 2;
  }
  while (q--) {
    long long a, b, m;
    cin >> a >> b >> m;
    solve(a, b, m);
  }
  return 0;
}

```


### Prompt

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

Natsuki and her friends were taken to the space by an alien and made friends with a lot of aliens. During the space travel, she discovered that aliens’ hands were often very different from humans’. Generally speaking, in a kind of aliens, there are N fingers and M bend rules on a hand. Each bend rule describes that a finger A always bends when a finger B bends. However, this rule does not always imply that the finger B bends when the finger A bends.

When she were counting numbers with the fingers, she was anxious how many numbers her alien friends can count with the fingers. However, because some friends had too complicated rule sets, she could not calculate those. Would you write a program for her?

Input

N M
S1 D1
S2 D2
.
.
.
SM DM

The first line contains two integers N and M (1 ≤ N ≤ 1000, 0 ≤ M ≤ 1000) in this order. The following M lines mean bend rules. Each line contains two integers Si and Di in this order, which mean that the finger Di always bends when the finger Si bends. Any finger appears at most once in S.

Output

Calculate how many numbers her alien friends can count with the fingers. Print the answer modulo 1000000007 in a line.

Examples

Input

5 4
2 3
3 4
4 3
5 4

Output

10

Input

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

Output

2

Input

5 0

Output

32

### Response

```cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int lli;
const lli mod = 1e9 +7;

void dfs(int node, vector<int> &ord, vector<bool> &used, vector<vector<int> > &adj){
    if(used[node]) return;
    used[node] = true;
    for(int to: adj[node]){
        dfs(to, ord, used, adj);
    }
    ord.push_back(node);
}

vector<vector<int> > scc_decomposition(vector<vector<int> > &adj){
    int n = adj.size();
    vector<vector<int> > revadj(n);
    for(int i=0; i<n; i++){
        for(int to: adj[i]){
            revadj[to].push_back(i);
        }
    }

    vector<bool> used(n, false);
    vector<int> ord;
    for(int i=0; i<n; i++){
        if(used[i]) continue;
        dfs(i, ord, used, adj);
    }
    used = vector<bool>(n, false);
    vector<vector<int> > res;
    for(int i=n-1; i>=0; i--){
        if(used[ord[i]]) continue;
        res.emplace_back();
        dfs(ord[i], res.back(), used, revadj);
        sort(res.back().begin(), res.back().end());
    }
    return res;
}

lli solve(vector<vector<int> > &adj){
    int n = adj.size();
    vector<int> ord_in(n, 0);
    for(vector<int> v: adj){
        for(int i: v){
            ord_in[i]++;
        }
    }

    queue<int> wait;
    for(int i=0; i<n; i++){
        if(ord_in[i] == 0) wait.push(i);
    }
    lli ans = 1;
    vector<lli> dp(n, 1);
    while(!wait.empty()){
        int cur = wait.front();
        wait.pop();
        for(int i: adj[cur]){
            dp[i] *= dp[cur] +1;
            dp[i] %= mod;
            ord_in[i]--;
            if(ord_in[i] == 0) wait.push(i);
        }
        if(adj[cur].empty()){
            ans *= (dp[cur] +1);
            ans %= mod;
        }
    }
    return ans;
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int> > adj(n);
    for(int i=0; i<m; i++){
        int s,d;
        cin >> s >> d;
        s--; d--;
        adj[s].push_back(d);
    }

    vector<vector<int> > scc = scc_decomposition(adj);
    vector<int> conv(n);
    for(int i=0; i<(int)scc.size(); i++){
        for(int j: scc[i]){
            conv[j] = i;
        }
    }

    {
        vector<vector<int> > newadj(scc.size());
        for(int i=0; i<n; i++){
            for(int j: adj[i]){
                if(conv[i] == conv[j]) continue;
                newadj[conv[i]].push_back(conv[j]);
            }
        }
        for(vector<int> v: newadj){
            sort(v.begin(), v.end());
            v.erase(unique(v.begin(), v.end()), v.end());
        }
        adj = newadj;
    }

    cout << solve(adj) << endl;
    return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

During the last 24 hours Hamed and Malek spent all their time playing "Sharti". Now they are too exhausted to finish the last round. So they asked you for help to determine the winner of this round.

"Sharti" is played on a n × n board with some of cells colored white and others colored black. The rows of the board are numbered from top to bottom using number 1 to n. Also the columns of the board are numbered from left to right using numbers 1 to n. The cell located at the intersection of i-th row and j-th column is denoted by (i, j).

The players alternatively take turns. In each turn the player must choose a square with side-length at most k with its lower-right cell painted white. Then the colors of all the cells in this square are inversed (white cells become black and vice-versa). The player who cannot perform a move in his turn loses.

You know Hamed and Malek are very clever and they would have played their best moves at each turn. Knowing this and the fact that Hamed takes the first turn, given the initial board as described in the input, you must determine which one of them will be the winner.

Input

In this problem the initial board is specified as a set of m rectangles. All cells that lie inside at least one of these rectangles are colored white and the rest are colored black.

In the first line of input three space-spereated integers n, m, k (1 ≤ k ≤ n ≤ 109, 1 ≤ m ≤ 5·104) follow, denoting size of the board, number of rectangles and maximum size of the turn square during the game, respectively.

In i-th line of the next m lines four space-seperated integers ai, bi, ci, di (1 ≤ ai ≤ ci ≤ n, 1 ≤ bi ≤ di ≤ n) are given meaning that i-th rectangle determining the initial board is a rectangle with upper-left cell at (ai, bi) and lower-right cell at (ci, di).

Output

If Hamed wins, print "Hamed", otherwise print "Malek" (without the quotes).

Examples

Input

5 2 1
1 1 3 3
2 2 4 4

Output

Malek

Input

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

Output

Hamed

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10000;
map<int, vector<pair<int, int> > > mpa, mpd;
vector<int> ps;
int arr[2 * maxn], C;
int a[maxn], b[maxn], c[maxn], d[maxn], n, m, k;
long long mn[4 * maxn], cn[4 * maxn], lz[4 * maxn];
void build(int l = 0, int r = C - 1, int id = 1) {
  if ((r - l) == 1) {
    cn[id] = arr[r] - arr[l];
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, 2 * id);
  build(mid, r, 2 * id + 1);
  cn[id] = cn[2 * id] + cn[2 * id + 1];
}
void get(int l, int r, int ind) {
  mn[ind] += lz[ind];
  if (l != r) {
    lz[2 * ind] += lz[ind];
    lz[2 * ind + 1] += lz[ind];
  }
  lz[ind] = 0;
}
void add(int f, int s, int x, int l = 0, int r = C - 1, int ind = 1) {
  if (f >= s || l >= r) return;
  get(l, r, ind);
  if (s <= l || r <= f) return;
  if (f <= l && r <= s) {
    lz[ind] += x;
    get(l, r, ind);
    return;
  }
  int mid = (l + r) / 2;
  add(f, s, x, l, mid, 2 * ind);
  add(f, s, x, mid, r, 2 * ind + 1);
  mn[ind] = min(mn[2 * ind], mn[2 * ind + 1]);
  cn[ind] = 0;
  if (mn[ind] == mn[2 * ind]) cn[ind] += cn[2 * ind];
  if (mn[ind] == mn[2 * ind + 1]) cn[ind] += cn[2 * ind + 1];
}
bool solve() {
  memset(mn, 0, sizeof mn);
  memset(cn, 0, sizeof cn);
  memset(lz, 0, sizeof lz);
  ps.clear();
  mpa.clear();
  mpd.clear();
  C = 0;
  for (int i = 0; i < m; i++) {
    if (a[i] < c[i] && b[i] < d[i]) {
      mpa[b[i]].push_back({a[i], c[i]});
      mpd[d[i]].push_back({a[i], c[i]});
      ps.push_back(b[i]);
      ps.push_back(d[i]);
      arr[C++] = a[i];
      arr[C++] = c[i];
    }
  }
  if (C == 0) return 0;
  sort(arr, arr + C);
  sort(ps.begin(), ps.end());
  C = unique(arr, arr + C) - arr;
  ps.resize(unique(ps.begin(), ps.end()) - ps.begin());
  build();
  bool ans = 0;
  int psb = 0;
  for (int pos : ps) {
    ans ^= (pos - psb) & (arr[C - 1] - arr[0] - (mn[1] != 0 ? 0 : cn[1])) & 1;
    psb = pos;
    for (pair<int, int> p : mpd[pos])
      add(lower_bound(arr, arr + C, p.first) - arr,
          lower_bound(arr, arr + C, p.second) - arr, -1);
    for (pair<int, int> p : mpa[pos])
      add(lower_bound(arr, arr + C, p.first) - arr,
          lower_bound(arr, arr + C, p.second) - arr, 1);
  }
  return ans;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
    c[i]++, d[i]++;
  }
  while (k > 0) {
    if (solve()) {
      printf("Hamed\n");
      return 0;
    }
    for (int i = 0; i < m; i++) {
      a[i] = (a[i] + 1) / 2;
      b[i] = (b[i] + 1) / 2;
      c[i] = (c[i] + 1) / 2;
      d[i] = (d[i] + 1) / 2;
    }
    k >>= 1;
  }
  printf("Malek\n");
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.

The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has n hotels, where the i-th hotel is located in the city with coordinate x_i. Sonya is a smart girl, so she does not open two or more hotels in the same city.

Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to d. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel.

Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original n hotels to the new one is equal to d.

Input

The first line contains two integers n and d (1≤ n≤ 100, 1≤ d≤ 10^9) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.

The second line contains n different integers in strictly increasing order x_1, x_2, …, x_n (-10^9≤ x_i≤ 10^9) — coordinates of Sonya's hotels.

Output

Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to d.

Examples

Input

4 3
-3 2 9 16

Output

6

Input

5 2
4 8 11 18 19

Output

5

Note

In the first example, there are 6 possible cities where Sonya can build a hotel. These cities have coordinates -6, 5, 6, 12, 13, and 19.

In the second example, there are 5 possible cities where Sonya can build a hotel. These cities have coordinates 2, 6, 13, 16, and 21.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, d;
  cin >> n >> d;
  long long* arr = new long long[n + 1];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long start = arr[0] - d;
  long long count = 0;
  long long end = arr[0] - d;
  unordered_map<int, int> taken;
  for (long long i = 0; i < n; i++) {
    long long left = arr[i] - d;
    long long right = arr[i] + d;
    if (left >= end && taken[left] == 0) {
      count++;
      taken[left] = 1;
    }
    end = right;
    if (i != n - 1) {
      if ((arr[i] + d) <= (arr[i + 1] - d)) {
        if (taken[right] == 0) {
          count++;
          taken[right]++;
        }
      }
    } else {
      if (taken[right] == 0) {
        count++;
        taken[right]++;
      }
    }
  }
  cout << count;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

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

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

Input

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

Output

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

Examples

Input

6 2 3
2 2 2 2 1 1

Output

2

Input

2 5 1
5 8

Output

9

Note

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int a[100005], t[400005], res, n, m, w, mx = 0;
long long int bs(long long int high, long long int low) {
  if (low > high) return -100;
  long long int mid = (high + low) / 2, cur = 0, sh = 0;
  for (int i = 0; i < n; i++) {
    cur -= t[i];
    t[i] = 0;
    if (mid > a[i] + cur) {
      sh += (mid - (a[i] + cur));
      t[i + w] += (mid - (a[i] + cur));
      cur = mid - a[i];
    }
  }
  if (sh > m) return bs(mid - 1, low);
  return max(mid, bs(high, mid + 1));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(t, 0, sizeof t);
  cin >> n >> m >> w;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > mx) mx = a[i];
  }
  res = bs(m + mx + 1, 0);
  cout << res << "\n";
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Dima and Inna love spending time together. The problem is, Seryozha isn't too enthusiastic to leave his room for some reason. But Dima and Inna love each other so much that they decided to get criminal...

Dima constructed a trap graph. He shouted: "Hey Seryozha, have a look at my cool graph!" to get his roommate interested and kicked him into the first node.

A trap graph is an undirected graph consisting of n nodes and m edges. For edge number k, Dima denoted a range of integers from lk to rk (lk ≤ rk). In order to get out of the trap graph, Seryozha initially (before starting his movements) should pick some integer (let's call it x), then Seryozha must go some way from the starting node with number 1 to the final node with number n. At that, Seryozha can go along edge k only if lk ≤ x ≤ rk.

Seryozha is a mathematician. He defined the loyalty of some path from the 1-st node to the n-th one as the number of integers x, such that if he initially chooses one of them, he passes the whole path. Help Seryozha find the path of maximum loyalty and return to his room as quickly as possible!

Input

The first line of the input contains two integers n and m (2 ≤ n ≤ 103, 0 ≤ m ≤ 3·103). Then follow m lines describing the edges. Each line contains four integers ak, bk, lk and rk (1 ≤ ak, bk ≤ n, 1 ≤ lk ≤ rk ≤ 106). The numbers mean that in the trap graph the k-th edge connects nodes ak and bk, this edge corresponds to the range of integers from lk to rk.

Note that the given graph can have loops and multiple edges.

Output

In a single line of the output print an integer — the maximum loyalty among all paths from the first node to the n-th one. If such paths do not exist or the maximum loyalty equals 0, print in a single line "Nice work, Dima!" without the quotes.

Examples

Input

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

Output

6

Input

5 6
1 2 1 10
2 5 11 20
1 4 2 5
1 3 10 11
3 4 12 10000
4 5 6 6

Output

Nice work, Dima!

Note

Explanation of the first example.

Overall, we have 2 ways to get from node 1 to node 4: first you must go along the edge 1-2 with range [1-10], then along one of the two edges 2-4.

One of them contains range [3-5], that is, we can pass through with numbers 3, 4, 5. So the loyalty of such path is 3.

If we go along edge 2-4 with range [2-7], then we can pass through with numbers 2, 3, 4, 5, 6, 7. The loyalty is 6. That is the answer.

The edge 1-2 have no influence on the answer because its range includes both ranges of the following edges.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e3 + 5;
struct Node {
  int b, l, r;
} tmp;
vector<Node> edge[N];
set<pair<int, int> > len[N];
int n, m, ans = 0;
void Add_edge(int a, int b, int l, int r) {
  tmp.b = b;
  tmp.l = l, tmp.r = r;
  edge[a].push_back(tmp);
}
void solve() {
  queue<Node> q;
  tmp.b = 1, tmp.l = 0, tmp.r = INF;
  q.push(tmp);
  set<pair<int, int> >::iterator it;
  while (!q.empty()) {
    tmp = q.front();
    q.pop();
    int id = tmp.b;
    int l = tmp.l, r = tmp.r;
    if (id == n) {
      ans = max(ans, r - l + 1);
      continue;
    }
    for (int i = 0; i < edge[id].size(); i++) {
      int ll = max(l, edge[id][i].l);
      int rr = min(r, edge[id][i].r);
      int t = edge[id][i].b;
      if (ll > rr) continue;
      bool flag = 0;
      for (it = len[t].begin(); it != len[t].end(); it++) {
        if ((*it).first <= ll && (*it).second >= rr) {
          flag = 1;
          break;
        }
      }
      if (flag) continue;
      len[t].insert(pair<int, int>(ll, rr));
      tmp.b = t;
      tmp.l = ll;
      tmp.r = rr;
      q.push(tmp);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int a, b, l, r;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b >> l >> r;
    Add_edge(a, b, l, r);
    Add_edge(b, a, l, r);
  }
  solve();
  if (ans == 0)
    cout << "Nice work, Dima!\n";
  else
    cout << ans << endl;
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Nick has n bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda ai and bottle volume bi (ai ≤ bi).

Nick has decided to pour all remaining soda into minimal number of bottles, moreover he has to do it as soon as possible. Nick spends x seconds to pour x units of soda from one bottle to another.

Nick asks you to help him to determine k — the minimal number of bottles to store all remaining soda and t — the minimal time to pour soda into k bottles. A bottle can't store more soda than its volume. All remaining soda should be saved.

Input

The first line contains positive integer n (1 ≤ n ≤ 100) — the number of bottles.

The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is the amount of soda remaining in the i-th bottle.

The third line contains n positive integers b1, b2, ..., bn (1 ≤ bi ≤ 100), where bi is the volume of the i-th bottle.

It is guaranteed that ai ≤ bi for any i.

Output

The only line should contain two integers k and t, where k is the minimal number of bottles that can store all the soda and t is the minimal time to pour the soda into k bottles.

Examples

Input

4
3 3 4 3
4 7 6 5

Output

2 6

Input

2
1 1
100 100

Output

1 1

Input

5
10 30 5 6 24
10 41 7 8 24

Output

3 11

Note

In the first example Nick can pour soda from the first bottle to the second bottle. It will take 3 seconds. After it the second bottle will contain 3 + 3 = 6 units of soda. Then he can pour soda from the fourth bottle to the second bottle and to the third bottle: one unit to the second and two units to the third. It will take 1 + 2 = 3 seconds. So, all the soda will be in two bottles and he will spend 3 + 3 = 6 seconds to do it.

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:128000000")
using namespace std;
void solve();
void precalc();
int TESTNUM = 0;
int main() {
  string s = "";
  cin.tie(0);
  cout.sync_with_stdio(0);
  cout.precision(10);
  cout << fixed;
  precalc();
  int t = 1;
  while (t--) {
    ++TESTNUM;
    solve();
  }
  return 0;
}
template <typename T>
T binpow(T q, T w, T mod) {
  if (!w) return 1 % mod;
  if (w & 1) return q * 1LL * binpow(q, w - 1, mod) % mod;
  return binpow(q * 1LL * q % mod, w / 2, mod);
}
void precalc() {}
template <typename T>
T gcd(T q, T w) {
  while (w) {
    q %= w;
    swap(q, w);
  }
  return q;
}
template <typename T>
T lcm(T q, T w) {
  return q / gcd(q, w) * w;
}
inline int nxt() {
  int x;
  cin >> x;
  return x;
}
const int C = 100 * 101;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  int a_sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a_sum += a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  vector<vector<vector<int>>> dp(
      2, vector<vector<int>>(n + 1, vector<int>(C, 1e9)));
  dp[0][0][0] = 0;
  int par = 0;
  for (int i = 0; i < n; ++i) {
    dp[par ^ 1].assign(n + 1, vector<int>(C, 1e9));
    for (int used = 0; used <= i; ++used) {
      for (int sum = 0; sum < C; ++sum) {
        dp[par ^ 1][used][sum] =
            min(dp[par ^ 1][used][sum], dp[par][used][sum] + a[i]);
        if (sum + b[i] < C) {
          dp[par ^ 1][used + 1][sum + b[i]] =
              min(dp[par ^ 1][used + 1][sum + b[i]], dp[par][used][sum]);
        }
      }
    }
    par ^= 1;
  }
  int used = 0;
  while (true) {
    bool f = false;
    for (int sum = a_sum; sum < C; ++sum) {
      if (dp[par][used][sum] < 1e8) {
        f = true;
        break;
      }
    }
    if (f) {
      break;
    }
    ++used;
  }
  cout << used << " ";
  int res = 1e9;
  for (int sum = a_sum; sum < C; ++sum) {
    res = min(res, dp[par][used][sum]);
  }
  cout << res << "\n";
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters.

There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogo, ogogo, ogogogo are fillers, but the words go, og, ogog, ogogog and oggo are not fillers.

The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here.

To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length.

Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking!

Input

The first line contains a positive integer n (1 ≤ n ≤ 100) — the length of the interview.

The second line contains the string s of length n, consisting of lowercase English letters.

Output

Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences.

Examples

Input

7
aogogob

Output

a***b

Input

13
ogogmgogogogo

Output

***gmg***

Input

9
ogoogoogo

Output

*********

Note

The first sample contains one filler word ogogo, so the interview for printing is "a***b".

The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  int n = 0;
  cin >> n >> a;
  for (int i = 0; i < a.size(); i++)
    if (a[i] == 'o' && a[i + 1] == 'g' && a[i + 2] == 'o' && i <= n - 3) {
      while (a[i + 1] == 'g' && a[i + 2] == 'o') i += 2;
      b.append("***");
    } else
      b.push_back(a[i]);
  cout << b << endl;
  return 0;
}

```


### Prompt

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

This problem is the most boring one you've ever seen.

Given a sequence of integers a1, a2, ..., an and a non-negative integer h, our goal is to partition the sequence into two subsequences (not necessarily consist of continuous elements). Each element of the original sequence should be contained in exactly one of the result subsequences. Note, that one of the result subsequences can be empty.

Let's define function f(ai, aj) on pairs of distinct elements (that is i ≠ j) in the original sequence. If ai and aj are in the same subsequence in the current partition then f(ai, aj) = ai + aj otherwise f(ai, aj) = ai + aj + h.

Consider all possible values of the function f for some partition. We'll call the goodness of this partiotion the difference between the maximum value of function f and the minimum value of function f.

Your task is to find a partition of the given sequence a that have the minimal possible goodness among all possible partitions.

Input

The first line of input contains integers n and h (2 ≤ n ≤ 105, 0 ≤ h ≤ 108). In the second line there is a list of n space-separated integers representing a1, a2, ..., an (0 ≤ ai ≤ 108).

Output

The first line of output should contain the required minimum goodness.

The second line describes the optimal partition. You should print n whitespace-separated integers in the second line. The i-th integer is 1 if ai is in the first subsequence otherwise it should be 2.

If there are several possible correct answers you are allowed to print any of them.

Examples

Input

3 2
1 2 3

Output

1
1 2 2

Input

5 10
0 1 0 2 1

Output

3
2 2 2 2 2

Note

In the first sample the values of f are as follows: f(1, 2) = 1 + 2 + 2 = 5, f(1, 3) = 1 + 3 + 2 = 6 and f(2, 3) = 2 + 3 = 5. So the difference between maximum and minimum values of f is 1.

In the second sample the value of h is large, so it's better for one of the sub-sequences to be empty.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long mod = (long long)1e+9 + 9;
int main() {
  int n, h;
  cin >> n >> h;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.begin(), a.end());
  vector<int> ans(n, 1);
  if (n == 2) {
    cout << 0 << endl << "1 1";
    return 0;
  }
  int extr = a[n - 1].first + a[n - 2].first - a[0].first - a[1].first;
  if (max(a[n - 1].first + a[n - 2].first, a[0].first + a[n - 1].first + h) -
          min(a[0].first + a[1].first + h, a[1].first + a[2].first) <
      extr) {
    extr =
        max(a[n - 1].first + a[n - 2].first, a[0].first + a[n - 1].first + h) -
        min(a[0].first + a[1].first + h, a[1].first + a[2].first);
    ans[a[0].second] = 2;
  }
  cout << extr << endl;
  for (int i = 0; i < n; ++i) cout << ans[i] << " ";
  return 0;
}

```