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

import numpy as np
def sieve_of_eratosthenes_2017(N):
    numbers = [n & 1 for n in range(N + 1)]
    numbers[1] = 0
    numbers[2] = 1
    like2017 = []
    p = 1
    while True:
        while not numbers[p]:
            p += 2
        if numbers[(p + 1) >> 1]:
            like2017.append(p)
        if p * p > N:
            for i in range(p, N + 1, 2):
                if (i + 1) >> 1:
                    like2017.append(i)
            return like2017
        for i in range(p * 2, N + 1, p):
            numbers[i] = 0
        p += 2

like2017 = np.array(sieve_of_eratosthenes_2017(10 ** 5), dtype=np.int32)
Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    lindex = np.searchsorted(like2017, l)
    rindex = np.searchsorted(like2017, r, side="right")
    print(rindex - lindex)

### FIXED CODE ###

from itertools import accumulate
def sieve_of_eratosthenes_2017(N):
    numbers = [n & 1 for n in range(N + 1)]
    numbers[1] = 0
    numbers[2] = 1
    like2017 = [0] * (N + 1)
    p = 1
    while True:
        while not numbers[p]:
            p += 2
        if p * p > N:
            for i in range(p, N + 1, 2):
                if numbers[i] & numbers[(i + 1) >> 1]:
                    like2017[i] = 1
            return like2017
        if numbers[(p + 1) >> 1]:
            like2017[p] = 1
        for i in range(p * 2, N + 1, p):
            numbers[i] = 0
        p += 2

like2017 = sieve_of_eratosthenes_2017(10 ** 5)
like2017_sum = list(accumulate(like2017))
Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(like2017_sum[r] - like2017_sum[l] + like2017[l])
### BUGGY CODE ###

def main():
    S = input()
    X, Y = map(int, input().split())
    cur = set([(0, 0, 0)])
    D = [(1, 0), (0, -1), (-1, 0), (0, 1)]
    for s in S:
        nxt = set()
        if s == 'F':
            for x, y, d in cur:
                tx, ty = D[d]
                nxt.add((x + tx, y + ty, d))
        else:
            for x, y, d in cur:
                nxt.add((x, y, (d + 1) % 4))
                nxt.add((x, y, (d - 1) % 4))
        cur = nxt
    return any((X, Y, i) in cur for i in range(4))

print('Yes' if main() else 'No')


### FIXED CODE ###

def main():
    S = input()
    X, Y = map(int, input().split())
    d = 0
    L = [[0], [0]]
    for s in S:
        if s == 'T':
            d = 1 - d
            if L[d][-1] != 0:
                L[d].append(0)
        else:
            L[d][-1] += 1
    xs, ys = set([L[0][0] if S[0] == 'F' else 0]), set([0])
    for i in L[0][1 if S[0] == 'F' else 0:]:
        xs = set(x + i for x in xs) | set(x - i for x in xs)
    for i in L[1]:
        ys = set(y + i for y in ys) | set(y - i for y in ys)
    return X in xs and Y in ys

print('Yes' if main() else 'No')
### BUGGY CODE ###

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

R=[]
G=[]
B=[]

for i in range(n):
    if s[i]=="R":
        R.append(i)
    elif s[i]=="G":
        G.append(i)
    else:
        B.append(i)

#print(B)
count = len(R)*len(G)*len(B)
for i in R:
    for j in G:
        big = max(i,j)
        small = min(i,j)
        
        if 2*big-small in B:
            count -= 1
            #print(i,j)
            #print("hoi")
        if 2*small-big in B:
            count -= 1
            #print(i,j)
        if (big+small)/2 in B:
            #print((big+small)/2)
            count -= 1
            #print(i,j)
        
print(count)
        


### FIXED CODE ###

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

R=[]
G=[]
B=[]

for i in range(n):
    if s[i]=="R":
        R.append(i)
    elif s[i]=="G":
        G.append(i)
    else:
        B.append(i)

#print(B)
count = len(R)*len(G)*len(B)
d={}
for i in R:
    for j in G:
        big = max(i,j)
        small = min(i,j)
        
        x = 2*big-small
        y = 2*small-big
        z = (big+small)/2
        
        if x in d:
            d[x] += 1
        else:
            d[x] = 1
        if y in d:
            d[y] += 1
        else:
            d[y] = 1
        if z%1==0:
            if z in d:
                d[z] += 1
            else:
                d[z] = 1
        
        #if 2*big-small in B:
            #count -= 1
            #print(i,j)
            #print("hoi")
        #if 2*small-big in B:
            #count -= 1
            #print(i,j)
        #if (big+small)/2 in B:
            #print((big+small)/2)
            #count -= 1
            #print(i,j)
    
for i in B:
    if i in d:
        count -= d[i]
    
print(count)
### BUGGY CODE ###

n,k = map(int, input().split())
a = [0] + list(map(int, input().split()))
r = [1]
k += 1
now = 1
for i in range(n):
   now = a[now]
   if now in r:break
   r.append(now)
I = r.index(now)

if len(r) > k: print(r[k-1])
else:
  if I != 0: 
    k -= I
    r = r[I:]
  print(r[-1] if k%len(r)==0 else r[k%len(r)-1])

### FIXED CODE ###

n,k = map(int, input().split())
a = [0] + list(map(int, input().split()))

now = 1
check = [-1]*(n+1)

for i in range(k):
  if check[now] == -1:
    check[now] = i
    now = a[now]
  else:
    loop = i - check[now]
    afterloop = (k-(i-loop))%loop
    print(check.index((i-loop) + afterloop))
    exit()
print(now)
### BUGGY CODE ###

n, q = (int(_) for _ in input().split())  
arr = [[1 if i == j else 0 for i in range(n)] for j in range(n)]
output = [0 for i in range(n)]

for i in range(n-1):
  a, b = (int(_) for _ in input().split()) 
  arr[a-1][b-1] = 1
  for x in range(a-1):
    if arr[x][a-1] == 1:
      arr[x][b-1] = 1

for i in range(q):
  p, q = (int(_) for _ in input().split()) 
  for i, x in enumerate(arr[p-1]):
    if x == 1:
      output[i] += q
    
print(' '.join([str(x) for x in output]))
  

### FIXED CODE ###

n,q=map(int,input().split())
a=[0]*(n-1)
c=[0 for i in range(n)]
for i in range(n-1):
  a[i]=list(map(int,input().split()))

a.sort()

for i in range(q):
  x,y=map(int,input().split())
  c[x-1]+=y

for i in range(n-1):
  c[a[i][1]-1]+=c[a[i][0]-1]

print(*c)
### BUGGY CODE ###

n = int(input())
p = list(map(int,input().split()))
ans = 1
d = [1] + [0]*(n-1)
for i in range(1,n):
  if (p[i] <= p[i-1] and d[i-1] == 1):
    ans += 1
    d[i] = 1
  elif (d[i-1] ==0 and min(sorted(p[:i+1])) == p[:i+1][-1]):
    ans += 1
    d[i] = 1
    
print(ans)

### FIXED CODE ###

n = int(input())
p = list(map(int,input().split()))
ans = 0
m= 10**10

for i in range(n):
  tmp = m
  m = min(m,p[i])
  if tmp != m:
    ans += 1
    
print(ans)
### BUGGY CODE ###

s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for i in range(m+1)] for j in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:
      dp[i+1][j+1]=dp[i][j]+1
    else:
      dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j])
ans=''
a=n
b=m
while a>0 and b>0:
  if dp[a][b]==dp[a-1][b]:
    a-=1
  elif dp[a][b]==dp[a][b-1]:
    b-=1
  else:
    a-=1
    b-=1
    ans=s[a]+ans
print(ans)

### FIXED CODE ###

s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for i in range(m+1)] for j in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i]==t[j]:
      dp[i+1][j+1]=dp[i][j]+1
    else:
      dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j])
ans=''
a=n
b=m
while a>0 and b>0:
  if dp[a][b]==dp[a-1][b]:
    a-=1
  elif dp[a][b]==dp[a][b-1]:
    b-=1
  else:
    a-=1
    b-=1
    ans=s[a]+ans
print(ans)
### BUGGY CODE ###

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

    inf = float('inf')

    N,Ma,Mb = map(int,input().split())

    # dp[i][j][k]: i番目までみてj(g), k(g)となるような最小予算
    dp = [[[inf]*401 for _ in range(401)] for _ in range(N+1)]
    dp[0][0][0] = 0

    for i in range(N):
        a,b,c = map(int,input().split())
        for j in range(401):
            for k in range(401):
                dp[i+1][j][k] = dp[i][j][k]
                if j - a >= 0 and k - b >= 0 and dp[i+1][j][k] > dp[i][j-a][k-b] + c:
                    dp[i+1][j][k] = dp[i][j-a][k-b] + c

    ans = inf

    for j in range(1,401):
        for k in range(1,401):
            if j * Mb == Ma * k and ans > dp[N][j][k]:
                ans = dp[N][j][k]

    if ans == inf:
        ans = -1
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

inf = float('inf')

N,Ma,Mb = map(int,input().split())

# dp[i][j][k]: i番目までみてj(g), k(g)となるような最小予算
dp = [[[inf]*401 for _ in range(401)] for _ in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
    a,b,c = map(int,input().split())
    for j in range(401):
        for k in range(401):
            dp[i+1][j][k] = dp[i][j][k]
            if j - a >= 0 and k - b >= 0 and dp[i+1][j][k] > dp[i][j-a][k-b] + c:
                dp[i+1][j][k] = dp[i][j-a][k-b] + c

ans = inf

for j in range(1,401):
    for k in range(1,401):
        if j * Mb == Ma * k and ans > dp[N][j][k]:
            ans = dp[N][j][k]

if ans == inf:
    ans = -1
print(ans)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
for i in range(N):
    print(A.index(i+1)+1,end=" ")

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
sort=[0]*N
for i in range(N):
    sort[A[i]-1]+=i+1
print(*sort)
### BUGGY CODE ###

import sys, os, random

def rd():
        return sys.stdin.readline().rstrip()

def rdi():
        return [ int(x) for x in rd().split() ]

def solve(N, M):
        i = N
        while i <= M:
                if M % i == 0:
                        return M / i
                i = i + 1
        assert 0

N, M = rdi()
print solve(N, M)

### FIXED CODE ###

import sys, os, random, math

def rd():
        return sys.stdin.readline().rstrip()

def rdi():
        return [ int(x) for x in rd().split() ]

def solve(N, M):
        L = math.sqrt(M) + 0.5
        i = N
        while i <= L:
                if M % i == 0:
                        return M / i
                i = i + 1
        i = N-1
        while i >= 1:
                if M % i == 0 and M / i >= N:
                        return i
                i = i - 1
        assert 0

N, M = rdi()
print solve(N, M)
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    import numpy as np
    from collections import Counter

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

    tmp = np.array(list(c.values()))
    l1= tmp*(tmp-1)//2
    l2= (tmp-1)*((tmp-1)-1)//2
    S = np.sum(l1)

    for a in A:
        r = list(c).index(a)
        sum = S + l2[r] -l1[r]
        print(int(sum))

if __name__ == '__main__':
    main()


### FIXED CODE ###

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

import collections 
c=collections.Counter(A)
sum=0
for i in c:
  sum+=c[i]*(c[i]-1)//2  
for a in A:
  print(sum - c[a]*(c[a]-1)//2 + (c[a]-1)*(c[a]-2)//2)
### BUGGY CODE ###

#a,b=map(int,input().split())
s=input()
n=len(s)
wayA=[0,0,0,0]
wayB=[0,0,0,0]
wayC=[0,0,0,0]
hatena=0
MOD=1000000007
for c in s:
	if c=="A":
		wayA[0]=wayA[0]+1
	if c=="B":
		wayB[0]=wayB[0]+wayA[0]
		wayB[1]=wayB[1]+wayA[1]
	if c=='C':
		wayC=wayC+wayB
		wayC[0]=wayC[0]+wayB[0]
		wayC[1]=wayC[1]+wayB[1]
		wayC[2]=wayC[2]+wayB[2]
	if c=='?':
		wayC[1]=wayC[1]+wayB[0]
		wayC[2]=wayC[2]+wayB[1]
		wayC[3]=wayC[3]+wayB[2]
		wayB[1]=wayB[1]+wayA[0]
		wayB[2]=wayB[2]+wayA[1]
		wayA[1]=wayA[1]+1
		hatena=hatena+1
	for z in range(0,4):
		wayA[z]=wayA[z]%MOD
		wayB[z]=wayB[z]%MOD
		wayC[z]=wayC[z]%MOD
ans=0
for i in range(0,4):
	p3=1
	if wayC[i]<=0:
		continue
	for k in range(0,hatena-i):
		p3=p3*3
		p3=p3%MOD
	ans=ans+p3*wayC[i]
ans = ans%1000000007
print(int(ans))

### FIXED CODE ###

#a,b=map(int,input().split())
import numpy as np

s=input()
n=len(s)
wayA=np.array([0,0,0,0],dtype=np.int64)
wayB=np.array([0,0,0,0],dtype=np.int64)
wayC=np.array([0,0,0,0],dtype=np.int64)
hatena=0
MOD=1000000007
for c in s:
	if c=="A":
		wayA[0]=wayA[0]+1
	if c=="B":
		wayB+=wayA;
	if c=='C':
		wayC=wayC+wayB
	if c=='?':
		wayC[1]=wayC[1]+wayB[0]
		wayC[2]=wayC[2]+wayB[1]
		wayC[3]=wayC[3]+wayB[2]
		wayB[1]=wayB[1]+wayA[0]
		wayB[2]=wayB[2]+wayA[1]
		wayA[1]=wayA[1]+1
		hatena=hatena+1
	for z in range(0,4):
		wayA[z]=wayA[z]%MOD
		wayB[z]=wayB[z]%MOD
		wayC[z]=wayC[z]%MOD
ans=0
for i in range(0,4):
	p3=1
	if wayC[i]<=0:
		continue
	for k in range(0,hatena-i):
		p3=p3*3
		p3=p3%MOD
	ans=ans+p3*wayC[i]
	ans=ans%MOD
print(int(ans))
### BUGGY CODE ###

N , M = map(int, input().split())
P = [0]*M
Y = [0]*M
x = [0]*M
for i in range(M):
    P[i],Y[i] =  map(int, input().split())

Y_s = sorted(Y)
count = [1]*(N+1)
ans = [0]*M
for i in range(M):
    j = Y.index(Y_s[i])
    ans[j] = str(P[j]).zfill(6) + str(count[P[j]]).zfill(6)
    count[P[j]] = count[P[j]] +1

for i in range (M):
    print(ans[i])


### FIXED CODE ###

import numpy as np
N , M = map(int, input().split())
P = [0]*M
Y = [0]*M
for i in range(M):
    P[i],Y[i] =  map(int, input().split())

Y_ = np.argsort(Y)
count = [1]*(N+1)
ans = [0]*M
for i in range(M):
    ans[Y_[i]] = str(P[Y_[i]]).zfill(6) + str(count[P[Y_[i]]]).zfill(6)
    count[P[Y_[i]]] = count[P[Y_[i]]] +1
 
for i in range (M):
    print(ans[i])
### BUGGY CODE ###

N = input()
digit = len(N)
mod = 1000000007

# dp[i番目まで][未満かどうか][mod13]
dp = [[[0]*13 for _ in range(2)] for _ in range(digit+2)]
dp[0][0][0] = 1

for i in range(digit-1,-1,-1):
  ii = digit-i-1
  d = 10**(ii)
  for j in range(2):
    for k in range(13):
      if N[i] == "?":
        for n in range(9+1):
          dp[ii+1][j][(k + n*d)%13] += dp[ii][j][k] %mod
      else:
        n = int(N[i])
        dp[ii+1][j][(k + n*d)%13] += dp[ii][j][k] %mod

print((dp[digit][0][5] + dp[digit][1][5]) %mod)

### FIXED CODE ###

#N = "?"*(100000)
N = input()
digit = len(N)
mod = 1000000007

# dp[i番目まで][未満かどうか][mod13], 計算量O(10**5 * 2 * 13 * 10)
dp = [[[0]*13 for _ in range(2)] for _ in range(digit+1)]
dp[0][0][0] = 1

d = 1/10
for i in range(digit-1,-1,-1):
  ii = digit-i-1
  d = int((d*10)%13)
  for j in range(2):
    for k in range(13):
      if N[i] == "?":
        for n in range(9+1):
          dp[ii+1][j][(k + n*d) %13] += dp[ii][j][k] %mod
      else:
        n = int(N[i])
        dp[ii+1][j][(k + n*d) %13] += dp[ii][j][k] %mod

print((dp[digit][0][5] + dp[digit][1][5]) %mod)
#print(dp[-10:])
### BUGGY CODE ###

N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
ans = 0
diff = [L[i] - L[i+1] for i in range(N-1)]

for i in range(N):
    d = 0
    for j in range(i+1, N):
        d += diff[j-1]
        for k in range(j+1, N):
            if d < L[k]:
                ans += 1
            else:
                break
print(ans)


### FIXED CODE ###

import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
R = sorted(L)
ans = 0
diff = [L[i] - L[i+1] for i in range(N-1)]

for i in range(N):
    d = 0
    for j in range(i+1, N):
        d += diff[j-1]
        k = bisect.bisect_left(R, d+1)
        ans += max(N-k-1 - j, 0)

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

S = list(input())
L = [0]*2019
L[0]=1

for i in range(len(S)):
    N = int("".join(S[i:]))%2019
    L[N] += 1

ans = 0

for i in range(len(L)):
    ans += L[i]*(L[i]-1)//2

print(ans)

### FIXED CODE ###

S = list(input())
L = [0]*2019
L[0]=1
digit = 1
x = 0

for i in S[::-1]:
    x += digit*int(i)
    digit *= 10
    x %= 2019
    digit %= 2019 
    L[x] += 1

ans = 0

for i in L:
    ans += i*(i-1)//2

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

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

### FIXED CODE ###

from collections import deque
s = deque(input())
n = int(input())
qs = [list(input().split()) for i in range(n)]
pre = deque()
suf = deque()
frag = True
for q in qs:
    if len(q) == 1:
        frag = not frag
    else:
        if (frag, q[1]) == (True, "1") or (frag, q[1]) == (False, "2"):
            pre.appendleft(q[2])
        else:
            suf.append(q[2])
if frag is True:
    print("".join(list(pre)+list(s)+list(suf)))
else:
    suf.reverse()
    s.reverse()
    pre.reverse()
    print("".join(list(suf)+list(s)+list(pre)))
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	n,m=map(int,input().split())
	li=[[] for i in range(n+1)]
	for i in range(m):
		l,r,d=map(int,input().split())
		li[l].append((r,d))
		li[r].append((l,-d))
	
	stack=[]
	check=set()
	a=["a"]*(n+1)
	
	for i in range(1,n+1):
		if li[i]==["a"] or (i in check):
			continue
		else:
			stack.append(i)
			a[i]=0
			while stack:
				now=stack.pop()
				check.add(now)
				for j in li[now]:
					if j[0] in check:
						if a[j[0]]-a[now]!=j[1]:
							print("No")
							exit(0)
						else:
							#a[j[0]]=a[now]+j[1]
							continue
					if j[0] in stack:
						continue
					a[j[0]] = a[now] + j[1]
					stack.append(j[0])
					
	print("Yes")
	
	
if __name__ == '__main__':
	main()

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	n,m=map(int,input().split())
	li=[[] for _ in range(n+1)]
	for i in range(m):
		l,r,d=map(int,input().split())
		li[l].append((r,d))
		li[r].append((l,-d))
	
	q=deque()
	a=[None]*(n+1)

	for i in range(1,n+1):
		if a[i]==None:
			q=[i]
			a[i]=0
			while q:
				now=q.pop()
				for r,d in li[now]:
					if a[r]==None:
						a[r] = a[now] + d
						q.append(r)
					else:
						if a[r]-a[now]!=d:
							print("No")
							exit(0)
						else:
							continue
					
	print("Yes")
	
	
if __name__ == '__main__':
	main()
### BUGGY CODE ###

import math
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))

A.sort()
C = defaultdict(int)
ans = 0

for a in A:
    C[a] += 1

D = set()

B = []


for a in A:
    if C[a] == 1:
        for b in B:
            if a % b == 0:
                break
        else:
            ans += 1
            B.append(a)
    else:
        if a not in D:
            B.append(a)
            D.add(a)


print(ans)


### FIXED CODE ###

import math
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))

A.sort()

D = defaultdict(int)
for a in A:
    D[a] += 1

B = [False] * (10**6 + 1)

ans = 0

for a in A:
    if B[a] == False:
        c = 1
        i = a * c
        while i <= 10 ** 6:
            B[i] = True
            c += 1
            i = a * c
        if D[a] == 1:
            ans += 1

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

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

for k in range(N):
    l = sorted([A[i] for i in range(N) if i!=k])
    counter = 0
    result = 0
    for i in range(len(l)):
        counter += 1
        if i!=len(l)-1:
            if l[i] != l[i+1]:
                #print(l[i],counter)
                result += counter*(counter-1)//2
                counter = 0
        else:
            #print(l[i],counter)
            result += counter*(counter-1)//2
    print(result)

### FIXED CODE ###

from collections import Counter

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

l = Counter(A)
ans = sum([v*(v-1)//2 for v in l.values()])

for a in A:
    print(ans - l[a]*(l[a]-1)//2 + (l[a]-1)*(l[a]-2)//2)
### BUGGY CODE ###

#
import sys
import math
import numpy as np
import itertools
# いくつか入力
n,t = (int(i) for i in input().split())  

# n行の複数列ある数値を二次元配列へ。x[n][?]
ab = [[int(i) for i in input().split()] for i in range(n)]
# 0:weight 1:value

ab = sorted(ab,key=lambda x: x[1])

dp = np.zeros((n+1,t),int)
dp2 = np.zeros((n+1,t),int)


for i in range(n):
    for w in range(t):
        if w >= ab[i][0] :
            dp[i+1][w] = max(dp[i][w-ab[i][0]] + ab[i][1], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]
        if w >= ab[i][0] :
            dp2[i+1][w] = max(dp2[i][w-ab[i][0]] + ab[i][1],dp[i][w] + ab[i][1], dp[i][w])
        else:
            dp2[i+1][w] = max(dp[i][w] + ab[i][1], dp[i][w])

answer =0
for i in range(n+1):
    for w in range(t):
        answer = max(answer, dp2[i][w])
print(answer)

#print(dp2)


### FIXED CODE ###

#
import sys
import math
import numpy as np
import itertools
# いくつか入力
n,t = (int(i) for i in input().split())

# n行の複数列ある数値を二次元配列へ。x[n][?]
ab = [[int(i) for i in input().split()] for i in range(n)]
# 0:weight 1:value

ab = sorted(ab,key=lambda x: x[1])

dp = np.zeros((n+1,t),int)
dp2 = np.zeros((n+1,t),int)

for i in range(n):
    w = ab[i][0]
    dp[i+1][w:] = np.fmax(dp[i][:-w] + ab[i][1], dp[i][w:])
    dp2[i+1][w:] = np.fmax(dp2[i][:-w] + ab[i][1],dp[i][w:] + ab[i][1], dp2[i][w:])
    dp[i+1][:w] = dp[i][:w]
    dp2[i+1][:w] = np.fmax(dp[i][:w] + ab[i][1], dp2[i][:w])

answer = np.amax(dp2)
print(answer)
### BUGGY CODE ###

n=int(input())
s=input()
ans=0
for i in range(10):
  flag1=False
  for a in range(n-2):
    if s[a]==str(i):
      flag1=True
      min_a=a
      break
  if flag1:
    for j in range(10):
      flag2=False
      for b in range(min_a+1,n-1):
        if s[b]==str(j):
          flag2=True
          min_b=b
          break
      if flag2:
        for k in range(10):
          flag3=False
          for c in range(min_b+1,n):
            if s[c]==str(k):
              flag3=True
              break
          if flag3==1:
            ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
s=input()
ans=0
alist=[0]*10
for i in range(n):
  alist[int(s[i])]=i
for i in range(10):
  flag1=False
  for a in range(n-2):
    if s[a]==str(i):
      flag1=True
      break
  if flag1:
    for j in range(10):
      flag2=False
      for b in range(a+1,n-1):
        if s[b]==str(j):
          flag2=True
          break
      if flag2:
        for k in range(10):
          if b<alist[k]:
            ans+=1
print(ans)