### Prompt

Create a solution in CPP for the following problem:

Niwango-kun, an employee of Dwango Co., Ltd., likes Niconico TV-chan, so he collected a lot of soft toys of her and spread them on the floor.

Niwango-kun has N black rare soft toys of Niconico TV-chan and they are spread together with ordinary ones. He wanted these black rare soft toys to be close together, so he decided to rearrange them.

In an infinitely large two-dimensional plane, every lattice point has a soft toy on it. The coordinates (x_i,y_i) of N black rare soft toys are given. All soft toys are considered to be points (without a length, area, or volume).

He may perform the following operation arbitrarily many times:

* Put an axis-aligned square with side length D, rotate the square by 90 degrees with four soft toys on the four corners of the square. More specifically, if the left bottom corner's coordinate is (x, y), rotate four points (x,y) \rightarrow (x+D,y) \rightarrow (x+D,y+D) \rightarrow (x,y+D) \rightarrow (x,y) in this order. Each of the four corners of the square must be on a lattice point.

Let's define the scatteredness of an arrangement by the minimum side length of an axis-aligned square enclosing all black rare soft toys. Black rare soft toys on the edges or the vertices of a square are considered to be enclosed by the square.

Find the minimum scatteredness after he performs arbitrarily many operations.

Constraints

* 2 \leq N \leq 10^5
* 1 \leq D \leq 1000
* 0 \leq x_i, y_i \leq 10^9
* Given coordinates are pairwise distinct
* All numbers given in input are integers

Input

Input is given from Standard Input in the following format:

N D
x_1 y_1
:
x_N y_N

Output

Print the answer.

Examples

Input

3 1
0 0
1 0
2 0

Output

1

Input

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

Output

4

Input

8 3
0 0
0 3
3 0
3 3
2 2
2 5
5 2
5 5

Output

4

### Response

```cpp

#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N, D;

int32_t num[1000][1000];
int32_t square[1000][1000];
int32_t num_one[2100][2100];
int32_t num_error[2100][2100];

using INT_T = int32_t;
template<typename ARR>
inline void add_full(ARR& v1, ARR& v2)
{
	v1 += v2;
}
template<typename ARR, size_t N>
inline void add_full(ARR(&v1)[N], ARR(&v2)[N])
{
	auto iter1 = v1, iter2 = v2, iter1end = v1 + N;
	while (iter1 != iter1end) {
		add_full(*iter1++, *iter2++);
	}
}
//1-indexed累積和
template<size_t N>void CuSum(INT_T(&arr)[N])
{
	for (size_t i = 2; i < N; i++)
	{
		arr[i] += arr[i - 1];
	}
}
template<typename ARR, size_t N>void CuSum(ARR(&arr)[N])
{
	for (auto& arr2 : arr) {
		CuSum(arr2);
	}
	for (size_t i = 2; i < N; i++)
	{
		add_full(arr[i], arr[i - 1]);
	}
}
#if 0
template<size_t N, size_t M>void CuSum(INT_T(&arr)[N][M])
{
	for (auto& arr2 : arr) {
		CuSum(arr2);
	}

	for (size_t i = 2; i < N; i++)
	{
		add_full(arr[i], arr[i - 1]);
	}
}
template<size_t N, size_t M, size_t O>void CuSum(INT_T(&arr)[N][M][O])
{
	for (auto& arr2 : arr) {
		CuSum(arr2);
	}

	for (size_t i = 2; i < N; i++)
	{
		add_full(arr[i], arr[i - 1]);
	}
}
#endif
//1-indexed、(]区間
template<size_t N> INT_T get_sum(INT_T(&arr)[N], int x, int x2)
{
	return (arr[x2] - arr[x]);
}
//1-indexed、(]区間
template<size_t N, size_t M> INT_T get_sum(INT_T(&arr)[N][M], int x, int y, int x2, int y2)
{
	return (arr[y2][x2] - arr[y][x2] - arr[y2][x] + arr[y][x]);
}
//1-indexed、(]区間
template<size_t N, size_t M, size_t O> INT_T get_sum(INT_T(&arr)[N][M][O], int x, int y, int z, int x2, int y2, int z2)
{

	return arr(arr[z2][y2][x2] - arr[z][y2][x2] - arr[z2][y][x2] - arr[z2][y2][x] + arr[z2][y][x] + arr[z2][y][x] + arr[z][y][x2] - arr[z][y][x]);
}

int main()
{
	using std::get;
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N >> D;

	for (size_t i = 0; i < N; i++)
	{
		int x, y;
		in >> x >> y;
		x %= D;
		y %= D;
		num[x][y]++;
	}

	int32_t max_square = -1;
	std::vector<std::tuple<int, int, int>> max_list;
	for (int32_t i = 0; i < D; i++)
	{
		for (int32_t j = 0; j < D; j++)
		{
			auto s = (int32_t)std::sqrt(square[i][j]);
			while ((s*s) < num[i][j]) {
				++s;
			}
			square[i][j] = s;
			int min_size = ((s*(s-1)) >= num[i][j])?1:0;
			if (max_square < s) {
				max_square = s;
				max_list.clear();
				max_list.emplace_back(i, j, min_size);
			}
			else if(max_square == s){
				max_list.emplace_back(i, j, min_size);
			}
		}
	}

	if (max_list.size() == 1)
	{
		out << (max_square - 1)*D << endl;
		return 0;
	}

	for (auto& i : max_list)
	{
		if (get<2>(i) == 1)
		{
			num_one[1+get<0>(i)][1+get<1>(i)]++;
			num_one[1+get<0>(i)][1+get<1>(i) + D]++;
			num_one[1+get<0>(i) + D][1 + get<1>(i)]++;
			num_one[1+get<0>(i)+D][1 + get<1>(i)+D]++;
		}
		else
		{
			num_error[1+get<0>(i)][1 + get<1>(i)]++;
			num_error[1+get<0>(i)][1 + get<1>(i) + D]++;
			num_error[1+get<0>(i) + D][1 + get<1>(i)]++;
			num_error[1+get<0>(i) + D][1 + get<1>(i) + D]++;
		}
	}
	CuSum(num_one);
	CuSum(num_error);

	using BS_INT = int32_t;
	BS_INT ok_range = D, ng_range = -1;
	while (std::abs(ok_range - ng_range) > 1) {
		BS_INT mid = (ok_range + ng_range) / 2;
		bool is_ok = false;

		for (int32_t i = 1-1; i <= D - 1; i++)
		{
			for (int32_t j = 1-1; j <= D - 1; j++)
			{
				if (get_sum(num_one, i + mid, j + mid, i + D, j + D) == 0 &&
					get_sum(num_error,i,j, i + D, j + D) - get_sum(num_error, i, j, i + mid, j + mid) == 0
					)
				{
					is_ok = true;
					goto break_2;
				}
			}
		}
	break_2:;

		//ここに書く

		if (is_ok) {
			ok_range = mid;
		}
		else {
			ng_range = mid;
		}
	}
	out << (max_square - 1)*D+ok_range-1 << endl;

#if 0
	std::vector<std::tuple<int, int, int>> max_list2;
	max_list2.reserve(max_list.size());
	for (auto& i : max_list) {
		max_list2.emplace_back(std::get<1>(i), std::get<0>(i), get<2>(i));
	}
	std::sort(max_list2.begin(), max_list2.end());

	int32_t min_diff = D;
	for (size_t i = 0; i < max_list.size(); i++)
	{
		if (i > 0 && get<0>(max_list[i]) == get<0>(max_list2[i-1])) { continue; }
		for (size_t j = 0; j < max_list2.size(); j++)
		{
			if (j > 0 && get<0>(max_list2[j]) == get<0>(max_list2[j-1])) { continue; }
			//for (auto& k : max_list)
			//{
			//	used[get<0>(k)][get<1>(k)] = false;
			//}

			auto cir_dec = [&max_list](size_t index) {if (index == 0) { return max_list.size() - 1; } else { return index - 1; }};
			auto cir_inc = [&max_list](size_t index) {if ((++index) == max_list.size()) { return (size_t)0; } else { return index; }};

			size_t k = cir_dec(i);
			for (; k != i; k = cir_dec(k))
			{
				if (get<2>(max_list[k]) == 0) {
					break;
				}
				used[get<0>(max_list[k])][get<1>(max_list[k])] = true;
			}
			size_t l = cir_dec(j);
			for (; k != i; k = cir_inc(k))
			{
				int32_t x_diff = get<0>(max_list[k]) - get<0>(max_list[i]);
				if (x_diff < 0) { x_diff += D; }

				while (get<2>(max_list2[l]) == 1 && used[get<1>(max_list2[l])][get<0>(max_list2[l])] == false && l != j);
				int32_t y_diff = get<0>(max_list[l]) - get<0>(max_list[j]);
				if (y_diff < 0) { y_diff += D; }

				min_diff = std::min(x_diff, y_diff);

				used[get<0>(max_list[k])][get<1>(max_list[k])] = false;
			}

#if 0
			for (size_t k = cir_dec(i); k != i; k= cir_dec(k))
			{
				int32_t x_diff = get<0>(max_list[k]) - get<0>(max_list[i]);
				if (x_diff < 0) { x_diff += D; }
				int32_t y_diff = 0;
				size_t l = cir_dec(j);
				while (get<2>(max_list2[l]) == 1 && used[get<1>(max_list2[l])][get<0>(max_list2[l])]==false && l != j);
				int32_t y_diff = get<0>(max_list[l]) - get<0>(max_list[l]);
				if (y_diff < 0) { y_diff += D; }

				if (get<2>(max_list[k]) == 0) {
					break;
				}
				used[get<0>(max_list[k])][get<1>(max_list[k])] = true;
			}
#endif
		}
	}
	out << (max_square - 1)*D + min_diff << endl;
#endif

	return 0;
}
#endif

```


### Prompt

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

Aizu is famous for its buckwheat. There are many people who make buckwheat noodles by themselves.

One day, you went shopping to buy buckwheat flour. You can visit three shops, A, B and C. The amount in a bag and its unit price for each shop is determined by the follows table. Note that it is discounted when you buy buckwheat flour in several bags.

|  Shop A |  Shop B |  Shop C
---|---|---|---
Amount in a bag |  200g|  300g|  500g
Unit price for a bag (nominal cost)|  380 yen |  550 yen |  850 yen
Discounted units |  per 5 bags | per 4 bags | per 3 bags
Discount rate|  reduced by 20 %|  reduced by 15 %|  reduced by 12 %

For example, when you buy 12 bags of flour at shop A, the price is reduced by 20 % for 10 bags, but not for other 2 bags. So, the total amount shall be (380 × 10) × 0.8 + 380 × 2 = 3,800 yen.

Write a program which reads the amount of flour, and prints the lowest cost to buy them. Note that you should buy the flour of exactly the same amount as the given input.

Input

The input consists of multiple datasets. For each dataset, an integer a (500 ≤ a ≤ 5000, a is divisible by 100) which represents the amount of flour is given in a line.

The input ends with a line including a zero. Your program should not process for the terminal symbol. The number of datasets does not exceed 50.

Output

For each dataset, print an integer which represents the lowest cost.

Example

Input

500
2200
0

Output

850
3390

### Response

```cpp
#include<iostream>
#include<algorithm>
#define INF 1<<28
using namespace std;

int memo[10000];

int solve(int n){

  if(!n) return 0;
  if(n < 0) return INF;
  if(memo[n]) return memo[n];

  return memo[n] = min(INF, min(solve(n-1000)+1520, min(solve(n-1200)+1870, min(solve(n-1500)+2244, min(solve(n-200)+380, min(solve(n-300)+550, solve(n-500)+850))))));
}

int main(){
  int n;
  for(int i=0;i<5001;i+=100) solve(i);
  while(cin >> n, n) cout << memo[n] << endl;
}
```


### Prompt

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

You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total?

Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.

Constraints

* 0 \leq A, B, C \leq 50
* A + B + C \geq 1
* 50 \leq X \leq 20 000
* A, B and C are integers.
* X is a multiple of 50.

Input

Input is given from Standard Input in the following format:

A
B
C
X

Output

Print the number of ways to select coins.

Examples

Input

2
2
2
100

Output

2

Input

5
1
0
150

Output

0

Input

30
40
50
6000

Output

213

### Response

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

int main(){
  int a,b,c,n,ans=0;
  cin>>a>>b>>c>>n;
  for(int i=0;i<=a;++i)
    for(int j=0;j<=b;++j)
      for(int k=0;k<=c;++k)
        if(500*i+100*j+50*k==n)ans++;
  cout << ans << endl;
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

During a break in the buffet of the scientific lyceum of the Kingdom of Kremland, there was formed a queue of n high school students numbered from 1 to n. Initially, each student i is on position i. Each student i is characterized by two numbers — a_i and b_i. Dissatisfaction of the person i equals the product of a_i by the number of people standing to the left of his position, add the product b_i by the number of people standing to the right of his position. Formally, the dissatisfaction of the student i, which is on the position j, equals a_i ⋅ (j-1) + b_i ⋅ (n-j).

The director entrusted Stas with the task: rearrange the people in the queue so that minimize the total dissatisfaction.

Although Stas is able to solve such problems, this was not given to him. He turned for help to you.

Input

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

Each of the following n lines contains two integers a_i and b_i (1 ≤ a_i, b_i ≤ 10^8) — the characteristic of the student i, initially on the position i.

Output

Output one integer — minimum total dissatisfaction which can be achieved by rearranging people in the queue.

Examples

Input

3
4 2
2 3
6 1

Output

12

Input

4
2 4
3 3
7 1
2 3

Output

25

Input

10
5 10
12 4
31 45
20 55
30 17
29 30
41 32
7 1
5 5
3 15

Output

1423

Note

In the first example it is optimal to put people in this order: (3, 1, 2). The first person is in the position of 2, then his dissatisfaction will be equal to 4 ⋅ 1+2 ⋅ 1=6. The second person is in the position of 3, his dissatisfaction will be equal to 2 ⋅ 2+3 ⋅ 0=4. The third person is in the position of 1, his dissatisfaction will be equal to 6 ⋅ 0+1 ⋅ 2=2. The total dissatisfaction will be 12.

In the second example, you need to put people in this order: (3, 2, 4, 1). The total dissatisfaction will be 25.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long int, long long int>& a,
         pair<long long int, long long int>& b) {
  return (a.first - a.second) > (b.first - b.second);
}
int main() {
  long long int n, p, q, i, j;
  cin >> n;
  vector<pair<long long int, long long int>> v;
  for (i = 1; i <= n; i++) {
    cin >> p >> q;
    v.push_back({p, q});
  }
  sort(v.begin(), v.end(), cmp);
  long long int ans = 0;
  for (i = 0; i < v.size(); i++) {
    ans = ans + (v[i].first * (i)) + v[i].second * (n - i - 1);
  }
  cout << ans;
}

```


### Prompt

Generate a CPP solution to the following problem:

Given is a positive integer L. Find the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.

Constraints

* 1 ≤ L ≤ 1000
* L is an integer.

Input

Input is given from Standard Input in the following format:

L

Output

Print the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L. Your output is considered correct if its absolute or relative error from our answer is at most 10^{-6}.

Examples

Input

3

Output

1.000000000000

Input

999

Output

36926037.000000000000

### Response

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

int main(){
  double l;
  cin>>l;
  printf("%.12f\n",pow(l/3,3.0));
}
```


### Prompt

Generate a Cpp solution to the following problem:

Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.

Dr. Evil is interested in sets, He has a set of n integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly x. the MEX of a set of integers is the minimum non-negative integer that doesn't exist in it. For example, the MEX of the set {0, 2, 4} is 1 and the MEX of the set {1, 2, 3} is 0 .

Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil?

Input

The first line contains two integers n and x (1 ≤ n ≤ 100, 0 ≤ x ≤ 100) — the size of the set Dr. Evil owns, and the desired MEX.

The second line contains n distinct non-negative integers not exceeding 100 that represent the set.

Output

The only line should contain one integer — the minimal number of operations Dr. Evil should perform.

Examples

Input

5 3
0 4 5 6 7

Output

2

Input

1 0
0

Output

1

Input

5 0
1 2 3 4 5

Output

0

Note

For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.

For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.

In the third test case the set is already evil.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, temp;
  int frequency[101] = {0};
  int counter = 0;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    frequency[temp]++;
  }
  for (int i = 0; i < x; i++) {
    if (frequency[i] == 0) {
      counter++;
    }
  }
  if (frequency[x] >= 1) {
    counter++;
  }
  cout << counter << endl;
  return 0;
}

```


### Prompt

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

Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer p (which may be positive, negative, or zero). To combine their tastes, they invented p-binary numbers of the form 2^x + p, where x is a non-negative integer.

For example, some -9-binary ("minus nine" binary) numbers are: -8 (minus eight), 7 and 1015 (-8=2^0-9, 7=2^4-9, 1015=2^{10}-9).

The boys now use p-binary numbers to represent everything. They now face a problem: given a positive integer n, what's the smallest number of p-binary numbers (not necessarily distinct) they need to represent n as their sum? It may be possible that representation is impossible altogether. Help them solve this problem.

For example, if p=0 we can represent 7 as 2^0 + 2^1 + 2^2.

And if p=-9 we can represent 7 as one number (2^4-9).

Note that negative p-binary numbers are allowed to be in the sum (see the Notes section for an example).

Input

The only line contains two integers n and p (1 ≤ n ≤ 10^9, -1000 ≤ p ≤ 1000).

Output

If it is impossible to represent n as the sum of any number of p-binary numbers, print a single integer -1. Otherwise, print the smallest possible number of summands.

Examples

Input

24 0

Output

2

Input

24 1

Output

3

Input

24 -1

Output

4

Input

4 -7

Output

2

Input

1 1

Output

-1

Note

0-binary numbers are just regular binary powers, thus in the first sample case we can represent 24 = (2^4 + 0) + (2^3 + 0).

In the second sample case, we can represent 24 = (2^4 + 1) + (2^2 + 1) + (2^0 + 1).

In the third sample case, we can represent 24 = (2^4 - 1) + (2^2 - 1) + (2^2 - 1) + (2^2 - 1). Note that repeated summands are allowed.

In the fourth sample case, we can represent 4 = (2^4 - 7) + (2^1 - 7). Note that the second summand is negative, which is allowed.

In the fifth sample case, no representation is possible.

### Response

```cpp
#include <bits/stdc++.h>
const long long INF = 2000000005;
const long long BIG_INF = 2000000000000000005;
const long long mod = 1000000007;
const long long P = 31;
const long double PI = 3.141592653589793238462643;
const double eps = 1e-9;
using namespace std;
vector<pair<long long, long long> > dir = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
bool valid(long long x, long long y, long long n, long long m) {
  return x >= 0 && y >= 0 && x < n && y < m;
}
mt19937 rng(1999999973);
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, p;
  cin >> n >> p;
  for (long long i = 1; i < 100; i++) {
    if (n - p * i > 0 && __builtin_popcountll(n - p * i) <= i &&
        n - p * i >= i) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}

```


### Prompt

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

Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n.

Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beautiful an array as possible (with largest possible beauty). Unfortunately, the shop has only one array a left. On the plus side, the seller said that he could decrease some numbers in the array (no more than by k for each number).

The seller can obtain array b from array a if the following conditions hold: bi > 0; 0 ≤ ai - bi ≤ k for all 1 ≤ i ≤ n.

Help mom find the maximum possible beauty of the array she will give to Vasya (that seller can obtain).

Input

The first line contains two integers n and k (1 ≤ n ≤ 3·105; 1 ≤ k ≤ 106). The second line contains n integers ai (1 ≤ ai ≤ 106) — array a.

Output

In the single line print a single number — the maximum possible beauty of the resulting array.

Examples

Input

6 1
3 6 10 12 13 16

Output

3

Input

5 3
8 21 52 15 77

Output

7

Note

In the first sample we can obtain the array:

3 6 9 12 12 15

In the second sample we can obtain the next array:

7 21 49 14 77

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool read(T &x) {
  int c = getchar();
  int sgn = 1;
  while ((~c && c < '0') || c > '9') {
    if (c == '-') sgn = -1;
    c = getchar();
  }
  for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  x *= sgn;
  return ~c;
}
int X[] = {-1, 0, 1, 0};
int Y[] = {0, 1, 0, -1};
int n, k, arr[300010];
bool isInside(int r, int div) { return (r % div <= k); }
int main() {
  read(n);
  read(k);
  for (int i = 0; i < n; i++) {
    read(arr[i]);
  }
  sort(arr, arr + n);
  int ans = arr[0];
  while (true) {
    bool flag = false;
    for (int i = 0; i < n; i++) {
      while (!isInside(arr[i], ans)) ans--, flag = true;
    }
    if (!flag) break;
  }
  printf("%d\n", ans);
  return 0;
}

```


### Prompt

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

A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they get bored, and if one compartment contain three or four students, then the compartment has fun throughout the entire trip.

The students want to swap with other people, so that no compartment with students had bored students. To swap places with another person, you need to convince him that it is really necessary. The students can not independently find the necessary arguments, so they asked a sympathetic conductor for help. The conductor can use her life experience to persuade any passenger to switch places with some student.

However, the conductor does not want to waste time persuading the wrong people, so she wants to know what is the minimum number of people necessary to persuade her to change places with the students. Your task is to find the number.

After all the swaps each compartment should either have no student left, or have a company of three or four students.

Input

The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train.

Output

If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places.

Examples

Input

5
1 2 2 4 3

Output

2

Input

3
4 1 1

Output

2

Input

4
0 3 0 4

Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int cnt[5] = {0};
  int n = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x = 0;
    scanf("%d", &x);
    cnt[x]++;
  }
  bool fail = false;
  int ans = 0;
  while (cnt[1]) {
    if (cnt[2] > 0) {
      cnt[2]--;
      cnt[1]--;
      cnt[3]++;
      ans++;
    } else if (cnt[1] >= 3) {
      cnt[2]++;
      cnt[1] -= 2;
      ans++;
    } else if (cnt[1] <= cnt[3]) {
      cnt[3] -= cnt[1];
      cnt[4] += cnt[1];
      ans += cnt[1];
      cnt[1] = 0;
    } else if (cnt[1] >= 2) {
      cnt[2]++;
      cnt[1] = 0;
      ans++;
    } else if (cnt[1] == 1) {
      if (cnt[4] < 2) {
        fail = true;
        break;
      }
      cnt[4] -= 2;
      cnt[1] = 0;
      cnt[3] += 2 + 1;
      ans += 2;
    }
  }
  while (cnt[2]) {
    if (cnt[2] >= 3) {
      cnt[2] -= 3;
      cnt[3] += 3;
      ans += 2;
    } else if (cnt[2] == 2) {
      cnt[4]++;
      cnt[2] -= 2;
      ans += 2;
    } else if (cnt[4]) {
      cnt[4]--;
      cnt[2]--;
      cnt[3] += 1 + 1;
      ans++;
    } else if (cnt[3] < 2) {
      fail = true;
      break;
    } else {
      cnt[3] -= 2;
      cnt[4] += 2;
      cnt[2]--;
      ans += 2;
    }
  }
  if (fail) ans = -1;
  printf("%d\n", ans);
  while (getchar() != EOF)
    ;
  return 0;
}

```


### Prompt

Develop a solution in cpp to the problem described below:

A binary heap which satisfies max-heap property is called max-heap. In a max-heap, for every node $i$ other than the root, $A[i] \leq A[parent(i)]$, that is, the value of a node is at most the value of its parent. The largest element in a max-heap is stored at the root, and the subtree rooted at a node contains values no larger than that contained at the node itself.

Here is an example of a max-heap.

<image>

Write a program which reads an array and constructs a max-heap from the array based on the following pseudo code.

$maxHeapify(A, i)$ move the value of $A[i]$ down to leaves to make a sub-tree of node $i$ a max-heap. Here, $H$ is the size of the heap.

1  maxHeapify(A, i)
2      l = left(i)
3      r = right(i)
4      // select the node which has the maximum value
5      if l ≤ H and A[l] > A[i]
6          largest = l
7      else
8          largest = i
9      if r ≤ H and A[r] > A[largest]
10         largest = r
11
12     if largest ≠ i　// value of children is larger than that of i
13         swap A[i] and A[largest]
14         maxHeapify(A, largest) // call recursively

The following procedure buildMaxHeap(A) makes $A$ a max-heap by performing maxHeapify in a bottom-up manner.

1 buildMaxHeap(A)
2    for i = H/2 downto 1
3        maxHeapify(A, i)

Input

In the first line, an integer $H$ is given. In the second line, $H$ integers which represent elements in the binary heap are given in order of node id (from $1$ to $H$).

Output

Print values of nodes in the max-heap in order of their id (from $1$ to $H$). Print a single space character before each value.

Example

Input

10
4 1 3 2 16 9 10 14 8 7

Output

16 14 10 8 7 9 3 2 4 1

### Response

```cpp
#include <stdio.h>

#define N 5000000

int n;
int A[N];

void maxHeap(int i){
	int l = i*2;
	int r = i*2 + 1;
	int largest = i;
	int tmp;
	if(l <= n && A[l]>A[i]) largest = l;
	else largest = i;
	if(r <= n && A[r]>A[largest]) largest = r;

	if(largest != i) {
		tmp = A[i];
		A[i] = A[largest];
		A[largest] = tmp;
		maxHeap(largest);
	}
}

void buildHeap(){
	int i;
	for(i=n/2;i>0;i--){
		maxHeap(i);
	}
}

int main(){
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++){
		scanf("%d",&A[i]);
	}
	buildHeap();
	for(i=1;i<=n;i++){
		printf(" %d",A[i]);
	}
	printf("\n");
	return 0;

}
```


### Prompt

Please create a solution in cpp to the following problem:

Inaka has a disc, the circumference of which is n units. The circumference is equally divided by n points numbered clockwise from 1 to n, such that points i and i + 1 (1 ≤ i < n) are adjacent, and so are points n and 1.

There are m straight segments on the disc, the endpoints of which are all among the aforementioned n points.

Inaka wants to know if her image is rotationally symmetrical, i.e. if there is an integer k (1 ≤ k < n), such that if all segments are rotated clockwise around the center of the circle by k units, the new image will be the same as the original one.

Input

The first line contains two space-separated integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number of segments, respectively.

The i-th of the following m lines contains two space-separated integers a_i and b_i (1 ≤ a_i, b_i ≤ n, a_i ≠ b_i) that describe a segment connecting points a_i and b_i.

It is guaranteed that no segments coincide.

Output

Output one line — "Yes" if the image is rotationally symmetrical, and "No" otherwise (both excluding quotation marks).

You can output each letter in any case (upper or lower).

Examples

Input

12 6
1 3
3 7
5 7
7 11
9 11
11 3

Output

Yes

Input

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

Output

Yes

Input

10 3
1 2
3 2
7 2

Output

No

Input

10 2
1 6
2 7

Output

Yes

Note

The first two examples are illustrated below. Both images become the same as their respective original ones after a clockwise rotation of 120 degrees around the center.

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
struct ac {
  int x, y;
} t[202400];
bool cmp(const ac &a, const ac &b) {
  if (a.x != b.x) {
    return a.x < b.x;
  } else {
    return a.y < b.y;
  }
}
bool wfHas(int x, int y) {
  int l = 0, r = m - 1, mid;
  while (l < r) {
    mid = (l + r) / 2;
    if (t[mid].x == x && t[mid].y == y) {
      return true;
    }
    if (x < t[mid].x || x == t[mid].x && y < t[mid].y) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  return (t[l].x == x && t[l].y == y);
}
bool wf(int k) {
  int i, x, y;
  for (i = 0; i < m; i++) {
    x = t[i].x + k;
    y = t[i].y + k;
    if (x > n) x -= n;
    if (y > n) y -= n;
    if (x > y) {
      x ^= y;
      y ^= x;
      x ^= y;
    }
    if (!wfHas(x, y)) {
      return false;
    }
  }
  return true;
}
void solve() {
  int i, k;
  int x, y;
  for (i = 0; i < m; i++) {
    scanf("%d %d", &x, &y);
    if (x > y) {
      k = x;
      x = y;
      y = k;
    }
    t[i].x = x;
    t[i].y = y;
  }
  sort(t, t + m, cmp);
  if (wf(1)) {
    printf("Yes\n");
    return;
  }
  for (i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      if (wf(i) || wf(n / i)) {
        printf("Yes\n");
        return;
      }
    }
  }
  printf("No\n");
}
int main() {
  while (scanf("%d %d", &n, &m) != EOF) {
    solve();
  }
  return 0;
}

```


### Prompt

Generate a Cpp solution to the following problem:

As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <image>. Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals xa·yb·zc.

To test the metric of mushroom scientists, the usual scientists offered them a task: find such x, y, z (0 ≤ x, y, z; x + y + z ≤ S), that the distance between the center of the Universe and the point (x, y, z) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task.

Note that in this problem, it is considered that 00 = 1.

Input

The first line contains a single integer S (1 ≤ S ≤ 103) — the maximum sum of coordinates of the sought point.

The second line contains three space-separated integers a, b, c (0 ≤ a, b, c ≤ 103) — the numbers that describe the metric of mushroom scientists.

Output

Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations.

A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10 - 6. We think that ln(0) = - ∞.

Examples

Input

3
1 1 1

Output

1.0 1.0 1.0

Input

3
2 0 0

Output

3.0 0.0 0.0

### Response

```cpp
#include <bits/stdc++.h>
int fix(double x) {
  if (fabs(x) <= 1e-9)
    return 0;
  else if (x > 1e-9)
    return 1;
  else
    return -1;
}
int main() {
  double s;
  while (scanf("%lf", &s) != EOF) {
    double num[4];
    double ans[4];
    for (int i = 1; i <= 3; i++) scanf("%lf", &num[i]);
    num[0] = 0;
    for (int i = 1; i <= 3; i++) num[0] += num[i];
    if (fix(num[0]) == 0)
      for (int i = 1; i <= 3; i++) ans[i] = s / 3;
    else
      for (int i = 1; i <= 3; i++) ans[i] = s * num[i] / num[0];
    for (int i = 1; i <= 3; i++)
      if (i == 3)
        printf("%.12f\n", ans[i]);
      else
        printf("%.12f ", ans[i]);
  }
  return 0;
}

```


### Prompt

Please formulate a CPP solution to the following problem:

By the age of three Smart Beaver mastered all arithmetic operations and got this summer homework from the amazed teacher:

You are given a sequence of integers a1, a2, ..., an. Your task is to perform on it m consecutive operations of the following type:

  1. For given numbers xi and vi assign value vi to element axi.
  2. For given numbers li and ri you've got to calculate sum <image>, where f0 = f1 = 1 and at i ≥ 2: fi = fi - 1 + fi - 2.
  3. For a group of three numbers li ri di you should increase value ax by di for all x (li ≤ x ≤ ri).

Smart Beaver planned a tour around great Canadian lakes, so he asked you to help him solve the given problem.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 2·105) — the number of integers in the sequence and the number of operations, correspondingly. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 105). Then follow m lines, each describes an operation. Each line starts with an integer ti (1 ≤ ti ≤ 3) — the operation type:

  * if ti = 1, then next follow two integers xi vi (1 ≤ xi ≤ n, 0 ≤ vi ≤ 105);
  * if ti = 2, then next follow two integers li ri (1 ≤ li ≤ ri ≤ n);
  * if ti = 3, then next follow three integers li ri di (1 ≤ li ≤ ri ≤ n, 0 ≤ di ≤ 105).

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

  * It is guaranteed that n does not exceed 100, m does not exceed 10000 and there will be no queries of the 3-rd type.

The input limits for scoring 70 points are (subproblems E1+E2):

  * It is guaranteed that there will be queries of the 1-st and 2-nd type only.

The input limits for scoring 100 points are (subproblems E1+E2+E3):

  * No extra limitations.

Output

For each query print the calculated sum modulo 1000000000 (109).

Examples

Input

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

Output

12
32
8
50

Input

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

Output

12
45

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long inf = INT_MAX, df = 3e5 + 7, mod = 1e9;
long long i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a[df], f[df],
    sum[df], tag[df * 20];
struct node {
  long long sum1, sum2, siz;
} ma[df * 20];
inline long long read() {
  long long x = 0, y = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') y = (ch == '-') ? -1 : 1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * y;
}
void pushdown(long long num, long long le, long long rig) {
  if (!tag[num]) return;
  ma[num].sum1 = ma[num].sum2 = 0;
  tag[(num << 1)] += tag[num] % mod, tag[(num << 1)] %= mod,
      tag[(num << 1 | 1)] += tag[num] % mod, tag[(num << 1 | 1)] %= mod;
  ma[(num << 1)].sum1 =
      (ma[(num << 1)].sum1 + tag[num] * sum[ma[(num << 1)].siz - 1] % mod) %
      mod,
             ma[(num << 1)].sum2 =
                 (ma[(num << 1)].sum2 +
                  tag[num] * (sum[ma[(num << 1)].siz] - sum[0]) % mod) %
                 mod;
  ma[(num << 1 | 1)].sum1 = (ma[(num << 1 | 1)].sum1 +
                             tag[num] * sum[ma[(num << 1 | 1)].siz - 1] % mod) %
                            mod,
                 ma[(num << 1 | 1)].sum2 =
                     (ma[(num << 1 | 1)].sum2 +
                      tag[num] * (sum[ma[(num << 1 | 1)].siz] - sum[0]) % mod) %
                     mod;
  tag[num] = 0;
}
node operator+(node st, node ch) {
  node tr;
  tr.sum1 = (st.sum1 + f[st.siz - 1] * ch.sum2 % mod +
             (st.siz >= 2) * f[st.siz - 2] * ch.sum1 % mod) %
            mod;
  tr.sum2 =
      (st.sum2 + f[st.siz] * ch.sum2 % mod + f[st.siz - 1] * ch.sum1 % mod) %
      mod;
  tr.siz = st.siz + ch.siz;
  return tr;
}
void build(long long num, long long le, long long rig) {
  if (le == rig) {
    ma[num].sum1 = a[le] * f[0] % mod, ma[num].sum2 = a[le] * f[1] % mod,
    ma[num].siz = 1;
    return;
  }
  build((num << 1), le, ((le + rig) >> 1)),
      build((num << 1 | 1), ((le + rig) >> 1) + 1, rig),
      ma[num] = ma[(num << 1)] + ma[(num << 1 | 1)];
  return;
}
void cov(long long num, long long le, long long rig, long long p, long long x) {
  if (le > p || rig < p) return;
  if (le == p && rig == p) {
    ma[num].sum1 = x * f[0] % mod, ma[num].sum2 = x * f[1] % mod,
    ma[num].siz = 1;
    return;
  }
  pushdown(num, le, rig), cov((num << 1), le, ((le + rig) >> 1), p, x),
      cov((num << 1 | 1), ((le + rig) >> 1) + 1, rig, p, x),
      ma[num] = ma[(num << 1)] + ma[(num << 1 | 1)];
}
void upd(long long num, long long le, long long rig, long long l, long long r,
         long long x) {
  if (le > r || rig < l) return;
  if (le >= l && rig <= r)
    ma[num].sum1 = (ma[num].sum1 % mod + x * sum[ma[num].siz - 1] % mod) % mod,
    ma[num].sum2 = (ma[num].sum2 + x * (sum[ma[num].siz] - sum[0]) % mod) % mod,
    tag[num] += x % mod, tag[num] %= mod;
  else
    pushdown(num, le, rig), upd((num << 1), le, ((le + rig) >> 1), l, r, x),
        upd((num << 1 | 1), ((le + rig) >> 1) + 1, rig, l, r, x),
        ma[num] = ma[(num << 1)] + ma[(num << 1 | 1)];
}
node qry(long long num, long long le, long long rig, long long l, long long r) {
  if (le >= l && rig <= r)
    return ma[num];
  else {
    pushdown(num, le, rig);
    node ty;
    if (((le + rig) >> 1) >= l && r >= ((le + rig) >> 1) + 1)
      ty = qry((num << 1), le, ((le + rig) >> 1), l, r) +
           qry((num << 1 | 1), ((le + rig) >> 1) + 1, rig, l, r);
    else if (((le + rig) >> 1) >= l)
      ty = qry((num << 1), le, ((le + rig) >> 1), l, r);
    else if (r >= ((le + rig) >> 1) + 1)
      ty = qry((num << 1 | 1), ((le + rig) >> 1) + 1, rig, l, r);
    ma[num] = ma[(num << 1)] + ma[(num << 1 | 1)];
    return ty;
  }
}
int main() {
  n = read(), m = read();
  f[0] = 1, sum[0] = 1;
  f[1] = 1, sum[1] = 2;
  for (long long i = (2); i <= (n + 7); ++i)
    f[i] = (f[i - 1] + f[i - 2]) % mod, sum[i] = (sum[i - 1] + f[i]) % mod;
  for (long long i = (1); i <= (n); ++i) a[i] = read() % mod;
  build(1, 1, n);
  for (long long i = (1); i <= (m); ++i) {
    long long op = read(), x = read(), y = read();
    if (op == 1) cov(1, 1, n, x, y);
    if (op == 2) {
      printf("%lld\n", (qry(1, 1, n, x, y).sum1 % mod + mod) % mod);
    }
    if (op == 3) {
      long long d = read();
      upd(1, 1, n, x, y, d % mod);
    }
  }
}

```


### Prompt

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

Dima came to the horse land. There are n horses living in the land. Each horse in the horse land has several enemies (enmity is a symmetric relationship). The horse land isn't very hostile, so the number of enemies of each horse is at most 3.

Right now the horse land is going through an election campaign. So the horses trusted Dima to split them into two parts. At that the horses want the following condition to hold: a horse shouldn't have more than one enemy in its party.

Help Dima split the horses into parties. Note that one of the parties can turn out to be empty.

Input

The first line contains two integers n, m <image> — the number of horses in the horse land and the number of enemy pairs.

Next m lines define the enemy pairs. The i-th line contains integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi), which mean that horse ai is the enemy of horse bi.

Consider the horses indexed in some way from 1 to n. It is guaranteed that each horse has at most three enemies. No pair of enemies occurs more than once in the input.

Output

Print a line, consisting of n characters: the i-th character of the line must equal "0", if the horse number i needs to go to the first party, otherwise this character should equal "1".

If there isn't a way to divide the horses as required, print -1.

Examples

Input

3 3
1 2
3 2
3 1

Output

100

Input

2 1
2 1

Output

00

Input

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

Output

0110000000

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T in() {
  char ch;
  T n = 0;
  bool ng = false;
  while (1) {
    ch = getchar();
    if (ch == '-') {
      ng = true;
      ch = getchar();
      break;
    }
    if (ch >= '0' && ch <= '9') break;
  }
  while (1) {
    n = n * 10 + (ch - '0');
    ch = getchar();
    if (ch < '0' || ch > '9') break;
  }
  return (ng ? -n : n);
}
vector<int> G[300005 + 5];
bool col[300005 + 5];
int n;
void Dfs(int u) {
  int i, sz = G[u].size(), cnt = 0;
  for (i = 0; i <= sz - 1; i++) {
    int v = G[u][i];
    cnt += (col[u] == col[v]);
  }
  if (cnt > 1) {
    col[u] ^= 1;
    for (i = 0; i <= sz - 1; i++) {
      int v = G[u][i];
      Dfs(v);
    }
  }
}
int main() {
  int m, i, j, k, x, y;
  n = in<int>();
  m = in<int>();
  for (i = 1; i <= m; i++) {
    x = in<int>();
    y = in<int>();
    G[x].push_back(y);
    G[y].push_back(x);
  }
  for (i = 1; i <= n; i++) {
    Dfs(i);
  }
  for (i = 1; i <= n; i++) printf("%d", col[i]);
  puts("");
  return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

Gildong is now developing a puzzle game. The puzzle consists of n platforms numbered from 1 to n. The player plays the game as a character that can stand on each platform and the goal of the game is to move the character from the 1-st platform to the n-th platform.

The i-th platform is labeled with an integer a_i (0 ≤ a_i ≤ n-i). When the character is standing on the i-th platform, the player can move the character to any of the j-th platforms where i+1 ≤ j ≤ i+a_i. If the character is on the i-th platform where a_i=0 and i ≠ n, the player loses the game.

Since Gildong thinks the current game is not hard enough, he wants to make it even harder. He wants to change some (possibly zero) labels to 0 so that there remains exactly one way to win. He wants to modify the game as little as possible, so he's asking you to find the minimum number of platforms that should have their labels changed. Two ways are different if and only if there exists a platform the character gets to in one way but not in the other way.

Input

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

Each test case contains two lines. The first line of each test case consists of an integer n (2 ≤ n ≤ 3000) — the number of platforms of the game.

The second line of each test case contains n integers. The i-th integer is a_i (0 ≤ a_i ≤ n-i) — the integer of the i-th platform.

It is guaranteed that:

  * For each test case, there is at least one way to win initially.
  * The sum of n in all test cases doesn't exceed 3000.

Output

For each test case, print one integer — the minimum number of different labels that should be changed to 0 so that there remains exactly one way to win.

Example

Input

3
4
1 1 1 0
5
4 3 2 1 0
9
4 1 4 2 1 0 2 1 0

Output

0
3
2

Note

In the first case, the player can only move to the next platform until they get to the 4-th platform. Since there is already only one way to win, the answer is zero.

In the second case, Gildong can change a_2, a_3, and a_4 to 0 so that the game becomes 4 0 0 0 0. Now the only way the player can win is to move directly from the 1-st platform to the 5-th platform.

In the third case, Gildong can change a_2 and a_8 to 0, then the only way to win is to move in the following way: 1 – 3 – 7 – 9.

### Response

```cpp
#include<cstdio>
#include<iostream>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
#define go(i,x,a) for(int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
#define lowbit(x) (x&(-x))
using namespace std;

const int maxn=3e3+5;
int n,m,p[maxn],f[maxn][maxn],t[maxn];

inline int rd(){
	int ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc == '-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

inline void gmax(int &a,int b){
	if(a < b) a=b; return ;
}

inline void gmin(int &a,int b){
	if(a > b) a=b; return ;
}

inline void add(int x){
	for(int i=x;i<=n;i+=lowbit(i)) t[i]++;
	return ;
}

inline int query(int x){
	int ss=0;
	for(int i=x;i>0;i-=lowbit(i)) ss+=t[i];
	return ss;
}

int main(){
	int T=rd();
	while(T--){
		n=rd(); int ans=0,ss=0;
		go(i,n+5,1) go(j,n+5,1) f[i][j]=0;
		go(i,n+1,1){
		 	p[i]=rd(); ss+=p[i] > 0;
			if(i != n) gmin(p[i],n-i);
		}
		//if(p[n] == 0) p[n]=1,ss++;
		go(i,n+1,1) t[i]=0;
		f[n][n+1]=1;
		for(int i=n-1;i>=1;i--)
			if(p[i]){
				int ls=i+p[i];
		 		go(j,ls+1,i+1)
		 			if(f[j][ls+1]) gmax(f[i][j],f[j][ls+1]+1+query(j-1));
				for(int j=n;j>=i+1;j--) gmax(f[i][j],f[i][j+1]);
				add(ls);
			}
		go(i,n+1,2) gmax(ans,f[1][i]);
		printf("%d\n",ss-ans+1);
	}
	return 0;
}

```


### Prompt

Construct a cpp code solution to the problem outlined:

Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:

Find k integers such that the sum of two to the power of each number equals to the number n and the largest integer in the answer is as small as possible. As there may be multiple answers, you are asked to output the lexicographically largest one.

To be more clear, consider all integer sequence with length k (a1, a2, ..., ak) with <image>. Give a value <image> to each sequence. Among all sequence(s) that have the minimum y value, output the one that is the lexicographically largest.

For definitions of powers and lexicographical order see notes.

Input

The first line consists of two integers n and k (1 ≤ n ≤ 1018, 1 ≤ k ≤ 105) — the required sum and the length of the sequence.

Output

Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and k numbers separated by space in the second line — the required sequence.

It is guaranteed that the integers in the answer sequence fit the range [ - 1018, 1018].

Examples

Input

23 5

Output

Yes
3 3 2 1 0

Input

13 2

Output

No

Input

1 2

Output

Yes
-1 -1

Note

Sample 1:

23 + 23 + 22 + 21 + 20 = 8 + 8 + 4 + 2 + 1 = 23

Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest.

Answers like (4, 1, 1, 1, 0) do not have the minimum y value.

Sample 2:

It can be shown there does not exist a sequence with length 2.

Sample 3:

<image>

Powers of 2:

If x > 0, then 2x = 2·2·2·...·2 (x times).

If x = 0, then 2x = 1.

If x < 0, then <image>.

Lexicographical order:

Given two different sequences of the same length, (a1, a2, ... , ak) and (b1, b2, ... , bk), the first one is smaller than the second one for the lexicographical order, if and only if ai < bi, for the first i where ai and bi differ.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long n, k;
  cin >> n >> k;
  multiset<long long> s;
  long long c = 0;
  long long check = 0;
  map<long long, long long> freq;
  while (n) {
    if (n % 2 == 1) {
      freq[check]++;
      c++;
    }
    check++;
    n /= 2;
  }
  if (c > k) {
    cout << "NO" << endl;
    return 0;
  }
  for (long long i = 66; i >= -66; i--) {
    if (c + freq[i] <= k) {
      c += freq[i];
      freq[i - 1] += 2 * freq[i];
      freq[i] = 0;
    } else {
      break;
    }
  }
  for (long long i = 65; i >= -65; i--) {
    for (long long j = 0; j < freq[i]; j++) {
      s.insert(i);
    }
  }
  while (s.size() != k) {
    auto itr = s.begin();
    long long x = *itr;
    s.erase(itr);
    s.insert(x - 1);
    s.insert(x - 1);
  }
  cout << "Yes" << endl;
  for (auto itr = s.rbegin(); itr != s.rend(); itr++) cout << *itr << " ";
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers — coordinates of cube's vertex (a single line contains coordinates of a single vertex, each vertex is written exactly once), put the paper on the table and left. While Peter was away, his little brother Nick decided to play with the numbers on the paper. In one operation Nick could swap some numbers inside a single line (Nick didn't swap numbers from distinct lines). Nick could have performed any number of such operations.

When Peter returned and found out about Nick's mischief, he started recollecting the original coordinates. Help Peter restore the original position of the points or else state that this is impossible and the numbers were initially recorded incorrectly.

Input

Each of the eight lines contains three space-separated integers — the numbers written on the piece of paper after Nick's mischief. All numbers do not exceed 106 in their absolute value.

Output

If there is a way to restore the cube, then print in the first line "YES". In each of the next eight lines print three integers — the restored coordinates of the points. The numbers in the i-th output line must be a permutation of the numbers in i-th input line. The numbers should represent the vertices of a cube with non-zero length of a side. If there are multiple possible ways, print any of them.

If there is no valid way, print "NO" (without the quotes) in the first line. Do not print anything else.

Examples

Input

0 0 0
0 0 1
0 0 1
0 0 1
0 1 1
0 1 1
0 1 1
1 1 1

Output

YES
0 0 0
0 0 1
0 1 0
1 0 0
0 1 1
1 0 1
1 1 0
1 1 1

Input

0 0 0
0 0 0
0 0 0
0 0 0
1 1 1
1 1 1
1 1 1
1 1 1

Output

NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int n = 8;
int a[n][3];
void yes() {
  cout << "YES\n";
  for (int i = 0; i < n; i++, cout << '\n')
    for (int j = 0; j < 3; j++) cout << a[i][j] << " ";
  exit(0);
}
long long get(int i, int j) {
  long long ret = 0;
  for (int k = 0; k < 3; k++) {
    ret += (a[i][k] - a[j][k]) * 1LL * (a[i][k] - a[j][k]);
  }
  return ret;
}
bool check() {
  long long s = LLONG_MAX;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) s = min(s, get(i, j));
  static vector<int> goal = {3, 3, 1};
  for (int i = 0; i < n; i++) {
    vector<int> cnt(3);
    for (int j = 0; j < n; j++) {
      if (j == i) continue;
      if (get(i, j) == s)
        cnt[0]++;
      else if (get(i, j) == s + s)
        cnt[1]++;
      else
        cnt[2]++;
    }
    if (cnt != goal) return 0;
  }
  return 1;
}
void find(int i) {
  if (i == n) {
    if (check()) yes();
    return;
  }
  sort(a[i], a[i] + 3);
  do {
    find(i + 1);
  } while (next_permutation(a[i], a[i] + 3));
}
int main() {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 3; j++) cin >> a[i][j];
  find(0);
  puts("NO\n");
  return 0;
}

```


### Prompt

Develop a solution in Cpp to the problem described below:

You are given a positive integer D. Let's build the following graph from it:

  * each vertex is a divisor of D (not necessarily prime, 1 and D itself are also included);
  * two vertices x and y (x > y) have an undirected edge between them if x is divisible by y and \frac x y is a prime;
  * the weight of an edge is the number of divisors of x that are not divisors of y.

For example, here is the graph for D=12:

<image>

Edge (4,12) has weight 3 because 12 has divisors [1,2,3,4,6,12] and 4 has divisors [1,2,4]. Thus, there are 3 divisors of 12 that are not divisors of 4 — [3,6,12].

There is no edge between 3 and 2 because 3 is not divisible by 2. There is no edge between 12 and 3 because 12/3=4 is not a prime.

Let the length of the path between some vertices v and u in the graph be the total weight of edges on it. For example, path [(1, 2), (2, 6), (6, 12), (12, 4), (4, 2), (2, 6)] has length 1+2+2+3+1+2=11. The empty path has length 0.

So the shortest path between two vertices v and u is the path that has the minimal possible length.

Two paths a and b are different if there is either a different number of edges in them or there is a position i such that a_i and b_i are different edges.

You are given q queries of the following form:

  * v u — calculate the number of the shortest paths between vertices v and u.

The answer for each query might be large so print it modulo 998244353.

Input

The first line contains a single integer D (1 ≤ D ≤ 10^{15}) — the number the graph is built from.

The second line contains a single integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of queries.

Each of the next q lines contains two integers v and u (1 ≤ v, u ≤ D). It is guaranteed that D is divisible by both v and u (both v and u are divisors of D).

Output

Print q integers — for each query output the number of the shortest paths between the two given vertices modulo 998244353.

Examples

Input

12
3
4 4
12 1
3 4

Output

1
3
1

Input

1
1
1 1

Output

1

Input

288807105787200
4
46 482955026400
12556830686400 897
414 12556830686400
4443186242880 325

Output

547558588
277147129
457421435
702277623

Note

In the first example:

  * The first query is only the empty path — length 0;
  * The second query are paths [(12, 4), (4, 2), (2, 1)] (length 3+1+1=5), [(12, 6), (6, 2), (2, 1)] (length 2+2+1=5) and [(12, 6), (6, 3), (3, 1)] (length 2+2+1=5).
  * The third query is only the path [(3, 1), (1, 2), (2, 4)] (length 1+1+1=3).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15;
const long long MOD = 998244353;
struct th {
  vector<int> arr;
  list<pair<int, char>> dist;
};
map<long long, long long> fake;
map<long long, long long> mp;
vector<pair<long long, long long>> dv;
long long gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void rec(int ind, long long prev, long long mn) {
  if (ind >= dv.size()) return;
  for (int i = 0; i < (int)dv[ind].second; ++i) {
    if (i) mp[prev] = mn;
    rec(ind + 1, prev, mn);
    prev *= dv[ind].first;
  }
  mp[prev] = mn;
  rec(ind + 1, prev, mn);
}
void firstRec(int ind) {
  long long cur = dv[ind].first;
  mp[cur] = 1;
  for (int i = 0; i < dv[ind].second; ++i) {
    rec(ind + 1, cur, dv[ind].first);
    cur *= dv[ind].first;
    mp[cur] = dv[ind].first;
  }
}
long long binpow(long long a, long long p) {
  long long ans = 1;
  while (p != 0) {
    if (p % 2 == 1) {
      ans *= a;
      ans %= MOD;
    }
    a *= a;
    a %= MOD;
    p /= 2;
  }
  return ans;
}
long long get(long long u, long long v) {
  if (u < v) swap(u, v);
  if (u % v != 0) {
    auto gc = gcd(u, v);
    long long ans = get(u, gc);
    ans *= get(v, gc);
    ans %= MOD;
    return ans;
  }
  u /= v;
  map<long long, long long> div;
  long long cnt = 0;
  while (u != 1) {
    if (mp[u] == 1) {
      ++div[u];
      u = 1;
    } else {
      ++div[mp[u]];
      u /= mp[u];
    }
    ++cnt;
  }
  long long ans = 1;
  for (long long i = 2; i <= cnt; ++i) {
    ans *= i;
    ans %= MOD;
  }
  for (auto &i : div) {
    long long fact = 1;
    for (long long j = 2; j <= i.second; ++j) {
      fact *= j;
      fact %= MOD;
    }
    ans *= binpow(fact, MOD - 2);
    ans %= MOD;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << setprecision(30);
  long long d, q;
  cin >> d >> q;
  long long cur = 2;
  long long temp = d;
  while (cur * cur <= temp) {
    while (temp % cur == 0) {
      temp /= cur;
      if (dv.empty() || dv.back().first != cur)
        dv.emplace_back(cur, 1);
      else
        ++dv.back().second;
    }
    ++cur;
  }
  if (temp != 1) dv.emplace_back(temp, 1);
  mp[1] = 1;
  cur = 1;
  for (int i = 0; i < dv.size(); ++i) {
    firstRec(i);
  }
  while (q--) {
    long long u, v;
    cin >> u >> v;
    cout << get(u, v) << '\n';
  }
  return 0;
}

```


### Prompt

Please create a solution in Cpp to the following problem:

problem

AOR Ika-chan, who loves feasts, defined "the number of feasts". A feast number is a natural number that includes "$ 51-3 $" in $ 10 $ decimal notation.
$? $ Can be any number from $ 0 $ to $ 9 $.

Find the number of feasts out of the natural numbers below $ N $.

input

$ N $

output

Output the number of feasts in one line. Also, output a line break at the end.

Example

Input

5124

Output

3

### Response

```cpp
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)

string s;
int len;

enum Ord {
    Le, Eq, Gt,
};

int dp[20][2][2][10000];

bool is_gochiusa(int x) {
    if (x / 1000 % 10 != 5) return false;
    if (x / 100 % 10 != 1) return false;
    if (x / 1 % 10 != 3) return false;
    return true;
}

int rec(int k, Ord ord, bool done, int tail) {
    int &ans = dp[k][ord][done][tail];
    if (ans != -1) return ans;

    ans = 0;
    if (k == len) {
        ans = done ? 1 : 0;
    } else {
        int d = s[k] - '0';
        rep(nd, 10) {
            Ord nord;
            if (ord == Le || ord == Gt) {
                nord = ord;
            } else {
                nord = nd < d ? Le : nd == d ? Eq : Gt;
            }
            if (nord == Gt) continue;
            int ntail = (tail * 10 + nd) % 10000;
            bool ndone = done || is_gochiusa(ntail);
            ans += rec(k + 1, nord, ndone, ntail);
        }
    }
    return ans;
}

signed main() {
    cin >> s;
    len = s.size();
    memset(dp, -1, sizeof dp);
    cout << rec(0, Eq, false, 0) << endl;
}

```


### Prompt

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

Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that.

Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them.

The English alphabet vowels are: A, E, I, O, U, Y

The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z

Input

The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter.

Output

Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".

Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters.

Examples

Input

Is it a melon?

Output

NO

Input

Is it an apple?

Output

YES

Input

  Is     it a banana ?

Output

YES

Input

Is   it an apple  and a  banana   simultaneouSLY?

Output

YES

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
  string thing;
  getline(cin, thing);
  int iter = thing.length() - 1;
  while (thing[iter] == '?' || thing[iter] == ' ') {
    iter--;
  }
  char inv = thing[iter];
  if (inv == 'a' || inv == 'A' || inv == 'i' || inv == 'I' || inv == 'u' ||
      inv == 'U' || inv == 'e' || inv == 'E' || inv == 'o' || inv == 'O' ||
      inv == 'y' || inv == 'Y') {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

```


### Prompt

Please formulate a cpp solution to the following problem:

Quick sort is based on the Divide-and-conquer approach. In QuickSort(A, p, r), first, a procedure Partition(A, p, r) divides an array A[p..r] into two subarrays A[p..q-1] and A[q+1..r] such that each element of A[p..q-1] is less than or equal to A[q], which is, inturn, less than or equal to each element of A[q+1..r]. It also computes the index q.

In the conquer processes, the two subarrays A[p..q-1] and A[q+1..r] are sorted by recursive calls of QuickSort(A, p, q-1) and QuickSort(A, q+1, r).

Your task is to read a sequence A and perform the Partition based on the following pseudocode:

Partition(A, p, r)
1 x = A[r]
2 i = p-1
3 for j = p to r-1
4     do if A[j] <= x
5        then i = i+1
6            exchange A[i] and A[j]
7 exchange A[i+1] and A[r]
8 return i+1

Note that, in this algorithm, Partition always selects an element A[r] as a pivot element around which to partition the array A[p..r].

Constraints

* 1 ≤ n ≤ 100,000
* 0 ≤ Ai ≤ 100,000

Input

The first line of the input includes an integer n, the number of elements in the sequence A.

In the second line, Ai (i = 1,2,...,n), elements of the sequence are given separated by space characters.

Output

Print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character. The element which is selected as the pivot of the partition should be indicated by [  ].

Example

Input

12
13 19 9 5 12 8 7 4 21 2 6 11

Output

9 5 8 7 4 2 6 [11] 21 13 19 12

### Response

```cpp
#include<iostream>

using namespace std;

int main()
{

	int n;
	int A[100000];

	cin>>n;
	for(int i=0;i<n;i++) cin>>A[i];

	int r=n-1;
	int i=0;
	int j=0;

	for(i=0;i<n-1;i++){
		if(A[i]<=A[r]){
			swap(A[i],A[j++]);
		}
	}

	if(A[j]>A[r]) swap(A[j],A[r]);

	for(i=0;i<n;i++){
		if(i) cout<<" ";
		if(j==i){
			cout<<"["<<A[i]<<"]";
		}else{
			cout<<A[i];
		}
	}
	cout<<endl;

	return 0;
}

```


### Prompt

Generate a cpp solution to the following problem:

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

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

Constraints

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

Input

Input is given from Standard Input in the following format:

A B C X Y

Output

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

Examples

Input

1500 2000 1600 3 2

Output

7900

Input

1500 2000 1900 3 2

Output

8500

Input

1500 2000 500 90000 100000

Output

100000000

### Response

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


### Prompt

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

For each positive integer n consider the integer ψ(n) which is obtained from n by replacing every digit a in the decimal notation of n with the digit (9 - a). We say that ψ(n) is the reflection of n. For example, reflection of 192 equals 807. Note that leading zeros (if any) should be omitted. So reflection of 9 equals 0, reflection of 91 equals 8.

Let us call the weight of the number the product of the number and its reflection. Thus, the weight of the number 10 is equal to 10·89 = 890.

Your task is to find the maximum weight of the numbers in the given range [l, r] (boundaries are included).

Input

Input contains two space-separated integers l and r (1 ≤ l ≤ r ≤ 109) — bounds of the range.

Output

Output should contain single integer number: maximum value of the product n·ψ(n), where l ≤ n ≤ r.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d).

Examples

Input

3 7

Output

20

Input

1 1

Output

8

Input

8 10

Output

890

Note

In the third sample weight of 8 equals 8·1 = 8, weight of 9 equals 9·0 = 0, weight of 10 equals 890.

Thus, maximum value of the product is equal to 890.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long cal(long long n) {
  long long m = n;
  long long x = 1, res = 0;
  while (m) {
    long long tmp = m % 10;
    tmp = 9 - tmp;
    res += (x * tmp);
    m /= 10;
    x *= 10;
  }
  return n * res;
}
long long magic(long long n) {
  long long m = n;
  long long x = 1, res = 0;
  while (m > 9) {
    res += (x * 9);
    m /= 10;
    x *= 10;
  }
  res += (x * 4);
  return res;
}
int main() {
  long long l, r;
  cin >> l >> r;
  long long m = magic(r);
  cout << cal(min(max(l, m), r)) << endl;
  return 0;
}

```


### Prompt

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

You are given a sequence with N integers: A = \\{ A_1, A_2, \cdots, A_N \\}. For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:

* If A_i and A_j (i < j) are painted with the same color, A_i < A_j.

Find the minimum number of colors required to satisfy the condition.

Constraints

* 1 \leq N \leq 10^5
* 0 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print the minimum number of colors required to satisfy the condition.

Examples

Input

5
2
1
4
5
3

Output

2

Input

4
0
0
0
0

Output

4

### Response

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	int t;
	multiset<int> ms;
	cin >> t;
	ms.insert(t);

	for (int i = 1; i < n; ++i) {
		cin >> t;
		if (*ms.begin() >= t) ms.insert(t);
		else {
			auto it = ms.lower_bound(t);
			it--;
			ms.erase(it);
			ms.insert(t);
		}
	}
	cout << ms.size() << '\n';
}
```


### Prompt

Develop a solution in cpp to the problem described below:

Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7.

Given n, the sum of p (i) from i = 1 to n s

s = p (1) + p (2) + .... + p (n)

Create a program that outputs. For example, when n = 9, s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 = 100.

Input

Given multiple datasets. Each dataset is given the integer n (n ≤ 10000). When n is 0, it is the last input. The number of datasets does not exceed 50.

Output

For n in each dataset, print s on one line.

Example

Input

2
9
0

Output

5
100

### Response

```cpp
#include<iostream>
int p[1<<17],n,s,i;
int main(){p[1]=1;for(i=2;i*i<1<<17;i++)if(!p[i])for(s=2;i*s<1<<17;s++)p[i*s]++;for(;std::cin>>n,n;){for(i=2,s=0;n;i++)if(!p[i])s+=i,n--;std::cout<<s<<"\n";}}
```


### Prompt

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

Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it!

Still unsatisfied with the garland, Nadeko decided to polish it again. The garland has n pieces numbered from 1 to n from left to right, and the i-th piece has a colour si, denoted by a lowercase English letter. Nadeko will repaint at most m of the pieces to give each of them an arbitrary new colour (still denoted by a lowercase English letter). After this work, she finds out all subsegments of the garland containing pieces of only colour c — Brother Koyomi's favourite one, and takes the length of the longest among them to be the Koyomity of the garland.

For instance, let's say the garland is represented by "kooomo", and Brother Koyomi's favourite colour is "o". Among all subsegments containing pieces of "o" only, "ooo" is the longest, with a length of 3. Thus the Koyomity of this garland equals 3.

But problem arises as Nadeko is unsure about Brother Koyomi's favourite colour, and has swaying ideas on the amount of work to do. She has q plans on this, each of which can be expressed as a pair of an integer mi and a lowercase letter ci, meanings of which are explained above. You are to find out the maximum Koyomity achievable after repainting the garland according to each plan.

Input

The first line of input contains a positive integer n (1 ≤ n ≤ 1 500) — the length of the garland.

The second line contains n lowercase English letters s1s2... sn as a string — the initial colours of paper pieces on the garland.

The third line contains a positive integer q (1 ≤ q ≤ 200 000) — the number of plans Nadeko has.

The next q lines describe one plan each: the i-th among them contains an integer mi (1 ≤ mi ≤ n) — the maximum amount of pieces to repaint, followed by a space, then by a lowercase English letter ci — Koyomi's possible favourite colour.

Output

Output q lines: for each work plan, output one line containing an integer — the largest Koyomity achievable after repainting the garland according to it.

Examples

Input

6
koyomi
3
1 o
4 o
4 m

Output

3
6
5

Input

15
yamatonadeshiko
10
1 a
2 a
3 a
4 a
5 a
1 b
2 b
3 b
4 b
5 b

Output

3
4
5
7
8
1
2
3
4
5

Input

10
aaaaaaaaaa
2
10 b
10 z

Output

10
10

Note

In the first sample, there are three plans:

  * In the first plan, at most 1 piece can be repainted. Repainting the "y" piece to become "o" results in "kooomi", whose Koyomity of 3 is the best achievable;
  * In the second plan, at most 4 pieces can be repainted, and "oooooo" results in a Koyomity of 6;
  * In the third plan, at most 4 pieces can be repainted, and "mmmmmi" and "kmmmmm" both result in a Koyomity of 5.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const int maxm = 4e5 + 10;
const int maxb = 26;
const int sigma_size = 62;
const double eps = 1e-8;
const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
const int Ha = 2333;
const long long Linf = 3e12 + 10;
const int inf = 1e9 + 7;
const double Dinf = 1000000007.0;
char s[1510];
int main() {
  int n, Q;
  while (~scanf("%d%s%d", &n, s, &Q)) {
    while (Q--) {
      int m;
      char op[2];
      scanf("%d%s", &m, op);
      char c = op[0];
      int ans = 0, cnt = m;
      int l = 0, r = 0;
      while (r < n) {
        if (s[r] != c) cnt--;
        r++;
        if (cnt < 0) {
          ans = max(ans, r - l - 1);
          while (s[l] == c) l++;
          l++;
          cnt++;
        }
      }
      ans = max(ans, r - l);
      printf("%d\n", ans);
    }
  }
  return 0;
}

```


### Prompt

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

The Little Elephant loves sortings.

He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.

Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.

Output

In a single line print a single integer — the answer to the problem.

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

Examples

Input

3
1 2 3

Output

0

Input

3
3 2 1

Output

2

Input

4
7 4 1 47

Output

6

Note

In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.

In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).

In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
const long long llinf = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1000000007;
int vis[maxn];
long long b[maxn];
struct node {
  long long a;
  int id;
} a[maxn];
bool cmp(node a, node b) { return a.a < b.a; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) vis[i] = 0;
  long long maxx = 0;
  int index = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i].a);
    b[i] = a[i].a;
    if (maxx <= a[i].a || a[i].a > a[i - 1].a) {
      maxx = a[i].a;
      index = i;
    }
    a[i].id = index;
  }
  sort(a + 1, a + 1 + n, cmp);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int tem = a[i].id;
    if (a[i].a < b[tem] && vis[tem] == 0) {
      vis[tem] = 1;
      ans += b[tem] - a[i].a;
    }
  }
  printf("%I64d\n", ans);
}

```


### Prompt

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

There are n cities on a two dimensional Cartesian plane. The distance between two cities is equal to the Manhattan distance between them (see the Notes for definition). A Hamiltonian cycle of the cities is defined as a permutation of all n cities. The length of this Hamiltonian cycle is defined as the sum of the distances between adjacent cities in the permutation plus the distance between the first and final city in the permutation. Please compute the longest possible length of a Hamiltonian cycle of the given cities.

Input

The first line contains an integer n (3 ≤ n ≤ 105). Then n lines follow, each consisting of two integers xi and yi (0 ≤ xi, yi ≤ 109), denoting the coordinates of a city. All given points will be distinct.

Output

A single line denoting the longest possible length of a Hamiltonian cycle of the given cities. You should not output the cycle, only its length.

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

Examples

Input

4
1 1
1 2
2 1
2 2

Output

6

Note

In the example, one of the possible Hamiltonian cycles with length 6 is (1, 1) (1, 2) (2, 1) (2, 2). There does not exist any other Hamiltonian cycle with a length greater than 6.

The Manhattan distance between two cities (xi, yi) and (xj, yj) is |xi - xj| + |yi - yj|.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
class point {
 public:
  int x, y;
} p[100010], q[100010];
int cmp1(const point &A, const point &B) {
  return A.x < B.x || (A.x == B.x && A.y < B.y);
}
int cmp2(const point &A, const point &B) {
  return A.y < B.y || (A.y == B.y && A.x < B.x);
}
int n, col[100010];
long long solve() {
  copy(p, p + n, q);
  sort(q, q + n, cmp2);
  long long ret = 0;
  for (int i = 1; i < n; i++)
    ret += 2ll * min(i, n - i) * (q[i].y - q[i - 1].y);
  int mid = n >> 1;
  if (n & 1) {
    for (int i = 0; i < n; i++) {
      if (q[i].x < p[mid].x)
        col[i] = 0;
      else if (q[i].x > p[mid].x)
        col[i] = 1;
      else
        col[i] = -1;
    }
    int it;
    int cur = -1;
    for (it = 0; it < mid; it++) {
      if (col[it] != -1) {
        if (cur != -1 && cur != col[it]) break;
        cur = col[it];
      }
    }
    if (it < mid) goto cont;
    ++it;
    for (; it < n; it++) {
      if (col[it] != -1) {
        if (cur != -1 && col[it] == cur) break;
        cur = !col[it];
      }
    }
  cont:
    if (!(it == n || col[mid] != -1))
      ret += 2ll * max(q[mid - 1].y - q[mid].y, q[mid].y - q[mid + 1].y);
    return ret;
  } else {
    for (int i = 0; i < n; i++) {
      if (q[i].x < p[mid].x)
        col[i] = 0;
      else if (q[i].x > p[mid - 1].x)
        col[i] = 1;
      else
        col[i] = -1;
    }
    int cur = -1, it;
    for (it = 0; it < mid; it++) {
      if (col[it] != -1) {
        if (cur != -1 && cur != col[it]) break;
        cur = col[it];
      }
    }
    if (it < mid) goto cont2;
    for (; it < n; it++) {
      if (col[it] != -1) {
        if (cur != -1 && cur == col[it]) break;
        cur = !col[it];
      }
    }
  cont2:
    if (it != n) ret += 2ll * (q[mid - 1].y - q[mid].y);
    return ret;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d%d", &p[i].x, &p[i].y);
  sort(p, p + n, cmp1);
  long long ans = 0;
  long long cur = 0;
  for (int i = 1; i < n; i++)
    cur += 2ll * min(i, n - i) * (p[i].x - p[i - 1].x);
  ans = cur + solve();
  for (int i = 0; i < n; i++) swap(p[i].x, p[i].y);
  sort(p, p + n, cmp1);
  cur = 0;
  for (int i = 1; i < n; i++)
    cur += 2ll * min(i, n - i) * (p[i].x - p[i - 1].x);
  ans = max(ans, cur + solve());
  printf("%lld\n", ans);
  return 0;
}

```


### Prompt

Create a solution in CPP for the following problem:

Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.

Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.

Help her to do so in finding the total number of such segments.

Input

The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 ≤ n ≤ 105, 1 ≤ |k| ≤ 10).

Next line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — affection values of chemicals.

Output

Output a single integer — the number of valid segments.

Examples

Input

4 2
2 2 2 2

Output

8

Input

4 -3
3 -6 -3 12

Output

3

Note

Do keep in mind that k0 = 1.

In the first sample, Molly can get following different affection values:

  * 2: segments [1, 1], [2, 2], [3, 3], [4, 4];

  * 4: segments [1, 2], [2, 3], [3, 4];

  * 6: segments [1, 3], [2, 4];

  * 8: segments [1, 4].

Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.

In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
using ll = long long;
ll a[maxn], pref[maxn];
int n;
ll get(ll k) {
  ll ret = 0;
  map<ll, int> mp;
  mp[0] = 1;
  for (int i = 1; i <= n; ++i) {
    ret += mp[pref[i] - k];
    mp[pref[i]]++;
  }
  return ret;
}
int main(int argc, char const *argv[]) {
  ll k;
  scanf("%d %lld", &n, &k);
  int pos = 0, neg = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
    if (a[i] >= 1) {
      pos = 1;
    }
    if (a[i] <= -1) {
      neg = 1;
    }
    pref[i] = pref[i - 1] + a[i];
  }
  if (llabs(k) == 1) {
    ll ans = 0;
    if (k == 1) {
      cout << get(1) << endl;
    } else {
      ans += get(1);
      ans += get(-1);
      cout << ans << endl;
    }
  } else {
    ll ans = get(1);
    ll kk = k;
    while (llabs(kk) <= 100000000000000LL) {
      ans += get(kk);
      kk *= k;
    }
    cout << ans << endl;
  }
  return 0;
}

```


### Prompt

Generate a CPP solution to the following problem:

Takahashi has a water bottle with the shape of a rectangular prism whose base is a square of side a~\mathrm{cm} and whose height is b~\mathrm{cm}. (The thickness of the bottle can be ignored.)

We will pour x~\mathrm{cm}^3 of water into the bottle, and gradually tilt the bottle around one of the sides of the base.

When will the water be spilled? More formally, find the maximum angle in which we can tilt the bottle without spilling any water.

Constraints

* All values in input are integers.
* 1 \leq a \leq 100
* 1 \leq b \leq 100
* 1 \leq x \leq a^2b

Input

Input is given from Standard Input in the following format:

a b x

Output

Print the maximum angle in which we can tilt the bottle without spilling any water, in degrees. Your output will be judged as correct when the absolute or relative error from the judge's output is at most 10^{-6}.

Examples

Input

2 2 4

Output

45.0000000000

Input

12 21 10

Output

89.7834636934

Input

3 1 8

Output

4.2363947991

### Response

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

int main(){
	double a,b,x,i;
	double theta;
	cin>>a>>b>>x;
	if(a*a*b/2>=x){
		i = a-2*x/(a*b);
		theta = atan(b/(a-i));
	}
	else{
		i = 2*b-2*x/(a*a);
		theta = atan(i/a);
    }
	cout<<std::setprecision(11)<<theta/M_PI*180<<endl;
}
```


### Prompt

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

The Berland Forest can be represented as an infinite cell plane. Every cell contains a tree. That is, contained before the recent events.

A destructive fire raged through the Forest, and several trees were damaged by it. Precisely speaking, you have a n × m rectangle map which represents the damaged part of the Forest. The damaged trees were marked as "X" while the remaining ones were marked as ".". You are sure that all burnt trees are shown on the map. All the trees outside the map are undamaged.

The firemen quickly extinguished the fire, and now they are investigating the cause of it. The main version is that there was an arson: at some moment of time (let's consider it as 0) some trees were set on fire. At the beginning of minute 0, only the trees that were set on fire initially were burning. At the end of each minute, the fire spread from every burning tree to each of 8 neighboring trees. At the beginning of minute T, the fire was extinguished.

The firemen want to find the arsonists as quickly as possible. The problem is, they know neither the value of T (how long the fire has been raging) nor the coordinates of the trees that were initially set on fire. They want you to find the maximum value of T (to know how far could the arsonists escape) and a possible set of trees that could be initially set on fire.

Note that you'd like to maximize value T but the set of trees can be arbitrary.

Input

The first line contains two integer n and m (1 ≤ n, m ≤ 10^6, 1 ≤ n ⋅ m ≤ 10^6) — the sizes of the map.

Next n lines contain the map. The i-th line corresponds to the i-th row of the map and contains m-character string. The j-th character of the i-th string is "X" if the corresponding tree is burnt and "." otherwise.

It's guaranteed that the map contains at least one "X".

Output

In the first line print the single integer T — the maximum time the Forest was on fire. In the next n lines print the certificate: the map (n × m rectangle) where the trees that were set on fire are marked as "X" and all other trees are marked as ".".

Examples

Input

3 6
XXXXXX
XXXXXX
XXXXXX

Output

1
......
.X.XX.
......

Input

10 10
.XXXXXX...
.XXXXXX...
.XXXXXX...
.XXXXXX...
.XXXXXXXX.
...XXXXXX.
...XXXXXX.
...XXXXXX.
...XXXXXX.
..........

Output

2
..........
..........
...XX.....
..........
..........
..........
.....XX...
..........
..........
..........

Input

4 5
X....
..XXX
..XXX
..XXX

Output

0
X....
..XXX
..XXX
..XXX

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int m, n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> m >> n;
  vector<vector<int>> a(m + 5, vector<int>(n + 5)),
      s(m + 5, vector<int>(n + 5)), atam(m + 5, vector<int>(n + 5));
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++) {
      char x;
      cin >> x;
      if (x == 'X')
        a[i][j] = 0;
      else
        a[i][j] = 1;
    }
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
  int mn = 1e9;
  int left = 0, right = min(n, m) / 2;
  while (left <= right) {
    int mid = (left + right) >> 1;
    for (int i = 1; i <= m; i++)
      for (int j = 1; j <= n; j++) atam[i][j] = 0;
    queue<pair<int, int>> qu;
    for (int i = 1; i <= m; i++)
      for (int j = 1; j <= n; j++) {
        bool ok = 1;
        int u = i - mid, d = i + mid, l = j - mid, r = j + mid;
        if (u < 1 || d > m || l < 1 || r > n)
          ok = 0;
        else if (s[d][r] + s[u - 1][l - 1] - s[d][l - 1] - s[u - 1][r])
          ok = 0;
        if (ok) qu.push(make_pair(i, j)), atam[i][j] = 1;
      }
    while (!qu.empty()) {
      pair<int, int> res = qu.front();
      qu.pop();
      for (int i = -1; i <= 1; i++)
        for (int j = -1; j <= 1; j++) {
          if (res == make_pair(res.first + i, res.second + j)) continue;
          int x = res.first + i, y = res.second + j;
          if (x < 1 || x > m || y < 1 || y > n || atam[x][y]) continue;
          if (atam[res.first][res.second] > mid) continue;
          atam[x][y] = atam[res.first][res.second] + 1;
          qu.push(make_pair(x, y));
        }
    }
    bool ok = 1;
    for (int i = 1; i <= m; i++)
      for (int j = 1; j <= n; j++)
        if ((!a[i][j]) ^ bool(atam[i][j])) ok = 0;
    if (ok)
      left = mid + 1;
    else
      right = mid - 1;
  }
  cout << right << "\n";
  for (int i = 1; i <= m; i++, cout << "\n")
    for (int j = 1; j <= n; j++) {
      bool ok = 1;
      int u = i - right, d = i + right, l = j - right, r = j + right;
      if (u < 1 || d > m || l < 1 || r > n)
        ok = 0;
      else if (s[d][r] + s[u - 1][l - 1] - s[d][l - 1] - s[u - 1][r])
        ok = 0;
      if (ok)
        cout << 'X';
      else
        cout << '.';
    }
}

```


### Prompt

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

Once, during a lesson, Sasha got bored and decided to talk with his friends. Suddenly, he saw Kefa. Since we can talk endlessly about Kefa, we won't even start doing that. The conversation turned to graphs. Kefa promised Sasha to tell him about one interesting fact from graph theory if Sasha helps Kefa to count the number of beautiful trees.

In this task, a tree is a weighted connected graph, consisting of n vertices and n-1 edges, and weights of edges are integers from 1 to m. Kefa determines the beauty of a tree as follows: he finds in the tree his two favorite vertices — vertices with numbers a and b, and counts the distance between them. The distance between two vertices x and y is the sum of weights of edges on the simple path from x to y. If the distance between two vertices a and b is equal to m, then the tree is beautiful.

Sasha likes graph theory, and even more, Sasha likes interesting facts, that's why he agreed to help Kefa. Luckily, Sasha is familiar with you the best programmer in Byteland. Help Sasha to count the number of beautiful trees for Kefa. Two trees are considered to be distinct if there is an edge that occurs in one of them and doesn't occur in the other one. Edge's weight matters.

Kefa warned Sasha, that there can be too many beautiful trees, so it will be enough to count the number modulo 10^9 + 7.

Input

The first line contains four integers n, m, a, b (2 ≤ n ≤ 10^6, 1 ≤ m ≤ 10^6, 1 ≤ a, b ≤ n, a ≠ b) — the number of vertices in the tree, the maximum weight of an edge and two Kefa's favorite vertices.

Output

Print one integer — the number of beautiful trees modulo 10^9+7.

Examples

Input

3 2 1 3

Output

5

Input

3 1 1 2

Output

2

Input

5 15 1 5

Output

345444

Note

There are 5 beautiful trees in the first example:

<image>

In the second example the following trees are beautiful:

<image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void solve();
mt19937 rnd(2007);
signed main() {
  mt19937 rrnd(
      std::chrono::high_resolution_clock::now().time_since_epoch().count());
  swap(rrnd, rnd);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  solve();
}
const long long mod = (long long)1e9 + 7;
const long long maxn = (long long)1e6 + 7;
long long fact0[maxn], fact_[maxn], pwn[maxn], pwm[maxn];
long long C(long long n, long long k) {
  return ((fact0[n] * fact_[k]) % mod * fact_[n - k]) % mod;
}
long long binpow(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) {
      res *= a;
      res %= mod;
    }
    a *= a;
    a %= mod;
    n >>= 1;
  }
  return res;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  fact0[0] = 1;
  for (long long(i) = 0; (i) < (maxn - 1); ++(i))
    fact0[i + 1] = (fact0[i] * (i + 1)) % mod;
  for (long long(i) = 0; (i) < (maxn); ++(i))
    fact_[i] = binpow(fact0[i], mod - 2);
  pwn[0] = 1;
  for (long long(i) = 0; (i) < (maxn - 1); ++(i))
    pwn[i + 1] = (pwn[i] * n) % mod;
  pwm[0] = 1;
  for (long long(i) = 0; (i) < (maxn - 1); ++(i))
    pwm[i + 1] = (pwm[i] * m) % mod;
  long long ans = 0;
  for (long long l = 1; l < n; ++l) {
    if (l > m) break;
    long long cur = 1;
    long long cnt_trees;
    if (n - l - 2 == -1)
      cnt_trees = ((l + 1) * binpow(n, mod - 2)) % mod;
    else {
      cnt_trees = ((l + 1) * pwn[(n - l - 2)]) % mod;
    }
    cur *= C(m - 1, l - 1);
    cur %= mod;
    cur *= pwm[n - 1 - l];
    cur %= mod;
    cur *= cnt_trees;
    cur %= mod;
    cur *= fact0[n - 2];
    cur %= mod;
    cur *= fact_[n - 1 - l];
    cur %= mod;
    ans += cur;
    ans %= mod;
  }
  cout << ans << '\n';
}

```


### Prompt

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

Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i.

The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere.

When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0.

What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?

Constraints

* All values in input are integers.
* 2 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the maximum total comfort the N players can get.

Examples

Input

4
2 2 1 3

Output

7

Input

7
1 1 1 1 1 1 1

Output

6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  int a[n];
  rep(i,0,n) cin>>a[i];
  sort(a,a+n);
  reverse(a,a+n);
  ll ans=a[0];
  rep(i,2,n){
    ans+=a[i/2];
  }
  cout<<ans<<endl;
}
```


### Prompt

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

You play the game with your friend. The description of this game is listed below.

Your friend creates n distinct strings of the same length m and tells you all the strings. Then he randomly chooses one of them. He chooses strings equiprobably, i.e. the probability of choosing each of the n strings equals <image>. You want to guess which string was chosen by your friend.

In order to guess what string your friend has chosen, you are allowed to ask him questions. Each question has the following form: «What character stands on position pos in the string you have chosen?» A string is considered guessed when the answers to the given questions uniquely identify the string. After the string is guessed, you stop asking questions.

You do not have a particular strategy, so as each question you equiprobably ask about a position that hasn't been yet mentioned. Your task is to determine the expected number of questions needed to guess the string chosen by your friend.

Input

The first line contains a single integer n (1 ≤ n ≤ 50) — the number of strings your friend came up with.

The next n lines contain the strings that your friend has created. It is guaranteed that all the strings are distinct and only consist of large and small English letters. Besides, the lengths of all strings are the same and are between 1 to 20 inclusive.

Output

Print the single number — the expected value. Your answer will be considered correct if its absolute or relative error doesn't exceed 10 - 9.

Examples

Input

2
aab
aac

Output

2.000000000000000

Input

3
aaA
aBa
Caa

Output

1.666666666666667

Input

3
aca
vac
wqq

Output

1.000000000000000

Note

In the first sample the strings only differ in the character in the third position. So only the following situations are possible:

  * you guess the string in one question. The event's probability is <image>;
  * you guess the string in two questions. The event's probability is <image> · <image> = <image> (as in this case the first question should ask about the position that is other than the third one);
  * you guess the string in three questions. The event's probability is <image> · <image> · <image> = <image>;

Thus, the expected value is equal to <image>

In the second sample we need at most two questions as any pair of questions uniquely identifies the string. So the expected number of questions is <image>.

In the third sample whatever position we ask about in the first question, we immediately identify the string.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void get_int(T &x) {
  char t = getchar();
  bool neg = false;
  x = 0;
  for (; (t > '9' || t < '0') && t != '-'; t = getchar())
    ;
  if (t == '-') neg = true, t = getchar();
  for (; t <= '9' && t >= '0'; t = getchar()) x = x * 10 + t - '0';
  if (neg) x = -x;
}
template <typename T>
void print_int(T x) {
  if (x < 0) putchar('-'), x = -x;
  short a[20] = {}, sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
const int inf = 0x3f3f3f3f;
const long long Linf = 1ll << 61;
const double pi = acos(-1.0);
int n, m, one[1 << 20], cnt[25], c[25][25];
char s[55][25];
long long msk[25], all[1 << 20];
double calc(int x) {
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i < m; i++) {
    msk[i] = 0;
    for (int j = 0; j < n; j++)
      if (j != x && s[j][i] == s[x][i]) msk[i] |= 1ll << j;
  }
  all[0] = (1ll << n) - 1;
  for (int i = 0; i < (1 << m); i++) {
    for (int j = 0; j < m; j++) {
      if ((i >> j) & 1) {
        all[i] = all[i ^ (1 << j)] & msk[j];
        break;
      }
    }
    if (all[i]) cnt[one[i]]++;
  }
  double ret = 0.0, sum = 0.0;
  for (int i = 0; i < m; i++) {
    cnt[i] = cnt[i] * (m - i) - cnt[i + 1] * (i + 1);
    ret += 1.0 * (i + 1) * cnt[i] / c[m][i] / (m - i);
    sum += 1.0 * cnt[i] / c[m][i] / (m - i);
  }
  return ret;
}
int main() {
  for (int i = 0; i < 25; i++) {
    c[i][0] = 1;
    for (int j = 1; j <= i; j++) c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
  }
  for (int i = 1; i < (1 << 20); i++) one[i] = (one[i >> 1] + (i & 1));
  get_int(n);
  if (n == 1) {
    printf("0.00000000000\n");
    return 0;
  }
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  m = strlen(s[0]);
  double ans = 0.0;
  for (int i = 0; i < n; i++) ans += calc(i);
  printf("%.10lf\n", ans / n);
  return 0;
}

```