Language: C++

#incljude<bits/stdc++.h>
using namespace std;

typedef long long ll;

ll mod = 1e9 + 7;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<ll> mosbat, manfi;
	for (int i = 0; i < n; i++)
	{
		ll x;
		cin >> x;
		if (x >= 0)
		{
			mosbat.push_back(x);
			continue;
		}
		manfi.push_back(-x);
	}
	sort(mosbat.begin(), mosbat.end());
	sort(manfi.begin(), manfi.end());
	if (mosbat.size() == 0)
	{
		ll maj = 1;
		for (int i = 0; i < k; i++)
		{
			maj *= manfi[i];
			maj %= mod;
		}
		if (k % 2 == 1) maj = mod - maj;
		if (maj == mod) maj = 0;
		cout << maj;
		return 0;
	}
	if (manfi.size() == 0)
	{
		ll maj = 1;
		for (int i = mosbat.size() - k; i < mosbat.size(); i++)
		{
			maj *= mosbat[i];
			maj %= mod;
		}
		cout << maj;
		return 0;
	}
	if (n == k)
	{
		ll maj = 1;
		for (int i = 0; i < mosbat.size(); i++)
		{
			maj *= mosbat[i];
			maj %= mod;
		}
		for (int i = 0; i < manfi.size(); i++)
		{
			maj *= manfi[i];
			maj %= mod;
		}
		if (manfi.size() % 2 == 1) maj = mod - maj;
		if (maj == mod) maj = 0;
		cout << maj;
		return 0;
	}
	vector<pair<ll, ll>> all;
	for (int i = 0; i < mosbat.size(); i++)
	{
		all.push_back(make_pair(mosbat[i], 0));
	}
	for (int i = 0; i < manfi.size(); i++)
	{
		all.push_back(make_pair(manfi[i], 1));
	}
	sort(all.begin(), all.end());
	ll maj = 1;
	int t = 0;
	int f = 0;
	for (int i = all.size() - k; i < all.size(); i++)
	{
		if (all[i].second) t++;
		if (all[i].first == 0) f = 1;
	}
	if (f)
	{
		cout << 0;
		return 0;
	}
	if (t % 2 == 0)
	{
		for (int i = all.size() - k; i < all.size(); i++)
		{
			maj *= all[i].first;
			maj %= mod;
		}
		cout << maj;
		return 0;
	}
	int indx_manfi = -1, indx_mosbat = -1;
	for (int i = all.size() - k; i < all.size(); i++)
	{
		if (all[i].second)
		{
			indx_manfi = i;
			break;
		}
	}
	for (int i = all.size() - k; i < all.size(); i++)
	{
		if (!all[i].second)
		{
			indx_mosbat = i;
			break;
		}
	}
	ll maj1 = all[indx_manfi].first, maj2 = all[indx_mosbat].first;
	int indman = -1, indmos = -1;
	for (int i = all.size() - k - 1; i > -1; i--)
	{
		if (all[i].second)
		{
			maj1 *= all[i].first;
			indman = i;
			break;
		}
	}
	for (int i = all.size() - k - 1; i > -1; i--)
	{
		if (!all[i].second)
		{
			maj2 *= all[i].first;
			indmos = i;
			break;
		}
	}
	if (indman == -1)
	{
		maj = all[indmos].first;
		maj %= mod;
		for (int i = all.size() - k; i < all.size(); i++)
		{
			if (i == indx_manfi) continue;
			maj *= all[i].first;
			maj %= mod;
		}
		cout << maj;
		return 0;
	}
	if (indmos == -1)
	{
		maj = all[indman].first;
		maj %= mod;
		for (int i = all.size() - k; i < all.size(); i++)
		{
			if (i == indx_mosbat) continue;
			maj *= all[i].first;
			maj %= mod;
		}
		cout << maj;
		return 0;
	}
	maj = max(maj1, maj2);
	maj %= mod;
	for (int i = all.size() - k; i < all.size(); i++)
	{
		if (i == indx_manfi || i == indx_mosbat) continue;
		maj *= all[i].first;
		maj %= mod;
	}
	cout << maj;
}


Compiler output:
a.cc:1:2: error: invalid preprocessing directive #incljude; did you mean #include?
    1 | #incljude<bits/stdc++.h>
      |  ^~~~~~~~
      |  include
a.cc: In function 'int main()':
a.cc:11:9: error: 'cin' was not declared in this scope
   11 |         cin >> n >> k;
      |         ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | #incljude<bits/stdc++.h>
a.cc:12:9: error: 'vector' was not declared in this scope
   12 |         vector<ll> mosbat, manfi;
      |         ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | #incljude<bits/stdc++.h>
a.cc:12:18: error: expected primary-expression before '>' token
   12 |         vector<ll> mosbat, manfi;
      |                  ^
a.cc:12:20: error: 'mosbat' was not declared in this scope
   12 |         vector<ll> mosbat, manfi;
      |                    ^~~~~~
a.cc:12:28: error: 'manfi' was not declared in this scope
   12 |         vector<ll> mosbat, manfi;
      |                            ^~~~~
a.cc:24:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   24 |         sort(mosbat.begin(), mosbat.end());
      |         ^~~~
      |         short
a.cc:36:17: error: 'cout' was not declared in this scope
   36 |                 cout << maj;
      |                 ^~~~
a.cc:36:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:47:17: error: 'cout' was not declared in this scope
   47 |                 cout << maj;
      |                 ^~~~
a.cc:47:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:65:17: error: 'cout' was not declared in this scope
   65 |                 cout << maj;
      |                 ^~~~
a.cc:65:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:68:16: error: 'pair' was not declared in this scope
   68 |         vector<pair<ll, ll>> all;
      |                ^~~~
a.cc:1:1: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
  +++ |+#include <utility>
    1 | #incljude<bits/stdc++.h>
a.cc:68:23: error: expected primary-expression before ',' token
   68 |         vector<pair<ll, ll>> all;
      |                       ^
a.cc:68:27: error: expected primary-expression before '>>' token
   68 |         vector<pair<ll, ll>> all;
      |                           ^~
a.cc:68:30: error: 'all' was not declared in this scope; did you mean 'll'?
   68 |         vector<pair<ll, ll>> all;
      |                              ^~~
      |                              ll
a.cc:71:31: error: 'make_pair' was not declared in this scope
   71 |                 all.push_back(make_pair(mosbat[i], 0));
      |                               ^~~~~~~~~
a.cc:71:31: note: 'std::make_pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
a.cc:75:31: error: 'make_pair' was not declared in this scope
   75 |                 all.push_back(make_pair(manfi[i], 1));
      |                               ^~~~~~~~~
a.cc:75:31: note: 'std::make_pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
a.cc:88:17: error: 'cout' was not declared in this scope
   88 |                 cout << 0;
      |                 ^~~~
a.cc:88:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:98:17: error: 'cout' was not declared in this scope
   98 |                 cout << maj;
      |                 ^~~~
a.cc:98:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:133:25: error: 'maj2' was not declared in this scope; did you mean 'maj1'?
  133 |                         maj2 *= all[i].first;
      |                         ^~~~
      |                         maj1
a.cc:148:17: error: 'cout' was not declared in this scope
  148 |                 cout << maj;
      |                 ^~~~
a.cc:148:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:161:17: error: 'cout' was not declared in this scope
  161 |                 cout << maj;
      |                 ^~~~
a.cc:161:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:164:25: error: 'maj2' was not declared in this scope; did you mean 'maj1'?
  164 |         maj = max(maj1, maj2);
      |                         ^~~~
      |                         maj1
a.cc:164:15: error: 'max' was not declared in this scope; did you mean 'maj'?
  164 |         maj = max(maj1, maj2);
      |               ^~~
      |               maj
a.cc:172:9: error: 'cout' was not declared in this scope
  172 |         cout << maj;
      |         ^~~~
a.cc:172:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'