### Prompt

Please formulate a cpp solution to the following problem:

Little C loves number «3» very much. He loves all things about it.

Now he is playing a game on a chessboard of size n × m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|.

He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place.

Input

A single line contains two integers n and m (1 ≤ n,m ≤ 10^9) — the number of rows and the number of columns of the chessboard.

Output

Print one integer — the maximum number of chessmen Little C can place.

Examples

Input

2 2

Output

0

Input

3 3

Output

8

Note

In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0.

In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void use_cio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
template <typename... Args>
void dbg(Args... args) {
  ((cout << args << " "), ...);
  cout << "\n";
}
int n, m;
int main() {
  use_cio();
  cin >> n >> m;
  if (n > m) swap(n, m);
  if (n == 1) {
    if (m % 6 < 4)
      cout << (m / 6) * 6;
    else
      cout << (m / 6) * 6 + ((m % 6) - 3) * 2;
  } else if (n == 2) {
    if (m == 2)
      cout << 0;
    else if (m == 3)
      cout << 4;
    else if (m == 7)
      cout << 12;
    else
      cout << 1LL * n * m;
  } else {
    cout << (1LL * n * m / 2) * 2;
  }
}

```


### Prompt

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

A graph is called planar, if it can be drawn in such a way that its edges intersect only at their vertexes.

An articulation point is such a vertex of an undirected graph, that when removed increases the number of connected components of the graph.

A bridge is such an edge of an undirected graph, that when removed increases the number of connected components of the graph.

You've got a connected undirected planar graph consisting of n vertexes, numbered from 1 to n, drawn on the plane. The graph has no bridges, articulation points, loops and multiple edges. You are also given q queries. Each query is a cycle in the graph. The query response is the number of graph vertexes, which (if you draw a graph and the cycle on the plane) are located either inside the cycle, or on it. Write a program that, given the graph and the queries, will answer each query.

Input

The first line contains two space-separated integers n and m (3 ≤ n, m ≤ 105) — the number of vertexes and edges of the graph. Next m lines contain the edges of the graph: the i-th line contains two space-separated integers ui and vi (1 ≤ ui, vi ≤ n) — the numbers of vertexes, connecting the i-th edge. The next n lines contain the positions of the planar graph vertexes on the plane: the i-th line contains a pair of space-separated integers xi and yi (|xi|, |yi| ≤ 109) — the coordinates of the i-th vertex of the graph on the plane.

The next line contains integer q (1 ≤ q ≤ 105) — the number of queries. Then follow q lines that describe the queries: the i-th line contains the sequence of space-separated integers ki, a1, a2, ..., aki (1 ≤ aj ≤ n; ki > 2), where ki is the cycle length in the i-th query, aj are numbers of the vertexes that form a cycle. The numbers of vertexes in the cycle are given in the clockwise or counterclockwise order. The given cycles are simple, that is they cannot go through a graph vertex more than once. The total length of all cycles in all queries does not exceed 105.

It is guaranteed that the given graph contains no bridges, articulation points, loops and multiple edges. It is guaranteed that the edge segments can have common points only at the graph's vertexes.

Output

For each query print a single integer — the number of vertexes inside the cycle or on it. Print the answers in the order, in which the queries follow in the input. Separate the numbers by spaces.

Examples

Input

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

Output

3

Input

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

Output

5

Input

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

Output

3
3
4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double Pi = acos(-1), eps = 1e-10;
int n, m, k, Q, id[100005], rt, siz[100005], f[100005];
int fir[100005], tot;
int sgn(double x) { return x > -eps && x < eps ? 0 : 1; }
struct node {
  double ang;
  int to, s;
  bool operator<(const node &p) const {
    return sgn(ang - p.ang) ? ang < p.ang : s < p.s;
  }
};
vector<node> G[100005];
struct Point {
  long long x, y;
  Point(long long x = 0, long long y = 0) : x(x), y(y) {}
  Point operator-(const Point &p) { return Point(x - p.x, y - p.y); }
  long long operator*(const Point &p) { return x * p.y - y * p.x; }
  double angle() { return atan2(y, x); }
} a[100005];
int find(int x) { return !f[x] ? x : f[x] = find(f[x]); }
void dfs(int u, int ff) {
  siz[u] = 1;
  for (int i = 0, v; i < G[u].size() - 1; i++) {
    if (G[u][i].to == ff) swap(G[u].back(), G[u][i]);
    dfs(v = G[u][i].to, u), siz[u] += siz[v];
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d%d", &x, &y);
    if (find(x) != find(y))
      G[x].push_back((node){0, y, 0}), G[y].push_back((node){0, x, 0}),
          f[find(x)] = find(y);
  }
  for (int i = 1; i <= n; i++)
    scanf("%lld%lld", &a[i].x, &a[i].y), (!rt || a[i].x < a[rt].x) && (rt = i);
  G[rt].push_back((node){0, 0, 0}), a[0].x = -2e9, a[0].y = a[rt].y;
  dfs(rt, 0);
  for (int u = 1; u <= n; u++) {
    for (int i = 0; i < G[u].size(); i++)
      G[u][i].ang = (a[G[u][i].to] - a[u]).angle();
    sort(G[u].begin(), G[u].end() - 1);
    for (int i = 0; i < G[u].size() - 1; i++)
      G[u][i].s = siz[G[u][i].to] + (i ? G[u][i - 1].s : 0);
  }
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d", &k);
    for (int i = 0; i < k; i++) scanf("%d", &id[i]);
    long long area = 0;
    for (int i = 0; i < k; i++) area += a[id[i]] * a[id[(i + 1) % k]];
    if (area < 0) reverse(id, id + k);
    int ans = 0;
    for (int o = 0; o < k; o++) {
      int i = id[o];
      double L = (a[id[(o + k - 1) % k]] - a[i]).angle(),
             R = (a[id[(o + 1) % k]] - a[i]).angle();
      if (L < R) {
        if (L + eps < G[i].back().ang && G[i].back().ang + eps < R)
          ans += siz[i];
        int l = lower_bound(G[i].begin(), G[i].end() - 1,
                            (node){L, 0, 1000000000}) -
                G[i].begin() - 1;
        int r = lower_bound(G[i].begin(), G[i].end() - 1, (node){R, 0, -1}) -
                G[i].begin() - 1;
        ans -= (r >= 0 ? G[i][r].s : 0) - (l >= 0 ? G[i][l].s : 0);
      } else {
        if (L + eps < G[i].back().ang || G[i].back().ang + eps < R)
          ans += siz[i];
        int l = lower_bound(G[i].begin(), G[i].end() - 1, (node){R, 0, -1}) -
                G[i].begin() - 1;
        int r = lower_bound(G[i].begin(), G[i].end() - 1,
                            (node){L, 0, 1000000000}) -
                G[i].begin() - 1;
        ans -= (G[i].size() >= 2 ? G[i][G[i].size() - 2].s : 0) -
               (r >= 0 ? G[i][r].s : 0) + (l >= 0 ? G[i][l].s : 0);
      }
    }
    printf("%d\n", ans);
  }
}

```


### Prompt

Please create a solution in CPP to the following problem:

There are n cities and m bidirectional roads in Berland. The i-th road connects the cities x_i and y_i, and has the speed limit s_i. The road network allows everyone to get from any city to any other city.

The Berland Transport Ministry is planning a road reform.

First of all, maintaining all m roads is too costly, so m - (n - 1) roads will be demolished in such a way that the remaining (n - 1) roads still allow to get to any city from any other city. Formally, the remaining roads should represent an undirected tree.

Secondly, the speed limits on the remaining roads might be changed. The changes will be done sequentially, each change is either increasing the speed limit on some road by 1, or decreasing it by 1. Since changing the speed limit requires a lot of work, the Ministry wants to minimize the number of changes.

The goal of the Ministry is to have a road network of (n - 1) roads with the maximum speed limit over all roads equal to exactly k. They assigned you the task of calculating the minimum number of speed limit changes they have to perform so the road network meets their requirements.

For example, suppose the initial map of Berland looks like that, and k = 7:

<image>

Then one of the optimal courses of action is to demolish the roads 1–4 and 3–4, and then decrease the speed limit on the road 2–3 by 1, so the resulting road network looks like that:

<image>

Input

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

The first line of each test case contains three integers n, m and k (2 ≤ n ≤ 2 ⋅ 10^5; n - 1 ≤ m ≤ min(2 ⋅ 10^5, (n(n-1))/(2)); 1 ≤ k ≤ 10^9) — the number of cities, the number of roads and the required maximum speed limit, respectively.

Then m lines follow. The i-th line contains three integers x_i, y_i and s_i (1 ≤ x_i, y_i ≤ n; x_i ≠ y_i; 1 ≤ s_i ≤ 10^9) — the cities connected by the i-th road and the speed limit on it, respectively. All roads are bidirectional.

The road network in each test case is connected (that is, it is possible to reach any city from any other city by traveling along the road), and each pair of cities is connected by at most one road.

The sum of n over all test cases does not exceed 2 ⋅ 10^5. Similarly, the sum of m over all test cases does not exceed 2 ⋅ 10^5.

Output

For each test case, print one integer — the minimum number of changes the Ministry has to perform so that the maximum speed limit among the remaining (n - 1) roads is exactly k.

Example

Input

4
4 5 7
4 1 3
1 2 5
2 3 8
2 4 1
3 4 4
4 6 5
1 2 1
1 3 1
1 4 2
2 4 1
4 3 1
3 2 1
3 2 10
1 2 8
1 3 10
5 5 15
1 2 17
3 1 15
2 3 10
1 4 14
2 5 8

Output

1
3
0
0

Note

The explanation for the example test:

The first test case is described in the problem statement.

In the second test case, the road network initially looks like that:

<image>

The Ministry can demolish the roads 1–2, 3–2 and 3–4, and then increase the speed limit on the road 1–4 three times.

In the third test case, the road network already meets all the requirements.

In the fourth test case, it is enough to demolish the road 1–2 so the resulting road network meets the requirements.

### Response

```cpp
#include<bits/stdc++.h>
#define inf 200000000000000000
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define fastio ios::sync_with_stdio(false);cin.tie(NULL)
#define rng_23 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef set<ll> si;
typedef multiset<ll> msi;
typedef map<ll,ll> mii;
ll parent[200001];
class edge
{
public:
    ll x,y,l;
    edge(ll x,ll y,ll l): x(x),y(y),l(l) {}
};
bool comp1(edge &a,edge& b)
{
    return a.l<b.l;
}
bool comp2(edge &a,edge& b)
{
    return a.l>b.l;
}
ll rep(ll a)
{
    if(a==parent[a])
        return a;
    parent[a]=rep(parent[a]);
    return parent[a];
}
int main()
{
    fastio;
    ll t;
    cin>>t;
    while(t--){
    ll i,j,k;
    ll n,m,l;
    ll x,y;
    ll respos=inf,resneg=inf;
    vector<edge> edgeneg,edgepos;
    cin>>n>>m>>k;
    for(i=0;i<m;i++){
        cin>>x>>y>>l;
        if(l<=k)
            edgeneg.pb(edge(x,y,l-k));
        else
            edgepos.pb(edge(x,y,l-k));
    }
    sort(edgepos.begin(),edgepos.end(),comp1);
    sort(edgeneg.begin(),edgeneg.end(),comp2);
    for(i=1;i<=n;i++){
        parent[i]=i;
    }

    for(auto edge: edgeneg){
        //prllf("%d %d %d\n",edge.x,edge.y,edge.l);
        ll r1=rep(edge.x);
        ll r2=rep(edge.y);
        parent[r1]=r2;
        resneg=min(resneg,-edge.l);

    }
    si temp;
    for(i=1;i<=n;i++){
        temp.insert(rep(i));
    }

    if((ll)temp.size()>1ll)
        resneg=inf;
    else {
        if(!edgepos.empty()){
            resneg=min(resneg,edgepos.front().l);
        }
    }

    //printf("%d\n",resneg);

    if(!edgepos.empty()){
        respos=0;
    }
    //printf("%d\n",resn);
    for(auto edge: edgepos){
        //prllf("%d %d %d\n",edge.x,edge.y,edge.l);
        ll r1=rep(edge.x);
        ll r2=rep(edge.y);
        if(r1!=r2){
            parent[r1]=r2;
            respos+=edge.l;
        }
    }
    if(respos==0)
        respos=edgepos.front().l;
    cout<<min(respos,resneg)<<"\n";
    }
}

```


### Prompt

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

The Little Elephant has two permutations a and b of length n, consisting of numbers from 1 to n, inclusive. Let's denote the i-th (1 ≤ i ≤ n) element of the permutation a as ai, the j-th (1 ≤ j ≤ n) element of the permutation b — as bj.

The distance between permutations a and b is the minimum absolute value of the difference between the positions of the occurrences of some number in a and in b. More formally, it's such minimum |i - j|, that ai = bj.

A cyclic shift number i (1 ≤ i ≤ n) of permutation b consisting from n elements is a permutation bibi + 1... bnb1b2... bi - 1. Overall a permutation has n cyclic shifts.

The Little Elephant wonders, for all cyclic shifts of permutation b, what is the distance between the cyclic shift and permutation a?

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the size of the permutations. The second line contains permutation a as n distinct numbers from 1 to n, inclusive. The numbers are separated with single spaces. The third line contains permutation b in the same format.

Output

In n lines print n integers — the answers for cyclic shifts. Print the answers to the shifts in the order of the shifts' numeration in permutation b, that is, first for the 1-st cyclic shift, then for the 2-nd, and so on.

Examples

Input

2
1 2
2 1

Output

1
0

Input

4
2 1 3 4
3 4 2 1

Output

2
1
0
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long a[100100], b[100100], n;
multiset<long> s;
multiset<long>::iterator it;
void read(void) {
  cin >> n;
  for (long x, i = 1; i <= n; ++i) {
    cin >> x;
    a[x] = i;
  }
  for (long i = 1; i <= n; ++i) cin >> b[i];
  for (long i = 1; i <= n; ++i) s.insert(i - a[b[i]]);
}
void kill(void) {
  for (long x, i = 0; i < n;) {
    it = s.lower_bound(i);
    x = 100100;
    if (it != s.end()) x = min(x, (*it - i));
    if (it != s.begin()) {
      it--;
      x = min(x, (i - *it));
    }
    cout << x << "\n";
    i++;
    s.erase(s.find(i - a[b[i]]));
    s.insert(i + n - a[b[i]]);
  }
}
int main() {
  read();
  kill();
  return 0;
}

```


### Prompt

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

Grisha come to a contest and faced the following problem.

You are given an array of size n, initially consisting of zeros. The elements of the array are enumerated from 1 to n. You perform q operations on the array. The i-th operation is described with three integers l_i, r_i and x_i (1 ≤ l_i ≤ r_i ≤ n, 1 ≤ x_i ≤ n) and means that you should add x_i to each of the elements with indices l_i, l_i + 1, …, r_i. After all operations you should find the maximum in the array.

Grisha is clever, so he solved the problem quickly.

However something went wrong inside his head and now he thinks of the following question: "consider we applied some subset of the operations to the array. What are the possible values of the maximum in the array?"

Help Grisha, find all integers y between 1 and n such that if you apply some subset (possibly empty) of the operations, then the maximum in the array becomes equal to y.

Input

The first line contains two integers n and q (1 ≤ n, q ≤ 10^{4}) — the length of the array and the number of queries in the initial problem.

The following q lines contain queries, one per line. The i-th of these lines contains three integers l_i, r_i and x_i (1 ≤ l_i ≤ r_i ≤ n, 1 ≤ x_i ≤ n), denoting a query of adding x_i to the segment from l_i-th to r_i-th elements of the array, inclusive.

Output

In the first line print the only integer k, denoting the number of integers from 1 to n, inclusive, that can be equal to the maximum in the array after applying some subset (possibly empty) of the given operations.

In the next line print these k integers from 1 to n — the possible values of the maximum. Print these integers in increasing order.

Examples

Input

4 3
1 3 1
2 4 2
3 4 4

Output

4
1 2 3 4

Input

7 2
1 5 1
3 7 2

Output

3
1 2 3

Input

10 3
1 1 2
1 1 3
1 1 6

Output

6
2 3 5 6 8 9

Note

Consider the first example. If you consider the subset only of the first query, the maximum is equal to 1. If you take only the second query, the maximum equals to 2. If you take the first two queries, the maximum becomes 3. If you take only the fourth query, the maximum becomes 4. If you take the fourth query and something more, the maximum becomes greater that n, so you shouldn't print it.

In the second example you can take the first query to obtain 1. You can take only the second query to obtain 2. You can take all queries to obtain 3.

In the third example you can obtain the following maximums:

  * You can achieve the maximim of 2 by using queries: (1).
  * You can achieve the maximim of 3 by using queries: (2).
  * You can achieve the maximim of 5 by using queries: (1, 2).
  * You can achieve the maximim of 6 by using queries: (3).
  * You can achieve the maximim of 8 by using queries: (1, 3).
  * You can achieve the maximim of 9 by using queries: (2, 3).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
const int N = 1e4 + 1;
using bs = bitset<N>;
vector<int> g[N << 2];
int n, q;
bs can;
void add(int& l, int& r, int& x, int u = 1, int b = 1, int e = n) {
  if (b > r or e < l) return;
  if (l <= b and e <= r) return void(g[u].emplace_back(x));
  int m = b + e >> 1;
  add(l, r, x, u << 1, b, m);
  add(l, r, x, u << 1 | 1, m + 1, e);
}
void solve(int u = 1, int b = 1, int e = n, bs B = can) {
  for (int x : g[u]) B = B | (B << x);
  if (b == e) return void(can |= B);
  int m = b + e >> 1;
  solve(u << 1, b, m, B);
  solve(u << 1 | 1, m + 1, e, B);
}
int main(int argc, char const* argv[]) {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= q; i++) {
    int l, r, x;
    scanf("%d %d %d", &l, &r, &x);
    add(l, r, x);
  }
  can[0] = 1;
  solve();
  vi ans;
  for (int i = 1; i <= n; i++) {
    if (can[i]) ans.emplace_back(i);
  }
  printf("%d\n", (int)ans.size());
  for (int i = 1; i <= (int)ans.size(); i++) {
    printf("%d%c", ans[i - 1], " \n"[i == ans.size()]);
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

You are given an array a consisting of 500000 integers (numbered from 1 to 500000). Initially all elements of a are zero.

You have to process two types of queries to this array:

  * 1 x y — increase a_x by y;
  * 2 x y — compute ∑_{i ∈ R(x, y)} a_i, where R(x, y) is the set of all integers from 1 to 500000 which have remainder y modulo x.

Can you process all the queries?

Input

The first line contains one integer q (1 ≤ q ≤ 500000) — the number of queries.

Then q lines follow, each describing a query. The i-th line contains three integers t_i, x_i and y_i (1 ≤ t_i ≤ 2). If t_i = 1, then it is a query of the first type, 1 ≤ x_i ≤ 500000, and -1000 ≤ y_i ≤ 1000. If t_i = 2, then it it a query of the second type, 1 ≤ x_i ≤ 500000, and 0 ≤ y_i < x_i.

It is guaranteed that there will be at least one query of type 2.

Output

For each query of type 2 print one integer — the answer to it.

Example

Input

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

Output

4
4
0

### Response

```cpp
#include <bits/stdc++.h>
const int n = 500000;
const int B = 710;
using namespace std;
int part[B + 10][B + 10], a[n + 10];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int o, x, y, i;
    scanf("%d%d%d", &o, &x, &y);
    if (o == 1) {
      a[x] += y;
      for (i = 1; i <= B; i++) part[i][x % i] += y;
    } else {
      if (x <= B)
        printf("%d\n", part[x][y]);
      else {
        int ans = 0;
        for (i = 0; i * x + y <= n; i++) ans += a[i * x + y];
        printf("%d\n", ans);
      }
    }
  }
}

```


### Prompt

Create a solution in cpp for the following problem:

For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $L$, find the minimum of each possible sub-arrays with size $L$ and print them from the beginning. For example, for an array $\\{1, 7, 7, 4, 8, 1, 6\\}$ and $L = 3$, the possible sub-arrays with size $L = 3$ includes $\\{1, 7, 7\\}$, $\\{7, 7, 4\\}$, $\\{7, 4, 8\\}$, $\\{4, 8, 1\\}$, $\\{8, 1, 6\\}$ and the minimum of each sub-array is 1, 4, 4, 1, 1 respectively.

Constraints

* $1 \leq N \leq 10^6$
* $1 \leq L \leq 10^6$
* $1 \leq a_i \leq 10^9$
* $L \leq N$

Input

The input is given in the following format.

$N$ $L$
$a_1$ $a_2$ ... $a_N$

Output

Print a sequence of the minimum in a line. Print a space character between adjacent elements.

Example

Input

7 3
1 7 7 4 8 1 6

Output

1 4 4 1 1

### Response

```cpp
// #include <algorithm>
#include <stdio.h>
#include <vector>
#include <math.h>
#include <deque>
#include <iostream>
using namespace std;

vector<unsigned int> Parent;
unsigned int queries;

// Sliding Window Minimum
void swm(vector<int> & elements, const int winsize){
  deque< pair<int, int> > window;
  int fb = 0; // first buffer
  for(int i = 0; i < elements.size() ; i++){
    while(!window.empty() && window.back().first >= elements[i] ){
      window.pop_back();
    }
    window.push_back(make_pair(elements[i], i));

    while(window.front().second <= i - winsize){
      window.pop_front();
    }
    fb++;
    if(fb >= winsize){
      printf("%d" , window.front().first);
      if(i < elements.size()-1){
        printf(" ");
      }
    }
  }
  printf("\n");
}

void ass(vector<int> v){
  int i = 0;
  for(const auto& e: v){
    printf("[%d]=%d\n" ,i ,e );
    i++;
  }
}

int main(){
	int N, L;
  scanf("%d %d" ,&N, &L);
  vector<int> elements(N);
  for(int i = 0 ; i < N; i++){
    int v;
    scanf("%d" ,&v );
		elements[i] = v;
  }
  swm(elements, L);
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.

A Bitlandish string is a string made only of characters "0" and "1".

BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.

The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.

So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.

You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations.

Input

The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths.

It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106.

Output

Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes.

Examples

Input

11
10

Output

YES

Input

1
01

Output

NO

Input

000
101

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double eps = 1E-8;
char s1[1000001], s2[1000001];
bool solve() {
  if (scanf("%s%s", s1, s2) == EOF) return false;
  bool e1 = false, e2 = false;
  int n1, n2;
  for (n1 = 0; s1[n1]; ++n1) e1 = e1 || s1[n1] == '1';
  for (n2 = 0; s2[n2]; ++n2) e2 = e2 || s2[n2] == '1';
  printf("%s\n", (e1 == e2 && n1 == n2) ? "YES" : "NO");
  return true;
}
int main() { solve(); }

```


### Prompt

Develop a solution in CPP to the problem described below:

You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.

A rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.

Input

The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).

Output

Print a single integer — the answer to a problem.

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

Examples

Input

10
12345

Output

6

Input

16
439873893693495623498263984765

Output

40

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void inout() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
}
int main() {
  inout();
  long long a, n, i, ans = 0, j;
  string second;
  cin >> a >> second;
  n = second.size();
  vector<long long> x;
  map<long long, long long> make_pair;
  for (auto c : second) x.push_back(c - '0');
  partial_sum(x.begin(), x.end(), x.begin());
  x.insert(x.begin(), 0);
  for (i = 1; i <= n; i++)
    for (j = i; j <= n; j++) make_pair[x[j] - x[i - 1]]++;
  for (i = 1; i <= n; i++)
    for (j = i; j <= n; j++) {
      if (x[j] == x[i - 1]) {
        if (!a) ans += ((n * (n + 1)) / 2);
      } else if (a % (x[j] - x[i - 1]))
        continue;
      else
        ans += make_pair[a / (x[j] - x[i - 1])];
    }
  cout << ans;
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the hardest. Limak knows it will take him 5·i minutes to solve the i-th problem.

Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs k minutes to get there from his house, where he will participate in the contest first.

How many problems can Limak solve if he wants to make it to the party?

Input

The only line of the input contains two integers n and k (1 ≤ n ≤ 10, 1 ≤ k ≤ 240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.

Output

Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.

Examples

Input

3 222

Output

2

Input

4 190

Output

4

Input

7 1

Output

7

Note

In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.

In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.

In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i, s, res, c;
  while (cin >> n >> k) {
    res = 240 - k, s = 0, c = 0;
    for (i = 1; i <= n; i++) {
      s += 5 * i;
      if (s > res) break;
      c = c + 1;
    }
    cout << c << endl;
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every a and b such that 1 ≤ a ≤ b ≤ 6, there is exactly one domino with a dots on one half and b dots on the other half. The set contains exactly 21 dominoes. Here is an exact illustration of his set:

<image>

Also, Anadi has an undirected graph without self-loops and multiple edges. He wants to choose some dominoes and place them on the edges of this graph. He can use at most one domino of each type. Each edge can fit at most one domino. It's not necessary to place a domino on each edge of the graph.

When placing a domino on an edge, he also chooses its direction. In other words, one half of any placed domino must be directed toward one of the endpoints of the edge and the other half must be directed toward the other endpoint. There's a catch: if there are multiple halves of dominoes directed toward the same vertex, each of these halves must contain the same number of dots.

How many dominoes at most can Anadi place on the edges of his graph?

Input

The first line contains two integers n and m (1 ≤ n ≤ 7, 0 ≤ m ≤ (n⋅(n-1))/(2)) — the number of vertices and the number of edges in the graph.

The next m lines contain two integers each. Integers in the i-th line are a_i and b_i (1 ≤ a, b ≤ n, a ≠ b) and denote that there is an edge which connects vertices a_i and b_i.

The graph might be disconnected. It's however guaranteed that the graph doesn't contain any self-loops, and that there is at most one edge between any pair of vertices.

Output

Output one integer which denotes the maximum number of dominoes which Anadi can place on the edges of the graph.

Examples

Input

4 4
1 2
2 3
3 4
4 1

Output

4

Input

7 0

Output

0

Input

3 1
1 3

Output

1

Input

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

Output

16

Note

Here is an illustration of Anadi's graph from the first sample test:

<image>

And here is one of the ways to place a domino on each of its edges:

<image>

Note that each vertex is faced by the halves of dominoes with the same number of dots. For instance, all halves directed toward vertex 1 have three dots.

### Response

```cpp
#include <bits/stdc++.h>
const int MAXN = 10;
std::pair<int, int> edge[MAXN * MAXN];
int node[MAXN], n, ans, m;
bool vis[MAXN * MAXN];
void dfs(int x) {
  if (x == n + 1) {
    int cnt = 0;
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= m; i++) {
      int a = node[edge[i].first], b = node[edge[i].second];
      if (a < b) std::swap(a, b);
      a = a * 8 + b;
      if (!vis[a]) cnt++, vis[a] = 1;
    }
    ans = std::max(ans, cnt);
  } else {
    for (int i = 1; i <= 6; i++) {
      node[x] = i;
      dfs(x + 1);
    }
  }
}
int main(int argc, char *argv[]) {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &edge[i].first, &edge[i].second);
  }
  dfs(1);
  printf("%d", ans);
  return 0;
}

```


### Prompt

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

Surely you have seen insane videos by South Korean rapper PSY, such as "Gangnam Style", "Gentleman" and "Daddy". You might also hear that PSY has been recording video "Oppa Funcan Style" two years ago (unfortunately we couldn't find it on the internet). We will remind you what this hit looked like (you can find original description [here](http://acm.timus.ru/problem.aspx?space=1&num=2107&locale=en)):

On the ground there are n platforms, which are numbered with integers from 1 to n, on i-th platform there is a dancer with number i. Further, every second all the dancers standing on the platform with number i jump to the platform with the number f(i). The moving rule f is selected in advance and is not changed throughout the clip.

The duration of the clip was k seconds and the rule f was chosen in such a way that after k seconds all dancers were in their initial positions (i.e. the i-th dancer stood on the platform with the number i). That allowed to loop the clip and collect even more likes.

PSY knows that enhanced versions of old artworks become more and more popular every day. So he decided to release a remastered-version of his video.

In his case "enhanced version" means even more insanity, so the number of platforms can be up to 10^{18}! But the video director said that if some dancer stays on the same platform all the time, then the viewer will get bored and will turn off the video immediately. Therefore, for all x from 1 to n f(x) ≠ x must hold.

Big part of classic video's success was in that looping, so in the remastered version all dancers should return to their initial positions in the end of the clip as well.

PSY hasn't decided on the exact number of platforms and video duration yet, so he asks you to check if there is a good rule f for different options.

Input

In the first line of input there is one integer t (1 ≤ t ≤ 10^{4}) — the number of options for n and k to check.

In the next t lines the options are given: each option is described with two integers n and k (1 ≤ n ≤ 10^{18}, 1 ≤ k ≤ 10^{15}) — the number of dancers and the duration in seconds.

It is guaranteed that the number of different values of k in one test is not greater than 50.

Output

Print t lines. If the i-th option of the video is feasible, print "YES" (without quotes) in i-th line, otherwise print "NO" (without quotes).

Example

Input

3
7 7
3 8
5 6

Output

YES
NO
YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const int N = 1e5 + 5;
const long long INF = (long long)2e18;
template <class T>
inline void read(T &x) {
  x = 0;
  int c = getchar(), f = 1;
  for (; !isdigit(c); c = getchar())
    if (c == 45) f = -1;
  for (; isdigit(c); c = getchar()) (x *= 10) += f * (c - '0');
}
vector<int> pl, spf;
int _;
map<long long, vector<pair<long long, int>>> mapchik;
long long dis[N];
bool ans[N];
void exgcd(long long a, long long b, long long &g, long long &x, long long &y) {
  if (!b)
    g = a, x = 1, y = 0;
  else {
    exgcd(b, a % b, g, y, x);
    y -= x * (a / b);
  }
}
void fast_sieve(int n) {
  pl.clear();
  spf.assign(n, 0);
  for (int i = 2; i < n; ++i) {
    if (!spf[i]) {
      pl.push_back(i);
      spf[i] = i;
    }
    for (int j = 0; j < ((int)(pl).size()) && i * pl[j] < n; ++j) {
      int p = pl[j];
      spf[i * p] = p;
      if (i % p == 0) break;
    }
  }
}
vector<long long> factorize(long long n) {
  vector<long long> u;
  for (int i = 0, t = sqrt(n + 1); pl[i] <= t; ++i)
    if (n % pl[i] == 0) {
      u.push_back(pl[i]);
      while (n % pl[i] == 0) n /= pl[i];
      t = sqrt(n + 1);
    }
  if (n > 1) u.push_back(n);
  return u;
}
void solve(long long k, vector<pair<long long, int>> queries) {
  vector<long long> p = factorize(k);
  int n = ((int)(p).size());
  if (n == 0) return;
  if (n == 1) {
    for (auto &q : queries) ans[q.second] = q.first % p[0] == 0;
    return;
  }
  if (n == 2) {
    long long a = p[1], b = p[0], g, x, y;
    exgcd(a, b, g, x, y);
    for (auto &q : queries)
      ans[q.second] = (((x % b * (q.first % b) % b + b) % b) * a) <= q.first;
    return;
  }
  for (int i = 0; i < p[0]; ++i) dis[i] = INF;
  dis[0] = 0;
  set<pair<long long, int>> pq;
  for (int i = 0; i < p[0]; ++i) pq.insert(make_pair(dis[i], i));
  while (!pq.empty()) {
    int u = (*pq.begin()).second;
    pq.erase(pq.begin());
    for (int i = 1; i < n; ++i) {
      int v = (u + p[i]) % p[0];
      long long w = dis[u] + p[i];
      if (w >= dis[v]) continue;
      pq.erase(make_pair(dis[v], v));
      dis[v] = w;
      pq.insert(make_pair(dis[v], v));
    }
  }
  for (auto &q : queries) ans[q.second] = dis[q.first % p[0]] <= q.first;
}
int main() {
  fast_sieve((int)35e6 + 5);
  read(_);
  for (int i = 0; i < _; ++i) {
    long long n, k;
    read(n);
    read(k);
    mapchik[k].push_back(make_pair(n, i));
  }
  for (auto &it : mapchik) solve(it.first, it.second);
  for (int i = 0; i < _; ++i)
    if (ans[i])
      puts("YES");
    else
      puts("NO");
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Write a program which reads a word W and a text T, and prints the number of word W which appears in text T

T consists of string Ti separated by space characters and newlines. Count the number of Ti which equals to W. The word and text are case insensitive.

Constraints

* The length of W ≤ 10
* W consists of lower case letters
* The length of T in a line ≤ 1000

Input

In the first line, the word W is given. In the following lines, the text T is given separated by space characters and newlines.

"END_OF_TEXT" indicates the end of the text.

Output

Print the number of W in the text.

Example

Input

computer
Nurtures computer scientists and highly-skilled computer engineers
who will create and exploit "knowledge" for the new era.
Provides an outstanding computer environment.
END_OF_TEXT

Output

3

### Response

```cpp
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	string W;
	cin >> W;
	string T;
	int num = 0;
	while(true){
		cin >> T;
		if(T == "END_OF_TEXT") break;
		transform(T.begin(), T.end(), T.begin(), ::tolower);
		if(T == W) ++num;
	}
	cout << num << endl;
	return 0;
}
```


### Prompt

Construct a cpp code solution to the problem outlined:

In 20XX, many years of research have paid off, and wireless energy transmission and reception technology has been put into practical use. By using this technology, it has become possible to supply power to depopulated areas where it was not possible to draw power lines because the cost was not worth it. This technology has some quirks and can send energy as far as it can go, but it has the limitation that it can only receive radio waves at specific locations. In other words, if the world is represented by a two-dimensional plane, the positive direction of the y-axis is north, and the positive direction of the x-axis is east, radio waves can be received only at points where both the x-coordinate and y-coordinate are integers (phase). It's a problem). In addition, radio waves can only be transmitted in eight directions (east, west, south, north, northeast, northwest, southeast, and southwest) when viewed from the base (equipment capable of transmitting and receiving radio waves).

Due to this restriction, it may not be possible to directly supply radio waves to the target location, but this can be solved by setting up a relay station. For example, energy cannot be sent directly from coordinates (0, 0) to (3, 7), but this can be solved by placing a relay station at (3, 3).

You are an engineer at an electric power company, and a customer asks you to set up a base in a certain place. However, in order to avoid the problem that the power stops just because a certain part breaks down, when laying a new base, it is necessary to receive energy from two or more bases that have already been built. Also, only one base can be built at a time, and two bases cannot be placed in the same location. Given two existing base locations, ask for at least how many more bases need to be built to meet customer demand.

Input

The input consists of multiple datasets.

The first line of input is given the number of datasets N (0 <N ≤ 300). Each dataset is given in the following N lines.

One dataset consists of one line of strings, given six integers separated by spaces as shown below.

x1 y1 x2 y2 X Y

(x1, y1) and (x2, y2) are the coordinates of the two existing bases, and (X, Y) are the coordinates of the destination. The x, y coordinate values given by the input satisfy -100000000 ≤ x, y ≤ 100000000. The coordinates of the two existing bases are guaranteed to be different.

Output

For each dataset, output the number of bases that need to be laid in one line.

Example

Input

4
0 1 3 2 0 1
1 1 2 2 9 9
0 0 1 4 5 5
0 0 1 4 5 10

Output

0
1
2
3

### Response

```cpp
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

using ld= long double;
ld eps=1e-9;

/* 幾何の基本 */

#include <complex>

typedef complex<ld> Point;

// 外積
ld cross(const Point& a, const Point& b) {
	return imag(conj(a) * b);
}

// 直線の定義
class Line {
public:
	Point a, b;
	Line() : a(Point(0, 0)), b(Point(0, 0)) {}
	Line(Point a, Point b) : a(a), b(b) {}
	Point operator[](const int _num)const {
		if (_num == 0)return a;
		else if (_num == 1)return b;
		else {
			assert(false);
			return Point();
		}
	}
};

// 直線と直線の交点
Point is_ll(const Line &s, const Line& t) {
	Point sv = s.b - s.a, tv = t.b - t.a;
	assert(cross(sv, tv) != 0);
	return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}

bool connect(pair<long long int, long long int>l, pair<long long int,long long  int>r) {
	long long int dx=r.first-l.first;
	long long int dy=r.second-l.second;
	if (!dx || !dy || abs(dx) == abs(dy)) {
		return true;
	}
	else {
		return false;
	}
}

vector<pair<long long int, long long int>>kouhos(pair<long long int, long long int>l, pair<long long int, long long int>r) {

	vector<pair<long long int, long long int>>kouho;
	int dx[4] = { 1,1,1,0 };
	int dy[4] = { -1,0,1,1 };
	for (int way1 = 0; way1 < 4; ++way1) {
		for (int way2 = 0; way2 < 4; ++way2) {
			if(way1==way2)continue;
			Point p1(l.first,l.second);
			Line l1(p1,p1+Point(dx[way1],dy[way1]));
			Point p2(r.first,r.second);
			Line l2(p2,p2+Point(dx[way2],dy[way2]));
			Point sect(is_ll(l1,l2));
			long long int n=static_cast<long long int>(sect.real()+eps*100);
			if (abs(static_cast<long long int>(sect.real()+eps*100) - sect.real()) < 0.1) {
				kouho.push_back(make_pair(static_cast<long long int>(sect.real()+eps*100), static_cast<long long int>(sect.imag()+eps*100)));
			}
		}
	}
	return kouho;
}

int solve(vector<pair<long long int, long long int>>&bases, const pair<long long int, long long  int>&goal) {
	if(bases.size()==6)return 4;

	int ans=4;
	for (int i = 0; i < bases.size(); ++i) {
		if (bases[i] == goal) {
			ans=min(ans,int(bases.size())-2);
		}
		if (connect(bases[i], goal)) {
			ans=min(ans,int(bases.size())-2+2);
		}
		if(bases.size()==5)continue;
		for (int j = 0; j < bases.size(); ++j) {
			if(i==j)continue;
			pair<long long int, long long int>l(bases[i]);
			pair<long long int, long long int>r(bases[j]);
			if (connect(l, goal) && connect(r, goal)) {
				ans=min(ans,int(bases.size()-2+1));
			}
			if (connect(l, r)) {
				ans=min(ans,int(bases.size())-2+3);
			}
			else {
				if (bases.size() == 2) {
					auto cands(kouhos(l, r));
					for (auto cand : cands) {
						if (connect(cand, goal)) {
							ans=min(ans,3);
						}
					}
				}

			}
		}
	}
	return ans;
}
int main() {
	int Q;cin>>Q;
	while (Q--) {
		long long int x1,y1,x2,y2,X,Y;cin>>x1>>y1>>x2>>y2>>X>>Y;
		x1+=1e10;
		y1+=1e10;
		x2+=1e10;
		y2+=1e10;
		X+=1e10;
		Y+=1e10;
		vector<pair<long long int, long long int>>bases{ make_pair(x1,y1),make_pair(x2,y2) };
		pair<long long int, long long int>goal(X,Y);
		int ans=solve(bases,goal);
		cout<<ans<<endl;
	}
	return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for the agricultural equipment in the warehouse.

He's got problems with some particularly large piece of equipment, which is, of course, turboplows. The problem is that when a turboplow is stored, it takes up not some simply rectangular space. It takes up a T-shaped space like on one of the four pictures below (here character "#" stands for the space occupied by the turboplow and character "." stands for the free space):

    ###      ..#      .#.      #..
    .#.      ###      .#.      ###
    .#.      ..#      ###      #..

Simon faced a quite natural challenge: placing in the given n × m cells warehouse the maximum number of turboplows. As one stores the turboplows, he can rotate them in any manner (so that they take up the space like on one of the four pictures above). However, two turboplows cannot "overlap", that is, they cannot share the same cell in the warehouse.

Simon feels that he alone cannot find the optimal way of positioning the plugs in the warehouse that would maximize their quantity. Can you help him?

Input

The only line contains two space-separated integers n and m — the sizes of the warehouse (1 ≤ n, m ≤ 9).

Output

In the first line print the maximum number of turboplows that can be positioned in the warehouse. In each of the next n lines print m characters. Use "." (dot) to mark empty space and use successive capital Latin letters ("A" for the first turboplow, "B" for the second one and so on until you reach the number of turboplows in your scheme) to mark place for the corresponding turboplows considering that they are positioned in the optimal manner in the warehouse. The order in which you number places for the turboplows does not matter. If there are several optimal solutions for a warehouse of the given size, print any of them.

Examples

Input

3 3

Output

1
AAA
.A.
.A.

Input

5 6

Output

4
A..C..
AAAC..
ABCCCD
.B.DDD
BBB..D

Input

2 2

Output

0
..
..

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char mymap[10][10], best[10][10];
int ans = -1, n, m;
bool shape[4][3][3] = {{{1, 1, 1}, {0, 1, 0}, {0, 1, 0}},
                       {{0, 1, 0}, {0, 1, 0}, {1, 1, 1}},
                       {{1, 0, 0}, {1, 1, 1}, {1, 0, 0}},
                       {{0, 0, 1}, {1, 1, 1}, {0, 0, 1}}};
bool valid(int x, int y, int k) {
  if (x < 0 || x + 2 > n - 1 || y < 0 || y + 2 > m - 1) return false;
  for (int i = 0; i <= 2; i++)
    for (int j = 0; j <= 2; j++) {
      if (shape[k][i][j] && mymap[x + i][y + j] != '.') return false;
    }
  return true;
}
void mtx_insert(int x, int y, int type, int k) {
  for (int i = 0; i <= 2; ++i)
    for (int j = 0; j <= 2; ++j) {
      if (shape[k][i][j]) mymap[x + i][y + j] = 'A' + type;
    };
};
void mtx_clear(int x, int y, int type) {
  int i, j;
  for (i = x; i <= x + 2; i++) {
    for (j = y; j <= y + 2; j++) {
      if (mymap[i][j] == 'A' + type) mymap[i][j] = '.';
    };
  };
};
void mtx_copy() {
  int i, j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      best[i][j] = mymap[i][j];
    };
  };
}
void mtx(int x, int y, int type) {
  int i, j, ort;
  if (type + ((n - x - 2) * m + m - y - 1) / 5 <= ans) return;
  if (x == n) return;
  for (i = x; i < n; i++) {
    for (j = (i == x ? y : 0); j < m; j++) {
      for (ort = 0; ort < 4; ort++) {
        if (valid(i, j, ort)) {
          mtx_insert(i, j, type, ort);
          if (j < m - 1)
            mtx(i, j + 1, type + 1);
          else
            mtx(i + 1, 0, type + 1);
          mtx_clear(i, j, type);
        };
      };
    };
  };
  if (type > ans) {
    mtx_copy();
    ans = type;
  };
}
int main() {
  int i, j;
  scanf(" %d %d", &n, &m);
  for (i = 0; i < n; i++) {
    fill_n(mymap[i], m, '.');
    fill_n(best[i], m, '.');
  };
  mtx(0, 0, 0);
  printf("%d\n", ans);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      printf("%c", best[i][j]);
    };
    printf("\n");
  };
  return 0;
};

```


### Prompt

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

A permutation of length n is an array p=[p_1,p_2,...,p_n], which contains every integer from 1 to n (inclusive) and, moreover, each number appears exactly once. For example, p=[3,1,4,2,5] is a permutation of length 5.

For a given number n (n ≥ 2), find a permutation p in which absolute difference (that is, the absolute value of difference) of any two neighboring (adjacent) elements is between 2 and 4, inclusive. Formally, find such permutation p that 2 ≤ |p_i - p_{i+1}| ≤ 4 for each i (1 ≤ i < n).

Print any such permutation for the given integer n or determine that it does not exist.

Input

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

Each test case is described by a single line containing an integer n (2 ≤ n ≤ 1000).

Output

Print t lines. Print a permutation that meets the given requirements. If there are several such permutations, then print any of them. If no such permutation exists, print -1.

Example

Input

6
10
2
4
6
7
13

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    if (n < 4) {
      cout << -1 << endl;
      continue;
    }
    for (int i = n; i >= 1; --i) {
      if (i & 1) cout << i << " ";
    }
    cout << 4 << " " << 2 << " ";
    for (int i = 6; i <= n; i += 2) {
      cout << i << " ";
    }
    cout << endl;
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

You have a description of a lever as string s. We'll represent the string length as record |s|, then the lever looks as a horizontal bar with weights of length |s| - 1 with exactly one pivot. We will assume that the bar is a segment on the Ox axis between points 0 and |s| - 1.

The decoding of the lever description is given below.

  * If the i-th character of the string equals "^", that means that at coordinate i there is the pivot under the bar.
  * If the i-th character of the string equals "=", that means that at coordinate i there is nothing lying on the bar.
  * If the i-th character of the string equals digit c (1-9), that means that at coordinate i there is a weight of mass c on the bar.

Your task is, given the lever description, print if it will be in balance or not. Assume that the bar doesn't weight anything. Assume that the bar initially is in balance then all weights are simultaneously put on it. After that the bar either tilts to the left, or tilts to the right, or is in balance.

Input

The first line contains the lever description as a non-empty string s (3 ≤ |s| ≤ 106), consisting of digits (1-9) and characters "^" and "=". It is guaranteed that the line contains exactly one character "^". It is guaranteed that the pivot of the lever isn't located in any end of the lever bar.

To solve the problem you may need 64-bit integer numbers. Please, do not forget to use them in your programs.

Output

Print "left" if the given lever tilts to the left, "right" if it tilts to the right and "balance", if it is in balance.

Examples

Input

=^==

Output

balance

Input

9===^==1

Output

left

Input

2==^7==

Output

right

Input

41^52==

Output

balance

Note

As you solve the problem, you may find the following link useful to better understand how a lever functions: http://en.wikipedia.org/wiki/Lever.

The pictures to the examples:

<image> <image> <image> <image>

### Response

```cpp
#include <bits/stdc++.h>
char s[1000006];
int main() {
  long long int i, n, l, r, c, x;
  scanf("%s", s);
  n = strlen(s);
  for (i = 0; i < n; i++) {
    if (s[i] == '^') {
      x = i;
      break;
    }
  }
  c = 0;
  l = 0;
  for (i = x - 1; i >= 0; i--) {
    c++;
    if (s[i] >= '0' && s[i] <= '9') l = l + c * (s[i] - '0');
  }
  c = 0;
  r = 0;
  for (i = x + 1; i < n; i++) {
    c++;
    if (s[i] >= '0' && s[i] <= '9') r = r + c * (s[i] - '0');
  }
  if (l > r)
    printf("left");
  else if (r > l)
    printf("right");
  else
    printf("balance");
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Given an integer x. Your task is to find out how many positive integers n (1 ≤ n ≤ x) satisfy $$$n ⋅ a^n ≡ b   (mod\;p), where a, b, p$$$ are all known constants.

Input

The only line contains four integers a,b,p,x (2 ≤ p ≤ 10^6+3, 1 ≤ a,b < p, 1 ≤ x ≤ 10^{12}). It is guaranteed that p is a prime.

Output

Print a single integer: the number of possible answers n.

Examples

Input

2 3 5 8

Output

2

Input

4 6 7 13

Output

1

Input

233 233 10007 1

Output

1

Note

In the first sample, we can see that n=2 and n=8 are possible answers.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long m) {
  long long x = 1 % m;
  a %= m;
  while (b) {
    if ((1 & b)) x = x * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return x;
}
vector<long long> sol[1000005];
int main() {
  long long a, b, p, x;
  cin >> a >> b >> p >> x;
  long long aa = 1;
  for (int q = 0; q < p - 1; q++) {
    sol[aa].push_back(q);
    aa = aa * a % p;
  }
  long long ans = 0;
  for (long long k = 1; k < p; k++) {
    if (k > x) break;
    long long d = b * power(k * power(a, k, p), p - 2, p) % p;
    if (sol[d].empty() == true) continue;
    long long lim = (x - k) / p;
    ans += ((int)sol[d].size()) * 1LL * (lim / (p - 1));
    long long upto = lim % (p - 1);
    ans += upper_bound(sol[d].begin(), sol[d].end(), upto) - sol[d].begin();
  }
  printf("%lld\n", ans);
}

```


### Prompt

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

Problem Statement

Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and always tries to save as much paper as possible. She decided to play a ghost leg with other participants to decide the team for the Aizu training camp.

How to make Amidakuji for this training camp is as follows. First, write N vertical bars in parallel on the paper. Then, write the M horizontal bars in order from the top so that they are perpendicular to the vertical bars and the heights of the horizontal bars are all different. For example, the Amida of Sample Input 1 is as shown in Fig. 1.

Here, Mr. Takatsuki, a little dissatisfied expression. It's a waste of paper to write a ghost leg so vertically. You should be able to compress the height more. So, I want her to solve the problem of height compression of Amidakuji shown below.

First, the height of the Amidakuji is the value obtained by counting the horizontal bars that exist at the same height together as the height 1 and counting this to the bottom horizontal bar. Here, it is assumed that each horizontal bar can be freely moved up and down in order to perform height compression. However, it is not permissible to remove or add horizontal bars. The Amidakuji after height compression must meet the following conditions.

* The end points of the horizontal bar do not touch the end points of other horizontal bars.
* The result of tracing the Amidakuji after compression and the result of tracing the Amidakuji before compression match.

FIG. 2 is a compressed version of FIG. The "horizontal bar connecting vertical bars 1 and 2" moves to the top and becomes the same height as the "horizontal bar connecting vertical bars 4 and 5", and these two are height 1. After that, the "horizontal bar connecting the vertical bars 3 and 4" and the "horizontal bar connecting the vertical bars 2 and 3" have different heights, and the total height is 3.

<image>

Compress the height of the given Amidakuji and output the compressed height.

Constraints

* 2 <= N <= 8
* 1 <= M <= 8
* 1 <= ai <= N --1

Input

Each data set is input in the following format.

N M
a1
a2
...
aM

All inputs are integers. N indicates the number of vertical bars and M indicates the number of horizontal bars. Then, the information of the horizontal bar is input over M lines. ai indicates that the i-th horizontal bar connects the vertical bar ai and the vertical bar to the right of it. The i-th horizontal bar exists above the i + 1-th horizontal bar.

Output

Outputs the height of the compressed Amidakuji in one line.

Examples

Input

5 4
4
3
1
2

Output

3

Input

4 3
1
2
3

Output

3

### Response

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

signed main(){

  int n,m; cin >> n >> m;
  vector<int> a(m);
  vector<int> result(n);
  for(int i = 0; i < n; i++) result[i] = i;
  for(int i = 0; i < m; i++){
    cin >> a[i];
    a[i]--;
    swap(result[a[i]],result[a[i]+1]);
  }
  sort(a.begin(),a.end());

  int ans = m;
  do{
    vector<int> perm(n);
    for(int i = 0; i < n; i++) perm[i] = i;
    for(int i = 0; i < m; i++){
      swap(perm[a[i]],perm[a[i]+1]);
    }
    if(perm == result){
      vector<int> h(n,0);
      int res = 0;
      for(int i = 0; i < m; i++){
        h[a[i]] = h[a[i]+1] = max(h[a[i]]+1,h[a[i]+1]+1);
        res = max(res,h[a[i]]);
      }
      ans = min(ans,res);
    }
  }while(next_permutation(a.begin(),a.end()));
  cout << ans << endl;

  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

It’s still hot every day, but September has already come. It’s autumn according to the calendar. Looking around, I see two red dragonflies at rest on the wall in front of me. It’s autumn indeed.

When two red dragonflies’ positional information as measured from the end of the wall is given, make a program to calculate the distance between their heads.

Input

The input is given in the following format.

$x_1$ $x_2$

The input line provides dragonflies’ head positions $x_1$ and $x_2$ ($0 \leq x_1, x_2 \leq 100$) as integers.

Output

Output the distance between the two red dragonflies in a line.

Examples

Input

20 30

Output

10

Input

50 25

Output

25

Input

25 25

Output

0

### Response

```cpp
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(a) a, a+sizeof(a)/sizeof(a[0])
using namespace std;
ll gcd(ll n, ll m) {
	if (m == 0) return n;
	return gcd(m, n % m);
}

ll lcm(ll n, ll m) {
	return m / gcd(n, m) * n;
}

int main(void) {
	int x1,x2;
	cin >> x1 >> x2;
	cout << abs(x1-x2) << endl;
	return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You want to make change for $ n $ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and / or 25 cents coins respectively, find the minimum number of coins you need.

Constraints

* $ 1 \ le n \ le 10 ^ 9 $

Input

$ n $

The integer $ n $ is given in a line.

output

Print the minimum number of coins you need in a line.

Examples

Input

100

Output

4

Input

54321

Output

2175

### Response

```cpp
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int s=0;
    while(true){
        if(n<25)    break;
        else{
            n=n-25;
            s=s+1;
        }
    }
    while(true){
        if(n<10)    break;
        else{
            n=n-10;
            s=s+1;
        }
    }
    while(true){
        if(n<5)    break;
        else{
            n=n-5;
            s=s+1;
        }
    }
    s=s+n;
    cout<<s;
    cout<<endl;
}

```


### Prompt

Generate a CPP solution to the following problem:

The Berland road network consists of n cities and of m bidirectional roads. The cities are numbered from 1 to n, where the main capital city has number n, and the culture capital — number 1. The road network is set up so that it is possible to reach any city from any other one by the roads. Moving on each road in any direction takes the same time.

All residents of Berland are very lazy people, and so when they want to get from city v to city u, they always choose one of the shortest paths (no matter which one).

The Berland government wants to make this country's road network safer. For that, it is going to put a police station in one city. The police station has a rather strange property: when a citizen of Berland is driving along the road with a police station at one end of it, the citizen drives more carefully, so all such roads are considered safe. The roads, both ends of which differ from the city with the police station, are dangerous.

Now the government wonders where to put the police station so that the average number of safe roads for all the shortest paths from the cultural capital to the main capital would take the maximum value.

Input

The first input line contains two integers n and m (2 ≤ n ≤ 100, <image>) — the number of cities and the number of roads in Berland, correspondingly. Next m lines contain pairs of integers vi, ui (1 ≤ vi, ui ≤ n, vi ≠ ui) — the numbers of cities that are connected by the i-th road. The numbers on a line are separated by a space.

It is guaranteed that each pair of cities is connected with no more than one road and that it is possible to get from any city to any other one along Berland roads.

Output

Print the maximum possible value of the average number of safe roads among all shortest paths from the culture capital to the main one. The answer will be considered valid if its absolute or relative inaccuracy does not exceed 10 - 6.

Examples

Input

4 4
1 2
2 4
1 3
3 4

Output

1.000000000000

Input

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

Output

1.714285714286

Note

In the first sample you can put a police station in one of the capitals, then each path will have exactly one safe road. If we place the station not in the capital, then the average number of safe roads will also make <image>.

In the second sample we can obtain the maximum sought value if we put the station in city 4, then 6 paths will have 2 safe roads each, and one path will have 0 safe roads, so the answer will equal <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 103;
int n, m, d[N], used[N], dist[N];
long long dp[N], f[N];
vector<int> adj[N];
void bfs(int v) {
  memset(&d, 0, sizeof(d));
  memset(&dp, 0, sizeof(dp));
  memset(&used, 0, sizeof(used));
  queue<int> q;
  q.push(v);
  dp[v] = 1;
  used[v] = 1;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int to : adj[cur]) {
      if (!used[to]) {
        d[to] = d[cur] + 1;
        q.push(to);
        used[to] = 1;
      }
      if (d[to] == d[cur] + 1) {
        dp[to] += dp[cur];
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  cin >> n >> m;
  int x, y;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  bfs(1);
  for (int i = 1; i <= n; i++) {
    f[i] = dp[i];
    dist[i] = d[i];
  }
  bfs(n);
  long double ans = 0;
  for (int i = 1; i <= n; i++) {
    if (dist[i] + d[i] > d[1]) {
      continue;
    }
    long double tmp = f[i] * dp[i];
    tmp /= f[n];
    if (i != 1 && i != n) {
      tmp *= 2;
    }
    ans = max(ans, tmp);
  }
  cout << setprecision(30) << ans;
}

```


### Prompt

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

The Smart Beaver from ABBYY has a lot of hobbies. One of them is constructing efficient hash tables. One of the most serious problems in hash tables is resolving collisions. The Beaver is interested in this problem very much and he decided to explore it in detail.

We assume that the hash table consists of h cells numbered from 0 to h - 1. Objects are added to and removed from it. Every object has its own unique identifier. In addition, every object has a corresponding hash value — an integer between 0 and h - 1, inclusive. When an object is added to the table, if the cell corresponding to the hash value of the object is free, then this object goes there. If the cell is already occupied by another object, there is a collision. When an object is deleted from the table, the cell which it occupied becomes empty.

The Smart Beaver has recently learned about the method of linear probing to resolve collisions. It is as follows. Let's say that the hash value for the added object equals t and cell t of the table is already occupied. Then we try to add this object to cell (t + m) mod h. If it is also occupied, then we try cell (t + 2·m) mod h, then cell (t + 3·m) mod h, and so on. Note that in some cases it's possible that the new object can not be added to the table. It is guaranteed that the input for this problem doesn't contain such situations.

The operation a mod b means that we take the remainder of the division of number a by number b.

This technique immediately seemed very inoptimal to the Beaver, and he decided to assess its inefficiency. So, you are given a sequence of operations, each of which is either an addition of an object to the table or a deletion of an object from the table. When adding a new object, a sequence of calls to the table is performed. Calls to occupied cells are called dummy. In other words, if the result of the algorithm described above is the object being added to cell (t + i·m) mod h (i ≥ 0), then exactly i dummy calls have been performed.

Your task is to calculate the total number of dummy calls to the table for the given sequence of additions and deletions. When an object is deleted from the table, assume that no dummy calls are performed. The table is empty before performing the operations, that is, initially it doesn't contain any objects.

Input

The first line of input contains three integers h, m and n (1 ≤ m < h), separated by spaces, where h is the size of the hash table, m is the number that is used to resolve collisions, n is the number of operations.

The following n lines contains the descriptions of the operations. Their execution order corresponds to the order in which they appear in the input file. Each operation is described by a single line. The operations are described as follows:

  * "+ id hash"

This is the format of the operation that adds an object to the table. The first character is "+" (ASCII 43), followed by a single space, then the object identifier id (0 ≤ id ≤ 109), then another space, and the hash value of the given object hash (0 ≤ hash < h). The object identifier and the hash value of this object are integers.

  * "- id"

This is the format of the operation that deletes an object from the table. The first character is "-" (ASCII 45), followed by a single space, then the object identifier id (0 ≤ id ≤ 109). The object identifier is an integer.

It is guaranteed that for all addition operations the value of id is unique. It is also guaranteed that the initial data is correct, that is, it's always possible to add an object to the hash table and there won't be any deletions of nonexisting objects.

The input limitations for getting 20 points are:

  * 1 ≤ h ≤ 5000
  * 1 ≤ n ≤ 5000

The input limitations for getting 50 points are:

  * 1 ≤ h ≤ 5·104
  * 1 ≤ n ≤ 5·104

The input limitations for getting 100 points are:

  * 1 ≤ h ≤ 2·105
  * 1 ≤ n ≤ 2·105

Output

Print a single number — the total number of dummy calls to the hash table.

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

Examples

Input

10 2 7
+ 11 0
+ 22 2
+ 33 6
+ 44 0
+ 55 0
- 22
+ 66 0

Output

7

Input

5 1 6
+ 123 0
+ 234 1
+ 345 2
- 234
+ 456 0
+ 567 0

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int M;
int* T[200000];
int query(int* T, int l, int r) {
  if (l == r) return T[M + l];
  l += M;
  r += M;
  int res = T[l] + T[r];
  while (l / 2 != r / 2) {
    if (l % 2 == 0) res += T[l + 1];
    if (r % 2 == 1) res += T[r - 1];
    l /= 2;
    r /= 2;
  }
  return res;
}
void update(int* T, int a, int v) {
  int a0 = a;
  a += M;
  while (a > 0) {
    T[a] += v;
    a /= 2;
  }
}
bool allOccupied(int* T, int a, int b) { return query(T, a, b) == (b - a + 1); }
long long dummy = 0;
int A, B;
int add(pair<int, int> where) {
  int* U = T[where.first];
  int X = where.second;
  if (allOccupied(U, X, B - 1)) {
    int a = 0, b = X - 1;
    while (a < b) {
      int s = (a + b) / 2;
      if (allOccupied(U, 0, s))
        a = s + 1;
      else
        b = s;
    }
    update(U, a, 1);
    dummy += (B - X) + a;
    return a;
  } else {
    int a = X, b = B - 1;
    while (a < b) {
      int s = (a + b) / 2;
      if (allOccupied(U, X, s))
        a = s + 1;
      else
        b = s;
    }
    update(U, a, 1);
    dummy += a - X;
    return a;
  }
}
void remove(pair<int, int> where) { update(T[where.first], where.second, -1); }
pair<int, int> which[200000];
int main() {
  int H, Mo, N;
  scanf("%d%d%d", &H, &Mo, &N);
  int D = gcd(H, Mo);
  A = D, B = H / D;
  for (int i = 0; i < (A); ++i)
    for (int j = 0; j < (B); ++j) {
      which[(i + j * (long long)Mo) % H] = pair<int, int>(i, j);
    }
  M = 1;
  while (M < B) M <<= 1;
  for (int i = 0; i < (A); ++i) {
    T[i] = new int[2 * M];
    for (int j = 0; j < (2 * M); ++j) T[i][j] = 0;
  }
  char buf[3];
  map<int, pair<int, int> > idToPos;
  for (int i = 0; i < (N); ++i) {
    scanf("%1s", buf);
    if (buf[0] == '+') {
      int id, h;
      scanf("%d%d", &id, &h);
      int res = add(which[h]);
      idToPos[id] = pair<int, int>(which[h].first, res);
    } else {
      int id;
      scanf("%d", &id);
      remove(idToPos[id]);
    }
  }
  cout << dummy << endl;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Alice guesses the strings that Bob made for her.

At first, Bob came up with the secret string a consisting of lowercase English letters. The string a has a length of 2 or more characters. Then, from string a he builds a new string b and offers Alice the string b so that she can guess the string a.

Bob builds b from a as follows: he writes all the substrings of length 2 of the string a in the order from left to right, and then joins them in the same order into the string b.

For example, if Bob came up with the string a="abac", then all the substrings of length 2 of the string a are: "ab", "ba", "ac". Therefore, the string b="abbaac".

You are given the string b. Help Alice to guess the string a that Bob came up with. It is guaranteed that b was built according to the algorithm given above. It can be proved that the answer to the problem is unique.

Input

The first line contains a single positive integer t (1 ≤ t ≤ 1000) — the number of test cases in the test. Then t test cases follow.

Each test case consists of one line in which the string b is written, consisting of lowercase English letters (2 ≤ |b| ≤ 100) — the string Bob came up with, where |b| is the length of the string b. It is guaranteed that b was built according to the algorithm given above.

Output

Output t answers to test cases. Each answer is the secret string a, consisting of lowercase English letters, that Bob came up with.

Example

Input

4
abbaac
ac
bccddaaf
zzzzzzzzzz

Output

abac
ac
bcdaf
zzzzzz

Note

The first test case is explained in the statement.

In the second test case, Bob came up with the string a="ac", the string a has a length 2, so the string b is equal to the string a.

In the third test case, Bob came up with the string a="bcdaf", substrings of length 2 of string a are: "bc", "cd", "da", "af", so the string b="bccddaaf".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int gcd(int A, int B) {
  if (!B) return A;
  return gcd(B, A % B);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.length();
    cout << s[0];
    for (int i = 1; i < n; i += 2) cout << s[i];
    cout << endl;
  }
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).

Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.

Who wins if both participants play optimally?

Alice and Bob would like to play several games, so you should determine the winner in each game.

Input

The first line contains the single integer T (1 ≤ T ≤ 100) — the number of games. Next T lines contain one game per line. All games are independent.

Each of the next T lines contains two integers n and k (0 ≤ n ≤ 109, 3 ≤ k ≤ 109) — the length of the strip and the constant denoting the third move, respectively.

Output

For each game, print Alice if Alice wins this game and Bob otherwise.

Example

Input

4
0 3
3 3
3 4
4 4

Output

Bob
Alice
Bob
Alice

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k, m, ans;
int a[300010];
char s[300010];
inline void prework() { scanf("%d%d", &n, &k); }
inline void mainwork() {
  if (n == 0) {
    ans = 0;
    return;
  }
  if (k > n || k % 3 != 0) {
    if (n % 3 == 0)
      ans = 0;
    else
      ans = 1;
    return;
  }
  int cnt = n / k;
  int id = n % (k + 1);
  if (id <= k - 3) {
    if (id % 3 == 0)
      ans = 0;
    else
      ans = 1;
    return;
  } else {
    id -= (k - 3);
    if (id <= 3)
      ans = 1;
    else
      ans = 0;
  }
}
inline void print() {
  if (ans)
    puts("Alice");
  else
    puts("Bob");
}
int main() {
  int t;
  scanf("%d", &t);
  for (int i = 1; i <= t; i++) {
    prework();
    mainwork();
    print();
  }
  return 0;
}

```


### Prompt

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

I, Fischl, Prinzessin der Verurteilung, descend upon this land by the call of fate an — Oh, you are also a traveler from another world? Very well, I grant you permission to travel with me.

It is no surprise Fischl speaks with a strange choice of words. However, this time, not even Oz, her raven friend, can interpret her expressions! Maybe you can help us understand what this young princess is saying?

You are given a string of n lowercase Latin letters, the word that Fischl just spoke. You think that the MEX of this string may help you find the meaning behind this message. The MEX of the string is defined as the shortest string that doesn't appear as a contiguous substring in the input. If multiple strings exist, the lexicographically smallest one is considered the MEX. Note that the empty substring does NOT count as a valid MEX.

A string a is lexicographically smaller than a string b if and only if one of the following holds:

  * a is a prefix of b, but a ≠ b;
  * in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.

A string a is a substring of a string b if a can be obtained from b by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

Find out what the MEX of the string is!

Input

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

The first line of each test case contains an integer n (1 ≤ n ≤ 1000) — the length of the word. The second line for each test case contains a single string of n lowercase Latin letters.

The sum of n over all test cases will not exceed 1000.

Output

For each test case, output the MEX of the string on a new line.

Example

Input

3
28
qaabzwsxedcrfvtgbyhnujmiklop
13
cleanairactbd
10
aannttoonn

Output

ac
f
b

### Response

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

#define int         long long
#define pb          push_back
#define m_p         make_pair
#define fi          first
#define ss          second
#define in          insert
#define clean       cout.flush()
#define pf          push_front
#define all(x)      x.begin(),x.end()
#define loop(a,b)   for(int i=(a);i<=(b);i++)
#define nloop(a,b)  for(int j=(a);j<=(b);j++)
#define loop1(a,b)  for(int i=(a); i<(b);i++)

//Here I have defined all the things.....have you any problem?
typedef pair<int,int>       pii;
typedef double              dl;
typedef unsigned long long  ull;
typedef vector<int>         vi;
typedef vector<pii>         vpii;

const int INF_MAX  = 1e18;
const int INF_MIN  = (1e18)*(-1);
const int mod      = 1e9+7;
const int N        = 2e5+10;
vector<string>v;
void make(){
    int cnt=0;
    for(char a='a'; a<='z'; a++){
        string s="";
        s+=a;
        v.pb(s);
        cnt++;
    }
    for(char a='a'; a<='z';a++){
        for(char b='a';b<='z';b++){
                string s=""; s+=a; s+=b;
                v.pb(s); cnt++;
        }
    }
    for(char a='a'; a<='z';a++){
        for(char b='a';b<='z';b++){
            for(char c='a';c<='z';c++){
                string s=""; s+=a; s+=b; s+=c;
                v.pb(s);
                cnt++;
                if(cnt>2000) break;
            }
            if(cnt>2000) break;
        }
        if(cnt>2000) break;
    }
}

void Solve(){
    map<string,int>st;
    int n; cin>>n; string s; cin>>s;
    for(int i=0;i<n;i++){
        string a="", b="", c="";
        a+=s[i]; if(i<n-2){b+=s[i]; b+=s[i+1]; b+=s[i+2];}
        if(i<n-1){c+=s[i]; c+=s[i+1];}
        st[a]++; st[b]++; st[c]++;
        //cout<<a<<" "<<b<<" "<<c<<endl;
    }
    //for(auto it: st) cout<<it<<" ";
    for(auto x: v){
       //cout<<x<<endl;
       if(st[x]==0){
           cout<<x<<endl; return;
       }
    }
}

int32_t main(){
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    make();
    int Test=1;
    cin>>Test;
    while(Test--){
        Solve();
    }
    return 0;
}
/* 20 11 3 8 4 1 9 6 1 13 9 5 11 5 4 19 12 8 13 5 4 8 4 7 9 2 10 13 3 7 16 7 14 19 4*/

```


### Prompt

Please formulate a cpp solution to the following problem:

There are two buttons, one of size A and one of size B.

When you press a button of size X, you get X coins and the size of that button decreases by 1.

You will press a button twice. Here, you can press the same button twice, or press both buttons once.

At most how many coins can you get?

Constraints

* All values in input are integers.
* 3 \leq A, B \leq 20

Input

Input is given from Standard Input in the following format:

A B

Output

Print the maximum number of coins you can get.

Examples

Input

5 3

Output

9

Input

3 4

Output

7

Input

6 6

Output

12

### Response

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

int main() {
    int a, b;
    cin >> a >> b;
    cout << max({a + a-1, a+b, b+b-1}) << endl;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.

Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.

You can apply the following operations any number of times:

  * Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
  * Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»).

You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.

What is the minimum number of coins you need to spend to get a string consisting only of ones?

Input

The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).

The second line contains the string a of length n, consisting of zeros and ones.

Output

Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.

Examples

Input

5 1 10
01000

Output

11

Input

5 10 1
01000

Output

2

Input

7 2 3
1111111

Output

0

Note

In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5].

Then the string was changed as follows:

«01000» → «10000» → «11111».

The total cost of operations is 1 + 10 = 11.

In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5].

Then the string was changed as follows:

«01000» → «11000» → «11111».

The overall cost is 1 + 1 = 2.

In the third example, string already consists only of ones, so the answer is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  t = 1;
  while (t--) {
    long long int x, y, n, i, j, k;
    cin >> n >> x >> y;
    string s;
    cin >> s;
    long long int count = 0, ans = 0, one = 0, zero = 0;
    for (i = 0; i < n; i++) {
      if (s[i] == '1') {
        one++;
        if (ans != 0) count = count + 1;
        ans = 0;
      } else {
        zero++;
        ans++;
      }
    }
    if (ans != 0) count++;
    if (zero == 0)
      cout << 0 << endl;
    else if (one == 0)
      cout << y << endl;
    else {
      cout << (count - 1) * min(x, y) + y << endl;
    }
  }
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. As the result can be very large, you should print the value modulo 109 + 7 (the remainder when divided by 109 + 7).

The modulo operator a mod b stands for the remainder after dividing a by b. For example 10 mod 3 = 1.

Input

The only line contains two integers n, m (1 ≤ n, m ≤ 1013) — the parameters of the sum.

Output

Print integer s — the value of the required sum modulo 109 + 7.

Examples

Input

3 4

Output

4

Input

4 4

Output

1

Input

1 1

Output

0

### Response

```cpp
#include <bits/stdc++.h>
long long n, k, l, r, sum = 0, p;
long long max(long long x, long long y) { return x > y ? x : y; }
long long min(long long x, long long y) { return x < y ? x : y; }
int main() {
  scanf("%lld%lld", &n, &p);
  for (k = 1; k <= n; k = n / (l - 1)) {
    l = n / (k + 1) + 1;
    r = n / k;
    sum = (sum + max((min(r, p) - l + 1) % 1000000007 *
                         ((l + min(r, p)) % 1000000007) % 1000000007 *
                         (k % 1000000007) % 1000000007 * 500000004 % 1000000007,
                     0)) %
          1000000007;
    if (l - 1 < 1) break;
  }
  printf("%lld\n",
         (n % 1000000007 * (p % 1000000007) % 1000000007 - sum + 1000000007) %
             1000000007);
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

You want to perform the combo on your opponent in one popular fighting game. The combo is the string s consisting of n lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in s. I.e. if s="abca" then you have to press 'a', then 'b', 'c' and 'a' again.

You know that you will spend m wrong tries to perform the combo and during the i-th try you will make a mistake right after p_i-th button (1 ≤ p_i < n) (i.e. you will press first p_i buttons right and start performing the combo from the beginning). It is guaranteed that during the m+1-th try you press all buttons right and finally perform the combo.

I.e. if s="abca", m=2 and p = [1, 3] then the sequence of pressed buttons will be 'a' (here you're making a mistake and start performing the combo from the beginning), 'a', 'b', 'c', (here you're making a mistake and start performing the combo from the beginning), 'a' (note that at this point you will not perform the combo because of the mistake), 'b', 'c', 'a'.

Your task is to calculate for each button (letter) the number of times you'll press it.

You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases.

Then t test cases follow.

The first line of each test case contains two integers n and m (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ m ≤ 2 ⋅ 10^5) — the length of s and the number of tries correspondingly.

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

The third line of each test case contains m integers p_1, p_2, ..., p_m (1 ≤ p_i < n) — the number of characters pressed right during the i-th try.

It is guaranteed that the sum of n and the sum of m both does not exceed 2 ⋅ 10^5 (∑ n ≤ 2 ⋅ 10^5, ∑ m ≤ 2 ⋅ 10^5).

It is guaranteed that the answer for each letter does not exceed 2 ⋅ 10^9.

Output

For each test case, print the answer — 26 integers: the number of times you press the button 'a', the number of times you press the button 'b', ..., the number of times you press the button 'z'.

Example

Input

3
4 2
abca
1 3
10 5
codeforces
2 8 3 2 9
26 10
qwertyuioplkjhgfdsazxcvbnm
20 10 1 2 3 5 10 5 9 4

Output

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

Note

The first test case is described in the problem statement. Wrong tries are "a", "abc" and the final try is "abca". The number of times you press 'a' is 4, 'b' is 2 and 'c' is 2.

In the second test case, there are five wrong tries: "co", "codeforc", "cod", "co", "codeforce" and the final try is "codeforces". The number of times you press 'c' is 9, 'd' is 4, 'e' is 5, 'f' is 3, 'o' is 9, 'r' is 3 and 's' is 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int p[N];
int cnt[26];
char str[N];
int main() {
  int t, n, m;
  scanf("%d", &t);
  while (t--) {
    memset(cnt, 0, sizeof(cnt));
    scanf("%d%d", &n, &m);
    scanf("%s", str + 1);
    for (int i = 1; i <= m; i++) scanf("%d", p + i);
    sort(p + 1, p + 1 + m);
    int i = 1, j = 1;
    while (i <= n && j <= m) {
      if (i <= p[j])
        cnt[str[i++] - 'a'] += m - j + 1;
      else
        j++;
    }
    for (i = 1; i <= n; i++) cnt[str[i] - 'a']++;
    for (i = 0; i < 26; i++) printf("%d ", cnt[i]);
    printf("\n");
  }
  return 0;
}

```


### Prompt

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

You have a string s — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands:

  * 'W' — move one cell up;
  * 'S' — move one cell down;
  * 'A' — move one cell left;
  * 'D' — move one cell right.

Let Grid(s) be the grid of minimum possible area such that there is a position in the grid where you can place the robot in such a way that it will not fall from the grid while running the sequence of commands s. For example, if s = DSAWWAW then Grid(s) is the 4 × 3 grid:

  1. you can place the robot in the cell (3, 2);
  2. the robot performs the command 'D' and moves to (3, 3);
  3. the robot performs the command 'S' and moves to (4, 3);
  4. the robot performs the command 'A' and moves to (4, 2);
  5. the robot performs the command 'W' and moves to (3, 2);
  6. the robot performs the command 'W' and moves to (2, 2);
  7. the robot performs the command 'A' and moves to (2, 1);
  8. the robot performs the command 'W' and moves to (1, 1).

<image>

You have 4 extra letters: one 'W', one 'A', one 'S', one 'D'. You'd like to insert at most one of these letters in any position of sequence s to minimize the area of Grid(s).

What is the minimum area of Grid(s) you can achieve?

Input

The first line contains one integer T (1 ≤ T ≤ 1000) — the number of queries.

Next T lines contain queries: one per line. This line contains single string s (1 ≤ |s| ≤ 2 ⋅ 10^5, s_i ∈ \{W, A, S, D\}) — the sequence of commands.

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

Output

Print T integers: one per query. For each query print the minimum area of Grid(s) you can achieve.

Example

Input

3
DSAWWAW
D
WA

Output

8
2
4

Note

In the first query you have to get string DSAWW\underline{D}AW.

In second and third queries you can not decrease the area of Grid(s).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2000010;
char tmpread[N];
string s;
void solve() {
  scanf("%s", tmpread);
  s = (string)tmpread;
  int mnx = 0, mxx = 0, mny = 0, mxy = 0;
  int x = 0, y = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    if (s[i] == 'W')
      y++;
    else if (s[i] == 'S')
      y--;
    else if (s[i] == 'A')
      x--;
    else
      x++;
    mnx = min(mnx, x);
    mxx = max(mxx, x);
    mny = min(mny, y);
    mxy = max(mxy, y);
  }
  int a = 0, b = 0, c = 0, d = 0;
  x = y = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    if (s[i] == 'W')
      y++;
    else if (s[i] == 'S')
      y--;
    else if (s[i] == 'A')
      x--;
    else
      x++;
    if (x == mnx) a++, x++;
    if (y == mny) c++, y++;
    if (x > mxx) a += 10;
    if (y > mxy) c += 10;
  }
  x = y = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    if (s[i] == 'W')
      y++;
    else if (s[i] == 'S')
      y--;
    else if (s[i] == 'A')
      x--;
    else
      x++;
    if (x == mxx) b++, x--;
    if (y == mxy) d++, y--;
    if (x < mnx) b += 10;
    if (y < mny) d += 10;
  }
  if (mnx == 0) a += 10;
  if (mxx == 0) b += 10;
  if (mny == 0) c += 10;
  if (mxy == 0) d += 10;
  x = (mxx - mnx) + 1;
  y = (mxy - mny) + 1;
  bool canx = false;
  bool cany = false;
  if (x > 2 && (a < 2 || b < 2)) canx = true;
  if (y > 2 && (c < 2 || d < 2)) cany = true;
  long long ans = (long long)x * y;
  if (canx) ans = min(ans, (long long)(x - 1) * y);
  if (cany) ans = min(ans, (long long)x * (y - 1));
  printf("%lld\n", ans);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

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

Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.

Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:

* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.

Constraints

* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1

Input

Input is given from Standard Input in the following format:

p
a_0 a_1 \ldots a_{p-1}

Output

Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.

It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.

Examples

Input

2
1 0

Output

1 1

Input

3
0 0 0

Output

0 0 0

Input

5
0 1 0 1 0

Output

0 2 0 1 3

### Response

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

int p;
int C[3005][3005];
void Init() {
	C[0][0] = 1;
	for(int i=1; i<=3000; i++) {
		C[i][0] = 1;
		for(int j=1; j<=i; j++) C[i][j] = (C[i-1][j] + C[i-1][j-1])%p;
	}
	return ;
}
int kx[3005];
int main() {
	cin >> p;
	Init ();
	for(int T=0,x; T<p; T++) {
		scanf("%d",&x);
		if(x) {
			kx[0] ++;
			kx[0] %= p;
			int b = 1;
			for(int i=p-1; i>=0; i--) {
				kx[i] = (kx[i]-C[p-1][p-1-i]*b)%p;
				b = (b*-T)%p;
			}
		}
	}
	for(int i=0; i<p; i++) printf("%d ",(kx[i]%p+p)%p);
	return 0;
}
```


### Prompt

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

Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid:

    ABCDEFGHIJKLM
    NOPQRSTUVWXYZ

We say that two tiles are adjacent if they share a side or a corner. In the example grid above, the tile with the letter 'A' is adjacent only to the tiles with letters 'B', 'N', and 'O'. A tile is not adjacent to itself.

A sequence of tiles is called a path if each tile in the sequence is adjacent to the tile which follows it (except for the last tile in the sequence, which of course has no successor). In this example, "ABC" is a path, and so is "KXWIHIJK". "MAB" is not a path because 'M' is not adjacent to 'A'. A single tile can be used more than once by a path (though the tile cannot occupy two consecutive places in the path because no tile is adjacent to itself).

You’re given a string s which consists of 27 upper-case English letters. Each English letter occurs at least once in s. Find a grid that contains a path whose tiles, viewed in the order that the path visits them, form the string s. If there’s no solution, print "Impossible" (without the quotes).

Input

The only line of the input contains the string s, consisting of 27 upper-case English letters. Each English letter occurs at least once in s.

Output

Output two lines, each consisting of 13 upper-case English characters, representing the rows of the grid. If there are multiple solutions, print any of them. If there is no solution print "Impossible".

Examples

Input

ABCDEFGHIJKLMNOPQRSGTUVWXYZ

Output

YXWVUTGHIJKLM
ZABCDEFSRQPON

Input

BUVTYZFQSNRIWOXXGJLKACPEMDH

Output

Impossible

### Response

```cpp
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const double PI = 3.1415926535897932384626433832795;
void fft(vector<complex<double> >& a, bool side) {
  int n = a.size();
  if (n == 1) return;
  vector<complex<double> > a0, a1;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0)
      a0.push_back(a[i]);
    else
      a1.push_back(a[i]);
  }
  fft(a0, side);
  fft(a1, side);
  double ang = 2 * PI / n * (side ? 1 : -1);
  complex<double> w(1), wn(cos(ang), sin(ang));
  for (int i = 0; i < n / 2; i++) {
    a[i] = a0[i] + a1[i] * w;
    a[i + n / 2] = a0[i] - a1[i] * w;
    if (!side) {
      a[i] /= 2;
      a[i + n / 2] /= 2;
    }
    w *= wn;
  }
}
void multiply(vector<int>& a, vector<int>& b, vector<int>& rez) {
  vector<complex<double> > fa(a.begin(), a.end()), fb(b.begin(), b.end());
  int n = 1;
  while (n < max(a.size(), b.size())) n <<= 1;
  n <<= 1;
  fa.resize(n);
  fb.resize(n);
  fft(fa, true);
  fft(fb, true);
  for (int i = 0; i < n; i++) {
    fa[i] *= fb[i];
  }
  fft(fa, false);
  rez.resize(n);
  for (int i = 0; i < n; i++) {
    rez[i] = fa[i].real() > 0 ? (int)(fa[i].real() + 0.5)
                              : (int)(fa[i].real() - 0.5);
  }
}
int modm = 1;
int mn(string& s, int fi, int se) {
  int y = 0;
  for (int i = fi; i <= se; i++) {
    y = y * 10 + s[i] - '0';
  }
  return y;
}
void fn(string& s, vector<int>& n) {
  int m = (s[0] == '-' ? 1 : 0);
  for (int i = s.size() - 1; i >= m; i -= modm)
    n.push_back(mn(s, max(i - (modm - 1), m), i));
}
int ns(int a) {
  if (a == 0) return 1;
  int k = 0;
  while (a > 0) {
    a /= 10;
    k++;
  }
  return k;
}
void umn(string& a, string& b, vector<int>& rez) {
  vector<int> a1, b1;
  fn(a, a1);
  fn(b, b1);
  multiply(a1, b1, rez);
  for (int i = 0; i < rez.size() - 1; i++) {
    rez[i + 1] += rez[i] / 10;
    rez[i] %= 10;
  }
  while (rez[rez.size() - 1] > 10) {
    int a = rez[rez.size() - 1] / 10;
    rez[rez.size() - 1] %= 10;
    rez.push_back(a);
  }
  while (rez.size() > 1 && rez[rez.size() - 1] == 0) rez.pop_back();
}
int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] == s[i + 1]) {
      cout << "Impossible";
      return 0;
    }
  }
  vector<vector<int> > al(26, vector<int>());
  for (int i = 0; i < 27; i++) {
    al[s[i] - 'A'].push_back(i);
  }
  int k = 0;
  int l = 0;
  int l1 = 0;
  for (int i = 0; i < 26; i++) {
    if (al[i].size() == 2) {
      k = abs(al[i][0] - al[i][1]) - 1;
      l = al[i][0];
      l1 = i;
    }
  }
  char a[13][2];
  int y = k / 2;
  for (int i = 0; i < y; i++) {
    a[i][0] = s[l + y - i];
  }
  a[y][0] = s[l];
  for (int i = 0; i < k - y; i++) {
    a[i][1] = s[l + y + i + 1];
  }
  int o = 1;
  int uuu = k - y;
  while (uuu < 13 && al[l1][1] + o < s.size()) {
    a[uuu][1] = s[al[l1][1] + o];
    uuu++;
    o++;
  }
  if (al[l1][1] + o < s.size()) {
    a[12][0] = s[al[l1][1] + o];
  }
  o++;
  int oo = 1;
  while (al[l1][1] + o < s.size()) {
    a[12 - oo][0] = s[al[l1][1] + o];
    o++;
    oo++;
  }
  int op = 0;
  for (int i = 0; i < 13; i++) {
    if (a[i][0] == s[l]) op = i;
  }
  int uy = 1;
  while (op + 1 < 13 && l - uy >= 0) {
    a[op + 1][0] = s[l - uy];
    uy++;
    op++;
  }
  if (l - uy >= 0) {
    a[12][1] = s[l - uy];
    uy++;
  }
  int poo = 1;
  while (l - uy >= 0) {
    a[12 - poo][1] = s[l - uy];
    poo++;
    uy++;
  }
  for (int i = 0; i < 13; i++) cout << a[i][0];
  cout << endl;
  for (int i = 0; i < 13; i++) cout << a[i][1];
  return 0;
}

```