### Prompt

Generate a CPP solution to the following problem:

You are given an array consisting of n integers a_1, a_2, ..., a_n, and a positive integer m. It is guaranteed that m is a divisor of n.

In a single move, you can choose any position i between 1 and n and increase a_i by 1.

Let's calculate c_r (0 ≤ r ≤ m-1) — the number of elements having remainder r when divided by m. In other words, for each remainder, let's find the number of corresponding elements in a with that remainder.

Your task is to change the array in such a way that c_0 = c_1 = ... = c_{m-1} = n/m.

Find the minimum number of moves to satisfy the above requirement.

Input

The first line of input contains two integers n and m (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ m ≤ n). It is guaranteed that m is a divisor of n.

The second line of input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^9), the elements of the array.

Output

In the first line, print a single integer — the minimum number of moves required to satisfy the following condition: for each remainder from 0 to m - 1, the number of elements of the array having this remainder equals n/m.

In the second line, print any array satisfying the condition and can be obtained from the given array with the minimum number of moves. The values of the elements of the resulting array must not exceed 10^{18}.

Examples

Input

6 3
3 2 0 6 10 12

Output

3
3 2 0 7 10 14

Input

4 2
0 1 2 3

Output

0
0 1 2 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int val = n / m;
  vector<vector<int>> v(m);
  for (int i = 0; i < n; i++) v[a[i] % m].push_back(i);
  long long ans = 0;
  vector<pair<int, int>> fre;
  for (int i = 0; i < 2 * m; ++i) {
    int cur = i % m;
    while (int(v[cur].size()) > val) {
      int elem = v[cur].back();
      v[cur].pop_back();
      fre.push_back(make_pair(elem, i));
    }
    while (int(v[cur].size()) < val && !fre.empty()) {
      int elem = fre.back().first;
      int mmod = fre.back().second;
      fre.pop_back();
      v[cur].push_back(elem);
      a[elem] += i - mmod;
      ans += i - mmod;
    }
  }
  cout << ans << endl;
  for (int i = 0; i < n; ++i) cout << a[i] << " ";
  cout << endl;
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Write a program which reverses a given string str.

Input

str (the size of str ≤ 20) is given in a line.

Output

Print the reversed str in a line.

Example

Input

w32nimda

Output

admin23w

### Response

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

int main(){
string str;
cin>>str;
reverse(str.begin(),str.end());
cout<<str<<endl;
   return 0;
}
```


### Prompt

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

You are given an undirected graph consisting of n vertices. Initially there are no edges in the graph. Also you are given q queries, each query either adds one undirected edge to the graph or removes it. After each query you have to check if the resulting graph is bipartite (that is, you can paint all vertices of the graph into two colors so that there is no edge connecting two vertices of the same color).

Input

The first line contains two integers n and q (2 ≤ n, q ≤ 100000).

Then q lines follow. ith line contains two numbers xi and yi (1 ≤ xi < yi ≤ n). These numbers describe ith query: if there is an edge between vertices xi and yi, then remove it, otherwise add it.

Output

Print q lines. ith line must contain YES if the graph is bipartite after ith query, and NO otherwise.

Example

Input

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

Output

YES
YES
NO
YES
NO

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
int inp() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int sum = 0;
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum;
}
std::unordered_map<int, int> used[100010];
bool ans[100010];
bool have;
int fa[100010], dis[100010], size[100010];
int fx, fy;
int find(int x) { return fa[x] == x ? x : find(fa[x]); }
int get(int x) {
  int ret = 0;
  while (fa[x] != x) {
    ret ^= dis[x];
    x = fa[x];
  }
  return ret;
}
bool insert(int a, int b) {
  have = false;
  if (find(a) == find(b)) {
    return get(a) != get(b);
  } else {
    have = true;
    fx = find(a);
    fy = find(b);
    if (size[fx] > size[fy]) std::swap(fx, fy);
    fa[fx] = fy;
    size[fy] += size[fx];
    dis[fx] ^= get(a) ^ get(b) ^ 1;
    return true;
  }
}
void erase(int a, int b) {
  fa[a] = a;
  size[b] -= size[a];
  dis[a] = 0;
}
struct SEG_Tree {
  struct SEG {
    int l;
    int r;
    std::vector<std::pair<int, int> > vec;
  } t[800010];
  void build(int cur, int l, int r) {
    t[cur].l = l;
    t[cur].r = r;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(((cur) << 1), l, mid);
    build(((cur) << 1 | 1), mid + 1, r);
  }
  void modify(int cur, int l, int r, std::pair<int, int> c) {
    if (t[cur].l > r || t[cur].r < l) return;
    if (t[cur].l >= l && t[cur].r <= r) {
      t[cur].vec.push_back(c);
      return;
    }
    modify(((cur) << 1), l, r, c);
    modify(((cur) << 1 | 1), l, r, c);
  }
  void solve(int cur, bool flg) {
    std::vector<std::pair<int, int> > v2;
    for (int i = 0; i < t[cur].vec.size(); i++) {
      flg &= insert(t[cur].vec[i].first, t[cur].vec[i].second);
      if (have) v2.push_back(std::make_pair(fx, fy));
    }
    if (t[cur].l == t[cur].r) {
      ans[t[cur].l] = flg;
    } else {
      solve(((cur) << 1), flg);
      solve(((cur) << 1 | 1), flg);
    }
    for (int i = v2.size() - 1; i >= 0; i--) erase(v2[i].first, v2[i].second);
  }
} t;
int x[100010], y[100010];
int main() {
  int ti = clock();
  int n = inp();
  int q = inp();
  t.build(1, 1, q);
  for (register int i = 1; i <= n; i++) {
    fa[i] = i;
    size[i] = 1;
  }
  for (register int i = 1; i <= q; i++) {
    x[i] = inp();
    y[i] = inp();
    if (used[x[i]][y[i]]) {
      t.modify(1, used[x[i]][y[i]], i - 1, std::make_pair(x[i], y[i]));
      used[x[i]][y[i]] = 0;
    } else {
      used[x[i]][y[i]] = i;
    }
  }
  for (register int i = q; i >= 1; i--) {
    if (used[x[i]][y[i]]) {
      t.modify(1, used[x[i]][y[i]], q, std::make_pair(x[i], y[i]));
      used[x[i]][y[i]] = 0;
    }
  }
  t.solve(1, true);
  for (int i = 1; i <= q; i++) {
    if (ans[i])
      puts("YES");
    else
      puts("NO");
  }
}

```


### Prompt

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

Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.

Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the sticks or glue them together. To make a h × w-sized frame, he needs two sticks whose lengths equal h and two sticks whose lengths equal w. Specifically, to make a square frame (when h = w), he needs four sticks of the same length.

Now Nicholas wants to make from the sticks that he has as many frames as possible; to be able to paint as many canvases as possible to fill the frames. Help him in this uneasy task. Note that it is not necessary to use all the sticks Nicholas has.

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100).

Output

Print the single number — the maximum number of frames Nicholas can make for his future canvases.

Examples

Input

5
2 4 3 2 3

Output

1

Input

13
2 2 4 4 4 4 6 6 6 7 7 9 9

Output

3

Input

4
3 3 3 5

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int cmp(int a, int b) { return b < a; }
int main() {
  int n;
  while (~scanf("%d", &n)) {
    int a[10001];
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    sort(a + 1, a + 1 + n, cmp);
    int h1[2] = {0};
    int count = 0;
    int flag = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] == a[i + 1]) {
        a[i] = a[i + 1] = 0;
        i++;
        count++;
        if (count % 2 == 0) {
          flag++;
        }
      }
    }
    printf("%d\n", flag);
  }
}

```


### Prompt

Generate a CPP solution to the following problem:

Andrew skipped lessons on the subject 'Algorithms and Data Structures' for the entire term. When he came to the final test, the teacher decided to give him a difficult task as a punishment.

The teacher gave Andrew an array of n numbers a1, ..., an. After that he asked Andrew for each k from 1 to n - 1 to build a k-ary heap on the array and count the number of elements for which the property of the minimum-rooted heap is violated, i.e. the value of an element is less than the value of its parent.

Andrew looked up on the Wikipedia that a k-ary heap is a rooted tree with vertices in elements of the array. If the elements of the array are indexed from 1 to n, then the children of element v are elements with indices k(v - 1) + 2, ..., kv + 1 (if some of these elements lie outside the borders of the array, the corresponding children are absent). In any k-ary heap every element except for the first one has exactly one parent; for the element 1 the parent is absent (this element is the root of the heap). Denote p(v) as the number of the parent of the element with the number v. Let's say that for a non-root element v the property of the heap is violated if av < ap(v).

Help Andrew cope with the task!

Input

The first line contains a single integer n (2 ≤ n ≤ 2·105).

The second line contains n space-separated integers a1, ..., an ( - 109 ≤ ai ≤ 109).

Output

in a single line print n - 1 integers, separate the consecutive numbers with a single space — the number of elements for which the property of the k-ary heap is violated, for k = 1, 2, ..., n - 1.

Examples

Input

5
1 5 4 3 2

Output

3 2 1 0

Input

6
2 2 2 2 2 2

Output

0 0 0 0 0

Note

Pictures with the heaps for the first sample are given below; elements for which the property of the heap is violated are marked with red.

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

In the second sample all elements are equal, so the property holds for all pairs.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long w = 0, h = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') h = -h;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    w = w * 10 + ch - '0';
    ch = getchar();
  }
  return w * h;
}
struct node {
  long long val, id;
  bool operator<(const node& p) const {
    if (val == p.val) return id < p.id;
    return val < p.val;
  }
} a[200010];
long long n, k, c[200010], res, ans[200010];
void modify(long long x) {
  for (; x <= n; x += x & (-x)) c[x]++;
}
long long ask(long long x) {
  for (res = 0; x; x -= x & (-x)) res += c[x];
  return res;
}
signed main() {
  n = read();
  for (long long i = 1; i <= n; i++) a[i].val = read(), a[i].id = i;
  sort(a + 1, a + n + 1);
  for (long long i = 1; i <= n; i++) {
    long long j = a[i].id;
    for (k = 1; k * (j - 1) + 2 <= n && k < n; k++) {
      long long l = k * (j - 1) + 2, r = min(n, k * j + 1);
      ans[k] += ask(r) - ask(l - 1);
    }
    modify(a[i].id);
  }
  for (long long i = 1; i < n; i++) printf("%lld ", ans[i]);
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

Write a program which print coordinates $(x_i, y_i)$ of given $n$ points on the plane by the following criteria.

1. first by $x$-coordinate
2. in case of a tie, by $y$-coordinate

Constraints

* $1 \leq n \leq 100,000$
* $-1,000,000,000 \leq x_i, y_i \leq 1,000,000,000$

Input

The input is given in the following format.

$n$
$x_0 \; y_0$
$x_1 \; y_1$
:
$x_{n-1} \; y_{n-1}$

In the first line, the number of points $n$ is given. In the following $n$ lines, coordinates of each point are given.

Output

Print coordinate of given points in order.

Example

Input

5
4 7
5 5
2 3
6 8
2 1

Output

2 1
2 3
4 7
5 5
6 8

### Response

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

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in(gcu());}
_sc(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
//_sc(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
template <typename T>
_vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
//_vo(string &s){for (char c: s) pcu(c);}
template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
_vl(){out('\n');}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	vector<pair<int, int>> v(in());
	for (auto &p: v)
		p = {in(), in()};
	sort(v.begin(), v.end());
	for (auto p: v)
		outl(p.first, ' ', p.second);
}

```


### Prompt

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

Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are m applications written in the following form: «employee ai is ready to become a supervisor of employee bi at extra cost ci». The qualification qj of each employee is known, and for each application the following is true: qai > qbi.

Would you help Nick calculate the minimum cost of such a hierarchy, or find out that it is impossible to build it.

Input

The first input line contains integer n (1 ≤ n ≤ 1000) — amount of employees in the company. The following line contains n space-separated numbers qj (0 ≤ qj ≤ 106)— the employees' qualifications. The following line contains number m (0 ≤ m ≤ 10000) — amount of received applications. The following m lines contain the applications themselves, each of them in the form of three space-separated numbers: ai, bi and ci (1 ≤ ai, bi ≤ n, 0 ≤ ci ≤ 106). Different applications can be similar, i.e. they can come from one and the same employee who offered to become a supervisor of the same person but at a different cost. For each application qai > qbi.

Output

Output the only line — the minimum cost of building such a hierarchy, or -1 if it is impossible to build it.

Examples

Input

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

Output

11

Input

3
1 2 3
2
3 1 2
3 1 3

Output

-1

Note

In the first sample one of the possible ways for building a hierarchy is to take applications with indexes 1, 2 and 4, which give 11 as the minimum total cost. In the second sample it is impossible to build the required hierarchy, so the answer is -1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000 + 7;
const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
const long long MOD2 = 998244353;
const long long N = 5000 * 100 + 1;
const long long N2 = 1000 * 1000 + 5;
const long double PI = 3.14159265;
const long long R = 250;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
bool sortbysec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.second < b.second);
}
const long long MAX = 1e4 + 5;
long long id[MAX], nodes, edges;
pair<long long, pair<long long, long long> > p[MAX];
long long vis[N2];
void initialize() {
  for (long long i = 0; i < MAX; ++i) id[i] = i;
}
long long root(long long x) {
  while (id[x] != x) {
    id[x] = id[id[x]];
    x = id[x];
  }
  return x;
}
void union1(long long x, long long y) {
  long long p = root(x);
  long long q = root(y);
  id[q] = id[p];
}
long long kruskal(pair<long long, pair<long long, long long> > p[]) {
  long long x, y;
  long long cost, minimumCost = 0;
  for (long long i = 0; i < edges; ++i) {
    x = p[i].second.first;
    y = p[i].second.second;
    cost = p[i].first;
    if (root(x) != root(y) && !vis[y]) {
      vis[y] = 1;
      minimumCost += cost;
      union1(x, y);
    }
  }
  return minimumCost;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long x, y;
  memset(vis, 0, sizeof(vis));
  long long weight, cost, minimumCost;
  initialize();
  cin >> nodes;
  long long q[N2];
  for (long long i = 1; i <= nodes; i++) {
    cin >> q[i];
  }
  cin >> edges;
  for (long long i = 0; i < edges; ++i) {
    cin >> x >> y >> weight;
    if (q[x] <= q[y]) continue;
    p[i] = make_pair(weight, make_pair(x, y));
  }
  sort(p, p + edges);
  minimumCost = kruskal(p);
  long long c = 0;
  for (long long i = 1; i <= nodes; i++) {
    if (id[i] == i) {
      c++;
    }
  }
  if (c == 1)
    cout << minimumCost << "\n";
  else
    cout << -1 << "\n";
}

```


### Prompt

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

Joisino has a formula consisting of N terms: A_1 op_1 A_2 ... op_{N-1} A_N. Here, A_i is an integer, and op_i is an binary operator either `+` or `-`. Because Joisino loves large numbers, she wants to maximize the evaluated value of the formula by inserting an arbitrary number of pairs of parentheses (possibly zero) into the formula. Opening parentheses can only be inserted immediately before an integer, and closing parentheses can only be inserted immediately after an integer. It is allowed to insert any number of parentheses at a position. Your task is to write a program to find the maximum possible evaluated value of the formula after inserting an arbitrary number of pairs of parentheses.

Constraints

* 1≦N≦10^5
* 1≦A_i≦10^9
* op_i is either `+` or `-`.

Input

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

N
A_1 op_1 A_2 ... op_{N-1} A_N

Output

Print the maximum possible evaluated value of the formula after inserting an arbitrary number of pairs of parentheses.

Examples

Input

3
5 - 1 - 3

Output

7

Input

5
1 - 2 + 3 - 4 + 5

Output

5

Input

5
1 - 20 - 13 + 14 - 5

Output

13

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 100005;
int n, x[MAXN], op[MAXN];
LL ans, rs[MAXN], suf[MAXN];
int main () {
	scanf("%d", &n);
	char ch[2]; op[1] = 1;
	for(int i = 1; i < n; ++i) {
		scanf("%d%s", &x[i], ch); op[i+1] = ch[0]=='+'?1:-1;
		ans += x[i]*op[i];
	}
	scanf("%d", &x[n]); ans += x[n]*op[n];
	for(int i = n; i >= 1; --i)
		rs[i] = (op[i+1] == 1 ? rs[i+1] : 0) + x[i],
		suf[i] = suf[i+1] + x[i];
	LL pre = 0;
	for(int i = 1; i <= n; pre += x[i]*op[i], ++i)
		if(op[i] == -1 ) {
			ans = max(ans, pre + suf[i] - 2*rs[i]);
		}
	printf("%lld\n", ans);
}

```


### Prompt

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

Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of hi identical blocks. For clarification see picture for the first sample.

Limak will repeat the following operation till everything is destroyed.

Block is called internal if it has all four neighbors, i.e. it has each side (top, left, down and right) adjacent to other block or to the floor. Otherwise, block is boundary. In one operation Limak destroys all boundary blocks. His paws are very fast and he destroys all those blocks at the same time.

Limak is ready to start. You task is to count how many operations will it take him to destroy all towers.

Input

The first line contains single integer n (1 ≤ n ≤ 105).

The second line contains n space-separated integers h1, h2, ..., hn (1 ≤ hi ≤ 109) — sizes of towers.

Output

Print the number of operations needed to destroy all towers.

Examples

Input

6
2 1 4 6 2 2

Output

3

Input

7
3 3 3 1 3 3 3

Output

2

Note

The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color.

<image> After first operation there are four blocks left and only one remains after second operation. This last block is destroyed in third operation.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a;
vector<int> v, l, r;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    v.push_back(x);
  }
  int c = 1;
  for (int i = 0; i < n; i++) {
    l.push_back(min(c, v[i]));
    c = min(c, v[i]) + 1;
  }
  c = 1;
  for (int i = n - 1; i >= 0; i--) {
    r.push_back(min(c, v[i]));
    c = min(c, v[i]) + 1;
  }
  reverse(r.begin(), r.end());
  int res = 0;
  for (int i = 0; i < n; i++) res = max(res, min(l[i], r[i]));
  cout << res << endl;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Write a program which prints multiplication tables in the following format:

1x1=1
1x2=2
.
.
9x8=72
9x9=81

Input

No input.

Output

1x1=1
1x2=2
.
.
9x8=72
9x9=81

Example

Input

Output

### Response

```cpp
#include <stdio.h>

int main()
{	int i,j;

	for(i=1;i<=9;i++)
		for(j=1;j<=9;j++)
			printf("%dx%d=%d\n",i,j,i*j);

	return(0);

}
```


### Prompt

Please create a solution in cpp to the following problem:

Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For example, if n = 6 then Funt has to pay 3 burles, while for n = 25 he needs to pay 5 and if n = 2 he pays only 1 burle.

As mr. Funt is a very opportunistic person he wants to cheat a bit. In particular, he wants to split the initial n in several parts n1 + n2 + ... + nk = n (here k is arbitrary, even k = 1 is allowed) and pay the taxes for each part separately. He can't make some part equal to 1 because it will reveal him. So, the condition ni ≥ 2 should hold for all i from 1 to k.

Ostap Bender wonders, how many money Funt has to pay (i.e. minimal) if he chooses and optimal way to split n in parts.

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 2·109) — the total year income of mr. Funt.

Output

Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax.

Examples

Input

4

Output

2

Input

27

Output

3

### Response

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

```


### Prompt

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

Levko has an array that consists of integers: a1, a2, ... , an. But he doesn’t like this array at all.

Levko thinks that the beauty of the array a directly depends on value c(a), which can be calculated by the formula:

<image> The less value c(a) is, the more beautiful the array is.

It’s time to change the world and Levko is going to change his array for the better. To be exact, Levko wants to change the values of at most k array elements (it is allowed to replace the values by any integers). Of course, the changes should make the array as beautiful as possible.

Help Levko and calculate what minimum number c(a) he can reach.

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 2000). The second line contains space-separated integers a1, a2, ... , an ( - 109 ≤ ai ≤ 109).

Output

A single number — the minimum value of c(a) Levko can get.

Examples

Input

5 2
4 7 4 7 4

Output

0

Input

3 1
-100 0 100

Output

100

Input

6 3
1 2 3 7 8 9

Output

1

Note

In the first sample Levko can change the second and fourth elements and get array: 4, 4, 4, 4, 4.

In the third sample he can get array: 1, 2, 3, 4, 5, 6.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 3000;
int n, k;
int a[N];
int dp[N];
bool Judge(long long x) {
  int i, j;
  for (i = 0; i <= n; i++) dp[i] = i;
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++)
      if (x * (j - i) >= abs(a[j] - a[i]))
        dp[j] = min(dp[j], dp[i] + j - i - 1);
    dp[n] = min(dp[n], dp[i] + n - i - 1);
  }
  if (dp[n] <= k) return true;
  return false;
}
int main() {
  scanf("%d%d", &n, &k);
  int i;
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  long long l = 0, r = (1ll << 31) - 1, mid;
  int ret;
  while (l + 1 < r) {
    mid = (l + r) / 2;
    if (Judge(mid))
      r = mid;
    else
      l = mid;
  }
  if (Judge(l))
    printf("%d\n", l);
  else
    printf("%d\n", r);
  return 0;
}

```


### Prompt

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

Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else.

For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic, 34 is 4-magic and 71 is 1-magic.

Find the number of d-magic numbers in the segment [a, b] that are multiple of m. Because the answer can be very huge you should only find its value modulo 109 + 7 (so you should find the remainder after dividing by 109 + 7).

Input

The first line contains two integers m, d (1 ≤ m ≤ 2000, 0 ≤ d ≤ 9) — the parameters from the problem statement.

The second line contains positive integer a in decimal presentation (without leading zeroes).

The third line contains positive integer b in decimal presentation (without leading zeroes).

It is guaranteed that a ≤ b, the number of digits in a and b are the same and don't exceed 2000.

Output

Print the only integer a — the remainder after dividing by 109 + 7 of the number of d-magic numbers in segment [a, b] that are multiple of m.

Examples

Input

2 6
10
99

Output

8

Input

2 0
1
9

Output

4

Input

19 7
1000
9999

Output

6

Note

The numbers from the answer of the first example are 16, 26, 36, 46, 56, 76, 86 and 96.

The numbers from the answer of the second example are 2, 4, 6 and 8.

The numbers from the answer of the third example are 1767, 2717, 5757, 6707, 8797 and 9747.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long M = 2001;
const long long N = 2001;
const long long D = 10;
long long dp[N][M][2];
vector<long long> v;
long long m, d, n;
long long mod = 1e9 + 7;
long long add(long long a, long long b) {
  return ((a % mod) + (b % mod)) % mod;
}
long long sub(long long a, long long b) {
  return ((a % mod) - (b % mod) + mod) % mod;
}
long long solve(long long idx, long long rem, long long flag) {
  if (idx == n) {
    return (rem == 0);
  }
  if (dp[idx][rem][flag] != -1) return dp[idx][rem][flag];
  long long ans = 0;
  if (idx % 2 == 0) {
    long long up;
    if (flag == 0) {
      up = v[idx];
    } else {
      up = 9;
    }
    for (long long i = 0; i <= up; i++) {
      if (i == d) continue;
      if (idx == 0 && i == 0) continue;
      if (i < v[idx]) {
        ans = add(ans, solve(idx + 1, (rem * 10 + i) % m, 1));
      } else {
        ans = add(ans, solve(idx + 1, (rem * 10 + i) % m, flag));
      }
    }
  } else {
    if (flag == 0) {
      if (d < v[idx])
        ans = solve(idx + 1, (rem * 10 + d) % m, 1);
      else if (d == v[idx])
        ans = solve(idx + 1, (rem * 10 + d) % m, 0);
    } else {
      ans = solve(idx + 1, (rem * 10 + d) % m, flag);
    }
  }
  dp[idx][rem][flag] = ans;
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> m >> d;
  string aa, bb;
  cin >> aa;
  cin >> bb;
  for (auto i : bb) {
    v.push_back(i - '0');
  }
  n = (long long)v.size();
  memset(dp, -1, sizeof(dp));
  long long r = solve(0, 0, 0);
  memset(dp, -1, sizeof(dp));
  v.clear();
  for (auto i : aa) {
    v.push_back(i - '0');
  }
  n = v.size();
  if (v[n - 1] == 0) {
    v[n - 1] = 9;
    long long idx = n - 2;
    while (idx >= 0 && v[idx] == 0) {
      v[idx] = 9;
      idx--;
    }
    v[idx]--;
  } else
    v[n - 1]--;
  long long l = solve(0, 0, 0);
  long long ans = sub(r, l);
  cout << ans;
}

```


### Prompt

Create a solution in cpp for the following problem:

You have a tree of n vertices. You are going to convert this tree into n rubber bands on infinitely large plane. Conversion rule follows:

  * For every pair of vertices a and b, rubber bands a and b should intersect if and only if there is an edge exists between a and b in the tree.
  * Shape of rubber bands must be a simple loop. In other words, rubber band is a loop which doesn't self-intersect.

Now let's define following things:

  * Rubber band a includes rubber band b, if and only if rubber band b is in rubber band a's area, and they don't intersect each other.
  * Sequence of rubber bands a_{1}, a_{2}, …, a_{k} (k ≥ 2) are nested, if and only if for all i (2 ≤ i ≤ k), a_{i-1} includes a_{i}.

<image> This is an example of conversion. Note that rubber bands 5 and 6 are nested.

It can be proved that is it possible to make a conversion and sequence of nested rubber bands under given constraints.

What is the maximum length of sequence of nested rubber bands can be obtained from given tree? Find and print it.

Input

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

The i-th of the next n-1 lines contains two integers a_{i} and b_{i} (1 ≤ a_{i} < b_{i} ≤ n) — it means there is an edge between a_{i} and b_{i}. It is guaranteed that given graph forms tree of n vertices.

Output

Print the answer.

Examples

Input

6
1 3
2 3
3 4
4 5
4 6

Output

4

Input

4
1 2
2 3
3 4

Output

2

Note

In the first sample, you can obtain a nested sequence of 4 rubber bands(1, 2, 5, and 6) by the conversion shown below. Of course, there are other conversions exist to make a nested sequence of 4 rubber bands. However, you cannot make sequence of 5 or more nested rubber bands with given tree.

<image>

You can see one of the possible conversions for the second sample below.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
vector<int> adj[MAXN];
int dp[MAXN][2];
int ans;
void merge(array<int, 2> &a, int x) {
  if (x > a[0]) {
    swap(a[0], a[1]);
    a[0] = x;
    return;
  }
  if (x > a[1]) a[1] = x;
}
void dfs(int s, int p = 0) {
  array<int, 2> owo = {0, 0}, uwu = {0, 0};
  dp[s][1] = 1;
  for (auto v : adj[s]) {
    if (v == p) continue;
    dfs(v, s);
    dp[s][0] = max(dp[s][0],
                   max(dp[v][0], dp[v][1]) + (int)adj[s].size() - 2 + (s == 0));
    dp[s][1] = max(dp[s][1], 1 + dp[v][0]);
    merge(owo, dp[v][0]);
    merge(uwu, max(dp[v][0], dp[v][1]));
  }
  ans = max(ans, dp[s][0]);
  ans = max(ans, dp[s][1]);
  ans = max(ans, uwu[0] + uwu[1] + (int)adj[s].size() - 2);
  ans = max(ans, owo[0] + owo[1] + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  ans = 0;
  dfs(1);
  cout << ans << '\n';
}

```


### Prompt

Please create a solution in CPP to the following problem:

We'll call string s[a, b] = sasa + 1... sb (1 ≤ a ≤ b ≤ |s|) a substring of string s = s1s2... s|s|, where |s| is the length of string s.

The trace of a non-empty string t is a set of characters that the string consists of. For example, the trace of string "aab" equals {'a', 'b'}.

Let's consider an arbitrary string s and the set of its substrings with trace equal to C. We will denote the number of substrings from this set that are maximal by inclusion by r(C, s). Substring s[a, b] of length n = b - a + 1 belonging to some set is called maximal by inclusion, if there is no substring s[x, y] in this set with length greater than n, such that 1 ≤ x ≤ a ≤ b ≤ y ≤ |s|. Two substrings of string s are considered different even if they are equal but they are located at different positions of s.

Polycarpus got a challenging practical task on a stringology exam. He must do the following: given string s and non-empty sets of characters C1, C2, ..., Cm, find r(Ci, s) for each set Ci. Help Polycarpus to solve the problem as he really doesn't want to be expelled from the university and go to the army!

Input

The first line contains a non-empty string s (1 ≤ |s| ≤ 106).

The second line contains a single integer m (1 ≤ m ≤ 104). Next m lines contain descriptions of sets Ci. The i-th line contains string ci such that its trace equals Ci. It is guaranteed that all characters of each string ci are different.

Note that Ci are not necessarily different. All given strings consist of lowercase English letters.

Output

Print m integers — the i-th integer must equal r(Ci, s).

Examples

Input

aaaaa
2
a
a

Output

1
1

Input

abacaba
3
ac
ba
a

Output

1
2
4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int M = 1e4 + 10;
int s[30];
short mp[1 << 26], tot;
int ans[M];
void init() {
  memset(s, 0, sizeof(s));
  for (int i = 0; i < 26; i++) {
    s[i] = 1 << i;
  }
}
int up(int aa[N], int l1, int bb[N], int l2) {
  for (int i = 0; i < l1; i++) {
    if (aa[i] == bb[0]) continue;
    bb[l2++] = aa[i];
  }
  return l2;
}
void up1(int aa[N], int l1, int next) {
  int mask = 0;
  for (int i = 0; i < l1; i++) {
    if (aa[i] == next) break;
    mask |= s[aa[i]];
    ans[mp[mask]]++;
  }
}
char ss[N], tt[30];
int fun() {
  int n = strlen(tt);
  int mask = 0;
  for (int i = 0; i < n; i++) {
    mask |= s[tt[i] - 'a'];
  }
  return mask;
}
int aa[M];
int sta[2][N], top[2];
int main() {
  init();
  while (scanf("%s", ss) != EOF) {
    int n = strlen(ss), m = 1;
    for (int i = 1; i < n; i++) {
      if (ss[i] == ss[i - 1])
        continue;
      else
        ss[m++] = ss[i];
    }
    n = m;
    int q;
    scanf("%d", &q);
    memset(mp, 0, sizeof(mp));
    memset(ans, 0, sizeof(ans));
    tot = 0;
    for (int i = 0; i < q; i++) {
      scanf("%s", tt);
      aa[i] = fun();
      if (mp[aa[i]] == 0) {
        mp[aa[i]] = ++tot;
      }
    }
    top[0] = top[1] = 0;
    int id = 0;
    for (int i = 0; i < n; i++) {
      top[id] = 1;
      sta[id][0] = ss[i] - 'a';
      top[id] = up(sta[id ^ 1], top[id ^ 1], sta[id], top[id]);
      if (i + 1 < n)
        up1(sta[id], top[id], ss[i + 1] - 'a');
      else
        up1(sta[id], top[id], -1);
      id ^= 1;
    }
    for (int i = 0; i < q; i++) {
      printf("%d\n", ans[mp[aa[i]]]);
    }
  }
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

The determinant of a matrix 2 × 2 is defined as follows:

<image>

A matrix is called degenerate if its determinant is equal to zero.

The norm ||A|| of a matrix A is defined as a maximum of absolute values of its elements.

You are given a matrix <image>. Consider any degenerate matrix B such that norm ||A - B|| is minimum possible. Determine ||A - B||.

Input

The first line contains two integers a and b (|a|, |b| ≤ 109), the elements of the first row of matrix A.

The second line contains two integers c and d (|c|, |d| ≤ 109) the elements of the second row of matrix A.

Output

Output a single real number, the minimum possible value of ||A - B||. Your answer is considered to be correct if its absolute or relative error does not exceed 10 - 9.

Examples

Input

1 2
3 4

Output

0.2000000000

Input

1 0
0 1

Output

0.5000000000

Note

In the first sample matrix B is <image>

In the second sample matrix B is <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  double a, b, c, d;
  scanf("%lf%lf%lf%lf", &a, &b, &c, &d);
  double l = 0, r = 1e9;
  int j = 0;
  while (r - l >= -1e9 && j <= 100000) {
    double mid = (r + l) / 2;
    double a1 = a + mid, a2 = a - mid, b1 = b + mid, b2 = b - mid, c1 = c + mid,
           c2 = c - mid, d1 = d + mid, d2 = d - mid;
    double l1, r1, l2, r2;
    l1 = min(a1 * d1, min(a1 * d2, min(a2 * d1, a2 * d2)));
    r1 = max(a1 * d1, max(a1 * d2, max(a2 * d1, a2 * d2)));
    l2 = min(b1 * c1, min(b1 * c2, min(b2 * c1, b2 * c2)));
    r2 = max(b1 * c1, max(b1 * c2, max(b2 * c1, b2 * c2)));
    if (l1 <= r2 && l2 <= r1)
      r = mid;
    else
      l = mid;
    j++;
  }
  printf("%.10f\n", l);
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get?

Definitions of subsegment and array splitting are given in notes.

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105) — the size of the array a and the number of subsegments you have to split the array to.

The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109).

Output

Print single integer — the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments.

Examples

Input

5 2
1 2 3 4 5

Output

5

Input

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

Output

-5

Note

A subsegment [l, r] (l ≤ r) of array a is the sequence al, al + 1, ..., ar.

Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark).

In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result.

In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is  - 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void frepik() {}
const int N = (int)1e5 + 1;
const int logN = (int)18;
int mn = (int)1e9 + 9;
int main() {
  frepik();
  int n;
  scanf("%d", &n);
  int k;
  scanf("%d", &k);
  int a[n];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]), mn = min(mn, a[i]);
  if (k == 1) printf("%d", mn), exit(0);
  if (k == 2) {
    int p = 0;
    int mx = (int)-1e9 - 1;
    for (int i = 0; i < n; i++) {
      if (a[i] > mx) mx = a[i], p = i;
    }
    if (p == 0 || p == n - 1)
      printf("%d", mx);
    else
      printf("%d", max(a[0], a[n - 1]));
    exit(0);
  }
  sort(a, a + n);
  printf("%d", a[n - 1]);
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

There is a house with n flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of n integer numbers a_1, a_2, ..., a_n, where a_i = 1 if in the i-th flat the light is on and a_i = 0 otherwise.

Vova thinks that people in the i-th flats are disturbed and cannot sleep if and only if 1 < i < n and a_{i - 1} = a_{i + 1} = 1 and a_i = 0.

Vova is concerned by the following question: what is the minimum number k such that if people from exactly k pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number k.

Input

The first line of the input contains one integer n (3 ≤ n ≤ 100) — the number of flats in the house.

The second line of the input contains n integers a_1, a_2, ..., a_n (a_i ∈ \{0, 1\}), where a_i is the state of light in the i-th flat.

Output

Print only one integer — the minimum number k such that if people from exactly k pairwise distinct flats will turn off the light then nobody will be disturbed.

Examples

Input

10
1 1 0 1 1 0 1 0 1 0

Output

2

Input

5
1 1 0 0 0

Output

0

Input

4
1 1 1 1

Output

0

Note

In the first example people from flats 2 and 7 or 4 and 7 can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.

There are no disturbed people in second and third examples.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  int a[n], i, j;
  int x = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (j = 0; j < n - 2; j++) {
    if (a[j] == 1 && a[j + 1] == 0 && a[j + 2] == 1) {
      a[j + 2] = 0;
      x++;
    }
  }
  printf("%d", x);
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Have you ever heard of the unit "○○ tsubo" that expresses the area of land? Since ancient times, one samurai has said the area for making rice to eat in a day.

There is a land of a [m] x b [m]. Enter a and b and create a program that outputs the tsubo area S [tsubo] of the land. 1 tsubo = 3.305785 [m2], and a and b are integers less than or equal to 100.

input

a b

A and b separated by one space are given on one line.

output

Output the tsubo area S in one line. An error of 0.0001 or less is allowed.

Example

Input

15 25

Output

113.437508

### Response

```cpp
#include<stdio.h>
int main()
{
	int a,b;
	double t;
	scanf("%d%d",&a,&b);
	t=(double)(a*b)/3.305785;
	printf("%4lf",t);
	return 0;
}
```


### Prompt

Please create a solution in cpp to the following problem:

The Bitlandians are quite weird people. They have very peculiar customs.

As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work.

The kids are excited because just as is customary, they're going to be paid for the job!

Overall uncle J. has got n eggs. G. named his price for painting each egg. Similarly, A. named his price for painting each egg. It turns out that for each egg the sum of the money both A. and G. want for the painting equals 1000.

Uncle J. wants to distribute the eggs between the children so as to give each egg to exactly one child. Also, Uncle J. wants the total money paid to A. to be different from the total money paid to G. by no more than 500.

Help Uncle J. Find the required distribution of eggs or otherwise say that distributing the eggs in the required manner is impossible.

Input

The first line contains integer n (1 ≤ n ≤ 106) — the number of eggs.

Next n lines contain two integers ai and gi each (0 ≤ ai, gi ≤ 1000; ai + gi = 1000): ai is the price said by A. for the i-th egg and gi is the price said by G. for the i-th egg.

Output

If it is impossible to assign the painting, print "-1" (without quotes).

Otherwise print a string, consisting of n letters "G" and "A". The i-th letter of this string should represent the child who will get the i-th egg in the required distribution. Letter "A" represents A. and letter "G" represents G. If we denote the money Uncle J. must pay A. for the painting as Sa, and the money Uncle J. must pay G. for the painting as Sg, then this inequality must hold: |Sa - Sg| ≤ 500.

If there are several solutions, you are allowed to print any of them.

Examples

Input

2
1 999
999 1

Output

AG

Input

3
400 600
400 600
400 600

Output

AGA

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
  int n;
  cin >> n;
  string sol = "";
  ll aSum = 0, gSum = 0;
  for (int i = 0; i < n; i++) {
    int a, g;
    cin >> a >> g;
    if (abs(aSum + a - gSum) <= 500) {
      aSum += a;
      sol += 'A';
    } else {
      gSum += g;
      sol += 'G';
    }
  }
  if (abs(aSum - gSum) > 500) {
    cout << -1 << endl;
    return;
  }
  cout << sol << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}

```


### Prompt

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

A tuple of positive integers {x1, x2, ..., xk} is called simple if for all pairs of positive integers (i, j) (1 ≤ i < j ≤ k), xi + xj is a prime.

You are given an array a with n positive integers a1, a2, ..., an (not necessary distinct). You want to find a simple subset of the array a with the maximum size.

A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.

Let's define a subset of the array a as a tuple that can be obtained from a by removing some (possibly all) elements of it.

Input

The first line contains integer n (1 ≤ n ≤ 1000) — the number of integers in the array a.

The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.

Output

On the first line print integer m — the maximum possible size of simple subset of a.

On the second line print m integers bl — the elements of the simple subset of the array a with the maximum size.

If there is more than one solution you can print any of them. You can print the elements of the subset in any order.

Examples

Input

2
2 3

Output

2
3 2

Input

2
2 2

Output

1
2

Input

3
2 1 1

Output

3
1 1 2

Input

2
83 14

Output

2
14 83

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
long long int arr[2000009], brr[2000009];
int main() {
  int test_case = 1;
  for (int cs = 1; cs <= test_case; cs++) {
    for (int i = 2; i <= 2000009 - 9; i++) {
      if (!arr[i]) {
        for (int j = i + i; j <= 2000009 - 9; j += i) arr[j] = 1;
      }
    }
    long long int n;
    scanf("%lld", &n);
    long long int a1 = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &brr[i]);
      if (brr[i] == 1) a1++;
    }
    if (a1) {
      long long int b1 = 0;
      for (int i = 1; i <= n; i++) {
        if (brr[i] != 1 && arr[brr[i] + 1] == 0) {
          b1 = brr[i];
          break;
        }
      }
      if ((b1 + a1) < 2) {
        for (int i = 1; i <= n; i++) {
          for (int j = i + 1; j <= n; j++) {
            if (arr[brr[i] + brr[j]] == 0) {
              printf("2\n%lld %lld\n", brr[i], brr[j]);
              return 0;
            }
          }
        }
      }
      if (b1)
        printf("%lld\n", a1 + 1);
      else
        printf("%lld\n", a1);
      if (b1) printf("%lld ", b1);
      while (a1--) printf("1 ");
      printf("\n");
      return 0;
    }
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        if (arr[brr[i] + brr[j]] == 0) {
          printf("2\n%lld %lld\n", brr[i], brr[j]);
          return 0;
        }
      }
    }
    printf("1\n%lld\n", brr[1]);
  }
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

A railroad running from west to east in Atcoder Kingdom is now complete.

There are N stations on the railroad, numbered 1 through N from west to east.

Tomorrow, the opening ceremony of the railroad will take place.

On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated.

The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds.

Here, it is guaranteed that F_i divides S_i.

That is, for each Time t satisfying S_i≤t and t％F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A％B denotes A modulo B, and there will be no other trains.

For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.

Constraints

* 1≤N≤500
* 1≤C_i≤100
* 1≤S_i≤10^5
* 1≤F_i≤10
* S_i％F_i=0
* All input values are integers.

Input

Input is given from Standard Input in the following format:

N
C_1 S_1 F_1
:
C_{N-1} S_{N-1} F_{N-1}

Output

Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x.

Examples

Input

3
6 5 1
1 10 1

Output

12
11
0

Input

4
12 24 6
52 16 4
99 2 2

Output

187
167
101
0

Input

4
12 13 1
44 17 17
66 4096 64

Output

4162
4162
4162
0

### Response

```cpp
#include <iostream>
using namespace std;
int n, c[505], s[505], f[505];
int main() {
	int i, j, t;
	cin>>n;
	for(i=0; i<n-1; i++) cin>>c[i]>>s[i]>>f[i];
	for(i=0; i<n; i++) {
		for(j=i, t=0; j<n-1; j++) t = max(s[j], (t+f[j]-1)/f[j]*f[j]) + c[j];
		cout<<t<<endl;
	}
	return 0;
}
```


### Prompt

Develop a solution in cpp to the problem described below:

For an array b of length m we define the function f as

 f(b) = \begin{cases} b[1] &   if  m = 1 \\\ f(b[1] ⊕ b[2],b[2] ⊕ b[3],...,b[m-1] ⊕ b[m]) &   otherwise, \end{cases}

where ⊕ is [bitwise exclusive OR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).

For example, f(1,2,4,8)=f(1⊕2,2⊕4,4⊕8)=f(3,6,12)=f(3⊕6,6⊕12)=f(5,10)=f(5⊕10)=f(15)=15

You are given an array a and a few queries. Each query is represented as two integers l and r. The answer is the maximum value of f on all continuous subsegments of the array a_l, a_{l+1}, …, a_r.

Input

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

The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^{30}-1) — the elements of the array.

The third line contains a single integer q (1 ≤ q ≤ 100 000) — the number of queries.

Each of the next q lines contains a query represented as two integers l, r (1 ≤ l ≤ r ≤ n).

Output

Print q lines — the answers for the queries.

Examples

Input

3
8 4 1
2
2 3
1 2

Output

5
12

Input

6
1 2 4 8 16 32
4
1 6
2 5
3 4
1 2

Output

60
30
12
3

Note

In first sample in both queries the maximum value of the function is reached on the subsegment that is equal to the whole segment.

In second sample, optimal segment for first query are [3,6], for second query — [2,5], for third — [3,4], for fourth — [1,2].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30) - 1;
const long long linf = (1ll << 62) - 1;
const int N = 5e3 + 100;
int n;
int a[N], na[N];
int result[N][N];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n - i; j++) {
      result[j][j + i] = a[j];
    }
    for (int j = 0; j < n - i - 1; j++) {
      na[j] = a[j] ^ a[j + 1];
    }
    for (int j = 0; j < n - i - 1; j++) {
      a[j] = na[j];
    }
  }
  for (int len = 2; len <= n; len++) {
    for (int i = 0; i <= n - len; i++) {
      int l = i, r = i + len - 1;
      result[l][r] = max(result[l][r], max(result[l + 1][r], result[l][r - 1]));
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    scanf("%d%d", &l, &r), l--, r--;
    printf("%d\n", result[l][r]);
  }
  return 0;
}

```


### Prompt

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

Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:

  * Tetrahedron. Tetrahedron has 4 triangular faces.
  * Cube. Cube has 6 square faces.
  * Octahedron. Octahedron has 8 triangular faces.
  * Dodecahedron. Dodecahedron has 12 pentagonal faces.
  * Icosahedron. Icosahedron has 20 triangular faces.

All five kinds of polyhedrons are shown on the picture below:

<image>

Anton has a collection of n polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number!

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of polyhedrons in Anton's collection.

Each of the following n lines of the input contains a string si — the name of the i-th polyhedron in Anton's collection. The string can look like this:

  * "Tetrahedron" (without quotes), if the i-th polyhedron in Anton's collection is a tetrahedron.
  * "Cube" (without quotes), if the i-th polyhedron in Anton's collection is a cube.
  * "Octahedron" (without quotes), if the i-th polyhedron in Anton's collection is an octahedron.
  * "Dodecahedron" (without quotes), if the i-th polyhedron in Anton's collection is a dodecahedron.
  * "Icosahedron" (without quotes), if the i-th polyhedron in Anton's collection is an icosahedron.

Output

Output one number — the total number of faces in all the polyhedrons in Anton's collection.

Examples

Input

4
Icosahedron
Cube
Tetrahedron
Dodecahedron

Output

42

Input

3
Dodecahedron
Octahedron
Octahedron

Output

28

Note

In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, a = 0, b;
  string ch;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> ch;
    if (ch == "Tetrahedron")
      a += 4;
    else if (ch == "Cube")
      a += 6;
    else if (ch == "Octahedron")
      a += 8;
    else if (ch == "Dodecahedron")
      a += 12;
    else if (ch == "Icosahedron")
      a += 20;
  }
  cout << a << endl;
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance?

Input

The first and only line of input contains a single integer n (1 ≤ n ≤ 10^9).

Output

Output the minimum number of bills that Allen could receive.

Examples

Input

125

Output

3

Input

43

Output

5

Input

1000000000

Output

10000000

Note

In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills.

In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills.

In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int total(int n) {
  int total = 0;
  if (n >= 100) {
    total += n / 100;
    n %= 100;
  }
  if (n >= 20) {
    total += n / 20;
    n %= 20;
  }
  if (n >= 10) {
    total += n / 10;
    n %= 10;
  }
  if (n >= 5) {
    total += n / 5;
    n %= 5;
  }
  if (n >= 1) {
    total += n;
  }
  return total;
}
int main() {
  int n;
  cin >> n;
  cout << total(n) << endl;
}

```


### Prompt

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

You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?

Let's assume that the rows of matrix a are numbered from 1 to n from top to bottom and the columns are numbered from 1 to m from left to right. A matrix cell on the intersection of the i-th row and the j-th column can be represented as (i, j). Formally, a submatrix of matrix a is a group of four integers d, u, l, r (1 ≤ d ≤ u ≤ n; 1 ≤ l ≤ r ≤ m). We will assume that the submatrix contains cells (i, j) (d ≤ i ≤ u; l ≤ j ≤ r). The area of the submatrix is the number of cells it contains.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 5000). Next n lines contain m characters each — matrix a. Matrix a only contains characters: "0" and "1". Note that the elements of the matrix follow without any spaces in the lines.

Output

Print a single integer — the area of the maximum obtained submatrix. If we cannot obtain a matrix of numbers one, print 0.

Examples

Input

1 1
1

Output

1

Input

2 2
10
11

Output

2

Input

4 3
100
011
000
101

Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[5005][5005], dp[5005][5005];
int main() {
  int t, i, j, n, m, ans, sum;
  char ch, str[5005];
  vector<int> vec;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    scanf("\n");
    gets(str);
    for (j = 1; j <= m; j++) a[i][j] = str[j - 1] - '0';
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++)
      (a[i][j] == 1) ? dp[i][j] = dp[i][j - 1] + 1 : dp[i][j] = 0;
  }
  ans = 0;
  for (j = 1; j <= m; j++) {
    for (i = 1; i <= n; i++) vec.push_back(dp[i][j]);
    sort(vec.begin(), vec.end());
    for (i = 1; i <= n; i++) ans = max(ans, vec[i - 1] * (n - i + 1));
    vec.clear();
  }
  cout << ans;
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris.

There are exactly s blocks in Chris's set, each block has a unique number from 1 to s. Chris's teacher picks a subset of blocks X and keeps it to himself. He will give them back only if Chris can pick such a non-empty subset Y from the remaining blocks, that the equality holds:

<image> "Are you kidding me?", asks Chris.

For example, consider a case where s = 8 and Chris's teacher took the blocks with numbers 1, 4 and 5. One way for Chris to choose a set is to pick the blocks with numbers 3 and 6, see figure. Then the required sums would be equal: (1 - 1) + (4 - 1) + (5 - 1) = (8 - 3) + (8 - 6) = 7.

<image>

However, now Chris has exactly s = 106 blocks. Given the set X of blocks his teacher chooses, help Chris to find the required set Y!

Input

The first line of input contains a single integer n (1 ≤ n ≤ 5·105), the number of blocks in the set X. The next line contains n distinct space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 106), the numbers of the blocks in X.

Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.

Output

In the first line of output print a single integer m (1 ≤ m ≤ 106 - n), the number of blocks in the set Y. In the next line output m distinct space-separated integers y1, y2, ..., ym (1 ≤ yi ≤ 106), such that the required equality holds. The sets X and Y should not intersect, i.e. xi ≠ yj for all i, j (1 ≤ i ≤ n; 1 ≤ j ≤ m). It is guaranteed that at least one solution always exists. If there are multiple solutions, output any of them.

Examples

Input

3
1 4 5

Output

2
999993 1000000

Input

1
1

Output

1
1000000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a[1001000], cnt;
bool b[1001000];
vector<int> pr;
int main() {
  int half = 500000, s = 1000000;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), b[a[i]] = true;
  for (int i = 1; i <= n; i++) {
    if (b[s - a[i] + 1]) {
      cnt++;
    } else
      pr.push_back(s - a[i] + 1);
  }
  cnt /= 2;
  for (int i = 1; i <= half; i++) {
    if (cnt == 0) break;
    if (!b[i] && !b[s - i + 1]) cnt--, pr.push_back(i), pr.push_back(s - i + 1);
  }
  sort(pr.begin(), pr.end());
  printf("%d\n", pr.size());
  for (int i = 0; i < pr.size(); i++) printf("%d ", pr[i]);
  printf("\n");
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

There are N lines in the xy-plane. The i-th line is represented by A_ix+B_iy=C_i. Any two lines among the N+2 lines, the above N lines plus the x-axis and y-axis, cross each other at exactly one point.

For each pair 1 \leq i < j \leq N, there is a car at the cross point of the i-th and j-th lines. Even where three or more lines intersect at a point, a car is individually placed for each pair of lines. That is, there will be k(k-1)/2 cars placed at the intersection of k lines.

Those cars are already very old, and can only be moved parallel to the x-axis or y-axis.

Takahashi will hold an exhibition of antique cars at a place on the xy-plane. In order to avoid damaging the half-broken cars too much, he will select the place of the exhibition so that the total distance covered will be minimized when all the cars are moved to the place. If such a place is not uniquely determined, among the places that satisfy the condition above, the place with the minimum x-coordinate will be selected. If the place is still not uniquely determined, among the places that satisfy the two conditions above, the place with the minimum y-coordinate will be selected.

Find the place of the exhibition that will be selected.

Constraints

* 2 \leq N \leq 4 × 10^4
* 1 \leq |A_i|,|B_i| \leq 10^4(1 \leq i \leq N)
* 0 \leq |C_i| \leq 10^4(1 \leq i \leq N)
* No two given lines are parallel.
* All input values are integers.

Inputs

Input is given from Standard Input in the following format:

N
A_1 B_1 C_1
:
A_N B_N C_N

Outputs

Print the x-coordinate and y-coordinate of the place of the exhibition that will be selected, in this order, with a space in between. The output will be judged as correct when the absolute or relative error is at most 10^{-9}.

Examples

Input

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

Output

1.000000000000000 1.000000000000000

Input

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

Output

-1.000000000000000 -1.000000000000000

Input

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

Output

-1.722222222222222 1.325000000000000

### Response

```cpp
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdio>
#include <functional>
#define int long long
using namespace std;

const int depth = 16;
class Segtree {
	int data[1 << (depth + 1)];
public:

	void init() { for (int i = 0; i < (1 << (depth + 1)); i++) data[i] = 0; }

	//区間[l, r)にvを足す
	void add(int l, int r, int v, int a = 0, int b = (1 << depth), int id = 0) {
		if (l >= b || r <= a) return;
		if (l <= a && b <= r) { data[id] += v; return; }
		add(l, r, v, a, a + (b - a) / 2, id * 2 + 1);
		add(l, r, v, a + (b - a) / 2, b, id * 2 + 2);
	}

	//要素posの値
	int getNum(int pos) {
		pos = (1 << depth) - 1 + pos;
		int ret = data[pos];
		while (pos > 0) {
			pos = (pos - 1) / 2;
			ret += data[pos];
		}
		return ret;
	}
};

Segtree seg;

int getHanten(vector<double> a) {
	map<double, int> pos;
	int i;
	int n = a.size();

	seg.init();
	for (i = 0; i < n; i++) {
		pos[a[i]] = i;
	}
	for (i = 0; i < n; i++) seg.add(i, i + 1, i);

	sort(a.begin(), a.end());

	int ans = 0;
	for (i = 0; i < n; i++) {
		ans += seg.getNum(pos[a[i]]);
		seg.add(pos[a[i]] + 1, n, -1);
	}
	return ans;
}

int n;
int a[40000], b[40000], c[40000];

int countX(double l) {
	int i;
	typedef pair<double, double> P;
	vector<P> ys;

	for (i = 0; i < n; i++) {
		double y = (c[i] - a[i] * l) / (double)b[i];
		double katamuki = -a[i] / (double)b[i];
		ys.push_back(P(y, katamuki));
	}
	sort(ys.begin(), ys.end(), greater<P>());

	vector<double> a;
	for (i = 0; i < n; i++) {
		a.push_back(ys[i].second);
	}

	return getHanten(a);
}

int countY(double l) {
	int i;
	typedef pair<double, double> P;
	vector<P> xs;

	for (i = 0; i < n; i++) {
		double x = (c[i] - b[i] * l) / (double)a[i];
		double kt = -b[i] / (double)a[i];
		xs.push_back(P(x, kt));
	}
	sort(xs.begin(), xs.end(), greater<P>());

	vector<double> a;
	for (i = 0; i < n; i++) {
		a.push_back(xs[i].second);
	}
	return getHanten(a);
}

signed main() {
	int i;

	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];

	int k = n * (n - 1) / 2;
	double st, ed, mid;

	st = -1e+9;
	ed = 1e+9;
	for (i = 0; i < 70; i++) {
		mid = (st + ed) / 2;
		if (countX(mid) >= (k - 1) / 2 + 1) { ed = mid; }
		else { st = mid; }
	}
	double ansX = st;

	st = -1e+9;
	ed = 1e+9;
	for (i = 0; i < 70; i++) {
		mid = (st + ed) / 2;
		if (countY(mid) >= (k - 1) / 2 + 1) { ed = mid; }
		else { st = mid; }
	}
	double ansY = st;

	printf("%.14f %.14f\n", ansX, ansY);
	return 0;
}
```


### Prompt

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

Berland has n cities, some of them are connected by bidirectional roads. For each road we know whether it is asphalted or not.

The King of Berland Valera II wants to asphalt all roads of Berland, for that he gathered a group of workers. Every day Valera chooses exactly one city and orders the crew to asphalt all roads that come from the city. The valiant crew fulfilled the King's order in a day, then workers went home.

Unfortunately, not everything is as great as Valera II would like. The main part of the group were gastarbeiters — illegal immigrants who are enthusiastic but not exactly good at understanding orders in Berlandian. Therefore, having received orders to asphalt the roads coming from some of the city, the group asphalted all non-asphalted roads coming from the city, and vice versa, took the asphalt from the roads that had it.

Upon learning of this progress, Valera II was very upset, but since it was too late to change anything, he asked you to make a program that determines whether you can in some way asphalt Berlandian roads in at most n days. Help the king.

Input

The first line contains two space-separated integers n, m <image> — the number of cities and roads in Berland, correspondingly. Next m lines contain the descriptions of roads in Berland: the i-th line contains three space-separated integers ai, bi, ci (1 ≤ ai, bi ≤ n; ai ≠ bi; 0 ≤ ci ≤ 1). The first two integers (ai, bi) are indexes of the cities that are connected by the i-th road, the third integer (ci) equals 1, if the road was initially asphalted, and 0 otherwise.

Consider the cities in Berland indexed from 1 to n, and the roads indexed from 1 to m. It is guaranteed that between two Berlandian cities there is not more than one road.

Output

In the first line print a single integer x (0 ≤ x ≤ n) — the number of days needed to asphalt all roads. In the second line print x space-separated integers — the indexes of the cities to send the workers to. Print the cities in the order, in which Valera send the workers to asphalt roads. If there are multiple solutions, print any of them.

If there's no way to asphalt all roads, print "Impossible" (without the quotes).

Examples

Input

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

Output

4
3 2 1 3

Input

3 3
1 2 0
2 3 0
3 1 0

Output

Impossible

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 205;
vector<int> g[MAXN];
vector<int> g2[MAXN];
bool mark[MAXN];
vector<int> topo;
inline void addE(int x, int y) {
  g[x ^ 1].push_back(y);
  g2[y].push_back(x ^ 1);
  g[y ^ 1].push_back(x);
  g2[x].push_back(y ^ 1);
}
void dfs(int u) {
  mark[u] = true;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (!mark[v]) dfs(v);
  }
  topo.push_back(u);
}
int cc;
int comp[MAXN];
void dfs2(int u) {
  mark[u] = true;
  comp[u] = cc;
  for (int i = 0; i < g2[u].size(); i++) {
    int v = g2[u][i];
    if (!mark[v]) dfs2(v);
  }
}
int ans[MAXN];
vector<int> fans;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    u *= 2;
    v *= 2;
    if (!w) {
      addE(u, v);
      addE(u ^ 1, v ^ 1);
    } else {
      addE(u, v ^ 1);
      addE(u ^ 1, v);
    }
  }
  for (int i = 0; i < n * 2; i++)
    if (!mark[i]) dfs(i);
  memset(mark, 0, sizeof mark);
  for (int i = topo.size() - 1; i >= 0; i--) {
    int u = topo[i];
    if (!mark[u]) {
      dfs2(u);
      cc++;
    }
  }
  for (int i = 0; i < n * 2; i++)
    if (comp[i] == comp[i ^ 1]) {
      cout << "Impossible" << endl;
      return 0;
    }
  for (int i = 0; i < topo.size(); i++) {
    int u = topo[i];
    if (ans[u]) continue;
    ans[u] = 1;
    ans[u ^ 1] = 2;
  }
  for (int i = 0; i < n * 2; i += 2)
    if (ans[i] == 2) fans.push_back(i / 2 + 1);
  cout << fans.size() << endl;
  for (int i = 0; i < fans.size(); i++) cout << fans[i] << ' ';
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

You have a coins of value n and b coins of value 1. You always pay in exact change, so you want to know if there exist such x and y that if you take x (0 ≤ x ≤ a) coins of value n and y (0 ≤ y ≤ b) coins of value 1, then the total value of taken coins will be S.

You have to answer q independent test cases.

Input

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

The only line of the test case contains four integers a, b, n and S (1 ≤ a, b, n, S ≤ 10^9) — the number of coins of value n, the number of coins of value 1, the value n and the required total value.

Output

For the i-th test case print the answer on it — YES (without quotes) if there exist such x and y that if you take x coins of value n and y coins of value 1, then the total value of taken coins will be S, and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

Example

Input

4
1 2 3 4
1 2 3 6
5 2 6 27
3 3 5 18

Output

YES
NO
NO
YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long a, b, n, s, t, p, bal, ans;
  cin >> t;
  while (t--) {
    cin >> a >> b >> n >> s;
    p = s / n;
    ans = min(p, a);
    bal = s - ans * n;
    if (bal <= b)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

You are given a rooted tree. Let's denote d(x) as depth of node x: depth of the root is 1, depth of any other node x is d(y) + 1, where y is a parent of x.

The tree has the following property: every node x with d(x) = i has exactly ai children. Maximum possible depth of a node is n, and an = 0.

We define fk as the number of unordered pairs of vertices in the tree such that the number of edges on the simple path between them is equal to k.

Calculate fk modulo 109 + 7 for every 1 ≤ k ≤ 2n - 2.

Input

The first line of input contains an integer n (2 ≤ n ≤ 5 000) — the maximum depth of a node.

The second line of input contains n - 1 integers a1, a2, ..., an - 1 (2 ≤ ai ≤ 109), where ai is the number of children of every node x such that d(x) = i. Since an = 0, it is not given in the input.

Output

Print 2n - 2 numbers. The k-th of these numbers must be equal to fk modulo 109 + 7.

Examples

Input

4
2 2 2

Output

14 19 20 20 16 16

Input

3
2 3

Output

8 13 6 9

Note

This the tree from the first sample:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
constexpr int inf32 = 0x3f3f3f3f;
constexpr long long inf64 = 0x3f3f3f3f3f3f3f3f;
constexpr int mod = 1000000007;
constexpr int i2 = 500000004;
struct mint {
  int first;
  mint(int first = 0) : first(first) {}
  friend mint operator+(const mint a, const mint &b) {
    int first = a.first + b.first;
    return mint(first >= mod ? first - mod : first);
  }
  friend mint operator-(const mint a, const mint &b) {
    int first = a.first - b.first;
    return mint(first < 0 ? first + mod : first);
  }
  friend mint operator*(const mint a, const mint &b) {
    return mint(1ll * a.first * b.first % mod);
  }
  friend mint &operator+=(mint &a, const mint &b) { return a = a + b; }
  friend mint &operator-=(mint &a, const mint &b) { return a = a - b; }
  friend mint &operator*=(mint &a, const mint &b) { return a = a * b; }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n, --n;
  vector<mint> a(n + 1);
  for (int i = 0; i < (n); ++i) cin >> a[i].first;
  vector<mint> p(n + 1, 1);
  for (int i = 0; i < (n); ++i) p[i + 1] = p[i] * a[i];
  vector<mint> dw(a), up(n + 1);
  mint res = 0;
  for (int j = 0; j < (n); ++j) res += dw[j] * p[j];
  cout << res.first << ' ';
  for (int i = 0; i < (n * 2 - 1); ++i) {
    res = 0;
    for (int j = (n)-1; j >= 0; --j) {
      up[j + 1] = up[j] * a[j];
      up[j + 1] = dw[j] * p[j] * (a[j] - 1) * i2 + up[j + 1];
      res += up[j + 1];
    }
    for (int j = 0; j < (n); ++j) {
      dw[j] = dw[j + 1] * a[j];
      res += dw[j] * p[j];
    }
    up[0] = dw[n] = 0;
    cout << res.first << ' ';
  }
  cout << '\n';
  return 0;
}

```


### Prompt

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

Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i.

Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen.

Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)

At most how much can he earn on balance?

Note that the same string may be written on multiple cards.

Constraints

* N and M are integers.
* 1 \leq N, M \leq 100
* s_1, s_2, ..., s_N, t_1, t_2, ..., t_M are all strings of lengths between 1 and 10 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N
M
t_1
t_2
:
t_M

Output

If Takahashi can earn at most X yen on balance, print X.

Examples

Input

3
apple
orange
apple
1
grape

Output

2

Input

3
apple
orange
apple
5
apple
apple
apple
apple
apple

Output

1

Input

1
voldemort
10
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort

Output

0

Input

6
red
red
blue
yellow
yellow
red
5
red
red
yellow
green
blue

Output

1

### Response

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

int main() {
	map<string, int> f;
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		f[s]++;
	}
	int M;
	cin >> M;
	for (int i = 0; i < M; i++) {
		string s;
		cin >> s;
		f[s]--;
	}

	int ans = 0;
	for (auto x : f) ans = max(ans, x.second);
	cout << ans << endl;
}
```


### Prompt

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

One player came to a casino and found a slot machine where everything depends only on how he plays. The rules follow.

A positive integer a is initially on the screen. The player can put a coin into the machine and then add 1 to or subtract 1 from any two adjacent digits. All digits must remain from 0 to 9 after this operation, and the leading digit must not equal zero. In other words, it is forbidden to add 1 to 9, to subtract 1 from 0 and to subtract 1 from the leading 1. Once the number on the screen becomes equal to b, the player wins the jackpot. a and b have the same number of digits.

Help the player to determine the minimal number of coins he needs to spend in order to win the jackpot and tell how to play.

Input

The first line contains a single integer n (2 ≤ n ≤ 10^5) standing for the length of numbers a and b.

The next two lines contain numbers a and b, each one on a separate line (10^{n-1} ≤ a, b < 10^n).

Output

If it is impossible to win the jackpot, print a single integer -1.

Otherwise, the first line must contain the minimal possible number c of coins the player has to spend.

min(c, 10^5) lines should follow, i-th of them containing two integers d_i and s_i (1≤ d_i≤ n - 1, s_i = ± 1) denoting that on the i-th step the player should add s_i to the d_i-th and (d_i + 1)-st digits from the left (e. g. d_i = 1 means that two leading digits change while d_i = n - 1 means that there are two trailing digits which change).

Please notice that the answer may be very big and in case c > 10^5 you should print only the first 10^5 moves. Your answer is considered correct if it is possible to finish your printed moves to win the jackpot in the minimal possible number of coins. In particular, if there are multiple ways to do this, you can output any of them.

Examples

Input

3
223
322

Output

2
1 1
2 -1

Input

2
20
42

Output

2
1 1
1 1

Input

2
35
44

Output

-1

Note

In the first example, we can make a +1 operation on the two first digits, transforming number 223 into 333, and then make a -1 operation on the last two digits, transforming 333 into 322.

It's also possible to do these operations in reverse order, which makes another correct answer.

In the last example, one can show that it's impossible to transform 35 into 44.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <class T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U>
void _W(const pair<T, U> &x) {
  _W(x.first);
  putchar(' ');
  _W(x.second);
}
template <class T>
void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin()) putchar(' ');
}
void W() {}
template <class T, class... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
int MOD = 1e9 + 7;
void ADD(long long &x, long long v) {
  x = (x + v) % MOD;
  if (x < 0) x += MOD;
}
const int SIZE = 1e6 + 10;
int d[2][SIZE], n, g[2][SIZE];
long long cal_answer() {
  long long an = 0;
  for (int i = (1); i < (n); ++i) {
    an += abs(g[0][i - 1] - g[1][i - 1]);
    g[0][i] += g[1][i - 1] - g[0][i - 1];
  }
  return an;
}
int need = 100000;
void try_to_add(int id, int v) {
  if (d[0][id + 1] + v >= 10 || d[0][id + 1] + v < 0) {
    try_to_add(id + 1, -v);
  }
  d[0][id] += v;
  d[0][id + 1] += v;
  W(id + 1, v);
  need--;
  if (!need) exit(0);
}
void check(int id) {
  while (d[0][id] < d[1][id]) {
    try_to_add(id, 1);
  }
  while (d[0][id] > d[1][id]) {
    try_to_add(id, -1);
  }
}
int main() {
  R(n);
  string s1, s2;
  R(s1, s2);
  int dif = 0;
  for (int i = 0; i < (n); ++i) {
    g[0][i] = d[0][i] = s1[i] - '0';
    g[1][i] = d[1][i] = s2[i] - '0';
    if (i % 2 == 0)
      dif += d[0][i] - d[1][i];
    else
      dif -= d[0][i] - d[1][i];
  }
  if (dif) {
    W(-1);
    return 0;
  }
  W(cal_answer());
  for (int i = 0; i < (n - 1); ++i) {
    check(i);
  }
  return 0;
}

```


### Prompt

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

As we all know, Dart is some kind of creature from Upside Down world. For simplicity, we call their kind pollywogs. Dart and x - 1 other pollywogs are playing a game. There are n stones in a row, numbered from 1 through n from left to right. At most 1 pollywog may be sitting on each stone at a time. Initially, the pollywogs are sitting on the first x stones (one pollywog on each stone).

<image>

Dart and his friends want to end up on the last x stones. At each second, the leftmost pollywog should jump to the right. A pollywog can jump at most k stones; more specifically, a pollywog can jump from stone number i to stones i + 1, i + 2, ... i + k. A pollywog can't jump on an occupied stone. Jumping a distance i takes ci amounts of energy from the pollywog.

Also, q stones are special Each time landing on a special stone p, takes wp amounts of energy (in addition to the energy for jump) from the pollywog. wp could be negative, in this case, it means the pollywog absorbs |wp| amounts of energy.

Pollywogs want to spend as little energy as possible (this value could be negative).

They're just pollywogs, so they asked for your help. Tell them the total change in their energy, in case they move optimally.

Input

The first line of input contains four integers, x, k, n and q (1 ≤ x ≤ k ≤ 8, k ≤ n ≤ 108, 0 ≤ q ≤ min(25, n - x)) — the number of pollywogs, the maximum length of jump, the number of stones and the number of special stones.

The next line contains k integers, c1, c2, ... ck, separated by spaces (1 ≤ ci ≤ 109) — the energetic costs of jumps.

The next q lines contain description of the special stones. Each line contains two integers p and wp (x + 1 ≤ p ≤ n, |wp| ≤ 109). All p are distinct.

Output

Print the minimum amount of energy they need, in the first and only line of output.

Examples

Input

2 3 10 2
1 2 3
5 -10
6 1000

Output

6

Input

4 7 85 3
17 5 28 4 52 46 6
59 -76
33 -69
19 2018

Output

135

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
template <typename T, typename Add = std::plus<T>,
          typename Mul = std::multiplies<T>>
struct Matrix {
  std::vector<std::vector<T>> D;
  Matrix(size_t m, size_t n) {
    D.resize(m);
    for (size_t i = 0; i < m; ++i) {
      D[i].resize(n);
    }
  }
  size_t m() const { return D.size(); }
  size_t n() const { return m() == 0 ? 0 : D[0].size(); }
  std::vector<T>& operator[](int i) { return D[i]; }
  Matrix<T, Add, Mul> operator*(const Matrix<T, Add, Mul>& that) const {
    assert(n() == that.m());
    Matrix<T, Add, Mul> r(m(), that.n());
    for (size_t i = 0; i < m(); ++i) {
      for (size_t j = 0; j < that.n(); ++j) {
        for (size_t k = 0; k < n(); ++k) {
          T tmp = Mul()(D[i][k], that.D[k][j]);
          r[i][j] = k == 0 ? tmp : Add()(r[i][j], tmp);
        }
      }
    }
    return r;
  }
  Matrix<T, Add, Mul> operator^(int k) const {
    assert(k >= 0);
    assert(m() == n());
    Matrix<T, Add, Mul> r(1, 1);
    bool initial = true;
    auto t = *this;
    while (k) {
      if (k & 1) {
        r = initial ? t : r * t;
        initial = false;
      }
      t = t * t;
      k >>= 1;
    }
    return r;
  }
  void print() const {
    for (size_t i = 0; i < m(); ++i) {
      for (size_t j = 0; j < n(); ++j) {
        std::cout << D[i][j] << ' ';
      }
      std::cout << std::endl;
    }
  }
};
const LL INF = 1LL << 61;
LL calcJumpCost(const bitset<10>& from, const bitset<10>& to, int Cost[]) {
  assert(from.count() == to.count());
  auto shift = to << 1;
  auto tmp = from ^ shift;
  if (tmp.count() == 0)
    return 0;
  else if (tmp.count() != 2)
    return INF;
  else {
    int p = 0;
    while (!from.test(p)) p++;
    if (!tmp.test(p)) return INF;
    tmp.reset(p);
    int q = 0;
    while (!tmp.test(q)) q++;
    if (q < p) return INF;
    return Cost[q - p];
  }
}
template <typename T>
struct Min {
  T operator()(T a, T b) { return min({a, b, INF}); }
};
Matrix<LL, Min<LL>, plus<LL>> buildMatrix(const vector<bitset<10>>& V,
                                          int C[]) {
  Matrix<LL, Min<LL>, plus<LL>> R(V.size(), V.size());
  for (size_t i = 0; i < V.size(); i++) {
    for (size_t j = 0; j < V.size(); j++) {
      auto from = V[i];
      auto to = V[j];
      R[i][j] = calcJumpCost(from, to, C);
    }
  }
  return R;
}
int x, k, n, q;
int C[10];
map<int, int> Special;
int main() {
  scanf("%d%d%d%d", &x, &k, &n, &q);
  vector<bitset<10>> V;
  for (int state = 1; state < (1 << k); state++) {
    auto bs = bitset<10>(state);
    if (int(bs.count()) != x) continue;
    V.push_back(bs);
  }
  for (int i = (1); i <= (k); ++i) scanf("%d", &C[i]);
  LL ans = 0;
  set<int> S;
  for (int i = (1); i <= (q); ++i) {
    int p, w;
    scanf("%d%d", &p, &w);
    if (p >= n - x + 1) {
      ans += w;
      continue;
    }
    for (int j = p - k; j <= p; j++) {
      if (j <= 1) continue;
      S.insert(j);
    }
    Special[p] = w;
  }
  S.insert(n - x + 1);
  auto Mul = buildMatrix(V, C);
  auto A = Mul;
  A.D.resize(1);
  for (size_t i = 0; i < A.n(); ++i) A[0][i] = INF;
  A[0][0] = 0;
  int pre = 1;
  for (auto cur : S) {
    if (cur == pre + 1) {
      auto B = A;
      for (int j = 0; j < int(V.size()); j++) {
        B[0][j] = INF;
        for (int i = 0; i < int(V.size()); i++) {
          LL update = A[0][i];
          auto from = V[i];
          auto to = V[j];
          update += calcJumpCost(from, to, C);
          auto tmp = (from ^ (to << 1)) & (~from);
          for (int k = 0; k < 10; k++) {
            if (tmp.test(k) && Special.find(k + pre) != Special.end()) {
              update += Special[k + pre];
              break;
            }
          }
          B[0][j] = min(B[0][j], update);
        }
      }
      A = B;
    } else {
      A = A * (Mul ^ (cur - pre));
    }
    pre = cur;
  }
  cout << A[0][0] + ans << endl;
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.

You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.

Input

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.

The second line contains n digits — the initial state of the display.

Output

Print a single line containing n digits — the desired state of the display containing the smallest possible number.

Examples

Input

3
579

Output

024

Input

4
2014

Output

0142

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1500;
const int INF = 100000000;
string key(string str, int n) {
  int i, j, num;
  if (str[0] != '0') {
    num = 1 + '9' - str[0];
    str[0] = '0';
    for (i = 1; i < n; i++) {
      str[i] += num;
      if (str[i] > '9') str[i] -= 10;
    }
  }
  return str;
}
int main() {
  int n;
  string a;
  while (~scanf("%d", &n)) {
    int i, j;
    string str, str1;
    a.clear();
    cin >> a;
    str1.clear();
    for (i = 0; i < n; i++) {
      str.clear();
      str += a.substr(i, n - i);
      if (i > 0) str += a.substr(0, i);
      str = key(str, n);
      if (i == 0) str1 = str;
      if (i != 0) {
        str1 = min(str, str1);
      }
    }
    cout << str1 << endl;
  }
  return 0;
}

```


### Prompt

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

Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information.

Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive.

Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages.

You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 105) — the number of blocks in the first and in the second messages.

The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 106) — the length of the blocks that form the first message.

The third line contains m integers y1, y2, ..., ym (1 ≤ yi ≤ 106) — the length of the blocks that form the second message.

It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≤ 106.

Output

Print the maximum number of files the intercepted array could consist of.

Examples

Input

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

Output

3

Input

3 3
1 10 100
1 100 10

Output

2

Input

1 4
4
1 1 1 1

Output

1

Note

In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8.

In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100.

In the third example the only possibility is that the archive contains a single file of size 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n);
  vector<long long> b(m);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  int i = 0, j = 0;
  long long sumi = 0, sumj = 0;
  long long res = 0;
  while (i < n && j < m) {
    if ((sumi + a[i]) == (sumj + b[j])) {
      i++, j++;
      sumi = 0, sumj = 0;
      res++;
      continue;
    }
    if ((sumi + a[i]) < (sumj + b[j])) {
      sumi += a[i];
      i++;
      continue;
    }
    sumj += b[j];
    j++;
  }
  res += ((i != n) || (j != m));
  cout << res << endl;
}

```


### Prompt

Please create a solution in CPP to the following problem:

This is the hard version of the problem. The difference between the versions is the constraint on n and the required number of operations. You can make hacks only if all versions of the problem are solved.

There are two binary strings a and b of length n (a binary string is a string consisting of symbols 0 and 1). In an operation, you select a prefix of a, and simultaneously invert the bits in the prefix (0 changes to 1 and 1 changes to 0) and reverse the order of the bits in the prefix.

For example, if a=001011 and you select the prefix of length 3, it becomes 011011. Then if you select the entire string, it becomes 001001.

Your task is to transform the string a into b in at most 2n operations. It can be proved that it is always possible.

Input

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

The first line of each test case contains a single integer n (1≤ n≤ 10^5) — the length of the binary strings.

The next two lines contain two binary strings a and b of length n.

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

Output

For each test case, output an integer k (0≤ k≤ 2n), followed by k integers p_1,…,p_k (1≤ p_i≤ n). Here k is the number of operations you use and p_i is the length of the prefix you flip in the i-th operation.

Example

Input

5
2
01
10
5
01011
11100
2
01
01
10
0110011011
1000110100
1
0
1

Output

3 1 2 1
6 5 2 5 3 1 2
0
9 4 1 2 10 4 1 2 1 5
1 1

Note

In the first test case, we have 01→ 11→ 00→ 10.

In the second test case, we have 01011→ 00101→ 11101→ 01000→ 10100→ 00100→ 11100.

In the third test case, the strings are already the same. Another solution is to flip the prefix of length 2, which will leave a unchanged.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int tt = 1; tt <= t; tt++) {
    string a, b;
    int n, k = 0;
    cin >> n;
    cin >> a >> b;
    int x = 0, y = 0;
    vector<int> v;
    for (int i = 0; i < n; i++) {
      x = y;
      bool xf = false;
      while (x < n && a[x] == '0') {
        x++;
        xf = true;
      }
      y = x;
      while (y < n && a[y] == '1') y++;
      i = max(i, y);
      if (xf && x != n) v.push_back(x);
      if (x != n) v.push_back(y);
    }
    char tmp = '0';
    for (int i = n - 1; i >= 0; i--) {
      if (tmp != b[i]) {
        if (tmp == '0')
          tmp = '1';
        else
          tmp = '0';
        v.push_back(i + 1);
      }
    }
    cout << v.size();
    for (auto i : v) cout << " " << i;
    cout << endl;
  }
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Recently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed n cans in a row on a table. Cans are numbered from left to right from 1 to n. Vasya has to knock down each can exactly once to finish the exercise. He is allowed to choose the order in which he will knock the cans down.

Vasya knows that the durability of the i-th can is a_i. It means that if Vasya has already knocked x cans down and is now about to start shooting the i-th one, he will need (a_i ⋅ x + 1) shots to knock it down. You can assume that if Vasya starts shooting the i-th can, he will be shooting it until he knocks it down.

Your task is to choose such an order of shooting so that the number of shots required to knock each of the n given cans down exactly once is minimum possible.

Input

The first line of the input contains one integer n (2 ≤ n ≤ 1 000) — the number of cans.

The second line of the input contains the sequence a_1, a_2, ..., a_n (1 ≤ a_i ≤ 1 000), where a_i is the durability of the i-th can.

Output

In the first line print the minimum number of shots required to knock each of the n given cans down exactly once.

In the second line print the sequence consisting of n distinct integers from 1 to n — the order of indices of cans that minimizes the number of shots required. If there are several answers, you can print any of them.

Examples

Input

3
20 10 20

Output

43
1 3 2

Input

4
10 10 10 10

Output

64
2 1 4 3

Input

6
5 4 5 4 4 5

Output

69
6 1 3 5 2 4

Input

2
1 4

Output

3
2 1

Note

In the first example Vasya can start shooting from the first can. He knocks it down with the first shot because he haven't knocked any other cans down before. After that he has to shoot the third can. To knock it down he shoots 20 ⋅ 1 + 1 = 21 times. After that only second can remains. To knock it down Vasya shoots 10 ⋅ 2 + 1 = 21 times. So the total number of shots is 1 + 21 + 21 = 43.

In the second example the order of shooting does not matter because all cans have the same durability.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  pair<int, int> arr[n];
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    arr[i] = make_pair(x, i + 1);
  }
  sort(arr, arr + n);
  int a = 0, sum = 0;
  for (int i = n - 1; i >= 0; --i) {
    sum += (arr[i].first) * a + 1;
    ++a;
  }
  cout << sum << endl;
  for (int i = n - 1; i >= 0; --i) {
    cout << arr[i].second << " ";
  }
  cout << endl;
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.

The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequence) equal to zero for some fixed k (k < n), and this should be done in the smallest possible number of moves.

One move is choosing an integer i (1 ≤ i ≤ n) such that ai > 0 and an integer t (t ≥ 0) such that i + 2t ≤ n. After the values of i and t have been selected, the value of ai is decreased by 1, and the value of ai + 2t is increased by 1. For example, let n = 4 and a = (1, 0, 1, 2), then it is possible to make move i = 3, t = 0 and get a = (1, 0, 0, 3) or to make move i = 1, t = 1 and get a = (0, 0, 2, 2) (the only possible other move is i = 1, t = 0).

You are given n and the initial sequence ai. The task is to calculate the minimum number of moves needed to make the first k elements of the original sequence equal to zero for each possible k (1 ≤ k < n).

Input

The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces.

The input limitations for getting 20 points are:

  * 1 ≤ n ≤ 300

The input limitations for getting 50 points are:

  * 1 ≤ n ≤ 2000

The input limitations for getting 100 points are:

  * 1 ≤ n ≤ 105

Output

Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero.

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

Examples

Input

4
1 0 1 2

Output

1
1
3

Input

8
1 2 3 4 5 6 7 8

Output

1
3
6
10
16
24
40

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int n;
  int A[100001];
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &A[i]);
  long long ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    ans += A[i];
    for (int t = log2(n) + 1; t >= 0; --t) {
      if (i + (1 << t) < n) {
        A[i + (1 << t)] += A[i];
        break;
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}

```


### Prompt

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

Takahashi is a teacher responsible for a class of N students.

The students are given distinct student numbers from 1 to N.

Today, all the students entered the classroom at different times.

According to Takahashi's record, there were A_i students in the classroom when student number i entered the classroom (including student number i).

From these records, reconstruct the order in which the students entered the classroom.

Constraints

* 1 \le N \le 10^5
* 1 \le A_i \le N
* A_i \neq A_j  (i \neq j)
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \ldots A_N

Output

Print the student numbers of the students in the order the students entered the classroom.

Examples

Input

3
2 3 1

Output

3 1 2

Input

5
1 2 3 4 5

Output

1 2 3 4 5

Input

8
8 2 7 3 4 5 6 1

Output

8 2 4 5 6 7 3 1

### Response

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

int main(){
	int n,a,b[100000];
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a;
		b[a] = i;
	}
	for(int i = 1; i <= n; i++){
		cout << b[i];
		if(i != n)cout << " ";
	}
}

```