Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
nums = [0] + list(map(int, input().split()))

A = [i + n for n in enumerate(nums, start=1)]
B = [j - n for n in enumerate(nums, start=1)]
BC = Counter(B)
answer = 0
for a in A:
  answer += BC[a]
print(answer)

Fixed submission:
from collections import Counter

N = int(input())
nums = list(map(int, input().split()))

A = [i + n for i, n in enumerate(nums, start=1)]
B = [j - n for j, n in enumerate(nums, start=1)]
BC = Counter(B)
answer = 0
for a in A:
  answer += BC[a]
print(answer)
Buggy python submission (verdict: Runtime Error):
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328

Fixed submission:
from collections import deque

N, M, Q = map(int, input().split())
queries = [list(map(int, input().split())) for _ in range(Q)]
patterns = []

ptn = deque([])
for i in range(M):
  ptn.append([i])
while len(ptn) > 0:
  p = ptn.pop()
  if len(p) < N:
    for i in range(p[-1], M):
      ptn.append(p+[i])
  else:
    patterns.append(p)
answer = 0
for p in patterns:
  point = 0
  for a, b, c, d in queries:
    if p[b-1]-p[a-1] == c:
      point += d
  answer = max(answer, point)
print(answer)
Buggy python submission (verdict: Runtime Error):
N = int(input())
nums = list(map(int, input().split()))
counts = [0 for _ in range(N+1)]
for num in nums:
  counts[num] += 1
combination = 0
for count in counts:
  if count >= 2
    combination += (count*(count-1))//2
for i in range(1, N+1):
  print(combination-counts[i]+1)


Fixed submission:
N = int(input())
nums = list(map(int, input().split()))
counts = [0 for _ in range(N+1)]
for num in nums:
  counts[num] += 1
combination = 0
for count in counts:
  if count >= 2:
    combination += (count*(count-1))//2
for num in nums:
  print(combination-counts[num]+1)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

S = list(input())
Q = int(input())
answer = deque(S)
reverse = False
for _ in range(Q):
  query = input()
  if query == '1':
    reverse ^= True
  else:
    ope, types, alphabet = query.split()
    if types == '1':
      if reverse:
        answer.append(alphabet)
      else:
        answer.appendleft(alphabet)
    else:
      if reverse:
        answer.appendleft(alphabet)
      else:
        answer.append(alphabet)
if reverse:
  result = ''
  for i in range(len(answer)):
    result += answer.pop()
  print(result)
else:
  result = ''
  for i in range(len(answer)):
    result += answer.popleft()
  print(result)

Fixed submission:
from collections import deque

S = list(input())
Q = int(input())
answer = deque(S)
reverse = False
for _ in range(Q):
  query = input()
  if query == '1':
    reverse ^= True
  else:
    ope, types, alphabet = query.split()
    if types == '1':
      if reverse:
        answer.append(alphabet)
      else:
        answer.appendleft(alphabet)
    else:
      if reverse:
        answer.appendleft(alphabet)
      else:
        answer.append(alphabet)
if reverse:
  result = ''
  for i in range(len(answer)):
    result += answer.pop()
  print(result)
else:
  result = ''
  for i in range(len(answer)):
    result += answer.popleft()
  print(result)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
digits = [-1 for _ in range(N+1)]
for __ in range(M):
  digit, num = map(int, input().split())
  if digit = 1 and num == 0:
    print(-1)
    exit()
  elif digits[digit] != -1 and num != digits[digit]:
    print(-1)
  else:
    digits[digit] = num
answer = 0
for i in range(1, N+1):
  if digits[i] == -1:
    if i == 1:
      answer += 1*10*(N-i)
  else:
    answer += digits[i]*10*(N-i)
print(answer)

Fixed submission:
N, M = map(int, input().split())
digits = [-1 for _ in range(N+1)]
for __ in range(M):
  digit, num = map(int, input().split())
  if digit == 1 and num == 0 and N != 1:
    print(-1)
    exit()
  elif digits[digit] != -1 and num != digits[digit]:
    print(-1)
    exit()
  else:
    digits[digit] = num
answer = 0
for i in range(1, N+1):
  if digits[i] == -1:
    if i == 1 and N != 1:
      answer += 1*10**(N-i)
  else:
    answer += digits[i]*10**(N-i)
print(answer)
Buggy python submission (verdict: Runtime Error):
N = int(input())
dict = {}
for _ in range(N):
  word = input()
  if word in dict:
    dict[word] += 1
  else:
    dict[word] = 1
sorted_dict = sorted(dict.items(), key=lambda(k,v): (-v,k))
max_v = sorted_dict[0][1]
for k, v in sorted_dict:
  if v == max_v:
    print(k)
  else:
    exit()
  

Fixed submission:
N = int(input())
words = {}
for _ in range(N):
  word = input()
  if word in words:
    words[word] += 1
  else:
    words[word] = 1
sorted_words = sorted(words.items(), key=lambda x: (-x[1], x[0]))
max_v = sorted_words[0][1]
for k, v in sorted_words:
  if v == max_v:
    print(k)
  else:
    exit()
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
results = [0 for _ in range(N+1)]
wa_cnt = 0
ac_cnt = 0
for _ in range(M):
  problem, result = input().split()
  if results[problem] == 0 and result == 'AC':
    ac_cnt += 1
    results[problem] = 1
  elif results[problem] == 0 and result == 'WA':
    wa_cnt += 1
print(ac_cnt, wa_cnt)

Fixed submission:
N, M = map(int,input().split())
results = [0 for _ in range(N+1)]
wa_list = [0 for __ in range(N+1)]
ac_cnt = 0
wa_cnt = 0
for _ in range(M):
  problem, result = input().split()
  if results[int(problem)] == 0 and result == 'AC':
    ac_cnt += 1
    results[int(problem)] = 1
  elif results[int(problem)] == 0 and result == 'WA':
    wa_list[int(problem)] += 1
for i in range(1, N+1):
  if results[i] == 1:
    wa_cnt += wa_list[i]
print(ac_cnt, wa_cnt)
Buggy python submission (verdict: Runtime Error):
import math

A, B = map(int, input().split())
print(a*b//math.gcd(a, b))

Fixed submission:
import math

A, B = map(int, input().split())
print(A*B//math.gcd(A, B))
Buggy python submission (verdict: Runtime Error):
if sum(list(map(int, input()))) > 21:
  print('bust')
else:
  print('win')

Fixed submission:
if sum(list(map(int, input().split()))) > 21:
  print('bust')
else:
  print('win')
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush

N, K = map(int, input().split())
digests = list(map(int, input().split()))
foods = list(map(int, input().split()))
foods.sort()
digests.sort(reverse=True)
hq = []
for i in range(N):
  heappush(hq, (-digests[i]*foods[i], digests[i], foods[i]))
for _ in range(K):
  cost, digest, food = heappop(hq)
  if cost == 0:
    heappush(hq, (0, 0, 0))
    break
  heappush(hq, (-(digest-1)*food, digest-1, food))
ans = 0
max_c, digest, food = heappop(hq)
print(-max_c)

Fixed submission:
N, K = map(int, input().split())
costs = list(map(int, input().split()))
foods = list(map(int, input().split()))
foods.sort()
costs.sort(reverse=True)

def can_eat(x):
  count = 0
  for i in range(N):
    count += max(0, costs[i]-x//foods[i])
  return count <= K

l, r = -1, 10**12+1
while r-l > 1:
  mid = (l+r)//2
  if can_eat(mid):
    r = mid
  else:
    l = mid
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush

N, K = map(int, input().split())
digests = list(map(int, input().split()))
foods = list(map(int, input().split()))
foods.sort()
digests.sort(reverse=True)
hq = []
for i in range(N):
  heappush(hq, (-digests[i]*foods[i], digests[i], foods[i]))
for _ in range(K):
  cost, digest, food = heappop(hq)
  if cost == 0:
    heappush(hq, (0, 0, 0))
    break
  heappush(hq, (-(digest-1)*food, digest-1, food))
ans = 0
max_c, digest, food = heappop(hq)
print(-max_c)

Fixed submission:
N, K = map(int, input().split())
costs = list(map(int, input().split()))
foods = list(map(int, input().split()))
foods.sort()
costs.sort(reverse=True)

def can_eat(x):
  count = 0
  for i in range(N):
    count += max(0, costs[i]-x//foods[i])
  return count <= K

l, r = -1, 10**12+1
while r-l > 1:
  mid = (l+r)//2
  if can_eat(mid):
    r = mid
  else:
    l = mid
print(r)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
a = set(1)
b = set(1)
n = 2
while n**2 > max(A, B):
  if A%n == 0 and n**2 <= A:
    a.add(n)
    a.add(A//n)
  if B%n == 0 and n**2 <= B:
    b.add(n)
    b.add(B//n)
ab = a & b
ab = list(ab)
answer = 0
for i, n in enumerate(ab):
  prime = True
  for j, m in enumerate(ab):
    if i != j and n%m == 0:
      prime = False
      break
  if prime:
    answer += 1
print(answer)
      



Fixed submission:
A, B = map(int, input().split())
a = set([])
b = set([])
n = 1
while n**2 <= max(A, B):
  if A%n == 0 and n**2 <= A:
    a.add(n)
    a.add(A//n)
  if B%n == 0 and n**2 <= B:
    b.add(n)
    b.add(B//n)
  n += 1
ab = a & b
ab.discard(1)
ab = list(ab)
answer = 0
for i, n in enumerate(ab):
  prime = True
  for j, m in enumerate(ab):
    if i != j and n%m == 0:
      prime = False
      break
  if prime:
    answer += 1
print(answer+1)
Buggy python submission (verdict: Runtime Error):
S = input()
W = ['Sunny', 'Cloudy', 'Rainy']
for i, w in enumerate(W):
  if S = w:
    print(W[(i+1)%3])
    break

Fixed submission:
S = input()
W = ['Sunny', 'Cloudy', 'Rainy']
for i, w in enumerate(W):
  if S == w:
    print(W[(i+1)%3])
    break
Buggy python submission (verdict: Runtime Error):
N = int(input())
nums = list(map(int, input().split()))
nums.sort()
ans = num
for num  in nums[1:]:
  ans = (ans + num)/2
print(ans)
  

Fixed submission:
N = int(input())
nums = list(map(int, input().split()))
nums.sort()
ans = nums[0]
for num  in nums[1:]:
  ans = (ans + num)/2
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
M = list(map(int, input().split()))
H = list(map(int, input().split()))

sum_m = 0
rest = 0
rest = max(0, H[1]-M[1])
sum_m += min(H[1], M[1])
for i in range(1, N):
  rest = max(0, H[i]+rest-M[i])
  if M[i] >= H[i]+rest:
    sum_m += H[i]+rest
  else:
    sum_m += M[i]
sum_m += min(rest, M[-1])

print(sum_m)


Fixed submission:
N = int(input())
M = list(map(int, input().split()))
H = list(map(int, input().split()))

sum_m = 0
killed = 0
rest = 0
for i in range(0, N):
  killed = min(H[i]+rest, M[i])
  rest = max(0, min(H[i]+rest-killed, H[i]))
  sum_m += killed
sum_m += min(rest, M[-1])
print(sum_m)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = ''
temp = (A[1] - A[0])*2
for i in range(N)[2:]:
    temp = A[i]*2 - temp
a = int(temp/2)
ans = ans + str(a) + ' '

temp = a
for i in range(N-1):
    temp = A[i]*2 - temp
    ans = ans + str(temp) + ' '

print(ans.rstrip())

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

ans = [] * (N)
temp = (A[1] - A[0])*2
for i in range(N)[2:]:
    temp = A[i]*2 - temp
a = int(temp/2)
ans.append(str(a))

temp = a
for i in range(N-1):
    temp = A[i]*2 - temp
    ans.append(str(temp))

print(' '.join(ans))
Buggy python submission (verdict: Runtime Error):
S = input()
if (S[0] == S[1] and S[2] == S[3] and S[0] != S[2]) or (S[0] == S[2] and S[1] == S[3] and S[0] != S[3]) or (S[0] == S[3] and S[1] == S[2] and S[0] != S[1]):
    print('Yes')
else:
    print('No')

Fixed submission:
N = int(input())
P = list(map(int, input().split()))
C = 0
for i in range(N):
    if i == 0 or i == N-1:
        continue
    elif (P[i] > P[i-1] and P[i+1] > P[i]) or (P[i-1] > P[i] and P[i] > P[i+1]):
        C += 1
print(C)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, D = map(int, input().split())
E = []
S = 0
for i in range(A, B+1):
    # if E[i-A] == 1:
    #     continue
    if i in E:
        E.remove(i)
        continue
    else:
        if i%C == 0:
            t = (B - i) // C
            for j in range(2, t+1):
                # E[i-A+j*C] = 1
                E.append(i+j*C)
        elif i%D == 0:
            t = (B - i) // D
            for j in range(2, t+1):
                # E[i-A+j*D] = 1
                E.append(i+j*D)
        else:
            S += 1
print(S)

Fixed submission:
import fractions

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

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

lcm_cd = lcm(C, D)

mod_ac = A % C
mod_ad = A % D
mod_lcm = A % lcm_cd

c_num = 0
d_num = 0
cd_num = 0

if mod_ac == 0:
    c_num = B//C - A//C + 1
else:
    c_num = B//C - A//C

if mod_ad == 0:
    d_num = B//D - A//D + 1
else:
    d_num = B//D - A//D

if mod_lcm == 0:
    cd_num = B//lcm_cd - A//lcm_cd + 1
else:
    cd_num = B//lcm_cd - A//lcm_cd

ans = B - A + 1 - (c_num + d_num - cd_num)
print(ans)
Buggy python submission (verdict: Runtime Error):
num = int(input())
A = list(map(int, input().split()))
H = sum(A) / 2
S = 0
for i in range(num):
  S += A[i]
  if abs(H - (S + A[i+1])) >= abs(H - S):
    print(abs(2 * S - 2 * H))
    break
    


Fixed submission:
F, S, T = map(int, input().split())
FS = F + S
ST = S + T
TF = T + F
L = [FS, ST, TF]
print(min(L))
Buggy python submission (verdict: Runtime Error):
num = int(input())
A = list(map(int, input().split()))
H = sum(A) / 2
S = 0
for i in range(num):
  S += A[i]
  if abs(H - (S + A[i+1])) >= abs(H - S):
    # print(abs(2 * S - 2 * H))
    # break()
    


Fixed submission:
num = int(input())
A = list(map(int, input().split()))
F = sum(A)
H = F / 2
S = 0
for i in range(num):
  S += A[i]
  if abs(H - (S + A[i+1])) > abs(H - S):
    print(abs(2 * S - F))
    break

Buggy python submission (verdict: Runtime Error):
num = int(input())
A = list(map(int, input().split()))
H = sum(A) / 2
S = 0
for i in range(num):
  S = A[i]
  if abs(H - (S + A[i+1])) >= abs(H - S):
    # print(abs(2 * S - 2 * H))
    break()

    


Fixed submission:
num = int(input())
A = list(map(int, input().split()))
F = sum(A)
H = F / 2
S = 0
for i in range(num):
  S += A[i]
  if abs(H - (S + A[i+1])) > abs(H - S):
    print(abs(2 * S - F))
    break

Buggy python submission (verdict: Runtime Error):
num = int(input())
A = list(map(int, input().split()))
H = sum(A) / 2
S = 0
for i in range(num):
  S = A[i]
  if abs(H - (S + A[i+1])) >= abs(H - S):
    print(abs(2 * S - 2 * H))
    break()

    


Fixed submission:
num = int(input())
A = list(map(int, input().split()))
F = sum(A)
H = F / 2
S = 0
for i in range(num):
  S += A[i]
  if abs(H - (S + A[i+1])) > abs(H - S):
    print(abs(2 * S - F))
    break

Buggy python submission (verdict: Runtime Error):
num = int(input())
A = list(map(int, input().split()))
H = sum(A) / 2
S = 0
for i in range(num):
  S = A[i]
  if abs(H - (S + A[i+1])) >= abs(H - S):
    print(abs(2 * S - 2 * H))

    


Fixed submission:
num = int(input())
A = list(map(int, input().split()))
F = sum(A)
H = F / 2
S = 0
for i in range(num):
  S += A[i]
  if abs(H - (S + A[i+1])) > abs(H - S):
    print(abs(2 * S - F))
    break

Buggy python submission (verdict: Runtime Error):
num = int(input())
A = list(map(int, input().split()))
H = sum(A) / 2
S = 0
for i in range(num):
  S = A[i]
  if (H - (S + A[i+1])) >= (H - S):
    print(abs(2 * S - 2 * H)

    


Fixed submission:
num = int(input())
A = list(map(int, input().split()))
F = sum(A)
H = F / 2
S = 0
for i in range(num):
  S += A[i]
  if abs(H - (S + A[i+1])) > abs(H - S):
    print(abs(2 * S - F))
    break

Buggy python submission (verdict: Runtime Error):
num = int(input())
A = list(map(int, input().split()))
H = sum(A)
S = 0
for i in range(num):
  S = A[i]
  if (H - (S + A[i+1])) >= (H - S):
    print(abs(2 * S - 2 * H)

    

Fixed submission:
num = int(input())
A = list(map(int, input().split()))
F = sum(A)
H = F / 2
S = 0
for i in range(num):
  S += A[i]
  if abs(H - (S + A[i+1])) > abs(H - S):
    print(abs(2 * S - F))
    break
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
cnt = 0
len_s = len(S)
i = 2
while i <= len_s-1:
  if S[i-2:i+1] == 'ABC':
    S = S[:i-2] + 'BCA' + S[i+1:]
    cnt += 1
    i = max(0, i-3)
  else:
    i += 1
print(cnt)

Fixed submission:
S = input()
idx = 0
a_cnt = 0
cnt = 0
len_s = len(S)
while idx < len_s:
  if S[idx:idx+3] == 'ABC':
    cnt += 1 + a_cnt
    idx += 3
    a_cnt += 1
    bc_cnt = 0
    while idx < len(S):
      if S[idx:idx+2] == 'BC':
        cnt += a_cnt
        idx += 2
      else:
        break
  else:
    if S[idx] == 'A':
      a_cnt += 1
    else:
      a_cnt = 0
    idx += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
N = int(input())
SP = [list(input().split())) for i in range(N)]

sorted_SP = sorted(SP, key=lambda x:x[1], reverse=True)
sorted_SP = sorted(sorted_SP, key=lambda x:x[0])

for i in range(N):
  for j in range(N):
    if SP[i][0] == sorted_SP[j][0] and SP[i][1] == sorted_SP[j][1]:
      print(j+1)
      break

Fixed submission:
N = int(input())
SP = [list(input().split()) for i in range(N)]

sorted_SP = sorted(SP, key=lambda x:int(x[1]), reverse=True)
sorted_SP = sorted(sorted_SP, key=lambda x:x[0])

for i in range(N):
  for j in range(N):
    if sorted_SP[i][0] == SP[j][0] and sorted_SP[i][1] == SP[j][1]:
      print(j+1)
      break

Buggy python submission (verdict: Runtime Error):
N = int(input())
SP = [list(map(int, input().split())) for i in range(N)]

sorted_SP = sorted(SP, key=lambda x:x[1], reverse=True)
sorted_SP = sorted(sorted_SP, key=lambda x:x[0])

for i in range(N):
  for j in range(N):
    if SP[i][0] == sorted_SP[j][0] and SP[i][1] == sorted_SP[j][1]:
      print(j+1)
      break


Fixed submission:
N = int(input())
SP = [list(input().split()) for i in range(N)]

sorted_SP = sorted(SP, key=lambda x:int(x[1]), reverse=True)
sorted_SP = sorted(sorted_SP, key=lambda x:x[0])

for i in range(N):
  for j in range(N):
    if sorted_SP[i][0] == SP[j][0] and sorted_SP[i][1] == SP[j][1]:
      print(j+1)
      break

Buggy python submission (verdict: Runtime Error):
N = int(input())
SP = [list(map(int, input().split())) for i in range(N)]

sorted_SP = sorted(SP, key=lambda x:x[1], reverxe=True)
sorted_SP = sorted(sorted_SP, key=lambda x:x[0])

for i in range(N):
  for j in range(N):
    if SP[i][0] == SP[j][0] and SP[i][1] == SP[j][1]:
      print(j+1)
      break


Fixed submission:
N = int(input())
SP = [list(input().split()) for i in range(N)]

sorted_SP = sorted(SP, key=lambda x:int(x[1]), reverse=True)
sorted_SP = sorted(sorted_SP, key=lambda x:x[0])

for i in range(N):
  for j in range(N):
    if sorted_SP[i][0] == SP[j][0] and sorted_SP[i][1] == SP[j][1]:
      print(j+1)
      break
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(M)]
p = list(map(int, input().split()))

def check(ar):
    cnt = 0
    for j in range(M):
        count = 0
        for k in ks[j][1::]:
            if ar[k-1] == 1:
                count += 1
        if count%2 == p[j]:
            cnt += 1
    return (cnt == M)


def dfs(n, ar):
    if n == 0:
        if check(ar):
            return 1
        else:
            return 0
    else:
        return dfs(n-1, ar.append(0)) + dfs(n-1, ar.append(1))
arr = []
ans = dfs(N, arr)
print(ans)


Fixed submission:
N, M = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(M)]
p = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    cnt = 0
    for j in range(M):
        count = 0
        for k in ks[j][1::]:
            if (i >> k-1)&1 == 1:
                count += 1
        if count%2 == p[j]:
            cnt += 1
    if cnt == M:
        ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(M)]
p = list(map(int, input().split()))

def check(ar):
    cnt = 0
    for j in range(M):
        count = 0
        for k in ks[1::]:
            if ar[k-1] == 1:
                count += 1
        if count%2 == p[j]:
            cnt += 1
    return (cnt == M)


def dfs(n, ar):
    if n == 0:
        if check(ar):
            return 1
        else:
            return 0
    else:
        return dfs(n-1, ar.append(0)) + dfs(n-1, ar.append(1))
arr = []
ans = dfs(N, arr)
print(ans)

Fixed submission:
N, M = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(M)]
p = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    cnt = 0
    for j in range(M):
        count = 0
        for k in ks[j][1::]:
            if (i >> k-1)&1 == 1:
                count += 1
        if count%2 == p[j]:
            cnt += 1
    if cnt == M:
        ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = mtp(int, input().split())
ks = [list(map(int, input().split())) for i in range(M)]
p = list(map(int, input().split()))

ans = 0
for i in range(2**M):
    cnt = 0
    for j in range(M):
        count = 0
        for k in ks[j][1::]:
            if (i >> k-1)&1 == 1:
                count += 1
        if count%2 == p[j]:
            cnt += 1
    if cnt == M:
        ans += 1
print(ans)

Fixed submission:
N, M = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(M)]
p = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    cnt = 0
    for j in range(M):
        count = 0
        for k in ks[j][1::]:
            if (i >> k-1)&1 == 1:
                count += 1
        if count%2 == p[j]:
            cnt += 1
    if cnt == M:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
jewels = [0] + list(map(int, input().split())) + [0]
ans = 0
for get in range(min(N, K)+1):
  put = get
  for left in range(get+1):
    right = get - left
    values = jewels[left:] + jewels[:N+1-right]
    sum_v = sum(values)
    minus_values = values.filter(lambda x: x<0)
    minus_values.sort()
    cnt = 0
    for v in minus_values:
      sum_v -= v
    ans = max(ans, sum_v)
print(ans)
    
  

Fixed submission:
N, K = map(int, input().split())
jewels = list(map(int, input().split())) + [0]
ans = 0
for get in range(1, min(N, K)+1):
  put = min(get, K-get)
  for left in range(get+1):
    right = get - left
    values = jewels[:left] + jewels[N-right:]
    sum_v = sum(values)
    minus_values = list(filter(lambda x: x<0, values))
    minus_values.sort()
    cnt = 0
    for v in minus_values:
      if cnt < put:
        sum_v -= v
        cnt += 1
      else:
          break
    ans = max(ans, sum_v)
print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
for get in range(K+1):
    put = K - get
    for right in range(get+1):
        left = get - right
        jewels = A[:right] + A[N-left:]
        jewels.sort()
        value = sum(jewels)
        for i in range(get):
            if i + 1 > put:
                break
            if jewels[i] < 0:
                value += abs(jewels[i])
            else:
                break
        ans = max(ans, value)
print(ans)

Fixed submission:
N, K = map(int, input().split())
jewels = list(map(int, input().split())) + [0]
ans = 0
for get in range(1, min(N, K)+1):
  put = min(get, K-get)
  for left in range(get+1):
    right = get - left
    values = jewels[:left] + jewels[N-right:]
    sum_v = sum(values)
    minus_values = list(filter(lambda x: x<0, values))
    minus_values.sort()
    cnt = 0
    for v in minus_values:
      if cnt < put:
        sum_v -= v
        cnt += 1
      else:
          break
    ans = max(ans, sum_v)
print(ans)