Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=1000000007,BS,k;

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
        ll n,k;cin>>n>>k;ll num;
        vector<ll> o,e;
        for(ll i=0;i<n;i++){
            cin>>num;
            if(num<0)
            o.push_back(num);
            else
            e.push_back(num);
        }
        sort(o.begin(),o.end());
        sort(e.begin(),e.end());
        reverse(e.begin(),e.end());
        ll u=0,d=0,lef=k,nn,nn1,ee=0,oo=0;double compa;vector<ll> ans;nn=o.size();nn1=e.size();
        // cout<<nn1<<" ";
        ll flg=0;
        if(nn==0){
            for(ll i=0;i<k;i++)ans.push_back(e[i]);
        }
        else if(nn1==0){
            if(k%2)
            for(ll i=0;i<k;i++)ans.push_back(o[n-1-i]);
            else
            for(ll i=0;i<k;i++)ans.push_back(o[i]);
        }
        else{
            if(k%2){
                nn1--;
                while(lef){
                    if(lef==1){
                        if(nn1+1-d){
                            if(lef)
                            ans.push_back(e[d]),lef--;
                            if(lef)
                            ans.push_back(e[d+1]),lef--;
                            break;
                        }
                        else{
                            if(lef)
                            ans.push_back(e[d]),lef--;
                            if(lef)
                            ans.push_back(o[nn-1]);
                            break;
                        }
                    }
                if(u+1<nn&&d+1<nn1){
                    if(e[d]==0||e[d+1]==0){
                        ans.push_back(o[u]);
                        ans.push_back(o[u+1]);
                        lef-=2;u+=2;
                        continue;
                    }
                    compa=(o[u]*o[u+1])/(e[d]*e[d+1]);
                    if(compa>=1.0)
                    {
                        ans.push_back(o[u]);
                        ans.push_back(o[u+1]);
                        lef-=2;u+=2;
                    }
                    else{
                        ans.push_back(e[d]);
                        ans.push_back(e[d+1]);
                        lef-=2;d+=2;
                    }
                }
                else if(u+1<nn){
                    ans.push_back(o[u]);
                    ans.push_back(o[u+1]);
                    lef-=2;u+=2;
                }
                else if(d+1<nn1){
                    ans.push_back(e[d]);
                    ans.push_back(e[d+1]);
                    lef-=2;d+=2;
                }
                else{
                    if(nn1+1-d){
                        if(lef)
                        ans.push_back(e[d]),lef--;
                        if(lef)
                        ans.push_back(e[d+1]),lef--;
                        break;
                    }
                    else{
                        if(lef)
                        ans.push_back(e[d]),lef--;
                        if(lef)
                        ans.push_back(o[nn-1]);
                        break;
                    }
                }
            }}
            else{
                if(nn1>1){
                    while(lef){
                        if(u+1<nn&&d+1<nn1){
                            if(e[d]==0||e[d+1]==0){
                                ans.push_back(o[u]);
                                ans.push_back(o[u+1]);
                                lef-=2;u+=2;
                                continue;
                            }
                            compa=(o[u]*o[u+1])/(e[d]*e[d+1]);
                            if(compa>=1.0)
                            {
                                ans.push_back(o[u]);
                                ans.push_back(o[u+1]);
                                lef-=2;u+=2;
                            }
                            else{
                                ans.push_back(e[d]);
                                ans.push_back(e[d+1]);
                                lef-=2;d+=2;
                            }
                        }
                        else if(u+1<nn){
                            ans.push_back(o[u]);
                            ans.push_back(o[u+1]);
                            lef-=2;u+=2;
                        }
                        else{
                            ans.push_back(e[d]);
                            ans.push_back(e[d+1]);
                            lef-=2;d+=2;
                        }
                    }
                }
                else{
                    for(ll i=0;i<k;i++)ans.push_back(o[i]);break;
                }
            }
        }}
        ll res=1;
        // for(auto it:ans)cout<<it<<" ";
        for(auto it:ans){
            res=(res*it)%mod;
            res=(res+mod)%mod;
        }
        cout<<res;


}


Compiler output:
a.cc: In function 'int main()':
a.cc:140:60: error: break statement not within loop or switch
  140 |                     for(ll i=0;i<k;i++)ans.push_back(o[i]);break;
      |                                                            ^~~~~
a.cc: At global scope:
a.cc:146:9: error: expected unqualified-id before 'for'
  146 |         for(auto it:ans){
      |         ^~~
a.cc:150:9: error: 'cout' does not name a type
  150 |         cout<<res;
      |         ^~~~
a.cc:153:1: error: expected declaration before '}' token
  153 | }
      | ^