Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
s = input().rstrip() + "#"

dic = {"R": deque(), "G":deque(), "B":deque()}

prev_ch = s[0]
cnt = 1
ans = 1
for i, ch in enumerate(s[1:]):
    if ch == prev_ch:
        cnt += 1
    else:
        dic[prev_ch].append([cnt, i-1])
        while dic["R"] and dic["G"] and dic["B"]:
            r = dic["R"].popleft()
            g = dic["G"].popleft()
            b = dic["B"].popleft()
            while(r[0] and g[0] and b[0]):
                ans *= r[0] * g[0] * b[0] // cnt
                r[0] -= 1; g[0] -= 1; b[0] -= 1
                cnt -= 1
            if r[0]:
                dic["R"].appendleft(r)
            if g[0]:
                dic["G"].appendleft(g)
            if b[0]:
                dic["B"].appendleft(b)
        cnt = 1
    prev_ch = ch
for i in range(n):
    ans *= (i+1)
print(ans)

Fixed submission:
#!/usr/bin/env python3
n = int(input())
s = input().rstrip()
MOD = 998244353

r = 0; g = 0; b = 0
rg = 0
gb = 0
br = 0
ans = 1
for ch in s:
    if ch == "R":
        if gb > 0:
            ans *= gb
            gb -= 1
        elif g > 0:
            ans *= g
            g -= 1
            rg += 1
        elif b > 0:
            ans *= b
            b -= 1
            br += 1
        else:
            r += 1
    elif ch == "G":
        if br > 0:
            ans *= br
            br -= 1
        elif b > 0:
            ans *= b
            b -= 1
            gb += 1
        elif r > 0:
            ans *= r
            r -= 1
            rg += 1
        else:
            g += 1
    elif ch == "B":
        if rg > 0:
            ans *= rg
            rg -= 1
        elif g > 0:
            ans *= g
            g -= 1
            gb += 1
        elif r > 0:
            ans *= r
            r -= 1
            br += 1
        else:
            b += 1
    ans %= MOD
for i in range(n):
    ans *= i+1
    ans %= MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
MAXVAL = 10**5
N = int(input())
edge = [[] for _ in range(MAXVAL*2)]
visited = [0] * (MAXVAL*2)
ans = 0
xnum = 0; ynum = 0; nodes = 0

def dfs(n):
    global xnum, ynum, nodes
    if visited[n] == 1:
        return True
    if n < MAXVAL:
        xnum += 1
    else:
        ynum += 1
    visited[n] = 1
    for item in edge[n]:
        nodes += 1
        dfs(item)
    return True

for i in range(N):
    x, y = [int(item) for item in input().split()]
    x -= 1; y -= 1
    edge[x].append(y+MAXVAL)
    edge[y+MAXVAL].append(x)

for i in range(MAXVAL*2):
    if visited[i] == 1:
        continue
    xnum = 0; ynum = 0; nodes = 0
    dfs(i)
    if nodes >= 3:
        ans += xnum * ynum - nodes // 2
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

MAXVAL = 10**5
N = int(input())
edge = [[] for _ in range(MAXVAL*2)]
visited = [0] * (MAXVAL*2)
ans = 0
xnum = 0; ynum = 0; nodes = 0

def dfs(n):
    global xnum, ynum, nodes
    if visited[n] == 1:
        return True
    if n < MAXVAL:
        xnum += 1
    else:
        ynum += 1
    visited[n] = 1
    for item in edge[n]:
        nodes += 1
        dfs(item)
    return True

for i in range(N):
    x, y = [int(item) for item in input().split()]
    x -= 1; y -= 1
    edge[x].append(y+MAXVAL)
    edge[y+MAXVAL].append(x)

for i in range(MAXVAL*2):
    if visited[i] == 1:
        continue
    xnum = 0; ynum = 0; nodes = 0
    dfs(i)
    if nodes >= 3:
        ans += xnum * ynum - nodes // 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7
n, m = [int(item) for item in input().split()]
s = [int(item) for item in input().split()]
t = [int(item) for item in input().split()]

dp = [[0] * (n+1) for _ in range(m+1)]
for i, tt in enumerate(t):
    val = 0 
    for j, ss in enumerate(s):
        # Update Partial
        if ss == tt:
            val += dp[i][j] + 1
        # Keep prev
        dp[i+1][j+1] += dp[i][j+1] + val
        dp[i+1][j+1] %= MOD 
print((dp[m][n]+1) % MOD)


Fixed submission:
MOD = 10**9 + 7
n, m = [int(item) for item in input().split()]
s = [int(item) for item in input().split()]
t = [int(item) for item in input().split()]

dp = [[0] * (n+1) for _ in range(m+1)]
for i, tt in enumerate(t):
    val = 0 
    for j, ss in enumerate(s):
        # Update Partial
        if ss == tt:
            val += dp[i][j] + 1
            val %= MOD
        # Keep prev
        dp[i+1][j+1] += dp[i][j+1] + val
        dp[i+1][j+1] %= MOD 
print((dp[m][n]+1) % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = [int(item) for item in input().split()]
s = [int(item) for item in input().split()]
t = [int(item) for item in input().split()]

dp = [[0] * (n+1) for _ in range(m+1)]
for i, tt in enumerate(t):
    val = 0 
    for j, ss in enumerate(s):
        # Update Partial
        if ss == tt:
            val += dp[i][j] + 1
        # Keep prev
        dp[i+1][j+1] += dp[i][j+1] + val
        dp[i+1][j+1] %= (10**9+7)
print((dp[m][n]+1) % (10**9+7))


Fixed submission:
MOD = 10**9 + 7
n, m = [int(item) for item in input().split()]
s = [int(item) for item in input().split()]
t = [int(item) for item in input().split()]

dp = [[0] * (n+1) for _ in range(m+1)]
for i, tt in enumerate(t):
    val = 0 
    for j, ss in enumerate(s):
        # Update Partial
        if ss == tt:
            val += dp[i][j] + 1
            val %= MOD
        # Keep prev
        dp[i+1][j+1] += dp[i][j+1] + val
        dp[i+1][j+1] %= MOD 
print((dp[m][n]+1) % MOD)
Buggy python submission (verdict: Runtime Error):
MOD = 10**9 + 7
L = input().rstrip()
n = len(L)

ans = 0
l_num = L.count("1")
dp_t = [[0] * n for _ in range(2)]
dp_l = [[0] * n for _ in range(2)]
dp_t[1][0] = 2
dp_l[0][1] = 1
dp_l[1][1] = 2
for i in range(1, n):
    if L[i] == "0":
        dp_t[0][i] += dp_t[0][i-1] + dp_t[1][i-1] 
    elif L[i] == "1":
        dp_t[1][i] += (dp_t[0][i-1] + dp_t[1][i-1]) * 2
        dp_l[0][i] += dp_t[0][i-1] + dp_t[1][i-1]
    dp_l[0][i] += dp_l[0][i-1] + dp_l[1][i-1]
    dp_l[1][i] += (dp_l[0][i-1] + dp_l[1][i-1]) * 2

    dp_l[1][i] %= MOD
    dp_l[0][i] %= MOD
    dp_t[1][i] %= MOD
    dp_t[0][i] %= MOD

print((dp_t[1][n-1] + dp_t[0][n-1] + dp_l[1][n-1] + dp_l[0][n-1]) % MOD)

Fixed submission:
MOD = 10**9 + 7
L = input().rstrip()
if L == "1":
    print(3)
    exit()
n = len(L)

ans = 0
l_num = L.count("1")
dp_t = [[0] * n for _ in range(2)]
dp_l = [[0] * n for _ in range(2)]
dp_t[1][0] = 2
dp_l[0][1] = 1
dp_l[1][1] = 2
for i in range(1, n):
    if L[i] == "0":
        dp_t[0][i] += dp_t[0][i-1] + dp_t[1][i-1] 
    elif L[i] == "1":
        dp_t[1][i] += (dp_t[0][i-1] + dp_t[1][i-1]) * 2
        dp_l[0][i] += dp_t[0][i-1] + dp_t[1][i-1]
    dp_l[0][i] += dp_l[0][i-1] + dp_l[1][i-1]
    dp_l[1][i] += (dp_l[0][i-1] + dp_l[1][i-1]) * 2

    dp_l[1][i] %= MOD
    dp_l[0][i] %= MOD
    dp_t[1][i] %= MOD
    dp_t[0][i] %= MOD

print((dp_t[1][n-1] + dp_t[0][n-1] + dp_l[1][n-1] + dp_l[0][n-1]) % MOD)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ab = [[int(item) for item in input().split()] for _ in range(n-1)]
c = [int(item) for item in input().split()]
c.sort()
c.reverse()
sum_score = sum(c[1:])

edge = [[] for _ in range(n)]
score = [0] * n

for a, b in ab:
    a-=1; b-=1
    edge[a].append(b)
    edge[b].append(a)

it = 0
def dfs(f ,n):
    global it
    score[n] = c[it]
    it += 1
    for item in edge[n]:
        if item == f:
            continue
        dfs(n, item)
    return True

dfs(-1, 0)
print(sum_score)
print(" ".join([str(item) for item in score]))

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

n = int(input())
ab = [[int(item) for item in input().split()] for _ in range(n-1)]
c = [int(item) for item in input().split()]
c.sort()
c.reverse()
sum_score = sum(c[1:])

edge = [[] for _ in range(n)]
score = [0] * n

for a, b in ab:
    a-=1; b-=1
    edge[a].append(b)
    edge[b].append(a)

it = 0
def dfs(f ,n):
    global it
    score[n] = c[it]
    it += 1
    for item in edge[n]:
        if item == f:
            continue
        dfs(n, item)
    return True

dfs(-1, 0)
print(sum_score)
print(" ".join([str(item) for item in score]))
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**6+3
n = MOD + 10
fac = [1] + [0] * n
for i in range(1, n+1):
    fac[i] = fac[i-1] * (i) % MOD

q = int(input())

def f(x, d, n):
    if d == 0:
        return pow(x, n, MOD)
    p = (x * pow(d, MOD-2, MOD)) % MOD
    if p + n - 1 >= MOD:
        return 0
    q = fac[(p + n - 1) % MOD]
    r = fac[p - 1]
    s = pow(d, n, MOD)
    return (q*pow(r, MOD-2, MOD)*s) % MOD

for i in range(q):
    x, d, n = [int(item) for item in input().split()]
    print(f(x, d, n))

Fixed submission:
MOD = 10**6+3
n = MOD + 10

fac = [1] + [0] * n
for i in range(1, n+1):
    fac[i] = fac[i-1] * i % MOD

q = int(input())

def f(x, d, n):
    if d == 0:
        return pow(x, n, MOD)
    p = (x * pow(d, MOD-2, MOD)) % MOD
    if p + n - 1 >= MOD:
        return 0
    q = fac[(p + n - 1) % MOD]
    r = fac[p - 1]
    s = pow(d, n, MOD)
    return (q*pow(r, MOD-2, MOD)*s) % MOD

for i in range(q):
    x, d, n = [int(item) for item in input().split()]
    print(f(x, d, n))
Buggy python submission (verdict: Runtime Error):
n = int(input())
edge = [[] for i in range(n)]
colors = [-1] * n
for i in range(n-1):
    u, v, w = [int(item) for item in input().split()] 
    u -= 1
    v -= 1
    edge[u].append([v, w%2])
    edge[v].append([u, w%2])

def dfs(frm, n):
    for tv, tw in edge[n]:
        if tv == frm:
            continue
        else:
            if tw == 1:
                colors[tv] = (colors[frm] + 1) % 2
            else:
                colors[tv] = colors[frm]
            dfs(n, tv)

colors[0] = 0
dfs(0, 0)
for item in colors:
    print(item)


Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n = int(input())
edge = [[] for i in range(n)]
colors = [0] * n
for i in range(n-1):
    u, v, w = [int(item) for item in input().split()] 
    u -= 1
    v -= 1
    edge[u].append([v, w%2])
    edge[v].append([u, w%2])

def dfs(frm, n, d):
    for tv, tw in edge[n]:
        if tv == frm:
            continue
        else:
            td = (d + tw) % 2
            if td == 1:
                colors[tv] = 1 
            else:
                colors[tv] = 0 
            dfs(n, tv, td)
    return True

colors[0] = 0
dfs(0, 0, 0)
for item in colors:
    print(item)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input().rstrip()

ans = 10 ** 6
for i in range(1,n):
    ans = min(ans, s[:i].count("#") + s[i:].count("."))

ans = min(ans, s.count("#"), s.count("."))
print(ans)

Fixed submission:
n = int(input())
s = input().rstrip()

ans = 10 ** 6
count=0
l_c = [0] * n
for i, c in enumerate(s):
    if c == "#":
        count += 1
    l_c[i] = count
count=0
r_c = [0] * n
for i, c in enumerate(s[::-1]):
    if c == ".":
        count += 1
    r_c[n-1-i] = count

for i in range(1,n):
    ans = min(ans, l_c[i-1] + r_c[i])

ans = min(ans, s.count("#"), s.count("."))
print(ans)
Buggy python submission (verdict: Runtime Error):
MOD = 998244353
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a.sort(reverse=True)
a_sum = sum(a)
half = int(sum(a) / 2)

dp = [[0] * (a_sum + 1) for _ in range(n+1)]
dp[0][0] = 1
for i, item in enumerate(a):
    ni = i+1
    for j in range(a_sum+1):
        if dp[i][j] != 0:
            dp[ni][j] += (dp[i][j] * 2) % MOD
            dp[ni][j+item] += dp[i][j]
total = 1
for i in range(n):
    total *= 3
    total = total % MOD
ans = total - (sum(dp[n][half:])*3)

if a_sum % 2 == 0:
    dp = [[0] * (n + 1) for _ in range(n+1)]
    dp[0][0] = 1
    for i, item in enumerate(a):
        ni = n+1
        for j in range(n):
            if dp[i][j] != 0:
                dp[ni][j] += dp[i][j] % MOD
                if j+item < n:
                    dp[ni][j+item] += dp[i][j] % MOD
ans += dp[n][half] * 3
ans = ans % MOD
if ans < 0:
    ans += MOD
print(ans)

Fixed submission:
MOD = 998244353
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_sum = sum(a)
half = int(a_sum / 2)

dp = [[0] * (a_sum + 1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
    ni = i+1
    for j in range(a_sum+1):
        if dp[i][j] != 0:
            dp[ni][j] += (dp[i][j] * 2) % MOD
            dp[ni][j+a[i]] += dp[i][j]
ans = pow(3, n, MOD)
for item in dp[n][half:]:
    ans -= item * 3
    ans %= MOD

if a_sum % 2 == 0:
    dp = [[0] * (half + 1) for _ in range(n+1)]
    dp[0][0] = 1
    for i in range(n):
        ni = i+1
        for j in range(half+1):
            dp[ni][j] += dp[i][j] % MOD
            if j+a[i] < half+1:
                dp[ni][j+a[i]] += dp[i][j] % MOD
ans += dp[n][half] * 3
ans %= MOD
if ans < 0:
    ans += MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
INF = -10**11
x, y, z, k = [int(item) for item in input().split()]
a = sorted([int(item) for item in input().split()], reverse=True) + [INF]
b = sorted([int(item) for item in input().split()], reverse=True) + [INF]
c = sorted([int(item) for item in input().split()], reverse=True) + [INF]

num = x + y + z
ac, bc, cc = 0, 0, 0
ad = a[0] - a[1]
bd = b[0] - b[1]
cd = c[0] - c[1]
kadd = min(60000, x*y*z)
while (ac+1) * (bc+1) * (cc+1) < kadd:
    if ad <= bd and ad <= cd:
        ac += 1
        ad = a[ac] - a[ac+1]
    elif bd <= ad and bd <= cd:
        bc += 1
        bd = b[bc] - b[bc+1]
    elif cd <= ad and cd <= bd:
        cc += 1
        cd = c[cc] - c[cc+1]

for i in range(50):
    if ac+1 < x:
        ac += 1
    if bc+1 < y:
        bc += 1
    if cc+1 < z:
        cc += 1

vals = []
for ai in a[:ac+1]:
    for bi in b[:bc+1]:
        for ci in c[:cc+1]:
            vals.append(ai+bi+ci)
vals.sort(reverse=True)
for i in range(k):
    print(vals[i])

Fixed submission:
INF = -10**11
x, y, z, k = [int(item) for item in input().split()]
a = sorted([int(item) for item in input().split()], reverse=True) + [INF]
b = sorted([int(item) for item in input().split()], reverse=True) + [INF]
c = sorted([int(item) for item in input().split()], reverse=True) + [INF]

num = x + y + z
ac, bc, cc = 0, 0, 0
ad = a[0] - a[1]
bd = b[0] - b[1]
cd = c[0] - c[1]
kadd = min(12000, x*y*z)
while (ac+1) * (bc+1) * (cc+1) < kadd:
    if ad <= bd and ad <= cd:
        ac += 1
        ad = a[ac] - a[ac+1]
    elif bd <= ad and bd <= cd:
        bc += 1
        bd = b[bc] - b[bc+1]
    elif cd <= ad and cd <= bd:
        cc += 1
        cd = c[cc] - c[cc+1]

for i in range(30):
    if ac+1 < x:
        ac += 1
    if bc+1 < y:
        bc += 1
    if cc+1 < z:
        cc += 1

vals = []
for ai in a[:ac+1]:
    for bi in b[:bc+1]:
        for ci in c[:cc+1]:
            vals.append(ai+bi+ci)
vals.sort(reverse=True)
for i in range(k):
    print(vals[i])
Buggy python submission (verdict: Runtime Error):
n = int(input())

b = [int(item) for item in input().split()]

def dfs(b_sub, ans):
  if len(b_sub) == 0:
    for a in ans[::-1]:
      print(a)
    return 0
  takeable = []
  for i, item in enumerate(b_sub):
    if i+1 == item:
      takeable.append(i)
  if len(takeable) == 0:
    print(-1)
    return -1
  for item in takeable[::-1]:
    tmp = b_sub
    taken = tmp.pop(item)
    ans.append(taken)
    dfs(tmp, ans)
  
print(dfs(b, []))

Fixed submission:
import sys

n = int(input())

b = [int(item) for item in input().split()]

def dfs(b_sub, ans):
  if len(b_sub) == 0:
    for a in ans[::-1]:
      print(a)
    sys.exit()
  takeable = []
  for i, item in enumerate(b_sub):
    if i+1 == item:
      takeable.append(i)
  if len(takeable) == 0:
    print(-1)
    sys.exit()
  for item in takeable[::-1]:
    tmp = b_sub
    taken = tmp.pop(item)
    ans.append(taken)
    dfs(tmp, ans)
  
print(dfs(b, []))
Buggy python submission (verdict: Runtime Error):
n, m = [int(item) for item in input().split()]
edge = [[] for _ in range(n)]

def find_single_self_loop(start, prev, n):
    if prev != -1 and len(edge[n]) != 2:
        if n == start:
            return True
        else:
            return False
    for item in edge[n]:
        if item == prev:
            continue
        ret = find_single_self_loop(start, n, item)
        if ret:
            return True
    return False

for i in range(m):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)

order = [0] * (10**5 + 10)
# Must be Euler graph
for i, line in enumerate(edge):
    o = len(line)
    order[o] += 1
    if o % 2 != 0:
        print("No")
        exit()
    if o >= 4:
        index = i

# Existance of over order-6 node means graph includes over 3 circuits
if max(order[6:]) > 0:
    print("Yes")
    exit()

print(order[:10])
# only 1 order-4 up to 2 circuit
if order[4] <= 1:
    print("No")
    exit()
# over 3 order-4 includes over 3 circuits 
elif order[4] >= 3:
    print("Yes")
    exit()
# 2 order-4
else:
    ret = find_single_self_loop(index, -1, index)
    if ret:
        print("Yes")
    else:
        print("No")

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n, m = [int(item) for item in input().split()]
edge = [[] for _ in range(n)]

def find_single_self_loop(start, prev, n):
    if prev != -1 and len(edge[n]) != 2:
        if n == start:
            return True
        else:
            return False
    for item in edge[n]:
        if item == prev:
            continue
        ret = find_single_self_loop(start, n, item)
        if ret:
            return True
    return False

for i in range(m):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)

order = [0] * (10**5 + 10)
# Must be Euler graph
for i, line in enumerate(edge):
    o = len(line)
    order[o] += 1
    if o % 2 != 0:
        print("No")
        exit()
    if o >= 4:
        index = i

# Existance of over order-6 node means graph includes over 3 circuits
if max(order[6:]) > 0:
    print("Yes")
    exit()

# only 1 order-4 up to 2 circuit
if order[4] <= 1:
    print("No")
    exit()
# over 3 order-4 includes over 3 circuits 
elif order[4] >= 3:
    print("Yes")
    exit()
# 2 order-4
else:
    ret = find_single_self_loop(index, -1, index)
    if ret:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

input = [int(item) for item in input().split()]
a, b, k = input
divisors = make_divisors(a)

th = 0
for i, item in enumerate(divisors):
  if b % item == 0:
    th += 1
  if th == k
    return th

return 0

Fixed submission:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

input = [int(item) for item in input().split()]
a, b, k = input
divisors = make_divisors(a)

th = 0
for i, item in enumerate(divisors[::-1]):
  if b % item == 0:
    th += 1
  if th == k:
    print(item)
    break
Buggy python submission (verdict: Runtime Error):
s = input()
year = int(s[0:4])
month = int(s[5:7])

if yaer >= 2019 and month >= 5:
  print("TBD")
else:
  print("Heisei")

Fixed submission:
s = input()
year = int(s[0:4])
month = int(s[5:7])
 
if year >= 2019 and month >= 5:
  print("TBD")
else:
  print("Heisei")
Buggy python submission (verdict: Runtime Error):
n = int(input())
 
otoshidamas = []
kingaku = 0
for i in range(n):
  otoshidamas.append(input().split())
  
for item in otoshidamas:
  if otoshidamas[1] == "JPY":
    kingaku += float(otoshidamas[0])
  else:
    kingaku += float(otoshidamas[0]) * 380000.0
 
print(kingaku)

Fixed submission:
n = int(input())
 
otoshidamas = []
kingaku = 0
for i in range(n):
  otoshidamas.append(input().split())
  
for item in otoshidamas:
  if item[1] == "JPY":
    kingaku += float(item[0])
  else:
    kingaku += float(item[0]) * 380000.0
 
print(kingaku)

Buggy python submission (verdict: Runtime Error):
n = int(input())
 
otoshidamas = []
kingaku = 0
for i in range(n):
  otoshidamas.append(input().split())
  
for item in otoshidamas:
  if otoshidamas[1] == "JPY":
    kingaku += float(otoshidamas[0])
  else:
    kingaku += float(otoshidamas[0]) * 380000.0
 
print(kingaku)

Fixed submission:
n = int(input())
 
otoshidamas = []
kingaku = 0
for i in range(n):
  otoshidamas.append(input().split())
  
for item in otoshidamas:
  if item[1] == "JPY":
    kingaku += float(item[0])
  else:
    kingaku += float(item[0]) * 380000.0
 
print(kingaku)

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

otoshidamas = []
kingaku = 0
for i in range(n):
  otoshidamas.append([float(item) for item in input()])
  
for item in otoshidamas:
  if otoshidamas[1] == "JPY":
    kingaku += otoshidamas[0]
  else:
    kingaku += otoshidamas[0] * 380000.0

print(kingaku)

Fixed submission:
n = int(input())
 
otoshidamas = []
kingaku = 0
for i in range(n):
  otoshidamas.append(input().split())
  
for item in otoshidamas:
  if item[1] == "JPY":
    kingaku += float(item[0])
  else:
    kingaku += float(item[0]) * 380000.0
 
print(kingaku)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
cnt = Counter()
for i in range(3):
  cnt.update([int(item) for item in input().split()])
a = cnt.values()
a.sort()
if a[0] == 1 and a[1] == 1 and a[2] == 2 and a[3] == 2:
  print("YES")
else:
  print("NO")

Fixed submission:
from collections import Counter
cnt = Counter()
for i in range(3):
  cnt.update([int(item) for item in input().split()])
a = list(cnt.values())
a.sort()
if a[0] == 1 and a[1] == 1 and a[2] == 2 and a[3] == 2:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
h, w = [int(item) for item in input().split()]
field = []
for i in range(h):
    field.append(input().rstrip())

black = 0; white = 0
visited = [[0] * w for _ in range(h)]

def dfs(is_black, i, j):
    global black
    global white
    visited[i][j] = 1
    for x, y in [[1,0], [0,1], [0,-1], [-1,0]]:
        if i+x < 0 or i+x >= h or j+y < 0 or j+y >= w:
            continue
        if visited[i + x][j + y] != 0:
            continue
        if is_black:
            if field[i+x][j+y] == ".":
                white += 1
                dfs(False, i+x, j+y)
        if not is_black:
            if field[i+x][j+y] == "#":
                black += 1
                dfs(True, i+x, j+y)

ans = 0
for i in range(h):
    for j in range(w):
        if visited[i][j] != 0:
            continue
        if field[i][j] == "#":
            white = 0; black = 1
            dfs(True, i, j)
        else:
            white = 1; black = 0
            dfs(False, i, j)
        ans += white * black

print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
h, w = [int(item) for item in input().split()]
field = []
for i in range(h):
    field.append(input().rstrip())

black = 0; white = 0
visited = [[0] * w for _ in range(h)]

def dfs(is_black, i, j):
    global black
    global white
    visited[i][j] = 1
    for x, y in [[1,0], [0,1], [0,-1], [-1,0]]:
        if i+x < 0 or i+x >= h or j+y < 0 or j+y >= w:
            continue
        if visited[i + x][j + y] != 0:
            continue
        if is_black:
            if field[i+x][j+y] == ".":
                white += 1
                dfs(False, i+x, j+y)
        if not is_black:
            if field[i+x][j+y] == "#":
                black += 1
                dfs(True, i+x, j+y)

ans = 0
for i in range(h):
    for j in range(w):
        if visited[i][j] != 0:
            continue
        if field[i][j] == "#":
            white = 0; black = 1
            dfs(True, i, j)
        else:
            white = 1; black = 0
            dfs(False, i, j)
        ans += white * black

print(ans)