Harryxun/stf_run huggingface dataset:
n = int(input())
re = 1

for i in range(n):
    m= int(input())
    re *= m
    
if(re > 1000000000000000000):
    print("-1")
else:
    print(re)

### FIXED CODE ###

n =int(input())
limit = 10**18
re =1
 
l = list(map(int, input().split()))
 
l.sort()
#print(l)
if(l[0] == 0):
    re = 0
else:
  for i in l:
    re *= i
    #print(re)
    if(re > limit):
      re = -1
      break
print(re)
a=int(input())
b=int(input())
print("LESS" if a<b else "GREATER" else "EQUAL")

### FIXED CODE ###

a=int(input())
b=int(input())
print("LESS" if a<b else "GREATER" if a>b else "EQUAL")
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
time = 0
while time < K:
    if not A:
        ans += 1
        if time + B[0] > K:
            break
        time += B[0]
        B.pop(0)
    elif not B:
        ans += 1
        if time + A[0]> K:
            break
        time += A[0]
        A.pop(0)
    elif A[0] > K or B[0] > K:
        break
    elif A[0] == B[0]:
        if A[1] > B[1]:
            if time + B[0] > K:
                break
            time += B[0]
            ans += 1
            B.pop(0)
        elif A[1] < B[1]:
            if time + A[0] > K:
                break
            time += B[0]
            ans += 1
            A.pop(0)
    elif A[0] > B[0] :
        if time + B[0] > K:
            break
        time += B[0]
        ans += 1
        B.pop(0)
    elif A[0] < B[0]:
        if time + A[0] > K:
            break
        time += B[0]
        ans += 1
        A.pop(0)
print(ans)


### FIXED CODE ###

#import sys
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a=[0]
b=[0]
for i in range(N):
    a.append(a[i]+A[i])
for j in range(M):
    b.append(b[j]+B[j])
ans = 0
l = M
for k in range(N+1):
    if a[k] > K:
        break
    while b[l] > K - a[k]:
        l -= 1
    ans = max(ans,k+l)
print(ans)
N=int(input())
L=list(map(int,input().split()))
counter=0
for t in range(N):
  for i in range(t+1,N):
    for p in range(i+1,N):
      if L[p]<L[t]+L[i] and L[t]<L[i]+L[p] and L[i]<L[p]+L[t]:
        counter+=1
print(counter

### FIXED CODE ###

import bisect
counter=0
N=int(input())
L=sorted(list(map(int,input().split())))
for a in range(N-2):
  for b in range(a+1,N-1):
    k=bisect.bisect_left(L,L[a]+L[b])
    counter+=k-b-1
print(counter)
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod = 998244353
INF = 10**18
eps = 10**-7

n,x,m = map(int,readline().split())

if n == 1:
    print(x)
    exit()

if n < 10**7:
    a = [0]*n
    a[0] = x
    for i in range(n-1):
        a[i+1] = a[i]**2%m
    print(sum(a))
    exit()

a = [0]*m
a[0] = x

for i in range(m-1):
    a[i+1] = a[i]**2%m

idx = [-1]*m

for i in range(m):
    if (idx[a[i]] == -1):
        idx[a[i]] = i
    else:
        idxx = idx[a[i]]
        now = i
        break

d = sum(a[idxx:now])
l = now-idxx
ans = sum(a[:idxx])
n -= idxx
ans += d*(n//l)
n = n%l
ans += sum(a[idxx:idxx+n])
print(ans)







### FIXED CODE ###

import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod = 998244353
INF = 10**18
eps = 10**-7

n,x,m = map(int,readline().split())

if n == 1:
    print(x)
    exit()

if n < 10**7:
    a = [0]*n
    a[0] = x
    for i in range(n-1):
        a[i+1] = a[i]**2%m
    print(sum(a))
    exit()



a = [0]*(m+10)
a[0] = x

for i in range(m+5):
    a[i+1] = a[i]**2%m

idx = [-1]*m

for i in range(m+5):
    if (idx[a[i]] == -1):
        idx[a[i]] = i
    else:
        idxx = idx[a[i]]
        now = i
        break

d = sum(a[idxx:now])
l = now-idxx
ans = sum(a[:idxx])
n -= idxx
ans += d*(n//l)
n = n%l
ans += sum(a[idxx:idxx+n])
print(ans)
mport math

a,b,x = (int(num) for num in input().split())
suf2 = a*b
vol = a*a*b
if (vol/2)>=x:
    l = x*2 / suf2
    x = b/l
    ans = math.degrees(math.atan(x))
else:
    l = (vol-x)*2 / (a*a)
    x = l/a
    ans = math.degrees(math.atan(x))
    
print(round(ans,6))


### FIXED CODE ###

import math

a,b,x = (int(num) for num in input().split())
suf2 = a*b
vol = a*a*b
if (vol/2)>=x:
    l1 = x*2 / suf2
    x = float(b)/l1
    ans = math.degrees(math.atan(x))
else:
    l2 = (vol-x)*2 / (a*a)
    x = l2/float(a)
    ans = math.degrees(math.atan(x))
    
print(round(ans,6))
N = int(input().strip())
A = list(map(int, input().strip().split(' ')))
A = sorted(A)

# 約数列挙
def divisor(n):
  result = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      result.append(i)
      if i != n // i:
        result.append(n//i)
  return result

# A(intのlist)のうちdで割り切れるものがlen(A)-1個以上あればTrue
def check(A, d):
  count = 0
  for a in A:
    if a % d == 0:
      continue
    count += 1
    if count > 1:
      return False
  return True

for i in sorted(list(set(divisor(A[0])+divisor(A[1]))))[::-1]:
  if check(A, i):
    print(i)
    exit()

### FIXED CODE ###

A,B,T = map(int, input().strip().split(' '))
print((T//A)*B)
n = int(input())
if n == 0:
    print(0)
    exit()
ans = ""
while n != 0:
    if n % (2) == 0:
        n = n // (-2)
        ans = ans + 0
    else:
        n = (n - 1) // (-2)
        ans = ans + 1
print(ans)

### FIXED CODE ###

n = int(input())
if n == 0:
    print(0)
    exit()
ans = ""
while n != 0:
    if n % (2) == 0:
        n = n // (-2)
        ans = "0" + ans
    else:
        n = (n - 1) // (-2)
        ans = "1" + ans
print(ans)
import collections

def dfs(v):
    if cache.get(v):
        return cache[v]
    path=0
    for adj in g[v]:
        path=max(path,1+dfs(adj))
    cache[v]=path
    return path


n,m=map(int,input().split())
g=collections.defaultdict(list)
cache={}
path=0
for _ in range(m):
    u,v=map(int,input().split())
    g[u].append(v)
for v in range(1,n+1):
    path=max(path,dfs(v))
print(path)



### FIXED CODE ###

import collections
import sys
sys.setrecursionlimit(10**9)
cache,edge={},collections.defaultdict(list)
def dp(node):
  if node in cache:
    return cache[node]
  lcl_max=0
  for child in edge[node]:
    
    lcl_max=max(lcl_max,1+dp(child))
  cache[node]=lcl_max
  return lcl_max
 
max_dis=0

n,m=map(int,input().split())
for _ in range(m):
  a,b=map(int,input().split())
  edge[a].append(b)
for node in range(1,n+1):
  max_dis=max(max_dis,dp(node))
print(max_dis)
import math

def prime(n):
    for i in range(2, int(math.sqrt(n))+1:
        if  n % i == 0:
            return False
    return True

num_prime = []
k = 0
while True:
    try:
        n = input()
    except:
        break
    if prime(int(n)):
        if not int(n) in num_prime:
            k += 1
            num_prime.append(int(n))

print(k)

### FIXED CODE ###

import math

def prime(n):
    for i in range(2, int(math.sqrt(n))+1):
        if  n % i == 0:
            return False
    return True

num_prime = []
k = 0
while True:
    try:
        n = input()
    except:
        break
    if prime(int(n)):
        if not int(n) in num_prime:
            k += 1
            num_prime.append(int(n))

print(k)
n,x=map(int,input().split())
L=list(map(int,input().split()))
count=1
D=0
for i in range(n+1):
  D=D+L[i]
  if D<=x:
    count+=1
  else:
    break
print(count)

### FIXED CODE ###

n,x=map(int,input().split())
L=list(map(int,input().split()))
count=1
D=0
for i in range(n):
  D=D+L[i]
  if D<=x:
    count+=1
  else:
    break
print(count)
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
a = list(map(int, input().split(" ")))
min8 = a[0]/0.08
max8 = (a[0]+1)/0.08
min10 = a[1]/0.1
max10 =(a[1]+1)/0.1
a = max(min8, min10)
if ((min8>=max10) or (max8<=min10)):
    print(-1)
else:
    print(Decimal(b).quantize(Decimal('0'), rounding = ROUND_HALF_UP))

### FIXED CODE ###

import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
a = list(map(int, input().split(" ")))
min8 = a[0]/0.08
max8 = (a[0]+1)/0.08
min10 = a[1]/0.1
max10 =(a[1]+1)/0.1
b = max(min8, min10)
if ((min8>=max10) or (max8<=min10)):
    print(-1)
else:
    print(Decimal(b).quantize(Decimal('0'), rounding = ROUND_HALF_UP))
n,m = map(int,input().split())
L = []
for i in range(m):
    L.append(list(((map(int,input().split())))))
#print(L)
if L == False:
    print(-1)
    exit()
li = [-1]*n
dic = {}
for i in range(m):
    if L[i][0] not in dic:
        dic[L[i][0]] = L[i][1]
#print(dic)
for i in range(m):
    if dic[L[i][0]] != L[i][1]:
        print(-1)
        exit()
    li[L[i][0]-1] = L[i][1]
#print(li)
if n == 1:
    print(li[0])
    exit()
else:
    for i in range(m):
        if li[i] == -1:
            li[i] = 0
    if li[0] == 0:
        print(-1)
        exit()
    else:
        li = [str(x) for x in li]
print("".join(li))

### FIXED CODE ###

n,m = map(int,input().split())
L = []
for i in range(m):
    L.append(list((map(int,input().split()))))

for i in range(1000):
    p = str(i)
    flag = False
    for j in range(m):
        if len(p) >= L[j][0]:
            if int(p[L[j][0]-1]) != L[j][1]:
                break
    else:
        if len(p) == n:
            flag = True

    if flag:
        print(i)
        exit()
print(-1)
from heapq import heappush, heappop
from itertools import permutations
INF = 10 ** 20

while True:
  n, m, p, a, b = map(int, input().split())
  if n == 0:
    break
  a -= 1
  b -= 1
  tlst = list(map(int, input().split()))
  edges = [[] for _ in range(m)]
  for _ in range(p):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    edges[x].append((z, y))
    edges[y].append((z, x))
  def search(lst):
    que = []
    heappush(que, (0, 0, a))
    costs = [[INF] * m for _ in range(n + 1)]
    costs[0][a] = 0
    while que and lst:
      total, num, city = heappop(que)
      if num >= n:
        continue
      speed = lst[num]
      for dist, to in edges[city]:
        next_total = total + dist / speed
        if costs[num][to] > next_total:
          costs[num][to] = next_total
          heappush(que, (next_total, num + 1, to))
    ret = min(costs[i][b] for i in range(n + 1))
    return ret
  
  ans = INF
  for lst in permutations(tlst, n):
    ans = min(ans, search(lst))
  if ans == INF:
    print("Impossible")
  else:
    print(ans)


### FIXED CODE ###

INF = 10 ** 20

def search(rest, now, goal, dp, edges):
  if now == goal:
    return 0
  if rest == ():
    return INF

  if (rest, now) in dp:
    return dp[(rest, now)]

  ret = INF
  for i, t in enumerate(rest):
    for dist, to in edges[now]:
      tmp = search(tuple(v for j, v in enumerate(rest) if i != j), to, goal, dp, edges) + dist / t
      if ret > tmp:
        ret = tmp
  dp[(rest, now)] = ret
  return ret

def main():
  while True:
    n, m, p, a, b = map(int, input().split())
    if n == 0:
      break
    a -= 1
    b -= 1
    tlst = list(map(int, input().split()))
    edges = [[] for _ in range(m)]
    for _ in range(p):
      x, y, z = map(int, input().split())
      x -= 1
      y -= 1
      edges[x].append((z, y))
      edges[y].append((z, x))
    tlst.sort()
    rest = tuple(tlst)
    dp = {}
    ans = search(rest, a, b, dp, edges)
    if ans == INF:
      print("Impossible")
    else:
      print(ans)
main()
n = int(input())
A = [int(input()) for _ in range(n)]
A = sorted(A)

l = 1
r = n-1

que = deque()
que.append(A[0])
c = 0

while l <= r:
  if r-l==0:
    if abs(que[0]-A[r]) >= abs(que[-1]-A[r]):
      que.appendleft(A[r])
    else:
      que.append(A[r])
    r-=1
  else:    
    if c%2 == 0:    
      if abs(que[0]-A[r]) >= abs(que[-1]-A[r]):
        que.appendleft(A[r])
        que.append(A[r-1])
      else:
        que.append(A[r])
        que.appendleft(A[r-1])
      r -= 2
    else:
      if abs(que[0]-A[l]) >= abs(que[-1]-A[l]):
        que.appendleft(A[l])
        que.append(A[l+1])
      else:
        que.append(A[l])
        que.appendleft(A[l+1])
      l += 2
  c += 1  

ans = 0  
for i in range(n-1):
  ans += abs(que[i]-que[i+1])
  
print(ans)  

### FIXED CODE ###

n = int(input())
A = [int(input()) for _ in range(n)]
A = sorted(A,reverse=True)

ans = 0
if n%2 == 1:
  i = -1
  for i in range((n-2)//2):
    ans += A[i]*2
    ans -= A[-i-1]*2    
  ans += A[i+1]
  ans += A[i+2]
  ans -= A[i+3] *2
  
  tmp = 0
  for i in range((n-2)//2):
    tmp += A[i]*2
    tmp -= A[-i-1]*2    
  tmp += A[i+1] *2
  tmp -= A[i+2]
  tmp -= A[i+3]
  ans = max(ans,tmp)
  
else:
  i = -1
  for i in range((n-2)//2):
    ans += 2*A[i]
    ans -= 2*A[-i-1]      
  ans += A[i+1]
  ans -= A[i+2]
  
print(ans)
H, W, N = map(int, input().split())
posObss = [{H} for y in range(W)]
for _ in range(N):
    X, Y = map(int, input().split())
    posObss[Y - 1].add(X - 1)

ans = H
xNow = 0
for y in range(W):
    xLim = min([x for x in posObss[y] if x > xNow])
    ans = min(ans, xLim)

    xNow += 1
    while xNow in posObss[y + 1]:
        xNow += 1
    if xNow >= xLim: break

print(ans)


### FIXED CODE ###

H, W, N = map(int, input().split())
posObss = [{H} for y in range(W)]
for _ in range(N):
    X, Y = map(int, input().split())
    posObss[Y - 1].add(X - 1)

ans = H
xNow = 0
for y in range(W):
    xLim = min([x for x in posObss[y] if x > xNow])
    ans = min(ans, xLim)

    if y == W - 1: break
    xNow += 1
    while xNow in posObss[y + 1]:
        xNow += 1
    if xNow >= xLim: break

print(ans)
R, C, K = map(int,input().split())
V = [[]for i in range(R)]
for i in range(K):
    r,c,v = map(int,input().split())
    V[r-1].append([c,v])
cost = [0]*C
for r in range(R):
    V[r].sort()
    hoge = [0,0,0,0]
    for c,v in V[r]:
        for i in range(3,-1,-1):
            hoge[i] = max(cost[c],hoge[i-1])
            hoge[i] += v
        hoge[0] -= v
        cost[c] = max(hoge)
    for i in range(1,C):
        cost[i] = max(cost[i],cost[i-1])

print(cost[-1][-1]) 

### FIXED CODE ###

R, C, K = map(int,input().split())
V = [[]for i in range(R)]
for i in range(K):
    r,c,v = map(int,input().split())
    V[r-1].append([c,v])
cost = [0]*(C+1)
for r in range(R):
    V[r].sort()
    hoge = [0,0,0,0]
    for c,v in V[r]:
        for i in range(3,0,-1):
            hoge[i] = max(cost[c]+v,hoge[i-1]+v,hoge[i])
        hoge[0] = cost[c]
        cost[c] = max(hoge)
    for i in range(1,C+1):
        cost[i] = max(cost[i],cost[i-1])

print(cost[-1])
N, M = map(int,input().split()) 
A = [list(map(int,input().split())) for i in range(M)]

w = sum(A)

r = N-w

if r<0:
  print(-1)
else:
  print(r)


### FIXED CODE ###

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

w = sum(A)

r = N-w

if r<0:
  print(-1)
else:
  print(r)
h, w = map(int, input().split())
s = [input() for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            ans = "No"
            for x, y in [(-1, 0), (0, -1), (0, 1), (1, 0)]:
                if  0<=i+x<h and 0<=j+y<w and s[i+x][j+y]=="#":
                    ans = "Yes"
            if ans == "No":
                print(ans)
                exit()
print(ans)

### FIXED CODE ###

h, w = map(int, input().split())
s = ["."*(w+2)]+["."+input()+"." for i in range(h)]+["."*(w+2)]
for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j]=="#" and s[i-1][j]==s[i][j-1]==s[i][j+1]==s[i+1][j]==".":
            print("No")
            exit()
print("Yes")
o=int(input())
a=int(input())
b=int(input())
if o==1:
    print('Hello World')
else:
    print(a+b)

### FIXED CODE ###

o=int(input())
if o==1:
    print('Hello World')
else:
    a=int(input())
    b=int(input())
    print(a+b)
n, y = map(int, input().split())

a = 0  # 1000
b = 0  # 5000
c = 0  # 10000

c = y//10000
b = (y - c*10000)//5000
a = (y - c*10000 - b*5000)//1000

#print(c,b,a)
flag = True

while (a+b+c) <= n:
    num = a+b+c
    if num == n:
        print(c, b, a)
        flag = False
        break
    else:
        if num + 9 <= n:
            c -= 1
            a += 10
        elif num + 4 <= n:
            b -= 1
            a += 5
        elif num + 1 <= n:
            c -= 1
            b += 2
        if c < 0 or b < 0:
            break

if flag:
   # print(-1, -1, -1)


### FIXED CODE ###

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

a = 0  # 1000
b = 0  # 5000
c = 0  # 10000

c = y//10000
b = (y - c*10000)//5000
a = (y - c*10000 - b*5000)//1000

flag = True

while (a+b+c) <= n:
    num = a+b+c
#    print(num)
#    print(c,b,a)
    if num == n:
        flag = False
        break
    else:
        if num + 9 <= n and c > 0:
            c -= 1
            a += 10
            continue
        elif num + 4 <= n and b > 0:
            b -= 1
            a += 5
            continue
        elif num + 1 <= n and c > 0:
            c -= 1
            b += 2
            continue
        else:
            break
if flag:
    print(-1, -1, -1)
else:
    print(c, b, a)
n, k = map(int,input().split())
x = list(map(int,input().split()))
x.append(0)
x.sort()
ans = 100000000
for i in range(n-k+1):
    cnt = 0
    cnt += abs(x[i])
    for j in range(i,k+i):
        cnt += abs(x[j+1] - x[j])    
    if cnt < ans:
        ans = cnt

print(min(ans))

### FIXED CODE ###

n, k = map(int,input().split())
x = list(map(int,input().split()))
result = []
for i in range(n-k+1):
    l, r = x[i], x[i+k-1]
    if l * r >= 0:
        result.append(max(abs(l), abs(r)))
    else:
        result.append(abs(2*l-r))
        result.append(abs(2*r-l))
print(min(result))
N = int(input())
import collections
mylist = []
for i in range(N):
  val = input("")
  if val:
    mylist.append(val)
if len(mylist) != len(set(mylist)):
    c = collections.Counter(mylist)
    A = [i for i in range(len(set(mylist))) if c.most_common()[0][1] == c.most_common()[i][1]]
    B = [c.most_common()[i][0] for i in range(len(A))]
    C = sorted(B)
    for item in C:
        print(item)
else:
    D = sorted(mylist)
    for item in D:
            print(item)


### FIXED CODE ###

A, B, C = map(int, input().split())
if A == B and A != C:
    print('Yes')
elif A == C and A != B:
    print('Yes')
elif B == C and B != A:
    print('Yes')
else:
    print('No')
n = input() % 10
if n == 3:
	print("bon")
elif n == 0 or 1 or 6 or 8:
	print("pon")
else:
	print("hon")

### FIXED CODE ###

n = int(input()) % 10
if n == 3:
	print("bon")
elif n == 0 or n == 1 or n == 6 or n == 8:
	print("pon")
else:
	print("hon")
import sys
import numpy as np

N = sys.stdin.readline()
a = np.fromstring(sys.stdin.readline(), dtype='i4', sep=' ')
a.sort()
p = a[a <= 0]
q = a[a > 0]

if len(p) == 0:
    print(np.sum(q[1:]) - q[0])
    t = q[0]
    for c in q[1:-1]:
        print(str(t) + ' ' + str(c))
        t -= c
    print(str(q[-1]) + ' ' + str(t))
elif len(q) == 0:
    print(p[-1] - np.sum(p[:-1]))
    t = p[-1]
    for c in p[:-1]:
        print(str(t) + ' ' + str(c))
        t -= c
else:
    print(sum(q) - sum(p))
    t = p[0]
    for c in q[:-1]:
        print(str(t) + ' ' + str(c))
        t -= c
    print(str(q[-1]) + ' ' + str(t))
    t = q[-1] - t
    for c in p[1:]:
        print(str(t) + ' ' + str(c))
        t -= c

### FIXED CODE ###

import sys
import numpy as np

N = sys.stdin.readline()
a = np.fromstring(sys.stdin.readline(), dtype='i4', sep=' ')
a.sort()
p = a[a <= 0]
q = a[a > 0]

if len(p) == 0:
    print(np.sum(q[1:]) - q[0])
    t = q[0]
    for c in q[1:-1]:
        print(str(t) + ' ' + str(c))
        t -= c
    print(str(q[-1]) + ' ' + str(t))
elif len(q) == 0:
    print(p[-1] - np.sum(p[:-1]))
    t = p[-1]
    for c in p[:-1]:
        print(str(t) + ' ' + str(c))
        t -= c
else:
    print(sum(q) - sum(p))
    t = p[0]
    for c in q[:-1]:
        print(str(t) + ' ' + str(c))
        t -= c
    print(str(q[-1]) + ' ' + str(t))
    t = q[-1] - t
    for c in p[1:]:
        print(str(t) + ' ' + str(c))
        t -= c
x = input()

print (x ** 3)

### FIXED CODE ###

x = int(input())
 
print (x ** 3)
from bisect import bisect_left
N,K=map(int, input().split())
A=list(map(int, input().split()))
p=10**9+7
A=sorted(A)
thresh=bisect_left(A,0)
minus=A[:thresh]
plus=A[thresh:][::-1]

#print(plus, minus)
if len(plus)==0:
    ans=1
    if K%2!=0:
        minus=minus[::-1]
        for i in range(K):
            ans*=minus[i]
            ans%=p
    else:
        for i in range(K):
            ans*=minus[i]
            ans%=p
    print(ans)
    exit()

if len(minus)==0:
    ans=1
    for i in range(K):
        ans*=plus[i]
        ans%=p
    print(ans)
    exit()

midx=0
pidx=0
ans=1
while K>0 and (0<=midx<len(minus) or 0<=pidx<len(plus)):
    if midx==len(minus)-1:
        nexmin=minus[midx]
    elif midx>=len(minus):
        nexmin=-1
    else:
        nexmin=minus[midx]*minus[midx+1]

    if pidx==len(plus)-1:
        nexplus=plus[pidx]
    elif pidx>=len(plus):
        nexplus=-float("INF")
    else:
        if plus[pidx+1]!=0:
            nexplus=plus[pidx]*plus[pidx+1]
        else:
            nexplus=plus[pidx]

    if nexmin>=nexplus and K>=2:
        ans*=nexmin
        ans%=p
        midx+=2
        K-=2
    else:
        ans*=plus[pidx]
        ans%=p
        pidx+=1
        K-=1

print(ans)



### FIXED CODE ###

from bisect import bisect_left
N,K=map(int, input().split())
A=list(map(int, input().split()))
p=10**9+7
A=sorted(A)
thresh=bisect_left(A,0)
minus=A[:thresh]
plus=A[thresh:][::-1]

#print(plus, minus)
if len(plus)==0:
    ans=1
    if K%2!=0:
        minus=minus[::-1]
        for i in range(K):
            ans*=minus[i]
            ans%=p
    else:
        for i in range(K):
            ans*=minus[i]
            ans%=p
    print(ans)
    exit()

if len(minus)==0:
    ans=1
    for i in range(K):
        ans*=plus[i]
        ans%=p
    print(ans)
    exit()

midx=0
pidx=0
ans=1

while K>0 and (0<=midx<len(minus) or 0<=pidx<len(plus)):
    if midx==len(minus)-1:
        nexmin=minus[midx]
    elif midx>=len(minus):
        nexmin=-1
    else:
        if K>=2:
            nexmin=minus[midx]*minus[midx+1]
        else:
            nexmin=minus[midx]

    if pidx==len(plus)-1:
        nexplus=plus[pidx]
        fact=nexplus
    elif pidx>=len(plus):
        nexplus=-float("INF")
        fact=nexplus
    else:
        #if plus[pidx+1]!=0:
        #    nexplus=plus[pidx]*plus[pidx+1]
        #else:
        #    nexplus=plus[pidx]
        if K>=2:
            nexplus=plus[pidx]*plus[pidx+1]
        else:
            nexplus=plus[pidx]
        fact=plus[pidx]

    if nexmin>=nexplus:
        ans*=nexmin
        ans%=p
        midx+=2
        K-=2
    else:
        ans*=fact
        ans%=p
        pidx+=1
        K-=1


print(ans)
while True:
    n,x=map(int,input().split())
    if n=0 and x=0:break
    ans =0
    for a in range(1,n+1):
        for b in range(1,n+1):
            if b<=a:continue
            c=x-(a+b)
            if c>b and c<=n:ans+1
    print("%d"%(ans))



### FIXED CODE ###

while True:
    n,x=map(int,input().split())
    a=0
    if n==0 and x==0:break
    for i in range(1,n+1):
        for j in range(1,i):
            for k in range(1,j):
                if i+j+k==x:a+=1
    print(a)
A=int(input())
B=int(input())

if A=B:
  print("EQUAL")
elif A>B:
  print("GREATER")
else:
  print("LESS")

### FIXED CODE ###

a=int(input())
b=int(input())

if a>b:
  print("GREATER")
elif a==b:
  print("EQUAL")
else:
  print("LESS")
S = input()
T = input()

print(T + S)

### FIXED CODE ###

S = list(map(str, input().split()))
 
print(S[1] + S[0])
n = int(input())
b = list(map(int, input().split()))

a = []

a.append(b[0])

for i in range(1, n-1):
  if b[i-1] <= b[i]:
    a.append(b[i-1])
  elif b[i] <= b[i+1]:
    a.append(b[i+1])
a.append(b[-1])
print(sum(a))

### FIXED CODE ###

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

a = []
a.append(b[0])

for i in range(1, n-1):
  if b[i-1] <= b[i]:
    a.append(b[i-1])
  elif b[i-1] > b[i]:
    a.append(b[i])
a.append(b[-1])
print(sum(a))