Given are N integers A_1,\ldots,A_N.
We will choose exactly K of these elements. Find the maximum possible product of the chosen elements.
Then, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).

-----Constraints-----
 - 1 \leq K \leq N \leq 2\times 10^5
 - |A_i| \leq 10^9

-----Input-----
Input is given from Standard Input in the following format:
N K
A_1 \ldots A_N

-----Output-----
Print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive).

-----Sample Input-----
4 2
1 2 -3 -4

-----Sample Output-----
12

The possible products of the two chosen elements are 2, -3, -4, -6, -8, and 12, so the maximum product is 12.

Difficulty: interview

Starter code:

Solutions:
n, k = [int(x) for x in input().strip().split(" ")]
p = 10**9 + 7

num_list = [int(x) for x in input().strip().split(" ")]
num_list = sorted(num_list, reverse = True)

ans = 1
l_idx = 0
r_idx = -1

if num_list[0] < 0 and k % 2 == 1:
  for i in range(k):
    ans = (ans * num_list[i]) % p
else:
  while True:
    if k >= 2:
      l_prod = num_list[l_idx] * num_list[l_idx+1]
      r_prod = num_list[r_idx] * num_list[r_idx-1]
      if l_prod >= r_prod:
        ans = (ans * num_list[l_idx]) % p
        l_idx +=1
        k -= 1
      else:
        ans = (ans * r_prod) % p
        r_idx -=2
        k -= 2
    elif k == 1:
      ans = (ans * num_list[l_idx]) % p
      ans %= p
      break
    else:
      break

print(ans)


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

import numpy

MAX = 10 ** 9 + 7

def prod_mod(la, mod):
  x = 1
  for a in la:
    x *= a
    x %= mod
  return x

def main():
  n, k = list(map(int, input().strip().split()))
  la = numpy.array(list(map(int, input().strip().split())))
  la.sort()
  if n == k:
    print((prod_mod(la, MAX)))
  else:
    if k % 2 == 1 and (la >= 0).sum() == 0:
      print((prod_mod(la[-k:], MAX)))
    else:
      il, ir = 0, n-1
      cnt = 0
      l = []
      if k % 2 == 1:
        l.append(la[ir])
        ir -= 1
        cnt += 1
      while k - (cnt + 2) >= 0:
        if la[il] * la[il+1] > la[ir-1] * la[ir]:
          l.extend([la[il], la[il+1]])
          il += 2
        else:
          l.extend([la[ir-1], la[ir]])
          ir -= 2
        cnt += 2
      print((prod_mod(l, MAX)))
      

def __starting_point():
  main()


__starting_point()

import sys

input = sys.stdin.readline

n_k = list(map(int, input().split()))
n = n_k[0]
k = n_k[1]
a = list(map(int, input().split()))
a_pos = list([v for v in a if v >= 0])
a_neg = list([v for v in a if v < 0])

a_pos.sort(reverse=True)
a_neg.sort()

mod = 10**9+7

ans = 1
if n == k:
    for a_i in a:
        ans = ans * a_i % mod
elif len(a_pos) == 0 and k % 2 == 1:
    for i in reversed(list(range(len(a_neg) - k, len(a_neg)))):
        ans = ans * a_neg[i] % mod
else:
    i_p = 0
    i_n = 0
    i = 0
    while i < k:
        if i_p < len(a_pos) and (i == k - 1 or i_n+1 >= len(a_neg) or a_pos[i_p] * (a_pos[i_p+1] if i_p+1 < len(a_pos) else 1) > a_neg[i_n] * a_neg[i_n+1]):
            ans = ans * a_pos[i_p] % mod
            i_p += 1
            i += 1
        else:
            ans = ans * a_neg[i_n] % mod * a_neg[i_n+1] % mod
            i_n += 2
            i += 2
print(ans)


def main():
    mod = 10**9+7
    n, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    a.sort(key=lambda x: -abs(x))
    kouho = []
    minus = 0
    last_plus = None
    last_minus = None
    if k == 1:
        print((max(a)))
        return
    for i in range(k):
        kouho.append(a[i])
        if a[i] >= 0:
            last_plus = a[i]
        if a[i] < 0:
            minus += 1
            last_minus = a[i]
    if minus % 2 == 0:
        ans = 1
        for i in kouho:
            ans = ans*i % mod
        print(ans)
        return
    change_plus = None
    change_minus = None
    if last_plus != None:
        # マイナスを追加する
        for i in range(k, n):
            if a[i] <= 0:
                change_plus = a[i]
                break
    if last_minus != None:
        # マイナスを追加する
        for i in range(k, n):
            if a[i] >= 0:
                change_minus = a[i]
                break

    # print(kouho)
    #print(last_plus, change_plus)
    #print(last_minus, change_minus)

    if change_plus == None and change_minus == None:
        ans = 1
        for i in range(k):
            ans = ans*a[-i-1] % mod
    elif change_plus == None:
        ans = change_minus
        for i in kouho:
            ans = ans*i % mod
        ans = ans*pow(last_minus, mod-2, mod) % mod
    elif change_minus == None:
        ans = change_plus
        for i in kouho:
            ans = ans*i % mod
        ans = ans*pow(last_plus, mod-2, mod) % mod
    else:
        if abs(change_plus*last_minus) < abs(change_minus*last_plus):
            ans = change_minus
            for i in kouho:
                ans = ans*i % mod
            ans = ans*pow(last_minus, mod-2, mod) % mod
        else:
            ans = change_plus
            for i in kouho:
                ans = ans*i % mod
            ans = ans*pow(last_plus, mod-2, mod) % mod
    print(ans)


main()


import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
sys.setrecursionlimit(int(1e+6))
MOD = int(1e+9) + 7
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

def main():
    N, K = i2nn()
    A = i2nn()
    # 選択の余地がない場合、全部掛けるしかない
    if N == K:
        n = 1
        for a in A:
            n = (n * a) % MOD
        print(n)
        return

    Ap = [ n for n in A if n >= 0]
    An = [-n for n in A if n < 0]
    Ap.sort()
    Ap.reverse()
    An.sort()
    An.reverse()
    Np = len(Ap)
    Nn = len(An)
    # 結果はプラスにしたい。Aiが全部マイナスかつKが奇数だとNG
    # 結果をプラスにできない場合、絶対値を最小化する
    if N == Nn and K % 2 == 1:
        n = 1
        A.sort()
        A.reverse()
        for i in range(K):
            n = (n * A[i]) % MOD
        print(n)
        return

    n = 1
    k = K
    i = 0
    j = 0
    # 結果をプラスに場合、プラスを維持しつつ、絶対値を最大化する
    # Kは偶数で考えたい。Kが奇数のとき、一番大きな正の数を取る
    if k % 2 == 1:
        n = (n * Ap[i]) % MOD
        i += 1
        k -= 1
    while k > 0:
        if Np - i < 2:
            n = (n * An[j]) % MOD
            j += 1
            n = (n * An[j]) % MOD
            j += 1
        elif Nn - j < 2:
            n = (n * Ap[i]) % MOD
            i += 1
            n = (n * Ap[i]) % MOD
            i += 1
        else:
            np = Ap[i] * Ap[i+1]
            nn = An[j] * An[j+1]
            if np >= nn:
                n = (n * np) % MOD
                i += 2
            else:
                n = (n * nn) % MOD
                j += 2
        k -= 2
    print(n)

main()


import numpy as np
N,K=map(int, input().split())
A =list(map(int,input().split()))
MOD = 10 ** 9 + 7
if N==K:
  ans0 = 1
  for a in A[0:N]:
    ans0 *= a
    ans0 %= MOD
  print(ans0)
  return

A=sorted(A)  
if (K%2==1 and A[-1]<0):
  ans1 = 1
  for a in A[N-K:N]:
    ans1 *= a
    ans1 %= MOD
  print(ans1)
  return

A=sorted(A, key=lambda x:abs(x), reverse=True)
AA=[np.sign(i) for i in A]
 
ansA = 1
for a in A[0:K]:
  ansA *= a
  ansA %= MOD
ansAA = AA[0:K].count(-1)%2
if ansA==0 or ansAA==0:
  print(ansA)
  return

B1=A[0:K]
C1=A[0:K]
B2=sorted(A[K:N])
Bp=[i for i in A[0:K] if i>0]
Bm=[i for i in A[0:K] if i<0]

if B2[0]>0:B2.insert(0,0)
if B2[-1]<0:B2.insert(-1,0)
if not Bp:Bp.insert(0,B1[-1])
if not Bm:Bm.insert(0,B1[0])
  
B1.remove(Bp[-1])
B1.append(min(B2[0],0))

ansB = 1
for a in B1[0:K]:
  ansB *= a
  ansB %= MOD

C1.remove(Bm[-1])
C1.append(max(B2[-1],0))
 
ansC = 1
for a in C1[0:K]:
  ansC *= a
  ansC %= MOD

BB1=[np.sign(i) for i in B1]
ansBB1 = BB1[0:K].count(-1)%2
BB2=[np.sign(i) for i in C1]
ansBB2 = BB2[0:K].count(-1)%2
if ansBB1==1:
  print(ansC)
  return
if ansBB2==1:
  print(ansB)
  return

if abs(Bp[-1]*B2[-1])-abs(Bm[-1]*B2[0])>=0:
  print(ansC)
else: print(ansB)

import datetime
import string
import re
import math

def isort(list, _beg, _end):
    if _beg < _end:
        beg = _beg
        end = _end
        pivot = abs(list[int((beg + end)/2)])
        while(True):
            while abs(list[beg]) < pivot: beg += 1
            while abs(list[end]) > pivot: end -= 1
            if beg <= end:
                tmp = list[beg]
                list[beg] = list[end]
                list[end] = tmp
                beg += 1
                end -= 1
            else:
                break
        isort(list, _beg, end)
        isort(list, beg, _end)

def searchByBool(list):
    for i in range(len(list)):
        if check(list[i]): return i
    return -1

def check(num):
    if num >= 0: return True
    else: return False

sp = list(map(int, input().split()))
N = sp[0]
K = sp[1]
alist = list(map(int, input().split()))
klist = []
isK = True

isort(alist, 0, len(alist) - 1)
alist.reverse()

numMinus = 0
for i in range(K):
    if check(alist[i]) == False: numMinus += 1

# select biggest K numbers in terms of absolute value

# for all chosen numbers
# if the number of negative number is even
if numMinus % 2 == 0:
    isK = False

# if odd
# -> choose the smallest number, and search opposite number
if isK and K < N:
    _right = -1
    _left = -1
    for right in range(K,N):
        if check(alist[K-1]) != check(alist[right]):
            _right = right
            break
    for left in range(K):
        if check(alist[K-1-left]) != check(alist[K]):
            _left = left
            break
    isK = False
    if _right != -1 and _left != -1:
        if abs(alist[K-1-left]*alist[_right]) < abs(alist[K-1]*alist[K]):
            alist[K-1-_left] = alist[K]
        else:
            alist[K-1] = alist[_right]
    elif _right == -1 and _left != -1:
        alist[K-1-_left] = alist[K]
    elif _right != -1 and _left == -1:
        alist[K-1] = alist[_right]
    else:
        isK = True

if isK:
    alist.reverse()
klist = alist[0:K]

multi = klist[0]
for i in range(1, K):
    multi *= klist[i]
    multi = multi % 1000000007

print(multi)


n,k=map(int,input().split())
a=[int(x) for x in input().split()]
mod=10**9+7
nega=sorted([a[i] for i in range(n) if a[i]<0],reverse=True)

v=[]
if k==n:
  # 全掛け算
  v=a
elif k%2 and n==len(nega):
  # 答えは負
  v=nega[:k]
else:
  # 答えは正
  a=sorted(a, key=lambda x:abs(x), reverse=True)
  pi=ni=-1; cnt=0;
  for i in range(k):
    v.append(a[i])
    if a[i]<0: ni=i; cnt+=1
    if a[i]>0: pi=i;
  if cnt%2:
    mx=max(a[k:]); mn=min(a[k:]);
    if pi>=0 and abs(a[pi]*mx)<=abs(a[ni]*mn):
      v.append(mn); v.remove(a[pi]);
    else:
      v.append(mx); v.remove(a[ni]);

ans=1
for i in range(k):
  ans*=v[i]; ans%=mod;

print(ans)

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

mod=10**9+7

if A[-1]<0 and k%2==1:
    now=1
    for i in range(k):
        now*=A[-i-1]%mod
        now%=mod
    print(now)
    return

l=0
r=n-1
ans=1
if k%2==1:
    ans=A[-1]
    r-=1

for i in range(k//2):
    mi=A[l]*A[l+1]
    pl=A[r]*A[r-1]
    if mi>pl:
        ans*= mi%mod
        ans%=mod
        l+=2
    else:
        ans*= pl%mod
        ans%=mod
        r-=2
print(ans%mod)

import sys
 
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
 
P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0:
  if zero and k%2:
    ans = 0
  else:
    if k%2:
      minus.reverse()
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2:
    ans *= plus[0]
    ans %= mod
    q = 1
  judge = []
  for i in range((len(plus)-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(len(minus)//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod
 
print(ans)

N, K = list(map(int, input().split()))
A = tuple(map(int, input().split()))
MOD = 10 ** 9 + 7

if K == N:
    ans = 1
    for x in A:
        ans = (ans * x) % MOD
    print(ans)
    return

plus, minus = [], []
for a in A:
    if a >= 0:
        plus.append(a)
    else:
        minus.append(a)

plus.sort(reverse=True)
minus.sort()

if not plus:
    ans = 1
    if K % 2:
        # 答えは負値になるので絶対値小さいのを取る
        for x in minus[-K:]:
            ans = (ans * x) % MOD
    else:
        # 答えは非負値になるので絶対値大きいのを取る
        for x in minus[:K]:
            ans = (ans * x) % MOD
    print(ans)
    return

idx = 0
for i in range(2, N, 2):
    if K - i < 0:
        break
    if not len(plus) >= K - i + 2:
        idx += 2
        continue
    if len(minus) >= i:
        if minus[i - 2] * minus[i - 1] < plus[K - i + 1] * plus[K - i]:
            break
        else:
            idx += 2

ans = 1
for x in minus[:idx] + plus[:K - idx]:
    ans = (ans * x) % MOD
print(ans)


N,K=map(int, input().split())
A=list(map(int, input().split()))
D,E=[],[]
zcnt,scnt,fcnt=0,0,0
for i in A:
  if i==0:
    zcnt+=1
    D.append(0)
  elif i>0:
    D.append(i)
    scnt+=1
  else:
    E.append(i)
    fcnt+=1
mod=10**9+7
ans=1
#全て使う場合は問答無用でかける
if K==N:
  for i in A:
    ans*=i
    ans%=mod
  print(ans)
  return
#マイナスを奇数個絶対かける→確実に答えはマイナス
if K%2==1 and max(A)<0:
  A=sorted(A)[::-1]
  for i in range(K):
    ans*=A[i]
    ans%=mod
  print(ans)
  return
#絶対0をかけなきゃいけない
if K>scnt+fcnt:
  print(0)
  return
D,E=sorted(D)[::-1],sorted(E)
#print(D,E)
ans=1
cnt=0
a,b=0,0
while K-cnt>1:
  if a+1<=len(D)-1 and b+1<=len(E)-1:
    d,e=D[a]*D[a+1],E[b]*E[b+1]
    if d>e:
      ans*=D[a]
      a+=1
      cnt+=1
      ans%=mod
    else:
      ans*=e
      b+=2    
      ans%=mod
      cnt+=2
  elif a+1<=len(D)-1:
    d=D[a]*D[a+1]
    ans*=D[a]
    a+=1
    cnt+=1
    ans%=mod
  elif b+1<=len(E)-1:
    e=E[b]*E[b+1]
    ans*=e
    b+=2
    cnt+=2
    ans%=mod

if K-cnt==1:
  Z=[]
  if a!=scnt:
    Z.append(D[a])
  if b!=fcnt:
    Z.append(E[-1])
  if 0 in A:
    Z.append(0)
  ans*=max(Z)
  ans%=mod
print(ans)

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

X = sorted([a for a in A if a >= 0])
Y = sorted([a for a in A if a < 0], key=lambda x: abs(x))

if 2 * (min(K, len(Y)) // 2) + len(X) >= K:
    ans = 1
    if K % 2 == 1:
        ans *= X.pop()
        K -= 1

    XX = [(x1 * x2) for x1, x2 in zip(*[iter(X[::-1])] * 2)]
    YY = [(y1 * y2) for y1, y2 in zip(*[iter(Y[::-1])] * 2)]
    ZZ = sorted(XX + YY)

    for i in range(K // 2):
        ans *= ZZ.pop()
        ans %= MOD

    print(ans)

else:
    ans = 1
    Z = sorted(X + Y, key=lambda x: abs(x), reverse=True)
    for i in range(K):
        ans *= Z.pop()
        ans %= MOD
    print(ans)


n,k=map(int,input().split())
a=[int(x) for x in input().split()]
mod=10**9+7
nega=sorted([a[i] for i in range(n) if a[i]<0],reverse=True)

ans=1
if k==n:
  # 全掛け算
  for i in a:
    ans*=i; ans%=mod
elif k%2 and n==len(nega):
  # 答えは負
  for i in range(k):
    ans*=nega[i]; ans%=mod
else:
  # 答えは正
  a=sorted(a, key=lambda x:abs(x), reverse=True)
  pi=ni=-1; cnt=0;
  x=[]
  for i in range(k):
    x.append(a[i])
    if a[i]<0: ni=i; cnt+=1
    if a[i]>0: pi=i;
  if cnt%2:
    t=a[k:]
    mx=max(t)
    mn=min(t)
    if mn>0 or pi==-1: # もう正しかとれる数値が存在していない
      x.append(mx)
      x.remove(a[ni])
    elif mx<=0: # もう負しかとれる数値が存在していない
      #if mx==0: print(0); return;
      x.append(mn)
      x.remove(a[pi])
    elif abs(a[pi]*mx)<=abs(a[ni]*mn):
      x.append(mn)
      x.remove(a[pi])
    else:
      x.append(mx)
      x.remove(a[ni])
  #print(x)
  for i in range(k):
    ans*=x[i]; ans%=mod;

print(ans)

def solve(n,k,a):
    mod = 10**9 + 7
    ans = 1
    l = 0
    r = n-1
    a.sort()
    
    if k%2 == 1:
        ans *= a[r]
        r-=1
    
    if ans < 0:
        ans = 1
        for i in range(k):
            ans*= a[n-i-1]
            ans%= mod
        return ans
    
    for i in range(k//2):
        tmp_min=a[l]*a[l+1]
        tmp_max=a[r]*a[r-1]
        if tmp_max> tmp_min:
            ans*=tmp_max
            ans%=mod
            r-=2
        else:
            ans*= tmp_min
            ans%=mod
            l+=2
    return ans


n, k = map(int, input().split())
A = list(map(int,input().split()))
ans = solve(n,k,A)
print(ans)

import sys
 
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
 
P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0:
  if zero and k%2 == 1:
    ans = 0
  else:
    if k%2:
      minus.reverse()
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2:
    ans *= plus[0]
    ans %= mod
    q = 1
  judge = []
  for i in range((len(plus)-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(len(minus)//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod

print(ans)

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

s = sorted(a,reverse=True)
mod = 10**9 + 7
ans = 1

if k % 2 == 1 and s[0] < 0:
        for i in range(k):
            ans = ans * s[i] % mod
        print(ans)
        return

l = 0
r = n - 1
if k % 2 == 1:
  ans = ans * s[l]
  l += 1

for _ in range(k // 2):
  ml = s[l] * s[l + 1]
  mr = s[r] * s[r - 1]
  if ml > mr:
    ans = ans * ml % mod
    l += 2
  else:
    ans = ans * mr % mod
    r -= 2

print(ans)

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
M = []
m = []
for a in A:
    if a < 0:
        m.append(abs(a))
    else:
        M.append(a)

i = 0
j = 0
tmp = 1
P = 10**9 + 7

if (K%2 == 0 and (len(m)//2*2 + len(M)//2*2) >= K) or (K%2 == 1 and (len(M) + len(m)//2*2) >= K and len(M) > 0):
    m.sort(reverse=True)
    M.sort(reverse=True)
    while K > 0:
        if K >= 2:
            if j+2 <= len(M) and i+2 <= len(m):
                if m[i]*m[i+1] < M[j]*M[j+1]:
                    tmp *= M[j]
                    j += 1
                    K -= 1
                else:
                    tmp *= m[i]*m[i+1]
                    i += 2
                    K -= 2
            elif j+2 <= len(M):
                tmp *= M[j]
                j += 1
                K -= 1
            elif i+2 <= len(m):
                tmp *= m[i]*m[i+1]
                i += 2
                K -= 2
            else:
                tmp *= m[i]*M[j]
        else:
            tmp *= M[j]
            K -= 1
        tmp %= P
else:
    m.sort()
    M.sort()
    for _ in range(K):
        if j+1 <= len(M) and i+1 <= len(m):
            if M[j] < m[i]:
                tmp *= M[j]
                j += 1
            else:
                tmp *= m[i]
                i += 1
        elif j+1 <= len(M):
            tmp *= M[j]
            j += 1
        else:
            tmp *= m[i]
            i += 1
        tmp %= P
    tmp *= -1
    tmp %= P
        
print(tmp)





# coding: utf-8
from functools import reduce


def solve(*args: str) -> str:
    n, k = list(map(int, args[0].split()))
    A = sorted(map(int, args[1].split()))
    mod = 10**9+7

    if n == k:
        return str(reduce(lambda a, b: (a*b) % mod, A, 1))

    if k % 2 and A[-1] < 0:
        return str(reduce(lambda a, b: (a*b) % mod, A[n-k:], 1))

    l, r = 0, n-1
    count = 0
    ret = 1

    if k % 2:
        ret *= A[-1]
        r -= 1
        count += 1

    while count < k-1:
        pos = max(0, A[r]*A[r-1])
        neg = max(0, A[l]*A[l+1])
        if pos <= neg:
            ret *= neg
            l += 2
        else:
            ret *= pos
            r -= 2
        ret %= mod
        count += 2

    return str(ret % mod)


def __starting_point():
    print((solve(*(open(0).read().splitlines()))))

__starting_point()

import math
import sys
N, K = map(int, input().split())
A = [int(x) for x in input().split()]

MOD = 10**9+7
def modinv(a):
    b = MOD
    u = 1
    v = 0
    while b != 0:
        t = a // b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u %= MOD
    if u < 0:
        u += MOD
    return u


def solve(N, K, A):
    A = sorted(A, key=lambda x : abs(x))
    #print(A, file=sys.stderr)

    
    if A[N-K] == 0:
        return 0
    Lpos0, Lneg0, Rpos0, Rneg0 = None, None, None, None
    Lneg, Lpos, Rneg, Rpos = 0, 0, 0, 0

    answer0 = 1
    for i in range(N-K, N):
        if A[i] < 0:
            if Rneg == 0:
                Rneg0 = -A[i]
            Rneg += 1
        else:
            if Rpos == 0:
                Rpos0 = A[i]
            Rpos += 1
        answer0 = (answer0 * abs(A[i])) % MOD

    if Rneg % 2 == 0:
        return answer0

    for i in range(N-K)[::-1]:
        if A[i] < 0:
            if Lneg == 0:
                Lneg0 = -A[i]
            Lneg += 1
        else:
            if Lpos == 0:
                Lpos0 = A[i]
            Lpos += 1

    print(f"{K=}",file=sys.stderr)
    #print(f"{Rneg=}, {Rpos=}, {Rneg0=} {Rpos0=}",file=sys.stderr)
    #print(f"{Lneg=}, {Lpos=}, {Lneg0=} {Lpos0=}",file=sys.stderr)
    #print(f"{Lpos0=}, {Lneg0=}, {Rpos0=} {Rneg0=}",file=sys.stderr)

    #    Lpos Lneg Rpos Rneg
    # A  o    O    O    o
    # B  o    O    x    o      / Rneg * Lpos
    # C  x    O    O    o      / Rpos * Lneg
    # B  o    x    O    o
    # B  o    x    x    o
    # D  x    O    x    o
    # D  x    x    o    o
    # D  x    x    x    o
    if (Lpos0 is not None and Rneg0 is not None
        and Rpos0 is not None and Lneg0 is not None):
        answer1 = (answer0 * modinv(Rneg0) % MOD) * Lpos0 % MOD
        answer2 = (answer0 * modinv(Rpos0) % MOD) * Lneg0 % MOD
        print(f"{Lpos0=}, {Lneg0=}, {Rpos0=} {Rneg0=}",file=sys.stderr)

        print(f"{answer1=} {answer2=}", file=sys.stderr)
        print(f"A {Lpos0*Lneg0=} {Rneg0*Rpos0=}", file=sys.stderr)
        if Lpos0 * Rpos0 > Lneg0 * Rneg0:
            print(f"A1 {answer1=}", file=sys.stderr)
            return answer1
        else:
            print(f"A2 {answer2=}", file=sys.stderr)
            return answer2

    if Lpos0 is not None and Rneg0 is not None:
        print("B", file=sys.stderr)
        return  (answer0 * modinv(Rneg0) % MOD) * Lpos0 % MOD
    if Rpos0 is not None and Lneg0 is not None:
        print("C", file=sys.stderr)
        return  (answer0 * modinv(Rpos0) % MOD) * Lneg0 % MOD

    print("D", file=sys.stderr)
    answer0 = 1
    for i in range(K):
        answer0 = (answer0 * A[i]) % MOD
    return answer0


print(solve(N, K, A))

from collections import defaultdict
def prod(A,k,mod):
  ans = 1
  for i in range(k):
      ans *= A[i]
      ans %= mod
  return ans
def solve():
  N, K = list(map(int, input().split()))
  A = list(map(int, input().split()))
  mod = 10**9+7
  ans = 1
  if K==N:
    return prod(A,N,mod)
  minus = len([a for a in A if a<0])
  if minus==N:
    if K%2==0:
      A.sort()
    else:
      A.sort(reverse=True)
    return prod(A,K,mod)
  if K==1:
    return max(A)
  A.sort(key=lambda x:-abs(x))
  if A[K]==0:
    return 0
  minus = len([a for a in A[:K] if a<0])
  flag = [1]*K+[0]*(N-K)
  d = defaultdict(lambda: -1)
  if minus%2==1:
    for i in range(K,N):
      if A[i]>=0:
        d['p2'] = i
        break
    for i in range(K,N):
      if A[i]<0:
        d['m2'] = i
        break
    for i in range(K-1,-1,-1):
      if A[i]>0:
        d['p1'] = i
        break
    for i in range(K-1,-1,-1):
      if A[i]<0:
        d['m1'] = i
        break
    if d['p2']==-1 or d['m1']==-1:
      flag[d['m2']],flag[d['p1']] = 1,0
    elif d['m2']==-1 or d['p1']==-1:
      flag[d['p2']],flag[d['m1']] = 1,0
    elif A[d['p2']]*A[d['p1']]>A[d['m1']]*A[d['m2']]:
        flag[d['p2']],flag[d['m1']] = 1,0
    else:
      flag[d['m2']],flag[d['p1']] = 1,0
    ans = 1
    for i in range(N):
      if flag[i]==1:
        ans *= A[i]
        ans %= mod
    return ans
  return prod(A,K,mod)
print((solve()))


n,k=map(int,input().split())
a=[int(x) for x in input().split()]
mod=10**9+7
nega=sorted([a[i] for i in range(n) if a[i]<0],reverse=True)

ans=1
if k==n:
  # 全掛け算
  for i in a:
    ans*=i; ans%=mod
elif k%2 and n==len(nega):
  # 答えは負
  for i in range(k):
    ans*=nega[i]; ans%=mod
else:
  # 答えは正
  a=sorted(a, key=lambda x:abs(x), reverse=True)
  pi=ni=-1; cnt=0;
  x=[]
  for i in range(k):
    x.append(a[i])
    if a[i]<0: ni=i; cnt+=1
    if a[i]>0: pi=i;
  if cnt%2:
    t=a[k:]
    mx=max(t)
    mn=min(t)
    if pi==-1:
      x.append(mx)
      x.remove(a[ni])
    elif abs(a[pi]*mx)<=abs(a[ni]*mn):
      x.append(mn)
      x.remove(a[pi])
    else:
      x.append(mx)
      x.remove(a[ni])
  #print(x)
  for i in range(k):
    ans*=x[i]; ans%=mod;

print(ans)

import sys

mod = 10 ** 9 + 7
N, K = map(int,input().split())
A = list(map(int,input().split()))
if all([a < 0 for a in A]):
    if K % 2 == 0:
        A.sort()
        ans = 1
        for i in range(K):
            ans *= A[i]
            ans %= mod
        print(ans)
        return
    else:
        A.sort(reverse = True)
        ans = 1
        for i in range(K):
            ans *= A[i]
            ans %= mod
        print(ans)
        return

A.sort()
l = 0
r = N - 1
ans = 1

if K % 2 == 1:
    ans *= A[r]
    ans %= mod
    r -= 1

for _ in range(K // 2):
    if A[l] * A[l+1] >= A[r] * A[r-1]:
        ans *= A[l] * A[l+1]
        ans %= mod
        l += 2
    else:
        ans *= A[r] * A[r-1]
        ans %= mod
        r -= 2

print(ans)

MOD = 10**9 + 7

def prod(a):
    res = 1
    for x in a:
        res = (res * x) % MOD
    return res

def solve(n, k, a):
    if k == 1:
        return max(a)
    elif k == n:
        return prod(a)
    elif (max(a) < 0) and (k % 2 == 1):
        a = sorted(a, reverse=True)
        return prod(a[:k])
    else:
        a = sorted(a, key=lambda x: -abs(x))
        num_negative = len(list(filter(lambda x: x < 0, a[:k])))
        if num_negative % 2 == 0:
            return prod(a[:k])
        else:
            i1, j1 = None, None
            for i in range(k):
                if a[i] < 0:
                    i1 = i
            for j in range(k,n):
                if a[j] >= 0:
                    j1 = j
                    break
            i2, j2 = None, None
            for i in range(k):
                if a[i] >= 0:
                    i2 = i
            for j in range(k, n):
                if a[j] < 0:
                    j2 = j
                    break
            if ((i1 is None) or (j1 is None)) and ((i2 is None) or (j2 is None)):
                return prod(a[:k])
            elif (i1 is None) or (j1 is None):
                return prod(a[:i2] + a[i2+1:k] + [a[j2]])
            elif (i2 is None) or (j2 is None):
                return prod(a[:i1] + a[i1+1:k] + [a[j1]])
            elif abs(a[j1] * a[i2]) > abs(a[i1] * a[j2]):
                return prod(a[:i1] + a[i1+1:k] + [a[j1]])
            else:
                return prod(a[:i2] + a[i2+1:k] + [a[j2]])

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

import sys
 
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
 
P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0 and k%2 ==1 :
  if zero >= 1:
    ans = 0
  else:
    minus.sort(reverse=True)
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2:
    ans *= plus[0]
    ans %= mod
    q = 1
  judge = []
  for i in range((len(plus)-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(len(minus)//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod
 
print(ans)

def abc173_e():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    mod = 10**9 + 7

    A.sort(reverse=True)  # 符号付きの大きい順
    B = sorted(A, key=lambda x: abs(x), reverse=True)  # 絶対値の大きい順
    C = []

    if k == n:
        C = A  # 全部使う
    elif k % 2 == 1 and A[0] < 0:
        C = A[:k]  # 絶対値小さい順にk個
    else:
        plus = []
        minus = []
        for b in B[:k]:
            if b >= 0: plus.append(b)
            else: minus.append(b)

        if len(minus) % 2 == 1:
            # 積が負になるので入れ替え検討
            rem1, add1, rem2, add2 = None, None, None, None

            rem1 = minus[-1]  # 負値の絶対値最小
            add1 = max(B[k:])  # 残りものの正値の絶対値最大
            valid1 = (add1 >= 0)

            valid2 = False
            if plus:
                rem2 = plus[-1]
                add2 = min(B[k:])  # 負値の絶対値最大
                valid2 = (add2 < 0)

            if valid1 and valid2:
                if add1 * rem2 > rem1 * add2:
                    minus[-1] = add1
                else:
                    plus[-1] = add2
            elif valid1:
                minus[-1] = add1
            elif valid2:
                plus[-1] = add2

        C = plus + minus

    ans = 1
    for c in C:
        ans *= c
        if ans < 0: ans += mod
        ans %= mod
    print(ans)

def __starting_point():
    abc173_e()
__starting_point()

MOD = 10 ** 9 + 7

n,k=map(int, input().split())
a=list(map(int, input().split()))
aplus,aminus=[],[]

for i in range(n):
    if a[i] >= 0: aplus.append(a[i])
    else: aminus.append(a[i])

      
if len(aplus) == 0 and k % 2 == 1:
    asort = sorted(a,reverse=True)
    ans = 1
    for i in range(k):
        ans = (ans * asort[i]) % MOD
    print(ans)
    return

if n == k:
    ans = 1
    for i in range(k):
        ans = (ans * a[i]) % MOD
    print(ans)
    return

newa = sorted(a,reverse=True,key=abs)
newaplus = sorted(aplus,reverse = True)
newaminus = sorted(aminus)

cntp,cntm,pp,mm=0,0,0,0

for i in range(k):
    if newa[i] >= 0:
        cntp += 1
        pp = i
    else:
        cntm += 1
        mm = i

if cntm % 2 == 1:
    if cntp == 0:
        newa[mm] = newaplus[cntp]
    elif len(newaplus) == cntp:
        newa[pp] = newaminus[cntm]
    elif len(newaminus) == cntm:
        newa[mm] = newaplus[cntp]
    else:
        if newa[pp] * newaplus[cntp] >= newa[mm] * newaminus[cntm]:
            newa[mm] = newaplus[cntp]
        else:
            newa[pp] = newaminus[cntm]

ans = 1
for i in range(k):
    ans = (ans * newa[i]) % MOD
    
print(ans)

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

A_neg = []
A_pos = []

for i in range(N):
  if A[i] <= 0:
    A_neg.append(-A[i])
  else:
    A_pos.append(A[i])

A_neg.sort(reverse=True)
A_pos.sort(reverse=True)

ans = 1

if K == N:
  for i in range(N):
    ans *= (A[i]%1000000007)
    ans %= 1000000007
  print(ans)

elif K%2==1 and len(A_pos)==0:
  for i in range(1, K+1):
    ans *= ((-A_neg[-i])%1000000007)
    ans %= 1000000007
  print(ans)

else:
  if K%2==1:
    ans *= A_pos.pop(0)
    K -= 1
  buf = []
  for i in range(len(A_pos)//2):
    buf.append(A_pos[2*i]*A_pos[2*i+1])
  for i in range(len(A_neg)//2):
    buf.append(A_neg[2*i]*A_neg[2*i+1])
  buf.sort(reverse=True)
  for i in range(K//2):
    ans *= (buf[i]%1000000007)
    ans %= 1000000007
  print(ans)
  



from math import log
mod = int(1e9) + 7
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()

def sign(v):
    if v == 0:
        return 0
    return 1 if v > 0 else -1

pref = [(0, 1)] * (n + 1)
suf = [(0, 1)] * (n + 1)

c = 1
sm = 0
sgn = 1
for j in range(n):
    c = c * a[j] % mod
    sgn *= sign(a[j])
    if a[j] != 0:
        sm += log(abs(a[j]))
    pref[j + 1] = (sgn * sm, c, sgn)

c = 1
sm = 0
sgn = 1
for j in range(n):
    c = c * a[n - j - 1] % mod
    sgn *= sign(a[n - j - 1])
    if a[n - j - 1] != 0:
        sm += log(abs(a[n - j - 1]))
    suf[j + 1] = (sgn * sm, c, sgn)

m = max(pref[k], suf[k])
for i in range(1, k):
    sgn = pref[i][2] * suf[k - i][2]
    pm = pref[i][1] * suf[k - i][1] % mod
    sm = abs(pref[i][0]) + abs(suf[k - i][0])
    m = max(m, (sgn * sm, pm, sgn))

    
print((m[1]))


n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = pow(10, 9) + 7
neg = 0
zero = 0
for i in range(n):
    if a[i] >= 0:
        if a[i] == 0:
            zero += 1
        a[i] = [a[i], 1]
    else:
        a[i] = [-a[i], 0]
        neg += 1
a.sort(reverse = True)
ans = 1
if n == k:
    for i in range(n):
        ans *= a[i][0]
        ans %= mod
        if not a[i][1]:
            ans *= -1
            ans %= mod
elif k % 2 == 1 and (neg == n or neg + zero == n):
    for i in range(1, k + 1):
        ans *= -a[-i][0]
        ans %= mod
else:
    pos, neg = 0, 0
    lastpos, lastneg = mod, mod
    for i in range(k):
        ans *= a[i][0]
        ans %= mod
        if a[i][1]:
            pos += 1
            lastpos = a[i][0]
        else:
            neg += 1
            lastneg = a[i][0]
    if neg % 2 == 1:
        firstpos, firstneg = mod, mod
        for i in range(k, n):
            if not firstpos == mod and not firstneg == mod:
                break
            if firstpos == mod and a[i][1]:
                firstpos = a[i][0]
            elif firstneg == mod and not a[i][1]:
                firstneg = a[i][0]
        if not mod in [lastpos, lastneg, firstpos, firstneg]:
            if firstpos * lastpos >= firstneg * lastneg:
                ans = ans * pow(lastneg, mod - 2, mod) * firstpos % mod
            else:
                ans = ans * pow(lastpos, mod - 2, mod) * firstneg % mod
        elif not mod in [lastpos, firstneg]:
            ans = ans * pow(lastpos, mod - 2, mod) * firstneg % mod
        elif not mod in [lastneg, firstpos]:
            ans = ans * pow(lastneg, mod - 2, mod) * firstpos % mod
print(ans)

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


mod=10**9+7

if A[-1]<0 and k%2==1:
    now=1
    for i in range(k):
        now*=A[-i-1]%mod
        now%=mod
    print(now) ;return

l=0 ; r=n-1
ans=1
if k%2==1:
    ans=A[-1]
    r-=1

for i in range(k//2):
    mi=A[l]*A[l+1]
    pl=A[r]*A[r-1]
    if mi>pl:
        ans*= mi%mod
        ans%=mod
        l+=2
    else:
        ans*= pl%mod
        ans%=mod
        r-=2
print((ans%mod))


# coding: utf-8
N,K=map(int,input().split())
A=list(map(int,input().split()))
MOD=10**9+7

ans=1

if K==N:
    for i in range(N):
        ans*=A[i]
        if ans>0:
            ans=ans%MOD
elif max(A)<=0 and K%2==1:
    A.sort(reverse=True)
    for i in range(K):
        ans*=A[i]
        if ans>0:
            ans=ans%MOD
else:
    Ap=[]
    Am=[]
    
    for i in range(N):
        if A[i]>0:
            Ap.append(A[i])
        else:
            Am.append(A[i])
        

    Ap.sort(reverse=True)
    Am.sort()
    
    if K%2==1 and Ap:
        ans*=Ap.pop(0)
    
    P=[]
    
    for i in range(len(Ap)//2):
        P.append(Ap[i*2]*Ap[i*2+1])
    
    for i in range(len(Am)//2):
        P.append(Am[i*2]*Am[i*2+1])
    
    P.sort(reverse=True)
    
    for i in range(K//2):
        ans*=P[i]
        ans=ans%MOD

print(ans%MOD)

N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
A.sort()
mod=10**9+7
ans=1

if K%2==1 and A[-1]<0:
    for i in range(K):
        ans=ans*A[N-(i+1)]%mod
    print(ans)
    return

l=0
r=N-1
if K%2==1:
    ans=ans*A[r]
    r-=1

for _ in range(K//2):
    ml=A[l]*A[l+1]
    mr=A[r]*A[r-1]
    if ml>mr:
        ans=ans*ml%mod
        l+=2
    else:
        ans=ans*mr%mod
        r-=2

print(ans)


# -*- coding: utf-8 -*-
import sys

def main():
    N,K = list(map(int, sys.stdin.readline().split()))
    A_list = list(map(int, sys.stdin.readline().split()))
    

    A_list.sort(key=lambda x: -abs(x))
    A_plus = []
    A_minus = []
    mod = 10**9 + 7

    for val in A_list:
        if val >= 0:
            A_plus.append(val)
        else:
            A_minus.append(val)
    

    if (not A_plus):
        if (K % 2 == 0):
            target_range = list(range(K))
        else:
            target_range = list(range(len(A_minus)-K, len(A_minus)))

        ans = 1

        for i in target_range:
            ans *= A_minus[i]
            ans %= mod
        
        print(ans)
        return


    if (not A_minus):
        ans = 1

        for i in range(K):
            ans *= A_plus[i]
            ans %= mod
        
        print(ans)
        return


    select = []
    i_p = 0  # index of A_plus
    i_m = 0  # index of A_minus


    while (len(select) < K):
        if (K - len(select)) == 1:
            if i_p < len(A_plus):
                select.append( A_plus[i_p] )
                i_p += 1
                break
            
            else:
                ans = 1

                for i in range( len(A_list)-K, len(A_list) ):
                    ans *= A_list[i]
                    ans %= mod

                print(ans)
                return


        if (i_m + 1) < len(A_minus):
            if (i_p + 1) < len(A_plus):
                if abs( A_plus[i_p] * A_plus[i_p + 1] ) > abs( A_minus[i_m] * A_minus[i_m + 1] ):
                    select.append( A_plus[i_p] )
                    i_p += 1
                else:
                    select.extend( [ A_minus[i_m] , A_minus[i_m + 1] ] )
                    i_m += 2

            else:
                select.extend( [ A_minus[i_m] , A_minus[i_m + 1] ] )
                i_m += 2
            
        else:
            select.append( A_plus[i_p] )
            i_p += 1
    

    ans = 1
 
    for i in range(K):
        ans *= select[i]
        ans %= mod
    
    print(ans)
    return

def __starting_point():
    main()

__starting_point()

import sys
input = sys.stdin.readline

def main():
    n,k = map(int, input().split())
    A = sorted(map(int, input().split()))
    mod = 10**9 + 7
    ans, sign = 1, 1

    l, r = 0, n-1

    if k%2:
        ans = A[r]
        r-=1
        k-=1
        if ans < 0:
            sign = -1
    while k:
        x = A[l]*A[l+1]
        y = A[r]*A[r-1]

        if x*sign > y*sign:
            ans = x%mod * ans%mod
            l+=2
        else:
            ans = y%mod * ans%mod
            r-=2
        k-=2
    print((ans+mod)%mod)
main()

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

A_neg = []
A_pos = []

for i in range(N):
  if A[i] <= 0:
    A_neg.append(-A[i])
  else:
    A_pos.append(A[i])

A_neg.sort(reverse=True)
A_pos.sort(reverse=True)

ans = 1

if K == N:
  for i in range(N):
    ans *= (A[i]%1000000007)
    ans %= 1000000007
  print(ans)

elif K%2==1 and len(A_pos)==0:
  for i in range(1, K+1):
    ans *= ((-A_neg[-i])%1000000007)
    ans %= 1000000007
  print(ans)

else:
  if K%2==1:
    ans *= A_pos.pop(0)
    K -= 1
  buf = []
  if len(A_pos)>=2:
    for i in range(len(A_pos)//2):
      buf.append(A_pos[2*i]*A_pos[2*i+1])
  if len(A_neg)>=2:
    for i in range(len(A_neg)//2):
      buf.append(A_neg[2*i]*A_neg[2*i+1])
  buf.sort(reverse=True)
  for i in range(K//2):
    ans *= (buf[i]%1000000007)
    ans %= 1000000007
  print(ans)
  



# -*- coding: utf-8 -*-
import sys

def main():
    N,K = list(map(int, sys.stdin.readline().split()))
    A_list = list(map(int, sys.stdin.readline().split()))
    

    A_list.sort(key=lambda x: -abs(x))
    A_plus = []
    A_minus = []
    mod = 10**9 + 7

    for val in A_list:
        if val >= 0:
            A_plus.append(val)
        else:
            A_minus.append(val)
    

    select = []
    i_p = 0  # index of A_plus
    i_m = 0  # index of A_minus

    
    while (len(select) < K):
        if (K - len(select)) == 1:
            if i_p < len(A_plus):
                select.append( A_plus[i_p] )
                i_p += 1
                break
            
            else:
                ans = 1

                for i in range( len(A_list)-K, len(A_list) ):
                    ans *= A_list[i]
                    ans %= mod

                print(ans)
                return


        if (i_m + 1) < len(A_minus):
            if (i_p + 1) < len(A_plus):
                if abs( A_plus[i_p] * A_plus[i_p + 1] ) > abs( A_minus[i_m] * A_minus[i_m + 1] ):
                    select.append( A_plus[i_p] )
                    i_p += 1
                else:
                    select.extend( [ A_minus[i_m] , A_minus[i_m + 1] ] )
                    i_m += 2

            else:
                select.extend( [ A_minus[i_m] , A_minus[i_m + 1] ] )
                i_m += 2
            
        else:
            select.append( A_plus[i_p] )
            i_p += 1
    


    ans = 1
 
    for i in range(K):
        ans *= select[i]
        ans %= mod
    
    print(ans)
    return


def __starting_point():
    main()

__starting_point()

def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    mod = 10 ** 9+ 7
    ans = 1

    def answer(a):
        ans =1
        for x in a:
            ans *= x
            ans %= mod
        return ans

    if n == k:
        print(answer(a))
        return
    a.sort(reverse=True, key= lambda x:abs(x))
    if sum(x<0 for x in a[:k])%2 == 0:
        print(answer(a[:k]))
    else:
        if all(x < 0 for x in a):
            print(answer(a[-k:]))
        else:
            try:
                x1, y1= min([x for x in a[:k] if x > 0]), min([x for x in a[k:] if x < 0])
            except ValueError:
                x1, y1 = 1, 0
            try:
                x2, y2= max([x for x in a[:k] if x < 0]),\
                    max([x for x in a[k:] if x >= 0])
            except ValueError:
                x2, y2 = 1, 0
            if abs(x2*y1) > abs(x1*y2):           
                a[a.index(x1)] = y1
            else:
                a[a.index(x2)] = y2
            print(answer(a[:k]))
            


def __starting_point():
    main()
__starting_point()

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

mod=10**9+7

if A[-1]<0 and k%2==1:
    now=1
    for i in range(k):
        now= now*A[-i-1]%mod
        # now%=mod
    print(now) ;return

l=0 ; r=n-1
ans=1
if k%2==1:
    ans=A[-1]
    r-=1

for i in range(k//2):
    mi=A[l]*A[l+1]
    pl=A[r]*A[r-1]
    if mi>pl:
        ans= ans*mi%mod
        l+=2
    else:
        ans= ans*pl%mod
        r-=2
print((ans%mod))


import sys
 
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
 
P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0:
  if zero >= 1 and k%2 == 1:
    ans = 0
  else:
    if k%2:
      minus.reverse()
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2:
    ans *= plus[0]
    ans %= mod
    q = 1
  judge = []
  for i in range((len(plus)-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(len(minus)//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod
 
print(ans)

# -*- coding: utf-8 -*-
import sys

def main():
    N,K = list(map(int, sys.stdin.readline().split()))
    A_list = list(map(int, sys.stdin.readline().split()))


    A_list.sort(key=lambda x: -abs(x))
    mod = 10**9 + 7

    L_plus  = R_plus  = -1 # the Index of plus value
    L_minus = R_minus = -1 # the Index of minus value
    # L : between index 0 to (K-1)
    # R : between index K to end


    for i in range(K-1, -1, -1):
        if (L_plus == -1) and (A_list[i] >= 0):
            L_plus = i
        if (L_minus == -1) and (A_list[i] < 0):
            L_minus = i
        if (L_plus != -1) and (L_minus != -1):
            break
    
    for i in range(K,N):
        if (R_plus == -1) and (A_list[i] >= 0):
            R_plus = i
        if (R_minus == -1) and (A_list[i] < 0):
            R_minus = i
        if (R_plus != -1) and (R_minus != -1):
            break


    cnt_minus = 0

    for i in range(K):
        if A_list[i] < 0:
            cnt_minus += 1


    if cnt_minus % 2 == 0:
        target_idx = [0, K-1]
    
    else: # cnt_minus % 2 != 0
        if (R_plus == -1) and \
           ( (L_plus == -1) or (R_minus == -1) ) :
        
            calc1 = calc2 = 0
        
        elif (R_plus != -1) and \
           ( (L_plus == -1) or (R_minus == -1) ) :
        
            calc1 = 1
            calc2 = 0
        
        elif (R_plus == -1) and \
           ( (L_plus != -1) and (R_minus != -1) ) :
        
            calc1 = 0
            calc2 = 1
        
        elif (R_plus != -1) and \
           ( (L_plus != -1) and (R_minus != -1) ) :
            
            calc1 = A_list[L_plus] * A_list[R_plus]
            calc2 = A_list[L_minus] * A_list[R_minus]


        if calc1 == calc2:
            target_idx = [N-K, N-1]
        
        elif calc1 > calc2:
            A_list[L_minus], A_list[R_plus] = A_list[R_plus], A_list[L_minus]
            target_idx = [0, K-1]

        elif calc1 < calc2:
            A_list[L_plus], A_list[R_minus] = A_list[R_minus], A_list[L_plus]
            target_idx = [0, K-1]


    ans = 1

    for i in range( target_idx[0], (target_idx[1] + 1) ):
        ans *= A_list[i]
        ans %= mod
    
    print(ans)


def __starting_point():
    main()

__starting_point()

def myabs(n):
    n = int(n)
    if n>0:
        return [n,1]
    else:
        return [abs(n),-1]


N,K = map(int,input().split())
A = list(map(myabs, input().split()))
A.sort(reverse=True)
Mod = 10**9+7

def main(n,k,a,mod):
    flag = True
    for i in a:
        if i[1]==1:
            flag = False
            break
    if k%2==0:
        flag = False

    #All elements are negative and odd k
    if flag:
        ans = 1
        for i in range(n-1,n-1-k,-1):
            ans *= (a[i][0]*(-1))%mod
            ans %= mod
        print(ans)
    else:
        ans = [1,1]
        neg_flag = False
        min_neg = -1
        min_pos = -1
        for i in range(k):
            if a[i][1]==-1:
                if neg_flag == True:
                    neg_flag = False
                    ans[1] *= a[i][0]
                    ans[0] = ans[1]
                else:
                    neg_flag = True
                    ans[1] *= a[i][0]
                    min_neg = i
            else:
                ans[0] *= a[i][0]
                ans[1] *= a[i][0]
                min_pos = i
            ans[0] %= mod
            ans[1] %= mod

        if neg_flag and n!=k:
            next_pos = -1
            next_neg = -1
            for i in range(k,n):
                if next_pos==-1 and a[i][1]==1:
                    next_pos = a[i][0]
                elif next_neg==-1 and a[i][1]==-1:
                    next_neg = a[i][0]
                if next_pos>=0 and next_neg>=0:
                    break
            if min_pos==-1:
                ans[0] *= next_pos%mod
                ans[0] %= mod
                print(ans[0])
            elif a[min_neg][0]*next_neg>a[min_pos][0]*next_pos:
                fin_ans = 1
                for i in range(k):
                    if i!=min_pos:
                        fin_ans *= a[i][0]%mod
                        fin_ans %= mod
                fin_ans *= next_neg%mod
                fin_ans %= mod
                print(fin_ans)
            else:
                fin_ans = 1
                for i in range(k):
                    if i!=min_neg:
                        fin_ans *= a[i][0]%mod
                        fin_ans %= mod
                fin_ans *= next_pos%mod
                fin_ans %= mod
                print(fin_ans)
        elif n==k and neg_flag:
            print((ans[1]*-1)%mod)
        else:
            print(ans[1])




def __starting_point():
    main(N,K,A,Mod)
__starting_point()

import sys
from collections import deque

import bisect


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


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

    #    print(A)
    pp = int(bisect.bisect_left(A, 0))
    A_minus = deque(A[:pp])
    A_plus = deque(A[pp:])

    AA = deque([])
    AAm = deque([])
    if N == K:
        ans = 1
        for i in A:
            ans *= i
            ans %= mod
        print((ans % mod))

    elif K % 2 == 0:
        ans = 1

        while len(A_minus) >= 2:
            a1 = A_minus.popleft()
            a2 = A_minus.popleft()
            AAm.append(a1 * a2)

        while len(A_plus) >= 2:
            a1 = A_plus.pop()
            a2 = A_plus.pop()
            AA.append(a1 * a2)

        for i in range(K // 2):
            if len(AAm) == 0:
                temp = AA.popleft()
            elif len(AA) == 0:
                temp = AAm.popleft()
            elif AAm[0] > AA[0]:
                temp = AAm.popleft()
            else:
                temp = AA.popleft()
            ans *= temp
            ans %= mod
        print((ans % mod))

    elif len(A_plus) == 0:
        ans = 1
        for i in range(K):
            ans *= A_minus.pop()
            ans %= mod
        print((ans % mod))

    else:
        ans = A_plus.pop()

        while len(A_minus) >= 2:
            a1 = A_minus.popleft()
            a2 = A_minus.popleft()
            AAm.append(a1 * a2)

        while len(A_plus) >= 2:
            a1 = A_plus.pop()
            a2 = A_plus.pop()
            AA.append(a1 * a2)

        for i in range(K // 2):
            if len(AAm) == 0:
                temp = AA.popleft()
            elif len(AA) == 0:
                temp = AAm.popleft()
            elif AAm[0] > AA[0]:
                temp = AAm.popleft()
            else:
                temp = AA.popleft()
            ans *= temp
            ans %= mod
        print((ans % mod))


def __starting_point():
    main()

__starting_point()

N,K = map(int, input().split())
A = [int(a) for a in input().split()]
mod = 10**9+7

P = []
M = []
z = 0
for a in A:
    if a > 0:
        P.append(a)
    elif a < 0:
        M.append(a)
    else:
        z += 1

P.sort()
M.sort()
ans = 1
if len(M) == 0 or N == K:
    A.sort(reverse=True)
    for i in range(K):
        ans *= A[i]
        ans %= mod
elif len(P) == 0:
    if K%2 == 0 and len(M) >= K:
        for i in range(K):
            ans *= M[i]
            ans %= mod
    elif K%2 == 1 and z == 0:
        for i in range(-1, -K-1, -1):
            ans *= M[i]
            ans %= mod
    else:
        ans = 0
elif N-z < K or (N-z == K and len(M)%2 == 1):
    ans = 0
else:
    L = []
    for i in range(N):
        if A[i] == 0:
            continue
        L.append((abs(A[i]), A[i]))
    L.sort(reverse=True)
    cnt = 0
    lp = -1
    lm = -1
    for i in range(K):
        if L[i][1] > 0:
            lp = i
        else:
            lm = i
            cnt += 1
        ans *= L[i][0]
        ans %= mod
    if cnt%2 == 1:
        p = -1
        m = -1
        for i in range(K, len(L)):
            if p > 0 and m > 0:
                break
            if L[i][1] > 0 and p < 0:
                p = L[i][0]
            elif L[i][1] < 0 and m < 0:
                m = L[i][0]
        if p < 0:
            ans *= m*pow(L[lp][0], mod-2, mod)
        elif m < 0:
            ans *= p*pow(L[lm][0], mod-2, mod)
        elif lp >= 0 and L[lm][0]*m > L[lp][0]*p:
            ans *= m*pow(L[lp][0], mod-2, mod)
        else:
            ans *= p*pow(L[lm][0], mod-2, mod)
        ans %= mod
print(ans)

DE = 10**9 + 7
N, K = list(map(lambda x: int(x), input().split(' ')))
A = list(map(lambda x: int(x), input().split(' ')))

def main():
  A_posi = []
  A_nega = []
  for a in A:
    if a > 0:
      A_posi.append(a)
    elif a < 0:
      A_nega.append(-a)

  len_posi = len(A_posi)
  len_nega = len(A_nega)
  
  if len_posi + len_nega < K:
    return 0

  if (len_nega % 2 == 1 and K == len_posi + len_nega) or (K % 2 == 1 and len_posi == 0):
    if len_posi + len_nega == N:
      A_posi.sort()
      A_nega.sort()
      answer = 1
      k = 0
      for a in A_nega:
        answer *= (- a) % DE
        answer %= DE
        k += 1
        if k >= K:
          break
      else:
        for a in A_posi:
          answer *= a % DE
          answer %= DE
          k += 1
          if k >= K:
            break
      return answer
    else:
      return 0
  A_posi.sort(reverse=True)
  A_nega.sort(reverse=True)
  posi = 0
  nega = 0
  answer = 1

  if K % 2 == 1:
    answer = A_posi[0] % DE
    posi = 1

  while posi + nega + 2 <= K:
    p = A_posi[posi] * A_posi[posi + 1] if posi + 1 < len_posi else 0
    n = A_nega[nega] * A_nega[nega + 1] if nega + 1 < len_nega else 0
    if p > n:
      answer *= p % DE
      answer %= DE
      posi += 2
    else:
      answer *= n % DE
      answer %= DE
      nega += 2

  return answer

print(main())

from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

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

import numpy as np

x = np.argsort(list([-abs(x) for x in A]))
B = []
C = []

for xx in x:
    B.append(A[xx])
    C.append(np.sign(A[xx]))

ans = 1
s = 1
flag4 = 0

for i in range(K):
    s *= C[i]

if s < 0:
    p = np.sign(B[K-1])
    flag1 = 0
    for i in range(K-1,-1,-1):
        if C[i] == p*(-1):
            idx1 = i
            flag1 = 1
            break

    flag2 = 0
    for i in range(K,N):
        if C[i] == p*(-1):
            idx2 = i
            flag2 = 1
            break

    flag3 = 0
    if flag1 == 1:
        for i in range(K,N):
            if C[i] == p:
                idx3 = i
                flag3 = 1
                break

    if flag1 and flag2 and flag3:
        if abs(B[K-1])*abs(B[idx3]) <= abs(B[idx1])*abs(B[idx2]):
            B[K-1] = B[idx2]
        else:
            B[idx1] = B[idx3]
    elif flag1 and (not flag2) and flag3:
        B[idx1] = B[idx3]
    elif flag1 and flag2 and (not flag3):
        B[K-1] = B[idx2]
    elif (not flag1) and flag2:
        B[K-1] = B[idx2]
    else:
        flag4 = 1

if flag4:
    for i in range(N-1,N-K-1,-1):
        ans = (ans * (B[i] % mod)) % mod
else:
    for i in range(K):
        ans = (ans * (B[i] % mod)) % mod

print((ans % mod))























mod=1000000007
n,k=map(int, input().split())
lst=list(map(int, input().split()))
lst=sorted(lst)
p=1
if lst[-1]==0 and k%2!=0:
    print(0)
elif lst[-1]<0 and k%2!=0:
    for i in range(n-1,n-k-1,-1):
        #print(p)
        p=(p%mod*lst[i]%mod)%mod
    #print(p)
    print(p%mod)
else:
    j=n-1
    if k%2!=0:
        p*=lst[j]
        k-=1
        j-=1
    k=k//2
    i=0
    for x in range(k):
        if lst[i]*lst[i+1]>lst[j]*lst[j-1]:
            p=(p%mod*lst[i]%mod*lst[i+1]%mod)%mod
            i+=2
        else:
            p=(p%mod*lst[j]%mod*lst[j-1]%mod)%mod
            j-=2
    #print(p)
    print(p%mod)

N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
div=7+10**9
ans=1
t=0
i,j=0,N-1

if A[-1]<0 and K%2==1:
    for i1 in range(N-K,N):
        ans*=A[i1]
        ans%=div
else:
    while t<K-1:
        if A[i]*A[i+1]>A[j]*A[j-1]:
            ans*=A[i]*A[i+1]
            ans%=div
            i+=2
            t+=2
        else:
            ans*=A[j]
            ans%=div
            j+=-1
            t+=1
    if t==K-1:
        ans*=A[j]
        ans%=div

print(ans)

def prod(li, MOD):
    ret = 1
    for a in li:
        ret *= a
        ret %= MOD
    return ret

N, K = list(map(int, input().split()))
MOD = 1_000_000_007
aaa = list(map(int, input().split()))
if N == K:
    print((prod(aaa, MOD)))
    return
aaa.sort(key=lambda x : abs(x))
if sum(a < 0 for a in aaa[-K:]) % 2 == 0:
    print((prod(aaa[-K:], MOD)))
else:
    if all(a <= 0 for a in aaa):
        bbb = aaa[:K]
    else:
        try:
            x1, y1 = min([a for a in aaa[-K:] if a > 0]), min([a for a in aaa[:-K] if a < 0])
        except:
            x1, y1 = 1, 0
        try:
            x2, y2 = max([a for a in aaa[-K:] if a < 0]), max([a for a in aaa[:-K] if a >= 0])
        except:
            x2, y2 = 1, 0
        bbb = aaa[-K:]
        if abs(x2 * y1) > abs(x1 * y2):
            bbb.remove(x1)
            bbb.append(y1)
        else:
            bbb.remove(x2)
            bbb.append(y2)
    print((prod(bbb, MOD)))


#!/usr/bin/env python3
from functools import reduce

mod = 10**9 + 7
n, k, *a = list(map(int, open(0).read().split()))
a.sort(key=lambda x: abs(x))
ans = reduce(lambda a, b: (a * b) % mod, a[-k:])

c = a[-k:]
j = sum(i < 0 for i in c) % 2
if j:
    c = a[-k:]
    neg = [i for i in c if i < 0]
    pos = [i for i in c if i > 0]
    b = sorted(a[:n - k])
    if b == []:
        print(ans)
        return
    if neg == []:
        if pos[0] * b[0] < 0:
            ans = ans * pow(pos[0], mod - 2, mod) * b[0] % mod
        else:
            ans = reduce(lambda a, b: (a * b) % mod, a[:k])
    elif pos == []:
        if neg[0] * b[-1] < 0:
            ans = ans * pow(neg[0], mod - 2, mod) * b[-1] % mod
        else:
            ans = reduce(lambda a, b: (a * b) % mod, a[:k])
    elif pos[0] * b[-1] < neg[0] * b[0] and pos[0] * b[0] < 0:
        ans = ans * pow(pos[0], mod - 2, mod) * b[0] % mod
    elif 0 > b[-1] * neg[0]:
        ans = ans * pow(neg[0], mod - 2, mod) * b[-1] % mod
    else:
        ans = reduce(lambda a, b: (a * b) % mod, a[:k])
print(ans)


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random,resource

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,k = LI()
    a = sorted(LI())

    r = 1
    i = n - 1
    j = 0
    if k % 2 == 1:
        r = a[i]
        i -= 1

    mf = r < 0

    for _ in range(k//2):
        t = a[i] * a[i-1]
        u = a[j] * a[j+1]
        if (not mf and t >= u) or (mf and t < u):
            r *= t
            r %= mod
            i -= 2
        else:
            r *= u
            r %= mod
            j += 2

    return r


print(main())




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

X = sorted([a for a in A if a > 0])
Y = sorted([a for a in A if a < 0], key=lambda x: abs(x))

if 2 * (min(K, len(Y)) // 2) + len(X) >= K:
    ans = 1
    if K % 2 == 1:
        ans *= X.pop()
        K -= 1

    XX = [(x1 * x2) for x1, x2 in zip(*[iter(X[::-1])] * 2)]
    YY = [(y1 * y2) for y1, y2 in zip(*[iter(Y[::-1])] * 2)]
    ZZ = sorted(XX + YY)

    for i in range(K // 2):
        ans *= ZZ.pop()
        ans %= MOD

    print(ans)

elif 0 in A:
    print((0))

else:
    ans = 1
    Z = sorted(X + Y, key=lambda x: abs(x), reverse=True)
    for i in range(K):
        ans *= Z.pop()
        ans %= MOD
    print(ans)


import sys
 
n, k = list(map(int, input().split()))
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
 
P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0 and k%2 ==1 :
  if zero >= 1:
    ans = 0
  else:
    minus.sort(reverse=True)
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2 == 1:
    ans *= plus[0]
    ans %= mod
    q = 1
  judge = []
  for i in range((len(plus)-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(len(minus)//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod
 
print(ans)


MOD = 10**9 + 7

def prod(a):
    res = 1
    for x in a:
        res = (res * x) % MOD
    return res

def solve(n, k, a):
    if k == 1:
        return max(a)
    elif k == n:
        return prod(a)
    elif (max(a) < 0) and (k % 2 == 1):
        a = sorted(a, reverse=True)
        return prod(a[:k])
    else:
        a = sorted(a, key=lambda x: -abs(x))
        num_negative = len(list([x for x in a[:k] if x < 0]))
        if num_negative % 2 == 0:
            return prod(a[:k])
        else:
            i1, j1 = None, None
            for i in range(k):
                if a[i] < 0:
                    i1 = i
            for j in range(k,n):
                if a[j] >= 0:
                    j1 = j
                    break
            i2, j2 = None, None
            for i in range(k):
                if a[i] >= 0:
                    i2 = i
            for j in range(k, n):
                if a[j] < 0:
                    j2 = j
                    break
            if (i1 is None) or (j1 is None):
                return prod(a[:i2] + a[i2+1:k] + [a[j2]])
            elif (i2 is None) or (j2 is None):
                return prod(a[:i1] + a[i1+1:k] + [a[j1]])
            elif abs(a[j1] * a[i2]) > abs(a[i1] * a[j2]):
                return prod(a[:i1] + a[i1+1:k] + [a[j1]])
            else:
                return prod(a[:i2] + a[i2+1:k] + [a[j2]])

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



n,k=list(map(int,input().split()))
a=[int(x) for x in input().split()]
mod=10**9+7
nega=sorted([a[i] for i in range(n) if a[i]<0],reverse=True)

ans=1
if k==n:
  # 全掛け算
  for i in a:
    ans*=i; ans%=mod
elif k%2 and n==len(nega):
  # 答えは負
  for i in range(k):
    ans*=nega[i]; ans%=mod
else:
  # 答えは正
  a=sorted(a, key=lambda x:abs(x), reverse=True)
  pi=ni=-1; cnt=0;
  x=[]
  for i in range(k):
    x.append(a[i])
    if a[i]<0: ni=i; cnt+=1
    if a[i]>0: pi=i;
  if cnt%2:
    mx=max(a[k:]); mn=min(a[k:]);
    if abs(a[pi]*mx)<=abs(a[ni]*mn) and pi>=0:
      x.append(mn); x.remove(a[pi]);
    else:
      x.append(mx); x.remove(a[ni]);
  #print(x)
  for i in range(k):
    ans*=x[i]; ans%=mod;

print(ans)


import numpy as np
N,K=map(int, input().split())
A =list(map(int,input().split()))
MOD = 10 ** 9 + 7
if N==K:
  ans0 = 1
  for a in A[0:N]:
    ans0 *= a
    ans0 %= MOD
  print(ans0)
  return
A=sorted(A)  
if (K%2==1 and A[-1]<0):
  ans1 = 1
  for a in A[N-K:N]:
    ans1 *= a
    ans1 %= MOD
  print(ans1)
  return
 
A=sorted(A, key=lambda x:abs(x), reverse=True)
AA=[np.sign(i) for i in A]
 
ansA = 1
for a in A[0:K]:
  ansA *= a
  ansA %= MOD
ansAA = AA[0:K].count(-1)%2
if ansA==0 or ansAA==0:
  print(ansA)
  return

while ansA>0:
  ansA-=MOD

B1=A[0:K]
C1=A[0:K]
B2=sorted(A[K:N])
Bp=[i for i in A[0:K] if i>0]
Bm=[i for i in A[0:K] if i<0]
 
if B2[0]>0:B2.insert(0,0)
if B2[-1]<0:B2.insert(-1,0)
if not Bp:Bp.insert(0,B1[-1])
if not Bm:Bm.insert(0,B1[0])
  
#print(Bp,Bm,B2)
#print(Bp[-1],B2[0])
B1.remove(Bp[-1])
B1.append(min(B2[0],0))
#print(B1)
ansB = 1
for a in B1[0:K]:
  ansB *= a
  ansB %= MOD
#print(Bm[-1],B2[-1])
C1.remove(Bm[-1])
C1.append(max(B2[-1],0))
 
ansC = 1
for a in C1[0:K]:
  ansC *= a
  ansC %= MOD
#print(B1,C1)
#print(ansB,ansC)
BB1=[np.sign(i) for i in B1]
ansBB1 = BB1[0:K].count(-1)%2
BB2=[np.sign(i) for i in C1]
ansBB2 = BB2[0:K].count(-1)%2
#print(ansBB1,ansBB2)
if ansBB1==1:
  print(ansC)
  return
if ansBB2==1:
  print(ansB)
  return
#print(B2[0]/Bp[-1],B2[-1]/Bm[-1])
#print(Bp[-1]*B2[-1],Bm[0]*B2[0])

#print(abs(Bp[-1]*B2[-1])-abs(Bm[-1]*B2[0]))
#print(ansB,ansC)
if abs(Bp[-1]*B2[-1])-abs(Bm[-1]*B2[0])>=0:
  print(ansC)
else: print(ansB)

import numpy as np
N,K=map(int, input().split())
A =list(map(int,input().split()))
MOD = 10 ** 9 + 7
if N==K:
  ans0 = 1
  for a in A:
    ans0 = ans0*a%MOD
  print(ans0)
  return

A=sorted(A)  
if (K%2==1 and A[-1]<0):
  ans1 = 1
  for a in A[N-K:N]:
    ans1 = ans1*a%MOD
  print(ans1)
  return

A=sorted(A, key=lambda x:abs(x), reverse=True)
AA=[np.sign(i) for i in A]
 
ansA = 1
for a in A[0:K]:
  ansA *= a
  ansA %= MOD
ansAA = AA[0:K].count(-1)%2
if ansA==0 or ansAA==0:
  print(ansA)
  return

B1=A[0:K]
C1=A[0:K]
B2=sorted(A[K:N])
Bp=[i for i in A[0:K] if i>0]
Bm=[i for i in A[0:K] if i<0]

if B2[0]>0:B2.insert(0,0)
if B2[-1]<0:B2.insert(-1,0)
if not Bp:Bp.insert(0,B1[-1])
if not Bm:Bm.insert(0,B1[0])
  
B1.remove(Bp[-1])
B1.append(min(B2[0],0))

ansB = 1
for a in B1[0:K]:
  ansB *= a
  ansB %= MOD

C1.remove(Bm[-1])
C1.append(max(B2[-1],0))
 
ansC = 1
for a in C1[0:K]:
  ansC *= a
  ansC %= MOD

BB1=[np.sign(i) for i in B1]
ansBB1 = BB1[0:K].count(-1)%2
BB2=[np.sign(i) for i in C1]
ansBB2 = BB2[0:K].count(-1)%2
if ansBB1==1:
  print(ansC)
  return
if ansBB2==1:
  print(ansB)
  return

if abs(Bp[-1]*B2[-1])-abs(Bm[-1]*B2[0])>=0:
  print(ansC)
else: print(ansB)

MOD = 10**9 + 7

def modpow(a,n):
    r=1
    while n > 0:
        if n%2==1:
            r = r*a%MOD
        a = a*a % MOD
        n = n//2
    return r

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



As.sort(key=lambda x:abs(x),reverse=True)
As_srt=sorted(As)

if N==K or (As_srt[-1]<0 and K%2==1):
    ans=1
    for i in range(K):
        ans *= As[N-i-1]
        ans %= MOD
    print(ans)
else:
    ans = 1
    sign = 1
    for i in range(K):
        ans *=As[i]
        ans %=MOD
        if As[i]<0:
            sign *= -1
    if sign < 0:
        #print(As,ans) ###
        # ansを正にする
        rm_p=None
        rm_n=None
        for i in range(K):
            if rm_p!=None and rm_n!=None:
                break
            if rm_p==None and As[K-i-1]>0:
                rm_p=As[K-i-1]
            if rm_n==None and As[K-i-1]<0:
                rm_n=As[K-i-1]
        
        apd_zp=None
        apd_n=None
        for i in range(N-K):
            if apd_zp!=None and apd_n!=None:
                break
            if apd_zp==None and As[K+i]>=0:
                apd_zp=As[K+i]
            if apd_n==None and As[K+i]<0:
                apd_n=As[K+i]
        #print(rm_n,rm_p,apd_n,apd_zp) ###

        if rm_n == None or apd_zp == None:
            rm=rm_p
            apd=apd_n
        elif rm_p == None or apd_n == None:
            rm=rm_n
            apd=apd_zp
        else:
            if abs(rm_p * apd_zp) <= abs(rm_n * apd_n):
               rm=rm_p
               apd=apd_n
            else:
                rm=rm_n
                apd=apd_zp
        ans *= apd
        ans %=MOD
        rm_inv = modpow(rm,MOD-2)
        ans *= rm_inv
        ans %= MOD

    print(ans)

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

X = sorted([a for a in A if a >= 0])
Y = sorted([a for a in A if a < 0], key=lambda x: abs(x))
ans = 1

if 2 * (min(K, len(Y)) // 2) + len(X) >= K:
    if K % 2 == 1:
        ans *= X.pop()
        K -= 1

    XX = [(x1 * x2) for x1, x2 in zip(*[iter(X[::-1])] * 2)]
    YY = [(y1 * y2) for y1, y2 in zip(*[iter(Y[::-1])] * 2)]
    ZZ = sorted(XX + YY)

    for i in range(K // 2):
        ans *= ZZ.pop()
        ans %= MOD

else:
    Z = sorted(X + Y, key=lambda x: abs(x), reverse=True)
    for i in range(K):
        ans *= Z.pop()
        ans %= MOD

print(ans)


import numpy as np
N,K=map(int, input().split())
A =list(map(int,input().split()))
MOD = 10 ** 9 + 7
if N==K:
  ans0 = 1
  for a in A[0:N]:
    ans0 *= a
    ans0 %= MOD
  print(ans0)
  return
A=sorted(A)  
if (K%2==1 and A[-1]<0):
  ans1 = 1
  for a in A[N-K:N]:
    ans1 *= a
    ans1 %= MOD
  print(ans1)
  return

A=sorted(A, key=lambda x:abs(x), reverse=True)
AA=[np.sign(i) for i in A]
 
ansA = 1
for a in A[0:K]:
  ansA *= a
  ansA %= MOD
ansAA = AA[0:K].count(-1)%2
if ansA==0 or ansAA==0:
  print(ansA)
  return

#while ansA>0:
#  ansA-=MOD

B1=A[0:K]
C1=A[0:K]
B2=sorted(A[K:N])
Bp=[i for i in A[0:K] if i>0]
Bm=[i for i in A[0:K] if i<0]
 
if B2[0]>0:B2.insert(0,0)
if B2[-1]<0:B2.insert(-1,0)
if not Bp:Bp.insert(0,B1[-1])
if not Bm:Bm.insert(0,B1[0])
  
B1.remove(Bp[-1])
B1.append(min(B2[0],0))

ansB = 1
for a in B1[0:K]:
  ansB *= a
  ansB %= MOD

C1.remove(Bm[-1])
C1.append(max(B2[-1],0))
 
ansC = 1
for a in C1[0:K]:
  ansC *= a
  ansC %= MOD

BB1=[np.sign(i) for i in B1]
ansBB1 = BB1[0:K].count(-1)%2
BB2=[np.sign(i) for i in C1]
ansBB2 = BB2[0:K].count(-1)%2

if ansBB1==1:
  print(ansC)
  return
if ansBB2==1:
  print(ansB)
  return

if abs(Bp[-1]*B2[-1])-abs(Bm[-1]*B2[0])>=0:
  print(ansC)
else: print(ansB)

MOD = 10 ** 9 + 7

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
ans = 1
if N == K:
    for a in A:
        ans = ans * a % MOD
    print(ans)
    return

minus = []
plus = []
for a in A:
    if a < 0:
        minus.append(a)
    else:
        plus.append(a)

if len(minus) == N:
    if K % 2 == 0:
        A.sort()
    else:
        A.sort(reverse=True)
    for i in range(K):
        ans = ans * A[i] % MOD
    print(ans)
    return

minus.sort(reverse=True)
plus.sort()

if  K % 2:
    ans *= plus.pop()

B = []

while len(minus) > 1:
    a = minus.pop()
    b = minus.pop()
    B.append(a * b)

while len(plus) > 1:
    a = plus.pop()
    b = plus.pop()
    B.append(a * b)

B.sort()

for i in range(K // 2):
    ans = ans * B.pop() % MOD

print(ans)


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

mod=10**9+7

if A[-1]<0 and k%2==1:
    now=1
    for i in range(k):
        now*=A[-i-1]%mod
        now%=mod
    print(now)
    return
	
l=0
r=n-1
ans=1
if k%2==1:
    ans=A[-1]
#    print(ans)
    r-=1	
for i in range(k//2):
    mi=A[l]*A[l+1]
#    print(mi)
    pl=A[r]*A[r-1]
#    print(pl)
    if mi>pl:
        ans*= mi%mod
        ans%=mod
        l+=2
    else:
        ans*= pl%mod
        ans%=mod
        r-=2
		
print(ans%mod)

import sys
 
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
 
P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0:
  if zero >= 1 and k%2 == 1:
    ans = 0
  else:
    if k%2 == 1:
      minus.reverse()
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2:
    ans *= plus[0]
    ans %= mod
    q = 1
  judge = []
  for i in range((len(plus)-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(len(minus)//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod
 
print(ans)

N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
A_neg = []
A_pos = []
 
for i in range(N):
  if A[i] <= 0:
    A_neg.append(-A[i])
  else:
    A_pos.append(A[i])
 
A_neg.sort(reverse=True)
A_pos.sort(reverse=True)
 
ans = 1
 
if K == N:
  for i in range(N):
    ans *= (A[i]%1000000007)
    ans %= 1000000007
  print(ans)
 
elif K%2==1 and len(A_pos)==0:
  for i in range(1, K+1):
    ans *= ((-A_neg[-i])%1000000007)
    ans %= 1000000007
  print(ans)
 
else:
  if K%2==1:
    ans *= A_pos.pop(0)
    K -= 1
  buf = []
  for i in range(len(A_pos)//2):
    buf.append(A_pos[2*i]*A_pos[2*i+1])
  for i in range(len(A_neg)//2):
    buf.append(A_neg[2*i]*A_neg[2*i+1])
  buf.sort(reverse=True)
  for i in range(K//2):
    ans *= (buf[i]%1000000007)
    ans %= 1000000007
  print(ans)
  


import sys
 
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
 
P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0 and k%2 ==1 :
  if zero >= 1:
    ans = 0
  else:
    minus.reverse()
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2:
    ans *= plus[0]
    ans %= mod
    q = 1
  judge = []
  for i in range((len(plus)-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(len(minus)//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod
 
print(ans)

from functools import reduce

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
Ap = [a for a in A if a>0]
Am = [a for a in A if a<0]
mod = 10**9+7
if len(Ap) + len(Am) < K:
    print((0))
    return
if len(Ap) + len(Am) == K:
    if 0 in A and len(Am) % 2:
        print((0))
    else:
        ans = reduce(lambda a, b: a * b % mod, Ap+Am, 1)
        print(ans)
    return
Ap.sort(reverse=True)
Am.sort()
if len(Ap) == 0:
    if K%2:
        if 0 in A:
            ans = 0
        else:
            ans = reduce(lambda a, b: a*b%mod, Am[-K:], 1)
    else:
        ans = reduce(lambda a, b: a*b%mod, Am[:K], 1)
    print(ans)
    return

idx_Am = 0
n = 0
ans = 1
for idx_Ap, ap in enumerate(Ap+[0]):
    while idx_Am < len(Am) and n < K and -Am[idx_Am] > ap:
        ans = ans * Am[idx_Am] % mod
        idx_Am += 1
        n += 1
    if n == K:
        break
    n += 1
    idx_Ap += 1
    ans = ans * ap % mod
    if n == K:
        break
else:
    assert False
if idx_Am % 2 == 0:
    print(ans)
else:
    if idx_Ap == len(Ap) or (idx_Am != len(Am) and idx_Ap > 0 and Am[idx_Am] * Am[idx_Am-1] > Ap[idx_Ap] * Ap[idx_Ap-1]):
        ans = ans * Am[idx_Am] * pow(Ap[idx_Ap-1], mod-2, mod) % mod
    else:
        ans = ans * Ap[idx_Ap] * pow(Am[idx_Am-1], mod-2, mod) % mod
    print(ans)


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

s = sorted(a,reverse=True)
mod = 10**9 + 7
ans = 1
#全部の要素が負の数であり奇数個の場合は大きい順に取ったものが答え
if k % 2 == 1 and s[0] < 0:
        for i in range(k):
            ans = ans * s[i] % mod
        print(ans)
        return#終了

l = 0
r = n - 1
#次の処理のための計算　（kが奇数だった場合)
#この処理の必要性
#奇数個だった場合三個のうち二つで正の数の最大値を作れば良い
if k % 2 == 1:
  ans = ans * s[l]
  l += 1


for _ in range(k // 2):
  ml = s[l] * s[l + 1]
  mr = s[r] * s[r - 1]
  if ml > mr:
    ans = ans * ml % mod
    l += 2
  else:
    ans = ans * mr % mod
    r -= 2

print(ans)


from collections import deque

N, K = map(int, input().split())
table = list(map(int, input().split()))
jnum = K - sum(1 for i in table if i >= 0)
num_mins = sum(1 for i in table if i < 0)
q_plus = deque(sorted([i for i in table if i >= 0], reverse=True))
q_mins = deque(sorted([-i for i in table if i < 0], reverse=True))
s_plus = []
s_mins = []
total = 1


# if jnum < 0 or jnum % 2 == 0:
if (K % 2 == 1 and N == num_mins) or (N == K and num_mins % 2 == 1):
    for i in range(K):
        if not q_plus:
            total = -total * q_mins.pop() % (10 ** 9 + 7)
        elif not q_mins:
            total = total * q_plus.pop() % (10 ** 9 + 7)
        elif q_plus[-1] > q_mins[-1]:
            total = -total * q_mins.pop() % (10 ** 9 + 7)
        else:
            total = total * q_plus.pop() % (10 ** 9 + 7)
    total = total % (10 ** 9 + 7)
else:
    for i in range(K):
        if not q_plus:
            s_mins.append(q_mins.popleft())
        elif not q_mins:
            s_plus.append(q_plus.popleft())
        elif q_plus[0] > q_mins[0]:
            s_plus.append(q_plus.popleft())
        else:
            s_mins.append(q_mins.popleft())
    if len(s_mins) % 2 == 1:
        if not q_plus:
            s_plus[-1] = q_mins[0]
        elif not q_mins or not s_plus:
            s_mins[-1] = q_plus[0]
        elif q_mins[0] * s_mins[-1] > q_plus[0] * s_plus[-1]:
            s_plus[-1] = q_mins[0]
        else:
            s_mins[-1] = q_plus[0]
    s_plus.extend(s_mins)
    for j in s_plus:
        total = total * j % (10 ** 9 + 7)


print(total)

n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort()
mod=10**9+7
ans=1
i=0
j=-1
k_1=k
while k_1>1:
  if a[i]*a[i+1]>a[j]*a[j-1]:
    ans=ans*a[i]*a[i+1]%mod
    i+=2
    k_1-=2
  else:
    ans=ans*a[j]%mod
    j-=1
    k_1-=1
if k_1==1:
  ans=ans*a[j]%mod
if a[-1]<0 and k%2==1:
  ans=1
  for i in a[n-k:]:
    ans=ans*i%mod
print(ans)


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


mod=10**9+7

if A[-1]<0 and k%2==1:
    now=1
    for i in range(k):
        now*=A[-i-1]%mod
        now%=mod
    print(now) ;return

l=0 ; r=n-1
ans=1
if k%2==1:
    ans=A[-1]
    r-=1

for i in range(k//2):
    mi=A[l]*A[l+1]
    pl=A[r]*A[r-1]
    if mi>pl:
        ans*= mi%mod
        ans%=mod
        l+=2
    else:
        ans*= pl%mod
        ans%=mod
        r-=2
print((ans%mod))


n,k=map(int,input().split())
a=[int(x) for x in input().split()]
mod=10**9+7
nega=sorted([a[i] for i in range(n) if a[i]<0],reverse=True)

v=[]
if k==n:
  # 全掛け算
  v=a
elif k%2 and n==len(nega):
  # 答えは負
  for i in range(k):
    v.append(nega[i])
else:
  # 答えは正
  a=sorted(a, key=lambda x:abs(x), reverse=True)
  pi=ni=-1; cnt=0;
  for i in range(k):
    v.append(a[i])
    if a[i]<0: ni=i; cnt+=1
    if a[i]>0: pi=i;
  if cnt%2:
    mx=max(a[k:]); mn=min(a[k:]);
    if pi>=0 and abs(a[pi]*mx)<=abs(a[ni]*mn):
      v.append(mn); v.remove(a[pi]);
    else:
      v.append(mx); v.remove(a[ni]);

ans=1
for i in range(k):
  ans*=v[i]; ans%=mod;

print(ans)

MOD = 10 ** 9 + 7

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

alst.sort()

if n == k:
    ans = 1
    for num in alst:
        ans *= num
        ans %= MOD
    print(ans)
    return

if k == 1:
    print((alst[-1] % MOD))
    return

if alst[0] >= 0:
    ans = 1
    alst.sort(reverse = True)
    for i in range(k):
        ans *= alst[i]
        ans %= MOD
    print(ans)
    return

if alst[-1] <= 0:
    ans = 1
    if k % 2 == 1:
        alst = alst[::-1]
    for i in range(k):
        ans *= alst[i]
        ans %= MOD
    print(ans)
    return

blst = []
for num in alst:
    try:
        blst.append([abs(num), abs(num) // num])
    except ZeroDivisionError:
        blst.append([abs(num), 0])
blst.sort(reverse = True,key = lambda x:x[0])
if blst[k - 1] == 0:
    print((0))
    return
    
minus = 0
last_minus = 0
last_plus = 0
ans_lst = []
for i in range(k):
    if blst[i][1] == -1:
        minus += 1
        last_minus = blst[i][0]
    elif blst[i][1] == 1:
        last_plus = blst[i][0]
    else:
        print((0))
        return
    ans_lst.append(blst[i][0])

next_minus = 0
next_plus = 0
flg_minus = False
flg_plus = False

for i in range(k, n):
    if blst[i][1] == -1 and (not flg_minus):
        next_minus = blst[i][0]
        flg_minus = True
    if blst[i][1] == 1 and (not flg_plus):
        next_plus = blst[i][0]
        flg_plus = True
    if (flg_plus and flg_minus) or blst[i][1] == 0:
        break

if minus % 2 == 0:
    ans = 1
    for num in ans_lst:
        ans *= num
        ans %= MOD
    print(ans)

else:
    minus_s = last_minus * next_minus
    plus_s = last_plus * next_plus
    ans = 1
    if minus == k:
        ans_lst.remove(last_minus)
        ans_lst.append(next_plus)
    elif minus_s == plus_s == 0:
        if next_minus == 0:
            ans_lst.remove(last_minus)
            ans_lst.append(next_plus)
        else:
            print((0))
            return
        
    elif minus_s > plus_s:
        ans_lst.remove(last_plus)
        ans_lst.append(next_minus)
    else:
        ans_lst.remove(last_minus)
        ans_lst.append(next_plus)
    for num in ans_lst:
        ans *= num
        ans %= MOD
    print(ans)


n,k=list(map(int,input().split()))
A=list(map(int,input().split()))
mod=10**9+7
flag=0

A.sort()

tmp1=1
tmp2=1

l=0
r=n-1
if k%2==1:
    tmp1=A[-1]%mod
    r-=1
    if A[-1]<0:
        flag=1
for i in range(k//2):
    vl=A[l]*A[l+1]
    vr=A[r]*A[r-1]
    if max(vl,vr)<0:
        flag=1
    if vl>vr:
        l+=2
        tmp1*=vl
    else:
        r-=2
        tmp1*=vr
    tmp1%=mod

from bisect import bisect_right
idx=bisect_right(A,0)
if idx==n:
    idx-=1
l=max(0,idx-1)
r=idx
for i in range(k):
    vl=A[l] if l>=0 else mod
    vr=A[r] if r<n else mod
    if abs(vl)<abs(vr) or r==n:
        l-=1
        tmp2*=vl
    else:
        r+=1
        tmp2*=vr
    tmp2%=mod

if flag==0:
    print(tmp1)
else:
    print(tmp2)



#/usr/bin/python

def solve():
    n, k = list(map(int, input().split()))
    a = sorted(map(int, input().split()), reverse=True)

    mod = 10 ** 9 + 7
    l = 0
    r = n - 1
    ans = 1

    if k % 2 == 1:
        ans = a[0]
        l = 1

    # If the maximum number is negative and k is odd, the answer is the product of the first k numbers.
    if ans < 0:
        mul = 1
        for i in range(k):
            mul = mul * a[i] % mod
        return mul

    # otherwise, multiply the leftmost two products and the rightmost two products, whichever is larger.
    for i in range(k//2):
        l_mul = a[l] * a[l+1]
        r_mul = a[r] * a[r-1]
        if l_mul >= r_mul:
            ans = ans * l_mul % mod
            l += 2
        else:
            ans = ans * r_mul % mod
            r -= 2

    return ans

print((solve()))


n,k=map(int,input().split())
a=[int(x) for x in input().split()]
mod=10**9+7
nega=sorted([a[i] for i in range(n) if a[i]<0],reverse=True)

v=[]
if k==n:
  # 全掛け算
  for i in a:
    v.append(i)
elif k%2 and n==len(nega):
  # 答えは負
  for i in range(k):
    v.append(nega[i])
else:
  # 答えは正
  a=sorted(a, key=lambda x:abs(x), reverse=True)
  pi=ni=-1; cnt=0;
  for i in range(k):
    v.append(a[i])
    if a[i]<0: ni=i; cnt+=1
    if a[i]>0: pi=i;
  if cnt%2:
    mx=max(a[k:]); mn=min(a[k:]);
    if pi>=0 and abs(a[pi]*mx)<=abs(a[ni]*mn):
      v.append(mn); v.remove(a[pi]);
    else:
      v.append(mx); v.remove(a[ni]);

ans=1
for i in range(k):
  ans*=v[i]; ans%=mod;

print(ans)

from copy import deepcopy
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mod = 10 ** 9 + 7
ans = 1
i, j = 0, n - 1
k2 = deepcopy(k)
while k2 > 1:
    if a[i] * a[i + 1] > a[j] * a[j - 1]:
        ans *= a[i] * a[i + 1]
        ans %= mod
        i += 2
        k2 -= 2
    else:
        ans *= a[j]
        j -= 1
        ans %= mod
        k2 -= 1
if k2 == 1:
    ans *= a[j]
    ans %= mod
if a[-1] < 0 and k % 2:
    ans = 1
    for i in range(n - k, n):
        ans *= a[i]
        ans %= mod
print(ans)

MOD = (int) (1e9+7)

def power(a,n):
    if a == 0: return 0
    if n == 0: return 1

    res = 1
    while n > 0:
        if n % 2 == 1: res = res * a % MOD
        a = a * a % MOD
        n //= 2

    return res

def inverse(n):
    return power(n, MOD-2)

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

B = []
pos, neg = 0, 0
for a in A:
    if a > 0:
        B.append([a,1])
        pos += 1
    if a < 0:
        B.append([-a,-1])
        neg += 1
    if a == 0:
        B.append([0,0])
B.sort(reverse=True)

ans, sign  = 1, 1
if N == neg and K % 2 == 1:
    for i in range(K):
        ans *= B[N-1-i][0] 
        ans %= MOD
    print((-ans % MOD))
    return

for i in range(K):
    ans *= B[i][0]
    ans %= MOD
    sign *= B[i][1]

if N == K:
    if sign >= 0: print(ans)
    else: print((-ans % MOD))
    return

if sign < 0:
    out_neg, out_pos = 0, 0
    in_pos, in_neg = 0, 0

    for i in range(K):
        if B[K-1-i][1] < 0:
            out_neg = B[K-1-i][0]
            break
    
    for i in range(K):
        if B[K-1-i][1] > 0:
            out_pos = B[K-1-i][0]
            break
    
    for i in range(N-K):
        if B[K+i][1] > 0:
            in_pos = B[K+i][0]
            break
    
    for i in range(N-K):
        if B[K+i][1] < 0:
            in_neg = B[K+i][0]
            break
    

    if in_neg == 0 or out_pos == 0:
        ans = (ans * in_pos % MOD) * inverse(out_neg) % MOD
    elif in_pos == 0 or out_neg == 0:
        ans = (ans * in_neg % MOD) * inverse(out_pos) % MOD
    else:
        if out_pos * in_pos < out_neg * in_neg:
            ans = (ans * in_neg % MOD) * inverse(out_pos) % MOD
        else:
            ans = (ans * in_pos % MOD) * inverse(out_neg) % MOD
            
print(ans)


n,k=map(int,input().split())
a=[int(x) for x in input().split()]
mod=10**9+7

v=[]
if k==n:
  # 全掛け算
  v=a
elif k%2 and max(a)<0:
  # 答えは負
  v=sorted([a[i] for i in range(n) if a[i]<0],reverse=True)[:k]
else:
  # 答えは正
  a=sorted(a, key=lambda x:abs(x), reverse=True)
  pi=ni=-1; cnt=0;
  for i in range(k):
    v.append(a[i])
    if a[i]<0: ni=i; cnt^=1
    if a[i]>0: pi=i;
  if cnt%2:
    mx=max(a[k:]); mn=min(a[k:]);
    if pi>=0 and abs(a[pi]*mx)<=abs(a[ni]*mn):
      v.append(mn); v.remove(a[pi]);
    else:
      v.append(mx); v.remove(a[ni]);

ans=1
for i in range(k):
  ans*=v[i]; ans%=mod;

print(ans)

N,K=list(map(int, input().split()))
A=list(map(int, input().split()))
D,E=[],[]
zcnt,scnt,fcnt=0,0,0
for i in A:
  if i==0:
    zcnt+=1
    D.append(0)
  elif i>0:
    D.append(i)
    scnt+=1
  else:
    E.append(i)
    fcnt+=1
mod=10**9+7
ans=1
if K==N:
  for i in A:
    ans*=i
    ans%=mod
  print(ans)
  return
#マイナスを奇数個絶対かける→確実に答えはマイナス
if K%2==1 and max(A)<0:
  A=sorted(A)[::-1]
  for i in range(K):
    ans*=A[i]
    ans%=mod
  print(ans)
  return
#絶対0をかけなきゃいけない
if K>scnt+fcnt:
  print((0))
  return
D,E=sorted(D)[::-1],sorted(E)
#print(D,E)
ans=1
cnt=0
a,b=0,0
while K-cnt>1:
  if a+1<=len(D)-1 and b+1<=len(E)-1:
    d,e=D[a]*D[a+1],E[b]*E[b+1]
    if d>e:
      ans*=D[a]
      a+=1
      cnt+=1
      ans%=mod
    else:
      ans*=e
      b+=2    
      ans%=mod
      cnt+=2
  elif a+1<=len(D)-1:
    d=D[a]*D[a+1]
    ans*=D[a]
    a+=1
    cnt+=1
    ans%=mod
  elif b+1<=len(E)-1:
    e=E[b]*E[b+1]
    ans*=e
    b+=2
    cnt+=2
    ans%=mod

if K-cnt==1:
  Z=[]
  if a!=scnt:
    Z.append(D[a])
  if b!=fcnt:
    Z.append(E[-1])
  if 0 in A:
    Z.append(0)
  ans*=max(Z)
  ans%=mod
print(ans)


import numpy as np
N,K=map(int, input().split())
A =list(map(int,input().split()))
MOD = 10 ** 9 + 7
if N==K:
  ans0 = 1
  for a in A:
    ans0 = ans0*a%MOD
  print(ans0)
  return

A=sorted(A)  
if (K%2==1 and A[-1]<0):
  ans1 = 1
  for a in A[N-K:N]:
    ans1 = ans1*a%MOD
  print(ans1)
  return

A=sorted(A, key=lambda x:abs(x), reverse=True)
AA=[np.sign(i) for i in A]
 
ansA = 1
for a in A[0:K]:
  ansA = ansA*a%MOD
ansAA = AA[0:K].count(-1)%2
if ansA==0 or ansAA==0:
  print(ansA)
  return

B1=A[0:K]
C1=A[0:K]
B2=sorted(A[K:N])
Bp=[i for i in A[0:K] if i>0]
Bm=[i for i in A[0:K] if i<0]

if B2[0]>0:B2.insert(0,0)
if B2[-1]<0:B2.insert(-1,0)
if not Bp:Bp.insert(0,B1[-1])
if not Bm:Bm.insert(0,B1[0])
  
B1.remove(Bp[-1])
B1.append(min(B2[0],0))

ansB = 1
for a in B1[0:K]:
  ansB = ansB*a%MOD

C1.remove(Bm[-1])
C1.append(max(B2[-1],0))
 
ansC = 1
for a in C1[0:K]:
  ansC = ansC*a%MOD

BB1=[np.sign(i) for i in B1]
ansBB1 = BB1[0:K].count(-1)%2
BB2=[np.sign(i) for i in C1]
ansBB2 = BB2[0:K].count(-1)%2
if ansBB1==1:
  print(ansC)
  return
if ansBB2==1:
  print(ansB)
  return

if abs(Bp[-1]*B2[-1])-abs(Bm[-1]*B2[0])>=0:
  print(ansC)
else: print(ansB)

import sys
 
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
 
P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0 and k%2 ==1 :
  if zero >= 1:
    ans = 0
  else:
    minus.sort(reverse=True)
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2 == 1:
    ans *= plus[0]
    ans %= mod
    q = 1
  judge = []
  for i in range((P-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(M//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod
 
print(ans)

import sys
 
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
 
P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0 and k%2 ==1 :
  if zero >= 1:
    ans = 0
  else:
    minus.sort(reverse=True)
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2 == 1:
    ans *= plus[0]
    q = 1
  judge = []
  for i in range((P-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(M//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod
 
print(ans)

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

def solve():
    A.sort(key=lambda x: abs(x), reverse=True)

    ans = 1
    nneg = 0
    a, b, c, d = -1, -1, -1, -1
    for k in range(K):
        ans = (ans * A[k])%MOD
        if A[k] < 0:
            nneg += 1
            b = k
        else:
            a = k
    
    if K == N or nneg%2 == 0:
        return ans
    
    for k in range(N-1, K-1, -1):
        if A[k] < 0:
            d = k
        else:
            c = k

    # b must be >= 0
    if a == -1 and c == -1: # all minus
        ans = 1
        for k in range(K):
            ans = (ans * A[-1-k])%MOD
        return ans
    
    if a == -1 or d == -1:
        outn = A[b]
        inn = A[c]
    elif c == -1:
        outn = A[a]
        inn = A[d]
    else:
        if A[a]*A[c] > A[b]*A[d]:
            outn = A[b]
            inn = A[c]
        else:
            outn = A[a]
            inn = A[d]

    ans = (ans * pow(outn, MOD-2, MOD))%MOD
    ans = (ans * inn)%MOD
    return ans

def __starting_point():
    print((solve()))

__starting_point()

import sys

sys.setrecursionlimit(10 ** 7)
# import bisect
# import numpy as np
# from collections import deque
from collections import deque
# map(int, sys.stdin.read().split())
#import itertools
#import heapq
import bisect


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


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

    #    print(A)
    pp = int(bisect.bisect_left(A,0))
    A_minus = deque(A[:pp])
    A_plus = deque(A[pp:])

    #    print(A_plus)
    #    print(A_minus)
    AA = deque([])
    AAm = deque([])
    if N == K:
        ans = 1
        for i in A:
            ans *= i % mod
            ans %=mod
        print((ans % mod))

    elif K % 2 == 0:
        ans = 1

        while len(A_minus) >= 2:
            a1 = A_minus.popleft()
            a2 = A_minus.popleft()
            AAm.append(a1 * a2)

        while len(A_plus) >= 2:
            a1 = A_plus.pop()
            a2 = A_plus.pop()
            AA.append(a1 * a2)


        for i in range(K // 2):
            if len(AAm)==0:
                temp = AA.popleft()
            elif len(AA) ==0:
                temp = AAm.popleft()
            elif AAm[0] > AA[0]:
                temp = AAm.popleft()
            else:
                temp = AA.popleft()
            ans *= temp % mod
            ans %=mod
        print((ans % mod))

    elif len(A_plus) == 0:
        ans = 1
        for i in range(K):
            ans *= A_minus.pop() % mod
            ans %=mod
        print((ans % mod))

    else:
        ans = A_plus.pop()

        while len(A_minus) >= 2:
            a1 = A_minus.popleft()
            a2 = A_minus.popleft()
            AAm.append(a1 * a2)

        while len(A_plus) >= 2:
            a1 = A_plus.pop()
            a2 = A_plus.pop()
            AA.append(a1 * a2)

        for i in range(K // 2):
            if len(AAm) == 0:
                temp = AA.popleft()
            elif len(AA) == 0:
                temp = AAm.popleft()
            elif AAm[0] > AA[0]:
                temp = AAm.popleft()
            else:
                temp = AA.popleft()
            ans *= temp
            ans %=mod
        print((ans % mod))
def __starting_point():
    main()

__starting_point()

# -*- coding: utf-8 -*-
import sys

def main():
    N,K = list(map(int, sys.stdin.readline().split()))
    A_list = list(map(int, sys.stdin.readline().split()))


    A_list.sort(key=lambda x: -abs(x))
    mod = 10**9 + 7

    L_plus  = R_plus  = -1 # the Index of plus value
    L_minus = R_minus = -1 # the Index of minus value
    # L : between index 0 to (K-1)
    # R : between index K to end


    for i in range(K-1, -1, -1):
        if (L_plus == -1) and (A_list[i] >= 0):
            L_plus = i
        if (L_minus == -1) and (A_list[i] < 0):
            L_minus = i
        if (L_plus != -1) and (L_minus != -1):
            break
    
    for i in range(K,N):
        if (R_plus == -1) and (A_list[i] >= 0):
            R_plus = i
        if (R_minus == -1) and (A_list[i] < 0):
            R_minus = i
        if (R_plus != -1) and (R_minus != -1):
            break


    cnt_minus = 0

    for i in range(K):
        if A_list[i] < 0:
            cnt_minus += 1


    if cnt_minus % 2 == 0:
        target = A_list[:K]
    
    else: # cnt_minus % 2 != 0
        if (R_plus == -1) and \
           ( (L_plus == -1) or (R_minus == -1) ) :
        
            calc1 = calc2 = 0
        
        elif (R_plus != -1) and \
           ( (L_plus == -1) or (R_minus == -1) ) :
        
            calc1 = 1
            calc2 = 0
        
        elif (R_plus == -1) and \
           ( (L_plus != -1) and (R_minus != -1) ) :
        
            calc1 = 0
            calc2 = 1
        
        elif (R_plus != -1) and \
           ( (L_plus != -1) and (R_minus != -1) ) :
            
            calc1 = A_list[L_plus] * A_list[R_plus]
            calc2 = A_list[L_minus] * A_list[R_minus]


        if calc1 == calc2:
            target = A_list[N-K:N]
        
        elif calc1 > calc2:
            A_list[L_minus], A_list[R_plus] = A_list[R_plus], A_list[L_minus]
            target = A_list[:K]

        elif calc1 < calc2:
            A_list[L_plus], A_list[R_minus] = A_list[R_minus], A_list[L_plus]
            target = A_list[:K]


    ans = 1

    for i in range(len(target)):
        ans *= target[i]
        ans %= mod
    
    print(ans)


def __starting_point():
    main()

__starting_point()

n,k=map(int,input().split())
a=[int(x) for x in input().split()]
mod=10**9+7
nega=sorted([a[i] for i in range(n) if a[i]<0],reverse=True)

ans=1
if k==n:
  # 全掛け算
  for i in a:
    ans*=i; ans%=mod
elif k%2 and n==len(nega):
  # 答えは負
  for i in range(k):
    ans*=nega[i]; ans%=mod
else:
  # 答えは正
  a=sorted(a, key=lambda x:abs(x), reverse=True)
  pi=ni=-1; cnt=0;
  x=[]
  for i in range(k):
    x.append(a[i])
    if a[i]<0: ni=i; cnt+=1
    if a[i]>0: pi=i;
  if cnt%2:  
    t=a[k:]
    mx=max(t)
    mn=min(t)
    if pi==-1:
      x.remove(a[ni])
      x.append(mx)
    #print(x,mx,mn)
    elif mn>0: # もう正しかとれる数値が存在していない
      x.append(mx)
      x.remove(a[ni])
    elif mx<=0: # もう負しかとれる数値が存在していない
      #if mx==0: print(0); return;
      x.append(mn)
      x.remove(a[pi])
    elif abs(a[pi]*mx)<=abs(a[ni]*mn):
      x.append(mn)
      x.remove(a[pi])
    else:
      x.append(mx)
      x.remove(a[ni])
  #print(x)
  for i in range(k):
    ans*=x[i]; ans%=mod;

print(ans)

mod = 10 ** 9 + 7

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

neg = []
zero = 0
pos = []
for a in A:
    if a < 0:
        neg.append(a)
    else:
        pos.append(a)

pos.sort()
neg.sort(reverse=True)

if len(pos) == 0:
    res = 1
    if K % 2 == 0:
        neg.reverse()
    for a in neg[:K]:
        res *= a
        res %= mod
else:
    res = 1
    if K % 2 == 1:
        res = pos.pop()
        K -= 1
    while K > 1 and len(pos) > 1 and len(neg) > 1:
        if pos[-1] * pos[-2] > neg[-1] * neg[-2]:
            res *= pos.pop()
            res %= mod
            res *= pos.pop()
            res %= mod
        else:
            res *= neg.pop()
            res %= mod
            res *= neg.pop()
            res %= mod
        K -= 2
    while K > 1 and len(pos) > 1:
        res *= pos.pop()
        res %= mod
        res *= pos.pop()
        res %= mod
        K -= 2
    while K > 1 and len(neg) > 1:
        res *= neg.pop()
        res %= mod
        res *= neg.pop()
        res %= mod
        K -= 2
    while K and pos:
        res *= pos.pop()
        res %= mod
        K -= 1
    while K and neg:
        res *= neg.pop()
        res %= mod
        K -= 1


print(res)

# -*- coding: utf-8 -*-
import sys

def main():
    N,K = list(map(int, sys.stdin.readline().split()))
    A_list = list(map(int, sys.stdin.readline().split()))
    

    A_list.sort(key=lambda x: -abs(x))
    A_plus = []
    A_minus = []
    mod = 10**9 + 7

    for val in A_list:
        if val >= 0:
            A_plus.append(val)
        else:
            A_minus.append(val)
    

    ans = 1
    cnt = 0
    i_p = 0  # index of A_plus
    i_m = 0  # index of A_minus


    while (cnt < K):
        if (K - cnt) == 1:
            if i_p < len(A_plus):
                ans *= A_plus[i_p]
                ans %= mod
                cnt += 1
                i_p += 1
                break
            
            else:
                ans2 = 1

                for i in range( len(A_list)-K, len(A_list) ):
                    ans2 *= A_list[i]
                    ans2 %= mod

                print(ans2)
                return


        if (i_m + 1) < len(A_minus):
            if (i_p + 1) < len(A_plus):
                if abs( A_plus[i_p] * A_plus[i_p + 1] ) > abs( A_minus[i_m] * A_minus[i_m + 1] ):
                    ans *= A_plus[i_p]
                    cnt += 1
                    i_p += 1
                else:
                    ans *= (A_minus[i_m] * A_minus[i_m + 1])
                    cnt += 2
                    i_m += 2

            else:
                ans *= (A_minus[i_m] * A_minus[i_m + 1])
                cnt += 2
                i_m += 2
            
        else:
            ans *= A_plus[i_p]
            cnt += 1
            i_p += 1
        

        ans %= mod
    
    
    print(ans)
    return

def __starting_point():
    main()

__starting_point()

# AFTER EDITORIAL, WIP

def solve(ls, k, debug=0):
    modulo = 10 ** 9 + 7
    n = len(ls)
    n_neg = 0
    for i in range(n):
        n_neg += ls[i] < 0
    n_pos = n - n_neg

    # Sort by abs
    ls_abs = [abs(x) for x in ls]
    ls_abs_argsort = sorted(list(range(n)), key=lambda i: -ls_abs[i])

    # Check if positive result is impossible
    if n_neg >= k:
        positive = (k % 2 == 0) or (n_pos > 0)
    else:
        positive = (n_neg % 2 == 0) or (n > k)

    # If positive is impossible, pick "abs" small ones
    if not positive:
        p = 1
        for i in range(k):
            x = ls[ls_abs_argsort[-1 - i]]
            p *= x
            p %= modulo
        return p

    #
    # If positive is possible, ...
    #
    # PROP.
    #   At most one swap is needed for making product non-negative.
    #   PROOF. TODO
    #

    # Check sign when we pick "abs" large ones
    s = 1
    for i in range(k):
        x = ls[ls_abs_argsort[i]]
        s *= -1 if x < 0 else 1

    # If non-negative, we take as it is
    if s > 0:
        p = 1
        for i in range(k):
            x = ls[ls_abs_argsort[i]]
            p *= x
            p %= modulo
        return p

    # If negative, ...
    #   1. replace small negative with large positive, or
    #   2. replace small positive with large negative
    opt1 = None
    opt2 = None
    neg1 = pos1 = None
    pos2 = neg2 = None

    # Check if "1" is possible
    swap_pos = None
    for i in range(k, n):
        if ls[ls_abs_argsort[i]] >= 0:
            swap_pos = i
            pos1 = ls[ls_abs_argsort[i]]
            break

    swap_neg = None
    for i in range(k)[::-1]:
        if ls[ls_abs_argsort[i]] < 0:
            swap_neg = i
            neg1 = ls[ls_abs_argsort[i]]
            break

    if swap_pos is not None and swap_neg is not None:
        p = 1
        p *= ls[ls_abs_argsort[swap_pos]]
        p %= modulo
        for i in range(k):
            if i == swap_neg:
                continue
            x = ls[ls_abs_argsort[i]]
            p *= x
            p %= modulo
        opt1 = p

    # Check if "2" is possible
    swap_pos = None
    for i in range(k)[::-1]:
        if ls[ls_abs_argsort[i]] >= 0:
            swap_pos = i
            pos2 = ls[ls_abs_argsort[i]]
            break

    swap_neg = None
    for i in range(k, n):
        if ls[ls_abs_argsort[i]] < 0:
            swap_neg = i
            neg2 = ls[ls_abs_argsort[i]]
            break

    if swap_pos is not None and swap_neg is not None:
        p = 1
        p *= ls[ls_abs_argsort[swap_neg]]
        p %= modulo
        for i in range(k):
            if i == swap_pos:
                continue
            x = ls[ls_abs_argsort[i]]
            p *= x
            p %= modulo
            opt2 = p

    # Pick opt1 or opt2
    if opt1 is None:
        return opt2

    if opt2 is None:
        return opt1

    if pos1 * pos2 > neg1 * neg2:
        return opt1

    return opt2


def main(istr, ostr):
    n, k = list(map(int, istr.readline().strip().split()))
    ls = list(map(int, istr.readline().strip().split()))
    result = solve(ls, k)
    print(result, file=ostr)


def __starting_point():
    import sys

    main(sys.stdin, sys.stdout)

__starting_point()

mod=10**9+7
num,k=map(int,input().rstrip().split())
mai=list(map(int, input().rstrip().split()))
main=sorted(mai,key=abs,reverse=True)
result=1
def findplus_plus(x):
    for i in range(x,len(main)):
        if main[i]>=0:
            return main[i]
    return ''
def findplus_minus(x):
    for i in range(x,len(main)):
        if main[i]<0:
            return main[i]
    return ''
def findminus_plus(x):
    for i in range(x-1,-1,-1):
        if main[i]>=0:
            return main[i]
    return ''
def findminus_minus(x):
    for i in range(x-1,-1,-1):
        if main[i]<0:
            return main[i]
    return ''

if num==k:
    for i in main:
        result*=i
        result%=mod
elif sorted(main)[len(sorted(main))-1]<0:
    if (k%2)==0:
        for i in range(k):
            result*=main[i]
            result%=mod
    else:
        for i in range(len(main)-1,len(main)-1-k,-1):
            result*=main[i]
            result%=mod

else:
    count=0
    for i in range(k):
        if main[i]<0:
            count+=1
        result*=main[i]
        result%=mod
    if (count%2)==1:
        minplus=findminus_plus(k)
        minminus=findminus_minus(k)
        maxplus=findplus_plus(k)
        maxminus=findplus_minus(k)
        if type(maxplus)==type(''):
            plusplus=-1
            minusminus=minminus*maxminus
        else:
            if type(maxminus)==type('') or type(minplus)==type(''):
                minusminus=-1
                plusplus=0
            else:
                minusminus=minminus*maxminus
                plusplus=minplus*maxplus
        if plusplus>minusminus:
            main.remove(minminus)
            result=1
            for i in range(k-1):
                result*=main[i]
                result%=mod
            result*=maxplus
        elif plusplus<=minusminus:
            main.remove(minplus)
            result=1
            for i in range(k-1):
                result*=main[i]
                result%=mod
            result*=maxminus
            
print(result%mod)

import copy
N, K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=sorted([(a,abs(a)) for a in A],key=lambda x:x[1],reverse=True)
R=10**9+7
P=1
minus=0
last_neg=-1
last_pos=-1
for i in range(K):
    if B[i][0]>0:
        if last_pos != -1:
            P = (P * B[last_pos][1]) % R
        last_pos=i
    elif B[i][0]<0:
        if last_neg != -1:
            P = (P * B[last_neg][1]) % R
        minus+=1
        last_neg=i
    else:
        print((0))
        return
F=copy.copy(P)
if last_pos!=-1:
    F=(F*B[last_pos][1]) % R
if last_neg!=-1:
    F=(F*B[last_neg][1]) % R
if minus%2==1:
    if K == N:
        print((-F %R))
        return
    first_neg=-1
    first_pos=-1
    count=[0,0]
    for i in range(K,N):
        if count[0]==0 and B[i][0]>0:
            first_pos=i
            count[0]=1
        elif count[1]==0 and B[i][0]<0:
            first_neg=i
            count[1]=1
        elif count==[1,1]:
            break
    if first_pos==-1 and last_pos==-1:
        P = 1
        for i in range(K):
           P = (P * B[N - i - 1][0]) % R
        print(P)
        return
    if first_pos==-1 and first_neg==-1:
        print((0))
        return
    list_product=[]
    if first_neg!=-1 and last_pos!=-1:
        list_product.append(B[last_neg][1]*B[first_neg][1])
    if first_pos!=-1:
        P1=B[first_pos][1]
        if last_pos!=-1:
            P1=P1*B[last_pos][1]
        list_product.append(P1)
    print((max(list_product)*P %R))
else:
    print(F)


import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = list(map(int, input().split()))
    A = list(map(int, input().split()))
    res = 1
    if n == k:
        for a in A:
            res = (res * a) % mod
        print(res)
        return

    P, M = [], []
    for a in A:
        P.append(a) if a >= 0 else M.append(a)

    if len(P) == n:
        A.sort(reverse=True)
        for i in range(k):
            res = (res * A[i]) % mod
    elif len(M) == n:
        A.sort(reverse=True) if k % 2 else A.sort()
        for i in range(k):
            res = (res * A[i]) % mod
    else:
        P.sort(reverse=True)
        M.sort()
        B = []
        if k % 2:
            k -= 1
            b = P.pop(0)
            B.append(b)
            res = (res * b) % mod
        for i in range(0, len(P), 2):
            if i + 1 < len(P):
                B.append(P[i] * P[i + 1])
        for j in range(0, len(M), 2):
            if j + 1 < len(M):
                B.append(M[j] * M[j + 1])
        B.sort(reverse=True)
        for i in range(k // 2):
            res = (res * B[i]) % mod

    print(res)

def __starting_point():
    resolve()

__starting_point()

n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9 + 7
res = 1
a.sort(reverse=True)
if a[0]<0 and k%2==1:
    for i in range(k):
        res = (res*a[i])%mod
else:
    right = n-1
    left = 0
    while k > 1:
        if a[right]*a[right-1] < a[left]*a[left+1]:
            res = (res*a[left])%mod
            left += 1
            k -= 1
        else:
            res = (res*a[right]*a[right-1])%mod
            right -= 2
            k -= 2
    if k == 1:
        res = (res*a[left])%mod

print(res)

#E_Multiplication4
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
MOD = 1000000007
#ソート
arr = []
j = 0
i = 0
seki = 1
gyaku = 1
minuscount = 0
minusposition = 0

def modpow(a,n,mod):
    res = 1
    while n > 0 :
        if n & 1 :
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res
def modinv(a,mod):
    return modpow(a, mod - 2, mod)
 
arr = sorted(A,reverse = True)
if arr[(N -1)] > 0 :
    for i in range(K):
        seki = seki * arr[i] % MOD
else:
    if arr[0] < 0 :
        for j in range(K):
            if K % 2 == 1:
                seki = seki * arr[j] % MOD
            else:
                seki = seki * arr[N-j-1] % MOD
    else:
        while (i + j) < K:
            if (i + j + 1) < K :
                if arr[i] * arr[i+1] > (arr[(N - j -1)] * arr[(N - j -2)]):
                    seki = seki * arr[i] % MOD
                    i += 1
                else:
                    minuscount += 2
                    minusposition = N - j -2
                    seki = (seki * arr[(N - j -1)] % MOD) * arr[(N - j -2)] % MOD
                    j += 2
            else:
                if abs(arr[i]) > abs( arr[(N - j -1)]) :
                    seki = seki * arr[i] % MOD
                    i += 1
                else:               
                    minuscount += 1
                    minusposition = N - j -1
                    seki = seki * arr[(N - j -1)] % MOD
                    j += 1
if (minuscount % 2) != 0:
    if minusposition != (i - 1):
        gyaku = modinv(arr[minusposition],MOD)
        seki  = seki * gyaku % MOD
        seki  = seki * arr[i] % MOD
print(seki)


n,k = list(map(int,input().split())); arr = list(map(int,input().split())); arr.sort(reverse=True)
absarr = [[abs(i), 1 if i>0 else -1 if i<0 else 0] for i in arr]; absarr.sort(reverse=True, key=lambda x: x[0])
mod = 10**9+7

zeroflag = True if absarr[-1][0] == 0 else False
from collections import Counter
posnegarr = Counter([i[1] for i in absarr[:k]])
pos = posnegarr[1]; neg = posnegarr[-1]

if absarr[k-1] == 0:
    ans = 0
elif neg % 2 == 0 or n == k:
    ans = 1
    for i in absarr[:k]:
        ans *= i[0]; ans %= mod
    if n == k and neg % 2 == 1:
        ans = -ans % mod
else:
    ans = 1
    for i in absarr[:k]:
        ans *= i[0]; ans %= mod
    if pos > 0:
        if absarr[k][0] == 0:
            ans = 0
        nextpos = nextneg = 0
        tmp = k
        while tmp < n and (nextpos == 0 or nextneg == 0):
            num = absarr[tmp]
            if num[0] == 0:
                break
            elif num[1] > 0 and nextpos == 0:
                nextpos = num[0]
            elif num[1] < 0 and nextneg == 0:
                nextneg = num[0]
            tmp += 1
        backpos = backneg = 0
        tmp = k-1
        while backpos == 0 or backneg == 0:
            num = absarr[tmp]
            if num[1] > 0 and backpos == 0:
                backpos = num[0]
            elif num[1] < 0 and backneg == 0:
                backneg = num[0]
            tmp -= 1
        if ans == 0:
            pass
        elif nextpos*backpos > nextneg*backneg:
            ans *= nextpos*pow(backneg,-1,mod); ans %= mod
        else:
            ans *= nextneg*pow(backpos,-1,mod); ans %= mod
    else:
        nextpos = 0
        tmp = k
        while tmp < n and nextpos == 0:
            num = absarr[tmp]
            if num[1] > 0:
                nextpos = num[0]
            tmp += 1
        backneg = absarr[k-1][0]
        if nextpos != 0:
            ans *= nextpos * pow(backneg,-1,mod); ans %= mod
        elif zeroflag:
            ans = 0
        else:
            ans = 1
            for i in arr[:k]:
                ans *= i; ans %= mod
        
print(ans)