### Prompt

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

Let's call left cyclic shift of some string t_1 t_2 t_3 ... t_{n - 1} t_n as string t_2 t_3 ... t_{n - 1} t_n t_1.

Analogically, let's call right cyclic shift of string t as string t_n t_1 t_2 t_3 ... t_{n - 1}.

Let's say string t is good if its left cyclic shift is equal to its right cyclic shift.

You are given string s which consists of digits 0–9.

What is the minimum number of characters you need to erase from s to make it good?

Input

The first line contains single integer t (1 ≤ t ≤ 1000) — the number of test cases.

Next t lines contains test cases — one per line. The first and only line of each test case contains string s (2 ≤ |s| ≤ 2 ⋅ 10^5). Each character s_i is digit 0–9.

It's guaranteed that the total length of strings doesn't exceed 2 ⋅ 10^5.

Output

For each test case, print the minimum number of characters you need to erase from s to make it good.

Example

Input

3
95831
100120013
252525252525

Output

3
5
0

Note

In the first test case, you can erase any 3 characters, for example, the 1-st, the 3-rd, and the 4-th. You'll get string 51 and it is good.

In the second test case, we can erase all characters except 0: the remaining string is 0000 and it's good.

In the third test case, the given string s is already good.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  long long i, j, k, n, m, t = 1;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    n = s.size();
    map<char, long long> make_pair;
    long long mx = INT_MIN;
    for (i = 0; i < n; i++) {
      make_pair[s[i]]++;
    }
    for (char c = '0'; c <= '9'; c++) {
      if (make_pair[c] > mx) {
        mx = make_pair[c];
      }
    }
    for (char c1 = '0'; c1 < '9'; c1++) {
      for (char c2 = c1 + 1; c2 <= '9'; c2++) {
        k = 0;
        char prev = '$';
        for (i = 0; i < n; i++) {
          if (s[i] == c1) {
            if (prev == c2) {
              prev = c1;
              k++;
            } else if (prev == '$') {
              prev = c1;
              k++;
            }
          } else if (s[i] == c2) {
            if (prev == c1) {
              prev = c2;
              k++;
            } else if (prev == '$') {
              prev = c2;
              k++;
            }
          }
        }
        if (k > mx && k % 2 == 0) {
          mx = k;
        } else if ((k - 1) > mx && (k - 1) % 2 == 0) {
          mx = k - 1;
        }
      }
    }
    cout << s.size() - mx << endl;
  }
  return 0;
}

```


### Prompt

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

Gerald got tired of playing board games with the usual six-sided die, and he bought a toy called Randomizer. It functions as follows.

A Randomizer has its own coordinate plane on which a strictly convex polygon is painted, the polygon is called a basic polygon. If you shake a Randomizer, it draws some nondegenerate (i.e. having a non-zero area) convex polygon with vertices at some vertices of the basic polygon. The result of the roll (more precisely, the result of the shaking) is considered to be the number of points with integer coordinates, which were strictly inside (the points on the border are not considered) the selected polygon. Now Gerald is wondering: what is the expected result of shaking the Randomizer?

During the shaking the Randomizer considers all the possible non-degenerate convex polygons with vertices at the vertices of the basic polygon. Let's assume that there are k versions of the polygons. Then the Randomizer chooses each of them with probability <image>.

Input

The first line of the input contains a single integer n (3 ≤ n ≤ 100 000) — the number of vertices of the basic polygon.

Next n lines contain the coordinates of the vertices of the basic polygon. The i-th of these lines contain two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — the coordinates of the i-th vertex of the polygon. The vertices are given in the counter-clockwise order.

Output

Print the sought expected value with absolute or relative error at most 10 - 9.

Examples

Input

4
0 0
2 0
2 2
0 2

Output

0.2

Input

5
0 0
2 0
2 2
1 3
0 2

Output

0.8125

Note

A polygon is called strictly convex if it is convex and no its vertices lie on the same line.

Let's assume that a random variable takes values x1, ..., xn with probabilities p1, ..., pn, correspondingly. Then the expected value of this variable equals to <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
long long x[100005], y[100005];
long double P, ans, sum;
long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; }
long long GCD(long long x, long long y) {
  if (x < 0) x = -x;
  if (y < 0) y = -y;
  if (x > y) swap(x, y);
  return gcd(x, y);
}
int main() {
  int i, j, k;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%I64d %I64d", &x[i], &y[i]);
  for (i = 1; i <= 90 && i < n; i++) {
    P = 1.0 / (pow(2, i + 1) -
               (1.0 + n + 0.5 * n * (n - 1)) / pow(2, n - i - 1)) -
        1.0 / (pow(2, n) - 1 - n - 0.5 * n * (n - 1));
    for (j = 1; j <= n; j++) {
      k = (j + i - 1) % n + 1;
      ans += (x[j] * y[k] - y[j] * x[k]) / 2.0 * P;
      sum += GCD(x[j] - x[k], y[j] - y[k]) * P;
    }
  }
  ans = ans - sum / 2.0 + 1;
  printf("%.10lf", (double)ans);
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Koa the Koala has a matrix A of n rows and m columns. Elements of this matrix are distinct integers from 1 to n ⋅ m (each number from 1 to n ⋅ m appears exactly once in the matrix).

For any matrix M of n rows and m columns let's define the following:

  * The i-th row of M is defined as R_i(M) = [ M_{i1}, M_{i2}, …, M_{im} ] for all i (1 ≤ i ≤ n).
  * The j-th column of M is defined as C_j(M) = [ M_{1j}, M_{2j}, …, M_{nj} ] for all j (1 ≤ j ≤ m).

Koa defines S(A) = (X, Y) as the spectrum of A, where X is the set of the maximum values in rows of A and Y is the set of the maximum values in columns of A.

More formally:

  * X = \{ max(R_1(A)), max(R_2(A)), …, max(R_n(A)) \}
  * Y = \{ max(C_1(A)), max(C_2(A)), …, max(C_m(A)) \}

Koa asks you to find some matrix A' of n rows and m columns, such that each number from 1 to n ⋅ m appears exactly once in the matrix, and the following conditions hold:

  * S(A') = S(A)
  * R_i(A') is bitonic for all i (1 ≤ i ≤ n)
  * C_j(A') is bitonic for all j (1 ≤ j ≤ m)

An array t (t_1, t_2, …, t_k) is called bitonic if it first increases and then decreases.

More formally: t is bitonic if there exists some position p (1 ≤ p ≤ k) such that: t_1 < t_2 < … < t_p > t_{p+1} > … > t_k.

Help Koa to find such matrix or to determine that it doesn't exist.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 250) — the number of rows and columns of A.

Each of the ollowing n lines contains m integers. The j-th integer in the i-th line denotes element A_{ij} (1 ≤ A_{ij} ≤ n ⋅ m) of matrix A. It is guaranteed that every number from 1 to n ⋅ m appears exactly once among elements of the matrix.

Output

If such matrix doesn't exist, print -1 on a single line.

Otherwise, the output must consist of n lines, each one consisting of m space separated integers — a description of A'.

The j-th number in the i-th line represents the element A'_{ij}.

Every integer from 1 to n ⋅ m should appear exactly once in A', every row and column in A' must be bitonic and S(A) = S(A') must hold.

If there are many answers print any.

Examples

Input

3 3
3 5 6
1 7 9
4 8 2

Output

9 5 1
7 8 2
3 6 4

Input

2 2
4 1
3 2

Output

4 1
3 2

Input

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

Output

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

Note

Let's analyze the first sample:

For matrix A we have:

    * Rows:
      * R_1(A) = [3, 5, 6]; max(R_1(A)) = 6
      * R_2(A) = [1, 7, 9]; max(R_2(A)) = 9
      * R_3(A) = [4, 8, 2]; max(R_3(A)) = 8

    * Columns:
      * C_1(A) = [3, 1, 4]; max(C_1(A)) = 4
      * C_2(A) = [5, 7, 8]; max(C_2(A)) = 8
      * C_3(A) = [6, 9, 2]; max(C_3(A)) = 9

  * X = \{ max(R_1(A)), max(R_2(A)), max(R_3(A)) \} = \{ 6, 9, 8 \}
  * Y = \{ max(C_1(A)), max(C_2(A)), max(C_3(A)) \} = \{ 4, 8, 9 \}
  * So S(A) = (X, Y) = (\{ 6, 9, 8 \}, \{ 4, 8, 9 \})

For matrix A' we have:

    * Rows:
      * R_1(A') = [9, 5, 1]; max(R_1(A')) = 9
      * R_2(A') = [7, 8, 2]; max(R_2(A')) = 8
      * R_3(A') = [3, 6, 4]; max(R_3(A')) = 6

    * Columns:
      * C_1(A') = [9, 7, 3]; max(C_1(A')) = 9
      * C_2(A') = [5, 8, 6]; max(C_2(A')) = 8
      * C_3(A') = [1, 2, 4]; max(C_3(A')) = 4

  * Note that each of this arrays are bitonic.
  * X = \{ max(R_1(A')), max(R_2(A')), max(R_3(A')) \} = \{ 9, 8, 6 \}
  * Y = \{ max(C_1(A')), max(C_2(A')), max(C_3(A')) \} = \{ 9, 8, 4 \}
  * So S(A') = (X, Y) = (\{ 9, 8, 6 \}, \{ 9, 8, 4 \})

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 100000000;
int main() {
  int n, m;
  cin >> n >> m;
  int a[252][252];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  int x[252]{0}, y[252]{0};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      x[i] = max(x[i], a[i][j]);
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      y[j] = max(y[j], a[i][j]);
    }
  }
  sort(x, x + n);
  sort(y, y + m);
  x[n] = INF;
  y[m] = INF;
  int i = 0, j = 0, k = 1;
  bool b[100000]{0};
  while (i < n && j < m) {
    if (x[i] < y[j]) {
      for (int l = m - 1; l > j; l--) {
        a[i][l] = k;
        b[k] = true;
        while (b[k]) {
          k++;
        }
      }
      b[x[i]] = true;
      a[i][j] = x[i];
      i++;
    } else if (x[i] > y[j]) {
      for (int l = n - 1; l > i; l--) {
        a[l][j] = k;
        b[k] = true;
        while (b[k]) {
          k++;
        }
      }
      b[y[j]] = true;
      a[i][j] = y[j];
      j++;
    } else {
      for (int l = m - 1; l > j; l--) {
        a[i][l] = k;
        b[k] = true;
        while (b[k]) {
          k++;
        }
      }
      for (int l = n - 1; l > i; l--) {
        a[l][j] = k;
        b[k] = true;
        while (b[k]) {
          k++;
        }
      }
      b[x[i]] = true;
      a[i][j] = x[i];
      i++;
      j++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
}

```


### Prompt

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

Consider car trips in a country where there is no friction. Cars in this country do not have engines. Once a car started to move at a speed, it keeps moving at the same speed. There are acceleration devices on some points on the road, where a car can increase or decrease its speed by 1. It can also keep its speed there. Your job in this problem is to write a program which determines the route with the shortest time to travel from a starting city to a goal city.

There are several cities in the country, and a road network connecting them. Each city has an acceleration device. As mentioned above, if a car arrives at a city at a speed v , it leaves the city at one of v - 1, v , or v + 1. The first road leaving the starting city must be run at the speed 1. Similarly, the last road arriving at the goal city must be run at the speed 1.

The starting city and the goal city are given. The problem is to find the best route which leads to the goal city going through several cities on the road network. When the car arrives at a city, it cannot immediately go back the road it used to reach the city. No U-turns are allowed. Except this constraint, one can choose any route on the road network. It is allowed to visit the same city or use the same road multiple times. The starting city and the goal city may be visited during the trip.

For each road on the network, its distance and speed limit are given. A car must run a road at a speed less than or equal to its speed limit. The time needed to run a road is the distance divided by the speed. The time needed within cities including that for acceleration or deceleration should be ignored.

Input

The input consists of multiple datasets, each in the following format.

> n  m
>  s  g
>  x 1 y 1 d 1 c 1
>  ...
>  xm ym dm cm
>

Every input item in a dataset is a non-negative integer. Input items in the same line are separated by a space.

The first line gives the size of the road network. n  is the number of cities in the network. You can assume that the number of cities is between 2 and 30, inclusive. m  is the number of roads between cities, which may be zero.

The second line gives the trip. s  is the city index of the starting city. g  is the city index of the goal city. s  is not equal to g . You can assume that all city indices in a dataset (including the above two) are between 1 and n , inclusive.

The following m  lines give the details of roads between cities. The i -th road connects two cities with city indices xi and yi , and has a distance di (1 ≤ i ≤ m ). You can assume that the distance is between 1 and 100, inclusive. The speed limit of the road is specified by ci . You can assume that the speed limit is between 1 and 30, inclusive.

No two roads connect the same pair of cities. A road never connects a city with itself. Each road can be traveled in both directions.

The last dataset is followed by a line containing two zeros (separated by a space).

Output

For each dataset in the input, one line should be output as specified below. An output line should not contain extra characters such as spaces.

If one can travel from the starting city to the goal city, the time needed for the best route (a route with the shortest time) should be printed. The answer should not have an error greater than 0.001. You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied.

If it is impossible to reach the goal city, the string "`unreachable`" should be printed. Note that all the letters of "`unreachable`" are in lowercase.

Sample Input

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

Output for the Sample Input

unreachable
4.00000
5.50000
11.25664

Example

Input

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

Output

unreachable
4.00000
5.50000
11.25664

### Response

```cpp
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;

typedef pair<pair<double,int>,pair<int,int> > P;

class road{
public:
  int to,d,c;
  road(int x,int y,int z){to = x;d = y;c = z;};
};

vector<road> G[31];

int main(){
  int n,m,s,g;
  int x,y,d,c;

  for(;;){
    scanf("%d %d",&n,&m);
    if(!n && !m)break;
    scanf("%d %d",&s,&g);

    double t[31][31][31];
    bool v[31][31][31];

    for(int i=0;i<=n;i++)G[i].clear();
    for(int i=0;i<m;i++){
      scanf("%d %d %d %d",&x,&y,&d,&c);
      G[x].push_back(road(y,d,c));
      G[y].push_back(road(x,d,c));
    }

    for(int i=0;i<=n;i++)
      for(int j=0;j<=n;j++)
	for(int k=0;k<=30;k++){
	t[i][j][k] = 1e10;
	v[i][j][k] = false;
      }

    t[s][0][0] = 0.0;
    priority_queue<P,vector<P>,greater<P> > q;
    q.push(P(pair<double,int>(0.0,s),pair<int,int>(0,0)));

    while(q.size()){
      P p = q.top();q.pop();

      double time = p.first.first;
      int now,prv,speed;
      now = p.first.second;
      prv = p.second.first;
      speed = p.second.second;

      if(v[now][prv][speed])continue;
      v[now][prv][speed] = true;

      for(int i=0;i<(int)G[now].size();i++){
	road r = G[now][i];
	if(r.to != prv){
	  for(int dif=-1;dif<=1;dif++){
	    if(speed+dif>0 &&  speed+dif<=r.c){
	      if(!v[r.to][now][speed+dif]){
		if(t[r.to][now][speed+dif] > time+(double)r.d/(speed+dif)){
		  t[r.to][now][speed+dif] = time+(double)r.d/(speed+dif);
		  q.push(P(pair<double,int>(t[r.to][now][speed+dif],r.to),pair<int,int>(now,speed+dif)));
		}
	      }
	    }
	  }
	}
      }
    }

    double ans = 1e10;
    for(int i=0;i<=n;i++)ans = min(ans,t[g][i][1]);
    if(ans==1e10)printf("unreachable\n");
    else printf("%.4lf\n",ans);
  }
}
```


### Prompt

Please formulate a CPP solution to the following problem:

Takahashi is solving quizzes. He has easily solved all but the last one.

The last quiz has three choices: 1, 2, and 3.

With his supernatural power, Takahashi has found out that the choices A and B are both wrong.

Print the correct choice for this problem.

Constraints

* Each of the numbers A and B is 1, 2, or 3.
* A and B are different.

Input

Input is given from Standard Input in the following format:

A
B

Output

Print the correct choice.

Examples

Input

3
1

Output

2

Input

1
2

Output

3

### Response

```cpp
#include <iostream>

int main(void) {
	int A, B;
	std::cin >> A >> B;
	std::cout << abs(6 - A - B);
	return 0;
}
```


### Prompt

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

You are given two tables A and B of size n × m.

We define a sorting by column as the following: we choose a column and reorder the rows of the table by the value in this column, from the rows with the smallest value to the rows with the largest. In case there are two or more rows with equal value in this column, their relative order does not change (such sorting algorithms are called stable).

You can find this behavior of sorting by column in many office software for managing spreadsheets. Petya works in one, and he has a table A opened right now. He wants to perform zero of more sortings by column to transform this table to table B.

Determine if it is possible to do so, and if yes, find a sequence of columns to sort by. Note that you do not need to minimize the number of sortings.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 1500) — the sizes of the tables.

Each of the next n lines contains m integers a_{i,j} (1 ≤ a_{i, j} ≤ n), denoting the elements of the table A.

Each of the next n lines contains m integers b_{i, j} (1 ≤ b_{i, j} ≤ n), denoting the elements of the table B.

Output

If it is not possible to transform A into B, print -1.

Otherwise, first print an integer k (0 ≤ k ≤ 5000) — the number of sortings in your solution.

Then print k integers c_1, …, c_k (1 ≤ c_i ≤ m) — the columns, by which Petya needs to perform a sorting.

We can show that if a solution exists, there is one in no more than 5000 sortings.

Examples

Input

2 2
2 2
1 2
1 2
2 2

Output

1
1

Input

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

Output

2
1 2

Input

2 2
1 1
2 1
2 1
1 1

Output

-1

Input

4 1
2
2
2
1
1
2
2
2

Output

1
1

Note

Consider the second example. After the sorting by the first column the table becomes

$$$\begin{matrix} 1&3&3\\\ 1&1&2\\\ 2&3&2. \end{matrix}$$$

After the sorting by the second column the table becomes

$$$\begin{matrix} 1&1&2\\\ 1&3&3\\\ 2&3&2, \end{matrix}$$$

and this is what we need.

In the third test any sorting does not change anything, because the columns are already sorted.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1505;
int a[N][N], b[N][N], n, m, pa[N], pb[N], num[N], ida[N], idb[N];
bool is[N][N], ned[N];
queue<int> q;
int ans[N], len;
bool cmpa(int A, int B)
{
    for (int j = 1; j <= m; j++)
        if (a[A][j] != a[B][j])
            return a[A][j] < a[B][j];
    return A < B;
}
bool cmpb(int A, int B)
{
    for (int j = 1; j <= m; j++)
        if (b[A][j] != b[B][j])
            return b[A][j] < b[B][j];
    return A < B;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> a[i][j];
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> b[i][j];
    for (int i = 1; i <= n; i++)
        pa[i] = pb[i] = i;
    sort(pa + 1, pa + 1 + n, cmpa);
    sort(pb + 1, pb + 1 + n, cmpb);
    for (int i = 1; i <= n; i++)
        ida[pa[i]] = i, idb[pb[i]] = i;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (a[pa[i]][j] != b[pb[i]][j])
            {
                cout << "-1" << '\n';
                return 0;
            }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
            if (b[i - 1][j] > b[i][j])
                num[j]++, is[i][j] = 1;
    }
    for (int i = 1; i <= n; i++)
        ned[i] = 1;
    for (int i = 1; i <= m; i++)
        if (!num[i])
            q.push(i);
    while (q.size())
    {
        int x = q.front();
        q.pop();
        ans[++len] = x;
        for (int i = 1; i <= n; i++)
            if (b[i - 1][x] < b[i][x] && ned[i])
            {
                ned[i] = 0;
                for (int j = 1; j <= m; j++)
                    if (is[i][j])
                    {
                        is[i][j] = 0;
                        num[j]--;
                        if (!num[j])
                            q.push(j);
                    }
            }
    }
    bool flag = 0;
    for (int i = 1; i <= n; i++)
        if (ned[i] && pa[idb[i - 1]] > pa[idb[i]])
            flag = 1;
    if (flag)
    {
        cout << "-1" << '\n';
        return 0;
    }
    cout << len << '\n';
    for (int i = len; i >= 1; i--)
        cout << ans[i] << ' ';
    cout << '\n';
    return 0;
}
```


### Prompt

Construct a Cpp code solution to the problem outlined:

Takahashi loves gold coins. He gains 1000 happiness points for each 500-yen coin he has and gains 5 happiness points for each 5-yen coin he has. (Yen is the currency of Japan.)

Takahashi has X yen. If he exchanges his money so that he will gain the most happiness points, how many happiness points will he earn?

(We assume that there are six kinds of coins available: 500-yen, 100-yen, 50-yen, 10-yen, 5-yen, and 1-yen coins.)

Constraints

* 0 \leq X \leq 10^9
* X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

Print the maximum number of happiness points that can be earned.

Examples

Input

1024

Output

2020

Input

0

Output

0

Input

1000000000

Output

2000000000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
  int X;
  cin>>X;
  int a=X/500,b=(X-a*500)/5;

  cout<<a*1000+b*5<<endl;
}
```


### Prompt

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

There is an array a of 2^{30} integers, indexed from 0 to 2^{30}-1. Initially, you know that 0 ≤ a_i < 2^{30} (0 ≤ i < 2^{30}), but you do not know any of the values. Your task is to process queries of two types:

  * 1 l r x: You are informed that the bitwise xor of the subarray [l, r] (ends inclusive) is equal to x. That is, a_l ⊕ a_{l+1} ⊕ … ⊕ a_{r-1} ⊕ a_r = x, where ⊕ is the bitwise xor operator. In some cases, the received update contradicts past updates. In this case, you should ignore the contradicting update (the current update).
  * 2 l r: You are asked to output the bitwise xor of the subarray [l, r] (ends inclusive). If it is still impossible to know this value, considering all past updates, then output -1.

Note that the queries are encoded. That is, you need to write an online solution.

Input

The first line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of queries.

Each of the next q lines describes a query. It contains one integer t (1 ≤ t ≤ 2) — the type of query.

The given queries will be encoded in the following way: let last be the answer to the last query of the second type that you have answered (initially, last = 0). If the last answer was -1, set last = 1.

  * If t = 1, three integers follow, l', r', and x' (0 ≤ l', r', x' < 2^{30}), meaning that you got an update. First, do the following: l = l' ⊕ last, r = r' ⊕ last, x = x' ⊕ last

and, if l > r, swap l and r.

This means you got an update that the bitwise xor of the subarray [l, r] is equal to x (notice that you need to ignore updates that contradict previous updates).

  * If t = 2, two integers follow, l' and r' (0 ≤ l', r' < 2^{30}), meaning that you got a query. First, do the following: l = l' ⊕ last, r = r' ⊕ last

and, if l > r, swap l and r.

For the given query, you need to print the bitwise xor of the subarray [l, r]. If it is impossible to know, print -1. Don't forget to change the value of last.

It is guaranteed there will be at least one query of the second type.

Output

After every query of the second type, output the bitwise xor of the given subarray or -1 if it is still impossible to know.

Examples

Input

12
2 1 2
2 1 1073741822
1 0 3 4
2 0 0
2 3 3
2 0 3
1 6 7 3
2 4 4
1 0 2 1
2 0 0
2 4 4
2 0 0

Output

-1
-1
-1
-1
5
-1
6
3
5

Input

4
1 5 5 9
1 6 6 5
1 6 5 10
2 6 5

Output

12

Note

In the first example, the real queries (without being encoded) are:

  * 12
  * 2 1 2
  * 2 0 1073741823
  * 1 1 2 5
  * 2 1 1
  * 2 2 2
  * 2 1 2
  * 1 2 3 6
  * 2 1 1
  * 1 1 3 0
  * 2 1 1
  * 2 2 2
  * 2 3 3

  * The answers for the first two queries are -1 because we don't have any such information on the array initially.
  * The first update tells us a_1 ⊕ a_2 = 5. Note that we still can't be certain about the values a_1 or a_2 independently (for example, it could be that a_1 = 1, a_2 = 4, and also a_1 = 3, a_2 = 6).
  * After we receive all three updates, we have enough information to deduce a_1, a_2, a_3 independently.

In the second example, notice that after the first two updates we already know that a_5 ⊕ a_6 = 12, so the third update is contradicting, and we ignore it.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char c;
  while ((c = getchar()) < '0' || c > '9') {
    if (c == '-') f = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
int q, ans;
map<int, int> fa, s;
int find(int x) {
  if (!fa.count(x)) return x;
  int tmp = find(fa[x]);
  s[x] ^= s[fa[x]];
  fa[x] = tmp;
  return fa[x];
}
void merge(int u, int v, int c) {
  int x = find(u), y = find(v);
  if (x == y) return;
  fa[x] = y;
  s[x] = s[u] ^ c ^ s[v];
}
signed main() {
  q = read();
  while (q--) {
    int op = read(), l = read() ^ ans, r = read() ^ ans;
    if (l > r) swap(l, r);
    r++;
    if (op == 1) {
      int x = read() ^ ans;
      merge(l, r, x);
    } else {
      if (find(l) != find(r)) {
        ans = 1;
        puts("-1");
      } else {
        ans = s[l] ^ s[r];
        printf("%d\n", ans);
      }
    }
  }
}

```


### Prompt

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

The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers.

Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than n digits.

Input

The only line of input contains one integer n (1 ≤ n ≤ 55) — the maximum length of a number that a door-plate can hold.

Output

Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than n digits.

Examples

Input

2

Output

6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int temp, n;
  cin >> n;
  temp = pow(2, n + 1) - 2;
  cout << temp;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.

Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.

Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.

Input

The first line contains two numbers n, k (1 ≤ n ≤ 100, 0 ≤ k ≤ 10 000), the number of instruments and number of days respectively.

The second line contains n integers ai (1 ≤ ai ≤ 100), representing number of days required to learn the i-th instrument.

Output

In the first line output one integer m representing the maximum number of instruments Amr can learn.

In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.

if there are multiple optimal solutions output any. It is not necessary to use all days for studying.

Examples

Input

4 10
4 3 1 2

Output

4
1 2 3 4

Input

5 6
4 3 1 1 2

Output

3
1 3 4

Input

1 3
4

Output

0

Note

In the first test Amr can learn all 4 instruments.

In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.

In the third test Amr doesn't have enough time to learn the only presented instrument.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int MAX = 100005;
vector<pair<int, int> > myvec;
int dp[110];
int main() {
  int n, k, ind = 0, cnt = 0;
  cin >> n >> k;
  for (int i = (0); i < (n); ++i) {
    int x;
    cin >> x;
    myvec.push_back(make_pair(x, ++cnt));
  }
  sort(myvec.begin(), myvec.end());
  int sum1 = 0;
  for (int i = (0); i < ((int)myvec.size()); ++i) {
    sum1 += myvec[i].first;
    dp[i] = sum1;
  }
  bool ok = true;
  while (ok) {
    if (dp[ind] <= k && dp[ind] != 0) {
      ind++;
      continue;
    } else
      ok = false;
  }
  cout << ind << '\n';
  for (int i = (0); i < (ind); ++i) {
    cout << myvec[i].second;
    if (i != ind - 1)
      cout << ' ';
    else
      cout << '\n';
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

There are n types of coins in Byteland. Conveniently, the denomination of the coin type k divides the denomination of the coin type k + 1, the denomination of the coin type 1 equals 1 tugrick. The ratio of the denominations of coin types k + 1 and k equals ak. It is known that for each x there are at most 20 coin types of denomination x.

Byteasar has bk coins of type k with him, and he needs to pay exactly m tugricks. It is known that Byteasar never has more than 3·105 coins with him. Byteasar want to know how many ways there are to pay exactly m tugricks. Two ways are different if there is an integer k such that the amount of coins of type k differs in these two ways. As all Byteland citizens, Byteasar wants to know the number of ways modulo 109 + 7.

Input

The first line contains single integer n (1 ≤ n ≤ 3·105) — the number of coin types.

The second line contains n - 1 integers a1, a2, ..., an - 1 (1 ≤ ak ≤ 109) — the ratios between the coin types denominations. It is guaranteed that for each x there are at most 20 coin types of denomination x.

The third line contains n non-negative integers b1, b2, ..., bn — the number of coins of each type Byteasar has. It is guaranteed that the sum of these integers doesn't exceed 3·105.

The fourth line contains single integer m (0 ≤ m < 1010000) — the amount in tugricks Byteasar needs to pay.

Output

Print single integer — the number of ways to pay exactly m tugricks modulo 109 + 7.

Examples

Input

1

4
2

Output

1

Input

2
1
4 4
2

Output

3

Input

3
3 3
10 10 10
17

Output

6

Note

In the first example Byteasar has 4 coins of denomination 1, and he has to pay 2 tugricks. There is only one way.

In the second example Byteasar has 4 coins of each of two different types of denomination 1, he has to pay 2 tugricks. There are 3 ways: pay one coin of the first type and one coin of the other, pay two coins of the first type, and pay two coins of the second type.

In the third example the denominations are equal to 1, 3, 9.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 300300, P = 1000000007;
int i, j, k, n, m, ch, An, ma;
long long x;
int a[N], b[N], f[N], g[N], A[N];
char s[N];
void R(int &x) {
  x = 0;
  ch = getchar();
  while (ch < '0' || '9' < ch) ch = getchar();
  while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
}
int main() {
  R(n);
  a[1] = 1;
  for (i = 2; i <= n; i++) R(a[i]);
  for (i = 1; i <= n; i++) R(b[i]);
  scanf("%s", s + 1);
  m = strlen(s + 1);
  for (i = 1; i <= m; i++) A[i] = s[m - i + 1] - '0';
  for (i = 1; i <= m; i += 4)
    A[++An] = A[i] + A[i + 1] * 10 + A[i + 2] * 100 + A[i + 3] * 1000;
  for (i = An + 1; i <= m; i++) A[i] = 0;
  f[0] = 1;
  for (i = 1; i <= n; i++) {
    if (a[i] != 1) {
      x = 0;
      for (j = An; j; j--) {
        x = x * 10000 + A[j];
        A[j] = x / a[i];
        x %= a[i];
      }
      while (An > 1 && !A[An]) An--;
      for (j = 0; j <= ma; j++) {
        if (j + x > ma)
          f[j] = 0;
        else
          f[j] = f[j + x];
      }
      while (ma && !f[ma]) ma--;
      for (j = 0; j * a[i] <= ma; j++) f[j] = f[j * a[i]];
      for (; j <= ma; j++) f[j] = 0;
      while (ma && !f[ma]) ma--;
    }
    ma += b[i];
    g[0] = f[0];
    for (j = 1; j <= ma; j++) g[j] = (g[j - 1] + f[j]) % P;
    for (j = 0; j <= ma; j++) {
      f[j] = g[j];
      if (j > b[i]) f[j] = (f[j] + P - g[j - b[i] - 1]) % P;
    }
  }
  if (An > 2) return puts("0"), 0;
  k = A[2] * 10000 + A[1];
  if (k > ma) return puts("0"), 0;
  printf("%d\n", f[k]);
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.

Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 ≤ x, y ≤ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.

Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.

Input

The first line contains a single integer n (1 ≤ n ≤ 109) — Polycarpus's number.

Output

Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.

Examples

Input

10

Output

10

Input

123

Output

113

Note

In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.

In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string s;
long long ans, n;
int a[20];
void solve(int t) {
  int temp = t;
  for (int k = 0; k < n; k++) {
    a[k] = temp % 2;
    temp /= 2;
  }
  for (int i = 1; i < 9; i++) {
    for (int j = i + 1; j <= 9; j++) {
      bool flag = 1;
      for (int k = 0; k < n; k++) {
        int l = a[n - k - 1];
        if (l == 0)
          l = i;
        else
          l = j;
        if (s[k] < l + '0') {
          flag = 0;
          k = n;
        } else if (l + '0' < s[k])
          k = n;
      }
      if (flag) {
        ans++;
      }
    }
  }
  if (a[n - 1]) {
    for (int i = 1; i <= 9; i++) {
      bool flag = 1;
      for (int k = 0; k < n; k++) {
        int l = a[n - k - 1];
        if (l) l = i;
        if (s[k] < l + '0') {
          flag = 0;
          k = n;
        } else if (l + '0' < s[k])
          k = n;
      }
      if (flag) ans++;
    }
  }
}
void solve2() {
  for (int i = 1; i <= 9; i++) {
    bool flag = 1;
    for (int j = 0; j < n; j++) {
      if (s[j] - '0' > i)
        j = n;
      else if (s[j] - '0' < i) {
        flag = 0;
        j = n;
      }
    }
    if (flag)
      ans++;
    else
      return;
  }
}
int main() {
  cin >> s;
  n = s.size();
  int p = pow(2, n) - 1;
  for (int i = 1; i < p; i++) {
    solve(i);
  }
  solve2();
  if (n > 1) ans += 9;
  for (int i = 2; i < n; i++) {
    ans += (pow(2, i) - 2) * 36;
    ans += (pow(2, i - 1) - 1) * 9;
    ans += 9;
  }
  cout << ans;
}

```


### Prompt

Generate a cpp solution to the following problem:

Berland has n cities, some of them are connected by bidirectional roads. For each road we know whether it is asphalted or not.

The King of Berland Valera II wants to asphalt all roads of Berland, for that he gathered a group of workers. Every day Valera chooses exactly one city and orders the crew to asphalt all roads that come from the city. The valiant crew fulfilled the King's order in a day, then workers went home.

Unfortunately, not everything is as great as Valera II would like. The main part of the group were gastarbeiters — illegal immigrants who are enthusiastic but not exactly good at understanding orders in Berlandian. Therefore, having received orders to asphalt the roads coming from some of the city, the group asphalted all non-asphalted roads coming from the city, and vice versa, took the asphalt from the roads that had it.

Upon learning of this progress, Valera II was very upset, but since it was too late to change anything, he asked you to make a program that determines whether you can in some way asphalt Berlandian roads in at most n days. Help the king.

Input

The first line contains two space-separated integers n, m <image> — the number of cities and roads in Berland, correspondingly. Next m lines contain the descriptions of roads in Berland: the i-th line contains three space-separated integers ai, bi, ci (1 ≤ ai, bi ≤ n; ai ≠ bi; 0 ≤ ci ≤ 1). The first two integers (ai, bi) are indexes of the cities that are connected by the i-th road, the third integer (ci) equals 1, if the road was initially asphalted, and 0 otherwise.

Consider the cities in Berland indexed from 1 to n, and the roads indexed from 1 to m. It is guaranteed that between two Berlandian cities there is not more than one road.

Output

In the first line print a single integer x (0 ≤ x ≤ n) — the number of days needed to asphalt all roads. In the second line print x space-separated integers — the indexes of the cities to send the workers to. Print the cities in the order, in which Valera send the workers to asphalt roads. If there are multiple solutions, print any of them.

If there's no way to asphalt all roads, print "Impossible" (without the quotes).

Examples

Input

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

Output

4
3 2 1 3

Input

3 3
1 2 0
2 3 0
3 1 0

Output

Impossible

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 405;
vector<int> g[MAXN];
vector<int> gr[MAXN];
vector<int> g2[MAXN];
int n, m;
inline int neg(int u) { return ((u <= n) ? u + n : u - n); }
bool mk[MAXN];
int order[MAXN], posord;
void dfs1(int u, vector<int> *g) {
  if (mk[u]) {
    return;
  }
  mk[u] = true;
  for (int i = 0; i < (int)(g[u].size()); ++i) {
    dfs1(g[u][i], g);
  }
  order[posord--] = u;
}
int SCC[MAXN], sccnum;
void dfs2(int u, int root) {
  if (mk[u]) {
    return;
  }
  mk[u] = true;
  SCC[u] = SCC[root];
  for (int i = 0; i < (int)(gr[u].size()); ++i) {
    dfs2(g[u][i], root);
  }
}
int color[MAXN];
int SCCORD[MAXN];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < (int)(m); ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    if ((c == 1)) {
      g[u].push_back(v);
      g[v].push_back(u);
      g[neg(u)].push_back(neg(v));
      g[neg(v)].push_back(neg(u));
    } else {
      g[u].push_back(neg(v));
      g[neg(v)].push_back(u);
      g[neg(u)].push_back(v);
      g[v].push_back(neg(u));
    }
  }
  for (int i = 1; i <= (int)(2 * n); ++i) {
    int u;
    u = i;
    for (int i = 0; i < (int)(g[u].size()); ++i) {
      int v;
      v = g[u][i];
      gr[v].push_back(u);
    }
  }
  posord = 2 * n;
  for (int i = 1; i <= (int)(2 * n); ++i) {
    int u;
    u = i;
    if (!mk[u]) {
      dfs1(u, g);
    }
  }
  fill(mk, mk + 2 * n + 1, false);
  sccnum = 0;
  for (int i = 1; i <= (int)(2 * n); ++i) {
    int u;
    u = order[i];
    if (!mk[u]) {
      sccnum++;
      SCC[u] = sccnum;
      dfs2(u, u);
    }
  }
  for (int u = 1; u <= (int)(n); ++u) {
    cerr << SCC[u] << ' ';
  }
  cerr << '\n';
  for (int u = 1; u <= (int)(n); ++u) {
    cerr << SCC[neg(u)] << ' ';
  }
  cerr << '\n';
  for (int u = 1; u <= (int)(n); ++u) {
    if ((SCC[u] == SCC[neg(u)])) {
      cout << "Impossible\n";
      return 0;
    }
  }
  for (int u = 1; u <= (int)(2 * n); ++u) {
    for (int i = 0; i < (int)(g[u].size()); ++i) {
      int v;
      v = g[u][i];
      if (!(SCC[u] == SCC[v])) {
        g2[SCC[u]].push_back(SCC[v]);
      }
    }
  }
  fill(mk, mk + sccnum + 1, false);
  posord = sccnum;
  for (int u = 1; u <= (int)(sccnum); ++u) {
    if (!mk[u]) {
      dfs1(u, g2);
    }
  }
  for (int i = 1; i <= (int)(sccnum); ++i) {
    SCCORD[order[i]] = i;
  }
  vector<int> sol;
  for (int u = 1; u <= (int)(n); ++u) {
    if (SCCORD[SCC[u]] > SCCORD[SCC[neg(u)]]) {
      sol.push_back(u);
    }
  }
  cout << sol.size() << '\n';
  for (int i = 0; i < (int)(sol.size()); ++i) {
    if (i > 0) {
      cout << ' ';
    }
    cout << sol[i];
  }
  if (sol.size() > 0) {
    cout << '\n';
  }
}

```


### Prompt

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

Vasya has an array a_1, a_2, ..., a_n.

You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 ≤ t_i ≤ 1, 1 ≤ l_i < r_i ≤ n) and it means:

  * if t_i=1 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is sorted in non-decreasing order;
  * if t_i=0 then subbarray a_{l_i}, a_{l_i + 1}, ..., a_{r_i} is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter.

For example if a = [2, 1, 1, 3, 2] then he could give you three facts: t_1=1, l_1=2, r_1=4 (the subarray [a_2, a_3, a_4] = [1, 1, 3] is sorted), t_2=0, l_2=4, r_2=5 (the subarray [a_4, a_5] = [3, 2] is not sorted), and t_3=0, l_3=3, r_3=5 (the subarray [a_3, a_5] = [1, 3, 2] is not sorted).

You don't know the array a. Find any array which satisfies all the given facts.

Input

The first line contains two integers n and m (2 ≤ n ≤ 1000, 1 ≤ m ≤ 1000).

Each of the next m lines contains three integers t_i, l_i and r_i (0 ≤ t_i ≤ 1, 1 ≤ l_i < r_i ≤ n).

If t_i = 1 then subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is sorted. Otherwise (if t_i = 0) subbarray a_{l_i}, a_{l_i + 1}, ... , a_{r_i} is not sorted.

Output

If there is no array that satisfies these facts in only line print NO (in any letter case).

If there is a solution, print YES (in any letter case). In second line print n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them.

Examples

Input

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

Output

YES
1 2 2 3 5 4 4

Input

4 2
1 1 4
0 2 3

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, m;
  vector<int> t, l, r, comp;
  int i, j;
  int num = 10000;
  bool flag;
  cin >> n >> m;
  t.resize(m + 1);
  l.resize(m + 1);
  r.resize(m + 1);
  comp.resize(n + 1, 0);
  for (i = 0; i < m; i++) {
    cin >> t[i] >> l[i] >> r[i];
  }
  for (i = 0; i < m; i++) {
    if (t[i]) {
      for (j = l[i]; j < r[i]; j++) {
        comp[j] = 1;
      }
    }
  }
  for (i = 0; i < m; i++) {
    if (!t[i]) {
      flag = false;
      for (j = l[i]; j < r[i]; j++) {
        if (!comp[j]) {
          flag = true;
        }
      }
      if (!flag) {
        cout << "NO\n";
        return 0;
      }
    }
  }
  cout << "YES\n";
  for (i = 1; i <= n; i++) {
    cout << num << " ";
    if (comp[i]) {
      num++;
    } else {
      num--;
    }
  }
  cout << endl;
  return 0;
}

```


### Prompt

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

Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!

A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system.

There are n booking requests received by now. Each request is characterized by two numbers: ci and pi — the size of the group of visitors who will come via this request and the total sum of money they will spend in the restaurant, correspondingly.

We know that for each request, all ci people want to sit at the same table and are going to spend the whole evening in the restaurant, from the opening moment at 18:00 to the closing moment.

Unfortunately, there only are k tables in the restaurant. For each table, we know ri — the maximum number of people who can sit at it. A table can have only people from the same group sitting at it. If you cannot find a large enough table for the whole group, then all visitors leave and naturally, pay nothing.

Your task is: given the tables and the requests, decide which requests to accept and which requests to decline so that the money paid by the happy and full visitors was maximum.

Input

The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of requests from visitors. Then n lines follow. Each line contains two integers: ci, pi (1 ≤ ci, pi ≤ 1000) — the size of the group of visitors who will come by the i-th request and the total sum of money they will pay when they visit the restaurant, correspondingly.

The next line contains integer k (1 ≤ k ≤ 1000) — the number of tables in the restaurant. The last line contains k space-separated integers: r1, r2, ..., rk (1 ≤ ri ≤ 1000) — the maximum number of people that can sit at each table.

Output

In the first line print two integers: m, s — the number of accepted requests and the total money you get from these requests, correspondingly.

Then print m lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this request. The requests and the tables are consecutively numbered starting from 1 in the order in which they are given in the input.

If there are multiple optimal answers, print any of them.

Examples

Input

3
10 50
2 100
5 30
3
4 6 9

Output

2 130
2 1
3 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e6 + 9;
const long long int mod = 1e9 + 7;
long long int powerk(long long int x, long long int y);
vector<pair<pair<long long int, long long int>, long long int>> v;
vector<pair<long long int, long long int>> ans;
set<pair<long long int, long long int>> st;
long long int a[N];
bool cmp(pair<pair<long long int, long long int>, long long int> a,
         pair<pair<long long int, long long int>, long long int> b) {
  if (a.first.first > b.first.first)
    return 1;
  else
    return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    long long int l, r;
    cin >> l >> r;
    v.push_back({{r, l}, i});
  }
  long long int k;
  cin >> k;
  for (int i = 1; i <= k; ++i) {
    long long int l;
    cin >> l;
    st.insert({l, i});
  }
  long long int cnt = 0, sum = 0;
  sort(v.begin(), v.end(), cmp);
  for (auto it : v) {
    auto itt = st.lower_bound({it.first.second, 0});
    if (itt != st.end()) {
      cnt++;
      sum += it.first.first;
      auto iit = *itt;
      ans.push_back({it.second, iit.second});
      st.erase(iit);
    }
  }
  sort(ans.begin(), ans.end());
  cout << cnt << " " << sum << '\n';
  for (auto it : ans) {
    cout << it.first << " " << it.second << '\n';
  }
}
long long int powerk(long long int x, long long int y) {
  if (y == 0) return 1;
  if (y == 1) return x % mod;
  if (y & 1)
    return ((powerk((x * x) % mod, y / 2) % mod) * x) % mod;
  else
    return powerk((x * x) % mod, y / 2) % mod;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Phoenix is picking berries in his backyard. There are n shrubs, and each shrub has a_i red berries and b_i blue berries.

Each basket can contain k berries. But, Phoenix has decided that each basket may only contain berries from the same shrub or berries of the same color (red or blue). In other words, all berries in a basket must be from the same shrub or/and have the same color.

For example, if there are two shrubs with 5 red and 2 blue berries in the first shrub and 2 red and 1 blue berries in the second shrub then Phoenix can fill 2 baskets of capacity 4 completely:

  * the first basket will contain 3 red and 1 blue berries from the first shrub;
  * the second basket will contain the 2 remaining red berries from the first shrub and 2 red berries from the second shrub.

Help Phoenix determine the maximum number of baskets he can fill completely!

Input

The first line contains two integers n and k ( 1≤ n, k ≤ 500) — the number of shrubs and the basket capacity, respectively.

The i-th of the next n lines contain two integers a_i and b_i (0 ≤ a_i, b_i ≤ 10^9) — the number of red and blue berries in the i-th shrub, respectively.

Output

Output one integer — the maximum number of baskets that Phoenix can fill completely.

Examples

Input

2 4
5 2
2 1

Output

2

Input

1 5
2 3

Output

1

Input

2 5
2 1
1 3

Output

0

Input

1 2
1000000000 1

Output

500000000

Note

The first example is described above.

In the second example, Phoenix can fill one basket fully using all the berries from the first (and only) shrub.

In the third example, Phoenix cannot fill any basket completely because there are less than 5 berries in each shrub, less than 5 total red berries, and less than 5 total blue berries.

In the fourth example, Phoenix can put all the red berries into baskets, leaving an extra blue berry behind.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long N, K, A[503], B[503], suma, sumb, numa, numb;
int main() {
  cin >> N >> K;
  for (int i = 1; i <= N; ++i) {
    cin >> A[i] >> B[i];
    numa += (suma + A[i]) / K + (sumb + B[i]) / K;
    suma = (suma + A[i]) % K;
    sumb = (sumb + B[i]) % K;
  }
  if (suma + sumb >= K) {
    static int dp[503][503];
    dp[0][suma] = 1;
    for (int j = 1; j <= N; ++j) {
      memcpy(dp[j], dp[j - 1], sizeof(dp[j]));
      for (int k = 0; k <= K; ++k)
        if (dp[j - 1][k])
          for (int l = 1; l <= A[j] && l < K; ++l)
            if (K - l <= B[j]) dp[j][(k - l + K) % K] = 1;
    }
    for (int j = 0; j <= suma + sumb - K; ++j)
      if (dp[N][j]) {
        ++numa;
        break;
      }
  }
  cout << numa;
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

One day Bob got a letter in an envelope. Bob knows that when Berland's post officers send a letter directly from city «A» to city «B», they stamp it with «A B», or «B A». Unfortunately, often it is impossible to send a letter directly from the city of the sender to the city of the receiver, that's why the letter is sent via some intermediate cities. Post officers never send a letter in such a way that the route of this letter contains some city more than once. Bob is sure that the post officers stamp the letters accurately.

There are n stamps on the envelope of Bob's letter. He understands that the possible routes of this letter are only two. But the stamps are numerous, and Bob can't determine himself none of these routes. That's why he asks you to help him. Find one of the possible routes of the letter.

Input

The first line contains integer n (1 ≤ n ≤ 105) — amount of mail stamps on the envelope. Then there follow n lines with two integers each — description of the stamps. Each stamp is described with indexes of the cities between which a letter is sent. The indexes of cities are integers from 1 to 109. Indexes of all the cities are different. Every time the letter is sent from one city to another, exactly one stamp is put on the envelope. It is guaranteed that the given stamps correspond to some valid route from some city to some other city.

Output

Output n + 1 numbers — indexes of cities in one of the two possible routes of the letter.

Examples

Input

2
1 100
100 2

Output

2 100 1

Input

3
3 1
100 2
3 2

Output

100 2 3 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    map<int, int> ma;
    map<int, int> mb;
    set<int> s;
    set<int>::iterator ps;
    int a, b;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &a, &b);
      s.insert(a);
      s.insert(b);
      if (ma[a])
        mb[a] = b;
      else
        ma[a] = b;
      if (ma[b])
        mb[b] = a;
      else
        ma[b] = a;
    }
    int sta;
    for (ps = s.begin(); ps != s.end(); ps++) {
      if (mb[*ps] == 0) {
        sta = *ps;
        break;
      }
    }
    printf("%d ", sta);
    int pre = sta;
    int next = ma[sta];
    if (next == 0) {
      printf("\n");
      continue;
    }
    while (1) {
      printf("%d ", next);
      if (ma[next] == pre) {
        pre = next;
        next = mb[next];
        if (next == 0) break;
      } else {
        pre = next;
        next = ma[next];
        if (next == 0) break;
      }
    }
    printf("\n");
  }
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i.

There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N:

* If the frog is currently on Stone i, jump to one of the following: Stone i + 1, i + 2, \ldots, i + K. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.

Find the minimum possible total cost incurred before the frog reaches Stone N.

Constraints

* All values in input are integers.
* 2 \leq N \leq 10^5
* 1 \leq K \leq 100
* 1 \leq h_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N K
h_1 h_2 \ldots h_N

Output

Print the minimum possible total cost incurred.

Examples

Input

5 3
10 30 40 50 20

Output

30

Input

3 1
10 20 10

Output

20

Input

2 100
10 10

Output

0

Input

10 4
40 10 20 70 80 10 20 70 80 60

Output

40

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N,K,dp[100001],h[100001];
    fill(dp,dp+100001,1e9);
    dp[0]=0;
    cin>>N>>K;
    for(int i=0;i<N;i++)cin>>h[i];
    for(int i=0;i<N;i++)for(int k=1;k<=K;k++)if(i+k<N)dp[i+k]=min(abs(h[i+k]-h[i])+dp[i],dp[i+k]);
    cout<<dp[N-1]<<endl;
}

```


### Prompt

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

Vladimir wants to modernize partitions in his office. To make the office more comfortable he decided to remove a partition and plant several bamboos in a row. He thinks it would be nice if there are n bamboos in a row, and the i-th from the left is ai meters high.

Vladimir has just planted n bamboos in a row, each of which has height 0 meters right now, but they grow 1 meter each day. In order to make the partition nice Vladimir can cut each bamboo once at any height (no greater that the height of the bamboo), and then the bamboo will stop growing.

Vladimir wants to check the bamboos each d days (i.e. d days after he planted, then after 2d days and so on), and cut the bamboos that reached the required height. Vladimir wants the total length of bamboo parts he will cut off to be no greater than k meters.

What is the maximum value d he can choose so that he can achieve what he wants without cutting off more than k meters of bamboo?

Input

The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1011) — the number of bamboos and the maximum total length of cut parts, in meters.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the required heights of bamboos, in meters.

Output

Print a single integer — the maximum value of d such that Vladimir can reach his goal.

Examples

Input

3 4
1 3 5

Output

3

Input

3 40
10 30 50

Output

32

Note

In the first example Vladimir can check bamboos each 3 days. Then he will cut the first and the second bamboos after 3 days, and the third bamboo after 6 days. The total length of cut parts is 2 + 0 + 1 = 3 meters.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, k, ans, sum, a[101];
void check(long long t) {
  long long ret = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] % t) ret += (a[i] / t + 1) * t - a[i];
  }
  if (ret <= k) ans = max(ans, t);
}
int main() {
  scanf("%lld%lld", &n, &k), sum += k;
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]), sum += a[i];
  }
  long long p = (long long)sqrt(sum);
  for (long long i = 1; i <= p; ++i) {
    if (sum / i > ans) check(sum / i);
    if (i > ans) check(i);
  }
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Alice and Bob are decorating a Christmas Tree.

Alice wants only 3 types of ornaments to be used on the Christmas Tree: yellow, blue and red. They have y yellow ornaments, b blue ornaments and r red ornaments.

In Bob's opinion, a Christmas Tree will be beautiful if:

  * the number of blue ornaments used is greater by exactly 1 than the number of yellow ornaments, and
  * the number of red ornaments used is greater by exactly 1 than the number of blue ornaments.

That is, if they have 8 yellow ornaments, 13 blue ornaments and 9 red ornaments, we can choose 4 yellow, 5 blue and 6 red ornaments (5=4+1 and 6=5+1).

Alice wants to choose as many ornaments as possible, but she also wants the Christmas Tree to be beautiful according to Bob's opinion.

In the example two paragraphs above, we would choose 7 yellow, 8 blue and 9 red ornaments. If we do it, we will use 7+8+9=24 ornaments. That is the maximum number.

Since Alice and Bob are busy with preparing food to the New Year's Eve, they are asking you to find out the maximum number of ornaments that can be used in their beautiful Christmas Tree!

It is guaranteed that it is possible to choose at least 6 (1+2+3=6) ornaments.

Input

The only line contains three integers y, b, r (1 ≤ y ≤ 100, 2 ≤ b ≤ 100, 3 ≤ r ≤ 100) — the number of yellow, blue and red ornaments.

It is guaranteed that it is possible to choose at least 6 (1+2+3=6) ornaments.

Output

Print one number — the maximum number of ornaments that can be used.

Examples

Input

8 13 9

Output

24

Input

13 3 6

Output

9

Note

In the first example, the answer is 7+8+9=24.

In the second example, the answer is 2+3+4=9.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int a, b, c;
  cin >> a >> b >> c;
  for (int(i) = (100); (i) >= (1); --(i)) {
    if (a >= i && b >= i + 1 && c >= i + 2) {
      cout << 3 * i + 3 << endl;
      return 0;
    }
  }
  return 0;
}

```


### Prompt

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

Ichiro likes baseball and has decided to write a program which simulates baseball.

The program reads events in an inning and prints score in that inning. There are only three events as follows:

Single hit

* put a runner on the first base.
* the runner in the first base advances to the second base and the runner in the second base advances to the third base.
* the runner in the third base advances to the home base (and go out of base) and a point is added to the score.

Home run

* all the runners on base advance to the home base.
* points are added to the score by an amount equal to the number of the runners plus one.

Out

* The number of outs is increased by 1.
* The runners and the score remain stationary.
* The inning ends with three-out.

Ichiro decided to represent these events using "HIT", "HOMERUN" and "OUT", respectively.

Write a program which reads events in an inning and prints score in that inning. You can assume that the number of events is less than or equal to 100.

Input

The input consists of several datasets. In the first line, the number of datasets n is given. Each dataset consists of a list of events (strings) in an inning.

Output

For each dataset, prints the score in the corresponding inning.

Example

Input

2
HIT
OUT
HOMERUN
HIT
HIT
HOMERUN
HIT
OUT
HIT
HIT
HIT
HIT
OUT
HIT
HIT
OUT
HIT
OUT
OUT

Output

7
0

### Response

```cpp
#include<iostream>
#include<string>
using namespace std;
int main(void){
	int n;

	cin >> n;
	while(n-->0){
		int hits = 0;
		int inningScore = 0;
		int outNum = 0;
		while( outNum < 3 ){
			string s;
			cin >> s;
			if( s.compare("HIT") == 0 ){
				hits++;
				if( hits == 4 ){
					inningScore++;
					hits = 3;
				}
			}else if( s.compare("HOMERUN") == 0 ){
				inningScore += hits + 1;
				hits = 0;
			}else if( s.compare("OUT") == 0 ){
				outNum++;
				/* inning end */
				if( outNum == 3 ) break;
			}
		}
		cout << inningScore << '\n';
	}
	return 0;
}
```


### Prompt

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

Example

Input

2
1 2

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k,n,p,i,j,s,m=-1;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  for(i=0;i<n-1;i++){
    for(j=i+1;j<n;j++){
      s=a[i]*a[j];
      k=s%10+1;
      while(s){
        p=s%10;
        if(p!=k-1)goto L;
        s/=10;
        k=p;
      }
      m=max(m,a[i]*a[j]);L:;
    }
  }
  cout<<m<<endl;
}
```


### Prompt

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

Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:

for i = 1 to A.length-1
key = A[i]
/* insert A[i] into the sorted sequence A[0,...,j-1] */
j = i - 1
while j >= 0 and A[j] > key
A[j+1] = A[j]
j--
A[j+1] = key

Note that, indices for array elements are based on 0-origin.

To illustrate the algorithms, your program should trace intermediate result for each step.

Hint

Template in C

Constraints

1 ≤ N ≤ 100

Input

The first line of the input includes an integer N, the number of elements in the sequence.

In the second line, N elements of the sequence are given separated by a single space.

Output

The output consists of N lines. Please output the intermediate sequence in a line for each step. Elements of the sequence should be separated by single space.

Examples

Input

6
5 2 4 6 1 3

Output

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

Input

3
1 2 3

Output

1 2 3
1 2 3
1 2 3

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int n,a[105];
void pr()
{
	int i;
	for(i=1;i<=n;i++)
	{
		if(i>1)printf(" ");
		printf("%d",a[i]);
	}
	printf("\n");
}
void sor()
{
	int i,j,k;
	for(i=2;i<=n;i++)
	{
		k=a[i];
		j=i-1;
		while(j>=1&&a[j]>k)
		{
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=k;
		pr();
	}
}
int main()
{
	int i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	scanf("%d",&a[i]);
	pr();
	sor();
	return 0;
}

```


### Prompt

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

Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once.

You are given the sequence A and q questions where each question contains Mi.

Notes

You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions:

solve(0, M)
solve(1, M-{sum created from elements before 1st element})
solve(2, M-{sum created from elements before 2nd element})
...

The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations.

For example, the following figure shows that 8 can be made by A[0] + A[2].

<image>

Constraints

* n ≤ 20
* q ≤ 200
* 1 ≤ elements in A ≤ 2000
* 1 ≤ Mi ≤ 2000

Input

In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given.

Output

For each question Mi, print yes or no.

Example

Input

5
1 5 7 10 21
8
2 4 17 8 22 21 100 35

Output

no
no
yes
yes
yes
yes
no
no

### Response

```cpp
#include<iostream>
using namespace std;
int n,a[100];

int slove(int i,int m);
int main()
{
	int i,qn,q;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	cin >> qn;
	for(i=0;i<qn;i++){
		cin >>q;
		if ( slove(0,q)){
			cout << "yes" << endl;
		}else{
			cout << "no" << endl;
		}
	}
}

int slove(int i,int m)
{
	int res;
	if (m==0) return 1;
	if (i>=n) return 0;
	res =slove(i+1,m) || slove(i+1,m-a[i]);
	return res;
}
```


### Prompt

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

I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below.

<image>
Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels)

Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.

Input

The input is given in the following format.

x y

A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).

Output

Output the number of points where the wire intersects with the panel boundaries.

Examples

Input

4 4

Output

5

Input

4 6

Output

9

### Response

```cpp
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
ll _gcd(ll x, ll y){
    while(1){
        if(x%y == 0)return y;
        else{
            ll z = x%y;
            x = y;
            y = z;
        }
    }
}
//ミョ(-ω- ?)
int main() {
    ll x,y;
    cin >> x >> y;
    cout << x + y - _gcd(x,y)+1 << endl;
    return 0;
}

```


### Prompt

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

A stowaway and a controller play the following game.

The train is represented by n wagons which are numbered with positive integers from 1 to n from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions — moving or idle. Every minute the players move.

The controller's move is as follows. The controller has the movement direction — to the train's head or to its tail. During a move the controller moves to the neighbouring wagon correspondingly to its movement direction. If at the end of his move the controller enters the 1-st or the n-th wagon, that he changes the direction of his movement into the other one. In other words, the controller cyclically goes from the train's head to its tail and back again during all the time of a game, shifting during each move by one wagon. Note, that the controller always have exactly one possible move.

The stowaway's move depends from the state of the train. If the train is moving, then the stowaway can shift to one of neighbouring wagons or he can stay where he is without moving. If the train is at a station and is idle, then the stowaway leaves the train (i.e. he is now not present in any train wagon) and then, if it is not the terminal train station, he enters the train again into any of n wagons (not necessarily into the one he's just left and not necessarily into the neighbouring one). If the train is idle for several minutes then each such minute the stowaway leaves the train and enters it back.

Let's determine the order of the players' moves. If at the given minute the train is moving, then first the stowaway moves and then the controller does. If at this minute the train is idle, then first the stowaway leaves the train, then the controller moves and then the stowaway enters the train.

If at some point in time the stowaway and the controller happen to be in one wagon, then the controller wins: he makes the stowaway pay fine. If after a while the stowaway reaches the terminal train station, then the stowaway wins: he simply leaves the station during his move and never returns there again.

At any moment of time the players know each other's positions. The players play in the optimal way. Specifically, if the controller wins, then the stowaway plays so as to lose as late as possible. As all the possible moves for the controller are determined uniquely, then he is considered to play optimally always. Determine the winner.

Input

The first line contains three integers n, m and k. They represent the number of wagons in the train, the stowaway's and the controller's initial positions correspondingly (2 ≤ n ≤ 50, 1 ≤ m, k ≤ n, m ≠ k).

The second line contains the direction in which a controller moves. "to head" means that the controller moves to the train's head and "to tail" means that the controller moves to its tail. It is guaranteed that in the direction in which the controller is moving, there is at least one wagon. Wagon 1 is the head, and wagon n is the tail.

The third line has the length from 1 to 200 and consists of symbols "0" and "1". The i-th symbol contains information about the train's state at the i-th minute of time. "0" means that in this very minute the train moves and "1" means that the train in this very minute stands idle. The last symbol of the third line is always "1" — that's the terminal train station.

Output

If the stowaway wins, print "Stowaway" without quotes. Otherwise, print "Controller" again without quotes, then, separated by a space, print the number of a minute, at which the stowaway will be caught.

Examples

Input

5 3 2
to head
0001001

Output

Stowaway

Input

3 2 1
to tail
0001

Output

Controller 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e9;
const long long NN = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
template <typename T, typename T1>
T maxn(T &a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T minn(T &a, T1 b) {
  if (b < a) a = b;
  return a;
}
void solve() {
  long long int n, k, m;
  cin >> n >> k >> m;
  m--;
  k--;
  string to, dir;
  cin >> to >> dir;
  long long int chng = 0;
  if (dir == "head")
    chng = -1;
  else
    chng = 1;
  string second;
  cin >> second;
  for (long long int(i) = 0; (i) < ((long long int)second.size()); (i)++) {
    if (second[i] == '0') {
      if (m + chng >= n || m + chng < 0) chng *= -1;
      m += chng;
      if (m == k) {
        if (k + chng < n && k + chng >= 0) k += chng;
      }
      if (m == k) {
        cout << "Controller ";
        cout << i + 1;
        return;
      }
    } else {
      if (i == (long long int)second.size() - 1) {
        cout << "Stowaway";
        return;
      }
      if (m + chng >= n || m + chng < 0) chng *= -1;
      if (chng > 0) {
        k = 0;
      } else {
        k = n - 1;
      }
      m += chng;
    }
  }
  cout << "Stowaway";
}
signed main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int testcase = 1;
  while (testcase--) solve();
  return 0;
}

```


### Prompt

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

You are given an array a consisting of n integers.

In one move, you can choose some index i (1 ≤ i ≤ n - 2) and shift the segment [a_i, a_{i + 1}, a_{i + 2}] cyclically to the right (i.e. replace the segment [a_i, a_{i + 1}, a_{i + 2}] with [a_{i + 2}, a_i, a_{i + 1}]).

Your task is to sort the initial array by no more than n^2 such operations or say that it is impossible to do that.

You have to answer t independent test cases.

Input

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

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

It is guaranteed that the sum of n does not exceed 500.

Output

For each test case, print the answer: -1 on the only line if it is impossible to sort the given array using operations described in the problem statement, or the number of operations ans on the first line and ans integers idx_1, idx_2, ..., idx_{ans} (1 ≤ idx_i ≤ n - 2), where idx_i is the index of left border of the segment for the i-th operation. You should print indices in order of performing operations.

Example

Input

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

Output

0

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void culc(int& a, int& b, int& c) { swap(b, c), swap(a, b); }
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> ans;
  for (int i = 0; i < n - 2; i++) {
    auto it = min_element(a.begin() + i, a.end()) - a.begin();
    if (i % 2 != it % 2) {
      if (it < n - 1) {
        culc(a[it - 1], a[it], a[it + 1]);
        ans.push_back(it - 1);
        it++;
      } else {
        culc(a[it - 2], a[it - 1], a[it]);
        culc(a[it - 2], a[it - 1], a[it]);
        ans.push_back(it - 2);
        ans.push_back(it - 2);
        it--;
      }
    }
    while (it != i) {
      culc(a[it - 2], a[it - 1], a[it]);
      ans.push_back(it - 2);
      it -= 2;
    }
  }
  bool flag = true;
  if (a[n - 1] < a[n - 2]) {
    flag = false;
    for (int i = n - 3; i >= 0; i--) {
      culc(a[i], a[i + 1], a[i + 2]);
      ans.push_back(i);
      if (a[i] <= a[i + 1]) {
        flag = true;
        break;
      }
    }
  }
  if (!flag) {
    cout << -1 << endl;
    return;
  } else {
    cout << ans.size() << endl;
    for (auto u : ans) cout << u + 1 << " ";
    cout << endl;
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}

```


### Prompt

Create a solution in cpp for the following problem:

The Prodiggers are quite a cool band and for this reason, they have been the surprise guest at the ENTER festival for the past 80 years. At the beginning of their careers, they weren’t so successful, so they had to spend time digging channels to earn money; hence the name. Anyway, they like to tour a lot and have surprising amounts of energy to do extremely long tours. However, they hate spending two consecutive days without having a concert, so they would like to avoid it.

A tour is defined by a sequence of concerts and days-off. You need to count in how many ways The Prodiggers can select k different tours of the same length between l and r.

For example if k = 2, l = 1 and r = 2, if we define concert day as {1} and day-off as {0}, here are all possible tours: {0}, {1}, {00}, {01}, {10}, {11}. But tour 00 can not be selected because it has 2 days-off in a row. Now, we need to count in how many ways we can select k = 2 tours of the same length in range [1;2]. Here they are: {0,1}; {01,10}; {01,11}; {10,11}.

Since their schedule is quite busy, they want you to tell them in how many ways can do that, modulo 1 000 000 007 (109 + 7).

Input

The first line of the input contains three integers k, l and r (1 ≤ k ≤ 200, 1 ≤ l ≤ r ≤ 1018).

Output

Output a single number: the number of ways to select k different tours of the same length, modulo 1 000 000 007.

Example

Input

1 1 2

Output

5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void in(T &x) {
  x = 0;
  char c = getchar();
  bool f = 0;
  while (!isdigit(c)) f |= (c == '-'), c = getchar();
  while (isdigit(c)) x = x * 10 + (c ^ '0'), c = getchar();
  f ? x = -x : 0;
}
template <class T>
inline void out(T x, const char c = '\n') {
  static short st[30];
  short m = 0;
  if (x < 0) putchar('-'), x = -x;
  do st[++m] = x % 10, x /= 10;
  while (x);
  while (m) putchar(st[m--] | '0');
  putchar(c);
}
template <class T, class... Args>
inline void in(T &x, Args &...args) {
  in(x);
  in(args...);
}
template <class T, class... Args>
inline void out(const T &x, const Args &...args) {
  out(x, ' ');
  out(args...);
}
template <class T>
inline void prt(T a[], int n) {
  for (register int i = 0; i < n; ++i) out(a[i], i == n - 1 ? '\n' : ' ');
}
template <class T>
inline void clr(T a[], int n) {
  memset(a, 0, sizeof(T) * n);
}
template <class T>
inline void clr(T *a, T *b) {
  memset(a, 0, sizeof(T) * (b - a));
}
template <class T>
inline bool ckmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
inline bool ckmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
namespace MOD_CALC {
const int md = 1e9 + 7, inv2 = (md + 1) / 2;
inline int add(const int a, const int b) {
  return a + b >= md ? a + b - md : a + b;
}
inline int sub(const int a, const int b) {
  return a - b < 0 ? a - b + md : a - b;
}
inline int mul(const int a, const int b) { return (long long)a * b % md; }
inline void inc(int &a, const int b) { (a += b) >= md ? a -= md : 0; }
inline void dec(int &a, const int b) { (a -= b) < 0 ? a += md : 0; }
inline int qpow(int a, int b) {
  int r = 1;
  for (; b; b >>= 1, a = mul(a, a))
    if (b & 1) r = mul(r, a);
  return r;
}
inline int qpow(int a, int b, const int p) {
  int r = 1;
  for (; b; b >>= 1, a = (long long)a * a % p)
    if (b & 1) r = (long long)r * a % p;
  return r;
}
inline int mdinv(const int a) { return qpow(a, md - 2); }
template <class... Args>
inline int add(const int a, const int b, const Args &...args) {
  return add(add(a, b), args...);
}
template <class... Args>
inline int mul(const int a, const int b, const Args &...args) {
  return mul(mul(a, b), args...);
}
}  // namespace MOD_CALC
using namespace MOD_CALC;
namespace i207M {
int c = 5;
struct cpx {
  int x, y;
  cpx(const int _x, const int _y) { x = _x, y = _y; }
  cpx() {}
  inline friend cpx operator+(const cpx &a, const cpx &b) {
    return cpx(add(a.x, b.x), add(a.y, b.y));
  }
  inline friend cpx operator-(const cpx &a, const cpx &b) {
    return cpx(sub(a.x, b.x), sub(a.y, b.y));
  }
  inline friend cpx operator*(const cpx &a, const cpx &b) {
    return cpx(add(mul(a.x, b.x), mul(c, a.y, b.y)),
               add(mul(a.x, b.y), mul(a.y, b.x)));
  }
  inline cpx operator*(const int v) const { return cpx(mul(x, v), mul(y, v)); }
  inline cpx operator~() const {
    int t = mdinv(sub(mul(x, x), mul(c, y, y)));
    return cpx(mul(x, t), mul(md - y, t));
  }
  inline friend cpx operator/(const cpx &a, const cpx &b) { return a * (~b); }
};
inline cpx qpow(cpx a, long long b) {
  cpx r(1, 0);
  for (; b; b >>= 1, a = a * a)
    if (b & 1) r = r * a;
  return r;
}
int bi[505][505], s[505][505], ifac[505];
int solve(cpx A, cpx B, cpx C, cpx D, int K, long long n) {
  int ans = 0;
  cpx XX(1, 0), YY(1, 0);
  for (register int i = 0; i <= K; ++i, XX = XX * B, YY = YY * D) {
    int sum = 0;
    cpx X = XX, Y = YY;
    for (register int j = 0; j <= i; ++j, X = X * A / B, Y = Y * C / D) {
      cpx t = (qpow(X, n + 1) - cpx(1, 0)) / (X - cpx(1, 0)) * Y;
      if (X.x == 1 && X.y == 0) t = Y * ((n + 1) % md);
      inc(sum, mul(bi[i][j], t.x));
    }
    sum = mul(s[K][i], sum);
    if ((K - i) & 1)
      dec(ans, sum);
    else
      inc(ans, sum);
  }
  ans = mul(ans, ifac[K]);
  return ans;
}
void prework() {
  bi[0][0] = s[0][0] = 1;
  for (register int i = 1; i <= 501; ++i) {
    bi[i][0] = 1;
    for (register int j = 1; j <= i; ++j) {
      bi[i][j] = add(bi[i - 1][j - 1], bi[i - 1][j]);
      s[i][j] = add(s[i - 1][j - 1], mul(s[i - 1][j], i - 1));
    }
  }
  ifac[0] = 1;
  for (register int i = 1; i <= 501; ++i) ifac[i] = mul(ifac[i - 1], mdinv(i));
}
const int inv10 = mdinv(10);
cpx A(inv2, inv2), B(inv2, md - inv2), C(inv2, inv10), D(inv2, md - inv10);
signed main() {
  long long l, r;
  int k, ans;
  prework();
  in(k, l, r);
  ans = solve(A, B, C, D, k, r + 1);
  dec(ans, solve(A, B, C, D, k, l));
  out(ans);
  return 0;
}
}  // namespace i207M
signed main() {
  i207M::main();
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

I came to the summer festival with the elementary school students in my neighborhood. To put it bluntly, it plays the role of a guardian, but the smell of yakisoba and takoyaki in the store, and the sound of fireworks that can be heard from time to time, are still exciting even at this age. But today I have to keep an eye on the curious children so they don't get lost.

The children seemed to be interested in opening a store. When I looked into it, I was supposed to play a game using dice with the uncle who opened the store, and if I win, I would get a prize. The game is a simple one called High & Low. Participants and uncles roll one dice each, but before that, participants predict whether their rolls will be greater or lesser than their uncle's rolls. If the prediction is correct, it is a victory, and if the same result is rolled, both roll the dice again.

The tricky part of this game is that the dice of the participants and the dice of the uncle may be different. Participants can see the development of both dice in advance, so they can expect it as a hint.

In other words, it's a simple probability calculation. However, the probability is in the range of high school mathematics, and it may be a little heavy for elementary school students. Even the most clever of the kids are thinking, shaking their braided hair. I'll be asking for help soon. By the way, let's show you something that seems to be an adult once in a while.

Input

The input consists of multiple cases.

In each case, a development of the dice is given in a 21x57 grid.
The first 21x28 ((0,0) is the upper left, (20,27) is the lower right) grid represents the participants' dice.
The last 21x28 ((0,29) is the upper left, (20,56) is the lower right) represents the uncle's dice.

Each side of the participant's dice is 7x7 with (0,7), (7,0), (7,7), (7,14), (7,21), (14,7) as the upper left. Given in the subgrid of.
The numbers written on the development drawing are the original numbers.
Flip horizontal
Flip left and right, then rotate 90 degrees counterclockwise
Flip horizontal
Flip left and right, then rotate 270 degrees counterclockwise
Flip horizontal
Flip upside down, then flip left and right
It was made to do.

Each side of the uncle's dice is 7x7 with (0,36), (7,29), (7,36), (7,43), (7,50), (14,36) as the upper left. Given in the subgrid.
The numbers on the uncle's dice development are drawn according to the same rules as the participants' dice.

One of 1 to 9 is written on each side of the dice.
The numbers are given in a 7x7 grid like this:

..... #
... |. #
..... #
... |. #
..-.. #

..-.. #
... |. #
..-.. #
. | ... #
..-.. #

..-.. #
... |. #
..-.. #
... |. #
..-.. #

..... #
. |. |. #
..-.. #
... |. #
..... #

..-.. #
. | ... #
..-.. #
... |. #
..-.. #

..-.. #
. | ... #
..-.. #
. |. |. #
..-.. #

..-.. #
... |. #
..... #
... |. #
..... #

..-.. #
. |. |. #
..-.. #
. |. |. #
..-.. #

..-.. #
. |. |. #
..-.. #
... |. #
..-.. #

However, when the above numbers are rotated 90 degrees or 270 degrees, the "|" and "-" are interchanged.

The end of the input is given by a single 0 line

The dice given as input are always correct. Also, dice that cannot be settled are not given.

Output

Output the one with the higher probability in one line when it becomes "HIGH" and when it becomes "LOW". If both probabilities are the same, output "HIGH".

Examples

Input

.......#######......................#######..............
.......#.....#......................#..-..#..............
.......#.|...#......................#.|.|.#..............
.......#.....#......................#..-..#..............
.......#.|...#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
############################.############################
#.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
#.-.-.##...|.##.-.-.##.|.|.#.#.....##.|.|.##.-.-.##.|.|.#
#|.|.|##..-..##|.|.|##..-..#.#....|##..-..##|.|.|##..-..#
#...-.##.|...##...-.##.|.|.#.#.-.-.##.|...##...-.##.|...#
#.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
############################.############################
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#.|.|.#......................#...|.#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#...|.#..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#.|.|.#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
############################.############################
#.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
#.-.-.##...|.##.-.-.##.|.|.#.#...-.##...|.##.-...##.|.|.#
#|.|.|##..-..##|.|.|##..-..#.#|.|.|##..-..##|.|.|##..-..#
#.-.-.##.|...##...-.##.|...#.#.-...##.|.|.##.-.-.##.|...#
#.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
############################.############################
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#...|.#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#.|.|.#..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
############################.############################
#.....##..-..##.....##..-..#.#.....##..-..##.....##.....#
#.-.-.##.|.|.##.-.-.##...|.#.#.....##.|.|.##...-.##.|...#
#|.|.|##..-..##|....##..-..#.#....|##..-..##|.|.|##.....#
#.-.-.##.|.|.##.....##.|.|.#.#.-.-.##.|.|.##.-...##.|...#
#.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
############################.############################
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#.|.|.#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#...|.#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#.|.|.#..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
############################.############################
#.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
#.-.-.##...|.##.-.-.##.|.|.#.#.-...##.|.|.##.-...##.|.|.#
#|.|.|##..-..##|.|.|##..-..#.#|.|.|##..-..##|.|.|##..-..#
#...-.##.|...##.-.-.##.|.|.#.#.-.-.##.|...##.-.-.##.|.|.#
#.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
############################.############################
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#.|.|.#..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#...|.#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
0

Output

LOW
HIGH
HIGH
LOW

Input

.......#######......................#######..............
.......#.....#......................#..-..#..............
.......#.|...#......................#.|.|.#..............
.......#.....#......................#..-..#..............
.......#.|...#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
.############################
.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
.-.-.##...|.##.-.-.##.|.|.#.#.....##.|.|.##.-.-.##.|.|.#
|.|.|##..-..##|.|.|##..-..#.#....|##..-..##|.|.|##..-..#
...-.##.|...##...-.##.|.|.#.#.-.-.##.|...##...-.##.|...#
.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
.############################
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#.|.|.#......................#...|.#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#...|.#..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#.|.|.#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
.############################
.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
.-.-.##...|.##.-.-.##.|.|.#.#...-.##...|.##.-...##.|.|.#
|.|.|##..-..##|.|.|##..-..#.#|.|.|##..-..##|.|.|##..-..#
.-.-.##.|...##...-.##.|...#.#.-...##.|.|.##.-.-.##.|...#
.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
.############################
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#...|.#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#.|.|.#..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
.############################
.....##..-..##.....##..-..#.#.....##..-..##.....##.....#
.-.-.##.|.|.##.-.-.##...|.#.#.....##.|.|.##...-.##.|...#
|.|.|##..-..##|....##..-..#.#....|##..-..##|.|.|##.....#
.-.-.##.|.|.##.....##.|.|.#.#.-.-.##.|.|.##.-...##.|...#
.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
.############################
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#.|.|.#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#...|.#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#.|.|.#..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#.|...#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
.############################
.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
.-.-.##...|.##.-.-.##.|.|.#.#.-...##.|.|.##.-...##.|.|.#
|.|.|##..-..##|.|.|##..-..#.#|.|.|##..-..##|.|.|##..-..#
...-.##.|...##.-.-.##.|.|.#.#.-.-.##.|...##.-.-.##.|.|.#
.....##..-..##.....##..-..#.#.....##..-..##.....##..-..#
.############################
.......#######......................#######..............
.......#..-..#......................#..-..#..............
.......#...|.#......................#.|.|.#..............
.......#..-..#......................#..-..#..............
.......#.|...#......................#...|.#..............
.......#..-..#......................#..-..#..............
.......#######......................#######..............
0

Output

LOW
HIGH
HIGH
LOW

### Response

```cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cassert>
using namespace std;
int dicea[6],diceb[6];
string str[21];
int mk_num(string *);

void lr_hanten(string a[]){
  for(int i=0;i<7;i++)
    for(int j=0;j<7/2;j++) swap(a[i][j],a[i][6-j]);
}

void ud_hanten(string a[]){
  for(int i=0;i<7;i++)
    for(int j=0;j<7/2;j++) swap(a[j][i],a[6-j][i]);
}

void rol_90(string a[]){
  string b[7];
  for(int i=0;i<7;i++)
    for(int j=0;j<7;j++) {
      b[i] += a[j][6-i];
      if(b[i][j] == '-') b[i][j] = '|';
      else if(b[i][j] =='|') b[i][j] = '-';
    }
  for(int i=0;i<7;i++) a[i] = b[i];
}

void choice(string num[],int x,int y){
  for(int i=0;i<7;i++){
    num[i]="";
    for(int j=0;j<7;j++) num[i]+=str[y+i][x+j];
  }
}

void mk_dice(){
  string num[2][7];
  //ue
  choice(num[0],7,0),choice(num[1],36,0);
  lr_hanten(num[0]),lr_hanten(num[1]);
  dicea[0] = mk_num(num[0]),diceb[0]=mk_num(num[1]);

  //hidari
  choice(num[0],0,7),choice(num[1],29,7);
  lr_hanten(num[0]),lr_hanten(num[1]);
  rol_90(num[0]),rol_90(num[1]);
  dicea[1] = mk_num(num[0]),diceb[1] = mk_num(num[1]);

  //mid_hidari
  choice(num[0],7,7),choice(num[1],36,7);
  lr_hanten(num[0]),lr_hanten(num[1]);
  dicea[2] = mk_num(num[0]),diceb[2] = mk_num(num[1]);

  //mid_migi
  choice(num[0],14,7),choice(num[1],43,7);
  lr_hanten(num[0]),lr_hanten(num[1]);
  for(int i=0;i<3;i++)rol_90(num[0]),rol_90(num[1]);
  dicea[3] = mk_num(num[0]),diceb[3] = mk_num(num[1]);

  //migi
  choice(num[0],21,7),choice(num[1],50,7);
  lr_hanten(num[0]),lr_hanten(num[1]);
  dicea[4] = mk_num(num[0]),diceb[4] = mk_num(num[1]);

  //sita
  choice(num[0],7,14),choice(num[1],36,14);
  ud_hanten(num[0]),ud_hanten(num[1]);
  lr_hanten(num[0]),lr_hanten(num[1]);
  dicea[5] = mk_num(num[0]),diceb[5] = mk_num(num[1]);
}

int main(){
  while(1) {
    for(int i=0;i<21;i++){
      cin >> str[i];
      if(str[i]=="0")break;
    }
    if(str[0]=="0")break;
    mk_dice();
    int a=0,b=0;
    for(int i=0;i<6;i++) assert(dicea[i]!=-1 && diceb[i]!=-1);

    for(int i=0;i<6;i++)
      for(int j=0;j<6;j++)
	if(dicea[i] > diceb[j]) a++;
	else if(dicea[i]<diceb[j])b++;

    if(a>=b) cout<<"HIGH"<<endl;
    else cout <<"LOW"<<endl;
  }

}

int mk_num(string a[]){
  if(a[1]=="#.....#" &&
     a[2]=="#...|.#") return 1;

  if(a[1]=="#..-..#" &&
     a[2]=="#...|.#" &&
     a[3]=="#..-..#" &&
     a[4]=="#.|...#" &&
     a[5]=="#..-..#") return 2;

  if(a[1]=="#..-..#" &&
     a[2]=="#...|.#" &&
     a[3]=="#..-..#" &&
     a[4]=="#...|.#" &&
     a[5]=="#..-..#") return 3;

  if(a[1]=="#.....#" &&
     a[5]=="#.....#") return 4;

  if(a[1]=="#..-..#" &&
     a[2]=="#.|...#" &&
     a[3]=="#..-..#" &&
     a[4]=="#...|.#" &&
     a[5]=="#..-..#") return 5;

  if(a[1]=="#..-..#" &&
     a[2]=="#.|...#" &&
     a[3]=="#..-..#" &&
     a[4]=="#.|.|.#" &&
     a[5]=="#..-..#") return 6;

  if(a[3]=="#.....#" &&
     a[5]=="#.....#") return 7;

  if(a[1]=="#..-..#" &&
     a[2]=="#.|.|.#" &&
     a[3]=="#..-..#" &&
     a[4]=="#.|.|.#" &&
     a[5]=="#..-..#") return 8;

  if(a[1]=="#..-..#" &&
     a[2]=="#.|.|.#" &&
     a[3]=="#..-..#" &&
     a[4]=="#...|.#" &&
     a[5]=="#..-..#") return 9;
  return -1;
}
```