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

import numpy as np
import sys
# import copy


def xnxn(n=0, flag="v"):
    """
    args:
        int n: a number of lows to read
    example:
        input   1
        retrun  1

        input   1 2 3
        return  [1,2,3]
        input   1 2 3
                4 
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        temp = list(map(int, input().split()))
        if len(temp) == 1:
            if flag == "l":
                return temp
            else:
                return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        temp = [list(map(int, input().split())) for _ in range(n)]
        return temp


n, k = xnxn()
a = xnxn(flag="l")
for _ in range(k):
    tmp = [0]*(n+1)
    for i in range(0, n):
        l = max(0, i - a[i])
        r = min(n, i + a[i]+1)
        tmp[l] += 1
        tmp[r] -= 1
    for i in range(1, n):
        tmp[i] += tmp[i - 1]

    if a == tmp:
        break
    a = tmp

for i in a[:n]:
    print(i, end=" ")


### FIXED CODE ###

# import numpy as np
import sys
# import copy


def xnxn(n=0, flag="v"):
    """
    args:
        int n: a number of lows to read
    example:
        input   1
        retrun  1

        input   1 2 3
        return  [1,2,3]
        input   1 2 3
                4 
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        temp = list(map(int, input().split()))
        if len(temp) == 1:
            if flag == "l":
                return temp
            else:
                return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        temp = [list(map(int, input().split())) for _ in range(n)]
        return temp


n, k = xnxn()
a = xnxn(flag="l")
for _ in range(k):
    tmp = [0]*(n+1)
    for i in range(0, n):
        l = max(0, i - a[i])
        r = min(n, i + a[i]+1)
        tmp[l] += 1
        tmp[r] -= 1
    for i in range(1, n):
        tmp[i] += tmp[i - 1]
    if a == tmp:
        break
    a = tmp

for i in a[:n]:
    print(i, end=" ")
### BUGGY CODE ###

MOD = 10**9 + 7

N,X = map(int,input().split())
S = list(map(int,input().split()))
S.sort()
S = [None] + S
dp = [[0 for i in range(X+1)] for j in range(N+1)]
dp[1] = [i % S[1] for i in range(X+1)]
for n in range(2, N+1):
	for x in range(X+1):
		dp[n][x] = (dp[n-1][x] * (n-1) + dp[n-1][x%S[n]]) % MOD
print(dp[N][X])

### FIXED CODE ###

MOD = 10**9 + 7

N,X = map(int,input().split())
S = list(map(int,input().split()))
S.sort()
S = [None] + S
dp = [[0 for i in range(X+1)] for j in range(N+1)]
dp[1] = [i % S[1] for i in range(X+1)]
for n in range(2, N+1):
	for x in range(X+1):
		dp[n][x] = (dp[n-1][x] * (n-1) + dp[n-1][x%S[n]]) % MOD
print(dp[N][X])
### BUGGY CODE ###

from sys import stdin
def S(): return stdin.readline().rstrip()

s = S()
ls = list(s)
l = []

tmp = ''
for i in range(len(ls)):
    if len(l)<1:
        l.append(ls.pop(0))
    else:
        tmp += ls.pop(0)
        if tmp != l[len(l)-1]:
            l.append(tmp)
            tmp = ''
        else:
            if i == len(l)-1:
                a = l.pop()
                l.append(a+tmp)

print(len(l))

### FIXED CODE ###

from sys import stdin
def S(): return stdin.readline().rstrip()

s = S()
ls = list(s)
l = []

tmp = ''
k = 0
for i in ls:
    k += 1
    if len(l)<1:
        l.append(i)
    else:
        tmp += i
        if tmp != l[len(l)-1]:
            l.append(tmp)
            tmp = ''
        else:
            if k == len(ls):
                a = l.pop()
                tmp = a+tmp
                l.append(tmp)

print(len(l))
### BUGGY CODE ###

LARGE = 998244353


def solve(n):
    r = 0
    mck = 1
    factorial_n = 1
    factorial_inv = [0] * (n + 1)
    factorial_inv[0] = 1
    for i in range(1, n + 1):
        factorial_n *= i
        factorial_n %= LARGE
    factorial_inv[-1] = pow(factorial_n, LARGE - 2, LARGE)
    for i in range(n):
        factorial_inv[n - i - 1] = (factorial_inv[n - i] * (n - i)) % LARGE
    pow_2 = 1
    for k in range(n // 2):
        r += factorial_n * factorial_inv[n - k] * factorial_inv[k] * pow_2
        r %= LARGE
        pow_2 *= 2
        pow_2 %= LARGE
    res = (pow(3, n, LARGE) - (2 * r)) % LARGE
    return res


def main():
    n = int(input())
    res = solve(n)
    print(res)


def test():
    assert solve(2) == 7
    assert solve(10) == 50007
    # assert solve(1000000) == 210055358


if __name__ == "__main__":
    test()
    main()


### FIXED CODE ###

LARGE = 998244353


def solve(n):
    r = 0
    mck = 1
    factorial_n = 1
    factorial_inv = [0] * (n + 1)
    factorial_inv[0] = 1
    for i in range(1, n + 1):
        factorial_n *= i
        factorial_n %= LARGE
    factorial_inv[-1] = pow(factorial_n, LARGE - 2, LARGE)
    for i in range(n):
        factorial_inv[n - i - 1] = (factorial_inv[n - i] * (n - i)) % LARGE
    pow_2 = 1
    for k in range(n // 2):
        r += factorial_n * factorial_inv[n - k] * factorial_inv[k] * pow_2
        r %= LARGE
        pow_2 *= 2
        pow_2 %= LARGE
    res = (pow(3, n, LARGE) - (2 * r)) % LARGE
    return res


def main():
    n = int(input())
    res = solve(n)
    print(res)


def test():
    assert solve(2) == 7
    assert solve(10) == 50007
    # assert solve(1000000) == 210055358


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

num=int(input())
count=0
num1=1
while count!=num:
  num2=str(num1)
  flag=0
  if len(num2)==1:
    ans=num1
    count=count+1
  else:
    for j in range(len(num2)-1):
      if abs(int(num2[j])-int(num2[j+1]))>=2:
        flag=1
        break
      else :
        continue
    if flag==0:
      ans=num1
      count=count+1
  num1=num1+1
print(ans)
      
      
    

### FIXED CODE ###

import queue
num=int(input())
q=queue.Queue()
for i in range(1,10):
  q.put(i)
for j in range(num):
  ans=q.get()
  if ans%10!=0:
    q.put(10*ans+(ans%10)-1)
  q.put(10*ans+(ans%10))
  if ans%10!=9:
    q.put(10*ans+(ans%10)+1)
print(ans)
### BUGGY CODE ###

H, W, D = map(int, input().split())
As = [list(map(int, input().split())) for i in range(H)]
Q = int(input())
LRs = [list(map(int, input().split())) for i in range(Q)]

poss = [(0, 0)] * (H * W)
for i in range(H):
    for j in range(W):
        poss[As[i][j] - 1] = (i, j)

for L, R in LRs:
    ans = 0
    pi, pj = poss[L - 1]
    for i, j in poss[L - 1 + D:R + 1:D]:
        ans += abs(i - pi) + abs(j - pj)
        pi, pj = i, j
    print(ans)


### FIXED CODE ###

H, W, D = map(int, input().split())
As = [list(map(int, input().split())) for i in range(H)]
Q = int(input())
LRs = [list(map(int, input().split())) for i in range(Q)]

poss = [(0, 0)] * (H * W)
for i in range(H):
    for j in range(W):
        poss[As[i][j] - 1] = (i, j)

MPs = [[] for i in range(D)]
for st in range(1, D + 1):
    MPs[st - 1] += [0]
    pi, pj = poss[st - 1]
    for i, j in poss[st - 1 + D::D]:
        MPs[st - 1] += [MPs[st - 1][-1] + abs(i - pi) + abs(j - pj)]
        pi, pj = i, j

for L, R in LRs:
    st = (L - 1) % D + 1
    print(MPs[st - 1][(R - st) // D] - MPs[st - 1][(L - st) // D])
### BUGGY CODE ###

from operator import itemgetter
import copy
N = int(input())
T = [list(map(int,input().split()))+[k] for k in range(N)]
A = copy.deepcopy(T)

T.sort(key = itemgetter(0,1), reverse = True)
A.sort(key = itemgetter(1,0), reverse = True)

U = [1 for k in range(N)]

ans = 0
l = 0
m = 0
for k in range(N):
    if k%2 == 0:
        while U[T[l][2]] == 0:
            l += 1
        ans += T[l][0]
        U[T[l][2]] = 0
    else:
        m = 0
        while U[A[m][2]] == 0:
            m += 1
        ans -= A[m][1]
        U[A[m][2]] = 0

print(ans)

### FIXED CODE ###

N = int(input())
D = [list(map(int,input().split()))+[k] for k in range(N)]

T = sorted(D, key = lambda x: x[0]+x[1], reverse = True)
A = sorted(D, key = lambda x: x[1]+x[0], reverse = True)
U = [1 for k in range(N)]

ans = 0
l = 0
m = 0
for k in range(N):
    if k%2 == 0:
        while U[T[l][2]] == 0:
            l += 1
        ans += T[l][0]
        U[T[l][2]] = 0
    else:
        while U[A[m][2]] == 0:
            m += 1
        ans -= A[m][1]
        U[A[m][2]] = 0

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


def factorization(n):
    pf_cnt = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i == 0:
            cnt = 0
            while temp%i == 0:
                cnt += 1
                temp //= i
            pf_cnt[i] = cnt

    if temp != 1: pf_cnt[temp] = 1
    if not pf_cnt: pf_cnt[n] = 1
    return pf_cnt


def main():
    n = int(input())
    al = list(map(int, input().split()))

    al_fac = [0]*n
    for i, a in enumerate(al):
        fac = factorization(a)
        al_fac[i] = fac

    gcd_l = [1]*n
    gcd_r = [1]*n

    gcd_l[0] = al_fac[0]
    gcd_r[-1] = al_fac[-1]

    for i in range(1,n):
        next_l = al_fac[i]
        next_l_gcd = {1:1}
        for prime,cnt in next_l.items():
            if prime in gcd_l[i-1]:
                next_l_gcd[prime] = min(cnt, gcd_l[i-1][prime])
        gcd_l[i] = next_l_gcd

        next_r = al_fac[n-i-1]
        next_r_gcd = {1:1}
        for prime,cnt in next_r.items():
            if prime in gcd_r[n-i]:
                next_r_gcd[prime] = min(cnt, gcd_r[n-i][prime])
        gcd_r[n-i-1] = next_r_gcd

    ans = 1
    for i in range(1,n-1):
        curr_gcd = 1
        for prime,cnt in gcd_l[i-1].items():
            if prime in gcd_r[i+1]:
                min_cnt = min(cnt, gcd_r[i+1][prime])
                curr_gcd *= prime**min_cnt
        ans = max(ans, curr_gcd)


    # i = 0
    curr_gcd = 1
    for prime,cnt in gcd_r[1].items():
        curr_gcd *= (prime**cnt)
    ans = max(ans, curr_gcd)

    # i = n-1
    curr_gcd = 1
    for prime,cnt in gcd_l[n-2].items():
        curr_gcd *= (prime**cnt)
    ans = max(ans, curr_gcd)

    # print(al_fac)
    # print(gcd_l)
    # print(gcd_r)
    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

from fractions import gcd

def factorization(n):
    pf_cnt = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i == 0:
            cnt = 0
            while temp%i == 0:
                cnt += 1
                temp //= i
            pf_cnt[i] = cnt

    if temp != 1: pf_cnt[temp] = 1
    if not pf_cnt: pf_cnt[n] = 1
    return pf_cnt


def main():
    n = int(input())
    al = list(map(int, input().split()))

    gcd_l = [1]*n
    gcd_r = [1]*n

    gcd_l[0] = al[0]
    gcd_r[-1] = al[-1]

    for i in range(1,n):
        next_l = al[i]
        gcd_l[i] = gcd(next_l, gcd_l[i-1])

        next_r = al[n-i-1]
        gcd_r[n-i-1] = gcd(next_r, gcd_r[n-i])


    ans = max(gcd_r[1], gcd_l[n-2])
    for i in range(1,n-1):
        curr_gcd = gcd(gcd_l[i-1], gcd_r[i+1])
        ans = max(ans, curr_gcd)

    print(ans)


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

N, M = map(int, input().split())
City_list = [[] for i in range(N)]
X_list = [None] * M
Y_list = [None] * M
for i in range(M):
  X, Y = map(int, input().split())
  City_list[X - 1].append(Y)
  X_list[i] = X
  Y_list[i] = Y
for j in range(N):
  City_list[j].sort()
for x, y in zip(X_list, Y_list):
  print(str(x).zfill(6)+str(City_list[x - 1].index(y) + 1).zfill(6))

### FIXED CODE ###

N, M = map(int, input().split())
XY_list = [[] for i in range(N)]
ans_list = [None] * M
for i in range(M):
  X, Y = map(int, input().split())
  XY_list[X - 1].append((Y, i))
for j, k in enumerate(XY_list):
  k.sort()
  for l, (y, m) in enumerate(k):
    ans_list[m] = str(j + 1).zfill(6) + str(l + 1).zfill(6)
print(*ans_list, sep = "\n")
### BUGGY CODE ###

N,K=map(int,input().split())
A=[]
C=[]
for i in range(N):
    a,b=map(int,input().split())
    T=[a,b]
    A.append(T)
A.sort()    
for i in range(N):
    if len(C)>K:
        break
    for j in range(A[i][1]):
        C.append(A[i][0])
        if len(C)>K:
            break      
print(C[K-1])

### FIXED CODE ###

N,K=map(int,input().split())
A=[]
C=[]
for i in range(N):
    a,b=map(int,input().split())
    T=[a,b]
    A.append(T)
A.sort()
counter=0
for i in range(N):
     counter+=A[i][1]
     if counter>=K:
         counter=i
         break   
print(A[counter][0])
### BUGGY CODE ###

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

AB = []
graph = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    AB.append((a, b))
    graph[a].append(b)
    graph[b].append(a)
AB = sorted(AB, key=lambda x: (x[1], x[0]))

root = 0
q = [root]
append_q = q.append
parent = [-1] * N
while q:
    x = q.pop(0)
    p = parent[x]
    for y in graph[x]:
        if y == p:
            continue
        parent[y] = x
        append_q(y)

C = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    p = p - 1
    C[p] += x

for a, b in AB:
    if a != parent[b]:
        tmp = a
        a = b
        b = tmp
    C[b] += C[a]

print(*C)

### FIXED CODE ###

from queue import deque


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

graph = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    graph[a].append(b)
    graph[b].append(a)

C = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    C[p - 1] += x

P = [-1] * N

root = 0
q = deque([root])
while q:
    x = q.popleft()
    for y in graph[x]:
        if y == P[x]:
            continue
        C[y] += C[x]
        q.append(y)
        P[y] = x

print(*C)
### BUGGY CODE ###

from collections import deque, defaultdict

mod = 10**9+7

n = int(input())
d = defaultdict(list)
for i in range(n-1):
    x,y = map(lambda x:int(x)-1, input().split())
    d[x].append(y)
    d[y].append(x)

if n == 1:
    print(2)
    exit()

dp = [[0]*2 for i in range(n)]

q = deque()
for i in range(n):
    if len(d[i]) == 1:
        q.append(i)

visited = set()

while True:
    i = q.popleft()
    if i in visited:
        continue

    white = 1
    other = 1
    cnt = 0
    next_i = -1
    for j in d[i]:
        if j in visited:
            white = (white*dp[j][0]) % mod
            other = (other*sum(dp[j])) % mod
        else:
            cnt += 1
            next_i = j
    if cnt > 1:
        q.append(i)
        continue
    dp[i][0] = other
    dp[i][1] = white
    visited.add(i)
    if cnt == 0:
        print(sum(dp[i])%mod)
        exit()
    q.append(next_i)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

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

    mod = 10**9+7
    n = int(input())
    edges = [[] for i in range(n)]
    for i in range(n-1):
        x,y = map(int, input().split())
        x,y = x-1, y-1
        edges[x].append(y)
        edges[y].append(x)

    def rec(cur, prev=None):
        white = 1
        black = 1
        for to in edges[cur]:
            if to == prev:
                continue
            w,b = rec(to, cur)
            white *= (w+b)
            white %= mod
            black *= w
            black %= mod
        return white, black

    w, b = rec(0)
    print((w+b)%mod)

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

a, b, c, n = map(int, input().split())
aa =[a,b,c]
aa.sort()
r = aa[2]
g = aa[1]
b = aa[0]

count = 0
for i_r in range(0,int(n/r)+1):
    if (n - r*i_r)<0:continue
    for i_g in range(0,int((n-r*i_r)/g)+1):
        if (n - r*i_r - g*i_g)<0:continue
        if 0==((n - r*i_r - g*i_g)%b):

            count = count + 1

print(count)


### FIXED CODE ###

a, b, c, n = map(int, input().split())
aa =[a,b,c]
aa.sort()
r = aa[2]
g = aa[1]
b = aa[0]
 
count = 0
for i_r in range(0,int(n/r)+1):
    if (n - r*i_r)<0:continue
    for i_g in range(0,int((n-r*i_r)/g)+1):
        if (n - r*i_r - g*i_g)<0:continue
        if 0==((n - r*i_r - g*i_g)%b):
 
            count = count + 1
 
print(count)
### BUGGY CODE ###

n,q=map(int,input().split())
s=input()
L=[0]*n
for i in range(n-1):
  if(s[i:i+2]=='AC'):
    L[i] = 1
for i in range(q):
  l,r=map(int,input().split())
  print(sum(L[l-1:r-1]))

### FIXED CODE ###

from itertools import accumulate
n, q = map(int, input().split())
s = input()
L = [0]*n
for i in range(1, n):
    if(s[i-1:i+1] == 'AC'):
        L[i] = 1
c = list(accumulate(L))
for i in range(q):
    l, r = map(int, input().split())
    print(c[r-1]-c[l-1])
### BUGGY CODE ###

N, u, v = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
v-=1
u-=1
que = [v]
par = [-1]*N
depth = [-1]*N
depth[v] = 0
while que:
    i = que.pop()
    d = depth[i]
    for nv in G[i]:
        if depth[nv]>=0:
            continue
        depth[nv] = d+1
        par[nv] = i
        que.append(nv)
d = depth[u]
now = u
m = 0
que = [now]
while que:
    i = que.pop()
    m = max(m, depth[i])
    for nv in G[i]:
        if depth[nv]<depth[i]:
            continue
        que.append(nv)
for i in range(d//2):
    now = par[now]
    que = [now]
    while que:
        i = que.pop()
        m = max(m, depth[i])
        for nv in G[i]:
            if depth[nv]<depth[i]:
                continue
            que.append(nv)
print(m-1)
    






### FIXED CODE ###

import sys
#input = sys.stdin.readline
from collections import deque
N, u, v = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
v-=1
u-=1
que = deque([v])
par = [-1]*N
depth = [-1]*N
depth[v] = 0
while que:
    i = que.popleft()
    d = depth[i]
    for nv in G[i]:
        if depth[nv]>=0:
            continue
        depth[nv] = d+1
        par[nv] = i
        que.append(nv)
d = depth[u]
now = u
m = 0
que = deque([now])
while que:
    i = que.pop()
    m = max(m, depth[i])
    for nv in G[i]:
        if depth[nv]<depth[i]:
            continue
        que.append(nv)
for i in range(d//2):
    pp = par[now]
    que = deque([pp])
    while que:
        i = que.pop()
        m = max(m, depth[i])
        for nv in G[i]:
            if depth[nv]<depth[i] or nv == now:
                continue
            que.append(nv)
    now = pp
print(m-1)
### BUGGY CODE ###

from collections import deque

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

cnt = [[-1]*W for _ in range(H)]

que = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            que.append((h, w))
            cnt[h][w] = 0

ans = 0
while que:
    h, w = que.popleft()
    ans = cnt[h][w]
    for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        next_h = h + dy
        next_w = w + dx
        if next_h < 0 or H <= next_h or next_w < 0 or W <= next_w:
            continue
        if cnt[next_h][next_w] == -1:
            cnt[next_h][next_w] = ans+1
            que.append((next_h, next_w))

print(int(ans))

### FIXED CODE ###

from collections import deque

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

cnt = [[-1]*W for _ in range(H)]

que = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            que.append((h, w))
            cnt[h][w] = 0

ans = 0
while que:
    h, w = que.popleft()
    ans = cnt[h][w]
    for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        next_h = h + dy
        next_w = w + dx
        if next_h < 0 or H <= next_h or next_w < 0 or W <= next_w:
            continue
        if cnt[next_h][next_w] == -1:
            cnt[next_h][next_w] = ans+1
            que.append((next_h, next_w))

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

N, K = [int(item) for item in input().split()]
h =[0] + [int(item) for item in input().split()]

dp = [0 for _ in range(N+1)]

for i in range(2, N+1):
    for k in range(1, K+1):
        if i - k >= 1:
            if dp[i] != 0:
                dp[i] = min(dp[i-k] + abs(h[i] - h[i-k]), dp[i])
            else:
                dp[i] = dp[i-k] + abs(h[i] - h[i-k])
print(dp[N])

### FIXED CODE ###

import numpy as np

N, K = [int(item) for item in input().split()]
h =np.array([int(item) for item in input().split()])
# print(h.shape)
dp = np.full(N+K, 10**10+1, dtype='int64')
dp[0] = 0

for i in range(1, N):
    max1 = min(N, i+K)
    cost = abs(h[i:max1] - h[i-1])
    # print(cost.shape, dp[i:max1].shape)
    dp[i:max1] = np.minimum(dp[i:max1], dp[i-1] + cost)

    # print(dp)
print(dp[N-1])
### BUGGY CODE ###

_,*l=map(int,open(0).read().split())
a=0
for i in list(set(l)):
	c=l.count(i)
	a+=c-i*(c>=i)
print(a)

### FIXED CODE ###

from collections import*
_,*l=map(int,open(0).read().split())
a=0
c=Counter(l)
for i in list(set(l)):
	j=c[i]
	a+=j-i*(i<=j)
print(a)
### BUGGY CODE ###

from itertools import combinations
N = int(input())
S = input()
print(len(set(combinations(S, 3))))

### FIXED CODE ###

N = int(input())
S = list(map(int, input()))
ans = 0
first = [0] * 10
a = 0
for i in range(N):
  if first[S[i]] == 0:
    first[S[i]] = 1
    a += 1
    second = [0] * 10
    b = 0
    for j in range(i+1, N):
      if second[S[j]] == 0:
        second[S[j]] = 1
        b += 1
        third = [0] * 10
        c = 0
        for k in range(j+1, N):
          if third[S[k]] == 0:
            third[S[k]] = 1
            ans += 1
            c += 1
            if c == 10:
              break
        if b == 10:
          break
    if a == 10:
      break
print(ans)
### BUGGY CODE ###

N, M = [int(x) for x in input().split()]
S = []
from1 = []
fromN = []
ans = "IMPOSSIBLE"
for i in range(M):
	S.append([int(x) for x in input().split()])
	if S[i][0] == 1:
		from1.append(S[i][1])
	if S[i][1] == N:
		fromN.append(S[i][0])

for x in from1:
	if x in fromN:
		ans = "POSSIBLE"

print(ans)

### FIXED CODE ###

N, M = [int(x) for x in input().split()]
S1 = []
S2 = []
for i in range(M):
	S1 = [int(x) for x in input().split()]
	if S1[0] == 1:
		S2.append(S1[1])
	if S1[1] == N:
		S2.append(S1[0])
		
if len(S2) == len(set(S2)):
	print("IMPOSSIBLE")
else:
	print("POSSIBLE")
### BUGGY CODE ###

h, n = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]
MOD = 10 ** 18
D = [MOD] * (h + 10 ** 4)
D[0] = 0
 
for i in range(h):
    for a, b in AB:
        D[i + a] = min(D[i + a], D[i] + b)
print(min(D[h:]))

### FIXED CODE ###

h, n = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]
MOD = 10 ** 18
D = [MOD] * (h + 10 ** 4)
D[0] = 0
 
for i in range(h):
    for a, b in AB:
        D[i + a] = min(D[i + a], D[i] + b)
print(min(D[h:]))
### BUGGY CODE ###

import collections
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a = a[::-1]
x,answer = collections.Counter(a),[]
while a != []:
	if x[a[0]]>=4 and len(answer)==0:
		answer = [a[0],a[0]]
		break
	elif x[a[0]]>=2:
		answer.append(a[0])
		if len(answer)==2:
			break
	a = a[x[a[0]]:]
if len(answer)==2:
	print(answer[0]*answer[1])
else:
	print(0)

### FIXED CODE ###

import collections
n = int(input())
a = [int(i) for i in input().split()]
x,y,z = collections.Counter(a),[0],[0,0]
for i in x.keys():
	if x[i]>=4:
		y.append(i)
	if x[i]>=2:
		z.append(i)
y,z = sorted(y),sorted(z)
print(max(y[-1]**2,z[-1]*z[-2]))
### BUGGY CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N = int(input())
    S = input()

    ans = 0
    for i in range(1000):
        s = str(i).zfill(3)
        j = 0
        flg0 = False
        flg1 = False
        flg2 = False
        for j in S:
            if not flg0 and j==s[0]:
                flg0 = True
            elif flg0 and not flg1 and j==s[1]:
                flg1 = True
            elif flg0 and flg1 and not flg2 and j==s[2]:
                flg2 = True
        if flg0 and flg1 and flg2:
            ans +=1

    print(ans)

if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N = int(input())
    S = input()

    ans = 0
    for i in range(1000):
        s = str(i).zfill(3)
        j = 0
        flg0 = False
        flg1 = False
        flg2 = False
        for j in S:
            if not flg0 and j==s[0]:
                flg0 = True
            elif flg0 and not flg1 and j==s[1]:
                flg1 = True
            elif flg0 and flg1 and not flg2 and j==s[2]:
                flg2 = True
        if flg0 and flg1 and flg2:
            ans +=1

    print(ans)

if __name__ == '__main__':
    resolve()