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

Fixed submission:
Alice = 'A'
Bob = 'B'
Charlie = 'C'

def answer(Sa, Sb, Sc):
    currentUser = Alice
    ai, bi, ci = (0, 0, 0)
    while(True):
        if currentUser == Alice:
            if ai == len(Sa):
                return Alice
            if Sa[ai] == 'b':
                currentUser = Bob
            if Sa[ai] == 'c':
                currentUser = Charlie
            ai += 1
            continue
        if currentUser == Bob:
            if bi == len(Sb):
                return Bob
            if Sb[bi] == 'a':
                currentUser = Alice
            if Sb[bi] == 'c':
                currentUser = Charlie
            bi += 1
            continue
        if currentUser == Charlie:
            if ci == len(Sc):
                return Charlie
            if Sc[ci] == 'a':
                currentUser = Alice
            if Sc[ci] == 'b':
                currentUser = Bob
            ci += 1
            continue
            
Sa = input()
Sb = input()
Sc = input()
print(answer(Sa, Sb, Sc))

Buggy submission (verdict: Runtime Error):
Alice = 'A'
Bob = 'B'
Charlie = 'C'

def answer(Sa, Sb, Sc):
    currentUser = Alice
    ai, bi, ci = (0, 0, 0)
    while(True):
        if currentUser == Alice:
            if ai == len(Sa):
                return Alice
            if Sa[ai] == 'b':
                currentUser = Bob
            if Sa[ai] == 'c':
                currentUser = Charlie
            ai += 1
            continue
        if currentUser == Bob:
            if bi == len(Sb):
                return Bob
            if Sa[bi] == 'a':
                currentUser = Alice
            if Sa[bi] == 'c':
                currentUser = Charlie
            bi += 1
            continue
        if currentUser == Charlie:
            if ci == len(Sc):
                return Charlie
            if Sa[ci] == 'a':
                currentUser = Alice
            if Sa[ci] == 'b':
                currentUser = Bob
            ci += 1
            continue
            
Sa = input()
Sb = input()
Sc = input()
print(answer(Sa, Sb, Sc))
Problem p02866 (python)

Fixed submission:
import sys
M = 998244353

n = int(input())
d = list(map(int, input().split()))
idx = [0]*n
ans = 1
for i in range(n):
    idx[d[i]] += 1

if not d[0] == 0 or not idx[0] == 1:
    print(0)
else:
    for i in range(1,n):
        if idx[i-1] == 0:
            if not idx[i] == 0:
                print(0)
                sys.exit()
        else:
            ans *= idx[i-1]**idx[i]%M
    else:
        print(ans%M)

Buggy submission (verdict: Runtime Error):
M = 998244353

n = int(input())
d = list(map(int, input().split()))
idx = [0]*n
ans = 1
for i in range(n):
    idx[d[i]] += 1

if not idx[0] == 1:
    print(0)
else:
    if n == 1:
        print(1)
        break
    for i in range(1,n):
        if idx[i-1] == 0:
            if not idx[i] == 0:
                print(0)
                break
        else:
            ans *= (idx[i-1]**idx[i]%M)
    else:
        print(ans%M)
Problem p02913 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
s = input()
dp = [[0]*(n+1) for y in range(n+1)]
ans = 0

for i in range(n):
    a = n-1-i
    for j in range(n):
        b = n-1-j
        if s[a] == s[b]:
            dp[a][b] = dp[a+1][b+1] + 1
for i in range(n):
    for j in range(n):
        now = min(dp[i][j], j-i)
        ans = max(ans, now)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, deque
n = int(input())
s = input()
dic = defaultdict(list)
used = [0]*(n+1)
ans = 0


def search(lst, a):
    global ans
    n_dic = defaultdict(list)
    for i in lst:
        used[i] = 1
        if used[i+1] == 0 and i < n-1:
            n_dic[s[i+1]].append(i+1)
    for n_lst in n_dic.values():
        if len(n_lst) >= 2:
            for j in range(len(n_lst)):
                for k in range(j+1, len(n_lst)):
                    n_lst = [n_lst[j], n_lst[k]]
                    search(n_lst, a+1)
    ans = max(ans, a)

for i in range(n):
    dic[s[i]].append(i)

for lst in dic.values():
    c_lst = []
    if len(lst) >= 2:
        search(lst, 1)
    else:
        used[lst[0]] = 1
print(ans)
Problem p02936 (python)

Fixed submission:
from collections import deque
n, Q = map(int, input().split())
edges = [[] for _ in range(n+1)]
count = [0]*(n+1)
q = deque()
q.append((1, 0))

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)
for _ in range(Q):
    p, x = map(int, input().split())
    count[p] += x

while(q):
    k = q.popleft()
    count[k[0]] += count[k[1]]
    for i in edges[k[0]]:
        if not i == k[1]:
            q.append((i, k[0]))

print(*count[1:])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, q = map(int, input().split())
counter = [0]*n
edges = {}

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[b] = a

for _ in range(q):
    p, x = map(int, input().split())
    counter[p-1] += x

for i in range(1, n):
    counter[i] += counter[edges[i+1]-1]

print(*counter)

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
counter = [0]*n
edges = {}

def have(p, add_lst):
    if p not in edges.keys():
        return
    for i in edges[p]:
        add_lst += [i]
        have(i, add_lst)


for i in range(n-1):
    a, b = map(int, input().split())
    if a in edges.keys():
        edges[a] += [b]
    else:
        edges[a] = [b]

for i in range(q):
    p, x = map(int, input().split())
    add_lst = [p]
    have(p, add_lst)
    for j in add_lst:
        counter[j-1] += x

for i in range(n):
    print(counter[i], end=" ")
Problem p02960 (python)

Fixed submission:
def main():
  M=10**9+7
  r=tuple(tuple((j-k)*9%13for j in range(10))for k in range(13))
  d=[1]+[0]*12
  for c in input():
    if c>'9':
      d=[sum(d[j]for j in k)%M for k in r]
    else:
      d=[d[(int(c)-k)*9%13]for k in range(13)]
  print(d[5])
main()

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

M=10**9+7
r=tuple(tuple((j-k)*9%13for j in range(10))for k in range(13))
d=[1]+[0]*12
for c in input():
    if c>'9':
      d=[sum(d[j]for j in k)%M for k in r]
    else:
      d=[d[(int(c)-k)*9%13]for k in range(13)]
print(d[5])
Problem p02983 (python)

Fixed submission:
import sys
l, r = map(int, input().split())
m = 2019
min = 2019

if r - l >= 2019:
    print(0)
else:
    l, r = l%m, r%m
    for i in range(l, r):
        for j in range(i+1, r+1):
            if min > (i * j)%m:
                min = (i * j)%m
    print(min)

Buggy submission (verdict: Runtime Error):
import sys
l, r = map(int, input().split())
m = 2019

if r - l + 1 >= 2019 or l == 0:
    print(0)
else:
    min = (l%m * (l+1)%m)%m
    for i in range(l, r):
        if i%m == 0:
            print(0)
            sys.exit()
        for j in range(i+1, r+1):
            else:
                if min > (i%m * j%m)%m:
                    min = (i%m * j%m)%m
print(min)
Problem p02995 (python)

Fixed submission:
a, b, c, d = map(int, input().split())

def gcd(x, y):
	while y:
		x, y = y, x % y
	return x

mc = b // c - (a-1) // c
md = b // d - (a-1) // d
mcd = b // (c*d//gcd(c, d)) - (a-1) // (c*d//gcd(c, d))

print(int((b - a + 1) - mc - md + mcd))

Buggy submission (verdict: Runtime Error):
from math import gcd
a, b, c, d = map(int, input().split())
mc = b // c - (a-1) // c
md = b // d - (a-1) // d
mcd = b // (c*d//gcd(c, d)) - (a-1) // (c*d//gcd(c, d))

print(int((b - a + 1) - mc - md + mcd))
Problem p02937 (python)

Fixed submission:
import bisect
s = list(input())
t = list(input())

ds = {}  # ｓに含まれる文字それぞれの数
dsl = {}  # ｓの文字の位置
for i in range(len(s)):
    if s[i] not in ds.keys():
        ds[s[i]] = 0
        dsl[s[i]] = []
    ds[s[i]] += 1
    dsl[s[i]].append(i)

for i in range(len(t)):
    if t[i] not in ds.keys():
        ds[t[i]] = 0

#print(ds, dsl)

ans = 0
now = -1
for i in range(len(t)):
    if ds[t[i]] == 0:  # ｓにｔを構成する文字がない場合
        print("-1")
        exit()
    elif ds[t[i]] == 1:
        if dsl[t[i]][0] > now:  # ｔの次の文字が現在地より右にある場合
            ans += (dsl[t[i]][0] - now)
        else:  # ｔの次の文字が現在地より左にある場合
            ans += dsl[t[i]][0] + (len(s) - now)
        now = dsl[t[i]][0]
    else:
        index = bisect.bisect_right(dsl[t[i]], now)
        if index == len(dsl[t[i]]):
            index = -1
        if dsl[t[i]][index] > now:  # ｔの次の文字が現在地より右にある場合
            ans += (dsl[t[i]][index] - now)
            now = dsl[t[i]][index]
        else:  # ｔの次の文字が現在地より左にある場合
            ans += dsl[t[i]][0] + (len(s) - now)
            now = dsl[t[i]][0]

print(ans)

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

ds = {}
dsl ={}
dt = {}
for i in range(len(s)):
    if s[i] not in ds.keys():    
        ds[s[i]] = 0
        dsl[s[i]] = []
    ds[s[i]]+=1
    dsl[s[i]].append(i)

for i in range(len(t)):
    if t[i] not in dt.keys():    
        dt[t[i]] = 0
    if t[i] not in ds.keys():
        ds[t[i]] = 0
    dt[t[i]]+=1

import bisect
ans = 1
now = 0
for i in range(len(t)):
    if ds[t[i]] == 0:
        print("-1")
        exit()
    elif ds[t[i]] == 1:
        if dsl[t[i]][0] > now:
            ans += (dsl[t[i]][0] - now)
        else:
            ans += dsl[t[i]][0]+1 +(len(s) - now - 1)
        now = dsl[t[i]][0] 
    else:
        index = bisect.bisect_right(dsl[t[i]],now)
        indexv = dsl[t[i]][index]
        if indexv > now:
            ans+= indexv - now
            now = indexv
        else:
            index = 0
            ans+= dsl[t[i]][index]+1 + (len(s) - now - 1)
            now = dsl[t[i]][index] 

print(ans)
Problem p02983 (python)

Fixed submission:
L,R = map(int,input().split())

for i in range(1,10**6):
    if i * 2019 >= L and i*2019 <= R:
        print(0)
        exit()

ans = 10**20

for i in range(L,min(L+2019,R+1)):
    for j in range(L,min(L+2019,R+1)):
        if i >= j:
            continue
        ans = min(ans,(i*j)%2019)
for i in range(max(L,R-2019),R+1):
    for j in range(max(L,R-2019),R+1):
        if i >= j:
            continue
        ans = min(ans,(i*j)%2019)
print(ans)

Buggy submission (verdict: Runtime Error):
L,R = map(int,input().split())

for i in range(1,10**6):
    if i * 2019 >= L and i*2019 <= R:
        print(0)
        exit()

ans = 10**20

for i in range(L,min(L+2019,R+1)):
    for j in range(L,min(L+2019,R+1)):
        if i >= j:
            continue
        ans = min(ans,(i*j)%2019)
￥for i in range(max(L,R-2019),R+1):
    for j in range(max(L,R-2019),R+1):
        if i >= j:
            continue
        ans = min(ans,(i*j)%2019)
print(ans)
Problem p03001 (python)

Fixed submission:
W,H,x,y = map(int,input().split())

ans = 0
if W % 2 == 0 and W//2==x and H %2 == 0 and H//2==y:
    ans = 1

tate = min((W-x)*H , (x - 0)*H)
yoko = min((H-y)*W , (y - 0)*W)
k = max(tate,yoko)

if (x == W and y == 0) or (x == 0 and y == H) or (x == W and y == H) or (x == 0 and y == 0):
    k = (W*H)/2

if H == W:
    if x == y:
        k = (W*H)/2
    elif y + x == H:
        k = (W*H)/2



k = (W*H)/2
print(k,ans,sep=" ")

Buggy submission (verdict: Runtime Error):
W,H,x,y = map(int,input().split())

ans = 0
if W % 2 == 0:
    if W // 2 == x:
        ans += 1
if H % 2 == 0:
    if H //2 == y:
        ans += 1

if ans == 2:
    ans = 1
else:
    ans = 0

if x == 0 or y == 0:
    ans = 0


tate = min((W-x)*H , (x - 0)*H)
yoko = min((H-y)*W , (y - 0)*W)

k = max(tate,yoko)

if (x == W and y == 0) or (x == 0 and y == H) or (x == W and y == H) or (x == 0 and y == 0):
    k = (W*H)/2
    ans = 0

if H == W:
    if x == y:
        k = (W*H)/2
    elif y + x == H:
        k = (W*H)/2


if H == 1 and  Y == 1:
    k = 0.5
    ans = 0


print(k,ans,sep=" ")
Problem p03032 (python)

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

if N < K:
    ans = sum(V)
    V = sorted(V)
    i = 0
    while len(V) > i:
        if V[i] >= 0:
            break
        ans += abs(V[i])
        i += 1
    print(ans)
    exit()


ans = 0
for a in range(K,-1,-1):
    for i in range(a+1):
        left = V[:a-i]
        if i != 0:
            right = V[-i:]
        else:
            right = []
        lr = sorted(left+right)
        tans = sum(lr)
        for j in range(min(len(lr),K-a)):
            if lr[j] < 0:
                tans += abs(lr[j])
        ans = max(ans , tans)
print(ans)

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

if N <= K:
    ans = sum(V)
    V = sorted(V)
    i = 0
    while True:
        if V[i] >= 0:
            break
        ans += abs(V[i])
        i += 1
    print(ans)
    exit()


ans = 0
for a in range(K,-1,-1):
    for i in range(a+1):
        left = V[:a-i]
        if i != 0:
            right = V[-i:]
        else:
            right = []
        lr = sorted(left+right)
        tans = sum(lr)
        for j in range(min(len(lr),K-a)):
            if lr[j] < 0:
                tans += abs(lr[j])
        ans = max(ans , tans)
print(ans)

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

if N < K:
    ans = sum(V)
    V = sorted(V)
    i = 0
    while True:
        if V[i] >= 0:
            break
        ans += abs(V[i])
        i += 1
    print(ans)
    exit()


ans = 0
for a in range(K,-1,-1):
    for i in range(a+1):
        left = V[:a-i]
        if i != 0:
            right = V[-i:]
        else:
            right = []
        lr = sorted(left+right)
        tans = sum(lr)
        for j in range(min(len(lr),K-a)):
            if lr[j] < 0:
                tans += abs(lr[j])
        ans = max(ans , tans)
print(ans)

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

if N < K:
    ans = sum(V)
    V = sorted(V)
    i = 0
    while True:
        if V[i] >= 0:
            break
        ans += abs(V[i])
        i += 1
    print(ans)
    exit()


ans = 0
for a in range(K,-1,-1):
    for i in range(a+1):
        left = V[:a-i]
        if i != 0:
            right = V[-i:]
        else:
            right = []
        print(left,right)
        lr = sorted(left+right)
        tans = sum(lr)
        for j in range(min(len(lr),K-a)):
            if lr[j] < 0:
                tans += abs(lr[j])
        ans = max(ans , tans)
print(ans)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
N = int(input())
e = [ [] for i in range(N+1)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    e[u].append((v,w))
    e[v].append((u,w))

col = [ -1 for i in range(N+1)]

def dfs(x,c):
    col[x] = c
    for v,w in e[x]:
        if col[v] == -1:
            dfs(v , c+w)

dfs(1,0)



for i in range(1,N+1):
    print(col[i] % 2)

Buggy submission (verdict: Runtime Error):
N = int(input())
e = [ [] for i in range(N+1)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    e[u].append((v,w))
    e[v].append((u,w))

col = [ -1 for i in range(N+1)]

def dfs(x,c):
    if col[x] == -1:
        col[x] = c
        for v,w in e[x]:
            if col[v] == -1:
                dfs(v , c+w)

dfs(1,0)
for i in range(1,N+1):
    if col[i] % 2 == 0:
        print(0)
    else:
        print(1)

Buggy submission (verdict: Runtime Error):
N = int(input())
e = [ [] for i in range(N+1)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    e[u].append((v,w))
    e[v].append((u,w))

col = [ -1 for i in range(N+1)]

def dfs(x,c):
    col[x] = c
    for v,w in e[x]:
        if col[v] == -1:
            dfs(v , c+w)

dfs(1,0)

for i in range(1,N+1):
    if col[i] % 2 == 0:
        print(0)
    else:
        print(1)
Problem p03061 (python)

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

l = []
r = []
import fractions as fr
l.append(0)
l.append(A[0])
for i in range(1,N-1):
    l.append(fr.gcd(l[i],A[i]))
r.append(0)
r.append(A[-1])
for i in range(1,N-1):
    r.append(fr.gcd(r[i],A[-i-1]))

ans = 0
for i in range(N):
    ans = max(ans, fr.gcd(l[i],r[-i-1]))
print(ans)

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

if N == 2:
    print(max(A))
    exit()

maxa = max(A)
import fractions
d = []
for i in range(N):
    d.append(fractions.gcd(maxa , A[i]))
d = list(set(d))
d = sorted(d)
print(d[1])

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


maxa = max(A)
import fractions
d = []
for i in range(N):
    if A[i] != maxa:
        d.append(fractions.gcd(maxa , A[i]))
d = list(set(d))
if len(d) == 0:
    print(A[0])
    exit()
d = sorted(d)
print(d[1])
Problem p03068 (python)

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

a = S[K-1]

ans = ""
for i in range(N):
    if S[i] == a:
        ans += a
    else:
        ans += "*"
print(ans)

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input().split())

if (a < b and b < c) or (a > b and b > c):
    print("No")
else:
    print("Yes")
Problem p03069 (python)

Fixed submission:
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    n = int(input())
    s = input()
    black = s.count("#")
    white = len(s) - black
    ans = min(black, white)
    
    b,w = 0,0
    for i in range(len(s)):
        if s[i] == "#":
            b += 1
        else:
            w += 1
        
        ans = min(ans, b + (white - w))
    print(ans)

if __name__ == '__main__':
    main()

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

ans = 0
for i in range(N-2):
    if S[i] == "#" and S[i+1] == "#" and S[i+2] == ".":
        ans += 1
        S[i+2] = "#"
    elif S[i] == "#" and S[i+1] == "." and S[i+2] == ".":
        ans += 1
        S[i] = "."
    elif S[i] == "#" and S[i+1] == "." and S[i+2] == "#":
        ans += 1
        S[i] = "."
if S[-2] == "#" and S[-1] == ".":
    ans += 1

print(ans)
Problem p03076 (python)

Fixed submission:
l = []
for i in range(5):
    l.append(int(input()))

ans = 10**10

import itertools
t = 0
tt = 0
for P in itertools.permutations(l,len(l)):
    for p in P:
        t += p
        if (p % 10) != 0:
            tt = 10-p%10
            t += (10 - p%10)
    ans = min(ans , t-tt)
    t = 0
print(ans)

Buggy submission (verdict: Runtime Error):
l = []
for i in range(5):
    l.append(int(input()))

ans = 10**10

import itertools
t = 0
for P in itertools.permutations(l,len(l)):
    for p in P:
        t += p
        if (p % 10) != 0:
            tt = 10-p%10
            t += (10 - p%10)


    ans = min(ans , t-tt)
    t = 0
print(ans)
Problem p03087 (python)

Fixed submission:
N,Q = map(int,input().split())
S = input()
ACnum = [0]
for i in range(1,N):
    if "AC" == S[i-1:i+1]:
        ACnum.append(ACnum[i-1] + 1)
    else:
        ACnum.append(ACnum[i-1])
lr = []
for i in range(Q):
    lr.append(list(map(int,input().split())))

for i in range(Q):
    print(ACnum[lr[i][1]-1] - ACnum[lr[i][0]-1])

Buggy submission (verdict: Runtime Error):
def main():
    n, q = map(int, input().split())
    s = list(input())
    lr = [list(map(int, input().split())) for i in range(q)]
    ruiseki = [0 for i in range(n)]

    for i in range(n - 1):
        if s[i] == "A" and s[i + 1] == "C":
            ruiseki[i + 1] = ruiseki[i] + 1
        else:
            ruiseki[i + 1] = ruiseki[i]

    for l, r in lr:
        print((ruiseki[r] - ruiseki[l]))


if __name__ == '__main__':
    main()
Problem p03102 (python)

Fixed submission:
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A = []
for i in range(N):
    A.append(list(map(int,input().split())))

ans = 0
for i in range(N):
    tmp = 0
    for j in range(M):
        tmp += A[i][j]*B[j]
    tmp += C
    if tmp > 0:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N,M,C = map(int,input().split())
ab = {}
for i in range(N):
    a,b = map(int,input().split())
    if a in ab.keys():
        ab[a] += b
        continue
    ab[a] = b

keys = sorted(ab.keys())

ans = 0
kosu = 0
for k in keys:
    kosu += ab[k]
    if kosu >= M:
        kosu -= ab[k]
        break
    ans += k * ab[k]

for i in range(ab[k]):
    if kosu == M:
        break
    kosu += 1
    ans += k
print(ans)
Problem p03103 (python)

Fixed submission:
N,M = map(int,input().split())
ab = {}
for i in range(N):
    a,b = map(int,input().split())
    if a in ab.keys():
        ab[a] += b
        continue
    ab[a] = b

keys = sorted(ab.keys())

ans = 0
kosu = 0
for k in keys:
    kosu += ab[k]
    if kosu >= M:
        kosu -= ab[k]
        break
    ans += k * ab[k]

for i in range(ab[k]):
    if kosu == M:
        break
    kosu += 1
    ans += k
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
ab = {}
for i in range(N):
    a,b = map(int,input().split())
    ab[a] = b

keys = sorted(ab.keys())

ans = 0
honsu = 0
money = 0
pre_money = 0
for i in keys:
    if honsu >= M:
        money = pre_money
        break
    ans += ab[i] * i
    honsu += ab[i]
    if honsu >= M:
        money = i
        break
    pre_money = i

for j in range(ab[money]):
    if honsu == M:
        break
    honsu -= 1
    ans -= money

print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
ab = {}
for i in range(N):
    a,b = map(int,input().split())
    ab[a] = b

keys = sorted(ab.keys())

ans = 0
honsu = 0
money = 0
for i in keys:
    if honsu >= M:
        break
    ans += ab[i] * i
    honsu += ab[i]
    if honsu >= M:
        money = i
        break

for j in range(ab[money]):
    if honsu == M:
        break
    honsu -= 1
    ans -= money

print(ans)
Problem p03110 (python)

Fixed submission:
N = int(input())
ans = 0
for i in range(N):
  x,v = input().split()
  x = float(x)
  if v == "JPY":
    ans += x
  else:
    ans += x*380000.0
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = 0
for i in range(N):
  x,v = map(int,input().split())
  if v == "JPY":
    ans += x
  else:
    ans += x*380000.0
print(ans)