Language: C++

#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("ride.in");ofstream coutt("ride.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 


signed main(){
    FASTER;
    int n,k;cin>>n>>k;
    int zero=0,pos=0,neg=0;
    vii v;
    for(int i=0;i<n;i++){
        int in;cin>>in;
        if(in>0)v.push_back({in,0}),pos++;
        if(in<0)v.push_back({-in,1}),neg++;
        if(in==0)zero++;
    }
    sort(all(v));
    reverse(all(v));
    
    if(pos+neg<k && zero){
        cout<<0;
        return 0;
    }
    
    int del=0,idn=-1,idp=-1;
    for(int i=0;i<k;i++){
        del+=v[i].second;
        if(v[i].second)idn=i;
        else idp=i;
    }
    
    if(del%2==0){
        int ans=1;
        for(int i=0;i<k;i++){
            ans=ans*v[i].first%MOD;
        }
        cout<<ans;
    }else{
        
        int id2p=-1,id2n=-1;
        for(int i=k;i<v.size();i++){
            if(v[i].second==0 && id2p==-1){
                id2p=i;
            }
            if(v[i].second==1 && id2n==-1){
                id2n=i;
            }
        }
        
        if(idp!=-1){
            if(id2p!=-1 && id2n!=-1){
                if(v[idn]*v[id2p]>v[idp]*v[id2n])swap(v[id2p],v[idn]);
                else swap(v[id2n],v[idp]);
                int ans=1;
                for(int i=0;i<k;i++){
                    ans=ans*v[i].first%MOD;
                }
                cout<<ans;
            }else if(id2p!=-1){
                swap(v[idn],v[id2p]);
                int ans=1;
                for(int i=0;i<k;i++){
                    ans=ans*v[i].first%MOD;
                }
                cout<<ans;
            }else if(id2n!=-1){
                swap(v[idp],v[id2n]);
                int ans=1;
                for(int i=0;i<k;i++){
                    ans=ans*v[i].first%MOD;
                }
                cout<<ans;
            }else{
                
                if(zero){
                    cout<<0;
                    return 0;
                }
                reverse(all(v));
                int ans=1;
                for(int i=0;i<k;i++)ans=ans*v[i].first%MOD;
                cout<<MOD-ans;
            
            }
        }else{
            
            if(id2p!=-1){
                swap(v[idn],v[id2p]);
                int ans=1;
                for(int i=0;i<k;i++){
                    ans=ans*v[i].first%MOD;
                }
                cout<<ans;
                
            }else{
            
                if(zero){
                    cout<<0;
                    return 0;
                }
                reverse(all(v));
                int ans=1;
                for(int i=0;i<k;i++)ans=ans*v[i].first%MOD;
                cout<<MOD-ans;
            
            }
        }
        
    }
    
}

Compiler output:
a.cc: In function 'int main()':
a.cc:77:26: error: no match for 'operator*' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} and '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'})
   77 |                 if(v[idn]*v[id2p]>v[idp]*v[id2n])swap(v[id2p],v[idn]);
In file included from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
                 from a.cc:1:
/usr/include/c++/14/complex:400:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const complex<_Tp>&, const complex<_Tp>&)'
  400 |     operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:400:5: note:   template argument deduction/substitution failed:
a.cc:77:33: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::complex<_Tp>'
   77 |                 if(v[idn]*v[id2p]>v[idp]*v[id2n])swap(v[id2p],v[idn]);
      |                                 ^
/usr/include/c++/14/complex:409:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const complex<_Tp>&, const _Tp&)'
  409 |     operator*(const complex<_Tp>& __x, const _Tp& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:409:5: note:   template argument deduction/substitution failed:
a.cc:77:33: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::complex<_Tp>'
   77 |                 if(v[idn]*v[id2p]>v[idp]*v[id2n])swap(v[id2p],v[idn]);
      |                                 ^
/usr/include/c++/14/complex:418:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const _Tp&, const complex<_Tp>&)'
  418 |     operator*(const _Tp& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/complex:418:5: note:   template argument deduction/substitution failed:
a.cc:77:33: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::complex<_Tp>'
   77 |                 if(v[idn]*v[id2p]>v[idp]*v[id2n])swap(v[id2p],v[idn]);
      |                                 ^
In file included from /usr/include/c++/14/valarray:605,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166:
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const _Expr<_Dom1, typename _Dom1::value_type>&, const _Expr<_Dom2, typename _Dom2::value_type>&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   template argument deduction/substitution failed:
a.cc:77:33: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   77 |                 if(v[idn]*v[id2p]>v[idp]*v[id2n])swap(v[id2p],v[idn]);
      |                                 ^
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const _Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   template argument deduction/substitution failed:
a.cc:77:33: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   77 |                 if(v[idn]*v[id2p]>v[idp]*v[id2n])swap(v[id2p],v[idn]);
      |                                 ^
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const typename _Dom::value_type&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   template argument deduction/substitution failed:
a.cc:77:33: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   77 |                 if(v[idn]*v[id2p]>v[idp]*v[id2n])swap(v[id2p],v[idn]);
      |                                 ^
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const _Expr<_Dom1, typename _Dom1::value_type>&, const valarray<typename _Dom::value_type>&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   template argument deduction/substitution failed:
a.cc:77:33: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   77 |                 if(v[idn]*v[id2p]>v[idp]*v[id2n])swap(v[id2p],v[idn]);
      |                                 ^
/usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const valarray<typename _Dom::value_type>&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  407 |     _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:407:5: note:   template argument deduction/substitution failed:
a.cc:77:33: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   77 |                 if(v[idn]*v[id2p]>v[idp]*v[id2n])swap(v[id2p],v[idn]);
      |                                 ^
/usr/include/c++/14/valarray:1198:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__multiplies, _Tp>::result_type> std::operator*(const valarray<_Tp>&, const valarray<_Tp>&)'
 1198 | _DEFINE_BINARY_OPERATOR(*, __multiplies)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1198:1: note:   template argument deduction/substitution failed:
a.cc:77:33: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::valarray<_Tp>'
   77 |                 if(v[idn]*v[id2p]>v[idp]*v[id2n])swap(v[id2p],v[idn]);
      |                                 ^
/usr/include/c++/14/valarray:1198:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_Constant, _Tp, _Tp>, typename std::__fun<std::__multiplies, _Tp>::result_type> std::operator*(const valarray<_Tp>&, const typename valarray<_Tp>::value_type&)'
 1198 | _DEFINE_BINARY_OPERATOR(*, __multiplies)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1198:1: note:   template argument deduction/substitution failed:
a.cc:77:33: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::valarray<_Tp>'
   77 |                 if(v[idn]*v[id2p]>v[idp]*v[id2n])swap(v[id2p],v[idn]);
      |                                 ^
/usr/include/c++/14/valarray:1198:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Constant, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__multiplies, _Tp>::result_type> std::operator*(const typename valarray<_Tp>::value_type&, const valarray<_Tp>&)'
 1198 | _DEFINE_BINARY_OPERATOR(*, __multiplies)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1198:1: note:   template argument deduction/substitution failed:
a.cc:77:33: note:   '__gnu_cxx::__alloc_traits<std::allocator<s