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

import math
Q = int(input())

l = []
r = []
while True:
  try:
    lr=list(map(int,input().split()))
    l.append(lr[0])
    r.append(lr[1])
  except:
    break

def is_prime(num):
  if(type(num) != type(0)):
    print('error at '+str(num)+' type = '+str(type(num)))
    print(type(int))
    return 0
  if(num<2):
    return 0
  elif(num == 2):
    return 1
  n = math.ceil(math.sqrt(num))
  for i in range(2,n+1):
    if((num%i) == 0):
      return 0
  return 1

def create_list():
  MAXI = max(r)+1
  
  prime = [1 for i in range(MAXI)]
  prime[0] = 0
  prime[1] = 0
  for i in range(2,MAXI):
    if(prime[i] == 0):
      continue
    else:
      prime[i] = is_prime(i)
      if(prime[i] == 0):
        for j in range(i,MAXI,i*2):
          prime[j] = 0
  sn = [0]
  for i in range(1,MAXI+1,2):
    sn.append(prime[i] * prime[int((i+1)/2)]) #odd
    sn.append(0) #even
  return sn

base = create_list()
for i in range(Q):
  if(l[i]==r[i]):
    print(base[l[i]])
  else:
    lnum = base[0:l[i]]
    rnum = base[0:r[i]]
    print( sum(rnum)-sum(lnum) )

### FIXED CODE ###

import math
import sys
sys.setrecursionlimit(10 ** 5 + 10)

Q = int(input())

l = [0 for _ in range(Q)]
r = [0 for _ in range(Q)]
i = 0
while True:
  try:
    lr=list(map(int,input().split()))
    l[i] = lr[0]
    r[i] = lr[1]
    i+=1
  except:
    break

def is_prime(num):
  #if(type(num) != type(0)):
  #  print('error at '+str(num)+' type = '+str(type(num)))
  #  print(type(int))
  #  return 0
  #if(num<2):
  #  return 0
  if(num == 2):
    return 1
  n = math.ceil(math.sqrt(num))
  for i in range(2,n+1):
    if((num%i) == 0):
      return 0
  return 1

def create_list():
  MAXI = max(r)+1
  
  prime = [1 for _ in range(MAXI+1)]
  prime[0] = 0
  prime[1] = 0
  for i in range(2,MAXI):
    if(prime[i] == 0):
      continue
    else:
      prime[i] = is_prime(i)
      for j in range(i*2,MAXI,i*2):
        prime[j] = 0
      for j in range(i*5,MAXI,i*3):
        prime[j] = 0
      for j in range(i*5,MAXI,i*5):
        prime[j] = 0
  #print(prime)
  sn = [0 for _ in range(MAXI+2)]
  for i in range(1,MAXI+1,2):
    #print('int(('+str(i+1)+')/2) = '+str(int((i+1)/2))+' when '+str(prime[int((i+1)/2)]))
    sn[i] += sn[i-1] + (prime[i] * prime[int((i+1)/2)]) #odd
    sn[i+1] = sn[i]
  return sn

base = create_list()
#print(base)
for i in range(Q):
  print( base[r[i]] - base[l[i]-1] )#sum(rnum)-sum(lnum) )
### BUGGY CODE ###

k = int(input())
s = input()
p = 1000000007
x = 0
inv = [0, 1]
fact = [1, 1]
factinv = [1, 1]
for i in range(2, k+len(s)+1):
    inv.append(-inv[p%i]*(p//i)%p)
    fact.append(fact[-1]*i%p)
    factinv.append(factinv[-1]*inv[-1]%p)
def cmb(n, r, p):
    return fact[n]*factinv[r]*factinv[n-r]%p
a = [1]
b = [1]
for _ in range(k):
    a.append(a[-1]*25%p)
    b.append(b[-1]*26%p)
for i in range(k+1):
    x = (x+a[i]*b[k-i]*cmb(i+len(s)-1, i, p))%p
print(x)

### FIXED CODE ###

k = int(input())
s = input()
p = 1000000007
x = 0
inv = [0, 1]
fact = [1, 1]
factinv = [1, 1]
for i in range(2, k+len(s)+1):
    inv.append(-inv[p%i]*(p//i)%p)
    fact.append(fact[-1]*i%p)
    factinv.append(factinv[-1]*inv[-1]%p)
def cmb(n, r, p):
    return fact[n]*factinv[r]*factinv[n-r]%p
a = [1]
b = [1]
for _ in range(k):
    a.append(a[-1]*25%p)
    b.append(b[-1]*26%p)
for i in range(k+1):
    x = (x+a[i]*b[k-i]*cmb(i+len(s)-1, i, p))%p
print(x)
### BUGGY CODE ###

n=int(input())
a=list(map(int, input().split()))
ans =1
for i in a:
    ans *= i
if ans > 10**18:
    print(-1)
    exit()    
print(ans)


### FIXED CODE ###

n=int(input())
a=list(map(int, input().split()))
ans = 1
if a.count(0)>0:
    print(0)
    exit()
for i in range(n):
    l = len(str(ans))
    L = len(str(a[i]))
    if a[i] > 10**18:
        print(-1)
        exit()
    elif l+L > 20:
        print(-1)
        exit()
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)
### BUGGY CODE ###

H,W = map(int,input().split())
G=[input() for _ in range(H)]
A_u=[[0 for _ in range(W)] for _ in range(H)]
A_d=[[0 for _ in range(W)] for _ in range(H)]
A_r=[[0 for _ in range(W)] for _ in range(H)]
A_l=[[0 for _ in range(W)] for _ in range(H)]
for h in range(H):
  for w in range(1,W):
    if G[h][w-1] == '.':
      A_r[h][w] = A_r[h][w-1]+1
  for w in range(W-2,-1,-1):
    if G[h][w+1] == '.':
      A_l[h][w] = A_l[h][w+1]+1
for w in range(W):
  for h in range(1,H):
    if G[h-1][w] == '.':
      A_d[h][w] = A_d[h-1][w]+1
  for h in range(H-2,-1,-1):
    if G[h+1][w] == '.':
      A_u[h][w] = A_u[h+1][w]+1
ans=0
for h in range(H):
  for w in range(W):
    if G[h][w] == '.':
      ans = max(ans,A_r[h][w]+A_l[h][w]+A_d[h][w]+A_u[h][w]+1)
print(ans)

### FIXED CODE ###

H,W = map(int,input().split())
G=[input() for _ in range(H)]
A_u=[[0 for _ in range(W)] for _ in range(H)]
A_d=[[0 for _ in range(W)] for _ in range(H)]
A_r=[[0 for _ in range(W)] for _ in range(H)]
A_l=[[0 for _ in range(W)] for _ in range(H)]
for h in range(H):
  for w in range(1,W):
    if G[h][w-1] == '.':
      A_r[h][w] = A_r[h][w-1]+1
  for w in range(W-2,-1,-1):
    if G[h][w+1] == '.':
      A_l[h][w] = A_l[h][w+1]+1
for w in range(W):
  for h in range(1,H):
    if G[h-1][w] == '.':
      A_d[h][w] = A_d[h-1][w]+1
  for h in range(H-2,-1,-1):
    if G[h+1][w] == '.':
      A_u[h][w] = A_u[h+1][w]+1
ans=0
for h in range(H):
  for w in range(W):
    if G[h][w] == '.':
      ans = max(ans,A_r[h][w]+A_l[h][w]+A_d[h][w]+A_u[h][w]+1)
print(ans)
### BUGGY CODE ###

# 試合を頂点とした有向グラフを書く
# 対戦2チームを元に試合ID(頂点番号)に変換できるようにする
# 閉路があるとNGなので-1
# 閉路がない場合は最長経路が答え

import sys
readline = sys.stdin.readline

N = int(readline())

to_id = [[-1] * N for i in range(N)]
next_id = 0
def convert_to_id(a,b,next_id):
  if to_id[a][b] == -1:
    to_id[a][b] = next_id
    to_id[b][a] = next_id
    return next_id + 1
  return next_id

G = [[] for i in range((N * (N - 1)) // 2)] # 試合グラフ
indegree = [0 for i in range((N * (N - 1)) // 2)] # 入次数
for i in range(N):
  A = list(map(int,readline().split()))
  cur = None
  for a in A:
    # i と a - 1の試合
    next_id = convert_to_id(i,a - 1,next_id)
    game = to_id[i][a - 1]
    if cur != None:
      G[cur].append(game)
      indegree[game] += 1 # 試合に対する入次数が1
    cur = game

done = set()
# 各日付ごとに、入次数が0の試合から行っていく
# 入次数が0になった試合を翌日の試合リスト
stack = []
for i in range(len(indegree)):
  if indegree[i] == 0:
    stack.append(i)

if len(stack) == 0:
  print(-1)
  exit(0)
  
day = 0
while stack:
  day += 1
  nextday = []
  while stack:
    game = stack.pop()
    if game in done: # 既に終わっている試合の場合　閉路と見なす
      print(-1)
      exit(0)
    done.add(game)
    for child in G[game]: # 翌日のゲームを探索
      indegree[child] -= 1
      if indegree[child] == 0: # 入次数が0になれば翌日試合できる
        nextday.append(child)
  stack = nextday

if len(done) != ((N * (N - 1)) // 2):
  print(-1)
  exit(0)
print(day)

### FIXED CODE ###

N=int(input())
a=[[0 for j in range(N-1)] for i in range(N)]
for i in range(N):
  line=list(map(int,input().split()))
  for j in range(N-1):
    a[i][j]=line[j]-1
  a[i]=a[i][::-1]
    
q=[]

#seen=[[False for j in range(N)] for i in range(N)]

# 選手nが試合できるならqueに入れる
def check(i):
  if len(a[i])==0:
    return False
  j=a[i][-1]
  if a[j][-1]==i:
    q.append([i,j])
  
for i in range(N):
  check(i)
  
from collections import defaultdict

day=0
while q:
  day+=1
 # q=sorted(q)
  prevQ=q.copy()
  q=[]
  matched=defaultdict(list)
  for p in prevQ:
    i=p[0]
    j=p[1]
    if i>j:
      i,j=j,i
    if matched[i]:
      continue
    a[i].pop()
    a[j].pop()
    check(i)
    check(j)
    matched[i].append(j)
    
for i in range(N):
  if len(a[i])!=0:
    print(-1)
    break
else:
  print(day)
### BUGGY CODE ###

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

Nmax = N
for i in range(N):
    if min(P[:i + 1]) < P[i]:
        Nmax += -1

print(Nmax)



### FIXED CODE ###

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

Nmax = N
Nmin = P[0]

for i in range(N):
    if P[i] <= Nmin:
        Nmin = P[i]
    else:
        Nmax += -1


print(Nmax)
### BUGGY CODE ###

n=int(input())
s=input()
dict={}
dict["R"]=[]
dict["G"]=[]
dict["B"]=[]
res=set()
for i in range(n):
  if s[i]=="R":
    dict["R"].append(i)
  elif s[i]=="G":
    dict["G"].append(i)
  elif s[i]=="B":
    dict["B"].append(i)
  else:
    raise Exception
#dict["R"]=sorted(dict["R"])
#dict["G"]=sorted(dict["G"])
#dict["B"]=sorted(dict["B"])
#print(dict["B"])
for r in dict["R"]:
  for g in dict["G"]:
      for b in dict["B"]:
        tup=tuple(sorted((r,g,b)))
        if 2*tup[1]!=tup[0]+tup[2]:
            res.add(tup)             
print(len(res))

### FIXED CODE ###

n=int(input())
s=input()
dict={}
dict["R"]=[]
dict["G"]=[]
dict["B"]=[]
for i in range(n):
  if s[i]=="R":
    dict["R"].append(i)
  elif s[i]=="G":
    dict["G"].append(i)
  elif s[i]=="B":
    dict["B"].append(i)
  else:
    raise Exception
res=len(dict["R"])*len(dict["G"])*len(dict["B"])
for r in dict["R"]:
  for g in dict["G"]:
      if (r+g)%2==0:
        if s[(r+g)//2]=="B":
          res-=1
      try:
        if s[2*r-g]=="B" and 2*r-g>=0:
          	res-=1
      except:pass
      try:
        if s[2*g-r]=="B" and 2*g-r>=0:
          res-=1
      except:pass      
      
print(res)
### BUGGY CODE ###

S = input()
Q = int(input())

for i in range(Q):
    q = input()
    if q[0] == "1":
        S = S[::-1]
    elif q[0] == "2":
        if q[2] == "1":
            S = q[4] + S
        elif q[2] == "2":
            S = S + q[4]

print(S)

### FIXED CODE ###

S = input()
Q = int(input())

head = ''
back = ''
direction = 1

for i in range(Q):
    q = list(map(str, input().split())) 
    if q[0] == "1":
        direction *= (-1)
        #S = S[::-1]
    else:
        if q[1] == "1":
            if direction == 1:
                head = head + q[2]
            else:
                back = back + q[2]
        else:
            if direction == 1:
                back = back + q[2]
            else:
                head = head + q[2]

if direction == 1:
    print(head[::-1]+S+back)
else:
    print(back[::-1]+S[::-1]+head)
### BUGGY CODE ###

n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
sum = 0
for i in range(len(l)):
    for j in range(i + 1, len(l)):
        for k in range(j + 1, len(l)):
            if l[k] < l[i] + l[j]:
                sum += 1
            else:
                break
print(sum)

### FIXED CODE ###

import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(len(l)):
    for j in range(i + 1, len(l)):
        ans += max(bisect.bisect_left(l, l[i] + l[j])-j-1, 0)
print(ans)
### BUGGY CODE ###

import math

MAX=10**6+3
table = list(range(MAX))
i=2
n=MAX
while i<=n:
    table[i] = 2
    i+=2

p=3
while p*p<=n:
    if table[p]<p:
        continue
    x=p
    while x<=n:
        table[x]=p
        x+=p
    p+=2

def primeFactorSet(n):
    result = set()
    while table[n]!=1:
        result.add(table[n])
        n //= table[n]
    return result
    

n = int(input())
A = list(map(int,input().split()))
pairwise = True
flags = [False for _ in range(MAX)]

for i in range(n):
    a=A[i]
    if pairwise:
        t = primeFactorSet(a)
        for p in t:
            if flags[p]:
                pairwise = False
                break
            flags[p]=True
    if i==0:
        g=a
    else:
        g=math.gcd(g,a)
    
if g>1:
    print("not coprime")
elif pairwise:
    print("pairwise coprime")
else:
    print("setwise coprime")


### FIXED CODE ###

import math

MAX=10**6+3
table = list(range(MAX))
i=2
n=MAX
while i<n:
    table[i] = 2
    i+=2
p=3
while p*p<=n:
    if table[p]<p:
        p+=2
        continue
    x=p
    while x<=n:
        table[x]=p
        x+=p
    p+=2


def primeFactorSet(n):
    result = set()
    while table[n]!=1:
        result.add(table[n])
        n //= table[n]
    return result
    

n = int(input())
A = list(map(int,input().split()))
pairwise = True
flags = [False for _ in range(MAX)]

for i in range(n):
    a=A[i]
    if pairwise:
        t = primeFactorSet(a)
        for p in t:
            if flags[p]:
                pairwise = False
                break
            flags[p]=True
    if i==0:
        g=a
    else:
        g=math.gcd(g,a)
    
if g>1:
    print("not coprime")
elif pairwise:
    print("pairwise coprime")
else:
    print("setwise coprime")
### BUGGY CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
b = [0]
for i in range(len(s)):
    b.append(int(s[i:])%2019)

import collections

c = collections.Counter(b)
ans = 0

for j in c.values():
    if j > 1:
        ans += j*(j-1)//2

print(ans)

### FIXED CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

from collections import defaultdict

s = ns()
d = defaultdict(int)
d[0] += 1
k = 1
n = 0
for i in range(len(s))[::-1]:
    n += int(s[i])*k%2019
    n%=2019
    d[n] += 1
    k = (k*10)%2019

ans = 0

for j in d.values():
    if j > 1:
        ans += j*(j-1)//2

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

L,R = map( int,input().split() )
ans = ( L * (L+1) ) % 2019  
for i in range(L,R):
    if ans == 0:
        break
    for j in range(i+1, R+1):
        ans = min( ( i * j ) %2019,ans)
print(ans)

### FIXED CODE ###

import math
L,R = map( int,input().split() )
ans = ( L * (L+1) ) % 2019  
for i in range(L,R):
    if ans == 0:
        break
    j = i + 1
    a = ( i * j ) % 2019
    ans = min(a, ans)
    plus = i % 2019
    while(True):
        over = math.ceil( ( 2019 - a ) / plus )
        j = j + over
        if j > R:
            break
        a = ( i * j) % 2019
        ans = min(a,ans)
        if ans == 0:
            break
print(ans)
### BUGGY CODE ###

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

h = list(h)

if k >= len(h):
  print("0")
else:
  for i in range(0, len(h)):
      h[i] = int(h[i])
      
  for i in range(0, k):
    h.remove(max(h))
  print(sum(h))
  

### FIXED CODE ###

N, K = map(int, input().lower().split())
H = []
total = 0
input_string = input()
H = input_string.split()
H = list(map(int, H))

H.sort(reverse = True)
del H[0:K]

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

A,B,K=map(int,input().split())
for i in range(A,B+1):
    if i<A+K or i>B-K:
        print(i)
    else:
        continue


### FIXED CODE ###

A,B,K=map(int,input().split())
ans=[]
for i in range(A,A+K):
    if A<=i<=B:
        ans.append(i)
    else:
        break
for t in range(B-K+1,B+1):
    if A<=t<=B: 
        ans.append(t)
    else:
        break
for z in sorted(set(ans)):
    print(z)
### BUGGY CODE ###

n = int(input())
a = [int(x) for x in input().split()]
ans = []
for i in range(n):
    ans.append(a[i])
    ans.reverse()
print(*ans)

### FIXED CODE ###

n = int(input())
a = [int(x) for x in input().split()]
ans = []
if n == 1: print(a[0])
else:
    for i in a[::-2]:
        ans.append(i)
    if n % 2 == 0:
        for i in a[::2]:
            ans.append(i)
    else:
        for i in a[1::2]:
            ans.append(i)
print(*ans)
### BUGGY CODE ###

class ZAlgorithm(object):
    def __init__(self, s: str):
        self.lcp = self.__create_z(s)

    def __call__(self, i: int):
        return self.lcp[i]

    def __create_z(self, s: str):
        n = len(s)
        lcp = [n] + [0]*(n-1)
        l, r = 0, 0

        for t in range(1, n):
            if t>r:
                z = 0
                while t+z<n and s[0+z]==s[t+z]:
                    z += 1
                lcp[t] = z
                if z>0:
                    l, r = t, t+z-1
            else:
                p, b = t-l, r-t+1
                if lcp[p]<b:
                    lcp[t] = lcp[p]
                else:
                    i = r+1
                    while i<n and s[i]==s[i-t]:
                        i += 1
                    lcp[t] = i-t
                    l, r = t, i-1
        return lcp

def main():
    n, s = open(0).read().split()
    a = 0
    for i in range(int(n)-1):
        ss = s[i:]
        z_algo = ZAlgorithm(ss)
        for j in range(len(ss)):
            a = max(a, min(z_algo(j), j))
    print(a)

if __name__ == "__main__":
    main()


### FIXED CODE ###

def f_e_dp():
    n = int(input())
    s = input()
    dp = [[0]*(n+1) for _ in range(n+1)]
    for i in reversed(range(n)):
        for j in reversed(range(n)):
            if s[i]==s[j] and i<j:
                dp[i][j] = dp[i+1][j+1]+1
    a = 0
    for i in range(n):
        for j in range(n):
            if i<j:
                a = max(a, min(j-i, dp[i][j]))
    print(a)

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

def func(x,y):
    return min(x,y)

class SegmentTree:
    def __init__(self, n): #a1, a2, ..., an
        n_ = 1
        while n_ < n:
            n_ *= 2

        self.n = n_
        self.arr = [10**18] * (2*self.n-1)

    def update(self, k, a): #0_indexed
        k += self.n - 1
        self.arr[k] = a

        while k > 0:
            k = (k-1) // 2
            self.arr[k] = min(self.arr[2*k+1], self.arr[2*k+2])

    def query(self, l, r):
        L, R = l+self.n, r+self.n
        ide_ele = float("inf")
        #単位元(ide_ele)は、区間外の値などに設定する値です。
         #ex) 最小値のセグ木 → +inf
         #　和のセグ木 → 0
         #　積のセグ木 → 1
         #  gcdのセグ木 → 0
        res = ide_ele
        while L < R:
            if R & 1:
                R -= 1
                res = func(res, self.arr[R-1]) #

            if L & 1:
                res = func(res, self.arr[L-1])
                L += 1

            L >>= 1
            R >>= 1

        return res
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
lrc=[tuple(map(int,input().split())) for _ in range(m)]
dp=SegmentTree(n+1)
dp.update(1,0)

rl=[[] for _ in range(n+1)]
rc=[[] for _ in range(n+1)]
for l,r,c in lrc:
    rl[r].append(l)
    rc[r].append(c)

for r in range(2,n+1):
    x=float("inf")
    for l,c in zip(rl[r],rc[r]):
        y=dp.query(l,r)+c
        if x>y:
            x=y
    dp.update(r,x)
    if r==n:
        ans=x

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


### FIXED CODE ###


from collections import defaultdict
from heapq import heappop, heappush


class Graph():

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra():

    def __init__(self, graph, start):
        self.g = graph.graph

        self.dist = defaultdict(lambda: float("inf"))
        self.dist[start] = 0

        self.prev = defaultdict(lambda: None)

        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            dist_u, u = heappop(self.Q)

            if self.dist[u] < dist_u:
                continue

            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):

        return self.dist[goal]

    def shortest_path(self, goal):
        path = []
        node = goal

        while node is not None:
            path.append(node)
            node = self.prev[node]

        return path[::-1]


import sys
input=sys.stdin.readline
n,m=map(int,input().split())
g=Graph()

for _ in range(m):
    l,r,c=map(int,input().split())
    g.add_edge(l,r,c)
for i in range(2,n+1):
    g.add_edge(i,i-1,0)


d = Dijkstra(g,1)
ans=d.shortest_distance(n)
print(ans if ans!=float("inf") else -1)
### BUGGY CODE ###

#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import sys

EMPTY = (0, 0, frozenset())


def solve(values, _nb, max_capacity):
    dp = [0] * (max_capacity + 1)
    for w, v in values:
        # dp = dp[:w] + [max(dp[j], dp[j - w] + v) for j in range(w, max_capacity + 1)]
        dp = dp[:w] + [
            max(dpj, dpjw + v)
            for dpj, dpjw in zip(dp[w:], dp[: (max_capacity + 1 - w)])
        ]
    return dp[max_capacity]


def solve_slow(values, nb, max_capacity):
    dp = [[0 for _ in range(max_capacity + 1)] for _ in range(nb + 1)]
    for i in range(1, nb + 1):
        w, v = values[i - 1]
        for j in range(1, max_capacity + 1):
            if w <= j:
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v)
            else:
                dp[i][j] = dp[i - 1][j]
    # print("\n".join(map(str, dp)))
    return dp[nb][max_capacity]


def do_job():
    "Do the work"
    # first line is number of test cases
    N, W = map(int, input().split())
    values = []
    for _ in range(N):
        values.append(list(map(int, input().split())))
    result = solve(values, N, W)
    print(result)


def print_output(testcase, result) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case #{}: {}".format(testcase + 1, result))


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


### FIXED CODE ###

# DP
def main():
    N, W = map(int, input().split())

    dp = [-1] * (W + 1)
    dp[0] = 0
    for _ in range(N):
        w, v = map(int, input().split())
        for i in range(W - w, -1, -1):
            if dp[i] == -1:
                continue
            if dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v
    print(max(dp))


main()
### BUGGY CODE ###

import numpy as np
goukei = 0

N = int(input()) * (-1)
Ai = list(map(int, input().split()))
array_Ai = np.array(Ai)
for i in range(len(Ai)):
    number = np.array([j + i for j in range(0, N, -1)])
    new_ai = number + array_Ai
    goukei += np.count_nonzero(new_ai == -Ai[i])
print(goukei)

### FIXED CODE ###

import collections
goukei = 0

N = int(input())
Ai = list(map(int, input().split()))
number = [j for j in range(1, N+1, 1)]
plus_Ai = [x + y for (x, y) in zip(Ai, number)]
minus_Ai = [x - y for (y, x) in zip(Ai, number)]
c = collections.Counter(plus_Ai)

for i in minus_Ai:
    goukei += c[i]
print(goukei)
### BUGGY CODE ###

import random
def score(D,c,s,t):
    v=list()
    last=[0]*26
    legacy=0
    for i in range(D):
        minus=0
        v.append(legacy)
        v[i]+=s[i][t[i]-1]
        last[t[i]-1]=i+1
        for j in range(26):
            minus+=c[j]*(i+1-last[j])
        v[i]-=minus
        legacy=v[i]
    return v[D-1]
s=list()
t=list()
D=int(input())
c=list(map(int,input().split()))
for i in range(D):
    s.append(list(map(int,input().split())))
for i in range(D):
    t.append(1)
    max=score(i+1,c,s,t)
    best=1
    randomlist=random.sample(range(2,26), k=13)
    for j in randomlist:
        t[i]=j+1
        tensuu=score(i+1,c,s,t)
        if max<tensuu:
            best=j+1
            max=tensuu
    t[i]=best
for i in range(D):
    print(t[i])

### FIXED CODE ###

import random
def score(D,c,s,t):
    v=list()
    last=[0]*26
    legacy=0
    for i in range(D):
        minus=0
        v.append(legacy)
        v[i]+=s[i][t[i]-1]
        last[t[i]-1]=i+1
        for j in range(26):
            minus+=c[j]*(i+1-last[j])
        v[i]-=minus
        legacy=v[i]
    return v[D-1]
s=list()
t=list()
D=int(input())
c=list(map(int,input().split()))
for i in range(D):
    s.append(list(map(int,input().split())))
t=[random.randint(1,26)]*D
for i in range(100):
    d=random.randint(1,D)
    q=random.randint(1,26)
    old=t[d-1]
    oldscore=score(D,c,s,t)
    t[d-1]=q
    if score(D,c,s,t)<oldscore:
        t[d-1]=old
for i in range(D):
    print(t[i])