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

N = int(input())
HN = list(map(int, input().split(" ")))

Max = 0

for i in range(N - 1):
    Count = 0
    NowHeight = HN[i]
    for j in range(i+1, N):
        NextHeight = HN[j]
        if NowHeight >= NextHeight:
            NowHeight = NextHeight
            Count = Count + 1
        else:
            break
    if Count > Max:
        Max = Count
    if N - i <= Max:
        break

print(Max)

### FIXED CODE ###

N = int(input())
HN = list(map(int, input().split(" ")))
 
Max = 0
 
i = 0
while i < (N - 1):
    Count = 0
    NowHeight = HN[i]
    for j in range(i+1, N):
        NextHeight = HN[j]
        if NowHeight >= NextHeight:
            NowHeight = NextHeight
            Count = Count + 1
        else:
            break
    if Count > Max:
        Max = Count
    i = i + 1 + Count
 
print(Max)
### BUGGY CODE ###


import numpy as np
def resolve():
    K, Q = map(int, input().split())
    D = np.array(input().split(), dtype=np.int64)


    for _ in range(Q):
        n, x, m = map(int, input().split())
        # 最初にmの余りをとっても変わらない
        # 与えられた要素をすべてmod mにとりあえずする
        E = D % m
        acc_E = np.cumsum(E)

        # 数列がN項であるということは、末項は数列dをN-1回足したものである
        loop, rem = divmod(n - 1, K)
        tot = x % m + acc_E[-1] * loop

        # Bi = Bi+1 になっている個所：0の個数
        zero = [int(e == 0) for e in E]
        zero_acc = np.cumsum(zero)
        tot_zero = zero_acc[-1] * loop

        if rem > 0:
            tot += acc_E[rem-1]
            tot_zero += zero_acc[rem - 1]
        dame = tot // m
        print(n - 1 - dame - tot_zero)

if __name__ == "__main__":
    resolve()


### FIXED CODE ###


import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline

import numpy as np
def resolve():
    K, Q = map(int, inp().split())
    D = np.array(inp().split(), dtype=np.int64)
    nxm = [list(map(int, inp().split())) for _ in range(Q)]

    for n, x, m in nxm:
        # 最初にmの余りをとっても変わらない
        # 与えられた要素をすべてmod mにとりあえずする
        E = D % m
        acc_E = np.cumsum(E)

        # 数列がN項であるということは、末項は数列dをN-1回足したものである
        loop, rem = divmod(n - 1, K)
        tot = x % m + acc_E[-1] * loop

        # Bi = Bi+1 になっている個所：0の個数
        zero_acc = np.cumsum(E == 0).astype(np.int64)
        tot_zero = zero_acc[-1] * loop

        if rem > 0:
            tot += acc_E[rem-1]
            tot_zero += zero_acc[rem - 1]
        dame = tot // m
        print(n - 1 - dame - tot_zero)

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

from heapq import heappop, heappush, heapify

N, M = map(int, input().split())
A = list(map(int, input().split()))
List = [list(map(int, input().split())) for _ in range(M)]

List = sorted(List, reverse=True, key=lambda x: x[1])

heapify(A)

i = 0
while i<M:
    m = min(A)
    tmp = List[i][1]
    cnt = List[i][0]
    while (0<cnt) and (m<tmp):
            m = heappop(A)
            heappush(A, tmp)
            tmp = List[i][1]
            cnt-=1
    i+=1

print(sum(A))

### FIXED CODE ###

from heapq import heappop, heappush, heapify

N, M = map(int, input().split())
A = list(map(int, input().split()))
List = [list(map(int, input().split())) for _ in range(M)]

List = sorted(List, reverse=True, key=lambda x: x[1])

heapify(A)

i = 0
while i<M:
    m = heappop(A)
    heappush(A, m)
    tmp = List[i][1]
    cnt = List[i][0]
    while (0<cnt) and (m<tmp):
            m = heappop(A)
            heappush(A, tmp)
            tmp = List[i][1]
            cnt-=1
    i+=1

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

S=input()
l = len(S)
S_list = [S[i] for i in range(l)]
ans =0
for _ in range(int(l/2)):
    l = len(S_list)
    if l<2:
        break
    check_dif = False
    for i in range(l-1):
        if S_list[i] != S_list[i+1]:
            S_list.pop(i)
            S_list.pop(i)
            check_dif = True
            break
    if check_dif:
        ans+=2
    else:
        break
print(ans)

### FIXED CODE ###

S=input()
num_one=S.count('1')
num_zero=S.count('0')
ans = 2*min(num_one,num_zero)
print(ans)
### BUGGY CODE ###

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

tmp_pre = 0
for i in range(1, N+1):
  if (i%B!=0):
    continue
  else:
    tmp = (A*(i-1))//B - A*((i-1)//B)
    if tmp > tmp_pre:
      tmp_pre = tmp
if (B > N):
  print((A*N)//B - A*(N//B))
else:
  print(int(tmp_pre))

### FIXED CODE ###

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

if B==1:
  print(0)
else:
  tb = B - 1
  tp_pre = 0
  while(True):
    tp = (A*tb)//B - A*(tb//B)
    if tp > tp_pre:
      tp_pre = tp
    tb += B
    if tb > N:
      break
  if (B > N):
    print((A*N)//B - A*(N//B))
  else:
    print(int(tp_pre))
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(M):
  B, C = map(int, input().split())
  A += [C] * B

A.sort(reverse=True)
print(sum(A[0:N]))

### FIXED CODE ###

import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
sortsecond = lambda val: val[1]
x = [list(map(int, input().split())) for _ in range(M)]
x.sort(key=sortsecond)

i = 0
for j in range(M):
  times = x[-(j+1)][0]
  num = x[-(j+1)][1]
  while (times > 0):
    try:
      tmp = A[i]
    except IndexError:
      print(sum(A))
      exit()
    
    if (tmp < num):
      A[i] = num
    else:
      print(sum(A))
      exit()
    times -= 1
    i += 1

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

N,K=map(int,input().split())
A=[0]+list(map(int,input().split()))+[0]
p=50

if K<=p:    
    for i in range(K):
        B=[0]+[0]*N+[0]
        for j in range(1,N+1):
            left  = max(0,j-A[j])
            right = min(N+1,j+A[j]+1)
            B[left]  += 1
            B[right] -= 1
        A[0]=B[0]
        for k in range(1,N+1):
            A[k]=A[k-1]+B[k]
else:
    A=[N]*(N+2)
print(*A[1:N+1])

### FIXED CODE ###

N,K=map(int,input().split())
A=[0]+list(map(int,input().split()))+[0]
p=50

if K<=p:    
    for i in range(K):
        B=[0]+[0]*N+[0]
        for j in range(1,N+1):
            left  = max(0,j-A[j])
            right = min(N+1,j+A[j]+1)
            B[left]  += 1
            B[right] -= 1
        A[0]=B[0]
        for k in range(1,N+1):
            A[k]=A[k-1]+B[k]
else:
    A=[N]*(N+2)
print(*A[1:N+1])
### BUGGY CODE ###

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

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

ans = 1
tmp = 0
for i in range(n):
    _a = a[:]
    _a.pop(i)
    tmp = _a[0]
    for j in range(n-1):
        tmp = gcd(tmp,_a[j])
    if tmp > ans:
        ans = tmp

print(ans)


### FIXED CODE ###

#EOFERROR
# import math
# import copy
# from functools import reduce
# n = int(input())
# a = list(map(int,input().split()))
# ans = reduce(math.gcd,a)
# if n<=2 or (min(a)==max(a)):
#     print(max(a))
# else:
#     for i in range(n):
#         _a = copy.copy(a)
#         _a.pop(i)
#         tmp = reduce(math.gcd,_a)
#         if tmp > ans:
#             print(tmp)
#             break
#         else:
#             pass

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

def cul(n,x):
    l = len(x)
    b = [x[i] for i in range(l)]
    b.pop(n)
    tmp = b[0]
    for i in range(1,l-1):
        tmp = gcd(tmp,b[i])
    return tmp

import sys
p = 50
N = int(input())
if p>N : p=N
a = list(map(int,input().split()))

ans = 0

for i in range(p):
    s = cul(i,a[:p])
    if s>ans : ans=s

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

def onlya(n , a):

    ans = "YES"

    for i in range(n):
        if a.count(a[i]) != 1:
            return "NO"

    return ans

def main():
    n = int(input())
    a = list(map(int,input().split()))
    print(onlya(n , a))

if __name__ == '__main__':
    main()

### FIXED CODE ###


def has_duplicates(seq):
    return len(seq) != len(set(seq))

def onlya(n , a):

    ans = "YES"

#    for i in range(n):
#        for w in range(i + 1 , n):
#            if a[i] == a[w]:
#                return "NO"

    if has_duplicates(a):
        return "NO"

    return ans

def main():
    n = int(input())
    a = list(map(int,input().split()))
    print(onlya(n , a))

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

import decimal


def main():
    N, K = map(int, input().split())
    ans = 0
    for n in range(1, N + 1):
        s = n
        c = 1
        while K > s:
            s *= 2
            c /= 2
        ans += decimal.Decimal((1 / N) * c)
    print(ans)


main()


### FIXED CODE ###

import decimal
 
 
def main():
    N, K = map(int, input().split())
    ans = 0
    for n in range(1, N + 1):
        s = 0
        s += n
        c = 0
        while K > s:
            s *= 2
            c += 1
        ans += decimal.Decimal((1 / N) * (1 / 2) ** c)
    print(ans)
 
 
main()
### BUGGY CODE ###

n,m = map(int,input().split())
a = [-1]
for i in range(1, m+1):
    a = a + [int(input())]
a =a+[n+1] 
for i in range(m+1):
    a[i]=a[i+1] - a[i]-1
b=[0]
b=b+[1]
for i in range(2, max(a)+1):
    b=b+[(b[i-1] + b[i-2])%(10**9+7)]
s=1
for i in range(m+1):
    s=(s*b[a[i]])%(10**9+7)
print(s)

### FIXED CODE ###

n,m = map(int,input().split())
c=10**9+7
a = [-1 for _ in range(m + 1)]
for i in range(1, m+1):
    a[i] = int(input())
a =a+[n+1] 
for i in range(m+1):
    a[i]=a[i+1] - a[i]-1
b=[0 for _ in range(max(a) + 1)]
b[1]=1
for i in range(2, max(a)+1):
    b[i] = (b[i-1] + b[i-2])%c
s=1
for i in range(m+1):
    s=(s*b[a[i]])%c
print(s)
### BUGGY CODE ###

import copy
def main():
    h, w = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    b = [list(map(int, input().split())) for _ in range(h)]
    n = 2*80*160 + 10
    m = n//2
    dp = [[[False]*n for j in range(w)] for i in range(h)]
    dp[0][0][m+abs(a[0][0] - b[0][0])] = True
    dp[0][0][m-abs(a[0][0] - b[0][0])] = True
    for i in range(h):
        for j in range(w):
            x = abs(a[i][j] - b[i][j])
            if 0 < i and 0 < h:
                for k in range(x, n-x):
                    if dp[i-1][j][k] or dp[i][j-1][k]:
                        dp[i][j][k-x] = True
                        dp[i][j][k+x] = True
            elif 0 < i:
                for k in range(x, n-x):
                    if dp[i-1][j][k]:
                        dp[i][j][k-x] = True
                        dp[i][j][k+x] = True
            elif 0 < j:
                for k in range(x, n-x):
                    if dp[i][j-1][k]:
                        dp[i][j][k-x] = True
                        dp[i][j][k+x] = True
    ans = float("inf")
    for i in range(n):
        if dp[h-1][w-1][i]:
            ans = min(ans, abs(m-i))
    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

import numpy as np
def main():
    h, w = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    b = [list(map(int, input().split())) for _ in range(h)]
    n = 80*(80+80) + 10
    m = n//2
    dp = [[None]*w for i in range(h)]
    for i in range(h):
        for j in range(w):
            dp[i][j] = np.zeros(n, np.bool)
    dp[0][0][m+abs(a[0][0] - b[0][0])] = True
    dp[0][0][m-abs(a[0][0] - b[0][0])] = True
    for i in range(h):
        for j in range(w):
            x = abs(a[i][j] - b[i][j])
            if 0 < i and 0 < h:
                dp[i][j][x:] |= dp[i-1][j][:n-x]
                dp[i][j][:n-x] |= dp[i-1][j][x:]
                dp[i][j][x:] |= dp[i][j-1][:n-x]
                dp[i][j][:n-x] |= dp[i][j-1][x:]
            elif 0 < i:
                dp[i][j][x:] |= dp[i-1][j][:n-x]
                dp[i][j][:n-x] |= dp[i-1][j][x:]
            elif 0 < j:
                dp[i][j][x:] |= dp[i][j-1][:n-x]
                dp[i][j][:n-x] |= dp[i][j-1][x:]
    ans = float("inf")
    for i in range(m-80-1, m+80+2):
        if dp[h-1][w-1][i]:
            ans = min(ans, abs(m-i))
    print(ans)

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

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

from sys import stdin


def main():
    X, Y, A, B, C = list(map(int, stdin.readline().split()))
    p = list(map(int, stdin.readline().split()))
    q = list(map(int, stdin.readline().split()))
    r = list(map(int, stdin.readline().split()))

    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)

    oisisa = 0
    x, y, z = 0, 0, 0
    for i in range(0, X + Y):
        m_p = p[0] if len(p) > 0 else 0
        m_q = q[0] if len(q) > 0 else 0
        m_r = r[0] if len(r) > 0 else 0
        m = max( [m_p, m_q, m_r] )

        if x < X and m_p == m:
            # pから取る
            oisisa += p.pop(0)
            x += 1

        elif y < Y and m_q == m:
            # qから取る
            oisisa += q.pop(0)
            y += 1
        else:
            # rから取る
            oisisa += r.pop(0)
            z += 1

        if x >= X:
            p = []
        if y >= Y:
            q = []

        if x + y + z == X + Y:
            print(oisisa)
            return


if __name__ == "__main__":
    main()


### FIXED CODE ###

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

from sys import stdin


def main():
    X, Y, A, B, C = list(map(int, stdin.readline().split()))
    p = list(map(int, stdin.readline().split()))
    q = list(map(int, stdin.readline().split()))
    r = list(map(int, stdin.readline().split()))

    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)

    oisii = []
    oisii.extend(p[0:X])
    oisii.extend(q[0:Y])
    oisii.extend(r)
    oisii.sort(reverse=True)
    print( sum( oisii[0:X+Y]) )


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

i = input()
N = int(i)
A = []
for x in range(N):
    j = input()
    A.append(int(j))

for x in range(N):
    #print(x)
    t = []
    if x != N - 1:
        t = A[:x] + A[x+1:]
    else:
        t = A[:x]
    print(max(t))


### FIXED CODE ###

import numpy as np

i = input()
N = int(i)
A = np.array([0]*N)
i = input()
a = int(i)
A[0] = a
i = input()
b = int(i)
A[1] = b
snd = min(a, b)
fst = max(a, b)
for x in range(N - 2):
    j = input()
    y = int(j)
    A[x+2] = y
    if y <= fst:
        snd = max(snd, y)
    fst = max(fst, y)

for x in range(N):
    if A[x] < fst:
        print(fst)
    else:
        print(snd)
### BUGGY CODE ###

a=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163]

def factorization(n):
    temp=n
    i=0
    icnt=1
    while temp>1 and i<len(a):
        if temp%a[i]==0:
            cnt=0
            while temp%a[i]==0:
                cnt+=1
                temp //= a[i]
            icnt=icnt*(cnt+1)
        i+=1

    if temp!=1:
        icnt=icnt*2
    if icnt==1:
        icnt=icnt*2

    return icnt

n=int(input())
isum=1
for ii in range(2,n+1):
    icnt=1
    isum+=ii*factorization(ii)

print(isum)


### FIXED CODE ###

n=int(input())
#n=10000000
ksum=0
for k in range(1,n+1):
    m=n//k
    ksum+=k*m*(m+1)//2
    
print(ksum)
### BUGGY CODE ###

N, M = map(int, input().split())
P = [i -1 for i in map(int,input().split())]
ss = []
point = 0
while True:
    if point in ss:
        break
    ss.append(point)
    point = P[point]
loop = ss[ss.index(point):]
ll = len(ss)
l = len(loop)
if ll >= M:
    print(ss[M]+1)
else:
    print(loop[(M-ll)%l]+1)


### FIXED CODE ###

N, M = map(int, input().split())
P = [i -1 for i in map(int,input().split())]
ss = set([])
point = 0
for i in range(N):
    if point in ss:
        break
    ss.add(point)
    point = P[point]
S = [0]
points = 0
for i in range(len(ss)-1):
    points = P[points]
    S.append(points)
loop = S[S.index(point):]
ll = len(S)
l = len(loop)
if ll > M:
    print(S[M]+1)
elif ll == M:
    print(point+1)
else:
    print(loop[(M-ll)%l]+1)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np
divisor = 1000000007
answer=1
# 文字列を一文字ずつのリストに代入 test は['t', 'e', 's', 't']
s = list(input())
t = []

for i in range( len(s) ):
    if s[i] == '?':
        t.append(-1)
    else:
        t.append(int(s[i]))

dp = [[0 for i in range(13)] for i in range(100005)]
dp[0][0]=1
for i in range(len(s)):
    for j in range(10):
        if t[i] == -1 or t[i] == j:
            for k in range(13):
                dp[i+1][(k*10+j)%13] += dp[i][k]
    for j in range(13):
        dp[i+1][j] = dp[i+1][j] % divisor

print(dp[len(s)][5])


### FIXED CODE ###

# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
divisor = 1000000007
# 文字列を一文字ずつのリストに代入 test は['t', 'e', 's', 't']
s = list(input())
t = []

for i in range( len(s) ):
    if s[i] == '?':
        t.append(-1)
    else:
        t.append(int(s[i]))

dp = [[0 for i in range(13)] for i in range(100005)]
dp[0][0]=1
for i in range(len(s)):
    for j in range(10):
        if t[i] == -1 or t[i] == j:
            for k in range(13):
                dp[i+1][(k*10+j)%13] += dp[i][k]
    for j in range(13):
        dp[i+1][j] = dp[i+1][j] % divisor

print(dp[len(s)][5])
### BUGGY CODE ###

from collections import defaultdict

N,W = map(int, input().split())
WV = [[int(i) for i in input().split()] for _ in range(N)]

w0 = WV[0][0]
for i in range(N):
    WV[i][0] -= w0

# (i, j, k): i番目まででj個選んで総重量がk以下のときの最大値
dp = defaultdict(lambda: -float("inf"))

# 初期条件
dp[(0, 0, 0)] = 0

# 配るDP
for i, (w, v) in enumerate(WV):
    for j in range(i + 1):
        for k in range(300):
            dp[(i + 1, j, k)] = max(dp[(i + 1, j, k)], dp[(i, j, k)])
            dp[(i + 1, j  + 1, k + w)] = max(dp[(i + 1, j  + 1, k + w)], dp[(i, j, k)] + v)

ans = 0
for j in range(N + 1):
    for k in range(300):
        if j * w0 + k <= W:
            ans = max(ans, dp[(N, j, k)])

print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
from itertools import accumulate

N,W = map(int,input().split())
WV = [[int(i) for i in input().split()] for _ in range(N)]

MINW = WV[0][0]

W0 = sorted([0] + [v for w,v in WV if w == MINW])
W1 = sorted([0] + [v for w,v in WV if w == MINW+1])
W2 = sorted([0] + [v for w,v in WV if w == MINW+2])
W3 = sorted([0] + [v for w,v in WV if w == MINW+3])

W0 = tuple(accumulate(W0))
W1 = tuple(accumulate(W1))
W2 = tuple(accumulate(W2))
W3 = tuple(accumulate(W3))

ans = 0
for w0 in range(len(W0)):
    for w1 in range(len(W1)):
        for w2 in range(len(W2)):
            for w3 in range(len(W3)):
                tmp = (len(W0) - (w0 + 1)) * MINW
                tmp += (len(W1) - (w1 + 1)) * (MINW+1)
                tmp += (len(W2) - (w2 + 1)) * (MINW+2)
                tmp += (len(W3) - (w3 + 1)) * (MINW+3)

                if tmp <= W:
                    tmp = W0[-1] - W0[w0]
                    tmp += W1[-1] - W1[w1]
                    tmp += W2[-1] - W2[w2]
                    tmp += W3[-1] - W3[w3]
                    ans = max(ans, tmp)

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

R, G, B, N = map(int, input().split())

cnt = 0
for r in range(N//R + 1):
    for b in range(N//B + 1):
        res = (N - r*R - b*B)
        if res >= 0 and res%G == 0:
            cnt += 1
print(cnt)

### FIXED CODE ###

def main():
    R, G, B, N = map(int, input().split())

    cnt = 0
    for r in range(N//R + 1):
        for b in range(N//B + 1):
            res = (N - r*R - b*B)
            if res >= 0 and res%G == 0:
                cnt += 1
    print(cnt)

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

a,b,c = map(int, input().split())
k = int(input())

while k:
    if a>=b:
        b *= 2
        k -= 1
    elif b>=c:
        c *= 2
        k -= 1

if a<b and b<c:
    print("Yes")
else:
    print("No")



### FIXED CODE ###

a,b,c = map(int, input().split())
k = int(input())

while k:
    if a>=b:
        b *= 2
        k -= 1
    elif b>=c:
        c *= 2
        k -= 1
    else:
        break

if a<b and b<c:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

N, M = map(int, input().split())
gates = []
res = 0
for _ in range(M):
  L, R = map(int, input().split())
  gates.append((L, R))

for i in range(1, N+1):
  flag = True
  for g in gates:
    if g[0] <= i <= g[1]:
      continue
    else:
      flag = False
      break 
  if flag: res+=1
  
print(res)

### FIXED CODE ###

N, M = map(int, input().split())
res = 0
L_max = 0
R_min = 100000
for _ in range(M):
  L, R = map(int, input().split())
  if L_max < L: L_max = L
  if R < R_min: R_min = R
  
  
print(max(0, (R_min - L_max + 1)))
### BUGGY CODE ###

import sys
from collections import Counter

n = int(sys.stdin.readline())
ct = Counter()
a_ls = dict()
for i in range(n):
    inp = [int(i) - 1 for i in sys.stdin.readline().split()]
    a_ls[i] = inp
cnt = 0
while True:
    combis = set()
    flg = False
    for i in range(n):
        if len(a_ls[i]) == 0:
            continue
        target = a_ls[i][0]
        if (i, target) in combis or (target, i) in combis:
            if len(a_ls[i]) > 0:
                a_ls[i].pop(0)
            if len(a_ls[target]) > 0:
                a_ls[target].pop(0)
            flg = True
        else:
            combis.add((i, target))
    if not flg:
        if not any([len(i) for i in a_ls.values()]):
            break
        cnt = -1
        break
    cnt += 1
print(cnt)

### FIXED CODE ###

import sys
from collections import Counter
import copy

n = int(sys.stdin.readline())
ct = Counter()
a_ls = dict()
for i in range(n):
    inp = [int(i) - 1 for i in sys.stdin.readline().split()]
    a_ls[i] = inp
cnt = 0
candidate = list(range(n))
rest = n * (n - 1) / 2
combis = set()
while rest:
    no_ls = []
    next_candidate = []
    flg = False
    for i in candidate:
        if len(a_ls[i]) == 0:
            continue
        target = a_ls[i][0]
        if (i, target) in combis or (target, i) in combis:
            next_candidate.append(i)
            next_candidate.append(target)
            rest -= 1
            if len(a_ls[i]) > 0:
                a_ls[i].pop(0)
            if len(a_ls[target]) > 0:
                a_ls[target].pop(0)
            flg = True
        else:
            combis.add((i, target))
    candidate = next_candidate
    if not flg:
        cnt = -1
        break
    cnt += 1
print(cnt)