Language: C++

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <map>
#include <string.h>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>

using namespace std;
#define set_precision cout << fixed << setprecision(10)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define replb(i, a, b) for (ll i = a; i >= b; i--)
#define repl(i, a, b) for (ll i = a; i < b; i++)
#define repit(arr) for (auto it = arr.begin(); it != arr.end(); it++)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define dsortA(arr) sort(arr.begin(), arr.end(), greater<int>())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define search(arr, c) binary_search(arr.begin(), arr.end(), c)
#define pb push_back
#define ll long long
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define castl static_cast<ll>
int fact(int n) 
{ 
    int res = 1; 
    for (int i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
}
int nCr(int n, int r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
}
int cel(int a,int b){return((a-1)/b+1);} 
int gcd(int a, int b)
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}
int lcm(int a,int b){
    return (a*b)/gcd(a,b);
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll k,x,y,z,w,n;ll a=int(1e9+7);
    cin>>n>>k;ll p=1,ans=1,ans1=1,c=0,c1=0,c2=0;vl v,u,v1,u1;
    rep(i,0,n){
        cin>>x;p=(p*x)%a;
        if(x<0){u.pb(x);u1.pb(x);c1++;}
        else if(x>=0){v.pb(x);v1.pb(x);c2++;}
    }
    dsortA(u);sortA(v);sortA(u1);dsortA(v1);
    if(k==n){
        if(p<0)cout<<p+a;
        else cout<<p%a;}
    else if(c2==0){
         if(k%2==0){
             rep(i,0,k){ans=(ans*abs(u1[i]))%a;}//cout<<ans<<" ";}
             cout<<ans;
         }
         else if(k%2){
             rep(i,0,k){ans=(ans*abs(u[i]))%a;//cout<<ans<<" ";}
             cout<<(a-(ans))%a;
         }
    }
    else if(c1==0){
        rep(i,0,k){ans=(ans*v1[i])%a;}
        if(ans%a<0)cout<<(ans)+a;
        else cout<<(ans);
    }
    else{
        ans1=1;c=0;
        while(1){
            if(c==k)break;
            else if(c==k-1){ans1=(ans1*v.back())%a;v.pop_back();c++;}
            else if(u.size()<=1){ans1=(ans1*v.back())%a;v.pop_back();c++;}
            else if(v.size()<=1){ans1=(ans1*u.back())%a;u.pop_back();ans1=(ans1*u.back())%a;u.pop_back();c+=2;}
            else{
                x=u.back();y=v.back();u.pop_back();v.pop_back();w=u.back();z=v.back();u.pop_back();v.pop_back();
                if(y*z>x*w){ans1=(ans1*(y))%a;u.pb(x);u.pb(w);v.pb(z);c++;}
                else{ans1=(ans1*(x*w))%a;v.pb(y);v.pb(z);c+=2;}
            }
        }
        if(ans1<0)cout<<(ans1)+a;
        else cout<<(ans1); 
    }  
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:111:2: error: expected '}' at end of input
  111 | }
      |  ^
a.cc:64:1: note: to match this '{'
   64 | {
      | ^