### Prompt

Create a solution in Cpp for the following problem:

Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them.

There are n planets in their universe numbered from 1 to n. Rick is in planet number s (the earth) and he doesn't know where Morty is. As we all know, Rick owns a portal gun. With this gun he can open one-way portal from a planet he is in to any other planet (including that planet). But there are limits on this gun because he's still using its free trial.

<image>

By default he can not open any portal by this gun. There are q plans in the website that sells these guns. Every time you purchase a plan you can only use it once but you can purchase it again if you want to use it more.

Plans on the website have three types:

  1. With a plan of this type you can open a portal from planet v to planet u.
  2. With a plan of this type you can open a portal from planet v to any planet with index in range [l, r].
  3. With a plan of this type you can open a portal from any planet with index in range [l, r] to planet v.

Rick doesn't known where Morty is, but Unity is going to inform him and he wants to be prepared for when he finds and start his journey immediately. So for each planet (including earth itself) he wants to know the minimum amount of money he needs to get from earth to that planet.

Input

The first line of input contains three integers n, q and s (1 ≤ n, q ≤ 105, 1 ≤ s ≤ n) — number of planets, number of plans and index of earth respectively.

The next q lines contain the plans. Each line starts with a number t, type of that plan (1 ≤ t ≤ 3). If t = 1 then it is followed by three integers v, u and w where w is the cost of that plan (1 ≤ v, u ≤ n, 1 ≤ w ≤ 109). Otherwise it is followed by four integers v, l, r and w where w is the cost of that plan (1 ≤ v ≤ n, 1 ≤ l ≤ r ≤ n, 1 ≤ w ≤ 109).

Output

In the first and only line of output print n integers separated by spaces. i-th of them should be minimum money to get from earth to i-th planet, or  - 1 if it's impossible to get to that planet.

Examples

Input

3 5 1
2 3 2 3 17
2 3 2 2 16
2 2 2 3 3
3 3 1 1 12
1 3 3 17

Output

0 28 12

Input

4 3 1
3 4 1 3 12
2 2 3 4 10
1 2 4 16

Output

0 -1 -1 12

Note

In the first sample testcase, Rick can purchase 4th plan once and then 2nd plan in order to get to get to planet number 2.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool exceed(long long x, long long y, long long m) { return x >= m / y + 1; }
template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  }
  return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
  for (typename map<T, U>::iterator itr = map_var.begin(); itr != map_var.end();
       itr++) {
    os << "(" << itr->first << ", " << itr->second << ")";
    itr++;
    if (itr != map_var.end()) os << ",";
    itr--;
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
  for (typename set<T>::iterator itr = set_var.begin(); itr != set_var.end();
       itr++) {
    os << *itr;
    ++itr;
    if (itr != set_var.end()) os << " ";
    itr--;
  }
  return os;
}
void dump_func() { cout << endl; }
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(Tail) > 0) cout << " ";
  dump_func(std::move(tail)...);
}
struct edge {
  long long to, cost;
  edge() {}
  edge(long long a, long long b) { to = a, cost = b; }
};
long long n, Q, s;
vector<edge> G[1 << 19];
long long A = 1 << 17, B = 1 << 18;
long long dist[1 << 19];
void query(int a, int b, int k, int l, int r, long long s, long long w) {
  if (b < l || r < a) return;
  if (a <= l && r <= b) {
    G[A + s].push_back(edge(k, w));
    return;
  }
  query(a, b, k * 2, l, (l + r) / 2, s, w);
  query(a, b, k * 2 + 1, (l + r) / 2 + 1, r, s, w);
}
void query(int a, int b, long long s, long long w) {
  return query(a, b, 1, 0, (1 << 17) - 1, s, w);
}
void query2(int a, int b, int k, int l, int r, long long s, long long w) {
  if (b < l || r < a) return;
  if (a <= l && r <= b) {
    G[B + k].push_back(edge(B + A + s, w));
    return;
  }
  query2(a, b, k * 2, l, (l + r) / 2, s, w);
  query2(a, b, k * 2 + 1, (l + r) / 2 + 1, r, s, w);
}
void query2(int a, int b, long long s, long long w) {
  return query2(a, b, 1, 0, (1 << 17) - 1, s, w);
}
void dijkstra(vector<edge> G[], long long S, long long dist[]) {
  for (int i = 0; i < (1 << 19); i++) dist[i] = 1e18;
  dist[S] = 0;
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      Q;
  Q.push(make_pair(0, S));
  long long v, d;
  while (Q.size()) {
    d = Q.top().first;
    v = Q.top().second;
    Q.pop();
    if (dist[v] < d) continue;
    for (int i = 0; i < G[v].size(); i++) {
      if (dist[G[v][i].to] > d + G[v][i].cost) {
        dist[G[v][i].to] = d + G[v][i].cost;
        Q.push(make_pair(dist[G[v][i].to], G[v][i].to));
      }
    }
  }
}
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> Q >> s;
  for (long long(i) = (1); (i) <= (n); (i)++)
    G[A + i].push_back(edge(B + A + i, 0)),
        G[B + A + i].push_back(edge(A + i, 0));
  for (long long(i) = (1); (i) <= ((1 << 17) - 1); (i)++) {
    G[i].push_back(edge(i * 2, 0)), G[i].push_back(edge(i * 2 + 1, 0));
    G[B + i * 2].push_back(edge(B + i, 0)),
        G[B + i * 2 + 1].push_back(edge(B + i, 0));
  }
  long long t, u, v, l, r, w;
  for (long long(i) = (1); (i) <= (Q); (i)++) {
    cin >> t;
    if (t == 1) {
      cin >> u >> v >> w;
      G[A + u].push_back(edge(A + v, w));
    }
    if (t == 2) {
      cin >> u >> l >> r >> w;
      query(l, r, u, w);
    }
    if (t == 3) {
      cin >> u >> l >> r >> w;
      query2(l, r, u, w);
    }
  }
  dijkstra(G, A + s, dist);
  for (long long(i) = (1); (i) <= (n); (i)++) {
    if (dist[A + i] > 1e18 / 2)
      cout << -1 << " ";
    else
      cout << dist[A + i] << " ";
  }
  cout << endl;
  return 0;
}

```


### Prompt

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

There was a large mansion surrounded by high walls. The owner of the mansion loved cats so much that he always prepared delicious food for the occasional cats. The hungry cats jumped over the high walls and rushed straight to the rice that was everywhere in the mansion.

One day the husband found some cats lying down in the mansion. The cats ran around the mansion in search of food, hitting and falling. The husband decided to devise a place to put the rice in consideration of the safety of the cats.

<image>

Seen from the sky, the fence of this mansion is polygonal. The owner decided to place the rice only at the top of the polygon on the premises so that the cats could easily find it. Also, since cats are capricious, it is unpredictable from which point on the circumference of the polygon they will enter the mansion. Therefore, the husband also decided to arrange the rice so that no matter where the cat entered, he would go straight from that point and reach one of the rice.

You can meet this condition by placing rice at all vertices. However, it is difficult to replenish the rice and go around, so the master wanted to place the rice at as few vertices as possible. Now, how many places does the master need to place the rice?

Enter the polygon that represents the wall of the mansion as an input, and create a program that finds the minimum number of vertices on which rice is placed. However, the cat shall be able to go straight only inside the polygon (the sides shall be included inside the polygon).

input

The input consists of multiple datasets. The end of the input is indicated by a single zero line. Each dataset is given in the following format:

n
x1 y1
x2 y2
...
xn yn

The number of vertices of the polygon n (3 ≤ n ≤ 16) is given in the first line. The following n lines give the coordinates of the vertices of the polygon. Each of the n lines consists of two integers separated by one space. xi (-1000 ≤ xi ≤ 1000) indicates the x coordinate of the i-th vertex, and yi (-1000 ≤ yi ≤ 1000) indicates the y coordinate of the i-th vertex. The vertices of a polygon are given in such an order that they visit adjacent vertices counterclockwise.

The number of datasets does not exceed 20.

output

For each data set, the number of vertices on which rice is placed is output on one line.

Example

Input

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

Output

1
2

### Response

```cpp
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

typedef complex<double> Point;
const double EPS = 1e-8;

int sign(double a){
    if(a > EPS) return +1;
    if(a < -EPS) return -1;
    return 0;
}
double dot(Point a, Point b){
    return real(conj(a) * b);
}
double cross(Point a, Point b){
    return imag(conj(a) * b);
}
int ccw(Point a, Point b, Point c) {
    b -= a; c -= a;
    double len = abs(b) * abs(c); // テゥツ?淌」ツ?陛」ツ?古ヲツーツ療」ツ?ォテ」ツ?ェテ」ツつ凝」ツ?ィテ」ツ?催」ツ?ッ1テ」ツ?ォテ」ツ?凖」ツつ?
    if (cross(b, c) > +len * EPS)   return +1; // テ・ツ渉催ヲツ卍づィツィツ暗・ツ崢榲」ツつ?
    if (cross(b, c) < -len * EPS)   return -1; // テヲツ卍づィツィツ暗・ツ崢榲」ツつ?
    if (dot(b, c) < 0)     return +2; // c--a--b テ」ツ?ョテゥツ??ァツ閉ェテ」ツ?ァテ、ツクツ?ァツ崢エテァツキツ堙、ツクツ?
    if (norm(b) < norm(c)) return -2; // a--b--c テ」ツ?ョテゥツ??ァツ閉ェテ」ツ?ァテ、ツクツ?ァツ崢エテァツキツ堙、ツクツ?
    return 0;                         // テァツつケテ」ツ?古ァツキツ堙・ツ按?bテ、ツクツ甘」ツ?ォテ」ツ?づ」ツつ?
}
struct Line : public vector<Point> {
    Line() {}
    Line(const Point& a, const Point& b) {
        push_back(a); push_back(b);
    }
    Point vector() const {
        return back() - front();
    }
};
typedef vector<Point> Polygon; // テ・ツ渉催ヲツ卍づィツィツ暗・ツ崢榲」ツつ甘」ツつ津、ツサツョテ・ツョツ?
Point crosspointLL(Line l, Line m){
    double A = cross(l.vector(), m.vector());
    double B = cross(l.vector(), l[1] - m[0]);
    if(sign(A) == 0 && sign(B) == 0) return m[0]; // テ、ツコツ古ァツ崢エテァツキツ堙」ツ?古ゥツ?催」ツ?ェテ」ツ?」テ」ツ?ヲテ」ツ??」ツつ?
    if(sign(A) == 0) assert(false); // テァツ崢エテァツキツ堙」ツ?古、ツコツ、テ」ツつ湘」ツつ嘉」ツ?ェテ」ツ??
    return m[0] + m.vector() * B / A;
}
// テ、ツクツ。テァツォツッテ」ツつ津・ツ青ォテ」ツ?セテ」ツ?ェテ」ツ??
bool intersectSP(Line s, Point p) {
    return ccw(s[0], s[1], p) == 0 && abs(s[0] - p) > EPS && abs(s[1] - p) > EPS;
}
bool equalLL(Line l, Line m){
    return sign(cross(l.vector(), m[0] - l[0])) == 0;
}
bool intersectLS(Line l, Line s) {
    // テァツ崢エテァツキツ嗟テ」ツ?ォテ」ツ?、テ」ツ??」ツ?ヲテ」ツ??ァツキツ堙・ツ按?テ」ツ?ョテァツォツッテァツつケテ」ツ?古ァツ閉ーテ」ツ?ェテ」ツつ凝・ツ?エテ」ツ?ォテ」ツ?づ」ツつ?
    return sign(cross(l.vector(), s[0] - l[0]) * cross(l.vector(), s[1] - l[0])) <= 0;
}
bool intersectSS(Line s, Line t) {
    bool f = ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 && ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
    if(!f) return false;
    Point cp = crosspointLL(s, t);
    return intersectSP(s, cp) && intersectSP(t, cp);
}

Point curr(const Polygon& P, int x){
    return P[x];
}
Point next(const Polygon& P, int x){
    return P[(x + 1) % P.size()];
}

enum { OUT, ON, IN };
int contains(const Polygon& P, const Point& p){
    // テァツつケpテ」ツ?凝」ツつ嘉・ツ債甘ァツ崢エテァツキツ堙」ツつ津」ツ?イテ」ツ?催」ツ??ィツセツコテ」ツ?ィテ、ツコツ、テ・ツキツョテ」ツ?凖」ツつ凝・ツ崢榲ヲツ閉ーテ」ツつ津ヲツ閉ーテ」ツ?暗」ツつ?
    bool in = false;
    for(int i = 0; i < P.size(); i++){
        Point a = curr(P, i) - p;
        Point b = next(P, i) - p;
        if(a.imag() > b.imag()) swap(a, b);
        // aテ」ツ?凝」ツつ叡テ」ツ?ョテァツ崢エテァツキツ堙」ツ?軽=0テ」ツ?ィテ、ツコツ、テ」ツつ湘」ツつ甘」ツ??」ツ?敕」ツ?ョテ、ツコツ、テァツつケテ」ツ?ッテ・ツ篠淌ァツつケテ」ツ?ョテ・ツ渉ウテ・ツ?エテ」ツ?ァテ」ツ?づ」ツつ?
        if(a.imag() <= 0 && 0 < b.imag() && cross(a, b) < 0){
            in = !in;
        }
        if(sign(cross(a, b)) == 0 && sign(dot(a, b)) <= 0) return ON;
    }
    return in ? IN : OUT;
}

bool arrivable(Point bp, Point tp, const vector<Line>& poly_line, const Polygon& P){
    if(contains(P, 0.5 * (bp + tp)) == OUT) return false;

    Line cat(bp, tp);
    for(int k = 0; k < poly_line.size(); k++){
        Line pol = poly_line[k];
        if(equalLL(cat, pol)) continue;
        if(intersectSS(cat, pol)) return false;
    }

    return true;
}

int main(){
    int N;
    while(cin >> N && N){
        Polygon P(N);
        for(int i = 0; i < N; i++){
            double x, y;
            cin >> x >> y;
            P[i] = Point(x, y);
        }

        vector<Line> poly_line(N);
        for(int i = 0; i < N; i++){
            poly_line[i] = Line(P[i], P[(i + 1) % P.size()]);
            //fprintf(stderr, "line(%f, %f, %f, %f);\n",
                    //P[i].real() * 100, P[i].imag() * 100, P[(i + 1) % P.size()].real() * 100, P[(i + 1) % P.size()].imag() * 100);
        }

        vector<Point> cand_point = P; // テ・ツ?凖ィツ」ツ愿ァツつケ
        for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++){
            if(i == j) continue;
            Point bp = P[i], ep = P[j];
            Line cat(bp, ep);

            bool is_cross = false;
            Point cross_p;
            Line cross_l;
            int cross_idx;
            for(int k = 0; k < N; k++){
                Line pol = poly_line[k];

                if(equalLL(cat, pol)) continue;
                if(!intersectLS(cat, pol)) continue;

                Point cp = crosspointLL(cat, pol);

                if(!intersectSP(pol, cp)) continue;

                assert(abs(ccw(cat[0], cat[1], cp)) != 1);
                if(dot(cat.vector(), cp - cat[0]) < 0) continue; // true??
                //if(ccw(cat[0], cat[1], cp) != -2) continue; // true???

                if(!is_cross){
                    is_cross = true;
                    cross_p = cp; cross_l = pol;
                    cross_idx = k;
                }else if(abs(cross_p - cat[0]) > abs(cp - cat[0])){
                    cross_p = cp; cross_l = pol;
                    cross_idx = k;
                }

            }
            if(is_cross){
                //fprintf(stderr, "o : line(p[%d] = (%.0f, %.0f), p[%d] = (%.0f, %.0f)) has intersect\n", i, bp.real(), bp.imag(), j, ep.real(), ep.imag());
                //fprintf(stderr, "    line[%d]((%.0f, %.0f), (%.0f, %.0f)) , cross (%f. %f) \n",
                        //cross_idx, cross_l[0].real(), cross_l[0].imag(), cross_l[1].real(), cross_l[1].imag(), cross_p.real(), cross_p.imag());
                //fprintf(stderr, "circle(%f, %f, 5.0);\n", cross_p.real() * 100, cross_p.imag() * 100);
                cand_point.push_back(cross_p + cross_l.vector() * EPS);
                cand_point.push_back(cross_p - cross_l.vector() * EPS);
            }else{
                //fprintf(stderr, "x : line(p[%d] = (%.0f, %.0f), p[%d] = (%.0f, %.0f)) has no intersect\n", i, bp.real(), bp.imag(), j, ep.real(), ep.imag());
            }
        }

        vector<vector<bool>> is_arrivable(N, vector<bool>(cand_point.size(), false));
        for(int i = 0; i < N; i++)
        for(int j = 0; j < cand_point.size(); j++){
            Point bp = P[i], tp = cand_point[j];
            is_arrivable[i][j] = arrivable(bp, tp, poly_line, P);
            //fprintf(stderr, "%c : p[%d] -> (%f, %f)\n", is_arrivable[i][j] ? 'o' : 'x', i, cand_point[j].real(), cand_point[j].imag());
            if(i == 0 && !is_arrivable[i][j]){
                //fprintf(stderr, "line(%f, %f, %f, %f)\n", bp.real() * 100, bp.imag() * 100, tp.real() * 100, tp.imag() * 100);
            }
        }

        int ans = N;
        for(int s = 1; s < (1 << N); s++){
            int bits = __builtin_popcount(s);
            if(bits >= ans) continue;
            vector<bool> ok(cand_point.size(), false);
            for(int i = 0; i < N; i++) if(s >> i & 1)
                for(int j = 0; j < cand_point.size(); j++)
                    ok[j] = ok[j] || is_arrivable[i][j];

            bool is_answer = true;
            for(int i = 0; i < cand_point.size(); i++) if(!ok[i]){
                is_answer = false;
                break;
            }

            if(is_answer) {
                ans = bits;
            }
        }

        cout << ans << endl;
    }
    return 0;
}
```


### Prompt

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

AtCoDeer has three cards, one red, one green and one blue.
An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card.
We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.
Is this integer a multiple of 4?

Constraints

* 1 ≤ r, g, b ≤ 9

Input

Input is given from Standard Input in the following format:

r g b

Output

If the three-digit integer is a multiple of 4, print `YES` (case-sensitive); otherwise, print `NO`.

Examples

Input

4 3 2

Output

YES

Input

2 3 4

Output

NO

### Response

```cpp
#include<iostream>
using namespace std;
int main(){
  int r,g,b;
  cin>>r>>g>>b;
  ((10*g+b)%4==0)?cout<<"YES":cout<<"NO";
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.

The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.

You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.

Input

The first line contains a non-empty string s — the sum Xenia needs to count. String s contains no spaces. It only contains digits and characters "+". Besides, string s is a correct sum of numbers 1, 2 and 3. String s is at most 100 characters long.

Output

Print the new sum that Xenia can count.

Examples

Input

3+2+1

Output

1+2+3

Input

1+1+3+1+3

Output

1+1+1+3+3

Input

2

Output

2

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int a = 0, b = 0, c = 0;
  char ch;
  while (ch = getchar()) {
    if (ch == '1')
      a++;
    else if (ch == '2')
      b++;
    else if (ch == '3')
      c++;
    else if (ch == '\n')
      break;
  }
  bool first = true;
  for (int i = 0; i < a; i++) {
    if (first == true) {
      printf("1");
      first = false;
    } else
      printf("+1");
  }
  for (int i = 0; i < b; i++) {
    if (first == true) {
      printf("2");
      first = false;
    } else
      printf("+2");
  }
  for (int i = 0; i < c; i++) {
    if (first == true) {
      printf("3");
      first = false;
    } else
      printf("+3");
  }
  printf("\n");
  return 0;
}

```


### Prompt

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

Imp is really pleased that you helped him. But it you solve the last problem, his gladness would raise even more.

<image> Let's define <image> for some set of integers <image> as the number of pairs a, b in <image>, such that:

  * a is strictly less than b;
  * a divides b without a remainder.

You are to find such a set <image>, which is a subset of {1, 2, ..., n} (the set that contains all positive integers not greater than n), that <image>.

Input

The only line contains two integers n and k <image>.

Output

If there is no answer, print "No".

Otherwise, in the first line print "Yes", in the second — an integer m that denotes the size of the set <image> you have found, in the second line print m integers — the elements of the set <image>, in any order.

If there are multiple answers, print any of them.

Examples

Input

3 3

Output

No

Input

6 6

Output

Yes
5
1 2 4 5 6

Input

8 3

Output

Yes
4
2 4 5 8

Note

In the second sample, the valid pairs in the output set are (1, 2), (1, 4), (1, 5), (1, 6), (2, 4), (2, 6). Thus, <image>.

In the third example, the valid pairs in the output set are (2, 4), (4, 8), (2, 8). Thus, <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k;
int sum[1000000];
bool bz[1000000];
long long all;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    bz[i] = 1;
    for (int j = 2; (long long)j * i <= n; j++) sum[j * i]++, all++;
  }
  if (all < k) {
    printf("No");
    return 0;
  }
  for (int i = n; i; i--) {
    int tot = sum[i];
    for (int j = 2; (long long)j * i <= n; j++)
      if (bz[i * j]) tot++;
    if (tot > 1 && all - tot >= k) {
      bz[i] = 0, all -= tot;
      for (int j = 1; (long long)j * i <= n; j++)
        if (bz[i * j]) sum[i * j]--;
    }
  }
  for (int i = n; i; i--)
    if (bz[i]) {
      int tot = sum[i];
      for (int j = 2; (long long)j * i <= n; j++)
        if (bz[i * j]) tot++;
      if (tot == 1 && all - tot >= k) {
        bz[i] = 0, all -= tot;
        for (int j = 1; (long long)j * i <= n; j++)
          if (bz[i * j]) sum[i * j]--;
      }
    }
  if (all == k) {
    printf("Yes\n");
    int tot = 0;
    for (int i = 1; i <= n; i++) tot += bz[i];
    printf("%d\n", tot);
    for (int i = 1; i <= n; i++)
      if (bz[i]) printf("%d ", i);
  } else
    printf("No");
  return 0;
}

```


### Prompt

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

Snuke arranged N colorful balls in a row. The i-th ball from the left has color c_i and weight w_i.

He can rearrange the balls by performing the following two operations any number of times, in any order:

* Operation 1: Select two balls with the same color. If the total weight of these balls is at most X, swap the positions of these balls.
* Operation 2: Select two balls with different colors. If the total weight of these balls is at most Y, swap the positions of these balls.

How many different sequences of colors of balls can be obtained? Find the count modulo 10^9 + 7.

Constraints

* 1 ≤ N ≤ 2 × 10^5
* 1 ≤ X, Y ≤ 10^9
* 1 ≤ c_i ≤ N
* 1 ≤ w_i ≤ 10^9
* X, Y, c_i, w_i are all integers.

Input

Input is given from Standard Input in the following format:

N X Y
c_1 w_1
:
c_N w_N

Output

Print the answer.

Examples

Input

4 7 3
3 2
4 3
2 1
4 4

Output

2

Input

1 1 1
1 1

Output

1

Input

21 77 68
16 73
16 99
19 66
2 87
2 16
7 17
10 36
10 68
2 38
10 74
13 55
21 21
3 7
12 41
13 88
18 6
2 12
13 87
1 9
2 27
13 15

Output

129729600

### Response

```cpp
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2*1e5+10,mod=1e9+7;;
int c[N],w[N];
int minn[N];
int numcol[N];
int cnt=0;
int n;
int fac[N],inv[N];
int poww(int x,int y)
{
	int sum=1ll;
	while(y)
	{
		if(y&1)sum=(sum*x)%mod;
		x=(x*x)%mod;
		y>>=1;
	}
	return sum;
}
void prec()
{
	fac[0]=1;
	for(int i=1;i<=n;i++)fac[i]=i*fac[i-1]%mod;
	inv[n]=poww(fac[n],mod-2);
	for(int i=n-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
}
int C(int x,int y)
{
	return ((fac[y]*inv[y-x])%mod*inv[x])%mod;
}
signed main()
{
	memset(minn,127,sizeof(minn));
	int x,y;
	scanf("%lld %lld %lld",&n,&x,&y);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld %lld",&c[i],&w[i]);
		minn[c[i]]=min(minn[c[i]],w[i]);
	}
	int fir_min=0,sec_min=0;
	for(int i=1;i<=n;i++)
	{
		if(minn[i]<minn[fir_min])
		{
			sec_min=fir_min;
			fir_min=i;
		}
		else if(minn[i]<minn[sec_min])sec_min=i;
	}
	for(int i=1;i<=n;i++)
	{
		if(w[i]+minn[c[i]]<=x)w[i]=minn[c[i]];
		if((c[i]==fir_min&&minn[sec_min]+w[i]<=y)||(c[i]!=fir_min&&minn[fir_min]+w[i]<=y))
		{
			numcol[c[i]]++;
			cnt++;
		}
	}
	prec();
	int ans=1;
	for(int i=1;i<=n;i++)
	{
		if(numcol[i])
		{
			ans=(ans*C(numcol[i],cnt))%mod;
			cnt-=numcol[i];
		}
	}
	printf("%lld",ans);
	return 0;
}
/*
4 7 3
3 2
4 3
2 1
4 4
*/
```


### Prompt

Develop a solution in Cpp to the problem described below:

Oleg Petrov loves crossword puzzles and every Thursday he buys his favorite magazine with crosswords and other word puzzles. In the last magazine Oleg found a curious puzzle, and the magazine promised a valuable prize for it's solution. We give a formal description of the problem below.

The puzzle field consists of two rows, each row contains n cells. Each cell contains exactly one small English letter. You also are given a word w, which consists of k small English letters. A solution of the puzzle is a sequence of field cells c1, ..., ck, such that:

  * For all i from 1 to k the letter written in the cell ci matches the letter wi;
  * All the cells in the sequence are pairwise distinct;
  * For all i from 1 to k - 1 cells ci and ci + 1 have a common side.

Oleg Petrov quickly found a solution for the puzzle. Now he wonders, how many distinct solutions are there for this puzzle. Oleg Petrov doesn't like too large numbers, so calculate the answer modulo 109 + 7.

Two solutions ci and c'i are considered distinct if the sequences of cells do not match in at least one position, that is there is such j in range from 1 to k, such that cj ≠ c'j.

Input

The first two lines contain the state of the field for the puzzle. Each of these non-empty lines contains exactly n small English letters.

The next line is left empty.

The next line is non-empty and contains word w, consisting of small English letters.

The length of each line doesn't exceed 2 000.

Output

Print a single integer — the number of distinct solutions for the puzzle modulo 109 + 7.

Examples

Input

code
edoc

code

Output

4

Input

aaa
aaa

aa

Output

14

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void inc(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
void dec(int &x, int y) {
  x -= y;
  if (x < 0) x += mod;
}
const int N = 2001, M = 2 * N;
int n, m;
char a[2][N], w[M];
int c[2][N][M], cr[2][N][M];
void calcc(int u, int c[N][M]) {
  for (int i(n - 1), b_(0); i >= b_; --i)
    for (int j(m - 1), b_(0); j >= b_; --j)
      c[i][j] = a[u][i] == w[j] ? 1 + c[i + 1][j + 1] : 0;
}
int d[2][N][M];
int solve(bool first) {
  int ans = 0;
  memset(d, 0, sizeof d);
  for (int i(0), b_(n); i < b_; ++i) {
    d[0][i][0] = d[1][i][0] = 1;
    for (int u(0), b_(2); u < b_; ++u)
      for (int j(2), b_(min(n - i, m / 2) + 1); j < b_; ++j)
        if (c[u][i][m - 2 * j] >= j && cr[u ^ 1][i][0] >= j)
          if (2 * j < m || first) inc(ans, d[u][i][m - 2 * j]);
    for (int u(0), b_(2); u < b_; ++u)
      for (int j(0), b_(m); j < b_; ++j)
        if (a[u][i] == w[j]) {
          inc(d[u][i + 1][j + 1], d[u][i][j]);
          if (j + 1 < m && a[u ^ 1][i] == w[j + 1])
            inc(d[u ^ 1][i + 1][j + 2], d[u][i][j]);
        }
    for (int u(0), b_(2); u < b_; ++u)
      for (int j(2), b_(min(i + 1, m / 2) + 1); j < b_; ++j) {
        int l = i - j + 1;
        if (c[u][l][j] >= j && cr[u ^ 1][l][m - j] >= j)
          if (2 * j < m || first) inc(d[u][i + 1][2 * j], 1);
      }
    for (int u(0), b_(2); u < b_; ++u) inc(ans, d[u][i + 1][m]);
  }
  return ans;
}
int main() {
  scanf("%s%s%s", a[0], a[1], w);
  n = strlen(a[0]);
  m = strlen(w);
  int ans = 0;
  if (2 * n >= m) {
    for (int u(0), b_(2); u < b_; ++u) calcc(u, cr[u]);
    reverse(w, w + m);
    for (int u(0), b_(2); u < b_; ++u) calcc(u, c[u]);
    ans = solve(true);
    if (m > 1) {
      reverse(w, w + m);
      for (int u(0), b_(2); u < b_; ++u)
        for (int i(0), b_(n); i < b_; ++i)
          for (int j(0), b_(m); j < b_; ++j) swap(c[u][i][j], cr[u][i][j]);
      inc(ans, solve(false));
      if (m == 2)
        for (int i(0), b_(n); i < b_; ++i)
          for (int u(0), b_(2); u < b_; ++u)
            if (a[u][i] == w[0] && a[u ^ 1][i] == w[1]) dec(ans, 1);
    }
  }
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

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

Motorist Kojiro spent 10 years saving up for his favorite car brand, Furrari. Finally Kojiro's dream came true! Kojiro now wants to get to his girlfriend Johanna to show off his car to her.

Kojiro wants to get to his girlfriend, so he will go to her along a coordinate line. For simplicity, we can assume that Kojiro is at the point f of a coordinate line, and Johanna is at point e. Some points of the coordinate line have gas stations. Every gas station fills with only one type of fuel: Regular-92, Premium-95 or Super-98. Thus, each gas station is characterized by a pair of integers ti and xi — the number of the gas type and its position.

One liter of fuel is enough to drive for exactly 1 km (this value does not depend on the type of fuel). Fuels of three types differ only in quality, according to the research, that affects the lifetime of the vehicle motor. A Furrari tank holds exactly s liters of fuel (regardless of the type of fuel). At the moment of departure from point f Kojiro's tank is completely filled with fuel Super-98. At each gas station Kojiro can fill the tank with any amount of fuel, but of course, at no point in time, the amount of fuel in the tank can be more than s liters. Note that the tank can simultaneously have different types of fuel. The car can moves both left and right.

To extend the lifetime of the engine Kojiro seeks primarily to minimize the amount of fuel of type Regular-92. If there are several strategies to go from f to e, using the minimum amount of fuel of type Regular-92, it is necessary to travel so as to minimize the amount of used fuel of type Premium-95.

Write a program that can for the m possible positions of the start fi minimize firstly, the amount of used fuel of type Regular-92 and secondly, the amount of used fuel of type Premium-95.

Input

The first line of the input contains four positive integers e, s, n, m (1 ≤ e, s ≤ 109, 1 ≤ n, m ≤ 2·105) — the coordinate of the point where Johanna is, the capacity of a Furrari tank, the number of gas stations and the number of starting points.

Next n lines contain two integers each ti, xi (1 ≤ ti ≤ 3, - 109 ≤ xi ≤ 109), representing the type of the i-th gas station (1 represents Regular-92, 2 — Premium-95 and 3 — Super-98) and the position on a coordinate line of the i-th gas station. Gas stations don't necessarily follow in order from left to right.

The last line contains m integers fi ( - 109 ≤ fi < e). Start positions don't necessarily follow in order from left to right.

No point of the coordinate line contains more than one gas station. It is possible that some of points fi or point e coincide with a gas station.

Output

Print exactly m lines. The i-th of them should contain two integers — the minimum amount of gas of type Regular-92 and type Premium-95, if Kojiro starts at point fi. First you need to minimize the first value. If there are multiple ways to do it, you need to also minimize the second value.

If there is no way to get to Johanna from point fi, the i-th line should look like that "-1 -1" (two numbers minus one without the quotes).

Examples

Input

8 4 1 1
2 4
0

Output

0 4

Input

9 3 2 3
2 3
1 6
-1 0 1

Output

-1 -1
3 3
3 2

Input

20 9 2 4
1 5
2 10
-1 0 1 2

Output

-1 -1
-1 -1
-1 -1
-1 -1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int result_good[300000];
int result_bad[300000];
int s = 0;
void solve(vector<int *> &positions) {
  int ends[3] = {0, 0, 0};
  int starts[3] = {0, 0, 0};
  int gas[3] = {0, 0, 0};
  for (vector<int *>::iterator it = positions.begin(); it != positions.end();
       ++it) {
    int *a = (*it);
    int pos = a[0], t = a[1], id = a[2];
    if (pos - s > *max_element(ends, ends + 3)) break;
    for (int i = 0; i < 3; ++i) {
      if (starts[i] < pos - s) starts[i] = pos - s;
      if (ends[i] < pos - s) ends[i] = pos - s;
    }
    if (t == 3) {
      result_bad[id] = gas[0] - (ends[0] - starts[0]);
      result_good[id] = gas[1] - (ends[1] - starts[1]);
    } else {
      for (int i = 0; i < t + 1; ++i) {
        gas[i] -= ends[i] - starts[i];
        ends[i] = pos - s;
        starts[i] = pos - s;
      }
      starts[t] = *max_element(ends, ends + 3);
      ends[t] = pos;
      gas[t] += ends[t] - starts[t];
    }
  }
}
bool comp(int *a, int *b) { return a[0] < b[0]; }
int main() {
  memset(result_bad, -1, sizeof(int) * 300000);
  memset(result_good, -1, sizeof(int) * 300000);
  int e, n, m;
  scanf("%d %d %d %d", &e, &s, &n, &m);
  vector<int *> positive, negative;
  int t, x;
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", &t, &x);
    int *a = new int[3];
    a[1] = t - 1;
    a[2] = -1;
    if (x > e) {
      a[0] = x - e;
      positive.push_back(a);
    } else {
      a[0] = e - x;
      negative.push_back(a);
    }
  }
  for (int i = 0; i < m; ++i) {
    scanf("%d", &x);
    int *a = new int[3];
    a[1] = 3;
    a[2] = i;
    if (x > e) {
      a[0] = x - e;
      positive.push_back(a);
    } else if (x < e) {
      a[0] = e - x;
      negative.push_back(a);
    } else {
      result_bad[i] = 0;
      result_good[i] = 0;
    }
  }
  sort(positive.begin(), positive.end(), comp);
  sort(negative.begin(), negative.end(), comp);
  solve(positive);
  solve(negative);
  for (int i = 0; i < m; ++i) {
    printf("%d %d\n", result_bad[i], result_good[i]);
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Some large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMSC.

For that, he asked to give him the statistics of the performance of the SMSC for some period of time. In the end, Polycarpus got a list of n tasks that went to the SMSC of the corporation. Each task was described by the time it was received by the SMSC and the number of text messages to send. More formally, the i-th task was described by two integers ti and ci — the receiving time (the second) and the number of the text messages, correspondingly.

Polycarpus knows that the SMSC cannot send more than one text message per second. The SMSC uses a queue to organize its work. Consider a time moment x, the SMSC work at that moment as follows:

  1. If at the time moment x the queue is not empty, then SMSC sends one message from the queue (SMSC gets the message from the head of the queue). Otherwise it doesn't send messages at the time moment x.
  2. If at the time moment x SMSC receives a task, then it adds to the queue all the messages from this task (SMSC adds messages to the tail of the queue). Note, that the messages from the task cannot be send at time moment x. That's because the decision about sending message or not is made at point 1 before adding these messages to the queue.

Given the information about all n tasks, Polycarpus wants to count two values: the time when the last text message was sent and the maximum size of the queue at some time. Help him count these two characteristics he needs to evaluate the efficiency of the SMSC.

Input

The first line contains a single integer n (1 ≤ n ≤ 103) — the number of tasks of the SMSC. Next n lines contain the tasks' descriptions: the i-th line contains two space-separated integers ti and ci (1 ≤ ti, ci ≤ 106) — the time (the second) when the i-th task was received and the number of messages to send, correspondingly.

It is guaranteed that all tasks were received at different moments of time. It is guaranteed that the tasks are sorted in the chronological order, that is, ti < ti + 1 for all integer i (1 ≤ i < n).

Output

In a single line print two space-separated integers — the time when the last text message was sent and the maximum queue size at a certain moment of time.

Examples

Input

2
1 1
2 1

Output

3 1

Input

1
1000000 10

Output

1000010 10

Input

3
3 3
4 3
5 3

Output

12 7

Note

In the first test sample:

  * second 1: the first message has appeared in the queue, the queue's size is 1;
  * second 2: the first message is sent, the second message has been received, the queue's size is 1;
  * second 3: the second message is sent, the queue's size is 0,

Thus, the maximum size of the queue is 1, the last message was sent at the second 3.

### Response

```cpp
#include <bits/stdc++.h>
int max(int a, int b) { return a > b ? a : b; }
int main(void) {
  int time, maximum, queue, t, c, i, n;
  while (scanf("%d", &n) != EOF) {
    queue = 0;
    time = 0;
    maximum = 0;
    for (i = 0; i < n; i++) {
      maximum = max(maximum, queue);
      if (queue) queue--;
      scanf("%d %d", &t, &c);
      if (t > time) {
        queue = max(0, queue - (t - time) + 1);
        time = t;
      } else {
        time++;
      }
      queue += c;
    }
    maximum = max(maximum, queue);
    time += queue;
    printf("%d %d\n", time, maximum);
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Sergey just turned five years old! When he was one year old, his parents gave him a number; when he was two years old, his parents gave him an array of integers. On his third birthday he received a string. When he was four, his mother woke him up in a quiet voice, wished him to be a good boy and gave him a rooted tree. Today he celebrates his birthday again! He found a directed graph without loops as a present from his parents.

Since Sergey is a very curious boy, he immediately came up with a thing to do. He decided to find a set Q of vertices in this graph, such that no two vertices x, y ∈ Q are connected by an edge, and it is possible to reach any vertex z ∉ Q from some vertex of Q in no more than two moves.

After a little thought, Sergey was able to solve this task. Can you solve it too?

A vertex y is reachable from a vertex x in at most two moves if either there is a directed edge (x,y), or there exist two directed edges (x,z) and (z, y) for some vertex z.

Input

The first line of input contains two positive integers n and m (1 ≤ n ≤ 1 000 000, 1 ≤ m ≤ 1 000 000) — the number of vertices and the number of edges in the directed graph.

Each of the following m lines describes a corresponding edge. Each one contains two integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) — the beginning and the end of the i-th edge. The graph may contain multiple edges between the same pair of vertices.

Output

First print the number k — the number of selected vertices. Then print k distinct integers — the indices of the selected vertices.

If multiple answers exist you can output any of them. In particular, you don't have to minimize the number of vertices in the set. It is guaranteed, that there is always at least one valid set.

Examples

Input

5 4
1 2
2 3
2 4
2 5

Output

4
1 3 4 5

Input

3 3
1 2
2 3
3 1

Output

1
3

Note

In the first sample, the vertices 1, 3, 4, 5 are not connected. The vertex 2 is reachable from vertex 1 by one edge.

In the second sample, it is possible to reach the vertex 1 in one move and the vertex 2 in two moves.

The following pictures illustrate sample tests and their answers.

<image> <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool bit(int n, int i) { return (n >> i) & 1; }
int ceil(int a, int b) { return ceil(((long double)a) / b); }
int faltu;
const int mod = 1e9 + 7;
const long long inf = 4e18;
const long long ninf = -inf;
const int imax = 2e9 + 100;
const int maxn = 1e6 + 100;
int n, m;
vector<int> g[maxn];
vector<int> save;
bool mark[maxn], mark1[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  ;
  time_t t1, t2;
  t1 = clock();
  srand(time(0));
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
  }
  for (int i = 1; i <= n; i++) {
    if (!mark[i]) {
      mark[i] = true;
      save.push_back(i);
      for (int j : g[i]) {
        mark[j] = true;
      }
    }
  }
  reverse(save.begin(), save.end());
  vector<int> ans;
  for (int i : save) {
    if (!mark1[i]) {
      ans.push_back(i);
      for (int j : g[i]) {
        mark1[j] = true;
      }
    }
  }
  cout << ans.size() << endl;
  for (int i : ans) {
    cout << i << ' ';
  }
  t2 = clock();
  cerr << "time taken: " << t2 - t1 << endl;
  return 0;
}

```


### Prompt

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

Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not.

Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days.

Input

In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters.

Output

If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≤ k ≤ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer li (1 ≤ li ≤ |s|), which is the length of the i-th subsequence, and then li indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1.

Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k.

Examples

Input

0010100

Output

3
3 1 3 4
3 2 5 6
1 7

Input

111

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int tinf = (int)1e9 + 7;
const long long inf = (long long)1e18 + 7;
const int N = 2e5 + 5;
int main() {
  {
    ios ::sync_with_stdio(false);
    cin.tie(0);
  }
  long long n, t, g;
  vector<vector<long long> > ans;
  string second;
  cin >> second;
  n = second.length();
  long long x = 0;
  t = -1, g = 0;
  for (int i = 0; i < n; i++)
    if (second[i] == '1') {
      if (t == -1) {
        cout << t;
        return 0;
      }
      ans[t].push_back(i), t--, g++;
    } else {
      if (!g) {
        t++;
        vector<long long> a;
        a.push_back(i);
        ans.push_back(a);
      } else
        t++, ans[t].push_back(i), g--;
    }
  if (g) {
    cout << -1;
    return 0;
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].size() << " ";
    for (int j = 0; j < ans[i].size(); j++) cout << ans[i][j] + 1 << " ";
    cout << endl;
  }
}

```


### Prompt

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

Welcome to Codeforces Stock Exchange! We're pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope you'll still be able to make profit from the market!

In the morning, there are n opportunities to buy shares. The i-th of them allows to buy as many shares as you want, each at the price of s_i bourles.

In the evening, there are m opportunities to sell shares. The i-th of them allows to sell as many shares as you want, each at the price of b_i bourles. You can't sell more shares than you have.

It's morning now and you possess r bourles and no shares.

What is the maximum number of bourles you can hold after the evening?

Input

The first line of the input contains three integers n, m, r (1 ≤ n ≤ 30, 1 ≤ m ≤ 30, 1 ≤ r ≤ 1000) — the number of ways to buy the shares on the market, the number of ways to sell the shares on the market, and the number of bourles you hold now.

The next line contains n integers s_1, s_2, ..., s_n (1 ≤ s_i ≤ 1000); s_i indicates the opportunity to buy shares at the price of s_i bourles.

The following line contains m integers b_1, b_2, ..., b_m (1 ≤ b_i ≤ 1000); b_i indicates the opportunity to sell shares at the price of b_i bourles.

Output

Output a single integer — the maximum number of bourles you can hold after the evening.

Examples

Input

3 4 11
4 2 5
4 4 5 4

Output

26

Input

2 2 50
5 7
4 2

Output

50

Note

In the first example test, you have 11 bourles in the morning. It's optimal to buy 5 shares of a stock at the price of 2 bourles in the morning, and then to sell all of them at the price of 5 bourles in the evening. It's easy to verify that you'll have 26 bourles after the evening.

In the second example test, it's optimal not to take any action.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int n, m, r;
  scanf("%d %d %d", &n, &m, &r);
  int a, b;
  int min = 1001, max = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    if (a < min) {
      min = a;
    }
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &b);
    if (b > max) {
      max = b;
    }
  }
  int div;
  int mod;
  mod = r % min;
  div = r / min;
  int sold;
  if (div > 0) {
    sold = div * max;
    int result;
    result = sold + mod;
    if (result < r) {
      printf("%d", r);
    } else {
      printf("%d", result);
    }
  } else if (div == 0) {
    printf("%d", r);
  }
  printf("\n");
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

Recently an official statement of the world Olympic Committee said that the Olympic Winter Games 2030 will be held in Tomsk. The city officials decided to prepare for the Olympics thoroughly and to build all the necessary Olympic facilities as early as possible. First, a biathlon track will be built.

To construct a biathlon track a plot of land was allocated, which is a rectangle divided into n × m identical squares. Each of the squares has two coordinates: the number of the row (from 1 to n), where it is located, the number of the column (from 1 to m), where it is located. Also each of the squares is characterized by its height. During the sports the biathletes will have to move from one square to another. If a biathlete moves from a higher square to a lower one, he makes a descent. If a biathlete moves from a lower square to a higher one, he makes an ascent. If a biathlete moves between two squares with the same height, then he moves on flat ground.

The biathlon track should be a border of some rectangular area of the allocated land on which biathletes will move in the clockwise direction. It is known that on one move on flat ground an average biathlete spends tp seconds, an ascent takes tu seconds, a descent takes td seconds. The Tomsk Administration wants to choose the route so that the average biathlete passes it in as close to t seconds as possible. In other words, the difference between time ts of passing the selected track and t should be minimum.

For a better understanding you can look at the first sample of the input data. In this sample n = 6, m = 7, and the administration wants the track covering time to be as close to t = 48 seconds as possible, also, tp = 3, tu = 6 and td = 2. If we consider the rectangle shown on the image by arrows, the average biathlete can move along the boundary in a clockwise direction in exactly 48 seconds. The upper left corner of this track is located in the square with the row number 4, column number 3 and the lower right corner is at square with row number 6, column number 7.

<image>

Among other things the administration wants all sides of the rectangle which boundaries will be the biathlon track to consist of no less than three squares and to be completely contained within the selected land.

You are given the description of the given plot of land and all necessary time values. You are to write the program to find the most suitable rectangle for a biathlon track. If there are several such rectangles, you are allowed to print any of them.

Input

The first line of the input contains three integers n, m and t (3 ≤ n, m ≤ 300, 1 ≤ t ≤ 109) — the sizes of the land plot and the desired distance covering time.

The second line also contains three integers tp, tu and td (1 ≤ tp, tu, td ≤ 100) — the time the average biathlete needs to cover a flat piece of the track, an ascent and a descent respectively.

Then n lines follow, each line contains m integers that set the heights of each square of the given plot of land. Each of the height values is a positive integer, not exceeding 106.

Output

In a single line of the output print four positive integers — the number of the row and the number of the column of the upper left corner and the number of the row and the number of the column of the lower right corner of the rectangle that is chosen for the track.

Examples

Input

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

Output

4 3 6 7

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int ma[305][305], up[305][305], down[305][305], rg[306][305], lf[305][305], n,
    m, T;
int tp, tu, td;
void lfAndRg() {
  for (int i = 0; i < n; i++) {
    rg[i][0] = 0;
    for (int j = 1; j < m; j++) {
      if (ma[i][j] > ma[i][j - 1]) rg[i][j] = rg[i][j - 1] + tu;
      if (ma[i][j] < ma[i][j - 1]) rg[i][j] = rg[i][j - 1] + td;
      if (ma[i][j] == ma[i][j - 1]) rg[i][j] = rg[i][j - 1] + tp;
    }
    lf[i][m - 1] = 0;
    for (int j = m - 2; j >= 0; j--) {
      if (ma[i][j] > ma[i][j + 1]) lf[i][j] = lf[i][j + 1] + tu;
      if (ma[i][j] < ma[i][j + 1]) lf[i][j] = lf[i][j + 1] + td;
      if (ma[i][j] == ma[i][j + 1]) lf[i][j] = lf[i][j + 1] + tp;
    }
  }
}
void upAndDown() {
  for (int j = 0; j < m; j++) {
    down[0][j] = 0;
    for (int i = 1; i < n; i++) {
      if (ma[i][j] > ma[i - 1][j]) down[i][j] = down[i - 1][j] + tu;
      if (ma[i][j] < ma[i - 1][j]) down[i][j] = down[i - 1][j] + td;
      if (ma[i][j] == ma[i - 1][j]) down[i][j] = down[i - 1][j] + tp;
    }
    up[n - 1][j] = 0;
    for (int i = n - 2; i >= 0; i--) {
      if (ma[i][j] > ma[i + 1][j]) up[i][j] = up[i + 1][j] + tu;
      if (ma[i][j] < ma[i + 1][j]) up[i][j] = up[i + 1][j] + td;
      if (ma[i][j] == ma[i + 1][j]) up[i][j] = up[i + 1][j] + tp;
    }
  }
}
void print() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << rg[i][j] << " ";
    cout << endl;
  }
}
void print2() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << lf[i][j] << " ";
    cout << endl;
  }
}
void print3() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << up[i][j] << " ";
    cout << endl;
  }
}
void print4() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << down[i][j] << " ";
    cout << endl;
  }
}
int sum(int row1, int row2, int col) {
  int suma = 0;
  suma += rg[row1][col];
  suma += lf[row2][0] - lf[row2][col];
  suma -= (up[row1][col] - up[row2][col]);
  return suma;
}
int sum2(int row1, int row2, int col) {
  int suma = 0;
  suma += rg[row1][col];
  suma += lf[row2][0] - lf[row2][col];
  suma += down[row2][col];
  suma -= down[row1][col];
  return suma;
}
int main() {
  int x1, y1, x2, y2, ans = 1000000000;
  cin >> n >> m >> T;
  cin >> tp >> tu >> td;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> ma[i][j];
  lfAndRg();
  upAndDown();
  set<pair<int, int> > res;
  set<pair<int, int> >::iterator it;
  int val, idx, cost;
  for (int i = 0; i < n; i++) {
    for (int l = i + 2; l < n; l++) {
      res.clear();
      for (int j = 2; j < m; j++) {
        res.insert(make_pair(sum(i, l, j - 2), j - 2));
        val = sum2(i, l, j);
        it = res.lower_bound(make_pair(val - T, 0));
        if (it != res.end()) {
          idx = (*it).second;
          cost = (*it).first;
          if (abs(T - (val - cost)) < ans) {
            ans = abs(T - (val - cost));
            x1 = i;
            y1 = idx;
            x2 = l;
            y2 = j;
          }
        }
        if (it != res.begin()) {
          it--;
          idx = (*it).second;
          cost = (*it).first;
          if (abs(T - (val - cost)) < ans) {
            ans = abs(T - (val - cost));
            x1 = i;
            y1 = idx;
            x2 = l;
            y2 = j;
          }
        }
      }
    }
  }
  cout << ++x1 << " " << ++y1 << " " << ++x2 << " " << ++y2 << "\n";
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Numbers 1, 2, 3, ... n (each integer from 1 to n once) are written on a board. In one operation you can erase any two numbers a and b from the board and write one integer (a + b)/(2) rounded up instead.

You should perform the given operation n - 1 times and make the resulting number that will be left on the board as small as possible.

For example, if n = 4, the following course of action is optimal:

  1. choose a = 4 and b = 2, so the new number is 3, and the whiteboard contains [1, 3, 3];
  2. choose a = 3 and b = 3, so the new number is 3, and the whiteboard contains [1, 3];
  3. choose a = 1 and b = 3, so the new number is 2, and the whiteboard contains [2].

It's easy to see that after n - 1 operations, there will be left only one number. Your goal is to minimize it.

Input

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

The only line of each test case contains one integer n (2 ≤ n ≤ 2 ⋅ 10^5) — the number of integers written on the board initially.

It's guaranteed that the total sum of n over test cases doesn't exceed 2 ⋅ 10^5.

Output

For each test case, in the first line, print the minimum possible number left on the board after n - 1 operations. Each of the next n - 1 lines should contain two integers — numbers a and b chosen and erased in each operation.

Example

Input

1
4

Output

2
2 4
3 3
3 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void run_case() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) {
    v[i] = i + 1;
  }
  vector<pair<long long, long long>> ans;
  for (long long i = n - 2; i >= 0; i--) {
    ans.push_back({v[i], v[i + 1]});
    v[i] = (v[i] + v[i + 1] + 1) / 2;
  }
  cout << v[0] << endl;
  for (auto i : ans) {
    cout << i.first << ' ' << i.second << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tc = 1;
  cin >> tc;
  while (tc--) run_case();
  return 0;
}

```


### Prompt

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

I decided to create a program that displays a "round and round pattern". The "round and round pattern" is as follows.

* If the length of one side is n, it is displayed as a character string with n rows and n columns.
* A spiral pattern that rotates clockwise with the lower left corner as the base point.
* The part with a line is represented by # (half-width sharp), and the blank part is represented by "" (half-width blank).
* Leave a space between the lines.

Create a program that takes an integer n as an input and outputs a "round and round pattern" with a side length of n.

Input

The input is given in the following format:

d
n1
n2
::
nd

The number of datasets d (d ≤ 20) is given to the first line, and the side length ni (1 ≤ ni ≤ 100) of the i-th round pattern is given to each of the following d lines.

Output

Please output a round and round pattern for each data set. Insert a blank line between the datasets.

Example

Input

2
5
6

Output

#####
#   #
# # #
# # #
# ###

######
#    #
# ## #
# #  #
# #  #
# ####

### Response

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

#define MAX 104

enum direction{UP,RIGHT,DOWN,LEFT};

int main()
{
	int d;
	cin >> d;

	for(int x = 0; x < d; ++x){
		int n;
		int s, t;
		int dir;
		short m[MAX][MAX] = {{0,}};
		cin >> n;

		if( x > 0 )
			cout << endl;

		for(int i = 0; i < n + 4; ++i){
			if( i == 0 || i == n+3 )
				for(int j = 1; j < n+3; ++j)
					m[i][j] = 1;
			m[i][0] = m[i][n+3] = 1;
		}

		s = n + 1;
		t = 2;
		dir = UP;
		while( true )
		{
			int cnt = 0;
			const int ds[] = {-1,0,1,0};
			const int dt[] = {0,1,0,-1};

			m[s][t] = 1;

			for(int i = 0; i < 4; ++i){
				if( m[ s + ds[i] ][ t + dt[i] ] )
					++cnt;
			}
			if( cnt >= 2 ){
				m[s][t] = 0;
				break;
			}

			switch( dir ){
				case UP: if( m[s-2][t] ) dir = RIGHT; break;
				case RIGHT: if( m[s][t+2] ) dir = DOWN; break;
				case DOWN: if( m[s+2][t] ) dir = LEFT; break;
				case LEFT: if( m[s][t-2] ) dir = UP; break;
			}
			switch( dir ){
				case UP: --s; break;
				case RIGHT: ++t; break;
				case DOWN: ++s; break;
				case LEFT: --t; break;
			}
		}

		for(int i = 2; i < n + 2; ++i){
			for(int j = 2; j < n + 2; ++j)
				cout << ( m[i][j] ? '#' : ' ' );
			cout << endl;
		}
	}
	return 0;
}
```


### Prompt

Develop a solution in CPP to the problem described below:

You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.

Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?

Input

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

Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).

It is guaranteed that p / q is an irreducible fraction.

Hacks. For hacks, an additional constraint of t ≤ 5 must be met.

Output

For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.

Example

Input

4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1

Output

4
10
0
-1

Note

In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.

In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.

In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.

In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool checker(long long int x, long long int y, long long int p, long long int q,
             long long int t) {
  if (p * t >= x && q * t - p * t >= y - x) return true;
  return false;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int x, y, p, q;
    cin >> x >> y >> p >> q;
    long long int l = -1, r = 1e9;
    if (checker(x, y, p, q, r)) {
      while (r - l > 1) {
        long long int mid = (r + l) / 2;
        if (checker(x, y, p, q, mid))
          r = mid;
        else
          l = mid;
      }
      cout << q * r - y << endl;
    } else {
      cout << "-1" << endl;
    }
  }
  return 0;
}

```


### Prompt

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

Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.

Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.

Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same?

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of participants Anton has outscored in this contest .

The next n lines describe participants results: the i-th of them consists of a participant handle namei and two integers beforei and afteri ( - 4000 ≤ beforei, afteri ≤ 4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters.

It is guaranteed that all handles are distinct.

Output

Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.

Examples

Input

3
Burunduk1 2526 2537
BudAlNik 2084 2214
subscriber 2833 2749

Output

YES

Input

3
Applejack 2400 2400
Fluttershy 2390 2431
Pinkie_Pie -2500 -2450

Output

NO

Note

In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.

In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vb = vector<bool>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
int main() {
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  bool good = false;
  for (int i = (0); i < (n); i++) {
    string name;
    ll b, a;
    cin >> name >> b >> a;
    if (a > b && b >= 2400) good = true;
  }
  if (good)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

```


### Prompt

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

Ashish has a tree consisting of n nodes numbered 1 to n rooted at node 1. The i-th node in the tree has a cost a_i, and binary digit b_i is written in it. He wants to have binary digit c_i written in the i-th node in the end.

To achieve this, he can perform the following operation any number of times:

  * Select any k nodes from the subtree of any node u, and shuffle the digits in these nodes as he wishes, incurring a cost of k ⋅ a_u. Here, he can choose k ranging from 1 to the size of the subtree of u.

He wants to perform the operations in such a way that every node finally has the digit corresponding to its target.

Help him find the minimum total cost he needs to spend so that after all the operations, every node u has digit c_u written in it, or determine that it is impossible.

Input

First line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) denoting the number of nodes in the tree.

i-th line of the next n lines contains 3 space-separated integers a_i, b_i, c_i (1 ≤ a_i ≤ 10^9, 0 ≤ b_i, c_i ≤ 1) — the cost of the i-th node, its initial digit and its goal digit.

Each of the next n - 1 lines contain two integers u, v (1 ≤ u, v ≤ n,   u ≠ v), meaning that there is an edge between nodes u and v in the tree.

Output

Print the minimum total cost to make every node reach its target digit, and -1 if it is impossible.

Examples

Input

5
1 0 1
20 1 0
300 0 1
4000 0 0
50000 1 0
1 2
2 3
2 4
1 5

Output

4

Input

5
10000 0 1
2000 1 0
300 0 1
40 0 0
1 1 0
1 2
2 3
2 4
1 5

Output

24000

Input

2
109 0 1
205 0 1
1 2

Output

-1

Note

The tree corresponding to samples 1 and 2 are:

<image>

In sample 1, we can choose node 1 and k = 4 for a cost of 4 ⋅ 1 = 4 and select nodes {1, 2, 3, 5}, shuffle their digits and get the desired digits in every node.

In sample 2, we can choose node 1 and k = 2 for a cost of 10000 ⋅ 2, select nodes {1, 5} and exchange their digits, and similarly, choose node 2 and k = 2 for a cost of 2000 ⋅ 2, select nodes {2, 3} and exchange their digits to get the desired digits in every node.

In sample 3, it is impossible to get the desired digits, because there is no node with digit 1 initially.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll LINF = 1001002003004005006ll;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  ll a[n];
  int b[n], c[n];
  for (int i = 0; i < (n); i++) cin >> a[i] >> b[i] >> c[i];
  vector<vector<int>> g(n);
  for (int i = 0; i < (n - 1); i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int valid = 0;
  for (int i = 0; i < (n); i++) valid += b[i] - c[i];
  if (valid != 0) {
    cout << -1 << endl;
    return 0;
  }
  ll cnt[n][2], dp[n];
  for (int i = 0; i < (n); i++) cnt[i][0] = 0, cnt[i][1] = 0, dp[i] = LINF;
  multiset<ll> st;
  ll ans = 0;
  function<void(int, int)> dfs = [&](int pre, int now) {
    st.insert(a[now]);
    for (auto to : g[now])
      if (to != pre) {
        dfs(now, to);
        cnt[now][0] += cnt[to][0];
        cnt[now][1] += cnt[to][1];
      }
    if (b[now] == 0 and c[now] == 1) cnt[now][0]++;
    if (b[now] == 1 and c[now] == 0) cnt[now][1]++;
    st.erase(st.find(a[now]));
    auto ite = st.lower_bound(a[now]);
    if (ite == st.begin()) {
      ll tmp = min(cnt[now][0], cnt[now][1]);
      ans += 2 * tmp * a[now];
      cnt[now][0] -= tmp;
      cnt[now][1] -= tmp;
    }
  };
  dfs(-1, 0);
  cout << ans << endl;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.

A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.

You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.

Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so.

Input

The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively.

Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v).

You may assume that there is at most one railway connecting any two towns.

Output

Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output  - 1.

Examples

Input

4 2
1 3
3 4

Output

2

Input

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

Output

-1

Input

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

Output

3

Note

In the first sample, the train can take the route <image> and the bus can take the route <image>. Note that they can arrive at town 4 at the same time.

In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4e2 + 1;
const int INF = 1e9 + 7;
bool gr[MAXN][MAXN];
bool was[MAXN];
int ans[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) was[i] = false, ans[i] = INF;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    gr[a][b] = gr[b][a] = true;
  }
  if (gr[0][n - 1])
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (i != j) gr[i][j] = !gr[i][j];
  deque<int> v;
  v.push_back(0);
  ans[0] = 0;
  while (v.size() > 0) {
    int x = v[0];
    v.pop_front();
    for (int i = 0; i < n; i++) {
      if (gr[x][i] && ans[i] > ans[x] + 1) {
        ans[i] = ans[x] + 1;
        v.push_back(i);
      }
    }
  }
  if (ans[n - 1] == INF)
    cout << -1 << endl;
  else
    cout << ans[n - 1] << endl;
  return 0;
}

```


### Prompt

Create a solution in Cpp for the following problem:

You are given a colored permutation p_1, p_2, ..., p_n. The i-th element of the permutation has color c_i.

Let's define an infinite path as infinite sequence i, p[i], p[p[i]], p[p[p[i]]] ... where all elements have same color (c[i] = c[p[i]] = c[p[p[i]]] = ...).

We can also define a multiplication of permutations a and b as permutation c = a × b where c[i] = b[a[i]]. Moreover, we can define a power k of permutation p as p^k=\underbrace{p × p × ... × p}_{k  times}.

Find the minimum k > 0 such that p^k has at least one infinite path (i.e. there is a position i in p^k such that the sequence starting from i is an infinite path).

It can be proved that the answer always exists.

Input

The first line contains single integer T (1 ≤ T ≤ 10^4) — the number of test cases.

Next 3T lines contain test cases — one per three lines. The first line contains single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the size of the permutation.

The second line contains n integers p_1, p_2, ..., p_n (1 ≤ p_i ≤ n, p_i ≠ p_j for i ≠ j) — the permutation p.

The third line contains n integers c_1, c_2, ..., c_n (1 ≤ c_i ≤ n) — the colors of elements of the permutation.

It is guaranteed that the total sum of n doesn't exceed 2 ⋅ 10^5.

Output

Print T integers — one per test case. For each test case print minimum k > 0 such that p^k has at least one infinite path.

Example

Input

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

Output

1
5
2

Note

In the first test case, p^1 = p = [1, 3, 4, 2] and the sequence starting from 1: 1, p[1] = 1, ... is an infinite path.

In the second test case, p^5 = [1, 2, 3, 4, 5] and it obviously contains several infinite paths.

In the third test case, p^2 = [3, 6, 1, 8, 7, 2, 5, 4] and the sequence starting from 4: 4, p^2[4]=8, p^2[8]=4, ... is an infinite path since c_4 = c_8 = 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 100 * 1000 + 20, inf = 1e9;
int n, a[N], ans = inf, c[N];
bool mark[N];
vector<int> vec;
void dfs(int v) {
  vec.push_back(v);
  mark[v] = true;
  if (!mark[a[v]]) dfs(a[v]);
}
bool ok(int k, int j) {
  for (int i = j + k; i < vec.size(); i += j)
    if (c[vec[i]] != c[vec[i - j]]) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      a[i]--;
    }
    for (int i = 0; i < n; i++) cin >> c[i];
    for (int i = 0; i < n; i++)
      if (!mark[i]) {
        dfs(i);
        for (int j = 1; j <= vec.size(); j++)
          if (vec.size() % j == 0)
            for (int k = 0; k < j; k++)
              if (ok(k, j)) ans = min(ans, j);
        vec.clear();
      }
    cout << ans << "\n";
    fill(mark, mark + n, false);
    ans = inf;
  }
  return 0;
}

```


### Prompt

Please formulate a Cpp solution to the following problem:

Vasya has n burles. One bottle of Ber-Cola costs a burles and one Bars bar costs b burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.

Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly n burles.

In other words, you should find two non-negative integers x and y such that Vasya can buy x bottles of Ber-Cola and y Bars bars and x·a + y·b = n or tell that it's impossible.

Input

First line contains single integer n (1 ≤ n ≤ 10 000 000) — amount of money, that Vasya has.

Second line contains single integer a (1 ≤ a ≤ 10 000 000) — cost of one bottle of Ber-Cola.

Third line contains single integer b (1 ≤ b ≤ 10 000 000) — cost of one Bars bar.

Output

If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly n burles print «NO» (without quotes).

Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers x and y — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly n burles, i.e. x·a + y·b = n. If there are multiple answers print any of them.

Any of numbers x and y can be equal 0.

Examples

Input

7
2
3

Output

YES
2 1

Input

100
25
10

Output

YES
0 10

Input

15
4
8

Output

NO

Input

9960594
2551
2557

Output

YES
1951 1949

Note

In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles.

In second example Vasya can spend exactly n burles multiple ways:

  * buy two bottles of Ber-Cola and five Bars bars;
  * buy four bottles of Ber-Cola and don't buy Bars bars;
  * don't buy Ber-Cola and buy 10 Bars bars.

In third example it's impossible to but Ber-Cola and Bars bars in order to spend exactly n burles.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int MAX = 100000;
const int MOD = 1000000007;
inline bool isEq(double a, double b) { return abs(a - b) < EPS; }
inline double toRad(double deg) { return deg * PI / 180; }
inline double toDeg(double rad) { return rad * 180 / PI; }
int egcd(int a, int b, long long& x, long long& y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1;
  int d = egcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, a, b;
  cin >> n >> a >> b;
  int x, y;
  for (x = 0; a * x <= n; x++) {
    if ((n - a * x) % b == 0) {
      y = (n - a * x) / b;
      cout << "YES\n";
      cout << x << " " << y << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

In some other world, today is the day before Christmas Eve.

Mr. Takaha is buying N items at a department store. The regular price of the i-th item (1 \leq i \leq N) is p_i yen (the currency of Japan).

He has a discount coupon, and can buy one item with the highest price for half the regular price. The remaining N-1 items cost their regular prices. What is the total amount he will pay?

Constraints

* 2 \leq N \leq 10
* 100 \leq p_i \leq 10000
* p_i is an even number.

Input

Input is given from Standard Input in the following format:

N
p_1
p_2
:
p_N

Output

Print the total amount Mr. Takaha will pay.

Examples

Input

3
4980
7980
6980

Output

15950

Input

4
4320
4320
4320
4320

Output

15120

### Response

```cpp
#include<iostream>
#include<stdlib.h>
using namespace std;
int main(){
	int n;
	cin >>n;
	int l,max=0,sum=0;
	for(int i=0;i<n;i++){
		cin>>l;
		if(max<l)
			max=l;
		sum+=l;
	}
	cout<<sum-max/2;
	return 0;
}
```


### Prompt

Please create a solution in CPP to the following problem:

You are given a connected undirected graph consisting of n vertices and m edges. There are no self-loops or multiple edges in the given graph.

You have to direct its edges in such a way that the obtained directed graph does not contain any paths of length two or greater (where the length of path is denoted as the number of traversed edges).

Input

The first line contains two integer numbers n and m (2 ≤ n ≤ 2 ⋅ 10^5, n - 1 ≤ m ≤ 2 ⋅ 10^5) — the number of vertices and edges, respectively.

The following m lines contain edges: edge i is given as a pair of vertices u_i, v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i). There are no multiple edges in the given graph, i. e. for each pair (u_i, v_i) there are no other pairs (u_i, v_i) and (v_i, u_i) in the list of edges. It is also guaranteed that the given graph is connected (there is a path between any pair of vertex in the given graph).

Output

If it is impossible to direct edges of the given graph in such a way that the obtained directed graph does not contain paths of length at least two, print "NO" in the first line.

Otherwise print "YES" in the first line, and then print any suitable orientation of edges: a binary string (the string consisting only of '0' and '1') of length m. The i-th element of this string should be '0' if the i-th edge of the graph should be directed from u_i to v_i, and '1' otherwise. Edges are numbered in the order they are given in the input.

Example

Input

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

Output

YES
10100

Note

The picture corresponding to the first example: <image>

And one of possible answers: <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, m, x[200010], y[200010], col[200010];
long long ver[400010], Next[400010], head[200010], tot;
inline long long read() {
  long long x = 0, tmp = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') tmp = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - 48;
    ch = getchar();
  }
  return tmp * x;
}
inline void addEdge(long long x, long long y) {
  ver[++tot] = y;
  Next[tot] = head[x];
  head[x] = tot;
}
void dfs(long long x, long long colour) {
  col[x] = colour;
  for (long long i = head[x]; i; i = Next[i]) {
    long long y = ver[i];
    if (col[x] == col[y]) {
      printf("NO\n");
      exit(0);
    }
    if (col[y]) continue;
    dfs(y, 3 - colour);
  }
}
signed main() {
  n = read();
  m = read();
  for (long long i = 1; i <= m; i++) {
    x[i] = read();
    y[i] = read();
    addEdge(x[i], y[i]);
    addEdge(y[i], x[i]);
  }
  dfs(1, 1);
  printf("YES\n");
  for (long long i = 1; i <= m; i++) printf("%lld", 2 - col[x[i]]);
  putchar('\n');
}

```


### Prompt

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

In the last war of PMP, he defeated all his opponents and advanced to the final round. But after the end of semi-final round evil attacked him from behind and killed him! God bless him.

Before his death, PMP signed a contract with the bus rapid transit (BRT) that improves public transportations by optimizing time of travel estimation. You should help PMP finish his last contract.

Each BRT line is straight line that passes n intersecting on its ways. At each intersection there is traffic light that periodically cycles between green and red. It starts illuminating green at time zero. During the green phase which lasts for g seconds, traffic is allowed to proceed. After the green phase the light changes to red and remains in this color for r seconds. During the red phase traffic is prohibited from proceeding. If a vehicle reaches the intersection exactly at a time when the light changes to red, it should stop, but the vehicle is clear to proceed if the light has just changed to green.

<image>

All traffic lights have the same timing and are synchronized. In other words the period of red (and green) phase is the same for all of traffic lights and they all start illuminating green at time zero.

The BRT Company has calculated the time that a bus requires to pass each road segment. A road segment is the distance between two consecutive traffic lights or between a traffic light and source (or destination) station. More precisely BRT specialists provide n + 1 positive integers li, the time in seconds that a bus needs to traverse i-th road segment in the path from source to destination. The l1 value denotes the time that a bus needs to pass the distance between source and the first intersection. The ln + 1 value denotes the time between the last intersection and destination.

In one day q buses leave the source station. The i-th bus starts from source at time ti (in seconds). Decision makers of BRT Company want to know what time a bus gets to destination?

The bus is considered as point. A bus will always move if it can. The buses do not interfere with each other.

Input

The first line of input contains three space-separated positive integers n, g, r (1 ≤ n ≤ 105, 2 ≤ g + r ≤ 109) — the number of intersections, duration of green phase and duration of red phase. Next line contains n + 1 integers li (1 ≤ li ≤ 109) — the time to pass the i-th road segment in the path from source to destination.

Next line contains a single integer q (1 ≤ q ≤ 105) — the number of buses in a day. The i-th of next q lines contains a single integer ti (1 ≤ ti ≤ 109) — the time when i-th bus leaves the source station.

Output

In the i-th line of output you should print a single integer — the time that i-th bus gets to destination.

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

Examples

Input

1 3 2
5 2
5
1
2
3
4
5

Output

8
9
12
12
12

Input

5 3 7
10 1 1 8 900000005 1000000000
3
1
10
1000000000

Output

1900000040
1900000040
2900000030

Note

In the first sample, buses #1, #2 and #5 will reach the destination without waiting behind the red light. But buses #3 and #4 should wait.

In the second sample, first bus should wait at third, fourth and fifth intersections. Second and third buses should wait only at the fifth intersection.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int tot, sum, p[N], w[N];
long long s[N], t[N];
struct data {
  int m, d;
} a[N];
struct data2 {
  int l, r, m, left, right, min;
} tree[N * 2];
bool compare(data a, data b) {
  if (a.m < b.m || (a.m == b.m && a.d < b.d))
    return (true);
  else
    return (false);
}
int min(int a, int b) { return (a < b ? a : b); }
void buildtree(int d) {
  tree[d].min = INT_MAX;
  if (tree[d].l + 1 == tree[d].r) return;
  tree[d].m = (tree[d].l + tree[d].r) / 2;
  tree[d].left = ++tot;
  tree[tot].l = tree[d].l;
  tree[tot].r = tree[d].m;
  buildtree(tot);
  tree[d].right = ++tot;
  tree[tot].l = tree[d].m;
  tree[tot].r = tree[d].r;
  buildtree(tot);
}
void modify(int d, int l, int w) {
  if (tree[d].min > w) tree[d].min = w;
  if (tree[d].l + 1 == tree[d].r) return;
  if (l < tree[d].m)
    modify(tree[d].left, l, w);
  else
    modify(tree[d].right, l, w);
}
int query(int d, int l, int r) {
  if (l >= r) return (INT_MAX);
  if (tree[d].l == l && tree[d].r == r) return (tree[d].min);
  if (r <= tree[d].m) return (query(tree[d].left, l, r));
  if (l >= tree[d].m) return (query(tree[d].right, l, r));
  return (min(query(tree[d].left, l, tree[d].m),
              query(tree[d].right, tree[d].m, r)));
}
int findnoless(int v) {
  if (v > w[sum]) return (sum + 1);
  if (v <= w[1]) return (1);
  int l = 1, r = sum, mid;
  while (l + 1 < r) {
    mid = (l + r) / 2;
    if (w[mid] >= v)
      r = mid;
    else
      l = mid;
  }
  return (r);
}
int findless(int v) {
  if (v <= w[1]) return (0);
  if (v > w[sum]) return (sum);
  int l = 1, r = sum, mid;
  while (l + 1 < r) {
    mid = (l + r) / 2;
    if (w[mid] < v)
      l = mid;
    else
      r = mid;
  }
  return (l);
}
int main() {
  int n, green, red, cycle, q, i, temp, l, r, time;
  long long ans;
  scanf("%d %d %d", &n, &green, &red);
  cycle = green + red;
  s[0] = 0;
  for (i = 1; i <= n + 1; i++) {
    scanf("%d", &temp);
    s[i] = s[i - 1] + temp;
    a[i].d = i;
    a[i].m = s[i] % cycle;
  }
  sort(a + 1, a + n + 2, compare);
  sum = 1;
  w[1] = 0;
  for (i = 1; i <= n + 1; i++) {
    if (a[i].m != w[sum]) {
      sum++;
      w[sum] = a[i].m;
    }
    p[a[i].d] = sum;
  }
  sum++;
  w[sum] = cycle - 1;
  tot = 1;
  tree[1].l = 1;
  tree[1].r = sum + 1;
  buildtree(tot);
  for (i = n; i >= 0; i--) {
    r = s[i] % cycle;
    l = (green + r) % cycle;
    if (l <= r) {
      l = findnoless(l);
      r = findless(r);
      temp = query(1, l, r + 1);
    } else {
      l = findnoless(l);
      r = findless(r);
      temp = min(query(1, 1, r + 1), query(1, l, sum + 1));
    }
    if (temp == INT_MAX)
      t[i] = s[n + 1] - s[i];
    else
      t[i] = s[temp] - s[i] + t[temp] + (cycle - (s[temp] - s[i]) % cycle);
    if (i != 0) modify(1, p[i], i);
  }
  scanf("%d", &q);
  for (i = 1; i <= q; i++) {
    scanf("%d", &time);
    l = green - (time % cycle);
    if (l < 0) l += cycle;
    r = cycle - (time % cycle);
    if (l <= r) {
      l = findnoless(l);
      r = findless(r);
      temp = query(1, l, r + 1);
    } else {
      l = findnoless(l);
      r = findless(r);
      temp = min(query(1, 1, r + 1), query(1, l, sum + 1));
    }
    if (temp == INT_MAX)
      ans = s[n + 1] + time;
    else
      ans = s[temp] + time + t[temp] + cycle - (s[temp] + time) % cycle;
    printf("%I64d\n", ans);
  }
  return (0);
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Lenny is playing a game on a 3 × 3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.

Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.

Input

The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The j-th number in the i-th row is the number of times the j-th light of the i-th row of the grid is pressed.

Output

Print three lines, each containing three characters. The j-th character of the i-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".

Examples

Input

1 0 0
0 0 0
0 0 1

Output

001
010
100

Input

1 0 1
8 8 8
2 0 3

Output

010
011
100

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int inc1 = 0, inc2 = 0;
  int even = 0;
  int odd = 0;
  int a;
  int arr[3][3] = {};
  int arrout[3][3] = {};
  for (int k = 0; k < 3; k++) {
    for (int t = 0; t < 3; t++) {
      cin >> a;
      arr[k][t] = a;
    }
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (arr[i][j] % 2 == 0) {
        even++;
      } else {
        odd++;
      }
      if (i < 1) {
        inc1 = 2;
        inc2 = 0;
      } else if (i == 1) {
        inc1 = 0;
        inc2 = 0;
      } else {
        inc1 = 0;
        inc2 = 1;
      }
      for (int f = -1 + inc1; f < 2; f = f + 2 + inc2) {
        if (arr[i + f][j] % 2 == 0) {
          even++;
        } else {
          odd++;
        }
      }
      inc1 = 0;
      inc2 = 0;
      if (j < 1) {
        inc1 = 2;
        inc2 = 0;
      } else if (j == 1) {
        inc1 = 0;
        inc2 = 0;
      } else {
        inc1 = 0;
        inc2 = 1;
      }
      for (int d = -1 + inc1; d < 2; d += 2 + inc2) {
        if (arr[i][j + d] % 2 == 0) {
          even++;
        } else {
          odd++;
        }
      }
      inc1 = 0;
      inc2 = 0;
      if (even % 2 == 0) {
        even = 0;
      } else {
        even = 1;
      }
      if (odd % 2 == 0) {
        odd = 0;
      } else {
        odd = 1;
      }
      if (even > odd) {
        arrout[i][j] = 1;
      } else if (even < odd) {
        arrout[i][j] = 0;
      } else if (even == 0 && odd == 0) {
        arrout[i][j] = 1;
      } else {
        arrout[i][j] = 0;
      }
      even = 0;
      odd = 0;
    }
    cout << arrout[i][0] << arrout[i][1] << arrout[i][2] << endl;
  }
  return 0;
}

```


### Prompt

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

Assume that sk(n) equals the sum of digits of number n in the k-based notation. For example, s2(5) = s2(1012) = 1 + 0 + 1 = 2, s3(14) = s3(1123) = 1 + 1 + 2 = 4.

The sequence of integers a0, ..., an - 1 is defined as <image>. Your task is to calculate the number of distinct subsequences of sequence a0, ..., an - 1. Calculate the answer modulo 109 + 7.

Sequence a1, ..., ak is called to be a subsequence of sequence b1, ..., bl, if there is a sequence of indices 1 ≤ i1 < ... < ik ≤ l, such that a1 = bi1, ..., ak = bik. In particular, an empty sequence (i.e. the sequence consisting of zero elements) is a subsequence of any sequence.

Input

The first line contains two space-separated numbers n and k (1 ≤ n ≤ 1018, 2 ≤ k ≤ 30).

Output

In a single line print the answer to the problem modulo 109 + 7.

Examples

Input

4 2

Output

11

Input

7 7

Output

128

Note

In the first sample the sequence ai looks as follows: (0, 1, 1, 0). All the possible subsequences are:

(), (0), (0, 0), (0, 1), (0, 1, 0), (0, 1, 1), (0, 1, 1, 0), (1), (1, 0), (1, 1), (1, 1, 0).

In the second sample the sequence ai looks as follows: (0, 1, 2, 3, 4, 5, 6). The subsequences of this sequence are exactly all increasing sequences formed from numbers from 0 to 6. It is easy to see that there are 27 = 128 such sequences.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int K = 30;
const int MOD = 1e9 + 7;
long long n, power[K + 1];
int k;
__inline void add(int &a, int b) {
  if ((a += b) >= MOD) {
    a -= MOD;
  }
}
struct Matrix {
  int trans[K][K];
  int go[K];
  Matrix() {
    memset(trans, 0, sizeof(trans));
    memset(go, 0, sizeof(go));
  }
  int all() {
    int result = 0;
    for (int i = 0; i < k; i++) {
      add(result, go[i]);
      for (int j = 0; j < k; j++) {
        add(result, trans[i][j]);
      }
    }
    return result;
  }
};
map<long long, Matrix> mp;
Matrix search(long long n) {
  if (mp.count(n)) {
    return mp[n];
  }
  Matrix ret;
  if (k >= n) {
    for (int i = 0; i < n; i++) {
      ret.go[i] = 0;
      ret.trans[i][i] = 1;
      for (int j = i + 1; j < n; j++) {
        ret.trans[i][j] = power[j - i - 1];
      }
    }
    return ret;
  }
  long long unit = 1;
  int length = 1;
  while (unit <= n / k && unit * k < n) {
    unit *= k;
    length++;
  }
  Matrix base = search(unit);
  ret = base;
  long long remaind = n % unit;
  Matrix extra = search(remaind);
  static int reach[K][K], _reach[K][K];
  for (int i = 0; i < k; i++) {
    ret.go[i] = base.go[i];
    for (int j = 0; j < k; j++) {
      reach[i][j] = base.trans[i][j];
    }
  }
  for (int i = 1; i <= n / unit; i++) {
    if (i == n / unit && remaind == 0) {
      break;
    }
    Matrix &nxt = (i < n / unit) ? base : extra;
    int lead = i;
    for (int j = 0; j < k; j++) {
      for (int l = 0; l < k; l++) {
        _reach[j][l] = reach[j][l];
        add(ret.go[j], reach[j][l]);
        reach[j][l] = 0;
      }
    }
    int t = ((k - 1) * (length - 2) + i - 1) % k;
    for (int start = 0; start < k; start++) {
      int sum = 0;
      for (int prev = k - 1; prev >= 0; prev--) {
        int pv = (prev + t) % k;
        add(sum, _reach[start][pv]);
        int succ = prev;
        int sv = (succ + t) % k, temp = ((sv - i) % k + k) % k;
        add(ret.go[start], 1LL * sum * nxt.go[temp] % MOD);
        for (int end = 0; end < k; end++) {
          add(reach[start][end],
              1LL * sum * nxt.trans[temp][((end - i) % k + k) % k] % MOD);
        }
      }
    }
    for (int i = 0; i < k; i++) {
      for (int j = 0; j < k; j++) {
        ret.trans[i][j] = reach[i][j];
      }
    }
  }
  return mp[n] = ret;
}
int main() {
  power[0] = 1;
  for (int i = 1; i <= K; i++) {
    power[i] = power[i - 1] * 2;
  }
  cin >> n >> k;
  Matrix answer = search(n);
  cout << (answer.all() + 1) % MOD << endl;
  return 0;
}

```


### Prompt

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

Snuke is having another barbeque party.

This time, he will make one serving of Skewer Meal.

He has a stock of N Skewer Meal Packs. The i-th Skewer Meal Pack contains one skewer, A_i pieces of beef and B_i pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.

To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.

(See the image in the Sample section for better understanding.)

In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo 10^9+7.

Constraints

* 2≦N≦200,000
* 1≦A_i≦2000, 1≦B_i≦2000

Input

The input is given from Standard Input in the following format:

N
A_1 B_1
A_2 B_2
:
A_N B_N

Output

Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo 10^9+7.

Example

Input

3
1 1
1 1
2 1

Output

26

### Response

```cpp
#include<complex>
#include<cstdio>
using namespace std;
const int mod=1e9+7;
const int N=2e5+7,M=2e3+7;
int n,ans,maxn;
int a[N],b[N];
long long f[M<<1][M<<1],fac[M<<2],fdiv[M<<2],num[M<<2];
int qread()
{
	int x=0;
	char ch=getchar();
	while(ch<'0' || ch>'9')ch=getchar();
	while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x;
}
int C(int n,int m)
{
	return fac[n]*fdiv[m]%mod*fdiv[n-m]%mod;
}
void Init()
{
	fac[0]=fdiv[0]=fdiv[1]=num[1]=1;
	for(int i=1;i<=maxn;i++)
		fac[i]=fac[i-1]*i%mod;
	for(int i=2;i<=maxn;i++)
	{
		num[i]=(mod-mod/i)*num[mod%i]%mod;
		fdiv[i]=fdiv[i-1]*num[i]%mod;
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		a[i]=qread();b[i]=qread();
		maxn=max(maxn,a[i]+b[i]<<1);
		f[M-a[i]][M-b[i]]++;
	}
	Init();
	for(int i=1;i<=n;i++)
		ans=(ans-C(a[i]+b[i]<<1,a[i]<<1)+mod)%mod;
	for(int i=1;i<M*2;i++)
		for(int j=1;j<M*2;j++)
			f[i][j]=(f[i][j]+f[i-1][j]+f[i][j-1])%mod;
	for(int i=1;i<=n;i++)
		ans=(ans+f[a[i]+M][b[i]+M])%mod;
	printf("%d\n",ans*fdiv[2]%mod);
	return 0;
}
```


### Prompt

Generate a cpp solution to the following problem:

You are given an undirected graph with N vertices and M edges. Here, N-1≤M≤N holds and the graph is connected. There are no self-loops or multiple edges in this graph.

The vertices are numbered 1 through N, and the edges are numbered 1 through M. Edge i connects vertices a_i and b_i.

The color of each vertex can be either white or black. Initially, all the vertices are white. Snuke is trying to turn all the vertices black by performing the following operation some number of times:

* Select a pair of adjacent vertices with the same color, and invert the colors of those vertices. That is, if the vertices are both white, then turn them black, and vice versa.

Determine if it is possible to turn all the vertices black. If the answer is positive, find the minimum number of times the operation needs to be performed in order to achieve the objective.

Constraints

* 2≤N≤10^5
* N-1≤M≤N
* 1≤a_i,b_i≤N
* There are no self-loops or multiple edges in the given graph.
* The given graph is connected.

Input

The input is given from Standard Input in the following format:

N M
a_1 b_1
a_2 b_2
:
a_M b_M

Output

If it is possible to turn all the vertices black, print the minimum number of times the operation needs to be performed in order to achieve the objective. Otherwise, print `-1` instead.

Examples

Input

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

Output

5

Input

3 2
1 2
2 3

Output

-1

Input

4 4
1 2
2 3
3 4
4 1

Output

2

Input

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

Output

7

### Response

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

using namespace std;

typedef long long ll;

int n, m;
int x, y;
vector<int> v[maxn];

int dep[maxn], fa[maxn];
ll ans, siz[maxn];
vector<ll> a;

void dfs(int i){
	dep[i] = dep[fa[i]] + 1, siz[i] = dep[i] & 1 ? 1 : -1;
	for(int j = 0;j < v[i].size();j++){
		int to = v[i][j];
		if(to == fa[i]) continue;
		if(dep[to]) x = to, y = i;
		else fa[to] = i, dfs(to), siz[i] += siz[to];
	}
	ans += abs(siz[i]);
}

int main(){
	scanf("%d%d", &n, &m);
	while(m--){
		scanf("%d%d", &x, &y);
		v[x].push_back(y), v[y].push_back(x);
	}
	x = y = 0;
	dfs(1);
	if(!x) return printf("%lld", siz[1] ? -1 : ans), 0;
	if((dep[x] - dep[y]) & 1){
		if(siz[1]) return printf("-1"), 0;
		for(int i = x;i != y;i = fa[i]){
			ans -= abs(siz[i]), a.push_back(siz[i]);
		}
		a.push_back(0);
		sort(a.begin(), a.end());
		for(int i = 0;i < a.size();i++) ans += abs(a[i] - a[a.size() / 2]);
		printf("%lld", ans);
	}else{
		if(siz[1] & 1) return printf("-1"), 0;
		ll sum = siz[1] >> 1;
		for(int i = x;i;i = fa[i]) ans -= abs(siz[i]), ans += abs(siz[i] -= sum);
		for(int i = y;i;i = fa[i]) ans -= abs(siz[i]), ans += abs(siz[i] -= sum);
		printf("%lld", ans + abs(sum));
	}

}
```


### Prompt

Generate a CPP solution to the following problem:

We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left.
According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j.
Determine if he is correct.

Constraints

* c_{i, j} \ (1 \leq i \leq 3, 1 \leq j \leq 3) is an integer between 0 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

c_{1,1} c_{1,2} c_{1,3}
c_{2,1} c_{2,2} c_{2,3}
c_{3,1} c_{3,2} c_{3,3}

Output

If Takahashi's statement is correct, print `Yes`; otherwise, print `No`.

Examples

Input

1 0 1
2 1 2
1 0 1

Output

Yes

Input

2 2 2
2 1 2
2 2 2

Output

No

Input

0 8 8
0 8 8
0 8 8

Output

Yes

Input

1 8 6
2 9 7
0 7 7

Output

No

### Response

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

int main() {
  int a,b,c,d,e,f,g,h,i;
  cin>>a>>b>>c>>d>>e>>f>>g>>h>>i;
  if(a+e+i==b+f+g&&b+f+g==c+d+h){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
}
```