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

from bisect import bisect_left
from collections import deque
from itertools import islice


N, M = list(map(int, input().split()))
As = list(map(int, input().split()))
cards = {}
for i in range(N):
    cards[As[i]] = cards.get(As[i], 0) + 1
# sorted_keys = deque(sorted(cards.keys()))
sorted_keys = list(sorted(cards.keys()))

for i in range(M):
    b, c = list(map(int, input().split()))
    cnt = 0
    # for k in islice(sorted_keys,0,bisect_left(sorted_keys, c)):
    for k in sorted_keys[0:bisect_left(sorted_keys, c)]:
        for _ in range(cards.get(k,0)):
            cards[k] = cards[k] - 1
            if cards[k] == 0:
                del(cards[k])
                sorted_keys.remove(k)
            cards[c] = cards.get(c, 0) + 1
            if c not in sorted_keys:
                sorted_keys.insert(bisect_left(sorted_keys, c),c )
            cnt += 1
            if cnt >= b:
                break
        if cnt >= b:
            break

print(sum([k * cnt for k,cnt in cards.items()]))




### FIXED CODE ###

N, M  = map(int,input().split())
As = sorted(list(map(int,input().split())))
di = {}
for i in range(M):
    b, c = map(int,input().split())
    di[c] = di.get(c, 0) + b

keys = list(sorted(di.keys(), reverse=True))
ichi = 0
for i in range(N):
    try:
        if keys[ichi] > As[i]:
            As[i] = keys[ichi]
            di[keys[ichi]] -= 1
        else:
            break
        if di[keys[ichi]] == 0:
            ichi += 1
    except:
        pass
print(sum(As))
### BUGGY CODE ###

N, M = map(int, input().split())
lst_A = list(map(int, input().split()))
lst_BC = [tuple(map(int, input().split())) for _ in range(M)]


lst_A.sort()
lst_BC.sort(key=lambda x:x[1], reverse=True)


lst_D = []
add_num = N
for tpl in lst_BC:
    b, c = tpl[0], tpl[1]
    if add_num >= b:
        lst_D = lst_D + [c] * b
        add_num -= b
    else:
        lst_D = lst_D + [c] * add_num
lst_D = lst_D + [0] * (N - len(lst_D))


for i in range(N):
    if lst_A[i] >= lst_D[i]:
        break
    lst_A[i] = lst_D[i]


print(sum(lst_A))

### FIXED CODE ###

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


lst_A.sort()
lst_BC.sort(key=lambda x:-x[1])


lst_D = []
add_num = N
for b, c in lst_BC:
    lst_D += [c] * min(b, N - len(lst_D))
lst_D = lst_D + [0] * (N - len(lst_D))


for i in range(N):
    if lst_A[i] >= lst_D[i]:
        break
    lst_A[i] = lst_D[i]


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

ai = lambda: list(map(int, input().split()))

n, m = ai()

from collections import defaultdict as dd

edge = dd(list)
for _ in range(m):
    a, b, c = ai()
    edge[a - 1].append([b - 1, -c])

dist = [float('inf')] * n
dist[0] = 0
vs = {0}
i = 0
while vs:
    cur_v = vs.pop()
    for v, c in edge[cur_v]:
        if dist[v] > dist[cur_v] + c:
            dist[v] = dist[cur_v] + c
            vs.add(v)
    i += 1
    if i > n and v == n-1:
        print('inf')
        exit()
print(-dist[-1])

### FIXED CODE ###

ai_ = lambda: [int(x)-1 for x in input().split()]
ai = lambda: list(map(int, input().split()))

n,m = ai()

from collections import defaultdict as dd
edge = dd(list)
for _ in range(m):
    a,b,c = ai()
    edge[a-1].append([b-1, -c])

dist = [float('inf')] * n
dist[0] = 0

for i in range(n):
    for cur_v in range(n):
        for v, c in edge[cur_v]:
            if dist[v] > dist[cur_v] + c:
                dist[v] = dist[cur_v] + c
                if i == n-1 and v == n-1:
                    print('inf')
                    exit()
print(-dist[-1])
### BUGGY CODE ###

#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
ans=0
lis=[I() for i in range(n)]
ind =[0 for i in range(n)]
for i in range(n):
    if lis[i]==0:
        ind[i]=-1
    ans+=lis[i]//2
    lis[i]=lis[i]%2
points=[]
for i in range(n):
    if lis[i]==1:
        points.append(i)
for i in range(len(points)-1):
    x=points[i]
    y=points[i+1]
    count=0
    #print(y)
    #print(x)
    for j in range(x,y+1):
        if ind[j]==0:
            count+=1
    if count==y-x+1:
        points[i+1]=-1
        ans+=1
print(ans)





        
        
    
    
        
    
    


### FIXED CODE ###

#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
ans=0
lis=[I() for i in range(n)]
ind =[0 for i in range(n)]
for i in range(n):
    if lis[i]==0:
        ind[i]=-1
    ans+=lis[i]//2
    lis[i]=lis[i]%2
points=[]
for i in range(n):
    if lis[i]==1:
        points.append(i)
#print(points)
#for i in range(len(points)-1):
z=0
while z<len(points)-1:
    x=points[z]
    y=points[z+1]
    count=0
    #print(y)
    #print(x)
    for j in range(x,y+1):
        if ind[j]==0:
            count+=1
    if count==y-x+1:
        z+=1
        ans+=1
    z+=1
print(ans)
### BUGGY CODE ###

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

# 書き換える必要ある？
# 2 36 72　などの場合,2を36にしたら最大公約数は大きくなる
# ならば、１つを除いた全ての数の組み合わせにおける最大公約数の最大値が答えでは？

import itertools
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

all_pairs=list(itertools.combinations(a,n-1))
gcd_box=[]
for lis in all_pairs:
    gcd_box.append(gcd_list(lis))
print(max(gcd_box))


### FIXED CODE ###

from fractions import gcd

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

L = [0]*(n+1)
R = [0]*(n+1)

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


# -*- coding: utf-8 -*-
import numpy as np
N=int(input())
As=list(map(int, input().split()))

As=np.array(As)
inds=np.argsort(As)[::-1]

ds=np.zeros((N+1,N+1),dtype=int)

ds[0][0]=0
for i in range(1,N+1):
    ds[i][0]=ds[i-1][0]+As[inds[i-1]]*(inds[i-1]-(i-1))
    ds[0][i]=ds[0][i-1]+As[inds[i-1]]*(N-i-inds[i-1])

for xy in range(2,N+1):
    for x in range(1,xy):
        y=xy-x
        c1=ds[x-1,y]+As[inds[xy-1]]*(inds[xy-1]-(x-1))
        c2=ds[x,y-1]+As[inds[xy-1]]*(N-y-inds[xy-1])
        ds[x,y]=max(c1,c2)

ans=0
for x in range(0,N+1):
    y=N-x
    c=ds[x,y]
    ans=max(c,ans)
print(ans)
#print(ds)
#print(inds)




### FIXED CODE ###


# -*- coding: utf-8 -*-

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

inds=sorted(range(len(As)), key=lambda k: As[k])[::-1]
#ds=[[0 for j in range(N+1-i)] for i in range(N+1)]

ds=[0]
for xy in range(1,N+1):
    i=inds[xy-1]
    a=As[i]
    nds=[0]*(xy+1)
    nds[-1]=ds[-1]+a*(i-(xy-1))
    nds[0]=ds[0]+a*(N-xy-i)

    for x in range(1,xy):
        y=xy-x
        c1=ds[x-1]+a*abs(i-(x-1))
        c2=ds[x]+a*abs(N-y-i)
        nds[x]=max(c1,c2)
    ds=nds.copy()
    #print(ds)


print(max(ds))
#print(ds)
#print(inds)
### BUGGY CODE ###

import sys


def input():
    return sys.stdin.readline().strip()


def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0] * n
    dp[0] = 0
    dp[1] = abs(h[0] - h[1])

    for i in range(2, n):
        dp[i] = min(abs(h[i] - h[j]) + dp[j] for j in range(max(0, i - k), i))
    print(dp[n - 1])


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys


def input():
    return sys.stdin.readline().strip()


def main():
    size, jumps = map(int, input().split())
    array = list(map(int, input().split()))
    dp = [999999999] * size
    dp[0]= 0
    dp[1] = abs(array[0]- array[1])
    for i in range(2,size):
        dp[i] = min(abs(array[i] - array[j]) + dp[j] for j in range(max(0, i - jumps), i))
    print(dp[size-1])

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

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

ans = N
i = 0
while i < N-1:
    cnt = 0
    sum_plus = A[i]
    sum_xor = A[i]
    for j in range(i+1, N):
        sum_plus += A[j]
        sum_xor ^= A[j]
        if sum_plus == sum_xor:
            cnt += 1
        else:
            break
    i += 1
    ans += cnt
    
print(ans)

### FIXED CODE ###

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

ans = 0
j = 1
k = 0
sum_plus = A[0]
sum_xor = A[0]
while j <= N and k < j:
    if sum_plus == sum_xor:
        ans += j-k
        if j < N:
            sum_plus += A[j]
            sum_xor ^= A[j]
        j += 1
    else:
        sum_plus -= A[k]
        sum_xor ^= A[k]
        k += 1
    
print(ans)
### BUGGY CODE ###

n,q=map(int,input().split())
s=input()
for i in range(q):
  l,r=map(int,input().split())
  print(s[l-1:r].count('AC'))

### FIXED CODE ###

n,q=map(int,input().split())
s=input()
c=[0 for _ in range(n)]
p=''
d=0
for i in range(n):
  x=s[i]
  if p=='A' and x=='C':
    d+=1
  p=x
  c[i]=d
for i in range(q):
  ans=0
  l,r=map(int,input().split())
  ans=c[r-1]-c[l-1]

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

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

### FIXED CODE ###

n = int(input())
cnt = 1
l = list(map(int, input().split()))
if 0 in l:
    print(0)
else:
    for i in l:
        cnt *= i
        if cnt > 10 ** 18:
            print(-1)
            exit()
        else:
            pass
    print(cnt)
### BUGGY CODE ###

N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
t = 0
while len(s)>0:
    a = s.count(s[0])
    if a==1:
        continue
    else:
        a = (a*(a-1))/2
        t = t+a
    s.remove(s[0])
print(t)

### FIXED CODE ###

N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
s = sorted(s)
t = 0
i = 0
while i<N:
    for j in range(i+1,N):
        if s[i]==s[j]:
            t = t+j-i
        else:
            break
    i = j
    if i==N-1:
        break
print(t)
### BUGGY CODE ###

def solve(n, k):
    occurence = set()

    diff = n % k

    if diff == 0:
        print(diff)
        return 
    else:
        while n not in occurence:
            if k == 1:
                print(0)
                return

            occurence.add(n)

            n = abs(n - k)

            if n == 0:
                print(n)
                return

    min_value = min(occurence)
    print(min_value)


if __name__ == '__main__':
    nk = input().split()

    n = int(nk[0])
    k = int(nk[1])

    solve(n, k)


### FIXED CODE ###

def solve(n, k):
    occurence = set()

    diff = n % k
    n = diff
    
    if diff == 0 or diff == 1:
        print(diff)
        return
    else:
        while n not in occurence:
            if k == 1:
                print(0)
                return

            occurence.add(n)

            n = abs(n - k)

            if n == 0:
                print(n)
                return

    min_value = min(occurence)
    print(min_value)


if __name__ == '__main__':
    nk = input().split()

    n = int(nk[0])
    k = int(nk[1])

    solve(n, k)
### BUGGY CODE ###

S = input()
L = [i for i in S]
K = len(S)
i = 0
while True:    
    if i == len(L)-1 or i > K:
        break
    if L[i:i+2] == ['1','0'] or L[i:i+2] == ['0','1']:
        del L[i:i+2]
        i = 0
    else:
        i += 1
print(K-len(L))

### FIXED CODE ###

S = input()
m1 = S.count('0')
m2 = S.count('1')
print(2*min(m1,m2))
### BUGGY CODE ###

import fractions

def lcm(X):
    ret = X[0]
    for i in range(1,len(X)):
        ret = ret * X[i] //fractions.gcd(ret,X[i])
    return ret


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

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

count = 0
a = A[0]
while a % 2 == 0:
    a //= 2
    count += 1

det = 0
for i in range(1,N):
    x = A[i] / (2**count)
    if x % 2 == 0 or int(x) != x:
        det = -1
#print(det)
if det == -1:
    print(0)
else:
    for i in range(N):
        A[i] //= 2**count
        min_l = lcm(A) * (2**(count-1))
    #print(min_l)
    t = M // min_l
    if t % 2 == 0:
        print(t//2)
    else:
        print((t+1)//2)

### FIXED CODE ###

import fractions

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

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

def lcm(X):
    ret = X[0]
    for i in range(1,len(X)):
        ret = ret * X[i] //fractions.gcd(ret,X[i])
        if ret > M:
            ret = M+1
            break
    return ret




count = 0
a = A[0]
while a % 2 == 0:
    a //= 2
    count += 1

det = 0
for i in range(1,N):
    x = A[i] / (2**count)
    if x % 2 == 0 or int(x) != x:
        det = -1
        break
#print(det)
if det == -1:
    print(0)
else:
    for i in range(N):
        A[i] //= 2**count
    min_l = lcm(A) * (2**(count-1))
    #print(min_l)
    t = M // min_l
    if t % 2 == 0:
        print(t//2)
    else:
        print((t+1)//2)
### BUGGY CODE ###

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

nums = []
for b in B:
    count = 0
    for c in C:
        if b < c:
            count += 1
    nums.append(count)

ans = 0
for a in A:
    for b, n in zip(B, nums):
        if a < b:
            ans += n
print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
idxa = 0
idxc = 0
ans = 0
for b in range(N):
    while idxa < N and A[idxa] < B[b]:
        idxa += 1
    while idxc < N and B[b] >= C[idxc]:
        idxc += 1
    ans += idxa * (N - idxc)
print(ans)
### BUGGY CODE ###

import sys
s = input()
X, Y = map(int, input().split())

sys.setrecursionlimit(8001)

dirs = [(1, 0), (0, -1), (-1, 0), (0, 1)]
S = list(map(len, s.split('T')))
N = len(S)
memo = {}
def process(i, x, y, d):
  if (i,x,y,d) in memo:
    return
  if i >= N:
    if x == X and y == Y:
      print('Yes')
      exit()
    return
  x += dirs[d][0] * S[i]
  y += dirs[d][1] * S[i]
  process(i+1, x, y, (d+1)%4)
  process(i+1, x, y, (d-1)%4)
  memo[(i,x,y,d)] = 1

process(0, 0, 0, 0)
print('No')

### FIXED CODE ###

import sys
sys.setrecursionlimit(8001)
s = input()
X, Y = map(int, input().split())
S = list(map(len, s.split('T')))
N = len(S)
# if N == 1:
#   print(['No', 'Yes'][X == S[0] and Y == 0])
#   exit()
# elif N == 2:
#   print(['No', 'Yes'][X == S[0] and abs(Y) == S[1]])
#   exit()

x = S[0]
y = 0
xmoves = S[2::2]
xmoves.sort()
xmoves.reverse()
ymoves = S[1::2]
ymoves.sort()
ymoves.reverse()

def process(a, l, i, v, d, memo, r):
  if (i,v) in memo:
    return False
  if l == i:
    return v == d
  ab = abs(d-v)
  if ab > r:
    ret = False
  elif a == r:
    ret = True
  else:
    ret = process(a, l, i+1, v+a[i], d, memo, r-a[i]) or process(a, l, i+1, v-a[i], d, memo, r-a[i])
  memo[(i,v)] = ret
  return ret

if process(xmoves, len(xmoves), 0, x, X, {}, sum(xmoves)) and process(ymoves, len(ymoves), 0, y, Y, {}, sum(ymoves)):
  print('Yes')
else:
  print('No')
### BUGGY CODE ###

N = int(input())

def check(p):
  _N = N
  while _N%p == 0:
    _N //= p
  return ((_N-1)%p == 0) or (_N == 1)

n = int(N**0.5) + 1
P0 = set([N])
P1 = set([N-1])
for i in range(2, n+1):
  if (N-1)%i == 0:
    P1.add(i)
    P1.add((N-1)//i)
  if N%i == 0:
    P0.add(i)
    P0.add(N//i)

ans = len(P1)
for p in P0:
  ans += check(p)

print(ans)

### FIXED CODE ###

N = int(input())

def check(p):
  _N = N
  while _N%p == 0:
    _N //= p
  return (_N-1)%p == 0

n = int(N**0.5) + 1
P0 = set([N])
P1 = set([N-1])
for i in range(2, n+1):
  if (N-1)%i == 0:
    P1.add(i)
    P1.add((N-1)//i)
  if N%i == 0:
    P0.add(i)
    P0.add(N//i)

P0.discard(1)
P1.discard(1)
ans = len(P1)
for p in P0:
  ans += check(p)

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

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

def main():
    mod = 10**9+7
    K = int(input())
    S = input()
    Nk = len(S)
    ret = 0
    nCk = 1
    for i in range(K+1):
        ret += nCk * pow(25,i,mod) * pow(26,K-i,mod)
        ret %= mod
        nCk *= (i+Nk) * pow(i+1,mod-2,mod)
        nCk %= mod
    print(ret)

if __name__ == '__main__':
    main()

### FIXED CODE ###

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

def main():
    mod = 10**9+7
    K = int(input())
    S = input()
    Nk = len(S)
    ret = 0
    nCk = 1
    pw25 = 1
    pw26 = pow(26,K,mod)
    inv26 = pow(26,mod-2,mod)
    for i in range(K+1):
        ret += nCk * pw25 * pw26
        ret %= mod
        nCk *= (i+Nk) * pow(i+1,mod-2,mod)
        nCk %= mod
        pw25 = (pw25*25)%mod
        pw26 = (pw26*inv26)%mod

    print(ret)

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

import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)


def make_divisors(mn, n):
    divisors = [1]
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            if i >= mn:
                divisors.append(i)
            if i*i != n and n//i >= mn:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


N = int(input())
A = list(map(int, input().split()))
setA = set(A)
countA = Counter(A)
if countA[1] == 1:
    print(1)
    exit()

minA = min(A)

count = 0
for num in A:
    if countA[num] >= 2:
        continue
    divisors = make_divisors(minA, num)
    # print(num, divisors)
    if any((e in setA) for e in divisors):
        continue
    count += 1

print(count)


### FIXED CODE ###

import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)


N = int(input())
A = list(map(int, input().split()))
A.sort()
countA = Counter(A)
maxA = A[-1]
# if countA[1] == 1:
#     print(1)
#     exit()

ef = [True]*(maxA+1)
count = 0
prev = -1
for num in A:
    if num == prev:
        continue
    if ef[num] and countA[num] == 1:
        count += 1

    b = 2*num
    while b <= maxA:
        ef[b] = False
        b += num

    prev = num

print(count)
### BUGGY CODE ###


import sys
read = sys.stdin.buffer.read # 全読み込み
readline = sys.stdin.buffer.readline # 一行読み込み
readlines = sys.stdin.buffer.readlines # 一行ずつ全読み込み
sys.setrecursionlimit(10**7) # 再帰限界変更（デフォルトは1000）

l,r=map(int,readline().rstrip().split())

min_2019=2019

if l-r>=2019:
    print(0)

else:
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            min_2019=min(min_2019,(i*j)%2019)

print(min_2019)

### FIXED CODE ###


l, r = map(int,input().split())
 
ans = 2019
for i in range(l, r):
    for j in range(i+1, r+1):
        tmp = i*j % 2019
        if ans > tmp:
            ans = tmp
        if ans == 0:
            print(ans)
            exit(0)
print(ans)
### BUGGY CODE ###

n = int(input())

arr = [0]*n
arr[0] = int(input())
color= [arr[0]]

for i in range(1, n):
	arr[i] = int(input())
	if arr[i] > color[-1]:
		color[-1] = arr[i]
	else:
		maxx = -1
		for idx, c in enumerate(color):
			if c < arr[i] and c > maxx:
				iidx = idx
				maxx = c
		if maxx != -1:
			color[iidx] = arr[i]
		else:
			color.append(arr[i])
print(len(color))

### FIXED CODE ###

from bisect import bisect

n = int(input())

seq = []
for i in range(n):
	ele = int(input())
	pos = bisect(seq, -ele)
	if len(seq) <= pos:
		seq.append(-ele)
	else:
		seq[pos] = -ele

print(len(seq))
### BUGGY CODE ###

n = int(input());
s = input();

r = [];
g = [];
b = [];
for i in range(n) :
    if s[i] == 'R' :
        r.append(i+1);
    if s[i] == 'G' :
        g.append(i+1);
    if s[i] == 'B' :
        b.append(i+1);

ans = 0;
for i in r :
    for j in g :
        for k in b :
            l = [i,j,k];
            l.sort();
            if not(l[1]-l[0]-1 == l[2]-l[1]-1) :
                ans += 1;

print(ans);

### FIXED CODE ###

n = int(input());
s = input();

r = [];
g = [];
b = [];
for i in range(n) :
    if s[i] == 'R' :
        r.append(i+1);
    if s[i] == 'G' :
        g.append(i+1);
    if s[i] == 'B' :
        b.append(i+1);

hiku = 0;
for j in range(2,n) :
    if j-1 < n-j :
        for i in range(1,j) :
            if (not(s[j-i-1]==s[j-1])) and (not(s[j-i-1]==s[j+i-1])) and (not(s[j-1]==s[j+i-1])) :
                hiku += 1;
    else :
        for i in range(1,n-j+1) :
            if (not(s[j-i-1]==s[j-1])) and (not(s[j-i-1]==s[j+i-1])) and (not(s[j-1]==s[j+i-1])) :
                hiku += 1;

print(len(r)*len(g)*len(b)-hiku);
### BUGGY CODE ###

#https://atcoder.jp/contests/abc110/tasks/abc110_c

s = list(str(input()))
t = list(str(input()))
u = []
v = []
flag = 'Yes'


for i in range(len(s)):
    for j in range(i, len(s)):
        if s[i] == s[j]:
            if t[i] != t[j]:
                flag = 'No'
                break
        if t[i] == t[j]:
            if s[i] != s[j]:
                flag = 'No'
                break
    if flag == 'No':
        break


print(flag)

### FIXED CODE ###

import sys
s = str(input())
t = str(input())
l = len(s)
tmp = [[], []]
for i in range(l):
    if (not s[i] in tmp[0]) and (not t[i] in tmp[1]):
        tmp[0].append(s[i])
        tmp[1].append(t[i])
    else:
        if s[i] in tmp[0]:
            tmp2 = 0
            for j in range(len(tmp[0])):
                if s[i] == tmp[0][j]:
                    tmp2 = j
            if t[i] != tmp[1][tmp2]:
                print('No')
                sys.exit()
        else:
            print('No')
            sys.exit()
print('Yes')
### BUGGY CODE ###

from bisect import bisect_left
 
N = int(input())
L = list(map(int, input().split()))
L.sort()
 
cnt = 0
for i in range(0,N-2):
  for j in range(i+1,N-1):
    t = L[i]+L[j]
    idx = bisect_left(L,t,lo=j)
    cnt += max(0,idx-j-1)
print(cnt)

### FIXED CODE ###

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

from bisect import bisect_left 
cnt = 0
for i in range(0,N):
  for j in range(i+1,N):
    t = L[i]+L[j]
    idx = bisect_left(L,t)
    cnt += max(0,idx-j-1)
print(cnt)
### BUGGY CODE ###

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

result = 1
for a in A:
  result *= a
  
if result > 1e18:
  print(-1)
else:
  print(result)

### FIXED CODE ###

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

if A[0] == 0:
  print(0)
  quit()

result = 1

for a in A:
  result *= a
  if result > 1e18:
    print(-1)
    quit()

print(result)