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

#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rrepa(i,a,n) for(int i=n-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

int main(){

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

    vi am,ap;
    rep(i,n){
        int num;
        cin>>num;
        if(num<0)am.push_back(-num);
        else ap.push_back(num);
    }

    sort(all(ap));
    sort(all(am));

    ll ans=1;

    if(n==k){
        int l=ap.size();
        rep(i,l)ans=(ans*ap[i])%MOD;
        l=am.size();
        rep(i,l)ans=(ans*am[i])%MOD;
        if(l%2)ans=(-ans+MOD)%MOD;

        cout<<ans<<"\n";
        return 0;
    }

    if((0==ap.size()) && k%2){
        rep(i,k)ans=(ans*am[i])%MOD;
        ans=(-ans+MOD)%MOD;

        cout<<ans<<"\n";
        return 0;
    }

    int ip=ap.size()-1,im=am.size()-1;

    rep(i,k){
        if((k-1-i)%2==0 || im<1){
            cerr<<"a\n";
            ans=(ans*ap[ip])%MOD;
            ip--;
        }else if(ip<1){
            cerr<<"b\n";
            ans=(ans*am[im])%MOD;
            ans=(ans*am[im-1])%MOD;
            im-=2;
            i++;
        }else{
            if(((ll)ap[ip])*ap[ip-1] > ((ll)am[im])*am[im-1]){
                cerr<<"c\n";
                ans=(ans*ap[ip])%MOD;
                ans=(ans*ap[ip-1])%MOD;
                ip-=2;
                i++
            }else{
                cerr<<"d\n";
                ans=(ans*am[im])%MOD;
                ans=(ans*am[im-1])%MOD;
                im-=2;
                i++;
            }
        }
        cerr<<"i="<<i<<",ans="<<ans<<"\n";
    }

    cout<<ans<<"\n";

    return 0;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:81:20: error: expected ';' before '}' token
   81 |                 i++
      |                    ^
      |                    ;
   82 |             }else{
      |             ~
Language: C++

#include <bits/stdc++.h>

using namespace std;
ll A[300001];
typedef long long ll;
const ll mod=1e9+7;
int main() {
    ll n,k;
	cin>>n>>k;
	
	for(int i=0;i<n;i++) cin>>A[i];
	sort(A,A+n);
	ll ans=1,sign=1;
	int l=0,r=n-1;
	if(k%2){
        ans=A[r--];
        --k;
        if(ans<0) sign=-1;
	}
	while(k){
        ll x=A[l]*A[l+1],y=A[r]*A[r-1];
        if(x*sign>y*sign){
            ans=x%mod*ans%mod;
            l+=2;
        }else{
            ans=y%mod*ans%mod;
            r-=2;
        }
        k-=2;
	}
	cout<<(ans+mod)%mod<<endl;
	return 0;
}


Compiler output:
a.cc:4:1: error: 'll' does not name a type
    4 | ll A[300001];
      | ^~
a.cc: In function 'int main()':
a.cc:11:35: error: 'A' was not declared in this scope
   11 |         for(int i=0;i<n;i++) cin>>A[i];
      |                                   ^
a.cc:12:14: error: 'A' was not declared in this scope
   12 |         sort(A,A+n);
      |              ^
a.cc:22:19: error: 'y' was not declared in this scope
   22 |         if(x*sign>y*sign){
      |                   ^
Language: Java


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class e_alt {
    public static long MOD = 1000000007;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] s = br.readLine().split(" ");

        int n = Integer.parseInt(s[0]);
        int k = Integer.parseInt(s[1]);

        String[] s2 = br.readLine().split(" ");
        Integer[] nums = new Integer[n];
        List<Long> positives = new ArrayList<>();
        List<Long> negatives = new ArrayList<>();

        int zeroCount = 0;

        for (int i = 0; i < n; i++) {
            nums[i] = Math.abs(Integer.parseInt(s2[i]));
            int temp = Integer.parseInt(s2[i]);
            if (temp<0)negatives.add((long) Math.abs(temp));
            else if (temp==0){
                ++zeroCount;
            }
            else  positives.add((long) temp);
        }

        boolean isPositive = positives.size() + ((int)(negatives.size()/2))*2 >= k && (k%2 == 0 || positives.size() > 0);


        if (isPositive){
            //positive sing = > select negatives or positives in groups of two (by whichever pair has higher product) and mul 1 more pos at the end if k nos not taken

            positives.sort(Collections.reverseOrder());
            negatives.sort(Collections.reverseOrder());

            int negIdx = 0;
            int posIdx = 0;
            int total = k;
            long ans  = 1L;
            if(k%2==1){
                ans = positives.get(posIdx);
                ++posIdx;
                --total;
            }
            while (total>0){

                long negProd = negatives.size()-negIdx>=2 ? (negatives.get(negIdx)*negatives.get(negIdx+1)) : 0;
                long posProd = positives.size()-posIdx>=2 ? (positives.get(posIdx)*positives.get(posIdx+1)) : 0;


                ans = (ans * (Math.max(negProd,posProd)%MOD))%MOD;
                if(negProd>posProd)
                    negIdx += 2;
                else
                    posIdx += 2;
                total -= 2;
            }
            System.out.println(ans);
        }else{
            // sign will be negative, hence choose smallest k numbers(by abs value).
            if(zeroCount>0){
                System.out.println(0);
                return;
            }
            Arrays.sort(nums);
            long ans = 1L;
            for(int i = 0 ; i<k; i++){
                ans = (ans*nums[i])%MOD;
            }
            System.out.println((MOD-ans)%MOD);
        }

    }
}


Compiler output:
Main.java:10: error: class e_alt is public, should be declared in a file named e_alt.java
public class e_alt {
       ^
1 error
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll m=1e9+7;
ll mod(ll n){
    return (n%m+m)%m;
}
ll mul(ll a, ll b){
    return mod(mod(a)*mod(b));
}
int main() {
    int n,k;
    cin>>n>>k;
    vector<ll> pos,neg;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        if(x>=0){
            pos.push_back(x);
        }
        else{
            neg.push_back(x);
        }
    }
    if(pos.size()==0){
        sort(neg.begin(),neg.end());
        if(k&1){
            reverse(neg.begin(),neg.end());
        }
        ll p=1;
        for(int i=0;i<k;i++){
            p=mul(p,neg[i]);
        }
        cout<<p<<endl;
    }
    else if(neg.size()==0){
        sort(pos.begin(),pos.end(),greater<ll>());
        ll p=1;
        for(int i=0;i<k;i++){
            p=mul(p,pos[i]);
        }
        cout<<p<<endl;
    }
    else{
        ll ans=1;
        if(k&1){
            sort(pos.begin(),pos.end());
            ans=mul(ans,pos[pos.size()-1]);
            pos.pop_back();
            k--;
        }
        vector<ll> ok;
        sort(pos.begin(),pos.end(),greater<ll>());
        sort(neg.begin(),neg.end());

        for(int i=0;i<(int)pos.size()-1;i+=2){
            ok.push_back(pos[i]*pos[i+1]);
        }
        for(int i=0;i(int)<neg.size()-1;i+=2){
            ok.push_back(neg[i]*neg[i+1]);
        }
        if(pos.size()%2==0 && neg.size()%2==0){
            ok.push_back(pos[pos.size()-1]*neg[neg.size()-1]);
        }
        sort(ok.begin(),ok.end(),greater<ll>());
        for(int i=0;i<(k/2);i++){
            ans=mul(ans,ok[i]);
        }
        cout<<ans<<endl;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:59:23: error: expected primary-expression before 'int'
   59 |         for(int i=0;i(int)<neg.size()-1;i+=2){
      |                       ^~~
a.cc:59:26: error: 'i' cannot be used as a function
   59 |         for(int i=0;i(int)<neg.size()-1;i+=2){
      |                          ^
Language: C++

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

int main() {
	int i;
	int j;
	int N;
	int K;
	int q;
	int q11;
	int q22;
	long long p;
	long long p1;
	long long p2;
	long long p3;
	long long p4;
   
	cin >> N >> K;
	int a[N];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
    sort(a, a + (N), greater<int>());  // a[0:N] を大きい順にソート
  	if (K==1){
		cin >> a[0];
 		p=1000000007;
      	p+=a[0];
		p=p%1000000007;
		cout << p << endl;
      return 0;
    }
	if ((K%2)==1)&&(a[0]<=0)){
		p=1;
		for(int i=0;i<K;i++){
			p*=a[i];
			p=p%1000000007;
		}
		p+=1000000007;
		p=p%1000000007;
		cout << p << endl;
		return 0;
	}
	q=0;
	q11=(K%2);
	q22=N-1;
	for(int i=(K%2);i<K;i++){
		if(a[q11]>-a[q22]) {
			q11++;
		} else {
			q22--;
			q++;
		}
	}
 	if ((q%2)==1){
 		p1=a[q11-1];
		p2=a[q11];
		p3=a[q22];
		p4=a[q22+1];
		if(p1*p2<p3*p4) {
			q11--;
			q22--;
		} else {
			q11++;
			q22++;
		}
	}
  	p=1;
	while (q11 > 0) {
		q11--;
		p*=a[q11];
		p=p%1000000007;
	}
	while (q22 < N-1) {
		q22++;
		p*=a[q22];
		p=p%1000000007;
	}
	p+=1000000007;
	p=p%1000000007;
	cout << p << endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:32:24: error: expected identifier before '(' token
   32 |         if ((K%2)==1)&&(a[0]<=0)){
      |                        ^
Language: C++

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n, k; cin >> n >> k;
    vector<long long> posi;
    vector<long long> nega;
    vector<long long> zen;
    for(long long i = 0; i < n; i ++){
        ll tmp; cin >> tmp;
        if(tmp < 0){
            nega.push_back(tmp);
            zen.push_back(tmp);
        }else{
            posi.push_back(tmp);
            zen.push_back(tmp);
        }
    }

    bool ok = false;
    //正にできるか
    if(posi.size() > 0){
        if(n == k && nega.size() % 2 == 1){
            ok = false;
        }else{
            ok = true;
        }
    }else{
        if(k % 2 == 1){
            ok = false;
        }else{
            ok = true;
        }
    }

    ll ans = 1;
    if(!ok){
        sort(zen.begin(), zen.end(), [](ll x, ll y){
            return abs(x) < abs(y);
        });
        for(ll i = 0; i < k; i++){
            ans = ((ans * zen[i]) % MOD) + MOD) % MOD;
        }
    }else{
        sort(posi.begin(), posi.end());
        sort(nega.rbegin(), nega.rend());
        if(k % 2 == 1){
            ans = (ans * posi.back()) % MOD;
            posi.pop_back();
        }
        vector<ll> ab;
        while(posi.size() >= 2){
            ll x = posi.back(); posi.pop_back();
            x = (x * posi.back()) % MOD; posi.pop_back();
            ab.push_back(x);
        }
        while(nega.size() >= 2){
            ll x = nega.back(); nega.pop_back();
            x = (x * nega.back()) % MOD; nega.pop_back();
            ab.push_back(x);
        }
        sort(ab.rbegin(), ab.rend());
        rep(i, k/2){
            ans = (ans * ab[i]) % MOD;
        }

    }

    cout << ans << endl;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:61:47: error: expected ';' before ')' token
   61 |             ans = ((ans * zen[i]) % MOD) + MOD) % MOD;
      |                                               ^
      |                                               ;
Language: C++

#include<bits/stdc++.h>
using namespace std;
long long int find_pro(int k,long long int arr[])
{
    int i;
    long long int pr=1;
    for(i=0;i<k;i++)
    {
        pr=(pr*arr[i])%(1000000007);
    }
    return pr%(1000000007);
    
}
int main()
{
  int n,k;
  cin>>n>>k;
  long long int arr[n];
  int i,p=0,ne=0,z=0,j;
  for(i=0;i<n;i++)
  {
      cin>>arr[i];
      arr[i]>0?p++:((arr[i]==0)?z++:ne++);
  }
  sort(arr,arr+n);
  if(p==0)
  {
      if(k%2!=0)
          { reverse(arr,arr+n);
          cout<<find_pro(k,arr);}
      else
          cout<<find_pro(k,arr);
  }
  else if(ne==0)
      cout<<find_pro(k,arr);
  else
  {   
      long long int pr=1,c=0;
      i=0,j=n-1;
      reverse(arr,arr+n);
      while(i<j&&c<k)
      {
              if(abs(arr[i])>abs(arr[j]))
              {
                 pr=(pr*arr[i])%(1000000007);
                 i++;
              }
              else
              {
                  pr=(pr*arr[j])%(1000000007);
                  j--;
              }
             else
              {
                  if(pr<0)
                  {
                      pr=(pr*arr[j])%(1000000007);
                      j--;
                  }
                  else
                  {
                      pr=(pr*arr[i])%(1000000007);
                      i++;
                  }
                    
              }
                  c++;
      }
      
      if(pr>=0)
         cout<<pr;
      else
      {
          pr=pr/arr[j+1];
          pr=pr*arr[i];
          cout<<pr%(1000000007);
      }
      
  }
  
  
}

Compiler output:
a.cc: In function 'int main()':
a.cc:53:14: error: 'else' without a previous 'if'
   53 |              else
      |              ^~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int ab(int x){
    return x<0?-x:x;
}
int power(int a,int b){
    int ans=1;
    a%=mod;
    while(b){
        if(b&1){
            ans=ans*a%mod;
            b--;
        }
        b>>=1;
        a=a*a%mod;
    }
    return ans%mod;
}
int fermat(int a){
    return power(a,mod-2);
}
main(){
    int n,k;
    cin>>n>>k;
    set<int>a[2];
    for(int i=0;i<n;++i){
        int x;
        cin>>x;
        if(x>=0)a[1].insert(x);
        else a[0].insert(x);
    }
    set<int>res;
    int ans=1ll;
    int pas=a[1].size();
    while(k>res.size()){
        if(a[0].empty()||!a[1].empty()&&*a[1].rbegin()>ab(*a[0].begin()))){
            res.insert(*a[1].rbegin());
            a[1].erase(prev(a[1].end()));
        }else if(!a[0].empty()){
            res.insert(*a[0].begin());
            a[0].erase(a[0].begin());
        }
    }
    for(auto i:res){
        ans=ans*i%mod;
    }
    if(ans<0){
        if(pas&&(!a[0].empty()||!a[1].empty())){
            int mx=-inf;
            int mi=-1;
            for(auto i:res){
                if(i<0)mx=max(mx,i);
                else mi=min(mi,i);
            }
            if(a[0].empty()){
                ans=ans*fermat(mx)%mod;
                ans=ans*(*a[1].rbegin())%mod;
            }else if(a[1].empty()){
                ans=ans*fermat(mi)%mod;
                ans=ans*(*a[0].begin())%mod;
            }else if(mi*(*a[1].rbegin())>mx*(*a[0].begin())){
                ans=ans*fermat(mx)%mod;
                ans=ans*(*a[1].rbegin())%mod;
            }else{
                ans=ans*fermat(mi)%mod;
                ans=ans*(*a[0].begin())%mod;
            }
            cout<<(ans+mod)%mod<<endl;
        }else{
            ans=1;
            for(auto i:res){
                if(i>=0)a[1].insert(i);
                else a[0].insert(i);
            }
            res.clear();
            while(k>res.size()){
                if(a[0].empty()||(!a[1].empty()&&*a[1].begin()<ab(*a[0].rbegin()))){
                    res.insert(*a[1].begin());
                    a[1].erase(a[1].begin());
                }else if(!a[0].empty()||a[1].empty()){
                    res.insert(*a[0].rbegin());
                    a[0].erase(prev(a[0].end()));
                }
            }
            for(auto i:res){
                ans=ans*i%mod;
            }
            cout<<(ans+mod)%mod<<endl;
        }
    }else cout<<(ans+mod)%mod<<endl;
}


Compiler output:
a.cc:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:39:74: error: expected primary-expression before ')' token
   39 |         if(a[0].empty()||!a[1].empty()&&*a[1].rbegin()>ab(*a[0].begin()))){
      |                                                                          ^
Language: C++

#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;

const int m = 1000000007;

int print(ll ans){
  ans%=m;
  if(ans<0) ans+=m;
  cout << ans << "\n";
  return 0;
}

int main(){
  int n,k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(a.rbegin(),a.rend());
  ll ans=1;
  if(a[0]<0){
    rep(i,k){ans*=a[i];ans%=m;}
    print(ans);
    return 0;
  }
  int index1=0,index2=n-1;
  if(k%2==1){
    ans*=a[0];
    k--;
    index1++;
  }
  rep(i,k/2){
    if(a[index1]*a[index1+1]>a[index2]*a[index2-1]){
      ans*=a[index1];ans%=m;
      ans*=a[index1+1];ans%=m;
      index1+=2;
    }else{
      ans*=a[index2];ans%=m;
      ans*=a[index2-1];ans%=m;
      index2-=2;
    }
  }
  if(ans<0){
    ans=1;
    rep(i,k){ans*=a[i];ans%=m;}
  }
  print(ans);
  
  cout << (-1*m-1)%m
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:52:21: error: expected ';' before 'return'
   52 |   cout << (-1*m-1)%m
      |                     ^
      |                     ;
   53 |   return 0;
      |   ~~~~~~
Language: C++

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

const int64_t MOD = 1e9+7;

void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int main() {
	// your code goes here
	inr n, k;
	int64_t ans = 1;
	cin >> n >> k;
	vector<int64_t> a, b, A;
	for(int i = 0; i < n; ++i){
		int64_t l;
		cin >> l;
		A.push_back(abs(l));
		if(l < 0)b.push_back(l);
		else if(l > 0) a.push_back(abs(l));
	}
	
	int szn = b.size(), szp = a.size();
	
	if((szp + szn/2*2 >= k) && (k%2 == 0 || szp > 0)){
		sort(a.rbegin(), a.rend());
        sort(b.rbegin(), b.rend());
		if(k%2)ans = a[0];
		vector<int64_t> V;
		for(int i=k%2; i+1<szp; i+=2) V.push_back(a[i]*a[i+1]);
        for(int i=0; i+1<szn; i+=2) V.push_back(b[i]*b[i+1]);
        sort(V.rbegin(), V.rend());
        for(int i=0; i<k/2; i++) mul(ans, V[i] % MOD);
	}
	else{
		sort(A.begin(), A.end());
        for(int i=0; i<k; i++) mul(ans, A[i]);
        ans = (MOD-ans) % MOD;
	}
	
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:9: error: 'inr' was not declared in this scope; did you mean 'int'?
   12 |         inr n, k;
      |         ^~~
      |         int
a.cc:14:16: error: 'n' was not declared in this scope; did you mean 'yn'?
   14 |         cin >> n >> k;
      |                ^
      |                yn
a.cc:14:21: error: 'k' was not declared in this scope
   14 |         cin >> n >> k;
      |                     ^
Language: C++

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

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) (v).begin(), (v).end()
#define sz(v) (int) (v).size()

#define int long long 

const int MOD = 1e9 + 7;

signed main(int argc, char* argv[]) {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> pos, neg;
  for (int a, i = 0; i < n; i++) {
    cin >> a;
    if (a > 0) pos.push_back(a);
    else neg.push_back(a);
  }
  sort(all(pos));
  sort(all(neg)); reverse(all(neg));
  if (pos.empty() && k % 2 == 1) {
    if (find(all(neg), 0) != neg.end())
      return cout << 0, 0;
    long long product = 1;
    for (int i = 0; i < k; i++) {
      product = (product % MOD * neg[i] % MOD) % MOD;
      while (product < 0) product += MOD;
      product %= MOD;
    }
    cout << product % MOD << '\n';
    return 0;
  }
  vi res;
  auto add = [&](vector<int>& nums) {
    res.push_back(nums.back());
    nums.pop_back();
    res.push_back(nums.back());
    nums.pop_back();
  };
  while (k >= 2) {
    if (sz(pos) >= 2 && sz(neg) >= 2) {
      long long a = pos[sz(pos) - 1] * pos[sz(pos) - 2];
      long long b = neg[sz(neg) - 1] * neg[sz(neg) - 2];
      if (a > b)
        add(pos);
      else
        add(neg);
    } else if (sz(pos) >= 2)
      add(pos);
    else if (sz(pos) >= 2)
      add(neg);
    else
      break;
    k -= 2;
  }
  if (!pos.empty() && k-- > 0) res.push_back(pos.back());
  if (!neg.empty() && k-- > 0) res.push_back(neg.back());
  long long product = 1;
  for (int& num : res) {
    product = (product % MOD * num % MOD) % MOD;
    while (product < 0) product += MOD;
    product %= MOD;
  }
  cout << product % MOD << '\n';
  return 0;
}

Compiler output:
a.cc:14:8: warning: first argument of 'int main(long long int, char**)' should be 'int' [-Wmain]
   14 | signed main(int argc, char* argv[]) {
      |        ^~~~
a.cc: In function 'int main(long long int, char**)':
a.cc:64:19: error: cannot bind non-const lvalue reference of type 'long long int&' to a value of type 'int'
   64 |   for (int& num : res) {
      |                   ^~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    long long int a[n];
    for(int i=0;i<n;i++)cin >> a[i];
    sort(a,a+n);
    long long int mod=1e9+7;
    long long int ans=1;
    vector<long long int> plus;
    vector<long long int> minus;
    for(int i=0;i<n;i++){
        if(a[i]<0)minus.push_back(a[i]);
        else plus.push_back(a[i]);
    }
    if(n==k){
        int t=0;
        for(int i=0;i<k;i++){
            ans *= abs(a[i]);
            ans %= mod;
            if(a[i]<0)t++;
        }
        if(t%2==1)cout << mod - ans;
        else cout << ans;
    }
    else if(a[n-1]<0 && k%2==1){
        for(int i=0;i<k;i++){
            ans *= abs(a[n-1-i]);
            ans %= mod;
        }
        cout << mod - ans;
    }
    else{
        int p;
        long unsigned int m;
        int count=0;
        p=plus.size()-1; m=0;
        while(count<k){
            while((m+1<minus.size() && p-1>=0) && count+2<=k){
                if(minus[m]*minus[m+1]>=plus[p]*plus[p-1]){
                ans *= ((minus[m]*minus[m+1])%mod);
                ans %= mod;
                m+=2;
                count+=2;
                }
                else break;
            }
            while(p<0 && count+1<=k){
                ans *= abs(minus[m]);
                ans %= mod;
                m++;
                count++;
                t++;           
            }
            if(count+1<=k && p>=0){
                ans *= plus[p];
                ans %= mod;
                p--;
                count++;                
            }
        }
        cout << ans;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:54:17: error: 't' was not declared in this scope
   54 |                 t++;
      |                 ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    long long int a[n];
    for(int i=0;i<n;i++)cin >> a[i];
    sort(a,a+n);
    long long int mod=1e9+7;
    long long int ans=1;
    vector<long long int> plus;
    vector<long long int> minus;
    for(int i=0;i<n;i++){
        if(a[i]<0)minus.push_back(a[i]);
        else plus.push_back(a[i]);
    }
    if(plus.length()<k && (k-plus.length())%2==1){
        long long int b[n];
        for(int i=0;i<n;i++)b[i]=abs(a[i]);
        sort(b,b+n);
        for(int i=0;i<k;i++){
            ans *= b[i];
            ans %= mod;
        }
        cout << mod - ans;
    }
    else{
        int p,m;
        int count=0;
        p=plus.length()-1; m=0;
        while(count<k){
            while((minus[m]*minus[m+1]>plus[p]*plus[p-1]
            && (m+1<minus.length() && p-1>=0))
            && count+2<=k){
                ans *= ((minus[m]*minus[m+1])%mod);
                ans %= mod;
                m+=2;
                count+=2;
            }
            if(count+1<=k && p>=0){
                ans *= ((plus[p])%mod);
                ans %= mod;
                p--;
                count++;                
            }
            else if((p==0 && m+1<minus.length()) && count+2<=k){
                ans *= ((minus[m]*minus[m+1])%mod);
                ans %= mod;
                m+=2;
                count+=2;                
            }
        }
        cout << ans;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:13: error: 'class std::vector<long long int>' has no member named 'length'
   17 |     if(plus.length()<k && (k-plus.length())%2==1){
      |             ^~~~~~
a.cc:17:35: error: 'class std::vector<long long int>' has no member named 'length'
   17 |     if(plus.length()<k && (k-plus.length())%2==1){
      |                                   ^~~~~~
a.cc:30:16: error: 'class std::vector<long long int>' has no member named 'length'
   30 |         p=plus.length()-1; m=0;
      |                ^~~~~~
a.cc:33:27: error: 'class std::vector<long long int>' has no member named 'length'
   33 |             && (m+1<minus.length() && p-1>=0))
      |                           ^~~~~~
a.cc:46:40: error: 'class std::vector<long long int>' has no member named 'length'
   46 |             else if((p==0 && m+1<minus.length()) && count+2<=k){
      |                                        ^~~~~~
Language: C++

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    llint n, k;
    cin >> n >> k;

    vector<llint> a(n);
    vector<llint> p;
    vector<llint> m;
    llint cntminus = 0;
    for(llint in=0;in<n;in++) {
        cin >> a[in];
        if (a[in]>=0) {
            p.push_back(a[in]);
        }
        else {
            m.push_back(a[in]); 
            cntminus++;
        }
    }

    llint ans = 1LL;
    if(k==n) {
        for(llint ik=0;ik<k;ik++) {
            ans *= a[ik];
            ans %= MOD;
        }
        if(ans<0) ans += MOD;
        cout << ans << endl;
        return 0;
    }
    else if(cntminus==n&&k%2==1) {
        sort(a.begin(), a.end(), greater<llint>());
        for(llint ik=0;ik<k;ik++) {
            ans *= a[ik];
            ans %= MOD;
        }
        if(ans<0) ans += MOD;
        cout << ans << endl;
        return 0;
    }
    else {
        sort(p.begin(), p.end(), greater<llint>());
        sort(m.begin(), m.end());
        int ip = 0, im = 0;
        vector<llint> s;
        while(s.size()<k) {
            if(s.size()==k-1) {
                s.push_back(p[ip]);
                ip++;
            }
            else if(ip=>p.size()-2) {
                s.push_back(m[im]);
                s.push_back(m[im+1]);
                im += 2;
            }
            else if(im>=m.size()-2) {
                s.push_back(p[ip]);
                ip++;
            }
            else if(p[ip]*p[ip+1]>=m[im]*m[im+1]){
                s.push_back(p[ip]);
                ip++;
            }
            else {
                s.push_back(m[im]);
                s.push_back(m[im+1]);
                im += 2;
            }
        }
        for(auto is:s) {
            ans *= is;
            ans %= MOD;
        }
        if(ans<0) ans += MOD;
        cout << ans << endl;
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:67:24: error: expected primary-expression before '>' token
   67 |             else if(ip=>p.size()-2) {
      |                        ^
Language: C++

#include<bits/stdc++.h>
#define N 300050
#define M 200
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N
#define MOD mod
using namespace std;
int n,k;
vector< pair< int , int > > ar;
int mod = 1e9 + 7;
int fast_exp(int base,int ex) {
    int res=1;
    while(ex>0) {
       if(ex%2==1) res=(res*base)%mod;
       base=(base*base)%mod;
       ex/=2;
    }
    return res%mod;
}
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
    int ans = 0;
    cin>>n>>k;
    ar.resize(n);
    for(int i=0;i<n;i++){
        cin>>ar[i].x;
        if(ar[i].x<0)ar[i].y = -1;
        else ar[i].y = 1;
        ar[i].x = abs(ar[i].x);
    }
    sort(all(ar));
    reverse(all(ar));
    int ne = 0, pos =0;
    int pr = 1;
    int ze = 0;
    for(int i=0;i<k;i++){
        pr *= ar[i].x;
        pr %= mod;
        if(ar[i].y<0)ne++;
        if(ar[i].x==0)ze = 1;
    }
    if(ne%2==0){
        cout<<pr;
        return 0;
    }
    //cout<<"he ";
    int a=1e10,b = 1e10;
    for(int i=k;i<n;i++){
        if(ar[i].x<0&&a==1e10&&ar[i].y==-1)a = ar[i].x;
        if(ar[i].x<0&&b==1e10&&ar[i].y==1)b = ar[i].x;
    }
    int c = 1e10,d = 1e10;
    for(int i=k-1;i>=0;i--){
        if(ar[i].x<0&&c==1e10&&ar[i].y==-1)c = ar[i].x;
        if(ar[i].x<0&&d==1e10&&ar[i].y==1)d = ar[i].x;
    }
    if((a==1e10||d==1e10)&&(b==1e10||c==1e10)){
        int ans = 1;
        for(int i=n-1;i>=n-k;i--){
            ans *= ar[i].x;

Compiler output:
a.cc: In function 'int main()':
a.cc:68:28: error: expected '}' at end of input
   68 |             ans *= ar[i].x;
      |                            ^
a.cc:67:34: note: to match this '{'
   67 |         for(int i=n-1;i>=n-k;i--){
      |                                  ^
a.cc:68:28: error: expected '}' at end of input
   68 |             ans *= ar[i].x;
      |                            ^
a.cc:65:47: note: to match this '{'
   65 |     if((a==1e10||d==1e10)&&(b==1e10||c==1e10)){
      |                                               ^
a.cc:68:28: error: expected '}' at end of input
   68 |             ans *= ar[i].x;
      |                            ^
a.cc:27:14: note: to match this '{'
   27 | signed main(){
      |              ^
Language: C++

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long LL;
const int N = 200010;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
LL a[N];
bool cmp(LL a,LL b){
	return abs(a)>abs(b);
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n,k;
	cin>>n>>k; 
	for(int i=1;i<=n;i++){
		scanf("%lld",a+i);
	}
	sort(a+1,a+n+1,cmp);
	LL ans=1;
	for(int i=1;i<=k;i++){
		ans*=a[i];
		ans%=mod;
	}
	bool f=false;
	for(int i=k+1;)
	if(ans>0 || n==k){
		cout<<(ans+mod)%mod<<endl;
	}
	else{
		LL t1=inf;		//1-k		min()  +
		LL t2=inf;		//1-k		min()  -
		LL t3=0;		//k+1-n		max()  +
		LL t4=0;		//k+1-n		max()  -
		for(int i=1;i<=k;i++){
			if(a[i]>=0){
				t1=min(t1,a[i]);
			}
			else{
				t2=min(t2,-a[i]);
			}
		}
		for(int i=k+1;i<=n;i++){
			if(a[i]>=0){
				t3=max(t3,a[i]);
			}
			else{
				t4=max(t4,-a[i]);
			}
		}
		if(t2*t4<t1*t3){
			bool f=false;
			ans=1;
			for(int i=1;i<=k;i++){
				if(a[i]==-t2 && !f){
					ans*=t3;
					ans%=mod; 
				}
				else{
					ans*=a[i];
					ans%=mod;
				}
			}
			cout<<ans<<endl;
		}
		else{
			bool f=false;
			ans=1;
			for(int i=1;i<=k;i++){
				if(a[i]==t1 && !f){
					ans*=-t4;
					ans%=mod; 
				}
				else{
					ans*=a[i];
					ans%=mod;
				}
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:29:23: error: expected primary-expression before ')' token
   29 |         for(int i=k+1;)
      |                       ^
a.cc:29:23: error: expected ';' before ')' token
   29 |         for(int i=k+1;)
      |                       ^
      |                       ;
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
ll exp(ll a,ll n){
  if(n==0) return 1;
  else if(n%2==0) return (exp(a,n/2)*exp(a,n/2))%mod;
  else return (a*exp(a,n-1))%mod;
}
int main() {
  int n,k;
  cin>>n>>k;
  vector<ll>a(n);
  rep(i,n) cin>>a[i];
  sort(a.begin(),a.end());
  vector<ll>minus;
  vector<ll>plus;
  ll zero=0;
  rep(i,n){
    if(a[i]>=0) plus.push_back(a[i]);
    else if(a[i]<0) minus.push_back(a[i]);
  }
  if(n==k){
    ll ans=1;
    rep(i,n){
      ans*=a[i];
      ans%=mod;
    }
    cout<<ans<<endl;
  }
  else if(minus.size()==n){
    ll ans=1;
    rep(i,k) {
      ans*=a[n-1-i];
      ans%=mod;
    }
    cout<<ans<<endl;
  }
  else{
    ll m=0;
    ll p=plus.size()-1;
    ll ans=1;
    ll odd=0;
    ll ss=minus.size();
      rep(i,k){
       if(m<ss && p>=0){
         if(abs(minus[m])<=plus[p]){
           ans*=plus[p];
           ans%=mod;
           p--;
         }
         else{
           ans*=abs(minus[m]);
           odd++;
           m++;
           ans%=mod;
         }
       }
      else if(m<ss && p<0){
        ans*=abs(minus[m]);
        ans%=mod;
        m++;
        odd++;
      }
      else if(m>=ss && p>=0){
        ans*=plus[p];
        ans%=mod;
        p--;
      }
      else{
        ans=0;
        z--;
      }
    }
    if(odd%2==0) cout<<ans<<endl;
    else{
    m--;
    ll y=exp(abs(minus[m]),mod-2);
      ll x=exp(plus[p+1],mod-2);
     if(p<0){
       ans*=x;
       ans%=mod;
       ans*=minus[m+1];
       ans%=mod;
       cout<<ans<<endl;
     }
      else if(m==minus.size()-1){
        ans*=y;
        ans%=mod;
        ans*=plus[p];
        ans%=mod;
        cout<<ans<<endl;
      }
      else{
        if(plus[p]*plus[p+1]>=minus[m]*minus[m+1]){
          ans*=y;
        ans%=mod;
        ans*=plus[p];
        ans%=mod;
        cout<<ans<<endl;
        }
        else{
         ans*=x;
       ans%=mod;
       ans*=minus[m+1];
       ans%=mod;
       cout<<ans<<endl;
        }
      }
    }
  }

}


Compiler output:
a.cc: In function 'int main()':
a.cc:73:9: error: 'z' was not declared in this scope
   73 |         z--;
      |         ^
Language: C++

#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;
  vi pl,mi;
  ll ze = 0;
  for(int i=0;i<n;i++){
    ll a;cin>>a;
    if(a > 0)
	  pl.pb(a);
    else if(a < 0)
      mi.pb(-a);
  }
  if(n-ze < k){cout<<0<<endl;return 0;}
  sort(ALL(pl),greater<ll>());
  sort(ALL(mi),greater<ll>());
  vector<pair<ll,ll>> prd(n+1),mrd(n+1),pri(n+1),mri(n+1);
  prd[0] = mp(1,0);
  pri[0] = mp(1,0);
  mrd[0] = mp(1,0);
  mri[0] = mp(1,0);
  for(int i=0;i<pl.size();i++){
    prd[i+1].F = (prd[i].F * pl[i])%MOD;
    prd[i+1].S = prd[i].S + (ll)((prd[i].F * pl[i])/MOD);
  }
  for(int i=0;i<mi.size();i++){
    mrd[i+1].F = (mrd[i].F * mi[i])%MOD;
    mrd[i+1].S = mrd[i].S + (ll)((mrd[i].F * mi[i])/MOD);
  }
  sort(ALL(pl));
  sort(ALL(mi));
  for(int i=0;i<pl.size();i++){
    pri[i+1].F = (pri[i].F * pl[i])%MOD;
    pri[i+1].S = pri[i].S + (ll)((pri[i].F * pl[i])/MOD);
  }
  for(int i=0;i<mi.size();i++){
    mri[i+1].F = (mri[i].F * mi[i])%MOD;
    mri[i+1].S = mri[i].S + (ll)((mri[i].F * mi[i])/MOD);
  }
  if((n == k && mi.size()%2) || (mi.size() == n && k%2)){
    if(n == k){
      cout<<(MOD-(pri[pl.size()].F * mri[mi.size()].F)%MOD)%MOD<<endl;
    }else{
      cout<<(MOD-mri[k].F)%MOD<<endl;
    }
  }else{
    ll now = k;
    while(now > pl.size())now-=2;
    ll mapo = prd[now].S+mri[k-now].S+(ll)((prd[now].F*mrd[k-now].F)/MOD);ans = (prd[now].F*mrd[k-now].F)%MOD;now-=2;
	while(now >= 0){
      if(k-now < 0)break;
      ll sum = (prd[now].F * mrd[k-now].F) % MOD;
      ll po = prd[now].S + mrd[k-now].S + (ll)((prd[now].F * mrd[k-now].F) / MOD);
      if(po > mapo){
        mapo = po;
        ans = sum;
      }else if(po == mapo){
        if(ans < sum){
          ans = sum;
        }
      }
      now-=2;
    }
    cout<<ans<<endl;
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:67:75: error: 'ans' was not declared in this scope; did you mean 'abs'?
   67 |     ll mapo = prd[now].S+mri[k-now].S+(ll)((prd[now].F*mrd[k-now].F)/MOD);ans = (prd[now].F*mrd[k-now].F)%MOD;now-=2;
      |                                                                           ^~~
      |                                                                           abs
Language: C++

#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;
  vi pl,mi;
  ll ze = 0;
  for(int i=0;i<n;i++){
    ll a;cin>>a;
    if(a > 0)
	  pl.pb(a);
    else if(a < 0)
      mi.pb(-a);
  }
  if(n-ze < k){cout<<0<<endl;return 0;}
  sort(ALL(pl),greater<ll>());
  sort(ALL(mi),greater<ll>());
  vector<pair<ll,ll>> prd(n+1),mrd(n+1),pri(n+1),mri(n+1);
  prd[0] = mp(1,0);
  pri[0] = mp(1,0);
  mrd[0] = mp(1,0);
  mri[0] = mp(1,0);
  for(int i=0;i<pl.size();i++){
    prd[i+1].F = (prd[i].F * pl[i])%MOD;
    prd[i+1].S = prd[i].S + (ll)((prd[i].F * pl[i])/MOD);
  }
  for(int i=0;i<mi.size();i++){
    mrd[i+1].F = (mrd[i].F * mi[i])%MOD;
    mrd[i+1].S = mrd[i].S + (ll)((mrd[i].F * mi[i])/MOD);
  }
  sort(ALL(pl));
  sort(ALL(mi));
  for(int i=0;i<pl.size();i++){
    pri[i+1].F = (pri[i].F * pl[i])%MOD;
    pri[i+1].S = pri[i].S + (ll)((pri[i].F * pl[i])/MOD);
  }
  for(int i=0;i<mi.size();i++){
    mri[i+1].F = (mri[i].F * mi[i])%MOD;
    mri[i+1].S = mri[i].S + (ll)((mri[i].F * mi[i])/MOD);
  }
  if((n == k && mi.size()%2) || (mi.size() == n && k%2)){
    if(n == k){
      cout<<(MOD-(pri[pl.size()].F * mri[mi.size()].F)%MOD)%MOD<<endl;
    }else{
      cout<<(MOD-mri[k].F)%MOD<<endl;
    }
  }else{
    ll now = k;
    while(now > pl.size())now-=2;
    ll mapo = prd[now].S+mri[k-now].S+(ll)((prd[now].F*mrd[k-now].F)/MOD);,ans = (prd[now].F*mrd[k-now].F)%MOD;now-=2;
	while(now >= 0){
      if(k-now < 0)break;
      ll sum = (prd[now].F * mrd[k-now].F) % MOD;
      ll po = prd[now].S + mrd[k-now].S + (ll)((prd[now].F * mrd[k-now].F) / MOD);
      if(po > mapo){
        mapo = po;
        ans = sum;
      }else if(po == mapo){
        if(ans < sum){
          ans = sum;
        }
      }
      now-=2;
    }
    cout<<ans<<endl;
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:67:75: error: expected primary-expression before ',' token
   67 |     ll mapo = prd[now].S+mri[k-now].S+(ll)((prd[now].F*mrd[k-now].F)/MOD);,ans = (prd[now].F*mrd[k-now].F)%MOD;now-=2;
      |                                                                           ^
a.cc:67:76: error: 'ans' was not declared in this scope; did you mean 'abs'?
   67 |     ll mapo = prd[now].S+mri[k-now].S+(ll)((prd[now].F*mrd[k-now].F)/MOD);,ans = (prd[now].F*mrd[k-now].F)%MOD;now-=2;
      |                                                                            ^~~
      |                                                                            abs
Language: C++

#include<bits/stdc++.h>
using namespace std;
long M=1e9+7,n,k,ans=1,l,r,b=1,a[1e6],x,y,i;
main(){cin>>n>>k;r=n-1;
  for(i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  if(k%2)ans=a[r],r--,k--,b=(ans<0?-1:1);
  while(k){x=a[l]*a[l+1],y=a[r]*a[r-1];
    if(x*b>y*b)ans*=x%M,ans%=M,l+=2;
    else ans*=y%M,ans%=M,r-=2;
    k-=2;
  }cout<<(ans+M)%M<<endl;
}


Compiler output:
a.cc:3:34: error: conversion from 'double' to 'long unsigned int' in a converted constant expression
    3 | long M=1e9+7,n,k,ans=1,l,r,b=1,a[1e6],x,y,i;
      |                                  ^~~
a.cc:3:34: error: could not convert '1.0e+6' from 'double' to 'long unsigned int'
    3 | long M=1e9+7,n,k,ans=1,l,r,b=1,a[1e6],x,y,i;
      |                                  ^~~
      |                                  |
      |                                  double
a.cc:3:34: error: size of array 'a' has non-integral type 'double'
a.cc:4:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    4 | main(){cin>>n>>k;r=n-1;
      | ^~~~
Language: C++

#include <bits/stdc++.h>

using namespace std;
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db long double
#define eps 1e-3
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
#define endl "\n"
const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 10;
deque<ll> a, pos, neg;
db posd[maxn], negd[maxn];

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k, zero = 0;
    cin >> n >> k;

    _rep(i, 1, n) {
        ll x;
        cin >> x;
        if (x < 0) {
            neg.push_back(-x);
        } else if (x > 0) {
            pos.push_back(x);
        } else zero++;
    }
    sort(all(pos), greater<ll>());
    sort(all(neg), greater<ll>());

    ll res = 1;
    if ((k & 1) <= pos.size() && (neg.size() - (neg.size() & 1)) + pos.size() >= k) {
        // 找正数
        pos.push_front(1);
        neg.push_front(1);

        _for(i, 1, pos.size()) {
            posd[i] = posd[i - 1] + log(pos[i]);
        }
        _for(i, 1, neg.size()) {
            negd[i] = negd[i - 1] + log(neg[i]);
        }
        int ind = 0;
        db ans = 0;
        for (int i = 0; i < neg.size() &&  k - i >= 0; i += 2) {
            if (posd[k - i] + negd[i] > ans && ) {
                ans = posd[k - i] + negd[i];
                ind = i;
            }
        }
        _rep(i, 1, ind) {
            res = (res * neg[i]) % mod;
        }
        _rep(i, 1, k - ind) {
            res = (res * pos[i]) % mod;
        }
        res = res % mod;
    } else if (zero) {
        res = 0;
    } else {
        assert(k<=neg.size());
        sort(all(neg));
        _for(i, 0, k) {
            res = res * neg[i] % mod;
        }
        res = (mod - res) % mod;
    }
    cout << (res + mod) % mod << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:58:48: error: expected primary-expression before ')' token
   58 |             if (posd[k - i] + negd[i] > ans && ) {
      |                                                ^
Language: C++

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void codeforces()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
bool compare(int a, int b)
{
    if( abs(a) > abs(b)) return true;
    else return !true;
}
int32_t main()
{
    int n, k;
    cin>>n>>k;
    int a[n];
    int flag = 0;
    for(int i=0; i<n; i++){ 
        cin>>a[i];
        if( a[i] > 0) flag = 1;
    }
    if(flag == 0){
        sort(a, a+n);
        int ans = 1;
        for(int i=0; i<k; i++) ans*=a[i];
        cout<<ans%mod;
        return;
    }
    if( k == n){
        int ans = 1;
        for(int i=0; i<k; i++) ans*=a[i];
        cout<<ans%mod;
        return;
    }
    sort(a, a+n, compare);
    int ans = 1;
    for(int i=0; i<k; i++){
        ans = ans*a[i];
    }
    if( ans > 0) cout<<ans%mod;
    else{
        int x = 0, y = 0;
        for(int i=k; i<n; i++){
            if( a[i] < x) x = a[i];
            if( a[i] > y) y = a[i];
        }
        cout<<ans<<" "<<x<<" "<<y<<endl;
        int maxi = 0;
        for(int i=0; i<k; i++){
            maxi = max({maxi, (ans*x)/a[i], (y*ans)/a[i]});
        }
        cout<<maxi%mod<<endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int32_t main()':
a.cc:55:9: error: return-statement with no value, in function returning 'int32_t' {aka 'int'} [-fpermissive]
   55 |         return;
      |         ^~~~~~
a.cc:61:9: error: return-statement with no value, in function returning 'int32_t' {aka 'int'} [-fpermissive]
   61 |         return;
      |         ^~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
void solve(){
	ll n,k;
	cin>>n>>k;
	vector<ll>a(n);
	for(ll i=0;i<n;i++) cin>>a[i];
	ll prod=1;
	sort(a.begin(),a.end());
	if(a[n-1]==0&&k%2==1) {cout<<0;return;}
	if(a[n-1]<0&&k&1){
		for(ll i=n-1;i>=n-k;i--){
			prod=(a[i]*prod)%mod;
		}
	}
	cout<<((prod%mod)+mod)%mod;return;
	}
	ll i=0;ll j=n-1;
	if(a[n-1]>0&&k&1){
		prod=(prod*a[n-1])%mod;
		j--;k--;
	}
	k=k>>1;
	for(ll itr=0;itr<k;itr++){
		ll lprod=a[i]*a[i+1];
		ll rprod=a[j]*a[j-1];
		if(lprod>rprod){
			prod=prod*a[i]%mod*a[i+1]%mod;
			i+=2;
		}
		else{
			prod=prod*a[j]%mod*a[j-1]%mod;
			j-=2;
		}
	}
	if(prod<0) cout<<((prod%mod)+mod)%mod;
	else cout<<prod%mod;
} 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);	 
	int T=1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

Compiler output:
a.cc:20:21: error: 'n' was not declared in this scope; did you mean 'yn'?
   20 |         ll i=0;ll j=n-1;
      |                     ^
      |                     yn
a.cc:21:9: error: expected unqualified-id before 'if'
   21 |         if(a[n-1]>0&&k&1){
      |         ^~
a.cc:25:9: error: 'k' does not name a type
   25 |         k=k>>1;
      |         ^
a.cc:26:9: error: expected unqualified-id before 'for'
   26 |         for(ll itr=0;itr<k;itr++){
      |         ^~~
a.cc:26:22: error: 'itr' does not name a type
   26 |         for(ll itr=0;itr<k;itr++){
      |                      ^~~
a.cc:26:28: error: 'itr' does not name a type
   26 |         for(ll itr=0;itr<k;itr++){
      |                            ^~~
a.cc:38:9: error: expected unqualified-id before 'if'
   38 |         if(prod<0) cout<<((prod%mod)+mod)%mod;
      |         ^~
a.cc:39:9: error: expected unqualified-id before 'else'
   39 |         else cout<<prod%mod;
      |         ^~~~
a.cc:40:1: error: expected declaration before '}' token
   40 | }
      | ^