Problem:
Score : 500 points

Problem Statement

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 1

4 2
1 2 -3 -4

Sample Output 1

12

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

Sample Input 2

4 3
-1 -2 -3 -4

Sample Output 2

1000000001

The possible products of the three chosen elements are -24, -12, -8, and -6, so the maximum product is -6.

We print this value modulo (10^9+7), that is, 1000000001.

Sample Input 3

2 1
-1 1000000000

Sample Output 3

1000000000

The possible products of the one chosen element are -1 and 1000000000, so the maximum product is 1000000000.

Sample Input 4

10 10
1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1

Sample Output 4

999983200

Be sure to print the product modulo (10^9+7).

Solution in PyPy3 (7.3.0) (judge verdict: Runtime Error)

'''n=int(input())
l=[]
M=(10**9)+7
count=0
for i in range(6):
	l.append(int(input()))



dp=[[[[[[[-1]*7 for _ in range(11)] for _ in range(11)] for _ in range(11)] for _ in range(11)] for _ in range(11)] for _ in range(11)]

def countWays(last,a,b,c,d,e,f,i):
    if a+b+c+d+e+f==0:
        return 1

    if (dp[a][b][c][d][e][f][last] != -1):  
        return dp[a][b][c][d][e][f][last]
    ans=0
    if (last == 0): 
        if b:ans+=countWays(1,a,b-1,c,d,e,f,i)
        if e:ans+=countWays(4,a,b,c,d,e-1,f,i)  
    elif (last == 1): 
        if a:ans+=countWays(0,a-1,b,c,d,e,f,i)
        if c:ans+=countWays(2,a,b,c-1,d,e,f,i)  
    elif (last == 2): 
        if d:ans+=countWays(3,a,b,c,d-1,e,f,i)
        if f:ans+=countWays(5,a,b,c,d,e,f-1,i) 
    elif (last == 3): 
        if a:ans+=countWays(0,a-1,b,c,d,e,f,i)
        if c:ans+=countWays(2,a,b,c-1,d,e,f,i)  
    elif (last == 4): 
        if d:ans+=countWays(3,a,b,c,d-1,e,f,i)
        if f:ans+=countWays(5,a,b,c,d,e,f-1,i)  
    elif (last == 5): 
        if b:ans+=countWays(1,a,b-1,c,d,e,f,i)
        if e:ans+=countWays(4,a,b,c,d,e-1,f,i) 
  
    dp[a][b][c][d][e][f][last]=ans
    return ans

def countUtil(i): 
    return (countWays(0,l[0],l[2],l[1],l[4],l[3],l[5],i) + 
            countWays(1,l[0],l[2],l[1],l[4],l[3],l[5],i) + 
            countWays(2,l[0],l[2],l[1],l[4],l[3],l[5],i))


di={}
oo=sum(l)
print(countUtil(15))
for a in range(11):
	for b in range(11):
		for c in range(11):
				for d in range(11):
						for e in range(11):
								for f in range(11):
									for k in range(7):
										if dp[a][b][c][d][e][f][k]!=-1:
											fi=a+b+c+d+e+f
											if fi in di:
												di[fi]+=dp[a][b][c][d][e][f][k]
											else:
												di[fi]=dp[a][b][c][d][e][f][k]
print(di)

'''
import math
import bisect
import copy
#import time
import itertools
#map(int,input().split())
#int(x) for x in input().split()
#for _ in range(int(input()))
M=10**9+7
n,k=map(int,input().split())
l=[int(x) for x in input().split()]
l.sort(reverse=True)
p=1
p1=1
for i in range(k):
	if l[i]<0:
		p=(p*l[i])
	else:
		p=(p*l[i])%M


f=0
if p<0:
	f=1
	p=p/l[k-1]
	for i in range(k,len(l)):
		if l[i]>0:
			p=(p*l[i])%M
			f=0
			break

if f==1:
	p=p*l[k-1]

l=l[::-1]
for i in range(k):
	if l[i]<0:
		p1=(p1*l[i])
	else:
		p1=(p1*l[i])%M


f=0
if p1<0:
	f=1
	p1=p1/l[k-1]
	for i in range(k,len(l)):
		if l[i]>0:
			p1=(p1*l[i])%M
			f=0
			break

if f==1:
	p1=p1*l[k-1]

ans=max(p,p1)
print(int(ans%M))