TnT/Multi_CodeNet4Repair huggingface dataset:
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
import itertools

N,P = [int(i) for i in input().split(" ")]
A = [int(i) for i in input().split(" ")]
k = 0
for i in range(N):
    if int(A[i] % 2) == P:
        k += 1

if k == 0:
    if P == 0:
        tmp = 0
        i = 0
        while i < N-k:
            tmp += int(math.factorial(N-k)/(math.factorial(N-k-i)*math.factorial(i)))
            i += 2
        print(tmp)
    elif P == 1:
        print(0)
else:
    tmp = 0
    i = 0
    while i < N-k:
        tmp += int(math.factorial(N-k)/(math.factorial(N-k-i)*math.factorial(i)))
        i += 2
    print(pow(2,k)*tmp)

import math
import itertools

N,P = [int(i) for i in input().split(" ")]
A = [int(i) for i in input().split(" ")]
k = 0
for i in range(N):
    if int(A[i] % 2) == P:
        k += 1

if k == 0:
    if P == 0:
        tmp = 0
        i = 0
        while i < N-k:
            tmp += int(math.factorial(N-k)/(math.factorial(N-k-i)*math.factorial(i)))
            i += 2
        print(tmp)
    elif P == 1:
        print(0)
else:
    tmp = 0
    i = 0
    while i <= N-k:
        tmp += int(math.factorial(N-k)/(math.factorial(N-k-i)*math.factorial(i)))
        i += 2
    print(pow(2,k)*tmp)

import math
import itertools

N,P = [int(i) for i in input().split(" ")]
A = [int(i) for i in input().split(" ")]
k = 0
for i in range(N):
    if int(A[i] % 2) == P:
        k += 1

if k == 0:
    if P == 0:
        tmp = 0
        i = 0
        while i < N-k:
            tmp += int(math.factorial(N)/(math.factorial(N-i)*math.factorial(i)))
            i += 2
        print(tmp)
    elif P == 1:
        print(0)
else:
    tmp = 0
    i = 0
    while i < N-k:
        tmp += int(math.factorial(N-k)/(math.factorial(N-k-i)*math.factorial(i)))
        i += 2
    print(pow(2,k)*tmp)


import math
import itertools

N,P = [int(i) for i in input().split(" ")]
A = [int(i) for i in input().split(" ")]
k = 0
for i in range(N):
    if int(A[i] % 2) == P:
        k += 1

if k == 0:
    if P == 0:
        tmp = 0
        i = 0
        while i <= N-k:
            tmp += int(math.factorial(N-k)/(math.factorial(N-k-i)*math.factorial(i)))
            i += 2
        print(tmp)
    elif P == 1:
        print(0)
else:
    tmp = 0
    i = 0
    while i <= N-k:
        tmp += int(math.factorial(N-k)/(math.factorial(N-k-i)*math.factorial(i)))
        i += 2
    print(pow(2,k)*tmp)


Verdicts: Wrong Answer

Wrong Answer

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())
l=list(map(lambda x:int(x)%2,input().split()))
a=l.count(0)
b=l.count(1)
ans1=1
for i in range(0,a+1,2):
  ans11=1
  for j in range(a,a-i,-1):
    ans11*=j
  for j in range(1,1+i):
    ans11//=j
  ans1+=ans11
ans2=1
for i in range(p,b+1,2):
  ans21=1
  for j in range(b,b-i,-1):
    ans21*=j
  for j in range(1,1+i):
    ans21//=j
  ans2+=ans21
print(ans1*ans2)

n,p=map(int,input().split())
l=list(map(lambda x:int(x)%2,input().split()))
a=l.count(0)
b=l.count(1)
ans1=1
if not a==0:
  for i in range(0,a+1,2):
    ans11=1
    for j in range(a,a-i-1,-1):
      ans11*=j
    for j in range(1,1+i):
      ans11//=j
    ans1+=ans11
ans2=1
if not b==0:
  for i in range(p,b+1,2):
    ans21=1
    for j in range(b,b-i-1,-1):
      ans21*=j
    for j in range(1,1+i):
      ans21//=j
    ans2+=ans21
print(ans1*ans2)

n,p=map(int,input().split())
l=list(map(lambda x:int(x)%2,input().split()))
a=l.count(0)
b=l.count(1)
ans1=1
for i in range(0,a+1,2):
  ans11=1
  for j in range(a,a-i,-1):
    ans11*=j
  for j in range(1,1+i):
    ans11//=j
  ans1+=ans11
ans2=1
for i in range(p,b+1,2):
  ans21=1
  for j in range(b,b-i,-1):
    ans21*=j
  for j in range(1,1+i):
    ans21//=j
  ans2+=ans21
print(ans1+ans2)

n,p=map(int,input().split())
l=list(map(lambda x:int(x)%2,input().split()))
a,b=0,0
for i in l:
  if l%2>0:
    a+=1
  else:
    b+=1
if a==0:
  if p==0:
    print(2**n)
  else:
    print(0)
else:
  print(2**(n-1))

n,p=map(int,input().split())
l=list(map(lambda x:int(x)%2,input().split()))
a,b=0,0
for i in l:
  if i>0:
    a+=1
  else:
    b+=1
if a==0:
  if p==0:
    print(2**n)
  else:
    print(0)
else:
  print(2**(n-1))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

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):
from collections import deque

nCr = {}


def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = cmb(n-1, r) + cmb(n-1, r-1)
    return nCr[(n, r)]


N, P = map(int, input().split())
A = np.array(list(map(int, input().split())))

li = list(np.mod(A, 2))
zero = li.count(0)
one = li.count(1)

if P == 0:
    combi = [0] + [2 * x for x in range(1, (one + 2) // 2)]
if P == 1:
    combi = [1] + [2 * x + 1 for x in range(1, (one + 1) // 2)]

q = deque(combi)

right = 0
while q:
    c = q.popleft()
    tmp = cmb(one, c)
    right += tmp

print(2**zero * right)

from scipy.special import comb
from collections import deque

N, P = map(int, input().split())
A = np.array(list(map(int, input().split())))

li = list(np.mod(A, 2))
zero = li.count(0)
one = li.count(1)

if P == 0:
    combi = [0] + [2 * x for x in range(1, (one + 2) // 2)]
if P == 1:
    combi = [1] + [2 * x + 1 for x in range(1, (one + 1) // 2)]

q = deque(combi)

right = 0
while q:
    c = q.popleft()
    tmp = comb(one, c, exact=True)
    right += tmp

print(2**zero * right)

from collections import deque
from functools import lru_cache

nCr = {}


@lru_cache(maxsize=None)
def cmb(n, r):
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    if (n, r) in nCr:
        return nCr[(n, r)]
    nCr[(n, r)] = cmb(n-1, r) + cmb(n-1, r-1)
    return nCr[(n, r)]


N, P = map(int, input().split())
A = np.array(list(map(int, input().split())))

li = list(np.mod(A, 2))
zero = li.count(0)
one = li.count(1)

if P == 0:
    combi = [0] + [2 * x for x in range(1, (one + 2) // 2)]
if P == 1:
    combi = [1] + [2 * x + 1 for x in range(1, (one + 1) // 2)]

q = deque(combi)

right = 0
while q:
    c = q.popleft()
    tmp = cmb(one, c)
    right += tmp

print(2**zero * right)

n, p = map(int, input().split())
arr = list(map(int, input().split()))

a = sum([x % 2 == 1 for x in arr])
b = n - a


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p


MOD = 10**18 + 7
N = 10**6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)

start = p


ans = 0
for i in range(p, a + 1, 2):
    for j in range(b + 1):
        ans += cmb(a, i, MOD) * cmb(b, j, MOD)

print(ans)

Verdicts: Runtime Error

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 odd(n):
    return n % 2 == 1
    
def even(n):
    return n % 2 == 0

from math import factorial as fact
def c(n, r):
    if n < r:
        return 0
    if n == 0:
        return 0
    if r == 0:
        return 1
    return fact(n) // (fact(n-r) * fact(r))

n, p = map(int, input().split())
a = list(map(int, input().split()))
o = [i for i in a if odd(i)]
e = [i for i in a if even(i)]
x = len(o)
y = len(e)
yc = 0
for i in range(y):
    yc += c(y, i + 1)
ans = 0
if p == 0:
    ans += yc
i = 2 - p
while True:
    if i > x:
        break
    ans += c(x, i)
    ans += c(x, i) * yc
    i += 2
print(ans)

def odd(n):
    return n % 2 == 1
    
def even(n):
    return n % 2 == 0

from math import factorial as fact
def c(n, r):
    if n < r:
        return 0
    if n == 0:
        return 0
    if r == 0:
        return 1
    return fact(n) // (fact(n-r) * fact(r))

n, p = map(int, input().split())
a = list(map(int, input().split()))
o = [i for i in a if odd(i)]
e = [i for i in a if even(i)]
x = len(o)
y = len(e)
yc = 0
for i in range(y):
    yc += c(y, i + 1)
ans = 0
if p == 0:
    ans += 1
i = 2 - p
while True:
    if i > x:
        break
    ans += c(x, i)
    ans += c(x, i) * yc
    i += 2
if p == 0:
    ans += yc
print(ans)

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 = map(int, input().split())

odds, evens = 0, 0

for i in A:
    if i & 1:
        odds += 1
        
    else:
        evens += 1

from math import factorial

if P == 0:
    ans = 0
    fo = factorial(odds)
    for r in range(2, odds + 1, 2):
        # ncr
        ans += fo // (factorial(odds - r) * factorial(r))
    ans *= 2**evens

else:
    ans = 0
    fo = factorial(odds)
    for r in range(1, odds + 1, 2):
        # ncr
        ans += fo // (factorial(odds - r) * factorial(r))

    ans *= 2**evens
print(ans)


N, P = map(int, input().split())
A = map(int, input().split())

odds, evens = 0, 0

for i in A:
    if i & 1:
        odds += 1
        
    else:
        evens += 1

from math import factorial

if P == 0:
    ans = 0
    fo = factorial(odds)
    for r in range(0, odds + 1, 2):
        ans += fo // (factorial(odds - r) * factorial(r))
    ans *= 2**evens

else:
    ans = 0
    fo = factorial(odds)
    for r in range(1, odds + 1, 2):
        ans += fo // (factorial(odds - r) * factorial(r))

    ans *= 2**evens
print(ans)


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):
def main():
    N, P = map(int, input().split())
    *A, = map(int, input().split())

    editorial(N, P, A)

def editorial(N, P, A):
    odds = [a for a in A if a % 2 == 1]
    odd = len(odds)
    even = N - odd

    if odd == 0:
        if P = 1:
            print(0)
        else:
            print(2 ** N)
        return
    
    
    ans = 2 ** (N - 1)
    
    
    
    
    
    print(ans)


if __name__ == '__main__':
    main()


def main():
    N, P = map(int, input().split())
    *A, = map(int, input().split())

    editorial(N, P, A)

def editorial(N, P, A):
    odds = [a for a in A if a % 2 == 1]
    odd = len(odds)
    even = N - odd

    if odd == 0:
        if P == 1:
            print(0)
        else:
            print(2 ** N)
        return
    
    
    ans = 2 ** (N - 1)
    
    
    
    
    
    print(ans)


if __name__ == '__main__':
    main()


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):
import numpy as np
N, P = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(A)
A = A % 2
A = list(A)
count0 = A.count(0)
count1 = A.count(1)

print(count0, count1, P)

if P == 0 and count1 % 2 == 0:
    tmp = 2**(count1-1) * 2**count0

elif P == 0 and count1 % 2 == 1:
    tmp = 2**(count1-1) * 2**count0

elif P == 1 and count1 % 2 == 0:
    tmp = 2**(count1-1) * 2**count0

elif P == 1 and count1 % 2 == 1:
    tmp = 2**(count1-1) * 2**count0 

print(round(tmp))

import numpy as np
N, P = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(A)
A = A % 2
A = list(A)
count0 = A.count(0)
count1 = A.count(1)

#print(count0, count1, P)

if P == 0 and count1 % 2 == 0:
    tmp = max(1, 2**(count1-1)) * 2**count0

elif P == 0 and count1 % 2 == 1:
    tmp = max(1, 2**(count1-1)) * 2**count0

elif P == 1 and count1 % 2 == 0:
    tmp = max(1, 2**(count1-1))* 2**count0

elif P == 1 and count1 % 2 == 1:
    tmp = max(1, 2**(count1-1)) * 2**count0 

if count1 == 0 and P ==1:
    tmp = 0

print(round(tmp))

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):
def main():
    from operator import mul
    from functools import reduce
    def combinations_count(n, r):
        r = min(r, n - r)
        numer = reduce(mul, range(n, n - r, -1), 1)
        denom = reduce(mul, range(1, r + 1), 1)
        return numer // denom
    n, p = list(map(int, input().split()))
    A = list(map(int, input().split()))
    odd = sum([a % 2 == 1 for a in A])
    even = n - odd
    if p == 0:
        odd_sum = 0
        for i in range(0, odd + 1, 2):
            odd_sum += combinations_count(odd, i)
    else:
        if odd == 0:
            print(0)
            exit()
        else:
            odd_sum = 0
            for i in range(1, odd + 1, 2):
                odd_sum += combinations_count(odd, i)
    if even == 0:
        even_sum = 0
    else:
        even_sum = pow(2, even)
    print(even_sum * odd_sum)


if __name__ == '__main__':
    main()


def main():
    from operator import mul
    from functools import reduce
    def combinations_count(n, r):
        r = min(r, n - r)
        numer = reduce(mul, range(n, n - r, -1), 1)
        denom = reduce(mul, range(1, r + 1), 1)
        return numer // denom
    n, p = list(map(int, input().split()))
    A = list(map(int, input().split()))
    odd = sum([a % 2 == 1 for a in A])
    even = n - odd
    if p == 0:
        odd_sum = 0
        for i in range(0, odd + 1, 2):
            odd_sum += combinations_count(odd, i)
    else:
        if odd == 0:
            print(0)
            exit()
        else:
            odd_sum = 0
            for i in range(1, odd + 1, 2):
                odd_sum += combinations_count(odd, i)
    if even == 0:
        even_sum = 0
        print(odd_sum)
    else:
        even_sum = pow(2, even)
        print(even_sum * odd_sum)


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=map(int,input().split())
a=[int(i) for i in input().split()]
b=[i%2 for i in a]
ans=(2**b.count(0))*(2**(b.count(1)-1))
print((p+1)%2 if p not in b else ans)

from math import factorial as f
n,p,*a=map(int,open(0).read().split())
x=len([i for i in a if i%2])
y=n-x

xx=0
for i in range(p,x,2):
    xx+=f(x)//f(i)//f(x-i)

yy=0
for i in range(0,y):
    yy+=f(y)//f(i)//f(y-i)

print(xx*yy+xx*(p^0)+yy*(p^1))

from math import factorial as f
n,p,*a=map(int,open(0).read().split())
x=len([i for i in a if i%2])
y=n-x

xx=0
for i in range(p,x,2):
    xx+=f(x)//f(i)//f(x-i)

yy=0
for i in range(0,y):
    yy+=f(y)//f(i)//f(y-i)

if x>0 and y>0:
    print(xx*yy+xx*(p^0)+yy*(p^1))
elif x==0:
    print(yy(p^1))
else:
    print(xx)

n,p=map(int,input().split())
a=[int(i) for i in input().split()]
b=[i%2 for i in a]
ans=(2**b.count(0))*(2**(b.count(1)-1))
print(0 if p not in b else ans)

from math import factorial as f
n,p,*a=map(int,open(0).read().split())
x=len([i for i in a if i%2])
y=n-x

xx=0
for i in range(p,x,2):
    xx+=f(x)//f(i)//f(x-i)

yy=0
for i in range(0,y):
    yy+=f(y)//f(i)//f(y-i)

print(xx*yy+xx)

n,p,*a=map(int,open(0).read().split())
if len([i for i in a if i%2])==0:
    print(2**n*(p^1))
else:
    print(2**(n-1))

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

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
n,p = map(int, input().split())
aa = list(map(int, input().split()))

aa = list(map(lambda x:x%2, aa))
odd = aa.count(1)
even = aa.count(0)
ans = 2**even
# if p==1:
#     ans*=odd


pattern = 0
for i in range(p, odd+1, 2):
    print(even, odd, i, math.factorial(odd) // (math.factorial(i)*math.factorial(odd-i)))
    pattern += math.factorial(odd) // (math.factorial(i)*math.factorial(odd-i))
print(ans*pattern)

import math
n,p = map(int, input().split())
aa = list(map(int, input().split()))

aa = list(map(lambda x:x%2, aa))
odd = aa.count(1)
even = aa.count(0)
ans = 2**even
# if p==1:
#     ans*=odd


pattern = 0
for i in range(p, odd+1, 2):
    
    pattern += math.factorial(odd) // (math.factorial(i)*math.factorial(odd-i))
print(ans*pattern)

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):
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


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

even=0
odd=0
for i in a:
    if i%2 == 0:
        even+=1
    else:
        odd+=1
ans = 0
if p == 0:
    print(1<<n)

else:
    evens = 0
    i = 1
    while(i <= even):
        evens += cmb(even, i)

        i+=1

    i = 1
    while(i <= odd):
        ans += cmb(odd, i) + cmb(odd, i)*evens

        i+=2
    print(ans)

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


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

even=0
odd=0
for i in a:
    if i%2 == 0:
        even+=1
    else:
        odd+=1
ans = 0
if p == 0:
    evens = 0
    i = 1
    while(i <= even):
        evens += cmb(even, i)

        i+=1

    ans += 1<<even
    i = 2
    while(i <= odd):
        ans += cmb(odd, i) + cmb(odd, i)*evens
        i+=2

    print(ans)

else:
    evens = 0
    i = 1
    while(i <= even):
        evens += cmb(even, i)

        i+=1

    i = 1
    while(i <= odd):
        ans += cmb(odd, i) + cmb(odd, i)*evens

        i+=2
    print(ans)

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()))

for i in range(n):
    A[i]%=2
one=A.count(1)
if one==n:
    print(2**n)
else:
    print(2**(n-1))

n,p=map(int,input().split())
A=list(map(int,input().split()))

for i in range(n):
    A[i]%=2
one=A.count(1)
if one==n and p==0:
    print(2**n)
elif one==n and p==1:
    print(0)
else:
    print(2**(n-1))

n,p=map(int,input().split())
A=list(map(int,input().split()))

for i in range(n):
    A[i]%=2
zero=A.count(0)
if zero==n and p==0:
    print(2**n)
elif zero==n and p==1:
    print(0)
else:
    print(2**(n-1))

Verdicts: Wrong Answer

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())
print(2**N)


import numpy as np

N, P = map(int, input().split())
A = list(map(int, input().split()))
odd = len([i for i in A if i%2!=0])
if odd==0 and P==0:
    ans = 2**N
elif odd==0 and P==1:
    ans = 0
else:
    ans = 2**(N-1)
print(ans)

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):
from sys import stdin
from math import factorial

n,p = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))

def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

guusu = 0
kisuu = 0

for i in li:
    if i%2 == 0:
        guusu += 1
    else:
        kisuu += 1

point = 0

if p == 0:
    for i in range(guusu//2+1):
        point += combinations_count(guusu,i*2)
    for j in range(kisuu//2+1):
        point += combinations_count(kisuu,j*2)
if p == 1:
    for i in range(guusu+1):
        for j in range(kisuu//2 if kisuu%2 == 0 else kisuu//2+1):
            point += combinations_count(guusu,i)*combinations_count(kisuu,j*2+1)

print(point)

from sys import stdin
from math import factorial

n,p = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))

def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

guusu = 0
kisuu = 0

for i in li:
    if i%2 == 0:
        guusu += 1
    else:
        kisuu += 1

point = 0

if p == 0:
    for i in range(guusu//2+1):
        point += combinations_count(guusu,i*2)
    for j in range(kisuu//2+1):
        point += combinations_count(kisuu,i*2)
if p == 1:
    for i in range(guusu+1):
        for j in range(kisuu//2 if kisuu%2 == 0 else kisuu//2+1):
            point += combinations_count(guusu,i)*combinations_count(kisuu,j*2+1)

print(point)

from sys import stdin

n,p = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))

if all(i%2 == 0 for i in li):
    if p == 0:
        print(2**n)
    else:
        print(0)
else:
    print(2**(n-1))

Verdicts: Wrong Answer

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):





import math

N, P = map(int,input().strip().split(" "))
A = list(map(int,input().strip().split(" ")))

even = 0
odd = 0
for a in A:
    if a % 2 == 0:
        even += 1
    else:
        odd += 1

even_combi = 2 ** even

odd_combi = 0
m = int(odd/2)
#print("m:", m)
for i in range(m+1):
    if P == 0:
        odd_combi += math.factorial(odd) / (math.factorial(i*2) * math.factorial(odd-i*2))
    else:
        if odd-(i*2+1) > 0:
            odd_combi += math.factorial(odd) / (math.factorial(i*2+1) * math.factorial(odd-(i*2+1)))


print(even_combi*odd_combi)







import math

N, P = map(int,input().strip().split(" "))
A = list(map(int,input().strip().split(" ")))

even = 0
odd = 0
for a in A:
    if a % 2 == 0:
        even += 1
    else:
        odd += 1

even_combi = 2 ** even

odd_combi = 0
m = int(odd/2)
#print("m:", m)
for i in range(m+1):
    if P == 0:
        odd_combi += math.factorial(odd) / (math.factorial(i*2) * math.factorial(odd-i*2))
    else:
        if odd-(i*2+1) > 0:
            odd_combi += math.factorial(odd) / (math.factorial(i*2+1) * math.factorial(odd-(i*2+1)))


print(int(even_combi*odd_combi))


Verdicts: Wrong Answer

Accepted
Problem: There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty.  Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:    * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive).  As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition.

Submission attempts (in order):
N,A,B,C,D=map(int,input().split())
for i in range(0,N-1):
    l.append(range(i*C-(N-i)*D,i*D-(N-i)*C+1))

for _ in l:
    if B-A in _:
        print("YES")
        break
else:
    print("NO")

N,A,B,C,D=map(int,input().split())
N=N-2
for i in range(0,N+1):
    l.append(range(i*C-(N-i)*D,i*D-(N-i)*C+1))

for _ in l:
    if B-A in _:
        print("YES")
        break
else:
    print("NO")


N,A,B,C,D=map(int,input().split())
N=N-1
l=[]
for i in range(0,N+1):
    l.append(range(i*C-(N-i)*D,i*D-(N-i)*C+1))

for _ in l:
    if B-A in _:
        print("YES")
        break
else:
    print("NO")

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty.  Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:    * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive).  As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition.

Submission attempts (in order):
def solve(n, a, b, c, d):
    return d == 0
    if d == 0:
        return a == b
    t = n - 1
    return (b - a - c * t) % (c + d) <= (d - c) * t


print('YES' if solve(*map(int, input().split())) else 'NO')


def solve(n, a, b, c, d):
    if d == 0:
        return a == b
    t = n - 1
    ab = abs(a - b)
    if ab > d * t:
        return False
    return (ab - c * t) % (c + d) <= (d - c) * t


print('YES' if solve(*map(int, input().split())) else 'NO')


Verdicts: Wrong Answer

Accepted
Problem: There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty.  Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:    * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive).  As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition.

Submission attempts (in order):
def main():
    n, a, b, c, d = map(int, input().split())

    for i in range(n):
        if c * (n-1-i) - d * i <= b - a <= -c * i + d * (n-1-i):
            print("Yes")
            break
    else:
        print("No")


if __name__ == '__main__':
    main()


def main():
    n, a, b, c, d = map(int, input().split())

    for i in range(n):
        if c * (n-1-i) - d * i <= b - a <= -c * i + d * (n-1-i):
            print("YES")
            break
    else:
        print("NO")


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty.  Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:    * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive).  As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition.

Submission attempts (in order):
N,a,b,c,d=map(int, input().split())
N-=1
a,b=0,abs(b-a)

if d*N<b:
  print('No')
  exit()
  
for i in range(N//2+1):
  e=b-(N-i*2)*d
  f=b-(N-i*2)*c
  if e<=(d-c)*i and (c-d)*i<=f:
    print('Yes')
    exit()
print('No')

N,a,b,c,d=map(int, input().split())
N-=1
a,b=0,abs(b-a)


for i in range(N//2+1):
  e=b-(N-i*2)*d
  f=b-(N-i*2)*c
  if e<=(d-c)*i and (c-d)*i<=f:
    print('YES')
    exit()
print('NO')

Verdicts: Wrong Answer

Accepted
Problem: There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty.  Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:    * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive).  As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition.

Submission attempts (in order):
N,A,B,C,D = map(int,input().split())
if N > 30 and D > 1:
	flag = 10 **9
else:
	flag = pow(D,N -1)
B -= A
if N % 2 == 1:
	if (B % (C + D) <= (N - 1) * (D - C) / 2 or abs(B % (C + D) - (C + D)) <= (N - 1) * (D - C) / 2) and B <= flag and B >= -flag:
		print("YES")
	else:
		print("NO")
else:
	if ((B - (D + C) / 2) % (C + D) <= (N - 1) * (D - C) / 2 : #and B <= flag and B >= -flagor (B + (D + C) / 2) % (C + D) <= (N - 1) *  (D - C) / 2)
		print("YES")
	else:
		print("NO")

N,A,B,C,D = map(int,input().split())
if N > 18 and D > 1:
	flag = 10 **9
else:
	flag = pow(D,N)
B -= A
if N % 2 == 1:
	if (B % (C + D) <= (N - 1) * (D - C) / 2 or abs(B % (C + D) - (C + D)) <= (N - 1) * (D - C) / 2) and B <= flag and B >= -flag:
		print("YES")
	else:
		print("NO")
else:
	if (abs(B % (C + D) - (D - C) / 2) <= (N - 1) * (D - C) / 2 or (B % (C + D) + (D - C) / 2) mod (C + D) <= (N - 1) * (D - C) / 2) and B <= flag and B >= -flag:
		print("YES")
	else:
		print("NO")

N,A,B,C,D = map(int,input().split())
flag = D * (N - 1)
B -= A
if D - C == 0:
	if A == B:
		print("YES")
	else:
		print("NO")
elif N % 2 == 1:
	if (B % (C + D) <= (N - 1) * (D - C) / 2 or abs(B % (C + D) - (C + D)) <= (N - 1) * (D - C) / 2) and B <= flag and B >= -flag:
		print("YES")
	else:
		print("NO")
else:
	if abs(B % (C + D) - (D + C) / 2) <= (N - 1) * (D - C) / 2 and B <= flag and B >= -flag:
		print("YES")
	else:
		print("NO")

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty.  Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:    * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive).  As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition.

Submission attempts (in order):
N, A, B, C, D = map(int, input().split())
lb, ub = A, A
for _ in range(1, N):
    if (lb + ub) / 2 < B:
        lb, ub = lb + C, ub + D
    else:
        lb, ub = lb - D, ub - C
if lb <= B <= ub:
    print('Yes')
else:
    print('No')

N, A, B, C, D = map(int, input().split())
for m in range(N):
    if C * (N - 1 - m) - D * m <= B - A <= D * (N - 1 - m) - C * m:
        print('YES')
        break
else:
    print('NO')

Verdicts: Wrong Answer

Accepted
Problem: There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty.  Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:    * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive).  As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition.

Submission attempts (in order):
import sys

def diff(N,A,B,C,D):
    mini = (B+(N-1)*D-A)/(C+D)
    for i in xrange(mini, N-1):
        lower_bound = A + i*C - (N-i-1)*D
        upper_bound = A + i*D - (N-i-1)*C
        print(lower_bound, upper_bound)
        if lower_bound <= B and B <= upper_bound:
            return True
        elif B < lower_bound:
            return False

str = sys.stdin.readline().strip() #"491995 412925347 825318103 59999126 59999339"
N,A,B,C,D = map(int,str.strip().split(" "))
print("YES" if diff(N,A,B,C,D) else "NO")


import sys

def diff(N,A,B,C,D):
    mini = (B+(N-1)*D-A)/(C+D)
    for i in range(int(mini), N-1):
        lower_bound = A + i*C - (N-i-1)*D
        upper_bound = A + i*D - (N-i-1)*C
        #print(lower_bound, upper_bound)
        if lower_bound <= B and B <= upper_bound:
            return True
        elif B < lower_bound:
            return False

str = sys.stdin.readline().strip() #"491995 412925347 825318103 59999126 59999339"
N,A,B,C,D = map(int,str.strip().split(" "))
print("YES" if diff(N,A,B,C,D) else "NO")

Verdicts: Runtime Error

Accepted
Problem: There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty.  Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:    * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive).  As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition.

Submission attempts (in order):
# encoding:utf-8
import math

def main():
	N, A, B, C, D = list(map(int, input().split()))
	cur_list = [(A, A)]

	for i in range(N - 1):
		cur_list = calcNextList(cur_list, C, D)
		cur_list =[x for x in cur_list if x[0] >= 0 and x[1] <= 10 ** 9]
		cur_list = merge(cur_list)

	print(cur_list)
	for x in cur_list:
		if x[0] <= B <= x[1]:
			print("YES")
			break
	else:
		print("NO")



# 	return((input_taple[0] - D, input_taple[1] + D))

def Duplicate(input_taple, C, D):
	first_tuple = (input_taple[0] + C, input_taple[1] + D)
	second_tuple = (input_taple[0] - D, input_taple[1] - C)
	return([first_tuple, second_tuple])

def calcNextList(cur_list, C, D):
	next_list = []
	for x in cur_list:
		next_list.extend(Duplicate(x, C, D))
	return(next_list)

def merge(cur_list):
	cur_list.sort()

	next_list = [cur_list[0]]

	for i in range(len(cur_list) - 1):
		if next_list[-1][1] >= cur_list[i+1][0]:
			merged = (next_list[-1][0], max(next_list[-1][1], cur_list[i+1][1]))
			next_list.pop()
			next_list.append(merged)
		else:
			next_list.append(cur_list[i+1])

	return(next_list)

if __name__ == '__main__':
	main()

# encoding:utf-8
import math

def main():
	N, A, B, C, D = list(map(int, input().split()))

	for i in range(N):
		plus_band = calcBand(i, C, D)
		minus_band = calcBand(N - i - 1, C, D)
		total_band = (plus_band[0] - minus_band[1], plus_band[1] - minus_band[0])

		if total_band[0] <= B - A <= total_band[1]:
			print("YES")
			break
	else:
		print("NO")

def calcBand(n_band, C, D):
	return((C * n_band, D * n_band))

if __name__ == '__main__':
	main()

Verdicts: Runtime Error

Accepted
Problem: There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty.  Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:    * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive).  As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition.

Submission attempts (in order):
n,a,b,c,d=map(int,input().split())
f=0
for i in range(n):f^=i*c-(~i+n)*d<=b-a<=i*d-(~i+n)*c
print('NYOE S'[f::2])

n,a,b,c,d=map(int,input().split());print('NYOE S'[any(i*c-(~i+n)*d<=b-a<=i*d-(~i+n)*cfor i in range(n))::2])

n,a,b,c,d=map(int,input().split());print('NYOE S'[any(c*i-d*(~i+n)<=b-a<=d*i-c*(~i+n)for i in range(n))::2])

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty.  Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:    * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive).  As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition.

Submission attempts (in order):
N, A, B, C, D = map(int, input().split())
E = B - A
for m in range(N):
  if C*(N-1-m) - D*m <= E <= -C*m + (N-1-m)*D:
    print("YES")
    break
else
print("NO")

N, A, B, C, D = map(int, input().split())
E = B - A
for m in range(N):
  if C*(N-1-m) - D*m <= E <= -C*m + (N-1-m)*D:
    print("YES")
    break
else:
  print("NO")


Verdicts: Runtime Error

Accepted
Problem: There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty.  Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:    * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive).  As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition.

Submission attempts (in order):
N,A,B,C,D=map(int,input().split())
if A> B:
  A,B=B,A
if C>D:
  C,B=B,C

flag=False
diff=B-A
d=0
for i in range(0,N,2):
  d+=D-C
  j= N-1 - i
  if j==0:
    if diff==d:
      flag=True
    break
  k=abs(diff - d) / j
  if k>=C and k<=D:
    flag=True
    break
    
if flag:
  print("YES")
else:
  print("NO")


N, A, B, C, D = map(int, input().split())
if A > B:
    A, B = B, A

flag = False
diff = B-A
d = 0
for i in range(0, N, 2):
    if i > 0:
        d += D-C
    j = N-1 - i
    if diff == d and j % 2 == 0:
        flag == True
        break
    if j == 0:
        break

    k = abs(diff - d) / j
    if (k >= C and k <= D) or (abs(diff-d) >= C and abs(diff-d) <= D and j % 2 == 1):
        flag = True
        break
    k = abs(diff + d) / j
    if (k >= C and k <= D) or (diff+d >= C and diff+d <= D and j % 2 == 1):
        flag = True
        break

if flag:
    print("YES")
else:
    print("NO")



Verdicts: Wrong Answer

Accepted
Problem: There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty.  Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:    * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive).  As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition.

Submission attempts (in order):
N,a,b,c,d = map(int,input().split())
n = N - 1
ans = "No"
for i in range(n+1):
    m1 = i*d - (n-i)*c
    m2 = -1*(n-i)*d + i*c
    if m1 <= m2:
        if a + m1 <= b and b <= a+ m2:
            ans = "Yes"
            #print(m1,m2)
            break
    else:
        if a + m2 <= b and b <= a + m1:
            ans = "Yes"
            #print(m1,m2)
            break
print(ans)

N,a,b,c,d = map(int,input().split())
n = N - 1
ans = "NO"
for i in range(n+1):
    m1 = i*d - (n-i)*c
    m2 = -1*(n-i)*d + i*c
    if m1 <= m2:
        if a + m1 <= b and b <= a+ m2:
            ans = "YES"
            #print(m1,m2)
            break
    else:
        if a + m2 <= b and b <= a + m1:
            ans = "YES"
            #print(m1,m2)
            break
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty.  Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:    * For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive).  As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition.

Submission attempts (in order):
N, A, B, C, D = map(int, input().split())
B -= A

ans = "NO"
for i in range(N):
    high = i * D - (N - i - 1) * C
    low = i * C - (N - i - 1) * D
    print(i, N-i-1, low, high)
    if low <= B <= high:
        ans = "YES"
print(ans)

N, A, B, C, D = map(int, input().split())

dif = B - A

ans = "NO"
for i in range(N):
    pos = i
    neg = N - i - 1
    high = D * pos - C * neg
    low = C * pos - D * neg
    if low <= dif <= high:
        ans = "YES"
        break

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There are N balls in a row. Initially, the i-th ball from the left has the integer A_i written on it.  When Snuke cast a spell, the following happens:    * Let the current number of balls be k. All the balls with k written on them disappear at the same time.  Snuke's objective is to vanish all the balls by casting the spell some number of times. This may not be possible as it is. If that is the case, he would like to modify the integers on the minimum number of balls to make his objective achievable.  By the way, the integers on these balls sometimes change by themselves. There will be M such changes. In the j-th change, the integer on the X_j-th ball from the left will change into Y_j.  After each change, find the minimum number of modifications of integers on the balls Snuke needs to make if he wishes to achieve his objective before the next change occurs. We will assume that he is quick enough in modifying integers. Here, note that he does not actually perform those necessary modifications and leaves them as they are.

Submission attempts (in order):
from collections import Counter, defaultdict

n, m = map(int, input().split())
an = list(map(int, input().split()))
ac = defaultdict(int, Counter(an))
ad = [0] * (n * 2)
for a, c in ac.items():
    for i in range(a - c, a):
        ad[i] += 1
ans = ad[:n].count(0)

for _ in range(m):
    x, y = map(int, input().split())
    ax = an[x - 1]
    xdi = ax - ac[ax]
    ad[xdi] -= 1
    ac[ax] -= 1
    ac[y] += 1
    ydi = y - ac[y]
    ad[ydi] += 1
    an[x - 1] = y
    if ad[xdi] == 0:
        ans += 1
    if ad[ydi] == 1:
        ans -= 1
    print(ans)


from collections import Counter

n, m = map(int, input().split())
an = list(map(int, input().split()))
ac_ = Counter(an)
ac = {i: ac_[i] if i in ac_ else 0 for i in range(1, n + 1)}
ad = [0] * n
for a, c in ac.items():
    for i in range(max(0, a - c), a):
        ad[i] += 1
ans = ad.count(0)
anss = []

for x, y in (map(int, input().split()) for _ in range(m)):
    ax = an[x - 1]
    xdi = ax - ac[ax]
    if xdi >= 0:
        ad[xdi] -= 1
        if ad[xdi] == 0:
            ans += 1
    ac[ax] -= 1
    ac[y] += 1
    ydi = y - ac[y]
    if ydi >= 0:
        ad[ydi] += 1
        if ad[ydi] == 1:
            ans -= 1
    an[x - 1] = y
    anss.append(ans)
print('\n'.join(map(str, anss)))


Verdicts: Wrong Answer

Accepted
Problem: You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.  The i-th operation is as follows:    1. Append a_i to the end of b.   2. Reverse the order of the elements in b.  Find the sequence b obtained after these n operations.

Submission attempts (in order):
N = int(input())
a = input().split()
b = []
for i in range(len(a)):
	if i % 2 == 1:
		b.insert(0, a[i])
	else:
		b.append(a[i])
if N % 2 == 1:
	b = b.reverse()
print(b)
line = " ".join(b)
print(line)

N = int(input())
a = input().split()
b = [""] * N
b1 = [a[i] for i in range(len(a)) if i % 2 == 1][::-1]
b2 = [a[i] for i in range(len(a)) if i % 2 == 0]
b = b1 + b2
if N % 2 == 1:
	b = b[::-1]
line = " ".join(b)
print(line)

Verdicts: Runtime Error

Accepted
Problem: You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.  The i-th operation is as follows:    1. Append a_i to the end of b.   2. Reverse the order of the elements in b.  Find the sequence b obtained after these n operations.

Submission attempts (in order):
n = int(input())
As= list(map(int,input().split()))
back = As[::-2]
if n%2==0:
    forward = As[::2]
else:
    forward = As[1::2]
print(back+forward)

n = int(input())
As= list(map(int,input().split()))
back = As[::-2]
if n%2==0:
    forward = As[::2]
else:
    forward = As[1::2]
ans = back+forward
print(" ".join(map(str,ans)))

Verdicts: Wrong Answer

Accepted