Language: C++

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

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

const int MOD = 1e9 + 7;

int main(int argc, char** argv[]) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> pos, neg;
  bool zero = false;
  vector<int> a(n);
  for (int x, i = 0; i < n; i++) {
    cin >> x;
    zero |= x == 0;
    if (x > 0) pos.push_back(x);
    if (x < 0) neg.push_back(x);
    a[i] = x;
  }
  if (sz(pos) + sz(neg) < k) return cout << 0, 0;
  sort(all(pos));
  sort(all(neg));
  reverse(all(neg));
  if ((pos.empty() && k % 2 == 1) || (sz(neg) + sz(pos) == k && sz(neg) & 1) || n == k) {
    if (zero) return cout << 0, 0;
    sort(all(a));
    reverse(all(a));
    long long product = 1;
    for (int i = 0; i < k; i++) {
      product = (product % MOD * a[i] % MOD) % MOD;
      product %= MOD;
    }
    while (product < 0) product %= MOD;
    return cout << product << '\n', 0;
  }
  vi res;
  auto add = [&](vi& nums) {
    res.push_back(nums.back());
    nums.pop_back();
    res.push_back(nums.back());
    nums.pop_back();
  };
  if (k & 1) {
    res.push_back(pos.back());
    pos.pop_back();
    --k;
  }
  while (k >= 2) {
    if (sz(pos) >= 2 && sz(neg) >= 2) {
      long long x = 1ll * pos[sz(pos) - 1] * pos[sz(pos) - 2];
      long long y = 1ll * neg[sz(neg) - 1] * neg[sz(neg) - 2];
      if (x > y)
        add(pos);
      else
        add(neg);
    } else if (sz(neg) >= 2)
      add(neg);
    else
      add(pos);
    k -= 2;
  }
  long long product = 1;
  for (int& num : res) {
    product = (product % MOD * num % MOD) % MOD;
    while (product < 0) product += MOD;
    product %= MOD;
  }
  cout << product % MOD << '\n';
  return 0;
}


Compiler output:
a.cc:13:1: error: extended character   is not valid in an identifier
   13 |   ios::sync_with_stdio(0);
      | ^
a.cc:14:1: error: extended character   is not valid in an identifier
   14 |   cin.tie(0);
      | ^
a.cc:15:1: error: extended character   is not valid in an identifier
   15 |   int n, k;
      | ^
a.cc:16:1: error: extended character   is not valid in an identifier
   16 |   cin >> n >> k;
      | ^
a.cc:17:1: error: extended character   is not valid in an identifier
   17 |   vector<int> pos, neg;
      | ^
a.cc:18:1: error: extended character   is not valid in an identifier
   18 |   bool zero = false;
      | ^
a.cc:19:1: error: extended character   is not valid in an identifier
   19 |   vector<int> a(n);
      | ^
a.cc:20:1: error: extended character   is not valid in an identifier
   20 |   for (int x, i = 0; i < n; i++) {
      | ^
a.cc:21:1: error: extended character   is not valid in an identifier
   21 |     cin >> x;
      | ^
a.cc:21:1: error: extended character   is not valid in an identifier
a.cc:21:1: error: extended character   is not valid in an identifier
a.cc:22:1: error: extended character   is not valid in an identifier
   22 |     zero |= x == 0;
      | ^
a.cc:22:1: error: extended character   is not valid in an identifier
a.cc:22:1: error: extended character   is not valid in an identifier
a.cc:23:1: error: extended character   is not valid in an identifier
   23 |     if (x > 0) pos.push_back(x);
      | ^
a.cc:23:1: error: extended character   is not valid in an identifier
a.cc:23:1: error: extended character   is not valid in an identifier
a.cc:24:1: error: extended character   is not valid in an identifier
   24 |     if (x < 0) neg.push_back(x);
      | ^
a.cc:24:1: error: extended character   is not valid in an identifier
a.cc:24:1: error: extended character   is not valid in an identifier
a.cc:25:1: error: extended character   is not valid in an identifier
   25 |     a[i] = x;
      | ^
a.cc:25:1: error: extended character   is not valid in an identifier
a.cc:25:1: error: extended character   is not valid in an identifier
a.cc:26:1: error: extended character   is not valid in an identifier
   26 |   }
      | ^
a.cc:28:1: error: extended character   is not valid in an identifier
   28 |   sort(all(pos));
      | ^
a.cc:29:1: error: extended character   is not valid in an identifier
   29 |   sort(all(neg));
      | ^
a.cc:30:1: error: extended character   is not valid in an identifier
   30 |   reverse(all(neg));
      | ^
a.cc:31:1: error: extended character   is not valid in an identifier
   31 |   if ((pos.empty() && k % 2 == 1) || (sz(neg) + sz(pos) == k && sz(neg) & 1) || n == k) {
      | ^
a.cc:32:1: error: extended character   is not valid in an identifier
   32 |     if (zero) return cout << 0, 0;
      | ^
a.cc:32:1: error: extended character   is not valid in an identifier
a.cc:32:1: error: extended character   is not valid in an identifier
a.cc:33:1: error: extended character   is not valid in an identifier
   33 |     sort(all(a));
      | ^
a.cc:33:1: error: extended character   is not valid in an identifier
a.cc:33:1: error: extended character   is not valid in an identifier
a.cc:34:1: error: extended character   is not valid in an identifier
   34 |     reverse(all(a));
      | ^
a.cc:34:1: error: extended character   is not valid in an identifier
a.cc:34:1: error: extended character   is not valid in an identifier
a.cc:35:1: error: extended character   is not valid in an identifier
   35 |     long long product = 1;
      | ^
a.cc:35:1: error: extended character   is not valid in an identifier
a.cc:35:1: error: extended character   is not valid in an identifier
a.cc:36:1: error: extended character   is not valid in an identifier
   36 |     for (int i = 0; i < k; i++) {
      | ^
a.cc:36:1: error: extended character   is not valid in an identifier
a.cc:36:1: error: extended character   is not valid in an identifier
a.cc:37:1: error: extended character   is not valid in an identifier
   37 |       product = (product % MOD * a[i] % MOD) % MOD;
      | ^
a.cc:37:1: error: extended character   is not valid in an identifier
a.cc:37:1: error: extended character   is not valid in an identifier
a.cc:37:1: error: extended character   is not valid in an identifier
a.cc:37:1: error: extended character   is not valid in an identifier
a.cc:38:1: error: extended character   is not valid in an identifier
   38 |       product %= MOD;
      | ^
a.cc:38:1: error: extended character   is not valid in an identifier
a.cc:38:1: error: extended character   is not valid in an identifier
a.cc:38:1: error: extended character   is not valid in an identifier
a.cc:38:1: error: extended character   is not valid in an identifier
a.cc:39:1: error: extended character   is not valid in an identifier
   39 |     }
      | ^
a.cc:39:1: error: extended character   is not valid in an identifier
a.cc:39:1: error: extended character   is not valid in an identifier
a.cc:40:1: error: extended character   is not valid in an identifier
   40 |     while (product < 0) product %= MOD;
      | ^
a.cc:40:1: error: extended character   is not valid in an identifier
a.cc:40:1: error: extended character   is not valid in an identifier
a.cc:41:1: error: extended character   is not valid in an identifier
   41 |     return cout << product << '\n', 0;
      | ^
a.cc:41:1: error: extended character   is not valid in an identifier
a.cc:41:1: error: extended character   is not valid in an identifier
a.cc:42:1: error: extended character   is not valid in an identifier
   42 |   }
      | ^
a.cc:43:1: error: extended character   is not valid in an identifier
   43 |   vi res;
      | ^
a.cc:44:1: error: extended character   is not valid in an identifier
   44 |   auto add = [&](vi& nums) {
      | ^
a.cc:45:1: error: extended character   is not valid in an identifier
   45 |     res.push_back(nums.back());
      | ^
a.cc:45:1: error: extended character   is not valid in an identifier
a.cc:45:1: error: extended character   is not valid in an identifier
a.cc:46:1: error: extended character   is not valid in an identifier
   46 |     nums.pop_back();
      | ^
a.cc:46:1: error: extended character   is not valid in an identifier
a.cc:46:1: error: extended character   is not valid in an identifier
a.cc:47:1: error: extended character   is not valid in an identifier
   47 |     res.push_back(nums.back());
      | ^
a.cc:47:1: error: extended character   is not valid in an identifier
a.cc:47:1: error: extended character   is not valid in an identifier
a.cc:48:1: error: extended character   is not valid in an identifier
   48 |     nums.pop_back();
      | ^
a.cc:48:1: error: extended character   is not valid in an identifier
a.cc:48:1: error: extended character   is not valid in an identifier
a.cc:49:1: error: extended character   is not valid in an identifier
   49 |   };
      | ^
a.cc:50:1: error: extended character   is not valid in an identifier
   50 |   if (k & 1) {
      | ^
a.cc:51:1: error: extended character   is not valid in an identifier
   51 |     res.push_back(pos.back());
      | ^
a.cc:51:1: error: extended character   is not valid in an identifier
a.cc:51:1: error: extended character   is not valid in an identifier
a.cc:52:1: error: extended character   is not valid in an identifier
   52 |     pos.pop_back();
      | ^
a.cc:52:1: error: extended character   is not valid in an identifier
a.cc:52:1: error: extended character   is not valid in an identifier
a.cc:53:1: error: extended character   is not valid in an identifier
   53 |     --k;
      | ^
a.cc:53:1: error: extended character   is not valid in an identifier
a.cc:53:1: error: extended character   is not valid in an identifier
a.cc:54:1: error: extended character   is not valid in an identifier
   54 |   }
      | ^
a.cc:55:1: error: extended character   is not valid in an identifier
   55 |   while (k >= 2) {
      | ^
a.cc:56:1: error: extended character   is not valid in an identifier
   56 |     if (sz(pos) >= 2 && sz(neg) >= 2) {
      | ^
a.cc:56:1: error: extended character   is not valid in an identifier
a.cc:56:1: error: extended character   is not valid in an identifier
a.cc:57:1: error: extended character   is not valid in an identifier
   57 |       long long x = 1ll * pos[sz(pos) - 1] * pos[sz(pos) - 2];
      | ^
a.cc:57:1: error: extended character   is not valid in an identifier
a.cc:57:1: error: extended character   is not valid in an identifier
a.cc:57:1: error: extended character   is not valid in an identifier
a.cc:57:1: error: extended character   is not valid in an identifier
a.cc:58:1: error: extended character   is not valid in an identifier
   58 |       long long y = 1ll * neg[sz(neg) - 1] * neg[sz(neg) - 2];
      | ^
a.cc:58:1: error: extended character   is not valid in an identifier
a.cc:58:1: error: extended character   is not valid in an identifier
a.cc:58:1: error: extended character   is not valid in an identifier
a.cc:58:1: error: extended character   is not valid in an identifier
a.cc:59:1: error: extended character   is not valid in an identifier
   59 |       if (x > y)
      | ^
a.cc:59:1: error: extended character   is not valid in an identifier
a.cc:59:1: error: extended character   is not valid in an identifier
a.cc:59:1: error: extended character   is not valid in an identifier
a.cc:59:1: error: extended character   is not valid in an identifier
a.cc:60:1: error: extended character   is not valid in an identifier
   60 |         add(pos);
      | ^
a.cc:60:1: error: extended character   is not valid in an identifier
a.cc:60:1: error: extended character   is not valid in an identifier
a.cc:60:1: error: extended character   is not valid in an identifier
a.cc:60:1: error: extended character   is not valid in an identifier
a.cc:60:1: error: extended character   is not valid in an identifier
a.cc:60:1: error: extended character   is not valid in an identifier
a.cc:61:1: error: extended character   is not v