JerryL/AlgoSimBench huggingface dataset:
1336_E1. Chiori and Doll Picking (easy version)

This is the easy version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved.

Chiori loves dolls and now she is going to decorate her bedroom!

<image>

As a doll collector, Chiori has got n dolls. The i-th doll has a non-negative integer value a_i (a_i < 2^m, m is given). Chiori wants to pick some (maybe zero) dolls for the decoration, so there are 2^n different picking ways.

Let x be the bitwise-xor-sum of values of dolls Chiori picks (in case Chiori picks no dolls x = 0). The value of this picking way is equal to the number of 1-bits in the binary representation of x. More formally, it is also equal to the number of indices 0 ≤ i < m, such that \left⌊ (x)/(2^i) \right⌋ is odd.

Tell her the number of picking ways with value i for each integer i from 0 to m. Due to the answers can be very huge, print them by modulo 998 244 353.

Input

The first line contains two integers n and m (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ m ≤ 35) — the number of dolls and the maximum value of the picking way.

The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i < 2^m) — the values of dolls.

Output

Print m+1 integers p_0, p_1, …, p_m — p_i is equal to the number of picking ways with value i by modulo 998 244 353.

Examples

Input


4 4
3 5 8 14


Output


2 2 6 6 0 

Input


6 7
11 45 14 9 19 81


Output


1 2 11 20 15 10 5 0 

Example input:
6 7
11 45 14 9 19 81

4 4
3 5 8 14


Example output:
1 2 11 20 15 10 5 0 

2 2 6 6 0 


Tags: bitmasks
brute force
combinatorics
math
Difficulty rating: 2700

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10, M = 36, mod = 998244353;
long long a[M];
unordered_map<long long, int> f[M];
int ans[M];
void add(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    long long x;
    scanf("%lld", &x);
    for (int j = 0; j < m; j++)
      if (x >> j & 1) x ^= a[j];
    cnt += !x;
    for (int j = m - 1; j >= 0; j--)
      if (x >> j & 1) {
        a[j] = x;
        for (int k = j + 1; k < m; k++)
          if (a[k] >> j & 1) a[k] ^= a[j];
        break;
      }
  }
  f[0][0] = 1;
  for (int i = 0; i < m; i++)
    if (a[i]) {
      for (int j = m - 1; j >= 0; j--) {
        for (auto k : f[j])
          add(f[j + 1][a[i] ^ (1ll << i) ^ k.first], k.second);
      }
    }
  for (int i = 0; i <= m; i++) {
    for (auto j : f[i]) add(ans[__builtin_popcountll(j.first) + i], j.second);
  }
  while (cnt--) {
    for (int i = 0; i <= m; i++) add(ans[i], ans[i]);
  }
  for (int i = 0; i <= m; i++) printf("%d%c", ans[i], " \n"[i == m]);
}
1515_E. Phoenix and Computers

There are n computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer i-1 and computer i+1 are both on, computer i (2 ≤ i ≤ n-1) will turn on automatically if it is not already on. Note that Phoenix cannot manually turn on a computer that already turned on automatically.

If we only consider the sequence of computers that Phoenix turns on manually, how many ways can he turn on all the computers? Two sequences are distinct if either the set of computers turned on manually is distinct, or the order of computers turned on manually is distinct. Since this number may be large, please print it modulo M.

Input

The first line contains two integers n and M (3 ≤ n ≤ 400; 10^8 ≤ M ≤ 10^9) — the number of computers and the modulo. It is guaranteed that M is prime.

Output

Print one integer — the number of ways to turn on the computers modulo M.

Examples

Input


3 100000007


Output


6


Input


4 100000007


Output


20


Input


400 234567899


Output


20914007

Note

In the first example, these are the 6 orders in which Phoenix can turn on all computers: 

  * [1,3]. Turn on computer 1, then 3. Note that computer 2 turns on automatically after computer 3 is turned on manually, but we only consider the sequence of computers that are turned on manually. 
  * [3,1]. Turn on computer 3, then 1. 
  * [1,2,3]. Turn on computer 1, 2, then 3. 
  * [2,1,3] 
  * [2,3,1] 
  * [3,2,1] 

Example input:
400 234567899

4 100000007

3 100000007


Example output:

20914007


20


6


Tags: combinatorics
dp
math
Difficulty rating: 2200

Solution:
from math import factorial
n, mod = map(int, input().split())
def binom(n, m):    return factorial(n) // factorial(m) // factorial(n-m)
def foo(x, k):
    ans = 0
    for i in range(k, 0, -1):sign = 1 if (i-k)%2 == 0 else -1;ans += sign * binom(k, i) * (i**x);ans %= mod
    return ans
def f(x, k):    return (foo(x, k) * pow(2, x-k, mod)) % mod
ans = 0
for i in range((n+1)//2):ans = (ans + f(n-i, i+1));ans %= mod
print(ans)
36_B. Fractal

Ever since Kalevitch, a famous Berland abstractionist, heard of fractals, he made them the main topic of his canvases. Every morning the artist takes a piece of graph paper and starts with making a model of his future canvas. He takes a square as big as n × n squares and paints some of them black. Then he takes a clean square piece of paper and paints the fractal using the following algorithm: 

Step 1. The paper is divided into n2 identical squares and some of them are painted black according to the model.

Step 2. Every square that remains white is divided into n2 smaller squares and some of them are painted black according to the model.

Every following step repeats step 2.

<image>

Unfortunately, this tiresome work demands too much time from the painting genius. Kalevitch has been dreaming of making the process automatic to move to making 3D or even 4D fractals.

Input

The first line contains integers n and k (2 ≤ n ≤ 3, 1 ≤ k ≤ 5), where k is the amount of steps of the algorithm. Each of the following n lines contains n symbols that determine the model. Symbol «.» stands for a white square, whereas «*» stands for a black one. It is guaranteed that the model has at least one white square. 

Output

Output a matrix nk × nk which is what a picture should look like after k steps of the algorithm.

Examples

Input

2 3
.*
..


Output

.*******
..******
.*.*****
....****
.***.***
..**..**
.*.*.*.*
........


Input

3 2
.*.
***
.*.


Output

.*.***.*.
*********
.*.***.*.
*********
*********
*********
.*.***.*.
*********
.*.***.*.

Example input:
2 3
.*
..

3 2
.*.
***
.*.


Example output:
.*******
..******
.*.*****
....****
.***.***
..**..**
.*.*.*.*
........

.*.***.*.
*********
.*.***.*.
*********
*********
*********
.*.***.*.
*********
.*.***.*.


Tags: implementation
Difficulty rating: 1600

Solution:
import java.io.*;
import java.util.*;
public class B {
	public static void main(String[] args) throws IOException {
		Scanner s = new Scanner(new File("input.txt"));
		PrintStream out = new PrintStream(new File("output.txt"));
		int n = s.nextInt(), k = s.nextInt();
		char[][] model = new char[n][n];
		for (int i =0;i<n;i++) {
			String st=  s.next();
			for (int j = 0; j < n; j++) {
				model[i][j] = st.charAt(j);
			}
		}
		int dim = n;
		char[][] prev = model;
		char[][] next = prev;
		for (int i = 1; i < k; i++) {
			dim*=n;
			next = new char[dim][dim];
			for (int r = 0; r < dim; r++) {
				for (int c = 0; c < dim; c++) {
					if (prev[r/n][c/n]=='.') {
						next[r][c] = model[r%n][c%n];
					} else {
						next[r][c] = '*';
					}
				}
			}
			prev = next;
		}
		for (int i = 0 ; i < dim; i++) {
			out.println(new String(next[i]));
		}
		
	}
}
749_A. Bachgold Problem

Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.

Recall that integer k is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and k. 

Input

The only line of the input contains a single integer n (2 ≤ n ≤ 100 000).

Output

The first line of the output contains a single integer k — maximum possible number of primes in representation.

The second line should contain k primes with their sum equal to n. You can print them in any order. If there are several optimal solution, print any of them.

Examples

Input

5


Output

2
2 3


Input

6


Output

3
2 2 2

Example input:
6

5


Example output:
3
2  2  2 

2
2 3


Tags: greedy
implementation
math
number theory
Difficulty rating: 800

Solution:
n=input()
print n/2
print '2 '*(n/2-1)+'23'[n%2]
230_B. T-primes

We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.

You are given an array of n positive integers. For each of them determine whether it is Т-prime or not.

Input

The first line contains a single positive integer, n (1 ≤ n ≤ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 ≤ xi ≤ 1012).

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

Output

Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Т-prime, and "NO" (without the quotes), if it isn't.

Examples

Input

3
4 5 6


Output

YES
NO
NO

Note

The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".

Example input:
3
4 5 6


Example output:
YES
NO
NO


Tags: binary search
implementation
math
number theory
Difficulty rating: 1300

Solution:
Z=6**8-7;l=[1]*Z;s={4}
for i in range(2,Z):
 if l[i]:l[i*i::i]=[0]*(Z/i-i+1);s.add(i*i)
r=raw_input;r()
for i in r().split():print"NYOE S"[int(i)in s::2]
472_A. Design Tutorial: Learn from Math

One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.

For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.

You are given an integer n no less than 12, express it as a sum of two composite numbers.

Input

The only line contains an integer n (12 ≤ n ≤ 106).

Output

Output two composite integers x and y (1 < x, y < n) such that x + y = n. If there are multiple solutions, you can output any of them.

Examples

Input

12


Output

4 8


Input

15


Output

6 9


Input

23


Output

8 15


Input

1000000


Output

500000 500000

Note

In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.

In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.

Example input:
1000000

23

15

12


Example output:
4 999996

8 15

6 9

4 8


Tags: math
number theory
Difficulty rating: 800

Solution:
n=input()
a=n%2*5+4
print a,n-a
584_D. Dima and Lisa

Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes.

More formally, you are given an odd numer n. Find a set of numbers pi (1 ≤ i ≤ k), such that

  1. 1 ≤ k ≤ 3
  2. pi is a prime
  3. <image>



The numbers pi do not necessarily have to be distinct. It is guaranteed that at least one possible solution exists.

Input

The single line contains an odd number n (3 ≤ n < 109).

Output

In the first line print k (1 ≤ k ≤ 3), showing how many numbers are in the representation you found.

In the second line print numbers pi in any order. If there are multiple possible solutions, you can print any of them.

Examples

Input

27


Output

3
5 11 11

Note

A prime is an integer strictly larger than one that is divisible only by one and by itself.

Example input:
27


Example output:
3
23 2 2


Tags: brute force
math
number theory
Difficulty rating: 1800

Solution:
n=int(input())
p=lambda x: True if sum(x%i==0 for i in range(2,int(x**0.5)+1))==0 else False
if n==3 or n==5:
  print(1)
  print(n)
else:
  for i in range(2,10**5):
    j=n-i-3
    if j>1 and p(i) and p(j):
      print(3)
      print(3,i,j)
      exit()
p03262 AtCoder Beginner Contest 109 - Skip

There are N cities on a number line. The i-th city is located at coordinate x_i.

Your objective is to visit all these cities at least once.

In order to do so, you will first set a positive integer D.

Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like:

* Move 1: travel from coordinate y to coordinate y + D.
* Move 2: travel from coordinate y to coordinate y - D.



Find the maximum value of D that enables you to visit all the cities.

Here, to visit a city is to travel to the coordinate where that city is located.

Constraints

* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq X \leq 10^9
* 1 \leq x_i \leq 10^9
* x_i are all different.
* x_1, x_2, ..., x_N \neq X

Input

Input is given from Standard Input in the following format:


N X
x_1 x_2 ... x_N


Output

Print the maximum value of D that enables you to visit all the cities.

Examples

Input

3 3
1 7 11


Output

2


Input

3 81
33 105 57


Output

24


Input

1 1
1000000000


Output

999999999

Example input:
3 81
33 105 57
3 3
1 7 11
1 1
1000000000

Example output:
24
2
999999999

Difficulty rating: 0

Solution:
n,x,*l=map(int,open(0).read().split())
from math import *
a=0
for i in l: a=gcd(a,abs(i-x))
print(a)
p02814 AtCoder Beginner Contest 150 - Semi Common Multiple

Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.

Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):

* There exists a non-negative integer p such that X= a_k \times (p+0.5).



Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Constraints

* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N M
a_1 a_2 ... a_N


Output

Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).

Examples

Input

2 50
6 10


Output

2


Input

3 100
14 22 40


Output

0


Input

5 1000000000
6 6 2 6 2


Output

166666667

Example input:
3 100
14 22 40
2 50
6 10
5 1000000000
6 6 2 6 2

Example output:
0
2
166666667

Difficulty rating: 0

Solution:
f=lambda:map(int,input().split())
n,m=f(); a=list(f())
from fractions import *
l=1
for i in a:
  i//=2; l=l*i//gcd(l,i)
  if (l//i)%2<1 or l>m: print(0); exit()
print(m//l-m//(l*2))
550_C. Divisibility by Eight

You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.

Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-negative integer, doesn't have leading zeroes and is divisible by 8. After the removing, it is forbidden to rearrange the digits.

If a solution exists, you should print it.

Input

The single line of the input contains a non-negative integer n. The representation of number n doesn't contain any leading zeroes and its length doesn't exceed 100 digits. 

Output

Print "NO" (without quotes), if there is no such way to remove some digits from number n. 

Otherwise, print "YES" in the first line and the resulting number after removing digits from number n in the second line. The printed number must be divisible by 8.

If there are multiple possible answers, you may print any of them.

Examples

Input

3454


Output

YES
344


Input

10


Output

YES
0


Input

111111


Output

NO

Example input:
111111

3454

10


Example output:
NO

YES
344

YES
0


Tags: brute force
dp
math
Difficulty rating: 1500

Solution:
import re
s=input()
for i in range(0,1000,8):
    if re.search('.*'.join(str(i)),s):print('YES\n',i);exit(0)
print('NO')
375_A. Divisible by Seven

You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.

Number a doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resulting number also mustn't contain any leading zeroes.

Input

The first line contains positive integer a in the decimal record. It is guaranteed that the record of number a contains digits: 1, 6, 8, 9. Number a doesn't contain any leading zeroes. The decimal representation of number a contains at least 4 and at most 106 characters.

Output

Print a number in the decimal notation without leading zeroes — the result of the permutation.

If it is impossible to rearrange the digits of the number a in the required manner, print 0.

Examples

Input

1689


Output

1869


Input

18906


Output

18690

Example input:
1689

18906


Example output:
1869

18690


Tags: math
number theory
Difficulty rating: 1600

Solution:
c=[0]*10
for d in raw_input():c[int(d)]+=1
for d in (1,6,8,9):c[d]-=1
m=0
for d in range(10):
  for p in range(c[d]):
    m=(m*10+d)%7
x=(1869,1896,1986,1698,6198,1689,1968)[m*10000%7]
s=''
for d in range(1,10):s+=str(d)*c[d]
print s+str(x)+'0'*c[0]
877_B. Nikita and string

One day Nikita found the string containing letters "a" and "b" only. 

Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".

Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?

Input

The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b". 

Output

Print a single integer — the maximum possible size of beautiful string Nikita can get.

Examples

Input

abba


Output

4

Input

bab


Output

2

Note

It the first sample the string is already beautiful.

In the second sample he needs to delete one of "b" to make it beautiful.

Example input:
bab

abba


Example output:
2

4


Tags: brute force
dp
Difficulty rating: 1500

Solution:
a = [0] * 3
for i in raw_input():
	if i == 'a':
		a[2] = max(a) + 1
		a[0] += 1
	else:
		a[1] = max(a[:2]) + 1
print max(a)
p03283 AtCoder Beginner Contest 106 - AtCoder Express 2

In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1, 2, 3, ..., N from west to east. A company called AtCoder Express possesses M trains, and the train i runs from City L_i to City R_i (it is possible that L_i = R_i). Takahashi the king is interested in the following Q matters:

* The number of the trains that runs strictly within the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.



Although he is genius, this is too much data to process by himself. Find the answer for each of these Q queries to help him.

Constraints

* N is an integer between 1 and 500 (inclusive).
* M is an integer between 1 and 200 \ 000 (inclusive).
* Q is an integer between 1 and 100 \ 000 (inclusive).
* 1 \leq L_i \leq R_i \leq N (1 \leq i \leq M)
* 1 \leq p_i \leq q_i \leq N (1 \leq i \leq Q)

Input

Input is given from Standard Input in the following format:


N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q


Output

Print Q lines. The i-th line should contain the number of the trains that runs strictly within the section from City p_i to City q_i.

Examples

Input

2 3 1
1 1
1 2
2 2
1 2


Output

3


Input

10 3 2
1 5
2 8
7 10
1 7
3 10


Output

1
1


Input

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


Output

7
9
10
6
8
9
6
7
8
10

Example input:
10 3 2
1 5
2 8
7 10
1 7
3 10
2 3 1
1 1
1 2
2 2
1 2
10 10 10
1 6
2 9
4 5
4 7
4 7
5 8
6 6
6 7
7 9
10 10
1 8
1 9
1 10
2 8
2 9
2 10
3 8
3 9
3 10
1 10

Example output:
1
1
3
7
9
10
6
8
9
6
7
8
10

Difficulty rating: 0

Solution:
N,M,Q=map(int,input().split())
c=[[0 for i in range(N+1)] for j in range(N+1)]
for i in range(M):
  a,b=map(int,input().split())
  c[a][b]+=1
for i in range(1,N):
  for j in range(1,N+1-i):
    c[j][i+j]+=c[j+1][i+j]+c[j][i+j-1]-c[j+1][i+j-1]
for i in range(Q):
  a,b=map(int,input().split())
  print(c[a][b])
p03087 AtCoder Beginner Contest 122 - GeT AC

You are given a string S of length N consisting of `A`, `C`, `G` and `T`. Answer the following Q queries:

* Query i (1 \leq i \leq Q): You will be given integers l_i and r_i (1 \leq l_i < r_i \leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does `AC` occurs as a substring?

Constraints

* 2 \leq N \leq 10^5
* 1 \leq Q \leq 10^5
* S is a string of length N.
* Each character in S is `A`, `C`, `G` or `T`.
* 1 \leq l_i < r_i \leq N

Input

Input is given from Standard Input in the following format:


N Q
S
l_1 r_1
:
l_Q r_Q


Output

Print Q lines. The i-th line should contain the answer to the i-th query.

Example

Input

8 3
ACACTACG
3 7
2 3
1 8


Output

2
0
3

Example input:
8 3
ACACTACG
3 7
2 3
1 8

Example output:
2
0
3

Difficulty rating: 0

Solution:
I=lambda:map(int,input().split());n,q=I();s=input();a=[0]
for i in range(n):a+=a[i]+(s[i-1:i+1]=='AC'),
while q:l,r=I();print(a[r]-a[l]);q-=1
p03776 AtCoder Beginner Contest 057 - Maximum Average Sets

You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.

Constraints

* 1 \leq N \leq 50
* 1 \leq A,B \leq N
* 1 \leq v_i \leq 10^{15}
* Each v_i is an integer.

Input

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


N A B
v_1
v_2
...
v_N


Output

Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.

Examples

Input

5 2 2
1 2 3 4 5


Output

4.500000
1


Input

4 2 3
10 20 10 10


Output

15.000000
3


Input

5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996


Output

1000000000000000.000000
1

Example input:
4 2 3
10 20 10 10
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
5 2 2
1 2 3 4 5

Example output:
15.000000
3
1000000000000000.000000
1
4.500000
1

Difficulty rating: 0

Solution:
n,a,b=map(int,input().split())
u=sorted(list(map(int,input().split())))[::-1]
v=sum(u[:a])/a
print(v)
f=[1]
for i in range(50):f+=[f[-1]*(i+1)]
x=u.count(u[a-1])
if u[0]==u[a-1]:print(sum(f[x]//(f[x-i]*f[i])for i in range(a,b+1)))
else:y=u[:a].count(u[a-1]);print(f[x]//(f[x-y]*f[y]))