criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include<bits/stdc++.h>
using namespace std;
int a[200005];
int zheng[200005];
int ffu[200005];
const long long mod=1e9+7;
bool cmp(int a,int b){
    return abs(a)>abs(b);
}

int n,k;
int main()
{
    scanf("%d%d",&n,&k);
    int s1=0,s2=0,kk=k,cnt0=0;
    for(int i=0;i<n;i++)
	{
        scanf("%d",&a[i]);
        if(a[i]>0){
           zheng[s1]=a[i];s1++;
		   }
        if(a[i]<0){
           ffu[s2]=a[i];s2++;
		   }
		if(a[i]==0)
		cnt0++;
    }
    if(n-cnt0<k)
	{
	    cout<<0<<endl;
		return 0;
	}
    sort(zheng,zheng+s1,cmp);
    sort(ffu,ffu+s2,cmp);
    long long ans=1;
    int ss1=0,ss2=0;
    while(k>0)
	{
        if(abs(zheng[ss1])>abs(ffu[ss2]))
		{
            ans=(ans*(long long)zheng[ss1]) 
            ss1++;
            k--;
        }
        else
		{
            ans=(ans*(long long)ffu[ss2]);
            ss2++;
            k--;
        }
    }
    if(ans>0){
    printf("%lld\n",ans%mod);
    return 0;
    }
    if(ans<0&&ss1>0)
	{
        long long ans1=1;
        if(ss1<s1)
        ans1=(ans*(long long)zheng[ss1]/(long long)ffu[ss2-1])%mod;
        if(ss2<s2)
        ans=(ans*(long long)ffu[ss2]/(long long)zheng[ss1-1])%mod;
        printf("%lld",max(ans1,ans)%mod);
        return 0;
    }
    if(ans<0&&ss1==0)
	{
        sort(ffu,ffu+s2);
        long long ans2=1;
        for(int i=s2-1;i>=s2-kk;i--)
            ans2=((long long)ffu[i]*ans2%mod);
        printf("%lld",(ans2+mod)%mod);
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:41:44: error: expected ';' before 'ss1'
   41 |             ans=(ans*(long long)zheng[ss1])
      |                                            ^
      |                                            ;
   42 |             ss1++;
      |             ~~~
Language: C++

// 及时当勉励，岁月不待人！
//当前状态 : attempted
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<cmath>
#include<string>
#include<iomanip>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
struct node{
    ll val;
    ll op;
    node(int a,int b){
        val=a;op=b;
    }
    bool operator<(const node&b)const{
        return this->val>b.val;
    }
};
const int maxn=2e5+120;
int tmp,n,k;
ll ans=1;
node aaa[200050];
int maxN=-1*inf;
bool cmp(node& a,node &b){
    return a.val>b.val;
}
//函数
int main()
{
    //std::ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i=1;i<=n;++i){
        cin>>tmp;
        maxN=max(maxN,tmp);
        if(tmp>0){
            aaa[i]=node(tmp,1);
        }else{
            aaa[i]=node(-1*tmp,0);
        }
    }
    //aaa[0]=node{-1*inf,0};
    if(k==1){
        cout<<(maxN%mod+mod)%mod<<endl;
        return 0;
    }
    sort(aaa+1,aaa+n+1,cmp);
    int now=1;
    ll mut=1;
    int isH=0;
    while(k){
        node t=aaa[now++];
        if(t.op==1){
            ans=(ans*t.val)%mod;
            --k;
        }else{
            if(isH==1){
                mut=(mut*t.val%mod)%mod;
                ans=(ans*mut)%mod;
                mut=1;
                isH=0;
                k-=2;
            }else{
                mut=(mut*t.val)%mod;
                isH=1;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Compiler output:
a.cc:30:16: error: no matching function for call to 'node::node()'
   30 | node aaa[200050];
      |                ^
a.cc:20:5: note: candidate: 'node::node(int, int)'
   20 |     node(int a,int b){
      |     ^~~~
a.cc:20:5: note:   candidate expects 2 arguments, 0 provided
a.cc:17:8: note: candidate: 'constexpr node::node(const node&)'
   17 | struct node{
      |        ^~~~
a.cc:17:8: note:   candidate expects 1 argument, 0 provided
a.cc:17:8: note: candidate: 'constexpr node::node(node&&)'
a.cc:17:8: note:   candidate expects 1 argument, 0 provided
Language: C++

#include<bits/stdc++.h>
using namespace std;
long long a[300005];
const long long inf=1e9+7;
int main()
{
    long long n,k;
    cin>>n>>k;
    for (long long i=0;i<n;i++){
        scanf("%llu",&a[i]);
    }
    sort(a,a+n);
    long long ans=1;
  
    for (long long i=0;i<k;i++){
        ans=(ans*a[i]+inf)%inf;
    }
    
    num=ans;
    for (long long i=1;i<n;i++){
         if (a[i-1]!=0)   num=(ans/a[i-1]*a[(k+i-1)%n]+inf)%inf);
        else {
              
             for (long long j=i;j<i+k;j++){
                num=(num*a[j]+inf)%inf;
    }   
        }
        ans=max(ans,num);
    }
    cout<<(ans+inf)%inf;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:5: error: 'num' was not declared in this scope; did you mean 'enum'?
   19 |     num=ans;
      |     ^~~
      |     enum
Language: C++

#include<bits/stdc++.h>
using namespace std;
int a[100005];
int zheng[100005];
int ffu[100005];
const long long mod=1e9+7;
bool cmp(int a,int b){
    return abs(a)>abs(b);
}
bool cmp1(int a,int b){
    return a>b;
}
int n,k;
int main()
{
    scanf("%d%d",&n,&k);
    int s1=0,s2=0;
    for(int i=0;i<n;i++)
	{
        scanf("%d",&a[i]);
        if(a[i]>0){
           z[s1]=a[i];s1++;
		   }
        if(a[i]<0){
           f[s2]=a[i];s2++;
		   }
    }
    sort(zheng,zheng+s1,cmp);
    sort(ffu,ffu+s2,cmp);
    long long ans=1;
    int ss1=0,ss2=0;
    while(true)
	{
        if(k==0)
           break;
        if(abs(zheng[ss1])>abs(ffu[ss2]))
		{
            ans=(ans*zheng[ss1])%mod;
            ss1++;
            k--;
        }
        else
		{
            ans=(ans*ffu[ss2])%mod;
            ss2++;
            k--;
        }
    }
    if(ans>0){
    printf("%lld\n",ans%mod);
    return 0;
    else
    printf("%lld\n",(ans+mod)%mod);
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:22:12: error: 'z' was not declared in this scope
   22 |            z[s1]=a[i];s1++;
      |            ^
a.cc:25:12: error: 'f' was not declared in this scope
   25 |            f[s2]=a[i];s2++;
      |            ^
a.cc:52:5: error: expected '}' before 'else'
   52 |     else
      |     ^~~~
a.cc:49:14: note: to match this '{'
   49 |     if(ans>0){
      |              ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define endl "\n"

const int M = (int) 1e9+7;
int n,k;
ll ans=1;
vector<ll> pos, neg;
int pcnt=0, ncnt=0;

ll solve(){
    cin>>n>>k;
    for (int i=0; i<n; ++i){
        ll foo; cin>>foo;
        if (foo>0) pos.push_back(foo);
        else if (foo<0) neg.push_back(abs(foo));
    }
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());
    int P=pos.size(), N=neg.size();
    if (k==n ? N%2==0 : P || k%2==0){
        reverse(pos.begin(), pos.end());
        reverse(neg.begin(), neg.end());
        for ( ; k; --k){
            if (pcnt<P && (ncnt>=N || pos[pcnt]>neg[nct])){
                ans=ans*pos[pcnt]%M; ++pcnt;
            }
            else{
                ans=ans*neg[ncnt]%M; ++ncnt;
            }
        }
        if (ncnt&1){
            ans=1;
            if (pcnt<P && ncnt>=1 && (ncnt>=N || pcnt==0 || pos[pcnt]*pos[pcnt-1]>neg[ncnt]*neg[ncnt-1])){
                for (int tt=0; tt<pcnt+1; ++tt)
                    ans=ans*pos[tt]%M;
                for (int tt=0; tt<ncnt-1; ++tt)
                    ans=ans*neg[tt]%M;
            }
            else{
                for (int tt=0; tt<pcnt-1; ++tt)
                    ans=ans*pos[tt]%M;
                for (int tt=0; tt<ncnt+1; ++tt)
                    ans=ans*neg[tt]%M;
            }
        }
        return ans;
    }
    for ( ; k; --k){
        if (pcnt<P && (ncnt>=N || pos[pcnt]<neg[ncnt])){
            ans=ans*pos[pcnt]%M; ++pcnt;
        }
        else{
            ans=ans*neg[ncnt]%M; ++ncnt;
        }
    }
    return M-ans;
}

int main(){
    // INT VS LL
    // freopen("input.txt", "r", stdin);
    //    INT VS LL
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout<<solve();
    return 0;
}

Compiler output:
a.cc: In function 'll solve()':
a.cc:27:53: error: 'nct' was not declared in this scope; did you mean 'ncnt'?
   27 |             if (pcnt<P && (ncnt>=N || pos[pcnt]>neg[nct])){
      |                                                     ^~~
      |                                                     ncnt
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

const int mn=2e5+6;
const LL mod=1e9+7;
int n,m;
LL a[mn],ans=1ll;

bool cmp1(LL a,LL b) {return a>b;}
bool cmp(LL a,LL b) {return abs(a)>abs(b);}

LL poww(LL a,LL b)
{
    LL ans=1;
    while(b) {
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i) 
        cin>>a[i];
    if(n==m) {
        for(int i=1;i<=m;++i) ans=ans*a[i]%mod;
        cout<<(mod+ans)%mod;
        return 0;
    }
    int f=0;
    for(int i=1;i<=n;++i) if(a[i]>=0) f=1;
    if(f==0&&m%2==1) {
        sort(a+1,a+n+1,cmp1);
        for(int i=1;i<=m;++i) ans=ans*a[i]%mod;
        cout<<(mod+ans)%mod;
        return 0;
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=m;++i) {
        ans=ans*a[i]%mod;
    }
    if(ans>=0) {cout<<ans%mod;return 0;}
    LL laspos=0,lasneg=0,nxtpos=0,nxtneg=0;
    for(int i=1;i<=m;++i) {
        if(a[i]>=0) laspos=a[i];if(a[i]<0) lasneg=a[i];
    }
    for(int i=n;i>m;--i) {
        if(a[i]>=0) nxtpos=a[i];if(a[i]<0) nxtneg=a[i];
    }
    LL ans1=0,ans2=0;
    if(laspos&&nxtneg) ans1=(ans*poww(laspos,mod-2)%mod)*nxtneg%mod;
    if(lasneg&&nxtlas) ans2=(ans*poww(lasneg,mod-2)%mod)*nxtpos%mod;
    cout<<max(ans1,ans2)%mod;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:56:16: error: 'nxtlas' was not declared in this scope; did you mean 'nxtpos'?
   56 |     if(lasneg&&nxtlas) ans2=(ans*poww(lasneg,mod-2)%mod)*nxtpos%mod;
      |                ^~~~~~
      |                nxtpos
Language: C++

import sys
input = sys.stdin.buffer.readline

def main():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    MOD = 10**9+7
    nega, posi = [], []
    for num in A:
        if num > 0:
            posi.append(num)
        elif num < 0:
            nega.append(num)
    
    if K > len(posi)+len(nega):
        print(0)
    elif K == len(nega)+len(posi):
        ans = 1
        for num in A:
            ans *= num
            ans = (ans+MOD)%MOD
        print(ans)
    elif len(posi) == 0:
        if K%2 != 0:
            if 0 in A:
                print(0)
            else:
                nega.sort(reverse = True)
                ans = 1
                for i in range(K):
                    ans *= nega[i]
                print((ans+MOD)%MOD)
        else:
            nega.sort()
            ans = 1
            for i in range(K):
                ans *= nega[i]
            print((ans+MOD)%MOD)
    else:
        nega.sort()
        posi.sort(reverse = True)
        if K <= len(posi):
            ans = 1
            for i in range(K):
                ans *= posi[i]
            print((ans+MOD)%MOD)
            exit()
        cn = [1]
        cp = [1]
        for num in nega:
            cn.append(cn[-1]*num)
        for num in posi:
            cp.append(cp[-1]*num)
        ans = 0
        l = len(cp)
        for i in range(l):
            if K-i > len(cn):
                continue
            ret = cp[i]*cn[K-i]
            ans = max(ans, ret)
        print((ans+MOD)%MOD)
    
if __name__ == "__main__":
    main()

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import sys
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
Language: C++

from sys import stdin, stdout
input, print = stdin.readline, stdout.write

MOD = int(1e9 + 7)

def divide(p, q):
    return (pow(q, MOD - 2, MOD) * (p % MOD)) % MOD

n, k = map(int, input().split())
a = list(map(int, input().split()))
b = []
negative = 0
for i in range(n):
    if a[i] > 0:
        b.append([a[i], 1])
    elif a[i] < 0:
        b.append([-a[i], -1])
        negative += 1
    else:
        b.append([0, 0])
b.sort(key = lambda x: x[0])
ans = 1
if negative == n and k % 2:
    for i in range(k):
        ans = (ans * -b[i][0]) % MOD
else:
    i = n - 1
    negative = 0
    last_negative = 0
    while i >= n - k:
        ans = (ans * b[i][0]) % MOD
        if b[i][1] == -1:
            negative += 1
            last_negative = b[i][0]
        i -= 1
    if negative % 2:
        ans = divide(ans, last_negative)
        while i != -1 or b[i][0] < 0:
            i -= 1
        ans = (ans * b[i][0]) % MOD
print(str(ans))

Compiler output:
a.cc:1:1: error: 'from' does not name a type
    1 | from sys import stdin, stdout
      | ^~~~
Language: C++

#include "stdafx.h"
#include "math.h"
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <functional>
#include <numeric>
#include <cmath>
using namespace std;

int n, k;
int long long modd = 1000000007;
int main()
{
	//freopen("input.txt", "r+", stdin);
	//freopen("output.txt", "w+", stdout);

	cin >> n >> k;
	vector<int long long> pos;
	vector<int long long> neg;
	int a;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		if (a > 0) {
			pos.push_back(a);
		}
		if (a < 0) {
			neg.push_back(-a);
		}
	}

	int long long mx = 1;
	if (size(pos) + size(neg) < k)
	{
		cout << 0;
	}
	else if (size(pos) == 0 && k % 2 == 1 && size(neg) < n) {
		cout << 0;
	}
	else if (size(pos) +size(neg) == k && size(neg)%2==1) {
		cout << 0;
	}
	else {
		if (size(pos) == 0)
		{
			sort(neg.begin(), neg.end());
			for (int i = 0; i < k; i++)
			{
				mx *= (modd - neg[i]);
				mx %= modd;
			}
			cout << mx;
		}
		else {
			sort(pos.begin(), pos.end(), greater<int>());
			sort(neg.begin(), neg.end(), greater<int>());
			int p, r;
			p = r = -1;
			int long long a, b;
			for (int i = 0; i < k; i++)
			{
				a = b = 0;
				if (p+1<size(pos))
				{
					a = pos[p+1];
				}
				if (r+1<size(neg))
				{
					b = neg[r+1];
				}
				if (a>b)
				{
					p++;
				}
				else {
					r++;
				}
			
			}
			if (k%2==1)
			{
				a = b = 1;
				if (r % 2 == 0) {
					if (p+1<size(pos) && r>0)
					{
						
						a = pos[p+1]*neg[r-1];
					}
					if (r+1<size(neg)&& p>0)
					{
						
						b = pos[p - 1] * neg[r+1];
					}
					if (a>b)
					{
						p++;
						r--;
					}
					else {
						p--;
						r++;
					}
				}
			}
			//cout << p << " " << r<<endl;
			while (p>=0)
			{
				mx *= pos[p];
				mx %= modd;
				p--;
			}
			while (r>=0)
			{
				mx *= neg[r];
				mx %= modd;
				r--;
			}
			cout << mx;
		}
	}
	cout << endl;


	return 0;
}


Compiler output:
a.cc:1:10: fatal error: stdafx.h: No such file or directory
    1 | #include "stdafx.h"
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include "math.h"
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <functional>
#include <numeric>
#include <cmath>
using namespace std;

int n, k;
int long long modd = 1000000007;

void go(vector<int long long> pos, vector<int long long> neg) {
	int long long mx = 1;
	int p, n;

	if (k % 2 == 1)
	{
		if (size(pos) == 0)
		{
			sort(neg.begin(), neg.end());
			for (int i = 0; i < floor(k/2); i++)
			{
				int long long temp = (neg[i]%modd) * (neg[i + 1]%modd);
				mx*=temp;
				mx %= modd;
			}
			mx *= -neg[k-1];
			while (mx < 0) {
				mx += modd;
			}
			cout << mx % modd;
			return;
		}
	}
	int long long a, b;
	sort(neg.begin(), neg.end());

	p = n = 0;
	if (k % 2 == 1)
	{
		p = 1;
		mx = pos[0] % modd;
	}


	for (int i = 0; i < floor(k / 2.0); i++)
	{
		a = b = 1;
		if (p + 1 < size(pos))
		{
			a = (pos[p]%modd)*([p + 1] % modd);
		}

		if (n + 1 < size(neg))
		{
			b = (neg[n] * neg[n + 1]) % modd;
		}
		if (a > b)
		{
			p += 2;
		}
		else {
			n += 2;
		}
		//cout << mx << " " << a << " " << b<<endl;
		(mx *= max(a, b)) %= modd;

	}

	std::cout << (mx) % modd << endl;
}

int main()
{
	//freopen("input.txt", "r+", stdin);
	//freopen("output.txt", "w+", stdout);

	cin >> n >> k;
	vector<int long long> pos;
	vector<int long long> neg;
	int a;

	for (int i = 0; i < n; i++)
	{
		cin >> a;
		if (a > 0) {
			pos.push_back(a);
		}
		if (a < 0) {
			neg.push_back(-a);
		}
	}

	if (size(pos) + size(neg) < k)
	{
		cout << 0;
	}
	else if (size(pos)==0 && (k%2==1)) {
		cout << 0;
	}
	else {

		sort(pos.begin(), pos.end(), greater<int>());
		go(pos, neg);
	}
	cout << endl;


	return 0;
}


Compiler output:
a.cc: In function 'void go(std::vector<long long int>, std::vector<long long int>)':
a.cc:55:46: error: expected ',' before '+' token
   55 |                         a = (pos[p]%modd)*([p + 1] % modd);
      |                                              ^~
      |                                              ,
a.cc:55:47: error: expected identifier before '+' token
   55 |                         a = (pos[p]%modd)*([p + 1] % modd);
      |                                               ^
a.cc: In lambda function:
a.cc:55:52: error: expected '{' before '%' token
   55 |                         a = (pos[p]%modd)*([p + 1] % modd);
      |                                                    ^
a.cc: In function 'void go(std::vector<long long int>, std::vector<long long int>)':
a.cc:55:52: error: no match for 'operator%' (operand types are 'go(std::vector<long long int>, std::vector<long long int>)::<lambda()>' and 'long long int')
   55 |                         a = (pos[p]%modd)*([p + 1] % modd);
      |                                            ~~~~~~~ ^ ~~~~
      |                                            |         |
      |                                            |         long long int
      |                                            go(std::vector<long long int>, std::vector<long long int>)::<lambda()>
Language: C++

#include "stdafx.h"
#include "math.h"
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <functional>
#include <numeric>
#include <cmath>
using namespace std;

int n,k;
int long long modd= 1000000007;

void go(vector<int long long> pos, vector<int long long> neg) {
	int long long mx = 1;
	int start = 0;
	int p, n;
	p = n = 0;
	if (k % 2 == 1)
	{
		if (size(pos) == 0)
		{
			for (int i = 0; i < k; i++)
			{
				mx = (mx*neg[(size(neg) - 1) - i])%modd;
			}
			while (mx < 0) {
				mx += modd;
			}
			cout << mx%modd;
			return;
		}
		else {
			mx = pos[0];
			start = 1;
			p = 1;
		}
	}
	int a, b;
	for (int i = start; i < k; i+=2)
	{
		a = b = 1;
		if (p+1<size(pos))
		{
			a = (pos[p] * pos[p + 1])%modd;
			p += 2;
		}
		if (n + 1<size(neg))
		{
			b = (neg[n] * neg[n + 1])%modd;
			n += 2;
		}
		//cout << mx << " " << a << " " << b<<endl;
		mx = (mx*max(a, b))%modd;
		
	}
	while (mx < 0) {
		mx += modd;
	}
	std::cout << (mx+modd) % modd<<endl;
}

int main()
{
	cin >> n>>k;
	vector<int long long> pos;
	vector<int long long> neg;
	int a;
	
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		if (a > 0) {
			pos.push_back(a);
		}
		if (a < 0) {
			neg.push_back(a);
		}
	}
	sort(pos.begin(), pos.end(), greater<int long long>());
	sort(neg.begin(), neg.end(), less<int long long>());
	
	go(pos,neg);

	return 0;
}



Compiler output:
a.cc:1:10: fatal error: stdafx.h: No such file or directory
    1 | #include "stdafx.h"
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, (b)<(e)?1:-1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define FOR(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)(__VA_ARGS__)
#ifdef LOCAL
#define dbg(x) cerr << '[' << #x << ":" << (x) << "]\n"
#else
#define dbg(x)
#endif
const int MOD=1e9+7;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,k;cin>>n>>k;
	int npos=0,nneg=0;
	vector<int> pos,neg;
	FOR(n){
		int a;cin>>a;
		if(a<0)neg.pb(a),nneg++;
		else pos.pb(a),npos++;
	}
	sort(rall(pos));
	sort(all(neg));
	auto mul=[&](vector<int>& v,int x){
		ll ans=1;
		FOR(x)(ans*=v[i])%=MOD;
		if(ans<0)ans+=MOD;
		return ans;
	};
	if(npos==0){
		reverse(all(neg));
		cout<<mul(neg,k);
		return 0;
	}
	int i=0,j=0;
	vector<int> chp,chn;
	FOR(z,k){
		if(j==nneg||(i<npos&&pos[i]>-neg[j]))chp.pb(pos[i]),i++;
		else chn.pb(neg[j]),j++;
	}
	if(j&1^1){
		dbg(i),dbg(j);
		cout<<mul(chp,chp.size())*mul(chn,chn.size())%MOD;
		return 0;
	}
	if(i<npos&&(j==nneg||chp.back()*pos[i]>chn.back()*neg[j])){
		chp.pb(pos[i]);
		chn.pop_back();
		cout<<mul(chp,chp.size())*mul(chn,chn.size())%MOD;
	}else if(j<nneg&&(i==npos||chp.back()*pos[i]<=chn.back()*neg[j])){
		chn.pb(neg[j]);
		chp.pop_back();
		cout<<mul(chp,chp.size())*mul(chn,chn.size())%MOD;
	}else{
		cout<<mul(chp,chp.size())*mul(chn,chn.size())%MOD;
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:51:23: error: expected primary-expression before ',' token
   51 |                 dbg(i),dbg(j);
      |                       ^
a.cc:51:30: error: expected primary-expression before ';' token
   51 |                 dbg(i),dbg(j);
      |                              ^
Language: C++

#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cerr<<' ';cout<<elem;}cerr<<endl;}

int main(){
	int n,k;
	cin>>n>>k;
	
	vi m,p;
	REP(i,n){
		int a;
		cin>>a;
		if(a<0) m.push_back(a);
		else p.push_back(a);
	}
	
	if(k==n){//全部選ぶ場合.
		llong ans=1;
		REP(i,m.size()) ans=ans*(MOD+m[i])%MOD;
		REP(i,p.size()) ans=ans*p[i]%MOD;
		cout<<ans<<endl;
		return 0;
	}
	
	if(m.size()==n and k%2==1){//全部負の数かつ奇数個選ぶ場合.
		llong ans=1;
		sort(ALL(m),greater<int>());//絶対値が小さくなるように.
		REP(i,k) ans=ans*(MOD+m[i])%MOD;
		cout<<ans<<endl;
		return 0;
	}
	
	auto comp=[](int x,int y){
		return abs(x)>abs(y);
	};
	sort(ALL(m),comp);
	sort(ALL(p),comp);
	
	llong ans=1;
	int mp=0, pp=0;
	while(k>0){
		if(k==1 or m.size()-mp<2 or(p.size()pp>=2 and m[mp]*m[mp+1]<p[pp]*p[pp+1])){
			ans=ans*p[pp++]%MOD;
			k--;
		}else{
			REP(i,2) ans=ans*(MOD+m[mp++])%MOD;
			k-=2;
		}
	}
	
	cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:53:53: error: expected ')' before 'pp'
   53 |                 if(k==1 or m.size()-mp<2 or(p.size()pp>=2 and m[mp]*m[mp+1]<p[pp]*p[pp+1])){
      |                                            ~        ^~
      |                                                     )
a.cc:56:18: error: expected ')' before 'else'
   56 |                 }else{
      |                  ^~~~
      |                  )
a.cc:53:19: note: to match this '('
   53 |                 if(k==1 or m.size()-mp<2 or(p.size()pp>=2 and m[mp]*m[mp+1]<p[pp]*p[pp+1])){
      |                   ^
a.cc:60:9: error: expected primary-expression before '}' token
   60 |         }
      |         ^
Language: C++

#include<bits/stdc++.h>
using namespace std;

#define mod 1000000007
using ll = long long;

int main(){

  int n,k;
  cin >> n >> k;

  if(n==k){
    ll ans=1;
    ll num;
    for(int i=0;i<n;i++){
      cin >> num;
      ans=ans*num%mod;
    }
    cout << (ans+mod)%mod;
    return 0;
  }

  priority_queue<ll> pos;
  priority_queue<ll> neg;
  ll num;
  for(int i=0;i<n;i++){
    cin >> num;
    if(num>=0){
      pos.push(num);
    }else{
      neg.push(-num);
    }
  }

  if(k%2==1 && pos.size()==0){
    ll ans=1;
    ll num;
    for(int i=0;i<n;i++){
      num=-neg.top();
      neg.pop();
      if(i>=n-k){
        num=num%mod;
        ans=ans*num%mod;
      }
    }
    cout << (ans+mod)%mod << endl;
    return 0;
  }

  ll posnum=1;
  ll negnum=1;
  bool posErase=1;
  bool negErase=1;
  ll ans=1;
  int i=0;
  if(k%2==1){
    ans=pos.top();
    pos.pop();
    i++;
  }
  while(1){
    if(i==k){
      cout << (ans+mod)%mod << endl;
      return 0;
    }
    if(pos.size()>=2 && posErase==1){
      posnum=pos.top();
      pos.pop();
      posnum=posnum*pos.top();
      pos.pop();
      posErase=0;
    }

    if(neg.size()>=2 && negErase==1){
      negnum=neg.top();
      neg.pop();
      negnum=negnum*neg.top();
      neg.pop();
      negErase=0;
    }

    if(posnum>=negnum){
      posErase=1;
      posnum=0;
      posnum=posnum%mod;
      ans=ans%mod*posnum%mod;
    }else{
      negErase=1;
      negnum=0;
      negnum=negnum%mod;
      ans=ans%mod*negnum%mod;
    }
    i+=2;
  }

Compiler output:
a.cc: In function 'int main()':
a.cc:94:4: error: expected '}' at end of input
   94 |   }
      |    ^
a.cc:7:11: note: to match this '{'
    7 | int main(){
      |           ^
Language: C++

#include<bits/stdc++.h>
using namespace std;

#define mod 1000000007
using ll = long long;

int main(){

  int n,k;
  cin >> n >> k;

  //n==kの場合
  if(n==k){
    ll num;
    ll ans=1;
    for(int i=0;i<n;i++){
      cin >> num;
      num=num%mod;
      ans=ans*num%mod;
      ans=ans%mod;
    }
    cout << (ans+mod)%mod;
    return 0;
  }

  priority_queue<ll> pos;
  priority_queue<ll> neg;
  ll num;
  for(int i=0;i<n;i++){
    cin >> num;
    if(num>=0){
      pos.push(num);
    }else{
      neg.push(-num);
    }
  }

  if(k%2==1 && pos.size()==0){
    ll ng;
    ll ans=1;
    for(int i=0;i<n;i++){
      ng=-neg.top();
      neg.pop();
      if(i>=n-k){
        ng=ne%mod;
        ans=ans*ng%mod;
        ans=ans%mod;
      }
    }
    cout << (ans+mod)%mod << endl;
    return 0;
  }

  ll posnum=1;
  ll negnum=1;
  bool posErase=1;
  bool negErase=1;
  ll ans=1;
  int i=0;
  if(k%2==1){
    posnum=pos.top();
    pos.pop();
    ans*=posnum;
    i++;
  }
  while(1){
    if(i==k){
      cout << (ans+mod)%mod << endl;
      return 0;
    }
    if(pos.size()>=2 && posErase==1){
      posnum=pos.top();
      pos.pop();
      posnum*=pos.top();
      pos.pop();
      posErase=0;
    }

    if(neg.size()>=2 && negErase==1){
      negnum=neg.top();
      neg.pop();
      negnum*=neg.top();
      neg.pop();
      negErase=0;
    }

    if(posnum>=negnum){
      posErase=1;
      posnum=posnum%mod;
      ans=ans*posnum%mod;
      ans=ans%mod;
    }else{
      negErase=1;
      negnum=negnum%mod;
      ans=ans*negnum%mod;
      ans=ans%mod;
    }
    i+=2;
  }

}

Compiler output:
a.cc: In function 'int main()':
a.cc:45:12: error: 'ne' was not declared in this scope; did you mean 'ng'?
   45 |         ng=ne%mod;
      |            ^~
      |            ng
Language: C++

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;
LLi mod=1000000007;

LLi modabs(LLi x){
	if(x>=0) return (x%mod);

	LLi tmp=abs(x);
	LLi di=(tmp+mod-1)/mod;
	return mod*di+x;
}
 
LLi modinv(LLi a) {
    LLi b = mod, u = 1, v = 0;
    while (b) {
        LLi t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}

int main(){

	int n, k, zer=0, pp=0, mp=0, sig=1;
	vector<LLi> pv, mv;
	LLi tmp, ans=1;

	cin>> n >> k;

	rep(i, n){
		cin >> tmp;
		if(0<tmp) pv.push_back(tmp);
		if(0>tmp) mv.push_back(tmp);
		if(tmp==0) zer++;
	}
	
	sort(pv.begin(), pv.end(), greater<LLi>());
	sort(mv.begin(), mv.end());

	if(k%2==1 && n==(int)mv.size()){
		rep(i, k){
			ans*=modabs(mv[mv.size()-1-i]);
			ans=ans%mod;
		}
		cout<< ans <<endl;
		return 0;
	}

	rep(i, k){
		if((int)pv.size()==pp && (int)mv.size()==mp){
			cout<< 0 <<endl;
			return 0;
		}else if((int)pv.size()==pp){
			ans*=modabs(mv[mp]);
			ans=ans%mod;
			sig*=-1;
			mp++;
		}else if((int)mv.size()==mp){
			ans*=pv[pp];
			ans=ans%mod;
			pp++;
		}else{
			if(-mv[mp]<=pv[pp]){
				ans*=pv[pp];
				ans=ans%mod;
				pp++;
			}else{
				ans*=modabs(mv[mp]);
				ans=ans%mod;
				sig*=-1;
				mp++;
			}
		}
	}
	//cout<< "mp=" << mp <<endl;//
	//cout<< "pp=" << pp <<endl;//

	LLi p1, p2;
	if(sig!=1){
		if(pp!=(int)pv.size() && mp!=0) p1=pv[pp]*pv[pp-1];
		if(mp!=(int)mv.size() && pp!=0) p2=mv[mp]*mv[mp-1];
		//cout<< p1 <<endl;
		/cout<< p2 <<endl;

		if(p1>p2){
			ans*=pv[pp];
			ans=ans%mod;
			ans*=modinv(modabs(mv[mp-1]));
			ans=ans%mod;
		}else{
			ans*=modabs(mv[mp]);
			ans=ans%mod;
			ans*=modinv(pv[pp-1]);
			ans=ans%mod;
		}
	}

	cout<< ans <<endl;
 
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:95:17: error: expected primary-expression before '/' token
   95 |                 /cout<< p2 <<endl;
      |                 ^
Language: C++

#include <bits/stdc++.h>
#define int long long
#define double long double
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,sse")
using namespace std;

bool comp(int a, int b) {
    return abs(a) >= abs(b);
}

const int MOD = 1e9 + 7;
const double EPS = 1e-9;

bool can(int a, int b, int k) {
    if (b % 2) {
        b--;
    }
    if (k % 2) {
        return a + b >= k && a > 0;
    } else {
        return a + b >= k;
    }
}

int n, k;
vector<int> arr;
vector<double> pa;
vector<double> pb;
vector<int> ra;
vector<int> rb;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> k;
    arr.resize(n);
    int a = 0;
    int b = 0;
    int z = 0;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        if (arr[i] > 0) {
            a++;
        } else if (arr[i] < 0) {
            b++;
        } else {
            z++;
        }
    }
    sort(arr.begin(), arr.end(), comp);
    if (can(a, b, k)) {
        pa.push_back(0);
        pb.push_back(0);
        ra.push_back(1);
        rb.push_back(1);
        for (int x : arr) {
            if (x > 0) {
                pa.push_back(pa.back() + log(x);
                ra.push_back((ra.back() * x) % MOD);
            } else if (x < 0) {
                pb.push_back(pb.back() + log(-x));
                rb.push_back((rb.back() * -x) % MOD);
            }
        }
        double fin = -1;
        int ans = INT_MIN;
        for (int i = 0; i <= k; i += 2) {
            if (i < pb.size() && k - i < pa.size()) {
                if (pb[i] + pa[k - i] > fin) {
                    fin = pb[i] + pa[k - i];
                    ans = (rb[i] * ra[k - i]) % MOD;
                }
            }
        }
        cout << ans << '\n';
    } else if (z > 0) {
        cout << 0 << '\n';
    } else {
        int res = 1;
        for (int i = n - 1; i >= n - k; i--) {
            res = (((res * arr[i]) % MOD) + MOD) % MOD;
        }
        cout << res << '\n';
    }

    fflush(stdout);
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:61:48: error: expected ')' before ';' token
   61 |                 pa.push_back(pa.back() + log(x);
      |                             ~                  ^
      |                                                )
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll 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, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n, k; cin >> n >> k; 
   vector<ll> A(n), B, C;

   rep(i,n){
      cin >> A[i];
      if(A[i]<0)C.push_back(A[i]);
      else B.push_back(A[i]);
   }
   mint ans = 1;
   sort(B.begin(), B.end());
   reverse(B.begin(), B.end());
   sort(C.begin(), C.end());
   if(k==n){
      rep(i,k)ans*=mint(A[i]);
      cout << ans << endl;
   }
   else if(B.size()==0 && k%2==1){
      rep(i,k)ans *= mint(C[n-i-1]);
   }
   int cnt=0;
   int bi=0,ci=0;
   else{
      while(cnt < k){
         if(bi >= B.size()-1){
            if((k-cnt)%2==1){
               ans*=mint(B[bi]);
               cnt++;
            }
            rep(i,k-cnt){
               ans *= mint(C[ci+i]);
            }
            cnt = k;
         }
         else if((ci >= C.size()-1)||(cnt==k-1)
            ||(B[bi]*B[bi+1]>C[ci]*C[ci+1])){
            ans *= mint(B[bi]);
            cnt++;
            bi++;
         }
         else{
            ans *= mint(C[ci]*C[ci+1]);
            cnt+=2;
            ci+=2;
      }
   }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:61:4: error: 'else' without a previous 'if'
   61 |    else{
      |    ^~~~
a.cc:85:2: error: expected '}' at end of input
   85 | }
      |  ^
a.cc:37:12: note: to match this '{'
   37 | int main() {
      |            ^
Language: C++

#include<bits/stdc++.h>
using namespace std;

#define mod 1000000007
using ll = long long;

int main(){

  int n,k;
  cin >> n >> k;

  //n==kの場合
  if(n==k){
    ll num;
    ll ans=1;
    for(int i=0;i<n;i++){
      cin >> num;
      ans=(ans*(num%mod))%mod;
    }
    cout << (ans+mod)%mod << endl;
    return 0;
  }

  priority_queue<ll> pos;
  priority_queue<ll> neg;
  ll num;
  for(int i=0;i<n;i++){
    cin >> num;
    if(num>0){
      pos.push(num);
    }else{
      neg.push(-num);
    }
  }

  if(k%2==1 && pos.size()==0){
    ll ng;
    ll ans=1;
    for(int i=0;i<n;i++){
      ng=-neg.top();
      neg.pop();
      if(i>=n-k){
        ans=ans*ng%mod;
      }
    }
    cout << (ans+mod)%mod << endl;
    return 0;
  }

  ll posnum;
  ll negnum;
  ll ans=1;
  bool posErase=1;
  bool negErase=1;
  int i=0;
  while(1){
    //cout << "i:" << i << endl;
    //cout << "ans:" << ans << endl;
    if(i==k){
      cout << (ans+mod)%mod << endl;
      return  0;
    }
    if(k%2==1 && i=0){
      posnum=pos.top();
      pos.pop();
      ans*=posnum%mod;
      i++;
    }

    if(posErase==1){
      if(pos.size()<2){
        posnum=-1;
        posErase=0;
        continue;
      }
      posnum=pos.top();
      pos.pop();
      posnum*=pos.top();
      pos.pop();
      posErase=0;
    }

    if(negErase==1){
      if(neg.size()<2){
        negnum=-1;
        negErase=0;
        continue;
      }
      negnum=neg.top();
      neg.pop();
      negnum*=neg.top();
      neg.pop();
      negErase=0;
    }

    if(posnum>=negnum){
      //cout << "posをとる:" << posnum << endl;
      posnum=posnum%mod;
      ans*=posnum%mod;
      posErase=1;
      i+=2;
    }else{
      //cout << "negをとる:" << negnum << endl;
      negnum=negnum%mod;
      ans*=negnum%mod;
      negErase=1;
      i+=2;
    }
  }

}

Compiler output:
a.cc: In function 'int main()':
a.cc:63:15: error: lvalue required as left operand of assignment
   63 |     if(k%2==1 && i=0){
      |        ~~~~~~~^~~~
Language: Java

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    long MOD = (long)Math.pow(10, 9) + 7;
    ArrayList<Long> list1 = new ArrayList<Long>();
    ArrayList<Long> list2 = new ArrayList<Long>();
    for(int i = 0; i < n; i++) {
      long a = sc.nextLong();
      if(a >= 0) {
        list1.add(a);
      } else {
        list2.add(a);
      }
    }
    Collections.sort(list1);
    Collections.sort(list2);
    long ans = 1;
    int p1 = list1.size() - 1;
    int p2 = 0;
    if(list1.size() == 0) {
      if((k % 2) == 1) {
        for(int i = list2.size() - 1; i >= list2.size() - k; i--) {
          long d = list2.get(i);
          d += MOD;
          ans = (ans * d) % MOD;
        }
      } else {
        for(int i = 0; i < k; i++) {
          long d = list2.get(i);
          d += MOD;
          ans = (ans * d) % MOD;
        }
      }
    } else if(list2.size() == 0) {
      for(int i = list1.size() - 1; i >= list1.size() - k; i--) {
        ans = (ans * list1.get(i)) % MOD;
      }
    } else {
    for(int i = 0; i < k; i++) {
      if(p2 < list2.size() - 1) {
        long s1 = list1.get(p1);
        if(p1 > 0) s1 *= list1.get(p1 - 1);
        long t1 = 1;
        //long t1 = list2.get(p2);
        long t2 = 1;
        //if(p2 < list2.size() - 1) t2 = list2.get(p2 + 1);
        long s2 = t1 * t2;
        /**
        if((p1 >= 0) && ((s1 >= s2) || (i == (k - 1)))) {
          ans = (ans * list1.get(p1)) % MOD;
          p1--;
        } else {
          s2 = (s2 % MOD);
          ans = (ans * s2) % MOD;
          i++;
          p2 = p2 + 1;
        } */
      } else {
        if(p1 >= 0) {
          long d = list1.get(p1);
          ans = (ans * d) % MOD;
          p1--; 
        } else {
          long d = 1;
          long d = list2.get(p2);
          d += MOD;
          ans = (ans * d) % MOD;
          p2++; 
        }
      }
    } 
    }
    System.out.println(ans);
  }
}

Compiler output:
Main.java:69: error: variable d is already defined in method main(String[])
          long d = list2.get(p2);
               ^
1 error
Language: C++

#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
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;
}

int main() {
    ll n, k, ans = 1;
    cin >> n >> k;
    vector<ll> a(n);
    vector<pair<ll, ll>> b(n);
    rep(i, n){
        cin >> a[i];
        if(a[i] < 0)b[i] = {abs(a[i]), -1};
        if(a[i] > 0)b[i] = {abs(a[i]), 1};
        if(a[i] == 0)b[i] = {abs(a[i]), 0};
    }
    sort(rall(b));
    rep(i, k)ans = ans * b[i].second;
    if(ans == 1){
        rep(i, k)ans = ans * b[i].first % mod;
        cout << ans << endl;
    }else if(ans == 0){
        cout << 0 << endl;
    }else{
        bool ok = true;
        rep(i, n)if(b[i].second != -1)ok = false;
        if(ok && k % 2 == 1){
            sort(all(b));
            rep(i, k)ans = ans * b[i].first % mod;
            cout << (ans+mod) % mod << endl;
        }else{
            ans = mod-1;
            rep(i, k)ans = ans * b[i].first % mod;

            
            }
        }
    }
}


Compiler output:
a.cc:62:1: error: expected declaration before '}' token
   62 | }
      | ^
Language: C++

#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> ap;
    vector<ll> am;
    rep(i, n) {
        ll tmp_a;
        cin >> tmp_a;
        if (tmp_a < 0) {
            am.push_back(abs(tmp_a));
        }
        else {
            ap.push_back(tmp_a);
        }
    }
    int ap_size = ap.size();
    int am_size = am.size();
    bool possible_plus = false;
    if (ap_size == 0) {
        if (!(k&1)) possible_plus = true;
    }
    else {
        if (n == k) possible_plus = !(am_size&1)
        else        possible_plus = true;
    }
    sort(ap.begin(), ap.end());
    sort(am.begin(), am.end());
    if (possible_plus) {
        reverse(ap.begin(), ap.end());
        reverse(am.begin(), am.end());
    }
    ll ans = 1;
    if (!possible_plus) {
        int idx_p = 0;
        int idx_m = 0;
        while(1) {
            if (idx_p + idx_m == k) break;
            if (idx_p == ap_size) {
                ans = (ans * am[idx_m]) % mod;
                ++idx_m;
            }
            else if (idx_m == am_size) {
                ans = (ans * ap[idx_p]) % mod;
                ++idx_p;
            }
            else if (ap[idx_p] < am[idx_m]) {
                ans = (ans * ap[idx_p]) % mod;
                ++idx_p;
            }
            else {
                ans = (ans * am[idx_m]) % mod;
                ++idx_m;
            }
        }
        //cout << ans << endl;
        cout << mod - ans << endl;
        return 0;
    }
    else {
        int idx_p = 0;
        int idx_m = 0;
        if (k&1) {
            ans = (ans * ap[0]) % mod;
            idx_p = 1;
            --k;
        }
        vector<ll> a_two_pair;
        while(1) {
            if (idx_p + 1 >= ap_size) break;
            a_two_pair.push_back(ap[idx_p] * ap[idx_p+1] % mod);
            idx_p += 2;
        }
        
        while(1) {
            if (idx_m + 1 >= am_size || am.empty()) break;
            a_two_pair.push_back(am[idx_m] * am[idx_m+1] % mod);
            idx_m += 2;
        }
        sort(a_two_pair.rbegin(), a_two_pair.rend());
        //for (auto t: a_two_pair) {
        //    cout << t << "  ";
        //}
        //cout << endl;
        //cout << ans << endl;
        rep(i, k/2) {
            ans = (ans * a_two_pair[i] ) % mod;
            //cout << ans << endl;
        }
        cout << ans << endl;
        return 0;
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:42:49: error: expected ';' before 'else'
   42 |         if (n == k) possible_plus = !(am_size&1)
      |                                                 ^
      |                                                 ;
   43 |         else        possible_plus = true;
      |         ~~~~
Language: Java


import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    long MOD = (long)Math.pow(10, 9) + 7;
    ArrayList<Long> list1 = new ArrayList<Long>();
    ArrayList<Long> list2 = new ArrayList<Long>();
    for(int i = 0; i < n; i++) {
      long a = sc.nextLong();
      if(a >= 0) {
        list1.add(a);
      } else {
        list2.add(a);
      }
    }
    Collections.sort(list1);
    Collections.sort(list2);
    long ans = 1;
    int p1 = list1.size() - 1;
    int p2 = 0;
    if(list1.size() == 0) {
      if((k % 2) == 1) {
        for(int i = list2.size() - 1; i >= list2.size() - k; i--) {
          long d = list2.get(i);
          d += MOD;
          ans = (ans * d) % MOD;
        }
      } else {
        for(int i = 0; i < k; i++) {
          long d = list2.get(i);
          d += MOD;
          ans = (ans * d) % MOD;
        }
      }
    } else if(list2.size() == 0) {
      for(int i = list1.size() - 1; i >= list1.size() - k; i--) {
        ans = (ans * list1.get(i)) % MOD;
      }
    } else {
    for(int i = 0; i < k; i++) {
      if(p2 < list2.size() - 1) {
        long s1 = 1;
        // long s1 = list1.get(p1);
        if(p1 > 0) s1 *= list1.get(p1 - 1);
        long t1 = 1;
        // long t1 = list2.get(p2);
        long t2 = 1;
        // if(p2 < list2.size() - 1) t2 = list2.get(p2 + 1);
        long s2 = t1 * t2;
        /**
        if((s1 >= s2) || (i == (k - 1))) {
          ans = (ans * list1.get(p1)) % MOD;
          p1--;
        } else {
          s2 = (s2 % MOD);
          ans = (ans * s2) % MOD;
          i++;
          // p2 = p2 + 2;
        } */
      } else {
        if(p1 >= 0) {
          long d = list1.get(p1);
          ans = (ans * d) % MOD;
          p1--; 
        } else {
          long d = 1;
          long d = list2.get(p2);
          d += MOD;
          ans = (ans * d) % MOD;
          p2++; 
        }
      }
    } 
    }
    System.out.println(ans);
  }
}

Compiler output:
Main.java:71: error: variable d is already defined in method main(String[])
          long d = list2.get(p2);
               ^
1 error
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef long long ull;
typedef long double ld;
#define in_arr(name,size) for(int i = 0;i<size;i++)\
cin >> name[i];
#define QUICK ios_base::sync_with_stdio(0);cout << fixed;
#define MOD 1000000007

string upper(string);
string lower(string);
bool isalup(string);
bool isallow(string);


int main(){
    QUICK

    int a,b;
    cin >> a >> b;
    vector<ll>wow(a);
    for(int i = 0;i<a;i++)cin >> wow[i];

    sort(wow.begin(),wow.end());
    ll ans;
    int sign = 1;
    int r = a-1,s = 0;
    if(k%2){
        ans = wow[r--];
        --k;
        if(ans<0)sign = -1;
    }

    while(k){
        ll x = wow[l]*wow[l+1],y = wow[r]*wow[r-1];
        if(x*sign>y*sign){
            ans = (ans%MOD)*(x%MOD);
            l +=2;
            ans %= MOD;
        }else{
            ans = (ans%MOD)*(y%MOD);
            ans %= MOD;
            r -= 2;
        }
        
        
        k -= 2;
    }
    cout << ans;
    return 0;
}















string upper(string a){
    for(char& c:a){
        if(islower(c))
            c -= 32;
       }
    return a;
}
    string lower(string a){
        for(char& c : a){
            if(isupper(c))
                c += 32;
        }
        return a;
    }
    bool isalup(string a){
        for(char& c: a){
            if(islower(c))
                return false;
        }
        return true;
    }
    bool isallow(string a){
        for(char& c:a){
            if(isupper(c))
                return false;
        }
       return true;
    }


Compiler output:
a.cc: In function 'int main()':
a.cc:29:8: error: 'k' was not declared in this scope
   29 |     if(k%2){
      |        ^
a.cc:35:11: error: 'k' was not declared in this scope
   35 |     while(k){
      |           ^
a.cc:36:20: error: 'l' was not declared in this scope
   36 |         ll x = wow[l]*wow[l+1],y = wow[r]*wow[r-1];
      |                    ^
a.cc:37:19: error: 'y' was not declared in this scope
   37 |         if(x*sign>y*sign){
      |                   ^