### Prompt

Please formulate a Cpp solution to the following problem:

Petya has an array a consisting of n integers. He has learned partial sums recently, and now he can calculate the sum of elements on any segment of the array really fast. The segment is a non-empty sequence of elements standing one next to another in the array.

Now he wonders what is the number of segments in his array with the sum less than t. Help Petya to calculate this number.

More formally, you are required to calculate the number of pairs l, r (l ≤ r) such that a_l + a_{l+1} + ... + a_{r-1} + a_r < t.

Input

The first line contains two integers n and t (1 ≤ n ≤ 200 000, |t| ≤ 2⋅10^{14}).

The second line contains a sequence of integers a_1, a_2, ..., a_n (|a_{i}| ≤ 10^{9}) — the description of Petya's array. Note that there might be negative, zero and positive elements.

Output

Print the number of segments in Petya's array with the sum of elements less than t.

Examples

Input

5 4
5 -1 3 4 -1

Output

5

Input

3 0
-1 2 -3

Output

4

Input

4 -1
-2 1 -2 3

Output

3

Note

In the first example the following segments have sum less than 4:

  * [2, 2], sum of elements is -1
  * [2, 3], sum of elements is 2
  * [3, 3], sum of elements is 3
  * [4, 5], sum of elements is 3
  * [5, 5], sum of elements is -1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd;
struct node {
  long long x;
  long long y;
  long long sz = 1;
  long long cnt = 1;
  node *left = 0;
  node *right = 0;
  node(long long _x) {
    x = _x;
    y = rnd();
  }
};
long long size(node *r) {
  if (!r) {
    return 0;
  }
  return r->sz;
}
void relax(node *r) {
  if (!r) {
    return;
  }
  r->sz = size(r->left) + r->cnt + size(r->right);
}
node *merge(node *r1, node *r2) {
  if (!r1) {
    return r2;
  }
  if (!r2) {
    return r1;
  }
  if (r1->y > r2->y) {
    r1->right = merge(r1->right, r2);
    relax(r1);
    return r1;
  } else {
    r2->left = merge(r1, r2->left);
    relax(r2);
    return r2;
  }
}
pair<node *, node *> split(node *r, long long v) {
  if (!r) {
    return make_pair(nullptr, nullptr);
  }
  if (r->x < v) {
    auto sup = split(r->right, v);
    r->right = sup.first;
    relax(r);
    return make_pair(r, sup.second);
  } else {
    auto sup = split(r->left, v);
    r->left = sup.second;
    relax(r);
    return make_pair(sup.first, r);
  }
}
node *addd(node *r, long long v) {
  node *q = new node(v);
  auto sup = split(r, v);
  auto sup2 = split(sup.second, v + 1);
  if (sup2.first == 0) {
    return merge(merge(sup.first, q), sup2.second);
  } else {
    sup2.first->cnt++;
    relax(sup2.first);
    return merge(merge(sup.first, sup2.first), sup2.second);
  }
}
node *delet(node *r, long long v) {
  auto sup = split(r, v);
  auto sup2 = split(sup.second, v + 1);
  if (sup2.first->cnt > 1) {
    sup2.first->cnt--;
    relax(sup2.first);
    return merge(merge(sup.first, sup2.first), sup2.second);
  } else {
    return merge(sup.first, sup2.second);
  }
}
long long counting(node *r, long long v) {
  if (!r) {
    return 0;
  }
  long long ans = 0;
  if (r->x < v) {
    return size(r->left) + r->cnt + counting(r->right, v);
  } else {
    return counting(r->left, v);
  }
}
void prt(node *r) {
  if (!r) {
    cout << "null   ";
  } else {
    prt(r->left);
    cout << (r->x) << ' ' << (r->cnt) << "   ";
    prt(r->right);
  }
}
struct cartesian {
  node *r = nullptr;
  cartesian() { r = nullptr; }
  void add(long long v) { r = addd(r, v); }
  void del(long long v) { r = delet(r, v); }
  long long count(long long v) { return counting(r, v); }
  void out() {
    prt(r);
    cout << endl;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cartesian q = cartesian();
  long long n, t;
  cin >> n >> t;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<long long> pref(n + 1);
  for (long long i = 0; i < n; i++) {
    pref[i + 1] = pref[i] + a[i];
  }
  for (long long i = 0; i <= n; i++) {
    q.add(pref[i]);
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    q.del(pref[i]);
    ans += q.count(pref[i] + t);
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

Pavel plays a famous computer game. A player is responsible for a whole country and he can travel there freely, complete quests and earn experience.

This country has n cities connected by m bidirectional roads of different lengths so that it is possible to get from any city to any other one. There are portals in k of these cities. At the beginning of the game all portals are closed. When a player visits a portal city, the portal opens. Strange as it is, one can teleport from an open portal to an open one. The teleportation takes no time and that enables the player to travel quickly between rather remote regions of the country.

At the beginning of the game Pavel is in city number 1. He wants to open all portals as quickly as possible. How much time will he need for that?

Input

The first line contains two space-separated integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 105) that show how many cities and roads are in the game.

Each of the next m lines contains the description of a road as three space-separated integers xi, yi, wi (1 ≤ xi, yi ≤ n, xi ≠ yi, 1 ≤ wi ≤ 109) — the numbers of the cities connected by the i-th road and the time needed to go from one city to the other one by this road. Any two cities are connected by no more than one road. It is guaranteed that we can get from any city to any other one, moving along the roads of the country.

The next line contains integer k (1 ≤ k ≤ n) — the number of portals.

The next line contains k space-separated integers p1, p2, ..., pk — numbers of the cities with installed portals. Each city has no more than one portal.

Output

Print a single number — the minimum time a player needs to open all portals.

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

Examples

Input

3 3
1 2 1
1 3 1
2 3 1
3
1 2 3

Output

2

Input

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

Output

16

Input

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

Output

3000000000

Note

In the second sample the player has to come to city 2, open a portal there, then go to city 3, open a portal there, teleport back to city 2 and finally finish the journey in city 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 5 + 1e5;
struct Graph {
  struct Edge {
    int to, nxt, k;
  };
  vector<int> head;
  vector<Edge> edge;
  Graph(int n = 0, int m = 0) {
    head = vector<int>(n + 1, -1);
    edge.clear();
    edge.reserve(m);
  }
  inline void add(int x, int y, int k) {
    edge.push_back((Edge){y, head[x], k});
    head[x] = edge.size() - 1;
  }
} G;
struct DSF {
  vector<int> fa;
  DSF(int n = 0) {
    fa = vector<int>(n + 1, 0);
    for (int i = 0; i <= n; ++i) fa[i] = i;
  }
  int fs(int x) {
    if (fa[x] != x) fa[x] = fs(fa[x]);
    return fa[x];
  }
  void merge(int x, int y) {
    if (fs(x) == fs(y)) return;
    fa[fs(y)] = fs(x);
  }
} dsf;
pair<long long, int> dis[N];
struct E {
  int x, y;
  long long w;
};
bool cmpE(E x, E y) { return x.w < y.w; }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  G = Graph(n, m + m);
  for (int i = 1; i <= m; ++i) {
    int x, y, w;
    scanf("%d%d%d", &x, &y, &w);
    G.add(x, y, w);
    G.add(y, x, w);
  }
  for (int i = 1; i <= n; ++i) dis[i] = make_pair((long long)2e18, 0);
  int k;
  scanf("%d", &k);
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      q;
  for (int i = 1; i <= k; ++i) {
    int x;
    scanf("%d", &x);
    dis[x] = make_pair(0, i);
    q.push(make_pair(dis[x].first, x));
  }
  while (!q.empty()) {
    int x = q.top().second;
    long long k = q.top().first;
    q.pop();
    if (k != dis[x].first) continue;
    for (int j = G.head[x]; ~j; j = G.edge[j].nxt) {
      int y = G.edge[j].to;
      if (dis[x].first + G.edge[j].k < dis[y].first) {
        dis[y].first = dis[x].first + G.edge[j].k;
        dis[y].second = dis[x].second;
        q.push(make_pair(dis[y].first, y));
      }
    }
  }
  dsf = DSF(k);
  vector<E> e;
  for (int x = 1; x <= n; ++x) {
    for (int j = G.head[x]; ~j; j = G.edge[j].nxt) {
      int y = G.edge[j].to;
      if (x < y && dis[x].second > 0 && dis[y].second > 0) {
        e.push_back((E){dis[x].second, dis[y].second,
                        dis[x].first + dis[y].first + G.edge[j].k});
      }
    }
  }
  sort(e.begin(), e.end(), cmpE);
  long long ans = dis[1].first;
  for (auto d : e) {
    int x = dsf.fs(d.x), y = dsf.fs(d.y);
    if (x == y) continue;
    dsf.merge(x, y);
    ans += d.w;
  }
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

In Aizu prefecture, we decided to create a new town to increase the population. To that end, we decided to cultivate a new rectangular land and divide this land into squares of the same size. The cost of developing this land is proportional to the number of plots, but the prefecture wants to minimize this cost.

Create a program to find the minimum maintenance cost for all plots, given the east-west and north-south lengths of the newly cultivated land and the maintenance cost per plot.

Input

The input is given in the following format.

W H C

The input is one line, the length W (1 ≤ W ≤ 1000) in the east-west direction and the length H (1 ≤ H ≤ 1000) in the north-south direction of the newly cultivated land, and the maintenance cost per plot C (1 ≤ 1000). C ≤ 1000) is given as an integer.

Output

Output the minimum cost required to maintain the land in one line.

Examples

Input

10 20 5

Output

10

Input

27 6 1

Output

18

### Response

```cpp
#include <bits/stdc++.h>

using namespace std;

int gcd(int x, int y) {
    int r = x % y;
    while (r > 0) {
        x = y;
        y = r;
        r = x %y;
    }
    return y;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a * b) / (gcd(a, b) * gcd(a, b)) * c << '\n';
    return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

You are given a multiset S consisting of positive integers (initially empty). There are two kind of queries:

  1. Add a positive integer to S, the newly added integer is not less than any number in it.
  2. Find a subset s of the set S such that the value <image> is maximum possible. Here max(s) means maximum value of elements in s, <image> — the average value of numbers in s. Output this maximum possible value of <image>.

Input

The first line contains a single integer Q (1 ≤ Q ≤ 5·105) — the number of queries.

Each of the next Q lines contains a description of query. For queries of type 1 two integers 1 and x are given, where x (1 ≤ x ≤ 109) is a number that you should add to S. It's guaranteed that x is not less than any number in S. For queries of type 2, a single integer 2 is given.

It's guaranteed that the first query has type 1, i. e. S is not empty when a query of type 2 comes.

Output

Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line.

Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10 - 6.

Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if <image>.

Examples

Input

6
1 3
2
1 4
2
1 8
2

Output

0.0000000000
0.5000000000
3.0000000000

Input

4
1 1
1 4
1 5
2

Output

2.0000000000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int a[510000];
int cnt = 0, maxx = 0, pre = 0;
double ans;
long long sum;
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d", &a[++cnt]);
      sum += a[cnt] - maxx;
      maxx = a[cnt];
      while (pre < cnt && maxx - 1.0 * sum / (pre + 1) <
                              maxx - 1.0 * (sum + a[pre + 1]) / (pre + 2))
        sum += a[++pre];
      if (maxx - 1.0 * sum / (pre + 1) > ans)
        ans = maxx - 1.0 * sum / (pre + 1);
    } else
      printf("%.10f\n", ans);
  }
  return 0;
}

```


### Prompt

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

Tavas lives in Kansas. Kansas has n cities numbered from 1 to n connected with m bidirectional roads. We can travel from any city to any other city via these roads. Kansas is as strange as Tavas. So there may be a road between a city and itself or more than one road between two cities.

Tavas invented a game and called it "Dashti". He wants to play Dashti with his girlfriends, Nafas.

In this game, they assign an arbitrary integer value to each city of Kansas. The value of i-th city equals to pi.

During the game, Tavas is in city s and Nafas is in city t. They play in turn and Tavas goes first. A player in his/her turn, must choose a non-negative integer x and his/her score increases by the sum of values of all cities with (shortest) distance no more than x from his/her city. Each city may be used once, or in the other words, after first time a player gets score from a city, city score becomes zero.

There is an additional rule: the player must choose x such that he/she gets the point of at least one city that was not used before. Note that city may initially have value 0, such city isn't considered as been used at the beginning of the game, i. e. each player may use it to fullfill this rule.

The game ends when nobody can make a move.

A player's score is the sum of the points he/she earned during the game. The winner is the player with greater score, or there is a draw if players score the same value. Both players start game with zero points.

<image>

If Tavas wins, he'll break his girlfriend's heart, and if Nafas wins, Tavas will cry. But if their scores are equal, they'll be happy and Tavas will give Nafas flowers.

They're not too emotional after all, so they'll play optimally. Your task is to tell Tavas what's going to happen after the game ends.

Input

The first line of input contains two integers n and m (2 ≤ n ≤ 2000, n - 1 ≤ m ≤ 105).

The second line of input contains two integers s and t (1 ≤ s, t ≤ n, s ≠ t).

The next line contains n integers p1, p2, ..., pn separated by spaces (|pi| ≤ 109).

The next m lines contain the roads. Each line contains three integers v, u, w and it means that there's an road with length w between cities v and u (1 ≤ u, v ≤ n and 0 ≤ w ≤ 109). The road may lead from the city to itself, there may be several roads between each pair of cities.

Output

If Tavas wins, print "Break a heart". If Nafas wins print "Cry" and if nobody wins (i. e. the game ended with draw) print "Flowers".

Examples

Input

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

Output

Cry

Input

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

Output

Break a heart

Input

2 1
1 2
-5 -5
1 2 10

Output

Flowers

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<pair<long long, long long> > > sus;
vector<long long> p;
vector<vector<long long> > tav_can_earn_mem, naf_can_earn_mem, tav_magic,
    naf_magic, tav_suf_max_mem, naf_suf_max_mem;
vector<vector<int> > tav_must_eat, naf_must_eat;
vector<vector<int> > ban;
vector<pair<long long, long long> > by_distance(int a) {
  vector<pair<long long, long long> > res(0);
  vector<long long> dist(n, 1023456789123456789ll);
  dist[a] = 0;
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      halda;
  halda.push(pair<long long, long long>(0, a));
  while (!halda.empty()) {
    pair<long long, long long> tp = halda.top();
    halda.pop();
    int cur = tp.second;
    if (tp.first > dist[cur]) continue;
    res.push_back(pair<long long, long long>(cur, dist[cur]));
    for (int i = 0; i < sus[cur].size(); i++) {
      int on = sus[cur][i].first;
      long long l = sus[cur][i].second;
      if (dist[on] > dist[cur] + l) {
        dist[on] = dist[cur] + l;
        halda.push(pair<long long, long long>(dist[on], on));
      }
    }
  }
  return res;
}
long long tav_can_earn(int t_e, int n_e);
long long naf_can_earn(int t_e, int n_e);
long long naf_get_max(int t_e, int n_e) {
  if (t_e == -1) return -1023456789123456789ll;
  if (naf_suf_max_mem[t_e][n_e] == -1023456789123456789ll) {
    long long cur = -naf_can_earn(t_e, n_e) + naf_magic[t_e][n_e];
    if (t_e == n)
      naf_suf_max_mem[t_e][n_e] = cur;
    else
      naf_suf_max_mem[t_e][n_e] = max(naf_get_max(t_e + 1, n_e), cur);
  }
  return naf_suf_max_mem[t_e][n_e];
}
long long tav_get_max(int t_e, int n_e) {
  if (n_e == -1) return -1023456789123456789ll;
  if (tav_suf_max_mem[t_e][n_e] == -1023456789123456789ll) {
    long long cur = -tav_can_earn(t_e, n_e) + tav_magic[t_e][n_e];
    if (n_e == n)
      tav_suf_max_mem[t_e][n_e] = cur;
    else
      tav_suf_max_mem[t_e][n_e] = max(tav_get_max(t_e, n_e + 1), cur);
  }
  return tav_suf_max_mem[t_e][n_e];
}
long long tav_can_earn(int t_e, int n_e) {
  if (ban[t_e][n_e]) return 1023456789123456789ll;
  if (tav_can_earn_mem[t_e][n_e] == -1023456789123456789ll) {
    tav_can_earn_mem[t_e][n_e] =
        naf_get_max(tav_must_eat[t_e][n_e], n_e) - naf_magic[t_e][n_e];
    if (tav_can_earn_mem[t_e][n_e] < -102345678912345ll)
      tav_can_earn_mem[t_e][n_e] = 0;
  }
  return tav_can_earn_mem[t_e][n_e];
}
long long naf_can_earn(int t_e, int n_e) {
  if (ban[t_e][n_e]) return 1023456789123456789ll;
  if (naf_can_earn_mem[t_e][n_e] == -1023456789123456789ll) {
    naf_can_earn_mem[t_e][n_e] =
        tav_get_max(t_e, naf_must_eat[t_e][n_e]) - tav_magic[t_e][n_e];
    if (naf_can_earn_mem[t_e][n_e] < -102345678912345ll)
      naf_can_earn_mem[t_e][n_e] = 0;
  }
  return naf_can_earn_mem[t_e][n_e];
}
int main() {
  scanf("%d %d", &n, &m);
  int s, t;
  scanf("%d %d", &s, &t);
  s--;
  t--;
  p.resize(n);
  for (int i = 0; i < n; i++) {
    int pom;
    scanf("%d", &pom);
    p[i] = pom;
  }
  sus.resize(n);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    u--;
    v--;
    sus[u].push_back(pair<long long, long long>(v, w));
    sus[v].push_back(pair<long long, long long>(u, w));
  }
  vector<pair<long long, long long> > tav_by_dist = by_distance(s),
                                      naf_by_dist = by_distance(t);
  ban.resize(n + 1, vector<int>(n + 1, 0));
  for (int y = 0; y <= n; y++) {
    for (int x = 0; x <= n; x++) {
      if (x > 0 && x < n) {
        if (naf_by_dist[x - 1].second == naf_by_dist[x].second) ban[y][x] = 1;
      }
      if (y > 0 && y < n) {
        if (tav_by_dist[y - 1].second == tav_by_dist[y].second) ban[y][x] = 1;
      }
    }
  }
  vector<int> which_for_t(n), which_for_n(n);
  for (int i = 0; i < n; i++) {
    which_for_t[tav_by_dist[i].first] = i;
    which_for_n[naf_by_dist[i].first] = i;
  }
  tav_must_eat.resize(n + 1, vector<int>(n + 1));
  naf_must_eat.resize(n + 1, vector<int>(n + 1));
  for (int tav_ate = 0; tav_ate <= n; tav_ate++) {
    vector<int> eaten(n, 0);
    int must_e = tav_ate + 1;
    if (must_e > n) must_e = -1;
    for (int naf_ate = 0; naf_ate <= n; naf_ate++) {
      tav_must_eat[tav_ate][naf_ate] = must_e;
      if (naf_ate < n) {
        int nid = which_for_t[naf_by_dist[naf_ate].first];
        eaten[nid] = 1;
        if (nid == must_e - 1) {
          while (eaten[must_e - 1]) {
            must_e++;
            if (must_e > n) {
              must_e = -1;
              break;
            }
          }
        }
      }
    }
  }
  for (int naf_ate = 0; naf_ate <= n; naf_ate++) {
    vector<int> eaten(n, 0);
    int must_e = naf_ate + 1;
    if (must_e > n) must_e = -1;
    for (int tav_ate = 0; tav_ate <= n; tav_ate++) {
      naf_must_eat[tav_ate][naf_ate] = must_e;
      if (tav_ate < n) {
        int tid = which_for_n[tav_by_dist[tav_ate].first];
        eaten[tid] = 1;
        if (tid == must_e - 1) {
          while (eaten[must_e - 1]) {
            must_e++;
            if (must_e > n) {
              must_e = -1;
              break;
            }
          }
        }
      }
    }
  }
  tav_magic.resize(n + 1, vector<long long>(n + 1, 0));
  naf_magic.resize(n + 1, vector<long long>(n + 1, 0));
  for (int y = 0; y <= n; y++) {
    for (int x = 1; x <= n; x++) {
      int id = naf_by_dist[x - 1].first;
      long long delta;
      if (which_for_t[id] >= y)
        delta = p[id];
      else
        delta = 0;
      tav_magic[y][x] = tav_magic[y][x - 1] + delta;
    }
  }
  for (int x = 0; x <= n; x++) {
    for (int y = 1; y <= n; y++) {
      int id = tav_by_dist[y - 1].first;
      long long delta;
      if (which_for_n[id] >= x)
        delta = p[id];
      else
        delta = 0;
      naf_magic[y][x] = naf_magic[y - 1][x] + delta;
    }
  }
  tav_can_earn_mem = vector<vector<long long> >(
      n + 1, vector<long long>(n + 1, -1023456789123456789ll));
  naf_can_earn_mem = tav_can_earn_mem;
  tav_suf_max_mem = vector<vector<long long> >(
      n + 1, vector<long long>(n + 1, -1023456789123456789ll));
  naf_suf_max_mem = tav_suf_max_mem;
  long long tav_e = tav_can_earn(0, 0);
  if (tav_e > 0) {
    printf("Break a heart\n");
  }
  if (tav_e < 0) {
    printf("Cry\n");
  }
  if (tav_e == 0) {
    printf("Flowers\n");
  }
  return 0;
}

```


### Prompt

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

Many people are aware of DMCA – Digital Millennium Copyright Act. But another recently proposed DMCA – Digital Millennium Calculation Act – is much less known.

In this problem you need to find a root of a number according to this new DMCA law.

Input

The input contains a single integer a (1 ≤ a ≤ 1000000).

Output

Output the result – an integer number.

Examples

Input

1

Output

1

Input

81

Output

9

### Response

```cpp
#include <bits/stdc++.h>

using namespace std;

int main() {
    long a, root=0;
    cin >> a;
    while(a!=0) {
        root += a%10;
        a /= 10;
    }
    root %= 9;
    if(root==0)
        root = 9;
    cout << root << endl;
    return 0;
}
```


### Prompt

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

As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup.

<image>

Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start.

After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right.

Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a1, a2, ..., ak such that

<image>

in other words, n is multiplication of all elements of the given array.

Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that <image>, where <image> is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 109 + 7.

Please note that we want <image> of p and q to be 1, not <image> of their remainders after dividing by 109 + 7.

Input

The first line of input contains a single integer k (1 ≤ k ≤ 105) — the number of elements in array Barney gave you.

The second line contains k integers a1, a2, ..., ak (1 ≤ ai ≤ 1018) — the elements of the array.

Output

In the only line of output print a single string x / y where x is the remainder of dividing p by 109 + 7 and y is the remainder of dividing q by 109 + 7.

Examples

Input

1
2

Output

1/2

Input

3
1 1 1

Output

0/1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long powi(long long x, long long y, long long p) {
  x = (x % p + p) % p;
  long long z = 1;
  for (long long i = 1; i <= y; i <<= 1) {
    if (y & i) z = z * x % p;
    x = x * x % p;
  }
  return z;
}
long long inv(long long x, long long p) { return powi(x, p - 2, p); }
const int mod = 1e9 + 7;
int main() {
  int n;
  scanf("%d", &n);
  vector<long long> xs(n);
  for (int i = 0; (i) < (n); ++(i)) scanf("%I64d", &xs[i]);
  long long a = -1;
  long long b = 2;
  for (long long x : xs) {
    a = powi(a, x, mod);
    b = powi(b, x, mod);
  }
  long long p = (2 * a + b) % mod * inv(6, mod) % mod;
  long long q = (3 * b) % mod * inv(6, mod) % mod;
  printf("%I64d/%I64d\n", p, q);
  return 0;
}

```


### Prompt

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

Let A = {a1, a2, ..., an} be any permutation of the first n natural numbers {1, 2, ..., n}. You are given a positive integer k and another sequence B = {b1, b2, ..., bn}, where bi is the number of elements aj in A to the left of the element at = i such that aj ≥ (i + k).

For example, if n = 5, a possible A is {5, 1, 4, 2, 3}. For k = 2, B is given by {1, 2, 1, 0, 0}. But if k = 3, then B = {1, 1, 0, 0, 0}.

For two sequences X = {x1, x2, ..., xn} and Y = {y1, y2, ..., yn}, let i-th elements be the first elements such that xi ≠ yi. If xi < yi, then X is lexicographically smaller than Y, while if xi > yi, then X is lexicographically greater than Y.

Given n, k and B, you need to determine the lexicographically smallest A.

Input

The first line contains two space separated integers n and k (1 ≤ n ≤ 1000, 1 ≤ k ≤ n). On the second line are n integers specifying the values of B = {b1, b2, ..., bn}.

Output

Print on a single line n integers of A = {a1, a2, ..., an} such that A is lexicographically minimal. It is guaranteed that the solution exists.

Examples

Input

5 2
1 2 1 0 0

Output

4 1 5 2 3

Input

4 2
1 0 0 0

Output

2 3 1 4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int MAXN = 1e6 + 10;
const int MOD = 1000000007;
int main() {
  int n, k;
  int i, j, q;
  int a[1010];
  cin >> n >> k;
  for (i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= n; ++j) {
      if (a[j] == 0) {
        printf("%d%c", j, i == n ? '\n' : ' ');
        break;
      }
    }
    for (q = 1; q <= j - k; ++q) a[q]--;
    a[j]--;
  }
  return 0;
}

```


### Prompt

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

Sereja has an n × m rectangular table a, each cell of the table contains a zero or a number one. Sereja wants his table to meet the following requirement: each connected component of the same values forms a rectangle with sides parallel to the sides of the table. Rectangles should be filled with cells, that is, if a component form a rectangle of size h × w, then the component must contain exactly hw cells.

A connected component of the same values is a set of cells of the table that meet the following conditions:

  * every two cells of the set have the same value;
  * the cells of the set form a connected region on the table (two cells are connected if they are adjacent in some row or some column of the table);
  * it is impossible to add any cell to the set unless we violate the two previous conditions.

Can Sereja change the values of at most k cells of the table so that the table met the described requirement? What minimum number of table cells should he change in this case?

Input

The first line contains integers n, m and k (1 ≤ n, m ≤ 100; 1 ≤ k ≤ 10). Next n lines describe the table a: the i-th of them contains m integers ai1, ai2, ..., aim (0 ≤ ai, j ≤ 1) — the values in the cells of the i-th row.

Output

Print -1, if it is impossible to meet the requirement. Otherwise, print the minimum number of cells which should be changed.

Examples

Input

5 5 2
1 1 1 1 1
1 1 1 1 1
1 1 0 1 1
1 1 1 1 1
1 1 1 1 1

Output

1

Input

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

Output

-1

Input

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

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int mp[105][105];
int a[1024][10];
int main() {
  int n, m, p, i, j, k, ans, sum, w;
  for (i = 0; i < 1024; i++) {
    for (j = 0; j < 10; j++) {
      if (i & (1 << j)) a[i][j] = 1;
    }
  }
  scanf("%d%d%d", &n, &m, &p);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) scanf("%d", &mp[i][j]);
  }
  ans = n * m;
  if (p < n) {
    for (k = 0; k < n; k++) {
      sum = 0;
      for (i = 0; i < n; i++) {
        w = 0;
        for (j = 0; j < m; j++) w += (mp[i][j] ^ mp[k][j]);
        sum += min(w, m - w);
      }
      ans = min(sum, ans);
    }
  } else {
    for (k = 0; k < (1 << n); k++) {
      sum = 0;
      for (j = 0; j < m; j++) {
        w = 0;
        for (i = 0; i < n; i++) w += (mp[i][j] ^ a[k][i]);
        sum += min(w, n - w);
      }
      ans = min(sum, ans);
    }
  }
  printf("%d\n", ans <= p ? ans : -1);
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted n × m rectangle (only the border, no filling). Anna and Maria move in turns and Anna starts. During each move one should paint inside the last-painted rectangle a new lesser rectangle (along the grid lines). The new rectangle should have no common points with the previous one. Note that when we paint a rectangle, we always paint only the border, the rectangles aren't filled.

Nobody wins the game — Anna and Maria simply play until they have done k moves in total. Count the number of different ways to play this game.

Input

The first and only line contains three integers: n, m, k (1 ≤ n, m, k ≤ 1000).

Output

Print the single number — the number of the ways to play the game. As this number can be very big, print the value modulo 1000000007 (109 + 7).

Examples

Input

3 3 1

Output

1

Input

4 4 1

Output

9

Input

6 7 2

Output

75

Note

Two ways to play the game are considered different if the final pictures are different. In other words, if one way contains a rectangle that is not contained in the other way.

In the first sample Anna, who performs her first and only move, has only one possible action plan — insert a 1 × 1 square inside the given 3 × 3 square.

In the second sample Anna has as much as 9 variants: 4 ways to paint a 1 × 1 square, 2 ways to insert a 1 × 2 rectangle vertically, 2 more ways to insert it horizontally and one more way is to insert a 2 × 2 square.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 2e4 + 15;
const long long Mod = 1e9 + 7;
long long c[1010][2020];
int main() {
  ios::sync_with_stdio(false);
  int n, m, k, i, j;
  for (int i = 0; i <= 1000; i++) {
    c[i][0] = 1;
    c[i][i] = 1;
    for (j = 1; j < i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % Mod;
  }
  cin >> n >> m >> k;
  cout << c[n - 1][2 * k] * c[m - 1][2 * k] % Mod << '\n';
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Since Boboniu finished building his Jianghu, he has been doing Kungfu on these mountains every day.

Boboniu designs a map for his n mountains. He uses n-1 roads to connect all n mountains. Every pair of mountains is connected via roads.

For the i-th mountain, Boboniu estimated the tiredness of doing Kungfu on the top of it as t_i. He also estimated the height of each mountain as h_i.

A path is a sequence of mountains M such that for each i (1 ≤ i < |M|), there exists a road between M_i and M_{i+1}. Boboniu would regard the path as a challenge if for each i (1≤ i<|M|), h_{M_i}≤ h_{M_{i+1}}.

Boboniu wants to divide all n-1 roads into several challenges. Note that each road must appear in exactly one challenge, but a mountain may appear in several challenges.

Boboniu wants to minimize the total tiredness to do all the challenges. The tiredness of a challenge M is the sum of tiredness of all mountains in it, i.e. ∑_{i=1}^{|M|}t_{M_i}.

He asked you to find the minimum total tiredness. As a reward for your work, you'll become a guardian in his Jianghu.

Input

The first line contains a single integer n (2 ≤ n ≤ 2 ⋅ 10^5), denoting the number of the mountains.

The second line contains n integers t_1, t_2, …, t_n (1 ≤ t_i ≤ 10^6), denoting the tiredness for Boboniu to do Kungfu on each mountain.

The third line contains n integers h_1, h_2, …, h_n (1 ≤ h_i ≤ 10^6), denoting the height of each mountain.

Each of the following n - 1 lines contains two integers u_i, v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i), denoting the ends of the road. It's guaranteed that all mountains are connected via roads.

Output

Print one integer: the smallest sum of tiredness of all challenges.

Examples

Input

5
40 10 30 50 20
2 3 2 3 1
1 2
1 3
2 4
2 5

Output

160

Input

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

Output

4000004

Input

10
510916 760492 684704 32545 484888 933975 116895 77095 127679 989957
402815 705067 705067 705067 623759 103335 749243 138306 138306 844737
1 2
3 2
4 3
1 5
6 4
6 7
8 7
8 9
9 10

Output

6390572

Note

For the first example:

<image>

In the picture, the lighter a point is, the higher the mountain it represents. One of the best divisions is:

  * Challenge 1: 3 → 1 → 2
  * Challenge 2: 5 → 2 → 4

The total tiredness of Boboniu is (30 + 40 + 10) + (20 + 10 + 50) = 160. It can be shown that this is the minimum total tiredness.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
string tostring(T x) {
  ostringstream out;
  out << x;
  return out.str();
}
long long toint(string s) {
  istringstream in(s);
  long long x;
  in >> x;
  return x;
}
int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, -1, 1, -1, 1};
int kx[8] = {1, 1, -1, -1, 2, 2, -2, -2};
int ky[8] = {2, -2, 2, -2, 1, -1, 1, -1};
const int MAX = 222222;
int n;
vector<int> edges[MAX];
int h[MAX];
long long t[MAX];
long long memo[MAX][3];
long long dfs(int root, int dir, int par = -1) {
  long long &res = memo[root][dir];
  if (res != -1) return res;
  if (par != -1 && edges[root].size() == 1) {
    return t[root];
  }
  long long known = 0;
  int in = 0, out = 0;
  if (dir == 1)
    in++;
  else if (dir == 2)
    out++;
  vector<pair<long long, long long>> unknown;
  for (int child : edges[root]) {
    if (child == par) continue;
    if (h[root] > h[child]) {
      out++;
      known += dfs(child, 1, root);
    } else if (h[root] < h[child]) {
      in++;
      known += dfs(child, 2, root);
    } else {
      unknown.push_back({dfs(child, 1, root), dfs(child, 2, root)});
    }
  }
  res = known;
  for (int i = 0; i < unknown.size(); i++) res += unknown[i].first;
  out += unknown.size();
  res += max(in, out) * t[root];
  vector<long long> v;
  for (int i = 0; i < unknown.size(); i++)
    v.push_back(unknown[i].second - unknown[i].first);
  sort(v.begin(), v.end());
  long long sum = 0;
  for (auto x : unknown) sum += x.first;
  for (int i = 0; i < v.size(); i++) {
    sum += v[i];
    in++;
    out--;
    res = min(res, sum + known + max(in, out) * t[root]);
  }
  return res;
}
void solveOne() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> t[i];
  for (int i = 0; i < n; i++) cin >> h[i];
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    edges[x].push_back(y);
    edges[y].push_back(x);
  }
  memset(memo, -1, sizeof(memo));
  cout << dfs(0, 0) << endl;
}
int main() {
  std::ios::sync_with_stdio(false);
  int T = 1;
  while (T--) {
    solveOne();
  }
  return 0;
}

```


### Prompt

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

This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output).

In this problem you should guess an array a which is unknown for you. The only information you have initially is the length n of the array a.

The only allowed action is to ask the sum of two elements by their indices. Formally, you can print two indices i and j (the indices should be distinct). Then your program should read the response: the single integer equals to ai + aj.

It is easy to prove that it is always possible to guess the array using at most n requests.

Write a program that will guess the array a by making at most n requests.

Interaction

In each test your program should guess a single array.

The input starts with a line containing integer n (3 ≤ n ≤ 5000) — the length of the array. Your program should read it at first.

After that your program should print to the standard output the requests about the sum of two elements or inform that the array is guessed.

  * In case your program is making a request to ask the sum of two elements, it should print line in the format "? i j" (i and j are distinct integers between 1 and n), where i and j are indices in the array a.
  * In case your program informs that the array is guessed, it should print line in the format "! a1 a2 ... an" (it is guaranteed that all ai are positive integers not exceeding 105), where ai is the i-th element of the array a.

The response on a request is a single integer equal to ai + aj, printed on a separate line.

Your program can do at most n requests. Note that the final line «! a1 a2 ... an» is not counted as a request.

Do not forget about flush operation after each printed line.

After you program prints the guessed array, it should terminate normally.

Example

Input

5

9

7

9

11

6

Output

? 1 5

? 2 3

? 4 1

? 5 2

? 3 4

! 4 6 1 5 5

Note

The format of a test to make a hack is:

  * The first line contains an integer number n (3 ≤ n ≤ 5000) — the length of the array.
  * The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 105) — the elements of the array to guess.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int a[N], sum[N];
int main() {
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    printf("? 1 %d\n", i);
    fflush(stdout);
    scanf("%d", &sum[i]);
  }
  printf("? 2 3\n");
  fflush(stdout);
  scanf("%d", &sum[1]);
  a[1] = (sum[2] + sum[3] - sum[1]) / 2;
  for (int i = 2; i <= n; i++) a[i] = sum[i] - a[1];
  printf("! ");
  fflush(stdout);
  for (int i = 1; i <= n - 1; i++) printf("%d ", a[i]);
  printf("%d\n", a[n]);
}

```


### Prompt

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

You are given an array a of n integers. Find the number of pairs (i, j) (1 ≤ i < j ≤ n) where the sum of a_i + a_j is greater than or equal to l and less than or equal to r (that is, l ≤ a_i + a_j ≤ r).

For example, if n = 3, a = [5, 1, 2], l = 4 and r = 7, then two pairs are suitable:

  * i=1 and j=2 (4 ≤ 5 + 1 ≤ 7);
  * i=1 and j=3 (4 ≤ 5 + 2 ≤ 7).

Input

The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.

The first line of each test case contains three integers n, l, r (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ l ≤ r ≤ 10^9) — the length of the array and the limits on the sum in the pair.

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

It is guaranteed that the sum of n overall test cases does not exceed 2 ⋅ 10^5.

Output

For each test case, output a single integer — the number of index pairs (i, j) (i < j), such that l ≤ a_i + a_j ≤ r.

Example

Input

4
3 4 7
5 1 2
5 5 8
5 1 2 4 3
4 100 1000
1 1 1 1
5 9 13
2 5 5 1 1

Output

2
7
0
1

### Response

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

int main(){
	int t;
	cin>>t;
	while(t--){
		int n,l,r;
		long long temp=0;
		cin>>n>>l>>r;
		long long a[n];
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		sort(a,a+n);
		for(int i=0;i<n;i++){
			temp+=((upper_bound(a+i+1,a+n,r-a[i])-a)-(lower_bound(a+i+1,a+n,l-a[i])-a));
		}
		cout<<temp<<endl;
	}
	return 0;
}
```


### Prompt

Generate a CPP solution to the following problem:

A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.

For example, the following numbers are round: 4000, 1, 9, 800, 90. The following numbers are not round: 110, 707, 222, 1001.

You are given a positive integer n (1 ≤ n ≤ 10^4). Represent the number n as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number n as a sum of the least number of terms, each of which is a round number.

Input

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

Each test case is a line containing an integer n (1 ≤ n ≤ 10^4).

Output

Print t answers to the test cases. Each answer must begin with an integer k — the minimum number of summands. Next, k terms must follow, each of which is a round number, and their sum is n. The terms can be printed in any order. If there are several answers, print any of them.

Example

Input

5
5009
7
9876
10000
10

Output

2
5000 9
1
7
4
800 70 6 9000
1
10000
1
10

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  for (int test_case = 0; test_case < T; test_case++) {
    int num, round = 1;
    vector<int> result;
    cin >> num;
    while (num > 0) {
      if (num % 10 != 0) {
        result.push_back((num % 10) * round);
      }
      num /= 10;
      round *= 10;
    }
    cout << result.size() << endl;
    for (int i = 0; i < result.size(); i++) {
      cout << result[i] << " ";
    }
    cout << endl;
  }
}

```


### Prompt

Generate a CPP solution to the following problem:

The campus has m rooms numbered from 0 to m - 1. Also the x-mouse lives in the campus. The x-mouse is not just a mouse: each second x-mouse moves from room i to the room i ⋅ x mod{m} (in fact, it teleports from one room to another since it doesn't visit any intermediate room). Starting position of the x-mouse is unknown.

You are responsible to catch the x-mouse in the campus, so you are guessing about minimum possible number of traps (one trap in one room) you need to place. You are sure that if the x-mouse enters a trapped room, it immediately gets caught.

And the only observation you made is GCD (x, m) = 1.

Input

The only line contains two integers m and x (2 ≤ m ≤ 10^{14}, 1 ≤ x < m, GCD (x, m) = 1) — the number of rooms and the parameter of x-mouse.

Output

Print the only integer — minimum number of traps you need to install to catch the x-mouse.

Examples

Input

4 3

Output

3

Input

5 2

Output

2

Note

In the first example you can, for example, put traps in rooms 0, 2, 3. If the x-mouse starts in one of this rooms it will be caught immediately. If x-mouse starts in the 1-st rooms then it will move to the room 3, where it will be caught.

In the second example you can put one trap in room 0 and one trap in any other room since x-mouse will visit all rooms 1..m-1 if it will start in any of these rooms.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int x, global;
int counter[100 + 5];
struct number {
  vector<long long int> P, A;
  number() {}
  number(long long int m) {
    int s = sqrtl(m);
    for (int i = 2; i <= s; i++)
      if (m % i == 0) {
        P.push_back(i);
        A.push_back(0);
        while (m % i == 0) {
          m = m / i;
          A.back()++;
        }
        s = sqrtl(m);
      }
    if (m != 1) {
      P.push_back(m);
      A.push_back(1);
    }
  }
  void merge(number ano) {
    int i, j;
    for (i = 0; i < (int)ano.P.size(); i++) {
      for (j = 0; j < (int)P.size(); j++)
        if (P[j] == ano.P[i]) {
          A[j] += ano.A[i];
          break;
        }
      if (j == (int)P.size()) {
        P.push_back(ano.P[i]);
        A.push_back(ano.A[i]);
      }
    }
  }
  long long int eval() {
    long long int ret = 1;
    for (int i = 0; i < (int)P.size(); i++) {
      for (int j = 1; j <= A[i]; j++) ret = ret * P[i];
    }
    return ret;
  }
} M, arr[100 + 5];
long long int mod;
inline long long int eval(long long int value) {
  if (value >= mod) return value - mod;
  return value;
}
inline long long int mul(long long int u, long long int v) {
  if (!v) return 0;
  if (v & 1) return eval((u + mul(u, v - 1)));
  long long int ret = mul(u, v / 2);
  return eval((ret + ret));
}
inline long long int ip(long long int a, long long int p) {
  if (!p) return 1 % mod;
  if (p & 1) return mul(a, ip(a, p - 1));
  long long int ret = ip(a, p / 2);
  return mul(ret, ret);
}
void G(number &d, number &phi) {
  long long int dvxr = d.eval();
  long long int phival = phi.eval();
  long long int ret = phival;
  mod = dvxr;
  long long int nx = x % dvxr;
  long long int nr = 1 % dvxr;
  for (int i = (int)phi.P.size() - 1; i >= 0; i--) {
    while (true) {
      if (phi.A[i] && ip(nx, ret / phi.P[i]) == nr)
        ret /= phi.P[i], phi.A[i]--;
      else
        break;
    }
  }
  global += phival / ret;
}
void F() {
  int i, j;
  number phi, d, ano;
  for (i = 0; i < (int)M.P.size(); i++)
    if (counter[i]) {
      d.P.push_back(M.P[i]);
      d.A.push_back(counter[i]);
    }
  phi = d;
  assert(d.A.size() == d.P.size());
  for (i = 0; i < (int)phi.P.size(); i++) {
    phi.A[i]--;
    for (j = 0; j < (int)M.P.size(); j++)
      if (M.P[j] == phi.P[i]) {
        ano.merge(arr[j]);
        break;
      }
  }
  phi.merge(ano);
  return G(d, phi);
}
void backTrack(int pos) {
  if (pos == (int)M.P.size()) return F();
  for (int c = 0; c <= M.A[pos]; c++) {
    counter[pos] = c;
    backTrack(pos + 1);
  }
}
int main() {
  int i;
  long long int v;
  cin >> v >> x;
  M = number(v);
  for (i = 0; i < (int)M.P.size(); i++) arr[i] = number(M.P[i] - 1);
  backTrack(0);
  cout << global << endl;
  return 0;
}

```


### Prompt

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

Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks.

There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each.

What is the minimum amount of money with which he can buy M cans of energy drinks?

It is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.

Constraints

* All values in input are integers.
* 1 \leq N, M \leq 10^5
* 1 \leq A_i \leq 10^9
* 1 \leq B_i \leq 10^5
* B_1 + ... + B_N \geq M

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print the minimum amount of money with which Takahashi can buy M cans of energy drinks.

Examples

Input

2 5
4 9
2 4

Output

12

Input

4 30
6 18
2 5
3 10
7 9

Output

130

Input

1 100000
1000000000 100000

Output

100000000000000

### Response

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

int main(){
ll N,M;
cin>>N>>M;
vector<pair<ll, ll>> a(N);
for(int i = 0;i<N;i++){
ll A, B;
cin >> A >> B;
a[i].first=A;
a[i].second=B;
}
sort(a.begin(),a.end());
ll ans = 0;
for(int i = 0;i<N&&M>0;i++){
ans+=a[i].first*min(M,a[i].second);
M-=a[i].second;
}
cout<<ans<<endl;

}
```


### Prompt

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

Polycarp is making a quest for his friends. He has already made n tasks, for each task the boy evaluated how interesting it is as an integer qi, and the time ti in minutes needed to complete the task.

An interesting feature of his quest is: each participant should get the task that is best suited for him, depending on his preferences. The task is chosen based on an interactive quiz that consists of some questions. The player should answer these questions with "yes" or "no". Depending on the answer to the question, the participant either moves to another question or goes to one of the tasks that are in the quest. In other words, the quest is a binary tree, its nodes contain questions and its leaves contain tasks.

We know that answering any of the questions that are asked before getting a task takes exactly one minute from the quest player. Polycarp knows that his friends are busy people and they can't participate in the quest for more than T minutes. Polycarp wants to choose some of the n tasks he made, invent the corresponding set of questions for them and use them to form an interactive quiz as a binary tree so that no matter how the player answers quiz questions, he spends at most T minutes on completing the whole quest (that is, answering all the questions and completing the task). Specifically, the quest can contain zero questions and go straight to the task. Each task can only be used once (i.e., the people who give different answers to questions should get different tasks).

Polycarp wants the total "interest" value of the tasks involved in the quest to be as large as possible. Help him determine the maximum possible total interest value of the task considering that the quest should be completed in T minutes at any variant of answering questions.

Input

The first line contains two integers n and T (1 ≤ n ≤ 1000, 1 ≤ T ≤ 100) — the number of tasks made by Polycarp and the maximum time a quest player should fit into.

Next n lines contain two integers ti, qi (1 ≤ ti ≤ T, 1 ≤ qi ≤ 1000) each — the time in minutes needed to complete the i-th task and its interest value.

Output

Print a single integer — the maximum possible total interest value of all the tasks in the quest.

Examples

Input

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

Output

11

Input

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

Output

9

Input

2 2
1 1
2 10

Output

10

Note

In the first sample test all the five tasks can be complemented with four questions and joined into one quest.

In the second sample test it is impossible to use all the five tasks, but you can take two of them, the most interesting ones.

In the third sample test the optimal strategy is to include only the second task into the quest.

Here is the picture that illustrates the answers to the sample tests. The blue circles represent the questions, the two arrows that go from every circle represent where a person goes depending on his answer to that question. The tasks are the red ovals.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 210;
priority_queue<int> pq[105];
int main() {
  int n, T, t, q;
  scanf("%d%d", &n, &T);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &t, &q);
    t = T - t;
    if (t >= 0) pq[t].push(q);
  }
  for (int i = T; i > 0; i--) {
    int mx = (i >= 10 ? 1024 : (1 << i)), a, b;
    while (!pq[i].empty() && mx) {
      a = pq[i].top();
      pq[i].pop();
      b = 0;
      if (!pq[i].empty()) {
        b = pq[i].top();
        pq[i].pop();
      }
      pq[i - 1].push(a + b);
    }
  }
  int ans = pq[0].top();
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed).

Let's consider empty cells are denoted by '.', then the following figures are stars:

<image> The leftmost figure is a star of size 1, the middle figure is a star of size 2 and the rightmost figure is a star of size 3.

You are given a rectangular grid of size n × m consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from 1 to n, columns are numbered from 1 to m. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed n ⋅ m. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes.

In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most n ⋅ m stars.

Input

The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000) — the sizes of the given grid.

The next n lines contains m characters each, the i-th line describes the i-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only.

Output

If it is impossible to draw the given grid using stars only, print "-1".

Otherwise in the first line print one integer k (0 ≤ k ≤ n ⋅ m) — the number of stars needed to draw the given grid. The next k lines should contain three integers each — x_j, y_j and s_j, where x_j is the row index of the central star character, y_j is the column index of the central star character and s_j is the size of the star. Each star should be completely inside the grid.

Examples

Input

6 8
....*...
...**...
..*****.
...**...
....*...
........

Output

3
3 4 1
3 5 2
3 5 1

Input

5 5
.*...
****.
.****
..**.
.....

Output

3
2 2 1
3 3 1
3 4 1

Input

5 5
.*...
***..
.*...
.*...
.....

Output

-1

Input

3 3
*.*
.*.
*.*

Output

-1

Note

In the first example the output

    2
    3 4 1
    3 5 2

is also correct.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<string> grid(n);
  for (int i = 0; i < n; i++) cin >> grid[i];
  vector<vector<int> > hs(n, vector<int>(m));
  vector<vector<int> > vs(n, vector<int>(m));
  vector<vector<int> > vr(n + 1, vector<int>(m + 1, 0));
  vector<vector<int> > hr(n + 1, vector<int>(m + 1, 0));
  vector<vector<int> > gr(n, vector<int>(m, 0));
  vector<int> ansx;
  vector<int> ansy;
  vector<int> anss;
  for (int i = 0; i < n; i++) {
    hs[i][0] = grid[i][0] == '*';
    for (int j = 1; j < m; j++) {
      hs[i][j] = hs[i][j - 1];
      if (grid[i][j] == '*') hs[i][j]++;
    }
  }
  for (int j = 0; j < m; j++) {
    vs[0][j] = grid[0][j] == '*';
    for (int i = 1; i < n; i++) {
      vs[i][j] = vs[i - 1][j];
      if (grid[i][j] == '*') vs[i][j]++;
    }
  }
  for (int i = 1; i < n - 1; i++) {
    for (int j = 1; j < m - 1; j++) {
      if (grid[i][j] == '*' && grid[i - 1][j] == '*' && grid[i][j - 1] == '*' &&
          grid[i + 1][j] == '*' && grid[i][j + 1] == '*') {
        int mini = 1, maxi = min(n, m);
        while (mini != maxi) {
          int midi = (mini + maxi + 1) / 2;
          bool cool = true;
          if (i + midi < n && j + midi < m && i - midi >= 0 && j - midi >= 0) {
            int h = hs[i][j + midi];
            if (j - midi > 0) h -= hs[i][j - midi - 1];
            int v = vs[i + midi][j];
            if (i - midi > 0) v -= vs[i - midi - 1][j];
            cool = (h == midi * 2 + 1) && (v == midi * 2 + 1);
          } else
            cool = false;
          if (cool)
            mini = midi;
          else
            maxi = midi - 1;
        }
        vr[i - mini][j]++;
        vr[i + mini + 1][j]--;
        hr[i][j - mini]++;
        hr[i][j + mini + 1]--;
        ansx.push_back(i + 1);
        ansy.push_back(j + 1);
        anss.push_back(mini);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    int c = 0;
    for (int j = 0; j < m; j++) {
      c += hr[i][j];
      gr[i][j] += c;
    }
  }
  for (int j = 0; j < m; j++) {
    int c = 0;
    for (int i = 0; i < n; i++) {
      c += vr[i][j];
      gr[i][j] += c;
    }
  }
  bool radical = true;
  for (int i = 0; i < n && radical; i++) {
    for (int j = 0; j < m && radical; j++) {
      if (gr[i][j] == 0 && grid[i][j] == '*') radical = false;
    }
  }
  if (radical) {
    cout << ansx.size() << "\n";
    for (int i = 0; i < ansx.size(); i++) {
      cout << ansx[i] << " " << ansy[i] << " " << anss[i] << endl;
    }
    cout << "\n";
  } else
    cout << "-1\n";
  return 0;
}

```


### Prompt

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

We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized:

* Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}.

Find the maximum possible number of i such that p_i = i after operations.

Constraints

* 2 ≤ N ≤ 10^5
* 1 ≤ M ≤ 10^5
* p is a permutation of integers from 1 through N.
* 1 ≤ x_j,y_j ≤ N
* x_j ≠ y_j
* If i ≠ j, \\{x_i,y_i\\} ≠ \\{x_j,y_j\\}.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
p_1 p_2 .. p_N
x_1 y_1
x_2 y_2
:
x_M y_M

Output

Print the maximum possible number of i such that p_i = i after operations.

Examples

Input

5 2
5 3 1 4 2
1 3
5 4

Output

2

Input

3 2
3 2 1
1 2
2 3

Output

3

Input

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

Output

8

Input

5 1
1 2 3 4 5
1 5

Output

5

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int par[200006],a[200006];
int rep(int n){
  if(par[n]==n)return n;
  return par[n] = rep(par[n]);
}
void join(int x,int y){
  int a = rep(x);
  int b  = rep(y);
  if(a!=b){
    par[a]=b;
  }
  if(rep(x)==rep(y)) return;
  par[rep(x)]= rep(y);
}
int main(){
  int n,q;
  scanf("%d%d",&n,&q);
  for(int i=1;i<=n;i++){
    scanf("%d",&a[i]);
    par[i]=i;
  }
  int x,y;
  for(int i=1;i<=q;i++){
    scanf("%d%d",&x,&y);
    join(x,y);
  }
  int ans = 0;
  for(int i=1;i<=n;i++){
    if(rep(a[i])==rep(i) ){
      //cout<<a[i]<<" "<<par[i]<<endl;
      ans++;
    }

  }
  printf("%d\n",ans);
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

While roaming the mystic areas of Stonefalls, in order to drop legendary loot, an adventurer was given a quest as follows. He was given an array A = {a_1,a_2,...,a_N } of length N, and a number K.

Define array B as B(q, A) =  { q-a_1, q-a_2, ..., q-a_N }. Define function F as F(B,K) being sum of products of all K-tuples of elements in array B. For example, if the array B is [2,3,4,5], and with K=3, sum of products of all 3-tuples is $$$F(B, 3) = 2*3*4+2*3*5+3*4*5+2*4*5$$$

He was then given a number Q, number of queries of two types:

  * Type 1: Given q, i, and d calculate F(B(q, A), K) where we make change to initial array as A[i] = d.
  * Type 2: Given q, L, R, and d calculate F(B(q, A), K) where we make change to initial array as A[i] = A[i] + d for all i in range [L, R] inclusive.

All changes are temporarily made to initial array, and don't propagate to following queries. Help the adventurer calculate the answer to a quest, and finally get that loot!

Input

In the first two lines, numbers N (1 ≤ N ≤ 2*10^4) and K (1 ≤ K ≤ N), the length of initial array A, and tuple size, followed by a_1,a_2,a_3,…,a_N (0 ≤ a_i ≤ 10^9) , elements of array A, in the next line. Then follows number Q (Q ≤ 10), number of queries. In the next Q lines come queries of the form:

  * 1 q i d, for type 1,
  * 2 q L R d, for type 2,

as explained above (0 ≤ q, d ≤ 10^9, 1 ≤ i,L,R ≤ N)

Output

Print Q lines, the answers to queries, modulo 998244353.

Example

Input

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

Output

85
127
63

Note

In the first query array A = [1, 2, 3, 4, 5], B = [5, 4, 3, 2, 1], sum of products of 2-tuples = 85.

In second query array A = [1, 2, 3, 4, 2], B = [5, 4, 3, 2, 4], sum of products of 2-tuples = 127

In third query array A = [1, 3, 4, 4, 5], B = [5, 3, 2, 2, 1], sum of products of 2-tuples = 63

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int arr = 2e5 + 10;
const int ar = 2e3 + 10;
const long double pi = acos(-1);
const long double eps = 1e-10;
const long long md = 1e9 + 7;
void inc(int& a, int b) {
  a += b;
  if (a >= (long long)(998244353ll)) {
    a -= (long long)(998244353ll);
  }
}
int bpow(int a, int n) {
  int res = 1;
  while (n) {
    if (n & 1) {
      res = 1ll * res * a % (long long)(998244353ll);
    }
    n /= 2;
    a = 1ll * a * a % (long long)(998244353ll);
  }
  return res;
}
const int K = 16;
const int N = (1ll << K);
int rev_N;
int pw[N];
int rpw[N];
void init() {
  int root = -1;
  for (int i = 2;; i++) {
    if (bpow(i, N) == 1) {
      int cur = 1;
      for (int j = 1; j < N; j++) {
        cur = 1ll * cur * i % (long long)(998244353ll);
        if (cur == 1) {
          break;
        }
      }
      if (cur != 1) {
        root = i;
        break;
      }
    }
  }
  pw[0] = 1;
  for (int i = 1; i < N; i++) {
    pw[i] = 1ll * pw[i - 1] * root % (long long)(998244353ll);
  }
  int rroot = bpow(root, (long long)(998244353ll) - 2);
  rpw[0] = 1;
  for (int i = 1; i < N; i++) {
    rpw[i] = 1ll * rpw[i - 1] * rroot % (long long)(998244353ll);
  }
}
void fft(int* a, int* pw) {
  for (int i = 0; i < N; i++) {
    int r = 0;
    for (int j = 0; j < K; j++) {
      if (i & (1ll << j)) {
        r |= (1ll << (K - j - 1));
      }
    }
    if (i < r) {
      swap(a[i], a[r]);
    }
  }
  for (int i = 1, pl = N / 2; i < N; i *= 2, pl /= 2) {
    for (int j = 0; j < N; j += 2 * i) {
      for (int k = j, cur = 0; k < j + i; k++, cur += pl) {
        int L = a[k];
        int R = 1ll * pw[cur] * a[k + i] % (long long)(998244353ll);
        a[k] = L + R;
        if (a[k] >= (long long)(998244353ll)) {
          a[k] -= (long long)(998244353ll);
          ;
        }
        a[k + i] = L - R;
        if (a[k + i] < 0) {
          a[k + i] += (long long)(998244353ll);
        }
      }
    }
  }
}
void make_mult(int* a, int* b, int* c) {
  fft(a, pw);
  fft(b, pw);
  for (int i = 0; i < N; i++) {
    c[i] = 1ll * a[i] * b[i] % (long long)(998244353ll);
  }
  fft(c, rpw);
  for (int i = 0; i < N; i++) {
    c[i] = 1ll * c[i] * rev_N % (long long)(998244353ll);
  }
}
const int B = 1000;
int fft_bl[N / B + 10][N];
int a[N];
int b[N];
int dp[B + 10][B + 10];
int ans_fft[N];
int main() {
  init();
  rev_N = bpow(N, (long long)(998244353ll) - 2);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  auto get_ans = [&](int q) {
    for (int i = 0; i < n; i++) {
      b[i] = q - a[i];
      b[i] %= (long long)(998244353ll);
      if (b[i] < 0) {
        b[i] += (long long)(998244353ll);
      }
    }
    int num = 0;
    for (int bl_st = 0; bl_st < n; bl_st += B) {
      int L = bl_st;
      int R = min(n - 1, L + B - 1);
      memset(dp, 0, sizeof(dp));
      dp[0][0] = 1;
      for (int j = L; j <= R; j++) {
        for (int t = 0; t <= j - L; t++) {
          inc(dp[j - L + 1][t], dp[j - L][t]);
          inc(dp[j - L + 1][t + 1],
              1ll * dp[j - L][t] * b[j] % (long long)(998244353ll));
        }
      }
      for (int j = 0; j <= B; j++) {
        fft_bl[num][j] = dp[R - L + 1][j];
      }
      for (int j = B + 1; j < N; j++) {
        fft_bl[num][j] = 0;
      }
      num++;
    }
    memset(ans_fft, 0, sizeof(ans_fft));
    ans_fft[0] = 1;
    for (int i = 0; i < num; i++) {
      make_mult(ans_fft, fft_bl[i], ans_fft);
    }
    return ans_fft[k];
  };
  int Q;
  cin >> Q;
  while (Q--) {
    int type, q;
    cin >> type >> q;
    if (type == 1) {
      int pos, d;
      cin >> pos >> d;
      pos--;
      int buf = a[pos];
      a[pos] = d;
      cout << get_ans(q) << "\n";
      a[pos] = buf;
    } else {
      int l, r, d;
      cin >> l >> r >> d;
      l--;
      r--;
      for (int j = l; j <= r; j++) {
        a[j] += d;
      }
      cout << get_ans(q) << "\n";
      for (int j = l; j <= r; j++) {
        a[j] -= d;
      }
    }
  }
}

```


### Prompt

Please create a solution in cpp to the following problem:

During the loading of the game "Dungeons and Candies" you are required to get descriptions of k levels from the server. Each description is a map of an n × m checkered rectangular field. Some cells of the field contain candies (each cell has at most one candy). An empty cell is denoted as "." on the map, but if a cell has a candy, it is denoted as a letter of the English alphabet. A level may contain identical candies, in this case the letters in the corresponding cells of the map will be the same.

<image>

When you transmit information via a network, you want to minimize traffic — the total size of the transferred data. The levels can be transmitted in any order. There are two ways to transmit the current level A:

  1. You can transmit the whole level A. Then you need to transmit n·m bytes via the network.
  2. You can transmit the difference between level A and some previously transmitted level B (if it exists); this operation requires to transmit dA, B·w bytes, where dA, B is the number of cells of the field that are different for A and B, and w is a constant. Note, that you should compare only the corresponding cells of levels A and B to calculate dA, B. You cannot transform the maps of levels, i.e. rotate or shift them relatively to each other.

Your task is to find a way to transfer all the k levels and minimize the traffic.

Input

The first line contains four integers n, m, k, w (1 ≤ n, m ≤ 10; 1 ≤ k, w ≤ 1000). Then follows the description of k levels. Each level is described by n lines, each line contains m characters. Each character is either a letter of the English alphabet or a dot ("."). Please note that the case of the letters matters.

Output

In the first line print the required minimum number of transferred bytes.

Then print k pairs of integers x1, y1, x2, y2, ..., xk, yk, describing the way to transfer levels. Pair xi, yi means that level xi needs to be transferred by way yi. If yi equals 0, that means that the level must be transferred using the first way, otherwise yi must be equal to the number of a previously transferred level. It means that you will transfer the difference between levels yi and xi to transfer level xi. Print the pairs in the order of transferring levels. The levels are numbered 1 through k in the order they follow in the input.

If there are multiple optimal solutions, you can print any of them.

Examples

Input

2 3 3 2
A.A
...
A.a
..C
X.Y
...

Output

14
1 0
2 1
3 1

Input

1 1 4 1
A
.
B
.

Output

3
1 0
2 0
4 2
3 0

Input

1 3 5 2
ABA
BBB
BBA
BAB
ABB

Output

11
1 0
3 1
2 3
4 2
5 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int n, m, k, w;
vector<vector<vector<char>>> mp;
struct dsu {
  vector<long long int> p, sz;
  dsu(long long int n) {
    p.resize(n);
    sz.resize(n, 1);
    for (long long int i = 0; i < n; i++) p[i] = i;
  }
  long long int getRoot(long long int v) {
    if (p[v] == v)
      return v;
    else
      return p[v] = getRoot(p[v]);
  }
  void unite(long long int a, long long int b) {
    a = getRoot(a);
    b = getRoot(b);
    if (a != b) {
      if (sz[a] < sz[b]) swap(a, b);
      p[b] = a;
      sz[a] += sz[b];
    }
  }
  bool inOne(long long int a, long long int b) {
    a = getRoot(a);
    b = getRoot(b);
    return a == b;
  }
};
long long int getR(long long int a, long long int b) {
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      ans += (mp[a][i][j] != mp[b][i][j]);
    }
  }
  return ans;
}
struct edge {
  long long int a, b, w;
  edge(long long int a = 0, long long int b = 0, long long int w = 0) {
    this->a = a;
    this->b = b;
    this->w = w;
  }
};
bool cmp(const edge& a, const edge& b) { return a.w < b.w; }
vector<vector<long long int>> g;
vector<pair<long long int, long long int>> path;
void dfs(long long int v = 0, long long int p = -1) {
  if (p > -1) path.push_back({v, p});
  for (auto to : g[v]) {
    if (to == p) continue;
    dfs(to, v);
  }
}
signed main() {
  cin >> n >> m >> k >> w;
  mp.resize(k + 1, vector<vector<char>>(n, vector<char>(m)));
  g.resize(k + 1);
  for (long long int i = 1; i <= k; i++) {
    for (long long int j = 0; j < n; j++) {
      for (long long int w = 0; w < m; w++) cin >> mp[i][j][w];
    }
  }
  vector<edge> ed;
  for (long long int i = 1; i <= k; i++) ed.push_back(edge(0, i, n * m));
  for (long long int i = 1; i <= k; i++) {
    for (long long int j = i + 1; j <= k; j++)
      ed.push_back(edge(i, j, getR(i, j) * w));
  }
  sort(ed.begin(), ed.end(), cmp);
  dsu s(k + 1);
  long long int ans = 0;
  for (auto e : ed) {
    long long int a = e.a, b = e.b, w = e.w;
    if (s.inOne(a, b)) continue;
    ans += w;
    s.unite(a, b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs();
  cout << ans << "\n";
  for (auto i : path) cout << i.first << " " << i.second << "\n";
  return 0;
}

```


### Prompt

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

Recently Vova found n candy wrappers. He remembers that he bought x candies during the first day, 2x candies during the second day, 4x candies during the third day, ..., 2^{k-1} x candies during the k-th day. But there is an issue: Vova remembers neither x nor k but he is sure that x and k are positive integers and k > 1.

Vova will be satisfied if you tell him any positive integer x so there is an integer k>1 that x + 2x + 4x + ... + 2^{k-1} x = n. It is guaranteed that at least one solution exists. Note that k > 1.

You have to answer t independent test cases.

Input

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

The only line of the test case contains one integer n (3 ≤ n ≤ 10^9) — the number of candy wrappers Vova found. It is guaranteed that there is some positive integer x and integer k>1 that x + 2x + 4x + ... + 2^{k-1} x = n.

Output

Print one integer — any positive integer value of x so there is an integer k>1 that x + 2x + 4x + ... + 2^{k-1} x = n.

Example

Input

7
3
6
7
21
28
999999999
999999984

Output

1
2
1
7
4
333333333
333333328

Note

In the first test case of the example, one of the possible answers is x=1, k=2. Then 1 ⋅ 1 + 2 ⋅ 1 equals n=3.

In the second test case of the example, one of the possible answers is x=2, k=2. Then 1 ⋅ 2 + 2 ⋅ 2 equals n=6.

In the third test case of the example, one of the possible answers is x=1, k=3. Then 1 ⋅ 1 + 2 ⋅ 1 + 4 ⋅ 1 equals n=7.

In the fourth test case of the example, one of the possible answers is x=7, k=2. Then 1 ⋅ 7 + 2 ⋅ 7 equals n=21.

In the fifth test case of the example, one of the possible answers is x=4, k=3. Then 1 ⋅ 4 + 2 ⋅ 4 + 4 ⋅ 4 equals n=28.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 9;
long long power(long long x, long long y) {
  if (y == 0) return 1;
  long long temp = power(x, y / 2);
  if (y % 2 == 1)
    return temp * temp * x;
  else
    return temp * temp;
}
void solve() {
  long long n;
  cin >> n;
  long long s = 1;
  for (long long i = 2;;) {
    s += i;
    if (n % s == 0) {
      cout << n / s << "\n";
      return;
    }
    i = i << 1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

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

You are given two strings s and t. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by 1. You can't choose a string if it is empty.

For example:

  * by applying a move to the string "where", the result is the string "here",
  * by applying a move to the string "a", the result is an empty string "".

You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings.

Write a program that finds the minimum number of moves to make two given strings s and t equal.

Input

The first line of the input contains s. In the second line of the input contains t. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and 2⋅10^5, inclusive.

Output

Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.

Examples

Input

test
west

Output

2

Input

codeforces
yes

Output

9

Input

test
yes

Output

7

Input

b
ab

Output

1

Note

In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".

In the second example, the move should be applied to the string "codeforces" 8 times. As a result, the string becomes "codeforces" → "es". The move should be applied to the string "yes" once. The result is the same string "yes" → "es".

In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty.

In the fourth example, the first character of the second string should be deleted.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string s, st;
int ans;
int main() {
  cin >> s >> st;
  for (int i = 0;; i++) {
    int ind_s = s.size() - 1 - i;
    int ind_st = st.size() - 1 - i;
    if (ind_s < 0 || ind_st < 0) break;
    if (s[ind_s] != st[ind_st]) break;
    ans = ans + 2;
  }
  ans = st.size() + s.size() - ans;
  cout << ans;
}

```


### Prompt

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

IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids — one triangular, one quadrangular and one pentagonal.

The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.

<image>

Input

The only line of the input contains three integers l3, l4, l5 (1 ≤ l3, l4, l5 ≤ 1000) — the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.

Output

Output one number — the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.

Examples

Input

2 5 3

Output

38.546168065709

### Response

```cpp
#include <bits/stdc++.h>
int sgn(double x) { return -1 ? x < -1e-8 : x > 1e-8; }
using namespace std;
int main() {
  long double l3, l4, l5;
  cin >> l3 >> l4 >> l5;
  long double sd = 5 * l5 * l5 / 2 / (1 - cos(72 * acos(-1.0) / 180)) *
                   sin(72 * acos(-1.0) / 180) / 2;
  long double h5 =
      sqrt(l5 * l5 - l5 * l5 / 2 / (1 - cos(72 * acos(-1.0) / 180)));
  cout << setprecision(12) << fixed
       << ((l3 * l3 * l3) * sqrt(2) / 4 + (l4 * l4 * l4) * sqrt(2) / 2 +
           sd * h5) /
              3
       << endl;
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

A divisor tree is a rooted tree that meets the following conditions:

  * Each vertex of the tree contains a positive integer number.
  * The numbers written in the leaves of the tree are prime numbers.
  * For any inner vertex, the number within it is equal to the product of the numbers written in its children.

Manao has n distinct integers a1, a2, ..., an. He tries to build a divisor tree which contains each of these numbers. That is, for each ai, there should be at least one vertex in the tree which contains ai. Manao loves compact style, but his trees are too large. Help Manao determine the minimum possible number of vertices in the divisor tree sought.

Input

The first line contains a single integer n (1 ≤ n ≤ 8). The second line contains n distinct space-separated integers ai (2 ≤ ai ≤ 1012).

Output

Print a single integer — the minimum number of vertices in the divisor tree that contains each of the numbers ai.

Examples

Input

2
6 10

Output

7

Input

4
6 72 8 4

Output

12

Input

1
7

Output

1

Note

Sample 1. The smallest divisor tree looks this way: <image>

Sample 2. In this case you can build the following divisor tree: <image>

Sample 3. Note that the tree can consist of a single vertex.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long A[11];
int f[11], n;
int ans = 1 << 30, sum, s;
int cmp(const void *xx, const void *yy) {
  long long x = *(long long *)xx, y = *(long long *)yy;
  if (x > y) return -1;
  return 1;
}
void dfs(int x) {
  if (x == n + 1) {
    ans = min(ans, sum + (s != 1));
    return;
  }
  int i;
  s++;
  dfs(x + 1);
  s--;
  for (i = 1; i < x; i++)
    if (A[i] % A[x] == 0) {
      A[i] /= A[x];
      sum -= f[x];
      dfs(x + 1);
      sum += f[x];
      A[i] *= A[x];
    }
}
int main() {
  int i, j;
  long long x;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%I64d", &A[i]);
  qsort(A + 1, n, sizeof(long long), cmp);
  for (i = 1; i <= n; i++) {
    x = A[i];
    for (j = 2; (long long)j * j <= x; j++)
      while (x % j == 0) x /= j, f[i]++;
    if (x != 1) f[i]++;
    if (f[i] == 1)
      sum++;
    else
      sum += f[i] + 1;
  }
  dfs(1);
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

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

In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...

For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.

However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.

This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).

In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?

Input

The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).

Output

Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.

Examples

Input

3 2

Output

5

Input

3 3

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long dp[40][40];
int n, h;
int main() {
  scanf("%d%d", &n, &h);
  for (int i = 0; i <= n; i++) dp[0][i] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 0; k < i; k++)
        dp[i][j] += dp[k][j - 1] * dp[i - k - 1][j - 1];
  printf("%lld\n", dp[n][n] - dp[n][h - 1]);
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

At first, there was a legend related to the name of the problem, but now it's just a formal statement.

You are given n points a_1, a_2, ..., a_n on the OX axis. Now you are asked to find such an integer point x on OX axis that f_k(x) is minimal possible.

The function f_k(x) can be described in the following way:

  * form a list of distances d_1, d_2, ..., d_n where d_i = |a_i - x| (distance between a_i and x);
  * sort list d in non-descending order;
  * take d_{k + 1} as a result.

If there are multiple optimal answers you can print any of them.

Input

The first line contains single integer T ( 1 ≤ T ≤ 2 ⋅ 10^5) — number of queries. Next 2 ⋅ T lines contain descriptions of queries. All queries are independent.

The first line of each query contains two integers n, k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k < n) — the number of points and constant k.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_1 < a_2 < ... < a_n ≤ 10^9) — points in ascending order.

It's guaranteed that ∑{n} doesn't exceed 2 ⋅ 10^5.

Output

Print T integers — corresponding points x which have minimal possible value of f_k(x). If there are multiple answers you can print any of them.

Example

Input

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

Output

3
500000000
4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k;
long long int a[200005], d[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    long long int ans = 1e9, x = a[0];
    for (int i = k; i < n; ++i) {
      long long int k1 = (a[i] + a[i - k]) / 2;
      if (ans > max(k1 - a[i - k], a[i] - k1)) {
        ans = max(k1 - a[i - k], a[i] - k1);
        x = k1;
      }
    }
    cout << x << "\n";
  }
  return 0;
}

```


### Prompt

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

Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.

Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.

Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.

Input

The first line contains two numbers n, k (1 ≤ n ≤ 100, 0 ≤ k ≤ 10 000), the number of instruments and number of days respectively.

The second line contains n integers ai (1 ≤ ai ≤ 100), representing number of days required to learn the i-th instrument.

Output

In the first line output one integer m representing the maximum number of instruments Amr can learn.

In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order.

if there are multiple optimal solutions output any. It is not necessary to use all days for studying.

Examples

Input

4 10
4 3 1 2

Output

4
1 2 3 4

Input

5 6
4 3 1 1 2

Output

3
1 3 4

Input

1 3
4

Output

0

Note

In the first test Amr can learn all 4 instruments.

In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.

In the third test Amr doesn't have enough time to learn the only presented instrument.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, r = 0, a = 0, t = 0, f = 0;
  ;
  cin >> n >> m;
  pair<int, int> A[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> A[i].first;
    A[i].second = i;
  }
  int d = 0;
  sort(A, A + n + 1);
  for (int i = 1; i <= n; i++) {
    d = 0;
    f = 0;
    for (int j = 1; j <= n; j++) {
      if (d + A[j].first <= m) {
        d += A[j].first;
        f++;
      }
    }
    if (d > r) {
      a = i;
      r = d;
      t = f;
    }
  }
  if (t == 0) {
    cout << t;
    return 0;
  }
  cout << t << endl;
  d = 0;
  for (int i = a; i <= n; i++) {
    if (d + A[i].first <= m) {
      d += A[i].first;
      cout << A[i].second << " ";
    } else
      break;
  }
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Today at the lesson of mathematics, Petya learns about the digital root.

The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.

Let's denote the digital root of x as S(x). Then S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1.

As a homework Petya got n tasks of the form: find k-th positive number whose digital root is x.

Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all n tasks from Petya's homework.

Input

The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks in Petya's homework. The next n lines contain two integers k_i (1 ≤ k_i ≤ 10^{12}) and x_i (1 ≤ x_i ≤ 9) — i-th Petya's task in which you need to find a k_i-th positive number, the digital root of which is x_i.

Output

Output n lines, i-th line should contain a single integer — the answer to the i-th problem.

Example

Input

3
1 5
5 2
3 1

Output

5
38
19

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5;
long long n, m, a[maxn + 4], k, id[maxn + 3], counter;
int kt[maxn + 3], dem, ans = 0;
vector<int> d;
vector<int>::iterator it, w;
string s;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  cin >> m;
  while (m-- > 0) {
    cin >> k >> n;
    cout << (long long)9 * (k - 1) + n << "\n";
  }
}

```


### Prompt

Generate a cpp solution to the following problem:

Problem statement

Cards with ranks of $ 2 $ and $ 8 $ are powerful in card game millionaires. Therefore, we call an integer consisting of only the numbers $ 2 $ and $ 8 $ in $ 10 $ decimal notation a good integer. The best integers are listed from the smallest to $ 2, 8, 22, 28, 82, 88, \ cdots $.

Let $ n $ be a positive integer. When $ n $ can be expressed in the form of a product of good integers, find the maximum product. If you can't, output $ -1 $.

Constraint

$ 1 \ leq n \ leq 10 ^ {18} $

sample

Sample input 1

1

Sample output 1

-1

Sample input 2

2

Sample output 2

1

Sample input 3

88

Sample output 3

3

It can be expressed as $ 2 \ times 2 \ times 22 $.

Sample input 4

100

Sample output 4

-1

Sample input 5

173553147234869248

Sample output 5

11

It can be expressed as $ 2 ^ 6 \ times 28 \ times 2222 ^ 3 \ times 8828 $.

input

$ n $

output

Print the answer on the $ 1 $ line.

Example

Input

1

Output

-1

### Response

```cpp
#include<iostream>
#include<vector>
#include<cassert>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<tuple>
#include<numeric>
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef ll int__;
#define rep(i,j) for(int__ i=0;i<(int__)(j);i++)
#define repeat(i,j,k) for(int__ i=(j);i<(int__)(k);i++)
#define all(v) v.begin(),v.end()
const int INF = 1 << 30;
template<typename T>
ostream& operator << (ostream &os , const vector<T> &v){
    rep(i,v.size()) os << v[i] << (i!=v.size()-1 ? " " : ""); return os;
}

template<typename T>
istream& operator >> (istream &is , vector<T> &v){
    rep(i,v.size()) is >> v[i]; return is;
}

bool is_good_number(ll n){
    while(n){
        if(n % 10 != 2 and n %10 != 8) return false;
        n /= 10;
    }
    return true;
}

pair<int,ll> div2(ll n){
    int cnt = 0;
    while(n % 2 == 0) n /= 2, cnt++;
    return make_pair(cnt, n);
}

vector<pair<int,ll>> calc_good_number(ll upper){
    vector<pair<int,ll>> res;
    set<ll> memo;
    queue<ll> que;
    que.push(2);
    que.push(8);
    while(que.size()){
        ll n = que.front(); que.pop();
        auto p = div2(n);
        if(not memo.count(p.second)){
            res.push_back(div2(n));
            memo.insert(p.second);
        }

        if(n < upper){
            que.push(n * 10 + 2);
            que.push(n * 10 + 8);
        }
    }
    return res;
}

map<pair<int,ll>, int> dp;
int dfs(const vector<pair<int,ll>> &good_number, int now, int left2, ll left){
    if(left == 1) return left2;
    if(dp.count(make_pair(left2, left))) return dp[make_pair(left2, left)];
    int ans = -INF;
    while(now < (int)good_number.size()){
        if(left % good_number[now].second == 0 and left2 >= good_number[now].first){
            ans = max(ans, dfs(good_number, now, left2 - good_number[now].first, left / good_number[now].second));
        }
        now++;
    }
    return dp[make_pair(left2, left)] = ans + 1;
}

bool solve(){
    ll n; cin >> n;
    if(n == 1){
        cout << -1 << endl;
        return 0;
    }
    vector<pair<int,ll>> good_number = calc_good_number(sqrt(n) + 1);
    //rep(i, good_number.size()) cerr << good_number[i].second << endl;
    bool flg = false;
    if(is_good_number(n)) flg = true;
    int left2 = 0;
    while(n % 2 == 0) n /= 2, left2++;
    int res = dfs(good_number, 0, left2, n);
    if(flg) res = max(1, res);
    cout << (res < 0 ? -1 : res) << endl;
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    while(solve());
    return 0;
}
```


### Prompt

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

Lunar New Year is approaching, and Bob is planning to go for a famous restaurant — "Alice's".

The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for serving exactly a_i dishes of the i-th kind. In the New Year's Eve, m customers will visit Alice's one after another and the j-th customer will order d_j dishes of the t_j-th kind of food. The (i + 1)-st customer will only come after the i-th customer is completely served.

Suppose there are r_i dishes of the i-th kind remaining (initially r_i = a_i). When a customer orders 1 dish of the i-th kind, the following principles will be processed.

  1. If r_i > 0, the customer will be served exactly 1 dish of the i-th kind. The cost for the dish is c_i. Meanwhile, r_i will be reduced by 1.
  2. Otherwise, the customer will be served 1 dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by 1.
  3. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is 0.

If the customer doesn't leave after the d_j dishes are served, the cost for the customer will be the sum of the cost for these d_j dishes.

Please determine the total cost for each of the m customers.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 10^5), representing the number of different kinds of food and the number of customers, respectively.

The second line contains n positive integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^7), where a_i denotes the initial remain of the i-th kind of dishes.

The third line contains n positive integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^6), where c_i denotes the cost of one dish of the i-th kind.

The following m lines describe the orders of the m customers respectively. The j-th line contains two positive integers t_j and d_j (1 ≤ t_j ≤ n, 1 ≤ d_j ≤ 10^7), representing the kind of food and the number of dishes the j-th customer orders, respectively.

Output

Print m lines. In the j-th line print the cost for the j-th customer.

Examples

Input

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

Output

22
24
14
10
39

Input

6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 6
3 6
4 6
5 6
6 66

Output

36
396
3996
39996
399996
0

Input

6 6
6 6 6 6 6 6
6 66 666 6666 66666 666666
1 6
2 13
3 6
4 11
5 6
6 6

Output

36
11058
99996
4333326
0
0

Note

In the first sample, 5 customers will be served as follows.

  1. Customer 1 will be served 6 dishes of the 2-nd kind, 1 dish of the 4-th kind, and 1 dish of the 6-th kind. The cost is 6 ⋅ 3 + 1 ⋅ 2 + 1 ⋅ 2 = 22. The remain of the 8 kinds of food will be \{8, 0, 2, 0, 4, 4, 7, 5\}.
  2. Customer 2 will be served 4 dishes of the 1-st kind. The cost is 4 ⋅ 6 = 24. The remain will be \{4, 0, 2, 0, 4, 4, 7, 5\}.
  3. Customer 3 will be served 4 dishes of the 6-th kind, 3 dishes of the 8-th kind. The cost is 4 ⋅ 2 + 3 ⋅ 2 = 14. The remain will be \{4, 0, 2, 0, 4, 0, 7, 2\}.
  4. Customer 4 will be served 2 dishes of the 3-rd kind, 2 dishes of the 8-th kind. The cost is 2 ⋅ 3 + 2 ⋅ 2 = 10. The remain will be \{4, 0, 0, 0, 4, 0, 7, 0\}.
  5. Customer 5 will be served 7 dishes of the 7-th kind, 3 dishes of the 1-st kind. The cost is 7 ⋅ 3 + 3 ⋅ 6 = 39. The remain will be \{1, 0, 0, 0, 4, 0, 0, 0\}.

In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served 6 dishes of the second kind, so the cost is 66 ⋅ 6 = 396.

In the third sample, some customers may not be served what they order. For example, the second customer is served 6 dishes of the second kind, 6 of the third and 1 of the fourth, so the cost is 66 ⋅ 6 + 666 ⋅ 6 + 6666 ⋅ 1 = 11058.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200001;
const long long mod = 1e9 + 7;
int main() {
  int N, M, ind = 0;
  scanf("%d %d", &N, &M);
  long long nums[N], arr[N];
  pair<long long, int> arr2[N];
  for (int i = 0; i < N; i++) {
    scanf("%lld", &nums[i]);
  }
  for (int i = 0; i < N; i++) {
    scanf("%lld", &arr[i]);
    arr2[i] = {arr[i], i};
  }
  sort(arr2, arr2 + N);
  long long res, a, b;
  for (int i = 0; i < M; i++) {
    scanf("%lld %lld", &a, &b);
    a--;
    if (nums[a] >= b) {
      printf("%lld\n", b * arr[a]);
      nums[a] -= b;
      continue;
    } else {
      res = 0;
      res = nums[a] * arr[a];
      b -= nums[a];
      nums[a] = 0;
      while (ind < N && b) {
        if (nums[arr2[ind].second] >= b) {
          res += b * arr[arr2[ind].second];
          nums[arr2[ind].second] -= b;
          b = 0;
        } else {
          res += nums[arr2[ind].second] * arr[arr2[ind].second];
          b -= nums[arr2[ind].second];
          nums[arr2[ind].second] = 0;
          ind++;
        }
      }
    }
    if (b)
      printf("0\n");
    else
      printf("%lld\n", res);
  }
}

```