Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# 後だし

import collections

H, W = map(int, input().split())
C = tuple((int(x)-1 for x in input().split()))
D = tuple((int(x)-1 for x in input().split()))
S = list()
for _ in range(H):
    S.append(list(input()))

queue = collections.deque()
visited = collections.deque()
queue.append(C)
cy, cx = C
S[cy][cx] = 0

while len(queue):
    while len(queue):
        y, x = queue.popleft()
        visited.append((y, x))
        cost = S[y][x]
        for i, j in [(y-1, x), (y+1, x), (y, x-1), (y, x+1)]:
            if not (0 <= i < H and 0 <= j < W):
                continue
            if S[i][j] == '.':
                S[i][j] = cost
                queue.append((i, j))

    while len(visited):
        y, x = visited.popleft()
        cost = S[y][x]
        for i in range(y-2, y+2+1):
            for j in range(x-2, x+2+1):
                if not (0 <= i < H and 0 <= j < W):
                    continue
                if S[i][j] == '.':
                    S[i][j] = cost+1
                    queue.append((i, j))

dy, dx = D
result = S[dy][dx]
if result == '.':
    print(-1)
else:
    print(result)


Fixed submission:
# 後だし

import collections

H, W = map(int, input().split())
C = tuple((int(x)-1 for x in input().split()))
D = tuple((int(x)-1 for x in input().split()))
S = list()
for _ in range(H):
    S.append(list(input()))

queue = collections.deque()
visited = collections.deque()
queue.append(C)
cy, cx = C
S[cy][cx] = 0

while len(queue):
    while len(queue):
        y, x = queue.popleft()
        visited.append((y, x))
        cost = S[y][x]
        for i, j in [(y-1, x), (y+1, x), (y, x-1), (y, x+1)]:
            if not (0 <= i < H and 0 <= j < W):
                continue
            if S[i][j] == '.':
                S[i][j] = cost
                queue.append((i, j))

    while len(visited):
        y, x = visited.popleft()
        cost = S[y][x]
        for i in range(y-2, y+2+1):
            for j in range(x-2, x+2+1):
                if not (0 <= i < H and 0 <= j < W):
                    continue
                if S[i][j] == '.':
                    S[i][j] = cost+1
                    queue.append((i, j))

dy, dx = D
result = S[dy][dx]
if result == '.':
    print(-1)
else:
    print(result)
Buggy python submission (verdict: Time Limit Exceeded):
X, K, D = map(int, input().split())

x = abs(X)
k = K
while x > 0 and k > 0:
    x -= D
    k -= 1

if k % 2 == 1:
    x += D

print(abs(x))


Fixed submission:
X, K, D = map(int, input().split())

x = abs(X)
k = K

xd = min(x // D + 1, K)
x -= D * xd
k -= xd

if k % 2 == 1:
    x += D

print(abs(x))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = list()
B = list()
for _ in range(M):
    a, b = map(int, input().split())
    A.append(a-1)
    B.append(b-1)

nice_count = 0
for tenbodai in range(N):
    for michi in range(M):
        if tenbodai in (A[michi], B[michi]):
            another_tenbodai = A[michi] if tenbodai == B[michi] else B[michi]
            if H[another_tenbodai] >= H[tenbodai]:
                break
    else:
        nice_count += 1

print(nice_count)


Fixed submission:
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = list()
B = list()
for _ in range(M):
    a, b = map(int, input().split())
    A.append(a-1)
    B.append(b-1)

kyuryo = [set() for _ in range(N)]
for michi in range(M):
    kyuryo[A[michi]].add(B[michi])
    kyuryo[B[michi]].add(A[michi])

nice_count = 0
for tenbodai in range(N):
    for neighbor in kyuryo[tenbodai]:
        if H[neighbor] >= H[tenbodai]:
            break
    else:
        nice_count += 1

print(nice_count)
Buggy python submission (verdict: Time Limit Exceeded):
import math

a, b, n = map(int, input().split())

max = -1
for x in range(n+1):
    value = math.floor(a * x / b) - a * math.floor(x / b)
    if value > max:
        max = value

print(max)


Fixed submission:
import math

a, b, n = map(int, input().split())

x = b - 1
if x > n:
    x = n

result = math.floor(a * x / b) - a * math.floor(x / b)
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = map(int, input().split())

a = list(a)
for i in range(n):
    count = 0
    for j in range(i, n - 1):
        if a[j] == i + 1:
            count += 1
    print(count)


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

a = list(a)
result = [0] * n
for i in range(n - 1):
    result[a[i] - 1] += 1

print(*result, sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = map(int, input().split())

a = list(a)
for i in range(n):
    print(a.count(i + 1))


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

a = list(a)
result = [0] * n
for i in range(n - 1):
    result[a[i] - 1] += 1

print(*result, sep='\n')
Buggy python submission (verdict: Runtime Error):
n, m = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

a.sort()
a.reverse()
print('Yes' if (a[m] >= (sum(a) / (4 * m))) else 'No')


Fixed submission:
n, m = [int(x) for x in input().split()]
a_list = [int(x) for x in input().split()]

a_sum = sum(a_list)
a_list.sort()
a_list.reverse()
for i in range(m):
    a = a_list[i]
    if a < a_sum / (4 * m):
        print('No')
        exit()
else:
    print('Yes')
Buggy python submission (verdict: Runtime Error):
import math
import sympy
# sympy.divisors(10**9)

n = int(input())

# count = 0
# for i in range(1, n):
#     count = count + math.ceil(len(sympy.divisors(i)))
#     # print(math.ceil(len(sympy.divisors(i))))
# print(count)

count = 0
for a in range(1, n - 1):
    if n % a != 0:
        b = n // a
    else:
        b = n // a - 1
    if a <= b:
        count = (count + b)
    else:
        count = (count + b)
    # print(count)

print(count + 1)

Fixed submission:
# import math
# import sympy
# sympy.divisors(10**9)

n = int(input())

# count = 0
# for i in range(1, n):
#     count = count + math.ceil(len(sympy.divisors(i)))
#     # print(math.ceil(len(sympy.divisors(i))))
# print(count)

count = 0
for a in range(1, n - 1):
    if n % a != 0:
        b = n // a
    else:
        b = n // a - 1
    if a <= b:
        count = (count + b)
    else:
        count = (count + b)
    # print(count)

print(count + 1)
Buggy python submission (verdict: Time Limit Exceeded):
n, x, m = list(map(int, input().split()))

count = 0

# table2jou = []
# for mi in range(m + 1):
#     table2jou.append(pow(mi, 2))

# tablef = []
# for mi in range(m + 1):
#     # tablef.append(table2jou[mi] % m)
#     tablef.append(pow(mi, 2, m))


count = x
pre_an = x
his = [x]
for ni in range(2, n + 1):
    # an = tablef[pre_an]
    an = pow(pre_an, 2, m)
    if an in his:
        leftnum = n - ni + 1
        start = his.index(an)
        end = leftnum % (len(his) - start) + start
        loopnum = leftnum // (len(his) - start)
        count = count + sum(his[start: end])
        count = count + sum(his[start:]) * loopnum
        break
    his.append(an)
    count = count + an
    pre_an = an

print(count)


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

count = 0

# table2jou = []
# for mi in range(m + 1):
#     table2jou.append(pow(mi, 2))

# tablef = []
# for mi in range(m + 1):
#     # tablef.append(table2jou[mi] % m)
#     tablef.append(pow(mi, 2, m))

is_used = [0] * (m + 1)

count = x
pre_an = x
his = [x]
for ni in range(2, n + 1):
    # an = tablef[pre_an]
    an = pow(pre_an, 2, m)
    if is_used[an] == 1:
        leftnum = n - ni + 1
        start = his.index(an)
        end = leftnum % (len(his) - start) + start
        loopnum = leftnum // (len(his) - start)
        count = count + sum(his[start: end])
        count = count + sum(his[start:]) * loopnum
        break
    his.append(an)
    is_used[an] = 1
    count = count + an
    pre_an = an

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n, x, m = list(map(int, input().split()))

count = 0

# table2jou = []
# for mi in range(m + 1):
#     table2jou.append(pow(mi, 2))

tablef = []
for mi in range(m + 1):
    # tablef.append(table2jou[mi] % m)
    tablef.append(pow(mi, 2, m))


count = x
pre_an = x
his = [x]
for ni in range(2, n + 1):
    an = tablef[pre_an]
    if an in his:
        leftnum = n - ni + 1
        start = his.index(an)
        end = leftnum % (len(his) - start) + start
        loopnum = leftnum // (len(his) - start)
        count = count + sum(his[start: end])
        count = count + sum(his[start:]) * loopnum
        break
    his.append(an)
    count = count + an
    pre_an = an

print(count)


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

count = 0

# table2jou = []
# for mi in range(m + 1):
#     table2jou.append(pow(mi, 2))

# tablef = []
# for mi in range(m + 1):
#     # tablef.append(table2jou[mi] % m)
#     tablef.append(pow(mi, 2, m))

is_used = [0] * (m + 1)

count = x
pre_an = x
his = [x]
for ni in range(2, n + 1):
    # an = tablef[pre_an]
    an = pow(pre_an, 2, m)
    if is_used[an] == 1:
        leftnum = n - ni + 1
        start = his.index(an)
        end = leftnum % (len(his) - start) + start
        loopnum = leftnum // (len(his) - start)
        count = count + sum(his[start: end])
        count = count + sum(his[start:]) * loopnum
        break
    his.append(an)
    is_used[an] = 1
    count = count + an
    pre_an = an

print(count)
Buggy python submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))
am = []
bm = []
for _ in range(m):
    a, b = list(map(int, input().split()))
    am.append(a)
    bm.append(b)

groups = []
for ai, bi in zip(am, bm):
    ag = None
    bg = None
    for g, group in enumerate(groups):
        if ai in group:
            ag = g
        if bi in group:
            bg = g
    if ag is None:
        if bg is None:
            groups.append([ai, bi])
        else:
            groups[bg].append(ai)
    else:
        if bg is None:
            groups[ag].append(bi)
        else:
            if ag != bg:
                groups[ag].extend(groups[bg])
                del groups[bg]

# max_gr_len = 1
# for group in groups:
#     if max_gr_len < len(group):
#         max_gr_len = len(group)
max_gr_len = max([len(group) for group in groups] + [1])

print(max_gr_len)


Fixed submission:
D, T, S = list(map(int, input().split()))


if S * T >= D:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
# coding: -*- utf-8 -*-

in_str = input()
a, b = in_str.split(" ")
if a*b % 2 == 0:
    print("Even")
else:
    print("Odd")

Fixed submission:
# coding: utf-8
in_str = input()
a, b = in_str.split(" ")
a = int(a)
b = int(b)

if a*b % 2 == 0:
    print("Even")
else:
    print("Odd")
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import math
n = int(input())
t = 0
x = 0
y = 0
# txy = []
# for i in range(n):
#     ti, xi, yi = list(map(int, input().split()))
#     txy.append((ti, xi, yi))

for ti, xi, yi in map(int, input().split()):
    if abs(xi - x) + abs(yi - y) > abs(ti - t):
        print("No")
        exit()
    elif (abs(xi - x) + abs(yi - y) - abs(ti - t)) % 2 != 0:
        print("No")
        exit()
    else:
        t = ti
        x = xi
        y = yi
print("Yes")


Fixed submission:
# coding: utf-8
import math
n = int(input())
t = 0
x = 0
y = 0
txy = []
for i in range(n):
    ti, xi, yi = list(map(int, input().split()))
    txy.append((ti, xi, yi))

for ti, xi, yi in txy:
    if abs(xi - x) + abs(yi - y) > abs(ti - t):
        print("No")
        exit()
    elif (abs(xi - x) + abs(yi - y) - abs(ti - t)) % 2 != 0:
        print("No")
        exit()
    else:
        t = ti
        x = xi
        y = yi
print("Yes")
Buggy python submission (verdict: Runtime Error):

N=15
input=input()

masu=[int(r) for r in input.split()]
ans=[]

for i in range(1,N+1,2):

    if masu[i-1]%2==1 and i%2==1:
        ans.append(i)

print(len(ans))

Fixed submission:
N=int(input())
#N=17



input=input()
#input="13 76 46 15 50 98 93 77 31 43 84 90 6 24 14 0 1"
masu=[int(r) for r in input.split()]
ans=[]

for i in range(1,N+1,2):

    if masu[i-1]%2==1:
        ans.append(i)

print(len(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N,K=list(map(int,input().split()))
hcost=list(map(int,input().split()))
hcost=[0]+hcost
dp=[0]*(N+1)
tmp=range(K+1)

for i in range(2,N+1):
  dp[i]=dp[i-1]+abs(hcost[i-1]-hcost[i])
  for k in tmp:
    if i-k > 0:
      dp[i]=min(dp[i],dp[i-k]+abs(hcost[i-k]-hcost[i]))
print(dp[N])      

Fixed submission:
N,K= list(map(int,input().split()))
hc=list(map(int,input().split()))
dp=[0]*N
for i in range(1,N):
  li=[abs(hc[i]-hc[j])+dp[j] for j in range( max(i-K,0),i) ]
  dp[i]=min(li)
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K=list(map(int,input().split()))
hcost=list(map(int,input().split()))
hcost=[0]+hcost
dp=[0]*(N+1)

for i in range(2,N+1):
  dp[i]=dp[i-1]+abs(hcost[i-1]-hcost[i])
  for k in range(K+1):
    if i-k > 0:
      dp[i]=min(dp[i],dp[i-k]+abs(hcost[i-k]-hcost[i]))
print(dp[N])      

Fixed submission:
N,K= list(map(int,input().split()))
hc=list(map(int,input().split()))
dp=[0]*N
for i in range(1,N):
  li=[abs(hc[i]-hc[j])+dp[j] for j in range( max(i-K,0),i) ]
  dp[i]=min(li)
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def ment(dp,hcost,i,K):
  K=min(i,K)
  ret=sys.maxsize
  for k in range(1,K+1):
    cost=dp[i-k]+abs(hcost[i-k]-hcost[i])
    ret=min(ret,cost)
    #print(cost)
  return ret                               
                                 

N,K=list(map(int,input().split()))
hcost=list(map(int,input().split()))
dp=[0]*(N)
#dp[1]=abs(hcost[1]-hcost[0])

for i in range(1,N):
  #dp[i]=min(dp[i-2]+abs(hcost[i-2]-hcost[i]),dp[i-1]+abs(hcost[i-1]-hcost[i]))
  dp[i]=ment(dp,hcost,i,K)
  
print(dp[N-1])
#print(dp)

Fixed submission:
N,K= list(map(int,input().split()))
hc=list(map(int,input().split()))
dp=[0]*N
for i in range(1,N):
  li=[abs(hc[i]-hc[j])+dp[j] for j in range( max(i-K,0),i) ]
  dp[i]=min(li)
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())

A = list(map(int, input().split()))

A.sort(reverse=True)
ans = A.pop(0)
N -= 2

while N > 0:
    if N >= 2:
        ans += A.pop(0)*2
        N -= 2
    else:
        ans += A.pop(0)
        N -= 1

print(ans)

Fixed submission:

N = int(input())

A = list(map(int, input().split()))

A.sort(reverse=True)
ans = A.pop(0)
N -= 2
n = N//2
if N % 2 == 0:
    ans += 2 * sum(A[:n])
else:
    ans += 2 * sum(A[:n])
    ans += A[n]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

A = list(map(int, input().split()))

now = 1

d = []

while True:
    if A[now-1] in d:
        i = d.index(A[now-1])
        check = d[i:]
        break
    d.append(A[now-1])
    now = A[now-1]

    if len(d) >= K:
        break

if K <= len(d):
    print(d[K-1])
else:
    K -= (len(d)-len(check))
    K = K % len(check)
    print(check[K-1])



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

A = list(map(int, input().split()))

now = 1

d = []
set_d = set()

while True:
    if A[now-1] in set_d:
        i = d.index(A[now-1])
        check = d[i:]
        break
    now = A[now-1]
    d.append(now)
    set_d.add(now)

    if len(set_d) >= K:
        break

if K <= len(set_d):
    print(d[K-1])
else:
    K -= (len(set_d)-len(check))
    K = K % len(check)
    print(check[K-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

A = list(map(int, input().split()))

now = 1

d = []

while True:
    if A[now-1] in d:
        i = d.index(A[now-1])
        check = d[i:]
        break
    d.append(A[now-1])
    now = A[now-1]

if K <= len(d):
    print(d[K-1])
else:
    K -= (len(d)-len(check))
    K = K % len(check)
    print(check[K-1])



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

A = list(map(int, input().split()))

now = 1

d = []
set_d = set()

while True:
    if A[now-1] in set_d:
        i = d.index(A[now-1])
        check = d[i:]
        break
    now = A[now-1]
    d.append(now)
    set_d.add(now)

    if len(set_d) >= K:
        break

if K <= len(set_d):
    print(d[K-1])
else:
    K -= (len(set_d)-len(check))
    K = K % len(check)
    print(check[K-1])

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

A = list(map(int, input().split()))

now = 1

d = []

while True:
    if A[now-1] in d:
        i = d.index(A[now-1])
        check = d[i:]
        break
    d.append(A[now-1])
    now = A[now-1]
    print(d,now)

if K <= len(d):
    print(d[K-1])
else:
    K -= (len(d)-len(check))
    K = K % len(check)
    print(check[K-1])



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

A = list(map(int, input().split()))

now = 1

d = []
set_d = set()

while True:
    if A[now-1] in set_d:
        i = d.index(A[now-1])
        check = d[i:]
        break
    now = A[now-1]
    d.append(now)
    set_d.add(now)

    if len(set_d) >= K:
        break

if K <= len(set_d):
    print(d[K-1])
else:
    K -= (len(set_d)-len(check))
    K = K % len(check)
    print(check[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int, input().split())
mod = 998244353
MAX_N = 2 * (10**5)

fact = [1]
fact_inv = [0] * (MAX_N + 4)

for i in range(MAX_N + 3):
    fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%mod

def cmb(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

ans = 0
col = M

for k in range(N-1, -1, -1):
    now = col
    now *= cmb(N-1,k,mod)
    if k <= K:
        ans += now
    ans %= mod
    col *= M-1

print(ans)



Fixed submission:
N, M, K = map(int, input().split())
mod = 998244353

fact = [1 for i in range(N+1)]
fact_inv = [1 for i in range(N+1)]

for i in range(1, N+1):
    fact[i] = fact[i-1] * i % mod
    fact_inv[i] = pow(fact[i], mod-2, mod)

def cmb(n,k):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

ans = 0

for k in range(K+1):
    now = M * pow(M-1, N-k-1, mod) * cmb(N-1,k)
    ans = (ans + now % mod) % mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int, input().split())

dp = {}
mod = 998244353

for k in range(K+1):
    dp[(1,k)] = M

for i in range(2,N+1):
    for k in range(K+1):
        if k == 0:
            dp[(i, 0)] = dp[(i-1,0)]*(M-1)%mod
        else:
            dp[(i,k)] = dp[(i-1,k)]*(M-1)%mod + dp[(i-1,k-1)]%mod
            dp[(i,k)] %= mod

ans = 0
for k in range(1, K+1):
    ans += dp[(N,k)] % mod
    ans %= mod

print(dp[N,K])

Fixed submission:
N, M, K = map(int, input().split())
mod = 998244353

fact = [1 for i in range(N+1)]
fact_inv = [1 for i in range(N+1)]

for i in range(1, N+1):
    fact[i] = fact[i-1] * i % mod
    fact_inv[i] = pow(fact[i], mod-2, mod)

def cmb(n,k):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

ans = 0

for k in range(K+1):
    now = M * pow(M-1, N-k-1, mod) * cmb(N-1,k)
    ans = (ans + now % mod) % mod

print(ans)
Buggy python submission (verdict: Runtime Error):
X = int(input())

d = {}
k = {}
for i in range(-100,101):
    d[i] = pow(i,5)
    k[d[i]] = i
i = -100

while True:
    if X + d[i] in d.values():
        b = i
        a = k[X + d[i]]
        break
    i += 1

print(a, b)

Fixed submission:
X = int(input())

d = {}
k = {}
for i in range(-1000,1001):
    d[i] = pow(i,5)
    k[d[i]] = i
i = 1000

while True:
    if X + d[i] in d.values():
        b = i
        a = k[X + d[i]]
        break
    i -= 1

print(a, b)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = list(map(int, input().split()))
check = []
ans = 0


for i, v in enumerate(A):
    if v in check:
        ans += check.count(v)
    check.append(-v)
    check = list(map(lambda x: x+1, check))

print(ans)
    

Fixed submission:
N = int(input())

A = list(map(int, input().split()))
check = {}
ans = 0


for i, v in enumerate(A):
    if (i-v) in check:
        ans += check[i-v]
    if v+i in check:
        check[v+i] += 1
    else:
        check[v+i] = 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int,input().split())
fivex = 0
i = 1
ans = 0
x = 0
while x <= N:
    x = -((-1)*i*B // A)
    if x > N:
        break
    now = i - A *  int(x / B)
    if now > ans and x <= N:
        ans = now
    i += 1

print(ans)

Fixed submission:
A, B, N = map(int,input().split())
fivex = 0
i = 1
ans = 0
x = 0
# ans_x = -((-1)*A*N // B)
# if ans_x>N:
#     ans_x -= 1
# print(ans_x)
# print(int(A*ans_x/B)-A*int(ans_x/B))
while x <= B:
    x = -((-1)*i*B // A)
    if x > N:
        break
    now = i - A *  int(x / B)
    if now > ans and x <= N:
        # print(x)
        ans = now
    i += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int,input().split())
fivex = 0
i = 1
ans = 0
while True:
    fivex = i * B
    if (fivex % A == 0):
        x = fivex // A
    else:
        x = fivex // A + 1
    if x > N:
        break
    if i - A *  int(x / B) > ans:
        ans = i - A *  int(x / B)
    i += 1

print(ans)

Fixed submission:
A, B, N = map(int,input().split())
fivex = 0
i = 1
ans = 0
x = 0
# ans_x = -((-1)*A*N // B)
# if ans_x>N:
#     ans_x -= 1
# print(ans_x)
# print(int(A*ans_x/B)-A*int(ans_x/B))
while x <= B:
    x = -((-1)*i*B // A)
    if x > N:
        break
    now = i - A *  int(x / B)
    if now > ans and x <= N:
        # print(x)
        ans = now
    i += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
l = len(S)
d = {}



ans = 0
for i in range(l):
    m = int(S) % 2019
    if m in d:
        d[m] += 1
    else:
        d[m] = 1
    S = S[1:]

for k, v in d.items():
    if v >= 2:
        ans += int(v * (v-1)/2)
    if k == 0:
        ans += v
print(ans)



Fixed submission:
S = input()
l = len(S)
d = {}

m = 0

ans = 0
for i in range(l):
    m  = (m + int(S[l-1-i]) * pow(10,i,2019)) % 2019
    if m in d:
        d[m] += 1
    else:
        d[m] = 1

for k, v in d.items():
    if v >= 2:
        ans += int(v * (v-1)/2)
    if k == 0:
        ans += v
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


S = input()
l = len(S)
d = {}


ans = 0
for i in range(l):
    m = int(S) % 2019
    if m in d:
        d[m] += 1
    else:
        d[m] = 1
    S = S[1:]

for k, v in d.items():
    if v >= 2:
        ans += cmb(v, 2)
    if k == 0:
        ans += v
print(ans)



Fixed submission:
S = input()
l = len(S)
d = {}

m = 0

ans = 0
for i in range(l):
    m  = (m + int(S[l-1-i]) * pow(10,i,2019)) % 2019
    if m in d:
        d[m] += 1
    else:
        d[m] = 1

for k, v in d.items():
    if v >= 2:
        ans += int(v * (v-1)/2)
    if k == 0:
        ans += v
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = input()
S = input()

R = []
G = []
B = []
i = 1
for c in S:
    if c == 'R':
        R.append(i)
    elif c == 'G':
        G.append(i)
    elif c == 'B':
        B.append(i)
    i += 1

ans = 0

for r in R:
    for g in G:
        for b in B:
            if abs(r-g) != abs(r-b) and abs(r-b) != abs(g-b) and abs(r-g) != abs(g-b):
                ans += 1

print(ans)

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

rcnt = 0
gcnt = 0
bcnt = 0

for c in S:
    if c == 'R':
        rcnt += 1
    elif c == 'G':
        gcnt += 1
    elif c == 'B':
        bcnt += 1

ans = rcnt * gcnt * bcnt
for i in range(N):
    for j in range(i+1,N):
        k = 2 * j - i
        if k >= N:
            continue
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            ans -= 1
print(ans)