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

s = int(input()) 

dict={}
num_list = list(map(int, input().split()))

length=len(num_list)
count=[0]*(s+1000)
for i in range(length):
    count[num_list[i]]+=1
    dict[num_list[i]]=count[num_list[i]]
    
#print(dict)


sum=0
count=0
n = int(input()) 
for i in range(n):
    a,b = map(int, input().split())  
    if dict.get(a)!=None:
        if dict.get(b)!=None:
            count=dict[b]
            dict[b]=dict[a]+dict[b]
        else:
            dict[b]=dict[a]
        dict[a]=0
    else:
        pass
    #print(dict)
    for k, v in dict.items():
        sum+=k*v
    print(sum)
    sum=0

   


### FIXED CODE ###

s = int(input()) 

dict={}
num_list = list(map(int, input().split()))

length=len(num_list)
count=[0]*(s+1000)
for i in range(length):
    count[num_list[i]]+=1
    dict[num_list[i]]=count[num_list[i]]
    
sum=0
#print(dict)
for k, v in dict.items():
    sum+=k*v
#print(dict)
#print(sum)

count=0
d=0
n = int(input()) 
for i in range(n):
    a,b = map(int, input().split())  
    if dict.get(a)!=None:
        d=(b-a)*dict[a]
        #print("d:{}".format(d))
        if dict.get(b)!=None:
            count=dict[b]
            dict[b]=dict[a]+dict[b]
        else:
            dict[b]=dict[a]
        dict[a]=0
        sum+=d
        
        #print(dict)
        
    else:
        pass
    d=0
    print(sum)
    #print()
### BUGGY CODE ###

S = input()
T = input()

dp = [[0] * (len(T)+1) for i in range(len(S)+1)]
for i, s in enumerate(S, 1):
  for j, t in enumerate(T, 1):
    if s == t:
      dp[i][j] = dp[i-1][j-1] + 1
    else:
      dp[i][j] = max(dp[i-1][j], dp[i][j-1])

ans = ''
while i > 0 and j > 0:
  if dp[i][j] == dp[i][j-1]:
    j -= 1
  elif dp[i][j] == dp[i-1][j]:
    i -= 1
  else:
    ans += S[i-1]
    i -= 1
    j -= 1

print(ans[::-1])

### FIXED CODE ###

S = input()
T = input()

dp = [[0] * (len(T)+1) for i in range(len(S)+1)]
for i, s in enumerate(S, 1):
  for j, t in enumerate(T, 1):
    if s == t:
      dp[i][j] = dp[i-1][j-1] + 1
    else:
      dp[i][j] = max(dp[i-1][j], dp[i][j-1])

ans = []
while i > 0 and j > 0:
  if dp[i][j] == dp[i][j-1]:
    j -= 1
  elif dp[i][j] == dp[i-1][j]:
    i -= 1
  else:
    ans.append(S[i-1])
    i -= 1
    j -= 1

print(''.join(ans[::-1]))
### BUGGY CODE ###

import sys
import numpy as np

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

U = 10**6 + 10

def prime_table(N):
    is_prime = np.zeros(N, np.int64)
    is_prime[2:3] = 1
    is_prime[3::2] = 1
    for p in range(3, N, 2):
        if p * p >= N:
            break
        if is_prime[p]:
            is_prime[p * p::p + p] = 0
    return is_prime, np.where(is_prime)[0]

def main(A, primes):
    B = np.zeros(U + 1, np.int64)
    for x in A:
        B[x] += 1
    for p in primes:
        for i in range(U // p + 1):
            B[p * i] += B[i]
    ret = 0
    for x in A:
        ret += B[x] == 1
    return ret

A = np.array(read().split(), np.int64)[1:]
_, primes = prime_table(U)

print(main(A, primes))


### FIXED CODE ###

import sys
import numpy as np
from numba import njit

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

@njit('(i4[::1],)', cache=True)
def solve(A):
    count = np.zeros(10**6 + 10, np.int32)
    for x in A:
        if count[x] > 1:
            continue
        count[::x] += 1
    ret = 0
    for x in A:
        ret += count[x] == 1
    return ret

A = np.array(read().split(), np.int32)[1:]

print(solve(A))
### BUGGY CODE ###

x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ab = []
for i in range(len(a)):
    for j in range(len(b)):
        ab.append(a[i] + b[j])

ab = sorted(ab, reverse=True)
ab = ab[:k]
abc = []
for i in range(len(ab)):
    for j in range(len(c)):
        abc.append(ab[i] + c[j])

abc = sorted(abc, reverse=True)
for i in range(k):
    print(abc[i])




### FIXED CODE ###

import itertools


x, y, z, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
AB = [a + b for (a, b) in list(itertools.product(A, B))]
AB.sort(reverse=True)
ABC = [ab + c for (ab, c) in list(itertools.product(AB[:k], C))]
ABC.sort(reverse=True)

for i in range(k):
    print(ABC[i])
### BUGGY CODE ###

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

mod = 10**9 + 7

ans = 0
# 制約より、aはそれぞれ60桁以内で表せる
# i+1(=1,2,...,60)桁目についてそれぞれ考える
for i in range(60):
    k = 1 << i  # k = 100....00(2) = 2**i(10)
    cnt_1 = 0
    cnt_0 = 0

    for ai in a:
        if k & ai:
            cnt_1 += 1
        else:
            cnt_0 += 1
    # 1 XOR 0 = 1 となる個数 = cnt_1 * cnt_0
    ans += (k % mod * cnt_1 * cnt_0) % mod

print(ans % mod)


### FIXED CODE ###

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

mod = 10**9 + 7

ans = 0
# 制約より、aはそれぞれ60桁以内で表せる
# i+1(=1,2,...,60)桁目についてそれぞれ考える
for i in range(60):
    k = 1 << i  # k = 100....00(2) = 2**i(10)
    cnt_1 = 0
    cnt_0 = 0

    for ai in a:
        if k & ai:
            cnt_1 += 1
        else:
            cnt_0 += 1
    # 1 XOR 0 = 1 となる個数 = cnt_1 * cnt_0
    ans += (k % mod * cnt_1 * cnt_0) % mod

print(ans % mod)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline


def dfs(cur, pls):
    pls += to_add[cur]
    ans[cur] = pls
    for u in e[cur]:
        if visited[u]:
            continue
        visited[u] = True
        dfs(u, pls)


n, q = map(int, input().split())

e = [set() for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    e[a].add(b)
    e[b].add(a)

to_add = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    to_add[p] += x

ans = [0] * n
visited = [False] * n
visited[0] = True

dfs(0, 0)

print(*ans)


### FIXED CODE ###

n, q = map(int, input().split())

g = [set() for _ in range(n)]
for _ in range(n - 1):
    a, b = (int(x) - 1 for x in input().split())
    g[a].add(b)
    g[b].add(a)

ctr = [0] * n
for _ in range(q):
    it = map(int, input().split())
    p = next(it) - 1
    x = next(it)
    ctr[p] += x

st = [(0, -1)]
while st:
    v, par = st.pop()
    for u in g[v]:
        if u == par: continue
        ctr[u] += ctr[v]
        st.append((u, v))
print(*ctr)
### BUGGY CODE ###

import fractions

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7
def lcm(a,b):
    return a*b // fractions.gcd(a,b)

LCM = 1
for a in A:
    LCM = lcm(LCM, a)

B = []
for i in range(N):
    B.append(LCM // A[i])

print(sum(B) % MOD)


### FIXED CODE ###

from fractions import gcd


def main():
        
    N = int(input())
    A = list(map(int, input().split())) 
    MOD = 10**9 + 7


    l = 1

    for a in A:
        l = l * a // gcd(l, a)


    ans = 0
    for a in A:
        ans += (l // a)
    ans %= MOD

    print(ans)


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

#
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def next_kenp(node, edges, dones):
    nodes = set()
    nodes2 = set()
    for n1 in edges[node]:
        for n2 in edges[n1]:
            if n2 not in nodes2:
                nodes2.add(n2)

    for nn in nodes2:
        for n3 in edges[nn]:
            if n3 in dones or n3 in nodes:
                continue
            nodes.add(n3)
    return nodes


def main():
    n, m = map(int, input().split())

    edges = defaultdict(list)

    for _ in range(m):
        u, v = map(int, input().split())
        edges[u].append(v)

    s, t = map(int, input().split())

    dones = set()
    que = deque()
    que.append((s, 0))
    while que:
        node, step = que.popleft()
        next_nodes = list(next_kenp(node, edges, dones))
        next_nodes.reverse()
        for n in next_nodes:
            if n == t:
                print(step + 1)
                exit()

            if n not in dones:
                que.append((n, step + 1))
                dones.add(n)
    print(-1)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n, m = map(int, input().split())

    edges = defaultdict(list)

    for _ in range(m):
        u, v = map(int, input().split())
        edges[(u, 0)].append((v, 1))
        edges[(u, 1)].append((v, 2))
        edges[(u, 2)].append((v, 0))

    s, t = map(int, input().split())

    # print(new_edges)

    dones = set()
    que = deque()
    que.append(((s, 0), 0))
    while que:
        node, step = que.popleft()

        next_nodes = edges[node]
        # print(next_nodes)
        for n, l in next_nodes:
            if n == t and l == 0:
                print((step + 1) // 3)
                exit()

            if (n, l) not in dones:
                que.append(((n, l), step + 1))
                dones.add((n, l))
    print(-1)


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

import sys
from operator import itemgetter
from itertools import accumulate
from collections import defaultdict
import bisect
input = sys.stdin.buffer.readline

N = int(input())
vws = [tuple(map(int, input().split())) for _ in range(N)]

dp_dict = [defaultdict(lambda: 0)]
dp_dict[0][0] = 0
dp_dict[0][vws[0][1]] = vws[0][0]

for i in range(1, min(2**9, N)):
    v, w = vws[i]
    dp_dict.append(dp_dict[(i-1)//2].copy())
    for w_sum, v_sum in dp_dict[(i-1)//2].items():
        dp_dict[i][w_sum + w] = max(v_sum + v, dp_dict[i][w_sum + w])

values_list = []
weights_list = []
for d in dp_dict:
    ls = sorted(d.items(), key = itemgetter(0))
    weights, values = zip(*ls)
    values = list(accumulate(values, max))
    values_list.append(values)
    weights_list.append(weights)
        
Q = int(input())
for _ in range(Q):
    V, L = map(int, input().split())
    if V-1 < len(dp_dict):
        index = bisect.bisect_right(weights_list[V-1], L) - 1
        print(values_list[V-1][index])
    else:
        V -= 1
        d = defaultdict(lambda: 0)
        d[0] = 0
        while V >= len(dp_dict):
            v, w = vws[V]
            iterator = list(d.items())
            for w_sum, v_sum in iterator:
                d[w_sum + w] = max(v_sum + v, d[w_sum + w])
            V = (V-1) // 2

        v_max = 0
        for w1, v1 in d.items():
            index = bisect.bisect_right(weights_list[V], L-w1) - 1
            if index == -1:
                continue
            v_max = max(v_max, v1 + values_list[V][index])
        print(v_max)


### FIXED CODE ###

import sys
import numpy as np
from numba import njit

input = sys.stdin.buffer.readline

N = int(input())
vws = [tuple(map(int, input().split())) for _ in range(N)]

n = min(2**11, N)
vws_arr = np.array(vws, np.int32)

dp = np.zeros((n, 10**5+1), np.int32)
for i in range(n):
    v, w = vws[i]
    dp[i] = dp[(i-1)//2]
    dp[i, w:] = np.maximum(dp[(i-1)//2, :-w]+v, dp[i, w:])


@njit("i4(i4[::1], i4[::1], i4, i4[::1])", cache = True)
def func(vs, ws, L, dp_):
    values = np.zeros(1 << len(vs), np.int32)
    weights = np.zeros(1 << len(vs), np.int32)
    for i in range(len(vs)):
        for bits in range(1 << len(vs)):
            if bits & (1 << i):
                values[bits] += vs[i]
                weights[bits] += ws[i]
    ret = 0
    for v, w in zip(values, weights):
        if w <= L:
            ret = max(dp_[L - w] + v, ret)
    return ret

Q = int(input())
for _ in range(Q):
    V, L = map(int, input().split())
    V -= 1
    if V < n:
        print(dp[V, L])
    else:
        Vs = []
        while V >= n:
            Vs.append(V)
            V = (V-1) // 2
        vs = vws_arr[Vs, 0]
        ws = vws_arr[Vs, 1]
        print(func(vs, ws, L, dp[V]))
### BUGGY CODE ###

import bisect
n = int(input()) 
A = sorted([int(i) for i in input().split()] )
B = sorted([int(i) for i in input().split()] )
C = sorted([int(i) for i in input().split()] )

result = 0
for c in C:
    B_sub = B[:bisect.bisect_left(B,c)]
    for b in B_sub:
        result += bisect.bisect_left(A,b)

print(result)

### FIXED CODE ###

import bisect
n = int(input()) 
A = sorted([int(i) for i in input().split()] )
B = sorted([int(i) for i in input().split()] )
C = sorted([int(i) for i in input().split()] )

b_count = []
pre_b = 0
for b in B:
    current_count = bisect.bisect_left(A,b)
    b_count.append(pre_b + current_count)
    pre_b += current_count

result = 0
for c in C:
    index = bisect.bisect_left(B,c)
    if index == 0:
        continue
    result += b_count[index-1]
    
print(result)
### BUGGY CODE ###

def gen(x):
    root = int(pow(x, 0.5))

    yield x

    for k in range(2, root):
        if x % k == 0:
            yield k
            yield x // k

    k = root
    if x % k == 0:
        yield k
        if k * k != x:
            yield x // k


N = int(input())

# N%K!=0
cnt = len(tuple(gen(N - 1)))

# N%K==0
for k in gen(N):
    X = N
    while X % k == 0:
        X //= k
    cnt += (X % k == 1)

print(cnt)


### FIXED CODE ###

def gen(x):
    root = int(pow(x, 0.5))
    for k in range(1, root + 1):
        if x % k == 0:
            yield k
            if k != x // k:
                yield x // k


def main():
    N = int(input())

    # N%K!=0
    cnt = sum(1 for _ in filter(lambda x: x > 1, gen(N - 1)))

    # N%K==0
    for k in filter(lambda x: x > 1, gen(N)):
        x = N
        while x % k == 0:
            x //= k

        if x % k == 1:
            cnt += 1

    print(cnt)


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

from collections import Counter
n=int(input())
string_list=[Counter(input()) for i in range(n)]
cnt=0
for i in range(n):
  si = string_list[i]
  for j in range(i+1, n):
    sj = string_list[j]
    if si==sj:
      cnt += 1
print(cnt)

### FIXED CODE ###

from collections import Counter
n=int(input())
string_list=["".join(sorted(list(input()))) for i in range(n)]
counter=Counter(string_list)
cnt=0
for k, v in counter.items():
  cnt+=int(v*(v-1)/2)
print(cnt)
### BUGGY CODE ###

s = input()

ans = 0
while s.find('BW') > -1:
    ans = ans + s.count('BW')
    s = s.replace('BW', 'WB')


print(ans)

### FIXED CODE ###

def solve(s):
    ans = 0
    d = 0
    sl = len(s)
    for i in range(sl):
        if s[i] == "B":
            ans = ans + (sl - i - 1 - d)
            d = d + 1
    return ans


print(solve(input()))
### BUGGY CODE ###

from collections import deque
N=int(input())
A=deque([*map(int,input().split())])
a=1
while A:
  a*=A.popleft()
if a > 10**18:
  print(-1)
else:
  print(a)

### FIXED CODE ###

N=int(input())
A=[*map(int,input().split())]
a=1
if 0 in A:
  a=0
else:
  while A:
    a*=A.pop()
    if a>10**18:
      a=-1
      break
print(a)
### BUGGY CODE ###

n = int(input());
l=list(map(int,input().strip().split()))
l.sort()
if l[0] == 0 : 
    print("0")
else :    
    ans = l[0]
    c=0
    for i in range(1, n, 1) :
        if l[i]*ans >  1000000000000000000 :
            print("-1")
            c=1
        ans = ans*l[i]    
    if c == 0 : 
        print(ans)        
    
  

### FIXED CODE ###

n = int(input());
l=list(map(int,input().strip().split()))
l.sort()
if l[0] == 0 : 
    print("0")
else :    
    ans = l[0]
    c=0
    for i in range(1, n) :
        if l[i]*ans >  int(1000000000000000000) :
            print("-1")
            c=1
        if c == 1 : 
            break 
        ans = ans*l[i]    
    if c == 0 : 
        print(ans)
### BUGGY CODE ###

n = int(input())
s = str(input())

s_r = []
s_g = []
s_b = []

for i in range(n):
  if s[i] == "R":
    s_r.append(i)
  elif s[i] == "G":
    s_g.append(i)
  else:
    s_b.append(i)

ans = 0
    
def conditions(a, b):
  c = [-1, -1, -1]
  if (a+b) % 2 == 0:
    c[0] = (a+b) / 2
    c[1] = 2*b - a
    c[2] = 2*a - b
  else:
    c[1] = 2*b - a
    c[2] = 2*a - b
  list = []
  for i in range(3):
    if c[i] >= 0 and c[i] <= n-1:
      list.append(c[i])
  return list
  
for item in s_r:
  for item2 in s_g:
    count = 0
    for i in conditions(item, item2):
      if i in s_b:
        count += 1
    ans += len(s_b) - count

print(ans)

### FIXED CODE ###

import collections

n = int(input())
s = str(input())

aaa = collections.Counter(s)
s_r = aaa["R"]
s_g = aaa["G"]
s_b = aaa["B"]

def noteq(a, b, c):
  if a != b and b != c and c != a:
    return True
  else:
    return False

ans = s_r * s_g * s_b

for i in range(n):
  for d in range(n):
    j = i + d
    k = j + d
    if k >= n:
      break;
    else:
      a = s[i]
      b = s[j]
      c = s[k]
      if noteq(a, b, c):
        ans -= 1
    
print(ans)
### BUGGY CODE ###

from math import sqrt
import heapq

def calc(arr, i, j):
    d = sqrt((arr[i][0] - arr[j][0])**2 + (arr[i][1] - arr[j][1])**2)
    if arr[i][2] + arr[j][2] <= d:
        return d - arr[i][2] - arr[j][2]
    else:
        return 0

def main():
    xs, ys, xt, yt = map(int, input().split())
    n = int(input())
    arr = [list(map(int, input().split())) for _ in range(n)]
    arr.append([xs, ys, 0])
    arr.append([xt, yt, 0])
    n += 2
    st = set()
    for i in range(n):
        st.add(i)
    dist = [float("inf")]*n
    dist[n-2] = 0
    hq = []
    heapq.heappush(hq, [0, n-2])
    while len(hq) > 0:
        v, p = heapq.heappop(hq)
        if p in st:
            st.remove(p)
            for nxt in st:
                d = calc(arr, p, nxt)
                if dist[nxt] > dist[p] + d:
                    dist[nxt] = dist[p] + d
                    heapq.heappush(hq, [dist[nxt], nxt])
    print(dist[-1])

if __name__ == "__main__":
    main()

### FIXED CODE ###

from math import sqrt
import heapq

def calc(arr, i, j):
    d = sqrt((arr[i][0] - arr[j][0])**2 + (arr[i][1] - arr[j][1])**2)
    if arr[i][2] + arr[j][2] <= d:
        return d - arr[i][2] - arr[j][2]
    else:
        return 0

def main():
    xs, ys, xt, yt = map(int, input().split())
    n = int(input())
    arr = [list(map(int, input().split())) for _ in range(n)]
    arr.append([xs, ys, 0])
    arr.append([xt, yt, 0])
    n += 2
    st = set()
    for i in range(n):
        st.add(i)
    dist = [float("inf")]*n
    dist[n-2] = 0
    dist[n-1] = calc(arr, n-2, n-1)
    hq = []
    heapq.heappush(hq, [0, n-2])
    while len(hq) > 0:
        _, p = heapq.heappop(hq)
        if p in st:
            st.remove(p)
            for nxt in st:
                d = calc(arr, p, nxt)
                if dist[nxt] > dist[p] + d:
                    dist[nxt] = dist[p] + d
                    heapq.heappush(hq, [dist[nxt], nxt])
    print(dist[-1])

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

import sys

def main():
    n = int(input())
    a=sys.stdin.readline().rstrip().split()
    if '0' in a:
        print(0)
        return
    ans=1
 
    for i in a:
        ans=ans*int(i)
 
    if ans>1000000000000000000:
        print("-1")
    else:
        print(ans)
main()

### FIXED CODE ###

import sys

def main():
    n = int(input())
    a=sys.stdin.readline().rstrip().split()
    if '0' in a:
        print(0)
        return
    ans=1
 
    for i in a:
        ans=ans*int(i)
        if ans>1000000000000000000:
            print("-1")
            return
    else:
        print(ans)
main()
### BUGGY CODE ###

a,b = map(int,input().split())
gcd = 1

i = 2
while True:
    c = i
    for i in range(c,min(a,b)+1):
        if a%i == 0 and b%i ==0:
            gcd *= i
            a = int(a/i)
            b = int(b/i)
            break
    else: break
print(gcd)
    

### FIXED CODE ###

def lcd(a,b): ##return least common multiple of a and b
    if a > b:
        return lcd(a-b,b)
    elif a < b:
        return lcd(b-a,a)
    elif a == b:
        return a

a,b = map(int,input().split())
print(lcd(a,b))
### BUGGY CODE ###

n, k = map(int, input().split())
netas_oishisas = []
for _ in range(n):
    netas_oishisas.append(tuple(map(int, input().split())))
netas_oishisas.sort(key = lambda no: no[1], reverse = True)
tabetaneta = []
second = []
greedyscore = 0
for i in range(k):
    neta, oishisa = netas_oishisas[i]
    if neta in tabetaneta:
        second.append(oishisa)
    else:
        tabetaneta.append(neta)
    greedyscore += oishisa
greedyscore += len(tabetaneta) ** 2
maxscore = greedyscore
currentscore = greedyscore
second.reverse()
secondpointer = 0
secondn = len(second)
for i in range(k, n):
    if secondpointer >= secondn:
        break
    neta, oishisa = netas_oishisas[i]
    if neta not in tabetaneta:
        currentscore = currentscore - second[secondpointer] + 2*len(tabetaneta) + 1 + oishisa
        maxscore = max(maxscore, currentscore)
        secondpointer += 1
        tabetaneta.append(neta)
print(maxscore)


### FIXED CODE ###

n, k = map(int, input().split())
netas_oishisas = []
for _ in range(n):
    netas_oishisas.append(tuple(map(int, input().split())))
netas_oishisas.sort(key = lambda no: no[1], reverse = True)
tabetaneta = set()
second = []
greedyscore = 0
for i in range(k):
    neta, oishisa = netas_oishisas[i]
    if neta in tabetaneta:
        second.append(oishisa)
    else:
        tabetaneta.add(neta)
    greedyscore += oishisa
greedyscore += len(tabetaneta) ** 2
maxscore = greedyscore
currentscore = greedyscore
second.reverse()
secondpointer = 0
secondn = len(second)
for i in range(k, n):
    if secondpointer >= secondn:
        break
    neta, oishisa = netas_oishisas[i]
    if neta not in tabetaneta:
        currentscore = currentscore - second[secondpointer] + 2*len(tabetaneta) + 1 + oishisa
        maxscore = max(maxscore, currentscore)
        secondpointer += 1
        tabetaneta.add(neta)
print(maxscore)
### BUGGY CODE ###

N, W = map(int, input().split())
items = []
for _ in range(N):
    items.append(tuple(map(int, input().split())))
dp = [[0 for j in range(W+1)] for i in range(N+1)]
for i in range(1, N+1):
    w, v = items[i-1]
    for j in range(W+1):
        if j - w >= 0:
            dp[i][j] = max(dp[i-1][j-w] + v, dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]
print(max(dp[N]))

### FIXED CODE ###

import numpy as np

N, W = map(int, input().split())
items = []
for _ in range(N):
    items.append(tuple(map(int, input().split())))
dp = np.array([[0 for j in range(W+1)] for _ in range(N+1)])
for i in range(1, N+1):
    w, v = items[i-1]
    dp[i, :w] = dp[i-1, :w]
    dp[i, w:] = np.maximum(dp[i-1, :-w] + v, dp[i-1, w:])
print(dp[N, W])