Language: C++

#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define pb push_back
#define F first 
#define S second 
#define f(i,n) for(int i=0;i<n;i++) 

using namespace std;

ll const mod = 1e9 + 7;

void test(){
	ll n,k;
	cin>>n>>k;
	ll a[n];
	f(i,n)cin>>a[i];
	vector<ll> x,y;
	ll zero = 0;
	f(i,n){
		if(a[i]>0)x.pb(a[i]);
		else if(a[i]<0)y.pb(a[i]);
		else zero++;	
	}
	sort(x.rbegin(),x.rend());
	sort(y.begin(),y.end());
	ll s1 = x.size(), s2 = y.size();
	bool flag = true;
	if((s1+s2)<k)cout<<"0\n";
	else{
		if(k%2==0){
			ll res = 1LL;
			int in1=0,in2 = 0;
			int count = 0;
			while(count<(k-k%2) and in1<(s1-1) and in2<(s2-1)){
				ll x1 = x[in1]*x[in1+1];
				ll x2 = y[in2]*y[in2+1];
				if(x1>x2){
					res = (res*(x1%mod))%mod;
					in1 = in1 + 2;
				}else{
					res = (res*(x2%mod))%mod;
					in2 = in2 + 2;	
				}
				count = count+2;
			}
			while(count<(k-k%2) and in1<(s1-1) ){
				ll x1 = x[in1]*x[in1+1];
				res = (res*(x1%mod))%mod;
				in1 = in1 + 2;
				count = count + 2;
			}
			while(count<(k-k%2) and in2<(s2-1) ){
				ll x2 = y[in2]*y[in2+1];
				res = (res*(x2%mod))%mod;
				in2 = in2 + 2;
				count = count + 2;
			}
			if(count==k)
				cout<<res<<"\n";
			else{
				res = (res*x[in])%mod;
				res = (res*y[in]);
				res = (res + mod)%mod;
				if(zero>0)cout<<"0\n";
				else cout<<res<<"\n";
			}
		}else{
			// if prod is possible to be positive 
			ll maxa = (s2-s2%2) ;
			maxa = maxa + s1;
			if(s1>0 and s1%2==0)maxa--;
			if(maxa>=k and s1>0){
				ll res = 1LL;
				int in1=0,in2 = 0;
				int count = 0;
				while(count<(k-k%2) and in1<(s1-2) and in2<(s2-1)){
					ll x1 = x[in1]*x[in1+1];
					ll x2 = y[in2]*y[in2+1];
					if(x1>x2){
						res = (res*(x1%mod))%mod;
						in1 = in1 + 2;
					}else{
						res = (res*(x2%mod))%mod;
						in2 = in2 + 2;	
					}
					count = count+2;
				}
				while(count<(k-k%2) and in1<(s1-2) ){
					ll x1 = x[in1]*x[in1+1];
					res = (res*(x1%mod))%mod;
					in1 = in1 + 2;
					count = count + 2;
				}
				while(count<(k-k%2) and in2<(s2-1) ){
					ll x2 = y[in2]*y[in2+1];
					res = (res*(x2%mod))%mod;
					in2 = in2 + 2;
					count = count + 2;
				}
				res = (res*x[in1])%mod;
				cout<<res<<"\n";
			}else if(zero>0){
				cout<<"0\n";
			}else{ // prod is negative 
				reverse(x.begin(),x.end());
				reverse(y.begin(),y.end());
				
				ll res = 1LL;
				int in1=0,in2 = 0;
				int count = 0;
				while(count<(k-k%2) and in1<(s1-1) and in2<(s2-1)){
					ll x1 = x[in1]*x[in1+1];
					ll x2 = y[in2]*y[in2+1];
					if(x1<=x2){
						res = (res*(x1%mod))%mod;
						in1 = in1 + 2;
					}else{
						res = (res*(x2%mod))%mod;
						in2 = in2 + 2;	
					}
					count = count+2;
				}
				while(count<(k-k%2) and in1<(s1-1) ){
					ll x1 = x[in1]*x[in1+1];
					res = (res*(x1%mod))%mod;
					in1 = in1 + 2;
					count = count + 2;
				}
				while(count<(k-k%2) and in2<(s2-1) ){
					ll x2 = y[in2]*y[in2+1];
					res = (res*(x2%mod))%mod;
					in2 = in2 + 2;
					count = count + 2;
				}
				res = res*y[in2];
				res = (res + mod )%mod;
				cout<<res<<"\n";
			}
		}
	}
}

int main(){
	int tests=1;
//	cin>>tests;
	while(tests--){
		test();
	}
}

Compiler output:
a.cc: In function 'void test()':
a.cc:62:46: error: 'in' was not declared in this scope; did you mean 'in2'?
   62 |                                 res = (res*x[in])%mod;
      |                                              ^~
      |                                              in2