### Prompt

Please create a solution in Cpp to the following problem:

The only difference between easy and hard versions is the length of the string.

You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).

For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".

You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.

If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).

Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.

Input

The first line of the input contains one string s consisting of at least 1 and at most 200 lowercase Latin letters.

The second line of the input contains one string t consisting of at least 1 and at most 200 lowercase Latin letters.

It is guaranteed that t is a subsequence of s.

Output

Print one integer — the maximum possible length of the substring you can remove so that t is still a subsequence of s.

Examples

Input

bbaba
bb

Output

3

Input

baaba
ab

Output

2

Input

abcde
abcde

Output

0

Input

asdfasdf
fasd

Output

3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int minPrefix[200000 + 3], maxSuffix[200000 + 3], answer;
string s, t;
int main() {
  cin >> s >> t;
  int ptrS;
  ptrS = 0;
  for (int i = 0; i < t.length(); i++) {
    while (s[ptrS] != t[i]) ptrS += 1;
    minPrefix[i + 1] = ptrS + 1;
    ptrS += 1;
  }
  ptrS = s.length() - 1;
  for (int i = t.length() - 1; i >= 0; i--) {
    while (s[ptrS] != t[i]) ptrS -= 1;
    maxSuffix[i + 1] = ptrS + 1;
    ptrS -= 1;
  }
  if (false) {
    for (int i = 1; i <= t.length(); i++) {
      cout << minPrefix[i] << " ";
    }
    cout << endl;
    for (int i = 1; i <= t.length(); i++) {
      cout << maxSuffix[i] << " ";
    }
    cout << endl;
  }
  answer = max((int)s.length() - minPrefix[t.length()], maxSuffix[1] - 1);
  for (int i = 1; i < t.length(); i++) {
    answer = max(answer, maxSuffix[i + 1] - minPrefix[i] - 1);
  }
  cout << answer << endl;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

J: City

Santa decides to deliver a present to a city.

The city has a rectangular shape divided into north-south $ H $ parcels x east-west $ W $ parcels, with one house delivering gifts to each parcel.

The $ X $ th section from the north and the $ Y $ th section from the west are represented by $ (X, Y) $.

Santa moves under the following conditions.

* First, get off at block $ (S, T) $ and start from this place.
* You can move to the adjacent sections in the north, south, east, and west with one move, and you cannot move outside the city.
* You will never enter the area you visited once.

Determine if Santa can visit all the houses in the city.

input

$ H, W, S, T $ are given separated by blanks.

output

Output "Yes" if Santa can visit all the homes in the city, otherwise output "No".

Constraint

* $ H, W $ are integers greater than or equal to $ 2 $ and less than or equal to $ 1 \ 000 \ 000 \ 000 $
* $ S $ is an integer greater than or equal to $ 1 $ and less than or equal to $ H $
* $ T $ is an integer greater than or equal to $ 1 $ and less than or equal to $ W $

Input example 1

4 5 2 3

Output example 1

Yes

For example, you can go to the figure.

<image>

Input example 2

3 3 1 2

Output example 2

No

Example

Input

4 5 2 3

Output

Yes

### Response

```cpp
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int h,w,s,t,flg;
	scanf("%d %d %d %d",&h,&w,&s,&t);
	flg=1;
	if((s-1)%2==0 && (h-s)%2==0)	{
		if((t-1)%2==1 && (w-t)%2==1)	flg=0;
	}
	if((t-1)%2==0 && (w-t)%2==0)	{
		if((s-1)%2==1 && (h-s)%2==1)	flg=0;
	}
	if(flg==1)	printf("Yes\n");
	else printf("No\n");
	return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Good job! Now that Heidi is able to distinguish between Poisson and uniform distributions, she is in a good position to actually estimate the populations.

Can you help Heidi estimate each village's population?

Input

Same as the easy version.

Output

Output one line per village, in the same order as provided in the input, containing your (integer) population estimate.

Your answer is considered correct if it is an integer that falls into the interval <image>, where P is the real population of the village, used to create the distribution (either Poisson or uniform) from which the marmots drew their answers.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
int n, a[N];
int cnt[N];
int main() {
  int T;
  srand(time(0));
  scanf("%d", &(T));
  while (T--) {
    memset(cnt, 0, sizeof(cnt));
    double ex = 0;
    for (int i = 1; i <= 250; i++)
      scanf("%d", &(a[i])), cnt[a[i]]++, ex += a[i];
    ex /= 250;
    int tot = 0;
    for (int i = 1; i <= ex / 3; i++) tot += cnt[i];
    if (tot < 250 / 6 - 25) {
    } else {
      double dx = 0;
      dx = 0;
      for (int i = 1; i <= 250; i++) dx = max(dx, (double)a[i]);
      dx /= 2.0;
      ex = dx;
    }
    printf("%.0lf\n", ex);
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Furik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his problems, the one Furik gave to Rubik. And Rubik asks you to solve it.

There is integer n and array a, consisting of ten integers, indexed by numbers from 0 to 9. Your task is to count the number of positive integers with the following properties:

  * the number's length does not exceed n;
  * the number doesn't have leading zeroes;
  * digit i (0 ≤ i ≤ 9) occurs in the number at least a[i] times.

Input

The first line contains integer n (1 ≤ n ≤ 100). The next line contains 10 integers a[0], a[1], ..., a[9] (0 ≤ a[i] ≤ 100) — elements of array a. The numbers are separated by spaces.

Output

On a single line print the remainder of dividing the answer to the problem by 1000000007 (109 + 7).

Examples

Input

1
0 0 0 0 0 0 0 0 0 1

Output

1

Input

2
1 1 0 0 0 0 0 0 0 0

Output

1

Input

3
1 1 0 0 0 0 0 0 0 0

Output

36

Note

In the first sample number 9 meets the requirements.

In the second sample number 10 meets the requirements.

In the third sample numbers 10, 110, 210, 120, 103 meet the requirements. There are other suitable numbers, 36 in total.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int maxN = 110;
int a[maxN];
long long c[maxN][maxN], dp[maxN][maxN], ans;
void fillC() {
  for (int i = 0; i < maxN; i++) c[i][i] = c[0][i] = 1;
  for (int i = 1; i < maxN; i++)
    for (int j = 1; j < maxN; j++)
      c[i][j] = (c[i - 1][j - 1] + c[i][j - 1]) % MOD;
}
int main() {
  int n;
  fillC();
  cin >> n;
  for (int i = 0; i < 10; i++) cin >> a[i];
  for (int i = a[9]; i <= n; i++) dp[i][9] = 1;
  for (int i = 0; i <= n; i++)
    for (int j = 8; j > 0; j--) {
      long long now = 0;
      for (int k = a[j]; k <= i; k++)
        now = (now + dp[i - k][j + 1] * c[k][i]) % MOD;
      dp[i][j] = now;
    }
  for (int i = 0; i <= n; i++) {
    for (int j = a[0]; j <= i; j++)
      dp[i][0] += (dp[i - j][1] * c[j][i - 1]) % MOD;
    ans = ans + dp[i][0];
    ans %= MOD;
  }
  cout << ans << endl;
  cin >> n;
}

```


### Prompt

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

Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes.

Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.

Input

The first line contains positive integer n (1 ≤ n ≤ 100) — the number of USB flash drives.

The second line contains positive integer m (1 ≤ m ≤ 105) — the size of Sean's file.

Each of the next n lines contains positive integer ai (1 ≤ ai ≤ 1000) — the sizes of USB flash drives in megabytes.

It is guaranteed that the answer exists, i. e. the sum of all ai is not less than m.

Output

Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.

Examples

Input

3
5
2
1
3

Output

2

Input

3
6
2
3
2

Output

3

Input

2
5
5
10

Output

1

Note

In the first example Sean needs only two USB flash drives — the first and the third.

In the second example Sean needs all three USB flash drives.

In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int i, j = 0, a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (i = n - 1; i >= 0; i--) {
    m = m - a[i];
    j++;
    if (m <= 0) {
      cout << j;
      return 0;
    }
  }
}

```


### Prompt

Develop a solution in cpp to the problem described below:

You are given $n$ integers $w_i (i = 0, 1, ..., n-1)$ to be sorted in ascending order. You can swap two integers $w_i$ and $w_j$. Each swap operation has a cost, which is the sum of the two integers $w_i + w_j$. You can perform the operations any number of times.

Write a program which reports the minimal total cost to sort the given integers.

Constraints

* $1 \leq n \leq 1,000$
* $0 \leq w_i\leq 10^4$
* $w_i$ are all different

Input

In the first line, an integer $n$ is given. In the second line, $n$ integers $w_i (i = 0, 1, 2, ... n-1)$ separated by space characters are given.

Output

Print the minimal cost in a line.

Examples

Input

5
1 5 3 4 2

Output

7

Input

4
4 3 2 1

Output

10

### Response

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

int do_cycle(vector<int> &v,int x){
	int s=0,m=1<<30;
	for(auto &e:v)s+=e,m=min(m,e);
	return min(s+(v.size()-2)*m,s+m+(v.size()+1)*x);
}

int main(){
	int N,x=1<<30,r=0;
	scanf("%d",&N);
	vector<int>v(N),b(N),se(N);
	map<int,int>m;
	vector<vector<int> >cycles;
	for(int i=0;i<N;i++)scanf("%d",&v[i]),x=min(x,v[i]),se[i]=v[i];
	sort(se.begin(),se.end());
	int i=0;for(auto &e:se){m[e]=i++;}
	for(int i=0;i<N;i++)if(!b[i]){
		vector<int>cycle;
		int k=i;
		do{
			cycle.push_back(se[k]);
			b[k]=1;
			k=m[v[k]];
		}while(k!=i);
		r+=do_cycle(cycle,x);
	}
	printf("%d\n",r);
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

Iahub is playing an uncommon game. Initially, he has n boxes, numbered 1, 2, 3, ..., n. Each box has some number of candies in it, described by a sequence a1, a2, ..., an. The number ak represents the number of candies in box k.

The goal of the game is to move all candies into exactly two boxes. The rest of n - 2 boxes must contain zero candies. Iahub is allowed to do several (possible zero) moves. At each move he chooses two different boxes i and j, such that ai ≤ aj. Then, Iahub moves from box j to box i exactly ai candies. Obviously, when two boxes have equal number of candies, box number j becomes empty.

Your task is to give him a set of moves such as Iahub to archive the goal of the game. If Iahub can't win the game for the given configuration of boxes, output -1. Please note that in case there exist a solution, you don't need to print the solution using minimal number of moves.

Input

The first line of the input contains integer n (3 ≤ n ≤ 1000). The next line contains n non-negative integers: a1, a2, ..., an — sequence elements. It is guaranteed that sum of all numbers in sequence a is up to 106.

Output

In case there exists no solution, output -1. Otherwise, in the first line output integer c (0 ≤ c ≤ 106), representing number of moves in your solution. Each of the next c lines should contain two integers i and j (1 ≤ i, j ≤ n, i ≠ j): integers i, j in the kth line mean that at the k-th move you will move candies from the j-th box to the i-th one.

Examples

Input

3
3 6 9

Output

2
2 3
1 3

Input

3
0 1 0

Output

-1

Input

4
0 1 1 0

Output

0

Note

For the first sample, after the first move the boxes will contain 3, 12 and 3 candies. After the second move, the boxes will contain 6, 12 and 0 candies. Now all candies are in exactly 2 boxes.

For the second sample, you can observe that the given configuration is not valid, as all candies are in a single box and they should be in two boxes. Also, any move won't change the configuration, so there exists no solution.

For the third sample, all candies are already in 2 boxes. Hence, no move is needed.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
struct _two {
  int a, b;
} ans[N * N], x, y, z;
bool operator<(_two x, _two y) { return x.a < y.a; }
int n, tot;
int a[N];
void Init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
}
void Sort() {
  if (z < x) swap(x, z);
  if (y < x) swap(x, y);
  if (z < y) swap(y, z);
}
void Change() {
  while (1) {
    Sort();
    if (!x.a) break;
    int temp = y.a / x.a;
    for (int i = 0; i <= 20; i++) {
      if (1 << i > temp) break;
      if (temp & 1 << i) {
        ans[++tot] = (_two){x.b, y.b};
        y.a -= x.a;
      } else {
        ans[++tot] = (_two){x.b, z.b};
        z.a -= x.a;
      }
      x.a += x.a;
    }
  }
}
void Work() {
  int num = 0;
  for (int i = 1; i <= n; i++)
    if (a[i]) num++;
  if (num < 2)
    puts("-1");
  else {
    num = tot = 0;
    for (int i = 1; i <= n; i++)
      if (a[i]) {
        ++num;
        if (num == 1) z = (_two){a[i], i};
        if (num == 2) y = (_two){a[i], i};
        if (num > 2) {
          x = (_two){a[i], i};
          Change();
        }
      }
    printf("%d\n", tot);
    for (int i = 1; i <= tot; i++) printf("%d %d\n", ans[i].a, ans[i].b);
  }
}
int main() {
  Init();
  Work();
  return 0;
}

```


### Prompt

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

There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n. The i-th child wants to get at least ai candies.

Jzzhu asks children to line up. Initially, the i-th child stands at the i-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:

  1. Give m candies to the first child of the line.
  2. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home.
  3. Repeat the first two steps while the line is not empty.

Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?

Input

The first line contains two integers n, m (1 ≤ n ≤ 100; 1 ≤ m ≤ 100). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100).

Output

Output a single integer, representing the number of the last child.

Examples

Input

5 2
1 3 1 4 2

Output

4

Input

6 4
1 1 2 2 3 3

Output

6

Note

Let's consider the first sample.

Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.

Child 4 is the last one who goes home.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int n, m;
  cin >> n >> m;
  vector<pair<long long int, long long int> > v;
  long long int i = 1;
  while (n--) {
    long long int x;
    cin >> x;
    if (x % m == 0) {
      v.push_back({(x / m), i});
    } else
      v.push_back({(x / m) + 1, i});
    i++;
  }
  sort(v.begin(), v.end());
  cout << (v[v.size() - 1].second);
}

```


### Prompt

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

Polycarp is currently developing a project in Vaja language and using a popular dependency management system called Vamen. From Vamen's point of view both Vaja project and libraries are treated projects for simplicity.

A project in Vaja has its own uniqie non-empty name consisting of lowercase latin letters with length not exceeding 10 and version — positive integer from 1 to 106. Each project (keep in mind that it is determined by both its name and version) might depend on other projects. For sure, there are no cyclic dependencies.

You're given a list of project descriptions. The first of the given projects is the one being developed by Polycarp at this moment. Help Polycarp determine all projects that his project depends on (directly or via a certain chain).

It's possible that Polycarp's project depends on two different versions of some project. In this case collision resolving is applied, i.e. for each such project the system chooses the version that minimizes the distance from it to Polycarp's project. If there are several options, the newer (with the maximum version) is preferred. This version is considered actual; other versions and their dependencies are ignored.

More formal, choose such a set of projects of minimum possible size that the following conditions hold:

  * Polycarp's project is chosen;
  * Polycarp's project depends (directly or indirectly) on all other projects in the set;
  * no two projects share the name;
  * for each project x that some other project in the set depends on we have either x or some y with other version and shorter chain to Polycarp's project chosen. In case of ties the newer one is chosen.

Output all Polycarp's project's dependencies (Polycarp's project itself should't be printed) in lexicographical order.

Input

The first line contains an only integer n (1 ≤ n ≤ 1 000) — the number of projects in Vaja.

The following lines contain the project descriptions. Each project is described by a line consisting of its name and version separated by space. The next line gives the number of direct dependencies (from 0 to n - 1) and the dependencies themselves (one in a line) in arbitrary order. Each dependency is specified by its name and version. The projects are also given in arbitrary order, but the first of them is always Polycarp's. Project descriptions are separated by one empty line. Refer to samples for better understanding.

It's guaranteed that there are no cyclic dependencies.

Output

Output all Polycarp's project's dependencies in lexicographical order.

Examples

Input

4
a 3
2
b 1
c 1

b 2
0

b 1
1
b 2

c 1
1
b 2

Output

2
b 1
c 1

Input

9
codehorses 5
3
webfrmk 6
mashadb 1
mashadb 2

commons 2
0

mashadb 3
0

webfrmk 6
2
mashadb 3
commons 2

extra 4
1
extra 3

extra 3
0

extra 1
0

mashadb 1
1
extra 3

mashadb 2
1
extra 1

Output

4
commons 2
extra 1
mashadb 2
webfrmk 6

Input

3
abc 1
2
abc 3
cba 2

abc 3
0

cba 2
0

Output

1
cba 2

Note

The first sample is given in the pic below. Arrow from A to B means that B directly depends on A. Projects that Polycarp's project «a» (version 3) depends on are painted black.

<image>

The second sample is again given in the pic below. Arrow from A to B means that B directly depends on A. Projects that Polycarp's project «codehorses» (version 5) depends on are paint it black. Note that «extra 1» is chosen instead of «extra 3» since «mashadb 1» and all of its dependencies are ignored due to «mashadb 2».

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
struct P {
  string s;
  int v;
};
bool operator<(P a, P b) {
  if (a.s == b.s) return a.v < b.v;
  return a.s < b.s;
}
int n;
P s;
map<P, vector<P>> g;
set<string> usd;
vector<P> q;
map<string, P> mp;
vector<P> ans;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    P u;
    cin >> u.s >> u.v;
    if (i == 0) s = u;
    int k;
    cin >> k;
    while (k--) {
      P v;
      cin >> v.s >> v.v;
      g[u].push_back(v);
    }
  }
  q.push_back(s);
  usd.insert(s.s);
  while (!q.empty()) {
    mp.clear();
    for (P u : q) {
      for (P v : g[u]) {
        if (usd.count(v.s)) continue;
        if (mp[v.s].v < v.v) mp[v.s] = v;
      }
    }
    q.clear();
    for (auto p : mp) {
      P u = p.second;
      q.push_back(u);
      usd.insert(u.s);
      ans.push_back(u);
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans.size() << "\n";
  for (P p : ans) cout << p.s << " " << p.v << "\n";
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Cthulhu decided to catch Scaygerboss. Scaygerboss found it out and is trying to hide in a pack of his scaygers. Each scayger except Scaygerboss is either a male or a female. Scaygerboss's gender is "other".

Scaygers are scattered on a two-dimensional map divided into cells. A scayger looks nerdy and loveable if it is staying in the same cell with exactly one scayger of a gender that is different from its own gender. Cthulhu will not be able to catch Scaygerboss if all the scaygers on the map look nerdy and loveable.

The scaygers can move around at different speeds. For each scayger, we are given the time it takes this scayger to move from a cell to an adjacent cell. Cells are adjacent if they share a common side. At any point of time, each cell that does not contain an obstacle can be occupied by an arbitrary number of scaygers. Scaygers cannot move to cells with obstacles.

Calculate minimal time in order to make all scaygers look nerdy and loveable if they move optimally toward this goal.

Input

The first line contains 4 integers: n, m, males, females (0 ≤ males, females ≤ n·m). n and m are dimensions of the map; males and females are numbers of male scaygers and female scaygers.

Next n lines describe the map. Each of these lines contains m characters. Character '.' stands for a free cell; character '#' stands for a cell with an obstacle.

The next line contains 3 integers r, c, and t (1 ≤ r ≤ n, 1 ≤ c ≤ m, 1 ≤ t ≤ 109): the current coordinates of Scaygerboss and the time it takes Scaygerboss to move to an adjacent cell. The next males lines contain coordinates and times of male scaygers in the same format as for Scaygerboss. The next females lines contain coordinates and times of female scaygers in the same format as for Scaygerboss. (The coordinates and times adhere to the same limits as for Scaygerboss.) All scaygers reside in cells without obstacles.

The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.

  * In subproblem F1 (14 points), the constraints 1 ≤ n, m ≤ 11 will hold.
  * In subproblem F2 (6 points), the constraints 1 ≤ n, m ≤ 22 will hold.

Output

Output the minimum possible time it takes to make all scaygers look nerdy and loveable or -1 if it is impossible.

Examples

Input

4 4 2 3
....
.###
####
####
2 1 1
2 1 2
2 1 2
2 1 2
2 1 2
1 1 2

Output

2

Input

2 4 2 2
....
.###
2 1 1
2 1 2
2 1 2
2 1 2
2 1 2

Output

-1

Note

Consider the first sample test. The scaygers are hiding on a 4 by 4 map. Scaygerboss initially resides in the cell (2, 1) and can move between cells in 1 unit of time. There are also 2 male and 3 female scaygers on the map. One of the females initially is in the cell (1, 1), and all the other scaygers are in the cell (2, 1). All the scaygers move between cells in 2 units of time. If Scaygerboss and the female scayger from the cell (1, 1) move to the cell (1, 2), and a male and a female scayger from those residing in the cell (2, 1) move to the cell (1, 1), then all the scaygers will look nerdy and lovable in 2 units of time.

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int INF = 1000000000;
class MaximumFlow {
  int s, f;

 public:
  struct edge {
    int u, v;
    int capacity, flow;
    edge() { u = v = capacity = flow = 0; }
    edge(int u_, int v_, int capacity_, int flow_)
        : u(u_), v(v_), capacity(capacity_), flow(flow_) {}
  };
  vector<edge> edges;
  vector<vector<int> > graph;
  vector<int> ptr, level;
  queue<int> q;
  int n;
  MaximumFlow() {}
  MaximumFlow(int number) {
    n = number;
    graph.resize(n);
    ptr.assign(n, 0);
    level.resize(n);
  }
  void addEdge(int u, int v, int capacity) {
    int sz = (int)(edges.size());
    edges.push_back(edge(u, v, capacity, 0));
    edges.push_back(edge(v, u, 0, 0));
    graph[u].push_back(sz);
    graph[v].push_back(sz + 1);
  }
  void updateLevels() {
    level.assign(n, -1);
    q.push(s);
    level[s] = 0;
    while (!q.empty()) {
      int topq = q.front();
      q.pop();
      for (int index = 0; index < graph[topq].size(); ++index) {
        int i = graph[topq][index];
        int to = edges[i].v;
        if (edges[i].capacity - edges[i].flow == 0) {
          continue;
        }
        if (level[to] == -1) {
          level[to] = level[topq] + 1;
          q.push(to);
        }
      }
    }
  }
  int pushFlow(int v, int flow) {
    if (v == f || flow == 0) {
      return flow;
    }
    for (; ptr[v] < graph[v].size(); ++ptr[v]) {
      int index = graph[v][ptr[v]];
      int to = edges[index].v;
      if (level[v] + 1 == level[to]) {
        int pushed =
            pushFlow(to, min(flow, edges[index].capacity - edges[index].flow));
        if (pushed > 0) {
          edges[index].flow += pushed;
          edges[index ^ 1].flow -= pushed;
          return pushed;
        }
      }
    }
    return 0;
  }
  int dinicFlow(int start, int finish) {
    s = start, f = finish;
    int result = 0;
    while (true) {
      updateLevels();
      if (level[f] == -1) {
        break;
      }
      while (true) {
        int pushed = pushFlow(start, INF);
        if (pushed == 0) {
          break;
        }
        result += pushed;
      }
      ptr.assign(n, 0);
    }
    return result;
  }
};
const int maxN = 25;
int n, m, male, female;
string s[maxN];
int r[2 * maxN * maxN], c[2 * maxN * maxN], t[2 * maxN * maxN];
int d[maxN][maxN][maxN][maxN];
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
bool isValid(int x, int y) {
  return 0 <= x && x < n && 0 <= y && y < m && s[x][y] == '.';
}
void calc(int d[maxN][maxN], int u, int v) {
  memset(d, -1, sizeof(d));
  d[u][v] = 0;
  queue<pair<int, int> > q;
  q.push(make_pair(u, v));
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    int x = p.first;
    int y = p.second;
    for (int i = 0; i < 4; ++i) {
      if (isValid(x + dx[i], y + dy[i]) && d[x + dx[i]][y + dy[i]] == -1) {
        d[x + dx[i]][y + dy[i]] = d[x][y] + 1;
        q.push(make_pair(x + dx[i], y + dy[i]));
      }
    }
  }
}
bool check(long long value) {
  {
    MaximumFlow F(male + female + 1 + 2 * n * m + 2);
    int start = male + female + 1 + 2 * n * m;
    int finish = start + 1;
    for (int i = (male < female ? 0 : 1); i <= male; ++i) {
      for (int x = 0; x < n; ++x) {
        for (int y = 0; y < m; ++y) {
          if (d[r[i]][c[i]][x][y] == -1) {
            continue;
          }
          if ((long long)(d[r[i]][c[i]][x][y]) * (long long)(t[i]) <= value) {
            F.addEdge(i, male + female + 1 + x * m + y, 1);
          }
        }
      }
      F.addEdge(start, i, 1);
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (isValid(i, j)) {
          F.addEdge(male + female + 1 + i * m + j,
                    male + female + 1 + n * m + i * m + j, 1);
        }
      }
    }
    for (int i = 0; i <= male + female; ++i) {
      if (i < male + 1) {
        if (female < male && i == 0) {
        } else {
          continue;
        }
      }
      for (int x = 0; x < n; ++x) {
        for (int y = 0; y < m; ++y) {
          if (d[r[i]][c[i]][x][y] == -1) {
            continue;
          }
          if ((long long)(d[r[i]][c[i]][x][y]) * (long long)(t[i]) <= value) {
            F.addEdge(male + female + 1 + n * m + x * m + y, i, 1);
          }
        }
      }
      F.addEdge(i, finish, 1);
    }
    return F.dinicFlow(start, finish) == (male + female + 1) / 2;
  }
}
int main() {
  cin >> n >> m >> male >> female;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  cin >> r[0] >> c[0] >> t[0];
  --r[0];
  --c[0];
  for (int i = 1; i <= male; ++i) {
    cin >> r[i] >> c[i] >> t[i];
    --r[i];
    --c[i];
  }
  for (int i = male + 1; i <= male + female; ++i) {
    cin >> r[i] >> c[i] >> t[i];
    --r[i];
    --c[i];
  }
  memset(d, -1, sizeof(d));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (isValid(i, j)) {
        calc(d[i][j], i, j);
      }
    }
  }
  if (male + 1 != female && male != female + 1) {
    cout << -1 << endl;
    return 0;
  }
  long long left_bound = 0, right_bound = 1000000000000000000LL;
  if (!check(right_bound)) {
    cout << -1 << endl;
    return 0;
  }
  while (right_bound - left_bound > 1) {
    long long middle = (left_bound + right_bound) / 2;
    if (check(middle)) {
      right_bound = middle;
    } else {
      left_bound = middle;
    }
  }
  if (check(left_bound)) {
    cout << left_bound << endl;
  } else {
    cout << right_bound << endl;
  }
  return 0;
}

```


### Prompt

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

Denis was very sad after Nastya rejected him. So he decided to walk through the gateways to have some fun. And luck smiled at him! When he entered the first courtyard, he met a strange man who was selling something.

Denis bought a mysterious item and it was... Random permutation generator! Denis could not believed his luck.

When he arrived home, he began to study how his generator works and learned the algorithm. The process of generating a permutation consists of n steps. At the i-th step, a place is chosen for the number i (1 ≤ i ≤ n). The position for the number i is defined as follows:

  * For all j from 1 to n, we calculate r_j — the minimum index such that j ≤ r_j ≤ n, and the position r_j is not yet occupied in the permutation. If there are no such positions, then we assume that the value of r_j is not defined.
  * For all t from 1 to n, we calculate count_t — the number of positions 1 ≤ j ≤ n such that r_j is defined and r_j = t.
  * Consider the positions that are still not occupied by permutation and among those we consider the positions for which the value in the count array is maximum.
  * The generator selects one of these positions for the number i. The generator can choose any position.

Let's have a look at the operation of the algorithm in the following example:

<image>

Let n = 5 and the algorithm has already arranged the numbers 1, 2, 3 in the permutation. Consider how the generator will choose a position for the number 4:

  * The values of r will be r = [3, 3, 3, 4, ×], where × means an indefinite value.
  * Then the count values will be count = [0, 0, 3, 1, 0].
  * There are only two unoccupied positions in the permutation: 3 and 4. The value in the count array for position 3 is 3, for position 4 it is 1.
  * The maximum value is reached only for position 3, so the algorithm will uniquely select this position for number 4.

Satisfied with his purchase, Denis went home. For several days without a break, he generated permutations. He believes that he can come up with random permutations no worse than a generator. After that, he wrote out the first permutation that came to mind p_1, p_2, …, p_n and decided to find out if it could be obtained as a result of the generator.

Unfortunately, this task was too difficult for him, and he asked you for help. It is necessary to define whether the written permutation could be obtained using the described algorithm if the generator always selects the position Denis needs.

Input

The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases. Then the descriptions of the test cases follow.

The first line of the test case contains a single integer n (1 ≤ n ≤ 10^5) — the size of the permutation.

The second line of the test case contains n different integers p_1, p_2, …, p_n (1 ≤ p_i ≤ n) — the permutation written by Denis.

It is guaranteed that the sum of n over all test cases doesn't exceed 10^5.

Output

Print "Yes" if this permutation could be obtained as a result of the generator. Otherwise, print "No".

All letters can be displayed in any case.

Example

Input

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

Output

Yes
Yes
No
Yes
No

Note

Let's simulate the operation of the generator in the first test.

At the 1 step, r = [1, 2, 3, 4, 5], count = [1, 1, 1, 1, 1]. The maximum value is reached in any free position, so the generator can choose a random position from 1 to 5. In our example, it chose 5.

At the 2 step, r = [1, 2, 3, 4, ×], count = [1, 1, 1, 1, 0]. The maximum value is reached in positions from 1 to 4, so the generator can choose a random position among them. In our example, it chose 1.

At the 3 step, r = [2, 2, 3, 4, ×], count = [0, 2, 1, 1, 0]. The maximum value is 2 and is reached only at the 2 position, so the generator will choose this position.

At the 4 step, r = [3, 3, 3, 4, ×], count = [0, 0, 3, 1, 0]. The maximum value is 3 and is reached only at the 3 position, so the generator will choose this position.

At the 5 step, r = [4, 4, 4, 4, ×], count = [0, 0, 0, 4, 0]. The maximum value is 4 and is reached only at the 4 position, so the generator will choose this position.

In total, we got a permutation of 2, 3, 4, 5, 1, that is, a generator could generate it.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int nums[n];
  bool good = 1;
  for (int i = 0; i < n; i++) {
    cin >> nums[i];
    if (i && nums[i] > nums[i - 1] + 1) {
      good = 0;
    }
  }
  cout << (good ? "Yes" : "No") << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed.

Let the total number of sequences listed in FEIS be X. Among those sequences, find the (X/2)-th (rounded up to the nearest integer) lexicographically smallest one.

Constraints

* 1 \leq N,K \leq 3 × 10^5
* N and K are integers.

Input

Input is given from Standard Input in the following format:

K N

Output

Print the (X/2)-th (rounded up to the nearest integer) lexicographically smallest sequence listed in FEIS, with spaces in between, where X is the total number of sequences listed in FEIS.

Examples

Input

3 2

Output

2 1

Input

2 4

Output

1 2 2 2

Input

5 14

Output

3 3 3 3 3 3 3 3 3 3 3 3 2 2

### Response

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

int main() {
    ll K, N;
    cin >> K >> N;

    vector<ll> ans;
    if (K % 2 == 0) {
        ans.push_back(K / 2);
        for (ll i = 0; i < N - 1; i++) {
            ans.push_back(K);
        }
    } else {
        for (ll i = 0; i < N; i++) {
            ans.push_back((K + 1) / 2);
        }

        for (ll i = 0; i < N / 2; i++) {
            if (ans.back() == 1) {
                ans.erase(ans.end() - 1);
            } else {
                ans.back()--;
                while (ans.size() != N) {
                    ans.push_back(K);
                }
            }
        }
    }

    for (ll i = 0; i < ans.size(); i++) {
        cout << ans[i] << " \n"[i == ans.size() - 1];
    }
}
```


### Prompt

Construct a Cpp code solution to the problem outlined:

Given are N points (x_i, y_i) in a two-dimensional plane.

Find the minimum radius of a circle such that all the points are inside or on it.

Constraints

* 2 \leq N \leq 50
* 0 \leq x_i \leq 1000
* 0 \leq y_i \leq 1000
* The given N points are all different.
* The values in input are all integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the minimum radius of a circle such that all the N points are inside or on it.

Your output will be considered correct if the absolute or relative error from our answer is at most 10^{-6}.

Examples

Input

2
0 0
1 0

Output

0.500000000000000000

Input

3
0 0
0 1
1 0

Output

0.707106781186497524

Input

10
10 9
5 9
2 0
0 0
2 7
3 3
2 5
10 0
3 7
1 9

Output

6.726812023536805158

### Response

```cpp
#include <cstdio>
#include <cmath>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>
using namespace std;
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
int n;
double x[1005], y[1005], X, Y, d, e;
double dist(double a, double b) {
	return a*a + b*b;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", &x[i], &y[i]);
		X += x[i]; Y += y[i];
	}
	X /= n; Y /= n;
	double P = 0.1;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dist(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			e = dist(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}
    cout << shosu(10) << sqrt(d) << endl;
	//printf("%.3lf %.3lf\n%.3lf", X, Y, sqrt(d));
}

```


### Prompt

Create a solution in Cpp for the following problem:

Compute A + B.

Constraints

* -1000 ≤ A, B ≤ 1000

Input

The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF.

Output

For each pair of input integers A and B, you must output the sum of A and B in one line.

Example

Input

1 2
10 5
100 20

Output

3
15
120

### Response

```cpp
#include <iostream>
#include <cstdio>
using namespace std;

int main(){
    int i,j;
    while(scanf("%d %d",&i,&j) != EOF){
        cout << i+j << endl;
    }
}
```


### Prompt

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

We guessed a permutation p consisting of n integers. The permutation of length n is the array of length n where each element from 1 to n appears exactly once. This permutation is a secret for you.

For each position r from 2 to n we chose some other index l (l < r) and gave you the segment p_l, p_{l + 1}, ..., p_r in sorted order (i.e. we rearranged the elements of this segment in a way that the elements of this segment are sorted). Thus, you are given exactly n-1 segments of the initial permutation but elements inside each segment are sorted. The segments are given to you in random order.

For example, if the secret permutation is p=[3, 1, 4, 6, 2, 5] then the possible given set of segments can be:

  * [2, 5, 6]
  * [4, 6]
  * [1, 3, 4]
  * [1, 3]
  * [1, 2, 4, 6]

Your task is to find any suitable permutation (i.e. any permutation corresponding to the given input data). It is guaranteed that the input data corresponds to some permutation (i.e. such permutation exists).

You have to answer t independent test cases.

Input

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

The first line of the test case contains one integer n (2 ≤ n ≤ 200) — the length of the permutation.

The next n-1 lines describe given segments.

The i-th line contains the description of the i-th segment. The line starts with the integer k_i (2 ≤ k_i ≤ n) — the length of the i-th segment. Then k_i integers follow. All integers in a line are distinct, sorted in ascending order, between 1 and n, inclusive.

It is guaranteed that the required p exists for each test case.

It is also guaranteed that the sum of n over all test cases does not exceed 200 (∑ n ≤ 200).

Output

For each test case, print the answer: n integers p_1, p_2, ..., p_n (1 ≤ p_i ≤ n, all p_i should be distinct) — any suitable permutation (i.e. any permutation corresponding to the test case input).

Example

Input

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

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<set<int>> segs;
    for (int i = 0; i < n - 1; i++) {
      set<int> cur;
      int k;
      cin >> k;
      for (int j = 0; j < k; j++) {
        int x;
        cin >> x;
        cur.insert(x);
      }
      segs.push_back(cur);
    }
    for (int fst = 1; fst <= n; fst++) {
      vector<int> ans;
      bool ok = true;
      vector<set<int>> cur = segs;
      for (auto &it : cur) {
        if (it.count(fst)) it.erase(fst);
      }
      ans.push_back(fst);
      for (int i = 1; i < n; i++) {
        int cnt1 = 0;
        int nxt = -1;
        for (auto &it : cur)
          if (it.size() == 1) {
            ++cnt1;
            nxt = *it.begin();
          }
        if (cnt1 != 1) {
          ok = false;
          break;
        }
        for (auto &it : cur)
          if (it.count(nxt)) it.erase(nxt);
        ans.push_back(nxt);
      }
      if (ok) {
        set<set<int>> all(segs.begin(), segs.end());
        for (int i = 1; i < n; ++i) {
          set<int> seg;
          seg.insert(ans[i]);
          bool found = false;
          for (int j = i - 1; j >= 0; --j) {
            seg.insert(ans[j]);
            if (all.count(seg)) {
              found = true;
              all.erase(seg);
              break;
            }
          }
          if (!found) ok = false;
        }
      }
      if (ok) {
        for (auto it : ans) cout << it << " ";
        cout << endl;
        break;
      }
    }
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Given is an integer sequence A_1, ..., A_N of length N.

We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen.

Find the maximum possible sum of the chosen elements.

Here \lfloor x \rfloor denotes the greatest integer not greater than x.

Constraints

* 2 \leq N \leq 2\times 10^5
* |A_i|\leq 10^9
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the maximum possible sum of the chosen elements.

Examples

Input

6
1 2 3 4 5 6

Output

12

Input

5
-1000 -100 -10 0 10

Output

0

Input

10
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Output

5000000000

Input

27
18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49

Output

295

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+50;
int t,n,m;
int arr[maxn];
ll dp[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
	}
/*  	if(n%2==0)
	{
		ll fin0=0;
		ll fin1=0;
		for(int i=1;i<=n;i++)
		{
			if(i&1) fin1+=arr[i];
			else fin0+=arr[i];
		}
		cout<<max(fin0,fin1)<<endl;
		return 0;
	}*/
	ll sum[maxn];
	sum[1]=arr[1];
	for(int i=3;i<=n;i+=2)
	{
		sum[i]=sum[i-2]+arr[i];
	}
	for(int i=2;i<=n;i++)
	{
		if(i%2==1)
		{
			dp[i]=max(dp[i-1],dp[i-2]+arr[i]);
		}
		else
		{
			dp[i]=max(sum[i-1],dp[i-2]+arr[i]);
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}
```


### Prompt

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

Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade ai for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write bi essays. He can raise the exam grade multiple times.

What is the minimum number of essays that Vanya needs to write to get scholarship?

Input

The first line contains three integers n, r, avg (1 ≤ n ≤ 105, 1 ≤ r ≤ 109, 1 ≤ avg ≤ min(r, 106)) — the number of exams, the maximum grade and the required grade point average, respectively.

Each of the following n lines contains space-separated integers ai and bi (1 ≤ ai ≤ r, 1 ≤ bi ≤ 106).

Output

In the first line print the minimum number of essays.

Examples

Input

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

Output

4

Input

2 5 4
5 2
5 2

Output

0

Note

In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point.

In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, r, avg;
  cin >> n >> r >> avg;
  vector<pair<long long int, long long int>> v;
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) {
    long long int a, b;
    cin >> a >> b;
    sum += a;
    v.push_back(make_pair(b, a));
  }
  if (sum / n >= avg) {
    cout << 0 << endl;
    return 0;
  }
  long long int count_ = 0;
  sort(v.begin(), v.end());
  sum = n * avg - sum;
  for (long long int i = 0; i < n; i++) {
    if (sum <= 0) break;
    if (sum >= r - v[i].second) {
      count_ += (r - v[i].second) * (v[i].first);
      sum = sum - (r - v[i].second);
    } else {
      count_ += sum * v[i].first;
      sum = 0;
    }
  }
  cout << count_ << endl;
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

You are given integers N and M.

Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.

Constraints

* All values in input are integers.
* 1 \leq N \leq 10^5
* N \leq M \leq 10^9

Input

Input is given from Standard Input in the following format:

N M

Output

Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition.

Examples

Input

3 14

Output

2

Input

10 123

Output

3

Input

100000 1000000000

Output

10000

### Response

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

```


### Prompt

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

To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible.

The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following:

  * aij — the cost of buying an item;
  * bij — the cost of selling an item;
  * cij — the number of remaining items.

It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind.

Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get.

Input

The first line contains three space-separated integers n, m and k (2 ≤ n ≤ 10, 1 ≤ m, k ≤ 100) — the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly.

Then follow n blocks describing each planet.

The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≤ bij < aij ≤ 1000, 0 ≤ cij ≤ 100) — the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces.

It is guaranteed that the names of all planets are different.

Output

Print a single number — the maximum profit Qwerty can get.

Examples

Input

3 3 10
Venus
6 5 3
7 6 5
8 6 10
Earth
10 9 0
8 6 4
10 9 3
Mars
4 3 0
8 4 12
7 2 5

Output

16

Note

In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3·6 + 7·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3·9 + 7·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 110;
char st[Maxn];
int a[Maxn][Maxn], b[Maxn][Maxn], c[Maxn][Maxn];
int v[Maxn], num[Maxn];
int n, m, lim;
int main() {
  scanf("%d%d%d", &n, &m, &lim);
  for (int i = 0; i < n; ++i) {
    scanf("%s", st);
    for (int j = 0; j < m; ++j) scanf("%d%d%d", &a[i][j], &b[i][j], &c[i][j]);
  }
  int res = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      if (i != j) {
        for (int k = 0; k < m; ++k) {
          v[k] = b[j][k] - a[i][k];
          num[k] = c[i][k];
        }
        for (int ii = 0; ii < m; ++ii)
          for (int jj = ii + 1; jj < m; ++jj)
            if (v[ii] < v[jj]) {
              swap(v[ii], v[jj]);
              swap(num[ii], num[jj]);
            }
        int z = 0;
        int rest = lim;
        for (int ii = 0; ii < m && v[ii] > 0 && rest > 0; ++ii) {
          int use = min(rest, num[ii]);
          z += v[ii] * use;
          rest -= use;
        }
        res = max(res, z);
      }
  printf("%d\n", res);
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

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

Now he has a positive integer n. He wants to split n into 3 positive integers a,b,c, such that a+b+c=n and none of the 3 integers is a multiple of 3. Help him to find a solution.

Input

A single line containing one integer n (3 ≤ n ≤ 10^9) — the integer Little C has.

Output

Print 3 positive integers a,b,c in a single line, such that a+b+c=n and none of them is a multiple of 3.

It can be proved that there is at least one solution. If there are multiple solutions, print any of them.

Examples

Input

3

Output

1 1 1

Input

233

Output

77 77 79

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const long long inf = 1e17 + 7;
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  long long n;
  cin >> n;
  if (n % 3 == 2) {
    cout << n - 3 << " " << 1 << " " << 2 << endl;
  } else {
    cout << n - 2 << " " << 1 << " " << 1 << endl;
  }
}

```


### Prompt

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

We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective.

Constraints

* H is an integer between 1 and 50 (inclusive).
* W is an integer between 1 and 50 (inclusive).
* For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is `#` or `.`.

Input

Input is given from Standard Input in the following format:

H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
:   :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}

Output

If square1001 can achieve his objective, print `Yes`; if he cannot, print `No`.

Examples

Input

3 3
.#.
###
.#.

Output

Yes

Input

3 3
.#.

.#.

Output

Yes

Input

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

Output

No

Input

11 11
...#####...
.##.....##.
..##.##..#
..##.##..#
.........#
...###...#
.#########.
.#.#.#.#.#.
.#.#.#.##
..##.#.##..
.##..#..##.

Output

Yes

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int H ,W;
cin >> H >> W;
char c[55][55] ={'.'};
for(int i = 1; i <= H; i++){
  for(int j = 1; j <= W; j++){
    cin >> c[i][j];
  }
}
for(int i = 1; i <=H; i++){
  for(int j = 1; j<= W; j++){
    if(c[i][j] == '#'){
      if(c[i][j-1] != '#' && c[i][j+1] != '#' && c[i+1][j] != '#' &&c[i-1][j] != '#'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
}
cout << "Yes" << endl;
}
```


### Prompt

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

A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.

Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.

Input

The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).

Output

Print a single integer the number of 2-3-integers on the segment [l, r].

Examples

Input

1 10

Output

7

Input

100 200

Output

5

Input

1 2000000000

Output

326

Note

In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.

In the second example the 2-3-integers are 108, 128, 144, 162 and 192.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<long long int> a;
long long int nn = 1e9;
int main() {
  long long int l, r;
  scanf("%lld %lld", &l, &r);
  for (long long int i = 0; i <= 30; ++i) {
    for (long long int j = 0; j <= 20; ++j) {
      long long int x = pow(2, i);
      long long int y = pow(3, j);
      if ((x > nn && y > nn) || x * y > 2 * nn) {
        continue;
      }
      a.push_back(x * y);
    }
  }
  sort(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < (int)a.size(); ++i) {
    if (a[i] > r) break;
    if (a[i] >= l && a[i] <= r) ans++;
  }
  printf("%d\n", ans);
}

```


### Prompt

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

For a given polygon g, computes the area of the polygon.

g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of g. The line segment connecting pn and p1 is also a side of the polygon.

Note that the polygon is not necessarily convex.

Constraints

* 3 ≤ n ≤ 100
* -10000 ≤ xi, yi ≤ 10000
* No point will occur more than once.
* Two sides can intersect only at a common endpoint.

Input

The input consists of coordinates of the points p1,..., pn in the following format:

n
x1 y1
x2 y2
:
xn yn

The first integer n is the number of points. The coordinate of a point pi is given by two integers xi and yi. The coordinates of points are given in the order of counter-clockwise visit of them.

Output

Print the area of the polygon in a line. The area should be printed with one digit to the right of the decimal point.

Examples

Input

3
0 0
2 2
-1 1

Output

2.0

Input

4
0 0
1 1
1 2
0 2

Output

1.5

### Response

```cpp
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

#define X real()
#define Y imag()
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}

typedef vector<P> G;

double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}

double area2(const G &P) {
  double A = 0.0;
  for (int i = 0; i < P.size(); ++i)
    A += cross(curr(P, i), next(P, i));
  return A / 2.0;
}

int main() {
  int N; cin >>N;
  G g(N);
  REP(i, N){
    int x, y; cin >>x >>y;
    g[i] = P(x, y);
  }
  printf("%.1lf\n", area2(g));
  return 0;
}
```


### Prompt

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

Let's assume that set S consists of m distinct intervals [l1, r1], [l2, r2], ..., [lm, rm] (1 ≤ li ≤ ri ≤ n; li, ri are integers).

Let's assume that f(S) is the maximum number of intervals that you can choose from the set S, such that every two of them do not intersect. We assume that two intervals, [l1, r1] and [l2, r2], intersect if there is an integer x, which meets two inequalities: l1 ≤ x ≤ r1 and l2 ≤ x ≤ r2.

Sereja wonders, how many sets S are there, such that f(S) = k? Count this number modulo 1000000007 (109 + 7).

Input

The first line contains integers n, k (1 ≤ n ≤ 500; 0 ≤ k ≤ 500).

Output

In a single line, print the answer to the problem modulo 1000000007 (109 + 7).

Examples

Input

3 1

Output

23

Input

3 2

Output

32

Input

2 0

Output

1

Input

2 2

Output

2

### Response

```cpp
#include <bits/stdc++.h>
long long int mod = 1000000007;
long long int f[510][510];
long long int pp[1000000];
long long int ans;
int n, k;
void prepare() {
  long long int cnt;
  int i, j;
  pp[0] = 1;
  for (i = 1; i < 1000000; i++) pp[i] = (pp[i - 1] * 2) % mod;
  for (i = 0; i <= 500; i++) f[i][0] = 1;
  for (n = 1; n <= 500; n++)
    for (k = 1; k <= n; k++) {
      for (j = k; j <= n; j++) {
        cnt = (pp[j * (n - j + 1)] - pp[(j - 1) * (n - j + 1)] + mod) % mod;
        cnt = (f[j - 1][k - 1] * cnt) % mod;
        f[n][k] = (f[n][k] + cnt);
      }
      f[n][k] %= mod;
    }
}
int main() {
  int i, j;
  prepare();
  scanf("%d %d", &n, &k);
  printf("%lld\n", f[n][k]);
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size.

In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points).

Input

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

The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≤ x_i ≤ 10^9) — the coordinates of points.

Output

In the first line print m — the maximum possible number of points in a subset that satisfies the conditions described above.

In the second line print m integers — the coordinates of points in the subset you have chosen.

If there are multiple answers, print any of them.

Examples

Input

6
3 5 4 7 10 12

Output

3
7 3 5

Input

5
-1 2 5 8 11

Output

1
8

Note

In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
map<int, pair<int, int>> m;
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  sort(a, a + n);
  int po[35];
  po[0] = 1;
  for (int i = 1; i <= 30; i++) {
    po[i] = (1 << i);
  }
  vector<pair<int, int>> ans[n];
  pair<int, int> mx = {0, 0};
  for (int i = 0; i < n; i++) {
    pair<int, int> cnt = {0, 0};
    for (int j = 0; j <= 30; j++) {
      int c = 0;
      int f = (upper_bound(a, a + n, a[i] + po[j]) - a) -
              (lower_bound(a, a + n, a[i] + po[j]) - a);
      int l = (upper_bound(a, a + n, a[i] + 2 * po[j]) - a) -
              (lower_bound(a, a + n, a[i] + 2 * po[j]) - a);
      c = l + f;
      c += ((upper_bound(a, a + n, a[i]) - a) -
            (lower_bound(a, a + n, a[i]) - a));
      if (cnt.first < c) cnt = {c, j};
    }
    ans[i].push_back({a[i], po[cnt.second]});
    if (cnt.first > mx.first) mx = {cnt.first, i};
  }
  printf("%d\n", mx.first);
  for (auto i : ans[mx.second]) {
    int st = (lower_bound(a, a + n, i.first) - a);
    int en = (upper_bound(a, a + n, i.first) - a);
    for (int j = st; j < en; j++) printf("%d ", a[j]);
    st = lower_bound(a, a + n, i.first + i.second) - a;
    en = upper_bound(a, a + n, i.first + i.second) - a;
    for (int j = st; j < en; j++) printf("%d ", a[j]);
    st = lower_bound(a, a + n, i.first + 2 * i.second) - a;
    en = upper_bound(a, a + n, i.first + 2 * i.second) - a;
    for (int j = st; j < en; j++) printf("%d ", a[j]);
  }
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

We call an array almost increasing if we can erase not more than one element from it so that the array becomes strictly increasing (that is, every element is striclty greater than every element before it).

You are given an array a consisting of n elements. You are allowed to replace any element with any integer number (and you may do so any number of times you need). What is the minimum number of replacements you have to perform in order to make the array almost increasing?

Input

The first line contains one integer n (2 ≤ n ≤ 200000) — the number of elements in a.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the array a.

Output

Print the minimum number of replaces you have to perform so that a is almost increasing.

Examples

Input

5
5 4 3 2 1

Output

3

Input

5
1 2 8 9 5

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, neg = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  return x * neg;
}
inline void print(int x) {
  if (x < 0) {
    putchar('-');
    print(abs(x));
    return;
  }
  if (x <= 9)
    putchar(x + '0');
  else {
    print(x / 10);
    putchar(x % 10 + '0');
  }
}
inline int qpow(int x, int e, int _MOD) {
  int ans = 1;
  while (e) {
    if (e & 1) ans = ans * x % _MOD;
    x = x * x % _MOD;
    e >>= 1;
  }
  return ans;
}
int n = read(), a[200005], f[200005], g[200005], ans = 0;
signed main() {
  for (int i = 1; i <= n; i++) a[i] = read();
  memset(f, 0x3f, sizeof(f));
  memset(g, 0x3f, sizeof(g));
  for (int i = 2; i <= n; i++) {
    int ind = upper_bound(g + 1, g + 1 + n, a[i] - i + 1) - g;
    g[ind] = a[i] - i + 1;
    ans = max(ans, ind);
    ind = upper_bound(f + 1, f + 1 + n, a[i - 1] - i + 1) - f;
    f[ind] = a[i - 1] - i + 1;
    g[ind] = min(g[ind], f[ind]);
    ans = max(ans, ind);
  }
  cout << n - 1 - ans << endl;
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

One way to create a task is to learn from life. You can choose some experience in real life, formalize it and then you will get a new task.

Let's think about a scene in real life: there are lots of people waiting in front of the elevator, each person wants to go to a certain floor. We can formalize it in the following way. We have n people standing on the first floor, the i-th person wants to go to the fi-th floor. Unfortunately, there is only one elevator and its capacity equal to k (that is at most k people can use it simultaneously). Initially the elevator is located on the first floor. The elevator needs |a - b| seconds to move from the a-th floor to the b-th floor (we don't count the time the people need to get on and off the elevator).

What is the minimal number of seconds that is needed to transport all the people to the corresponding floors and then return the elevator to the first floor?

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 2000) — the number of people and the maximal capacity of the elevator.

The next line contains n integers: f1, f2, ..., fn (2 ≤ fi ≤ 2000), where fi denotes the target floor of the i-th person.

Output

Output a single integer — the minimal time needed to achieve the goal.

Examples

Input

3 2
2 3 4

Output

8

Input

4 2
50 100 50 100

Output

296

Input

10 3
2 2 2 2 2 2 2 2 2 2

Output

8

Note

In first sample, an optimal solution is:

  1. The elevator takes up person #1 and person #2.
  2. It goes to the 2nd floor.
  3. Both people go out of the elevator.
  4. The elevator goes back to the 1st floor.
  5. Then the elevator takes up person #3.
  6. And it goes to the 2nd floor.
  7. It picks up person #2.
  8. Then it goes to the 3rd floor.
  9. Person #2 goes out.
  10. Then it goes to the 4th floor, where person #3 goes out.
  11. The elevator goes back to the 1st floor.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  int a[3000];
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    a[i]--;
  }
  sort(a, a + n);
  int ans = 0;
  int i;
  for (i = n - 1; i >= 0; i -= k) {
    ans += a[i] * 2;
  }
  printf("%d\n", ans);
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

A permutation is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. Let's denote the i-th element of permutation p as pi. We'll call number n the size of permutation p1, p2, ..., pn.

Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation p that for any i (1 ≤ i ≤ n) (n is the permutation size) the following equations hold ppi = i and pi ≠ i. Nickolas asks you to print any perfect permutation of size n for the given n.

Input

A single line contains a single integer n (1 ≤ n ≤ 100) — the permutation size.

Output

If a perfect permutation of size n doesn't exist, print a single integer -1. Otherwise print n distinct integers from 1 to n, p1, p2, ..., pn — permutation p, that is perfect. Separate printed numbers by whitespaces.

Examples

Input

1

Output

-1

Input

2

Output

2 1

Input

4

Output

2 1 4 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x7f7f7f7f;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  ;
  long long n;
  cin >> n;
  if (n & 1) {
    cout << "-1" << endl;
    return 0;
  }
  for (long long i = 0; i < n; i += 2) {
    cout << i + 2 << " " << i + 1 << " ";
  }
  cout << endl;
  return 0;
}

```


### Prompt

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

There are n points marked on the plane. The points are situated in such a way that they form a regular polygon (marked points are its vertices, and they are numbered in counter-clockwise order). You can draw n - 1 segments, each connecting any two marked points, in such a way that all points have to be connected with each other (directly or indirectly).

But there are some restrictions. Firstly, some pairs of points cannot be connected directly and have to be connected undirectly. Secondly, the segments you draw must not intersect in any point apart from the marked points (that is, if any two segments intersect and their intersection is not a marked point, then the picture you have drawn is invalid).

How many ways are there to connect all vertices with n - 1 segments? Two ways are considered different iff there exist some pair of points such that a segment is drawn between them in the first way of connection, but it is not drawn between these points in the second one. Since the answer might be large, output it modulo 109 + 7.

Input

The first line contains one number n (3 ≤ n ≤ 500) — the number of marked points.

Then n lines follow, each containing n elements. ai, j (j-th element of line i) is equal to 1 iff you can connect points i and j directly (otherwise ai, j = 0). It is guaranteed that for any pair of points ai, j = aj, i, and for any point ai, i = 0.

Output

Print the number of ways to connect points modulo 109 + 7.

Examples

Input

3
0 0 1
0 0 1
1 1 0

Output

1

Input

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

Output

12

Input

3
0 0 0
0 0 1
0 1 0

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a[550][550];
long long f[550][550], g[550][550];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
  for (int i = 1; i <= n; i++) f[i][i] = 1;
  for (int l = 1; l < n; l++)
    for (int i = 1; i + l <= n; i++) {
      int j = i + l;
      for (int k = i; k <= j; k++) {
        if (k < j && a[i][j])
          f[i][j] = (f[i][j] + (f[i][k] + g[i][k]) % 1000000007 *
                                   ((f[k + 1][j] + g[k + 1][j]) % 1000000007) %
                                   1000000007) %
                    1000000007;
        if (k > i && k < j && a[j][k])
          g[i][j] = (g[i][j] +
                     (f[i][k] + g[i][k]) % 1000000007 * f[k][j] % 1000000007) %
                    1000000007;
      }
    }
  printf("%I64d\n", (f[1][n] + g[1][n]) % 1000000007);
  return 0;
}

```


### Prompt

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

qd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf.

Input

jxu ydfkj sediyiji ev q iydwbu ydjuwuh d (1 ≤ d ≤ 11184) — jxu edu-rqiut ydtun ev jxu ucyhf je vydt.

Output

ekjfkj q iydwbu dkcruh.

Examples

Input

1

Output

13

### Response

```cpp
#include <bits/stdc++.h>
int diri[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dirj[] = {0, 1, 0, -1, 1, 1, -1, -1};
int compare(double d1, double d2) {
  if (fabs(d1 - d2) < 1e-9) return 0;
  if (d1 < d2) return -1;
  return 1;
}
using namespace std;
const int maxPrime = 1000001;
bool isPrime[maxPrime];
void sievePrime() {
  memset(isPrime, 1, sizeof(isPrime));
  int i, j;
  isPrime[0] = isPrime[1] = 0;
  for (i = 2; i * i <= maxPrime; i++) {
    if (isPrime[i])
      for (j = i * i; j < maxPrime; j += i) {
        isPrime[j] = 0;
      }
  }
}
int main() {
  int n;
  cin >> n;
  sievePrime();
  vector<int> ans;
  vector<int> prim;
  for (int i = 0; i < (int)maxPrime; i++) {
    if (isPrime[i]) {
      prim.push_back(i);
    }
  }
  for (int i = 0; i < (int)prim.size(); i++) {
    stringstream ss;
    string s;
    int t;
    ss << prim[i];
    ss >> s;
    reverse(s.begin(), s.end());
    stringstream tt(s);
    tt >> t;
    if (t != prim[i] && isPrime[t]) {
      ans.push_back(prim[i]);
    }
  }
  n--;
  cout << ans[n] << endl;
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

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

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

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

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

Can you help him?

Input

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

Output

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

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

Examples

Input

3 1

Output

1 1

Input

2 3

Output

2 0

Input

7 3

Output

3 2

Note

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

### Response

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

```


### Prompt

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

Vasya is choosing a laptop. The shop has n laptops to all tastes.

Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties.

If all three properties of a laptop are strictly less than those properties of some other laptop, then the first laptop is considered outdated by Vasya. Among all laptops Vasya does not consider outdated, he chooses the cheapest one.

There are very many laptops, which is why Vasya decided to write a program that chooses the suitable laptop. However, Vasya doesn't have his own laptop yet and he asks you to help him.

Input

The first line contains number n (1 ≤ n ≤ 100).

Then follow n lines. Each describes a laptop as speed ram hdd cost. Besides,

  * speed, ram, hdd and cost are integers
  * 1000 ≤ speed ≤ 4200 is the processor's speed in megahertz
  * 256 ≤ ram ≤ 4096 the RAM volume in megabytes
  * 1 ≤ hdd ≤ 500 is the HDD in gigabytes
  * 100 ≤ cost ≤ 1000 is price in tugriks

All laptops have different prices.

Output

Print a single number — the number of a laptop Vasya will choose. The laptops are numbered with positive integers from 1 to n in the order in which they are given in the input data.

Examples

Input

5
2100 512 150 200
2000 2048 240 350
2300 1024 200 320
2500 2048 80 300
2000 512 180 150

Output

4

Note

In the third sample Vasya considers the first and fifth laptops outdated as all of their properties cannot match those of the third laptop. The fourth one is the cheapest among the laptops that are left. Thus, Vasya chooses the fourth laptop.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, k, m, i, j, a[1100], speed[1001], ram[1001], hdd[1001], cost[1001];
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) cin >> speed[i] >> ram[i] >> hdd[i] >> cost[i];
  for (i = 1; i <= n; i++)
    if (a[i] == 0)
      for (j = 1; j <= n; j++)
        if (i != j && a[j] == 0) {
          if (speed[i] > speed[j] && ram[i] > ram[j] && hdd[i] > hdd[j])
            a[j] = 1;
          if (speed[i] < speed[j] && ram[i] < ram[j] && hdd[i] < hdd[j]) {
            a[i] = 1;
            break;
          }
        }
  k = 10000;
  m = 1;
  for (i = 1; i <= n; i++)
    if (a[i] == 0 && k > cost[i]) {
      k = cost[i];
      m = i;
    }
  cout << endl << m;
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Vasya has a tree consisting of n vertices with root in vertex 1. At first all vertices has 0 written on it.

Let d(i, j) be the distance between vertices i and j, i.e. number of edges in the shortest path from i to j. Also, let's denote k-subtree of vertex x — set of vertices y such that next two conditions are met:

  * x is the ancestor of y (each vertex is the ancestor of itself);
  * d(x, y) ≤ k.

Vasya needs you to process m queries. The i-th query is a triple v_i, d_i and x_i. For each query Vasya adds value x_i to each vertex from d_i-subtree of v_i.

Report to Vasya all values, written on vertices of the tree after processing all queries.

Input

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

Each of next n - 1 lines contains two integers x and y (1 ≤ x, y ≤ n) — edge between vertices x and y. It is guarantied that given graph is a tree.

Next line contains single integer m (1 ≤ m ≤ 3 ⋅ 10^5) — number of queries.

Each of next m lines contains three integers v_i, d_i, x_i (1 ≤ v_i ≤ n, 0 ≤ d_i ≤ 10^9, 1 ≤ x_i ≤ 10^9) — description of the i-th query.

Output

Print n integers. The i-th integers is the value, written in the i-th vertex after processing all queries.

Examples

Input

5
1 2
1 3
2 4
2 5
3
1 1 1
2 0 10
4 10 100

Output

1 11 1 100 0

Input

5
2 3
2 1
5 4
3 4
5
2 0 4
3 10 1
1 2 3
2 3 10
1 1 7

Output

10 24 14 11 11

Note

In the first exapmle initial values in vertices are 0, 0, 0, 0, 0. After the first query values will be equal to 1, 1, 1, 0, 0. After the second query values will be equal to 1, 11, 1, 0, 0. After the third query values will be equal to 1, 11, 1, 100, 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void update(vector<long long int>& arr, int s, int e,
            vector<long long int>& segment, int sind, int ind,
            long long int val) {
  if (s == e) {
    arr[ind] += val;
    segment[sind] += val;
  } else {
    int m = (s + e) / 2;
    if (ind <= m) {
      update(arr, s, m, segment, 2 * sind + 1, ind, val);
    } else {
      update(arr, m + 1, e, segment, 2 * sind + 2, ind, val);
    }
    segment[sind] = segment[2 * sind + 1] + segment[2 * sind + 2];
  }
}
long long int query(vector<long long int>& arr, int s, int e,
                    vector<long long int>& segment, int sind, int l, int r) {
  if (l > r) return 0LL;
  if (s == l && e == r) return segment[sind];
  int m = (s + e) / 2;
  long long int left = query(arr, s, m, segment, 2 * sind + 1, l, min(m, r));
  long long int right =
      query(arr, m + 1, e, segment, 2 * sind + 2, max(m + 1, l), r);
  return left + right;
}
void traverse(int u, vector<vector<int>>& adj, vector<int>& visit,
              vector<vector<pair<int, int>>>& queries,
              vector<long long int>& vals, int d, vector<long long int>& arr,
              vector<long long int>& seg) {
  visit[u] = 1;
  int n = adj.size();
  for (int i = 0; i < queries[u].size(); i++) {
    update(arr, 0, n - 1, seg, 0, min(n - 1, d + queries[u][i].first),
           queries[u][i].second);
  }
  vals[u] = query(arr, 0, n - 1, seg, 0, d, n - 1);
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (visit[v] == 0) {
      traverse(v, adj, visit, queries, vals, d + 1, arr, seg);
    }
  }
  for (int i = 0; i < queries[u].size(); i++) {
    update(arr, 0, n - 1, seg, 0, min(n - 1, d + queries[u][i].first),
           -1 * queries[u][i].second);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<long long int> arr(n, 0), segment(4 * n, 0);
  vector<vector<int>> adj(n, vector<int>());
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    adj[a - 1].push_back(b - 1);
    adj[b - 1].push_back(a - 1);
  }
  vector<vector<pair<int, int>>> queries(n, vector<pair<int, int>>());
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int v, d, x;
    cin >> v >> d >> x;
    queries[v - 1].push_back({d, x});
  }
  vector<int> visit(n, 0);
  vector<long long int> values(n, 0);
  traverse(0, adj, visit, queries, values, 0, arr, segment);
  for (auto val : values) cout << val << " ";
  cout << endl;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month).

Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year.

Nastya owns x dresses now, so she became interested in the [expected number](https://en.wikipedia.org/wiki/Expected_value) of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months.

Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer.

Input

The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland.

Output

In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7.

Examples

Input

2 0

Output

4

Input

2 1

Output

7

Input

3 2

Output

21

Note

In the first example a year consists on only one month, so the wardrobe does not eat dresses at all.

In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, int p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long x, k, h, ans;
  cin >> x >> k;
  int p = 1000000007;
  h = power(2, k, p);
  ans = (((h % p * (2 * (x % p) - 1 % p) % p + p) % p) % p + 1) % p;
  if (x == 0)
    cout << 0 << endl;
  else
    cout << ans << endl;
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Arthur and Alexander are number busters. Today they've got a competition.

Arthur took a group of four integers a, b, w, x (0 ≤ b < w, 0 < x < w) and Alexander took integer с. Arthur and Alexander use distinct approaches to number bustings. Alexander is just a regular guy. Each second, he subtracts one from his number. In other words, he performs the assignment: c = c - 1. Arthur is a sophisticated guy. Each second Arthur performs a complex operation, described as follows: if b ≥ x, perform the assignment b = b - x, if b < x, then perform two consecutive assignments a = a - 1; b = w - (x - b).

You've got numbers a, b, w, x, c. Determine when Alexander gets ahead of Arthur if both guys start performing the operations at the same time. Assume that Alexander got ahead of Arthur if c ≤ a.

Input

The first line contains integers a, b, w, x, c (1 ≤ a ≤ 2·109, 1 ≤ w ≤ 1000, 0 ≤ b < w, 0 < x < w, 1 ≤ c ≤ 2·109).

Output

Print a single integer — the minimum time in seconds Alexander needs to get ahead of Arthur. You can prove that the described situation always occurs within the problem's limits.

Examples

Input

4 2 3 1 6

Output

2

Input

4 2 3 1 7

Output

4

Input

1 2 3 2 6

Output

13

Input

1 1 2 1 1

Output

0

### Response

```cpp
#include <bits/stdc++.h>
int t[10001];
int C[10001];
int v[10001];
int a, b, x, w, c, times, st;
bool check(long long x) {
  long long y = x / (times - st);
  x = x % (times - st);
  long long z = a - y * (C[times] - C[st]), zz = c - y * (times - st);
  if (zz <= z) return true;
  for (int i = 1; i <= x; ++i) {
    if (C[st + i] != C[st + i - 1]) --z;
    --zz;
    if (zz <= z) return true;
  }
  return false;
}
int main() {
  scanf("%d%d%d%d%d", &a, &b, &w, &x, &c);
  int bb = b;
  v[b] = 1;
  t[1] = b;
  for (times = 2;; ++times) {
    if (bb >= x)
      bb -= x, C[times] = C[times - 1];
    else
      bb = w - (x - bb), C[times] = C[times - 1] + 1;
    t[times] = bb;
    if (!v[bb])
      v[bb] = times;
    else {
      st = v[bb];
      break;
    }
  }
  for (int i = 1; i < times; ++i) {
    if (c <= a) {
      printf("%d\n", i - 1);
      return 0;
    }
    if (b >= x)
      b -= x;
    else
      --a, b = w - (x - b);
    --c;
  }
  if (c <= a) {
    printf("%d\n", times - 1);
    return 0;
  }
  long long lans = 0, rans = ~0ULL >> 2;
  while (lans + 1 != rans) {
    long long mid = (lans + rans) / 2;
    if (check(mid))
      rans = mid;
    else
      lans = mid;
  }
  std::cout << lans + times << std::endl;
  return 0;
}

```


### Prompt

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

On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on which a square mesh is marked. They use only a single stone. The purpose of the game is to lead the stone from the start to the goal with the minimum number of moves.

Fig. D-1 shows an example of a game board. Some squares may be occupied with blocks. There are two special squares namely the start and the goal, which are not occupied with blocks. (These two squares are distinct.) Once the stone begins to move, it will proceed until it hits a block. In order to bring the stone to the goal, you may have to stop the stone by hitting it against a block, and throw again.

<image>
Fig. D-1: Example of board (S: start, G: goal)

The movement of the stone obeys the following rules:

* At the beginning, the stone stands still at the start square.
* The movements of the stone are restricted to x and y directions. Diagonal moves are prohibited.
* When the stone stands still, you can make it moving by throwing it. You may throw it to any direction unless it is blocked immediately(Fig. D-2(a)).
* Once thrown, the stone keeps moving to the same direction until one of the following occurs:
* The stone hits a block (Fig. D-2(b), (c)).
* The stone stops at the square next to the block it hit.
* The block disappears.
* The stone gets out of the board.
* The game ends in failure.
* The stone reaches the goal square.
* The stone stops there and the game ends in success.
* You cannot throw the stone more than 10 times in a game. If the stone does not reach the goal in 10 moves, the game ends in failure.

<image>
Fig. D-2: Stone movements

Under the rules, we would like to know whether the stone at the start can reach the goal and, if yes, the minimum number of moves required.

With the initial configuration shown in Fig. D-1, 4 moves are required to bring the stone from the start to the goal. The route is shown in Fig. D-3(a). Notice when the stone reaches the goal, the board configuration has changed as in Fig. D-3(b).

<image>
Fig. D-3: The solution for Fig. D-1 and the final board configuration

Input

The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. The number of datasets never exceeds 100.

Each dataset is formatted as follows.

> the width(=w) and the height(=h) of the board
>  First row of the board
>  ...
>  h-th row of the board
>

The width and the height of the board satisfy: 2 <= w <= 20, 1 <= h <= 20.
Each line consists of w decimal numbers delimited by a space. The number describes the status of the corresponding square.

> 0 | vacant square
> ---|---
> 1 | block
> 2 | start position
> 3 | goal position

The dataset for Fig. D-1 is as follows:

> 6 6
>  1 0 0 2 1 0
>  1 1 0 0 0 0
>  0 0 0 0 0 3
>  0 0 0 0 0 0
>  1 0 0 0 0 1
>  0 1 1 1 1 1
>

Output

For each dataset, print a line having a decimal integer indicating the minimum number of moves along a route from the start to the goal. If there are no such routes, print -1 instead. Each line should not have any character other than this number.

Example

Input

2 1
3 2
6 6
1 0 0 2 1 0
1 1 0 0 0 0
0 0 0 0 0 3
0 0 0 0 0 0
1 0 0 0 0 1
0 1 1 1 1 1
6 1
1 1 2 1 1 3
6 1
1 0 2 1 1 3
12 1
2 0 1 1 1 1 1 1 1 1 1 3
13 1
2 0 1 1 1 1 1 1 1 1 1 1 3
0 0

Output

1
4
-1
4
10
-1

### Response

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

int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

#define INF (1<<24)

int f[30][30],W,H;

int dfs(int x, int y, int c, bool gf)
{
	if(gf) return c;
	if(c>=10) return INF;

	int ret=INF;
	for(int i=0; i<4; i++)
	{
		int tx=x, ty=y;
		bool gf=false;
		while(1)
		{
			tx+=dx[i], ty+=dy[i];
			if(tx<0||ty<0||tx>=W||ty>=H) break;
			if(f[tx][ty]==3) gf=1;
			if(f[tx][ty]==1) break;
		}

		if(gf)
		{
			ret=min(ret, dfs(tx,ty,c+1,gf));
		}
		else
		{
			if(tx<0||ty<0||tx>=W||ty>=H) continue;
			if(x==tx-dx[i]&&y==ty-dy[i]) continue;
			f[tx][ty]=0;
			tx-=dx[i], ty-=dy[i];

			ret=min(ret, dfs(tx,ty,c+1,gf));

			tx+=dx[i], ty+=dy[i];

			f[tx][ty]=1;
		}
	}

	return ret;
}

int main()
{

	while(cin >> W >> H, (W||H))
	{
		int sx,sy;
		for(int i=0; i<H; i++)
		for(int j=0; j<W; j++)
		{
			cin >> f[j][i];
			if(f[j][i]==2)
			{
				sx=j;
				sy=i;
			}
		}

		int ret=dfs(sx,sy,0,0);
		cout << (ret==INF?-1:ret) << endl;
	}
}
```


### Prompt

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

There are n seats in the train's car and there is exactly one passenger occupying every seat. The seats are numbered from 1 to n from left to right. The trip is long, so each passenger will become hungry at some moment of time and will go to take boiled water for his noodles. The person at seat i (1 ≤ i ≤ n) will decide to go for boiled water at minute t_i.

Tank with a boiled water is located to the left of the 1-st seat. In case too many passengers will go for boiled water simultaneously, they will form a queue, since there can be only one passenger using the tank at each particular moment of time. Each passenger uses the tank for exactly p minutes. We assume that the time it takes passengers to go from their seat to the tank is negligibly small.

Nobody likes to stand in a queue. So when the passenger occupying the i-th seat wants to go for a boiled water, he will first take a look on all seats from 1 to i - 1. In case at least one of those seats is empty, he assumes that those people are standing in a queue right now, so he would be better seating for the time being. However, at the very first moment he observes that all seats with numbers smaller than i are busy, he will go to the tank.

There is an unspoken rule, that in case at some moment several people can go to the tank, than only the leftmost of them (that is, seating on the seat with smallest number) will go to the tank, while all others will wait for the next moment.

Your goal is to find for each passenger, when he will receive the boiled water for his noodles.

Input

The first line contains integers n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 10^9) — the number of people and the amount of time one person uses the tank.

The second line contains n integers t_1, t_2, ..., t_n (0 ≤ t_i ≤ 10^9) — the moments when the corresponding passenger will go for the boiled water.

Output

Print n integers, where i-th of them is the time moment the passenger on i-th seat will receive his boiled water.

Example

Input

5 314
0 310 942 628 0

Output

314 628 1256 942 1570

Note

Consider the example.

At the 0-th minute there were two passengers willing to go for a water, passenger 1 and 5, so the first passenger has gone first, and returned at the 314-th minute. At this moment the passenger 2 was already willing to go for the water, so the passenger 2 has gone next, and so on. In the end, 5-th passenger was last to receive the boiled water.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return x * f;
}
void write(long long x) {
  if (x < 0)
    putchar('-'), write(-x);
  else {
    if (x >= 10) write(x / 10);
    putchar(x % 10 + '0');
  }
}
const long long N = 600010, mod = 1e9 + 7;
bool operator<(pair<long long, long long> a, pair<long long, long long> b) {
  return a.first < b.first;
}
multiset<long long> q1;
multiset<long long>::iterator it;
priority_queue<long long, vector<long long>, greater<long long> > q2;
long long n, p, t[N], id[N], ans[N], q[N], he, ta;
bool cmp(long long a, long long b) {
  if (t[a] == t[b]) return a < b;
  return t[a] < t[b];
}
int main() {
  n = read();
  p = read();
  for (long long i = (1); i <= (n); ++i) t[i] = read(), id[i] = i;
  sort(id + 1, id + n + 1, cmp);
  long long pos = 0, now = 0;
  for (;;) {
    if (he == ta) {
      if (ta == n) break;
      ++pos;
      now = t[id[pos]];
      q[++ta] = id[pos];
      q1.insert(id[pos]);
    }
    long long x = q[++he], cur = x;
    ans[x] = now + p;
    now += p;
    it = q1.lower_bound(x);
    q1.erase(it);
    for (; (pos < n) && (t[id[pos + 1]] <= now);) {
      it = q1.begin();
      if (((it != q1.end()) && ((*it) < id[pos + 1])) || (cur < id[pos + 1])) {
        ++pos;
        q2.push(id[pos]);
      } else {
        ++pos;
        q1.insert(id[pos]);
        q[++ta] = id[pos];
      }
    }
    for (; (!q2.empty()) && ((he == ta) || ((q2.top() < (*q1.begin()))));) {
      x = q2.top();
      q2.pop();
      q[++ta] = x;
      q1.insert(x);
    }
  }
  for (long long i = (1); i <= (n); ++i) write(ans[i]), putchar(' ');
}

```


### Prompt

Create a solution in Cpp for the following problem:

While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1 to n, not necessarily distinct. Then he picked some sequence f1, f2, ..., fn of length n and for each number ai got number bi = fai. To finish the prank he erased the initial sequence ai.

It's hard to express how sad Patrick was when he returned home from shopping! We will just say that Spongebob immediately got really sorry about what he has done and he is now trying to restore the original sequence. Help him do this or determine that this is impossible.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100 000) — the lengths of sequences fi and bi respectively.

The second line contains n integers, determining sequence f1, f2, ..., fn (1 ≤ fi ≤ n).

The last line contains m integers, determining sequence b1, b2, ..., bm (1 ≤ bi ≤ n).

Output

Print "Possible" if there is exactly one sequence ai, such that bi = fai for all i from 1 to m. Then print m integers a1, a2, ..., am.

If there are multiple suitable sequences ai, print "Ambiguity".

If Spongebob has made a mistake in his calculations and no suitable sequence ai exists, print "Impossible".

Examples

Input

3 3
3 2 1
1 2 3

Output

Possible
3 2 1

Input

3 3
1 1 1
1 1 1

Output

Ambiguity

Input

3 3
1 2 1
3 3 3

Output

Impossible

Note

In the first sample 3 is replaced by 1 and vice versa, while 2 never changes. The answer exists and is unique.

In the second sample all numbers are replaced by 1, so it is impossible to unambiguously restore the original sequence.

In the third sample fi ≠ 3 for all i, so no sequence ai transforms into such bi and we can say for sure that Spongebob has made a mistake.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int b[100000], f[100000], a[100000], d[100000 + 1];
int main() {
  int n, m;
  while (cin >> n >> m) {
    for (int i = 0; i < n; ++i) cin >> f[i];
    for (int i = 0; i < m; ++i) cin >> b[i];
    memset(d, 0, sizeof(d));
    for (int i = 0; i < n; ++i) {
      if (d[f[i]] != 0)
        d[f[i]] = -1;
      else
        d[f[i]] = i + 1;
    }
    int ok = 1;
    for (int i = 0; i < m; ++i) {
      if (d[b[i]] < 0) {
        ok = -1;
      } else if (!d[b[i]]) {
        ok = 0;
        break;
      }
      a[i] = d[b[i]];
    }
    if (ok < 0) {
      cout << "Ambiguity" << endl;
    } else if (!ok) {
      cout << "Impossible" << endl;
    } else {
      cout << "Possible" << endl;
      cout << a[0];
      for (int i = 1; i < m; ++i) {
        cout << " " << a[i];
      }
      cout << endl;
    }
  }
  return 0;
}

```