### Prompt

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

Mayor of Yusland just won the lottery and decided to spent money on something good for town. For example, repair all the roads in the town.

Yusland consists of n intersections connected by n - 1 bidirectional roads. One can travel from any intersection to any other intersection using only these roads.

There is only one road repairing company in town, named "RC company". Company's center is located at the intersection 1. RC company doesn't repair roads you tell them. Instead, they have workers at some intersections, who can repair only some specific paths. The i-th worker can be paid ci coins and then he repairs all roads on a path from ui to some vi that lies on the path from ui to intersection 1.

Mayor asks you to choose the cheapest way to hire some subset of workers in order to repair all the roads in Yusland. It's allowed that some roads will be repaired more than once.

If it's impossible to repair all roads print  - 1.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 300 000) — the number of cities in Yusland and the number of workers respectively.

Then follow n−1 line, each of them contains two integers xi and yi (1 ≤ xi, yi ≤ n) — indices of intersections connected by the i-th road.

Last m lines provide the description of workers, each line containing three integers ui, vi and ci (1 ≤ ui, vi ≤ n, 1 ≤ ci ≤ 109). This means that the i-th worker can repair all roads on the path from vi to ui for ci coins. It's guaranteed that vi lies on the path from ui to 1. Note that vi and ui may coincide.

Output

If it's impossible to repair all roads then print  - 1. Otherwise print a single integer — minimum cost required to repair all roads using "RC company" workers.

Example

Input

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

Output

8

Note

In the first sample, we should choose workers with indices 1, 3, 4 and 5, some roads will be repaired more than once but it is OK. The cost will be equal to 2 + 3 + 1 + 2 = 8 coins.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10;
const long long MX = 1e18;
long long n, m, maper, dp[MAXN], seg[4 * MAXN], lazy[4 * MAXN];
long long heavy[MAXN], l_[MAXN], r_[MAXN];
struct worker {
  long long w = 0, id = 0;
  worker(int c) { w = c; }
};
vector<worker> workers;
vector<int> be[MAXN], en[MAXN];
vector<int> adj[MAXN];
void dfs(int v, int par = 0) {
  int local = -1;
  l_[v] = m + 10;
  for (auto i : adj[v])
    if (i != par) {
      dfs(i, v);
      l_[v] = min(l_[v], l_[i]);
    }
  l_[v] = min(l_[v], maper + 1);
  for (auto i : be[v]) workers[i].id = ++maper;
  r_[v] = maper;
}
void add(int s, int e, long long val, int l = 1, int r = maper + 1,
         int id = 1) {
  if (l >= e || r <= s) return;
  if (l >= s && r <= e) {
    lazy[id] += val;
    seg[id] += val;
    lazy[id] = min(lazy[id], MX);
    seg[id] = min(seg[id], MX);
    return;
  }
  int mid = l + r >> 1;
  add(s, e, val, l, mid, id << 1);
  add(s, e, val, mid, r, id << 1 | 1);
  seg[id] = min(seg[id << 1], seg[id << 1 | 1]);
  seg[id] += lazy[id];
  seg[id] = min(MX, seg[id]);
}
void change(int s, int e, long long val, int l = 1, int r = maper + 1,
            int id = 1) {
  if (l >= e || r <= s) return;
  if (l >= s && r <= e) {
    lazy[id] = val;
    seg[id] = val;
    return;
  }
  int mid = l + r >> 1;
  change(s, e, val, l, mid, id << 1);
  change(s, e, val, mid, r, id << 1 | 1);
  seg[id] = min(seg[id << 1], seg[id << 1 | 1]);
  seg[id] += lazy[id];
  seg[id] = min(MX, seg[id]);
}
long long get(int s, int e, int l = 1, int r = maper + 1, int id = 1) {
  if (l >= e || r <= s) return MX;
  if (l >= s && r <= e) return seg[id];
  int mid = l + r >> 1;
  long long mn = MX;
  mn = min(mn, get(s, e, l, mid, id << 1));
  mn = min(mn, get(s, e, mid, r, id << 1 | 1));
  mn += lazy[id];
  mn = min(mn, MX);
  return mn;
}
void solve(int v, int par = 0) {
  if (!(adj[v].size() - 1 + (!par))) {
    long long mini = MX;
    dp[v] = MX;
    for (auto i : be[v]) mini = min(mini, workers[i].w);
    for (auto i : be[v]) change(workers[i].id, workers[i].id + 1, workers[i].w);
    dp[v] = mini;
    return;
  }
  for (auto i : adj[v])
    if (i != par) solve(i, v);
  long long pre = 0;
  for (auto i : adj[v])
    if (i != par) {
      add(l_[i], r_[i] + 1, pre);
      pre += dp[i];
      pre = min(pre, MX);
    }
  pre = 0;
  reverse(adj[v].begin(), adj[v].end());
  for (auto i : adj[v])
    if (i != par) {
      add(l_[i], r_[i] + 1, pre);
      pre += dp[i];
      pre = min(pre, MX);
    }
  long long mini = MX;
  dp[v] = MX;
  if (!par) {
    mini = 0;
    dp[v] = pre;
  }
  for (auto i : be[v]) mini = min(mini, (long long)workers[i].w);
  dp[v] = min(dp[v], mini + get(l_[v], r_[v] + 1));
  for (auto i : en[v]) change(workers[i].id, workers[i].id + 1, MX);
  dp[v] = min(dp[v], get(l_[v], r_[v] + 1));
  for (auto i : be[v])
    change(workers[i].id, workers[i].id + 1, pre + workers[i].w);
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  if (n == 1) return cout << 0 << endl, 0;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 0; i < m; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    workers.push_back(worker(c));
    if (u != v) {
      en[v].push_back(i);
      be[u].push_back(i);
    }
  }
  for (int i = 1; i < 4 * MAXN; i++) seg[i] = MX;
  dfs(1);
  solve(1);
  if (dp[1] == MX) dp[1] = -1;
  cout << dp[1] << endl;
  cin >> n;
  return 0;
}

```


### Prompt

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

There is a tree with N vertices numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.

Initially, each edge is painted blue. Takahashi will convert this blue tree into a red tree, by performing the following operation N-1 times:

* Select a simple path that consists of only blue edges, and remove one of those edges.
* Then, span a new red edge between the two endpoints of the selected path.

His objective is to obtain a tree that has a red edge connecting vertices c_i and d_i, for each i.

Determine whether this is achievable.

Constraints

* 2 ≤ N ≤ 10^5
* 1 ≤ a_i,b_i,c_i,d_i ≤ N
* a_i ≠ b_i
* c_i ≠ d_i
* Both input graphs are trees.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
:
a_{N-1} b_{N-1}
c_1 d_1
:
c_{N-1} d_{N-1}

Output

Print `YES` if the objective is achievable; print `NO` otherwise.

Examples

Input

3
1 2
2 3
1 3
3 2

Output

YES

Input

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

Output

YES

Input

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

Output

NO

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
#define N 111116
typedef pair<int,int> edge;

int n,f[N];
multiset<int> s[N];
map<edge,int> h;
queue<edge> q;

edge make(int x,int y){
	if (x>y) swap(x,y);
	return edge(x,y);
}

int find(int x){
	if (f[x]==x) return x;
	return f[x]=find(f[x]);
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();
	for (int i=1;i<=2*n-2;i++){
		int x=read(),y=read();edge e=make(x,y);
		s[x].insert(y);s[y].insert(x);
		if (++h[e]==2) q.push(e);
	}
	for (int i=1;i<=n;i++) f[i]=i;
	for (int i=1;i<=n-1;i++){
		int x=0,y=0;
		while (x==y){
			if (q.empty()) {printf("NO\n");return 0;};
			x=find(q.front().first);y=find(q.front().second);q.pop();
		}
		if (s[x].size()>s[y].size()) swap(x,y);f[x]=y;
		for (set<int>::iterator i=s[x].begin();i!=s[x].end();i++){
			int z=find(*i);edge e=make(y,z);
			if (y==z) continue;
			s[y].insert(z);s[z].insert(y);
			if (++h[e]==2) q.push(e);
			s[z].erase(s[z].find(x));
		}
		s[y].erase(s[y].find(x));s[x].clear();
	}
	printf("YES\n");return 0;
}
```


### Prompt

Please formulate a CPP solution to the following problem:

Hit n nails one by one at the coordinates P1 (x1, y1), P2 (x2, y2), P3 (x3, y3), ..., Pn (xn, yn) on the flat plate, and put them on the rubber band ring. Surround it with a single rubber band so that all the nails fit inside. At this time, the rubber bands must not intersect.

Create a program that reads the coordinates of the nails and outputs the number of nails that are not in contact with the rubber band when the nail is surrounded by the rubber band as described above. The rubber band shall expand and contract sufficiently. You may not hit more than one nail at the same coordinates. In addition, it is assumed that the nails covered with rubber bands are connected by a straight line, and that no more than three nails are lined up on the straight line. For example, there can be no input as shown in Figure 1. As shown in Figure 2, it is possible for nails without rubber bands to line up in a straight line.

<image> | <image>
--- | ---
Figure 1 | Figure 2

However, each coordinate value is a real number between -1000.0 and 1000.0. Also, n is an integer between 3 and 100.

Hint

Below is a diagram for the second sample input.

<image>
---

Input

Given multiple datasets. Each dataset is given in the following format:

n
x1, y1
x2, y2
...
...
xn, yn

When n is 0, it indicates the end of input. The number of datasets does not exceed 50.

Output

For each dataset, output the number of nails that are not in contact with the rubber. For example, if there is an input representing the four nails shown in Fig. 3, it will be surrounded as shown in Fig. 4, so the number of nails that are not in contact with the rubber band is one.

<image> | <image>
--- | ---
Figure 3 | Figure 4

Example

Input

4
1.0,0.0
0.0,1.0
2.0,1.0
1.0,2.0
9
-509.94,892.63
567.62,639.99
-859.32,-64.84
-445.99,383.69
667.54,430.49
551.12,828.21
-940.2,-877.2
-361.62,-970
-125.42,-178.48
0

Output

0
3

### Response

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

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=a;i--)
#define per(i,b) gnr(i,0,b)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define fs first
#define sc second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif
#define tmp template<class t>

tmp void chmax(t&a,t b){if(a<b)a=b;}
tmp void chmin(t&a,t b){if(a>b)a=b;}

tmp using vc=vector<t>;
tmp using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.fs<<","<<p.sc<<"}";
}

tmp ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

constexpr ll ten(int n){
	return n==0?1:ten(n-1)*10;
}

tmp void mkuni(vc<t>&v){
	sort(all(v));
	v.erase(unique(all(v)),v.ed);
}

ll read(){ll i;cin>>i;return i;}

using ld=long double;
using cm=complex<ld>;
#define x real()
#define y imag()
const ld eps=1e-7;
int sgn(ld a){return a<-eps?-1:(a>eps?1:0);}
auto cmcmp=[](const cm&a,const cm&b){
	if(sgn(a.x-b.x))return a.x<b.x;
	else return sgn(a.y-b.y)<0;
};

ld dot(cm a,cm b){return a.x*b.x+a.y*b.y;}
ld crs(cm a,cm b){return a.x*b.y-a.y*b.x;}
int ccw(cm a,cm b){return sgn(crs(a,b));}
int ccw(cm a,cm b,cm c){return ccw(b-a,c-a);}

//(-2)[a,-1](0)[b,1](2)
int bet(cm a,cm b,cm c){
	cm d=b-a;
	ld e=dot(d,c-a);
	if(sgn(e)<=0)return sgn(e)-1;
	return sgn(e-norm(d))+1;
}

ld tri2(cm a,cm b,cm c){
	return crs(b-a,c-a);
}

//0-no,1-edge,2-in
int cont(cm a,cm b,cm c,cm d){
	if(ccw(a,b,c)==-1)
		swap(b,c);
	return min({ccw(a,b,d),ccw(b,c,d),ccw(c,a,d)})+1;
}

//no point in edges
vc<cm> convex(vc<cm> s){
	swap(s[0],*min_element(all(s),cmcmp));
	sort(s.bg+1,s.ed,[&](cm a,cm b){
		int c=ccw(s[0],a,b);
		if(c)return c==1;
		else return bet(s[0],a,b)==2;
	});
	vc<cm> t;
	rep(i,s.size()){
		int ss;
		while((ss=t.size())>=2){
			cm a=t[ss-2];
			cm b=t[ss-1];
			cm c=s[i];
			if(ccw(a,b,c)>0)
				break;
			t.pop_back();
		}
		t.pb(s[i]);
	}
	return t;
}

cm readcm(){
	ld a,b;
	char c;
	cin>>a>>c>>b;
	return cm(a,b);
}

ld readld(){
	ld a;
	cin>>a;
	return a;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	while(1){
		int n=read();
		if(n==0)break;
		vc<cm> s(n);
		rep(i,n)
			s[i]=readcm();
		cout<<n-convex(s).size()<<endl;
	}
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

The athletics competition 200M semi-final three races were held. Eight players (24 players in total) will participate in each group. A total of eight players, including the top two players in each group and the top two players from all the players in each group who are third or lower, will advance to the final.

Create a program that inputs the player numbers and times and outputs the numbers and times of the eight finalists.

Input

The input is given in the following format:

p1 t1
p2 t2
::
p24 t24

Lines 1-8, 1st set player number pi (integer, 1 ≤ pi ≤ 10000) and time ti (real number measured to 1/100, 1 ≤ ti ≤ 100), lines 9-16 Is given the player number pi and time ti of the second group, and the player number pi and time ti of the third group on the 17th to 24th lines. It is assumed that there are no players with the same player number or the same time.

Output

In the following order, please output the player numbers and times of the finalists on one line, separated by blanks.

1st place player in the 1st group
2nd place player in the 1st group
1st place player in the 2nd group
2nd place player in the 2nd group
1st place player in the 3rd group
Second place player in the third group
The player with the fastest time among the players who are 3rd or lower in each group
The player with the second fastest time among the players who are third or lower in each group

Example

Input

18 25.46
16 26.23
3 23.00
10 24.79
5 22.88
11 23.87
19 23.90
1 25.11
23 23.88
4 23.46
7 24.12
12 22.91
13 21.99
14 22.86
21 23.12
9 24.09
17 22.51
22 23.49
6 23.02
20 22.23
24 21.89
15 24.14
8 23.77
2 23.42

Output

5 22.88
3 23.00
13 21.99
14 22.86
24 21.89
20 22.23
17 22.51
12 22.91

### Response

```cpp
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<double,int> P;

int main(){
  P a[3][8];
  vector <P> b,ans;
  for(int i=0;i<3;i++){
    for(int j=0;j<8;j++) cin>>a[i][j].s>>a[i][j].f;
    sort(a[i],a[i]+8);
    ans.push_back(a[i][0]);
    ans.push_back(a[i][1]);
    for(int j=2;j<8;j++) b.push_back(a[i][j]);
  }
  sort(b.begin(),b.end());
  ans.push_back(b[0]);
  ans.push_back(b[1]);
  for(int i=0;i<8;i++) cout <<ans[i].s<<" "<<ans[i].f<<endl;

  return 0;
}
```


### Prompt

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

Today is Matvey's birthday. He never knows what to ask as a present so friends gave him a string s of length n. This string consists of only first eight English letters: 'a', 'b', ..., 'h'.

First question that comes to mind is: who might ever need some string? Matvey is a special boy so he instantly found what to do with this string. He used it to build an undirected graph where vertices correspond to position in the string and there is an edge between distinct positions a and b (1 ≤ a, b ≤ n) if at least one of the following conditions hold:

  1. a and b are neighbouring, i.e. |a - b| = 1.
  2. Positions a and b contain equal characters, i.e. sa = sb.

Then Matvey decided to find the diameter of this graph. Diameter is a maximum distance (length of the shortest path) among all pairs of vertices. Also, Matvey wants to find the number of pairs of vertices such that the distance between them is equal to the diameter of the graph. As he is very cool and experienced programmer he managed to solve this problem very fast. Will you do the same?

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the length of the string.

The second line contains the string s itself. It's guaranteed that s consists of only first eight letters of English alphabet.

Output

Print two integers — the diameter of the graph and the number of pairs of positions with the distance equal to the diameter.

Examples

Input

3
abc

Output

2 1

Input

7
aaabaaa

Output

2 4

Note

Consider the second sample.

The maximum distance is 2. It's obtained for pairs (1, 4), (2, 4), (4, 6) and (4, 7).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int gi() {
  int res = 0, s = 1;
  char ch;
  for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
    ;
  if (ch == '-') s = -1, ch = getchar();
  for (; ch >= '0' && ch <= '9'; ch = getchar()) res = res * 10 + ch - 48;
  return res * s;
}
int n, m, dis[100010][9], d[9][9], last[9], c[100010], que[100010 << 2], h, t,
    mask[100010], tong[9][280];
long long sum[20];
char str[100010];
void init() {
  memset(dis, 0x3f3f3f3f, sizeof(dis));
  memset(d, 0x3f3f3f3f, sizeof(d));
  memset(tong, 0, sizeof(tong));
  memset(mask, 0, sizeof(mask));
  memset(sum, 0, sizeof(sum));
}
int main() {
  n = gi();
  m = 8;
  scanf("%s", str + 1);
  for (int i = 1; i <= n; ++i) c[i] = str[i] - 'a' + 1;
  init();
  for (int i = 1; i <= m; ++i) {
    que[h = t = n + m] = n + i, d[i][i] = 0;
    while (h <= t) {
      int p = que[h];
      h++;
      if (p > n) {
        for (int j = 1; j <= n; ++j)
          if (c[j] == p - n && dis[j][i] > d[p - n][i])
            dis[j][i] = d[p - n][i], que[--h] = j;
      } else {
        if (p > 1 && dis[p - 1][i] > dis[p][i] + 1)
          dis[p - 1][i] = dis[p][i] + 1, que[++t] = p - 1;
        if (p < n && dis[p + 1][i] > dis[p][i] + 1)
          dis[p + 1][i] = dis[p][i] + 1, que[++t] = p + 1;
        if (d[c[p]][i] > dis[p][i] + 1)
          d[c[p]][i] = dis[p][i] + 1, que[++t] = c[p] + n;
      }
    }
  }
  for (int i = 1; i <= m; ++i) {
    d[i][i] = 0;
    for (int j = 1; j <= m; ++j)
      if (i != j) d[i][j]--;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (dis[i][j] > d[c[i]][j]) mask[i] |= (1 << (j - 1));
  for (int i = 1; i <= n; ++i) {
    if (i > 2 * m) {
      for (int sub = mask[i - 2 * m]; sub; sub = (sub - 1) & mask[i - 2 * m])
        tong[c[i - 2 * m]][sub]++;
      tong[c[i - 2 * m]][0]++;
    }
    for (int j = 1; j <= 2 * m - 1 && j < i; ++j) {
      int ds = j;
      for (int trans = 1; trans <= m; ++trans)
        ds = min(ds, dis[i - j][trans] + dis[i][trans] + 1);
      sum[ds]++;
    }
    for (int to = 1; to <= m; ++to) {
      int ds = 0x3f3f3f3f, sub = 0;
      for (int trans = 1; trans <= m; ++trans)
        ds = min(ds, dis[i][trans] + d[trans][to] + 1);
      if (ds > 2 * m - 1) continue;
      for (int trans = 1; trans <= m; ++trans)
        if (dis[i][trans] + d[trans][to] + 1 == ds) sub |= (1 << (trans - 1));
      sum[ds] += tong[to][0] - tong[to][sub];
      sum[ds + 1] += tong[to][sub];
    }
  }
  for (int i = 2 * m - 1; i >= 0; --i)
    if (sum[i] > 0) {
      printf("%d %I64d\n", i, sum[i]);
      break;
    }
  return 0;
}

```


### Prompt

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

You are the God of Wind.

By moving a big cloud around, you can decide the weather: it invariably rains under the cloud, and the sun shines everywhere else.

But you are a benign God: your goal is to give enough rain to every field in the countryside, and sun to markets and festivals. Small humans, in their poor vocabulary, only describe this as “weather forecast”.

You are in charge of a small country, called Paccimc. This country is constituted of 4 × 4 square areas, denoted by their numbers.

<image>

Your cloud is of size 2 × 2, and may not cross the borders of the country.

You are given the schedule of markets and festivals in each area for a period of time.

On the first day of the period, it is raining in the central areas (6-7-10-11), independently of the schedule.

On each of the following days, you may move your cloud by 1 or 2 squares in one of the four cardinal directions (North, West, South, and East), or leave it in the same position. Diagonal moves are not allowed. All moves occur at the beginning of the day.

You should not leave an area without rain for a full week (that is, you are allowed at most 6 consecutive days without rain). You don’t have to care about rain on days outside the period you were given: i.e. you can assume it rains on the whole country the day before the period, and the day after it finishes.

Input

The input is a sequence of data sets, followed by a terminating line containing only a zero.

A data set gives the number N of days (no more than 365) in the period on a single line, followed by N lines giving the schedule for markets and festivals. The i-th line gives the schedule for the i-th day. It is composed of 16 numbers, either 0 or 1, 0 standing for a normal day, and 1 a market or festival day. The numbers are separated by one or more spaces.

Output

The answer is a 0 or 1 on a single line for each data set, 1 if you can satisfy everybody, 0 if there is no way to do it.

Example

Input

1
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
7
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1
0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1
0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0
0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0
7
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0
0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0
0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
15
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0
0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0
1 0 0 1 1 0 0 0 0 1 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0
0

Output

0
1
0
1

### Response

```cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

struct info{
    int n,w,s,e,p;
    info(int n, int w, int s, int e, int p):n(n), w(w), s(s), e(e), p(p){}
    info(){}
    void decrease(){
        n--; w--; s--; e--;
    }
    bool isvalid(){
        return n>0 && w>0 && s>0 && e>0;
    }
    bool operator < (const info &a) const{
        return (n +(w<<3) +(s<<6) +(e<<9) +(p<<12)) < (a.n +(a.w<<3) +(a.s<<6) +(a.e<<9) +(a.p<<12));
    }
};

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

        vector<vector<int> > w(n, vector<int>(17));
        for(int i=0; i<n; i++){
            for(int j=1; j<=16; j++){
                cin >> w[i][j];
            }
        }
        set<info> s;
        if(w[0][6] +w[0][7] +w[0][10] +w[0][11] == 0){
            s.insert(info(6, 6, 6, 6, 6));
        }
        for(int i=1; i<n; i++){
            set<info> ns;
            for(set<info>::iterator itr=s.begin(); itr != s.end(); itr++){
                info e = *itr;
                int x = (e.p -1) %4;
                int y = (e.p -1) /4;
                e.decrease();
                for(int d=0; d<4; d++){
                    for(int t=(d==0)?0:1; t<=2; t++){
                        int nx = x +t*dx[d];
                        int ny = y +t*dy[d];
                        info ni = e;
                        ni.p = 4*ny +nx +1;
                        if(nx<0 || nx>2 || ny<0 || ny>2) break;
                        if(w[i][ni.p] +w[i][ni.p+1] +w[i][ni.p+4] +w[i][ni.p+5] > 0) continue;
                        if(ni.p == 1) ni.n = 7;
                        if(ni.p == 3) ni.w = 7;
                        if(ni.p == 9) ni.s = 7;
                        if(ni.p == 11) ni.e = 7;
                        if(ni.isvalid()) ns.insert(ni);
                    }
                }
            }
            s = ns;
        }

        if(s.size()!=0){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
    }
    return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

For given three points p1, p2, p, find the reflection point x of p onto p1p2.

<image>

Constraints

* 1 ≤ q ≤ 1000
* -10000 ≤ xi, yi ≤ 10000
* p1 and p2 are not identical.

Input

xp1 yp1 xp2 yp2
q
xp0 yp0
xp1 yp1
...
xpq−1 ypq−1

In the first line, integer coordinates of p1 and p2 are given. Then, q queries are given for integer coordinates of p.

Output

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

Examples

Input

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

Output

-1.0000000000 -1.0000000000
0.0000000000 -1.0000000000
1.0000000000 -1.0000000000

Input

0 0 3 4
3
2 5
1 4
0 3

Output

4.2400000000 3.3200000000
3.5600000000 2.0800000000
2.8800000000 0.8400000000

### Response

```cpp
#include<stdio.h>
#include<math.h>

using namespace std;

int main(){
    const double dTolerance = 1.0e-10;
    double x1, x2, y1, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    int q;
    scanf("%d", &q);

    for (int i = 0; i < q; i++){
        double x, y;
        scanf("%lf %lf", &x, &y);
        if (fabs(x1 - x2) < dTolerance) {
            printf("%.10lf %.10lf\n", 2 * x1 - x, y);
        } else if (fabs(y1 - y2) < dTolerance){
            printf("%.10lf %.10lf\n", x, 2 * y1 - y);
        } else {
            double dt = ((x2 - x1) * (x2 - x) + (y2 - y1) * (y2 - y)) / ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
            double ds = ((x2 - x1) * (x - x1) + (y2 - y1) * (y - y1)) / ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
            printf("%.10lf %.10lf\n", 2 * (dt * x1 + ds * x2) - x, 2 * (dt * y1 + ds * y2) - y);
        }
    }
    return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

The subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

You are given an integer n.

You have to find a sequence s consisting of digits \{1, 3, 7\} such that it has exactly n subsequences equal to 1337.

For example, sequence 337133377 has 6 subsequences equal to 1337:

  1. 337\underline{1}3\underline{3}\underline{3}7\underline{7} (you can remove the second and fifth characters);
  2. 337\underline{1}\underline{3}3\underline{3}7\underline{7} (you can remove the third and fifth characters);
  3. 337\underline{1}\underline{3}\underline{3}37\underline{7} (you can remove the fourth and fifth characters);
  4. 337\underline{1}3\underline{3}\underline{3}\underline{7}7 (you can remove the second and sixth characters);
  5. 337\underline{1}\underline{3}3\underline{3}\underline{7}7 (you can remove the third and sixth characters);
  6. 337\underline{1}\underline{3}\underline{3}3\underline{7}7 (you can remove the fourth and sixth characters).

Note that the length of the sequence s must not exceed 10^5.

You have to answer t independent queries.

Input

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

Next t lines contains a description of queries: the i-th line contains one integer n_i (1 ≤ n_i ≤ 10^9).

Output

For the i-th query print one string s_i (1 ≤ |s_i| ≤ 10^5) consisting of digits \{1, 3, 7\}. String s_i must have exactly n_i subsequences 1337. If there are multiple such strings, print any of them.

Example

Input

2
6
1

Output

113337
1337

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0, ff = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar();
  return sum * ff;
}
const int mod = 1e9 + 7;
const int mo = 998244353;
const int N = 1e5 + 5;
int n, Q;
int main() {
  Q = read();
  for (int q = (1); q <= (Q); q++) {
    n = read();
    int gs1 = 0, gs7 = 0, gs3 = 0;
    int siz = sqrt(2 * n);
    for (int i = (siz); i <= (n * 2); i++) {
      if (i * (i - 1) > 2 * n) break;
      int tmp = i * (i - 1) / 2;
      gs7 = n - tmp;
      gs3 = i;
    }
    printf("133");
    for (int i = (1); i <= (gs7); i++) putchar('7');
    for (int i = (1); i <= (gs3 - 2); i++) putchar('3');
    putchar('7');
    puts("");
  }
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Eshag has an array a consisting of n integers.

Eshag can perform the following operation any number of times: choose some subsequence of a and delete every element from it which is strictly larger than AVG, where AVG is the average of the numbers in the chosen subsequence.

For example, if a = [1 , 4 , 3 , 2 , 4] and Eshag applies the operation to the subsequence containing a_1, a_2, a_4 and a_5, then he will delete those of these 4 elements which are larger than (a_1+a_2+a_4+a_5)/(4) = 11/4, so after the operation, the array a will become a = [1 , 3 , 2].

Your task is to find the maximum number of elements Eshag can delete from the array a by applying the operation described above some number (maybe, zero) times.

A sequence b is a subsequence of an array c if b can be obtained from c by deletion of several (possibly, zero or all) elements.

Input

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

The first line of each test case contains an integer n (1≤ n≤ 100) — the length of the array a.

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

Output

For each test case print a single integer — the maximum number of elements Eshag can delete from the array a.

Example

Input

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

Output

3
0
3

Note

Consider the first test case.

Initially a = [1, 1, 1, 2, 2, 3].

In the first operation, Eshag can choose the subsequence containing a_1, a_5 and a_6, their average is equal to (a_1 + a_5 + a_6)/(3) = 6/3 = 2. So a_6 will be deleted.

After this a = [1, 1, 1, 2, 2].

In the second operation, Eshag can choose the subsequence containing the whole array a, the average of all its elements is equal to 7/5. So a_4 and a_5 will be deleted.

After this a = [1, 1, 1].

In the second test case, Eshag can't delete any element.

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while(t--)
    {
        int n;
        cin >> n;
        int a, cnt[104]={0}, i, j, k, mx=-5, mn=999;

        for(i=0; i<n; i++){
            cin >> a;
            if(a<mn)
                mn = a;
            cnt[a]++;
        }
        cout << (n-cnt[mn]) << endl;
    }

}

```


### Prompt

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

Winters are just damn freezing cold in Nvodsk! That's why a group of n friends prefers to take a taxi, order a pizza and call girls. The phone numbers in the city consist of three pairs of digits (for example, 12-34-56). Each friend has a phonebook of size si (that's the number of phone numbers). We know that taxi numbers consist of six identical digits (for example, 22-22-22), the numbers of pizza deliveries should necessarily be decreasing sequences of six different digits (for example, 98-73-21), all other numbers are the girls' numbers.

You are given your friends' phone books. Calculate which friend is best to go to when you are interested in each of those things (who has maximal number of phone numbers of each type).

If the phone book of one person contains some number two times, you should count it twice. That is, each number should be taken into consideration the number of times it occurs in the phone book.

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the number of friends.

Then follow n data blocks that describe each friend's phone books. Each block is presented in the following form: first goes the line that contains integer si and string namei (0 ≤ si ≤ 100) — the number of phone numbers in the phone book of the i-th friend and the name of the i-th friend. The name is a non-empty sequence of uppercase and lowercase Latin letters, containing no more than 20 characters. Next si lines contain numbers as "XX-XX-XX", where X is arbitrary digits from 0 to 9.

Output

In the first line print the phrase "If you want to call a taxi, you should call: ". Then print names of all friends whose phone books contain maximal number of taxi phone numbers.

In the second line print the phrase "If you want to order a pizza, you should call: ". Then print names of all friends who have maximal number of pizza phone numbers.

In the third line print the phrase "If you want to go to a cafe with a wonderful girl, you should call: ". Then print names of all friends who have maximal number of girls' phone numbers.

Print the names in the order in which they are given in the input data. Separate two consecutive names with a comma and a space. Each line should end with exactly one point. For clarifications concerning the output form, see sample tests. It is necessary that you follow the output form strictly. Extra spaces are not allowed.

Examples

Input

4
2 Fedorov
22-22-22
98-76-54
3 Melnikov
75-19-09
23-45-67
99-99-98
7 Rogulenko
22-22-22
11-11-11
33-33-33
44-44-44
55-55-55
66-66-66
95-43-21
3 Kaluzhin
11-11-11
99-99-99
98-65-32

Output

If you want to call a taxi, you should call: Rogulenko.
If you want to order a pizza, you should call: Fedorov, Rogulenko, Kaluzhin.
If you want to go to a cafe with a wonderful girl, you should call: Melnikov.

Input

3
5 Gleb
66-66-66
55-55-55
01-01-01
65-43-21
12-34-56
3 Serega
55-55-55
87-65-43
65-55-21
5 Melnik
12-42-12
87-73-01
36-04-12
88-12-22
82-11-43

Output

If you want to call a taxi, you should call: Gleb.
If you want to order a pizza, you should call: Gleb, Serega.
If you want to go to a cafe with a wonderful girl, you should call: Melnik.

Input

3
3 Kulczynski
22-22-22
65-43-21
98-12-00
4 Pachocki
11-11-11
11-11-11
11-11-11
98-76-54
0 Smietanka

Output

If you want to call a taxi, you should call: Pachocki.
If you want to order a pizza, you should call: Kulczynski, Pachocki.
If you want to go to a cafe with a wonderful girl, you should call: Kulczynski.

Note

In the first sample you are given four friends. Fedorov's phone book contains one taxi number and one pizza delivery number, Melnikov's phone book only has 3 numbers of girls, Rogulenko's one has 6 taxi numbers and one pizza delivery number, Kaluzhin's one contains 2 taxi numbers and one pizza delivery number.

Thus, if you need to order a taxi, you should obviously call Rogulenko, if you need to order a pizza you should call anybody of the following: Rogulenko, Fedorov, Kaluzhin (each of them has one number). Melnikov has maximal number of phone numbers of girls.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int getMax(int ara[], int initial, int final) {
  int i, max = ara[initial];
  int index = initial;
  for (i = initial + 1; i < final; i++)
    if (ara[i] > max) {
      max = ara[i];
      index = i;
    }
  return ara[index];
}
int getMax(int ara[], int n) { return getMax(ara, 0, n); }
string getMaxName(int ara[], int n, string s[]) {
  string str;
  int max = getMax(ara, n);
  for (int i = 0; i < n; i++) {
    if (ara[i] == max) {
      if (str[0]) str = str + ", ";
      str = str + s[i];
    }
  }
  str += ".\0";
  return str;
}
int main() {
  string name[101];
  string s;
  string number[100][100];
  int m;
  int count[3][100] = {0};
  int i, j, k, n;
  bool pitza = false, driver = false;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> m >> name[i];
    for (j = 0; j < m; j++) {
      cin >> s;
      driver = true;
      pitza = true;
      s[2] = s[3];
      s[3] = s[4];
      s[4] = s[6];
      s[5] = s[7];
      s[6] = 0;
      s[7] = 0;
      for (k = 0; k < 5; k++) {
        if (s[k] != s[k + 1]) driver = false;
        if (s[k] <= s[k + 1]) {
          pitza = false;
        }
      }
      if (!driver && !pitza)
        count[2][i]++;
      else if (driver)
        count[0][i]++;
      else if (pitza)
        count[1][i]++;
    }
  }
  cout << "If you want to call a taxi, you should call: "
       << getMaxName(count[0], n, name) << endl;
  cout << "If you want to order a pizza, you should call: "
       << getMaxName(count[1], n, name) << endl;
  cout << "If you want to go to a cafe with a wonderful girl, you should call: "
       << getMaxName(count[2], n, name) << endl;
  return 0;
}

```


### Prompt

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

As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered from 1 to n. You can get from one city to another moving along the roads.

The «Two Paths» company, where Bob's brother works, has won a tender to repair two paths in Flatland. A path is a sequence of different cities, connected sequentially by roads. The company is allowed to choose by itself the paths to repair. The only condition they have to meet is that the two paths shouldn't cross (i.e. shouldn't have common cities).

It is known that the profit, the «Two Paths» company will get, equals the product of the lengths of the two paths. Let's consider the length of each road equals 1, and the length of a path equals the amount of roads in it. Find the maximum possible profit for the company.

Input

The first line contains an integer n (2 ≤ n ≤ 200), where n is the amount of cities in the country. The following n - 1 lines contain the information about the roads. Each line contains a pair of numbers of the cities, connected by the road ai, bi (1 ≤ ai, bi ≤ n).

Output

Output the maximum possible profit.

Examples

Input

4
1 2
2 3
3 4

Output

1

Input

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

Output

0

Input

6
1 2
2 3
2 4
5 4
6 4

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > edges;
vector<int> conn[201];
bool v1[201], v2[201];
int mx = 0;
void setEdge(int a, int b, int v) {
  for (int s = 0; s < conn[a].size(); s++) {
    if (conn[a][s] == b || conn[a][s] == -1) conn[a][s] = (v == 1 ? b : -1);
  }
  for (int s = 0; s < conn[b].size(); s++) {
    if (conn[b][s] == a || conn[b][s] == -1) conn[b][s] = (v == 1 ? a : -1);
  }
}
int getHeight(int i) {
  v2[i] = 1;
  int ret = 0;
  for (int j = 0; j < conn[i].size(); j++) {
    if (conn[i][j] != -1 && !v2[conn[i][j]]) {
      ret = max(ret, 1 + getHeight(conn[i][j]));
    }
  }
  v2[i] = 0;
  return ret;
}
int longestPath(int i) {
  v1[i] = 1;
  int ret = 0;
  int cnt = 0;
  for (int j = 0; j < conn[i].size(); j++) {
    if (conn[i][j] != -1 && !v1[conn[i][j]]) {
      ret = max(ret, longestPath(conn[i][j]));
      cnt++;
    }
  }
  if (cnt == 0) ret = max(ret, getHeight(i));
  v1[i] = 0;
  return ret;
}
int main() {
  cin >> n;
  memset(v1, 0, sizeof v1);
  memset(v2, 0, sizeof v2);
  int a, b;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    edges.push_back(make_pair(a - 1, b - 1));
    conn[a - 1].push_back(b - 1);
    conn[b - 1].push_back(a - 1);
  }
  for (int i = 0; i < edges.size(); i++) {
    a = edges[i].first;
    b = edges[i].second;
    setEdge(a, b, 0);
    mx = max(mx, longestPath(a) * longestPath(b));
    setEdge(a, b, 1);
  }
  cout << mx << endl;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You are given an array a consisting of n positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 2) or determine that there is no such subset.

Both the given array and required subset may contain equal values.

Input

The first line contains a single integer t (1 ≤ t ≤ 100), number of test cases to solve. Descriptions of t test cases follow.

A description of each test case consists of two lines. The first line contains a single integer n (1 ≤ n ≤ 100), length of array a.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 100), elements of a. The given array a can contain equal values (duplicates).

Output

For each test case output -1 if there is no such subset of elements. Otherwise output positive integer k, number of elements in the required subset. Then output k distinct integers (1 ≤ p_i ≤ n), indexes of the chosen elements. If there are multiple solutions output any of them.

Example

Input

3
3
1 4 3
1
15
2
3 5

Output

1
2
-1
2
1 2

Note

There are three test cases in the example.

In the first test case, you can choose the subset consisting of only the second element. Its sum is 4 and it is even.

In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.

In the third test case, the subset consisting of all array's elements has even sum.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> even;
    vector<int> odd;
    for (int i = 0; i < n; i++) {
      int temp;
      cin >> temp;
      if (temp % 2 == 0)
        even.push_back(i + 1);
      else {
        odd.push_back(i + 1);
      }
    }
    if (even.size()) {
      cout << 1 << endl;
      cout << even[0] << endl;
    } else if (odd.size() == 1) {
      cout << -1 << endl;
    } else {
      cout << 2 << endl;
      cout << odd[0] << " " << odd[1] << endl;
    }
  }
  return 0;
}

```


### Prompt

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

When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.

"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."

"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.

The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.

When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.

You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.

Input

The first and only line of input contains a non-empty string s consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (\lvert s \rvert ≤ 100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.

Output

Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.

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

Examples

Input

.BAC.

Output

Yes

Input

AA..CB

Output

No

Note

In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.

In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char s[100050];
bool vis;
int main() {
  scanf("%s", s + 1);
  int len = strlen(s + 1);
  if (len <= 2) {
    printf("No\n");
    return 0;
  }
  for (int i = 1; i <= len - 2; i++) {
    if (s[i] != s[i + 1] && s[i + 1] != s[i + 2] && s[i] != s[i + 2] &&
        s[i] != '.' && s[i + 1] != '.' && s[i + 2] != '.') {
      vis = 1;
      break;
    }
  }
  if (vis == 1)
    printf("Yes\n");
  else
    printf("No\n");
}

```


### Prompt

Create a solution in cpp for the following problem:

Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencies.

Rubik has 3 computers, on which he can play this game. All computers are located in different houses. Besides, it has turned out that each part of the game can be completed only on one of these computers. Let's number the computers with integers from 1 to 3. Rubik can perform the following actions:

  * Complete some part of the game on some computer. Rubik spends exactly 1 hour on completing any part on any computer.
  * Move from the 1-st computer to the 2-nd one. Rubik spends exactly 1 hour on that.
  * Move from the 1-st computer to the 3-rd one. Rubik spends exactly 2 hours on that.
  * Move from the 2-nd computer to the 1-st one. Rubik spends exactly 2 hours on that.
  * Move from the 2-nd computer to the 3-rd one. Rubik spends exactly 1 hour on that.
  * Move from the 3-rd computer to the 1-st one. Rubik spends exactly 1 hour on that.
  * Move from the 3-rd computer to the 2-nd one. Rubik spends exactly 2 hours on that.

Help Rubik to find the minimum number of hours he will need to complete all parts of the game. Initially Rubik can be located at the computer he considers necessary.

Input

The first line contains integer n (1 ≤ n ≤ 200) — the number of game parts. The next line contains n integers, the i-th integer — ci (1 ≤ ci ≤ 3) represents the number of the computer, on which you can complete the game part number i.

Next n lines contain descriptions of game parts. The i-th line first contains integer ki (0 ≤ ki ≤ n - 1), then ki distinct integers ai, j (1 ≤ ai, j ≤ n; ai, j ≠ i) — the numbers of parts to complete before part i.

Numbers on all lines are separated by single spaces. You can assume that the parts of the game are numbered from 1 to n in some way. It is guaranteed that there are no cyclic dependencies between the parts of the game.

Output

On a single line print the answer to the problem.

Examples

Input

1
1
0

Output

1

Input

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

Output

7

Note

Note to the second sample: before the beginning of the game the best strategy is to stand by the third computer. First we complete part 5. Then we go to the 1-st computer and complete parts 3 and 4. Then we go to the 2-nd computer and complete parts 1 and 2. In total we get 1+1+2+1+2, which equals 7 hours.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[280];
int com[280], n, dir[280], in[280];
bool mark[280];
int go(int a) {
  vector<int> ad[280];
  for (int i = 0; i < n; i++) ad[i] = adj[i];
  int inn[280];
  for (int i = 0; i < n; i++) inn[i] = in[i];
  memset(mark, 0, sizeof mark);
  int sum = 0, node = 0, cnt = 0;
  while (node < n) {
    while (1) {
      bool f = 1;
      for (int j = 0; j < n; j++) {
        if (com[j] == dir[a] && inn[j] == 0 && !mark[j]) {
          mark[j] = 1;
          f = 0;
          for (int k = 0; k < ad[j].size(); k++) {
            inn[ad[j][k]]--;
            ad[j].erase(ad[j].begin() + k);
            k--;
          }
          node++;
        }
      }
      if (f) {
        cnt++;
        break;
      }
      cnt = 0;
    }
    if (cnt == 3) return 200000;
    sum++;
    a++;
  }
  return sum - cnt;
}
int main() {
  int k = 1;
  for (int i = 0; i < 280; i++) {
    dir[i] = k++;
    if (k == 4) k = 1;
  }
  memset(in, 0, sizeof in);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> com[i];
  for (int i = 0; i < n; i++) {
    int t, x;
    cin >> t;
    while (t--) {
      cin >> x;
      x--;
      adj[x].push_back(i);
      in[i]++;
    }
  }
  int mn = go(0);
  mn = min(mn, go(1));
  mn = min(mn, go(2));
  cout << mn + n << endl;
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:

* For any two vertices painted in the same color, the distance between them is an even number.

Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.

Constraints

* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq u_i < v_i \leq N
* 1 \leq w_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
u_1 v_1 w_1
u_2 v_2 w_2
.
.
.
u_{N - 1} v_{N - 1} w_{N - 1}

Output

Print a coloring of the vertices that satisfies the condition, in N lines. The i-th line should contain `0` if Vertex i is painted white and `1` if it is painted black.

If there are multiple colorings that satisfy the condition, any of them will be accepted.

Examples

Input

3
1 2 2
2 3 1

Output

0
0
1

Input

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

Output

1
0
1
0
1

### Response

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

typedef long long ll;
typedef pair<ll,int> P;

int main(){
	int N;
	cin >> N;
	vector<vector<int>> G(N);
	map<P,int> d;
	rep(i,N-1){
		int u,v,w;
		cin >> u >> v >> w;
		u--; v--; w%=2;
		d[P(u,v)] = d[P(v,u)] = w;
		G[u].push_back(v);
		G[v].push_back(u);
	}

	vector<int> used(N,-1);
	used[0] = 0;
	queue<int> que;
	que.push(0);
	while(!que.empty()){
		int x = que.front(); que.pop();
		for(int u : G[x]){
			if(used[u]==-1){
				used[u] = used[x] xor d[P(x,u)];
				que.push(u);
			}
		}
	}

	for(int u : used)cout << u << endl;
}

```


### Prompt

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

Bandits appeared in the city! One of them is trying to catch as many citizens as he can.

The city consists of n squares connected by n-1 roads in such a way that it is possible to reach any square from any other square. The square number 1 is the main square.

After Sunday walk all the roads were changed to one-way roads in such a way that it is possible to reach any square from the main square.

At the moment when the bandit appeared on the main square there were a_i citizens on the i-th square. Now the following process will begin. First, each citizen that is currently on a square with some outgoing one-way roads chooses one of such roads and moves along it to another square. Then the bandit chooses one of the one-way roads outgoing from the square he is located and moves along it. The process is repeated until the bandit is located on a square with no outgoing roads. The bandit catches all the citizens on that square.

The bandit wants to catch as many citizens as possible; the citizens want to minimize the number of caught people. The bandit and the citizens know positions of all citizens at any time, the citizens can cooperate. If both sides act optimally, how many citizens will be caught?

Input

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

The second line contains n-1 integers p_2, p_3 ... p_n meaning that there is a one-way road from the square p_i to the square i (1 ≤ p_i < i).

The third line contains n integers a_1, a_2, ..., a_n — the number of citizens on each square initially (0 ≤ a_i ≤ 10^9).

Output

Print a single integer — the number of citizens the bandit will catch if both sides act optimally.

Examples

Input

3
1 1
3 1 2

Output

3

Input

3
1 1
3 1 3

Output

4

Note

In the first example the citizens on the square 1 can split into two groups 2 + 1, so that the second and on the third squares will have 3 citizens each.

In the second example no matter how citizens act the bandit can catch at least 4 citizens.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double PI = 2 * acos(0);
const double EPS = 1e-9;
const int oo = 2e9;
const long long MOD = 1e9 + 7;
const int N = 2e5 + 5;
vector<int> adj[N];
int leaves[N], arr[N];
long long sum[N];
void dfs(int u) {
  bool leave = 1;
  for (auto& v : adj[u]) {
    leave = 0;
    dfs(v);
    leaves[u] += leaves[v];
    sum[u] += sum[v];
  }
  sum[u] += arr[u];
  leaves[u] += leave;
}
int main() {
  int n;
  scanf("%d", &(n));
  for (int i = 0; i < n - 1; i++) {
    int p;
    scanf("%d", &(p));
    adj[p].push_back(i + 2);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &(arr[i]));
  }
  dfs(1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, (sum[i] + leaves[i] - 1) / leaves[i]);
  }
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

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

When Kefa came to the restaurant and sat at a table, the waiter immediately brought him the menu. There were n dishes. Kefa knows that he needs exactly m dishes. But at that, he doesn't want to order the same dish twice to taste as many dishes as possible.

Kefa knows that the i-th dish gives him ai units of satisfaction. But some dishes do not go well together and some dishes go very well together. Kefa set to himself k rules of eating food of the following type — if he eats dish x exactly before dish y (there should be no other dishes between x and y), then his satisfaction level raises by c.

Of course, our parrot wants to get some maximal possible satisfaction from going to the restaurant. Help him in this hard task!

Input

The first line of the input contains three space-separated numbers, n, m and k (1 ≤ m ≤ n ≤ 18, 0 ≤ k ≤ n * (n - 1)) — the number of dishes on the menu, the number of portions Kefa needs to eat to get full and the number of eating rules.

The second line contains n space-separated numbers ai, (0 ≤ ai ≤ 109) — the satisfaction he gets from the i-th dish.

Next k lines contain the rules. The i-th rule is described by the three numbers xi, yi and ci (1 ≤ xi, yi ≤ n, 0 ≤ ci ≤ 109). That means that if you eat dish xi right before dish yi, then the Kefa's satisfaction increases by ci. It is guaranteed that there are no such pairs of indexes i and j (1 ≤ i < j ≤ k), that xi = xj and yi = yj.

Output

In the single line of the output print the maximum satisfaction that Kefa can get from going to the restaurant.

Examples

Input

2 2 1
1 1
2 1 1

Output

3

Input

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

Output

12

Note

In the first sample it is best to first eat the second dish, then the first one. Then we get one unit of satisfaction for each dish and plus one more for the rule.

In the second test the fitting sequences of choice are 4 2 1 or 2 1 4. In both cases we get satisfaction 7 for dishes and also, if we fulfill rule 1, we get an additional satisfaction 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long m, n, k, cnt;
long long res, a[20], c[20][20], dp[265000][20];
long long Max(long long x, long long y) { return (x > y) ? x : y; }
long getBit(long state, long k) { return (state >> k & 1); }
long setBit(long state, long k) { return state | (1 << k); }
long clearBit(long state, long k) { return state & ~(1 << k); }
long toggleBit(long state, long k) { return state ^ (1 << k); }
void DP() {
  long state, tmp, cnt = 0;
  for (long i = 2; i <= (1 << n) - 1; ++i)
    for (long j = 1; j <= n; ++j)
      if (!dp[i][j] && getBit(i, j - 1)) {
        cnt = 1;
        state = clearBit(i, j - 1);
        for (long k = 1; k <= n; ++k)
          if (getBit(state, k - 1)) {
            ++cnt;
            dp[i][j] = Max(dp[i][j], dp[state][k] + c[k][j] + a[j]);
          }
        if (cnt == m) res = Max(res, dp[i][j]);
      }
}
int main() {
  scanf("%ld%ld%ld", &n, &m, &k);
  for (long i = 1; i <= n; ++i) {
    scanf("%I64d", &a[i]);
    dp[1 << (i - 1)][i] = a[i];
    if (m == 1) res = Max(res, a[i]);
  }
  long u, v;
  long long x;
  for (long i = 1; i <= k; ++i) {
    scanf("%ld%ld%I64d", &u, &v, &x);
    c[u][v] = x;
  }
  DP();
  printf("%I64d", res);
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.

The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.

Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.

Output

Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).

Examples

Input

2
><
1 2

Output

FINITE

Input

3
>><
2 1 1

Output

INFINITE

Note

In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.

Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, ara[100001], pos = 0;
  cin >> n;
  string str;
  cin >> str;
  for (int i = 0; i < n; i++) {
    cin >> ara[i];
  }
  for (int i = 1; i <= 1000000; i++) {
    if (str[pos] == '>') {
      pos += ara[pos];
    } else if (str[pos] == '<') {
      pos -= ara[pos];
    }
    if (pos < 0 || pos >= str.size()) {
      cout << "FINITE" << endl;
      return 0;
    }
  }
  cout << "INFINITE" << endl;
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

During the last Sereja's Codesecrof round the server crashed many times, so the round was decided to be made unrated for some participants.

Let's assume that n people took part in the contest. Let's assume that the participant who got the first place has rating a1, the second place participant has rating a2, ..., the n-th place participant has rating an. Then changing the rating on the Codesecrof site is calculated by the formula <image>.

After the round was over, the Codesecrof management published the participants' results table. They decided that if for a participant di < k, then the round can be considered unrated for him. But imagine the management's surprise when they found out that the participants' rating table is dynamic. In other words, when some participant is removed from the rating, he is removed from the results' table and the rating is recalculated according to the new table. And of course, all applications for exclusion from the rating are considered in view of the current table.

We know that among all the applications for exclusion from the rating the first application to consider is from the participant with the best rank (the rank with the minimum number), for who di < k. We also know that the applications for exclusion from rating were submitted by all participants.

Now Sereja wonders, what is the number of participants to be excluded from the contest rating, and the numbers of the participants in the original table in the order of their exclusion from the rating. Pay attention to the analysis of the first test case for a better understanding of the statement.

Input

The first line contains two integers n, k (1 ≤ n ≤ 2·105, - 109 ≤ k ≤ 0). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — ratings of the participants in the initial table.

Output

Print the numbers of participants in the order in which they were removed from the table. Print the initial numbers of the participants, that is, the numbers that the participants had in the initial table.

Examples

Input

5 0
5 3 4 1 2

Output

2
3
4

Input

10 -10
5 5 1 7 5 1 2 4 9 2

Output

2
4
5
7
8
9

Note

Consider the first test sample.

  1. Initially the sequence of the contest participants' ratings equals [5, 3, 4, 1, 2]. You can use this sequence to calculate the sequence of rating changes: [0, -9, -13, 8, 14]. According to the problem statement, the application of the participant who won the second place will be considered first.
  2. As soon as the second place winner is out from the ratings, the participants' rating sequence will equal [5, 4, 1, 2]. By this sequence you can count the new sequence of rating changes: [0, -8, 2, 6]. According to the problem statement, the application of the participant who won the second place will be considered. Initially this participant won third place.
  3. The new rating sequence equals [5, 1, 2], the new sequence of rating changes equals [0, -1, 1]. The second place participant's application is taken into consideration, initially this participant won the fourth place.
  4. The new rating sequence equals [5, 2], the new sequence of rating changes equals [0, 0]. No more applications will be considered.

Thus, you should print 2, 3, 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long* a = new long long[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long d;
  long long sum = 0;
  long long die = 0;
  for (long long i = 0; i < n; i++) {
    d = sum - (n - i - 1) * a[i] * (i - die);
    if (d < k)
      cout << i + 1 << endl, die++;
    else
      sum += (i - die) * a[i];
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Consider a tree (that is, an undirected connected graph without loops) T_1 and a tree T_2. Let's define their cartesian product T_1 × T_2 in a following way.

Let V be the set of vertices in T_1 and U be the set of vertices in T_2.

Then the set of vertices of graph T_1 × T_2 is V × U, that is, a set of ordered pairs of vertices, where the first vertex in pair is from V and the second — from U.

Let's draw the following edges:

  * Between (v, u_1) and (v, u_2) there is an undirected edge, if u_1 and u_2 are adjacent in U.
  * Similarly, between (v_1, u) and (v_2, u) there is an undirected edge, if v_1 and v_2 are adjacent in V.

Please see the notes section for the pictures of products of trees in the sample tests.

Let's examine the graph T_1 × T_2. How much cycles (not necessarily simple) of length k it contains? Since this number can be very large, print it modulo 998244353.

The sequence of vertices w_1, w_2, ..., w_k, where w_i ∈ V × U called cycle, if any neighboring vertices are adjacent and w_1 is adjacent to w_k. Cycles that differ only by the cyclic shift or direction of traversal are still considered different.

Input

First line of input contains three integers — n_1, n_2 and k (2 ≤ n_1, n_2 ≤ 4000, 2 ≤ k ≤ 75) — number of vertices in the first tree, number of vertices in the second tree and the cycle length respectively.

Then follow n_1 - 1 lines describing the first tree. Each of this lines contains two integers — v_i, u_i (1 ≤ v_i, u_i ≤ n_1), which define edges of the first tree.

Then follow n_2 - 1 lines, which describe the second tree in the same format.

It is guaranteed, that given graphs are trees.

Output

Print one integer — number of cycles modulo 998244353.

Examples

Input

2 2 2
1 2
1 2

Output

8

Input

2 2 4
1 2
1 2

Output

32

Input

2 3 4
1 2
1 2
1 3

Output

70

Input

4 2 2
1 2
1 3
1 4
1 2

Output

20

Note

The following three pictures illustrate graph, which are products of the trees from sample tests.

In the first example, the list of cycles of length 2 is as follows:

  * «AB», «BA»
  * «BC», «CB»
  * «AD», «DA»
  * «CD», «DC»

<image> <image> <image>

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")
using namespace std;
using Int = long long;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
  return os << "(" << a.first << ", " << a.second << ")";
};
template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cerr << *i << " ";
  cerr << endl;
}
template <class T>
bool chmin(T &t, const T &f) {
  if (t > f) {
    t = f;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T &t, const T &f) {
  if (t < f) {
    t = f;
    return true;
  }
  return false;
}
template <int M_>
struct ModInt {
  static constexpr int M = M_;
  int x;
  constexpr ModInt() : x(0) {}
  constexpr ModInt(long long x_) : x(x_ % M) {
    if (x < 0) x += M;
  }
  ModInt &operator+=(const ModInt &a) {
    x += a.x;
    if (x >= M) x -= M;
    return *this;
  }
  ModInt &operator-=(const ModInt &a) {
    x -= a.x;
    if (x < 0) x += M;
    return *this;
  }
  ModInt &operator*=(const ModInt &a) {
    x = static_cast<int>((static_cast<long long>(x) * a.x) % M);
    return *this;
  }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator-() const { return ModInt(-x); }
  ModInt pow(long long e) const {
    ModInt x2 = x, xe = 1;
    for (; e; e >>= 1) {
      if (e & 1) xe *= x2;
      x2 *= x2;
    }
    return xe;
  }
  ModInt inv() const {
    int a = x, b = M, y = 1, z = 0, t;
    for (;;) {
      t = a / b;
      a -= t * b;
      if (a == 0) {
        assert(b == 1 || b == -1);
        return ModInt(b * z);
      }
      y -= t * z;
      t = b / a;
      b -= t * a;
      if (b == 0) {
        assert(a == 1 || a == -1);
        return ModInt(a * y);
      }
      z -= t * y;
    }
  }
  friend ModInt operator+(long long a, const ModInt &b) {
    return (ModInt(a) += b);
  }
  friend ModInt operator-(long long a, const ModInt &b) {
    return (ModInt(a) -= b);
  }
  friend ModInt operator*(long long a, const ModInt &b) {
    return (ModInt(a) *= b);
  }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) {
    return os << a.x;
  }
};
constexpr int MO = 998244353;
using Mint = ModInt<MO>;
constexpr int LIM = 100;
Mint inv[LIM], fac[LIM], invFac[LIM];
void prepare() {
  inv[1] = 1;
  for (int i = 2; i < LIM; ++i) {
    inv[i] = -(Mint::M / i) * inv[Mint::M % i];
  }
  fac[0] = invFac[0] = 1;
  for (int i = 1; i < LIM; ++i) {
    fac[i] = fac[i - 1] * i;
    invFac[i] = invFac[i - 1] * inv[i];
  }
}
Mint binom(Int n, Int k) {
  if (0 <= k && k <= n) {
    assert(n < LIM);
    return fac[n] * invFac[k] * invFac[n - k];
  } else {
    return 0;
  }
}
int Ns[2], K;
Mint cycs[2][110];
int N;
int U[4010], V[4010];
vector<int> G[4010];
int usLen, vsLen;
int us[4010], vs[4010];
vector<int> gU[4010], gV[4010];
Mint dpU[4010], dpV[4010];
void dfs(int u, int p, int c) {
  ((c == 0) ? us[usLen++] : vs[vsLen++]) = u;
  for (const int v : G[u]) {
    if (v != p) {
      dfs(v, u, c ^ 1);
    }
  }
}
void doIt(int h) {
  N = Ns[h];
  for (int i = 0; i < N - 1; ++i) {
    scanf("%d%d", &U[i], &V[i]);
    --U[i];
    --V[i];
  }
  fill(cycs[h], cycs[h] + K + 1, 0);
  if (K % 2 != 0) {
    return;
  }
  fill(G, G + N, vector<int>{});
  for (int i = 0; i < N - 1; ++i) {
    G[U[i]].push_back(V[i]);
    G[V[i]].push_back(U[i]);
  }
  usLen = vsLen = 0;
  dfs(0, -1, 0);
  if (usLen > vsLen) {
    usLen = vsLen = 0;
    dfs(0, -1, 1);
  }
  sort(us, us + usLen);
  sort(vs, vs + vsLen);
  fill(gU, gU + usLen, vector<int>{});
  fill(gV, gV + vsLen, vector<int>{});
  for (int x = 0; x < usLen; ++x) {
    const int u = us[x];
    for (const int v : G[u]) {
      gU[x].push_back(lower_bound(vs, vs + vsLen, v) - vs);
    }
  }
  for (int y = 0; y < vsLen; ++y) {
    const int v = vs[y];
    for (const int u : G[v]) {
      gV[y].push_back(lower_bound(us, us + usLen, u) - us);
    }
  }
  for (int s = 0; s < usLen; ++s) {
    fill(dpU, dpU + usLen, 0);
    dpU[s] = 1;
    for (int k = 0; k < K; k += 2) {
      cycs[h][k] += dpU[s];
      fill(dpV, dpV + vsLen, 0);
      for (int x = 0; x < usLen; ++x) {
        for (const int y : gU[x]) {
          dpV[y] += dpU[x];
        }
      }
      fill(dpU, dpU + usLen, 0);
      for (int y = 0; y < vsLen; ++y) {
        for (const int x : gV[y]) {
          dpU[x] += dpV[y];
        }
      }
    }
    cycs[h][K] += dpU[s];
  }
  cycs[h][0] = N;
  for (int k = 2; k <= K; k += 2) {
    cycs[h][k] *= 2;
  }
}
int main() {
  prepare();
  for (; ~scanf("%d%d%d", &Ns[0], &Ns[1], &K);) {
    doIt(0);
    doIt(1);
    Mint ans = 0;
    if (K % 2 == 0) {
      for (int k = 0; k <= K; k += 2) {
        ans += binom(K, k) * cycs[0][k] * cycs[1][K - k];
      }
    }
    printf("%d\n", ans.x);
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

You are given an array a consisting of n integers (it is guaranteed that n is even, i.e. divisible by 2). All a_i does not exceed some integer k.

Your task is to replace the minimum number of elements (replacement is the following operation: choose some index i from 1 to n and replace a_i with some integer in range [1; k]) to satisfy the following conditions:

  * after all replacements, all a_i are positive integers not greater than k;
  * for all i from 1 to n/2 the following equation is true: a_i + a_{n - i + 1} = x, where x should be the same for all n/2 pairs of elements.

You have to answer t independent test cases.

Input

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

The first line of the test case contains two integers n and k (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 2 ⋅ 10^5) — the length of a and the maximum possible value of some a_i correspondingly. It is guratanteed that n is even (i.e. divisible by 2). The second line of the test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ k), where a_i is the i-th element of a.

It is guaranteed that the sum of n (as well as the sum of k) over all test cases does not exceed 2 ⋅ 10^5 (∑ n ≤ 2 ⋅ 10^5, ∑ k ≤ 2 ⋅ 10^5).

Output

For each test case, print the answer — the minimum number of elements you have to replace in a to satisfy the conditions from the problem statement.

Example

Input

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

Output

0
1
4
2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int N, K;
    cin >> N >> K;
    int a[N];
    for (int i = 0; i < N; i++) {
      cin >> a[i];
    }
    int b[2 * K + 3], c[2 * K + 3];
    memset(b, 0, sizeof b);
    memset(c, 0, sizeof c);
    for (int i = 0; i < N / 2; i++) {
      b[min(a[i], a[N - (i + 1)]) + 1] += 1;
      b[max(a[i], a[N - (i + 1)]) + K + 1] -= 1;
      c[a[i] + a[N - (i + 1)]]++;
    }
    int d[2 * K + 3];
    memset(d, 0, sizeof d);
    for (int i = 0; i < 2 * K + 3; i++) {
      if (i == 0)
        d[i] = b[i];
      else
        d[i] = d[i - 1] + b[i];
    }
    int ans = INT_MAX;
    for (int i = 2; i <= 2 * K; i++) {
      int t1 = c[i];
      int t2 = d[i];
      ans = min(ans, (t2 - t1) + (+N - (2 * t2)));
    }
    cout << ans << '\n';
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

To satisfy his love of matching socks, Phoenix has brought his n socks (n is even) to the sock store. Each of his socks has a color c_i and is either a left sock or right sock.

Phoenix can pay one dollar to the sock store to either:

  * recolor a sock to any color c' (1 ≤ c' ≤ n)
  * turn a left sock into a right sock
  * turn a right sock into a left sock

The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa.

A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make n/2 matching pairs? Each sock must be included in exactly one matching pair.

Input

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

The first line of each test case contains three integers n, l, and r (2 ≤ n ≤ 2 ⋅ 10^5; n is even; 0 ≤ l, r ≤ n; l+r=n) — the total number of socks, and the number of left and right socks, respectively.

The next line contains n integers c_i (1 ≤ c_i ≤ n) — the colors of the socks. The first l socks are left socks, while the next r socks are right socks.

It is guaranteed that the sum of n across all the test cases will not exceed 2 ⋅ 10^5.

Output

For each test case, print one integer — the minimum cost for Phoenix to make n/2 matching pairs. Each sock must be included in exactly one matching pair.

Example

Input

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

Output

2
3
5
3

Note

In the first test case, Phoenix can pay 2 dollars to:

  * recolor sock 1 to color 2
  * recolor sock 3 to color 2

There are now 3 matching pairs. For example, pairs (1, 4), (2, 5), and (3, 6) are matching.

In the second test case, Phoenix can pay 3 dollars to:

  * turn sock 6 from a right sock to a left sock
  * recolor sock 3 to color 1
  * recolor sock 4 to color 1

There are now 3 matching pairs. For example, pairs (1, 3), (2, 4), and (5, 6) are matching.

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll t;
    cin>>t;
    while(t--!=0){
        ll n,l,r;
        cin>>n>>l>>r;
        ll c[n];
        for(ll i=0;i<n;i++){
            c[i]=0;
        }

        for(ll i=0;i<n;i++){
            ll c1;
            cin>>c1;
            c1--;
            if(i<l){
                c[c1]--;
            }
            else{
                c[c1]++;
            }
        }
        ll ans=0;
        ll odd1=0;
        ll even1=0;
        ll odd2=0;
        ll even2=0;
        for(ll i=0;i<n;i++){
            ll d=abs(c[i]);
            if(c[i]<0){
                if(d%2==1){
                    odd1++;
                    d--;
                    even1+=d;
                }
                else{
                    even1+=d;
                }
            }
            else{
                if(d%2==1){
                    odd2++;
                    d--;
                    even2+=d;
                }
                else{
                    even2+=d;
                }
            }
        }
        //cout<<odd1<<" "<<even1<<" "<<odd2<<" "<<even2<<endl;
        if(odd1>=odd2){
            odd1-=odd2;
            ans+=odd2;
            odd2=0;
        }
        if(odd2>=odd1){
            odd2-=odd1;
            ans+=odd1;
            odd1=0;
        }
        if(odd1!=0 && even2!=0){

            if(odd1>=even2){
                odd1-=even2;
                ans+=even2;
                even2=0;

            }
            else{
                ans+=odd1;
                even2-=odd1;
                odd1=0;

            }
        }
        if(odd2!=0 && even1!=0){

            if(odd2>=even1){
                odd2-=even1;
                ans+=even1;
                even1=0;
            }
            else{
                ans+=odd2;
                even1-=odd2;
                odd2=0;

            }
        }
        ans+=odd1+odd2+((even1+even2)/2);
        cout<<ans<<endl;
    }
}
```


### Prompt

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

Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of n × m square cells.

In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated as follows:

<image>

Each pipe segment has two ends, illustrated by the arrows in the picture above. For example, segment 1 has ends at top and left side of it.

Little John considers the piping system to be leaking if there is at least one pipe segment inside the grid whose end is not connected to another pipe's end or to the border of the grid. The image below shows an example of leaking and non-leaking systems of size 1 × 2.

<image>

Now, you will be given the grid that has been partially filled by Little John. Each cell will either contain one of the four segments above, or be empty. Find the number of possible different non-leaking final systems after Little John finishes filling all of the empty cells with pipe segments. Print this number modulo 1000003 (106 + 3).

Note that rotations or flipping of the grid are not allowed and so two configurations that are identical only when one of them has been rotated or flipped either horizontally or vertically are considered two different configurations.

Input

The first line will contain two single-space separated integers n and m (1 ≤ n, m, n·m ≤ 5·105) — the number of rows and columns respectively. Then n lines follow, each contains exactly m characters — the description of the grid. Each character describes a cell and is either one of these:

  * "1" - "4" — a pipe segment of one of four types as described above
  * "." — an empty cell

Output

Print a single integer denoting the number of possible final non-leaking pipe systems modulo 1000003 (106 + 3). If there are no such configurations, print 0.

Examples

Input

2 2
13
..

Output

2

Input

3 1
1
4
.

Output

0

Input

2 2
3.
.1

Output

1

Note

For the first example, the initial configuration of the grid is as follows.

<image>

The only two possible final non-leaking pipe configurations are as follows:

<image> <image>

For the second example, the initial grid is already leaking, so there will be no final grid that is non-leaking.

For the final example, there's only one possible non-leaking final grid as follows.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000003;
struct A {
  char a[500005];
  int n, m;
  char& at(const int& x, const int& y) { return a[x * m + y]; }
} ma;
int main() {
  int i, j, n, m;
  scanf("%d%d", &n, &m);
  ma.n = n;
  ma.m = m;
  char str[500005];
  for (i = 0; i < n; ++i) {
    scanf("%s", str);
    for (j = 0; j < m; ++j) {
      switch (str[j]) {
        case '.':
          ma.at(i, j) = -1;
          break;
        case '3':
          ma.at(i, j) = 3;
          break;
        case '4':
          ma.at(i, j) = 2;
          break;
        default:
          ma.at(i, j) = str[j] - '1';
      }
    }
  }
  bool tag;
  int ans = 1, dir;
  for (i = 0; i < n; ++i) {
    tag = false;
    for (j = 0; j < m; ++j) {
      if (ma.at(i, j) != -1) {
        if (!tag) {
          tag = true;
          dir = (ma.at(i, j) ^ (j << 1)) & 2;
        } else if (((ma.at(i, j) ^ (j << 1)) & 2) != dir) {
          puts("0");
          return 0;
        }
      }
    }
    if (!tag) {
      ans = (ans << 1) % mod;
    }
  }
  for (j = 0; j < m; ++j) {
    tag = false;
    for (i = 0; i < n; ++i) {
      if (ma.at(i, j) != -1) {
        if (!tag) {
          tag = true;
          dir = (ma.at(i, j) ^ i) & 1;
        } else if (((ma.at(i, j) ^ i) & 1) != dir) {
          puts("0");
          return 0;
        }
      }
    }
    if (!tag) {
      ans = (ans << 1) % mod;
    }
  }
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

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

Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n × n cells (represented as unit squares), each cell has some number.

At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell with coordinates (n, n). Right after the start Furik runs towards Rubik, besides, if Furik stands at a cell with coordinates (i, j), then he can move to cell (i + 1, j) or (i, j + 1). After Furik reaches Rubik, Rubik starts running from cell with coordinates (n, n) to cell with coordinates (1, 1). If Rubik stands in cell (i, j), then he can move to cell (i - 1, j) or (i, j - 1). Neither Furik, nor Rubik are allowed to go beyond the boundaries of the field; if a player goes beyond the boundaries, he will be disqualified.

To win the race, Furik and Rubik must earn as many points as possible. The number of points is the sum of numbers from the cells Furik and Rubik visited. Each cell counts only once in the sum.

Print the maximum number of points Furik and Rubik can earn on the relay race.

Input

The first line contains a single integer (1 ≤ n ≤ 300). The next n lines contain n integers each: the j-th number on the i-th line ai, j ( - 1000 ≤ ai, j ≤ 1000) is the number written in the cell with coordinates (i, j).

Output

On a single line print a single number — the answer to the problem.

Examples

Input

1
5

Output

5

Input

2
11 14
16 12

Output

53

Input

3
25 16 25
12 18 19
11 13 8

Output

136

Note

Comments to the second sample: The profitable path for Furik is: (1, 1), (1, 2), (2, 2), and for Rubik: (2, 2), (2, 1), (1, 1).

Comments to the third sample: The optimal path for Furik is: (1, 1), (1, 2), (1, 3), (2, 3), (3, 3), and for Rubik: (3, 3), (3, 2), (2, 2), (2, 1), (1, 1). The figure to the sample:

<image> Furik's path is marked with yellow, and Rubik's path is marked with pink.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300 + 10;
const int INF = 1e9 + 2;
int n;
int cc[MAXN][MAXN];
int d[2 * MAXN][MAXN][MAXN];
bool fit(int a, int b) { return a >= 0 && a < n && b >= 0 && b < n; }
int get(int a, int b, int c) {
  if (d[a][b][c] != INF) return d[a][b][c];
  if (a == 2 * n - 2) return d[a][b][c] = 0;
  int r1, r2, col1, col2;
  d[a][b][c] = -INF;
  if (a < n - 1) {
    r1 = b, r2 = c;
    col1 = a - b, col2 = a - c;
    if (fit(r1 + 1, col1) && fit(r2 + 1, col2))
      d[a][b][c] =
          max(d[a][b][c], get(a + 1, b + 1, c + 1) + cc[r1 + 1][col1] +
                              cc[r2 + 1][col2] -
                              int(r2 == r1 && col1 == col2) * cc[r1 + 1][col1]);
    if (fit(r1 + 1, col1) && fit(r2, col2 + 1))
      d[a][b][c] =
          max(d[a][b][c],
              get(a + 1, b + 1, c) + cc[r1 + 1][col1] + cc[r2][col2 + 1] -
                  int(r2 == r1 + 1 && col2 + 1 == col1) * cc[r2][col2 + 1]);
    if (fit(r1, col1 + 1) && fit(r2 + 1, col2))
      d[a][b][c] =
          max(d[a][b][c],
              get(a + 1, b, c + 1) + cc[r1][col1 + 1] + cc[r2 + 1][col2] -
                  int(r2 + 1 == r1 && col1 + 1 == col2) * cc[r2 + 1][col2]);
    if (fit(r1, col1 + 1) && fit(r2, col2 + 1))
      d[a][b][c] = max(d[a][b][c],
                       get(a + 1, b, c) + cc[r1][col1 + 1] + cc[r2][col2 + 1] -
                           int(r1 == r2 && col1 == col2) * cc[r2][col2 + 1]);
  } else {
    int t = a - n;
    r1 = t + b + 1, r2 = t + 1 + c;
    col1 = a - r1, col2 = a - r2;
    if (fit(r1 + 1, col1) && fit(r2 + 1, col2))
      d[a][b][c] = max(d[a][b][c],
                       get(a + 1, b, c) + cc[r1 + 1][col1] + cc[r2 + 1][col2] -
                           int(r2 == r1 && col1 == col2) * cc[r1 + 1][col1]);
    if (fit(r1 + 1, col1) && fit(r2, col2 + 1))
      d[a][b][c] =
          max(d[a][b][c],
              get(a + 1, b, c - 1) + cc[r1 + 1][col1] + cc[r2][col2 + 1] -
                  int(r2 == r1 + 1 && col2 + 1 == col1) * cc[r2][col2 + 1]);
    if (fit(r1, col1 + 1) && fit(r2 + 1, col2))
      d[a][b][c] =
          max(d[a][b][c],
              get(a + 1, b - 1, c) + cc[r1][col1 + 1] + cc[r2 + 1][col2] -
                  int(r2 + 1 == r1 && col1 + 1 == col2) * cc[r2 + 1][col2]);
    if (fit(r1, col1 + 1) && fit(r2, col2 + 1))
      d[a][b][c] =
          max(d[a][b][c], get(a + 1, b - 1, c - 1) + cc[r1][col1 + 1] +
                              cc[r2][col2 + 1] -
                              int(r1 == r2 && col1 == col2) * cc[r2][col2 + 1]);
  }
  return d[a][b][c];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cin >> cc[i][j];
  for (int i = 0; i < 2 * MAXN; i++)
    for (int j = 0; j < MAXN; j++)
      for (int w = 0; w < MAXN; w++) d[i][j][w] = INF;
  cout << get(0, 0, 0) + cc[0][0] << endl;
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

<image>

Arrange integers (0 or more and 99 or less) in a rhombus as illustrated in Fig. 1. Create a program that reads the data representing the rhombus and outputs the maximum value of the sum of the integers that pass when starting from the top and proceeding to the bottom according to the following rules.

* At each step, you can proceed to the lower left diagonal or the lower right diagonal.

For example, in the example of Fig. 1, as shown in Fig. 2, when 7,3,8,7,5,7,8,3,7 is selected and passed, the sum is the maximum 55 (7 + 3 + 8). + 7 + 5 + 7 + 8 + 3 + 7 = 55).

Input

As shown in the input example, a comma-separated sequence of integers is given to the diamond. Each line does not contain whitespace. The input example corresponds to Fig. 1. There are less than 100 rows of data.

Output

Outputs the maximum value of the sum of integers that pass according to the rules on one line.

Example

Input

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

Output

55

### Response

```cpp
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back

const double EPS = 1e-10;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

vi split(string s, char sep) {
	vi res;
	int a = 0;
	rep (i, s.size()) {
		if (s[i] == sep) {
			res.pb(a);
			a = 0;
		}
		else {
			a = a * 10 + s[i] - '0';
		}
	}
	if (s[s.size() - 1] != sep) res.pb(a);
	return res;
}

int main() {
	vector<vi> a;
	for(string s; getline(cin, s); ) a.pb(split(s, ','));
	int n = a.size() / 2;
	int dp[100][100];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = a[0][0];
	REP(i, 1, n) rep(j, i + 1) dp[i][j] = a[i][j] + max(dp[i - 1][j], dp[i - 1][j - 1]);
	REP(i, n + 1, a.size() - 1) rep(j, a.size() - i) dp[i][j] = a[i][j] + max(dp[i - 1][j], dp[i - 1][j + 1]);
	cout << dp[a.size() - 1][0] << endl;

	return 0;
}
```


### Prompt

Please create a solution in CPP to the following problem:

There are n persons located on a plane. The i-th person is located at the point (x_i, y_i) and initially looks at the point (u_i, v_i).

At the same moment of time, all persons will start to rotate clockwise synchronously with the same angular speed. They will rotate until they do one full 360-degree turn.

It is said that persons A and B made eye contact if person A looks in person B's direction at the same moment when person B looks in person A's direction. If there is a person C located between persons A and B, that will not obstruct A and B from making eye contact. A person can make eye contact with more than one person at the same time.

Calculate the number of pairs of persons that will make eye contact at least once during the rotation (including the initial moment).

Input

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

The first line of each test case contains a single integer n (1 ≤ n ≤ 10^5) — the number of persons. The following n lines describe persons, each line containing four space-separated integers x_i, y_i, u_i, v_i (|x_i|, |y_i|, |u_i|, |v_i| ≤ 10^9; x_i ≠ u_i or y_i ≠ v_i), where (x_i, y_i) are the coordinates of the point where the i-th person is located and (u_i, v_i) are the coordinates of the point that the i-th person looks at initially. Each person's location is unique in each test case.

The sum of n over all test cases does not exceed 10^5.

Output

For each test case, print one integer — the number of pairs of persons who will make eye contact at least once during the rotation, including the initial moment.

Example

Input

3
2
0 0 0 1
1 0 2 0
3
0 0 1 1
1 1 0 0
1 0 2 0
6
0 0 0 1
1 0 1 2
2 0 2 3
3 0 3 -5
4 0 4 -5
5 0 5 -5

Output

0
1
9

### Response

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

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef vector<LL> 		VL;
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
#define DRT() int t; si(t); while(t--)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//# define M_PI           3.14159265358979323846264338327950288
// DSU

void IO(){
	#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	off;
}
LL gcd(LL x, LL y){
	return y == 0 ? x : gcd(y, x % y);
}
int main(){
	IO();
	DRT(){
		LL n;cin>>n;
		map<pair<LL, LL> , LL> cnt;
		LL x,y,u,v;
		LL ans = 0;
		rep(i,0,n){
			cin>>x>>y>>u>>v;
			LL num = x - u;
			LL deo = y - v;
			LL g;
			if(num == 0){
				if(deo < 0){
					cnt[{0, 1}]++;
					ans += cnt[{0, -1}];
				}
				else{
					cnt[{0, -1}]++;
					ans += cnt[{0, 1}];
				}
			}
			else if(deo == 0){
				if(num < 0){
					cnt[{-1, 0}]++;
					ans += cnt[{1, 0}];
				}
				else{
					cnt[{1, 0}]++;
					ans += cnt[{-1, 0}];
				}
			}
			else{
				if(abs(num) > abs(deo))
					g = gcd(abs(num), abs(deo));
				else
					g = gcd(abs(deo), abs(num));
				num /= g;
				deo /= g;
				ans += cnt[{-num, -deo}];
				cnt[{num, deo}]++;
			}
		}
		dout(ans);
	}
	return 0;
}
```


### Prompt

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

<image>

Matryoshka is a wooden doll in the shape of a female figure and is a typical Russian folk craft. Matryoshka has a nested structure in which smaller dolls are contained inside a large doll, and is composed of multiple dolls of different sizes. In order to have such a nested structure, the body of each doll has a tubular structure that can be divided into upper and lower parts. Matryoshka dolls are handmade by craftsmen, so each doll is unique and extremely valuable in the world.

Brothers Ichiro and Jiro loved to play with matryoshka dolls, and each had a pair of matryoshka dolls. Ichiro's matryoshka is made up of n dolls, and Jiro's matryoshka is made up of m dolls.

One day, curious Ichiro wondered if he could combine the dolls contained in these two pairs of matryoshka dolls to create a new matryoshka doll containing more dolls. In other words, I tried to make a pair of matryoshka dolls consisting of k dolls using n + m dolls. If k can be made larger than the larger of n and m, Ichiro's purpose will be achieved.

The two brothers got along well and wondered how to combine the dolls to maximize the value of k. But for the two younger ones, the problem is so difficult that you, older, decided to program to help your brothers.

Create a program that inputs the information of the matryoshka dolls of Ichiro and Jiro and outputs the number k of the dolls that the new matryoshka contains. No doll of the same size exists. Also, if we consider a doll to be a cylinder with a height h and a radius r, a doll with a height h and a radius r can contain a doll with a height x radius y that satisfies x <h and y <r.

Input

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

n
h1 r1
h2 r2
::
hn rn
m
h1 r1
h2 r2
::
hm rm

The first line gives the number of matryoshka dolls of Ichiro n (n ≤ 100), and the following n lines give the height hi and radius ri (hi, ri <1000) of the ith doll of Ichiro. ..

The following line gives the number of Jiro's matryoshka dolls m (m ≤ 100), and the following m lines give the height hi and radius ri (hi, ri <1000) of Jiro's i-th doll.

The number of datasets does not exceed 20.

Output

Outputs the number k of dolls that the new matryoshka contains for each input dataset.

Example

Input

6
1 1
4 3
6 5
8 6
10 10
14 14
5
2 2
5 4
6 6
9 8
15 10
4
1 1
4 3
6 5
8 6
3
2 2
5 4
6 6
4
1 1
4 3
6 5
8 6
4
10 10
12 11
18 15
24 20
0

Output

9
6
8

### Response

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 201
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

struct M {
    int r, h;
};

bool comp_r (const M& l, const M& r) {
    return l.r < r.r;
}

bool comp_h (const M& l, const M& r) {
    return l.h < r.h;
}

int main() {

    int n, m, dp[MAXN];
    M a[MAXN];

    while (cin >> n, n) {
        vector<pair <int, int> >A;
        int h, r;
        rep(i, n) {
            cin >> a[i].h >> a[i].r;
        }
        cin >> m;

        rep(i, m) {
            cin >> a[n+i].h >> a[n+i].r;
        }

        sort(a, a+n+m, comp_r);

        dp[0] = 1;

        for(int i=1; i<n+m; ++i) {
            dp[i] = 1;
            for(int j=0; j<i; ++j) {
                if ( a[j].r < a[i].r and a[j].h < a[i].h ) {
                    dp[i] = max(dp[i], dp[j]+1);
                }
            }
        }

        int res_r = dp[n+m-1];

        sort(a, a+n+m, comp_h);

        dp[0] = 1;
        for(int i=1; i<n+m; ++i) {
            dp[i] = 1;
            for(int j=0; j<i; ++j) {
                if ( a[j].r < a[i].r and a[j].h < a[i].h) {
                    dp[i] = max(dp[i], dp[j]+1);
                }
            }
        }
        int res_h = dp[n+m-1];
        cout << max(res_r, res_h) << endl;
    }
}

```


### Prompt

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

problem

You have to play a darts game with the following rules.

You can throw up to four arrows towards the target. You don't have to throw all four, you don't have to throw one. The target is divided into N parts. The score P1, ..., PN is written in each part. The total score S of the place where the arrow is stuck is the basis of your score. S is a predetermined score M or less. In the case of, S will be your score as it is. However, if S exceeds M, your score will be 0 points.

Create a program that finds the maximum number of points you can get given the written points and the value of M.

input

The input consists of multiple datasets. Each dataset is given in the following format.

On the first line, the integers N (1 ≤ N ≤ 1000) and M (1 ≤ M ≤ 200000000 = 2 × 108) are written in this order, separated by blanks. In (1 ≤ i ≤ N), Pi (1 ≤ Pi ≤ 100000000 = 108) is written.

Of the scoring data, 20% of the points satisfy N ≤ 100 and 50% of the points satisfy N ≤ 300.

When both N and M are 0, the input is completed. The number of data sets does not exceed 10.

output

Outputs the maximum number of points you can get for each dataset on one line.

Examples

Input

4 50
3
14
15
9
3 21
16
11
2
0 0

Output

48
20

Input

None

Output

None

### Response

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX

typedef long long ll;
typedef pair<int, int> ii;

#define DEBUG false

int main(){

	ll n, m;
	while(cin >> n >> m){
		if(n == 0 && m == 0) break;
		vector<ll> p(n+1);
		rep(i, n) cin >> p[i];

		rep(i, n){
			REP(j, i, n){
				p.push_back(p[i] + p[j]);
			}
		}

		SORT(p);

		ll ans = 0;

		rep(i, p.size()){
			auto it2 = upper_bound(p.begin(), p.end(), m - p[i]);
			if(it2 == p.begin()) continue;
			it2--;
			if(p[i] > *it2) break;
			ans = max(ans, p[i] + *it2);
		}

		cout << ans << endl;

	}

	return 0;
}
```