### Prompt

Please formulate a CPP solution to the following problem:

Medicine faculty of Berland State University has just finished their admission campaign. As usual, about 80\% of applicants are girls and majority of them are going to live in the university dormitory for the next 4 (hopefully) years.

The dormitory consists of n rooms and a single mouse! Girls decided to set mouse traps in some rooms to get rid of the horrible monster. Setting a trap in room number i costs c_i burles. Rooms are numbered from 1 to n.

Mouse doesn't sit in place all the time, it constantly runs. If it is in room i in second t then it will run to room a_i in second t + 1 without visiting any other rooms inbetween (i = a_i means that mouse won't leave room i). It's second 0 in the start. If the mouse is in some room with a mouse trap in it, then the mouse get caught into this trap.

That would have been so easy if the girls actually knew where the mouse at. Unfortunately, that's not the case, mouse can be in any room from 1 to n at second 0.

What it the minimal total amount of burles girls can spend to set the traps in order to guarantee that the mouse will eventually be caught no matter the room it started from?

Input

The first line contains as single integers n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of rooms in the dormitory.

The second line contains n integers c_1, c_2, ..., c_n (1 ≤ c_i ≤ 10^4) — c_i is the cost of setting the trap in room number i.

The third line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — a_i is the room the mouse will run to the next second after being in room i.

Output

Print a single integer — the minimal total amount of burles girls can spend to set the traps in order to guarantee that the mouse will eventually be caught no matter the room it started from.

Examples

Input

5
1 2 3 2 10
1 3 4 3 3

Output

3

Input

4
1 10 2 10
2 4 2 2

Output

10

Input

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

Output

2

Note

In the first example it is enough to set mouse trap in rooms 1 and 4. If mouse starts in room 1 then it gets caught immideately. If mouse starts in any other room then it eventually comes to room 4.

In the second example it is enough to set mouse trap in room 2. If mouse starts in room 2 then it gets caught immideately. If mouse starts in any other room then it runs to room 2 in second 1.

Here are the paths of the mouse from different starts from the third example:

  * 1 → 2 → 2 → ...;
  * 2 → 2 → ...;
  * 3 → 2 → 2 → ...;
  * 4 → 3 → 2 → 2 → ...;
  * 5 → 6 → 7 → 6 → ...;
  * 6 → 7 → 6 → ...;
  * 7 → 6 → 7 → ...;

So it's enough to set traps in rooms 2 and 6.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool cmp(const pair<long long, long long> &a,
         const pair<long long, long long> &b) {
  return (a.first > b.first);
}
long long power(long long x, long long y) {
  long long res = 1;
  x = x;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long power2(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long n, a[200010], c[200010], vis[200010], ans;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> c[i];
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) {
    long long x = i, v, mn;
    while (!vis[x]) {
      vis[x] = i;
      x = a[x];
    }
    if (vis[x] != i) continue;
    v = x;
    mn = c[x];
    while (a[x] != v) {
      x = a[x];
      mn = min(mn, c[x]);
    };
    ans += mn;
  }
  cout << ans;
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Snuke found a record of a tree with N vertices in ancient ruins. The findings are as follows:

* The vertices of the tree were numbered 1,2,...,N, and the edges were numbered 1,2,...,N-1.
* Edge i connected Vertex a_i and b_i.
* The length of each edge was an integer between 1 and 10^{18} (inclusive).
* The sum of the shortest distances from Vertex i to Vertex 1,...,N was s_i.

From the information above, restore the length of each edge. The input guarantees that it is possible to determine the lengths of the edges consistently with the record. Furthermore, it can be proved that the length of each edge is uniquely determined in such a case.

Constraints

* 2 \leq N \leq 10^{5}
* 1 \leq a_i,b_i \leq N
* 1 \leq s_i \leq 10^{18}
* The given graph is a tree.
* All input values are integers.
* It is possible to consistently restore the lengths of the edges.
* In the restored graph, the length of each edge is an integer between 1 and 10^{18} (inclusive).

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
:
a_{N-1} b_{N-1}
s_1 s_2 ... s_{N}

Output

Print N-1 lines. The i-th line must contain the length of Edge i.

Examples

Input

4
1 2
2 3
3 4
8 6 6 8

Output

1
2
1

Input

5
1 2
1 3
1 4
1 5
10 13 16 19 22

Output

1
2
3
4

Input

15
9 10
9 15
15 4
4 13
13 2
13 11
2 14
13 6
11 1
1 12
12 3
12 7
2 5
14 8
1154 890 2240 883 2047 2076 1590 1104 1726 1791 1091 1226 841 1000 901

Output

5
75
2
6
7
50
10
95
9
8
78
28
89
8

### Response

```cpp
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#define SIZE 100005

using namespace std;
typedef long long int ll;

struct edge
{
	int to,id;
	edge(int to=0,int id=0):to(to),id(id){}
};
vector <edge> vec[SIZE];
int nd[SIZE];
int A[SIZE],B[SIZE];
ll C[SIZE];
ll sum[SIZE];
ll all;

void dfs(int v=0,int p=-1)
{
	nd[v]=1;
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i].to;
		if(to!=p)
		{
			dfs(to,v);
			nd[v]+=nd[to];
		}
	}
}
void dfs2(int v=0,int p=-1,ll d=0)
{
	all+=d;
	for(int i=0;i<vec[v].size();i++)
	{
		edge e=vec[v][i];
		if(e.to!=p)
		{
			dfs2(e.to,v,d+C[e.id]);
		}
	}
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n-1;i++)
	{
		scanf("%d %d",&A[i],&B[i]);
		A[i]--,B[i]--;
		vec[A[i]].push_back(edge(B[i],i));
		vec[B[i]].push_back(edge(A[i],i));
		C[i]=-1;
	}
	for(int i=0;i<n;i++) scanf("%lld",&sum[i]);
	dfs();
	int a=-1,b=-1;
	for(int i=0;i<n-1;i++)
	{
		if(nd[A[i]]<nd[B[i]]) swap(A[i],B[i]);
		//A[i] : parent of B[i]
		if(sum[A[i]]!=sum[B[i]])
		{
			//A[i]=a+b+nd[b]*C[i]
			//B[i]=a+b+(n-nd[b])*C[i]
			C[i]=(sum[A[i]]-sum[B[i]])/(ll) (2*nd[B[i]]-n);
		}
		else
		{
			a=A[i];
			b=B[i];
		}
	}
	if(a!=-1)
	{
		all=0;
		dfs2(b,a,0);
		dfs2(a,b,0);
		for(int i=0;i<n-1;i++)
		{
			if(C[i]==-1)
			{
				C[i]=(sum[A[i]]-all)/(ll) nd[B[i]];
			}
		}
	}
	for(int i=0;i<n-1;i++) printf("%lld\n",C[i]);
	return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Note that the difference between easy and hard versions is that in hard version unavailable cells can become available again and in easy version can't. You can make hacks only if all versions are solved.

Ildar and Ivan are tired of chess, but they really like the chessboard, so they invented a new game. The field is a chessboard 2n × 2m: it has 2n rows, 2m columns, and the cell in row i and column j is colored white if i+j is even, and is colored black otherwise.

The game proceeds as follows: Ildar marks some of the white cells of the chessboard as unavailable, and asks Ivan to place n × m kings on the remaining white cells in such way, so that there are no kings attacking each other. A king can attack another king if they are located in the adjacent cells, sharing an edge or a corner.

Ildar would like to explore different combinations of cells. Initially all cells are marked as available, and then he has q queries. In each query he marks a cell as unavailable. After each query he would like to know whether it is possible to place the kings on the available cells in a desired way. Please help him!

Input

The first line of input contains three integers n, m, q (1 ≤ n, m, q ≤ 200 000) — the size of the board and the number of queries.

q lines follow, each of them contains a description of a query: two integers i and j, denoting a white cell (i, j) on the board (1 ≤ i ≤ 2n, 1 ≤ j ≤ 2m, i + j is even) that becomes unavailable. It's guaranteed, that each cell (i, j) appears in input at most once.

Output

Output q lines, i-th line should contain answer for a board after i queries of Ildar. This line should contain "YES" if it is possible to place the kings on the available cells in the desired way, or "NO" otherwise.

Examples

Input

1 3 3
1 1
1 5
2 4

Output

YES
YES
NO

Input

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

Output

YES
YES
NO
NO
NO
NO
NO

Note

In the first example case after the second query only cells (1, 1) and (1, 5) are unavailable. Then Ivan can place three kings on cells (2, 2), (2, 4) and (2, 6).

After the third query three cells (1, 1), (1, 5) and (2, 4) are unavailable, so there remain only 3 available cells: (2, 2), (1, 3) and (2, 6). Ivan can not put 3 kings on those cells, because kings on cells (2, 2) and (1, 3) attack each other, since these cells share a corner.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
set<int> stl[maxn], str[maxn];
map<pair<int, int>, int> mp;
int n, m, q;
namespace Segtree {
int mx[maxn << 2], mi[maxn << 2], eleg[maxn << 2];
void pushup(int o) {
  int lch = o * 2, rch = o * 2 + 1;
  mx[o] = max(mx[lch], mx[rch]);
  mi[o] = min(mi[lch], mi[rch]);
  eleg[o] = (eleg[lch] | eleg[rch]);
  eleg[o] |= (mx[rch] >= mi[lch]);
  return;
}
void build(int o, int L, int R) {
  int lch = o * 2, rch = o * 2 + 1;
  if (L == R) {
    mx[o] = 0;
    mi[o] = m + 1;
    eleg[o] = 0;
    return;
  }
  int mid = (L + R) / 2;
  build(lch, L, mid);
  build(rch, mid + 1, R);
  pushup(o);
}
void update(int o, int L, int R, int pos) {
  int lch = o * 2, rch = o * 2 + 1;
  if (L == R) {
    if (str[L].empty())
      mx[o] = 0;
    else
      mx[o] = *str[L].rbegin();
    if (stl[L].empty())
      mi[o] = m + 1;
    else
      mi[o] = *stl[L].begin();
    eleg[o] = (mx[o] >= mi[o] ? 1 : 0);
    return;
  }
  int mid = (L + R) / 2;
  if (pos <= mid)
    update(lch, L, mid, pos);
  else
    update(rch, mid + 1, R, pos);
  pushup(o);
  return;
}
};  // namespace Segtree
using namespace Segtree;
int main() {
  scanf("%d%d%d", &n, &m, &q);
  build(1, 1, n);
  while (q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    ++x;
    x /= 2;
    ++y;
    if (y & 1) {
      if (str[x].count(y / 2))
        str[x].erase(y / 2);
      else
        str[x].insert(y / 2);
    } else {
      if (stl[x].count(y / 2))
        stl[x].erase(y / 2);
      else
        stl[x].insert(y / 2);
    }
    update(1, 1, n, x);
    printf("%s\n", eleg[1] ? "NO" : "YES");
  }
  return 0;
}

```


### Prompt

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

Piet is one of the most known visual esoteric programming languages. The programs in Piet are constructed from colorful blocks of pixels and interpreted using pretty complicated rules. In this problem we will use a subset of Piet language with simplified rules.

The program will be a rectangular image consisting of colored and black pixels. The color of each pixel will be given by an integer number between 0 and 9, inclusive, with 0 denoting black. A block of pixels is defined as a rectangle of pixels of the same color (not black). It is guaranteed that all connected groups of colored pixels of the same color will form rectangular blocks. Groups of black pixels can form arbitrary shapes.

The program is interpreted using movement of instruction pointer (IP) which consists of three parts:

  * current block pointer (BP); note that there is no concept of current pixel within the block;
  * direction pointer (DP) which can point left, right, up or down;
  * block chooser (CP) which can point to the left or to the right from the direction given by DP; in absolute values CP can differ from DP by 90 degrees counterclockwise or clockwise, respectively.

Initially BP points to the block which contains the top-left corner of the program, DP points to the right, and CP points to the left (see the orange square on the image below).

One step of program interpretation changes the state of IP in a following way. The interpreter finds the furthest edge of the current color block in the direction of the DP. From all pixels that form this edge, the interpreter selects the furthest one in the direction of CP. After this, BP attempts to move from this pixel into the next one in the direction of DP. If the next pixel belongs to a colored block, this block becomes the current one, and two other parts of IP stay the same. It the next pixel is black or outside of the program, BP stays the same but two other parts of IP change. If CP was pointing to the left, now it points to the right, and DP stays the same. If CP was pointing to the right, now it points to the left, and DP is rotated 90 degrees clockwise.

This way BP will never point to a black block (it is guaranteed that top-left pixel of the program will not be black).

You are given a Piet program. You have to figure out which block of the program will be current after n steps.

Input

The first line of the input contains two integer numbers m (1 ≤ m ≤ 50) and n (1 ≤ n ≤ 5·107). Next m lines contain the rows of the program. All the lines have the same length between 1 and 50 pixels, and consist of characters 0-9. The first character of the first line will not be equal to 0.

Output

Output the color of the block which will be current after n steps of program interpretation.

Examples

Input

2 10
12
43

Output

1

Input

3 12
1423
6624
6625

Output

6

Input

5 9
10345
23456
34567
45678
56789

Output

5

Note

In the first example IP changes in the following way. After step 1 block 2 becomes current one and stays it after two more steps. After step 4 BP moves to block 3, after step 7 — to block 4, and finally after step 10 BP returns to block 1.

<image>

The sequence of states of IP is shown on the image: the arrows are traversed clockwise, the main arrow shows direction of DP, the side one — the direction of CP.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char a[55][55];
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int n, T, m;
inline int valid(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }
int cyc[55][55][4][2] = {};
int main(void) {
  scanf("%d%d", &n, &T);
  for (int i = 0; i < n; i++) scanf("%s", a[i]);
  m = strlen(a[0]);
  int x = 0, y = 0, DP = 0, CP = 0;
  int Cx = -dy[DP] * (CP ? -1 : 1), Cy = dx[DP] * (CP ? -1 : 1);
  int Dx = dx[DP], Dy = dy[DP];
  for (int step = 1; step <= T; step++) {
    while (valid(x + Dx, y + Dy) && a[x + Dx][y + Dy] == a[x][y])
      x += Dx, y += Dy;
    while (valid(x + Cx, y + Cy) && a[x + Cx][y + Cy] == a[x][y])
      x += Cx, y += Cy;
    if (cyc[x][y][DP][CP]) {
      int ii = step - cyc[x][y][DP][CP];
      while (step + ii <= T) step += ii;
    } else
      cyc[x][y][DP][CP] = step;
    if (!valid(x + Dx, y + Dy) || a[x + Dx][y + Dy] == '0') {
      if (CP == 0)
        CP = 1;
      else if (CP == 1) {
        DP = (DP + 1) % 4;
        CP = 0;
      }
      Cx = -dy[DP] * (CP ? -1 : 1), Cy = dx[DP] * (CP ? -1 : 1);
      Dx = dx[DP], Dy = dy[DP];
    } else
      x += Dx, y += Dy;
  }
  printf("%c\n", a[x][y]);
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

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

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

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

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

Input

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

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

Output

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

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

See the examples for better understanding.

Examples

Input

3
1 2
1 3

Output

3
2 3 3
2 1 1

Input

5
1 2
1 3
2 4
2 5

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 7;
const long long mod = 1e9 + 9;
const long long INF = 1e9 + 7;
const long long mlog = 21;
const long long SQ = 400;
struct NODE {
  long long a;
  long long b;
  long long c;
};
vector<long long> adj[maxn];
vector<long long> leaves;
long long n;
long long par[mlog][maxn];
long long h[maxn];
long long loss[maxn];
long long vr = 1, ur;
void dfs(long long v, long long pr = -1) {
  for (long long u : adj[v]) {
    if (u != pr) {
      h[u] = h[v] + 1, par[0][u] = v;
      if (h[u] > h[vr]) vr = u;
      dfs(u, v);
    }
  }
}
void pre_process() {
  for (long long j = 1; j < mlog; j++)
    for (long long i = 1; i <= n; i++) par[j][i] = par[j - 1][par[j - 1][i]];
}
long long getpar(long long v, long long l) {
  for (long long j = 0; j < mlog; j++)
    if (l & (1 << j)) v = par[j][v];
  return v;
}
long long LCA(long long u, long long v) {
  if (h[u] < h[v]) swap(u, v);
  u = getpar(u, h[u] - h[v]);
  if (u == v) return v;
  for (long long j = mlog - 1; j >= 0; j--) {
    long long p1 = par[j][u];
    long long p2 = par[j][v];
    if (p1 != p2) u = p1, v = p2;
  }
  return par[0][v];
}
pair<long long, long long> ADD(long long v) {
  long long lcaU = LCA(ur, v);
  long long lcaV = LCA(vr, v);
  return ((h[v] + h[ur] - 2 * h[lcaU] > h[v] + h[vr] - 2 * h[lcaV])
              ? (make_pair(ur, h[v] + h[ur] - 2 * h[lcaU]))
              : make_pair(vr, h[v] + h[vr] - 2 * h[lcaV]));
}
long long mark[maxn];
long long ans = 0;
vector<NODE> path;
void solve() {
  dfs(1);
  h[vr] = 0;
  ur = vr;
  par[0][vr] = 0;
  dfs(vr);
  long long x = vr;
  while (x != 0) {
    mark[x] = true;
    x = par[0][x];
  }
  pre_process();
  for (long long i = 1; i <= n; i++)
    if (adj[i].size() == 1 && !mark[i]) leaves.push_back(i);
  long long i = 0;
  long long m = leaves.size();
  while (i < m) {
    if (leaves[i] == -1) {
      i++;
      continue;
    }
    long long v = leaves[i];
    loss[par[0][v]]++;
    pair<long long, long long> p1 = ADD(v);
    ans += p1.second;
    path.push_back({p1.first, v, v});
    if (!mark[par[0][v]] && adj[par[0][v]].size() - loss[par[0][v]] == 1)
      leaves[i] = par[0][v];
    else
      leaves[i] = -1;
  }
  x = vr;
  while (x != ur) {
    ans += h[x];
    path.push_back({ur, x, x});
    x = par[0][x];
  }
}
int32_t main() {
  long long t = 1;
  while (t--) {
    scanf("%lld", &n);
    for (long long i = 0; i < n - 1; i++) {
      long long u, v;
      scanf("%lld%lld", &u, &v);
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    solve();
    cout << ans << "\n";
    for (auto v : path) printf("%lld %lld %lld\n", v.a, v.b, v.c);
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

The ICPC committee would like to have its meeting as soon as possible to address every little issue of the next contest. However, members of the committee are so busy maniacally developing (possibly useless) programs that it is very difficult to arrange their schedules for the meeting. So, in order to settle the meeting date, the chairperson requested every member to send back a list of convenient dates by E-mail. Your mission is to help the chairperson, who is now dedicated to other issues of the contest, by writing a program that chooses the best date from the submitted lists. Your program should find the date convenient for the most members. If there is more than one such day, the earliest is the best.

Input

The input has multiple data sets, each starting with a line containing the number of committee members and the quorum of the meeting.

> N Q

Here, N, meaning the size of the committee, and Q meaning the quorum, are positive integers. N is less than 50, and, of course, Q is less than or equal to N.

N lines follow, each describing convenient dates for a committee member in the following format.

> M Date1 Date2 ... DateM

Here, M means the number of convenient dates for the member, which is an integer greater than or equal to zero. The remaining items in the line are his/her dates of convenience, which are positive integers less than 100, that is, 1 means tomorrow, 2 means the day after tomorrow, and so on. They are in ascending order without any repetition and separated by a space character. Lines have neither leading nor trailing spaces.

A line containing two zeros indicates the end of the input.

Output

For each data set, print a single line containing the date number convenient for the largest number of committee members. If there is more than one such date, print the earliest. However, if no dates are convenient for more than or equal to the quorum number of members, print 0 instead.

Example

Input

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

Output

4
5
0
2

### Response

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

using namespace std;

#define all(c) (c).begin(), (c).end()

int main(){
    int N, Q;
    while(cin >> N >> Q, N|Q){
        vector<int> date(100); date[0] = Q - 1;
        while(N--){
            int M;
            cin >> M;
            while(M--){
                int d;
                cin >> d;
                date[d]++;
            }
        }
        cout << max_element(all(date)) - date.begin() << '\n';
    }
    return 0;
}
```


### Prompt

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

Breaking Good is a new video game which a lot of gamers want to have. There is a certain level in the game that is really difficult even for experienced gamers.

Walter William, the main character of the game, wants to join a gang called Los Hermanos (The Brothers). The gang controls the whole country which consists of n cities with m bidirectional roads connecting them. There is no road is connecting a city to itself and for any two cities there is at most one road between them. The country is connected, in the other words, it is possible to reach any city from any other city using the given roads.

The roads aren't all working. There are some roads which need some more work to be performed to be completely functioning.

The gang is going to rob a bank! The bank is located in city 1. As usual, the hardest part is to escape to their headquarters where the police can't get them. The gang's headquarters is in city n. To gain the gang's trust, Walter is in charge of this operation, so he came up with a smart plan.

First of all the path which they are going to use on their way back from city 1 to their headquarters n must be as short as possible, since it is important to finish operation as fast as possible.

Then, gang has to blow up all other roads in country that don't lay on this path, in order to prevent any police reinforcements. In case of non-working road, they don't have to blow up it as it is already malfunctional.

If the chosen path has some roads that doesn't work they'll have to repair those roads before the operation.

Walter discovered that there was a lot of paths that satisfied the condition of being shortest possible so he decided to choose among them a path that minimizes the total number of affected roads (both roads that have to be blown up and roads to be repaired).

Can you help Walter complete his task and gain the gang's trust?

Input

The first line of input contains two integers n, m (2 ≤ n ≤ 105, <image>), the number of cities and number of roads respectively.

In following m lines there are descriptions of roads. Each description consists of three integers x, y, z (1 ≤ x, y ≤ n, <image>) meaning that there is a road connecting cities number x and y. If z = 1, this road is working, otherwise it is not.

Output

In the first line output one integer k, the minimum possible number of roads affected by gang.

In the following k lines output three integers describing roads that should be affected. Each line should contain three integers x, y, z (1 ≤ x, y ≤ n, <image>), cities connected by a road and the new state of a road. z = 1 indicates that the road between cities x and y should be repaired and z = 0 means that road should be blown up.

You may output roads in any order. Each affected road should appear exactly once. You may output cities connected by a single road in any order. If you output a road, it's original state should be different from z.

After performing all operations accroding to your plan, there should remain working only roads lying on some certain shortest past between city 1 and n.

If there are multiple optimal answers output any.

Examples

Input

2 1
1 2 0

Output

1
1 2 1

Input

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

Output

3
1 2 0
1 3 1
2 3 0

Input

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

Output

3
2 3 0
1 5 0
6 8 1

Note

In the first test the only path is 1 - 2

In the second test the only shortest path is 1 - 3 - 4

In the third test there are multiple shortest paths but the optimal is 1 - 4 - 6 - 8

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct Node {
  int node;
  int dist;
  int fixs;
  Node() {}
  Node(int node, int dist, int fixs) {
    this->node = node;
    this->dist = dist;
    this->fixs = fixs;
  }
};
int n;
int parentOf[100001];
int changesTo[100001];
int distanceTo[100001];
vector<Node> graph[100001];
set<pair<int, int> > toFix;
set<pair<int, int> > toBlow;
bool operator<(Node n1, Node n2) {
  if (n1.dist == n2.dist) return n1.fixs > n2.fixs;
  return n1.dist > n2.dist;
}
void DIJKSTRA(int source, int target) {
  int current;
  int newFixs;
  int newDist;
  priority_queue<Node> toVisit;
  for (int i = 0; i < n; i++) {
    parentOf[i] = -1;
    changesTo[i] = INT_MAX;
    distanceTo[i] = INT_MAX;
  }
  parentOf[source] = -2;
  changesTo[source] = 0;
  distanceTo[source] = 0;
  toVisit.push(Node(source, distanceTo[source], changesTo[source]));
  while (!toVisit.empty()) {
    current = toVisit.top().node;
    toVisit.pop();
    for (Node child : graph[current]) {
      newFixs = changesTo[current] + child.fixs;
      newDist = distanceTo[current] + child.dist;
      if (distanceTo[child.node] >= newDist) {
        if (distanceTo[child.node] > newDist) {
          parentOf[child.node] = current;
          changesTo[child.node] = newFixs;
          distanceTo[child.node] = newDist;
          toVisit.push(
              Node(child.node, distanceTo[child.node], changesTo[child.node]));
        } else if (changesTo[child.node] > newFixs) {
          parentOf[child.node] = current;
          changesTo[child.node] = newFixs;
          toVisit.push(
              Node(child.node, distanceTo[child.node], changesTo[child.node]));
        }
      }
    }
  }
}
void getRoads() {
  int node1;
  int node2;
  vector<pair<int, int> > fixes;
  node1 = n - 1;
  while (node1 != -2) {
    node2 = parentOf[node1];
    if (toFix.count({node1, node2}) != 0 || toFix.count({node2, node1}) != 0) {
      toFix.erase({node1, node2});
      toFix.erase({node2, node1});
      fixes.push_back({node1, node2});
    } else {
      toBlow.erase({node1, node2});
      toBlow.erase({node2, node1});
    }
    node1 = parentOf[node1];
  }
  printf("%d\n", fixes.size() + toBlow.size());
  for (pair<int, int> road : fixes)
    printf("%d %d %d\n", road.first + 1, road.second + 1, 1);
  for (pair<int, int> road : toBlow)
    printf("%d %d %d\n", road.first + 1, road.second + 1, 0);
}
int main() {
  int m;
  int x;
  int y;
  int z;
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &x);
    scanf("%d", &y);
    scanf("%d", &z);
    x--;
    y--;
    z ^= 1;
    graph[x].push_back(Node(y, 1, z));
    graph[y].push_back(Node(x, 1, z));
    if (z == 1) {
      toFix.insert({x, y});
      toFix.insert({y, x});
    } else
      toBlow.insert({x, y});
  }
  DIJKSTRA(0, n - 1);
  getRoads();
}

```


### Prompt

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

Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Petya got an array consisting of n numbers, it is the gift for his birthday. Now he wants to sort it in the non-decreasing order. However, a usual sorting is boring to perform, that's why Petya invented the following limitation: one can swap any two numbers but only if at least one of them is lucky. Your task is to sort the array according to the specified limitation. Find any possible sequence of the swaps (the number of operations in the sequence should not exceed 2n).

Input

The first line contains an integer n (1 ≤ n ≤ 105) — the number of elements in the array. The second line contains n positive integers, not exceeding 109 — the array that needs to be sorted in the non-decreasing order.

Output

On the first line print number k (0 ≤ k ≤ 2n) — the number of the swaps in the sorting. On the following k lines print one pair of distinct numbers (a pair per line) — the indexes of elements to swap. The numbers in the array are numbered starting from 1. If it is impossible to sort the given sequence, print the single number -1.

If there are several solutions, output any. Note that you don't have to minimize k. Any sorting with no more than 2n swaps is accepted.

Examples

Input

2
4 7

Output

0

Input

3
4 2 1

Output

1
1 3

Input

7
77 66 55 44 33 22 11

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
struct data {
  int id, num, sortid;
};
data a[maxn];
int circle[maxn];
vector<pair<int, int> > path;
vector<pair<int, int> >::iterator ite;
bool lucky[maxn] = {0}, h[maxn] = {0};
bool cmp1(data a, data b) {
  if (a.num == b.num)
    return a.id < b.id;
  else
    return a.num < b.num;
}
bool cmp2(data a, data b) { return a.id < b.id; }
bool check(int);
void init();
void gao();
void output();
int n, totlucky, pos_lucky, confirm;
int minswap;
int main() {
  init();
  gao();
  output();
  return 0;
}
bool check(int n) {
  while (n) {
    if (n % 10 != 4 && n % 10 != 7) return false;
    n /= 10;
  }
  return true;
}
void init() {
  int i;
  scanf("%d", &n);
  totlucky = 0;
  confirm = -1;
  pos_lucky = -1;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i].num);
    a[i].id = i;
    a[i].sortid = 0;
    lucky[i] = check(a[i].num);
    if (lucky[i]) {
      totlucky++;
      pos_lucky = i;
      confirm = 0;
    }
  }
}
void gao() {
  int head, tail, bp, i;
  minswap = 0;
  path.clear();
  sort(a + 1, a + n + 1, cmp1);
  head = 1;
  while (head <= n) {
    tail = head;
    while (a[tail].num == a[head].num) tail++;
    for (i = head; i < tail; i++)
      if (a[i].id >= head && a[i].id < tail)
        a[i].sortid = a[i].id, h[a[i].id] = 1;
    bp = head;
    for (i = head; i < tail; i++)
      if (a[i].id < head || a[i].id >= tail) {
        while (h[bp]) bp++;
        a[i].sortid = bp;
        h[bp] = 1;
      }
    head = tail;
  }
  sort(a + 1, a + n + 1, cmp2);
  int j, cnt, havelucky, loc, _cnt;
  for (i = 1; i <= n; i++)
    if (h[i]) {
      j = i;
      cnt = 0;
      havelucky = 0;
      loc = -1;
      while (h[j]) {
        circle[cnt++] = j;
        if (lucky[j]) havelucky = 1, loc = cnt - 1;
        h[j] = 0;
        j = a[j].sortid;
      }
      if (cnt == 1 || havelucky) {
        minswap += cnt - 1;
        j = loc;
        _cnt = cnt;
        while (_cnt-- > 1) {
          path.push_back(make_pair(circle[j], circle[(j - 1 + cnt) % cnt]));
          j = (j - 1 + cnt) % cnt;
        }
        if (!confirm && loc >= 0) {
          confirm = 1;
          pos_lucky = a[circle[loc]].sortid;
        }
      } else {
        minswap += cnt + 1;
        if (confirm < 0) return;
        path.push_back(make_pair(pos_lucky, i));
        j = 0;
        _cnt = cnt;
        while (_cnt-- > 1) {
          path.push_back(make_pair(circle[j], circle[(j - 1 + cnt) % cnt]));
          j = (j - 1 + cnt) % cnt;
        }
        path.push_back(make_pair(pos_lucky, a[i].sortid));
      }
      if (minswap > 2 * n) return;
    }
}
void output() {
  if (minswap && !totlucky)
    printf("-1\n");
  else if (minswap > 2 * n)
    printf("-1\n");
  else {
    printf("%d\n", minswap);
    for (ite = path.begin(); ite != path.end(); ite++)
      printf("%d %d\n", ite->first, ite->second);
  }
}

```


### Prompt

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

You are a warrior fighting against the machine god Thor.

Thor challenge you to solve the following problem:

There are n conveyors arranged in a line numbered with integers from 1 to n from left to right. Each conveyor has a symbol "<" or ">". The initial state of the conveyor i is equal to the i-th character of the string s. There are n+1 holes numbered with integers from 0 to n. The hole 0 is on the left side of the conveyor 1, and for all i ≥ 1 the hole i is on the right side of the conveyor i.

When a ball is on the conveyor i, the ball moves by the next rules:

If the symbol "<" is on the conveyor i, then:

  * If i=1, the ball falls into the hole 0.
  * If the symbol "<" is on the conveyor i-1, the ball moves to the conveyor i-1.
  * If the symbol ">" is on the conveyor i-1, the ball falls into the hole i-1.

If the symbol ">" is on the conveyor i, then:

  * If i=n, the ball falls into the hole n.
  * If the symbol ">" is on the conveyor i+1, the ball moves to the conveyor i+1.
  * If the symbol "<" is on the conveyor i+1, the ball falls into the hole i.

You should answer next q queries, each query is defined by the pair of integers l, r (1 ≤ l ≤ r ≤ n):

  * First, for all conveyors l,l+1,...,r, the symbol "<" changes to ">" and vice versa. These changes remain for the next queries.
  * After that, put one ball on each conveyor l,l+1,...,r. Then, each ball falls into some hole. Find the maximum number of balls in one hole. After the query all balls disappear and don't considered in the next queries.

Input

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

The second line contains a string s of length n. It consists of characters "<" and ">".

Next q lines contain the descriptions of the queries, i-th of them contains two integers l, r (1 ≤ l ≤ r ≤ n), describing the i-th query.

Output

Print q lines, in the i-th of them print the answer to the i-th query.

Example

Input

5 6
><>><
2 4
3 5
1 5
1 3
2 4
1 5

Output

3
3
5
3
2
3

Note

  * In the first query, the conveyors change to ">><<<". After that, put a ball on each conveyor \{2,3,4\}. All three balls fall into the hole 2. So the answer is 3.
  * In the second query, the conveyors change to ">>>>>". After that, put a ball on each conveyor \{3,4,5\}. All three balls fall into the hole 5. So the answer is 3.
  * In the third query, the conveyors change to "<<<<<". After that, put a ball on each conveyor \{1,2,3,4,5\}. All five balls fall into the hole 0. So the answer is 5.
  * In the fourth query, the conveyors change to ">>><<". After that, put a ball on each conveyor \{1,2,3\}. All three balls fall into the hole 3. So the answer is 3.
  * In the fifth query, the conveyors change to "><<><". After that, put a ball on each conveyor \{2,3,4\}. Two balls fall into the hole 1, and one ball falls into the hole 4. So, the answer is 2.
  * In the sixth query, the conveyors change to "<>><>". After that, put a ball on each conveyor \{1,2,3,4,5\}. Three balls fall into the hole 3, one ball falls into the hole 0 and one ball falls into the hole 5. So, the answer is 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1},
          dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T &a, U b) {
  return a < b ? (a = b, true) : false;
}
template <typename T, typename U>
inline bool chmin(T &a, U b) {
  return a > b ? (a = b, true) : false;
}
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;
template <typename Monoid, typename OperatorMonoid = Monoid>
struct LazySegmentTree {
  using MM = function<Monoid(Monoid, Monoid)>;
  using MOI = function<Monoid(Monoid, OperatorMonoid, int)>;
  using OO = function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;
  LazySegmentTree(int sz, MM mm, MOI moi, OO oo, const Monoid M_UNITY,
                  const OperatorMonoid O_UNITY)
      : mm(mm), moi(moi), oo(oo), M_UNITY(M_UNITY), O_UNITY(O_UNITY) {
    init(sz);
    dat.assign(n << 1, M_UNITY);
  }
  LazySegmentTree(const vector<Monoid> &a, MM mm, MOI moi, OO oo,
                  const Monoid M_UNITY, const OperatorMonoid O_UNITY)
      : mm(mm), moi(moi), oo(oo), M_UNITY(M_UNITY), O_UNITY(O_UNITY) {
    int a_sz = a.size();
    init(a_sz);
    dat.resize(n << 1);
    for (int i = (0); i < (a_sz); ++i) dat[i + n] = a[i];
    for (int i = n - 1; i > 0; --i) dat[i] = mm(dat[i << 1], dat[(i << 1) + 1]);
  }
  void update(int a, int b, OperatorMonoid val) { update(a, b, val, 1, 0, n); }
  Monoid query(int a, int b) { return query(a, b, 1, 0, n); }
  Monoid operator[](const int idx) { return query(idx, idx + 1); }

 private:
  int n = 1;
  MM mm;
  MOI moi;
  OO oo;
  const Monoid M_UNITY;
  const OperatorMonoid O_UNITY;
  vector<Monoid> dat;
  vector<OperatorMonoid> lazy;
  vector<bool> need_to_be_eval;
  void init(int sz) {
    while (n < sz) n <<= 1;
    lazy.assign(n << 1, O_UNITY);
    need_to_be_eval.assign(n << 1, false);
  }
  inline void evaluate(int node, int len) {
    if (need_to_be_eval[node]) {
      dat[node] = moi(dat[node], lazy[node], len);
      if (node < n) {
        lazy[node << 1] = oo(lazy[node << 1], lazy[node]);
        need_to_be_eval[node << 1] = true;
        lazy[(node << 1) + 1] = oo(lazy[(node << 1) + 1], lazy[node]);
        need_to_be_eval[(node << 1) + 1] = true;
      }
      lazy[node] = O_UNITY;
      need_to_be_eval[node] = false;
    }
  }
  void update(int a, int b, OperatorMonoid val, int node, int left, int right) {
    evaluate(node, right - left);
    if (right <= a || b <= left) return;
    if (a <= left && right <= b) {
      lazy[node] = oo(lazy[node], val);
      need_to_be_eval[node] = true;
      evaluate(node, right - left);
    } else {
      update(a, b, val, node << 1, left, (left + right) >> 1);
      update(a, b, val, (node << 1) + 1, (left + right) >> 1, right);
      dat[node] = mm(dat[node << 1], dat[(node << 1) + 1]);
    }
  }
  Monoid query(int a, int b, int node, int left, int right) {
    evaluate(node, right - left);
    if (right <= a || b <= left) return M_UNITY;
    if (a <= left && right <= b) return dat[node];
    return mm(query(a, b, node << 1, left, (left + right) >> 1),
              query(a, b, (node << 1) + 1, (left + right) >> 1, right));
  }
};
int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  struct Node {
    int l0, l1, l01, l10, r0, r1, r10, r01, len, ans, rev;
    Node(int l0 = 0, int l1 = 0, int l01 = 0, int l10 = 0, int r0 = 0,
         int r1 = 0, int r01 = 0, int r10 = 0, int len = 0, int ans = 0,
         int rev = 0)
        : l0(l0),
          l1(l1),
          l01(l01),
          l10(l10),
          r0(r0),
          r1(r1),
          r01(r01),
          r10(r10),
          len(len),
          ans(ans),
          rev(rev) {}
  };
  vector<Node> init;
  for (char c : s) {
    init.emplace_back(c == '>' ? Node(1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1)
                               : Node(0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1));
  }
  function<Node(Node, Node)> mm = [](Node a, Node b) {
    Node node;
    node.l0 = a.l0 == a.len ? a.l0 + b.l0 : a.l0;
    node.l1 = a.l1 == a.len ? a.l1 + b.l1 : a.l1;
    if (a.l0 == a.len) {
      node.l01 = a.l0 + b.l01;
    } else if (a.l01 == a.len) {
      node.l01 = a.l01 + b.l1;
    } else {
      node.l01 = a.l01;
    }
    if (a.l1 == a.len) {
      node.l10 = a.l1 + b.l10;
    } else if (a.l10 == a.len) {
      node.l10 = a.l10 + b.l0;
    } else {
      node.l10 = a.l10;
    }
    node.r0 = b.r0 == b.len ? b.r0 + a.r0 : b.r0;
    node.r1 = b.r1 == b.len ? b.r1 + a.r1 : b.r1;
    if (b.r0 == b.len) {
      node.r10 = b.r0 + a.r10;
    } else if (b.r10 == b.len) {
      node.r10 = b.r10 + a.r1;
    } else {
      node.r10 = b.r10;
    }
    if (b.r1 == b.len) {
      node.r01 = b.r1 + a.r01;
    } else if (b.r01 == b.len) {
      node.r01 = b.r01 + a.r0;
    } else {
      node.r01 = b.r01;
    }
    node.len = a.len + b.len;
    node.ans = max({a.ans, b.ans, node.l01, node.r01});
    chmax(node.ans, max({a.r0 + b.l01, a.r01 + b.l1}));
    node.rev = max({a.rev, b.rev, node.l10, node.r10});
    chmax(node.rev, max({a.r1 + b.l10, a.r10 + b.l0}));
    return node;
  };
  function<Node(Node, int, int)> moi = [](Node m, int o, int i) {
    if (o) {
      swap(m.l0, m.l1);
      swap(m.l01, m.l10);
      swap(m.r0, m.r1);
      swap(m.r01, m.r10);
      swap(m.ans, m.rev);
    }
    return m;
  };
  function<int(int, int)> oo = [](int a, int b) { return a ^ b; };
  LazySegmentTree<Node, int> seg(init, mm, moi, oo, Node(), 0);
  while (q--) {
    int l, r;
    cin >> l >> r;
    --l;
    --r;
    seg.update(l, r + 1, 1);
    cout << seg.query(l, r + 1).ans << '\n';
  }
  return 0;
}

```


### Prompt

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

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

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

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

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

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

Input

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

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

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

Output

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

Examples

Input

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

Output

5

Input

glo?yto?e??an?
or

Output

3

Input

??c?????
abcab

Output

2

Note

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

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

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int const sze = 1 << 17, MOD1 = 1e9 + 9, x1 = 119, INF = -1e6;
int get(const string &s, const string &f, int ind) {
  int length = 0;
  while (length != f.length() && ind + length < s.length() &&
         (s[ind + length] == '?' || s[ind + length] == f[length]))
    length++;
  return length;
}
signed main() {
  string s, f;
  cin >> s >> f;
  int n = s.size(), m = f.size();
  vector<vector<bool>> may_pref(n);
  vector<int> may_suf(n);
  for (int i = 0; i < n; ++i) {
    may_pref[i].resize(m + 1);
  }
  for (int i = 0; i + m - 1 < n; ++i) {
    int v = get(s, f, i);
    for (int j = 0; j < v; ++j) may_pref[i + j][j + 1] = 1;
  }
  for (int i = 0; i < n; ++i) {
    int length = 0;
    while (i >= length && m > length &&
           (s[i - length] == '?' || s[i - length] == f[m - length - 1]))
      length++;
    may_suf[i] = length;
  }
  vector<int> dp(n);
  vector<int> lengthes;
  for (int i = 1; i < m; ++i) {
    if (f.substr(0, i) == f.substr(m - i, i)) lengthes.push_back(i);
  }
  int cur = 0;
  vector<int> c(n);
  for (int i = 0; i < n; ++i) {
    if (i >= m) {
      cur = max(cur, dp[i - m]);
      dp[i] = max(dp[i], cur);
    }
    c[i] = dp[i];
    if (i) {
      c[i] = max(c[i], c[i - 1]);
    }
    if (may_suf[i] == m && !lengthes.size())
      dp[i] = max(dp[i], (i + 1 == m ? 1 : cur + 1));
    for (int j : lengthes) {
      if (may_pref[i][j] && i + (m - j) < n &&
          may_suf[i + (m - j)] >= (m - j)) {
        dp[i + (m - j)] =
            max(dp[i + (m - j)], max(dp[i], (i >= j) ? c[i - j] : 0) + 1);
      }
    }
  }
  int ans = dp[n - 1];
  for (int i = 0; i < n; ++i) ans = max(ans, dp[i]);
  cout << ans << '\n';
  return 0;
}

```


### Prompt

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

Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 ≤ li ≤ ri ≤ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.

Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 ≤ xi ≤ yi ≤ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.

Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.

Input

The first line contains integers n, m, k (1 ≤ n, m, k ≤ 105). The second line contains n integers: a1, a2, ..., an (0 ≤ ai ≤ 105) — the initial array.

Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 ≤ li ≤ ri ≤ n), (0 ≤ di ≤ 105).

Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 ≤ xi ≤ yi ≤ m).

The numbers in the lines are separated by single spaces.

Output

On a single line print n integers a1, a2, ..., an — the array after executing all the queries. Separate the printed numbers by spaces.

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

Examples

Input

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

Output

9 18 17

Input

1 1 1
1
1 1 1
1 1

Output

2

Input

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

Output

5 18 31 20

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
long long n, m, k, tree[4 * N], lz[4 * N], l[N], r[N], d[N], f[N], a[N];
void lazy(long long l, long long r, long long pos) {
  tree[pos] += ((r - l + 1) * lz[pos]);
  if (l != r) {
    lz[2 * pos] += lz[pos];
    lz[2 * pos + 1] += lz[pos];
  }
  lz[pos] = 0;
  return;
}
void update(long long l, long long r, long long pos, long long L, long long R,
            long long v) {
  lazy(l, r, pos);
  if (l > R || r < L) return;
  if (l >= L && r <= R) {
    tree[pos] += v * (r - l + 1);
    if (l != r) {
      lz[2 * pos] += v;
      lz[2 * pos + 1] += v;
    }
    return;
  }
  long long mid = (l + r) / 2;
  update(l, mid, 2 * pos, L, R, v);
  update(mid + 1, r, 2 * pos + 1, L, R, v);
  tree[pos] = tree[2 * pos] + tree[2 * pos + 1];
  return;
}
long long query(long long l, long long r, long long pos, long long P) {
  lazy(l, r, pos);
  if (l > P || r < P) return 0;
  if (l == r && l == P) return tree[pos];
  long long mid = (l + r) / 2;
  return query(l, mid, 2 * pos, P) + query(mid + 1, r, 2 * pos + 1, P);
}
int solve() {
  scanf("%lld%lld", &n, &m);
  scanf("%lld", &k);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%lld%lld", &l[i], &r[i]);
    scanf("%lld", &d[i]);
  }
  while (k--) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    update(1, m, 1, x, y, 1);
  }
  for (int i = 1; i <= m; i++) {
    f[i] = query(1, m, 1, i);
  }
  memset(tree, 0, sizeof(tree));
  for (int i = 1; i <= m; i++) {
    update(1, n, 1, l[i], r[i], d[i] * f[i]);
  }
  for (int i = 1; i <= n; i++) {
    printf("%lld ", a[i] + query(1, n, 1, i));
  }
  return 0;
}
int main() { return solve(); }

```


### Prompt

Construct a CPP code solution to the problem outlined:

Butler Ostin wants to show Arkady that rows of odd number of fountains are beautiful, while rows of even number of fountains are not.

The butler wants to show Arkady n gardens. Each garden is a row of m cells, the i-th garden has one fountain in each of the cells between li and ri inclusive, and there are no more fountains in that garden. The issue is that some of the gardens contain even number of fountains, it is wrong to show them to Arkady.

Ostin wants to choose two integers a ≤ b and show only part of each of the gardens that starts at cell a and ends at cell b. Of course, only such segments suit Ostin that each garden has either zero or odd number of fountains on this segment. Also, it is necessary that at least one garden has at least one fountain on the segment from a to b.

Help Ostin to find the total length of all such segments, i.e. sum up the value (b - a + 1) for each suitable pair (a, b).

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of gardens and the length of each garden.

n lines follow. The i-th of these lines contains two integers li and ri (1 ≤ li ≤ ri ≤ m) — the bounds of the segment that contains fountains in the i-th garden.

Output

Print one integer: the total length of all suitable segments.

Examples

Input

1 5
2 4

Output

23

Input

3 6
2 4
3 6
4 4

Output

19

Note

In the first example the following pairs suit Ostin: (a, b): (1, 2), (1, 4), (1, 5), (2, 2), (2, 4), (2, 5), (3, 3), (4, 4), (4, 5).

In the second example the following pairs suit Ostin: (a, b): (1, 2), (1, 5), (2, 2), (2, 5), (3, 3), (4, 4), (4, 6), (5, 5), (6, 6).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 20;
long long n, m, l[N], r[N];
long long x[N], p[N], d[N], t[N];
map<long long, long long> cnt, sum;
long long ans;
inline long long get_random() {
  return 1ll * rand() * rand() * rand() + rand() * rand() + rand();
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
    l[i]--;
    long long val = get_random();
    x[l[i]] ^= val;
    x[r[i]] ^= val;
    d[l[i]] ^= val;
    t[r[i]] ^= val;
  }
  for (long long i = 0; i < m; i++) {
    if (i) {
      x[i] ^= x[i - 1];
      p[i] ^= p[i - 1];
      d[i] ^= d[i - 1];
      t[i] ^= t[i - 1];
    }
    p[i] ^= x[i];
    cnt[(i ? p[i - 1] : 0) ^ t[i]]++;
    sum[(i ? p[i - 1] : 0) ^ t[i]] += i;
    ans += cnt[p[i] ^ d[i]] * (i + 1) - sum[p[i] ^ d[i]];
  }
  long long last = -1;
  for (long long i = 0; i < m; i++) {
    if (!x[i]) {
      ans -= (i - last) * (i - last + 1) / 2;
    } else
      last = i;
  }
  cout << ans << '\n';
}

```


### Prompt

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

C --Misawa's rooted tree

Problem Statement

You noticed that your best friend Misawa's birthday was near, and decided to give him a rooted binary tree as a gift. Here, the rooted binary tree has the following graph structure. (Figure 1)

* Each vertex has exactly one vertex called the parent of that vertex, which is connected to the parent by an edge. However, only one vertex, called the root, has no parent as an exception.
* Each vertex has or does not have exactly one vertex called the left child. If you have a left child, it is connected to the left child by an edge, and the parent of the left child is its apex.
* Each vertex has or does not have exactly one vertex called the right child. If you have a right child, it is connected to the right child by an edge, and the parent of the right child is its apex.

<image>

Figure 1. An example of two rooted binary trees and their composition

You wanted to give a handmade item, so I decided to buy two commercially available rooted binary trees and combine them on top of each other to make one better rooted binary tree. Each vertex of the two trees you bought has a non-negative integer written on it. Mr. Misawa likes a tree with good cost performance, such as a small number of vertices and large numbers, so I decided to create a new binary tree according to the following procedure.

1. Let the sum of the integers written at the roots of each of the two binary trees be the integers written at the roots of the new binary tree.
2. If both binary trees have a left child, create a binary tree by synthesizing each of the binary trees rooted at them, and use it as the left child of the new binary tree root. Otherwise, the root of the new bifurcation has no left child.
3. If the roots of both binaries have the right child, create a binary tree by synthesizing each of the binary trees rooted at them, and use it as the right child of the root of the new binary tree. Otherwise, the root of the new bifurcation has no right child.

You decide to see what the resulting rooted binary tree will look like before you actually do the compositing work. Given the information of the two rooted binary trees you bought, write a program to find the new rooted binary tree that will be synthesized according to the above procedure.

Here, the information of the rooted binary tree is expressed as a character string in the following format.

> (String representing the left child) [Integer written at the root] (String representing the right child)

A tree without nodes is an empty string. For example, the synthesized new rooted binary tree in Figure 1 is `(() [6] ()) [8] (((() [4] ()) [7] ()) [9] () ) `Written as.

Input

The input is expressed in the following format.

$ A $
$ B $

$ A $ and $ B $ are character strings that represent the information of the rooted binary tree that you bought, and the length is $ 7 $ or more and $ 1000 $ or less. The information given follows the format described above and does not include extra whitespace. Also, rooted trees that do not have nodes are not input. You can assume that the integers written at each node are greater than or equal to $ 0 $ and less than or equal to $ 1000 $. However, note that the integers written at each node of the output may not fall within this range.

Output

Output the information of the new rooted binary tree created by synthesizing the two rooted binary trees in one line. In particular, be careful not to include extra whitespace characters other than line breaks at the end of the line.

Sample Input 1

((() [8] ()) [2] ()) [5] (((() [2] ()) [6] (() [3] ())) [1] ())
(() [4] ()) [3] (((() [2] ()) [1] ()) [8] (() [3] ()))

Output for the Sample Input 1

(() [6] ()) [8] (((() [4] ()) [7] ()) [9] ())

Sample Input 2

(() [1] ()) [2] (() [3] ())
(() [1] (() [2] ())) [3] ()

Output for the Sample Input 2

(() [2] ()) [5] ()

Sample Input 3

(() [1] ()) [111] ()
() [999] (() [9] ())

Output for the Sample Input 3

() [1110] ()

Sample Input 4

(() [2] (() [4] ())) [8] ((() [16] ()) [32] (() [64] ()))
((() [1] ()) [3] ()) [9] (() [27] (() [81] ()))

Output for the Sample Input 4

(() [5] ()) [17] (() [59] (() [145] ()))

Sample Input 5

() [0] ()
() [1000] ()

Output for the Sample Input 5

() [1000] ()

Example

Input

((()[8]())[2]())[5](((()[2]())[6](()[3]()))[1]())
(()[4]())[3](((()[2]())[1]())[8](()[3]()))

Output

(()[6]())[8](((()[4]())[7]())[9]())

### Response

```cpp
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;

pair<int, int> num(const string &s, int i) {
  int n = 0;
  while (isdigit(s[i])) {
    n *= 10;
    n += s[i] - '0';
    ++i;
  }
  return make_pair(n, i);
}

int skip(const string &s, int i) {
  if (s[i] == '(') {
    i = skip(s, i+1);
    assert(s[i] == ')');
    assert(s[i+1] == '[');
    i = num(s, i+2).second;
    assert(s[i] == ']');
    assert(s[i+1] == '(');
    i = skip(s, i+2);
    return i+1;
  } else {
    return i;
  }
}

pair<int, int> parse(const string &a, const string &b, int i, int j) {
  if (a[i] == '(' && b[j] == '(') {
    cout << '(';
    tie(i, j) = parse(a, b, i+1, j+1);
    assert(a[i] == ')');
    assert(b[j] == ')');
    cout << ')';
    assert(a[i+1] == '[');
    assert(b[j+1] == '[');
    cout << '[';
    int n, m;
    tie(n, i) = num(a, i+2);
    tie(m, j) = num(b, j+2);
    cout << (n+m);
    assert(a[i] == ']');
    assert(b[j] == ']');
    cout << ']';
    assert(a[i+1] == '(');
    assert(b[j+1] == '(');
    cout << '(';
    tie(i, j) = parse(a, b, i+2, j+2);
    assert(a[i] == ')');
    assert(b[j] == ')');
    cout << ')';
    ++i; ++j;
  } else {
    if (a[i] == '(') {
      i = skip(a, i);
    } else if (b[j] == '(') {
      j = skip(b, j);
    }
  }
  return make_pair(i, j);
}

int main() {
  string a, b;
  cin>>a>>b;
  parse(a, b, 0, 0);
  cout << endl;
  return 0;
}
```


### Prompt

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

There is a blackboard on which all integers from -10^{18} through 10^{18} are written, each of them appearing once. Takahashi will repeat the following sequence of operations any number of times he likes, possibly zero:

* Choose an integer between 1 and N (inclusive) that is written on the blackboard. Let x be the chosen integer, and erase x.
* If x-2 is not written on the blackboard, write x-2 on the blackboard.
* If x+K is not written on the blackboard, write x+K on the blackboard.

Find the number of possible sets of integers written on the blackboard after some number of operations, modulo M. We consider two sets different when there exists an integer contained in only one of the sets.

Constraints

* 1 \leq K\leq N \leq 150
* 10^8\leq M\leq 10^9
* N, K, and M are integers.

Input

Input is given from Standard Input in the following format:

N K M

Output

Print the number of possible sets of integers written on the blackboard after some number of operations, modulo M.

Examples

Input

3 1 998244353

Output

7

Input

6 3 998244353

Output

61

Input

9 4 702443618

Output

312

Input

17 7 208992811

Output

128832

Input

123 45 678901234

Output

256109226

### Response

```cpp
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
long long M;
long long dp[160][80][80][80];
long long DP[160][160][160];
int main(){
	int a,b;
	scanf("%d%d%lld",&a,&b,&M);
	if(b%2==0){
		DP[0][0][1]=1;
		for(int i=0;i<a;i++){
			for(int j=0;j<=i+1;j++){
				for(int k=0;k<=i+1;k++){
					if(!DP[i][j][k])continue;
					if(i%2==0){
						DP[i+1][i+2][k]=(DP[i+1][i+2][k]+DP[i][j][k])%M;
						if(i-j<b)DP[i+1][j][k]=(DP[i+1][j][k]+DP[i][j][k])%M;
					}else{
						DP[i+1][j][i+2]=(DP[i+1][j][i+2]+DP[i][j][k])%M;
						if(i-k<b)DP[i+1][j][k]=(DP[i+1][j][k]+DP[i][j][k])%M;
					}
				}
			}
		}
		long long ret=0;
		for(int i=0;i<=a+1;i++){
			for(int j=0;j<=a+1;j++){
				ret+=DP[a][i][j];
			}
		}
		ret%=M;
		printf("%lld\n",ret);
		return 0;
	}else{
		dp[0][0][0][79]=1;
		for(int i=0;i<a;i++){
			for(int j=0;j<80;j++){
				for(int k=0;k<80;k++){
					for(int l=0;l<80;l++){
						if(!dp[i][j][k][l])continue;

						int x=j*2-2;
						int y=k*2-1;
					//	printf("%d %d %d %d: %lld\n",i,x,y,l,dp[i][j][k][l]);
						if(x<y){
							if(i%2==0){
								if(i<l*2)dp[i+1][j][k][l]=(dp[i+1][j][k][l]+dp[i][j][k][l])%M;
								dp[i+1][(i+2)/2][k][79]=(dp[i+1][(i+2)/2][k][79]+dp[i][j][k][l])%M;
							}else{
								if(x+2+b<=i)dp[i+1][j][k][min(l,(y+2+b)/2)]=(dp[i+1][j][k][min(l,(y+b+2)/2)]+dp[i][j][k][l])%M;
								else dp[i+1][j][k][l]=(dp[i+1][j][k][l]+dp[i][j][k][l])%M;
								dp[i+1][j][(i+1)/2][l]=(dp[i+1][j][(i+1)/2][l]+dp[i][j][k][l])%M;
							}
						}else{
							if(i%2==1){
								if(i<l*2-1)dp[i+1][j][k][l]=(dp[i+1][j][k][l]+dp[i][j][k][l])%M;
								dp[i+1][j][(i+1)/2][79]=(dp[i+1][j][(i+1)/2][79]+dp[i][j][k][l])%M;
							}else{
								if(y+2+b<=i)dp[i+1][j][k][min(l,(x+b+3)/2)]=(dp[i+1][j][k][min(l,(x+b+3)/2)]+dp[i][j][k][l])%M;
								else dp[i+1][j][k][l]=(dp[i+1][j][k][l]+dp[i][j][k][l])%M;
								dp[i+1][(i+2)/2][k][l]=(dp[i+1][(i+2)/2][k][l]+dp[i][j][k][l])%M;
							}
						}
					}
				}
			}
		}
		long long ret=0;
		for(int i=0;i<80;i++){
			for(int j=0;j<80;j++){
				for(int k=0;k<80;k++){
					ret+=dp[a][i][j][k];
				}
			}
		}
		ret%=M;
		printf("%lld\n",ret);
	}
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has n cities connected by n - 1 undirected roads, and for any two cities there always exists a path between them.

Fox Ciel needs to assign an officer to each city. Each officer has a rank — a letter from 'A' to 'Z'. So there will be 26 different ranks, and 'A' is the topmost, so 'Z' is the bottommost.

There are enough officers of each rank. But there is a special rule must obey: if x and y are two distinct cities and their officers have the same rank, then on the simple path between x and y there must be a city z that has an officer with higher rank. The rule guarantee that a communications between same rank officers will be monitored by higher rank officer.

Help Ciel to make a valid plan, and if it's impossible, output "Impossible!".

Input

The first line contains an integer n (2 ≤ n ≤ 105) — the number of cities in Tree Land.

Each of the following n - 1 lines contains two integers a and b (1 ≤ a, b ≤ n, a ≠ b) — they mean that there will be an undirected road between a and b. Consider all the cities are numbered from 1 to n.

It guaranteed that the given graph will be a tree.

Output

If there is a valid plane, output n space-separated characters in a line — i-th character is the rank of officer in the city with number i.

Otherwise output "Impossible!".

Examples

Input

4
1 2
1 3
1 4

Output

A B B B

Input

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

Output

D C B A D C B D C D

Note

In the first example, for any two officers of rank 'B', an officer with rank 'A' will be on the path between them. So it is a valid solution.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
vector<int> g[MAXN];
char c[MAXN];
int mark[MAXN], n, l = 1, dp[MAXN], par[MAXN];
int go(int v, int sz, int p = 0) {
  par[v] = p;
  dp[v] = 1;
  mark[v] = l;
  int ans = -1;
  for (int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    if (mark[u] != l - 1) continue;
    int q = go(u, sz, v);
    dp[v] += dp[u];
    if (q != -1 && ans == -1) ans = q;
  }
  if (ans != -1) return ans;
  if (dp[v] >= (sz + 1) / 2) {
    mark[v] = -mark[v];
    return v;
  }
  return -1;
}
void solve(int v, int sz, int p) {
  l = p;
  int cen = go(v, sz);
  for (int u : g[cen])
    if (mark[u] > 0)
      if (u == par[cen])
        solve(u, sz - dp[cen], p + 1);
      else
        solve(u, dp[u], p + 1);
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int v, u;
    cin >> v >> u;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  solve(1, n, 1);
  for (int i = 1; i <= n; i++) cout << char(abs(mark[i]) + 'A' - 1) << " ";
  cout << endl;
  return 0;
}

```


### Prompt

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

Consider a permutation p_1, p_2, ... p_n of integers from 1 to n. We call a sub-segment p_l, p_{l+1}, ..., p_{r-1}, p_{r} of the permutation an interval if it is a reordering of some set of consecutive integers. For example, the permutation (6,7,1,8,5,3,2,4) has the intervals (6,7), (5,3,2,4), (3,2), and others.

Each permutation has some trivial intervals — the full permutation itself and every single element. We call a permutation interval-free if it does not have non-trivial intervals. In other words, interval-free permutation does not have intervals of length between 2 and n - 1 inclusive.

Your task is to count the number of interval-free permutations of length n modulo prime number p.

Input

In the first line of the input there are two integers t (1 ≤ t ≤ 400) and p (10^8 ≤ p ≤ 10^9) — the number of test cases to solve and the prime modulo. In each of the next t lines there is one integer n (1 ≤ n ≤ 400) — the length of the permutation.

Output

For each of t test cases print a single integer — the number of interval-free permutations modulo p.

Examples

Input

4 998244353
1
4
5
9

Output

1
2
6
28146

Input

1 437122297
20

Output

67777575

Note

For n = 1 the only permutation is interval-free. For n = 4 two interval-free permutations are (2,4,1,3) and (3,1,4,2). For n = 5 — (2,4,1,5,3), (2,5,3,1,4), (3,1,5,2,4), (3,5,1,4,2), (4,1,3,5,2), and (4,2,5,1,3). We will not list all 28146 for n = 9, but for example (4,7,9,5,1,8,2,6,3), (2,4,6,1,9,7,3,8,5), (3,6,9,4,1,5,8,2,7), and (8,4,9,1,3,6,2,7,5) are interval-free.

The exact value for n = 20 is 264111424634864638.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e2 + 5;
long long mod;
long long A[maxn], B[maxn][maxn];
long long G[maxn], F[maxn];
void pre() {
  A[1] = A[0] = 1;
  for (int i = 2; i < maxn; i++) A[i] = A[i - 1] * i % mod;
  B[0][0] = 1;
  for (int i = 1; i < maxn; i++)
    for (int j = 1; j <= i; j++)
      for (int k = 1; k <= i; k++)
        B[i][j] = (B[i][j] + B[i - k][j - 1] * A[k] % mod) % mod;
  for (int i = 1; i < maxn; i++) {
    F[i] = G[i] = A[i];
    for (int k = 1; k < i; k++) {
      G[i] = (G[i] - G[k] * A[i - k] % mod + mod) % mod;
      F[i] = (F[i] - 2 * G[k] % mod * A[i - k] % mod + mod) % mod;
    }
    for (int k = 4; k < i; k++)
      F[i] = (F[i] - B[i][k] * F[k] % mod + mod) % mod;
  }
  F[2] = 2;
}
int main() {
  int t;
  cin >> t >> mod;
  pre();
  while (t--) {
    int n;
    cin >> n;
    cout << F[n] << endl;
  }
  return 0;
}

```


### Prompt

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

Assume that you have k one-dimensional segments s_1, s_2, ... s_k (each segment is denoted by two integers — its endpoints). Then you can build the following graph on these segments. The graph consists of k vertexes, and there is an edge between the i-th and the j-th vertexes (i ≠ j) if and only if the segments s_i and s_j intersect (there exists at least one point that belongs to both of them).

For example, if s_1 = [1, 6], s_2 = [8, 20], s_3 = [4, 10], s_4 = [2, 13], s_5 = [17, 18], then the resulting graph is the following:

<image>

A tree of size m is good if it is possible to choose m one-dimensional segments so that the graph built on these segments coincides with this tree.

You are given a tree, you have to find its good subtree with maximum possible size. Recall that a subtree is a connected subgraph of a tree.

Note that you have to answer q independent queries.

Input

The first line contains one integer q (1 ≤ q ≤ 15 ⋅ 10^4) — the number of the queries.

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

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

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

Output

For each query print one integer — the maximum size of a good subtree of the given tree.

Example

Input

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

Output

8

Note

In the first query there is a good subtree of size 8. The vertices belonging to this subtree are {9, 4, 10, 2, 5, 1, 6, 3}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = int(3e5 + 5);
int n;
vector<int> G[MAXN];
int dp[MAXN], FA[MAXN];
void Addedge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}
void Dfs(int u, int fa) {
  int cnt = 0, Max = 0;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == fa) continue;
    FA[v] = u;
    Dfs(v, u);
    cnt++;
    Max = max(Max, dp[v]);
  }
  if (cnt == 0) {
    dp[u] = 1;
    return;
  }
  dp[u] = cnt + Max;
}
int Solve(int u) {
  int Max1 = 0, Max2 = 0, cnt = 0;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == FA[u]) continue;
    cnt++;
    if (dp[v] >= Max1) {
      Max2 = Max1;
      Max1 = dp[v];
    } else if (dp[v] >= Max2)
      Max2 = dp[v];
  }
  if (cnt == 0) return 2;
  if (cnt == 1) return Max1 + (u != 1) + 1;
  if (u == 1) return G[u].size() - 2 + Max1 + Max2 + 1;
  return G[u].size() - 3 + Max1 + Max2 + 2;
}
int ANS() {
  int ret = 0;
  for (int i = 1; i <= n; i++) ret = max(ret, Solve(i));
  return ret;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (int i = 0; i <= n; i++) {
      dp[i] = 0;
      G[i].clear();
    }
    int u, v;
    for (int i = 1; i <= n - 1; i++) {
      scanf("%d%d", &u, &v);
      Addedge(u, v);
    }
    Dfs(1, -1);
    printf("%d\n", ANS());
  }
}

```


### Prompt

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

In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.

Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.

Given this information, is it possible to restore the exact floor for flat n?

Input

The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.

m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.

It is guaranteed that the given information is not self-contradictory.

Output

Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.

Examples

Input

10 3
6 2
2 1
7 3

Output

4

Input

8 4
3 1
6 2
5 2
2 1

Output

-1

Note

In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.

In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  long long f[m + 5];
  long long k[m + 5];
  for (int i = 0; i < m; i++) {
    cin >> k[i] >> f[i];
  }
  int e = -1;
  bool lol = true;
  long long cnt = 0;
  long long ans = 0;
  for (int x = 1; x <= 200; x++) {
    bool fl = true;
    for (int i = 0; i < m; i++) {
      int y = f[i];
      int s = k[i];
      if (s <= y * x && s >= (y - 1) * x + 1) {
      } else {
        fl = false;
      }
    }
    if (fl) {
      int w = (n - 1) / x + 1;
      if (e == -1) {
        e = w;
      } else {
        if (w != e) {
          lol = false;
        }
      }
      cnt++;
      ans = x;
    }
  }
  int kek = (n - 1) / ans + 1;
  if (lol == true) {
    cout << kek;
  } else {
    cout << -1;
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Sereja has painted n distinct points on the plane. The coordinates of each point are integers. Now he is wondering: how many squares are there with sides parallel to the coordinate axes and with points painted in all its four vertexes? Help him, calculate this number.

Input

The first line contains integer n (1 ≤ n ≤ 105). Each of the next n lines contains two integers xi, yi (0 ≤ xi, yi ≤ 105), the integers represent the coordinates of the i-th point. It is guaranteed that all the given points are distinct.

Output

In a single line print the required number of squares.

Examples

Input

5
0 0
0 2
2 0
2 2
1 1

Output

1

Input

9
0 0
1 1
2 2
0 1
1 0
0 2
2 0
1 2
2 1

Output

5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
int n;
struct Point {
  int x, y;
  bool operator<(const Point &rhs) const {
    if (y == rhs.y)
      return x < rhs.x;
    else
      return y < rhs.y;
  }
} a[N];
set<pair<int, int> > st;
vector<int> X[N];
vector<int> Y[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &a[i].x, &a[i].y);
  sort(a + 1, a + 1 + n);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (X[a[i].x].size() < Y[a[i].y].size()) {
      for (int j = 0; j < X[a[i].x].size(); j++) {
        int len = a[i].y - X[a[i].x][j];
        if (st.count(make_pair(a[i].x - len, a[i].y)) &&
            st.count(make_pair(a[i].x - len, a[i].y - len)))
          ans++;
      }
    } else {
      for (int j = 0; j < Y[a[i].y].size(); j++) {
        int len = a[i].x - Y[a[i].y][j];
        if (st.count(make_pair(a[i].x, a[i].y - len)) &&
            st.count(make_pair(a[i].x - len, a[i].y - len)))
          ans++;
      }
    }
    st.insert(make_pair(a[i].x, a[i].y));
    X[a[i].x].push_back(a[i].y);
    Y[a[i].y].push_back(a[i].x);
  }
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

The only difference between easy and hard versions are constraints on n and k.

You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most k most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals 0).

Each conversation is between you and some of your friends. There is at most one conversation with any of your friends. So each conversation is uniquely defined by your friend.

You (suddenly!) have the ability to see the future. You know that during the day you will receive n messages, the i-th message will be received from the friend with ID id_i (1 ≤ id_i ≤ 10^9).

If you receive a message from id_i in the conversation which is currently displayed on the smartphone then nothing happens: the conversations of the screen do not change and do not change their order, you read the message and continue waiting for new messages.

Otherwise (i.e. if there is no conversation with id_i on the screen):

  * Firstly, if the number of conversations displayed on the screen is k, the last conversation (which has the position k) is removed from the screen.
  * Now the number of conversations on the screen is guaranteed to be less than k and the conversation with the friend id_i is not displayed on the screen.
  * The conversation with the friend id_i appears on the first (the topmost) position on the screen and all the other displayed conversations are shifted one position down.

Your task is to find the list of conversations (in the order they are displayed on the screen) after processing all n messages.

Input

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 2 ⋅ 10^5) — the number of messages and the number of conversations your smartphone can show.

The second line of the input contains n integers id_1, id_2, ..., id_n (1 ≤ id_i ≤ 10^9), where id_i is the ID of the friend which sends you the i-th message.

Output

In the first line of the output print one integer m (1 ≤ m ≤ min(n, k)) — the number of conversations shown after receiving all n messages.

In the second line print m integers ids_1, ids_2, ..., ids_m, where ids_i should be equal to the ID of the friend corresponding to the conversation displayed on the position i after receiving all n messages.

Examples

Input

7 2
1 2 3 2 1 3 2

Output

2
2 1

Input

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

Output

3
1 3 2

Note

In the first example the list of conversations will change in the following way (in order from the first to last message):

  * [];
  * [1];
  * [2, 1];
  * [3, 2];
  * [3, 2];
  * [1, 3];
  * [1, 3];
  * [2, 1].

In the second example the list of conversations will change in the following way:

  * [];
  * [2];
  * [3, 2];
  * [3, 2];
  * [1, 3, 2];
  * and then the list will not change till the end.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long int power(long long int x, long long int y) {
  long long int temp;
  if (y == 0) return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
long long int GCD(long long int A, long long int B) {
  if (B == 0)
    return A;
  else
    return GCD(B, A % B);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  long long int n, k, i, j;
  cin >> n >> k;
  map<long long int, bool> m;
  deque<long long int> q;
  for (i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    if (m.find(x) != m.end() || m[x] == 1) {
    } else if (q.size() < k) {
      q.push_front(x);
      m[x] = 1;
    } else {
      long long int t = q[q.size() - 1];
      m.erase(t);
      q.pop_back();
      q.push_front(x);
      m[x] = 1;
    }
  }
  cout << q.size() << endl;
  for (i = 0; i < q.size(); i++) cout << q[i] << " ";
}

```


### Prompt

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

We have N points numbered 1 to N arranged in a line in this order.

Takahashi decides to make an undirected graph, using these points as the vertices. In the beginning, the graph has no edge. Takahashi will do M operations to add edges in this graph. The i-th operation is as follows:

* The operation uses integers L_i and R_i between 1 and N (inclusive), and a positive integer C_i. For every pair of integers (s, t) such that L_i \leq s < t \leq R_i, add an edge of length C_i between Vertex s and Vertex t.

The integers L_1, ..., L_M, R_1, ..., R_M, C_1, ..., C_M are all given as input.

Takahashi wants to solve the shortest path problem in the final graph obtained. Find the length of the shortest path from Vertex 1 to Vertex N in the final graph.

Constraints

* 2 \leq N \leq 10^5
* 1 \leq M \leq 10^5
* 1 \leq L_i < R_i \leq N
* 1 \leq C_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N M
L_1 R_1 C_1
:
L_M R_M C_M

Output

Print the length of the shortest path from Vertex 1 to Vertex N in the final graph. If there is no shortest path, print `-1` instead.

Examples

Input

4 3
1 3 2
2 4 3
1 4 6

Output

5

Input

4 2
1 2 1
3 4 2

Output

-1

Input

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

Output

28

### Response

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

const int MAXN = 100005;

int N, M, Li, Ri, Ci;
vector < pair <int, int> > evs[MAXN];

int main(){
	scanf("%d %d", &N, &M);
	while(M--){
		scanf("%d %d %d", &Li, &Ri, &Ci);
		Li--, Ri--;

		evs[Li].push_back(make_pair(Ri, Ci));
	}

	set < pair <long long, int> > S;
	S.insert(make_pair(0, 0));

	for(int i = 0; i < N; i++){
		while(!S.empty() && S.begin()->second < i)
			S.erase(S.begin());

		if(S.empty()){
			printf("-1\n");
			return 0;
		}

		long long dist = S.begin()->first;

		if(i == N - 1){
			printf("%lld\n", dist);
			return 0;
		}

		for(pair <int, int> e : evs[i])
			S.insert(make_pair(dist + e.second, e.first));
	}

	return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game.

Initially, Bob chooses integer m, bit depth of the game, which means that all numbers in the game will consist of m bits. Then he asks Peter to choose some m-bit number. After that, Bob computes the values of n variables. Each variable is assigned either a constant m-bit number or result of bitwise operation. Operands of the operation may be either variables defined before, or the number, chosen by Peter. After that, Peter's score equals to the sum of all variable values.

Bob wants to know, what number Peter needs to choose to get the minimum possible score, and what number he needs to choose to get the maximum possible score. In both cases, if there are several ways to get the same score, find the minimum number, which he can choose.

Input

The first line contains two integers n and m, the number of variables and bit depth, respectively (1 ≤ n ≤ 5000; 1 ≤ m ≤ 1000).

The following n lines contain descriptions of the variables. Each line describes exactly one variable. Description has the following format: name of a new variable, space, sign ":=", space, followed by one of:

  1. Binary number of exactly m bits.
  2. The first operand, space, bitwise operation ("AND", "OR" or "XOR"), space, the second operand. Each operand is either the name of variable defined before or symbol '?', indicating the number chosen by Peter.

Variable names are strings consisting of lowercase Latin letters with length at most 10. All variable names are different.

Output

In the first line output the minimum number that should be chosen by Peter, to make the sum of all variable values minimum possible, in the second line output the minimum number that should be chosen by Peter, to make the sum of all variable values maximum possible. Both numbers should be printed as m-bit binary numbers.

Examples

Input

3 3
a := 101
b := 011
c := ? XOR b

Output

011
100

Input

5 1
a := 1
bb := 0
cx := ? OR a
d := ? XOR ?
e := d AND bb

Output

0
0

Note

In the first sample if Peter chooses a number 0112, then a = 1012, b = 0112, c = 0002, the sum of their values is 8. If he chooses the number 1002, then a = 1012, b = 0112, c = 1112, the sum of their values is 15.

For the second test, the minimum and maximum sum of variables a, bb, cx, d and e is 2, and this sum doesn't depend on the number chosen by Peter, so the minimum Peter can choose is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int TYPE_CONSTANT = 0;
const int TYPE_OPERATION = 1;
const int OPERATION_AND = 0;
const int OPERATION_XOR = 1;
const int OPERATION_OR = 2;
struct Clause {
  int type;
  string constant;
  int op1, op2;
  int optype;
};
map<string, int> mp;
int getidx(const string& str) {
  if (str == "?") return 0;
  int& val = mp[str];
  if (val == 0) {
    val = mp.size();
  }
  return val;
}
bool isnumber(const string& str) {
  for (char c : str)
    if (c != '0' && c != '1') return false;
  return true;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<Clause> clauses(n + 1);
  for (int i = 0; i < n; ++i) {
    string aaa;
    cin >> aaa;
    Clause& c = clauses[getidx(aaa)];
    string __;
    cin >> __;
    string lhs;
    cin >> lhs;
    if (isnumber(lhs)) {
      c.type = TYPE_CONSTANT;
      c.constant = lhs;
    } else {
      c.type = TYPE_OPERATION;
      string optype, rhs;
      cin >> optype >> rhs;
      if (optype == "AND") {
        c.optype = OPERATION_AND;
      } else if (optype == "XOR") {
        c.optype = OPERATION_XOR;
      } else {
        c.optype = OPERATION_OR;
      }
      c.op1 = getidx(lhs);
      c.op2 = getidx(rhs);
    }
  }
  auto solvebit = [&](const int idx, const bool val) {
    vector<bool> values(n + 1);
    values[0] = val;
    for (int i = 1; i <= n; ++i) {
      Clause& c = clauses[i];
      if (c.type == TYPE_CONSTANT) {
        values[i] = c.constant[idx] == '1';
      } else {
        if (c.optype == OPERATION_AND) {
          values[i] = values[c.op1] && values[c.op2];
        } else if (c.optype == OPERATION_XOR) {
          values[i] = values[c.op1] != values[c.op2];
        } else {
          values[i] = values[c.op1] || values[c.op2];
        }
      }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) ans += values[i];
    return ans;
  };
  vector<bool> best(m);
  for (int i = 0; i < m; ++i) {
    if (solvebit(i, 1) < solvebit(i, 0)) {
      best[i] = true;
    }
  }
  for (int i = 0; i < m; ++i) cout << (best[i] ? '1' : '0');
  cout << endl;
  fill(best.begin(), best.end(), false);
  for (int i = 0; i < m; ++i) {
    if (solvebit(i, 1) > solvebit(i, 0)) {
      best[i] = true;
    }
  }
  for (int i = 0; i < m; ++i) cout << (best[i] ? '1' : '0');
  cout << endl;
}

```


### Prompt

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

Write a program which reads an integer n and draws a Koch curve based on recursive calles of depth n.

The Koch curve is well known as a kind of fractals.

You can draw a Koch curve in the following algorithm:

* Divide a given segment (p1, p2) into three equal segments.
* Replace the middle segment by the two sides of an equilateral triangle (s, u, t) of the same length as the segment.
* Repeat this procedure recursively for new segments (p1, s), (s, u), (u, t), (t, p2).

<image>

You should start (0, 0), (100, 0) as the first segment.

Notes

Constraints

* 0 ≤ n ≤ 6

Input

An integer n is given.

Output

Print each point (x, y) of the Koch curve. Print a point in a line. You should start the point(0, 0), which is the endpoint of the first segment and end with the point (100, 0), the other endpoint so that you can draw the Koch curve as an unbroken line. Each solution should be given as a decimal with an arbitrary number of fractional digits, and with an absolute error of at most 10-4.

Examples

Input

1

Output

0.00000000 0.00000000
33.33333333 0.00000000
50.00000000 28.86751346
66.66666667 0.00000000
100.00000000 0.00000000

Input

2

Output

0.00000000 0.00000000
11.11111111 0.00000000
16.66666667 9.62250449
22.22222222 0.00000000
33.33333333 0.00000000
38.88888889 9.62250449
33.33333333 19.24500897
44.44444444 19.24500897
50.00000000 28.86751346
55.55555556 19.24500897
66.66666667 19.24500897
61.11111111 9.62250449
66.66666667 0.00000000
77.77777778 0.00000000
83.33333333 9.62250449
88.88888889 0.00000000
100.00000000 0.00000000

### Response

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

struct P{
	double x,y;
};
const double th=M_PI*60.0/180.0;

void koch(int n,P a,P b){
	if(n==0)
		return ;
	P s,t,u;
	s.x=(2*a.x+b.x)/3;
	s.y=(2*a.y+b.y)/3;
	t.x=(a.x+2*b.x)/3;
	t.y=(a.y+2*b.y)/3;
	u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
	u.y=(t.y-s.y)*cos(th)+(t.x-s.x)*sin(th)+s.y;
	koch(n-1,a,s);
	printf("%.5f %.5f\n",s.x,s.y);
	koch(n-1,s,u);
	printf("%.5f %.5f\n",u.x,u.y);
	koch(n-1,u,t);
	printf("%.5f %.5f\n",t.x,t.y);
	koch(n-1,t,b);
}

int main(){
	int n;
	scanf("%d",&n);
	P a={0,0},b={100.0,0};
	printf("%.5f %.5f\n",a.x,a.y);
	koch(n,a,b);
	printf("%.5f %.5f\n",b.x,b.y);
	return 0;
}
```


### Prompt

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

Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string s = s_1 s_2 ... s_{n} of length n where each letter is either R, S or P.

While initializing, the bot is choosing a starting index pos (1 ≤ pos ≤ n), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of s_{pos}:

  * if s_{pos} is equal to R the bot chooses "Rock";
  * if s_{pos} is equal to S the bot chooses "Scissors";
  * if s_{pos} is equal to P the bot chooses "Paper";

In the second round, the bot's choice is based on the value of s_{pos + 1}. In the third round — on s_{pos + 2} and so on. After s_n the bot returns to s_1 and continues his game.

You plan to play n rounds and you've already figured out the string s but still don't know what is the starting index pos. But since the bot's tactic is so boring, you've decided to find n choices to each round to maximize the average number of wins.

In other words, let's suggest your choices are c_1 c_2 ... c_n and if the bot starts from index pos then you'll win in win(pos) rounds. Find c_1 c_2 ... c_n such that (win(1) + win(2) + ... + win(n))/(n) is maximum possible.

Input

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

Next t lines contain test cases — one per line. The first and only line of each test case contains string s = s_1 s_2 ... s_{n} (1 ≤ n ≤ 2 ⋅ 10^5; s_i ∈ \{R, S, P\}) — the string of the bot.

It's guaranteed that the total length of all strings in one test doesn't exceed 2 ⋅ 10^5.

Output

For each test case, print n choices c_1 c_2 ... c_n to maximize the average number of wins. Print them in the same manner as the string s.

If there are multiple optimal answers, print any of them.

Example

Input

3
RRRR
RSP
S

Output

PPPP
RSP
R

Note

In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all n = 4 rounds, so the average is also equal to 4.

In the second test case:

  * if bot will start from pos = 1, then (s_1, c_1) is draw, (s_2, c_2) is draw and (s_3, c_3) is draw, so win(1) = 0;
  * if bot will start from pos = 2, then (s_2, c_1) is win, (s_3, c_2) is win and (s_1, c_3) is win, so win(2) = 3;
  * if bot will start from pos = 3, then (s_3, c_1) is lose, (s_1, c_2) is lose and (s_2, c_3) is lose, so win(3) = 0;

The average is equal to (0 + 3 + 0)/(3) = 1 and it can be proven that it's the maximum possible average.

A picture from Wikipedia explaining "Rock paper scissors" game:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string solve(string &S) {
  int n = S.size();
  int r = 0, s = 0, p = 0;
  for (int i = 0; i < n; i++) {
    if (S[i] == 'R')
      r++;
    else if (S[i] == 'S')
      s++;
    else
      p++;
  }
  vector<pair<int, char>> ranks(3);
  ranks[0] = make_pair(r, 'P');
  ranks[1] = make_pair(s, 'R');
  ranks[2] = make_pair(p, 'S');
  sort(ranks.begin(), ranks.end());
  string ans = "";
  while (n > 0) {
    ans += ranks[2].second;
    n--;
  }
  return ans;
}
int main() {
  int t;
  cin >> t;
  cin.ignore(numeric_limits<streamsize>::max(), '\n');
  while (t--) {
    string S;
    getline(cin, S);
    cout << solve(S) << endl;
  }
}

```


### Prompt

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

Tree is a connected acyclic graph. Suppose you are given a tree consisting of n vertices. The vertex of this tree is called centroid if the size of each connected component that appears if this vertex is removed from the tree doesn't exceed <image>.

You are given a tree of size n and can perform no more than one edge replacement. Edge replacement is the operation of removing one edge from the tree (without deleting incident vertices) and inserting one new edge (without adding new vertices) in such a way that the graph remains a tree. For each vertex you have to determine if it's possible to make it centroid by performing no more than one edge replacement.

Input

The first line of the input contains an integer n (2 ≤ n ≤ 400 000) — the number of vertices in the tree. Each of the next n - 1 lines contains a pair of vertex indices ui and vi (1 ≤ ui, vi ≤ n) — endpoints of the corresponding edge.

Output

Print n integers. The i-th of them should be equal to 1 if the i-th vertex can be made centroid by replacing no more than one edge, and should be equal to 0 otherwise.

Examples

Input

3
1 2
2 3

Output

1 1 1

Input

5
1 2
1 3
1 4
1 5

Output

1 0 0 0 0

Note

In the first sample each vertex can be made a centroid. For example, in order to turn vertex 1 to centroid one have to replace the edge (2, 3) with the edge (1, 3).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> E[400000 + 5];
int dp[400000 + 5];
int max1[400000 + 5];
int max2[400000 + 5];
int sz[400000 + 5];
void dfs1(int x, int fa) {
  sz[x] = 1;
  dp[x] = 0;
  for (int y : E[x]) {
    if (y != fa) {
      dfs1(y, x);
      sz[x] += sz[y];
      if (dp[y] > dp[x]) {
        dp[x] = dp[y];
        max2[x] = max1[x];
        max1[x] = y;
      } else if (dp[y] > dp[max2[x]])
        max2[x] = y;
    }
  }
  if (sz[x] <= n / 2) dp[x] = sz[x];
}
int ans[400000 + 5];
void dfs2(int x, int fa, int pre) {
  int flag = 1;
  for (int y : E[x]) {
    if (y == fa) {
      if (n - sz[x] > n / 2 && n - sz[x] - pre > n / 2) flag = 0;
    } else if (sz[y] > n / 2) {
      if (sz[y] - dp[y] > n / 2) flag = 0;
    }
  }
  ans[x] = flag;
  for (int y : E[x]) {
    if (y != fa) {
      int tmp;
      if (n - sz[y] <= n / 2)
        tmp = n - sz[y];
      else {
        if (y == max1[x])
          tmp = max(pre, dp[max2[x]]);
        else
          tmp = max(pre, dp[max1[x]]);
      }
      dfs2(y, x, tmp);
    }
  }
}
int main() {
  int u, v;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &u, &v);
    E[u].push_back(v);
    E[v].push_back(u);
  }
  dfs1(1, 0);
  dfs2(1, 0, 0);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}

```


### Prompt

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

Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) — mathematical expectation of the minimal element among all k-element subsets.

But only function does not interest him. He wants to do interesting things with it. Mom brought him two arrays A and B, each consists of m integers. For all i, j such that 1 ≤ i, j ≤ m the condition Ai ≥ Bj holds. Help Leha rearrange the numbers in the array A so that the sum <image> is maximally possible, where A' is already rearranged array.

Input

First line of input data contains single integer m (1 ≤ m ≤ 2·105) — length of arrays A and B.

Next line contains m integers a1, a2, ..., am (1 ≤ ai ≤ 109) — array A.

Next line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 109) — array B.

Output

Output m integers a'1, a'2, ..., a'm — array A' which is permutation of the array A.

Examples

Input

5
7 3 5 3 4
2 1 3 2 3

Output

4 7 3 5 3

Input

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

Output

2 6 4 5 8 8 6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2 * 1e5 + 190;
int n, A[maxN], ans[maxN];
pair<int, int> B[maxN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> A[i];
  for (int i = 0; i < n; ++i) {
    cin >> B[i].first;
    B[i].second = i;
  }
  sort(A, A + n);
  sort(B, B + n);
  for (int i = 0; i < n; ++i) ans[B[n - i - 1].second] = A[i];
  for (int i = 0; i < n; ++i) cout << ans[i] << " ";
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Allen and Bessie are playing a simple number game. They both know a function f: \{0, 1\}^n → R, i. e. the function takes n binary arguments and returns a real value. At the start of the game, the variables x_1, x_2, ..., x_n are all set to -1. Each round, with equal probability, one of Allen or Bessie gets to make a move. A move consists of picking an i such that x_i = -1 and either setting x_i → 0 or x_i → 1.

After n rounds all variables are set, and the game value resolves to f(x_1, x_2, ..., x_n). Allen wants to maximize the game value, and Bessie wants to minimize it.

Your goal is to help Allen and Bessie find the expected game value! They will play r+1 times though, so between each game, exactly one value of f changes. In other words, between rounds i and i+1 for 1 ≤ i ≤ r, f(z_1, ..., z_n) → g_i for some (z_1, ..., z_n) ∈ \{0, 1\}^n. You are to find the expected game value in the beginning and after each change.

Input

The first line contains two integers n and r (1 ≤ n ≤ 18, 0 ≤ r ≤ 2^{18}).

The next line contains 2^n integers c_0, c_1, ..., c_{2^n-1} (0 ≤ c_i ≤ 10^9), denoting the initial values of f. More specifically, f(x_0, x_1, ..., x_{n-1}) = c_x, if x = \overline{x_{n-1} … x_0} in binary.

Each of the next r lines contains two integers z and g (0 ≤ z ≤ 2^n - 1, 0 ≤ g ≤ 10^9). If z = \overline{z_{n-1} ... z_0} in binary, then this means to set f(z_0, ..., z_{n-1}) → g.

Output

Print r+1 lines, the i-th of which denotes the value of the game f during the i-th round. Your answer must have absolute or relative error within 10^{-6}.

Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if \frac{|a - b|}{max{(1, |b|)}} ≤ 10^{-6}.

Examples

Input

2 2
0 1 2 3
2 5
0 4

Output

1.500000
2.250000
3.250000

Input

1 0
2 3

Output

2.500000

Input

2 0
1 1 1 1

Output

1.000000

Note

Consider the second test case. If Allen goes first, he will set x_1 → 1, so the final value will be 3. If Bessie goes first, then she will set x_1 → 0 so the final value will be 2. Thus the answer is 2.5.

In the third test case, the game value will always be 1 regardless of Allen and Bessie's play.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
map<long long, int> m;
int main() {
  int n, r;
  long long z, g;
  long long sum = 0;
  scanf("%d%d", &n, &r);
  for (long long i = 0; i < pow(2, n); i++) {
    scanf("%d", &m[i]);
    sum += m[i];
  }
  printf("%f\n", sum / pow(2, n));
  while (r--) {
    scanf("%lld%lld", &z, &g);
    sum += g - m[z];
    m[z] = g;
    printf("%f\n", sum / pow(2, n));
  }
}

```