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

import sys
from collections import deque

n,m=map(int,input().split())
arr=[[0]*n for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    arr[a-1][b-1]=1
    arr[b-1][a-1]=1

arr2=[0]*n
for i in range(n):
    tmp=[]
    for j in range(n):
        if arr[i][j]==1:
            tmp.append(j)
    arr2[i]=tuple(tmp)
    if len(arr2[i])==0:
        print('No')
        sys.exit()


def bfs(d):
    que=deque()
    que.append(0)
    ans=[0]*n
    while que:
        x=que.popleft()
        if x==0:
            for j in range(n):
                if arr[0][j]==1:
                    ans[j]=1
                    que.append(j)
        else:
            for i in arr2[x]:
                if ans[i]==0 and i!=0:
                    ans[i]=x+1
                    que.append(i)
    print('Yes')
    for i in range(1,n):
        print(ans[i])        

bfs(arr)

### FIXED CODE ###

import sys
from collections import deque

n,m=map(int,input().split())
arr=[[]*n for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    arr[a-1].append(b-1)
    arr[b-1].append(a-1)

for i in range(n):
    if len(arr[i])==0:
        print('No')
        sys.exit()

def bfs(d):
    que=deque()
    que.append(0)
    ans=[0]*n
    while que:
        x=que.popleft()
        if x==0:
            for i in arr[x]:
                ans[i]=1
                que.append(i)
        else:
            for i in arr[x]:
                if ans[i]==0 and i!=0:
                    ans[i]=x+1
                    que.append(i)
    print('Yes')
    for i in range(1,n):
        print(ans[i])        

bfs(arr)
### BUGGY CODE ###

import math
import fractions
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

def is_prime(num):
    for i in range(2, num):  # 第二引数は sqrt(num)+1 でも良い
        if num % i == 0:
            return False

    return True

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

g = fractions.gcd(A, B)

# print(g)
div = make_divisors(g)
# print()
p = [i for i in div[:int((len(div))/2)+1] if is_prime(i)]
# print(p)
print(len(p))

### FIXED CODE ###

import math
import fractions
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

def is_prime(p):
    if p == 1:
        return False
    for i in range(2,int(p ** .5) + 1):
        if p % i == 0:
            return False
    return True

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

g = fractions.gcd(A, B)

div = make_divisors(g)
ans = 1
for i in div:
    if is_prime(i):
        ans += 1
print(ans)
### BUGGY CODE ###

N = int(input())
H = input().split()

for i in range(N):
  H[i] = int(H[i])

Cnt = 0
MaxCnt = 0

if (N == 1):
  print(0)
else:
  for i in range(N-1):
    Cnt = 0
    for j in range(i, N-1, 1):
      if (H[j] >= H[j+1]):
        Cnt += 1
      else:
        break
    MaxCnt = max(Cnt, MaxCnt)
  print(MaxCnt)

### FIXED CODE ###

N = int(input())
H = input().split()

for i in range(N):
  H[i] = int(H[i])

Cnt = 0
MaxCnt = 0

if (N == 1):
  print(0)
else:
  i = 0
  while(i < N-1):
    Cnt = 0
    for j in range(i, N-1, 1):
      if (H[j] >= H[j+1]):
        Cnt += 1
        if (j == N-2):
          i = j+1
      else:
        i = j+1
        break
    MaxCnt = max(Cnt, MaxCnt)
  print(MaxCnt)
### BUGGY CODE ###

n,k = (int(x) for x in input().split())
list = list(map(int, input().split()))
list2=[]
for i in range(0,n-k+1):
	su = sum(list[i:i+k])
	list2.append(su)
print((max(list2)+k)/2)

### FIXED CODE ###

n,k = (int(x) for x in input().split())
list = list(map(int, input().split()))
max=0
list2=[0]
for i in range(n):
	list2.append(list2[i]+list[i])
for i in range(n-k+1):
	if max < list2[i+k] - list2[i]:
		max=list2[i+k]-list2[i]
print((max+k)/2)
### BUGGY CODE ###

num=int(input())
lst=[]
counter =0
for i in range(num):
    s=input()
    if s not in lst:
        lst.append(s)
        counter+=1
print(counter)

### FIXED CODE ###

num=int(input())
lst=[]
if 1<=num<=2*10**5:
    lst=[input() for i in range(num)]
    print(len(set(lst)))
### BUGGY CODE ###

s = list(input())
n = int(input())
from collections import deque
s = deque(s)
for i in range(n):
    q = list(input().split())
    if q[0] == "1":
        s.reverse()
    if len(q) != 1:
        if q[1] == '1':
            s.appendleft(q[2])
        elif q[1] == "2":
            s.append(q[2])
print(''.join(s))       


### FIXED CODE ###

from collections import deque

s = deque(input())
q = int(input())
flg = 0

for _ in range(q):
  Q = [x for x in input().split()]
  if Q[0] == '1':
    flg += 1
  else:
    if (Q[1] == '1' and flg%2==0) or (Q[1] == '2' and flg%2==1):
      s.appendleft(Q[2])
    else:
      s.append(Q[2])
if flg%2==1:
  s.reverse()

print('' . join(s))
### BUGGY CODE ###

n=int(input())
mod=10**9+7
ans=1
for i in range(1,n+1):
    ans*=i
ans%=mod
print(ans)

### FIXED CODE ###

n=int(input())
mod=10**9+7
ans=1
for i in range(1,n+1):
    ans*=i
    ans%=mod
print(ans)
### BUGGY CODE ###

S = input()
T = input()
maxCount = len(T)

for i in range(len(T)):
    for j in range(len(S)):
        if S[j] == T[i]:
            if j >= i and len(S)-j >= len(T)-i:
                copyS = S[j-i:j-i+len(T)]
                countNotEqual = 0
                for k in range(len(copyS)):
                    if copyS[k] != T[k]:
                        countNotEqual += 1
                if countNotEqual < maxCount:
                    maxCount = countNotEqual
print(maxCount)

### FIXED CODE ###

S = input()
T = input()
maxCount = len(T)
for i in range(len(S)-len(T)+1):
    countNotEqual = 0
    for j in range(len(T)):
        if S[j+i] != T[j]:
            countNotEqual += 1
    if countNotEqual < maxCount:
        maxCount = countNotEqual
print(maxCount)
### BUGGY CODE ###

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

left = []
right = []
ans = 3*10**5
E = S.count("E")
W = len(S)-E
# print(E)
# print(W)

for i in range(N):
    left_count = 0
    right_count = 0
    left = S[0:i]
#     right = S[i+1:]

    left_count = left.count("W")
    if S[i]== "W":
        right_count = E - (i - left_count)
    else:
        right_count = E - 1 - (i - left_count)

#     print(left_count)
#     print(right_count)
    count = left_count + right_count
    ans = min(count, ans)
print(ans)


### FIXED CODE ###

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

# 一番左がリーダーの時
l = 0
r = S[1:].count('W')
ans = l + r
for i in range(1, N):
    if S[i-1] == 'E':  # 元リーダーの人が東向きの時
        l += 1
    if S[i] == 'W':  # 元リーダーが西向きの時
        r -= 1
    cnt = l+r
    ans = max(cnt, ans)  # 向きを変える必要のない人数
print(N - ans -1)  # 向きを変える必要のある人数
### BUGGY CODE ###

from collections import Counter
import math

n = int(input())
s = [input() for _ in range(n)]
ans = 0
while len(s) > 0:
    count = 1
    si = Counter([x for x in s[0]])
    j = 1
    while j < len(s):
        if si == Counter([x for x in s[j]]):
            count += 1
            s.pop(j)
        else:
            j += 1
    if count > 1:
        ans += math.factorial(count) // (2 * math.factorial(count-2))
    s.pop(0)
print(int(ans))


### FIXED CODE ###

n = int(input())
s = [[x for x in input()] for _ in range(n)]
ans = 0
d = {}
for i in range(n):
    key = "".join(sorted(s[i]))
    if key in d:
        ans += d[key]
        d[key] += 1
    else:
        d[key] = 1

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

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

   a.sort()
   b = []
   c = []
   for i in range(len(a)):
      if (a[i] in b)==False:
         b.append(a[i])
         c.append(1)
      else:
         c[-1] += 1

   count = 0
   for i in range(len(b)):
      if b[i] < c[i]:
         count += c[i] - b[i]
      elif b[i] > c[i]:
         count += c[i]
   return count

print(main())


### FIXED CODE ###

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

   a.sort()
   a.append(0)
   b = 0
   c = 0
   count = 0
   for a in a:
      if a != b:
         if b < c:
            count += c - b
         elif b > c:
            count += c
         b = a
         c = 1
      else:
         c += 1
   return count

print(main())
### BUGGY CODE ###

N,K=map(int, input().split())
A=list(map(int, input().split()))
s=1
for i in range(K):
  s*=A[i]
l,r=0,K
for i in range(N-K):
  ne=s*A[r]//A[l]
  if ne>s:
    print('Yes')
  else:
    print('No')
  l+=1
  r+=1
  s=ne

### FIXED CODE ###

N,K=map(int, input().split())
A=list(map(int, input().split()))
l,r=0,K
for i in range(N-K):
  s,ne=A[l],A[r]
  if ne>s:
    print('Yes')
  else:
    print('No')
  l+=1
  r+=1
### BUGGY CODE ###

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

tempArray = [1]*(M + 1)
for i, x in enumerate(S):
  tempArray2 = tempArray[:]
  k = 0
  for j, y in enumerate(T):
    if x == y:
      k += tempArray[j]
    tempArray2[j + 1] = tempArray[j + 1] + k
  tempArray = tempArray2
print(tempArray[-1] % (10**9 + 7))

### FIXED CODE ###

import numpy as np
N, M = map(int, input().split())
S = input().split()
T = np.array(input().split(), dtype = np.int32)
mod = 10 ** 9 + 7
dp = np.ones(M + 1, dtype = np.int64)
 
for s in S:
  dp[1:] = ((dp[:-1] * (T == int(s))).cumsum() + dp[1:]) % mod

print(dp[M])
### BUGGY CODE ###

N = int(input())

lis = [i for i in range(1, N)]

print(sum(lis))


### FIXED CODE ###

N = int(input())

ans = N * (N - 1) // 2

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

K=int(input())

sum=0

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a


for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      sum += gcd(gcd(i,j),k)

print(sum)

### FIXED CODE ###

K=int(input())
import math
sum=0


for i in range(1,K+1):
  for j in range(1,K+1):
    c=math.gcd(i,j)
    for k in range(1,K+1):
      sum += math.gcd(c,k)

print(sum)
### BUGGY CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
dp = [True] * (10 ** 6 + 1)
s = list(set(a))
for x in s:
    e = x * 2
    # エラトステネスの篩
    while e <= 10 ** 6:
        dp[e] = False
        e += x
ret = 0
for x in a:
    # 重複なし and 約数なし 
    if c[x] == 1 and dp[x] == True:
        ret += 1
print(ret)


### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
dp = [True] * (10 ** 6 + 1)
s = list(set(a))
for x in s:
    e = x * 2
    while e <= 10 ** 6:
        dp[e] = False
        e += x
ret = 0
for x in a:
    if c[x] == 1 and dp[x] == True:
        ret += 1
print(ret)
### BUGGY CODE ###

from heapq import heapify, heappop, heappush
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
input = sys.stdin.readline

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1
S = [input().rstrip() for _ in [0]*H]

INF = 10**10
D = [[INF]*W for _ in [0]*H]
used = set()

q = []
heappush(q, (0, Ch, Cw))

dirs = [(-1, 0), (1, 0), (0, 1), (0, -1)]
wps = [
    [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -1), (-1, 1)],
    [(2, 2), (2, -1), (2, 0), (2, 1), (2, 2), (1, -1), (1, 1)],
    [(-2, 2), (-1, 2), (0, 2), (1, 2), (2, 2), (-1, 1), (1, 1)],
    [(-2, -2), (-1, -2), (0, -2), (1, -2), (2, -2), (-1, -1), (1, -1)]
]

while q:
    d, i, j = heappop(q)
    used.add((i, j))
    D[i][j] = d
    if i == Dh and j == Dw:
        break

    for k, (di, dj) in enumerate(dirs):
        _i = i + di
        _j = j + dj
        if 0 <= _i < H and 0 <= _j < W:
            if (_i, _j) in used:
                continue
            if S[_i][_j] == '.':
                used.add((_i, _j))
                heappush(q, (d, _i, _j))
            else:
                for di, dj in wps[k]:
                    _i = i + di
                    _j = j + dj
                    if 0 <= _i < H and 0 <= _j < W and (_i, _j) not in used and S[_i][_j] == '.':
                        heappush(q, (d+1, _i, _j))

ans = D[Dh][Dw]
print(ans if ans < INF else -1)


### FIXED CODE ###

from heapq import heapify, heappop, heappush
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
input = sys.stdin.readline

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1
S = [input().rstrip() for _ in [0]*H]

INF = 10**10
D = [[INF]*W for _ in [0]*H]
used = set()

q = []
heappush(q, (0, Ch*W+Cw))


while q:
    d, ij = heappop(q)
    i, j = divmod(ij, W)

    for di in range(-2, 3):
        for dj in range(-2, 3):
            if di == dj == 0:
                continue
            I = i+di; J = j+dj
            if 0 <= I < H and 0 <= J < W and S[I][J] == '.':
                if abs(di)+abs(dj) == 1:
                    if D[I][J] <= d:
                        continue
                    D[I][J] = d
                    heappush(q, (d, I*W+J))
                else:
                    if D[I][J] <= d+1:
                        continue
                    D[I][J] = d+1
                    heappush(q, (d+1, I*W+J))

ans = D[Dh][Dw]
print(ans if ans < INF else -1)
### BUGGY CODE ###

def main():
    from collections import deque
    S = input()
    Sd = deque(list(S))
    Q = int(input())
    Query = [input().split() for i in range(Q)]
    for q in Query:
        if q[0] == "1":
            Sd.reverse()
        elif q[0] == "2":
            if q[1] == "1":
                Sd.appendleft(q[2])
            elif q[1] == "2":
                Sd.append(q[2])

    print("".join(Sd))

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    from collections import deque
    S = input()
    Sd = deque(list(S))
    Q = int(input())
    Query = [input().split() for i in range(Q)]
    flag = 0
    for q in Query:
        if q[0] == "1":
            flag += 1
        elif q[0] == "2":
            if q[1] == "1":
                if flag % 2 == 1:
                    Sd.append(q[2])
                elif flag % 2 == 0:
                    Sd.appendleft(q[2])
            elif q[1] == "2":
                if flag % 2 == 1:
                    Sd.appendleft(q[2])
                elif flag % 2 == 0:
                    Sd.append(q[2])

    if flag % 2 == 1:
        Sd.reverse()
        print("".join(Sd))
    elif flag % 2 == 0:
        print("".join(Sd))

if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

x, y, z = 0,0,0
for i in range(N):
    if S[i] == "R":
        x += 1
    elif S[i] == "G":
        y += 1
    elif S[i] == "B":
        z += 1
    else:
        print("ERROR")

no = 0
for s in range(N-2):
    d = 1
    while(s+2*d < N):
        if len(set([S[s],S[s+d],S[s+2*d]])) == 3:
            no += 1
        d += 1

print(x*y*z-no)

### FIXED CODE ###

from time import time 
N = int(input())
S = str(input())
t0 = time()
x, y, z = 0,0,0
for i in range(N):
    if S[i] == "R":
        x += 1
    elif S[i] == "G":
        y += 1
    elif S[i] == "B":
        z += 1
    else:
        print("ERROR")

no = 0
for s in range(N-2):
    d = 1
    while(s+2*d < N):
#         if len(set([S[s],S[s+d],S[s+2*d]])) == 3:
        a = S[s]
        b = S[s+d]
        c = S[s+2*d]
        if a != b and b != c and c != a:
            no += 1
        d += 1

print(x*y*z-no)
# print(time() - t0)
### BUGGY CODE ###

# ABC068c
import collections
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
n, m = map(int, input().split())
INF = 10**12


class Edge:  # 通常の辺
    def __init__(self, to, cost):
        self.to = to
        self.cost = cost


class Dijkstra:  # ダイクストラ法 O(E * logV)
    def __init__(self, n):
        self.n = n
        self.dist = [INF for _ in range(n)]
        self.edges = [list() for _ in range(n)]
        self.q = collections.deque()

    def calcShortest(self, start):
        self.q.append((start, 0))
        while(len(self.q) != 0):
            v, cost = self.q.popleft()
            if self.dist[v] <= cost:
                continue
            self.dist[v] = cost
            for edge in self.edges[v]:
                self.q.append((edge.to, cost+edge.cost))

    def addEdge(self, st, gl, cost):
        self.edges[st].append(Edge(gl, cost))


v = Dijkstra(n)
for _ in range(m):
    a, b = map(int, input().split())
    v.addEdge(a-1, b-1, 1)
    v.addEdge(b-1, a-1, 1)

v.calcShortest(0)
if v.dist[n-1] <= 2:
    print('POSSIBLE')
    exit(0)
print('IMPOSSIBLE')


### FIXED CODE ###

# ABC068c
import collections
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
n, m = map(int, input().split())
INF = 10**12


class Edge:  # 通常の辺
    def __init__(self, to, cost):
        self.to = to
        self.cost = cost


class Dijkstra:  # ダイクストラ法 O(E * logV)
    def __init__(self, n):
        self.n = n
        self.dist = [INF for _ in range(n)]
        self.edges = [list() for _ in range(n)]
        self.q = collections.deque()

    def calcShortest(self, start):
        self.q.append((start, 0))
        while(len(self.q) != 0):
            v, cost = self.q.popleft()
            if cost > 3:
                continue
            if self.dist[v] <= cost:
                continue
            self.dist[v] = cost
            for edge in self.edges[v]:
                self.q.append((edge.to, cost+edge.cost))

    def addEdge(self, st, gl, cost):
        self.edges[st].append(Edge(gl, cost))


v = Dijkstra(n)
for _ in range(m):
    a, b = map(int, input().split())
    v.addEdge(a-1, b-1, 1)
    v.addEdge(b-1, a-1, 1)

v.calcShortest(0)
if v.dist[n-1] <= 2:
    print('POSSIBLE')
    exit(0)
print('IMPOSSIBLE')
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
anslist=[]
for x in range(N):
  print((A).count(x+1))

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
A.sort()
indexA=0
A.append(N+10)
for x in range(N):
  check=1
  countA=0
  while check==1:
    if A[indexA]!=x+1:
      check=0
      countA-=1
      indexA-=1
    indexA+=1
    countA+=1
  print(countA)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
s = input()
ans = set()
for i in range(n-2):
  for j in range(i+1,n-1):
    for l in range(j+1,n):
      ans.add(int(s[i])*100+int(s[j])*10+int(s[l]))
print(len(ans))

### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
s = input()
def multi_index(l,x):
  return tuple([i for i,_x in enumerate(l) if _x == x])

ans = 0
for i in range(10):
  e = 0
  if str(i) in s:
    c = multi_index(s,str(i))[0]
    for j in range(10):
      if str(j) in s and i!=j and c<=len(s)-2:
        for q in range(c+1,len(s)-1):
          if str(j) == s[q]:
            d = q
            break
        else:
          d = -1
      elif str(j) in s and i==j and len(multi_index(s,str(i)))>=2:
        d = multi_index(s,str(i))[1]
      else:
        d = -1
      if d > c:
        for l in range(10):
          if str(l) in s and i!=j and j!=l and i!=l:
            e = multi_index(s,str(l))[-1]
            if e > d:
              ans += 1
          if str(l) in s and i!=j and j==l:
            e = multi_index(s,str(l))[-1]
            if e > d:
              ans += 1
          if str(l) in s and i==j and j!=l:
            e = multi_index(s,str(l))[-1]
            if e > d:
              ans += 1
          if str(l) in s and i==j and j==l:
            e = multi_index(s,str(l))[-1]
            if e > d:
              ans += 1
          if str(l) in s and i==l and j!=l:
            e = multi_index(s,str(l))[-1]
            if e > d:
              ans += 1
print(ans)
### BUGGY CODE ###

import sys
import heapq
n, m = [int(i) for i in sys.stdin.readline().split()]
graph = {j:[] for j in range(3 * n)}
for i in range(m):
    u, v = [int(i) for i in sys.stdin.readline().split()]
    u -= 1
    v -= 1
    graph[u].append(n+v)
    graph[u+n].append(2*n+v)
    graph[u + 2 * n].append(v)
s, t = [int(i) for i in sys.stdin.readline().split()]
s -= 1
t -= 1

que = [(0,s)]
already = set()
flg = False
while que:
    cost, cur = heapq.heappop(que)
    already.add(cur)
    if cur == t:
        flg = True
        break
    for i in graph[cur]:
        if i in already:
            continue
        heapq.heappush(que, (cost + 1, i))
if not flg:
    cost = -1
else:
    cost //= 3

print(cost)

### FIXED CODE ###

import sys
INF = 10 ** 9
n, m = [int(i) for i in sys.stdin.readline().split()]
graph = {j:[] for j in range(3 * n)}
for i in range(m):
    u, v = [int(i) for i in sys.stdin.readline().split()]
    u -= 1
    v -= 1
    graph[u].append(n+v)
    graph[u+n].append(2*n+v)
    graph[u + 2 * n].append(v)
s, t = [int(i) for i in sys.stdin.readline().split()]
s -= 1
t -= 1

que = [s]
flg = False
already = set()
dist = [INF for i in range(3 * n)]
dist[s] = 0
while que:
    cur= que[0]
    que.pop(0)
    for i in graph[cur]:
        if i not in already:
            if i == t:
                res = dist[cur] + 1
                que.clear()
                flg = True
                break
            que.append(i)
            dist[i] = dist[cur] + 1
            already.add(i)
if not flg:
    res = -1
else:
    res //= 3

print(res)
### BUGGY CODE ###

n=int(input())
a=[int(input()) for i in range(n)]
for i in range(n):
  x=a[i]
  a[i]=0
  print(max(a))
  a[i]=x

### FIXED CODE ###

n=int(input())
a=[int(input()) for i in range(n)]
b=[a[i] for i in range(n)]
b.sort()
m=b[n-1]
m2=b[n-2]
for i in range(n):
  if a[i]==m:
    print(m2)
  else:
    print(m)
### BUGGY CODE ###

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

s=list(map(int,list(s)))

password=[str(i).zfill(3) for i in range(1000)]

cnt=0
can=[]
for word in password:
    w1=int(word[0])
    w2=int(word[1])
    w3=int(word[2])

    i=0
    while i<n-2:
        if s[i]==w1:
            i_1=i
            break
        else:
            i+=1

        if i==n-3 and s[i]!=w1:
            i_1=-1
            break
    
    if i_1==-1:
        continue

    j=i+1
    while j<n-1:
        if s[j]==w2:
            i_2=j
            break
        else:
            j+=1

        if j==n-2 and s[j]!=w2:
            i_2=-1
            break
    
    if i_2==-1:
        continue

    k=j+1
    while k<n:
        if s[k]==w3:
            i_3=k
            break
        else:
            k+=1
        
        if k>=n-1 and s[n-1]!=w3:
            i_3=-1
            break

    if i_3==-1:
        continue
    elif i_1<i_2 and i_2<i_3:
        cnt+=1
        can.append(word)


print(cnt)


### FIXED CODE ###

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

s=list(map(int,list(s)))

password=[str(i).zfill(3) for i in range(1000)]

cnt=0
can=[]
for word in password:
    w1=int(word[0])
    w2=int(word[1])
    w3=int(word[2])

    i=0
    while i<n-2:
        if s[i]==w1:
            i_1=i
            break
        else:
            i+=1

        if i==n-3 and s[i]!=w1:
            i_1=-1
            break
    
    if i_1==-1:
        continue

    j=i+1
    while j<n-1:
        if s[j]==w2:
            i_2=j
            break
        else:
            j+=1

        if j==n-2 and s[j]!=w2:
            i_2=-1
            break
    
    if i_2==-1:
        continue

    k=j+1
    while k<n:
        if s[k]==w3:
            i_3=k
            break
        else:
            k+=1
        
        if k>=n-1 and s[n-1]!=w3:
            i_3=-1
            break

    if i_3==-1:
        continue
    elif i_1<i_2 and i_2<i_3:
        cnt+=1
        can.append(word)


print(cnt)