Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(key=lambda x: abs(x), reverse=True)

    res = 1

    if max(a) < 0:
        if k % 2 == 1:
            for i in range(n - k, n):
                res *= a[i]
                res %= MOD
        else:
            for i in range(k):
                res *= a[i]
                res %= MOD
    else:
        plus_a = [e for e in a if e >= 0]
        minus_a = [e for e in a if e < 0]

        minus_cnt = min(k, len(minus_a))
        minus_cnt -= minus_cnt % 2
        plus_cnt = k - minus_cnt

        minus_a = minus_a[:minus_cnt]
        minus_a.reverse()

        max_change_cnt = min(minus_cnt, len(plus_a) - plus_cnt)
        max_change_cnt -= max_change_cnt % 2
        change_cnt = 0
        while change_cnt < max_change_cnt:
            if plus_a[plus_cnt + change_cnt] * plus_a[plus_cnt + change_cnt + 1]\
                    <= minus_a[change_cnt] * minus_a[change_cnt + 1]:
                break
            change_cnt += 2

        for i in range(change_cnt, minus_cnt):
            res *= minus_a[i]
            res %= MOD

        for i in range(plus_cnt + change_cnt):
            res *= plus_a[i]
            res %= MOD

    print(res)


main()


Fixed submission:
MOD = 10 ** 9 + 7


def mul_mod(x, y, mod):
    return x * y % mod


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(key=lambda x: abs(x), reverse=True)

    res = 1

    if k == 1:
        res = max(a) % MOD
    elif k == n:
        res = 1
        for e in a:
            res *= e
            res %= MOD
    elif max(a) < 0:
        if k % 2 == 1:
            for i in range(n - k, n):
                res *= a[i]
                res %= MOD
        else:
            for i in range(k):
                res *= a[i]
                res %= MOD
    else:
        plus_a = [e for e in a if e >= 0]
        minus_a = [e for e in a if e < 0]

        minus_cnt = min(k, len(minus_a))
        minus_cnt -= minus_cnt % 2
        plus_cnt = k - minus_cnt

        minus_a = minus_a[:minus_cnt]
        minus_a.reverse()

        max_change_cnt = min(minus_cnt, len(plus_a) - plus_cnt)
        max_change_cnt -= max_change_cnt % 2
        change_cnt = 0
        while change_cnt < max_change_cnt:
            if plus_a[plus_cnt + change_cnt] * plus_a[plus_cnt + change_cnt + 1]\
                    <= minus_a[change_cnt] * minus_a[change_cnt + 1]:
                break
            change_cnt += 2

        for i in range(change_cnt, minus_cnt):
            res *= minus_a[i]
            res %= MOD

        for i in range(plus_cnt + change_cnt):
            res *= plus_a[i]
            res %= MOD

    print(res)


main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter


n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
a = set(a)

cnt = 0
while a:
    min_val = min(a)
    a.remove(min_val)

    if c[min_val] == 1:
        cnt += 1

    if not a:
        break

    max_val = max(a)

    del_a = set()
    mul = 2
    while True:
        mul_val = min_val * mul

        if mul_val > max_val:
            break

        if mul_val in a:
            del_a.add(min_val * mul)

        mul += 1

    a -= del_a

print(cnt)


Fixed submission:
from collections import Counter


n = int(input())
a = list(map(int, input().split()))
a.sort()
c = Counter(a)

flags = [True] * (a[-1] + 1)

for e in a:
    for mul in range(2, a[-1] // e + 1):
        flags[e * mul] = False

print(sum([flags[a[i]] and c[a[i]] == 1 for i in range(n)]))

Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;


int main(void) {
    int n;
    cin >> n;

    auto a = vector<int>(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    
    int cnt = 0;
    auto flags = vector<bool>(n, true);

    for (int i = 0; i < n; i++)
    {
        if (!flags[i])
        {
            continue;
        }
        
        if (i == n - 1 || a[i] != a[i + 1])
        {
            cnt += 1;
        }
        
        for (int j = i + 1; j < n; j++)
        {
            if (flags[j] && a[j] % a[i] == 0)
            {
                flags[j] = false;
            }
        }
    }
    
    cout << cnt << endl;
    
    return 0;
}


Fixed submission:
from collections import Counter


n = int(input())
a = list(map(int, input().split()))
a.sort()
c = Counter(a)

flags = [True] * (a[-1] + 1)

for e in a:
    for mul in range(2, a[-1] // e + 1):
        flags[e * mul] = False

print(sum([flags[a[i]] and c[a[i]] == 1 for i in range(n)]))

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

a.sort()

cnt = 0
flags = [True] * n
for i in range(n):
    if not flags[i]:
        continue

    if i == n - 1 or a[i] != a[i + 1]:
        cnt += 1

    for j in range(i + 1, n):
        if flags[j] and a[j] % a[i] == 0:
            flags[j] = False

print(cnt)


Fixed submission:
from collections import Counter


n = int(input())
a = list(map(int, input().split()))
a.sort()
c = Counter(a)

flags = [True] * (a[-1] + 1)

for e in a:
    for mul in range(2, a[-1] // e + 1):
        flags[e * mul] = False

print(sum([flags[a[i]] and c[a[i]] == 1 for i in range(n)]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
mul = 1
for e in a:
    mul *= e
if mul > 10 ** 18:
    print(-1)
else:
    print(mul)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

if a[-1] == 0:
    print(0)
    exit(0)

mul = 1
for e in a:
    mul *= e
    if mul > (10 ** 18):
        print(-1)
        exit(0)

print(mul)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


class Room:
    def __init__(self, prev=-1, dist=1 << 64):
        self.prev = prev
        self.dist = dist


n, m = map(int, input().split())
passages = [set() for _ in range(n)]
for _ in range(m):
    a, b = map(lambda x: int(x) - 1, input().split())
    passages[a].add(b)
    passages[b].add(a)

cave = [Room() for _ in range(n)]
cave[0].dist = 0

opening = deque({0})
while opening:
    curr_room = opening.pop()
    next_dist = cave[curr_room].dist + 1
    for next_room in passages[curr_room]:
        if next_dist < cave[next_room].dist:
            cave[next_room].prev = curr_room
            cave[next_room].dist = next_dist
            opening.append(next_room)

guide_points = [cave[i].prev + 1 for i in range(1, n)]

print('Yes')
print('\n'.join(map(str, guide_points)))


Fixed submission:
class Room:
    def __init__(self, prev=-1, dist=1 << 64):
        self.prev = prev
        self.dist = dist


n, m = map(int, input().split())
passages = [set() for _ in range(n)]
for _ in range(m):
    a, b = map(lambda x: int(x) - 1, input().split())
    passages[a].add(b)
    passages[b].add(a)

opening = {0}
closing = {0}
guide_points = [-1] * n
while opening:
    next_opening = set()

    for curr_room in opening:
        for next_room in passages[curr_room]:
            if next_room in closing:
                continue

            guide_points[next_room] = curr_room
            next_opening.add(next_room)
            closing.add(next_room)

    opening = next_opening

print('Yes')
print('\n'.join(map(lambda x: str(x + 1), guide_points[1:])))
Buggy python submission (verdict: Time Limit Exceeded):
def f(x):
    div = 1
    while div * div <= x:
        if x % div == 0:
            for a in range(0, div + 1):
                b = a - div
                if a ** 5 - b ** 5 == x:
                    return a, b

            opp_div = x // div
            for a in range(0, opp_div + 1):
                b = a - opp_div
                if a ** 5 - b ** 5 == x:
                    return a, b
        div += 1


def main():
    x = int(input())
    a, b = f(x)
    print(a, b)


main()


Fixed submission:
def f(x):
    div = 1
    while div * div <= x:
        if x % div == 0:
            for a in range(0, int((x // div) ** 0.25) + 2):
                b = a - div
                if a ** 5 - b ** 5 == x:
                    return a, b

            opp_div = x // div
            for a in range(0, int((x // opp_div) ** 0.25) + 2):
                b = a - opp_div
                if a ** 5 - b ** 5 == x:
                    return a, b
        div += 1


def main():
    x = int(input())
    a, b = f(x)
    print(a, b)


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

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


Fixed submission:
from collections import Counter


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

a_plus_idx = Counter([a[i] + i for i in range(n)])
a_minus_idx = Counter([i - a[i] for i in range(n)])

total = 0
for k, v in a_plus_idx.items():
    total += v * a_minus_idx[k]

print(total)
Buggy python submission (verdict: Time Limit Exceeded):
# unfinished
INF = 1 << 64


def find_max(a):
    n = len(a)
    odd_a = [a[i] for i in range(n) if i % 2 == 0]
    even_a = [a[i] for i in range(n) if i % 2 == 1]

    cum_odd_a = [0]
    sum_odd_a = 0
    for odd_a_elem in odd_a:
        cum_odd_a.append(cum_odd_a[-1] + odd_a_elem)
        sum_odd_a += odd_a_elem

    cum_even_a = [0]
    sum_even_a = 0
    for even_a_elem in even_a:
        cum_even_a.append(cum_even_a[-1] + even_a_elem)
        sum_even_a += even_a_elem

    max_sum_half_a = -INF

    if n % 2 == 0:  # nが偶数である場合
        # 奇数と偶数の境目
        for i in range(n // 2 + 1):
            odd_part_sum = cum_odd_a[i]
            even_part_sum = sum_even_a - cum_even_a[i]
            sum_half_a = odd_part_sum + even_part_sum

            if sum_half_a > max_sum_half_a:
                max_sum_half_a = sum_half_a
    else:  # nが奇数である場合
        # 奇数と偶数の境目
        for i in range(n // 2 + 1):
            odd_part_sum_1 = cum_odd_a[i]

            # 偶数と奇数の境目
            for j in range(i, n // 2 + 1):
                even_part_sum = cum_even_a[j] - cum_even_a[i]
                odd_part_sum_2 = sum_odd_a - cum_odd_a[j + 1]

                sum_half_a = odd_part_sum_1 + even_part_sum + odd_part_sum_2

                if sum_half_a > max_sum_half_a:
                    max_sum_half_a = sum_half_a

    return max_sum_half_a


def main():
    _ = int(input())
    a = list(map(int, input().split()))

    print(find_max(a))


main()


Fixed submission:
def find_max(a):
    n = len(a)

    if n <= 3:
        return max(a)

    dp = [[-(1 << 64)] * (2 + n % 2) for _ in range(n)]

    for i in range(2 + n % 2):
        dp[i][i] = a[i]
        dp[i + 1][i] = a[i]

    for i in range(2, n):
        for j in range(2 + n % 2):
            for extra_space in range(j + 1):
                curr_sum = dp[i - (2 + extra_space)][j - extra_space] + a[i]
                if curr_sum > dp[i][j]:
                    dp[i][j] = curr_sum

    return dp[-1][1 + n % 2]


def main():
    _ = int(input())
    a = list(map(int, input().split()))

    print(find_max(a))


main()
Buggy python submission (verdict: Time Limit Exceeded):
def pow_mod(a, b, p):
    res = 1
    mul = a
    for i in range(len(bin(b)) - 2):
        if (1 << i) & b:
            res = (res * mul) % p
        mul = (mul ** 2) % p
    return res


def perm_mod(n, r, p):
    res = 1
    for i in range(r):
        res = (res * (n - i)) % p
    return res


def comb_mod(n, r, p, factorial=None, invert_factorial=None):
    if factorial and invert_factorial:
        return (factorial[n] * invert_factorial[r] * invert_factorial[n - r]) % p

    r = min(r, n - r)
    return (perm_mod(n, r, p) * pow_mod(perm_mod(r, r, p), p - 2, p)) % p


def main():
    p = 10 ** 9 + 7
    n, k = map(int, input().split())

    factorial = [1] * (n + 1)
    for i in range(1, n + 1):
        factorial[i] = (factorial[i - 1] * i) % p

    invert_factorial = [pow_mod(x, p - 2, p) for x in factorial]

    res = 0
    for i in range(min(k + 1, n)):
        res = (res + comb_mod(n, i, p, factorial, invert_factorial)
               * comb_mod(n - 1, i, p, factorial, invert_factorial)) % p
    print(res)


main()


Fixed submission:
def pow_mod(a, b, p):
    res = 1
    mul = a
    for i in range(len(bin(b)) - 2):
        if (1 << i) & b:
            res = (res * mul) % p
        mul = (mul ** 2) % p
    return res


def comb_mod(n, r, p, factorial=None, invert_factorial=None):
    return (factorial[n] * invert_factorial[r] * invert_factorial[n - r]) % p


def main():
    p = 10 ** 9 + 7
    n, k = map(int, input().split())

    factorial = [1] * (n + 1)
    for i in range(1, n + 1):
        factorial[i] = (factorial[i - 1] * i) % p

    invert_factorial = [0] * (n + 1)
    invert_factorial[n] = pow_mod(factorial[n], p - 2, p)
    for i in range(n - 1, -1, -1):
        invert_factorial[i] = (invert_factorial[i + 1] * (i + 1)) % p

    res = 0
    for i in range(min(k + 1, n)):
        res = (res + comb_mod(n, i, p, factorial, invert_factorial)
               * comb_mod(n - 1, i, p, factorial, invert_factorial)) % p
    print(res)


main()
Buggy python submission (verdict: Time Limit Exceeded):
k, q = map(int, input().split())
d = list(map(int, input().split()))
queries = [tuple(map(int, input().split())) for _ in range(q)]

for n, x, m in queries:
    d_mod = [elem % m for elem in d]
    rem_d_mod = d_mod[: (n - 1) % k]
    print(n - 1 - (x % m + ((n - 1) // k) * sum(d_mod) + sum(rem_d_mod)) // m
          - ((n - 1) // k) * d_mod.count(0) - rem_d_mod.count(0))


Fixed submission:
import numpy as np


k, q = map(int, input().split())
d = np.array(list(map(int, input().split())), dtype=np.int64)
queries = [tuple(map(int, input().split())) for _ in range(q)]

for n, x, m in queries:
    d_mod = d % m
    rem_d_mod = d_mod[: (n - 1) % k]
    print(n - 1 - (x % m + ((n - 1) // k) * np.sum(d_mod) + np.sum(rem_d_mod)) // m
          - ((n - 1) // k) * np.count_nonzero(d_mod == 0) - np.count_nonzero(rem_d_mod == 0))
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	N, K = MAP()
	R, S, P = MAP()
	T = input().rstrip()

	Tokuten = [R, S, P]
	Te = ['r', 's', 'p']

	A = [-1] * N

	ans = 0
	for i in range(N):
		now = 0 if T[i]=='s' else 1 if T[i]=='p' else 2
		# print(Te[now])
		if i-K >= 0:
			past = 0 if T[i-K]=='s' else 1 if T[i-K]=='p' else 2
			# print(now, past, i)
			# 過去に出している手だったら、違う手を出す
			if past == now:
				if i-(2*K) >= 0:
					ppast = 0 if T[i-2*K]=='s' else 1 if T[i-2*K]=='p' else 2
					if ppast == past:
						A[i] = now
						ans += Tokuten[now]
					else:
						if i+K < N:
							feature = 0 if T[i+K]=='s' else 1 if T[i+K]=='p' else 2
							for j in range(3):
								if not j in [now, feature]:
									A[i] = j
						else:
							A[i] = (now+1)%3
				else:
					if i+K < N:
						feature = 0 if T[i+K]=='s' else 1 if T[i+K]=='p' else 2
						for j in range(3):
							if not j in [now, feature]:
								A[i] = j
					else:
						A[i] = (now+1)%3
			else:
				A[i] = now
				ans += Tokuten[now]
		else:
			A[i] = now
			ans += Tokuten[now]

	# print(A)
	for i in range(K, N):
		if A[i]==A[i-K]:
			f = A[i+K]
			for j in range(3):
				if not j in [A[i],f]:
					A[i] = j
	# print(A)

	ans = 0
	for i in range(N):
		te = A[i]
		if te==0 and T[i]=='s':
			ans += Tokuten[0]
		elif te==1 and T[i]=='p':
			ans += Tokuten[1]
		elif te==2 and T[i]=='r':
			ans += Tokuten[2]

	print(ans)
	
if __name__ == '__main__':
	main()

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	N, K = MAP()
	R, S, P = MAP()
	T = input().rstrip()

	Tokuten = [R, S, P]
	Te = ['r', 's', 'p']

	A = [-1] * N
	for i in range(N):
		now = 0 if T[i]=='s' else 1 if T[i]=='p' else 2
		if i-K < 0:
			A[i] = now
		else:
			past = A[i-K]
			if now == past:
				if i+K < N:
					future = 0 if T[i+K]=='s' else 1 if T[i+K]=='p' else 2
					for j in range(3):
						if not j in [now, future]:
							A[i] = j
			else:
				A[i] = now
	
	# print(A)

	ans = 0
	for i in range(N):
		te = A[i]
		if te==0 and T[i]=='s':
			ans += Tokuten[0]
		elif te==1 and T[i]=='p':
			ans += Tokuten[1]
		elif te==2 and T[i]=='r':
			ans += Tokuten[2]

	print(ans)

if __name__ == '__main__':
	main()
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = []
for i in range(N):
	tmp = []
	n = INT()
	shougen = []
	for j in range(n):
		shougen = MAP()
		tmp.append(shougen)
	A.append(tmp)

cand = []
for i in range(2**N):
	shojiki = [0]*N
	for j in range(N):
		if (i>>j & 1):
			shojiki[N-j-1]=1
	cand.append(shojiki)
# print(cand)

ans = []
for c in cand:
	list = [-1]*(N+1)
	success = True
	for idx,a in enumerate(A):
		# idxの人が正直者であると仮定
		if c[idx] == 1:
			for aa in a:
				if list[aa[0]] == -1:
					list[aa[0]] = aa[1]
				else:
					if list[aa[0]]!=aa[1]:
						success=False
		# そうでなければ、その人の発言は無視
		else:
			for aa in a:
				list[aa[0]] = 0 if aa[1] == 1 else 1
	for k in range(len(c)):
		if c[k]==1 and list[k+1]==0:
			success = False
		if c[k]==0 and list[k+1]==1:
			success = False
	if success:
		#print(c, list)
		ans.append(sum(c))
	
#print(ans)
print(max(ans))

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = []
for i in range(N):
	tmp = []
	n = INT()
	shougen = []
	for j in range(n):
		shougen = MAP()
		tmp.append(shougen)
	A.append(tmp)

cand = []
for i in range(2**N):
	shojiki = [0]*N
	for j in range(N):
		if (i>>j & 1):
			shojiki[N-j-1]=1
	cand.append(shojiki)
# print(cand)

ans = []
for c in cand:
	list = [-1]*(N+1)
	success = True
	ones = [a for idx,a in enumerate(A) if c[idx]==1]
	for idx,a in enumerate(ones):
		for aa in a:
			if list[aa[0]] == -1:
				list[aa[0]] = aa[1]
			else:
				if list[aa[0]]!=aa[1]:
					success=False
	for k in range(len(c)):
		if c[k]==1 and list[k+1]==0:
			success = False
		if c[k]==0 and list[k+1]==1:
			success = False
	if success:
		#print(c, list)
		ans.append(sum(c))
	
#print(ans)
if ans:
	print(max(ans))
else:
	print(0)
Buggy python submission (verdict: Time Limit Exceeded):
#encoding: utf-8
import sys

input = sys.stdin.readline
def MAP(): return [int(s) for s in input().split()]

N = int(input())
S = input()

# 入力の網羅は 30,000C3 の組み合わせとなり全探索は不可能
# 出力は000〜999までの10**3であり、3*10**4とのかけあわせで
# O(10**7)であれば、制限時間内に計算が可能（出力全探索による貪欲法）

# PIN[0]に該当する文字が入力Sから見つかった場合、
# そのSを利用するのが最も効果的であるので貪欲法が利用できる
# (最初に見つかったものを使うとのちのちの制約に引っかかる、というような場合はDPなどを考慮)

# s in S に対し、PIN[0]に該当するsがあれば PIN[1]に該当するsを探索、、という繰り返しで3桁分見つかればans+=1

ans = 0
for i in range(1000):
	pin = str(i).zfill(3)
	cnt = 0 # 該当するsのカウント
	idx = 0 # 探索するPINのインデックス
	for s in S:
		if s==pin[idx]:
			cnt += 1 # カウントアップ
			idx += 1 # インデックスをPINの次の文字へ送る
			if idx == 3:
				break
	if cnt == 3:
		#print(pin)
		ans += 1
				
print(ans)

Fixed submission:
#encoding: utf-8
import sys

input = sys.stdin.readline
def MAP(): return [int(s) for s in input().split()]

N = int(input())
S = input()

# 入力の網羅は 30,000C3 の組み合わせとなり全探索は不可能
# 出力は000〜999までの10**3であり、3*10**4とのかけあわせで
# O(10**7)であれば、制限時間内に計算が可能（出力全探索による貪欲法）

# PIN[0]に該当する文字が入力Sから見つかった場合、
# そのSを利用するのが最も効果的であるので貪欲法が利用できる
# (最初に見つかったものを使うとのちのちの制約に引っかかる、というような場合はDPなどを考慮)

# s in S に対し、PIN[0]に該当するsがあれば PIN[1]に該当するsを探索、、という繰り返しで3桁分見つかればans+=1

ans = 0
for i in range(1000):
	pin = str(i).zfill(3)
	cnt = 0 # 該当するsのカウント
	idx = 0 # 探索するPINのインデックス
	for s in S:
		if s==pin[idx]:
			cnt += 1 # カウントアップ
			idx += 1 # インデックスをPINの次の文字へ送る
			if idx == 3:
				break
	if cnt == 3:
		#print(pin)
		ans += 1
				
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools
sys.setrecursionlimit(10**6)
def MAP(): return [int(s) for s in input().split()]

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N = int(input())
S = input().rstrip()
s = [int(x) for x in S]

remove= list(itertools.combinations(range(len(S)), N-3))
#print('to remove: ', remove)

ans = []
for i in range(len(remove)):
	ans.append([num for idx,num in enumerate(s) if not idx in remove[i]])

#print('answer: ',ans)
answer = len(set(map(tuple, ans)))
print(answer)

Fixed submission:
#encoding: utf-8
import sys

input = sys.stdin.readline
def MAP(): return [int(s) for s in input().split()]

N = int(input())
S = input()

# 入力の網羅は 30,000C3 の組み合わせとなり全探索は不可能
# 出力は000〜999までの10**3であり、3*10**4とのかけあわせで
# O(10**7)であれば、制限時間内に計算が可能（出力全探索による貪欲法）

# PIN[0]に該当する文字が入力Sから見つかった場合、
# そのSを利用するのが最も効果的であるので貪欲法が利用できる
# (最初に見つかったものを使うとのちのちの制約に引っかかる、というような場合はDPなどを考慮)

# s in S に対し、PIN[0]に該当するsがあれば PIN[1]に該当するsを探索、、という繰り返しで3桁分見つかればans+=1

ans = 0
for i in range(1000):
	pin = str(i).zfill(3)
	cnt = 0 # 該当するsのカウント
	idx = 0 # 探索するPINのインデックス
	for s in S:
		if s==pin[idx]:
			cnt += 1 # カウントアップ
			idx += 1 # インデックスをPINの次の文字へ送る
			if idx == 3:
				break
	if cnt == 3:
		#print(pin)
		ans += 1
				
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
import itertools

x, y = [int(x) for x in input().split()]

total_move = int((x+y) /3)
move_a = 2 * total_move - x

print(math.factorial(total_move) // (math.factorial(total_move - move_a) * math.factorial(move_a)))

Fixed submission:
import math
import itertools
import sys

x, y = [int(x) for x in input().split()]

if (x+y) % 3:
  print(0)
  sys.exit()

total_move = (x+y) // 3
move_a = 2 * total_move - x

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = total_move
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

a = cmb(total_move,move_a,mod)

print(a)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N = int(input())
L = [int(x) for x in input().split()]

#i+j>k and i+k>j and j+k>i

N_2 = int(N/2)+1

L.sort()

ans=0
for i in range(0, N-1):
	for j in range(1, N-1):
		for k in range(N-1, N_2-3, -1):
			#print(i,j,k,'=',L[i],L[j],L[k])
			if i>=j or j>=k or i>=k:
				#print('skip')
				continue
			elif L[i]+L[j]>L[k]:
				ans+=1
				#print('here')
print(ans)

Fixed submission:
import sys
import bisect

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N = int(input())
L = [int(x) for x in input().split()]
L.sort()

ans=0
for i in range(0, N-1):
	for j in range(1, N-1):
		if i>=j:
			continue
		ans += bisect.bisect_left(L, L[i]+L[j], lo=j+1)-1-j
print(ans)