Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import deque

def search(h, w, pre_h, pre_w):
    can = []
    if h > 0:
        can.append((h-1, w))
    if h < H-1:
        can.append((h+1, w))
    if w > 0:
        can.append((h, w-1))
    if w < W-1:
        can.append((h, w+1))
    res = []
    for h, w in can:
        if S[h][w]=='.' and (h, w) != (pre_h, pre_w):
            res.append((h, w))
    return res

def bfs(h, w):
    d = [[float('inf') for _ in range(W)] for _ in range(H)]
    d[h][w] = 0
    pre_h, pre_w = h, w
    adj_list = search(h, w, pre_h, pre_w)
    open_list = deque([])
    closed_list = []
    closed_list = set(closed_list)
    for adj in adj_list:
        open_list.append((adj[0], adj[1], pre_h, pre_w))
    cnt = 0
    while True:
        cnt+=1
        if H==20 and W==20:
            if cnt > 2200:
                break
        if len(open_list) == 0:
            break
        h, w, pre_h, pre_w = open_list.popleft()
        closed_list.add((h, w, pre_h, pre_w))
        d[h][w] = min(d[h][w], d[pre_h][pre_w] + 1)
        adj_list = search(h, w, pre_h, pre_w)
        for adj in adj_list:
            if (adj[0], adj[1], h, w) in closed_list:
                continue
            open_list.append((adj[0], adj[1], h, w))

    res = 0
    for h in range(H):
        for w in range(W):
            if not d[h][w] == float('inf'):
                res = max(res, d[h][w])
    return res

def bounday():
    for h in range(H):
        for w in range(W):
            if S[h][w] == '#':
                return False
    return True

H, W = map(int, input().split())
S = []
for i in range(H): 
    S.append(list(input()))

if __name__ == "__main__":

    if bounday():
        print(H+W-2)
        exit(0)

    ans = 0
    for h in range(H):
        for w in range(W):
            if S[h][w] == '#':
                continue
            maxd = bfs(h, w)
            ans = max(maxd, ans)
    print(ans)

Fixed submission:
c = input()
print(chr(ord(c) + 1))
Buggy python submission (verdict: Runtime Error):
k, x = map(int, input().split())

if k*500 >= x:
    print('Yes')
else:
    print('No'

Fixed submission:
k, x = map(int, input().split())

if k*500 >= x:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
def f(n):
    if n<2:
        return 1
    return n*f(n-2)

N = int(input())
if N%2==1:
    print(0)
    exit(1)
ans = 0
tmp = N//50//2
for i in range(1, len(str(N))):
    # if i != len(str(N))-1:
    #     ans+=(10**(i))
    ans += N//5//2
    N //= 10
print(ans+tmp)

Fixed submission:
N = int(input())
if N%2==1:
    print(0)
    exit(0)
ans = 0
tmp = N
for i in range(1, 100):
    ans += tmp//pow(5, i)//2
print(ans)

Buggy python submission (verdict: Runtime Error):
def f(n):
    if n<2:
        return 1
    return n*f(n-2)

N = int(input())
if N%2==1:
    print(0)
    exit(1)
ans = 0
for i in range(1, len(str(N))):
    # if i != len(str(N))-1:
    #     ans+=(10**(i))
    ans += N//5//2
    N //= 10
ans = list(str(ans))
ans2 = []
for i in range(len(ans)):
    i = int(i)
    if i==len(ans)-1:
        res = 0
    elif i==len(ans)-2:
        res = 1
    elif i==len(ans)-3:
        res = 3
    elif i==0:
        res = 4
    else:
        res = 8
    ans2.append(str(res+int(ans[i])))
ans2.reverse()
ans2 = int(''.join(ans2))
print(ans2)

Fixed submission:
N = int(input())
if N%2==1:
    print(0)
    exit(0)
ans = 0
tmp = N
for i in range(1, 100):
    ans += tmp//pow(5, i)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
x = input()
s = list(x)
x = int(x)

xx = int(s[-2]+s[-1])
num_item = xx//5
if xx%5 != 0:
    num_item += 1

hun = int(''.join(s[0:-2]))
if hun < num_item:
    print(0)
else:
    print(1)

Fixed submission:
x = input()
s = list(x)
x = int(x)

if len(s) < 3:
    print(0)
else:
    xx = int(s[-2]+s[-1])
    num_item = xx//5
    if xx%5 != 0:
        num_item += 1
    
    hun = int(''.join(s[0:-2]))
    if hun < num_item:
        print(0)
    else:
        print(1)
Buggy python submission (verdict: Runtime Error):
r = int(input())
print(r**2

Fixed submission:
r = int(input())
print(r**2)
Buggy python submission (verdict: Runtime Error):
import sys
from functools import lru_cache

sys.setrecursionlimit(10000)

INF = 10**9+7

@lru_cache(maxsize=1000)
def c(n,k):
    return 1 if (k<=0 or n<=k) else (c(n-1,k-1)+c(n-1,k))%INF

# for i in range(5):
#     print([c(i, j) for j in range(i+1)])

def solver(x, y):
    if (x, y) == (0, 0):
        return 0
    if (x+y)%3 != 0:
        return 0
    k = (x+y)//3
    (xi, yi) = (k, 2*k)
    for i in range(k+1):
        if (xi, yi) == (x, y):
            return c(k, i)
        else:
            (xi, yi) = (xi+1, yi-1)
    return 0

x, y = map(int, input().split())
res = solver(x, y)
print(res)

Fixed submission:
import sys

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def comb_num_mod(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

def solver(x, y):


    if (x, y) == (0, 0):
        return 0
    if (x+y)%3 != 0:
        return 0
    k = (x+y)//3
    (xi, yi) = (k, 2*k)
    for i in range(k+1):
        if (xi, yi) == (x, y):
            return comb_num_mod(k, i) 
        else:
            (xi, yi) = (xi+1, yi-1)
    return 0

x, y = map(int, input().split())
res = solver(x, y)
print(res)
Buggy python submission (verdict: Runtime Error):
from math import degrees, atan, sqrt, tan

a, b, x = map(int, input().split())

if x>a*a*b/2:
    print(degrees(atan(2*(a*a*b-x)/(a**3))))
else:
    print(degrees(atan((a*b*b)/(2*x)))

Fixed submission:
from math import degrees, atan, sqrt, tan

a, b, x = map(int, input().split())

if x>a*a*b/2:
    print(degrees(atan(2*(a*a*b-x)/(a**3))))
else:
    print(degrees(atan((a*b*b)/(2*x))))
Buggy python submission (verdict: Time Limit Exceeded):
def cf(x1,x2):
    cf=[]
    for i in range(2,min(x1,x2)+1):
        if x1%i==0 and x2%i==0:
            cf.append(i)
    return cf

a, b = map(int, input().split())
ab = cf(a, b)
del_cnt = 0
for i, ab_i in enumerate(ab):
    for j, ab_j in enumerate(ab[i+1:]):
        j = j+i+1 - del_cnt
        if ab_j%ab_i==0:
            del ab[j]
            del_cnt += 1

print(len(ab)+1)

Fixed submission:
def pf(n:int):
    r = []
    while n%2==0:
        r.append(2)
        n//=2
    f=3
    while f*f<=n:
        if n%f==0:
            r.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        r.append(n)
    return r

a, b = map(int, input().split())
a = pf(a)
b = pf(b)
a = set(a)
b = set(b)
print(len(set(a&b))+1)

Buggy python submission (verdict: Time Limit Exceeded):
def cf(x1,x2):
    cf=[]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

a, b = map(int, input().split())
ab = cf(a, b)
i = 0
for ab_i in ab:
    for ab_j in ab[i+1:]:
        if ab_j%ab_i==0:
            for k, ab_k in enumerate(ab):
                if ab_k == ab_j:
                    del ab[k]
    i += 1
print(len(ab)+1)

Fixed submission:
def pf(n:int):
    r = []
    while n%2==0:
        r.append(2)
        n//=2
    f=3
    while f*f<=n:
        if n%f==0:
            r.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        r.append(n)
    return r

a, b = map(int, input().split())
a = pf(a)
b = pf(b)
a = set(a)
b = set(b)
print(len(set(a&b))+1)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

N, Q = map(int, input().split())
edge = defaultdict(list)
for i in range(N-1):
    a, b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)

cnt = [0]*(N+1)
for i in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x

root_node = (1, -1) # (id, value, parent_id)
open_list = [root_node]
closed_list = []
while True:
    if len(open_list) == 0:
        break
    cur_node = open_list.pop()
    cur_id, parent_id = cur_node
    if not(parent_id == -1):
        cnt[cur_id] += cnt[parent_id]
    for child_id in edge[cur_id]:
        if child_id == parent_id:
            continue
        open_list.append((child_id, cur_id))
print(*cnt[1:])

Fixed submission:
a = int(input())
s = input()
if a >= 3200:
    print(s)
else:
    print('red')
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
a.reverse()

def search(x):
    n = 1
    res = 0
    while True:
        nx = n*x
        if nx > N:
            break
        res += boxes[nx-1]
        n += 1
    return res%2


boxes = [0]*N
for i, ai in enumerate(a):
    i = N-i
    eo = search(i)
    if ai!=eo:
        boxes[i]=1

ans=[]
for i, box in enumerate(boxes):
    if box==1:
        ans.append(i)

if ans==[]:
    print(0)
else:
    print(*ans)

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

M = 0
boxes = [0]*N
for i in reversed(range(N)):
    num_balls = 0
    for k in range(i, N, i+1):
        num_balls += boxes[k]
    if num_balls%2 != a[i]:
        boxes[i] = 1
        M += 1

print(M)
for i in range(N):
    if boxes[i]==1:
        print(i+1)

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

def search(x):
    n = 1
    res = 0
    while True:
        nx = n*x
        if nx >= N:
            break
        res += boxes[nx]
        n += 1
    return res%2


boxes = [0]*N
for i, ai in enumerate(a):
    i = N-i
    eo = search(i)
    if ai!=eo:
        boxes[i]=1

ans=[]
for i, box in enumerate(boxes):
    if box==1:
        ans.append(i)

if ans==[]:
    print(0)
else:
    print(*ans)

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

M = 0
boxes = [0]*N
for i in reversed(range(N)):
    num_balls = 0
    for k in range(i, N, i+1):
        num_balls += boxes[k]
    if num_balls%2 != a[i]:
        boxes[i] = 1
        M += 1

print(M)
for i in range(N):
    if boxes[i]==1:
        print(i+1)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = list(map(int, input().split()))

D = 0
res = 0
while True:
    if D > X:
        break
    res += 1
    D += L[res-1] 

print(res)

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

D = 0
cnt = 1
for i in range(N):
    D+=L[i]
    if D>X:
        break
    else:
        cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
c = [0]*(n+1)
for i in range(m):
    l, r = map(int, input().split())
    for j in range(l, r+1):
        c[j] += 1

ans = 0
for ci in c:
    if ci==m:
        ans+=1
print(ans)

Fixed submission:
n, m = map(int, input().split())
c = [0]*(n+1)
L, R = [], []
for i in range(m):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)
maxL = max(L)
minR = min(R)
print(max(minR+1-maxL, 0))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

A = list(map(int, input().split()))
A.sort()
X = []
for i in range(m):
    b, c = map(int, input().split())
    X += [c]*b
X.sort(reverse=True)

ans = sum(A)
for i in range(min(len(A), len(X))):
    if A[i] >= X[i]:
        break
    ans += X[i] - A[i]

print(ans)

Fixed submission:
n, m = map(int, input().split())

A = list(map(int, input().split()))
A.sort()
bc = []
for i in range(m):
    b, c = map(int, input().split())
    bc.append([b, c])
bc.sort(key=lambda x:x[1], reverse=True)

X = []
for b, c in bc:
    X += [c]*b
    if len(X) >= len(A):
        break

ans = sum(A)
for i in range(min(len(A), len(X))):
    if A[i] >= X[i]:
        break
    ans += X[i] - A[i]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

A = list(map(int, input().split()))
A.sort()
X = []
for i in range(m):
    b, c = map(int, input().split())
    X += [c]*b
X.sort(reverse=True)

for i in range(min(len(A), len(X))):
    if A[i] < X[i]:
        A[i] = X[i]
    else:
        break

print(sum(A))

Fixed submission:
n, m = map(int, input().split())

A = list(map(int, input().split()))
A.sort()
bc = []
for i in range(m):
    b, c = map(int, input().split())
    bc.append([b, c])
bc.sort(key=lambda x:x[1], reverse=True)

X = []
for b, c in bc:
    X += [c]*b
    if len(X) >= len(A):
        break

ans = sum(A)
for i in range(min(len(A), len(X))):
    if A[i] >= X[i]:
        break
    ans += X[i] - A[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, deque

class Node:

    def __init__(self, id, parent_id=None):
        self.id = id
        self.parent_id = parent_id
        self.distance = 0 

def distance_between(id1, id2):
    return distance_dict[(id1, id2)]


N = int(input())

distance_dict = {}
adj_dict = defaultdict(list)
for i in range(N-1):
    ui, vi, wi = map(int, input().split())
    distance_dict[(ui, vi)] = wi
    distance_dict[(vi, ui)] = wi
    adj_dict[ui].append(vi)
    adj_dict[vi].append(ui)

id_to_node = {}
cur_node = Node(id=2)
id_to_node[cur_node.id] = cur_node
open_list = deque()
open_list.append(cur_node)
closed_list = []
while True:
    if len(open_list) == 0:
        break
    cur_node = open_list.pop()
    closed_list.append(cur_node.id)
    adj_id_list = adj_dict[cur_node.id]
    for adj_id in adj_id_list:
        if adj_id in closed_list: 
            continue
        adj_node = Node(id=adj_id, parent_id=cur_node.id)
        adj_node.distance = distance_between(cur_node.id, adj_node.id)+cur_node.distance
        id_to_node[adj_id] = adj_node
        open_list.append(adj_node)

for id in range(1, N+1):
    if id_to_node[id].distance%2==0:
        print(0)
    else:
        print(1)

Fixed submission:
from collections import defaultdict

N = int(input())
edge = defaultdict(list)
# 辺の情報と距離を記録
for i in range(N-1):
    u, v, w = map(int, input().split())
    edge[u].append((v, w))
    edge[v].append((u, w))

# 幅優先探索
distance = [0]*N
queue = [(1, -1)]
while True:
    if len(queue) == 0:
        break
    cur_id, parent_id = queue.pop()
    for child_id, w in edge[cur_id].copy():
        if child_id == parent_id:
            continue
        queue.append((child_id, cur_id))
        distance[child_id-1] = distance[cur_id-1] + w

for i in range(N):
    print(distance[i]%2)
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd(numbers):
    return reduce(math.gcd, numbers)

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

max_gcd = 1
for i in range(N):
    i_gcd =  gcd(A[:(i-1)] + A[i:])
    if max_gcd < i_gcd:
        max_gcd = i_gcd

print(max_gcd)

Fixed submission:
def gcd(a, b):
    if b > a:
        a, b = b, a
    while b:
        a, b = b, a%b
    return a

def cul(n, x):
    l = len(x)
    b = x
    b.pop(n)
    tmp = b[0]
    for i in range(1, l-1):
        tmp = gcd(tmp, b[i])
    return tmp

import sys
p = 50
N = int(input())
if p>N: p=N
a = list(map(int, input().split()))

ans = 0
for i in range(p):
    s = cul(i, a[:p])
    if s>ans: ans=s

print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())

if (a, b, k) == (1, 1, 1):
    print(1)
    exit(0)
if k==1:

cnt = 0
for i in range(max(a,b), -1, -1):
    if a%i==0 and b%i==0:
        cnt+=1
    if cnt==k:
        break
print(i)

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

if (a, b, k) == (1, 1, 1):
    print(1)
    exit(0)

cnt = 0
for i in range(max(a,b), -1, -1):
    if a%i==0 and b%i==0:
        cnt+=1
    if cnt==k:
        break
print(i)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
print(min(b//a, c))

Fixed submission:
S = list(input())
n0 = S.count('0')
n1 = S.count('1')
print(2*min(n0, n1))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

INF = 10**4 + 1
dp = [INF] * N
dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2, N):
    candidate = []
    for j in range(i-K, i):
        if j >= 0:
            candidate.append(dp[j]+abs(h[i]-h[j]))
    dp[i] = min(candidate)

print(dp[-1])

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

dp = [0]*N

for i in range(1, N):
    h_to = h[i]
    dp[i] = min(
        [
            dp_from + abs(h_to - h_from)
            for dp_from, h_from in zip(
                dp[max(0, i-K):i], h[max(0, i-K):i]
            )
        ]
    )

print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())

w, v = [], []
for i in range(N):
    w_i, v_i = map(int, input().split())
    w.append(w_i)
    v.append(v_i)

# dp[i][j]: 荷物iまでにおける重さj以下の最大価値
dp = [[0]*(W+1) for i in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if w[i] > j:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i])

print(dp[-1][-1])

Fixed submission:
import numpy as np

N, W = map(int, input().split())

dp = np.zeros(W+1, dtype=np.int64)

for _ in range(N):
    w, v = map(int, input().split())
    np.maximum(dp[:-w]+v, dp[w:], out=dp[w:])

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
d, x = map(int, input().split())
a = list(map(int, [input() for i in range(n)]))

ans = 0

for t in range(1, d+1):
    for ai in a:
        if t%ai == 1:
            ans += 1

print(ans+x)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())

ans = min(a+c, a+d, b+c, b+d)
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
d, x = map(int, input().split())
a = list(map(int, [input() for i in range(n)]))

ans = 0

for t in range(1, d+1):
    for ai in a:
        if t%ai == 1:
            ans += 1

print(ans+x)


Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())

ans = min(a+c, a+d, b+c, b+d)
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

def possible():
    if N%2==0:
        for cnt in cnt_dict.values():
            if cnt != 2:
                return False
        return True
    else:
        for i, cnt in enumerate(cnt_dict.values()):
            if i==0:
                if cnt != 1:
                    return False
            else:
                if cnt != 2:
                    return False
        return True

N = int(input())
A = list(map(int, input().split()))
num = N//2

cnt_dict = defaultdict(list)

if N%2==0:
    for i in range(1, N, 2):
        cnt_dict[i] = 0
else:
    for i in range(0, N, 2):
        cnt_dict[i] = 0
for a in A:
    cnt_dict[a]+=1

if __name__ == "__main__":    

    if possible():
        mod = 10**9+7
        res = 1
        for i in range(1, num+1):
            res = res*2%mod
        print(res)
    else:
        print(0)

Fixed submission:
from collections import defaultdict

def possible():
    if N%2==0:
        for cnt in cnt_dict.values():
            if cnt != 2:
                return False
        return True
    else:
        for i, cnt in enumerate(cnt_dict.values()):
            if i==0:
                if cnt != 1:
                    return False
            else:
                if cnt != 2:
                    return False
        return True

N = int(input())
A = list(map(int, input().split()))
num = N//2

cnt_dict = defaultdict(list)

if N%2==0:
    for i in range(1, N, 2):
        cnt_dict[i] = 0
else:
    for i in range(0, N, 2):
        cnt_dict[i] = 0
for a in A:
    if not(a in cnt_dict.keys()):
        flag=False
    else:
        cnt_dict[a]+=1
        flag=True

if __name__ == "__main__":    

    if possible() and flag:
        mod = 10**9+7
        res = 1
        for i in range(1, num+1):
            res = res*2%mod
        print(res)
    else:
        print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N, x = map(int, input().split())
a = [0]+list(map(int, input().split()))

cnt = 0
for i in range(2, N+1):
    while True:
        if a[i-1]+a[i]>x:
            a[i] -= 1
            cnt += 1
        else:
            break
print(cnt)

Fixed submission:
N, x = map(int, input().split())
a = [0]+list(map(int, input().split()))

cnt = 0
for i in range(1, N+1):
    if i == 1:
        if a[i]>x:
            cnt += a[i]-x
            a[i] -= a[i]-x
        continue
    if a[i-1]+a[i]>x:
        cnt += a[i]+a[i-1]-x
        a[i] -= a[i]+a[i-1]-x
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int, input().split())

ans = []

for i in range(1, N+1):
    ans.append(((A*i)//B) - A*(i//B))

print(max(ans))

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

if N < B:
    ans = ((A*N)//B) - A*(N//B)
elif B <= N < 2*B:
    ans = max((((A*N)//B) - A*(N//B)), (((A*(B-1))//B) - A*((B-1)//B)))
elif 2*B <= N:
    ans = max((((A*(B-1))//B) - A*((B-1)//B)), (((A*(2*B-1))//B) - A*((2*B-1)//B)), (((A*(3*B-1))//B) - A*((3*B-1)//B)))

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(20000*20000)

S = str(input())
ans = set()
check = set()

def dfs(i, j):
    if (i, j) in check:
        return
    else:
        check.add((i, j))
    if int(S[i:j+1])%2019 == 0:
        ans.add((i, j))
    if j == len(S)-1:
        return

    dfs(i+1, j+1)
    dfs(i, j+1)

if len(S) < 4:
    print(0)

else:
    dfs(0, 3)
    print(len(ans))

Fixed submission:
s, w = map(int, input().split())

if s <= w:
    print('unsafe')
else:
    print('safe')
Buggy python submission (verdict: Runtime Error):
/usr/local/bin/python3.8 /Users/tmohiro/Desktop/Atcoder/ABC163/B.py
314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3
9

Process finished with exit code 0


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

total = sum(A)
if total > n:
    print(-1)
else:
    print(n-total)
Buggy python submission (verdict: Time Limit Exceeded):
import math
k = int(input())
ans = 0

for i in range(1, k+1):
    for j in range(1, k+1):
        for m in range(1, k+1):
            ans += math.gcd(math.gcd(i, j), m)

print(ans)

Fixed submission:
import math
k = int(input())
ans = 0
   
for i in range(1, k+1):
    for j in range(1, k+1):
        for m in range(1, k+1):
            ans += math.gcd(math.gcd(i, j), m)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = 0

for i in range(n):
    for j in range(i, n):
        if s[i] == s[j]:
            continue
        for k in range(j, n):
            if s[j] == s[k] or s[i] == s[k] or j-i == k-j:
                continue

            ans += 1

print(ans)

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

R = s.count('R')
G = s.count('G')
B = s.count('B')
ans = R*G*B

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n: break
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = 0

for i in range(n):
    for j in range(i, n):
        for k in range(j, n):
            if (s[i] != s[j] and s[i] != s[k] and s[j] != s[k]) and (j-i != k-j):
                ans += 1

print(ans)

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

R = s.count('R')
G = s.count('G')
B = s.count('B')
ans = R*G*B

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n: break
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            ans -= 1

print(ans)