### Prompt

Construct a Cpp code solution to the problem outlined:

Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.

Output

Output the single number — the number of Alyona's leaves.

Examples

Input

5
birch yellow
maple red
birch yellow
maple yellow
maple green

Output

4

Input

3
oak yellow
oak yellow
oak yellow

Output

1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, i;
  cin >> n;
  set<pair<string, string> > a;
  string c, d;
  for (i = 0; i < n; i++) {
    cin >> c >> d;
    a.insert(make_pair(c, d));
  }
  cout << a.size() << "\n";
  return 0;
}

```


### Prompt

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

In the country there are N cities numbered 1 through N, which are connected by N-1 bidirectional roads. In terms of graph theory, there is a unique simple path connecting every pair of cities. That is, the N cities form a tree. Besides, if we view city 1 as the root of this tree, the tree will be a full binary tree (a tree is a full binary tree if and only if every non-leaf vertex in the tree has exactly two children). Roads are numbered 1 through N-1. The i-th road connects city i+1 and city a_i. When you pass through road i, the toll you should pay is v_i (if v_i is 0, it indicates the road does not require a toll).

A company in city 1 will give each employee a family travel and cover a large part of the tolls incurred. Each employee can design the travel by themselves. That is, which cities he/she wants to visit in each day and which city to stay at each night. However, there are some constraints. More details are as follows:

* The travel must start and end at city 1. If there are m leaves in the tree formed by the cities, then the number of days in the travel must be m+1. At the end of each day, except for the last day, the employee must stay at some hotel in a leaf city. During the whole travel, the employee must stay at all leaf cities exactly once.

* During the whole travel, all roads of the country must be passed through exactly twice.

* The amount that the employee must pay for tolls by him/herself is the maximum total toll incurred in a single day during the travel, except the first day and the last day. The remaining tolls will be covered by the company.

Shik, as an employee of this company, has only one hope for his travel. He hopes that the amount he must pay for tolls by himself will be as small as possible. Please help Shik to design the travel which satisfies his hope.

Constraints

* 2 < N < 131,072
* 1 \leq a_i \leq i for all i
* 0 \leq v_i \leq 131,072
* v_i is an integer
* The given tree is a full binary tree

Input

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

N
a_1 v_1
a_2 v_2
:
a_{N-1} v_{N-1}

Output

Print an integer denoting the minimum amount Shik must pay by himself for tolls incurred during the travel.

Examples

Input

7
1 1
1 1
2 1
2 1
3 1
3 1

Output

4

Input

9
1 2
1 2
3 2
3 2
5 2
5 2
7 2
7 2

Output

6

Input

15
1 2
1 5
3 3
4 3
4 3
6 5
5 4
5 3
6 3
3 2
11 5
11 3
13 2
13 1

Output

15

Input

3
1 0
1 0

Output

0

### Response

```cpp
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;
typedef vector<pii> Vp;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=140000+19;

struct Edge{
	int y,z,nxt;
} E[N*2];

int las[N];
int n,cnt,x;
ll l,r,mid;

void Add_Edge(int x,int y,int z){
	E[cnt]=(Edge){y,z,las[x]};las[x]=cnt++;
}
Vp Merge(Vp A,Vp B){
	Vp res,ans;
	int c=-1;
	For(i,0,A.size()){
		for (;c+1<B.size()&&A[i].se+B[c+1].fi<=mid;c++);
		if (c>=0) res.pb(mp(A[i].fi,B[c].se));
	}
	c=-1;
	For(i,0,B.size()){
		for (;c+1<A.size()&&B[i].se+A[c+1].fi<=mid;c++);
		if (c>=0) res.pb(mp(B[i].fi,A[c].se));
	}
	sort(res.begin(),res.end());
	For(i,0,res.size()){
		//if (res[i].fi>mid||res[i].se>mid) continue;
		if (!ans.empty()&&res[i].se>=ans.back().se) continue;
		ans.pb(res[i]);
	}
	return ans;
}
Vp dfs(int x){
	if (las[x]==-1){
		return {mp(0,0)};
	}
	Vp V[2];
	int len[2],c=0;
	for (int i=las[x],y;~i;i=E[i].nxt){
		y=E[i].y;
		V[c]=dfs(y);
		len[c++]=E[i].z;
	}
	For(i,0,2) For(j,0,V[i].size()){
		V[i][j].fi+=len[i];
		V[i][j].se+=len[i];
	}
	return Merge(V[0],V[1]);
}

int main(){
	memset(las,-1,sizeof(las));
	n=IN();
	For(i,2,n+1){
		x=IN();
		Add_Edge(x,i,IN());
	}
	l=0,r=131072ll*n;
	while (l<=r){
		mid=(l+r)/2;
		if (!dfs(1).empty()) r=mid-1;else l=mid+1;
	}
	cout<<r+1<<endl;
}
```


### Prompt

Create a solution in cpp for 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;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q = 0, l = 0, r = 0, u = 0, d = 0, x = 0, y = 0;
  string s;
  cin >> q;
  while (q--) {
    cin >> s;
    l = 0;
    r = 0;
    u = 0;
    d = 0;
    for (int i = 0; i < s.length(); ++i) {
      if (s[i] == 'L')
        ++l;
      else if (s[i] == 'R')
        ++r;
      else if (s[i] == 'U')
        ++u;
      else
        ++d;
    }
    x = min(l, r);
    y = min(u, d);
    if (l == 0 || r == 0) x = 0;
    if (u == 0 || d == 0) y = 0;
    if (x == 0) {
      if (y == 0) {
        cout << "0" << endl;
        continue;
      } else {
        cout << "2" << endl;
        cout << "UD" << endl;
        continue;
      }
    } else if (y == 0) {
      cout << "2" << endl;
      cout << "LR" << endl;
      continue;
    } else {
      cout << 2 * (x + y) << endl;
      for (int i = 1; i <= y; ++i) cout << "U";
      for (int i = 1; i <= x; ++i) cout << "R";
      for (int i = 1; i <= y; ++i) cout << "D";
      for (int i = 1; i <= x; ++i) cout << "L";
      cout << endl;
      continue;
    }
  }
}

```


### Prompt

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

You have matrix a of size n × n. Let's number the rows of the matrix from 1 to n from top to bottom, let's number the columns from 1 to n from left to right. Let's use aij to represent the element on the intersection of the i-th row and the j-th column.

Matrix a meets the following two conditions:

  * for any numbers i, j (1 ≤ i, j ≤ n) the following inequality holds: aij ≥ 0;
  * <image>.

Matrix b is strictly positive, if for any numbers i, j (1 ≤ i, j ≤ n) the inequality bij > 0 holds. You task is to determine if there is such integer k ≥ 1, that matrix ak is strictly positive.

Input

The first line contains integer n (2 ≤ n ≤ 2000) — the number of rows and columns in matrix a.

The next n lines contain the description of the rows of matrix a. The i-th line contains n non-negative integers ai1, ai2, ..., ain (0 ≤ aij ≤ 50). It is guaranteed that <image>.

Output

If there is a positive integer k ≥ 1, such that matrix ak is strictly positive, print "YES" (without the quotes). Otherwise, print "NO" (without the quotes).

Examples

Input

2
1 0
0 1

Output

NO

Input

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

Output

YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void mine(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
inline void maxe(T1 &x, T2 y) {
  if (x < y) x = y;
}
ostream &operator<<(ostream &a, const vector<long long> &b) {
  for (auto k : b) cout << k << ' ';
  return a;
}
const long long MOD = 1000000007;
const long long INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const long long MX = 2001;
const double EPS = 1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
bitset<MX> used1;
bitset<MX> used2;
long long n;
void dfs(long long v, vector<vector<long long> > &a, bool inv = false) {
  if (inv)
    used2[v] = true;
  else
    used1[v] = true;
  for (long long i = 0; i < n; i++) {
    if (inv && !used2[i] && a[i][v] > 0)
      dfs(i, a, inv);
    else if (!inv && !used1[i] && a[v][i] > 0)
      dfs(i, a, inv);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  vector<vector<long long> > a(n, vector<long long>(n));
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < n; j++) cin >> a[i][j];
  for (long long i = 0; i < n; i++) {
    if (a[i][i] > 0) {
      dfs(i, a, false);
      dfs(i, a, true);
      break;
    }
  }
  cout << (used1.count() + used2.count() == 2 * n ? "YES\n" : "NO\n");
}

```


### Prompt

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

Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A", "T", "G", "C". A DNA strand is a sequence of nucleotides. Scientists decided to track evolution of a rare species, which DNA strand was string s initially.

Evolution of the species is described as a sequence of changes in the DNA. Every change is a change of some nucleotide, for example, the following change can happen in DNA strand "AAGC": the second nucleotide can change to "T" so that the resulting DNA strand is "ATGC".

Scientists know that some segments of the DNA strand can be affected by some unknown infections. They can represent an infection as a sequence of nucleotides. Scientists are interested if there are any changes caused by some infections. Thus they sometimes want to know the value of impact of some infection to some segment of the DNA. This value is computed as follows:

  * Let the infection be represented as a string e, and let scientists be interested in DNA strand segment starting from position l to position r, inclusive.
  * Prefix of the string eee... (i.e. the string that consists of infinitely many repeats of string e) is written under the string s from position l to position r, inclusive.
  * The value of impact is the number of positions where letter of string s coincided with the letter written under it.

Being a developer, Innokenty is interested in bioinformatics also, so the scientists asked him for help. Innokenty is busy preparing VK Cup, so he decided to delegate the problem to the competitors. Help the scientists!

Input

The first line contains the string s (1 ≤ |s| ≤ 105) that describes the initial DNA strand. It consists only of capital English letters "A", "T", "G" and "C".

The next line contains single integer q (1 ≤ q ≤ 105) — the number of events.

After that, q lines follow, each describes one event. Each of the lines has one of two formats:

  * 1 x c, where x is an integer (1 ≤ x ≤ |s|), and c is a letter "A", "T", "G" or "C", which means that there is a change in the DNA: the nucleotide at position x is now c.
  * 2 l r e, where l, r are integers (1 ≤ l ≤ r ≤ |s|), and e is a string of letters "A", "T", "G" and "C" (1 ≤ |e| ≤ 10), which means that scientists are interested in the value of impact of infection e to the segment of DNA strand from position l to position r, inclusive.

Output

For each scientists' query (second type query) print a single integer in a new line — the value of impact of the infection on the DNA.

Examples

Input

ATGCATGC
4
2 1 8 ATGC
2 2 6 TTT
1 4 T
2 2 6 TA

Output

8
2
4

Input

GAGTTGTTAA
6
2 3 4 TATGGTG
1 1 T
1 6 G
2 5 9 AGTAATA
1 10 G
2 2 6 TTGT

Output

0
3
1

Note

Consider the first example. In the first query of second type all characters coincide, so the answer is 8. In the second query we compare string "TTTTT..." and the substring "TGCAT". There are two matches. In the third query, after the DNA change, we compare string "TATAT..."' with substring "TGTAT". There are 4 matches.

### Response

```cpp
#include <bits/stdc++.h>
const double pi = 4.0 * atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int maxm = 1005000;
const int mod = 1e9 + 7;
using namespace std;
int n, m;
int T, tol;
int cnt[4][11][10][maxn];
char s[maxn];
int mx;
int getid(char c) {
  if (c == 'A') return 0;
  if (c == 'T') return 1;
  if (c == 'C') return 2;
  if (c == 'G') return 3;
}
void update(int id, int i, int j, int pos, int val) {
  for (int x = pos; x <= mx + 1; x += (x & (-x))) cnt[id][i][j][x] += val;
}
int query(int id, int i, int j, int pos) {
  int ans = 0;
  for (int x = pos; x > 0; x -= (x & (-x))) ans += cnt[id][i][j][x];
  return ans;
}
void init() {
  for (int i = 1; i <= 10; i++) {
    for (int j = 1; j <= mx; j++) {
      update(getid(s[j]), i, (j - 1) % i, j, 1);
    }
  }
}
int main() {
  scanf("%s", s + 1);
  mx = strlen(s + 1);
  memset(cnt, 0, sizeof cnt);
  init();
  int q;
  scanf("%d", &q);
  while (q--) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      int pos;
      char tmp[15];
      scanf("%d%s", &pos, tmp);
      for (int i = 1; i <= 10; i++)
        update(getid(s[pos]), i, (pos - 1) % i, pos, -1);
      for (int i = 1; i <= 10; i++)
        update(getid(tmp[0]), i, (pos - 1) % i, pos, 1);
      s[pos] = tmp[0];
    } else {
      int l, r;
      char tmp[15];
      scanf("%d%d%s", &l, &r, tmp);
      int len = strlen(tmp);
      int ans = 0;
      for (int i = 0; i < len; i++) {
        ans += query(getid(tmp[i]), len, (l + i - 1) % len, r) -
               query(getid(tmp[i]), len, (l + i - 1) % len, l - 1);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

For given two segments s1 and s2, print the coordinate of the cross point of them.

s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3.

Constraints

* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.
* The given segments have a cross point and are not in parallel.

Input

The entire input looks like:

q (the number of queries)
1st query
2nd query
...
qth query

Each query consists of integer coordinates of end points of s1 and s2 in the following format:

xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3

Output

For each query, print the coordinate of the cross point. The output values should be in a decimal fraction with an error less than 0.00000001.

Example

Input

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

Output

1.0000000000 0.0000000000
0.5000000000 0.5000000000
0.5000000000 0.5000000000

### Response

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

P calc(P a,P b,P c,P d){
  double A=imag((a-d)*conj(d-c));
  double B=imag((b-d)*conj(d-c));
  return a+(b-a)*A/(A-B);
}

int main(){
  int n;
  double ax,ay,bx,by,cx,cy,dx,dy;
  scanf("%d",&n);
  while(n--){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy);
    P ans=calc(P(ax,ay),P(bx,by),P(cx,cy),P(dx,dy));
    printf("%.8f %.8f\n",ans.real(),ans.imag());
  }
  return 0;
}
```


### Prompt

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

Phoenix has a string s consisting of lowercase Latin letters. He wants to distribute all the letters of his string into k non-empty strings a_1, a_2, ..., a_k such that every letter of s goes to exactly one of the strings a_i. The strings a_i do not need to be substrings of s. Phoenix can distribute letters of s and rearrange the letters within each string a_i however he wants.

For example, if s =  baba and k=2, Phoenix may distribute the letters of his string in many ways, such as:

  * ba and ba
  * a and abb
  * ab and ab
  * aa and bb

But these ways are invalid:

  * baa and ba
  * b and ba
  * baba and empty string (a_i should be non-empty)

Phoenix wants to distribute the letters of his string s into k strings a_1, a_2, ..., a_k to minimize the lexicographically maximum string among them, i. e. minimize max(a_1, a_2, ..., a_k). Help him find the optimal distribution and print the minimal possible value of max(a_1, a_2, ..., a_k).

String x is lexicographically less than string y if either x is a prefix of y and x ≠ y, or there exists an index i (1 ≤ i ≤ min(|x|, |y|)) such that x_i < y_i and for every j (1 ≤ j < i) x_j = y_j. Here |x| denotes the length of the string x.

Input

The input consists of multiple test cases. The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases. Each test case consists of two lines.

The first line of each test case consists of two integers n and k (1 ≤ k ≤ n ≤ 10^5) — the length of string s and the number of non-empty strings, into which Phoenix wants to distribute letters of s, respectively.

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

It is guaranteed that the sum of n over all test cases is ≤ 10^5.

Output

Print t answers — one per test case. The i-th answer should be the minimal possible value of max(a_1, a_2, ..., a_k) in the i-th test case.

Example

Input

6
4 2
baba
5 2
baacb
5 3
baacb
5 3
aaaaa
6 4
aaxxzz
7 1
phoenix

Output

ab
abbc
b
aa
x
ehinopx

Note

In the first test case, one optimal solution is to distribute baba into ab and ab.

In the second test case, one optimal solution is to distribute baacb into abbc and a.

In the third test case, one optimal solution is to distribute baacb into ac, ab, and b.

In the fourth test case, one optimal solution is to distribute aaaaa into aa, aa, and a.

In the fifth test case, one optimal solution is to distribute aaxxzz into az, az, x, and x.

In the sixth test case, one optimal solution is to distribute phoenix into ehinopx.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int bin(long int a[], long int low, long int high, long d, long day[]) {
  if (low > high) return -1;
  long mid = (low + high) / 2;
  if (a[mid] > (a[low] + d) && (a[mid - 1] <= (a[low] + d) || day[mid - 1]) &&
      day[mid] == 0)
    return mid;
  else if (a[mid] > (a[low] + d) && day[mid] == 0)
    return bin(a, low, mid - 1, d, day);
  else
    return bin(a, mid + 1, high, d - a[mid + 1] + a[low], day);
}
bool sortbysecdesc(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first > b.first;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  for (int X = 1; X <= t; X++) {
    int n, k, p, i;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<char> v;
    for (long long int i = 0; i < (n); i++) v.push_back(s[i]);
    sort((v).begin(), (v).end());
    if (v[k - 1] > v[0]) {
      cout << v[k - 1] << "\n";
      continue;
    }
    if (v[n - 1] > v[k]) {
      cout << v[0];
      for (i = k; i < n; i++) cout << v[i];
      cout << "\n";
      continue;
    }
    p = (n + k - 1) / k;
    p--;
    cout << v[0];
    for (long long int i = 0; i < (p); i++) cout << v[k];
    cout << "\n";
  }
  return 0;
}

```


### Prompt

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

Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n.

s = f (1) + f (2) + ... + f (n)

Create a program that reads a, b, n, outputs s, and exits.

Input

The input consists of multiple datasets. For each dataset, three integers a (1 ≤ a ≤ 1000), b (1 ≤ b ≤ 10000), n (1 ≤ n ≤ 100) are given on one line, separated by blanks.

The number of datasets does not exceed 100.

Output

Prints s on one line for each dataset.

Example

Input

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

Output

5
24
7
6

### Response

```cpp
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define int long long
signed main(){
	int a,b,n;
	while( scanf("%lld %lld %lld", &a, &b, &n) != EOF ){
		int s=0;
		a = a % b;
		for(int i=1;i<=n;i++){
			a *= 10;
			s += a/b;
			a = a - a/b*b;
		}
		cout << s << endl;
	}
	return 0;
}
```


### Prompt

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

Gardener Alex loves to grow trees. We remind that tree is a connected acyclic graph on n vertices.

Today he decided to grow a rooted binary tree. A binary tree is a tree where any vertex has no more than two sons. Luckily, Alex has a permutation of numbers from 1 to n which he was presented at his last birthday, so he decided to grow a tree according to this permutation. To do so he does the following process: he finds a minimum element and makes it a root of the tree. After that permutation is divided into two parts: everything that is to the left of the minimum element, and everything that is to the right. The minimum element on the left part becomes the left son of the root, and the minimum element on the right part becomes the right son of the root. After that, this process is repeated recursively on both parts.

Now Alex wants to grow a forest of trees: one tree for each cyclic shift of the permutation. He is interested in what cyclic shift gives the tree of minimum depth. Unfortunately, growing a forest is a hard and long process, but Alex wants the answer right now. Will you help him?

We remind that cyclic shift of permutation a_1, a_2, …, a_k, …, a_n for k elements to the left is the permutation a_{k + 1}, a_{k + 2}, …, a_n, a_1, a_2, …, a_k.

Input

First line contains an integer number n ~ (1 ⩽ n ⩽ 200 000) — length of the permutation.

Second line contains n integer numbers a_1, a_2, …, a_n ~ (1 ⩽ a_i ⩽ n), and it is guaranteed that all numbers occur exactly one time.

Output

Print two numbers separated with space: minimum possible depth of a tree and how many elements we need to shift left to achieve this depth. The number of elements should be a number from 0 to n - 1. If there are several possible answers, print any of them.

Example

Input

4
1 2 3 4

Output

3 2

Note

The following picture depicts all possible trees for sample test and cyclic shifts on which they are achieved.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct SegTree {
  struct node {
    int mx, lazy;
    node() { mx = lazy = 0; }
  };
  vector<node> tree;
  void init(int n) {
    tree.resize(4 * n);
    for (int i = 0; i < ((int)tree.size()); i++) {
      tree[i].mx = tree[i].lazy = 0;
    }
  }
  void push(int tl, int tr, int h) {
    if (tl < tr) {
      tree[h * 2].lazy += tree[h].lazy;
      tree[h * 2 + 1].lazy += tree[h].lazy;
    }
    tree[h].mx += tree[h].lazy;
    tree[h].lazy = 0;
  }
  void update(int l, int r, int x, int tl, int tr, int h = 1) {
    push(tl, tr, h);
    if (l > r || tr < l || r < tl) return;
    if (l <= tl && tr <= r) {
      tree[h].lazy += x;
      push(tl, tr, h);
      return;
    }
    int mid = (tl + tr) / 2;
    update(l, r, x, tl, mid, h * 2);
    update(l, r, x, mid + 1, tr, h * 2 + 1);
    tree[h].mx = max(tree[h * 2].mx, tree[h * 2 + 1].mx);
  }
  int query() { return tree[1].mx; }
  int query(int p, int tl, int tr, int h = 1) {
    push(tl, tr, h);
    if (tr < p || p < tl) return 0;
    if (tl == tr) return tree[h].mx;
    int mid = (tl + tr) / 2;
    return max(query(p, tl, mid, h * 2), query(p, mid + 1, tr, h * 2 + 1));
  }
} mst;
int n;
int a[200010], rev[200010];
int dep[200010], L[200010], R[200010];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int i, j;
  cin >> n;
  set<int> st;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    rev[a[i]] = i;
  }
  for (i = 1; i <= n; i++) {
    int pos = rev[i];
    if (i > 1) {
      auto it = st.lower_bound(pos);
      if (it == st.end())
        R[pos] = *st.begin();
      else
        R[pos] = *it;
      if (it == st.begin())
        L[pos] = *st.rbegin();
      else
        L[pos] = *prev(it, 1);
      int par = -1;
      if (it == st.end())
        par = *prev(it, 1);
      else if (it == st.begin())
        par = *it;
      else if (a[*prev(it, 1)] < a[*it])
        par = *it;
      else
        par = *prev(it, 1);
      dep[pos] = dep[par] + 1;
    }
    st.insert(pos);
  }
  mst.init(n + 1);
  for (i = 1; i <= n; i++) {
    mst.update(i, i, dep[i], 1, n);
  }
  int ans = mst.query(), ansk = 0;
  for (i = 1; i < n; i++) {
    if (a[i] == 1) continue;
    int delta = mst.query(L[i], 1, n) + 1 - mst.query(i, 1, n);
    mst.update(i, i, delta, 1, n);
    if (i <= R[i]) {
      mst.update(i + 1, R[i] - 1, -1, 1, n);
    } else {
      mst.update(i + 1, n, -1, 1, n);
      mst.update(1, R[i] - 1, -1, 1, n);
    }
    if (L[i] <= i) {
      mst.update(L[i] + 1, i - 1, 1, 1, n);
    } else {
      mst.update(1, i - 1, 1, 1, n);
      mst.update(L[i] + 1, n, 1, 1, n);
    }
    int qry = mst.query();
    if (qry < ans) {
      ans = qry;
      ansk = i;
    }
  }
  cout << ans + 1 << ' ' << ansk;
  return 0;
}

```


### Prompt

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

The ABC number of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:

* 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)
* T_i = `A` (T_i is the i-th character of T from the beginning.)
* T_j = `B`
* T_k = `C`

For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.

You are given a string S. Each character of S is `A`, `B`, `C` or `?`.

Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings.

This sum can be extremely large, so print the sum modulo 10^9 + 7.

Constraints

* 3 ≤ |S| ≤ 10^5
* Each character of S is `A`, `B`, `C` or `?`.

Input

Input is given from Standard Input in the following format:

S

Output

Print the sum of the ABC numbers of all the 3^Q strings, modulo 10^9 + 7.

Examples

Input

A??C

Output

8

Input

ABCBC

Output

3

Input

????C?????B??????A???????

Output

979596887

### Response

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

long long a[4] = {1};
char s[100005];
int main(){
	scanf("%s", s);
	for(int i = 0; s[i] != '\0'; i++) for(int j = 3; j >= 0; j--)
		a[j] = (a[j]*(s[i]=='?'?3:1) + (j&&(s[i]=='?'||s[i]-'A'==j-1)?a[j-1]:0))%md;
	printf("%lld\n", a[3]);
}

```


### Prompt

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

You are given a permutation p = (p_1, \ldots, p_N) of \\{ 1, \ldots, N \\}. You can perform the following two kinds of operations repeatedly in any order:

* Pay a cost A. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the left by one. That is, replace p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r with p_{l + 1}, p_{l + 2}, \ldots, p_r, p_l, respectively.
* Pay a cost B. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the right by one. That is, replace p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r with p_r, p_l, \ldots, p_{r - 2}, p_{r - 1}, respectively.

Find the minimum total cost required to sort p in ascending order.

Constraints

* All values in input are integers.
* 1 \leq N \leq 5000
* 1 \leq A, B \leq 10^9
* (p_1 \ldots, p_N) is a permutation of \\{ 1, \ldots, N \\}.

Input

Input is given from Standard Input in the following format:

N A B
p_1 \cdots p_N

Output

Print the minimum total cost required to sort p in ascending order.

Examples

Input

3 20 30
3 1 2

Output

20

Input

4 20 30
4 2 3 1

Output

50

Input

1 10 10
1

Output

0

Input

4 1000000000 1000000000
4 3 2 1

Output

3000000000

Input

9 40 50
5 3 4 7 6 1 2 9 8

Output

220

### Response

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

using namespace std;
const int N = 5e3 + 10;
typedef long long ll;

ll a , b , f[N];
int n , p[N];
int main(){
	scanf("%d%lld%lld",&n,&a,&b);
	for (int i = 1;i <= n;i++){
		scanf("%d",p + i);
	}
	p[n + 1] = n + 1;
	memset(f , 0x3f , sizeof f);
	f[0] = 0;

	for (int i = 1;i <= n + 1;i++){
		int g = 0;
		for (int j = i - 1;j >= 0;j--){
			if (p[j] > p[i]){
				g++;
			}else{
				f[i] = min(f[i] , f[j] + 1ll * g * a + 1ll * (i - j - 1 - g) * b);
			}
		}
	}
	cout<<f[n + 1];
	return 0;
}
```


### Prompt

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

You are given an unweighted tree with n vertices. Then n - 1 following operations are applied to the tree. A single operation consists of the following steps:

  1. choose two leaves;
  2. add the length of the simple path between them to the answer;
  3. remove one of the chosen leaves from the tree.

Initial answer (before applying operations) is 0. Obviously after n - 1 such operations the tree will consist of a single vertex.

Calculate the maximal possible answer you can achieve, and construct a sequence of operations that allows you to achieve this answer!

Input

The first line contains one integer number n (2 ≤ n ≤ 2·105) — the number of vertices in the tree.

Next n - 1 lines describe the edges of the tree in form ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi). It is guaranteed that given graph is a tree.

Output

In the first line print one integer number — maximal possible answer.

In the next n - 1 lines print the operations in order of their applying in format ai, bi, ci, where ai, bi — pair of the leaves that are chosen in the current operation (1 ≤ ai, bi ≤ n), ci (1 ≤ ci ≤ n, ci = ai or ci = bi) — choosen leaf that is removed from the tree in the current operation.

See the examples for better understanding.

Examples

Input

3
1 2
1 3

Output

3
2 3 3
2 1 1

Input

5
1 2
1 3
2 4
2 5

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 200100;
long long p1, p2, n, ans, niv[MAXN], ordem[MAXN], distp1[MAXN], distp2[MAXN];
vector<long long> graph[MAXN], path, diam, atp;
bool pro[MAXN], mark[MAXN];
void ponta1(long long x) {
  pro[x] = true;
  for (auto u : graph[x]) {
    if (pro[u]) continue;
    niv[u] = niv[x] + 1;
    if (niv[u] > niv[p1]) p1 = u;
    ponta1(u);
  }
  p1 = p1 == 0 ? x : p1;
}
void ponta2(long long x) {
  pro[x] = true;
  for (auto u : graph[x]) {
    if (pro[u]) continue;
    niv[u] = niv[x] + 1;
    if (niv[u] > niv[p2]) p2 = u;
    ponta2(u);
  }
  p2 = (p2 == 0 ? x : p2);
}
void caminho(long long v, long long t, long long p) {
  if (path.size() > 0) return;
  atp.push_back(v);
  if (v == t) path = atp;
  for (auto u : graph[v])
    if (u != p) caminho(u, t, v);
  atp.pop_back();
}
vector<long long> diametro(long long x) {
  memset(pro, false, sizeof pro);
  p1 = p2 = 0;
  ponta1(x);
  memset(pro, false, sizeof pro);
  ponta2(p1);
  vector<long long> r;
  path.clear();
  caminho(p1, p2, -1);
  r = path;
  return r;
}
void defniv(long long x) {
  for (auto u : graph[x]) {
    if (mark[u] || (ordem[u] < ordem[x] && ordem[u] != 0)) continue;
    ordem[u] = ordem[x] + 1;
    defniv(u);
  }
}
void calcp1(long long x = p1) {
  for (auto u : graph[x]) {
    if (distp1[u] != 0) continue;
    distp1[u] = distp1[x] + 1 + (x == p1 ? 1 : 0);
    calcp1(u);
  }
}
void calcp2(long long x = p2) {
  for (auto u : graph[x]) {
    if (distp2[u] != 0) continue;
    distp2[u] = distp2[x] + 1 + (x == p2 ? 1 : 0);
    calcp2(u);
  }
}
signed main() {
  scanf("%lld", &n);
  for (long long i = 1, a, b; i < n; i++)
    scanf("%lld %lld", &a, &b), graph[a].push_back(b), graph[b].push_back(a);
  diam = diametro(1);
  distp1[p1] = distp2[p2] = -1;
  calcp1(), calcp2();
  for (long long i = 0; i < diam.size(); i++)
    mark[diam[i]] = 1, ordem[diam[i]] = 0;
  for (long long i = 0; i < diam.size(); i++) defniv(diam[i]);
  vector<pair<long long, pair<long long, long long>>> resp;
  for (long long i = 1, r1, r2; i <= n; i++) {
    if (!mark[i]) {
      r1 = distp1[i];
      r2 = distp2[i];
      if (r1 > r2)
        resp.push_back({ordem[i], {i, p1}});
      else
        resp.push_back({ordem[i], {i, p2}});
      ans += max(r1, r2);
    }
  }
  printf("%lld\n", ans + (((long long)diam.size()) * 1LL *
                          ((long long)diam.size() - 1LL) / 2LL));
  sort(resp.begin(), resp.end()), reverse(resp.begin(), resp.end());
  for (auto u : resp)
    printf("%lld %lld %lld\n", u.second.first, u.second.second, u.second.first);
  for (long long i = 0; i < diam.size() - 1; i++)
    printf("%lld %lld %lld\n", diam[i], diam[diam.size() - 1], diam[i]);
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Alice and Bob are playing a game. They have a tree consisting of n vertices. Initially, Bob has k chips, the i-th chip is located in the vertex a_i (all these vertices are unique). Before the game starts, Alice will place a chip into one of the vertices of the tree.

The game consists of turns. Each turn, the following events happen (sequentially, exactly in the following order):

  1. Alice either moves her chip to an adjacent vertex or doesn't move it;
  2. for each Bob's chip, he either moves it to an adjacent vertex or doesn't move it. Note that this choice is done independently for each chip.

The game ends when Alice's chip shares the same vertex with one (or multiple) of Bob's chips. Note that Bob's chips may share the same vertex, even though they are in different vertices at the beginning of the game.

Alice wants to maximize the number of turns, Bob wants to minimize it. If the game ends in the middle of some turn (Alice moves her chip to a vertex that contains one or multiple Bob's chips), this turn is counted.

For each vertex, calculate the number of turns the game will last if Alice places her chip in that vertex.

Input

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

Then n - 1 lines follow, each line contains two integers u_i, v_i (1 ≤ u_i, v_i ≤ n; u_i ≠ v_i) that denote the endpoints of an edge. These edges form a tree.

The next line contains one integer k (1 ≤ k ≤ n - 1) — the number of Bob's chips.

The last line contains k integers a_1, a_2, ..., a_k (1 ≤ a_i ≤ n; a_i ≠ a_j if i ≠ j) — the vertices where the Bob's chips are initially placed.

Output

Print n integers. The i-th of them should be equal to the number of turns the game will last if Alice initially places her chip in the vertex i. If one of Bob's chips is already placed in vertex i, then the answer for vertex i is 0.

Examples

Input

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

Output

2 1 2 0 0

Input

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

Output

3 0 0 3 1 2 3 0

Input

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

Output

0 2 2 2 2 0 2 2 0 0

### Response

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

#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i)
#define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i)

const int maxn=4e5+10;
void chkmin(int&x,int y){if(x>y)x=y;}
void chkmax(int&x,int y){if(x<y)x=y;}
int n,k;bool can[maxn];vector<int>E[maxn];

int sss,rt,sumsz,maxd,sz[maxn],dis[maxn],dep[maxn],ans[maxn],val[maxn];bool vis[maxn];
void dfs1(int u,int f){
  dis[u]=can[u]?0:n+1;
  for(int v:E[u])if(v!=f){
    dfs1(v,u),chkmin(dis[u],dis[v]+1);
  }
}
void dfs2(int u,int f){
  for(int v:E[u])if(v!=f)chkmin(dis[v],dis[u]+1),dfs2(v,u);
}
void dfs3(int u,int f){
  int res=0;sz[u]=1;for(int v:E[u])if(v!=f&&!vis[v])dfs3(v,u),sz[u]+=sz[v],chkmax(res,sz[v]);
  chkmax(res,sumsz-sz[u]);
  if(sss>res)sss=res,rt=u;
}
void dfs6(int u,int f){
  sz[u]=1,chkmax(maxd,dep[u]);
  for(int v:E[u])if(v!=f&&!vis[v])dep[v]=dep[u]+1,dfs6(v,u),sz[u]+=sz[v];
}
void dfs4(int u,int f){
  if(dis[u]>dep[u])chkmax(val[dis[u]-dep[u]-1],dis[u]);
  for(int v:E[u])if(v!=f&&!vis[v])dfs4(v,u);
}
void dfs5(int u,int f){
  chkmax(ans[u],val[dep[u]]);
  for(int v:E[u])if(v!=f&&!vis[v])dfs5(v,u);
}
void divide(int u){
  sss=1e9,dfs3(u,0),u=rt,maxd=dep[u]=0,dfs6(u,0),maxd=maxd*4+5;
  memset(val,0,(maxd+1)<<2),dfs4(u,0);
  per(i,maxd,1)val[i-1]=max(val[i-1],val[i]);dfs5(u,0);
  vis[u]=1;
  for(int v:E[u])if(!vis[v])sumsz=sz[v],divide(v);
}

int main(){
  cin>>n;rep(i,2,n){
    int u,v;scanf("%d%d",&u,&v),E[u].push_back(v),E[v].push_back(u);
  }cin>>k;rep(i,1,k){
    int x;scanf("%d",&x),can[x]=1;
  }dfs1(1,0),dfs2(1,0);
  sumsz=n,divide(1);
  rep(i,1,n)printf("%d ",ans[i]);
  return 0;
}

```


### Prompt

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

You are given the current time in 24-hour format hh:mm. Find and print the time after a minutes.

Note that you should find only the time after a minutes, see the examples to clarify the problem statement.

You can read more about 24-hour format here <https://en.wikipedia.org/wiki/24-hour_clock>.

Input

The first line contains the current time in the format hh:mm (0 ≤ hh < 24, 0 ≤ mm < 60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes).

The second line contains integer a (0 ≤ a ≤ 104) — the number of the minutes passed.

Output

The only line should contain the time after a minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed).

See the examples to check the input/output format.

Examples

Input

23:59
10

Output

00:09

Input

20:20
121

Output

22:21

Input

10:10
0

Output

10:10

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x7fffffffffffffff;
const int inf = 0x7fffffff;
const int N = 1e6 + 5;
clock_t start, finish;
void time_in() { start = clock(); }
void time_out() {
  finish = clock();
  double tim = (double)(finish - start) / CLOCKS_PER_SEC;
  printf("Running time is %lf\n", tim);
}
inline long long mul(long long a, long long b) {
  long long s = 0;
  while (b) {
    if (b & 1) s = (s + a) % 20010905;
    a = (a << 1) % 20010905;
    b >>= 1;
  }
  return s % 20010905;
}
inline long long pow_mul(long long a, long long b) {
  long long s = 1;
  while (b) {
    if (b & 1) s = mul(s, a);
    a = mul(a, a);
    b >>= 1;
  }
  return s;
}
inline long long poww(long long a, long long b) {
  long long s = 1;
  while (b) {
    if (b & 1) s = (s * a) % 20010905;
    a = (a * a) % 20010905;
    b >>= 1;
  }
  return s % 20010905;
}
inline bool read(int &ret) {
  char c = getchar();
  int sgn;
  if (c == EOF) return 0;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = ((c == '-') ? -1 : 1);
  ret = ((c == '-') ? 0 : (c - '0'));
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}
inline void write(int x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline long long phi(long long x) {
  long long ans = x;
  for (long long i = 2; i * i <= x; i++)
    if (x % i == 0) {
      ans -= ans / i;
      while (x % i == 0) x /= i;
    }
  if (x > 1) ans -= ans / x;
  return ans;
}
inline long long inv(long long down) {
  return down == 1
             ? 1
             : ((20010905 - 20010905 / down) * inv(20010905 % down)) % 20010905;
}
int t, cas;
int n, m;
int main() {
  while (~scanf("%d:%d", &n, &m)) {
    int x;
    scanf("%d", &x);
    x += (n * 60 + m);
    x %= (24 * 60);
    n = x / 60;
    m = x % 60;
    printf("%02d:%02d\n", n, m);
  }
}

```


### Prompt

Generate a cpp solution to the following problem:

You have a simple and connected undirected graph consisting of n nodes and m edges.

Consider any way to pair some subset of these n nodes such that no node is present in more than one pair.

This pairing is valid if for every pair of pairs, the induced subgraph containing all 4 nodes, two from each pair, has at most 2 edges (out of the 6 possible edges). More formally, for any two pairs, (a,b) and (c,d), the induced subgraph with nodes \\{a,b,c,d\} should have at most 2 edges.

Please note that the subgraph induced by a set of nodes contains nodes only from this set and edges which have both of its end points in this set.

Now, do one of the following:

  * Find a simple path consisting of at least ⌈ n/2 ⌉ nodes. Here, a path is called simple if it does not visit any node multiple times.
  * Find a valid pairing in which at least ⌈ n/2 ⌉ nodes are paired.

It can be shown that it is possible to find at least one of the two in every graph satisfying constraints from the statement.

Input

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

The first line of each test case contains 2 integers n, m (2 ≤ n ≤ 5⋅ 10^5, 1 ≤ m ≤ 10^6), denoting the number of nodes and edges, respectively.

The next m lines each contain 2 integers u and v (1 ≤ u, v ≤ n, u ≠ v), denoting that there is an undirected edge between nodes u and v in the given graph.

It is guaranteed that the given graph is connected, and simple — it does not contain multiple edges between the same pair of nodes, nor does it have any self-loops.

It is guaranteed that the sum of n over all test cases does not exceed 5⋅ 10^5.

It is guaranteed that the sum of m over all test cases does not exceed 10^6.

Output

For each test case, the output format is as follows.

If you have found a pairing, in the first line output "PAIRING" (without quotes).

  * Then, output k (⌈ n/2 ⌉ ≤ 2⋅ k ≤ n), the number of pairs in your pairing.
  * Then, in each of the next k lines, output 2 integers a and b — denoting that a and b are paired with each other. Note that the graph does not have to have an edge between a and b!
  * This pairing has to be valid, and every node has to be a part of at most 1 pair.

Otherwise, in the first line output "PATH" (without quotes).

  * Then, output k (⌈ n/2 ⌉ ≤ k ≤ n), the number of nodes in your path.
  * Then, in the second line, output k integers, v_1, v_2, …, v_k, in the order in which they appear on the path. Formally, v_i and v_{i+1} should have an edge between them for every i (1 ≤ i < k).
  * This path has to be simple, meaning no node should appear more than once.

Example

Input

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

Output

PATH
4
1 5 3 6
PAIRING
2
1 6
2 4
PAIRING
3
1 8
2 5
4 10
PAIRING
4
1 7
2 9
3 11
4 5

Note

The path outputted in the first case is the following.

<image>

The pairing outputted in the second case is the following.

<image>

Here is an invalid pairing for the same graph — the subgraph \{1,3,4,5\} has 3 edges.

<image>

Here is the pairing outputted in the third case.

<image>

It's valid because —

  * The subgraph \{1,8,2,5\} has edges (1,2) and (1,5).
  * The subgraph \{1,8,4,10\} has edges (1,4) and (4,10).
  * The subgraph \{4,10,2,5\} has edges (2,4) and (4,10).

Here is the pairing outputted in the fourth case.

<image>

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("fast-math")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC diagnostic ignored "-Woverflow"
using namespace std;
const short INF16 = ~(1 << 15);
const int INF32 = 2e9 + 11;
const int SZ = 4e5 + 11;
const int SZ2 = int(1e6 + 11);
const int mod = 1e9 + 7;
const int mod2 = 998244353;
const int PIVO = 1e6 + 11;
const long long INF64 = 8e18;
const long long P1 = 53;
const long long P2 = 47;
const long double eps = 1e-10;
const long double PI = acosl(-1);
inline long long MOD(long long x) {
  x %= mod, x += mod;
  return x % mod;
}
inline long long MOD(long long x, long long m) {
  x %= m, x += m;
  return x % m;
}
inline long long T(int x) { return 1ll * x * (x + 1) >> 1; }
inline long long TT(int x) { return 1ll * x * (x + 1) * (x + 2) / 6; }
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long fpow(long long a, long long b, long long mod) {
  if (!b) return 1;
  if (b == 1) return a % mod;
  if (b & 1) return fpow(a, b ^ 1, mod) * a % mod;
  long long d = fpow(a, b >> 1, mod);
  return d * d % mod;
}
long long fpow(long long a, long long b) {
  if (!b) return 1;
  if (b == 1) return a;
  if (b & 1) return fpow(a, b ^ 1) * a;
  long long d = fpow(a, b >> 1);
  return d * d;
}
vector<vector<int>> g;
vector<int> h, p;
int n;
void dfs(int v, int& finish, int pp = 0, int hh = 1) {
  h[v] = hh;
  p[v] = pp;
  if (h[v] >= (n + 1) / 2) finish = v;
  for (int u : g[v])
    if (!h[u]) dfs(u, finish, v, hh + 1);
}
void Solve(int num_test) {
  int m;
  cin >> n >> m;
  g.clear();
  h.clear();
  p.clear();
  g.resize(n + 1);
  h.resize(n + 1);
  p.resize(n + 1);
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  int finish = -1;
  dfs(1, finish);
  if (finish == -1) {
    vector<vector<int>> cnt((n + 1) / 2 + 1);
    vector<pair<int, int>> ans;
    for (int v = 1; v <= n; v++) cnt[h[v]].push_back(v);
    for (int hh = 1; hh <= (n + 1) / 2; hh++) {
      while (cnt[hh].size() >= 2) {
        pair<int, int> kek = {cnt[hh][cnt[hh].size() - 1],
                              cnt[hh][cnt[hh].size() - 2]};
        cnt[hh].erase(cnt[hh].begin() + cnt[hh].size() - 1);
        cnt[hh].erase(cnt[hh].begin() + cnt[hh].size() - 1);
        ans.push_back(kek);
      }
    }
    cout << "PAIRING\n" << ans.size() << '\n';
    for (auto x : ans) cout << x.first << ' ' << x.second << '\n';
  } else {
    cout << "PATH\n";
    int pp = finish;
    vector<int> ans = {};
    while (pp) {
      ans.push_back(pp);
      pp = p[pp];
    }
    cout << ans.size() << '\n';
    for (int x : ans) cout << x << ' ';
    cout << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(10);
  srand(time(NULL));
  int test = 1;
  cin >> test;
  for (int i = 1; i <= test; i++) Solve(i);
}

```


### Prompt

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

Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For the given integer values A, B, n and x find the value of g(n)(x) modulo 109 + 7.

Input

The only line contains four integers A, B, n and x (1 ≤ A, B, x ≤ 109, 1 ≤ n ≤ 1018) — the parameters from the problem statement.

Note that the given value n can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

Output

Print the only integer s — the value g(n)(x) modulo 109 + 7.

Examples

Input

3 4 1 1

Output

7

Input

3 4 2 1

Output

25

Input

3 4 3 1

Output

79

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long a, b, n, x;
const int mod = 1e9 + 7;
long long ans;
long long aced(long long i, long long k) {
  if (k == 0) return 1;
  long long tmp = aced(i, k / 2);
  if (k % 2 == 1)
    return 1LL * tmp * tmp % mod * i % mod;
  else
    return 1LL * tmp * tmp % mod;
}
int main() {
  cin >> a >> b >> n >> x;
  if (a == 1) {
    cout << 1LL * (x + 1LL * b * (n % mod)) % mod;
    return 0;
  }
  ans = 1LL * (ans + 1LL * aced(a, n) * x % mod) % mod;
  long long tmp =
      1LL * (aced(a, n) % mod - 1) % mod * aced(a - 1, mod - 2) % mod * b % mod;
  ans = 1LL * (ans + tmp) % mod;
  cout << ans << endl;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n × n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:

The cleaning of all evil will awaken the door!

Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.

The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile — then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.

You would like to purify all n × n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.

Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.

Input

The first line will contain a single integer n (1 ≤ n ≤ 100). Then, n lines follows, each contains n characters. The j-th character in the i-th row represents the cell located at row i and column j. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.

Output

If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts x "Purification" spells (where x is the minimum possible number of spells), output x lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.

Examples

Input

3
.E.
E.E
.E.

Output

1 1
2 2
3 3

Input

3
EEE
E..
E.E

Output

-1

Input

5
EE.EE
E.EE.
E...E
.EE.E
EE.EE

Output

3 3
1 3
2 2
4 4
5 3

Note

The first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.

<image>

In the second example, it is impossible to purify the cell located at row 1 and column 1.

For the third example:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
int have[2][maxn];
int n;
bool work(int k) {
  for (int i = 1; i <= n; i++)
    if (!have[k][i]) return 0;
  for (int i = 1; i <= n; i++)
    if (k == 0)
      printf("%d %d\n", i, have[k][i]);
    else
      printf("%d %d\n", have[k][i], i);
  return 1;
}
int main() {
  cin >> n;
  char c;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      do c = getchar();
      while (c != '.' && c != 'E');
      if (c == '.') {
        have[0][i] = j;
        have[1][j] = i;
      }
    }
  if (work(0)) return 0;
  if (!work(1)) printf("-1\n");
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You are given n strings a_1, a_2, …, a_n: all of them have the same length m. The strings consist of lowercase English letters.

Find any string s of length m such that each of the given n strings differs from s in at most one position. Formally, for each given string a_i, there is no more than one position j such that a_i[j] ≠ s[j].

Note that the desired string s may be equal to one of the given strings a_i, or it may differ from all the given strings.

For example, if you have the strings abac and zbab, then the answer to the problem might be the string abab, which differs from the first only by the last character, and from the second only by the first.

Input

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

Each test case starts with a line containing two positive integers n (1 ≤ n ≤ 10) and m (1 ≤ m ≤ 10) — the number of strings and their length.

Then follow n strings a_i, one per line. Each of them has length m and consists of lowercase English letters.

Output

Print t answers to the test cases. Each answer (if it exists) is a string of length m consisting of lowercase English letters. If there are several answers, print any of them. If the answer does not exist, print "-1" ("minus one", without quotes).

Example

Input

5
2 4
abac
zbab
2 4
aaaa
bbbb
3 3
baa
aaa
aab
2 2
ab
bb
3 1
a
b
c

Output

abab
-1
aaa
ab
z

Note

The first test case was explained in the statement.

In the second test case, the answer does not exist.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<string> vec(n);
    for (int i = 0; i < n; i++) cin >> vec[i];
    string ans = vec[0];
    bool flag;
    for (int i = 0; i < m; i++) {
      int sa = ans[i];
      for (char j = 'a'; j <= 'z'; j++) {
        ans[i] = j;
        flag = true;
        for (int z = 0; z < n; z++) {
          int cntErrors = 0;
          for (int c = 0; c < m; c++) {
            if (vec[z][c] != ans[c]) cntErrors++;
          }
          if (cntErrors > 1) {
            flag = false;
            break;
          }
        }
        if (flag) {
          cout << ans << endl;
          break;
        }
      }
      if (flag) break;
      ans[i] = sa;
    }
    if (flag) continue;
    cout << "-1";
    cout << endl;
  }
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

You are given an array a_1, a_2, …, a_n of integers. This array is non-increasing.

Let's consider a line with n shops. The shops are numbered with integers from 1 to n from left to right. The cost of a meal in the i-th shop is equal to a_i.

You should process q queries of two types:

  * 1 x y: for each shop 1 ≤ i ≤ x set a_{i} = max(a_{i}, y).
  * 2 x y: let's consider a hungry man with y money. He visits the shops from x-th shop to n-th and if he can buy a meal in the current shop he buys one item of it. Find how many meals he will purchase. The man can buy a meal in the shop i if he has at least a_i money, and after it his money decreases by a_i.

Input

The first line contains two integers n, q (1 ≤ n, q ≤ 2 ⋅ 10^5).

The second line contains n integers a_{1},a_{2}, …, a_{n} (1 ≤ a_{i} ≤ 10^9) — the costs of the meals. It is guaranteed, that a_1 ≥ a_2 ≥ … ≥ a_n.

Each of the next q lines contains three integers t, x, y (1 ≤ t ≤ 2, 1≤ x ≤ n, 1 ≤ y ≤ 10^9), each describing the next query.

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

Output

For each query of type 2 output the answer on the new line.

Example

Input

10 6
10 10 10 6 6 5 5 5 3 1
2 3 50
2 4 10
1 3 10
2 2 36
1 4 7
2 2 17

Output

8
3
6
2

Note

In the first query a hungry man will buy meals in all shops from 3 to 10.

In the second query a hungry man will buy meals in shops 4, 9, and 10.

After the third query the array a_1, a_2, …, a_n of costs won't change and will be \{10, 10, 10, 6, 6, 5, 5, 5, 3, 1\}.

In the fourth query a hungry man will buy meals in shops 2, 3, 4, 5, 9, and 10.

After the fifth query the array a of costs will be \{10, 10, 10, 7, 6, 5, 5, 5, 3, 1\}.

In the sixth query a hungry man will buy meals in shops 2 and 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 5;
long long stmn[4 * maxn], stsum[4 * maxn], lazy[4 * maxn];
long long N, a[maxn], Q;
void push(long long id, long long l, long long r) {
  if (lazy[id] == 0) return;
  stmn[id] = lazy[id];
  stsum[id] = (r - l + 1) * lazy[id];
  if (l != r) {
    lazy[id << 1] = lazy[id];
    lazy[id << 1 | 1] = lazy[id];
  }
  lazy[id] = 0;
}
void pull(long long id) {
  stsum[id] = stsum[id << 1] + stsum[id << 1 | 1];
  stmn[id] = min(stmn[id << 1], stmn[id << 1 | 1]);
}
void build(long long id, long long l, long long r) {
  if (l == r) {
    stmn[id] = stsum[id] = a[l];
    return;
  }
  long long mid = (l + r) / 2;
  build(id << 1, l, mid);
  build(id << 1 | 1, mid + 1, r);
  pull(id);
}
void modify(long long L, long long R, long long v, long long id = 1,
            long long l = 1, long long r = N) {
  push(id, l, r);
  if (R < l || r < L) return;
  if (L <= l && r <= R) {
    lazy[id] = v;
    push(id, l, r);
    return;
  }
  long long mid = (l + r) / 2;
  modify(L, R, v, id << 1, l, mid);
  modify(L, R, v, id << 1 | 1, mid + 1, r);
  pull(id);
}
long long findfirst(long long val, long long id = 1, long long l = 1,
                    long long r = N) {
  push(id, l, r);
  if (stmn[id] > val) return N + 1;
  if (l == r) {
    if (stmn[id] <= val) return l;
    return N + 1;
  }
  long long mid = (l + r) / 2;
  push(id << 1, l, mid);
  push(id << 1 | 1, mid + 1, r);
  if (stmn[id << 1] <= val) return findfirst(val, id << 1, l, mid);
  return findfirst(val, id << 1 | 1, mid + 1, r);
}
long long getval(long long L, long long R, long long id = 1, long long l = 1,
                 long long r = N) {
  push(id, l, r);
  if (R < l || r < L) return 0;
  if (L <= l && r <= R) {
    return stsum[id];
  }
  long long mid = (l + r) / 2;
  return getval(L, R, id << 1, l, mid) + getval(L, R, id << 1 | 1, mid + 1, r);
}
long long findfirstsum(long long val, long long id = 1, long long l = 1,
                       long long r = N) {
  push(id, l, r);
  if (l == r) {
    if (stsum[id] > val) return l;
    return N + 1;
  }
  long long mid = (l + r) / 2;
  push(id << 1, l, mid);
  push(id << 1 | 1, mid + 1, r);
  if (stsum[id << 1] <= val)
    return findfirstsum(val - stsum[id << 1], id << 1 | 1, mid + 1, r);
  return findfirstsum(val, id << 1, l, mid);
}
signed main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> Q;
  for (long long i = 1; i <= N; ++i) {
    cin >> a[i];
  }
  build(1, 1, N);
  for (long long i = 1; i <= Q; ++i) {
    long long type;
    cin >> type;
    long long x, y;
    cin >> x >> y;
    if (type == 1) {
      long long pos = findfirst(y);
      if (pos <= x) modify(pos, x, y);
    } else {
      long long ret = 0;
      while (x <= N && y > 0) {
        x = max(x, findfirst(y));
        long long psum = getval(1, x - 1);
        long long nxtpos = findfirstsum(psum + y);
        if (i == Q) cerr << x << ' ' << y << ' ' << nxtpos << '\n';
        if (nxtpos == x) {
          break;
        } else {
          y -= getval(x, nxtpos - 1);
          ret += nxtpos - x;
          x = nxtpos;
        }
      }
      cout << ret << '\n';
    }
  }
}

```


### Prompt

Please create a solution in CPP to the following problem:

To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings.

More formally, for each invited person the following conditions should be fulfilled:

  * all his friends should also be invited to the party;
  * the party shouldn't have any people he dislikes;
  * all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≤ i < p) are friends.

Help the Beaver find the maximum number of acquaintances he can invite.

Input

The first line of input contains an integer n — the number of the Beaver's acquaintances.

The second line contains an integer k <image> — the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi <image> — indices of people who form the i-th pair of friends.

The next line contains an integer m <image> — the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described.

Each pair of people is mentioned in the input at most once <image>. In particular, two persons cannot be friends and dislike each other at the same time.

The input limitations for getting 30 points are:

  * 2 ≤ n ≤ 14

The input limitations for getting 100 points are:

  * 2 ≤ n ≤ 2000

Output

Output a single number — the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0.

Examples

Input

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

Output

3

Note

Let's have a look at the example.

<image>

Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[3000];
bool ma[3000][3000] = {};
bool vis[3000] = {};
set<long long> like, dislike;
bool val;
void pri(set<long long> s) {
  set<long long>::iterator it;
  for (it = s.begin(); it != s.end(); it++) cout << *it << " ";
  cout << endl;
}
void init(long long n) {
  like.clear();
  like.insert(n);
  dislike.clear();
  val = true;
}
void dfs(long long n) {
  vis[n] = true;
  for (long long i = 0; i < adj[n].size(); i++) {
    long long u = adj[n][i];
    if (!ma[n][u]) {
      if (like.find(u) != like.end()) val = false;
      dislike.insert(u);
    } else {
      if (dislike.find(u) != dislike.end()) val = false;
      like.insert(u);
      if (!vis[u]) dfs(u);
    }
  }
}
int main() {
  long long n;
  cin >> n;
  long long k;
  cin >> k;
  pair<long long, long long> a[k];
  for (long long i = 0; i < k; i++) {
    long long c, d;
    cin >> c >> d;
    a[i].first = c;
    a[i].second = d;
    adj[c].push_back(d);
    adj[d].push_back(c);
    ma[c][d] = ma[d][c] = true;
  }
  long long m;
  cin >> m;
  pair<long long, long long> b[m];
  for (long long i = 0; i < m; i++) {
    long long c, d;
    cin >> c >> d;
    b[i].first = c;
    b[i].second = d;
    adj[c].push_back(d);
    adj[d].push_back(c);
  }
  long long res = 0;
  for (long long i = 1; i <= n; i++) {
    init(i);
    if (!vis[i]) {
      dfs(i);
      long long tam = like.size();
      if (val) res = max(res, tam);
    }
  }
  cout << res << endl;
  return 0;
}

```


### Prompt

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

Monocarp would like to open a bakery in his local area. But, at first, he should figure out whether he can compete with other shops.

Monocarp plans that the bakery will work for n days. On the i-th day, a_i loaves of bread will be baked in the morning before the opening. At the end of the n-th day, Monocarp will sell all the remaining bread that wasn't sold earlier with a huge discount.

Because of how bread is stored, the bakery seller sells the bread in the following order: firstly, he sells the loaves that were baked that morning; secondly, he sells the loaves that were baked the day before and weren't sold yet; then the loaves that were baked two days before and weren't sold yet, and so on. That's why some customers may buy a rather stale bread and will definitely spread negative rumors.

Let's define loaf spoilage as the difference between the day it was baked and the day it was sold. Then the unattractiveness of the bakery will be equal to the maximum spoilage among all loaves of bread baked at the bakery.

Suppose Monocarp's local area has consumer demand equal to k, it means that each day k customers will come to the bakery and each of them will ask for one loaf of bread (the loaves are sold according to the aforementioned order). If there is no bread left, then the person just doesn't buy anything. During the last day sale, all the remaining loaves will be sold (and they will still count in the calculation of the unattractiveness).

Monocarp analyzed his competitors' data and came up with m possible consumer demand values k_1, k_2, ..., k_m, and now he'd like to calculate the unattractiveness of the bakery for each value of demand. Can you help him?

Input

The first line contains two integers n and m (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ m ≤ 2 ⋅ 10^5) — the number of days the bakery is open and the number of possible values of consumer demand.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the number of bread loaves that will be baked each day.

The third line contains m integers k_1, k_2, ..., k_m (1 ≤ k_1 < k_2 < ... < k_m ≤ 10^9) — the possible consumer demand values in the ascending order.

Output

Print m integers: for each consumer demand, print the unattractiveness of the bakery.

Examples

Input

5 4
5 2 1 3 7
1 3 4 10

Output

4 2 1 0

Input

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

Output

7 5 3 3 2 1 1 1 0

Note

In the first example, let's describe what happens for couple consumer demands:

If consumer demand is equal to 1:

  * at day 1: 5 loaves are baked and only 1 is sold with spoilage equal to 1 - 1 = 0;
  * at day 2: 4 loaves are left and 2 more are baked. Only 1 loaf was sold and it was the loaf baked today with spoilage 2 - 2 = 0;
  * at day 3: 4 loaves from the first day and 1 loaf from the second day left. One more loaf was baked and was sold this day with spoilage 3 - 3 = 0;
  * at day 4: 4 loaves from the first day and 1 loaf from the second day left. 3 more loaves were baked and one of them was sold this day with spoilage 4 - 4 = 0;
  * at day 5: 4 loaves from the first day, 1 loaf from the second day and 2 loaves from the fourth day left. 7 more loaves were baked and, since it's the last day, all 14 loaves were sold. 4 loaves from the first day have the maximum spoilage equal to 5 - 1 = 4.

In total, the unattractiveness of the bakery will be equal to 4.

If consumer demand is equal to 10 then all baked bread will be sold in the day it was baked and will have spoilage equal to 0.

### Response

```cpp
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<ll, ll>
#define f first
#define s second

const int mxn = 200001;
int n, q;
ll a[mxn], b[mxn], r[mxn];

int f(int x){
	return r[x] - x + 1;
}

auto cmp = [](pi x, pi y){
	ll v = x.f * f(y.s) - y.f * f(x.s);
	return v ? v > 0 : x.s < y.s;
};
set<pi, decltype(cmp)> s(cmp);

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> q;

	for(int i = 1; i <= n; i++){
		cin >> a[i];
		r[i] = i;
		if(i < n) s.insert({a[i], i});
		a[i] += a[i - 1];
	}

	for(int i = 0; i < q; i++) cin >> b[i];

	for(int i = q - 1; ~i; i--){
		int ret = b[i + 1];
		while(!s.empty() && b[i] * f(s.begin()->s) < s.begin()->f){
			int x = s.begin()->s, y = r[x] + 1;
			s.erase(s.begin());
			r[x] = r[y];
			if(r[y] != n){
				s.erase({a[r[y]] - a[y - 1], y});
				s.insert({a[r[x]] - a[x - 1], x});
			}
			ret = max(ret, f(x) - 1);
		}
		b[i] = ret;
	}

	cout << b[0];
	for(int i = 1; i < q; i++) cout << " " << b[i];
	cout << endl;

	return 0;
}
```


### Prompt

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

You are given n sequences. Each sequence consists of positive integers, not exceeding m. All integers in one sequence are distinct, but the same integer may appear in multiple sequences. The length of the i-th sequence is ki.

Each second integers in each of the sequences are shifted by one to the left, i.e. integers at positions i > 1 go to positions i - 1, while the first integers becomes the last.

Each second we take the first integer of each sequence and write it down to a new array. Then, for each value x from 1 to m we compute the longest segment of the array consisting of element x only.

The above operation is performed for 10100 seconds. For each integer from 1 to m find out the longest segment found at this time.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100 000) — the number of sequences and the maximum integer that can appear in the sequences.

Then follow n lines providing the sequences. Each of them starts with an integer ki (1 ≤ ki ≤ 40) — the number of integers in the sequence, proceeded by ki positive integers — elements of the sequence. It's guaranteed that all integers in each sequence are pairwise distinct and do not exceed m.

The total length of all sequences doesn't exceed 200 000.

Output

Print m integers, the i-th of them should be equal to the length of the longest segment of the array with all its values equal to i during the first 10100 seconds.

Examples

Input

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

Output

2
1
3
2

Input

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

Output

3
1
4
0
1

Input

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

Output

0
0
2
1
1
2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 99, K = 41;
int n, m, bad, rem[K][K], t[K];
vector<pair<int, pair<int, int> > > v[N];
vector<int> d[N];
void add(pair<int, pair<int, int> > x) {
  for (int i = 0; i < d[x.second.first].size(); i++) {
    int dv = d[x.second.first][i], re = x.second.second % dv;
    rem[dv][re]++;
    if (rem[dv][re] == 1) {
      t[dv]++;
      if (t[dv] == 2) bad++;
    }
  }
}
void del(pair<int, pair<int, int> > x) {
  for (int i = 0; i < d[x.second.first].size(); i++) {
    int dv = d[x.second.first][i], re = x.second.second % dv;
    rem[dv][re]--;
    if (rem[dv][re] == 0) {
      t[dv]--;
      if (t[dv] == 1) bad--;
    }
  }
}
int main() {
  for (int i = 2; i < K; i++)
    for (int j = i; j < K; j += i) d[j].push_back(i);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int ki;
    scanf("%d", &ki);
    ;
    for (int j = 0; j < ki; j++) {
      int x;
      scanf("%d", &x);
      ;
      v[x].push_back(make_pair(i, make_pair(ki, j)));
    }
  }
  for (int i = 1; i < m + 1; i++) {
    for (int j = 0; j < K; j++)
      for (int l = 0; l < K; l++) rem[j][l] = t[j] = bad = 0;
    int l = 0, ans = 0;
    for (int r = 0; r < int(v[i].size()); r++) {
      add(v[i][r]);
      while (l < r && (bad || v[i][r - 1].first + 1 < v[i][r].first)) {
        del(v[i][l]);
        l++;
      }
      ans = max(ans, r - l + 1);
    }
    cout << ans << " ";
  }
}

```


### Prompt

Please create a solution in cpp to the following problem:

Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd.

Input

The only line contains odd integer n (1 ≤ n ≤ 49).

Output

Print n lines with n integers. All the integers should be different and from 1 to n2. The sum in each row, column and both main diagonals should be odd.

Examples

Input

1

Output

1

Input

3

Output

2 1 4
3 5 7
6 9 8

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void generateSquare(int n) {
  int magicSquare[n][n];
  memset(magicSquare, 0, sizeof(magicSquare));
  int i = n / 2;
  int j = n - 1;
  for (int num = 1; num <= n * n;) {
    if (i == -1 && j == n) {
      j = n - 2;
      i = 0;
    } else {
      if (j == n) j = 0;
      if (i < 0) i = n - 1;
    }
    if (magicSquare[i][j]) {
      j -= 2;
      i++;
      continue;
    } else
      magicSquare[i][j] = num++;
    j++;
    i--;
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) printf("%d ", magicSquare[i][j]);
    printf("\n");
  }
}
int main() {
  int n;
  cin >> n;
  generateSquare(n);
  return 0;
}

```


### Prompt

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

The Shuseki Islands are an archipelago of 30001 small islands in the Yutampo Sea. The islands are evenly spaced along a line, numbered from 0 to 30000 from the west to the east. These islands are known to contain many treasures. There are n gems in the Shuseki Islands in total, and the i-th gem is located on island pi.

Mr. Kitayuta has just arrived at island 0. With his great jumping ability, he will repeatedly perform jumps between islands to the east according to the following process:

  * First, he will jump from island 0 to island d.
  * After that, he will continue jumping according to the following rule. Let l be the length of the previous jump, that is, if his previous jump was from island prev to island cur, let l = cur - prev. He will perform a jump of length l - 1, l or l + 1 to the east. That is, he will jump to island (cur + l - 1), (cur + l) or (cur + l + 1) (if they exist). The length of a jump must be positive, that is, he cannot perform a jump of length 0 when l = 1. If there is no valid destination, he will stop jumping.

Mr. Kitayuta will collect the gems on the islands visited during the process. Find the maximum number of gems that he can collect.

Input

The first line of the input contains two space-separated integers n and d (1 ≤ n, d ≤ 30000), denoting the number of the gems in the Shuseki Islands and the length of the Mr. Kitayuta's first jump, respectively.

The next n lines describe the location of the gems. The i-th of them (1 ≤ i ≤ n) contains a integer pi (d ≤ p1 ≤ p2 ≤ ... ≤ pn ≤ 30000), denoting the number of the island that contains the i-th gem.

Output

Print the maximum number of gems that Mr. Kitayuta can collect.

Examples

Input

4 10
10
21
27
27

Output

3

Input

8 8
9
19
28
36
45
55
66
78

Output

6

Input

13 7
8
8
9
16
17
17
18
21
23
24
24
26
30

Output

4

Note

In the first sample, the optimal route is 0  →  10 (+1 gem)  →  19  →  27 (+2 gems)  → ...

In the second sample, the optimal route is 0  →  8  →  15  →  21 →  28 (+1 gem)  →  36 (+1 gem)  →  45 (+1 gem)  →  55 (+1 gem)  →  66 (+1 gem)  →  78 (+1 gem)  → ...

In the third sample, the optimal route is 0  →  7  →  13  →  18 (+1 gem)  →  24 (+2 gems)  →  30 (+1 gem)  → ...

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000000000000000000;
long long mod = 1000000000;
long double pi = 3.141592653589793238;
void pls() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long mul_mod(long long a, long long b, long long m) {
  long long x = 0, y = a;
  while (b > 0) {
    if (b & 1) {
      x = (x + y) % m;
    }
    y = (y + y) % m;
    b >>= 1;
  }
  return x;
}
inline long long modu(long long val, long long modul) {
  return (val % modul + modul) % modul;
}
inline int madd(int x, int y) { return (x % mod + y % mod) % mod; }
inline int msub(int x, int y) { return (mod + x % mod - y % mod) % mod; }
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long powmod(long long a, long long mod, long long p) {
  if (p == 0) return 1;
  long long res;
  long long x = powmod(a, mod, p / 2);
  res = x;
  if (p & 1) x = mul_mod(x, a, mod);
  return mul_mod(x, res, mod);
}
long long exp(long long a, long long p) {
  if (p == 0) return 1;
  long long res;
  long long x = exp(a, p / 2);
  res = x;
  if (p & 1) x = (x * a);
  return (x * res);
}
long long sqt(long long x) {
  long long l = 1LL;
  long long r = x;
  long long res;
  while (l <= r) {
    long long mid = l + (r - l) / 2;
    if (mid * mid <= x) {
      res = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return res;
}
bool isprime(long long n) {
  for (int i = 2; i <= sqt(n); i++)
    if (n % i == 0) return 0;
  return 1;
}
vector<int> soe(long long upto) {
  vector<bool> prime(upto + 1, 0);
  prime[1] = 1;
  prime[0] = 1;
  for (int i = 2; i <= sqt(upto); i++) {
    if (!prime[i]) {
      for (int j = 2 * i; j <= upto; j += i) prime[j] = 1;
    }
  }
  vector<int> res;
  res.push_back(2);
  for (int i = 3; i < prime.size(); i += 2) {
    if (!prime[i]) res.push_back(i);
  }
  return res;
}
int di[8] = {-1, -1, -1, 1, 1, 1, 0, 0};
int dj[8] = {-1, 0, 1, -1, 0, 1, -1, 1};
int ii[4] = {0, 0, -1, 1};
int jj[4] = {-1, 1, 0, 0};
long long n, d;
long long a[30001];
long long ex;
long long dp[500][30001];
long long top_down(int ix, int pre) {
  if (ix > 30000) return 0;
  if (dp[pre][ix] != -1) return dp[pre][ix];
  long long previous = d + (pre - 250);
  long long p = 0, q = 0, r = 0;
  if (previous > 0) p = top_down(ix + previous, pre);
  if (previous > 1) q = top_down(ix + previous - 1, pre - 1);
  r = top_down(ix + previous + 1, pre + 1);
  return dp[pre][ix] = a[ix] + max({p, q, r});
}
void solve() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    a[x] += 1;
  }
  memset(dp, -1, sizeof(dp));
  cout << top_down(d, 250) << endl;
}
int main() {
  pls();
  solve();
  return 0;
}

```


### Prompt

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

You are given two integers n and d. You need to construct a rooted binary tree consisting of n vertices with a root at the vertex 1 and the sum of depths of all vertices equals to d.

A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. A parent of a vertex v is the last different from v vertex on the path from the root to the vertex v. The depth of the vertex v is the length of the path from the root to the vertex v. Children of vertex v are all vertices for which v is the parent. The binary tree is such a tree that no vertex has more than 2 children.

You have to answer t independent test cases.

Input

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

The only line of each test case contains two integers n and d (2 ≤ n, d ≤ 5000) — the number of vertices in the tree and the required sum of depths of all vertices.

It is guaranteed that the sum of n and the sum of d both does not exceed 5000 (∑ n ≤ 5000, ∑ d ≤ 5000).

Output

For each test case, print the answer.

If it is impossible to construct such a tree, print "NO" (without quotes) in the first line. Otherwise, print "{YES}" in the first line. Then print n-1 integers p_2, p_3, ..., p_n in the second line, where p_i is the parent of the vertex i. Note that the sequence of parents you print should describe some binary tree.

Example

Input

3
5 7
10 19
10 18

Output

YES
1 2 1 3
YES
1 2 3 3 9 9 2 1 6
NO

Note

Pictures corresponding to the first and the second test cases of the example:

<image>

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
const int INF = 0x3f3f3f3f;
int t, n, d, lf[N], rt[N], nok[N], p[N], h[N];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> d;
    int lb = 0, aux = 0;
    for (int i = 1; i <= n; i++) {
      lf[i] = rt[i] = nok[i] = p[i] = h[i] = 0;
      lb += aux;
      if (!(i & (i + 1))) aux++;
    }
    for (int i = 1; i + 1 <= n; i++) p[i + 1] = i, h[i + 1] = i, lf[i] = i + 1;
    int ans = (n * (n - 1)) / 2;
    if (ans < d or d < lb)
      cout << "NO\n";
    else {
      int cond = 1;
      while (ans != d) {
        int mn = INF, node = -1;
        for (int i = 1; i <= n; i++)
          if (!lf[i] and !rt[i] and !nok[i] and h[i] < mn) mn = h[i], node = i;
        if (node == -1) {
          cond = 0;
          break;
        }
        int nxt = -1;
        for (int i = 1; i <= n; i++)
          if (h[i] == mn - 2 and (!lf[i] or !rt[i])) {
            nxt = i;
            break;
          }
        if (nxt != -1) {
          if (lf[p[node]] == node)
            lf[p[node]] = 0;
          else
            rt[p[node]] = 0;
          p[node] = nxt;
          if (!lf[nxt])
            lf[nxt] = node;
          else
            rt[nxt] = node;
          h[node] = h[nxt] + 1;
          ans--;
        } else
          nok[node] = 1;
      }
      if (!cond)
        cout << "NO\n";
      else {
        cout << "YES\n";
        for (int i = 2; i <= n; i++) cout << p[i] << " ";
        cout << "\n";
      }
    }
  }
}

```


### Prompt

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

«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.

However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every k-th dragon got punched in the face with a frying pan. Every l-th dragon got his tail shut into the balcony door. Every m-th dragon got his paws trampled with sharp heels. Finally, she threatened every n-th dragon to call her mom, and he withdrew in panic.

How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of d dragons?

Input

Input data contains integer numbers k, l, m, n and d, each number in a separate line (1 ≤ k, l, m, n ≤ 10, 1 ≤ d ≤ 105).

Output

Output the number of damaged dragons.

Examples

Input

1
2
3
4
12

Output

12

Input

2
3
4
5
24

Output

17

Note

In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.

In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, l, m, n, d, cnt, i;
  scanf("%d%d%d%d%d", &k, &l, &m, &n, &d);
  cnt = d;
  if (k == 1 || l == 1 || m == 1 || n == 1)
    printf("%d\n", cnt);
  else {
    for (i = 1; i <= d; i++) {
      if ((i % k != 0) && (i % l != 0) && (i % m != 0) && (i % n != 0)) {
        cnt--;
      }
    }
    printf("%d\n", cnt);
  }
  return 0;
}

```


### Prompt

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

You have integer n. Calculate how many ways are there to fully cover belt-like area of 4n-2 triangles with diamond shapes.

Diamond shape consists of two triangles. You can move, rotate or flip the shape, but you cannot scale it.

2 coverings are different if some 2 triangles are covered by the same diamond shape in one of them and by different diamond shapes in the other one.

Please look at pictures below for better understanding.

<image> On the left you can see the diamond shape you will use, and on the right you can see the area you want to fill.

<image> These are the figures of the area you want to fill for n = 1, 2, 3, 4.

You have to answer t independent test cases.

Input

The first line contains a single integer t (1 ≤ t ≤ 10^{4}) — the number of test cases.

Each of the next t lines contains a single integer n (1 ≤ n ≤ 10^{9}).

Output

For each test case, print the number of ways to fully cover belt-like area of 4n-2 triangles using diamond shape. It can be shown that under given constraints this number of ways doesn't exceed 10^{18}.

Example

Input

2
2
1

Output

2
1

Note

In the first test case, there are the following 2 ways to fill the area:

<image>

In the second test case, there is a unique way to fill the area:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long power(long long a, long long b) {
  if (b == 0) return 1;
  long long ans = 1;
  while (b > 0) {
    if (b & 1) (ans = ans * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return ans;
}
long long max(long long x, long long y) { return x > y ? x : y; }
long long min(long long x, long long y) { return x < y ? x : y; }
void solve() {
  long long n;
  cin >> n;
  cout << n;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
}

```


### Prompt

Generate a Cpp solution to the following problem:

Create a program that inputs the vertex information of two polygons inscribed in one circle and outputs the magnitude relationship of their areas.

Assume that each vertex of the X-side is numbered counterclockwise from 1 to X (the figure shows an example when X = 4). However, the given polygon assumes that the center of the circle is contained inside, and the data on the position of vertex i is the angle v (1 ≤ v <180) of the central angle measured counterclockwise from vertex i to vertex i + 1. Integer). Regarding the magnitude relationship to be output, 1 (half-width number) when the area of the first polygon is large, 2 (half-width number) when the area of the second polygon is large, and when the areas are the same, Please output 0 (half-width number).

<image>

Input

A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:

m
v1
v2
::
vm −1
n
v1
v2
::
vn − 1

The first line gives the number of vertices of the first polygon m (3 ≤ m ≤ 50), and the following m − 1 line gives the information vi (1 ≤ vi <180) of the vertices i of the first polygon. ..

The following line gives the number of vertices n (3 ≤ n ≤ 50) of the second polygon, and the following n − 1 line gives the information vi (1 ≤ vi <180) for the vertices i of the second polygon.

The number of datasets does not exceed 200.

Output

Outputs the magnitude relationship (half-width numbers) for each data set on one line.

Example

Input

4
30
125
75
4
30
125
75
5
30
125
75
65
4
30
125
75
4
30
125
75
6
30
50
50
25
75
0

Output

0
1
2

### Response

```cpp
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
#define PI 3.141592653589793238462643L
int K[100000];
long double SIN(long double b) { return sinl(b * PI / 180.0L); }
int main() {
	int N, cnt = 0; long double a, sum, s[2], V;
	while (true) {
		for (int i = 0; i < 2; i++) {
			cin >> N; V = 0.0L; sum = 0.0L; if (N == 0) { goto E; }
			for (int i = 0; i < N - 1; i++) { cin >> a; sum += SIN(a); V += a; }
			sum += SIN(360.0L - V); s[i] = sum;
		}
		if (fabs(s[0] - s[1]) < 1e-9) { cout << '0' << endl; }
		else if (s[0] > s[1]) { cout << '1' << endl; }
		else if (s[0] < s[1]) { cout << '2' << endl; }
	}
E:;
	return 0;
}
```


### Prompt

Please create a solution in Cpp to the following problem:

The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map of the solar system that contains the Death Star. However, this time the Empire has hidden the Death Star very well, and Heidi needs to find a place that appears on both maps in order to detect the Death Star.

The first map is an N × M grid, each cell of which shows some type of cosmic object that is present in the corresponding quadrant of space. The second map is an M × N grid. Heidi needs to align those two maps in such a way that they overlap over some M × M section in which all cosmic objects are identical. Help Heidi by identifying where such an M × M section lies within both maps.

Input

The first line of the input contains two space-separated integers N and M (1 ≤ N ≤ 2000, 1 ≤ M ≤ 200, M ≤ N). The next N lines each contain M lower-case Latin characters (a-z), denoting the first map. Different characters correspond to different cosmic object types. The next M lines each contain N characters, describing the second map in the same format.

Output

The only line of the output should contain two space-separated integers i and j, denoting that the section of size M × M in the first map that starts at the i-th row is equal to the section of the second map that starts at the j-th column. Rows and columns are numbered starting from 1.

If there are several possible ways to align the maps, Heidi will be satisfied with any of those. It is guaranteed that a solution exists.

Example

Input

10 5
somer
andom
noise
mayth
eforc
ebewi
thyou
hctwo
again
noise
somermayth
andomeforc
noiseebewi
againthyou
noisehctwo

Output

4 6

Note

The 5-by-5 grid for the first test case looks like this:

    mayth
    eforc
    ebewi
    thyou
    hctwo

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1061109567;
const ll INF = 4557430888798830399;
const int MOD = 1e9 + 7;
const int p = 131;
const int q = 113;
int n, m;
char a[2005][205];
char b[205][2005];
int hashp[205];
int hashq[2005];
int s[2005][2005];
int t[2005][2005];
int get(int u, int v, int x, int y, int c[2005][2005]) {
  int res = (c[x][y] + (ll)c[u - 1][v - 1] * hashp[x - u + 1] % MOD *
                           hashq[y - v + 1] % MOD) %
            MOD;
  res = (res - (ll)c[x][v - 1] * hashq[y - v + 1] % MOD + MOD) % MOD;
  res = (res - (ll)c[u - 1][y] * hashp[x - u + 1] % MOD + MOD) % MOD;
  return res;
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  if (fopen(""
            ".in",
            "r")) {
    freopen(
        ""
        ".in",
        "r", stdin);
    freopen(
        ""
        ".out",
        "w", stdout);
  }
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cin >> a[i][j];
  for (int i = 1; i <= m; ++i)
    for (int j = 1; j <= n; ++j) cin >> b[i][j];
  hashq[0] = hashp[0] = 1;
  for (int i = 1; i <= m; ++i) hashp[i] = (ll)hashp[i - 1] * p % MOD;
  for (int i = 1; i <= n; ++i) hashq[i] = (ll)hashq[i - 1] * q % MOD;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      s[i][j] = a[i][j];
      (s[i][j] += (ll)s[i - 1][j] * p % MOD) %= MOD;
      (s[i][j] += (ll)s[i][j - 1] * q % MOD) %= MOD;
      s[i][j] = (s[i][j] - (ll)s[i - 1][j - 1] * p % MOD * q % MOD + MOD) % MOD;
    }
  for (int i = 1; i <= m; ++i)
    for (int j = 1; j <= n; ++j) {
      t[i][j] = b[i][j];
      (t[i][j] += (ll)t[i - 1][j] * p % MOD) %= MOD;
      (t[i][j] += (ll)t[i][j - 1] * q % MOD) %= MOD;
      t[i][j] = (t[i][j] - (ll)t[i - 1][j - 1] * p % MOD * q % MOD + MOD) % MOD;
    }
  for (int i = 1; i <= n - m + 1; ++i) {
    int cur = get(1, i, m, i + m - 1, t);
    for (int j = 1; j <= n - m + 1; ++j) {
      int tmp = get(j, 1, j + m - 1, m, s);
      if (cur == tmp) {
        cout << j << " " << i << "\n";
        return 0;
      }
    }
  }
  return 0;
}

```


### Prompt

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

There is a square grid of size n × n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs max(h, w) to color a rectangle of size h × w. You are to make all cells white for minimum total cost.

Input

The first line contains a single integer n (1 ≤ n ≤ 50) — the size of the square grid.

Each of the next n lines contains a string of length n, consisting of characters '.' and '#'. The j-th character of the i-th line is '#' if the cell with coordinates (i, j) is black, otherwise it is white.

Output

Print a single integer — the minimum total cost to paint all cells in white.

Examples

Input

3
###
#.#
###

Output

3

Input

3
...
...
...

Output

0

Input

4
#...
....
....
#...

Output

2

Input

5
#...#
.#.#.
.....
.#...
#....

Output

5

Note

The examples and some of optimal solutions are shown on the pictures below.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double PI = atan(1.0) * 4;
const long long int INF = 1e7 + 9;
int dp[52][52][52][52] = {0};
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i < n + 1; i++)
    for (int j = 1; j < n + 1; j++) {
      char c;
      cin >> c;
      if (c == '#')
        dp[i][j][i][j] = 1;
      else
        dp[i][j][i][j] = 0;
    }
  for (int r = 0; r < n + 1; r++)
    for (int c = 0; c < n + 1; c++) {
      if (!(r | c)) continue;
      for (int i = 1; i < n + 1; i++)
        for (int j = 1; j < n + 1; j++) {
          int x = i + r;
          int y = j + c;
          if (x > n || y > n) continue;
          int min1 = 1e9;
          for (int p = i; p < x; p++)
            min1 = min(min1, dp[i][j][p][y] + dp[p + 1][j][x][y]);
          for (int q = j; q < y; q++)
            min1 = min(min1, dp[i][j][x][q] + dp[i][q + 1][x][y]);
          dp[i][j][x][y] = min(min1, max(r + 1, c + 1));
        }
    }
  cout << dp[1][1][n][n] << '\n';
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Polycarpus has a sequence, consisting of n non-negative integers: a1, a2, ..., an.

Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formally: f(l, r) = al | al + 1 | ... | ar.

Polycarpus took a piece of paper and wrote out the values of function f(l, r) for all l, r (l, r are integer, 1 ≤ l ≤ r ≤ n). Now he wants to know, how many distinct values he's got in the end.

Help Polycarpus, count the number of distinct values of function f(l, r) for the given sequence a.

Expression x | y means applying the operation of bitwise OR to numbers x and y. This operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "|", in Pascal — as "or".

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of elements of sequence a. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 106) — the elements of sequence a.

Output

Print a single integer — the number of distinct values of function f(l, r) for the given sequence a.

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

Examples

Input

3
1 2 0

Output

4

Input

10
1 2 3 4 5 6 1 2 9 10

Output

11

Note

In the first test case Polycarpus will have 6 numbers written on the paper: f(1, 1) = 1, f(1, 2) = 3, f(1, 3) = 3, f(2, 2) = 2, f(2, 3) = 2, f(3, 3) = 0. There are exactly 4 distinct numbers among them: 0, 1, 2, 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int d[100010];
int num[21];
struct Node {
  int v, p;
};
vector<struct Node> u;
bool cmp(struct Node a, struct Node b) { return a.p > b.p; }
struct Node make_node(int v, int p) {
  struct Node tmp;
  tmp.v = v;
  tmp.p = p;
  return tmp;
}
int main() {
  int n;
  while (scanf(" %d", &n) == 1) {
    for (int i = 1; i <= n; i++) {
      scanf(" %d", &d[i]);
    }
    memset(num, 0, sizeof(num));
    set<int> out;
    for (int i = 1; i <= n; i++) {
      u.clear();
      for (int j = 0; j < 20; j++) {
        if ((1 << j) & d[i]) {
          num[j] = i;
        }
        u.push_back(make_node(j, num[j]));
      }
      sort(u.begin(), u.end(), cmp);
      int v = d[i];
      out.insert(v);
      for (size_t i = 0; i < u.size();) {
        v |= d[u[i].p];
        i++;
        while (i < u.size() && u[i - 1].p == u[i].p) {
          i++;
        }
        out.insert(v);
      }
    }
    printf("%d\n", out.size());
    bool is_first = true;
  }
  return 0;
}

```