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

n = int(input())
a_ls = list(map(int, input().split()))
a_ls.sort(reverse=True)
ans = 0
for i in range(n):
    not_divisible = True
    for j in range(i+1,n):
        if a_ls[i] % a_ls[j] == 0 or a_ls[i] == a_ls[j]:
            not_divisible = False
            break
    if i > 0 and a_ls[i-1] == a_ls[i]:
        not_divisible = False
    if not_divisible:
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
a_ls = list(map(int, input().split()))
a_ls.sort()
a_max = a_ls[-1]
times_ls = [0] * (a_max + 1)
divisible_ls = [0] * (a_max + 1)
for i in range(n):
    base = a_ls[i]
    times_ls[base] += 1
    times = 2
    while base*times <= a_max:
        divisible_ls[base*times] = 1
        times += 1
ans = 0
for i in range(1,a_max+1):
    if times_ls[i] == 1 and divisible_ls[i] == 0:
        ans += 1
print(ans)
### BUGGY CODE ###

s = input()
Q = int(input())
for _ in range(Q):
  q = input()
  if (q[0] == "1"):
    s = s[::-1]
  else:
    if (q[2] == "1"):
      s = q[4] + s
    else:
      s = s + q[4]
print(s)

### FIXED CODE ###

from collections import deque
s = deque(input())
Q = int(input())
c = 0
for _ in range(Q):
  q = input()
  if (q[0] == "1"):
    c += 1
  else:
    if (q[2] == "1"):
      if (c % 2 == 0):
        s.appendleft(q[4])
      else:
        s.append(q[4])
    else:
      if (c % 2 == 0):
        s.append(q[4])
      else:
        s.appendleft(q[4])
if (c % 2 == 0):
  print("".join(list(s)))
else:
  print("".join(list(s))[::-1])
### BUGGY CODE ###

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

# 入力された文字列
string = input()

# 最大処理数。100000以下なら文字列長。
max = min(len(string), 100000)

# 削除した文字数
del_count = 0

# 削除があった場合True
del_flg = True

# 削除文字がなくなるまでループする
while del_flg:
    del_flg = False

    # 
    for idx in range(max):
        if idx == max or idx > max:
            break
            
        # 照合対象の文字を切り出す
        target = string[idx : idx + 2]
        
        if target == "01" or target == "10":
            # 削除文字に一致した場合、元の文字列からそれを削除しカウントを進め、
            # 削除フラグを立てる
            string = string[:idx] + string[idx + 2:]
            del_count += 2
            max -= 2
            del_flg = True

print(del_count)

### FIXED CODE ###

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

string = input()

red_count  = string.count('0')
blue_count = string.count('1')

print(min(red_count, blue_count) * 2)
### BUGGY CODE ###

import numpy as np

N = int(input())
A = [0]*N
X = np.zeros([N,N],dtype=int)
Y = np.zeros([N,N],dtype=int)

for n in range(N):
    A[n] = int(input())
    for a in range(A[n]):
        X[n][a], Y[n][a] = list(map(int,input().split()))

def counter( x ):
    if x == 0:
        return 0
    return counter( x >> 1 ) + (x & 1)

ans = 0
       
for bits in range( 1, 1<<N ):
    ok = True
    for i in range( 0, N ):
        if not ( bits & (1 << i) ):
            continue
        for j in range( 0, A[i] ):
            if (( bits >> (X[i][j]-1) ) & 1) ^ Y[i][j]:
                ok = False
    if ok:
        ans = max( ans, counter(bits) )
        
print(ans)

### FIXED CODE ###

import numpy as np

N = int(input())
A = [0]*N
X = np.zeros([N,N],dtype=int)
Y = np.zeros([N,N],dtype=int)

for n in range(N):
    A[n] = int(input())
    for a in range(A[n]):
        X[n][a], Y[n][a] = list(map(int,input().split()))

ans = 0

for bits in range( 1, 1<<N ):
    ok = True
    for i in range( 0, N ):
        if not ok:
            break
        if not ( bits & (1 << i) ):
            continue
        for j in range( 0, A[i] ):
            if (( bits >> (X[i][j]-1) ) & 1) ^ Y[i][j]:
                ok = False
                break
    if ok:
        ans = max( ans, (str(bin(bits))[2:]).count('1'))
        
print(ans)
### BUGGY CODE ###

from copy import copy
from collections import defaultdict
n, p = map(int, input().split())

s = input()
ans = 0
if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i + 1
else:
    dp = [0] * p
    dp[0] = 1
    tmp = 0
    for i in range(n)[::-1]:
        tmp = (int(s[i]) * 10 ** (n - i - 1) + tmp) % p
        # print(tmp, int(s[i]) * 10 ** (n - i - 1))
        ans += dp[tmp]
        dp[tmp] += 1 
    # print(dp)

print(ans)

### FIXED CODE ###

from collections import defaultdict
n, p = map(int, input().split())

s = input()
ans = 0
if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i + 1
else:
    tmp = 0
    d = defaultdict(int)
    d[0] = 1
    for i in range(n)[::-1]:
        tmp += int(s[i]) * pow(10, n - i - 1, p)
        tmp %= p
        ans += d[tmp]
        d[tmp] += 1
print(ans)
### BUGGY CODE ###

# Sum of Divisors
N = int(input())
ans = 0

for i in range(1,N+1):
    j = 1
    while i * j <= N:
        ans += i * j
        j += 1

print(ans)


### FIXED CODE ###

# Sum of Divisors
import math

N = int(input())
ans = 0

for i in range(1,N+1):
    K = math.floor(N/i)
    ans += (K * (K+1) * i)/2

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


def main():
    n = int(input())
    sum = 0
    for i in range(n):
        sum += i
    print(sum)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n = int(input())
    print(n*(n-1)//2)


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

N = 4
m = {0: {1, 4}, 1: {0, 2, 5}, 2: {1, 3, 6}, 3: {2, 7},
     4: {0, 5, 8}, 5: {1, 4, 6, 9}, 6: {2, 5, 7, 10}, 7: {3, 6, 11},
     8: {4, 9, 12}, 9: {5, 8, 10, 13}, 10: {6, 9, 11, 14}, 11: {7, 10, 15},
     12: {8, 13}, 13: {9, 12, 14}, 14: {10, 13, 15}, 15: {11, 14}}
goal = 0x123456789abcdef0
def g(i, j, a):
    t = a // (16 ** j) % 16
    return a - t * (16 ** j) + t * (16 ** i)
def solve():
    MAP = sum((input().split() for _ in range(N)), [])
    start = int("".join(f"{int(i):x}" for i in MAP), base=16)
    if start == goal:
        return 0
    zero = 15 - MAP.index("0")
    dp = [(start, zero, -1)]
    for i in range(1, 46):
        dp0 = []
        while dp:
            M, space, lower = dp.pop()
            for nyx in m[space]:
                if nyx != lower:
                    key = g(space, nyx, M)
                    if key == goal:
                        return i
                    dp0.append((key, nyx, space))
        dp = dp0
def MAIN():
    print(solve())
MAIN()



### FIXED CODE ###

from heapq import heappop, heappush
manhattan = tuple(tuple(abs((i % 4) - (j % 4)) + abs((i // 4) - (j // 4)) for j in range(16)) for i in range(16))
movables = ((1, 4), (0, 2, 5), (1, 3, 6), (2, 7), (0, 5, 8), (1, 4, 6, 9), (2, 5, 7, 10), (3, 6, 11),
            (4, 9, 12), (5, 8, 10, 13), (6, 9, 11, 14), (7, 10, 15), (8, 13), (9, 12, 14), (10, 13, 15), (11, 14))
swap_mul = tuple(tuple((1 << mf) - (1 << mt) for mt in range(0, 64, 4)) for mf in range(0, 64, 4))
destination = 0xfedcba9876543210
i = 0
board_init = 0
blank_init = 0
for _ in range(4):
    for n in map(int, input().split()):
        if n:
            n -= 1
        else:
            n = 15
            blank_init = i
        board_init += n * 16 ** i
        i += 1
estimation_init = sum(manhattan[i][((board_init >> (4 * i)) & 15)] for i in range(16) if i != blank_init)
queue = [(estimation_init, board_init, blank_init)]
visited = set()
while True:
    estimation, board, blank = heappop(queue)
    if board in visited:
        continue
    elif board == destination:
        print(estimation)
        break
    visited.add(board)
    for new_blank in movables[blank]:
        num = (board >> (4 * new_blank)) & 15
        new_board = board + swap_mul[new_blank][blank] * (15 - num)
        if new_board in visited:
            continue
        new_estimation = estimation + 1 - manhattan[new_blank][num] + manhattan[blank][num]
        if new_estimation > 45:
            continue
        heappush(queue, (new_estimation, new_board, new_blank))
### BUGGY CODE ###

N = int(input())
S =  input()
n_list = [0] * N
max_length = 0
for i in range(N):
    for j in range(max_length,N):
        if S[i:j] in S[j:N]:
            continue
        else:
            current_length = j-i-1
            if current_length > max_length:
                max_length = current_length
            break
print(max_length)

### FIXED CODE ###

n = int(input())
S = input()
N = [0]*n
j = 0
 
for i in range(n):
  while S[i:j] in S[j:n]:
    N[i] = j-i
    j += 1
    
print(max(N))
### BUGGY CODE ###

import math
N,M=map(int, input().split())
A=list(map(int, input().split()))
for i in range(M):
    A.sort()
    A[N-1]=math.trunc(A[N-1]/2)
print(sum(A))

### FIXED CODE ###

import heapq
N,M=map(int, input().split())
A=list(map(int, input().split()))
for i in range(N):
    A[i]=-1*A[i]
heapq.heapify(A)
for i in range(M):
    q=heapq.heappop(A)
    q=q/2
    heapq.heappush(A,q)
for i in range(N):
    A[i]=-1*int(A[i])
print(sum(A))
### BUGGY CODE ###

N = int(input())
L = sorted(list(map(int, input().split())))[::-1]

s = 0
for i in range(N-2):
    for j in range(i + 1, N-1):        
        if L[j + 1] > abs(L[i] - L[j]):
            s += N - (j + 1)
            k = N - 1
            while True:
                if L[k] > abs(L[i] - L[j]):
                    break
                else:
                    s -= 1
                    k -= 1
print(s)

### FIXED CODE ###

import bisect
N = int(input())
L = sorted(list(map(int, input().split())))

s = 0
for i in range(N):
    for j in range(i + 1, N):        
        k = bisect.bisect_left(L, L[i] + L[j])
        s += k - j - 1

print(s)
### BUGGY CODE ###

class Node:
    def __init__(self):
        self.p = None
        self.depth = None
        self.l = None
        self.r = None

    def show(self, i):
        global T
        ans = 'node {}: parent = {}, depth = {}, {}, {}'.format(i, self.p, self.depth, self.t(), self.degree(T))
        print(ans)

    def degree(self, T):
        if self.l != None:
            deg = [self.l]
            ch = T[self.l]
            while ch.r != None:
                deg.append(ch.r)
                ch = T[ch.r]
            return deg
        else:
            return []

    def t(self):
        if self.p == -1:
            return 'root'
        elif self.l == None:
            return 'leaf'
        else:
            return 'internal node'

def set_depth(root, d):
    r = T[root]
    r.depth = d
    if r.r != None:
        set_depth(r.r, d)
    if r.l != None:
        set_depth(r.l, d+1)

n = int(input())

T = [Node() for x in range(n)]
for i in range(n):
    A = list(map(int, input().split()))
    l = 0
    for x in range(A[1]):
        if x == 0:
            T[A[0]].l = A[2:][x]
        else:
            T[l].r = A[2:][x]
        l = A[2:][x]
        T[A[2:][x]].p = A[0]

root = None
for i in range(n):
    if T[i].p == None:
        root = i
        T[root].p = -1

set_depth(root, 0)

count = 0
for node in T:
    node.show(count)
    count += 1

### FIXED CODE ###

def set_info(i, p, d):
    r = T[i]
    r[1], r[2] = p, d
    for c in r[0]:
        set_info(c, i, d+1)

n = int(input())
T = [None] * n
root = set(range(n))

for i in range(n):
    A = list(map(int, input().split()))
    ch = A[2:]
    T[A[0]] = [ch, None, None]
    root -= set(ch)

set_info(root.pop(), -1, 0)

for i,node in enumerate(T):
    ch, p, d = node
    print('node {}: parent = {}, depth = {}, {}, {}'.format(
            i, p, d, 'root' if not d else 'internal node' if ch else 'leaf', ch
        ))
### BUGGY CODE ###

import bisect

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

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

A.sort()

for i in range(M):
    B, C = list(map(int,input().split()))
    in_idx = bisect.bisect_right(A,C)

    if B >= in_idx:
        A = [C]*in_idx + A[in_idx:]
    else:
        A = A[B:in_idx] + [C]*B + A[in_idx:]

print(sum(A))

### FIXED CODE ###

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

A = [-1]
A += list(map(int,input().split()))
A.sort()

BC = [[1,-1]]

for i in range(M):
    BC.append(list(map(int,input().split())))

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


x = 0

for i in range(N):
    if A[-1] > BC[-1][1]:
        x += A.pop()
        
    else:
        x += BC[-1][1]
        BC[-1][0] -= 1
        if BC[-1][0] == 0:
            BC.pop()

print(x)
### BUGGY CODE ###

import copy
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    ans = 0
    ad=copy.copy(a)
    del(ad[i])
    adset=list(set(ad))
    for j in adset:
        if(ad.count(j)>=2):
           ans += (ad.count(j)*(ad.count(j)-1)) /2
        else:
            continue
    print(int(ans))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
aset=list(set(a))
ans=0
al=[0]*200000
for i in a:
    al[i]+=1
for j in aset:
    k=al[j]
    ans+=(k*(k-1))//2
for u in a:
    print(ans-al[u]+1)
### BUGGY CODE ###

import itertools
 
num = int(input())
arr = input()
 
c = list(itertools.combinations(list(arr), 3))
 
mat = list(set(c))
 
print(len(mat))

### FIXED CODE ###

n=int(input())
S = input()
 
ans = 0
for i in range(1000):
    a, b, c = map(str, list(str(i).zfill(3)))
    mode = 'a'
    for j in S:
        if mode == 'a' and j == a:
            mode = 'b'
        elif mode == 'b' and j == b:
            mode = 'c'
        elif mode == 'c' and j == c:
            ans += 1
            break
print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
result = 1
for a in A:
    result = result * a
if result > pow(10,18):
    print(-1)
else:
    print (result)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
result = 1
flag = 0
zero_flag = 0
for a in A:
    if a == 0:
        zero_flag = 1
        result = 0
        break
    else:
        result = result * a
        if result > pow(10, 18):
            flag = 1
            result = 0
if flag == 1 and zero_flag != 1:
    print(-1)
else:
    print(result)
### BUGGY CODE ###

N,M=map(int,input().split())
mod=10**9+7
A=[]
for i in range(M):
  A.append(int(input()))
#print(A)
next=0
dp=[0 for i in range(N+1)]
dp[0]=1
dp[-1]=0
for i in range(1,N+1):
  if i in A:
    if next==1:
      break
    else:
      dp[i]=1
      next=1
  elif next==1:
    dp[i]=dp[i-2]
    next=2
  elif next==2:
    dp[i]=dp[i-1]
    next=0
  else:
    dp[i]=(dp[i-1]+dp[i-2])%mod
print(dp[N]%mod)



### FIXED CODE ###

N,M=map(int,input().split())
mod=10**9+7
dp=[0]*(N+1)
dp[0]=1
dp[-1]=0
A=[]
for i in range(M):
  A.append(int(input()))
A=set(A)
#print(A)
for i in range(1,N+1):
  if dp[i-1]==0 and dp[i-2]==0:
    break
  elif i in A:
    continue
  else:
    dp[i]=(dp[i-1]+dp[i-2])%mod
print(dp[N]%mod)
### BUGGY CODE ###

k = int(input())
s = input()
len_s = len(s)
MOD = 1000000007

pow26_i = pow(26, k, MOD)
inv_26 = pow(26, -1, MOD)
pow25_i = 1
comb_i = 1

a = 0
for i in range(k + 1):  
  a += (((comb_i  * pow26_i) % MOD) * pow25_i ) % MOD
  a %= MOD
  
  pow26_i = (pow26_i * inv_26) % MOD
  pow25_i = (pow25_i * 25) % MOD
  comb_i = ((((comb_i * (len_s + i)) % MOD)) * pow(i + 1, -1, MOD)) % MOD


print(a)

### FIXED CODE ###

k = int(input())
s = input()
len_s = len(s)
MOD = 1000000007

x_i = pow(26, k, MOD)
r = (25 * pow(26, -1, MOD)) % MOD
comb_i = 1

a = 0
for i in range(k + 1):  
  a += (comb_i  * x_i  ) % MOD
  a %= MOD
  
  x_i  = (x_i  * r) % MOD
  comb_i = (comb_i * (len_s + i) * pow(i + 1, -1, MOD)) % MOD


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

N = int(input())
L = list(map(int, input().split()))
L.sort()
#print(L)
ans = 0
def find(x, arr):
  a = len(arr)//2
  cur = a
  while True:
    a //= 2
    if arr[cur] < x:
      if cur == len(arr)-1:
        return cur+1
      elif arr[cur+1] >=x:
        return cur+1
      else:
        cur += max(1,a)
    else:
      if cur == 0:
        return 0
      else:
        cur -= max(1, a)
for i in range(N-2):
  for j in range(i+1, N-1):
    ans += find(L[i] + L[j], L)-j-1
print(ans)

### FIXED CODE ###

N = int(input())
L = list(map(int, input().split()))
L.sort()
#print(L)
ans = 0
def find(x, arr):
  a = len(arr)//2
  cur = a
  while True:
    a //= 2
    if arr[cur] < x:
      if cur == len(arr)-1:
        return cur+1
      elif arr[cur+1] >=x:
        return cur+1
      else:
        cur += max(1,a)
    else:
      if cur == 0:
        return 0
      else:
        cur -= max(1, a)
for i in range(N-2):
  for j in range(i+1, N-1):
    ans += find(L[i] + L[j], L)-j-1
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
#p = list(map(int, input().split()))
from sys import stdin
p = [int(x) for x in stdin.readline().rstrip().split()]

m = [0] * n
for i in range(n-k+1):
  m[i] = sum(p[i:i+k])
print((max(m) + k)/2)


### FIXED CODE ###

import itertools

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

pa = list(itertools.accumulate([0] + p))

m = 0
for i in range(n-k+1):
  s = pa[i+k] - pa[i]
  if s > m:
    m = s
print((m+k)/2)
### BUGGY CODE ###

nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

import numpy as np
dp = np.zeros((N+1, M+1), dtype=np.uint64)
for i in range(1, N+1):
    for j in range(1, M+1):
        dp[i, j] = dp[i-1, j] + dp[i, j-1]
        if S[i-1] == T[j-1]:
            dp[i, j] += 1
        else:
            dp[i, j] -= dp[i-1, j-1]
        dp[i, j] %= 1000000007

print(int(dp[N, M]+1))


### FIXED CODE ###

nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

dp = [0] * (M+1)
for i, s in enumerate(S):
    dp2 = dp[:]
    for j, t in enumerate(T):
        dp2[j+1] += dp2[j] - dp[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
    dp = dp2

print((dp[M]+1) % 1000000007)
### BUGGY CODE ###

import fractions
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int,input().split()))
g = 1
MOD = 10**9+7
for elem in a:
    g *= elem//fractions.gcd(g,elem)
res = 0
for elem in a:
    res += g//elem
print(res%MOD)


### FIXED CODE ###

import fractions
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int,input().split()))
g = 1
res = 0
MOD = 10**9+7
for elem in a:
    tmp = g*elem//fractions.gcd(g,elem)
    res *= tmp//g
    g = tmp
    res += g//elem
print(res%MOD)
### BUGGY CODE ###

import numpy as np

def isPrime_np(n):
    maxp = int(np.sqrt(n))
    searchlist = [i for i in range(2,n+1)]
    primeNum = []

    while searchlist[0] <= maxp:
        primeNum.append(searchlist[0])
        tmp = searchlist[0]
        searchlist = [i for i in searchlist if i % tmp != 0]
    primeNum.extend(searchlist)
    
    return primeNum

Q = int(input())
lr = [list(map(int,input().split())) for _ in range(Q)]

a = [0]*10**5
prime = isPrime_np(10**5)
pset = set(prime)
for p in prime:
    if (p+1)/2 in pset:
        a[p] = 1

ans = []
for l,r in lr:        
    ans.append(sum(a[l:r+1]))

print(*ans,sep="\n") 

### FIXED CODE ###

import numpy as np

def isPrime_np(n):
    maxp = int(np.sqrt(n))
    searchlist = [i for i in range(2,n+1)]
    primeNum = []

    while searchlist[0] <= maxp:
        primeNum.append(searchlist[0])
        tmp = searchlist[0]
        searchlist = [i for i in searchlist if i % tmp != 0]
    primeNum.extend(searchlist)
    
    return primeNum

MaxQ = 10**5+1
Q = int(input())
lr = [list(map(int,input().split())) for _ in range(Q)]

a = [0]*MaxQ
s = [0]*MaxQ
prime = isPrime_np(MaxQ)
pset = set(prime)
for p in prime:
    if (p+1)/2 in pset:
        a[p] = 1

ans = []
for i in range(MaxQ-1):
    s[i+1] = s[i] + a[i]
    
for l,r in lr:
    ans.append(s[r+1] - s[l])
print(*ans,sep="\n")
### BUGGY CODE ###

def soinsu(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n=int(input())
a=soinsu(n)
c=[]
if n>=2:
    for i in range(max(a)):
        c.append(0)
for i in a:
    c[i-1]+=1
f=0
if n>=2:
    f=max(c)
    s=[]
    for i in range(f+1):
        s.append(0)
    for i in c:
        s[i]+=1
z=0
g=[1]
d=1
e=1
while e<=f:
    d+=1
    e=d*(d+1)/2
    g.append(e)
for i in range(len(g)):
    g[i]=int(g[i])
for i in range(1,len(g)):
    z+=i*(sum(s[g[i-1]:g[i]]))


print(z)

### FIXED CODE ###

n=int(input())
import math
s=round(math.sqrt(n))+1

i=2
c1=0
c2=1
ans=0
while i<=s:
    if n%i==0:
        n//=i
        c1+=1
        if c1==c2:
            c1=0
            c2+=1
            ans+=1
    else:
        c2=1
        i+=1
        c1=0
if n>s:
    ans+=1
    
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def solve():
    H, W = map(int, input().split())
    Ass = [tuple(map(int, input().split())) for _ in range(H)]
    Bss = [tuple(map(int, input().split())) for _ in range(H)]

    dp = [[set() for j in range(W)] for i in range(H)]
    A, B = Ass[0][0], Bss[0][0]
    dp[0][0] = set([(A, B), (B, A)])

    for i in range(H):
        for j in range(W):
            if i < H-1:
                A, B = Ass[i+1][j], Bss[i+1][j]
                for x, y in dp[i][j]:
                    dp[i+1][j].add((x+A, y+B))
                    dp[i+1][j].add((x+B, y+A))
            if j < W-1:
                A, B = Ass[i][j+1], Bss[i][j+1]
                for x, y in dp[i][j]:
                    dp[i][j+1].add((x+A, y+B))
                    dp[i][j+1].add((x+B, y+A))

    ans = float('inf')
    for x, y in dp[-1][-1]:
        score = abs(x-y)
        ans = min(ans, score)

    #for dpi in dp:
    #    print(dpi)
    print(ans)


solve()


### FIXED CODE ###

maxV = 80*(80+80)

H, W = map(int, input().split())
Ass = [tuple(map(int, input().split())) for _ in range(H)]
Bss = [tuple(map(int, input().split())) for _ in range(H)]

dp = [[0 for j in range(W)] for i in range(H)]

for i in range(H):
    for j in range(W):
        A, B = Ass[i][j], Bss[i][j]
        if A > B:
            A, B = B, A
        if i == 0 and j == 0:
            dp[i][j] = 1<<(maxV+B-A) | 1<<(maxV-B+A)
        if i > 0:
            dp[i][j] |= dp[i-1][j]<<(B-A) | dp[i-1][j]>>(B-A)
        if j > 0:
            dp[i][j] |= dp[i][j-1]<<(B-A) | dp[i][j-1]>>(B-A)

bitset = dp[-1][-1]
mask = 1<<(2*maxV)
ans = maxV
for i in range(-maxV, maxV+1):
    if bitset & mask:
        ans = min(ans, abs(i))
    mask >>= 1

print(ans)
### 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 for _ in range(max_capacity + 1)]
    for i in range(1, nb + 1):
        w, v = values[i - 1]
        dp = dp[:w] + [max(dp[j], dp[j - w] + v) for j in range(w, max_capacity + 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]
    return dp[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 sys
input = sys.stdin.readline
 
K,S=map(int,input().split())
count=0
for x in range(K+1):
  for y in range(K+1):
    for z in range(K+1):
      if z==S-x-y: count+=1
print(count)

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())
count=0
for x in range(K+1):
    for y in range(K+1):
        if S-(x+y)>=0 and S-(x+y)<=K: count+=1
print(count)