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

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

A.sort()
BC.sort(key=lambda x: x[1],reverse=True)

ans = 0
cnt = 0
for i in BC:
  for _ in range(i[0]):
#    print(len(A), cnt)
    if A[cnt] < i[1]:
      ans += i[1]
    else:
      ans += A[cnt]
    cnt += 1
    if len(A) < cnt+1:
      print(ans)
      exit()
#    print(i, _, ans, cnt)
if cnt  < len(A):
  ans += sum(A[cnt - len(A):])

#print(A)
#print(BC)
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

tank = []

idx = 0
while (len(tank) < n + 1) and (idx < m):
  for _ in range(BC[idx][0]): 
    heapq.heappush(tank, -BC[idx][1])
  idx +=  1

# print(A)
# print(BC)
# print(tank)

ans = 0
p = -heapq.heappop(tank)
for a in A:
  if p > a:
    ans += p
    p = -heapq.heappop(tank)
  else:
    ans += a

print(ans)
Problem p03075 (python)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if e-a <= k:
  ans = 'Yay!'
else:
  ans = ':('
print(ans)

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

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

AB = [0] * (K * K)
for itra, a in enumerate(A):
  if itra >= K:
    break
  for itrb, b in enumerate(B):
    AB[itra * K + itrb] = (a + b)
    if itrb >= K - 1:
      break
    
AB.sort(reverse=True)    
    
ABC = [0] * (K * K)
for itrab, ab in enumerate(AB):
  if itrab >= K:
    break
  for itrc, c in enumerate(C):
    ABC[itrab * K + itrc] = (ab + c)
    if itrc >= K - 1:
      break
    
ABC.sort(reverse=True)
for itr, i in enumerate(ABC):
  print(i)
  if itr >= K - 1:
    break
Problem p03426 (python)

Fixed submission:
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for _ in range(Q)]

li = [[]] * (H * W)
for i in range(H):
  for j in range(W):
    li[A[i][j] - 1] = [j, i]

cost = [[0 for _ in range((H * W) // D + 1)] for _ in range(D)]
for i in range(H * W):
  d, m = divmod(i, D)
  if d > 0:
    cost[m][d] = cost[m][d - 1] + abs(li[i][0] - li[i - D][0]) + abs(li[i][1] - li[i - D][1]) 

# print(cost)

for l, r in LR:
  print(cost[(l - 1) % D][(r - 1) // D] - cost[(l - 1) % D][(l - 1) // D])

Buggy submission (verdict: Runtime Error):
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for _ in range(Q)]

li = [[]] * (H * W)
for i in range(H):
  for j in range(W):
    li[A[i][j] - 1] = [j, i]

cost = [[0 for _ in range(H * W)] for _ in range(D)]
for i in range(H * W):
  d, m = divmod(i, D)
  if d > 0:
    cost[m][d] = cost[m][d - 1] + abs(li[i][0] - li[i - D][0]) + abs(li[i][1] - li[i - D][1]) 

# print(cost)

for l, r in LR:
  print(cost[(l - 1) % D][r // D] - cost[(l - 1) % D][l // D])
Problem p03137 (python)

Fixed submission:
# -*- coding: utf-8 -*-
 
n, m = map(int, input().split())
l = sorted(list(map(int, input().split())))
divcount = n - 1
 
l1 = l[1:]
l2 = l[:m - 1]
divl = []
 
for i in range(m - 1):
    divl.append(l1[i] - l2[i])
 
divl.sort(reverse = True)
 
if n == 1:
    print(max(l) - min(l))
else:
    if m > n:
        for i in range(divcount):
            del divl[0]
    
        print (sum(divl))
    
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
 
n, m = map(int, input().split())
l = sorted(list(map(int, input().split())))
divcount = n - 1
 
l1 = l[1:]
l2 = l[:m - 1]
divl = []
 
for i in range(m - 1):
    divl.append(l1[i] - l2[i])
 
divl.sort(reverse = True)
 
if n == 1:
    print(max(l) - min(l))
else:
    for i in range(divcount):
        del divl[0]
    
    print (sum(divl))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from itertools import starmap

n, m = map(int, input().split())
l = sorted(list(map(int, input().split())))
divcount = n - 1

if n == 1:
    print(max(l) - min(l))
else:
    divl = sorted(list(starmap(lambda a,b: a - b, zip(l[1:], l[:m - 2])), reverse = True)
    for i in range(divcount):
        del divl[0]
    
    print (sum(divl))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

n, m = map(int, input().split())
l = sorted(list(map(int, input().split())))
divcount = n - 1

l1 = l[1:]
l2 = l[:m - 1]
divl = []

for i in range(m - 1):
    divl.append(l1[i] - l2[i])

divl.sort(reverse = True)

if n == 1:
    print(max(l) - min(l))
else:
    for i in range(divcount):
        del divl[0]
    
    print (sum(divl))
Problem p02622 (python)

Fixed submission:
s = input()
t = input()
n = len(s)
ans = 0
for i in range(n):
	if s[i] is not t[i]:
		ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
n = len(s)
ans = 0
for i in range(n):
	if s[i] is not t[i]:
		ans += 1
print(ans)
Problem p02699 (python)

Fixed submission:
sheep, wolves = map(int, input().split())
print("unsafe" if wolves >= sheep else "safe")

Buggy submission (verdict: Runtime Error):
s, w = map(int, input().split())
if w >= s:
  	print("unsafe")
else:
  	print("safe)
Problem p02757 (python)

Fixed submission:
from collections import Counter
N, P = map(int, input().split())
S = input()

ans = 0
if P in [2, 5]:
    for i, c in enumerate(S):
        if int(c) % P == 0:
            ans += i + 1
else:
    ct = Counter()
    ct[0] = 1
    prevmod = 0
    mods = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    for i in range(N-1, -1, -1):
        n = int(S[i])
        mod = (mods[n] + prevmod) % P
        ans += ct[mod]
        ct[mod] += 1
        prevmod = mod
        mods = [10 * a % P for a in mods]
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N, P = map(int, input().split())
S = input()
L = len(str(P))
M = []
for i in range(10 ** (L+1)):
    M.append(i % P)

q = Counter([int(S[i:L-1]) for i in range(L-1)])
q[0] += 1
ans = 0
for i in range(L-1, N):
    nq = Counter()
    n = int(S[i])
    for a, c in q.items():
        s = M[a * 10 + n]
        if s == 0:
            ans += c
        nq[s] += c
    nq[0] += 1
    q = nq
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N, P = map(int, input().split())
S = input()
L = len(str(P))
M = []
for i in range(10 ** L):
    M.append(i % P)

q = Counter([int(S[i:L-1]) for i in range(L-1)])
q[0] += 1
ans = 0
for i in range(L-1, N):
    nq = Counter()
    n = int(S[i])
    for a, c in q.items():
        s = (a * 10 + n) % P
        if s == 0:
            ans += c
        nq[s] += c
    nq[0] += 1
    q = nq
print(ans)
Problem p02831 (python)

Fixed submission:
import fractions
A, B = map(int, input().split())
print(A * B // fractions.gcd(A, B))

Buggy submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())
print(A * B // math.gcd(A, B))
Problem p02987 (python)

Fixed submission:
from collections import Counter
ct = Counter(input())
a = ct.most_common(2)
if len(a) == 2 and a[0][1] == 2 and a[1][1] == 2:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
from collections import Counter
ct = Counter(input())
a1, a2 = ct.most_common(2)
if a1[1] == 2 and a2[1] == 2:
  print('Yes')
else:
  print('No')
Problem p03291 (python)

Fixed submission:
from collections import Counter
S = input()
MOD = 10 ** 9 + 7
ans = 0
front = [0, 0, 0, 0]
back = [0, 0, 0, 0]
m = { 'A': 0, 'B': 1, 'C': 2, '?': 3 }
for c in S:
  back[m[c]] += 1

pow3 = [1]
for i in range(max(3, back[3])):
  pow3.append((pow3[-1] * 3) % MOD)

for i in range(len(S)):
  c = S[i]
  back[m[c]] -= 1
  # Bの位置を固定
  if c == 'B' or c == '?':
    fbsum = front[3] + back[3]
    # ?を使わない
    ans += front[0] * back[2] * (pow3[fbsum])
    # Aだけ?をつかう
    ans += front[3] * back[2] * (pow3[fbsum - 1])
    # Cだけ?をつかう
    ans += front[0] * back[3] * (pow3[fbsum - 1])
    # 両方?をつかう
    ans += front[3] * back[3] * (pow3[fbsum - 2])
    ans %= MOD
  front[m[c]] += 1

print(int(ans))

Buggy submission (verdict: Runtime Error):
from collections import Counter
S = input()
MOD = 10 ** 9 + 7
ans = 0
front = Counter({})
back = Counter(S)
pow3 = [1]
for i in range(back['?']):
  pow3.append(pow3[-1] * 3)

for i in range(len(S)):
  c = S[i]
  back[c] -= 1
  # Bの位置を固定
  if c == 'B' or c == '?':
    # ?を使わない
    ans += front['A'] * back['C'] * (pow3[front['?'] + back['?']])
    # Aだけ?をつかう
    ans += front['?'] * back['C'] * (pow3[front['?'] + back['?'] - 1])
    # Cだけ?をつかう
    ans += front['A'] * back['?'] * (pow3[front['?'] + back['?'] - 1])
    # 両方?をつかう
    ans += front['?'] * back['?'] * (pow3[front['?'] + back['?'] - 2])
    ans %= MOD
  front[c] += 1

print(int(ans))
Problem p03329 (python)

Fixed submission:
N = int(input())
vals = [1]

tmp = 6
while tmp <= 100000:
  vals.append(tmp)
  tmp *= 6

tmp = 9
while tmp <= 100000:
  vals.append(tmp)
  tmp *= 9

vals.sort()

dp = [0] + [float('inf')] * N
for n in range(1, N+1):
  i = 0
  while i < len(vals) and vals[i] <= n:
    dp[n] = min(dp[n], dp[n-vals[i]]+1)
    i += 1

print(dp[N])

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
vals = [1]

tmp = 6
while tmp <= 100000:
  vals.append(tmp)
  tmp *= 6

tmp = 9
while tmp <= 100000:
  vals.append(tmp)
  tmp *= 9

vals.sort()

dp = [0] + [float('inf')] * N
for n in range(1, N+1):
  i = 0
  while vals[i] <= n:
    dp[n] = min(dp[n], dp[n-vals[i]]+1)
    i += 1

print(dp[N])
Problem p03332 (python)

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

MOD = 998244353
factorials = [1]
inv_facts = [1]
for i in range(1, N+1):
    factorials.append(factorials[-1] * i % MOD)
    inv_facts.append(inv_facts[-1] * pow(i, MOD-2, MOD) % MOD)

def combi(n, k):
    ret = factorials[n]
    ret *= inv_facts[k]
    ret %= MOD
    ret *= inv_facts[n-k]
    ret %= MOD
    return ret

ans = 0
for a in range(N+1):
    rest = K - (A * a)
    if rest < 0:
        break
    if rest % B == 0:
        b = rest // B
        if b <= N:
            tmp = combi(N, a) * combi(N, b) % MOD
            ans += tmp
            ans %= MOD
print(ans)

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

MOD = 998244353
factorials = [1]
inv_facts = [1]
for i in range(1, N+1):
    factorials.append(factorials[-1] * i % MOD)
    inv_facts.append(inv_facts[-1] * pow(i, MOD-2, MOD) % MOD)

def combi(n, k):
    ret = factorials[n]
    ret *= inv_facts[k]
    ret %= MOD
    ret *= inv_facts[n-k]
    ret %= MOD
    return ret

ans = 0
for a in range(N+1):
    rest = K - (A * a)
    if rest >= 0 and rest % B == 0:
        b = rest // B
        tmp = combi(N, a) * combi(N, b) % MOD
        ans += tmp
        ans %= MOD
print(ans)
Problem p02880 (python)

Fixed submission:
n =int(input())
if n<10:
    print("Yes")
    exit()

for i in range(9) :
    if n%(i+1)==0 and n/(i+1)<10:
        print("Yes\n")
        exit()
print("No")

Buggy submission (verdict: Runtime Error):
n =int(input())
if n<10:
    input("Yes")
    exit()

for i in range(9) :
    if n%(i+1)==0 and n/(i+1)<10:
        input("Yes\n")
        exit()

input("No")

Buggy submission (verdict: Runtime Error):
n =int(input())
if n<10:
    input("Yes")
    exit()

for i in range(9) :
    if n%(i+1)==0 and n/(i+1)<10:
        input("Yes\n")
        exit()

input("No")
Problem p02879 (python)

Fixed submission:
num = [ int(v) for v in input().split() ]
print( num[0]*num[1] if all([ 1 <= i < 10 for i in num ]) else -1 )

Buggy submission (verdict: Runtime Error):
num = [ int(v) for v in input().split() ]
print( i[0]*i[1] if all([ 1 <= i < 10 for i in num ]) else -1 )
Problem p02891 (python)

Fixed submission:

s = input()
k = int(input())
ls = len(s)

word_list = []

a = ""
b = 1

for i, v in enumerate(s):
    if a != v:
        if a != "":
            word_list.append((a,b))
        a = v
        b = 1
    else:
        b += 1
    if i == ls-1:
        word_list.append((a,b))

ans = 0
if len(word_list) == 1:
    ans = (word_list[0][1] * k) // 2
else:
    if word_list[-1][0] != word_list[0][0]:
        for i in word_list:
            ans += (i[1])//2
        ans *= k
    else:
        head, *body, tail = word_list

        for i in body:
            ans += (i[1])//2
        ans *= k
        ans += head[1] // 2
        ans += tail[1] // 2
        headtail = (head[1]+tail[1]) //2 *(k-1)
        ans += headtail

print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
ls = len(s)

word_list = []

a = s[0]
b = 1
for i, v in enumerate(s[1:],1):
    if a != v:
        word_list.append((a,b))
        a = v
        b = 1
    else:
        b += 1
    if i == ls-1:
        word_list.append((a,b))

ans = 0
if len(word_list) == 1:
    ans = (word_list[0][1] * k) // 2
else:
    if word_list[-1][0] != word_list[0][0]:
        for i in word_list:
            ans += (i[1])//2
        ans *= k
    else:
        head, *body, tail = word_list

        for i in body:
            ans += (i[1])//2
        ans *= k
        ans += head[1] // 2
        ans += tail[1] // 2
        headtail = (head[1]+tail[1]) //2 *(k-1)
        ans += headtail
print(ans)
Problem p02892 (python)

Fixed submission:
n = int(input())
connect_matrix = [ list(input()) for i in range(n) ]

def bfs(x):
    node_set = [ None for i in range(n)]
    color_list = [ "White" for i in range(n) ]
    search_list = [x]
    d = 0
    node_set[x] = 0
    color_list[x] = "Black"
    ans = 0
    while search_list != []:
        d += 1
        new_search_list = []
        for i in search_list:
            for j, v in enumerate(connect_matrix[i]):
                if v == "1":
                    if color_list[j] == "White":
                        if node_set[j] is None:
                            node_set[j] = node_set[i] + 1

                        new_search_list.append(j)
                        color_list[j] = "Black"
                    else:
                        if (node_set[j] + node_set[i]) % 2 == 0:
                            ans = -1
        search_list = new_search_list
    return ans, d-1

judge_list = []
dist_list = []
for i in range(n):
    a = bfs(i)
    judge_list.append(a[0])
    dist_list.append(a[1])

if -1 in judge_list:
    print(-1)
else:
    print(max(dist_list)+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
connect_matrix = [ list(input()) for i in range(n) ]
node_set = [ None for i in range(n)]
color_list = [ "White" for i in range(n) ]
search_list = [0]
node_set[0] = 0
color_list[0] = "Black"

ans = 2
while search_list != []:
    new_search_list = []
    for i in search_list:
        for j, v in enumerate(connect_matrix[i]):
            if v == "1" and color_list[j] == "White":
                if node_set[j] is None:
                    node_set[j] = node_set[i] + 1

                new_search_list.append(j)
                color_list[j] = "Black"
            else:
                if (node_set[j] + node_set[i]) % 2 == 0:
                    ans = -1
    search_list = new_search_list

print(ans)
Problem p03038 (python)

Fixed submission:
import sys
input = sys.stdin.readline

def swap(a):
    return ((a[1],a[0]))


n, m = [ int(v) for v in input().split() ]
num_list = [ (int(v), 1) for v in input().split() ]
change_list = [ swap([ int(v) for v in input().split() ]) for i in range(m) ]
total_list = sorted(num_list + change_list, reverse = True)

k = n
ans = 0

for i in total_list:

    j = min(i[1], k)
    k -= j
    ans += i[0] * j
    if k == 0:
        break
print(ans)

Buggy submission (verdict: Runtime Error):

n, m = [ int(v) for v in input().split() ]
num_list = sorted([ -int(v) for v in input().split() ])

for i in range(m):
	a, b = [ int(v) for v in input().split() ]
	for j in range(a):
		heapq.heappush(num_list,-b)

ans = 0
for i in range(n):
	ans += heapq.heappop(num_list)

print(-ans)
Problem p03045 (python)

Fixed submission:

import sys
input = sys.stdin.readline
n, k = [ int(v) for v in input().split() ]
card_parent = [ i for i in range(n) ]
card_set = [ set([i]) for i in range(n) ]
card_list = [ tuple( int(v)-1 for v in input().split() ) for i in range(k) ]

def parent(x,a):
    if card_parent[x] == x:
        return x, a
    else:
        return parent(card_parent[x],a+1)


for i in card_list:
    p, q = i[0], i[1]
    card_parent[p], rank_p = parent(p,0)
    card_parent[q], rank_q = parent(q,0)
    if card_parent[p] != card_parent[q]:
        if rank_p > rank_q:
            card_parent[card_parent[q]] = card_parent[p]
        else:
            card_parent[card_parent[p]] = card_parent[q]




card_parent = [ parent(i,0)[0] for i in range(n) ]

print(len(set(card_parent)))

Buggy submission (verdict: Runtime Error):
def parent(x,a):
    if card_parent[x] == x:
        return x, a
    else:
        return parent(card_parent[x],a+1)


for i in card_list:
    p, q = i[0], i[1]
    card_parent[p], rank_p = parent(p,0)
    card_parent[q], rank_q = parent(q,0)
    if card_parent[p] != card_parent[q]:
        if rank_p > rank_q:
            card_parent[card_parent[q]] = card_parent[p]
        else:
            card_parent[card_parent[p]] = card_parent[q]




card_parent = [ parent(i,0)[0] for i in range(n) ]

print(len(set(card_parent)))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n, k = [ int(v) for v in input().split() ]
card_parent = [ i for i in range(n) ]
card_set = [ set([i]) for i in range(n) ]
card_list = [ tuple( int(v)-1 for v in input().split() ) for i in range(k) ]

def parent(x):
    if card_parent[x] == x:
        return x
    else:
        return parent(card_parent[x])


for i in card_list:
    p, q = i[0], i[1]
    card_parent[p] = parent(p)
    card_parent[q] = parent(q)
    if card_parent[p] != card_parent[q]:
        if p < q:
            card_parent[card_parent[q]] = card_parent[p]
        else:
            card_parent[card_parent[p]] = card_parent[q]




card_parent = [ parent(i) for i in range(n) ]

print(len(set(card_parent)))
Problem p03072 (python)

Fixed submission:
n = int(input())
num_list = [ int(v) for v in input().split() ]
s = 0
for i in range(n):
  if max(num_list[:i+1]) <= num_list[i]:
    s += 1
print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
num_list = [ int(v) for v in range(n)]
s = 0
for i in range(n):
	if max(num_list[:i+1]) <= i:
		s += 1
print(ans)
Problem p03107 (python)

Fixed submission:
s = input()
	
print(min(s.count("1"),s.count("0"))*2)

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

print(abs(s.count("1")-abs(s.count("0")))
Problem p03108 (python)

Fixed submission:
def star(x):
    return x*(x-1)//2

def root(x):
    compress_node = []
    while parent_list[x] != x:
        compress_node.append(x)
        x = parent_list[x]   
    for i in compress_node:
        parent_list[i] = x
    return x


n, m = [ int(v) for v in input().split() ]
bridge_list = [ [ int(v)-1 for v in input().split() ] for i in range(m) ]
bridge_list.reverse()
parent_list = [ i for i in range(n) ]
connect_list = [ 1 for i in range(n) ]
total_inconvinience = star(n)
ans_list = [total_inconvinience]

for i in bridge_list:
    a, b = i
    ra, rb = root(a), root(b)
    if ra != rb:
        parent_list[ra] = rb
        rc = connect_list[rb]
        connect_list[rb] += connect_list[ra]
        total_inconvinience -= star(connect_list[rb]) - star(connect_list[ra]) - star(rc)
        connect_list[ra] = 0
    ans_list.append(total_inconvinience)

ans_list = ans_list[:-1]
ans_list.reverse()
for i in ans_list:
    print(i)

Buggy submission (verdict: Runtime Error):
s = input()
total_1_list = [ [ 0 for i in range(10) ]  for j in range(10)]

for i in range(1,10):
    total_1_list[0][i] = 1
total_1 = 0
for i in range(1,10):
    base_1 = 1 + i * ( 10 ** (i-1) )
    total_1_list[i][1] = base_1
    base_9 = ( 10 + (9 * i) ) * 10 ** (i-1)
    for j in range(2,10):
        total_1_list[i][j] = base_9 - (i * (10 ** (i-1) ) ) * (9-j) 

ans = 0
for i in range(len(s)):
    a = int(s[::-1][i])
    if i != 0  and a == 1:
        ans += int(s[len(s)-i:])
    ans += total_1_list[i][a]
print(ans)
Problem p03186 (python)

Fixed submission:
a, b, c = [ int(v) for v in input().split() ]
print(b+min(c,a+b+1))

Buggy submission (verdict: Runtime Error):
a, b, c = [ list(input()) for i in range(h) ]
print(b+min(c,a+b))
Problem p03207 (python)

Fixed submission:
n = int(input())
present_list = [0]*n
for i in range(n):
	present_list[i] = int(input())
present_list = sorted(present_list)
print(sum(present_list)-present_list[-1]//2)

Buggy submission (verdict: Runtime Error):
n = int(input)
present_list = [0]*n
for i in range(n):
	present_list[i] = int(input())

print(sum(present_list)-present_list[-1]//2)

Buggy submission (verdict: Runtime Error):
n = int(input)

for i in range(n):
	present_list[i] = int(input())

print(sum(present_list)-present_list[-1]//2)
Problem p03242 (python)

Fixed submission:
s = list(input())
for i in range(len(s)):
  if s[i] == "1":
    s[i] = "9"
  elif s[i] == "9":
    s[i] = "1"


print("".join(s))

Buggy submission (verdict: Runtime Error):
s = list(input())
for i in range(s):
  if s[i] == "1":
    s[i] = "9"
  elif s[i] == "9":
    s[i] = "1"


print("".join(s))
Problem p03317 (python)

Fixed submission:
n, k = [ int(v) for v in input().split() ]
a = (n-1)//(k-1)
b = (n-1)%(k-1)

if b != 0:
    a += 1
print(a)

Buggy submission (verdict: Runtime Error):
n = int(input())
blue_list = [ input() for i in range(n)]
m = int(input())
red_list = [ input() for i in range(m)]

card_list = list(set(blue_list+red_list))

point = 0

for i in card_list:
	point = max(point,blue_list.count(i)-red_list.count(i))

print(point)
Problem p03426 (python)

Fixed submission:
import sys
input = sys.stdin.readline

h, w, d = [ int(v) for v in input().split() ]
def manhattan(intuple1,intuple2):
	return abs(intuple1[2]-intuple2[2]) + abs(intuple1[1]-intuple2[1])

grid_list = [ None for i in range(w*h) ]
for i in range(h):
	num_list = [ int(v) for v in input().split() ]
	for j in range(w):
		grid_list[i*w+j] = (num_list[j],i,j)
grid_list = sorted(grid_list)

sum_list = []

for i in range(1,d+1):
	temp_list = []
	left = i
	s = 0
	for j in range(i,w*h+1,d):
		s +=  manhattan(grid_list[left-1],grid_list[j-1])
		temp_list.append(s)

		left = j
	sum_list.append(temp_list)

m = int(input())
for i in range(m):
	l, r = [ int(v) for v in input().split() ]
	print(sum_list[r%d-1][(r-1)//d]-sum_list[l%d-1][(l-1)//d])

Buggy submission (verdict: Runtime Error):
h, w, d = [ int(v) for v in input().split() ]
def manhattan(intuple1,intuple2):
	return abs(intuple1[2]-intuple2[2]) + abs(intuple1[1]-intuple2[1])

grid_list = [ None for i in range(w*h) ]
for i in range(h):
	num_list = [ int(v) for v in input().split() ]
	for j in range(w):
		grid_list[i*h+j] = (num_list[j],i,j)
grid_list = sorted(grid_list)


m = int(input())
for i in range(m):
	l, r = [ int(v) for v in input().split() ]
	score = 0
	left = grid_list[l-1]
	for j in range(l+d,r+d,d):
		right = grid_list[j-1]
		score += manhattan(left,right)
		left = right
	print(score)
Problem p03723 (python)

Fixed submission:
a, b, c = [ int(v) for v in input().split() ]
t = 0

if not all([a%2==0,b%2==0,c%2==0]):
    print(t)
elif all([a==b,b==c]):
    print(-1)


else:
    while True:
        a, b, c = map( int,[ b/2+c/2, c/2+a/2, a/2+b/2 ] )
        t += 1

        if not all([a%2==0,b%2==0,c%2==0]):
            print(t)
            break
        elif all([a==b,b==c]):
            print(-1)
            break

Buggy submission (verdict: Runtime Error):


a, b, c = [ int(v) for v in input().split() ]

if all([a==b,b==c]):
    print(-1)

else:
    t = 0
    while:
        a, b, c = map( int,[ b/2+c/2, c/2+a/2, a/2+b/2 ] )
        t += 1

        if not all([a%2==0,b%2==0,c%2==0]):
            print(t)
            break
        if all([a==b,b==c]):
            print(-1)
            break