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 fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#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;
/
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
const int mod = 1000000007;
const int mod = 998244353;
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;}

//obj;
class binary{
public:
    bool isOK(int index, int key,vi a) {
    if (a[index] >= key) return true;
    else return false;
}
int binary_search(int key,vi a) {
   
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key,a)) ok = mid;
        else ng = mid;
    }
    return ok;
}
}obj;

ll hantei(int a){
    ll ans=1;
   for (int i = 2; i <= sqrt(a); i++) {
    ll cnt = 0;
    while (a % i == 0) {
      cnt++;
      a /= i;
    }
    ans *= (cnt + 1);
    if (a == 1) break;
   }
   if (a != 1) ans *= 2;
ans=ans*a;
    return ans;
   
}
#define MAX 1000000007

int main(){
    int n,k;cin>>n>>k;
	vll a(n+1,-1);
	vll b(n+1,1);
	rep(i,n){
ll an=0;
	cin>>an;
	if(an<0)b.at(i)=an;
	else a.at(i)=an%MAX;
	}
ll ans=1;
	sort(all(a));
	reverse(all(a));
	sort(all(b));
  ll ansn=1;
	if(a.at(0)==-1){
	
		if(k%2==0){rep(i,k){
			ansn*=b.at(i);
			
		}
		ansn%=MAX;
		cout<<ansn<<endl;
		return 0;
		}else{
		reverse(all(b));
		for(int i=1;i<=k;i++){
					ansn*=b.at(i);
			
				}
          //cout<<ansn<<endl;
		  		ans%=MAX;
		        if(ans<0)ans+=MAX;
				cout<<ansn<<endl;
				return 0;
		
		}
	}else {
	if(k%2==0){
		for(int j=0;j<n;j+=2){
			a.at(j)=(a.at(j)*a.at(j+1))%MAX;
			b.at(j)=(b.at(j)*b.at(j+1))%MAX;
   
		}
		int h=0,in=0,jn=0;
		while(h<k){
			ans*=max(a.at(in),b.at(jn));
		ans%=MAX;
      if(ans<0)ans+=MAX;
			if(a.at(in)<b.at(jn))jn+=2;
			else in+=2;
			h+=2;
			
		}
		cout<<ans<<endl;
		return 0;
	
	}else{
	for(int j=0;j<n;j+=2){
		b.at(j)=(b.at(j)*b.at(j+1))%MAX;
     
	}
	for(int j=1;j<n;j+=2){
		a.at(j)=(a.at(j)*a.at(j+1))%MAX;
	}
	int h=0,in=0,jn=0;
	while(h<k){
		ans*=max(a.at(in),b.at(jn));
		ans%=MAX;
      if(ans<0)ans+=MAX;
		if(a.at(in)<b.at(jn)){
		jn+=2;
		h+=2;}
		else if(in==0&&a.at(in)>b.at(jn)){
		in++;
		h++;}
		else {
		in+=2;
		h+=2;
	}
	}
	cout<<ans<<endl;
	return 0;
	
	
	}
	
	
	}
	
	
	
	return 0;
 }


Compiler output:
a.cc:34:1: error: expected unqualified-id before '/' token
   34 | /
      | ^
a.cc:20:13: error: expected unqualified-id before numeric constant
   20 | #define mod 998244353
      |             ^~~~~~~~~
a.cc:46:11: note: in expansion of macro 'mod'
   46 | const int mod = 1000000007;
      |           ^~~
a.cc:20:13: error: expected unqualified-id before numeric constant
   20 | #define mod 998244353
      |             ^~~~~~~~~
a.cc:47:11: note: in expansion of macro 'mod'
   47 | const int mod = 998244353;
      |           ^~~