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

Fixed submission:
import sys
from collections import Counter
INF = 10**18
N, K = [int(i) for i in sys.stdin.readline().split()]
len_k = len(bin(K)[2:])
A_ls = [bin(int(i))[2:] for i in sys.stdin.readline().split()]
max_len = max([len(i) for i in A_ls] + [len_k])
K = bin(K)[2:].zfill(max_len)
A_ls = [A.zfill(max_len) for A in A_ls]
# i番目の解
memo_ls = [0 for i in range(max_len)]
# i番目のみの最適解を考えた時の和
memo_ls2 = [0 for i in range(max_len)]
for i in range(max_len):
    ct = Counter([A[-1-i] for A in A_ls])
    # i番目のけたとして0を選んだ時の和
    ans_0 = 2**i*ct["1"]
    ans_1 = 2**i*ct["0"]
    ct.clear()
    memo_ls[-1-i] = (ans_0, ans_1)
    memo_ls2[-1-i] = max(ans_0, ans_1)
# i-1番目までの解の最大
# memo_ls3[i][j] j : 答えが決まっている時1, いない時0
memo_ls3 = [[0 for i in range(2)] for i in range(max_len + 1)]
memo_ls3[0][1] = -INF
for i, j in enumerate(K, 1):
    if j == "0":
        memo_ls3[i][0] = memo_ls3[i-1][0] + memo_ls[i-1][0]
        memo_ls3[i][1] = memo_ls3[i-1][1] + memo_ls2[i-1]
    else:
        memo_ls3[i][0] = memo_ls3[i-1][0] + memo_ls[i-1][1]
        memo_ls3[i][1] = max(memo_ls3[i-1][1] + memo_ls2[i-1], memo_ls3[i-1][0] + memo_ls[i-1][0])
res = max(memo_ls3[-1])
print(int(res))

Buggy submission (verdict: Runtime Error):
from itertools import zip_longest
def get_X(ls):
    X = list()
    for xs in zip_longest(*ls):
        xs = [i for i in xs if i is not None]
        _sum = sum(xs)
        _len = len(xs)
        if _len - _sum > _sum:
            X.append(1)
        else:
            X.append(0)
    return X

def get_2_order(d, max_len=None):
    ls = str(bin(d))[2:]
    if max_len is not None and max_len > len(ls):
        ls = (max_len - len(ls)) * "0" + ls
    return ls

def get_max(X,ls):
    _sum = 0
    for i, xs in enumerate(zip_longest(*ls)):
        xs = [i for i in xs if i is not None]
        _sum += 2**i*sum([1 if x != X[i] else 0 for j,x in enumerate(xs)])
    return _sum


N, K = map(int, input().split())
A_ls = [int(i) for i in input().split()]
if len(A_ls) == 1:
    print(A_ls[0])
else:
    _max = 0
    len_K = len(bin(K))-2
    A_ls = [get_2_order(d, len_K)[::-1] for d in A_ls]
    for i in range(K):
        X = get_2_order(i, len_K)[::-1]
        result = get_max(X, A_ls)
        if _max < result:
            _max = result
    print(_max)
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
N, M = [int(i) for i in input().split()]
edges = {j : [] for j in range(N + 1)}
for j in range(M):
    x, y = [int(i) for i in input().split()]
    x -= 1
    y -= 1
    edges[x].append(y)
for i in range(N):
    edges[N].append(i)

memo_ls = [None for i in range(N + 1)]


def dfs(last):
    if memo_ls[last] is not None:
        return memo_ls[last]
    if len(edges[last]) == 0:
        return 0
    cnt = max([dfs(_next) + 1 for _next in edges[last]])
    memo_ls[last] = cnt
    return cnt


print(dfs(N) - 1)

Buggy submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]
edges = {j : [] for j in range(N + 1)}
for i in range(M):
    x, y = [int(i) for i in input().split()]
    x -= 1
    y -= 1
    edges[x].append(y)
for i in range(N):
    edges[N].append(i)

memo_ls = [None for i in range(N + 1)]


def dfs(last):
    if memo_ls[last] is not None:
        return memo_ls[last]
    if len(edges[last]) == 0:
        return 0
    cnt = max([dfs(_next) + 1 for _next in edges[last]])
    memo_ls[last] = cnt
    return cnt


print(dfs(N) - 1)

Buggy submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]
edges = {j : [] for j in range(N + 1)}
for i in range(M):
    x, y = [int(i) for i in input().split()]
    x -= 1
    y -= 1
    edges[x].append(y)
for i in range(N):
    edges[N].append(i)

memo_ls = [None for i in range(N + 1)]


def dfs(last):
    if memo_ls[last] is not None:
        return memo_ls[last]
    if len(edges[last]) == 0:
        return 0
    cnt = max([dfs(next) + 1 for next in edges[last]])
    memo_ls[last] = cnt
    return cnt


print(dfs(N) - 1)
Problem p03167 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
h, w = [int(i) for i in sys.stdin.readline().split()]
MAP = []
memo_ls = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    inp = [0 if i == "." else 1 for i in input()]
    MAP.append(inp)


memo_ls[h-1][w-1] = 1
for _h in range(h-1,-1,-1):
    for _w in range(w-1,-1,-1):
        if MAP[_h][_w] == 1:
            continue
        if _w < w - 1:
            memo_ls[_h][_w] += memo_ls[_h][_w+1]
        if _h < h - 1:
            memo_ls[_h][_w] += memo_ls[_h+1][_w]
        memo_ls[_h][_w] %= (1e9+7)
print(int(memo_ls[0][0] % (1e9+7)))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 7)
h, w = [int(i) for i in sys.stdin.readline().split()]
MAP = []
memo_ls = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    inp = [0 if i == "." else 1 for i in input()]
    MAP.append(inp)


memo_ls[h-1][w-1] = 1
for _h in range(h-1,-1,-1):
    for _w in range(w-1,-1,-1):
        if MAP[_h][_w] == 1:
            continue
        if _w < w - 1:
            memo_ls[_h][_w] += memo_ls[_h][_w+1]
        if _h < h - 1:
            memo_ls[_h][_w] += memo_ls[_h+1][_w]
print(int(memo_ls[0][0] % (1e9+7)))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 7)
h, w = [int(i) for i in sys.stdin.readline().split()]
MAP = []
memo_ls = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    inp = [0 if i == "." else 1 for i in sys.stdin.readline()][:-1]
    MAP.append(inp)


memo_ls[h-1][w-1] = 1
for _h in range(h-1,-1,-1):
    for _w in range(w-1,-1,-1):
        if MAP[_h][_w] == 1:
            continue
        if _w < w - 1:
            memo_ls[_h][_w] += memo_ls[_h][_w+1]
        if _h < h - 1:
            memo_ls[_h][_w] += memo_ls[_h+1][_w]
print(int(memo_ls[0][0] % (1e9+7)))

Buggy submission (verdict: Runtime Error):
import sys
h, w = [int(i) for i in sys.stdin.readline().split()]
MAP = []
memo_ls = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    inp = [0 if i == "." else 1 for i in sys.stdin.readline()][:-1]
    MAP.append(inp)


memo_ls[h-1][w-1] = 1
for _h in range(h-1,-1,-1):
    for _w in range(w-1,-1,-1):
        if MAP[_h][_w] == 1:
            continue
        if _w < w - 1:
            memo_ls[_h][_w] += memo_ls[_h][_w+1]
        if _h < h - 1:
            memo_ls[_h][_w] += memo_ls[_h+1][_w]
print(int(memo_ls[0][0] % (1e9+7)))
Problem p03175 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n = int(input())
graph = {i:[] for i in range(n+1)}
for j in range(n-1):
    x, y = [int(i) for i in sys.stdin.readline().split()]
    x -= 1
    y -= 1
    graph[x].append(y)
    graph[y].append(x)

memo_ls = [[None for j in range(2)] for i in range(n+1)]
# i番目の人がj色の時の通り数 0 : 白
cur = 0
def dfs(cur, col, last):
    if memo_ls[cur][col] is not None:
        return memo_ls[cur][col]
    next_col_num = 1 if col == 1 else 2
    _sum = 1
    cnt = 0
    for _next in graph[cur]:
        if _next == last:
            continue
        cnt += 1
        res = 0
        for next_col in range(next_col_num):
            res += dfs(_next, next_col, cur)
        _sum *= max(1, res)
    if cnt == 0:
        memo_ls[cur][col] = 1
        return 1
    res = _sum % (10 ** 9 + 7)
    memo_ls[cur][col] = res
    return res
res = dfs(0,0,-1) + dfs(0,1,-1)
print(res % (10**9+7))

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
graph = {i:[] for i in range(n)}
for j in range(n-1):
    x, y = [int(i) for i in sys.stdin.readline().split()]
    x -= 1
    y -= 1
    graph[x].append(y)
    graph[y].append(x)

memo_ls = [[None for j in range(2)] for i in range(n+1)]
# i番目の人がj色の時の通り数 0 : 白
cur = 0
def dfs(cur, col, last):
    if memo_ls[cur][col] is not None:
        return memo_ls[cur][col]
    next_col_num = 1 if col == 1 else 2
    _sum = 1
    cnt = 0
    for _next in graph[cur]:
        res = 0
        for next_col in range(next_col_num):
            if _next == last:
                continue
            cnt += 1
            res += dfs(_next, next_col, cur)
        _sum *= max(1, res)
    if cnt == 0:
        memo_ls[cur][col] = 1
        return 1
    res = _sum % (10 ** 9 + 7)
    memo_ls[cur][col] = res
    return res
res = dfs(0,0,-1) + dfs(0,1,-1)
print(res % (10**9+7))

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
n = int(input())
graph = {i:[] for i in range(n)}
for i in range(n-1):
    x, y = [int(i) for i in sys.stdin.readline().split()]
    x -= 1
    y -= 1
    graph[x].append(y)
    graph[y].append(x)

memo_ls = [[None for j in range(2)] for i in range(n)]
# i番目の人がj色の時の通り数 0 : 白
cur = 0
def dfs(cur, col, last):
    if memo_ls[cur][col] is not None:
        return memo_ls[cur][col]
    next_col_num = 1 if col == 1 else 2
    _sum = 1
    cnt = 0
    for _next in graph[cur]:
        res = 0
        for next_col in range(next_col_num):
            if _next == last:
                continue
            cnt += 1
            res += dfs(_next, next_col, cur)
        _sum *= max(1, res)
    if cnt == 0:
        memo_ls[cur][col] = 1
        return 1
    res = _sum % (10 ** 9 + 7)
    memo_ls[cur][col] = res
    return res
res = dfs(0,0,-1) + dfs(0,1,-1)
print(res % (10**9+7))
Problem p03178 (python)

Fixed submission:
import sys
from math import log10, floor
K = input()
d = int(input())
digit_num = len(K)
MOD = 10**9+7
# memo_ls[i][j][k] : 上からi桁目まででMODがjでflgがkの個数
memo_ls = [[[0 for _k in range(2)] for j in range(d)] for i in range(digit_num + 1)]
memo_ls[0][0][0] = 1
dic = {j : j % d for j in range(10)}
for i, n in enumerate(K, 1):
    n = int(n)
    for j in range(10):
        for k in range(d):
            _from = (k - j) % d
            memo_ls[i][k][1] = (memo_ls[i][k][1] + memo_ls[i-1][_from][1]) % MOD
            if j == n:
                memo_ls[i][k][0] = (memo_ls[i-1][_from][0] + memo_ls[i][k][0]) % MOD
            elif j < n:
                memo_ls[i][k][1] = (memo_ls[i-1][_from][0] + memo_ls[i][k][1]) % MOD
print((sum(memo_ls[digit_num][0]) - 1) % MOD)

Buggy submission (verdict: Runtime Error):
import sys
from math import log10, floor
k = int(sys.stdin.readline().strip())
d = int(input())
digit_num = floor(log10(k)) + 1
MOD = 10**9+7
# memo_ls[i][j][k] : 上からi桁目まででMODがjでflgがkの個数
memo_ls = [[[0 for k in range(2)] for j in range(d)] for i in range(digit_num + 1)]
memo_ls[0][0][0] = 1
dic = {j : j % d for j in range(d)}
for i, n in enumerate(str(k), 1):
    n = int(n)
    for j in range(10):
        x = dic[j]
        for k in range(d):
            _from = k - x if k - x >= 0 else d + k - x
            if j == n:
                memo_ls[i][k][0] += memo_ls[i-1][_from][0]
                memo_ls[i][k][1] += memo_ls[i-1][_from][1]
            elif j < n:
                memo_ls[i][k][1] += memo_ls[i-1][_from][1] + memo_ls[i-1][_from][0]
            else:
                memo_ls[i][k][1] += memo_ls[i - 1][_from][1]
            memo_ls[i][k][0] %= MOD
            memo_ls[i][k][1] %= MOD
print(sum(memo_ls[-1][0]) - 1)
Problem p03219 (python)

Fixed submission:
X, Y = [int(i) for i in input().split()]
print(X + Y // 2)

Buggy submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]
data = list()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([i, p, y])
data.sort(key=lambda x:(x[1],x[2]))
ind = 1
for j, (i, p, y) in enumerate(data):
    if data[j-1][1] != p:
        ind = 1
    data[j].append(ind)
    ind += 1
data.sort(key=lambda x:x[0])
for i, p, y, j in data:
    print(str(p).zfill(6) + str(j).zfill(6))
Problem p03243 (python)

Fixed submission:
N = int(input())
len_N = len(str(N))
num = int(str(N)[0])
if int(str(num) * len_N) < N:
  print(str(num + 1) * len_N)
else:
  print(str(num) * (len(str(N))))

Buggy submission (verdict: Runtime Error):
N = int(input())
len_N = len(N)
num = int(str(N)[0]) + 1
if int(str(num) * len_N) < N:
  print(str(num) * len_N)
else:
  print(str(num + 1) * (len(str(N))))
Problem p03262 (python)

Fixed submission:
N, X = [int(i) for i in input().split()]
x_ls = [int(i) for i in input().split()]
x_ls = [abs(x - X) for x in x_ls]
while True:
    min_x = min(x_ls)
    x_ls = [x % min_x for x in x_ls]
    if not any(x_ls):
        break
    x_ls = [x for x in x_ls if x != 0]
print(min_x)

Buggy submission (verdict: Runtime Error):
N, X = [int(i) for i in input().split()]
x_ls = [int(i) for i in input().split()]
x_ls = [abs(x - X) for x in x_ls]
while True:
    if all([x % min(x_ls) == 0 for x in x_ls]):
        break
    else:
        x_ls = [x % min(x_ls) for x in x_ls]
print(min(x_ls))
Problem p03282 (python)

Fixed submission:
s = [int(i) for i in input().strip()]
k = int(input())
ind = -1
while k > 0:
    ind += 1
    if s[ind] == 1:
        k -= 1
    else:
        k = 0
print(s[ind])

Buggy submission (verdict: Runtime Error):
s = [int(i) for i in input().strip()]
k = int(input())
ind = 0
while k > 0:
    if s[ind] == 1:
        k -= 1
        ind += 1
    else:
        k = 0
print(s[ind])
Problem p03290 (python)

Fixed submission:
import math
D, G = [int(i) for i in input().split()]
data_ls = list()
for i in range(D):
    data_ls.append([int(i) for i in input().split()])
ps, cs = zip(*data_ls)

def search(cnt, sum, flg, rest_max):
    if sum >= G:
        return cnt
    if flg == len(data_ls):
        if sum + (ps[rest_max] - 1) * 100 * (rest_max + 1) >= G:
            return cnt + math.ceil((G - sum) / (100 * (rest_max+1)))
        else:
            return 1e9
    cnt = min(search(cnt + ps[flg], sum + (ps[flg] * 100 * (flg+1) + cs[flg]), flg + 1, rest_max),
              search(cnt, sum, flg + 1, flg))
    return cnt

print(search(0,0,0,0))

Buggy submission (verdict: Runtime Error):
import math
D, G = [int(i) for i in input().split()]
data_ls = list()
for i in range(D):
    data_ls.append([int(i) for i in input().split()])
ps, cs = zip(*data_ls)

def search(cnt, sum, flg, rest_max):
    if sum > G:
        return cnt
    if flg == len(data_ls):
        if sum + (ps[rest_max] - 1) * 100 * (rest_max + 1) >= G:
            return cnt + math.floor((G - sum) / (100 * (rest_max+1)))
        else:
            return 1e9
    cnt = min(search(cnt + ps[flg], sum + (ps[flg] * 100 * (flg+1) + cs[flg]), flg + 1, rest_max),
              search(cnt, sum, flg + 1, flg))
    return cnt

print(search(0,0,0,-1))
Problem p03436 (python)

Fixed submission:
H, W = [int(i) for i in input().split()]
sy, sx = [0,0]
gy, gx = [H-1, W-1]
c_ls = list()
yet_ls = [(sy,sx)]
dist_dict = {(sy, sx): 0}
road_len = 0
for i in range(H):
    c_ls.append([i for i in list(input())])
    road_len += len([i for i in c_ls[-1] if i == "."])


def dfs():
    ind = 0
    while len(yet_ls) > ind:
        y, x = yet_ls[ind]
        for move_y, move_x in [(1,0),(-1,0),(0,1),(0,-1)]:
            next_y = y + move_y
            next_x = x + move_x
            if 0 <= next_y < H and 0 <= next_x < W:
                pass
            else:
                continue
            if c_ls[next_y][next_x] == "#":
                continue
            c_ls[next_y][next_x] = "#"
            if (next_y, next_x) not in dist_dict:
                dist_dict[(next_y, next_x)] = dist_dict[(y,x)] + 1
                yet_ls.append((next_y,next_x))
            if (next_y, next_x) == (gy, gx):
                return dist_dict[(next_y, next_x)]
        ind += 1
    return road_len


print(road_len - dfs() - 1)

Buggy submission (verdict: Runtime Error):
H, W = [int(i) for i in input().split()]
sy, sx = [0,0]
gy, gx = [H-1, W-1]
c_ls = list()
yet_ls = [(sy,sx)]
dist_dict = {(sy, sx): 0}
road_len = 0
for i in range(H):
    c_ls.append([i for i in list(input())])
    road_len += len([i for i in c_ls[-1] if i == "."])


def dfs():
    ind = 0
    while len(yet_ls) > ind:
        y, x = yet_ls[ind]
        for move_y, move_x in [(1,0),(-1,0),(0,1),(0,-1)]:
            next_y = y + move_y
            next_x = x + move_x
            if 0 <= next_y < H and 0 <= next_x < W:
                pass
            else:
                continue
            if c_ls[next_y][next_x] == "#":
                continue
            c_ls[next_y][next_x] = "#"
            if (next_y, next_x) not in dist_dict:
                dist_dict[(next_y, next_x)] = dist_dict[(y,x)] + 1
                yet_ls.append((next_y,next_x))
            if (next_y, next_x) == (gy, gx):
                return dist_dict[(next_y, next_x)]
        ind += 1

print(road_len - dfs() - 1)
Problem p03450 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

n, m = [int(i) for i in sys.stdin.readline().split()]
parent = [i for i in range(n)]

graph = {j:[] for j in range(n)}
for i in range(m):
    l, r, d = [int(i) for i in sys.stdin.readline().split()]
    l -= 1
    r -= 1
    graph[l].append((r, d))
    graph[r].append((l, -d))

already = set()
x_ls = [None for i in range(n)]
x_ls[0] = 0
stack = list(range(n))[::-1]
flg = True
while len(stack) > 0:
    cur = stack.pop(-1)
    if cur in already:
        continue
    if x_ls[cur] is None:
        cur_pos = 0
    else:
        cur_pos = x_ls[cur]
    already.add(cur)
    for _next, dis in graph[cur]:
        if x_ls[_next] is None:
            x_ls[_next] = cur_pos + dis
            stack.append(_next)
        else:
            if x_ls[_next] != cur_pos + dis:
                flg = False
                break
    if not flg:
        break
if flg:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
sys.setrecursionlimit(10**7)

n, m = [int(i) for i in sys.stdin.readline().split()]
parent = [i for i in range(n)]

graph = {j:[] for j in range(n)}
for i in range(m):
    l, r, d = [int(i) for i in sys.stdin.readline().split()]
    l -= 1
    r -= 1
    graph[l].append((r, d))
    graph[r].append((l, -d))

yet = set(list(range(n)))
x_ls = [None for i in range(n)]
x_ls[0] = 0
que = deque([0])
flg = True
while len(que) > 0:
    cur = que.popleft()
    if cur in yet:
        yet.remove(cur)
    cur_pos = x_ls[cur]
    for _next, dis in graph[cur]:
        if x_ls[_next] is None:
            x_ls[_next] = cur_pos + dis
            que.append(_next)
        else:
            if x_ls[_next] != cur_pos + dis:
                flg = False
                break
    if not flg:
        break
    if len(que) == 0 and len(yet) > 0:
        que.append(list(yet)[0])
        x_ls[list(yet)[0]] = 0
        yet.pop(0)
if flg:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
n, m = [int(i) for i in sys.stdin.readline().split()]
parent = [i for i in range(n)]

graph = {j:[] for j in range(n)}
for i in range(m):
    l, r, d = [int(i) for i in sys.stdin.readline().split()]
    l -= 1
    r -= 1
    graph[l].append((r, d))
    graph[r].append((l, -d))

yet = set(list(range(n)))
x_ls = [None for i in range(n)]
x_ls[0] = 0
que = deque([0])
flg = True
while len(que) > 0:
    cur = que.popleft()
    if cur in yet:
        yet.remove(cur)
    cur_pos = x_ls[cur]
    for _next, dis in graph[cur]:
        if x_ls[_next] is None:
            x_ls[_next] = cur_pos + dis
            que.append(_next)
        else:
            if x_ls[_next] != cur_pos + dis:
                flg = False
                break
    if not flg:
        break
    if len(que) == 0 and len(yet) > 0:
        que.append(list(yet)[0])
        x_ls[list(yet)[0]] = 0
        yet.pop(0)
if flg:
    print("Yes")
else:
    print("No")
Problem p03504 (python)

Fixed submission:
import sys
from itertools import accumulate
N, C = [int(i) for i in sys.stdin.readline().split()]
ls = {j : [0 for i in range(2*10**5)] for j in range(1,C+1)}
for i in range(N):
    s, t, c = [int(i) for i in sys.stdin.readline().split()]
    ls[c][s] += 1
    ls[c][t+1] -= 1

res = [0 for i in range(2*10**5)]
for _c in range(1, C+1):
    for i, j in enumerate(accumulate(ls[_c])):
        res[i] += min(1,j)
print(max(res))

Buggy submission (verdict: Runtime Error):
import sys
from itertools import accumulate
n, c = [int(i) for i in sys.stdin.readline().split()]
ls = [0 for i in range(10**5+1)]
for i in range(n):
    s, t, c = [int(i) for i in sys.stdin.readline().split()]
    ls[s] += 1
    ls[t+1] -= 1
ls = [i for i in accumulate(ls)]
print(max(ls))
Problem p03660 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

n = int(input())
graph = {i : [] for i in range(n)}
for i in range(n-1):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

stack = [0]
already = set()
parent = [i for i in range(n)]
flg = False
while len(stack) > 0:
    cur = stack.pop(-1)
    already.add(cur)
    for _next in graph[cur]:
        if _next not in already:
            stack.append(_next)
            parent[_next] = cur
            if _next == n - 1:
                flg = True
                break
    if flg:
        break

path = []
cur = n - 1
while cur != 0:
    path.append(cur)
    cur = parent[cur]
path.append(0)
path.reverse()
flg_2 = len(path) % 2 != 0
left = path[len(path) // 2 - 1 + flg_2]
right = path[len(path) // 2 + flg_2]

def dfs(x, last):
    res = 1
    for _next in graph[x]:
        if _next != last:
           res += dfs(_next, x)
    return res

left_res = dfs(left, right)
#print(left_res)
print("Fennec" if left_res > (n - left_res) else "Snuke")

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
graph = {i : [] for i in range(n)}
for i in range(n-1):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

stack = [0]
already = set()
parent = [i for i in range(n)]
flg = False
while len(stack) > 0:
    cur = stack.pop(-1)
    already.add(cur)
    for _next in graph[cur]:
        if _next not in already:
            stack.append(_next)
            parent[_next] = cur
            if _next == n - 1:
                flg = True
                break
    if flg:
        break

path = []
cur = n - 1
while cur != 0:
    path.append(cur)
    cur = parent[cur]
path.append(0)
path.reverse()
flg_2 = len(path) % 2 != 0
left = path[len(path) // 2 - 1 + flg_2]
right = path[len(path) // 2 + flg_2]

def dfs(x, last):
    res = 1
    for _next in graph[x]:
        if _next != last:
           res += dfs(_next, x)
    return res

left_res = dfs(left, right)
#print(left_res)
print("Fennec" if left_res > (n - left_res) else "Snuke")
Problem p02802 (python)

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

ac_list = [0]*(n+1)
wa_list = [0]*(n+1)
wa = 0
ac = 0
if m == 0:
    pass
else:
    for i in range(m):
        p, s = input().split()
        p = int(p)
        if ac_list[p] == 1:
            continue
        if ac_list[p] == 0 and s == 'AC':
            ac_list[p] = 1
        #elif check_list[p] == 0 and s == 'WA':                                          
        else:
            wa_list[p] += 1
    for t_ac, t_wa in zip(ac_list, wa_list):
        if t_ac == 1:
            wa += t_wa
            ac += t_ac
print(ac, wa)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())

if m == 0:
    print(0, 0)
else:
    check_list = [0]*20000
    wa = 0
    ac = 0
    for i in range(m):
        p, s = input().split()
        p = int(p)
        if check_list[p] == 1:
            continue
        elif check_list[p] == 0 and s == 'AC':
            check_list[p] = 1
            ac += 1
        elif check_list[p] ==0 and s == 'WA':
            wa += 1
    print(ac, wa)