JerryL/AlgoSimBench huggingface dataset:
467_B. Fedor and New Game

After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3».

The game has (m + 1) players and n types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (m + 1). Types of soldiers are numbered from 0 to n - 1. Each player has an army. Army of the i-th player can be described by non-negative integer xi. Consider binary representation of xi: if the j-th bit of number xi equal to one, then the army of the i-th player has soldiers of the j-th type. 

Fedor is the (m + 1)-th player of the game. He assume that two players can become friends if their armies differ in at most k types of soldiers (in other words, binary representations of the corresponding numbers differ in at most k bits). Help Fedor and count how many players can become his friends.

Input

The first line contains three integers n, m, k (1 ≤ k ≤ n ≤ 20; 1 ≤ m ≤ 1000).

The i-th of the next (m + 1) lines contains a single integer xi (1 ≤ xi ≤ 2n - 1), that describes the i-th player's army. We remind you that Fedor is the (m + 1)-th player.

Output

Print a single integer — the number of Fedor's potential friends.

Examples

Input

7 3 1
8
5
111
17


Output

0


Input

3 3 3
1
2
3
4


Output

3

Example input:
7 3 1
8
5
111
17

3 3 3
1
2
3
4


Example output:
0

3


Tags: bitmasks
brute force
constructive algorithms
implementation
Difficulty rating: 1100

Solution:
n,m,k=map(int,input().split())
x=[int(input()) for _ in range(m+1)]
print(sum(bin(x[m]^y).count('1')<=k for y in x)-1)
988_D. Points and Powers of Two

There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size.

In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points).

Input

The first line contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of points.

The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≤ x_i ≤ 10^9) — the coordinates of points.

Output

In the first line print m — the maximum possible number of points in a subset that satisfies the conditions described above.

In the second line print m integers — the coordinates of points in the subset you have chosen.

If there are multiple answers, print any of them.

Examples

Input

6
3 5 4 7 10 12


Output

3
7 3 5

Input

5
-1 2 5 8 11


Output

1
8

Note

In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property.

Example input:
5
-1 2 5 8 11

6
3 5 4 7 10 12


Example output:
1
-1

3
3 4 5


Tags: brute force
math
Difficulty rating: 1800

Solution:
n=int(input())
s=set(map(int,input().split()))
m=max(s)
p=0
for x in s:
 d=1
 while x+d<=m:
  y=x+d
  if y in s:
   p=x,y
   if y+d in s:
    print(3);print(x,y,y+d);exit()
  d*=2
if p:
 print(2);print(*p)
else:print('1\n'+str(m))
p02704 AtCoder Beginner Contest 164 - I hate Matrix Construction

Given are an integer N and arrays S, T, U, and V, each of length N. Construct an N×N matrix a that satisfy the following conditions:

* a_{i,j} is an integer.
* 0 \leq a_{i,j} \lt 2^{64}.
* If S_{i} = 0, the bitwise AND of the elements in the i-th row is U_{i}.
* If S_{i} = 1, the bitwise OR of the elements in the i-th row is U_{i}.
* If T_{i} = 0, the bitwise AND of the elements in the i-th column is V_{i}.
* If T_{i} = 1, the bitwise OR of the elements in the i-th column is V_{i}.



However, there may be cases where no matrix satisfies the conditions.

Constraints

* All values in input are integers.
* 1 \leq N \leq 500
* 0 \leq S_{i} \leq 1
* 0 \leq T_{i} \leq 1
* 0 \leq U_{i} \lt 2^{64}
* 0 \leq V_{i} \lt 2^{64}

Input

Input is given from Standard Input in the following format:


N
S_{1} S_{2} ...  S_{N}
T_{1} T_{2} ...  T_{N}
U_{1} U_{2} ...  U_{N}
V_{1} V_{2} ...  V_{N}


Output

If there exists a matrix that satisfies the conditions, print one such matrix in the following format:


a_{1,1} ...  a_{1,N}
:
a_{N,1} ...  a_{N,N}


Note that any matrix satisfying the conditions is accepted.

If no matrix satisfies the conditions, print -1.

Examples

Input

2
0 1
1 0
1 1
1 0


Output

1 1
1 0


Input

2
1 1
1 0
15 15
15 11


Output

15 11
15 11

Example input:
2
1 1
1 0
15 15
15 11
2
0 1
1 0
1 1
1 0

Example output:
15 11
15 11
1 1
1 0

Difficulty rating: 0

Solution:
n,*s=map(int,open(0).read().split());s,t,f,g=[s[i*n:i*n+n]for i in range(4)];r=range(n);a=[n*[0]for _ in r];e=enumerate
for b in range(64):
 y=1<<b;u=[k&y for k in f];v=[k&y for k in g];l=[0]*n;m=l[:]
 for i,k in e(u):
  for j,h in e(v):
   if(k&h)|((s[i]^1)*k)|((t[j]^1)*h):a[i][j]|=y;l[i]+=1;m[j]+=1
 for i in r:
  if(l[i]==0)*s[i]*u[i]:
   for j in r:
    if(t[j]^1)*(n-m[j]>1):a[i][j]|=y;m[j]+=1;break
  if(m[i]==0)*t[i]*v[i]:
   for j in r:
    if(s[j]^1)*(n-l[j]>1):a[j][i]|=y;l[j]+=1;break
h=a[0][:];w=[i[0]for i in a]
for i,k in e(a):
 for j,l in e(k):w[i]=(l|w[i]if s[i]else w[i]&l);h[j]=(l|h[j]if t[j]else h[j]&l)
if g+f!=h+w:exit(print(-1))
for i in a:print(*i)
p02690 AtCoder Beginner Contest 166 - I hate Factorization

Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.

Constraints

* 1 \leq X \leq 10^9
* X is an integer.
* There exists a pair of integers (A, B) satisfying the condition in Problem Statement.

Input

Input is given from Standard Input in the following format:


X


Output

Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them.


A B

Output

Print A and B, with space in between. If there are multiple pairs of integers (A, B) satisfying the condition, you may print any of them.


A B

Examples

Input

33


Output

2 -1


Input

1


Output

0 -1

Example input:
33
1

Example output:
2 -1
0 -1

Difficulty rating: 0

Solution:
i=j=x=int(input())
while i**5-j**5-x:i=-~i%127;j=j%257-i
print(i,j)
464_B. Restore Cube 

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

Example 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

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


Example 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 

NO


Tags: brute force
geometry
Difficulty rating: 2000

Solution:
from itertools import permutations as p

d = lambda a, b: sum((i - j) ** 2 for i, j in zip(a, b))
f = lambda a, b: [i + j - k for i, j, k in zip(a, b, q)]
g = lambda t: sorted(sorted(q) for q in t)

v = [sorted(map(int, input().split())) for i in range(8)]
q = v.pop()

def yes(t, v):
    print('YES')
    d = [str(sorted(i)) for i in t]
    for j in v:
        i = d.index(str(j))
        q = t.pop(i)
        print(*q)
        d.pop(i)
    exit()

u = g(v)
for a, b, c in p(v, 3):
    for x in p(a):
        s = 2 * d(q, x)
        if not s: continue
        for y in p(b):
            if not 2 * d(q, y) == d(x, y) == s: continue
            for z in p(c):
                if not 2 * d(q, z) == d(x, z) == d(y, z) == s: continue
                t = [x, y, z] + [f(x, y), f(x, z), f(y, z), f(f(x, y), z)]
                if g(t) == u: yes(t + [q], v + [q])

print('NO')
p02695 AtCoder Beginner Contest 165 - Many Requirements

Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i , c_i , d_i ).

Consider a sequence A satisfying the following conditions:

* A is a sequence of N positive integers.
* 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.



Let us define a score of this sequence as follows:

* The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)



Find the maximum possible score of A.

Constraints

* All values in input are integers.
* 2 ≤ N ≤ 10
* 1 \leq M \leq 10
* 1 \leq Q \leq 50
* 1 \leq a_i < b_i \leq N ( i = 1, 2, ..., Q )
* 0 \leq c_i \leq M - 1 ( i = 1, 2, ..., Q )
* (a_i, b_i, c_i) \neq (a_j, b_j, c_j) (where i \neq j)
* 1 \leq d_i \leq 10^5 ( i = 1, 2, ..., Q )

Input

Input is given from Standard Input in the following format:


N M Q
a_1 b_1 c_1 d_1
:
a_Q b_Q c_Q d_Q


Output

Print the maximum possible score of A.

Examples

Input

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


Output

110


Input

4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328


Output

357500


Input

10 10 1
1 10 9 1


Output

1

Example input:
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
10 10 1
1 10 9 1
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328

Example output:
110
1
357500

Difficulty rating: 0

Solution:
from itertools import*
n,m,q,*L=map(int,open(0).read().split())
print(max(sum(d*(x[b-1]-x[a-1]==c)for a,b,c,d in zip(*[iter(L)]*4))for x in combinations_with_replacement(range(m),n)))
292_C. Beautiful IP Addresses

The problem uses a simplified TCP/IP address model, please read the statement carefully.

An IP address is a 32-bit integer, represented as a group of four decimal 8-bit integers (without leading zeroes), separated by commas. For example, record 0.255.1.123 shows a correct IP address and records 0.256.1.123 and 0.255.1.01 do not. In the given problem an arbitrary group of four 8-bit integers is a correct IP address.

Our hero Polycarpus still works as a system administrator in some large corporation. He likes beautiful IP addresses. To check if some IP address is beautiful, he should do the following:

  1. write out in a line four 8-bit numbers of the IP address, without the commas; 
  2. check if the resulting string is a palindrome. 



Let us remind you that a palindrome is a string that reads the same from right to left and from left to right.

For example, IP addresses 12.102.20.121 and 0.3.14.130 are beautiful (as strings "1210220121" and "0314130" are palindromes), and IP addresses 1.20.20.1 and 100.4.4.1 are not.

Polycarpus wants to find all beautiful IP addresses that have the given set of digits. Each digit from the set must occur in the IP address at least once. IP address must not contain any other digits. Help him to cope with this difficult task.

Input

The first line contains a single integer n (1 ≤ n ≤ 10) — the number of digits in the set. The second line contains the set of integers a1, a2, ..., an (0 ≤ ai ≤ 9). It is guaranteed that all digits in the set are distinct.

Output

In the first line print a single integer k — the number of beautiful IP addresses that contain the given set of digits. In the following k lines print the IP addresses, one per line in the arbitrary order.

Examples

Input

6
0 1 2 9 8 7


Output

6
78.190.209.187
79.180.208.197
87.190.209.178
89.170.207.198
97.180.208.179
98.170.207.189


Input

1
4


Output

16
4.4.4.4
4.4.4.44
4.4.44.4
4.4.44.44
4.44.4.4
4.44.4.44
4.44.44.4
4.44.44.44
44.4.4.4
44.4.4.44
44.4.44.4
44.4.44.44
44.44.4.4
44.44.4.44
44.44.44.4
44.44.44.44

Example input:
6
0 1 2 9 8 7

1
4


Example output:
6
78.190.209.187
79.180.208.197
87.190.209.178
89.170.207.198
97.180.208.179
98.170.207.189

16
4.4.4.4
4.4.4.44
4.4.44.4
4.4.44.44
4.44.4.4
4.44.4.44
4.44.44.4
4.44.44.44
44.4.4.4
44.4.4.44
44.4.44.4
44.4.44.44
44.44.4.4
44.44.4.44
44.44.44.4
44.44.44.44


Tags: brute force
Difficulty rating: 2000

Solution:
m=input()
g=map(int,raw_input().split())
n=reduce(lambda x,y:x|(1<<y),g,0)
a=set()
v=[0]*4
def sp(s,u=0):
  if u<4:
    n=len(s)
    x,y=0,-1
    for i in range(min(3,n-3+u)):
      x=x*10+s[i]
      if x>255 or 0==y:break
      v[u],y=x,x
      sp(s[i+1:],u+1)
  elif not s:
    a.add(tuple(v))
def go(a,b,o=0):
  l=len(a)+len(b)
  if 3<l<13 and o==n:sp(a+b)
  if 2<l<12:
    for c in g:
      if (o|(1<<c))==n:sp(a+[c]+b)
  if l<12:
    for c in g:go(a+[c],[c]+b,o|(1<<c))
if m<7:
  go([],[])
  print len(a)
  for x in a:print '%d.%d.%d.%d'%x
else:
  print 0
193_B. Xor

John Doe has four arrays: a, b, k, and p. Each array consists of n integers. Elements of all arrays are indexed starting from 1. Array p is a permutation of integers 1 to n.

John invented a game for his friends and himself. Initially a player is given array a. The player must consecutively execute exactly u operations on a. You are permitted to execute the following operations:

  * Operation 1: For each <image> change ai into <image>. Expression <image> means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in language C++ and Java it is marked as "^", in Pascal — as "xor". 
  * Operation 2: For each <image> change ai into api + r. When this operation is executed, all changes are made at the same time. 



After all u operations are applied, the number of points the player gets is determined by the formula <image>. 

John wants to find out what maximum number of points a player can win in his game. Help him.

Input

The first line contains space-separated integers n, u and r (1 ≤ n, u ≤ 30, 0 ≤ r ≤ 100) — the number of elements in each array, the number of operations and the number that describes one of the operations. 

Each of the next four lines contains n space-separated integers — arrays a, b, k, p. The first line has array a, the second line has array b, the third line has array k and the fourth one has array p. 

It is guaranteed that elements of arrays a and b are positive and do not exceed 104 (1 ≤ ai, bi ≤ 104), elements of array k do not exceed 104 in the absolute value (|k| ≤ 104) and p is a permutation of numbers from 1 to n.

Output

On a single line print number s — the maximum number of points that a player can win in John's game.

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 2 1
7 7 7
8 8 8
1 2 3
1 3 2


Output

96


Input

2 1 0
1 1
1 1
1 -1
1 2


Output

0

Note

In the first sample you should first apply the operation of the first type, then the operation of the second type.

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

2 1 0
1 1
1 1
1 -1
1 2


Example output:
96

0


Tags: brute force
Difficulty rating: 2000

Solution:
#include <bits/stdc++.h>
using namespace std;
long long n, u, r, t, *b, *k, *p;
void dfs(long long i, long long* a, long long o = 1) {
  if (i < u) {
    if (!((u - i) & 1)) dfs(u, a);
    long long c[32];
    if (o) {
      for (long long j = 1; j <= n; ++j) c[j] = a[j] ^ b[j];
      dfs(i + 1, c, 0);
    }
    for (long long j = 1; j <= n; ++j) c[j] = a[p[j]] + r;
    dfs(i + 1, c);
  } else {
    long long s = 0;
    for (long long j = 1; j <= n; ++j) s += a[j] * k[j];
    if (t < s) t = s;
  }
}
int main(void) {
  long long a[4][32];
  cin >> n >> u >> r;
  for (int i = 0; i < 4; ++i)
    for (int j = 1; j <= n; ++j) cin >> a[i][j];
  b = a[1], k = a[2], p = a[3];
  t = -(1LL << 60);
  dfs(0, a[0]);
  cout << t << endl;
}
p02614 AtCoder Beginner Contest 173 - H and V

We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`.

Consider doing the following operation:

* Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns.



You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.

Constraints

* 1 \leq H, W \leq 6
* 1 \leq K \leq HW
* c_{i,j} is `.` or `#`.

Input

Input is given from Standard Input in the following format:


H W K
c_{1,1}c_{1,2}...c_{1,W}
c_{2,1}c_{2,2}...c_{2,W}
:
c_{H,1}c_{H,2}...c_{H,W}


Output

Print an integer representing the number of choices of rows and columns satisfying the condition.

Examples

Input

2 3 2
..#
###


Output

5


Input

2 3 2
..#


Output

5


Input

2 3 4
..#


Output

1


Input

2 2 3


Output

0


Input

6 6 8
..##..
.#..#.
....#

....#
....#


Output

208

Example input:
2 3 4
..#
6 6 8
..##..
.#..#.
....#

....#
....#
2 3 2
..#
2 2 3
2 3 2
..#
###

Example output:
1
208
5
0
5

Difficulty rating: 0

Solution:
h,*c=open(0)
h,w,k=map(int,h.split())
print(sum(k==sum(y>>w+z//w&y>>z%w&ord(c[z//w][z%w])&1for z in range(h*w))for y in range(1<<h+w)))
124_B. Permutations

You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers.

Input

The first line contains integers n and k — the number and digit capacity of numbers correspondingly (1 ≤ n, k ≤ 8). Next n lines contain k-digit positive integers. Leading zeroes are allowed both in the initial integers and the integers resulting from the rearranging of digits.

Output

Print a single number: the minimally possible difference between the largest and the smallest number after the digits are rearranged in all integers by the same rule.

Examples

Input

6 4
5237
2753
7523
5723
5327
2537


Output

2700


Input

3 3
010
909
012


Output

3


Input

7 5
50808
36603
37198
44911
29994
42543
50156


Output

20522

Note

In the first sample, if we rearrange the digits in numbers as (3,1,4,2), then the 2-nd and the 4-th numbers will equal 5237 and 2537 correspondingly (they will be maximum and minimum for such order of digits).

In the second sample, if we swap the second digits and the first ones, we get integers 100, 99 and 102.

Example input:
6 4
5237
2753
7523
5723
5327
2537

7 5
50808
36603
37198
44911
29994
42543
50156

3 3
010
909
012


Example output:
2700

20522

3


Tags: brute force
combinatorics
implementation
Difficulty rating: 1400

Solution:
from itertools import *
r=raw_input
print min(max(i)-min(i)for i in zip(*[map(int,map("".join,permutations(r())))for i in[0]*int(r()[0])]))
p03805 AtCoder Beginner Contest 054 - One-stroke Path

You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges.
Here, a self-loop is an edge where a_i = b_i (1≤i≤M), and double edges are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M).
How many different paths start from vertex 1 and visit all the vertices exactly once?
Here, the endpoints of a path are considered visited.

For example, let us assume that the following undirected graph shown in Figure 1 is given.

<image>

Figure 1: an example of an undirected graph

The following path shown in Figure 2 satisfies the condition.

<image>

Figure 2: an example of a path that satisfies the condition

However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices.

<image>

Figure 3: an example of a path that does not satisfy the condition

Neither the following path shown in Figure 4, because it does not start from vertex 1.

<image>

Figure 4: another example of a path that does not satisfy the condition

Constraints

* 2≦N≦8
* 0≦M≦N(N-1)/2
* 1≦a_i<b_i≦N
* The given graph contains neither self-loops nor double edges.

Input

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


N M
a_1 b_1
a_2 b_2
:
a_M b_M


Output

Print the number of the different paths that start from vertex 1 and visit all the vertices exactly once.

Examples

Input

3 3
1 2
1 3
2 3


Output

2


Input

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


Output

1

Example input:
7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7
3 3
1 2
1 3
2 3

Example output:
1
2

Difficulty rating: 0

Solution:
from itertools import*
n,*t=map(int,open(0).read().split())
e={0}
for a in zip(t[1::2],t[2::2]):e|={a,a[::-1]}
print(sum(all(u in e for u in zip(t,t[1:]))for t in permutations(range(1,n+1))if t[0]<2))