Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def inpl(): return [int(i) for i in input().split()]
N, C = inpl()
channel = [[] for _ in range(C)]
for i in range(N):
    s, t, c = inpl()
    channel[c-1].append([s,t])
H = [0 for i in range(10**5+3)]
for i in range(C):
    channel[i].sort(key = lambda x: x[0])
    for j in range(len(channel[i])-1):
        if channel[i][j][1] == channel[i][j+1][0]:
            channel[i][j+1] = [channel[i][j][0],channel[i][j+1][1]]
            channel[i][j] = []
        channel[i] = [k for k in channel[i] if k != []]

for i in range(C):
    for st, en in channel[i]:
        H[st] += 1
        H[en+1] -= 1
ans = H[0]
for i in range(10**5+1):
    H[i+1] += H[i]
    ans = max(ans,H[i+1])
        
print(ans)


Fixed submission:
def inpl(): return [int(i) for i in input().split()]
N, C = inpl()
channel = [[] for _ in range(C)]
for i in range(N):
    s, t, c = inpl()
    channel[c-1].append([s,t])
H = [0 for i in range(10**5+3)]
for i in range(C):
    channel[i].sort(key = lambda x: x[0])
    for j in range(len(channel[i])-1):
        if channel[i][j][1] == channel[i][j+1][0]:
            channel[i][j+1] = [channel[i][j][0],channel[i][j+1][1]]
            channel[i][j] = []
    channel[i] = [k for k in channel[i] if k != []]

for i in range(C):
    for st, en in channel[i]:
        H[st] += 1
        H[en+1] -= 1
ans = H[0]
for i in range(10**5+1):
    H[i+1] += H[i]
    ans = max(ans,H[i+1])
        
print(ans)

Buggy python submission (verdict: Runtime Error):
def inpl(): return [int(i) for i in input().split()]
N, C = inpl()
channel = [[] for _ in range(C)]
for i in range(N):
    s, t, c = inpl()
    channel[c-1].append([s,t])
H = [0 for i in range(10**5+1)]
for i in range(C):
    channel[i].sort(key = lambda x: x[0])
    for j in range(len(channel[i])-1):
        if channel[i][j][1] == channel[i][j][0]:
            channel[i][j+1] = [channel[i][j][0],channel[i][j+1][1]]
            channel[i][j] = []
        channel[i][j] = [i for i in channel[i][j] if i != []]

for i in range(C):
    for st, en in channel[i]:
        H[st] += 1
        H[en+1] -= 1
ans = H[0]
for i in range(10**5):
    H[i+1] += H[i]
    ans = max(ans,H[i+1])
        
print(ans)


Fixed submission:
def inpl(): return [int(i) for i in input().split()]
N, C = inpl()
channel = [[] for _ in range(C)]
for i in range(N):
    s, t, c = inpl()
    channel[c-1].append([s,t])
H = [0 for i in range(10**5+3)]
for i in range(C):
    channel[i].sort(key = lambda x: x[0])
    for j in range(len(channel[i])-1):
        if channel[i][j][1] == channel[i][j+1][0]:
            channel[i][j+1] = [channel[i][j][0],channel[i][j+1][1]]
            channel[i][j] = []
    channel[i] = [k for k in channel[i] if k != []]

for i in range(C):
    for st, en in channel[i]:
        H[st] += 1
        H[en+1] -= 1
ans = H[0]
for i in range(10**5+1):
    H[i+1] += H[i]
    ans = max(ans,H[i+1])
        
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque
readline = sys.stdin.readline

K = int(readline())

inf = 10**9+7
dist = [inf]*(K+1)
dist[K] = 0
Q = deque([K])
used = [False]*(K+1)
while Q:
    vn = Q.pop()
    if used[vn]:
        continue
    used[vn] = True
    vf = (vn*10)%K
    if vn%K and not used[vf]:
        dist[vf] = min(dist[vf], dist[vn])
        Q.append(vf)
    vf = (vn+1)%K
    if not used[(vn+1)%K]:
        dist[vf] = min(dist[vf], 1+dist[vn])
        Q.appendleft(vf)
print(dist[0])        


Fixed submission:
import sys
from collections import deque
readline = sys.stdin.readline

K = int(readline())

inf = 10**9+7
dist = [inf]*(K+1)
dist[K] = 0
Q = deque([K])
used = [False]*(K+1)
while Q:
    vn = Q.pop()
    if used[vn]:
        continue
    used[vn] = True
    vf = (vn*10)%K
    if vn%K and not used[vf]:
        dist[vf] = min(dist[vf], dist[vn])
        Q.append(vf)
    vf = (vn+1)%K
    if not used[(vn+1)%K]:
        dist[vf] = min(dist[vf], 1+dist[vn])
        Q.appendleft(vf)
print(dist[0])
Buggy python submission (verdict: Time Limit Exceeded):
def inpl(): return [int(i) for i in input().split()]
from collections import defaultdict

N,M = inpl()
edge = defaultdict(lambda: [])
for _ in range(M):
    a, b = inpl()
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

Qu = [0] 
ctr = 1
color = [0 for _ in range(N)]
color[0] = -1
while ctr < N:
    st = Qu.pop()
    for i in edge[st]:
        if color[st] == -color[i]:
            Qu.append(i)
            continue
        if color[i] == 0:
            color[i] = -color[st]
            Qu.append(i)
            ctr += 1
sumc = sum(color)
ans =(N**2-sumc**2)//4-M
for i in range(N):
    for j in edge[i]:
        if color[i] == color[j]:
            ans = N*(N-1)//2-M
            break
    else:
        continue
    break
print(ans)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]
from collections import defaultdict

N,M = inpl()
edge = defaultdict(lambda: [])
for _ in range(M):
    a, b = inpl()
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

Qu = [0] 
ctr = 1
color = [0 for _ in range(N)]
color[0] = -1
while ctr < N:
    st = Qu.pop()
    for i in edge[st]:
        if color[st] == -color[i]:
            continue
        if color[i] == 0:
            color[i] = -color[st]
            Qu.append(i)
            ctr += 1
sumc = sum(color)
ans =(N**2-sumc**2)//4-M
for i in range(N):
    for j in edge[i]:
        if color[i] == color[j]:
            ans = N*(N-1)//2-M
            break
    else:
        continue
    break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def inpl(): return [int(i) for i in input().split()]
N, K = inpl()
H = {0: 0}
for i in range(N):
    a, b= inpl()
    for ia, ib in H.copy().items():
        if ia | a <= K or (ia == 0 and a <= K):
            H[ia|a] = max(H.get(ia|a, 0), ib+b)
print(max(H.values()))

Fixed submission:
import sys
N, K = map(int, input().split())
candi = []
p = 0
for i in range(30, -1, -1):
    if 2**i & K == 0:
        p += 2**i
        continue
    else:
        candi.append(p + 2**i)
candi.append(p)
AB = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0

for c in candi:
    cans = 0
    for a, b in AB:
        if a & c:
            continue
        cans += b
    ans = max(ans, cans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def inpl(): return [int(i) for i in input().split()]
import sys 
N = int(input())
A = [inpl() for _ in range(N)]
ans = 0
for i in range(N):
    A[i][i] = float('inf')
for i in range(N):
    for j in range(i):
        mindis = min([A[i][k] + A[j][k] for k in range(N)])
        if mindis > A[i][j]:
            ans += A[i][j]
            continue
        if mindis < A[i][j]:
            print(-1)
            sys.exit()

print(ans)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]
import sys
import numpy 
N = int(input())
A = numpy.asarray([inpl() for _ in range(N)])
ans = 0
for i in range(N):
    A[i][i] = 10**9+1
for i in range(N):
    for j in range(i):
        mindis = numpy.min([A[i] + A[j]])
        if mindis > A[i][j]:
            ans += A[i][j]
            continue
        if mindis < A[i][j]:
            print(-1)
            sys.exit()

print(ans)
Buggy python submission (verdict: Runtime Error):
import bisect
import sys
from math import atan
def lis(L):
    if not L:
        return 0
    seq = [L[0]]
    for i in L[1:]:
        if seq[-1] < i:
            seq.append(i)
        else:
            seq[bisect.bisect_left(seq, i)] = i
    return len(seq)

def mhd(x, y):
    return abs(x) + abs(y)

x1, y1, x2, y2 = map(int, sys.stdin.readline().split())
        
N = int(sys.stdin.readline())

if x1 == x2 or y1 == y2:
    if x1 == x2:
        if y1 > y2:
            y1, y2 = y2, y1
        for _ in range(N):
            X, Y = map(int, sys.stdin.readline().split())
            if X != x1:
                continue
            else:
                if y1 <= Y <= y2:
                    print(100*mhd(0, y1-y2) - 20 + 40*atan(1))
                    sys.exit()
                else:
                    print(100*mhd(0, y1-y2))
                    sys.exit()
    else:
        if x1 > x2:
            x1, x2 = x2, x1
        for _ in range(N):
            X, Y = map(int, sys.stdin.readline().split())
            if Y != y1:
                continue
            else:
                if x1 <= X <= x2:
                    print(100*mhd(x1-x2, 0) - 20 + 40*atan(1))
                    sys.exit()
                else:
                    print(100*mhd(x1-x2, 0))
                    sys.exit()
if x1 > x2:
    x1, x2 = x2, x1
    y1, y2 = y2, y1

geta = 10**9+7
B = []
if y1 < y2:
    for _ in range(N):
        X, Y = map(int, sys.stdin.readline().split())
        if x1 <= X <= x2 and y1 <= Y <= y2:
            B.append(X*geta + Y)
    B.sort()
    B = [b%geta for b in B]
    lb = lis(B)
    if lb == min(abs(x1-x2), abs(y1-y2)) + 1:
        print(100*mhd(x1-x2, y1-y2) + (lb-1)*(20*atan(1)-20) + 40*atan(1) - 20)
    else:
        print(100*mhd(x1-x2, y1-y2) + lb*(20*atan(1)-20))
    
else:
    for _ in range(N):
        X, Y = map(int, sys.stdin.readline().split())
        if x1 <= X <= x2 and y2 <= Y <= y1:
            B.append(X*geta - Y)
    B.sort()
    B = [b%geta for b in B]
    lb = lis(B)
    if lb == min(abs(x1-x2), abs(y1-y2)) + 1:
        print(100*mhd(x1-x2, y1-y2) + (lb-1)*(20*atan(1)-20) + 40*atan(1) - 20)
    else:
        print(100*mhd(x1-x2, y1-y2) + lb*(20*atan(1)-20))

Fixed submission:
def inpl(): return [int(i) for i in input().split()]

Q, H, S, D = inpl()
N = int(input())
mini2 = min(8*Q, 4*H, 2*S, D)
mini1 = min(4*Q, 2*H, S)
print(N//2*mini2 + N%2*mini1)
Buggy python submission (verdict: Runtime Error):
def inpl(): return [int(i) for i in input().split()]

H, W = inpl()
ans = max(H, W)
S = ''
for _ in range(H):
    S += input()
T = [[0]*(W-1)]
for i in range(H-1):
    t = []
    for j in range(W-1):
        r = S[i*W+j] + S[i*W+j+1] + S[(i+1)*W+j] + S[(i+1)*W+j+1]
        t.append(r.count('.')%2)
    ts = [0]*(W-1)
    for i, k in enumerate(t):
        if k:
            continue
        ts[i] = T[-1][i] + 1
    T.append(ts)
for iT in T[1:]:
    stack = []
    for i, l in enumerate(iT):
        while stack:
            w, h = stack[-1]
            if h > l:
                dw, dh = stack.pop()
                ans = max(ans, (dh+1)*(i-dw+1))
                continue
            break
        stack.append((i, l))
    while stack:
        dw, dh = stack.pop()
        ans = max(ans, (dh+1)*(i-dw+2))
print(ans)

Fixed submission:
from collections import defaultdict
edge = defaultdict(lambda: 0)
def inpl(): return [int(i) for i in input().split()]
N = int(input())
A = inpl()
for i in A:
    edge[i] += 1
doubled = []
for j,k in edge.items():
    if k >= 2:
        doubled.append(j)
    if k >= 4:
        doubled.append(j)
doubled = (sorted(doubled))
if len(doubled) < 2:
    print(0)
else:
    print(doubled[-1]*doubled[-2])
Buggy python submission (verdict: Time Limit Exceeded):
def inpl(): return [int(i) for i in input().split()]

H, W = inpl()
ans = max(H, W)
S = ''
for _ in range(H):
    S += input()
T = [[0]*(W-1)]
for i in range(H-1):
    t = []
    for j in range(W-1):
        r = S[i*W+j] + S[i*W+j+1] + S[(i+1)*W+j] + S[(i+1)*W+j+1]
        t.append(r.count('.')%2)
    ts = [0]*(W-1)
    for i, k in enumerate(t):
        if k:
            continue
        ts[i] = T[-1][i] + 1
    T.append(ts)
for iT in T[1:]:
    stack = []
    for i, l in enumerate(iT):
        while stack:
            w, h = stack[-1]
            if h > l:
                dw, dh = stack.pop()
                ans = max(ans, (dh+1)*(i-dw+1))
                continue
            break
        stack.append((i, l))
    while stack:
        dw, dh = stack.pop()
        ans = max(ans, (dh+1)*(i-dw+2))
print(ans)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]

H, W = inpl()
ans = max(H, W)
S = [input() for _ in range(H)]
T = [[0]*(W-1)]
for i in range(H-1):
    t = []
    for j in range(W-1):
        r = S[i][j:j+2] + S[i+1][j:j+2]
        t.append(r.count('.')%2)
    ts = [T[-1][i] + 1 if not k else 0 for i, k in enumerate(t) ]
    T.append(ts)
for iT in T[1:]:
    stack = []
    for i, l in enumerate(iT+[0]):
        dw = -1
        while stack and stack[-1][1] >= l:
            dw, dh = stack.pop()
            ans = max(ans, (dh+1)*(i-dw+1))
        if dw != -1:
            stack.append((dw,l))
            continue
        stack.append((i, l))
print(ans)
Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
    
    if a == 1 or b == 1:
        return 1
    if a == b:
        return a
    if a > b:
        a,b = b,a
    if b%a == 0:
        return a
    b = b%a
    return gcd(a,b)

N = int(input())
A = 1

for _ in range(N):
    B = int(input())
    ans = int(A*B/gcd(A,B))
    A = ans
print(ans)

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

N = int(input())
ans = 1
for _ in range(N):
    A = int(input())
    ans = ans*A//gcd(ans,A)
print(ans)
Buggy python submission (verdict: Runtime Error):
print('?', 10**10)
if input() == 'Y':
    for nod in range(10):
        print('?', 10**nod+1)
        if input() == 'Y':
            break
    ans = 10**nod
else:
    for nod in range(1, 10):
        print('?', 10**nod)
        if input() == 'Y':
            continue
            nod -= 1
        break
    ok = 10**(nod-1)
    ng = 10**nod
    while abs(ok - ng) > 1:
        med = (ok + ng)//2
        print('?', med*10+1)
        if input() == 'N':
            ok = med
        else:
            ng = med
    ans = ok+1
print('!', ans)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]
import numpy as np
ans = float('inf')
N = int(input())
a = np.cumsum(np.array(inpl()))
suma = a[-1]
a = np.delete(a, -1)
for i in a:
    ans = min(ans, abs(suma-2*i))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def inpl(): return [int(i) for i in input().split()]

N,A,B = inpl()
C = A-B
h = [int(input()) for _ in range(N)]

ans = -(-sum(h)//((N-1)*B+A))
while True:
    hprime = [h[i]-ans*B for i in range(N) if h[i]-ans*B >0]
    hans = ans    
    for j in hprime:
            hans -= -(-j//C)
    if hans >= 0:
        break
    ans += 1
print(ans)    

Fixed submission:
def inpl(): return [int(i) for i in input().split()]

N,A,B = inpl()
C = A-B
h = [int(input()) for _ in range(N)]

lo = -(-sum(h)//((N-1)*B+A)) -1
hi = sum([-(-i//A) for i in h]) 
while hi - lo > 1:
    me = (hi+lo)//2
    hprime = [h[i]-me*B for i in range(N) if h[i]-me*B >0]    
    hans = 0
    for j in hprime:
            hans += -(-j//C)
    if hans <= me:
        hi = me
    else:
        lo = me
print(hi)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from itertools import accumulate
readline = sys.stdin.readline

N, M, Q = map(int, readline().split())
direc = [(-1, 0), (1, 0), (0, -1), (0, 1)]
G = [[0]*(M+2)] + [[0] + list(map(int, readline().strip())) + [0] for _ in range(N)] + [[0]*(M+2)]
U = [[0]*(M+2) for _ in range(N+2)]
L = [[0]*(M+2) for _ in range(N+2)]
for i in range(1, N+1):
    for j in range(1, M+1):
        if G[i][j]:
            if G[i-1][j]:
                U[i][j] += 1
            if G[i][j-1]:
                L[i][j] += 1
G = [list(accumulate(k)) for k in G]
G = list(map(list, zip(*G)))
G = [list(accumulate(k)) for k in G]
G = list(map(list, zip(*G)))
U = [list(accumulate(k)) for k in U]
U = list(map(list, zip(*U)))
U = [list(accumulate(k)) for k in U]
U = list(map(list, zip(*U)))
L = [list(accumulate(k)) for k in L]
L = list(map(list, zip(*L)))
L = [list(accumulate(k)) for k in L]
L = list(map(list, zip(*L)))
Ans = [None]*Q 
for qu in range(Q):
    x1, y1, x2, y2 = map(int, readline().split())
    u = U[x1][y1-1] + U[x2][y2] - U[x1][y2] - U[x2][y1-1]
    l = L[x1-1][y1] + L[x2][y2] - L[x1-1][y2] - L[x2][y1]
    g = G[x1-1][y1-1] + G[x2][y2] - G[x1-1][y2] - G[x2][y1-1]
    Ans[qu] = g - u - l
print('\n'.join(map(str, Ans)))

Fixed submission:
import sys
from itertools import accumulate
readline = sys.stdin.readline

def accumulate2d(X):
    N = len(X)
    M = len(X[0])
    
    for i in range(1, N):
        for j in range(1, M):
            X[i][j] += X[i][j-1]
    
    for j in range(1, M):
        for i in range(1, N):
            X[i][j] += X[i-1][j]
    
    return X
    

N, M, Q = map(int, readline().split())
G = [[0]*(M+2)] + [[0] + list(map(int, readline().strip())) + [0] for _ in range(N)] + [[0]*(M+2)]
U = [[0]*(M+2) for _ in range(N+2)]
L = [[0]*(M+2) for _ in range(N+2)]
for i in range(1, N+1):
    for j in range(1, M+1):
        if G[i][j]:
            if G[i-1][j]:
                U[i][j] += 1
            if G[i][j-1]:
                L[i][j] += 1
G = accumulate2d(G)
L = accumulate2d(L)
U = accumulate2d(U)
Ans = [None]*Q 
for qu in range(Q):
    x1, y1, x2, y2 = map(int, readline().split())
    u = U[x1][y1-1] + U[x2][y2] - U[x1][y2] - U[x2][y1-1]
    l = L[x1-1][y1] + L[x2][y2] - L[x1-1][y2] - L[x2][y1]
    g = G[x1-1][y1-1] + G[x2][y2] - G[x1-1][y2] - G[x2][y1-1]
    Ans[qu] = g - u - l
print('\n'.join(map(str, Ans)))
Buggy python submission (verdict: Runtime Error):
def inpl(): return [int(i) for i in input().split()]

N, M = inpl()
inf = float('inf')
path = [0 for _ in range(N)]
score = [-inf]*N
score[0] = 0
ans = 0
for i in range(M):
    a, b, c = inpl()
    path[i] = (a-1,b-1,c)

for i in range(N-1):
    update = False
    for na, nb, nc in path:
        if score[na] != -inf and score[nb] < score[na] + nc:
            score[nb] = score[na]+nc
            update = True
    if not update:
        break
ans = score[N-1]
for na, nb, nc in path:
        if score[na] != -inf and score[nb] < score[na] + nc:
            score[nb] = score[na]+nc
print(ans if ans == score[N-1] else 'inf')

Fixed submission:
def inpl(): return [int(i) for i in input().split()]

N, M = inpl()
inf = float('inf')
path = [0 for _ in range(M)]
score = [-inf]*N
score[0] = 0
ans = 0
for i in range(M):
    a, b, c = inpl()
    path[i] = (a-1,b-1,c)

for i in range(N-1):
    update = False
    for na, nb, nc in path:
        if score[na] != -inf and score[nb] < score[na] + nc:
            score[nb] = score[na]+nc
            update = True
    if not update:
        break
ans = score[N-1]
for na, nb, nc in path:
        if score[na] != -inf and score[nb] < score[na] + nc:
            score[nb] = score[na]+nc
print(ans if ans == score[N-1] else 'inf')
Buggy python submission (verdict: Runtime Error):
def inpl(): return [int(i) for i in input().split()]
def next(v):
    for i in edge[v]:
        if visited[i]:
            continue
        visited[i] = True
        return i
    return -1

from collections import defaultdict
edge = defaultdict(lambda: [])
N, M = inpl()
visited = [False for _ in range(N+1)]
visited[1] = True
for _ in range(M):
    A,B = inpl()
    edge[A].append(B)
    edge[B].append(A)
v = 1
nv = 1
path = [1]
while nv >= 0:
    nv = next(v)
    path.append(nv)
    v = nv
path.pop()
path = list(reversed(path))
v = 1
nv = 1
while nv >= 0:
    nv = next(v)
    path.append(nv)
    v = nv
path.pop()
print(len(path))
print(*path)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]

N = int(input())
A = inpl()
ans = 1
first = True
for i in range(N-1):
    if first:
        if A[i+1] == A[i]:
            continue
        else:
            c = (A[i+1]-A[i])//abs((A[i+1]-A[i]))
            first = False
            continue
    if c*A[i] > c*A[i+1]:
        ans += 1
        first = True
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def inpl(): return [int(i) for i in input().split()]
def next(v):
    for i in edge[v].copy():
        if i in path:
            continue
        if i in path1:
            continue
        return i
    return -1

from collections import defaultdict
edge = defaultdict(lambda: [])
N, M = inpl()
for _ in range(M):
    A,B = inpl()
    edge[A].append(B)
    edge[B].append(A)
v = 1
nv = 1
path = [1]
path1 = [1]
while nv >= 0:
    nv = next(v)
    path.append(nv)
    v = nv
path.pop()
v = 1
nv = 1
while nv >= 0:
    nv = next(v)
    path1.append(nv)
    v = nv
path1=list(reversed(path1))
path1.pop(0)
path1.pop()
path = path1 + path
print(len(path))

print(*path)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]
def next(v):
    for i in edge[v]:
        if visited[i]:
            continue
        visited[i] = True
        return i
    return -1

from collections import defaultdict
edge = defaultdict(lambda: [])
N, M = inpl()
visited = [False for _ in range(N+1)]
visited[1] = True
for _ in range(M):
    A,B = inpl()
    edge[A].append(B)
    edge[B].append(A)
v = 1
nv = 1
path = [1]
while nv >= 0:
    nv = next(v)
    path.append(nv)
    v = nv
path.pop()
path = list(reversed(path))
v = 1
nv = 1
while nv >= 0:
    nv = next(v)
    path.append(nv)
    v = nv
path.pop()
print(len(path))
print(*path)

Buggy python submission (verdict: Time Limit Exceeded):
def inpl(): return [int(i) for i in input().split()]
def next(v):
    for i in edge[v].copy():
        if i in path:
            edge[i].remove(v)
            edge[v].remove(i)
            continue
        elif i in path1:
            edge[i].remove(v)
            edge[v].remove(i)
            continue
        edge[i].remove(v)
        edge[v].remove(i)
        return i
    return -1

from collections import defaultdict
edge = defaultdict(lambda: [])
N, M = inpl()
for _ in range(M):
    A,B = inpl()
    edge[A].append(B)
    edge[B].append(A)

flag = True
v = 1
nv = 1
path = [1]
path1 = [1]
while nv >= 0:
    nv = next(v)
    flag = nv
    path.append(nv)
    v = nv
path.pop()
flag = True
v = 1
nv = 1
while nv >= 0:
    nv = next(v)
    flag = nv
    path1.append(nv)
    v = nv
path1=list(reversed(path1))
path1.pop(0)
path1.pop()
path = path1 + path
print(len(path))

print(*path)

Fixed submission:
def inpl(): return [int(i) for i in input().split()]
def next(v):
    for i in edge[v]:
        if visited[i]:
            continue
        visited[i] = True
        return i
    return -1

from collections import defaultdict
edge = defaultdict(lambda: [])
N, M = inpl()
visited = [False for _ in range(N+1)]
visited[1] = True
for _ in range(M):
    A,B = inpl()
    edge[A].append(B)
    edge[B].append(A)
v = 1
nv = 1
path = [1]
while nv >= 0:
    nv = next(v)
    path.append(nv)
    v = nv
path.pop()
path = list(reversed(path))
v = 1
nv = 1
while nv >= 0:
    nv = next(v)
    path.append(nv)
    v = nv
path.pop()
print(len(path))
print(*path)
Buggy python submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline
MOD = 10**9+7
N = int(readline())

dp1 = [0]*(N+1)
Dp1 = [0]*(N+1)
dp2 = [0]*(N+1)
Dp2 = [0]*(N+1)
dp1[0] = 1
Dp1[0] = 1
dp2[0] = N-1
Dp2[0] = N-1
dp1[1] = N-1
dp2[1] = (N-1)**2
dp1[2] = N-1
dp2[2] = (N-1)**2
Dp1[1] = Dp1[0] + dp1[1]
Dp2[1] = Dp2[0] + dp2[1]
Dp1[2] = Dp1[1] + dp1[2]
Dp2[2] = Dp2[1] + dp2[2]
for i in range(3, N+1):
    dp1[i] = (dp1[i-1] + Dp1[i-3] - 1) % MOD
    dp2[i] = (dp2[i-1] + Dp2[i-3]) % MOD
    Dp1[i] = (Dp1[i-1] + dp1[i]) % MOD
    Dp2[i] = (Dp2[i-1] + dp2[i]) % MOD
print((Dp1[N-1] + Dp2[N-1]) % MOD)  

Fixed submission:
import sys
readline = sys.stdin.readline
MOD = 10**9+7
N = int(readline())

dp1 = [0]*(N+3)
Dp1 = [0]*(N+3)
dp2 = [0]*(N+3)
Dp2 = [0]*(N+3)
dp1[0] = 1
Dp1[0] = 1
dp2[0] = N-1
Dp2[0] = N-1
dp1[1] = N-1
dp2[1] = (N-1)**2
dp1[2] = N-1
dp2[2] = (N-1)**2
Dp1[1] = Dp1[0] + dp1[1]
Dp2[1] = Dp2[0] + dp2[1]
Dp1[2] = Dp1[1] + dp1[2]
Dp2[2] = Dp2[1] + dp2[2]
for i in range(3, N+1):
    dp1[i] = (dp1[i-1] + Dp1[i-3] - 1) % MOD
    dp2[i] = (dp2[i-1] + Dp2[i-3]) % MOD
    Dp1[i] = (Dp1[i-1] + dp1[i]) % MOD
    Dp2[i] = (Dp2[i-1] + dp2[i]) % MOD
print((Dp1[N-1] + Dp2[N-1]) % MOD)