### Prompt

Develop a solution in cpp to the problem described below:

Billy investigates the question of applying greedy algorithm to different spheres of life. At the moment he is studying the application of greedy algorithm to the problem about change. There is an amount of n coins of different face values, and the coins of each value are not limited in number. The task is to collect the sum x with the minimum amount of coins. Greedy algorithm with each its step takes the coin of the highest face value, not exceeding x. Obviously, if among the coins' face values exists the face value 1, any sum x can be collected with the help of greedy algorithm. However, greedy algorithm does not always give the optimal representation of the sum, i.e. the representation with the minimum amount of coins. For example, if there are face values {1, 3, 4} and it is asked to collect the sum 6, greedy algorithm will represent the sum as 4 + 1 + 1, while the optimal representation is 3 + 3, containing one coin less. By the given set of face values find out if there exist such a sum x that greedy algorithm will collect in a non-optimal way. If such a sum exists, find out the smallest of these sums.

Input

The first line contains an integer n (1 ≤ n ≤ 400) — the amount of the coins' face values. The second line contains n integers ai (1 ≤ ai ≤ 109), describing the face values. It is guaranteed that a1 > a2 > ... > an and an = 1.

Output

If greedy algorithm collects any sum in an optimal way, output -1. Otherwise output the smallest sum that greedy algorithm collects in a non-optimal way.

Examples

Input

5
25 10 5 2 1

Output

-1

Input

3
4 3 1

Output

6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, ans, a[500], b[500], c[500];
int deal(int x) {
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    b[i] = x / a[i];
    ans += b[i];
    x %= a[i];
    if (!x) break;
  }
  return ans;
}
bool cmp(int a, int b) { return a > b; }
int main() {
  cin.sync_with_stdio(false);
  ans = 2100000007;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n, cmp);
  for (int i = 1; i < n; i++) {
    deal(a[i] - 1);
    for (int i = 1; i <= n; i++) c[i] = b[i];
    for (int j = i + 1; j <= n; j++) {
      int temp = 0, temp2 = 0;
      for (int k = 1; k <= j; k++) {
        temp2 += a[k] * c[k];
        temp += c[k];
      }
      temp2 += a[j], temp++;
      if (deal(temp2) > temp) ans = min(temp2, ans);
    }
  }
  if (ans == 2100000007)
    cout << -1 << endl;
  else
    cout << ans << endl;
}

```


### Prompt

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

Recently a lot of students were enrolled in Berland State University. All students were divided into groups according to their education program. Some groups turned out to be too large to attend lessons in the same auditorium, so these groups should be divided into two subgroups. Your task is to help divide the first-year students of the computer science faculty.

There are t new groups belonging to this faculty. Students have to attend classes on three different subjects — maths, programming and P. E. All classes are held in different places according to the subject — maths classes are held in auditoriums, programming classes are held in computer labs, and P. E. classes are held in gyms.

Each group should be divided into two subgroups so that there is enough space in every auditorium, lab or gym for all students of the subgroup. For the first subgroup of the i-th group, maths classes are held in an auditorium with capacity of a_{i, 1} students; programming classes are held in a lab that accomodates up to b_{i, 1} students; and P. E. classes are held in a gym having enough place for c_{i, 1} students. Analogically, the auditorium, lab and gym for the second subgroup can accept no more than a_{i, 2}, b_{i, 2} and c_{i, 2} students, respectively.

As usual, some students skip some classes. Each student considers some number of subjects (from 0 to 3) to be useless — that means, he skips all classes on these subjects (and attends all other classes). This data is given to you as follows — the i-th group consists of:

  1. d_{i, 1} students which attend all classes;
  2. d_{i, 2} students which attend all classes, except for P. E.;
  3. d_{i, 3} students which attend all classes, except for programming;
  4. d_{i, 4} students which attend only maths classes;
  5. d_{i, 5} students which attend all classes, except for maths;
  6. d_{i, 6} students which attend only programming classes;
  7. d_{i, 7} students which attend only P. E.

There is one more type of students — those who don't attend any classes at all (but they, obviously, don't need any place in auditoriums, labs or gyms, so the number of those students is insignificant in this problem).

Your task is to divide each group into two subgroups so that every auditorium (or lab, or gym) assigned to each subgroup has enough place for all students from this subgroup attending the corresponding classes (if it is possible). Each student of the i-th group should belong to exactly one subgroup of the i-th group; it is forbidden to move students between groups.

Input

The first line contains one integer t (1 ≤ t ≤ 300) — the number of groups.

Then the descriptions of groups follow. The description of the i-th group consists of three lines:

  * the first line contains three integers a_{i, 1}, b_{i, 1} and c_{i, 1} (1 ≤ a_{i, 1}, b_{i, 1}, c_{i, 1} ≤ 3000) — the capacity of the auditorium, lab and gym assigned to the first subgroup of the i-th group, respectively;
  * the second line contains three integers a_{i, 2}, b_{i, 2} and c_{i, 2} (1 ≤ a_{i, 2}, b_{i, 2}, c_{i, 2} ≤ 3000) — the capacity of the auditorium, lab and gym assigned to the second subgroup of the i-th group, respectively;
  * the third line contains integers d_{i, 1}, d_{i, 2}, ..., d_{i, 7} (0 ≤ d_{i, j} ≤ 3000) — the number of students belonging to each of the seven aforementioned types in the i-th group. It is not guaranteed that the sum of these values is positive — a group can consist entirely of students that don't attend classes at all.

It is guaranteed that the total number of students in all groups is not greater than 3000.

Output

For each group, print the result of its division as follows:

  * if it is impossible to divide the group, print one integer -1;
  * otherwise print seven integers f_{i, 1}, f_{i, 2}, ..., f_{i, 7} (0 ≤ f_{i, j} ≤ d_{i, j}) — the number of students the first, second, ..., seventh type in the first subgroup of the i-th group (all other students will be assigned to the second subgroup). If there are multiple answers, print any of them.

Example

Input

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

Output

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
double const eps = 1e-7;
struct LP {
  int n;
  vector<vector<double> > e;
  void adeq(vector<double> const &v) { e.push_back(v); }
  int bad() {
    for (int i = 1; i < (int)(e.size()); ++i)
      if (e[i][n] < -eps) {
        for (int j = 0; j < (int)(n); ++j)
          if (e[i][j] < -eps) return j;
        return -2;
      }
    return -1;
  }
  int getkl() {
    for (int i = 0; i < (int)(n); ++i)
      if (e[0][i] > eps) return i;
    return -1;
  }
  int getmn(int j) {
    int an = 0;
    double mn = 1e18;
    for (int i = 1; i < (int)(e.size()); ++i)
      if (e[i][j] > eps) {
        double t = e[i][n] / e[i][j];
        if (t < mn) mn = t, an = i;
      }
    return an;
  }
  void kl(int j) {
    int i = getmn(j);
    double t = e[i][j];
    for (int k = 0; k < (int)(e[i].size()); ++k) e[i][k] /= t;
    for (int k = 0; k < (int)(e.size()); ++k)
      if (k != i) {
        double z = e[k][j];
        for (int w = 0; w < (int)(e[k].size()); ++w) e[k][w] -= z * e[i][w];
      }
  }
  void pl() {
    int t = e[0].size() - 1;
    n = e[0].size() + e.size() - 2;
    for (int i = 0; i < (int)(e.size()); ++i) e[i].resize(n + 1);
    for (int i = 1; i < (int)(e.size()); ++i) swap(e[i][t], e[i][n]);
    for (int i = 1; i < (int)(e.size()); ++i) e[i][t + i - 1] = 1.0;
  }
  pair<double, bool> solve() {
    pl();
    int j;
    while ((j = bad()) >= 0) kl(j);
    if (j == -2) return make_pair(0.0, false);
    while ((j = getkl()) >= 0) kl(j);
    return make_pair(-e[0][n], true);
  }
  vector<double> gtval(int m) {
    vector<char> vis(e.size());
    vis[0] = true;
    vector<double> an(m);
    for (int i = 0; i < (int)(m); ++i)
      if (abs(e[0][i]) < eps) {
        int j = 0;
        for (int k = 1; k < (int)(e.size()); ++k)
          if (abs(e[k][i]) > eps) {
            if (j) {
              j = 0;
              break;
            }
            j = k;
          }
        if (!vis[j]) {
          an[i] = e[j][n] / e[j][i];
          vis[j] = true;
        }
      }
    return an;
  }
};
int g[2][3], fr[8];
bool ok(vector<int> const &v) {
  int sm[2][3] = {};
  for (int i = 0; i < (int)(v.size()); ++i)
    for (int j = 0; j < (int)(3); ++j)
      if (i + 1 >> j & 1) {
        sm[0][j] += v[i];
        sm[1][j] += fr[i + 1] - v[i];
      }
  for (int i = 0; i < (int)(3); ++i)
    if (g[0][2 - i] < sm[0][i] || g[1][2 - i] < sm[1][i]) return false;
  return true;
}
void solve() {
  for (int i = 0; i < (int)(2); ++i)
    for (int j = 0; j < (int)(3); ++j) scanf("%d", g[i] + j);
  for (int i = 7; i > 0; --i) scanf("%d", fr + i);
  LP s;
  vector<double> v(8);
  s.adeq(v);
  for (int i = 0; i < (int)(7); ++i) {
    for (int j = 0; j < (int)(7); ++j) v[j] = 0;
    v[i] = 1;
    v[7] = fr[i + 1];
    s.adeq(v);
    v[i] = -1;
    v[7] = 0;
    s.adeq(v);
  }
  for (int i = 0; i < (int)(3); ++i) {
    for (int j = 1; j < (int)(8); ++j) v[j - 1] = j >> i & 1;
    v[7] = g[0][2 - i];
    s.adeq(v);
    int z = 0;
    for (int j = 1; j < (int)(8); ++j)
      if (v[j - 1]) {
        v[j - 1] *= -1;
        z += fr[j];
      }
    v[7] = -(z - g[1][2 - i]);
    s.adeq(v);
  }
  if (!s.solve().second) {
    printf("-1\n");
    return;
  }
  vector<double> val = s.gtval(7);
  vector<int> an(7);
  for (int i = 0; i < (int)(1 << 7); ++i) {
    for (int j = 0; j < (int)(7); ++j)
      an[j] = val[j] + 0.5 + (i >> j & 1 ? -eps : eps);
    if (ok(an)) break;
  }
  if (!ok(an)) {
    printf("-1\n");
    return;
  }
  for (int i = 0; i < (int)(7); ++i) printf("%d ", an[6 - i]);
  printf("\n");
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
}

```


### Prompt

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

You are given four integers n, c_0, c_1 and h and a binary string s of length n.

A binary string is a string consisting of characters 0 and 1.

You can change any character of the string s (the string should be still binary after the change). You should pay h coins for each change.

After some changes (possibly zero) you want to buy the string. To buy the string you should buy all its characters. To buy the character 0 you should pay c_0 coins, to buy the character 1 you should pay c_1 coins.

Find the minimum number of coins needed to buy the string.

Input

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

The first line of the description of each test case contains four integers n, c_{0}, c_{1}, h (1 ≤ n, c_{0}, c_{1}, h ≤ 1000).

The second line of the description of each test case contains the binary string s of length n.

Output

For each test case print a single integer — the minimum number of coins needed to buy the string.

Example

Input

6
3 1 1 1
100
5 10 100 1
01010
5 10 1 1
11111
5 1 10 1
11111
12 2 1 10
101110110101
2 100 1 10
00

Output

3
52
5
10
16
22

Note

In the first test case, you can buy all characters and pay 3 coins, because both characters 0 and 1 costs 1 coin.

In the second test case, you can firstly change 2-nd and 4-th symbols of the string from 1 to 0 and pay 2 coins for that. Your string will be 00000. After that, you can buy the string and pay 5 ⋅ 10 = 50 coins for that. The total number of coins paid will be 2 + 50 = 52.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, c, a, h;
    cin >> n >> c >> a >> h;
    string s;
    cin >> s;
    int sum = 0;
    if (c == a) {
      cout << (n * c) << endl;
    } else {
      if (abs(c - a) > h) {
        if (c < a) {
          for (int i = 0; i < s.length(); i++) {
            if (s[i] == '0')
              sum = sum + c;
            else
              sum = sum + c + h;
          }
        } else {
          for (int i = 0; i < s.length(); i++) {
            if (s[i] == '1')
              sum = sum + a;
            else
              sum = sum + a + h;
          }
        }
        cout << sum << endl;
      } else {
        for (int i = 0; i < s.length(); i++) {
          if (s[i] == '0')
            sum = sum + c;
          else
            sum = sum + a;
        }
        cout << sum << endl;
      }
    }
  }
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!

However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).

Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between the i-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).

Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.

Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.

Input

The first line contains four positive space-separated integers n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.

The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.

Output

In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.

In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Number pi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.

Examples

Input

3 250 185 230
0 185 250

Output

1
230

Input

4 250 185 230
0 20 185 250

Output

0

Input

2 300 185 230
0 300

Output

2
185 230

Note

In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.

In the second sample you already can use the ruler to measure the distances of 185 and 230 centimeters, so you don't have to add new marks.

In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long mn, mx, n, k, imx, imn, l, x, y, a[300000], kx, ky, ans1, ans2, ans3,
    ans4;
map<long long, long long> mp;
int main() {
  cin >> n >> l >> x >> y;
  for (int i = 1; i <= n; i++) {
    cin >> a[i], mp[a[i]] = 1;
  }
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    if (mp[a[i] - x] == 1) kx++;
    if (mp[a[i] - y] == 1) ky++;
    if (mp[a[i] - y + x] == 1 && (a[i] - y >= 0)) {
      ans1 = a[i] - y;
    }
    if (mp[a[i] - x + y] == 1 && (a[i] + y <= l)) {
      ans2 = a[i] + y;
    }
    if (mp[a[i] + x + y] == 1) {
      ans3 = a[i] + x;
    }
    if (mp[a[i] - x - y] == 1) {
      ans4 = a[i] - x;
    }
  }
  if (kx != 0 && ky != 0)
    cout << 0;
  else if (kx != 0 || ky != 0) {
    cout << 1 << '\n';
    if (kx != 0)
      cout << y;
    else
      cout << x;
  } else if (ans1 != 0) {
    cout << 1 << '\n';
    cout << ans1;
  } else if (ans2 != 0) {
    cout << 1 << '\n';
    cout << ans2;
  } else if (ans3 != 0) {
    cout << 1 << '\n';
    cout << ans3;
  } else if (ans4 != 0) {
    cout << 1 << '\n';
    cout << ans4;
  } else {
    cout << 2 << '\n';
    cout << x << ' ' << y;
  }
}

```


### Prompt

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

Divide and rule

Taro, Hanako, and Jiro rule the JAG Kingdom together. There are N cities in the JAG Kingdom, some of which are connected by two-way roads. You can always reach all the other cities from any city via one or more roads.

One day, Taro and Hanako finally made a mistake and decided to share the city and govern it. However, I don't even like the fact that the city governed by Taro and the city governed by Hanako are directly connected by a single road because they have become so bad. Therefore, we decided to share the governing towns so as to satisfy the following conditions.

* Any pair of towns governed by Taro and Hanako are not directly connected by roads. This is because the relationship between Taro and Hanako is insanely bad.
* Towns governed by the same person are not directly connected by roads. This is to encourage diplomacy by obliging the passage under the control of others.
* The total number of towns governed by Taro and the total number of towns governed by Hanako must be the same. This is because if the total number is not equal, the relationship between Taro and Hanako will be even worse. Here, Mr. Jiro is very open-minded, so the total number of cities governed by Mr. Jiro can be any number.

If the division meets the above conditions, the three people can be convinced to rule, and even if there are no cities governed by someone, there is no complaint. At this time, create a program that enumerates all possible numbers as the total number of cities governed by Mr. Taro (= the total number of cities governed by Mr. Hanako).

Input

The input consists of multiple datasets. The maximum number of datasets is 50. Each data set is represented in the following format.

> N M u1 v1 ... uM vM

The first line consists of two integers N (2 ≤ N ≤ 103) and M (1 ≤ M ≤ 103), which represent the number of cities and the number of roads, respectively. The i-th line of the following M lines consists of two integers ui and vi (1 ≤ ui <vi ≤ N), indicating that the i-th road connects the city ui and the city vi in both directions. Here, it is guaranteed that one city can always reach all other cities via one or more roads. Also, no multiple roads connecting pairs of the same city will be given. That is, (ui, vi) ≠ (uj, vj) is satisfied for all 1 ≤ i <j ≤ M.

The end of the input is represented by a line of two zeros.

Output

For each dataset, if there are K possible total numbers of cities governed by Taro, first output K on the first line, then output the possible total number on each line in ascending order.

Sample Input

6 7
1 2
14
twenty three
twenty five
3 4
4 5
4 6
twenty one
1 2
3 3
1 2
13
twenty three
4 3
1 2
twenty three
3 4
5 4
1 2
twenty three
3 4
4 5
0 0

Output for the Sample Input

2
1
2
0
0
1
1
1
1

Example

Input

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

Output

2
1
2
0
0
1
1
1
1

### Response

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

int main() {
    int n, m;
    while(cin >> n >> m, n) {
        vector<vector<int>> g(n);
        for(int i = 0; i < m; ++i) {
            int a, b; cin >> a >> b;
            g[a - 1].push_back(b - 1);
            g[b - 1].push_back(a - 1);
        }
        vector<int> col(n, -1), cnt(2);
        function<void(int, int)> coloring =
            [&] (int v, int c) {
                if(col[v] != -1 && col[v] != c) throw runtime_error("");
                if(col[v] != -1) return;
                col[v] = c;
                cnt[c] += 1;
                for(auto to : g[v]) {
                    coloring(to, !c);
                }
            };
        try {
            coloring(0, 0);
        } catch (...) {
            cout << 0 << endl;
            continue;
        }
        set<int> s;
        if(cnt[0] % 2 == 0) s.insert(cnt[0] / 2);
        if(cnt[1] % 2 == 0) s.insert(cnt[1] / 2);
        cout << s.size() << endl;
        for(auto x : s) {
            cout << x << endl;
        }
    }
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Lenny had an n × m matrix of positive integers. He loved the matrix so much, because each row of the matrix was sorted in non-decreasing order. For the same reason he calls such matrices of integers lovely.

One day when Lenny was at school his little brother was playing with Lenny's matrix in his room. He erased some of the entries of the matrix and changed the order of some of its columns. When Lenny got back home he was very upset. Now Lenny wants to recover his matrix.

Help him to find an order for the columns of the matrix so that it's possible to fill in the erased entries of the matrix to achieve a lovely matrix again. Note, that you can fill the erased entries of the matrix with any integers.

Input

The first line of the input contains two positive integers n and m (1 ≤ n·m ≤ 105). Each of the next n lines contains m space-separated integers representing the matrix. An integer -1 shows an erased entry of the matrix. All other integers (each of them is between 0 and 109 inclusive) represent filled entries.

Output

If there exists no possible reordering of the columns print -1. Otherwise the output should contain m integers p1, p2, ..., pm showing the sought permutation of columns. So, the first column of the lovely matrix will be p1-th column of the initial matrix, the second column of the lovely matrix will be p2-th column of the initial matrix and so on.

Examples

Input

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

Output

3 1 2

Input

2 3
1 2 2
2 5 4

Output

1 3 2

Input

2 3
1 2 3
3 2 1

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool debug = true;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2> ptt) {
  os << ptt.first << "," << ptt.second;
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vt) {
  os << "{";
  for (int i = 0; i < vt.size(); i++) {
    os << vt[i] << " ";
  }
  os << "}";
  return os;
}
int n, m;
vector<int> a[100005];
vector<int> nei[500005];
int deg[500005];
map<int, int> vn[100005];
int vnc;
const int MAX = 1e9 + 7;
int getVN(int ln, int x) {
  if (vn[ln].count(x)) {
  } else {
    vn[ln][x] = vnc;
    vnc++;
    assert(vnc <= 500000);
  }
  return vn[ln][x];
}
void add(int x, int y) {
  nei[x].push_back(y);
  deg[y]++;
}
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  vnc = m;
  for (int i = 0; i < n; i++) {
    a[i].resize(m);
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] != -1) {
        a[i][j]++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    vector<pair<int, int> > p;
    for (int j = 0; j < m; j++) {
      if (a[i][j] != -1) {
        p.push_back(make_pair(a[i][j], j));
      }
    }
    sort(p.begin(), p.end());
    for (int j = 0; j < p.size(); j++) {
      add(getVN(i, p[j].first), p[j].second);
      add(p[j].second, getVN(i, p[j].first + MAX));
    }
  }
  for (int i = 0; i < n; i++) {
    int last = -1;
    for (pair<int, int> x : vn[i]) {
      if (x.first > MAX) {
        break;
      }
      if (last != -1) {
        add(getVN(i, last + MAX), x.second);
      }
      last = x.first;
    }
  }
  queue<int> q;
  for (int i = 0; i < vnc; i++) {
    if (deg[i] == 0) {
      q.push(i);
    }
  }
  vector<int> ans;
  while (!q.empty()) {
    int last = q.front();
    q.pop();
    if (last < m) {
      ans.push_back(last + 1);
    }
    for (int to : nei[last]) {
      deg[to]--;
      if (deg[to] == 0) {
        q.push(to);
      }
    }
  }
  if (ans.size() != m) {
    cout << "-1";
  } else {
    for (int x : ans) {
      cout << x << endl;
    }
  }
  return 0;
}

```


### Prompt

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

You are given a special jigsaw puzzle consisting of n⋅ m identical pieces. Every piece has three tabs and one blank, as pictured below.

<image>

The jigsaw puzzle is considered solved if the following conditions hold:

  1. The pieces are arranged into a grid with n rows and m columns.
  2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.

Through rotation and translation of the pieces, determine if it is possible to solve the jigsaw puzzle.

Input

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

Each test case contains two integers n and m (1 ≤ n,m ≤ 10^5).

Output

For each test case output a single line containing "YES" if it is possible to solve the jigsaw puzzle, or "NO" otherwise. You can print each letter in any case (upper or lower).

Example

Input

3
1 3
100000 100000
2 2

Output

YES
NO
YES

Note

For the first test case, this is an example solution:

<image>

For the second test case, we can show that no solution exists.

For the third test case, this is an example solution:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    if (min(n, m) == 1)
      cout << "YES" << endl;
    else if (n == 2 && m == 2)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules:

  * There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb.
  * There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine.
  * Masculine adjectives end with -lios, and feminine adjectives end with -liala.
  * Masculine nouns end with -etr, and feminime nouns end with -etra.
  * Masculine verbs end with -initis, and feminime verbs end with -inites.
  * Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language.
  * It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language.
  * There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications.
  * A sentence is either exactly one valid language word or exactly one statement.

Statement is any sequence of the Petya's language, that satisfy both conditions:

  * Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs.
  * All words in the statement should have the same gender.

After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language.

Input

The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105.

It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language.

Output

If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes).

Examples

Input

petr

Output

YES

Input

etis atis animatis etis atis amatis

Output

NO

Input

nataliala kataliala vetra feinites

Output

YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char st[100005];
int word[100005];
int wordCount = 0;
int parse(string s) {
  int pol = -1;
  int type = -1;
  int l = s.length();
  if (l < 3) return -1;
  string temp;
  temp = s.substr(l - 3, 3);
  if (!temp.compare("etr")) {
    pol = 1;
    type = 1;
  } else if (l < 4)
    return -1;
  else {
    temp = s.substr(l - 4, 4);
    if (!temp.compare("etra")) {
      pol = 0;
      type = 1;
    } else if (!temp.compare("lios")) {
      pol = 1;
      type = 0;
    } else if (l < 5)
      return -1;
    else {
      temp = s.substr(l - 5, 5);
      if (!temp.compare("liala")) {
        pol = 0;
        type = 0;
      } else if (l < 6)
        return -1;
      else {
        temp = s.substr(l - 6, 6);
        if (!temp.compare("initis")) {
          pol = 1;
          type = 2;
        } else if (!temp.compare("inites")) {
          pol = 0;
          type = 2;
        }
      }
    }
  }
  if (pol < 0 || type < 0) return -1;
  return pol * 10 + type;
}
int main() {
  gets(st);
  string tmp = "";
  int len = strlen(st);
  for (int i = 0; i < len; i++) {
    if (st[i] == ' ' || i == len - 1) {
      if (i == len - 1) tmp += st[i];
      int j = parse(tmp);
      word[wordCount++] = j;
      if (j < 0) {
        cout << "NO";
        return 0;
      }
      tmp = "";
    } else
      tmp += st[i];
  }
  if (wordCount > 1) {
    int p = word[0] / 10;
    for (int i = 1; i < wordCount; i++) {
      if (word[i] / 10 != p) {
        cout << "NO";
        return 0;
      }
    }
    int j = 0, kl = 0;
    int t = 0;
    while (j < wordCount && word[j] % 10 == t) j++;
    if (j == wordCount) {
      cout << "NO";
      return 0;
    }
    kl = 0;
    t++;
    while (j < wordCount && word[j] % 10 == t) {
      j++;
      kl++;
    }
    if (kl != 1) {
      cout << "NO";
      return 0;
    }
    t++;
    while (j < wordCount && word[j] % 10 == t) j++;
    if (j != wordCount) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Amugae has a hotel consisting of 10 rooms. The rooms are numbered from 0 to 9 from left to right.

The hotel has two entrances — one from the left end, and another from the right end. When a customer arrives to the hotel through the left entrance, they are assigned to an empty room closest to the left entrance. Similarly, when a customer arrives at the hotel through the right entrance, they are assigned to an empty room closest to the right entrance.

One day, Amugae lost the room assignment list. Thankfully Amugae's memory is perfect, and he remembers all of the customers: when a customer arrived, from which entrance, and when they left the hotel. Initially the hotel was empty. Write a program that recovers the room assignment list from Amugae's memory.

Input

The first line consists of an integer n (1 ≤ n ≤ 10^5), the number of events in Amugae's memory.

The second line consists of a string of length n describing the events in chronological order. Each character represents:

  * 'L': A customer arrives from the left entrance.
  * 'R': A customer arrives from the right entrance.
  * '0', '1', ..., '9': The customer in room x (0, 1, ..., 9 respectively) leaves.

It is guaranteed that there is at least one empty room when a customer arrives, and there is a customer in the room x when x (0, 1, ..., 9) is given. Also, all the rooms are initially empty.

Output

In the only line, output the hotel room's assignment status, from room 0 to room 9. Represent an empty room as '0', and an occupied room as '1', without spaces.

Examples

Input

8
LLRL1RL1

Output

1010000011

Input

9
L0L0LLRR9

Output

1100000010

Note

In the first example, hotel room's assignment status after each action is as follows.

  * First of all, all rooms are empty. Assignment status is 0000000000.
  * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000.
  * L: one more customer from the left entrance. Assignment status is 1100000000.
  * R: one more customer from the right entrance. Assignment status is 1100000001.
  * L: one more customer from the left entrance. Assignment status is 1110000001.
  * 1: the customer in room 1 leaves. Assignment status is 1010000001.
  * R: one more customer from the right entrance. Assignment status is 1010000011.
  * L: one more customer from the left entrance. Assignment status is 1110000011.
  * 1: the customer in room 1 leaves. Assignment status is 1010000011.

So after all, hotel room's final assignment status is 1010000011.

In the second example, hotel room's assignment status after each action is as follows.

  * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000.
  * 0: the customer in room 0 leaves. Assignment status is 0000000000.
  * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000 again.
  * 0: the customer in room 0 leaves. Assignment status is 0000000000.
  * L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000.
  * L: one more customer from the left entrance. Assignment status is 1100000000.
  * R: one more customer from the right entrance. Assignment status is 1100000001.
  * R: one more customer from the right entrance. Assignment status is 1100000011.
  * 9: the customer in room 9 leaves. Assignment status is 1100000010.

So after all, hotel room's final assignment status is 1100000010.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int n, arr[10];
char ch;
int main() {
  cin >> n;
  while (n--) {
    cin >> ch;
    if (ch == 'L') {
      int i;
      for (i = 0; i < 10; i++) {
        if (arr[i] == 0) {
          arr[i] = 1;
          break;
        }
      }
    } else if (ch == 'R') {
      int i;
      for (i = 9; i >= 0; i--) {
        if (arr[i] == 0) {
          arr[i] = 1;
          break;
        }
      }
    } else if (isdigit(ch)) {
      arr[ch - 48] = 0;
    }
  }
  for (int i = 0; i < 10; i++) cout << arr[i];
}

```


### Prompt

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

A laser beam generator, a target object and some mirrors are placed on a plane. The mirrors stand upright on the plane, and both sides of the mirrors are flat and can reflect beams. To point the beam at the target, you may set the beam to several directions because of different reflections. Your job is to find the shortest beam path from the generator to the target and answer the length of the path.

Figure G-1 shows examples of possible beam paths, where the bold line represents the shortest one.

<image>

Figure G-1: Examples of possible paths

Input

The input consists of a number of datasets. The end of the input is indicated by a line containing a zero.

Each dataset is formatted as follows. Each value in the dataset except n is an integer no less than 0 and no more than 100.

> n
>  PX1 PY1 QX1 QY1
>  ...
>  PXn PYn QXn QYn
>  TX TY
>  LX LY
>

The first line of a dataset contains an integer n (1 ≤ n ≤ 5), representing the number of mirrors. The following n lines list the arrangement of mirrors on the plane. The coordinates (PXi, PYi) and (QXi, QYi) represent the positions of both ends of the mirror. Mirrors are apart from each other. The last two lines represent the target position (TX, TY) and the position of the beam generator (LX, LY). The positions of the target and the generator are apart from each other, and these positions are also apart from mirrors.

The sizes of the target object and the beam generator are small enough to be ignored. You can also ignore the thicknesses of mirrors.

In addition, you can assume the following conditions on the given datasets.

* There is at least one possible path from the beam generator to the target.
* The number of reflections along the shortest path is less than 6.
* The shortest path does not cross or touch a plane containing a mirror surface at any points within 0.001 unit distance from either end of the mirror.
* Even if the beam could arbitrarily select reflection or passage when it reaches each plane containing a mirror surface at a point within 0.001 unit distance from one of the mirror ends, any paths from the generator to the target would not be shorter than the shortest path.
* When the beam is shot from the generator in an arbitrary direction and it reflects on a mirror or passes the mirror within 0.001 unit distance from the mirror, the angle θ formed by the beam and the mirror satisfies sin(θ) > 0.1, until the beam reaches the 6th reflection point (exclusive).

Figure G-1 corresponds to the first dataset of the Sample Input below. Figure G-2 shows the shortest paths for the subsequent datasets of the Sample Input.

<image>

Figure G-2: Examples of the shortest paths

Output

For each dataset, output a single line containing the length of the shortest path from the beam generator to the target. The value should not have an error greater than 0.001. No extra characters should appear in the output.

Sample Input

2
30 10 30 75
60 30 60 95
90 0
0 100
1
20 81 90 90
10 90
90 10
2
10 0 10 58
20 20 20 58
0 70
30 0
4
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
24 0
24 64
5
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
100 0 100 50
24 0
24 64
0

Output for the Sample Input

180.27756377319946
113.13708498984761
98.99494936611666
90.50966799187809
90.50966799187809

Example

Input

2
30 10 30 75
60 30 60 95
90 0
0 100
1
20 81 90 90
10 90
90 10
2
10 0 10 58
20 20 20 58
0 70
30 0
4
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
24 0
24 64
5
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
100 0 100 50
24 0
24 64
0

Output

180.27756377319946
113.13708498984761
98.99494936611666
90.50966799187809
90.50966799187809

### Response

```cpp
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <tuple>
#include <cmath>

using namespace std;
const double EPS = 1e-8;
const double INF = 1e10;

struct Point {
	double x, y;
	Point() : x(0), y(0) { }
	Point(double x, double y) : x(x), y(y) { }
	Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); }
	Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); }
	Point operator*(double s) const { return Point(x * s, y * s); }
	Point operator/(double s) const { return Point(x / s, y / s); }
	Point &operator+=(const Point &p){ x += p.x; y += p.y; return *this; }
	Point &operator-=(const Point &p){ x -= p.x; y -= p.y; return *this; }
	Point &operator*=(double s){ x *= s; y *= s; return *this; }
	Point &operator/=(double s){ x /= s; y /= s; return *this; }
	bool operator==(const Point &p) const { return x == p.x && y == p.y; }
	bool operator!=(const Point &p) const { return x != p.x || y != p.y; }
	bool operator<(const Point &p) const {
		return (x == p.x) ? (y < p.y) : (x < p.x);
	}
};
inline Point operator*(double s, const Point &p){ return p * s; }

inline double norm(const Point &p){ return p.x * p.x + p.y * p.y; }
inline double abs(const Point &p){ return sqrt(norm(p)); }
inline double arg(const Point &p){ return atan2(p.y, p.x); }
inline Point unit(const Point &p){ return p / abs(p); }
inline Point ortho(const Point &p){ return Point(-p.y, p.x); }
inline double cross(const Point &a, const Point &b){
	return a.x * b.y - a.y * b.x;
}
inline double dot(const Point &a, const Point &b){
	return a.x * b.x + a.y * b.y;
}
inline int ccw(const Point &a, const Point &b, const Point &c){
	const Point d = b - a, e = c - a;
	if(cross(d, e) > 0.0){ return 1; }
	if(cross(d, e) < 0.0){ return -1; }
	if(dot(d, e) < 0.0){ return 2; }
	if(abs(d) < abs(e)){ return -2; }
	return 0;
}

struct Line {
	Point a, b;
	Line() : a(), b() { }
	Line(const Point &a, const Point &b) : a(a), b(b) { }
	bool operator==(const Line &l) const { return a == l.a && b == l.b; }
	bool operator!=(const Line &l) const { return a != l.a || b != l.b; }
	bool operator<(const Line &l) const {
		return (a == l.a) ? (b < l.b) : (a < l.a);
	}
};

inline Point direction(const Line &l){ return unit(l.b - l.a); }
inline int is_parallel(const Line &a, const Line &b){
	// 0: not parallel, 1: parallel, -1: same line
	const double s = cross(direction(a), direction(b));
	if(s >= EPS){ return 0; }
	const double t = cross(direction(b), a.b - b.a);
	return (t >= EPS) ? 1 : -1;
}
inline Line bisect(const Point &a, const Point &b){
	const Point &p = (a + b) * 0.5;
	return Line(p, unit(ortho(b - a)));
}
inline Point projection(const Line &l, const Point &p){
	double t = dot(p - l.a, l.b - l.a) / norm(l.b - l.a);
	return l.a + t * (l.b - l.a);
}
inline Point reflection(const Line &l, const Point &p){
	return p + 2.0 * (projection(l, p) - p);
}
inline Point crossing_point(const Line &a, const Line &b){
	const double x = cross(a.b - a.a, b.b - b.a);
	const double y = cross(a.b - a.a, a.b - b.a);
	return Point(b.a + (y / x) * (b.b - b.a));
}

struct Segment : public Line {
	Segment() : Line() { }
	Segment(const Point &a, const Point &b) : Line(a, b) { }
};

inline bool intersect(const Segment &a, const Segment &b){
	if(ccw(a.a, a.b, b.a) * ccw(a.a, a.b, b.b) > 0){ return false; }
	if(ccw(b.a, b.b, a.a) * ccw(b.a, b.b, a.b) > 0){ return false; }
	return true;
}

typedef tuple<double, int> tdi;
typedef tuple<Segment, int, int> tsii;

double solve(
	int depth, int prev, const Point &s, const Point &t,
	const vector<Segment> &mirrors,
	vector<tsii> &imag_mirrors, vector<int> &history)
{
	const int n = mirrors.size(), m = imag_mirrors.size();
	const Segment st(s, t);
	for(int i = 0; i < n; ++i){
		if(i != prev){ imag_mirrors.push_back(tsii(mirrors[i], i, depth)); }
	}
	vector<tdi> crossing_order;
	for(int i = 0; i < imag_mirrors.size(); ++i){
		if(intersect(st, get<0>(imag_mirrors[i]))){
			const Point p = crossing_point(st, get<0>(imag_mirrors[i]));
			crossing_order.push_back(tdi(norm(p - s), i));
		}
	}
	sort(crossing_order.begin(), crossing_order.end());
	int reflected = 0;
	bool accept = true;
	for(int i = 0; i < crossing_order.size(); ++i){
		const tsii &mirror = imag_mirrors[get<1>(crossing_order[i])];
		const int level = get<2>(mirror);
		const int mask = (1 << level) - 1;
		if((reflected & mask) != mask){ continue; }
		if(reflected & (1 << level)){ continue; }
		if(level >= depth || history[level] != get<1>(mirror)){
			accept = false;
			break;
		}
		reflected |= (1 << level);
	}
	if(reflected != ((1 << depth) - 1)){ accept = false; }
	double answer = INF;
	if(accept){ answer = abs(t - s); }
	if(depth >= 5){
		imag_mirrors.resize(m);
		return answer;
	}
	for(int i = 0; i < n; ++i){
		if(i == prev){ continue; }
		vector<Segment> next_mirrors(n);
		for(int j = 0; j < n; ++j){
			next_mirrors[j] = Segment(
				reflection(mirrors[i], mirrors[j].a),
				reflection(mirrors[i], mirrors[j].b));
		}
		history.push_back(i);
		const Point next_t = reflection(mirrors[i], t);
		answer = min(answer, solve(
			depth + 1, i, s, next_t, next_mirrors, imag_mirrors, history));
		history.pop_back();
	}
	imag_mirrors.resize(m);
	return answer;
}

int main(){
	ios_base::sync_with_stdio(false);
	cout << setiosflags(ios::fixed) << setprecision(10);
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		vector<Segment> mirrors(n);
		for(int i = 0; i < n; ++i){
			Segment &s = mirrors[i];
			cin >> s.a.x >> s.a.y >> s.b.x >> s.b.y;
		}
		Point s, t;
		cin >> s.x >> s.y >> t.x >> t.y;
		vector<tsii> imag_mirrors;
		vector<int> history;
		cout << solve(0, -1, s, t, mirrors, imag_mirrors, history) << endl;
	}
	return 0;
}
```


### Prompt

Create a solution in CPP for the following problem:

Priority queue is a container of elements which the element with the highest priority should be extracted first.

For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations.

* insert($t$, $x$): Insert $x$ to $Q_t$.
* getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing.
* deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing.

In the initial state, all queues are empty.

Constraints

* $1 \leq n \leq 1,000$
* $1 \leq q \leq 200,000$
* $-1,000,000,000 \leq x \leq 1,000,000,000$

Input

The input is given in the following format.

$n \; q$
$query_1$
$query_2$
:
$query_q$

Each query $query_i$ is given by

0 $t$ $x$

or

1 $t$

or

2 $t$

where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively.

Output

For each getMax operation, print an integer in a line.

Example

Input

2 10
0 0 3
0 0 9
0 0 1
1 0
2 0
1 0
0 0 4
1 0
0 1 8
1 1

Output

9
3
4
8

### Response

```cpp
#include <iostream>
#include<list>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    priority_queue<int> que[n];
    int tp1,tp2,a;
    while(q--){
        cin>>tp1;
        switch(tp1){
        case 0:
            cin>>tp2>>a;
            que[tp2].push(a);
            break;
        case 1:
            cin>>tp2;
            if(!que[tp2].empty())cout<<que[tp2].top()<<"\n";
            break;
        case 2:
            cin>>tp2;
            if(!que[tp2].empty())que[tp2].pop();
            break;
        }
    }
}

//list<int> lit;
//list<int>::iterator it;
//int main()
//{
//    lit.clear();
//    int t,tp,a;
//    it=lit.begin();
//    cin>>t;
//    while(t--){
//        cin>>tp;
//        switch(tp){
//        case 0:
//            cin>>a;
//            lit.insert(it,a);
//            break;
//    case 1:
//            cin>>a;
//            if(a<0){
//                while(a++){
//                    if(it!=lit.end())it++;
//                }
//            }
//            else if(a>0){
//                while(a--){
//                    if(it!=lit.begin())it--;
//                }
//            }
//        break;
//    case 2:
//        lit.erase(--it);
//        break;
//        }
//    }
//    lit.reverse();
//    for(it=lit.begin();it!=lit.end();it++){
//
//        cout<<*it<<"\n";
//    }
//}

```


### Prompt

Please create a solution in CPP to the following problem:

You are given two strings s and t. Both strings have length n and consist of lowercase Latin letters. The characters in the strings are numbered from 1 to n.

You can successively perform the following move any number of times (possibly, zero):

  * swap any two adjacent (neighboring) characters of s (i.e. for any i = \{1, 2, ..., n - 1\} you can swap s_i and s_{i + 1}).

You can't apply a move to the string t. The moves are applied to the string s one after another.

Your task is to obtain the string t from the string s. Find any way to do it with at most 10^4 such moves.

You do not have to minimize the number of moves, just find any sequence of moves of length 10^4 or less to transform s into t.

Input

The first line of the input contains one integer n (1 ≤ n ≤ 50) — the length of strings s and t.

The second line of the input contains the string s consisting of n lowercase Latin letters.

The third line of the input contains the string t consisting of n lowercase Latin letters.

Output

If it is impossible to obtain the string t using moves, print "-1".

Otherwise in the first line print one integer k — the number of moves to transform s to t. Note that k must be an integer number between 0 and 10^4 inclusive.

In the second line print k integers c_j (1 ≤ c_j < n), where c_j means that on the j-th move you swap characters s_{c_j} and s_{c_j + 1}.

If you do not need to apply any moves, print a single integer 0 in the first line and either leave the second line empty or do not print it at all.

Examples

Input

6
abcdef
abdfec

Output

4
3 5 4 5

Input

4
abcd
accd

Output

-1

Note

In the first example the string s changes as follows: "abcdef" → "abdcef" → "abdcfe" → "abdfce" → "abdfec".

In the second example there is no way to transform the string s into the string t through any allowed moves.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, i, j, k;
  string s, t;
  vector<int> ans;
  bool solved = true;
  cin >> n >> s >> t;
  for (i = 0; i < n; i++) {
    bool matched = false;
    for (j = i; j < n; j++) {
      if (s[j] == t[i]) {
        matched = true;
        for (k = j - 1; k >= i; k--) {
          ans.push_back(k);
          swap(s[k], s[k + 1]);
        }
        break;
      }
    }
    if (!matched) {
      solved = false;
      break;
    }
  }
  if (!solved)
    cout << "-1\n";
  else {
    cout << ans.size() << "\n";
    for (auto p : ans) cout << p + 1 << " ";
    cout << "\n";
  }
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Zane once had a good sequence a consisting of n integers a1, a2, ..., an — but he has lost it.

A sequence is said to be good if and only if all of its integers are non-negative and do not exceed 109 in value.

<image>

However, Zane remembers having played around with his sequence by applying m operations to it.

There are two types of operations:

1. Find the maximum value of integers with indices i such that l ≤ i ≤ r, given l and r.

2. Assign d as the value of the integer with index k, given k and d.

After he finished playing, he restored his sequence to the state it was before any operations were applied. That is, sequence a was no longer affected by the applied type 2 operations. Then, he lost his sequence at some time between now and then.

Fortunately, Zane remembers all the operations and the order he applied them to his sequence, along with the distinct results of all type 1 operations. Moreover, among all good sequences that would produce the same results when the same operations are applied in the same order, he knows that his sequence a has the greatest cuteness.

We define cuteness of a sequence as the bitwise OR result of all integers in such sequence. For example, the cuteness of Zane's sequence a is a1 OR a2 OR ... OR an.

Zane understands that it might not be possible to recover exactly the lost sequence given his information, so he would be happy to get any good sequence b consisting of n integers b1, b2, ..., bn that:

1. would give the same results when the same operations are applied in the same order, and

2. has the same cuteness as that of Zane's original sequence a.

If there is such a sequence, find it. Otherwise, it means that Zane must have remembered something incorrectly, which is possible.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the number of integers in Zane's original sequence and the number of operations that have been applied to the sequence, respectively.

The i-th of the following m lines starts with one integer ti (<image>) — the type of the i-th operation.

If the operation is type 1 (ti = 1), then three integers li, ri, and xi follow (1 ≤ li ≤ ri ≤ n, 0 ≤ xi ≤ 109) — the leftmost index to be considered, the rightmost index to be considered, and the maximum value of all integers with indices between li and ri, inclusive, respectively.

If the operation is type 2 (ti = 2), then two integers ki and di follow (1 ≤ ki ≤ n, 0 ≤ di ≤ 109) — meaning that the integer with index ki should become di after this operation.

It is guaranteed that xi ≠ xj for all pairs (i, j) where 1 ≤ i < j ≤ m and ti = tj = 1.

The operations are given in the same order they were applied. That is, the operation that is given first was applied first, the operation that is given second was applied second, and so on.

Output

If there does not exist a valid good sequence, print "NO" (without quotation marks) in the first line.

Otherwise, print "YES" (without quotation marks) in the first line, and print n space-separated integers b1, b2, ..., bn (0 ≤ bi ≤ 109) in the second line.

If there are multiple answers, print any of them.

Examples

Input

5 4
1 1 5 19
1 2 5 1
2 5 100
1 1 5 100

Output

YES
19 0 0 0 1

Input

5 2
1 1 5 0
1 1 5 100

Output

NO

Note

In the first sample, it is easy to verify that this good sequence is valid. In particular, its cuteness is 19 OR 0 OR 0 OR 0 OR 1 =  19.

In the second sample, the two operations clearly contradict, so there is no such good sequence.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
map<int, int> cnt;
int t[300005 * 4];
int a[300005];
int n, m;
struct note {
  int Type, x, y, z;
} s[300005];
void buildnew(int v, int l, int r) {
  if (l == r) {
    t[v] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  buildnew(v << 1, l, mid);
  buildnew(v << 1 | 1, mid + 1, r);
  t[v] = max(t[v << 1], t[v << 1 | 1]);
}
void change(int v, int l, int r, int x, int y) {
  if (l == r) {
    t[v] = y;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    change(v << 1, l, mid, x, y);
  else
    change(v << 1 | 1, mid + 1, r, x, y);
  t[v] = max(t[v << 1], t[v << 1 | 1]);
}
int getmax(int v, int l, int r, int x, int y) {
  if (l == x && r == y) return t[v];
  int mid = (l + r) >> 1;
  if (y <= mid)
    return getmax(v << 1, l, mid, x, y);
  else if (x > mid)
    return getmax(v << 1 | 1, mid + 1, r, x, y);
  else
    return max(getmax(v << 1, l, mid, x, mid),
               getmax(v << 1 | 1, mid + 1, r, mid + 1, y));
}
void build(int v, int l, int r) {
  t[v] = 2e9;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(v << 1, l, mid);
  build(v << 1 | 1, mid + 1, r);
}
void mntag(int v, int l, int r, int x, int y, int z) {
  if (l == x && r == y) {
    t[v] = min(t[v], z);
    return;
  }
  int mid = (l + r) >> 1;
  if (y <= mid)
    mntag(v << 1, l, mid, x, y, z);
  else if (x > mid)
    mntag(v << 1 | 1, mid + 1, r, x, y, z);
  else
    mntag(v << 1, l, mid, x, mid, z),
        mntag(v << 1 | 1, mid + 1, r, mid + 1, y, z);
}
int getmin(int v, int l, int r, int x) {
  if (l == r) return t[v];
  int mid = (l + r) >> 1;
  if (x <= mid)
    return min(t[v], getmin(v << 1, l, mid, x));
  else
    return min(t[v], getmin(v << 1 | 1, mid + 1, r, x));
}
int main() {
  scanf("%d%d", &n, &m);
  build(1, 1, n);
  memset(a, 255, sizeof(a));
  for (int i = 1; i <= m; i++) {
    int Type, x, y, z;
    scanf("%d", &Type);
    if (Type == 1) {
      scanf("%d%d%d", &x, &y, &z);
      mntag(1, 1, n, x, y, z);
    } else {
      scanf("%d%d", &x, &y);
      if (a[x] == -1) a[x] = getmin(1, 1, n, x);
    }
    s[i].Type = Type;
    s[i].x = x;
    s[i].y = y;
    s[i].z = z;
  }
  for (int i = 1; i <= n; i++)
    if (a[i] == -1) a[i] = getmin(1, 1, n, i);
  buildnew(1, 1, n);
  for (int i = 1; i <= m; i++) {
    if (s[i].Type == 1) {
      if (getmax(1, 1, n, s[i].x, s[i].y) != s[i].z) {
        puts("NO");
        return 0;
      }
    } else {
      change(1, 1, n, s[i].x, s[i].y);
    }
  }
  puts("YES");
  for (int i = 1; i <= n; i++) cnt[a[i]]++;
  if (cnt[2e9] >= 2) {
    bool fi = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] != 2e9) {
        printf("%d ", a[i]);
        continue;
      }
      if (!fi) {
        fi = 1;
        a[i] = (1 << 29) - 1;
      } else
        a[i] = 1e9;
      printf("%d ", a[i]);
    }
    return 0;
  }
  int own = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == 0 || a[i] == 2e9) continue;
    --cnt[a[i]];
    if (cnt[a[i]] > 0) {
      int wz = 0;
      for (int j = 0; j <= 30; j++) {
        if ((1 << j) <= a[i]) wz = j;
      }
      a[i] = (1 << wz) - 1;
      own |= a[i];
    } else
      own |= a[i];
  }
  int ned = 0;
  for (int i = 30; i >= 0; i--) {
    if (own & (1 << i)) continue;
    if (ned + (1 << i) > 1e9) continue;
    ned += 1 << i;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 2e9) a[i] = ned;
    printf("%d ", a[i]);
  }
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

T is a complete binary tree consisting of n vertices. It means that exactly one vertex is a root, and each vertex is either a leaf (and doesn't have children) or an inner node (and has exactly two children). All leaves of a complete binary tree have the same depth (distance from the root). So n is a number such that n + 1 is a power of 2.

In the picture you can see a complete binary tree with n = 15.

<image>

Vertices are numbered from 1 to n in a special recursive way: we recursively assign numbers to all vertices from the left subtree (if current vertex is not a leaf), then assign a number to the current vertex, and then recursively assign numbers to all vertices from the right subtree (if it exists). In the picture vertices are numbered exactly using this algorithm. It is clear that for each size of a complete binary tree exists exactly one way to give numbers to all vertices. This way of numbering is called symmetric.

You have to write a program that for given n answers q queries to the tree.

Each query consists of an integer number ui (1 ≤ ui ≤ n) and a string si, where ui is the number of vertex, and si represents the path starting from this vertex. String si doesn't contain any characters other than 'L', 'R' and 'U', which mean traverse to the left child, to the right child and to the parent, respectively. Characters from si have to be processed from left to right, considering that ui is the vertex where the path starts. If it's impossible to process a character (for example, to go to the left child of a leaf), then you have to skip it. The answer is the number of vertex where the path represented by si ends.

For example, if ui = 4 and si = «UURL», then the answer is 10.

Input

The first line contains two integer numbers n and q (1 ≤ n ≤ 1018, q ≥ 1). n is such that n + 1 is a power of 2.

The next 2q lines represent queries; each query consists of two consecutive lines. The first of these two lines contains ui (1 ≤ ui ≤ n), the second contains non-empty string si. si doesn't contain any characters other than 'L', 'R' and 'U'.

It is guaranteed that the sum of lengths of si (for each i such that 1 ≤ i ≤ q) doesn't exceed 105.

Output

Print q numbers, i-th number must be the answer to the i-th query.

Example

Input

15 2
4
UURL
8
LRLLLLLLLL

Output

10
5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long btcnt(long long n) {
  long long k = 0;
  while (n % 2 == 0) {
    k++;
    n /= 2;
  }
  return k;
}
long long arr[100];
int main() {
  long long n, q;
  cin >> n >> q;
  long long mx = btcnt(n + 1) - 1;
  arr[0] = 1;
  for (long long i = 1; i <= 64; i++) {
    arr[i] = arr[i - 1] * 2;
  }
  while (q--) {
    long long pvt;
    cin >> pvt;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
      long long temp = btcnt(pvt);
      if (s[i] == 'U') {
        if (temp == mx) continue;
        long long a, b;
        a = pvt + arr[temp];
        b = pvt - arr[temp];
        if (a % arr[temp + 1] == 0 && a % arr[temp + 2] != 0)
          pvt = a;
        else
          pvt = b;
      } else if (s[i] == 'L') {
        if (temp == 0)
          continue;
        else {
          pvt -= arr[temp - 1];
        }
      } else {
        if (temp == 0)
          continue;
        else {
          pvt += arr[temp - 1];
        }
      }
    }
    cout << pvt << endl;
  }
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Duff is the queen of her country, Andarz Gu. She's a competitive programming fan. That's why, when he saw her minister, Malek, free, she gave her a sequence consisting of n non-negative integers, a1, a2, ..., an and asked him to perform q queries for her on this sequence.

<image>

There are two types of queries:

  1. given numbers l, r and k, Malek should perform <image> for each l ≤ i ≤ r (<image>, bitwise exclusive OR of numbers a and b).
  2. given numbers l and r Malek should tell her the score of sequence al, al + 1, ... , ar.

Score of a sequence b1, ..., bk is the number of its different Kheshtaks. A non-negative integer w is a Kheshtak of this sequence if and only if there exists a subsequence of b, let's denote it as bi1, bi2, ... , bix (possibly empty) such that <image> (1 ≤ i1 < i2 < ... < ix ≤ k). If this subsequence is empty, then w = 0.

Unlike Duff, Malek is not a programmer. That's why he asked for your help. Please help him perform these queries.

Input

The first line of input contains two integers, n and q (1 ≤ n ≤ 2 × 105 and 1 ≤ q ≤ 4 × 104).

The second line of input contains n integers, a1, a2, ..., an separated by spaces (0 ≤ ai ≤ 109 for each 1 ≤ i ≤ n).

The next q lines contain the queries. Each line starts with an integer t (1 ≤ t ≤ 2), type of the corresponding query. If t = 1, then there are three more integers in that line, l, r and k. Otherwise there are two more integers, l and r. (1 ≤ l ≤ r ≤ n and 0 ≤ k ≤ 109)

Output

Print the answer of each query of the second type in one line.

Examples

Input

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

Output

8
16
1

Note

In the first query, we want all Kheshtaks of sequence 1, 2, 3, 4, 2 which are: 0, 1, 2, 3, 4, 5, 6, 7.

In the third query, we want all Khestaks of sequence 1, 10, 3, 4, 2 which are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15.

In the fifth query, we want all Kheshtaks of sequence 0 which is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, Q, a[maxn], opt, u, v, c;
struct Linear_Basis {
  int bas[32], tag, x;
  void init() {
    memset(bas, 0, sizeof bas);
    tag = 0;
    x = 0;
  }
  int Count() {
    int ret = 0;
    for (int i = 0; i < 30; i++)
      if (bas[i]) ret++;
    return ret;
  }
  void ins(int o) {
    for (int i = 29; ~i; i--) {
      if ((o >> i) & 1) {
        if (bas[i])
          o ^= bas[i];
        else {
          bas[i] = o;
          break;
        }
      }
    }
  }
  Linear_Basis operator+(const Linear_Basis& rhs) const {
    Linear_Basis ret;
    ret.init();
    for (int i = 0; i < 30; i++) {
      ret.ins(bas[i]);
      ret.ins(rhs.bas[i]);
    }
    ret.ins(x ^ rhs.x);
    ret.x = rhs.x;
    return ret;
  }
} tr[maxn << 2], ans;
void build(int rt = 1, int st = 1, int ed = n) {
  tr[rt].init();
  if (st == ed) {
    tr[rt].x = a[st];
    return;
  }
  int mid = st + ed >> 1;
  build(rt << 1, st, mid);
  build(rt << 1 | 1, mid + 1, ed);
  tr[rt] = tr[rt << 1] + tr[rt << 1 | 1];
}
void push_down(int rt) {
  if (tr[rt].tag) {
    tr[rt << 1].tag ^= tr[rt].tag;
    tr[rt << 1].x ^= tr[rt].tag;
    tr[rt << 1 | 1].tag ^= tr[rt].tag;
    tr[rt << 1 | 1].x ^= tr[rt].tag;
    tr[rt].tag = 0;
  }
}
void update(int nl, int nr, int c, int rt = 1, int st = 1, int ed = n) {
  if (nl <= st && nr >= ed) {
    tr[rt].x ^= c;
    tr[rt].tag ^= c;
    return;
  }
  push_down(rt);
  int mid = st + ed >> 1;
  if (nl <= mid) update(nl, nr, c, rt << 1, st, mid);
  if (nr >= mid + 1) update(nl, nr, c, rt << 1 | 1, mid + 1, ed);
  tr[rt] = tr[rt << 1] + tr[rt << 1 | 1];
}
void query(int nl, int nr, int rt = 1, int st = 1, int ed = n) {
  if (nl <= st && nr >= ed) {
    ans = ans + tr[rt];
    return;
  }
  push_down(rt);
  int mid = st + ed >> 1;
  if (nl <= mid) query(nl, nr, rt << 1, st, mid);
  if (nr >= mid + 1) query(nl, nr, rt << 1 | 1, mid + 1, ed);
}
int main() {
  scanf("%d %d", &n, &Q);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  build();
  while (Q--) {
    scanf("%d %d %d", &opt, &u, &v);
    if (opt == 1) {
      scanf("%d", &c);
      update(u, v, c);
    } else {
      ans.init();
      query(u, v);
      printf("%d\n", 1 << ans.Count());
    }
  }
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

After many years of research, Ikta has acquired the ability to predict the future! The time and money he spent on this research was enormous, but it's finally time to be rewarded. To get the money back, Ikta decided to start investing in stocks.

Ikta does not currently own any shares, but owns x yen. He has invested in n stocks, and has succeeded in predicting the stock price for d days from today. As a result, it was surprisingly found that there was no intraday stock price fluctuation for d days from today. In other words, we know the stock price pi, j yen of the stock j (1 ≤ j ≤ n) on the i (1 ≤ i ≤ d) day when today is the first day. Ikta is free to buy and sell stocks each day. That is, the following operations (purchase / sale) can be performed at any time in any order and any number of times. However, the amount of money held and the number of units held of shares before and after each operation must be non-negative integers.

* Purchase: On day i, select one stock type j (1 ≤ j ≤ n) and pay pi, j yen in possession to obtain 1 unit of stock j.
* Sale: On day i, select one stock type j (1 ≤ j ≤ n) and pay 1 unit of stock j to get pi, j yen.

(While he was absorbed in his research, the securities trading system made great progress and there were no transaction fees.)

Ikta had studied information science at university, but had forgotten everything he had learned at university before he could devote himself to future prediction research. Instead of him, write a program that maximizes your money on the final day.

Input

The input is given in the following format.

n d x
p1,1 ... p1, n
...
pd, 1 ... pd, n

* n: Number of stock types
* d: days
* x: Money on the first day
* pi, j: Stock price of stock j on day i (today is the first day)

Constraints

Each variable being input is an integer that satisfies the following constraints.

* 1 ≤ n ≤ 10
* 1 ≤ d ≤ 10
* 1 ≤ x, pi, j ≤ 105
* It is guaranteed that the amount of money you have on the last day will be 105 or less.

Output

Output the last day's money in one line when you invest optimally.

Examples

Input

2 2 5
3 2
5 4

Output

9

Input

1 2 5
6
10000

Output

5

Input

2 3 5
4 5
6 3
8 5

Output

11

Input

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

Output

10

### Response

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

int main() {
    int n, d, x;
    cin >> n >> d >> x;

    vector<vector<int> > p(d, vector<int>(n));
    for (auto& i : p) for (auto& j : i) cin >> j;

    vector<int> dp(100001);
    dp[x] = 1;
    for (int i = 0; i < d-1; i++) {
        vector<int> s(100001);
        for (int j = 0; j < n; j++) {
            int sub = p[i+1][j] - p[i][j];
            if (sub <= 0) continue;
            for (int k = 0; k < 100001; k++) {
                if (k - p[i][j] >= 0) s[k] = max(s[k], s[k - p[i][j]] + sub);
            }
        }

        for (int j = 100000; j >= 0; j--)
            if (j + s[j] < 100001) dp[j + s[j]] |= dp[j];
    }

    int ans = 0;
    for (int i = 0; i < 100001; i++)
        ans = max(ans, dp[i] * i);

    cout << ans << endl;

    return 0;
}
```


### Prompt

Create a solution in Cpp for the following problem:

Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where

  * <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <username> is between 1 and 16, inclusive.
  * <hostname> — is a sequence of word separated by periods (characters «.»), where each word should contain only characters allowed for <username>, the length of each word is between 1 and 16, inclusive. The length of <hostname> is between 1 and 32, inclusive.
  * <resource> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <resource> is between 1 and 16, inclusive.

The content of square brackets is optional — it can be present or can be absent.

There are the samples of correct Jabber IDs: mike@codeforces.com, 007@en.codeforces.com/contest.

Your task is to write program which checks if given string is a correct Jabber ID.

Input

The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive.

Output

Print YES or NO.

Examples

Input

mike@codeforces.com

Output

YES

Input

john.smith@codeforces.ru/contest.icpc/12

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
int isAlpha(char x) { return x >= 'A' && x <= 'Z' || x >= 'a' && x <= 'z'; }
int isDigit(char x) { return x >= '0' && x <= '9'; }
int main(void) {
  char a[100];
  int flag = 0, i;
  scanf("%[^@]", a);
  for (i = 0; a[i]; i++)
    if (isAlpha(a[i]) || isDigit(a[i]) || a[i] == '_')
      ;
    else
      flag = 1;
  if (!a[i] && i >= 1 && i <= 16)
    ;
  else {
    flag = 1;
  }
  if (scanf("@%[^/\n\r]", a) == 0) {
    flag = 1;
  }
  int c = 0;
  for (i = 0; a[i]; i++)
    if (isAlpha(a[i]) || isDigit(a[i]) || a[i] == '_') {
      flag |= (++c > 16);
    } else if (a[i] == '.') {
      flag |= (c == 0);
      c = 0;
    } else
      flag = 1;
  if (c == 0) flag = 1;
  if (i >= 1 && i <= 32)
    ;
  else
    flag = 1;
  gets(a);
  if (a[0] == '/') {
    for (i = 1; a[i]; i++)
      if (isAlpha(a[i]) || isDigit(a[i]) || a[i] == '_')
        ;
      else
        flag = 1;
    if (i >= 2 && i <= 17)
      ;
    else
      flag = 1;
  }
  puts(flag ? "NO" : "YES");
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game.

Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has).

The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints.

A color hint goes like that: a player names some color and points at all the cards of this color.

Similarly goes the value hint. A player names some value and points at all the cards that contain the value.

Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of Borya's cards. The next line contains the descriptions of n cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in.

Output

Print a single integer — the minimum number of hints that the other players should make.

Examples

Input

2
G3 G3

Output

0

Input

4
G4 R4 R3 B3

Output

2

Input

5
B1 Y1 W1 G1 R1

Output

4

Note

In the first sample Borya already knows for each card that it is a green three.

In the second sample we can show all fours and all red cards.

In the third sample you need to make hints about any four colors.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, tmp, res;
string a[101];
int gt(char z) {
  if (z == 'R') return 0;
  if (z == 'G') return 1;
  if (z == 'B') return 2;
  if (z == 'Y') return 3;
  if (z == 'W') return 4;
  return (4 + z - '0');
}
int solve(int x) {
  int kt[10], count = 0, trues = 0, condi = 0;
  for (int i = 0; i <= 9; i++) {
    if (((x >> i) & 1) == 1) {
      kt[i] = 1;
      count++;
    } else
      kt[i] = 0;
  }
  for (int i = 1; i <= n - 1; i++) {
    for (int j = i + 1; j <= n; j++)
      if (a[i] != a[j]) {
        trues = 1;
        if ((a[i][0] != a[j][0]) and
            ((kt[gt(a[i][0])] == 1) or (kt[gt(a[j][0])] == 1)))
          trues = 0;
        if ((a[i][1] != a[j][1]) and
            ((kt[gt(a[i][1])] == 1) or (kt[gt(a[j][1])] == 1)))
          trues = 0;
        if (trues != 0) condi = 1;
        if (condi == 1) break;
      }
    if (condi == 1) break;
  }
  if (condi != 0) return 0;
  if (count < res) res = count;
  return 0;
}
int main() {
  scanf("%d\n", &n);
  res = 11;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 0; i <= 1023; i++) tmp = solve(i);
  cout << res;
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Mishka got a six-faced dice. It has integer numbers from 2 to 7 written on its faces (all numbers on faces are different, so this is an almost usual dice).

Mishka wants to get exactly x points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.

Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly x points for them. Mishka is very lucky, so if the probability to get x points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.

Mishka is also very curious about different number of points to score so you have to answer t independent queries.

Input

The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of queries.

Each of the next t lines contains one integer each. The i-th line contains one integer x_i (2 ≤ x_i ≤ 100) — the number of points Mishka wants to get.

Output

Print t lines. In the i-th line print the answer to the i-th query (i.e. any number of rolls Mishka can make to be able to get exactly x_i points for them). It is guaranteed that at least one answer exists.

Example

Input

4
2
13
37
100

Output

1
3
8
27

Note

In the first query Mishka can roll a dice once and get 2 points.

In the second query Mishka can roll a dice 3 times and get points 5, 5 and 3 (for example).

In the third query Mishka can roll a dice 8 times and get 5 points 7 times and 2 points with the remaining roll.

In the fourth query Mishka can roll a dice 27 times and get 2 points 11 times, 3 points 6 times and 6 points 10 times.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> x;
    cout << x / 2 << endl;
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Recently Lynyrd and Skynyrd went to a shop where Lynyrd bought a permutation p of length n, and Skynyrd bought an array a of length m, consisting of integers from 1 to n.

Lynyrd and Skynyrd became bored, so they asked you q queries, each of which has the following form: "does the subsegment of a from the l-th to the r-th positions, inclusive, have a subsequence that is a cyclic shift of p?" Please answer the queries.

A permutation of length n is a sequence of n integers such that each integer from 1 to n appears exactly once in it.

A cyclic shift of a permutation (p_1, p_2, …, p_n) is a permutation (p_i, p_{i + 1}, …, p_{n}, p_1, p_2, …, p_{i - 1}) for some i from 1 to n. For example, a permutation (2, 1, 3) has three distinct cyclic shifts: (2, 1, 3), (1, 3, 2), (3, 2, 1).

A subsequence of a subsegment of array a from the l-th to the r-th positions, inclusive, is a sequence a_{i_1}, a_{i_2}, …, a_{i_k} for some i_1, i_2, …, i_k such that l ≤ i_1 < i_2 < … < i_k ≤ r.

Input

The first line contains three integers n, m, q (1 ≤ n, m, q ≤ 2 ⋅ 10^5) — the length of the permutation p, the length of the array a and the number of queries.

The next line contains n integers from 1 to n, where the i-th of them is the i-th element of the permutation. Each integer from 1 to n appears exactly once.

The next line contains m integers from 1 to n, the i-th of them is the i-th element of the array a.

The next q lines describe queries. The i-th of these lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ m), meaning that the i-th query is about the subsegment of the array from the l_i-th to the r_i-th positions, inclusive.

Output

Print a single string of length q, consisting of 0 and 1, the digit on the i-th positions should be 1, if the subsegment of array a from the l_i-th to the r_i-th positions, inclusive, contains a subsequence that is a cyclic shift of p, and 0 otherwise.

Examples

Input

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

Output

110

Input

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

Output

010

Note

In the first example the segment from the 1-st to the 5-th positions is 1, 2, 3, 1, 2. There is a subsequence 1, 3, 2 that is a cyclic shift of the permutation. The subsegment from the 2-nd to the 6-th positions also contains a subsequence 2, 1, 3 that is equal to the permutation. The subsegment from the 3-rd to the 5-th positions is 3, 1, 2, there is only one subsequence of length 3 (3, 1, 2), but it is not a cyclic shift of the permutation.

In the second example the possible cyclic shifts are 1, 2 and 2, 1. The subsegment from the 1-st to the 2-nd positions is 1, 1, its subsequences are not cyclic shifts of the permutation. The subsegment from the 2-nd to the 3-rd positions is 1, 2, it coincides with the permutation. The subsegment from the 3 to the 4 positions is 2, 2, its subsequences are not cyclic shifts of the permutation.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int n, m, q;
int gde[maxn];
int poz[maxn];
int last[maxn];
int niz[maxn];
int lift[maxn][20];
template <class T, int SZ>
struct RMQ {
  T sp[SZ][32 - __builtin_clz(SZ)];
  void napravi(int N, int a[]) {
    for (int i = 1; i <= N; i++) sp[i][0] = a[i];
    for (int j = 1; j < 32 - __builtin_clz(SZ); j++) {
      for (int i = 1; i <= SZ - (1 << (j - 1)); i++)
        sp[i][j] = max(sp[i][j - 1], sp[i + (1 << (j - 1))][j - 1]);
    }
  }
  T query(int l, int r) {
    int x = 31 - __builtin_clz(r - l + 1);
    return max(sp[l][x], sp[r - (1 << x) + 1][x]);
  }
};
RMQ<long long, maxn> rq;
int nadji(int x) {
  int kol = n - 1;
  for (int i = 19; i >= 0; i--) {
    int pw = (1 << i);
    if (kol >= pw) {
      kol -= pw;
      x = lift[x][i];
    }
  }
  return x;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m >> q;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    poz[x] = i;
  }
  for (int i = 1; i <= m; i++) {
    int x;
    cin >> x;
    gde[i] = poz[x];
  }
  for (int i = 1; i <= m; i++) {
    int koji = gde[i];
    last[koji] = i;
    lift[i][0] = last[(koji == 1 ? n : koji - 1)];
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j < 20; j++) lift[i][j] = lift[lift[i][j - 1]][j - 1];
  }
  for (int i = 1; i <= m; i++) niz[i] = nadji(i);
  rq.napravi(m, niz);
  while (q--) {
    int l, r;
    cin >> l >> r;
    int rez = rq.query(l, r);
    cout << (rez >= l ? 1 : 0);
  }
  return 0;
}

```


### Prompt

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

There are N squares lining up in a row, numbered 1 through N from left to right. Initially, all squares are white. We also have N-1 painting machines, numbered 1 through N-1. When operated, Machine i paints Square i and i+1 black.

Snuke will operate these machines one by one. The order in which he operates them is represented by a permutation of (1, 2, ..., N-1), P, which means that the i-th operated machine is Machine P_i.

Here, the score of a permutation P is defined as the number of machines that are operated before all the squares are painted black for the first time, when the machines are operated in the order specified by P. Snuke has not decided what permutation P to use, but he is interested in the scores of possible permutations. Find the sum of the scores over all possible permutations for him. Since this can be extremely large, compute the sum modulo 10^9+7.

Constraints

* 2 \leq N \leq 10^6

Input

Input is given from Standard Input in the following format:

N

Output

Print the sum of the scores over all possible permutations, modulo 10^9+7.

Examples

Input

4

Output

16

Input

2

Output

1

Input

5

Output

84

Input

100000

Output

341429644

### Response

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

template <class T>
T pow(T x, T n, T mod) {
    T ret = 1;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

template <class T>
T inverse(T x, T p) { return pow(x, p - 2, p); }

int main() {
    long long n, ret = 0;
    const auto mod = 1000000007ll;
    std::cin >> n;
    std::vector<long long> fact(n + 1), inv(n + 1);
    fact[0] = 1;
    for (auto i = 1ll; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    inv[n] = inverse(fact[n], mod);
    for (auto i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
    auto pre = 0ll;
    for (auto i = (n + 1) / 2; i < n; i++) {
        auto t = fact[i - 1] * inv[n - 1 - i] % mod * inv[2 * i - n] % mod * fact[i] % mod * fact[n - 1 - i] % mod;
        ret = (ret + (t - pre + mod) % mod * i) % mod;
        pre = t;
    }

    std::cout << ret << std::endl;

    return 0;
}
```


### Prompt

Create a solution in cpp for the following problem:

Yasin has an array a containing n integers. Yasin is a 5 year old, so he loves ultimate weird things.

Yasin denotes weirdness of an array as maximum gcd(ai, aj) value among all 1 ≤ i < j ≤ n. For n ≤ 1 weirdness is equal to 0, gcd(x, y) is the greatest common divisor of integers x and y.

He also defines the ultimate weirdness of an array. Ultimate weirdness is <image> where f(i, j) is weirdness of the new array a obtained by removing all elements between i and j inclusive, so new array is [a1... ai - 1, aj + 1... an].

Since 5 year old boys can't code, Yasin asks for your help to find the value of ultimate weirdness of the given array a!

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of elements in a.

The next line contains n integers ai (1 ≤ ai ≤ 200 000), where the i-th number is equal to the i-th element of the array a. It is guaranteed that all ai are distinct.

Output

Print a single line containing the value of ultimate weirdness of the array a.

Example

Input

3
2 6 3

Output

6

Note

Consider the first sample.

  * f(1, 1) is equal to 3.
  * f(2, 2) is equal to 1.
  * f(3, 3) is equal to 2.
  * f(1, 2), f(1, 3) and f(2, 3) are equal to 0.

Thus the answer is 3 + 0 + 0 + 1 + 0 + 2 = 6.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5, maxm = 1e6, mx = 2e5 + 10;
int a[maxm], b[maxm];
long long s[maxm];
int c[maxn], fac[maxn];
long long h[maxn];
vector<int> v[maxn];
long long ans;
int n, i, j, k, L, R;
void update(int o, int l, int r) {
  int m = (l + r) >> 1;
  a[o] = 0;
  s[o] = 0;
  if (b[2 * o]) {
    a[o] = max(a[o], b[2 * o]);
    s[o] += (long long)(m - l) * b[2 * o];
  } else {
    a[o] = max(a[o], a[2 * o]);
    s[o] += s[2 * o];
  }
  if (b[2 * o + 1]) {
    a[o] = max(a[o], b[2 * o + 1]);
    s[o] += (long long)(r - m) * b[2 * o + 1];
  } else {
    a[o] = max(a[o], a[2 * o + 1]);
    s[o] += s[2 * o + 1];
  }
}
void pushdown(int o) {
  if (b[o]) {
    b[2 * o] = b[o];
    b[2 * o + 1] = b[o];
    b[o] = 0;
  }
}
void build(int o, int l, int r) {
  if (l + 1 == r) {
    a[o] = l;
    s[o] = l;
    return;
  }
  int m = (l + r) >> 1;
  build(2 * o, l, m);
  build(2 * o + 1, m, r);
  update(o, l, r);
}
void modify(int o, int l, int r, int x, int y, int v) {
  if (x >= y) return;
  if (x <= l && r <= y) {
    b[o] = v;
    return;
  }
  pushdown(o);
  int m = (l + r) >> 1;
  if (x < m) modify(2 * o, l, m, x, y, v);
  if (m < y) modify(2 * o + 1, m, r, x, y, v);
  update(o, l, r);
}
bool ok(int o, int v) {
  if (b[o])
    return b[o] <= v;
  else
    return a[o] <= v;
}
void find(int o, int l, int r, int v, int &re) {
  if (l + 1 == r) {
    if (ok(o, v)) re = l;
    return;
  }
  pushdown(o);
  int m = (l + r) >> 1;
  if (ok(2 * o, v)) {
    re = m - 1;
    find(2 * o + 1, m, r, v, re);
  } else
    find(2 * o, l, m, v, re);
  update(o, l, r);
}
int main() {
  scanf("%d", &n);
  L = 1;
  R = n + 1;
  for (i = 2; i <= mx; i++)
    if (!fac[i])
      for (j = i; j <= mx; j += i) fac[j] = i;
  for (int nn = 1; nn <= n; nn++) {
    scanf("%d", &c[nn]);
    int x = c[nn];
    vector<int> d(1, 1);
    while (x > 1) {
      i = 0;
      int y = fac[x];
      int sz = d.size();
      while (x % y == 0) {
        x /= y;
        int len = d.size();
        for (j = i; j < len; j++) {
          int z = d[j] * y;
          d.push_back(z);
        }
        i += sz;
      }
    }
    int len = d.size();
    for (i = 0; i < len; i++) v[d[i]].push_back(nn);
  }
  build(1, L, R);
  for (i = mx; i >= 0; i--) {
    int len = v[i + 1].size();
    if (len >= 2) {
      int b1, b2, bk, bk_1;
      bk = v[i + 1][len - 1];
      bk_1 = v[i + 1][len - 2];
      b1 = v[i + 1][0];
      b2 = v[i + 1][1];
      modify(1, L, R, v[i + 1][1] + 1, R, n + 1);
      int re = 0;
      find(1, L, R, v[i + 1][len - 1], re);
      modify(1, L, R, v[i + 1][0] + 1, re + 1, v[i + 1][len - 1]);
      re = 0;
      find(1, L, R, v[i + 1][len - 2], re);
      modify(1, L, R, 1, re + 1, v[i + 1][len - 2]);
    }
    h[i] = (long long)n * (n + 1) - s[1];
  }
  for (i = mx; i >= 1; i--) ans += (h[i] - h[i - 1]) * i;
  printf("%I64d", ans);
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Bob got a job as a system administrator in X corporation. His first task was to connect n servers with the help of m two-way direct connection so that it becomes possible to transmit data from one server to any other server via these connections. Each direct connection has to link two different servers, each pair of servers should have at most one direct connection. Y corporation, a business rival of X corporation, made Bob an offer that he couldn't refuse: Bob was asked to connect the servers in such a way, that when server with index v fails, the transmission of data between some other two servers becomes impossible, i.e. the system stops being connected. Help Bob connect the servers.

Input

The first input line contains 3 space-separated integer numbers n, m, v (3 ≤ n ≤ 105, 0 ≤ m ≤ 105, 1 ≤ v ≤ n), n — amount of servers, m — amount of direct connections, v — index of the server that fails and leads to the failure of the whole system.

Output

If it is impossible to connect the servers in the required way, output -1. Otherwise output m lines with 2 numbers each — description of all the direct connections in the system. Each direct connection is described by two numbers — indexes of two servers, linked by this direct connection. The servers are numbered from 1. If the answer is not unique, output any.

Examples

Input

5 6 3

Output

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

Input

6 100 1

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long double epsilon = 1e-9;
int main() {
  long long n, m, v;
  cin >> n >> m >> v;
  long long p = ((n - 1) * (n - 2)) / 2LL + 1;
  if (m > p || m < n - 1) {
    cout << -1 << endl;
    return 0;
  }
  int other = 1;
  if (v == 1) other = 2;
  for (int i = 1; i <= n; i++) {
    if (i == v)
      continue;
    else
      cout << v << " " << i << endl;
  }
  m -= n - 1;
  for (int i = 1; i <= n && m > 0; i++) {
    if (i == v || i == other) continue;
    for (int j = i + 1; j <= n && m > 0; j++) {
      if (j == v || j == other || j == i) continue;
      printf("%d %d\n", i, j);
      m--;
    }
  }
  return 0;
}

```


### Prompt

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

Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.

The building consists of n floors with stairs at the left and the right sides. Each floor has m rooms on the same line with a corridor that connects the left and right stairs passing by all the rooms. In other words, the building can be represented as a rectangle with n rows and m + 2 columns, where the first and the last columns represent the stairs, and the m columns in the middle represent rooms.

Sagheer is standing at the ground floor at the left stairs. He wants to turn all the lights off in such a way that he will not go upstairs until all lights in the floor he is standing at are off. Of course, Sagheer must visit a room to turn the light there off. It takes one minute for Sagheer to go to the next floor using stairs or to move from the current room/stairs to a neighboring room/stairs on the same floor. It takes no time for him to switch the light off in the room he is currently standing in. Help Sagheer find the minimum total time to turn off all the lights.

Note that Sagheer does not have to go back to his starting position, and he does not have to visit rooms where the light is already switched off.

Input

The first line contains two integers n and m (1 ≤ n ≤ 15 and 1 ≤ m ≤ 100) — the number of floors and the number of rooms in each floor, respectively.

The next n lines contains the building description. Each line contains a binary string of length m + 2 representing a floor (the left stairs, then m rooms, then the right stairs) where 0 indicates that the light is off and 1 indicates that the light is on. The floors are listed from top to bottom, so that the last line represents the ground floor.

The first and last characters of each string represent the left and the right stairs, respectively, so they are always 0.

Output

Print a single integer — the minimum total time needed to turn off all the lights.

Examples

Input

2 2
0010
0100

Output

5

Input

3 4
001000
000010
000010

Output

12

Input

4 3
01110
01110
01110
01110

Output

18

Note

In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs.

In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to the second room in the last floor.

In the third example, he will walk through the whole corridor alternating between the left and right stairs at each floor.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
string a[110];
int dp[2][110], c[2][110];
int main() {
  int N, M, ans = 0;
  cin >> N >> M;
  for (int i = N; i > 0; i--) {
    cin >> a[i];
  }
  for (int f = 1; f <= N; f++) {
    for (int i = 0; i < M + 1 && a[f][i] == '0'; i++) c[0][f]++;
    for (int i = M + 1; i > 0 && a[f][i] == '0'; i--) c[1][f]++;
  }
  dp[0][1] = 2 * (M + 1 - c[1][1]);
  dp[1][1] = M + 1;
  ans = (M + 1 - c[1][1]);
  for (int f = 2; f <= N; f++) {
    dp[0][f] =
        min(1 + (M + 1 - c[1][f]) * 2 + dp[0][f - 1], 1 + M + dp[1][f - 1] + 1);
    dp[1][f] =
        min(1 + (M + 1 - c[0][f]) * 2 + dp[1][f - 1], 1 + M + dp[0][f - 1] + 1);
    if (c[0][f] != M + 1 && c[1][f] != M + 1 && f != 1) {
      ans = min(dp[0][f - 1] + 1 + (M + 1 - c[1][f]),
                dp[1][f - 1] + 1 + (M + 1 - c[0][f]));
    }
  }
  cout << ans << endl;
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the selling are made only once. To carry out his plan, Qwerty is going to take a bank loan that covers all expenses and to return the loaned money at the end of the operation (the money is returned without the interest). At the same time, Querty wants to get as much profit as possible.

The system has n planets in total. On each of them Qwerty can buy or sell items of m types (such as food, medicine, weapons, alcohol, and so on). For each planet i and each type of items j Qwerty knows the following:

  * aij — the cost of buying an item;
  * bij — the cost of selling an item;
  * cij — the number of remaining items.

It is not allowed to buy more than cij items of type j on planet i, but it is allowed to sell any number of items of any kind.

Knowing that the hold of Qwerty's ship has room for no more than k items, determine the maximum profit which Qwerty can get.

Input

The first line contains three space-separated integers n, m and k (2 ≤ n ≤ 10, 1 ≤ m, k ≤ 100) — the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly.

Then follow n blocks describing each planet.

The first line of the i-th block has the planet's name as a string with length from 1 to 10 Latin letters. The first letter of the name is uppercase, the rest are lowercase. Then in the i-th block follow m lines, the j-th of them contains three integers aij, bij and cij (1 ≤ bij < aij ≤ 1000, 0 ≤ cij ≤ 100) — the numbers that describe money operations with the j-th item on the i-th planet. The numbers in the lines are separated by spaces.

It is guaranteed that the names of all planets are different.

Output

Print a single number — the maximum profit Qwerty can get.

Examples

Input

3 3 10
Venus
6 5 3
7 6 5
8 6 10
Earth
10 9 0
8 6 4
10 9 3
Mars
4 3 0
8 4 12
7 2 5

Output

16

Note

In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3·6 + 7·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3·9 + 7·9 = 90 units of money for the items, he should give 74 of them for the loan. The resulting profit equals 16 units of money. We cannot get more profit in this case.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_BUF_SIZE = 16384;
char BUFOR[MAX_BUF_SIZE];
int BUF_SIZE, BUF_POS;
char ZZZ;
int _MINUS;
const int MXN = 110;
const int C = 262144;
const int INF = 1000000001;
int n, m, k;
string str[MXN];
int a[MXN][MXN], b[MXN][MXN], c[MXN][MXN];
int main() {
  cin >> n >> m >> k;
  for (int i = (1); i <= (n); i++) {
    cin >> str[i];
    for (int j = (1); j <= (m); j++)
      scanf("%d %d %d", &a[i][j], &b[i][j], &c[i][j]);
  }
  int res = 0;
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (n); j++)
      if (i != j) {
        vector<pair<int, int> > vec;
        for (int o = (1); o <= (m); o++)
          vec.push_back(make_pair(b[j][o] - a[i][o], c[i][o]));
        sort((vec).begin(), (vec).end());
        int resTmp = 0;
        int cnt = k;
        for (int o = ((int)(vec).size() - 1); o >= (0); o--) {
          pair<int, int> p1 = vec[o];
          if (p1.first > 0) {
            while (p1.second && cnt > 0) {
              p1.second--;
              resTmp += p1.first;
              cnt--;
            }
          }
        }
        res = max(res, resTmp);
      }
  printf("%d\n", res);
  return 0;
}

```