message stringlengths 2 67k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 463 109k | cluster float64 19 19 | __index_level_0__ int64 926 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers x and y from the board, he gets gcd(x, y) points. At the beginning of the game Bimokh has zero points.
Mashmokh wants to win in the game. For this reason he wants his boss to get exactly k points in total. But the guy doesn't know how choose the initial sequence in the right way.
Please, help him. Find n distinct integers a1, a2, ..., an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109.
Input
The first line of input contains two space-separated integers n, k (1 ≤ n ≤ 105; 0 ≤ k ≤ 108).
Output
If such sequence doesn't exist output -1 otherwise output n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Examples
Input
5 2
Output
1 2 3 4 5
Input
5 3
Output
2 4 3 7 1
Input
7 2
Output
-1
Note
gcd(x, y) is greatest common divisor of x and y.
Submitted Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
#vsInput()
n,k=value()
if(k==0 and n==1):
print(1)
exit()
if(k<n//2 or n==1):
print(-1)
exit()
ans=[]
#print(ans)
pairs=n//2
k-=(pairs-1)
ans.append(k)
ans.append(k*2)
k=2*k+1
for i in range(pairs-1):
ans.append(k)
ans.append(k+1)
k+=2
if(n%2==1):
ans.append(ans[-1]+1)
print(*ans)
``` | instruction | 0 | 15,421 | 19 | 30,842 |
Yes | output | 1 | 15,421 | 19 | 30,843 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers x and y from the board, he gets gcd(x, y) points. At the beginning of the game Bimokh has zero points.
Mashmokh wants to win in the game. For this reason he wants his boss to get exactly k points in total. But the guy doesn't know how choose the initial sequence in the right way.
Please, help him. Find n distinct integers a1, a2, ..., an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109.
Input
The first line of input contains two space-separated integers n, k (1 ≤ n ≤ 105; 0 ≤ k ≤ 108).
Output
If such sequence doesn't exist output -1 otherwise output n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Examples
Input
5 2
Output
1 2 3 4 5
Input
5 3
Output
2 4 3 7 1
Input
7 2
Output
-1
Note
gcd(x, y) is greatest common divisor of x and y.
Submitted Solution:
```
n,k = map(int,input().split())
if n==1 :
print(1 if k==0 else -1)
else:
pr = (n-2)//2
k -= pr
if k<1 :
print(-1)
else:
res = []
res += [k,2*k]
res += list(range(2*k+1,2*k+1+2*pr))
if n%2:
res += [2*k+1+2*pr]
print(*res)
# C:\Users\Usuario\HOME2\Programacion\ACM
``` | instruction | 0 | 15,422 | 19 | 30,844 |
Yes | output | 1 | 15,422 | 19 | 30,845 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers x and y from the board, he gets gcd(x, y) points. At the beginning of the game Bimokh has zero points.
Mashmokh wants to win in the game. For this reason he wants his boss to get exactly k points in total. But the guy doesn't know how choose the initial sequence in the right way.
Please, help him. Find n distinct integers a1, a2, ..., an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109.
Input
The first line of input contains two space-separated integers n, k (1 ≤ n ≤ 105; 0 ≤ k ≤ 108).
Output
If such sequence doesn't exist output -1 otherwise output n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Examples
Input
5 2
Output
1 2 3 4 5
Input
5 3
Output
2 4 3 7 1
Input
7 2
Output
-1
Note
gcd(x, y) is greatest common divisor of x and y.
Submitted Solution:
```
#from sys import stdin
#input=stdin.readline
#a = sorted([(n, i) for i, n in enumerate(map(int, input().split()))])
# from collections import Counter
# import sys
#s="abcdefghijklmnopqrstuvwxyz"
#n=int(input())
#n,k=map(int,input().split())
#arr=list(map(int,input().split()))
#arr=list(map(int,input().split()))
n,k=map(int,input().split())
var=k-n//2+1
if k<n//2:
print(-1)
exit()
if n==1:
print(-1)
exit()
g=1
for i in range(n):
if i==0:
print(var,end=" ")
elif i==1:
print(2*var,end=" ")
else:
print(2*var+g,end=" ")
g+=1
``` | instruction | 0 | 15,423 | 19 | 30,846 |
No | output | 1 | 15,423 | 19 | 30,847 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers x and y from the board, he gets gcd(x, y) points. At the beginning of the game Bimokh has zero points.
Mashmokh wants to win in the game. For this reason he wants his boss to get exactly k points in total. But the guy doesn't know how choose the initial sequence in the right way.
Please, help him. Find n distinct integers a1, a2, ..., an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109.
Input
The first line of input contains two space-separated integers n, k (1 ≤ n ≤ 105; 0 ≤ k ≤ 108).
Output
If such sequence doesn't exist output -1 otherwise output n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Examples
Input
5 2
Output
1 2 3 4 5
Input
5 3
Output
2 4 3 7 1
Input
7 2
Output
-1
Note
gcd(x, y) is greatest common divisor of x and y.
Submitted Solution:
```
from math import *
from bisect import *
from collections import Counter,defaultdict
from sys import stdin, stdout
input = stdin.readline
I =lambda:int(input())
SI =lambda:input()
M =lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))
n,k=M()
a=[]
b=n//2
if b>k or b==0:
print(-1)
else:
c=k-(b-1)
a+=[c,c+c]
d=2*c+1
for i in range(d,(d+n)-2):
a+=[i]
print(*a)
``` | instruction | 0 | 15,424 | 19 | 30,848 |
No | output | 1 | 15,424 | 19 | 30,849 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers x and y from the board, he gets gcd(x, y) points. At the beginning of the game Bimokh has zero points.
Mashmokh wants to win in the game. For this reason he wants his boss to get exactly k points in total. But the guy doesn't know how choose the initial sequence in the right way.
Please, help him. Find n distinct integers a1, a2, ..., an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109.
Input
The first line of input contains two space-separated integers n, k (1 ≤ n ≤ 105; 0 ≤ k ≤ 108).
Output
If such sequence doesn't exist output -1 otherwise output n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Examples
Input
5 2
Output
1 2 3 4 5
Input
5 3
Output
2 4 3 7 1
Input
7 2
Output
-1
Note
gcd(x, y) is greatest common divisor of x and y.
Submitted Solution:
```
n , m = map(int,input().split())
ans=[]
c=0
if m<n//2:
print(-1)
exit()
elif n==1 and m!=0:
print(-1)
exit()
elif n==1 and m==0:
print(0)
exit()
m-=(n//2-1)
ans.append((1)*m)
ans.append((2)*m)
k=ans[-1]
for i in range(1,n-2,2):
ans.append(k+i)
ans.append(k+i+1)
if n%2!=0:
ans.append(10**9)
print(*ans)
``` | instruction | 0 | 15,425 | 19 | 30,850 |
No | output | 1 | 15,425 | 19 | 30,851 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers x and y from the board, he gets gcd(x, y) points. At the beginning of the game Bimokh has zero points.
Mashmokh wants to win in the game. For this reason he wants his boss to get exactly k points in total. But the guy doesn't know how choose the initial sequence in the right way.
Please, help him. Find n distinct integers a1, a2, ..., an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109.
Input
The first line of input contains two space-separated integers n, k (1 ≤ n ≤ 105; 0 ≤ k ≤ 108).
Output
If such sequence doesn't exist output -1 otherwise output n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Examples
Input
5 2
Output
1 2 3 4 5
Input
5 3
Output
2 4 3 7 1
Input
7 2
Output
-1
Note
gcd(x, y) is greatest common divisor of x and y.
Submitted Solution:
```
n,k=(int(i) for i in input().split())
k1=(n-2)//2
x=k-((n-2)//2)
l=[x,2*x]
if(k>=n//2):
for i in range(n-2):
l.append(2*x+1+i)
print(*l)
else:
print(-1)
``` | instruction | 0 | 15,426 | 19 | 30,852 |
No | output | 1 | 15,426 | 19 | 30,853 |
Provide a correct Python 3 solution for this coding contest problem.
Background
The kindergarten attached to the University of Aizu is a kindergarten where children who love programming gather. Yu, one of the kindergarten children, loves darts as much as programming. Yu-kun was addicted to darts recently, but he got tired of ordinary darts, so he decided to make his own darts board.
See darts for darts.
Problem
The contents of the darts that Yu-kun thought about are as follows.
The infinitely wide darts board has several polygons with scores. The player has only one darts arrow. The player throws an arrow and stabs the arrow into one of the polygons to get the score written there. If you stab it in any other way, you will not get any points.
Yu-kun decided where to throw the arrow, but it doesn't always stick exactly. The darts board is a two-dimensional plane, and the position Yu-kun is aiming for is a point (cx, cy). The place where the arrow thrown by Yu-kun sticks is selected with a uniform probability from any point included in the circle with radius r centered on the point (cx, cy). The coordinates of the exposed points do not have to be integers.
Since the information on the darts board, the position (cx, cy) that Yu-kun aims at, and the radius r are given, answer the expected value of the score that Yu-kun can get.
Constraints
The input satisfies the following conditions.
* All inputs are given as integers
* 1 ≤ n ≤ 50
* 0 ≤ cx, cy, x, y ≤ 1000
* 1 ≤ r ≤ 100
* 3 ≤ p ≤ 10
* 1 ≤ score ≤ 100
* Polygon vertices are given in such an order that they visit adjacent vertices clockwise or counterclockwise.
* The sides of a polygon do not have anything in common with the sides of another polygon
* A polygon does not contain another polygon
* If the arrow sticks on the side of the polygon, no score will be given.
Input
n cx cy r
Information on the 0th polygon
Information on the first polygon
...
Information on the (n-1) th polygon
n is the number of polygons on the darts board. Polygonal information is given in the following format.
p score
x0 y0
x1 y1
...
x (p-1) y (p-1)
p represents the number of vertices of the polygon, and score represents the score written on the polygon. Each line segment of the polygon is a line segment connecting the vertices of (xi, yi) and (xi + 1, yi + 1) (i <p-1), and (xp-1, yp-1) and (x0, It is a line segment connecting the vertices of y0).
Output
Output the expected value of the score that Yu-kun can get in one line. Any number of digits after the decimal point may be output. However, the error in the answer must not exceed 0.000001 (10-6).
Examples
Input
1 2 2 1
4 1
0 0
2 0
2 2
0 2
Output
0.2500000000
Input
1 2 2 1
4 1
0 0
5 0
5 5
0 5
Output
1.0000000000
Input
4 3 3 2
3 1
1 1
3 3
1 5
4 2
2 0
5 0
4 2
3 2
3 3
4 3
6 1
6 5
4 4
3 4
4 4
5 6
2 6
Output
1.0574955319
Input
1 10 10 1
4 10
0 0
1 0
1 1
0 1
Output
0.0000000000 | instruction | 0 | 15,896 | 19 | 31,792 |
"Correct Solution:
```
# 参考 http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3277276#1
from math import acos, hypot, isclose, sqrt
def intersection(circle, polygon):
# 円と多角形の共通部分の面積
# 多角形の点が反時計回りで与えられれば正の値、時計回りなら負の値を返す
x, y, r = circle
polygon = [(xp-x, yp-y) for xp, yp in polygon]
area = 0.0
for p1, p2 in zip(polygon, polygon[1:] + [polygon[0]]):
ps = seg_intersection((0, 0, r), (p1, p2))
for pp1, pp2 in zip([p1] + ps, ps + [p2]):
c = cross(pp1, pp2) # pp1 と pp2 の位置関係によって正負が変わる
if c == 0: # pp1, pp2, 原点が同一直線上にある場合
continue
d1 = hypot(*pp1)
d2 = hypot(*pp2)
if le(d1, r) and le(d2, r):
area += c / 2 # pp1, pp2, 原点を結んだ三角形の面積
else:
t = acos(dot(pp1, pp2) / (d1 * d2)) # pp1-原点とpp2-原点の成す角
sign = 1.0 if c >= 0 else -1.0
area += sign * r * r * t / 2 # 扇形の面積
return area
def cross(v1, v2): # 外積
x1, y1 = v1
x2, y2 = v2
return x1 * y2 - x2 * y1
def dot(v1, v2): # 内積
x1, y1 = v1
x2, y2 = v2
return x1 * x2 + y1 * y2
def seg_intersection(circle, seg):
# 円と線分の交点(円の中心が原点でない場合は未検証)
x0, y0, r = circle
p1, p2 = seg
x1, y1 = p1
x2, y2 = p2
p1p2 = (x2 - x1) ** 2 + (y2 - y1) ** 2
op1 = (x1 - x0) ** 2 + (y1 - y0) ** 2
rr = r * r
dp = dot((x1 - x0, y1 - y0), (x2 - x1, y2 - y1))
d = dp * dp - p1p2 * (op1 - rr)
ps = []
if isclose(d, 0.0, abs_tol=1e-9):
t = -dp / p1p2
if ge(t, 0.0) and le(t, 1.0):
ps.append((x1 + t * (x2 - x1), y1 + t * (y2 - y1)))
elif d > 0.0:
t1 = (-dp - sqrt(d)) / p1p2
if ge(t1, 0.0) and le(t1, 1.0):
ps.append((x1 + t1 * (x2 - x1), y1 + t1 * (y2 - y1)))
t2 = (-dp + sqrt(d)) / p1p2
if ge(t2, 0.0) and le(t2, 1.0):
ps.append((x1 + t2 * (x2 - x1), y1 + t2 * (y2 - y1)))
# assert all(isclose(r, hypot(x, y)) for x, y in ps)
return ps
def le(f1, f2): # less equal
return f1 < f2 or isclose(f1, f2, abs_tol=1e-9)
def ge(f1, f2): # greater equal
return f1 > f2 or isclose(f1, f2, abs_tol=1e-9)
N, cx, cy, r = map(int, input().split())
ans = 0
from math import pi
circle_area = pi * r * r
for _ in range(N):
p, score = map(int, input().split())
ps = []
for _ in range(p):
x, y = map(int, input().split())
ps.append((x, y))
area = intersection((cx, cy, r), ps)
ans += abs(area) * score / circle_area
print(f"{ans:.10f}")
``` | output | 1 | 15,896 | 19 | 31,793 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct.
Nikolay has m cards, distinct numbers from 1 to m are written on them, one per card. It means that Nikolay has exactly one card with number 1, exactly one card with number 2 and so on.
A single exchange is a process in which Eugeny gives one card to Nikolay and takes another one from those Nikolay has. Your task is to find the minimum number of card exchanges and determine which cards Eugeny should exchange.
Input
The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 109) — the number of cards Eugeny has and the number of cards Nikolay has. It is guaranteed that n is even.
The second line contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers on Eugeny's cards.
Output
If there is no answer, print -1.
Otherwise, in the first line print the minimum number of exchanges. In the second line print n integers — Eugeny's cards after all the exchanges with Nikolay. The order of cards should coincide with the card's order in the input data. If the i-th card wasn't exchanged then the i-th number should coincide with the number from the input data. Otherwise, it is considered that this card was exchanged, and the i-th number should be equal to the number on the card it was exchanged to.
If there are multiple answers, it is allowed to print any of them.
Examples
Input
6 2
5 6 7 9 4 5
Output
1
5 6 7 9 4 2
Input
8 6
7 7 7 7 8 8 8 8
Output
6
7 2 4 6 8 1 3 5
Input
4 1
4 2 1 10
Output
-1 | instruction | 0 | 16,464 | 19 | 32,928 |
Tags: greedy, implementation, math
Correct Solution:
```
n, m = map(int, input().split())
a = list(map(int, input().split()))
counter = 0
s = set(a)
nech = set()
chet = set()
for elem in a:
if elem % 2:
nech.add(elem)
else:
chet.add(elem)
while len(nech) > n // 2:
nech.pop()
while len(chet) > n // 2:
chet.pop()
l_n = set([i for i in range(1, min(m + 1, 1000000), 2)])
l_ch = set([i for i in range(2, min(m + 1, 1000000), 2)])
l_ch.difference_update(chet)
l_n.difference_update(nech)
#print(l_ch)
#print(l_n, nech)
if len(l_ch) + len(chet) < n // 2 or len(l_n) + len(nech) < n // 2:
print(-1)
else:
n1 = len(chet)
n2 = len(nech)
for i in range(n):
if a[i] in chet:
chet.remove(a[i])
elif a[i] in nech:
nech.remove(a[i])
else:
counter += 1
if (n//2 - n1) > 0:
a[i] = l_ch.pop()
n1 += 1
else:
a[i] = l_n.pop()
n2 += 1
print(counter)
print(*a)
``` | output | 1 | 16,464 | 19 | 32,929 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct.
Nikolay has m cards, distinct numbers from 1 to m are written on them, one per card. It means that Nikolay has exactly one card with number 1, exactly one card with number 2 and so on.
A single exchange is a process in which Eugeny gives one card to Nikolay and takes another one from those Nikolay has. Your task is to find the minimum number of card exchanges and determine which cards Eugeny should exchange.
Input
The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 109) — the number of cards Eugeny has and the number of cards Nikolay has. It is guaranteed that n is even.
The second line contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers on Eugeny's cards.
Output
If there is no answer, print -1.
Otherwise, in the first line print the minimum number of exchanges. In the second line print n integers — Eugeny's cards after all the exchanges with Nikolay. The order of cards should coincide with the card's order in the input data. If the i-th card wasn't exchanged then the i-th number should coincide with the number from the input data. Otherwise, it is considered that this card was exchanged, and the i-th number should be equal to the number on the card it was exchanged to.
If there are multiple answers, it is allowed to print any of them.
Examples
Input
6 2
5 6 7 9 4 5
Output
1
5 6 7 9 4 2
Input
8 6
7 7 7 7 8 8 8 8
Output
6
7 2 4 6 8 1 3 5
Input
4 1
4 2 1 10
Output
-1 | instruction | 0 | 16,465 | 19 | 32,930 |
Tags: greedy, implementation, math
Correct Solution:
```
#!/usr/bin/env python3
class CantException(Exception):
pass
def odd_v(value):
return 1 if value % 2 == 1 else -1
change_idx = 1
acceptable = {-1: set(), 1: set()}
def change(card_values, oddv, m):
global change_idx
if acceptable[oddv]:
res = acceptable[oddv].pop()
card_values.add(res)
return res
change_idx_start = change_idx
while change_idx in card_values or odd_v(change_idx) != oddv:
if change_idx not in card_values:
acceptable[odd_v(change_idx)].add(change_idx)
change_idx += 1
if change_idx > m:
change_idx = 1
if change_idx == change_idx_start:
raise CantException()
res = change_idx
card_values.add(res)
change_idx += 1
if change_idx > m:
change_idx = 1
return res
def solve():
n, m = map(int, input().split())
cards = list(map(int, input().split()))
odd_balance = 0
card_values = set()
indices_to_be_changed = set()
for i, c in enumerate(cards):
odd_balance += odd_v(c)
if c in card_values:
indices_to_be_changed.add(i)
card_values.add(c)
# print("indices to be changed: ", indices_to_be_changed)
change_count = len(indices_to_be_changed)
for i in indices_to_be_changed:
if odd_v(cards[i]) * odd_balance <= 0:
#print("Changing ", cards[i])
cards[i] = change(card_values, odd_v(cards[i]), m)
#print("Changed to ", cards[i])
else:
#print("For teh balance changing ", cards[i])
odd_balance -= 2 * odd_v(cards[i])
cards[i] = change(card_values, - odd_v(cards[i]), m)
#print("Changed to ", cards[i])
#print("current odd balance:", odd_balance)
for i in range(len(cards)):
if odd_balance == 0:
break
if odd_v(cards[i]) * odd_balance > 0:
# print("gonna change")
change_count += 1
odd_balance -= 2 * odd_v(cards[i])
cards[i] = change(card_values, -odd_v(cards[i]), m)
odd_balance = 0
for i, c in enumerate(cards):
odd_balance += odd_v(c)
if odd_balance != 0:
print(odd_balance)
print("WTFFFFF")
return change_count, cards
if __name__ == '__main__':
try:
change_cnt, cards = solve()
print(change_cnt)
print(" ".join(map(str, cards)))
except CantException:
print("-1")
``` | output | 1 | 16,465 | 19 | 32,931 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct.
Nikolay has m cards, distinct numbers from 1 to m are written on them, one per card. It means that Nikolay has exactly one card with number 1, exactly one card with number 2 and so on.
A single exchange is a process in which Eugeny gives one card to Nikolay and takes another one from those Nikolay has. Your task is to find the minimum number of card exchanges and determine which cards Eugeny should exchange.
Input
The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 109) — the number of cards Eugeny has and the number of cards Nikolay has. It is guaranteed that n is even.
The second line contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers on Eugeny's cards.
Output
If there is no answer, print -1.
Otherwise, in the first line print the minimum number of exchanges. In the second line print n integers — Eugeny's cards after all the exchanges with Nikolay. The order of cards should coincide with the card's order in the input data. If the i-th card wasn't exchanged then the i-th number should coincide with the number from the input data. Otherwise, it is considered that this card was exchanged, and the i-th number should be equal to the number on the card it was exchanged to.
If there are multiple answers, it is allowed to print any of them.
Examples
Input
6 2
5 6 7 9 4 5
Output
1
5 6 7 9 4 2
Input
8 6
7 7 7 7 8 8 8 8
Output
6
7 2 4 6 8 1 3 5
Input
4 1
4 2 1 10
Output
-1 | instruction | 0 | 16,466 | 19 | 32,932 |
Tags: greedy, implementation, math
Correct Solution:
```
import sys
import math
def main():
n,m = map(int,sys.stdin.readline().split())
x = list(map(int,sys.stdin.readline().split()))
c = []
nc = []
d = {}
for i in range(n):
xi = x[i]
if xi in d:
continue
d[xi] = True
if xi%2 == 0:
c.append((xi,i))
else:
nc.append((xi,i))
a, b = -1,0
if len(nc) > len(c):
c,nc = nc,c
a,b = b,a
c = sorted(c, key=lambda x: -x[0])
d = {}
r = [0]*n
for i in range(len(nc)):
xi,j = nc[i]
r[j] = xi
d[xi]= True
for i in range(min(n//2,len(c))):
xi,j = c[i]
r[j] = xi
d[xi]= True
j=0
ans=0
for i in range(len(c),n//2):
b+=2
while b in d:
b+=2
while r[j]!=0:
j+=1
r[j] = b
ans+=1
for i in range(len(nc),n//2):
a+=2
while a in d:
a+=2
while r[j]!=0:
j+=1
r[j] = a
ans+=1
if a>m or b>m:
print(-1)
return
print(ans)
print(' '.join(map(str,r)))
main()
``` | output | 1 | 16,466 | 19 | 32,933 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct.
Nikolay has m cards, distinct numbers from 1 to m are written on them, one per card. It means that Nikolay has exactly one card with number 1, exactly one card with number 2 and so on.
A single exchange is a process in which Eugeny gives one card to Nikolay and takes another one from those Nikolay has. Your task is to find the minimum number of card exchanges and determine which cards Eugeny should exchange.
Input
The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 109) — the number of cards Eugeny has and the number of cards Nikolay has. It is guaranteed that n is even.
The second line contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers on Eugeny's cards.
Output
If there is no answer, print -1.
Otherwise, in the first line print the minimum number of exchanges. In the second line print n integers — Eugeny's cards after all the exchanges with Nikolay. The order of cards should coincide with the card's order in the input data. If the i-th card wasn't exchanged then the i-th number should coincide with the number from the input data. Otherwise, it is considered that this card was exchanged, and the i-th number should be equal to the number on the card it was exchanged to.
If there are multiple answers, it is allowed to print any of them.
Examples
Input
6 2
5 6 7 9 4 5
Output
1
5 6 7 9 4 2
Input
8 6
7 7 7 7 8 8 8 8
Output
6
7 2 4 6 8 1 3 5
Input
4 1
4 2 1 10
Output
-1 | instruction | 0 | 16,467 | 19 | 32,934 |
Tags: greedy, implementation, math
Correct Solution:
```
from collections import *
f = lambda: map(int, input().split())
g = lambda: exit(print(-1))
n, m = f()
if n & 1: g()
t = list(f())
a = [set(), set()]
b = [[], []]
u = []
for q in t:
if q in a[q & 1]: u.append(q)
a[q & 1].add(q)
for q in range(1, min(m, n) + 1):
if q not in a[q & 1]: b[q & 1].append(q)
d = len(a[0]) < len(a[1])
a = list(a[d])[len(a[not d]):]
x, y = b[not d], b[d]
k = len(a) + len(u) >> 1
if len(a) > len(u): a, u = a[:k], u + a[k:]
k = min(len(a), len(x))
v, x = x[:k], x[k:]
u += a[k:]
k = len(u) - len(v) >> 1
if k > min(len(x), len(y)): g()
v += x[:k] + y[:k]
c = Counter(u)
print(len(v))
for q in t:
if c[q]: c[q], q = c[q] - 1, v.pop()
print(q)
``` | output | 1 | 16,467 | 19 | 32,935 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct.
Nikolay has m cards, distinct numbers from 1 to m are written on them, one per card. It means that Nikolay has exactly one card with number 1, exactly one card with number 2 and so on.
A single exchange is a process in which Eugeny gives one card to Nikolay and takes another one from those Nikolay has. Your task is to find the minimum number of card exchanges and determine which cards Eugeny should exchange.
Input
The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 109) — the number of cards Eugeny has and the number of cards Nikolay has. It is guaranteed that n is even.
The second line contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers on Eugeny's cards.
Output
If there is no answer, print -1.
Otherwise, in the first line print the minimum number of exchanges. In the second line print n integers — Eugeny's cards after all the exchanges with Nikolay. The order of cards should coincide with the card's order in the input data. If the i-th card wasn't exchanged then the i-th number should coincide with the number from the input data. Otherwise, it is considered that this card was exchanged, and the i-th number should be equal to the number on the card it was exchanged to.
If there are multiple answers, it is allowed to print any of them.
Examples
Input
6 2
5 6 7 9 4 5
Output
1
5 6 7 9 4 2
Input
8 6
7 7 7 7 8 8 8 8
Output
6
7 2 4 6 8 1 3 5
Input
4 1
4 2 1 10
Output
-1 | instruction | 0 | 16,468 | 19 | 32,936 |
Tags: greedy, implementation, math
Correct Solution:
```
def solve(A, n, m):
uniq = set(A)
odd = list(filter(lambda x: x%2, uniq))
even = list(filter(lambda x: x%2 == 0, uniq))
if len(odd) > n//2:
odd.sort()
odd = odd[-n//2:]
if len(even) > n//2:
even.sort()
even = even[-n//2:]
odd_needed = n//2 - len(odd)
changes = n - len(odd) - len(even)
k = 1 if odd_needed else 2
D = {x: True for x in odd + even}
A1 = A[:]
for i, a in enumerate(A):
if a in D and D[a]:
D[a] = False
else:
while k in D:
k += 2
if k > m:
return None
A1[i] = k
k += 2
if odd_needed == 1: k = 2
if odd_needed >= 1: odd_needed -= 1
return A1, changes
n, m = map(int, input().split())
A = [int(x) for x in input().split()]
p = solve(A, n, m)
if p is None:
print(-1)
else:
print(p[1])
print(' '.join(map(str, p[0])))
``` | output | 1 | 16,468 | 19 | 32,937 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct.
Nikolay has m cards, distinct numbers from 1 to m are written on them, one per card. It means that Nikolay has exactly one card with number 1, exactly one card with number 2 and so on.
A single exchange is a process in which Eugeny gives one card to Nikolay and takes another one from those Nikolay has. Your task is to find the minimum number of card exchanges and determine which cards Eugeny should exchange.
Input
The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 109) — the number of cards Eugeny has and the number of cards Nikolay has. It is guaranteed that n is even.
The second line contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers on Eugeny's cards.
Output
If there is no answer, print -1.
Otherwise, in the first line print the minimum number of exchanges. In the second line print n integers — Eugeny's cards after all the exchanges with Nikolay. The order of cards should coincide with the card's order in the input data. If the i-th card wasn't exchanged then the i-th number should coincide with the number from the input data. Otherwise, it is considered that this card was exchanged, and the i-th number should be equal to the number on the card it was exchanged to.
If there are multiple answers, it is allowed to print any of them.
Examples
Input
6 2
5 6 7 9 4 5
Output
1
5 6 7 9 4 2
Input
8 6
7 7 7 7 8 8 8 8
Output
6
7 2 4 6 8 1 3 5
Input
4 1
4 2 1 10
Output
-1 | instruction | 0 | 16,469 | 19 | 32,938 |
Tags: greedy, implementation, math
Correct Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
#sys.setrecursionlimit(300000)
#threading.stack_size(10**8)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------------------------------------------------------------
#mod = 9223372036854775807
class SegmentTree:
def __init__(self, data, default=-10**6, func=lambda a, b: max(a,b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
class SegmentTree1:
def __init__(self, data, default=10**6, func=lambda a, b: min(a,b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
MOD=10**9+7
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod=10**9+7
omod=998244353
#-------------------------------------------------------------------------
prime = [True for i in range(200001)]
pp=[0]*200001
def SieveOfEratosthenes(n=200000):
# Create a boolean array "prime[0..n]" and initialize
# all entries it as true. A value in prime[i] will
# finally be false if i is Not a prime, else true.
p = 2
while (p * p <= n):
# If prime[p] is not changed, then it is a prime
if (prime[p] == True):
# Update all multiples of p
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
#---------------------------------running code------------------------------------------
n,m=map(int,input().split())
a=list(map(int,input().split()))
so=set()
se=set()
s=set()
odd,even=0,0
for i in range (1,min(n,m)+1):
if i%2:
so.add(i)
else:
se.add(i)
for num in a:
if num%2:
odd+=1
if num in so:
so.remove(num)
else:
even+=1
if num in se:
se.remove(num)
ch=1
c=a.copy()
for i in range (n):
if a[i] in s:
if a[i]%2:
if odd>even:
if len(se)==0:
ch=0
break
odd-=1
even+=1
a[i]=se.pop()
s.add(a[i])
else:
if len(so)==0:
ch=0
break
a[i]=so.pop()
s.add(a[i])
else:
if even>odd:
if len(so)==0:
ch=0
break
odd+=1
even-=1
a[i]=so.pop()
s.add(a[i])
else:
if len(se)==0:
ch=0
break
a[i]=se.pop()
s.add(a[i])
else:
s.add(a[i])
if odd>even:
ct=(odd-even)//2
if len(se)<ct:
ch=0
else:
for i in range (n):
if a[i]%2 and ct>0:
ct-=1
a[i]=se.pop()
else:
ct=(even-odd)//2
if len(so)<ct:
ch=0
else:
for i in range (n):
if a[i]%2==0 and ct>0:
ct-=1
a[i]=so.pop()
if ch:
res=0
for i in range (n):
if a[i]!=c[i]:
res+=1
print(res)
print(*a)
else:
print(-1)
``` | output | 1 | 16,469 | 19 | 32,939 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct.
Nikolay has m cards, distinct numbers from 1 to m are written on them, one per card. It means that Nikolay has exactly one card with number 1, exactly one card with number 2 and so on.
A single exchange is a process in which Eugeny gives one card to Nikolay and takes another one from those Nikolay has. Your task is to find the minimum number of card exchanges and determine which cards Eugeny should exchange.
Input
The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 109) — the number of cards Eugeny has and the number of cards Nikolay has. It is guaranteed that n is even.
The second line contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers on Eugeny's cards.
Output
If there is no answer, print -1.
Otherwise, in the first line print the minimum number of exchanges. In the second line print n integers — Eugeny's cards after all the exchanges with Nikolay. The order of cards should coincide with the card's order in the input data. If the i-th card wasn't exchanged then the i-th number should coincide with the number from the input data. Otherwise, it is considered that this card was exchanged, and the i-th number should be equal to the number on the card it was exchanged to.
If there are multiple answers, it is allowed to print any of them.
Examples
Input
6 2
5 6 7 9 4 5
Output
1
5 6 7 9 4 2
Input
8 6
7 7 7 7 8 8 8 8
Output
6
7 2 4 6 8 1 3 5
Input
4 1
4 2 1 10
Output
-1 | instruction | 0 | 16,470 | 19 | 32,940 |
Tags: greedy, implementation, math
Correct Solution:
```
n, m = map(int, input().split())
c = list(map(int, input().split()))
odd_numbs = set()
nodd_numbs = set()
curr_odd = 2
r = 0
curr_nodd = 1
for i in range(len(c)):
if c[i] % 2 == 0:
if len(odd_numbs) >= n//2:
while curr_nodd in nodd_numbs and curr_nodd <= m:
curr_nodd += 2
if curr_nodd > m:
print(-1)
exit()
c[i] = curr_nodd
r += 1
nodd_numbs.add(c[i])
elif c[i] in odd_numbs:
while curr_odd in odd_numbs and curr_odd <= m:
curr_odd += 2
if curr_odd > m:
print(-1)
exit()
c[i] = curr_odd
r += 1
odd_numbs.add(c[i])
else:
odd_numbs.add(c[i])
else:
if len(nodd_numbs) >= n//2:
while curr_odd in odd_numbs and curr_odd <= m:
curr_odd += 2
if curr_odd > m:
print(-1)
exit()
c[i] = curr_odd
r+=1
odd_numbs.add(c[i])
elif c[i] in nodd_numbs:
while curr_nodd in nodd_numbs and curr_nodd <= m:
curr_nodd += 2
if curr_nodd > m:
print(-1)
exit()
c[i] = curr_nodd
r += 1
nodd_numbs.add(c[i])
else:
nodd_numbs.add(c[i])
print(r)
print(*c)
``` | output | 1 | 16,470 | 19 | 32,941 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct.
Nikolay has m cards, distinct numbers from 1 to m are written on them, one per card. It means that Nikolay has exactly one card with number 1, exactly one card with number 2 and so on.
A single exchange is a process in which Eugeny gives one card to Nikolay and takes another one from those Nikolay has. Your task is to find the minimum number of card exchanges and determine which cards Eugeny should exchange.
Input
The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 109) — the number of cards Eugeny has and the number of cards Nikolay has. It is guaranteed that n is even.
The second line contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers on Eugeny's cards.
Output
If there is no answer, print -1.
Otherwise, in the first line print the minimum number of exchanges. In the second line print n integers — Eugeny's cards after all the exchanges with Nikolay. The order of cards should coincide with the card's order in the input data. If the i-th card wasn't exchanged then the i-th number should coincide with the number from the input data. Otherwise, it is considered that this card was exchanged, and the i-th number should be equal to the number on the card it was exchanged to.
If there are multiple answers, it is allowed to print any of them.
Examples
Input
6 2
5 6 7 9 4 5
Output
1
5 6 7 9 4 2
Input
8 6
7 7 7 7 8 8 8 8
Output
6
7 2 4 6 8 1 3 5
Input
4 1
4 2 1 10
Output
-1
Submitted Solution:
```
from collections import defaultdict as dd
first_line = input().split()
eugene_cards = [int(i) for i in input().split()]
nikolay_cards = [i for i in range(1,int(first_line[1])+1)]
odd = even = exchange = 0
eugene_dict = dd(int)
new_dict = dd(int)
for i in eugene_cards:
eugene_dict[i] += 1
new_dict[i] += 1
if i % 2:
odd+=1
else:
even+=1
replaced_set = []
for i in eugene_dict:
replaced_list = []
while eugene_dict[i] > 1:
if (i % 2==1) and (odd > even):
for u in range(len(nikolay_cards)):
if (u%2==1) and nikolay_cards[u] not in eugene_dict:
replaced_list.append(nikolay_cards[u])
nikolay_cards.remove(nikolay_cards[u])
eugene_dict[i] -= 1
odd-=1
even+=1
exchange+=1
break;
elif (i%2) and (odd <= even):
for u in range(len(nikolay_cards)):
if u%2== 0 and nikolay_cards[u] not in eugene_dict:
replaced_list.append(nikolay_cards[u])
nikolay_cards.remove(nikolay_cards[u])
eugene_dict[i] -= 1
exchange+=1
break
elif (i % 2==0) and (odd >= even):
for u in range(len(nikolay_cards)):
if (u%2==1) and nikolay_cards[u] not in eugene_dict:
replaced_list.append(nikolay_cards[u])
nikolay_cards.remove(nikolay_cards[u])
eugene_dict[i] -= 1
exchange+=1
break;
elif (i % 2==0) and (odd < even):
for u in range(len(nikolay_cards)):
if (u%2==0) and nikolay_cards[u] not in eugene_dict:
replaced_list.append(nikolay_cards[u])
nikolay_cards.remove(nikolay_cards[u])
eugene_dict[i] -= 1
odd-=1
even+=1
exchange+=1
break;
if replaced_list:
replaced_set.append([i,replaced_list])
for i in replaced_set:
if (len(i[1])):
print(i[1][0])
for u in range(len(eugene_cards)+1):
while(len(i[1])):
if eugene_cards[u] == i[0]:
eugene_cards[u] = i[1][0]
i[1].remove(eugene_cards[u])
print(exchange)
print(eugene_cards)
``` | instruction | 0 | 16,471 | 19 | 32,942 |
No | output | 1 | 16,471 | 19 | 32,943 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct.
Nikolay has m cards, distinct numbers from 1 to m are written on them, one per card. It means that Nikolay has exactly one card with number 1, exactly one card with number 2 and so on.
A single exchange is a process in which Eugeny gives one card to Nikolay and takes another one from those Nikolay has. Your task is to find the minimum number of card exchanges and determine which cards Eugeny should exchange.
Input
The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 109) — the number of cards Eugeny has and the number of cards Nikolay has. It is guaranteed that n is even.
The second line contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers on Eugeny's cards.
Output
If there is no answer, print -1.
Otherwise, in the first line print the minimum number of exchanges. In the second line print n integers — Eugeny's cards after all the exchanges with Nikolay. The order of cards should coincide with the card's order in the input data. If the i-th card wasn't exchanged then the i-th number should coincide with the number from the input data. Otherwise, it is considered that this card was exchanged, and the i-th number should be equal to the number on the card it was exchanged to.
If there are multiple answers, it is allowed to print any of them.
Examples
Input
6 2
5 6 7 9 4 5
Output
1
5 6 7 9 4 2
Input
8 6
7 7 7 7 8 8 8 8
Output
6
7 2 4 6 8 1 3 5
Input
4 1
4 2 1 10
Output
-1
Submitted Solution:
```
from collections import *
f = lambda: map(int, input().split())
g = lambda: exit(print(-1))
n, m = f()
if n & 1: g()
t = list(f())
a = [set(), set()]
b = [[], []]
u = []
for q in t:
if q in a[q & 1]: u.append(q)
a[q & 1].add(q)
for q in range(1, m + 1):
if q not in a[q & 1]: b[q & 1].append(q)
d = len(a[0]) < len(a[1])
a = list(a[d])[:-len(a[1 - d])]
x, y = b[d], b[1 - d]
k = min(len(a), len(u), len(x))
v, x = x[:k], x[k:]
u += a[k:]
k = len(u) - len(v) >> 1
if k > min(len(x), len(y)): g()
v += x[:k] + y[:k]
u = Counter(u)
print(len(v))
for q in t:
if u[q]:
u[q] -= 1
q = v.pop()
print(q)
``` | instruction | 0 | 16,472 | 19 | 32,944 |
No | output | 1 | 16,472 | 19 | 32,945 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct.
Nikolay has m cards, distinct numbers from 1 to m are written on them, one per card. It means that Nikolay has exactly one card with number 1, exactly one card with number 2 and so on.
A single exchange is a process in which Eugeny gives one card to Nikolay and takes another one from those Nikolay has. Your task is to find the minimum number of card exchanges and determine which cards Eugeny should exchange.
Input
The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 109) — the number of cards Eugeny has and the number of cards Nikolay has. It is guaranteed that n is even.
The second line contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers on Eugeny's cards.
Output
If there is no answer, print -1.
Otherwise, in the first line print the minimum number of exchanges. In the second line print n integers — Eugeny's cards after all the exchanges with Nikolay. The order of cards should coincide with the card's order in the input data. If the i-th card wasn't exchanged then the i-th number should coincide with the number from the input data. Otherwise, it is considered that this card was exchanged, and the i-th number should be equal to the number on the card it was exchanged to.
If there are multiple answers, it is allowed to print any of them.
Examples
Input
6 2
5 6 7 9 4 5
Output
1
5 6 7 9 4 2
Input
8 6
7 7 7 7 8 8 8 8
Output
6
7 2 4 6 8 1 3 5
Input
4 1
4 2 1 10
Output
-1
Submitted Solution:
```
n,m=map(int,input().split())
a=list(map(int,input().split()))
ans=0
d=dict()
for i in range(n):
if a[i] in d:
d[a[i]].append(i)
else:
d[a[i]]=[i]
#偶数,奇数がいくつずつか
x,y=sum(i%2 for i in a),sum(1-i%2 for i in a)
#偶数,奇数で変えるべきところ
#だめなやつ
num0,num1=[],[]
s0,s1=set(),set()
for i in d:
if i%2==0:
if len(d[i])>1:
num0+=d[i][:-1]
s0.add(i)
else:
if len(d[i])>1:
num1+=d[i][:-1]
s1.add(i)
#変えるべきところの個数
f,g=len(num0),len(num1)
#f,gの変え方を決める
#f,gを全部使う場合
#偶数へと変える場合
if y+f<n//2:
#print(1)
ans=f+g
now=2
l=f+g
ch=num0+num1
for i in range(l):
while now in s0:
now+=2
a[ch[i]]=now
if a[ch[i]]>m:
print(-1)
exit()
now+=2
#まだ足りないからもっと偶数に変える
#今の時点での奇数のインデックス
ind=[i for i in range(n) if a[i]%2==1]
ans+=(len(ind)-n//2)
for i in range(len(ind)-n//2):
while now in s0:
now+=2
a[ind[i]]=now
if a[ind[i]]>m:
print(-1)
exit()
now+=2
print(ans)
print(" ".join(map(str,a)))
#奇数へと変える場合
elif x+g<n//2:
#print(2)
ans=f+g
now=1
l=f+g
ch=num0+num1
for i in range(l):
while now in s1:
now+=2
a[ch[i]]=now
if a[ch[i]]>m:
print(-1)
exit()
now+=2
#まだ足りないからもっと奇数に変える
#今の時点での奇数のインデックス
ind=[i for i in range(n) if a[i]%2==0]
ans+=(len(ind)-n//2)
for i in range(len(ind)-n//2):
while now in s1:
now+=2
a[ind[i]]=now
if a[ind[i]]>m:
print(-1)
exit()
now+=2
print(ans)
print(" ".join(map(str,a)))
#全部使う必要がない場合
else:
now0,now1=2,1
l=f+g
ch=num0+num1
if x-f<=n//2:
v=n//2-(x-f)
x0,x1=ch[:v],ch[v:]
else:
v=n//2-(y-g)
x1,x0=ch[:v],ch[v:]
for i in x0:
while now0 in s0:
now0+=2
a[i]=now0
if a[i]>m:
print(-1)
exit()
now0+=2
for i in x1:
while now1 in s1:
now1+=2
a[i]=now1
if a[i]>m:
print(-1)
exit()
now1+=2
print(f+g)
print(" ".join(map(str,a)))
``` | instruction | 0 | 16,473 | 19 | 32,946 |
No | output | 1 | 16,473 | 19 | 32,947 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct.
Nikolay has m cards, distinct numbers from 1 to m are written on them, one per card. It means that Nikolay has exactly one card with number 1, exactly one card with number 2 and so on.
A single exchange is a process in which Eugeny gives one card to Nikolay and takes another one from those Nikolay has. Your task is to find the minimum number of card exchanges and determine which cards Eugeny should exchange.
Input
The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 109) — the number of cards Eugeny has and the number of cards Nikolay has. It is guaranteed that n is even.
The second line contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers on Eugeny's cards.
Output
If there is no answer, print -1.
Otherwise, in the first line print the minimum number of exchanges. In the second line print n integers — Eugeny's cards after all the exchanges with Nikolay. The order of cards should coincide with the card's order in the input data. If the i-th card wasn't exchanged then the i-th number should coincide with the number from the input data. Otherwise, it is considered that this card was exchanged, and the i-th number should be equal to the number on the card it was exchanged to.
If there are multiple answers, it is allowed to print any of them.
Examples
Input
6 2
5 6 7 9 4 5
Output
1
5 6 7 9 4 2
Input
8 6
7 7 7 7 8 8 8 8
Output
6
7 2 4 6 8 1 3 5
Input
4 1
4 2 1 10
Output
-1
Submitted Solution:
```
#!/usr/bin/env python3
class CantException(Exception):
pass
def odd_v(value):
return 1 if value % 2 == 1 else -1
change_idx = 1
acceptable = {-1: set(), 1: set()}
def change(card_values, oddv, m):
global change_idx
if acceptable[oddv]:
res = acceptable[oddv].pop()
card_values.add(res)
return res
change_idx_start = change_idx
# print(change_idx_start)
while change_idx in card_values or odd_v(change_idx) != oddv:
if change_idx not in card_values:
acceptable[odd_v(change_idx)].add(change_idx)
#print(change_idx)
change_idx += 1
if change_idx > m:
change_idx = 1
if change_idx == change_idx_start:
raise CantException()
change_idx += 1
card_values.add(change_idx - 1)
res = change_idx - 1
if change_idx > m:
change_idx = 1
return res
def solve():
n, m = map(int, input().split())
cards = list(map(int, input().split()))
odd_balance = 0
card_values = set()
indices_to_be_changed = set()
for i, c in enumerate(cards):
odd_balance += odd_v(c)
if c in card_values:
indices_to_be_changed.add(i)
card_values.add(c)
# print("indices to be changed: ", indices_to_be_changed)
change_count = len(indices_to_be_changed)
for i in indices_to_be_changed:
if odd_balance == 0:
cards[i] = change(card_values, odd_v(cards[i]), m)
else:
if odd_v(cards[i]) * odd_balance > 0:
odd_balance -= 2 * odd_v(cards[i])
cards[i] = change(card_values, - odd_v(cards[i]), m)
# print("current odd balance:", odd_balance)
for i in range(len(cards)):
if odd_balance == 0:
break
if odd_v(cards[i]) * odd_balance > 0:
# print("gonna change")
change_count += 1
odd_balance -= 2 * odd_v(cards[i])
cards[i] = change(card_values, -odd_v(cards[i]), m)
return change_count, cards
if __name__ == '__main__':
try:
change_cnt, cards = solve()
print(change_cnt)
print(" ".join(map(str, cards)))
except CantException:
print("-1")
``` | instruction | 0 | 16,474 | 19 | 32,948 |
No | output | 1 | 16,474 | 19 | 32,949 |
Provide a correct Python 3 solution for this coding contest problem.
There are 2^N players, numbered 1, 2, ..., 2^N. They decided to hold a tournament.
The tournament proceeds as follows:
* Choose a permutation of 1, 2, ..., 2^N: p_1, p_2, ..., p_{2^N}.
* The players stand in a row in the order of Player p_1, Player p_2, ..., Player p_{2^N}.
* Repeat the following until there is only one player remaining in the row:
* Play the following matches: the first player in the row versus the second player in the row, the third player versus the fourth player, and so on. The players who lose leave the row. The players who win stand in a row again, preserving the relative order of the players.
* The last player who remains in the row is the champion.
It is known that, the result of the match between two players can be written as follows, using M integers A_1, A_2, ..., A_M given as input:
* When y = A_i for some i, the winner of the match between Player 1 and Player y (2 \leq y \leq 2^N) will be Player y.
* When y \neq A_i for every i, the winner of the match between Player 1 and Player y (2 \leq y \leq 2^N) will be Player 1.
* When 2 \leq x < y \leq 2^N, the winner of the match between Player x and Player y will be Player x.
The champion of this tournament depends only on the permutation p_1, p_2, ..., p_{2^N} chosen at the beginning. Find the number of permutation p_1, p_2, ..., p_{2^N} chosen at the beginning of the tournament that would result in Player 1 becoming the champion, modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 16
* 0 \leq M \leq 16
* 2 \leq A_i \leq 2^N (1 \leq i \leq M)
* A_i < A_{i + 1} (1 \leq i < M)
Input
Input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
Print the answer.
Examples
Input
2 1
3
Output
8
Input
4 3
2 4 6
Output
0
Input
3 0
Output
40320
Input
3 3
3 4 7
Output
2688
Input
16 16
5489 5490 5491 5492 5493 5494 5495 5497 18993 18995 18997 18999 19000 19001 19002 19003
Output
816646464 | instruction | 0 | 16,658 | 19 | 33,316 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
def main():
def com(com_n, com_r):
return fac[com_n] * inv[com_r] * inv[com_n - com_r] % md
md = 10 ** 9 + 7
n, m = map(int, input().split())
aa = list(map(lambda x: int(x) - 1, input().split()))
n2 = 2 ** n
# combinationの準備
n_max = n2
fac = [1]
inv = [1] * (n_max + 1)
k_fac_inv = 1
for i in range(1, n_max + 1):
k_fac_inv = k_fac_inv * i % md
fac.append(k_fac_inv)
k_fac_inv = pow(k_fac_inv, md - 2, md)
for i in range(n_max, 1, -1):
inv[i] = k_fac_inv
k_fac_inv = k_fac_inv * i % md
dp = [[0] * n2 for _ in range(m + 1)]
dp[0][0] = 1
for i in range(m):
a = aa[m - 1 - i]
for b in range(n2):
pre = dp[i][b]
if pre == 0: continue
dp[i + 1][b] = (dp[i + 1][b] + pre) % md
k = 1
for _ in range(n):
if b & k == 0 and n2 - a - b >= k:
nb = b | k
dp[i + 1][nb] = (dp[i + 1][nb] + pre * com(n2 - 1 - a - b, k - 1)) % md
k <<= 1
for b in range(n2):
k = 1
p = n2 - 1 - b
for _ in range(n):
if b & k == 0:
dp[m][b] = dp[m][b] * com(p, k) % md
p -= k
k <<= 1
ans = 0
for b in range(n2):
coff = -1 if bin(b).count("1") % 2 else 1
ans = ans + coff * dp[m][b]
k = 1
for _ in range(n - 1):
k <<= 1
ans = ans * fac[k] % md
ans = ans * n2 % md
print(ans)
main()
``` | output | 1 | 16,658 | 19 | 33,317 |
Provide a correct Python 3 solution for this coding contest problem.
There are 2^N players, numbered 1, 2, ..., 2^N. They decided to hold a tournament.
The tournament proceeds as follows:
* Choose a permutation of 1, 2, ..., 2^N: p_1, p_2, ..., p_{2^N}.
* The players stand in a row in the order of Player p_1, Player p_2, ..., Player p_{2^N}.
* Repeat the following until there is only one player remaining in the row:
* Play the following matches: the first player in the row versus the second player in the row, the third player versus the fourth player, and so on. The players who lose leave the row. The players who win stand in a row again, preserving the relative order of the players.
* The last player who remains in the row is the champion.
It is known that, the result of the match between two players can be written as follows, using M integers A_1, A_2, ..., A_M given as input:
* When y = A_i for some i, the winner of the match between Player 1 and Player y (2 \leq y \leq 2^N) will be Player y.
* When y \neq A_i for every i, the winner of the match between Player 1 and Player y (2 \leq y \leq 2^N) will be Player 1.
* When 2 \leq x < y \leq 2^N, the winner of the match between Player x and Player y will be Player x.
The champion of this tournament depends only on the permutation p_1, p_2, ..., p_{2^N} chosen at the beginning. Find the number of permutation p_1, p_2, ..., p_{2^N} chosen at the beginning of the tournament that would result in Player 1 becoming the champion, modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 16
* 0 \leq M \leq 16
* 2 \leq A_i \leq 2^N (1 \leq i \leq M)
* A_i < A_{i + 1} (1 \leq i < M)
Input
Input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
Print the answer.
Examples
Input
2 1
3
Output
8
Input
4 3
2 4 6
Output
0
Input
3 0
Output
40320
Input
3 3
3 4 7
Output
2688
Input
16 16
5489 5490 5491 5492 5493 5494 5495 5497 18993 18995 18997 18999 19000 19001 19002 19003
Output
816646464 | instruction | 0 | 16,659 | 19 | 33,318 |
"Correct Solution:
```
def cmb(n, r, mod):#コンビネーションの高速計算
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**5
g1 = [1]*(N+1) # 元テーブル
g2 = [1]*(N+1) #逆元テーブル
inverse = [1]*(N+1) #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1[i]=( ( g1[i-1] * i ) % mod )
inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
g2[i]=( (g2[i-1] * inverse[i]) % mod )
inverse[0]=0
N,M=map(int,input().split())
A=[0]+list(map(int,input().split()))
dp=[[0 for i in range(2**N)] for j in range(M+1)]
dp[0][0]=g1[2**N-1]
for i in range(1,M+1):
for j in range(2**N):
dp[i][j]=dp[i-1][j]
for k in range(N):
if j>>k &1==0 and 2**N-A[i]-j>=2**k-1:
dp[i][j]=(dp[i][j]+((-1)*((g1[2**N-A[i]-j]*g2[2**N-A[i]+1-(j+2**k)])%mod)*((dp[i-1][j+2**k]+g1[2**N-1-j-2**k])*2**k)%mod)%mod)%mod
#for i in range(M+1):
#print(dp[i])
print((dp[M][0]*pow(2,N,mod))%mod)
``` | output | 1 | 16,659 | 19 | 33,319 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are 2^N players, numbered 1, 2, ..., 2^N. They decided to hold a tournament.
The tournament proceeds as follows:
* Choose a permutation of 1, 2, ..., 2^N: p_1, p_2, ..., p_{2^N}.
* The players stand in a row in the order of Player p_1, Player p_2, ..., Player p_{2^N}.
* Repeat the following until there is only one player remaining in the row:
* Play the following matches: the first player in the row versus the second player in the row, the third player versus the fourth player, and so on. The players who lose leave the row. The players who win stand in a row again, preserving the relative order of the players.
* The last player who remains in the row is the champion.
It is known that, the result of the match between two players can be written as follows, using M integers A_1, A_2, ..., A_M given as input:
* When y = A_i for some i, the winner of the match between Player 1 and Player y (2 \leq y \leq 2^N) will be Player y.
* When y \neq A_i for every i, the winner of the match between Player 1 and Player y (2 \leq y \leq 2^N) will be Player 1.
* When 2 \leq x < y \leq 2^N, the winner of the match between Player x and Player y will be Player x.
The champion of this tournament depends only on the permutation p_1, p_2, ..., p_{2^N} chosen at the beginning. Find the number of permutation p_1, p_2, ..., p_{2^N} chosen at the beginning of the tournament that would result in Player 1 becoming the champion, modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 16
* 0 \leq M \leq 16
* 2 \leq A_i \leq 2^N (1 \leq i \leq M)
* A_i < A_{i + 1} (1 \leq i < M)
Input
Input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
Print the answer.
Examples
Input
2 1
3
Output
8
Input
4 3
2 4 6
Output
0
Input
3 0
Output
40320
Input
3 3
3 4 7
Output
2688
Input
16 16
5489 5490 5491 5492 5493 5494 5495 5497 18993 18995 18997 18999 19000 19001 19002 19003
Output
816646464
Submitted Solution:
```
def cmb(n, r, mod):#コンビネーションの高速計算
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**5
g1 = [1]*(N+1) # 元テーブル
g2 = [1]*(N+1) #逆元テーブル
inverse = [1]*(N+1) #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1[i]=( ( g1[i-1] * i ) % mod )
inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
g2[i]=( (g2[i-1] * inverse[i]) % mod )
inverse[0]=0
N,M=map(int,input().split())
A=[0]+list(map(int,input().split()))
start=time.time()
dp=[[0 for i in range(2**N)] for j in range(M+1)]
dp[0][0]=g1[2**N-1]
for i in range(1,M+1):
for j in range(2**N):
dp[i][j]=dp[i-1][j]
for k in range(N):
if j>>k &1==0 and 2**N-A[i]-j>=2**k-1:
dp[i][j]=(dp[i][j]+((-1)*((g1[2**N-A[i]-j]*g2[2**N-A[i]+1-(j+2**k)])%mod)*((dp[i-1][j+2**k]+g1[2**N-1-j-2**k])*2**k)%mod)%mod)%mod
#for i in range(M+1):
#print(dp[i])
print((dp[M][0]*pow(2,N,mod))%mod)
``` | instruction | 0 | 16,660 | 19 | 33,320 |
No | output | 1 | 16,660 | 19 | 33,321 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are 2^N players, numbered 1, 2, ..., 2^N. They decided to hold a tournament.
The tournament proceeds as follows:
* Choose a permutation of 1, 2, ..., 2^N: p_1, p_2, ..., p_{2^N}.
* The players stand in a row in the order of Player p_1, Player p_2, ..., Player p_{2^N}.
* Repeat the following until there is only one player remaining in the row:
* Play the following matches: the first player in the row versus the second player in the row, the third player versus the fourth player, and so on. The players who lose leave the row. The players who win stand in a row again, preserving the relative order of the players.
* The last player who remains in the row is the champion.
It is known that, the result of the match between two players can be written as follows, using M integers A_1, A_2, ..., A_M given as input:
* When y = A_i for some i, the winner of the match between Player 1 and Player y (2 \leq y \leq 2^N) will be Player y.
* When y \neq A_i for every i, the winner of the match between Player 1 and Player y (2 \leq y \leq 2^N) will be Player 1.
* When 2 \leq x < y \leq 2^N, the winner of the match between Player x and Player y will be Player x.
The champion of this tournament depends only on the permutation p_1, p_2, ..., p_{2^N} chosen at the beginning. Find the number of permutation p_1, p_2, ..., p_{2^N} chosen at the beginning of the tournament that would result in Player 1 becoming the champion, modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 16
* 0 \leq M \leq 16
* 2 \leq A_i \leq 2^N (1 \leq i \leq M)
* A_i < A_{i + 1} (1 \leq i < M)
Input
Input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
Print the answer.
Examples
Input
2 1
3
Output
8
Input
4 3
2 4 6
Output
0
Input
3 0
Output
40320
Input
3 3
3 4 7
Output
2688
Input
16 16
5489 5490 5491 5492 5493 5494 5495 5497 18993 18995 18997 18999 19000 19001 19002 19003
Output
816646464
Submitted Solution:
```
import sys
input = sys.stdin.readline
def main():
def com(com_n, com_r):
return fac[com_n] * inv[com_r] * inv[com_n - com_r] % md
md = 10 ** 9 + 7
n, m = map(int, input().split())
aa = list(map(lambda x: int(x) - 1, input().split()))
if aa[0] == 1:
print(0)
exit()
n2 = 2 ** n
# combinationの準備
n_max = n2
fac = [1]
inv = [1] * (n_max + 1)
k_fac_inv = 1
for i in range(1, n_max + 1):
k_fac_inv = k_fac_inv * i % md
fac.append(k_fac_inv)
k_fac_inv = pow(k_fac_inv, md - 2, md)
for i in range(n_max, 1, -1):
inv[i] = k_fac_inv
k_fac_inv = k_fac_inv * i % md
dp = [[0] * n2 for _ in range(m + 1)]
dp[0][0] = 1
for i in range(m):
a = aa[m - 1 - i]
for b in range(n2):
pre = dp[i][b]
if pre == 0: continue
dp[i + 1][b] = (dp[i + 1][b] + pre) % md
k = 1
for _ in range(n):
if b & k == 0 and n2 - a - b >= k:
nb = b | k
dp[i + 1][nb] = (dp[i + 1][nb] + pre * com(n2 - 1 - a - b, k - 1)) % md
k <<= 1
for b in range(n2):
k = 1
p = n2 - 1 - b
for _ in range(n):
if b & k == 0:
dp[m][b] = dp[m][b] * com(p, k) % md
p -= k
k <<= 1
ans = 0
for b in range(n2):
coff = -1 if bin(b).count("1") % 2 else 1
ans = ans + coff * dp[m][b]
k = 1
for _ in range(n - 1):
k <<= 1
ans = ans * fac[k] % md
ans = ans * n2 % md
print(ans)
main()
``` | instruction | 0 | 16,661 | 19 | 33,322 |
No | output | 1 | 16,661 | 19 | 33,323 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are 2^N players, numbered 1, 2, ..., 2^N. They decided to hold a tournament.
The tournament proceeds as follows:
* Choose a permutation of 1, 2, ..., 2^N: p_1, p_2, ..., p_{2^N}.
* The players stand in a row in the order of Player p_1, Player p_2, ..., Player p_{2^N}.
* Repeat the following until there is only one player remaining in the row:
* Play the following matches: the first player in the row versus the second player in the row, the third player versus the fourth player, and so on. The players who lose leave the row. The players who win stand in a row again, preserving the relative order of the players.
* The last player who remains in the row is the champion.
It is known that, the result of the match between two players can be written as follows, using M integers A_1, A_2, ..., A_M given as input:
* When y = A_i for some i, the winner of the match between Player 1 and Player y (2 \leq y \leq 2^N) will be Player y.
* When y \neq A_i for every i, the winner of the match between Player 1 and Player y (2 \leq y \leq 2^N) will be Player 1.
* When 2 \leq x < y \leq 2^N, the winner of the match between Player x and Player y will be Player x.
The champion of this tournament depends only on the permutation p_1, p_2, ..., p_{2^N} chosen at the beginning. Find the number of permutation p_1, p_2, ..., p_{2^N} chosen at the beginning of the tournament that would result in Player 1 becoming the champion, modulo 10^9 + 7.
Constraints
* 1 \leq N \leq 16
* 0 \leq M \leq 16
* 2 \leq A_i \leq 2^N (1 \leq i \leq M)
* A_i < A_{i + 1} (1 \leq i < M)
Input
Input is given from Standard Input in the following format:
N M
A_1 A_2 ... A_M
Output
Print the answer.
Examples
Input
2 1
3
Output
8
Input
4 3
2 4 6
Output
0
Input
3 0
Output
40320
Input
3 3
3 4 7
Output
2688
Input
16 16
5489 5490 5491 5492 5493 5494 5495 5497 18993 18995 18997 18999 19000 19001 19002 19003
Output
816646464
Submitted Solution:
```
import itertools
def battle(x, y, As):
winner = x
if x == 1:
if y in As:
winner = y
return winner
def main():
data = list(map(int,input().split()))
N = data[0]
M = data[1]
As = list(map(int,input().split()))
winner_is_1 = 0
combi_list = itertools.permutations(list(range(1, 2**N+1)))
for combi in combi_list:
combi_cur = combi
while len(combi_cur) >1 :
#print(combi_cur)
combi_next = []
for i in range(int(len(combi_cur)/2)):
if combi_cur[2*i] > combi_cur[2*i+1]:
y = combi_cur[2*i]
x = combi_cur[2*i+1]
else:
x = combi_cur[2*i]
y = combi_cur[2*i+1]
winner = battle(x, y, As)
combi_next.append(winner)
combi_cur = combi_next
if combi_cur[0] == 1:
winner_is_1 += 1
print(winner_is_1 % (10**9+7))
if __name__ == "__main__":
main()
``` | instruction | 0 | 16,662 | 19 | 33,324 |
No | output | 1 | 16,662 | 19 | 33,325 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There are the following two-player card games.
* This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100.
* Deal n cards to each of the two.
* Put cards into play alternately one by one according to the following rules.
* If there are no cards in play, you can play any card you like.
* If there are cards in play, you can play a larger number of written cards than the last card in play.
* If you can play a card, you must put it into play.
* If there is no card that can be issued, it will be a pass and it will be the opponent's turn. At this time, there are no cards in play.
* The game starts with no cards in play.
* The game ends when either card is exhausted.
* The number of cards the opponent has at the end of the game will be scored.
Taro and Hanako will play in this game. The game starts with Taro's turn. Both of them always issue the card with the smallest number of cards that can be issued.
Create a program that outputs the scores of Taro and Hanako when the cards dealt to Taro are input.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input is n + 1 lines. The integer n is written on the first line. Each line from the 2nd line to the n + 1th line has one integer written on it, which represents the integer written on the card dealt to Taro.
When n is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, print Taro's score on the first line and Hanako's score on the second line.
Examples
Input
5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0
Output
3
0
2
0
Input
None
Output
None | instruction | 0 | 16,744 | 19 | 33,488 |
"Correct Solution:
```
import bisect
for e in iter(input,'0'):
n=int(e)
c=[sorted(int(input())for _ in[0]*n)]
c+=[sorted(set(range(1,2*n+1))-set(c[0]))]
t=f=0
while 1:
x=bisect.bisect(c[t],f)
if not c[t]:break
f=c[t].pop(x)if x<len(c[t])else 0
t^=1
for i in'10':print(len(c[int(i)]))
``` | output | 1 | 16,744 | 19 | 33,489 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There are the following two-player card games.
* This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100.
* Deal n cards to each of the two.
* Put cards into play alternately one by one according to the following rules.
* If there are no cards in play, you can play any card you like.
* If there are cards in play, you can play a larger number of written cards than the last card in play.
* If you can play a card, you must put it into play.
* If there is no card that can be issued, it will be a pass and it will be the opponent's turn. At this time, there are no cards in play.
* The game starts with no cards in play.
* The game ends when either card is exhausted.
* The number of cards the opponent has at the end of the game will be scored.
Taro and Hanako will play in this game. The game starts with Taro's turn. Both of them always issue the card with the smallest number of cards that can be issued.
Create a program that outputs the scores of Taro and Hanako when the cards dealt to Taro are input.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input is n + 1 lines. The integer n is written on the first line. Each line from the 2nd line to the n + 1th line has one integer written on it, which represents the integer written on the card dealt to Taro.
When n is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, print Taro's score on the first line and Hanako's score on the second line.
Examples
Input
5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0
Output
3
0
2
0
Input
None
Output
None | instruction | 0 | 16,745 | 19 | 33,490 |
"Correct Solution:
```
def discard(c, cards):
for card in cards:
if c < card:
return card
return 0
while True:
n = int(input())
if n == 0:
break
taro = [int(input()) for _ in range(n)]
hanako = [x + 1 for x in range(2*n) if (x + 1) not in taro]
taro.sort()
hanako.sort()
table = 0
while True:
if taro:
table = discard(table, taro)
if table:
taro.remove(table)
if not taro:
print(len(hanako))
print(0)
break
if hanako:
table = discard(table, hanako)
if table:
hanako.remove(table)
if not hanako:
print(0)
print(len(taro))
break
``` | output | 1 | 16,745 | 19 | 33,491 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There are the following two-player card games.
* This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100.
* Deal n cards to each of the two.
* Put cards into play alternately one by one according to the following rules.
* If there are no cards in play, you can play any card you like.
* If there are cards in play, you can play a larger number of written cards than the last card in play.
* If you can play a card, you must put it into play.
* If there is no card that can be issued, it will be a pass and it will be the opponent's turn. At this time, there are no cards in play.
* The game starts with no cards in play.
* The game ends when either card is exhausted.
* The number of cards the opponent has at the end of the game will be scored.
Taro and Hanako will play in this game. The game starts with Taro's turn. Both of them always issue the card with the smallest number of cards that can be issued.
Create a program that outputs the scores of Taro and Hanako when the cards dealt to Taro are input.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input is n + 1 lines. The integer n is written on the first line. Each line from the 2nd line to the n + 1th line has one integer written on it, which represents the integer written on the card dealt to Taro.
When n is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, print Taro's score on the first line and Hanako's score on the second line.
Examples
Input
5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0
Output
3
0
2
0
Input
None
Output
None | instruction | 0 | 16,746 | 19 | 33,492 |
"Correct Solution:
```
import bisect
while True:
n = int(input())
if not n:
break
cards = [None, None]
cards[0] = sorted(map(int, (input() for _ in range(n))))
cards[1] = sorted(set(range(1, 2 * n + 1)).difference(cards[0]))
turn = 0
field = 0
while True:
idx = bisect.bisect(cards[turn], field)
if idx < len(cards[turn]):
field = cards[turn].pop(idx)
if not cards[turn]:
break
else:
field = 0
turn = (turn + 1) & 1
print(len(cards[1]))
print(len(cards[0]))
``` | output | 1 | 16,746 | 19 | 33,493 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There are the following two-player card games.
* This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100.
* Deal n cards to each of the two.
* Put cards into play alternately one by one according to the following rules.
* If there are no cards in play, you can play any card you like.
* If there are cards in play, you can play a larger number of written cards than the last card in play.
* If you can play a card, you must put it into play.
* If there is no card that can be issued, it will be a pass and it will be the opponent's turn. At this time, there are no cards in play.
* The game starts with no cards in play.
* The game ends when either card is exhausted.
* The number of cards the opponent has at the end of the game will be scored.
Taro and Hanako will play in this game. The game starts with Taro's turn. Both of them always issue the card with the smallest number of cards that can be issued.
Create a program that outputs the scores of Taro and Hanako when the cards dealt to Taro are input.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input is n + 1 lines. The integer n is written on the first line. Each line from the 2nd line to the n + 1th line has one integer written on it, which represents the integer written on the card dealt to Taro.
When n is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, print Taro's score on the first line and Hanako's score on the second line.
Examples
Input
5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0
Output
3
0
2
0
Input
None
Output
None | instruction | 0 | 16,747 | 19 | 33,494 |
"Correct Solution:
```
def hand(card, board):
for i, c in enumerate(card):
if board < c:
board = card.pop(i)
return board
else:
return board
while 1:
n = int(input())
if n == 0:
break
taro = []
for _ in range(n):
taro.append(int(input()))
taro.sort()
hanako = []
for i in range(1, 2*n+1):
if i not in taro:
hanako.append(i)
hanako.sort()
board = 0
order = 0
while 1:
if order == 0:
card = hand(taro, board)
if taro == [] or hanako == []:
break
if board == card:
board = 0
order = 1
continue
board = card
card = hand(hanako, board)
if taro == [] or hanako == []:
break
if board == card:
board = 0
continue
board = card
else:
card = hand(hanako, board)
if taro == [] or hanako == []:
break
if board == card:
board = 0
order = 0
continue
board = card
card = hand(taro, board)
if taro == [] or hanako == []:
break
if board == card:
board = 0
continue
board = card
print(len(hanako))
print(len(taro))
``` | output | 1 | 16,747 | 19 | 33,495 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There are the following two-player card games.
* This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100.
* Deal n cards to each of the two.
* Put cards into play alternately one by one according to the following rules.
* If there are no cards in play, you can play any card you like.
* If there are cards in play, you can play a larger number of written cards than the last card in play.
* If you can play a card, you must put it into play.
* If there is no card that can be issued, it will be a pass and it will be the opponent's turn. At this time, there are no cards in play.
* The game starts with no cards in play.
* The game ends when either card is exhausted.
* The number of cards the opponent has at the end of the game will be scored.
Taro and Hanako will play in this game. The game starts with Taro's turn. Both of them always issue the card with the smallest number of cards that can be issued.
Create a program that outputs the scores of Taro and Hanako when the cards dealt to Taro are input.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input is n + 1 lines. The integer n is written on the first line. Each line from the 2nd line to the n + 1th line has one integer written on it, which represents the integer written on the card dealt to Taro.
When n is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, print Taro's score on the first line and Hanako's score on the second line.
Examples
Input
5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0
Output
3
0
2
0
Input
None
Output
None | instruction | 0 | 16,748 | 19 | 33,496 |
"Correct Solution:
```
import bisect
while True:
n = int(input())
if n == 0:
break
tc = sorted([int(input()) for _ in range(n)])
hc = sorted([v for v in range(1, 2*n+1) if v not in tc])
ba = []
flag = True
while tc and hc:
if len(ba) == 0:
try:
if flag:
tmp = tc.pop(0)
flag = False
else:
tmp = hc.pop(0)
flag = True
except IndexError:
pass
ba = [tmp]
continue
last_card = ba[-1]
if flag:
x = bisect.bisect_left(tc, last_card)
flag = False
try:
tmp = tc.pop(x)
except IndexError:
ba = []
continue
else:
x = bisect.bisect_left(hc, last_card)
flag = True
try:
tmp = hc.pop(x)
except IndexError:
ba = []
continue
ba.append(tmp)
print(len(hc))
print(len(tc))
``` | output | 1 | 16,748 | 19 | 33,497 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There are the following two-player card games.
* This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100.
* Deal n cards to each of the two.
* Put cards into play alternately one by one according to the following rules.
* If there are no cards in play, you can play any card you like.
* If there are cards in play, you can play a larger number of written cards than the last card in play.
* If you can play a card, you must put it into play.
* If there is no card that can be issued, it will be a pass and it will be the opponent's turn. At this time, there are no cards in play.
* The game starts with no cards in play.
* The game ends when either card is exhausted.
* The number of cards the opponent has at the end of the game will be scored.
Taro and Hanako will play in this game. The game starts with Taro's turn. Both of them always issue the card with the smallest number of cards that can be issued.
Create a program that outputs the scores of Taro and Hanako when the cards dealt to Taro are input.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input is n + 1 lines. The integer n is written on the first line. Each line from the 2nd line to the n + 1th line has one integer written on it, which represents the integer written on the card dealt to Taro.
When n is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, print Taro's score on the first line and Hanako's score on the second line.
Examples
Input
5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0
Output
3
0
2
0
Input
None
Output
None | instruction | 0 | 16,749 | 19 | 33,498 |
"Correct Solution:
```
# AOJ 0523: Card GameI
# Python3 2018.6.30 bal4u
while True:
n = int(input())
if n == 0: break
c = [1] * (2*n+1)
for i in range(1, n+1): c[int(input())] = 0
m = [n]*2
t, ba = 0, 0
while m[0] > 0 and m[1] > 0:
f = 1
for i in range(ba+1, 2*n+1):
if t == c[i]:
ba = i
c[i] = 2
m[t] -= 1
f = 0
break
if i == 2*n: ba = 0
if f: ba = 0
t = 1-t
print(m[1], m[0], sep='\n')
``` | output | 1 | 16,749 | 19 | 33,499 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There are the following two-player card games.
* This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100.
* Deal n cards to each of the two.
* Put cards into play alternately one by one according to the following rules.
* If there are no cards in play, you can play any card you like.
* If there are cards in play, you can play a larger number of written cards than the last card in play.
* If you can play a card, you must put it into play.
* If there is no card that can be issued, it will be a pass and it will be the opponent's turn. At this time, there are no cards in play.
* The game starts with no cards in play.
* The game ends when either card is exhausted.
* The number of cards the opponent has at the end of the game will be scored.
Taro and Hanako will play in this game. The game starts with Taro's turn. Both of them always issue the card with the smallest number of cards that can be issued.
Create a program that outputs the scores of Taro and Hanako when the cards dealt to Taro are input.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input is n + 1 lines. The integer n is written on the first line. Each line from the 2nd line to the n + 1th line has one integer written on it, which represents the integer written on the card dealt to Taro.
When n is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, print Taro's score on the first line and Hanako's score on the second line.
Examples
Input
5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0
Output
3
0
2
0
Input
None
Output
None | instruction | 0 | 16,750 | 19 | 33,500 |
"Correct Solution:
```
def bisect(a, x, lo=0, hi=None):
if hi is None:
hi = len(a)
while lo < hi:
mid = (lo+hi)//2
if x < a[mid]: hi = mid
else: lo = mid+1
return lo
while True:
n = int(input())
if n==0: break
dealt = [0]*(2*n)
thand = []
hhand = []
for i in range(n):
dealt[int(input())-1] = 1
for i in range(2*n):
if dealt[i]:
thand.append(i)
else:
hhand.append(i)
thand.sort()
hhand.sort()
tarosturn = 1
ba = -1
while True:
if len(thand) == 0:
print(len(hhand))
print(0)
break
elif len(hhand) == 0:
print(0)
print(len(thand))
break
if tarosturn:
taro = bisect(thand,ba)
if taro != len(thand):
ba = thand.pop(taro)
else:
ba = -1
tarosturn = 0
else:
hanako = bisect(hhand,ba)
if hanako != len(hhand):
ba = hhand.pop(hanako)
else:
ba = -1
tarosturn = 1
``` | output | 1 | 16,750 | 19 | 33,501 |
Provide a correct Python 3 solution for this coding contest problem.
problem
There are the following two-player card games.
* This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100.
* Deal n cards to each of the two.
* Put cards into play alternately one by one according to the following rules.
* If there are no cards in play, you can play any card you like.
* If there are cards in play, you can play a larger number of written cards than the last card in play.
* If you can play a card, you must put it into play.
* If there is no card that can be issued, it will be a pass and it will be the opponent's turn. At this time, there are no cards in play.
* The game starts with no cards in play.
* The game ends when either card is exhausted.
* The number of cards the opponent has at the end of the game will be scored.
Taro and Hanako will play in this game. The game starts with Taro's turn. Both of them always issue the card with the smallest number of cards that can be issued.
Create a program that outputs the scores of Taro and Hanako when the cards dealt to Taro are input.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input is n + 1 lines. The integer n is written on the first line. Each line from the 2nd line to the n + 1th line has one integer written on it, which represents the integer written on the card dealt to Taro.
When n is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, print Taro's score on the first line and Hanako's score on the second line.
Examples
Input
5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0
Output
3
0
2
0
Input
None
Output
None | instruction | 0 | 16,751 | 19 | 33,502 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Card Game
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0523
"""
import sys
from bisect import bisect_right
def solve(taro, hanako):
ba = taro.pop(0)
player = hanako
while taro and hanako:
i = bisect_right(player, ba)
if i != len(player):
ba = player.pop(i)
else:
player = taro if player == hanako else hanako
ba = player.pop(0)
player = taro if player == hanako else hanako
return len(hanako), len(taro)
def main(args):
while True:
n = int(input())
if n == 0:
break
taro = sorted([int(input()) for _ in range(n)])
hanako = sorted(set(range(1, 2*n+1)) - set(taro))
ans = solve(taro, hanako)
print(*ans, sep='\n')
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 16,751 | 19 | 33,503 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
There are the following two-player card games.
* This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100.
* Deal n cards to each of the two.
* Put cards into play alternately one by one according to the following rules.
* If there are no cards in play, you can play any card you like.
* If there are cards in play, you can play a larger number of written cards than the last card in play.
* If you can play a card, you must put it into play.
* If there is no card that can be issued, it will be a pass and it will be the opponent's turn. At this time, there are no cards in play.
* The game starts with no cards in play.
* The game ends when either card is exhausted.
* The number of cards the opponent has at the end of the game will be scored.
Taro and Hanako will play in this game. The game starts with Taro's turn. Both of them always issue the card with the smallest number of cards that can be issued.
Create a program that outputs the scores of Taro and Hanako when the cards dealt to Taro are input.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input is n + 1 lines. The integer n is written on the first line. Each line from the 2nd line to the n + 1th line has one integer written on it, which represents the integer written on the card dealt to Taro.
When n is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, print Taro's score on the first line and Hanako's score on the second line.
Examples
Input
5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0
Output
3
0
2
0
Input
None
Output
None
Submitted Solution:
```
def taro_turn(ba):
if ba==0:
return(taro.pop(-1))
elif ba>0:
for i in range(len(taro))[::-1]:
if taro[i]>ba:
k=taro[i]
taro.remove(k)
return(k)
return(0)
def hana_turn(ba):
if ba==0:
return(hana.pop(-1))
elif ba>0:
for i in range(len(hana))[::-1]:
if hana[i]>ba:
k=hana[i]
hana.remove(k)
return(k)
return(0)
while 1:
n=int(input())
if n==0:break
taro=[]
hana=[]
tarop=0
hanap=0
for i in range(n):
taro.append(int(input()))
for i in range(1,2*n+1)[::-1]:
if not i in taro:
hana.append(i)
taro.sort(reverse=True)
ba=0
while 1:
ba=taro_turn(ba)
if len(taro)==0:
tarop+=len(hana)
break
ba=hana_turn(ba)
if len(hana)==0:
hanap+=len(taro)
break
print(tarop)
print(hanap)
``` | instruction | 0 | 16,752 | 19 | 33,504 |
Yes | output | 1 | 16,752 | 19 | 33,505 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
There are the following two-player card games.
* This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100.
* Deal n cards to each of the two.
* Put cards into play alternately one by one according to the following rules.
* If there are no cards in play, you can play any card you like.
* If there are cards in play, you can play a larger number of written cards than the last card in play.
* If you can play a card, you must put it into play.
* If there is no card that can be issued, it will be a pass and it will be the opponent's turn. At this time, there are no cards in play.
* The game starts with no cards in play.
* The game ends when either card is exhausted.
* The number of cards the opponent has at the end of the game will be scored.
Taro and Hanako will play in this game. The game starts with Taro's turn. Both of them always issue the card with the smallest number of cards that can be issued.
Create a program that outputs the scores of Taro and Hanako when the cards dealt to Taro are input.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input is n + 1 lines. The integer n is written on the first line. Each line from the 2nd line to the n + 1th line has one integer written on it, which represents the integer written on the card dealt to Taro.
When n is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, print Taro's score on the first line and Hanako's score on the second line.
Examples
Input
5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0
Output
3
0
2
0
Input
None
Output
None
Submitted Solution:
```
while True:
n = int(input())
if not n: break
lst = [0 for i in range(n * 2)]
for i in range(n):
lst[int(input()) - 1] = 1
T = [i for i in range(n * 2) if lst[i]]
H = [i for i in range(n * 2) if not lst[i]]
f = -1
t = 0
while T and H:
if not t:
for i in range(len(T)):
if T[i] >= f:
f = T.pop(i)
t = 1
break
else:
t = 1
f = -1
elif t:
for i in range(len(H)):
if H[i] >= f:
f = H.pop(i)
t = 0
break
else:
t = 0
f = -1
print(len(H))
print(len(T))
``` | instruction | 0 | 16,753 | 19 | 33,506 |
Yes | output | 1 | 16,753 | 19 | 33,507 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
There are the following two-player card games.
* This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100.
* Deal n cards to each of the two.
* Put cards into play alternately one by one according to the following rules.
* If there are no cards in play, you can play any card you like.
* If there are cards in play, you can play a larger number of written cards than the last card in play.
* If you can play a card, you must put it into play.
* If there is no card that can be issued, it will be a pass and it will be the opponent's turn. At this time, there are no cards in play.
* The game starts with no cards in play.
* The game ends when either card is exhausted.
* The number of cards the opponent has at the end of the game will be scored.
Taro and Hanako will play in this game. The game starts with Taro's turn. Both of them always issue the card with the smallest number of cards that can be issued.
Create a program that outputs the scores of Taro and Hanako when the cards dealt to Taro are input.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input is n + 1 lines. The integer n is written on the first line. Each line from the 2nd line to the n + 1th line has one integer written on it, which represents the integer written on the card dealt to Taro.
When n is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, print Taro's score on the first line and Hanako's score on the second line.
Examples
Input
5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0
Output
3
0
2
0
Input
None
Output
None
Submitted Solution:
```
while True:
n=int(input())
if n==0:break
card_t=sorted([int(input())for i in range(n)])
card_h=[]
for i in range(2*n):
if i+1 not in card_t:card_h.append(i+1)
ba=0
while True:
for i in range(len(card_t)):
if card_t[i]>ba:
ba=card_t.pop(i)
break
if i==len(card_t)-1:ba=0
if len(card_t)==0:break
for i in range(len(card_h)):
if card_h[i]>ba:
ba=card_h.pop(i)
break
if i==len(card_h)-1:ba=0
if len(card_h)==0:break
print(len(card_h))
print(len(card_t))
``` | instruction | 0 | 16,754 | 19 | 33,508 |
Yes | output | 1 | 16,754 | 19 | 33,509 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
There are the following two-player card games.
* This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100.
* Deal n cards to each of the two.
* Put cards into play alternately one by one according to the following rules.
* If there are no cards in play, you can play any card you like.
* If there are cards in play, you can play a larger number of written cards than the last card in play.
* If you can play a card, you must put it into play.
* If there is no card that can be issued, it will be a pass and it will be the opponent's turn. At this time, there are no cards in play.
* The game starts with no cards in play.
* The game ends when either card is exhausted.
* The number of cards the opponent has at the end of the game will be scored.
Taro and Hanako will play in this game. The game starts with Taro's turn. Both of them always issue the card with the smallest number of cards that can be issued.
Create a program that outputs the scores of Taro and Hanako when the cards dealt to Taro are input.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input is n + 1 lines. The integer n is written on the first line. Each line from the 2nd line to the n + 1th line has one integer written on it, which represents the integer written on the card dealt to Taro.
When n is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, print Taro's score on the first line and Hanako's score on the second line.
Examples
Input
5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0
Output
3
0
2
0
Input
None
Output
None
Submitted Solution:
```
import bisect
for e in iter(input,'0'):
n=int(e)
c=[sorted(int(input())for _ in[0]*n)]
c+=[sorted(set(range(1,2*n+1))-set(c[0]))]
t=f=0
while 1:
l=len(c[t])
if l<1:break
x=bisect.bisect(c[t],f)
f=c[t].pop(x)if x<l else 0
t^=1
for i in[1,0]:print(len(c[i]))
``` | instruction | 0 | 16,755 | 19 | 33,510 |
Yes | output | 1 | 16,755 | 19 | 33,511 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
There are the following two-player card games.
* This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100.
* Deal n cards to each of the two.
* Put cards into play alternately one by one according to the following rules.
* If there are no cards in play, you can play any card you like.
* If there are cards in play, you can play a larger number of written cards than the last card in play.
* If you can play a card, you must put it into play.
* If there is no card that can be issued, it will be a pass and it will be the opponent's turn. At this time, there are no cards in play.
* The game starts with no cards in play.
* The game ends when either card is exhausted.
* The number of cards the opponent has at the end of the game will be scored.
Taro and Hanako will play in this game. The game starts with Taro's turn. Both of them always issue the card with the smallest number of cards that can be issued.
Create a program that outputs the scores of Taro and Hanako when the cards dealt to Taro are input.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input is n + 1 lines. The integer n is written on the first line. Each line from the 2nd line to the n + 1th line has one integer written on it, which represents the integer written on the card dealt to Taro.
When n is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, print Taro's score on the first line and Hanako's score on the second line.
Examples
Input
5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0
Output
3
0
2
0
Input
None
Output
None
Submitted Solution:
```
import bisect
while True:
n = int(input())
if n == 0:
break
card_set = [sorted(int(input()) for _ in range(n)), []]
card_set[1] = sorted({i for i in range(1, 2*n+1)}.difference(card_set[0]))
card = turn = 0
flag = 1
ba = []
while flag:
if len(ba) == 0:
card = card_set[turn].pop(0)
ba.append(card)
flag = 0 if len(card_set[turn])==0 else 1
turn = 0 if turn else 1
continue
last_card = ba[-1]
x = bisect.bisect_left(card_set[turn], last_card)
try:
card = card_set[turn].pop(x)
ba.append(card)
except IndexError:
ba = []
flag = 0 if len(card_set[turn])==0 else 1
turn = 0 if turn else 1
print(*[len(cet) for cet in card_set], sep='\n')
``` | instruction | 0 | 16,756 | 19 | 33,512 |
No | output | 1 | 16,756 | 19 | 33,513 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
There are the following two-player card games.
* This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100.
* Deal n cards to each of the two.
* Put cards into play alternately one by one according to the following rules.
* If there are no cards in play, you can play any card you like.
* If there are cards in play, you can play a larger number of written cards than the last card in play.
* If you can play a card, you must put it into play.
* If there is no card that can be issued, it will be a pass and it will be the opponent's turn. At this time, there are no cards in play.
* The game starts with no cards in play.
* The game ends when either card is exhausted.
* The number of cards the opponent has at the end of the game will be scored.
Taro and Hanako will play in this game. The game starts with Taro's turn. Both of them always issue the card with the smallest number of cards that can be issued.
Create a program that outputs the scores of Taro and Hanako when the cards dealt to Taro are input.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input is n + 1 lines. The integer n is written on the first line. Each line from the 2nd line to the n + 1th line has one integer written on it, which represents the integer written on the card dealt to Taro.
When n is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, print Taro's score on the first line and Hanako's score on the second line.
Examples
Input
5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0
Output
3
0
2
0
Input
None
Output
None
Submitted Solution:
```
import bisect
while True:
n = int(input())
if n == 0:
break
tc = sorted([int(input()) for _ in range(n)])
hc = sorted([v for v in range(1, 2*n+1) if v not in tc])
ba = []
flag = True
while tc and hc:
if len(ba) == 0:
try:
if flag:
tmp = tc.pop(0)
flag = False
else:
tmp = hc.pop(0)
flag = True
except IndexError:
pass
ba = [tmp]
continue
last_card = ba[-1]
if flag:
x = bisect.bisect_left(tc, last_card)
flag = False
try:
tmp = tc.pop(x)
except IndexError:
ba = []
continue
else:
x = bisect.bisect_left(hc, last_card)
flag = True
try:
tmp = hc.pop(x)
except IndexError:
ba = []
continue
ba.append(tmp)
print(len(tc))
print(len(hc))
``` | instruction | 0 | 16,757 | 19 | 33,514 |
No | output | 1 | 16,757 | 19 | 33,515 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
There are the following two-player card games.
* This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100.
* Deal n cards to each of the two.
* Put cards into play alternately one by one according to the following rules.
* If there are no cards in play, you can play any card you like.
* If there are cards in play, you can play a larger number of written cards than the last card in play.
* If you can play a card, you must put it into play.
* If there is no card that can be issued, it will be a pass and it will be the opponent's turn. At this time, there are no cards in play.
* The game starts with no cards in play.
* The game ends when either card is exhausted.
* The number of cards the opponent has at the end of the game will be scored.
Taro and Hanako will play in this game. The game starts with Taro's turn. Both of them always issue the card with the smallest number of cards that can be issued.
Create a program that outputs the scores of Taro and Hanako when the cards dealt to Taro are input.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input is n + 1 lines. The integer n is written on the first line. Each line from the 2nd line to the n + 1th line has one integer written on it, which represents the integer written on the card dealt to Taro.
When n is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, print Taro's score on the first line and Hanako's score on the second line.
Examples
Input
5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0
Output
3
0
2
0
Input
None
Output
None
Submitted Solution:
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
while True:
n = int(input())
if n == 0:
break
taro = []
for i in range(n):
taro.append(int(input()))
hanako = [i for i in range(1, 2*n + 1) if not i in taro]
ret = max(max(taro), max(hanako)) - min(max(taro), max(hanako))
print(ret + 1 if ret > 0 else 0)
print(0 if ret > 0 else ret + 1)
``` | instruction | 0 | 16,758 | 19 | 33,516 |
No | output | 1 | 16,758 | 19 | 33,517 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
There are the following two-player card games.
* This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100.
* Deal n cards to each of the two.
* Put cards into play alternately one by one according to the following rules.
* If there are no cards in play, you can play any card you like.
* If there are cards in play, you can play a larger number of written cards than the last card in play.
* If you can play a card, you must put it into play.
* If there is no card that can be issued, it will be a pass and it will be the opponent's turn. At this time, there are no cards in play.
* The game starts with no cards in play.
* The game ends when either card is exhausted.
* The number of cards the opponent has at the end of the game will be scored.
Taro and Hanako will play in this game. The game starts with Taro's turn. Both of them always issue the card with the smallest number of cards that can be issued.
Create a program that outputs the scores of Taro and Hanako when the cards dealt to Taro are input.
input
The input consists of multiple datasets. Each dataset is given in the following format.
The input is n + 1 lines. The integer n is written on the first line. Each line from the 2nd line to the n + 1th line has one integer written on it, which represents the integer written on the card dealt to Taro.
When n is 0, it indicates the end of input. The number of data sets does not exceed 5.
output
For each dataset, print Taro's score on the first line and Hanako's score on the second line.
Examples
Input
5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0
Output
3
0
2
0
Input
None
Output
None
Submitted Solution:
```
def discard(c, cards):
for card in cards:
if c < card:
return card
return 0
while True:
n = int(input())
if n == 0:
break
taro = [int(input()) for _ in range(n)]
hanako = [x + 1 for x in range(2*n) if (x + 1) not in taro]
taro.sort()
hanako.sort()
table = 0
while True:
if taro:
table = discard(table, taro)
if table:
taro.remove(table)
if not taro:
print(len(hanako))
print(0)
break
if hanako:
table = discard(table, hanako)
if table:
hanako.remove(table)
if not hanako:
print(0)
print(len(taro))
``` | instruction | 0 | 16,759 | 19 | 33,518 |
No | output | 1 | 16,759 | 19 | 33,519 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are n piles of cows, with the i-th pile containing ai cows. During each player's turn, that player calls upon the power of Sunlight, and uses it to either:
1. Remove a single cow from a chosen non-empty pile.
2. Choose a pile of cows with even size 2·x (x > 0), and replace it with k piles of x cows each.
The player who removes the last cow wins. Given n, k, and a sequence a1, a2, ..., an, help Kevin and Nicky find the winner, given that both sides play in optimal way.
Input
The first line of the input contains two space-separated integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109).
The second line contains n integers, a1, a2, ... an (1 ≤ ai ≤ 109) describing the initial state of the game.
Output
Output the name of the winning player, either "Kevin" or "Nicky" (without quotes).
Examples
Input
2 1
3 4
Output
Kevin
Input
1 2
3
Output
Nicky
Note
In the second sample, Nicky can win in the following way: Kevin moves first and is forced to remove a cow, so the pile contains two cows after his move. Next, Nicky replaces this pile of size 2 with two piles of size 1. So the game state is now two piles of size 1. Kevin then removes one of the remaining cows and Nicky wins by removing the other. | instruction | 0 | 17,237 | 19 | 34,474 |
Tags: games, math
Correct Solution:
```
G_EVEN = {0:0, 1:1, 2:2}
G_ODD = {0:0, 1:1, 2:0, 3:1}
def grundy(k, ai):
if k % 2:
if ai <= 3:
return G_ODD[ai]
elif ai % 2:
return 0
else:
p = 0
j = ai
while not j & 1:
p += 1
j >>= 1
if j == 3:
return 2 if p % 2 else 1
else:
return 1 if p % 2 else 2
return 1 + p % 2
else:
if ai <= 2:
return G_EVEN[ai]
else:
return ~ai & 1
def nim_sum(ns):
s = 0
for ni in ns:
s ^= ni
return s
def winner(k, a):
return bool(nim_sum(grundy(k, ai) for ai in a))
if __name__ == '__main__':
n, k = map(int, input().split())
a = list(map(int, input().split()))
print("Kevin" if winner(k, a) else "Nicky")
``` | output | 1 | 17,237 | 19 | 34,475 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are n piles of cows, with the i-th pile containing ai cows. During each player's turn, that player calls upon the power of Sunlight, and uses it to either:
1. Remove a single cow from a chosen non-empty pile.
2. Choose a pile of cows with even size 2·x (x > 0), and replace it with k piles of x cows each.
The player who removes the last cow wins. Given n, k, and a sequence a1, a2, ..., an, help Kevin and Nicky find the winner, given that both sides play in optimal way.
Input
The first line of the input contains two space-separated integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109).
The second line contains n integers, a1, a2, ... an (1 ≤ ai ≤ 109) describing the initial state of the game.
Output
Output the name of the winning player, either "Kevin" or "Nicky" (without quotes).
Examples
Input
2 1
3 4
Output
Kevin
Input
1 2
3
Output
Nicky
Note
In the second sample, Nicky can win in the following way: Kevin moves first and is forced to remove a cow, so the pile contains two cows after his move. Next, Nicky replaces this pile of size 2 with two piles of size 1. So the game state is now two piles of size 1. Kevin then removes one of the remaining cows and Nicky wins by removing the other.
Submitted Solution:
```
from collections import Counter
def winner(k, a):
m = max(a)
w = [2]
for i in range(1, m+1):
if i % 2:
if w[i-1] == 2:
wi = 1
else:
wi = 2
else:
if w[i-1] & 1:
w1 = 2
else:
w1 = 1
j = i//2
if w[j] & 1:
if k % 2:
w2 = 2
else:
w2 = 1
else:
w2 = 1
wi = w1 | w2
w.append(wi)
c = Counter(w[ai] for ai in a)
return c[1]%2 or c[3]%2
if __name__ == '__main__':
n, k = map(int, input().split())
a = list(map(int, input().split()))
print("Kevin" if winner(k, a) else "Nicky")
``` | instruction | 0 | 17,238 | 19 | 34,476 |
No | output | 1 | 17,238 | 19 | 34,477 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are n piles of cows, with the i-th pile containing ai cows. During each player's turn, that player calls upon the power of Sunlight, and uses it to either:
1. Remove a single cow from a chosen non-empty pile.
2. Choose a pile of cows with even size 2·x (x > 0), and replace it with k piles of x cows each.
The player who removes the last cow wins. Given n, k, and a sequence a1, a2, ..., an, help Kevin and Nicky find the winner, given that both sides play in optimal way.
Input
The first line of the input contains two space-separated integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109).
The second line contains n integers, a1, a2, ... an (1 ≤ ai ≤ 109) describing the initial state of the game.
Output
Output the name of the winning player, either "Kevin" or "Nicky" (without quotes).
Examples
Input
2 1
3 4
Output
Kevin
Input
1 2
3
Output
Nicky
Note
In the second sample, Nicky can win in the following way: Kevin moves first and is forced to remove a cow, so the pile contains two cows after his move. Next, Nicky replaces this pile of size 2 with two piles of size 1. So the game state is now two piles of size 1. Kevin then removes one of the remaining cows and Nicky wins by removing the other.
Submitted Solution:
```
from collections import Counter
def winner(k, a):
m = max(a)
w = [2]
for i in range(1, m+1):
if i % 2:
wi = w[i-1] ^ 3
else:
w1 = w[i-1] ^ 3
if k % 2:
w2 = w[i//2] ^ 3
else:
w2 = 1
wi = w1 | w2
w.append(wi)
c = Counter(w[ai] for ai in a)
return c[1]%2 or c[3]%2
if __name__ == '__main__':
n, k = map(int, input().split())
a = list(map(int, input().split()))
print("Kevin" if winner(k, a) else "Nicky")
``` | instruction | 0 | 17,239 | 19 | 34,478 |
No | output | 1 | 17,239 | 19 | 34,479 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are n piles of cows, with the i-th pile containing ai cows. During each player's turn, that player calls upon the power of Sunlight, and uses it to either:
1. Remove a single cow from a chosen non-empty pile.
2. Choose a pile of cows with even size 2·x (x > 0), and replace it with k piles of x cows each.
The player who removes the last cow wins. Given n, k, and a sequence a1, a2, ..., an, help Kevin and Nicky find the winner, given that both sides play in optimal way.
Input
The first line of the input contains two space-separated integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109).
The second line contains n integers, a1, a2, ... an (1 ≤ ai ≤ 109) describing the initial state of the game.
Output
Output the name of the winning player, either "Kevin" or "Nicky" (without quotes).
Examples
Input
2 1
3 4
Output
Kevin
Input
1 2
3
Output
Nicky
Note
In the second sample, Nicky can win in the following way: Kevin moves first and is forced to remove a cow, so the pile contains two cows after his move. Next, Nicky replaces this pile of size 2 with two piles of size 1. So the game state is now two piles of size 1. Kevin then removes one of the remaining cows and Nicky wins by removing the other.
Submitted Solution:
```
from functools import wraps
def sep2(k):
p = 0
while not (k & 1):
p += 1
k >>= 1
return k, p
def winner(k, a):
if k % 2:
w = 0
wl = 0
for ai in a:
if ai == 1 or ai == 3:
w += 1
elif ai >= 4 and ai % 2 == 0:
r, p = sep2(ai)
if r == 1:
p -= 1
wl += p
return (w % 2) or (wl % 2)
else:
# Win iff there are an odd number of even or 1 piles
return sum(1 for ai in a if ai==1 or ai % 2 == 0) % 2 == 1
if __name__ == '__main__':
n, k = map(int, input().split())
a = list(map(int, input().split()))
print("Kevin" if winner(k, a) else "Nicky")
``` | instruction | 0 | 17,240 | 19 | 34,480 |
No | output | 1 | 17,240 | 19 | 34,481 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are n piles of cows, with the i-th pile containing ai cows. During each player's turn, that player calls upon the power of Sunlight, and uses it to either:
1. Remove a single cow from a chosen non-empty pile.
2. Choose a pile of cows with even size 2·x (x > 0), and replace it with k piles of x cows each.
The player who removes the last cow wins. Given n, k, and a sequence a1, a2, ..., an, help Kevin and Nicky find the winner, given that both sides play in optimal way.
Input
The first line of the input contains two space-separated integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109).
The second line contains n integers, a1, a2, ... an (1 ≤ ai ≤ 109) describing the initial state of the game.
Output
Output the name of the winning player, either "Kevin" or "Nicky" (without quotes).
Examples
Input
2 1
3 4
Output
Kevin
Input
1 2
3
Output
Nicky
Note
In the second sample, Nicky can win in the following way: Kevin moves first and is forced to remove a cow, so the pile contains two cows after his move. Next, Nicky replaces this pile of size 2 with two piles of size 1. So the game state is now two piles of size 1. Kevin then removes one of the remaining cows and Nicky wins by removing the other.
Submitted Solution:
```
from collections import Counter
def winner(k, a):
m = max(a)
w = [2]
for i in range(1, m+1):
if i % 2:
if w[i-1] == 2:
wi = 1
else:
wi = 2
else:
if w[i-1] & 1:
w1 = 2
else:
w1 = 1
j = i//2
if w[j] & 1:
if k % 2:
w2 = 2
else:
w2 = 3
else:
w2 = 1
wi = w1 | w2
w.append(wi)
c = Counter(w[ai] for ai in a)
return c[1]%2 or c[3]%2
if __name__ == '__main__':
n, k = map(int, input().split())
a = list(map(int, input().split()))
print("Kevin" if winner(k, a) else "Nicky")
``` | instruction | 0 | 17,241 | 19 | 34,482 |
No | output | 1 | 17,241 | 19 | 34,483 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the code name "dot" with the following rules:
* On the checkered paper a coordinate system is drawn. A dot is initially put in the position (x, y).
* A move is shifting a dot to one of the pre-selected vectors. Also each player can once per game symmetrically reflect a dot relatively to the line y = x.
* Anton and Dasha take turns. Anton goes first.
* The player after whose move the distance from the dot to the coordinates' origin exceeds d, loses.
Help them to determine the winner.
Input
The first line of the input file contains 4 integers x, y, n, d ( - 200 ≤ x, y ≤ 200, 1 ≤ d ≤ 200, 1 ≤ n ≤ 20) — the initial coordinates of the dot, the distance d and the number of vectors. It is guaranteed that the initial dot is at the distance less than d from the origin of the coordinates. The following n lines each contain two non-negative numbers xi and yi (0 ≤ xi, yi ≤ 200) — the coordinates of the i-th vector. It is guaranteed that all the vectors are nonzero and different.
Output
You should print "Anton", if the winner is Anton in case of both players play the game optimally, and "Dasha" otherwise.
Examples
Input
0 0 2 3
1 1
1 2
Output
Anton
Input
0 0 2 4
1 1
1 2
Output
Dasha
Note
In the first test, Anton goes to the vector (1;2), and Dasha loses. In the second test Dasha with her first move shifts the dot so that its coordinates are (2;3), and Anton loses, as he has the only possible move — to reflect relatively to the line y = x. Dasha will respond to it with the same move and return the dot in position (2;3). | instruction | 0 | 17,278 | 19 | 34,556 |
Tags: dp, games
Correct Solution:
```
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
x, y, n, d = map(int, input().split())
vector = [list(map(int, input().split())) for _ in range(n)]
dp = [[-1] * (d * 2 + 1) for _ in range(d * 2 + 1)]
for i in range(d * 2 + 1):
for j in range(d * 2 + 1):
if (i - d) ** 2 + (j - d) ** 2 > d**2:
dp[i][j] = 1
def solve(x, y):
if dp[x][y] != -1:
return dp[x][y]
for dx, dy in vector:
if 0 <= x + dx <= 2 * d and 0 <= y + dy <= 2 * d and solve(x + dx, y + dy) == 0:
dp[x][y] = 1
return 1
dp[x][y] = 0
return 0
if solve(x + d, y + d):
print('Anton')
else:
print('Dasha')
``` | output | 1 | 17,278 | 19 | 34,557 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the code name "dot" with the following rules:
* On the checkered paper a coordinate system is drawn. A dot is initially put in the position (x, y).
* A move is shifting a dot to one of the pre-selected vectors. Also each player can once per game symmetrically reflect a dot relatively to the line y = x.
* Anton and Dasha take turns. Anton goes first.
* The player after whose move the distance from the dot to the coordinates' origin exceeds d, loses.
Help them to determine the winner.
Input
The first line of the input file contains 4 integers x, y, n, d ( - 200 ≤ x, y ≤ 200, 1 ≤ d ≤ 200, 1 ≤ n ≤ 20) — the initial coordinates of the dot, the distance d and the number of vectors. It is guaranteed that the initial dot is at the distance less than d from the origin of the coordinates. The following n lines each contain two non-negative numbers xi and yi (0 ≤ xi, yi ≤ 200) — the coordinates of the i-th vector. It is guaranteed that all the vectors are nonzero and different.
Output
You should print "Anton", if the winner is Anton in case of both players play the game optimally, and "Dasha" otherwise.
Examples
Input
0 0 2 3
1 1
1 2
Output
Anton
Input
0 0 2 4
1 1
1 2
Output
Dasha
Note
In the first test, Anton goes to the vector (1;2), and Dasha loses. In the second test Dasha with her first move shifts the dot so that its coordinates are (2;3), and Anton loses, as he has the only possible move — to reflect relatively to the line y = x. Dasha will respond to it with the same move and return the dot in position (2;3). | instruction | 0 | 17,279 | 19 | 34,558 |
Tags: dp, games
Correct Solution:
```
from sys import stdin
x,y,n,d = [int(x) for x in stdin.readline().split()]
d = d**2
v = []
for vec in range(n):
v.append([int(x) for x in stdin.readline().split()])
found = {}
def winner(x,y,v,d):
if x**2 + y**2 > d:
return 1
if (x,y) in found:
return found[(x,y)]
for a,b in v:
if winner(x+a,y+b,v,d) == 0:
found[(x,y)] = 1
return 1
found[(x,y)] = 0
return 0
if winner(x,y,v,d):
print('Anton')
else:
print('Dasha')
``` | output | 1 | 17,279 | 19 | 34,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the code name "dot" with the following rules:
* On the checkered paper a coordinate system is drawn. A dot is initially put in the position (x, y).
* A move is shifting a dot to one of the pre-selected vectors. Also each player can once per game symmetrically reflect a dot relatively to the line y = x.
* Anton and Dasha take turns. Anton goes first.
* The player after whose move the distance from the dot to the coordinates' origin exceeds d, loses.
Help them to determine the winner.
Input
The first line of the input file contains 4 integers x, y, n, d ( - 200 ≤ x, y ≤ 200, 1 ≤ d ≤ 200, 1 ≤ n ≤ 20) — the initial coordinates of the dot, the distance d and the number of vectors. It is guaranteed that the initial dot is at the distance less than d from the origin of the coordinates. The following n lines each contain two non-negative numbers xi and yi (0 ≤ xi, yi ≤ 200) — the coordinates of the i-th vector. It is guaranteed that all the vectors are nonzero and different.
Output
You should print "Anton", if the winner is Anton in case of both players play the game optimally, and "Dasha" otherwise.
Examples
Input
0 0 2 3
1 1
1 2
Output
Anton
Input
0 0 2 4
1 1
1 2
Output
Dasha
Note
In the first test, Anton goes to the vector (1;2), and Dasha loses. In the second test Dasha with her first move shifts the dot so that its coordinates are (2;3), and Anton loses, as he has the only possible move — to reflect relatively to the line y = x. Dasha will respond to it with the same move and return the dot in position (2;3).
Submitted Solution:
```
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
x, y, n, d = map(int, input().split())
vector = [list(map(int, input().split())) for _ in range(n)]
dp = [-1] * (1 << n)
def solve(bit, x, y):
if dp[bit] != -1:
return dp[bit]
for i in range(n):
if (1 << i) & bit:
continue
if (x + vector[i][0]) ** 2 + (y + vector[i][1])**2 <= d**2 and solve(bit | (1 << i), x + vector[i][0], y + vector[i][1]) == 0:
dp[bit] = 1
return 1
dp[bit] = 0
return 0
if solve(0, x, y):
print('Anton')
else:
print('Dasha')
``` | instruction | 0 | 17,280 | 19 | 34,560 |
No | output | 1 | 17,280 | 19 | 34,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the code name "dot" with the following rules:
* On the checkered paper a coordinate system is drawn. A dot is initially put in the position (x, y).
* A move is shifting a dot to one of the pre-selected vectors. Also each player can once per game symmetrically reflect a dot relatively to the line y = x.
* Anton and Dasha take turns. Anton goes first.
* The player after whose move the distance from the dot to the coordinates' origin exceeds d, loses.
Help them to determine the winner.
Input
The first line of the input file contains 4 integers x, y, n, d ( - 200 ≤ x, y ≤ 200, 1 ≤ d ≤ 200, 1 ≤ n ≤ 20) — the initial coordinates of the dot, the distance d and the number of vectors. It is guaranteed that the initial dot is at the distance less than d from the origin of the coordinates. The following n lines each contain two non-negative numbers xi and yi (0 ≤ xi, yi ≤ 200) — the coordinates of the i-th vector. It is guaranteed that all the vectors are nonzero and different.
Output
You should print "Anton", if the winner is Anton in case of both players play the game optimally, and "Dasha" otherwise.
Examples
Input
0 0 2 3
1 1
1 2
Output
Anton
Input
0 0 2 4
1 1
1 2
Output
Dasha
Note
In the first test, Anton goes to the vector (1;2), and Dasha loses. In the second test Dasha with her first move shifts the dot so that its coordinates are (2;3), and Anton loses, as he has the only possible move — to reflect relatively to the line y = x. Dasha will respond to it with the same move and return the dot in position (2;3).
Submitted Solution:
```
def game(x, y, turn, t_r, f_r):
if x * x + y * y > d * d:
return not turn
for v in vectors:
outcome = game(x + v[0], y + v[1], not turn, t_r, f_r)
if outcome == turn:
return turn
if turn and t_r:
outcome = game(-y, -x, not turn, False, f_r)
if outcome == turn:
return turn
if not turn and f_r:
outcome = game(-y, -x, not turn, t_r, False)
if outcome == turn:
return turn
return not turn
q = input().split()
x = int(q[0])
y = int(q[1])
n = int(q[2])
d = int(q[3])
vectors = []
for i in range(n):
vectors.append(list(map(int, input().split())))
print("Dasha" if game(x, y, True, True, True) else "Anton")
``` | instruction | 0 | 17,281 | 19 | 34,562 |
No | output | 1 | 17,281 | 19 | 34,563 |
Provide a correct Python 3 solution for this coding contest problem.
Whist is a game played by four players with a standard deck of playing cards. The players seat around a table, namely, in north, east, south, and west. This game is played in a team-play basis: the players seating opposite to each other become a team. In other words, they make two teams we could call the north-south team and the east-west team.
Remember that the standard deck consists of 52 cards each of which has a rank and a suit. The rank indicates the strength of the card and is one of the following: 2, 3, 4, 5, 6, 7, 8, 9, 10, jack, queen, king, and ace (from the lowest to the highest). The suit refers to the type of symbols printed on the card, namely, spades, hearts, diamonds, and clubs. The deck contains exactly one card for every possible pair of a rank and a suit, thus 52 cards.
One of the four players (called a dealer) shuffles the deck and deals out all the cards face down, one by one, clockwise from the player left to him or her. Each player should have thirteen cards. Then the last dealt card, which belongs to the dealer, is turned face up. The suit of this card is called trumps and has a special meaning as mentioned below.
A deal of this game consists of thirteen tricks. The objective for each team is winning more tricks than another team. The player left to the dealer leads the first trick by playing one of the cards in his or her hand. Then the other players make their plays in the clockwise order. They have to play a card of the suit led if they have one; they can play any card otherwise. The trick is won by the player with the highest card of the suit led if no one plays a trump, or with the highest trump otherwise. The winner of this trick leads the next trick, and the remaining part of the deal is played similarly. After the thirteen tricks have been played, the team winning more tricks gains a score, one point per trick in excess of six.
Your task is to write a program that determines the winning team and their score for given plays of a deal.
Input
The input is a sequence of datasets. Each dataset corresponds to a single deal and has the following format:
Trump
CardN,1 CardN,2 ... CardN,13
CardE,1 CardE,2 ... CardE,13
CardS,1 CardS,2 ... CardS,13
CardW,1 CardW,2 ... CardW,13
Trump indicates the trump suit. CardN,i, CardE,i, CardS,i, and CardW,i denote the card played in the i-th trick by the north, east, south, and west players respectively. Each card is represented by two characters; the first and second character indicates the rank and the suit respectively.
The rank is represented by one of the following characters: ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘T’ (10), ‘J’ (jack), ‘Q’ (queen), ‘K’ (king), and ‘A’ (ace). The suit is represented by one of the following characters: ‘S’ (spades), ‘H’ (hearts), ‘D’ (diamonds), and ‘C’ (clubs).
You should assume the cards have been dealt out by the west player. Thus the first trick is led by the north player. Also, the input does not contain any illegal plays.
The input is terminated by a line with “#”. This is not part of any dataset and thus should not be processed.
Output
For each dataset, print the winner and their score of the deal in a line, with a single space between them as a separator. The winner should be either “NS” (the north-south team) or “EW” (the east-west team). No extra character or whitespace should appear in the output.
Examples
Input
H
4C 8H QS 5D JD KS 8S AH 6H 7H 3S 7S 6D
TC JC JS KD AC QC QD 2H QH 3H 3C 7C 4D
6C 9C AS TD 5H 6S 5S KH TH AD 9S 8D 2D
8C 5C 2S 7D KC 4S TS JH 4H 9H 2C 9D 3D
D
8D 9D 9S QS 4H 5H JD JS 9H 6S TH 6H QH
QD 9C 5S 7S 7H AC 2D KD 6C 3D 8C TC 7C
5D QC 3S 4S 3H 3C 6D KS JC AS 5C 8H TS
4D 4C 8S 2S 2H KC TD JH 2C AH 7D AD KH
#
Output
EW 1
EW 2
Input
H
4C 8H QS 5D JD KS 8S AH 6H 7H 3S 7S 6D
TC JC JS KD AC QC QD 2H QH 3H 3C 7C 4D
6C 9C AS TD 5H 6S 5S KH TH AD 9S 8D 2D
8C 5C 2S 7D KC 4S TS JH 4H 9H 2C 9D 3D
D
8D 9D 9S QS 4H 5H JD JS 9H 6S TH 6H QH
QD 9C 5S 7S 7H AC 2D KD 6C 3D 8C TC 7C
5D QC 3S 4S 3H 3C 6D KS JC AS 5C 8H TS
4D 4C 8S 2S 2H KC TD JH 2C AH 7D AD KH
Output
EW 1
EW 2 | instruction | 0 | 17,644 | 19 | 35,288 |
"Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
mk = {}
mk['T'] = 10
mk['J'] = 11
mk['Q'] = 12
mk['K'] = 13
mk['A'] = 14
for i in range(1,10):
mk[str(i)] = i
while True:
t = S()
if t == '#':
break
a = [list(map(lambda x: (mk[x[0]], x[1]), LS())) for _ in range(4)]
d = 0
ns = 0
ew = 0
for i in range(13):
m = -1
mi = -1
it = a[d][i][1]
for j in range(4):
k = a[j][i][0]
if a[j][i][1] == t:
k += 100
if a[j][i][1] == it:
k += 50
if m < k:
m = k
mi = j
d = mi
if mi % 2 == 0:
ns += 1
else:
ew += 1
if ns > 6:
rr.append('NS {}'.format(ns - 6))
else:
rr.append('EW {}'.format(ew - 6))
return '\n'.join(map(str, rr))
print(main())
``` | output | 1 | 17,644 | 19 | 35,289 |
Provide a correct Python 3 solution for this coding contest problem.
Whist is a game played by four players with a standard deck of playing cards. The players seat around a table, namely, in north, east, south, and west. This game is played in a team-play basis: the players seating opposite to each other become a team. In other words, they make two teams we could call the north-south team and the east-west team.
Remember that the standard deck consists of 52 cards each of which has a rank and a suit. The rank indicates the strength of the card and is one of the following: 2, 3, 4, 5, 6, 7, 8, 9, 10, jack, queen, king, and ace (from the lowest to the highest). The suit refers to the type of symbols printed on the card, namely, spades, hearts, diamonds, and clubs. The deck contains exactly one card for every possible pair of a rank and a suit, thus 52 cards.
One of the four players (called a dealer) shuffles the deck and deals out all the cards face down, one by one, clockwise from the player left to him or her. Each player should have thirteen cards. Then the last dealt card, which belongs to the dealer, is turned face up. The suit of this card is called trumps and has a special meaning as mentioned below.
A deal of this game consists of thirteen tricks. The objective for each team is winning more tricks than another team. The player left to the dealer leads the first trick by playing one of the cards in his or her hand. Then the other players make their plays in the clockwise order. They have to play a card of the suit led if they have one; they can play any card otherwise. The trick is won by the player with the highest card of the suit led if no one plays a trump, or with the highest trump otherwise. The winner of this trick leads the next trick, and the remaining part of the deal is played similarly. After the thirteen tricks have been played, the team winning more tricks gains a score, one point per trick in excess of six.
Your task is to write a program that determines the winning team and their score for given plays of a deal.
Input
The input is a sequence of datasets. Each dataset corresponds to a single deal and has the following format:
Trump
CardN,1 CardN,2 ... CardN,13
CardE,1 CardE,2 ... CardE,13
CardS,1 CardS,2 ... CardS,13
CardW,1 CardW,2 ... CardW,13
Trump indicates the trump suit. CardN,i, CardE,i, CardS,i, and CardW,i denote the card played in the i-th trick by the north, east, south, and west players respectively. Each card is represented by two characters; the first and second character indicates the rank and the suit respectively.
The rank is represented by one of the following characters: ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘T’ (10), ‘J’ (jack), ‘Q’ (queen), ‘K’ (king), and ‘A’ (ace). The suit is represented by one of the following characters: ‘S’ (spades), ‘H’ (hearts), ‘D’ (diamonds), and ‘C’ (clubs).
You should assume the cards have been dealt out by the west player. Thus the first trick is led by the north player. Also, the input does not contain any illegal plays.
The input is terminated by a line with “#”. This is not part of any dataset and thus should not be processed.
Output
For each dataset, print the winner and their score of the deal in a line, with a single space between them as a separator. The winner should be either “NS” (the north-south team) or “EW” (the east-west team). No extra character or whitespace should appear in the output.
Examples
Input
H
4C 8H QS 5D JD KS 8S AH 6H 7H 3S 7S 6D
TC JC JS KD AC QC QD 2H QH 3H 3C 7C 4D
6C 9C AS TD 5H 6S 5S KH TH AD 9S 8D 2D
8C 5C 2S 7D KC 4S TS JH 4H 9H 2C 9D 3D
D
8D 9D 9S QS 4H 5H JD JS 9H 6S TH 6H QH
QD 9C 5S 7S 7H AC 2D KD 6C 3D 8C TC 7C
5D QC 3S 4S 3H 3C 6D KS JC AS 5C 8H TS
4D 4C 8S 2S 2H KC TD JH 2C AH 7D AD KH
#
Output
EW 1
EW 2
Input
H
4C 8H QS 5D JD KS 8S AH 6H 7H 3S 7S 6D
TC JC JS KD AC QC QD 2H QH 3H 3C 7C 4D
6C 9C AS TD 5H 6S 5S KH TH AD 9S 8D 2D
8C 5C 2S 7D KC 4S TS JH 4H 9H 2C 9D 3D
D
8D 9D 9S QS 4H 5H JD JS 9H 6S TH 6H QH
QD 9C 5S 7S 7H AC 2D KD 6C 3D 8C TC 7C
5D QC 3S 4S 3H 3C 6D KS JC AS 5C 8H TS
4D 4C 8S 2S 2H KC TD JH 2C AH 7D AD KH
Output
EW 1
EW 2 | instruction | 0 | 17,645 | 19 | 35,290 |
"Correct Solution:
```
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10
#solve
def solve():
n = input().rstrip()
if n == "#":
return False
lis = [LS() for i in range(4)]
num = ["2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"]
ans = [0] * 4
master = 0
for i in range(13):
north, east, south, west = lis[0][i], lis[1][i], lis[2][i], lis[3][i]
suit = [north[1], east[1], south[1], west[1]]
tmp = [num.index(lis[master][i][0]), master]
if n in suit:
tmp = [-1, -1]
for k in range(4):
if suit[k] == n:
if tmp[0] < num.index(lis[k][i][0]):
tmp = [num.index(lis[k][i][0]), k]
else:
for k in range(4):
if suit[tmp[1]] == suit[k] and tmp[0] < num.index(lis[k][i][0]):
tmp = [num.index(lis[k][i][0]), k]
ans[tmp[1]] += 1
master = tmp[1]
a = ans[0] + ans[2] - 6
b = ans[1] + ans[3] - 6
if a > b:
print("NS {}".format(a))
else:
print("EW {}".format(b))
return True
#main
if __name__ == '__main__':
while solve():
pass
``` | output | 1 | 17,645 | 19 | 35,291 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.