### Prompt

Create a solution in Cpp for the following problem:

You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.

The boss battle consists of n turns. During each turn, you will get several cards. Each card has two parameters: its cost c_i and damage d_i. You may play some of your cards during each turn in some sequence (you choose the cards and the exact order they are played), as long as the total cost of the cards you play during the turn does not exceed 3. After playing some (possibly zero) cards, you end your turn, and all cards you didn't play are discarded. Note that you can use each card at most once.

Your character has also found an artifact that boosts the damage of some of your actions: every 10-th card you play deals double damage.

What is the maximum possible damage you can deal during n turns?

Input

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

Then n blocks of input follow, the i-th block representing the cards you get during the i-th turn.

Each block begins with a line containing one integer k_i (1 ≤ k_i ≤ 2 ⋅ 10^5) — the number of cards you get during i-th turn. Then k_i lines follow, each containing two integers c_j and d_j (1 ≤ c_j ≤ 3, 1 ≤ d_j ≤ 10^9) — the parameters of the corresponding card.

It is guaranteed that ∑ _{i = 1}^{n} k_i ≤ 2 ⋅ 10^5.

Output

Print one integer — the maximum damage you may deal.

Example

Input

5
3
1 6
1 7
1 5
2
1 4
1 3
3
1 10
3 5
2 3
3
1 15
2 4
1 10
1
1 100

Output

263

Note

In the example test the best course of action is as follows:

During the first turn, play all three cards in any order and deal 18 damage.

During the second turn, play both cards and deal 7 damage.

During the third turn, play the first and the third card and deal 13 damage.

During the fourth turn, play the first and the third card and deal 25 damage.

During the fifth turn, play the only card, which will deal double damage (200).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
long long int powmod(long long int a, long long int b) {
  long long int res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int nxt() {
  int x;
  scanf("%d", &x);
  return x;
}
void max_self(long long int &a, long long int b) { a = max(a, b); }
int main() {
  int n = nxt();
  vector<long long int> dp(10);
  for (int i = 0; i < 10; i++) dp[i] = LLONG_MIN;
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    vector<long long int> tmp = dp;
    int k = nxt();
    vector<int> a[3];
    long long int best = 0;
    for (int _ = 0; _ < k; _++) {
      int c = nxt(), d = nxt();
      c--;
      a[c].push_back(d);
      max_self(best, d);
    }
    for (int j = 0; j < 3; j++)
      sort((a[j]).begin(), (a[j]).end(), greater<int>());
    for (int j = 0; j < 10; j++) {
      max_self(tmp[(j + 1) % 10], dp[j] + best * (j == 9 ? 2 : 1));
    }
    if (a[0].size() >= 2) {
      long long int tt = 1LL * a[0][0] + a[0][1];
      long long int t2 = a[0][0];
      for (int j = 0; j < 10; j++) {
        max_self(tmp[(j + 2) % 10], dp[j] + tt + (j >= 8 ? t2 : 0));
      }
    }
    if (a[0].size() && a[1].size()) {
      long long int tt = 1LL * a[0][0] + a[1][0];
      long long int t2 = max(a[0][0], a[1][0]);
      for (int j = 0; j < 10; j++) {
        max_self(tmp[(j + 2) % 10], dp[j] + tt + (j >= 8 ? t2 : 0));
      }
    }
    if (a[0].size() >= 3) {
      long long int tt = 1LL * a[0][0] + a[0][1] + a[0][2];
      long long int t2 = a[0][0];
      for (int j = 0; j < 10; j++) {
        max_self(tmp[(j + 3) % 10], dp[j] + tt + (j >= 7 ? t2 : 0));
      }
    }
    dp = tmp;
  }
  printf("%lld\n", *max_element((dp).begin(), (dp).end()));
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

You're given Q queries of the form (L, R).

For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = ap.

Input

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

The next Q lines contains two integers L, R each (1 ≤ L ≤ R ≤ 1018).

Output

Output Q lines — the answers to the queries.

Example

Input

6
1 4
9 9
5 7
12 29
137 591
1 1000000

Output

2
1
0
3
17
1111

Note

In query one the suitable numbers are 1 and 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
set<long long> Set;
vector<long long> Se;
vector<long long>::iterator it;
long long M = 1000000000000000000;
int main() {
  ios::sync_with_stdio(false);
  int Q;
  cin >> Q;
  long double L, R, l, r;
  float A;
  long long S, lp, rp, p, a, g, b;
  for (int i = 2; i <= 60; i++) {
    g = 1;
    p = 2;
    while (g == 1) {
      a = p;
      A = p;
      for (int y = 0; y < i; y++) {
        a *= p;
        A *= p;
        if (a <= 0 || a > M || A / 1.01 > a) {
          g = 0;
        }
      }
      b = sqrt(a);
      if (g == 1 && b * b != a && (b - 1) * (b - 1) != a &&
          (b + 1) * (b + 1) != a) {
        if (Set.find(a) == Set.end()) {
          Set.insert(a);
          Se.push_back(a);
        }
      }
      p++;
    }
  }
  sort(Se.begin(), Se.end());
  for (int i = 0; i < Q; i++) {
    cin >> L >> R;
    S = 0;
    g = 1;
    l = sqrt(L);
    r = sqrt(R);
    lp = l;
    rp = r;
    if (lp * lp == L || (lp - 1) * (lp - 1) == L || (lp + 1) * (lp + 1) == L ||
        (lp + 2) * (lp + 2) == L || (lp - 2) * (lp - 2) == L) {
      S++;
      g = 0;
    }
    S += rp - lp;
    it = lower_bound(Se.begin(), Se.end(), L);
    a = it - Se.begin();
    it = lower_bound(Se.begin(), Se.end(), R);
    b = it - Se.begin();
    if (g == 1 && Se[b] == R) {
      S++;
    }
    S += b - a;
    cout << S << "\n";
  }
  return 0;
}

```


### Prompt

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

It's the turn of the year, so Bash wants to send presents to his friends. There are n cities in the Himalayan region and they are connected by m bidirectional roads. Bash is living in city s. Bash has exactly one friend in each of the other cities. Since Bash wants to surprise his friends, he decides to send a Pikachu to each of them. Since there may be some cities which are not reachable from Bash's city, he only sends a Pikachu to those friends who live in a city reachable from his own city. He also wants to send it to them as soon as possible.

He finds out the minimum time for each of his Pikachus to reach its destination city. Since he is a perfectionist, he informs all his friends with the time their gift will reach them. A Pikachu travels at a speed of 1 meters per second. His friends were excited to hear this and would be unhappy if their presents got delayed. Unfortunately Team Rocket is on the loose and they came to know of Bash's plan. They want to maximize the number of friends who are unhappy with Bash.

They do this by destroying exactly one of the other n - 1 cities. This implies that the friend residing in that city dies, so he is unhappy as well.

Note that if a city is destroyed, all the roads directly connected to the city are also destroyed and the Pikachu may be forced to take a longer alternate route.

Please also note that only friends that are waiting for a gift count as unhappy, even if they die.

Since Bash is already a legend, can you help Team Rocket this time and find out the maximum number of Bash's friends who can be made unhappy by destroying exactly one city.

Input

The first line contains three space separated integers n, m and s (2 ≤ n ≤ 2·105, <image>, 1 ≤ s ≤ n) — the number of cities and the number of roads in the Himalayan region and the city Bash lives in.

Each of the next m lines contain three space-separated integers u, v and w (1 ≤ u, v ≤ n, u ≠ v, 1 ≤ w ≤ 109) denoting that there exists a road between city u and city v of length w meters.

It is guaranteed that no road connects a city to itself and there are no two roads that connect the same pair of cities.

Output

Print a single integer, the answer to the problem.

Examples

Input

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

Output

2

Input

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

Output

4

Note

In the first sample, on destroying the city 2, the length of shortest distance between pairs of cities (3, 2) and (3, 4) will change. Hence the answer is 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pii = pair<ll, ll>;
const ll maxN = 201005;
const ll MAXLOG = 20;
struct BinaryLifting {
  ll BL[maxN][MAXLOG];
  ll D[maxN];
  void init(ll root) { D[root] = 1; }
  void insert(ll n, ll par) {
    D[n] = D[par] + 1;
    BL[n][0] = par;
    for (ll j = (1); j < ll(MAXLOG); j++) BL[n][j] = BL[BL[n][j - 1]][j - 1];
  }
  ll lift(ll node, ll h) {
    ll cnt = 0;
    while (h) {
      if (h & 1) node = BL[node][cnt];
      cnt++;
      h >>= 1;
    }
    return node;
  }
  int lca(int a, int b) {
    if (D[a] > D[b]) swap(a, b);
    for (ll i = (MAXLOG)-1; i >= ll(0); i--)
      if (D[BL[b][i]] >= D[a]) b = BL[b][i];
    if (a == b) return a;
    for (ll i = (MAXLOG)-1; i >= ll(0); i--)
      if (BL[a][i] != BL[b][i]) a = BL[a][i], b = BL[b][i];
    return BL[a][0];
  }
};
vector<pii> adj[maxN];
ll dist[maxN];
bool visited[maxN];
vector<ll> adj2[maxN];
ll indeg[maxN];
ll imdom[maxN];
vector<ll> adjdom[maxN];
BinaryLifting bl;
void domdfs(ll cur) {
  for (auto o : adj2[cur]) {
    if (imdom[o] == -1) {
      imdom[o] = cur;
    } else {
      imdom[o] = bl.lca(cur, imdom[o]);
    }
    indeg[o]--;
    if (!indeg[o]) {
      adjdom[imdom[o]].push_back(o);
      bl.insert(o, imdom[o]);
      domdfs(o);
    }
  }
}
ll coun[maxN];
void countc2(ll cur) {
  ll c = 1;
  for (auto o : adjdom[cur]) {
    countc2(o);
    c += coun[o];
  }
  coun[cur] = c;
}
ll countc(ll cur) {
  ll c = 1;
  for (auto o : adjdom[cur]) {
    c += countc(o);
  }
  return c;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m, s;
  cin >> n >> m >> s;
  for (ll i = (0); i < ll(m); i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    adj[a].emplace_back(b, c);
    adj[b].emplace_back(a, c);
  }
  memset(dist, 0x3f, sizeof(dist));
  dist[s] = 0;
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  pq.push(make_pair(0, s));
  while (!pq.empty()) {
    ll cur = pq.top().second;
    pq.pop();
    if (visited[cur]) continue;
    visited[cur] = true;
    for (auto &o : adj[cur]) {
      if (dist[o.first] > dist[cur] + o.second) {
        dist[o.first] = dist[cur] + o.second;
        pq.push(make_pair(dist[o.first], o.first));
      }
    }
  }
  for (ll i = (1); i < ll(n + 1); i++) {
    if (0) cout << i << ": " << dist[i] << endl;
    for (auto &o : adj[i]) {
      if (dist[i] + o.second == dist[o.first]) {
        adj2[i].push_back(o.first);
        indeg[o.first] += 1;
      }
    }
  }
  memset(imdom, -1, sizeof(imdom));
  bl.init(s);
  domdfs(s);
  ll res = 0;
  countc2(s);
  for (ll i = (1); i < ll(n + 1); i++) {
    if (i != s && dist[i] < (1ll << 50)) res = max(coun[i], res);
  }
  cout << res << endl;
}

```


### Prompt

Generate a CPP solution to the following problem:

A conglomerate consists of n companies. To make managing easier, their owners have decided to merge all companies into one. By law, it is only possible to merge two companies, so the owners plan to select two companies, merge them into one, and continue doing so until there is only one company left.

But anti-monopoly service forbids to merge companies if they suspect unfriendly absorption. The criterion they use is the difference in maximum salaries between two companies. Merging is allowed only if the maximum salaries are equal.

To fulfill the anti-monopoly requirements, the owners can change salaries in their companies before merging. But the labor union insists on two conditions: it is only allowed to increase salaries, moreover all the employees in one company must get the same increase.

Sure enough, the owners want to minimize the total increase of all salaries in all companies. Help them find the minimal possible increase that will allow them to merge companies into one.

Input

The first line contains a single integer n — the number of companies in the conglomerate (1 ≤ n ≤ 2 ⋅ 10^5). Each of the next n lines describes a company.

A company description start with an integer m_i — the number of its employees (1 ≤ m_i ≤ 2 ⋅ 10^5). Then m_i integers follow: the salaries of the employees. All salaries are positive and do not exceed 10^9.

The total number of employees in all companies does not exceed 2 ⋅ 10^5.

Output

Output a single integer — the minimal total increase of all employees that allows to merge all companies.

Example

Input

3
2 4 3
2 2 1
3 1 1 1

Output

13

Note

One of the optimal merging strategies is the following. First increase all salaries in the second company by 2, and merge the first and the second companies. Now the conglomerate consists of two companies with salaries [4, 3, 4, 3] and [1, 1, 1]. To merge them, increase the salaries in the second of those by 3. The total increase is 2 + 2 + 3 + 3 + 3 = 13.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10, mod = 1e9 + 7;
const long long inf = 1e18;
pair<int, int> p[maxn];
int mm;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, mx = 0;
    cin >> x;
    for (int j = 0; j < x; j++) {
      int y;
      cin >> y;
      mx = max(mx, y);
      mm = max(mm, y);
    }
    p[i] = {x, mx};
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += 1ll * p[i].first * (mm - p[i].second);
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

Drazil and Varda are the earthworm couple. They want to find a good place to bring up their children. They found a good ground containing nature hole. The hole contains many rooms, some pairs of rooms are connected by small tunnels such that earthworm can move between them.

Let's consider rooms and small tunnels as the vertices and edges in a graph. This graph is a tree. In the other words, any pair of vertices has an unique path between them.

Each room that is leaf in the graph is connected with a ground by a vertical tunnel. Here, leaf is a vertex that has only one outgoing edge in the graph.

Each room is large enough only to fit one earthworm living in it. Earthworm can't live in a tunnel.

Drazil and Varda have a plan to educate their children. They want all their children to do morning exercises immediately after getting up!

When the morning is coming, all earthworm children get up in the same time, then each of them chooses the farthest path to the ground for gathering with others (these children are lazy, so they all want to do exercises as late as possible).

Drazil and Varda want the difference between the time first earthworm child arrives outside and the time the last earthworm child arrives outside to be not larger than l (otherwise children will spread around the ground and it will be hard to keep them exercising together).

Also, The rooms that are occupied by their children should form a connected set. In the other words, for any two rooms that are occupied with earthworm children, all rooms that lie on the path between them should be occupied with earthworm children too.

How many children Drazil and Varda may have at most in order to satisfy all conditions above? Drazil and Varda want to know the answer for many different choices of l.

(Drazil and Varda don't live in the hole with their children)

Input

The first line contains one integer n denoting how many rooms there are in the hole (2 ≤ n ≤ 105).

Then there are n - 1 lines following. Each of these lines contains three integers x, y, v (1 ≤ x, y ≤ n, 1 ≤ v ≤ 106) denoting there is a small tunnel between room x and room y that takes time v to pass.

Suppose that the time for an earthworm to get out to the ground from any leaf room is the same.

The next line contains an integer q (1 ≤ q ≤ 50), denoting the number of different value of l you need to process.

The last line contains q numbers, each number denoting a value of l (1 ≤ l ≤ 1011).

Output

You should print q lines. Each line should contain one integer denoting the answer for a corresponding value of l.

Examples

Input

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

Output

1
3
3
3
5

Input

12
5 9 3
2 1 7
11 7 2
6 5 5
2 5 3
6 7 2
1 4 4
8 5 7
1 3 8
11 12 3
10 8 2
10
13 14 14 13 13 4 6 7 2 1

Output

10
10
10
10
10
3
3
5
2
1

Note

For the first sample the hole looks like the following. Rooms 1 and 5 are leaves, so they contain a vertical tunnel connecting them to the ground. The lengths of farthest path from rooms 1 – 5 to the ground are 12, 9, 7, 9, 12 respectively.

If l = 1, we may only choose any single room.

If l = 2..4, we may choose rooms 2, 3, and 4 as the answer.

If l = 5, we may choose all rooms.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, x, y, son[100005], q;
int fir[100005], nxt[200005], to[200005], cnt;
long long wi[200005], z, dp[100005][2], f[100005];
struct node {
  int id;
  long long val;
} c[100005];
int size[100005], fa[100005], Fa[100005];
long long read() {
  long long x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return x;
}
void dfs(int x, int fa) {
  for (int i = fir[x]; i; i = nxt[i]) {
    if (to[i] == fa) continue;
    dfs(to[i], x);
    if (dp[x][0] < dp[to[i]][0] + wi[i])
      dp[x][1] = dp[x][0], dp[x][0] = dp[to[i]][0] + wi[i], son[x] = to[i];
    else if (dp[x][1] < dp[to[i]][0] + wi[i])
      dp[x][1] = dp[to[i]][0] + wi[i];
  }
}
void Dfs(int x, int fa, long long W) {
  f[x] = max(dp[x][0], W);
  for (int i = fir[x]; i; i = nxt[i]) {
    if (to[i] == fa) continue;
    if (to[i] == son[x])
      Dfs(to[i], x, max(W, dp[x][1]) + wi[i]);
    else
      Dfs(to[i], x, max(W, dp[x][0]) + wi[i]);
  }
}
int cmp(node u, node v) { return u.val < v.val; }
void DFS(int x, int f) {
  Fa[x] = f;
  for (int i = fir[x]; i; i = nxt[i]) {
    if (to[i] == f) continue;
    DFS(to[i], x);
  }
}
int find(int x) {
  if (x == fa[x]) return x;
  return fa[x] = find(fa[x]);
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    x = read(), y = read(), z = read();
    to[++cnt] = y, nxt[cnt] = fir[x], fir[x] = cnt, wi[cnt] = z;
    to[++cnt] = x, nxt[cnt] = fir[y], fir[y] = cnt, wi[cnt] = z;
  }
  dfs(1, 0);
  Dfs(1, 0, 0);
  for (int i = 1; i <= n; i++) c[i] = (node){i, f[i]};
  sort(c + 1, c + n + 1, cmp);
  DFS(c[1].id, 0);
  q = read();
  for (int i = 1; i <= q; i++) {
    z = read();
    for (int i = 1; i <= n; i++) fa[i] = i;
    for (int i = 1; i <= n; i++) size[i] = 1;
    int r = n, ans = 0;
    for (int j = n; j >= 1; j--) {
      while (r && c[r].val - c[j].val > z) size[find(c[r].id)]--, r--;
      ans = max(ans, size[find(c[j].id)]);
      int u = find(c[j].id), v = find(Fa[c[j].id]);
      if (u != v) fa[u] = v, size[v] += size[u];
    }
    printf("%d\n", ans);
  }
  return 0;
}

```


### Prompt

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

n fishermen have just returned from a fishing vacation. The i-th fisherman has caught a fish of weight a_i.

Fishermen are going to show off the fish they caught to each other. To do so, they firstly choose an order in which they show their fish (each fisherman shows his fish exactly once, so, formally, the order of showing fish is a permutation of integers from 1 to n). Then they show the fish they caught according to the chosen order. When a fisherman shows his fish, he might either become happy, become sad, or stay content.

Suppose a fisherman shows a fish of weight x, and the maximum weight of a previously shown fish is y (y = 0 if that fisherman is the first to show his fish). Then:

  * if x ≥ 2y, the fisherman becomes happy;
  * if 2x ≤ y, the fisherman becomes sad;
  * if none of these two conditions is met, the fisherman stays content.

Let's call an order in which the fishermen show their fish emotional if, after all fishermen show their fish according to this order, each fisherman becomes either happy or sad. Calculate the number of emotional orders modulo 998244353.

Input

The first line contains one integer n (2 ≤ n ≤ 5000).

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).

Output

Print one integer — the number of emotional orders, taken modulo 998244353.

Examples

Input

4
1 1 4 9

Output

20

Input

4
4 3 2 1

Output

0

Input

3
4 2 1

Output

6

Input

8
42 1337 13 37 420 666 616 97

Output

19200

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int ri() {
  int x;
  if (scanf(" %d", &x) == EOF) return -1;
  return x;
}
long long int rl() {
  long long int x;
  if (cin >> x) return x;
  return -1;
}
string rs() {
  string s;
  if (cin >> s) return s;
  return "";
}
const long long int mod = 998244353;
struct SingleCase {
  int n;
  vector<int> v, halfIdx;
  vector<long long int> memo, Fact, Inv, Sum;
  long long int fact(int a) {
    if (a == 0) return 1;
    long long int& ret = Fact[a];
    if (ret != -1) return ret;
    return ret = a * fact(a - 1) % mod;
  }
  long long int inverse(int a) {
    long long int& ret = Inv[a];
    if (ret != -1) return ret;
    Inv[1] = 1;
    for (int i = 2; i < Inv.size(); ++i)
      Inv[i] = (mod - (mod / i) * Inv[mod % i] % mod) % mod;
    return ret;
  }
  long long int doit(int idx) {
    long long int& ret = memo[idx];
    if (ret != -1) return ret;
    ret = 1;
    int r = halfIdx[idx];
    ret = (ret + sum(r)) % mod;
    return ret;
  }
  long long int sum(int idx) {
    if (idx < 0) return 0;
    long long int& ret = Sum[idx];
    if (ret != -1) return ret;
    return ret =
               (sum(idx - 1) + inverse(n - 2 - halfIdx[idx]) * doit(idx)) % mod;
  }
  void computeHalfIdx() {
    halfIdx = vector<int>(n, -1);
    int x = -1, y = 0;
    while (y < n) {
      if (x + 1 < n && 2 * v[x + 1] <= v[y])
        x++;
      else {
        halfIdx[y] = x;
        y++;
      }
    }
  }
  bool solveCase() {
    n = ri();
    if (n < 0) return false;
    for (int i = 0; i < n; ++i) v.push_back(ri());
    sort(v.begin(), v.end());
    memo = vector<long long int>(n, -1);
    Fact = vector<long long int>(n, -1);
    Inv = vector<long long int>(n, -1);
    Sum = vector<long long int>(n, -1);
    computeHalfIdx();
    long long int ret;
    if (n >= 2 && 2 * v[n - 2] > v[n - 1])
      ret = 0;
    else
      ret = doit(n - 1) * fact(n - 1) % mod;
    cout << ret << endl;
    return true;
  }
};
int main() {
  while (SingleCase().solveCase()) {
  };
  return 0;
}

```


### Prompt

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

Yanagi is a high school student, and she is called "Hime" by her boyfriend who is a ninja fanboy. She likes picture books very much, so she often writes picture books by herself. She always asks you to make her picture book as an assistant. Today, you got asked to help her with making a comic.

She sometimes reads her picture books for children in kindergartens. Since Yanagi wants to let the children read, she wants to insert numbers to frames in order. Of course, such a task should be done by the assistant, you.

You want to do the task easily and fast, so you decide to write a program to output the order of reading frames based on the positions of the frames.

Write a program to print the number of order for each frame.

The comics in this problem satisfy the following rules.

The each comic is drawn on a sheet of rectangle paper. You can assume that the top side of the paper is on the x-axis. And you can assume that the right-hand side of the paper is on the y-axis. The positive direction of the x-axis is leftward. The positive direction of the y-axis is down direction. The paper is large enough to include all frames of the comic. In other words, no area in a frame is out of the paper.

The area of each frame is at least one. All sides of each frame are parallel to the x-axis or the y-axis. The frames can't overlap one another. However the frames may share the line of side.

You must decide the order to read  K , where  K  is a set of frames, with the following steps.

Step 1:You must choose an unread frame at the right-most position in K.
If you find such frames multiple, you must choose the frame at the top position among them.
If you can't find any unread frames, you stop reading K.
The frame you chose is "Starting Frame".
In step 1, you assume that the position of a frame is the top-right point of the frame.

Step 2:You should draw a line from the right-bottom point of "Starting Frame" to leftward horizontally.
If the line touch the right-hand side of other frame, you should stop drawing.
If the line is on the side of other frame, you should not stop drawing.
If the line touch the edge of paper, you should stop drawing.

Step 3:The set of the unread frames which are above the line ( they may be the bottom-side on the line ) drawn at Step 2 is L.
And you should read L.

Step 4: Go back to Step 1.

Constraints

0 < n < 10
(x0i != x1i) and (y0i != y1i)
0 ≤ x0i ,  y0i , x1i ,  y1i ≤ 500

Input

The input consists of multiple datasets. The last dataset is followed by a line containing one zero. You don't have to process this data.

Each datasets is in the following format.

n
x01 y01 x11 y11
x02 y02 x12 y12
....
x0n y0n x1n y1n

All numbers of the datasets are integer. They are separated by a space. The first line of a dataset contains one integer. n is the number of frames of the comic.  x0i ,  y0i ,  x1i ,  y1i are two non-neighboring points of  i  th frame in the line.

Output

Print n lines for each dataset. Print the number of order for ith frame in the ith line. And you should print blank line between the datasets.
Output format:

num1
num2
...
numi
...
numn

Example

Input

4
0 0 100 60
0 60 50 90
50 60 100 90
0 90 100 120
6
0 0 100 40
0 40 50 70
50 40 100 60
50 60 100 80
0 70 50 120
50 80 100 120
0

Output

1
2
3
4

1
2
4
5
3
6

### Response

```cpp
#include<bits/stdc++.h>
#define LL long long
#define REP(i, n) for(int i=0;i<(n);++i)
#define REPA(i, n) for(int i=1;i<(n);++i)
#define lp(i, n) for(int i=0;i<(n);++i)
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define DEKAI ((int)1e9+7)
#define ALL(x) (x).begin(), (x).end()
#define BIT(x) (1<<(x))
#define foreach(i, n) for(auto &i:(n))
using namespace std;
vector<vector<int>> ans;
#define NULI {{-1}}

void read(vector<vector<int>> l){
  if(l.empty()) return;
  int ri=1000,yi=1000,rit;
  lp(i,l.size()){
    if(ri>l[i][0]){
      ri=l[i][0];
      yi=l[i][1];
      rit=i;
    }
    else if(ri==l[i][0]){
      if(yi>l[i][1]){
      ri=l[i][0];
      yi=l[i][1];
      rit=i;
      }
    }
  }
  ans.push_back(l[rit]);
  int left=l[rit][2];
  int under=l[rit][3];
  l.erase(l.begin()+rit);
  int findtoright=1000;
  if(l.empty()) return;
  //cout<<"    "<<under<<endl;
  lp(i,l.size()){
    if(under>l[i][1]&&under<l[i][3]){
      //cout<<" "<<l[i][0]<<endl;
      findtoright=min(l[i][0],findtoright);
    }
  }
  //cout<<l.size()<<endl;
  //cout<<findtoright<<endl;
  vector<vector<int>> next;
  lp(i,l.size()){
    if(l[i][2]<=findtoright){
      if(l[i][3]<=under){
	next.push_back(l[i]);
	l.erase(l.begin()+i);
	i--;
      }
    }
  }
  if(!next.empty())
    read(next);
  if(!l.empty())
    read(l);
}

int main(){
  int check=0;
  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    if(check==1)cout<<endl;
    check=1;
    vector<vector<int>> l;
    lp(i,n){
      int a,b,c,d;
      cin>>a>>b>>c>>d;
      if(b>d) swap(b,d);
      if(a>c) swap(a,c);
      l.push_back({a,b,c,d});
    }
    ans.clear();
    read(l);
    lp(i,n){
      lp(j,n){
	if(ans[j]==l[i]){
	  cout<<j+1<<endl;
	  break;
	}
      }
    }
  }
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Suppose you have two strings s and t, and their length is equal. You may perform the following operation any number of times: choose two different characters c1 and c2, and replace every occurence of c1 in both strings with c2. Let's denote the distance between strings s and t as the minimum number of operations required to make these strings equal. For example, if s is abcd and t is ddcb, the distance between them is 2 — we may replace every occurence of a with b, so s becomes bbcd, and then we may replace every occurence of b with d, so both strings become ddcd.

You are given two strings S and T. For every substring of S consisting of |T| characters you have to determine the distance between this substring and T.

Input

The first line contains the string S, and the second — the string T (1 ≤ |T| ≤ |S| ≤ 125000). Both strings consist of lowercase Latin letters from a to f.

Output

Print |S| - |T| + 1 integers. The i-th of these integers must be equal to the distance between the substring of S beginning at i-th index with length |T| and the string T.

Example

Input

abcdefa
ddcb

Output

2 3 3 3

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
const int N = 1 << 18;
const int M = 125010;
struct base {
  double x, y;
  base() : x(0), y(0) {}
  base(const double &_x, const double &_y) : x(_x), y(_y) {}
};
inline base operator+(const base &a, const base &b) {
  return base(a.x + b.x, a.y + b.y);
}
inline base operator-(const base &a, const base &b) {
  return base(a.x - b.x, a.y - b.y);
}
inline base operator*(const base &a, const base &b) {
  return base(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
}
inline base conj(const base &a) { return base(a.x, -a.y); }
base w[N + 5];
int rev[N + 5];
inline void prepare(int n) {
  int L = __builtin_ctz(n);
  for (int i = 0; i < n; ++i) {
    rev[i] = rev[i >> 1] >> 1 | ((i & 1) << (L - 1));
    w[i] = base(cos(2 * PI * i / n), sin(2 * PI * i / n));
  }
}
inline void fft(base *a, int n) {
  for (int i = 0; i < n; ++i)
    if (i < rev[i]) swap(a[i], a[rev[i]]);
  for (int i = 2, h = n >> 1; i <= n; i <<= 1, h >>= 1) {
    for (int j = 0; j < n; j += i) {
      base *l = a + j, *r = a + j + (i >> 1), *p = w;
      for (int k = 0; k < (i >> 1); ++k) {
        base tmp = *r * *p;
        *r = *l - tmp, *l = *l + tmp;
        ++l, ++r, p += h;
      }
    }
  }
}
base A[6][N], B[6][N], C[N];
char S[N], T[N];
struct dsu {
  int p[6], sz;
  dsu() {
    for (int i = 0; i < 6; i++) p[i] = i;
    sz = 6;
  }
  int find(int u) { return u == p[u] ? u : p[u] = find(p[u]); }
  void Union(int u, int v) {
    u = find(u);
    v = find(v);
    if (u != v) {
      sz--, p[u] = v;
    }
  }
} DS[M];
int main(int argc, char const *argv[]) {
  scanf("%s", S);
  scanf("%s", T);
  int n = strlen(S), m = strlen(T), t = n + m, sz = 1;
  while (sz < t) sz <<= 1;
  prepare(sz);
  for (char &c : S) c -= 'a';
  for (char &c : T) c -= 'a';
  for (int a = 0; a < 6; a++) {
    for (int i = 0; i < n; i++) A[a][i] = base(S[i] == a, 0);
    fft(A[a], sz);
  }
  for (int b = 0; b < 6; b++) {
    for (int i = 0; i < m; i++) B[b][i] = base(T[m - i - 1] == b, 0);
    fft(B[b], sz);
  }
  for (int a = 0; a < 6; a++) {
    for (int b = 0; b < 6; b++)
      if (a != b) {
        for (int i = 0; i < sz; i++) C[i] = A[a][i] * B[b][i];
        reverse(C + 1, C + sz);
        fft(C, sz);
        for (int i = m - 1; i < n; i++) {
          int f = C[i].x + 0.5;
          if (f) DS[i].Union(a, b);
        }
      }
  }
  for (int i = m - 1; i < n; i++) {
    printf("%d ", 6 - DS[i].sz);
  }
  puts("");
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.

Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per coconut. Sasha has x chizhiks, Masha has y chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.

The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.

Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2 + 1 = 3 coconuts.

It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).

Input

The first line contains three integers x, y and z (0 ≤ x, y ≤ 10^{18}, 1 ≤ z ≤ 10^{18}) — the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.

Output

Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.

Examples

Input

5 4 3

Output

3 1

Input

6 8 2

Output

7 0

Note

The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 7 coconuts.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long x, y, z;
  cin >> x >> y >> z;
  long long ga = x / z;
  long long gba = x % z;
  long long gb = y / z;
  long long gbm = y % z;
  long long ex = (gbm + gba) / z;
  long long ex1 = (gbm + gba) % z;
  long long z1 = 0;
  cout << ga + gb + ex << " " << max(z1, min(gbm, gba) - ex1) << "\n";
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a connected undirected acyclic graph.

Ostap's tree now has n vertices. He wants to paint some vertices of the tree black such that from any vertex u there is at least one black vertex v at distance no more than k. Distance between two vertices of the tree is the minimum possible number of edges of the path between them.

As this number of ways to paint the tree can be large, Ostap wants you to compute it modulo 109 + 7. Two ways to paint the tree are considered different if there exists a vertex that is painted black in one way and is not painted in the other one.

Input

The first line of the input contains two integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ min(20, n - 1)) — the number of vertices in Ostap's tree and the maximum allowed distance to the nearest black vertex. Don't miss the unusual constraint for k.

Each of the next n - 1 lines contain two integers ui and vi (1 ≤ ui, vi ≤ n) — indices of vertices, connected by the i-th edge. It's guaranteed that given graph is a tree.

Output

Print one integer — the remainder of division of the number of ways to paint the tree by 1 000 000 007 (109 + 7).

Examples

Input

2 0
1 2

Output

1

Input

2 1
1 2

Output

3

Input

4 1
1 2
2 3
3 4

Output

9

Input

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

Output

91

Note

In the first sample, Ostap has to paint both vertices black.

In the second sample, it is enough to paint only one of two vertices, thus the answer is 3: Ostap can paint only vertex 1, only vertex 2, vertices 1 and 2 both.

In the third sample, the valid ways to paint vertices are: {1, 3}, {1, 4}, {2, 3}, {2, 4}, {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}, {1, 2, 3, 4}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int SIZE = 1e6 + 5;
const long long INF = 1LL << 60;
const double eps = 1e-4;
const double PI = 3.1415926535897932;
const int SZE = 1e6 + 1;
vector<int> adj[109], radj[109];
long long dp[109][42];
int n, m;
void dfs(int x) {
  for (int i : adj[x]) {
    dfs(i);
  }
  if (((int)(adj[x]).size()) == 0) {
    dp[x][m + 1] = dp[x][0] = 1;
    return;
  }
  long long dp2[((int)(adj[x]).size())][42][42];
  for (int i = 0; i < (((int)(adj[x]).size())); ++i) {
    for (int j = 0; j < (2 * m + 1); ++j) {
      for (int k = 0; k < (2 * m + 1); ++k) {
        dp2[i][j][k] = 0;
      }
    }
  }
  for (int i = 0; i < (2 * m + 1); ++i) dp2[0][i][i] = dp[adj[x][0]][i];
  for (int i = (1); i < (((int)(adj[x]).size())); ++i) {
    for (int j = 0; j < (2 * m + 1); ++j) {
      for (int k = (j); k < (2 * m + 1); ++k) {
        for (int l = 0; l < (2 * m + 1); ++l) {
          int nmn = min(j, l), nmx = max(k, l);
          dp2[i][nmn][nmx] =
              (dp2[i][nmn][nmx] + dp2[i - 1][j][k] * dp[adj[x][i]][l]) % MOD;
        }
      }
    }
  }
  for (int j = 0; j < (2 * m + 1); ++j) {
    for (int k = (j); k < (2 * m + 1); ++k) {
      int nx;
      if (j + k + 1 > 2 * m)
        nx = k + 1;
      else
        nx = j + 1;
      dp[x][0] = (dp[x][0] + dp2[((int)(adj[x]).size()) - 1][j][k]) % MOD;
      if (nx <= 2 * m) {
        dp[x][nx] = (dp[x][nx] + dp2[((int)(adj[x]).size()) - 1][j][k]) % MOD;
      }
    }
  }
}
void ft(int x, int p) {
  for (int i : radj[x]) {
    if (i == p) continue;
    adj[x].push_back(i);
    ft(i, x);
  }
}
int main() {
  scanf("%d%d", &(n), &(m));
  for (int i = 0; i < (n - 1); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    radj[a].push_back(b);
    radj[b].push_back(a);
  }
  ft(0, -1);
  dfs(0);
  long long ans = 0;
  for (int i = 0; i < (m + 1); ++i) {
    ans = (ans + dp[0][i]) % MOD;
  }
  printf("%I64d", ans);
}

```


### Prompt

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

Alice and Bob begin their day with a quick game. They first choose a starting number X0 ≥ 3 and try to reach one million by the process described below.

Alice goes first and then they take alternating turns. In the i-th turn, the player whose turn it is selects a prime number smaller than the current number, and announces the smallest multiple of this prime number that is not smaller than the current number.

Formally, he or she selects a prime p < Xi - 1 and then finds the minimum Xi ≥ Xi - 1 such that p divides Xi. Note that if the selected prime p already divides Xi - 1, then the number does not change.

Eve has witnessed the state of the game after two turns. Given X2, help her determine what is the smallest possible starting number X0. Note that the players don't necessarily play optimally. You should consider all possible game evolutions.

Input

The input contains a single integer X2 (4 ≤ X2 ≤ 106). It is guaranteed that the integer X2 is composite, that is, is not prime.

Output

Output a single integer — the minimum possible X0.

Examples

Input

14

Output

6

Input

20

Output

15

Input

8192

Output

8191

Note

In the first test, the smallest possible starting number is X0 = 6. One possible course of the game is as follows:

  * Alice picks prime 5 and announces X1 = 10
  * Bob picks prime 7 and announces X2 = 14.

In the second case, let X0 = 15.

  * Alice picks prime 2 and announces X1 = 16
  * Bob picks prime 5 and announces X2 = 20.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 10;
const int INF = 1e9 + 7;
int prime[MAX];
int main() {
  int x2;
  scanf("%d", &x2);
  for (int i = 2; i <= x2; i++) {
    if (!prime[i]) {
      for (int j = i * 2; j <= x2; j += i) prime[j] = i;
    }
  }
  int ans = INF;
  for (int i = x2 - prime[x2] + 1; i <= x2; i++) {
    if (prime[i] == 0) continue;
    ans = min(ans, i - prime[i] + 1);
  }
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Heidi and Doctor Who hopped out of the TARDIS and found themselves at EPFL in 2018. They were surrounded by stormtroopers and Darth Vader was approaching. Miraculously, they managed to escape to a nearby rebel base but the Doctor was very confused. Heidi reminded him that last year's HC2 theme was Star Wars. Now he understood, and he's ready to face the evils of the Empire!

The rebels have s spaceships, each with a certain attacking power a.

They want to send their spaceships to destroy the empire bases and steal enough gold and supplies in order to keep the rebellion alive.

The empire has b bases, each with a certain defensive power d, and a certain amount of gold g.

A spaceship can attack all the bases which have a defensive power less than or equal to its attacking power.

If a spaceship attacks a base, it steals all the gold in that base.

The rebels are still undecided which spaceship to send out first, so they asked for the Doctor's help. They would like to know, for each spaceship, the maximum amount of gold it can steal.

Input

The first line contains integers s and b (1 ≤ s, b ≤ 10^5), the number of spaceships and the number of bases, respectively.

The second line contains s integers a (0 ≤ a ≤ 10^9), the attacking power of each spaceship.

The next b lines contain integers d, g (0 ≤ d ≤ 10^9, 0 ≤ g ≤ 10^4), the defensive power and the gold of each base, respectively.

Output

Print s integers, the maximum amount of gold each spaceship can steal, in the same order as the spaceships are given in the input.

Example

Input

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

Output

1 9 11 9 11

Note

The first spaceship can only attack the first base.

The second spaceship can attack the first and third bases.

The third spaceship can attack the first, second and third bases.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int hashP = 239017;
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; i++) cin >> a[i].first, a[i].second = i;
  vector<pair<int, int> > b(m);
  for (auto& now : b) {
    cin >> now.first >> now.second;
  }
  vector<int> ans(n);
  sort(b.begin(), b.end());
  sort(a.begin(), a.end());
  long long j = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    for (j = j; j < m; j++) {
      if (b[j].first <= a[i].first)
        sum += b[j].second;
      else {
        break;
      }
    }
    ans[a[i].second] += sum;
  }
  for (auto now : ans) cout << now << " ";
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Holidays are coming up really soon. Rick realized that it's time to think about buying a traditional spruce tree. But Rick doesn't want real trees to get hurt so he decided to find some in an n × m matrix consisting of "*" and ".".

<image>

To find every spruce first let's define what a spruce in the matrix is. A set of matrix cells is called a spruce of height k with origin at point (x, y) if:

  * All cells in the set contain an "*".
  * For each 1 ≤ i ≤ k all cells with the row number x+i-1 and columns in range [y - i + 1, y + i - 1] must be a part of the set. All other cells cannot belong to the set.

Examples of correct and incorrect spruce trees:

<image>

Now Rick wants to know how many spruces his n × m matrix contains. Help Rick solve this problem.

Input

Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10).

The first line of each test case contains two integers n and m (1 ≤ n, m ≤ 500) — matrix size.

Next n lines of each test case contain m characters c_{i, j} — matrix contents. It is guaranteed that c_{i, j} is either a "." or an "*".

It is guaranteed that the sum of n ⋅ m over all test cases does not exceed 500^2 (∑ n ⋅ m ≤ 500^2).

Output

For each test case, print single integer — the total number of spruces in the matrix.

Example

Input

4
2 3
.*.
***
2 3
.*.
**.
4 5
.***.
*****
*****
*.*.*
5 7
..*.*..
.*****.
*******
.*****.
..*.*..

Output

5
3
23
34

Note

In the first test case the first spruce of height 2 has its origin at point (1, 2), the second spruce of height 1 has its origin at point (1, 2), the third spruce of height 1 has its origin at point (2, 1), the fourth spruce of height 1 has its origin at point (2, 2), the fifth spruce of height 1 has its origin at point (2, 3).

In the second test case the first spruce of height 1 has its origin at point (1, 2), the second spruce of height 1 has its origin at point (2, 1), the third spruce of height 1 has its origin at point (2, 2).

### Response

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

int main() {

     #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("outputw.txt", "w", stdout);
    #endif

    long long int t;
    cin>>t;
    while(t--)
    {
        int m,n;
        cin>>n>>m;
        char a[n][m];

        for(int i = 0;i<n;i++)
        {
            for(int j = 0;j<m;j++)
            {
                cin>>a[i][j];
            }
        }

        int left[n][m];
        for(int i = 0;i<n;i++)
        {
            int count = 0;
            for(int j = 0;j<m;j++)
            {
                if(a[i][j] == '*')
                {
                    count++;
                }
                else
                    count = 0;

                left[i][j] = count;
            }
        }
        int right[n][m];
        for(int i = 0;i<n;i++)
        {
            int count = 0;
            for(int j = m-1;j>=0;j--)
            {
                if(a[i][j] == '*')
                {
                    count++;
                }
                else
                    count = 0;

                right[i][j] = count;
            }
        }
        long long int ans = 0;

        for(int i = 0;i<n;i++)
        {
            for(int j = 0;j<m;j++)
            {
                if(a[i][j] == '*')
                {

                    for(int k = i,w = 1;k<n && a[k][j] == '*';k++,w++)
                    {

                        if(left[k][j] >= w && right[k][j] >= w)
                        {
                            ans++;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }

        cout<<ans<<"\n";
    }

    return 0;
}
```


### Prompt

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

It is now 125 years later, but humanity is still on the run from a humanoid-cyborg race determined to destroy it. Or perhaps we are getting some stories mixed up here... In any case, the fleet is now smaller. However, in a recent upgrade, all the navigation systems have been outfitted with higher-dimensional, linear-algebraic jump processors.

Now, in order to make a jump, a ship's captain needs to specify a subspace of the d-dimensional space in which the events are taking place. She does so by providing a generating set of vectors for that subspace.

Princess Heidi has received such a set from the captain of each of m ships. Again, she would like to group up those ships whose hyperspace jump subspaces are equal. To do so, she wants to assign a group number between 1 and m to each of the ships, so that two ships have the same group number if and only if their corresponding subspaces are equal (even though they might be given using different sets of vectors).

Help Heidi!

Input

The first line of the input contains two space-separated integers m and d (2 ≤ m ≤ 30 000, 1 ≤ d ≤ 5) – the number of ships and the dimension of the full underlying vector space, respectively. Next, the m subspaces are described, one after another. The i-th subspace, which corresponds to the i-th ship, is described as follows:

The first line contains one integer ki (1 ≤ ki ≤ d). Then ki lines follow, the j-th of them describing the j-th vector sent by the i-th ship. Each of the j lines consists of d space-separated integers aj, j = 1, ..., d, that describe the vector <image>; it holds that |aj| ≤ 250. The i-th subspace is the linear span of these ki vectors.

Output

Output m space-separated integers g1, ..., gm, where <image> denotes the group number assigned to the i-th ship. That is, for any 1 ≤ i < j ≤ m, the following should hold: gi = gj if and only if the i-th and the j-th subspaces are equal. In addition, the sequence (g1, g2, ..., gm) should be lexicographically minimal among all sequences with that property.

Example

Input

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

Output

1 2 2 2 3 3 3 1

Note

In the sample testcase, the first and the last subspace are equal, subspaces 2 to 4 are equal, and subspaces 5 to 7 are equal.

Recall that two subspaces, one given as the span of vectors <image> and another given as the span of vectors <image>, are equal if each vector vi can be written as a linear combination of vectors w1, ..., wk (that is, there exist coefficients <image> such that vi = α1w1 + ... + αkwk) and, similarly, each vector wi can be written as a linear combination of vectors v1, ..., vn.

Recall that a sequence (g1, g2, ..., gm) is lexicographically smaller than a sequence (h1, h2, ..., hm) if there exists an index i, 1 ≤ i ≤ m, such that gi < hi and gj = hj for all j < i.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int pow_mod(long long x, long long n, int M) {
  long long ans = 1;
  for (; n; n >>= 1) {
    if (n & 1) ans = ans * x % M;
    x = x * x % M;
  }
  return ans;
}
int inv_mod(int x, int p) { return pow_mod(x, p - 2, p); }
vector<vector<int>> f(vector<vector<int>> a, int MOD) {
  int N = a.size(), M = a[0].size();
  int k = 0;
  for (int j = 0; j < M; j++) {
    int i0;
    for (i0 = k; i0 < N && !a[i0][j]; i0++)
      ;
    if (i0 == N) continue;
    swap(a[k], a[i0]);
    int x = inv_mod(a[k][j], MOD);
    for (int j = 0; j < M; j++) a[k][j] = (long long)a[k][j] * x % MOD;
    for (int i = 0; i < N; i++)
      if (i != k) {
        int x = a[i][j];
        for (int j = 0; j < M; j++)
          a[i][j] = (a[i][j] - (long long)a[k][j] * x) % MOD;
      }
    k++;
  }
  while (N) {
    bool ok = true;
    for (int j = 0; j < M; j++)
      if (a[N - 1][j]) ok = false;
    if (ok)
      N--, a.pop_back();
    else
      break;
  }
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) a[i][j] = (a[i][j] + MOD) % MOD;
  return a;
}
int main() {
  int T, M;
  cin >> T >> M;
  map<pair<vector<vector<int>>, vector<vector<int>>>, vector<int>> mp;
  for (int t = 0; t < T; t++) {
    int N;
    scanf("%d", &N);
    vector<vector<int>> a(N, vector<int>(M));
    for (int i = 0; i < N; i++)
      for (int j = 0; j < M; j++) scanf("%d", &a[i][j]);
    vector<vector<int>> b = f(a, 1e9 + 7);
    vector<vector<int>> c = f(a, 1e9 + 9);
    mp[{b, c}].push_back(t);
  }
  vector<int> ans(T);
  int K = 0;
  for (auto z : mp) {
    for (int t : z.second) ans[t] = K;
    K++;
  }
  vector<int> mi(K, INT_MAX);
  for (int t = 0; t < T; t++) mi[ans[t]] = min(mi[ans[t]], t);
  vector<pair<int, int>> v(K);
  for (int k = 0; k < K; k++) v[k] = {mi[k], k};
  sort(v.begin(), v.end());
  for (int k = 0; k < K; k++) mi[v[k].second] = k;
  for (int t = 0; t < T; t++) printf("%d ", mi[ans[t]] + 1);
  cout << endl;
}

```


### Prompt

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

The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.

The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array a, only if array a can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements.

Help the Little Elephant, determine if he could have accidentally changed the array a, sorted by non-decreasing, himself.

Input

The first line contains a single integer n (2 ≤ n ≤ 105) — the size of array a. The next line contains n positive integers, separated by single spaces and not exceeding 109, — array a.

Note that the elements of the array are not necessarily distinct numbers.

Output

In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise.

Examples

Input

2
1 2

Output

YES

Input

3
3 2 1

Output

YES

Input

4
4 3 2 1

Output

NO

Note

In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES".

In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES".

In the third sample we can't sort the array in more than one swap operation, so the answer is "NO".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int N;
int A[100001];
pair<int, int> B[100001];
bool comp(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) return a.first < b.first;
  return a.second < b.second;
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
    B[i].first = A[i];
    B[i].second = i;
  }
  sort(B + 1, B + N + 1, comp);
  int cnt = 0;
  for (int i = 1; i <= N; i++)
    if (A[i] != B[i].first) cnt++;
  if (cnt == 0 || cnt == 2)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them.

Limak is a little polar bear. He lives in a tree that consists of n vertices, numbered 1 through n.

Limak recently learned how to jump. He can jump from a vertex to any vertex within distance at most k.

For a pair of vertices (s, t) we define f(s, t) as the minimum number of jumps Limak needs to get from s to t. Your task is to find the sum of f(s, t) over all pairs of vertices (s, t) such that s < t.

Input

The first line of the input contains two integers n and k (2 ≤ n ≤ 200 000, 1 ≤ k ≤ 5) — the number of vertices in the tree and the maximum allowed jump distance respectively.

The next n - 1 lines describe edges in the tree. The i-th of those lines contains two integers ai and bi (1 ≤ ai, bi ≤ n) — the indices on vertices connected with i-th edge.

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

Output

Print one integer, denoting the sum of f(s, t) over all pairs of vertices (s, t) such that s < t.

Examples

Input

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

Output

20

Input

13 3
1 2
3 2
4 2
5 2
3 6
10 6
6 7
6 13
5 8
5 9
9 11
11 12

Output

114

Input

3 5
2 1
3 1

Output

3

Note

In the first sample, the given tree has 6 vertices and it's displayed on the drawing below. Limak can jump to any vertex within distance at most 2. For example, from the vertex 5 he can jump to any of vertices: 1, 2 and 4 (well, he can also jump to the vertex 5 itself).

<image>

There are <image> pairs of vertices (s, t) such that s < t. For 5 of those pairs Limak would need two jumps: (1, 6), (3, 4), (3, 5), (3, 6), (5, 6). For other 10 pairs one jump is enough. So, the answer is 5·2 + 10·1 = 20.

In the third sample, Limak can jump between every two vertices directly. There are 3 pairs of vertices (s < t), so the answer is 3·1 = 3.

### Response

```cpp
#include <bits/stdc++.h>
struct link {
  link *nxt;
  int p;
};
const int N = 200000 + 10, K = 5 + 2;
int n, k;
long long ans, f[N][K], g[N];
link poool[N << 1], *pool = poool, *head[N];
inline void connect(int u, int v) {
  pool->p = v, pool->nxt = head[u], head[u] = pool++;
}
inline void dplink(int p, int s) {
  for (int i = 0; i < k - 1; ++i) f[p][i + 1] += f[s][i];
  g[p] += g[s] + f[s][k - 1], f[p][0] += f[s][k - 1];
}
inline void undplink(int p, int s) {
  for (int i = 0; i < k - 1; ++i) f[p][i + 1] -= f[s][i];
  g[p] -= g[s] + f[s][k - 1], f[p][0] -= f[s][k - 1];
}
inline void revlink(int p, int s) { undplink(p, s), dplink(s, p); }
void dfs1(int p, int fa) {
  f[p][0] = 1;
  for (link *e = head[p]; e; e = e->nxt)
    if (e->p != fa) dfs1(e->p, p), dplink(p, e->p);
}
void dfs2(int p, int fa) {
  for (int i = 1; i < k; ++i) ans += f[p][i];
  ans += g[p];
  for (link *e = head[p]; e; e = e->nxt)
    if (e->p != fa) revlink(p, e->p), dfs2(e->p, p), revlink(e->p, p);
}
int main(void) {
  scanf("%d %d", &n, &k);
  for (int i = 2, u, v; i <= n; ++i)
    scanf("%d %d", &u, &v), connect(u, v), connect(v, u);
  dfs1(1, 0), dfs2(1, 0), printf("%lld\n", ans >> 1);
}

```


### Prompt

Create a solution in cpp for the following problem:

The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.

Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.

If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.

Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.

Input

The first line of input will contain an integer n (1 ≤ n ≤ 105), the number of events. The next line will contain n space-separated integers.

If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.

Output

Print a single integer, the number of crimes which will go untreated.

Examples

Input

3
-1 -1 1

Output

2

Input

8
1 -1 1 -1 -1 1 1 1

Output

1

Input

11
-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1

Output

8

Note

Lets consider the second example:

  1. Firstly one person is hired.
  2. Then crime appears, the last hired person will investigate this crime.
  3. One more person is hired.
  4. One more crime appears, the last hired person will investigate this crime.
  5. Crime appears. There is no free policeman at the time, so this crime will go untreated.
  6. One more person is hired.
  7. One more person is hired.
  8. One more person is hired.

The answer is one, as one crime (on step 5) will go untreated.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, sum = 0, c = 0;
  cin >> n;
  while (n--) {
    int temp;
    cin >> temp;
    if (sum >= abs(temp) && temp < 0) {
      sum += temp;
    } else if (temp > 0) {
      sum += temp;
    } else {
      c++;
    }
  }
  cout << c;
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight <image> (where <image> is the [bitwise-xor operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)). Can you find the weight of the minimum spanning tree of that graph?

You can read about complete graphs in <https://en.wikipedia.org/wiki/Complete_graph>

You can read about the minimum spanning tree in <https://en.wikipedia.org/wiki/Minimum_spanning_tree>

The weight of the minimum spanning tree is the sum of the weights on the edges included in it.

Input

The only line contains an integer n (2 ≤ n ≤ 1012), the number of vertices in the graph.

Output

The only line contains an integer x, the weight of the graph's minimum spanning tree.

Example

Input

4

Output

4

Note

In the first sample: <image> The weight of the minimum spanning tree is 1+2+1=4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int inf = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
const double PI = acos(-1);
long long int i, j, k;
void solve(void);
inline bool equal(double a, double b) { return fabs(a - b) < eps; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int t = 1;
  while (t--) solve();
  return 0;
}
void solve() {
  long long int n;
  cin >> n;
  long long int sum = 0;
  i = 1;
  while (n > 1) {
    sum += i * (n / 2);
    i *= 2;
    n = (n / 2) + (n % 2 > 0);
  }
  cout << sum << '\n';
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Petya and Vasya arranged a game. The game runs by the following rules. Players have a directed graph consisting of n vertices and m edges. One of the vertices contains a chip. Initially the chip is located at vertex s. Players take turns moving the chip along some edge of the graph. Petya goes first. Player who can't move the chip loses. If the game lasts for 106 turns the draw is announced.

Vasya was performing big laboratory work in "Spelling and parts of speech" at night before the game, so he fell asleep at the very beginning of the game. Petya decided to take the advantage of this situation and make both Petya's and Vasya's moves.

Your task is to help Petya find out if he can win the game or at least draw a tie.

Input

The first line of input contain two integers n and m — the number of vertices and the number of edges in the graph (2 ≤ n ≤ 105, 0 ≤ m ≤ 2·105).

The next n lines contain the information about edges of the graph. i-th line (1 ≤ i ≤ n) contains nonnegative integer ci — number of vertices such that there is an edge from i to these vertices and ci distinct integers ai, j — indices of these vertices (1 ≤ ai, j ≤ n, ai, j ≠ i).

It is guaranteed that the total sum of ci equals to m.

The next line contains index of vertex s — the initial position of the chip (1 ≤ s ≤ n).

Output

If Petya can win print «Win» in the first line. In the next line print numbers v1, v2, ..., vk (1 ≤ k ≤ 106) — the sequence of vertices Petya should visit for the winning. Vertex v1 should coincide with s. For i = 1... k - 1 there should be an edge from vi to vi + 1 in the graph. There must be no possible move from vertex vk. The sequence should be such that Petya wins the game.

If Petya can't win but can draw a tie, print «Draw» in the only line. Otherwise print «Lose».

Examples

Input

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

Output

Win
1 2 4 5

Input

3 2
1 3
1 1
0
2

Output

Lose

Input

2 2
1 2
1 1
1

Output

Draw

Note

In the first example the graph is the following:

<image>

Initially the chip is located at vertex 1. In the first move Petya moves the chip to vertex 2, after that he moves it to vertex 4 for Vasya. After that he moves to vertex 5. Now it is Vasya's turn and there is no possible move, so Petya wins.

In the second example the graph is the following:

<image>

Initially the chip is located at vertex 2. The only possible Petya's move is to go to vertex 1. After that he has to go to 3 for Vasya. Now it's Petya's turn but he has no possible move, so Petya loses.

In the third example the graph is the following:

<image>

Petya can't win, but he can move along the cycle, so the players will draw a tie.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a, m, s, c, n, vp[100005][2], visitado[100005], camino[200005];
vector<int> G[100005];
void dfs(int v, int p, int id) {
  if (vp[v][p]) return;
  if (!G[v].size() && p) {
    cout << "Win" << endl;
    for (int i = 0; i < id; ++i) {
      cout << camino[i] << endl;
    }
    cout << v;
    exit(0);
  }
  vp[v][p] = 1;
  camino[id] = v;
  for (auto x : G[v]) {
    dfs(x, !p, id + 1);
  }
}
void ciclo(int v) {
  if (visitado[v]) {
    cout << "Draw";
    exit(0);
  }
  visitado[v] = 1;
  int l = G[v].size();
  for (int i = 0; i < l; i++) {
    ciclo(G[v][i]);
  }
  visitado[v] = 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    for (scanf("%d", &c); c--;) {
      scanf("%d", &a);
      G[i].push_back(a);
    }
  scanf("%d", &s);
  c = 0;
  dfs(s, 0, 0);
  ciclo(s);
  cout << "Lose" << endl;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

After a hard-working week Polycarp prefers to have fun. Polycarp's favorite entertainment is drawing snakes. He takes a rectangular checkered sheet of paper of size n × m (where n is the number of rows, m is the number of columns) and starts to draw snakes in cells.

Polycarp draws snakes with lowercase Latin letters. He always draws the first snake with the symbol 'a', the second snake with the symbol 'b', the third snake with the symbol 'c' and so on. All snakes have their own unique symbol. There are only 26 letters in the Latin alphabet, Polycarp is very tired and he doesn't want to invent new symbols, so the total number of drawn snakes doesn't exceed 26.

Since by the end of the week Polycarp is very tired, he draws snakes as straight lines without bends. So each snake is positioned either vertically or horizontally. Width of any snake equals 1, i.e. each snake has size either 1 × l or l × 1, where l is snake's length. Note that snakes can't bend.

When Polycarp draws a new snake, he can use already occupied cells for drawing the snake. In this situation, he draws the snake "over the top" and overwrites the previous value in the cell.

Recently when Polycarp was at work he found a checkered sheet of paper with Latin letters. He wants to know if it is possible to get this sheet of paper from an empty sheet by drawing some snakes according to the rules described above. If it is possible, he is interested in a way to draw snakes.

Input

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

The first line of the test case description contains two integers n, m (1 ≤ n,m ≤ 2000) — length and width of the checkered sheet of paper respectively.

Next n lines of test case description contain m symbols, which are responsible for the content of the corresponding cell on the sheet. It can be either lowercase Latin letter or symbol dot ('.'), which stands for an empty cell.

It is guaranteed that the total area of all sheets in one test doesn't exceed 4⋅10^6.

Output

Print the answer for each test case in the input.

In the first line of the output for a test case print YES if it is possible to draw snakes, so that you can get a sheet of paper from the input. If it is impossible, print NO.

If the answer to this question is positive, then print the way to draw snakes in the following format. In the next line print one integer k (0 ≤ k ≤ 26) — number of snakes. Then print k lines, in each line print four integers r_{1,i}, c_{1,i}, r_{2,i} and c_{2,i} — coordinates of extreme cells for the i-th snake (1 ≤ r_{1,i}, r_{2,i} ≤ n, 1 ≤ c_{1,i}, c_{2,i} ≤ m). Snakes should be printed in order of their drawing. If there are multiple solutions, you are allowed to print any of them.

Note that Polycarp starts drawing of snakes with an empty sheet of paper.

Examples

Input

1
5 6
...a..
..bbb.
...a..
.cccc.
...a..

Output

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

Input

3
3 3
...
...
...
4 4
..c.
adda
bbcb
....
3 5
..b..
aaaaa
..b..

Output

YES
0
YES
4
2 1 2 4
3 1 3 4
1 3 3 3
2 2 2 3
NO

Input

2
3 3
...
.a.
...
2 2
bb
cc

Output

YES
1
2 2 2 2
YES
3
1 1 1 2
1 1 1 2
2 1 2 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 2010;
char g[N][N], res[N][N];
int r1[30], r2[30], c1[30], c2[30];
int n, m;
int main() {
  int T;
  for (scanf("%d", &T); T--;) {
    int R, C;
    scanf("%d%d", &R, &C);
    for (int i = 0; i < R; i++) scanf("%s", g[i]);
    memset(r1, 0xbf, sizeof r1);
    memset(r2, 0x3f, sizeof r2);
    memset(c1, 0x3f, sizeof c1);
    memset(c2, 0xbf, sizeof c2);
    for (int i = 0; i < R; i++)
      for (int j = 0; j < C; j++)
        if (g[i][j] != '.') {
          int k = g[i][j] - 'a';
          r1[k] = max(r1[k], i);
          c1[k] = min(c1[k], i);
          r2[k] = min(r2[k], j);
          c2[k] = max(c2[k], j);
        }
    int ans1 = 0;
    for (int i = 0; i < 26; i++) {
      if (r1[i] >= 0) ans1 = i + 1;
    }
    for (int i = ans1 - 1; i >= 0; i--) {
      if (r1[i] < 0) {
        r1[i] = r1[i + 1];
        r2[i] = r2[i + 1];
        c1[i] = c1[i + 1];
        c2[i] = c2[i + 1];
      }
    }
    bool ok = 1;
    for (int i = 0; i < R; i++)
      for (int j = 0; j < C; j++) res[i][j] = '.';
    for (int i = 0; ok && i < ans1; i++) {
      if (r1[i] == c1[i]) {
        for (int j = r2[i]; j <= c2[i]; j++) res[r1[i]][j] = i + 'a';
      } else if (r2[i] == c2[i]) {
        for (int j = c1[i]; j <= r1[i]; j++) res[j][r2[i]] = i + 'a';
      } else
        ok = 0;
    }
    for (int i = 0; i < R && ok; i++)
      for (int j = 0; j < C && ok; j++)
        if (res[i][j] != g[i][j]) ok = 0;
    if (!ok) {
      puts("NO");
      continue;
    }
    printf("YES\n%d\n", ans1);
    for (int i = 0; i < ans1; i++)
      printf("%d %d %d %d\n", r1[i] + 1, r2[i] + 1, c1[i] + 1, c2[i] + 1);
  }
  return 0;
}

```


### Prompt

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

In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.

In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.

The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.

Input

The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.

The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).

Output

Print a single number — the sought number of days.

Examples

Input

4
10 3 5 10

Output

5

Input

5
10 2 8 3 5

Output

5

Note

In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.

In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int arr1[100007];
int arr2[100007];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr1[i];
    arr2[i] = arr1[i];
  }
  sort(arr1, arr1 + n);
  for (int i = 0; i < n; i++) {
    int mini = arr1[i];
    for (int j = 0; j < n; j++)
      if (arr2[j] == mini) arr2[j] = -1;
    for (int j = 0; j < n; j++)
      if ((arr2[j] == -1 && arr2[j + 1] == -1) || (arr2[n - 1] == -1) ||
          (arr2[0] == -1)) {
        cout << mini << endl;
        return 0;
      }
  }
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

A renowned abstract artist Sasha, drawing inspiration from nowhere, decided to paint a picture entitled "Special Olympics". He justly thought that, if the regular Olympic games have five rings, then the Special ones will do with exactly two rings just fine.

Let us remind you that a ring is a region located between two concentric circles with radii r and R (r < R). These radii are called internal and external, respectively. Concentric circles are circles with centers located at the same point.

Soon a white canvas, which can be considered as an infinite Cartesian plane, had two perfect rings, painted with solid black paint. As Sasha is very impulsive, the rings could have different radii and sizes, they intersect and overlap with each other in any way. We know only one thing for sure: the centers of the pair of rings are not the same.

When Sasha got tired and fell into a deep sleep, a girl called Ilona came into the room and wanted to cut a circle for the sake of good memories. To make the circle beautiful, she decided to cut along the contour.

We'll consider a contour to be a continuous closed line through which there is transition from one color to another (see notes for clarification). If the contour takes the form of a circle, then the result will be cutting out a circle, which Iona wants.

But the girl's inquisitive mathematical mind does not rest: how many ways are there to cut a circle out of the canvas?

Input

The input contains two lines.

Each line has four space-separated integers xi, yi, ri, Ri, that describe the i-th ring; xi and yi are coordinates of the ring's center, ri and Ri are the internal and external radii of the ring correspondingly ( - 100 ≤ xi, yi ≤ 100; 1 ≤ ri < Ri ≤ 100).

It is guaranteed that the centers of the rings do not coinside.

Output

A single integer — the number of ways to cut out a circle from the canvas.

Examples

Input

60 60 45 55
80 80 8 32

Output

1

Input

60 60 45 55
80 60 15 25

Output

4

Input

50 50 35 45
90 50 35 45

Output

0

Note

Figures for test samples are given below. The possible cuts are marked with red dotted line.

<image> <image> <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
double d;
int check(double a, double b, double c) {
  if (a + c <= d || a + d <= b || d + c <= a)
    return 1;
  else
    return 0;
}
int main() {
  double x1, y1, r1, R1;
  cin >> x1 >> y1 >> r1 >> R1;
  double x2, y2, r2, R2;
  cin >> x2 >> y2 >> r2 >> R2;
  d = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  int ans = 0;
  ans = check(r1, r2, R2) + check(R1, r2, R2) + check(r2, r1, R1) +
        check(R2, r1, R1);
  cout << ans;
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Give you N cards. Only one natural number is written on each card. However, the same number is never written.

From now on, as a question, I will say an appropriate natural number. Please answer the largest remainder you get when you divide the number on the card you have by the number I said.

For example, suppose you have three cards with 9, 3, and 8, respectively. If I say "4", find the remainder of 9 and 3 and 8 divided by 4, respectively. The remainders are 1, 3, and 0, respectively, but the largest remainder is 3, so 3 is the correct answer.

Let's get started. e? Is it hard to have a lot of cards? It can not be helped. Now let's use the computer to find the largest remainder. Create a program that finds the largest of the remainders of the number on the card divided by the number asked. Ask the question many times, not just once, but never ask the same number more than once.

input

The input consists of one dataset. Input data is given in the following format.

N Q
c1 c2 ... cN
q1
q2
::
qQ

The number of cards N (2 ≤ N ≤ 300000) and the number of questions Q (2 ≤ Q ≤ 100000) are given in the first line, separated by one space, and the number ci (1 ≤ 100000) written on the card in the second line. ci ≤ 300000) is given with one space delimiter. The following Q line is given the number qi (1 ≤ qi ≤ 300000) given as a question.

output

Output the maximum remainder on one line for each question.

Example

Input

3 3
9 3 8
4
6
5

Output

3
3
4

### Response

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

int main()
{
    int N, Q;
    cin >> N >> Q;

    set<int> S;
    rep(i, N){
        int c;
        cin >> c;
        S.insert(c);
    }

    rep(i, Q){
        int q;
        cin >> q;

        int ans = 0;
        for(int j=0; j*q <= 300000+q; ++j){
            auto itr = S.lower_bound(j*q);
            if(itr != S.begin()){
                --itr;
                ans = max(ans, *itr % q);
            }
        }

        cout << ans << endl;
    }
}
```


### Prompt

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

Skyscraper "MinatoHarukas"

Mr. Port plans to start a new business renting one or more floors of the new skyscraper with one giga floors, MinatoHarukas. He wants to rent as many vertically adjacent floors as possible, because he wants to show advertisement on as many vertically adjacent windows as possible. The rent for one floor is proportional to the floor number, that is, the rent per month for the n-th floor is n times that of the first floor. Here, the ground floor is called the first floor in the American style, and basement floors are out of consideration for the renting. In order to help Mr. Port, you should write a program that computes the vertically adjacent floors satisfying his requirement and whose total rental cost per month is exactly equal to his budget.

For example, when his budget is 15 units, with one unit being the rent of the first floor, there are four possible rent plans, 1+2+3+4+5, 4+5+6, 7+8, and 15. For all of them, the sums are equal to 15. Of course in this example the rent of maximal number of the floors is that of 1+2+3+4+5, that is, the rent from the first floor to the fifth floor.

Input

The input consists of multiple datasets, each in the following format.

> b
>

A dataset consists of one line, the budget of Mr. Port b as multiples of the rent of the first floor. b  is a positive integer satisfying 1 < b < 109.

The end of the input is indicated by a line containing a zero. The number of datasets does not exceed 1000.

Output

For each dataset, output a single line containing two positive integers representing the plan with the maximal number of vertically adjacent floors with its rent price exactly equal to the budget of Mr. Port. The first should be the lowest floor number and the second should be the number of floors.

Sample Input

15
16
2
3
9699690
223092870
847288609
900660121
987698769
999999999
0

Output for the Sample Input

1 5
16 1
2 1
1 2
16 4389
129 20995
4112949 206
15006 30011
46887 17718
163837 5994

Example

Input

15
16
2
3
9699690
223092870
847288609
900660121
987698769
999999999
0

Output

1 5
16 1
2 1
1 2
16 4389
129 20995
4112949 206
15006 30011
46887 17718
163837 5994

### Response

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    LL b;
    cin >> b;
    if(b==0) return 0;
    pair<LL,LL> ans={0,-1};
    repp(i,1,sqrt(2*b)+1){
      if(2*b%i==0){
        if((2*b/i-i-1)>=0&&(2*b/i-i-1)%2==0) ans=max(ans,{i,(2*b/i-i-1)/2});
      }
    }
    cout << ans.second+1 SP ans.first << endl;
  }
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Using the given four integers from 1 to 9, we create an expression that gives an answer of 10. When you enter four integers a, b, c, d, write a program that outputs an expression that gives an answer of 10 according to the following conditions. Also, if there are multiple answers, only the first answer found will be output. If there is no answer, output 0.

* Use only addition (+), subtraction (-), and multiplication (*) as operators. Do not use division (/). You can use three operators.
* You must use all four numbers.
* You can freely change the order of the four numbers.
* You can use parentheses. You can use up to 3 sets (6) of parentheses.

Input

Given multiple datasets. The format of each dataset is as follows:

a b c d

Input ends with four 0s. The number of datasets does not exceed 40.

Output

For each dataset, combine the given four integers with the above arithmetic symbols and parentheses to output an expression or 0 with a value of 10 on one line. The expression string must not exceed 1024 characters.

Example

Input

8 7 9 9
4 4 4 4
5 5 7 5
0 0 0 0

Output

((9 * (9 - 7)) - 8)
0
((7 * 5) - (5 * 5))

### Response

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

using namespace std;

//c -> 1,+ 2,-, 3,*
int calc(int a,int b,int c){
	switch(c){
		case 1:return a+b;
		case 2:return a-b;
		case 3:return a*b;
	}
	return 0;
}
char n2c(int n){
	switch(n){
		case 1: return '+';
		case 2: return '-';
		case 3: return '*';
	}
}

bool comb(int a[], int n){
	if(n == 3){
		for(int i = 1; i <= 3; i++){
			for(int j = 1; j <= 3; j++){
				for(int k = 1; k <= 3; k++){
					if(calc(calc(a[0],a[1],i),calc(a[2],a[3],j),k) == 10){
						cout<<'('<<a[0]<<n2c(i)<<a[1]<<')'<<n2c(k)<<'('<<a[2]<<n2c(j)<<a[3]<<')'<<endl;
						return true;
					}
					if(calc(a[0],calc(a[1],calc(a[2],a[3],i),j),k) == 10){
						cout<<a[0]<<n2c(k)<<'('<<a[1]<<n2c(j)<<'('<<a[2]<<n2c(i)<<a[3]<<"))"<<endl;
						return true;
					}
					if(calc(calc(calc(a[0],a[1],i),a[2],j),a[3],k)== 10){
						cout<<"(("<<a[0]<<n2c(i)<<a[1]<<')'<<n2c(j)<<a[2]<<')'<<n2c(k)<<a[3]<<endl;
						return true;
					}
				}
			}
		}
		return false;
	}else{
		for(int i = n; i < 4; i++){
			swap(a[i],a[n]);
			if(comb(a,n+1)) return true;
			swap(a[i],a[n]);
		}
	}
	return false;
}

int main(){
	int a[4];
	for(int i = 0; i < 4; i++){
		cin >> a[i];
	}
	while(a[0]){
		if(!comb(a,0)) cout << 0 << endl;
		for(int i = 0; i < 4; i++){
			cin >> a[i];
		}
	}
}
```


### Prompt

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

The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king.

Check the king's moves here https://en.wikipedia.org/wiki/King_(chess).

<image> King moves from the position e4

Input

The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'.

Output

Print the only integer x — the number of moves permitted for the king.

Example

Input

e4

Output

8

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
constexpr int N = 1e3 + 5;
int a, b, ans = -1;
char v;
void Solve() {
  cin >> v;
  a = v - 'a';
  cin >> v;
  b = v - '1';
  for (int i = -1; i < 2; i++)
    for (int j = -1; j < 2; j++) {
      ans += (a + i >= 0 && a + i < 8 && b + j >= 0 && b + j < 8);
    }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  Solve();
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Sereja has a sequence that consists of n positive integers, a1, a2, ..., an.

First Sereja took a piece of squared paper and wrote all distinct non-empty non-decreasing subsequences of sequence a. Then for each sequence written on the squared paper, Sereja wrote on a piece of lines paper all sequences that do not exceed it.

A sequence of positive integers x = x1, x2, ..., xr doesn't exceed a sequence of positive integers y = y1, y2, ..., yr, if the following inequation holds: x1 ≤ y1, x2 ≤ y2, ..., xr ≤ yr.

Now Sereja wonders, how many sequences are written on the lines piece of paper. Help Sereja, find the required quantity modulo 1000000007 (109 + 7).

Input

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

Output

In the single line print the answer to the problem modulo 1000000007 (109 + 7).

Examples

Input

1
42

Output

42

Input

3
1 2 2

Output

13

Input

5
1 2 3 4 5

Output

719

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long sum[1100000];
long long res[1100000];
int lowbit(int x) { return x & (-x); }
long long query(int x) {
  long long ans = 0;
  while (x) {
    (ans += sum[x]) %= mod;
    x -= lowbit(x);
  }
  return ans;
}
void update(int x, long long k) {
  while (x <= 1000000) {
    (sum[x] += k) %= mod;
    x += lowbit(x);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int t;
    scanf("%d", &t);
    long long tt = (query(t) * t + t) % mod;
    update(t, ((tt - res[t]) % mod + mod) % mod);
    res[t] = tt;
  }
  printf("%I64d\n", query(1000000));
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.

But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.

Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.

It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.

Input

The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.

Output

Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».

Examples

Input

4 2

Output

1/2

Note

Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int w, y;
  cin >> y >> w;
  int r = max(y, w);
  r = (6 - r) + 1;
  switch (r) {
    case 0:
      cout << "0/1";
      break;
    case 1:
      cout << "1/6";
      break;
    case 2:
      cout << "1/3";
      break;
    case 3:
      cout << "1/2";
      break;
    case 4:
      cout << "2/3";
      break;
    case 5:
      cout << "5/6";
      break;
    case 6:
      cout << "1/1";
      break;
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

You are given a string s of length n consisting of lowercase Latin letters. You may apply some operations to this string: in one operation you can delete some contiguous substring of this string, if all letters in the substring you delete are equal. For example, after deleting substring bbbb from string abbbbaccdd we get the string aaccdd.

Calculate the minimum number of operations to delete the whole string s.

Input

The first line contains one integer n (1 ≤ n ≤ 500) — the length of string s.

The second line contains the string s (|s| = n) consisting of lowercase Latin letters.

Output

Output a single integer — the minimal number of operation to delete string s.

Examples

Input

5
abaca

Output

3

Input

8
abcddcba

Output

4

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
int n;
string second;
int dp[505][505];
int calc(int i, int j) {
  if (dp[i][j] != 0) return dp[i][j];
  if (i == j) return 1;
  if (i > j) return 0;
  int res = 1000000000;
  res = min(res, 1 + calc(i + 1, j));
  for (int k = (i + 1); k <= (signed)(j); k++) {
    if (second[i] == second[k]) {
      res = min(res, calc(i + 1, k - 1) + calc(k, j));
    }
  }
  dp[i][j] = res;
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> second;
  cout << calc(0, n - 1) << "\n";
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

The Ohgas are a prestigious family based on Hachioji. The head of the family, Mr. Nemochi Ohga, a famous wealthy man, wishes to increase his fortune by depositing his money to an operation company. You are asked to help Mr. Ohga maximize his profit by operating the given money during a specified period.

From a given list of possible operations, you choose an operation to deposit the given fund to. You commit on the single operation throughout the period and deposit all the fund to it. Each operation specifies an annual interest rate, whether the interest is simple or compound, and an annual operation charge. An annual operation charge is a constant not depending on the balance of the fund. The amount of interest is calculated at the end of every year, by multiplying the balance of the fund under operation by the annual interest rate, and then rounding off its fractional part. For compound interest, it is added to the balance of the fund under operation, and thus becomes a subject of interest for the following years. For simple interest, on the other hand, it is saved somewhere else and does not enter the balance of the fund under operation (i.e. it is not a subject of interest in the following years). An operation charge is then subtracted from the balance of the fund under operation. You may assume here that you can always pay the operation charge (i.e. the balance of the fund under operation is never less than the operation charge). The amount of money you obtain after the specified years of operation is called ``the final amount of fund.'' For simple interest, it is the sum of the balance of the fund under operation at the end of the final year, plus the amount of interest accumulated throughout the period. For compound interest, it is simply the balance of the fund under operation at the end of the final year.

Operation companies use C, C++, Java, etc., to perform their calculations, so they pay a special attention to their interest rates. That is, in these companies, an interest rate is always an integral multiple of 0.0001220703125 and between 0.0001220703125 and 0.125 (inclusive). 0.0001220703125 is a decimal representation of 1/8192. Thus, interest rates' being its multiples means that they can be represented with no errors under the double-precision binary representation of floating-point numbers.

For example, if you operate 1000000 JPY for five years with an annual, compound interest rate of 0.03125 (3.125 %) and an annual operation charge of 3000 JPY, the balance changes as follows.

The balance of the fund under operation (at the beginning of year) | Interest|  The balance of the fund under operation (at the end of year)
---|---|---
A| B = A × 0.03125 (and rounding off fractions) | A + B - 3000
1000000| 31250| 1028250
1028250| 32132| 1057382
1057382| 33043| 1087425
1087425| 33982| 1118407
1118407| 34950| 1150357

After the five years of operation, the final amount of fund is 1150357 JPY.

If the interest is simple with all other parameters being equal, it looks like:

The balance of the fund under operation (at the beginning of year) | Interest | The balance of the fund under operation (at the end of year) | Cumulative interest
---|---|---|---
A| B = A × 0.03125 (and rounding off fractions)| A - 3000|
1000000| 31250| 997000| 31250
997000| 31156| 994000| 62406
994000| 31062| 991000| 93468
991000| 30968| 988000| 124436
988000| 30875| 985000| 155311

In this case the final amount of fund is the total of the fund under operation, 985000 JPY, and the cumulative interests, 155311 JPY, which is 1140311 JPY.

Input

The input consists of datasets. The entire input looks like:

> the number of datasets (=m)
>  1st dataset
>  2nd dataset
>  ...
>  m-th dataset
>

The number of datasets, m, is no more than 100. Each dataset is formatted as follows.

> the initial amount of the fund for operation
>  the number of years of operation
>  the number of available operations (=n)
>  operation 1
>  operation 2
>  ...
>  operation n
>

The initial amount of the fund for operation, the number of years of operation, and the number of available operations are all positive integers. The first is no more than 100000000, the second no more than 10, and the third no more than 100.

Each ``operation'' is formatted as follows.

> simple-or-compound annual-interest-rate annual-operation-charge

where simple-or-compound is a single character of either '0' or '1', with '0' indicating simple interest and '1' compound. annual-interest-rate is represented by a decimal fraction and is an integral multiple of 1/8192. annual-operation-charge is an integer not exceeding 100000.

Output

For each dataset, print a line having a decimal integer indicating the final amount of fund for the best operation. The best operation is the one that yields the maximum final amount among the available operations. Each line should not have any character other than this number.

You may assume the final balance never exceeds 1000000000. You may also assume that at least one operation has the final amount of the fund no less than the initial amount of the fund.

Example

Input

4
1000000
5
2
0 0.03125 3000
1 0.03125 3000
6620000
7
2
0 0.0732421875 42307
1 0.0740966796875 40942
39677000
4
4
0 0.0709228515625 30754
1 0.00634765625 26165
0 0.03662109375 79468
0 0.0679931640625 10932
10585000
6
4
1 0.0054931640625 59759
1 0.12353515625 56464
0 0.0496826171875 98193
0 0.0887451171875 78966

Output

1150357
10559683
50796918
20829397

### Response

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

int main(){
  int m;
  while(cin >> m){
    for(int k=0;k<m;k++){
      int funds, period, n, ans=-1;
      cin >> funds >> period >> n;
      for(int i=0;i<n;i++){
	bool interest;
	double rate;
	int charge, tmp;
	cin >> tmp >> rate >> charge;
	if(tmp==1) interest=true;
	else interest=false;
	tmp=funds;

	if(interest){
	  for(int j=0;j<period;j++){
	    tmp+=(int)((double)tmp*rate)-charge;
	  }
	}
	else{
	  int sum=0;
	  for(int j=0;j<period;j++){
	    sum+=(int)((double)tmp*rate);
	    tmp-=charge;
	  }
	  tmp+=sum;
	}

	ans=max(ans, tmp);
      }
      cout << ans << endl;
    }
  }
  return 0;
}
```