Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02684 (python)

Fixed submission:
# D
N, K = map(int, input().split())
A = list(map(int, input().split()))
dct = {i+1:a for i,a in enumerate(A)}
visited = [0] * N
visited[0] = 1
if (K <= 2 * 10**5):
    nex = 1
    for _ in range(K):
        nex = dct[nex]
    print(nex)
else:
    cnt = 0
    nex = 1
    for _ in range(N):
        cnt += 1
        nex = dct[nex]
        visited[nex-1] += 1
        if visited[nex-1] > 1:
            break
    cnt1 = 0
    nex1 = 1
    for _ in range(N):
        cnt1 += 1
        nex1 = dct[nex1]
        if nex1 == nex:
            break
    if (cnt - cnt1) == 0:
        print(1)
    else:
        l = (K - cnt1) % (cnt - cnt1)
        for i in range(l):
            nex = dct[nex]
        print(nex)

Buggy submission (verdict: Runtime Error):
# D
N, K = map(int, input().split())
A = list(map(int, input().split()))
dct = {i+1:a for i,a in enumerate(A)}
visited = [0] * N
visited[0] = 1
if (K <= 2 * 10**5):
    nex = 1
    for _ in range(K):
        nex = dct[nex]
    print(nex)
else:
    cnt = 0
    nex = 1
    for _ in range(N):
        cnt += 1
        nex = dct[nex]
        visited[nex-1] += 1
        if visited[nex-1] > 1:
            break
    cnt1 = 0
    nex1 = 1
    for _ in range(N):
        cnt1 += 1
        nex1 = dct[nex1]
        if nex1 == nex:
            break
    l = (K - cnt1) % (cnt - cnt1)
    for i in range(l):
        nex = dct[nex]
print(nex)

Buggy submission (verdict: Runtime Error):
# D
N, K = map(int, input().split())
A = list(map(int, input().split()))
dct = {i+1:a for i,a in enumerate(A)}
visited = [0] * N
visited[0] = 1
cnt = 0
if (K <= 2 * 10**5):
    nex = 1
    for _ in range(K):
        nex = dct[nex]
else:
    nex = 1
    for _ in range(N):
        cnt += 1
        nex = dct[nex]
        visited[nex-1] += 1
        if visited[nex-1] > 1:
            break
    cnt1 = 0
    nex1 = 1
    for _ in A:
        cnt1 += 1
        nex1 = dct[nex1]
        if nex1 == nex:
            break
    l = (K - cnt1) % (cnt - cnt1)
    for i in range(l):
        nex = dct[nex]
print(nex)
Problem p02732 (python)

Fixed submission:
# D
import collections

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

N = int(input())
A = list( map(int,input().split()))
c = dict(collections.Counter(A))
su = 0
for i in c.values():
    if (i >= 2):
        su += combinations_count(i, 2)

for i in A:
    if (c[i]  >= 3):
        print(su - combinations_count(c[i],2) + combinations_count(c[i]-1,2))
    elif (c[i] == 2):
        print(su - 1)
    else:
        print(su)

Buggy submission (verdict: Runtime Error):
# D
import collections

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def combination_count(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res
N = int(input())
A = list( map(int,input().split()))
c = dict(collections.Counter(A))
su = 0
for i in c.values():
    if (i >= 2):
        su += combinations_count(i, 2)

for i in A:
    if (c[i]  >= 3):
        print(su - combinations_count(c[i],2) + combinations_count(c[i]-1,2))
    elif (c[i] == 2):
        print(su - 1)
    else:
        print(su)
Problem p02837 (python)

Fixed submission:
N = int(input())
lst = [[] for i in range(N)]
for i in range(N):
  for j in range(int(input())):
    lst[i].append(list(map(int,input().split())))
ans = 0
for i in range(2**N):
  flag = True
  bin_lst = list(bin(i)[2:].zfill(N))
  for idx,j in enumerate(bin_lst):
    if (j == '1'):
      for v, w in lst[idx]:
        if (bin_lst[v-1] != str(w)):
          flag = False
  if (flag):
    ans = max(ans,bin_lst.count('1'))
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
lst = []
for i in range(N):
  for j in range(int(input())):
    lst.append(list(map(int,input().split())))
ans = 0
for i in range(2**N):
  flag = True
  bin_lst = list(bin(i)[2:].zfill(N))
  for idx,j in enumerate(bin_lst):
    if (j == '1'):
      for v, w in zip(lst[idx][:-1],lst[idx][1:]):
        if (bin_lst[v-1] != str(w)):
          flag = False
  if (flag):
    ans = max(ans,bin_lst.count('1'))
print(ans)
Problem p02844 (python)

Fixed submission:
N = int(input())
s = input()
ans = 0
for i in range(1000):
  code = str(i).zfill(3)
  f = 0
  for j in range(len(s)):
    if (s[j] == code[f]):
      f += 1
    if (f == 3):
      break
  if (f == 3):
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
s = input()
ans = 0
for i in range(1000):
  num = str(i).zfill(3)
  flag1 = True
  flag2 = True
  flag3 = True
  first = -1
  second = -1
  third = -1
  for j in range(s):
    if (s[j] == num[0] and flag1):
      first = j
      flsg1 = False
    if (s[j] == num[1] and j > first and flag2):
      second = j
      flsg2 = False
    if (s[j] == num[2] and j > second and flag3):
      second = j
      flsg3 = False
  if (first != -1 and second != -1 and third != -1):
    ans += 1
print(ans)
Problem p02969 (python)

Fixed submission:
r = int(input())

print(3 * r **2)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = 0
lst = list(map(int, input().split()))
slice_lst = lst[:int(N / 2)]
for i,k in enumerate(reversed(slice_lst)):
  sub_lst = lst[len(slice_lst)-i-1:len(lst):len(slice_lst)-i]
  if (k != sum(sub_lst) % 2):
    if (k == 0):
      lst[len(slice_lst)-i-1] = 1
    else:
      ans = -1
      break

if (ans == -1):
  print(ans)
else:
  ans_lst = []
  for i,k in enumerate(lst):
    if (k == 1):
      ans_lst.append(str(i+1))
  print(len(ans_lst))
  result = ' '.join(ans_lst)
  print(result)
Problem p03037 (python)

Fixed submission:
N, M = map(int, input().split())
l, r = map(int, input().split())
cnt = 0
num = 0
if (l == r):
  cnt += 1
  num = l
for i in range(M-1):
  L, R = map(int, input().split())
  if (cnt == 1 and L == R and num == L):
    num = L
  elif (cnt == 1 and L == R and num != L):
    cnt += 1
    print(0)
    break
  elif (cnt == 0 and L == R):
    cnt += 1
    num = L
  elif ((cnt == 0 or cnt == 1) and L != R):
    if (L >= l):
      l = L
    if (R <= r):
      r = R
      
if (l > r and (cnt == 0 or cnt == 1)):
  print(0)
elif(l <= r and (cnt == 0 or cnt == 1)):
  if (num != 0 and cnt == 1):
    if (num >= l and num <= r):
      print(1)
    else:
      print(0)
  elif(cnt == 0 or cnt == 1):
    print(r - l + 1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
l, r = map(int, input().split())
for i in range(M-1):
  L, R = map(int, input().split())
  if (L >= l):
    l = L
  if (R =< r):
    r = R
print(r - l + 1)
Problem p03047 (python)

Fixed submission:
N, K = map(int, input().split())
print(N-K+1)

Buggy submission (verdict: Runtime Error):
lst = list(map(int, input().split()))
N = lst.pop(3)
lst.sort(reverse=True)
R,G,B = lst
sum = 0
for i in range(int(N / R) + 1):
  for j in range(int((N - (i * R)) / G) + 1):
    for k in range(int((N - (i * R) - (j * G)) / B) + 1):
      ans = i * R + j * G + k * B
      if (ans == N):
        sum += 1
print(sum)
Problem p03076 (python)

Fixed submission:
array1 = [int(input()) for i in range(5)]
array2 = [i for i in array1 if i % 10 == 0]
array3 = [i for i in array1 if i % 10 != 0]
array4 = [i % 10 for i in array3]
sum1 = 0
sum2 = sum(array2)
if (len(array3) != 0):
  idx = array4.index(min(array4))
  for k, i in enumerate(array3):
    if (k == idx):
      sum1 += i
    else:
      sum1 += i + (10 - i % 10)
print(sum1 + sum2)

Buggy submission (verdict: Runtime Error):
array1 = [int(input()) for i in range(5)]
array2 = [i for i in array1 if i % 10 == 0]
array3 = [i for i in array1 if i % 10 =! 0]
array4 = [i % 10 for i in array3]
sum1 = 0
sum2 = sum(array2)
if (len(array3) != 0):
  idx = array4.index(min(array4))
  for k, i in enumerate(array3):
    if (k == idx):
      sum1 += i
    else:
      sum1 += i + (10 - i % 10)
print(sum1 + sum2)

Buggy submission (verdict: Runtime Error):
array1 = [int(input()) for i in range(5)]
array2 = [i for i in array1 if i % 10 == 0]
array3 = [i for i in array1 if i % 10 != 0]
array4 = [i % 10 for i in array3]
idx = array4.index(min(array4))
sum1 = 0
sum2 = sum(array2)
for k, i in enumerate(array3):
  if (k == idx):
    sum1 += i
  else:
    sum1 += i + (10 - i % 10)
print(sum1 + sum2)

Buggy submission (verdict: Runtime Error):
array1 = [int(input()) for i in range(5)]
array2 = [i for i in array1 if i % 10 == 0]
array3 = [i for i in array1 if i % 10 =! 0]
array4 = [i % 10 for i in array3]
idx = array4.index(min(array4))
sum1 = 0
sum2 = sum(array2)
for k, i in enumerate(array3):
  if (k == idx):
    sum1 += i
  else:
    sum1 += i + (10 - i % 10)
print(sum1 + sum2)

Buggy submission (verdict: Runtime Error):
array1 = [int(input()) for i in range(5)]
array2 = [i % 10 for i in array1]
array3 = [i for i in array2 if i != 0]
idx = array3.index(min(array3))
sum1 = 0
sum2 = sum(array2)
for k, i in enumerate(array3):
  if (k == idx):
    sum1 += i
  else:
    sum1 += i + (10 - i % 10)
print(sum1 + sum2)

Buggy submission (verdict: Runtime Error):
array = [int(input()) for i in range(5)]
array_sub = [i % 10 for i in array]
new_lst = [i for i in array_sub if i != 0]
minimum = min(new_lst)
sum = 0
for i in array:
  if (i % 10 == 0):
    sum += i
  else:
    if (i % 10 == minimum):
      sum += i
    else:
      sum += (i + (10 - (i % 10)))
print(sum)

Buggy submission (verdict: Runtime Error):
array = [int(input()) for i in range(5)]
array_sub = [i % 10 for i in array]
new_lst = [i for i in array_sub if i != 0]
minimum = min(new_lst)
sum = 0
for i in array:
  if (i % 10 == minimum):
    sum += i
  else:
    sum += i + (10 - i % 10)
print(sum)

Buggy submission (verdict: Runtime Error):
array = [int(input()) for i in range(5)]
array_sub = [i % 10 for i in array]
new_lst = [i for i in array_sub if i != 0]
minimum = min(new_lst)
sum = 0
for i in array:
  if (i % 10 == minimum):
    sum += i
  else 
  	sum += i + (10 - i % 10)
print(sum)
Problem p03085 (python)

Fixed submission:
b = input()
 
if (b == 'A'):
  print('T')
elif (b == 'T'):
  print('A')
elif (b == 'C'):
  print('G')
elif (b == 'G'):
  print('C')

Buggy submission (verdict: Runtime Error):
n,q = map(int, input().split())
str = input()
for i in range(q):
  l,r = map(int, input().split())
  sub_str = str[(l-1):r]
  count = 0
  for j in range(len(sub_str)):
    if (sub_str[j:j+2] == 'AC'):
      count += 1
  print(count)
Problem p03087 (python)

Fixed submission:
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
  t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1] - t[l-1])

Buggy submission (verdict: Runtime Error):
import re
 
a = []
for i in range(5):
    a.append(input().split())
n = int(a[0][0])
q = int(a[0][1])
str = a[1][0]
b = a[2:]
for i in b:
  l = int(i[0])
  r = int(i[1])
  sub_str = str[(l-1):r]
  print(len(re.findall('AC', sub_str)))

Buggy submission (verdict: Runtime Error):
import re

a = []
for i in range(5):
    a.append(input().split())
n = int(a[0][0])
q = int(a[0][1])
str = a[1][0]
b = a[2:]
for i in b:
  l = int(i[0])
  r = int(i[1])
  sub_str = str[(l-1):r]
  print(len(re.findall('AC', sub_str)))
Problem p03101 (python)

Fixed submission:
H,W = map(int, input().split())
h,w = map(int, input().split())

sum = H * W
cnt = (W * h) + (w * (H - h))
print(sum - cnt)

Buggy submission (verdict: Runtime Error):
H,W = map(int, input())
h,w = map(int, input())

sum = H * w
cnt = W * h + w * (H - h)
print(sum - cnt)
Problem p03106 (python)

Fixed submission:
def cd(a,b):
  p = min(a,b)
  q = max(a,b)
  lst = []
  for i in range(1, p + 1):
    if (p % i == 0 and q % i == 0):
      lst.append(i)
  return lst
 
A,B,K = map(int, input().split())
lst = cd(A,B)
print(lst[-K])

Buggy submission (verdict: Runtime Error):
def cd(a,b):
  p = min(a,b)
  q = max(a,b)
  lst = []
  for i in range(1, p + 1):
    if (p % i == 0 and q % i == 0):
      lst.append(i)
  return lst
 
A,B,K = map(int, input().split())
lst = cd(A,B)
print(lst[-1 - K-1])
Problem p03125 (python)

Fixed submission:
A, B = map(int, input().split())
if (B % A == 0):
  print(A + B)
else:
  print(B - A)

Buggy submission (verdict: Runtime Error):
N = int(input())
lst = list(map(int, input().split()))
boolean = False
updated_lst = []
minimum = min(lst)
min_num = 0
for i in lst:
  num = i % minimum
  if (i != minimum):
    updated_lst.append(num)
  else:
    updated_lst.append(minimum)
    min_num += 1
  if (num % 2 == 1):
    boolean = True

if (min_num == len(lst)):
  print(minimum)
else:
  if (boolean):
    print(1)
  else:
    print(min(updated_lst))
Problem p03146 (python)

Fixed submission:
s = int(input())
lst = []
lst.append(s)
cnt = 1
while (True):
  cnt += 1
  if (s % 2 == 0):
    s = int(s / 2)
  else:
    s = int(3*s + 1)
  if (s not in lst):
    lst.append(s)
  else:
    break
print(cnt)

Buggy submission (verdict: Runtime Error):
s = int(input())
lst = []
cnt = 0
While True:
  cnt += 1
  if (s % 2 == 0):
    s = int(s / 2)
  else:
    s = int(3*s + 1)
  lst.append(s)
  if (s in lst):
    break
print(cnt)
Problem p03147 (python)

Fixed submission:
N = int(input())

lst = list(map(int, input().split()))

ans = 0
for i in range(len(lst)-1):
  if (lst[i+1] > lst[i]):
    ans += lst[i+1] - lst[i]
print(ans + lst[0])

Buggy submission (verdict: Runtime Error):
N = int(input())
lst = list(map(int, input().split()))
boolean = False
updated_lst = []
minimum = min(lst)
min_num = 0
for i in lst:
  num = i % minimum
  if (i != minimum):
    updated_lst.append(num)
  else:
    updated_lst.append(minimum)
    min_num += 1
  if (num % 2 == 1):
    boolean = True

if (min_num == len(lst)):
  print(minimum)
else:
  if (boolean):
    print(1)
  else:
    print(2)
Problem p03238 (python)

Fixed submission:
N = int(input())
if (N == 1):
  print('Hello World')
else:
  lst = [int(input()) for i in range(N)]
  print(sum(lst))

Buggy submission (verdict: Runtime Error):
N = int(input())
lst = [int(input()) for i in range(2)]
if (N == 1):
    print('Hello World')
else:
    print(sum(lst))

Buggy submission (verdict: Runtime Error):
N = int(input())
lst = [int(input()) for i in range(N)]
if (N == 1):
    print('Hello World')
else:
    print(sum(lst))

Buggy submission (verdict: Runtime Error):
N = int(input())
lst = [int(input()) for i in range(N)]
if (N == 1):
    print('Hello World')
else:
    print(sum(lst))
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())

n = 5 * 10 ** 15
l = 0
ans = 0
for i in S:
  if (int(i) != 1):
    ans = int(i)
    break
  else:
    l += 1
if (l >= K):
  ans = 1

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())

n = 5 * 10 ** 15

for i in S:
  if (int(i) != 1):
    ans = int(i)
    break
print(ans)
Problem p03294 (python)

Fixed submission:
N = int(input())

lst = list(map(int, input().split()))

sum = 0
for i in lst:
  sum += i-1
print(sum)

Buggy submission (verdict: Runtime Error):
lst = list(map(int, input().split()))

lst.sort(reverse=True)
print(abs(lst[0] - lst[1]) + abs(lst[1] - lst[2]))
Problem p03353 (python)

Fixed submission:
s = input()
K = int(input())
S = set()
ans = []
for i in range(K):
  for j in range(len(s)-i):
    c = s[j:j+i+1]
    S.add(c)
  
set_ans = sorted(list(S))
print(set_ans[K-1])

Buggy submission (verdict: Runtime Error):
s = input()
K = int(input())

ans = []
for i in range(K):
  for j in range(len(s)-i):
    c = s[j:j+i+1]
    if (i != 0 and c.count(c[0]) == len(c)):
      c = "".join(set(c))
    ans.append(c)
  
set_ans = sorted(set(ans))
print(set_ans[K-1])

Buggy submission (verdict: Runtime Error):
s = input()
K = int(input())

ans = []
flg = False
for i in range(len(s)):
  for j in range(len(s)-i):
    c = s[j:j+i+1]
    if (len(c) > K):
      flg = True
      break
    if (i != 0 and c.count(c[0]) == len(c)):
      c = "".join(set(c))
    ans.append(c)
  if flg:
    break
  
set_ans = list(set(ans))
set_ans.sort()
print(set_ans[K-1])

Buggy submission (verdict: Runtime Error):
s = input()
K = int(input())

ans = []
flg = False
for i in range(len(s)):
  for j in range(len(s)-i):
    c = s[j:j+i+1]
    if (len(c) > K):
      flg = True
      break
    if (i != 0 and c.count(c[0]) == len(c)):
      c = c[0]
    ans.append(c)
  if flg:
    break
  
set_ans = list(set(ans))
set_ans.sort()
print(set_ans[K-1])

Buggy submission (verdict: Runtime Error):
s = input()
K = int(input())

ans = []
flg = False
for i in range(len(s)):
  for j in range(len(s)-i):
    c = s[j:j+i+1]
    if (i != 0 and c.count(c[0]) == len(c)):
      c = c[0]
    ans.append(c)
    
set_ans = list(set(ans))
set_ans.sort()
print(set_ans[K-1])

Buggy submission (verdict: Runtime Error):
s = input()
K = int(input())

ans = []
for i in range(len(s)):
  for j in range(len(s)-i):
    c = s[j:j+i+1]
    if c.count(c[0]) == len(c):
      c = c[0]
    if c not in ans:
      ans.append(s[j:j+i+1])
ans.sort()
print(ans[K-1])

Buggy submission (verdict: Runtime Error):
import itertools

s = input()
K = int(input())

ans = []
for i in range(1, len(s)+1):
  for j in list(itertools.combinations(s,i)):
    c = "".join(j)
    if (len(c) == c.count(c[0])):
      c = c[0]
    if c not in ans:
      ans.append(c)
print(ans[-K])
Problem p03611 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
dct = {}
for i in range(-1,10**5+1):
  dct[i] = 0
for i in A:
  dct[i-1] += 1
  dct[i] += 1
  dct[i+1] += 1

sorted_dct = sorted(dct.items(), key=lambda x:-x[1])
print(sorted_dct[0][1])

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
dct = {}
for i in range(-1,10**5):
  dct[i] = 0
for i in A:
  dct[i-1] += 1
  dct[i] += 1
  dct[i+1] += 1

sorted_dct = sorted(dct.items(), key=lambda x:-x[1])
print(sorted_dct[0][1])

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
dct = {}
for i in range(10**5):
  dct[i] = 0
for i in A:
  dct[i-1] += 1
  dct[i] += 1
  dct[i+1] += 1

sorted_dct = sorted(dct.items(), key=lambda x:-x[1])
print(sorted_dct[0][1])
Problem p03612 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(len(A)-1):
  if (i+1 == A[i]):
    ans += 1
    A[i],A[i+1] = A[i+1],A[i]
if (A[-1] == len(A)):
  ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(len(A)-1):
  if (i+1 == A[i]):
    ans += 1
    A[i],A[i+1] = A[i+1],A[i]
if (A[-1] == l):
  ans += 1
print(ans)
Problem p03659 (python)

Fixed submission:
from itertools import accumulate

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

cumsum = list(accumulate(lst))

mi = 2 * 10 ** 9
su = cumsum[-1]
for i in range(len(cumsum)-1):
  mi = min(mi, abs(cumsum[i] - (su-cumsum[i])))
print(mi)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate

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

cumsum = list(accumulate(lst))

mi = 2 * 10 ** 9
su = cumsum[-1]
for i in cumsum:
  mi = min(mi, abs(i - (su-i))
print(mi)
Problem p02708 (python)

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

min = K*(K-1)/2
max = K*(2*N-K+1)/2


sum=0
for k in range(K,N+2):
    min = k*(k-1)/2
    max = k*(2*N-k+1)/2

    sum+=(int(max-min+1))
print(sum%(10**9+7))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
import math
import itertools



def cal(num, r, count):

    for v in itertools.combinations(range(num), r):
        count[sum(v)] += 1
    real_count = 0
    for i in count:
        if i>0:
            real_count += 1

    return real_count

total = 0
while K<=N+1:
    count = [0]*1000000000
    total += cal(N+1, K,count)
    K+=1

total = total % (10**9+7)
print(total)
Problem p02727 (python)

Fixed submission:
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p_sort = sorted(p, reverse=True)
q_sort = sorted(q, reverse=True)
r_sort = sorted(r, reverse=True)

del p_sort[X:]
del q_sort[Y:]

total_list = p_sort + q_sort + r_sort
total_list_sort = sorted(total_list, reverse=True)
del total_list_sort[(X+Y):]
print(sum(total_list_sort))

Buggy submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

import copy

pp = p[:]
qq = q[:]
rr = r[:]

count = 0
another_count = 0

check_r = []
check_g = []
# 赤く塗り替える
# 赤いりんごX
for i in range(X):
    max_red = 0
    if max(p)>=max(r):
        max_red = max(p)
        p.remove(max_red)
    else:
        max_red = max(r)
        check_r.append(max_red)
        r.remove(max_red)

    count += max_red


# 緑のりんごY
for i in range(Y):
    max_green = 0
    if max(q)>=max(r):
        max_green = max(q)
        q.remove(max_green)
    else:
        max_green = max(r)
        r.remove(max_green)
    count += max_green

#
# # 緑に塗り替える
# # 緑のりんごY
# for i in range(Y):
#     max_green = 0
#     if max(qq)>=max(rr):
#         max_green = max(qq)
#         qq.remove(max_green)
#     else:
#         max_green = max(rr)
#
#         rr.remove(max_green)
#
#     another_count += max_green
#
#
# # 赤いりんごX
# for i in range(X):
#     max_red = 0
#     if max(pp)>=max(rr):
#         max_red = max(pp)
#         pp.remove(max_red)
#     else:
#         max_red = max(rr)
#         check_g.append(max_red)
#         rr.remove(max_red)
#     another_count += max_red

print(count)
# print(another_count)
Problem p02761 (python)

Fixed submission:
N,M = map(int,input().split())
S=[]
C=[]
for i in range(M):
    s,c = map(int,input().split())
    S.append(s)
    C.append(c)
not_ans=0
ans = 0
C_check = []
S_check = []
for i in range(M):
    j = (N-S[i])
    if S[i] in S_check:
        index = S_check.index(S[i])
        if C[i]!=C[index]:
            not_ans = '-1'
            break
        continue
    if S[i] < N:
        if S[i]==1 and C[i]==0:
            not_ans = '-1'
            break
    if N < S[i]:
        not_ans = '-1'

    ans += 10**j*C[i]
    S_check.append(S[i])

if not 1 in S_check:
    ans += 10**(N-1)

if N==1 and M==0:
    ans = 0




if not_ans=='-1':
    print(not_ans)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
S=[]
C=[]
for i in range(M):
    s,c = map(int,input().split())
    S.append(s)
    C.append(c)

ans = 0
C_check = []
S_check = []
for i in range(M):
    j = (N-S[i])
    if S[i] in S_check:
        index = S_check.index(S[i])
        if C[i]!=C[index]:
            ans = '-1'
            break
        continue
    if S[i] < N:
        if S[i]==1 and C[i]==0:
            ans = '-1'
            break

    ans += 10**j*C[i]
    S_check.append(S[i])

if not 1 in S_check:
    ans += 10**(N-1)





print(ans)
Problem p02946 (python)

Fixed submission:
k, x = map(int, input().split())
for i in range(x-k+1 , x+k):
    print(str(i)+' ', end='')

Buggy submission (verdict: Runtime Error):

k, x = map(int, input().split())
for i in range(x-k+1 , x+k):
    print(i+' ', end='')
Problem p02702 (python)

Fixed submission:


def solve():

    s = input()
    mod = 2019
    remains = [0]*mod

    ans = 0
    now = 0
    remains[0] = 1
    for i, val in enumerate(s[::-1]):
        now += int(val) * pow(10, i, mod)
        now %= mod
        ans += remains[now]
        remains[now] += 1

    print(ans)


if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):


anslist = []


def solve():

    S = input()

    def dfs(s, start, end):
        global anslist
        if end == len(s)+1:
            return

        if int(s[start:end]) % 2019 == 0:
            anslist.append(str(start)+str(end))

        dfs(s, start, end+1)
        dfs(s, start+1, end+1)

    dfs(S, 0, 4)
    print(len(set(anslist)))


if __name__ == "__main__":
    solve()