Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
m=float('INF')
sa=[]
for i,a in enumerate(A):
    sa.append(sa[i]+ai)
for i in range(n+1):
    ans=min(ans,abs(sa[i]-(sa[-1]-sa[i])))
print(ans)
    

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
ans=float('INF')
sa=[0]
for i,a in enumerate(A):
    sa.append(sa[i]+a)
for i in range(n+1):
    ans=min(ans,abs(sa[i]-(sa[-1]-sa[i])))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))
m=float('inf')
s=sum(A)
for i in range(len(A)):
    m=min(m,abs(2*sum(A[0:i])-s))
print(m)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
ans=float('INF')
sa=[0]
for i,a in enumerate(A):
    sa.append(sa[i]+a)
for i in range(n+1):
    ans=min(ans,abs(sa[i]-(sa[-1]-sa[i])))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))
m=float('inf')
for i in range(len(A)):
    m=min(m,abs(sum(A[0:i])-sum(A[i:n])))
print(m)


Fixed submission:
n=int(input())
A=list(map(int,input().split()))
ans=float('INF')
sa=[0]
for i,a in enumerate(A):
    sa.append(sa[i]+a)
for i in range(n+1):
    ans=min(ans,abs(sa[i]-(sa[-1]-sa[i])))
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = list(map(int,input().split()))
if d[0] != 0:
    print(0)
else:
    ans = 1
    most_far = max(d)
    for i in range(most_far-1):
        ans *= d.count(most_far - (i+1))**d.count(most_far-i)
print(ans)

    
    

Fixed submission:
from collections import Counter
mod = 998244353
n = int(input())
d = list(map(int,input().split()))
if d[0] != 0:
    print(0)
    exit()

C = Counter(d)
C = dict(sorted(C.items()))

memo1 = C[1]
memo2 = 1
ans = 1

for i in range(1,n):
    if d[i] == 0:
        print(0)
        exit()

for key in C:
    if key >= 2:
        if memo2 + 1 != key: #道が途切れている場合はダメ
            print(0)
            exit()
        ans = (ans * memo1 ** C[key]) % mod #modは和について閉じているため先にわる
        memo1 = C[key]
        memo2 = key
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
d = list(map(int,input().split()))
if d[0] != 0:
    print(0)
else:
    ans = 1
    for i in range(1,n):
        dp = d[i] - 1
        ans *= d.count(dp)
print(ans)


Fixed submission:
from collections import Counter
mod = 998244353
n = int(input())
d = list(map(int,input().split()))
if d[0] != 0:
    print(0)
    exit()

C = Counter(d)
C = dict(sorted(C.items()))

memo1 = C[1]
memo2 = 1
ans = 1

for i in range(1,n):
    if d[i] == 0:
        print(0)
        exit()

for key in C:
    if key >= 2:
        if memo2 + 1 != key: #道が途切れている場合はダメ
            print(0)
            exit()
        ans = (ans * memo1 ** C[key]) % mod #modは和について閉じているため先にわる
        memo1 = C[key]
        memo2 = key
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))
for i in range(1,n):
    print(str(A.index(i)+1)+" ",end="")
print(str(A.index(n)+1),end="")
    

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
ans=[None for i in range(n)]
for i in range(n):
    ans[A[i]-1]=str(i+1)
print(" ".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))
ans=[]
for i in range(1,n+1):
    ans.append(A.index(i)+1)
print(*ans)
    

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
ans=[None for i in range(n)]
for i in range(n):
    ans[A[i]-1]=str(i+1)
print(" ".join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
for i in range(m):
    A[0]//=2
    A.sort(reverse=True)
print(sum(A))

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

a=list(map(lambda x:int(x)*(-1), input().split()))
heapq.heapify(a)

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a,(-1)*(-tmp_min//2))
print(-sum(a))
Buggy python submission (verdict: Runtime Error):
def solve():
    def dfs(tree, n, ans):
        for i in tree[n]:
            ans[i] += ans[n]
            tree[i].remove(n)
            dfs(tree, i, ans) #再帰関数になっている。次の木の中を探索
     
    n, q = map(int,input().split())
    ab = [list(map(int,input().split())) for _ in range(n-1)]
    px = [list(map(int,input().split())) for _ in range(q)]
     
    g = [[] for _ in range(n)]
    for i in range(n-1):
        g[ab[i][0]-1].append(ab[i][1]-1)
        g[ab[i][1]-1].append(ab[i][0]-1)
    
    ans = [0]*n
    for i in range(q):
        ans[px[i-1][0]-1] += px[i-1][1]
    dfs(g, 0, ans)
     
    print(*ans)
    
if __name__ == "__main__":
    solve()

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
def dfs(tree, n, ans):
    for i in tree[n]:
        ans[i] += ans[n]
        tree[i].remove(n)
        dfs(tree, i, ans)
 
n, q = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n-1)]
px = [list(map(int,input().split())) for _ in range(q)]
 
g = [[] for _ in range(n)]
for i in range(n-1):
    g[ab[i][0]-1].append(ab[i][1]-1)
    g[ab[i][1]-1].append(ab[i][0]-1)
 
ans = [0]*n
for i in range(q):
    ans[px[i-1][0]-1] += px[i-1][1]
dfs(g, 0, ans)
 
print(*ans)

Buggy python submission (verdict: Runtime Error):
def dfs(tree, n, ans):
    for i in tree[n]:
        ans[i] += ans[n]
        tree[i].remove(n)
        dfs(tree, i, ans)

n, q = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n-1)]
px = [list(map(int,input().split())) for _ in range(q)]
 
g = [[] for _ in range(n)]

for i in range(n-1):
    g[ab[i][0]-1].append(ab[i][1]-1)
    g[ab[i][1]-1].append(ab[i][0]-1)

ans = [0]*n
for i in range(q):
    ans[px[i-1][0]-1] += px[i-1][1]
dfs(g, 0, ans)

print(*ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
def dfs(tree, n, ans):
    for i in tree[n]:
        ans[i] += ans[n]
        tree[i].remove(n)
        dfs(tree, i, ans)
 
n, q = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n-1)]
px = [list(map(int,input().split())) for _ in range(q)]
 
g = [[] for _ in range(n)]
for i in range(n-1):
    g[ab[i][0]-1].append(ab[i][1]-1)
    g[ab[i][1]-1].append(ab[i][0]-1)
 
ans = [0]*n
for i in range(q):
    ans[px[i-1][0]-1] += px[i-1][1]
dfs(g, 0, ans)
 
print(*ans)
Buggy python submission (verdict: Runtime Error):
S=input()
l=len(S)
def solve(s,h):
    if h==1:
        return 1
    elif h==2:
        if s[0]==s[1]:
            return 1
        else:
            return 2
    else:
        if s[h-1]==s[h-2]:
            return solve(s,h-3)+2
        else:
            return solve(s,h-1)+1
print(solve(S,l))
        

Fixed submission:
S=input()
cnt=0
pre=''
tmp=''
for s in S:
    tmp+=s
    if tmp!=pre:
        pre=tmp
        tmp=''
        cnt+=1
print(cnt)

Buggy python submission (verdict: Runtime Error):
S=input()
l=len(S)
def solve(s,h):
    if h==1:
        return 1
    elif h==2:
        if s[0]==s[1]:
            return 1
        else:
            return 2
    elif h==0:
        return 0
    else:
        if s[h-1]==s[h-2]:
            return solve(s,h-3)+2
        else:
            return solve(s,h-1)+1
print(solve(S,l))
        

Fixed submission:
S=input()
cnt=0
pre=''
tmp=''
for s in S:
    tmp+=s
    if tmp!=pre:
        pre=tmp
        tmp=''
        cnt+=1
print(cnt)

Buggy python submission (verdict: Runtime Error):
S=input()
l=len(S)
def solve(s,h):
    if h==1:
        return 1
    elif h==2:
        if s[0]==s[1]:
            return 1
        else:
            return 2
    elif h==0:
        return 0
    else:
        if s[h-1]==s[h-2]:
            return solve(s,h-3)+2
        else:
            return solve(s,h-1)+1
print(solve(S,l))

Fixed submission:
S=input()
cnt=0
pre=''
tmp=''
for s in S:
    tmp+=s
    if tmp!=pre:
        pre=tmp
        tmp=''
        cnt+=1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
def f():
    s = int(input())
    for i in range(int(s**0.5), -1, -1):
        if s%i == 0:
            x = i
            y = s//i
            break
    
    
    ans = [0, 0]
    ans.append(x)
    ans.append(0)
    ans.append(0)
    ans.append(y)
    print(*ans)

if __name__ == '__main__':
    f()

Fixed submission:
def f():
    s = int(input())
    i9 = 10**9
    if s == i9 ** 2:
        print(i9, 0, 0, i9, 0, 0)
    else:
        print(i9 - (s%i9), s//i9 + 1, i9, 1, 0, 0)

if __name__ == '__main__':
    f()
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
D=list(map(int,input().split()))
cnt=0
for i in range(min(D),max(D)+1):
    c=[]
    for d in D:
        if d>=i:
            c.append(d)
    if len(c)==N//2:
        cnt+=1
print(cnt)

Fixed submission:
n=int(input())
D=list(map(int,input().split()))
D=sorted(D,reverse=True)
print(D[n//2-1]-D[n//2])
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
ID=[0 for i in range(n)]
for i in range(m):
    l,r=map(int,input().split())
    for j in range(r-l+1):
        ID[l-1+j]+=1
print(ID.count(m))

Fixed submission:
n,m=map(int,input().split())
L=[]
R=[]
for i in range(m):
    l,r=map(int,input().split())
    L.append(l)
    R.append(r)
print(min(R)-max(L)+1 if min(R)-max(L)+1>0 else 0)
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))

law_ans = 0
absminA = float('inf')
for a in A:
    law_ans += abs(a)
    absminA = min(absminA, abs(a))


cnt_neg = 0

for a in A:
    if a < 0:
        cnt_neg += 1

cnt_0 = A.count(0)

if cnt_0 == 0:
    if cnt_neg%2 == 0:
        print(law_ans)
    else:
        print(law_ans-2*absminA)
else:
    pritn(law_ans)


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

law_ans = 0
absminA = float('inf')
for a in A:
    law_ans += abs(a)
    absminA = min(absminA, abs(a))


cnt_neg = 0

for a in A:
    if a < 0:
        cnt_neg += 1

cnt_0 = A.count(0)

if cnt_0 == 0:
    if cnt_neg%2 == 0:
        print(law_ans)
    else:
        print(law_ans-2*absminA)
else:
    print(law_ans)

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

law_ans = 0
absminA = float('inf')
for a in A:
    law_ans += abs(a)
    absminA = min(absminA, a)


cnt_neg = 0

for a in A:
    if a < 0:
        cnt_neg += 1

cnt_0 = A.count(0)

if cnt_0 == 0:
    if cnt_neg%2 == 0:
        print(law_ans)
    else:
        print(law_ans-2*absminA)
else:
    pritn(law_ans)


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

law_ans = 0
absminA = float('inf')
for a in A:
    law_ans += abs(a)
    absminA = min(absminA, abs(a))


cnt_neg = 0

for a in A:
    if a < 0:
        cnt_neg += 1

cnt_0 = A.count(0)

if cnt_0 == 0:
    if cnt_neg%2 == 0:
        print(law_ans)
    else:
        print(law_ans-2*absminA)
else:
    print(law_ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())

ans = float('inf')

for i in range(n+1):
    ans = min(ans, s[:i].count('#') + s[i+1:].count('.'))
print(ans)

Fixed submission:
n = int(input())
s = input()
x = 0
y = s.count('.')
c = min(n-y, y)
for i in range(n):
    t = s[i] == '#' #＃であればｔがTrueになる
    x += t
    y -= 1 - t
    c = min(c, x+y)
print(c)

Buggy python submission (verdict: Runtime Error):
from copy import *
n = int(input())
s = list(input())
S = []
l = 0
for i in range(n-1):
    if s[i] != s[i+1]:
        S.append(s[l:i+1])
        l = i+1
if S[-1][0] == s[-1]:
    S[-1] += s[l:]
else:
    S.append(s[l:])


ans = 0
m = len(S)

if S[0][0] == '#':
    for i in range(m//2):
        ans += min(len(S[i*2]), len(S[i*2+1]))
else:
    for i in range(m//2 - 1):
        ans += min(len(S[i*2+1]), len(S[i*2+2]))

print(ans)

Fixed submission:
n = int(input())
s = input()
x = 0
y = s.count('.')
c = min(n-y, y)
for i in range(n):
    t = s[i] == '#' #＃であればｔがTrueになる
    x += t
    y -= 1 - t
    c = min(c, x+y)
print(c)

Buggy python submission (verdict: Runtime Error):
 = int(input())
s = list(input())
cnt1 = 0
for i in range(n-1):
    if s[i] == '#' and s[i+1] == '.':
        cnt += 1
        s[i+1] = '#'

cnt2 = 0
for i in range(n-1):
    if s[i] == '#' and s[i+1] == '.':
        cnt2 += 1
        s[i+1] = '.'


print(min(cnt1, cnt2))

Fixed submission:
n = int(input())
s = input()
x = 0
y = s.count('.')
c = min(n-y, y)
for i in range(n):
    t = s[i] == '#' #＃であればｔがTrueになる
    x += t
    y -= 1 - t
    c = min(c, x+y)
print(c)
Buggy python submission (verdict: Runtime Error):
ースコード 

Copy
Copy
#参考 ： AtCoder # 14682107
s = input()
len = len(s)
 
if len == 1:
    print(0)
    exit()
 
even = s[::2]
odd = s[1::2]
 
#偶数番目に0が並ぶと仮定したときの異物の数
# 0101...
odd_zero = odd.count("0")
even_one = even.count("1")
 
 
#奇数番目に0が並ぶと仮定したときの異物の数
# 1010...
odd_one = odd.count("1")
even_zero = even.count("0")
 
print(min(odd_zero + even_one, odd_one + even_zero))

Fixed submission:
s = input()
l= len(s)
 
if l== 1:
    print(0)
    exit()
 
even = s[::2]
odd = s[1::2]

odd_zero = odd.count("0")
even_one = even.count("1")
 

odd_one = odd.count("1")
even_zero = even.count("0")
 
print(min(odd_zero + even_one, odd_one + even_zero))

Buggy python submission (verdict: Runtime Error):
ースコード 

Copy
Copy
#参考 ： AtCoder # 14682107
s = input()
len = len(s)
 
if len == 1:
    print(0)
    exit()
 
even = s[::2]
odd = s[1::2]
 
#偶数番目に0が並ぶと仮定したときの異物の数
# 0101...
odd_zero = odd.count("0")
even_one = even.count("1")
 
 
#奇数番目に0が並ぶと仮定したときの異物の数
# 1010...
odd_one = odd.count("1")
even_zero = even.count("0")
 
print(min(odd_zero + even_one, odd_one + even_zero))

Fixed submission:
s = input()
l= len(s)
 
if l== 1:
    print(0)
    exit()
 
even = s[::2]
odd = s[1::2]

odd_zero = odd.count("0")
even_one = even.count("1")
 

odd_one = odd.count("1")
even_zero = even.count("0")
 
print(min(odd_zero + even_one, odd_one + even_zero))
Buggy python submission (verdict: Runtime Error):
S=list(str(input()))
A=["A","T","G","C"]
#print(S)
cnt=0
ans=[]
for (i,s) in enumerate(S):
    if s in A:
        cnt+=1
    else:
        ans.append(cnt)
        cnt=0
print(max(ans))

Fixed submission:
S=input()
n=len(S)
ans=0
for i in range(n):
    for j in range(i,n):
        if all('ACGT'.count(c)==1 for c in S[i:j+1]):
            ans=max(ans,j-i+1)
print(ans)

Buggy python submission (verdict: Runtime Error):
S=list(str(input()))
A=["A","T","G","C"]
print(S)
cnt=0
ans=[]
for (i,s) in enumerate(S):
    if s in A:
        cnt+=1
    else:
        ans.append(cnt)
        cnt=0
print(max(ans))

Fixed submission:
S=input()
n=len(S)
ans=0
for i in range(n):
    for j in range(i,n):
        if all('ACGT'.count(c)==1 for c in S[i:j+1]):
            ans=max(ans,j-i+1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=int(input())
a=[]
a.append(s)
for i in range(10**6):
    if s%2==0:
        s//=2
        a.append(s)
    else:
        s=3*s+1
        a.append(s)
for i in range(10**6):
    for j in range(i+1,10**6):
        if a[i]==a[j]:
            print(j+1)
            exit(0)


Fixed submission:
s=int(input())
a=[]
a.append(s)
for i in range(10**6):
    if s%2==0:
        s//=2
        if s in a:
            print(i+2)
            break
        else:
            a.append(s)
    else:
        s=3*s+1
        if s in a:
            print(i+2)
            break
        else:
            a.append(s)
Buggy python submission (verdict: Runtime Error):
keyence

Fixed submission:
s=input()
ans=False
for x in range(len(s)):
    for y in range(x,len(s)):
        if (s[:x]+s[y:])=='keyence':
            ans=True
if ans:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
H = list(map(int,input().split()))
dp=[float('inf') for i in range(n)]
k=n-1 if k>n-1 else k
for i in range(k):
    if i==0:
        dp[0]=0
    else:
        f=float('inf')
        for j in range(i):
            f=min(f,dp[j]+abs(H[j]-H[i]))
        dp[i]=f

for i in range(n-k):
    x=float('inf')
    for j in range(k):
        x=min(x,dp[i+k-j-1]+abs(H[i+k]-H[i+k-j-1]))
    dp[i+k]=x

print(dp[n-1])

Fixed submission:
import numpy as np
n,k = map(int,input().split())
h = np.array(list(map(int, input().split())))
dp = np.array([np.inf] * n)
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    if i-k > 0:
        dp[i] = min(dp[i-k:i]+abs(h[i]-h[i-k:i]))
    else:
        dp[i] = min(dp[0:i]+abs(h[i]-h[0:i]))
print(int(dp[n-1]))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
n = len(s)

for i in range(n):
    if s.count(s[i]) == 1:
        continue
    else:
        memo1 = [t[i]]
        for j in range(i+1,n):
            if s[j] == s[i]:
                memo1.append(t[j])
        if len(set(memo1)) != 1:
            print('No')
            exit()


for i in range(n):
    if t.count(t[i]) == 1:
        continue
    else:
        memo2 = [s[i]]
        for j in range(i+1,n):
            if t[j] == t[i]:
                memo2.append(s[j])
        if len(set(memo2)) != 1:
            print('No')
            exit()
print('Yes')

Fixed submission:
s = input()
t = input()
n = len(s)
x = []
y = []

for i in range(n):
    if s[i] not in x:
        x.append(s[i])
    if t[i] not in y:
        y.append(t[i])

for i in range(len(x)):
    s = s.replace(x[i], str(i))
for i in range(len(y)):
    t = t.replace(y[i], str(i))
print('Yes' if s == t else 'No')
Buggy python submission (verdict: Runtime Error):
n=int(input())
lw=[input() for i in range(n)]
used=set()
last=lw[0][0]
for w in lw:
    if w in used or last !=w[0]:
        cond=False
        break
    used.add(w)
    last=w[-1]
print("Yes" if cond else "No")

Fixed submission:
n=int(input())
lw=[input() for i in range(n)]
used=set()
cond=True
last=lw[0][0]
for w in lw:
    if w in used or last !=w[0]:
        cond=False
        break
    used.add(w)
    last=w[-1]
print("Yes" if cond else "No")
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,k=map(int,input().split())
if a==b and b==c:
    print(0)
else:
    for i in range(k):
        a,b,c=b+c,a+c,a+b
    if abs(a-b)>10**18:
        print("Unfair")
    else:
        print(a-b)
    

Fixed submission:
a,b,c,k=map(int,input().split())
if abs(a-b)<10**18:
    if k%2==0:
        print(a-b)
    else:
        print(b-a)
else:
    print("Unfair")
Buggy python submission (verdict: Runtime Error):
N,H=map(int,input().split())
B=[]
A=0
for _ in range(N):
    a,b = map(int,input().split())
    A = max(A,a)
    B.append(b)
B = sorted(reverse=True) + [0]

i = 0
while B[i] >= A:
    i += 1
B = B[:i]

ans = 0
for i in range(len(B)):
    H -= B[i]
    ans += 1
    if H <= 0:
        print(ans)
        exit()
print(ans + (H -1)//A + 1)


Fixed submission:
N,H=map(int,input().split())
B=[]
A=0
for _ in range(N):
    a,b=map(int,input().split())
    A=max(A,a)
    B.append(b)
B.sort(reverse=True)
ans=(H-1)//A+1
for i in range(N):
    H-=B[i]
    if H<=0:
        ans=min(ans,i+1)
        break
    ans=min(ans,(H-1)//A+1+i+1)
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
s=input()
f=s.index("-")
l=len(s)-s.index("-")-1
print("Yes" if a==f and b==l else "No")

Fixed submission:
a,b = map(int,input().split())
s = input()
for i in range(a):
    if s[i] == '-':
        print('No')
        exit(0)
 
if s[a] != '-':
    print('No')
    exit(0)
 
for i in range(a+1,a+b):
    if s[i] == '-':
        print('No')
        exit(0)
 
print('Yes')
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[2,1]
for i in range(84):
    a.append(a[i]+a[i+1])
print(a[n])

Fixed submission:
n=int(input())
a=[2,1]
for i in range(100):
    a.append(a[i]+a[i+1])
print(a[n])
Buggy python submission (verdict: Runtime Error):
h,w = map(int,input().split())
s = []
for i in range(h):
    s.append(list(input()))

dx = [-1,0,1,-1,1,-1,0,1]
dy = [1,1,1,0,0,-1,-1,-1]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            continue
        cnt = 0
        for t in range(8):
            ni=i+dx[t]
            nj=j+dy[t]
            if ni<0 or h<=ni: continue
            if nj<0 or h<=nj: continue
            if s[ni][nj] == '#':
                cnt += 1
        
        s[i][j] = str(cnt)

for i in s:
    print(''.join(i))

Fixed submission:
h,w = map(int,input().split())
s = []
for i in range(h):
    s.append(list(input()))

dx = [-1,0,1,-1,1,-1,0,1]
dy = [1,1,1,0,0,-1,-1,-1]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            continue
        cnt = 0
        for t in range(8):
            ni=i+dx[t]
            nj=j+dy[t]
            if ni<0 or h<=ni: continue
            if nj<0 or w<=nj: continue
            if s[ni][nj] == '#':
                cnt += 1
        
        s[i][j] = str(cnt)

for i in s:
    print(''.join(i))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))
ans=0
for i in range(min(A)-1,max(A)+2):
    x=0
    for a in A:
        if a-1==i or a==i or a+1==i:
            x+=1
    ans=max(ans,x)
print(ans)
    

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
D=[0 for i in range(10**7)]
for a in A:
    D[a-1]+=1
    D[a]+=1
    D[a+1]+=1
print(max(D))
Buggy python submission (verdict: Runtime Error):
n=int(input())
tens=[]
others=[]
for i in range(n):
    s=int(input())
    if s%10==0:
        tens.append(s)
    else:
        others.append(s)
tens.sort(reverse=True)
others.sort(reverse=True)

score=sum(tens)+sum(others)
if score%10==0:
    print(score-min(others))
else:
    print(score)

Fixed submission:
n=int(input())
tens=[]
others=[]
for i in range(n):
    s=int(input())
    if s%10==0:
        tens.append(s)
    else:
        others.append(s)
tens.sort(reverse=True)
others.sort(reverse=True)

score=sum(tens)+sum(others)
if score%10==0:
    if len(others)!=0:
        print(score-min(others))
    else:
        print(0)
else:
    print(score)
Buggy python submission (verdict: Runtime Error):
from itertools import combinations
import math
n,d=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(n)]
cnt=0
for perm in list(combinations(range(n),2)):
    d=sum(map(lambda x: (x[0]-x[1])**2,zip(X[perm[0]],X[perm[1]])))
    if d==int(math.sqrt(d))**2:
        cnt+=1
print(cnt)

Fixed submission:
n,m=map(int,input().split())
d={}
for i in range(n):
    d[i]=0
for i in range(m):
    a,b=map(int,input().split())
    d[a-1]+=1
    d[b-1]+=1
for i in range(n):
    print(d[i])

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
d={}
for i in range(5):
    d[i]=0
for i in range(m):
    a,b=map(int,input().split())
    d[a-1]+=1
    d[b-1]+=1
for i in range(n):
    print(d[i])

Fixed submission:
n,m=map(int,input().split())
d={}
for i in range(n):
    d[i]=0
for i in range(m):
    a,b=map(int,input().split())
    d[a-1]+=1
    d[b-1]+=1
for i in range(n):
    print(d[i])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)

ans = n
for i in range(1,n):
    if a[i-1] <= 2*sum(a[i:]):
        pass
    else:
        print(i)
        exit()

print(n)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
sum_a = sum(a)

ans = n
for i in range(1,n):
    sum_a -= a[i-1]
    if a[i-1] <= 2*sum_a:
        pass
    else:
        print(i)
        exit()

print(n)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
x=1
for i in range(1,n+1):
    x*=i
print(x%(10**9+7))

Fixed submission:
n=int(input())
mod=10**9+7
power=1
for i in range(1,n+1):
    power=power*i%mod
print(power)