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

Fixed submission:
from collections import defaultdict
import heapq


def dijkstra(N, adj, cost, start):
    INF = 10 ** 15
    min_cost = [INF] * N
    min_cost[start] = 0
    que = [(0, start)]
    while len(que) > 0:
        c, node = heapq.heappop(que)
        for next_node in adj[node]:
            next_cost = min_cost[node] + cost[(node, next_node)]
            if next_cost < min_cost[next_node]:
                min_cost[next_node] = next_cost
                heapq.heappush(que, (next_cost, next_node))
    return min_cost


def main():
    MONEY_MAX = 10 ** 15
    N, M, S, T = list(map(int, input().split()))
    S -= 1
    T -= 1
    adj = defaultdict(list)
    yen = defaultdict(int)
    snuuk = defaultdict(int)
    for _ in range(M):
        U, V, A, B = list(map(int, input().split()))
        U -= 1
        V -= 1
        adj[U].append(V)
        adj[V].append(U)
        yen[(U, V)], yen[(V, U)] = A, A
        snuuk[(U, V)], snuuk[(V, U)] = B, B
    min_yen = dijkstra(N, adj, yen, S)
    min_snuuk = dijkstra(N, adj, snuuk, T)
    # 都市iで両替をしてs -> tを移動した場合の最小コスト
    min_cost = [y + s for y, s in zip(min_yen, min_snuuk)]
    city_cost = [(cost, city) for city, cost in enumerate(min_cost)]
    heapq.heapify(city_cost)
    ans = [0] * N
    cost, city = heapq.heappop(city_cost)
    for i in range(N):
        # i年後に都市0 ～ i - 1の両替所は使えない
        while city < i:
            cost, city = heapq.heappop(city_cost)
        ans[i] = MONEY_MAX - cost
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import heapq


def dijkstra(N, adj, cost, start):
    INF = 10 ** 10
    min_cost = [INF] * N
    min_cost[start] = 0
    que = [(0, start)]
    while len(que) > 0:
        c, node = heapq.heappop(que)
        for next_node in adj[node]:
            next_cost = min_cost[node] + cost[(node, next_node)]
            if next_cost < min_cost[next_node]:
                min_cost[next_node] = next_cost
                heapq.heappush(que, (next_cost, next_node))
    return min_cost


def main():
    N, M, S, T = list(map(int, input().split()))
    S -= 1
    T -= 1
    adj = defaultdict(list)
    yen = defaultdict(int)
    snuuk = defaultdict(int)
    for _ in range(M):
        U, V, A, B = list(map(int, input().split()))
        U -= 1
        V -= 1
        adj[U].append(V)
        adj[V].append(U)
        yen[(U, V)], yen[(V, U)] = A, A
        snuuk[(U, V)], snuuk[(V, U)] = B, B
    min_yen = dijkstra(N, adj, yen, S)
    min_snuuk = dijkstra(N, adj, snuuk, T)
    # 都市iで両替をしてs -> tを移動した場合の最小コスト
    min_cost = [y + s for y, s in zip(min_yen, min_snuuk)]
    # ゴールの都市Tで両替するのはNGなことに注意
    city_cost = [(cost, city) for city, cost in enumerate(min_cost) if city != T]
    heapq.heapify(city_cost)
    ans = [0] * N
    cost, city = heapq.heappop(city_cost)
    for i in range(N):
        # i年後に都市0 ～ i - 1の両替所は使えない
        while city < i:
            cost, city = heapq.heappop(city_cost)
        ans[i] = 10 ** 15 - cost
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()
Problem p03488 (python)

Fixed submission:
def parse(s):
    first_val = None
    verticals, horizontals = list(), list()
    seq = 0
    is_horizontal = True
    is_first = True
    for c in s:
        if c == 'T':
            if is_first:
                first_val = seq
                is_first = False
            elif is_horizontal:
                horizontals.append(seq)
            else:
                verticals.append(seq)
            is_horizontal = not is_horizontal
            seq = 0
        else:
            seq += 1
    if seq > 0:
        if is_first:
            first_val = seq
        elif is_horizontal:
            horizontals.append(seq)
        else:
            verticals.append(seq)
    return first_val, verticals, horizontals


def check(vals, target):
    val_set = {0}
    for v in vals:
        tmp_set = set()
        for sv in val_set:
            tmp_set.add(sv + v)
            tmp_set.add(sv - v)
        val_set = tmp_set
    return target in val_set


def main():
    S = input()
    X, Y = list(map(int, input().split(' ')))
    fv, vs, hs = parse(S)
    if check(hs, X - fv) and check(vs, Y):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def parse(s):
    first_val = None
    verticals, horizontals = list(), list()
    seq = 0
    is_horizontal = True
    is_first = True
    for c in s:
        if c == 'T':
            if is_first:
                first_val = seq
                is_first = False
            elif is_horizontal:
                horizontals.append(seq)
            else:
                verticals.append(seq)
            is_horizontal = not is_horizontal
            seq = 0
        else:
            seq += 1
    if seq > 0:
        if is_first:
            first_val = seq
        elif is_horizontal:
            horizontals.append(seq)
        else:
            verticals.append(seq)
    return first_val, verticals, horizontals


def check(vals, target):
    N = sum(vals)
    if N == 0:
        return target == 0
    dp = [0 for _ in range(N + 1)]
    dp[0] = 1
    for v in vals:
        for n in range(N + 1):
            if n + v <= N:
                dp[n + v] = max([dp[n], dp[n + v]])
            if n - v >= 0:
                dp[n - v] = max([dp[n], dp[n - v]])
            else:
                dp[v - n] = max([dp[n], dp[v - n]])
    return dp[abs(target)] == 1


def main():
    S = input()
    X, Y = list(map(int, input().split(' ')))
    fv, vs, hs = parse(S)
    if check(hs, X - fv) and check(vs, Y):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()
Problem p03584 (python)

Fixed submission:
from collections import defaultdict


def main():
    N, K = map(int, input().split())
    integers = [list(map(int, input().split())) for _ in range(N)]
    # bitwise orの結果の候補を計算
    len_bin_k = len('{:b}'.format(K))
    keys = [K]
    for shift in range(1, len_bin_k + 1):
        if (K >> shift) & 1 == 1:
            # 右からshift bit目が0で、それより右が全部1の数
            # （例）K:1100101、shift:3 => 1100011
            keys.append(((K >> shift) << shift) - 1)
    vals = defaultdict(int)
    for a, b in integers:
        for k in keys:
            # bitwise orの結果を変えない整数の場合は価値を合算
            if k | a == k:
                vals[k] += b
    if len(vals.values()) == 0:
        print(0)
    else:
        print(max(vals.values()))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict


def main():
    N, K = map(int, input().split())
    integers = [list(map(int, input().split())) for _ in range(N)]
    # bitwise orの結果の候補を計算
    len_bin_k = len('{:b}'.format(K))
    keys = [K]
    for shift in range(1, len_bin_k + 1):
        if (K >> shift) & 1 == 1:
            # 右からshift bit目が0で、それより右が全部1の数
            # （例）K:1100101、shift:3 => 1100011
            keys.append(((K >> shift) << shift) - 1)
    vals = defaultdict(int)
    for a, b in integers:
        for k in keys:
            # bitwise orの結果を変えない整数の場合は価値を合算
            if k | a == k:
                vals[k] += b
    ans = max(vals.values())
    print(ans)


if __name__ == '__main__':
    main()
Problem p03600 (python)

Fixed submission:
from scipy.sparse.csgraph import floyd_warshall
import numpy as np


def main():
    INF = 10**12
    N = int(input())
    A = [list(map(int, input().split(' '))) for _ in range(N)]
    wf = floyd_warshall(A)
    for i in range(N):
        A[i][i] = INF
        wf[i][i] = INF
    ans = 0
    for i in range(N):
        for j in range(N):
            if A[i][j] != wf[i][j]:
                print(-1)
                return
            if wf[i][j] < np.min(wf[i] + wf[j]):
                ans += wf[i][j]
    print(int(ans // 2))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def warshall_floyd(N, A):
    dist = A.copy()
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if dist[i][j] > dist[i][k] + dist[k][j]:
                    dist[i][j] = dist[i][k] + dist[k][j]
    return dist


def main():
    N = int(input())
    A = [list(map(int, input().split(' '))) for _ in range(N)]
    wf = warshall_floyd(N, A)
    edges = list()
    for i in range(N):
        for j in range(i + 1, N):
            edges.append((A[i][j], i, j))  # (cost, from, to)
    edges.sort(key=lambda e: e[0])
    ans = 0
    for edge in edges:
        cost, from_node, to_node = edge
        if A[from_node][to_node] > wf[from_node][to_node]:
            print(-1)
            return
        to_be_added = True
        for via_node in range(N):
            if via_node in [from_node, to_node]:
                continue
            if wf[from_node][to_node] == wf[from_node][via_node] + wf[via_node][to_node]:
                to_be_added = False
                break
        if to_be_added:
            ans += A[from_node][to_node]
    print(ans)


if __name__ == '__main__':
    main()
Problem p03608 (python)

Fixed submission:
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
import itertools


def main():
    N, M, R = list(map(int, input().split(' ')))
    towns = list(map(lambda t: int(t) - 1, input().split(' ')))
    A = np.zeros((N, N), dtype=int)
    for _ in range(M):
        a, b, c = list(map(int, input().split(' ')))
        A[a-1][b-1] = c
        A[b-1][a-1] = c
    fw = floyd_warshall(A)
    d = fw[towns, :][:, towns]
    min_d = 10**12
    for trip in itertools.permutations(range(R)):
        min_d = min([min_d, sum([d[trip[i]][trip[i+1]] for i in range(len(trip) - 1)])])
    print(int(min_d))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import floyd_warshall
import itertools


def main():
    N, M, R = list(map(int, input().split(' ')))
    towns = list(map(lambda t: int(t) - 1, input().split(' ')))
    A = np.zeros((N, N), dtype=int)
    for _ in range(M):
        a, b, c = list(map(int, input().split(' ')))
        A[a-1][b-1] = c
        A[b-1][a-1] = c
    fw = floyd_warshall(A)
    d = fw[towns, :][:, towns]
    min_d = 10**12
    for trip in itertools.permutations(range(R)):
        min_d = min([min_d, sum([d[trip[i]][trip[i+1]] for i in range(len(trip) - 1)])])
    print(int(min_d))


if __name__ == '__main__':
    main()
Problem p03633 (python)

Fixed submission:
def gcd(a, b):
    a, b = max([a, b]), min([a, b])
    if b == 0:
        return a
    return gcd(b, a % b)
N = int(input())
current_lcm = None
for _ in range(N):
    t = int(input())
    if current_lcm is None:
        current_lcm = t
        continue
    current_lcm = current_lcm * t // gcd(current_lcm, t)
print(current_lcm)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
current_lcm = None
for _ in range(N):
    t = int(input())
    if current_lcm is None:
        current_lcm = t
        continue
    current_lcm = current_lcm // math.gcd(current_lcm, t)
    current_lcm *= t
print(current_lcm)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
current_lcm = None
for _ in range(N):
    t = int(input())
    if current_lcm is None:
        current_lcm = t
        continue
    current_lcm = current_lcm * t // math.gcd(current_lcm, t)
print(current_lcm)
Problem p03714 (python)

Fixed submission:
from collections import deque
from heapq import heapify, heappop, heappush
N = int(input())
tmp = list(map(int, input().split(' ')))
former_A = deque(tmp)
latter_A = deque(tmp.copy())
former_heap = list()
latter_heap = list()
for _ in range(N):
    former_heap.append(former_A.popleft())
    latter_heap.append(- latter_A.pop())
heapify(former_heap)
heapify(latter_heap)

former_sum = sum(former_heap)
former_sum_list = [former_sum]
for k in range(N):
    new_a = former_A.popleft()
    heappush(former_heap, new_a)
    min_a = heappop(former_heap)
    former_sum += new_a - min_a
    former_sum_list.append(former_sum)

latter_sum = sum(latter_heap)
latter_sum_list = [latter_sum]
for k in range(N):
    new_a = - latter_A.pop()
    heappush(latter_heap, new_a)
    min_a = heappop(latter_heap)
    latter_sum += new_a - min_a
    latter_sum_list.append(latter_sum)
latter_sum_list.reverse()

answer = max([former + latter for former, latter in zip(former_sum_list, latter_sum_list)])
print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
tmp = list(map(int, input().split(' ')))
former_A = deque(tmp)
latter_A = deque(tmp.copy())
former_heap = list()
latter_heap = list()
for _ in range(N):
    former_heap.append(former_A.popleft())
    latter_heap.append(- latter_A.pop())
heapify(former_heap)
heapify(latter_heap)

former_sum = sum(former_heap)
former_sum_list = [former_sum]
for k in range(N):
    new_a = former_A.popleft()
    heappush(former_heap, new_a)
    min_a = heappop(former_heap)
    former_sum += new_a - min_a
    former_sum_list.append(former_sum)

latter_sum = sum(latter_heap)
latter_sum_list = [latter_sum]
for k in range(N):
    new_a = - latter_A.pop()
    heappush(latter_heap, new_a)
    min_a = heappop(latter_heap)
    latter_sum += new_a - min_a
    latter_sum_list.append(latter_sum)
latter_sum_list.reverse()

answer = max([former + latter for former, latter in zip(former_sum_list, latter_sum_list)])
print(answer)

Buggy submission (verdict: Runtime Error):
from collections import deque
from heapq import heapify, heappop, heappush
N = int(input())
A = deque(map(int, input().split(' ')))
former_heap = list()
latter_heap = list()
for _ in range(N):
    former_heap.append(A.popleft())
    latter_heap.append(- A.pop())
heapify(former_heap)
heapify(latter_heap)

former_sum = sum(former_heap)
former_sum_list = [former_sum]
former_A = A.copy()
for k in range(N):
    new_a = former_A.popleft()
    heappush(former_heap, new_a)
    min_a = heappop(former_heap)
    former_sum += new_a - min_a
    former_sum_list.append(former_sum)

latter_sum = sum(latter_heap)
latter_sum_list = [latter_sum]
latter_A = A.copy()
for k in range(N):
    new_a = - latter_A.pop()
    heappush(latter_heap, new_a)
    min_a = heappop(latter_heap)
    latter_sum += new_a - min_a
    latter_sum_list.append(latter_sum)
latter_sum_list.reverse()

answer = max([former + latter for former, latter in zip(former_sum_list, latter_sum_list)])
print(answer)
Problem p03828 (python)

Fixed submission:
N = int(input())
if N == 1:
    print(1)
    exit()
# calculate primes by sieve
primes = list(range(2, N + 1))
prime_index = 0
n = primes[prime_index]
while n**2 <= N:
    primes = list(filter(lambda x: x == n or x % n != 0, primes))
    prime_index += 1
    n = primes[prime_index]
# calculate exponents
exponents = [0 for _ in range(len(primes))]
for n in range(2, N + 1):
    for prime_index, prime in enumerate(primes):
        exponent = 0
        tmp = n
        while tmp % prime == 0:
            tmp //= prime
            exponent += 1
        exponents[prime_index] += exponent
# calculate answer
const = 10**9 + 7
answer = 1
for e in exponents:
    answer = answer * (e + 1)
    answer %= const
print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N == 1:
    print(1)
# calculate primes by sieve
primes = list(range(2, N + 1))
prime_index = 0
n = primes[prime_index]
while n**2 <= N:
    primes = list(filter(lambda x: x == n or x % n != 0, primes))
    prime_index += 1
    n = primes[prime_index]
# calculate exponents
exponents = [0 for _ in range(len(primes))]
for n in range(2, N + 1):
    for prime_index, prime in enumerate(primes):
        exponent = 0
        tmp = n
        while tmp % prime == 0:
            tmp //= prime
            exponent += 1
        exponents[prime_index] += exponent
# calculate answer
const = 10**9 + 7
answer = 1
for e in exponents:
    answer = answer * (e + 1)
    answer %= const
print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
# calculate primes by sieve
primes = list(range(2, N + 1))
prime_index = 0
n = primes[prime_index]
while n**2 <= N:
    primes = list(filter(lambda x: x == n or x % n != 0, primes))
    prime_index += 1
    n = primes[prime_index]
# calculate exponents
exponents = [0 for _ in range(len(primes))]
for n in range(2, N + 1):
    for prime_index, prime in enumerate(primes):
        exponent = 0
        tmp = n
        while tmp % prime == 0:
            tmp //= prime
            exponent += 1
        exponents[prime_index] += exponent
# calculate answer
const = 10**9 + 7
answer = 1
for e in exponents:
    answer = answer * (e + 1)
    answer %= const
print(answer)
Problem p04001 (python)

Fixed submission:
S = input()
N = len(S)
plus_flag = [0] * (N - 1)


def calc(flags):
    val = 0
    num_begin_index = 0
    num_end_index = None
    for flag_index in range(len(flags)):
        if flags[flag_index] == 0:
            continue
        num_end_index = flag_index + 1
        val += int(S[num_begin_index:num_end_index])
        num_begin_index = num_end_index
    num_end_index = len(flags) + 1
    val += int(S[num_begin_index:num_end_index])
    return val


def calc_sum(index, flag):
    plus_flag[index] = flag
    if index == len(plus_flag) - 1:
        return calc(plus_flag)
    return calc_sum(index + 1, 0) + calc_sum(index + 1, 1)


if N == 1:
    print(S)
else:
    print(calc_sum(0, 0) + calc_sum(0, 1))

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)
plus_flag = [0] * (N - 1)


def calc(flags):
    val = 0
    num_begin_index = 0
    num_end_index = None
    for flag_index in range(len(flags)):
        if flags[flag_index] == 0:
            continue
        num_end_index = flag_index + 1
        val += int(S[num_begin_index:num_end_index])
        num_begin_index = num_end_index
    num_end_index = len(flags) + 1
    val += int(S[num_begin_index:num_end_index])
    return val


def calc_sum(index, flag):
    plus_flag[index] = flag
    if index == len(plus_flag) - 1:
        return calc(plus_flag)
    return calc_sum(index + 1, 0) + calc_sum(index + 1, 1)


print(calc_sum(0, 0) + calc_sum(0, 1))
Problem p02556 (python)

Fixed submission:
n = int(input())
min1 = 10000000000
max1 = -10000000000
min2 = 10000000000
max2 = -10000000000

for _ in range(n):
    x, y = map(int,input().split())
    if x+y> max1:
        r1 = [x,y]
        max1 = x+y
    if x+y<min1:
        l1 = [x,y]
        min1 = x+y
    if x-y>max2:
        r2 = [x,y]
        max2 = x-y
    if x-y<min2:
        l2 = [x,y]
        min2 = x-y


#print(abs(l[0]-r[0]) + abs(r[1]-l[1]))
print(max(max1-min1,max2-min2))

Buggy submission (verdict: Runtime Error):
n = int(input())
min = 10000000000
max = -10000000000

for _ in range(n):
    x, y = map(int,input().split())
    if x+y < min:
        l = [x,y]
        min = x+y
    elif x+y > max:
        r = [x,y]
        max = x+y

print(abs(l[0]-r[0]) + abs(r[1]-l[1]))
Problem p02573 (python)

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

class unionfind():
    def __init__(self,n):
        self.li = [i for i in range(n+1)]
        self.group = [1]*(n+1)

    def find(self, x):
        while self.li[x]!=x:
            x = self.li[x]
        return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return;
        elif x>y:
            self.li[y] = x
            self.group[x] += self.group[y]
        else:
            self.li[x] = y
            self.group[y] += self.group[x]
x = unionfind(n)
ans = 0
for _ in range(m):
    a,b = map(int,input().split())
    x.union(a,b)
print(max(x.group))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
li = [0]*(n+1)
lii = []
flag = 1
for _ in range(m):
    a, b = map(int, input().split())
    if li[a] and li[b]:
        if li[a] != li[b]:
            lii.append(li[a],li[b])
    elif li[a] or li[b]:
        s = max(li[a],li[b])
        li[a] = s
        li[b] = s
    else:
        li[a] = flag
        li[b] = flag
        flag += 1
for i in range(len(li)):
    if li[i] == 0:
        li[i] = -i
    for j in lii:
        a,b = j
        if li[i] == a or li[i] == b:
            li[i] = a+b
from collections import Counter
result = Counter(li)
print(result.most_common(1)[0][1])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
li = [0]*(n+1)
flag = 1
for _ in range(m):
    a, b = map(int, input().split())
    if li[a] and li[b]:
        if li[a]!=li[b]:
            x = li[b]
            for i in len(li):
                if li[i]==x:
                    li[i] = li[a]
    elif li[a] or li[b]:
        s = max(li[a],li[b])
        li[a] = s
        li[b] = s
    else:
        li[a] = flag
        li[b] = flag
        flag += 1
for i in range(len(li)):
    if li[i] == 0:
        li[i] = -i
from collections import Counter
result = Counter(li)
print(result.most_common(1)[0][1])
Problem p02613 (python)

Fixed submission:
n = int(input())
li = [0]*4
for _ in range(n):
    s = input()
    if s == 'AC':
        li[0]+=1
    elif s == 'WA':
        li[1]+=1
    elif s == 'TLE':
        li[2]+=1
    elif s == 'RE':
        li[3]+=1
print('AC x ',li[0])
print('WA x ',li[1])
print('TLE x ',li[2])
print('RE x ',li[3])

Buggy submission (verdict: Runtime Error):
n = int(input())
li = [0]*4
for _ in n:
  s = input()
  if s == 'AC':
    li[0]+=1
  elif s == 'WA':
    li[1]+=1
  elif s == 'TLE':
    li[2]+=1
  elif s == 'RE':
    li[3]+=1
print('AC x ',li[0])
print('WA x ',li[1])
print('TLE x ',li[2])
print('RE x ',li[3])
Problem p02585 (python)

Fixed submission:
N, K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))
scores = []
for i in range(N):
  pos = P[i]-1
  s = [C[i]]
  j = 1
  while j < K and pos != i:
    s.append(s[-1]+C[pos])
    pos = P[pos]-1
    j += 1
  smax = max(s)
  length = len(s)
  if length < K and s[-1] > 0:
    if K%length != 0:
      smod = s[:K%length]
      smodmax = max(smod)
    else:
      smodmax = 0
    scores.append(max(s[-1] * ((K//length)-1) + smax, s[-1] * (K//length), s[-1] * (K//length) + smodmax))
  else:
    scores.append(smax)
print(max(scores))

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))
scores = []
for i in range(N):
  pos = P[i]-1
  s = [C[i]]
  j = 1
  while j < K and pos != i:
    s.append(s[-1]+C[pos])
    pos = P[pos]-1
    j += 1
  smax = max(s)
  length = len(s)
  if length < K and s[-1] > 0:
    smod = s[:K%length]
    smodmax = max(smod)
    scores.append(max(s[-1] * ((K//length)-1) + smax, s[-1] * (K//length), s[-1] * (K//length) + smodmax))
  else:
    scores.append(smax)
print(max(scores))

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))
scores = []
for i in range(N):
  pos = P[i]-1
  s = [C[i]]
  j = 1
  while j < K and pos != i:
    s.append(s[-1]+C[pos])
    pos = P[pos]-1
    j += 1
  smax = max(s)
  length = len(s)
  if length < K and s[-1] > 0:
    smod = s[:K%length]
    smodmax = max(smod)
    if smax == smodmax:
      scores.append(s[length-1] * (K//length) + smax)
    else:
      scores.append(max(s[length-1] * ((K//length)-1) + smax, s[length-1] * (K//length), s[length-1] * (K//length) + smodmax))
  else:
    scores.append(smax)
print(max(scores))
Problem p02618 (python)

Fixed submission:
D = int(input())
for i in range(D):
  print(i%26+1)

Buggy submission (verdict: Runtime Error):
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [0 for i in range(26)]
for i in range(1, D+1):
  inc = [s[i-1][j] - c[j]*(i-t[i-1])*(i+1-t[i-1])//2 for j in range(26)]
  max_index = inc.index(max(inc))
  t[max_index] = i
  print(max_index+1)

Buggy submission (verdict: Runtime Error):
for i in range(D):
  print(i%26+1)
Problem p02687 (python)

Fixed submission:
S = input()
if S == "ABC":
  print("ARC")
else:
  print("ABC")

Buggy submission (verdict: Runtime Error):
X = int(input())
c = 0
for a in range(-118, 119):
  for b in range(-118, 119):
    Y = a ** 5 - b ** 5
    if Y == X:
      A = a
      B = b
      print(A, B)
      c = 1
      break
    if c ==1:
      break