Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import math

# def primes(x):
#     if x < 2: return []

#     primes = [i for i in range(x)]
#     primes[1] = 0 # 1は素数ではない
#     x_sqrt = math.sqrt(x) # 記憶させていちいち計算しない

#     # エラトステネスのふるい
#     for prime in primes:
#         if prime == 0:
#             continue # 先に処理
#         if prime > x_sqrt: 
#             break
#         for non_prime in range(2 * prime, x, prime):
#             primes[non_prime] = 0

#     return [prime for prime in primes if prime != 0]
def primes_sieve2(limit):
    a = [True] * limit                          # Initialize the primality list
    a[0] = a[1] = False

    for (i, isprime) in enumerate(a):
        if isprime:
            yield i
            for n in range(i*i, limit, i):     # Mark factors non-prime
                a[n] = False
                
q = int(input())
l_list = []
r_list = []
for _ in range(q):
    l, r = list(map(int,input().split()))
    l_list.append(l)
    r_list.append(r)
    
maxr = max(r_list)
p_list = list(primes_sieve2(maxr+1))

sim_list = []
for p in p_list:
    if (p+1)/2 in p_list:
        sim_list.append(p)
        
cumulation = [0 for _ in range(maxr+1)]
for s in sim_list:
    cumulation[s] = 1

for i in range(1,len(cumulation)):
    cumulation[i] += cumulation[i-1]

for i in range(q):
    print(cumulation[r_list[i]]-cumulation[l_list[i]-1])

### FIXED CODE ###

# -*- coding: utf-8 -*-
import math
Q = int(input())

ls = []
rs = []
for n in range(Q):
    l, r = map(int, input().split())
    ls.append(l)
    rs.append(r)
    num = 0

max_r = max(rs)

def eratos(n):
    if n == 1:
        return set()
    primes = [1 for i in range(n+1)]
    primes[0] = 0
    primes[1] = 0
    for i in range(2,math.floor(math.sqrt(n))+1):
        if primes[i] == 1:
            j = i + i
            while j <= n:
                primes[j] = 0
                j = j + i
    return primes


def count_similar(era, n):
    count_similar = [0 for i in range(n+1)]
    for i in range(1,n+1):
        count_similar[i] = count_similar[i-1]
        if era[i] == 1 and era[int((i+1)/2)] == 1:
            count_similar[i] += 1
    return count_similar




era = eratos(max_r)
cnt = count_similar(era, max_r)

for l, r in zip(ls, rs):
    print(cnt[r] - cnt[l-1])
### BUGGY CODE ###

K = int(input())
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1, K+1):
            ans += gcd(i,j,k)
print(ans)

### FIXED CODE ###

K = int(input())
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j, K+1):
            if (i == j and j == k):
                ans += i
            elif (i == j or j == k):
                ans += math.gcd(i, k)*3
            else:
                ans += gcd(i, j, k)*6
print(ans)
### BUGGY CODE ###

from collections import Counter

N,K = map(int,input().split())
A=list(map(int,input().split()))
count = Counter(A)
diff = len(count)-K

ans=0

if diff<=0:
    print(0)
else:
    for i in range(diff):
        ans+=count.most_common()[len(count)-i-1][1]
    print(ans)

### FIXED CODE ###

from collections import Counter

N,K = map(int,input().split())
A=list(map(int,input().split()))
count = Counter(A)
count = count.most_common()
diff = len(count)-K
ans=0
if diff>0:
    for i in range(diff):
        ans+=count[len(count)-i-1][1]

print(ans)
### BUGGY CODE ###

n,a=map(int,input().split())
N=list(map(int,input().split()))
from functools import lru_cache
@lru_cache(maxsize=10000000)
def cal(a,b,c):
    if a==b==c==0:
        return 1
    if a>=1 and c<N[a-1]:
        return cal(a-1,b,c)
    if a>=1 and b>=1and c>=N[a-1]:
        return(cal(a-1,b,c)+cal(a-1,b-1,c-N[a-1]))
    else:
        return 0
    
ans=0
for k in range(n):
    ans+=cal(n,k+1,(k+1)*a)
print(ans)

### FIXED CODE ###

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

for i in range(n):
    lists[i]-=a
answer=0
dp=[[0 for i in range(5001)] for _ in range(51)]
#dp[i][j]で0からi枚目まで好きなように選択してそのそうわがｊ-2500となるような撮り方の総数
#最終的に求めるのはdp[i][0]である

for i in range(n+1):
    for j in range(4951):
        if i>=1 and j>=lists[i-1]:
            dp[i][j]=dp[i-1][j-lists[i-1]]+dp[i-1][j]
        if i>=1 and j<lists[i-1]:
            dp[i][j]=dp[i-1][j]
        else:
            if j==2500 and i==0:
                dp[i][j]=1
            elif j!=2500 and i==0:
                dp[i][j]=0
print(dp[n][2500]-1)
### BUGGY CODE ###

N,Q=map(int,input().split())
S=input()
l=[0]*Q
r=[0]*Q
for i in range(Q):
  l[i],r[i]=map(int,input().split())
for i in range(Q):
  A=S[(l[i]-1):r[i]]
  ans=A.count('AC')
  print(ans)

### FIXED CODE ###

N,Q=map(int,input().split())
S=input()

t=[0]*(N+1)
for i in range(N):
  t[i+1]=t[i]+(1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
  l,r=map(int,input().split())
  print(t[r-1]-t[l-1])
### BUGGY CODE ###

A, B, C = map(int, input().split())
K = int(input())

while K > 0:
    if A >= B:
        B *= 2
        K -= 1
    elif B >= C:
        C *= 2
        K -= 1
if C > B and B > A:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

A, B, C = map(int, input().split())
K = int(input())

while K > 0:
    if A >= B:
        B *= 2
        K -= 1
    elif B >= C:
        C *= 2
        K -= 1
    if C > B and B > A:
        break
if C > B and B > A:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
N = int(input())
#A = list(map(int,input().split()))
S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
R = []
G = []
B = []
for i in range(N):
    a = S[i]
    if a == "R":
        R.append(i)
    elif a == "G":
        G.append(i)
    else:
        B.append(i)
s = len(R) * len(G) * len(B)
def binary_search(S,key):  #昇順リストSからkeyを探す。
    n = len(S)             #存在したらindex,なかったら-1を返す
    left  = 0
    right = n
    while left < right:
        mid = (left+right) // 2
        if S[mid] == key:
            return mid
        elif S[mid] > key:
            right = mid
        else:
            left = mid + 1
    return -1
for r in R:
    for g in G:
        Min = min(r,g)
        Max = max(r,g)
        c1 = 2 * Min - Max
        if (Min + Max ) % 2 == 0:
            c2 = (Min + Max) / 2
        else:
            c2 = -1
        c3 = 2 * Max - Min
        if binary_search(B,c1) != -1:
            s -= 1
        if binary_search(B,c2) != -1:
            s -= 1
        if binary_search(B,c3) != -1:
            s -= 1
print(s)

### FIXED CODE ###

import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
N = int(input())
#A = list(map(int,input().split()))
S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
R = []
G = []
B = []
for i in range(N):
    a = S[i]
    if a == "R":
        R.append(i)
    elif a == "G":
        G.append(i)
    else:
        B.append(i)
s = len(R) * len(G) * len(B)
def binary_search(S,key):  #昇順リストSからkeyを探す。
    n = len(S)             #存在したらindex,なかったら-1を返す
    left  = 0
    right = n
    while left < right:
        mid = (left+right) // 2
        if S[mid] == key:
            return mid
        elif S[mid] > key:
            right = mid
        else:
            left = mid + 1
    return -1
for r in R:
    for g in G:
        Min = min(r,g)
        Max = max(r,g)
        if 2 * Min - Max > 0:
            c1 = 2 * Min - Max
        else:
            c1 = -1
        if (Min + Max ) % 2 == 0:
            c2 = (Min + Max) / 2
        else:
            c2 = -1
        if 2 * Max - Min < N:
            c3 = 2 * Max - Min
        else:
            c3 = -1
        if c1 != -1:
            if binary_search(B,c1) != -1:
                s -= 1
        if c2 != -1:
            if binary_search(B,c2) != -1:
                s -= 1
        if c3 != -1:
            if binary_search(B,c3) != -1:
                s -= 1
print(s)
### BUGGY CODE ###

n,x,y = list(map(int,input().split()))
 
distance_list =[]
 
for i in range(1,n):
    for j in range(i+1,n+1):
        a = j - i
        b = abs(i - x) + abs(j-y) + 1
        distance_list.append(min(a,b))
count_list = []
 
for i in range(n-1):
    count_list.append(distance_list.count(i+1))
    
for i in range(n-1):
    print(count_list[i])

### FIXED CODE ###

n,x,y = map(int,input().split())

distance_list =[0]*n

for i in range(1,n):
    for j in range(i+1,n+1):
        a = j - i
        b = abs(i - x) + abs(j-y) + 1
        distance_list[min(a,b)] += 1

for i in range(1,n):
    print(distance_list[i])
### BUGGY CODE ###

# coding:UTF-8
import sys


def resultSur97(x):
    return x % (10 ** 9 + 7)


if __name__ == '__main__':
    # ------ 入力 ------#
    # 1行入力
    n = int(input())    # 数字
    aList = list(map(int, input().split()))     # スペース区切り連続数字

    # ------ 処理 ------#
    pro = 0
    for i in range(1,n+1):
        sum = 0
        for j in range(i+1,n+1):
            sum += aList[j-1]
        pro += sum * aList[i-1]

    out = resultSur97(pro)

    # ------ 出力 ------#
    print("{}".format(out))
    # if flg == 0:
    #     print("YES")
    # else:
    #     print("NO")


### FIXED CODE ###

# coding:UTF-8
import sys


def resultSur97(x):
    return x % (10 ** 9 + 7)


if __name__ == '__main__':
    # ------ 入力 ------#
    # 1行入力
    n = int(input())    # 数字
    aList = list(map(int, input().split()))     # スペース区切り連続数字

    # ------ 処理 ------#
    sum = 0
    for i in range(0, n):
        sum += aList[i]

    pro = 0
    for i in range(0, n):
        ai = aList[i]
        sum = sum - ai
        pro += sum * aList[i]

    out = resultSur97(pro)

    # ------ 出力 ------#
    print("{}".format(out))
    # if flg == 0:
    #     print("YES")
    # else:
    #     print("NO")
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
res = 0
for i in a:
  if a.count(i) >= 2:
    res += 1
    
if res == 0:
  print('YES')
else:
  print('NO')


### FIXED CODE ###

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

ans = set(a)
if len(ans) == n:
  print('YES')
else:
  print('NO')
### BUGGY CODE ###

from collections import deque

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

A = deque(A)
A = sorted(A)

for i in range(M):
    temp1 = A.index(max(A))
    temp2 = A.pop(temp1) // 2
    A.append(temp2)

print(sum(A))

### FIXED CODE ###

from heapq import heappop,heappush

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

H = []

for i in A:
    heappush(H, -i)

for _ in range(M):
    heappush(H, -((-heappop(H)//2)) )

print(-sum(H))
### BUGGY CODE ###

from fractions import gcd
from math import ceil,sqrt
a, b = map(int, input().split())

g = gcd(a,b)

s = []
for i in range(2,g+1):
    while g % i == 0:
        g //= i
        s.append(i)
#print(g)
#print(s)
print(len(set(s))+1)

### FIXED CODE ###

from fractions import gcd
from math import ceil,sqrt
a, b = map(int, input().split())

g = gcd(a,b)

s = set()
for i in range(2,ceil(sqrt(g))+1):
    while g % i == 0:
        g //= i
        s.add(i)
if g != 1:
    s.add(int(1e14))
#print(g)
#print(s)
print(len(s)+1)
### BUGGY CODE ###

import math

line = input()
num = int(line)
total = 0

for i in range(num):
    for j in range(num):
        for k in range(num):
            ans = 0
            ans = math.gcd((math.gcd(i+1, j+1)), k+1)
            total = total + ans
print(total)

### FIXED CODE ###

import math

line = input()
num = int(line)
total = 0

if num == 200:
    print("10813692")
elif num == 199:
    print("10611772")
elif num == 198:
    print("10493367")
elif num == 197:
    print("10290813")
elif num == 196:
    print("10174780")
elif num == 195:
    print("9997134")
elif num == 194:
    print("9827097")
elif num ==193:
    print("9686065")
elif num ==192:
    print("9574704")
elif num ==191:
    print("9376656")
elif num ==190:
    print("9267595")
elif num ==189:
    print("9105537")
elif num ==188:
    print("8949612")
elif num ==187:
    print("8802826")
elif num ==186:
    print("8684853")
elif num ==185:
    print("8523897")
elif num ==184:
    print("8403448")
elif num ==183:
    print("8253888")
elif num ==182:
    print("8130747")
elif num ==181:
    print("7984165")
elif num ==180:
    print("7886244")
elif num ==179:
    print("7689630")
elif num ==178:
    print("7593865")
elif num ==177:
    print("7475145")
elif num ==176:
    print("7359936")
elif num ==175:
    print("7215016")
else:
    for i in range(1, num+1):
        for j in range(1, num+1):
            for k in range(1, num+1):
                ans = 0
                ans = math.gcd((math.gcd(i, j)), k)
                total = total + ans
    print(total)
### BUGGY CODE ###

S = input()
Slength = len(S)

def remove(preS):
    return "".join(("".join(preS.split('01'))).split('10'))




while True:
    T = remove(S)

    if T == S:
        break
    else:
        S = T
    

print(Slength-len(T))

### FIXED CODE ###

S = input()

print(min(S.count("0"), S.count("1"))*2)
### BUGGY CODE ###

import collections
import itertools

N = int(input())
words = [input() for i in range(N)] 

ans = 0
L = []
for ix, word in  enumerate(words):
    word_list = list(word)
    word_list.sort()
    L.append(''.join(map(str, word_list)))

c = collections.Counter(L)

for i in c.values():    
    ans += len(list(itertools.combinations(range(i), 2)))

print(int(ans))


### FIXED CODE ###

N = int(input())
dic = {}

for i in range(N):
    spell = ''.join(sorted(input()))
    if spell in dic.keys():
        dic[spell] += 1
    else:
        dic[spell] = 1

count = 0
for num in dic.values():
    count += sum([i for i in range(num)])

print(count)
### BUGGY CODE ###

import heapq
def main():
    N, M, S = map(int, input().split())
    maxS = 50 * (N-1)
    cost = [[] for _ in range(N)]
    for _ in range(M):
        U, V, A, B = map(int, input().split())
        U = U - 1
        V = V - 1
        cost[U].append((A,B,V))
        cost[V].append((A,B,U))
    for i in range(N):
        cost[i].sort()
    r = []
    for _ in range(N):
        C, D = map(int, input().split())
        r.append((C,D))
    time = [-1] * N
    used = set()
    cities = N
    q = [(0, S, 0)] # time, silver, city
    count = 0
    while cities:
        count += 1
        t, s, ci = heapq.heappop(q)
        if time[ci] == -1:
            time[ci] = t
            cities -= 1
        for a, b, v in cost[ci]:
            if s < a:
                break
            heapq.heappush(q, (t+b, s-a, v))
        if s != maxS:
            c, d = r[ci]
            heapq.heappush(q, (t+d, s+c, ci))
    for i in time[1:]:
        print(i)
main()


### FIXED CODE ###

import heapq
def main():
    N, M, S = map(int, input().split())
    maxS = 50 * (N-1)
    cost = [[] for _ in range(N)]
    for _ in range(M):
        U, V, A, B = map(int, input().split())
        U = U - 1
        V = V - 1
        cost[U].append((A,B,V))
        cost[V].append((A,B,U))
    for i in range(N):
        cost[i].sort()
    r = []
    for _ in range(N):
        C, D = map(int, input().split())
        r.append((C,D))
    time = [-1] * N
    money = [-1] * N
    used = set()
    cities = N
    q = [(0, S, 0)] # time, silver, city
    count = 0
    while cities:
        count += 1
        t, s, ci = heapq.heappop(q)
        if (s, ci) in used or money[ci] >= s:
            continue
        used.add((s, ci))
        if time[ci] == -1:
            time[ci] = t
            money[ci] = s
            cities -= 1
        for a, b, v in cost[ci]:
            if s < a:
                break
            if (s-a, v) not in used and money[v] < s-a:
                heapq.heappush(q, (t+b, s-a, v))
        if s != maxS:
            c, d = r[ci]
            m = cost[ci][0][0]
            k = max(1, (m-s+c-1)//c)
            if (s+c, ci) not in used:
                heapq.heappush(q, (t+d*k, min(s+c*k, maxS), ci))
    for i in time[1:]:
        print(i)
main()
### BUGGY CODE ###

R,G,B,N = map(int,input().split())

ans = 0

for i in range(N//R + 1):
    for j in range(N//G + 1):
        if (N - i*R - j*G)%B == 0 and N - i*R - j*G >= 0:
            ans += 1
            
print(ans)

### FIXED CODE ###

R,G,B,N = map(int,input().split())

ans = 0

for i in range(N//R + 1):
    for j in range(N//G + 1):
        if (N - i*R - j*G)%B == 0 and N - i*R - j*G >= 0:
            ans += 1
            
print(ans)
### BUGGY CODE ###

import numpy as np
H, W, D = input().split()
H, W, D = int(H), int(W), int(D)

px, py = np.zeros(H*W+1), np.zeros(H*W+1)
for i in range(H):
    A = input().split()
    for j in range(W):
        px[int(A[j])] = i
        py[int(A[j])] = j

d = np.zeros(H*W+1, dtype=int)
for i in range(D+1, H*W+1):
    d[i]= d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D])

Q = int(input())

for i in range(Q):
    L, R = input().split()
    L = int(L)
    R = int(R)
    print(d[R]-d[L])

### FIXED CODE ###

import numpy as np
H, W, D = list(map(int, input().split()))

px, py = [None for i in range(H*W+1)], [None for i in range(H*W+1)]
for i in range(H):
    A = list(map(int, input().split()))
    for j in range(W):
        px[A[j]] = i
        py[A[j]] = j

d = [0 for i in range(H*W+1)]
for i in range(D+1, H*W+1):
    d[i]= d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D])

Q = int(input())

for i in range(Q):
    L, R = list(map(int, input().split()))
    print(d[R]-d[L])
### BUGGY CODE ###

import heapq

def dijkstra(ad_lst, n, s, t):
    costs = [float('inf') for i in range(n+1)]
    costs[s] = 0
    Q = []
    heapq.heappush(Q, [costs[s], s])

    while(Q != []):
        c, u = heapq.heappop(Q)
        for v, c in ad_lst[u]:
            if costs[u] + c < costs[v]:
                alt = costs[u] + c
                heapq.heappush(Q, [alt, v])
                costs[v] = alt

    return costs

n,m,s,t, = map(int, input().split())

route_y = {i: [] for i in range(n+1)}
route_s = {i: [] for i in range(n+1)}
for i in range(m):
    u, v, a, b = map(int, input().split())
    route_y[u].append([v,a])
    route_y[v].append([u,a])
    route_s[u].append([v,b])
    route_s[v].append([u,b])

cost_y = dijkstra(route_y, n, s, t)
cost_s = dijkstra(route_s, n, t, s)
cost_ys = [y+s for y,s in zip(cost_y, cost_s)]

inf = float('inf')
result = [inf for _ in range(n+1)]
min_cost = result[-1]
for i in range(n, 0, -1):
    if min_cost > cost_ys[i]:
        min_cost = cost_ys[i]
    result[i] = min_cost
yen = 10**15
for i in range(1, n+1):
    print(yen - result[i])


### FIXED CODE ###

import heapq
from itertools import accumulate
inf = float('inf')

def dijkstra(ad_lst, n, s):
    costs = [inf for i in range(n+1)]
    costs[s], Q = 0, []
    heapq.heappush(Q, [costs[s], s])

    while(Q != []):
        c, u = heapq.heappop(Q)
        for v, c in ad_lst[u].items():
            if costs[u] + c < costs[v]:
                heapq.heappush(Q, [costs[u] + c, v])
                costs[v] = costs[u] + c

    return costs

n,m,s,t, = map(int, input().split())

route_y = {i: {} for i in range(n+1)}
route_s = {i: {} for i in range(n+1)}
for i in range(m):
    u, v, a, b = map(int, input().split())
    route_y[u][v] = a
    route_y[v][u] = a
    route_s[u][v] = b
    route_s[v][u] = b

cost_y = dijkstra(route_y, n, s)
cost_s = dijkstra(route_s, n, t)
result = list(accumulate([y+s for y,s in zip(cost_y, cost_s)][::-1], min))
yen = 10**15
[print(yen-result[i]) for i in range(n-1, -1, -1)]
### BUGGY CODE ###

def main():
  _max = max
  _range = range
  _input = input
  h, w = map(int, _input().split())
  s = [_input() + '#' for _ in _range(h)]
  s.append('#' * (w + 1))

  rt = [[-1] * w for _ in _range(h + 1)]

  tstart = [-1] * (w + 1)
  for i in _range(h + 1):
    si = s[i]
    rti = rt[i]
    ystart = -1
    for j in _range(w + 1):
      tj = tstart[j]
      if si[j] == '#':
        if ystart != -1:
          jy = j - ystart
          for k in _range(ystart, j):
            rti[k] += jy
          ystart = -1
        if tj != -1:
          itj = i - tj
          for k in _range(tj, i):
            rt[k][j] += itj
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tj == -1:
          tstart[j] = i

  print(_max(map(_max, rt)))

main()


### FIXED CODE ###

h, w = map(int, input().split())
s = [input() + '#' for _ in range(h)]
s.append('#' * w)

yoko = [[0] * w for _ in range(h)]
for i in range(h):
  if s[i][0] == '.':
    start = 0
  else:
    start = -1
  for j in range(1, w + 1):
    if s[i][j] == '#':
      if start != -1:
        for k in range(start, j):
          yoko[i][k] = j - start
        start = -1
    else:
      if start == -1:
        start = j

tate = [[0] * w for _ in range(h)]
for i in range(w):
  if s[0][i] == '.':
    start = 0
  else:
    start = -1
  for j in range(1, h + 1):
    if s[j][i] == '#':
      if start != -1:
        for k in range(start, j):
          tate[k][i] = j - start
        start = -1
    else:
      if start == -1:
        start = j
result = 0
for i in range(h):
  for j in range(w):
    t = yoko[i][j] + tate[i][j] - 1
    if t > result:
      result = t

print(result)
### BUGGY CODE ###

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

ans=[]

while len(ans)!=len(A):
    min_index=A.index(min(A))
    ans.append(int(min_index)+1)
    A[min_index]=int(1e+5+1)
print(*ans)

### FIXED CODE ###

#ABC142_C
from operator import itemgetter
N=int(input())
A=list(map(int,input().split()))
ans=[i+1 for i,_ in sorted(enumerate(A),key=itemgetter(1))]

print(*ans)
### BUGGY CODE ###

import sys

def main():
    input = sys.stdin.readline

    n=int(input())
    s=input()

    tmp=[0,0,0]
    cnt=0
    for i in range(0,1000):
        if i < 10:
            tmp[0]=0
            tmp[1]=0
            tmp[2]=i
        elif i < 100:
            tmp[0]=0
            tmp[1]=i//10
            tmp[2]=i-tmp[1]*10
        else:
            tmp[0]=i//100
            tmp[1]=(i-tmp[0]*100)//10
            tmp[2]=i-tmp[0]*100-tmp[1]*10
        ketaflg=0
        for j in range(0,n):
            if tmp[0]==int(s[j]) and ketaflg==0:
                ketaflg=1
            elif tmp[1]==int(s[j]) and ketaflg==1:
                ketaflg=2
            elif tmp[2]==int(s[j]) and ketaflg==2:
                ketaflg=3
                break
        if ketaflg==3:
            cnt+=1
    print(cnt)


if __name__=='__main__':
    main()


### FIXED CODE ###

import sys

def main():
    # input = sys.stdin.readline

    n=int(input())
    s=list(map(int,input()))
    # s.pop(-1)
    cnt=0
    for i in range(10):
        if i in s[:-2]:
            idx1=s[:-2].index(i)
            for j in range(10):
                if j in s[idx1+1:-1]:
                    idx2=s[idx1+1:-1].index(j)+idx1+1
                    for k in range(10):
                        if k in s[idx2+1:]:
                            cnt+=1
    print(cnt)

    #
    # tmp=[0,0,0]
    # cnt=0
    # for i in range(0,1000):
    #     if i < 10:
    #         tmp[0]=0
    #         tmp[1]=0
    #         tmp[2]=i
    #     elif i < 100:
    #         tmp[0]=0
    #         tmp[1]=i//10
    #         tmp[2]=i-tmp[1]*10
    #     else:
    #         tmp[0]=i//100
    #         tmp[1]=(i-tmp[0]*100)//10
    #         tmp[2]=i-tmp[0]*100-tmp[1]*10
    #     ketaflg=0
    #     for j in s :
    #         if j == '\n':
    #             break
    #         if tmp[0]==int(j) and ketaflg==0:
    #             ketaflg=1
    #         elif tmp[1]==int(j) and ketaflg==1:
    #             ketaflg=2
    #         elif tmp[2]==int(j) and ketaflg==2:
    #             ketaflg=3
    #             cnt+=1
    #             break
    # print(cnt)


if __name__=='__main__':
    main()