### Prompt

Construct a Cpp code solution to the problem outlined:

Berland has n cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them.

The president of Berland decided to split country into r states in such a way that each city will belong to exactly one of these r states.

After this split each road will connect either cities of the same state or cities of the different states. Let's call roads that connect two cities of the same state "inner" roads.

The president doesn't like odd people, odd cities and odd numbers, so he wants this split to be done in such a way that each city would have even number of "inner" roads connected to it.

Please help president to find smallest possible r for which such a split exists.

Input

The input contains one or several test cases. The first input line contains a single integer number t — number of test cases. Then, t test cases follow. Solve test cases separately, test cases are completely independent and do not affect each other.

Then t blocks of input data follow. Each block starts from empty line which separates it from the remaining input data. The second line of each block contains two space-separated integers n, m (1 ≤ n ≤ 2000, 0 ≤ m ≤ 10000) — the number of cities and number of roads in the Berland. Each of the next m lines contains two space-separated integers — x_i, y_i (1 ≤ x_i, y_i ≤ n; x_i ≠ y_i), which denotes that the i-th road connects cities x_i and y_i. Each pair of cities are connected by at most one road.

Sum of values n across all test cases doesn't exceed 2000. Sum of values m across all test cases doesn't exceed 10000.

Output

For each test case first print a line containing a single integer r — smallest possible number of states for which required split is possible. In the next line print n space-separated integers in range from 1 to r, inclusive, where the j-th number denotes number of state for the j-th city. If there are multiple solutions, print any.

Example

Input

2

5 3
1 2
2 5
1 5

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

Output

1
1 1 1 1 1
2
2 1 1 1 1 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
struct graph {
  vector<int> deg;
  bitset<N> con[N];
  int n;
  graph(int n) : n(n) {}
  void add_edge(int a, int b) { con[a][b] = con[b][a] = 1; }
  pair<set<int>, set<int>> partition() {
    set<int> A, B;
    for (int i = 1; i <= n; i++) A.insert(i);
    int node = 0;
    for (int i = 1; i <= n; i++)
      if (con[i].count() & 1) node = i;
    if (node == 0) return {A, {}};
    A.clear();
    bitset<N> temp = con[node];
    con[node].reset();
    for (int i = 1; i <= n; i++) {
      con[i][node] = 0;
      if (temp[i]) {
        con[i] ^= temp;
        con[i][i] = 0;
      }
    }
    pair<set<int>, set<int>> part = partition();
    A = part.first, B = part.second;
    int cnt1 = 0, cnt2 = 0;
    for (int i = 1; i <= n; i++)
      if (temp[i]) {
        cnt1 ^= A.count(i);
        cnt2 ^= B.count(i);
      }
    if (cnt1 == 0 && !A.count(node)) {
      A.insert(node);
      B.erase(node);
    } else if (cnt1 == 1 && A.count(node)) {
      B.insert(node);
      A.erase(node);
    }
    con[node] = temp;
    return {A, B};
  }
};
int main() {
  int t, n = 0, m = 0;
  scanf("%d", &(t));
  while (t--) {
    scanf("%d", &(n));
    scanf("%d", &(m));
    graph g(n);
    for (int i = 1; i <= m; i++) {
      int x, y;
      scanf("%d", &(x));
      scanf("%d", &(y));
      g.add_edge(x, y);
    }
    pair<set<int>, set<int>> part = g.partition();
    printf("%d\n", (part.second.empty()) ? 1 : 2);
    for (int i = 1; i <= n; i++) {
      if (part.first.count(i))
        printf("%d ", 1);
      else
        printf("%d ", 2);
    }
    printf("\n");
  }
}

```


### Prompt

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

Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem.

Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible.

He has already composed major part of the anthem and now just needs to fill in some letters. King asked you to help him with this work.

The anthem is the string s of no more than 105 small Latin letters and question marks. The most glorious victory is the string t of no more than 105 small Latin letters. You should replace all the question marks with small Latin letters in such a way that the number of occurrences of string t in string s is maximal.

Note that the occurrences of string t in s can overlap. Check the third example for clarification.

Input

The first line contains string of small Latin letters and question marks s (1 ≤ |s| ≤ 105).

The second line contains string of small Latin letters t (1 ≤ |t| ≤ 105).

Product of lengths of strings |s|·|t| won't exceed 107.

Output

Output the maximum number of occurrences of string t you can achieve by replacing all the question marks in string s with small Latin letters.

Examples

Input

winlose???winl???w??
win

Output

5

Input

glo?yto?e??an?
or

Output

3

Input

??c?????
abcab

Output

2

Note

In the first example the resulting string s is "winlosewinwinlwinwin"

In the second example the resulting string s is "glorytoreorand". The last letter of the string can be arbitrary.

In the third example occurrences of string t are overlapping. String s with maximal number of occurrences of t is "abcabcab".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e5, A = 26;
string s, t;
int n, m;
vector<vector<int>> dp;
struct autoac {
  int sl[mxN + 1], sz = 1, c[mxN + 1][A], d[mxN + 1][A], w[mxN + 1];
  void add(string s, int x) {
    int u = 0;
    for (char a : s) {
      if (!c[u][a - 'a']) c[u][a - 'a'] = sz++;
      u = c[u][a - 'a'];
    }
    w[u] += x;
  }
  void ac() {
    for (queue<int> q({0}); q.size(); q.pop()) {
      int u = q.front();
      w[u] += w[sl[u]];
      for (int a = 0; a < A; ++a) {
        int v = c[u][a], s = sl[u];
        if (v) {
          sl[v] = d[s][a];
          q.push(v);
        }
        d[u][a] = v ? v : d[s][a];
      }
    }
  }
} ac;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> s >> t;
  n = s.size(), m = t.size();
  ac.add(t, 0);
  ac.ac();
  dp = vector<vector<int>>(n + 1, vector<int>(m + 1, -1e9));
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= m; ++j) {
      for (int k = 0; k < 26; ++k) {
        if (s[i] == '?' || s[i] == 'a' + k) {
          int l = ac.d[j][k];
          dp[i + 1][l] = max(dp[i + 1][l], dp[i][j] + (l == m));
        }
      }
    }
  }
  cout << *max_element(dp[n].begin(), dp[n].end());
}

```


### Prompt

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

There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N.

On this sequence, Snuke can perform the following operation:

* Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.

Snuke would like to make all the elements in this sequence equal by repeating the operation above some number of times. Find the minimum number of operations required. It can be proved that, Under the constraints of this problem, this objective is always achievable.

Constraints

* 2 \leq K \leq N \leq 100000
* A_1, A_2, ..., A_N is a permutation of 1, 2, ..., N.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of operations required.

Examples

Input

4 3
2 3 1 4

Output

2

Input

3 3
1 2 3

Output

1

Input

8 3
7 3 1 8 4 6 2 5

Output

4

### Response

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


### Prompt

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

Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the workers of Hanoi Factory to create as high tower as possible. They were not ready to serve such a strange order so they had to create this new tower using already produced rings.

There are n rings in factory's stock. The i-th ring has inner radius ai, outer radius bi and height hi. The goal is to select some subset of rings and arrange them such that the following conditions are satisfied:

  * Outer radiuses form a non-increasing sequence, i.e. one can put the j-th ring on the i-th ring only if bj ≤ bi.
  * Rings should not fall one into the the other. That means one can place ring j on the ring i only if bj > ai.
  * The total height of all rings used should be maximum possible.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of rings in factory's stock.

The i-th of the next n lines contains three integers ai, bi and hi (1 ≤ ai, bi, hi ≤ 109, bi > ai) — inner radius, outer radius and the height of the i-th ring respectively.

Output

Print one integer — the maximum height of the tower that can be obtained.

Examples

Input

3
1 5 1
2 6 2
3 7 3

Output

6

Input

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

Output

4

Note

In the first sample, the optimal solution is to take all the rings and put them on each other in order 3, 2, 1.

In the second sample, one can put the ring 3 on the ring 4 and get the tower of height 3, or put the ring 1 on the ring 2 and get the tower of height 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long seg[400005];
long long a[100005];
long long b[100005];
long long c[100005];
vector<pair<pair<int, int>, int> > v;
long long getMax(int x, int l, int r, int ql, int qr) {
  if (l > r) return 0;
  if (r < ql || l > qr) {
    return 0;
  }
  if (l >= ql && r <= qr) {
    return seg[x];
  }
  int mid = (l + r) / 2;
  long long lval = getMax(2 * x + 1, l, mid, ql, qr);
  long long rval = getMax(2 * x + 2, mid + 1, r, ql, qr);
  return max(lval, rval);
}
void update(int x, int l, int r, int ind, long long val) {
  if (l > r) return;
  if (ind > r || ind < l) return;
  if (l == r) {
    if (l == ind) {
      seg[x] = max(seg[x], val);
    }
    return;
  }
  int mid = (l + r) / 2;
  if (ind <= mid) {
    update(2 * x + 1, l, mid, ind, val);
  } else {
    update(2 * x + 2, mid + 1, r, ind, val);
  }
  seg[x] = max(seg[x], val);
}
int main() {
  int n;
  scanf("%d", &n);
  long long ans = 0;
  long long x, y, z;
  for (int i = (0); i < (n); ++i) {
    scanf("%lld", &x), scanf("%lld", &y), scanf("%lld", &z);
    v.push_back(make_pair(pair<int, int>(y, x), z));
  }
  sort(v.begin(), v.end());
  for (int i = (0); i < (n); ++i) {
    a[i] = (long long)v[i].first.second;
    b[i] = (long long)v[i].first.first;
    c[i] = (long long)v[i].second;
    ans = max(ans, c[i]);
  }
  sort(v.begin(), v.end());
  for (int i = (0); i < (n); ++i) {
    int l = 0;
    int h = i;
    int val = a[i] + 1;
    while (l < h) {
      int md = (l + h) / 2;
      if (b[md] < val) {
        l = md + 1;
      } else {
        h = md;
      }
    }
    long long mx = getMax(0, 0, n - 1, l, i - 1);
    update(0, 0, n - 1, i, mx + c[i]);
    ans = max(ans, mx + c[i]);
  }
  cout << ans << endl;
}

```


### Prompt

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

We have a graph with N vertices, numbered 0 through N-1. Edges are yet to be added.

We will process Q queries to add edges. In the i-th (1≦i≦Q) query, three integers A_i, B_i and C_i will be given, and we will add infinitely many edges to the graph as follows:

* The two vertices numbered A_i and B_i will be connected by an edge with a weight of C_i.
* The two vertices numbered B_i and A_i+1 will be connected by an edge with a weight of C_i+1.
* The two vertices numbered A_i+1 and B_i+1 will be connected by an edge with a weight of C_i+2.
* The two vertices numbered B_i+1 and A_i+2 will be connected by an edge with a weight of C_i+3.
* The two vertices numbered A_i+2 and B_i+2 will be connected by an edge with a weight of C_i+4.
* The two vertices numbered B_i+2 and A_i+3 will be connected by an edge with a weight of C_i+5.
* The two vertices numbered A_i+3 and B_i+3 will be connected by an edge with a weight of C_i+6.
* ...

Here, consider the indices of the vertices modulo N. For example, the vertice numbered N is the one numbered 0, and the vertice numbered 2N-1 is the one numbered N-1.

The figure below shows the first seven edges added when N=16, A_i=7, B_i=14, C_i=1:

<image>

After processing all the queries, find the total weight of the edges contained in a minimum spanning tree of the graph.

Constraints

* 2≦N≦200,000
* 1≦Q≦200,000
* 0≦A_i,B_i≦N-1
* 1≦C_i≦10^9

Input

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

N Q
A_1 B_1 C_1
A_2 B_2 C_2
:
A_Q B_Q C_Q

Output

Print the total weight of the edges contained in a minimum spanning tree of the graph.

Examples

Input

7 1
5 2 1

Output

21

Input

2 1
0 0 1000000000

Output

1000000001

Input

5 3
0 1 10
0 2 10
0 4 10

Output

42

### Response

```cpp
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cctype>

#define int long long

using namespace std;

const int N = 6e5;
const int INF = 2100000000;

int n, m, ec, a, b, c, q, fir;
int f[N], fa[N], way[N];

struct Edge
{
	int u, v, w, nxt, id;
	bool operator < (const Edge &b) const
		{ return w < b.w; }
}e[N << 1];

inline void Addedge(int a, int b, int c)
{
	++ec;
	e[ec].u = a;
	e[ec].v = b;
	e[ec].w = c;
	e[ec].nxt = f[a];
	f[a] = ec;
}

inline void read(int &x)
{
	int k = 1; x = 0;
	char c = getchar();
	while (!isdigit(c))
		if (c == '-') c = getchar(), k = -1;
		else c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ 48),
		c = getchar();
	x *= k;
}

int Find(int x)
{
	return (x == fa[x]) ? x : fa[x] = Find(fa[x]);
}

signed main()
{
	read(n), read(m);
	memset(f, -1, sizeof(f));
	for (int i = 1; i <= n; ++i) way[i] = INF;
	for (int i = 1; i <= m; ++i)
		read(a), read(b), read(c), ++a, ++b, Addedge(a, b, c),
		way[a] = min(way[a], c + 1), way[b] = min(way[b], c + 2);
	for (int i = 1; i <= n; ++i)
		way[i] = min(way[i], way[(i == 1) ? n : i - 1] + 2);
	for (int i = 1; i <= n; ++i)
		way[i] = min(way[i], way[(i == 1) ? n : i - 1] + 2);
	for (int i = 1; i <= n; ++i)
		Addedge(i, (i == n) ? 1 : i + 1, way[i]), fa[i] = i;
	sort(e + 1, e + ec + 1);
	for (int i = 1; i <= ec; ++i)
	{
		if (way[0] >= n - 1) break;
		if (Find(e[i].u) != Find(e[i].v) && e[i].w != INF)
			fa[Find(e[i].u)] = Find(e[i].v), ++way[0], q += e[i].w;
	}
	printf("%lld", q);
	return 0;
}
```


### Prompt

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

Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer.

In this game there are n objects numbered from 1 to n arranged in a circle (in clockwise order). Object number 1 is a black hole and the others are planets. There's a monster in one of the planet. Rick and Morty don't know on which one yet, only that he's not initially in the black hole, but Unity will inform them before the game starts. But for now, they want to be prepared for every possible scenario.

<image>

Each one of them has a set of numbers between 1 and n - 1 (inclusive). Rick's set is s1 with k1 elements and Morty's is s2 with k2 elements. One of them goes first and the player changes alternatively. In each player's turn, he should choose an arbitrary number like x from his set and the monster will move to his x-th next object from its current position (clockwise). If after his move the monster gets to the black hole he wins.

Your task is that for each of monster's initial positions and who plays first determine if the starter wins, loses, or the game will stuck in an infinite loop. In case when player can lose or make game infinity, it more profitable to choose infinity game.

Input

The first line of input contains a single integer n (2 ≤ n ≤ 7000) — number of objects in game.

The second line contains integer k1 followed by k1 distinct integers s1, 1, s1, 2, ..., s1, k1 — Rick's set.

The third line contains integer k2 followed by k2 distinct integers s2, 1, s2, 2, ..., s2, k2 — Morty's set

1 ≤ ki ≤ n - 1 and 1 ≤ si, 1, si, 2, ..., si, ki ≤ n - 1 for 1 ≤ i ≤ 2.

Output

In the first line print n - 1 words separated by spaces where i-th word is "Win" (without quotations) if in the scenario that Rick plays first and monster is initially in object number i + 1 he wins, "Lose" if he loses and "Loop" if the game will never end.

Similarly, in the second line print n - 1 words separated by spaces where i-th word is "Win" (without quotations) if in the scenario that Morty plays first and monster is initially in object number i + 1 he wins, "Lose" if he loses and "Loop" if the game will never end.

Examples

Input

5
2 3 2
3 1 2 3

Output

Lose Win Win Loop
Loop Win Win Win

Input

8
4 6 2 3 4
2 3 6

Output

Win Win Win Win Win Win Win
Lose Win Lose Lose Win Lose Lose

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 8000;
const int M = 1e9 + 7;
const double eps = 1e-6;
const double PI(acos(-1.0));
int n, a[N][2];
int f[N][2], vis[N][2], c[N][2];
int k[2];
void dfs(int pos, int t) {
  vis[pos][t] = 1;
  for (int j = 0; j < (k[!t]); j++) {
    int pre = (pos - a[j][!t] + n) % n;
    if (!pre) continue;
    if (vis[pre][!t]) continue;
    if (f[pos][t] == 0) {
      f[pre][!t] = 1;
      dfs(pre, !t);
    } else if (f[pos][t] == 1 && ++c[pre][!t] == k[!t]) {
      f[pre][!t] = 0;
      dfs(pre, !t);
    }
  }
}
int main() {
  cin >> n;
  cin >> k[0];
  for (int i = 0; i < (k[0]); i++) cin >> a[i][0];
  cin >> k[1];
  for (int i = 0; i < (k[1]); i++) cin >> a[i][1];
  memset(f, -1, sizeof f);
  f[0][0] = f[0][1] = 0;
  dfs(0, 0);
  dfs(0, 1);
  for (int i = 0; i < (2); i++) {
    for (int j = (1); j <= (n - 1); j++) {
      if (~f[j][i]) {
        if (f[j][i])
          cout << "Win ";
        else
          cout << "Lose ";
      } else
        cout << "Loop ";
    }
    cout << endl;
  }
}

```


### Prompt

Create a solution in cpp for the following problem:

Example

Input

2 1
WE

Output

1 2

### Response

```cpp
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> dp(n+1), dq(n+1);
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < n; ++j) {
            if(s[j] == 'W') dp[j]++;
            else dq[j+1]++;
        }
    }
    for (int i = 1; i <= n; ++i) dq[i] += dq[i-1];
    for (int i = n-1; i >= 0; --i) dp[i] += dp[i+1];
    int M = dp[0]+dq[0], ans = 0;
    for (int i = 0; i <= n; ++i) {
        if(dp[i]+dq[i] < M){
            M = dp[i]+dq[i];
            ans = i;
        }
    }
    cout << ans << " " << ans+1 << "\n";
    return 0;
}

```


### Prompt

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

Take the'IOI'train

A new railway has been laid in IOI. Trains running on railways in IOI are a combination of several vehicles, and there are two types of vehicles, I and O. Vehicles can only be connected to different types of vehicles. Also, because the train has a driver's seat, the cars at both ends of the train must be of type I. A train is represented by a character string in which characters indicating the type of vehicle are connected in order, and the length of the train is assumed to be the length of the character string. For example, if vehicles are connected in the order of IOIOI, a train with a length of 5 can be formed, and vehicle I is a train with a length of 1 alone. Trains cannot be formed by arranging vehicles in the order of OIOI or IOOI.

Some vehicles are stored in two garages. Vehicles are lined up in a row in each garage. When forming a train, take out the train from the garage and connect it in front of the garage. Only the vehicle closest to the entrance of the garage can be taken out of the garage, but the order of taking out the vehicle from which garage is arbitrary.

Before forming a train, you can take as many cars out of the garage as you like and move them to another waiting rail. Vehicles that have been moved to the standby rails cannot be used to organize trains in the future. Also, once the train formation is started, the vehicle cannot be moved from the garage to the standby rail until the formation is completed.

When organizing a train, it is not necessary to use up all the cars in the garage. That is, after the train formation is completed, unused cars may remain in the garage.

It is believed that there are so many people on the railroad in IOI, so I want to organize the longest possible train.

<image>

Figure: The train is being organized, and the vehicle in the garage cannot be moved to the standby rail at this time. This figure corresponds to I / O example 1.

Task

Create a program to find the maximum length of trains that can be organized given the information of the cars stored in the garage. The row of vehicles stored in each garage is represented by a string consisting of only two types of letters I and O, and the information in the two garages is represented by the string S of length M and the string T of length N, respectively. Given. Each letter represents one vehicle, the letter of which is the same as the type of vehicle. The first letter of the string represents the vehicle closest to the entrance to the garage, and the last letter represents the vehicle closest to the garage.

Limits

* 1 ≤ M ≤ 2000 Length of string S
* 1 ≤ N ≤ 2000 Length of string T

input

Read the following data from standard input.

* In the first line, M and N are written separated by blanks.
* The character string S is written on the second line.
* The character string T is written on the third line.

output

Output an integer representing the maximum train length that can be organized to the standard output on one line. If no train can be organized, output 0.

Input / output example

Input example 1

5 5
OIOOI
OOIOI

Output example 1

7

Let the garage represented by S be the garage S and the garage represented by T be the garage T. At this time, for example, the first vehicle from the garage S, the first two vehicles from the garage T are put out and put on standby, and then the garage S, the garage S, the garage T, the garage S, the garage S, the garage T, and the garage T are placed in this order. If you take out the vehicle, you can form a train IOIOIOI with a length of 7.

In addition, after the first vehicle from garage S and the first two vehicles from garage T are put out and put on standby, the order is garage T, garage T, garage S, garage S, garage T, garage S, and garage S. You can also organize a 7-length train by putting out a vehicle. Since it is not possible to form a train longer than this, 7 is output.

Input example 2

5 9
IIIII
IIIIIIIII

Output example 2

1

Note that train I, which consists of only one car, also meets the conditions for a train.

The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.

Example

Input

5 5
OIOOI
OOIOI

Output

7

### Response

```cpp

#include <iomanip>
#include <utility>
#include <algorithm>
#include <type_traits>
#include <set>
#include <string>
#include <iostream>
#include <fstream>
#include <cassert>
#include <memory>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <queue>
#include <vector>
#include <array>
#include <chrono>
#include <random>
#include <forward_list>
#include <iomanip>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <numeric>

using namespace std;
#define MFOR(i,end) for(size_t i = 0, end_##i = (end); i < end_##i; ++i)

size_t M, N;
char S[2500];
char T[2500];
enum class Mode_T : int8_t {
	none = 0, I, O
};
int dp[2010][2010][3];
int func(int spos, int tpos, Mode_T last)
{
	if (S[spos] == '\0' && T[tpos] == '\0') { return -2010 * 2010 * 3; }
	if (dp[spos][tpos][(int8_t)last] != -1) {
		return dp[spos][tpos][(int8_t)last];
	}
	int max = -2010* 2010*3;
	if (last == Mode_T::none) {
		if (S[spos] == 'I') {
			max = std::max(max, 1 + std::max(0, func(spos + 1, tpos, Mode_T::I)));
		}
		if (S[spos] != '\0')max = std::max(max, 0 + func(spos + 1, tpos, Mode_T::none));
		if (T[tpos] == 'I') {
			max = std::max(max, 1 + std::max(0, func(spos, tpos + 1, Mode_T::I)));
		}
		if (T[tpos] != '\0')max = std::max(max, 0 + func(spos, tpos + 1, Mode_T::none));
	}
	else if (last == Mode_T::I)
	{
		if (S[spos] == 'O') {
			auto snpos = spos + 1;
			if (S[snpos] == 'I') {
				max = std::max(max, 2 + std::max(0, func(snpos + 1, tpos, Mode_T::I)));
			}
			if (T[tpos] == 'I') {
				max = std::max(max, 2 + std::max(0, func(snpos, tpos + 1, Mode_T::I)));
			}
		}
		if (T[tpos] == 'O') {
			auto tnpos = tpos + 1;
			if (S[spos] == 'I') {
				max = std::max(max, 2 + std::max(0, func(spos + 1, tnpos, Mode_T::I)));
			}
			if (T[tnpos] == 'I') {
				max = std::max(max, 2 + std::max(0, func(spos, tnpos + 1, Mode_T::I)));
			}
		}
	}
	else if (last == Mode_T::O)
	{
		assert(false);
		if (S[spos] == 'I') {
			max = std::max(max, 1 + std::max(0, func(spos + 1, tpos, Mode_T::I)));
		}
		if (T[tpos] == 'I') {
			max = std::max(max, 1 + std::max(0, func(spos, tpos + 1, Mode_T::I)));
		}
	}
	return dp[spos][tpos][(int8_t)last] = max;
}

int main()
{
	for (auto& arr2 : dp)for (auto& arr1 : arr2)for (auto& i : arr1) {
		i = -1;
	}
	std::cin >> M >> N;
	std::cin >> S >> T;
	std::cout << std::max(0, func(0, 0, Mode_T::none)) << std::endl;
}
```


### Prompt

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

Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.

Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!

Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.

Input

The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).

Output

Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.

Examples

Input

5 1 3 4

Output

800

Input

1 1 1 1

Output

256

Note

In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.

In the second sample, the optimal answer is to create on integer 256, thus the answer is 256.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int mini(long long int p, long long int q) {
  if (p < q) return p;
  return q;
}
int main() {
  long long int k2, k3, k5, k6, total = 0;
  cin >> k2 >> k3 >> k5 >> k6;
  int m = 0;
  m = mini(k2, k5);
  m = mini(m, k6);
  total = m * 256;
  m = mini(k2 - m, k3);
  total += m * 32;
  cout << total << endl;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Due to atheistic Soviet past, Christmas wasn't officially celebrated in Russia for most of the twentieth century. As a result, the Russian traditions for Christmas and New Year mixed into one event celebrated on the New Year but including the tree, a Santa-like 'Grandfather Frost', presents and huge family reunions and dinner parties all over the country. Bying a Tree at the New Year and installing it in the house is a tradition. Usually the whole family decorates the tree on the New Year Eve. We hope that Codeforces is a big and loving family, so in this problem we are going to decorate a tree as well.

So, our decoration consists of n pieces, each piece is a piece of colored paper, its border is a closed polyline of a special shape. The pieces go one by one as is shown on the picture. The i-th piece is a polyline that goes through points: (0, 0), (0, y0), (1, y1), (2, y2), ..., (k, yk), (k, 0). The width of each piece equals k.

<image> The figure to the left shows the decoration, the figure to the right shows the individual pieces it consists of.

The piece number 1 (shown red on the figure) is the outer piece (we see it completely), piece number 2 (shown yellow) follows it (we don't see it completely as it is partially closed by the first piece) and so on. The programmers are quite curious guys, so the moment we hung a decoration on the New Year tree we started to wonder: what area of each piece can people see?

Input

The first line contains two integers, n and k (1 ≤ n, k ≤ 300). Each of the following n lines contains k + 1 integers — the description of the polyline. If the i-th line contains ontegers yi, 0, yi, 1, ..., yi, k, that means that the polyline of the i-th piece goes through points (0, 0), (0, yi, 0), (1, yi, 1), (2, yi, 2), ..., (k, yi, k), (k, 0) (1 ≤ yi, j ≤ 1000).

Output

Print n real numbers — for each polyline, the area of its visible part.

The answer will be considered correct if its relative or absolute error do not exceed 10 - 4.

Examples

Input

2 2
2 1 2
1 2 1

Output

3.000000000000
0.500000000000

Input

1 1
1 1

Output

1.000000000000

Input

4 1
2 7
7 2
5 5
6 4

Output

4.500000000000
1.250000000000
0.050000000000
0.016666666667

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 310, M = 1e6;
int n, k;
double A[M + 10], y[N];
int main() {
  scanf("%d%d", &n, &k);
  int m = M / k;
  for (int i = 1; i <= n; ++i) {
    double y1, y2, ans = 0;
    scanf("%lf", &y1);
    for (int j = 0; j < k; ++j) {
      scanf("%lf", &y2);
      for (int t = 0; t < m; ++t) {
        double pos = double(m - t) / double(m);
        double tmp = y2 + (y1 - y2) * pos;
        if (tmp > A[j * m + t]) {
          ans += tmp - A[j * m + t];
          A[j * m + t] = tmp;
        }
      }
      y1 = y2;
    }
    ans /= m;
    printf("%.12f\n", ans);
  }
  return 0;
}

```


### Prompt

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

The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x, y).

  * If the wind blows to the east, the boat will move to (x + 1, y).
  * If the wind blows to the south, the boat will move to (x, y - 1).
  * If the wind blows to the west, the boat will move to (x - 1, y).
  * If the wind blows to the north, the boat will move to (x, y + 1).

Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (x, y). Given the wind direction for t seconds, what is the earliest time they sail to (ex, ey)?

Input

The first line contains five integers t, sx, sy, ex, ey (1 ≤ t ≤ 105, - 109 ≤ sx, sy, ex, ey ≤ 109). The starting location and the ending location will be different.

The second line contains t characters, the i-th character is the wind blowing direction at the i-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north).

Output

If they can reach (ex, ey) within t seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).

Examples

Input

5 0 0 1 1
SESNW

Output

4

Input

10 5 3 3 6
NENSWESNEE

Output

-1

Note

In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4.

In the second sample, they cannot sail to the destination.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int t;
long long sx, sy, ex, ey;
int main(void) {
  cin >> t >> sx >> sy >> ex >> ey;
  int ans = 0;
  for (int i = 0; i < t; i++) {
    char c;
    cin >> c;
    if (sx == ex && sy == ey) {
      cout << ans << "\n";
      return 0;
    }
    if (c == 'N' && sy < ey) sy++;
    if (c == 'W' && sx > ex) sx--;
    if (c == 'S' && sy > ey) sy--;
    if (c == 'E' && sx < ex) sx++;
    ans++;
  }
  if (sx == ex && sy == ey) {
    cout << ans << "\n";
    return 0;
  }
  cout << "-1\n";
  return 0;
}

```


### Prompt

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

One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go to a distant mountain village to procure a large pillar (the carpenter would have to go from town to satoyama and back in town).

The carpenter's reward is the remainder of the money received from the lord minus the pillar price and transportation costs. As shown in the map below, there are many highways that pass through various towns to reach the mountain village, and the highways that connect the two towns have different transportation costs. How do you follow the road and procure to maximize the carpenter's reward? Create a program that outputs the maximum carpenter's reward. However, if the number of towns is n, then each town is identified by an integer from 1 to n. There are no more than one road that connects the two towns directly.

<image>

* The numbers on the arrows indicate the transportation costs to go in that direction.

Input

The input is given in the following format:

n
m
a1, b1, c1, d1
a2, b2, c2, d2
::
am, bm, cm, dm
s, g, V, P

The first line gives the total number of towns n (n ≤ 20), and the second line gives the total number of roads m (m ≤ 100). The following m lines are given the i-th road information ai, bi, ci, di (1 ≤ ai, bi ≤ n, 0 ≤ ci, di ≤ 1,000). ai and bi are the numbers of the towns connected to the highway i, ci is the transportation cost from ai to bi, and di is the transportation cost from bi to ai.

On the last line, the number s of the town where the carpenter departs, the number g of the mountain village with the pillar, the money V received by the carpenter from the lord, and the price P of the pillar are given.

Output

Output the carpenter's reward (integer) on one line.

Example

Input

6
8
1,2,2,2
1,3,4,3
1,4,4,2
2,5,3,2
3,4,4,2
3,6,1,2
4,6,1,1
5,6,1,2
2,4,50,30

Output

11

### Response

```cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define INFINITY 100000
int cost[20][20];

int main(void){
  char s;
  int n,m,x1,x2,y1,y2;
  REP(i,20)
    REP(j,20)
      cost[i][j] = (i!=j)?INFINITY:0;
  cin>>n>>m;
  while(m--){
    int a,b,c,d;
    cin>>a>>s>>b>>s>>c>>s>>d;
    cost[a-1][b-1] = c;
    cost[b-1][a-1] = d;
  }
  cin>>x1>>s>>x2>>s>>y1>>s>>y2;
  REP(k,n)
    REP(i,n)
      REP(j,n)
       cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
  cout << y1 - y2 - cost[x1-1][x2-1] - cost[x2-1][x1-1] << endl;
  return 0;
}
```


### Prompt

Please create a solution in CPP to the following problem:

[Thanos sort](https://codegolf.stackexchange.com/questions/182221/implement-the-thanos-sorting-algorithm) is a supervillain sorting algorithm, which works as follows: if the array is not sorted, snap your fingers* to remove the first or the second half of the items, and repeat the process.

Given an input array, what is the size of the longest sorted array you can obtain from it using Thanos sort?

*Infinity Gauntlet required.

Input

The first line of input contains a single number n (1 ≤ n ≤ 16) — the size of the array. n is guaranteed to be a power of 2.

The second line of input contains n space-separated integers a_i (1 ≤ a_i ≤ 100) — the elements of the array.

Output

Return the maximal length of a sorted array you can obtain using Thanos sort. The elements of the array have to be sorted in non-decreasing order.

Examples

Input

4
1 2 2 4

Output

4

Input

8
11 12 1 2 13 14 3 4

Output

2

Input

4
7 6 5 4

Output

1

Note

In the first example the array is already sorted, so no finger snaps are required.

In the second example the array actually has a subarray of 4 sorted elements, but you can not remove elements from different sides of the array in one finger snap. Each time you have to remove either the whole first half or the whole second half, so you'll have to snap your fingers twice to get to a 2-element sorted array.

In the third example the array is sorted in decreasing order, so you can only save one element from the ultimate destruction.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<long long> arr;
long long thanos(long long l, long long r) {
  bool sorted = true;
  for (long long i = l + 1; i <= r; i++) {
    sorted &= (arr[i] >= arr[i - 1]);
  }
  if (sorted) return (r - l + 1);
  long long mid = (l + r) / 2;
  return max(thanos(l, mid), thanos(mid + 1, r));
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  arr.resize(n);
  for (long long &x : arr) cin >> x;
  cout << thanos(0, n - 1) << '\n';
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

There are two rooted trees, each with N vertices. The vertices of each tree are numbered 1 through N. In the first tree, the parent of Vertex i is Vertex A_i. Here, A_i=-1 if Vertex i is the root of the first tree. In the second tree, the parent of Vertex i is Vertex B_i. Here, B_i=-1 if Vertex i is the root of the second tree.

Snuke would like to construct an integer sequence of length N, X_1 , X_2 , ... , X_N, that satisfies the following condition:

* For each vertex on each tree, let the indices of its descendants including itself be a_1 , a_2 , ..., a_k. Then, abs(X_{a_1} + X_{a_2} + ... + X_{a_k})=1 holds.

Determine whether it is possible to construct such a sequence. If the answer is possible, find one such sequence.

Constraints

* 1 \leq N \leq 10^5
* 1 \leq A_i \leq N, if Vertex i is not the root in the first tree.
* A_i = -1, if Vertex i is the root in the first tree.
* 1 \leq B_i \leq N, if Vertex i is not the root in the second tree.
* B_i = -1, if Vertex i is the root in the second tree.
* Input corresponds to valid rooted trees.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 .. A_N
B_1 B_2 .. B_N

Output

If it is not possible to construct an integer sequence that satisfies the condition, print `IMPOSSIBLE`. If it is possible, print `POSSIBLE` in the first line. Then, in the second line, print X_1 , X_2 , ... , X_N, an integer sequence that satisfies the condition.

Examples

Input

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

Output

POSSIBLE
1 -1 -1 3 -1

Input

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

Output

IMPOSSIBLE

Input

8
2 7 1 2 2 1 -1 4
4 -1 4 7 4 4 2 4

Output

POSSIBLE
1 2 -1 0 -1 1 0 -1

### Response

```cpp
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=200010,M=300010;
struct edge{
	int y,next;
	bool f;
}data[M*2];
int n,h[N],num,cur[N],son1[N],son2[N],a[N];
inline int read(){
	int x=0,f=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f?-x:x;
}
inline void add(int x,int y){
	data[++num].y=y;data[num].next=h[x];h[x]=num;data[num].f=true;
	data[++num].y=x;data[num].next=h[y];h[y]=num;data[num].f=true;
}
void f(int x){
	for(int& i=cur[x];i!=-1;i=data[i].next){
		int v=data[i].y;
		if(data[i].f){
			data[i].f=data[i^1].f=false;
			//printf("%d %d\n",x,v);
			if(v==x+n&&x!=0)a[x]=1;
			if(v==x-n&&x!=n)a[x-n]=-1;
			f(v);
		}
	}
}
int main(){
	n=read();
	memset(h,-1,sizeof h);num=-1;
	memset(son1,0,sizeof son1);
	memset(son2,0,sizeof son2);
	for(int x,i=1;i<=n;i++){
		x=read();
		son1[x]++;
		if(x!=-1)add(x,i);
		else add(0,i);
	}
	for(int x,i=1;i<=n;i++){
		x=read();
		son2[x]++;
		if(x!=-1)add(x+n,i+n);
		else add(0,i+n);
	}
	for(int i=1;i<=n;i++){
		if((son1[i]%2)!=(son2[i]%2)){printf("IMPOSSIBLE");return 0;}
		if(son1[i]%2==0)add(i,i+n);
	}
	printf("POSSIBLE\n");
	//for(int i=1;i<=n;i++)printf("%d %d\n",son1[i],son2[i]);
	for(int i=0;i<=n*2;i++)cur[i]=h[i];
	memset(a,0,sizeof a);
	f(0);
	for(int i=1;i<=n;i++)printf("%d ",a[i]);
	return 0;
}
```


### Prompt

Develop a solution in CPP to the problem described below:

You are given two huge binary integer numbers a and b of lengths n and m respectively. You will repeat the following process: if b > 0, then add to the answer the value a~ \&~ b and divide b by 2 rounding down (i.e. remove the last digit of b), and repeat the process again, otherwise stop the process.

The value a~ \&~ b means bitwise AND of a and b. Your task is to calculate the answer modulo 998244353.

Note that you should add the value a~ \&~ b to the answer in decimal notation, not in binary. So your task is to calculate the answer in decimal notation. For example, if a = 1010_2~ (10_{10}) and b = 1000_2~ (8_{10}), then the value a~ \&~ b will be equal to 8, not to 1000.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the length of a and the length of b correspondingly.

The second line of the input contains one huge integer a. It is guaranteed that this number consists of exactly n zeroes and ones and the first digit is always 1.

The third line of the input contains one huge integer b. It is guaranteed that this number consists of exactly m zeroes and ones and the first digit is always 1.

Output

Print the answer to this problem in decimal notation modulo 998244353.

Examples

Input

4 4
1010
1101

Output

12

Input

4 5
1001
10101

Output

11

Note

The algorithm for the first example:

  1. add to the answer 1010_2~ \&~ 1101_2 = 1000_2 = 8_{10} and set b := 110;
  2. add to the answer 1010_2~ \&~ 110_2 = 10_2 = 2_{10} and set b := 11;
  3. add to the answer 1010_2~ \&~ 11_2 = 10_2 = 2_{10} and set b := 1;
  4. add to the answer 1010_2~ \&~ 1_2 = 0_2 = 0_{10} and set b := 0.

So the answer is 8 + 2 + 2 + 0 = 12.

The algorithm for the second example:

  1. add to the answer 1001_2~ \&~ 10101_2 = 1_2 = 1_{10} and set b := 1010;
  2. add to the answer 1001_2~ \&~ 1010_2 = 1000_2 = 8_{10} and set b := 101;
  3. add to the answer 1001_2~ \&~ 101_2 = 1_2 = 1_{10} and set b := 10;
  4. add to the answer 1001_2~ \&~ 10_2 = 0_2 = 0_{10} and set b := 1;
  5. add to the answer 1001_2~ \&~ 1_2 = 1_2 = 1_{10} and set b := 0.

So the answer is 1 + 8 + 1 + 0 + 1 = 11.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  string str1, str2;
  cin >> str1 >> str2;
  reverse(str1.begin(), str1.end());
  reverse(str2.begin(), str2.end());
  vector<long long> dp(m + 1, 0);
  for (int i = m - 1; i >= 0; i--) dp[i] = dp[i + 1] + ((str2[i] - '0') & 1);
  int ind = n;
  if (n > m) ind = m;
  vector<long long> ans(ind + 1, 1);
  for (int i = 1; i <= ind; i++) ans[i] = (ans[i - 1] * 2) % 998244353;
  long long total = 0;
  for (int i = 0; i < ind; i++) {
    if (str1[i] == '1')
      total = (total + (dp[i] * ans[i]) % 998244353) % 998244353;
  }
  cout << total % 998244353;
}

```


### Prompt

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

This is the easy version of the problem. The difference between the versions is that in the easy version all prices a_i are different. You can make hacks if and only if you solved both versions of the problem.

Today is Sage's birthday, and she will go shopping to buy ice spheres. All n ice spheres are placed in a row and they are numbered from 1 to n from left to right. Each ice sphere has a positive integer price. In this version all prices are different.

An ice sphere is cheap if it costs strictly less than two neighboring ice spheres: the nearest to the left and the nearest to the right. The leftmost and the rightmost ice spheres are not cheap. Sage will choose all cheap ice spheres and then buy only them.

You can visit the shop before Sage and reorder the ice spheres as you wish. Find out the maximum number of ice spheres that Sage can buy, and show how the ice spheres should be reordered.

Input

The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of ice spheres in the shop.

The second line contains n different integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the prices of ice spheres.

Output

In the first line print the maximum number of ice spheres that Sage can buy.

In the second line print the prices of ice spheres in the optimal order. If there are several correct answers, you can print any of them.

Example

Input

5
1 2 3 4 5

Output

2
3 1 4 2 5

Note

In the example it's not possible to place ice spheres in any order so that Sage would buy 3 of them. If the ice spheres are placed like this (3, 1, 4, 2, 5), then Sage will buy two spheres: one for 1 and one for 2, because they are cheap.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, i;
  cin >> n;
  long long a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (n < 3) {
    cout << "0" << endl;
    for (i = 0; i < n; i++) cout << a[i] << " ";
  } else {
    sort(a, a + n);
    long l = 0, r = n - 1;
    cout << n / 2 - (n % 2 == 0) << endl;
    for (i = 0; i < n; i++) {
      if (i % 2 == 0) {
        cout << a[r] << " ";
        r--;
      } else {
        cout << a[l] << " ";
        l++;
      }
    }
  }
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Peter decided to lay a parquet in the room of size n × m, the parquet consists of tiles of size 1 × 2. When the workers laid the parquet, it became clear that the tiles pattern looks not like Peter likes, and workers will have to re-lay it.

The workers decided that removing entire parquet and then laying it again is very difficult task, so they decided to make such an operation every hour: remove two tiles, which form a 2 × 2 square, rotate them 90 degrees and put them back on the same place.

<image>

They have no idea how to obtain the desired configuration using these operations, and whether it is possible at all.

Help Peter to make a plan for the workers or tell that it is impossible. The plan should contain at most 100 000 commands.

Input

The first line contains integer n and m, size of the room (1 ≤ n, m ≤ 50). At least one of them is even number.

The following n lines contain m characters each, the description of the current configuration of the parquet tiles. Each character represents the position of the half-tile. Characters 'L', 'R', 'U' and 'D' correspond to the left, right, upper and lower halves, respectively.

The following n lines contain m characters each, describing the desired configuration in the same format.

Output

In the first line output integer k, the number of operations. In the next k lines output description of operations. The operation is specified by coordinates (row and column) of the left upper half-tile on which the operation is performed.

If there is no solution, output -1 in the first line.

Examples

Input

2 3
ULR
DLR
LRU
LRD

Output

2
1 2
1 1

Input

4 3
ULR
DLR
LRU
LRD
ULR
DUU
UDD
DLR

Output

3
3 1
3 2
2 2

Note

In the first sample test first operation is to rotate two rightmost tiles, after this all tiles lie vertically. Second operation is to rotate two leftmost tiles, after this we will get desired configuration.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string arr[55], arr2[55];
vector<pair<int, int> > hasil;
int i, j, n, t, tc, r, x, y, k, c;
void tuker_lr(int x, int y) {
  arr[x][y] = 'U';
  arr[x + 1][y] = 'D';
  arr[x][y + 1] = 'U';
  arr[x + 1][y + 1] = 'D';
}
void tuker_ud(int x, int y) {
  arr[x][y] = 'L';
  arr[x][y + 1] = 'R';
  arr[x + 1][y] = 'L';
  arr[x + 1][y + 1] = 'R';
}
void l_u_ganjil(int x, int y) {
  if (arr[x + 1][y] == 'L') {
    tuker_lr(x, y);
    hasil.push_back(make_pair(x, y));
  } else if (arr[x + 1][y + 1] == 'U') {
    tuker_ud(x + 1, y);
    hasil.push_back(make_pair(x + 1, y));
    tuker_lr(x, y);
    hasil.push_back(make_pair(x, y));
  } else {
    l_u_ganjil(x + 1, y + 1);
    tuker_ud(x + 1, y);
    hasil.push_back(make_pair(x + 1, y));
    tuker_lr(x, y);
    hasil.push_back(make_pair(x, y));
  }
}
void u_d_ganjil(int x, int y) {
  if (arr[x][y + 1] == 'U') {
    tuker_ud(x, y);
    hasil.push_back(make_pair(x, y));
  } else if (arr[x][y + 1] == 'L') {
    l_u_ganjil(x, y + 1);
    tuker_ud(x, y);
    hasil.push_back(make_pair(x, y));
  } else {
    u_d_ganjil(x - 1, y + 1);
    l_u_ganjil(x, y + 1);
    tuker_ud(x, y);
    hasil.push_back(make_pair(x, y));
  }
}
int main() {
  scanf("%d %d", &r, &c);
  for (i = 0; i < r; i++) cin >> arr[i];
  for (i = 0; i < r; i++) cin >> arr2[i];
  if (c % 2 == 1) {
    for (j = 0; j < c; j++)
      for (i = 0; i < r; i++)
        if (arr[i][j] == 'L') l_u_ganjil(i, j);
  } else {
    for (j = 0; j < c; j++)
      for (i = 0; i < r; i++)
        if (arr[i][j] == 'U') u_d_ganjil(i, j);
  }
  for (j = 0; j < c; j++) {
    for (i = 0; i < r; i++) {
      if (arr[i][j] == arr2[i][j])
        continue;
      else if (arr[i][j] == 'U')
        u_d_ganjil(i, j);
      else
        l_u_ganjil(i, j);
    }
  }
  printf("%d\n", hasil.size());
  for (i = 0; i < hasil.size(); i++)
    printf("%d %d\n", hasil[i].first + 1, hasil[i].second + 1);
}

```


### Prompt

Please create a solution in CPP to the following problem:

We are given a permutation sequence a1, a2, ..., an of numbers from 1 to n. Let's assume that in one second, we can choose some disjoint pairs (u1, v1), (u2, v2), ..., (uk, vk) and swap all aui and avi for every i at the same time (1 ≤ ui < vi ≤ n). The pairs are disjoint if every ui and vj are different from each other.

We want to sort the sequence completely in increasing order as fast as possible. Given the initial permutation, calculate the number of ways to achieve this. Two ways are different if and only if there is a time t, such that the set of pairs used for swapping at that time are different as sets (so ordering of pairs doesn't matter). If the given permutation is already sorted, it takes no time to sort, so the number of ways to sort it is 1.

To make the problem more interesting, we have k holes inside the permutation. So exactly k numbers of a1, a2, ..., an are not yet determined. For every possibility of filling the holes, calculate the number of ways, and print the total sum of these values modulo 1000000007 (109 + 7).

Input

The first line contains two integers n (1 ≤ n ≤ 105) and k (0 ≤ k ≤ 12). The second line contains the permutation sequence a1, ..., an (0 ≤ ai ≤ n). If a number is not yet determined, it is denoted as 0. There are exactly k zeroes. All the numbers ai that aren't equal to zero are distinct.

Output

Print the total sum of the number of ways modulo 1000000007 (109 + 7).

Examples

Input

5 0
1 5 2 4 3

Output

6

Input

5 2
1 0 2 4 0

Output

7

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> v[100005], l, sm[1 << 12];
int c[100005], p[100005], ip[100005];
int f[20];
bool s[100005];
int n, k;
void calc(int i) {
  v[i][0] = 1;
  v[i][1] = i;
  for (int j = (2); j < (int(v[i].size())); j++)
    v[i][j] = (i * (v[i][j - 1] + (j - 1) * 1ll * v[i][j - 2])) % 1000000007ll;
}
long long ans = 0;
void go(int m, int cr, bool r2) {
  if (m == 0) {
    if (r2)
      ans += cr;
    else
      ans += 1;
    if (ans >= 1000000007ll) ans -= 1000000007ll;
  } else {
    int t = 1 << __builtin_ctz(m);
    for (int st : sm[m ^ t]) {
      int gc = st | t;
      int nm = m ^ gc;
      int os = 0;
      int ml = 0;
      long long nr = cr;
      while (gc) {
        int ind = __builtin_ctz(gc);
        os += l[ind];
        gc ^= 1 << ind;
        ml++;
      }
      c[os]++;
      nr = (nr * v[os][c[os]]) % 1000000007ll;
      nr = (nr * f[ml - 1]) % 1000000007ll;
      go(nm, nr, r2 || (os > 2));
      c[os]--;
    }
  }
}
long long pw(long long a, long long b) {
  long long r = 1;
  while (b) {
    if (b & 1) r = (r * a) % 1000000007ll;
    a = (a * a) % 1000000007ll;
    b /= 2;
  }
  return r;
}
long long inv(long long x) { return pw(x, 1000000007ll - 2); }
int main() {
  scanf("%d%d", &n, &k);
  f[0] = 1;
  for (int i = (1); i < (20); i++) f[i] = (f[i - 1] * 1ll * i) % 1000000007ll;
  for (int i = (0); i < (1 << k); i++) {
    for (int j = (0); j < (1 << k); j++)
      if ((i & j) == j) {
        sm[i].push_back(j);
      }
  }
  for (int i = (1); i < (n + 1); i++) {
    scanf("%d", p + i);
    if (p[i]) ip[p[i]] = i;
  }
  for (int i = (1); i < (n + 1); i++)
    if (!ip[i]) {
      int r = 0;
      for (int j = i; j; j = p[j]) {
        s[j] = true;
        r++;
      }
      l.push_back(r);
    }
  assert(int(l.size()) == k);
  for (int i = (1); i < (n + 1); i++)
    if (!s[i]) {
      int r = 0;
      for (int j = i; !s[j]; j = p[j]) {
        s[j] = true;
        r++;
      }
      c[r]++;
    }
  long long res = 1;
  bool r2 = false;
  for (int i = (1); i < (n + 1); i++) {
    v[i].resize(c[i] + 13);
    calc(i);
    res = (res * v[i][c[i]]) % 1000000007ll;
    r2 |= c[i] && i > 2;
    for (int j = int(v[i].size()) - 1; j >= 1; j--) {
      v[i][j] = (v[i][j] * 1ll * inv(v[i][j - 1])) % 1000000007ll;
    }
  }
  go((1 << k) - 1, res, r2);
  printf("%lld\n", ans);
}

```


### Prompt

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

Consider the following game for two players. There is one white token and some number of black tokens. Each token is placed on a plane in a point with integer coordinates x and y.

The players take turn making moves, white starts. On each turn, a player moves all tokens of their color by 1 to up, down, left or right. Black player can choose directions for each token independently.

After a turn of the white player the white token can not be in a point where a black token is located. There are no other constraints on locations of the tokens: positions of black tokens can coincide, after a turn of the black player and initially the white token can be in the same point with some black point. If at some moment the white player can't make a move, he loses. If the white player makes 10100500 moves, he wins.

You are to solve the following problem. You are given initial positions of all black tokens. It is guaranteed that initially all these positions are distinct. In how many places can the white token be located initially so that if both players play optimally, the black player wins?

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of black points.

The (i + 1)-th line contains two integers xi, yi ( - 105 ≤ xi, yi, ≤ 105) — the coordinates of the point where the i-th black token is initially located.

It is guaranteed that initial positions of black tokens are distinct.

Output

Print the number of points where the white token can be located initially, such that if both players play optimally, the black player wins.

Examples

Input

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

Output

4

Input

4
-2 0
-1 1
0 -2
1 -1

Output

2

Input

16
2 1
1 2
-1 1
0 1
0 0
1 1
2 -1
2 0
1 0
-1 -1
1 -1
2 2
0 -1
-1 0
0 2
-1 2

Output

4

Note

In the first and second examples initial positions of black tokens are shown with black points, possible positions of the white token (such that the black player wins) are shown with white points.

The first example: <image>

The second example: <image>

In the third example the white tokens should be located in the inner square 2 × 2, to make the black player win. <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void amin(T &x, const T &y) {
  if (y < x) x = y;
}
template <class T>
inline void amax(T &x, const T &y) {
  if (x < y) x = y;
}
template <class Iter>
void rprintf(const char *fmt, Iter begin, Iter end) {
  for (bool sp = 0; begin != end; ++begin) {
    if (sp)
      putchar(' ');
    else
      sp = true;
    printf(fmt, *begin);
  }
  putchar('\n');
}
int Y_high[1000111], Y_low[1000111];
long long solve(vector<pair<int, int> > ps) {
  if ((int)ps.size() < 4) return 0;
  sort(ps.begin(), ps.end());
  int left = ps[0].first, right = ps.back().first;
  int cur = 0;
  const int INF = 1 << 29;
  int y_high = -INF, y_low = INF;
  for (int x = left + 1; x < right; x += 2) {
    while (cur < (int)ps.size() && ps[cur].first < x) {
      amax(y_high, ps[cur].second);
      amin(y_low, ps[cur].second);
      cur++;
    }
    Y_high[x - left] = y_high;
    Y_low[x - left] = y_low;
  }
  long long ret = 0;
  cur = ps.size() - 1;
  y_high = -INF;
  y_low = INF;
  for (int x = right - 1; x > left; x -= 2) {
    while (cur && x < ps[cur].first) {
      amax(y_high, ps[cur].second);
      amin(y_low, ps[cur].second);
      cur--;
    }
    int hi = min(Y_high[x - left], y_high);
    int lo = max(Y_low[x - left], y_low);
    if (hi > lo) ret += (hi - lo) / 2;
  }
  return ret;
}
int N;
void MAIN() {
  scanf("%d", &N);
  vector<pair<int, int> > odd, even;
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    int xx = x + y, yy = x - y;
    if (xx & 1) {
      odd.emplace_back(xx + 1, yy + 1);
    } else {
      even.emplace_back(xx, yy);
    }
  }
  long long ans = solve(odd) + solve(even);
  printf("%lld\n", ans);
}
int main() {
  int TC = 1;
  for (int tc = 0, tc_len = (TC); tc < tc_len; ++tc) MAIN();
  return 0;
}

```


### Prompt

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

Matrix of given integers

a1,1 a1,2 ... a1, n
a2,1 a2,2 ... a2, n
::
an, 1 an, 2 ... an, n

Then, create a program that outputs the maximum value of the sum of one or more consecutive terms (submatrix) in the vertical and horizontal directions and ends.

Input

The input data is given in the following format.

n
a1,1 a1,2 ... a1, n
a2,1 a2,2 ... a2, n
::
an, 1 an, 2 ... an, n

n is 1 or more and 100 or less, and ai, j is -10000 or more and 10000 or less.

Output

Print the maximum value on one line.

Examples

Input

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

Output

16

Input

4
1 3 -9 2
2 7 -1 5
-8 3 2 -1
5 0 -3 1

Output

15

### Response

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

int n;
int t[102][102];
int sum[102][102];

int main(){
  while(cin >> n){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        cin >> t[i][j];

        sum[i][j] = t[i][j]
          + (0 <= i - 1 ? sum[i - 1][j] : 0)
          + (0 <= j - 1 ? sum[i][j - 1] : 0)
          - (0 <= i - 1 && 0 <= j - 1 ? sum[i - 1][j - 1] : 0);
      }
    }

    int ans = INT_MIN;

    for(int si = 0; si < n; si++){
      for(int sj = 0; sj < n; sj++){
        for(int gi = si; gi < n; gi++){
          for(int gj = sj; gj < n; gj++){
            int calc = sum[gi][gj]
              - (0 <= si - 1 ? sum[si - 1][gj] : 0)
              - (0 <= sj - 1 ? sum[gi][sj - 1] : 0)
              + (0 <= si - 1 && 0 <= sj - 1 ? sum[si - 1][sj - 1] : 0);

            ans = max(ans, calc);
          }
        }
      }
    }

    cout << ans << endl;
  }
}
```


### Prompt

Create a solution in cpp for the following problem:

Peace, which was supposed to last forever, suddenly ended. The Demon King, who had been sealed long ago, has finally revived. But when the world was about to be covered in darkness, a brave man appeared. The hero then set out on a journey to collect legendary crystals scattered around the world. Legend has it that if you can collect all the crystals, you can summon the legendary dragon god who can fulfill any wish. With the help of the dragon god, it should be possible to defeat the Demon King.

Crystals are scattered all over the world. The hero needs to collect them one by one by his own hands. This is because if someone other than the hero gets the crystal, it may be stolen by the Demon King's minions. A hero can travel only one Euclidean distance per day.

But there is one serious problem here. The Demon King constantly disperses the darkness of the miasma, and the place contaminated with the miasma turns into a land of death that no one can enter. Even a brave man cannot enter the place. Furthermore, since the miasma spreads concentrically with time, the area where the hero can move decreases with the passage of time. Miasma has been confirmed to spread by an Euclidean distance of 1 per day. And the hero cannot take the crystal on the boundary line. We also know that the newly resurrected Demon King will not move to store power.

The hero must get the crystal as soon as possible. But if it's not possible to get all the crystals, you'll have to think of another way. Therefore, I would like you to create a program to find out if you can get all the crystals from the initial position of the hero, the place where the demon king was resurrected, and the position where the crystals exist.

By the way, the brave does not get tired. And I don't sleep. Keep moving and collect crystals until you collect all the crystals and save the world! !!

Input

The input consists of multiple test cases. The first line of each test case gives the five integers n (0 <n <= 20), hx, hy, dx, and dy. n is the number of crystals, (hx, hy) is the position of the hero at the moment the Demon King was resurrected, and (dx, dy) is the position where the Demon King was resurrected. The n lines that follow are given the two integers cx, cy, that represent the position of each crystal. Input ends when n = hx = hy = dx = dy = 0, which is not included in the test case.

All coordinates given in the input are guaranteed to be integers with an absolute value of 1000 or less.

Output

For each test case, output "YES" if you can collect all the crystals, and "NO" if not.

Example

Input

2 0 0 10 10
1 1
4 4
2 0 0 10 10
1 1
6 6
2 0 0 10 10
1 1
5 5
0 0 0 0 0

Output

YES
NO
NO

### Response

```cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
vi x,y;
int n,a,b,c,d;
bool f(int q,int nx,int ny,double t){
	if(q==(1<<n)-1)return 1;
	rep(i,n)if((q&1<<i)==0&&(hypot(nx-x[i],ny-y[i])+t+EPS>hypot(c-x[i],d-y[i])))return 0;
	rep(i,n)if((q&1<<i)==0&&f(q^1<<i,x[i],y[i],t+hypot(nx-x[i],ny-y[i])))return 1;
	return 0;
}
int main(){
	while(cin>>n,n){
		cin>>a>>b>>c>>d;
		y=x=vi(n);
		rep(i,n)cin>>x[i]>>y[i];
		cout<<(f(0,a,b,0)?"YES":"NO")<<endl;
	}
	cin>>n>>n>>n>>n;
}
```


### Prompt

Please formulate a cpp solution to the following problem:

Example

Input

3 3 1 2 4
1 2
2 3
3 1

Output

IMPOSSIBLE

### Response

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

using namespace std;

const int inf = 0x3f3f3f3f;

struct Node {
	int d, x;
	Node(int _x = 0, int _d = 0):d(_d), x(_x) {}
};

int n, m, X[5], u, v;
int S[5][60][60];
int dis[60];
vector <int> G[60];
queue <Node> Q;
bool vis[60][200];

void BFS(int u) {
	memset(vis, 0, sizeof(vis));
	while(!Q.empty()) Q.pop();
	Q.push(Node(u, 0)); vis[u][0] = 1;
	while(!Q.empty()) {
		int x = Q.front().x, d = Q.front().d; Q.pop();
		for(int i = 0; i < 3; i ++) if(d == X[i]) {
			S[i][x][u] = 1;
		}
		if(d == X[2]) continue;
		for(unsigned i = 0; i < G[x].size(); i ++) {
			int y = G[x][i];
			if(!vis[y][d+1]) {
				Q.push(Node(y, d+1));
				vis[y][d+1] = 1;
			}
		}
	}
}

int main() {
	//freopen("C.in", "r", stdin);
	scanf("%d%d%d%d%d", &n, &m, &X[0], &X[1], &X[2]);
	sort(X, X+3);
	for(int i = 0; i < m; i ++) {
		scanf("%d%d", &u, &v);
		G[v].push_back(u);
	}
	memset(S, 0, sizeof(S));
	for(int i = 1; i <= n; i ++) BFS(i);

	memset(dis, 0x3f, sizeof(dis));
	dis[n] = 0;
	for(int p = 1; p <= 2*n; p ++) {
		for(int i = 1; i <= n; i ++) {
			int Mx = 0;
			for(int k = 0; k < 3; k ++) {
				int Mn = inf;
				for(int j = 1; j <= n; j ++) if(S[k][i][j]) {
					Mn = min(Mn, dis[j]);
				}
				Mx = max(Mx, Mn);
			}
			dis[i] = min(dis[i], Mx+1);
		}
	}

	if(dis[1] == inf) printf("IMPOSSIBLE\n");
	else printf("%d\n", dis[1]);
	return 0;
}
```


### Prompt

Please formulate a Cpp solution to the following problem:

In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road either from city a to city b, or from city b to city a. The road network is such that from any city you can get to any other one by moving along the roads.

You want to destroy the largest possible number of roads in the country so that the remaining roads would allow you to get from city s1 to city t1 in at most l1 hours and get from city s2 to city t2 in at most l2 hours.

Determine what maximum number of roads you need to destroy in order to meet the condition of your plan. If it is impossible to reach the desired result, print -1.

Input

The first line contains two integers n, m (1 ≤ n ≤ 3000, <image>) — the number of cities and roads in the country, respectively.

Next m lines contain the descriptions of the roads as pairs of integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi). It is guaranteed that the roads that are given in the description can transport you from any city to any other one. It is guaranteed that each pair of cities has at most one road between them.

The last two lines contains three integers each, s1, t1, l1 and s2, t2, l2, respectively (1 ≤ si, ti ≤ n, 0 ≤ li ≤ n).

Output

Print a single number — the answer to the problem. If the it is impossible to meet the conditions, print -1.

Examples

Input

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

Output

0

Input

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

Output

1

Input

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

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 3;
const int inf = 1e9;
int n, m;
int a, b;
vector<int> v[N];
int s1, t1, l1, s2, t2, l2;
int dist[N][N];
int ans;
void bfs(int start) {
  for (int i = 1; i <= n; ++i) {
    dist[start][i] = inf;
  }
  dist[start][start] = 0;
  queue<int> q;
  q.push(start);
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    for (int next : v[node]) {
      if (dist[start][next] > dist[start][node] + 1) {
        dist[start][next] = dist[start][node] + 1;
        q.push(next);
      }
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d", &a, &b);
    v[a].emplace_back(b);
    v[b].emplace_back(a);
  }
  scanf("%d %d %d %d %d %d", &s1, &t1, &l1, &s2, &t2, &l2);
  for (int i = 1; i <= n; ++i) {
    bfs(i);
  }
  if (dist[s1][t1] > l1 || dist[s2][t2] > l2) {
    printf("-1\n");
    return 0;
  }
  ans = m - dist[s1][t1] - dist[s2][t2];
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (dist[s1][i] + dist[j][t1] + dist[i][j] <= l1 &&
          dist[s2][i] + dist[j][t2] + dist[i][j] <= l2) {
        ans = max(ans, m - (dist[s1][i] + dist[s2][i] + dist[j][t1] +
                            dist[j][t2] + dist[i][j]));
      }
      if (dist[s1][i] + dist[j][t1] + dist[i][j] <= l1 &&
          dist[s2][j] + dist[i][t2] + dist[i][j] <= l2) {
        ans = max(ans, m - (dist[s1][i] + dist[s2][j] + dist[j][t1] +
                            dist[i][t2] + dist[i][j]));
      }
    }
  }
  printf("%d\n", ans);
}

```


### Prompt

Generate a CPP solution to the following problem:

Yaroslav has an array, consisting of (2·n - 1) integers. In a single operation Yaroslav can change the sign of exactly n elements in the array. In other words, in one operation Yaroslav can select exactly n array elements, and multiply each of them by -1.

Yaroslav is now wondering: what maximum sum of array elements can be obtained if it is allowed to perform any number of described operations?

Help Yaroslav.

Input

The first line contains an integer n (2 ≤ n ≤ 100). The second line contains (2·n - 1) integers — the array elements. The array elements do not exceed 1000 in their absolute value.

Output

In a single line print the answer to the problem — the maximum sum that Yaroslav can get.

Examples

Input

2
50 50 50

Output

150

Input

2
-1 -100 -1

Output

100

Note

In the first sample you do not need to change anything. The sum of elements equals 150.

In the second sample you need to change the sign of the first two elements. Then we get the sum of the elements equal to 100.

### Response

```cpp
#include <bits/stdc++.h>
int a[100200], b[100200];
int bs(int);
void burbuja(int n);
int main() {
  int n, all, i, neg, j, sum, min;
  scanf("%d", &n);
  n = bs(n);
  all = 2 * n - 1;
  if (n % 2) n = all;
  scanf("%d", &a[0]);
  min = bs(a[0]);
  neg = 0;
  for (i = 1; i < all; i++) {
    scanf("%d", &a[i]);
    if (bs(a[i]) < min) min = bs(a[i]);
  }
  burbuja(all);
  for (i = j = 0; i < all; i++) {
    if (a[i] < 0) a[i] = -a[i], neg++;
  }
  for (sum = i = 0; i < all; i++) {
    sum += a[i];
  }
  printf("%d\n", (n % 2 == 0 && neg && neg % 2) ? sum - (2 * min) : sum);
}
void burbuja(int all) {
  int i, j, aux;
  for (i = 0; i < all - 1; i++) {
    for (j = 0; j < all - 1 - i; j++) {
      if ((a[j]) > (a[j + 1])) {
        aux = a[j];
        a[j] = a[j + 1];
        a[j + 1] = aux;
      }
    }
  }
}
int bs(int a) { return (a < 0) ? -a : a; }

```


### Prompt

Develop a solution in cpp to the problem described below:

Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store.

Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the greatest common divisor of numbers of the apples in each group must be greater than 1. Of course, each apple can be part of at most one group.

Jzzhu wonders how to get the maximum possible number of groups. Can you help him?

Input

A single integer n (1 ≤ n ≤ 105), the number of the apples.

Output

The first line must contain a single integer m, representing the maximum number of groups he can get. Each of the next m lines must contain two integers — the numbers of apples in the current group.

If there are several optimal answers you can print any of them.

Examples

Input

6

Output

2
6 3
2 4

Input

9

Output

3
9 3
2 4
6 8

Input

2

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mn = 2e5 + 10;
bool p[mn], u[mn];
vector<pair<int, int> > v;
int f;
int main() {
  int n, i, j;
  scanf("%d", &n);
  memset(p, 1, sizeof(p));
  p[0] = p[1] = 0;
  for (i = 2; i * i <= n; i++)
    if (p[i])
      for (j = i * i; j <= n; j += i) p[j] = 0;
  for (i = 3; i <= n; i++) {
    if (!p[i]) continue;
    int num = 0;
    for (j = i; j <= n; j += i)
      if (!u[j]) num++;
    if (num < 2) continue;
    int f = i;
    u[f] = 1;
    for (j = (num & 1) ? (3 * i) : (2 * i); j <= n; j += i) {
      if (u[j]) continue;
      u[j] = 1;
      if (f)
        v.push_back({f, j}), f = 0;
      else
        f = j;
    }
  }
  i = 2;
  int f = i;
  u[f] = 1;
  for (j = 2 * i; j <= n; j += i) {
    if (u[j]) continue;
    u[j] = 1;
    if (f)
      v.push_back({f, j}), f = 0;
    else
      f = j;
  }
  printf("%d\n", v.size());
  for (pair<int, int> p : v) printf("%d %d\n", p.first, p.second);
}

```


### Prompt

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

A balancing network is an abstract device built up of N wires, thought of as running from left to right, and M balancers that connect pairs of wires. The wires are numbered from 1 to N from top to bottom, and the balancers are numbered from 1 to M from left to right. Balancer i connects wires x_i and y_i (x_i < y_i).

pic1-small-2acea94b.png

Each balancer must be in one of two states: up or down.

Consider a token that starts moving to the right along some wire at a point to the left of all balancers. During the process, the token passes through each balancer exactly once. Whenever the token encounters balancer i, the following happens:

* If the token is moving along wire x_i and balancer i is in the down state, the token moves down to wire y_i and continues moving to the right.
* If the token is moving along wire y_i and balancer i is in the up state, the token moves up to wire x_i and continues moving to the right.
* Otherwise, the token doesn't change the wire it's moving along.

Let a state of the balancing network be a string of length M, describing the states of all balancers. The i-th character is `^` if balancer i is in the up state, and `v` if balancer i is in the down state.

A state of the balancing network is called uniforming if a wire w exists such that, regardless of the starting wire, the token will always end up at wire w and run to infinity along it. Any other state is called non-uniforming.

You are given an integer T (1 \le T \le 2). Answer the following question:

* If T = 1, find any uniforming state of the network or determine that it doesn't exist.
* If T = 2, find any non-uniforming state of the network or determine that it doesn't exist.

Note that if you answer just one kind of questions correctly, you can get partial score.

Constraints

* 2 \leq N \leq 50000
* 1 \leq M \leq 100000
* 1 \leq T \leq 2
* 1 \leq x_i < y_i \leq N
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N M T
x_1 y_1
x_2 y_2
:
x_M y_M

Output

Print any uniforming state of the given network if T = 1, or any non-uniforming state if T = 2. If the required state doesn't exist, output `-1`.

Examples

Input

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

Output

^^^^^

Input

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

Output

v^^^^

Input

3 1 1
1 2

Output

-1

Input

2 1 2
1 2

Output

-1

### Response

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

// N*M = 5,000,000,000 -> 5/8 GB
// N*N = 2,500,000,000 -> 2.5/8 GB

const int MAX_N = 50123;

int n, m, T;
vector<pair<int,int>> balancers;

void one() {
	vector<bitset<MAX_N>> mask(n);
	for(int i = 0; i < n; ++i) {
		mask[i][i] = 1;
	}
	for(pair<int,int> p : balancers) {
		mask[p.first] |= mask[p.second];
		mask[p.second] = mask[p.first];
	}
	int last = -1;
	for(int i = 0; i < n; ++i) {
		if((int) mask[i].count() == n) {
			last = i;
			break;
		}
	}
	if(last == -1) {
		puts("-1");
		exit(0);
	}
	vector<bool> good(n);
	good[last] = true;
	string s(m, '?');
	for(int i = m - 1; i >= 0; --i) {
		int x = balancers[i].first;
		int y = balancers[i].second;
		if(good[x]) {
			s[i] = '^';
			good[y] = true;
		}
		else if(good[y]) {
			s[i] = 'v';
			good[x] = true;
		}
		else {
			s[i] = 'v';
		}
	}
	printf("%s\n", s.c_str());
}

vector<pair<int, pair<int,int>>> parent[1000][1000];
vector<vector<bool>> good;
void can_go(int a, int b, int c, int d, int tim) {
	if(good[a][b] && !good[c][d]) {
		good[c][d] = true;
		parent[c][d].push_back({tim, {a, b}});
	}
}

void two() {
	assert(T == 2);
	set<pair<int,int>> set;
	for(pair<int,int> p : balancers) {
		set.insert(p);
	}
	for(int i = 0; i < n; ++i) {
		for(int j = i + 1; j < n; ++j) {
			if(!set.count({i, j})) {
				string s;
				for(pair<int,int> p : balancers) {
					assert(p != make_pair(i, j));
					if(p.first == i || p.first == j) {
						s += '^';
					}
					else if(p.second == i || p.second == j) {
						s += 'v';
					}
					else {
						s += 'v';
					}
				}
				printf("%s\n", s.c_str());
				cerr << "pair is " << i << " " << j << endl;
				exit(0);
			}
		}
	}
	cerr << "N is for sure small!" << endl;
	assert(n < 1000);
	good.resize(n, vector<bool>(n));
	// vector<vector<bool>> good(n, vector<bool>(n));
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			if(i != j) {
				good[i][j] = true;
			}
		}
	}

	for(int tim = 0; tim < m; ++tim) {
		pair<int,int> p = balancers[tim];
		int x = p.first;
		int y = p.second;
		good[x][y] = good[y][x] = false;
		for(int i = 0; i < n; ++i) {
			if(i != x && i != y) {
				// can_go(i, x, i, x, tim);
				can_go(i, x, i, y, tim);
				can_go(i, y, i, x, tim);
				can_go(x, i, y, i, tim);
				can_go(y, i, x, i, tim);
			}
		}
	}
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			assert(good[i][j] == good[j][i]);
			if(i < j && good[i][j]) {
				string s(m, '?');
				// printf("%d %d\n", i, j);
				// printf("YES %d %d\n", i, j);
				int tim = m;
				auto move_down_to = [&](int new_time) { // tim-1 ... new_time
					for(int b = tim - 1; b >= new_time; --b) {
						int x = balancers[b].first;
						int y = balancers[b].second;
						assert(make_pair(min(i, j), max(i, j)) != make_pair(x, y));
						assert(s[b] == '?');
						if(x == i || x == j) {
							s[b] = '^';
						}
						else if(y == i || y == j) {
							s[b] = 'v';
						}
						else {
							s[b] = 'v';
						}
					}
				};
				while(!parent[i][j].empty()) {
					pair<int, pair<int,int>> pp = parent[i][j].back();
					if(pp.first > tim) {
						parent[i][j].pop_back();
					}
					else {
						assert(pp.first < tim);
						move_down_to(pp.first + 1);
						tim = pp.first;
						assert(0 <= tim && tim < m);
						assert(s[tim] == '?');
						assert((i == pp.second.first) != (j == pp.second.second));
						if(make_pair(i, j) < pp.second) {
							s[tim] = '^';
						}
						else {
							s[tim] = 'v';
						}
						tie(i, j) = pp.second;
						// printf("%d %d time=%d\n", i, j, tim);
					}
				}
				move_down_to(0);
				for(char ch : s) {
					assert(ch != '?');
				}
				// assert(false);
				printf("%s\n", s.c_str());
				exit(0);
			}
		}
	}
	puts("-1");
}

int main() {
	scanf("%d%d%d", &n, &m, &T);
	balancers.resize(m);
	for(pair<int,int>& p : balancers) {
		scanf("%d%d", &p.first, &p.second);
		--p.first;
		--p.second;
	}
	if(T == 1) {
		one();
	}
	else {
		two();
	}
}

```


### Prompt

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

Nagini, being a horcrux You-know-who created with the murder of Bertha Jorkins, has accumulated its army of snakes and is launching an attack on Hogwarts school.

Hogwarts' entrance can be imagined as a straight line (x-axis) from 1 to 105. Nagini is launching various snakes at the Hogwarts entrance. Each snake lands parallel to the entrance, covering a segment at a distance k from x = l to x = r. Formally, each snake can be imagined as being a line segment between points (l, k) and (r, k). Note that k can be both positive and negative, but not 0.

Let, at some x-coordinate x = i, there be snakes at point (i, y1) and point (i, y2), such that y1 > 0 and y2 < 0. Then, if for any point (i, y3) containing a snake such that y3 > 0, y1 ≤ y3 holds and for any point (i, y4) containing a snake such that y4 < 0, |y2| ≤ |y4| holds, then the danger value at coordinate x = i is y1 + |y2|. If no such y1 and y2 exist, danger value is 0.

Harry wants to calculate the danger value of various segments of the Hogwarts entrance. Danger value for a segment [l, r) of the entrance can be calculated by taking the sum of danger values for each integer x-coordinate present in the segment.

Formally, you have to implement two types of queries:

  * 1 l r k: a snake is added parallel to entrance from x = l to x = r at y-coordinate y = k (l inclusive, r exclusive).
  * 2 l r: you have to calculate the danger value of segment l to r (l inclusive, r exclusive).

Input

First line of input contains a single integer q (1 ≤ q ≤ 5·104) denoting the number of queries.

Next q lines each describe a query. Each query description first contains the query type typei (1 ≤ typei ≤ 2). This is followed by further description of the query. In case of the type being 1, it is followed by integers li, ri and ki (<image>,  - 109 ≤ ki ≤ 109, k ≠ 0). Otherwise, it just contains two integers, li and ri (1 ≤ li < ri ≤ 105).

Output

Output the answer for each query of type 2 in a separate line.

Examples

Input

3
1 1 10 10
1 2 4 -7
2 1 10

Output

34

Input

7
1 2 3 5
1 1 10 10
1 4 5 -5
2 4 8
1 1 10 -10
2 4 8
2 1 10

Output

15
75
170

Note

In the first sample case, the danger value for x-coordinates 1 is 0 as there is no y2 satisfying the above condition for x = 1.

Danger values for x-coordinates 2 and 3 is 10 + | - 7| = 17.

Danger values for x-coordinates 4 to 9 is again 0 as there is no y2 satisfying the above condition for these coordinates.

Thus, total danger value is 17 + 17 = 34.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = (int)1e5;
const int INF = (int)1e9 + 10;
struct SegmTree {
  struct Node {
    int max1 = INF, max2 = -1, freq1 = 0, lazy = INF, cnt = 0;
    int64_t sum = 0;
    void Apply() {
      if (lazy > max1) return;
      assert(lazy != INF && lazy > max2);
      sum -= 1LL * (max1 - lazy) * freq1;
      max1 = lazy;
    }
  };
  int n;
  vector<Node> t;
  SegmTree(int n_) : n(n_) {
    int sz = 1;
    while (sz < n) sz <<= 1;
    t.resize(2 * sz);
  }
  void Recalc(int node) {
    t[node].sum = t[2 * node + 1].sum + t[2 * node + 2].sum;
    t[node].cnt = t[2 * node + 1].cnt + t[2 * node + 2].cnt;
    map<int, int> mp;
    for (int i = 1; i <= 2; ++i) {
      int son = 2 * node + i;
      mp[t[son].max1] += t[son].freq1;
      mp[t[son].max2] = 0;
    }
    auto it = mp.end();
    --it;
    tie(t[node].max1, t[node].freq1) = *it;
    t[node].max2 = (--it)->first;
  }
  void Push(int node) {
    if (t[node].lazy == INF) return;
    for (int i = 1; i <= 2; ++i) {
      int son = 2 * node + i;
      t[son].lazy = min(t[son].lazy, t[node].lazy);
      t[son].Apply();
    }
    t[node].lazy = INF;
  }
  void Use(int node, int left, int right, int pos) {
    if (left == right) {
      t[node].cnt = 1;
      t[node].freq1 = 1;
      t[node].sum = t[node].max1;
      return;
    }
    Push(node);
    int mid = left + (right - left) / 2;
    if (pos <= mid)
      Use(2 * node + 1, left, mid, pos);
    else
      Use(2 * node + 2, mid + 1, right, pos);
    Recalc(node);
  }
  int64_t Get(int node, int left, int right, int x, int y) {
    if (y < left || x > right) return 0;
    if (x <= left && right <= y) {
      return t[node].sum;
    }
    Push(node);
    int mid = left + (right - left) / 2;
    return Get(2 * node + 1, left, mid, x, y) +
           Get(2 * node + 2, mid + 1, right, x, y);
  }
  void Update(int node, int left, int right, int x, int y, int val) {
    if (t[node].max1 <= val) return;
    if (x <= left && right <= y && val > t[node].max2) {
      t[node].lazy = val;
      t[node].Apply();
      return;
    }
    Push(node);
    int mid = left + (right - left) / 2;
    if (x <= mid) Update(2 * node + 1, left, mid, x, y, val);
    if (mid < y) Update(2 * node + 2, mid + 1, right, x, y, val);
    Recalc(node);
  }
  void Use(int pos) { Use(0, 0, n - 1, pos); }
  int64_t Get(int l, int r) { return Get(0, 0, n - 1, l, r); }
  void Update(int l, int r, int k) { Update(0, 0, n - 1, l, r, k); }
};
struct Solver {
  vector<SegmTree> st;
  vector<set<int>> coords;
  Solver() : st(2, MAX), coords(3) {
    for (int i = 0; i < MAX; ++i) {
      coords[0].emplace(i);
    }
  }
  void Add(int id, int l, int r, int k) {
    auto masks = {0, 1 << (1 ^ id)};
    for (int mask : masks) {
      auto &s = coords[mask];
      for (auto it = s.lower_bound(l); it != s.end() && *it <= r;
           it = s.erase(it)) {
        int new_mask = mask | (1 << id);
        if (new_mask == 3) {
          st[0].Use(*it);
          st[1].Use(*it);
        } else {
          coords[new_mask].emplace(*it);
        }
      }
    }
    st[id].Update(l, r, k);
  }
  int64_t Get(int l, int r) {
    int64_t a = st[0].Get(l, r), b = st[1].Get(l, r);
    return a + b;
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  Solver solver;
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int t, l, r;
    cin >> t >> l >> r;
    --l;
    r -= 2;
    if (t == 1) {
      int k;
      cin >> k;
      solver.Add(k < 0, l, r, abs(k));
    } else {
      cout << solver.Get(l, r) << '\n';
    }
  }
}

```


### Prompt

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

You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.

You have to answer t independent test cases.

Input

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

The only line of the test case contains two integers n and s (1 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 162).

Output

For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.

Example

Input

5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1

Output

8
0
500
2128012501878
899999999999999999

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const long long int MAX = 1e9 + 7;
void array_show(int *array, int array_n, char middle = ' ') {
  for (int i = 0; i < array_n; i++)
    printf("%d%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(long long int *array, int array_n, char middle = ' ') {
  for (int i = 0; i < array_n; i++)
    printf("%lld%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(vector<int> &vec_s, int vec_n = -1, char middle = ' ') {
  if (vec_n == -1) vec_n = vec_s.size();
  for (int i = 0; i < vec_n; i++)
    printf("%d%c", vec_s[i], (i != vec_n - 1 ? middle : '\n'));
}
void array_show(vector<long long int> &vec_s, int vec_n = -1,
                char middle = ' ') {
  if (vec_n == -1) vec_n = vec_s.size();
  for (int i = 0; i < vec_n; i++)
    printf("%lld%c", vec_s[i], (i != vec_n - 1 ? middle : '\n'));
}
void init() {}
int check(long long int a) {
  if (a == 0) return 0;
  return a % 10 + check(a / 10);
}
void solve() {
  int n, m;
  int i, j, k;
  long long int a, b, c, d;
  cin >> a >> b;
  c = a, d = 1;
  for (i = 0; i <= 18; i++, d *= 10) {
    c = ((c - 1) / d + 1) * d;
    if (check(c) <= b) break;
  }
  cout << c - a << endl;
}
int main() {
  int n, i;
  init();
  cin >> n;
  for (i = 0; i < n; i++) {
    solve();
  }
}

```


### Prompt

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

We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer.

Snuke's objective is to permute the element in a so that the following condition is satisfied:

* For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4.

Determine whether Snuke can achieve his objective.

Constraints

* 2 ≤ N ≤ 10^5
* a_i is an integer.
* 1 ≤ a_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

If Snuke can achieve his objective, print `Yes`; otherwise, print `No`.

Examples

Input

3
1 10 100

Output

Yes

Input

4
1 2 3 4

Output

No

Input

3
1 4 1

Output

Yes

Input

2
1 1

Output

No

Input

6
2 7 1 8 2 8

Output

Yes

### Response

```cpp
#include<cstdio>

using namespace std;

int n,a[100005],c,d;

int main () {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		if (a[i] % 4 == 0) c++;
		if (a[i] % 2 == 0) d++;
	}
	d -= c;
	if (d % 2 == 1) d--;
	if (n - c * 2 - 1 - d <= 0) printf("Yes\n");
	else printf("No\n");
	return 0;
}
```


### Prompt

Construct a cpp code solution to the problem outlined:

You are given an integer n and an integer k.

In one step you can do one of the following moves:

  * decrease n by 1;
  * divide n by k if n is divisible by k.

For example, if n = 27 and k = 3 you can do the following steps: 27 → 26 → 25 → 24 → 8 → 7 → 6 → 2 → 1 → 0.

You are asked to calculate the minimum number of steps to reach 0 from n.

Input

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

The only line of each query contains two integers n and k (1 ≤ n ≤ 10^{18}, 2 ≤ k ≤ 10^{18}).

Output

For each query print the minimum number of steps to reach 0 from n in single line.

Example

Input

2
59 3
1000000000000000000 10

Output

8
19

Note

Steps for the first test case are: 59 → 58 → 57 → 19 → 18 → 6 → 2 → 1 → 0.

In the second test case you have to divide n by k 18 times and then decrease n by 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, k;
int T;
int main() {
  scanf("%d", &T);
  for (; T--;) {
    cin >> n >> k;
    long long s = 0;
    for (; n;)
      if (n % k == 0)
        n /= k, s++;
      else
        s += n - n / k * k, n = n / k * k;
    cout << s << endl;
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Some days ago, WJMZBMR learned how to answer the query "how many times does a string x occur in a string s" quickly by preprocessing the string s. But now he wants to make it harder.

So he wants to ask "how many consecutive substrings of s are cyclical isomorphic to a given string x". You are given string s and n strings xi, for each string xi find, how many consecutive substrings of s are cyclical isomorphic to xi.

Two strings are called cyclical isomorphic if one can rotate one string to get the other one. 'Rotate' here means 'to take some consecutive chars (maybe none) from the beginning of a string and put them back at the end of the string in the same order'. For example, string "abcde" can be rotated to string "deabc". We can take characters "abc" from the beginning and put them at the end of "de".

Input

The first line contains a non-empty string s. The length of string s is not greater than 106 characters.

The second line contains an integer n (1 ≤ n ≤ 105) — the number of queries. Then n lines follow: the i-th line contains the string xi — the string for the i-th query. The total length of xi is less than or equal to 106 characters.

In this problem, strings only consist of lowercase English letters.

Output

For each query xi print a single integer that shows how many consecutive substrings of s are cyclical isomorphic to xi. Print the answers to the queries in the order they are given in the input.

Examples

Input

baabaabaaa
5
a
ba
baa
aabaa
aaba

Output

7
5
7
3
5

Input

aabbaa
3
aa
aabb
abba

Output

2
3
3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1000006, SZ = 26;
char ss[N], t[N + N];
int Q;
class SuffixAutomaton {
 public:
  struct state {
    int len, link, nxt[SZ];
    bool is_cloned;
    state() {
      len = 0;
      link = -1;
      is_cloned = false;
      memset(nxt, -1, sizeof nxt);
    }
  };
  string s;
  int n, last, sz;
  vector<state> st;
  vector<bool> terminal;
  SuffixAutomaton() {}
  void init(string sss) {
    s = sss;
    n = s.size();
    st.clear();
    terminal.clear();
    st.resize(n + n);
    terminal.resize(n + n, 0);
    last = 0;
    sz = 1;
    build();
  }
  void extend(char cc) {
    int c = cc - 'a';
    int cur = sz++;
    st[cur].len = st[last].len + 1;
    int p = last;
    while (p != -1 && st[p].nxt[c] == -1) {
      st[p].nxt[c] = cur;
      p = st[p].link;
    }
    if (p == -1) {
      st[cur].link = 0;
    } else {
      int q = st[p].nxt[c];
      if (st[p].len + 1 == st[q].len) {
        st[cur].link = q;
      } else {
        int clone = sz++;
        st[clone].is_cloned = true;
        st[clone].len = st[p].len + 1;
        for (int i = 0; i < SZ; i++) {
          st[clone].nxt[i] = st[q].nxt[i];
        }
        st[clone].link = st[q].link;
        st[q].link = st[cur].link = clone;
        while (p != -1 && st[p].nxt[c] == q) {
          st[p].nxt[c] = clone;
          p = st[p].link;
        }
      }
    }
    last = cur;
  }
  void getTerminal() {
    int p = last;
    while (p != -1) {
      terminal[p] = true;
      p = st[p].link;
    }
  }
  void build() {
    for (int i = 0; i < n; i++) {
      extend(s[i]);
    }
    getTerminal();
  }
  vector<int> dp, vis;
  int rec(int x) {
    if (dp[x] != -1) return dp[x];
    dp[x] = 0;
    for (int i = 0; i < SZ; i++) {
      if (st[x].nxt[i] == -1) continue;
      dp[x] += rec(st[x].nxt[i]);
    }
    dp[x] += terminal[x];
    return dp[x];
  }
  long long go(int m) {
    long long res = 0;
    int x = 0, i = 0, ln = 0;
    while (i < m + m - 1) {
      while (x != -1 && st[x].nxt[t[i] - 'a'] == -1) {
        x = st[x].link;
        if (x != -1) {
          ln = st[x].len;
        }
      }
      if (x != -1) {
        x = st[x].nxt[t[i] - 'a'];
        ln++;
      } else {
        x = ln = 0;
      }
      if (ln == m) {
        if (vis[x] != Q) {
          res += dp[x];
          vis[x] = Q;
        }
        if (ln == st[st[x].link].len + 1) {
          x = st[x].link;
          ln = st[x].len;
        } else {
          ln--;
        }
      }
      i++;
    }
    return res;
  }
  void calc() {
    dp.clear();
    dp.resize(n + n, -1);
    vis.clear();
    vis.resize(n + n, -1);
    rec(0);
  }
  void print() {
    for (int i = 0; i < sz; i++) {
      printf("%d: link: %d len: %d %d %d\n", i, st[i].link, st[i].len,
             (int)terminal[i], dp[i]);
      for (int j = 0; j < SZ; j++) {
        if (st[i].nxt[j] != -1) {
          printf("%c %d\n", 'a' + j, st[i].nxt[j]);
        }
      }
    }
  }
};
int main() {
  scanf("%s", ss);
  string s = "";
  for (int i = 0; ss[i]; i++) {
    s += ss[i];
  }
  SuffixAutomaton SA;
  SA.init(s);
  SA.calc();
  int q;
  scanf("%d", &q);
  for (Q = 0; Q < q; Q++) {
    scanf("%s", t);
    int m = strlen(t);
    for (int i = m; i < m + m - 1; i++) {
      t[i] = t[i - m];
    }
    t[m + m - 1] = '\0';
    printf("%lld\n", SA.go(m));
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n.

A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem.

Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros.

In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below.

For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$

Formally,

  * if p ≥ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q;
  * if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q.

Mishanya gives you an array consisting of n integers a_i, your task is to help students to calculate ∑_{i = 1}^{n}∑_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the elements of the array.

Output

Print the answer modulo 998 244 353.

Examples

Input

3
12 3 45

Output

12330

Input

2
123 456

Output

1115598

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long m = 998244353) {
  if (y == 0) return 1;
  long long p = power(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
long long sum(string s, long long l, long long num) {
  if (num == 0) return 0;
  long long ans = 0;
  long long curr_len = s.size();
  long long total_len = curr_len + l;
  long long maxl = min(l, curr_len) * 2;
  long long bar = 0;
  if (curr_len > l) {
    while (curr_len > l) {
      ans += ((((((s[bar] - '0') *
                  ((long long)power(10, total_len - 1) % 998244353)) %
                 998244353) *
                num) %
               998244353) *
              2) %
             998244353;
      ans %= 998244353;
      bar++;
      total_len--;
      curr_len--;
    }
  }
  while (maxl > 0) {
    ans += ((((s[bar] - '0') * ((long long)power(10, maxl - 1)) % 998244353) %
             998244353) *
            num) %
           998244353;
    ans += ((((s[bar] - '0') * ((long long)power(10, maxl - 2)) % 998244353) %
             998244353) *
            num) %
           998244353;
    maxl -= 2;
    bar++;
  }
  return ans;
}
signed main() {
  long long n;
  cin >> n;
  string a[n];
  long long nums[11] = {0};
  for (long long i = 0; i <= n - 1; i++) {
    cin >> a[i];
    nums[a[i].size()]++;
  }
  long long ans = 0;
  for (long long i = 0; i <= n - 1; i++) {
    for (long long len = 1; len <= 10; len++) {
      ans = (ans + sum(a[i], len, nums[len])) % 998244353;
    }
  }
  cout << ans << "\n";
}

```