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

Fixed submission:
import numpy as np
def cumsum(x):
    return list(np.cumsum(x))

def cumsum_number(N,K,x):
    ans=[0]*(N-K+1)
    number_cumsum = cumsum(x)
    number_cumsum.insert(0,0)
    for i in range(N-K+1):
        ans[i]=number_cumsum[i+K]-number_cumsum[i]
    return ans
"""
int #整数
float #小数

#for
for name in fruits: #fruitの頭から操作
    print(name)

#リスト
list0 = [] #リスト生成
list0 = [1,2,3,4] #初期化
list0 = [0]*10 #[0,0,0,0,0,0,0,0,0,0]
list1= [i for i in range(10)] #>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list1 = list(map(int, input().split()))　# 複数の入力をリストに入れる
number=[int(input()) for i in range(int(input()))] #複数行の入力をリストに
list1 = list1 + [6, 7, 8] #リストの追加
list2.append(34) #リストの追加　最後に（）内が足される
list.insert(3,10) #リストの追加　任意の位置（追加したい位置,追加したい値）
len(list4) #リストの要素数
max(sa) #list saの最小値
list5.count(2) #リスト(文字列も可）内の2の数
list1.sort() #並び替え小さい順
list1.sort(reverse=True)  #並び替え大きい順
set(list1) #list1内の重複している要素を削除し、小さい順に並べる
sum([2,3,   ,3]) #リストの合計

abs(a) #aの絶対値
max(a,b) min(a,b) #最大値　最小値
text1 = text1.replace("34","test") #text1内の"34"を"test"に書き換える(文字列内の文字を入れ替える)

exit(0) #強制終了

cumsum(リスト) #累積和をリストで返す
cumsum_number(N,K,x) #N個の数が含まれるリストx内のK個からなる部分和をリストで返す
"""
N,A,B=map(int,input().split())
S=N//(A+B) #SはA+Bのセット数
M=N-S*(A+B) #Mは残り
if A<=M:
    print(A+S*A)
else:
    print(M+S*A)

Buggy submission (verdict: Runtime Error):
import numpy as np
def cumsum(x):
    return list(np.cumsum(x))

def cumsum_number(N,K,x):
    ans=[0]*(N-K+1)
    number_cumsum = cumsum(x)
    number_cumsum.insert(0,0)
    for i in range(N-K+1):
        ans[i]=number_cumsum[i+K]-number_cumsum[i]
    return ans
"""
int #整数
float #小数

#for
for name in fruits: #fruitの頭から操作
    print(name)

#リスト
list0 = [] #リスト生成
list0 = [1,2,3,4] #初期化
list0 = [0]*10 #[0,0,0,0,0,0,0,0,0,0]
list1= [i for i in range(10)] #>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list1 = list(map(int, input().split()))　# 複数の入力をリストに入れる
number=[int(input()) for i in range(int(input()))] #複数行の入力をリストに
list1 = list1 + [6, 7, 8] #リストの追加
list2.append(34) #リストの追加　最後に（）内が足される
list.insert(3,10) #リストの追加　任意の位置（追加したい位置,追加したい値）
len(list4) #リストの要素数
max(sa) #list saの最小値
list5.count(2) #リスト(文字列も可）内の2の数
list1.sort() #並び替え小さい順
list1.sort(reverse=True)  #並び替え大きい順
set(list1) #list1内の重複している要素を削除し、小さい順に並べる
sum([2,3,   ,3]) #リストの合計

abs(a) #aの絶対値
max(a,b) min(a,b) #最大値　最小値
text1 = text1.replace("34","test") #text1内の"34"を"test"に書き換える(文字列内の文字を入れ替える)

exit(0) #強制終了

cumsum(リスト) #累積和をリストで返す
cumsum_number(N,K,x) #N個の数が含まれるリストx内のK個からなる部分和をリストで返す
"""
N,A,B=map(int,input().split())
S=N//(A+B) #SはA+Bのセット数
M=N-S*(A+B) #Mは残り
if A<=M:
    print(A+S*A)
else:
    print(M+S*A)
Problem p02766 (python)

Fixed submission:
import numpy as np
def cumsum(x):
    return list(np.cumsum(x))

def cumsum_number(N,K,x):
    ans=[0]*(N-K+1)
    number_cumsum = cumsum(x)
    number_cumsum.insert(0,0)
    for i in range(N-K+1):
        ans[i]=number_cumsum[i+K]-number_cumsum[i]
    return ans
"""
int #整数
float #小数

#for
for name in fruits: #fruitの頭から操作
    print(name)

#リスト
list0 = [] #リスト生成
list0 = [1,2,3,4] #初期化
list0 = [0]*10 #[0,0,0,0,0,0,0,0,0,0]
list1= [i for i in range(10)] #>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list1 = list(map(int, input().split()))　# 複数の入力をリストに入れる
number=[int(input()) for i in range(int(input()))] #複数行の入力をリストに
list1 = list1 + [6, 7, 8] #リストの追加
list2.append(34) #リストの追加　最後に（）内が足される
list.insert(3,10) #リストの追加　任意の位置（追加したい位置,追加したい値）
len(list4) #リストの要素数
max(sa) #list saの最小値
list5.count(2) #リスト(文字列も可）内の2の数
list1.sort() #並び替え小さい順
list1.sort(reverse=True)  #並び替え大きい順
set(list1) #list1内の重複している要素を削除し、小さい順に並べる
sum([2,3,   ,3]) #リストの合計

abs(a) #aの絶対値
max(a,b) min(a,b) #最大値　最小値
text1 = text1.replace("34","test") #text1内の"34"を"test"に書き換える(文字列内の文字を入れ替える)

exit(0) #強制終了

cumsum(リスト) #累積和をリストで返す
cumsum_number(N,K,x) #N個の数が含まれるリストx内のK個からなる部分和をリストで返す
"""
N,K=map(int,input().split())
for i in range(10000):
    if K**i<=N<K**(i+1):
        print(i+1)

Buggy submission (verdict: Runtime Error):
import numpy as np
def cumsum(x):
    return list(np.cumsum(x))

def cumsum_number(N,K,x):
    ans=[0]*(N-K+1)
    number_cumsum = cumsum(x)
    number_cumsum.insert(0,0)
    for i in range(N-K+1):
        ans[i]=number_cumsum[i+K]-number_cumsum[i]
    return ans
"""
int #整数
float #小数

#for
for name in fruits: #fruitの頭から操作
    print(name)

#リスト
list0 = [] #リスト生成
list0 = [1,2,3,4] #初期化
list0 = [0]*10 #[0,0,0,0,0,0,0,0,0,0]
list1= [i for i in range(10)] #>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list1 = list(map(int, input().split()))　# 複数の入力をリストに入れる
number=[int(input()) for i in range(int(input()))] #複数行の入力をリストに
list1 = list1 + [6, 7, 8] #リストの追加
list2.append(34) #リストの追加　最後に（）内が足される
list.insert(3,10) #リストの追加　任意の位置（追加したい位置,追加したい値）
len(list4) #リストの要素数
max(sa) #list saの最小値
list5.count(2) #リスト(文字列も可）内の2の数
list1.sort() #並び替え小さい順
list1.sort(reverse=True)  #並び替え大きい順
set(list1) #list1内の重複している要素を削除し、小さい順に並べる
sum([2,3,   ,3]) #リストの合計

abs(a) #aの絶対値
max(a,b) min(a,b) #最大値　最小値
text1 = text1.replace("34","test") #text1内の"34"を"test"に書き換える(文字列内の文字を入れ替える)

exit(0) #強制終了

cumsum(リスト) #累積和をリストで返す
cumsum_number(N,K,x) #N個の数が含まれるリストx内のK個からなる部分和をリストで返す
"""
N,K=map(int,input().split())
for i in range(10000):
    if K**i<=N<K**(i+1):
        print(i+1)
        exit(0)
Problem p02819 (python)

Fixed submission:
import math
def prime(n):
    limit = math.floor(math.sqrt(n))
    for i in range(2,limit+1):
        if n % i == 0:
            return prime(n+1)
    return n

X = int(input())

print(prime(X))

Buggy submission (verdict: Runtime Error):
import numpy as np
import math
from collections import Counter

def cumsum(x):
    return list(np.cumsum(x))

def cumsum_number(N,K,x):
    ans=[0]*(N-K+1)
    number_cumsum = cumsum(x)
    number_cumsum.insert(0,0)
    for i in range(N-K+1):
        ans[i]=number_cumsum[i+K]-number_cumsum[i]
    return ans
"""
int #整数
float #小数

#リスト
list0 = [0]*10 #[0,0,0,0,0,0,0,0,0,0]
list1= [i for i in range(10)] #>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
number=[int(input()) for i in range(int(input()))] #複数行の入力をリストに
list1 = list1 + [6, 7, 8] #リストの追加
list2.append(34) #リストの追加　最後に（）内が足される
list.insert(3,10) #リストの追加　任意の位置（追加したい位置,追加したい値）
list5.count(2) #リスト(文字列も可）内の2の数
list1.sort() #並び替え小さい順
list1.sort(reverse=True)  #並び替え大きい順
set(list1) #list1内の重複している要素を削除し、小さい順に並べる

number=Counter(list) #listを値（文字）ごとにカウントし辞書型で返す [1:4,2:5 …]

text1 = text1.replace("34","test") #text1内の"34"を"test"に書き換える(文字列内の文字を入れ替える)
sorted(S) #Sを辞書順にソート
exit(0) #強制終了

cumsum(リスト) #累積和をリストで返す
cumsum_number(N,K,x) #N個の数が含まれるリストx内のK個からなる部分和をリストで返す

alphabet={0:"A",1:"B",2:"C",3:"D",4:"E",5:"F",6:"G",7:"H",8:"I",9:"J",
          10:"K",11:"L",12:"M",13:"N",14:"O",15:"P",16:"Q",17:"R",18:"S",19:"T",
          20:"U",21:"V",22:"W",23:"X",24:"Y",25:"Z",}
print(*S,sep="") #リストSを1つずつ出力

math.floor() #切り捨て
math.ceil() #切り上げ
"""
def prime(n):
    limit = math.floor(math.sqrt(n))
    for i in range(2,limit+1):
        if n % i == 0:
            return prime(n+1)
    return n

X = int(input())

print(prime(X))

Buggy submission (verdict: Runtime Error):
def prime(n):
    limit = math.floor(math.sqrt(n))
    for i in range(2,limit+1):
        if n % i == 0:
            return prime(n+1)
    return n

X = int(input())

print(prime(X))

Buggy submission (verdict: Runtime Error):
def prime(n):
    limit = math.floor(math.sqrt(n))
    for i in range(2,limit+1):
        if n % i == 0:
            return prime(n+1)
    return n

X = int(input())

print(prime(X))
Problem p02829 (python)

Fixed submission:
A=int(input())
B=int(input())
print(6-A-B)

Buggy submission (verdict: Runtime Error):
A=int(input())
B=int(input())
number=[1,2,3]
del number[A-1]
del number[B-1]
print(number[0])
Problem p02951 (python)

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

Buggy submission (verdict: Runtime Error):
A,B,C = map(int,input().split())
if C-A+B>0:
    print(C=A+B)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
A,B,C = map(int,input().split())
if C-A+B>0:print(C=A+B)
else:print(0)

Buggy submission (verdict: Runtime Error):
A,B,C = map(int,input().split())
if C-A+B>0:print(C=A+B)
else:print(0)
Problem p02970 (python)

Fixed submission:
import math
N,D=map(int,input().split())
print(math.ceil(N/(2*D+1)))

Buggy submission (verdict: Runtime Error):
N,D=map(int,input().split())
print(math.ceil(N/(2*D+1)))
Problem p02659 (python)

Fixed submission:
#C - Multiplication 3
from decimal import Decimal
A,B= map(str,input().split())
A2 = Decimal(A)
B2 = Decimal(B)
#print(A*B*100000)
print(int(A2*B2))

Buggy submission (verdict: Runtime Error):
A,B= input().split()
A = int(A)
B2 = int(B*1000)
#print(A*B*100000)
print(int(A*B2/1000))

Buggy submission (verdict: Runtime Error):
A,B= input().split()
A = int(A)
B2 = B*1000
#print(A*B*100000)
print(int(A*B2/1000))

Buggy submission (verdict: Runtime Error):
A,B= map(input().split())
A = int(A)
B2 = B*1000
#print(A*B*100000)
print(int(A*B2/1000))
Problem p02773 (python)

Fixed submission:
#C - Poll
N = int(input())
S = [str(input()) for i in range(N)]
S = sorted(S)
count = 1
tmpcount = 1
DP = [S[0]]
for i in range(1,N):
    if S[i] == S[i-1]:
        count += 1
        if tmpcount < count:
            DP.clear()
            DP.append(S[i])
            tmpcount = count
        elif tmpcount == count:
            DP.append(S[i])
        else:
            pass
    else:
        count = 1
        if tmpcount == count:
            DP.append(S[i])
        else:
            pass

for l in range(len(DP)):
     print(DP[l])

Buggy submission (verdict: Runtime Error):
#C - Poll
N = int(input())
S = [str(input()) for i in range(N)]
S = sorted(S)
count = 1
tmpcount = 1
DP = [S[0]]
for i in range(1,N):
    if S[i] == S[i-1]:
        count += 1
        if tmpcount < count:
            DP.clear()
            DP.append(S[i])
            tmpcount = count
        elif tmpcount == count:
            DP.append(S[i])
        else:
            pass
    else:
        count = 1
        if tmpcount == count:
            DP.append(S[i])
        else:
            pass

for l in range(len(DP)):
     print(DP[l])

Buggy submission (verdict: Runtime Error):
#C - Poll
import collections
N = int(input())
S = [str(input()) for i in range(N)]
S = sorted(S)
count = 1
tmpcount = 1
DP = [S[0]]
for i in range(1,N):
    if S[i] == S[i-1]:
        count += 1
        if tmpcount < count:
            DP.clear()
            DP.append(S[i])
            tmpcount = count
        elif tmpcount == count:
            DP.append(S[i])
        else:
            pass
    else:
        count = 1
        if tmpcount == count:
            DP.append(S[i])
        else:
            pass

for l in range(len(DP)):
     print(DP[l])
Problem p02831 (python)

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

Buggy submission (verdict: Runtime Error):
# C - Snack
import math
A,B = map(int, input().split())
ans = (A * B) // math.gcd(A, B)
print(ans)
Problem p03012 (python)

Fixed submission:
# B - Balance
N = int(input())
W = list(map(int, input().split()))
sum_l = 0
sum_r = sum(W)
abs_W =[]
for i in range(N):
    sum_l += W[i]
    sum_r -= W[i]
    abs_W.append(abs(sum_r - sum_l))

print(min(abs_W))

Buggy submission (verdict: Runtime Error):
# B - Balance
N = int(input())
W = list(map(int, input().split()))
sum1 = 0
sum2 = 0
i = 0
while sum1 <= sum(W)/2:
    sum1 += W[i]
    sum2 = sum1 + W[i+1]
    i += 1

ans = min(abs(sum(W)-sum1-sum1),abs(sum(W)-sum2 - sum2))

#ans = abs(sum(W) - sum1-sum1)
print(ans)

Buggy submission (verdict: Runtime Error):
# B - Balance
N = int(input())
W = list(map(int, input().split()))
sum1 = 0

i = 0
while sum1 <= sum(W)/2:
    sum1 += W[i]
    i += 1
    sum2 = sum1 + W[i+1]

ans = min(abs(sum(W)-sum1-sum1),abs(sum(W)-sum2-sum2))

#ans = abs(sum(W) - sum1-sum1)
print(ans)

Buggy submission (verdict: Runtime Error):
# B - Balance
N = int(input())
W = list(map(int, input().split()))
sum1 = 0

i = 0
while sum1 < sum(W)/2:
    sum1 += W[i]
    i += 1
    sum2 = sum1 + W[i+1]

ans = min(abs(sum(W)-sum1-sum1),abs(sum(W)-sum2-sum2))

print(ans)
Problem p02623 (python)

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

a, b = [0], [0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from itertools import accumulate
import operator as op
input = sys.stdin.readline

n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a = list(accumulate(A,op.add))
b = list(accumulate(B,op.add))
ans = 0
j = m-1
for i in range(n+1):
    if a[i]>k:
        break
    while b[j]>k-a[i] and j>=0:
        j-=1
    ans=max(ans,i+j+2)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from itertools import accumulate
import operator as op
input = sys.stdin.readline

n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a = list(accumulate(A,op.add))
b = list(accumulate(B,op.add))
ans = 0
j = m-1
for i in range(n):
    if a[i]>k:
        break
    while b[j]>k-a[i]:
        j-=1
    ans=max(ans,i+j+2)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from itertools import accumulate
import operator as op
input = sys.stdin.readline

n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a = list(accumulate(A,op.add))
b = list(accumulate(B,op.add))

ans = 0
j = m-1
for i in range(n):
    if a[i]>k:
        break
    while b[j]>k-a[i]:
        j-=1
    ans=max(ans,i+j+2)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from itertools import accumulate
import operator as op
input = sys.stdin.readline

n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a = list(accumulate(A,op.add))
b = list(accumulate(B,op.add))

ans = 0
j = m-1
for i in range(n):
    if a[i]>k:
        break
    while b[j]>k-a[i]:
        j-=1
    ans=max(ans,i+j+2)
print(ans)
Problem p02659 (python)

Fixed submission:
import math
from decimal import *
a,b=input().split()
print(math.floor(Decimal(a)*Decimal(b)))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

a,b = input().strip().split()
a = int(a)
b = b.replace('.','')
ans = (a*b)//100
print(ans)
Problem p02699 (python)

Fixed submission:
s,w=map(int,input().split())
if s>w:
	print('safe')
else:
	print('unsafe')

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

Fixed submission:
import sys

def solve():
    input = sys.stdin.readline
    N, P = map(int, input().split())
    S = list(input().strip("\n"))

    if P == 2 or P == 5:
        count = 0
        for i in range(N):
            s = int(S[N - 1 - i])
            if s % P == 0: count += N - i
        print(count)
    else:
        modDict = dict()
        modDict[0] = 1
        sSum = 0
        for i in range(N):
            s = int(S[N - 1 - i])
            sSum += s * pow(10, i, P)
            sSum %= P
            if sSum in modDict: modDict[sSum] += 1
            else: modDict[sSum] = 1
        count = 0
        for key in modDict:
            count += modDict[key] * (modDict[key] - 1) // 2
        print(count)
            

    return 0

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict

def solve():
    input = sys.stdin.readline
    N, P = map(int, input().split())
    S = input().strip("\n")
    modSum = 0
    modSum = int(S[0]) % P
    modDict = defaultdict(int)
    ans = 0

    if P == 2 or P == 5:
        for i in range(N):
            if int(S[i]) % P == 0:
                ans += i + 1
        
    else:
        modDict[modSum[0]] += 1
        for i in range(1, N):
            modSum = ((modSum * 10) + int(S[i])) % P
            modDict[modSum] += 1

        for key in modDict:
            v = modDict[key]
            if key > 0: ans += v * (v - 1) // 2
            else: ans += v + (v * (v - 1) // 2)
    
    print(ans)

    return 0

if __name__ == "__main__":
    solve()
Problem p02847 (python)

Fixed submission:
S = ["SUN", "MON","TUE","WED","THU","FRI","SAT"]
d = input()
for i in range(7):
  if d == S[i]:
    print(7 - i)
    break

Buggy submission (verdict: Runtime Error):
S = ["SUN", "MON","TUE","WED","THU","FRI","SAT"]
d = input()
for i in range(d):
  if d == S[i]:
    print(7 - i)
    break
Problem p03016 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000000)

def mult(A, B, mod): #行列A, Bの内積を求める。
    D = [[(A[0][0] * B[0][0]) % mod, 0, 0], [0, 1, 0], [0, 0, 1]]
    D[1][0] = (A[1][0] * B[0][0] + A[1][1] * B[1][0]) % mod
    D[2][0] = (A[2][0]*B[0][0]+A[2][1]*B[1][0]+A[2][2]*B[2][0]) % mod
    D[2][1] = (A[2][1]*B[1][1]+A[2][2]*B[2][1]) % mod
    return D

def double(C, mod):
    D = [[pow(C[0][0], 2, mod), 0, 0], [(C[1][0] * C[0][0] + C[1][0]) % mod, 1, 0], [(C[2][0] * C[0][0] + C[2][1] * C[1][0] + C[2][0]) % mod, (C[2][1] * 2) % mod, 1]]
    return D

def Cpow(C, n, mod):
    if n == 1: return C
    else:
        D = double(C, mod)
        if n % 2 == 0:
            return Cpow(D, n // 2, mod)
        else:
            return mult(Cpow(D, n // 2, mod), C, mod)

def solve():
    L, a, b, M = map(int, input().split())
    X = 0
    s = a
    nd = -1
    ne = 0
    for d in range(1, 19):
        ne = min((pow(10, d) - a - 1) // b, L-1)
        if ne < 0: continue
        elif ne == nd: continue
        C = [[pow(10, d, M), 0, 0], [1, 1, 0], [0, b % M, 1]]
        D = Cpow(C, ne - nd, M)
        X = (X * D[0][0] + D[1][0] * s + D[2][0]) % M
        s += D[2][1]
        if ne == L - 1: break
        nd = ne
    print(X)
    return

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
def mult(A, B, mod): #行列A, Bの内積を求める。
    D = [[0, 0, 0] for i in range(3)]
    D[0][0] = (A[0][0] * B[0][0]) % mod
    D[1][0] = (A[1][0] * B[0][0] + A[1][1] * B[1][0]) % mod
    D[1][1] = 1
    D[2][0] = (A[2][0]*B[0][0]+A[2][1]*B[1][0]+A[2][2]*B[2][0]) % mod
    D[2][1] = (A[2][1]*B[1][1]+A[2][2]*B[2][1]) % mod
    D[2][2] = 1
    return D


def Cpow(C, n, mod):
    if n == 1: return C
    else:
        D = mult(C, C, mod)
        if n % 2 == 0:
            return Cpow(D, n // 2, mod)
        else:
            return mult(Cpow(D, n // 2, mod), C, mod)

def solve():
    L, a, b, M = map(int, input().split())
    X = "0"
    s = a
    nd = -1
    ne = 0
    for d in range(1, 19):
        ne = min((pow(10, d) - a - 1) // b, L-1)
        if nd == ne and ne == L - 1: break
        elif nd == ne: continue
        C = [[pow(10, d, M), 0, 0], [1, 1, 0], [0, b % M, 1]]
        D = Cpow(C, ne - nd, M)
        X = str((int(X) * D[0][0] + D[1][0] * s + D[2][0]) % M)
        s += D[2][1]
        nd = ne
    print(X)
    return

if __name__ == "__main__":
    solve()
Problem p03038 (python)

Fixed submission:
import sys, math, collections, heapq, itertools

F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    N, M = map(int, line_input())
    A = [int(a) for a in line_input()]
    change = [None] * M
    for i in range(M):
        b, c = map(int, line_input())
        change[i] = [c, b]
    A.sort()
    change.sort(reverse = True)

    sum = 0
    index = 0
    for c, b in change:
        bleft = b
        while bleft > 0:
            if c > A[index]:
                sum += c
                index += 1
                bleft -= 1
                if index == N: break
            else: break
        if index == N: break
    if index < N:
        for i in range(index, N):
            sum += A[i]
    print(sum)

    return 0
  
if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import sys
from operator import itemgetter

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    A = [int(a) for a in input().split()]
    A.sort()
    change = [[int(i) for i in input().split()] for _ in range(M)]
    change.sort(key = itemgetter(1), reverse = True)
    ai = 0
    for i in range(M):
        cb, c = change[i]
        if c < A[ai] or ai >= N: break
        for _ in range(cb):
            if ai >= N: break
            if A[ai] <= c:
                A[ai] = c
                ai += 1
            else: break
    print(sum(A))
    return 0

if __name__ == "__main__":
    solve()
Problem p03042 (python)

Fixed submission:
import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    S = single_input()
    YYMM = False
    MMYY = False
    if 1 <= int(S[2:]) <= 12: YYMM = True
    if 1 <= int(S[:2]) <= 12: MMYY = True

    if YYMM and MMYY: print("AMBIGUOUS")
    elif YYMM: print("YYMM")
    elif MMYY: print("MMYY")
    else: print("NA")
    return 0
  
if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
    import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    S = single_input()
    YYMM = False
    MMYY = False
    if 1 <= int(S[2:]) <= 12: YYMM = True
    if 1 <= int(S[:2]) <= 12: MMYY = True

    if YYMM and MMYY: print("AMBIGUOUS")
    elif YYMM: print("YYMM")
    elif MMYY: print("MMYY")
    else: print("NA")
    return 0
  
if __name__ == "__main__":
    solve()
Problem p03108 (python)

Fixed submission:
N, M = map(int, input().split())
Bridge= [[int(i) for i in input().split()] for _ in range(M)]
Parent = [int(i) for i in range(N)]
Rank = [1] * N
 
def find(x):
    if x == Parent[x]: return x
    else:
        Parent[x] = y = find(Parent[x])
        return y
 
def unite(x, y, Total):
    rx, ry = find(x), find(y)
    if rx == ry: return Total
    else:
      Total -= Rank[rx] * Rank[ry]
      if Rank[rx] < Rank[ry]:
        Parent[rx] = ry
        Rank[ry] += Rank[rx]
      else:
        Parent[ry] = rx
        Rank[rx] += Rank[ry]
      return Total
 
Total = N * (N - 1) // 2
Ans = [Total] * M
for i in reversed(range(1, M)):
    A, B = Bridge[i]
    Total = unite(A-1, B-1, Total)
    Ans[i-1] = Total  
 
print("\n".join(map(str, Ans)))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
Bridge= [[int(i) for i in input().split()] for _ in range(M)]
Parent = [int(i) for i in range(N)]
Rank = [1] * N
 
def find(x):
    if x == Parent[x]: return x
    else:
        Parent[x] = y = find(Parent[x])
        return y
 
def unite(x, y, Total):
    rx, ry = find(x), find(y)
    if rx == ry: return Total
    else:
    	Total -= Rank[rx] * Rank[ry]
        if rx > ry:
    		Parent[rx] = ry
    		Rank[ry] += Rank[rx]
        else:
          Parent[ry] = rx
          Rank[rx] += Rank[ry]
    	return Total
 
Total = N * (N - 1) // 2
Ans = str(Total)
for i in reversed(range(1, M)):
    A, B = Bridge[i]
    A -= 1
    B -= 1
    Total = unite(A, B, Total)
    Ans = str(Total) + "\n" + Ans  
 
print(Ans)