Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
nums = [int(input()) for _ in range(5)]
l = map(int,filter(lambda x:x !="0",[str(n)[-1] for n in nums]))
r = [(n+9) // 10 for n in nums]
print(sum(r)*10-(10-min(l))) if len(l) != 0 else print(sum(r)*10)

Fixed submission:
nums = [int(input()) for _ in range(5)]
l = list(map(int,filter(lambda x:x !="0",[str(n)[-1] for n in nums])))
r = [(n+9) // 10 for n in nums]
print(sum(r)*10-(10-min(l))) if len(l) != 0 else print(sum(r)*10)

Buggy python submission (verdict: Runtime Error):
nums = [int(input()) for _ in range(5)]
l = map(int,filter(lambda x:x !="0",[str(n)[-1] for n in nums]))
r = [(n+9) // 10 for n in nums]
print(sum(r)*10-(10-min(l)))

Fixed submission:
nums = [int(input()) for _ in range(5)]
l = list(map(int,filter(lambda x:x !="0",[str(n)[-1] for n in nums])))
r = [(n+9) // 10 for n in nums]
print(sum(r)*10-(10-min(l))) if len(l) != 0 else print(sum(r)*10)
Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
AC = []
ans = []
AC.append(0)
for i in range(1,N+1):
    if S[i - 1] == "A" and S[i] == "C":
        AC.append(AC[i - 1] + 1)
    else:
        AC.append(AC[i - 1])
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(AC[r - 1] - AC[l - 1])
print("\n".join(map(str,ans)))

Fixed submission:
N, Q = map(int, input().split())
S = input()
AC = []
ans = []
AC.append(0)
for i in range(1,N):
    if S[i - 1] == "A" and S[i] == "C":
        AC.append(AC[i - 1] + 1)
    else:
        AC.append(AC[i - 1])
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(AC[r - 1] - AC[l - 1])
print("\n".join(map(str,ans)))
Buggy python submission (verdict: Runtime Error):
#ABC117 A
T, X = input(split())
print(T/X)

Fixed submission:
#ABC117 A
T, X = map(int, input().split())
print(T/X)
Buggy python submission (verdict: Runtime Error):
#ABC117 B
N = int(input())
Ln = list(map(int, input().split()))
Ln.sort()
max = L[0]
sum = sum(ln)
    
if max < max - sum:
    print("Yes")
else:
    print("No")


Fixed submission:
#ABC117 B
N = int(input())
Ln = list(map(int, input().split()))
Ln.sort(reverse=True)
max = Ln[0]
sum = sum(Ln)
    
if max < sum - max:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
#ABC117 B
N = int(input())
Ln = [input() for i in range(N)]
Ln.sort()
max = L[0]
sun = 0
for i in N-1:
    sum += L[i+1]
    
if max < sum:
    print("Yes")
else:
    print("No")


Fixed submission:
#ABC117 B
N = int(input())
Ln = list(map(int, input().split()))
Ln.sort(reverse=True)
max = Ln[0]
sum = sum(Ln)
    
if max < sum - max:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
#ABC117 B
N = int(input()
Ln = [input() for i in range(N)]
Ln.sort()
max = L[0]
sun = 0
for i in N-1:
sum += L[i+1]
    
if max < sum:
    print("Yes")
else:
    print("No")


Fixed submission:
#ABC117 B
N = int(input())
Ln = list(map(int, input().split()))
Ln.sort(reverse=True)
max = Ln[0]
sum = sum(Ln)
    
if max < sum - max:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M = map(int, input().split())
X = list(map(int, input().split()))

if M == 1:
    print(0)
else:
    X.sort()
    X_difs = np.array(X)
    X_difs = np.diff(X_difs)
    X_difs[::-1].sort()
    for _ in range(N-1):
        X_difs = np.delete(X_difs, 0)
        
    print(sum(X_difs))


Fixed submission:
N, M = map(int, input().split())
X = list(map(int, input().split()))
if M == 1 or N>=M:
    print(0)
else:
    X.sort()
    X_difs = [X[i+1] - X[i] for i in range(M-1)]
    X_difs.sort()
    for _ in range(N-1):
        X_difs.pop(-1)
    print(sum(X_difs))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
X = list(map(int, input().split()))
if M == 1:
    print(0)
else:
    X.sort()
    X_difs = [X[i+1] - X[i] for i in range(M-1)]
    X_difs.sort()
    for _ in range(N-1):
        X_difs.pop(-1)
    print(sum(X_difs))


Fixed submission:
N, M = map(int, input().split())
X = list(map(int, input().split()))
if M == 1 or N>=M:
    print(0)
else:
    X.sort()
    X_difs = [X[i+1] - X[i] for i in range(M-1)]
    X_difs.sort()
    for _ in range(N-1):
        X_difs.pop(-1)
    print(sum(X_difs))
Buggy python submission (verdict: Runtime Error):
#ABC117 A
T, X = map(int, input().split())
print(T/X)


Fixed submission:
#ABC116 A
AB, BC, CA = list(map(int, input().split()))
print(AB*BC//2)
Buggy python submission (verdict: Time Limit Exceeded):

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

dp = [float("inf")] * N
dp[0] = 0

for i in range(N):
    for j in range(1, K + 1):
        if i>=j:
                dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]),dp[i])

print(dp[-1])

Fixed submission:

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

dp = [float("inf")] * N
dp[0] = 0

for i in range(N):
    for j in range(1, K + 1):
        if i>=j:
                dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]),dp[i])

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
#コピペコード
H, W = map(int, input().split())
a = [input() for _ in range(H)]
row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True
 
for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end = '')
		print()

Fixed submission:
#コピペコード
H, W = map(int, input().split())
a = [input() for _ in range(H)]
row = [False] * H
col = [False] * W
for i in range(H):
	for j in range(W):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True
 
for i in range(H):
	if row[i]:
		for j in range(W):
			if col[j]:
				print(a[i][j], end = '')
		print()
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
for s in S:
    if s == "1":
        if K == 1:
            print(1)
            break
        k -= 1
        continue
    print(s)
    break

Fixed submission:
S = input()
K = int(input())
for s in S:
    if s == "1":
        if K == 1:
            print(1)
            break
        K -= 1
        continue
    print(s)
    break
Buggy python submission (verdict: Runtime Error):
#ABC105B
N = int(input())
OK = False
for i in range(N/4):
    for j in range(N/7):
        if i*4 + j*7 == N:
            OK = True
if OK:
    print("Yes")
else:
    print("No") 

Fixed submission:
#ABC105B
N = int(input())
flag = False
for i in range(30):
    for j in range(30):
        if i*4 + j*7 == N:
            flag = True
if flag:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
#ABC105B
N = int(input())
OK = False
for i in range(N/4):
    for j in range(N/7):
        if i*4 + j*7 == N:
            flag = True
if OK:
    print("Yes")
else:
    print("No") 

Fixed submission:
#ABC105B
N = int(input())
flag = False
for i in range(30):
    for j in range(30):
        if i*4 + j*7 == N:
            flag = True
if flag:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import sys
S = input()
T = input()
length = len(S)
for i in range(length):
    if S[length - i - 1 :] + S[: length - i - 1] == T:
        print("Yes")
        sys.exit(1)
print("No")

Fixed submission:
import sys
S = input()
T = input()
length = len(S)
for i in range(length):
    if S[length - i - 1 :] + S[: length - i - 1] == T:
        print("Yes")
        sys.exit(0)
print("No")
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
import sys
dxy = [(1,0),(0,1),(-1,0),(0,-1)]
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            flag = 0
            for dy,dx in dxy:
                if 0<= i+dy < W and 0 <= i+dx < H and s[i+dy][j+dx] == "#":
                    flag = 1
            if flag == 0:
                print("No")
                sys.exit(0)
print("Yes")


Fixed submission:
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
import sys
dxy = [(1,0),(0,1),(-1,0),(0,-1)]
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            flag = 0
            for dy,dx in dxy:
                if 0<= i+dy < H and 0 <= j+dx < W and s[i+dy][j+dx] == "#":
                    flag = 1
            if flag == 0:
                print("No")
                sys.exit(0)
print("Yes")
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = list(map(int,input().split()))
ans1 = 0
ans2 = 0
for a in A:
    if M > a:
        ans1 +=1
    else:
        ans2 +=1 
print(min(ans1,ans2))

Fixed submission:
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
ans1 = 0
ans2 = 0
for a in A:
    if X > a:
        ans1 +=1
    else:
        ans2 +=1 
print(min(ans1,ans2))

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = list(map(int,input().split()))
ans1 = 0
ans2 = 0
for a in A:
    if M > a:
        ans1 +=1
    else:
        ans2 +=1 
paint(min(ans1,ans2))

Fixed submission:
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
ans1 = 0
ans2 = 0
for a in A:
    if X > a:
        ans1 +=1
    else:
        ans2 +=1 
print(min(ans1,ans2))

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = list(map(int,input().split()))
ans1 = 0
ans2 = 0
for a in A:
    if x > a:
        ans1 +=1
    else:
        ans2 +=1 
paint(min(ans1,ans2))

Fixed submission:
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
ans1 = 0
ans2 = 0
for a in A:
    if X > a:
        ans1 +=1
    else:
        ans2 +=1 
print(min(ans1,ans2))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
now = 0
ans = []

A.append(0)
A.insert(0,0)
for i in range(len(A)-1):
    ans.append(abs(A[i+1]-A[i]))

for j in range(1,len(A)-1):
    print(sum(ans)-ans[j]-ans[j-1]+abs(A[j+1]-A[j-1]))

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
now = 0
ans = []

A.append(0)
A.insert(0,0)
for i in range(len(A)-1):
    ans.append(abs(A[i+1]-A[i]))

sm = sum(ans)

for j in range(1,len(A)-1):
    print(sm-ans[j]-ans[j-1]+abs(A[j+1]-A[j-1]))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
now = 0
ans = []

A.append(0)
A.insert(0,0)
for i in range(len(A)-1):
    ans.append(abs(A[i+1]-A[i]))

for j in range(1,len(A)-1):
    print(sum(ans)-ans[j]-ans[j-1]+abs(A[j+1]-A[j-1]))

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
now = 0
ans = []

A.append(0)
A.insert(0,0)
for i in range(len(A)-1):
    ans.append(abs(A[i+1]-A[i]))

sm = sum(ans)

for j in range(1,len(A)-1):
    print(sm-ans[j]-ans[j-1]+abs(A[j+1]-A[j-1]))
Buggy python submission (verdict: Runtime Error):
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]

s.sort()
t.sort()

ans = 0
sset = set(s)

for si in sset:
    ans = max(ans, s.count(si)-t.coutn(si))
print(ans)

Fixed submission:
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]

s.sort()
t.sort()

ans = 0
sset = set(s)

for si in sset:
    ans = max(ans, s.count(si)-t.count(si))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#https://atcoder.jp/contests/abc089/tasks/abc089_c
import itertools
N = int(input())
S = [input() for _ in range(N)]
march = [0]*max(N,3)
ans = 0
for s in S:
    if s[0] == "M":
        march[0] +=1
    if s[0] == "A":
        march[1] +=1
    if s[0] == "R":
        march[2] +=1
    if s[0] == "C":
        march[3] +=1
    if s[0] == "H":
        march[4] +=1

for i,j,k in itertools.combinations(march,3):
    ans += i*j*k
print(ans)

Fixed submission:
#https://atcoder.jp/contests/abc089/tasks/abc089_c
import itertools
N = int(input())
S = [input() for _ in range(N)]
M,A,R,C,H = 0,0,0,0,0
ans = 0
for s in S:
    if s[0] == "M":
        M +=1
    if s[0] == "A":
        A +=1
    if s[0] == "R":
        R +=1
    if s[0] == "C":
        C +=1
    if s[0] == "H":
        H +=1

for i,j,k in itertools.combinations([M,A,R,C,H],3):
    ans += i*j*k
print(ans)

Buggy python submission (verdict: Runtime Error):
#https://atcoder.jp/contests/abc089/tasks/abc089_c
import itertools
N = int(input())
S = [input() for _ in range(N)]
march = [0]*N
ans = 0
for s in S:
    if s[0] == "M":
        march[0] +=1
    if s[0] == "A":
        march[1] +=1
    if s[0] == "R":
        march[2] +=1
    if s[0] == "C":
        march[3] +=1
    if s[0] == "H":
        march[4] +=1

for i,j,k in itertools.combinations(march,3):
    ans += i*j*k
print(ans)

Fixed submission:
#https://atcoder.jp/contests/abc089/tasks/abc089_c
import itertools
N = int(input())
S = [input() for _ in range(N)]
M,A,R,C,H = 0,0,0,0,0
ans = 0
for s in S:
    if s[0] == "M":
        M +=1
    if s[0] == "A":
        A +=1
    if s[0] == "R":
        R +=1
    if s[0] == "C":
        C +=1
    if s[0] == "H":
        H +=1

for i,j,k in itertools.combinations([M,A,R,C,H],3):
    ans += i*j*k
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H, W, D = map(int, input().split())
mass = [0]*(H*W+1)
for y in range(1,H+1):
    for x,i in enumerate(input().split()):
        mass[int(i)]= (y,x+1)

Q = int(input())
for _ in range(Q):
    ans = 0
    L, R = map(int, input().split())
    while L < R:
        ans += abs(mass[L + D][0] - mass[L][0]) + abs(mass[L + D][1] - mass[L][1])
        L += D
    print(ans)

Fixed submission:
H, W, D = map(int, input().split())
mass = [0]*(H*W+1)
for y in range(1,H+1):
    for x,i in enumerate(input().split()):
        mass[int(i)]= (y,x+1)

Q = int(input())
dp = [H*W+2]*(H*W+1)

for i in range(1,H*W+1):
    if i > D:
        dp[i] = dp[i-D] + abs(mass[i][0] - mass[i-D][0]) + abs(mass[i][1] - mass[i-D][1])
    else:
        dp[i] = mass[i][0] + mass[i][1]

for _ in range(Q):
    L, R = map(int, input().split())
    print(dp[R] - dp[L])
Buggy python submission (verdict: Time Limit Exceeded):
#https://atcoder.jp/contests/abc084/tasks/abc084_c
N = int(input())
CSF = [list(map(int,input().split())) for _ in range(N-1)]
for i in range(1,N+1):
    if i == N:
        print(0)
        break
    time = 0
    for j in range(i,N):
        if time == 0:
            time += CSF[j-1][1]  #はじめはS[j]秒経過  
        else:
            if time < CSF[j-1][1]:
                time = CSF[j-1][1]
            lv = CSF[j-1][1]
            while time > lv:  #timeがS[j]+F[j]またはS[j]より小さいなら
                lv += CSF[j-1][2]   #F[j]経過
        time += CSF[j-1][0]  #その後C[j]秒経過
    print(time)

Fixed submission:
#https://atcoder.jp/contests/abc084/tasks/abc084_c
N = int(input())
CSF = [list(map(int,input().split())) for _ in range(N-1)]
for i in range(1,N+1):
    if i == N:
        print(0)
        break
    time = 0
    for j in range(i,N):
        if time == 0:
            time += CSF[j-1][1]  #はじめはS[j]秒経過  
        else:
            if time < CSF[j-1][1]:
                time = CSF[j-1][1]
           # lv = CSF[j-1][1]
            while time % CSF[j-1][2] != 0:  #timeがS[j]+F[j]またはS[j]より小さいなら
                time +=1   #F[j]経過
        time += CSF[j-1][0]  #その後C[j]秒経過
    print(time)
Buggy python submission (verdict: Runtime Error):
#https://atcoder.jp/contests/abc075/tasks/abc075_b?lang=ja
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
for i in range(H):
    for j in range(W):
        count = 0
        if s[i][j] == ".":
            if i > 0 and j > 0 and s[i-1][j-1] == "#": #
                count +=1
            if i > 0 and s[i-1][j]=="#": #上
                count +=1
            if i > 0 and j <W-1 and s[i-1][j+1] =="#": #
                count +=1  
            if j < W-1 and s[i][i+1] =="#": #右
                count +=1
            if i < H-1 and j<W-1 and s[i+1][j+1] =="#":
                count +=1
            if i < H-1 and s[i+1][j] =="#": #下
                count +=1
            if i<H-1 and j<0 and s[i+1][j-1] =="#":
                count +=1
            if j > 0 and s[i][j-1] == "#":   #左
                count +=1
            s[i][j] = str(count)         
        else:
            pass
for i in range(H):
    print("".join(s[i]))
    

Fixed submission:
#https://atcoder.jp/contests/abc075/tasks/abc075_b?lang=ja
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
for i in range(H):
    for j in range(W):
        count = 0
        if s[i][j] == "#":
            pass
        else:
            if i > 0 and j > 0 and s[i-1][j-1] == "#": #左上
                count +=1
            if i > 0 and s[i-1][j]=="#": #上
                count +=1
            if i > 0 and j <W-1 and s[i-1][j+1] =="#": #右上
                count +=1  
            if j < W-1 and s[i][j+1] =="#": #右
                count +=1
            if i < H-1 and j<W-1 and s[i+1][j+1] =="#": #右下
                count +=1
            if i < H-1 and s[i+1][j] =="#": #下
                count +=1
            if i<H-1 and j>0 and s[i+1][j-1] =="#":  #左下
                count +=1
            if j > 0 and s[i][j-1] == "#":   #左
                count +=1
            s[i][j] = str(count)         
for i in range(H):
    print("".join(s[i]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]
newA = list(set(A))
count = 0
for an in newA:
    if A.count(an) %2 == 1:
        count += 1

print(count)

Fixed submission:
import sys
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()
stack = A[0]
count_num = 1
ans = 0
for i in range(1,N):
        if A[i] == stack:
                count_num += 1
        else:
                if count_num % 2 == 1:
                        ans += 1
                count_num = 1
        stack = A[i]
if count_num%2 == 1:
        ans +=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]
newA = list(set(A))
count = 0
for an in newA:
    if A.count(an) %2 == 1:
        count += 1

print(count)

Fixed submission:
import sys
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()
stack = A[0]
count_num = 1
ans = 0
for i in range(1,N):
        if A[i] == stack:
                count_num += 1
        else:
                if count_num % 2 == 1:
                        ans += 1
                count_num = 1
        stack = A[i]
if count_num%2 == 1:
        ans +=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]
ans = []
for an in A:
    if an in ans:
        del ans[ans.index(an)]
    else:
        ans.append(an)
print(len(ans))

Fixed submission:
import sys
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()
stack = A[0]
count_num = 1
ans = 0
for i in range(1,N):
        if A[i] == stack:
                count_num += 1
        else:
                if count_num % 2 == 1:
                        ans += 1
                count_num = 1
        stack = A[i]
if count_num%2 == 1:
        ans +=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]
ans = []
for an in A:
    if an in ans:
        del ans[ans.index(an)]
    else:
        ans.append(an)
print(len(ans))

Fixed submission:
import sys
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()
stack = A[0]
count_num = 1
ans = 0
for i in range(1,N):
        if A[i] == stack:
                count_num += 1
        else:
                if count_num % 2 == 1:
                        ans += 1
                count_num = 1
        stack = A[i]
if count_num%2 == 1:
        ans +=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
inf = float("inf")
d = [[inf] * (N+1) for _ in range(N+1)]
ans = inf
for _ in range(M): #隣接行列
    A,B,C = map(int, input().split())
    d[A][B] = C
    d[B][A] = C

def warshall_floyd(n):
    for i in range(1,n+1): #経由する点
        for j in range(1,n+1): #始点
            for k in range(1,n+1): #終点
                d[j][k] = min(d[j][k], d[j][i] + d[i][k])

warshall_floyd(N)

for p in permutations(r): #通る町の順列生成
    tmp = 0
    for r1,r2 in zip(p,p[1:]):
        tmp += d[r1][r2]
    ans = min(ans, tmp)
print(ans)

Fixed submission:
from itertools import permutations
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
inf = float("inf")
d = [[inf] * (N+1) for _ in range(N+1)]
ans = inf
for _ in range(M): #隣接行列
    A,B,C = map(int, input().split())
    d[A][B] = C
    d[B][A] = C

def warshall_floyd(n):
    for i in range(1,n+1): #経由する点
        for j in range(1,n+1): #始点
            for k in range(1,n+1): #終点
                d[j][k] = min(d[j][k], d[j][i] + d[i][k])

warshall_floyd(N)

for p in permutations(r): #通る町の順列生成
    tmp = 0
    for r1,r2 in zip(p,p[1:]):
        tmp += d[r1][r2]
    ans = min(ans, tmp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
p = list(map(int, input().split()))
cnt = 0
i = 0
while i < N:
    if i + 1 == p[i]:
        c = 1
        for j in range(i + 1, N):
            if j+1 != p[j]:
                i = j
                break
            else:
                c += 1
        i = j
        cnt += (c+1)//2
    i += 1

print(cnt)
        

Fixed submission:
N = int(input())
p = list(map(int, input().split()))
cnt = 0
i = 0
while i < N:
    if i + 1 == p[i]:
        c = 1
        j = i+1
        while j < N:
            if j+1 != p[j]:
                i = j
                break
            else:
                c += 1
            j += 1
        else:
            i = j
        cnt += (c+1)//2
    i += 1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
#https://atcoder.jp/contests/abc071/tasks/arc081_a
N = int(input())
A = list(map(int, input().split()))
A.sort()
tmp = [0,0]
for i in range(len(A)-1):
    if A[i] == A[i+1] and not A[i] in tmp:
        tmp.append(A[i])
ans = tmp[-1]*tmp[-2]
if A.count(tmp[-1]) >=4:
        ans = tmp[-1]*tmp[-1]
print(ans)

Fixed submission:
#https://atcoder.jp/contests/abc071/tasks/arc081_a
N = int(input())
A = list(map(int, input().split()))
A.sort()
tmp = [0,0]
for i in range(len(A)-1):
    if A[i] == A[i+1] and not A[i] in tmp:
        tmp.append(A[i])
ans = tmp[-1]*tmp[-2]
if A.count(tmp[-1]) >=4:
        ans = tmp[-1]*tmp[-1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#https://atcoder.jp/contests/abc068/tasks/arc079_a
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]
flag = False
tmp = -1
for i in range(M):
    if ab[i][0] == N:
        tmp = ab[i][1]
        for j in range(M):
            if ab[j][0] == tmp and ab[j][1] == 1:
                flag = True
                break
            if ab[j][1] == tmp and ab[j][0] == 1:
                flag = True
                break


    if ab[i][1] == N:
        tmp = ab[i][0]
        for j in range(M):
            if ab[j][0] == tmp and ab[j][1] == 1:
                flag = True
                break
            if ab[j][1] == tmp and ab[j][0] == 1:
                flag = True
                break


if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Fixed submission:
from collections import deque
N, M = map(int, input().split())
lst = [[] for _ in range(N + 1)]
dist = [float("inf")]*(N+1)
for _ in range(M):
    a, b = map(int, input().split())
    lst[a].append(b)
    lst[b].append(a)

q = deque()
d = 0
q.append([1,d])

while q:
    now, d = q.popleft()
    dist[now] = d
    if now == N:
        if d <= 2:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")
        exit()
    
    for itm in lst[now]:
        if dist[itm] > d+1:
            q.append([itm,d+1])
            
print("IMPOSSIBLE")