### Prompt

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

A palindrome is a string t which reads the same backward as forward (formally, t[i] = t[|t| + 1 - i] for all i ∈ [1, |t|]). Here |t| denotes the length of a string t. For example, the strings 010, 1001 and 0 are palindromes.

You have n binary strings s_1, s_2, ..., s_n (each s_i consists of zeroes and/or ones). You can swap any pair of characters any number of times (possibly, zero). Characters can be either from the same string or from different strings — there are no restrictions.

Formally, in one move you:

  * choose four integer numbers x, a, y, b such that 1 ≤ x, y ≤ n and 1 ≤ a ≤ |s_x| and 1 ≤ b ≤ |s_y| (where x and y are string indices and a and b are positions in strings s_x and s_y respectively),
  * swap (exchange) the characters s_x[a] and s_y[b].

What is the maximum number of strings you can make palindromic simultaneously?

Input

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

The first line on each test case contains single integer n (1 ≤ n ≤ 50) — the number of binary strings you have.

Next n lines contains binary strings s_1, s_2, ..., s_n — one per line. It's guaranteed that 1 ≤ |s_i| ≤ 50 and all strings constist of zeroes and/or ones.

Output

Print Q integers — one per test case. The i-th integer should be the maximum number of palindromic strings you can achieve simultaneously performing zero or more swaps on strings from the i-th test case.

Example

Input

4
1
0
3
1110
100110
010101
2
11111
000001
2
001
11100111

Output

1
2
2
2

Note

In the first test case, s_1 is palindrome, so the answer is 1.

In the second test case you can't make all three strings palindromic at the same time, but you can make any pair of strings palindromic. For example, let's make s_1 = 0110, s_2 = 111111 and s_3 = 010000.

In the third test case we can make both strings palindromic. For example, s_1 = 11011 and s_2 = 100001.

In the last test case s_2 is palindrome and you can make s_1 palindrome, for example, by swapping s_1[2] and s_1[3].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<string> v;
int main() {
  long long t, n, i, k;
  string s;
  cin >> t;
  while (t--) {
    scanf("%lld", &n);
    long long odd = 0, evengood = 0, evenbad = 0, zero = 0;
    k = n;
    while (k--) {
      zero = 0;
      cin >> s;
      if (s.size() % 2 == 1)
        odd++;
      else {
        for (i = 0; i < s.size(); i++)
          if (s[i] == '0') zero++;
        if (zero % 2 == 0)
          evengood++;
        else
          evenbad++;
      }
    }
    if (odd) {
      printf("%lld\n", n);
    } else {
      if (evenbad % 2 == 1)
        cout << n - 1 << endl;
      else
        cout << n << endl;
    }
  }
}

```


### Prompt

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

Little Petya likes to draw. He drew N red and M blue points on the plane in such a way that no three points lie on the same line. Now he wonders what is the number of distinct triangles with vertices in red points which do not contain any blue point inside.

Input

The first line contains two non-negative integer numbers N and M (0 ≤ N ≤ 500, 0 ≤ M ≤ 500) — the number of red and blue points respectively. The following N lines contain two integer numbers each — coordinates of red points. The following M lines contain two integer numbers each — coordinates of blue points. All coordinates do not exceed 109 by absolute value.

Output

Output one integer — the number of distinct triangles with vertices in red points which do not contain any blue point inside.

Examples

Input

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

Output

2

Input

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

Output

7

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const int N = 1e3 + 5;
int f[N][N];
struct node {
  long long x, y;
} a[N], b[N];
bool cmp(node x, node y) { return x.y < y.y; }
long long area(node a, node b, node c) {
  return a.x * b.y - a.y * b.x + b.x * c.y - b.y * c.x + c.x * a.y - c.y * a.x;
}
bool toleft(node a, node b, node c) {
  if (c.y <= a.y || c.y > b.y) return 0;
  return area(a, b, c) > 0;
}
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) scanf("%lld%lld", &a[i].x, &a[i].y);
  for (int i = 1; i <= m; ++i) scanf("%lld%lld", &b[i].x, &b[i].y);
  sort(a + 1, a + n + 1, cmp);
  int ans = 0;
  for (int i = 1; i < n; ++i)
    for (int j = i + 1; j <= n; ++j)
      for (int k = 1; k <= m; ++k)
        if (toleft(a[i], a[j], b[k])) f[i][j]++;
  for (int i = 1; i < n; ++i)
    for (int j = i + 1; j < n; ++j)
      for (int k = j + 1; k <= n; ++k)
        if (f[i][j] + f[j][k] == f[i][k]) ans++;
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

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

You are given a string S as input. This represents a valid date in the year 2019 in the `yyyy/mm/dd` format. (For example, April 30, 2019 is represented as `2019/04/30`.)

Write a program that prints `Heisei` if the date represented by S is not later than April 30, 2019, and prints `TBD` otherwise.

Constraints

* S is a string that represents a valid date in the year 2019 in the `yyyy/mm/dd` format.

Input

Input is given from Standard Input in the following format:

S

Output

Print `Heisei` if the date represented by S is not later than April 30, 2019, and print `TBD` otherwise.

Examples

Input

2019/04/30

Output

Heisei

Input

2019/11/01

Output

TBD

### Response

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

int main() {
  string S;
  cin >> S;

  if (S <= "2019/04/30")
    puts("Heisei");
  else
    puts("TBD");
}
```


### Prompt

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

Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b.

Determine whether the arrangement of the poles is beautiful.

Constraints

* 1 \leq a,b,c \leq 100
* a, b and c are integers.

Input

Input is given from Standard Input in the following format:

a b c

Output

Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise.

Examples

Input

2 4 6

Output

YES

Input

2 5 6

Output

NO

Input

3 2 1

Output

YES

### Response

```cpp
#include <cstdio>

int a, b, c;

int main(){
	scanf("%d %d %d", &a, &b, &c);
	if(b - a == c - b) printf("YES\n");
	else printf("NO\n");
}
```


### Prompt

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

Example

Input

4 4
0 0
6 0
6 6
0 6

Output

35.759506

### Response

```cpp
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

struct P {
	double x, y;
	P() {
	}
	P(double _x, double _y) :
			x(_x), y(_y) {
	}
	P operator+(const P&p) const {
		return P(x + p.x, y + p.y);
	}
	P operator-(const P&p) const {
		return P(x - p.x, y - p.y);
	}
	P operator*(double d) const {
		return P(x * d, y * d);
	}
	P operator/(double d) const {
		return P(x / d, y / d);
	}
	double det(const P&p) const {
		return x * p.y - y * p.x;
	}
	double dot(const P&p) const {
		return x * p.x + y * p.y;
	}
	double alpha() const {
		return atan2(y, x);
	}
	P rot90() const {
		return P(-y, x);
	}
	void read() {
		scanf("%lf%lf", &x, &y);
	}
	void write() const {
		printf("(%lf,%lf)", x, y);
	}
	double abs() {
		return sqrt(abs2());
	}
	double abs2() {
		return x * x + y * y;
	}
	P unit() {
		return *this / abs();
	}
};

#define cross(p1,p2,p3) ((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))

const double EPS = 1e-8; //you should change it according to problem, nevertheless, it mustn't be a constant value some times.
inline int sign(double a) {
	return a < -EPS ? -1 : a > EPS;
}

#define crossOp(p1,p2,p3) (sign(cross(p1,p2,p3)))

P isSS(P p1, P p2, P q1, P q2) {
	double a1 = cross(q1,q2,p1), a2 = -cross(q1,q2,p2);
	return (p1 * a2 + p2 * a1) / (a1 + a2);
}

int n;

double x[12],y[12],r;

bool onLine(P p, P q, P x){
	return (x-p).dot(x-q) <= EPS;
}

vector<P> isCS(P c,double r,P p, P q){
	double d = cross(q,p,c) / (p-q).abs();
	vector<P> ret;

	if(d>=r+EPS)
		return ret;

	P dir = (q-p).rot90();
	P pq = (p-q);
	pq = pq/pq.abs();

	dir = dir / dir.abs();

	P mid = c + dir * d;

	double h = sqrt(max(r*r-d*d,0.0));
	if(onLine(p,q,mid + pq*h))
		ret.push_back(mid + pq*h);
	if(onLine(p,q,mid - pq*h))
		ret.push_back(mid - pq*h);
	return ret;
}

double rad(P p,P q){
	return atan2(p.det(q),p.dot(q));
}

double calc(P p, P q){
	bool inp = p.abs2() <= r*r;
	bool inq = q.abs2() <= r*r;
	if(inp && inq){
		return p.det(q)/2;
	}
	if(inp && !inq){
		return -calc(q,p);
	}
	vector<P> is = isCS(P(0,0),r,p,q);
	if(!inp && inq){
		P m = is[0];
		return r*r*rad(p,m)/2 + m.det(q)/2;
	}

	if(!inp && !inq){
		if(is.empty())
			return r*r*rad(p,q)/2;
		return r*r*(rad(p,is[0]) + rad(is[1],q))/2 + is[0].det(is[1])/2;
	}
}

double calcArea(double cx,double cy){
	P ps[12];
	rep(i,n) ps[i].x=x[i]-cx,ps[i].y=y[i]-cy;
	ps[n] = ps[0];

	double area = 0;

	rep(i,n){
		P p=ps[i],q=ps[i+1];
		area += calc(p,q);
	}

	//cout<<area<<endl;

	return area;
}

double ffy(double x){
	double l = 1e100,r=-1e100;

	P ps[12];
	rep(i,n) ps[i].x=::x[i], ps[i].y=y[i];

	ps[n] = ps[0];

	rep(i,n){
		P p = ps[i], q = ps[i+1];
		if(p.x > q.x)
			swap(p,q);

		if(p.x<=x+EPS && x<=q.x+EPS){
			double iy;
			if(p.y==q.y)
				iy = p.y;
			else
				iy = p.y + (q.y - p.y) * (x-p.x) / (q.x-p.x);
			l = min(l,iy);
			r = max(r,iy);
		}
	}

	rep(it,100){
		double ll=(l*2+r)/3,rr=(l+r*2)/3;
		if(calcArea(x,ll)>calcArea(x,rr))
			r=rr;
		else
			l=ll;
	}
	return calcArea(x,l);
}

double ffx(){
	double l=*min_element(x,x+n),r=*max_element(x,x+n);

	rep(it,100){
		double ll=(l*2+r)/3,rr=(l+r*2)/3;
		if(ffy(ll)>ffy(rr))
			r=rr;
		else
			l=ll;
	}
	return ffy(l);
}

int main(){
	cin>>n>>r;
	rep(i,n) cin>>x[i]>>y[i];

	printf("%0.10lf\n",ffx());
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

Nauuo is a girl who loves drawing circles.

One day she has drawn a circle and wanted to draw a tree on it.

The tree is a connected undirected graph consisting of n nodes and n-1 edges. The nodes are numbered from 1 to n.

Nauuo wants to draw a tree on the circle, the nodes of the tree should be in n distinct points on the circle, and the edges should be straight without crossing each other.

"Without crossing each other" means that every two edges have no common point or the only common point is an endpoint of both edges.

Nauuo wants to draw the tree using a permutation of n elements. A permutation of n elements is a sequence of integers p_1,p_2,…,p_n in which every integer from 1 to n appears exactly once.

After a permutation is chosen Nauuo draws the i-th node in the p_i-th point on the circle, then draws the edges connecting the nodes.

The tree is given, Nauuo wants to know how many permutations are there so that the tree drawn satisfies the rule (the edges are straight without crossing each other). She only wants to know the answer modulo 998244353, can you help her?

It is obvious that whether a permutation is valid or not does not depend on which n points on the circle are chosen.

Input

The first line contains a single integer n (2≤ n≤ 2⋅ 10^5) — the number of nodes in the tree.

Each of the next n-1 lines contains two integers u and v (1≤ u,v≤ n), denoting there is an edge between u and v.

It is guaranteed that the given edges form a tree.

Output

The output contains a single integer — the number of permutations suitable to draw the given tree on a circle satisfying the rule, modulo 998244353.

Examples

Input

4
1 2
1 3
2 4

Output

16

Input

4
1 2
1 3
1 4

Output

24

Note

Example 1

All valid permutations and their spanning trees are as follows.

<image>

Here is an example of invalid permutation: the edges (1,3) and (2,4) are crossed.

<image>

Example 2

Every permutation leads to a valid tree, so the answer is 4! = 24.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void gmax(T &a, T b) {
  a = a > b ? a : b;
}
template <typename T>
inline void gmin(T &a, T b) {
  a = a < b ? a : b;
}
const int mod = 998244353;
inline int mul(int x, int y) { return (long long)x * y % mod; }
const int MAXN = 200010;
int n, ans;
int du[MAXN];
int fac[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    du[x]++;
    du[y]++;
  }
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = mul(fac[i - 1], i);
  ans = n;
  for (int i = 1; i <= n; i++) ans = mul(ans, fac[du[i]]);
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

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

Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only T seconds after coming.

Fortunately, Adilbek can spend time without revising any boring theorems or formulas. He has an app on this smartphone which contains n Japanese crosswords to solve. Adilbek has decided to solve them all one by one in the order they are listed in the app, without skipping any crossword. For each crossword, a number t_i is given that represents the time it takes an average crossword expert to solve this crossword (the time is given in seconds).

Adilbek is a true crossword expert, but, unfortunately, he is sometimes unlucky in choosing the way to solve the crossword. So, it takes him either t_i seconds or t_i + 1 seconds to solve the i-th crossword, equiprobably (with probability 1/2 he solves the crossword in exactly t_i seconds, and with probability 1/2 he has to spend an additional second to finish the crossword). All these events are independent.

After T seconds pass (or after solving the last crossword, if he manages to do it in less than T seconds), Adilbek closes the app (if he finishes some crossword at the same moment, that crossword is considered solved; otherwise Adilbek does not finish solving the current crossword at all). He thinks it would be an interesting probability theory problem to calculate E — the expected number of crosswords he will be able to solve completely. Can you calculate it?

Recall that the expected value of a discrete random variable is the probability-weighted average of all possible values — in this problem it means that the expected value of the number of solved crosswords can be calculated as E = ∑ _{i = 0}^{n} i p_i, where p_i is the probability that Adilbek will solve exactly i crosswords.

We can represent E as rational fraction P/Q with Q > 0. To give the answer, you should print P ⋅ Q^{-1} mod (10^9 + 7).

Input

The first line contains two integers n and T (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ T ≤ 2 ⋅ 10^{14}) — the number of crosswords and the time Adilbek has to spend, respectively.

The second line contains n integers t_1, t_2, ..., t_n (1 ≤ t_i ≤ 10^9), where t_i is the time it takes a crossword expert to solve the i-th crossword.

Note that Adilbek solves the crosswords in the order they are given in the input without skipping any of them.

Output

Print one integer — the expected value of the number of crosswords Adilbek solves in T seconds, expressed in the form of P ⋅ Q^{-1} mod (10^9 + 7).

Examples

Input

3 5
2 2 2

Output

750000007

Input

3 5
2 1 2

Output

125000003

Note

The answer for the first sample is equal to 14/8.

The answer for the second sample is equal to 17/8.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
namespace IO {
template <class T>
inline bool read(T &x) {
  int c = getchar();
  int sgn = 1;
  while (~c && c < '0' || c > '9') {
    if (c == '-') sgn = -1;
    c = getchar();
  }
  for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  x *= sgn;
  return ~c;
}
}  // namespace IO
namespace Utility {
template <typename T>
T gcd(T a, T b) {
  return a ? gcd(b % a, a) : b;
}
template <typename T>
T lcm(T a, T b) {
  return (a / gcd(a, b) * b);
}
template <typename T>
inline T addmod(T a, T b, T mod) {
  T c = a + b;
  return c > mod ? c - mod : c;
}
template <typename T>
inline T submod(T a, T b, T mod) {
  T c = a - b;
  return c < mod ? c + mod : c;
}
template <typename T>
inline T mulmod(T a, T b, T mod) {
  return a * 1LL * b % mod;
}
template <typename T>
T exEuclid(T a, T b, T &x, T &y) {
  x = 0, y = 1;
  if (a == 0) return b;
  T x1, y1;
  T d = exEuclid(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
template <typename T>
T modInv(T a, T mod) {
  T x, y;
  exEuclid(a, mod, x, y);
  return x < 0 ? x + mod : x;
}
template <typename T>
T bigmod(T b, T p, T mod) {
  T ret = b > 0;
  while (p) {
    if (p & 1) ret = mulmod(ret, b, mod);
    p >>= 1, b = mulmod(b, b, mod);
  }
  return ret;
}
}  // namespace Utility
using namespace IO;
using namespace Utility;
const int INF = 2000000009;
const int MX = 200005;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int MOD = 1000000007;
int fac[MX], ifac[MX], inv[MX], pw[MX];
int ncr(int n, int r) {
  if (r > n || r < 0) return 0;
  return (int)(1LL * fac[n] * ifac[r] % MOD * ifac[n - r] % MOD);
}
int main() {
  fac[0] = fac[1] = ifac[0] = ifac[1] = inv[0] = inv[1] = 1;
  pw[0] = 1, pw[1] = 2;
  for (int i = 2; i < MX; i++) {
    fac[i] = 1LL * fac[i - 1] * i % MOD;
    inv[i] = MOD - 1LL * inv[MOD % i] * (MOD / i) % MOD;
    ifac[i] = 1LL * ifac[i - 1] * inv[i] % MOD;
    pw[i] = pw[i - 1] * 2 % MOD;
  }
  int n = ({
    int a;
    read(a);
    a;
  });
  long long T = ({
    long long a;
    read(a);
    a;
  }),
            t = 0LL;
  int sum = 0LL;
  int k = 0, ways = 1;
  for (int i = 1; i <= n; i++) {
    t += ({
      long long a;
      read(a);
      a;
    });
    if (t > T) break;
    int cur_k = (int)min(1LL * i, T - t);
    while (k > cur_k) {
      ways = (ways - ncr(i - 1, k--));
      if (ways < 0) ways += MOD;
    }
    while (k < cur_k) {
      ways = (ways + ncr(i - 1, ++k)) % MOD;
    }
    ways = ways * 2 % MOD;
    ways -= ncr(i - 1, k);
    if (ways < 0) ways += MOD;
    sum = (sum + 1LL * ways * pw[n - i] % MOD) % MOD;
  }
  int ans = 1LL * sum * modInv(pw[n], MOD) % MOD;
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`.

So he has decided to make a program that puts the single space he omitted.

You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s.

Constraints

* s contains exactly 12 letters.
* All letters in s are uppercase English letters.

Input

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

s

Output

Print the string putting a single space between the first 4 letters and last 8 letters in the string s. Put a line break at the end.

Examples

Input

CODEFESTIVAL

Output

CODE FESTIVAL

Input

POSTGRADUATE

Output

POST GRADUATE

Input

ABCDEFGHIJKL

Output

ABCD EFGHIJKL

### Response

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

using namespace std;
int main() {
  string s;
  cin >> s;
  cout << s.substr(0, 4) << " " << s.substr(4, 100) << endl;
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

Let's define the Eulerian traversal of a tree (a connected undirected graph without cycles) as follows: consider a depth-first search algorithm which traverses vertices of the tree and enumerates them in the order of visiting (only the first visit of each vertex counts). This function starts from the vertex number 1 and then recursively runs from all vertices which are connected with an edge with the current vertex and are not yet visited in increasing numbers order. Formally, you can describe this function using the following pseudocode:

    next_id = 1
    id = array of length n filled with -1
    visited = array of length n filled with false

    function dfs(v):
        visited[v] = true
        id[v] = next_id
        next_id += 1
        for to in neighbors of v in increasing order:
            if not visited[to]:
                dfs(to)

You are given a weighted tree, the vertices of which were enumerated with integers from 1 to n using the algorithm described above.

A leaf is a vertex of the tree which is connected with only one other vertex. In the tree given to you, the vertex 1 is not a leaf. The distance between two vertices in the tree is the sum of weights of the edges on the simple path between them.

You have to answer q queries of the following type: given integers v, l and r, find the shortest distance from vertex v to one of the leaves with indices from l to r inclusive.

Input

The first line contains two integers n and q (3 ≤ n ≤ 500 000, 1 ≤ q ≤ 500 000) — the number of vertices in the tree and the number of queries, respectively.

The (i - 1)-th of the following n - 1 lines contains two integers p_i and w_i (1 ≤ p_i < i, 1 ≤ w_i ≤ 10^9), denoting an edge between vertices p_i and i with the weight w_i.

It's guaranteed that the given edges form a tree and the vertices are enumerated in the Eulerian traversal order and that the vertex with index 1 is not a leaf.

The next q lines describe the queries. Each of them contains three integers v_i, l_i, r_i (1 ≤ v_i ≤ n, 1 ≤ l_i ≤ r_i ≤ n), describing the parameters of the query. It is guaranteed that there is at least one leaf with index x such that l_i ≤ x ≤ r_i.

Output

Output q integers — the answers for the queries in the order they are given in the input.

Examples

Input

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

Output

3
0
13

Input

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

Output

3000000000
1000000000
2000000000

Input

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

Output

8
8
9
16
9
10
0
34

Note

In the first example, the tree looks like this:

<image>

In the first query, the nearest leaf for the vertex 1 is vertex 4 with distance 3. In the second query, the nearest leaf for vertex 5 is vertex 5 with distance 0. In the third query the nearest leaf for vertex 4 is vertex 4; however, it is not inside interval [1, 2] of the query. The only leaf in interval [1, 2] is vertex 2 with distance 13 from vertex 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = numeric_limits<ll>::max() / 2;
constexpr int TREE_SIZE = 1 << 19;
ll tr[TREE_SIZE * 2] = {};
ll prop[TREE_SIZE * 2] = {};
void unroll(int p) {
  if (p >= TREE_SIZE) {
    prop[p] = 0;
    return;
  }
  tr[p * 2] += prop[p];
  tr[p * 2 + 1] += prop[p];
  prop[p * 2] += prop[p];
  prop[p * 2 + 1] += prop[p];
  prop[p] = 0;
}
void inc(int l, int r, ll val, int p = 1, int ll = 0, int rr = TREE_SIZE) {
  l = max(ll, l);
  r = min(rr, r);
  if (r <= l) {
    return;
  }
  if (l == ll && r == rr) {
    tr[p] += val;
    prop[p] += val;
    return;
  }
  unroll(p);
  int mm = (ll + rr) / 2;
  inc(l, r, val, p * 2, ll, mm);
  inc(l, r, val, p * 2 + 1, mm, rr);
  tr[p] = min(tr[p * 2], tr[p * 2 + 1]);
}
ll get(int l, int r, int p = 1, int ll = 0, int rr = TREE_SIZE) {
  l = max(ll, l);
  r = min(rr, r);
  if (r <= l) {
    return INF;
  }
  if (l == ll && r == rr) {
    return tr[p];
  }
  unroll(p);
  int mm = (ll + rr) / 2;
  return min(get(l, r, p * 2, ll, mm), get(l, r, p * 2 + 1, mm, rr));
}
bool is_inner[TREE_SIZE] = {};
ll depth[TREE_SIZE] = {};
int parent[TREE_SIZE] = {};
int rightmost[TREE_SIZE] = {};
vector<vector<pair<int, ll>>> edges;
vector<vector<tuple<int, int, int>>> queries;
vector<ll> result;
void dfs(int p) {
  for (const auto& q : queries[p]) {
    int l, r, ind;
    tie(ind, l, r) = q;
    result[ind] = get(l, r) + depth[p];
  }
  for (const auto& e : edges[p]) {
    inc(e.first, rightmost[e.first] + 1, -2 * e.second);
    dfs(e.first);
    inc(e.first, rightmost[e.first] + 1, 2 * e.second);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q;
  cin >> n >> q;
  edges.resize(n);
  queries.resize(n);
  for (int i = 1; i < n; ++i) {
    int p;
    ll w;
    cin >> p >> w;
    --p;
    is_inner[p] = true;
    depth[i] = depth[p] + w;
    edges[p].push_back(make_pair(i, w));
    parent[i] = p;
  }
  for (int i = n - 1; i >= 0; --i) {
    rightmost[i] = max(i, rightmost[i]);
    rightmost[parent[i]] = max(rightmost[parent[i]], rightmost[i]);
  }
  for (int i = 0; i < q; ++i) {
    int v, l, r;
    cin >> v >> l >> r;
    --v;
    --l;
    --r;
    queries[v].push_back(make_tuple(i, l, r + 1));
  }
  result.assign(q, -1);
  inc(0, TREE_SIZE, INF);
  for (int i = 0; i < n; i++) {
    if (!is_inner[i]) {
      inc(i, i + 1, depth[i] - INF);
    }
  }
  dfs(0);
  for (int i = 0; i < q; ++i) {
    cout << result[i] << endl;
  }
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

This is the easy version of the problem. The difference between the versions is in the constraints on the array elements. You can make hacks only if all versions of the problem are solved.

You are given an array [a_1, a_2, ..., a_n].

Your goal is to find the length of the longest subarray of this array such that the most frequent value in it is not unique. In other words, you are looking for a subarray such that if the most frequent value occurs f times in this subarray, then at least 2 different values should occur exactly f times.

An array c is a subarray of an array d if c can be obtained from d by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

Input

The first line contains a single integer n (1 ≤ n ≤ 200 000) — the length of the array.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ min(n, 100)) — elements of the array.

Output

You should output exactly one integer — the length of the longest subarray of the array whose most frequent value is not unique. If there is no such subarray, output 0.

Examples

Input

7
1 1 2 2 3 3 3

Output

6

Input

10
1 1 1 5 4 1 3 1 2 2

Output

7

Input

1
1

Output

0

Note

In the first sample, the subarray [1, 1, 2, 2, 3, 3] is good, but [1, 1, 2, 2, 3, 3, 3] isn't: in the latter there are 3 occurrences of number 3, and no other element appears 3 times.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 0;
  char c = getchar();
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  return f ? -x : x;
}
inline int max(int a, int b, int c) { return max(a, max(b, c)); }
int n, a[200010], cnt[200010];
int f[2 * 200010], ans;
int main() {
  cin >> n;
  vector<int> pos[200010];
  for (int i = 1; i <= n; ++i) a[i] = read(), ++cnt[a[i]];
  int mx = 0, p = 0;
  bool F = 0;
  for (int i = 1; i <= 100; ++i)
    if (cnt[i] > mx) mx = cnt[i], p = i;
  for (int i = 1; i <= 100; ++i)
    if (cnt[i] == mx && p != i) F = 1;
  for (int i = 1; i <= 100; ++i) {
    memset(f, -1, sizeof f);
    f[200000] = 0;
    int s = 0;
    for (int j = 1; j <= n; ++j) {
      if (a[j] == p)
        --s;
      else if (a[j] == i)
        ++s;
      if (~f[s + 200000])
        ans = max(ans, j - f[s + 200000]);
      else
        f[s + 200000] = j;
    }
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that.

How many times can Artem give presents to Masha?

Input

The only line of the input contains a single integer n (1 ≤ n ≤ 109) — number of stones Artem received on his birthday.

Output

Print the maximum possible number of times Artem can give presents to Masha.

Examples

Input

1

Output

1

Input

2

Output

1

Input

3

Output

2

Input

4

Output

3

Note

In the first sample, Artem can only give 1 stone to Masha.

In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.

In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.

In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.

### Response

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

```


### Prompt

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

You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side that is parallel to the Oy axis, equals h. The second rectangle can be obtained by rotating the first rectangle relative to the origin of coordinates by angle α.

<image>

Your task is to find the area of the region which belongs to both given rectangles. This region is shaded in the picture.

Input

The first line contains three integers w, h, α (1 ≤ w, h ≤ 106; 0 ≤ α ≤ 180). Angle α is given in degrees.

Output

In a single line print a real number — the area of the region which belongs to both given rectangles.

The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.

Examples

Input

1 1 45

Output

0.828427125

Input

6 4 30

Output

19.668384925

Note

The second sample has been drawn on the picture above.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
const int inf = 1 << 28;
double pi = acos(-1.0);
double PI = acos(-1.0);
int main() {
  double w, h, alph;
  cin >> w >> h >> alph;
  if (w < h) swap(w, h);
  if (alph > 90) alph = 180 - alph;
  alph = alph / 180.0 * PI;
  double x = (w * w + h * h) * 1.0 / (2 * w * 1.0);
  double mya = asin(h * 1.0 / x);
  double ans = 0;
  if (alph >= mya) {
    ans = h * h * 1.0 / sin(alph);
  } else {
    double n = (h * (1 + cos(alph)) - w * sin(alph)) /
               ((1 + cos(alph)) * (1 + cos(alph)) - sin(alph) * sin(alph));
    double m = (h * sin(alph) - w * (1 + cos(alph))) /
               (sin(alph) * sin(alph) - (1 + cos(alph)) * (1 + cos(alph)));
    ans = w * h - (m * m + n * n) * sin(alph) * cos(alph);
  }
  printf("%.16lf\n", ans);
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

A string is binary, if it consists only of characters "0" and "1".

String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their positions of occurrence are different. So, if some string occurs multiple times, we should consider it the number of times it occurs.

You are given a binary string s. Your task is to find the number of its substrings, containing exactly k characters "1".

Input

The first line contains the single integer k (0 ≤ k ≤ 106). The second line contains a non-empty binary string s. The length of s does not exceed 106 characters.

Output

Print the single number — the number of substrings of the given string, containing exactly k characters "1".

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

Examples

Input

1
1010

Output

6

Input

2
01010

Output

4

Input

100
01010

Output

0

Note

In the first sample the sought substrings are: "1", "1", "10", "01", "10", "010".

In the second sample the sought substrings are: "101", "0101", "1010", "01010".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void adskiy_razgon() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
long long nod(long long a, long long b) {
  if (b > a) {
    swap(a, b);
  }
  while (b > 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long nok(long long a, long long b) { return a * b / nod(a, b); }
void sp(long long a, double b) { cout << fixed << setprecision(a) << b; }
long long binpow(long long a, long long n) {
  if (n == 0) {
    return 1;
  }
  if (n % 2 == 1) {
    return binpow(a, n - 1) * a;
  } else {
    long long b = binpow(a, n / 2);
    return b * b;
  }
}
template <class A>
void read(vector<A>& v);
template <class A, size_t S>
void read(array<A, S>& a);
template <class T>
void read(T& x) {
  cin >> x;
}
void read(double& d) {
  string t;
  read(t);
  d = stod(t);
}
void read(long double& d) {
  string t;
  read(t);
  d = stold(t);
}
template <class H, class... T>
void read(H& h, T&... t) {
  read(h);
  read(t...);
}
template <class A>
void read(vector<A>& x) {
  for (auto& a : x) read(a);
}
template <class A, size_t S>
void read(array<A, S>& x) {
  for (auto& a : x) read(a);
}
string to_string(char c) { return string(1, c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return string(s); }
string to_string(string s) { return s; }
string to_string(vector<bool> v) {
  string res;
  for (int i = (0); (1) > 0 ? i < ((int)(v).size()) : i > ((int)(v).size());
       i += (1))
    res += char('0' + v[i]);
  return res;
}
template <size_t S>
string to_string(bitset<S> b) {
  string res;
  for (int i = (0); (1) > 0 ? i < (S) : i > (S); i += (1))
    res += char('0' + b[i]);
  return res;
}
template <class T>
string to_string(T v) {
  bool f = 1;
  string res;
  for (auto& x : v) {
    if (!f) res += ' ';
    f = 0;
    res += to_string(x);
  }
  return res;
}
template <class A>
void write(A x) {
  cout << to_string(x);
}
template <class H, class... T>
void write(const H& h, const T&... t) {
  write(h);
  write(t...);
}
void print() { write("\n"); }
template <class H, class... T>
void print(const H& h, const T&... t) {
  write(h);
  if (sizeof...(t)) write(' ');
  print(t...);
}
void yes(bool ok) { print((ok ? "YES" : "Yes")); }
void no(bool ok) { print((ok ? "NO" : "No")); }
long long cnt[1000000];
void solve() {
  long long n;
  read(n);
  string s;
  read(s);
  cnt[0] = 1;
  long long sum = 0, ans = 0;
  for (int i = (0); (1) > 0 ? i < ((int)(s).size()) : i > ((int)(s).size());
       i += (1)) {
    if (s[i] == '1') sum++;
    if (sum >= n) {
      ans += cnt[sum - n];
    }
    cnt[sum]++;
  }
  print(ans);
}
int main() {
  adskiy_razgon();
  long long t = 1;
  for (int i = 1; i <= t; ++i) {
    solve();
  }
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

There is a robot on a checkered field that is endless in all directions. Initially, the robot is located in the cell with coordinates (0, 0). He will execute commands which are described by a string of capital Latin letters 'L', 'R', 'D', 'U'. When a command is executed, the robot simply moves in the corresponding direction:

  * 'L': one cell to the left (the x-coordinate of the current cell decreases by 1);
  * 'R': one cell to the right (the x-coordinate of the current cell is increased by 1);
  * 'D': one cell down (the y-coordinate of the current cell decreases by 1);
  * 'U': one cell up (the y-coordinate of the current cell is increased by 1).

Your task is to put an obstacle in one cell of the field so that after executing the commands, the robot will return to the original cell of its path (0, 0). Of course, an obstacle cannot be placed in the starting cell (0, 0). It is guaranteed that if the obstacle is not placed, then the robot will not return to the starting cell.

An obstacle affects the movement of the robot in the following way: if it tries to go in a certain direction, and there is an obstacle, then it simply remains in place (the obstacle also remains, that is, it does not disappear).

Find any such cell of the field (other than (0, 0)) that if you put an obstacle there, the robot will return to the cell (0, 0) after the execution of all commands. If there is no solution, then report it.

Input

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

Each test case consists of a single line containing s — the sequence of commands, which are uppercase Latin letters 'L', 'R', 'D', 'U' only. The length of s is between 1 and 5000, inclusive. Additional constraint on s: executing this sequence of commands leads the robot to some cell other than (0, 0), if there are no obstacles.

The sum of lengths of all s in a test doesn't exceed 5000.

Output

For each test case print a single line:

  * if there is a solution, print two integers x and y (-10^9 ≤ x,y ≤ 10^9) such that an obstacle in (x, y) will force the robot to return back to the cell (0, 0);
  * otherwise, print two zeroes (i. e. 0 0).

If there are multiple answers, you can print any of them.

Example

Input

4
L
RUUDL
LLUU
DDDUUUUU

Output

-1 0
1 2
0 0
0 1

### Response

```cpp
//****************************Template Begins****************************//

// Header Files
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#include<set>
#include<list>
#include<iterator>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<complex>
#include<math.h>
#include<string>
// Header Files End

using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<=b;i++)
#define all(v) (v).begin(),(v).end()
#define sort0(v) sort(all(v))
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define inf 9999999999999
const ll mod=1e9+7;

ll inv(ll i){if(i==1) return 1;return (mod-((mod/i)*inv(mod%i))%mod)%mod;}

ll gcd(ll a,ll b){ if (b==0) return a;return gcd(b,a%b);}

ll pwr(ll a, ll b) {a %= mod; ll res = 1;while (b > 0) {if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1;}return res;}
//****************************Template Ends*******************************//

int main() {
    fio;
    ll t,n,i,j,ans,temp,sum,x,y,xf,yf,x1,y1,a1,a2;
    cin>>t;
    string s;
    while(t--)
    {
        ans=temp=sum=x=y=a1=a2=0;
        cin>>s;
        n=s.size();
        fo(i,0,n-1)
        {
            x1=0;
            y1=0;
            if(s[i]=='U')y++;
            else if(s[i]=='R')x++;
            else if(s[i]=='L')x--;
            else if(s[i]=='D')y--;
            fo(j,0,n-1)
            {
                if(s[j]=='U' and !(x1==x and y1+1 == y))y1++;
                else if(s[j]=='D' and !(x1==x and y1-1==y))y1--;
                else if(s[j]=='R' and !(y1==y and x1+1 == x))x1++;
                else if(s[j]=='L' and !(y1==y and x1-1 == x))x1--;
            }

            if(x1==0 and y1==0)
            {
                a1=x;
                a2=y;
                break;
            }
        }
        cout<<a1<<" "<<a2<<"\n";
    }
return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Yui Hirasawa, who attends private Sakuragaoka Girls' High School, has to make a career hope by the day after tomorrow, but the trouble is that she hasn't decided anything yet. When I consulted with my friend Wa, I knew that my first choice was K University, so I consulted with my career guidance teacher to see if I could join K University.

As a career guidance teacher who was consulted, you decided to refer to Yui's final exam results in order to predict whether Yui would be able to enter K University. However, Yui's grades are greatly affected by whether or not he wins the exam, so he decided to check the best and worst scores of the final exams in the past. The data of the past final exams only remained for each score of the five subjects, and the total score of the exam did not remain. Therefore, your job is to write a program that takes the score data of each exam as input and outputs the score of the best time and the score of the worst time in the past final exams.

Notes on Test Cases

Multiple datasets are given in the above input format. Create a program that outputs each data set in the above output format.

When n is 0, it indicates the end of input.

<!-

Input

n
s11 s12 s13 s14 s15
...
sn1 sn2 sn3 sn4 sn5

n is the number of tests taken so far. The number of tests is 1 or more and 100 or less. The next n lines are given scores for 5 subjects in each exam. The range of points is an integer between 0 and 100.

Output

Output the highest and lowest points in one line. Separate the highest and lowest points with a single space and do not include any other characters.

Examples

Input

3
49 50 87 78 41
27 61 100 45 84
28 88 40 95 66
2
100 100 100 100 100
0 0 0 0 0
1
89 90 85 93 82
0

Output

317 305
500 0
439 439

Input

3
49 50 87 78 41
27 61 100 45 84
28 88 40 95 66

Output

317 305

Input

2
100 100 100 100 100
0 0 0 0 0

Output

500 0

Input

1
89 90 85 93 82

Output

439 439

### Response

```cpp
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

int main(){

	int n,maximum,minimum,sum,a,b,c,d,e;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		maximum = -1;
		minimum = 1000000000;

		for(int loop = 0; loop < n; loop++){
			scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
			sum = a + b + c + d + e;
			maximum = max(maximum,sum);
			minimum = min(minimum,sum);
		}

		printf("%d %d\n",maximum,minimum);

	}

	return 0;
}
```


### Prompt

Create a solution in cpp for the following problem:

The Professor has lost his home robot yet again. After some thinking Professor understood that he had left the robot in the basement.

The basement in Professor's house is represented by a rectangle n × m, split into 1 × 1 squares. Some squares are walls which are impassable; other squares are passable. You can get from any passable square to any other passable square moving through edge-adjacent passable squares. One passable square is the exit from the basement. The robot is placed exactly in one passable square. Also the robot may be placed in the exit square.

Professor is scared of going to the dark basement looking for the robot at night. However, he has a basement plan and the robot's remote control. Using the remote, Professor can send signals to the robot to shift one square left, right, up or down. When the robot receives a signal, it moves in the required direction if the robot's neighboring square in the given direction is passable. Otherwise, the robot stays idle.

Professor wrote a sequence of k commands on a piece of paper. He thinks that the sequence can lead the robot out of the basement, wherever it's initial position might be. Professor programmed another robot to press the required buttons on the remote according to the notes on the piece of paper. Professor was just about to run the program and go to bed, when he had an epiphany.

Executing each command takes some energy and Professor doesn't want to get huge electricity bill at the end of the month. That's why he wants to find in the sequence he has written out the minimal possible prefix that would guarantee to lead the robot out to the exit after the prefix is fulfilled. And that's the problem Professor challenges you with at this late hour.

Input

The first line contains three integers n, m and k (3 ≤ n, m ≤ 150, 1 ≤ k ≤ 105). Next n lines contain m characters each — that is the Professor's basement's description: "#" stands for a wall, "." stands for a passable square and "E" stands for the exit from the basement (this square also is passable). It is possible to get from each passable square to the exit, all squares located by the n × m rectangle's perimeter are the walls. Exactly one square is the exit from the basement. The last line contains k characters, the description of the sequence of commands that Professor has written out on a piece of paper. "L", "R", "U", "D" stand for commands left, right, up and down correspondingly.

Output

Print in the output file the length of the smallest possible prefix that will lead the robot to the exit square. In other words, wherever the robot had been positioned initially, it should be positioned in the exit square after all the commands from the prefix are fulfilled (during doing commands the robot can come and leave the exit square, but only the last position of the robot is interesting for us). If Professor is mistaken and no prefix (including the whole sequence) can bring the robot to the exit, print "-1" (without the quotes). If there is the only passable square and it is the exit, print "0" (without the quotes).

Examples

Input

5 5 7
#####
#...#
#...#
#E..#
#####
UULLDDR

Output

6

Input

5 5 7
#####
#.#.#
#...#
#E..#
#####
UULLDDR

Output

-1

Input

5 3 2
###
#.#
#.#
#E#
###
DD

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
string st;
int main() {
  int i, j;
  bitset<23005> a, b, c, e;
  cin >> n >> m >> k;
  for (i = 0; i < n; i = i + 1) {
    cin >> st;
    for (j = 0; j < m; j = j + 1) {
      if (st[j] == '#')
        b.set(i * m + j);
      else
        a.set(i * m + j);
      if (st[j] == 'E') e.set(i * m + j);
    }
  }
  cin >> st;
  c = a;
  for (i = 0; i < k; i = i + 1) {
    if (c == e) {
      cout << i << endl;
      return 0;
    }
    if (st[i] == 'U') c = ((c >> m) & a) | (c & (b << m));
    if (st[i] == 'D') c = ((c << m) & a) | (c & (b >> m));
    if (st[i] == 'L') c = ((c >> 1) & a) | (c & (b << 1));
    if (st[i] == 'R') c = ((c << 1) & a) | (c & (b >> 1));
  }
  if (c == e)
    cout << i << endl;
  else
    cout << -1 << endl;
  return 0;
}

```


### Prompt

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

Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.

The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.

You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.

Input

The first line contains a non-empty string s — the sum Xenia needs to count. String s contains no spaces. It only contains digits and characters "+". Besides, string s is a correct sum of numbers 1, 2 and 3. String s is at most 100 characters long.

Output

Print the new sum that Xenia can count.

Examples

Input

3+2+1

Output

1+2+3

Input

1+1+3+1+3

Output

1+1+1+3+3

Input

2

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int a1 = 0, a2 = 0, a3 = 0;
  for (int i = 0; i < s.length(); i += 2) {
    if (s[i] == '1')
      a1++;
    else if (s[i] == '2')
      a2++;
    else
      a3++;
  }
  if (a1 > 0) {
    cout << 1;
    for (int i = 1; i < a1; i++) {
      cout << "+" << 1;
    }
  }
  if (a1 == 0 && a2 > 0) {
    cout << 2;
    for (int i = 1; i < a2; i++) {
      cout << "+" << 2;
    }
  } else {
    for (int i = 0; i < a2; i++) {
      cout << "+" << 2;
    }
  }
  if (a1 == 0 && a2 == 0 && a3 > 0) {
    cout << 3;
    a3--;
  }
  for (int i = 0; i < a3; i++) {
    cout << "+" << 3;
  }
}

```


### Prompt

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

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;
int win[7005][2], od[7005][2];
queue<pair<int, int> > que;
vector<int> step[2];
char outp[3][20] = {
    "Lose",
    "Loop",
    "Win",
};
int main() {
  int n, i, j, other;
  pair<int, int> now;
  scanf("%d", &n);
  for (i = 0; i < 2; ++i) {
    int t, tmp;
    scanf("%d", &t);
    while (t--) {
      scanf("%d", &tmp);
      step[i].push_back(tmp);
    }
  }
  win[0][0] = win[0][1] = -1;
  que.push(make_pair(0, 1));
  que.push(make_pair(0, 0));
  while (!que.empty()) {
    now = que.front();
    que.pop();
    other = now.second ^ 1;
    if (win[now.first][now.second] == -1) {
      for (i = 0; i < step[other].size(); ++i) {
        if (win[(now.first - step[other][i] + n) % n][other] != 0) continue;
        win[(now.first - step[other][i] + n) % n][other] = 1;
        que.push(make_pair((now.first - step[other][i] + n) % n, other));
      }
    }
    if (win[now.first][now.second] == 1) {
      for (i = 0; i < step[other].size(); ++i) {
        if (win[(now.first - step[other][i] + n) % n][other] != 0) continue;
        od[(now.first - step[other][i] + n) % n][other]++;
        if (od[(now.first - step[other][i] + n) % n][other] ==
            step[other].size()) {
          win[(now.first - step[other][i] + n) % n][other] = -1;
          que.push(make_pair((now.first - step[other][i] + n) % n, other));
        }
      }
    }
  }
  for (i = 1; i < n; ++i) {
    printf("%s ", outp[win[i][0] + 1]);
  }
  puts("");
  for (i = 1; i < n; ++i) {
    printf("%s ", outp[win[i][1] + 1]);
  }
  puts("");
  return 0;
}

```


### Prompt

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

Vus the Cossack has n real numbers a_i. It is known that the sum of all numbers is equal to 0. He wants to choose a sequence b the size of which is n such that the sum of all numbers is 0 and each b_i is either ⌊ a_i ⌋ or ⌈ a_i ⌉. In other words, b_i equals a_i rounded up or down. It is not necessary to round to the nearest integer.

For example, if a = [4.58413, 1.22491, -2.10517, -3.70387], then b can be equal, for example, to [4, 2, -2, -4].

Note that if a_i is an integer, then there is no difference between ⌊ a_i ⌋ and ⌈ a_i ⌉, b_i will always be equal to a_i.

Help Vus the Cossack find such sequence!

Input

The first line contains one integer n (1 ≤ n ≤ 10^5) — the number of numbers.

Each of the next n lines contains one real number a_i (|a_i| < 10^5). It is guaranteed that each a_i has exactly 5 digits after the decimal point. It is guaranteed that the sum of all the numbers is equal to 0.

Output

In each of the next n lines, print one integer b_i. For each i, |a_i-b_i|<1 must be met.

If there are multiple answers, print any.

Examples

Input

4
4.58413
1.22491
-2.10517
-3.70387

Output

4
2
-2
-4

Input

5
-6.32509
3.30066
-0.93878
2.00000
1.96321

Output

-6
3
-1
2
2

Note

The first example is explained in the legend.

In the second example, we can round the first and fifth numbers up, and the second and third numbers down. We can round the fourth number neither up, nor down.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <typename T>
istream& operator>>(istream& in, pair<T, T>& p) {
  in >> p.first >> p.second;
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, pair<T, T> p) {
  out << p.first << " " << p.second;
  return out;
}
vector<double> arr;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  long long sum = 0;
  cin >> n;
  arr.resize(n);
  for (auto& it : arr) {
    cin >> it;
    sum += floor(it);
  }
  for (auto it : arr) {
    if (it == (int)it) {
      if ((int)it == 0)
        cout << 0 << '\n';
      else
        cout << (int)it << '\n';
    } else if (sum < 0) {
      if (ceil(it) == 0)
        cout << 0 << '\n';
      else
        cout << ceil(it) << '\n';
      sum++;
    } else {
      if (floor(it) == 0)
        cout << 0 << '\n';
      else
        cout << floor(it) << '\n';
    }
  }
  return 0;
}

```


### Prompt

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

There are N towns in the State of Atcoder, connected by M bidirectional roads.

The i-th road connects Town A_i and B_i and has a length of C_i.

Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order).

She will fly to the first town she visits, and fly back from the last town she visits, but for the rest of the trip she will have to travel by road.

If she visits the towns in the order that minimizes the distance traveled by road, what will that distance be?

Constraints

* 2≤N≤200
* 1≤M≤N×(N-1)/2
* 2≤R≤min(8,N) (min(8,N) is the smaller of 8 and N.)
* r_i≠r_j (i≠j)
* 1≤A_i,B_i≤N, A_i≠B_i
* (A_i,B_i)≠(A_j,B_j),(A_i,B_i)≠(B_j,A_j) (i≠j)
* 1≤C_i≤100000
* Every town can be reached from every town by road.
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N M R
r_1 ... r_R
A_1 B_1 C_1
:
A_M B_M C_M

Output

Print the distance traveled by road if Joisino visits the towns in the order that minimizes it.

Examples

Input

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

Output

2

Input

3 3 2
1 3
2 3 2
1 3 6
1 2 2

Output

4

Input

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

Output

3

### Response

```cpp
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int n,m,r;
  cin>>n>>m>>r;
  int g[300][300];
  vector<int> path(r);
  rep(i,r){
    cin>>path[i];
    path[i]--;
  }
  rep(i,n)rep(j,n)g[i][j]=(i==j?0:INF);
  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    if(g[a][b]>c)g[a][b]=g[b][a]=c;
  }
  rep(k,n)rep(i,n)rep(j,n)g[i][j]=min(g[i][j],g[i][k]+g[k][j]);

  int ans=INF;
  sort(path.begin(),path.end());
  do{
    int tmp=0;
    rep(i,r-1) tmp+=g[path[i]][path[i+1]];
    ans=min(ans,tmp);
  }while( next_permutation(path.begin(),path.end()) );

  cout<<ans<<endl;

  return 0;
}

```


### Prompt

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

Amr loves Geometry. One day he came up with a very interesting problem.

Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y').

In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.

Help Amr to achieve his goal in minimum number of steps.

Input

Input consists of 5 space-separated integers r, x, y, x' y' (1 ≤ r ≤ 105,  - 105 ≤ x, y, x', y' ≤ 105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.

Output

Output a single integer — minimum number of steps required to move the center of the circle to the destination point.

Examples

Input

2 0 0 0 4

Output

1

Input

1 1 1 4 4

Output

3

Input

4 5 6 5 6

Output

0

Note

In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).

<image>

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:99999999999")
using namespace std;
int main() {
  double x, x1, y1, y;
  int r;
  cin >> r >> x >> y >> x1 >> y1;
  r *= 2;
  double d = (x - x1) * (x - x1) + (y - y1) * (y - y1);
  d = sqrt(d);
  double h = d / r;
  if (double(int(h + 0.0000001)) != h) {
    h = double(int(h)) + 1.0;
  }
  cout << int(h) << endl;
  return 0;
}

```


### Prompt

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

You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).

Input

The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100.

Output

Output one number — length of the longest substring that can be met in the string at least twice.

Examples

Input

abcd

Output

0

Input

ababa

Output

3

Input

zzz

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int main() {
  cin.sync_with_stdio(false);
  string s;
  while (cin >> s) {
    int len = s.length();
    mp.clear();
    for (int i = 0; i < len; ++i) {
      string t = "";
      for (int j = i; j < len; ++j) {
        t += s[j];
        ++mp[t];
      }
    }
    int res = 0;
    for (auto it = mp.begin(); it != mp.end(); ++it) {
      if (it->second >= 2) {
        res = max(res, (int)it->first.length());
      }
    }
    cout << res << endl;
  }
  return 0;
}

```


### Prompt

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

As you know, the most intelligent beings on the Earth are, of course, cows. This conclusion was reached long ago by the Martian aliens, as well as a number of other intelligent civilizations from outer space.

Sometimes cows gather into cowavans. This seems to be seasonal. But at this time the cows become passive and react poorly to external stimuli. A cowavan is a perfect target for the Martian scientific saucer, it's time for large-scale abductions, or, as the Martians say, raids. Simply put, a cowavan is a set of cows in a row.

If we number all cows in the cowavan with positive integers from 1 to n, then we can formalize the popular model of abduction, known as the (a, b)-Cowavan Raid: first they steal a cow number a, then number a + b, then — number a + 2·b, and so on, until the number of an abducted cow exceeds n. During one raid the cows are not renumbered.

The aliens would be happy to place all the cows on board of their hospitable ship, but unfortunately, the amount of cargo space is very, very limited. The researchers, knowing the mass of each cow in the cowavan, made p scenarios of the (a, b)-raid. Now they want to identify the following thing for each scenario individually: what total mass of pure beef will get on board of the ship. All the scenarios are independent, in the process of performing the calculations the cows are not being stolen.

<image>

Input

The first line contains the only positive integer n (1 ≤ n ≤ 3·105) — the number of cows in the cowavan.

The second number contains n positive integer wi, separated by spaces, where the i-th number describes the mass of the i-th cow in the cowavan (1 ≤ wi ≤ 109).

The third line contains the only positive integer p — the number of scenarios of (a, b)-raids (1 ≤ p ≤ 3·105).

Each following line contains integer parameters a and b of the corresponding scenario (1 ≤ a, b ≤ n).

Output

Print for each scenario of the (a, b)-raid the total mass of cows, that can be stolen using only this scenario.

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

Examples

Input

3
1 2 3
2
1 1
1 2

Output

6
4

Input

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

Output

9
3
10

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:25600000")
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-9;
const long long INF = 1000000000;
const int BORDER = 300;
struct request {
  int a;
  int b;
  int num;
  long long res;
} r[3 * 102400];
bool cmp1(const request& a, const request& b) { return a.b < b.b; }
bool cmp2(const request& a, const request& b) { return a.num < b.num; }
int n, m;
int a[3 * 102400];
long long d[3 * 102400];
int main() {
  cin >> n;
  for (long long i = 1; i <= n; ++i) cin >> a[i];
  cin >> m;
  for (long long i = 0; i < m; ++i) {
    cin >> r[i].a >> r[i].b;
    r[i].num = i;
  }
  sort(r, r + m, cmp1);
  for (long long i = 0; i < m; ++i) {
    if (r[i].b > BORDER) {
      r[i].res = 0;
      for (int j = r[i].a; j <= n; j += r[i].b) r[i].res += a[j];
    } else {
      if (i == 0 || r[i].b != r[i - 1].b) {
        memset(d, 0, sizeof d);
        for (long long j = n; j >= 1; --j) {
          d[j] = a[j];
          if (j + r[i].b <= n) d[j] += d[j + r[i].b];
        }
      }
      r[i].res = d[r[i].a];
    }
  }
  sort(r, r + m, cmp2);
  for (long long i = 0; i < m; ++i) cout << r[i].res << endl;
}

```


### Prompt

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

Vasily exited from a store and now he wants to recheck the total price of all purchases in his bill. The bill is a string in which the names of the purchases and their prices are printed in a row without any spaces. Check has the format "name1price1name2price2...namenpricen", where namei (name of the i-th purchase) is a non-empty string of length not more than 10, consisting of lowercase English letters, and pricei (the price of the i-th purchase) is a non-empty string, consisting of digits and dots (decimal points). It is possible that purchases with equal names have different prices.

The price of each purchase is written in the following format. If the price is an integer number of dollars then cents are not written.

Otherwise, after the number of dollars a dot (decimal point) is written followed by cents in a two-digit format (if number of cents is between 1 and 9 inclusively, there is a leading zero).

Also, every three digits (from less significant to the most) in dollars are separated by dot (decimal point). No extra leading zeroes are allowed. The price always starts with a digit and ends with a digit.

For example:

  * "234", "1.544", "149.431.10", "0.99" and "123.05" are valid prices,
  * ".333", "3.33.11", "12.00", ".33", "0.1234" and "1.2" are not valid.

Write a program that will find the total price of all purchases in the given bill.

Input

The only line of the input contains a non-empty string s with length not greater than 1000 — the content of the bill.

It is guaranteed that the bill meets the format described above. It is guaranteed that each price in the bill is not less than one cent and not greater than 106 dollars.

Output

Print the total price exactly in the same format as prices given in the input.

Examples

Input

chipsy48.32televizor12.390

Output

12.438.32

Input

a1b2c3.38

Output

6.38

Input

aa0.01t0.03

Output

0.04

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline bool skip_alpha() {
  char s;
  while (cin >> s && isalpha(s))
    ;
  if (!(cin)) return false;
  cin.putback(s);
  return true;
}
inline long long to_integer(vector<string> &s) {
  long long n = 0;
  if (s.back().size() == 2 && s.size() > 1) {
    n = stoi(s.back());
    s.pop_back();
  }
  long long i = 100;
  while (s.size() != 0) {
    n += stoi(s.back()) * i;
    i *= 1000;
    s.pop_back();
  }
  return n;
}
void output(long long sum);
int main() {
  vector<string> v;
  long long sum = 0;
  while (skip_alpha()) {
    char ch;
    string digits = "";
    while (cin >> ch && isdigit(ch)) digits += ch;
    v.push_back(digits);
    if (isalpha(ch) || !cin) sum += to_integer(v);
  }
  output(sum);
  return 0;
}
void output(long long sum) {
  string dollarStr = to_string(sum / 100);
  string resultStr = "";
  int i = 1;
  for (auto rit = dollarStr.rbegin(); rit != dollarStr.rend(); ++rit, ++i) {
    resultStr += *rit;
    if (i % 3 == 0 && rit != dollarStr.rend() - 1) resultStr += '.';
  }
  for (auto rit = resultStr.rbegin(); rit != resultStr.rend(); ++rit)
    cout << *rit;
  if (sum % 100) cout << '.' << setfill('0') << setw(2) << sum % 100;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how many ways are there to extract k ≥ 1 non-overlapping substrings from it such that each of them contains string t as a substring? More formally, you need to calculate the number of ways to choose two sequences a1, a2, ..., ak and b1, b2, ..., bk satisfying the following requirements:

  * k ≥ 1
  * <image>
  * <image>
  * <image>
  * <image> t is a substring of string saisai + 1... sbi (string s is considered as 1-indexed).

As the number of ways can be rather large print it modulo 109 + 7.

Input

Input consists of two lines containing strings s and t (1 ≤ |s|, |t| ≤ 105). Each string consists of lowercase Latin letters.

Output

Print the answer in a single line.

Examples

Input

ababa
aba

Output

5

Input

welcometoroundtwohundredandeightytwo
d

Output

274201

Input

ddd
d

Output

12

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MX = 100005;
char s[MX], t[MX];
int st[MX];
int pi[MX];
long long dp[MX], sum[MX], sums[MX];
void calc_pi(char *p, int pn) {
  int i, q;
  pi[1] = q = 0;
  for (i = 1; i < pn; i++) {
    for (; q && p[q] != p[i]; q = pi[q])
      ;
    if (p[q] == p[i]) q++;
    pi[i + 1] = q;
  }
}
void KMP(char *t, int tn, char *p, int pn) {
  int i, q;
  calc_pi(p, pn);
  q = 0;
  for (i = 0; i < tn; i++) {
    for (; q && p[q] != t[i]; q = pi[q])
      ;
    if (p[q] == t[i]) q++;
    if (q == pn) {
      st[i - pn + 1] = i;
      q = pi[q];
    }
  }
}
int main() {
  memset(st, -1, sizeof(st));
  cin >> s >> t;
  KMP(s, strlen(s), t, strlen(t));
  int n = strlen(s);
  int save = n;
  for (int i = n - 1; i >= 0; i--) {
    if (st[i] != -1) {
      dp[i] = save - st[i] + sums[st[i] + 1] - sums[save + 1] + dp[i + 1];
      dp[i] %= 1000000007;
      save = st[i];
    } else {
      dp[i] = dp[i + 1];
    }
    sum[i] = sum[i + 1] + dp[i];
    sums[i] = sums[i + 1] + sum[i];
    sums[i] %= 1000000007;
    sum[i] %= 1000000007;
  }
  long long rlt = 0;
  for (int i = 0; i < n; i++) {
    rlt += dp[i];
    rlt %= 1000000007;
  }
  cout << rlt % 1000000007 << endl;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substring of ABCDEF.

You are given two strings s1, s2 and another string called virus. Your task is to find the longest common subsequence of s1 and s2, such that it doesn't contain virus as a substring.

Input

The input contains three strings in three separate lines: s1, s2 and virus (1 ≤ |s1|, |s2|, |virus| ≤ 100). Each string consists only of uppercase English letters.

Output

Output the longest common subsequence of s1 and s2 without virus as a substring. If there are multiple answers, any of them will be accepted.

If there is no valid common subsequence, output 0.

Examples

Input

AJKEQSLOBSROFGZ
OVGURWZLWVLUXTH
OZ

Output

ORZ

Input

AA
A
A

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long sz = 105;
long long dp[sz][sz][sz], len1, len2, len3;
long long prefMatch[sz][26];
char s1[sz], s2[sz], s3[sz];
string ans;
long long solve(long long pos1, long long pos2, long long pos3) {
  if (pos3 > len3) return -(1LL << 61);
  if (pos1 > len1 || pos2 > len2) return 0;
  long long &ret = dp[pos1][pos2][pos3];
  if (ret != -1) return ret;
  ret = solve(pos1 + 1, pos2, pos3);
  ret = max(ret, solve(pos1, pos2 + 1, pos3));
  if (s1[pos1] == s2[pos2]) {
    if (s3[pos3] == s1[pos1])
      ret = max(ret, 1 + solve(pos1 + 1, pos2 + 1, pos3 + 1));
    else {
      long long mx = (s3[1] == s1[pos1]) ? 1 : 0, ch = s1[pos1] - 'A';
      ;
      mx = max(mx, prefMatch[pos3 - 1][ch]);
      ret = max(ret, 1 + solve(pos1 + 1, pos2 + 1, mx + 1));
    }
  }
  return ret;
}
void make_ans(long long pos1, long long pos2, long long pos3, long long res) {
  if (pos1 > len1 || pos2 > len2) return;
  if (solve(pos1 + 1, pos2, pos3) == res)
    make_ans(pos1 + 1, pos2, pos3, res);
  else if (solve(pos1, pos2 + 1, pos3) == res)
    make_ans(pos1, pos2 + 1, pos3, res);
  else {
    ans.push_back(s1[pos1]);
    if (s3[pos3] == s1[pos1])
      make_ans(pos1 + 1, pos2 + 1, pos3 + 1, res - 1);
    else {
      long long mx = (s3[1] == s1[pos1]) ? 1 : 0, ch = s1[pos1] - 'A';
      mx = max(mx, prefMatch[pos3 - 1][ch]);
      make_ans(pos1 + 1, pos2 + 1, mx + 1, res - 1);
    }
  }
}
int main() {
  scanf("%s %s %s", s1 + 1, s2 + 1, s3 + 1);
  len1 = strlen(s1 + 1);
  len2 = strlen(s2 + 1);
  len3 = strlen(s3 + 1);
  for (long long i = 1; i <= len3; ++i) {
    for (long long j = i, k = 1; j <= len3; j++, k++) {
      if (s3[j] != s3[k]) break;
      if (k + 1 <= len3) {
        long long ch = s3[k + 1] - 'A';
        prefMatch[j][ch] = max(prefMatch[j][ch], k + 1);
      }
    }
  }
  memset(dp, -1, sizeof(dp));
  long long got = solve(1, 1, 1);
  if (got == 0) {
    cout << 0 << '\n';
    return 0;
  }
  make_ans(1, 1, 1, got);
  cout << ans << '\n';
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

In a far away galaxy there are n inhabited planets, numbered with numbers from 1 to n. They are located at large distances from each other, that's why the communication between them was very difficult until on the planet number 1 a hyperdrive was invented. As soon as this significant event took place, n - 1 spaceships were built on the planet number 1, and those ships were sent to other planets to inform about the revolutionary invention.

Paradoxical thought it may be, but the hyperspace is represented as simple three-dimensional Euclidean space. The inhabited planets may be considered fixed points in it, and no two points coincide and no three points lie on the same straight line. The movement of a ship with a hyperdrive between two planets is performed along a straight line at the constant speed, the same for all the ships. That's why the distance in the hyperspace are measured in hyperyears (a ship with a hyperdrive covers a distance of s hyperyears in s years).

When the ship reaches an inhabited planet, the inhabitants of the planet dissemble it, make n - 2 identical to it ships with a hyperdrive and send them to other n - 2 planets (except for the one from which the ship arrived). The time to make a new ship compared to the time in which they move from one planet to another is so small that it can be disregarded. New ships are absolutely identical to the ones sent initially: they move at the same constant speed along a straight line trajectory and, having reached a planet, perform the very same mission, i.e. are dissembled to build new n - 2 ships and send them to all the planets except for the one from which the ship arrived. Thus, the process of spreading the important news around the galaxy continues.

However the hyperdrive creators hurried to spread the news about their invention so much that they didn't study completely what goes on when two ships collide in the hyperspace. If two moving ships find themselves at one point, they provoke an explosion of colossal power, leading to the destruction of the galaxy!

Your task is to find the time the galaxy will continue to exist from the moment of the ships' launch from the first planet.

Input

The first line contains a number n (3 ≤ n ≤ 5000) — the number of inhabited planets in the galaxy. The next n lines contain integer coordinates of the planets in format "xi yi zi" ( - 104 ≤ xi, yi, zi ≤ 104).

Output

Print the single number — the solution to the task with an absolute or relative error not exceeding 10 - 6.

Examples

Input

4
0 0 0
0 0 1
0 1 0
1 0 0

Output

1.7071067812

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y, z;
  point() {}
};
double dis(point A, point B) {
  return sqrt(pow(A.x - B.x, 2) + pow(A.y - B.y, 2) + pow(A.z - B.z, 2));
}
double per(point A, point B, point C) {
  return dis(A, B) + dis(B, C) + dis(C, A);
}
point p[5000];
int main() {
  int n, i, k;
  double ret = 1000000000;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d %d %d", &p[i].x, &p[i].y, &p[i].z);
  for (i = 1; i < n - 1; i++)
    for (k = i + 1; k < n; k++) ret = min(ret, 0.5 * per(p[0], p[i], p[k]));
  printf("%.10lf", ret);
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.

But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.

Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.

It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.

Input

The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.

Output

Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».

Examples

Input

4 2

Output

1/2

Note

Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool isprime(unsigned long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (unsigned long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int y, w;
  cin >> y >> w;
  long long int n, d = 6, i, j, k;
  k = max(y, w);
  n = 7 - k;
  for (i = n; i >= 2; i--) {
    if ((n % i == 0) && (6 % i == 0)) {
      n = n / i;
      d = 6 / i;
      break;
    }
  }
  cout << n << "/" << d;
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

There are n candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from 1 to n. The i-th box contains r_i candies, candies have the color c_i (the color can take one of three values — red, green, or blue). All candies inside a single box have the same color (and it is equal to c_i).

Initially, Tanya is next to the box number s. Tanya can move to the neighbor box (that is, with a number that differs by one) or eat candies in the current box. Tanya eats candies instantly, but the movement takes one second.

If Tanya eats candies from the box, then the box itself remains in place, but there is no more candies in it. In other words, Tanya always eats all the candies from the box and candies in the boxes are not refilled.

It is known that Tanya cannot eat candies of the same color one after another (that is, the colors of candies in two consecutive boxes from which she eats candies are always different). In addition, Tanya's appetite is constantly growing, so in each next box from which she eats candies, there should be strictly more candies than in the previous one.

Note that for the first box from which Tanya will eat candies, there are no restrictions on the color and number of candies.

Tanya wants to eat at least k candies. What is the minimum number of seconds she will need? Remember that she eats candies instantly, and time is spent only on movements.

Input

The first line contains three integers n, s and k (1 ≤ n ≤ 50, 1 ≤ s ≤ n, 1 ≤ k ≤ 2000) — number of the boxes, initial position of Tanya and lower bound on number of candies to eat. The following line contains n integers r_i (1 ≤ r_i ≤ 50) — numbers of candies in the boxes. The third line contains sequence of n letters 'R', 'G' and 'B', meaning the colors of candies in the correspondent boxes ('R' for red, 'G' for green, 'B' for blue). Recall that each box contains candies of only one color. The third line contains no spaces.

Output

Print minimal number of seconds to eat at least k candies. If solution doesn't exist, print "-1".

Examples

Input

5 3 10
1 2 3 4 5
RGBRR

Output

4

Input

2 1 15
5 6
RG

Output

-1

Note

The sequence of actions of Tanya for the first example:

  * move from the box 3 to the box 2;
  * eat candies from the box 2;
  * move from the box 2 to the box 3;
  * eat candy from the box 3;
  * move from the box 3 to the box 4;
  * move from the box 4 to the box 5;
  * eat candies from the box 5.

Since Tanya eats candy instantly, the required time is four seconds.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int N, S, K;
char colors[55];
vector<array<int, 2>> arr;
int dp[55][2005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> S >> K;
  arr.resize(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> arr[i][0];
    arr[i][1] = i;
  }
  for (int i = 1; i <= N; i++) {
    cin >> colors[i];
  }
  memset(dp, -1, sizeof dp);
  sort(arr.begin() + 1, arr.begin() + N + 1);
  for (int i = N; i >= 1; i--) {
    for (int j = 0; j <= K; j++) {
      if (arr[i][0] >= j) {
        dp[i][j] = 0;
        continue;
      }
      for (int k = i + 1; k <= N; k++) {
        if (colors[arr[k][1]] == colors[arr[i][1]]) continue;
        if (arr[k][0] == arr[i][0]) continue;
        if (dp[k][j - arr[i][0]] != -1) {
          int amt = dp[k][j - arr[i][0]] + abs(arr[i][1] - arr[k][1]);
          if (dp[i][j] == -1 || amt < dp[i][j]) {
            dp[i][j] = amt;
          }
        }
      }
    }
  }
  int ans = -1;
  for (int i = 1; i <= N; i++) {
    if (dp[i][K] != -1) {
      int amt = dp[i][K] + abs(arr[i][1] - S);
      if (ans == -1 || amt < ans) {
        ans = amt;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

This is an interactive problem.

Now Serval is a senior high school student in Japari Middle School. However, on the way to the school, he must go across a pond, in which there is a dangerous snake. The pond can be represented as a n × n grid. The snake has a head and a tail in different cells, and its body is a series of adjacent cells connecting the head and the tail without self-intersecting. If Serval hits its head or tail, the snake will bite him and he will die.

Luckily, he has a special device which can answer the following question: you can pick a rectangle, it will tell you the number of times one needs to cross the border of the rectangle walking cell by cell along the snake from the head to the tail. The pictures below show a possible snake and a possible query to it, which will get an answer of 4.

<image> <image>

Today Serval got up too late and only have time to make 2019 queries. As his best friend, can you help him find the positions of the head and the tail?

Note that two cells are adjacent if and only if they have a common edge in the grid, and a snake can have a body of length 0, that means it only has adjacent head and tail.

Also note that the snake is sleeping, so it won't move while Serval using his device. And what's obvious is that the snake position does not depend on your queries.

Input

The first line contains a single integer n (2≤ n ≤ 1000) — the size of the grid.

Output

When you are ready to answer, you should print ! x1 y1 x2 y2, where (x_1, y_1) represents the position of the head and (x_2,y_2) represents the position of the tail. You can print head and tail in any order.

Interaction

To make a query, you should print ? x1 y1 x2 y2 (1 ≤ x_1 ≤ x_2 ≤ n, 1≤ y_1 ≤ y_2 ≤ n), representing a rectangle consisting of all cells (x,y) such that x_1 ≤ x ≤ x_2 and y_1 ≤ y ≤ y_2. You will get a single integer as the answer.

After printing a query, do not forget to output the end of line and flush the output, otherwise you will get Idleness limit exceeded. To do this, use:

  * fflush(stdout) or cout.flush() in C++;
  * System.out.flush() in Java;
  * flush(output) in Pascal;
  * stdout.flush() in Python;
  * see documentation for other languages.

Answer -1 instead of a valid answer means that you made an invalid query or exceeded the maximum number of queries. Exit immediately after receiving -1 and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.

If your program cannot find out the head and tail of the snake correctly, you will also get a Wrong Answer verdict.

Hacks

To make a hack, print a single integer n (2 ≤ n ≤ 1000) in the first line, indicating the size of the grid.

Then print an integer k (2 ≤ k ≤ n^2) in the second line, indicating the length of the snake.

In the next k lines, print k pairs of integers x_i, y_i (1 ≤ x_i, y_i ≤ n), each pair in a single line, indicating the i-th cell of snake, such that the adjacent pairs are adjacent, and all k pairs are distinct.

Examples

Input

2

1

0

0

Output

? 1 1 1 1

? 1 2 1 2

? 2 2 2 2

! 1 1 2 1

Input

3

2

0

Output

? 2 2 2 2

? 2 1 2 3

! 2 1 2 3

Note

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

The pictures above show our queries and the answers in the first example. We first made a query for (1,1) and got an answer 1, then found that it must be connected to exactly one other cell. Then we made a query for (1,2) and got an answer of 0, then knew that the snake never entered it. So the cell connected to (1,1) must be (2,1). Then we made a query for (2,2) and got an answer 0, then knew that it never entered (2,2) as well. So the snake cannot leave (2,1), which implies that the answer is (1,1) and (2,1).

<image> <image> <image>

The pictures above show our queries and the answers in the second example. By making query to (2,2) and receiving 2, we found that the snake occupies (2,2). And by making query to rectangle from (2,1) to (2,3) and receiving answer 0, we knew that it never goes out of the rectangle from (2,1) to (2,3). Since the first answer is 2, both (2,1) and (2,3) must be occupied but none of others, so the answer is (2,1) and (2,3).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
int n;
int qx[2], qy[2], len = 0;
void get(int x) {
  int l = 1, r = n, mid;
  for (; l < r;) {
    mid = (l + r) >> 1;
    printf("? %d %d %d %d\n", x, 1, x, mid);
    fflush(stdout);
    int w;
    scanf("%d", &w);
    if (w & 1)
      r = mid;
    else
      l = mid + 1;
  }
  qx[++len] = x, qy[len] = l;
}
void get2(int x) {
  int l = 1, r = n, mid;
  for (; l < r;) {
    mid = (l + r) >> 1;
    printf("? %d %d %d %d\n", 1, x, mid, x);
    fflush(stdout);
    int w;
    scanf("%d", &w);
    if (w & 1)
      r = mid;
    else
      l = mid + 1;
  }
  qx[++len] = l, qy[len] = x;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    printf("? %d %d %d %d\n", i, 1, i, n);
    fflush(stdout);
    int w;
    scanf("%d", &w);
    if (w & 1) {
      get(i);
      if (len >= 2) break;
    }
  }
  if (!len) {
    for (int i = 1; i <= n; i++) {
      printf("? %d %d %d %d\n", 1, i, n, i);
      fflush(stdout);
      int w;
      scanf("%d", &w);
      if (w & 1) {
        if (!len)
          get2(i);
        else
          qx[++len] = qx[1], qy[len] = i;
        if (len >= 2) break;
      }
    }
  }
  printf("! %d %d %d %d\n", qx[1], qy[1], qx[2], qy[2]);
  fflush(stdout);
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

You are a lover of bacteria. You want to raise some bacteria in a box.

Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment.

What is the minimum number of bacteria you need to put into the box across those days?

Input

The only line containing one integer x (1 ≤ x ≤ 109).

Output

The only line containing one integer: the answer.

Examples

Input

5

Output

2

Input

8

Output

1

Note

For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.

For the second sample, we can put one in the first morning and in the 4-th morning there will be 8 in the box. So the answer is 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, i = 1, ans = 0;
int main() {
  cin >> n;
  while (n > 0) {
    if (n % 2 == 1) {
      ans++;
      n -= 1;
    }
    n /= 2;
  }
  cout << ans << endl;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks.

According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.

Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.

Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.

Can you help him?

Input

The single line of the input contains two positive integers a and b (1 ≤ a, b ≤ 100) — the number of red and blue socks that Vasya's got.

Output

Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.

Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.

Examples

Input

3 1

Output

1 1

Input

2 3

Output

2 0

Input

7 3

Output

3 2

Note

In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b;
  cin >> a >> b;
  if (a > b) {
    cout << b << " " << (a - b) / 2;
  } else
    cout << a << " " << (b - a) / 2;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

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

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

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

Input

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

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

Some positions may coincide.

Output

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

Examples

Input

3
1 1
7 5
1 5

Output

2

Input

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

Output

11

Note

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp1, mp2;
map<pair<int, int>, int> mp;
int n, x, y;
void solve() {
  mp1.clear();
  mp2.clear();
  mp.clear();
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &x, &y);
    pair<int, int> t(x, y);
    ans += mp1[x] + mp2[y] - mp[t];
    mp1[x]++;
    mp2[y]++;
    mp[t]++;
  }
  printf("%I64d\n", ans);
}
int main() {
  while (~scanf("%d", &n)) solve();
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360 degrees and a pointer which initially points at zero:

<image>

Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n times. The i-th rotation should be a_i degrees, either clockwise or counterclockwise, and after all n rotations the pointer should again point at zero.

This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n rotations the pointer will point at zero again.

Input

The first line contains one integer n (1 ≤ n ≤ 15) — the number of rotations.

Each of the following n lines contains one integer a_i (1 ≤ a_i ≤ 180) — the angle of the i-th rotation in degrees.

Output

If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case.

You can print each letter in any case (upper or lower).

Examples

Input

3
10
20
30

Output

YES

Input

3
10
10
10

Output

NO

Input

3
120
120
120

Output

YES

Note

In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise.

In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end.

In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360 degrees clockwise and the pointer will point at zero again.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int BIT[10000005];
int maxi;
int read(int idx) {
  int sum = 0;
  while (idx > 0) {
    sum += BIT[idx];
    idx -= (idx & -idx);
  }
  return sum;
}
void update(int idx, int val) {
  while (idx <= maxi) {
    BIT[idx] += val;
    idx += (idx & -idx);
  }
}
long long n, f = 0;
vector<int> v;
void recur(int index, int sum) {
  if (index == n - 1) {
    if ((sum + v[index]) % 360 == 0 || (sum - v[index]) % 360 == 0) f = 1;
    return;
  }
  recur(index + 1, sum + v[index]);
  recur(index + 1, sum - v[index]);
  return;
}
int main() {
  long long k;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> k;
    v.push_back(k);
  }
  recur(0, 0);
  if (f)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Recently you have bought a snow walking robot and brought it home. Suppose your home is a cell (0, 0) on an infinite grid.

You also have the sequence of instructions of this robot. It is written as the string s consisting of characters 'L', 'R', 'U' and 'D'. If the robot is in the cell (x, y) right now, he can move to one of the adjacent cells (depending on the current instruction).

  * If the current instruction is 'L', then the robot can move to the left to (x - 1, y);
  * if the current instruction is 'R', then the robot can move to the right to (x + 1, y);
  * if the current instruction is 'U', then the robot can move to the top to (x, y + 1);
  * if the current instruction is 'D', then the robot can move to the bottom to (x, y - 1).

You've noticed the warning on the last page of the manual: if the robot visits some cell (except (0, 0)) twice then it breaks.

So the sequence of instructions is valid if the robot starts in the cell (0, 0), performs the given instructions, visits no cell other than (0, 0) two or more times and ends the path in the cell (0, 0). Also cell (0, 0) should be visited at most two times: at the beginning and at the end (if the path is empty then it is visited only once). For example, the following sequences of instructions are considered valid: "UD", "RL", "UUURULLDDDDLDDRRUU", and the following are considered invalid: "U" (the endpoint is not (0, 0)) and "UUDD" (the cell (0, 1) is visited twice).

The initial sequence of instructions, however, might be not valid. You don't want your robot to break so you decided to reprogram it in the following way: you will remove some (possibly, all or none) instructions from the initial sequence of instructions, then rearrange the remaining instructions as you wish and turn on your robot to move.

Your task is to remove as few instructions from the initial sequence as possible and rearrange the remaining ones so that the sequence is valid. Report the valid sequence of the maximum length you can obtain.

Note that you can choose any order of remaining instructions (you don't need to minimize the number of swaps or any other similar metric).

You have to answer q independent test cases.

Input

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

The next q lines contain test cases. The i-th test case is given as the string s consisting of at least 1 and no more than 10^5 characters 'L', 'R', 'U' and 'D' — the initial sequence of instructions.

It is guaranteed that the sum of |s| (where |s| is the length of s) does not exceed 10^5 over all test cases (∑ |s| ≤ 10^5).

Output

For each test case print the answer on it. In the first line print the maximum number of remaining instructions. In the second line print the valid sequence of remaining instructions t the robot has to perform. The moves are performed from left to right in the order of the printed sequence. If there are several answers, you can print any. If the answer is 0, you are allowed to print an empty line (but you can don't print it).

Example

Input

6
LRU
DURLDRUDRULRDURDDL
LRUDDLRUDRUL
LLLLRRRR
URDUR
LLL

Output

2
LR
14
RUURDDDDLLLUUR
12
ULDDDRRRUULL
2
LR
2
UD
0

Note

There are only two possible answers in the first test case: "LR" and "RL".

The picture corresponding to the second test case:

<image> Note that the direction of traverse does not matter

Another correct answer to the third test case: "URDDLLLUURDR".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void printar(int ar[], int s) {
  cout << "Sended array is : " << endl;
  for (int i = 0; i < s; i++) cout << ar[i] << " ";
  cout << endl;
  cout << "__________________________________________________" << endl;
}
void printch(char ch, int n) {
  for (int i = 0; i < n; i++) {
    cout << ch;
  }
}
void solve() {
  string st;
  cin >> st;
  int d, u, l, r;
  d = u = l = r = 0;
  int len = st.size();
  for (int i = 0; i < len; i++) {
    if (st[i] == 'D')
      d++;
    else if (st[i] == 'U')
      u++;
    else if (st[i] == 'L')
      l++;
    else if (st[i] == 'R')
      r++;
  }
  int lr = min(l, r);
  int ud = min(u, d);
  if (lr == 0 and ud == 0) {
    cout << "0" << endl;
    return;
  }
  if (lr == 0) {
    cout << "2\n";
    cout << "UD\n";
    return;
  }
  if (ud == 0) {
    cout << "2\n";
    cout << "LR\n";
    return;
  }
  int res = (lr * 2) + (ud * 2);
  cout << res << "\n";
  printch('R', lr);
  printch('U', ud);
  printch('L', lr);
  printch('D', ud);
  cout << endl;
  return;
}
int main() {
  int tc = 1;
  int m;
  cin >> tc;
  for (int i = 0; i < tc; i++) {
    solve();
  }
  return 0;
}

```