Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02850 (python)

Fixed submission:
if __name__ == "__main__":
    import sys
    from collections import deque
    input = sys.stdin.readline
    N = int(input())
    edges = [[] for _ in range(N)]
    for i in range(N-1):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        edges[a].append((b,i))
        edges[b].append((a,i))

    color = [None]*(N-1)
    SIZE = 1
    q = deque([(0,None)])
    while q:
        v, prev_color = q.popleft()
        c = 1
        for w, i in edges[v]:
            if not color[i]:
                if c == prev_color:
                    c += 1
                color[i] = c
                c += 1
                q.append((w,color[i]))
        SIZE = max(SIZE, c-1)
    print(SIZE)
    for n in range(N-1):
        print(color[n])

Buggy submission (verdict: Runtime Error):
N = int(input())
edges = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append((b,i))
    edges[b].append((a,i))

color = [None]*(N-1)
SIZE = 1
def dfs(i, prev):
    global SIZE
    colors = list(range(1, SIZE+1))
    if prev:
        colors.remove(prev)
    for j, n in edges[i]:
        if not color[n]:
            if not colors:
                SIZE += 1
                color[n] = SIZE
            else:
                color[n] = colors.pop()
            dfs(j, color[n])
dfs(0, None)
print(SIZE)
for n in range(N-1):
    print(color[n])
Problem p02883 (python)

Fixed submission:
from math import ceil
def main():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    C = list(map(int,input().split()))
    A.sort(reverse=True)
    C.sort()
    def chk(x):
        cnt = 0
        for i in range(N):
            cnt += max(ceil(A[i]-x/C[i]), 0)
            if cnt > K:
                return False
        return True
    ng, ok = -1, 10**12
    while ok - ng > 1:
        m = (ok+ng)//2
        if chk(m):
            ok = m
        else:
            ng = m
    print(ok)
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from math import ceil
def chk(A, C, x, K):
    cnt = 0
    for i in range(N):
        cnt += max(ceil(A[i]-x/C[i]), 0)
        if cnt > K:
            return False
    return True
def main():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    C = list(map(int,input().split()))
    A.sort(reverse=True)
    C.sort()
    ng, ok = -1, 10**12
    while ok - ng > 1:
        m = (ok+ng)//2
        if chk(A, C, m, K):
            ok = m
        else:
            ng = m
    print(ok)
if __name__ == "__main__":
    main()
Problem p02936 (python)

Fixed submission:
import sys
from collections import defaultdict
sys.setrecursionlimit(1000000)
N, Q = map(int,input().split())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

d = defaultdict(int)
for _ in range(Q):
    p,x = map(int,input().split())
    d[p-1] += x
visited = [False]*N
cnt = [0]*N
def dfs(n, acc):
    cnt[n] = acc
    for m in edges[n]:
        if not visited[m]:
            visited[m] = True
            dfs(m, acc+d[m])
visited[0] = True
dfs(0, d[0])
print(*cnt)

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict
sys.setrecursionlimit(100000)
N, Q = map(int,input().split())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

d = defaultdict(int)
for _ in range(Q):
    p,x = map(int,input().split())
    d[p-1] += x
visited = [False]*N
cnt = [0]*N
def dfs(n, acc):
    cnt[n] = acc
    for m in edges[n]:
        if not visited[m]:
            visited[m] = True
            dfs(m, acc+d[m])
visited[0] = True
dfs(0, d[0])
print(*cnt)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N, Q = map(int,input().split())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

d = defaultdict(int)
for _ in range(Q):
    p,x = map(int,input().split())
    d[p-1] += x
visited = [False]*N
cnt = [0]*N
def dfs(n, acc):
    cnt[n] = acc
    for m in edges[n]:
        if not visited[m]:
            visited[m] = True
            dfs(m, acc+d[m])
visited[0] = True
dfs(0, d[0])
print(*cnt)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import sys
input = sys.stdin.readline
N, Q = map(int,input().split())
edge_from = defaultdict(list)
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edge_from[a].append(b)
tmp = [0]*N
for i in range(Q):
    p, x = map(int,input().split())
    tmp[p-1] += x
q = [None]*N
head = 0
tail = 1
q[0] = (0, 0)
while head < N:
    p, x = q[head]
    x += tmp[p]
    tmp[p] = x
    head += 1
    for nx in edge_from[p]:
        q[tail] = (nx, x)
        tail += 1
print(*tmp)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import sys
input = sys.stdin.readline
N, Q = map(int,input().split())
edge_from = defaultdict(list)
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edge_from[a].append(b)
tmp = [0]*N
for i in range(Q):
    p, x = map(int,input().split())
    tmp[p-1] += x
q = [None]*N
head = 0
tail = 1
q[0] = (0, 0)
while head < N:
    p, x = q[head]
    x += tmp[p]
    tmp[p] = x
    head += 1
    for nx in edge_from[p]:
        q[tail] = (nx, x)
        tail += 1
print(*tmp)
Problem p02972 (python)

Fixed submission:
N = int(input())
a = [0]+list(map(int,input().split()))
ls = [0]*(N+1)
for i in range(N, 0, -1):
    sm = 0
    for j in range(i, N+1, i):
        sm += ls[j]
    ls[i] = (sm % 2) ^ a[i]
b = [i for i in range(N+1) if ls[i] == 1]
print(len(b))
print(*b)

Buggy submission (verdict: Runtime Error):
N=int(input())
a=list(map(int,input().split()))
box=[0]*N
for i in range(N, 0,-1):
    sm = 0
    for j in range(i, N+1, i):
        sm += box[j-1]
    print(i, sm)
    box[i-1] = (sm % 2) ^ a[i-1]
print(sum(box))
print(*sum)
Problem p02985 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
N,K = map(int,input().split())
edges = [[] for _ in range(N)]
used = [False]*N
mod = 10**9+7
for _ in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)
def f(n,c):
    sm = 1
    t = K-c
    for m in edges[n]:
        if not used[m]:
            used[m] = True
            if t <= 0:
                print(0)
                exit(0)
            sm = (sm*f(m,2)*t) % mod
            t -= 1
    return sm
used[0] = True
print(K*f(0,1) % mod)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
edges = [[] for _ in range(N)]
used = [False]*N
mod = 10**9+7
for _ in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)
def f(n,c):
    sm = 1
    t = K-c
    for m in edges[n]:
        if not used[m]:
            used[m] = True
            if t <= 0:
                print(0)
                exit(0)
            sm = (sm*f(m,2)*t) % mod
            t -= 1
    return sm
used[0] = True
print(K*f(0,1) % mod)
Problem p03032 (python)

Fixed submission:
import heapq as pq
from collections import deque
from itertools import accumulate
N,K = map(int,input().split())
v = list(map(int,input().split()))
acc = [0]+list(accumulate(v,lambda x,y: x+y))
anss = -1
M = min(K,N)
for k in range(M+1):
    for i in range(k+1):
        ans = 0
        ls = deque(v)
        heap = []
        j = k-i
        ans += acc[i]+acc[-1]-acc[-1-j]
        for q in range(i):
            if ls:
                pq.heappush(heap,ls.popleft())
            else:
                break
        for q in range(j):
            if ls:
                pq.heappush(heap,ls.pop())
            else:
                break
        for i in range(K-k):
            if heap:
                x = pq.heappop(heap)
                if x < 0:
                    ans -= x
                else:
                    break
        anss = max(ans,anss)
print(anss)

Buggy submission (verdict: Runtime Error):
import heapq as pq
from collections import deque
from itertools import accumulate
N,K = map(int,input().split())
v = list(map(int,input().split()))
acc = [0]+list(accumulate(v,lambda x,y: x+y))
anss = -1
for k in range(K+1):
    for i in range(k+1):
        ans = 0
        ls = deque(v)
        heap = []
        j = k-i
        ans += acc[i]+acc[-1]-acc[-1-j]
        for q in range(i):
            if ls:
                pq.heappush(heap,ls.popleft())
            else:
                break
        for q in range(j):
            if ls:
                pq.heappush(heap,ls.pop())
            else:
                break
        for i in range(K-k):
            if heap:
                x = pq.heappop(heap)
                if x < 0:
                    ans -= x
                else:
                    break
        anss = max(ans,anss)
print(anss)
Problem p03074 (python)

Fixed submission:
N,K = map(int,input().split())
s = input()
ls = []
i = 0
c = 0
while i < N and s[i] == "1":
    c += 1
    i += 1
if i==N:
    print(N)
    exit()
while i < N:
    l = c
    c = 0
    while i < N and s[i] == "0":
        c += 1
        i += 1
    m = c
    c = 0
    while i < N and s[i] == "1":
        c += 1
        i += 1
    r = c
    ls.append((l,m,r))
K = min(K, len(ls))
from itertools import accumulate
acc = list(accumulate([0]+ls, lambda x,y:x+y[1]+y[2]))
ans = 0
for i in range(len(ls)-K+1):
    ans = max(ans, acc[i+K]-acc[i]+ls[i][0])
print(ans)

Buggy submission (verdict: Runtime Error):
def f(s):
    if s == "":
        return []
    if s[0] == "1": 
        if "0" in s:
            i = s.index("0")
            return [len(s[:i])]+f(s[i:])
        else:
            return [len(s)]
    else:
        if "1" in s:
            i = s.index("1")
            return [-len(s[:i])]+f(s[i:])
        else:
            return [-len(s)]
from itertools import accumulate
N,K = map(int,input().split())
S = input()
ls = f(S)
inds = []
for i in range(len(ls)):
    if ls[i] < 0:
        inds.append(i)
acc1 = [0]+list(accumulate(ls, lambda x,y:max(x,0)+max(0,y)))
if acc1[1] < 0:
    acc1[1] *= -1
acc2 = [0]+list(accumulate([-ls[i] for i in inds], lambda x,y:x+y))
ans = max(ls)

for i in range(len(inds)-K+1):
    #print(acc2[i+K]-acc2[i], acc1[min(inds[i+K-1]+2, len(acc1)-1)],acc1[max(inds[i]-1,0)])
    ans = max(acc2[i+K]-acc2[i]+acc1[min(inds[i+K-1]+2, len(acc1)-1)]-acc1[max(inds[i]-1,0)], ans)
print(ans)
Problem p03078 (python)

Fixed submission:
import heapq as hq
x,y,z,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ab = []
for a in A:
    for b in B:
        hq.heappush(ab, -a-b)
abc = []
cnt = 0
while cnt < k and ab:
    cnt += 1
    a = hq.heappop(ab)
    for b in C:
        hq.heappush(abc, a-b)
cnt = 0
while cnt < k:
    print(-hq.heappop(abc))
    cnt += 1

Buggy submission (verdict: Runtime Error):
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
abc = [(-(A[0]+B[0]+C[0]), 0,0,0)]
used = set((0,0,0))
while K > 0:
    K -= 1
    p,i,j,k = hq.heappop(abc)
    print(-p)
    for a,b,c in [(i+1,j,k), (i,j+1,k), (i,j,k+1)]:
        if a < x and b < y and c < z and (a,b,c) not in used:
            used.add((a,b,c))
            hq.heappush(abc, (-(A[a]+B[b]+C[c]), a,b,c))

Buggy submission (verdict: Runtime Error):
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ab = list()
for a in A:
    for b in B:
        ab.append(a+b)
ab.sort(reverse=True)
C.sort(reverse=True)
i = 0
cnt = 0
abc = []
for a in ab[:k]:
    for b in C:
        abc.append(a+b)
abc.sort(reverse=True)
print(*abc[:k], sep="\n")
Problem p03138 (python)

Fixed submission:
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))
MAXBITS = 40
bits = np.ndarray((N, MAXBITS), dtype=int)
for i in range(N):
    a = A[i]
    bits[i] = np.array([(a >> j) & 1 for j in range(MAXBITS-1, -1, -1)])
sm = bits[0]
for b in bits[1:]:
    sm += b
lower = False
Kbits = np.array([(K >> j) & 1 for j in range(MAXBITS-1, -1, -1)])
ans = 0
for i in range(MAXBITS):
    ones = sm[i]
    zeros = N-sm[i]
    base = 2**(MAXBITS-i-1)
    bit = 0
    if ones >= zeros:
        bit = 0
    elif lower or Kbits[i] == 1:
        bit = 1
    if Kbits[i] > bit:
        lower = True
    ans += ones*base if bit == 0 else zeros*base
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))
MAXBITS = 40
bits = np.ndarray((N, MAXBITS), dtype=int)
for i in range(N):
    a = A[i]
    bits[i] = np.array([(a >> j) & 1 for j in range(MAXBITS-1, -1, -1)])
sm = bits[0]
for b in bits[1:]:
    sm += b
lower = False
Kbits = np.array([(K >> j) & 1 for j in range(MAXBITS-1, -1, -1)])
ans = 0
for i in range(MAXBITS):
    ones = sm[i]
    zeros = N-sm[i]
    base = 2**(MAXBITS-i-1)
    if ones >= zeros:
        b = 0
    elif lower or Kbits[i] == 1:
        b = 1
    if Kbits[i] > b:
        lower = True
    ans += ones*base if b == 0 else zeros*base
print(ans)
Problem p03244 (python)

Fixed submission:
from collections import defaultdict
n = int(input())
v = list(map(int,input().split()))
a = v[::2]
b = v[1::2]
def calc(l):
    d = defaultdict(int)
    for x in l:
        d[x] += 1
    return sorted([(d[x], x) for x in d],reverse=True)
A = calc(a)
B = calc(b)
al,ax = A[0]
bl,bx = B[0]
if ax != bx:
    print(n-al-bl)
else:
    ar,ay = A[1] if len(A) > 1 else (0,None)
    br,by = B[1] if len(B) > 1 else (0,None)
    print(min(n-al-br,n-ar-bl))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
n = int(input())
v = list(map(int,input().split()))
a = v[::2]
b = v[1::2]
def calc(l):
    d = defaultdict(int)
    for x in l:
        d[x] += 1
    return sorted([(d[x], x) for x in d],reverse=True)
A = calc(a)
B = calc(b)
al,ax = A[0]
bl,bx = B[0]
if ax != bx:
    print(n-al-bl)
else:
    ar,ay = A[1] if len(A) > 1 else 0,None
    br,by = B[1] if len(B) > 1 else 0,None
    print(min(n-al-br,n-ar-bl))
Problem p03324 (python)

Fixed submission:
d,n = map(int,input().split())
print(n*100**d if n < 100 else 101*100**d)

Buggy submission (verdict: Runtime Error):
ｔd,n = map(int,input().split())
print(n*100**d)
Problem p03409 (python)

Fixed submission:
N = int(input())
red = [tuple(map(int,input().split())) for _ in range(N)]
blue = [tuple(map(int,input().split())) for _ in range(N)]
 
red.sort(key=lambda x:x[0], reverse=True)
blue.sort(key=lambda x:x[1])
 
ans = 0
for i in range(N):
    a,b = red[i]
    for j in range(len(blue)):
        c,d = blue[j]
        if a < c and b < d:
            blue.pop(j)
            ans += 1
            break
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
red = [tuple(map(int,input().split())) for _ in range(N)]
blue = [tuple(map(int,input().split())) for _ in range(N)]
 
red.sort(key=lambda x:x[0])
red.sort(key=lambda x:x[1])
blue.sort(key=lambda x:x[0])
blue.sort(key=lambda x:x[1])
 
ans = 0
for i in range(N):
    a,b = red[i]
    for j in range(len(blue)):
        c,d = blue[j]
        if a < c and b < d:
            print(a,b,c,d)
            blue.pop(j)
            ans += 1
            break
print(ans)
N = int(input())
red = [tuple(map(int,input().split())) for _ in range(N)]
blue = [tuple(map(int,input().split())) for _ in range(N)]

red.sort(key=lambda x:x[0])
red.sort(key=lambda x:x[1])
blue.sort(key=lambda x:x[0])
blue.sort(key=lambda x:x[1])

ans = 0
for i in range(N):
    a,b = red[i]
    for j in range(len(blue)):
        c,d = blue[j]
        if a < c and b < d:
            blue.pop(j)
            ans += 1
            break
print(ans)
Problem p03436 (python)

Fixed submission:
H, W = map(int,input().split())
s = []
black = 0
for i in range(H):
    tmp = list(input())
    s.append(tmp)
    for j in range(W):
        if tmp[j] == "#":
            black += 1
white = H*W - black


q = [(0,0,0)]
s[0][0] = "#"
while q:
    i, j, cnt = q.pop(0)
    for di, dj in [(1,0),(0,1),(-1,0),(0,-1)]:
        ni, nj = i+di, j+dj
        if ni == H-1 and nj == W-1:
            print(white-cnt-2)
            exit(0)
        elif 0 <= ni < H and 0 <= nj < W and s[ni][nj] == ".":
            s[ni][nj] = "#"
            q.append((ni,nj,cnt+1))
print(-1)

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
s = []
black = 0
for i in range(H):
    l = list(input())
    for j in range(W):
        if l[j] == "#":
            black += 1
    s.append(l)
white = H*W-black
from collections import deque
q = deque([(0,0,0)])
s[0][0] = "#"
while q:
    x,y,cnt = q.popleft()
    for dx,dy in [(0,1),(0,-1),(1,0),(-1,0)]:
        nx,ny = x+dx,y+dy
        if 0<=nx<H and 0<=ny<W and s[nx][ny] != "#":
            if nx == H-1 and ny == W-1:
                print(white-cnt-2)
                exit(114514)
            s[nx][ny] = "#"
            q.append((nx,ny,cnt+1))
print(-1)
Problem p03593 (python)

Fixed submission:
from collections import defaultdict
H,W = map(int,input().split())
d = defaultdict(int)
for _ in range(H):
    for c in list(input()):
        d[c] += 1
for i in range((H-1)//2+1):
    for j in range((W-1)//2+1):
        s = set([(x,y) for x,y in [(i,j),(i,W-1-j),(H-1-i,j),(H-1-i,W-1-j)] if 0<=x<H and 0<=y<W])
        f = True
        for k,_ in sorted(d.items(),key=lambda x:x[1]):
            if d[k] >= len(s):
                d[k] -= len(s)
                f = False
                break
        if f:
            print("No")
            exit(0)
print("Yes")

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
H,W = map(int,input().split())
d = defaultdict(int)
for _ in range(H):
    for c in list(input()):
        d[c] += 1
for i in range((H-1)//2+1):
    for j in range((W-1)//2+1):
        s = set([(x,y) for x,y in [(i,j),(i,W-1-j),(H-1-i,j),(H-1-i,W-1-j)] if 0<=x<H and 0<=y<W])
        f = True
        for k,_ in sorted(d.items(),key=lambda x:x[1]):
            if d[k] >= len(s):
                d[k] -= len(s)
                f = False
                for x,y in s:
                    test[x][y] = k
                break
        if f:
            print("No")
            exit(0)
print("Yes")
Problem p03608 (python)

Fixed submission:
from itertools import permutations
N,M,R = map(int,input().split())
r = list(map(lambda x:int(x)-1,input().split()))
edges = [[] for _ in range(N)]
for _ in range(M):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    edges[a].append((b,c))
    edges[b].append((a,c))
V = N
INF = float("inf")
dp = [[INF]*V for _ in range(V)]
for i in range(V):
    for j, w in edges[i]:
        dp[i][j] = w
for k in range(V):
    for i in range(V):
        for j in range(V):
            dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])

ans = INF
for p in permutations(r):
    t = 0
    for i in range(1, R):
        t += dp[p[i]][p[i-1]]
    ans = min(ans, t)
print(ans)

Buggy submission (verdict: Runtime Error):
#include <iostream> 
#include <algorithm>
#include <vector>
//#include <string>
#include <queue>
//#include <functional>
using namespace std;

int main() {
    const long INF = 100000*200;
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r;
    for (int i=0; i<R; i++) {
        int x;
        cin >> x;
        r.push_back(x-1);
    }
    long dp[200][200];
    for (int i=0; i<200; i++) {
        for (int j=0; j<200; j++) {
           dp[i][j] = INF;
        }
    }
    for (int i=0; i<M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        dp[a][b] = c;
        dp[b][a] = c;
    }
    for (int k=0; k<N; k++)
        for (int i=0; i<N; i++)
            for (int j=0; j<N; j++)
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]);
    long long ans = -1;
    do {
        long long tmp = 0;
        for (int i=0; i<R-1; i++)
            tmp += dp[r[i]][r[i+1]];
        if (ans == -1) ans = tmp;
        else ans = min(ans, tmp);
    } while(next_permutation(r.begin(), r.end()));
    cout << ans;
    return 0;
}
Problem p03633 (python)

Fixed submission:
def gcd(n,m):
    if n < m:
        t = n
        n = m
        m = t
    r = n % m
    while r > 0:
        n, m = m, r
        r = n % m
    return m
N = int(input())
T = [int(input()) for _ in range(N)]
ans = T[0]
for i in range(1,N):
    g = gcd(ans,T[i])
    ans = ans*T[i]//g
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
from itertools import accumulate
def GCD(args):
    return list(accumulate(args,gcd))[-1]
N = int(input())
T = [int(input()) for _ in range(N)]
g = GCD(T)
ans = g
for t in T:
    ans *= t//g
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
from itertools import accumulate
def GCD(*args):
    return list(accumulate(*args,gcd))[-1]
N = int(input())
T = [int(input()) for _ in range(N)]
g = GCD(T)
ans = g
for t in T:
    ans *= t//g
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
from itertools import accumulate
def GCD(*args):
    return list(accumulate(*args,gcd))[-1]
def LCM(*args):
    g = GCD(args)
    return list(accumulate([x//g for x in list(args)], lambda x,y:x*y))[-1]*g
_,*T = open(0)
print(LCM(*map(int,T)))
Problem p03660 (python)

Fixed submission:
import heapq as hq
from collections import deque
N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int,input().split())
    a-=1
    b-=1
    edges[a].append((b,1))
    edges[b].append((a,1))
INF = float("inf")
d = [INF]*N
d[0] = 0
prev = [None]*N
q = [(0,0)]
while q:
    dist, i = hq.heappop(q)
    if d[i] < dist:
        continue
    for j, w in edges[i]:
        if d[j] > d[i]+w:
            d[j] = d[i]+w
            prev[j] = i
            hq.heappush(q, (d[j], j))
path = deque()
i = N-1
while prev[i] != 0:
    path.append(prev[i])
    i = prev[i]
fncq = deque([0])
snkq = deque([N-1])
fnc = 1
snk = 1
visited = [False]*N
visited[0] = True
visited[N-1] = True
while path:
    v = path.pop()
    fncq.append(v)
    visited[v] = True
    fnc += 1
    if path:
        v = path.popleft()
        snkq.append(v)
        visited[v] = True
        snk += 1
po = [fncq, snkq]
while fncq or snkq:
    for i in range(2):
        q = po[i]
        if q:
            v = q.popleft()
            for w,_ in edges[v]:
                if not visited[w]:
                    visited[w] = True
                    q.append(w)
                    if i == 0:
                        fnc += 1
                    else:
                        snk += 1
print("Fennec" if fnc > snk else "Snuke")

Buggy submission (verdict: Runtime Error):
import heapq as hq
N = int(input())
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int,input().split())
    a-=1
    b-=1
    edges[a].append((b,1))
    edges[b].append((a,1))
INF = float("inf")
d = [INF]*N
d[0] = 0
q = [(0,0)]
while q:
    dist, i = hq.heappop(q)
    if d[i] < dist:
        continue
    for j, w in edges[i]:
        if d[j] > d[i]+w:
            d[j] = d[i]+w
            hq.heappush(q, (d[j], j))
def cnt(n,m):
    ret = 1
    for v,_ in edges[n]:
        if v != m and not visited[v]:
            visited[v] = True
            ret += cnt(v,m)
    return ret
visited = [False]*N
visited[0] = True
fnc = cnt(0,N-1)
visited = [False]*N
visited[N-1] = True
snk = cnt(N-1,0)
if d[N-1] % 2 == 0:
    snk -= 1
print("Fennec" if snk < fnc else "Snuke")