Language: C++

#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)
#define large pow(10,9)+7

//template functions
/////////////////////////
long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}
long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}
/////////////////////////



//Answer


int main() {

long count;
long N,K;
long minuscount=0;
cin>>N>>K;
long multi=1;

vector<long> A(N);

for(long i=0;i<N;i++){
cin>>A.at(i);
    if(A.at(i)<0){
        minuscount++;
    }
}

sort(A.begin(),A.end());
reverse(A.begin(),A.end());

vector<long> B(N);
vector<pair<int,int>> C(N);

if((minuscount==N&&K%2==1)||(N==K&&minuscount%2==1)){
    for(long i=0;i<N-minuscount;i++){
        B.at(i)=A.at(i);
    }
    for(long i=0;i<minuscount;i++){
        B.at(i)=(-1)*A.at(N-minusount+i)
    }

sort(B.begin(),B.end());

    for(long i=0;i<K;i++){
        multi=(B.at(i)*multi)%large;
    }
Answer=large-multi;
cout<<Answer<<endl;

}else{

    for(long i=0;i<N-minuscount;i++){
        C.at(i).first=A.at(i);
        C.at(i).second=0;
    }
    for(long i=0;i<minuscount;i++){
        C.at(i)=(-1)*A.at(N-minusount+i)
        C.at(i).second=1;
    }

sort(C.begin(),C.end());
int last;
int number;

    for(long i=0;i<K;i++){
        if(C.at(i).second==1){
            last=multi;
            number=i;
        }
        multi=(C.at(i).first*multi)%large;
    }


if(multi<0){
    for(long i=number+1;i<K;i++){
        multi=(C.at(i).first*last)%large;
    }
}

    for(long i=K;i<N;i++){
        if(C.at(i).second>0){
            multi=(C.at(i).first*multi)%large;
            break;
        }
    }

long A1=multi;



    for(long i=0;i<K;i++){
        if(C.at(i).second==0){
            last=multi;
            number=i;
        }
        multi=(C.at(i).first*multi)%large;
    }


if(multi<0){
    for(long i=number+1;i<K;i++){
        multi=(C.at(i).first*last)%large;
    }
}

    for(long i=K;i<N;i++){
        if(C.at(i).second>0){
            multi=(C.at(i).first*multi)%large;
            break;
        }
    }

long A2=multi;

cout<<max(A1,A2)<<endl;

}







Compiler output:
a.cc: In function 'int main()':
a.cc:60:29: error: 'minusount' was not declared in this scope; did you mean 'minuscount'?
   60 |         B.at(i)=(-1)*A.at(N-minusount+i)
      |                             ^~~~~~~~~
      |                             minuscount
a.cc:66:30: error: invalid operands of types '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'} and '__gnu_cxx::__promote<double>::__type' {aka 'double'} to binary 'operator%'
   66 |         multi=(B.at(i)*multi)%large;
      |               ~~~~~~~~~~~~~~~^
      |                       |
      |                       __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type {aka long int}
a.cc:68:1: error: 'Answer' was not declared in this scope
   68 | Answer=large-multi;
      | ^~~~~~
a.cc:78:29: error: 'minusount' was not declared in this scope; did you mean 'minuscount'?
   78 |         C.at(i)=(-1)*A.at(N-minusount+i)
      |                             ^~~~~~~~~
      |                             minuscount
a.cc:91:36: error: invalid operands of types 'long int' and '__gnu_cxx::__promote<double>::__type' {aka 'double'} to binary 'operator%'
   91 |         multi=(C.at(i).first*multi)%large;
      |               ~~~~~~~~~~~~~~~~~~~~~^
      |                             |
      |                             long int
a.cc:97:35: error: invalid operands of types 'int' and '__gnu_cxx::__promote<double>::__type' {aka 'double'} to binary 'operator%'
   97 |         multi=(C.at(i).first*last)%large;
      |               ~~~~~~~~~~~~~~~~~~~~^
      |                             |
      |                             int
a.cc:103:40: error: invalid operands of types 'long int' and '__gnu_cxx::__promote<double>::__type' {aka 'double'} to binary 'operator%'
  103 |             multi=(C.at(i).first*multi)%large;
      |                   ~~~~~~~~~~~~~~~~~~~~~^
      |                                 |
      |                                 long int
a.cc:117:36: error: invalid operands of types 'long int' and '__gnu_cxx::__promote<double>::__type' {aka 'double'} to binary 'operator%'
  117 |         multi=(C.at(i).first*multi)%large;
      |               ~~~~~~~~~~~~~~~~~~~~~^
      |                             |
      |                             long int
a.cc:123:35: error: invalid operands of types 'int' and '__gnu_cxx::__promote<double>::__type' {aka 'double'} to binary 'operator%'
  123 |         multi=(C.at(i).first*last)%large;
      |               ~~~~~~~~~~~~~~~~~~~~^
      |                             |
      |                             int
a.cc:129:40: error: invalid operands of types 'long int' and '__gnu_cxx::__promote<double>::__type' {aka 'double'} to binary 'operator%'
  129 |             multi=(C.at(i).first*multi)%large;
      |                   ~~~~~~~~~~~~~~~~~~~~~^
      |                                 |
      |                                 long int
a.cc:138:2: error: expected '}' at end of input
  138 | }
      |  ^
a.cc:32:12: note: to match this '{'
   32 | int main() {
      |            ^