### Prompt

Construct a Cpp code solution to the problem outlined:

Alfred wants to buy a toy moose that costs c dollars. The store doesn’t give change, so he must give the store exactly c dollars, no more and no less. He has n coins. To make c dollars from his coins, he follows the following algorithm: let S be the set of coins being used. S is initially empty. Alfred repeatedly adds to S the highest-valued coin he has such that the total value of the coins in S after adding the coin doesn’t exceed c. If there is no such coin, and the value of the coins in S is still less than c, he gives up and goes home. Note that Alfred never removes a coin from S after adding it.

As a programmer, you might be aware that Alfred’s algorithm can fail even when there is a set of coins with value exactly c. For example, if Alfred has one coin worth $3, one coin worth $4, and two coins worth $5, and the moose costs $12, then Alfred will add both of the $5 coins to S and then give up, since adding any other coin would cause the value of the coins in S to exceed $12. Of course, Alfred could instead combine one $3 coin, one $4 coin, and one $5 coin to reach the total.

Bob tried to convince Alfred that his algorithm was flawed, but Alfred didn’t believe him. Now Bob wants to give Alfred some coins (in addition to those that Alfred already has) such that Alfred’s algorithm fails. Bob can give Alfred any number of coins of any denomination (subject to the constraint that each coin must be worth a positive integer number of dollars). There can be multiple coins of a single denomination. He would like to minimize the total value of the coins he gives Alfred. Please find this minimum value. If there is no solution, print "Greed is good". You can assume that the answer, if it exists, is positive. In other words, Alfred's algorithm will work if Bob doesn't give him any coins.

Input

The first line contains c (1 ≤ c ≤ 200 000) — the price Alfred wants to pay. The second line contains n (1 ≤ n ≤ 200 000) — the number of coins Alfred initially has. Then n lines follow, each containing a single integer x (1 ≤ x ≤ c) representing the value of one of Alfred's coins.

Output

If there is a solution, print the minimum possible total value of the coins in a solution. Otherwise, print "Greed is good" (without quotes).

Examples

Input

12
3
5
3
4

Output

5

Input

50
8
1
2
4
8
16
37
37
37

Output

Greed is good

Note

In the first sample, Bob should give Alfred a single coin worth $5. This creates the situation described in the problem statement.

In the second sample, there is no set of coins that will cause Alfred's algorithm to fail.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int cnt[200020], prv[200020];
int main() {
  int c, n;
  cin >> c >> n;
  while (n--) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  for (int i = 1; i <= c + 1; i++) {
    prv[i] = cnt[i - 1] ? i - 1 : prv[i - 1];
  }
  for (int i = 1; i <= c; i++) {
    int t = c;
    int m = max(prv[t + 1], i);
    bool used = false;
    while (t && m) {
      int num = min(t / m, (m == i) + cnt[m]);
      t -= m * num;
      if (m == i) used = cnt[m] < num;
      int nxt = prv[min(t + 1, m)];
      if (m > i && nxt < i) nxt = i;
      m = nxt;
    }
    if (t && used) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "Greed is good" << endl;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and n, inclusive.

Input

Input contains one integer number n (1 ≤ n ≤ 3000).

Output

Output the amount of almost prime numbers between 1 and n, inclusive.

Examples

Input

10

Output

2

Input

21

Output

8

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool fn(int x);
int main() {
  int n, i, k = 0;
  scanf("%d", &n);
  i = 6;
  while (k < n && i <= n)
    if (fn(i)) {
      i++;
      k++;
    } else
      i++;
  printf("%d", k);
  return 0;
}
bool fn(int x) {
  int i = 2, a = x, b = 1, k = 0;
  while (1) {
    if (a % i == 0) {
      a /= i;
      if (i > b) {
        k++;
        b = i;
      }
      i = 2;
    } else
      i++;
    if (a == 1) break;
  }
  if (k == 2) return 1;
  return 0;
}

```


### Prompt

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

ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of n × m rooms, and the rooms are arranged in n rows (numbered from the top to the bottom starting from 1) and m columns (numbered from the left to the right starting from 1). The room in the i-th row and j-th column is denoted by (i, j). A player starts in the room (1, 1) and wants to reach the room (n, m).

Each room has four doors (except for ones at the maze border), one on each of its walls, and two adjacent by the wall rooms shares the same door. Some of the doors are locked, which means it is impossible to pass through the door. For example, if the door connecting (i, j) and (i, j + 1) is locked, then we can't go from (i, j) to (i, j + 1). Also, one can only travel between the rooms downwards (from the room (i, j) to the room (i + 1, j)) or rightwards (from the room (i, j) to the room (i, j + 1)) provided the corresponding door is not locked.

<image> This image represents a maze with some doors locked. The colored arrows denotes all the possible paths while a red cross denotes a locked door.

ZS the Coder considers a maze to have difficulty x if there is exactly x ways of travelling from the room (1, 1) to the room (n, m). Two ways are considered different if they differ by the sequence of rooms visited while travelling.

Your task is to create a maze such that its difficulty is exactly equal to T. In addition, ZS the Coder doesn't like large mazes, so the size of the maze and the number of locked doors are limited. Sounds simple enough, right?

Input

The first and only line of the input contains a single integer T (1 ≤ T ≤ 1018), the difficulty of the required maze.

Output

The first line should contain two integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the maze respectively.

The next line should contain a single integer k (0 ≤ k ≤ 300) — the number of locked doors in the maze.

Then, k lines describing locked doors should follow. Each of them should contain four integers, x1, y1, x2, y2. This means that the door connecting room (x1, y1) and room (x2, y2) is locked. Note that room (x2, y2) should be adjacent either to the right or to the bottom of (x1, y1), i.e. x2 + y2 should be equal to x1 + y1 + 1. There should not be a locked door that appears twice in the list.

It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.

Examples

Input

3

Output

3 2
0

Input

4

Output

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

Note

Here are how the sample input and output looks like. The colored arrows denotes all the possible paths while a red cross denotes a locked door.

In the first sample case:

<image>

In the second sample case:

<image>

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
const long long N = 2e6 + 5;
const long long M = 70;
const long long SZ = 450;
const long long mod = 998244353;
const long long inf = 0x3f3f3f3f3f3f3f3f;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
long long ksm(long long x, long long y = mod - 2, long long z = mod) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = (ret * x) % z;
    x = (x * x) % z;
    y >>= 1;
  }
  return ret;
}
struct Four {
  long long x1, _, x2, y2;
};
set<pair<pair<long long, long long>, pair<long long, long long> > > S;
void add(long long x1, long long _, long long x2, long long y2) {
  if (x1 < 1 || _ < 1 || x2 < 1 || y2 < 1) return;
  if (x1 + _ > x2 + y2) swap(x1, x2), swap(_, y2);
  S.insert(make_pair(make_pair(x1, _), make_pair(x2, y2)));
}
long long X, Y;
void change(long long k) {
  add(X - 2, X + 3, X - 1, X + 3);
  add(X - 1, X + 1, X, X + 1);
  add(X, X + 2, X, X + 3);
  add(X, X + 4, X + 1, X + 4);
  add(X + 1, X + 2, X + 1, X + 3);
  add(X + 2, X, X + 3, X);
  add(X + 2, X + 1, X + 3, X + 1);
  add(X + 3, X - 2, X + 3, X - 1);
  add(X + 4, X, X + 4, X + 1);
  if (k % 3 == 0) add(X - 1, X + 2, X, X + 2);
  if (k % 3 != 2) add(X + 2, X - 1, X + 2, X);
  if (k < 3) add(X + 1, X - 1, X + 1, X);
  X += 2;
  Y += 2;
}
long long T;
long long a[N], t, sz;
signed main() {
  T = read();
  add(1, 2, 2, 2);
  add(2, 1, 2, 2);
  X = Y = 2;
  while (T) a[++t] = T % 6, T /= 6;
  for (long long i = t; i >= 1; i--) change(a[i]);
  cout << X << " " << Y << endl;
  for (pair<pair<long long, long long>, pair<long long, long long> > p : S) {
    if (p.first.first > X || p.second.second > X || p.first.second > X ||
        p.second.first > X)
      sz++;
  }
  cout << S.size() - sz << endl;
  for (pair<pair<long long, long long>, pair<long long, long long> > p : S) {
    if (p.first.first > X || p.second.second > X || p.first.second > X ||
        p.second.first > X)
      continue;
    cout << p.first.first << " " << p.first.second << " " << p.second.first
         << " " << p.second.second << "\n";
  }
}

```


### Prompt

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

problem

You are playing with J using the Midakuji. The Amida lottery consists of n vertical bars and m horizontal bars. The vertical bars are numbered from 1 to n in order from the left, and the vertical bar i The positive integer si is written at the bottom of.

<image>

Figure 3-1 Example of Amidakuji (n = 4, m = 5, s1 = 20, s2 = 80, s3 = 100, s4 = 50)

The integer written at the bottom of the vertical bar i, which is reached by following the path from the top of the vertical bar i, is the score when the vertical bar i is selected. For example, in Fig. 3-1 the vertical bar 1 is selected. And the score is 80 points, and if the vertical bar 2 is selected, the score is 100 points.

<image>

Figure 3-2 Example of how to follow the road

Mr. J decides to choose a series of k books from vertical bar 1 to vertical bar k. The total score when selecting those k vertical bars is J's score. However, you are in the Amidakuji You can select one horizontal bar and delete that horizontal bar from the Amidakuji. (You do not have to delete it.) If you delete one horizontal bar, the vertical bar in the deleted Amidakuji will be displayed vertically. J's score is the total of the points when selecting k consecutive vertical bars from bar 1 to vertical bar k.

Given the shape of the Amida lottery and the number of vertical bars k that J chooses as input, create a program that finds the minimum value of J's score.

input

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

On the first line, four integers n, m, h, k are written separated by blanks. N (2 ≤ n ≤ 1000) is the number of vertical bars, and m (1 ≤ m ≤ 100000) is the horizontal bar. H (2 ≤ h ≤ 1000) represents the length of the vertical bar, and k (1 ≤ k ≤ n) represents the number of vertical bars you choose.

The following n lines contain the score written at the bottom of the vertical bar. The first line (1 ≤ i ≤ n) contains the positive integer si. Also, s1 + s2 + ... + sn ≤ 2000000000 = 2 × 109.

The following m lines indicate the position of the horizontal bar. The horizontal bars are numbered from 1 to m. The first line (1 ≤ i ≤ m) is the horizontal bar i. The two integers ai, bi (1 ≤ ai ≤ n --1, 1 ≤ bi ≤ h --1) representing the position are separated by blanks, and the horizontal bar i connects the vertical bar ai and the vertical bar ai + 1. , Indicates that the distance from the top edge of the horizontal bar i is bi. However, no two horizontal bars share an endpoint.

Of the scoring data, 20% of the points will have the lowest score for Mr. J if the horizontal bar is not deleted. Also, 30% of the points will satisfy n ≤ 20, m ≤ 30, h ≤ 10. 60% of the points are m ≤ 1000.

The end of the input is indicated by a line containing four zeros. The number of datasets does not exceed 10.

output

For each dataset, output the minimum score of Mr. J on one line.

Examples

Input

4 5 7 2
20
80
100
50
1 1
2 6
2 3
1 5
3 1
2 2 5 1
10
20
1 1
1 3
0 0 0 0

Output

100
10

Input

None

Output

None

### Response

```cpp
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

template <class T> void max_swap(T& a, const T b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;

struct swap_info { int no1, no2, p1, p2; };
int main()
{
	int n, m, h, k;
	while (scanf("%d%d%d%d", &n, &m, &h, &k), n | m | h | k)
	{
		int s[1024];
		static pint stick[100100];
		for (int i = 0; i < n; ++i)
			scanf("%d", s + i);
		for (int i = 0; i < m; ++i)
		{
			int a, b;
			scanf("%d%d", &a, &b);
			stick[i] = pint(b, a - 1);
		}
		sort(stick, stick + m);

		static pint swap_pair[100100];
		int no[1024];
		for (int i = 0; i < n; ++i)
			no[i] = i;
		for (int i = 0; i < m; ++i)
		{
			int x = stick[i].second;
			swap_pair[i].first = no[x];
			swap_pair[i].second = no[x + 1];

			swap(no[x], no[x + 1]);
		}

		int p[1024];
		for (int i = 0; i < n; ++i)
			p[i] = s[i];

		int max_sub = 0;
		for (int i = m - 1; i >= 0; --i)
		{
			int x = stick[i].second;
			swap(p[x], p[x + 1]);

			pint a(swap_pair[i].first, p[x]);
			pint b(swap_pair[i].second, p[x + 1]);
			if (a > b)
				swap(a, b);
			if (a.first < k && k <= b.first)
				max_swap(max_sub, a.second - b.second);
		}

		printf("%d\n", accumulate(p, p + k, 0) - max_sub);
	}
}
```


### Prompt

Please create a solution in CPP to the following problem:

Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.

This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the n-th digit of this string (digits are numbered starting with 1.

Input

The only line of the input contains a single integer n (1 ≤ n ≤ 1000) — the position of the digit you need to print.

Output

Print the n-th digit of the line.

Examples

Input

3

Output

3

Input

11

Output

0

Note

In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.

In the second sample, the digit at position 11 is '0', it belongs to the integer 10.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n > 0 && n < 10)
    cout << n;
  else if (n > 9 && n <= 189) {
    n = n - 9;
    if (n % 2 == 0) {
      n = 9 + n / 2;
      cout << n % 10;
    } else {
      n = 9 + n / 2 + 1;
      n = n / 10;
      cout << n % 10;
    }
  } else {
    n = n - 189;
    int z = 100 + n / 3;
    if (n % 3 == 0)
      cout << (z - 1) % 10;
    else if (n % 3 == 2) {
      z = z / 10;
      cout << z % 10;
    } else {
      z = z / 100;
      cout << z % 10;
    }
  }
  return 0;
}

```


### Prompt

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

Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement.

Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve.

A wonder strikes Tommy. How many regions are formed by the circles on the sky? We consider the sky as a flat plane. A region is a connected part of the plane with positive area, whose bound consists of parts of bounds of the circles and is a curve or several curves without self-intersections, and that does not contain any curve other than its boundaries. Note that exactly one of the regions extends infinitely.

Input

The first line of input contains one integer n (1 ≤ n ≤ 3), denoting the number of circles.

The following n lines each contains three space-separated integers x, y and r ( - 10 ≤ x, y ≤ 10, 1 ≤ r ≤ 10), describing a circle whose center is (x, y) and the radius is r. No two circles have the same x, y and r at the same time.

Output

Print a single integer — the number of regions on the plane.

Examples

Input

3
0 0 1
2 0 1
4 0 1

Output

4

Input

3
0 0 2
3 0 2
6 0 2

Output

6

Input

3
0 0 2
2 0 2
1 1 2

Output

8

Note

For the first example,

<image>

For the second example,

<image>

For the third example,

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1);
bool eq(double a, double b) { return abs(a - b) < EPS; }
bool lt(double a, double b) { return (a - b < -EPS); }
bool gt(double a, double b) { return (a - b > EPS); }
bool leq(double a, double b) { return a - b < EPS; }
bool geq(double a, double b) { return a - b > -EPS; }
double mySqrt(double a) { return (eq(a, 0) ? 0 : sqrt(a)); }
double sqr(double a) { return a * a; }
struct Point {
  Point(){};
  Point(double x, double y) : x(x), y(y) {}
  double x;
  double y;
  Point operator+=(const Point &other) {
    x = x + other.x;
    y = y + other.y;
    return *this;
  }
  Point operator+(const Point &other) const {
    Point temp = *this;
    return temp += other;
  }
  Point operator-=(const Point &other) {
    x = x - other.x;
    y = y - other.y;
    return *this;
  }
  Point operator-(const Point &other) const {
    Point temp = *this;
    return temp -= other;
  }
  Point operator*(double c) const { return Point{x * c, y * c}; }
  Point operator/(double c) const { return Point{x / c, y / c}; }
  bool operator==(const Point &other) const {
    return eq(x, other.x) && eq(y, other.y);
  }
  bool operator<(const Point &other) const {
    if (eq(x, other.x)) return lt(y, other.y);
    return lt(x, other.x);
  }
  bool operator>(const Point &other) const {
    if (eq(x, other.x)) return gt(y, other.y);
    return gt(x, other.x);
  }
};
istream &operator>>(std::istream &stream, Point &a) {
  stream >> a.x >> a.y;
  return stream;
}
ostream &operator<<(std::ostream &stream, const Point &a) {
  stream << a.x << " " << a.y;
  return stream;
}
double cross(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; }
double dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; }
double dist(const Point &a) { return mySqrt(dot(a, a)); }
double dist(const Point &a, const Point &b) {
  return mySqrt(dot(a - b, a - b));
}
Point footPerp(const Point &a, const Point &b, const Point &c) {
  double x = dot(a - b, c - b) / dist(c - b);
  return b + (c - b) * (x / dist(c - b));
}
double dist(const Point &a, const Point &b, const Point &c) {
  return dist(a - footPerp(a, b, c));
}
vector<Point> intersect(const Point &cen1, double r1, const Point &cen2,
                        double r2) {
  double d = dist(cen1 - cen2);
  if (lt(r1 + r2, d) || gt(abs(r1 - r2), d)) return {};
  double l = ((sqr(r1) - sqr(r2)) / d + d) / 2;
  double h = mySqrt(sqr(r1) - sqr(l));
  Point a = cen1 + (cen2 - cen1) * (l / d);
  Point b = {(cen2 - cen1).y, -(cen2 - cen1).x};
  b = b * (h / dist(cen2 - cen1));
  if (b == Point{0, 0}) return {a};
  return {a + b, a - b};
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<Point> a(n);
  vector<int> r(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> r[i];
  }
  if (n == 1) {
    cout << 2 << endl;
    return 0;
  }
  if (n == 2) {
    vector<Point> d = intersect(a[0], r[0], a[1], r[1]);
    if ((int)(d).size() == 2) {
      cout << 4 << endl;
    } else {
      cout << 3 << endl;
    }
    return 0;
  }
  vector<Point> c;
  vector<vector<Point>> b(n);
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    int j = (i + 1) % n;
    vector<Point> d = intersect(a[i], r[i], a[j], r[j]);
    for (int k = 0; k < (int)(d).size(); ++k) {
      b[i].push_back(d[k]);
      b[j].push_back(d[k]);
      c.push_back(d[k]);
    }
    if ((int)(d).size() != 0) {
      ++cnt;
    }
  }
  sort((c).begin(), (c).end());
  c.resize(unique((c).begin(), (c).end()) - c.begin());
  for (int i = 0; i < n; ++i) {
    sort((b[i]).begin(), (b[i]).end());
    b[i].resize(unique((b[i]).begin(), (b[i]).end()) - b[i].begin());
  }
  int v = (int)(c).size();
  int e = 0;
  for (int i = 0; i < n; ++i) {
    e += (int)(b[i]).size();
  }
  int comp = max(1, n - cnt);
  int f = e - v + comp + 1;
  cout << f << endl;
  return 0;
}

```


### Prompt

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

Sereja has two sequences a and b and number p. Sequence a consists of n integers a1, a2, ..., an. Similarly, sequence b consists of m integers b1, b2, ..., bm. As usual, Sereja studies the sequences he has. Today he wants to find the number of positions q (q + (m - 1)·p ≤ n; q ≥ 1), such that sequence b can be obtained from sequence aq, aq + p, aq + 2p, ..., aq + (m - 1)p by rearranging elements.

Sereja needs to rush to the gym, so he asked to find all the described positions of q.

Input

The first line contains three integers n, m and p (1 ≤ n, m ≤ 2·105, 1 ≤ p ≤ 2·105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). The next line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 109).

Output

In the first line print the number of valid qs. In the second line, print the valid values in the increasing order.

Examples

Input

5 3 1
1 2 3 2 1
1 2 3

Output

2
1 3

Input

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

Output

2
1 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 5;
int n, m, p, a[maxn], b[maxn];
struct T {
  void ins(int x) {
    int &t = f[x];
    s -= abs(t);
    ++t;
    s += abs(t);
  }
  void del(int x) {
    int &t = f[x];
    s -= abs(t);
    --t;
    s += abs(t);
  }
  bool check() { return s == 0; }
  map<int, int> f;
  int s;
} t;
int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  for (int i = 0; i < m; ++i) {
    scanf("%d", b + i);
    t.del(b[i]);
  }
  vector<int> ans;
  for (int i = 0; i < p; ++i)
    if (i < n) {
      int j = i, k = i;
      while (j < n) {
        t.ins(a[j]);
        j += p;
        if ((j - k) / p > m) {
          t.del(a[k]);
          k += p;
        }
        if ((j - k) / p == m && t.check()) ans.push_back(k);
      }
      while (k < j) {
        t.del(a[k]);
        k += p;
      }
    }
  sort(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i) cout << ans[i] + 1 << " ";
  cout << endl;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

You have an array a_1, a_2, ..., a_n. All a_i are positive integers.

In one step you can choose three distinct indices i, j, and k (i ≠ j; i ≠ k; j ≠ k) and assign the sum of a_j and a_k to a_i, i. e. make a_i = a_j + a_k.

Can you make all a_i lower or equal to d using the operation above any number of times (possibly, zero)?

Input

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

The first line of each test case contains two integers n and d (3 ≤ n ≤ 100; 1 ≤ d ≤ 100) — the number of elements in the array a and the value d.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 100) — the array a.

Output

For each test case, print YES, if it's possible to make all elements a_i less or equal than d using the operation above. Otherwise, print NO.

You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).

Example

Input

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

Output

NO
YES
YES

Note

In the first test case, we can prove that we can't make all a_i ≤ 3.

In the second test case, all a_i are already less or equal than d = 4.

In the third test case, we can, for example, choose i = 5, j = 1, k = 2 and make a_5 = a_1 + a_2 = 2 + 1 = 3. Array a will become [2, 1, 5, 3, 3].

After that we can make a_3 = a_5 + a_2 = 3 + 1 = 4. Array will become [2, 1, 4, 3, 3] and all elements are less or equal than d = 4.

### Response

```cpp
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<stdio.h>
#include<string>
#include<set>
#include<iomanip>
#include<numeric>
#include<map>
#include<limits>
#include<unordered_set>
#include<array>
#include<deque>

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	std::cout.tie(0);
	long long t, q, x, l, y, r, g, k, c, m, p;
	long long n;
	string s;
	cin >> t;
	while (t--)
	{
		cin >> n >> k;
		vector<int>a(n);
		int flag = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
			if (a[i] > k)
			{
				flag = 1;
			}
		}
		if (flag == 0)
		{
			cout << "YES";
		}
		else {
			sort(a.begin(), a.end());
			if (a[0] + a[1] <= k)
			{
				cout << "YES";
			}
			else {
				cout << "NO";
			}
		}
		cout << endl;
	}
	return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Rng is going to a festival.

The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer.

Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.

Constraints

* 9 \leq |S| \leq 50
* S consists of uppercase English letters.
* S ends with `FESTIVAL`.

Input

Input is given from Standard Input in the following format:

S

Output

Print the answer to the question: "Rng is going to a festival of what?"

Examples

Input

CODEFESTIVAL

Output

CODE

Input

CODEFESTIVALFESTIVAL

Output

CODEFESTIVAL

Input

YAKINIKUFESTIVAL

Output

YAKINIKU

### Response

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

int main() {
    string s; cin >> s;
    cout << s.substr(0, s.length() - 8) << endl;
    return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Due to the success of TWICE, JYP Entertainment has earned countless money and emerged as the biggest entertainment firm by market capitalization. Therefore, the boss, JYP, has decided to create a new nation and has appointed you to provide a design diagram.

The new nation consists of n cities and some roads between them. JYP has given some restrictions:

  * To guarantee efficiency while avoiding chaos, for any 2 different cities A and B, there is exactly one road between them, and it is one-directional. There are no roads connecting a city to itself.

  * The logo of rivaling companies should not appear in the plan, that is, there does not exist 4 distinct cities A,B,C,D , such that the following configuration occurs.

<image>

JYP has given criteria for your diagram. For two cities A,B, let dis(A,B) be the smallest number of roads you have to go through to get from A to B. If it is not possible to walk from A to B, dis(A,B) = 614n. Then, the efficiency value is defined to be the sum of dis(A,B) for all ordered pairs of distinct cities (A,B).

Note that dis(A,B) doesn't have to be equal to dis(B,A).

You have drawn a design diagram that satisfies JYP's restrictions. Find the sum of dis(A,B) over all ordered pairs of cities (A,B) with A≠ B.

Note that the input is given in compressed form. But even though it is compressed, you'd better use fast input.

Input

The first line contains a single integer n (4 ≤ n ≤ 8000, n ≡ 0 \pmod{4}) — the number of cities.

A binary matrix is encrypted in the following format. Each of n next lines contains n/4 one-digit hexadecimal numbers (that is, these numbers can be represented either as digits from 0 to 9 or as uppercase Latin letters from A to F). Binary representation of each of these numbers denotes next 4 elements of the matrix in the corresponding row. For example, if the number B is given, then the corresponding elements are 1011, and if the number is 5, then the corresponding elements are 0101.

After you obtain the decrypted binary matrix, the j-th character of the i-th row is 1 if the one-directional road between cities i and j is directed from i to j, and 0 otherwise. It is guaranteed that the graph satisfies the restrictions mentioned above.

Output

Output one integer, representing the sum of dis(A,B) over all ordered pairs of cities (A,B) with A≠ B.

Examples

Input

4
7
2
1
4

Output

7380

Input

8
7F
3F
1F
0C
06
03
11
18

Output

88464

Note

The first example corresponds to the matrix:

\begin{matrix} 0111 \\\ 0010 \\\ 0001 \\\ 0100 \\\ \end{matrix}

Which corresponds to this graph:

<image>

dis(1,2)=dis(1,3)=dis(1,4)=dis(2,3)=dis(3,4)=dis(4,2)=1

dis(2,4)=dis(4,3)=dis(3,2)=2

dis(2,1)=dis(3,1)=dis(4,1)=2456

Therefore the answer for the diagram is 7380.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 8e3 + 7;
bool fl[N];
long long val;
bool f[N][N];
char p;
int n, cnt, opt, q[N], g[N];
inline void tarjan(int u) {
  q[++cnt] = u, g[u] = ++opt, fl[u] = 1;
  int c = opt;
  for (int i = 1; i <= n; i++) {
    if (!f[u][i]) continue;
    if (!g[i]) tarjan(i);
    if (fl[i]) g[u] = min(g[u], g[i]);
  }
  if (g[u] == c) {
    while (q[cnt + 1] != u) fl[q[cnt]] = 0, g[q[cnt]] = c, cnt--;
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n / 4; j++) {
      int c = 0;
      char p = getchar();
      while (!(('0' <= p && p <= '9') || ('A' <= p && p <= 'F'))) p = getchar();
      if ('0' <= p && p <= '9')
        c = p - '0';
      else
        c = p - 'A' + 10;
      for (int x = 0; x <= 3; x++)
        if (c & (1 << x)) f[i][j * 4 - x] = 1;
    }
  }
  for (int i = 1; i <= n; i++)
    if (!g[i]) tarjan(i);
  for (int i = 1; i <= n; i++) {
    int w = 0;
    for (int j = 1; j <= n; j++)
      if (!w && f[i][j])
        w = j;
      else if (f[i][j] && f[w][j])
        w = j;
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      if (f[i][j])
        val++;
      else if (f[w][j])
        val += 2;
      else if (g[i] == g[j])
        val += 3;
      else
        val += 614 * n;
    }
  }
  cout << val << endl;
}

```


### Prompt

Please create a solution in CPP to the following problem:

One university has just found out about a sport programming contest called ACM ICPC v2.0. This contest doesn't differ much from the well-known ACM ICPC, for example, the participants are not allowed to take part in the finals more than two times. However, there is one notable difference: the teams in the contest should consist of exactly n participants.

Having taken part in several ACM ICPC v2.0 finals and having not won any medals, the students and the university governors realized that it's high time they changed something about the preparation process. Specifically, as the first innovation it was decided to change the teams' formation process. Having spent considerable amount of time on studying the statistics of other universities' performance, they managed to receive some interesting information: the dependence between the probability of winning a medal and the number of team members that participated in the finals in the past. More formally, we know n + 1 real numbers p0 ≤ p1 ≤ ... ≤ pn, where pi is the probability of getting a medal on the finals if the team has i participants of previous finals, and other n - i participants arrived to the finals for the first time.

Despite such useful data, the university governors are unable to determine such team forming tactics that would provide the maximum probability of winning a medal at ACM ICPC v2.0 finals on average (we are supposed to want to provide such result to the far future and we are also supposed to have an endless supply of students). And how about you, can you offer such optimal tactic? At the first stage the university governors want to know the value of maximum average probability.

More formally, suppose that the university sends a team to the k-th world finals. The team has ak participants of previous finals (0 ≤ ak ≤ n). Since each person can participate in the finals no more than twice, the following condition must be true: <image>. Your task is to choose sequence <image> so that the limit Ψ exists and it's value is maximal:

<image>

As <image> is an infinite sequence, you should only print the maximum value of the Ψ limit.

Input

The first line contains an integer n (3 ≤ n ≤ 100), n is the number of team participants. The second line contains n + 1 real numbers with no more than 6 digits after decimal point pi (0 ≤ i ≤ n, 0 ≤ pi ≤ 1) — the probability of that the team will win a medal if it contains i participants who has already been on the finals. Also the condition pi ≤ pi + 1 should be fulfilled for all 0 ≤ i ≤ n - 1.

Output

Print the only real number — the expected average number of medals won per year if the optimal strategy is used. The result may have absolute or relative error 10 - 6.

Examples

Input

3
0.115590 0.384031 0.443128 0.562356

Output

0.4286122500

Input

3
1 1 1 1

Output

0.9999999999

Note

In the second test, no matter what participants the team contains, it is doomed to be successful.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
double Max = -0.0;
double p[100001];
int main() {
  scanf("%d", &n);
  for (int i = 0; i <= n; i++) scanf("%lf", &p[i]);
  for (int i = 0; i <= (n >> 1); i++)
    for (int j = (n >> 1) + 1; j <= n; j++) {
      double ans = 0.0;
      ans += p[i] * (j * 2 - n);
      if (ans <= 0.0) continue;
      ans += p[j] * (n - i * 2);
      if (ans <= 0.0) continue;
      ans /= 2.0;
      Max = max(Max, ans / ((j - i) * 1.0));
    }
  printf("%.10lf\n", Max);
  return 0;
}

```


### Prompt

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

D: Anipero 2012

Anipero Summer Live, commonly known as Anipero, is the largest anime song live event in Japan where various anime song artists gather. 2D, who loves anime songs, decided to go to Anipero this year as well as last year.

He has already purchased m of psyllium to enjoy Anipero. Psyllium is a stick that glows in a chemical reaction when folded. By shaking the psyllium in time with the rhythm, you can liven up the live performance and increase your satisfaction. All the psylliums he purchased this time have the following properties.

* The psyllium becomes darker as time passes after it is folded, and loses its light in 10 minutes.
* Very bright for 5 minutes after folding (hereinafter referred to as "level 2").
* It will be a little dark 5 minutes after folding (hereinafter referred to as "level 1").
* The speed at which light is lost does not change whether it is shaken or not.

2D decided to consider the following problems as to how satisfied he would be with this year's Anipero by properly using the limited psyllium depending on the song.

He anticipates n songs that will be played during the live. The length of each song is 5 minutes. n songs continue to flow, and the interval between songs can be considered as 0 minutes. The following three parameters are given to each song.

* Satisfaction that increases when only one level 2 is shaken for a certain song
* Satisfaction that increases when only one level 1 is shaken for a certain song
* Satisfaction increases when no song is shaken in a certain song

Shaking the glow stick does not necessarily increase satisfaction. If you shake it, it may disturb the atmosphere of the venue and reduce your satisfaction. The same can be said when not shaking.

Psyllium must be used according to the following rules.

* You can fold only when the song starts, and you can fold as many as you like at one time. The time it takes to fold the psyllium can be ignored.
* Up to 8 songs can be played at the same time in one song.
* When shaking multiple psylliums, calculate the satisfaction level to be added by the following formula.
* (Number of Level 1) x (Satisfaction per level 1) + (Number of Level 2) x (Satisfaction per Level 2)
* If no psyllium is shaken, only the satisfaction level when no one is shaken is added.
* Once you decide to shake the psyllium, you cannot change it until the end of one song.
* The psyllium can be left unshaken. Also, it is not necessary to use up all the psyllium.

2D had finished predicting the live song, but he was tired of it and didn't feel like solving the problem. Your job is to write a program for him that seeks the maximum satisfaction you're likely to get at this year's live concert.

Input

Satisfaction information for the expected song list of the live is input.

On the first line, the number of songs n (1 <= n <= 50) sung live and the number m (0 <= m <= 50) of new psyllium that 2D has at the start of the live are separated by spaces. Is entered in. In the following n lines, the information of one song is input line by line. The i-th (1 <= i <= n) song information is

* Satisfaction level when one level 2 psyllium is shaken for song i ai
* Satisfaction level bi when swinging one level 1 psyllium for song i
* Satisfaction ci when no psyllium is shaken in song i

Are entered separated by spaces (-100 <= ai, bi, ci <= 100).

Output

Output the prediction of 2D's maximum satisfaction at the end of the live in one line. Please note that the maximum satisfaction level may be negative. Output a line break at the end of the line.

Sample Input 1

1 5
2 3 8

Sample Output 1

Ten

Sample Input 2

2 10
2 2 20
2 3 -10

Sample Output 2

44

Sample Input 3

3 10
5 1 9
-3 2 1
1 11 0

Sample Output 3

102

Example

Input

1 5
2 3 8

Output

10

### Response

```cpp
//Name: Anipero 2012
//Level: 2
//Category: 動的計画法,DP
//Note:

/*
 * [i曲目][残り本数][レベル2を振る本数] = 累計満足度でDP。
 * 更新は、レベル1をl本振るとして、dp[i][j][k] = max(∀l,k'. dp[i-1][j+max(l-k',0)+k][k'] + f(i,l,k))
 * （レベル1を増やしたいとき、過去に遡って折っていたことにする；初日はレベル1を振れないことに注意）。
 * サイリウムを折っても、必ずしも振る必要はないことに注意。
 *
 * オーダーは O(NML^3)。
 * ただし、Lは同時に使えるサイリウムの最大本数で、L=8。
 */
#include <iostream>
#include <array>

using namespace std;

template <typename T>
struct Maybe {
    T val;
    bool valid;

    Maybe() : valid(false) {}
    Maybe(T &t) : val(t), valid(true) {}

    T& operator =(const T &rv) {
        val = rv;
        valid = true;
        return val;
    }
};

bool solve() {
    int N, M;
    if(!(cin >> N >> M)) return false;

    array<array<array<Maybe<int>,9>,51>,51> dp;
    dp[0][M][0] = 0;
    for(int i = 1; i <= N; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        for(int j = 0; j <= M; ++j) {
            for(int k = 0; k <= 8; ++k) {
                for(int l = 0; l <= 8-k; ++l) {
                    if(i == 1 && l > 0) break;
                    const int add = (k+l == 0) ? c : l*b + k*a;
                    for(int pk = 0; pk <= 8; ++pk) {
                        const int pj = j + max(0, l-pk) + k;
                        if(pj < 0 || pj > M) continue;
                        if(!dp[i-1][pj][pk].valid) continue;
                        const int ns = dp[i-1][pj][pk].val + add;
                        if(!dp[i][j][k].valid || dp[i][j][k].val < ns) dp[i][j][k] = ns;
                    }
                }
            }
        }
    }
    Maybe<int> ans;
    for(int j = 0; j <= M; ++j) {
        for(int k = 0; k <= 8; ++k) {
            if(dp[N][j][k].valid) {
                const int v = dp[N][j][k].val;
                if(!ans.valid || ans.val < v) ans = v;
            }
        }
    }
    cout << ans.val << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}
```


### Prompt

Construct a Cpp code solution to the problem outlined:

You are given a matrix with n rows (numbered from 1 to n) and m columns (numbered from 1 to m). A number a_{i, j} is written in the cell belonging to the i-th row and the j-th column, each number is either 0 or 1.

A chip is initially in the cell (1, 1), and it will be moved to the cell (n, m). During each move, it either moves to the next cell in the current row, or in the current column (if the current cell is (x, y), then after the move it can be either (x + 1, y) or (x, y + 1)). The chip cannot leave the matrix.

Consider each path of the chip from (1, 1) to (n, m). A path is called palindromic if the number in the first cell is equal to the number in the last cell, the number in the second cell is equal to the number in the second-to-last cell, and so on.

Your goal is to change the values in the minimum number of cells so that every path is palindromic.

Input

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

The first line of each test case contains two integers n and m (2 ≤ n, m ≤ 30) — the dimensions of the matrix.

Then n lines follow, the i-th line contains m integers a_{i, 1}, a_{i, 2}, ..., a_{i, m} (0 ≤ a_{i, j} ≤ 1).

Output

For each test case, print one integer — the minimum number of cells you have to change so that every path in the matrix is palindromic.

Example

Input

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

Output

0
3
4
4

Note

The resulting matrices in the first three test cases:

\begin{pmatrix} 1 & 1\\\ 0 & 1 \end{pmatrix}  \begin{pmatrix} 0 & 0 & 0\\\ 0 & 0 & 0 \end{pmatrix}  \begin{pmatrix} 1 & 0 & 1 & 1 & 1 & 1 & 1\\\ 0 & 1 & 1 & 0 & 1 & 1 & 0\\\ 1 & 1 & 1 & 1 & 1 & 0 & 1 \end{pmatrix}

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int a[n][m], p[n + m - 1], q[n + m - 1];
    for (int i = 0; i < n + m - 1; i++) {
      p[i] = 0;
      q[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> a[i][j];
        if (a[i][j] == 0)
          p[i + j]++;
        else
          q[i + j]++;
      }
    }
    int ind = (n + m - 2) / 2, ans = 0;
    for (int i = 0; i <= ind; i++) {
      int x = p[i] + p[m + n - 2 - i];
      int y = q[i] + q[m + n - 2 - i];
      if ((m + n) % 2 == 0 && i == ind) {
        continue;
      } else
        ans += min(x, y);
    }
    cout << ans << "\n";
  }
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

John Doe has an n × m table. John Doe can paint points in some table cells, not more than one point in one table cell. John Doe wants to use such operations to make each square subtable of size n × n have exactly k points.

John Doe wondered, how many distinct ways to fill the table with points are there, provided that the condition must hold. As this number can be rather large, John Doe asks to find its remainder after dividing by 1000000007 (109 + 7).

You should assume that John always paints a point exactly in the center of some cell. Two ways to fill a table are considered distinct, if there exists a table cell, that has a point in one way and doesn't have it in the other.

Input

A single line contains space-separated integers n, m, k (1 ≤ n ≤ 100; n ≤ m ≤ 1018; 0 ≤ k ≤ n2) — the number of rows of the table, the number of columns of the table and the number of points each square must contain.

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.

Output

In a single line print a single integer — the remainder from dividing the described number of ways by 1000000007 (109 + 7).

Examples

Input

5 6 1

Output

45

Note

Let's consider the first test case:

<image> The gray area belongs to both 5 × 5 squares. So, if it has one point, then there shouldn't be points in any other place. If one of the white areas has a point, then the other one also must have a point. Thus, there are about 20 variants, where the point lies in the gray area and 25 variants, where each of the white areas contains a point. Overall there are 45 variants.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 105, mod = 1e9 + 7;
int dp[N][N * N];
bool done[N][N * N];
int fact[N], inv[N];
int arr1[N];
int arr2[N];
int n, k;
long long m;
inline int add(int a, int b) {
  int res = a + b;
  if (res >= mod) res -= mod;
  return res;
}
inline int mult(int a, int b) {
  long long res = a * 1LL * b;
  return res % mod;
}
int powmod(int a, long long b) {
  int res = 1;
  while (b) {
    if (b & 1) {
      res = mult(res, a);
    }
    a = mult(a, a);
    b >>= 1;
  }
  return res;
}
int ncr(int n, int r) {
  int res = fact[n];
  res = mult(res, inv[r]);
  res = mult(res, inv[n - r]);
  return res;
}
int solve(int pos, int cnt) {
  if (cnt < 0) return 0;
  if (pos == n + 1) return (cnt == 0);
  if (done[pos][cnt]) return dp[pos][cnt];
  if ((n + 1 - pos) * n < cnt) return 0;
  long long p = m / n;
  bool b = (pos <= m % n);
  if (b) {
    for (int i = 0; i <= n; i++) {
      dp[pos][cnt] = add(mult(solve(pos + 1, cnt - i), arr2[i]), dp[pos][cnt]);
    }
  } else {
    for (int i = 0; i <= n; i++) {
      dp[pos][cnt] = add(mult(solve(pos + 1, cnt - i), arr1[i]), dp[pos][cnt]);
    }
  }
  done[pos][cnt] = true;
  return dp[pos][cnt];
}
int main() {
  scanf("%d %I64d %d", &n, &m, &k);
  fact[0] = 1, inv[0] = 1;
  long long p = m / n;
  for (int i = 1; i < N; i++) {
    fact[i] = mult(fact[i - 1], i);
    inv[i] = powmod(fact[i], mod - 2);
  }
  for (int i = 0; i <= n; i++) {
    arr1[i] = powmod(ncr(n, i), p);
    arr2[i] = powmod(ncr(n, i), p + 1);
  }
  memset(dp, 0, sizeof(dp));
  int ans = solve(1, k);
  printf("%d\n", ans);
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Once upon a time in the galaxy of far, far away...

Darth Wader found out the location of a rebels' base. Now he is going to destroy the base (and the whole planet that the base is located at), using the Death Star.

When the rebels learnt that the Death Star was coming, they decided to use their new secret weapon — space mines. Let's describe a space mine's build.

Each space mine is shaped like a ball (we'll call it the mine body) of a certain radius r with the center in the point O. Several spikes protrude from the center. Each spike can be represented as a segment, connecting the center of the mine with some point P, such that <image> (transporting long-spiked mines is problematic), where |OP| is the length of the segment connecting O and P. It is convenient to describe the point P by a vector p such that P = O + p.

The Death Star is shaped like a ball with the radius of R (R exceeds any mine's radius). It moves at a constant speed along the v vector at the speed equal to |v|. At the moment the rebels noticed the Star of Death, it was located in the point A.

The rebels located n space mines along the Death Star's way. You may regard the mines as being idle. The Death Star does not know about the mines' existence and cannot notice them, which is why it doesn't change the direction of its movement. As soon as the Star of Death touched the mine (its body or one of the spikes), the mine bursts and destroys the Star of Death. A touching is the situation when there is a point in space which belongs both to the mine and to the Death Star. It is considered that Death Star will not be destroyed if it can move infinitely long time without touching the mines.

Help the rebels determine whether they will succeed in destroying the Death Star using space mines or not. If they will succeed, determine the moment of time when it will happen (starting from the moment the Death Star was noticed).

Input

The first input data line contains 7 integers Ax, Ay, Az, vx, vy, vz, R. They are the Death Star's initial position, the direction of its movement, and its radius ( - 10 ≤ vx, vy, vz ≤ 10, |v| > 0, 0 < R ≤ 100).

The second line contains an integer n, which is the number of mines (1 ≤ n ≤ 100). Then follow n data blocks, the i-th of them describes the i-th mine.

The first line of each block contains 5 integers Oix, Oiy, Oiz, ri, mi, which are the coordinates of the mine centre, the radius of its body and the number of spikes (0 < ri < 100, 0 ≤ mi ≤ 10). Then follow mi lines, describing the spikes of the i-th mine, where the j-th of them describes the i-th spike and contains 3 integers pijx, pijy, pijz — the coordinates of the vector where the given spike is directed (<image>).

The coordinates of the mines' centers and the center of the Death Star are integers, their absolute value does not exceed 10000. It is guaranteed that R > ri for any 1 ≤ i ≤ n. For any mines i ≠ j the following inequality if fulfilled: <image>. Initially the Death Star and the mines do not have common points.

Output

If the rebels will succeed in stopping the Death Star using space mines, print the time from the moment the Death Star was noticed to the blast.

If the Death Star will not touch a mine, print "-1" (without quotes).

For the answer the absolute or relative error of 10 - 6 is acceptable.

Examples

Input

0 0 0 1 0 0 5
2
10 8 0 2 2
0 -3 0
2 2 0
20 0 0 4 3
2 4 0
-4 3 0
1 -5 0

Output

10.0000000000

Input

8 8 4 4 4 2 6
1
-2 -2 -1 3 0

Output

-1

Input

30 30 2 1 2 1 20
3
0 0 40 5 1
1 4 4
-10 -40 -5 7 0
100 200 95 8 1
-10 0 0

Output

74.6757620881

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
class vec {
 public:
  long double x, y, z;
  vec operator-(const vec& rhs) {
    vec res;
    res.x = x - rhs.x;
    res.y = y - rhs.y;
    res.z = z - rhs.z;
    return res;
  }
  vec operator+(const vec& rhs) {
    vec res;
    res.x = x + rhs.x;
    res.y = y + rhs.y;
    res.z = z + rhs.z;
    return res;
  }
  vec operator*(long double t) {
    vec res = *this;
    res.x *= t;
    res.y *= t;
    res.z *= t;
    return res;
  }
};
long double len(const vec& v) {
  return sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
}
long double len2(const vec& v) { return v.x * v.x + v.y * v.y + v.z * v.z; }
long double dot(const vec& a, const vec& b) {
  return a.x * b.x + a.y * b.y + a.z * b.z;
}
long double cross(const vec& a, const vec& b) {
  vec r;
  r.x = a.y * b.z - b.y * a.z;
  r.y = a.z * b.x - b.z * a.x;
  r.z = a.x * b.y - b.x * a.y;
  return len(r);
}
istream& operator>>(istream& s, vec& v) {
  s >> v.x >> v.y >> v.z;
  return s;
}
ostream& operator<<(ostream& s, vec& v) {
  s << "[" << v.x << ", " << v.y << ", " << v.z << "]";
  return s;
}
long double calc_t(vec p, vec v, long double R) {
  if (dot(p, v) < 0) return 1E+100;
  long double t = dot(p, v) / len2(v);
  if (len2(v * t - p) > R * R) return 1E+100;
  long double l = 0;
  long double r = t;
  while (r - l > 1E-10) {
    t = (r + l) / 2;
    if (len2(v * t - p) > R * R)
      l = t;
    else
      r = t;
  }
  vec x = (v * ((r + l) / 2) - p);
  return (r + l) / 2;
}
int main() {
  vec A, v;
  long double R;
  cin >> A >> v >> R;
  int N;
  cin >> N;
  long double res = 1E+100;
  for (int i = 0; i < N; i++) {
    int m;
    long double r;
    vec C;
    cin >> C >> r >> m;
    res = min(res, calc_t(C - A, v, R + r));
    for (int j = 0; j < m; j++) {
      vec p;
      cin >> p;
      res = min(res, calc_t(C + p - A, v, R));
    }
  }
  if (res == 1E+100)
    cout << -1 << endl;
  else
    cout << fixed << setprecision(10) << res << endl;
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Nathan O. Davis is trying to capture a game and struggling to get a very rare item. This rare item can be obtained by arranging special patterns in a row on a casino slot machine. The slot machine has N reels, and pressing the button once stops the currently rotating leftmost reel. Therefore, you need to press the button N times to get this rare item. Also, in order to stop with a special pattern, it is necessary to press the button at a certain timing. However, the timing of pressing this button was very severe, so I was in trouble because it didn't go well. Therefore, Nathan decided to analyze the game while checking the memory value during the game using the memory viewer.

As a result of Nathan's analysis, in order to stop the reel with that special pattern, the "random number" written at address 007E0D1F in the memory must have a specific value when the button is pressed. I found out. It was also found that the value of the random number changes every frame by the linear congruential method, and whether or not the button is pressed is judged once every frame. Here, the linear congruential method is one of the methods for generating pseudo-random numbers, and the value is determined by the following formula.

x'= (A x x + B) mod C

Here, x is the value of the current random number, x'is the value of the next random number, and A, B, and C are some constants. Also, y mod z represents the remainder when y is divided by z.

For example, suppose a slot machine with two reels has A = 5, B = 7, C = 11 and the first "random number" value is 10. And, the condition for stopping the reel with a special pattern is that the reel on the left side is 2 and the reel on the right side is 4. At this time, the value of the random number in the first frame is (5 × 10 + 7) mod 11 = 2, so if you press the button in the first frame, the reel on the left side will stop with a special pattern. Since the value of the random number in the second frame that follows is (5 x 2 + 7) mod 11 = 6, the reel on the right side does not stop with a special pattern even if the button is pressed in the second frame. In the following 3rd frame, the random number value becomes (5 x 6 + 7) mod 11 = 4, so if you press the button in the 3rd frame, the reel on the right side will stop with a special pattern. Therefore, all reels can be stopped with a special pattern in a minimum of 3 frames, and rare items can be obtained.

Your job is to help Nathan get a rare item by writing a program that asks how many frames in the shortest frame all reels can be stopped with a special pattern. ..

Input

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

> N A B C X
> Y1 Y2 ... YN

The first row contains five integers N (1 ≤ N ≤ 100), A, B (0 ≤ A, B ≤ 10,000), C (1 ≤ C ≤ 10,000), and X (0 ≤ X <C), respectively. It is given separated by two whitespace characters. Here, X represents the value of the first random number. On the following line, N integers Y1, Y2, ..., YN (0 ≤ Yi ≤ 10,000) are given, separated by a single space character. These represent the conditions for stopping the reel with a specific pattern, and the i-th number Yi is the random number value Yi to stop the i-th reel from the left with a special pattern. It means that there must be.

The end of the input is indicated by a single line containing five zeros separated by blanks.

Output

For each dataset, output the shortest number of frames required to stop at a special pattern on one line. If it cannot be stopped within 10,000 frames, output -1 instead of the number of frames. The output must not contain extra blanks or line breaks.

Sample Input

1 5 7 11 10
Ten
2 5 7 11 10
twenty four
2 1 1 256 0
128 255
2 0 0 1 0
1 2 3 4 5 6 7 8
2 1 1 100 0
99 98
2 1 1 100 0
99 99
2 1 1 10000 0
Ten
2 1 1 10000 0
twenty one
0 0 0 0 0

Output for the Sample Input

0
3
255
-1
198
199
10000
-1

Example

Input

1 5 7 11 10
10
2 5 7 11 10
2 4
2 1 1 256 0
128 255
2 0 0 1 0
1234 5678
2 1 1 100 0
99 98
2 1 1 100 0
99 99
2 1 1 10000 0
1 0
2 1 1 10000 0
2 1
0 0 0 0 0

Output

0
3
255
-1
198
199
10000
-1

### Response

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

int main(){
  int n,a,b,c,x,sum;
  int stop[101];
  while(cin>>n>>a>>b>>c>>x,n||a||b||c||x){
    sum = 0;
    for(int i=0;i<n;i++) cin >> stop[i];

    for(int i=0,j=0;i<n;i++){
      while(true){
	if(stop[i] == x) break;
	j++;
	x = (a * x + b) % c;
	if(sum + j > 10000){ sum = -1; goto exit; }
      }
      sum += j;
      x = (a * x + b) % c; j=1;
    }

  exit:
    cout << sum << endl;
  }
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

You are given two integers b and w. You have a chessboard of size 10^9 × 10^9 with the top left cell at (1; 1), the cell (1; 1) is painted white.

Your task is to find a connected component on this chessboard that contains exactly b black cells and exactly w white cells. Two cells are called connected if they share a side (i.e. for the cell (x, y) there are at most four connected cells: (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)). A set of cells is called a connected component if for every pair of cells C_1 and C_2 from this set, there exists a sequence of cells c_1, c_2, ..., c_k such that c_1 = C_1, c_k = C_2, all c_i from 1 to k are belong to this set of cells and for every i ∈ [1, k - 1], cells c_i and c_{i + 1} are connected.

Obviously, it can be impossible to find such component. In this case print "NO". Otherwise, print "YES" and any suitable connected component.

You have to answer q independent queries.

Input

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

The only line of the query contains two integers b and w (1 ≤ b, w ≤ 10^5) — the number of black cells required and the number of white cells required.

It is guaranteed that the sum of numbers of cells does not exceed 2 ⋅ 10^5 (∑ w + ∑ b ≤ 2 ⋅ 10^5).

Output

For each query, print the answer to it.

If it is impossible to find the required component, print "NO" on the first line.

Otherwise, print "YES" on the first line. In the next b + w lines print coordinates of cells of your component in any order. There should be exactly b black cells and w white cells in your answer. The printed component should be connected.

If there are several answers, you can print any. All coordinates in the answer should be in the range [1; 10^9].

Example

Input

3
1 1
1 4
2 5

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int q, b, w;
int main() {
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int x = 2;
    scanf("%d%d", &b, &w);
    swap(b, w);
    if (b > w) swap(b, w), x = 3;
    if (b * 3 + 1 < w) {
      printf("NO\n");
      continue;
    }
    printf("YES\n");
    for (int i = 1; i <= b; ++i) printf("%d %d\n", x, i * 2);
    for (int i = 1; i <= b; ++i) {
      printf("%d %d\n", x, i * 2 - 1);
      --w;
    }
    if (w > 0) {
      printf("%d %d\n", x, b * 2 + 1);
      w--;
    }
    if (w > 0) {
      for (int i = 1; i <= b && w > 0; ++i, w--)
        printf("%d %d\n", x + 1, i * 2);
    }
    if (w > 0) {
      for (int i = 1; i <= b && w > 0; ++i, --w)
        printf("%d %d\n", x - 1, i * 2);
    }
  }
  return 0;
}

```


### Prompt

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

Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed.

For example, the following matrices are palindromic:

<image>

The following matrices are not palindromic because they change after the order of rows is reversed:

<image>

The following matrices are not palindromic because they change after the order of columns is reversed:

<image>

You are given n^2 integers. Put them into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic. If there are multiple answers, print any. If there is no solution, print "NO".

Input

The first line contains one integer n (1 ≤ n ≤ 20).

The second line contains n^2 integers a_1, a_2, ..., a_{n^2} (1 ≤ a_i ≤ 1000) — the numbers to put into a matrix of n rows and n columns.

Output

If it is possible to put all of the n^2 numbers into a matrix of n rows and n columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic, then print "YES". Then print n lines with n space-separated numbers — the resulting matrix.

If it's impossible to construct any matrix, then print "NO".

You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.

Examples

Input

4
1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1

Output

YES
1 2 2 1
8 2 2 8
8 2 2 8
1 2 2 1

Input

3
1 1 1 1 1 3 3 3 3

Output

YES
1 3 1
3 1 3
1 3 1

Input

4
1 2 1 9 8 4 3 8 8 3 4 8 9 2 1 1

Output

NO

Input

1
10

Output

YES
10

Note

Note that there exist multiple answers for the first two examples.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a[405], ans[25][25], maxx, num[1005];
struct node {
  int num, id;
};
queue<int> q[1005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n * n; i++) {
    scanf("%d", &a[i]);
    num[a[i]]++;
    maxx = max(maxx, a[i]);
  }
  for (int i = 1; i <= maxx; i++)
    if (num[i]) q[num[i]].push(i);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (ans[i][j]) continue;
      int x1 = i, y = j;
      int x2 = i, y2 = n - j + 1;
      int x3 = n - i + 1, y3 = j;
      int x4 = n - i + 1, y4 = n - j + 1;
      if (x1 == x2 && y == y2 && x3 == x1 && y3 == y) {
        int f = 0;
        for (int k = 1; k <= n * n; k++) {
          if (q[k].size()) {
            f = 1;
            int t = q[k].front();
            q[k].pop(), num[t]--;
            q[num[t]].push(t);
            ans[i][j] = t;
            break;
          }
        }
        if (!f) {
          printf("NO\n");
          return 0;
        }
      } else if (x1 == x2 && y == y2) {
        int f = 0;
        for (int k = 2; k <= n * n; k++) {
          if (q[k].size()) {
            f = 1;
            int t = q[k].front();
            q[k].pop(), num[t] -= 2;
            q[num[t]].push(t);
            ans[i][j] = t, ans[x3][y3] = t;
            break;
          }
        }
        if (!f) {
          printf("NO\n");
          return 0;
        }
      } else if (x1 == x3 && y == y3) {
        int f = 0;
        for (int k = 2; k <= n * n; k++) {
          if (q[k].size()) {
            f = 1;
            int t = q[k].front();
            q[k].pop(), num[t] -= 2;
            q[num[t]].push(t);
            ans[i][j] = t, ans[x2][y2] = t;
            break;
          }
        }
        if (!f) {
          printf("NO\n");
          return 0;
        }
      } else {
        int f = 0;
        for (int k = 4; k <= n * n; k++) {
          if (q[k].size()) {
            f = 1;
            int t = q[k].front();
            q[k].pop(), num[t] -= 4;
            q[num[t]].push(t);
            ans[i][j] = t, ans[x2][y2] = t, ans[x3][y3] = t, ans[x4][y4] = t;
            break;
          }
        }
        if (!f) {
          printf("NO\n");
          return 0;
        }
      }
    }
  }
  printf("YES\n");
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      printf("%d ", ans[i][j]);
    }
    printf("\n");
  }
  return 0;
}

```


### Prompt

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

We have a string S consisting of uppercase English letters. Additionally, an integer N will be given.

Shift each character of S by N in alphabetical order (see below), and print the resulting string.

We assume that `A` follows `Z`. For example, shifting `A` by 2 results in `C` (`A` \to `B` \to `C`), and shifting `Y` by 3 results in `B` (`Y` \to `Z` \to `A` \to `B`).

Constraints

* 0 \leq N \leq 26
* 1 \leq |S| \leq 10^4
* S consists of uppercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the string resulting from shifting each character of S by N in alphabetical order.

Examples

Input

2
ABCXYZ

Output

CDEZAB

Input

0
ABCXYZ

Output

ABCXYZ

Input

13
ABCDEFGHIJKLMNOPQRSTUVWXYZ

Output

NOPQRSTUVWXYZABCDEFGHIJKLM

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,i;
	string s;
	cin>>n>>s;
	for(i=0;i<s.size();i++)
	{
	    cout<<char('A'+(s[i]+n-'A')%26);
	}
	return 0;
}
```


### Prompt

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

Alice has a string consisting of characters 'A', 'B' and 'C'. Bob can use the following transitions on any substring of our string in any order any number of times:

  * A <image> BC
  * B <image> AC
  * C <image> AB
  * AAA <image> empty string

Note that a substring is one or more consecutive characters. For given queries, determine whether it is possible to obtain the target string from source.

Input

The first line contains a string S (1 ≤ |S| ≤ 105). The second line contains a string T (1 ≤ |T| ≤ 105), each of these strings consists only of uppercase English letters 'A', 'B' and 'C'.

The third line contains the number of queries Q (1 ≤ Q ≤ 105).

The following Q lines describe queries. The i-th of these lines contains four space separated integers ai, bi, ci, di. These represent the i-th query: is it possible to create T[ci..di] from S[ai..bi] by applying the above transitions finite amount of times?

Here, U[x..y] is a substring of U that begins at index x (indexed from 1) and ends at index y. In particular, U[1..|U|] is the whole string U.

It is guaranteed that 1 ≤ a ≤ b ≤ |S| and 1 ≤ c ≤ d ≤ |T|.

Output

Print a string of Q characters, where the i-th character is '1' if the answer to the i-th query is positive, and '0' otherwise.

Example

Input

AABCCBAAB
ABCB
5
1 3 1 2
2 2 2 4
7 9 1 1
3 4 2 3
4 5 1 3

Output

10011

Note

In the first query we can achieve the result, for instance, by using transitions <image>.

The third query asks for changing AAB to A — but in this case we are not able to get rid of the character 'B'.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int sbc[N], sras[N];
int tbc[N], tras[N];
int main() {
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    sbc[i + 1] = sbc[i] + (s[i] == 'B' or s[i] == 'C');
    if (s[i] == 'A') sras[i + 1] = sras[i] + 1;
  }
  for (int i = 0; i < t.size(); i++) {
    tbc[i + 1] = tbc[i] + (t[i] == 'B' or t[i] == 'C');
    if (t[i] == 'A') tras[i + 1] = tras[i] + 1;
  }
  int q;
  cin >> q;
  while (q--) {
    int i1, j1, i2, j2;
    cin >> i1 >> j1 >> i2 >> j2;
    i1--, i2--;
    int ra1 = min(sras[j1], j1 - i1);
    int ra2 = min(tras[j2], j2 - i2);
    int bc1 = sbc[j1] - sbc[i1];
    int bc2 = tbc[j2] - tbc[i2];
    if (ra2 % 3 != ra1 % 3) bc1 += 2;
    if (ra2 > ra1 or ra2 == ra1 and bc1 == 0 and bc2 > 0)
      cout << 0;
    else if (bc1 > bc2 or bc1 % 2 != bc2 % 2)
      cout << 0;
    else
      cout << 1;
  }
  cout << endl;
}

```


### Prompt

Please create a solution in CPP to the following problem:

This is the easier version of the problem. In this version 1 ≤ n, m ≤ 100. You can hack this problem only if you solve and lock both problems.

You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by removing zero or more elements from the sequence a (they do not necessarily go consecutively). For example, for the sequence a=[11,20,11,33,11,20,11]:

  * [11,20,11,33,11,20,11], [11,20,11,33,11,20], [11,11,11,11], [20], [33,20] are subsequences (these are just some of the long list);
  * [40], [33,33], [33,20,20], [20,20,11,11] are not subsequences.

Suppose that an additional non-negative integer k (1 ≤ k ≤ n) is given, then the subsequence is called optimal if:

  * it has a length of k and the sum of its elements is the maximum possible among all subsequences of length k;
  * and among all subsequences of length k that satisfy the previous item, it is lexicographically minimal.

Recall that the sequence b=[b_1, b_2, ..., b_k] is lexicographically smaller than the sequence c=[c_1, c_2, ..., c_k] if the first element (from the left) in which they differ less in the sequence b than in c. Formally: there exists t (1 ≤ t ≤ k) such that b_1=c_1, b_2=c_2, ..., b_{t-1}=c_{t-1} and at the same time b_t<c_t. For example:

  * [10, 20, 20] lexicographically less than [10, 21, 1],
  * [7, 99, 99] is lexicographically less than [10, 21, 1],
  * [10, 21, 0] is lexicographically less than [10, 21, 1].

You are given a sequence of a=[a_1,a_2,...,a_n] and m requests, each consisting of two numbers k_j and pos_j (1 ≤ k ≤ n, 1 ≤ pos_j ≤ k_j). For each query, print the value that is in the index pos_j of the optimal subsequence of the given sequence a for k=k_j.

For example, if n=4, a=[10,20,30,20], k_j=2, then the optimal subsequence is [20,30] — it is the minimum lexicographically among all subsequences of length 2 with the maximum total sum of items. Thus, the answer to the request k_j=2, pos_j=1 is the number 20, and the answer to the request k_j=2, pos_j=2 is the number 30.

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the length of the sequence a.

The second line contains elements of the sequence a: integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).

The third line contains an integer m (1 ≤ m ≤ 100) — the number of requests.

The following m lines contain pairs of integers k_j and pos_j (1 ≤ k ≤ n, 1 ≤ pos_j ≤ k_j) — the requests.

Output

Print m integers r_1, r_2, ..., r_m (1 ≤ r_j ≤ 10^9) one per line: answers to the requests in the order they appear in the input. The value of r_j should be equal to the value contained in the position pos_j of the optimal subsequence for k=k_j.

Examples

Input

3
10 20 10
6
1 1
2 1
2 2
3 1
3 2
3 3

Output

20
10
20
10
20
10

Input

7
1 2 1 3 1 2 1
9
2 1
2 2
3 1
3 2
3 3
1 1
7 1
7 7
7 4

Output

2
3
2
3
2
3
1
1
3

Note

In the first example, for a=[10,20,10] the optimal subsequences are:

  * for k=1: [20],
  * for k=2: [10,20],
  * for k=3: [10,20,10].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, tmp_int, k, pos;
  cin >> n;
  vector<int> a;
  vector<pair<int, int>> b;
  for (int i = 0; i < n; ++i) {
    cin >> tmp_int;
    a.push_back(tmp_int);
    b.emplace_back(tmp_int, -1 * i);
  }
  cin >> m;
  sort((b).begin(), (b).end());
  for (int req = 0; req < m; ++req) {
    cin >> k >> pos;
    vector<pair<int, int>> c;
    for (int i = n - k; i < n; ++i) {
      c.emplace_back(-1 * b[i].second, b[i].first);
    }
    sort((c).begin(), (c).end());
    cout << c[pos - 1].second << '\n';
  }
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Example

Input

2 10 6
4 4 E
6 4 W

Output

2

### Response

```cpp
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <tuple>

using namespace std;
typedef pair<int, int> pii;
static const int INF = 1000000000;

int main(){
	ios_base::sync_with_stdio(false);
	int n, w, h;
	cin >> n >> w >> h;
	vector<pii> ranges;
	for(int i = 0; i < n; ++i){
		int x, y;
		string f;
		cin >> x >> y >> f;
		const int hw2 = h + w + h + w;
		const int lu = y + x;
		const int ru = h + x + (h - y);
		const int rd = h + w + (h - y) + (w - x);
		const int ld = h + w + h + (w - x) + y;
		int lo = 0, hi = 0;
		if(f[0] == 'N'){
			lo = lu; hi = ru;
		}else if(f[0] == 'E'){
			lo = ru; hi = rd;
		}else if(f[0] == 'S'){
			lo = rd; hi = ld;
		}else if(f[0] == 'W'){
			lo = ld; hi = lu + hw2;
		}
		if(lo >= hw2){
			lo -= hw2;
			hi -= hw2;
		}
		ranges.emplace_back(lo, hi);
		ranges.emplace_back(lo + hw2, hi + hw2);
	}
	sort(ranges.begin(), ranges.end());
	int answer = INF;
	for(int i = 0; i < n; ++i){
		const int hw2 = (h + w) * 2;
		vector<pii> r(ranges.begin() + i, ranges.begin() + i + n);
		sort(r.begin(), r.end(), [](const pii &a, const pii &b){
			return (a.second == b.second) ? (a.first < b.first) : (a.second < b.second);
		});
		int count = 1, last = r[0].second;
		for(int j = 0; j < n; ++j){
			if(r[j].first <= last){ continue; }
			if(r[j].second >= r[0].second + hw2){ continue; }
			++count;
			last = r[j].second;
		}
		answer = min(answer, count);
	}
	cout << answer << endl;
	return 0;
}
```


### Prompt

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

Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.

Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by A students, BeaverKing — by B students and C students visited both restaurants. Vasya also knows that there are N students in his group.

Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?

Input

The first line contains four integers — A, B, C and N (0 ≤ A, B, C, N ≤ 100).

Output

If a distribution of N students exists in which A students visited BugDonalds, B — BeaverKing, C — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam.

If such a distribution does not exist and Vasya made a mistake while determining the numbers A, B, C or N (as in samples 2 and 3), output -1.

Examples

Input

10 10 5 20

Output

5

Input

2 2 0 4

Output

-1

Input

2 2 2 1

Output

-1

Note

The first sample describes following situation: 5 only visited BugDonalds, 5 students only visited BeaverKing, 5 visited both of them and 5 students (including Vasya) didn't pass the exam.

In the second sample 2 students only visited BugDonalds and 2 only visited BeaverKing, but that means all 4 students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.

The third sample describes a situation where 2 students visited BugDonalds but the group has only 1 which makes it clearly impossible.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, n;
  cin >> a >> b >> c >> n;
  if ((a + b - c) >= n || a < c || b < c)
    cout << "-1" << endl;
  else
    cout << n - a - b + c << endl;
}

```


### Prompt

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

In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.

Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are ai people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.

Help platform select such an hour, that the number of people who will participate in the contest is maximum.

Input

The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.

The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 10 000), where ai is the number of people in the i-th timezone who want to participate in the contest.

The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).

Output

Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.

Examples

Input

3
1 2 3
1 3

Output

3

Input

5
1 2 3 4 1
1 3

Output

4

Note

In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.

In second example only people from the third and the fourth timezones will participate.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 5;
int a[N], sum[N], n, s, f;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  scanf("%d%d", &s, &f);
  for (int i = n; i < n + n; i++) a[i] = a[i - n];
  for (int i = 0; i < n + n; i++) {
    if (!i)
      sum[i] = a[i];
    else
      sum[i] = sum[i - 1] + a[i];
  }
  int len = f - s;
  int mx = -1, ans = 1;
  int t = s;
  for (int i = 0; i < n; i++) {
    int cnt = i ? sum[i + len - 1] - sum[i - 1] : sum[i + len - 1];
    if (cnt > mx || cnt == mx && t < ans) {
      mx = cnt;
      ans = t;
    }
    t--;
    if (t == 0) t = n;
  }
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

You're given a tree with n vertices. The color of the i-th vertex is h_{i}.

The value of the tree is defined as ∑_{h_{i} = h_{j}, 1 ≤ i < j ≤ n}{dis(i,j)}, where dis(i,j) is the number of edges on the shortest path between i and j.

The color of each vertex is lost, you only remember that h_{i} can be any integer from [l_{i}, r_{i}](inclusive). You want to calculate the sum of values of all trees meeting these conditions modulo 10^9 + 7 (the set of edges is fixed, but each color is unknown, so there are ∏_{i = 1}^{n} (r_{i} - l_{i} + 1) different trees).

Input

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

Then n lines follow, each line contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^5) denoting the range of possible colors of vertex i.

Then n - 1 lines follow, each containing two integers u and v (1 ≤ u, v ≤ n, u ≠ v) denoting an edge of the tree. It is guaranteed that these edges form a tree.

Output

Print one integer — the sum of values of all possible trees, taken modulo 10^9 + 7.

Example

Input

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

Output

22

Note

In the first example there are four different ways to color the tree (so, there are four different trees):

  * a tree with vertices colored as follows: { 1,1,1,1 }. The value of this tree is dis(1,2)+dis(1,3)+dis(1,4)+dis(2,3)+dis(2,4)+dis(3,4) = 10;
  * a tree with vertices colored as follows: { 1,2,1,1 }. The value of this tree is dis(1,3)+dis(1,4)+dis(3,4)=4;
  * a tree with vertices colored as follows: { 1,1,1,2 }. The value of this tree is dis(1,2)+dis(1,3)+dis(2,3)=4;
  * a tree with vertices colored as follows: { 1,2,1,2 }. The value of this tree is dis(1,3)+dis(2,4)=4.

Overall the sum of all values is 10+4+4+4=22.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, ans, gsub, all = 1;
int l[100005], r[100005], sub[100005], inv[100005], c[100005], f[100005],
    F[100005];
vector<int> v[100005];
int mul(int x, int y) { return (long long)x * y % 1000000007; }
int add(int x, int y) {
  x += y;
  if (x >= 1000000007) x -= 1000000007;
  if (x < 0) x += 1000000007;
  return x;
}
int fe(int x, int y) {
  if (y == 0) return 1;
  if (y & 1) return mul(fe(x, y ^ 1), x);
  int res = fe(x, y >> 1);
  return mul(res, res);
}
int get(int x) {
  int res = 0;
  for (int i = x; i >= 1; i -= i & -i) {
    res = add(res, add(c[i], mul(x, F[i])));
  }
  return res;
}
void upf(int x, int val) {
  for (int i = x; i <= (100005 - 5); i += i & -i) F[i] = add(F[i], val);
}
void upc(int x, int val) {
  for (int i = x; i <= (100005 - 5); i += i & -i) c[i] = add(c[i], val);
}
void up(int x, int y, int val) {
  upc(x, mul(x - 1, -val));
  upc(y + 1, mul(y, val));
  upf(x, val);
  upf(y + 1, -val);
}
void dfs2(int node, int dad, int dep, int upv) {
  up(l[node], r[node], mul(dep * upv, inv[node]));
  for (int i : v[node])
    if (!f[i] && i != dad) dfs2(i, node, dep + 1, upv);
}
void dfs1(int node, int dad) {
  ans = add(ans, mul(add(get(r[node]), -get(l[node] - 1)), inv[node]));
  for (int i : v[node])
    if (!f[i] && i != dad) dfs1(i, node);
}
void count(int cnt, int ok) {
  for (int i : v[cnt]) {
    if (!f[i]) dfs1(i, 0), dfs2(i, 0, 1, 1);
  }
  if (ok) ans = add(ans, mul(add(get(r[cnt]), -get(l[cnt] - 1)), inv[cnt]));
  for (int i : v[cnt]) {
    if (!f[i]) dfs2(i, 0, 1, -1);
  }
}
int fcnt(int node, int dad) {
  for (int i : v[node])
    if (!f[i] && i != dad && sub[i] > gsub / 2) return fcnt(i, node);
  return node;
}
void fsubs(int node, int dad) {
  sub[node] = 1;
  for (int i : v[node])
    if (!f[i] && i != dad) fsubs(i, node), sub[node] += sub[i];
}
void solve(int node) {
  fsubs(node, 0);
  gsub = sub[node];
  int cnt = fcnt(node, 0);
  f[cnt] = 1;
  count(cnt, 0);
  reverse(v[cnt].begin(), v[cnt].end());
  count(cnt, 1);
  for (int i : v[cnt]) {
    if (!f[i]) solve(i);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", l + i, r + i);
    inv[i] = fe(r[i] - l[i] + 1, 1000000007 - 2);
    all = mul(all, r[i] - l[i] + 1);
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  solve(1);
  printf("%d", mul(ans, all));
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

n ants are on a circle of length m. An ant travels one unit of distance per one unit of time. Initially, the ant number i is located at the position si and is facing in the direction di (which is either L or R). Positions are numbered in counterclockwise order starting from some point. Positions of the all ants are distinct.

All the ants move simultaneously, and whenever two ants touch, they will both switch their directions. Note that it is possible for an ant to move in some direction for a half of a unit of time and in opposite direction for another half of a unit of time.

Print the positions of the ants after t time units.

Input

The first line contains three integers n, m and t (2 ≤ n ≤ 3·105, 2 ≤ m ≤ 109, 0 ≤ t ≤ 1018) — the number of ants, the length of the circle and the number of time units.

Each of the next n lines contains integer si and symbol di (1 ≤ si ≤ m and di is either L or R) — the position and the direction of the i-th ant at the start. The directions L and R corresponds to the clockwise and counterclockwise directions, respectively.

It is guaranteed that all positions si are distinct.

Output

Print n integers xj — the position of the j-th ant after t units of time. The ants are numbered from 1 to n in order of their appearing in input.

Examples

Input

2 4 8
1 R
3 L

Output

1 3

Input

4 8 6
6 R
5 L
1 R
8 L

Output

7 4 2 7

Input

4 8 2
1 R
5 L
6 L
8 R

Output

3 3 4 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long a = 0, b = getchar(), c = 1;
  while (!isdigit(b)) c = b == '-' ? -1 : 1, b = getchar();
  while (isdigit(b)) a = a * 10 + b - '0', b = getchar();
  return a * c;
}
const int N = 3e5 + 5;
long long n, m, t, a[N], id[N], b[N], ans[N];
bool cmp(int x, int y) { return a[x] < a[y]; }
int main() {
  n = read(), m = read(), t = read();
  for (int i = 0; i < n; i++) {
    a[i] = read() - 1, id[i] = i;
    char ch;
    scanf("%c", &ch);
    b[i] = ch == 'L' ? -1 : 1;
  }
  sort(id, id + n, cmp);
  int x = 0;
  for (int i = 0; i < n; i++) {
    if (b[i] == 1)
      x += (a[i] + t) / m % n;
    else
      x += (a[i] - t - m + 1) / m % n;
    x = (x % n + n) % n;
    a[i] = a[i] + t % m * b[i];
    a[i] = (a[i] % m + m) % m;
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) ans[id[(i + n - x) % n]] = a[i] + 1;
  for (int i = 0; i < n; i++) printf("%lld ", ans[i]);
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.

There are two armies on the playing field each of which consists of n men (n is always even). The current player specifies for each of her soldiers an enemy's soldier he will shoot (a target) and then all the player's soldiers shot simultaneously. This is a game world, and so each soldier shoots perfectly, that is he absolutely always hits the specified target. If an enemy soldier is hit, he will surely die. It may happen that several soldiers had been indicated the same target. Killed soldiers do not participate in the game anymore.

The game "GAGA" consists of three steps: first Valera makes a move, then Arcady, then Valera again and the game ends.

You are asked to calculate the maximum total number of soldiers that may be killed during the game.

Input

The input data consist of a single integer n (2 ≤ n ≤ 108, n is even). Please note that before the game starts there are 2n soldiers on the fields.

Output

Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns.

Examples

Input

2

Output

3

Input

4

Output

6

Note

The first sample test:

1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1.

2) Arcady's soldier 2 shoots at Valera's soldier 1.

3) Valera's soldier 1 shoots at Arcady's soldier 2.

There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int sh = 0, a, f, p = 1, c = 1000000000, k, b = 97, m, i, s1, s2, s3,
              n, q = 0, nl, np, ans = 1000000000, ans1 = -1;
int main() {
  cin >> m;
  cout << m + m / 2;
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Alice and Bob don't play games anymore. Now they study properties of all sorts of graphs together. Alice invented the following task: she takes a complete undirected graph with n vertices, chooses some m edges and keeps them. Bob gets the <image> remaining edges.

Alice and Bob are fond of "triangles" in graphs, that is, cycles of length 3. That's why they wonder: what total number of triangles is there in the two graphs formed by Alice and Bob's edges, correspondingly?

Input

The first line contains two space-separated integers n and m (1 ≤ n ≤ 106, 0 ≤ m ≤ 106) — the number of vertices in the initial complete graph and the number of edges in Alice's graph, correspondingly. Then m lines follow: the i-th line contains two space-separated integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi), — the numbers of the two vertices connected by the i-th edge in Alice's graph. It is guaranteed that Alice's graph contains no multiple edges and self-loops. It is guaranteed that the initial complete graph also contains no multiple edges and self-loops.

Consider the graph vertices to be indexed in some way from 1 to n.

Output

Print a single number — the total number of cycles of length 3 in Alice and Bob's graphs together.

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

Examples

Input

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

Output

3

Input

5 3
1 2
2 3
1 3

Output

4

Note

In the first sample Alice has 2 triangles: (1, 2, 3) and (2, 3, 4). Bob's graph has only 1 triangle : (1, 4, 5). That's why the two graphs in total contain 3 triangles.

In the second sample Alice's graph has only one triangle: (1, 2, 3). Bob's graph has three triangles: (1, 4, 5), (2, 4, 5) and (3, 4, 5). In this case the answer to the problem is 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
set<int> adj[1000100];
long long cnt[1000100];
long long intersection(int x, int y) {
  long long ret = 0;
  set<int>::iterator it;
  if (adj[x].size() > adj[y].size()) {
    swap(x, y);
  }
  for (it = adj[x].begin(); it != adj[x].end(); it++) {
    if (adj[y].find(*it) != adj[y].end()) {
      ret++;
    }
  }
  return ret;
}
int main() {
  long long n, m;
  scanf("%lld %lld", &n, &m);
  long long ans1 = n * (n - 1) * (n - 2) / 6, ans2 = 0;
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    ans1 -= n - 2 - cnt[x] - cnt[y];
    cnt[x]++, cnt[y]++;
  }
  printf("%lld\n", ans1 + ans2);
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Given 2 integers u and v, find the shortest array such that [bitwise-xor](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of its elements is u, and the sum of its elements is v.

Input

The only line contains 2 integers u and v (0 ≤ u,v ≤ 10^{18}).

Output

If there's no array that satisfies the condition, print "-1". Otherwise:

The first line should contain one integer, n, representing the length of the desired array. The next line should contain n positive integers, the array itself. If there are multiple possible answers, print any.

Examples

Input

2 4

Output

2
3 1

Input

1 3

Output

3
1 1 1

Input

8 5

Output

-1

Input

0 0

Output

0

Note

In the first sample, 3⊕ 1 = 2 and 3 + 1 = 4. There is no valid array of smaller length.

Notice that in the fourth sample the array is empty.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long mod = 1e9 + 7;
vector<long long> adj[N];
vector<bool> vis(N);
void dfs(long long x) {
  vis[x] = true;
  for (long long i = 0; i < adj[x].size(); i++) {
    if (!vis[adj[x][i]]) dfs(adj[x][i]);
  }
}
long long d, x, y;
void extendedEuclid(long long A, long long B) {
  if (B == 0) {
    d = A;
    x = 1;
    y = 0;
  } else {
    extendedEuclid(B, A % B);
    long long temp = x;
    x = y;
    y = temp - (A / B) * y;
  }
}
long long modInverse(long long A, long long M) {
  extendedEuclid(A, M);
  return (x % M + M) % M;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long a, b;
  cin >> a >> b;
  if ((abs(a - b)) % 2 == 1 || a > b) {
    cout << -1;
    return 0;
  }
  vector<long long> a1(64, 0), b1(64, 0);
  for (long long i = 0; i < 64; i++) {
    if (a % 2 == 1) a1[i] = 1;
    a /= 2;
  }
  for (long long i = 0; i < 64; i++) {
    if (b % 2 == 1) b1[i] = 1;
    b /= 2;
  }
  long long l = 0;
  for (long long i = 63; i > 0; i--) {
    if (b1[i] % 2 != a1[i]) {
      b1[i - 1] += 2;
      b1[i]--;
    }
  }
  for (long long i = 0; i < 63; i++) {
    if (b1[i] < 0) {
      b1[i] += 4;
      b1[i + 1] -= 2;
    }
  }
  long long num = 0, c1 = 0, c2 = 0, c3 = 0, k = 1;
  for (long long i = 0; i < 64; i++) {
    if (b1[i] == 1) {
      c1 += k;
    } else if (b1[i] == 2) {
      c1 += k;
      c2 += k;
    } else if (b1[i] == 3) {
      c1 += k;
      c2 += k;
      c3 += k;
    }
    k = k << 1;
    num = max(num, b1[i]);
  }
  cout << num << "\n";
  if (c1 > 0) cout << c1 << " ";
  if (c2 > 0) cout << c2 << " ";
  if (c3 > 0) cout << c3 << " ";
  return 0;
}

```


### Prompt

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

The life goes up and down, just like nice sequences. Sequence t1, t2, ..., tn is called nice if the following two conditions are satisfied:

  * ti < ti + 1 for each odd i < n;
  * ti > ti + 1 for each even i < n.

For example, sequences (2, 8), (1, 5, 1) and (2, 5, 1, 100, 99, 120) are nice, while (1, 1), (1, 2, 3) and (2, 5, 3, 2) are not.

Bear Limak has a sequence of positive integers t1, t2, ..., tn. This sequence is not nice now and Limak wants to fix it by a single swap. He is going to choose two indices i < j and swap elements ti and tj in order to get a nice sequence. Count the number of ways to do so. Two ways are considered different if indices of elements chosen for a swap are different.

Input

The first line of the input contains one integer n (2 ≤ n ≤ 150 000) — the length of the sequence.

The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 150 000) — the initial sequence. It's guaranteed that the given sequence is not nice.

Output

Print the number of ways to swap two elements exactly once in order to get a nice sequence.

Examples

Input

5
2 8 4 7 7

Output

2

Input

4
200 150 100 50

Output

1

Input

10
3 2 1 4 1 4 1 4 1 4

Output

8

Input

9
1 2 3 4 5 6 7 8 9

Output

0

Note

In the first sample, there are two ways to get a nice sequence with one swap:

  1. Swap t2 = 8 with t4 = 7.
  2. Swap t1 = 2 with t5 = 7.

In the second sample, there is only one way — Limak should swap t1 = 200 with t4 = 50.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 200000;
vector<int> x, bad, status;
int n;
inline bool is_good(int pos) {
  if (pos % 2) return x[pos] < x[pos - 1] and x[pos] < x[pos + 1];
  return x[pos] > x[pos - 1] and x[pos] > x[pos + 1];
}
int sum = 0;
inline void update(int pos) {
  if (pos <= 0 or pos > n) return;
  sum -= status[pos];
  status[pos] = is_good(pos);
  sum += status[pos];
}
int main() {
  cin >> n;
  status = vector<int>(n + 5, 0);
  x.push_back(inf);
  set<pair<int, int> > ans;
  for (int i = 0; i < n; i++) {
    int tmp;
    scanf("%d", &tmp);
    x.push_back(tmp);
  }
  if (n % 2)
    x.push_back(inf);
  else
    x.push_back(0);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (is_good(i))
      sum++, status[i] = 1;
    else
      bad.push_back(i);
  }
  cerr << "sum" << '=' << sum << endl;
  if (bad.size() > 9) return printf("0\n"), 0;
  for (auto i : bad) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      swap(x[i], x[j]);
      update(i);
      update(i - 1);
      update(i + 1);
      update(j);
      update(j - 1);
      update(j + 1);
      if (sum == n) {
        ans.insert(make_pair(min(i, j), max(i, j)));
      }
      swap(x[i], x[j]);
      update(i);
      update(i - 1);
      update(i + 1);
      update(j);
      update(j - 1);
      update(j + 1);
    }
  }
  cout << ans.size() << endl;
}

```


### Prompt

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

There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.

Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.

You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.

Input

The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.

The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.

The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.

Each of the next q lines contains a single event. The events are given in chronological order.

Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.

Output

Print n integers — the balances of all citizens after all events.

Examples

Input

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

Output

3 2 3 4

Input

5
3 50 2 1 10
3
1 2 0
2 8
1 3 20

Output

8 8 20 8 10

Note

In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4

In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10

### Response

```cpp
#include <bits/stdc++.h>
namespace kyel {
const int maxn(212345);
int n, q, val[maxn], rank[maxn];
int change[maxn], cr[maxn], end;
int find(int v) {
  int left(0), right(end - 1), ret(-1);
  while (left <= right) {
    int mid(left + right >> 1);
    if (cr[mid] > v)
      right = mid - 1, ret = mid;
    else
      left = mid + 1;
  }
  return ret;
}
void kyel() {
  scanf("%d", &n);
  for (int i(1); i <= n; ++i) scanf("%d", val + i);
  scanf("%d", &q);
  for (int i(1); i <= q; ++i) {
    int cmd, x, y;
    scanf("%d%d", &cmd, &x);
    if (cmd == 1) {
      scanf("%d", &y);
      val[x] = y, rank[x] = i;
    } else {
      while (end && change[end - 1] <= x) --end;
      change[end] = x, cr[end++] = i;
    }
  }
  for (int i(1); i <= n; ++i) {
    int pos(find(rank[i]));
    if (~pos && change[pos] > val[i]) val[i] = change[pos];
    printf("%d", val[i]);
    if (i != n) printf(" ");
  }
  printf("\n");
}
}  // namespace kyel
int main() {
  kyel::kyel();
  return 0;
}

```


### Prompt

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

Consider an analog clock whose hour and minute hands are A and B centimeters long, respectively.

An endpoint of the hour hand and an endpoint of the minute hand are fixed at the same point, around which each hand rotates clockwise at constant angular velocity. It takes the hour and minute hands 12 hours and 1 hour to make one full rotation, respectively.

At 0 o'clock, the two hands overlap each other. H hours and M minutes later, what is the distance in centimeters between the unfixed endpoints of the hands?

Constraints

* All values in input are integers.
* 1 \leq A, B \leq 1000
* 0 \leq H \leq 11
* 0 \leq M \leq 59

Input

Input is given from Standard Input in the following format:

A B H M

Output

Print the answer without units. Your output will be accepted when its absolute or relative error from the correct value is at most 10^{-9}.

Examples

Input

3 4 9 0

Output

5.00000000000000000000

Input

3 4 10 40

Output

4.56425719433005567605

### Response

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

int main() {
  int a, b, h, m;
  double ang;

  cin >> a >> b >> h >> m;

  ang = 2 * M_PI * ((m / 60.0 + h) / 12.0 - m / 60.0);

  printf("%.15f\n", sqrt(pow(a, 2) + pow(b, 2) - (2.0 * a * b * cos(ang))));
}
```