Language: C++

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define mod 1000000007
signed main() {
    int n, k;
    cin >> n >> k;
    int arr[n];
    int i;
    for(i=0;i<n;i++)
        cin >> arr[i];
    sort(arr, arr+n);
    if(arr[n-1] < 0)
    {
        int ans = 1;
        for(i=n-1;i>=n-k;i--)
            ans = ans*arr[i]%mod;
        cout << (ans+mod)%mod; 
        return 0;
    }
    else
    {
        vector<int> pos,neg;
        int s = 0, e = n-1;
        for(int i=0;i<k;++i){
            if(abs(a[s])>abs(a[e])){
                if(a[s]<0){
                    neg.push_back(a[s]);
                }else{
                    pos.push_back(a[s]);
                }
                ++s;
            }else{
                if(a[e]<0){
                    neg.push_back(a[e]);
                }else{
                    pos.push_back(a[e]);
                }
                --e;
            }
        }
        if(neg.size()&1){
            if(e==n-1){
                //No positive
                neg.pop_back();
                pos.push_back(a[e]);
            }else{
                //Atleast one pos present
                //case remove neg add pos
                int p1=-1;
                if(a[e]>=0){
                    p1=a[e]*a[e+1];
                }
                //case add neg remove pos
                int p2=-1;
                if(a[s]<=0){
                    p2=a[s]*a[s-1];
                }
                if(p1==-1&&p2!=-1){
                    pos.pop_back();
                    neg.push_back(a[s]);
                }else if(p1!=-1&&p2==-1){
                    neg.pop_back();
                    pos.push_back(a[e]);
                }else{
                    if(p1>p2){
                        neg.pop_back();
                        pos.push_back(a[e]);
                    }else{
                        pos.pop_back();
                        neg.push_back(a[s]);
                    }
                }
            }
        }
        int ans=1;
        for(int ele:pos){
            ans=ans*ele%mod;
        }
        for(int ele:neg){
            ans=ans*abs(ele)%mod;
        }
        cout<<ans<<'\n';
    }
    
    
    
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:20: error: 'a' was not declared in this scope
   27 |             if(abs(a[s])>abs(a[e])){
      |                    ^
a.cc:47:31: error: 'a' was not declared in this scope
   47 |                 pos.push_back(a[e]);
      |                               ^
a.cc:52:20: error: 'a' was not declared in this scope
   52 |                 if(a[e]>=0){
      |                    ^
a.cc:57:20: error: 'a' was not declared in this scope
   57 |                 if(a[s]<=0){
      |                    ^
a.cc:62:35: error: 'a' was not declared in this scope
   62 |                     neg.push_back(a[s]);
      |                                   ^
a.cc:65:35: error: 'a' was not declared in this scope
   65 |                     pos.push_back(a[e]);
      |                                   ^
a.cc:69:39: error: 'a' was not declared in this scope
   69 |                         pos.push_back(a[e]);
      |                                       ^
a.cc:72:39: error: 'a' was not declared in this scope
   72 |                         neg.push_back(a[s]);
      |                                       ^