Language: C++

#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif


// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};


using mint = Fp<MOD>;


int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	ll N, K; cin >> N >> K;
	vector<ll> A(N), l, r;
	rep(i, N) {
		cin >> A[i];
		if(A[i] < 0) l.push_back(A[i]);
		else r.push_back(A[i]);
	}

	sort(ALL(l));
	sort(ALL(r), graeter<ll>());

	if(N == K){
		ll ans = 1;
		rep(i, N){
			ans = ans * A[i] % MOD;
			if(ans < 0) ans += MOD;
		}
		cout << ans << endl;
		return 0;
	}
	if(N == l.size() && K % 2 == 1){
		sort(ALL(A), greater<ll>());
		ll ans = 1;
		rep(i, K){
			ans = ans * A[i] % MOD;
			if(ans < 0) ans += MOD;
		}
		cout << ans << endl;
		return 0;
	}

	// print(1);

	int l_idx = 0;
	int r_idx = 0;
	int choiced_cnt = 0;
	mint ans = 1;
	while(choiced_cnt < K){
		ll lv = 1, rv = 1;
		rep(i, 2){
			if(l_idx + i >= l.size()){
				lv = 0;
				break;
			}
			lv *= l[l_idx + i];
		}

		rep(i, 2){
			if(r_idx + i >= r.size()){
				if(!i) rv = 0;
				break;
			}
			rv *= r[r_idx + i];
		}

		if(lv > rv && K - choiced_cnt > 1){
			ans *= lv;
			choiced_cnt+=2;
			l_idx += 2;
		}
		else{
			ans *= r[r_idx];
			r_idx++;
			choiced_cnt++;
		}
	}

	cout << ans << endl;


	return 0;
}


Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:127:22: error: 'graeter' was not declared in this scope
  127 |         sort(ALL(r), graeter<ll>());
      |                      ^~~~~~~
a.cc:127:32: error: expected primary-expression before '>' token
  127 |         sort(ALL(r), graeter<ll>());
      |                                ^
a.cc:127:34: error: expected primary-expression before ')' token
  127 |         sort(ALL(r), graeter<ll>());
      |                                  ^