TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times:    * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written.  Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.

Submission attempts (in order):
import math

import math
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
g = A.pop()
for a in A:
    g = math.gcd(g, a)

N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]


def gcd(x, y):
    if x < y:
        return gcd(y, x)
    elif y == 0:
        return x
    else:
        return gcd(y, x % y)


g = A[0]
for a in A:
    g = gcd(g, a)
if K <= max(A) and K % g == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times:    * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written.  Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.

Submission attempts (in order):
n,k=map(int,input().split())
a=list(map(int,input().split()))
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

if n==1:
  x=a[0]
else:
  x=gcd(a[0],a[1])
  for i in range(2,n):
    x=gcd(x,a[i])

if max(a)>=k and k%g==0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

n,k=map(int,input().split())
a=list(map(int,input().split()))
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

if n==1:
  x=a[0]
else:
  x=gcd(a[0],a[1])
  for i in range(2,n):
    x=gcd(x,a[i])

if max(a)>=k and k%x==0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Verdicts: Runtime Error

Accepted
Problem: There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times:    * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written.  Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.

Submission attempts (in order):
N, K = map(int, input().split())
A = list(map(int, input().split()))

P = "POSSIBLE"
IP = "IMPOSSIBLE"

A.sort()

def gcd(a, b):
    if a == 0:
        return b
    else:
        gcd(b, b%a)

t = gcd(A[1], A[0])
if N <= 2:
    for a in A[2:]:
        t = gcd(t, a)

if K%t == 0 and K <= M:
    print(P)
else:
    print(IP)

N, K = map(int, input().split())
A = list(map(int, input().split()))

P = "POSSIBLE"
IP = "IMPOSSIBLE"

M = max(A)

def gcd(a, b):
    if a == 0:
        return b
    else:
        return gcd(b%a, a)

t = gcd(A[0], A[0])
if N > 1:
    for a in A[1:]:
        t = gcd(t, a)

if K%t == 0 and K <= M:
    print(P)
else:
    print(IP)

Verdicts: Runtime Error

Accepted
Problem: There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times:    * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written.  Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.

Submission attempts (in order):
def gcd(a,b) :
    while b :
        a,b = b, a % b
    return a

N,K = map(int,input().split())
L = list(map(int,input().split()))

p = 10**9
for i in range(N-1) :
    q = gcd(L[i],L[i+1])
    if q < p :
        p = q

if (K % p ==  0) and (K <= max(L))
    ans = "POSSIBLE"
else :
    ans = "IMPOSSIBLE"
print(ans)


def gcd(a,b) :
    while b :
        a,b = b, a % b
    return a

N,K = map(int,input().split())
L = list(map(int,input().split()))

if len(L) == 1 :
    if L[0] == K :
        ans = "POSSIBLE"
    else :
        ans = "IMPOSSIBLE"

else :
    for i in range(N-1) :
        q = gcd(L[i],L[i+1])
        if i == 0 :
            p = gcd(L[i],L[i+1])
        if q < p :
            p = q

    if (K % p ==  0) and (K <= max(L)) :
        ans = "POSSIBLE"
    else :
        ans = "IMPOSSIBLE"
print(ans)


Verdicts: Runtime Error

Accepted
Problem: There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times:    * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written.  Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.

Submission attempts (in order):
n,k=map(int,input().split())
l=soted(map(int,input().split()))
def gcd(x,y):
  if y==0:return x
  return gcd(y,x%y)
ans=""
s=0
for i in l:
  s=gcd(i,s)
  if s==1:break
else:
  if k%s!=l[-1]%s:
    ans="IM"
print(ans+"POSSIBLE")

n,k=map(int,input().split())
l=soted(list(map(int,input().split())))
def gcd(x,y):
  if y==0:return x
  return gcd(y,x%y)
ans=""
s=0
for i in l:
  s=gcd(i,s)
  if s==1:break
else:
  if k%s!=l[-1]%s:
    ans="IM"
print(ans+"POSSIBLE")


n,k=map(int,input().split())
l=sorted(map(int,input().split()))
def gcd(x,y):
  if y==0:return x
  return gcd(y,x%y)
ans=""
s=0
for i in l:
  s=gcd(i,s)
  if s==1:break
else:
  if k%s!=l[-1]%s:
    ans="IM"
if l[-1]<k:ans="IM"
print(ans+"POSSIBLE")


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times:    * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written.  Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.

Submission attempts (in order):
from functools import reduce
n,k=map(int,input().split())
a=list(map(int,input().split()))
def gcd(a, b):
    while a != 0:
        a,b=b%a,a
    return b
def lcm(x, y):
    return (x * y)//gcd(x, y)
t=reduce(lcm,a)
if t==1:
    if max(a)>=k:
        print('POSSIBLE')
        exit()
else:
    if k in a:
        print('POSSIBLE')
        exit()
    if k%t==0:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')


from functools import reduce
n,k=map(int,input().split())
a=list(map(int,input().split()))
def gcd(a, b):
    while a != 0:
        a,b=b%a,a
    return b
def lcm(x, y):
    return (x * y)//gcd(x, y)
t=reduce(gcd,a)
if t==1:
    if max(a)>=k:
        print('POSSIBLE')
        exit()
else:
    if k in a:
        print('POSSIBLE')
        exit()
    if k%t==0 and max(a)>=k:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')


Verdicts: Wrong Answer

Accepted
Problem: There is a box containing N balls. The i-th ball has the integer A_i written on it. Snuke can perform the following operation any number of times:    * Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written.  Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written.

Submission attempts (in order):
def gcd(a, b):
    return gcd(b, a % b) if b > 0 else a


n, k = map(int, input().split())
a = list(map(int, input().split())
        
m = max(a)
         
g = a[0]
         
for i in range(n):
    g = gcd(g, a[i])

if k > m:
    print("IMPOSSIBLE")
elif k % g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")



from fractions import gcd

n,k = map(int, input().split())
a = list(map(int, input().split())
         
m = max(a)
         
g = a[0]
         
for i in range(n):
    g = gcd(g, a[i])

if k>m:
    print("IMPOSSIBLE")
elif k % g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


def gcd(a, b):
    return gcd(b, a % b) if b > 0 else a


n, k = map(int, input().split())
a = list(map(int, input().split()))

m = max(a)

g = a[0]

for i in range(n):
    g = gcd(g, a[i])

if k > m:
    print("IMPOSSIBLE")
elif k % g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.  Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.  Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.

Submission attempts (in order):
from collections import Counter
N, M = map( int, input().split())
A = [ [] for _ in range(N)]
for i in range(N):
    A[i] = list( map( int, input().split())) 
V = [1]*(M+1)
ans = N
for _ in range(M-1):
    W = []
    for i in range(N):
        while A[i]:
            a = A[i].pop(0)
            if V[a] == 1:
                W.append(a)
    if not W:
        break
    a, c = Counter(W).most_common()[0]
    ans = min( ans, c)
    V[a] = 0
print(ans)

from collections import Counter
N, M = map( int, input().split())
A = [ [] for _ in range(N)]
for i in range(N):
    A[i] = list( map( int, input().split())) 
V = [1]*(M+1)
ans = N
for _ in range(M-1):
    W = []
    for i in range(N):
        while True:
            if V[A[i][0]] == 1:
                W.append(A[i][0])
                break
            else:
                A[i].pop(0)
    a, c = Counter(W).most_common()[0]
    ans = min( ans, c)
    V[a] = 0
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.  Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.  Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.

Submission attempts (in order):
n,m=map(int,input().split())
k=[[0]*m for i in range(n)]
for i in range(n):
    k[i]=list(map(int,input().split()))
ans=1000
for i in range(m-1):
    ma=[0]*m
    mi=-1
    for j in range(n):
        ma[k[j][0]]+=1
    if ans>max(ma):
        ans=max(ma)
    mi=ma.index(max(ma))+1
    for j in range(n):
        k[j].remove(mi)
print(ans)
        


n,m=map(int,input().split())
k=[[0]*m for i in range(n)]
for i in range(n):
    k[i]=list(map(int,input().split()))
ans=1000
for i in range(m-1):
    ma=[0]*m
    mi=-1
    for j in range(n):
        ma[k[j][0]-1]+=1
    if ans>max(ma):
        ans=max(ma)
    mi=ma.index(max(ma))+1
    for j in range(n):
        k[j].remove(mi)
if m==1:
    print(n)
else:
    print(ans)
        


Verdicts: Runtime Error

Accepted
Problem: Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.  Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.  Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.

Submission attempts (in order):
n, m = map(int, input().split())
prefers = [list(reversed(list(map(int, input().split())))) for _ in range(n)]
items = [True] * (m + 1)
competes = {i: 0 for i in range(1, m + 1)}
persons = [set() for _ in range(m + 1)]

for i, ps in enumerate(prefers):
    item = ps[-1]
    competes[item] += 1
    persons[item].add(i)

ans = m
remain = m
while remain:
    mx = max(competes.values())
    ans = min(ans, mx)
    del_items = [a for a, k in competes.items() if k == mx]
    for a in del_items:
        items[a] = False
        del competes[a]
    for a in del_items:
        pa = persons[a]
        for p in pa:
            pf = prefers[p]
            while not items[pf[-1]]:
                pf.pop()
            item = pf[-1]
            persons[item].add(p)
            competes[item] += 1
    remain -= 1

print(ans)


from collections import defaultdict
from operator import itemgetter


def sub(prefers, canceled):
    res = defaultdict(int)
    for pref in prefers:
        p = pref[-1]
        while p in canceled:
            pref.pop()
            p = pref[-1]
        res[p] += 1

    return max(res.items(), key=itemgetter(1))


def solve(m, prefers):
    canceled = set()
    ans = float('inf')
    for _ in range(m):
        s, c = sub(prefers, canceled)
        canceled.add(s)
        ans = min(ans, c)
    return ans


n, m = map(int, input().split())
prefers = [list(reversed(list(map(int, input().split())))) for _ in range(n)]

print(solve(m, prefers))


Verdicts: Runtime Error

Accepted
Problem: Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.  Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.  Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.

Submission attempts (in order):
N, M = map(int, input().split())
A = [[0 for _ in range(M)] for _ in range(N)]
for i in range(N):
  A[i] = [int(x) - 1 for x in input().split()]
S = [[0, i] for i in range(M)]
for a in A:
  S[a[0]][0] += 1
minmax = N
for _ in range(M - 1):
  _S = sorted(S, reverse=True)
  s = _S[0][1]
  minmax = min(S[s][0], minmax)
  S[s][0] = -1
  for a in A:
    while S[a[0]][0] < 0:
      a.pop(0)
    S[a[0]][0] += 1
print(minmax)

N, M = map(int, input().split())
A = [[0 for _ in range(M)] for _ in range(N)]
for i in range(N):
  A[i] = [int(x) - 1 for x in input().split()]
S = [[0, i] for i in range(M)]
for a in A:
  S[a[0]][0] += 1
minmax = N
for _ in range(M - 1):
  _S = sorted(S, reverse=True)
  s = _S[0][1]
  minmax = min(S[s][0], minmax)
  S[s][0] = -1
  for a in A:
    if S[a[0]][0] > 0:
      continue
    while S[a[0]][0] < 0:
      a.pop(0)
    S[a[0]][0] += 1
print(minmax)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.  Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.  Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.

Submission attempts (in order):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
    a[i].reverse()

ans = n
used = set()
for i in range(m):
    count = [0]*(m+1)
    for j in range(n):
        count[a[j][-1]] += 1

    ans = min(max(count), ans)
    num = count.index(max(count))
    used.add(num)
    for j in range(n):
        while True:
            if a[j][-1] in used:
                a[j].pop()
            else:
                break

print(ans)


n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
    a[i].reverse()

ans = n
used = set()
for i in range(m):
    count = [0]*(m+1)
    for j in range(n):
        count[a[j][-1]] += 1

    ans = min(max(count), ans)
    num = count.index(max(count))
    used.add(num)
    for j in range(n):
        if a[j][-1] in num:
            a[j].pop()

print(ans)


n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
    a[i].reverse()

ans = n
used = set()
for i in range(m):
    count = [0]*(m+1)
    for j in range(n):
        count[a[j][-1]] += 1

    ans = min(max(count), ans)
    num = count.index(max(count))
    used.add(num)
    for j in range(n):
        while len(a[j]) > 0:
            if a[j][-1] in used:
                a[j].pop()
            else:
                break

print(ans)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.  Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.  Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.

Submission attempts (in order):
N,M=map(int, input().split())
A=[]
for i in range(N):
  d=list(map(int, input().split()))
  A.append(d)
num=[0]*N
ans=M
S=set()
for i in range(M-1):
  cnt=[0]*M
  for j in range(N):
    for k in range(M):
      d=A[j][k]-1
      if d in S:
        continue
      else:
        cnt[d]+=1
  e=max(cnt)
  ans=min(e,ans)
  f=cnt.index(e)
  S.add(f)
print(ans)


N,M=map(int, input().split())
A=[]
for i in range(N):
  d=list(map(int, input().split()))
  A.append(d)
S=[1]*M
num=[0]*N
ans=N
for i in range(M):
  cnt=[0]*M
  for j in range(N):
    d=A[j][num[j]]
    while S[d-1]==0:
      num[j]+=1
      d=A[j][num[j]]
    cnt[d-1]+=1
  e=max(cnt)
  ans=min(e,ans)
  f=cnt.index(e)
  S[f]=0
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.  Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.  Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.

Submission attempts (in order):
def dfs(people, sports, use_sports, answer):
    rank = [0 for n in range(sports)]
    for p in range(people):
        for s in (preference[p]):
            if s in use_sports:
                rank[s] += 1
                break
            will_delete = []
    max_p = max(rank)
    exclude = rank.index(max_p)
    answer = min(answer, max_p, dfs(people, sports, use_sports - {exclude}, answer))
    return answer

people, sports = (int(n) for n in input().split(" "))
preference = []
for _ in range(people):
    pre = [int(n) for n in input().split(" ")]
    preference.append(pre)
answer = float("inf")
use_sports = {n for n in range(sports)}
print(dfs(people, sports, use_sports, answer))


people, sports = (int(n) for n in input().split(" "))
preference = []
for _ in range(people):
    pre = [int(n) - 1 for n in input().split(" ")]
    preference.append(pre)
answer = float("inf")
use_sports = {n for n in range(sports)}
for _ in range(sports):
    rank = [0 for n in range(sports)]
    for p in range(people):
        for s in (preference[p]):
            if s in use_sports:
                rank[s] += 1
                break
    answer = min(answer, max(rank))
    use_sports -= {rank.index(max(rank))}
print(answer)

Verdicts: Runtime Error

Accepted
Problem: Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.  Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.  Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.

Submission attempts (in order):
from collections import Counter
from operator import itemgetter

def sub(prefers, canceled):
    res = Counter()
    for pref in prefers:
       p = pref[-1]
        while p in canceled:
            pref.pop()
            p = pref[-1]
        res[p] += 1
    return max(res.items(), key=itemgetter(1))

def solve(m, prefers):
    canceled = set()
    ans = float('inf')
    for _ in [0] * m:
        s, c = sub(prefers, canceled)
        canceled.add(s)
        ans = min(ans, c)
    return ans

if __name__ == '__main__':
    N, M = map(int, input().split())
    A = [list(map(int, input().split()))[::-1] for _ in [0] * N]
    print(solve(M, A))

from collections import Counter
from operator import itemgetter

def sub(prefers, canceled):
    res = Counter()
    for pref in prefers:
        p = pref[-1]
        while p in canceled:
            pref.pop()
            p = pref[-1]
        res[p] += 1
    return max(res.items(), key=itemgetter(1))

def solve(m, prefers):
    canceled = set()
    ans = float('inf')
    for _ in [0] * m:
        s, c = sub(prefers, canceled)
        canceled.add(s)
        ans = min(ans, c)
    return ans

if __name__ == '__main__':
    N, M = map(int, input().split())
    A = [list(map(int, input().split()))[::-1] for _ in [0] * N]
    print(solve(M, A))

Verdicts: Runtime Error

Accepted
Problem: Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi will select one or more sports (possibly all) to be played in the event.  Takahashi knows that Person i's j-th favorite sport is Sport A_{ij}. Each person will only participate in his/her most favorite sport among the ones that are actually played in the event, and will not participate in the other sports.  Takahashi is worried that one of the sports will attract too many people. Therefore, he would like to carefully select sports to be played so that the number of the participants in the sport with the largest number of participants is minimized. Find the minimum possible number of the participants in the sport with the largest number of participants.

Submission attempts (in order):
N,M=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
ans=N
s=set()
for i in range(M-1):
  d=[0]*M
  for j in range(N):
    for k in range(M):
      if A[j][k]-1 in s:
        continue
      else:
        d[A[j][k]-1]+=1
  ans=min(ans,max(d))
  s.add(d.index(max(d)))
print(ans)
  

def main():
  import sys
  input=sys.stdin.buffer.readline
  N,M=map(int,input().split())
  A=[list(map(int,input().split())) for i in range(N)]
  ans=N
  s=set()
  for i in range(M-1):
    d=[0]*M
    for j in range(N):
      for k in range(M):
        if A[j][k]-1 in s:
          continue
        else:
          d[A[j][k]-1]+=1
          break
    ans=min(ans,max(d))
    s.add(d.index(max(d)))
  print(ans)
main()
  


Verdicts: Wrong Answer

Accepted
Problem: Fennec and Snuke are playing a board game.  On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree.  Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn:    * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**.   * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**.  A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.

Submission attempts (in order):
N=int(input())
from collections import defaultdict,deque
branch=defaultdict(set)
for i in range(N-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    branch[a]|={b}
    branch[b]|={a}
check={0}
bef=[-2]*N
bef[0]=-1
dist=[float('inf')]*N
dist[0]=0
while len(check)>0:
    now=check.pop()
    for nex in branch[now]:
        if bef[nex]==-2:
            bef[nex]=now
            check|={nex}
            dist[nex]=dist[now]+1
print("NO")
exit()

N=int(input())
from collections import defaultdict,deque
branch=defaultdict(set)
for i in range(N-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    branch[a]|={b}
    branch[b]|={a}
check={0}
path=[0]*N
path[0]=[0]
while len(check)>0:
    x=check.pop()
    for nex in branch[x]:
        if path[nex]==0:
            check|={nex}
            path[nex]=path[x]+[nex]
print("NO")
exit()
G=path[N-1]
ng=G[(len(G)+1)//2]
cnt=0
for i in range(N):
    if ng not in path[i]:
        cnt+=1
if cnt>N-cnt:
    print("Fennec")
else:
    print("Snuke")

N=int(input())
from collections import defaultdict,deque
branch=defaultdict(set)
for i in range(N-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    branch[a]|={b}
    branch[b]|={a}
check={0}
bef=[-2]*N
bef[0]=-1
dist=[float('inf')]*N
dist[0]=0
while len(check)>0:
    now=check.pop()
    for nex in branch[now]:
        if bef[nex]==-2:
            bef[nex]=now
            check|={nex}
            dist[nex]=dist[now]+1
NG=set()
OK={0}
now=N-1
checked={0}
for i in range((1+dist[N-1])//2):
    NG|={now}
    now=bef[now]
checked|=NG
for i in range(N):
    if i in checked:
        continue
    else:
        visited={i}
        now=i
        while True:
            now=bef[now]
            visited|={now}
            if now in NG:
                NG|=visited
                checked|=visited
                break
            elif now in OK:
                OK|=visited
                checked|=visited
                break
if len(OK)>N//2:
    print("Fennec")
else:
    print("Snuke")

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Fennec and Snuke are playing a board game.  On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree.  Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn:    * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**.   * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**.  A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.

Submission attempts (in order):
ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]

n = int(input())

path = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = ai_()
    path[a].append(b)
    path[b].append(a)

from collections import deque
q = deque()
q.append(0)

d1 = [float('inf') for _ in range(n)]
d1[0] = 0
c = 0
w = set()
while q:
    c += 1
    v = q.popleft()
    w.add(v)
    for vv in path[v]:
        if vv not in w:
            d1[vv] = c
            q.append(vv)


q = deque()
q.append(n-1)

dn = [float('inf') for _ in range(n)]
dn[n-1] = 0
c = 0
w = set()
while q:
    c += 1
    v = q.popleft()
    w.add(v)
    for vv in path[v]:
        if vv not in w:
            dn[vv] = c
            q.append(vv)


print(d1,dn)
d = [1 if d1[v] >= dn[v] else 0 for v in range(n)]

if d.count(1) > d.count(0):
    print('Snuke')
else:
    print('Fennec')


ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]

n = int(input())

path = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = ai_()
    path[a].append(b)
    path[b].append(a)

from collections import deque
q = deque()
q.append(0)

d1 = [float('inf') for _ in range(n)]
d1[0] = 0
w = set()
while q:
    v = q.popleft()
    w.add(v)
    for vv in path[v]:
        if vv not in w:
            d1[vv] = d1[v] + 1
            q.append(vv)


q = deque()
q.append(n-1)

dn = [float('inf') for _ in range(n)]
dn[n-1] = 0
w = set()
while q:
    v = q.popleft()
    w.add(v)
    for vv in path[v]:
        if vv not in w:
            dn[vv] = dn[v] + 1
            q.append(vv)


d = [1 if d1[v] <= dn[v] else -1 for v in range(n)]

if sum(d) > 0:
    print('Fennec')
else:
    print('Snuke')


Verdicts: Wrong Answer

Accepted
Problem: Fennec and Snuke are playing a board game.  On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree.  Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn:    * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**.   * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**.  A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.

Submission attempts (in order):
n=int(input())
tree=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  tree[a-1].append(b-1)
  tree[b-1].append(a-1)
def dist(k):
  l=[-1]*n
  node=[k]
  while node:
    s=node.pop()
    d=l[s]
    for t in tree[s]:
      if l[t]!=-1:
        continue
      l[t]=d+1
      node.append(t)
  return l
from_fennec=dist(0)
from_snuke=dist(n-1)
res=0
for i,j in zip(from_fennec,from_snuke):
  if i>=j:
    res+=1
  else:
    res-=1
print('Snuke' if res>=0 else 'Fennec')

n=int(input())
tree=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  tree[a-1].append(b-1)
  tree[b-1].append(a-1)
def dist(k):
  l=[-1]*n
  node=[k]
  while node:
    s=node.pop()
    d=l[s]
    for t in tree[s]:
      if l[t]!=-1:
        continue
      l[t]=d+1
      node.append(t)
  return l
from_fennec=dist(0)
from_snuke=dist(n-1)
res=0
for i,j in zip(from_fennec,from_snuke):
  if i<=j:
    res+=1
  else:
    res-=1
print('Snuke' if res<=0 else 'Fennec')

Verdicts: Wrong Answer

Accepted
Problem: Fennec and Snuke are playing a board game.  On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree.  Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn:    * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**.   * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**.  A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.

Submission attempts (in order):
N=int(input())
import sys
ab=[list(map(int, input().split())) for _ in range (N-1)]
con=[[] for _ in range(N+1)]

#print(ab)
for a,b in ab :
  con[a].append(b)
  con[b].append(a)


pc=[0]*(N+1)
q=[(1,0)]
vis=[False]*(N+1)
vis[1]=True
Fcnt=N
while q:
  n,c=q.pop()
  pc[n]=c
  for ch in con[n]:
    if vis[ch]==True:
      continue
    q.append((ch,c+1))
    
q=[(N,0)]
vis=[False]*(N+1)
vis[1]=True
while q:
  n,c=q.pop()
  if pc[n]>c:
    Fcnt-=1
  for ch in con[n]:
    if vis[ch]==True:
      continue
    q.append((ch,c+1))
    
if Fcnt>N-Fcnt:
  print("Fennec")
else:
  print("Snuke")


N=int(input())
import sys
ab=[[int(j) for j in sys.stdin.readline()] for _ in range (N-1)]
con=[[] for _ in range(N+1)]

for a,b in ab :
  con[a].append(b)
  con[b].append(a)


pc=[0]*(N+1)
q=[(1,0)]
vis=[False]*(N+1)
vis[1]=True
Fcnt=N
while q:
  n,c=q.pop()
  pc[n]=c
  for ch in con[n]:
    if vis[ch]==True:
      continue
    q.append((ch,c+1))
    
q=[(N,0)]
vis=[False]*(N+1)
vis[1]=True
while q:
  n,c=q.pop()
  if pc[n]>c:
    Fcnt-=1
  for ch in con[n]:
    if vis[ch]==True:
      continue
    q.append((ch,c+1))
    
if Fcnt>N-Fcnt:
  print("Fennec")
else:
  print("Snuke")

N=int(input())

import sys
sys.setrecursionlimit(10**5)
ab=[list(map(int, input().split())) for _ in range (N-1)]
con=[[] for _ in range(N+1)]

#print(ab)
for a,b in ab :
  con[a].append(b)
  con[b].append(a)


pc=[0]*(N+1)
q=[(1,0)]
vis=[False]*(N+1)
vis[1]=True
Fcnt=N
while q:
  n,c=q.pop()
  pc[n]=c
  for ch in con[n]:
    if vis[ch]==True:
      continue
    vis[ch]=True
    q.append((ch,c+1))
    
q=[(N,0)]
vis=[False]*(N+1)
vis[N]=True
while q:
  n,c=q.pop()
  if pc[n]>c:
    Fcnt-=1
  for ch in con[n]:
    if vis[ch]==True:
      continue
    vis[ch]=True
    q.append((ch,c+1))
    
if Fcnt>N-Fcnt:
  print("Fennec")
else:
  print("Snuke")


Verdicts: Time Limit Exceeded

Runtime Error

Accepted
Problem: Fennec and Snuke are playing a board game.  On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree.  Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn:    * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**.   * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**.  A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.

Submission attempts (in order):
import sys
sys.setrecursionlimit(2000000)
n = int(input())
p = []
for i in range(n-1):
    p.append(list(map(int, input().split()))+ [1])
l = [[] for i in range(n+1)]
for pi in p: 
    l[pi[0]].append([pi[0],pi[1]])
    l[pi[1]].append([pi[1],pi[0]])
kyo = [float("inf")]*(n+1)
kyo[1] = 0
memo = [0] * (n+1)
memo[1] = 1
ruto = []
def dfs(start,ruto):
  ruto.extend(l[start])
  memo[start] = 1
  while ruto:
    a = ruto.pop()
    if memo[a[1]] == 1:
      continue
    kyo[a[1]] = kyo[a[0]] + 1
    dfs(a[1],ruto)
  return
dfs(1,ruto)

nkyo = [float("inf")]*(n+1)
nkyo[n] = 0
memo = [0] * (n+1)
memo[n] = 1
ruto = []
def dfs(start,ruto):
  ruto.extend(l[start])
  memo[start] = 1
  while ruto:
    a = ruto.pop()
    if memo[a[1]] == 1:
      continue
    nkyo[a[1]] = nkyo[a[0]] + 1
    dfs(a[1],ruto)
  return
dfs(n,ruto)
iti = 0
nko = 0
for i in range(1,n+1):
  if kyo[i] <= nkyo[i]:
    iti += 1
  else:
    nko += 1
print(kyo,nkyo)
if iti <= nko:
  print("Snuke")
else:
  print("Fennec")

import sys
sys.setrecursionlimit(2000000)
n = int(input())
p = []
for i in range(n-1):
    p.append(list(map(int, input().split()))+ [1])
l = [[] for i in range(n+1)]
for pi in p: 
    l[pi[0]].append([pi[0],pi[1]])
    l[pi[1]].append([pi[1],pi[0]])
kyo = [float("inf")]*(n+1)
kyo[1] = 0
memo = [0] * (n+1)
memo[1] = 1
ruto = []
def dfs(start,ruto):
  ruto.extend(l[start])
  memo[start] = 1
  while ruto:
    a = ruto.pop()
    if memo[a[1]] == 1:
      continue
    kyo[a[1]] = kyo[a[0]] + 1
    dfs(a[1],ruto)
  return
dfs(1,ruto)

nkyo = [float("inf")]*(n+1)
nkyo[n] = 0
memo = [0] * (n+1)
memo[n] = 1
ruto = []
def dfs(start,ruto):
  ruto.extend(l[start])
  memo[start] = 1
  while ruto:
    a = ruto.pop()
    if memo[a[1]] == 1:
      continue
    nkyo[a[1]] = nkyo[a[0]] + 1
    dfs(a[1],ruto)
  return
dfs(n,ruto)
iti = 0
nko = 0
for i in range(1,n+1):
  if kyo[i] <= nkyo[i]:
    iti += 1
  else:
    nko += 1
if iti <= nko:
  print("Snuke")
else:
  print("Fennec")

Verdicts: Wrong Answer

Accepted
Problem: Fennec and Snuke are playing a board game.  On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree.  Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn:    * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**.   * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**.  A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.

Submission attempts (in order):
n = int(input())
edges = [[] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

def bfs(v):
    q = []
    depth = [n]*n
    q.append(v)
    depth[v] = 0
    i = 0
    while i < len(q):
        x = q[i]
        d = depth[x]
        for e in edges[x]:
            if depth[e] == n:
                depth[e] = d+1
                q.append(e)
        i += 1
    return depth

d1 = bfs(0)
d2 = bfs(n-1)

c = 0
for i in range(n):
    if d1[i] <= d2[i]:
        c += 1
print(c)
if 2*c > n:
    print("Fennec")
else:
    print("Sunuke")


n = int(input())
edges = [[] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

def bfs(v):
    q = []
    depth = [n]*n
    q.append(v)
    depth[v] = 0
    i = 0
    while i < len(q):
        x = q[i]
        d = depth[x]
        for e in edges[x]:
            if depth[e] == n:
                depth[e] = d+1
                q.append(e)
        i += 1
    return depth

d1 = bfs(0)
d2 = bfs(n-1)

c = 0
for i in range(n):
    if d1[i] <= d2[i]:
        c += 1
if 2*c > n:
    print("Fennec")
else:
    print("Snuke")


Verdicts: Wrong Answer

Accepted
Problem: There are N bags of biscuits. The i-th bag contains A_i biscuits.  Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags.  He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2. How many such ways to select bags there are?

Submission attempts (in order):
n,p=map(int,input().split())
a=list(map(int,input().split()))
c=0
for i in range(n):
  if a[i]%2==1:
    c=1
    break
if c=1:print(2**(n-1))
else:
  if p=0:print(2**(n))
  else:print(0)

n,p=map(int,input().split())
a=list(map(int,input().split()))
c=0
for i in range(n):
  if a[i]%2==1:c+=1
if c==0:
  if p==0:print(2**n)
  else:print(0)
elif c==n:
  if n!=1:print(2**(n-1))
  else:print(0)
else:print(2**(n-1))

Verdicts: Runtime Error

Accepted
Problem: There are N bags of biscuits. The i-th bag contains A_i biscuits.  Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags.  He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2. How many such ways to select bags there are?

Submission attempts (in order):
def cmb(n, k):
  s = 1
  for j in range(n - k):
    s *= j
  for j in range(1, k+1):
    s //= j
  return s

n, p = map(int, input().split())
aa = list(map(lambda x: int(x) % 2, input().split()))
odd = sum(aa)
even = n - odd
if p == 0:
  c = 2**even * sum(cmb(odd, k) for k in range(0, odd+1, 2))
  print(c)
else:
  c = 2**even * sum(cmb(odd, k) for k in range(1, odd+1, 2))
  print(c)

def cmb(n, k):
  s = 1
  for j in range(n - k + 1, n + 1, 1):
    s *= j
  for j in range(1, k+1):
    s //= j
  return s

n, p = map(int, input().split())
aa = list(map(lambda x: int(x) % 2, input().split()))
odd = sum(aa)
even = n - odd
if p == 0:
  c = 2**even * sum(cmb(odd, k) for k in range(0, odd+1, 2))
  print(c)
else:
  c = 2**even * sum(cmb(odd, k) for k in range(1, odd+1, 2))
  print(c)


Verdicts: Wrong Answer

Accepted
Problem: There are N bags of biscuits. The i-th bag contains A_i biscuits.  Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags.  He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2. How many such ways to select bags there are?

Submission attempts (in order):
import math
def AGC017C(a,f):
    p=0
    for i in range(f,a,2):
        p+=math.factorial(a)//math.factorial(a-i)//math.factorial(i)
    return p

n,p=map(int,input().split())
d={1:0,0:0}
a=list(map(int,input().split()))
for i in a:
    d[i%2]+=1
if p==0:
    print((2**d[0])*AGC017C(d[1]),0)
else:
    if d[1]==0:
        print(0)
    else:
        print((2**d[0])*(AGC017C(d[1],1)))

import math
def AGC017C(a,f):
    p=0
    for i in range(f,a,2):
        p+=math.factorial(a)//math.factorial(a-i)//math.factorial(i)
    return p

n,p=map(int,input().split())
d={1:0,0:0}
a=list(map(int,input().split()))
for i in a:
    d[i%2]+=1
print(d)
print(AGC017C(2,0))
if p==0:
    print((2**d[0])*AGC017C(d[1]),0)
else:
    if d[1]==0:
        print(0)
    else:
        print((2**d[0])*(AGC017C(d[1],1)))

import math
def AGC017C(a,f):
    p=0
    for i in range(f,a+1,2):
        p+=math.factorial(a)//math.factorial(a-i)//math.factorial(i)
    return p

n,p=map(int,input().split())
d={1:0,0:0}
a=list(map(int,input().split()))
for i in a:
    d[i%2]+=1
if p==0:
    print((2**d[0])*AGC017C(d[1],0))
else:
    if d[1]==0:
        print(0)
    else:
        print((2**d[0])*(AGC017C(d[1],1)))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There are N bags of biscuits. The i-th bag contains A_i biscuits.  Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags.  He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2. How many such ways to select bags there are?

Submission attempts (in order):

def main():
    n, p = tuple(map(int, input().rstrip().split()))
    A = tuple(map(lambda x: int(x) % 2, input().rstrip().split()))
    if sum(A) == n:  # all numbers are even
        print(2 ** n if p == 0 else 0)
    else:
        print(2 ** (n - 1))


if __name__ == "__main__":
    main()


def main():
    N, P, *A = map(int, open(0).read().split())
    total = sum(i % 2 for i in A)
    if total == 0:  # all numbers are even
        flg = P == 0
        print(2 ** N if flg else 0)
    else:
        print(2 ** (N - 1))


if __name__ == "__main__":
    main()

Verdicts: Wrong Answer

Accepted
Problem: There are N bags of biscuits. The i-th bag contains A_i biscuits.  Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags.  He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2. How many such ways to select bags there are?

Submission attempts (in order):
N,P = int(input())
A = [int(x) for x in input().split()]

odd = sum(x&1 for x in A)

if odd:
  
  answer = 2**(N-1)
else:
  answer = (2 ** N) * P

print(answer)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, P, *A = map(int, read().split())

A = [x & 1 for x in A]

if A.count(1):
    x = pow(2, N - 1)
else:
    x = pow(2, N)
    if P:
        x = 0
print(x)

Verdicts: Runtime Error

Accepted