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

num = int(input())
def to3(x,n):
  if (int(x/n)):
    return to3(int(x/n),n) + str(x%n)
  return str(x%n)
c = ["3","5","7"]
ch = ["0","3","5","7"]
ans = 0
for i in range(4 ** len(str(num))):
  s = to3(i,4)
  ss = ""
  for j in range(len(s)):
    ss += ch[int(s[j])]
  key = 1
  k1 = 0
  k2 = 0
  k3 = 0
  for k in range(len(ss)):
    if ss[k] == "0":
      key = 0
      break
    elif ss[k] == "3":
      k1 = 1
    elif ss[k] == "5":
      k2 = 1
    else:
      k3 = 1
  if key == 1 and k1 and k2 and k3 and int(ss) <= num:ans += 1
print(ans)

### FIXED CODE ###

num = int(input())
def to3(x,n):
  if (int(x/n)):
    return to3(int(x/n),n) + str(x%n)
  return str(x%n)
ch = ["3","5","7"]
ans = 0
for i in range(3 ** len(str(num))+1):
  s = to3(i,3)
  for u in range(len(str(num))-len(s)+2):
    if u > 0:
      s = "0" + s
    k1 = 0
    k2 = 0
    k3 = 0
    ss = ""
    for j in range(len(s)):
      if s[j] == "0":k1 = 1
      elif s[j] == "1":k2 = 1
      else: k3 = 1
      ss += ch[int(s[j])]
    if k1 and k2 and k3 and int(ss) <= num:ans += 1
print(ans)
### BUGGY CODE ###

import bisect

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

R_index = []
G_index = []
B_index = []

for i, s in enumerate(S):
    if s == 'R':
        R_index.append(i)
    elif s == 'G':
        G_index.append(i)
    elif s == 'B':
        B_index.append(i)

ans = 0
for i in R_index:
    for j in G_index:
        for k in B_index:
            if i < j < k and j - i != k - j:
                ans += 1
    for j in B_index:
        for k in G_index:
            if i < j < k and j - i != k - j:
                ans += 1

for i in G_index:
    for j in R_index:
        for k in B_index:
            if i < j < k and j - i != k - j:
                ans += 1
    for j in B_index:
        for k in R_index:
            if i < j < k and j - i != k - j:
                ans += 1

for i in B_index:
    for j in G_index:
        for k in R_index:
            if i < j < k and j - i != k - j:
                ans += 1
    for j in R_index:
        for k in G_index:
            if i < j < k and j - i != k - j:
                ans += 1

print(ans)

### FIXED CODE ###

from collections import Counter

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

counter = Counter(S)
r_count = counter['R']
g_count = counter['G']
b_count = counter['B']

ans = r_count * g_count * b_count
for i in range(N):
    for j in range(N):
        k = 2 * j - i
        if k > N-1:
            break
        if i < j < k and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1

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

n, k = map(int, input().split())

for i in range(10**9):
    if k**i < n and n < k**(i + 1):
        cnt = i + 1
        break

print(cnt)


### FIXED CODE ###

import math

n, k = map(int, input().split())

a = int(math.log(n, k))

for i in range(a + 2):
    if n < k**i:
        print(i)
### BUGGY CODE ###

n = int(input())
a_list = list(map(int,input().split()))
p = 1
for i in range(n):
    p *= a_list[i]
if p > 10**18:
        print(-1)
else:
    print(p)


### FIXED CODE ###

n = int(input())
a_list = list(map(int,input().split()))
p = 1
for i in range(n):
    if a_list[i] == 0:
        print(0)
        exit()
for i in range(n):
    p *= a_list[i]
    if p > 10**18:
        print(-1)
        exit()
print(p)
### BUGGY CODE ###

import itertools
S = input()
N = len(S)
S = '0' + S
if S[:2] == '01' and S == S[::-1]:
    B = set([i for i, v in enumerate(S[:(N + 1) // 2 + 1]) if v == '1'])
    before = 1
    for i in range(2, N + 1):
        print(before, i)
        if i - 1 in B and i < max(B) + 2:
            before = i
else:
    print(-1)


### FIXED CODE ###

S = input()
N = len(S)
S = '0' + S
if S[:2] == '01' and S == S[::-1]:
    before = 1
    for i in range(2, N + 1):
        print(before, i)
        if S[i - 1] == '1' and i < (N + 1) // 2 + 2:
            before = i
else:
    print(-1)
### BUGGY CODE ###

s = input()
n = len(s)
ans = 0
for i in range(n-3):
    for j in range(i+3,n):
        if int(s[i:j+1]) % 2019 == 0:
            ans += 1
print(ans)


### FIXED CODE ###

s = input()[::-1]
a = 0
cnt = [0]*2019
cnt[0] = 1
d = 1
for c in s:
    a += int(c) * d
    a %= 2019
    d *= 10
    d %= 2019
    cnt[a] += 1

#slist = [(s%(10**i))%2019 for i in range(n+1)]
#print(slist)


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

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

N = int(input())
s_list = [input() for _ in range(N)]

new_s = []
for i, s in enumerate(s_list):
    new_s.append(set(s))

match = []
new_match = []
M=[i for i in range(N)]
center = int(N/2)

if N%2==0:
    for i in range(N-1):
        for i in range(center):
            match.append((M[0+i],M[-1-i]))
        M = M[:1] + M[2:] + M[1:2]
else:
    for i in range(N):
        for i in range(1,center+1):
            match.append((M[i],M[-i+1]))
        M = M[1:] + M[:1]
for m in match:
    if new_s[m[0]] == new_s[m[1]]:
        new_match.append(m)

a = []
count = 0
for nm in new_match:
    if [{char, s_list.count(char)}for char in list(set(s_list[nm[0]]))] == [{char, s_list.count(char)}for char in list(set(s_list[nm[1]]))]:
        count += 1
print(count)

### FIXED CODE ###

N = int(input())
s_list = [input() for _ in range(int(N))]
import math
ok = {}
count = 0
for s in s_list:
    s = ''.join(sorted(s))
    if s in ok:
        ok[s] += 1 
    else:
        ok[s] = 1

for val in ok:
    prev = (ok[val] - 1)
    if prev != 0:
        count += math.floor(ok[val] * prev / 2)
print(count)
### BUGGY CODE ###

def digits_of (n):
  digits = []
  while n != 0:
    r = n % 10
    digits.append(r)
    n = n // 10
  return digits

N = int(input())
S = 0
for i in digits_of(N):
  S += i

if S % 9 == 0:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

N = list(input())
S = 0
for i in N:
  S += int(i)

if S % 9 == 0:
  print('Yes')
else:
  print('No')
### BUGGY CODE ###

from itertools import product
from collections import deque
import numpy as np
class Grid():
    def __init__(self, grid, w=0, h=0, function=lambda x: x):
        self.w = w = w if w else len(grid[0])
        self.h = h = h if h else len(grid)
        dtype = type(function(grid[0][0]))
        self.grid = np.empty((h, w), dtype=dtype)
        for i, row in zip(range(h), grid):
            for j, val in zip(range(w), row):
                self.grid[i][j] = function(val)
    
    def is_valid_x(self, x):
        return 0 <= x < self.w
    def is_valid_y(self, y):
        return 0 <= y < self.h
    def is_valid_xy(self, x, y):
        return self.is_valid_x(x) and self.is_valid_y(y) 
    
    def __iter__(self):
        return iter(self.grid)
    def __repr__(self):
        return '\n'.join([' '.join(map(str, row)) for row in self.grid])
    def __getitem__(self, x):
        return self.grid[x]
    def __setitem__(self, x, val):
        self.grid[x] = val

X = iter(open(0).readlines())
h, w = map(int, next(X).split())
ch, cw = map(int, next(X).split())
dh, dw = map(int, next(X).split())
dp = Grid([x.strip() for x in X], function=lambda x: 10**6 if x == '.' else -1)

def bfs(root):
    def search(queue):
        delta = [(dx, dy) for dx, dy in product(range(-2, 3), repeat=2) if abs(dx) + abs(dy) >= 2]
        
        while queue:
            x, y = queue.pop()
            d = dp[y, x]
            for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
                nx, ny = x+dx, y+dy
                if dp.is_valid_xy(nx, ny) and dp[ny, nx] > d:
                    dp[ny, nx] = d
                    queue.append((nx, ny))
        for x, y in product(range(w), range(h)):
            if dp[y, x] == d:
                 for dx, dy in delta:
                    nx, ny = x+dx, y+dy
                    if dp.is_valid_xy(nx, ny) and dp[ny, nx] > d+1:
                        dp[ny, nx] = d+1
                        queue.append((nx, ny))
        if queue:
            search(queue)
    
    x, y = root
    dp[y, x] = 0
    queue = deque([root])
    search(queue)
    
bfs((cw-1, ch-1))
if dp[dh-1, dw-1] == 10**6:
    print(-1)
else:
    print(dp[dh-1, dw-1])

### FIXED CODE ###

from collections import deque
from itertools import product
h, w = list(map(int,input().split()))
sy, sx = list(map(int,input().split()))
gy, gx = list(map(int,input().split()))
sx, sy, gx, gy = sx-1, sy-1, gx-1, gy-1
 
G = [list(input()) for _ in range(h)]
D = [[10**6]*w for _ in range(h)]
D[sy][sx] = 0
Q = deque([(sy, sx)])
while Q:
    y, x = Q.pop()
    for dy, dx in product(range(-2, 3), repeat=2):
        ny, nx = y+dy, x+dx
        if dx==dy==0:
            G[y][x] = '#'
            continue
        elif ny<0 or h<=ny or nx<0 or w<=nx:
            continue
        elif G[ny][nx] == '#':
            continue
        elif abs(dy)+abs(dx)<=1:
            G[ny][nx] = '#'
            D[ny][nx] = D[y][x]
            Q.append((ny, nx))
        elif D[ny][nx] == 10**6:
            D[ny][nx] = D[y][x]+1
            Q.appendleft((ny, nx))
            
if D[gy][gx] == 10**6:
    print(-1)
else:
    print(D[gy][gx])
### BUGGY CODE ###

import statistics
n = int(input())
x = list(map(int,input().split()))

for i in range(n):
  xx = x[:i] + x[i+1:]
  print(statistics.median(xx))
  

### FIXED CODE ###

import statistics
n = int(input())
x = list(map(int,input().split()))

median_left = statistics.median_low(x)
median_right = statistics.median_high(x)

for i in range(n):
  if x[i] == median_right:
    print(median_left)
  elif x[i] == median_left:
    print(median_right)
  else:
    if x[i] < median_left:
      print(median_right)
    else:
      print(median_left)
### BUGGY CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
a=list(map(int,input().split()))
ans=float('inf')
rui=[0]*(n+1)
for i in range(n):
    rui[i+1]=rui[i]+a[i]
for i in range(2,n-1):
    p,q,r,s=0,0,0,0
    # left=sum(a[:i])
    # right=sum(a[i:])
    # print()
    # print(left)
    # print(right)
    tmppq=[float('inf'),0,0]
    tmprs=[float('inf'),0,0]
    for j in range(i-1):
        p=rui[j+1]
        q=rui[i]-p
        if tmppq[0]>abs(p-q):
            tmppq=[abs(p-q),p,q]
    for j in range(i,n-1):
        r=rui[j+1]-rui[i]
        s=rui[n]-rui[j+1]
        # print(r)
        # print(s)
        if tmprs[0]>abs(r-s):
            tmprs=[abs(r-s),r,s]
    ans=min(ans,max(tmppq[1],tmppq[2],tmprs[1],tmprs[2])-min(tmppq[1],tmppq[2],tmprs[1],tmprs[2]))
print(ans)

### FIXED CODE ###

import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

lst=ruiseki(a)
ans=float('inf')

kirekomi=[1,3]

for i in range(2,n-1):
    while 1:
        if abs(lst[kirekomi[0]]-(lst[i]-lst[kirekomi[0]]))>abs(lst[kirekomi[0]+1]-(lst[i]-lst[kirekomi[0]+1])):
            kirekomi[0]+=1
        else:
            break
    
    while 1:
        if abs((lst[n]-lst[kirekomi[1]])-(lst[kirekomi[1]]-lst[i]))>abs((lst[n]-lst[kirekomi[1]+1])-(lst[kirekomi[1]+1]-lst[i])):
            kirekomi[1]+=1
        else:
            break
    
    # print(kirekomi)
    p=lst[kirekomi[0]]
    q=lst[i]-lst[kirekomi[0]]
    r=lst[kirekomi[1]]-lst[i]
    s=lst[n]-lst[kirekomi[1]]
    anslst=[p,q,r,s]
    ans=min(ans,max(anslst)-min(anslst))
    # print(anslst)
print(ans)
### BUGGY CODE ###

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

MOD = 998244353
 
# dp[i][j] = i 番目までの選択をして、1 つめの選択肢を選んだ k に対する ak の和が j であるような場合の数
dp = [[0] * (s + 1) for _ in range(n + 1)]
dp[0][0] = 1

for i in range(n):
  for j in range(s + 1):
    dp[i + 1][j] += dp[i][j] * 2
    dp[i + 1][j] %= MOD
    if j + A[i] <= s:
      dp[i + 1][j + A[i]] += dp[i][j]
      dp[i + 1][j + A[i]] %= MOD

print(dp[-1][-1])

### FIXED CODE ###

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

MOD = 998244353
 
# dp[i][j] = i 番目までの選択をして、1 つめの選択肢を選んだ k に対する ak の和が j であるような場合の数
dp = [[0] * (s + 1) for _ in range(n + 1)]
dp[0][0] = 1

for i in range(n):
  for j in range(s + 1):
    dp[i + 1][j] += dp[i][j] * 2
    dp[i + 1][j] %= MOD
    if j + A[i] <= s:
      dp[i + 1][j + A[i]] += dp[i][j]
      dp[i + 1][j + A[i]] %= MOD

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

import sys
sys.setrecursionlimit(10**7)
from functools import lru_cache

def main():
    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))
    dp = [0] * N

    @lru_cache(maxsize=None)
    def hoge(z, w, n, turn):
        if n == 0:
            return abs(z - w)
        if turn:
            return max(hoge(A[N - 1 - i], w, i, not turn) for i in range(n))
        else:
            return min(hoge(z, A[N - 1 - i], i, not turn) for i in range(n))
    return hoge(Z, W, N, True)

print(main())


### FIXED CODE ###

def main():
    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))
    if N == 1:
        return abs(A[-1] - W)
    return max(abs(A[-1] - W), abs(A[-1] - A[-2]))


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

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

c = 0

while True:
    gusu = False

    for i, aa in enumerate(a):
        if gusu is False and a[i] % 2 == 0:
            a[i] /= 2
            gusu = True

    if gusu is False:
        break

    c += 1

print(c)


### FIXED CODE ###

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

c = 0

for i, aa in enumerate(a):
    while a[i] % 2 == 0:
        a[i] /= 2
        c += 1

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

N=int(input())
S=input()
counter=[[0 for i in range(N)] for _ in range(3)]#i+1より右側にあるR(0),G(1),B(2)の数
if S[N-1]=="R":
  counter[0][N-1]=1
elif S[N-1]=="G":
  counter[1][N-1]=1
else:
  counter[2][N-1]=1
for i in range(1,N):
  if S[N-1-i]=="R":
    counter[0][N-1-i]=counter[0][N-i]+1
  elif S[N-1-i]=="G":
    counter[1][N-1-i]=counter[1][N-i]+1
  else:
    counter[2][N-1-i]=counter[2][N-i]+1
  counter[0][N-1-i]=max(counter[0][N-i],counter[0][N-1-i])
  counter[1][N-1-i]=max(counter[1][N-i],counter[1][N-1-i])
  counter[2][N-1-i]=max(counter[2][N-i],counter[2][N-1-i])
ans=0
for i in range(N-1):
  if S[i]=="R":
    for j in range(i+1,N):
      if S[j]=="G":
        ans+=counter[2][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="B":
            ans-=1
      elif S[j]=="B":
        ans+=counter[1][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="G":
            ans-=1
for i in range(N-1):
  if S[i]=="G":
    for j in range(i+1,N):
      if S[j]=="R":
        ans+=counter[2][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="B":
            ans-=1
      elif S[j]=="B":
        ans+=counter[0][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="R":
            ans-=1
for i in range(N-1):
  if S[i]=="B":
    for j in range(i+1,N):
      if S[j]=="R":
        ans+=counter[1][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="G":
            ans-=1
      elif S[j]=="G":
        ans+=counter[0][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="R":
            ans-=1
print(ans)

### FIXED CODE ###

N=int(input())
S=input()
counter=[[0 for i in range(N)] for _ in range(3)]#i+1より右側にあるR(0),G(1),B(2)の数
if S[N-1]=="R":
  counter[0][N-1]=1
elif S[N-1]=="G":
  counter[1][N-1]=1
else:
  counter[2][N-1]=1
for i in range(1,N):
  if S[N-1-i]=="R":
    counter[0][N-1-i]=counter[0][N-i]+1
  elif S[N-1-i]=="G":
    counter[1][N-1-i]=counter[1][N-i]+1
  else:
    counter[2][N-1-i]=counter[2][N-i]+1
  counter[0][N-1-i]=max(counter[0][N-i],counter[0][N-1-i])
  counter[1][N-1-i]=max(counter[1][N-i],counter[1][N-1-i])
  counter[2][N-1-i]=max(counter[2][N-i],counter[2][N-1-i])
ans=0
for i in range(N-1):
  if S[i]=="R":
    for j in range(i+1,N):
      if S[j]=="G":
        ans+=counter[2][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="B":
            ans-=1
      elif S[j]=="B":
        ans+=counter[1][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="G":
            ans-=1
for i in range(N-1):
  if S[i]=="G":
    for j in range(i+1,N):
      if S[j]=="R":
        ans+=counter[2][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="B":
            ans-=1
      elif S[j]=="B":
        ans+=counter[0][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="R":
            ans-=1
for i in range(N-1):
  if S[i]=="B":
    for j in range(i+1,N):
      if S[j]=="R":
        ans+=counter[1][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="G":
            ans-=1
      elif S[j]=="G":
        ans+=counter[0][j]
        if 2*j-i<=N-1:
          if S[2*j-i]=="R":
            ans-=1
print(ans)
### BUGGY CODE ###

n = int(raw_input())
A = map(int, raw_input().split())
q = int(raw_input())
m = map(int, raw_input().split())

A = sorted(A)
#m = sorted(m)

def sum_A(A, n, pos, sum, m, res):
    if res[0] == "yes":
        return 0
    if sum + A[pos] > m:
        return 0
    if sum + A[pos] == m:
        res[0] = "yes"
        return 0
    if pos + 1 > n - 1:
        return 0
    sum_A(A, n, pos + 1, sum + A[pos], m, res)
    sum_A(A, n, pos + 1, sum, m, res)

for i, m_i in enumerate(m):
    sum = 0
    res = ["no"]
    sum_A(A, n, 0, sum, m_i, res)
    print res[0]

### FIXED CODE ###

def sequence(A, n):
    dic = {}
    
    def solve(i, m):
        if (i, m) in dic:
            return dic[(i, m)]
        if m == 0:
            dic[(i, m)] = True
        elif i >= n:
            dic[(i, m)] = False
        elif solve(i+1, m):
            dic[(i, m)] = True
        elif solve(i+1, m-A[i]):
            dic[(i, m)] = True
        else:
            dic[(i, m)] = False
        return dic[(i, m)]
    
    return solve

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    q = int(raw_input())
    m = map(int, raw_input().split())

    solve = sequence(A, n)
    for m_i in m:
        print "yes" if solve(0, m_i) else "no"
### BUGGY CODE ###

import math
import copy
import sys
import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

a = getInputListInt()
min = a[0]
max = a[1]

ans_max = 2019
ans = ans_max

for i in range(min, max):
    for j in range(i+1, max+1):
        tmp = (i*j) % ans_max

        if ans > tmp:
            ans = tmp

print(ans)

### FIXED CODE ###

import math
import copy
# import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

a = getInputListInt()
min = a[0]
max = a[1]

ans_max = 2019
ans = ans_max

flg = False

for i in range(min, max):
    for j in range(i+1, max+1):
        tmp = (i*j) % ans_max

        if ans > tmp:
            ans = tmp

        if ans == 0:
            flg = True
            break

    if flg:
        break

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

def resolve():
    N = int(input())
    power = 1
    for i in range(1, N+1):
        power *= i
    print(power%(10**9+7))


if '__main__' == __name__:
    resolve()

### FIXED CODE ###

def resolve():
    N = int(input())
    power = 1
    for i in range(1, N+1):
        power *= i
        power = power%(10**9+7)
    print(power)


if '__main__' == __name__:
    resolve()
### BUGGY CODE ###

n,w=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]

lim=n*10**3+1
dp=[[float('inf') for i in range(lim)] for i in range(n+1)]

for i in range(n+1):
 dp[i][0]=0

for i in range(n):
 for sum_v in range(lim):

  if sum_v-l[i][1]>=0:
   dp[i+1][sum_v] = min(dp[i+1][sum_v],dp[i][sum_v-l[i][1]]+l[i][0])

  dp[i+1][sum_v]=min(dp[i+1][sum_v],dp[i][sum_v])

ans=0
for i in range(lim):
 if dp[-1][i]<=w:
  ans=max(ans,i)
print(ans)

### FIXED CODE ###

n,w=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]

lim=n*10**3+1
#dp=[[float('inf') for i in range(lim)] for i in range(n+1)]
dp=[[10**15 for i in range(lim)] for i in range(n+1)]

'''
for i in range(n+1):
 dp[i][0]=0
'''
dp[0][0]=0

for i in range(n):
 for sum_v in range(lim):

  if sum_v-l[i][1]>=0:
   dp[i+1][sum_v] = min(dp[i+1][sum_v],dp[i][sum_v-l[i][1]]+l[i][0])

  dp[i+1][sum_v]=min(dp[i+1][sum_v],dp[i][sum_v])

ans=0
for i in range(lim):
 if dp[-1][i]<=w:
  ans=max(ans,i)
print(ans)
### BUGGY CODE ###

import numpy as np                       
                                         
N,K,*A = map(int, open(0).read().split())
                                         
for _ in range(K):                       
    X = np.ones(N, int)                  
    for i, d in enumerate(A):            
        X[max(0,i-d):max(0,i)] += 1      
        X[i+1:i+d+1] += 1                
    A = X                                
                                         
print(" ".join(map(str, A)))             

### FIXED CODE ###

N,K,*A = map(int, open(0).read().split())
                                         
for _ in range(K):                       
    b = [0] * N                          
    for i, d in enumerate(A):            
        b[max(0, i-d)] += 1              
        if i+d+1 < N:                    
            b[i+d+1] -= 1                
    for i in range(1, N):                
        b[i] += b[i-1]                   
    if A == b:                           
        break                            
    A = b                                
                                         
print(" ".join(map(str, A)))
### BUGGY CODE ###

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

memo = [0]*100
counter = 0

for i in range(n):
    for j in range(i+1,n):
            if memo[int(s[i])*10+int(s[j])] == 0:
                memo[int(s[i])*10+int(s[j])] = 1
                counter += len(set(s[j+1:]))
        
print(counter)

### FIXED CODE ###


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

imemo = [0]*10
memo = [0]*100
counter = 0

for i in range(n):
    if imemo[int(s[i])] == 0:
        imemo[int(s[i])] = 1
    else:
        continue
        
    for j in range(i+1,n):
        if memo[int(s[i])*10+int(s[j])] == 0:
                memo[int(s[i])*10+int(s[j])] = 1
                counter += len(set(s[j+1:]))
print(counter)