Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
*A, = map(int,input().split())

if N%2==0:
    1/0
    ans = max(sum(A[::2]),sum(A[1::2]))
    print(ans)
else:
    INF = 2* 10**9
    dp = [[-INF]*N for _ in [0]*3]
    dp[0][0] = A[0]
    dp[1][1] = A[1]
    dp[2][2] = A[2]
    for i in range(2,N,2):
        a = A[i]
        dp[0][i] = dp[0][i-2] + a
    for i in range(3,N):
        a = A[i]
        dp[1][i] = max(dp[1][i-2],dp[0][i-3]) + a
    for i in range(4,N,2):
        a = A[i]
        dp[2][i] = max(dp[2][i-2],dp[1][i-3],dp[0][i-4]) + a
    print(dp[2][-1])

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

if N%2==0:
    INF = 2* 10**9
    dp = [[-INF]*N for _ in [0]*2]
    dp[0][0] = A[0]
    dp[1][1] = A[1]
    for i in range(2,N,2):
        a = A[i]
        dp[0][i] = dp[0][i-2] + a
    for i in range(3,N):
        a = A[i]
        dp[1][i] = max(dp[1][i-2],dp[0][i-3]) + a
    print(max(dp[1][-1],dp[0][-2]))
else:
    INF = 2* 10**9
    dp = [[-INF]*N for _ in [0]*3]
    dp[0][0] = A[0]
    dp[1][1] = A[1]
    dp[2][2] = A[2]
    for i in range(2,N,2):
        a = A[i]
        dp[0][i] = dp[0][i-2] + a
    for i in range(3,N):
        a = A[i]
        dp[1][i] = max(dp[1][i-2],dp[0][i-3]) + a
    for i in range(4,N,2):
        a = A[i]
        dp[2][i] = max(dp[2][i-2],dp[1][i-3],dp[0][i-4]) + a
    print(max(dp[2][-1],dp[1][-2],dp[0][-3]))
Buggy python submission (verdict: Time Limit Exceeded):
H,W,K = map(int,input().split())
S = [list(map(int,input())) for _ in [0]*H]

ans = H*W
S2 = [[0]*(W+1) for _ in [0]*(H+1)]
for i in range(H):
    for j in range(W):
        S2[i+1][j+1] = S2[i][j+1] + S[i][j]
for i in range(1,H+1):
    for j in range(W):
        S2[i][j+1] += S2[i][j]

for i in range(1<<(H-1)):
    check = [0]+[j+1 for j in range(H-1) if i>>j&1]+[H]
    cnt = len(check)-2
    l = 0
    r = 1
    while r<=W:
        for j,k in zip(check[:-1],check[1:]):
            if S2[j][l] + S2[k][r] - S2[j][r] - S2[k][l] > K:
                cnt += 1
                l = r-1
                r = r
                break
        else:
            r += 1
    ans = min(ans,cnt)
print(ans)

Fixed submission:
H,W,K = map(int,input().split())
S = [list(map(int,input())) for _ in [0]*H]

ans = H*W
S2 = [[0]*(W+1) for _ in [0]*(H+1)]
for i in range(H):
    for j in range(W):
        S2[i+1][j+1] = S2[i][j+1] + S[i][j]
for i in range(1,H+1):
    for j in range(W):
        S2[i][j+1] += S2[i][j]

for i in range(1<<(H-1)):
    check = [0]+[j+1 for j in range(H-1) if i>>j&1]+[H]
    cnt = len(check)-2
    l = 0
    r = 1
    while r<=W:
        for j,k in zip(check[:-1],check[1:]):
            if S2[j][l] + S2[k][r] - S2[j][r] - S2[k][l] > K:
                if r==l+1:
                    cnt += H*W
                    r = W+1
                    break
                cnt += 1
                l = r-1
                r = r
                break
        else:
            r += 1
    ans = min(ans,cnt)
print(ans)
Buggy python submission (verdict: Runtime Error):
from sympy import *
a,b,c = map(int,input().split())
print("Yes" if sqrt(a)+sqrt(b)<sqrt(c) else "No")

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

if a+b<c and 4*a*b<(c-(a+b))**2:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())

mod = 10**9+7

m = 10**5 * 4 +10 
fac = [1]*m
ninv = [1]*m
finv = [1]*m
for i in range(2,m):
    fac[i] = fac[i-1]*i%mod
    ninv[i] = (-(mod//i)*ninv[mod%i])%mod
    finv[i] = finv[i-1]*ninv[i]%mod

def comb(n,k):
    return (fac[n]*finv[k]%mod)*finv[n-k]%mod

if k*2 >= n:
    print(comb(2*n-1,n))
    1/0
else:
    ans = 0
    for i in range(k+1):
        ans += comb(n,i)*comb(n-1,i)
        ans %= mod
    print(ans)

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

mod = 10**9+7

m = 10**5 * 4 +10 
fac = [1]*m
ninv = [1]*m
finv = [1]*m
for i in range(2,m):
    fac[i] = fac[i-1]*i%mod
    ninv[i] = (-(mod//i)*ninv[mod%i])%mod
    finv[i] = finv[i-1]*ninv[i]%mod

def comb(n,k):
    return (fac[n]*finv[k]%mod)*finv[n-k]%mod

ans = 0
for i in range(min(n,k+1)):
    ans += comb(n,i)*comb(n-1,i)
    ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
AB = [list(map(int,input().split())) for _ in [0]*(N-1)]
M = int(input())
UV = [list(map(int,input().split())) for _ in [0]*M]

E = [[] for _ in [0]*N]
for a,b in AB:
    a-=1
    b-=1
    E[a].append(b)
    E[b].append(a)

P = [-1]*N
P[0] = 0
q = [0]
while q:
    i = q.pop()
    for j in E[i]:
        if P[j]!=-1: continue
        P[j] = i
        q.append(j)
P[0] = -1

def dist_bfs(N,E,start):
    d = [-1]*N
    d[start] = 0
    q = [start]
    while q:
        qq = []
        for i in q:
            di = d[i]
            for j in E[i]:
                if d[j]!=-1:continue
                d[j] = di+1
                q.append(j)
        q = qq
    return d

path = []
for u,v in UV:
    u -= 1
    v -= 1
    tmp = []
    d = dist_bfs(N,E,u)
    q = [v]
    while q:
        i = q.pop()
        di = d[i]
        for j in E[i]:
            if d[j] == di-1:
                q.append(j)
                if P[i]==j:
                    tmp.append(i)
                else:
                    tmp.append(j)
    path.append(set(tmp))

ans = 2**(N-1)
for i in range(1,2**M):
    tmp = set()
    cnt = 0
    for j in range(M):
        if (i>>j)&1==0:continue
        cnt += 1
        tmp = tmp | path[j]
    ans += ((-1)**cnt) * (2**(N-1-len(tmp)))
print(ans)

Fixed submission:
N = int(input())
AB = [list(map(int,input().split())) for _ in [0]*(N-1)]
M = int(input())
UV = [list(map(int,input().split())) for _ in [0]*M]

E = [[] for _ in [0]*N]
for a,b in AB:
    a-=1
    b-=1
    E[a].append(b)
    E[b].append(a)

P = [-1]*N
P[0] = 0
q = [0]
while q:
    i = q.pop()
    for j in E[i]:
        if P[j]!=-1: continue
        P[j] = i
        q.append(j)
P[0] = -1

def dist_bfs(N,E,start):
    d = [-1]*N
    d[start] = 0
    q = [start]
    while q:
        qq = []
        for i in q:
            di = d[i]
            for j in E[i]:
                if d[j]!=-1:continue
                d[j] = di+1
                q.append(j)
        q = qq
    return d

path = []
for u,v in UV:
    u -= 1
    v -= 1
    tmp = []
    d = dist_bfs(N,E,u)
    q = [v]
    while q:
        i = q.pop()
        di = d[i]
        for j in E[i]:
            if d[j] == di-1:
                q.append(j)
                if P[i]==j:
                    tmp.append(i)
                else:
                    tmp.append(j)
    path.append(set(tmp))

ans = 2**(N-1)
for i in range(1,2**M):
    tmp = set(range(1,N))
    cnt = 0
    for j in range(M):
        if (i>>j)&1==0:continue
        cnt += 1
        tmp -= path[j]
    ans += ((-1)**cnt) * (2**(len(tmp)))
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
*A, = map(int,input().split())

mod = 10**9+7

ans = 3
dp = [1,0,0]
for a in A[1:]:
    ans *= dp.count(a)
    dp[dp.index(a)] += 1
    ans %= mod
print(ans)

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

mod = 10**9+7

ans = 3
if A[0]!=0: ans = 0
dp = [1,0,0]
for a in A[1:]:
    ans *= dp.count(a)
    ans %= mod
    if ans == 0: break
    dp[dp.index(a)] += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
M = int(input())
DC = [list(map(int,input().split())) for _ in [0]*M]

ans = 0
res = []
for d,c in DC:
    while c>0:
        if c%2==1:
            res.append(d)
            c -=1
        d *= 2
        if d>=10:
            d = d//10 + d%10
            ans += c
            c//=2
        else:
            ans += c//2
            c//=2

tmp = 0
for r in res:
    ans += 1
    tmp += r
    if tmp >= 10:
        tmp -=9
        ans += 1
ans -=1
print(ans)

Fixed submission:
M = int(input())
DC = [list(map(int,input().split())) for _ in [0]*M]

ans = 0
res = []
for d,c in DC:
    while c>0:
        if c%2==1:
            res.append(d)
            c -=1
        d *= 2
        if d>=10:
            d = d//10 + d%10
            ans += c
            c//=2
        else:
            ans += c//2
            c//=2

tmp = 0
for r in res:
    ans += 1
    tmp += r
    if tmp >= 10:
        tmp -=9
        ans += 1
ans -=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#"""
import sys
input = sys.stdin.readline
#"""

N,T = map(int,input().split())
AB = [list(map(int,input().split())) for _ in [0]*N]

dp = [[[0,[]] for _ in [0]*T] for _ in [0]*(N+1)]

for i in range(N):
    a,b = AB[i]
    for t in range(T):
        dp[i+1][t][0] = dp[i][t][0]
        dp[i+1][t][1] = dp[i][t][1][:]
        if t-a>=0:
            if dp[i+1][t][0] < dp[i][t-a][0] + b:
                dp[i+1][t][0] = dp[i][t-a][0]+b
                dp[i+1][t][1] = dp[i][t-a][1][:]
                dp[i+1][t][1].append(i)

ans0 = dp[N][-1][0]
ans = ans0
s = set(dp[N][-1][1])
for i in range(N):
    if i in s:continue
    ans = max(ans,ans0+AB[i][1])
print(ans)

Fixed submission:
#"""
import sys
input = sys.stdin.readline
#"""

N,T = map(int,input().split())
AB = [list(map(int,input().split())) for _ in [0]*N]

dp = [[0 for _ in [0]*T] for _ in [0]*(N+1)]

for i in range(N):
    a,b = AB[i]
    for t in range(T):
        dp[i+1][t] = dp[i][t]
        if t-a>=0:
            dp[i+1][t] = max(dp[i+1][t],dp[i][t-a]+b)

s = []
t = T-1
for j in range(N-1,-1,-1):
    a,b = AB[j]
    while (dp[j+1][t] == dp[j+1][t-1]) and t>0:
        t -= 1
    if dp[j+1][t] == dp[j][t]:
        pass
    else:
        t -= a
        s.append(j)

ans0 = dp[N][-1]
ans = ans0
for i in range(N):
    if s and i==s[-1] :
        s.pop()
        continue
    ans = max(ans,ans0+AB[i][1])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#"""
import sys
input = sys.stdin.readline
#"""

N,T = map(int,input().split())
AB = [list(map(int,input().split())) for _ in [0]*N]

dp = [[(0,[])]*T for _ in [0]*(N+1)]

for i in range(N):
    a,b = AB[i]
    for t in range(T):
        dp[i+1][t] = dp[i][t]
        if t-a>=0:
            if dp[i+1][t][0] < dp[i][t-a][0] + b:
                dp[i+1][t] = (dp[i][t-a][0]+b,dp[i][t-a][1]+[i])

ans0 = dp[N][-1][0]
ans = ans0
s = set(dp[N][-1][1])
for i in range(N):
    if i in s:continue
    ans = max(ans,ans0+AB[i][1])
print(ans)

Fixed submission:
#"""
import sys
input = sys.stdin.readline
#"""

N,T = map(int,input().split())
AB = [list(map(int,input().split())) for _ in [0]*N]

dp = [[0 for _ in [0]*T] for _ in [0]*(N+1)]

for i in range(N):
    a,b = AB[i]
    for t in range(T):
        dp[i+1][t] = dp[i][t]
        if t-a>=0:
            dp[i+1][t] = max(dp[i+1][t],dp[i][t-a]+b)

s = []
t = T-1
for j in range(N-1,-1,-1):
    a,b = AB[j]
    while (dp[j+1][t] == dp[j+1][t-1]) and t>0:
        t -= 1
    if dp[j+1][t] == dp[j][t]:
        pass
    else:
        t -= a
        s.append(j)

ans0 = dp[N][-1]
ans = ans0
for i in range(N):
    if s and i==s[-1] :
        s.pop()
        continue
    ans = max(ans,ans0+AB[i][1])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))

L=sorted(L)
counter=0

for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[i]+L[j]>L[k]:counter+=1
print(counter)



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

import bisect
L.sort()
ans = 0
bl = bisect.bisect_left
br = bisect.bisect_right
for i,a in enumerate(L):
    for j,b in enumerate(L[i+1:],i+1):
        m = b-a+1
        M = b+a-1
        ans += br(L,M,j+1) - bl(L,m,j+1)
print(ans)
Buggy python submission (verdict: Runtime Error):
import bisect
s = input()
t = input()
N = len(s)

next_map = sorted(zip(s*2,range(N*2)))
br = bisect.bisect_right
ans = 0
i = 0
for c in t:
    map_idx = br(next_map,(c,i))
    if map_idx == N*2:
        ans = -2/0
        break
    a,j = next_map[map_idx]
    if a != c :
        ans = -2
        break
    ans += j - i
    i = j%N
ans += 1
print(ans)

Fixed submission:
import bisect
s = input()
t = input()
N = len(s)

next_map = sorted(zip(s*2,range(N*2)))
br = bisect.bisect_right
ans = 0
i = -1
for c in t:
    map_idx = br(next_map,(c,i))
    if map_idx == N*2:
        ans = -1
        break
    a,j = next_map[map_idx]
    if a != c :
        ans = -1
        break
    ans += j - i
    i = j%N
print(ans)

Buggy python submission (verdict: Runtime Error):
import bisect
s = input()
t = input()
N = len(s)

next_map = sorted(zip(s*2,range(N*2)))
br = bisect.bisect_right
ans = 0
i = 0
for c in t:
    map_idx = br(next_map,(c,i))
    if map_idx == N*2:
        ans = -2
        break
    a,j = next_map[map_idx]
    if a != c :
        ans = -2/0
        break
    ans += j - i
    i = j%N
ans += 1
print(ans)

Fixed submission:
import bisect
s = input()
t = input()
N = len(s)

next_map = sorted(zip(s*2,range(N*2)))
br = bisect.bisect_right
ans = 0
i = -1
for c in t:
    map_idx = br(next_map,(c,i))
    if map_idx == N*2:
        ans = -1
        break
    a,j = next_map[map_idx]
    if a != c :
        ans = -1
        break
    ans += j - i
    i = j%N
print(ans)

Buggy python submission (verdict: Runtime Error):
import bisect
s = input()
t = input()
N = len(s)

next_map = sorted(zip(s*2,range(N*2)))
br = bisect.bisect_right
ans = 0
i = 0
for c in t:
    map_idx = br(next_map,(c,i))
    a,j = next_map[map_idx]
    if a != c :
        ans = -2
        break
    ans += j - i
    i = j%N
ans += 1
print(ans)

Fixed submission:
import bisect
s = input()
t = input()
N = len(s)

next_map = sorted(zip(s*2,range(N*2)))
br = bisect.bisect_right
ans = 0
i = -1
for c in t:
    map_idx = br(next_map,(c,i))
    if map_idx == N*2:
        ans = -1
        break
    a,j = next_map[map_idx]
    if a != c :
        ans = -1
        break
    ans += j - i
    i = j%N
print(ans)
Buggy python submission (verdict: Runtime Error):
L,R = map(int,input().split())

mod = 10**9+7
m = 64 +1
fac = [1]*m
ninv = [1]*m
finv = [1]*m
for i in range(2,m):
    fac[i] = fac[i-1]*i%mod
    ninv[i] = (-(mod//i)*ninv[mod%i])%mod
    finv[i] = finv[i-1]*ninv[i]%mod

def comb(n,k):
    return (fac[n]*finv[k]%mod)*finv[n-k]%mod

def f(N):
    S = bin(N)[2:]
    L = len(S)
    ret = pow(2,S.count("1")-1,mod)
    for i in range(L):
        if S[i] == "0" : continue
        c = S[:i].count("1")
        j = max(0,L-i-1)
        for k in range(j+1):
            if c+k == 0 : continue
            ret += pow(2,c+k-1,mod)*comb(j,k)
            ret %= mod
    return ret

ans = (f(R)-f(L-1))%mod
print(ans)

Fixed submission:
L,R = map(int,input().split())

mod = 10**9+7
m = 64 +1
fac = [1]*m
ninv = [1]*m
finv = [1]*m
for i in range(2,m):
    fac[i] = fac[i-1]*i%mod
    ninv[i] = (-(mod//i)*ninv[mod%i])%mod
    finv[i] = finv[i-1]*ninv[i]%mod

def comb(n,k):
    return (fac[n]*finv[k]%mod)*finv[n-k]%mod

def f(N):
    if N==0:return 0
    S = bin(N)[2:]
    L = len(S)
    ret = pow(2,S.count("1")-1,mod)
    for i in range(L):
        if S[i] == "0" : continue
        c = S[:i].count("1")
        j = max(0,L-i-1)
        for k in range(j+1):
            if c+k == 0 : continue
            ret += pow(2,c+k-1,mod)*comb(j,k)
            ret %= mod
    return ret

def g(R,L):
    if L==0 : return 0
    Nr = len(bin(R))-2
    Nl = len(bin(L))-2
    if Nr!=Nl :
        R = int("1"*Nl,2)
        Nr = Nl
    ret = f(int("0"+"1"*(Nr-1),2))
    
    R = bin(R)[2:]
    L = bin(L)[2:]
    for i in range(Nr):
        if R[i] == "0": continue
        if i==0 : R2 = R
        else: R2 = R[:i] + "0" + "?"*(Nr-i-1)
        for j in range(Nl):
            if L[j] == "0" : continue
            if j==0 : L2 = L
            else: L2 = L[:j] + "0" + "?"*(Nl-j-1)
            tmp = 1
            for r,l in zip(R2,L2):
                if r==l=="?" : tmp *= 3
                if r=="?" and l=="0" : tmp *= 2
                if r=="1" and l=="?" : tmp *= 2
                if r=="0" and l=="1" : tmp *= 0
                tmp %= mod
            ret += tmp
    return ret

print((f(R)-g(R,L-1))%mod)
Buggy python submission (verdict: Runtime Error):
N,M,P = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in [0]*M]

Ef = [{} for _ in [0]*N]
Eb = [{} for _ in [0]*N]

for a,b,c in ABC:
    Ef[a-1][b-1] = P-c
    Eb[b-1][a-1] = P-c

#pre process

d = [-1]*N
d[0] = 0
q = [0]
while q:
    i = q.pop()
    di = d[i]
    for j in Ef[i]:
        if d[j] != -1 : continue
        d[j] = di + 1
        q.append(j)

for i in range(N):
    if d[i] != -1: continue
    for j in Ef[i]:
        Eb[j].pop(i)
    Ef[i] = {}

d = [-1]*N
d[N-1] = 0
q = [N-1]
while q:
    i = q.pop()
    di = d[i]
    for j in Eb[i]:
        if d[j] != -1 : continue
        d[j] = di + 1
        q.append(j)

for i in range(N):
    if d[i] != -1: continue
    for j in Eb[i]:
        Ef[j].pop(i)
    Eb[i] = {}

#main process
ans = 0
d = [None]*N
d[0] = 0
for _ in [0]*N:
    done = [False]*N
    q = [0]
    while q:
        i = q.pop()
        if done[i]: continue
        done[i] = True
        di = d[i]
        for j,c in Ef[i].items():
            if d[j] == None:
                d[j] = di + c
            else:
                d[j] = min(d[j],di+c)
            if done[j]:continue
            q.append(j)

ans = d[-1]
check = d[:]

#check
for _ in [0]:
    done = [False]*N
    q = [0]
    while q:
        i = q.pop()
        if done[i]: continue
        done[i] = True
        di = d[i]
        for j,c in Ef[i].items():
            if d[j] == None:
                d[j] = di + c
            else:
                d[j] = min(d[j],di+c)
            if done[j]:continue
            q.append(j)

if check!=d: ans = -1/0
else: ans = -min(0,ans)

print(ans)

Fixed submission:
def connect_dfs(N,E,start):
    connect = {start}
    q = [start]
    while q:
        i = q.pop()
        for j in E[i]:
            if j in connect:continue
            connect.add(j)
            q.append(j)
    return connect

def remove_Edge(N,Ef,Eb,start,goal):
    v = connect_dfs(N,Ef,start) & connect_dfs(N,Eb,goal)
    for i in range(N):
        if i in v:continue
        for j in Eb[i]:
            Ef[j].pop(i)

def Bellman_Ford(N,E,start,INFTY=10**18):
    def update(dist,N,E,start):
        done = [False]*N
        done[start] = True
        q = [start]
        d = dist[:]
        while q:
            i = q.pop()
            di = d[i]
            for j,c in E[i].items():
                d[j] = min(d[j],d[i]+c)
                if not done[j]:
                    q.append(j)
                    done[j] = True
        return d
    #
    d = [INFTY]*N
    d[start] = 0
    for _ in range(N-1):
        d = update(d,N,E,start)
    if d!=update(d,N,E,start): return None
    else: return d

N,M,P = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in [0]*M]

Ef = [{} for _ in [0]*N]
Eb = [{} for _ in [0]*N]
INFTY = 10**18
for a,b,c in ABC:
    Ef[a-1][b-1] = min(P-c,Ef[a-1].get(b-1,INFTY))
    Eb[b-1][a-1] = min(P-c,Eb[b-1].get(a-1,INFTY))
    
remove_Edge(N,Ef,Eb,0,N-1)
d = Bellman_Ford(N,Ef,0)

if d==None:ans=-1
else:ans = max(0,-d[-1])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
X,Y = map(int,input().split())

ans = [(X,Y)]
x,y = ans[-1]
while abs(x)>=2*K:
    x,y = ans[-1]
    if x>=K:
        x -= K
    elif x<=-K:
        x += K
    ans.append((x,y))
dx = abs(x)

while abs(y)>2*K-dx:
    x,y = ans[-1]
    if y>0:
        y -= K
    else:
        y += K
    ans.append((x,y))

x,y = ans[-1]
if abs(y)+abs(x)!=K:
    if (x+y)%2==0 and K%2==0:
        d2 = (abs(x)+abs(y))//2
        if abs(x)>abs(y):
            x -= d2 * (1 if x>0 else -1)
            y += (K-d2) * (1 if y>0 else -1)
        else:
            x += (K-d2) * (1 if x>0 else -1)
            y -= d2 * (1 if y>0 else -1)
        ans.append((x,y))
    else:
        if (x+y+K)%2 == 0:
            y -= K if y>0 else (-K)
            ans.append((x,y))
        d = abs(x)+abs(y)
        if abs(x)>abs(y):
            x -= d//2 * (1 if x>0 else -1)
            y += (K-d//2) * (1 if y>0 else -1)
        else:
            x += (K-d//2) * (1 if x>0 else -1)
            y -= d//2 * (1 if y>0 else -1)
        ans.append((x,y))
x,y = ans[-1]

if abs(x)+abs(y)!=K:
    print(-1)
else:
    ans = ans[::-1]
    print(len(ans))
    for out in ans:
        print(*out)

Fixed submission:
K = int(input())
X,Y = map(int,input().split())

ans = [(X,Y)]
x,y = ans[-1]
while abs(x)>=3*K//2:
    x,y = ans[-1]
    if x>=K:
        x -= K
    elif x<=-K:
        x += K
    ans.append((x,y))
dx = abs(x)

while abs(y)>2*K-dx:
    x,y = ans[-1]
    if y>0:
        y -= K
    else:
        y += K
    ans.append((x,y))

x,y = ans[-1]
if abs(y)+abs(x)!=K:
    if (x+y)%2==0 and K%2==0:
        d2 = (abs(x)+abs(y))//2
        if abs(x)>abs(y):
            x -= d2 * (1 if x>0 else -1)
            y += (K-d2) * (1 if y>0 else -1)
        else:
            x += (K-d2) * (1 if x>0 else -1)
            y -= d2 * (1 if y>0 else -1)
        ans.append((x,y))
    else:
        if (x+y+K)%2 == 0:
            y -= K if y>0 else (-K)
            ans.append((x,y))
        d = abs(x)+abs(y)
        if abs(x)>abs(y):
            x -= d//2 * (1 if x>0 else -1)
            y += (K-d//2) * (1 if y>0 else -1)
        else:
            x += (K-d//2) * (1 if x>0 else -1)
            y -= d//2 * (1 if y>0 else -1)
        ans.append((x,y))
x,y = ans[-1]

if abs(x)+abs(y)!=K:
    print(-1)
else:
    ans = ans[::-1]
    print(len(ans))
    for out in ans:
        print(*out)
Buggy python submission (verdict: Runtime Error):
def get_divisor(n):
    if n==1:return [1]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            a.append(i)
            b.append(n//i)
    if a[-1]==b[-1]:b.pop()
    a.extend(b[::-1])
    return a

N = int(input())
*A, = map(int,input().split())
D = [0]*(N+1)
ans = []
for i in range(N,0,-1):
    if D[i]%2 != A[i-1]:
        ans.append(i)
        for j in get_divisor(i):
            D[j]+=1
print(len(ans))
print(*ans)

Fixed submission:
N = int(input())
*A, = map(int,input().split())
D = [0]*(N+1)
ans = []
for i in range(N,0,-1):
    if D[i]%2 != A[i-1]:
        ans.append(i)
        for j in range(1,int(i**0.5)+1):
            if i%j==0:
                D[j] += 1
                if i//j != j:D[i//j] += 1
print(len(ans))
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in [0]*N]
B = [A[0]]
for a in A[1:]:
    for i,b in enumerate(B):
        if b<a:
            B[i] = a
            break
    else:
        B.append(a)
print(len(B))

Fixed submission:
N = int(input())
A = [int(input()) for _ in [0]*N]
B = [A[0]]
ans = 1

for a in A[1:]:
    l = 0
    r = ans - 1
    if B[0]<a:r=0
    while l+1<r:
        i = (l+r)//2
        if B[i] < a:
            r = i
        else:
            l = i
    if B[r]<a:B[r] = a
    else:
        B.append(a)
        ans += 1
print(ans)