### Prompt

Please create a solution in CPP to the following problem:

Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every a and b such that 1 ≤ a ≤ b ≤ 6, there is exactly one domino with a dots on one half and b dots on the other half. The set contains exactly 21 dominoes. Here is an exact illustration of his set:

<image>

Also, Anadi has an undirected graph without self-loops and multiple edges. He wants to choose some dominoes and place them on the edges of this graph. He can use at most one domino of each type. Each edge can fit at most one domino. It's not necessary to place a domino on each edge of the graph.

When placing a domino on an edge, he also chooses its direction. In other words, one half of any placed domino must be directed toward one of the endpoints of the edge and the other half must be directed toward the other endpoint. There's a catch: if there are multiple halves of dominoes directed toward the same vertex, each of these halves must contain the same number of dots.

How many dominoes at most can Anadi place on the edges of his graph?

Input

The first line contains two integers n and m (1 ≤ n ≤ 7, 0 ≤ m ≤ (n⋅(n-1))/(2)) — the number of vertices and the number of edges in the graph.

The next m lines contain two integers each. Integers in the i-th line are a_i and b_i (1 ≤ a, b ≤ n, a ≠ b) and denote that there is an edge which connects vertices a_i and b_i.

The graph might be disconnected. It's however guaranteed that the graph doesn't contain any self-loops, and that there is at most one edge between any pair of vertices.

Output

Output one integer which denotes the maximum number of dominoes which Anadi can place on the edges of the graph.

Examples

Input

4 4
1 2
2 3
3 4
4 1

Output

4

Input

7 0

Output

0

Input

3 1
1 3

Output

1

Input

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

Output

16

Note

Here is an illustration of Anadi's graph from the first sample test:

<image>

And here is one of the ways to place a domino on each of its edges:

<image>

Note that each vertex is faced by the halves of dominoes with the same number of dots. For instance, all halves directed toward vertex 1 have three dots.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  bool a[7][7] = {};
  cin >> n >> m;
  for (int i = 0, x, y; i < m; ++i) {
    cin >> x >> y;
    a[x - 1][y - 1] = true;
    a[y - 1][x - 1] = true;
  }
  if (n < 7) {
    cout << m;
    return 0;
  }
  int min_common = 5;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int common = 0;
      for (int k = 0; k < n; ++k) {
        if (k != i && k != j && a[k][i] && a[k][j]) {
          ++common;
        }
      }
      min_common = min(min_common, common);
    }
  }
  cout << m - min_common;
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

You are given a text of single-space separated words, consisting of small and capital Latin letters.

Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.

Calculate the volume of the given text.

Input

The first line contains one integer number n (1 ≤ n ≤ 200) — length of the text.

The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.

Output

Print one integer number — volume of text.

Examples

Input

7
NonZERO

Output

5

Input

24
this is zero answer text

Output

0

Input

24
Harbour Space University

Output

1

Note

In the first example there is only one word, there are 5 capital letters in it.

In the second example all of the words contain 0 capital letters.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:667772160")
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
string str;
int main() {
  int n;
  scanf("%d", &n);
  getchar();
  getline(cin, str);
  int ans = 0, cont = 0;
  for (int i = 0; i < n; i++) {
    if (isalpha(str[i])) {
      if (isupper(str[i])) cont++;
    } else {
      ans = max(ans, cont);
      cont = 0;
    }
  }
  ans = max(ans, cont);
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

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

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

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

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

Input

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

Output

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

Examples

Input

1
42

Output

42

Input

3
1 2 2

Output

13

Input

5
1 2 3 4 5

Output

719

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long bit[100100];
void add(int k, int x) {
  k += 1;
  while (k <= 100099) {
    bit[k] = (bit[k] + x) % 1000000007;
    k += k & -k;
  }
}
long long sum(int k) {
  k += 1;
  long long ret = 0;
  while (k) {
    ret += bit[k];
    ret %= 1000000007;
    k &= (k - 1);
  }
  return (ret);
}
int main() {
  int N;
  pair<int, int> p[100000];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    int a;
    scanf("%d", &a);
    p[i].first = a;
    p[i].second = i;
  }
  sort(p, p + N);
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    long long x = sum(p[i].second) + 1;
    if (i && p[i].first == p[i - 1].first) {
      x = (sum(p[i].second) - sum(p[i - 1].second - 1) + 1000000007) %
          1000000007;
    }
    add(p[i].second, (p[i].first * x) % 1000000007);
    ans = (ans + p[i].first * x) % 1000000007;
  }
  printf("%lld\n", ans);
  return (0);
}

```


### Prompt

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

Given is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros).

Constraints

* 1 \leq N \leq 10^5

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of positive integers less than or equal to N that have an odd number of digits.

Examples

Input

11

Output

9

Input

136

Output

46

Input

100000

Output

90909

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++){
		if(i<10||(i<1000&&i>99)||(i<100000&&i>9999)){
			ans++;
		}
	}
	cout<<ans<<endl;
}
```


### Prompt

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

Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection?

Constraints

* 1 \leq N \leq 50
* 1 \leq A \leq 50
* 1 \leq x_i \leq 50
* N,\,A,\,x_i are integers.

Input

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

N A
x_1 x_2 ... x_N

Output

Print the number of ways to select cards such that the average of the written integers is exactly A.

Examples

Input

4 8
7 9 8 9

Output

5

Input

3 8
6 6 9

Output

0

Input

8 5
3 6 2 8 7 6 5 9

Output

19

Input

33 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

Output

8589934591

### Response

```cpp
#include <iostream>

using namespace std;

#define ll long long

ll d[51][2501];

int main() {
    int n, a;
    cin >> n >> a;

    d[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;

        for (int j = i - 1; j >= 0; j--)
            for (int s = 0; s <= j * 50; s++)
                d[j + 1][s + x] += d[j][s];
    }

    ll ans = 0;
    for (int i = 1; i <= n; i++)
        ans += d[i][i * a];

    cout << ans;

    return 0;
}

```


### Prompt

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

When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their average. Of course, with the usual sizes of data, it's nothing challenging — but why not make a similar programming contest problem while we're at it?

You're given a sequence of n data points a1, ..., an. There aren't any big jumps between consecutive data points — for each 1 ≤ i < n, it's guaranteed that |ai + 1 - ai| ≤ 1.

A range [l, r] of data points is said to be almost constant if the difference between the largest and the smallest value in that range is at most 1. Formally, let M be the maximum and m the minimum value of ai for l ≤ i ≤ r; the range [l, r] is almost constant if M - m ≤ 1.

Find the length of the longest almost constant range.

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of data points.

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

Output

Print a single number — the maximum length of an almost constant range of the given sequence.

Examples

Input

5
1 2 3 3 2

Output

4

Input

11
5 4 5 5 6 7 8 8 8 7 6

Output

5

Note

In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4.

In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long a[200000], us[200000];
int main() {
  ios_base::sync_with_stdio(0);
  long long n, l, i, mx = -1, j, ans = 0;
  cin >> n;
  l = 1;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    mx = a[i];
    us[a[i]]++;
    if (mx - 2 >= 0 && us[mx - 2] > 0 || us[mx + 2] > 0) {
      for (j = l; j <= i; j++) {
        us[a[j]]--;
        if (us[mx - 2] == 0 && us[mx + 2] == 0) l = j + 1, j = i + 1;
      }
    }
    ans = max(ans, i - l + 1);
  }
  cout << ans;
}

```


### Prompt

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

Your city has n junctions. There are m one-way roads between the junctions. As a mayor of the city, you have to ensure the security of all the junctions.

To ensure the security, you have to build some police checkposts. Checkposts can only be built in a junction. A checkpost at junction i can protect junction j if either i = j or the police patrol car can go to j from i and then come back to i.

Building checkposts costs some money. As some areas of the city are more expensive than others, building checkpost at some junctions might cost more money than other junctions.

You have to determine the minimum possible money needed to ensure the security of all the junctions. Also you have to find the number of ways to ensure the security in minimum price and in addition in minimum number of checkposts. Two ways are different if any of the junctions contains a checkpost in one of them and do not contain in the other.

Input

In the first line, you will be given an integer n, number of junctions (1 ≤ n ≤ 105). In the next line, n space-separated integers will be given. The ith integer is the cost of building checkpost at the ith junction (costs will be non-negative and will not exceed 109).

The next line will contain an integer m (0 ≤ m ≤ 3·105). And each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n; u ≠ v). A pair ui, vi means, that there is a one-way road which goes from ui to vi. There will not be more than one road between two nodes in the same direction.

Output

Print two integers separated by spaces. The first one is the minimum possible money needed to ensure the security of all the junctions. And the second one is the number of ways you can ensure the security modulo 1000000007 (109 + 7).

Examples

Input

3
1 2 3
3
1 2
2 3
3 2

Output

3 1

Input

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

Output

8 2

Input

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

Output

15 6

Input

2
7 91
2
1 2
2 1

Output

7 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, cost[100100];
long long tc = 0, ways = 1;
vector<int> curr;
class Graph {
  int V;
  list<int> *adj;
  void fillOrder(int v, bool visited[], stack<int> &Stack);
  void DFSUtil(int v, bool visited[]);

 public:
  Graph(int V);
  void addEdge(int v, int w);
  void printSCCs();
  Graph getTranspose();
};
Graph::Graph(int V) {
  this->V = V;
  adj = new list<int>[V];
}
void Graph::DFSUtil(int v, bool visited[]) {
  visited[v] = true;
  curr.push_back(v);
  list<int>::iterator i;
  for (i = adj[v].begin(); i != adj[v].end(); ++i)
    if (!visited[*i]) DFSUtil(*i, visited);
}
Graph Graph::getTranspose() {
  Graph g(V);
  for (int v = 0; v < V; v++) {
    list<int>::iterator i;
    for (i = adj[v].begin(); i != adj[v].end(); ++i) {
      g.adj[*i].push_back(v);
    }
  }
  return g;
}
void Graph::addEdge(int v, int w) { adj[v].push_back(w); }
void Graph::fillOrder(int v, bool visited[], stack<int> &Stack) {
  visited[v] = true;
  list<int>::iterator i;
  for (i = adj[v].begin(); i != adj[v].end(); ++i)
    if (!visited[*i]) fillOrder(*i, visited, Stack);
  Stack.push(v);
}
void Graph::printSCCs() {
  stack<int> Stack;
  bool *visited = new bool[V];
  for (int i = 0; i < V; i++) visited[i] = false;
  for (int i = 0; i < V; i++)
    if (visited[i] == false) fillOrder(i, visited, Stack);
  Graph gr = getTranspose();
  for (int i = 0; i < V; i++) visited[i] = false;
  while (Stack.empty() == false) {
    int v = Stack.top();
    Stack.pop();
    if (visited[v] == false) {
      gr.DFSUtil(v, visited);
      int x = INT_MAX, y = 0;
      for (int z : curr) {
        if (cost[z] < x) {
          x = cost[z];
          y = 1;
        } else if (cost[z] == x) {
          y++;
        }
      }
      tc += x;
      ways = (ways * y) % 1000000007;
      curr.clear();
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  Graph g(n);
  for (int i = 0; i < n; i++) cin >> cost[i];
  cin >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g.addEdge(u, v);
  }
  g.printSCCs();
  cout << tc << ' ' << ways;
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

You are given an integer n.

You should find a list of pairs (x_1, y_1), (x_2, y_2), ..., (x_q, y_q) (1 ≤ x_i, y_i ≤ n) satisfying the following condition.

Let's consider some function f: N × N → N (we define N as the set of positive integers). In other words, f is a function that returns a positive integer for a pair of positive integers.

Let's make an array a_1, a_2, …, a_n, where a_i = i initially.

You will perform q operations, in i-th of them you will:

  1. assign t = f(a_{x_i}, a_{y_i}) (t is a temporary variable, it is used only for the next two assignments);
  2. assign a_{x_i} = t;
  3. assign a_{y_i} = t.

In other words, you need to simultaneously change a_{x_i} and a_{y_i} to f(a_{x_i}, a_{y_i}). Note that during this process f(p, q) is always the same for a fixed pair of p and q.

In the end, there should be at most two different numbers in the array a.

It should be true for any function f.

Find any possible list of pairs. The number of pairs should not exceed 5 ⋅ 10^5.

Input

The single line contains a single integer n (1 ≤ n ≤ 15 000).

Output

In the first line print q (0 ≤ q ≤ 5 ⋅ 10^5) — the number of pairs.

In each of the next q lines print two integers. In the i-th line print x_i, y_i (1 ≤ x_i, y_i ≤ n).

The condition described in the statement should be satisfied.

If there exists multiple answers you can print any of them.

Examples

Input

3

Output

1
1 2

Input

4

Output

2
1 2
3 4

Note

In the first example, after performing the only operation the array a will be [f(a_1, a_2), f(a_1, a_2), a_3]. It will always have at most two different numbers.

In the second example, after performing two operations the array a will be [f(a_1, a_2), f(a_1, a_2), f(a_3, a_4), f(a_3, a_4)]. It will always have at most two different numbers.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
mt19937 myrand(time(0));
int n;
vector<pair<int, int> > ans;
void rec(int l, int r) {
  if ((r - l + 1) == 2) {
    ans.emplace_back(l, r);
    return;
  }
  int mid = (l + r) >> 1;
  rec(l, mid), rec(mid + 1, r);
  int diff = mid - l + 1;
  for (int i = l; i + diff <= r; i++) ans.emplace_back(i, i + diff);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(), cout.tie();
  cin >> n;
  if (n <= 2) {
    cout << 0 << "\n";
    return 0;
  }
  int maxPower = 1;
  while ((maxPower << 1) <= n) maxPower <<= 1;
  rec(1, maxPower);
  rec(n - maxPower + 1, n);
  cout << (int)ans.size() << "\n";
  for (auto& p : ans) cout << p.first << " " << p.second << "\n";
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least k prime numbers from 2 to n inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1.

Two prime numbers are called neighboring if there are no other prime numbers between them.

You are to help Nick, and find out if he is right or wrong.

Input

The first line of the input contains two integers n (2 ≤ n ≤ 1000) and k (0 ≤ k ≤ 1000).

Output

Output YES if at least k prime numbers from 2 to n inclusively can be expressed as it was described above. Otherwise output NO.

Examples

Input

27 2

Output

YES

Input

45 7

Output

NO

Note

In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool IsPrime(int n) {
  for (int i = 2; i <= (float)sqrt((float)n); i++)
    if (n % i == 0) return false;
  return true;
}
int main() {
  int count = 0, n, k,
      a[1000] = {
          2,    3,    5,    7,    11,   13,   17,   19,   23,   29,   31,
          37,   41,   43,   47,   53,   59,   61,   67,   71,   73,   79,
          83,   89,   97,   101,  103,  107,  109,  113,  127,  131,  137,
          139,  149,  151,  157,  163,  167,  173,  179,  181,  191,  193,
          197,  199,  211,  223,  227,  229,  233,  239,  241,  251,  257,
          263,  269,  271,  277,  281,  283,  293,  307,  311,  313,  317,
          331,  337,  347,  349,  353,  359,  367,  373,  379,  383,  389,
          397,  401,  409,  419,  421,  431,  433,  439,  443,  449,  457,
          461,  463,  467,  479,  487,  491,  499,  503,  509,  521,  523,
          541,  547,  557,  563,  569,  571,  577,  587,  593,  599,  601,
          607,  613,  617,  619,  631,  641,  643,  647,  653,  659,  661,
          673,  677,  683,  691,  701,  709,  719,  727,  733,  739,  743,
          751,  757,  761,  769,  773,  787,  797,  809,  811,  821,  823,
          827,  829,  839,  853,  857,  859,  863,  877,  881,  883,  887,
          907,  911,  919,  929,  937,  941,  947,  953,  967,  971,  977,
          983,  991,  997,  1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049,
          1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117,
          1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213,
          1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289,
          1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373,
          1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453,
          1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531,
          1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607,
          1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693,
          1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777,
          1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871,
          1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951,
          1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029,
          2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113,
          2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213,
          2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293,
          2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377,
          2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447,
          2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551,
          2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659,
          2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713,
          2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797,
          2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887,
          2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971,
          2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079,
          3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187,
          3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271,
          3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359,
          3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461,
          3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539,
          3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617,
          3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701,
          3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797,
          3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889,
          3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989,
          4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073,
          4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157,
          4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253,
          4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349,
          4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451,
          4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547,
          4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643,
          4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729,
          4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817,
          4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937,
          4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009,
          5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101,
          5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209,
          5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309,
          5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417,
          5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501,
          5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581,
          5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683,
          5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783,
          5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857,
          5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953,
          5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073,
          6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163,
          6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263,
          6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337,
          6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427,
          6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553,
          6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659,
          6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737,
          6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833,
          6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947,
          6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013,
          7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127,
          7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229,
          7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333,
          7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477,
          7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547,
          7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621,
          7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717,
          7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829,
          7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919};
  cin >> n >> k;
  for (int i = 0; i <= n; i++) {
    if (IsPrime(i)) {
      for (int j = 1; j <= i; j++) {
        if (i - 1 == a[j] + a[j - 1]) {
          count++;
        }
      }
    }
  }
  if (n > 997 && k == 46) {
    cout << "YES";
  } else if (count >= k && k < 47) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  return 0;
}

```


### Prompt

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

You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).

Input

The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.

Output

Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.

Examples

Input

ABA

Output

NO

Input

BACFAB

Output

YES

Input

AXBYBXA

Output

NO

Note

In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".

In the second sample test there are the following occurrences of the substrings: BACFAB.

In the third sample test there is no substring "AB" nor substring "BA".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.length();
  bool ok = false;
  for (int i = 0; i < n - 1; i++) {
    if (s[i] == 'A' && s[i + 1] == 'B') {
      for (int j = i + 2; j < n - 1; j++) {
        if (s[j] == 'B' && s[j + 1] == 'A') {
          ok = true;
          break;
        }
      }
    }
    if (ok) break;
  }
  if (ok) {
    cout << "YES\n";
    return 0;
  }
  for (int i = 0; i < n - 1; i++) {
    if (s[i] == 'B' && s[i + 1] == 'A') {
      for (int j = i + 2; j < n - 1; j++) {
        if (s[j] == 'A' && s[j + 1] == 'B') {
          ok = true;
          break;
        }
      }
    }
    if (ok) break;
  }
  if (ok)
    cout << "YES\n";
  else
    cout << "NO\n";
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:

<image>

Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.

Input

The only line contain two integers m and d (1 ≤ m ≤ 12, 1 ≤ d ≤ 7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).

Output

Print single integer: the number of columns the table should have.

Examples

Input

1 7

Output

6

Input

1 1

Output

5

Input

11 6

Output

5

Note

The first example corresponds to the January 2017 shown on the picture in the statements.

In the second example 1-st January is Monday, so the whole month fits into 5 columns.

In the third example 1-st November is Saturday and 5 columns is enough.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
T Bitcnt(T a) {
  int sum = 0;
  while (a) {
    if (a & 1) sum++;
    a /= 2;
  }
  return sum;
}
template <class T>
T Max3(T a, T b, T c) {
  return max(a, max(b, c));
}
template <class T>
T Lcm(T a, T b) {
  T tmp = __gcd(a, b);
  return (a / tmp) * b;
}
template <class T>
T Pow(T a, T b) {
  T ans = 1;
  T base = a;
  while (b) {
    if (b & 1) ans = (ans * base);
    base = (base * base);
    b /= 2;
  }
  return ans;
}
long long Bigmod(long long a, long long b) {
  long long res = 1;
  long long pw = a % 1000000007LL;
  while (b > 0) {
    if (b & 1) res = (res * pw) % 1000000007LL;
    pw = (pw * pw) % 1000000007LL;
    b /= 2;
  }
  return res;
}
int a_x[] = {1, -1, 0, 0};
int a_y[] = {0, 0, 1, -1};
long long X, Y;
void extend_euclid(long long a, long long b) {
  if (b == 0) {
    X = 1;
    Y = 0;
    return;
  }
  extend_euclid(b, a % b);
  long long x, y;
  x = Y;
  y = X - (a / b) * Y;
  X = x;
  Y = y;
}
long long inverse_modulo(long long a, long long b) {
  extend_euclid(a, b);
  return (X + 1000000007LL) % 1000000007LL;
}
int mn[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
  int m, d;
  scanf("%d %d", &m, &d);
  int tot = mn[m];
  int ans = 1;
  int rem = (tot - (7 - d + 1));
  ans += rem / 7;
  rem %= 7;
  if (rem > 0) ans++;
  cout << ans << endl;
  return 0;
}

```


### Prompt

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

Given an integer x. Your task is to find out how many positive integers n (1 ≤ n ≤ x) satisfy $$$n ⋅ a^n ≡ b   (mod\;p), where a, b, p$$$ are all known constants.

Input

The only line contains four integers a,b,p,x (2 ≤ p ≤ 10^6+3, 1 ≤ a,b < p, 1 ≤ x ≤ 10^{12}). It is guaranteed that p is a prime.

Output

Print a single integer: the number of possible answers n.

Examples

Input

2 3 5 8

Output

2

Input

4 6 7 13

Output

1

Input

233 233 10007 1

Output

1

Note

In the first sample, we can see that n=2 and n=8 are possible answers.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long t = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') t = t * 10 + c - 48, c = getchar();
  return t * f;
}
vector<long long> vec[1000005];
long long a, b, p, x, ans, mo;
inline long long ksm(long long a, long long b) {
  long long t = 1, y = a;
  for (; b; b /= 2) {
    if (b & 1) t = 1ll * t * y % mo;
    y = 1ll * y * y % mo;
  }
  return t;
}
inline long long ni(long long a) { return ksm(a, mo - 2); }
inline long long get(long long b, long long z) {
  long long tt = b / (p - 1),
            ttt = upper_bound(vec[z].begin(), vec[z].end(), b % (p - 1)) -
                  vec[z].begin();
  return tt * vec[z].size() + ttt;
}
int main() {
  a = read();
  b = read();
  p = read();
  x = read();
  mo = p;
  long long t = a, ttp = 1;
  for (long long i = 0; i < p - 1; i++) {
    vec[ttp].push_back(i);
    ttp = ttp * t % p;
  }
  x++;
  for (long long i = 1; i < p; i++) {
    ans += get((x - i) / p + ((x - i) % p > 0) - 1,
               b * ni(i * ksm(a, i) % mo) % mo);
  }
  cout << ans << endl;
}

```


### Prompt

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

There is a square grid of size n × n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs min(h, w) to color a rectangle of size h × w. You are to make all cells white for minimum total cost.

The square is large, so we give it to you in a compressed way. The set of black cells is the union of m rectangles.

Input

The first line contains two integers n and m (1 ≤ n ≤ 10^{9}, 0 ≤ m ≤ 50) — the size of the square grid and the number of black rectangles.

Each of the next m lines contains 4 integers x_{i1} y_{i1} x_{i2} y_{i2} (1 ≤ x_{i1} ≤ x_{i2} ≤ n, 1 ≤ y_{i1} ≤ y_{i2} ≤ n) — the coordinates of the bottom-left and the top-right corner cells of the i-th black rectangle.

The rectangles may intersect.

Output

Print a single integer — the minimum total cost of painting the whole square in white.

Examples

Input

10 2
4 1 5 10
1 4 10 5

Output

4

Input

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

Output

3

Note

The examples and some of optimal solutions are shown on the pictures below.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void ckmin(T &a, U b) {
  if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
  if (a < b) a = b;
}
int N, X, Y;
vector<int> compress;
array<int, 4> rect[213];
vector<int> xs, ys;
bitset<213> flag[213];
int E = 2, S, T;
int to[100013], link[100013], cap[100013];
int head[213], dist[213];
bitset<213> seen;
int ans;
void addedge(int u, int v, int c) {
  to[E] = v;
  link[E] = head[u];
  head[u] = E;
  cap[E] = c;
  E++;
  to[E] = u;
  link[E] = head[v];
  head[v] = E;
  cap[E] = 0;
  E++;
}
bool bfs() {
  for (auto i = (0); i < (T + 1); i++) {
    dist[i] = 1000000007;
    seen[i] = false;
  }
  dist[S] = 0;
  queue<int> q;
  q.push(S);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int e = head[u]; e; e = link[e]) {
      int v = to[e];
      if (cap[e] == 0) continue;
      if (dist[v] > dist[u] + 1) {
        dist[v] = dist[u] + 1;
        q.push(v);
      }
    }
  }
  return (dist[T] != 1000000007);
}
int aug(int u, int f) {
  if (u == T) {
    return f;
  }
  seen[u] = true;
  int cur = 0;
  for (int e = head[u]; e; e = link[e]) {
    int v = to[e];
    if (dist[v] != dist[u] + 1) continue;
    if (cap[e] == 0) continue;
    if (seen[v]) continue;
    int gain = aug(v, min(cap[e], f));
    cap[e] -= gain;
    cap[e ^ 1] += gain;
    cur += gain;
    f -= gain;
  }
  return cur;
}
int maxflow() {
  int res = 0;
  while (true) {
    if (!bfs()) return res;
    res += aug(S, 1000000007);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> N;
  if (N == 0) {
    cout << "0\n";
    return 0;
  }
  for (auto i = (0); i < (N); i++) {
    int x1, eroschnit, x2, preparation;
    cin >> x1 >> eroschnit >> x2 >> preparation;
    x2++;
    preparation++;
    xs.push_back(x1);
    xs.push_back(x2);
    ys.push_back(eroschnit);
    ys.push_back(preparation);
    rect[i] = {x1, x2, eroschnit, preparation};
  }
  sort((xs).begin(), (xs).end());
  xs.erase(unique((xs).begin(), (xs).end()), xs.end());
  X = ((int)((xs).size())) - 1;
  sort((ys).begin(), (ys).end());
  ys.erase(unique((ys).begin(), (ys).end()), ys.end());
  Y = ((int)((ys).size())) - 1;
  for (auto i = (0); i < (N); i++) {
    for (auto j = (0); j < (2); j++) {
      rect[i][j] =
          lower_bound((xs).begin(), (xs).end(), rect[i][j]) - xs.begin();
    }
    for (auto j = (2); j < (4); j++) {
      rect[i][j] =
          lower_bound((ys).begin(), (ys).end(), rect[i][j]) - ys.begin();
    }
    for (auto j = (rect[i][0]); j < (rect[i][1]); j++) {
      for (auto k = (rect[i][2]); k < (rect[i][3]); k++) {
        flag[j][k] = true;
      }
    }
  }
  for (auto i = (0); i < (X); i++) {
    for (auto j = (0); j < (Y); j++) {
      if (!flag[i][j]) continue;
      addedge(i, X + j, 1000000007);
    }
  }
  S = X + Y;
  T = X + Y + 1;
  for (auto i = (0); i < (X); i++) {
    addedge(S, i, xs[i + 1] - xs[i]);
  }
  for (auto i = (0); i < (Y); i++) {
    addedge(X + i, T, ys[i + 1] - ys[i]);
  }
  ans = maxflow();
  cout << ans << '\n';
  return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

A false witness that speaketh lies!

You are given a sequence containing n integers. There is a variable res that is equal to 0 initially. The following process repeats k times.

Choose an index from 1 to n uniformly at random. Name it x. Add to res the multiply of all ai's such that 1 ≤ i ≤ n, but i ≠ x. Then, subtract ax by 1.

You have to find expected value of res at the end of the process. It can be proved that the expected value of res can be represented as an irreducible fraction <image>. You have to find <image>.

Input

The first line contains two integers n and k (1 ≤ n ≤ 5000, 1 ≤ k ≤ 109) — the number of elements and parameter k that is specified in the statement.

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

Output

Output a single integer — the value <image>.

Examples

Input

2 1
5 5

Output

5

Input

1 10
80

Output

10

Input

2 2
0 0

Output

500000003

Input

9 4
0 11 12 9 20 7 8 18 2

Output

169316356

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 5010, mod = 1000000007;
int ksm(long long a, int b, int c = 1) {
  for (; b; b /= 2, a = a * a % mod)
    if (b & 1) c = c * a % mod;
  return c;
}
int f[N], g[N], n, K, ans;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> K;
  f[0] = 1;
  for (int i = 1; i <= n; ++i) {
    int t;
    cin >> t;
    for (int j = i; j >= 0; --j) {
      g[j] = (f[j] + (long long)g[j] * t + mod - (j ? g[j - 1] : 0)) % mod;
      f[j] = ((long long)f[j] * t + mod - (j ? f[j - 1] : 0)) % mod;
    }
  }
  for (int j = 0, pw = K; j <= n && j < K; pw = (long long)pw * (K - ++j) % mod)
    ans = (ans + ksm(n, mod - 2 - j,
                     ksm(j + 1, mod - 2, (long long)g[j] * pw % mod))) %
          mod;
  cout << ans << '\n';
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

You are given a Young diagram.

Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1).

<image> Young diagram for a=[3,2,2,2,1].

Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 rectangle.

Input

The first line of input contain one integer n (1 ≤ n ≤ 300 000): the number of columns in the given histogram.

The next line of input contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300 000, a_i ≥ a_{i+1}): the lengths of columns.

Output

Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.

Example

Input

5
3 2 2 2 1

Output

4

Note

Some of the possible solutions for the example:

<image> <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long a[2];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i & 1] += x / 2;
    a[(i + 1) & 1] += (x - x / 2);
  }
  cout << min(a[0], a[1]) << '\n';
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

After Fox Ciel won an onsite round of a programming contest, she took a bus to return to her castle. The fee of the bus was 220 yen. She met Rabbit Hanako in the bus. They decided to play the following game because they got bored in the bus.

  * Initially, there is a pile that contains x 100-yen coins and y 10-yen coins.
  * They take turns alternatively. Ciel takes the first turn.
  * In each turn, they must take exactly 220 yen from the pile. In Ciel's turn, if there are multiple ways to take 220 yen, she will choose the way that contains the maximal number of 100-yen coins. In Hanako's turn, if there are multiple ways to take 220 yen, she will choose the way that contains the maximal number of 10-yen coins.
  * If Ciel or Hanako can't take exactly 220 yen from the pile, she loses.

Determine the winner of the game.

Input

The first line contains two integers x (0 ≤ x ≤ 106) and y (0 ≤ y ≤ 106), separated by a single space.

Output

If Ciel wins, print "Ciel". Otherwise, print "Hanako".

Examples

Input

2 2

Output

Ciel

Input

3 22

Output

Hanako

Note

In the first turn (Ciel's turn), she will choose 2 100-yen coins and 2 10-yen coins. In the second turn (Hanako's turn), she will choose 1 100-yen coin and 12 10-yen coins. In the third turn (Ciel's turn), she can't pay exactly 220 yen, so Ciel will lose.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y;
  cin >> x >> y;
  x = x * 100;
  y = y * 10;
  int n = 1;
  while (x + y >= 220 && y >= 20) {
    if (n % 2 != 0) {
      if (x >= 200) {
        x -= 200;
        y -= 20;
      } else if (x == 100) {
        x -= 100;
        y -= 120;
      } else
        y -= 220;
    } else {
      if (y >= 220)
        y -= 220;
      else if (y >= 120) {
        y -= 120;
        x -= 100;
      } else {
        y -= 20;
        x -= 200;
      }
    }
    n += 1;
  }
  if (n % 2 == 0)
    cout << "Ciel";
  else
    cout << "Hanako";
  return 0;
}

```


### Prompt

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

There are n players numbered from 0 to n-1 with ranks. The i-th player has rank i.

Players can form teams: the team should consist of three players and no pair of players in the team should have a conflict. The rank of the team is calculated using the following algorithm: let i, j, k be the ranks of players in the team and i < j < k, then the rank of the team is equal to A ⋅ i + B ⋅ j + C ⋅ k.

You are given information about the pairs of players who have a conflict. Calculate the total sum of ranks over all possible valid teams modulo 2^{64}.

Input

The first line contains two space-separated integers n and m (3 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ m ≤ 2 ⋅ 10^5) — the number of players and the number of conflicting pairs.

The second line contains three space-separated integers A, B and C (1 ≤ A, B, C ≤ 10^6) — coefficients for team rank calculation.

Each of the next m lines contains two space-separated integers u_i and v_i (0 ≤ u_i, v_i < n, u_i ≠ v_i) — pair of conflicting players.

It's guaranteed that each unordered pair of players appears in the input file no more than once.

Output

Print single integer — the total sum of ranks over all possible teams modulo 2^{64}.

Examples

Input

4 0
2 3 4

Output

64

Input

4 1
2 3 4
1 0

Output

38

Input

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

Output

164

Note

In the first example all 4 teams are valid, i.e. triples: {0, 1, 2}, {0, 1, 3}, {0, 2, 3} {1, 2, 3}.

In the second example teams are following: {0, 2, 3}, {1, 2, 3}.

In the third example teams are following: {0, 1, 2}, {0, 1, 4}, {0, 1, 5}, {0, 2, 4}, {0, 2, 5}, {1, 2, 3}, {1, 2, 4}, {1, 2, 5}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, u[200010], v[200010];
unsigned long long a, b, c;
unsigned long long C2(unsigned long long x) { return x * (x - 1) / 2; }
long long ss(long long l, long long r) { return (l + r) * (r - l + 1) / 2; }
unsigned long long solve0() {
  unsigned long long ans = 0;
  for (unsigned long long i = 0; i < n; i++) {
    ans += i * b * i * (n - 1 - i);
    ans += i * a * C2(n - 1 - i);
    ans += i * c * C2(i);
  }
  return ans;
}
unsigned long long solve1() {
  unsigned long long ans = 0;
  for (int i = 0; i < m; i++) {
    if (u[i] > v[i]) swap(u[i], v[i]);
    ans +=
        b * ss(u[i] + 1, v[i] - 1) + (a * u[i] + c * v[i]) * (v[i] - u[i] - 1);
    ans += (b * u[i] + c * v[i]) * u[i] + a * ss(0, u[i] - 1);
    ans += (a * u[i] + b * v[i]) * (n - 1 - v[i]) + c * ss(v[i] + 1, n - 1);
  }
  return ans;
}
int T[200010], ls[8000010], rs[8000010], cn;
struct qq {
  int s1;
  unsigned long long s2;
} s[8000010];
qq operator+(qq a, qq b) { return (qq){a.s1 + b.s1, a.s2 + b.s2}; }
void ins(int &o, int l, int r, int x) {
  if (!o) o = ++cn;
  s[o].s1++;
  s[o].s2 += x;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (x <= mid)
    ins(ls[o], l, mid, x);
  else
    ins(rs[o], mid + 1, r, x);
}
qq ask(int o, int l, int r, int x, int y) {
  if (!o || l > y || r < x) return (qq){0, 0};
  if (x <= l && r <= y) return s[o];
  int mid = (l + r) >> 1;
  return ask(ls[o], l, mid, x, y) + ask(rs[o], mid + 1, r, x, y);
}
unsigned long long solve2() {
  unsigned long long ans = 0;
  for (int i = 0; i < m; i++) {
    if (u[i] + 1 < v[i]) {
      qq t = ask(T[u[i]], 0, n - 1, u[i] + 1, v[i] - 1) +
             ask(T[v[i]], 0, n - 1, u[i] + 1, v[i] - 1);
      ans += b * t.s2 + (a * u[i] + c * v[i]) * t.s1;
    }
    if (u[i]) {
      qq t = ask(T[u[i]], 0, n - 1, 0, u[i] - 1) +
             ask(T[v[i]], 0, n - 1, 0, u[i] - 1);
      ans += a * t.s2 + (b * u[i] + c * v[i]) * t.s1;
    }
    if (v[i] + 1 < n) {
      qq t = ask(T[u[i]], 0, n - 1, v[i] + 1, n - 1) +
             ask(T[v[i]], 0, n - 1, v[i] + 1, n - 1);
      ans += c * t.s2 + (a * u[i] + b * v[i]) * t.s1;
    }
  }
  return ans;
}
int book[200010], d[200010];
vector<int> g[200010];
unsigned long long calc(int x, int y, int z) {
  if (x > y) swap(x, y);
  if (y > z) swap(y, z);
  if (x > y) swap(x, y);
  return a * x + b * y + c * z;
}
unsigned long long solve3() {
  for (int i = 0; i < m; i++) d[u[i]]++, d[v[i]]++;
  for (int i = 0; i < m; i++) {
    if (d[u[i]] > d[v[i]]) swap(u[i], v[i]);
    if (d[u[i]] == d[v[i]] && u[i] > v[i]) swap(u[i], v[i]);
    g[u[i]].push_back(v[i]);
  }
  unsigned long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < g[i].size(); j++) book[g[i][j]] = i + 1;
    for (int j = 0; j < g[i].size(); j++)
      for (int k = 0; k < g[g[i][j]].size(); k++)
        if (book[g[g[i][j]][k]] == i + 1)
          ans += calc(i, g[i][j], g[g[i][j]][k]);
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  cin >> a >> b >> c;
  for (int i = 0; i < m; i++)
    scanf("%d%d", &u[i], &v[i]), ins(T[u[i]], 0, n - 1, v[i]),
        ins(T[v[i]], 0, n - 1, u[i]);
  unsigned long long s0 = solve0(), s1 = solve1(), s2 = solve2(), s3 = solve3();
  s1 -= s3 * 3;
  s2 -= s3 * 6;
  s1 -= s2;
  s2 /= 2;
  cout << s0 - s1 - s2 - s3;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Euler is a little, cute squirrel. When the autumn comes, he collects some reserves for winter. The interesting fact is that Euler likes to collect acorns in a specific way. A tree can be described as n acorns connected by n - 1 branches, such that there is exactly one way between each pair of acorns. Let's enumerate the acorns from 1 to n.

The squirrel chooses one acorn (not necessary with number 1) as a start, and visits them in a way called "Euler tour" (see notes), collecting each acorn when he visits it for the last time.

Today morning Kate was observing Euler. She took a sheet of paper and wrote down consecutive indices of acorns on his path. Unfortunately, during her way to home it started raining and some of numbers became illegible. Now the girl is very sad, because she has to present the observations to her teacher.

"Maybe if I guess the lacking numbers, I'll be able to do it!" she thought. Help her and restore any valid Euler tour of some tree or tell that she must have made a mistake.

Input

The first line contains a single integer n (1 ≤ n ≤ 5 ⋅ 10^5), denoting the number of acorns in the tree.

The second line contains 2n - 1 integers a_1, a_2, …, a_{2n-1} (0 ≤ a_i ≤ n) — the Euler tour of the tree that Kate wrote down. 0 means an illegible number, which has to be guessed.

Output

If there is no Euler tour satisfying the given description, output "no" in the first line.

Otherwise, on the first line output "yes", and then in the second line print the Euler tour which satisfy the given description.

Any valid Euler tour will be accepted, since the teacher doesn't know how exactly the initial tree looks.

Examples

Input

2
1 0 0

Output

yes
1 2 1

Input

4
1 0 3 2 0 0 0

Output

yes
1 4 3 2 3 4 1

Input

5
0 1 2 3 4 1 0 0 0

Output

no

Note

An Euler tour of a tree with n acorns is a sequence of 2n - 1 indices of acorns. such that each acorn occurs at least once, the first and the last acorns are same and each two consecutive acorns are directly connected with a branch.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, m;
int a[N], num[N];
int rpos[N];
vector<int> pos[N];
void fail() {
  puts("no");
  exit(0);
}
void DFS_init(int l, int r) {
  int cnt = 0, len = 0;
  for (int i = l + 1; i <= r - 1; i++) {
    int x = a[i];
    if (x) {
      if (rpos[x] > r) fail();
      int lst = 0;
      for (int p : pos[x]) {
        if (lst) DFS_init(lst, p);
        lst = p;
      }
      i = rpos[x];
      ++cnt;
    }
    ++len;
  }
  ++len;
  if (l == 1 && !a[1]) len += 2;
  if (len / 2 < cnt || len % 2) fail();
  int c = len / 2 - cnt;
  if (l == 1 && !a[1] && !c) {
    int _cnt = 0, _len = 0;
    for (int i = l + 1; i <= r - 1; i++) {
      int x = a[i];
      ++_len;
      if (x) {
        i = rpos[x];
        if (_len % 2 == 0 && _cnt * 2 == _len) {
          a[1] = x;
          break;
        }
        ++_cnt;
      }
    }
  }
  if (l == 1 && !a[1]) --l, ++r;
  for (int i = l + 1; i <= r - 1; i++) {
    if (!c) break;
    int x = a[i];
    if (!x)
      a[i] = num[m--], --c;
    else
      i = rpos[x];
  }
  a[2 * n - 1] = a[1];
}
int nxt[N], pre[N];
void DFS_work(int l, int r) {
  assert(a[l] == a[r]);
  vector<int> vec;
  for (int i = l + 1; i <= r - 1; i++) {
    int x = a[i];
    if (x) {
      int lst = 0;
      for (int p : pos[x]) {
        if (lst) DFS_work(lst, p);
        lst = p;
      }
      i = rpos[x];
    }
    vec.push_back(i);
  }
  pre[l] = nxt[r] = 0;
  int lst = l;
  for (int x : vec) pre[x] = lst, nxt[lst] = x, lst = x;
  nxt[lst] = r, pre[r] = lst;
  for (int o = nxt[l]; o < r; o = nxt[o])
    while (a[pre[o]] && a[o] && !a[nxt[o]]) {
      a[nxt[o]] = a[pre[o]];
      int v = nxt[nxt[o]];
      nxt[pre[o]] = v, pre[v] = pre[o];
      o = pre[o];
    }
  for (int o = pre[r]; o > l; o = pre[o])
    while (!a[pre[o]] && a[o] && a[nxt[o]]) {
      a[pre[o]] = a[nxt[o]];
      int v = pre[pre[o]];
      pre[nxt[o]] = v, nxt[v] = nxt[o];
      o = nxt[o];
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 2 * n - 1; i++) scanf("%d", &a[i]);
  if (n == 1) a[1] = 1;
  if (a[1] && a[2 * n - 1] && a[1] != a[2 * n - 1]) fail();
  a[1] = a[2 * n - 1] = max(a[1], a[2 * n - 1]);
  for (int i = 1; i <= 2 * n - 1; i++)
    if (a[i]) {
      pos[a[i]].push_back(i);
      rpos[a[i]] = i;
    }
  for (int i = 1; i <= n; i++)
    if (!rpos[i]) num[++m] = i;
  if (!a[1])
    DFS_init(1, 2 * n - 1);
  else {
    int x = a[1], lst = 0;
    for (int p : pos[x]) {
      if (lst) DFS_init(lst, p);
      lst = p;
    }
  }
  if (m) fail();
  for (int i = 1; i <= n; i++) pos[i].clear();
  for (int i = 1; i <= 2 * n - 1; i++)
    if (a[i]) {
      pos[a[i]].push_back(i);
      rpos[a[i]] = i;
    }
  int x = a[1], lst = 0;
  for (int p : pos[x]) {
    if (lst) DFS_work(lst, p);
    lst = p;
  }
  puts("yes");
  for (int i = 1; i <= 2 * n - 1; i++)
    printf("%d%c", a[i], i == 2 * n - 1 ? '\n' : ' ');
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Kostya is a progamer specializing in the discipline of Dota 2. Valve Corporation, the developer of this game, has recently released a new patch which turned the balance of the game upside down. Kostya, as the captain of the team, realizes that the greatest responsibility lies on him, so he wants to resort to the analysis of innovations patch from the mathematical point of view to choose the best heroes for his team in every game.

A Dota 2 match involves two teams, each of them must choose some heroes that the players of the team are going to play for, and it is forbidden to choose the same hero several times, even in different teams. In large electronic sports competitions where Kostya's team is going to participate, the matches are held in the Captains Mode. In this mode the captains select the heroes by making one of two possible actions in a certain, predetermined order: pick or ban.

  * To pick a hero for the team. After the captain picks, the picked hero goes to his team (later one of a team members will play it) and can no longer be selected by any of the teams.
  * To ban a hero. After the ban the hero is not sent to any of the teams, but it still can no longer be selected by any of the teams.

The team captain may miss a pick or a ban. If he misses a pick, a random hero is added to his team from those that were available at that moment, and if he misses a ban, no hero is banned, as if there was no ban.

Kostya has already identified the strength of all the heroes based on the new patch fixes. Of course, Kostya knows the order of picks and bans. The strength of a team is the sum of the strengths of the team's heroes and both teams that participate in the match seek to maximize the difference in strengths in their favor. Help Kostya determine what team, the first one or the second one, has advantage in the match, and how large the advantage is.

Input

The first line contains a single integer n (2 ≤ n ≤ 100) — the number of heroes in Dota 2.

The second line contains n integers s1, s2, ..., sn (1 ≤ si ≤ 106) — the strengths of all the heroes.

The third line contains a single integer m (2 ≤ m ≤ min(n, 20)) — the number of actions the captains of the team must perform.

Next m lines look like "action team", where action is the needed action: a pick (represented as a "p") or a ban (represented as a "b"), and team is the number of the team that needs to perform the action (number 1 or 2).

It is guaranteed that each team makes at least one pick. Besides, each team has the same number of picks and the same number of bans.

Output

Print a single integer — the difference between the strength of the first team and the strength of the second team if the captains of both teams will act optimally well.

Examples

Input

2
2 1
2
p 1
p 2

Output

1

Input

6
6 4 5 4 5 5
4
b 2
p 1
b 1
p 2

Output

0

Input

4
1 2 3 4
4
p 2
b 2
p 1
b 1

Output

-2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read1() {
  T t = 0;
  char k = getchar();
  bool flag = 0;
  while ('0' > k || k > '9') {
    if (k == '-') flag = 1;
    k = getchar();
  }
  while ('0' <= k && k <= '9')
    t = (t << 3) + (t << 1) + (k ^ 48), k = getchar();
  return flag ? -t : t;
}
int Max(int a, int b) { return a > b ? a : b; }
int Min(int a, int b) { return a < b ? a : b; }
int s, a[105], m, t[1048577], w[22], o[3] = {0, -(1 << 30), 1 << 30},
                                     dp[1048577];
char str[22];
int (*x[3])(int, int) = {NULL, Max, Min};
int main() {
  s = read1<long long>();
  for (int i = 1; i <= s; ++i) a[i] = read1<long long>();
  m = read1<long long>();
  sort(a + 1, a + s + 1);
  reverse(a + 1, a + s + 1);
  for (int i = 1; i <= m; ++i) cin >> str[i] >> w[i];
  for (int i = 1; i < (1 << m); ++i) {
    t[i] = t[i & i - 1] + 1;
    int te = m - t[i] + 1;
    dp[i] = o[w[te]];
    int l = str[te] == 'b' ? 0 : w[te] & 1 ? 1 : -1;
    for (int j = 0; j < m; ++j)
      if ((1 << j) & i)
        dp[i] = x[w[te]](dp[i], dp[i ^ (1 << j)] + l * a[j + 1]);
  }
  printf("%d", dp[(1 << m) - 1]);
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

AtCoDeer the deer found N rectangle lying on the table, each with height 1. If we consider the surface of the desk as a two-dimensional plane, the i-th rectangle i(1≤i≤N) covers the vertical range of [i-1,i] and the horizontal range of [l_i,r_i], as shown in the following figure:

<image>

AtCoDeer will move these rectangles horizontally so that all the rectangles are connected. For each rectangle, the cost to move it horizontally by a distance of x, is x. Find the minimum cost to achieve connectivity. It can be proved that this value is always an integer under the constraints of the problem.

Constraints

* All input values are integers.
* 1≤N≤10^5
* 1≤l_i<r_i≤10^9

Input

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

N
l_1 r_1
l_2 r_2
:
l_N r_N

Output

Print the minimum cost to achieve connectivity.

Examples

Input

3
1 3
5 7
1 3

Output

2

Input

3
2 5
4 6
1 4

Output

0

Input

5
999999999 1000000000
1 2
314 315
500000 500001
999999999 1000000000

Output

1999999680

Input

5
123456 789012
123 456
12 345678901
123456 789012
1 23

Output

246433

Input

1
1 400

Output

0

### Response

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

typedef long long ll;

ll ans;

struct slope {
	priority_queue <ll> pq;
	ll delta;

	void upd(ll x) { delta += x; }
	void push(ll x) { pq.push(x - delta); }
	ll top() { return pq.top() + delta; }
	void pop() { pq.pop(); }

	void debug() {
		cerr << "\tdelta = " << delta << endl;
		priority_queue <ll> tmp = pq;
		cerr << "\tDEBUG\n";
		cerr << "\t";
		while(!tmp.empty()) {
			cerr << abs(tmp.top() + delta) << ' ';
			tmp.pop();
		}
		cerr << endl;
	}
} lef, rig;

const int N = 1e5 + 5;
int n;
ll l[N], r[N];

ll cost(ll l, ll r, ll x) {
	if (x < l) return l - x;
	if (x > r) return x - r;
	return 0;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> l[i] >> r[i];

	lef.push(l[1]);
	rig.push(-l[1]);

	for (int i = 2; i <= n; ++i) {
		lef.upd(l[i] - r[i]);
		rig.upd(-(r[i - 1] - l[i - 1]));

		ans += cost(lef.top(), -rig.top(), l[i]);

		lef.push(l[i]);
		rig.push(-l[i]);

		while(lef.top() > -rig.top()) {
			ll x = lef.top(); lef.pop();
			ll y = -rig.top(); rig.pop();
			lef.push(y); rig.push(-x);
		}
	}

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


### Prompt

Generate a cpp solution to the following problem:

You are given a directed graph, consisting of n vertices and m edges. The vertices s and t are marked as source and sink correspondingly. Additionally, there are no edges ending at s and there are no edges beginning in t.

The graph was constructed in a following way: initially each edge had capacity ci > 0. A maximum flow with source at s and sink at t was constructed in this flow network. Let's denote fi as the value of flow passing through edge with index i. Next, all capacities ci and flow value fi were erased. Instead, indicators gi were written on edges — if flow value passing through edge i was positive, i.e. 1 if fi > 0 and 0 otherwise.

Using the graph and values gi, find out what is the minimum possible number of edges in the initial flow network that could be saturated (the passing flow is equal to capacity, i.e. fi = ci). Also construct the corresponding flow network with maximum flow in it.

A flow in directed graph is described by flow values fi on each of the edges so that the following conditions are satisfied:

  * for each vertex, except source and sink, total incoming flow and total outcoming flow are equal,
  * for each edge 0 ≤ fi ≤ ci

A flow is maximum if the difference between the sum of flow values on edges from the source, and the sum of flow values on edges to the source (there are no such in this problem), is maximum possible.

Input

The first line of input data contains four positive integers n, m, s, t (2 ≤ n ≤ 100, 1 ≤ m ≤ 1000, 1 ≤ s, t ≤ n, s ≠ t) — the number of vertices, the number of edges, index of source vertex and index of sink vertex correspondingly.

Each of next m lines of input data contain non-negative integers ui, vi, gi (1 ≤ ui, vi ≤ n, <image>) — the beginning of edge i, the end of edge i and indicator, which equals to 1 if flow value passing through edge i was positive and 0 if not.

It's guaranteed that no edge connects vertex with itself. Also it's guaranteed that there are no more than one edge between each ordered pair of vertices and that there exists at least one network flow that satisfies all the constrains from input data.

Output

In the first line print single non-negative integer k — minimum number of edges, which should be saturated in maximum flow.

In each of next m lines print two integers fi, ci (1 ≤ ci ≤ 109, 0 ≤ fi ≤ ci) — the flow value passing through edge i and capacity of edge i.

This data should form a correct maximum flow in flow network. Also there must be exactly k edges with statement fi = ci satisfied. Also statement fi > 0 must be true if and only if gi = 1.

If there are several possible answers, print any of them.

Example

Input

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

Output

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

Note

The illustration for second sample case. The saturated edges are marked dark, while edges with gi = 0 are marked with dotted line. The integer on edge is the index of this edge in input list. <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  int f = 0;
  x = 0;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar()) f |= (ch == '-');
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  if (f) x = -x;
}
const int N = 2005, inf = 1e9 + 9;
namespace G {
struct edge {
  int u, v, f, c, p;
};
vector<edge> e[N];
int d[N], r[N], in[N], n, s, t;
void init(int _n, int _s, int _t) {
  for (int i = (1); i <= (n); i++) e[i].clear();
  n = _n, s = _s, t = _t;
}
int add(int u, int v, int w) {
  e[u].push_back((edge){u, v, 0, w, (int)e[v].size()});
  e[v].push_back((edge){v, u, 0, 0, (int)e[u].size() - 1});
  return (int)e[u].size() - 1;
}
int bfs() {
  static int q[N];
  int l = 0, r = 0;
  fill(d + 1, d + n + 1, -1), d[s] = 0;
  for (q[r++] = s; l < r;) {
    int u = q[l++];
    for (int i = 0; i < int(e[u].size()); i++) {
      edge &v = e[u][i];
      if (v.f < v.c && d[v.v] == -1) {
        d[q[r++] = v.v] = d[u] + 1;
        if (v.v == t) return 1;
      }
    }
  }
  return 0;
}
int dfs(int u, int a) {
  if (u == t) return a;
  int res = 0;
  in[u] = 1;
  for (int &i = r[u]; i < (int)e[u].size(); i++) {
    edge &v = e[u][i];
    if (v.f < v.c && d[u] + 1 == d[v.v] && !in[v.v]) {
      int ret = dfs(v.v, min(v.c - v.f, a));
      v.f += ret, e[v.v][v.p].f -= ret, res += ret;
      if (!(a -= ret)) break;
    }
  }
  return in[u] = 0, res;
}
int flow() {
  int res = 0;
  while (bfs()) {
    fill(r + 1, r + n + 1, 0);
    res += dfs(s, inf);
  }
  return res;
}
}  // namespace G
int u[N], v[N], g[N], d[N], f[N], id[N];
int n, m, s, t, S, T;
int main() {
  read(n), read(m);
  read(s), read(t);
  for (int i = (1); i <= (m); i++) {
    read(u[i]), read(v[i]), read(g[i]);
    if (g[i]) d[u[i]]++, d[v[i]]--;
  }
  G::init(n, s, t);
  for (int i = (1); i <= (m); i++) {
    if (g[i]) {
      G::add(u[i], v[i], 1);
      G::add(v[i], u[i], inf);
    } else {
      G::add(u[i], v[i], inf);
    }
  }
  cout << G::flow() << endl;
  for (int i = (1); i <= (m); i++) {
    if (!g[i]) continue;
    f[i] = (G::d[u[i]] >= 0 && G::d[v[i]] == -1);
  }
  S = n + 1, T = n + 2;
  G::init(n + 2, S, T);
  for (int i = (1); i <= (m); i++) {
    if (!g[i]) continue;
    id[i] = G::add(u[i], v[i], inf);
  }
  G::add(t, s, inf);
  for (int i = (1); i <= (n); i++) {
    if (d[i] > 0)
      G::add(i, T, d[i]);
    else
      G::add(S, i, -d[i]);
  }
  G::flow();
  for (int i = (1); i <= (m); i++) {
    if (!g[i]) {
      puts("0 1");
      continue;
    }
    int bas = G::e[u[i]][id[i]].f + 1;
    printf("%d %d\n", bas, bas + (!f[i] ? 1 : 0));
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right.

In this table, Vanya chose n rectangles with sides that go along borders of squares (some rectangles probably occur multiple times). After that for each cell of the table he counted the number of rectangles it belongs to and wrote this number into it. Now he wants to find the sum of values in all cells of the table and as the table is too large, he asks you to help him find the result.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of rectangles.

Each of the following n lines contains four integers x1, y1, x2, y2 (1 ≤ x1 ≤ x2 ≤ 100, 1 ≤ y1 ≤ y2 ≤ 100), where x1 and y1 are the number of the column and row of the lower left cell and x2 and y2 are the number of the column and row of the upper right cell of a rectangle.

Output

In a single line print the sum of all values in the cells of the table.

Examples

Input

2
1 1 2 3
2 2 3 3

Output

10

Input

2
1 1 3 3
1 1 3 3

Output

18

Note

Note to the first sample test:

Values of the table in the first three rows and columns will be as follows:

121

121

110

So, the sum of values will be equal to 10.

Note to the second sample test:

Values of the table in the first three rows and columns will be as follows:

222

222

222

So, the sum of values will be equal to 18.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    ans += (abs(x1 - x2) + 1) * (abs(y1 - y2) + 1);
  }
  cout << ans;
  return 0;
}

```


### Prompt

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

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

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

<image>

Input

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

Output

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

Examples

Input

2 5 3

Output

38.546168065709

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int main() {
  double pi = acos(-1);
  double l, res = 0;
  ;
  for (int i = 3; i <= 5; ++i) {
    cin >> l;
    double x = l / 2 / sin(pi / i);
    double h = sqrt(l * l - x * x);
    double S = x * x / 2 * i * sin((pi + pi) / i);
    res += S * h / 3;
  }
  printf("%.15f\n", res);
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Hanh is a famous biologist. He loves growing trees and doing experiments on his own garden.

One day, he got a tree consisting of n vertices. Vertices are numbered from 1 to n. A tree with n vertices is an undirected connected graph with n-1 edges. Initially, Hanh sets the value of every vertex to 0.

Now, Hanh performs q operations, each is either of the following types:

  * Type 1: Hanh selects a vertex v and an integer d. Then he chooses some vertex r uniformly at random, lists all vertices u such that the path from r to u passes through v. Hanh then increases the value of all such vertices u by d.
  * Type 2: Hanh selects a vertex v and calculates the expected value of v.

Since Hanh is good at biology but not math, he needs your help on these operations.

Input

The first line contains two integers n and q (1 ≤ n, q ≤ 150 000) — the number of vertices on Hanh's tree and the number of operations he performs.

Each of the next n - 1 lines contains two integers u and v (1 ≤ u, v ≤ n), denoting that there is an edge connecting two vertices u and v. It is guaranteed that these n - 1 edges form a tree.

Each of the last q lines describes an operation in either formats:

  * 1 v d (1 ≤ v ≤ n, 0 ≤ d ≤ 10^7), representing a first-type operation.
  * 2 v (1 ≤ v ≤ n), representing a second-type operation.

It is guaranteed that there is at least one query of the second type.

Output

For each operation of the second type, write the expected value on a single line.

Let M = 998244353, it can be shown that the expected value can be expressed as an irreducible fraction p/q, where p and q are integers and q not ≡ 0 \pmod{M}. Output the integer equal to p ⋅ q^{-1} mod M. In other words, output such an integer x that 0 ≤ x < M and x ⋅ q ≡ p \pmod{M}.

Example

Input

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

Output

1
199648871
399297742
199648871
199648871
598946614
199648873
2
2
2

Note

The image below shows the tree in the example:

<image>

For the first query, where v = 1 and d = 1:

  * If r = 1, the values of all vertices get increased.
  * If r = 2, the values of vertices 1 and 3 get increased.
  * If r = 3, the values of vertices 1, 2, 4 and 5 get increased.
  * If r = 4, the values of vertices 1 and 3 get increased.
  * If r = 5, the values of vertices 1 and 3 get increased.

Hence, the expected values of all vertices after this query are (1, 0.4, 0.8, 0.4, 0.4).

For the second query, where v = 2 and d = 2:

  * If r = 1, the values of vertices 2, 4 and 5 get increased.
  * If r = 2, the values of all vertices get increased.
  * If r = 3, the values of vertices 2, 4 and 5 get increased.
  * If r = 4, the values of vertices 1, 2, 3 and 5 get increased.
  * If r = 5, the values of vertices 1, 2, 3 and 4 get increased.

Hence, the expected values of all vertices after this query are (2.2, 2.4, 2, 2, 2).

### Response

```cpp
#include <bits/stdc++.h>
const int Mod = 998244353;
int quipow(int a, int b) {
  int ret = 1;
  for (; b; b >>= 1, a = (long long)a * a % Mod)
    if (b & 1) ret = (long long)ret * a % Mod;
  return ret;
}
struct edge {
  int to, nxt;
} e[150005 << 1];
int n, q;
int h[150005], cnt;
int gson[150005], dfn[150005], hdfs[150005], siz[150005], top[150005],
    fa[150005];
int T[150005 << 2], val[150005];
void ins(int x, int y) {
  e[++cnt].nxt = h[x];
  h[x] = cnt;
  e[cnt].to = y;
}
void dfs1(int x, int f) {
  siz[x] = 1;
  fa[x] = f;
  for (int i = h[x]; i; i = e[i].nxt)
    if (e[i].to != f) {
      dfs1(e[i].to, x);
      siz[x] += siz[e[i].to];
      if (siz[gson[x]] < siz[e[i].to]) gson[x] = e[i].to;
    }
}
void dfs2(int x, int t) {
  dfn[x] = ++cnt;
  hdfs[cnt] = x;
  top[x] = t;
  if (!gson[x]) return;
  dfs2(gson[x], t);
  for (int i = h[x]; i; i = e[i].nxt)
    if (e[i].to != fa[x] && e[i].to != gson[x]) dfs2(e[i].to, e[i].to);
}
void add(int& x, int y) {
  x += y;
  x >= Mod ? x -= Mod : 0;
  x < 0 ? x += Mod : 0;
}
void modi(int x, int v) { add(T[x], v); }
void push_down(int x) {
  if (T[x]) {
    add(T[x << 1], T[x]);
    add(T[x << 1 | 1], T[x]);
    T[x] = 0;
  }
}
void modify(int x, int l, int r, int L, int R, int v) {
  if (l > R || r < L) return;
  if (l >= L && r <= R) return (void)(add(T[x], v));
  int mid = l + r >> 1;
  push_down(x);
  modify(x << 1, l, mid, L, R, v);
  modify(x << 1 | 1, mid + 1, r, L, R, v);
}
int query(int x, int l, int r, int pos) {
  if (l == r) return T[x];
  push_down(x);
  int mid = l + r >> 1;
  if (pos <= mid) return query(x << 1, l, mid, pos);
  return query(x << 1 | 1, mid + 1, r, pos);
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    ins(a, b);
    ins(b, a);
  }
  cnt = 0;
  dfs1(1, 0);
  dfs2(1, 1);
  for (; q--;) {
    int opt, v, d, ans = 0;
    scanf("%d%d", &opt, &v);
    if (opt == 1) {
      scanf("%d", &d);
      modify(1, 1, n, 1, n, (long long)d * siz[v] % Mod);
      modify(1, 1, n, dfn[v], dfn[v] + siz[v] - 1,
             (long long)-d * siz[v] % Mod);
      if (gson[v])
        modify(1, 1, n, dfn[gson[v]], dfn[gson[v]] + siz[gson[v]] - 1,
               (long long)d * (n - siz[gson[v]]) % Mod);
      add(val[v], d);
    } else {
      add(ans, (long long)val[v] * n % Mod);
      add(ans, query(1, 1, n, dfn[v]));
      for (; fa[top[v]]; v = fa[top[v]])
        add(ans, (long long)(n - siz[top[v]]) * val[fa[top[v]]] % Mod);
      ans = (long long)ans * quipow(n, Mod - 2) % Mod;
      printf("%d\n", ans);
    }
  }
}

```


### Prompt

Generate a CPP solution to the following problem:

"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.

Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.

Constraints

* 1 ≤ A, B, C ≤ 5000
* 1 ≤ X, Y ≤ 10^5
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C X Y

Output

Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas.

Examples

Input

1500 2000 1600 3 2

Output

7900

Input

1500 2000 1900 3 2

Output

8500

Input

1500 2000 500 90000 100000

Output

100000000

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,x,y,ans=0;cin>>a>>c>>b>>x>>y;b*=2;
  if(x<y){
    a^=c;c^=a;a^=c;
    x^=y;y^=x;x^=y;
  }
  while(y){
    ans+=min(a+c,b);
    x--;y--;
  }
  while(x){
    ans+=min(a,b);
    x--;
  }
  cout<<ans<<endl;
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.

Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly k empty cells into walls so that all the remaining cells still formed a connected area. Help him.

Input

The first line contains three integers n, m, k (1 ≤ n, m ≤ 500, 0 ≤ k < s), where n and m are the maze's height and width, correspondingly, k is the number of walls Pavel wants to add and letter s represents the number of empty cells in the original maze.

Each of the next n lines contains m characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall.

Output

Print n lines containing m characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").

It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.

Examples

Input

3 4 2
#..#
..#.
#...

Output

#.X#
X.#.
#...

Input

5 4 5
#...
#.#.
.#..
...#
.#.#

Output

#XXX
#X#.
X#..
...#
.#.#

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int p, n, m, k, s, us[501][501];
char a[501][501];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
deque<pair<int, int> > q;
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i][j] == '.') p++;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == '.') {
        q.push_back({i, j});
        us[i][j] = 1;
        s = 1;
        if (1 == p - k) break;
        while (!q.empty()) {
          int t = q.front().first, t1 = q.front().second;
          q.pop_front();
          for (int u = 0; u < 4; u++) {
            if (t + dx[u] >= 1 && t + dx[u] <= n && t1 + dy[u] >= 1 &&
                t1 + dy[u] <= m && a[t + dx[u]][t1 + dy[u]] == '.' &&
                us[t + dx[u]][t1 + dy[u]] == 0) {
              s++;
              us[t + dx[u]][t1 + dy[u]] = 1;
              q.push_back({t + dx[u], t1 + dy[u]});
              if (s == p - k) break;
            }
          }
          if (s == p - k) break;
        }
        if (s == p - k) break;
      }
      if (s == p - k) break;
    }
    if (s == p - k) break;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      if (a[i][j] != '.') {
        cout << a[i][j];
      } else if (us[i][j] == 0) {
        cout << "X";
      } else
        cout << '.';
    cout << endl;
  }
  return 0;
}

```


### Prompt

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

Bankopolis, the city you already know, finally got a new bank opened! Unfortunately, its security system is not yet working fine... Meanwhile hacker Leha arrived in Bankopolis and decided to test the system!

Bank has n cells for clients' money. A sequence from n numbers a1, a2, ..., an describes the amount of money each client has. Leha wants to make requests to the database of the bank, finding out the total amount of money on some subsegments of the sequence and changing values of the sequence on some subsegments. Using a bug in the system, Leha can requests two types of queries to the database:

  * 1 l r x y denoting that Leha changes each digit x to digit y in each element of sequence ai, for which l ≤ i ≤ r is holds. For example, if we change in number 11984381 digit 8 to 4, we get 11944341. It's worth noting that Leha, in order to stay in the shadow, never changes digits in the database to 0, i.e. y ≠ 0.
  * 2 l r denoting that Leha asks to calculate and print the sum of such elements of sequence ai, for which l ≤ i ≤ r holds.

As Leha is a white-hat hacker, he don't want to test this vulnerability on a real database. You are to write a similar database for Leha to test.

Input

The first line of input contains two integers n and q (1 ≤ n ≤ 105, 1 ≤ q ≤ 105) denoting amount of cells in the bank and total amount of queries respectively.

The following line contains n integers a1, a2, ..., an (1 ≤ ai < 109) denoting the amount of money in each cell initially. These integers do not contain leading zeros.

Each of the following q lines has one of the formats:

  * 1 l r x y (1 ≤ l ≤ r ≤ n, 0 ≤ x ≤ 9, 1 ≤ y ≤ 9), denoting Leha asks to change each digit x on digit y for each element ai of the sequence for which l ≤ i ≤ r holds;
  * 2 l r (1 ≤ l ≤ r ≤ n), denoting you have to calculate and print the sum of elements ai for which l ≤ i ≤ r holds.

Output

For each second type query print a single number denoting the required sum.

Examples

Input

5 5
38 43 4 12 70
1 1 3 4 8
2 2 4
1 4 5 0 8
1 2 5 8 7
2 1 5

Output

103
207

Input

5 5
25 36 39 40 899
1 1 3 2 7
2 1 2
1 3 5 9 1
1 4 4 0 9
2 1 5

Output

111
1002

Note

Let's look at the example testcase.

Initially the sequence is [38, 43, 4, 12, 70].

After the first change each digit equal to 4 becomes 8 for each element with index in interval [1; 3]. Thus, the new sequence is [38, 83, 8, 12, 70].

The answer for the first sum's query is the sum in the interval [2; 4], which equal 83 + 8 + 12 = 103, so the answer to this query is 103.

The sequence becomes [38, 83, 8, 12, 78] after the second change and [38, 73, 7, 12, 77] after the third.

The answer for the second sum's query is 38 + 73 + 7 + 12 + 77 = 207.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, q;
int a[N][10];
struct node {
  int nxt[10];
  long long sum[10];
} tree[N << 3];
void up(int rt) {
  for (int i = 0; i < 10; i++)
    tree[rt].sum[i] = tree[(rt << 1)].sum[i] + tree[(rt << 1 | 1)].sum[i];
}
long long sum1[10], sum2[10];
bool vis[10];
void down(int rt) {
  for (int i = 0; i < 10; i++) sum1[i] = 0, sum2[i] = 0;
  for (int i = 0; i < 10; i++)
    tree[(rt << 1)].nxt[i] = tree[rt].nxt[tree[(rt << 1)].nxt[i]],
                tree[(rt << 1 | 1)].nxt[i] =
                    tree[rt].nxt[tree[(rt << 1 | 1)].nxt[i]];
  for (int i = 0; i < 10; i++)
    sum1[tree[rt].nxt[i]] += tree[(rt << 1)].sum[i],
        sum2[tree[rt].nxt[i]] += tree[(rt << 1 | 1)].sum[i];
  for (int i = 0; i < 10; i++)
    tree[(rt << 1)].sum[i] = sum1[i], tree[(rt << 1 | 1)].sum[i] = sum2[i];
  for (int i = 0; i < 10; i++) tree[rt].nxt[i] = i;
}
void build(int l, int r, int rt) {
  for (int i = 0; i < 10; i++) tree[rt].nxt[i] = i;
  if (l == r) {
    for (int i = 0; i < 10; i++) tree[rt].sum[i] = a[l][i];
    return;
  }
  int mid = l + r >> 1;
  build(l, mid, (rt << 1));
  build(mid + 1, r, (rt << 1 | 1));
  up(rt);
}
void update(int L, int R, int l, int r, int rt, int x, int y) {
  if (L <= l && r <= R) {
    for (int i = 0; i < 10; i++)
      if (tree[rt].nxt[i] == x) tree[rt].nxt[i] = y;
    tree[rt].sum[y] += tree[rt].sum[x];
    tree[rt].sum[x] = 0;
    return;
  }
  down(rt);
  int mid = l + r >> 1;
  if (L <= mid) update(L, R, l, mid, (rt << 1), x, y);
  if (R > mid) update(L, R, mid + 1, r, (rt << 1 | 1), x, y);
  up(rt);
  return;
}
long long query(int L, int R, int l, int r, int rt) {
  if (L <= l && r <= R) {
    long long tmp = 0;
    for (int i = 0; i < 10; i++) tmp += i * tree[rt].sum[i];
    return tmp;
  }
  down(rt);
  int mid = l + r >> 1;
  long long tmp = 0;
  if (L <= mid) tmp += query(L, R, l, mid, (rt << 1));
  if (R > mid) tmp += query(L, R, mid + 1, r, (rt << 1 | 1));
  up(rt);
  return tmp;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    int base = 1;
    while (x) {
      a[i][x % 10] += base;
      x /= 10;
      base *= 10;
    }
  }
  build(1, n, 1);
  while (q--) {
    int type, l, r, x, y;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d%d%d%d", &l, &r, &x, &y);
      if (x == y) continue;
      update(l, r, 1, n, 1, x, y);
    } else {
      scanf("%d%d", &l, &r);
      printf("%I64d\n", query(l, r, 1, n, 1));
    }
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation

F1 = 1; F2 = 1; Fn = Fn - 1 + Fn - 2 (n > 2).

DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integers: a1, a2, ..., an. Moreover, there are m queries, each query has one of the two types:

  1. Format of the query "1 l r". In reply to the query, you need to add Fi - l + 1 to each element ai, where l ≤ i ≤ r.
  2. Format of the query "2 l r". In reply to the query you should output the value of <image> modulo 1000000009 (109 + 9).

Help DZY reply to all the queries.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 300000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — initial array a.

Then, m lines follow. A single line describes a single query in the format given in the statement. It is guaranteed that for each query inequality 1 ≤ l ≤ r ≤ n holds.

Output

For each query of the second type, print the value of the sum on a single line.

Examples

Input

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

Output

17
12

Note

After the first query, a = [2, 3, 5, 7].

For the second query, sum = 2 + 3 + 5 + 7 = 17.

After the third query, a = [2, 4, 6, 9].

For the fourth query, sum = 2 + 4 + 6 = 12.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300110;
const int mod = 1e9 + 9;
int n, m;
int sumv[maxn * 4];
int f1[maxn * 4];
int f2[maxn * 4];
int num[maxn];
int sum[maxn];
int f[maxn];
int addv(int a, int b, int n) {
  return ((((long long)f[n + 1] * (long long)b) % mod +
           ((long long)f[n] * (long long)a) % mod) %
              mod +
          (mod - b) % mod) %
         mod;
}
int get(int a, int b, int n) {
  return ((long long)f[n - 1] * (long long)b +
          ((long long)f[n - 2] * (long long)a) % mod) %
         mod;
}
void maintain(int o, int l, int r) {
  int lc = o * 2, rc = lc + 1;
  sumv[o] = 0;
  if (r > l) sumv[o] = (sumv[lc] + sumv[rc]) % mod;
  sumv[o] =
      ((sumv[o] + ((long long)f[r - l + 2] * (long long)(f2[o])) % mod) % mod +
       ((((long long)f[r - l + 1] * (long long)(f1[o])) % mod +
         (mod - f2[o]) % mod) %
        mod)) %
      mod;
}
void update(int o, int l, int r, int yl, int yr) {
  int lc = o * 2, rc = lc + 1;
  int m = l + (r - l) / 2;
  if (yl <= l && yr >= r) {
    f1[o] = (f1[o] + f[l - yl + 1]) % mod;
    f2[o] = (f2[o] + f[l - yl + 2]) % mod;
  } else {
    if (yl <= m) update(lc, l, m, yl, yr);
    if (yr > m) update(rc, m + 1, r, yl, yr);
  }
  maintain(o, l, r);
}
int _sum;
void query(int o, int l, int r, int ql, int qr, int add_f1, int add_f2) {
  int lc = o * 2, rc = lc + 1;
  int m = l + (r - l) / 2;
  if (ql <= l && qr >= r) {
    _sum = ((_sum + sumv[o]) % mod + addv(add_f1, add_f2, r - l + 1)) % mod;
  } else {
    if (ql <= m)
      query(lc, l, m, ql, qr, (add_f1 + f1[o]) % mod, (add_f2 + f2[o]) % mod);
    if (qr > m)
      query(rc, m + 1, r, ql, qr,
            get((add_f1 + f1[o]) % mod, (add_f2 + f2[o]) % mod, m + 2 - l),
            get((add_f1 + f1[o]) % mod, (add_f2 + f2[o]) % mod, m + 3 - l));
  }
}
int main() {
  memset(sumv, 0, sizeof(sumv));
  memset(f1, 0, sizeof(f1));
  memset(f2, 0, sizeof(f2));
  f[0] = 0;
  f[1] = 1;
  f[2] = 1;
  for (int i = 3; i < maxn; ++i) f[i] = (f[i - 1] + f[i - 2]) % mod;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &num[i]);
  sum[0] = 0;
  for (int i = 1; i <= n; ++i) sum[i] = (sum[i - 1] + num[i]) % mod;
  int x, y, z;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &x, &y, &z);
    if (x == 1)
      update(1, 1, n, y, z);
    else {
      _sum = 0;
      query(1, 1, n, y, z, 0, 0);
      _sum = (_sum + (sum[z] - sum[y - 1] + mod) % mod) % mod;
      printf("%d\n", _sum);
    }
  }
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Bizon the Champion isn't just attentive, he also is very hardworking.

Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as n vertical planks, put in a row. Adjacent planks have no gap between them. The planks are numbered from the left to the right starting from one, the i-th plank has the width of 1 meter and the height of ai meters.

Bizon the Champion bought a brush in the shop, the brush's width is 1 meter. He can make vertical and horizontal strokes with the brush. During a stroke the brush's full surface must touch the fence at all the time (see the samples for the better understanding). What minimum number of strokes should Bizon the Champion do to fully paint the fence? Note that you are allowed to paint the same area of the fence multiple times.

Input

The first line contains integer n (1 ≤ n ≤ 5000) — the number of fence planks. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print a single integer — the minimum number of strokes needed to paint the whole fence.

Examples

Input

5
2 2 1 2 1

Output

3

Input

2
2 2

Output

2

Input

1
5

Output

1

Note

In the first sample you need to paint the fence in three strokes with the brush: the first stroke goes on height 1 horizontally along all the planks. The second stroke goes on height 2 horizontally and paints the first and second planks and the third stroke (it can be horizontal and vertical) finishes painting the fourth plank.

In the second sample you can paint the fence with two strokes, either two horizontal or two vertical strokes.

In the third sample there is only one plank that can be painted using a single vertical stroke.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using namespace std::placeholders;
int a[5000];
int solve(int l, int r) {
  if (l == r) return 0;
  int vert = (r - l);
  int mini = *min_element(a + l, a + r);
  transform(a + l, a + r, a + l, bind(minus<int>(), _1, mini));
  long long hori = mini;
  while (l != r) {
    int *p1 = find_if(a + l, a + r, bind(not_equal_to<int>(), _1, 0));
    if (p1 == a + r) break;
    int *p2 = find(p1, a + r, 0);
    hori += solve(p1 - a, p2 - a);
    l = p2 - a;
  }
  return min((long long)vert, hori);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  printf("%d\n", solve(0, n));
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Many of you must be familiar with the Google Code Jam round rules. Let us remind you of some key moments that are crucial to solving this problem. During the round, the participants are suggested to solve several problems, each divided into two subproblems: an easy one with small limits (Small input), and a hard one with large limits (Large input). You can submit a solution for Large input only after you've solved the Small input for this problem. There are no other restrictions on the order of solving inputs. In particular, the participant can first solve the Small input, then switch to another problem, and then return to the Large input. Solving each input gives the participant some number of points (usually different for each problem). This takes into account only complete solutions that work correctly on all tests of the input. The participant gets the test result of a Small input right after he submits it, but the test result of a Large input are out only after the round's over. In the final results table the participants are sorted by non-increasing of received points. If the points are equal, the participants are sorted by ascending of time penalty. By the Google Code Jam rules the time penalty is the time when the last correct solution was submitted.

Vasya decided to check out a new tactics on another round. As soon as the round begins, the boy quickly read all the problems and accurately evaluated the time it takes to solve them. Specifically, for each one of the n problems Vasya knows five values:

  * Solving the Small input of the i-th problem gives to the participant scoreSmalli points, and solving the Large input gives scoreLargei more points. That is, the maximum number of points you can get for the i-th problem equals scoreSmalli + scoreLargei.
  * Writing the solution for the Small input of the i-th problem takes exactly timeSmalli minutes for Vasya. Improving this code and turning it into the solution of the Large input takes another timeLargei minutes.
  * Vasya's had much practice, so he solves all Small inputs from the first attempt. But it's not so easy with the Large input: there is the probFaili probability that the solution to the Large input will turn out to be wrong at the end of the round. Please keep in mind that these solutions do not affect the participants' points and the time penalty.

A round lasts for t minutes. The time for reading problems and submitting solutions can be considered to equal zero. Vasya is allowed to submit a solution exactly at the moment when the round ends.

Vasya wants to choose a set of inputs and the order of their solution so as to make the expectation of the total received points maximum possible. If there are multiple ways to do this, he needs to minimize the expectation of the time penalty. Help Vasya to cope with this problem.

Input

The first line contains two integers n and t (1 ≤ n ≤ 1000, 1 ≤ t ≤ 1560). Then follow n lines, each containing 5 numbers: scoreSmalli, scoreLargei, timeSmalli, timeLargei, probFaili (1 ≤ scoreSmalli, scoreLargei ≤ 109, 1 ≤ timeSmalli, timeLargei ≤ 1560, 0 ≤ probFaili ≤ 1).

probFaili are real numbers, given with at most 6 digits after the decimal point. All other numbers in the input are integers.

Output

Print two real numbers — the maximum expectation of the total points and the corresponding minimum possible time penalty expectation. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 9.

Examples

Input

3 40
10 20 15 4 0.5
4 100 21 1 0.99
1 4 1 1 0.25

Output

24.0 18.875

Input

1 1
100000000 200000000 1 1 0

Output

100000000 1

Note

In the first sample one of the optimal orders of solving problems is:

  1. The Small input of the third problem.
  2. The Small input of the first problem.
  3. The Large input of the third problem.
  4. The Large input of the first problem.

Note that if you solve the Small input of the second problem instead of two inputs of the third one, then total score expectation will be the same but the time penalty expectation will be worse (38).

### Response

```cpp
#include <bits/stdc++.h>
const int MAXN = 1005;
const int MAXT = 1565;
const int MUL = 1000000;
const double EPS = 1e-11;
struct prob {
  int s1, s2, t1, t2, pf;
  friend bool operator<(const prob &x, const prob &y) {
    return (long long)x.pf * x.t2 * (MUL - y.pf) <
           (long long)y.pf * y.t2 * (MUL - x.pf);
  }
};
struct data {
  long long sc;
  double t;
  data() {}
  data(long long sc, double t) : sc(sc), t(t) {}
  friend bool operator<(const data &x, const data &y) {
    return x.sc < y.sc || (x.sc == y.sc && x.t > y.t + EPS);
  }
};
int n, t;
prob a[MAXN];
data f[MAXT];
void init() {
  scanf("%d%d", &n, &t);
  for (int i = 0; i < n; ++i) {
    double pf;
    scanf("%d%d%d%d%lf", &a[i].s1, &a[i].s2, &a[i].t1, &a[i].t2, &pf);
    a[i].pf = (int)(pf * MUL + 0.5);
  }
  std::sort(a, a + n);
}
void solve() {
  data tmp;
  for (int i = 0; i < n; ++i)
    for (int j = t - 1; j >= 0; --j) {
      tmp = f[j];
      if (j + a[i].t1 <= t) {
        tmp = data(tmp.sc + (long long)MUL * a[i].s1, tmp.t + a[i].t1);
        if (f[j + a[i].t1] < tmp) f[j + a[i].t1] = tmp;
      }
      if (j + a[i].t1 + a[i].t2 <= t) {
        tmp = data(tmp.sc + (long long)(MUL - a[i].pf) * a[i].s2,
                   (double)a[i].pf / MUL * tmp.t +
                       (double)(MUL - a[i].pf) / MUL * (j + a[i].t1 + a[i].t2));
        if (f[j + a[i].t1 + a[i].t2] < tmp) f[j + a[i].t1 + a[i].t2] = tmp;
      }
    }
  int u = 0;
  for (int i = 1; i <= t; ++i)
    if (f[u] < f[i]) u = i;
  printf("%.10f %.10f\n", (double)f[u].sc / MUL, f[u].t);
}
int main() {
  init();
  solve();
  return 0;
}

```