Language: C++

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

typedef long long int ll;
typedef vector<int> vi;			typedef vector<ll> vl;
typedef vector<vi> vvi; 		typedef vector<vl> vvl;
typedef pair<int, int> 	pii;	typedef pair<ll, ll> pll;
typedef vector<pii> vii; 		typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
const ll INFL = 1e18;
const int INFI = 1e9;
#ifdef KARAN
	#include "../../trace.h"
#else
    #define trace(args...)
#endif

ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}
ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

bool compare(ll a, ll b){
	return abs(a)>abs(b);
}

bool compare1(ll a, ll b){
	return abs(a)<abs(b);
}

void solve(){
	ll n, k; cin>>n>>k;
	ll cntr = 0;
	vl a(n);
	forn(i, n) cin>>a[i];
	sort(all(a), compare1);
	vl b;
	forn(i, n) if(a[i]!=0) b.pb(a[i]); else cntr++;

	sort(b.begin(), b.end(), compare);

	ll answer = 1;
	ll cntneg = 0;
	ll cntpos = 0;
	ll smallneg = 1e9+10;
	ll smallpos = 1e9+10;

	trace(b);
	forn(i, min(k, sz(b))){
		answer = ((answer*b[i])%MOD+MOD)%MOD;
		if(b[i]<0) cntneg++;
		if(b[i]>0) cntpos++;
		if(b[i]<0) smallneg = min(smallneg, abs(b[i]));
		else smallpos = min(smallpos, abs(b[i]));
	}

	trace(answer, cntneg);
	if(k>b.size()||(k==b.size()&&cntneg%2&&cntr)){
		cout<<0<<endl; return;
	}
	if(k==b.size()||(cntneg%2==0)){
		cout<<answer<<endl;
		return;
	}

	ll largeneg = 0, largepos = 0;
	ll cntlneg = 0, cntlpos = 0;  
	forse(i, k, sz(b)){
		if(b[i]>0) largepos = max(largepos, b[i]), cntlpos++;
		else largeneg = max(largeneg, abs(b[i])), cntlneg++;
	}

	trace(smallneg, smallpos, cntneg, cntpos);
	trace(largeneg, largepos, cntlneg, cntlpos);

	if(cntlneg>0&&cntpos>0&&(largeneg*smallneg>=largepos*smallpos)){
		answer = (answer*modinv(smallpos))%MOD;
		answer = (answer*largeneg)%MOD;
		answer = (MOD - answer)%MOD;
		cout<<answer<<endl;
		return;
	}
	else if(cntlpos>0&&cntneg>0&&(largeneg*smallneg<=largepos*smallpos)){
		answer = (answer*modinv(smallneg))%MOD;
		answer = (answer*largepos)%MOD;	
		answer = (MOD-answer)%MOD;
		cout<<answer<<endl; 
		return;
	}
	else{
		trace("Here");
		answer = 1;
		forn(i, k) answer = ((answer*a[i])%MOD+MOD)%MOD;
		cout<<answer<<endl;
		return;
	}
	assert(1<0);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef KARAN
		freopen("inp.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    	freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	// cin>>t;
	while(t--)
		solve();
}#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef vector<int> vi;			typedef vector<ll> vl;
typedef vector<vi> vvi; 		typedef vector<vl> vvl;
typedef pair<int, int> 	pii;	typedef pair<ll, ll> pll;
typedef vector<pii> vii; 		typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
const ll INFL = 1e18;
const int INFI = 1e9;
#ifdef KARAN
	#include "../../trace.h"
#else
    #define trace(args...)
#endif

ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}
ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

bool compare(ll a, ll b){
	return abs(a)>abs(b);
}

bool compare1(ll a, ll b){
	return abs(a)<abs(b);
}

void solve(){
	ll n, k; cin>>n>>k;
	ll cntr = 0;
	vl a(n);
	forn(i, n) cin>>a[i];
	sort(all(a), compare1);
	vl b;
	forn(i, n) if(a[i]!=0) b.pb(a[i]); else cntr++;

	sort(b.begin(), b.end(), compare);

	ll answer = 1;
	ll cntneg = 0;
	ll cntpos = 0;
	ll smallneg = 1e9+10;
	ll smallpos = 1e9+10;

	trace(b);
	forn(i, min(k, sz(b))){
		answer = ((answer*b[i])%MOD+MOD)%MOD;
		if(b[i]<0) cntneg++;
		if(b[i]>0) cntpos++;
		if(b[i]<0) smallneg = min(smallneg, abs(b[i]));
		else smallpos = min(smallpos, abs(b[i]));
	}

	trace(answer, cntneg);
	if(k>b.size()||(k==b.size()&&cntneg%2&&cntr)){
		cout<<0<<endl; return;
	}
	if(k==b.size()||(cntneg%2==0)){
		cout<<answer<<endl;
		return;
	}

	ll largeneg = 0, largepos = 0;
	ll cntlneg = 0, cntlpos = 0;  
	forse(i, k, sz(b)){
		if(b[i]>0) largepos = max(largepos, b[i]), cntlpos++;
		else largeneg = max(largeneg, abs(b[i])), cntlneg++;
	}

	trace(smallneg, smallpos, cntneg, cntpos);
	trace(largeneg, largepos, cntlneg, cntlpos);

	if(cntlneg>0&&cntpos>0&&(largeneg*smallneg>=largepos*smallpos)){
		answer = (answer*modinv(smallpos))%MOD;
		answer = (answer*largeneg)%MOD;
		answer = (MOD - answer)%MOD;
		cout<<answer<<endl;
		return;
	}
	else if(cntlpos>0&&cntneg>0&&(largeneg*smallneg<=largepos*smallpos)){
		answer = (answer*modinv(smallneg))%MOD;
		answer = (answer*largepos)%MOD;	
		answer = (MOD-answer)%MOD;
		cout<<answer<<endl; 
		return;
	}
	else{
		trace("Here");
		answer = 1;
		forn(i, k) answer = ((answer*a[i])%MOD+MOD)%MOD;
		cout<<answer<<endl;
		return;
	}
	assert(1<0);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef KARAN
		freopen("inp.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    	freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	// cin>>t;
	while(t--)
		solve();
}

Compiler output:
a.cc:142:2: error: stray '#' in program
  142 | }#include <bits/stdc++.h>
      |  ^
a.cc:142:3: error: 'include' does not name a type
  142 | }#include <bits/stdc++.h>
      |   ^~~~~~~
a.cc:177:10: error: redefinition of 'const ll INFL'
  177 | const ll INFL = 1e18;
      |          ^~~~
a.cc:36:10: note: 'const ll INFL' previously defined here
   36 | const ll INFL = 1e18;
      |          ^~~~
a.cc:178:11: error: redefinition of 'const int INFI'
  178 | const int INFI = 1e9;
      |           ^~~~
a.cc:37:11: note: 'const int INFI' previously defined here
   37 | const int INFI = 1e9;
      |           ^~~~
a.cc:185:4: error: redefinition of 'll div_floor(const ll&, const ll&)'
  185 | ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
      |    ^~~~~~~~~
a.cc:44:4: note: 'll div_floor(const ll&, const ll&)' previously defined here
   44 | ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
      |    ^~~~~~~~~
a.cc:186:4: error: redefinition of 'll div_ceil(const ll&, const ll&)'
  186 | ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}
      |    ^~~~~~~~
a.cc:45:4: note: 'll div_ceil(const ll&, const ll&)' previously defined here
   45 | ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}
      |    ^~~~~~~~
a.cc:187:4: error: redefinition of 'll modpow(ll, ll, ll)'
  187 | ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1;
      |    ^~~~~~
a.cc:46:4: note: 'll modpow(ll, ll, ll)' previously defined here
   46 | ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1;
      |    ^~~~~~
a.cc:189:4: error: redefinition of 'll bpow(ll, ll)'
  189 | ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
      |    ^~~~
a.cc:48:4: note: 'll bpow(ll, ll)' previously defined here
   48 | ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
      |    ^~~~
a.cc:190:4: error: redefinition of 'll modinv(ll, ll)'
  190 | ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
      |    ^~~~~~
a.cc:49:4: note: 'll modinv(ll, ll)' previously defined here
   49 | ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
      |    ^~~~~~
a.cc:191:6: error: redefinition of 'void graph(vvi&, int)'
  191 | void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}
      |      ^~~~~
a.cc:50:6: note: 'void graph(vvi&, int)' previously defined here
   50 | void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}
      |      ^~~~~
a.cc:193:6: error: redefinition of 'bool compare(ll, ll)'
  193 | bool compare(ll a, ll b){
      |      ^~~~~~~
a.cc:52:6: note: 'bool compare(ll, ll)' previously defined here
   52 | bool compare(ll a, ll b){
      |      ^~~~~~~
a.cc:197:6: error: redefinition of 'bool compare1(ll, ll)'
  197 | bool compare1(ll a, ll b){
      |      ^~~~~~~~
a.cc:56:6: note: 'bool compare1(ll, ll)' previously defined here
   56 | bool compare1(ll a, ll b){
      |      ^~~~~~~~
a.cc:201:6: error: redefinition of 'void solve()'
  201 | void solve(){
      |      ^~~~~
a.cc:60:6: note: 'void solve()' previously defined here
   60 | void solve(){
      |      ^~~~~
a.cc:270:5: error: redefinition of 'int main()'
  270 | int main(){
      |     ^~~~
a.cc:129:5: note: 'int main()' previously defined here
  129 | int main(){
      |     ^~~~