### Prompt

Create a solution in CPP for the following problem:

Drazil likes heap very much. So he created a problem with heap:

There is a max heap with a height h implemented on the array. The details of this heap are the following:

This heap contains exactly 2^h - 1 distinct positive non-zero integers. All integers are distinct. These numbers are stored in the array a indexed from 1 to 2^h-1. For any 1 < i < 2^h, a[i] < a[\left ⌊{i/2}\right ⌋].

Now we want to reduce the height of this heap such that the height becomes g with exactly 2^g-1 numbers in heap. To reduce the height, we should perform the following action 2^h-2^g times:

Choose an index i, which contains an element and call the following function f in index i:

<image>

Note that we suppose that if a[i]=0, then index i don't contain an element.

After all operations, the remaining 2^g-1 element must be located in indices from 1 to 2^g-1. Now Drazil wonders what's the minimum possible sum of the remaining 2^g-1 elements. Please find this sum and find a sequence of the function calls to achieve this value.

Input

The first line of the input contains an integer t (1 ≤ t ≤ 70 000): the number of test cases.

Each test case contain two lines. The first line contains two integers h and g (1 ≤ g < h ≤ 20). The second line contains n = 2^h-1 distinct positive integers a[1], a[2], …, a[n] (1 ≤ a[i] < 2^{20}). For all i from 2 to 2^h - 1, a[i] < a[\left ⌊{i/2}\right ⌋].

The total sum of n is less than 2^{20}.

Output

For each test case, print two lines.

The first line should contain one integer denoting the minimum sum after reducing the height of heap to g. The second line should contain 2^h - 2^g integers v_1, v_2, …, v_{2^h-2^g}. In i-th operation f(v_i) should be called.

Example

Input

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

Output

10
3 2 3 1
8
2 1 3 1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long arr[20000020];
long long del(long long i, long long k) {
  long long val = arr[i];
  long long left = 2 * i;
  long long right = 2 * i + 1;
  if (arr[left] == 0 && arr[right] == 0) {
    arr[i] = 0;
    if (i < k) {
      return val;
    } else {
      return 0;
    }
  } else {
    if (arr[left] > arr[right]) {
      long long l = arr[left];
      long long x = del(left, k);
      if (x) {
        arr[i] = 0;
        return val + x;
      } else {
        arr[i] = l;
        return 0;
      }
    } else {
      long long l = arr[right];
      long long x = del(right, k);
      if (x) {
        arr[i] = 0;
        return val + x;
      } else {
        arr[i] = l;
        return 0;
      }
    }
  }
}
int main() {
  long long T;
  scanf("%lld", &T);
  ;
  while (T--) {
    long long J, K;
    scanf("%lld", &J);
    ;
    scanf("%lld", &K);
    ;
    long long qq = (1 << (J + 1));
    long long n = 1 << J;
    long long m = 1 << K;
    long long dif = n - m;
    long long sum = 0;
    for (long long i = n; i < qq; i++) {
      arr[i] = 0;
    }
    for (long long i = 1; i <= n - 1; i++) {
      long long in;
      scanf("%lld", &in);
      ;
      arr[i] = in;
    }
    vector<long long> ans;
    for (long long i = 1; i < m;) {
      if (arr[i] == 0) {
        i++;
        continue;
      }
      long long x = del(i, m);
      if (x) {
        sum += x;
        i++;
      } else {
        ans.push_back(i);
      }
    }
    cout << sum << "\n";
    for (auto i : ans) {
      cout << i << " ";
    }
    puts("");
  }
}

```


### Prompt

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

You want to perform the combo on your opponent in one popular fighting game. The combo is the string s consisting of n lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in s. I.e. if s="abca" then you have to press 'a', then 'b', 'c' and 'a' again.

You know that you will spend m wrong tries to perform the combo and during the i-th try you will make a mistake right after p_i-th button (1 ≤ p_i < n) (i.e. you will press first p_i buttons right and start performing the combo from the beginning). It is guaranteed that during the m+1-th try you press all buttons right and finally perform the combo.

I.e. if s="abca", m=2 and p = [1, 3] then the sequence of pressed buttons will be 'a' (here you're making a mistake and start performing the combo from the beginning), 'a', 'b', 'c', (here you're making a mistake and start performing the combo from the beginning), 'a' (note that at this point you will not perform the combo because of the mistake), 'b', 'c', 'a'.

Your task is to calculate for each button (letter) the number of times you'll press it.

You have to answer t independent test cases.

Input

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

Then t test cases follow.

The first line of each test case contains two integers n and m (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ m ≤ 2 ⋅ 10^5) — the length of s and the number of tries correspondingly.

The second line of each test case contains the string s consisting of n lowercase Latin letters.

The third line of each test case contains m integers p_1, p_2, ..., p_m (1 ≤ p_i < n) — the number of characters pressed right during the i-th try.

It is guaranteed that the sum of n and the sum of m both does not exceed 2 ⋅ 10^5 (∑ n ≤ 2 ⋅ 10^5, ∑ m ≤ 2 ⋅ 10^5).

It is guaranteed that the answer for each letter does not exceed 2 ⋅ 10^9.

Output

For each test case, print the answer — 26 integers: the number of times you press the button 'a', the number of times you press the button 'b', ..., the number of times you press the button 'z'.

Example

Input

3
4 2
abca
1 3
10 5
codeforces
2 8 3 2 9
26 10
qwertyuioplkjhgfdsazxcvbnm
20 10 1 2 3 5 10 5 9 4

Output

4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 9 4 5 3 0 0 0 0 0 0 0 0 9 0 0 3 1 0 0 0 0 0 0 0
2 1 1 2 9 2 2 2 5 2 2 2 1 1 5 4 11 8 2 7 5 1 10 1 5 2

Note

The first test case is described in the problem statement. Wrong tries are "a", "abc" and the final try is "abca". The number of times you press 'a' is 4, 'b' is 2 and 'c' is 2.

In the second test case, there are five wrong tries: "co", "codeforc", "cod", "co", "codeforce" and the final try is "codeforces". The number of times you press 'c' is 9, 'd' is 4, 'e' is 5, 'f' is 3, 'o' is 9, 'r' is 3 and 's' is 1.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, M;
  cin >> n >> M;
  vector<char> s(n);
  int m = M;
  vector<int> p(m), b(n), yes(n, 0), cnt(26, 0);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    cnt[s[i] - 'a']++;
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
    p[i]--;
  }
  sort(p.begin(), p.end());
  int top = 0;
  for (int i = 0; i < n; i++) {
    if (top >= M) break;
    if (p[top] != i)
      cnt[s[i] - 'a'] += m;
    else {
      int t = top;
      while (top < M - 1 && p[top] == p[top + 1]) top++;
      int c = ++top - t;
      cnt[s[i] - 'a'] += m;
      m -= c;
    }
  }
  for (int i = 0; i < 26; i++) cout << cnt[i] << " ";
  cout << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket.

The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fedor has n discount coupons, the i-th of them can be used with products with ids ranging from li to ri, inclusive. Today Fedor wants to take exactly k coupons with him.

Fedor wants to choose the k coupons in such a way that the number of such products x that all coupons can be used with this product x is as large as possible (for better understanding, see examples). Fedor wants to save his time as well, so he asks you to choose coupons for him. Help Fedor!

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 3·105) — the number of coupons Fedor has, and the number of coupons he wants to choose.

Each of the next n lines contains two integers li and ri ( - 109 ≤ li ≤ ri ≤ 109) — the description of the i-th coupon. The coupons can be equal.

Output

In the first line print single integer — the maximum number of products with which all the chosen coupons can be used. The products with which at least one coupon cannot be used shouldn't be counted.

In the second line print k distinct integers p1, p2, ..., pk (1 ≤ pi ≤ n) — the ids of the coupons which Fedor should choose.

If there are multiple answers, print any of them.

Examples

Input

4 2
1 100
40 70
120 130
125 180

Output

31
1 2

Input

3 2
1 12
15 20
25 30

Output

0
1 2

Input

5 2
1 10
5 15
14 50
30 70
99 100

Output

21
3 4

Note

In the first example if we take the first two coupons then all the products with ids in range [40, 70] can be bought with both coupons. There are 31 products in total.

In the second example, no product can be bought with two coupons, that is why the answer is 0. Fedor can choose any two coupons in this example.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct range {
  int l, r;

 public:
  range(int a, int b) {
    l = a;
    r = b;
  }
  range() {}
};
int main() {
  range arr[300300];
  int n, a, b, k;
  cin >> n >> k;
  pair<int, int> toGo[300300];
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    arr[i] = range(a, b);
    toGo[i] = make_pair(a, i);
  }
  sort(toGo, toGo + n);
  multiset<int> ends;
  int res = 0;
  int sst, send;
  for (int i = 0; i < n; i++) {
    ends.insert(arr[toGo[i].second].r);
    if (ends.size() > k) ends.erase(ends.begin());
    if (ends.size() == k) {
      int st = toGo[i].first;
      if (*ends.begin() - toGo[i].first + 1 > res) {
        res = *ends.begin() - toGo[i].first + 1;
        sst = toGo[i].first;
        send = *ends.begin();
      }
    }
  }
  cout << res << endl;
  for (int i = 0; i < n; i++)
    if ((arr[i].l <= sst && arr[i].r >= send) || res == 0) {
      cout << i + 1 << " ";
      k--;
      if (k == 0) break;
    }
}

```


### Prompt

Develop a solution in cpp to the problem described below:

Gildong has an interesting machine that has an array a with n integers. The machine supports two kinds of operations:

  1. Increase all elements of a suffix of the array by 1.
  2. Decrease all elements of a suffix of the array by 1.

A suffix is a subsegment (contiguous elements) of the array that contains a_n. In other words, for all i where a_i is included in the subsegment, all a_j's where i < j ≤ n must also be included in the subsegment.

Gildong wants to make all elements of a equal — he will always do so using the minimum number of operations necessary. To make his life even easier, before Gildong starts using the machine, you have the option of changing one of the integers in the array to any other integer. You are allowed to leave the array unchanged. You want to minimize the number of operations Gildong performs. With your help, what is the minimum number of operations Gildong will perform?

Note that even if you change one of the integers in the array, you should not count that as one of the operations because Gildong did not perform it.

Input

Each test contains one or more test cases. The first line contains the number of test cases t (1 ≤ t ≤ 1000).

Each test case contains two lines. The first line of each test case consists of an integer n (2 ≤ n ≤ 2 ⋅ 10^5) — the number of elements of the array a.

The second line of each test case contains n integers. The i-th integer is a_i (-5 ⋅ 10^8 ≤ a_i ≤ 5 ⋅ 10^8).

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

Output

For each test case, print one integer — the minimum number of operations Gildong has to perform in order to make all elements of the array equal.

Example

Input

7
2
1 1
3
-1 0 2
4
99 96 97 95
4
-3 -5 -2 1
6
1 4 3 2 4 1
5
5 0 0 0 5
9
-367741579 319422997 -415264583 -125558838 -300860379 420848004 294512916 -383235489 425814447

Output

0
1
3
4
6
5
2847372102

Note

In the first case, all elements of the array are already equal. Therefore, we do not change any integer and Gildong will perform zero operations.

In the second case, we can set a_3 to be 0, so that the array becomes [-1,0,0]. Now Gildong can use the 2-nd operation once on the suffix starting at a_2, which means a_2 and a_3 are decreased by 1, making all elements of the array -1.

In the third case, we can set a_1 to 96, so that the array becomes [96,96,97,95]. Now Gildong needs to:

  * Use the 2-nd operation on the suffix starting at a_3 once, making the array [96,96,96,94].
  * Use the 1-st operation on the suffix starting at a_4 2 times, making the array [96,96,96,96].

In the fourth case, we can change the array into [-3,-3,-2,1]. Now Gildong needs to:

  * Use the 2-nd operation on the suffix starting at a_4 3 times, making the array [-3,-3,-2,-2].
  * Use the 2-nd operation on the suffix starting at a_3 once, making the array [-3,-3,-3,-3].

### Response

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

#define ll long long
#define fast()  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define f(i,s,n) for(i=s;i<n;i++)
#define pb push_back
#define mll map<long long,long long>
#define umll unordered_map<long long,long long>
#define pll pair<long long,long long>
#define vl vector<long long>
#define sl set<long long>
#define fi first
#define se second
#define inf 1e18

ll i,j,k;

void solve();
int main() {
     fast();
     ll t=1;
     cin>>t;
    while(t--)
    {
        solve();
    }
	return 0;
}

void solve()
{
   ll n;
   cin>>n;
   ll a[n];
   f(i,0,n)
   cin>>a[i];

   ll flag = 0;
   f(i,1,n)
   {
       if(a[i]!=a[i-1])
       {
           flag = 1;
           break;
       }
   }
   if(flag==0)
   cout<<0<<endl;
   else
   {
       ll sum = 0;
       f(i,0,n)
       sum+=a[i];

       double avg = (double)sum/(double)n;

          ll mm = 0,b=0;
          f(i,1,n)
          {
              mm+=abs(a[i]-a[i-1]);
          }
          b = mm - abs(a[0]-a[1]);
          b = min(b,mm-abs(a[n-1]-a[n-2]));
          ll c  =0;
          f(i,1,n-1)
          {
              c = mm;
              c-= abs(a[i]-a[i-1]);
              c-= abs(a[i]-a[i+1]);
              c+=abs(a[i-1]-a[i+1]);
              b = min(b,c);

          }
          cout<<b<<endl;
         /*ll x = a[0],maxi=0,mini=INT_MAX,count = 0,dp[n]={0};
          for(i=0;i<n;i++)
          {
              ll u = abs(x-a[i]);
              dp[i] = u;
              maxi = max(maxi,u);
              mini = min(mini,u);
          }
         f(i,0,n)
          cout<<dp[i]<<" ";
          cout<<endl;
          f(i,1,n)
          {
              dp[i] -= dp[i-1];
          }
           f(i,0,n)
          cout<<dp[i]<<" ";
          cout<<endl;

          cout<<count<<endl;*/

   }
}
```


### Prompt

Generate a Cpp solution to the following problem:

The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai.

Additionally the Little Elephant has m queries to the array, each query is characterised by a pair of integers lj and rj (1 ≤ lj ≤ rj ≤ n). For each query lj, rj the Little Elephant has to count, how many numbers x exist, such that number x occurs exactly x times among numbers alj, alj + 1, ..., arj.

Help the Little Elephant to count the answers to all queries.

Input

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the size of array a and the number of queries to it. The next line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). Next m lines contain descriptions of queries, one per line. The j-th of these lines contains the description of the j-th query as two space-separated integers lj and rj (1 ≤ lj ≤ rj ≤ n).

Output

In m lines print m integers — the answers to the queries. The j-th line should contain the answer to the j-th query.

Examples

Input

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

Output

3
1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
map<int, int> match;
int tree[100010], n, m, num, ans[100010], val[100010], f[100010], p[100010];
vector<int> vc[100010];
struct node {
  int l, r, pos;
} op[100010];
bool cmp(node a, node b) { return a.r < b.r; }
int lowbit(int x) { return x & (-x); }
void update(int x, int val) {
  for (; x <= n; x += lowbit(x)) tree[x] += val;
}
int query(int x) {
  int ret = 0;
  for (; x > 0; x -= lowbit(x)) ret += tree[x];
  return ret;
}
int main() {
  int i, j, k, pos;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &val[i]);
    f[i] = val[i];
  }
  sort(f + 1, f + 1 + n);
  for (i = 1; i <= n; i++)
    if (f[i] != f[i - 1]) {
      num++;
      match[f[i]] = num;
    }
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &op[i].l, &op[i].r);
    op[i].pos = i;
  }
  for (i = 1; i <= num; i++) vc[i].push_back(0);
  sort(op + 1, op + 1 + m, cmp);
  op[m + 1].r = 0;
  pos = 1;
  for (i = 1; i <= n; i++) {
    k = match[val[i]];
    p[k]++;
    vc[k].push_back(i);
    if (p[k] >= val[i]) {
      update(vc[k][p[k] - val[i]] + 1, 1);
      update(vc[k][p[k] - val[i] + 1] + 1, -1);
      if (p[k] > val[i]) {
        update(vc[k][p[k] - val[i] - 1] + 1, -1);
        update(vc[k][p[k] - val[i]] + 1, 1);
      }
    }
    while (op[pos].r == i) {
      ans[op[pos].pos] = query(op[pos].l);
      pos++;
    }
  }
  for (i = 1; i <= m; i++) printf("%d\n", ans[i]);
}

```


### Prompt

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

For a non-negative integer K, we define a fractal of level K as follows:

* A fractal of level 0 is a grid with just one white square.
* When K > 0, a fractal of level K is a 3^K \times 3^K grid. If we divide this grid into nine 3^{K-1} \times 3^{K-1} subgrids:
* The central subgrid consists of only black squares.
* Each of the other eight subgrids is a fractal of level K-1.

For example, a fractal of level 2 is as follows:

A fractal of level 2

In a fractal of level 30, let (r, c) denote the square at the r-th row from the top and the c-th column from the left.

You are given Q quadruples of integers (a_i, b_i, c_i, d_i). For each quadruple, find the distance from (a_i, b_i) to (c_i, d_i).

Here the distance from (a, b) to (c, d) is the minimum integer n that satisfies the following condition:

* There exists a sequence of white squares (x_0, y_0), \ldots, (x_n, y_n) satisfying the following conditions:
* (x_0, y_0) = (a, b)
* (x_n, y_n) = (c, d)
* For every i (0 \leq i \leq n-1), (x_i, y_i) and (x_{i+1}, y_{i+1}) share a side.

Constraints

* 1 \leq Q \leq 10000
* 1 \leq a_i, b_i, c_i, d_i \leq 3^{30}
* (a_i, b_i) \neq (c_i, d_i)
* (a_i, b_i) and (c_i, d_i) are white squares.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:

Q
a_1 \ b_1 \ c_1 \ d_1
:
a_Q \ b_Q \ c_Q \ d_Q

Output

Print Q lines. The i-th line should contain the distance from (a_i, b_i) to (c_i, d_i).

Example

Input

2
4 2 7 4
9 9 1 9

Output

5
8

### Response

```cpp
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

ll t3[31];
void solve() {
	t3[0] = 1;
	rep(i, 30) {
		t3[i + 1] = t3[i] * 3;
	}
		ll x[2], y[2];
		cin >> x[0] >> y[0] >> x[1] >> y[1];
		rep(i, 2) {
			x[i]--; y[i]--;
		}

		if (x[0] > x[1]) {
			swap(x[0], x[1]);
			swap(y[0], y[1]);
		}
		ll ans = abs(x[1] - x[0]) + abs(y[1] - y[0]);
		for (int t = 29; t >= 0; t--) {
			ll dx = x[0] / t3[t+1];
			ll gdx = x[1] / t3[t + 1];
			ll dy = y[0] / t3[t + 1];
			ll gdy = y[1] / t3[t + 1];

			if (dx == gdx) {
				ll rx = x[0] % t3[t + 1];
				ll grx = x[1] % t3[t + 1];
				if (t3[t] <= rx && rx < 2 * t3[t] && t3[t] <= grx && grx < 2 * t3[t]) {
					bool prob = true;
					if (dy == gdy) {
						ll ry = y[0] % t3[t + 1];
						ll gry = y[1] % t3[t + 1];
						prob = false;
						if (ry < t3[t] && gry >= 2 * t3[t])prob = true;
						if (gry < t3[t] && ry >= 2 * t3[t])prob = true;
					}
					else {
						ll yy = abs(y[1] - y[0]);
						if (yy < 2 * t3[t])prob = false;
					}
					if (prob) {
						ll ori = abs(x[1] - x[0]);
						ll nexu = rx - t3[t] + 1 + grx - t3[t] + 1;
						ll nexd = 2 * t3[t] - rx + 2 * t3[t] - grx;
						ll ad = min(nexu, nexd) - ori;
						//cout << "izyou x " << t << endl;
						cout << ans + ad << endl; return;
					}
				}
			}
			if (dy == gdy) {
				ll ry = y[0] % t3[t + 1];
				ll gry = y[1] % t3[t + 1];
				if (t3[t] <= ry && ry < 2 * t3[t] && t3[t] <= gry && gry < 2 * t3[t]) {
					bool prob = true;
					if (dx == gdx) {
						ll rx = x[0] % t3[t + 1];
						ll grx = x[1] % t3[t + 1];
						prob = false;
						if (rx < t3[t] && grx >= 2 * t3[t])prob = true;
						if (grx < t3[t] && rx >= 2 * t3[t])prob = true;
					}
					else {
						ll xx = abs(x[1] - x[0]);
						if (xx < 2 * t3[t])prob = false;
					}
					if (prob) {
						ll ori = abs(y[1] - y[0]);
						ll nexu = ry - t3[t] + 1 + gry - t3[t] + 1;
						ll nexd = 2 * t3[t] - ry + 2 * t3[t] - gry;
						ll ad = min(nexu, nexd) - ori;
						//cout << "izyou y " << t << endl;
						cout << ans + ad << endl; return;
					}
				}
			}
		}
		//cout << "hutuu" << endl;
		cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init_f();
	//init();
	int t; cin >> t; rep(i, t)solve();
	//solve();
	stop
		return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

You are given the array a consisting of n elements and the integer k ≤ n.

You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operations:

  * Take one of the minimum elements of the array and increase its value by one (more formally, if the minimum value of a is mn then you choose such index i that a_i = mn and set a_i := a_i + 1);
  * take one of the maximum elements of the array and decrease its value by one (more formally, if the maximum value of a is mx then you choose such index i that a_i = mx and set a_i := a_i - 1).

Your task is to calculate the minimum number of moves required to obtain at least k equal elements in the array.

Input

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and the required number of equal elements.

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is the i-th element of a.

Output

Print one integer — the minimum number of moves required to obtain at least k equal elements in the array.

Examples

Input

6 5
1 2 2 4 2 3

Output

3

Input

7 5
3 3 2 1 1 1 3

Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  vector<vector<int> > DATA(2123456);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    int cnt = 0;
    while (x > 0) {
      DATA[x].push_back(cnt);
      cnt++;
      x /= 2;
    }
    DATA[0].push_back(cnt);
  }
  int answer = 987654321;
  for (int i = 0; i <= 2123456; i++) {
    if (DATA[i].size() < k) {
      continue;
    }
    sort(DATA[i].begin(), DATA[i].end());
    int answer1 = 0;
    for (int j = 0; j < k; j++) {
      answer1 += DATA[i][j];
    }
    answer = min(answer, answer1);
  }
  cout << answer;
  return 0;
}

```


### Prompt

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

This problem only differs from the next problem in constraints.

This is an interactive problem.

Alice and Bob are playing a game on the chessboard of size n × m where n and m are even. The rows are numbered from 1 to n and the columns are numbered from 1 to m. There are two knights on the chessboard. A white one initially is on the position (x_1, y_1), while the black one is on the position (x_2, y_2). Alice will choose one of the knights to play with, and Bob will use the other one.

The Alice and Bob will play in turns and whoever controls the white knight starts the game. During a turn, the player must move their knight adhering the chess rules. That is, if the knight is currently on the position (x, y), it can be moved to any of those positions (as long as they are inside the chessboard):

(x+1, y+2), (x+1, y-2), (x-1, y+2), (x-1, y-2),

(x+2, y+1), (x+2, y-1), (x-2, y+1), (x-2, y-1).

We all know that knights are strongest in the middle of the board. Both knight have a single position they want to reach:

  * the owner of the white knight wins if it captures the black knight or if the white knight is at (n/2, m/2) and this position is not under attack of the black knight at this moment;
  * The owner of the black knight wins if it captures the white knight or if the black knight is at (n/2+1, m/2) and this position is not under attack of the white knight at this moment.

Formally, the player who captures the other knight wins. The player who is at its target square ((n/2, m/2) for white, (n/2+1, m/2) for black) and this position is not under opponent's attack, also wins.

A position is under attack of a knight if it can move into this position. Capturing a knight means that a player moves their knight to the cell where the opponent's knight is.

If Alice made 350 moves and nobody won, the game is a draw.

Alice is unsure in her chess skills, so she asks you for a help. Choose a knight and win the game for her. It can be shown, that Alice always has a winning strategy.

Interaction

The interaction starts with two integers n and m (6 ≤ n,m ≤ 40, n and m are even) — the dimensions of the chessboard.

The second line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1, x_2 ≤ n, 1 ≤ y_1, y_2 ≤ m) — the positions of the white and the black knight. It is guaranteed that the two knights have different starting positions. It is also guaranteed that none of the knights are in their own target square in the beginning of the game (however, they can be on the opponent's target position).

Your program should reply with either "WHITE" or "BLACK", depending on the knight you want to play with. In case you select the white knight, you start the game.

During every your turn, you need to print two integers: x and y, the position to move the knight. If you won the game by this turn, you must terminate your program immediately.

After every turn of the opponent, you will receive two integers: x and y, the position where Bob moved his knight.

If your last move was illegal or you lost the game after jury's turn, or you made 350 moves, and haven't won, you will receive "-1 -1". In such cases, you should terminate your program and then you will get a Wrong Answer verdict.

After printing anything, do not forget to output the end of line and flush the output. Otherwise, you might get Idleness limit exceeded. To do this, use:

  * fflush(stdout) or cout.flush() in C++;
  * System.out.flush() in Java;
  * flush(output) in Pascal;
  * stdout.flush() in Python;
  * see documentation for other languages.

Hacks are disabled for this problem.

Jury's program is adaptive: the moves of jury may depend on the moves made by your program.

Examples

Input

8 8
2 3 1 8

Output

WHITE
4 4

Input

6 6
4 4 2 2
6 3

Output

BLACK
4 3

Note

In the first example, the white knight can reach it's target square in one move.

In the second example black knight wins, no matter what white knight moves.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int INFi = 2e9 + 5;
const int maxN = 40;
const int md = 239;
const long long INF = 2e18;
int win[maxN][maxN][maxN][maxN];
int tox[maxN][maxN][maxN][maxN];
int toy[maxN][maxN][maxN][maxN];
int deg[maxN][maxN][maxN][maxN];
bool ended[maxN][maxN][maxN][maxN];
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j)
      for (int e = 0; e < (n); ++e)
        for (int w = 0; w < (m); ++w) {
          win[i][j][e][w] = tox[i][j][e][w] = toy[i][j][e][w] = -1;
        }
  queue<array<int, 4>> q;
  vector<int> dx = {-1, 1, -2, 2, -1, 1, -2, 2};
  vector<int> dy = {2, 2, 1, 1, -2, -2, -1, -1};
  int X = n / 2 - 1;
  int Y = m / 2 - 1;
  for (int x1 = 0; x1 < (n); ++x1)
    for (int y1 = 0; y1 < (m); ++y1)
      for (int x2 = 0; x2 < (n); ++x2)
        for (int y2 = 0; y2 < (m); ++y2) {
          if (x1 == x2 && y1 == y2) {
            win[x1][y1][x2][y2] = 0;
            q.push({x1, y1, x2, y2});
            ended[x1][y1][x2][y2] = true;
            continue;
          }
          int xd = abs(x1 - x2);
          int yd = abs(y1 - y2);
          if (xd + yd == 3 && xd && yd) {
            win[x1][y1][x2][y2] = 1;
            tox[x1][y1][x2][y2] = x2;
            toy[x1][y1][x2][y2] = y2;
            q.push({x1, y1, x2, y2});
            continue;
          }
          if (x1 == X && y1 == Y) {
            win[x1][y1][x2][y2] = 1;
            ended[x1][y1][x2][y2] = true;
            q.push({x1, y1, x2, y2});
            continue;
          }
          if (x2 == X + 1 && y2 == Y) {
            win[x1][y1][x2][y2] = 0;
            ended[x1][y1][x2][y2] = true;
            q.push({x1, y1, x2, y2});
            continue;
          }
          for (int w = 0; w < (8); ++w) {
            int xx = x1 + dx[w];
            int yy = y1 + dy[w];
            if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue;
            deg[x1][y1][x2][y2]++;
          }
        }
  while (!q.empty()) {
    auto [x1, y1, x2, y2] = q.front();
    q.pop();
    if (win[x1][y1][x2][y2]) {
      int xx1 = n - 1 - x2;
      int yy1 = y2;
      int xx2 = n - 1 - x1;
      int yy2 = y1;
      for (int w = 0; w < (8); ++w) {
        int xx = xx1 + dx[w];
        int yy = yy1 + dy[w];
        if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue;
        if (win[xx][yy][xx2][yy2] != -1) continue;
        if (!(--deg[xx][yy][xx2][yy2])) {
          win[xx][yy][xx2][yy2] = 0;
          q.push({xx, yy, xx2, yy2});
        }
      }
    } else {
      int xx1 = n - 1 - x2;
      int yy1 = y2;
      int xx2 = n - 1 - x1;
      int yy2 = y1;
      for (int w = 0; w < (8); ++w) {
        int xx = xx1 + dx[w];
        int yy = yy1 + dy[w];
        if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue;
        if (win[xx][yy][xx2][yy2] != -1) continue;
        win[xx][yy][xx2][yy2] = 1;
        tox[xx][yy][xx2][yy2] = xx1;
        toy[xx][yy][xx2][yy2] = yy1;
        q.push({xx, yy, xx2, yy2});
      }
    }
  }
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  x1--;
  y1--;
  x2--;
  y2--;
  if (win[x1][y1][x2][y2] == 1) {
    cout << "WHITE" << endl;
    while (true) {
      assert(win[x1][y1][x2][y2] == 1);
      if (ended[x1][y1][x2][y2]) return;
      int x11 = tox[x1][y1][x2][y2];
      int y11 = toy[x1][y1][x2][y2];
      cout << x11 + 1 << ' ' << y11 + 1 << endl;
      if (ended[n - 1 - x2][y2][n - 1 - x11][y11]) return;
      int x22, y22;
      cin >> x22 >> y22;
      if (x22 == -1) exit(0);
      x1 = x11;
      y1 = y11;
      x2 = x22 - 1;
      y2 = y22 - 1;
    }
  } else {
    cout << "BLACK" << endl;
    swap(x1, x2);
    swap(y1, y2);
    x1 = n - 1 - x1;
    x2 = n - 1 - x2;
    cin >> x2 >> y2;
    x2--;
    y2--;
    x2 = n - 1 - x2;
    while (true) {
      assert(win[x1][y1][x2][y2] == 1);
      if (ended[x1][y1][x2][y2]) return;
      int x11 = tox[x1][y1][x2][y2];
      int y11 = toy[x1][y1][x2][y2];
      cout << n - x11 << ' ' << y11 + 1 << endl;
      if (ended[n - 1 - x2][y2][n - 1 - x11][y11]) return;
      int x22, y22;
      cin >> x22 >> y22;
      if (x22 == -1) exit(0);
      x1 = x11;
      y1 = y11;
      x2 = x22 - 1;
      y2 = y22 - 1;
      x2 = n - x2 - 1;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tests = 1;
  for (int _ = 0; _ < (tests); ++_) {
    solve();
  }
  return 0;
}

```


### Prompt

Please create a solution in cpp to the following problem:

Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 ≤ i ≤ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.

Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.

For example, if Monocarp wants to draw four segments with lengths 1, 2, 3 and 4, he can do it the following way:

<image> Here, Monocarp has drawn segments AB (with length 1), CD (with length 2), BC (with length 3) and EF (with length 4). He got a rectangle ABCF with area equal to 3 that is enclosed by the segments.

Calculate the maximum area of a rectangle Monocarp can enclose with four segments.

Input

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

Each test case consists of a single line containing four integers a_1, a_2, a_3, a_4 (1 ≤ a_i ≤ 10^4) — the lengths of the segments Monocarp wants to draw.

Output

For each test case, print one integer — the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).

Example

Input

4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100

Output

3
25
3
2000

Note

The first test case of the example is described in the statement.

For the second test case, Monocarp can draw the segments AB, BC, CD and DA as follows:

<image> Here, Monocarp has drawn segments AB (with length 5), BC (with length 5), CD (with length 5) and DA (with length 5). He got a rectangle ABCD with area equal to 25 that is enclosed by the segments.

### Response

```cpp
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin>>t;
    while(t--) {
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        int arr[4] = {a,b,c,d};
        sort(arr, arr + 4);
        cout<<arr[0] * arr[2]<<endl;
    }
}
```


### Prompt

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

Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other one, using only the existing roads.

The President of Berland decided to make changes to the road system and instructed the Ministry of Transport to make this reform. Now, each road should be unidirectional (only lead from one city to another).

In order not to cause great resentment among residents, the reform needs to be conducted so that there can be as few separate cities as possible. A city is considered separate, if no road leads into it, while it is allowed to have roads leading from this city.

Help the Ministry of Transport to find the minimum possible number of separate cities after the reform.

Input

The first line of the input contains two positive integers, n and m — the number of the cities and the number of roads in Berland (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000).

Next m lines contain the descriptions of the roads: the i-th road is determined by two distinct integers xi, yi (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi and yi are the numbers of the cities connected by the i-th road.

It is guaranteed that there is no more than one road between each pair of cities, but it is not guaranteed that from any city you can get to any other one, using only roads.

Output

Print a single integer — the minimum number of separated cities after the reform.

Examples

Input

4 3
2 1
1 3
4 3

Output

1

Input

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

Output

0

Input

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

Output

1

Note

In the first sample the following road orientation is allowed: <image>, <image>, <image>.

The second sample: <image>, <image>, <image>, <image>, <image>.

The third sample: <image>, <image>, <image>, <image>, <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int dfs_(int n, vector<vector<int>> &adj_list) {
  set<int> unvisited;
  for (int i = 1; i <= n; i++) unvisited.insert(i);
  int count = 0;
  while (!unvisited.empty()) {
    auto iter_set = unvisited.begin();
    int start_node = *iter_set;
    bool cycle = 0;
    stack<int> st;
    st.push(start_node);
    unvisited.erase(start_node);
    int prev_node = start_node;
    while (!st.empty()) {
      int cur_node = st.top();
      st.pop();
      for (auto &iter : adj_list[cur_node]) {
        if (unvisited.find(iter) != unvisited.end()) {
          st.push(iter);
          prev_node = iter;
          unvisited.erase(iter);
        } else if (iter != prev_node && iter != start_node) {
          cycle = true;
        }
      }
      prev_node = cur_node;
    }
    if (!cycle) count++;
  }
  return count;
}
bool visited[100001];
int levels[100001];
int temp_count = 0;
int res_count = 0;
void dfs(int src, vector<vector<int>> &adj_list) {
  visited[src] = true;
  for (auto &iter : adj_list[src]) {
    if (!visited[iter]) {
      levels[iter] = levels[src] + 1;
      dfs(iter, adj_list);
    } else if (levels[iter] > levels[src] + 1) {
      temp_count++;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  int x, y;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) visited[i] = false;
  for (int i = 1; i <= n; i++) levels[i] = 0;
  vector<vector<int>> adj_list(n + 1);
  for (int i = 0; i < m; ++i) {
    cin >> x >> y;
    adj_list[x].push_back(y);
    adj_list[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      temp_count = 0;
      dfs(i, adj_list);
      if (temp_count == 0) res_count++;
    }
  }
  cout << res_count << endl;
}

```


### Prompt

Generate a cpp solution to the following problem:

Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).

In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.

Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.

Input

The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.

Output

For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.

Examples

Input

2
1 2
2 1

Output

2 0
2 0

Input

3
1 2
2 1
1 3

Output

3 1
4 0
2 2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n;
  cin >> n;
  long long arr[n][2];
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++)
    cin >> arr[i][0] >> arr[i][1], mp[arr[i][0]]++;
  long long brr[n][2];
  for (long long i = 0; i < n; i++) brr[i][1] = n - 1, brr[i][0] = n - 1;
  for (long long i = 0; i < n; i++) {
    long long x = mp[arr[i][1]];
    brr[i][0] += x, brr[i][1] -= x;
  }
  for (long long i = 0; i < n; i++)
    cout << brr[i][0] << ' ' << brr[i][1] << endl;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

The only difference between easy and hard versions is constraints.

A session has begun at Beland State University. Many students are taking exams.

Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:

  * The i-th student randomly chooses a ticket.
  * if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
  * if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.

Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.

The duration of the whole exam for all students is M minutes (max t_i ≤ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.

For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.

For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.

Input

The first line of the input contains two integers n and M (1 ≤ n ≤ 100, 1 ≤ M ≤ 100) — the number of students and the total duration of the exam in minutes, respectively.

The second line of the input contains n integers t_i (1 ≤ t_i ≤ 100) — time in minutes that i-th student spends to answer to a ticket.

It's guaranteed that all values of t_i are not greater than M.

Output

Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.

Examples

Input

7 15
1 2 3 4 5 6 7

Output

0 0 0 0 0 2 3

Input

5 100
80 40 40 40 60

Output

0 1 1 2 3

Note

The explanation for the example 1.

Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.

In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).

In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int mx = 1e6 + 5;
const int INF = 1000000007;
long long power(int x, unsigned int y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y >>= 1;
    x *= x;
  }
  return res;
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<long long> arr(n);
  cin >> arr;
  vector<long long> count(101, 0);
  long long total_sum = arr[0];
  count[arr[0]]++;
  cout << 0 << ' ';
  for (int i = 1; i < n; i++) {
    long long curr_sum = total_sum + arr[i] - m;
    long long ref = 0;
    if (curr_sum > 0) {
      for (int j = 100; j > 0; j--) {
        long long x = j * count[j];
        if (curr_sum <= x) {
          ref += ceil(curr_sum * 1.0 / j);
          break;
        }
        ref += count[j];
        curr_sum -= x;
      }
    }
    count[arr[i]]++;
    total_sum += arr[i];
    cout << ref << ' ';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
}

```


### Prompt

Please formulate a cpp solution to the following problem:

One day Petya was solving a very interesting problem. But although he used many optimization techniques, his solution still got Time limit exceeded verdict. Petya conducted a thorough analysis of his program and found out that his function for finding maximum element in an array of n positive integers was too slow. Desperate, Petya decided to use a somewhat unexpected optimization using parameter k, so now his function contains the following code:

    int fast_max(int n, int a[]) {
        int ans = 0;
        int offset = 0;
        for (int i = 0; i < n; ++i)
            if (ans < a[i]) {
                ans = a[i];
                offset = 0;
            } else {
                offset = offset + 1;
                if (offset == k)
                    return ans;
            }
        return ans;
    }

That way the function iteratively checks array elements, storing the intermediate maximum, and if after k consecutive iterations that maximum has not changed, it is returned as the answer.

Now Petya is interested in fault rate of his function. He asked you to find the number of permutations of integers from 1 to n such that the return value of his function on those permutations is not equal to n. Since this number could be very big, output the answer modulo 109 + 7.

Input

The only line contains two integers n and k (1 ≤ n, k ≤ 106), separated by a space — the length of the permutations and the parameter k.

Output

Output the answer to the problem modulo 109 + 7.

Examples

Input

5 2

Output

22

Input

5 3

Output

6

Input

6 3

Output

84

Note

Permutations from second example:

[4, 1, 2, 3, 5], [4, 1, 3, 2, 5], [4, 2, 1, 3, 5], [4, 2, 3, 1, 5], [4, 3, 1, 2, 5], [4, 3, 2, 1, 5].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long mod = 1e9 + 7;
unordered_map<int, int> cache;
int inv(int a) {
  if (a == 1) return 1;
  if (cache.count(a)) return cache[a];
  int x = (mod + a - 1) / a;
  int b = (a * x) % mod;
  return cache[a] = ((long long)inv(b) * x) % mod;
}
int n, k;
long long E[1000005];
long long ES[1000005];
long long fact[1000005];
int main(void) {
  fact[0] = 1;
  for (int i = 1; i <= 1000000; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  scanf(" %d %d", &n, &k);
  E[0] = E[1] = 0;
  ES[0] = ES[1] = 0;
  long long finv = 1LL;
  for (int m = 2; m <= n; m++) {
    finv *= inv(m - 1);
    finv %= mod;
    if (m - k < 1) {
      E[m] = ES[m] = 0;
      continue;
    }
    long long sum = (ES[m - 1] - ES[m - k - 1] + mod) % mod;
    long long D = fact[m - 2] * (sum + max(m - 1 - k, 0));
    D %= mod;
    E[m] = (D * finv) % mod;
    ES[m] = (ES[m - 1] + E[m]) % mod;
  }
  cout << (fact[n - 1] * ES[n]) % mod << endl;
  return 0;
}

```


### Prompt

Please create a solution in CPP to the following problem:

Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.

The world can be modeled as an undirected graph with n nodes and m edges. k of the nodes are home to the governments of the k countries that make up the world.

There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.

Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add.

Input

The first line of input will contain three integers n, m and k (1 ≤ n ≤ 1 000, 0 ≤ m ≤ 100 000, 1 ≤ k ≤ n) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government.

The next line of input will contain k integers c1, c2, ..., ck (1 ≤ ci ≤ n). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world.

The following m lines of input will contain two integers ui and vi (1 ≤ ui, vi ≤ n). This denotes an undirected edge between nodes ui and vi.

It is guaranteed that the graph described by the input is stable.

Output

Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable.

Examples

Input

4 1 2
1 3
1 2

Output

2

Input

3 3 1
2
1 2
1 3
2 3

Output

0

Note

For the first sample test, the graph looks like this:

<image> Vertices 1 and 3 are special. The optimal solution is to connect vertex 4 to vertices 1 and 2. This adds a total of 2 edges. We cannot add any more edges, since vertices 1 and 3 cannot have any path between them.

For the second sample test, the graph looks like this:

<image> We cannot add any more edges to this graph. Note that we are not allowed to add self-loops, and the graph must be simple.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool isSpecial[112345] = {false};
vector<int> adj[112345];
bool vis[112345];
long long int vCnt, eCnt, maxV = 0, spare = 0;
bool spcThr = false;
void dfs(int u) {
  vis[u] = true;
  if (isSpecial[u]) {
    spcThr = true;
  }
  vCnt++;
  for (int i = 0; i < adj[u].size(); ++i) {
    int v = adj[u][i];
    if (u < v) {
      eCnt++;
    }
    if (vis[v] == false) {
      dfs(v);
    }
  }
}
int main() {
  int n, m, k;
  long long int ans = 0;
  cin >> n >> m >> k;
  for (int i = 0; i < k; ++i) {
    int c;
    scanf("%d", &c);
    isSpecial[c] = true;
  }
  while (m--) {
    int u, v;
    scanf("%d", &u);
    scanf("%d", &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i < n + 1; ++i) {
    if (vis[i] == false) {
      spcThr = false;
      vCnt = 0;
      eCnt = 0;
      dfs(i);
      ans += (vCnt * (vCnt - 1)) / 2 - eCnt;
      if (spcThr) {
        maxV = max(maxV, vCnt);
      } else {
        ans += spare * vCnt;
        spare += vCnt;
      }
    }
  }
  ans += maxV * spare;
  cout << ans << endl;
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

Janusz is a businessman. He owns a company "Januszex", which produces games for teenagers. Last hit of Januszex was a cool one-person game "Make it one". The player is given a sequence of n integers a_i.

It is allowed to select any subset of them, and the score is equal to the greatest common divisor of selected elements. The goal is to take as little elements as it is possible, getting the score 1. Now Janusz wonders, for given sequence, how much elements should the player choose?

Input

The first line contains an only integer n (1 ≤ n ≤ 300 000) — the number of integers in the sequence.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300 000).

Output

If there is no subset of the given sequence with gcd equal to 1, output -1.

Otherwise, output exactly one integer — the size of the smallest subset with gcd equal to 1.

Examples

Input

3
10 6 15

Output

3

Input

3
2 4 6

Output

-1

Input

7
30 60 21 42 70 15 30

Output

3

Note

In the first example, selecting a subset of all numbers gives a gcd of 1 and for all smaller subsets the gcd is greater than 1.

In the second example, for all subsets of numbers the gcd is at least 2.

### Response

```cpp
#include <bits/stdc++.h>
const int maxn = 333333;
int np[maxn], mp[maxn], mu[maxn], pr[maxn], pn;
int a[maxn], c[maxn], g[maxn], n;
int In() {
  register int c, f, s;
  for (; c = getchar(), c != '-' && !isdigit(c);)
    ;
  for (s = (f = c == '-') ? 0 : c - '0'; c = getchar(), isdigit(c);)
    s = s * 10 + c - '0';
  return f ? -s : s;
}
bool cmin(register int &a, register int b) { return a > b ? (a = b, 1) : 0; }
int gcd(register int a, register int b) { return b ? gcd(b, a % b) : a; }
int main() {
  np[1] = 1, mu[1] = 1;
  for (register int i = 2; i <= 300000; ++i) {
    if (!np[i]) pr[++pn] = i, mp[i] = i, mu[i] = -1;
    for (register int j = 1; j <= pn && i * pr[j] <= 300000; ++j) {
      np[i * pr[j]] = 1, mp[i * pr[j]] = pr[j];
      if (i % pr[j])
        mu[i * pr[j]] = -mu[i];
      else {
        mu[i * pr[j]] = 0;
        break;
      }
    }
  }
  n = In();
  for (register int i = 1; i <= n; ++i) ++a[In()];
  for (register int i = 1; i <= 300000; ++i) g[i] = a[i] ? 1 : 0x3f3f3f3f;
  for (register int i = 1; i <= 300000; ++i)
    for (register int j = i * 2; j <= 300000; j += i) a[i] += a[j];
  for (register int i = 1; i <= 300000; ++i)
    if (mu[i])
      for (register int j = i; j <= 300000; j += i) c[j] += mu[i] * a[i];
  for (register int i = 300000; i >= 1; --i)
    for (register int j = i * 2; j <= 300000; j += i)
      if (c[j / i]) cmin(g[i], g[j] + 1);
  printf("%d\n", g[1] == 0x3f3f3f3f ? -1 : g[1]);
  return 0;
}

```


### Prompt

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

Smart Beaver is careful about his appearance and pays special attention to shoes so he has a huge number of pairs of shoes from the most famous brands of the forest. He's trying to handle his shoes carefully so that each pair stood side by side. But by the end of the week because of his very active lifestyle in his dressing room becomes a mess.

Smart Beaver from ABBYY is not only the brightest beaver in the area, but he also is the most domestically oriented. For example, on Mondays the Smart Beaver cleans everything in his home.

It's Monday morning. Smart Beaver does not want to spend the whole day cleaning, besides, there is much in to do and it’s the gym day, so he wants to clean up as soon as possible. Now the floors are washed, the dust is wiped off — it’s time to clean up in the dressing room. But as soon as the Smart Beaver entered the dressing room, all plans for the day were suddenly destroyed: chaos reigned there and it seemed impossible to handle, even in a week. Give our hero some hope: tell him what is the minimum number of shoes need to change the position to make the dressing room neat.

The dressing room is rectangular and is divided into n × m equal squares, each square contains exactly one shoe. Each pair of shoes has a unique number that is integer from 1 to <image>, more formally, a square with coordinates (i, j) contains an integer number of the pair which is lying on it. The Smart Beaver believes that the dressing room is neat only when each pair of sneakers lies together. We assume that the pair of sneakers in squares (i1, j1) and (i2, j2) lies together if |i1 - i2| + |j1 - j2| = 1.

Input

The first line contains two space-separated integers n and m. They correspond to the dressing room size. Next n lines contain m space-separated integers each. Those numbers describe the dressing room. Each number corresponds to a snicker.

It is guaranteed that:

  * n·m is even.
  * All numbers, corresponding to the numbers of pairs of shoes in the dressing room, will lie between 1 and <image>.
  * Each number from 1 to <image> will occur exactly twice.

The input limits for scoring 30 points are (subproblem C1):

  * 2 ≤ n, m ≤ 8.

The input limits for scoring 100 points are (subproblems C1+C2):

  * 2 ≤ n, m ≤ 80.

Output

Print exactly one integer — the minimum number of the sneakers that need to change their location.

Examples

Input

2 3
1 1 2
2 3 3

Output

2

Input

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

Output

4

Note

<image> The second sample.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int dp[10][1 << 10], num[10][10];
int n, m;
void OP(int msk) {
  for (int i = 0; i < m; i++)
    if (1 << i & msk)
      cout << 1;
    else
      cout << 0;
}
void shift(int &a, int b) {
  if (a == -1 || a > b) a = b;
}
void dfs(int p, int flag, int i, int msk, int cost, int nmsk) {
  if (p == m) {
    if (flag == 0) {
      shift(dp[i + 1][nmsk], cost + dp[i][msk]);
    }
    return;
  }
  if (1 << p & msk) {
    if (flag == 0) {
      int c = cost;
      if (num[i + 1][p] != num[i][p]) c++;
      dfs(p + 1, 0, i, msk, c, nmsk);
    }
  } else if (flag) {
    int c = cost;
    if (num[i + 1][p] != num[i + 1][p - 1]) c++;
    dfs(p + 1, 0, i, msk, c, nmsk);
  } else {
    int c = cost;
    dfs(p + 1, 0, i, msk, cost, nmsk | (1 << p));
    c = cost;
    dfs(p + 1, 1, i, msk, cost, nmsk);
  }
}
int main() {
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < m; j++) cin >> num[i][j];
  for (int i = 0; i < n; i++) {
    for (int msk = 0; msk < (1 << m); msk++)
      if (dp[i][msk] != -1) {
        dfs(0, 0, i, msk, 0, 0);
      }
  }
  cout << dp[n][0] << endl;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height h, and there is a moving platform on each height x from 1 to h.

Each platform is either hidden inside the cliff or moved out. At first, there are n moved out platforms on heights p_1, p_2, ..., p_n. The platform on height h is moved out (and the character is initially standing there).

If you character is standing on some moved out platform on height x, then he can pull a special lever, which switches the state of two platforms: on height x and x - 1. In other words, the platform you are currently standing on will hide in the cliff and the platform one unit below will change it state: it will hide if it was moved out or move out if it was hidden. In the second case, you will safely land on it. Note that this is the only way to move from one platform to another.

Your character is quite fragile, so it can safely fall from the height no more than 2. In other words falling from the platform x to platform x - 2 is okay, but falling from x to x - 3 (or lower) is certain death.

Sometimes it's not possible to come down from the cliff, but you can always buy (for donate currency) several magic crystals. Each magic crystal can be used to change the state of any single platform (except platform on height h, which is unaffected by the crystals). After being used, the crystal disappears.

What is the minimum number of magic crystal you need to buy to safely land on the 0 ground level?

Input

The first line contains one integer q (1 ≤ q ≤ 100) — the number of queries. Each query contains two lines and is independent of all other queries.

The first line of each query contains two integers h and n (1 ≤ h ≤ 10^9, 1 ≤ n ≤ min(h, 2 ⋅ 10^5)) — the height of the cliff and the number of moved out platforms.

The second line contains n integers p_1, p_2, ..., p_n (h = p_1 > p_2 > ... > p_n ≥ 1) — the corresponding moved out platforms in the descending order of their heights.

The sum of n over all queries does not exceed 2 ⋅ 10^5.

Output

For each query print one integer — the minimum number of magic crystals you have to spend to safely come down on the ground level (with height 0).

Example

Input

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

Output

0
1
2
0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void READ(vector<long long> &v, long long n) {
  long long a;
  for (long long i = 0; i < n; i = i + 1) {
    cin >> a;
    v.push_back(a);
  }
}
void PRINT(vector<long long> &v, long long a = 0) {
  for (long long i = a; i < v.size(); i = i + 1) {
    cout << v[i] << " ";
  }
  cout << "\n";
}
double logy(long long n, long long b) {
  if (b == 0) {
    return (-1);
  }
  if (n == 1) {
    return (0);
  }
  return ((double)log10(n) / log10(b));
}
long long power(long long k, long long n, long long m = 1000000007) {
  long long res = 1;
  while (n) {
    if (n % 2 != 0) {
      res = (res * k) % m;
    }
    k = (k * k) % m;
    n = n / 2;
  }
  return (res);
}
double power(double k, long long n) {
  double res = 1;
  while (n) {
    if (n % 2 != 0) {
      res = (res * k);
    }
    k = (k * k);
    n = n / 2;
  }
  return (res);
}
double distance(pair<long long, long long> a, pair<long long, long long> b) {
  return ((double)(sqrt((a.first - b.first) * (a.first - b.first) +
                        (a.second - b.second) * (a.second - b.second))));
}
const long long dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const long long dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vector<pair<long long, long long> > dr;
long long n, m, k, h;
bool ok = false;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  std::cout.unsetf(std::ios::floatfield);
  std::cout.precision((long long)10);
  long long a, b, c, d, i, j, t, x, y, z;
  double p, q, r, u, w;
  string str, st, str1, str2, str3, str4;
  cin >> t;
  while (t--) {
    cin >> h >> n;
    vector<long long> v;
    map<long long, long long> hai;
    for (i = 0; i < n; i++) {
      cin >> a;
      v.push_back(a);
      hai[a] = 1;
    }
    x = 0;
    for (j = 0; j < n;) {
      i = v[j];
      if (i <= 2) {
        break;
      }
      if (!hai[i - 1]) {
        if (i - 1 <= 2) {
          break;
        }
        j++;
        while (j < n) {
          if (hai[v[j]] && hai[v[j] - 1]) {
            j++;
            break;
          }
          if (v[j] <= 1) {
            break;
          }
          x++;
          j++;
        }
        if (j < n && v[j] <= 1) {
          break;
        }
        continue;
      }
      if (hai[i - 1] && hai[i - 2]) {
        j += 2;
        continue;
      }
      if (hai[i - 1]) {
        x++;
        if (i - 2 <= 2) {
          break;
        }
        j += 2;
        while (j < n) {
          if (hai[v[j]] && hai[v[j] - 1]) {
            j++;
            break;
          }
          if (v[j] <= 1) {
            break;
          }
          x++;
          j++;
        }
        if (j < n && v[j] <= 1) {
          break;
        }
      }
    }
    cout << x << "\n";
  }
}

```


### Prompt

Create a solution in Cpp for the following problem:

We have an N \times M grid. The square at the i-th row and j-th column will be denoted as (i,j). Particularly, the top-left square will be denoted as (1,1), and the bottom-right square will be denoted as (N,M). Takahashi painted some of the squares (possibly zero) black, and painted the other squares white.

We will define an integer sequence A of length N, and two integer sequences B and C of length M each, as follows:

* A_i(1\leq i\leq N) is the minimum j such that (i,j) is painted black, or M+1 if it does not exist.
* B_i(1\leq i\leq M) is the minimum k such that (k,i) is painted black, or N+1 if it does not exist.
* C_i(1\leq i\leq M) is the maximum k such that (k,i) is painted black, or 0 if it does not exist.

How many triples (A,B,C) can occur? Find the count modulo 998244353.

Constraints

* 1 \leq N \leq 8000
* 1 \leq M \leq 200
* N and M are integers.

Partial Score

* 1500 points will be awarded for passing the test set satisfying N\leq 300.

Constraints

* 1 \leq N \leq 8000
* 1 \leq M \leq 200
* N and M are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of triples (A,B,C), modulo 998244353.

Examples

Input

2 3

Output

64

Input

4 3

Output

2588

Input

17 13

Output

229876268

Input

5000 100

Output

57613837

### Response

```cpp
#include<bits/stdc++.h>
#define pb push_back
#define gc getchar
using namespace std;
const int N=5e4+10,mod=998244353,g=3;
typedef long long ll;
typedef double db;

int n,m,ans,f[N],h[N],t[N],frc[N],nv[N],ivg;

char cp;
template<class T>inline void rd(T &x)
{
	cp=gc();x=0;int f=0;
	for(;!isdigit(cp);cp=gc()) if(cp=='-') f=1;
	for(;isdigit(cp);cp=gc()) x=x*10+(cp^48);
	if(f) x=-x;
}

inline int fp(int x,int y)
{
	int re=1;
	for(;y;y>>=1,x=(ll)x*x%mod)
	  if(y&1) re=(ll)re*x%mod;
	return re;
}

inline int ad(int x,int y){x+=y;return x>=mod?x-mod:x;}
inline int dc(int x,int y){x-=y;return x<0?x+mod:x;}
inline int C(int n,int m)
{
	if(m>n) return 0;
	return (ll)frc[n]*nv[m]%mod*(ll)nv[n-m]%mod;
}

namespace poly{
   int rv[N],L,len;

   inline void ntt(int *e,int pr)
   {
   	   int i,j,k,ix,iy,pd,ori,G=pr?g:ivg;
   	   for(i=1;i<len;++i) if(i<rv[i]) swap(e[i],e[rv[i]]);
   	   for(i=1;i<len;i<<=1){
   	      ori=fp(G,(mod-1)/(i<<1));
   	      for(j=0;j<len;j+=(i<<1)){
   	      	for(pd=1,k=0;k<i;++k,pd=(ll)pd*ori%mod){
   	      		ix=e[j+k];iy=(ll)pd*e[j+i+k]%mod;
   	      		e[j+k]=ad(ix,iy);e[i+j+k]=dc(ix,iy);
			}
		  }
	   }
	   if(pr) return;
	   G=fp(len,mod-2);
	   for(i=0;i<len;++i) e[i]=(ll)e[i]*G%mod;
   }

   void mul(int *f,int *g,int n,int m)
   {
   	   int i;
   	   for(L=0,len=1;len<=n+m;len<<=1) L++;
	   for(i=1;i<len;++i) rv[i]=(rv[i>>1]>>1)|((i&1)<<(L-1));
	   for(i=n+1;i<len;++i) f[i]=0;
   	   for(i=m+1;i<len;++i) g[i]=0;
   	   ntt(f,1);ntt(g,1);
   	   for(i=0;i<len;++i) f[i]=(ll)f[i]*g[i]%mod;
	   ntt(f,0);
   }
}
using namespace poly;

int main(){
	int i,j,x,y;ivg=fp(g,mod-2);
	rd(n);rd(m);
	f[0]=frc[0]=nv[0]=frc[1]=nv[1]=1;
    for(i=2;i<n+3;++i)
	  frc[i]=(ll)frc[i-1]*i%mod,
	  nv[i]=(ll)(mod-mod/i)*nv[mod%i]%mod;
	for(i=2;i<n+3;++i) nv[i]=(ll)nv[i-1]*nv[i]%mod;
	for(i=1;i<=n;++i) h[i]=nv[i+2];
	for(L=0,len=1;len<=(n<<1);len<<=1) L++;
	for(i=1;i<len;++i) rv[i]=((rv[i>>1]>>1)|((i&1)<<(L-1)));
	ntt(h,1);
	for(j=1;j<=m;++j){
		for(i=0;i<=n;++i) t[i]=(ll)nv[i]*f[i]%mod;
		for(i=n+1;i<len;++i) t[i]=0;
		ntt(t,1);
		for(i=0;i<len;++i) t[i]=(ll)h[i]*t[i]%mod;
		ntt(t,0);
		for(i=0;i<=n;++i)
		 f[i]=ad((ll)(1+C(i+1,2))*f[i]%mod,(ll)t[i]*frc[i+2]%mod);
	}
	for(i=0;i<=n;++i) ans=ad(ans,(ll)C(n,i)*f[i]%mod);
	printf("%d",ans);
	return 0;
}
```


### Prompt

Please formulate a Cpp solution to the following problem:

At the beginning of the new semester there is new schedule in the Berland State University. According to this schedule, n groups have lessons at the room 31. For each group the starting time of the lesson and the finishing time of the lesson are known. It has turned out that it is impossible to hold all lessons, because for some groups periods of their lessons intersect. If at some moment of time one groups finishes it's lesson, and the other group starts the lesson, their lessons don't intersect.

The dean wants to cancel the lesson in one group so that no two time periods of lessons of the remaining groups intersect. You are to find all ways to do that.

Input

The first line contains integer n (1 ≤ n ≤ 5000) — amount of groups, which have lessons in the room 31. Then n lines follow, each of them contains two integers li ri (1 ≤ li < ri ≤ 106) — starting and finishing times of lesson of the i-th group. It is possible that initially no two lessons intersect (see sample 1).

Output

Output integer k — amount of ways to cancel the lesson in exactly one group so that no two time periods of lessons of the remaining groups intersect. In the second line output k numbers — indexes of groups, where it is possible to cancel the lesson. Groups are numbered starting from 1 in the order that they were given in the input. Output the numbers in increasing order.

Examples

Input

3
3 10
20 30
1 3

Output

3
1 2 3

Input

4
3 10
20 30
1 3
1 39

Output

1
4

Input

3
1 5
2 6
3 7

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct aaa {
  int l, r, num;
  bool us;
};
bool comp(const aaa a, const aaa b) { return a.l < b.l; }
int main() {
  aaa f[5002];
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &f[i].l, &f[i].r);
    f[i].num = i;
  }
  sort(f + 1, f + n + 1, comp);
  f[n + 1].l = 10000000;
  int res = 0;
  for (int i = 1; i <= n; i++) {
    f[i].us = false;
    bool flag = true;
    for (int j = 1; j < n; j++) {
      if (j != i) {
        if (i == j + 1) {
          if (f[j].r > f[j + 2].l) {
            flag = false;
            break;
          }
        } else {
          if (f[j].r > f[j + 1].l) {
            flag = false;
            break;
          }
        }
      }
    }
    if (flag) {
      res++;
      f[i].us = true;
    }
  }
  printf("%d\n", res);
  vector<int> p;
  for (int i = 1; i <= n; i++) {
    if (f[i].us) p.push_back(f[i].num);
  }
  sort(p.begin(), p.end());
  for (int i = 0; i < res; i++) {
    if (i == res - 1)
      printf("%d\n", p[i]);
    else
      printf("%d ", p[i]);
  }
  return 0;
}

```


### Prompt

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

We have 3N colored balls with IDs from 1 to 3N. A string S of length 3N represents the colors of the balls. The color of Ball i is red if S_i is `R`, green if S_i is `G`, and blue if S_i is `B`. There are N red balls, N green balls, and N blue balls.

Takahashi will distribute these 3N balls to N people so that each person gets one red ball, one blue ball, and one green ball. The people want balls with IDs close to each other, so he will additionally satisfy the following condition:

* Let a_j < b_j < c_j be the IDs of the balls received by the j-th person in ascending order.
* Then, \sum_j (c_j-a_j) should be as small as possible.

Find the number of ways in which Takahashi can distribute the balls. Since the answer can be enormous, compute it modulo 998244353. We consider two ways to distribute the balls different if and only if there is a person who receives different sets of balls.

Constraints

* 1 \leq N \leq 10^5
* |S|=3N
* S consists of `R`, `G`, and `B`, and each of these characters occurs N times in S.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of ways in which Takahashi can distribute the balls, modulo 998244353.

Examples

Input

3
RRRGGGBBB

Output

216

Input

5
BBRGRRGRGGRBBGB

Output

960

### Response

```cpp
#include<cstdio>
int n,i,j,b[3],a=1,P=998244353;int main(){scanf("%d\n",&n);for(i=3*n;--i;){char c=getchar();int &t=b[c%3],m=P;for(j=3;~--j;)m=b[j]>t&&b[j]-t<m?b[j]-t:m;a=1ll*a*(m<=n?m:1)%P*(i<=n?i:1)%P;++t;}printf("%d",a);}
```


### Prompt

Create a solution in cpp for 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<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,l[100],i,j,k,c=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&l[i]);
	}
	sort(l,l+n);
	for(i=0;i<n-2;i++){
		for(j=i+1;j<n-1;j++){
			for(k=j+1;k<n;k++){
				if(l[i]!=l[j]&&l[i]!=l[k]&&l[j]!=l[k]){
					if(l[i]+l[j]>l[k]) c++;
				}
			}
		}
	}
	printf("%d\n",c);
	return 0;
}

```


### Prompt

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

You are given a string S of length N consisting of `A`, `B` and `C`, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it.

Constraints

* 1 ≤ N ≤ 50
* 1 ≤ K ≤ N
* S is a string of length N consisting of `A`, `B` and `C`.

Input

Input is given from Standard Input in the following format:

N K
S

Output

Print the string S after lowercasing the K-th character in it.

Examples

Input

3 1
ABC

Output

aBC

Input

4 3
CABA

Output

CAbA

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,K;
  cin>>N>>K;
  string S;
  cin>>S;
  S.at(K-1)+=0x20;
  cout<<S<<endl;

  return 0;
}
```


### Prompt

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

A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.

Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation.

Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom.

<image>

You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously.

Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.

Note one milliliter equals to one cubic centimeter.

Input

The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where:

  * d — the diameter of your cylindrical cup,
  * h — the initial level of water in the cup,
  * v — the speed of drinking process from the cup in milliliters per second,
  * e — the growth of water because of rain if you do not drink from the cup.

Output

If it is impossible to make the cup empty, print "NO" (without quotes).

Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.

Examples

Input

1 2 3 100

Output

NO

Input

1 1 1 1

Output

YES
3.659792366325

Note

In the first example the water fills the cup faster than you can drink from it.

In the second example area of the cup's bottom equals to <image>, thus we can conclude that you decrease the level of water by <image> centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in <image> seconds.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
const double EPS = 1e-9;
int main() {
  double d, h, v, e;
  while (cin >> d >> h >> v >> e) {
    double t1 = v - e * pi * (d * d / 4.0);
    if (t1 < EPS) {
      cout << "NO" << endl;
    } else {
      double t2 = h * pi * (d * d) / 4.0;
      cout << "YES" << endl << t2 / t1 << endl;
    }
  }
}

```


### Prompt

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

Recently, the Fair Nut has written k strings of length n, consisting of letters "a" and "b". He calculated c — the number of strings that are prefixes of at least one of the written strings. Every string was counted only one time.

Then, he lost his sheet with strings. He remembers that all written strings were lexicographically not smaller than string s and not bigger than string t. He is interested: what is the maximum value of c that he could get.

A string a is lexicographically smaller than a string b if and only if one of the following holds:

  * a is a prefix of b, but a ≠ b;
  * in the first position where a and b differ, the string a has a letter that appears earlier in the alphabet than the corresponding letter in b.

Input

The first line contains two integers n and k (1 ≤ n ≤ 5 ⋅ 10^5, 1 ≤ k ≤ 10^9).

The second line contains a string s (|s| = n) — the string consisting of letters "a" and "b.

The third line contains a string t (|t| = n) — the string consisting of letters "a" and "b.

It is guaranteed that string s is lexicographically not bigger than t.

Output

Print one number — maximal value of c.

Examples

Input

2 4
aa
bb

Output

6

Input

3 3
aba
bba

Output

8

Input

4 5
abbb
baaa

Output

8

Note

In the first example, Nut could write strings "aa", "ab", "ba", "bb". These 4 strings are prefixes of at least one of the written strings, as well as "a" and "b". Totally, 6 strings.

In the second example, Nut could write strings "aba", "baa", "bba".

In the third example, there are only two different strings that Nut could write. If both of them are written, c=8.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long l, r, n, k;
long long ans = 0;
char s[500010], b[500010];
int main() {
  cin >> n >> k;
  scanf("%s%s", s + 1, b + 1);
  for (int i = 1; i <= n; ++i) {
    if (s[i] == 'b') l++;
    if (b[i] == 'b') r++;
    ans += min((r - l + 1), k);
    if ((r - l + 1) <= k + 10) l *= 2, r *= 2, r -= l, l = 0;
  }
  cout << ans;
  return 0;
}

```


### Prompt

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

Professor GukiZ makes a new robot. The robot are in the point with coordinates (x1, y1) and should go to the point (x2, y2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps the robot should make to get the finish position.

Input

The first line contains two integers x1, y1 ( - 109 ≤ x1, y1 ≤ 109) — the start position of the robot.

The second line contains two integers x2, y2 ( - 109 ≤ x2, y2 ≤ 109) — the finish position of the robot.

Output

Print the only integer d — the minimal number of steps to get the finish position.

Examples

Input

0 0
4 5

Output

5

Input

3 4
6 1

Output

3

Note

In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its y coordinate and get the finish position.

In the second example robot should simultaneously increase x coordinate and decrease y coordinate by one three times.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int a = abs(x1 - x2);
  int b = abs(y1 - y2);
  int res = max(a, b);
  cout << res;
  return 0;
}

```


### Prompt

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

N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.

The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`.

You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.

At least how many tiles need to be repainted to satisfy the condition?

Constraints

* 1 \leq |S| \leq 10^5
* S_i is `0` or `1`.

Input

Input is given from Standard Input in the following format:

S

Output

Print the minimum number of tiles that need to be repainted to satisfy the condition.

Examples

Input

000

Output

1

Input

10010010

Output

3

Input

0

Output

0

### Response

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

int main(){
  string S;
  cin>>S;
  int n=S.size();
  int ans=0;
  for(int i=0;i<n;i++){
    ans+=(S.at(i)+i)%2;
  }
  cout<<min(ans,n-ans)<<endl;
}

```


### Prompt

Develop a solution in CPP to the problem described below:

This is an interactive problem.

Note: the XOR-sum of an array a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) is defined as a_1 ⊕ a_2 ⊕ … ⊕ a_n, where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).

Little Dormi received an array of n integers a_1, a_2, …, a_n for Christmas. However, while playing with it over the winter break, he accidentally dropped it into his XOR machine, and the array got lost.

The XOR machine is currently configured with a query size of k (which you cannot change), and allows you to perform the following type of query: by giving the machine k distinct indices x_1, x_2, …, x_k, it will output a_{x_1} ⊕ a_{x_2} ⊕ … ⊕ a_{x_k}.

As Little Dormi's older brother, you would like to help him recover the XOR-sum of his array a_1, a_2, …, a_n by querying the XOR machine.

Little Dormi isn't very patient, so to be as fast as possible, you must query the XOR machine the minimum number of times to find the XOR-sum of his array. Formally, let d be the minimum number of queries needed to find the XOR-sum of any array of length n with a query size of k. Your program will be accepted if you find the correct XOR-sum in at most d queries.

Lastly, you also noticed that with certain configurations of the machine k and values of n, it may not be possible to recover the XOR-sum of Little Dormi's lost array. If that is the case, you should report it as well.

The array a_1, a_2, …, a_n is fixed before you start querying the XOR machine and does not change with the queries.

Input

The only line of input contains the integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n), the length of the lost array and the configured query size of the XOR machine.

Elements of the original array satisfy 1 ≤ a_i ≤ 10^9.

It can be proven that that if it is possible to recover the XOR sum under the given constraints, it can be done in at most 500 queries. That is, d ≤ 500.

After taking n and k, begin interaction.

Output

If it is impossible to recover the XOR-sum of the array, output -1 immediately after taking n and k. Do not begin interaction.

Otherwise, when your program finds the XOR-sum of the lost array a_1, a_2, …, a_n, report the answer in the following format: "! x", where x is the XOR sum of the array a_1, a_2, …, a_n, and terminate your program normally immediately after flushing the output stream.

Note that answering does not count as a query.

Interaction

Each query is made in the format "? b", where b is an array of exactly k distinct integers from 1 to n denoting the indices of the elements in the lost array that you want to query the XOR sum of.

You will then receive an integer x, the XOR sum of the queried elements. It can be proven that 0 ≤ x ≤ 2 ⋅ 10^9 will always be true.

After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

  * fflush(stdout) or cout.flush() in C++;
  * System.out.flush() in Java;
  * flush(output) in Pascal;
  * stdout.flush() in Python;
  * see documentation for other languages.

If at any point you make an invalid query or try to make more than 500 queries (which is the hard limit), the interaction will terminate immediately and give you a Wrong Answer verdict. Note that if you exceed d queries, the interaction will continue normally unless you also exceed the 500 query hard limit, though you will still receive a Wrong Answer verdict either way.

Hacks

To hack a solution, use the following format.

The first line contains the integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n).

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

Examples

Input

5 3

4

0

1

Output

? 1 2 3

? 2 3 5

? 4 1 5

! 7

Input

3 2

Output

-1

Note

In the first example interaction, the array a_1, a_2, …, a_n is 2, 1, 7, 5, 6 and its XOR-sum is 7.

The first query made asks for indices 1,2,3, so the response is a_1 ⊕ a_2 ⊕ a_3 = 2 ⊕ 1 ⊕ 7 = 4.

The second query made asks for indices 2,3,5, so the response is a_2 ⊕ a_3 ⊕ a_5 = 1 ⊕ 7 ⊕ 6 = 0.

The third query made asks for indices 4,1,5, so the response is a_4 ⊕ a_1 ⊕ a_5 = 5 ⊕ 2 ⊕ 6 = 1. Note that the indices may be output in any order.

Additionally, even though three queries were made in the example interaction, it is just meant to demonstrate the interaction format and does not necessarily represent an optimal strategy.

In the second example interaction, there is no way to recover the XOR-sum of Little Dormi's array no matter what is queried, so the program immediately outputs -1 and exits.

### Response

```cpp
#include <bits/stdc++.h>
using ll = long long;
#define all(x) (x).begin(), (x).end()
int main() {
//	std::ios_base::sync_with_stdio(false);
//	std::cin.tie(nullptr);
//	std::cout.tie(nullptr);
	constexpr int INF = std::numeric_limits<int>::max() / 2;
	int n, k;
	std::cin >> n >> k;
	auto ask = [&] (std::vector<int> v) {
		std::cout << "?";
		for (int x : v) std::cout << " " << x + 1;
		std::cout << "\n";
		int res;
		std::cin >> res;
		return res;
	};
	auto link = [&] (std::vector<int> a, std::vector<int> b) {
		std::vector<int> v;
		for (int x : a) v.emplace_back(x);
		for (int x : b) v.emplace_back(x);
		return v;
	};
	std::vector<int> pre(n + 1, 0), dis(n + 1, INF);
	std::queue<int> que;
	pre[0] = -1;
	dis[0] = 0;
	que.emplace(0);
	while (!que.empty()) {
		int x = que.front();
		que.pop();
		for (int i = 1; i <= k; ++i) {
			if (i <= n - x && k - i <= x) {
				int y = x + i * 2 - k;
				if (dis[y] == INF) {
					dis[y] = dis[x] + 1;
					pre[y] = x;
					que.emplace(y);
				}
			}
		}
	}
	if (dis[n] == INF) {
		std::cout << "-1\n";
		return 0;
	}
	std::vector<int> t, f(n), p;
	for (int i = n; ~i; i = pre[i]) p.emplace_back(i);
	std::reverse(all(p));
	int ans = 0;
	std::iota(all(f), 0);
	for (size_t i = 0; i < p.size() - 1; ++i) {
		int x = (p[i + 1] - p[i] + k) / 2, y = k - x;
		std::vector<int> mt, mf;
		for (int j = 0; j < x; ++j) {
			mt.emplace_back(f.back());
			f.pop_back();
		}
		for (int j = 0; j < y; ++j) {
			mf.emplace_back(t.back());
			t.pop_back();
		}
		ans ^= ask(link(mt, mf));
		t.insert(t.end(), all(mt));
		f.insert(f.end(), all(mf));
	}
	std::cout << "! " << ans << "\n";
	return 0;
}
```


### Prompt

Develop a solution in Cpp to the problem described below:

JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array a_1, a_2, ..., a_n of integers, such that 1 ≤ a_1 < a_2 < … < a_n ≤ 10^3, and then went to the bathroom.

JATC decided to prank his friend by erasing some consecutive elements in the array. Since he doesn't want for the prank to go too far, he will only erase in a way, such that Giraffe can still restore the array using the information from the remaining elements. Because Giraffe has created the array, he's also aware that it's an increasing array and all the elements are integers in the range [1, 10^3].

JATC wonders what is the greatest number of elements he can erase?

Input

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

The second line of the input contains n integers a_i (1 ≤ a_1<a_2<...<a_n ≤ 10^3) — the array written by Giraffe.

Output

Print a single integer — the maximum number of consecutive elements in the array that JATC can erase.

If it is impossible to erase even a single element, print 0.

Examples

Input

6
1 3 4 5 6 9

Output

2

Input

3
998 999 1000

Output

2

Input

5
1 2 3 4 5

Output

4

Note

In the first example, JATC can erase the third and fourth elements, leaving the array [1, 3, \\_, \\_, 6, 9]. As you can see, there is only one way to fill in the blanks.

In the second example, JATC can erase the second and the third elements. The array will become [998, \\_, \\_]. Because all the elements are less than or equal to 1000, the array is still can be restored. Note, that he can't erase the first 2 elements.

In the third example, JATC can erase the first 4 elements. Since all the elements are greater than or equal to 1, Giraffe can still restore the array. Note, that he can't erase the last 4 elements.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 100;
const int MINVAL = 1;
const int MAXVAL = 1000;
int n;
int a[MAXN];
int solve() {
  int ret = 0, cur = 0;
  for (int i = (0); i < (n); ++i) {
    if (i - 1 >= 0 && a[i - 1] < a[i] - 1 || i == 0 && a[i] - 1 >= MINVAL) {
      cur = 0;
      continue;
    }
    if (i + 1 < n && a[i + 1] > a[i] + 1 || i + 1 == n && a[i] + 1 <= MAXVAL) {
      cur = 0;
      continue;
    }
    ++cur;
    ret = max(ret, cur);
  }
  return ret;
}
void run() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) scanf("%d", &a[i]);
  printf("%d\n", solve());
}
int main() {
  run();
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

This is the easier version of the problem. In this version, 1 ≤ n ≤ 10^5 and 0 ≤ a_i ≤ 1. You can hack this problem only if you solve and lock both problems.

Christmas is coming, and our protagonist, Bob, is preparing a spectacular present for his long-time best friend Alice. This year, he decides to prepare n boxes of chocolate, numbered from 1 to n. Initially, the i-th box contains a_i chocolate pieces.

Since Bob is a typical nice guy, he will not send Alice n empty boxes. In other words, at least one of a_1, a_2, …, a_n is positive. Since Alice dislikes coprime sets, she will be happy only if there exists some integer k > 1 such that the number of pieces in each box is divisible by k. Note that Alice won't mind if there exists some empty boxes.

Charlie, Alice's boyfriend, also is Bob's second best friend, so he decides to help Bob by rearranging the chocolate pieces. In one second, Charlie can pick up a piece in box i and put it into either box i-1 or box i+1 (if such boxes exist). Of course, he wants to help his friend as quickly as possible. Therefore, he asks you to calculate the minimum number of seconds he would need to make Alice happy.

Input

The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of chocolate boxes.

The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 1) — the number of chocolate pieces in the i-th box.

It is guaranteed that at least one of a_1, a_2, …, a_n is positive.

Output

If there is no way for Charlie to make Alice happy, print -1.

Otherwise, print a single integer x — the minimum number of seconds for Charlie to help Bob make Alice happy.

Examples

Input

3
1 0 1

Output

2

Input

1
1

Output

-1

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void swap(long long &a, long long &b) {
  auto tm = a;
  a = b;
  b = tm;
}
const long long mod = 1000000009;
const long long mod2 = 998244353;
const long long INF = (1LL << 50) - 1;
const long long N = 1e6 + 25;
bool isp(long long x) {
  for (long long i = 2; i * i <= x; ++i)
    if (x % i == 0) return 0;
  return 1;
}
void bheja_fry() {
  long long n, x;
  cin >> n;
  vector<long long> a;
  for (long long(i) = (0); (i) < (n); ++(i)) {
    cin >> x;
    if (x % 2) a.push_back(i + 1);
  }
  vector<long long> f;
  n = (long long)(a).size();
  for (long long i = 2; i <= n; ++i)
    if (n % i == 0) f.push_back(i);
  if ((long long)(f).size() == 0) {
    cout << -1;
    return;
  }
  vector<long long> pre(n + 1);
  for (long long(i) = (1); (i) < (n + 1); ++(i)) pre[i] = pre[i - 1] + a[i - 1];
  long long ans = INF;
  for (auto &(p) : (f)) {
    long long ct = 0;
    for (long long i = 0; i < n; i += p) {
      long long t = abs(pre[i + p / 2] - pre[i] - (p / 2) * a[i + p / 2]);
      t += abs((p / 2 + p % 2) * a[i + p / 2] - (pre[i + p] - pre[i + p / 2]));
      ct += t;
    }
    ans = min(ct, ans);
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  for (long long(i) = (1); (i) < (t + 1); ++(i)) {
    bheja_fry();
    if (i < t) cout << "\n";
  }
  return 0;
}

```


### Prompt

Construct a CPP code solution to the problem outlined:

Find the number, modulo 998244353, of sequences of length N consisting of 0, 1 and 2 such that none of their contiguous subsequences totals to X.

Constraints

* 1 \leq N \leq 3000
* 1 \leq X \leq 2N
* N and X are integers.

Input

Input is given from Standard Input in the following format:

N X

Output

Print the number, modulo 998244353, of sequences that satisfy the condition.

Examples

Input

3 3

Output

14

Input

8 6

Output

1179

Input

10 1

Output

1024

Input

9 13

Output

18402

Input

314 159

Output

459765451

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 998244353LL

ll c[6010][6010];
int n,m;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline ll pls(const ll &x,const ll &y) { return (x+y<mod)?x+y:x+y-mod; }
inline ll mns(const ll &x,const ll &y) { return (x-y<0)?x-y+mod:x-y; }
inline ll ksm(ll x,ll y) { ll res=1;for (;y;y>>=1,x=x*x%mod) if (y&1) res=res*x%mod;return res; }

inline void pre_gao()
{
	for (int i=0;i<=6000;i++)
	{
		c[i][0]=1;
		for (int j=1;j<=i;j++) c[i][j]=pls(c[i-1][j-1],c[i-1][j]);
	}
}

inline ll calc(const int &x,const int &y) { return (x<0||y<0||x>y||y>x*2)?0:c[x][y-x]; }

inline ll gao(const int &x,const int &y)
{
	if (y<m) return calc(x,y);
	if (y>=m*2) return ((m&1)&&y==x*2);
	int hh=y-m-1;
	if (hh&1) return 0;
	int hhh=m+1;
	int now=x-(y-hhh)/2-1-hh/2;
	return calc(now-1,hhh-hh-4);
}

int main()
{
	n=rd();m=rd();pre_gao();
	ll ans=0;
	for (int i=0;i<=n;i++) for (int j=i;j<=i*2;j++) ans=pls(ans,gao(i,j)*c[n][i]%mod);
	printf("%lld\n",ans);
	return 0;
}
```