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

N, X, M = map(int, input().split())
ind = 0
l = [X]
while True:
  t = l[-1] ** 2 % M
  if t not in l:
    l.append(t)
  else:
    ind = l.index(t)
    break
S = sum(l[ind:])
L = len(l)
ans = 0
if N <= L:
  ans = sum(l[:N])
else:
  ans = sum(l)
  N -= L
  ans += S * (N // (L - ind))
  ans += sum(l[ind:ind+(N % (L - ind))])
print(ans)

### FIXED CODE ###

N, X, M = map(int, input().split())
checklist = [True] * 100000
ind = 0
l = [X]
while True:
  t = l[-1] ** 2 % M
  if checklist[t]:
    l.append(t)
    checklist[t] = False
  else:
    ind = l.index(t)
    break
S = sum(l[ind:])
L = len(l)
ans = 0
if N <= L:
  ans = sum(l[:N])
else:
  ans = sum(l)
  N -= L
  ans += S * (N // (L - ind))
  ans += sum(l[ind:ind+(N % (L - ind))])
print(ans)
### BUGGY CODE ###

N = int(input())
nums = list(map(int, input().split()))
ans = 10**9
for num in nums:
  div_num = num
  cnt = 0
  while True:
    if num%2 == 0:
      div_num = num//2
      cnt += 1
    else:
      ans = min(ans, cnt)
      break
print(ans)

### FIXED CODE ###

N = int(input())
nums = list(map(int, input().split()))
ans = 0
while True:
  for idx, num in enumerate(nums):
    if num%2 != 0:
      print(ans)
      exit()
    else:
      nums[idx] = num//2
  ans += 1
### BUGGY CODE ###

n,k = map(int, input().split())
p = [int(x) for x in input().split()]

max = -1
ans=0


for i in range(0,n-k+2):
    buf = p[i:i+k]
    tmp = sum(buf)
    if tmp > max:
        max = tmp
        li = p[i:i+k]

for j in range(len(li)):
    ans += (1+li[j])/2
    
print(ans)


### FIXED CODE ###

n,k = map(int, input().split())
p = [int(x) for x in input().split()]

li = []
count=0
ans = 0

for i in range(len(p)):
    p[i] += 1
    li.append(p[i])
    if len(li) < k:
        continue
    elif len(li) == k:
        max = sum(li)
        buf = max
    elif len(li) > k:
        tmp = buf - li[count] + li[-1]
        buf = tmp
        if tmp >= max:
            max = tmp
        count+=1

print(max/2)
### BUGGY CODE ###

from collections import defaultdict

s=input()
d=defaultdict(int)

dp=0
d[0]+=1
for i in range(len(s)-1,-1,-1):
	dp = (dp+int(s[i])*(10**(len(s)-1-i)))%2019
	d[dp]+=1
res=0

l=list(d.values())
for a in l:
	res+=a*(a-1)//2
	
print(res)

### FIXED CODE ###

s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)
### BUGGY CODE ###

N = int(input())

s = set()

for _ in range(N):

    A = int(input())

    if A in s:
        s = s - set({A})
    else:
        s.add(A)

print(len(s))


### FIXED CODE ###

N = int(input())
d = {}
a = []
for _ in range(N):
    A = int(input())
    a.append(A)
    if not(A in d):
        d[A] = 1
        continue
    elif d[A]==1:
        d[A] = 0
    else:
        d[A] = 1

ans = 0
for key in d:
    if d[key]==1:
        ans = ans + 1
print(ans)
### BUGGY CODE ###

N = int(input())
# A[0]
A = list(map(lambda x: int(x)-1, [input() for n in range(N)]))
#[int(input())-1]
 
count = [-1]*N
n = 0
ans = 1
for k in range(N+1):
  if A[n] == 2-1:
    break

  elif A[n] in count:
    ans = -1
    break
  
  else:
    count[n] = A[n]
    ans += 1
    n = A[n]
 
print(ans)

### FIXED CODE ###

n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append(a)
 
al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)
### BUGGY CODE ###

n, k, l = map(int, input().split())
load = [-1] * (n + 1)
train = [-1] * (n + 1)

def find_load(x, u = load):
    if u[x] < 0 :
        return x
    else:
        return find_load(u[x])

def find_train(x, u = train):
    if u[x] < 0 :
        return x
    else:
        return find_train(u[x])

for i in range(k):
    p, q = map(int, input().split())
    p, q = map(find_load, [p, q])
    p, q = sorted((p, q))
    if p != q:
        load[p] += load[q]
        load[q] = p

for i in range(l):
    r, s = map(int, input().split())
    r, s = map(find_train, [r, s])
    r, s = sorted((r, s))
    if r != s:
        train[r] += train[s]
        train[s] = r

load = [find_load(x) if x > 0 else x for x in load]

train = [find_train(x) if x > 0 else x for x in train]

load = [i if x < 0 else x for i, x in enumerate(load)]

train = [i if x < 0 else x for i, x in enumerate(train)]

ans = []
for x, y in zip(load, train):
    if x == -1 or y == -1:
        ans.append(1)
    else:
        ans.append(sum([(x == X and y == Y) for X, Y in zip(load,train)]))

print(*ans[1:])

### FIXED CODE ###

n, k, l = map(int, input().split())
load = [-1] * (n + 1)
train = [-1] * (n + 1)

def find_load(x, u = load):
    if u[x] < 0 :
        return x
    else:
        u[x] = find_load(u[x])
        return u[x]

def find_train(x, u = train):
    if u[x] < 0 :
        return x
    else:
        u[x] = find_train(u[x])
        return u[x]

for i in range(k):

    p, q = map(int, input().split())
    p, q = map(find_load, [p, q])
    p, q = sorted((p, q))
    if p != q:
        load[q] = p

load = [i if x < 0 else x for i, x in enumerate(load)]

for i in range(l):
    r, s = map(int, input().split())
    r, s = map(find_train, [r, s])
    r, s = sorted((r, s))
    if r != s:
        train[s] = r
train = [i if x < 0 else x for i, x in enumerate(train)]

keys = []
dic  = {}

for node in range(n):
    key = (find_load(load[node + 1]), find_train(train[node + 1]))
    keys.append(key)
    if key in dic:
        dic[key] += 1
    else:
        dic[key] = 1

ans = [str(dic[key]) for key in keys]
print(" ".join(ans))
### BUGGY CODE ###

import math
A, B, N = map(int, input().split())
ans = []
for x in range(N//(10**7), N+1):
    cal = math.floor((A*x)/B) - (int(A) * math.floor(x/B))
    ans.append(cal)
print(max(ans))

### FIXED CODE ###

a, b, n = map(int, input().split())
n = min(n, b-1)
 
print(int((a * n) / b) - a * int(n / b))
### BUGGY CODE ###

n=int(input())
p_base=list(map(int,input().split()))
p={}
for i in range(1,n+1):
    p[i]=p_base[i-1]
count=0
for i in range(1,n+1):
    
    if i==1:
        count+=1
    else:
        count2=0
        for j in range(1,i):
            if p[i]>p[j]:
                count2+=1
        if count2==0:
            count+=1
print(count)
        


### FIXED CODE ###

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

count=0
min=p[0]
for i in range(n):
    if p[i]<=min:
        count+=1
        min=p[i]
print(count)
### BUGGY CODE ###

import sys
import numpy as np
if __name__ == '__main__':
    NX = [int(n) for n in input().split()]
    X = [int(n) for n in input().split()]
    X.append(NX[1])
    # if len(X) == 1:
    #     print(abs(X[0]-NX[1]))
    #     sys.exit(0)

    X.sort()
    diff = [X[i] - X[i-1] for i in range(1, len(X))]
    D = min(diff)
    while any(np.array(diff)%D):
        D -= 1
    print(D)

### FIXED CODE ###

import sys
import functools
import fractions

if __name__ == '__main__':
    NX = [int(n) for n in input().split()]
    X = [int(n) for n in input().split()]
    if len(X) == 1:
        print(abs(X[0]-NX[1]))
        sys.exit(0)

    X.append(NX[1])
    X.sort()
    diff = [X[i] - X[i-1] for i in range(1, len(X))]
    D = functools.reduce(fractions.gcd, diff)
    print(D)
    # D = min(diff)
    # while any(np.array(diff)%D):
    #     D -= 1
    # print(D)
### BUGGY CODE ###

from bisect import bisect_left

N,Q = map(int, input().split())
STX = []
for i in range(N):
  *stx, = list(map(int, input().split()))
  STX.append(stx)
D = []
for i in range(Q):
  D.append(int(input()))

STX = sorted(STX, key=lambda x: x[2])

DI = [i for i in range(Q)]
ANS = [-1]*Q
for (s,t,x) in STX:
  s2 = (s - x)
  t2 = (t - x)

  D_sub = [D[di] for di in DI]
  start = bisect_left(D_sub, s2)
  end = bisect_left(D_sub, t2, lo=start)
    
  #print(start, end, DI)
  DI_copy = DI[:]
  while (start < end):
    di = DI_copy[start]
    ANS[di] = x
    DI.remove(di)
    start += 1

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


### FIXED CODE ###

import sys
from bisect import bisect_left
input = sys.stdin.readline

N,Q = map(int, input().split())
STX = [list(map(int, input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]

STX = sorted(STX, key=lambda x: x[2])

MASK = [-1]*Q
ANS = [-1]*Q

for (s,t,x) in STX:
  s2 = (s - x)
  t2 = (t - x)

  start = bisect_left(D, s2)
  end = bisect_left(D, t2, lo=start)

  #print(start, end, DI)
  while (start < end):
    if (-1 == MASK[start]):
      ANS[start] = x
      MASK[start] = end
      start += 1
    else:
      start = MASK[start]


print(*ANS, sep='\n')
### BUGGY CODE ###

n=int(input())
s=[input() for _ in range(n)]
ls=[0]*n

for i in s:
  ls[s.index(i)]+=1
  
maxcount=max(ls)
li=[]

for i in s:
  if s.count(i)==maxcount:
    li.append(i)
    
lis=[]
for i in li:
  if i in lis:
    pass
  else:
    lis.append(i)
    
lis=sorted(lis)
for i in lis:
  print(i)

### FIXED CODE ###

n=int(input())
s=[input() for _ in range(n)]
s.sort()
ans,be=[],""
cnt,maxcount=1,0

for i in range(n):
  if be==s[i]:
    cnt+=1
    
  else:
    if cnt>=1:
      if cnt>maxcount:
        maxcount=cnt
        ans.clear()
        ans.append(be)
      
      elif cnt==maxcount:
        ans.append(be)
      
      cnt=1
  be=s[i]
  if i==n-1:
    if cnt>=1:
      if cnt>maxcount:
        maxcount=cnt
        ans.clear()
        ans.append(be)
      
      elif cnt==maxcount:
        ans.append(be)
    
ans.sort()
for i in ans:
  if i!="":
    print(i)
### BUGGY CODE ###

input()
s = list(map(int, input().split()))
input()
t = list(map(int, input().split()))

cnt = 0
for i in t:
    if i in s:
        cnt += 1
print(cnt)


### FIXED CODE ###

def binary_search(ary, key, imin, imax):
    if imax < imin:
        return False
    else:
        imid = imin + (imax - imin) // 2
        if ary[imid] > key:
            return binary_search(ary, key, imin, imid - 1)
        elif ary[imid] < key:
            return binary_search(ary, key, imid + 1, imax)
        else:
            return True

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

cnt = 0
for i in t:
    if binary_search(s, i, 0, n-1):
        cnt += 1
print(cnt)
### BUGGY CODE ###

from collections import deque

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

stack = deque()

stack.appendleft((0, 1000, 0))
max_money = 1000

while stack:
    target = stack.popleft()

    day = target[0]
    money = target[1]
    stock = target[2]

    if day + 1 <= N:
        max_buy = money // A[day]
        max_fee = stock * A[day]

        stack.appendleft((day + 1, money + stock * A[day], 0))
        stack.appendleft(
            (day + 1, money - (money // A[day]) * A[day], money // A[day]))
    else:
        if max_money < money:
            max_money = money

print(max_money)


### FIXED CODE ###

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

money = 1000
stock = 0

for i in range(N-1):
    if A[i] <= A[i+1]:
        stock += money // A[i]
        money -= (money // A[i]) * A[i]
    else:
        money += A[i] * stock
        stock = 0

print(money + stock * A[N-1])
### BUGGY CODE ###

K , S = map(int, input().split())
x , y , z , cnt = 0 , 0 , 0 , 0
A = K + 1
if K * 3 == S:
    cnt = 1
else :
    for i in range(A):
        x = i
        for j in range(A):
            y = j
            for k2 in range(A) :
                z = k2
                if x + y + z == S:
                    cnt += 1

print(cnt)


### FIXED CODE ###

K , S = map(int, input().split())
x , y , z , cnt = 0 , 0 , 0 , 0
A = K + 1
if K * 3 == S:
    cnt = 1
else :
    for i in range(A):
        for j in range(A):
            if  S - (i + j) <= K :
                if 0 <= S - (i + j): 
                    cnt += 1
print(cnt)
### BUGGY CODE ###

import sys
import numpy as np

sys.setrecursionlimit(10000)
INF = float('inf')

H, W = list(map(int, input().split()))
A = [list(input()) for _ in range(H)]

counts = np.empty((H, W))
counts.fill(np.inf)


def ok_range(h, w):
    return 0 <= h < H and 0 <= w < W


# 左上から右下へ DP してく
for i in range(H * W):
    for j in range(i + 1):
        h = j
        w = i - j
        if not ok_range(h, w):
            continue
        if A[h][w] == '#':
            counts[h][w] = 0
        else:
            counts[h][w] = min(
                counts[h][w],
                counts[h - 1][w] + 1 if ok_range(h - 1, w) else INF,
                counts[h][w - 1] + 1 if ok_range(h, w - 1) else INF,
            )

# 左下から右上へ
for i in range(H * W):
    for j in range(i + 1):
        h = H - j - 1
        w = i - j
        if not ok_range(h, w):
            continue
        if A[h][w] == '#':
            counts[h][w] = 0
        else:
            counts[h][w] = min(
                counts[h][w],
                counts[h + 1][w] + 1 if ok_range(h + 1, w) else INF,
                counts[h][w - 1] + 1 if ok_range(h, w - 1) else INF,
            )

# 右上から左下
for i in range(H * W):
    for j in range(i + 1):
        h = j
        w = W - (i - j) - 1
        if not ok_range(h, w):
            continue
        if A[h][w] == '#':
            counts[h][w] = 0
        else:
            counts[h][w] = min(
                counts[h][w],
                counts[h - 1][w] + 1 if ok_range(h - 1, w) else INF,
                counts[h][w + 1] + 1 if ok_range(h, w + 1) else INF,
            )

# 右下から左上
for i in range(H * W):
    for j in range(i + 1):
        h = H - j - 1
        w = W - (i - j) - 1
        if not ok_range(h, w):
            continue
        if A[h][w] == '#':
            counts[h][w] = 0
        else:
            counts[h][w] = min(
                counts[h][w],
                counts[h + 1][w] + 1 if ok_range(h + 1, w) else INF,
                counts[h][w + 1] + 1 if ok_range(h, w + 1) else INF,
            )

print(int(counts.max()))


### FIXED CODE ###

import sys
import numpy as np

sys.setrecursionlimit(10000)
INF = float('inf')

H, W = list(map(int, input().split()))
A = np.array([list(input()) for _ in range(H)])

counts = np.zeros((H, W))
counts[A == '.'] = np.inf

for h in range(1, H):
    counts[h, :] = np.minimum(counts[h, :], counts[h - 1, :] + 1)
    counts[-1 - h, :] = np.minimum(counts[-1 - h, :], counts[-h, :] + 1)
for w in range(1, W):
    counts[:, w] = np.minimum(counts[:, w], counts[:, w - 1] + 1)
    counts[:, -1 - w] = np.minimum(counts[:, -1 - w], counts[:, -w] + 1)

print(int(np.max(counts)))
### BUGGY CODE ###

import sys
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]


NN = 10 ** 6 + 100
primes = []
isprime = [True for _ in range(NN + 1)]
min_factor = [-1 for _ in range(NN + 1)]
#エラトステネスの篩
for i in range(2, NN + 1):
    if not isprime[i]:
        continue
    primes.append(i)
    min_factor[i] = i
    for j in range(i * 2, NN + 1, i):
        isprime[j] = False
        if min_factor[j] == -1:
            min_factor[j] = i
def prime_factrize(n):
    res = []
    while n != 1:
        prime = min_factor[n]
        exp = 0
        while min_factor[n] == prime:
            exp += 1
            n //= prime
        res.append([prime, exp])
    return res


n = INT()
a = LIST()
ll = []
for i in range(n):
    aa = prime_factrize(a[i])
    for j in range(len(aa)):
        tmp = [ll[k][0] for k in range(len(ll))]
        if aa[j][0] in tmp:
            idx = tmp.index(aa[j][0])
            ll[idx][1] = max(ll[idx][1], aa[j][1])
        else:
            ll.append(aa[j])
l = 1
for i in range(len(ll)):
    l *= pow(ll[i][0], ll[i][1], mod)
ans = 0
for i in range(n):
    ans += l // a[i]
    ans %= mod
print(ans)


### FIXED CODE ###

import sys
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
l = 1
for i in a:
    l = lcm(l, i)
l %= mod
ans = 0
for i in a:
    ans += l * pow(i, mod - 2, mod)
print(ans % mod)
### BUGGY CODE ###

n = int(raw_input())
a = map(int, raw_input().split())
a.append(0)
for i in range(n):
    c = 0
    p = 0
    for j in range(n+1):
        if j == i:
            continue
        c += abs(a[j] - p)
        p = a[j]
    print c


### FIXED CODE ###

n = int(raw_input())
a = [0] + map(int, raw_input().split()) + [0]
s = 0
for i in range(n+1):
    s += abs(a[i+1] - a[i])
for i in range(1,n+1):
    print s + abs(a[i+1] - a[i-1]) - (abs(a[i+1] - a[i]) + abs(a[i] - a[i-1]))
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = [str(a.index(i)+1) for i in range(1,n+1) ]
print(' '.join(ans))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = [0 for _ in range(n)]
for i, A in enumerate(a):
  ans[A-1] = str(i+1)
print(' '.join(ans))
### BUGGY CODE ###

import fractions

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

def lcm(x, y):
	return (x * y) // fractions.gcd(x, y)

num = a[0]
to = a[0]
for i in range(1, n):
	num = lcm(num, a[i])
	to *= a[i]

ans = 0
for i in range(n):
	ans += to//a[i]
print(((num*ans)//to)%1000000007)


### FIXED CODE ###

import fractions
 
n = int(input())
a = list(map(int, input().split()))
 
l = 1
for i in range(n):
	l = l // fractions.gcd(l, a[i])*a[i]
 
ans = 0
for i in range(n):
	ans += l//a[i]
print(ans%(10**9+7))
### BUGGY CODE ###

import sys

input = sys.stdin.readline

from collections import deque

H, W = map(int, input().split())
a = [input() for _ in range(H)]

dist = [[-1] * W for _ in range(H)]
dq = deque()

for r in range(H):
    for c in range(W):
        if a[r][c] == '#':
            dist[r][c] = 0
            dq.append((r, c))


def in_range(r, c):
    return 0 <= r < H and 0 <= c < W


dr_s = (0, 0, -1, 1)
dc_s = (-1, 1, 0, 0)

d = 0
while dq:
    r, c = dq.popleft()
    d = dist[r][c]
    for dr, dc in zip(dr_s, dc_s):
        nr = r + dr
        nc = c + dc
        if not in_range(nr, nc): continue
        if dist[nr][nc] != -1: continue
        dist[nr][nc] = d + 1
        dq.append((nr, nc))

print(d)


### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
a = [input() for _ in range(H)]

dist = [[-1] * W for _ in range(H)]
dq = deque()

for r in range(H):
    for c in range(W):
        if a[r][c] == '#':
            dist[r][c] = 0
            dq.append((r, c))


def in_range(r, c):
    return 0 <= r < H and 0 <= c < W


dr_s = (0, 0, -1, 1)
dc_s = (-1, 1, 0, 0)

d = 0
while dq:
    r, c = dq.popleft()
    d = dist[r][c]
    for dr, dc in zip(dr_s, dc_s):
        nr = r + dr
        nc = c + dc
        if not in_range(nr, nc): continue
        if dist[nr][nc] != -1: continue
        dist[nr][nc] = d + 1
        dq.append((nr, nc))

print(d)
### BUGGY CODE ###

import numpy as np
X = int(input())

i = 0
while True:
    n = abs(i**5 - X)**(1/5)
    if n.is_integer():
        if (i**5 - X) < 0:
            n *= -1
        if i**5-n**5==X:
            print(i,int(n))
            break
    n = abs((-i)**5 - X)**(1/5)
    if n.is_integer():
        if (i**5 - X) < 0:
            n *= -1
        if i**5-n**5==X:
            print(i,int(n))
            break
    i += 1

### FIXED CODE ###

X = int(input())

flag = False
for i in range(150):
    for j in range(150):
        if i**5 - j**5 == X:
            print(i,j)
            flag = True
            break
        if (-i)**5 - j**5 == X:
            print(-i,j)
            flag = True
            break
        if i**5 - (-j)**5 == X:
            print(i,-j)
            flag = True
            break
        if (-i)**5 - (-j)**5 == X:
            print(-i,-j)
            flag = True
            break
    if flag:
        break
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
b = set(i for i in range(n))
ans = [0]*n
warizai_index = set()

for i in range(n):
    for wari in warizai_index:
        if a[i]%a[wari] == 0 and i != wari:
            ans[i] = 1
            if i in warizai_index:
                warizai_index.remove(i)
            break
    if ans[i] == 1:
        continue
    
    #for j in b:
    for j in range(n):
        if i == j:
            continue
        if a[i]%a[j] == 0:
            ans[i] = 1
            if i in warizai_index:
                warizai_index.remove(i)
            warizai_index.add(j)
            break

print(ans.count(0))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
aMax = a[-1]
ans = 0
dp = [1] * (aMax+1)

for i in range(n-1):
    p = a[i]
    if dp[p] == 1:
        for j in range(aMax//p+1):
            dp[p*j] = 0
        if a[i] != a[i+1]:
            ans += 1
if dp[aMax] == 1:
    ans += 1
print(ans)
### BUGGY CODE ###

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

ans = 0
for pin in ("%03d" % x for x in range(10 ** 3)):
    x = 0
    for c in S:
        if c == pin[x]:
            x += 1
            if x == 3:
                ans += 1
                break
print(ans)

### FIXED CODE ###

N = int(input())
S = tuple(map(int, input()))

ans = 0
pins = [0] * 3
for pin in range(1000):
    pins[0] = pin // 100
    pins[1] = (pin % 100) // 10
    pins[2] = pin % 10
    x = 0
    for c in S:
        if c == pins[x]:
            x += 1
            if x == 3:
                ans += 1
                break
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int):
    for i in range(1, 3501):
        for j in range(i, 3501):
            # dN, di, dj = Decimal(N), Decimal(i), Decimal(j)
            z = 4*i*j - N*j - N*i
            if z != 0:
                h, r = divmod((N*i*j), z)
                if r == 0 and 0 <= h:
                    print(h, i, j)
                    exit()
            

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int):
    for i in range(1, 3501):
        for j in range(i, 3501):
            z = 4*i*j - N*(j+i)
            if z > 0:
                h, r = divmod((N*i*j), z)
                if r == 0:
                    print(h, i, j)
                    exit()
            

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


# #!/usr/bin/env python3
# n = int(input())
# for i in range(1, 3501):
#   for j in range(1, 3501):
#     seed = 4 * i * j - n * (i + j) 
#     if seed > 0:
#       k, mod = divmod(n * i * j, seed) 
#       if mod == 0:
#         print(i, j, k)
#         exit()