Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  5 21:49:24 2020

@author: NEC-PCuser
"""

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

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

A.sort()

minus_list = []
plus_list = []
for i in range(len(A)):
    if (A[i] <= 0):
        minus_list.append(A[i])
    else:
        plus_list.append(A[i])

ans = 1
mod = 10 ** 9 + 7   
if N == K:
    for i in A:
        ans = (ans * i) % mod
elif 0 == len(plus_list) and  K % 2 == 1:
    minus_list.sort(reverse=True)
    for i in range(K):
        ans = (ans * minus_list[i]) % mod
else:
    minus_list.sort()
    plus_list.sort(reverse=True)
    if K % 2 == 1:
        ans = plus_list.pop(0)
    for i in range(K // 2):
        if (len(plus_list) < 2):
            ans = (minus_list[0] * ans) % mod
            ans = (minus_list[1] * ans) % mod
            minus_list = minus_list[2:]
        elif (len(minus_list) < 2):
            ans = (plus_list[0] * ans) % mod
            ans = (plus_list[1] * ans) % mod
            plus_list = plus_list[2:]
        elif (plus_list[0] * plus_list[1] > minus_list[0] * minus_list[1]):
            ans = (plus_list[0] * ans) % mod
            ans = (plus_list[1] * ans) % mod
            plus_list = plus_list[2:]
        else:
            ans = (minus_list[0] * ans) % mod
            ans = (minus_list[1] * ans) % mod
            minus_list = minus_list[2:]
print(ans)
        

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  5 21:49:24 2020

@author: NEC-PCuser
"""

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

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

A.sort()

minus_list = []
plus_list = []
for i in range(len(A)):
    if (A[i] <= 0):
        minus_list.append(A[i])
    else:
        plus_list.append(A[i])

ans = 1
mod = 10 ** 9 + 7   
if N == K:
    for i in A:
        ans = (ans * i) % mod
elif 0 == len(plus_list) and  K % 2 == 1:
    minus_list.sort(reverse=True)
    for i in range(K):
        ans = (ans * minus_list[i]) % mod
else:
    minus_list.sort(reverse=True)
    plus_list.sort()
    if K % 2 == 1:
        ans = plus_list.pop()
    for i in range(K // 2):
        if (len(plus_list) < 2):
            ans = (minus_list.pop() * ans) % mod
            ans = (minus_list.pop() * ans) % mod
        elif (len(minus_list) < 2):
            ans = (plus_list.pop() * ans) % mod
            ans = (plus_list.pop() * ans) % mod
        elif (plus_list[len(plus_list) - 1] * plus_list[len(plus_list) - 2] > minus_list[len(minus_list) - 1] * minus_list[len(minus_list) - 2]):
            ans = (plus_list.pop()* ans) % mod
            ans = (plus_list.pop() * ans) % mod
        else:
            ans = (minus_list.pop() * ans) % mod
            ans = (minus_list.pop()* ans) % mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  5 21:49:24 2020

@author: NEC-PCuser
"""

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

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

A.sort()

minus_list = []
plus_list = []
for i in range(len(A)):
    if (A[i] <= 0):
        minus_list.append(A[i])
    else:
        plus_list.append(A[i])

ans = 1
mod = 10 ** 9 + 7   
if N == K:
    for i in A:
        ans = (ans * i) % mod
elif 0 == len(plus_list) and  K % 2 == 1:
    minus_list.sort(reverse=True)
    for i in range(K):
        ans = (ans * minus_list[i]) % mod
else:
    minus_list.sort()
    plus_list.sort(reverse=True)
    if K % 2 == 1:
        ans = plus_list.pop(0)
    for i in range(K // 2):
        if (len(plus_list) < 2):
            ans = (minus_list.pop(0) * ans) % mod
            ans = (minus_list.pop(0) * ans) % mod
        elif (len(minus_list) < 2):
            ans = (plus_list.pop(0) * ans) % mod
            ans = (plus_list.pop(0) * ans) % mod
        elif (plus_list[0] * plus_list[1] > minus_list[0] * minus_list[1]):
            ans = (plus_list.pop(0) * ans) % mod
            ans = (plus_list.pop(0) * ans) % mod
        else:
            ans = (minus_list.pop(0) * ans) % mod
            ans = (minus_list.pop(0) * ans) % mod
print(ans)
        

Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  5 21:49:24 2020

@author: NEC-PCuser
"""

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

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

A.sort()

minus_list = []
plus_list = []
for i in range(len(A)):
    if (A[i] <= 0):
        minus_list.append(A[i])
    else:
        plus_list.append(A[i])

ans = 1
mod = 10 ** 9 + 7   
if N == K:
    for i in A:
        ans = (ans * i) % mod
elif 0 == len(plus_list) and  K % 2 == 1:
    minus_list.sort(reverse=True)
    for i in range(K):
        ans = (ans * minus_list[i]) % mod
else:
    minus_list.sort(reverse=True)
    plus_list.sort()
    if K % 2 == 1:
        ans = plus_list.pop()
    for i in range(K // 2):
        if (len(plus_list) < 2):
            ans = (minus_list.pop() * ans) % mod
            ans = (minus_list.pop() * ans) % mod
        elif (len(minus_list) < 2):
            ans = (plus_list.pop() * ans) % mod
            ans = (plus_list.pop() * ans) % mod
        elif (plus_list[len(plus_list) - 1] * plus_list[len(plus_list) - 2] > minus_list[len(minus_list) - 1] * minus_list[len(minus_list) - 2]):
            ans = (plus_list.pop()* ans) % mod
            ans = (plus_list.pop() * ans) % mod
        else:
            ans = (minus_list.pop() * ans) % mod
            ans = (minus_list.pop()* ans) % mod
print(ans)