### Prompt

Construct a Cpp code solution to the problem outlined:

Piglet has got a birthday today. His friend Winnie the Pooh wants to make the best present for him — a honey pot. Of course Winnie realizes that he won't manage to get the full pot to Piglet. In fact, he is likely to eat all the honey from the pot. And as soon as Winnie planned a snack on is way, the pot should initially have as much honey as possible.

The day before Winnie the Pooh replenished his honey stocks. Winnie-the-Pooh has n shelves at home, each shelf contains some, perhaps zero number of honey pots. During the day Winnie came to the honey shelves q times; on the i-th time he came to some shelf ui, took from it some pots ki, tasted the honey from each pot and put all those pots on some shelf vi. As Winnie chose the pots, he followed his intuition. And that means that among all sets of ki pots on shelf ui, he equiprobably chooses one.

Now Winnie remembers all actions he performed with the honey pots. He wants to take to the party the pot he didn't try the day before. For that he must know the mathematical expectation of the number m of shelves that don't have a single untasted pot. To evaluate his chances better, Winnie-the-Pooh wants to know the value m after each action he performs.

Your task is to write a program that will find those values for him.

Input

The first line of the input contains a single number n (1 ≤ n ≤ 105) — the number of shelves at Winnie's place. The second line contains n integers ai (1 ≤ i ≤ n, 0 ≤ ai ≤ 100) — the number of honey pots on a shelf number i.

The next line contains integer q (1 ≤ q ≤ 105) — the number of actions Winnie did the day before. Then follow q lines, the i-th of them describes an event that follows chronologically; the line contains three integers ui, vi and ki (1 ≤ ui, vi ≤ n, 1 ≤ ki ≤ 5) — the number of the shelf from which Winnie took pots, the number of the shelf on which Winnie put the pots after he tasted each of them, and the number of the pots Winnie tasted, correspondingly.

Consider the shelves with pots numbered with integers from 1 to n. It is guaranteed that Winnie-the-Pooh Never tried taking more pots from the shelf than it has.

Output

For each Winnie's action print the value of the mathematical expectation m by the moment when this action is performed. The relative or absolute error of each value mustn't exceed 10 - 9.

Examples

Input

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

Output

0.000000000000
0.333333333333
1.000000000000
1.000000000000
2.000000000000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1, M = 102;
int n, a[N], c[N], q, u, v, k;
double A, f[N][M];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) c[i] = a[i], f[i][a[i]] = 1, A += f[i][0];
  cin >> q;
  while (q-- && cin >> u >> v >> k) {
    A -= f[u][0];
    for (int i = 1; i <= k; i++) {
      for (int j = 0; j <= c[u]; j++)
        f[u][j] = f[u][j] * (a[u] - j) / a[u] + f[u][j + 1] * (j + 1) / a[u];
      a[u]--;
    }
    A += f[u][0], a[v] += k;
    printf("%.9lf\n", A);
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

You are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K. The order of a,b,c does matter, and some of them can be the same.

Constraints

* 1 \leq N,K \leq 2\times 10^5
* N and K are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.

Examples

Input

3 2

Output

9

Input

5 3

Output

1

Input

31415 9265

Output

27

Input

35897 932

Output

114191

### Response

```cpp
#include <bits/stdc++.h>
using ll = long long;
int main()
{
  int N, K;
  std::cin >> N >> K;
  auto cb = [](const ll n){return n*n*n;};
  std::cout << (K%2==1?cb(N/K):cb(N/K)+cb((N+K/2)/K)) << std::endl;
  return 0;
}
```


### Prompt

Create a solution in CPP for the following problem:

Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. However, in order not to lose face in front of the relatives, the King should first finish reforms in his kingdom. As the King can not wait for his daughter's marriage, reforms must be finished as soon as possible.

The kingdom currently consists of n cities. Cities are connected by n - 1 bidirectional road, such that one can get from any city to any other city. As the King had to save a lot, there is only one path between any two cities.

What is the point of the reform? The key ministries of the state should be relocated to distinct cities (we call such cities important). However, due to the fact that there is a high risk of an attack by barbarians it must be done carefully. The King has made several plans, each of which is described by a set of important cities, and now wonders what is the best plan.

Barbarians can capture some of the cities that are not important (the important ones will have enough protection for sure), after that the captured city becomes impassable. In particular, an interesting feature of the plan is the minimum number of cities that the barbarians need to capture in order to make all the important cities isolated, that is, from all important cities it would be impossible to reach any other important city.

Help the King to calculate this characteristic for each of his plan.

Input

The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cities in the kingdom.

Each of the next n - 1 lines contains two distinct integers ui, vi (1 ≤ ui, vi ≤ n) — the indices of the cities connected by the i-th road. It is guaranteed that you can get from any city to any other one moving only along the existing roads.

The next line contains a single integer q (1 ≤ q ≤ 100 000) — the number of King's plans.

Each of the next q lines looks as follows: first goes number ki — the number of important cities in the King's plan, (1 ≤ ki ≤ n), then follow exactly ki space-separated pairwise distinct numbers from 1 to n — the numbers of important cities in this plan.

The sum of all ki's does't exceed 100 000.

Output

For each plan print a single integer — the minimum number of cities that the barbarians need to capture, or print  - 1 if all the barbarians' attempts to isolate important cities will not be effective.

Examples

Input

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

Output

1
-1
1
-1

Input

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

Output

2

Note

In the first sample, in the first and the third King's plan barbarians can capture the city 3, and that will be enough. In the second and the fourth plans all their attempts will not be effective.

In the second sample the cities to capture are 3 and 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read() {
  T x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const int N = 100010, INF = 0x3f3f3f3f;
int n, q, k, key[N];
struct Edge {
  int to, nxt;
};
struct Graph {
  int head[N], tot;
  Edge e[N << 1];
  void addedge(int x, int y) {
    e[++tot] = (Edge){y, head[x]};
    head[x] = tot;
  }
};
struct Tree : public Graph {
  int dfn[N], ti, f[N][19], dep[N];
  void dfs(int x, int fa) {
    dfn[x] = ++ti;
    f[x][0] = fa;
    dep[x] = dep[fa] + 1;
    for (int i = 1; i <= 18; i++) f[x][i] = f[f[x][i - 1]][i - 1];
    for (int i = head[x]; i; i = e[i].nxt) {
      int y = e[i].to;
      if (y == fa) continue;
      dfs(y, x);
    }
  }
  int lca(int x, int y) {
    if (dep[x] < dep[y]) swap(x, y);
    for (int i = 18; i >= 0; i--) {
      if (dep[f[x][i]] >= dep[y]) x = f[x][i];
    }
    if (x == y) return x;
    for (int i = 18; i >= 0; i--) {
      if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
    }
    return f[x][0];
  }
} t;
struct Virtual_Tree : public Graph {
  int dp[N][2], d[N], st[N], tp;
  void build_vtree(Tree& t, int* key, int cnt) {
    memcpy(d, key, sizeof(int) * (cnt + 1));
    sort(d + 1, d + cnt + 1, [&](int x, int y) { return t.dfn[x] < t.dfn[y]; });
    head[1] = 0, tot = 0;
    st[tp = 1] = 1;
    for (int i = 1; i <= cnt; i++) {
      if (d[i] == 1) continue;
      int lc = t.lca(d[i], st[tp]);
      if (lc != st[tp]) {
        while (t.dfn[lc] < t.dfn[st[tp - 1]]) {
          addedge(st[tp - 1], st[tp]);
          tp--;
        }
        if (t.dfn[lc] != t.dfn[st[tp - 1]]) {
          head[lc] = 0, addedge(lc, st[tp]);
          st[tp] = lc;
        } else
          addedge(lc, st[tp]), tp--;
      }
      head[d[i]] = 0, st[++tp] = d[i];
    }
    for (int i = 1; i < tp; i++) addedge(st[i], st[i + 1]);
  }
  void dfs_dp(int, int);
} vt;
int iskey[N];
void Virtual_Tree::dfs_dp(int x, int fa) {
  dp[x][0] = (!iskey[x]) * n, dp[x][1] = iskey[x] * n;
  int minx = INF, sum = 1, cnt = 0;
  for (int i = head[x]; i; i = e[i].nxt) {
    int y = e[i].to;
    if (y == fa) continue;
    cnt += iskey[y];
    dfs_dp(y, x);
    if (iskey[x])
      dp[x][0] += min(dp[y][1], dp[y][0] + 1);
    else {
      minx = min(minx, dp[y][0] - dp[y][1]);
      sum += min(dp[y][0], dp[y][1]);
      dp[x][1] += dp[y][1];
    }
  }
  if (!iskey[x] && cnt <= 1) dp[x][0] = dp[x][1] + minx;
  if (!iskey[x]) dp[x][1] = min(dp[x][1], sum);
}
void solve() {
  k = read<int>();
  for (int i = 1; i <= k; i++) iskey[key[i] = read<int>()] = 1;
  for (int i = 1; i <= k; i++) {
    int x = key[i];
    if (iskey[t.f[x][0]]) {
      for (int j = 1; j <= k; j++) iskey[key[j]] = 0;
      puts("-1");
      return;
    }
  }
  vt.build_vtree(t, key, k);
  vt.dfs_dp(1, 0);
  printf("%d\n", min(vt.dp[1][0], vt.dp[1][1]));
  for (int j = 1; j <= k; j++) iskey[key[j]] = 0;
}
int main() {
  n = read<int>();
  for (int i = 1; i < n; i++) {
    int x = read<int>(), y = read<int>();
    t.addedge(x, y);
    t.addedge(y, x);
  }
  t.dfs(1, 0);
  q = read<int>();
  while (q--) solve();
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money.

Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance.

Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.

Input

The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account.

Output

In a single line print an integer — the maximum state of the bank account that Ilya can get.

Examples

Input

2230

Output

2230

Input

-10

Output

0

Input

-100003

Output

-10000

Note

In the first test sample Ilya doesn't profit from using the present.

In the second test sample you can delete digit 1 and get the state of the account equal to 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, k;
  cin >> n;
  if (n >= 0)
    cout << n;
  else {
    k = n / 10;
    m = n % 10;
    n = n / 100;
    n = (n * 10) + m;
    if (k >= n)
      cout << k;
    else
      cout << n;
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

You're given a tree with n vertices.

Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size.

Input

The first line contains an integer n (1 ≤ n ≤ 10^5) denoting the size of the tree.

The next n - 1 lines contain two integers u, v (1 ≤ u, v ≤ n) each, describing the vertices connected by the i-th edge.

It's guaranteed that the given edges form a tree.

Output

Output a single integer k — the maximum number of edges that can be removed to leave all connected components with even size, or -1 if it is impossible to remove edges in order to satisfy this property.

Examples

Input

4
2 4
4 1
3 1

Output

1

Input

3
1 2
1 3

Output

-1

Input

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

Output

4

Input

2
1 2

Output

0

Note

In the first example you can remove the edge between vertices 1 and 4. The graph after that will have two connected components with two vertices in each.

In the second example you can't remove edges in such a way that all components have even number of vertices, so the answer is -1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 15;
int N;
struct Edge {
  int to, next;
  Edge() {}
  Edge(int to, int next) : to(to), next(next) {}
} E[maxn * 2];
int head[maxn], tot;
void initEdge() {
  for (int i = 1; i <= N; i++) head[i] = -1;
  tot = 0;
}
void addEdge(int u, int v) {
  E[tot] = Edge(v, head[u]);
  head[u] = tot++;
}
int Count = 0;
int DFS(int u, int fa) {
  int si = 1;
  for (int k = head[u]; ~k; k = E[k].next) {
    int v = E[k].to;
    if (v == fa) continue;
    int num = DFS(v, u);
    if (num)
      si ^= 1;
    else
      Count++;
  }
  return si;
}
int main() {
  scanf("%d", &N);
  int u, v;
  if (N % 2) {
    for (int i = 1; i <= N - 1; i++) scanf("%d %d", &u, &v);
    printf("-1\n");
  } else {
    initEdge();
    for (int i = 1; i <= N - 1; i++) {
      scanf("%d %d", &u, &v);
      addEdge(u, v);
      addEdge(v, u);
    }
    DFS(1, 0);
    printf("%d\n", Count);
  }
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence of characters to print, using the following method.

The integers of the array are processed one by one, starting from the first. Processing i-th element of the array is done in three steps:

1. The 8-bit binary notation of the ASCII-code of the previous printed character is reversed. When the first element of the array is processed, the result of this step is considered to be 0.

2. The i-th element of the array is subtracted from the result of the previous step modulo 256.

3. The binary notation of the result of the previous step is reversed again to produce ASCII-code of the i-th character to be printed.

You are given the text printed using this method. Restore the array used to produce this text.

Input

The input will consist of a single line text which contains the message printed using the described method. String text will contain between 1 and 100 characters, inclusive. ASCII-code of each character of text will be between 32 (space) and 126 (tilde), inclusive.

Output

Output the initial array, which was used to produce text, one integer per line.

Examples

Input

Hello, World!

Output

238
108
112
0
64
194
48
26
244
168
24
16
162

Note

Let's have a closer look at the beginning of the example. The first character is "H" with ASCII-code 72 = 010010002. Its reverse is 000100102 = 18, and this number should become the result of the second step of processing. The result of the first step is considered to be 0, so the first element of the array has to be (0 - 18) mod 256 = 238, where a mod b is the remainder of division of a by b.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int rev(int x) {
  int t = 0;
  for (int i = 0; i < (8); ++i)
    if (x & (1 << (i)))
      t = (t << 1) | 1;
    else
      t = (t << 1) | 0;
  return t;
}
int gao(int x, int y) {
  int a = rev(y);
  int b = (x - a) % 256;
  b = (b + 256) % 256;
  return b;
}
int main() {
  string text;
  getline(cin, text);
  for (int i = 0; i < (((int)text.size())); ++i) {
    int p = 0;
    if (i > 0) p = text[i - 1];
    int x = gao(rev(p), text[i]);
    printf("%d\n", x);
  }
  return 0;
}

```


### Prompt

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

Opposite to Grisha's nice behavior, Oleg, though he has an entire year at his disposal, didn't manage to learn how to solve number theory problems in the past year. That's why instead of Ded Moroz he was visited by his teammate Andrew, who solemnly presented him with a set of n distinct prime numbers alongside with a simple task: Oleg is to find the k-th smallest integer, such that all its prime divisors are in this set.

Input

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

The next line lists n distinct prime numbers p1, p2, ..., pn (2 ≤ pi ≤ 100) in ascending order.

The last line gives a single integer k (1 ≤ k). It is guaranteed that the k-th smallest integer such that all its prime divisors are in this set does not exceed 1018.

Output

Print a single line featuring the k-th smallest integer. It's guaranteed that the answer doesn't exceed 1018.

Examples

Input

3
2 3 5
7

Output

8

Input

5
3 7 11 13 31
17

Output

93

Note

The list of numbers with all prime divisors inside {2, 3, 5} begins as follows:

(1, 2, 3, 4, 5, 6, 8, ...)

The seventh number in this list (1-indexed) is eight.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const ll inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-7;
int a[17], n;
ll k;
ll cnt(ll x, int pos = 1, ll y = 1) {
  ll res = 0;
  if (y <= x / a[pos]) res += cnt(x, pos, y * a[pos]);
  if (pos + 1 <= n)
    res += cnt(x, pos + 1, y);
  else
    res++;
  return min(res, k);
}
vector<ll> cur, FIRST, SECOND, W, Q;
void go(ll x, int pos, int END, ll y = 1) {
  if (y <= x / a[pos]) go(x, pos, END, y * a[pos]);
  if (pos + 1 <= END)
    go(x, pos + 1, END, y);
  else
    cur.push_back(y);
}
ll FIND(ll x) {
  if (n <= 6) {
    return cnt(x);
  }
  Q.clear(), W.clear();
  for (auto i : FIRST) {
    if (i <= x) {
      Q.push_back(i);
    }
  }
  for (auto i : SECOND) {
    if (i <= x) {
      W.push_back(i);
    }
  }
  ll res = 0;
  for (ll y : W) {
    if (res >= k) res = k;
    if (res >= k) return k;
    res += upper_bound(Q.begin(), Q.end(), x / y) - Q.begin();
  }
  return res;
}
void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  cin >> k;
  if (n > 6) {
    cur.clear();
    go(INF, 1, 5);
    sort(cur.begin(), cur.end());
    FIRST = cur;
    cur.clear();
    go(INF, 6, n);
    sort(cur.begin(), cur.end());
    SECOND = cur;
  }
  ll l = 1, r = INF, ans = 0;
  while (l <= r) {
    ll m = l + (r - l) / 2;
    if (FIND(m) >= k) {
      r = m - 1;
      ans = m;
    } else {
      l = m + 1;
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  int tt = 1;
  while (tt--) {
    solve();
    cout << "\n";
  }
}

```


### Prompt

Please create a solution in CPP to the following problem:

There is a plan view consisting of 12 vertical and 12 horizontal squares showing the terrain. Each square is painted white or black. White represents the sea and black represents the land. When two black squares touch each other vertically or horizontally, they are said to be continuous. In this plan view, the area created by only one black square or a continuous black square is called an "island". For example, in the figure below, there are five islands.

■■■■ □□□□ ■■■■
■■■ □□□□□ ■■■■
■■ □□□□□□ ■■■■
■ □□□□□□□ ■■■■
□□□ ■ □□□ ■ □□□□
□□□□□□ ■■■ □□□
□□□□□ ■■■■■ □□
■ □□□ ■■■■■■■ □
■■ □□□ ■■■■■ □□
■■■ □□□ ■■■ □□□
■■■■ □□□ ■ □□□□
□□□□□□□□□□□□

Create a program that reads the mass data and outputs the number of islands.

Hint

The following shows the sample inputs with ■ and □.

■■■■ □□□□ ■■■■ □ ■ □□□ ■■■■■ □□ □□□□□□□□□□□□
■■■ □□□□□ ■■■■ ■■ □□ ■ □□□□□ ■ □ ■■■■■■■■■■■■
■■ □□□□□□ ■■■■ □ ■ □□ ■ □□□□□□ ■ ■ □□□ ■ □ ■ □□□□ ■
■ □□□□□□□ ■■■■ □ ■ □□□□□□□□□ ■ ■ □□□ ■ □ ■ □□□□ ■
□□□ ■ □□□ ■ □□□□ □ ■ □□□□□□□ ■■ □ ■ □□□ ■ □ ■ □□□□ ■
□□□□□□ ■■■ □□□ □ ■ □□□□ ■■■ □□□ ■ □□□ ■ □ ■ □□□□ ■
□□□□□ ■■■■■ □□ □ ■ □□□□□□□ ■ □□ ■ □□ ■ □□ ■ □□ ■ □ ■
■ □□□ ■■■■■■■ □ □ ■ □□□□□□□□ ■ □ ■ □ ■ □□□□ ■■■ □ ■
■■ □□□ ■■■■■ □□ □ ■ □□□□□□□□□ ■ ■ □□□□□□□□□□ ■
■■■ □□□ ■■■ □□□ □ ■ □□ ■ □□□□□□ ■ ■ □□□□□□□□□□ ■
■■■■ □□□ ■ □□□□ □ ■ □□ ■ □□□□□ ■ □ ■■■■■■■■■■■■
□□□□□□□□□□□□ ■■■ □□ ■■■■■ □□ ■ □□□□□□□□□□ ■

Input

The input consists of multiple datasets. One plan view is given for each dataset. A plan view is represented by 12 rows of 12 number columns, with black squares represented by 1 and white squares represented by 0. The datasets are separated by a single blank line.

The number of datasets does not exceed 20.

Output

Outputs the number of islands on one line for each dataset.

Example

Input

111100001111
111000001111
110000001111
100000001111
000100010000
000000111000
000001111100
100011111110
110001111100
111000111000
111100010000
000000000000

010001111100
110010000010
010010000001
010000000001
010000000110
010000111000
010000000100
010000000010
010000000001
010010000001
010010000010
111001111100

000000000000
111111111111
100010100001
100010100001
100010100001
100010100001
100100100101
101000011101
100000000001
100000000001
111111111111
100000000001

Output

5
13
4

### Response

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

char ss[12][12];

void dfs(int x, int y) {
  if (x < 0 || y < 0 || x >= 12 || y >= 12 || ss[y][x] == '0')
    return;
  ss[y][x] = '0';
  dfs(x + 1, y);
  dfs(x - 1, y);
  dfs(x, y + 1);
  dfs(x, y - 1);
}
int main() {
  int n, ans = 0;
  while (cin >> ss[0][0]) {
    ans = 0;
    rep(i, 12) rep(j, 12) {
      if (i == 0 && j == 0)
        ;
      else
        cin >> ss[i][j];
    }
    rep(i, 12) rep(j, 12) {
      if (ss[i][j] == '1') {
        ans++;
        dfs(j, i);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
```


### Prompt

Please formulate a Cpp solution to the following problem:

Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0, 1]. Next, n stones will fall and Liss will escape from the stones. The stones are numbered from 1 to n in order.

The stones always fall to the center of Liss's interval. When Liss occupies the interval [k - d, k + d] and a stone falls to k, she will escape to the left or to the right. If she escapes to the left, her new interval will be [k - d, k]. If she escapes to the right, her new interval will be [k, k + d].

You are given a string s of length n. If the i-th character of s is "l" or "r", when the i-th stone falls Liss will escape to the left or to the right, respectively. Find the sequence of stones' numbers from left to right after all the n stones falls.

Input

The input consists of only one line. The only line contains the string s (1 ≤ |s| ≤ 106). Each character in s will be either "l" or "r".

Output

Output n lines — on the i-th line you should print the i-th stone's number from the left.

Examples

Input

llrlr

Output

3
5
4
2
1

Input

rrlll

Output

1
2
5
4
3

Input

lrlrr

Output

2
4
5
3
1

Note

In the first example, the positions of stones 1, 2, 3, 4, 5 will be <image>, respectively. So you should print the sequence: 3, 5, 4, 2, 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char g[1000002];
int main() {
  int i = 0;
  scanf("%s", g);
  for (; g[i] != '\0'; i++) g[i] == 'r' ? printf("%d ", i + 1) : 0;
  for (i--; i >= 0; i--) g[i] == 'l' ? printf("%d ", i + 1) : 0;
  return 0;
}

```


### Prompt

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

A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.

Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation.

Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom.

<image>

You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously.

Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.

Note one milliliter equals to one cubic centimeter.

Input

The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where:

  * d — the diameter of your cylindrical cup,
  * h — the initial level of water in the cup,
  * v — the speed of drinking process from the cup in milliliters per second,
  * e — the growth of water because of rain if you do not drink from the cup.

Output

If it is impossible to make the cup empty, print "NO" (without quotes).

Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.

Examples

Input

1 2 3 100

Output

NO

Input

1 1 1 1

Output

YES
3.659792366325

Note

In the first example the water fills the cup faster than you can drink from it.

In the second example area of the cup's bottom equals to <image>, thus we can conclude that you decrease the level of water by <image> centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in <image> seconds.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979;
int main() {
  cout.precision(13);
  int d, h, v, e;
  scanf("%d %d %d %d", &d, &h, &v, &e);
  double vi = PI * (d * d / 4.0) * h;
  double fl = v - PI * (d * d / 4.0) * e;
  if (fl <= 0) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  cout << vi / fl;
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

problem

Five students, Taro, Jiro, Saburo, Shiro, and Hanako, participated in the JOI High School class.

In this class, a final exam was conducted. All five people took the final exam. For students with a final exam score of 40 or higher, the final exam score was used as is. All students with a final exam score of less than 40 received supplementary lessons and scored 40 points.

Create a program that calculates the average score of the five students' grades given the final exam scores of the five students.

Example

Input

10
65
100
30
95

Output

68

### Response

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

using namespace std;

int main(void){

  int ans=0,a;

  for(int i=0;i<5;i++){
    cin >> a;
    ans+=max(40,a);
  }

  cout << ans/5 << endl;

  return 0;
}
```


### Prompt

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

You can perfectly predict the price of a certain stock for the next N days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. Initially you own zero shares, and you cannot sell shares when you don't own any. At the end of the N days you would like to again own zero shares, but want to have as much money as possible.

Input

Input begins with an integer N (2 ≤ N ≤ 3·105), the number of days.

Following this is a line with exactly N integers p1, p2, ..., pN (1 ≤ pi ≤ 106). The price of one share of stock on the i-th day is given by pi.

Output

Print the maximum amount of money you can end up with at the end of N days.

Examples

Input

9
10 5 4 7 9 12 6 2 10

Output

20

Input

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

Output

41

Note

In the first example, buy a share at 5, buy another at 4, sell one at 9 and another at 12. Then buy at 2 and sell at 10. The total profit is  - 5 - 4 + 9 + 12 - 2 + 10 = 20.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  multiset<int> ms;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    long long num;
    cin >> num;
    if (!ms.empty() && *ms.begin() < num) {
      auto it = ms.begin();
      ans = ans + num - *it;
      ms.erase(it);
      ms.insert(num);
      ms.insert(num);
    } else {
      ms.insert(num);
    }
  }
  cout << ans;
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

The little girl loves the problems on array queries very much.

One day she came across a rather well-known problem: you've got an array of n elements (the elements of the array are indexed starting from 1); also, there are q queries, each one is defined by a pair of integers l_i, r_i (1 ≤ l_i ≤ r_i ≤ n). You need to find for each query the sum of elements of the array with indexes from l_i to r_i, inclusive.

The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.

Input

The first line contains two space-separated integers n (1 ≤ n ≤ 2⋅10^5) and q (1 ≤ q ≤ 2⋅10^5) — the number of elements in the array and the number of queries, correspondingly.

The next line contains n space-separated integers a_i (1 ≤ a_i ≤ 2⋅10^5) — the array elements.

Each of the following q lines contains two space-separated integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — the i-th query.

Output

In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered.

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

Examples

Input

3 3
5 3 2
1 2
2 3
1 3

Output

25

Input

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

Output

33

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long double E = 2.71828182845904523536;
const long double pi = acos(-1);
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const long long oo = 1LL << 30;
void out(long long a[], long long n) {
  for (int i = 0; i <= n + 5; i++) cout << a[i] << "  ";
  cout << "\n";
}
void out(vector<long long> v) {
  for (auto a : v) cout << a << "  ";
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  auto start = chrono::steady_clock::now();
  long long n, q, x, y, ans = 0;
  cin >> n >> q;
  vector<long long> v(n, 0), u(n + 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  while (q--) {
    cin >> x >> y;
    u[x - 1] += 1;
    u[y] -= 1;
  }
  for (int i = 1; i < n; i++) {
    u[i] += u[i - 1];
  }
  sort(v.begin(), v.end());
  sort(u.begin(), u.end() - 1);
  for (int i = 0; i < n; i++) {
    ans += v[i] * u[i];
  }
  cout << ans << "\n";
  auto end = chrono::steady_clock::now();
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Artsem is on vacation and wants to buy souvenirs for his two teammates. There are n souvenir shops along the street. In i-th shop Artsem can buy one souvenir for ai dollars, and he cannot buy more than one souvenir in one shop. He doesn't want to introduce envy in his team, so he wants to buy two souvenirs with least possible difference in price.

Artsem has visited the shopping street m times. For some strange reason on the i-th day only shops with numbers from li to ri were operating (weird? yes it is, but have you ever tried to come up with a reasonable legend for a range query problem?). For each visit, Artsem wants to know the minimum possible difference in prices of two different souvenirs he can buy in the opened shops.

In other words, for each Artsem's visit you should find the minimum possible value of |as - at| where li ≤ s, t ≤ ri, s ≠ t.

Input

The first line contains an integer n (2 ≤ n ≤ 105).

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

The third line contains the number of queries m (1 ≤ m ≤ 3·105).

Next m lines describe the queries. i-th of these lines contains two space-separated integers li and ri denoting the range of shops working on i-th day (1 ≤ li < ri ≤ n).

Output

Print the answer to each query in a separate line.

Example

Input

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

Output

0
1
1
3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int read() {
  char c = getchar();
  long long x = 1, s = 0;
  while (c < '0' || c > '9') {
    if (c == '-') x = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    s = s * 10 + c - '0';
    c = getchar();
  }
  return s * x;
}
const int N = 3e5 + 5;
int n, m, a[N], l, r, ans[N], minn[N * 4];
vector<int> s[N];
vector<pair<int, int> > q[N];
void build(int u, int l, int r) {
  for (int i = l; i <= r; i++) s[u].push_back(a[i]);
  sort(s[u].begin(), s[u].end());
  minn[u] = 2e9 + 7;
  if (l == r) return;
  build((u << 1), l, ((l + r) >> 1));
  build((u << 1 | 1), ((l + r) >> 1) + 1, r);
}
int maxx = 0, ne;
void modify(int u, int l, int r, int x) {
  int tmp = 2e9 + 7;
  int pre = upper_bound(s[u].begin(), s[u].end(), ne) - s[u].begin() - 1;
  int prv = upper_bound(s[u].begin(), s[u].end(), ne) - s[u].begin();
  if (pre >= 0) tmp = min(tmp, abs(ne - s[u][pre]));
  if (prv != s[u].size()) tmp = min(tmp, abs(ne - s[u][prv]));
  if (tmp >= maxx) return;
  if (l == r) {
    minn[u] = min(minn[u], abs(a[l] - ne));
    maxx = min(maxx, minn[u]);
    return;
  }
  if (x > ((l + r) >> 1)) modify((u << 1 | 1), ((l + r) >> 1) + 1, r, x);
  maxx = min(maxx, minn[(u << 1 | 1)]);
  modify((u << 1), l, ((l + r) >> 1), x);
  minn[u] = min(minn[(u << 1)], minn[(u << 1 | 1)]);
}
int query(int u, int l, int r, int L, int R) {
  if (L <= l and R >= r) {
    return minn[u];
  }
  int maa = 2e9 + 7;
  if (L <= ((l + r) >> 1))
    maa = min(maa, query((u << 1), l, ((l + r) >> 1), L, R));
  if (R > ((l + r) >> 1))
    maa = min(maa, query((u << 1 | 1), ((l + r) >> 1) + 1, r, L, R));
  return maa;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  build(1, 1, n);
  m = read();
  for (int i = 1; i <= m; i++) {
    l = read();
    r = read();
    q[r].push_back(make_pair(l, i));
  }
  for (int i = 2; i <= n; i++) {
    maxx = 2e9 + 7;
    ne = a[i];
    modify(1, 1, n, i - 1);
    for (int k = 0; k < q[i].size(); k++) {
      ans[q[i][k].second] = query(1, 1, n, q[i][k].first, i - 1);
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}

```


### Prompt

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

With the motto "Creating your own path," a shrine created a fortune-telling fortune with its own hands. Ask the person who draws the lottery to throw six stones first, then the line segment connecting the first and second of the thrown stones, the line segment connecting the third and fourth, the fifth and six The fortune is determined from the area of the triangle whose apex is the intersection of the three line segments connecting the second line segment. The relationship between each fortune and the area of the triangle is as follows.

Area of a triangle whose apex is the intersection of line segments | Fortune
--- | ---
Over 1,900,000 | Daikichi
1,000,000 or more and less than 1,900,000 | Nakayoshi (chu-kichi)
100,000 or more and less than 1,000,000 | Kichi
Greater than 0 and less than 100,000 | Kokichi (syo-kichi)
No triangle | Kyo

However, the size of the area of the triangle is determined by the priest by hand, so it cannot be said to be accurate and it takes time. So, as an excellent programmer living in the neighborhood, you decided to write a program as soon as possible to help the priest.

Create a program that takes the information of three line segments as input and outputs the fortune from the area of the triangle whose vertices are the intersections of the line segments. The line segment information is given the coordinates of the start point (x1, y1) and the coordinates of the end point (x2, y2), and the coordinates of the start point and the end point must be different. Also, if two or more line segments are on the same straight line, if there are two line segments that do not have intersections, or if three line segments intersect at one point, it is "no triangle".

<image>

Input

A sequence of multiple datasets is given as input. The end of the input is indicated by four zero lines. Each dataset is given in the following format:

line1
line2
line3

The i-th line is given the information of the i-th line segment. Information for each line is given in the following format.

x1 y1 x2 y2

Integers (x1, y1), (x2, y2) (-1000 ≤ x1, y1, x2, y2 ≤ 1000) representing the coordinates of the endpoints of the line segment are given, separated by blanks.

Output

The result of the fortune telling is output to one line for each data set.

Example

Input

-3 -2 9 6
3 -2 7 6
-1 0 5 0
2 2 -1 -1
0 1 2 1
-3 -1 3 1
0 0 0 0

Output

syo-kichi
kyo

### Response

```cpp
// Triangle and Circle

#include<iostream>
#include<cmath>     // fabs(), hypot()
#include<vector>    // Circle::crosspoint()の戻り値, Polygonのメンバ変数
#include<algorithm> // min()

const double EPS = 1e-10;
enum POSITION {ONLINE_FRONT = -2, CLOCKWISE, ON_SEGMENT, COUNTER_CLOCKWISE, ONLINE_BACK};   // ccw(a, b, p)で3点a, b, pの位置関係を返す
                                                                                //   0: a-p-b, 2: p-a-b, -2: a-b-p, 1: -a-b-の上にp, -1: -a-b-の下にp
// class
class Point;
class Segment;
class Line;
class Circle;
class Polygon;
// member
class Point {
    double x_value, y_value;
public:
    Point() :x_value(0.0), y_value(0.0) {}
    Point(double d) :x_value(d), y_value(d) {}
    Point(double a, double b) :x_value(a), y_value(b) {}
    double x() const {return x_value;}
    double y() const {return y_value;}
    double x(double d) {return x_value = d;}
    double y(double d) {return y_value = d;}
    bool operator== (const Point&) const;
    bool operator!= (const Point&) const;
    bool operator< (const Point&) const;
    bool operator> (const Point&) const;
    bool operator<= (const Point&) const;
    bool operator>= (const Point&) const;
    const Point operator-() const;
    const Point& operator=(const Point&);
    const Point& operator+=(const Point&);
    const Point& operator-=(const Point&);
    const Point& operator*=(const Point&);
    const Point& operator/=(const Point&);
    double dot(const Point&) const;
    double cross(const Point&) const;
    double abs() const;
    double norm() const;
    double distance(const Point&) const;
    double distance(const Segment&) const;
    double distance(const Line&) const;
    bool intersect(const Point&) const;
    bool intersect(const Segment&) const;
    bool intersect(const Line&) const;
    const Point projection(const Line&) const;
    const Point reflection(const Line&) const;
    POSITION ccw(const Point&, const Point&) const;
};
const Point operator+(const Point& lhs, const Point& rhs);
const Point operator-(const Point& lhs, const Point& rhs);
const Point operator*(const Point& lhs, const Point& rhs);
const Point operator/(const Point& lhs, const Point& rhs);
class Segment {
    Point source_point, target_point;
public:
    Segment(double x1 = 0.0, double y1 = 0.0, double x2 = 0.0, double y2 = 0.0) :source_point(Point(x1, y1)), target_point(Point(x2, y2)) {}
    Segment(const Point& a, const Point& b) :source_point(a), target_point(b) {}
    const Point& source() const {return source_point;}
    const Point& target() const {return target_point;}
    const Point& source(const Point& p) {return source_point = p;}
    const Point& target(const Point& p) {return target_point = p;}
    const Line line() const;
    double distance(const Point&) const;
    double distance(const Segment&) const;
    double distance(const Line&) const;
    bool intersect(const Point&) const;
    bool intersect(const Segment&) const;
    bool intersect(const Line&) const;
    POSITION ccw(const Point&) const;
};
class Line {
    Point source_point, target_point;
public:
    Line(double x1 = 0.0, double y1 = 0.0, double x2 = 0.0, double y2 = 0.0) :source_point(Point(x1, y1)), target_point(Point(x2, y2)) {}
    Line(const Point& a, const Point& b) :source_point(a), target_point(b) {}
    const Point& source() const {return source_point;}
    const Point& target() const {return target_point;}
    const Point& source(const Point& p) {return source_point = p;}
    const Point& target(const Point& p) {return target_point = p;}
    const Segment segment() const;
    double distance(const Point&) const;
    double distance(const Segment&) const;
    double distance(const Line&) const;
    bool intersect(const Point&) const;
    bool intersect(const Segment&) const;
    bool intersect(const Line&) const;
    bool parallel(const Line&) const;
    bool orthogonal(const Line&) const;
    const Point projection(const Point&) const;
    const Point reflection(const Point&) const;
    const Point crosspoint(const Line&) const;
    POSITION ccw(const Point&) const;
};
class Circle {
    Point center_point;
    double radius;
public:
    Circle(double a = 0.0, double b = 0.0, double c = 0.0) :center_point(Point(a, b)), radius(c) {}
    const Point& center() const {return center_point;}
    double x() const {return center_point.x();}
    double y() const {return center_point.y();}
    double r() const {return radius;}
    const Point& center(const Point& p) {return center_point = p;}
    double x(double d) {return center_point.x(d);}
    double y(double d) {return center_point.y(d);}
    double r(double d) {return radius = d;}
    bool include(const Point&) const;
    bool include(const Segment&) const;
    bool include(const Circle&) const;
    bool intersect(const Circle&) const;
    std::vector<Point> crosspoint(const Circle&) const;
};
class Polygon {
    std::vector<Point> point;
public:
    Polygon() {}
    const std::vector<Point>& vertex() const {return point;}
    const Point& vertex(int i) const {return point.at(i);}
    const std::vector<Segment> edge() const {
        std::vector<Segment> result;
        for(int i = 0; i < size(); ++i) result.push_back(Segment(vertex(i), vertex((i + 1) % size())));
        return result;
    }
    const Segment edge(int i) const {return Segment(vertex(i), vertex((i + 1) % size()));}
    int size() const {return point.size();}
    void add(const Point&);
    double area() const;
    bool convex() const;
    bool include(const Point&) const;
    bool on_edge(const Point&) const;
};
// Point
bool Point::operator== (const Point &p) const {return x() == p.x() && y() == p.y();}
bool Point::operator!= (const Point &p) const {return x() != p.x() || y() != p.y();}
bool Point::operator<(const Point &p) const {return x() != p.x() ? x() < p.x() : y() < p.y();}
bool Point::operator>(const Point &p) const {return x() != p.x() ? x() > p.x() : y() > p.y();}
bool Point::operator<=(const Point &p) const {return x() != p.x() ? x() < p.x() : y() <= p.y();}
bool Point::operator>=(const Point &p) const {return x() != p.x() ? x() > p.x() : y() >= p.y();}
const Point operator+(const Point& lhs, const Point& rhs) {return Point(lhs.x() + rhs.x(), lhs.y() + rhs.y());}
const Point operator-(const Point& lhs, const Point& rhs) {return Point(lhs.x() - rhs.x(), lhs.y() - rhs.y());}
const Point operator*(const Point& lhs, const Point& rhs) {return Point(lhs.x() * rhs.x(), lhs.y() * rhs.y());}
const Point operator/(const Point& lhs, const Point& rhs) {return Point(lhs.x() / rhs.x(), lhs.y() / rhs.y());}
const Point Point::operator-() const {return Point(-x(), -y());}
const Point& Point::operator=(const Point& p) {x(p.x()); y(p.y()); return *this;}
const Point& Point::operator+=(const Point& p) {return *this = *this + p;}
const Point& Point::operator-=(const Point& p) {return *this = *this - p;}
const Point& Point::operator*=(const Point& p) {return *this = *this * p;}
const Point& Point::operator/=(const Point& p) {return *this = *this / p;}
double Point::dot(const Point& p) const {return x() * p.x() + y() * p.y();}
double Point::cross(const Point& p) const {return x() * p.y() - y() * p.x();}
double Point::abs() const {return hypot(x(), y());}
double Point::norm() const {return x() * x() + y() * y();}
double Point::distance(const Point& p) const {return (p - (*this)).abs();}
double Point::distance(const Segment& s) const {return s.distance(*this);}
double Point::distance(const Line& l) const {return l.distance(*this);}
bool Point::intersect(const Point& p) const {return *this == p;}
bool Point::intersect(const Segment& s) const {return s.intersect(*this);}
bool Point::intersect(const Line& l) const {return l.intersect(*this);}
const Point Point::projection(const Line& l) const {return l.projection(*this);}
const Point Point::reflection(const Line& l) const {return l.reflection(*this);}
POSITION Point::ccw(const Point& b, const Point& p) const {
    const Point& a = *this;
    Point v1 = b - a;
    Point v2 = p - a;
    if(v1.cross(v2) > EPS) return COUNTER_CLOCKWISE;
    if(v1.cross(v2) < -EPS) return CLOCKWISE;
    if(v1.dot(v2) < -EPS) return ONLINE_BACK;
    if(v2.norm() - v1.norm() > EPS) return ONLINE_FRONT;
    return ON_SEGMENT;
}
// Segment
const Line Segment::line() const {return Line(source(), target());}
double Segment::distance(const Point& p) const {
    Point q = line().projection(p);
    if(intersect(q)) return q.distance(p);
    return std::min(source().distance(p), target().distance(p));
}
double Segment::distance(const Segment& s) const {
    if(intersect(s)) return 0.0;
    double a = distance(s.source());
    double b = distance(s.target());
    double c = s.distance(source());
    double d = s.distance(target());
    return std::min({a, b, c, d});
}
double Segment::distance(const Line& l) const {return l.distance(*this);}
bool Segment::intersect(const Point& p) const {return source().distance(p) + target().distance(p) - target().distance(source()) <= EPS;}
bool Segment::intersect(const Segment& s) const {
    bool a = ccw(s.source()) * ccw(s.target()) <= 0;
    bool b = s.ccw(source()) * s.ccw(target()) <= 0;
    return a && b;
}
bool Segment::intersect(const Line& l) const {return l.intersect(*this);}
POSITION Segment::ccw(const Point& p) const {return source().ccw(target(), p);}
// Line
const Segment Line::segment() const {return Segment(source(), target());}
double Line::distance(const Point& p) const {return p.distance(projection(p));}
double Line::distance(const Segment& s) const {
    if(intersect(s)) return 0.0;
    double a = distance(s.source());
    double b = distance(s.target());
    return a < b ? a : b;
}
double Line::distance(const Line& l) const {return intersect(l) ? 0.0 : distance(l.source());}
bool Line::intersect(const Point& p) const {
    Point v1 = source() - p;
    Point v2 = target() - p;
    return fabs(v2.cross(v1)) < EPS;
}
bool Line::intersect(const Segment& s) const {
    Point v1 = target() - source();
    Point v2 = s.source() - source();
    Point v3 = s.target() - source();
    return v1.cross(v2) * v1.cross(v3) <= EPS;
}
bool Line::intersect(const Line& l) const {
    Point v1 = target() - source();
    Point v2 = l.target() - l.source();
    Point v3 = l.source() - source();
    return fabs(v1.cross(v2)) > EPS || fabs(v1.cross(v3)) < EPS;
}
const Point Line::projection(const Point& p) const {
    Point v1 = p - source();
    Point v2 = source() - target();
    return Point(source() + v2 * (v1.dot(v2) / v2.norm()));
}
const Point Line::reflection(const Point& p) const {
    return p + (projection(p) - p) * 2.0;
}
const Point Line::crosspoint(const Line& l) const {
    Point v1 = target() - source();
    Point v2 = l.target() - l.source();
    Point v3 = target() - l.source();
    double a = v1.cross(v2);
    double b = v1.cross(v3);
    if(fabs(a) <= EPS && fabs(b) <= EPS) return l.source();
    return l.source() + v2 * (b / a);
}
bool Line::parallel(const Line& l) const {
    double dx = target().x() - source().x();
    double dy = target().y() - source().y();
    double dxl = l.target().x() - l.source().x();
    double dyl = l.target().y() - l.source().y();
    return fabs(dy * dxl - dyl * dx) <= EPS;
}
bool Line::orthogonal(const Line& l) const {
    double dx = target().x() - source().x();
    double dy = target().y() - source().y();
    double dxl = l.target().x() - l.source().x();
    double dyl = l.target().y() - l.source().y();
    return fabs(dy * dyl + dxl * dx) <= EPS;
}
POSITION Line::ccw(const Point& p) const {return source().ccw(target(), p);}
// Circle
bool Circle::include(const Point& p) const {return center().distance(p) - r() <= EPS;}
bool Circle::include(const Segment& s) const {return center().distance(s) - r() <= EPS;}
bool Circle::include(const Circle& c) const {return center().distance(c.center()) - (r() - c.r()) <= EPS;}
bool Circle::intersect(const Circle& c) const {return center().distance(c.center()) - r() - c.r() <= EPS;}
std::vector<Point> Circle::crosspoint(const Circle& c) const {
    double angle = atan2(c.y() - y(), c.x() - x());
    double d = center().distance(c.center());
    double add = acos((d * d + r() * r() - c.r() * c.r()) / (2.0 * d * r()));
    std::vector<Point> result;
    result.push_back(Point(x() + r() * cos(angle + add), y() + r() * sin(angle + add)));
    result.push_back(Point(x() + r() * cos(angle - add), y() + r() * sin(angle - add)));
    return result;
}
// Polygon
void Polygon::add(const Point& p) {point.push_back(p);}
double Polygon::area() const {
    double sum = 0.0;
    for(int i = 0; i < size(); ++i) sum += vertex(i).cross(vertex((i+1) % size()));
    return fabs(sum) / 2.0;
}
bool Polygon::convex() const {
    POSITION direction = ONLINE_BACK;
    for(int i = 1; i < size(); ++i) {
        POSITION d = vertex(i - 1).ccw(vertex(i), vertex((i + 1) % size()));
        if(d != CLOCKWISE && d != COUNTER_CLOCKWISE) continue;
        if(direction == ONLINE_BACK) direction = d;
        if(direction != d) return false;
    }
    return true;
}
bool Polygon::include(const Point& p) const {
    bool in = false;
    for(int i = 0; i < size(); ++i) {
        Point a = vertex(i) - p;
        Point b = vertex((i + 1) % size()) - p;
        if(a.y() > b.y()) std::swap(a, b);
        if(a.y() <= 0.0 && 0 < b.y() && a.cross(b) < 0.0) in = !in;
        if(fabs(a.cross(b)) <= EPS && a.dot(b) <= EPS) return true;
    }
    return in;
}
bool Polygon::on_edge(const Point& p) const {
    for(int i = 0; i < size(); ++i) if(vertex(i).ccw(vertex((i + 1) % size()), p) == ON_SEGMENT) return true;
    return false;
}

using namespace std;

int main() {
    double x1, y1, x2, y2;
    while(cin >> x1 >> y1 >> x2 >> y2, x1 != 0 || y1 != 0 || x2 != 0 || y2 != 0) {
        Segment s1(x1, y1, x2, y2);
        cin >> x1 >> y1 >> x2 >> y2;
        Segment s2(x1, y1, x2, y2);
        cin >> x1 >> y1 >> x2 >> y2;
        Segment s3(x1, y1, x2, y2);

        if((s1.intersect(s2) && s2.intersect(s3) && s3.intersect(s1)) && !s1.line().parallel(s2.line()) && !s2.line().parallel(s3.line()) && !s3.line().parallel(s1.line())) {
            Polygon triangle;
            triangle.add(s1.line().crosspoint(s2.line()));
            triangle.add(s2.line().crosspoint(s3.line()));
            triangle.add(s3.line().crosspoint(s1.line()));
            if(triangle.vertex(0) == triangle.vertex(1) || triangle.vertex(1) == triangle.vertex(2) || triangle.vertex(2) == triangle.vertex(0)) cout << "kyo" << endl;
            else if(triangle.area() >= 1900000.0) cout << "dai-kichi" << endl;
            else if(triangle.area() >= 1000000.0) cout << "chu-kichi" << endl;
            else if(triangle.area() >= 100000.0) cout << "kichi" << endl;
            else cout << "syo-kichi" << endl;
        } else {
            cout << "kyo" << endl;
        }
    }
}
```


### Prompt

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

Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.

There are two sequences of n strings s_1, s_2, s_3, …, s_{n} and m strings t_1, t_2, t_3, …, t_{m}. These strings contain only lowercase letters. There might be duplicates among these strings.

Let's call a concatenation of strings x and y as the string that is obtained by writing down strings x and y one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".

The year 1 has a name which is the concatenation of the two strings s_1 and t_1. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.

For example, if n = 3, m = 4, s = {"a", "b", "c"}, t = {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat.

<image>

You are given two sequences of strings of size n and m and also q queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system?

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 20).

The next line contains n strings s_1, s_2, …, s_{n}. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least 1 and at most 10.

The next line contains m strings t_1, t_2, …, t_{m}. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least 1 and at most 10.

Among the given n + m strings may be duplicates (that is, they are not necessarily all different).

The next line contains a single integer q (1 ≤ q ≤ 2 020).

In the next q lines, an integer y (1 ≤ y ≤ 10^9) is given, denoting the year we want to know the name for.

Output

Print q lines. For each line, print the name of the year as per the rule described above.

Example

Input

10 12
sin im gye gap eul byeong jeong mu gi gyeong
yu sul hae ja chuk in myo jin sa o mi sin
14
1
2
3
4
10
11
12
13
73
2016
2017
2018
2019
2020

Output

sinyu
imsul
gyehae
gapja
gyeongo
sinmi
imsin
gyeyu
gyeyu
byeongsin
jeongyu
musul
gihae
gyeongja

Note

The first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, c, x;
  char s[21][11], t[21][11];
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  for (int i = 0; i < m; i++) scanf("%s", t[i]);
  ;
  scanf("%d", &c);
  while (c--) {
    scanf("%d", &x);
    x--;
    printf("%s%s\n", s[x % n], t[x % m]);
  }
  return 0;
}

```


### Prompt

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

Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were the first integer is the number of vertices adjacent to vertex v, and the second integer is the XOR sum of the numbers of vertices adjacent to v (if there were no adjacent vertices, he wrote down 0).

Next day Misha couldn't remember what graph he initially had. Misha has values degreev and sv left, though. Help him find the number of edges and the edges of the initial graph. It is guaranteed that there exists a forest that corresponds to the numbers written by Misha.

Input

The first line contains integer n (1 ≤ n ≤ 216), the number of vertices in the graph.

The i-th of the next lines contains numbers degreei and si (0 ≤ degreei ≤ n - 1, 0 ≤ si < 216), separated by a space.

Output

In the first line print number m, the number of edges of the graph.

Next print m lines, each containing two distinct numbers, a and b (0 ≤ a ≤ n - 1, 0 ≤ b ≤ n - 1), corresponding to edge (a, b).

Edges can be printed in any order; vertices of the edge can also be printed in any order.

Examples

Input

3
2 3
1 0
1 0

Output

2
1 0
2 0

Input

2
1 1
1 0

Output

1
0 1

Note

The XOR sum of numbers is the result of bitwise adding numbers modulo 2. This operation exists in many modern programming languages. For example, in languages C++, Java and Python it is represented as "^", and in Pascal — as "xor".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> info;
queue<int> Q;
int xrv[70000];
int baki[70000];
vector<pair<int, int> > ans;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> baki[i] >> xrv[i];
    if (baki[i] == 0) continue;
    if (baki[i] == 1) Q.push(i);
  }
  int lim = 0;
  while (!Q.empty()) {
    int top = Q.front();
    Q.pop();
    while (baki[top] > 0) {
      int v = xrv[top];
      ans.push_back(make_pair(top, v));
      lim++;
      xrv[v] = (xrv[v] ^ top);
      baki[top]--;
      baki[v]--;
      if (baki[v] == 1) Q.push(v);
    }
  }
  cout << lim << endl;
  for (int i = 0; i < ((int)ans.size()); ++i) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}

```


### Prompt

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

The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon pond at (1, n).

The mayor of Fishtopia wants to place k hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.

A person can move from one cell to another if those cells are not occupied by hotels and share a side.

Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?

Input

The first line of input contain two integers, n and k (3 ≤ n ≤ 99, 0 ≤ k ≤ 2×(n-2)), n is odd, the width of the city, and the number of hotels to be placed, respectively.

Output

Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".

If it is possible, print an extra 4 lines that describe the city, each line should have n characters, each of which is "#" if that cell has a hotel on it, or "." if not.

Examples

Input

7 2

Output

YES
.......
.#.....
.#.....
.......

Input

5 3

Output

YES
.....
.###.
.....
.....

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7ffffff;
const int MAXN = +3;
int n, k;
int main() {
  cin >> n >> k;
  if (!(k % 2)) {
    cout << "YES" << endl;
    for (int i = 0; i < n; i++) cout << ".";
    cout << endl;
    cout << ".";
    for (int i = 0; i < k / 2; i++) cout << "#";
    for (int i = 0; i < n - 1 - k / 2; i++) cout << ".";
    cout << endl;
    cout << ".";
    for (int i = 0; i < k / 2; i++) cout << "#";
    for (int i = 0; i < n - 1 - k / 2; i++) cout << ".";
    cout << endl;
    for (int i = 0; i < n; i++) cout << ".";
  } else {
    if (n > 3 && k == (n - 2) * 2 - 1) {
      cout << "YES\n";
      for (int i = 0; i < n; i++) cout << ".";
      cout << endl << ".";
      for (int i = 0; i < n - 2; i++) cout << "#";
      cout << "." << endl << ".";
      for (int i = 0; i < n / 2 - 1; i++) cout << "#";
      cout << ".";
      for (int i = 0; i < n / 2 - 1; i++) cout << "#";
      cout << "." << endl;
      for (int i = 0; i < n; i++) cout << ".";
    } else if (k == 1) {
      cout << "YES\n";
      for (int i = 0; i < n; i++) cout << ".";
      cout << endl;
      for (int i = 0; i < n / 2; i++) cout << ".";
      cout << "#";
      for (int i = 0; i < n / 2; i++) cout << ".";
      cout << endl;
      for (int i = 0; i < n; i++) cout << ".";
      cout << endl;
      for (int i = 0; i < n; i++) cout << ".";
    } else {
      cout << "YES" << endl;
      for (int i = 0; i < n; i++) cout << ".";
      cout << endl;
      for (int i = 0; i < n - (k - 3) / 2 - 4; i++) cout << '.';
      for (int i = 0; i < (k - 3) / 2; i++) cout << '#';
      cout << "#.#.\n";
      for (int i = 0; i < n - (k - 3) / 2 - 4; i++) cout << '.';
      for (int i = 0; i < (k - 3) / 2; i++) cout << '#';
      cout << "#...\n";
      for (int i = 0; i < n; i++) cout << ".";
    }
  }
  return 0;
}

```


### Prompt

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

AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code.

The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.

How many different PIN codes can he set this way?

Both the lucky number and the PIN code may begin with a 0.

Constraints

* 4 \leq N \leq 30000
* S is a string of length N consisting of digits.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of different PIN codes Takahashi can set.

Examples

Input

4
0224

Output

3

Input

6
123123

Output

17

Input

19
3141592653589793238

Output

329

### Response

```cpp
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	int ans = 0;
	for (int i = 0; i <= 999; i++) {
		string T = to_string(i);
		T = string(3 - T.size(), '0') + T;
		int k = 0;
		for (int j = 0; j < N; j++) {
			if (S[j] == T[k]) {
				k++;
			}
		}
		if (k == 3) ans++;
	}
	cout << ans << endl;
}

```


### Prompt

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

A schoolboy Petya studies square equations. The equations that are included in the school curriculum, usually look simple:

x2 + 2bx + c = 0 where b, c are natural numbers.

Petya noticed that some equations have two real roots, some of them have only one root and some equations don't have real roots at all. Moreover it turned out that several different square equations can have a common root.

Petya is interested in how many different real roots have all the equations of the type described above for all the possible pairs of numbers b and c such that 1 ≤ b ≤ n, 1 ≤ c ≤ m. Help Petya find that number.

Input

The single line contains two integers n and m. (1 ≤ n, m ≤ 5000000).

Output

Print a single number which is the number of real roots of the described set of equations.

Examples

Input

3 3

Output

12

Input

1 2

Output

1

Note

In the second test from the statement the following equations are analysed:

b = 1, c = 1: x2 + 2x + 1 = 0; The root is x = - 1

b = 1, c = 2: x2 + 2x + 2 = 0; No roots

Overall there's one root

In the second test the following equations are analysed:

b = 1, c = 1: x2 + 2x + 1 = 0; The root is x = - 1

b = 1, c = 2: x2 + 2x + 2 = 0; No roots

b = 1, c = 3: x2 + 2x + 3 = 0; No roots

b = 2, c = 1: x2 + 4x + 1 = 0; The roots are <image>

b = 2, c = 2: x2 + 4x + 2 = 0; The roots are <image>

b = 2, c = 3: x2 + 4x + 3 = 0; The roots are x1 = - 3, x2 = - 1

b = 3, c = 1: x2 + 6x + 1 = 0; The roots are <image>

b = 3, c = 2: x2 + 6x + 2 = 0; The roots are <image>

b = 3, c = 3: x2 + 6x + 3 = 0; The roots are <image> Overall there are 13 roots and as the root  - 1 is repeated twice, that means there are 12 different roots.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char tree[33554432];
const int BASE = 16777216;
int st, ed;
void cover(int now, int s, int e) {
  if (st <= s && e <= ed) {
    tree[now] = 1;
  } else {
    int m = (s + e) / 2;
    if (st <= m) cover(now * 2, s, m);
    if (m + 1 <= ed) cover(now * 2 + 1, m + 1, e);
  }
}
int get(int now, int s, int e) {
  if (tree[now]) {
    return e - s + 1;
  }
  if (now >= BASE) return 0;
  int m = (s + e) / 2;
  return get(now * 2, s, m) + get(now * 2 + 1, m + 1, e);
}
int main() {
  memset(tree, 0, sizeof(tree));
  int _n, _m;
  long long n, m;
  scanf("%d%d", &_n, &_m);
  n = _n, m = _m;
  long long isol = 0;
  long long dsol = 0;
  for (long long i = 1; i <= _n; ++i) {
    if (i * i > m) {
      double s1 = sqrt(i * i - 1);
      double s2 = sqrt(i * i - m);
      int cnt = (int)((double)i - s2 + 1e-9);
      if (cnt > 0) {
        st = 2 * i - cnt;
        ed = 2 * i - 1;
        cover(1, 0, BASE - 1);
        st = 1;
        ed = cnt;
        cover(1, 0, BASE - 1);
      }
      dsol += 2 * m - 2 * cnt;
    } else {
      st = 1, ed = 2 * i - 1;
      cover(1, 0, BASE - 1);
      dsol += 2 * i * i - 2 * i;
    }
  }
  isol = get(1, 0, BASE - 1);
  cout << dsol + isol << endl;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended up entangled and now have to be untangled again.

The device is powered by two wires "plus" and "minus". The wires run along the floor from the wall (on the left) to the device (on the right). Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order. The wires are considered entangled if there are one or more places where one wire runs above the other one. For example, the picture below has four such places (top view):

<image>

Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device. Determine if it is possible to do that. A wire can be freely moved and stretched on the floor, but cannot be cut.

To understand the problem better please read the notes to the test samples.

Input

The single line of the input contains a sequence of characters "+" and "-" of length n (1 ≤ n ≤ 100000). The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise.

Output

Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled.

Examples

Input

-++-

Output

Yes

Input

+-

Output

No

Input

++

Output

Yes

Input

-

Output

No

Note

The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.

In the second testcase the "plus" wire makes one full revolution around the "minus" wire. Thus the wires cannot be untangled:

<image>

In the third testcase the "plus" wire simply runs above the "minus" wire twice in sequence. The wires can be untangled by lifting "plus" and moving it higher:

<image>

In the fourth testcase the "minus" wire runs above the "plus" wire once. The wires cannot be untangled without moving the device itself:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
void doh() {
  printf("No\n");
  exit(0);
}
int main() {
  string s;
  cin >> s;
  int n = int((s).size());
  if (n & 1) doh();
  int bal = 0;
  for (int i = 0; i < n; i += 2) {
    if (s[i] != s[i + 1]) {
      if (s[i] == '+')
        ++bal;
      else
        --bal;
    }
  }
  if (bal != 0) doh();
  printf("Yes\n");
  return 0;
}

```


### Prompt

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

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

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

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

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

Input

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

Output

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

Examples

Input

2 0

Output

4

Input

2 1

Output

7

Input

3 2

Output

21

Note

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

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

### Response

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

```


### Prompt

Please formulate a CPP solution to the following problem:

Let's play Amidakuji.

In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.

<image>

In the starting points (top of the figure), numbers are assigned to vertical lines in ascending order from left to right. At the first step, 2 and 4 are swaped by the first horizontal line which connects second and fourth vertical lines (we call this operation (2, 4)). Likewise, we perform (3, 5), (1, 2) and (3, 4), then obtain "4 1 2 5 3" in the bottom.

Your task is to write a program which reads the number of vertical lines w and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., w are assigne to the vertical lines from left to right.

Hint

Try it. -->

Input

w
n
a1,b1
a2,b2
.
.
an,bn

w (w ≤ 30) is the number of vertical lines. n (n ≤ 30) is the number of horizontal lines. A pair of two integers ai and bi delimited by a comma represents the i-th horizontal line.

Output

The number which should be under the 1st (leftmost) vertical line
The number which should be under the 2nd vertical line
:
The number which should be under the w-th vertical line

Example

Input

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

Output

4
1
2
5
3

### Response

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

int main(){

	int w,n;
	int a,b;
	char c;
	int temp;
	int x[31]={};

	cin >> w >> n ;

	for( int i=1 ; i<=w ; i++ ) x[i]=i;

	for( int i=0 ; i<n ; i++ ){
		cin >> a >> c >> b ;

		temp=x[a];
		x[a]=x[b];
		x[b]=temp;
	}

	for( int i=1 ; i<=w ; i++ ) cout << x[i] << endl ;

return 0;
}
```


### Prompt

Please formulate a Cpp solution to the following problem:

A tree is an undirected connected graph without cycles.

Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1, p2, ..., pn, where pi denotes a parent of vertex i (here, for convenience a root is considered its own parent).

<image> For this rooted tree the array p is [2, 3, 3, 2].

Given a sequence p1, p2, ..., pn, one is able to restore a tree:

  1. There must be exactly one index r that pr = r. A vertex r is a root of the tree.
  2. For all other n - 1 vertices i, there is an edge between vertex i and vertex pi.

A sequence p1, p2, ..., pn is called valid if the described procedure generates some (any) rooted tree. For example, for n = 3 sequences (1,2,2), (2,3,1) and (2,1,3) are not valid.

You are given a sequence a1, a2, ..., an, not necessarily valid. Your task is to change the minimum number of elements, in order to get a valid sequence. Print the minimum number of changes and an example of a valid sequence after that number of changes. If there are many valid sequences achievable in the minimum number of changes, print any of them.

Input

The first line of the input contains an integer n (2 ≤ n ≤ 200 000) — the number of vertices in the tree.

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

Output

In the first line print the minimum number of elements to change, in order to get a valid sequence.

In the second line, print any valid sequence possible to get from (a1, a2, ..., an) in the minimum number of changes. If there are many such sequences, any of them will be accepted.

Examples

Input

4
2 3 3 4

Output

1
2 3 4 4

Input

5
3 2 2 5 3

Output

0
3 2 2 5 3

Input

8
2 3 5 4 1 6 6 7

Output

2
2 3 7 8 1 6 6 7

Note

In the first sample, it's enough to change one element. In the provided output, a sequence represents a tree rooted in a vertex 4 (because p4 = 4), which you can see on the left drawing below. One of other correct solutions would be a sequence 2 3 3 2, representing a tree rooted in vertex 3 (right drawing below). On both drawings, roots are painted red.

<image>

In the second sample, the given sequence is already valid.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
inline int read() {
  int s = 0, t = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') t = -1;
    c = getchar();
  }
  while (isdigit(c)) s = s * 10 + c - 48, c = getchar();
  return s * t;
}
int fa[maxn], pa[maxn], q[maxn], tot = 0, bel = 0;
inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int main() {
  int n = read(), x, y;
  for (register int i = 1; i <= n; i++) pa[i] = read(), fa[i] = i;
  for (register int i = 1; i <= n; i++) {
    if (i == pa[i]) {
      if (!bel)
        bel = i;
      else
        q[++tot] = i;
      continue;
    }
    x = find(pa[i]), y = find(i);
    if (x == y)
      q[++tot] = i;
    else
      fa[y] = x;
  }
  if (!bel) {
    x = q[1], pa[x] = x;
    for (register int i = 2; i <= tot; i++) pa[q[i]] = x;
    cout << tot << endl;
    for (register int i = 1; i <= n; i++) cout << pa[i] << " ";
    cout << endl;
  } else {
    cout << tot << endl;
    for (register int i = 1; i <= tot; i++) pa[q[i]] = bel;
    for (register int i = 1; i <= n; i++) cout << pa[i] << " ";
    cout << endl;
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Vasya writes his own library for building graphical user interface. Vasya called his creation VTK (VasyaToolKit). One of the interesting aspects of this library is that widgets are packed in each other.

A widget is some element of graphical interface. Each widget has width and height, and occupies some rectangle on the screen. Any widget in Vasya's library is of type Widget. For simplicity we will identify the widget and its type.

Types HBox and VBox are derivatives of type Widget, so they also are types Widget. Widgets HBox and VBox are special. They can store other widgets. Both those widgets can use the pack() method to pack directly in itself some other widget. Widgets of types HBox and VBox can store several other widgets, even several equal widgets — they will simply appear several times. As a result of using the method pack() only the link to the packed widget is saved, that is when the packed widget is changed, its image in the widget, into which it is packed, will also change.

We shall assume that the widget a is packed in the widget b if there exists a chain of widgets a = c1, c2, ..., ck = b, k ≥ 2, for which ci is packed directly to ci + 1 for any 1 ≤ i < k. In Vasya's library the situation when the widget a is packed in the widget a (that is, in itself) is not allowed. If you try to pack the widgets into each other in this manner immediately results in an error.

Also, the widgets HBox and VBox have parameters border and spacing, which are determined by the methods set_border() and set_spacing() respectively. By default both of these options equal 0.

<image>

The picture above shows how the widgets are packed into HBox and VBox. At that HBox and VBox automatically change their size depending on the size of packed widgets. As for HBox and VBox, they only differ in that in HBox the widgets are packed horizontally and in VBox — vertically. The parameter spacing sets the distance between adjacent widgets, and border — a frame around all packed widgets of the desired width. Packed widgets are placed exactly in the order in which the pack() method was called for them. If within HBox or VBox there are no packed widgets, their sizes are equal to 0 × 0, regardless of the options border and spacing.

The construction of all the widgets is performed using a scripting language VasyaScript. The description of the language can be found in the input data.

For the final verification of the code Vasya asks you to write a program that calculates the sizes of all the widgets on the source code in the language of VasyaScript.

Input

The first line contains an integer n — the number of instructions (1 ≤ n ≤ 100). Next n lines contain instructions in the language VasyaScript — one instruction per line. There is a list of possible instructions below.

  * "Widget [name]([x],[y])" — create a new widget [name] of the type Widget possessing the width of [x] units and the height of [y] units.
  * "HBox [name]" — create a new widget [name] of the type HBox.
  * "VBox [name]" — create a new widget [name] of the type VBox.
  * "[name1].pack([name2])" — pack the widget [name2] in the widget [name1]. At that, the widget [name1] must be of type HBox or VBox.
  * "[name].set_border([x])" — set for a widget [name] the border parameter to [x] units. The widget [name] must be of type HBox or VBox.
  * "[name].set_spacing([x])" — set for a widget [name] the spacing parameter to [x] units. The widget [name] must be of type HBox or VBox.

All instructions are written without spaces at the beginning and at the end of the string. The words inside the instruction are separated by exactly one space. There are no spaces directly before the numbers and directly after them.

The case matters, for example, "wiDget x" is not a correct instruction. The case of the letters is correct in the input data.

All names of the widgets consist of lowercase Latin letters and has the length from 1 to 10 characters inclusive. The names of all widgets are pairwise different. All numbers in the script are integers from 0 to 100 inclusive

It is guaranteed that the above-given script is correct, that is that all the operations with the widgets take place after the widgets are created and no widget is packed in itself. It is guaranteed that the script creates at least one widget.

Output

For each widget print on a single line its name, width and height, separated by spaces. The lines must be ordered lexicographically by a widget's name.

Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout stream (also you may use %I64d specificator)

Examples

Input

12
Widget me(50,40)
VBox grandpa
HBox father
grandpa.pack(father)
father.pack(me)
grandpa.set_border(10)
grandpa.set_spacing(20)
Widget brother(30,60)
father.pack(brother)
Widget friend(20,60)
Widget uncle(100,20)
grandpa.pack(uncle)

Output

brother 30 60
father 80 60
friend 20 60
grandpa 120 120
me 50 40
uncle 100 20

Input

15
Widget pack(10,10)
HBox dummy
HBox x
VBox y
y.pack(dummy)
y.set_border(5)
y.set_spacing(55)
dummy.set_border(10)
dummy.set_spacing(20)
x.set_border(10)
x.set_spacing(10)
x.pack(pack)
x.pack(dummy)
x.pack(pack)
x.set_border(0)

Output

dummy 0 0
pack 10 10
x 40 10
y 10 10

Note

In the first sample the widgets are arranged as follows:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 1999999999;
const double pi = acos(-1.0);
const double eps = 1e-10;
char gc() {
  char c;
  while (isspace(c = getchar()))
    ;
  return c;
}
struct box {
  int type;
  long long x, y;
  int bord, space;
  string s;
  vector<int> v;
  bool operator<(const box& o) const { return s < o.s; }
};
box bx[100];
map<string, int> m;
int geti(string& s) {
  map<string, int>::iterator it = m.find(s);
  if (it == m.end()) {
    int t = ((int)(m).size());
    m[s] = t;
    bx[t].s = s;
    return t;
  }
  return it->second;
}
int vis[100];
void dfs(int a) {
  box& t = bx[a];
  if (t.type == 0) return;
  if (((int)(t.v).size()) == 0) {
    t.x = 0;
    t.y = 0;
    return;
  }
  if (t.type == 1) {
    long long sx = 0, sy = 0;
    for (int i = 0; i < ((int)(t.v).size()); i++) {
      int c = t.v[i];
      if (!vis[c]) {
        vis[c] = true;
        dfs(c);
      }
      sx += bx[c].x + t.space;
      sy = max(sy, bx[c].y);
    }
    sx += 2 * t.bord - t.space;
    sy += 2 * t.bord;
    t.x = sx;
    t.y = sy;
  } else if (t.type == 2) {
    long long sx = 0, sy = 0;
    for (int i = 0; i < ((int)(t.v).size()); i++) {
      int c = t.v[i];
      if (!vis[c]) {
        vis[c] = true;
        dfs(c);
      }
      sx = max(sx, bx[c].x);
      sy += bx[c].y + t.space;
    }
    sx += 2 * t.bord;
    sy += 2 * t.bord - t.space;
    t.x = sx;
    t.y = sy;
  }
}
int main() {
  char in[10000];
  gets(in);
  int n;
  sscanf(in, "%d", &n);
  for (int ln = 0; ln < n; ln++) {
    gets(in);
    for (int i = 0; in[i]; i++)
      if (!isalpha(in[i]) && !isdigit(in[i])) in[i] = ' ';
    stringstream ss((string)in);
    string t;
    ss >> t;
    if (isupper(t[0])) {
      if (t[0] == 'W') {
        ss >> t;
        int i = geti(t);
        int x, y;
        ss >> x >> y;
        bx[i].type = 0;
        bx[i].x = x;
        bx[i].y = y;
      } else if (t[0] == 'H') {
        ss >> t;
        int i = geti(t);
        bx[i].type = 1;
      } else if (t[0] == 'V') {
        ss >> t;
        int i = geti(t);
        bx[i].type = 2;
      }
    } else {
      int a = geti(t);
      ss >> t;
      if (t[0] == 'p') {
        ss >> t;
        int b = geti(t);
        bx[a].v.push_back(b);
      } else {
        ss >> t;
        if (t[0] == 'b') {
          int d;
          ss >> d;
          bx[a].bord = d;
        } else if (t[0] == 's') {
          int d;
          ss >> d;
          bx[a].space = d;
        }
      }
    }
  }
  for (int i = 0; i < ((int)(m).size()); i++)
    if (!vis[i]) {
      vis[i] = true;
      dfs(i);
    }
  sort(bx, bx + ((int)(m).size()));
  for (int i = 0; i < ((int)(m).size()); i++)
    printf("%s %I64d %I64d\n", bx[i].s.c_str(), bx[i].x, bx[i].y);
}

```


### Prompt

Please formulate a CPP solution to the following problem:

In this problem, we use the 24-hour clock.

Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study for K consecutive minutes while he is up. What is the length of the period in which he can start studying?

Constraints

* 0 \le H_1, H_2 \le 23
* 0 \le M_1, M_2 \le 59
* The time H_1 : M_1 comes before the time H_2 : M_2.
* K \ge 1
* Takahashi is up for at least K minutes.
* All values in input are integers (without leading zeros).

Input

Input is given from Standard Input in the following format:

H_1 M_1 H_2 M_2 K

Output

Print the length of the period in which he can start studying, as an integer.

Examples

Input

10 0 15 0 30

Output

270

Input

10 0 12 0 120

Output

0

### Response

```cpp
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	int f=a*60+b,g=c*60+d;
	int ans=(g-f-e);
	cout<<ans<<'\n';
}
```


### Prompt

Generate a Cpp solution to the following problem:

International Center for Picassonian Cubism is a Spanish national museum of cubist artworks, dedicated to Pablo Picasso. The center held a competition for an artwork that will be displayed in front of the facade of the museum building. The artwork is a collection of cubes that are piled up on the ground and is intended to amuse visitors, who will be curious how the shape of the collection of cubes changes when it is seen from the front and the sides.

The artwork is a collection of cubes with edges of one foot long and is built on a flat ground that is divided into a grid of one foot by one foot squares. Due to some technical reasons, cubes of the artwork must be either put on the ground, fitting into a unit square in the grid, or put on another cube in the way that the bottom face of the upper cube exactly meets the top face of the lower cube. No other way of putting cubes is possible.

You are a member of the judging committee responsible for selecting one out of a plenty of artwork proposals submitted to the competition. The decision is made primarily based on artistic quality but the cost for installing the artwork is another important factor. Your task is to investigate the installation cost for each proposal. The cost is proportional to the number of cubes, so you have to figure out the minimum number of cubes needed for installation.

Each design proposal of an artwork consists of the front view and the side view (the view seen from the right-hand side), as shown in Figure 1.

<image>

Figure 1: An example of an artwork proposal

The front view (resp., the side view) indicates the maximum heights of piles of cubes for each column line (resp., row line) of the grid.

There are several ways to install this proposal of artwork, such as the following figures.

<image>

In these figures, the dotted lines on the ground indicate the grid lines. The left figure makes use of 16 cubes, which is not optimal. That is, the artwork can be installed with a fewer number of cubes. Actually, the right one is optimal and only uses 13 cubes. Note that, a single pile of height three in the right figure plays the roles of two such piles in the left one.

Notice that swapping columns of cubes does not change the side view. Similarly, swapping rows does not change the front view. Thus, such swaps do not change the costs of building the artworks.

For example, consider the artwork proposal given in Figure 2.

<image>

Figure 2: Another example of artwork proposal

An optimal installation of this proposal of artwork can be achieved with 13 cubes, as shown in the following figure, which can be obtained by exchanging the rightmost two columns of the optimal installation of the artwork of Figure 1.

<image>

Input

The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. Each dataset is formatted as follows.

w d
h1 h2 ... hw
h'1 h'2 ... h'd

The integers w and d separated by a space are the numbers of columns and rows of the grid, respectively. You may assume 1 ≤ w ≤ 10 and 1 ≤ d ≤ 10. The integers separated by a space in the second and third lines specify the shape of the artwork. The integers hi (1 ≤ hi ≤ 20, 1 ≤ i ≤ w) in the second line give the front view, i.e., the maximum heights of cubes per each column line, ordered from left to right (seen from the front). The integers hi (1 ≤ hi ≤ 20, 1 ≤ i ≤ d) in the third line give the side view, i.e., the maximum heights of cubes per each row line, ordered from left to right (seen from the right-hand side).

Output

For each dataset, output a line containing the minimum number of cubes. The output should not contain any other extra characters.

You can assume that, for each dataset, there is at least one way to install the artwork.

Example

Input

5 5
1 2 3 4 5
1 2 3 4 5
5 5
2 5 4 1 3
4 1 5 3 2
5 5
1 2 3 4 5
3 3 3 4 5
3 3
7 7 7
7 7 7
3 3
4 4 4
4 3 4
4 3
4 2 2 4
4 2 1
4 4
2 8 8 8
2 3 8 3
10 10
9 9 9 9 9 9 9 9 9 9
9 9 9 9 9 9 9 9 9 9
10 9
20 1 20 20 20 20 20 18 20 20
20 20 20 20 7 20 20 20 20
0 0

Output

15
15
21
21
15
13
32
90
186

### Response

```cpp
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main()
{
	while (true) {
		int w, d;

		cin >> w >> d;

		if (w == 0 && d == 0) {
			break;
		}

		vector<int> front(w);
		vector<int> side(d);

		rep(i, w) {
			cin >> front[i];
		}

		rep(i, d) {
			cin >> side[i];
		}

		rep(i, w) {
			rep(j, d) {
				if (front[i] == side[j]) {
					side[j] = 0;
					break;
				}
			}
		}

		int sum = 0;

		rep(i, w) {
			sum += front[i];
		}

		rep(i, d) {
			sum += side[i];
		}

		cout << sum << endl;
	}

	return 0;
}
```


### Prompt

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

Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :

* Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).

Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.

Constraints

* 1 \leq N \leq 50
* 0 \leq a_{i}, b_{i} \leq 50
* All values in the input are integers.

Input

Input is given from Standard Input in the following format:

N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}

Output

Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.

Examples

Input

3
19 10 14
0 3 4

Output

160

Input

3
19 15 14
0 0 0

Output

2

Input

2
8 13
5 13

Output

-1

Input

4
2 0 1 8
2 0 1 8

Output

0

Input

1
50
13

Output

137438953472

### Response

```cpp
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int f[60][60],a[60],b[60];
int n,ans[60],tot;
bool solve(int mx)
{
	memset(f,0,sizeof(f));
	for (int i=0;i<=50;i++)
	{
		f[i][i]=1;
		for (int j=1;j<mx;j++) f[i][i%j]=1;
		for (int j=1;j<=tot;j++) f[i][i%ans[j]]=1;
	}
	for (int k=0;k<=50;k++)
		for (int i=0;i<=50;i++)
			for (int j=0;j<=50;j++) f[i][j]|=f[i][k]&f[k][j];
	bool p=1;
	for (int i=1;i<=n;i++)
		p&=f[a[i]][b[i]];
	return p;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) scanf("%d",&b[i]);
	for (int i=50;i>=1;i--)
		if (!solve(i)) ans[++tot]=i;
	long long cnt=0;
	for (int i=1;i<=tot;i++) cnt+=1ll<<ans[i];
	if (tot==50)printf("-1");
	else printf("%lld",cnt);
}
```


### Prompt

Generate a Cpp solution to the following problem:

One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal.

Input

The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A<B.

Output

It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.

Examples

Input

A>B
C<B
A>C

Output

CBA

Input

A<B
B>C
C>A

Output

ACB

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a = 0, b = 0, c = 0;
  for (int i = 0; i < 3; i++) {
    string s;
    cin >> s;
    if (s == "A<B")
      b++;
    else if (s == "A<C")
      c++;
    else if (s == "A>B")
      a++;
    else if (s == "A>C")
      a++;
    else if (s == "B>A")
      b++;
    else if (s == "B>C")
      b++;
    else if (s == "B<A")
      a++;
    else if (s == "B<C")
      c++;
    else if (s == "C>A")
      c++;
    else if (s == "C>B")
      c++;
    else if (s == "C<A")
      a++;
    else if (s == "C<B")
      b++;
  }
  int ar[3];
  ar[0] = a;
  ar[1] = b;
  ar[2] = c;
  sort(ar, ar + 3);
  if (ar[0] == 0 && ar[1] == 1 && ar[2] == 2) {
    if (a > b && a > c) {
      if (b > c)
        cout << "CBA" << endl;
      else
        cout << "BCA" << endl;
    } else if (b > a && b > c) {
      if (a > c)
        cout << "CAB" << endl;
      else
        cout << "ACB" << endl;
    } else if (c > a && c > b) {
      if (a > b)
        cout << "BAC" << endl;
      else
        cout << "ABC" << endl;
    }
  } else
    cout << "Impossible" << endl;
  return 0;
}

```


### Prompt

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

Reca company makes monitors, the most popular of their models is AB999 with the screen size a × b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular with users. That's why the company wants to reduce monitor AB999 size so that its screen sides ratio becomes x: y, at the same time they want its total area to be maximal of all possible variants. Your task is to find the screen parameters of the reduced size model, or find out that such a reduction can't be performed.

Input

The first line of the input contains 4 integers — a, b, x and y (1 ≤ a, b, x, y ≤ 2·109).

Output

If the answer exists, output 2 positive integers — screen parameters of the reduced size model. Output 0 0 otherwise.

Examples

Input

800 600 4 3

Output

800 600

Input

1920 1200 16 9

Output

1920 1080

Input

1 1 1 2

Output

0 0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  long long int r;
  while (b != 0) r = a % b, a = b, b = r;
  return a;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int a, b, x, y;
  cin >> a >> b >> x >> y;
  long long int ans = 0;
  long long int g = gcd(x, y);
  x /= g;
  y /= g;
  long long int l = 1, r = 2000000000ll;
  for (int i = 0; i < 70; i++) {
    long long int m = l + (r - l) / 2;
    if (m == 119) {
    }
    if (x * m <= a && y * m <= b) {
      ans = m;
      l = m + 1;
    } else {
      r = m - 1;
    }
  }
  cout << x * ans << " " << y * ans << '\n';
  return 0;
}

```