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

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

if 0 in l:
    a = 0
    
print(a)
    

### FIXED CODE ###

def main():
    n = int(input())
    a = list(map(int,input().split()))
    
    if 0 in a:
        print(0)
        return
    
    prod = 1
    for i in a:
        prod *= i
        if prod > 10 ** 18:
            print(-1)
            return
    
    print(prod)
    
    return

main()
### BUGGY CODE ###

import itertools, math, collections, sys
input = sys.stdin.readline
H, W, K = [int(_) for _ in input().split()]
A = [input() for _ in range(H)]
for i, j in itertools.product(range(H), range(W)):
    if A[i][j] == 'S':
        break
visited = [[False] * W for _ in range(H)]
ans = min([i, H - 1 - i, j, W - 1 - j])
Q = collections.deque([[i, j, K]])
while Q:
    h, w, res = Q.popleft()
    visited[h][w] = True
    ans = min([ans, h, H - 1 - h, w, W - 1 - w])
    if res:
        res -= 1
        if h and A[h - 1][w] == '.':
            Q += [[h - 1, w, res]]
        if h < H - 1 and A[h + 1][w] == '.':
            Q += [[h + 1, w, res]]
        if w and A[h][w - 1] == '.':
            Q += [[h, w - 1, res]]
        if w < W - 1 and A[h][w + 1] == '.':
            Q += [[h, w + 1, res]]
print(1 + math.ceil(ans / K))


### FIXED CODE ###

import itertools, math, collections, sys
input = sys.stdin.readline
H, W, K = [int(_) for _ in input().split()]
A = [input() for _ in range(H)]
for h in range(H):
    if 'S' in A[h]:
        w = A[h].index('S')
        break
visited = [[False] * W for _ in range(H)]
ans = min([h, H - 1 - h, w, W - 1 - w])
res = K - 1
Q = collections.deque([[h - 1, w, res], [h + 1, w, res], [h, w - 1, res],
                       [h, w + 1, res]])
while Q:
    h, w, res = Q.popleft()
    if 0 <= h < H and 0 <= w < W and A[h][w] == '.' and not visited[h][w]:
        visited[h][w] = True
        ans = min([ans, h, H - 1 - h, w, W - 1 - w])
        if res:
            res -= 1
            Q += [[h - 1, w, res], [h + 1, w, res], [h, w - 1, res],
                  [h, w + 1, res]]
print(1 + math.ceil(ans / K))
### BUGGY CODE ###

n,k=map(int,input().split())
l=[int(x) for x in input().split()]
dp=[0]*n
dp[0]=0
for i in range(1,n):
    m=10**20
    if i-k<=0:
        for j in range(i):
            t=dp[j]+abs(l[i]-l[j])
            m=min(t,m)
    else:
        for j in range(i-1,i-k-1,-1):
            t=dp[j]+abs(l[i]-l[j])
            m=min(t,m)
    dp[i]=m
print(dp[n-1])

### FIXED CODE ###

n,k=map(int,input().split())
l=[int(x) for x in input().split()]
dp=[0]*n
dp[0]=0
for i in range(1,n):
    m=10**20
    if i-k<=0:
        for j in range(i):
            t=dp[j]+abs(l[i]-l[j])
            m=min(t,m)
    else:
        for j in range(i-1,i-k-1,-1):
            t=dp[j]+abs(l[i]-l[j])
            m=min(t,m)
    dp[i]=m
print(dp[n-1])
### BUGGY CODE ###

n = int(input())
a = [int(x) for x in input().split()]
for i in range(n):
    a[i] -= i+1

def hoge(b):
    t = [abs(x-b) for x in a]
    return sum(t)

tmp = float('inf')
for x in a:
    if hoge(x) < tmp:
        tmp = hoge(x)

print(tmp)

### FIXED CODE ###

n = int(input())
a = [int(x) for x in input().split()]
for i in range(n):
    a[i] -= i+1

#中央値を求める
a.sort()
if len(a) % 2 == 0:
    c = (a[len(a)//2] + a[len(a)//2-1]) // 2
else:
    c = a[len(a)//2]

def hoge(b):
    v = 0
    for x in a:
        v += abs(x-b)
    return v

print(hoge(c))
### BUGGY CODE ###

import sys
n,m = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(m)]
start = a[0][0]
goal = n
tmp,ans = [],[]
for i in range(m):
	if a[i][1] == goal:
		tmp.append(a[i][0])
#print(tmp)
for j in range(m):
		if a[j][0] == start:
			if a[j][1] in tmp:
				print('POSSIBLE')
				sys.exit()
print('IMPOSSIBLE')


### FIXED CODE ###

import sys
n,m = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(m)]
start = a[0][0]
goal = n
tmp,ans = [],[]
for i in range(m):
	if a[i][1] == goal:
		tmp.append(a[i][0])
#print(tmp)
for j in range(m):
		if a[j][0] == start:
			ans.append(a[j][1])
if len(set(tmp)&set(ans)) > 0:
	print('POSSIBLE')
	sys.exit()
print('IMPOSSIBLE')
### BUGGY CODE ###

K, S = map(int, input().split())
count = 0

for x in range(0, K+1):
    for y in range(0, K+1):
        z = S-x-y
        if x + y + z == S and 0 <= z <= K:
            count += 1

print(count)


### FIXED CODE ###

K, S = map(int, input().split())
count = 0

for x in range(0, K+1):
    for y in range(0, K+1):
        z = S-x-y
        if 0 <= z <= K:
            count += 1
print(count)
### BUGGY CODE ###

# coding: utf-8
import numpy as np

n = int(input())
numlist = list(map(int, input().split()))
ans = 1;

for i in numlist:
    ans *= i
if ans > 10**18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

# coding: utf-8
import numpy as np
 
n = int(input())
numlist = list(map(int, input().split()))
ans = 1;

if 0 in numlist:
    ans = 0
else:
    for i in numlist:
        ans *= i
        if ans > 10**18:
            ans = -1
            break
 
print(ans)
### BUGGY CODE ###

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

def is_dislike_number(number, dislike_list):
  if number in dislike_list:
    return True
  else:
    return False

while True:
  for i, num in enumerate(str(n)):
    num = int(num)
    if is_dislike_number(num, d_list):
      n += 1
      break
  print(n)


### FIXED CODE ###

N,K=map(int,input().split())
D=list(map(int,input().split()))
def solve():
  for i in range(10*N+2):
    if i>=N:
      s=str(i)
      for j in range(len(s)):
        if int(s[j]) in D: break
      else:
        print(i)
        return 0
 
solve()
### BUGGY CODE ###

from collections import defaultdict
import sys

sys.setrecursionlimit(10**9)

N, Q = map(int, input().split())
G = defaultdict(list)
for i in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1  # 0-indexed
    G[a].append(b)
    G[b].append(a)

# print('G', G)

V = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    p = p - 1  # 0-indexed
    V[p] += x


def dfs(v, p):
    if p != -1:
        V[v] += V[p]
    for idx in G[v]:
        if idx == p:
            continue
        dfs(idx, v)


dfs(0, -1)

# print('V', V)

for v in V:
    print(v)


### FIXED CODE ###

from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

N, Q = map(int, input().split())
G = defaultdict(list)
for i in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1  # 0-indexed
    G[a].append(b)
    G[b].append(a)

# print('G', G)

V = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    p = p - 1  # 0-indexed
    V[p] += x


def dfs(v, p):
    if p != -1:
        V[v] += V[p]
    for idx in G[v]:
        if idx == p:
            continue
        dfs(idx, v)


dfs(0, -1)

# print('V', V)

print(' '.join(map(str, V)))
### BUGGY CODE ###

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    u = 2 *  A[0]
    l = 0
    k = []
    while True:
        m = (u + l)//2
        t = 0
        s = N
        p = 0
        for i in range(N):
            for j in reversed(range(s)):
                if A[i] + A[j] >= m:
                    if A[i] + A[j] == m:
                        p += 1
                    k.append(j)
                    t += j+1
                    s = j+1
                    break
        if t >= M and t - p <= M:
            break
        elif t > M:
            l = m + 1
        else:
            u = m - 1
        k = []
    r = 0   
    s = N
    B = []
    tmp = 0
    for i in A:
        tmp += i
        B.append(tmp)
    for i in range(len(k)):
        r += (k[i]+1) * A[i] + B[k[i]]
    return r - (t - M) * m
    
print(main())
    


### FIXED CODE ###

import bisect
def judge(k, N, A):
    t = 0
    for i in A:
        j = bisect.bisect_left(A, k - i)
        t += N - j
    return t
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    t = A[-1] * 2
    b = 0
    X = None
    while t - b > 1:
        m = (t + b)//2
        i = judge(m, N, A)
        if i == M:
            X = m
            break
        if i > M:
            ip = judge(m + 1, N, A)
            if ip == M:
                X = m + 1
                break
            if ip < M:
                X = m
                break
            b = m + 1
        if i < M:
            im = judge(m - 1, N, A)
            if im >= M:
                X = m - 1
                break
            t = m - 1
    if X is None:
        X = b
    B = []
    tmp = 0
    for i in reversed(range(N)):
        tmp += A[i]
        B.append(tmp)
    B.reverse()
    r = 0
    tot = 0
    for i in reversed(range(N)):
        j = bisect.bisect_left(A, X - A[i])
        tot += N - j
        if j == N:
            break
        r += A[i] * (N - j) + B[j]
    return r - (tot - M) * X
print(main())
### BUGGY CODE ###

def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))

s = rls()
a = 0
z = 0
for i in range(len(s)):
    if(s[i] == "A"):
        a = i
        break
for i in range(len(s[::-1])):
    if(s[::-1][i] == "Z"):
        z = len(s) - i
        break
print(z-a)

### FIXED CODE ###

def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))

s = rls()
t = s[::-1]
a = 0
z = 0
for i in range(len(s)):
    if(s[i] == "A"):
        a = i
        break
for i in range(len(t)):
    if(t[i] == "Z"):
        z = len(s) - i
        break
print(z-a)
### BUGGY CODE ###

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

m = {}
for i in a:
    if i in m.keys():
        m[i] = m[i] + 1
    else:
        m[i] = 1

for i in range(q):
    b, c = map(int,input().split())
    if b in m.keys():
        if c in m.keys():
            m[c] = m[c] + m[b]
        else:
            m[c] = m[b]
        m.pop(b)
    ans = 0
    for k in m:
        ans += m[k] * k
    print(ans)


### FIXED CODE ###

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

m = {}
for i in a:
    if i in m.keys():
        m[i] = m[i] + 1
    else:
        m[i] = 1

ans = 0
for k in m:
    ans += m[k] * k

for i in range(q):
    b, c = map(int,input().split())
    if b in m.keys():
        t = 0
        if c in m.keys():
            t = m[c] * c
            m[c] = m[c] + m[b]
        else:
            m[c] = m[b]
        ans += m[c] * c - m[b] * b - t
        m.pop(b)
    print(ans)
### BUGGY CODE ###

import math
import sys
input = sys.stdin.readline
def main():
	H,N = map(int,input().split())
	A,B = [],[]
	ap = A.append
	bp = B.append
	for _ in range(N):
		a,b = map(int,input().split())
		ap(a)
		bp(b)
	
	dp = [[0 for _ in range(H+1)] for _ in range(N)]
	
	for i in range(1,H+1):
		dp[0][i] = math.ceil(i/A[0])*B[0]

	for i in range(1,N):
		for j in range(1,H+1):
			if j<=A[i]:
				dp[i][j] = min(dp[i-1][j],B[i])
			else:
				dp[i][j] = min([dp[i-1][j],dp[i-1][j-A[i]]+B[i],
										   dp[i][j-A[i]]+B[i]])

	print(dp[N-1][H])
if __name__ == '__main__':
	main()

### FIXED CODE ###

import math
import sys
input = sys.stdin.readline
def main():
	H,N = map(int,input().split())
	A,B = [],[]
	ap = A.append
	bp = B.append
	for _ in range(N):
		a,b = map(int,input().split())
		ap(a)
		bp(b)
	
	dp = [[0 for _ in range(H+1)] for _ in range(N)]
	
	for i in range(1,H+1):
		dp[0][i] = math.ceil(i/A[0])*B[0]

	for i in range(1,N):
		for j in range(1,H+1):
			if j<=A[i]:
				dp[i][j] = min(dp[i-1][j],B[i])
			else:
				dp[i][j] = min(dp[i-1][j],dp[i][j-A[i]]+B[i])

	print(dp[N-1][H])
if __name__ == '__main__':
	main()
### BUGGY CODE ###

N = int(input())
arr = list(input())
a = 0
b = 0
c = 0
count = 0
for i in range(N - 2):
  for j in range(i + 1, N - 1):
    if arr[i] != arr[j]:
      for k in range(j + 1, N):
        if j - i != k - j:
          a = k
          b = j 
          c = i
          if arr[a] == arr[b] or arr[c] == arr[b] or arr[a] == arr[c]:
            continue
          else:
            count += 1
print(count)

### FIXED CODE ###

N = int(input())
arr = list(input())
a = arr.count("R")
b = arr.count("G")
c = arr.count("B")
count = a * b * c

for i in range(N - 2):
  for j in range(i + 1, N - 1):
    k = i + (j - i) * 2
    if k < N and arr[i] != arr[j] and arr[j] != arr[k] and arr[k] != arr[i]:
      count -= 1
print(count)
### BUGGY CODE ###

# 初期入力
N=int(input())
S = [list(map(int, input().split())) for i in range(N)]

#町のいく順番　順列
from itertools import permutations
import math
from statistics import mean
junban=[]
for t in permutations(range(N)):
    if t[::-1] not in junban:
        junban.append(t)
#junban =[ t for t in permutations(range(N)) ]
#junban =junban_2[:len(junban_2)//2] # 逆順は考えなくていい
j_len =len(junban) # 順番の要素数
x =[] #距離
x_sum =[]

def kyori(a,b): 
    return math.sqrt(pow( S[a][0]-S[b][0],2) + pow( S[a][1] - S[b][1],2) )

# 各点の距離　　組み合わせ
from itertools import combinations
kumiawase = [t for t in combinations(range(N), 2)]
kyori_all ={i:kyori(i[0],i[1]) for i in kumiawase}

#
for i in junban:
    for ji,jv in enumerate(i[:-1]):
        if i[ji]<i[ji+1]:
            x.append(kyori_all[ i[ji],i[ji+1] ] )
        if i[ji+1]<i[ji]:
            x.append(kyori_all[ i[ji+1],i[ji] ] )

    y =sum(x)    
    x_sum.append(y)
    x.clear()
kotae =mean(x_sum) 

print(kotae)

### FIXED CODE ###

# 初期入力
N=int(input())
S = [list(map(int, input().split())) for i in range(N)]

#町のいく順番　順列
from itertools import permutations
import math
from statistics import mean
junban =[ t for t in permutations(range(N)) ]
#junban =junban_2[:len(junban_2)//2] # 逆順は考えなくていい
j_len =len(junban) # 順番の要素数
x =[] #距離
x_sum =[]
def kyori(a,b): 
    return math.sqrt(pow( S[a][0]-S[b][0],2) + pow( S[a][1] - S[b][1],2) )

# 各点の距離　　組み合わせ
from itertools import combinations
kumiawase = [t for t in combinations(range(N), 2)]
kyori_all ={i:kyori(i[0],i[1]) for i in kumiawase}

#
for i in junban:
    for ji,jv in enumerate(i[:-1]):
        if i[ji]<i[ji+1]:
            x.append(kyori_all[ i[ji],i[ji+1] ] )
        if i[ji+1]<i[ji]:
            x.append(kyori_all[ i[ji+1],i[ji] ] )

    y =sum(x)    
    x_sum.append(y)
    x.clear()
kotae =mean(x_sum) 

print(kotae)
### BUGGY CODE ###

import fractions
A,B=map(int,input().split())

gcd=fractions.gcd(A,B)
count=1

for i in range(2,gcd+1):
    if gcd!=1:
        if gcd%i==0:
            #print(gcd)
            count+=1
            #print(i)
            while gcd%i==0:
                gcd//=i
    else:
        break
print(count)
    

### FIXED CODE ###

import fractions
A,B=map(int,input().split())

base=fractions.gcd(A,B)
count=1


for i in range(2,int(pow(base,1/2)+1)):
    if base==1:
        break
    else:
        if base%i==0:
            count+=1
            while base%i==0:
                base//=i
if base!=1:
    count+=1
print(count)
### BUGGY CODE ###

n=int(input())
a=[int(input()) for _ in range(5)]
num=[n,0,0,0,0,0]
cnt=0
while num[5]<n:
    for i in range(4,-1,-1):
        move=min(num[i],a[i])
        num[i+1]+=move
        num[i]-=move
    cnt+=1
print(cnt)


### FIXED CODE ###

import math
n=int(input())
a=[int(input()) for _ in range(5)]
print(math.ceil(n/min(a))+4)
### BUGGY CODE ###

n = int(input())
L = list(map(int, input().split()))
L.sort()

cnt = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        for c in range(b+1, n):
            if L[c]>=L[a]+L[b]:
                break
            else:
                cnt += 1
print(cnt)

### FIXED CODE ###

from bisect import bisect_left
n = int(input())
L = list(map(int, input().split()))
L.sort()

cnt = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        cnt += bisect_left(L,L[a]+L[b])-(b+1)
print(cnt)
### BUGGY CODE ###

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

def sim(a):
    b = [0]*n
    for i in range(n):
        l = max(0,i-a[i])
        r = min(n-1,i+a[i])
        b[l] +=1
        if r+1<n:
            b[r+1] -= 1
    for i in range(1,n):
        b[i] += b[i-1]
    return b

for i in range(min(k,41)):
    a = copy.copy(sim(a))
print(*a)


### FIXED CODE ###

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

def sim(a):
    b = [0]*n
    for i in range(n):
        l = max(0,i-a[i])
        r = min(n-1,i+a[i])
        b[l] +=1
        if r+1<n:
            b[r+1] -= 1
    for i in range(1,n):
        b[i] += b[i-1]
    return b

for i in range(min(k,41)):
    a = copy.copy(sim(a))
print(*a)
### BUGGY CODE ###

#E
N,P=map(int,input().split())
S=input()
ans=0
if P in (2,5):
    for i,s in enumerate(S):
        if int(s)%P==0:
            ans+=i+1
else:
    cnt=[0 for _ in range(P)]
    CS=0
    for i,s in enumerate(S[::-1]):
        tmp=(int(s)*(10**i))%P
        CS=(CS+tmp)%P
        cnt[CS]+=1
        # print(CS)
        # print(cnt)
    for c in cnt:
        ans+=c*(c-1)//2
    ans+=cnt[0]
print(ans)

### FIXED CODE ###

#E
N,P=map(int,input().split())
S=input()
ans=0
if P in (2,5):
    for i,s in enumerate(S):
        if int(s)%P==0:
            ans+=i+1
else:
    cnt=[0 for _ in range(P)]
    CS=0
    PLC=1
    for s in S[::-1]:
        tmp=(int(s)*PLC)%P
        CS=(CS+tmp)%P
        cnt[CS]+=1
        PLC=(PLC*10)%P
        # print(CS)
        # print(cnt)
    for c in cnt:
        ans+=c*(c-1)//2
    ans+=cnt[0]
print(ans)
### BUGGY CODE ###

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

l.sort()
cnt=0
for ind_a,a in enumerate(l[:-2]):
    for ind_b,b in enumerate(l[ind_a+1:-1]):
        for ind_c,c in enumerate(l[ind_a+ind_b+2:]):
            #print(a,b,c)
            if a+b<=c:
                cnt+=ind_c
                break
        if a+b>c:
            cnt+=ind_c+1

print(cnt)


### FIXED CODE ###

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

l.sort()
l.append(10**9)
cnt=0
i=0
#print(l)

while i<n-2:
    j=i+1
    while j<n-1:
        LL=j+1
        RR=n-1
        #print("#",l[i],l[j],l[LL],l[RR])
        while LL<=RR:
            k=(LL+RR)//2
            if k==n:
                break
            #print(l)
            #print(i,j,LL,RR,k)
            #print(l[i]+l[j],l[k],l[k+1])
            if l[i]+l[j]>l[k] and l[i]+l[j]<=l[k+1]:
                cnt+=k-j
                break
            elif LL==RR:
                break
            elif l[i]+l[j]<=l[k]:
                RR=k
            elif l[i]+l[j]>l[k]:
                LL=k+1
            elif l[i]+l[j]<l[k] and k==j+1:
                break
        j+=1
    i+=1

print(cnt)
### BUGGY CODE ###

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

import math

divisor=[]
for i in range(1, M+1):
    if M%i==0:
        divisor.append(i)
#print(divisor)

divisor=list(reversed(divisor))
for val in divisor:
    if M//val>=N:
        print(val)
        break

### FIXED CODE ###

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

import math

divisor=[]
for i in range(1, math.ceil(math.sqrt(M))+1):
    if M%i==0:
        divisor.append(i)
#print(divisor)

divisor+=[M//val for val in reversed(divisor)]
#print(divisor)
for val in divisor:
    if val>=N:
        print(M//val)
        break
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int):
    for i in range(1, 3501):
        for j in range(i, 3501):
            # dN, di, dj = Decimal(N), Decimal(i), Decimal(j)
            if (4*i*j - N*j - N*i) == 0:
                continue
            h, r = divmod((N*i*j), 4*i*j - N*j - N*i)
            if r == 0 and 0 <= h:
                print(h, i, j)
                exit()
            

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    solve(N)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int):
    for i in range(1, 3501):
        for j in range(i, 3501):
            z = 4*i*j - N*(j+i)
            if z > 0:
                h, r = divmod((N*i*j), z)
                if r == 0:
                    print(h, i, j)
                    exit()
            

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    solve(N)

if __name__ == '__main__':
    main()


# #!/usr/bin/env python3
# n = int(input())
# for i in range(1, 3501):
#   for j in range(1, 3501):
#     seed = 4 * i * j - n * (i + j) 
#     if seed > 0:
#       k, mod = divmod(n * i * j, seed) 
#       if mod == 0:
#         print(i, j, k)
#         exit()
### BUGGY CODE ###

n=int(input())
a=[]
count=0
for i in range(n):
    d=input()
    d="".join(sorted(d))
    count+=a.count(d)
    a.append(d)
print(count)

### FIXED CODE ###

from collections import Counter
n=int(input())
d=Counter()
ans=0
for i in range(n):
    t=str("".join(sorted(input())))
    if t in d:
        ans+=d[t]
    d[t]+=1
print(ans)
### BUGGY CODE ###

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

cnt = 0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if x + y + z == S:
                cnt += 1
print(cnt)

### FIXED CODE ###

k, s = map(int, input().split())
count = 0
for x in range(k + 1):
    for y in range(k + 1):
        z = s - x - y
        if 0 <= z <= k:
            count += 1
print(count)
### BUGGY CODE ###

N = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

L = [N,0,0,0,0,0]

time = 0
while L != [0,0,0,0,0,N]:
  if L[4] > e:
    L[5] = L[5] + e
    L[4] = L[4] - e
  else:
    L[5] = L[5] + L[4]
    L[4] = 0
  if L[3] > d:
    L[4] = L[4] + d
    L[3] = L[3] - d
  else:
    L[4] = L[4] + L[3]
    L[3] = 0
  if L[2] > c:
    L[3] = L[3] + c
    L[2] = L[2] - c
  else:
    L[3] = L[3] + L[2]
    L[2] = 0
  if L[1] > b:
    L[2] = L[2] + b
    L[1] = L[1] - b
  else:
    L[2] = L[2] + L[1]
    L[1] = 0
  if L[0] > a:
    L[1] = L[1] + a
    L[0] = L[0] - a
  else:
    L[1] = L[1] + L[0]
    L[0] = 0
  time = time + 1
  
print(time)

### FIXED CODE ###

N = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
if min(a,b,c,d,e) == a:
  if N % a == 0:
    print(N//a + 4)
  else:
    print(N//a + 5)
elif min(b,c,d,e) == b:
  if N % b == 0:
    print(N//b + 4)
  else:
    print(N//b + 5)
elif min(c,d,e) == c:
  if N % c == 0:
    print(N//c + 4)
  else:
    print(N//c + 5)
elif min(d,e) == d:
  if N % d == 0:
    print(N//d + 4)
  else:
    print(N//d + 5)
else:
  if N % e == 0:
    print(N//e + 4)
  else:
    print(N//e + 5)
### BUGGY CODE ###

(N, W), *D = [list(map(int, o.split())) for o in open(0)]
w, v = 0, 1
dp = [[0]*-~W for _ in [0]*-~N]
for i in range(N):
  for j in range(W + 1):
    dp[i + 1][j] = max(dp[i][j], (dp[i][j - D[i][w]] + D[i][v])*(j >= D[i][w]))
print(dp[N][W])

### FIXED CODE ###

(N, W), *D = [list(map(int, o.split())) for o in open(0)]
w, v = 0, 1
dp = [[0]*-~W for _ in [0]*-~N]
for i in range(N):
  for j in range(W + 1):
    dp[i + 1][j] = max(dp[i][j], (dp[i][j - D[i][w]] + D[i][v])*(j >= D[i][w]))
print(dp[N][W])