Language: C++

#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int mnm,k,cnt,tag;
long long a[200100],res,mod=1000000007,x1,x2,y1,y2;
deque<long long> n,nn;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>mnm>>k;
	res=1;
	for(int i=1;i<=mnm;i++) cin>>a[i];
	sort(a+1,a+mnm+1);
	for(int i=mnm;i>=1;i--) if(a[i]>=0) nn.push_back(a[i]);
	for(int i=1;i<=mnm;i++) if(a[i]<0) n.push_back(a[i]);
	if(mnm==k){
		for(int i=1;i<=mnm;i++) res=(res*a[i])%mod;
		cout<<res<<endl;
		return 0;
	}
	for(int N=0;N<=k;N+=2){
		if(n.size()>=N&&nn.size()>=(k-N)){
			while(1){
				x1=-1;x2=1;y1=-1;y2=1;
				if(nn.size()>=2){
					x1=nn.front();nn.pop_front();
					x2=nn.front();nn.pop_front();
				}
				if(nn.size()==1){
					x1=nn.front();nn.pop_front();
					tag=1;
				}
				if(n.size()>=2){
					y1=n.front();n.pop_front();
					y2=n.front();n.pop_front();
				}
				if((cnt==k-1)||(x1*x2>y1*y2)){
					res=(res*x1)%mod;
					if(!tag) nn.push_front(x2);
					n.push_front(y2);
					n.push_front(y1);
					cnt++;
				}
				else{
					res=((res*y1)%mod*y2)%mod;
					nn.push_front(x2);
					nn.push_front(x1);
					cnt+=2;
				}
				if(cnt==k) break;
			}
			cout<<res<<endl;
			return 0;
		}
	}
	for(int i=1;i<=mnm;i++) if(a[i]<0) a[i]*=-1LL;
	sort(a+1,a+mnm+1);
	for(int i=1;i<=k;i++) res=(res*a[i])%mod;
	cout<<mod-res<<endl;
	return 0;
}


Compiler output:
a.cc:10:46: error: 'long long int y1' redeclared as different kind of entity
   10 | long long a[200100],res,mod=1000000007,x1,x2,y1,y2;
      |                                              ^~
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683,
                 from /usr/include/c++/14/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:33,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:257:1: note: previous declaration 'double y1(double)'
  257 | __MATHCALL (y1,, (_Mdouble_));
      | ^~~~~~~~~~
a.cc: In function 'int main()':
a.cc:36:46: error: assignment of function 'double y1(double)'
   36 |                                 x1=-1;x2=1;y1=-1;y2=1;
      |                                            ~~^~~
a.cc:46:43: error: assignment of function 'double y1(double)'
   46 |                                         y1=n.front();n.pop_front();
      |                                         ~~^~~~~~~~~~
a.cc:49:57: error: invalid operands of types 'double(double) noexcept' and 'long long int' to binary 'operator*'
   49 |                                 if((cnt==k-1)||(x1*x2>y1*y2)){
      |                                                       ~~^~~
      |                                                       |  |
      |                                                       |  long long int
      |                                                       double(double) noexcept
a.cc:53:53: error: no matching function for call to 'push_front(double (&)(double) noexcept)'
   53 |                                         n.push_front(y1);
      |                                         ~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/14/deque:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:139:
/usr/include/c++/14/bits/stl_deque.h:1501:7: note: candidate: 'void std::deque<_Tp, _Alloc>::push_front(const value_type&) [with _Tp = long long int; _Alloc = std::allocator<long long int>; value_type = long long int]' (near match)
 1501 |       push_front(const value_type& __x)
      |       ^~~~~~~~~~
/usr/include/c++/14/bits/stl_deque.h:1501:7: note:   conversion of argument 1 would be ill-formed:
a.cc:53:54: error: invalid conversion from 'double (*)(double) noexcept' to 'std::deque<long long int>::value_type' {aka 'long long int'} [-fpermissive]
   53 |                                         n.push_front(y1);
      |                                                      ^~
      |                                                      |
      |                                                      double (*)(double) noexcept
/usr/include/c++/14/bits/stl_deque.h:1516:7: note: candidate: 'void std::deque<_Tp, _Alloc>::push_front(value_type&&) [with _Tp = long long int; _Alloc = std::allocator<long long int>; value_type = long long int]' (near match)
 1516 |       push_front(value_type&& __x)
      |       ^~~~~~~~~~
/usr/include/c++/14/bits/stl_deque.h:1516:7: note:   conversion of argument 1 would be ill-formed:
a.cc:53:54: error: invalid conversion from 'double (*)(double) noexcept' to 'std::deque<long long int>::value_type' {aka 'long long int'} [-fpermissive]
   53 |                                         n.push_front(y1);
      |                                                      ^~
      |                                                      |
      |                                                      double (*)(double) noexcept
a.cc:57:50: error: invalid operands of types 'long long int' and 'double(double) noexcept' to binary 'operator*'
   57 |                                         res=((res*y1)%mod*y2)%mod;
      |                                               ~~~^~~
      |                                               |   |
      |                                               |   double(double) noexcept
      |                                               long long int