JerryL/AlgoSimBench huggingface dataset:
623_D. Birthday

A MIPT student named Misha has a birthday today, and he decided to celebrate it in his country house in suburban Moscow. n friends came by, and after a typical party they decided to play blind man's buff.

The birthday boy gets blindfolded and the other players scatter around the house. The game is played in several rounds. In each round, Misha catches exactly one of his friends and has to guess who it is. The probability of catching the i-th friend does not change between rounds and is equal to pi percent (as we know, it is directly proportional to the amount of alcohol consumed by the i-th friend) and p1 + p2 + ... + pn = 100 holds. Misha has no information about who he caught. After Misha makes an attempt to guess the caught person, the round ends. Even then, Misha isn't told whether he guessed correctly, and a new round begins.

The game ends when Misha guesses every friend at least once, that is, there exists such set of rounds k1, k2, ..., kn, that during round number ki Misha caught the i-th friend and guessed him. Misha wants to minimize the expectation of the number of rounds of the game. Despite the fact that at any point in the game Misha has no information about who he has already guessed, his friends are honest, and if they see that the condition for the end of the game is fulfilled, the game ends immediately. Find the expectation of the number of rounds in the game if Misha plays optimally.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of Misha's friends.

The second line contains n integers pi (<image>), giving the probability to catch the i-th friend in one particular round in percent.

Output

Print a single real value — the expectation of the number of rounds provided that Misha plays optimally. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. 

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

Examples

Input

2
50 50


Output

5.0000000000


Input

4
50 20 20 10


Output

39.2846263444

Note

The optimal strategy in the first sample is to guess friends alternately.

Example input:
4
50 20 20 10

2
50 50


Example output:
39.284626344368

5.000000000000


Tags: greedy
math
probabilities
Difficulty rating: 2700

Solution:
#include <bits/stdc++.h>
using namespace std;
double p[111], q[111];
int main() {
  int n;
  cin >> n;
  for (int i = 0, u; i < n; i++) {
    scanf("%d", &u);
    p[i] = u / 100.0;
    q[i] = 1;
  }
  double ans = 0;
  while (1) {
    int now = 0;
    double tmp = 1;
    for (int i = 0; i < n; i++) {
      if (q[i] * p[i] * (1 - q[now]) > q[now] * p[now] * (1 - q[i])) now = i;
      tmp *= 1 - q[i];
    }
    ans += 1 - tmp;
    q[now] *= (1 - p[now]);
    if (1 - tmp < 1e-10) break;
  }
  printf("%.6lf\n", ans);
  return 0;
}
626_D. Jerry's Protest

Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to the player with the larger number and returns the balls to the jar. The winner of the game is the one who wins at least two of the three rounds.

Andrew wins rounds 1 and 2 while Jerry wins round 3, so Andrew wins the game. However, Jerry is unhappy with this system, claiming that he will often lose the match despite having the higher overall total. What is the probability that the sum of the three balls Jerry drew is strictly higher than the sum of the three balls Andrew drew?

Input

The first line of input contains a single integer n (2 ≤ n ≤ 2000) — the number of balls in the jar.

The second line contains n integers ai (1 ≤ ai ≤ 5000) — the number written on the ith ball. It is guaranteed that no two balls have the same number.

Output

Print a single real value — the probability that Jerry has a higher total, given that Andrew wins the first two rounds and Jerry wins the third. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. 

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

Examples

Input

2
1 2


Output

0.0000000000


Input

3
1 2 10


Output

0.0740740741

Note

In the first case, there are only two balls. In the first two rounds, Andrew must have drawn the 2 and Jerry must have drawn the 1, and vice versa in the final round. Thus, Andrew's sum is 5 and Jerry's sum is 4, so Jerry never has a higher total.

In the second case, each game could've had three outcomes — 10 - 2, 10 - 1, or 2 - 1. Jerry has a higher total if and only if Andrew won 2 - 1 in both of the first two rounds, and Jerry drew the 10 in the last round. This has probability <image>.

Example input:
3
1 2 10

2
1 2


Example output:
0.0740740741
0.0000000000

Tags: brute force
combinatorics
dp
probabilities
Difficulty rating: 1800

Solution:
from itertools import accumulate

n = int(input())
A = [int(x) for x in input().split()]
m = max(A)
difference = [0 for i in range(m)]
for i in range(n):
    for j in range(i+1, n):
        difference[abs(A[i]-A[j])] += 1
diffsum = [0 for i in range(2*m)]
for i in range(m):
    for j in range(m):
        diffsum[i+j] += difference[i]*difference[j]
D = list(accumulate(diffsum))
ans = sum(difference[k] * D[k-1] for k in range(m))
print(8*ans/((n*(n-1)) ** 3))
626_E. Simple Skewness

Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness.

The mean of a collection is the average of its elements. The median of a collection is its middle element when all of its elements are sorted, or the average of its two middle elements if it has even size.

Input

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

The second line contains n integers xi (0 ≤ xi ≤ 1 000 000) — the ith element of the list.

Output

In the first line, print a single integer k — the size of the subset.

In the second line, print k integers — the elements of the subset in any order.

If there are multiple optimal subsets, print any.

Examples

Input

4
1 2 3 12


Output

3
1 2 12 


Input

4
1 1 2 2


Output

3
1 1 2 


Input

2
1 2


Output

2
1 2

Note

In the first case, the optimal subset is <image>, which has mean 5, median 2, and simple skewness of 5 - 2 = 3.

In the second case, the optimal subset is <image>. Note that repetition is allowed.

In the last case, any subset has the same median and mean, so all have simple skewness of 0.

Example input:
2
1 2

4
1 1 2 2

4
1 2 3 12


Example output:
1
                                                               1 

3
                                                               1                                                                1                                                                2 

3
                                                               1                                                                2                                                               12 


Tags: binary search
math
ternary search
Difficulty rating: 2400

Solution:
#include <bits/stdc++.h>
using namespace std;
int n, a[200005], k, R;
long long S[200005];
double ans = -(1 << 30);
double F(int t, int k) {
  return 1.0 * (S[t] - S[t - k - 1] + S[n] - S[n - k]) / (2 * k + 1) - a[t];
}
int main() {
  int i, l, r, mid;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (i = 1; i <= n; i++) S[i] = S[i - 1] + a[i];
  for (i = 1; i <= n; i++) {
    l = 0, r = min(i, n - i + 1);
    while (r - l > 1) {
      mid = (l + r) >> 1;
      if (F(i, mid) > F(i, mid - 1))
        l = mid;
      else
        r = mid;
    }
    if (F(i, l) > ans) ans = F(i, l), k = i, R = l;
  }
  printf("%d\n", 2 * R + 1);
  for (i = k - R; i <= k; i++) printf("%d ", a[i]);
  for (i = n - R + 1; i <= n; i++) printf("%d ", a[i]);
  return 0;
}
626_F. Group Projects

There are n students in a class working on group projects. The students will divide into groups (some students may be in groups alone), work on their independent pieces, and then discuss the results together. It takes the i-th student ai minutes to finish his/her independent piece.

If students work at different paces, it can be frustrating for the faster students and stressful for the slower ones. In particular, the imbalance of a group is defined as the maximum ai in the group minus the minimum ai in the group. Note that a group containing a single student has an imbalance of 0. How many ways are there for the students to divide into groups so that the total imbalance of all groups is at most k?

Two divisions are considered distinct if there exists a pair of students who work in the same group in one division but different groups in the other.

Input

The first line contains two space-separated integers n and k (1 ≤ n ≤ 200, 0 ≤ k ≤ 1000) — the number of students and the maximum total imbalance allowed, respectively.

The second line contains n space-separated integers ai (1 ≤ ai ≤ 500) — the time it takes the i-th student to complete his/her independent piece of work.

Output

Print a single integer, the number of ways the students can form groups. As the answer may be large, print its value modulo 109 + 7.

Examples

Input

3 2
2 4 5


Output

3


Input

4 3
7 8 9 10


Output

13


Input

4 0
5 10 20 21


Output

1

Note

In the first sample, we have three options: 

  * The first and second students form a group, and the third student forms a group. Total imbalance is 2 + 0 = 2. 
  * The first student forms a group, and the second and third students form a group. Total imbalance is 0 + 1 = 1. 
  * All three students form their own groups. Total imbalance is 0. 



In the third sample, the total imbalance must be 0, so each student must work individually.

Example input:
3 2
2 4 5

4 0
5 10 20 21

4 3
7 8 9 10


Example output:
3

1

13


Tags: dp
Difficulty rating: 2400

Solution:
#include <bits/stdc++.h>
using namespace std;
int n, k, i, j, p, a[210], memo[210][210][1010];
int dyn(int i, int j, int p) {
  if (i == n) return (j == 0);
  if (memo[i][j][p] != -1) return memo[i][j][p];
  int x = j * (a[i + 1] - a[i]) + p;
  if (x > k) return memo[i][j][p] = 0;
  return memo[i][j][p] = (int)((1LL * dyn(i + 1, j + 1, x) +
                                1LL * dyn(i + 1, j, x) * (j + 1) +
                                1LL * dyn(i + 1, j - 1, x) * j) %
                               1000000007);
  return 0;
}
int main() {
  cin >> n >> k;
  memset(memo, -1, sizeof(memo));
  for (i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  cout << dyn(0, 0, 0);
  return 0;
}
665_F. Four Divisors

If an integer a is divisible by another integer b, then b is called the divisor of a.

For example: 12 has positive 6 divisors. They are 1, 2, 3, 4, 6 and 12.

Let’s define a function D(n) — number of integers between 1 and n (inclusive) which has exactly four positive divisors.

Between 1 and 10 only the integers 6, 8 and 10 has exactly four positive divisors. So, D(10) = 3.

You are given an integer n. You have to calculate D(n).

Input

The only line contains integer n (1 ≤ n ≤ 1011) — the parameter from the problem statement.

Output

Print the only integer c — the number of integers between 1 and n with exactly four divisors.

Examples

Input

10


Output

3


Input

20


Output

5

Example input:
10

20


Example output:
3

5


Tags: data structures
dp
math
number theory
sortings
two pointers
Difficulty rating: 2400

Solution:
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, sum, f[320001], g[320001];
int main() {
  cin >> n, k = pow(n + 1, 1.0 / 3);
  for (m = 1; m * m <= n; m++) g[m] = m, f[m] = n / m;
  m--;
  for (long long i = 2; i <= m; i++)
    if (g[i] > g[i - 1]) {
      for (long long j = 1; j <= min(m, n / i / i); j++) {
        f[j] += g[i - 1];
        if (i * j <= m)
          f[j] -= f[i * j];
        else
          f[j] -= g[n / i / j];
      }
      for (long long j = m; j >= i * i; j--) g[j] -= g[j / i] - g[i - 1];
    }
  sum = g[k] - 1;
  for (long long i = 2; i <= m; i++)
    if (g[i] > g[i - 1]) sum += f[i] - g[i];
  cout << sum << "\n";
}
739_E. Gosha is hunting

Gosha is hunting. His goal is to catch as many Pokemons as possible. Gosha has a Poke Balls and b Ultra Balls. There are n Pokemons. They are numbered 1 through n. Gosha knows that if he throws a Poke Ball at the i-th Pokemon he catches it with probability pi. If he throws an Ultra Ball at the i-th Pokemon he catches it with probability ui. He can throw at most one Ball of each type at any Pokemon.

The hunting proceeds as follows: at first, Gosha chooses no more than a Pokemons at which he will throw Poke Balls and no more than b Pokemons at which he will throw Ultra Balls. After that, he throws the chosen Balls at the chosen Pokemons. If he throws both Ultra Ball and Poke Ball at some Pokemon, he is caught if and only if he is caught by any of these Balls. The outcome of a throw doesn't depend on the other throws.

Gosha would like to know what is the expected number of the Pokemons he catches if he acts in an optimal way. In other words, he would like to know the maximum possible expected number of Pokemons can catch.

Input

The first line contains three integers n, a and b (2 ≤ n ≤ 2000, 0 ≤ a, b ≤ n) — the number of Pokemons, the number of Poke Balls and the number of Ultra Balls.

The second line contains n real values p1, p2, ..., pn (0 ≤ pi ≤ 1), where pi is the probability of catching the i-th Pokemon if Gosha throws a Poke Ball to it.

The third line contains n real values u1, u2, ..., un (0 ≤ ui ≤ 1), where ui is the probability of catching the i-th Pokemon if Gosha throws an Ultra Ball to it.

All the probabilities are given with exactly three digits after the decimal separator.

Output

Print the maximum possible expected number of Pokemons Gosha can catch. The answer is considered correct if it's absolute or relative error doesn't exceed 10 - 4.

Examples

Input

3 2 2
1.000 0.000 0.500
0.000 1.000 0.500


Output

2.75


Input

4 1 3
0.100 0.500 0.500 0.600
0.100 0.500 0.900 0.400


Output

2.16


Input

3 2 0
0.412 0.198 0.599
0.612 0.987 0.443


Output

1.011

Example input:
3 2 2
1.000 0.000 0.500
0.000 1.000 0.500

4 1 3
0.100 0.500 0.500 0.600
0.100 0.500 0.900 0.400

3 2 0
0.412 0.198 0.599
0.612 0.987 0.443


Example output:
2.750000000000

2.160000000000

1.011000000000


Tags: brute force
data structures
dp
flows
math
probabilities
sortings
Difficulty rating: 3000

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int n, p, q;
double a[N], b[N], c[N], f[N][N];
inline void upd(double& x, const double& y) { x < y ? x = y : 0; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> p >> q;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) cin >> b[i], c[i] = a[i] + b[i] - a[i] * b[i];
  for (int i = 1; i <= n; ++i)
    for (int j = min(p, i - 1); j >= 0 && j >= i - 1 - (n - p); --j)
      for (int k = min(q, i - 1); k >= 0 && k >= i - 1 - (n - q); --k) {
        upd(f[j + 1][k], f[j][k] + a[i]);
        upd(f[j][k + 1], f[j][k] + b[i]);
        upd(f[j + 1][k + 1], f[j][k] + c[i]);
      }
  cout << f[p][q] << '\n';
  return 0;
}
755_G. PolandBall and Many Other Balls

PolandBall is standing in a row with Many Other Balls. More precisely, there are exactly n Balls. Balls are proud of their home land — and they want to prove that it's strong.

The Balls decided to start with selecting exactly m groups of Balls, each consisting either of single Ball or two neighboring Balls. Each Ball can join no more than one group.

The Balls really want to impress their Enemies. They kindly asked you to calculate number of such divisions for all m where 1 ≤ m ≤ k. Output all these values modulo 998244353, the Enemies will be impressed anyway.

Input

There are exactly two numbers n and k (1 ≤ n ≤ 109, 1 ≤ k < 215), denoting the number of Balls and the maximim number of groups, respectively.

Output

You should output a sequence of k values. The i-th of them should represent the sought number of divisions into exactly i groups, according to PolandBall's rules.

Examples

Input

3 3


Output

5 5 1 

Input

1 1


Output

1 

Input

5 10


Output

9 25 25 9 1 0 0 0 0 0 

Note

In the first sample case we can divide Balls into groups as follows: 

{1}, {2}, {3}, {12}, {23}.

{12}{3}, {1}{23}, {1}{2}, {1}{3}, {2}{3}.

{1}{2}{3}.

Therefore, output is: 5 5 1.

Example input:
3 3

5 10

1 1


Example output:
5 5 1 
9 25 25 9 1 0 0 0 0 0 
1 

Tags: combinatorics
divide and conquer
dp
fft
math
number theory
Difficulty rating: 3200

Solution:
#include <bits/stdc++.h>
using namespace std;
const long long N = 7e4, D = 998244353, P = D * D;
int n, k, b[N], f[N], g[N];
long long t, A;
int Q(long long a, int b) {
  t = 1;
  while (b) {
    if (b & 1) (t *= a) %= D;
    (a *= a) %= D, b /= 2;
  }
  return t;
}
int main() {
  cin >> n >> k, b[0] = g[0] = 1, f[0] = n;
  for (int i = 1; i < N; i++) b[i] = (long long)b[i - 1] * Q(i, D - 2) % D;
  for (int i = 1; i <= 2 * k; i++) f[i] = (long long)f[i - 1] * (n - i) % D;
  for (int i = 1; i <= k; i++) g[i] = (long long)b[i] * Q(f[i - 1], D - 2) % D;
  for (int i = 1; i <= k; i++) {
    A = 0;
    for (int j = 0; j <= i && j <= n - i; j++)
      A += (long long)f[i + j - 1] * g[j] % D * b[i - j] - P, A += A >> 63 & P;
    cout << A % D << ' ';
  }
  return 0;
}
77_B. Falling Anvils

For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.

Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!

It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.

Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]. p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root: 

<image>

Determine the probability with which an aim can be successfully hit by an anvil.

You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.

Input

The first line contains integer t (1 ≤ t ≤ 10000) — amount of testcases.

Each of the following t lines contain two space-separated integers a and b (0 ≤ a, b ≤ 106).

Pretests contain all the tests with 0 < a < 10, 0 ≤ b < 10.

Output

Print t lines — the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10 - 6.

Examples

Input

2
4 2
1 2


Output

0.6250000000
0.5312500000

Example input:
2
4 2
1 2


Example output:
0.6250000000
0.5312500000


Tags: math
probabilities
Difficulty rating: 1800

Solution:
for i in range(int(input())):
    a, b = map(int, input().split())
    print(0.5 + a / (b << 4) if 4 * b > a else 1 - b / a if a else 1)
827_E. Rusty String

Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consisted of letters "V" and "K". Unfortunately, rust has eaten some of the letters so that it's now impossible to understand which letter was written.

Grigory couldn't understand for a long time what these letters remind him of, so he became interested in the following question: if we put a letter "V" or "K" on each unreadable position, which values can the period of the resulting string be equal to?

A period of a string is such an integer d from 1 to the length of the string that if we put the string shifted by d positions to the right on itself, then all overlapping letters coincide. For example, 3 and 5 are periods of "VKKVK".

Input

There are several (at least one) test cases in the input. The first line contains single integer — the number of test cases.

There is an empty line before each test case. Each test case is described in two lines: the first line contains single integer n (1 ≤ n ≤ 5·105) — the length of the string, the second line contains the string of length n, consisting of letters "V", "K" and characters "?". The latter means the letter on its position is unreadable.

It is guaranteed that the sum of lengths among all test cases doesn't exceed 5·105.

For hacks you can only use tests with one test case.

Output

For each test case print two lines. In the first line print the number of possible periods after we replace each unreadable letter with "V" or "K". In the next line print all these values in increasing order.

Example

Input

3
 
5
V??VK
 
6
??????
 
4
?VK?


Output

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

Note

In the first test case from example we can obtain, for example, "VKKVK", which has periods 3 and 5.

In the second test case we can obtain "VVVVVV" which has all periods from 1 to 6.

In the third test case string "KVKV" has periods 2 and 4, and string "KVKK" has periods 3 and 4.

Example input:
3
 
5
V??VK
 
6
??????
 
4
?VK?


Example output:
0

0

0



Tags: fft
math
strings
Difficulty rating: 2700

Solution:
#include <bits/stdc++.h>
using namespace std;
int t, n, Ans[4000005], cnt;
char s[4000005];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d %s", &n, s + 1);
    cnt = 0;
    for (int x = 1; x <= n; x++) {
      bool fail = 0;
      for (int j = x + 1; j <= n; j++) {
        if (s[j] == '?') continue;
        int pos = j - x;
        while (pos >= 0 && s[pos] == '?') pos -= x;
        if (pos <= 0) continue;
        if (s[pos] != s[j]) {
          fail = 1;
          break;
        }
      }
      if (!fail) Ans[++cnt] = x;
    }
    printf("%d\n", cnt);
    for (int i = 1; i <= cnt; i++) printf("%d ", Ans[i]);
    puts("");
  }
  return 0;
}