Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> V;
typedef pair<int,int> P;
typedef vector<vector<int>> Graph;

const int 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, const 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<pair<ll,int>> a(n);
    int cnt=0;
    rep(i,n){
        ll c;
        cin >> c;
        if(c<0) a[i] = make_pair(-c,-1);
        else if(c>0) a[i] = make_pair(c,1);
        else cnt++;
    }

    if(cnt>=k){
        cout << 0 << endl;
        return 0;
    }

    sort(ALL(a));
    reverse(ALL(a));
    mint ans = 1;
    ll p,m;
    int flag = 0; 
    rep(i,k){
        ans *= a[i].first;
        if(a[i].second==1){
            p = i;
        }
        else {
            m = i;
            flag++;
        }
    }

    if(flag%2==0){
        cout << ans << endl;
        return 0;
    }
    int np=p,nm=m;
    for(int i = p+1;i<n;i++){
        if(a[i].second==1){
            np = i;
            break;
        }
    }
    for(int i = m+1;i<n;i++){
        if(a[i].second==-1){
            nm = i;
            break;
        }
    }
    if(p==np&&m==nm) {
        ans = -1;
        reverse(ALL(a))
        rep(i,k){
            ans *= a[i].first;
        }
    }
    else if(p==np) {
        ans /= a[p].first;
        ans *= a[nm].first;
    }
    else if(m==nm){
        ans /= a[m].first;
        ans *= a[np].first;
    }
    else {
        if(a[p].first*a[nm].first>=a[np].first*a[m].first){
            ans /= a[p].first;
            ans *= a[nm].first;
        }
        else {
            ans /= a[m].first;
            ans *= a[np].first;
        }
    }
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:99:24: error: expected ';' before 'for'
   99 |         reverse(ALL(a))
      |                        ^
      |                        ;
a.cc:100:13: error: 'i' was not declared in this scope
  100 |         rep(i,k){
      |             ^
a.cc:2:31: note: in definition of macro 'rep'
    2 | #define rep(i,n) for (int i=0;i < (n); ++i)
      |                               ^