### Prompt

Develop a solution in CPP to the problem described below:

In this problem you will need to deal with an n × m grid graph. The graph's vertices are the nodes of the n × m grid. The graph's edges are all the sides and diagonals of the grid's unit squares.

The figure below shows a 3 × 5 graph. The black lines are the graph's edges, the colored circles are the graph's vertices. The vertices of the graph are painted on the picture for a reason: the coloring is a correct vertex coloring of the 3 × 5 graph into four colors. A graph coloring is correct if and only if each vertex is painted and no two vertices connected by an edge are painted the same color.

<image>

You are given the size of the grid graph n × m and the colors of some of its vertices. Find any way how to paint the unpainted vertices of the graph in 4 colors to make the final coloring a correct vertex graph coloring. If there is no such correct vertex coloring, say that the answer doesn't exist.

Input

The first line contains two integers n and m (2 ≤ n, m ≤ 1000). Each of the next n lines consists of m characters — the given graph. Each character is either «0», «1», «2», «3», «4». Character «0» means that the corresponding vertex is unpainted, otherwise the character means the color of the vertex.

Assume that all the available colors are numbered from 1 to 4.

Output

If there is no way to get correct vertex coloring of the graph, print 0 in a single line. Otherwise print the colored n × m graph. Print the graph in the same format as in the input.

If multiple answers exist, print any of them.

Examples

Input

3 5
10101
00020
01000

Output

13131
42424
31313

Input

2 2
00
00

Output

12
34

Input

2 2
11
00

Output

0

Note

The answer to the first sample is shown on the picture (1 — green color, 2 — blue, 3 — dark blue, 4 — pink).

In the second sample there exists 4! answers, each of them is considered correct.

In the third sample two vertices with equal colors are connected. So the correct vertex coloring couldn't be obtained.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[1111][1111], r[1111][1111];
char b[11];
void result() {
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) printf("%c", r[i][j]);
    puts("");
  }
}
bool process1() {
  int cd1 = 0, cd2 = 1;
  for (int i = 1; i <= n; ++i) {
    cd2 = 1;
    for (int j = 1; j <= m; ++j) r[i][j] = b[cd1 + cd2], cd2 = 3 - cd2;
    bool check = 0;
    for (int j = 1; j <= m; ++j)
      if (s[i][j] != '0' && s[i][j] != r[i][j]) {
        check = 1;
        break;
      }
    if (!check) {
      cd1 = 2 - cd1;
      continue;
    }
    cd2 = 2;
    for (int j = 1; j <= m; ++j) r[i][j] = b[cd1 + cd2], cd2 = 3 - cd2;
    check = 0;
    for (int j = 1; j <= m; ++j)
      if (s[i][j] != '0' && s[i][j] != r[i][j]) {
        check = 1;
        break;
      }
    if (check) return 0;
    cd1 = 2 - cd1;
  }
  return 1;
}
bool process2() {
  int cd1 = 0, cd2 = 1;
  for (int j = 1; j <= m; ++j) {
    cd2 = 1;
    for (int i = 1; i <= n; ++i) r[i][j] = b[cd1 + cd2], cd2 = 3 - cd2;
    bool check = 0;
    for (int i = 1; i <= n; ++i)
      if (s[i][j] != '0' && s[i][j] != r[i][j]) {
        check = 1;
        break;
      }
    if (!check) {
      cd1 = 2 - cd1;
      continue;
    }
    cd2 = 2;
    for (int i = 1; i <= n; ++i) r[i][j] = b[cd1 + cd2], cd2 = 3 - cd2;
    check = 0;
    for (int i = 1; i <= n; ++i)
      if (s[i][j] != '0' && s[i][j] != r[i][j]) {
        check = 1;
        break;
      }
    if (check) return 0;
    cd1 = 2 - cd1;
  }
  return 1;
}
int main() {
  scanf("%d%d\n", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%s\n", s[i] + 1);
  }
  for (int i = 1; i < 5; ++i) b[i] = '0' + i;
  do {
    if (process1()) {
      result();
      return 0;
    }
    if (process2()) {
      result();
      return 0;
    }
  } while (next_permutation(b + 1, b + 5));
  cout << '0' << '\n';
  return 0;
}

```


### Prompt

Construct a Cpp code solution to the problem outlined:

Berland has n cities, the capital is located in city s, and the historic home town of the President is in city t (s ≠ t). The cities are connected by one-way roads, the travel time for each of the road is a positive integer.

Once a year the President visited his historic home town t, for which his motorcade passes along some path from s to t (he always returns on a personal plane). Since the president is a very busy man, he always chooses the path from s to t, along which he will travel the fastest.

The ministry of Roads and Railways wants to learn for each of the road: whether the President will definitely pass through it during his travels, and if not, whether it is possible to repair it so that it would definitely be included in the shortest path from the capital to the historic home town of the President. Obviously, the road can not be repaired so that the travel time on it was less than one. The ministry of Berland, like any other, is interested in maintaining the budget, so it wants to know the minimum cost of repairing the road. Also, it is very fond of accuracy, so it repairs the roads so that the travel time on them is always a positive integer.

Input

The first lines contain four integers n, m, s and t (2 ≤ n ≤ 105; 1 ≤ m ≤ 105; 1 ≤ s, t ≤ n) — the number of cities and roads in Berland, the numbers of the capital and of the Presidents' home town (s ≠ t).

Next m lines contain the roads. Each road is given as a group of three integers ai, bi, li (1 ≤ ai, bi ≤ n; ai ≠ bi; 1 ≤ li ≤ 106) — the cities that are connected by the i-th road and the time needed to ride along it. The road is directed from city ai to city bi.

The cities are numbered from 1 to n. Each pair of cities can have multiple roads between them. It is guaranteed that there is a path from s to t along the roads.

Output

Print m lines. The i-th line should contain information about the i-th road (the roads are numbered in the order of appearance in the input).

If the president will definitely ride along it during his travels, the line must contain a single word "YES" (without the quotes).

Otherwise, if the i-th road can be repaired so that the travel time on it remains positive and then president will definitely ride along it, print space-separated word "CAN" (without the quotes), and the minimum cost of repairing.

If we can't make the road be such that president will definitely ride along it, print "NO" (without the quotes).

Examples

Input

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

Output

YES
CAN 2
CAN 1
CAN 1
CAN 1
CAN 1
YES

Input

3 3 1 3
1 2 10
2 3 10
1 3 100

Output

YES
YES
CAN 81

Input

2 2 1 2
1 2 1
1 2 2

Output

YES
NO

Note

The cost of repairing the road is the difference between the time needed to ride along it before and after the repairing.

In the first sample president initially may choose one of the two following ways for a ride: 1 → 2 → 4 → 5 → 6 or 1 → 2 → 3 → 5 → 6.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int inf = 2e18;
vector<pair<pair<int, int>, long long int> > e;
vector<pair<int, long long int> > g[200005], ng[200005], rg[200005];
long long int s[200005], d[200005];
int vs[200005];
int ans[100005];
int in[200005], p[200005], t = 0, m[100005];
int dfs(int u) {
  vs[u] = 1;
  in[u] = t++;
  int dbe = in[u];
  for (int i = 0; i < (int)(ng[u].size()); i++) {
    int w = ng[u][i].first, index = ng[u][i].second;
    if (!vs[w]) {
      ans[index] = 1;
      m[index] = 1;
      p[w] = u;
      int be = dfs(w);
      if (be == in[w]) {
        ;
        ans[index] = 2;
      } else
        dbe = min(dbe, be);
    } else if (!m[index]) {
      ans[index] = 1;
      dbe = min(dbe, in[w]);
    }
  }
  return dbe;
}
int main() {
  int n, m, start, finish, a, b;
  long long int c;
  scanf("%d", &n);
  scanf("%d", &m);
  scanf("%d", &start);
  scanf("%d", &finish);
  for (int i = 0; i < m; i++) {
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%lld", &c);
    g[a].push_back(make_pair(b, c));
    rg[b].push_back(make_pair(a, c));
    e.push_back(make_pair(make_pair(a, b), c));
  }
  set<pair<long long int, int> > q;
  for (int i = 1; i <= n; i++) {
    s[i] = inf;
    vs[i] = 0;
  }
  s[start] = 0;
  q.insert(make_pair(s[start], start));
  while (!q.empty()) {
    int u = (*q.begin()).second;
    q.erase(q.begin());
    vs[u] = 1;
    for (int i = 0; i < (int)(g[u].size()); i++) {
      int w = g[u][i].first;
      long long int edge = g[u][i].second;
      if (s[u] + edge < s[w]) {
        s[w] = s[u] + edge;
        q.insert(make_pair(s[w], w));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    d[i] = inf;
    vs[i] = 0;
  }
  d[finish] = 0;
  q.insert(make_pair(d[finish], finish));
  while (!q.empty()) {
    int u = (*q.begin()).second;
    q.erase(q.begin());
    vs[u] = 1;
    for (int i = 0; i < (int)(rg[u].size()); i++) {
      int w = rg[u][i].first;
      long long int edge = rg[u][i].second;
      if (d[u] + edge < d[w]) {
        d[w] = d[u] + edge;
        q.insert(make_pair(d[w], w));
      }
    }
  }
  for (int i = 0; i < (int)(e.size()); i++) {
    a = e[i].first.first, b = e[i].first.second, c = e[i].second;
    if (s[a] + c + d[b] == s[finish]) {
      ng[a].push_back(make_pair(b, i));
      ng[b].push_back(make_pair(a, i));
      ;
    }
  }
  memset(vs, 0, sizeof(vs));
  dfs(start);
  for (int i = 0; i < (int)(e.size()); i++) {
    if (ans[i] == 2)
      cout << "YES" << endl;
    else {
      a = e[i].first.first, b = e[i].first.second, c = e[i].second;
      if (s[a] == inf || d[b] == inf) {
        cout << "NO" << endl;
        continue;
      }
      int nw = s[finish] - s[a] - d[b] - 1;
      ;
      if (nw > 0)
        cout << "CAN " << c - nw << endl;
      else
        cout << "NO" << endl;
    }
  }
  return 0;
}

```


### Prompt

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

Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.

However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0, 1, 0, 1}, {1, 0, 1}, and {1, 0, 1, 0} are alternating sequences, while {1, 0, 0} and {0, 1, 0, 1, 1} are not.

Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.

Input

The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000).

The following line contains a binary string of length n representing Kevin's results on the USAICO.

Output

Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.

Examples

Input

8
10000011

Output

5

Input

2
01

Output

2

Note

In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.

In the second sample, Kevin can flip the entire string and still have the same score.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 5;
int n;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  stack<int> st;
  int id = 0;
  for (int i = 0; i < n; i++) {
    if (st.size() == 0 || st.top() != s[i]) {
      st.push(s[i]);
    } else {
      if (id < 2) {
        id++;
        st.push(s[i]);
      }
    }
  }
  ans += st.size();
  cout << ans;
}

```


### Prompt

Generate a cpp solution to the following problem:

Let f(x) be the sum of digits of a decimal number x.

Find the smallest non-negative integer x such that f(x) + f(x + 1) + ... + f(x + k) = n.

Input

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

Each test case consists of one line containing two integers n and k (1 ≤ n ≤ 150, 0 ≤ k ≤ 9).

Output

For each test case, print one integer without leading zeroes. If there is no such x that f(x) + f(x + 1) + ... + f(x + k) = n, print -1; otherwise, print the minimum x meeting that constraint.

Example

Input

7
1 0
1 1
42 7
13 7
99 1
99 0
99 2

Output

1
0
4
-1
599998
99999999999
7997

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int ds(int x) {
  int res = 0;
  while (x) {
    res += x % 10;
    x /= 10;
  }
  return res;
}
int main(int argc, char** argv) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(15);
  if (argc == 2 && atoi(argv[1]) == 123456789)
    freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
  int T;
  cin >> T;
  for (int(t) = 0; (t) < (T); (t)++) {
    int n, k;
    cin >> n >> k;
    string ans = string(n + 1, '9');
    for (int(a) = 0; (a) < (100); (a)++) {
      int s = 0;
      for (int(x) = 0; (x) < (k + 1); (x)++) s += ds(a + x);
      string str = to_string(a);
      if (s == n)
        if (str.length() < ans.length() ||
            str.length() == ans.length() && str < ans)
          ans = str;
    }
    for (int(a) = 0; (a) < (10); (a)++) {
      for (int(tt) = 0; (tt) < ((n + 8) / 9); (tt)++) {
        for (int(c) = 0; (c) < (10); (c)++) {
          int s = 0;
          for (int(x) = 0; (x) < (k + 1); (x)++) {
            if (x + c < 10)
              s += a + tt * 9 + c + x;
            else
              s += ds(a + 1) + c + x - 10;
          }
          if (s == n) {
            string str =
                string(1, a + '0') + string(tt, '9') + string(1, c + '0');
            if (str.length() < ans.length() ||
                str.length() == ans.length() && str < ans)
              ans = str;
          }
        }
        for (int c = 10; c < 100; c++) {
          int s = 0;
          for (int(x) = 0; (x) < (k + 1); (x)++) {
            if (x + c < 100)
              s += a + tt * 9 + ds(c + x);
            else
              s += ds(a + 1) + ds(c + x - 100);
          }
          if (s == n) {
            string str = string(1, a + '0') + string(tt, '9') + to_string(c);
            if (str.length() < ans.length() ||
                str.length() == ans.length() && str < ans)
              ans = str;
          }
        }
      }
    }
    if (ans[0] == '0' && ans.length() > 1) ans = ans.substr(1);
    if (ans.length() == n + 1)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  if (argc == 2 && atoi(argv[1]) == 123456789)
    cout << clock() * 1.0 / CLOCKS_PER_SEC << " sec\n";
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Polycarp found n segments on the street. A segment with the index i is described by two integers l_i and r_i — coordinates of the beginning and end of the segment, respectively. Polycarp realized that he didn't need all the segments, so he wanted to delete some of them.

Polycarp believes that a set of k segments is good if there is a segment [l_i, r_i] (1 ≤ i ≤ k) from the set, such that it intersects every segment from the set (the intersection must be a point or segment). For example, a set of 3 segments [[1, 4], [2, 3], [3, 6]] is good, since the segment [2, 3] intersects each segment from the set. Set of 4 segments [[1, 2], [2, 3], [3, 5], [4, 5]] is not good.

Polycarp wonders, what is the minimum number of segments he has to delete so that the remaining segments form a good set?

Input

The first line contains a single integer t (1 ≤ t ≤ 2 ⋅ 10^5) — number of test cases. Then t test cases follow.

The first line of each test case contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments. This is followed by n lines describing the segments.

Each segment is described by two integers l and r (1 ≤ l ≤ r ≤ 10^9) — coordinates of the beginning and end of the segment, respectively.

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

Output

For each test case, output a single integer — the minimum number of segments that need to be deleted in order for the set of remaining segments to become good.

Example

Input

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

Output

0
1
2
0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll  long long
#define int long long
#define ld  long double
#define endl "\n"
#define pb  push_back
#define fill(a,val) memset(a,val,sizeof(a))
#define ff  first
#define ss  second
#define test  ll t; cin>>t; while(t--)
#define loop(i,a,b)  for(ll i=a;i<b;i++)
#define loopr(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod     = 1000*1000*1000+7;
const ll inf     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll mod2    = 998244353;
const ll N       = 1000 + 10;
const ld pi      = 3.141592653589793;
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

void solve(){
    ll n;
    cin>>n;
    pii p[n];
    ll l[n],r[n];
    loop(i,0,n){
        cin>>p[i].ff>>p[i].ss;
        l[i]=p[i].ff;
        r[i]=p[i].ss;
    }
    sort(l,l+n);
    sort(r,r+n);
    ll ans=LLONG_MAX;
    for(ll i=0;i<n;i++){
        ll cnt=0;
        // for(ll j=0;j<n;j++){
        //     if(p[j].ff>r || p[j].ss<l){
        //         continue;
        //     }
        //     cnt++;
        // }
        auto it=upper_bound(l,l+n,p[i].ss)-l;
        cnt+=n-it;
        auto it2=lower_bound(r,r+n,p[i].ff)-r;
        cnt+=it2;
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
    return;
}
signed main(){
    fastio();
    test{

        solve();

    }
    return 0;
}
```


### Prompt

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

Vasya plays the Need For Brake. He plays because he was presented with a new computer wheel for birthday! Now he is sure that he will win the first place in the championship in his favourite racing computer game!

n racers take part in the championship, which consists of a number of races. After each race racers are arranged from place first to n-th (no two racers share the same place) and first m places are awarded. Racer gains bi points for i-th awarded place, which are added to total points, obtained by him for previous races. It is known that current summary score of racer i is ai points. In the final standings of championship all the racers will be sorted in descending order of points. Racers with an equal amount of points are sorted by increasing of the name in lexicographical order.

Unfortunately, the championship has come to an end, and there is only one race left. Vasya decided to find out what the highest and lowest place he can take up as a result of the championship.

Input

The first line contains number n (1 ≤ n ≤ 105) — number of racers. Each of the next n lines contains si and ai — nick of the racer (nonempty string, which consist of no more than 20 lowercase Latin letters) and the racer's points (0 ≤ ai ≤ 106). Racers are given in the arbitrary order.

The next line contains the number m (0 ≤ m ≤ n). Then m nonnegative integer numbers bi follow. i-th number is equal to amount of points for the i-th awarded place (0 ≤ bi ≤ 106).

The last line contains Vasya's racer nick.

Output

Output two numbers — the highest and the lowest place Vasya can take up as a result of the championship.

Examples

Input

3
teama 10
teamb 20
teamc 40
2
10 20
teama

Output

2 3

Input

2
teama 10
teamb 10
2
10 10
teamb

Output

2 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100010;
string nick[MAX];
int ara[MAX], ord[MAX], b[MAX];
int save[MAX];
bool cmp(int a, int b) {
  if (ara[a] == ara[b]) return nick[a] < nick[b];
  return ara[a] > ara[b];
}
deque<int> D;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n;
  if (n == 0) {
    cout << 0 << " " << 0 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    cin >> nick[i] >> ara[i];
    save[i] = ara[i];
  }
  cin >> m;
  for (int i = 1; i <= m; i++) cin >> b[i], D.push_back(b[i]);
  sort(D.begin(), D.end());
  string s;
  cin >> s;
  int id = -1;
  for (int i = 1; i <= n; i++) {
    if (s == nick[i]) {
      if (id == -1)
        id = i;
      else
        assert(false);
    }
  }
  for (int i = 1; i <= n; i++) ord[i] = i;
  sort(ord + 1, ord + n + 1, cmp);
  int ans1, ans2;
  if (m == 0) {
    for (int i = 1; i <= n; i++)
      if (ord[i] == id) {
        ans2 = ans1 = i;
        break;
      }
    cout << ans1 << " " << ans2 << endl;
    return 0;
  }
  int cur;
  for (int i = 1; i <= n; i++)
    if (ord[i] == id) cur = i;
  if (n == m) {
    ara[id] += D.front();
    D.pop_front();
  }
  int parbo = n - cur;
  int bad = D.size() - parbo;
  for (int i = cur - 1; i >= 1 and bad > 0; i--, bad--) {
    ara[ord[i]] += D.front();
    D.pop_front();
  }
  int need;
  for (int i = cur + 1; i <= n; i++) {
    need = (ara[id] + 1) - ara[ord[i]];
    int paic = 0;
    while (D.size() > 0) {
      if (D.front() >= need) {
        paic = D.front();
        D.pop_front();
        break;
      } else
        D.pop_front();
    }
    ara[ord[i]] += paic;
  }
  sort(ord + 1, ord + n + 1, cmp);
  for (int i = 1; i <= n; i++)
    if (ord[i] == id) ans2 = i;
  for (int i = 1; i <= n; i++) ara[i] = save[i];
  D.clear();
  for (int i = 1; i <= m; i++) D.push_back(b[i]);
  sort(D.begin(), D.end());
  ara[id] += D.back();
  D.pop_back();
  sort(ord + 1, ord + n + 1, cmp);
  for (int i = n; i >= 1 and D.size() > 0; i--) {
    if (ord[i] == id) continue;
    ara[ord[i]] += D.back();
    D.pop_back();
  }
  sort(ord + 1, ord + n + 1, cmp);
  for (int i = 1; i <= n; i++)
    if (ord[i] == id) ans1 = i;
  cout << ans1 << " " << ans2 << endl;
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.

Input

The single line of the input contains a pair of integers m, s (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers.

Output

In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).

Examples

Input

2 15

Output

69 96

Input

3 0

Output

-1 -1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s;
  cin >> n >> s;
  if ((n > 1 && s == 0) || (s > 9 * n))
    cout << "-1"
         << " "
         << "-1" << endl;
  else if (n == 1 && s == 0)
    cout << '0' << " " << '0';
  else {
    string str = "", r = "", t = "";
    int x = s / 9;
    int y = s % 9;
    for (int i = 0; i < x; i++) {
      str += '9';
    }
    if (x < n) {
      str += char(y + 48);
      for (int i = x + 1; i < n; i++) str += '0';
    }
    for (int i = 0; i < x; i++) {
      r += '9';
    }
    if (x < n) {
      r += char(y + 48);
      for (int i = x + 1; i < n; i++) {
        r += '0';
      }
    }
    if (r[n - 1] == '0') {
      if (r[x] == '0') {
        r[x - 1] = '8';
        r[n - 1] = '1';
      } else {
        r[x] = char((y - 1) + 48);
        r[n - 1] = '1';
      }
    }
    reverse(r.begin(), r.end());
    cout << r << " " << str;
  }
}

```


### Prompt

Please create a solution in CPP to the following problem:

There is a programing contest named SnakeUp, 2n people want to compete for it. In order to attend this contest, people need to form teams of exactly two people. You are given the strength of each possible combination of two people. All the values of the strengths are distinct.

Every contestant hopes that he can find a teammate so that their team’s strength is as high as possible. That is, a contestant will form a team with highest strength possible by choosing a teammate from ones who are willing to be a teammate with him/her. More formally, two people A and B may form a team if each of them is the best possible teammate (among the contestants that remain unpaired) for the other one.

Can you determine who will be each person’s teammate?

Input

There are 2n lines in the input.

The first line contains an integer n (1 ≤ n ≤ 400) — the number of teams to be formed.

The i-th line (i > 1) contains i - 1 numbers ai1, ai2, ... , ai(i - 1). Here aij (1 ≤ aij ≤ 106, all aij are distinct) denotes the strength of a team consisting of person i and person j (people are numbered starting from 1.)

Output

Output a line containing 2n numbers. The i-th number should represent the number of teammate of i-th person.

Examples

Input

2
6
1 2
3 4 5

Output

2 1 4 3

Input

3
487060
3831 161856
845957 794650 976977
83847 50566 691206 498447
698377 156232 59015 382455 626960

Output

6 5 4 3 2 1

Note

In the first sample, contestant 1 and 2 will be teammates and so do contestant 3 and 4, so the teammate of contestant 1, 2, 3, 4 will be 2, 1, 4, 3 respectively.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, pair<int, int>>> v;
int fri[1000];
bool taken[1000];
int main() {
  cin >> n;
  for (int i = 2; i <= 2 * n; i++) {
    for (int j = 1; j <= i - 1; j++) {
      int x;
      cin >> x;
      v.push_back({x, {i, j}});
    }
  }
  sort(v.rbegin(), v.rend());
  for (int i = 0; i < (int)v.size(); i++) {
    int p1 = v[i].second.first, p2 = v[i].second.second;
    if (!taken[p1] and !taken[p2]) {
      fri[p1] = p2;
      fri[p2] = p1;
      taken[p1] = taken[p2] = 1;
    }
  }
  for (int i = 1; i <= 2 * n; i++) cout << fri[i] << ' ';
}

```


### Prompt

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

Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank.

The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.)

Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?

Constraints

* 101 \le X \le 10^{18}
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

X

Output

Print the number of years it takes for Takahashi's balance to reach X yen or above for the first time.

Examples

Input

103

Output

3

Input

1000000000000000000

Output

3760

Input

1333333333

Output

1706

### Response

```cpp
#include<iostream>
using namespace std;
int main() {
  long X;
  cin >> X;
  int ans = 0;
  for (long x = 100; x < X; x += x / 100, ans++);
  cout << ans << endl;
}
```


### Prompt

Please create a solution in Cpp to the following problem:

You are given two integers a and b. Moreover, you are given a sequence s_0, s_1, ..., s_{n}. All values in s are integers 1 or -1. It's known that sequence is k-periodic and k divides n+1. In other words, for each k ≤ i ≤ n it's satisfied that s_{i} = s_{i - k}.

Find out the non-negative remainder of division of ∑ _{i=0}^{n} s_{i} a^{n - i} b^{i} by 10^{9} + 9.

Note that the modulo is unusual!

Input

The first line contains four integers n, a, b and k (1 ≤ n ≤ 10^{9}, 1 ≤ a, b ≤ 10^{9}, 1 ≤ k ≤ 10^{5}).

The second line contains a sequence of length k consisting of characters '+' and '-'.

If the i-th character (0-indexed) is '+', then s_{i} = 1, otherwise s_{i} = -1.

Note that only the first k members of the sequence are given, the rest can be obtained using the periodicity property.

Output

Output a single integer — value of given expression modulo 10^{9} + 9.

Examples

Input

2 2 3 3
+-+

Output

7

Input

4 1 5 1
-

Output

999999228

Note

In the first example:

(∑ _{i=0}^{n} s_{i} a^{n - i} b^{i}) = 2^{2} 3^{0} - 2^{1} 3^{1} + 2^{0} 3^{2} = 7

In the second example:

(∑ _{i=0}^{n} s_{i} a^{n - i} b^{i}) = -1^{4} 5^{0} - 1^{3} 5^{1} - 1^{2} 5^{2} - 1^{1} 5^{3} - 1^{0} 5^{4} = -781 ≡ 999999228 \pmod{10^{9} + 9}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int vv[65];
inline int ksm(int p, int k) {
  vv[0] = p;
  for (int i = 1; i <= 29; ++i)
    vv[i] = (long long)vv[i - 1] * vv[i - 1] % 1000000009;
  int s = 1;
  for (int i = 29; i >= 0; --i) {
    if (1 << i <= k) {
      k -= 1 << i;
      s = (long long)s * vv[i] % 1000000009;
    }
  }
  return s;
}
long long ll, a_, b_, s, l, ans, q, n, a, b, k;
char ss[1000050];
long long aa[1000050];
inline void upt(long long &a, long long b) { a = (a + b) % 1000000009; }
int main() {
  scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
  scanf("%s", ss + 1);
  for (int i = 1; i <= k; ++i)
    if (ss[i] == '+')
      aa[i - 1] = 1;
    else
      aa[i - 1] = 1000000009 - 1;
  for (int i = 0; i < k; ++i)
    upt(s, aa[i] * ksm(a, n - i) % 1000000009 * ksm(b, i) % 1000000009);
  a_ = ksm(a, k);
  b_ = ksm(b, k);
  q = b_ * ksm(a_, 1000000009 - 2) % 1000000009;
  if (q == 1) {
    l = (n + 1) / k;
    s = s * l % 1000000009;
    cout << s;
    return 0;
  }
  l = (n + 1) / k;
  ans = (ksm(q, l) + 1000000009 - 1) % 1000000009;
  ans = ans * ksm(q + 1000000009 - 1, 1000000009 - 2) % 1000000009;
  ans = ans * s % 1000000009;
  cout << ans;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

Fox Ciel has a board with n rows and n columns, there is one integer in each cell.

It's known that n is an odd number, so let's introduce <image>. Fox Ciel can do the following operation many times: she choose a sub-board with size x rows and x columns, then all numbers in it will be multiplied by -1.

Return the maximal sum of numbers in the board that she can get by these operations.

Input

The first line contains an integer n, (1 ≤ n ≤ 33, and n is an odd integer) — the size of the board.

Each of the next n lines contains n integers — the numbers in the board. Each number doesn't exceed 1000 by its absolute value.

Output

Output a single integer: the maximal sum of numbers in the board that can be accomplished.

Examples

Input

3
-1 -1 1
-1 1 -1
1 -1 -1

Output

9

Input

5
-2 0 0 0 -2
0 -2 0 -2 0
0 0 -2 0 0
0 -2 0 -2 0
-2 0 0 0 -2

Output

18

Note

In the first test, we can apply this operation twice: first on the top left 2 × 2 sub-board, then on the bottom right 2 × 2 sub-board. Then all numbers will become positive.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 35;
int a[N][N];
int m, n, x, X;
int best;
int up(int x, int y) {
  x = x ^ y;
  return x == 0 ? 1 : -1;
}
int bit(int p, int v) { return (p >> v) & 1; }
void check(int p) {
  int ans = 0;
  int tmp0, tmp1;
  int tmp00, tmp01, tmp10, tmp11;
  int c00, c01, c10, c11;
  int r0, r1;
  for (int i = 0; i < x; ++i)
    if (bit(p, i))
      ans += -a[i][m];
    else
      ans += a[i][m];
  for (int i = x; i < n; ++i) ans += a[i][m] * up(bit(p, i - x), bit(p, m));
  c00 = up(0, 0);
  c01 = up(0, 1);
  c10 = up(1, 0);
  c11 = up(1, 1);
  for (int c = 0; c < m; ++c) {
    tmp0 = a[m][c] + up(0, bit(p, m)) * a[m][c + x];
    tmp1 = -a[m][c] + up(1, bit(p, m)) * a[m][c + x];
    for (int r = 0; r < m; ++r) {
      r0 = up(0, bit(p, r));
      r1 = up(1, bit(p, r));
      tmp00 = a[r][c] + r0 * a[r][c + x] + c00 * a[r + x][c] +
              a[r + x][c + x] * up(0 ^ bit(p, m), 0 ^ bit(p, r));
      tmp10 = -a[r][c] + r1 * a[r][c + x] + c10 * a[r + x][c] +
              a[r + x][c + x] * up(0 ^ bit(p, m), 1 ^ bit(p, r));
      tmp01 = a[r][c] + r0 * a[r][c + x] + c01 * a[r + x][c] +
              a[r + x][c + x] * up(1 ^ bit(p, m), 0 ^ bit(p, r));
      tmp11 = -a[r][c] + r1 * a[r][c + x] + c11 * a[r + x][c] +
              a[r + x][c + x] * up(1 ^ bit(p, m), 1 ^ bit(p, r));
      tmp0 += max(tmp00, tmp10);
      tmp1 += max(tmp01, tmp11);
    }
    ans += max(tmp0, tmp1);
  }
  best = max(best, ans);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) cin >> a[i][j];
  x = (n + 1) / 2;
  m = x - 1;
  best = -(int)1e9;
  X = 1 << x;
  for (int mask = 0; mask < X; ++mask) check(mask);
  cout << best << endl;
}

```


### Prompt

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

Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parallel to one of the coordinate axes, which connects the edges of the bar. More formally, each break goes along the line x = xc or y = yc, where xc and yc are integers. It should divide one part of the bar into two non-empty parts. After Bob breaks some part into two parts, he breaks the resulting parts separately and independently from each other. Also he doesn't move the parts of the bar. Bob made n breaks and wrote them down in his notebook in arbitrary order. At the end he got n + 1 parts. Now he wants to calculate their areas. Bob is lazy, so he asks you to do this task.

Input

The first line contains 3 integers W, H and n (1 ≤ W, H, n ≤ 100) — width of the bar, height of the bar and amount of breaks. Each of the following n lines contains four integers xi, 1, yi, 1, xi, 2, yi, 2 — coordinates of the endpoints of the i-th break (0 ≤ xi, 1 ≤ xi, 2 ≤ W, 0 ≤ yi, 1 ≤ yi, 2 ≤ H, or xi, 1 = xi, 2, or yi, 1 = yi, 2). Breaks are given in arbitrary order.

It is guaranteed that the set of breaks is correct, i.e. there is some order of the given breaks that each next break divides exactly one part of the bar into two non-empty parts.

Output

Output n + 1 numbers — areas of the resulting parts in the increasing order.

Examples

Input

2 2 2
1 0 1 2
0 1 1 1

Output

1 1 2

Input

2 2 3
1 0 1 2
0 1 1 1
1 1 2 1

Output

1 1 1 1

Input

2 4 2
0 1 2 1
0 3 2 3

Output

2 2 4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int w, h, num;
int x[4] = {-1, 0, 1, 0};
int y[4] = {0, 1, 0, -1};
bool visit[105][105] = {0}, g[105][105][4];
vector<int> ans;
void dfs(int n, int m) {
  if (n < 0 || n >= w || m < 0 || m >= h || visit[n][m]) return;
  visit[n][m] = 1;
  num++;
  for (int i = 0; i < 4; i++)
    if (g[n][m][i]) dfs(n + x[i], m + y[i]);
}
int main(void) {
  memset(g, true, sizeof(g));
  int n;
  cin >> w >> h >> n;
  for (int i = 0; i < n; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a == c)
      for (int i = b; i < d; i++) g[a][i][0] = g[a - 1][i][2] = 0;
    else
      for (int i = a; i < c; i++) g[i][b][3] = g[i][b - 1][1] = 0;
  }
  for (int i = 0; i < w; i++)
    for (int j = 0; j < h; j++)
      if (!visit[i][j]) {
        num = 0;
        dfs(i, j);
        ans.push_back(num);
      }
  sort(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << ' ';
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.

For a given number n, find the number of ordinary numbers among the numbers from 1 to n.

Input

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

Each test case is characterized by one integer n (1 ≤ n ≤ 10^9).

Output

For each test case output the number of ordinary numbers among numbers from 1 to n.

Example

Input

6
1
2
3
4
5
100

Output

1
2
3
4
5
18

### Response

```cpp
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
//#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n"
#define ll long long int
#define ld long double
#define ull unsigned long long
#define li long int
#define str string
#define fr(i,n) for(ll i = 0; i<n; i++)

int main() {

	fastio;
    int t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        if(n<10){
          cout<<n<<endl;
        }
        else{
        ll p=n;
        int count=0,a=0;
        while(p!=0){
          int rem=p%10;
          count++;
          if(p<10){
            a=rem;
           }
            p=p/10;
        }
        ll temp = 0;
        for(int i=0;i<count;i++){
           temp+=a*pow(10,i);
        }
        //cout<<temp<<endl;
        if(n>=temp){
          cout<<(9*(count-1) + a)<<endl;
        }
        else
          cout<<(9*(count-1) +a -1)<<endl;
        }

    }
	return 0;
}
```


### Prompt

Please create a solution in Cpp to the following problem:

We have sticks numbered 1, \cdots, N. The length of Stick i (1 \leq i \leq N) is L_i.

In how many ways can we choose three of the sticks with different lengths that can form a triangle?

That is, find the number of triples of integers (i, j, k) (1 \leq i < j < k \leq N) that satisfy both of the following conditions:

* L_i, L_j, and L_k are all different.
* There exists a triangle whose sides have lengths L_i, L_j, and L_k.

Constraints

* 1 \leq N \leq 100
* 1 \leq L_i \leq 10^9
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 \cdots L_N

Output

Print the number of ways to choose three of the sticks with different lengths that can form a triangle.

Examples

Input

5
4 4 9 7 5

Output

5

Input

6
4 5 4 3 3 5

Output

8

Input

10
9 4 6 1 9 6 10 6 6 8

Output

39

Input

2
1 1

Output

0

### Response

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

int main(){
  int n;
  cin>>n;
  vector<long> v(n);
  for(int i=0;i<n;i++) cin>>v[i];
  long cnt=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
        if(v[i]!=v[j]&&v[j]!=v[k]&&v[k]!=v[i]){
          long M=max(v[i],max(v[j],v[k]));
          if(v[i]+v[j]+v[k]>2*M) cnt++;
        }
      }
    }
  }
  cout<<cnt;
}

```


### Prompt

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

Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.

Note that the order of the points inside the group of three chosen points doesn't matter.

Input

The first line contains two integers: n and d (1 ≤ n ≤ 105; 1 ≤ d ≤ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 — the x-coordinates of the points that Petya has got.

It is guaranteed that the coordinates of the points in the input strictly increase.

Output

Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed d.

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

Examples

Input

4 3
1 2 3 4

Output

4

Input

4 2
-3 -2 -1 0

Output

2

Input

5 19
1 10 20 30 50

Output

1

Note

In the first sample any group of three points meets our conditions.

In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.

In the third sample only one group does: {1, 10, 20}.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e9 + 7;
const double pie = 3.14159265358979323846;
const char nl = '\n';
const char spc = ' ';
template <typename Type>
istream &operator>>(istream &in, vector<Type> &v) {
  long long int n = v.size();
  for (int i = 0; i < n; i++) in >> v[i];
  return in;
}
template <typename Type>
ostream &operator<<(ostream &out, vector<Type> &v) {
  for (auto value : v) out << value << ' ';
  out << nl;
  return out;
}
bool isPrime(long long int n) {
  if (n < 4) return true;
  if (n % 2 == 0) return false;
  long long int i = 3;
  while (i * i <= n) {
    if (n % i == 0) return false;
    i += 2;
  }
  return true;
}
void solve() {
  long long int n, d;
  cin >> n >> d;
  vector<long long int> a(n);
  cin >> a;
  long long int c = 0, l = 0;
  for (long long int r = 0; r < n; ++r) {
    while (a[r] - a[l] > d) ++l;
    long long int len = r - l;
    c += len * (len - 1) / 2;
  }
  cout << c << nl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

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

To your surprise, Jamie is the final boss! Ehehehe.

Jamie has given you a tree with n vertices, numbered from 1 to n. Initially, the root of the tree is the vertex with number 1. Also, each vertex has a value on it.

Jamie also gives you three types of queries on the tree:

1 v — Change the tree's root to vertex with number v.

2 u v x — For each vertex in the subtree of smallest size that contains u and v, add x to its value.

3 v — Find sum of values of vertices in the subtree of vertex with number v.

A subtree of vertex v is a set of vertices such that v lies on shortest path from this vertex to root of the tree. Pay attention that subtree of a vertex can change after changing the tree's root.

Show your strength in programming to Jamie by performing the queries accurately!

Input

The first line of input contains two space-separated integers n and q (1 ≤ n ≤ 105, 1 ≤ q ≤ 105) — the number of vertices in the tree and the number of queries to process respectively.

The second line contains n space-separated integers a1, a2, ..., an ( - 108 ≤ ai ≤ 108) — initial values of the vertices.

Next n - 1 lines contains two space-separated integers ui, vi (1 ≤ ui, vi ≤ n) describing edge between vertices ui and vi in the tree.

The following q lines describe the queries.

Each query has one of following formats depending on its type:

1 v (1 ≤ v ≤ n) for queries of the first type.

2 u v x (1 ≤ u, v ≤ n, - 108 ≤ x ≤ 108) for queries of the second type.

3 v (1 ≤ v ≤ n) for queries of the third type.

All numbers in queries' descriptions are integers.

The queries must be carried out in the given order. It is guaranteed that the tree is valid.

Output

For each query of the third type, output the required answer. It is guaranteed that at least one query of the third type is given by Jamie.

Examples

Input

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

Output

27
19
5

Input

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

Output

18
21

Note

The following picture shows how the tree varies after the queries in the first sample.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, q, opt, x, y, z, aa, bb, cc,
    cap = 1, cnt, tot, out, fh, a[100010], at[100010], h[100010], dep[100010],
    size[100010], dad[100010], son[100010], id[100010], top[100010],
    fa[100010][18];
char c;
struct Edge {
  int next, to;
} e[200010];
struct SegT {
  long long s, l;
} t[400010];
int read() {
  out = 0, fh = 1, c = getchar();
  while (c < 48 || c > 57) {
    if (c == 45) {
      fh = -1;
    }
    c = getchar();
  }
  while (c >= 48 && c <= 57) {
    out = (out << 3) + (out << 1) + (c & 15), c = getchar();
  }
  return out * fh;
}
void Add(int x, int y) { e[++cnt].next = h[x], e[cnt].to = y, h[x] = cnt; }
void DFS1(int x) {
  dep[x] = dep[dad[x]] + 1, size[x] = 1;
  for (int i = h[x]; i; i = e[i].next) {
    int y = e[i].to;
    if (y ^ dad[x]) {
      dad[y] = x, fa[y][0] = x;
      DFS1(y);
      size[x] += size[y];
      if (size[son[x]] < size[y]) {
        son[x] = y;
      }
    }
  }
}
void DFS2(int x) {
  id[x] = ++tot, at[tot] = a[x], top[x] = x == son[dad[x]] ? top[dad[x]] : x;
  for (int i = 1; i <= 17; ++i) {
    fa[x][i] = fa[fa[x][i - 1]][i - 1];
  }
  if (!son[x]) {
    return;
  }
  DFS2(son[x]);
  for (int i = h[x]; i; i = e[i].next) {
    int y = e[i].to;
    if (y ^ dad[x] && y ^ son[x]) {
      DFS2(y);
    }
  }
}
void DFS(int x) {
  DFS1(x);
  DFS2(x);
}
void Pushup(int k) { t[k].s = t[k << 1].s + t[k << 1 | 1].s; }
void Pushdown(int k, int l, int r) {
  if (!t[k].l) {
    return;
  }
  int mid = l + r >> 1;
  t[k << 1].l += t[k].l, t[k << 1 | 1].l += t[k].l,
      t[k << 1].s += t[k].l * (mid - l + 1),
      t[k << 1 | 1].s += t[k].l * (r - mid), t[k].l = 0;
}
void Build(int k, int l, int r) {
  if (l == r) {
    t[k].s = at[l];
    return;
  }
  int mid = l + r >> 1;
  Build(k << 1, l, mid);
  Build(k << 1 | 1, mid + 1, r);
  Pushup(k);
}
void Change(int k, int l, int r, int ll, int rr, long long x) {
  if (r < ll || rr < l) {
    return;
  }
  if (ll <= l && r <= rr) {
    t[k].s += x * (r - l + 1), t[k].l += x;
    return;
  }
  Pushdown(k, l, r);
  int mid = l + r >> 1;
  Change(k << 1, l, mid, ll, rr, x);
  Change(k << 1 | 1, mid + 1, r, ll, rr, x);
  Pushup(k);
}
long long Query(int k, int l, int r, int ll, int rr) {
  if (r < ll || rr < l) {
    return 0;
  }
  if (ll <= l && r <= rr) {
    return t[k].s;
  }
  Pushdown(k, l, r);
  int mid = l + r >> 1;
  return Query(k << 1, l, mid, ll, rr) + Query(k << 1 | 1, mid + 1, r, ll, rr);
}
int LCA(int x, int y) {
  while (top[x] ^ top[y]) {
    if (dep[top[x]] < dep[top[y]]) {
      x ^= y ^= x ^= y;
    }
    x = dad[top[x]];
  }
  return dep[x] > dep[y] ? y : x;
}
int Son(int x, int p) {
  for (int i = 0; i <= 17; ++i) {
    if (p & 1) {
      x = fa[x][i];
    }
    p >>= 1;
  }
  return x;
}
int main() {
  n = read(), q = read();
  for (int i = 1; i <= n; ++i) {
    a[i] = read();
  }
  for (int i = 1; i < n; ++i) {
    x = read(), y = read();
    Add(x, y);
    Add(y, x);
  }
  DFS(1);
  Build(1, 1, n);
  while (q--) {
    opt = read();
    if (opt == 1) {
      cap = read();
    }
    if (opt == 2) {
      x = read(), y = read(), z = read(), aa = LCA(x, y), bb = LCA(x, cap),
      cc = LCA(y, cap),
      x = dep[aa] > dep[bb]   ? dep[aa] > dep[cc] ? aa : cc
          : dep[bb] > dep[cc] ? bb
                              : cc;
      if (x == cap) {
        Change(1, 1, n, 1, n, z);
      } else {
        if (id[x] < id[cap] && id[x] + size[x] > id[cap]) {
          x = Son(cap, dep[cap] - dep[x] - 1);
          Change(1, 1, n, 1, id[x] - 1, z);
          Change(1, 1, n, id[x] + size[x], n, z);
        } else {
          Change(1, 1, n, id[x], id[x] + size[x] - 1, z);
        }
      }
    }
    if (opt == 3) {
      x = read();
      if (x == cap) {
        printf("%lld\n", t[1].s);
      } else {
        if (id[x] < id[cap] && id[x] + size[x] > id[cap]) {
          x = Son(cap, dep[cap] - dep[x] - 1);
          printf("%lld\n", t[1].s - Query(1, 1, n, id[x], id[x] + size[x] - 1));
        } else {
          printf("%lld\n", Query(1, 1, n, id[x], id[x] + size[x] - 1));
        }
      }
    }
  }
  return 0;
}

```


### Prompt

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

Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right.

Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the note to one of his neighbours in the row. In other words, if this spy's number is x, he can pass the note to another spy, either x - 1 or x + 1 (if x = 1 or x = n, then the spy has only one neighbour). Also during a step the spy can keep a note and not pass it to anyone.

But nothing is that easy. During m steps Xenia watches some spies attentively. Specifically, during step ti (steps are numbered from 1) Xenia watches spies numbers li, li + 1, li + 2, ..., ri (1 ≤ li ≤ ri ≤ n). Of course, if during some step a spy is watched, he can't do anything: neither give the note nor take it from some other spy. Otherwise, Xenia reveals the spies' cunning plot. Nevertheless, if the spy at the current step keeps the note, Xenia sees nothing suspicious even if she watches him.

You've got s and f. Also, you have the steps during which Xenia watches spies and which spies she is going to watch during each step. Find the best way the spies should act in order to pass the note from spy s to spy f as quickly as possible (in the minimum number of steps).

Input

The first line contains four integers n, m, s and f (1 ≤ n, m ≤ 105; 1 ≤ s, f ≤ n; s ≠ f; n ≥ 2). Each of the following m lines contains three integers ti, li, ri (1 ≤ ti ≤ 109, 1 ≤ li ≤ ri ≤ n). It is guaranteed that t1 < t2 < t3 < ... < tm.

Output

Print k characters in a line: the i-th character in the line must represent the spies' actions on step i. If on step i the spy with the note must pass the note to the spy with a lesser number, the i-th character should equal "L". If on step i the spy with the note must pass it to the spy with a larger number, the i-th character must equal "R". If the spy must keep the note at the i-th step, the i-th character must equal "X".

As a result of applying the printed sequence of actions spy s must pass the note to spy f. The number of printed characters k must be as small as possible. Xenia must not catch the spies passing the note.

If there are miltiple optimal solutions, you can print any of them. It is guaranteed that the answer exists.

Examples

Input

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

Output

XXRR

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int M = 110000;
int t[M], l[M], r[M];
char ans[2 * M];
int main() {
  int i;
  int n, m, s, f;
  scanf("%d %d %d %d", &n, &m, &s, &f);
  for (i = 0; i < m; i++) scanf("%d %d %d", &t[i], &l[i], &r[i]);
  int k = 0, cr = 0, ds;
  while (s != f) {
    if (s < f)
      ds = 1;
    else
      ds = -1;
    int fl = 1;
    if (t[cr] - 1 == k) {
      if ((l[cr] <= s + ds && r[cr] >= s + ds) || (l[cr] <= s && r[cr] >= s)) {
        fl = 0;
        ans[k] = 'X';
      }
      cr++;
    }
    if (fl) {
      if (ds < 0)
        ans[k] = 'L';
      else
        ans[k] = 'R';
      s += ds;
    }
    k++;
  }
  ans[k] = '\0';
  printf("%s\n", ans);
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

There are 2N points evenly spaced on the circumference of a circle. These points are numbered 1 to 2N in clockwise order, starting from some of them.

Snuke will divide these points into N pairs, then for each pair, he will draw a line segment connecting the two points. After the line segments are drawn, two points are connected when one can reach from one of those points to the other by traveling only on the line segments. The number of the connected parts here is the number of the connected components in the graph with 2N vertices, corresponding to the 2N points, where every pair of vertices corresponding to two connected points is connected with an edge.

Snuke has already decided K of the pairs, and the i-th of them is a pair of Point A_i and Point B_i.

He is thinking of trying all possible ways to make the remaining N-K pairs and counting the number of the connected parts for each of those ways. Find the sum of those numbers of the connected parts. As the answer can be extremely large, compute the sum modulo 10^9+7.

Constraints

* 1 \leq N \leq 300
* 0 \leq K \leq N
* 1 \leq A_i,B_i \leq 2N
* A_1,\ A_2,\ ...\ A_K,\ B_1,\ B_2,\ ...\ B_K are all distinct.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 B_1
A_2 B_2
:
A_K B_K

Output

Print the sum of the numbers of the connected parts for all possible ways to make the remaining N-K pairs.

Examples

Input

2 0

Output

5

Input

4 2
5 2
6 1

Output

6

Input

20 10
10 18
11 17
14 7
4 6
30 28
19 24
29 22
25 32
38 34
36 39

Output

27087418

### Response

```cpp
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=602,M=1000000007;
typedef long long ll;
int n,k,i,j,l,r,x,y,L[N],R[N],cnt[N],num[N][N];
ll g[N],f[N][N],Ans;
bool ok;
void init(){
    scanf("%d%d",&n,&k);
    n*=2;
    for(i=1;i<=k;i++){
        scanf("%d%d",L+i,R+i);
        if(L[i]>R[i])
            swap(L[i],R[i]);
        cnt[L[i]]++;
        cnt[R[i]]++;
    }
    for(i=1;i<=n;i++)
        cnt[i]=1-cnt[i]+cnt[i-1];
    for(l=1;l<=n;l++)
        for(r=l;r<=n;r++)
            num[l][r]=cnt[r]-cnt[l-1];
}
void work(){
    g[0]=1;
    for(i=2;i<=n;i++)
        g[i]=(i-1)*g[i-2]%M;
    for(j=1;j<=n;j+=2)
        for(x=1;x+j<=n;x++){
            y=x+j;
            ok=1;
            for(i=1;i<=k&&ok;i++){
                if(L[i]<x&&x<=R[i]&&R[i]<=y)
                    ok=0;
                if(x<=L[i]&&L[i]<=y&&y<R[i])
                    ok=0;
            }
            if(ok){
                f[x][y]=g[num[x][y]];
                for(i=x+1;i<y;i+=2)
                    f[x][y]=(f[x][y]-f[x][i]*g[num[i+1][y]])%M;
            }
            Ans=(Ans+f[x][y]*g[num[1][x-1]+num[y+1][n]])%M;
        }
    printf("%lld",(Ans+M)%M);
}
int main(){
    init();
    work();
    return 0;
}
```


### Prompt

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

Zookeeper is playing a game. In this game, Zookeeper must use bombs to bomb a string that consists of letters 'A' and 'B'. He can use bombs to bomb a substring which is either "AB" or "BB". When he bombs such a substring, the substring gets deleted from the string and the remaining parts of the string get concatenated.

For example, Zookeeper can use two such operations: AABABBA → AABBA → AAA.

Zookeeper wonders what the shortest string he can make is. Can you help him find the length of the shortest string?

Input

Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 20000) — the number of test cases. The description of the test cases follows.

Each of the next t lines contains a single test case each, consisting of a non-empty string s: the string that Zookeeper needs to bomb. It is guaranteed that all symbols of s are either 'A' or 'B'.

It is guaranteed that the sum of |s| (length of s) among all test cases does not exceed 2 ⋅ 10^5.

Output

For each test case, print a single integer: the length of the shortest string that Zookeeper can make.

Example

Input

3
AAA
BABA
AABBBABBBB

Output

3
2
0

Note

For the first test case, you can't make any moves, so the answer is 3.

For the second test case, one optimal sequence of moves is BABA → BA. So, the answer is 2.

For the third test case, one optimal sequence of moves is AABBBABBBB → AABBBABB → AABBBB → ABBB → AB → (empty string). So, the answer is 0.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int MOD = 1e9 + 7;
void solve() {
  string s;
  cin >> s;
  int n = int(s.size());
  int b = 0, ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'B')
      ++b;
    else {
      if (b > 0) {
        --b;
      } else {
        ans++;
        ans += b % 2;
        b = 0;
      }
    }
  }
  if (b > 0) ans += b % 2;
  cout << ans << endl;
}
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  cin >> tt;
  for (int tc = 1; tc <= tt; tc++) {
    solve();
  }
}

```


### Prompt

Please create a solution in cpp to the following problem:

Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings a and b. It is known that |b| ≤ |a|, that is, the length of b is at most the length of a.

The Cossack considers every substring of length |b| in string a. Let's call this substring c. He matches the corresponding characters in b and c, after which he counts the number of positions where the two strings are different. We call this function f(b, c).

For example, let b = 00110, and c = 11000. In these strings, the first, second, third and fourth positions are different.

Vus the Cossack counts the number of such substrings c such that f(b, c) is even.

For example, let a = 01100010 and b = 00110. a has four substrings of the length |b|: 01100, 11000, 10001, 00010.

  * f(00110, 01100) = 2;
  * f(00110, 11000) = 4;
  * f(00110, 10001) = 4;
  * f(00110, 00010) = 1.

Since in three substrings, f(b, c) is even, the answer is 3.

Vus can not find the answer for big strings. That is why he is asking you to help him.

Input

The first line contains a binary string a (1 ≤ |a| ≤ 10^6) — the first string.

The second line contains a binary string b (1 ≤ |b| ≤ |a|) — the second string.

Output

Print one number — the answer.

Examples

Input

01100010
00110

Output

3

Input

1010111110
0110

Output

4

Note

The first example is explained in the legend.

In the second example, there are five substrings that satisfy us: 1010, 0101, 1111, 1111.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char s[2000000], t[2000000];
int a[2000000];
int main() {
  cin >> s >> t;
  int tot = 0;
  a[0] = 0;
  int lt = strlen(t), ls = strlen(s);
  for (int i = 0; i < ls; ++i) {
    a[i + 1] = a[i];
    if (s[i] == '1') a[i + 1]++;
  }
  for (int i = 0; i < lt; ++i) {
    if (t[i] == '1') ++tot;
  }
  int ans = 0;
  for (int i = lt; i <= ls; ++i) {
    if ((a[i] - a[i - lt]) % 2 == (tot % 2)) ++ans;
  }
  printf("%d", ans);
  return 0;
}

```


### Prompt

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

While creating high loaded systems one should pay a special attention to caching. This problem will be about one of the most popular caching algorithms called LRU (Least Recently Used).

Suppose the cache may store no more than k objects. At the beginning of the workflow the cache is empty. When some object is queried we check if it is present in the cache and move it here if it's not. If there are more than k objects in the cache after this, the least recently used one should be removed. In other words, we remove the object that has the smallest time of the last query.

Consider there are n videos being stored on the server, all of the same size. Cache can store no more than k videos and caching algorithm described above is applied. We know that any time a user enters the server he pick the video i with probability pi. The choice of the video is independent to any events before.

The goal of this problem is to count for each of the videos the probability it will be present in the cache after 10100 queries.

Input

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 20) — the number of videos and the size of the cache respectively. Next line contains n real numbers pi (0 ≤ pi ≤ 1), each of them is given with no more than two digits after decimal point.

It's guaranteed that the sum of all pi is equal to 1.

Output

Print n real numbers, the i-th of them should be equal to the probability that the i-th video will be present in the cache after 10100 queries. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.

Examples

Input

3 1
0.3 0.2 0.5

Output

0.3 0.2 0.5

Input

2 1
0.0 1.0

Output

0.0 1.0

Input

3 2
0.3 0.2 0.5

Output

0.675 0.4857142857142857 0.8392857142857143

Input

3 3
0.2 0.3 0.5

Output

1.0 1.0 1.0

### Response

```cpp
#include <bits/stdc++.h>
long double f[1 << 20];
double p[1 << 20];
int g[1 << 20];
double ans[20];
int main() {
  f[0] = 1;
  int n, k;
  scanf("%d%d", &n, &k);
  int cnt = n;
  for (int i = 0; i < n; ++i) {
    scanf("%lf", &p[1 << i]);
    if (p[1 << i] == 0) cnt--;
  }
  if (cnt < k) k = cnt;
  int lim = 1 << n;
  for (int i = 1; i < lim; ++i) {
    p[i] = p[i & (-i)] + p[i ^ (i & (-i))];
    g[i] = (i & 1) + g[i >> 1];
  }
  for (int i = 0; i < lim; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i & (1 << j)) continue;
      if (p[i] != 1) f[i ^ (1 << j)] += f[i] * p[1 << j] / (1 - p[i]);
    }
    if (g[i] == k) {
      for (int j = 0; j < n; ++j) {
        if (i & (1 << j)) ans[j] += f[i];
      }
    }
  }
  for (int i = 0; i < n; ++i)
    printf("%.7f%c", ans[i], (i == n - 1) ? '\n' : ' ');
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

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>
const int64_t MOD = 1e9 + 7;
int64_t as[100005];
int64_t bit[100006];
int64_t raw[100006];
void add(int64_t i, int64_t v) {
  raw[i] = (raw[i] + v) % MOD;
  for (i++; i < 100006; i += (i & -i)) {
    bit[i] = (bit[i] + v) % MOD;
  }
}
void set(int64_t i, int64_t v) { add(i, (v + MOD - raw[i]) % MOD); }
int64_t prefix(int64_t i) {
  int64_t ac = 0;
  for (i++; i > 0; i -= (i & -i)) {
    ac = (ac + bit[i]) % MOD;
  }
  return ac;
}
int64_t total = 0;
int main() {
  int64_t N;
  scanf("%I64d", &N);
  std::map<int64_t, int64_t> cps;
  for (int64_t i = 0; i < N; i++) {
    scanf("%I64d", &as[i]);
    cps[as[i]];
  }
  int64_t last = 1;
  for (auto& pair : cps) {
    pair.second = last++;
  }
  add(0, 1);
  for (int64_t i = 0; i < N; i++) {
    int64_t x = cps[as[i]];
    int64_t q = prefix(x);
    set(x, q * as[i] % MOD);
  }
  printf("%I64d\n", (prefix(last) + MOD - 1) % MOD);
  return 0;
}

```


### Prompt

Create a solution in cpp for the following problem:

Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.

Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th minute of the lecture then ti will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told — ai during the i-th minute. Otherwise he writes nothing.

You know some secret technique to keep Mishka awake for k minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and n - k + 1. If you use it on some minute i then Mishka will be awake during minutes j such that <image> and will write down all the theorems lecturer tells.

You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.

Input

The first line of the input contains two integer numbers n and k (1 ≤ k ≤ n ≤ 105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.

The second line of the input contains n integer numbers a1, a2, ... an (1 ≤ ai ≤ 104) — the number of theorems lecturer tells during the i-th minute.

The third line of the input contains n integer numbers t1, t2, ... tn (0 ≤ ti ≤ 1) — type of Mishka's behavior at the i-th minute of the lecture.

Output

Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.

Example

Input

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

Output

16

Note

In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.

### Response

```cpp
#include <bits/stdc++.h>
int main() {
  int y, i, j, k, n, a = 0, b = 0, max, s[100050], x[100050];
  scanf("%d %d", &n, &k);
  for (i = 0; i < n; i++) scanf("%d", &s[i]);
  for (j = 0; j < n; j++) scanf("%d", &x[j]);
  for (i = 0; i < n; i++) {
    if (x[i] == 1) {
      a += s[i];
    }
  }
  for (i = 0; i < k; i++) {
    if (x[i] == 0) b = b + s[i];
  }
  max = b;
  for (i = 1; i < n; i++) {
    if (x[i - 1] == 0) b = b - s[i - 1];
    if (x[i + k - 1] == 0 && i + k - 1 < n) b = b + s[i + k - 1];
    if (max < b) max = b;
  }
  printf("%d\n", a + max);
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

Count the number of strings S that satisfy the following constraints, modulo 10^9 + 7.

* The length of S is exactly N.
* S consists of digits (`0`...`9`).
* You are given Q intervals. For each i (1 \leq i \leq Q), the integer represented by S[l_i \ldots r_i] (the substring of S between the l_i-th (1-based) character and the r_i-th character, inclusive) must be a multiple of 9.

Here, the string S and its substrings may have leading zeroes. For example, `002019` represents the integer 2019.

Constraints

* 1 \leq N \leq 10^9
* 1 \leq Q \leq 15
* 1 \leq l_i \leq r_i \leq N

Input

Input is given from Standard Input in the following format:

N
Q
l_1 r_1
:
l_Q r_Q

Output

Print the number of strings that satisfy the conditions, modulo 10^9 + 7.

Examples

Input

4
2
1 2
2 4

Output

136

Input

6
3
2 5
3 5
1 3

Output

2720

Input

20
10
2 15
5 6
1 12
7 9
2 17
5 15
2 4
16 17
2 12
8 17

Output

862268030

### Response

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

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){
        if(n>0) initialize(n);
    }

    void initialize(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0; i<n; i++){
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(sz[x] < sz[y]){
            par[x] = y;
            sz[y] += sz[x];
        }else{
            par[y] = x;
            sz[x] += sz[y];
        }
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int main(){
    int N, Q, L[15], R[15];
    cin >> N >> Q;
    for(int i=0; i<Q; i++){
        cin >> L[i] >> R[i];
        L[i]--;
    }

    vector<int> compress;
    for(int i=0; i<Q; i++){
        compress.push_back(L[i]);
        compress.push_back(R[i]);
    }
    sort(compress.begin(), compress.end());
    compress.erase(unique(compress.begin(), compress.end()), compress.end());
    map<int, int> compress_inv;
    for(int i=0; i<compress.size(); i++) compress_inv[compress[i]] = i;

    UnionFind uf(Q);
    for(int i=0; i<Q; i++) for(int j=i+1; j<Q; j++){
        if(L[i] == L[j] || L[i] == R[j] || R[i] == L[j] || R[i] == R[j]) uf.unite(i, j);
    }

    vector<vector<int>> components;
    for(int i=0; i<Q; i++){
        if(uf.find(i) != i) continue;
        vector<int> v;
        for(int j=0; j<Q; j++){
            if(uf.same(i, j)){
                v.push_back(compress_inv[L[j]]);
                v.push_back(compress_inv[R[j]]);
            }
        }
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        components.push_back(v);
    }
    sort(components.begin(), components.end());
    Q = components.size();

    static int64_t coefficients[1<<15];
    for(int bits=0; bits<(1<<Q); bits++){
        vector<int> pts;
        for(int i=0; i<Q; i++) if(nth_bit(bits, i)){
            for(int v : components[i]) pts.push_back(v);
        }
        sort(pts.begin(), pts.end());

        int64_t c = 1;
        for(int i=0; i<(int)pts.size()-1; i++){
            if(pts[i]+1 == pts[i+1]){
                int dist = compress[pts[i+1]] - compress[pts[i]];
                int64_t val = power_mod(10, dist) - 1;
                mul(c, (val+9) * inv_mod(val) % MOD);
            }
        }
        coefficients[bits] = c;
    }

    int64_t init[10];
    for(int i=1; i<=9; i++) init[i] = ((power_mod(10, compress[0]) - 1) * inv_mod(9) + (i==9)) % MOD;

    static int64_t dp[10][1<<15];
    dp[0][0] = 1;
    for(int n=1; n<=9; n++){
        for(int bits=0; bits<(1<<Q); bits++){
            for(int use=bits; use>=0; use=(use-1)&bits){
                int64_t result = dp[n-1][bits-use] * coefficients[use] % MOD;
                if(nth_bit(use, 0)) mul(result, init[n]);
                add(dp[n][bits], result);
                if(use == 0) break;
            }
        }
    }

    int64_t ans = dp[9][(1<<Q)-1];
    for(int i=0; i<compress.size()-1; i++){
        int dist = compress[i+1] - compress[i];
        int64_t result = (power_mod(10, dist) - 1 + MOD) * inv_mod(9) % MOD;
        mul(ans, result);
    }
    mul(ans, power_mod(10, N - compress.back()));
    cout << ans << endl;
    return 0;
}
```


### Prompt

Construct a CPP code solution to the problem outlined:

Today you are to solve the problem even the famous Hercule Poirot can't cope with! That's why this crime has not yet been solved and this story was never included in Agatha Christie's detective story books.

You are not informed on what crime was committed, when and where the corpse was found and other details. We only know that the crime was committed in a house that has n rooms and m doors between the pairs of rooms. The house residents are very suspicious, that's why all the doors can be locked with keys and all the keys are different. According to the provided evidence on Thursday night all the doors in the house were locked, and it is known in what rooms were the residents, and what kind of keys had any one of them. The same is known for the Friday night, when all the doors were also locked. On Friday it was raining heavily, that's why nobody left the house and nobody entered it. During the day the house residents could

  * open and close doors to the neighboring rooms using the keys at their disposal (every door can be opened and closed from each side);
  * move freely from a room to a room if a corresponding door is open;
  * give keys to one another, being in one room.

"Little grey matter" of Hercule Poirot are not capable of coping with such amount of information. Find out if the positions of people and keys on the Thursday night could result in the positions on Friday night, otherwise somebody among the witnesses is surely lying.

Input

The first line contains three preset integers n, m и k (1 ≤ n, m, k ≤ 1000) — the number of rooms, the number of doors and the number of house residents respectively. The next m lines contain pairs of room numbers which join the doors. The rooms are numbered with integers from 1 to n. There cannot be more that one door between the pair of rooms. No door connects a room with itself. The next k lines describe the residents' position on the first night. Every line contains a resident's name (a non-empty line consisting of no more than 10 Latin letters), then after a space follows the room number, then, after a space — the number of keys the resident has. Then follow written space-separated numbers of the doors that can be unlocked by these keys. The doors are numbered with integers from 1 to m in the order in which they are described in the input data. All the residents have different names, uppercase and lowercase letters considered to be different. Every m keys occurs exactly once in the description. Multiple people may be present in one room, some rooms may be empty. The next k lines describe the position of the residents on the second night in the very same format. It is guaranteed that in the second night's description the residents' names remain the same and every m keys occurs exactly once.

Output

Print "YES" (without quotes) if the second arrangement can result from the first one, otherwise, print "NO".

Examples

Input

2 1 2
1 2
Dmitry 1 1 1
Natalia 2 0
Natalia 1 1 1
Dmitry 2 0

Output

YES

Input

4 4 3
1 3
1 2
2 3
3 4
Artem 1 1 4
Dmitry 1 1 2
Edvard 4 2 1 3
Artem 2 0
Dmitry 1 0
Edvard 4 4 1 2 3 4

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int tt = 1111;
int x[tt], y[tt], fa[tt], key[tt];
int n, m, k;
bool p1[tt], p2[tt];
char s[tt];
map<string, int> nm;
bool ans = true;
int findfa(int a) { return a == fa[a] ? a : fa[a] = findfa(fa[a]); }
void getans(bool *p) {
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (bool pd = true; pd;) {
    pd = false;
    for (int i = 1; i <= m; i++)
      if (!p[i]) {
        int a = findfa(key[i]), b = findfa(x[i]), c = findfa(y[i]);
        if (a == b || a == c) {
          fa[b] = c;
          pd = p[i] = true;
        }
      }
  }
}
int main() {
  int i, r, t, q;
  scanf("%d%d%d", &n, &m, &k);
  for (i = 1; i <= m; i++) scanf("%d%d", x + i, y + i), p1[i] = p2[i] = false;
  for (i = 1; i <= k; i++) {
    scanf("%s%d%d", s, &r, &t);
    for (nm[s] = r; t; t--) key[scanf("%d", &q), q] = r;
  }
  getans(p1);
  for (i = 1; i <= k; i++) {
    scanf("%s%d%d", s, &r, &t);
    ans &= findfa(nm[s]) == findfa(r);
    for (; t; t--) {
      ans &= findfa(key[scanf("%d", &q), q]) == findfa(r);
      key[q] = r;
    }
  }
  getans(p2);
  for (i = 1; i <= m; i++) ans &= p1[i] == p2[i];
  puts(ans ? "YES" : "NO");
  return 0;
}

```


### Prompt

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

You are given a rooted tree with n nodes, labeled from 1 to n. The tree is rooted at node 1. The parent of the i-th node is p_i. A leaf is node with no children. For a given set of leaves L, let f(L) denote the smallest connected subgraph that contains all leaves L.

You would like to partition the leaves such that for any two different sets x, y of the partition, f(x) and f(y) are disjoint.

Count the number of ways to partition the leaves, modulo 998244353. Two ways are different if there are two leaves such that they are in the same set in one way but in different sets in the other.

Input

The first line contains an integer n (2 ≤ n ≤ 200 000) — the number of nodes in the tree.

The next line contains n-1 integers p_2, p_3, …, p_n (1 ≤ p_i < i).

Output

Print a single integer, the number of ways to partition the leaves, modulo 998244353.

Examples

Input

5
1 1 1 1

Output

12

Input

10
1 2 3 4 5 6 7 8 9

Output

1

Note

In the first example, the leaf nodes are 2,3,4,5. The ways to partition the leaves are in the following image <image>

In the second example, the only leaf is node 10 so there is only one partition. Note that node 1 is not a leaf.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, y, z, l, i, j, x, r;
long long a[100500], b[100500];
vector<long long> g[200500];
long long dp[200500][2];
long long binpow(long long x, long long y) {
  if (y == 0) {
    return 1;
  }
  long long tmp = binpow(x, y / 2);
  tmp = tmp * tmp % 998244353;
  if (y % 2) return x * tmp % 998244353;
  return tmp;
}
long long inv(long long x) { return binpow(x, 998244353 - 2); }
void dfs(long long v, long long p = -1) {
  long long k = 0;
  long long prod1 = 1;
  long long prod = 1;
  long long sum = 0;
  long long sum1 = 0;
  for (auto to : g[v]) {
    if (to == p) continue;
    dfs(to, v);
    prod1 = prod1 * (dp[to][0] + dp[to][1]) % 998244353;
    prod = prod * (dp[to][1]) % 998244353;
    sum = (sum + dp[to][0]) % 998244353;
    sum1 = (sum1 + dp[to][1]) % 998244353;
    k++;
  }
  if (k == 0) {
    dp[v][0] = 1;
    dp[v][1] = 1;
    return;
  }
  long long mag = prod1;
  for (auto to : g[v]) {
    if (to == p) continue;
    mag = (mag - prod * inv(dp[to][1]) % 998244353 * dp[to][0] % 998244353) +
          998244353;
    mag %= 998244353;
  }
  dp[v][0] = (prod1 - prod + 998244353 + 998244353) % 998244353;
  dp[v][1] = mag;
}
int main() {
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int x;
    scanf("%d", &x);
    g[x].push_back(i);
    g[i].push_back(x);
  }
  dfs(1);
  cout << dp[1][1] << endl;
  return 0;
}

```


### Prompt

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

— Thanks a lot for today.

— I experienced so many great things.

— You gave me memories like dreams... But I have to leave now...

— One last request, can you...

— Help me solve a Codeforces problem?

— ......

— What?

Chtholly has been thinking about a problem for days:

If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.

Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p.

Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!

Input

The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109).

Output

Output single integer — answer to the problem.

Examples

Input

2 100

Output

33

Input

5 30

Output

15

Note

In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.

In the second example, <image>.

### Response

```cpp
#include <bits/stdc++.h>
int mod = 1000000007;
const double pi = 3.141592653689793238460;
const int inf = 0x3f3f3f3f;
using namespace std;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void r(int arr[], int d, int n) {
  d = d % n;
  int g_c_d = gcd(d, n);
  for (int i = 0; i < g_c_d; i++) {
    int temp = arr[i];
    int j = i;
    while (1) {
      int k = j + d;
      if (k >= n) k = k - n;
      if (k == i) break;
      arr[j] = arr[k];
      j = k;
    }
    arr[j] = temp;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long k, p;
  cin >> k >> p;
  long long sum = 0;
  for (int i = 0; i < k + 1; i++) {
    string s = to_string(i);
    string x = to_string(i);
    reverse(x.begin(), x.end());
    s += x;
    long long m = stoll(s);
    sum = (sum + m) % p;
  }
  cout << sum % p << endl;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an h × w field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only some of them are black. Currently Gerald is finishing a game of giant chess against his friend Pollard. Gerald has almost won, and the only thing he needs to win is to bring the pawn from the upper left corner of the board, where it is now standing, to the lower right corner. Gerald is so confident of victory that he became interested, in how many ways can he win?

The pawn, which Gerald has got left can go in two ways: one cell down or one cell to the right. In addition, it can not go to the black cells, otherwise the Gerald still loses. There are no other pawns or pieces left on the field, so that, according to the rules of giant chess Gerald moves his pawn until the game is over, and Pollard is just watching this process.

Input

The first line of the input contains three integers: h, w, n — the sides of the board and the number of black cells (1 ≤ h, w ≤ 105, 1 ≤ n ≤ 2000).

Next n lines contain the description of black cells. The i-th of these lines contains numbers ri, ci (1 ≤ ri ≤ h, 1 ≤ ci ≤ w) — the number of the row and column of the i-th cell.

It is guaranteed that the upper left and lower right cell are white and all cells in the description are distinct.

Output

Print a single line — the remainder of the number of ways to move Gerald's pawn from the upper left to the lower right corner modulo 109 + 7.

Examples

Input

3 4 2
2 2
2 3

Output

2

Input

100 100 3
15 16
16 15
99 88

Output

545732279

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int sz = 200010;
long long int f[sz], rev[sz], dp[sz];
pair<int, int> p[sz];
void compute() {
  f[0] = 1;
  rev[0] = rev[1] = 1;
  for (int i = 1; i < sz; i++) {
    f[i] = (i * f[i - 1]) % 1000000007;
  }
  for (int i = 2; i < sz; i++) {
    rev[i] = (1000000007 - 1000000007 / i) * rev[1000000007 % i] % 1000000007;
  }
  for (int i = 2; i < sz; i++) {
    rev[i] = (rev[i] * rev[i - 1]) % 1000000007;
  }
}
long long int comb(long long int n, long long int r) {
  long long int ans =
      (((f[n] * rev[r]) % 1000000007) * rev[n - r]) % 1000000007;
  return ans;
}
int main() {
  compute();
  long long int h, w, n;
  cin >> h >> w >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
  }
  p[n] = make_pair(h, w);
  sort(p, p + n + 1);
  for (int i = 0; i <= n; i++) {
    dp[i] = comb(p[i].first - 1 + p[i].second - 1, p[i].first - 1);
    for (int j = 0; j < i; j++) {
      if (p[j].first <= p[i].first && p[j].second <= p[i].second) {
        dp[i] -= dp[j] *
                 comb(p[i].first - p[j].first + p[i].second - p[j].second,
                      p[i].first - p[j].first) %
                 1000000007;
        dp[i] = (dp[i] % 1000000007 + 1000000007) % 1000000007;
      }
    }
  }
  dp[n] = ((dp[n] % 1000000007) + 1000000007) % 1000000007;
  cout << dp[n] << endl;
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

We start with a permutation a_1, a_2, …, a_n and with an empty array b. We apply the following operation k times.

On the i-th iteration, we select an index t_i (1 ≤ t_i ≤ n-i+1), remove a_{t_i} from the array, and append one of the numbers a_{t_i-1} or a_{t_i+1} (if t_i-1 or t_i+1 are within the array bounds) to the right end of the array b. Then we move elements a_{t_i+1}, …, a_n to the left in order to fill in the empty space.

You are given the initial permutation a_1, a_2, …, a_n and the resulting array b_1, b_2, …, b_k. All elements of an array b are distinct. Calculate the number of possible sequences of indices t_1, t_2, …, t_k modulo 998 244 353.

Input

Each test contains multiple test cases. The first line contains an integer t (1 ≤ t ≤ 100 000), denoting the number of test cases, followed by a description of the test cases.

The first line of each test case contains two integers n, k (1 ≤ k < n ≤ 200 000): sizes of arrays a and b.

The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n): elements of a. All elements of a are distinct.

The third line of each test case contains k integers b_1, b_2, …, b_k (1 ≤ b_i ≤ n): elements of b. All elements of b are distinct.

The sum of all n among all test cases is guaranteed to not exceed 200 000.

Output

For each test case print one integer: the number of possible sequences modulo 998 244 353.

Example

Input

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

Output

2
0
4

Note

\require{cancel}

Let's denote as a_1 a_2 … \cancel{a_i} \underline{a_{i+1}} … a_n → a_1 a_2 … a_{i-1} a_{i+1} … a_{n-1} an operation over an element with index i: removal of element a_i from array a and appending element a_{i+1} to array b.

In the first example test, the following two options can be used to produce the given array b:

  * 1 2 \underline{3} \cancel{4} 5 → 1 \underline{2} \cancel{3} 5 → 1 \cancel{2} \underline{5} → 1 2; (t_1, t_2, t_3) = (4, 3, 2);
  * 1 2 \underline{3} \cancel{4} 5 → \cancel{1} \underline{2} 3 5 → 2 \cancel{3} \underline{5} → 1 5; (t_1, t_2, t_3) = (4, 1, 2).

In the second example test, it is impossible to achieve the given array no matter the operations used. That's because, on the first application, we removed the element next to 4, namely number 3, which means that it couldn't be added to array b on the second step.

In the third example test, there are four options to achieve the given array b:

  * 1 4 \cancel{7} \underline{3} 6 2 5 → 1 4 3 \cancel{6} \underline{2} 5 → \cancel{1} \underline{4} 3 2 5 → 4 3 \cancel{2} \underline{5} → 4 3 5;
  * 1 4 \cancel{7} \underline{3} 6 2 5 → 1 4 3 \cancel{6} \underline{2} 5 → 1 \underline{4} \cancel{3} 2 5 → 1 4 \cancel{2} \underline{5} → 1 4 5;
  * 1 4 7 \underline{3} \cancel{6} 2 5 → 1 4 7 \cancel{3} \underline{2} 5 → \cancel{1} \underline{4} 7 2 5 → 4 7 \cancel{2} \underline{5} → 4 7 5;
  * 1 4 7 \underline{3} \cancel{6} 2 5 → 1 4 7 \cancel{3} \underline{2} 5 → 1 \underline{4} \cancel{7} 2 5 → 1 4 \cancel{2} \underline{5} → 1 4 5;

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  long long f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f *= -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  x *= f;
}
int a[200010];
int b[200010];
int lf[200010], rg[200010];
int pre[200010], nxt[200010];
bool vis[200010];
int main() {
  int t;
  int n, m;
  const long long p = 998244353;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    memset(vis, 0, sizeof(bool) * (n + 1));
    memset(lf, 0, sizeof(int) * (n + 1));
    memset(rg, 0, sizeof(int) * (n + 1));
    memset(pre, 0, sizeof(int) * (n + 1));
    memset(nxt, 0, sizeof(int) * (n + 1));
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &a[i]);
    }
    for (int i = 1; i <= m; ++i) {
      scanf("%d", &b[i]);
      vis[b[i]] = true;
    }
    int sum = 0, pe = 0;
    for (int i = 1; i <= n; ++i) {
      int x = a[i];
      if (!vis[x]) {
        ++sum;
        continue;
      }
      lf[x] = sum;
      rg[pe] = sum;
      pre[x] = pe;
      nxt[pe] = x;
      sum = 0;
      pe = x;
    }
    rg[pe] = sum;
    long long ans = 1;
    for (int i = 1; i <= m; ++i) {
      int x = b[i];
      if (lf[x] == 0 && rg[x] == 0) {
        ans = 0;
        break;
      }
      if (lf[x] && rg[x]) {
        ans = ans * 2 % p;
      }
      int pe = pre[x], nt = nxt[x];
      rg[pe] += rg[x];
      lf[nt] += lf[x];
      nxt[pe] = nt;
      pre[nt] = pe;
    }
    printf("%lld\n", ans);
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.

The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23.

Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.

Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.

Input

The first line of the input contains integer number n (1 ≤ n ≤ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 .

Output

Write n lines, each line should contain a cell coordinates in the other numeration system.

Examples

Input

2
R23C55
BC23

Output

BC23
R23C55

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    char s[100];
    cin >> s;
    int len = strlen(s);
    int i = 0;
    while (i < len) {
      if ('A' <= s[i] && s[i] <= 'Z')
        i++;
      else
        break;
    }
    while (i < len) {
      if ('0' <= s[i] && s[i] <= '9')
        i++;
      else
        break;
    }
    if (i == len) {
      int col = 0;
      i = 0;
      while ('A' <= s[i] && s[i] <= 'Z') {
        col = col * 26 + s[i] - 'A' + 1;
        i++;
      }
      int row = 0;
      while (i < len) {
        row = row * 10 + s[i] - '0';
        i++;
      }
      cout << "R" << row << "C" << col << "\n";
    } else {
      i = 1;
      int row = 0;
      while (s[i] != 'C') {
        row = row * 10 + s[i] - '0';
        i++;
      }
      i++;
      int col = 0;
      while (i < len) {
        col = col * 10 + s[i] - '0';
        i++;
      }
      len = 0;
      char ans[100];
      while (col != 0) {
        int md = col % 26;
        col /= 26;
        if (md == 0) {
          ans[len++] = 'Z';
          col--;
        } else
          ans[len++] = md + 'A' - 1;
      }
      for (i = len - 1; i >= 0; i--) cout << ans[i];
      cout << row << "\n";
    }
  }
  return 0;
}

```


### Prompt

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

Miyako came to the flea kingdom with a ukulele. She became good friends with local flea residents and played beautiful music for them every day.

In return, the fleas made a bigger ukulele for her: it has n strings, and each string has (10^{18} + 1) frets numerated from 0 to 10^{18}. The fleas use the array s_1, s_2, …, s_n to describe the ukulele's tuning, that is, the pitch of the j-th fret on the i-th string is the integer s_i + j.

Miyako is about to leave the kingdom, but the fleas hope that Miyako will answer some last questions for them.

Each question is in the form of: "How many different pitches are there, if we consider frets between l and r (inclusive) on all strings?"

Miyako is about to visit the cricket kingdom and has no time to answer all the questions. Please help her with this task!

Formally, you are given a matrix with n rows and (10^{18}+1) columns, where the cell in the i-th row and j-th column (0 ≤ j ≤ 10^{18}) contains the integer s_i + j. You are to answer q queries, in the k-th query you have to answer the number of distinct integers in the matrix from the l_k-th to the r_k-th columns, inclusive.

Input

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

The second line contains n integers s_1, s_2, …, s_n (0 ≤ s_i ≤ 10^{18}) — the tuning of the ukulele.

The third line contains an integer q (1 ≤ q ≤ 100 000) — the number of questions.

The k-th among the following q lines contains two integers l_k，r_k (0 ≤ l_k ≤ r_k ≤ 10^{18}) — a question from the fleas.

Output

Output one number for each question, separated by spaces — the number of different pitches.

Examples

Input

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

Output

5 10 18

Input

2
1 500000000000000000
2
1000000000000000000 1000000000000000000
0 1000000000000000000

Output

2 1500000000000000000

Note

For the first example, the pitches on the 6 strings are as follows.

$$$ \begin{matrix} Fret & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & … \\\ s_1: & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & ... \\\ s_2: & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & ... \\\ s_3: & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & ... \\\ s_4: & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & ... \\\ s_5: & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & ... \\\ s_6: & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & ... \end{matrix} $$$

There are 5 different pitches on fret 7 — 8, 10, 11, 12, 16.

There are 10 different pitches on frets 0, 1, 2 — 1, 2, 3, 4, 5, 6, 7, 9, 10, 11.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> s(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  n = unique(s.begin(), s.end()) - s.begin();
  vector<long long> d(n);
  for (int i = 1; i < n; ++i) {
    d[i] = s[i] - s[i - 1] - 1;
  }
  sort(d.begin(), d.end());
  vector<long long> sum(n);
  for (int i = 1; i < n; ++i) {
    sum[i] = sum[i - 1] + d[i];
  }
  int q;
  cin >> q;
  while (q--) {
    long long l, r;
    cin >> l >> r;
    r -= l;
    long long ans = n;
    int iter = upper_bound(d.begin(), d.end(), r) - d.begin();
    ans += sum[iter - 1];
    ans += r * (n - iter + 1);
    cout << ans << " ";
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.

Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.

Help Amr by choosing the smallest subsegment possible.

Input

The first line contains one number n (1 ≤ n ≤ 105), the size of the array.

The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.

Output

Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.

If there are several possible answers you may output any of them.

Examples

Input

5
1 1 2 2 1

Output

1 5

Input

5
1 2 2 3 1

Output

2 3

Input

6
1 2 2 1 1 2

Output

1 5

Note

A subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long fastmul(long long a, long long b) {
  if (b == 0) return 0;
  if (b == 1) return a;
  long long tmp = fastmul(a, b >> 1);
  return (b & 1) ? ((tmp << 1) + a) % 1000000007LL : (tmp << 1) % 1000000007LL;
}
struct Point {
  double x, y;
  Point() {}
  Point(double A, double B) : x(A), y(B) {}
};
struct Vec {
  double x, y;
  Vec() {}
  Vec(double A, double B) : x(A), y(B) {}
};
struct line {
  double a, b, c;
  line() {}
  line(double A, double B, double C) : a(A), b(B), c(C) {}
  line(Point A, Point B) {
    a = A.y - B.y;
    b = B.x - A.x;
    c = -a * A.x - b * A.y;
  }
};
Point intersect(line AB, line CD) {
  AB.c = -AB.c;
  CD.c = -CD.c;
  double D = (AB.a * CD.b - AB.b * CD.a);
  double Dx = (AB.c * CD.b - AB.b * CD.c);
  double Dy = (AB.a * CD.c - AB.c * CD.a);
  if (D == 0.0)
    return Point(1e9, 1e9);
  else
    return Point(Dx / D, Dy / D);
}
struct matrix {
  long long a[2 + 5][2 + 5];
  matrix() {}
};
matrix matmul(matrix A, matrix B) {
  matrix c;
  for (int i = 1; i <= 2; i++)
    for (int j = 1; j <= 2; j++) {
      c.a[i][j] = 0;
      for (int k = 1; k <= 2; k++)
        c.a[i][j] = (c.a[i][j] + fastmul(A.a[i][k], B.a[k][j])) % 1000000007LL;
    }
  return c;
}
int n, x, res = 0, cnt[1000005], Start[1000005], Stop[1000005], luui = 0,
          luuj = 0;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i <= 1000000; i++) Start[i] = long(1e9);
  for (int i = 1; i <= n; i++) {
    cin >> x;
    cnt[x]++;
    Start[x] = min(Start[x], i);
    Stop[x] = max(Stop[x], i);
    res = max(res, cnt[x]);
  }
  int RES = long(1e9);
  for (int i = 1; i <= 1000000; i++) {
    if (cnt[i] == res) {
      if (Stop[i] - Start[i] + 1 < RES) {
        RES = Stop[i] - Start[i] + 1;
        luui = Start[i];
        luuj = Stop[i];
      }
    }
  }
  cout << luui << ' ' << luuj;
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Andrey needs one more problem to conduct a programming contest. He has n friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this friend will come up with a problem if Andrey asks him.

Help Andrey choose people to ask. As he needs only one problem, Andrey is going to be really upset if no one comes up with a problem or if he gets more than one problem from his friends. You need to choose such a set of people that maximizes the chances of Andrey not getting upset.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of Andrey's friends. The second line contains n real numbers pi (0.0 ≤ pi ≤ 1.0) — the probability that the i-th friend can come up with a problem. The probabilities are given with at most 6 digits after decimal point.

Output

Print a single real number — the probability that Andrey won't get upset at the optimal choice of friends. The answer will be considered valid if it differs from the correct one by at most 10 - 9.

Examples

Input

4
0.1 0.2 0.3 0.8

Output

0.800000000000

Input

2
0.1 0.2

Output

0.260000000000

Note

In the first sample the best strategy for Andrey is to ask only one of his friends, the most reliable one.

In the second sample the best strategy for Andrey is to ask all of his friends to come up with a problem. Then the probability that he will get exactly one problem is 0.1·0.8 + 0.9·0.2 = 0.26.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
double p[105], suff[105];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
  }
  sort(p + 1, p + n + 1);
  cout << fixed << setprecision(10);
  if (p[n] == 1) {
    cout << 1. << '\n';
    return 0;
  }
  suff[n] = 1 - p[n];
  for (int i = n - 1; i >= 1; i--) {
    suff[i] = (1 - p[i]) * suff[i + 1];
  }
  double ans = 0;
  for (int i = n; i >= 1; i--) {
    double tmp = 0;
    for (int j = i; j <= n; j++) {
      tmp += p[j] / (1 - p[j]);
    }
    tmp *= suff[i];
    ans = max(ans, tmp);
  }
  cout << ans << '\n';
}

```