Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
cam = [input() for _ in range(h)]
painted = [[False for i in range(w)] for j in range(h)]

def dfs(x, y):
    global cnt
    if x < 0 or y < 0 or x > h-1 or y > w-1:
        return
    elif cam[x][y] == ".":
        return
    elif painted[x][y]:
        return
    cnt += 1
    painted[x][y] = True
    dfs(x-1, y)
    dfs(x, y-1)
    dfs(x+1, y)
    dfs(x, y+1)
    
for i in range(h):
    for j in range(w):
        cnt = 0
        if cam[i][j] == "#":
            dfs(i, j)
        if cnt == 1:
            painted[i][j] = False
            
flag = False
for i in range(h):
    for j in range(w):
        if cam[i][j] == "#":
            if not painted[i][j]:
                flag = True
                break
        elif cam[i][j] == ".":
            if painted[i][j]:
                flag = True
                break
    if flag:
        break
if flag:
    print("No")
else:
    print("Yes")

Fixed submission:
import sys
sys.setrecursionlimit(10000)
h, w = map(int, input().split())
cam = [input() for _ in range(h)]
painted = [[False for i in range(w)] for j in range(h)]

def dfs(x, y):
    global cnt
    if x < 0 or y < 0 or x > h-1 or y > w-1:
        return
    elif cam[x][y] == ".":
        return
    elif painted[x][y]:
        return
    cnt += 1
    painted[x][y] = True
    dfs(x-1, y)
    dfs(x, y-1)
    dfs(x+1, y)
    dfs(x, y+1)
    
for i in range(h):
    for j in range(w):
        cnt = 0
        if cam[i][j] == "#":
            dfs(i, j)
        if cnt == 1:
            painted[i][j] = False
            
flag = False
for i in range(h):
    for j in range(w):
        if cam[i][j] == "#":
            if not painted[i][j]:
                flag = True
                break
        elif cam[i][j] == ".":
            if painted[i][j]:
                flag = True
                break
    if flag:
        break
if flag:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
d = []
for i in range(n+1):
    d.append(abs(a[i+1]-a[i]))
for i in range(1, n+1):
    if max(a[i-1:i+2]) == a[i] or min(a[i-1:i+2]) == a[i]:
        tmp = d[:i-1] + [abs(d[i-1]-d[i])] + d[i+1:]
        print(sum(tmp))
    else:
        print(sum(d))
            

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
d = []
for i in range(n+1):
    d.append(abs(a[i+1]-a[i]))
s = sum(d)
for i in range(1, n+1):
    if max(a[i-1:i+2]) == a[i] or min(a[i-1:i+2]) == a[i]:
        tmp = abs(d[i]-d[i-1])
        print(s - d[i-1] - d[i] + tmp)
    else:
        print(s)
Buggy python submission (verdict: Runtime Error):
N=int(input())
slimes = []
slimes.append(input())
lastColor = slimes[0]
for i in range(N-1):
	new_slime = input()
	if not lastColor == new_slime:
    	slimes.append(new_slime)
print(slimes.length())

Fixed submission:
N=int(input())
slimes = []
all_slime=input()
slimes.append(all_slime[0])
lastColor = all_slime[0]
for i in range(1,N):
    new_slime = all_slime[i]
    if not lastColor == new_slime:
        slimes.append(new_slime)
    lastColor=new_slime
print(len(slimes))
Buggy python submission (verdict: Runtime Error):
S = str(input())
step_count = 0
ans='Yes'
for step in S:
    step_count += 1
    if step_count%2:
        if step == 'L':
            ans='No'
            brake
            
    else:
        if step == 'R':
            ans='No'
            brake
print(ans)

Fixed submission:
S = str(input())
step_count = 0
ans='Yes'
for step in S:
    step_count += 1
    if step_count%2:
        if step == 'L':
            ans='No'
            break
            
    else:
        if step == 'R':
            ans='No'
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
A,B = [int(x) for x in input().split()]
print((B-1)//(A-1)+1)

Fixed submission:
S = str(input())
T = str(input())
# 出力
A = 0

for i in range(3):
    if S[i] == T[i]:
        A += 1

print(A)
Buggy python submission (verdict: Runtime Error):
A,B = map(int, input().split())
print((B-1)//(A-2) + 1)

Fixed submission:
import math
Input = input().split(" ")
A = int(Input[0])
B = int(Input[1])
n = (B-1)/(A-1)
print(math.ceil(n))

Buggy python submission (verdict: Runtime Error):
A,B = [int(x) for x in input().split()]
print((B-1)//(A-2) + 1)

Fixed submission:
import math
Input = input().split(" ")
A = int(Input[0])
B = int(Input[1])
n = (B-1)/(A-1)
print(math.ceil(n))
Buggy python submission (verdict: Runtime Error):
a, b = map(int,input().split())
v = ""
if a = b:
    v = "Draw"
elif a == 1 or a > b:
    v = "Alice"
elif b == 1 or a < b:
    v = "Bob"
print(v)


Fixed submission:
a, b = map(int,input().split())
v = ""
if a == b:
    v = "Draw"
elif a == 1:
    v = "Alice"
elif b == 1:
    v = "Bob"
elif a > b:
    v = "Alice"
else:
    v = "Bob"

print(v)

Buggy python submission (verdict: Runtime Error):
import math

N, Ma, Mb = map(int,input().split())
rate = Ma / Mb
a = [0] * N
b = [0] * N
c = [0] * N
MA = 0
MB = 0
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
    MA += a[i]
    MB += b[i]

dp = [[[math.inf for i in range(MB+1)] for j in range(MA+1)] for k in range(N+1)]
dp[0][0][0] = 0

for it_N in range(N):
    for it_MA in range(MA+1):
        for it_MB in range(MB+1):
            if it_MA >= a[it_N] and it_MB >= b[it_N]:
                if dp[it_N][it_MA-a[it_N]][it_MB-b[it_N]] != math.inf:
                    dp[it_N+1][it_MA][it_MB] = min(dp[it_N][it_MA-a[it_N]][it_MB-b[it_N]] + c[it_N], dp[it_N][it_MA][it_MB])
            else:
                dp[it_N+1][it_MA][it_MB]=dp[it_N][it_MA][it_MB]

#    for it_MA in range(MA+1):
#        for it_MB in range(MB+1):
#print(it_N+1,it_MA,it_MB,dp[it_N+1][it_MA][it_MB])

#中身確認
ans = -1
for a in range(1, MA+1):
    for b in range(1, MB+1):
        print(a,b,dp[N][a][b])
        if a/b == rate and dp[N][a][b] != math.inf:
            if ans == -1:
                ans = dp[N][a][b]
            else:
                ans = min([dp[N][a][b], ans])
print(ans)


Fixed submission:
a, b = map(int,input().split())
v = ""
if a == b:
    v = "Draw"
elif a == 1:
    v = "Alice"
elif b == 1:
    v = "Bob"
elif a > b:
    v = "Alice"
else:
    v = "Bob"

print(v)

Buggy python submission (verdict: Runtime Error):
import math

N, Ma, Mb = map(int,input().split())
rate = Ma / Mb
a = [0] * N
b = [0] * N
c = [0] * N
MA = 0
MB = 0
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())
    MA += a[i]
    MB += b[i]

dp = [[[math.inf for i in range(MB+1)] for j in range(MA+1)] for k in range(N+1)]
dp[0][0][0] = 0

for it_N in range(N):
    for it_MA in range(MA+1):
        for it_MB in range(MB+1):
            if it_MA >= a[it_N] and it_MB >= b[it_N]:
                if dp[it_N][it_MA-a[it_N]][it_MB-b[it_N]] != math.inf:
                    dp[it_N+1][it_MA][it_MB] = min(dp[it_N][it_MA-a[it_N]][it_MB-b[it_N]] + c[it_N], dp[it_N][it_MA][it_MB])
            else:
                dp[it_N+1][it_MA][it_MB]=dp[it_N][it_MA][it_MB]

    for it_MA in range(MA+1):
        for it_MB in range(MB+1):
#            print(it_N+1,it_MA,it_MB,dp[it_N+1][it_MA][it_MB])

#中身確認
ans = -1
for a in range(1, MA+1):
    for b in range(1, MB+1):
        print(a,b,dp[N][a][b])
        if a/b == rate and dp[N][a][b] != math.inf:
            if ans == -1:
                ans = dp[N][a][b]
            else:
                ans = min([dp[N][a][b], ans])
print(ans)


Fixed submission:
a, b = map(int,input().split())
v = ""
if a == b:
    v = "Draw"
elif a == 1:
    v = "Alice"
elif b == 1:
    v = "Bob"
elif a > b:
    v = "Alice"
else:
    v = "Bob"

print(v)
Buggy python submission (verdict: Runtime Error):
N = input()
N = int(N)

i=0
L=[]

while 2*i+1 < N:
    j = 2*i+1
    L.extend([j])
    i += 1
a = int(len(L))
pro = N/a
print(pro)


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

i=0
L=[]

while 2*i+1 <= N:
    j = 2*i+1
    L.extend([j])
    i += 1
a = int(len(L))
pro = a/N
print(pro)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = int(sys.stdin.readline().strip())
l_list = list(sorted(list(map(int, sys.stdin.readline().strip().split(" ")))))
count = 0

for i in reversed(range(2, N)):
    t_max = l_list[i]
    point = None
    for j in range(0, i-1):
        if l_list[j]+l_list[i-1] > t_max:
            point = j
            break
    if point is None:
        continue
    count += (i-1-point)

    for j in reversed(range(point, i-1)):
        point_sec = point
        t_sec = l_list[j]
        flag = False
        for k in range(point_sec, j):
            if l_list[k]+l_list[j] > t_max:
                point_sec = k
                flag = True
                break
        if not flag:
            continue
        count += (j-point_sec)

print(count)

Fixed submission:
import sys

def bi_search(array, target):
    l, r = -1, len(array)-1
    while r-l > 1:
        mid = int((r+l)/2)
        if array[mid] > target:
            r = mid
        else:
            l = mid
    return r

N = int(sys.stdin.readline().strip())
l_list = list(sorted(list(map(int, sys.stdin.readline().strip().split(" ")))))
count = 0
#print(l_list)

for i in reversed(range(N)):
    a = l_list[i]
    for j in reversed(range(i)):
        b = l_list[j]
        index = bi_search(l_list[:j], a-b)
        """
        print("====")
        print(b-a)
        print(i, j, index)
        """
        if index > -1 and index < j and l_list[index] + b > a:
            count += (j-index)

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = int(sys.stdin.readline().strip())
l_list = list(sorted(list(map(int, sys.stdin.readline().strip().split(" ")))))
count = 0

for i in reversed(range(2, N)):
    t_max = l_list[i]
    point = None
    for j in range(0, i-1):
        if l_list[j]+l_list[i-1] > t_max:
            point = j
            break
    if point is None:
        continue
    count += (i-1-point)

    for j in reversed(range(point, i-1)):
        point_sec = None
        t_sec = l_list[j]
        for k in range(point, j):
            if l_list[k]+l_list[j] > t_max:
                point_sec = k
                break
        if point_sec is None:
            continue
        count += (j-point_sec)

print(count)


Fixed submission:
import sys

def bi_search(array, target):
    l, r = -1, len(array)-1
    while r-l > 1:
        mid = int((r+l)/2)
        if array[mid] > target:
            r = mid
        else:
            l = mid
    return r

N = int(sys.stdin.readline().strip())
l_list = list(sorted(list(map(int, sys.stdin.readline().strip().split(" ")))))
count = 0
#print(l_list)

for i in reversed(range(N)):
    a = l_list[i]
    for j in reversed(range(i)):
        b = l_list[j]
        index = bi_search(l_list[:j], a-b)
        """
        print("====")
        print(b-a)
        print(i, j, index)
        """
        if index > -1 and index < j and l_list[index] + b > a:
            count += (j-index)

print(count)
Buggy python submission (verdict: Runtime Error):
import sys

N, M, L = list(map(int, sys.stdin.readline().strip().split(" ")))
INF = 10**10

def warshall_floyd(g_mat):
    dp = [[INF for _ in range(N)] for _ in range(N)]
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
    return dp

graph = [[INF for _ in range(N)] for _ in range(N)]

for _ in range(M):
    a, b, c = list(map(int, sys.stdin.readline().strip().split(" ")))
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c

dist_graph = warshall_floyd(graph)
bool_graph = [[INF for _ in range(N)] for _ in range(N)]

for i in range(N):
    for j in range(N):
        if dist_graph[i][j] <= L:
            bool_graph[i][j] = 1

ans_graph = warshall_floyd(bool_graph)

Q = int(sys.stdin.readline().strip())
for _ in range(Q):
    s, t = list(map(int, sys.stdin.readline().strip().split(" ")))
    ans = ans_graph[s][t]
    print(ans if ans != INF else -1)

    


Fixed submission:
import sys
import copy

N, M, L = list(map(int, sys.stdin.readline().strip().split(" ")))
INF = 10**10

def warshall_floyd(g_mat):
    dp = copy.copy(g_mat)
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
    return dp

graph = [[INF for _ in range(N)] for _ in range(N)]

for _ in range(M):
    a, b, c = list(map(int, sys.stdin.readline().strip().split(" ")))
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c

dist_graph = warshall_floyd(graph)
bool_graph = [[INF for _ in range(N)] for _ in range(N)]

for i in range(N):
    for j in range(N):
        if dist_graph[i][j] <= L:
            bool_graph[i][j] = 1

ans_graph = warshall_floyd(bool_graph)

Q = int(sys.stdin.readline().strip())
for _ in range(Q):
    s, t = list(map(int, sys.stdin.readline().strip().split(" ")))
    ans = ans_graph[s-1][t-1]
    print(ans-1 if ans != INF else -1)
Buggy python submission (verdict: Runtime Error):
import sys

W, H, x, y = list(map(int, sys.stdin.readline()))
b = 0

if x == W/2 and y == H/2:
    b = 1

print(str(W*H/2) + " " + str(b))


Fixed submission:
import sys

W, H, x, y = list(map(int, sys.stdin.readline().strip().split(" ")))
b = 0

if x == W/2 and y == H/2:
    b = 1

print(str(W*H/2) + " " + str(b))
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np

N, M = list(map(int, sys.stdin.readline().strip().split(" ")))
A = list(map(int, sys.stdin.readline().strip().split(" ")))
B = []
C = []

for _ in range(M):
    b, c = list(map(int, sys.stdin.readline().strip().split(" ")))
    B.append(b)
    C.append(c)

A = sorted(A)
arg_list = list(reversed(np.argsort(C)))
B = np.array(B)[arg_list]
C = np.array(C)[arg_list]

index = 0
count = 0
flag = False
for b, c in zip(B, C):
    for _ in range(b):
        if A[index] >= c:
            flag = True
            break
        if index == N:
            flag = True
            break
        A[index] = c
        index += 1
    if flag:
        break

print(sum(A))
        



Fixed submission:
import sys
import numpy as np

N, M = list(map(int, sys.stdin.readline().strip().split(" ")))
A = list(map(int, sys.stdin.readline().strip().split(" ")))
B = []
C = []

for _ in range(M):
    b, c = list(map(int, sys.stdin.readline().strip().split(" ")))
    B.append(b)
    C.append(c)

A = sorted(A)
arg_list = list(reversed(np.argsort(C)))
B = np.array(B)[arg_list]
C = np.array(C)[arg_list]

index = 0
count = 0
flag = False
for b, c in zip(B, C):
    for _ in range(b):
        if index == N:
            flag = True
            break
        if A[index] >= c:
            flag = True
            break
        A[index] = c
        index += 1
    if flag:
        break

print(sum(A))

Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np

N, M = list(map(int, sys.stdin.readline().strip().split(" ")))
A = list(map(int, sys.stdin.readline().strip().split(" ")))
B = []
C = []

for _ in range(M):
    b, c = list(map(int, sys.stdin.readline().strip().split(" ")))
    B.append(b)
    C.append(c)

A = sorted(A)
arg_list = list(reversed(np.argsort(C)))
B = np.array(B)[arg_list]
C = np.array(C)[arg_list]

index = 0
count = 0
flag = False
for b, c in zip(B, C):
    for _ in range(b):
        if A[index] >= c:
            flag = True
            break
        A[index] = c
        index += 1
    if flag:
        break

print(sum(A))


Fixed submission:
import sys
import numpy as np

N, M = list(map(int, sys.stdin.readline().strip().split(" ")))
A = list(map(int, sys.stdin.readline().strip().split(" ")))
B = []
C = []

for _ in range(M):
    b, c = list(map(int, sys.stdin.readline().strip().split(" ")))
    B.append(b)
    C.append(c)

A = sorted(A)
arg_list = list(reversed(np.argsort(C)))
B = np.array(B)[arg_list]
C = np.array(C)[arg_list]

index = 0
count = 0
flag = False
for b, c in zip(B, C):
    for _ in range(b):
        if index == N:
            flag = True
            break
        if A[index] >= c:
            flag = True
            break
        A[index] = c
        index += 1
    if flag:
        break

print(sum(A))
Buggy python submission (verdict: Runtime Error):
import os
import sys

N = int(sys.stdin.readline().strip())
cost_list = list(map(int, sys.stdin.readline().strip()))
dp = [10**9 for _ in range(N)]
dp[0] = 0
dp[1] = abs(cost_list[1] - cost_list[0])

for i in range(2, N):
    dp[i] = min(dp[i-2] + abs(cost_list[i] - cost_list[i-2]), dp[i-1] + abs(cost_list[i] - cost_list[i-1]))

print(dp[N-1])

Fixed submission:
import sys

N = int(sys.stdin.readline().strip())
cost_list = list(map(int, sys.stdin.readline().strip().split(" ")))
dp = [10**9 for _ in range(N)]
dp[0] = 0
dp[1] = abs(cost_list[1] - cost_list[0])

for i in range(2, N):
    dp[i] = min(dp[i-2] + abs(cost_list[i] - cost_list[i-2]), dp[i-1] + abs(cost_list[i] - cost_list[i-1]))

print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
import sys

a = int(sys.stdin.readline().strip())
b = int(sys.stdin.readline().strip())
c = int(sys.stdin.readline().strip())

if a == 1:
    print("Hello World")
else:
    print(b + c)

Fixed submission:
import sys

a = int(sys.stdin.readline().strip())
if a == 1:
    print("Hello World")
else:
    b = int(sys.stdin.readline().strip())
    c = int(sys.stdin.readline().strip())
    print(b + c)

Buggy python submission (verdict: Runtime Error):
import sys
a = int(sys.stdin.readline().strip())
b = int(sys.stdin.readline().strip())
c = int(sys.stdin.readline().strip())

if a == 1:
  print("Hello World")
else:
  print(b + c)

Fixed submission:
import sys

a = int(sys.stdin.readline().strip())
if a == 1:
    print("Hello World")
else:
    b = int(sys.stdin.readline().strip())
    c = int(sys.stdin.readline().strip())
    print(b + c)
Buggy python submission (verdict: Time Limit Exceeded):
import scipy.misc as scm
import sys

N = int(sys.stdin.readline().strip())
a = list(map(lambda x: int(x), sys.stdin.readline().strip().split(" ")))

n = max(a)
max_m = -1
max_c = -1

for m in a:
    s = scm.comb(n, m)
    if m == n:
        continue
    if max_c < s:
        max_c = s
        max_m = m
print(str(n) + " " + str(max_m))

Fixed submission:
import sys
import numpy as np

N = int(sys.stdin.readline().strip())
a = list(map(lambda x: int(x), sys.stdin.readline().strip().split(" ")))

index = np.argmax(a)
n = a.pop(index)

m = -1
tmp = n

for e in a:
    if abs((n/2) - e) < tmp:
        tmp = abs((n/2) - e)
        m = e
        
print(str(n) + " " + str(int(m)))
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
import itertools

N = int(sys.stdin.readline().strip())
dct = {}
dct["M"] = 0
dct["A"] = 0
dct["R"] = 0
dct["C"] = 0
dct["H"] = 0
char_list = ["M", "A", "R", "C", "H"]

for _ in range(N):
    name = sys.stdin.readline().strip()
    first = name[0]
    dct[first] += 1

count = 0
for a, b, c in list(itertools.combinations(char_list, 3)):
    count += dct[a] * dct[b] * dct[c]
print(count)


Fixed submission:
import sys
import numpy as np
import itertools

N = int(sys.stdin.readline().strip())
dct = {}
dct["M"] = 0
dct["A"] = 0
dct["R"] = 0
dct["C"] = 0
dct["H"] = 0
char_list = ["M", "A", "R", "C", "H"]

for _ in range(N):
    name = sys.stdin.readline().strip()
    first = name[0]
    if first not in dct:
        continue
    dct[first] += 1

count = 0
for a, b, c in list(itertools.combinations(char_list, 3)):
    count += dct[a] * dct[b] * dct[c]
print(count)
Buggy python submission (verdict: Runtime Error):
import sys

n, y = list(map(int, sys.stdin.readline().strip().split(" ")))

t_list = []

for a in range(n + 1):
    for b in range(n-i+1):
        #t_list.append((n-i-j, j, i))
        c = n-a-b
        if 10000 * a + 5000 * b + 1000 * c == y:
            print(" ".join([str(a), str(b), str(c)]))
            sys.exit()

print("-1 -1 -1")


Fixed submission:
import sys

n, y = list(map(int, sys.stdin.readline().strip().split(" ")))

t_list = []

for a in range(n + 1):
    for b in range(n-a+1):
        #t_list.append((n-i-j, j, i))
        c = n-a-b
        if 10000 * a + 5000 * b + 1000 * c == y:
            print(" ".join([str(a), str(b), str(c)]))
            sys.exit()

print("-1 -1 -1")

Buggy python submission (verdict: Runtime Error):
import sys

n, y = list(map(int, sys.stdin.readline().strip().split(" ")))

t_list = []

for i in range(n + 1):
    for j in range(n-i+1):
        t_list.append(N-i-j, j, i)

for a, b, c in t_list:
    if 10000 * a + 5000 * b + 1000 * c == y:
        print(" ".join([str(a), str(b), str(c)]))
        sys.exit()

print("-1 -1 -1")


Fixed submission:
import sys

n, y = list(map(int, sys.stdin.readline().strip().split(" ")))

t_list = []

for a in range(n + 1):
    for b in range(n-a+1):
        #t_list.append((n-i-j, j, i))
        c = n-a-b
        if 10000 * a + 5000 * b + 1000 * c == y:
            print(" ".join([str(a), str(b), str(c)]))
            sys.exit()

print("-1 -1 -1")

Buggy python submission (verdict: Runtime Error):
import sys

n, y = list(map(int, sys.stdin.readline(),strip().split(" ")))

t_list = []

for i in range(n + 1):
    for j in range(n-i+1):
        t_list.append(N-i-j, j, i)

for a, b, c in t_list:
    if 10000 * a + 5000 * b + 1000 * c == y:
        print(" ".join([str(a), str(b), str(c)]))
        sys.exit()

print("-1 -1 -1")


Fixed submission:
import sys

n, y = list(map(int, sys.stdin.readline().strip().split(" ")))

t_list = []

for a in range(n + 1):
    for b in range(n-a+1):
        #t_list.append((n-i-j, j, i))
        c = n-a-b
        if 10000 * a + 5000 * b + 1000 * c == y:
            print(" ".join([str(a), str(b), str(c)]))
            sys.exit()

print("-1 -1 -1")
Buggy python submission (verdict: Runtime Error):
import sys

def add_char(l, string):
    for s in string:
        l.append(s)

n = int(sys.stdin.readline().strip())
common_list = []

for i in range(n):
    s = sys.stdin.readline().strip()
    if i == 0:
        add_char(common_list, s)
    else:
        tmp = []
        add_char(tmp, s)
        for c in common_list:
            if c in tmp:
                tmp.pop(c)
            else:
                common_list.pop(c)
if len(common_list) == 0:
    print("")
else:
    common_list = sorted(common_list)
    s = ""
    for c in common_list:
        s += c
    print(s)


Fixed submission:
import sys

def add_char(l, string):
    for s in string:
        l.append(s)

n = int(sys.stdin.readline().strip())
common_list = []

for i in range(n):
    s = sys.stdin.readline().strip()
    if i == 0:
        add_char(common_list, s)
    else:
        tmp = []
        add_char(tmp, s)
        tmp_c = list(common_list)
        for c in tmp_c:
            if c in tmp:
                tmp.remove(c)
            else:
                common_list.remove(c)
if len(common_list) == 0:
    print("")
else:
    common_list = sorted(common_list)
    s = ""
    for c in common_list:
        s += c
    print(s)
Buggy python submission (verdict: Runtime Error):
import sys

dct = {"b": "d", "d", "b", "p": "q", "q": "p"}
S = sys.stdin.readline().strip()
rev = ""
for s in S[::-1]:
    rev += dct[s]

if rev == S:
    print("Yes")
else:
    print("No")

Fixed submission:
import sys

dct = {"b": "d", "d": "b", "p": "q", "q": "p"}
S = sys.stdin.readline().strip()
rev = ""
for s in S[::-1]:
    rev += dct[s]

if rev == S:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
# coding:utf-8

n, y = [int(x) for x in input().split(' ')]

sen = y//1000

target = sen - n

if target < 0:
    print('-1 -1 -1')
else:
    iti_man = target % 4
    go_sen = target // 4 - iti_man * 2
    sen = sen - iti_man * 10 - go_sen * 5
    if sen > -1 and go_sen > -1 and iti_man > -1 :
        print('{} {} {}'.format(iti_man, go_sen, sen))
    else:
        print("-1 -1 -1")


Fixed submission:
s = input()

print(s[0:3] + '8' + s[4:])