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

import sys
sys.setrecursionlimit(1000000000)

N = int(input())
S = input()
MOD = 10**9 + 7

def dp(i, a, used):
    if i == N-1:
        if S[i] in used:
            return a
        else:
            return 2*a
    else:
        if S[i] in used:
            return dp(i+1, a, used)
        else:
            return dp(i+1, a, used) + dp(i+1, a, used|set(S[i]))

print(dp(0, 1, set())-1)

### FIXED CODE ###

from collections import Counter

N = int(input())
S = input()
MOD = 10**9 + 7

c = Counter(S)
ans = 1

for v in c.values():
    ans *= v+1
    ans %= MOD

print((ans-1)%MOD)
### BUGGY CODE ###

from pprint import pprint
import queue

def solve(n, a, b):
    a_pq = queue.PriorityQueue()
    for i, a_i in enumerate(a):
        a_pq.put((a_i, i))
    b_pq = queue.PriorityQueue()
    for i, b_i in enumerate(b):
        b_pq.put((b_i, i))

    state = queue.Queue()
    state.put((0, b[:]))
    while not state.empty():
        count, b_tmp = state.get()
        b_tmp_pq = queue.PriorityQueue()
        for b_tmp_i in b_tmp:
            b_tmp_pq.put(b_tmp_i)
        # print("next:" + str(count))
        # pprint(b_tmp)
        while not b_tmp_pq.empty():
            b_i = b_tmp_pq.get()
            i_b = b_tmp.index(b_i)
            # print(i_b, b_i)
            i_a = (i_b - 1 + n) % n
            i_c = (i_b + 1) % n
            b_cand = b_i
            if b_cand - b_tmp[i_a] - b_tmp[i_c] < a[i_b]:
                continue

            while b_cand - b_tmp[i_a] - b_tmp[i_c] >= a[i_b]:
                b_cand = b_cand - b_tmp[i_a] - b_tmp[i_c]
                count += 1

            b_next = b_tmp[:]
            b_next[i_b] = b_cand
            if b_next == a:
                return count
            # print(count + 1)
            state.put((count, b_next))
    
    return -1


if __name__ == '__main__':

    n = int(input().strip())
    a = list(map(int, input().strip().split(" ")))
    b = list(map(int, input().strip().split(" ")))
    print(solve(n, a, b))

### FIXED CODE ###

from pprint import pprint
import heapq

def solve(n, a, b):
    b_pq = []
    b_rev = {}
    delete = []
    for i, b_i in enumerate(b):
        if b_i == a[i]:
            continue
        heapq.heappush(b_pq, (-1 * b_i, i))

    count = 0
    while b_pq:
        tmp = heapq.heappop(b_pq)
        # pprint(tmp)
        b_i = tmp[0] * -1
        i_b = tmp[1]
        # print(i_b, b_i)
        i_a = (i_b - 1 + n) % n
        i_c = (i_b + 1) % n
        b_cand = b_i
        if b_cand - b[i_a] - b[i_c] < a[i_b]:
            continue

        #while b_cand - b[i_a] - b[i_c] >= a[i_b]:
        #    b_cand = b_cand - b[i_a] - b[i_c]
        #    count += 1
        tmp_count =  (b_cand - a[i_b]) // (b[i_a] + b[i_c])
        b_cand -= (b[i_a] + b[i_c]) * tmp_count
        count += tmp_count

        b[i_b] = b_cand
        if b_cand != a[i_b]:
            heapq.heappush(b_pq, (-1 * b_cand, i_b))
        # print("count: ", count)
        # pprint(b)
         

        if b_cand == a[i_b] and b == a:
            return count
    
    return -1


if __name__ == '__main__':

    n = int(input().strip())
    a = list(map(int, input().strip().split(" ")))
    b = list(map(int, input().strip().split(" ")))
    print(solve(n, a, b))
### BUGGY CODE ###

N, M = list(map(int, input().split()))
a = [int(input()) for i in range(M)]

dp = [0, 1]

for i in range(1, N + 1):
    if i in a:
        dp.append(0)
        continue
    dp.append(dp[i - 1] + dp[i])

print(dp[N + 1] % 1000000007)


### FIXED CODE ###

N, M = list(map(int, input().split()))
a = [int(input()) for i in range(M)]
a.append(0)
dp = [0, 1]
a_flag = 0

for i in range(1, N + 1):
    if i == a[a_flag]:
        dp.append(0)
        a_flag += 1
        continue
    dp.append(dp[i - 1] + dp[i])

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

import sys,io,os
I = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
#I = input

n,m = map(int, I().split())
p=[-1]*(n+1)
s=[0]*(n+1)
S=n-1
def t(a):
	while p[a] != -1:
		a = p[a]
	return a
for _ in range(m):
	a,b=map(int, I().split())
	a,b = t(a), t(b)
	if a != b:
		S -= 1
		if s[a] > s[b]:
			a,b = b,a
		p[a] = b
		s[b] += s[a]
print(S)



### FIXED CODE ###

import sys,io,os
I = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
#I = input

n,m = map(int, I().split())
p=[-1]*(n+1)
s=[0]*(n+1)
S=n-1
def t(a):
	b = a
	while p[b] != -1:
		b = p[b]
	while p[a] != -1:
		p[a],a = b,p[a]
	return a
for _ in range(m):
	a,b=map(int, I().split())
	a,b = t(a), t(b)
	if a != b:
		S -= 1
		if s[a] > s[b]:
			a,b = b,a
		p[a] = b
		s[b] += s[a]
print(S)
### BUGGY CODE ###

def binary_search(cards,n,number):
    low=0
    high=len(cards)-1

    while high-low>1:
        mid=(low+high)//2
        base=cards[mid]
        if base==number:
            for i in range(n):
                cards.insert(mid,number)
            return cards
        if base<number:
            low=mid
        else:
            high=mid

    if cards[high]==cards[low]:
        if number>cards[high]:
            for i in range(n):
                cards.insert(high+1, number)
        else:
            for i in range(n):
                cards.insert(low, number)
    else:
        for i in range(n):
            cards.insert(high,number)
    return cards

#1 3 5 7 9 11 <=8
#1 3 [5] 7 9 11 <= 8
#1 3 (5) 7 9 (11) <=8
#1 3 5 [7] 9 11 <= 8
#1 3 5 (7) 9 (11) <= 8
#1 3 5 7 [9] 11 <= 8
#1 3 5 (7) (9) 11
#1 3 5 [7] 9 11 <=8
#1 3 5 (7)

def main():
    inp1=list(map(lambda x:int(x),input().split()))
    cards=list(map(lambda x:int(x),input().split()))
    N=inp1[0]
    M=inp1[1]
    B=[]
    C=[]
    for i in range(M):
        changes=list(map(lambda x:int(x),input().split()))
        B.append(changes[0])
        C.append(changes[1])

    cards=sorted(cards)

    for i in range(M):
        cards=binary_search(cards,B[i],C[i])

    cards=cards[len(cards)-N:len(cards)]

    print(sum(cards))

if __name__=="__main__":
    main()

### FIXED CODE ###

from heapq import heappush,heappop

def main():
    inp1=list(map(lambda x:int(x),input().split()))
    cards=list(map(lambda x:int(x),input().split()))
    cards_heap=[]
    for i in cards:
        heappush(cards_heap,i)

    N=inp1[0]
    M=inp1[1]
    B=[]
    C=[]
    for i in range(M):
        changes=list(map(lambda x:int(x),input().split()))
        B.append(changes[0])
        C.append(changes[1])

    cb=zip(C,B)
    cb=sorted(cb,reverse=True)


    for C,B in cb:
        for _ in range(B):
            a=heappop(cards_heap)
            if C>a:
                heappush(cards_heap,C)
            else:
                heappush(cards_heap,a)
                break

    print(sum(cards_heap))

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

import sys
sys.setrecursionlimit(10**5)

N = int(input())
*A, = map(int, input().split())
memo = [[-1]*(N+1) for i in range(N+1)]
for i in range(N+1):
    memo[i][i] = 0
def dfs(p, q, t):
    if memo[p][q] != -1:
        return memo[p][q]
    if t:
        r = min(dfs(p+1, q, 0) - A[p], dfs(p, q-1, 0) - A[q-1])
    else:
        r = max(dfs(p+1, q, 1) + A[p], dfs(p, q-1, 1) + A[q-1])
    memo[p][q] = r
    return r

print(dfs(0, N, 0))

### FIXED CODE ###

N = int(input())
*A, = map(int, input().split())
dp = [[-1]*(N+1-i) for i in range(N+1)]
for i in range(N+1):
    dp[0][i] = 0
t = (N & 1)
for l in range(1, N+1):
    S = dp[l-1]; T = dp[l]
    t ^= 1
    if t:
        T[:] = (min(S[i+1] - A[i], S[i] - A[i+l-1]) for i in range(N-l+1))
    else:
        T[:] = (max(S[i+1] + A[i], S[i] + A[i+l-1]) for i in range(N-l+1))
print(dp[N][0])
### BUGGY CODE ###

N = int(input())
S = input()
S = list(map(lambda x: 0 if x=="." else 1, S))
#all_white
# all_white = sum(S)
# all_black = len(S) - all_white

# white, black, white
ans_list = []
for thresh in range(len(S)+1):
    ans = sum(S[:thresh]) + (len(S[thresh:])-sum(S[thresh:]))
    ans_list.append(ans)
print(min(ans_list))

### FIXED CODE ###

N = int(input())
S = input()
S = list(map(lambda x: 0 if x=="." else 1, S))
#all_white
# all_white = sum(S)
# all_black = len(S) - all_white

# white, black, white
ans_list = []
for thresh in range(len(S)):        
    if thresh == 0:
        ans = len(S) - sum(S)
        ans_list.append(ans)
    
    else:
        ans = ans_list[-1]
        if S[thresh-1] == 1: 
            ans += 1
        else:
            ans -= 1
        ans_list.append(ans)
ans_list.append(sum(S))
        
print(min(ans_list))
### BUGGY CODE ###

import sys
import collections
import copy
def input(): return sys.stdin.readline().strip()
N = int(input())
sc = [[int(i) for i in input().split()] for i in range(N)]
count = [0] * N
done = [0] * N
fin = [N-1] * N
ans = 0
for j in range(N*(N-1)//2):
    done = [0] * N
    for i in range(N-1):
        if N-1 > count[i]:
            if done[sc[i][count[i]]-1] == 0 and done[i] == 0:
                if sc[sc[i][count[i]]-1][count[sc[i][count[i]]-1]] == i+1:
                    done[sc[i][count[i]]-1] = 1
                    done[i] = 1
                    count[sc[i][count[i]]-1] += 1
                    count[i] += 1
    if done == [0] * N:
        if count == fin:
            break
        else:
            ans = -1
            break
    ans += 1
print(ans)

### FIXED CODE ###

import sys
import collections
import copy
def input(): return sys.stdin.readline().strip()
N = int(input())
sc = [[int(i) for i in input().split()] for i in range(N)]
count = [0] * N
done = [0] * N
fin = [N-1] * N
ans = 0
chk = 0
for j in range(N*(N-1)//2):
    if j >= 4000:
        chk = 1
        break
    done = [0] * N
    for i in range(N-1):
        if N-1 > count[i]:
            if done[sc[i][count[i]]-1] == 0 and done[i] == 0:
                if sc[sc[i][count[i]]-1][count[sc[i][count[i]]-1]] == i+1:
                    done[sc[i][count[i]]-1] = 1
                    done[i] = 1
                    count[sc[i][count[i]]-1] += 1
                    count[i] += 1
    if done == [0] * N:
        if count == fin:
            break
        else:
            ans = -1
            break
    ans += 1
if chk == 0:
    print(ans)
else:
    print(N*(N-1)//2)
### BUGGY CODE ###

import sys
import bisect
input = sys.stdin.readline

def main():
    N = int(input())
    l = sorted(list(map(int, input().split())))

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            a = l[i]
            b = l[j]
            left = bisect.bisect_right(l, b - a)
            right = bisect.bisect_left(l, a + b)
            ans += max(0, right - 1 - max(left-1, j))
    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
import bisect
input = sys.stdin.readline

def main():
    N = int(input())
    l = sorted(list(map(int, input().split())))
    memo = [-1] * (l[-2] + l[-1] + 1)
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            a = l[i]
            b = l[j]
            if memo[a + b] == -1:
                right = bisect.bisect_left(l, a + b)
                memo[a + b] = right
            else:
                right = memo[a + b]
            ans += max(0, right - j - 1)
    print(ans)


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

n,k = map(int,input().split())
A=[*map(int,input().split())]
# print(n,k)
# print(A)
B = []
for i in range(k):
    B = [0]*n
    for j in range(n):
        d = A[j] # 強さ
        x = j + 1
        l = max(1, abs(x-d)) # 範囲
        r = min(n, abs(x+d)) # 範囲
        # print('x,l,r',x,l,r)
        for k in range(l-1,r): # (l,r)
            B[k] += 1
        # print('---')
    # print(B)
    A = B

print(*A, sep=' ')


### FIXED CODE ###

n,k = map(int,input().split())
A=[*map(int,input().split())]
for i in range(k):
    B = [0]*n
    for j in range(n):
        d = A[j] # 強さ
        l = max(0, j-d) # 範囲
        r = j+d+1 # 範囲
        B[l] += 1
        if r <= n-1: B[r] -= 1
    is_same = True
    for j in range(n-1):
        B[j+1] = B[j+1] + B[j]
        if B[j+1] != n: is_same = False
    # print(B)
    if is_same: break
    A = B
# print(B)
print(*B,sep=' ')
### BUGGY CODE ###

import numpy as np

n = int(input())
l = []
r = []
for i in range(n):
    li, ri = map(int, input().split())
    l.append(li)
    r.append(ri+1)

arglmax = l.index(max(l))
argrmin = r.index(min(r))
num = 0
for i in range(n):
    num = max(r[i] - l[i], num)
ans1 = num + max(0, r[argrmin]-l[arglmax])

lst = [l, r]
lst = list(np.array(lst).T)
lst = sorted(lst, key=lambda x: (x[0]), reverse=True)
lst = sorted(lst, key=lambda x: (x[1]))
lst = list(np.array(lst).T)
sorted_l = list(lst[0])
sorted_r = list(lst[1])

sorted_r_minus_lmax = list(np.array(sorted_r)-l[arglmax])
mini = sorted_r_minus_lmax[n-1]
for i in range(1, n):
    mini = min(mini, sorted_r_minus_lmax[n-1-i])
    sorted_r_minus_lmax[n-1-i] = mini

ans2 = 0
for i in range(n-1):
    ai = max(0, sorted_r_minus_lmax[i+1])
    bi = max(0, min(r[argrmin]-np.array(sorted_l[:i+1])))
    ans2 = max(ans2, ai+bi)

print(max(ans1, ans2))

### FIXED CODE ###

import numpy as np

n = int(input())
l = []
r = []
for i in range(n):
    li, ri = map(int, input().split())
    l.append(li)
    r.append(ri+1)

arglmax = l.index(max(l))
argrmin = r.index(min(r))
num = 0
for i in range(n):
    num = max(r[i] - l[i], num)
ans1 = num + max(0, r[argrmin]-l[arglmax])

lst = [l, r]
lst = list(np.array(lst).T)
lst = sorted(lst, key=lambda x: (x[0]), reverse=True)
lst = sorted(lst, key=lambda x: (x[1]))
lst = list(np.array(lst).T)
sorted_l = list(lst[0])
sorted_r = list(lst[1])

sorted_r_minus_lmax = list(np.array(sorted_r)-l[arglmax])
mini = sorted_r_minus_lmax[n-1]
for i in range(1, n):
    mini = min(mini, sorted_r_minus_lmax[n-1-i])
    sorted_r_minus_lmax[n-1-i] = mini
rmin_minus_sorted_l = list(r[argrmin]-np.array(sorted_l))
mini = rmin_minus_sorted_l[0]
for i in range(1, n):
    mini = min(mini, rmin_minus_sorted_l[i])
    rmin_minus_sorted_l[i] = mini

ans2 = 0
for i in range(n-1):
    ai = max(0, sorted_r_minus_lmax[i+1])
    bi = max(0, rmin_minus_sorted_l[i])
    ans2 = max(ans2, ai+bi)

print(max(ans1, ans2))
### BUGGY CODE ###

N = int(input())
A = input()
ans = 0
for i in range(1,N-1):
  for j in range(i+1,N):
    if A[i-1] != A[j-1]:
      for k in range(j+1 ,N+1):
        if A[i -1] != A[k-1] and A[j -1] != A[k-1] and j-i != k-j:
          ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
A = input()
ans = 0
R = 0
G = 0
B = 0
for i in A:
  if i == 'R':
    R += 1
  elif i == 'G':
    G += 1
  elif i == 'B':
    B += 1
ans = R*G*B
for i in range(0,N-2):
  for j in range(i+1,N-1):
    k = 2*j -i
    if k < N:
      if A[i] != A[j] and A[j] != A[k] and A[k] != A[i]:
        ans -= 1
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from bisect import bisect_left

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
L = 30
ans = 0
for l in range(L):
    P = []
    g = 1<<l
    P1 = []
    P2 = []
    for b in B:
        if b&g:
            P1.append(b)
        else:
            P2.append(b)
    B = P2 + P1
    P = []
    for b in B:
        P.append(b%(2*g))
    count = 0
    for a in A:
        count += (bisect_left(P, (2*g-a)%(2*g)) - bisect_left(P, (g-a)%(2*g)))%N
    if count%2 == 1:
        ans += g
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
from bisect import bisect_left

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


L = 30
ans = 0
for l in range(L):
    P = []
    g = 1<<l
    g2 = 1<<(1+l)
    B1 = []
    B2 = []
    for b in B:
        if b&g:
            B1.append(b)
        else:
            B2.append(b)
    B = B2 + B1

    A1 = []
    A2 = []
    for a in A:
        if a&g:
            A1.append(a)
        else:
            A2.append(a)
    A = A1 + A2

    count = 0
    ind1 = 0
    ind2 = 0
    ind3 = 0
    for a in A:
        while ind1 < N and B[ind1]%g2 + a%g2 < g:
            ind1 += 1
        while ind2 < N and B[ind2]%g2 + a%g2 < 2*g:
            ind2 += 1
        while ind3 < N and B[ind3]%g2 + a%g2 < 3*g:
            ind3 += 1
        count += ind2 - ind1 + N - ind3
    if count%2 == 1:
        ans += g
print(ans)
### BUGGY CODE ###

from collections import deque
n,m = map(int,input().split())

maze = [list(input()) for _ in range(n)]

def bfs():
    dx = (1, 0, -1, 0)
    dy = (0, 1, 0, -1)
    d = [([-1]*m)for _ in range(n)]
    q = deque([])
    for i in range(n):
        for j in range(m):
            if maze[i][j] == "#":
                d[i][j] = 0
                q.append((i,j))


    while q:
        x,y = q.popleft()
        if -1 in sum(d,[]):
            for i in range(4):
                nx = x + dx[i]
                ny = y + dy[i]
                if 0<= nx < n and 0<= ny < m and maze[nx][ny] != '#' and d[nx][ny] == -1:
                    q.append((nx,ny))
                    d[nx][ny] = d[x][y] +1
    return max(sum(d,[]))

print(bfs())

### FIXED CODE ###

from collections import deque
n,m = map(int,input().split())

maze = [list(input()) for _ in range(n)]

def bfs():
    dx = (1, 0, -1, 0)
    dy = (0, 1, 0, -1)
    d = [([-1]*m)for _ in range(n)]
    q = deque([])
    for i in range(n):
        for j in range(m):
            if maze[i][j] == "#":
                d[i][j] = 0
                q.append((i,j))
    a = 0

    while q:
        x,y = q.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if 0<= nx < n and 0<= ny < m and maze[nx][ny] != '#' and d[nx][ny] == -1:
                q.append((nx,ny))
                d[nx][ny] = d[x][y] +1
                a = max(a,d[nx][ny])
    return a

print(bfs())
### BUGGY CODE ###

n,k=map(int,input().split())
arr=list(map(int,input().split()))
for i in range(n):
  arr[i]-=1
flag=format(k,'b')
flag=flag[::-1]
pos=0
for i in range(len(flag)):
  if flag[i]=='1':
    pos=arr[pos]
  tmp=[]
  for j in range(n):
    tmp.append(arr[arr[j]])
  arr=tmp
print(pos+1)

### FIXED CODE ###

n,k=map(int,input().split())
arr=list(map(int,input().split()))
for i in range(n):
  arr[i]-=1
flag=format(k,'b')
flag=flag[::-1]
pos=0
for i in range(len(flag)):
  if flag[i]=='1':
    pos=arr[pos]
  tmp=[]
  for j in range(n):
    tmp.append(arr[arr[j]])
  arr=tmp
print(pos+1)
### BUGGY CODE ###

mod =1000000007
n = int(input())
a = list(map(int, input().split()))
a.sort()
sumpro = 0

for i in range(n-1):
    for j in range(i+1, n):
            sumpro += (a[i]*a[j])%mod
            
print(sumpro%mod)

### FIXED CODE ###

MOD = 10 ** 9 + 7  # MODは変数に入れてしまったほうが打ち間違えなくていいです

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

S = sum(A) % MOD
ans = 0

# A_Nも含まれてしまいますが、そのときはs=0なので問題ありません
for x in A:
    S -= x  # 自分と自分自身を掛けないように、先に引く必要があります
    S %= MOD  # MODはいちいち取っておくといいです
    ans += S * x
    ans %= MOD

ans %= MOD  # この行は完全に不要ですが、最後だけMODを取り忘れてWAになるミスは非常によくあるので、必要以上に取っておくと安心できます
print(ans)
### BUGGY CODE ###

s=[int(j) for j in input()][::-1]
m=len(s)
from collections import Counter
c=Counter()
tmp=0
c[0]+=1
t=1
for i in range(m):
    tmp+=t*s[i]
    c[tmp%2019]+=1
    t*=10
ll=c.most_common()
ans=0
for i,j in ll:
    if j>=2:
        ans+=j*(j-1)//2
    else:
        break
print(ans)


### FIXED CODE ###

s=[int(j) for j in input()][::-1]
c=[0]*2019
tmp=0
c[0]+=1
t=1
import numpy as np
for i in s:
    tmp+=t*i
    c[tmp%2019]+=1
    t=t*10%2019
c=np.array(c)
ans=c*(c-1)//2
print(ans.sum())
### BUGGY CODE ###

n=int(input())
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd,numbers)
count=0
a=1
b=1
c=1
for i in range(n):
    for j in range(n):
        for m in range(n):
            count+=gcd(a,b,c)
            c+=1
        c=1
        b+=1
    b=1
    a+=1
print(count)

### FIXED CODE ###

n=int(input())
import math
count=0
a=1
b=1
c=1
for i in range(n):
    for j in range(n):
        for m in range(n):
            k=math.gcd(a,b)
            l=math.gcd(k,c)
            count+=l
            c+=1
        c=1
        b+=1
    b=1
    a+=1
print(count)
### BUGGY CODE ###

N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        direct = A[i][j]
        for k in range(N):
            if k == i or k == j:
                continue
            ind = A[i][k] + A[k][j]
            if direct > ind:
                print(-1)
                exit()
            elif direct == ind:
                break
        else:
            ans += direct
print(ans)

### FIXED CODE ###

N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        direct = A[i][j]
        for k in range(N):
            if k == i or k == j:
                continue
            ind = A[i][k] + A[k][j]
            if direct > ind:
                print(-1)
                exit()
            elif direct == ind:
                break
        else:
            ans += direct
print(ans)
### BUGGY CODE ###

N = int(input())
A = [int(x) for x in input().split()]

M = 1
for a in A:
    if a == 0:
        M = 0
        break
    M *= a

if M > 1000000000000000000:
    M = -1

print(M)

### FIXED CODE ###

N = int(input())
#A = [int(x) for x in input().split()]
A = input().split()

M = 1
if '0' in A:
    M = 0
else:
    for a in A:
        a = int(a)
        M *= a
        if M > 1000000000000000000:
            M = -1
            break

print(M)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
k = max(A)
l = []
while k >= min(A):
  if len(l)>=2:
    break
  if A.count(k)>=4:
    l.append(k)
    l.append(k)
  elif A.count(k)>=2:
    l.append(k)
  k += -1
if len(l)<= 1:
  print(0)
else:
  print(l[0]*l[1])

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
dic={}
mx=[0,0]
for x in a:
    if x in dic:
        dic[x]+=1
    else:
        dic[x]=1
    if dic[x]==2:
        dic[x]=0
        for i in range(2):
            mx.sort()
            if mx[i]<x:
                mx[i]=x
                break
print(mx[0]*mx[1])