Language: C++

#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using P = pair<int,int>;
using ll = long long;

const int mod 1000000007;
#define MOD 1000000007
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> pos,neg,a(n);
    rep(i,n) {
        cin >> a[i];
        if (a[i] < 0) neg.push_back(a[i]);
        else pos.push_back(a[i]);
    }
    bool ok = false;
    int p_size = pos.size(), n_size = neg.size();
    if (p_size > 0) {
        if (n == k) ok = (n_size%2 == 0);
        else ok = true;
    } else {
        ok = (k%2 == 0);
    }
     
 	mint = 1;
    if (!ok) {
        sort(a.begin(),a.end(),[](int x, int y){
            return abs(x) < abs(y);
        });
        rep(i,k) {
            ans *= a[i];
            ans = (ans + MOD)%MOD;
        }
    } else {
        sort(pos.begin(),pos.end());
        sort(neg.rbegin(),neg.rend());
        if (k%2 == 1) {
            ans *= pos.back();
            pos.pop_back();
        }
        vector<ll> stk;
        while (pos.size() >= 2) {
            ll x = pos.back(); pos.pop_back();
            x *= pos.back(); pos.pop_back();
            x %= MOD;
            stk.push_back(x);
        }
        while (neg.size() >= 2) {
            ll x = neg.back(); neg.pop_back();
            x *= neg.back(); neg.pop_back();
            x %= MOD;
            stk.push_back(x);
        }
        sort(stk.rbegin(),stk.rend());
        rep(i,k/2) {
            ans *= stk[i];
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc:7:15: error: expected initializer before numeric constant
    7 | const int mod 1000000007;
      |               ^~~~~~~~~~
a.cc: In constructor 'mint::mint(ll)':
a.cc:11:21: error: 'mod' was not declared in this scope; did you mean 'modf'?
   11 |   mint(ll x=0):x((x%mod+mod)%mod){}
      |                     ^~~
      |                     modf
a.cc: In member function 'mint& mint::operator+=(mint)':
a.cc:14:23: error: 'mod' was not declared in this scope; did you mean 'modf'?
   14 |     if ((x += a.x) >= mod) x -= mod;
      |                       ^~~
      |                       modf
a.cc: In member function 'mint& mint::operator-=(mint)':
a.cc:18:15: error: 'mod' was not declared in this scope; did you mean 'modf'?
   18 |     if ((x += mod-a.x) >= mod) x -= mod;
      |               ^~~
      |               modf
a.cc: In member function 'mint& mint::operator*=(mint)':
a.cc:21:50: error: 'mod' was not declared in this scope; did you mean 'modf'?
   21 |   mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
      |                                                  ^~~
      |                                                  modf
a.cc: In member function 'mint mint::inv() const':
a.cc:34:33: error: 'mod' was not declared in this scope; did you mean 'modf'?
   34 |   mint inv() const { return pow(mod-2);}
      |                                 ^~~
      |                                 modf
a.cc: In function 'int main()':
a.cc:59:14: error: expected unqualified-id before '=' token
   59 |         mint = 1;
      |              ^
a.cc:65:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   65 |             ans *= a[i];
      |             ^~~
      |             abs
a.cc:72:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   72 |             ans *= pos.back();
      |             ^~~
      |             abs
a.cc:90:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   90 |             ans *= stk[i];
      |             ^~~
      |             abs
a.cc:94:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   94 |     cout << ans << endl;
      |             ^~~
      |             abs