Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
S = list(input())
Q = int(input())

is_reversed = False
for _ in range(Q):
    token = input().split(' ')
    if len(token) == 1:
        is_reversed = ~is_reversed

    else:
        _, f, c = token
        f = int(f)
        if (f == 1 and is_reversed) or (f == 2 and not is_reversed):
            S.append(c)

        else:
        # elif (f == 1 and not is_reversed) or (f == 2 and is_reversed):
            S.insert(0, c)

if is_reversed:
    S.reverse()
    print(''.join(S))

else:
    print(''.join(S))



Fixed submission:
# -*- coding: utf-8 -*-
S = list(input())
Q = int(input())

lim = 10**5 *2
buf = [None for _ in range(lim)] + S + [None for _ in range(lim)]
forward_i, back_i = lim-1, lim + len(S) + 1
is_reversed = False
for _ in range(Q):
    token = input().split(' ')
    if len(token) == 1:
        is_reversed = ~is_reversed

    else:
        _, f, c = token
        f = int(f)
        if (f == 1 and is_reversed) or (f == 2 and not is_reversed):
            buf[back_i] = c
            back_i += 1
            # S.append(c)

        else:
        # elif (f == 1 and not is_reversed) or (f == 2 and is_reversed):
            buf[forward_i] = c
            forward_i -= 1
            # S.insert(0, c)

S = ''.join([b for b in buf if b is not None])
if is_reversed:
    print(''.join(reversed(list(S))))
    # S.reverse()
    # print(''.join(S))

else:
    print(S)
    # print(''.join(S))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math
N = int(input())
ans = 0
for i in range(int(math.log2(N))+1):
    ans += 2 ** i

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-
import math
N = int(input())
ans = 0
for i in range(int(math.log(N, 2))+1):
    ans += 2 ** i

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
H, N = map(int, input().split(' '))
nums = [float('inf') for _ in range(H+1)]
nums[0] = 0

for _ in range(N):
    a, b = map(int, input().split(' '))
    for i in range(H + 1):
        j = min(H, i+a)
        nums[j] = min(nums[j], nums[i] + b)

print(nums[H])

Fixed submission:
# -*- coding: utf-8 -*-
H, N = map(int, input().split(' '))

lim = float('inf')
powers = [lim for _ in range(H+1)]
powers[0] = 0

for _ in range(N):
    A, B = map(int, input().split(' '))
    for i in range(H):
        if powers[i] != lim:
            if i+A > H:
                powers[H] = min(powers[H], powers[i] + B)
            else:
                powers[i+A] = min(powers[i+A], powers[i] + B)


# print(powers)
print(powers[H])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N, D, A = map(int, input().split(' '))
X_H_pairs = [list(map(int, input().split(' '))) for _ in range(N)]

X_H_pairs.sort(key=lambda x: x[0])

import math
i, ans = 0, 0
while i < N:
    x, h = X_H_pairs[i]
    if h <= 0:
        i += 1
        continue
    else:
        times = int(math.ceil(h / A))
        ans += times

        dh = times * A
        dx = x + 2*D
        j = i
        while j < N and X_H_pairs[j][0] <= dx:
            X_H_pairs[j][1] -= dh
            j += 1
        i += 1

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-
N, D, A = map(int, input().split(' '))
X_H_pairs = [list(map(int, input().split(' '))) for _ in range(N)]

X_H_pairs.sort(key=lambda x: x[0])

import math
i, ans = 0, 0
powers = []
damage = 0
while i < N:
    x, h = X_H_pairs[i]
    if powers:
        while powers and x - powers[0][0] > 2*D:
            damage -= powers[0][1]
            powers.pop(0)

    h -= damage
    if h <= 0:
        i += 1
        continue
    else:
        times = int(math.ceil(h / A))
        ans += times

        dh = times * A
        damage += dh
        powers.append((x, dh))
        i += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N = int(input())

#
X, Y = [], []
for _ in range(N):
    x, y = map(int, input().split(' '))
    X.append(x)
    Y.append(y)

#
import collections
xy_frq_dict = collections.defaultdict(int)
for i in range(N):
    for j in range(N):
        if i == j:
            continue

        x, y = X[i] - X[j], Y[i] - Y[j]
        xy_frq_dict[(x, y)] += 1

xy_frq_pairs = list(xy_frq_dict.items())
xy_frq_pairs.sort(key=lambda x: x[1])
ret = N - xy_frq_pairs[-1][1]
print(ret)





Fixed submission:
# -*- coding: utf-8 -*-
N = int(input())

if N == 1:
    print(1)
    exit()

#
X, Y = [], []
for _ in range(N):
    x, y = map(int, input().split(' '))
    X.append(x)
    Y.append(y)

#
import collections
xy_frq_dict = collections.defaultdict(int)
for i in range(N):
    for j in range(N):
        if i == j:
            continue

        x, y = X[i] - X[j], Y[i] - Y[j]
        xy_frq_dict[(x, y)] += 1

xy_frq_pairs = list(xy_frq_dict.items())
xy_frq_pairs.sort(key=lambda x: x[1])
ret = N - xy_frq_pairs[-1][1]
print(ret)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split(' '))
dp = [0 for _ in range(N + 1)]
for _ in range(M):
    i = int(input())
    dp[i] = -float('inf')

dp[0] = 1
for i in range(N+1):
    if 0 <= i-1 < N and dp[i-1] != -float('inf'):
        dp[i] += dp[i-1]

    if 0 <= i-2 < N and dp[i-2] != -float('inf'):
        dp[i] += dp[i-2]

print(dp[N] % 1000000007 )

Fixed submission:
N, M = map(int, input().split(' '))
dp = [0 for _ in range(N + 1)]
for _ in range(M):
    i = int(input())
    dp[i] = -float('inf')

mod = 10**9 + 7
dp[0] = 1
for i in range(N+1):
    if dp[i] ==  -float('inf'):
        continue

    if 0 <= i-1 < N and dp[i-1] != -float('inf'):
        dp[i] += dp[i-1]

    if 0 <= i-2 < N and dp[i-2] != -float('inf'):
        dp[i] += dp[i-2]

    dp[i] = dp[i] % mod

print(dp[N] )
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = list(map(lambda x: int(x), input().split(' ')))
S = input()

for _ in range(Q):
    l, r = list(map(lambda x: int(x), input().split(' ')))
    l -=1
    r -=1
    ans = 0
    for i in range(l, r):
        # print(S[i:i+2])
        if S[i:i+2] == 'AC':
            ans += 1

    # print(S[l:r+1])
    print(ans)
    # exit()

Fixed submission:
N, Q = list(map(lambda x: int(x), input().split(' ')))
S = input()

#
buf = [0 for _ in range(N)]
prev = 0
for i in range(N-1):
    if S[i:i+2] == 'AC':
        buf[i+1] = prev + 1
    else:
        buf[i+1] = prev

    prev = buf[i+1]

# print(buf)

for _ in range(Q):
    l, r = list(map(lambda x: int(x), input().split(' ')))
    l -=1
    r -=1
    ans = buf[r] - buf[l]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
A, B = map(int, input().split(' '))
ans = B
for n in range(A, B):
    ans ^= n

print(ans)


Fixed submission:
# -*- coding: utf-8 -*-
A, B = map(int, input().split(' '))
# A, B = 2, 4

if A % 2 == 0:
    n = (B - A) // 2
    b = 2 * n + A

    ans = 0 if n % 2 == 0 else 1
    for i in range(b, B+1):
        ans ^= i

    # print(b)
    # print(n)
    print(ans)
else:
    a = A
    A += 1

    n = (B - A) // 2
    b = 2 * n + A

    ans = 0 if n % 2 == 0 else 1
    ans ^= a
    for i in range(b, B+1):
        ans ^= i

    # print(b)
    # print(n)
    print(ans)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
H, W = map(int, input().split(' '))
table = [list(map(int, input().split(' '))) for _ in range(H)]

def get_next():
    for h in range(H):
        if h % 2:
            for w in range(W-1, -1, -1):
                yield h, w
        else:
            for w in range(W):
                yield h, w


ret = []
prv_h, prv_w = -1, -1
for h, w in get_next():
    if prv_h >= 0 and prv_w >= 0:
        if table[prv_h][prv_w] % 2:
            ret.append(prv_h, prv_w, h, w)

    prv_h, prv_w = h, w


print(len(ret))
for prv_h, prv_w, h, w in ret:
    print(prv_h + 1, prv_w + 1, h + 1, w + 1)






Fixed submission:
# -*- coding: utf-8 -*-
H, W = map(int, input().split(' '))
table = [list(map(int, input().split(' '))) for _ in range(H)]

def get_next():
    for h in range(H):
        if h % 2:
            for w in range(W-1, -1, -1):
                yield h, w
        else:
            for w in range(W):
                yield h, w


ret = []
routes = list(get_next())
prv_h, prv_w = routes[0]
for h, w in routes[1:]:
    if table[prv_h][prv_w] % 2:
        ret.append((prv_h, prv_w, h, w))
        table[h][w] += 1

    prv_h, prv_w = h, w


print(len(ret))
for prv_h, prv_w, h, w in ret:
    print(prv_h + 1, prv_w + 1, h + 1, w + 1)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N, M = map(int, input().split(' '))
graph = [[] for _ in range(N)]
for i in range(M):
    l, r, d = map(int, input().split(' '))
    l -= 1
    r -= 1
    graph[l].append((r, d))
    graph[r].append((l, -d))

dsts = [float('inf') for _ in range(N)]

for n in range(N):
    if dsts[n] != float('inf'):
        continue

    buf = [n]
    dsts[n] = 0
    while buf:
        src = buf.pop(0)
        for dst, d, in graph[src]:
            next_d = dsts[src] + d

            if dsts[dst] == float('inf'):
                dsts[dst] = next_d
                buf.append(dst)

            elif dsts[dst]  != next_d:
                # print(dsts)
                # print(dst, src, dsts[dst], dsts[src], d, next_d)
                print("No")
                exit()

print("Yes")




Fixed submission:
# -*- coding: utf-8 -*-
from collections import deque
N, M = map(int, input().split(' '))
graph = [[] for _ in range(N)]
for i in range(M):
    l, r, d = map(int, input().split(' '))
    l -= 1
    r -= 1
    graph[l].append((r, d))
    graph[r].append((l, -d))

dsts = [float('inf') for _ in range(N)]

for n in range(N):
    if dsts[n] != float('inf'):
        continue

    buf = deque()
    buf.append(n)
    dsts[n] = 0
    while buf:
        src = buf.popleft()
        for dst, d, in graph[src]:
            next_d = dsts[src] + d

            if dsts[dst] == float('inf'):
                dsts[dst] = next_d
                buf.append(dst)

            elif dsts[dst]  != next_d:
                # print(dsts)
                # print(dst, src, dsts[dst], dsts[src], d, next_d)
                print("No")
                exit()

print("Yes")
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
S = input()

#
can_solve = True
m = [s for s in S if s != 'x']
len_m = len(m)
for i in range(len_m):
    if m[i] != m[len_m - i - 1]:
        can_solve = False
        break

#
if can_solve:
    nums = [0 for _ in range(len_m+1)]
    i, n = 0, 0
    for s in S:
        if s == 'x':
            n += 1
        else:
            nums[i] = n
            i += 1
            n = 0
    nums[i] = n

    len_nums = len_m+1
    ans = 0
    for i in range(len_nums // 2):
        ans += max(nums[i], nums[len_nums - i - 1])
    if len_nums % 2 == 1:
        ans += nums[len_nums // 2 + 1] % 2
    # print(nums)
    print(ans)


else:
    print(-1)





Fixed submission:
# -*- coding: utf-8 -*-
S = input()
ans = 0
left, right = 0, len(S)-1
while left < right:
    if S[left] == S[right]:
        left += 1
        right -= 1
    elif S[left] == 'x':
        left += 1
        ans += 1
    elif S[right] == 'x':
        right -= 1
        ans += 1
    else:
        print(-1)
        exit()

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N, K = map(int, input().split(' '))
points = [list(map(int, input().split(' '))) for i in range(N)]

X = list(set([x for x, y in points]))
Y = list(set([y for x, y in points]))


ans = float('inf')
import itertools
all_indices = list(range(N))
for part_x in itertools.combinations(X, 2):
    for part_y in itertools.combinations(Y, 2):
        max_x = max(part_x)
        min_x = min(part_x)
        max_y = max(part_y)
        min_y = min(part_y)

        m = (max_x - min_x) * (max_y - min_y)
        internal_points = [(x, y) for x, y in points if min_x <= x <= max_x and min_y <= y <= max_y]
        if len(internal_points) >= K:
            ans = min(ans, m)

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-
N, K = map(int, input().split(' '))
points = [list(map(int, input().split(' '))) for i in range(N)]

X = list(set([x for x, y in points]))
Y = list(set([y for x, y in points]))

X.sort()
Y.sort()

ans = float('inf')
for i, min_x in enumerate(X):
    for max_x in X[i+1:]:
        for j, min_y in enumerate(Y):
            for max_y in Y[j + 1:]:
                m = (max_x - min_x) * (max_y - min_y)
                internal_points = [(x, y) for x, y in points if min_x <= x <= max_x and min_y <= y <= max_y]
                if len(internal_points) >= K:
                    ans = min(ans, m)

print(ans)
Buggy python submission (verdict: Runtime Error):
import collections

graph = collections.defaultdict(list)

N = int(input())
for i in range(N-1):
    # print(i)
    a, b, c = map(int, input().split(' '))
    a -= 1
    b -= 1
    graph[a].append([b, c])
    graph[b].append([a, c])


Q, K = map(int, input().split(' '))

dist = [-1 for _ in range(N)]
dist[K-1] = 0

def dfs(a):
    for b, c in graph[a]:
        if dist[b] == -1:
            dist[b] = dist[a] + c
            dfs(b)
dfs(K-1)
# print(dist)


for _ in range(Q):
    x, y = map(int, input().split(' '))
    x -= 1
    y -= 1
    print(dist[x] + dist[y])

Fixed submission:
# -*- coding: utf-8 -*-

import collections


N = int(input())
graph = [[] for _ in range(N)]
# graph = collections.defaultdict(list)

for i in range(N-1):
    # print(i)
    a, b, c = map(int, input().split(' '))
    a -= 1
    b -= 1
    graph[a].append([b, c])
    graph[b].append([a, c])


Q, K = map(int, input().split(' '))

dist = [-1 for _ in range(N)]
dist[K-1] = 0
stack = [K-1]
while len(stack) != 0:
    a = stack.pop()
    for b, c in graph[a]:
        if dist[b] == -1:
            dist[b] = dist[a] + c
            stack.append(b)


# def dfs(a):
#     for b, c in graph[a]:
#         if dist[b] == -1:
#             dist[b] = dist[a] + c
#             dfs(b)
# dfs(K-1)
# print(dist)


for _ in range(Q):
    x, y = map(int, input().split(' '))
    x -= 1
    y -= 1
    print(dist[x] + dist[y])
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
S = list(input())
K = int(input())

for i in range(len(S)-1):
    if S[i] == 'a':
        continue

    d = ord('z') - ord(S[i]) + 1
    if K >= d:
        S[i] = 'a'
        K -= d
    # print(K, d)

if K > 0:
    j = ord(S[-1]) + K
    S[-1] = chr(j)

print(''.join(S))

Fixed submission:
# -*- coding: utf-8 -*-
S = list(input())
K = int(input())

for i in range(len(S)):
    if S[i] == 'a':
        continue

    d = ord('z') - ord(S[i]) + 1
    if K >= d:
        S[i] = 'a'
        K -= d
    # print(K, d)

if K > 0:
    j = ord(S[-1]) + K % 26
    S[-1] = chr(j)

print(''.join(S))

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
S = list(input())
K = int(input())

for i in range(len(S)):
    d = ord('z') - ord(S[i]) + 1
    if K >= d:
        S[i] = 'a'
        K -= d
    # print(K, d)

if K > 0:
    j = ord(S[-1]) + K
    S[-1] = chr(j)

print(''.join(S))

Fixed submission:
# -*- coding: utf-8 -*-
S = list(input())
K = int(input())

for i in range(len(S)):
    if S[i] == 'a':
        continue

    d = ord('z') - ord(S[i]) + 1
    if K >= d:
        S[i] = 'a'
        K -= d
    # print(K, d)

if K > 0:
    j = ord(S[-1]) + K % 26
    S[-1] = chr(j)

print(''.join(S))
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
len_size = len(S)

queue = []
cnt = 0

for i in range(len_size):

	# キューの更新
	for j in range(len(queue)):
		queue[j] += S[i]

		# 2019で割れるかチェック
		tmp_val = int(queue[j])
		if(tmp_val % 2019 == 0):
			cnt += 1
			queue[j] = ""

	queue.append(S[i])	

print(cnt)

Fixed submission:
M = 2019

S = list(input())
s_size = len(S)

S.reverse()
x = 1
tot = 0
ans = 0

cnt_list = [0 for i in range(M)]

for i in range(s_size):
	cnt_list[tot] += 1
	tot += (ord(S[i])-ord('0'))*x
	tot %= M
	ans += cnt_list[tot]
	x = x*10%M

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
len_size = len(S)

queue = []
cnt = 0

for i in range(len_size):

	# キューの更新
	for j in range(len(queue)):
		queue[j] += S[i]
	queue.append(S[i])

	# 2019で割れるかチェック
	for j in range(len(queue)):
		tmp_val = int(queue[j])
		if(tmp_val % 2019 == 0):
			cnt += 1
			queue[j] = ""

print(cnt)

Fixed submission:
M = 2019

S = list(input())
s_size = len(S)

S.reverse()
x = 1
tot = 0
ans = 0

cnt_list = [0 for i in range(M)]

for i in range(s_size):
	cnt_list[tot] += 1
	tot += (ord(S[i])-ord('0'))*x
	tot %= M
	ans += cnt_list[tot]
	x = x*10%M

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# N=総数、A=青、B=赤
N, A, B = map(int, input().split())

# 残りボールのカウント
a_r_bal = A
b_r_bal = B
# セットしたボールのカウント
a_s_bal = 0
b_s_bal = 0
for i in range(N):
    # a,bのボールなし
    if(a_r_bal == 0 and b_r_bal == 0):
        a_r_bal = A
        b_r_bal = B

    # aの残りボールあり
    if(a_r_bal > 0):
        a_r_bal -= 1
        a_s_bal += 1
    else:
        b_r_bal -= 1
        b_s_bal += 1
# 出力
print(a_s_bal)

Fixed submission:
# N=総数、A=青、B=赤
N, A, B = map(int, input().split())

# A+Bの商
n = N // (A+B)
# A+Bのあまり
r = N % (A+B)

# A+BのあまりがAより大きい場合は、Aとする
if(r > A):
    b_r = A
else:
    b_r = r

# 青の個数 = 商*A + あまり(0~A)
blue = n * A + b_r

print(blue)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
input_v_list = list(map(int, input().split()))

cnt = 0             # 出力の個数
check_list = []     # 比較用リスト

# 比較用リストに一つずつ値をセット
for i in input_v_list:
    check_list.append(i)
    min_var = min(check_list)
    # i <= min のとき個数をカウント
    if(i <= min_var):
        cnt += 1

# 出力
print(cnt)

Fixed submission:
N = int(input())
input_v_list = list(map(int, input().split()))

cnt = 0             # 出力の個数
min_var = 2 * 10**6 # 最小値(初期値2*10^5以上)

# 比較用リストに一つずつ値をセット
for i in input_v_list:
    
    # 最小値更新
    if(min_var > i):
        min_var = i

    # i <= min のとき個数をカウント
    if(i <= min_var):
        cnt += 1

# 出力
print(cnt)
Buggy python submission (verdict: Runtime Error):
import numpy as np
X, N = map(int, input().split())
P = list(map(int, input().split()))
candidate = list(range(1, 101))
P = sorted(set(candidate).difference(set(P)))
i = np.argmin([abs(p - X) for p in P])
print(P[i])


Fixed submission:
import numpy as np
X, N = map(int, input().split())
P = list(map(int, input().split()))
candidate = list([x - 500 for x in range(1, 1000)])
P = sorted(set(candidate).difference(set(P)))
i = np.argmin([abs(p - X) for p in P])
print(P[i])

Buggy python submission (verdict: Runtime Error):
import numpy as np
X, N = map(int, input().split())
P = list(map(int, input().split()))
candidate = list(range(1, 101))
P = sorted(set(candidate).difference(set(P)))
i = np.argmin([abs(p - X) for p in P])
print(P[i])


Fixed submission:
import numpy as np
X, N = map(int, input().split())
P = list(map(int, input().split()))
candidate = list([x - 500 for x in range(1, 1000)])
P = sorted(set(candidate).difference(set(P)))
i = np.argmin([abs(p - X) for p in P])
print(P[i])
Buggy python submission (verdict: Time Limit Exceeded):
from math import pow
from itertools import combinations
x = int(input())

def prime_factorize(n):
    a = [1]
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def func(a, b):
    return pow(a, 5) - pow(b,5)
    
cands = prime_factorize(x)
ok = False

for i in range(2 ** len(cands)):
    y = 1
    for j in range(len(cands)):        
        if (i >> j) & 1:
            y *= cands[j]
        for a in range(1, y + 1):
            b = a - y
            if func(a, b) == x:
                print(a, b)
                ok = True
                break
        if ok:
            break
    if ok:
        break
        

Fixed submission:
from math import pow
from itertools import combinations
x = int(input())

def func(a, b):
    return pow(a, 5) - pow(b,5)

ok = False
for a in range(-200, 200):
    for b in range(-200, 200):
        if func(a, b) == x:
            print(a, b)
            ok = True
            break
    if ok:
        break

Buggy python submission (verdict: Time Limit Exceeded):
from math import pow
from itertools import combinations
x = int(input())

def prime_factorize(n):
    a = [1]
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def func(a, b):
    return pow(a, 5) - pow(b,5)
    
cands = prime_factorize(x) + [1]
ok = False

for i in range(1, len(cands)):
    for c in combinations(cands, i):    
        y = 1
        for j in c:
            y *= j
        for a in range(1, y + 1):
            b = a - y
            if func(a,b) == x:
                print(a, b)
                ok = True
                break
        if ok:
            break
    if ok:
        break

Fixed submission:
from math import pow
from itertools import combinations
x = int(input())

def func(a, b):
    return pow(a, 5) - pow(b,5)

ok = False
for a in range(-200, 200):
    for b in range(-200, 200):
        if func(a, b) == x:
            print(a, b)
            ok = True
            break
    if ok:
        break
Buggy python submission (verdict: Time Limit Exceeded):
import math
a, b, n = map(int, input().split())

n = min(n, b)


mem = {}
m = 0
for x in range(1, n + 1):
    if mem.get(((a * x) % b, x % b)) is not None:
        break    
    else:
        c = math.floor(a * x / b) - a * math.floor(x / b)
        mem[((a * x) % b, x % b)] = 1
        m = max(m, c)
print(m)


Fixed submission:
import math
a, b, n = map(int, input().split())

n = min(n, b-1)

print(math.floor(a * n / b) - a * math.floor(n / b))

Buggy python submission (verdict: Time Limit Exceeded):
import math
a, b, n = map(int, input().split())
n = min(n, b)
mem = {}
for x in range(1, n + 1):
    if mem.get(((a * x) % b, x % b)) is not None:
        break    
    else:
        mem[((a * x) % b, x % b)] = math.floor(a * x / b) - a * math.floor(x / b)
print(max(mem.values()))


Fixed submission:
import math
a, b, n = map(int, input().split())

n = min(n, b-1)

print(math.floor(a * n / b) - a * math.floor(n / b))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

ans = 0
for i in range(N-2):
    for j in range(i, N-1):
        for k in range(j, N):
            if len({S[i], S[j], S[k]}) == 3:
                if (j - i) != (k - j):
                    ans += 1                

print(ans)

Fixed submission:
N = int(input())
S = list(input())

smap = {
    'R': 0,
    'G': 1,
    'B': 2,
}

def get_t(a, b):
    a, b = smap[a], smap[b]
    if a + b == 1:
        return 2
    elif a + b == 3:
        return 0
    else:
        return 1

d = [[0 for _ in range(3)] for _ in range(N)]

for i in range(N):
    for j in range(N):
        if i < j:
            s = S[j]
            d[i][smap[s]] += 1

ans = 0
for j in range(1, N-1):
    c = S[j]
    for i in range(0, j):        
        l = S[i]
        if c == l:
            continue
        t = get_t(c, l)
            
        if j + j - i < N and smap[S[j + (j - i)]] == t:
            ans -= 1
        ans += d[j][t]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

balls = Counter(A)
for i in range(N):
    # 除外
    balls[A[i]] -= 1

    # 2個以上のペア
    s = 0
    for k, v in balls.most_common():        
        if v >= 2:
            s += v * (v - 1) // 2
    print(s)
    balls[A[i]] += 1

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

balls = Counter(A)
s = 0
for k, v in balls.most_common():        
    if v >= 2:
        s += v * (v - 1) // 2

for i in range(N):
    c = balls[A[i]]
    d = (c * (c - 1) / 2) - ((c - 1) * (c - 2) / 2)
    print(int(s-d))