Language: C++

// author - saiku_ni_naro
// TO THE TOP

#include<bits/stdc++.h>
using namespace std;
#define F_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define double long double
#define endl '\n'
#define For(i,a,n) for(int i=(a);i<=(n);i++)
#define RFor(i,a,n) for(int i=(n);i>=(a);i--)
#define SET(a,val) memset((a),(val),sizeof((a)))
#define X first
#define Y second
#define pb push_back
#define over(v) v.begin(),v.end()
#define sz(x) (int)x.size()
#define inp(x) cin>>x;
#define oup(x) cout<<x<<endl;

const int N = 2e5 + 10;
int a[N];
const int MOD = 1e9 + 7;
vector<int> Pos,Neg;
vector<double> PosSum,NegSum;
vector<int> NegPair;
vector<double> NegPairSum;

void solving_problem(){
    int n,k; cin>>n>>k;

    For(i,1,n) cin>>a[i];
    sort(a+1,a+n+1);

    int product = 1;

    if(a[n] == 0 && (k&1)){
        cout<<0<<endl;
        return;
    }

    if(a[n] <= 0 && (k&1)){
        RFor(i,n-k+1,n) {
            a[i] = (a[i]+MOD)%MOD;
            product = (product*a[i])%MOD;
        }
        cout<<product<<endl;
        return;
    }

    int i = 1,j = n;

    if(k&1){
        product = (product*a[j])%MOD;
        j--,k--;
    }

    k>>=1;

    For(i,1,n) a[i] = abs(a[i));

    For(itr,1,k){
        int leftP = a[i]*a[i+1];
        int rightP = a[j]*a[j-1];

        if(leftP > rightP){
            leftP = leftP%MOD;
            product = (product*leftP)%MOD;
            i+=2;
        }else {
            rightP = rightP%MOD;
            product = (product*rightP)%MOD;
            j-=2;
        }
    }

    cout<<product<<endl;
}

signed main(){
    F_IO;

    int testcases = 1; 
    // cin>>testcases;

    For(i,1,testcases){
        // cout<<"Cases #"<<i<<": ";
        solving_problem();
    }
}


    // For(i,1,n){
    //     cin>>a[i];
    //     if(a[i] < 0) Neg.push_back(-a[i]);
    //     else if(a[i] > 0) Pos.push_back(a[i]);
    //     else zero++;
    // }

    // sort(all(Pos)); reverse(all(Pos));
    // sort(all(Neg)); reverse(all(Neg));

    // For(i,0,sz(Pos)-1) PosSum.push_back(log(Pos[i]));
    
    // For(i,1,sz(Neg)-1) NegPair.push_back(Neg[i]*Neg[i-1]);
    // For(i,0,sz(NegPair)) NegPairSum.push_back(log(NegPair[i]));

    // if(sz(Pos) + sz(Neg) < k){
    //     cout<<0<<endl; 
    //     return;
    // }

    // int NegC = -1;
    // double Sum = 0;

    // For(i,0,sz(NegSum)){
    //     double sumTemp = 0;
    //     if(i > 0) sumTemp += NegPairSum[i-1];

    //     int Left = k - 2*i;
    //     if(Left < 0 || sz(Pos) < Left) continue;

    //     int FromPos = min(Left,sz(Pos));
    //     if(FromPos > 0) sumTemp += PosSum[FromPos-1];

    //     if(sumTemp > Sum) Sum = sumTemp,NegC = i;
    //     continue;
    // }

    // if(NegC == -1){
    //     if(zero) cout<<0<<endl;
    //     else 
    // }

Compiler output:
a.cc: In function 'void solving_problem()':
a.cc:60:30: error: expected ']' before ')' token
   60 |     For(i,1,n) a[i] = abs(a[i));
      |                              ^
      |                              ]
a.cc:60:31: error: expected ';' before ')' token
   60 |     For(i,1,n) a[i] = abs(a[i));
      |                               ^
      |                               ;