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

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

c = 0

while True:
	f = 0	
	for i in range(n-1):
		if a[i] + a[i+1] > x:
			f = 1
			if a[i+1] >= a[i]:
				a[i+1] -= 1
			else:
				a[i] -= 1
			c += 1
			break
	if f == 0:
		break
print(c) 

### FIXED CODE ###

n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    delta = max(0, a[i] + a[i+1] - x)
    a[i+1] -= delta
    if a[i+1] < 0:
        a[i] += a[i+1]
        a[i+1] = 0
    ans += delta
print(ans)
### BUGGY CODE ###

#import pdb; pdb.set_trace()

s = list(map(int,input()))
t = len(s)
mod = 2019

import numpy as np
arr = [0] * t
arr = np.array(arr)
arr[0] = s[0]
for i in range(1,t):
    arr[i] = (arr[i-1] * 10 + s[i]) % mod

powarr = [pow(10,i,mod) for i in range(t)]

ans = list(arr).count(0)
for i in range(1,t):
    tmp = (arr[i:] - powarr[i]*arr[:t-i]) % mod
    ans += list(tmp).count(0)


print(ans)

### FIXED CODE ###

s = list(map(int,input()))
s.reverse()
t = len(s)
mod = 2019

arr = [0] * (t+1)
arr[-2] = s[0]
for i in range(1,t):
    arr[t-i-1] = (arr[t-i] + s[i]*pow(10,i,mod)) % mod

from collections import Counter
arr = Counter(arr)

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

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

from functools import reduce
def gcd(a,b):
    if a<b:
        a,b = b,a
    while b:
        a,b = b,a%b
    return a

N = int(input())
A = list(map(int,input().split()))
gcd_max = 0
for i in range(N):
    B = A.copy()
    B[i:i+1] = []
    gcd_max = max(gcd_max,reduce(gcd,B))
print(gcd_max)

### FIXED CODE ###

def gcd(x,y):
    while y != 0:
        x,y = y,x%y
    return x
n = int(input())
a = list(map(int,input().split()))

L,R = [0],[0]
for i in range(1,n+1): #L[i]は左i個,R[i]は右i個
    L.append(gcd(L[-1],a[i-1]))
    R.append(gcd(R[-1],a[n-i]))
print(max(gcd(L[i],R[n-i-1]) for i in range(n)))
### BUGGY CODE ###

# coding: utf-8
import sys
from collections import deque

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def main():
    N = ir()
    P = lr()
    dp = [[min(i, N-1-i)] * N for i in range(N)]
    people = [[True] * N for i in range(N)]
    for j in range(N):
        x = min(j, N-1-j)
        for i in range(N):
            dp[i][j] = min(dp[i][j], x)

    answer = 0

    def bfs(sy, sx):
        que = deque([(sy, sx, dp[sy][sx])])
        popleft = que.popleft; append = que.append
        used = set()
        while que:
            y, x, cur = popleft()
            if (y, x) in used:
                continue
            used.add((y, x))
            if cur == -1 and not people[y][x]:
                people[y][x] = True
            for dy, dx in zip([0, 1, 0, -1], [1, 0, -1, 0]):
                ny = y + dy
                nx = x + dx
                if 0 <= ny < N and 0 <= nx < N:
                    if dp[ny][nx] > cur + 1:
                        dp[ny][nx] = cur + 1
                        if not people[ny][nx]:
                            dp[ny][nx] = cur
                        if (ny, nx) not in used:
                            append((ny, nx, dp[ny][nx]))
                    elif dp[ny][nx] > cur and (not people[ny][nx]):
                        # 人がいない時
                        dp[ny][nx] = cur
                        if (ny, nx) not in used:
                            append((ny, nx, cur))

    for p in P:
        p -= 1
        i = p // N
        j = p % N
        answer += dp[i][j]
        dp[i][j] -= 1
        people[i][j] = False
        bfs(i, j)

    print(answer)
    
if __name__ == "__main__":
    main()


### FIXED CODE ###

# coding: utf-8
import sys
from collections import deque

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def main():
    N = ir()
    P = lr()
    P = [((p-1)//N, (p-1)%N) for p in P]
    dp = [[min(i, N-1-i, j, N-1-j) for j in range(N)] for i in range(N)]
    people = [[True] * N for i in range(N)]

    answer = 0
    for i, j in P:
        answer += dp[i][j]
        people[i][j] = False
        que = deque([(i, j, dp[i][j])])
        popleft = que.popleft; append = que.append
        while que:
            y, x, cur = popleft()
            cur += people[y][x]
            if x > 0:
                if dp[y][x-1] > cur:
                    dp[y][x-1] = cur
                    append((y, x-1, cur))
            if x < N-1:
                if dp[y][x+1] > cur:
                    dp[y][x+1] = cur
                    append((y, x+1, cur))
            if y > 0:
                if dp[y-1][x] > cur:
                    dp[y-1][x] = cur
                    append((y-1, x, cur))
            if y < N-1:
                if dp[y+1][x] > cur:
                    dp[y+1][x] = cur
                    append((y+1, x, cur))

    print(answer)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

from collections import deque
from copy import copy
import bisect
 
n = int(input())
order = sorted(list(map(int, input().split())))
l = deque(order)
ans = 0
 
for _ in range(len(l)-2):
    first = l.pop()
    m = copy(l)
    for _ in range(len(m)-1):
        second = m.pop()
        fix = first-second
        ans += len(m)-bisect.bisect_right(list(m), fix)
 
print(ans)

### FIXED CODE ###

from bisect import bisect_right

n = int(input())
order = sorted(list(map(int, input().split())))
ans = 0

for i in reversed(range(2, n)):
    for j in reversed(range(1, i)):
        ans += j - bisect_right(order[0:j], order[i]-order[j])

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

import bisect
from collections import deque
class UnionFind(): #Union-Find木の実装
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 0
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
N = int(input())
same = set()
xseq = []
yseq = []
edge = []
uf = UnionFind(N)
ans = 0

x,y = (int(x) for x in input().split())
same.add((x,y))
xseq.append((x,0))
yseq.append((y,0))
for i in range(1,N):
    x,y = (int(x) for x in input().split())
    if (x,y) not in same:
        same.add((x,y))
        xb = bisect.bisect_left(xseq,(x,i))
        xseq.insert(xb,(x,i))
        if xb == 0:
            edge.append((xseq[1][0]-x,(xseq[1][1],i)))
        elif xb == len(xseq)-1:
            edge.append((x-xseq[-2][0],(xseq[-2][1],i)))
        else:
            edge.append((xseq[xb+1][0]-x,(xseq[xb+1][1],i)))
            edge.append((x-xseq[xb-1][0],(xseq[xb-1][1],i)))
        yb = bisect.bisect_left(yseq,(y,i))
        yseq.insert(yb,(y,i))
        if yb == 0:
            edge.append((yseq[1][0]-y,(yseq[1][1],i)))
        elif yb == len(yseq)-1:
            edge.append((y-yseq[-2][0],(yseq[-2][1],i)))
        else:
            edge.append((yseq[yb+1][0]-y,(yseq[yb+1][1],i)))
            edge.append((y-yseq[yb-1][0],(yseq[yb-1][1],i)))
edge.sort()
d = deque(edge)
for i in range(len(d)):
    temp = d.popleft()
    if uf.find(temp[1][0]) != uf.find(temp[1][1]):
        uf.union(temp[1][0],temp[1][1])
        ans += temp[0]
print(ans)

### FIXED CODE ###

from collections import deque
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 0
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
N = int(input())
xseq = []
yseq = []
uf = UnionFind(N)
ans = 0

for i in range(N):
    x,y = (int(x) for x in input().split())
    xseq.append((x,i))
    yseq.append((y,i))
xseq.sort()
yseq.sort()
xdiff = [(xseq[i][0]-xseq[i-1][0],(xseq[i][1],xseq[i-1][1])) for i in range(1,N)]
ydiff = [(yseq[i][0]-yseq[i-1][0],(yseq[i][1],yseq[i-1][1])) for i in range(1,N)]
diff = xdiff + ydiff
diff.sort()
d = deque(diff)

for i in range(len(d)):
    temp = d.popleft()
    if uf.find(temp[1][0]) != uf.find(temp[1][1]):
        uf.union(temp[1][0],temp[1][1])
        ans += temp[0]
print(ans)
### BUGGY CODE ###

def main():
    N, W = (int(i) for i in input().split())
    WV = [[int(i) for i in input().split()] for j in range(N)]
    w0 = WV[0][0]
    Ws = [w[0] for w in WV]
    Vs = [v[1] for v in WV]
    from collections import defaultdict
    dp = defaultdict(int)
    for i in range(N):
        for j in range(w0, W+1):
            dp[i+1, j] = max(dp[i+1, j], dp[i, j])
            if 0 <= j - Ws[i]:
                dp[i+1, j] = max(dp[i+1, j], dp[i, j - Ws[i]] + Vs[i])
    print(dp[N, W])


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N, W = (int(i) for i in input().split())
    WV = [[int(i) for i in input().split()] for j in range(N)]
    for i in range(1, N):
        WV[i][0] -= WV[0][0]
    w0 = WV[0][0]
    WV[0][0] = 0
    V = {i: [] for i in range(4)}
    for w, v in WV:
        V[w].append(v)
    for i in range(4):
        V[i].sort(reverse=True)
    S = [[0] for i in range(4)]
    for i in range(4):
        for b in V[i]:
            S[i].append(S[i][-1] + b)
    ans = 0
    for i, v0 in enumerate(S[0]):
        for j, v1 in enumerate(S[1]):
            for k, v2 in enumerate(S[2]):
                for m, v3 in enumerate(S[3]):
                    w_cur = w0*(i+j+k+m) + j + 2*k + 3*m
                    if W < w_cur:
                        continue
                    ans = max(ans, v0+v1+v2+v3)
    print(ans)


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

import sys
from collections import deque
sys.setrecursionlimit(10 ** 7)

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

for _ in range(N - 1):
    a, b = map(int, input().split())
    count[a - 1].append(b - 1)
    count[b - 1].append(a - 1)
    inputs.append(sorted([a - 1, b - 1]))

K = 0
for c in count:
    K = max(K, len(c))
print(K)

def dfs(root, count):
    done = [-1 for _ in range(N)]
    done[root] = 0
    info = []
    d = deque([root])
    r = d.pop()
    childs = count[r]
    tmp = 1
    for c in childs:
        if done[c] == -1:
            d.append([c, r, tmp])
            tmp += 1
            done[c] += 1
    while d:
        data = d.pop()
        info.append(data)
        childs = count[data[0]]
        tmp = 1
        for c in childs:
            if done[c] == -1:
                if tmp != data[2]:
                    d.append([c, data[0], tmp])
                else:
                    tmp += 1
                    d.append([c, data[0], tmp])
                tmp += 1
                done[c] += 1
    return info

info = dfs(0, count)
info_new = [[sorted([i[0], i[1]]), i[2]] for i in info]

for i in inputs:
    for k in info_new:
        if i == k[0]:
            print(k[1])

### FIXED CODE ###

import sys
from collections import deque, OrderedDict
sys.setrecursionlimit(10 ** 7)

N = int(input())
count = [[] for _ in range(N)]
inputs = OrderedDict()

for _ in range(N - 1):
    a, b = map(int, input().split())
    count[a - 1].append(b - 1)
    count[b - 1].append(a - 1)
    inputs["-".join(list(map(str, sorted([a - 1, b - 1]))))] = 0

K = 0
for c in count:
    K = max(K, len(c))
print(K)

def dfs(root, count, inputs):
    done = [-1 for _ in range(N)]
    done[root] = 0
    d = deque([root])
    r = d.pop()
    childs = count[r]
    tmp = 1
    for c in childs:
        if done[c] == -1:
            d.append([c, r, tmp])
            tmp += 1
            done[c] += 1
    while d:
        data = d.pop()
        inputs["-".join(list(map(str, sorted(data[:2]))))] = data[2]
        childs = count[data[0]]
        tmp = 1
        for c in childs:
            if done[c] == -1:
                if tmp != data[2]:
                    d.append([c, data[0], tmp])
                else:
                    tmp += 1
                    d.append([c, data[0], tmp])
                tmp += 1
                done[c] += 1
    
    return inputs

inputs = dfs(0, count, inputs)

for i in inputs.values():
    print(i)
### BUGGY CODE ###

N, M = map(int, input().split())
sum = 0
height = list(map(int, input().split()))
road = []
for i in range(M):
  R = list(map(int, input().split()))
  road.append(R)

for i in range(N):#0~N-1
  p = 0
  s = 0
  for j in range(M):#0~M-1
    if road[j][0] - 1 == i:
      s += 1
      if height[road[j][1] - 1] >= height[i]:
        p += 1
    if road[j][1] - 1 == i:
      s += 1
      if height[road[j][0] - 1] >= height[i]:
        p += 1

  if p == 0 or s == 0:
    sum += 1
    
print(sum)

### FIXED CODE ###

N, M = map(int, input().split())
sum = 0
height = list(map(int, input().split()))
road = []
for i in range(M):
  R = list(map(int, input().split()))
  road.append(R)

other = []

for i in range(N):
  other.append([0])

for i in range(M):
  other[road[i][0] - 1].append(height[road[i][1] - 1])
  other[road[i][1] - 1].append(height[road[i][0] - 1])
for i in range(N):
  if height[i] > max(other[i]):
    sum += 1

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

N = int(input())

mes_dict = {}
for i in range(N):
  m = input()
  if m not in mes_dict:
    mes_dict[m] = 0
  mes_dict[m] += 1

answer = sorted([k for k, v in mes_dict.items() if v == max(mes_dict.values())])
for ans in answer:
  print(ans)

### FIXED CODE ###

N = int(input())
 
mes_dict = {}
for i in range(N):
  m = input()
  try:
    mes_dict[m] += 1
  except:
    mes_dict[m] = 1

ma =max(mes_dict.values())
answer = sorted([k for k, v in mes_dict.items() if v == ma])
for ans in answer:
  print(ans)
### BUGGY CODE ###

n = int(input())
A = list(map(int,input().split()))
MOD = 10**9 + 7
for i in range(n):
  b = format(A[i],'b').zfill(61)
  A[i] = b


bit = [0]*61
for i in range(n):
  for j in range(61):
    if A[i][j] =='1':
      bit[j] += 1

ans = 0
for k in range(61):
  multi = ((bit[k]%MOD)*(n-bit[k])%MOD)%MOD
  if k > 30:
    ans += (((2**(60-k))%MOD) * multi)%MOD
  else:
    ooo = ((2**(30-k))%MOD * (2**20)%MOD * (2**10)%MOD) %MOD
    ans += (ooo * multi)%MOD
  ans %= MOD
print(ans)

### FIXED CODE ###

n = int(input())
A = list(map(int,input().split()))
MOD = 10**9 + 7
for i in range(n):
  b = format(A[i],'b').zfill(61)
  A[i] = b


bit = [0]*61
for i in range(n):
  for j in range(61):
    if A[i][j] =='1':
      bit[j] += 1

ans = 0
for k in range(61):
  multi = (bit[k]*(n-bit[k]))%MOD
  if k > 30:
    ans += (((2**(60-k))%MOD) * multi)%MOD
  else:
    ooo = ((2**(30-k))%MOD * (2**20)%MOD * (2**10)%MOD) %MOD
    ans += (ooo * multi)%MOD
  ans %= MOD
print(ans)
### BUGGY CODE ###

n = int(input())
ans = [0] * 10001
for x in range(1, n+1):
    for y in range(1, n+1):
        for z in range(1, n+1):
            t = x**2+y**2+z**2+x*y+y*z+z*x
            if t <= n:
                ans[t] += 1
for i in range(1, n+1):
    print(ans[i])

### FIXED CODE ###

import math

n = int(input())
ans = [0] * 10001
for x in range(1, int(math.sqrt(n+1))):
    for y in range(1, int(math.sqrt(n+1))):
        for z in range(1, int(math.sqrt(n+1))):
            t = x**2+y**2+z**2+x*y+y*z+z*x
            if t <= n:
                ans[t] += 1
for i in range(1, n+1):
    print(ans[i])
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N=int(input())
A=map(int,input().split())
Q=int(input())
numbers=[]
for _ in range(Q):
    B,C=map(int,input().split())
    numbers.append([B,C])
answers=[0 for _ in range(100001)]
for a in A:
    answers[a]+=a
for number in numbers:
    suuji=answers[number[0]]//number[0]
    answers[number[0]]=0
    answers[number[1]]+=suuji*number[1]
    print(sum(answers))


### FIXED CODE ###

import sys
input = sys.stdin.readline

N=int(input())
A=map(int,input().split())
Q=int(input())
numbers=[]
for _ in range(Q):
    B,C=map(int,input().split())
    numbers.append([B,C])
answers=[0 for _ in range(100001)]
for a in A:
    answers[a]+=a
whole=sum(answers)
for number in numbers:
    suuji=answers[number[0]]//number[0]
    answers[number[0]]=0
    answers[number[1]]+=suuji*number[1]
    whole+=(number[1]-number[0])*suuji
    print(whole)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# TLE
# O(HW(H+W)) で10^8になるので無理

H, W = map(int, input().split())

S = [input() for _ in range(H)]
NUM = [[0] * (W) for _ in range(H)]

for r in range(H):
    cnt = 0
    for c in range(W):
        if S[r][c] == '#':
            cnt = 0
        else:
            cnt += 1
            NUM[r][c] += cnt

    cnt = 0
    for c in range(W - 1, -1, -1):
        if S[r][c] == '#':
            cnt = 0
        else:
            cnt += 1
            NUM[r][c] += cnt

for c in range(W):
    cnt = 0
    for r in range(H):
        if S[r][c] == '#':
            cnt = 0
        else:
            cnt += 1
            NUM[r][c] += cnt

    cnt = 0
    for r in range(H - 1, -1, -1):
        if S[r][c] == '#':
            cnt = 0
        else:
            cnt += 1
            NUM[r][c] += cnt

ans = 4
for i in range(H):
    t = max(NUM[i])
    ans = max(ans, t)

print(ans-3)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# TLE
# O(HW(H+W)) で10^8になるので無理

H, W = map(int, input().split())

S = [input() for _ in range(H)]
NUM = [[0] * (W) for _ in range(H)]

for r in range(H):
    cnt = 0
    for c in range(W):
        if S[r][c] == '#':
            cnt = 0
        else:
            cnt += 1
            NUM[r][c] += cnt

    cnt = 0
    for c in range(W - 1, -1, -1):
        if S[r][c] == '#':
            cnt = 0
        else:
            cnt += 1
            NUM[r][c] += cnt

for c in range(W):
    cnt = 0
    for r in range(H):
        if S[r][c] == '#':
            cnt = 0
        else:
            cnt += 1
            NUM[r][c] += cnt

    cnt = 0
    for r in range(H - 1, -1, -1):
        if S[r][c] == '#':
            cnt = 0
        else:
            cnt += 1
            NUM[r][c] += cnt

ans = 4
for i in range(H):
    t = max(NUM[i])
    ans = max(ans, t)

print(ans-3)
### BUGGY CODE ###

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

s = 1
for i in range(n):
    s *= a[i]

if s > 1000000000000000000:
    print(-1)
else:
    print(s)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
if 0 in a:
    print(0)
else:
    s = 1
    for i in range(n):
        s *= a[i]
        if s > 10**18:
            break
        elif a[i] == 0:
            break
            
    if s > 10**18:
        print(-1)
    else:
        print(s)
### BUGGY CODE ###

#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right

def main():
    N,C,K = map(int, input().split())
    Ti = list(int(input()) for _ in range(N))
    Ti.sort()
    ret = 0
#    print(Ti)
    while len(Ti)>0:
        Tto = K + Ti[0]
        Ti = Ti[min(C,bisect_right(Ti[:min(C,len(Ti))], Tto)):]
        ret += 1
#        print(Ti)
    print(ret)

if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right

def main():
    N,C,K = map(int, input().split())
    Ti = list(int(input()) for _ in range(N))
    Ti.sort()
    i = 0
    ret = 0
    while i<N:
        ret += 1
        s = i
        Ts = Ti[i]
        while i<N and Ti[i]<=(Ts+K) and (i-s)<C:
            i += 1

    print(ret)

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

N, K = map(int, input().split())

XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x, y))
    
    
dots = XY[:]

import sys
INT_MAX = sys.maxsize

x_dots = [(x, y) for x, y in dots]
x_dots = sorted(x_dots)
y_dots = [(x, y) for x, y in dots]
y_dots = sorted(y_dots, key=lambda x: x[1])

ans = INT_MAX
for i in range(N):
    for j in range(i+1, N):
        sub_x_dots = set(x_dots[i:j+1])
        xl = x_dots[i:j+1][0][0]
        xr = x_dots[i:j+1][-1][0]
        for k in range(N):
            for l in range(k+1, N):
                sub_y_dots = set(y_dots[k:l+1])
                #print("----")
                #print(x_dots[i:j+1])
                #print(y_dots[k:l+1])
                intersection = (sub_x_dots) & sub_y_dots
                if len(intersection) >= K:
                    yl = y_dots[k:l+1][0][1]
                    yr = y_dots[k:l+1][-1][1]
                    area = (xl-xr) * (yl-yr)
                    
                    ans = min(ans, area)
print(ans)
                
                

### FIXED CODE ###

N, K = map(int, input().split())

XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x, y))
    
dots = XY[:]

import sys
INT_MAX = sys.maxsize

ans = INT_MAX

import itertools
for ((left_x, _), (right_x, _)) in itertools.combinations(dots, 2):
    if left_x > right_x:
        left_x, right_x = right_x, left_x
    for ((_, under_y), (_, top_y)) in itertools.combinations(dots, 2):
        if under_y > top_y:
            under_y, top_y = top_y, under_y
        counter = 0
        for d_x, d_y in dots:
            if  (left_x <= d_x) and (d_x <= right_x) and (under_y <= d_y) and (d_y <= top_y):
                counter += 1
                
        if counter >= K:
            area = (top_y-under_y) * (right_x-left_x)
            if ans > area:
                ans = area
            
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, W: int, w: "List[int]", v: "List[int]"):
    dp = [[float('inf')] * (N * 1000 + 1) for _ in range(N+1)]
    dp[0][0] = 0

    for i, (cw, cv) in enumerate(zip(w, v)):
        for j in range(N * 1000 + 1):
            dp[i+1][j] = dp[i][j]
            if 0 <= (j - cv) and (dp[i][j - cv] + cw) <= W:
                dp[i+1][j] = min(dp[i+1][j], dp[i][j - cv] +  cw)

    return max([cv for cv, cw in enumerate(dp[-1]) if isfinite(cw)])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    w = [int()] * (N)  # type: "List[int]" 
    v = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        w[i] = int(next(tokens))
        v[i] = int(next(tokens))
    result = solve(N, W, w, v)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, W: int, w: "List[int]", v: "List[int]"):
    dp = [[float('inf')] * (N * 1000 + 1) for _ in range(N+1)]
    dp[0][0] = 0

    for i, (cw, cv) in enumerate(zip(w, v)):
        for j in range(N * 1000 + 1):
            dp[i+1][j] = dp[i][j]
            if 0 <= (j - cv) and (dp[i][j - cv] + cw) <= W:
                dp[i+1][j] = min(dp[i+1][j], dp[i][j - cv] +  cw)

    return max([cv for cv, cw in enumerate(dp[-1]) if isfinite(cw)])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    w = [int()] * (N)  # type: "List[int]"
    v = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        w[i] = int(next(tokens))
        v[i] = int(next(tokens))
    result = solve(N, W, w, v)
    print(result)

if __name__ == '__main__':
    main()