Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split(' '))
l = map(int, input().split(' '))

s = 1
if n == k:
	for i in l:
		s *= i
	print(s % 1000000007)
else:
	pos = []
	neg = []

	for i in l:
		if i >= 0:
			pos.append(i)
		else:
			neg.append(i)

	pos.sort()
	neg.sort(reverse=True)
	answer = []

	if k % 2 == 1 and not pos:
		for i in range(k):
			s *= neg[i]
		print(s % 1000000007)

	else:
		if k % 2 == 1:
			s = pos.pop()
		for i in range(k//2):
			if len(pos) >= 2:
				answer.append(pos.pop()*pos.pop())
			else:
				break
		for i in range(k//2):
			if len(neg) >= 2:
				answer.append(neg.pop()*neg.pop())
			else:
				break
		answer.sort(reverse=True)
		for i in range(k//2):
			s *= answer[i]
		print(s % 1000000007)

Fixed submission:
n, k = map(int, input().split(' '))
l = map(int, input().split(' '))

s = 1
if n == k:
	for i in l:
		s *= i
		s %= 1000000007
	print(s)
else:
	pos = []
	neg = []

	for i in l:
		if i >= 0:
			pos.append(i)
		else:
			neg.append(i)

	pos.sort()
	neg.sort(reverse=True)
	answer = []

	if k % 2 == 1 and not pos:
		for i in range(k):
			s *= neg[i]
			s %= 1000000007
		print(s)

	else:
		if k % 2 == 1:
			s = pos.pop()
		for i in range(k//2):
			if len(pos) >= 2:
				answer.append(pos.pop()*pos.pop())
			else:
				break
		for i in range(k//2):
			if len(neg) >= 2:
				answer.append(neg.pop()*neg.pop())
			else:
				break
		answer.sort(reverse=True)
		for i in range(k//2):
			s *= answer[i]
			s %= 1000000007
		print(s)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split(' '))
l = map(int, input().split(' '))

s = 1
if n == k:
	for i in l:
		s *= i
	print(s % 1000000007)
else:
	pos = []
	neg = []

	for i in l:
		if i >= 0:
			pos.append(i)
		else:
			neg.append(i)

	pos.sort()
	neg.sort(reverse=True)
	answer = []

	if k % 2 == 1 and not pos:
		for i in range(k):
			s *= neg[i]
		print(s % 1000000007)

	else:
		if k % 2 == 1:
			s = pos.pop()
		while len(pos) >= 2:
			answer.append(pos.pop()*pos.pop())
		while len(neg) >= 2:
			answer.append(neg.pop()*neg.pop())
		answer.sort(reverse=True)
		for i in range(k//2):
			s *= answer[i]
		print(s % 1000000007)

Fixed submission:
n, k = map(int, input().split(' '))
l = map(int, input().split(' '))

s = 1
if n == k:
	for i in l:
		s *= i
		s %= 1000000007
	print(s)
else:
	pos = []
	neg = []

	for i in l:
		if i >= 0:
			pos.append(i)
		else:
			neg.append(i)

	pos.sort()
	neg.sort(reverse=True)
	answer = []

	if k % 2 == 1 and not pos:
		for i in range(k):
			s *= neg[i]
			s %= 1000000007
		print(s)

	else:
		if k % 2 == 1:
			s = pos.pop()
		for i in range(k//2):
			if len(pos) >= 2:
				answer.append(pos.pop()*pos.pop())
			else:
				break
		for i in range(k//2):
			if len(neg) >= 2:
				answer.append(neg.pop()*neg.pop())
			else:
				break
		answer.sort(reverse=True)
		for i in range(k//2):
			s *= answer[i]
			s %= 1000000007
		print(s)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split(' '))
l = map(int, input().split(' '))

s = 1
if n == k:
	for i in l:
		s *= i
	print(s % 1000000007)
else:
	pos = []
	neg = []

	for i in l:
		if i >= 0:
			pos.append(i)
		else:
			neg.append(i)

	pos = sorted(pos)
	neg = sorted(neg)[::-1]
	answer = []
	s = 1

	if k % 2 == 1 and not pos:
		for i in neg[:k]:
			s *= i
		print(s % 1000000007)

	else:
		if k % 2 == 1:
			s = pos.pop()
		while len(pos) >= 2:
			answer.append(pos.pop()*pos.pop())
		while len(neg) >= 2:
			answer.append(neg.pop()*neg.pop())
		answer = sorted(answer)[::-1]
		for i in range(k//2):
			s *= answer[i]
		print(s % 1000000007)

Fixed submission:
n, k = map(int, input().split(' '))
l = map(int, input().split(' '))

s = 1
if n == k:
	for i in l:
		s *= i
		s %= 1000000007
	print(s)
else:
	pos = []
	neg = []

	for i in l:
		if i >= 0:
			pos.append(i)
		else:
			neg.append(i)

	pos.sort()
	neg.sort(reverse=True)
	answer = []

	if k % 2 == 1 and not pos:
		for i in range(k):
			s *= neg[i]
			s %= 1000000007
		print(s)

	else:
		if k % 2 == 1:
			s = pos.pop()
		for i in range(k//2):
			if len(pos) >= 2:
				answer.append(pos.pop()*pos.pop())
			else:
				break
		for i in range(k//2):
			if len(neg) >= 2:
				answer.append(neg.pop()*neg.pop())
			else:
				break
		answer.sort(reverse=True)
		for i in range(k//2):
			s *= answer[i]
			s %= 1000000007
		print(s)

Buggy python submission (verdict: Time Limit Exceeded):
import math

n, k = map(int, input().split(' '))
l = map(int, input().split(' '))
pos = []
neg = []

for i in l:
	if i >= 0:
		pos.append(i)
	else:
		neg.append(i)

p = 0
n = 0
pos = sorted(pos)[::-1]
neg = sorted(neg)

answer = []
placeholder = -1

if k % 2 == 1:
	if len(pos) > 0:
		placeholder = pos.pop()
	else:
		placeholder = -2
		neg = neg[::-1]
	k -= 1

len_pos = len(pos)
len_neg = len(neg)
pos.append(0)
pos.append(0)
neg.append(0)
neg.append(0)

for i in range(k//2):
	if pos[p+0] * pos[p+1] >= neg[n+0] * neg[n+1]:
		answer.append(pos[p+0])
		answer.append(pos[p+1])
		p += 2
		p = min(p, len_pos)

	else:
		answer.append(neg[n+0])
		answer.append(neg[n+1])
		n += 2
		n = min(n, len_neg)

if placeholder == -2:
	answer.append(neg[n])
elif placeholder != -1:
	answer.append(max(placeholder, pos[p]))

s = 1
for i in answer:
	s *= i
print(s % 1000000007)

Fixed submission:
n, k = map(int, input().split(' '))
l = map(int, input().split(' '))

s = 1
if n == k:
	for i in l:
		s *= i
		s %= 1000000007
	print(s)
else:
	pos = []
	neg = []

	for i in l:
		if i >= 0:
			pos.append(i)
		else:
			neg.append(i)

	pos.sort()
	neg.sort(reverse=True)
	answer = []

	if k % 2 == 1 and not pos:
		for i in range(k):
			s *= neg[i]
			s %= 1000000007
		print(s)

	else:
		if k % 2 == 1:
			s = pos.pop()
		for i in range(k//2):
			if len(pos) >= 2:
				answer.append(pos.pop()*pos.pop())
			else:
				break
		for i in range(k//2):
			if len(neg) >= 2:
				answer.append(neg.pop()*neg.pop())
			else:
				break
		answer.sort(reverse=True)
		for i in range(k//2):
			s *= answer[i]
			s %= 1000000007
		print(s)

Buggy python submission (verdict: Runtime Error):
import math

n, k = map(int, input().split(' '))
l = map(int, input().split(' '))
pos = []
neg = []


for i in l:
	if i >= 0:
		pos.append(i)
	else:
		neg.append(i)

p = 0
n = 0
pos = sorted(pos)[::-1]
neg = sorted(neg)

answer = []
placeholder = -1

if k % 2 == 1:
	if len(pos) > 0:
		placeholder = pos.pop()
	else:
		placeholder = -2
		neg = neg[::-1]
	k -= 1

pos.append(0)
pos.append(0)
neg.append(0)
neg.append(0)

for i in range(k//2):
	if pos[p+0] * pos[p+1] > neg[n+0] * neg[n+1]:
		answer.append(pos[p+0])
		answer.append(pos[p+1])
		p += 2
	else:
		answer.append(neg[n+0])
		answer.append(neg[n+1])
		n += 2

if placeholder == -2:
	answer.append(neg[n])
elif placeholder != -1:
	if pos[p] > n:
		placeholder = pos[p]
	answer.append(placeholder)

s = 1
for i in answer:
	s *= i
print(s % 1000000007)

Fixed submission:
n, k = map(int, input().split(' '))
l = map(int, input().split(' '))

s = 1
if n == k:
	for i in l:
		s *= i
		s %= 1000000007
	print(s)
else:
	pos = []
	neg = []

	for i in l:
		if i >= 0:
			pos.append(i)
		else:
			neg.append(i)

	pos.sort()
	neg.sort(reverse=True)
	answer = []

	if k % 2 == 1 and not pos:
		for i in range(k):
			s *= neg[i]
			s %= 1000000007
		print(s)

	else:
		if k % 2 == 1:
			s = pos.pop()
		for i in range(k//2):
			if len(pos) >= 2:
				answer.append(pos.pop()*pos.pop())
			else:
				break
		for i in range(k//2):
			if len(neg) >= 2:
				answer.append(neg.pop()*neg.pop())
			else:
				break
		answer.sort(reverse=True)
		for i in range(k//2):
			s *= answer[i]
			s %= 1000000007
		print(s)