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

def main():
    S = input()
    l = []
    l2 = []
    mod = (10 ** 9) + 7
    for i in range(6):
        d = {j:0 for j in range(13)}
        d2 = {j:0 for j in range(10)}
        for j in range(0, 10):
            t = (j *(10 ** i)) % 13
            d[t] += 1
            d2[j] = t
        l.append(d)
        l2.append(d2)
    r = 0
    c = {j:0 for j in range(13)}
    c[0] = 1
    n = {j:0 for j in range(13)}
    for i, v in enumerate(reversed(S)):
        if v == '?':
            for j in range(13):
                for k in range(13):
                    n[(j + k) % 13] += c[k] * l[i % 6][j]
            c = n
            n = {j:0 for j in range(13)}
        else:
            r += (l2[i % 6][int(v)])
    r = (5 - r) % 13
    print(c[r] % mod)
main()



### FIXED CODE ###

def main():
    S = input()
    l = []
    l2 = []
    mod = (10 ** 9) + 7
    for i in range(6):
        d = [0] * 13
        d2 = [0] * 10
        for j in range(0, 10):
            t = (j *(10 ** i)) % 13
            d[t] += 1
            d2[j] = t
        l.append(d)
        l2.append(d2)
    r = 0
    c = [0] * 13
    c[0] = 1
    n = [0] * 13
    i = 0
    for v in reversed(S):
        if v == '?':
            k = 0
            for j in range(13):
                for k in range(13):
                    if l[i][j]:
                        kk = (j+k) % 13
                        n[kk] += c[k]
                        n[kk] %= mod
            c = n
            n = [0] * 13
        else:
            r += (l2[i][int(v)])
            r %= 13
        i += 1
        i %= 6
    r = (5 - r) % 13
    print(c[r] % mod)
main()
### BUGGY CODE ###

n,m = map(int,input().split(" "))
a=[]
mod = 10 ** 9 + 7
for i in range(m):
    a.append(int(input()))

dp = [0] * (n+1)
for j in range(n+1):
    if j in a:
        dp[j] = 0
    elif j == 1 or j == 0:
        dp[j] = 1
    else:
        dp[j] = (dp[j-1] + dp[j-2]) % mod

print(dp[n])


### FIXED CODE ###

n,m = map(int,input().split(" "))
a=[0] * (n+1)
mod = 10 ** 9 + 7
for i in range(m):
    a[int(input())] = 1

dp = [0] * (n+1)
for j in range(n+1):
    if a[j] == 1:
        dp[j] = 0
    elif j == 1 or j == 0:
        dp[j] = 1
    else:
        dp[j] = (dp[j-1] + dp[j-2]) % mod

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

T = input()

while "?" in T:
    idx = T.find("?")
    if idx == len(T) - 1:
        T = T[:-1] + "D"
    elif idx == 0:
        if T[idx + 1] == "D":
            T = "P" + T[idx + 1 :]
        else:
            T = "D" + T[idx + 1 :]
    else:
        if T[idx + 1] == "D":
            T = T[:idx] + "P" + T[idx + 1 :]
        else:
            T = T[:idx] + "D" + T[idx + 1 :]

print(T)

### FIXED CODE ###

T = list(input())

for i in range(len(T)):
    if T[i] == "?":
        if i == len(T) - 1:
            T[i] = "D"
        else:
            if i > 0 and T[i - 1] == "P":
                T[i] = "D"
            elif T[i + 1] == "D" or T[i + 1] == "?":
                T[i] = "P"
            else:
                T[i] = "D"

print("".join(T))
### BUGGY CODE ###

def main(n,a,b,c):
  import bisect
  ans=0
  todo=[[ai] for ai in a]
  while len(todo)>0:
    d=todo.pop()
    if len(d)==1:
      l=bisect.bisect_right(b,d[-1])
      for li in b[l:]:
        e=[di for di in d]
        e.append(li)
        todo.append(e)
    if len(d)==2:
      l=bisect.bisect_right(c,d[-1])
      for li in c[l:]:
        e=[di for di in d]
        e.append(li)
        todo.append(e)
    if len(d)==3:
      ans+=1
  print(ans)
if __name__=='__main__':
  n=int(input())
  a=sorted(list(map(int,input().split())))
  b=sorted(list(map(int,input().split())))
  c=sorted(list(map(int,input().split())))
  """
  n=100000
  a=list(range(1,1+n))
  b=list(range(2,2+n))
  c=list(range(3,3+n))
  """
  main(n,a,b,c)


### FIXED CODE ###

def main(n,a,b,c):
  import bisect
  ans=0
  for i in range(n):
    na=bisect.bisect_left(a,b[i])
    nc=n-bisect.bisect_right(c,b[i])
    ans+=na*nc
  print(ans)
if __name__=='__main__':
  n=int(input())
  a=sorted(list(map(int,input().split())))
  b=sorted(list(map(int,input().split())))
  c=sorted(list(map(int,input().split())))
  main(n,a,b,c)
### BUGGY CODE ###

def gcd(a,b):
	if b ==0:
		return a
	else:
		return gcd(b,a%b)

k = int(input())
ans = 0
for i in range(1,k+1):
	for p in range(1,k+1):
		for q in range(1,k+1):
			ans+=gcd(i,gcd(p,q))

print(ans)

### FIXED CODE ###


from math import gcd
k = int(input())
ans = 0
for i in range(1,k+1):
	for p in range(1,k+1):
		for q in range(1,k+1):
			ans+=gcd(q,gcd(i,p))

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

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

a = []
x = 0 #1の個数
y = 0 #0の個数
for i in range(n):
  if s[i] == 1:
    x += 1
  else:
    y += 1
  if x > 0 and y > 0:
    if s[i] == 0:
      a.append(x)
      x = 0
    else:
      a.append(-y)
      y = 0
if x > y:
  a.append(x)
else:
  a.append(-y)

m = len(a)
ans = 0
for i in range(m):
  x = 0
  flag = 0
  for j in range(m - i):
    if flag < k:
      if a[i+j] > 0:
        x += a[i+j]
      else:
        x += -a[i+j]
        flag += 1
    if flag == k and a[i+j] >0:
      x += a[i+j]
      flag += 1
  if ans < x:
    ans = x
print(ans)

### FIXED CODE ###

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

a = []
x = 0 #1の個数
y = 0 #0の個数
if s[0] == 0:
  a.append(0)
for i in range(n):
  if s[i] == 1:
    x += 1
  else:
    y += 1
  if x > 0 and y > 0:
    if s[i] == 0:
      a.append(x)
      x = 0
    else:
      a.append(y)
      y = 0
if x > y:
  a.append(x)
else:
  a.append(y)
  a.append(0)


m = len(a)
left=[0]*(m+1)
right=[0]*(m+1)

for i in range(m):
  left[i+1] = left[i] + a[i]
for i in range(m):
  right[m-i-1] = right[m-i] + a[m-i-1]

ans = 0
if m%2 == 0:
  r = int(m/2) + 1
else:
  r = int((m+1)/2) 
#print(r,a,right,left)
for i in range(r):
  if 2*i+2*k+1 <= m:
    x = left[2*i+2*k+1]-left[2*i]
  else:
    x = left[-1] - left[2*i]
  if ans < x:
    ans = x
print(ans)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
L=[0]*(10**5)
for i in A:L[i-1]+=i
for i in range(Q):
    B,C=map(int,input().split())
    L[C-1]+=(L[B-1]//B)*C;L[B-1]=0
    print(sum(L))

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
L=[0]*(10**5)
S=sum(A)
for i in A:L[i-1]+=1
for i in range(Q):
    B,C=map(int,input().split());B-=1;C-=1
    S+=((C+1)-(B+1))*L[B]
    L[C]+=L[B];L[B]=0
    print(S)
### BUGGY CODE ###

from collections import deque
import sys
import copy

def main():
  input = sys.stdin.readline
  n = int(input())
  a = [None]*n
  for i in range(n):
    a[i] = [int(x)-1 for x in input().split()]
  
  count = 0
  ans = 0
  bef_checked = [int(x) for x in range(n)]
  index = [0]*n
  while True:
    ans += 1
    check = copy.deepcopy(bef_checked)
    bef_checked = []
    already = set()
    flag = True
    for v in check:
      if v in already:
        continue
      flag = False
      v2 = a[v][index[v]]
      if v2 in already:
        continue
      if v != a[v2][index[v2]]:
        continue
      already = already|{v, v2}
      index[v] += 1
      index[v2] += 1
      if index[v] == n-1:
        count += 1
      else:
        bef_checked.append(v)
      if index[v2] == n-1:
        count += 1
      else:
        bef_checked.append(v2)
        
    if flag:
      print(-1)
      sys.exit()
    if count == n:
      break
  
  print(ans)
  

if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
from copy import deepcopy as copy

def main():
    input = sys.stdin.readline
    n = int(input())
    a = [None]*n
    for i in range(n):
        a[i] = [int(x)-1 for x in input().split()]
    
    index = [0]*n
    search = [int(x) for x in range(n)]
    ans = 0
    while True:
        already = set()
        judge = True
        sub = []
        for key in search:
            if index[key] == n-1:
                continue
            key2 = a[key][index[key]]
            if index[key2] == n-1:
                continue
            if key != a[key2][index[key2]]:
                continue
            if key in already or key2 in already:
                continue
            already.add(key)
            already.add(key2)
            index[key] += 1
            index[key2] += 1
            sub.append(key)
            sub.append(key2)
            judge = False
        if judge:
            break
        ans += 1
        search = copy(sub)
        
    for value in index:
        if value != n-1:
            print(-1)
            sys.exit()
    print(ans)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

s = input()
ans = 0
mod = []
t = s[len(s)-1]
for i in range(len(s)-1,-1,-1):
#     mod.append(int(s[i:])%2019)
    mod.append(int(t)%2019)
#     t = int(t) + (10**(len(s)-i-1))*int(s[i])
    t = int(t) + 10**(len(s)-i)*int(s[i-1])
for i in range(1,2019):
    ans += mod.count(i)*(mod.count(i)-1)/2
ans += mod.count(0)
print(int(ans))

### FIXED CODE ###

s = input()
ans = 0
mod = [0]*2019
t = s[len(s)-1]
n = 1
for i in range(len(s)-1,-1,-1):
#     mod.append(int(s[i:])%2019)
    mod[int(t)%2019] += 1
#     t = int(t) + (10**(len(s)-i-1))*int(s[i])
    t = int(t) + n*10*int(s[i-1])
    n = n*10%2019
for i in range(0,2019):
    ans += mod[i]*(mod[i]-1)/2
ans += mod[0]
print(int(ans))
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
if K <41:
    for q in range(K):
        foo = [1 for k in range(N)]
        for k in range(N):
            for j in range(1, min(A[k]+1, N-k)):
                foo[k+j] +=1
            for j in range(1, min(A[k]+1, k+1)):
                foo[k-j] +=1
        #print(foo)

        for k in range(N):
            A[k] = foo[k]
        #print(A)
else:
    for k in range(N):
        A[k] = N
ans = ""

for k in range(len(A)):
    ans += str(A[k]) + " "
print(ans.rstrip())

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
foo = [[0 for k in range(N)] for k in range(42)]
for k in range(len(A)):
    foo[0][k] = A[k]
if K <42:
    for q in range(K):
        unko = [0 for k in range(N)]
        for k in range(N):
            if k + foo[q][k]+1 < N:
                unko[k + foo[q][k]+1] -=1
            unko[max(k - foo[q][k], 0)] +=1
        unchi = 0
        for k in range(N):
            unchi += unko[k]
            foo[q+1][k] = unchi
        #print(unko)
        #print(foo[q+1])
        count =0
        for l in range(N):
            if foo[q+1][l] < N:
                break
            else:
                count +=1
        
        if count == N:
            break
        
                        
        #print(foo)
    print(" ".join(map(str, foo[q+1])))

     
else:
    print((str(N)+" ")*(N-1)+str(N))
### BUGGY CODE ###

from sys import exit
n, m = map(int, input().split())
s = input()

if n <= m:
    print(n)
    exit()

one_sequence = 0
for i in range(1, n):
    if s[i] == "1":
        one_sequence += 1
        if one_sequence == m:
            print(-1)
            exit()
    else:
        one_sequence = 0

pos = n
ans = ""
while pos > -1:
    for i in range(1, m+1)[::-1]:
        if pos-i < 0:
            continue
        if s[pos-i] != "1":
            ans = str(i) + " " + ans
            pos -= i
            break
print(ans.strip())


### FIXED CODE ###

from sys import exit
n, m = map(int, input().split())
s = input()

one_sequence = 0
for i in range(1, n):
    if s[i] == "1":
        one_sequence += 1
        if one_sequence == m:
            print(-1)
            exit()
    else:
        one_sequence = 0

pos = n
ans = ""
while pos != 0:
    for i in range(1, m+1)[::-1]:
        if pos-i < 0:
            continue
        if s[pos-i] != "1":
            ans = str(i) + " " + ans
            pos -= i
            break
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
1000000

output:
400000
"""

import sys


def gcd(x, y):
    if x < y:
        x, y = y, x

    while y > 0:
        r = x % y
        x = y
        y = r

    return x


def phi(n):
    ans = 0

    for k in range(1, n + 1):
        if gcd(n, k) == 1:
            ans += 1

    return ans


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    n1 = int(_input[0])
    print(phi(n1))

### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
1000000

output:
400000
"""

import sys


def min_prime_factor(n):
    k = 2
    while True:
        if pow(k, 2) > n:
            return n
        if not n % k:
            return k
        k += 1


def phi(n):
    ans = n
    while True:
        p = min_prime_factor(n)
        if n == 1:
            break
        while not n % p:
            n //= p
        ans *= (1 - 1 / p)
    return int(ans)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    n1 = int(_input[0])
    print(phi(n1))
### BUGGY CODE ###

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

isPrime = [True for i in range(max(A, B)+1)]
isPrime[0] = False
isPrime[1] = False

for i in range(2, max(A, B) + 1):
    if isPrime[i]:
        for j in range(2*i, max(A, B)+1, i):
            isPrime[j] = False


print(sum(p for i, p in enumerate(isPrime) if i>0 and A%i==0 and B%i==0) + 1)


### FIXED CODE ###

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

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

num = gcd(A, B)

if num < 2:
    print(1)
    quit()

length = int(num ** 0.5) + 2
isPrime = [True for i in range(length)]
isPrime[2] = True
for i in range(2, length):
    if isPrime[i]:
        for j in range(2 * i, length, i):
            isPrime[j] = False

count = 1

cur = 2
while num != 1 and cur < length:
    if isPrime[cur] and num % cur == 0:
        while num % cur == 0:
            num //= cur
        count += 1
    cur += 1

print(count + (num != 1))
### BUGGY CODE ###

n = int(input())

ans = 0
for num in range(1, n+1):
    count = n // num
    last = count * num
    total = count * (num + last) // 2
    ans += total

print(ans)


### FIXED CODE ###

n = int(input())

ans = 0
for num in range(1, n+1):
    count = n // num
    last = count * num
    total = count * (num + last) // 2
    ans += total

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

n, k = map(int, input().split())
N = 10 ** 9 + 7

def kai(a):
    res = 1
    for i in range(1, a+1):
        res = res * i
    return res

def cmb(n, r):
    return kai(n) // kai(r) // kai(n-r)

for i in range(1, k + 1):
    # print(i)
    sao = i - 1
    sak = i
    nao = cmb(k - 1, sao)
    nak = cmb(n - k + 1,  sak)
    # print(nao, nak)
    print(nao * nak % N)


### FIXED CODE ###

n, k = map(int, input().split())
N = 10 ** 9 + 7

def kai(a):
    res = 1
    for i in range(1, a+1):
        res = res * i
    return res

def cmb(n, r):
    return kai(n) // kai(r) // kai(n-r)
#
# for i in range(1, k + 1):
#     nao = cmb(k - 1, i - 1)
#     nak = cmb(n - k + 1,  i)
#     print(nao * nak % N)

ans = 0
for i in range(1, k+1):
    if i == 1:
        ans = cmb(k - 1, i - 1) * cmb(n - k + 1,  i)
    print(ans  % N)
    ans = ans * (k - i) // i * (n - k - i + 1) // (i + 1)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

import sys
import os
import math


n, m = list(map(int, input().split()))
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

def sum_len(A):
    all = 0
    for i in range(len(A)):
        for j in range(i+1, len(A)):
            l = A[j] - A[i]
            all += l
    return all

a = 10**9 + 7
xl = sum_len(X)
yl = sum_len(Y)
print(xl * yl % a)

### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys
import os
import math


n, m = list(map(int, input().split()))
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

def sum_len(A):
    all_sum = 0
    previous_sum = 0
    for i in range(1, len(A)):
        now_sum = previous_sum + i * (A[i] - A[i-1])
        all_sum += now_sum
        previous_sum = now_sum
    return all_sum

a = 10**9 + 7
xl = sum_len(X)
yl = sum_len(Y)
#print(xl)
#print(yl)
print(xl * yl % a)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0099
"""
import sys
import bisect



def main(args):
    #data = [(1, 4), (2, 5), (1, 3), (3, 6), (2, 7)]
    #data = [(1, 4), (2, 5), (2, -3),(3, 4), (1, -1)]
    fisher, event = [int(x) for x in input().split(' ')]
    fishes = [0 for _ in range(fisher + 1)]

    for _ in range(event):
        id, fish = [int(x) for x in input().strip().split(' ')]
        fishes[id] += fish
        max_fish = max(fishes)
        winner = fishes.index(max_fish)
        print('{} {}'.format(winner, max_fish))


if __name__ == '__main__':
    main(sys.argv[1:])

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0099
"""
import sys
import bisect



def main(args):
    #data = [(1, 4), (2, 5), (1, 3), (3, 6), (2, 7)]
    #data = [(1, 4), (2, 5), (2, -3),(3, 4), (1, -1)]
    fisher, event = [int(x) for x in input().split(' ')]
    fishes = [0 for _ in range(fisher + 1)]

    winner = 9999999999
    max_fish = -1
    for _ in range(event):
        id, fish = [int(x) for x in input().strip().split(' ')]
        fishes[id] += fish
        if fish > 0:
            if fishes[id] > max_fish:
                max_fish = fishes[id]
                winner = id
            elif fishes[id] == max_fish:
                winner = min(winner, id)
            else:
                pass
        else:
            if winner == id:
                max_fish = max(fishes)
                winner = fishes.index(max_fish)
        print('{} {}'.format(winner, max_fish))


if __name__ == '__main__':
    main(sys.argv[1:])
### BUGGY CODE ###

from itertools import accumulate
from itertools import combinations

N, K = [int(x) for x in input().strip().split(" ")]
As = [0] + [int(x) for x in input().strip().split(" ")]

aAs = list(accumulate(As))

keta = 41
d = [set() for _ in range(41)]

for i, j in combinations(range(N), 2):
    rr = aAs[j + 1] - aAs[i]
    rr = "{0:041d}".format(int(bin(rr)[2:]))
    for k in range(keta):
        if rr[k] == "1":
            d[k].add((i, j))

for i in range(N):
    j = i
    rr = As[i+1]
    rr = "{0:041d}".format(int(bin(rr)[2:]))
    for k in range(keta):
        if rr[k] == "1":
            d[k].add((i, j))

candidates = None
rr = 0
for i, ss in enumerate(d):
    if len(ss) < K:
        continue
    if candidates == None:
        candidates = ss
        rr += pow(2, 40-i)
    else:
        xx = ss & candidates
        if len(xx) < K:
            continue
        candidates = xx
        rr += pow(2, 40-i)
print(rr)


### FIXED CODE ###

N, K = map(int, input().split())
from itertools import accumulate
As = [0] + list(map(int, input().split()))
As = list(accumulate(As))
L = len(bin(As[-1]))-2
xs = []
for i in range(N+1):
    for j in range(i+1, N+1):
        xs.append(As[j] - As[i])
xs.sort()
ts = set(range(N*(N+1)//2))
for j in range(L-1,-1,-1):
    nts = set()
    for i in ts:
        if (xs[i]>>j)%2:
            nts.add(i)
    if len(nts) >= K:
        ts = nts
c = 0
r = 0
for i in ts:
    c += 1
    if r == 0:
        r = xs[i]
    else:
        r = r&xs[i]
    if c == K:
        break
print(r)
### BUGGY CODE ###

from collections import deque
S=deque(input())
q=int(input())
for i in range(q):
  c=list(input().split())
  if c[0]=='1':
    S.reverse()
  elif c[1]=='1':
    S.appendleft(c[2])
  else :
    S.append(c[2])
ans=''.join(S)
print(ans)

### FIXED CODE ###

from collections import deque
S=deque(input())
q=int(input())
rev=False
for i in range(q):
  c=list(input().split())
  if c[0]=='1':
    rev=not rev
  elif c[1]=='1' and rev==False:
    S.appendleft(c[2])
  elif c[1]=='2' and rev==True:
    S.appendleft(c[2])
  else:
    S.append(c[2])
if rev:
  S.reverse()
ans=''.join(S)
print(ans)
### BUGGY CODE ###

n, m, *a = map(int, open(0).read().split())
a = sorted(a, reverse=True)

for i in range (0,m):
  a[0] = a[0]//2
  a = sorted(a, reverse=True)
  if a[0] == 0:
    break

print(sum(a))

### FIXED CODE ###

n, m, *a = map(int, open(0).read().split())

a.sort(reverse=True)

if n == 1:
  for i in range (0,m):
    a[0] = a[0]//2
    if a[0] == 0:
      break
else:
  a.append(0)
  biggest = a[0]
  now = 0
  while m > 0:
    a[now] = a[now]//2
    m = m - 1
    biggest = a[0]
    for i in range (n-1):
      if a [i+1] >= biggest and m>0:
        a[i+1] = a[i+1]//2
        m = m -1
      else:
        a.sort(reverse = True)
        break

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

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

for i in range(N):
    if a != []:
        ans += a[-2]
        a = a[1:-2]
print(ans)

### FIXED CODE ###

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

a.sort(reverse=True)
ans = 0
count = 0
for i in range(1, N*3+1, 2):
    if count == N:
        break
    else:
        ans += a[i]
        count += 1

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

n = int(input())
h_l = list(map(int,input().split()))
cnt = 0
cnt = sum([sum([1 for j in range(i,n) if((j-i)==(h_l[j]+h_l[i]))]) for i in range(n)])            

print(cnt)

### FIXED CODE ###

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

#Ai + i 
#j-Aj
ans = 0
cnt = [0]*(n+1)
for i in range(n-1):
    j=i+1
    a = mp[i]+i
    if(a<=n):
        cnt[a] += 1 
    b = j-mp[j]
    if(b<0):
        continue
    ans += cnt[b]
    

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

K,S = map(int,input().split())
count = 0
for x in range(0,K+1):
  for y in range(0,K+1):
    for z in range(0,K+1):
      if(x + y + z == S):
        count += 1
print(str(count))

### FIXED CODE ###

K,S = map(int,input().split())
count = 0
for x in range(0,K+1):
  for y in range(0,K+1):
    if (S - (x + y) <= K and S - (x + y) >= 0):
      count += 1
print(str(count))
### BUGGY CODE ###

import sys
N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for i in range(N)]
for i in range(N):
    A2 = A.copy()
    A2[i] = 0
    print(max(A2))

### FIXED CODE ###

import sys
def main():
    N = int(sys.stdin.readline())
    A = [int(sys.stdin.readline()) for i in range(N)]
    maxa = max(A)
    maxb = sorted(A)[-2]
    if A.count(maxa) > 1:
        for i in range(N):
            print(maxa)
    else:
        for i in range(N):
            if A[i] != maxa:
                print(maxa)
            else:
                print(maxb)
                
main()
### BUGGY CODE ###

n,w = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
#l[i][0]が重さ、l[i][1]が価値
#print(n,w,l)

ans = [[0]*(w+1) for i in range(n)]
#print(ans)

for i in range(n):
  for j in range(0,w+1):
    if i == 0 and j >= l[0][0]:
      ans[0][j] = l[0][1]
    elif i > 0:
      new_w = j + l[i][0]
      if new_w <= w:
        ans[i][new_w] = max(ans[i-1][new_w], ans[i-1][j] + l[i][1])
    if ans[i][j] < ans[i-1][j]:
      ans[i][j] = ans[i-1][j]
        
#print(ans)
print(ans[n-1][w])

### FIXED CODE ###

n,w = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
#l[i][0]が重さ、l[i][1]が価値
#print(n,w,l)

ans = [[0]*(w+1) for i in range(n)]
#print(ans)

for i in range(n):
  for j in range(0,w+1):
    if i == 0 and j >= l[0][0]:
      ans[0][j] = l[0][1]
    elif i > 0:
      new_w = j + l[i][0]
      if new_w <= w:
        ans[i][new_w] = max(ans[i-1][new_w], ans[i-1][j] + l[i][1])
    if ans[i][j] < ans[i-1][j]:
      ans[i][j] = ans[i-1][j]
        
#print(ans)
print(ans[n-1][w])