Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue
N, Q = map(int, input().split())
E = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)
d = [0]*N
ok = [True]*N
cnt = [0]*N
for i in range(Q):
    p, x = map(int, input().split())
    cnt[p-1] += x
q = Queue()
q.put(0)
while not q.empty():
    p = q.get()
    d[p] += cnt[p]
    ok[p] = False
    for np in E[p]:
        if ok[np]:
            cnt[np] += cnt[p]
            q.put(np)

print(*d)

Fixed submission:
from collections import defaultdict
N, Q = map(int, input().split())
E = defaultdict(list)
for i in range(N-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)
d = [0]*N
ok = [True]*N
cnt = [0]*N
for i in range(Q):
    p, x = map(int, input().split())
    cnt[p-1] += x
stack = [0]
while stack:
    p = stack.pop()
    d[p] += cnt[p]
    ok[p] = False
    for np in E[p]:
        if ok[np]:
            cnt[np] += cnt[p]
            stack.append(np)

print(*d)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from collections import defaultdict
N, M = map(int, input().split())
d = [0]*N
G = defaultdict(list)
for i in range(N-1+M):
    s, t = map(int, input().split())
    d[t-1] += 1
    G[s-1].append(t-1)
q = deque([])
for i in range(N):
    if d[i] == 0:
        q.append(i)
ans = [0]*N
cnt = []
while q:
    for i in range(len(q)):
        s = q.popleft()
        for x in cnt:
            if s in G[x]:
                ans[s] = x+1
        cnt.append(s)
        for t in G[s]:
            d[t] -= 1
            if d[t] == 0:
                q.append(t)
for x in ans:
    print(x)

Fixed submission:
from collections import deque
from collections import defaultdict
N, M = map(int, input().split())
d = [0]*N
G = defaultdict(list)
for i in range(N-1+M):
    s, t = map(int, input().split())
    d[t-1] += 1
    G[s-1].append(t-1)
q = deque([])
for i in range(N):
    if d[i] == 0:
        q.append(i)
rank = [0]*N
ans = [0]*N
while q:
    s = q.popleft()
    for t in G[s]:
        d[t] -= 1
        if d[t] == 0:
            rank[t] = rank[s]+1
            q.append(t)
for i in range(N):
    for x in G[i]:
        if rank[x] - rank[i] == 1:
            ans[x] = i+1
for x in ans:
    print(x)
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i], v[i] = map(int, input().split())
vmax = max(v)
dp = [[0]*(N * vmax + 1) for i in range(N + 1)]
dp[0][0] = 0
for j in range(N * vmax):
    dp[0][j + 1] = float("inf")

for i in range(N):
    for j in range(N * vmax + 1):
        if j < v[i]:
            dp[i + 1][j] = dp[i][j]
        else: 
            dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i])

ans = 0
for j in range(N * vmax + 1):
    if dp[N][j] <= W:
        ans = j
print(ans)

Fixed submission:
N, W = map(int, input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i], v[i] = map(int, input().split())
vmax = max(v)
dp = [[0]*(N * vmax + 1) for i in range(N + 1)]
dp[0][0] = 0
for j in range(N * vmax):
    dp[0][j + 1] = float("inf")

for i in range(N):
    for j in range(N * vmax + 1):
        if j < v[i]:
            dp[i + 1][j] = dp[i][j]
        else: 
            dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i])

ans = 0
for j in range(N * vmax + 1):
    if dp[N][j] <= W:
        ans = j
print(ans)

Buggy python submission (verdict: Runtime Error):
N, W = map(int, input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i], v[i] = map(int, input().split())
vmax = max(v)
dp = [[0]*(N * vmax + 1) for i in range(N + 1)]
dp[0][0] = 0
for j in range(N * vmax):
    dp[0][j + 1] = float("inf")

for i in range(N):
    for j in range(N * vmax + 1):
        if j < v[i]:
            dp[i + 1][j] = dp[i][j]
        else: 
            dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i])

ans = 0
for j in range(N*vmax):
    if dp[N][j] <= W:
        ans = j
print(ans

Fixed submission:
N, W = map(int, input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i], v[i] = map(int, input().split())
vmax = max(v)
dp = [[0]*(N * vmax + 1) for i in range(N + 1)]
dp[0][0] = 0
for j in range(N * vmax):
    dp[0][j + 1] = float("inf")

for i in range(N):
    for j in range(N * vmax + 1):
        if j < v[i]:
            dp[i + 1][j] = dp[i][j]
        else: 
            dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i])

ans = 0
for j in range(N * vmax + 1):
    if dp[N][j] <= W:
        ans = j
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
t = list(input())
ls = len(s)
lt = len(t)
dp = [[[] for i in range(lt+1)] for i in range(ls+1)]
for i in range(ls):
    flag = True
    for j in range(lt):
        if flag and s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i][j+1]+[s[i]],dp[i+1][j]+[s[i]],key=lambda x: len(x))
            flag= False
        elif s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i][j+1]+[s[i]],dp[i+1][j],key=lambda x: len(x))
        else:
            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j],key=lambda x: len(x))
print(''.join(dp[ls][lt]))

Fixed submission:
s = list(input())
t = list(input())
ls = len(s)
lt = len(t)
ans = []
dp = [[0] * (lt+1) for i in range(ls+1)]
for i in range(ls):
    flag = True
    for j in range(lt):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])
i = ls
j = lt
while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        i -= 1
        j -= 1
        ans.append(s[i])
print(''.join(reversed(ans)))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
t = list(input())
ls = len(s)
lt = len(t)
dp = [[[] for i in range(lt+1)] for i in range(ls+1)]
for i in range(ls):
    flag = True
    for j in range(lt):
        if flag and s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i][j+1]+[s[i]],dp[i+1][j]+[s[i]],key=lambda x: len(x))
            flag= False
        elif s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i][j+1]+[s[i]],dp[i+1][j],key=lambda x: len(x))
        else:
            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j],key=lambda x: len(x))
print(''.join(dp[ls][lt]))

Fixed submission:
s = list(input())
t = list(input())
ls = len(s)
lt = len(t)
ans = []
dp = [[0] * (lt+1) for i in range(ls+1)]
for i in range(ls):
    flag = True
    for j in range(lt):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])
i = ls
j = lt
while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        i -= 1
        j -= 1
        ans.append(s[i])
print(''.join(reversed(ans)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
c1 = 0
c2 = 0 
c3 = 0
for i in range(N):
    if a[i] == 1:
        c1 += 1
    if a[i] == 2:
        c2 += 1
    if a[i] == 3:
        c3 += 1
dp= [[[-1] * (N+1) for i in range(N+1)] for j in range(N+1)]
dp[c1][c2][c3] = 0
def solve(c1, c2, c3):
    if dp[c1][c2][c3] > 0:
        return dp[c1][c2][c3]
    if c1 == c2 == c3 == 0:
        return 0
    res = 1/(1-(N-c1-c2-c3)/N)
    if c1 > 0:
        res += solve(c1-1,c2,c3)*(c1/N)/(1-(N-c1-c2-c3)/N)
    if c2 > 0:
        res += solve(c1+1,c2-1,c3)*(c2/N)/(1-(N-c1-c2-c3)/N)
    if c3 > 0:
        res += solve(c1,c2+1,c3-1)*(c3/N)/(1-(N-c1-c2-c3)/N)
    dp[c1][c2][c3] = res
    return dp[c1][c2][c3]
print(solve(c1, c2, c3))

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
c1 = 0
c2 = 0 
c3 = 0
for i in range(N):
    if a[i] == 1:
        c1 += 1
    if a[i] == 2:
        c2 += 1
    if a[i] == 3:
        c3 += 1
dp= [[[0] * (N+1) for i in range(N+1)] for j in range(N+1)]
for k in range(c3+1):
    for j in range(c3+c2-k+1):
        for i in range(N-j-k+1):
            if i == j == k == 0:
                continue
            else:
                res = N
                if i > 0:
                    res += dp[k][j][i-1]*i
                if j > 0:
                    res += dp[k][j-1][i+1]*j
                if k > 0:
                    res += dp[k-1][j+1][i]*k
                dp[k][j][i] = res/(i+j+k)
print(dp[c3][c2][c1])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
c1 = 0
c2 = 0 
c3 = 0
for i in range(N):
    if a[i] == 1:
        c1 += 1
    if a[i] == 2:
        c2 += 1
    if a[i] == 3:
        c3 += 1
dp= [[[-1] * (N+1) for i in range(N+1)] for j in range(N+1)]
dp[c1][c2][c3] = 0
def solve(c1, c2, c3):
    if dp[c1][c2][c3] > 0:
        return dp[c1][c2][c3]
    if c1 == c2 == c3 == 0:
        return 0
    res = 1/(1-(N-c1-c2-c3)/N)
    if c1 > 0:
        res += solve(c1-1,c2,c3)*(c1/N)/(1-(N-c1-c2-c3)/N)
    if c2 > 0:
        res += solve(c1+1,c2-1,c3)*(c2/N)/(1-(N-c1-c2-c3)/N)
    if c3 > 0:
        res += solve(c1,c2+1,c3-1)*(c3/N)/(1-(N-c1-c2-c3)/N)
    dp[c1][c2][c3] = res
    return dp[c1][c2][c3]
print(solve(c1, c2, c3))

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
c1 = 0
c2 = 0 
c3 = 0
for i in range(N):
    if a[i] == 1:
        c1 += 1
    if a[i] == 2:
        c2 += 1
    if a[i] == 3:
        c3 += 1
dp= [[[0] * (N+1) for i in range(N+1)] for j in range(N+1)]
for k in range(c3+1):
    for j in range(c3+c2-k+1):
        for i in range(N-j-k+1):
            if i == j == k == 0:
                continue
            else:
                res = N
                if i > 0:
                    res += dp[k][j][i-1]*i
                if j > 0:
                    res += dp[k][j-1][i+1]*j
                if k > 0:
                    res += dp[k-1][j+1][i]*k
                dp[k][j][i] = res/(i+j+k)
print(dp[c3][c2][c1])
Buggy python submission (verdict: Runtime Error):
lc = [0] * (1<<N)
mod = 10**9+7
N = int(input())
li = [list(map(int, input().split())) for i in range(N)]
dp = [0]*(1<<N)
dp[0] = 1
for S in range(1, 1<<N):
    lc[S] = lc[S>>1]+S%2
    for i in range(N):
        if S>>i&li[lc[S]-1][i] == 1:
            dp[S] = (dp[S]+dp[S-(1<<i)]) %mod
print(dp[(1<<N)-1])

Fixed submission:
mod = 10**9+7
N = int(input())
li = [list(map(int, input().split())) for i in range(N)]
lc = [0] * (1<<N)
dp = [0]*(1<<N)
dp[0] = 1
for S in range(1, 1<<N):
    lc[S] = lc[S>>1]+S%2
    for i in range(N):
        if S>>i&li[lc[S]-1][i] == 1:
            dp[S] = (dp[S]+dp[S-(1<<i)]) %mod
print(dp[(1<<N)-1])

Buggy python submission (verdict: Time Limit Exceeded):
def c(S):
    cnt = 0
    for i in range(len(bin(S))-2):
        cnt += S>>i&1
    return cnt
mod = 10**9+7
N = int(input())
li = [list(map(int, input().split())) for i in range(N)]
dp = [0]*(1<<N)
dp[0] = 1
for S in range(1, 1<<N):
    num = c(S)
    for i in range(N):
        if S>>i&li[num-1][i] == 1:
            dp[S] = (dp[S]+dp[S-(1<<i)]) %mod
print(dp[(1<<N)-1])

Fixed submission:
mod = 10**9+7
N = int(input())
li = [list(map(int, input().split())) for i in range(N)]
lc = [0] * (1<<N)
dp = [0]*(1<<N)
dp[0] = 1
for S in range(1, 1<<N):
    lc[S] = lc[S>>1]+S%2
    for i in range(N):
        if S>>i&li[lc[S]-1][i] == 1:
            dp[S] = (dp[S]+dp[S-(1<<i)]) %mod
print(dp[(1<<N)-1])
Buggy python submission (verdict: Time Limit Exceeded):
class SegmentTree():
    def segfunc(self, x, y):
        return max(x, y)
    
    def __init__(self, a): #a:リスト
        n = len(a)
        self.ide_ele = 0 #単位元
        self.num = 2**((n-1).bit_length()) #num:n以上の最小の2のべき乗
        self.seg = [self.ide_ele]*2*self.num
        
        #set_val
        for i in range(n):
            self.seg[i+self.num-1] = a[i]
        #built
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segfunc(self.seg[2*i+1], self.seg[2*i+2])
        
        
    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1], self.seg[k*2+2])
            
    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res = self.ide_ele
        while q - p > 1:
            if p&1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

N = int(input())
h = list(map(int, input().split()))
a = list(map(int, input().split()))
dp = [0] * N
S = SegmentTree(dp)
for i in range(N):
    tmp = S.query(0,h[i]-1)
    S.update(h[i]-1, tmp+a[i])
print(S.query(0,N))

Fixed submission:
class SegmentTree():
    def segfunc(self, x, y):
        return max(x, y)
    
    def __init__(self, a): #a:リスト
        n = len(a)
        self.ide_ele = 0 #単位元
        self.num = 2**((n-1).bit_length()) #num:n以上の最小の2のべき乗
        self.seg = [self.ide_ele]*2*self.num
        
        #set_val
        for i in range(n):
            self.seg[i+self.num-1] = a[i]
        #built
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segfunc(self.seg[2*i+1], self.seg[2*i+2])
        
        
    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1], self.seg[k*2+2])
            
    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res = self.ide_ele
        while q - p > 1:
            if p&1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

N = int(input())
h = list(map(int, input().split()))
a = list(map(int, input().split()))
dp = [0] * N
S = SegmentTree(dp)
for i in range(N):
    tmp = S.query(0,h[i]-1)
    S.update(h[i]-1, tmp+a[i])
print(S.query(0,N))
Buggy python submission (verdict: Runtime Error):
N = int(input())
ball = list(map(int, input().split()))
ball.sort(reverse = True)
ok = {}
for x in ball:
    if x in ok:
        dic[x] += 1
    else:
        dic[x] = 1
ans = 0
for x in ball:
    if ok[x] != 0:
        y = 2**(x.bit_length()) - x
        if ok[y] != 0:
            if y == x and ok[y] == 1: 
                continue
            ans += 1
            dic[x] -= 1
            dic[y] -= 1
print(ans)

Fixed submission:
N = int(input())
ball = list(map(int, input().split()))
ball.sort(reverse = True)
ok = {}
for x in ball:
    if x in ok:
        ok[x] += 1
    else:
        ok[x] = 1
ans = 0
for x in ball:
    if ok[x] != 0:
        y = 2**(x.bit_length()) - x
        if y in ok:
            if ok[y] != 0:
                if y == x and ok[y] == 1: 
                    continue
                ans += 1
                ok[x] -= 1
                ok[y] -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ball = list(map(int, input().split()))
ball.sort(reverse = True)
dic = {}
for i in range(ball[0] + 1):
    dic[i] = 0
for x in ball:
    dic[x] += 1

ans = 0
for x in ball:
    if dic[x] != 0:
        y = 2**(x.bit_length()) - x
        if dic[y] != 0:
            if y == x and dic[y] == 1: 
                continue
            ans += 1
            dic[x] -= 1
            dic[y] -= 1
print(ans)

Fixed submission:
N = int(input())
ball = list(map(int, input().split()))
ball.sort(reverse = True)
ok = {}
for x in ball:
    if x in ok:
        ok[x] += 1
    else:
        ok[x] = 1
ans = 0
for x in ball:
    if ok[x] != 0:
        y = 2**(x.bit_length()) - x
        if y in ok:
            if ok[y] != 0:
                if y == x and ok[y] == 1: 
                    continue
                ans += 1
                ok[x] -= 1
                ok[y] -= 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
ball = list(map(int, input().split()))
ball.sort(reverse = True)
dic = {}
for x in ball:
    dic[x] = 1

ans = 0
for x in ball:
    dic[x] = 0
    y = 2**(x.bit_length()) - x
    if dic[y] == 1:
        ans += 1
        dic[y] = 0
print(ans)

Fixed submission:
N = int(input())
ball = list(map(int, input().split()))
ball.sort(reverse = True)
ok = {}
for x in ball:
    if x in ok:
        ok[x] += 1
    else:
        ok[x] = 1
ans = 0
for x in ball:
    if ok[x] != 0:
        y = 2**(x.bit_length()) - x
        if y in ok:
            if ok[y] != 0:
                if y == x and ok[y] == 1: 
                    continue
                ans += 1
                ok[x] -= 1
                ok[y] -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = input()
T = input()
f = fractions.gcd(N, M)
flag = True
for i in range(f):
    if S[i*N//f] != T[i*M//f]:
        flag = False
        break
print([-1,N*M//f][flag])

Fixed submission:
import fractions
N, M = map(int, input().split())
S = input()
T = input()
f = fractions.gcd(N, M)
flag = True
for i in range(f):
    if S[i*N//f] != T[i*M//f]:
        flag = False
        break
print([-1,N*M//f][flag])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
a = M//N
ans = 0
for i in range(1, a+1):
    if M%i == 0:
        ans = i
print(ans)

Fixed submission:
N, M = map(int, input().split())
a = M//N
ans = 0
ok = True
for i in range(1, a+1):
    if M%i == 0:
        ans = i
        if M//i <= a:
            print(M//i)
            ok = False
            break
if ok:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
a = M//N
ans = 0
for i in range(1, a+1):
    if M%i == 0:
        ans = i
print(ans)

Fixed submission:
N, M = map(int, input().split())
a = M//N
ans = 0
ok = True
for i in range(1, a+1):
    if M%i == 0:
        ans = i
        if M//i <= a:
            print(M//i)
            ok = False
            break
if ok:
    print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ad = defaultdict(lambda: -1)
i, j = 0, 0
while i < N and j < N:
    if A[i] < B[j]:
        ad[i] = j
        i += 1
    else:
        j += 1
bd = defaultdict(lambda: -1)
i, j = 0, 0
while i < N and j < N:
    if B[i] < C[j]:
        bd[i] = j
        i += 1
    else:
        j += 1
csum = [0] * N
for i in range(N):
    if bd[i] >= 0:
        csum[i] = N-bd[i]
bsum = [0]* N
cnt = 0
for i in range(N):
    cnt += csum[N-1-i]
    bsum[N-1-i] = cnt
ans = 0
for i in range(N):
    if ad[i] >= 0:
        ans += bsum[ad[i]]
print(ans)

Fixed submission:
from collections import defaultdict
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ad = defaultdict(lambda: -1)
i, j = 0, 0
while i < N and j < N:
    if A[i] < B[j]:
        ad[i] = j
        i += 1
    else:
        j += 1
bd = defaultdict(lambda: -1)
i, j = 0, 0
while i < N and j < N:
    if B[i] < C[j]:
        bd[i] = j
        i += 1
    else:
        j += 1
csum = [0] * N
for i in range(N):
    if bd[i] >= 0:
        csum[i] = N-bd[i]
bsum = [0]* N
cnt = 0
for i in range(N):
    cnt += csum[N-1-i]
    bsum[N-1-i] = cnt
ans = 0
for i in range(N):
    if ad[i] >= 0:
        ans += bsum[ad[i]]
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        ans += 1
if p[n-1] = n:
    p[n-1], p[n-2] = p[n-2], p[n-1]
    ans += 1
print(ans)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        ans += 1
if p[n-1] == n:
    p[n-1], p[n-2] = p[n-2], p[n-1]
    ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        ans += 1
print(ans)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        ans += 1
if p[n-1] == n:
    p[n-1], p[n-2] = p[n-2], p[n-1]
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
def lcm(list):
    if len(list) == 2:
        [a, b] = list
        return a*b//gcd(a,b)
    x = list.pop()
    y = lcm(list)
    return x*y//gcd(x,y)

N = int(input())
li = []
for i in range(N):
    li.append(int(input()))
print(lcm(li))

Fixed submission:
from fractions import gcd
def lcm(list):
    if len(list) == 1:
        return list[0]
    if len(list) == 2:
        [a, b] = list
        return a*b//gcd(a,b)
    x = list.pop()
    y = lcm(list)
    return x*y//gcd(x,y)

N = int(input())
li = []
for i in range(N):
    li.append(int(input()))
print(lcm(li))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = []
for x in a:
    b.append(x)
    b.reverse()
print(*b)

Fixed submission:
l1 = []
l2 = []
n = int(input())
a = list(map(int, input().split()))
flag = -1
for i in range(n):
    if flag < 0:
        l1.append(a[i])
    else:
        l2.append(a[i])
    flag *= -1
if n%2 == 0:
    print(*(list(reversed(l2))+l1))
else:
    print(*(list(reversed(l1))+l2))
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N == 1 or N == 2:
    print(N)
else:
    for i in range(N):
        if i*(i+1)//2 > N:
            num = i-1
            break
    ans = []
    for i in range(num):
        ans.append(i+1)
    if num*(num+1)//2 != N:
        cnt = N-num*(num+1)//2
        ans.pop(num-cnt)
        ans.append(num+1)
    for x in ans:
        print(x)

Fixed submission:
N = int(input())
if N == 1 or N == 2:
    print(N)
else:
    for i in range(N+1):
        if i*(i+1)//2 > N:
            num = i-1
            break
    ans = []
    for i in range(num):
        ans.append(i+1)
    if num*(num+1)//2 != N:
        cnt = N-num*(num+1)//2
        ans.remove(num+1-cnt)
        ans.append(num+1)
    for x in ans:
        print(x)

Buggy python submission (verdict: Runtime Error):
N = int(input())
if N == 1 or N == 2:
    print(N)
else:
    for i in range(N):
        if i*(i+1)//2 > N:
            num = i-1
            break
    ans = []
    for i in range(num):
        ans.append(i+1)
    if num*(num+1)//2 != N:
        cnt = N-num*(num+1)//2
        ans.remove(num+1-cnt)
        ans.append(num+1)
    for x in ans:
        print(x)

Fixed submission:
N = int(input())
if N == 1 or N == 2:
    print(N)
else:
    for i in range(N+1):
        if i*(i+1)//2 > N:
            num = i-1
            break
    ans = []
    for i in range(num):
        ans.append(i+1)
    if num*(num+1)//2 != N:
        cnt = N-num*(num+1)//2
        ans.remove(num+1-cnt)
        ans.append(num+1)
    for x in ans:
        print(x)