Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <iostream>
#include <bitset>
#include <map>

#define db double
#define vi vector<int>
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define pp pair<int,int>
#define fix(n) fixed << setprecision(n)
#define gmax(a,b) __gcd(a,b)
#define gmin(a,b) a/__gcd(a,b)*b
using namespace std;
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, 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;
	vi a;
	vi b;
	vll p;
rep(i,n){
	int an;
	cin>>an;
	if(an<0)b.pb(an);
	else a.pb(an);
}	
sort(all(a));
sort(all(b));
ll ans=1;
//mint ans=1;
if(a.size()==0){
	if(k%2==0)rep(i,k){
	ans*=b.at(i);
	ans=(ans%mod+mod)%mod;
	}
	else {
	rep(i,k){
	ans*=b.back();
	b.popb();
	//cout<<ans;
	ans=(ans%mod+mod)%mod;
	}
	}
	cout<<ans<<endl;
	return 0;	
}else{
	if(k%2==0){
	reverse(all(b));
	while(b.size()>=2){
	ll x=b.back();b.popb();
	x*=b.back();b.popb();x=(x%mod+mod)%mod;
	p.pb(x);
	}
	if(b.size()==1)p.bp(b.back());
	while(a.size()>=2){
	ll x=a.back();a.popb();
	x*=a.back();a.popb();
	x=(x%mod+mod)%mod;
	p.pb(x);
	}
	if(a.size()==1)p.bp(a.back());
	sort(all(p));
	rep(i,k/2){
	ans*=p.back();
	p.popb();
		
	ans=(ans%mod+mod)%mod;
	//cout<<ans<<endl;
	}
	cout<<ans<<endl;
	return 0;
	}else{
	reverse(all(b));
	while(b.size()>=2){
	ll x=b.back();b.popb();
	x*=b.back();b.popb();x=(x%mod+mod)%mod;
	p.pb(x);
	}
	if(b.size()==1)p.pb(b.back());
	ll exp=a.back();
	a.popb();
	while(a.size()>=2){
	ll x=a.back();a.popb();
	x*=a.back();a.popb();
	x=(x%mod+mod)%mod;
	p.pb(x);
	}
	if(a.size()==1)p.pb(a.back());
	sort(all(p));
	rep(i,k/2){
	ans*=p.back();	
	p.popb();	
	ans=(ans%mod+mod)%mod;
	}
	ans*=exp;
	ans=(ans%mod+mod)%mod;
	cout<<ans<<endl;
	return 0;
	
	}
	
}


	
return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:107:26: error: 'class std::vector<long long int>' has no member named 'bp'
  107 |         if(b.size()==1)p.bp(b.back());
      |                          ^~
a.cc:114:26: error: 'class std::vector<long long int>' has no member named 'bp'
  114 |         if(a.size()==1)p.bp(a.back());
      |                          ^~