Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
length = len(S)
alpha, n = 'abcdefghijklmnopqrstuvwxyz', 26
i = 0
ans = ''
while i < length:
    diff = (n - (ord(S[i]) - ord('a'))) % 26
    
    if 0 <= diff <= K:
        ans += 'a'
        K -= diff
    else:
        ans += S[i]
        
    i += 1
    if K == 0:
        ans += S[i:]
else:
    ans = ans[:-1] + chr(ord(ans[-1]) + K % 26)
print(ans)

Fixed submission:
S = input()
K = int(input())
length = len(S)
alpha, n = 'abcdefghijklmnopqrstuvwxyz', 26
i = 0
ans = ''
while i < length:
    diff = (n - (ord(S[i]) - ord('a'))) % 26
    
    if 0 <= diff <= K:
        ans += 'a'
        K -= diff
    else:
        ans += S[i]
    i += 1
if K: ans = ans[:-1] + chr(ord('a') + (ord(ans[-1]) - ord('a') + K) % 26)
print(ans)

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
length = len(S)
alpha, n = 'abcdefghijklmnopqrstuvwxyz', 26
i = 0
ans = ''
while i < length:
    diff = (n - (ord(S[i]) - ord('a'))) % 26
    
    if 0 <= diff <= K:
        ans += 'a'
        K -= diff
    else:
        ans += S[i]
        
    i += 1
    if K == 0:
        ans += S[i:]
else:
    print(K)
    ans = ans[:-1] + chr(ord(ans[-1]) + K % 26)
print(ans)

Fixed submission:
S = input()
K = int(input())
length = len(S)
alpha, n = 'abcdefghijklmnopqrstuvwxyz', 26
i = 0
ans = ''
while i < length:
    diff = (n - (ord(S[i]) - ord('a'))) % 26
    
    if 0 <= diff <= K:
        ans += 'a'
        K -= diff
    else:
        ans += S[i]
    i += 1
if K: ans = ans[:-1] + chr(ord('a') + (ord(ans[-1]) - ord('a') + K) % 26)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
q = [sorted(list(map(int, input().split()))) for _ in range(N-1)]

ans = 0

for l in range(1, N+1):
    ql = [q[i] for i in range(N-1) if l <= q[i][0]]
    for r in range(l, N+1):
        points = (r - l + 1)
        edges = len([qli for qli in ql if qli[1] <= r])
        res = points - edges
        ans += res

print(ans)


Fixed submission:
N = int(input())
q = [sorted(list(map(int, input().split()))) for _ in range(N-1)]

ans = 0

for i in range(1, N+1):
    ans += i * (N - i + 1)
for qi in q:
    u, v = qi[0], qi[1]
    ans -= u * (N - v + 1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
q = [sorted(list(map(int, input().split()))) for _ in range(N-1)]

ans = 0

for l in range(1, N+1):
    for r in range(l, N+1):
        points = (r - l + 1)
        edges = len([q[i] for i in range(N-1) if l <= q[i][0] and q[i][1] <= r])
        res = points - edges
        ans += res

print(ans)


Fixed submission:
N = int(input())
q = [sorted(list(map(int, input().split()))) for _ in range(N-1)]

ans = 0

for i in range(1, N+1):
    ans += i * (N - i + 1)
for qi in q:
    u, v = qi[0], qi[1]
    ans -= u * (N - v + 1)

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

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

# エラトステネスの篩っぽく処理
ans_list = [True for _ in range(A[-1] + 1)]
ans = 0

# ダブリを省くために先に数える
c = Counter(A)

for a in A:
    if ans_list[a] == True:
        if c[a] == 1:
            ans += 1
        i = 2
        while a * i <= A[-1]:
            ans_list[a * i] = False
            i += 1

print(ans)


Fixed submission:
from collections import Counter

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

# エラトステネスの篩っぽく処理
ans_list = [True for _ in range(A[-1] + 1)]
ans = 0

# ダブリを省くために先に数える
c = Counter(A)

for a in A:
    if ans_list[a] == True:
        if c[a] == 1:
            ans += 1
        i = 2
        while a * i <= A[-1]:
            ans_list[a * i] = False
            i += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
from copy import deepcopy

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

ans = 0

if len(set(A)) == 1:
    print(0)
    exit()

# エラトステネスの篩っぽく処理
search_list = deepcopy(A)
ans = 0

tmp = min(search_list)
smax = int(max(search_list)**0.5) + 1

while search_list:
    ans += 1
    search_list = [i for i in search_list if i % tmp != 0]
    tmp = min(search_list)
    if tmp < smax:
        ans += len(search_list)
        break

print(ans)


Fixed submission:
from collections import Counter

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

# エラトステネスの篩っぽく処理
ans_list = [True for _ in range(A[-1] + 1)]
ans = 0

# ダブリを省くために先に数える
c = Counter(A)

for a in A:
    if ans_list[a] == True:
        if c[a] == 1:
            ans += 1
        i = 2
        while a * i <= A[-1]:
            ans_list[a * i] = False
            i += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
print(A*B)


Fixed submission:
A, B = map(int, input().split())
print(A*B)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

if 0 in A:
    print(0)
else:
    ans = 1
    for i in range(A):
        ans += A[i]
        if ans > 10**18:
            print(-1)
            exit()
    print(ans)


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

if 0 in A:
    print(0)
    exit()

ans = A[0]
for i in range(1, N):
    ans *= A[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)

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

ans = A[0]
for i in range(1, N):
    ans *= A[i]
if ans > 10**18:
    print(-1)
    exit()
print(ans)


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

if 0 in A:
    print(0)
    exit()

ans = A[0]
for i in range(1, N):
    ans *= A[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import product

N, M, X = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
ans = float("inf")

for now in product(range(2), N):
    res = 0
    An = [0 for _ in range(M)]
    for n in range(N):
        if now[n] == 1:
            res += A[n][0]
            An = [An[j] + A[n][j+1] for j in range(M)]
    if min(An) >= X:
        ans = min(ans, res)

if ans == float("inf"):
    print(-1)
else:
    print(ans)


Fixed submission:
N, M, X = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
ans = float("inf")

for i in range(2**N):
    now = bin(i)[2:].zfill(N)  # now[i]: 参考書iを買う
    res = 0
    An = [0] * M
    for n in range(N):
        if now[n] == "1":
            res += A[n][0]
            An = [An[j] + A[n][j+1] for j in range(M)]
    if min(An) >= X:
        ans = min(ans, res)

if ans == float("inf"):
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int, input().split())

if N < B:
    print((A*N)//B)
    exit()

qa, ra = divmod(A, B)
ans = 0
rx = 0

for x in range(N+1):
    rx = max(rx, x%B)
    if rx == B-1:
        break

print(qa*rx + (ra*rx)//B)


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

if N < B:
    print((A*N)//B)
else:
    qa, ra = divmod(A, B)
    rx = B-1
    print(qa*rx + (ra*rx)//B)

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

if N < B:
    print((A*N)//B)
    exit()

ans = 0
for x in range(N+1):
    q, r = divmod(x, B)
    ans = max(ans, (A*r)//B - (A-1)*q)
    # 終了判定
    if ans == B-1:
        break

print(ans)


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

if N < B:
    print((A*N)//B)
else:
    qa, ra = divmod(A, B)
    rx = B-1
    print(qa*rx + (ra*rx)//B)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
    print(A.count(i+1))


Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
c = Counter(A)

for i in range(1, N+1):
    if i in c.keys():
        print(c[i])
    else:
        print(0)
Buggy python submission (verdict: Runtime Error):
hogehoge

Fixed submission:
from math import gcd

K = int(input())

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        res = gcd(a, b)
        for c in range(1, K+1):
            ans += gcd(res, c)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd

def gcd3(a, b, c):
    res = gcd(a, b)
    return gcd(res, c)


K = int(input())
ans = 0

for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += gcd3(a, b, c)

print(ans)


Fixed submission:
from math import gcd

K = int(input())

ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        res = gcd(a, b)
        for c in range(1, K+1):
            ans += gcd(res, c)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil
from copy import deepcopy

N0 = int(input())
ans = 0


for K in range(2, N0+1):
    N = deepcopy(N0)
    #print("K", K)
    # 下処理、N -> N/K を可能な限り行う。いずれ割り切れなくなる
    while (N % K == 0):
        #print("step1", N, "to", N//K)
        N = N // K

    # 割り切れない場合 N -> N-K を可能な限り行う
    #print("step2", N, "to", N - K * (ceil(N/K) - 1))
    N = N - K * (ceil(N/K) - 1)

    # 判定
    #print("judge", N, N==1, "\n")
    if N == 1:
        ans += 1

print(ans)


Fixed submission:
from copy import deepcopy

# 約数を全列挙する関数
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    divisors.sort()
    return divisors

N0 = int(input())
ans = 0

# N = K^a (bK + 1) と表現できるので K は N or N-1 の約数であることが必要
K_cand = set(make_divisors(N0) + make_divisors(N0-1))

for K in K_cand:
    N = deepcopy(N0)
    if K == 1:  # K = 1 を除外
        continue
    else:
        while N%K == 0:
            N = N // K  # 割れるだけ割る
        N = N%K  # 引けるだけ引く
        if N == 1:
            ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y = map(int, input().split())
# グラフの作成 数字が小さい方から大きい方への有向グラフ
g = [[i-1, i+1] for i in range(N)]
g[0].remove(-1)
g[N-1].remove(N)
g[X-1].append(Y-1)
g[Y-1].append(X-1)
#print(g)

ans_list = [0] * N
# 各頂点からの最短経路長を計算
for i in range(N):
    queue = g[i]
    seen = [False] * N
    length = 0
    while queue:
        length += 1
        #print("now length:", length, queue)
        add = []
        for qi in queue:
            if seen[qi] == False:
                if i < qi:
                    ans_list[length] += 1
                seen[qi] = True
                add += g[qi]
                #print("add,", g[qi])
        queue = list(set(add))
        #print(queue)

# 答えの出力
for k in range(1, N):
    print(ans_list[k])


Fixed submission:
N, X, Y = map(int, input().split())
# グラフの作成 数字が小さい方から大きい方への有向グラフ
g = [[i-1, i+1] for i in range(N)]
g[0].remove(-1)
g[N-1].remove(N)
g[X-1].append(Y-1)
g[Y-1].append(X-1)

ans_list = [0] * N
# 各頂点からの最短経路長を計算
for i in range(N):
    queue = g[i]
    seen = [False] * N
    length = 0
    while queue:
        length += 1
        add = []
        for qi in queue:
            if seen[qi] == False:
                if i < qi:
                    ans_list[length] += 1
                seen[qi] = True
                add += g[qi]
        queue = list(set(add))

# 答えの出力
for k in range(1, N):
    print(ans_list[k])
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify, heappushpop

X, Y, A, B, C = map(int, input().split())
# 大きい順にソートして受け取っておく
p = sorted(list(map(int, input().split())))[::-1]
q = sorted(list(map(int, input().split())))[::-1]
r = sorted(list(map(int, input().split())))[::-1]
ans_list = p[:X] + q[:Y]  # 着色しない場合
heapify(ans_list)
m = min(ans_list)
for ri in r:
    if ri > m:
        heappushpop(ans_list, ri)
        m = min(ans_list)
    else:
        break
print(sum(ans_list))


Fixed submission:
from heapq import heapify, heappushpop

X, Y, A, B, C = map(int, input().split())
# 大きい順にソートして受け取っておく
p = sorted(list(map(int, input().split())))[::-1]
q = sorted(list(map(int, input().split())))[::-1]
r = sorted(list(map(int, input().split())))[::-1]
ans_list = p[:X] + q[:Y]  # 着色しない場合
heapify(ans_list)
for ri in r:
    if ri > ans_list[0]:
        heappushpop(ans_list, ri)
    else:
        break
print(sum(ans_list))

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify, heappushpop

X, Y, A, B, C = map(int, input().split())
# 大きい順にソートして受け取っておく
p = sorted(list(map(int, input().split())))[::-1]
q = sorted(list(map(int, input().split())))[::-1]
r = sorted(list(map(int, input().split())))[::-1]
ans_list = p[:X] + q[:Y]  # 着色しない場合
heapify(ans_list)
for ri in r:
    if ri > min(ans_list):
        heappushpop(ans_list, ri)
    else:
        break
print(sum(ans_list))


Fixed submission:
from heapq import heapify, heappushpop

X, Y, A, B, C = map(int, input().split())
# 大きい順にソートして受け取っておく
p = sorted(list(map(int, input().split())))[::-1]
q = sorted(list(map(int, input().split())))[::-1]
r = sorted(list(map(int, input().split())))[::-1]
ans_list = p[:X] + q[:Y]  # 着色しない場合
heapify(ans_list)
for ri in r:
    if ri > ans_list[0]:
        heappushpop(ans_list, ri)
    else:
        break
print(sum(ans_list))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
c = Counter(A)

for k in range(N):
    ans = 0
    res = c.copy()
    res[A[k]] -= 1
    for ri in res.values():
        n = ri
        ans += n * (n-1) // 2
    print(ans)


Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
c = Counter(A)

# 先にk番目を抜かない場合を求めておく
ans = 0
for n in c.values():
    ans += n*(n-1)//2

# k番目を抜く場合の差分を加える
for k in range(N):
    m = c[A[k]]
    print(ans - (m-1))  # -m*(m-1)//2 + (m-1)*(m-2)//2
Buggy python submission (verdict: Runtime Error):
terms = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(terms[K])


Fixed submission:
terms = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(terms[K-1])

Buggy python submission (verdict: Runtime Error):
terms = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(terms[K+1])


Fixed submission:
terms = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(terms[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
# input
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x, y, c = [0] * M, [0] * M, [0] * M
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())
ans = float("inf")

for i in range(M):
    ans = min(ans, a[x[i]-1] + b[y[i]-1] - c[i])

for i in range(A):
    for j in range(B):
        ans = min(ans, a[i] + b[j])
print(ans)


Fixed submission:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = min(a) + min(b)
for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x-1] + b[y-1] - c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# input
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x, y, c = [0] * M, [0] * M, [0] * M
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())
ans = float("inf")
for i in range(A):
    for j in range(B):
        cmax = 0
        for k in range(M):
            if i+1 == x[k] and j+1 == y[k]:
                cmax = max(cmax, c[k])
        res = a[i] + b[j] - cmax
        ans = min(ans, res)
print(ans)


Fixed submission:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = min(a) + min(b)
for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x-1] + b[y-1] - c)
print(ans)
Buggy python submission (verdict: Runtime Error):
S, T = input().split()
A, B = map(int, input().split())
U = input()

if U == S:
    print(S-1, T)
else:
    print(S, T-1)


Fixed submission:
S, T = input().split()
A, B = map(int, input().split())
U = input()

if U == S:
    print(A-1, B)
else:
    print(A, B-1)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
p = list(map(int, input().split()))

res = sum(p[:K])
res_max = res
for i in range(1, N-K+1):
    res += p[i+K-1] - p[i-1]
    if res > res_max:
        i_max = i

ans = 0
for j in range(K):
    ans += (p[i_max + j] + 1) / 2
print(ans)


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

res = sum(p[:K])
res_max = res
i_max = 0
for i in range(1, N-K+1):
    res += p[i+K-1] - p[i-1]
    if res > res_max:
        res_max = res
        i_max = i

ans = 0
for j in range(K):
    ans += (p[i_max + j] + 1) / 2
print(ans)

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

res = sum(p[:K])
res_max = res
for i in range(1, N-K+1):
    res += p[i+k] - p[i-1]
    if res > res_max:
        i_max = i

ans = 0
for j in range(K):
    ans += (p[i_max + j] + 1) / 2
print(ans)


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

res = sum(p[:K])
res_max = res
i_max = 0
for i in range(1, N-K+1):
    res += p[i+K-1] - p[i-1]
    if res > res_max:
        res_max = res
        i_max = i

ans = 0
for j in range(K):
    ans += (p[i_max + j] + 1) / 2
print(ans)

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

p_likelihood = [0] * N
for i in range(N):
    p_likelihood[i] = (p[i] + 1) / 2

ans = 0
for i in range(N-K+1):
    res = sum(p_likelihood[i:i+K])
    ans = max(ans, res)

print(ans)


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

res = sum(p[:K])
res_max = res
i_max = 0
for i in range(1, N-K+1):
    res += p[i+K-1] - p[i-1]
    if res > res_max:
        res_max = res
        i_max = i

ans = 0
for j in range(K):
    ans += (p[i_max + j] + 1) / 2
print(ans)

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

p_likelihood = [0] * N
for pi in range(N):
    p_likelihood[i] = (p[i] + 1) / 2

ans = 0
for i in range(N-K+1):
    res = sum(p_likelihood[i:i+K])
    ans = max(ans, res)

print(ans)


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

res = sum(p[:K])
res_max = res
i_max = 0
for i in range(1, N-K+1):
    res += p[i+K-1] - p[i-1]
    if res > res_max:
        res_max = res
        i_max = i

ans = 0
for j in range(K):
    ans += (p[i_max + j] + 1) / 2
print(ans)
Buggy python submission (verdict: Runtime Error):
H, W, N = int(input()) * 3
x = max(H, W)
print((N+x-1)//x)

Fixed submission:
from math import ceil

H = int(input())
W = int(input())
N = int(input())

print(ceil(N/(max(W, H))))
Buggy python submission (verdict: Runtime Error):
from math import gcd

A, B = map(int, input().split())
G = gcd(A, B)
print(A*B // G)


Fixed submission:
from fractions import gcd

A, B = map(int, input().split())
G = gcd(A, B)
print(A*B // G)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
remain = 1  # 残す整数
index = 0

if remain not in a:
    print(-1)
    exit()

while remain in a[index:]:
    index = a[index:].index(remain)
    remain += 1

print(N - remain + 1)


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

now = 1
for ai in a:
    if ai == now:
        now += 1

if now == 1:
    print(-1)
else:
    print(N - now + 1)
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())
for a in range(X//100+1):
    for b in range(X//101+1):
        for c in range(X//102+1):
            for d in range(X//103+1):
                for e in range(X//104+1):
                    for f in range(X//105+1):
                        if 100*a + 101*b +102*c + 103*d + 104*e + 105*f == X:
                            print(1)
                            exit()
print(0)


Fixed submission:
X = int(input())
# とりあえず 100 で構成しようとして、余剰分を 100 を置換することで構成できないか調べる
q, r = X//100, X%100
if r <= 5 * q:
    print(1)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
N = int(input())
S = list(input())
print(len(set(tuple(combinations(S, 3)))))


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

ans = 0

for i in range(10):
    if str(i) not in S:
        continue
    ind_i = S.index(str(i))
    for j in range(10):
        if str(j) not in S[ind_i+1:]:
            continue
        ind_j = S[ind_i+1:].index(str(j)) + ind_i+1
        for k in range(10):
            if str(k) in S[ind_j+1:]:
                ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
N = int(input())
S = list(input())
print(len(set(list(combinations(S, 3)))))


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

ans = 0

for i in range(10):
    if str(i) not in S:
        continue
    ind_i = S.index(str(i))
    for j in range(10):
        if str(j) not in S[ind_i+1:]:
            continue
        ind_j = S[ind_i+1:].index(str(j)) + ind_i+1
        for k in range(10):
            if str(k) in S[ind_j+1:]:
                ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
from numpy import cumsum

N = int(input())
A = list(map(int, input().split()))
a_cum = cumsum(A)
inv_a_cum = [a_cum[-1] - a_cum[i] for i in range(N)]

for i in range(N):
    ans = min(ans, abs(a_cum[i] - inv_a_cum[i]))


Fixed submission:
from numpy import cumsum

N = int(input())
A = list(map(int, input().split()))
a_cum = cumsum(A)
cand = [abs(a_cum[i] - (a_cum[-1] - a_cum[i])) for i in range(N)]
print(min(cand))
Buggy python submission (verdict: Runtime Error):
from math import factorial

def dist(x1, y1, x2, y2):
    return ((x1 - x2)**2 + (y1 - y2)**2)**0.5

N = int(input())
x, y = [map(int, input().split()) for _ in range(N)]

ans = 0

for i in range(N-1):
    for j in range(i+1, N):
        ans += dist(x[i], y[i], x[j], y[j]) * 2

ans /= factorial(N)

print(ans)


Fixed submission:
def dist(x1, y1, x2, y2):
    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5

N = int(input())
x, y = [0] * N, [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())
ans = 0

for i in range(N - 1):
    for j in range(i + 1, N):
        ans += dist(x[i], y[i], x[j], y[j])

ans = ans * 2 / N

print(ans)
Buggy python submission (verdict: Runtime Error):
def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors


N = int(input())
divs = make_divisors(N)
if len(divs) % 2 == 0:
    print(divs[len(divs)//2 - 1] + divs[len(divs)//2] - 2)
else:
    print(divs[len(divs//2)] * 2 - 2)


Fixed submission:
def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors


N = int(input())
divs = make_divisors(N)
if len(divs) % 2 == 0:
    print(divs[len(divs)//2 - 1] + divs[len(divs)//2] - 2)
else:
    print(divs[len(divs)//2] * 2 - 2)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)

Asum = sum(A)

def test(X):
    return (Asum - np.minimum(A, X//F).sum() <= K)

l = -1
r = 10**13

while (l +1 < r):
    mid = (l + r) // 2
    if test(mid):
        r = mid
    else:
        l = mid

ans = r
print(ans)


Fixed submission:
import numpy as np

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)

A = np.array(A, np.int64)
F = np.array(F, np.int64)

Asum = sum(A)

def test(X):
    return (Asum - np.minimum(A, X//F).sum() <= K)

l = -1
r = 10**12

while (l + 1 < r):
    mid = (l + r) // 2
    if test(mid):
        r = mid
    else:
        l = mid

ans = r
print(ans)