Harryxun/stf_run huggingface dataset:
import numpy as np

def main():
    H, W = [int(i) for i in input().split()]
    N = int(input())
    a = [int(i) for i in input().split()]
    
    color_ar = np.zeros((H, W), dtype=np.int32)
    #print(color_ar)
    
    y = 0
    x = 1
    
    for i in range(N):
        t = a[i]
        while t > 0:
            if(np.count_nonzero(color_ar) == 0):
                color_ar[0,0] = i + 1
            else:
                color_ar[y,x] = i + 1
                if((y + 1) % 2 == 0):
                    x -= 1
                else:
                    x += 1
                
                if((x < 0) or (x >= W)):
                    y += 1
                    if(x < 0):
                        x = 0
                    else:
                        x = W - 1
            t -= 1
            
    #print(color_ar)
    for y in range(H):
        for x in range(W):
            print(color_ar[y,x], end="")
        print("\n")
            
if __name__=="__main__":
    main()

### FIXED CODE ###

import numpy as np

def main():
    H, W = [int(i) for i in input().split()]
    N = int(input())
    a = [int(i) for i in input().split()]
    
    color_ar = np.zeros((H, W), dtype=np.int32)
    #print(color_ar)
    
    y = 0
    x = 0
    
    for i in range(N):
        t = a[i]
        while t > 0:
            if(np.count_nonzero(color_ar) == 0):
                color_ar[0,0] = i + 1
                if((y + 1) % 2 == 0):
                    x -= 1
                else:
                    x += 1
                
                if((x < 0) or (x >= W)):
                    y += 1
                    if(x < 0):
                        x = 0
                    else:
                        x = W - 1
                    
            else:
                color_ar[y,x] = i + 1
                if((y + 1) % 2 == 0):
                    x -= 1
                else:
                    x += 1
                
                if((x < 0) or (x >= W)):
                    y += 1
                    if(x < 0):
                        x = 0
                    else:
                        x = W - 1
            t -= 1
            
    #print(color_ar)
    for y in range(H):
        for x in range(W):
            print(color_ar[y,x], end="")
            if(x < W - 1):
                print(" ",end="")
        if(y < H - 1 ):
            print("")
            
if __name__=="__main__":
    main()
N = int(input())
for i in range(N):
  t,x,y = map(int,input().split())
  if (x + y) > t or (x + y + t)%2 != 0:
    print("No")
    exit()
print("Yes")

### FIXED CODE ###

numbers = input().split()
a = int(numbers[0])
b = int(numbers[1])
if (a*b)%2==0:
  print("Even")
else:
  print("Odd")
r = int(input())

s = r * r * 3.14159
l = r * 2 * 3.14159

print(s,l)  

### FIXED CODE ###

import math
r = float(input())

s = r * r * math.pi
l = r * 2 * math.pi

print("%.6f %.6f" % (s,l))
import sys
def ink(x,y,size):
    global P
    P[y][x]+=1
    for d in [-1,1]:
        P[y+d][x]+=1
        P[y][x+d]+=1
    if size==1: return
    for d in [-1,1]:
        P[y+d][x+d]+=1
        P[y+d][x-d]+=1
    if size==2: return
    for d in [-2,2]:
        P[y+d][x]+=1
        P[y][x+d]+=1
    return

R=range(14)
A=[-1:1]
P=[[0 for i in R] for j in R]
for s in sys.stdin:
    x,y,size = map(int, s.split(","))
    ink(x+2,y+2,size)
c=0
m=0
for e in P[2:-2]:
    x=e[2:-2]
    c+=x.count(0)
    m=max(max(x),m)
print c
print m

### FIXED CODE ###

import sys
def ink(x,y,s):
    global P
    P[y][x]+=1
    P[y+1][x]+=1
    P[y-1][x]+=1
    P[y][x+1]+=1
    P[y][x-1]+=1
    if s==1: return
    P[y+1][x+1]+=1
    P[y+1][x-1]+=1
    P[y-1][x+1]+=1
    P[y-1][x-1]+=1
    if s==2: return
    P[y+2][x]+=1
    P[y-2][x]+=1
    P[y][x+2]+=1
    P[y][x-2]+=1
    return

P=[[0]*14 for j in range(14)]
for s in sys.stdin:
    x,y,s = map(int, s.split(","))
    ink(x+2,y+2,s)
c=0
m=0
for e in P[2:-2]:
    x=e[2:-2]
    c+=x.count(0)
    m=max(max(x),m)
print c
print m
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    K = int(input())
    ans = ''
    for s in S:
        if s=='a':
            ans += s
        else:
            if 123 - ord(s) <= K:
                ans += 'a'
                K -= 123 - ord(s)
            else:
                ans += s
    if K > 0:
        ans = ans[:-1] + (chr(ord(ans[-1]) + K))
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    K = int(input())
    ans = ''
    for s in S:
        if s=='a':
            ans += s
        else:
            if 123 - ord(s) <= K:
                ans += 'a'
                K -= 123 - ord(s)
            else:
                ans += s
    if K > 0:
        ans = ans[:-1] + (chr(ord(ans[-1]) + K%26))
    print(ans)


if __name__ == '__main__':
    main()
n = int(input())
i = 1
for i range in (1,n):
    if i % 10 == 3:
        print('{0}'.format(i))
    elif i % 3 == 0:
        if i % 10 == 3:
            continue
        print('{0}'.format(i))
    i = i + 1
    


### FIXED CODE ###

n = int(input())
for i in range(1, n+1):
    if i%3 == 0 :
        print(' {}'.format(i),end='')

    elif '3' in str(i):
        print(' {}'.format(i),end='')
print()
N = list(input().split())
A = int(N[0])
b1,b2 = N[1].split('.')
B = int(b1+b2)
prd = list(str(A*B))
ans = 0
if len(prd) < 3:
    ans = 0
else:
    prd.pop(-1,-2)
    ans = int(''.join(prd))
print(ans)


### FIXED CODE ###

N = list(input().split())
A = int(N[0])
b1,b2 = N[1].split('.')
B = int(b1+b2)
prd = list(str(A*B))
ans = 0
if len(prd) < 3:
    ans = 0
else:
    prd.pop()
    prd.pop()
    ans = int(''.join(prd))
print(ans)
A, B = list(map(int, input().split()))

import math

print(int(A * B // math.gcd(A, B)))

### FIXED CODE ###

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

_A, _B = min(A, B), max(A, B)

pres = _A
while True:
    res = _B % _A
    if res == 0:
        break
    else:
        pres = res
        _B = _A
        _A = res

print((A * B) // pres)
def main():
    S = input()
    k = int(input())

    array = []
    for i in range(len(S)):
        for j in range(i+1,len(S)+1):
            if j-i < len(S):
                array.append(S[i:j])
    array = list(set(array))
    array.sort()
    print(array[k-1])


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    S = input()
    k = int(input())

    array = []
    for i in range(len(S)):
        for j in range(i+1,len(S)+1):
            if j-i <= k:
                array.append(S[i:j])
    array = list(set(array))
    array.sort()
    print(array[k-1])


if __name__ == '__main__':
    main()
import fractions
N = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, N):
    ans = ans * a[i] // fractions.gcd(ans, a[i])

total=0  
for i in range(0,N):
  if total+ ans/a[i] >= 10**9+7:
    total = (total+ans/a[i])%(10**9+7)
  else:
    total+= ans/a[i]
  
  
  
print(int(total))

### FIXED CODE ###

import fractions
N = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, N):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
 
total=0  
for i in range(0,N):
    total+= ans//a[i]

print(total%(10**9+7))
N = input()
a = sorter(map(int,input().split()))

print(a[-1] - a[0])

### FIXED CODE ###

N = input()
a = sorted(map(int,input().split()))

print(a[-1] - a[0])
def main():
    N = int(input())
    W = []
    for n in range(N):
        W.append(input())
    for i, w in enumerate(W):
        if i==0:
            prev_w = w
            continue
        for wn in W[:i]:
            if w == wn:
                print('No')
                return 
        if prev_w[-1] != w[0]:
            print('No')
            return
        prev_w = w
    print('Yes')
    return

main()


### FIXED CODE ###

s = input()
a,b = s.split(' ')
a = int(a)
b = int(b)
if (a%2 == 0) or (b%2 == 0):
    print('No')
else:
    print('Yes')
import sys


a = sys.argv[1]
b = sys.argv[2]

k = (a + b) / 2

print(k) if int(k) == k else print("IMPOSSIBLE")


### FIXED CODE ###

import sys

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

k = (i[0] + i[1]) / 2

print(int(k), end="") if int(k) == k else print("IMPOSSIBLE", end="")
import numpy as np

N, M, K = map(int, input().split())
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]

A = np.array(A)
B = np.array(B)

A = np.cumsum(A)
B = np.cumsum(B)

A1 = np.zeros((len(A),2))
A1[:,0] = A
A1[:,1] = np.arange(1,len(A)+1)

B1 = np.zeros((len(B),2))
B1[:,0] = B
B1[:,1] = np.arange(1,len(B)+1)

C1 = np.zeros((len(A)*len(B),2))
lenB = len(B)
for i in range(len(A)):
    for j in range(len(B)):
        C1[lenB*i+j,:] = A1[i,:] + B1[j,:]
C2 = np.array([[Cl[0],Cl[1]] for Cl in C1 if Cl[0] <= K])
print(int(C2[:,1].max()))

### FIXED CODE ###

import numpy as np

N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

A = np.array(A).cumsum()
B = np.array(B).cumsum()

ans = 0
j = M
for i in range(N+1):
    if A[i] > K:
        break
    while B[j] > K - A[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)
A,B,C=map(int,input().split())
k=int(input())
m=max(A,B,C)
print(A+B+C-m+m*2**k)


### FIXED CODE ###

a,b=map(int,input().split())
if a>b:
    print(a-1)
else:
    print(a)
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
s = [0] * 200000
for i in range(N):
    s[i+1] = s[i] + A[i]

max_s = 0
for i in range(N):
    if max_s < s[i+K] - s[i]:
        max_s = s[i+K] - s[i]


print((max_s+K) / 2)


### FIXED CODE ###

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
s = [0] * 1000000
for i in range(N):
    s[i+1] = s[i] + A[i]

max_s = 0
for i in range(N):
    if max_s < s[i+K] - s[i]:
        max_s = s[i+K] - s[i]


print((max_s+K) / 2)
n, m = map(int, input().split())
uv = [list(map(int, input().split())) for _ in range(m)]
alist = [[] for _ in range(n)]
for u, v in uv:
    alist[u-1].append(v-1)
s, t = map(int, input().split())

alist3 = [set([]) for _ in range(n)]
for v in range(n):
    for v1 in alist[v]:
        for v2 in alist[v1]:
            for v3 in alist[v2]:
                alist3[v].add(v3)

# BFS
queue = [s]
visited = [-1]*n
visited[s] = 0
while len(queue) > 0:
    q = queue.pop(0)
    for v in alist3[q]:
        if visited[v] < 0:
            queue.append(v)
            visited[v] = visited[q] + 1
print(visited[t])




### FIXED CODE ###

n, m = map(int, input().split())
uv = [list(map(int, input().split())) for _ in range(m)]
s, t = map(int, input().split())

alist = [[] for _ in range(3*n)]
for u, v in uv:
    u, v = u-1, v-1
    alist[u].append(n+v)
    alist[n+u].append(2*n+v)
    alist[2*n+u].append(v)


# BFS
queue = [s-1]
visited = [-3]*(3*n)
visited[s-1] = 0
while len(queue) > 0:
    q = queue.pop(0)
    for v in alist[q]:
        if visited[v] < 0:
            queue.append(v)
            visited[v] = visited[q] + 1
print(visited[t-1]//3)
a = input()
b = input()

if  a > b :
print "a > b"
if  a < b :
print "a < b"
if  a == b :
print "a == b"

### FIXED CODE ###

a,b=map(int,raw_input().split())
if a > b:
    print 'a > b'
elif a < b:
    print 'a < b'
else:
    print 'a == b'
N, M = map(int,input().split())
H = list(map(int,input().split()))
AB = [0]*M
for i in range(M):
    AB[i] = list(map(int,input().split()))

GD = [0]*N

for A ,B in AB:
    HA = H[A-1]
    HB = H[B-1]
    if HA < HB:
        GD[A-1] -= 1
    elif HA > HB:
        GD[B-1] -= 1
    else:
        GD[A-1] -= 1
        GD[B-1] -= 1

ans = 0
for i in GD:
    if i == 0:
        ans += 1
print(ans)

### FIXED CODE ###

import collections
X = int(input())

for i in range(1000):
    for j in range(-1000,1000):
        if i**5 - j**5 == X:
            print(i,j)
            exit()
import numpy as np

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

# インデックスはライフ 値はそれを以下にする最小MP
dp = [np.inf for i in range(H+1)]
dp[0] = 0

for i in range(1, H+1):
    quietus_MP = np.inf
    for a, b in AB:
        # if i-a >= 0:
        dp[i] = min(dp[max(i-a, 0)] + b, dp[i])
        # 一回で倒せて一番MP使わない魔法
        # if a > i:
        #     quietus_MP = min(b, quietus_MP)
    # 一回で倒す場合
    # dp[i] = min(quietus_MP, dp[i])

print(dp[-1])

### FIXED CODE ###

import numpy as np

H, N = map(int, input().split())
AB = np.array([list(map(int, input().split())) for i in range(N)])
A = AB[:, 0]
B = AB[:, 1]

# インデックスはライフ 値はそれを以下にする最小MP
dp = np.array([10**10 for i in range(H+1)], dtype=int)
# dp = np.array([np.inf for i in range(H+1)], dtype=int)
dp[0] = 0

for i in range(1, H+1):
    # print(np.maximum(i-A, 0))
    dp[i] = min(dp[np.maximum(i-A, 0)] + B)

print(dp[-1])
import fraction
N=int(input())
As=input().split()
As=[int(a) for a in As]
count=As[0]
for i in As:
    count=fraction.gcd(count,i)
print(str(count))

### FIXED CODE ###

import fractions
N=int(input())
As=input().split()
As=[int(a) for a in As]
count=As[0]
for i in As:
    count=fractions.gcd(count,i)
print(str(count))
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/arc081/tasks/arc081_b
# D - Coloring Dominoes
"""
need to consider the case that ticket is not enough to lower everything
"""

N = gi()
M = gi()
A = [0] * N
ops = []

for i in range(N):
    A[i] = gi()
for _ in range(M):
    b = gi()
    c = gi()
    ops.append((-c, b))

A.sort()
ops.sort()

i = 0
for op in ops:
    nv = -op[0]
    for _ in range(op[1]):
        if nv < A[i]:
            break
        if i >= N:
            break
        A[i] = nv
        i += 1

print(sum(A))


### FIXED CODE ###

from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/arc081/tasks/arc081_b
# D - Coloring Dominoes
"""
need to consider the case that ticket is not enough to lower everything
"""

N = gi()
M = gi()
A = [0] * N
ops = []

for i in range(N):
    A[i] = gi()
for _ in range(M):
    b = gi()
    c = gi()
    ops.append((-c, b))

A.sort()
ops.sort()

i = 0
for op in ops:
    nv = -op[0]
    for _ in range(op[1]):
        if i >= N:
            break
        if nv < A[i]:
            break
        A[i] = nv
        i += 1

print(sum(A))
import sys
n = int(sys.stdin.readline())
li = []
for _ in range(n):
  li.append(sys.stdin.readline().strip())
li2 = list(set(li)).sort(reverse = True)
cnt_box = []
for i in li2:
  cnt_box.append(li.count(i))
m = max(cnt_box)
i = 0
while i < len(cnt_box):
  if cnt_box[i] == m:
    print(li2[i])
  i += 1


### FIXED CODE ###

import sys
import math
import itertools
import numpy
import collections

rl = sys.stdin.readline

n = int(rl())

li = []
for _ in range(n):
    li.append(rl().rstrip())
c = collections.Counter(li)
max_cnt = 0
li = []
for k, v in c.items():
    if v < max_cnt:
        continue
    elif v == max_cnt:
        li.append(k)
    else:
        max_cnt = v
        li = [k]
li.sort()
for i in li:
    print(i)
s=input()
k=input()
if s[0]=='1' or len(s)==1:
    print(s[1])
else:
    for i in s:
        if int(i)>1:
            print(i)

### FIXED CODE ###

s=input()
k=int(input())
for i in range(min(len(s),k)):
    if int(s[i])>1:
            print(s[i])
            exit()
print(1)
# coding: utf-8

def North(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[3]
    new_dice[1] = dice[0]
    new_dice[2] = dice[2]
    new_dice[3] = dice[5]
    new_dice[4] = dice[4]
    new_dice[5] = dice[1]
    return new_dice

def East(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[4]
    new_dice[1] = dice[1]
    new_dice[2] = dice[0]
    new_dice[3] = dice[3]
    new_dice[4] = dice[5]
    new_dice[5] = dice[2]
    return new_dice

def West(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[2] #3
    new_dice[1] = dice[1] #5
    new_dice[2] = dice[5] #6
    new_dice[3] = dice[3] #2
    new_dice[4] = dice[0] #1
    new_dice[5] = dice[4] #4
    return new_dice

def South(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[1] #5
    new_dice[1] = dice[5] #6
    new_dice[2] = dice[2] #3
    new_dice[3] = dice[0] #1
    new_dice[4] = dice[4] #4
    new_dice[5] = dice[3] #2
    return new_dice

def Right(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[0] #1
    new_dice[1] = dice[4] #4
    new_dice[2] = dice[1] #5
    new_dice[3] = dice[2] #3
    new_dice[4] = dice[3] #2
    new_dice[5] = dice[5] #6
    return new_dice

def Left(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[0] #1
    new_dice[1] = dice[2] #3
    new_dice[2] = dice[3] #2
    new_dice[3] = dice[4] #4
    new_dice[4] = dice[1] #5
    new_dice[5] = dice[5] #6
    return new_dice

while True:
    n = int(raw_input())
    if n == 0:
        break
        dice = [1,5,3,2,4,6] # ??? ??? ??± ??? ?\? ??? ??????
        sum = 1
        for i in range(n):
            instruct = raw_input()
            if instruct == "North":
                dice = North(dice)
            elif instruct == "East":
                dice = East(dice)
            elif instruct == "South":
                dice = South(dice)
            elif instruct == "West":
                dice = West(dice)
            elif instruct == "Right":
                dice = Right(dice)
            elif instruct == "Left":
                dice = Left(dice)
            #print("** {:} **".format(dice[0]))
            sum += dice[0]
        print(sum)

### FIXED CODE ###

while(1):
    num=int(raw_input())
    if num==0:
        break
    else:
        d=[0,1,2,3,4,5,6]
        sum=1
        for i in range(num):
            dir=num=raw_input()
            if dir=="North":
                d=[0,d[2],d[6],d[3],d[4],d[1],d[5]]
            elif dir=="East":
                d=[0,d[4],d[2],d[1],d[6],d[5],d[3]]
            elif dir=="West":
                d=[0,d[3],d[2],d[6],d[1],d[5],d[4]]
            elif dir=="South":
                d=[0,d[5],d[1],d[3],d[4],d[6],d[2]]
            elif dir=="Right":
                d=[0,d[1],d[3],d[5],d[2],d[4],d[6]]
            else:
                d=[0,d[1],d[4],d[2],d[5],d[3],d[6]]
            sum=sum+d[1]
        print sum
import re
A,B = map(int,input().split())
S = input()


if S.count("-") == 1:
    s1,s2 = S.split("-")
    result = re.match(f"^[0-9]", s1)

    for x in range(2):
        if x == 1:
            result = re.match(f"^[0-9]", s2)
        if result:
            continue
        else:
            print("No")
            sys.exit(0)

    judgment = s1
    n = A
    for x in range(2):
        if x == 1:
            judgment = s2
            n = B
        if len(judgment) == n:
            continue
        else:
            print("No")
            sys.exit(0)

    print("Yes")
else:
    print("No")


### FIXED CODE ###

import re
A,B = list(map(int,input().split()))
S = input()

d = re.compile("\d+")

if (d.match(S[:A])) and S[A] == "-" and d.match(S[A+1:]):
    print("Yes")

else:print("No")
# coding=utf-8

A, B, C, D = 4, 9, 2, 3
A, B, C, D = 10, 40, 6, 8
A, B, C, D = 314159265358979323, 846264338327950288, 419716939, 937510582
A, B, C, D = map(int, raw_input().split())


def f(d):
    return B / d - (A - 1) / d


def gcd(a, b):
    while b != 0:
        a, b = b, b % a
    return a

E = C / gcd(C, D) * D

good = f(C) + f(D) - f(E)
print B - A + 1 - good


### FIXED CODE ###

# coding=utf-8

A, B, C, D = 4, 9, 2, 3
A, B, C, D = 10, 40, 6, 8
A, B, C, D = 314159265358979323, 846264338327950288, 419716939, 937510582
A, B, C, D = map(int, raw_input().split())


def f(d):
    return B / d - (A - 1) / d


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

E = C / gcd(C, D) * D

good = f(C) + f(D) - f(E)
print B - A + 1 - good
import sys


input = list()
N, D = sys.stdin
for item in sys.stdin:
    input.append(item)

count = 0
for item in input:
    if 1 <= N and N <= 2*10**5:
        if 0 <= D and D <= 2*10**5:
            if abs(item[0]) <= 2*10**5 and abs(item[1]) <= 2*10**5:
                if D >= (int(item[0])**2 + int(item[1])**2)**(1/2):
                    count += 1
print(count)

### FIXED CODE ###

import sys


input_array = list()
N, D = map(int, input().split())
if 1 <= N and N <= 2*10**5:
    for _ in range(N):
        input_array.append(map(int, input().split()))

count = 0
for x0, x1 in input_array:
    if 0 <= D and D <= 2*10**5:
        if abs(x0) <= 2*10**5 and abs(x1) <= 2*10**5:            
            if D >= (int(x0)**2 + int(x1)**2)**(1/2):
                count += 1
print(count)
import itertools
import heapq
import sys
import functools
import operator
import numpy as np
input = sys.stdin.readline
#-------------
n,k = map(int,input().split())
a = list(map(int,input().split()))
#-------------
a.sort(reverse = True)
print(a)
w = 10**9 + 7
ans = 1
if k%2 == 1:
  for i in range(k):
    ans *= a[i]
    print(ans % w)

else:
  if n%2 == 0:
    a_new = [a[2*i]*a[2*i+1] for i in range(n//2)]
    a_new.sort(reverse = True)
    print(a_new)
    for j in range(k//2):
      ans *= a_new[j]
      print(ans % w)
      
  else:
    a_plus = heapq.nlargest(k, a)
    a_minus = heapq.nsmallest(k, a)
    a_plus.sort(reverse = True)
    a_minus.sort()
    a_plus_new = [a_plus[2*i]*a_plus[2*i+1] for i in range(k//2)]
    a_minus_new = [a_minus[2*i]*a_minus[2*i+1] for i in range(k//2)]
    a_new = a_plus_new + a_minus_new
    a_new.sort(revserse = True)
    for j in range(k//2):
      ans *= a_new[j]
      print(ans % w)

### FIXED CODE ###

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)
tmp = input()
if tmp = "0":
  print("1")
else:
  print("0")

### FIXED CODE ###

tmp = input()
if tmp =="0":
  print("1")
else:
  print("0")
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

    n = int(input())
    s = input().rstrip()
    eng_list = 'abcdefghigklmnopqrstuvwxyz'
    eng_dict = {}
    for i in eng_list:
        eng_dict[i] = 1
    for i in s:
        eng_dict[i] += 1
    ans = 1
    size = 10**9+7
    for i in eng_dict.values():
        ans = (ans*i)%size
    print((ans-1)%size)


### FIXED CODE ###

if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

    n = int(input())
    s = input().rstrip()
    eng_list = 'abcdefghigklmnopqrstuvwxyz'
    eng_dict = {}
    for i in eng_list:
        eng_dict[i] = 1
    for i in s:
        try:
            eng_dict[i] += 1
        except KeyError:
            eng_dict[i] = 2
    ans = 1
    size = 10**9+7
    for i in eng_dict.values():
        ans = (ans*i)%size
    print((ans-1)%size)