Language: C++

#include<bits/stdc++.h>

using namespace std;
 
// Competetive Template:
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
typedef pair <lli,lli> pll;
typedef pair <lli,string> pls;
typedef pair <lli,lli> pll;

typedef vector <lli> vl;
typedef vector <pll> vll;
typedef vector <string> vs;
typedef vector <char> vc;

typedef set <lli> sl;

typedef map <lli, lli> mll;
typedef map <pll, lli> mpll;
typedef map <string, lli> msl;

typedef priority_queue <lli> max_heap ;
typedef priority_queue < lli, vector<lli> , greater<lli> > min_heap;

// Debugging :
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define pb push_back 
#define pf push_front
#define in insert 
#define popb pop_back
#define popf pop_front
#define ba  back
#define si size()
#define be begin()
#define en end()
#define le length()
#define lb lower_bound
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define deb debug
#define all(v) v.be, v.en
#define INF LLONG_MAX
const ldb PI = acos(-1.0);

#define forz(i, n) for (int i = 0; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)

#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rfore(i, m, n) for (int i = n; i >= m; i--)

#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353

// Printing Data :
#define pvec(v) forz(i,v.si) cout<<v[i]<<" "; cout<<endl;
#define parr(arr, n) forz(i,n) cout<<arr[i]<<" "; cout<<endl;

#define p1(i) cout<<i<<endl
#define p2(i, j) cout<<i<<" "<<j<<endl
#define p3(i, j, k) cout<<i<<" "<<j<<" "<<k<<endl
#define p4(i, j, k, l) cout<<i<<" "<<j<<" "<<k<<" "<<l<<endl

// Exponentiation in O(log y)
lli power(lli x,lli y){lli res=1; x=x;while(y>0){if(y&1) res=(res*x);y=y>>1;x=(x*x);}return res;} 

// Modular Exponentiation in O(log y)
lli power(lli x,lli y,lli p){lli res=1; x=x%p;while(y>0){if(y&1) res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 

// Euclidean gcd
lli gcd(lli a, lli b) { if (a==0) return b; return gcd(b % a, a);}

// Required function 

string multiply(string num1, string num2) 
{ 
    int len1 = num1.size(); 
    int len2 = num2.size(); 
    if (len1 == 0 || len2 == 0) 
    return "0"; 
  
    vector<int> result(len1 + len2, 0); 
  
    int i_n1 = 0;  
    int i_n2 = 0;  
      
    // Go from right to left in num1 
    for (int i=len1-1; i>=0; i--) 
    { 
        int carry = 0; 
        int n1 = num1[i] - '0'; 
  
        // To shift position to left after every 
        // multiplication of a digit in num2 
        i_n2 = 0;  
          
        // Go from right to left in num2              
        for (int j=len2-1; j>=0; j--) 
        { 
            // Take current digit of second number 
            int n2 = num2[j] - '0'; 
  
            // Multiply with current digit of first number 
            // and add result to previously stored result 
            // at current position.  
            int sum = n1*n2 + result[i_n1 + i_n2] + carry; 
  
            // Carry for next iteration 
            carry = sum/10; 
  
            // Store result 
            result[i_n1 + i_n2] = sum % 10; 
  
            i_n2++; 
        } 
  
        // store carry in next cell 
        if (carry > 0) 
            result[i_n1 + i_n2] += carry; 
  
        // To shift position to left after every 
        // multiplication of a digit in num1. 
        i_n1++; 
    } 
  
    // ignore '0's from the right 
    int i = result.size() - 1; 
    while (i>=0 && result[i] == 0) 
    i--; 
  
    // If all were '0's - means either both or 
    // one of num1 or num2 were '0' 
    if (i == -1) 
    return "0"; 
  
    // generate the result string 
    string s = ""; 
      
    while (i >= 0) 
        s += std::to_string(result[i--]); 
  
    return s; 
} 

string fx(lli n)
{
    if(n==0)
    {
        string t="0";
        return t;
    }

    string res;
    while(n!=0) {res.pb((char)n%10+'0'); n/=10;}
    reverse(all(res));
    return res;
}

bool cmp(string a, string b)
{
    if(a.le>b.le) return true;

    for(int i = 0; i < a.length(); ++i)
    if ((a[i] - '0') < (b[i] - '0'))
    { 
        return false;
    }

    return true;
}

lli maxProductSubarrayOfSizeK(lli A[], lli n, lli k) 
{ 
	sort(A, A + n); 

	lli product = 1; 

	if (A[n - 1] == 0 && (k & 1)) 
		return 0; 

	if (A[n - 1] <= 0 && (k & 1)) { 
		for (int i = n - 1; i >= n - k; i--) 
			product = (product%mod A[i]%mod)%mod; 
		return product; 
	} 


	lli i=0, j=n-1;
 
	if (k & 1) { 
		product *= A[j]; 
		j--; 
		k--; 
	} 

	k >>= 1; 
 
	for (lli itr = 0; itr < k; itr++) { 

        lli x1 = A[i];
        lli x2 = A[i+1];
        lli x3 = A[j];
        lli x4 = A[j-1];

        string y1 = fx(x1);
        string y2 = fx(x2);
        string y3 = fx(x3);
        string y4 = fx(x4);

        string t1 = multiply(y1, y2);
        string t2 = multiply(y3, y4);
        
        // Returns t1>t2
        bool bo = cmp(t1, t2);

		if (bo) { 
			product = (product%mod * (A[i]%mod * A[i + 1]%mod)%mod)%mod; 
			i += 2; 
		} 
		else { 
			product = (product%mod * (A[j]%mod * A[j - 1]%mod)%mod)%mod; 
			j -= 2; 
		} 
	} 

	return product; 
} 

// CODE BEGINS :
int main()
{
	ios::sync_with_stdio(0), cin.tie(0),cout.tie(0);

    lli n, k; cin>>n>>k;
    lli arr[n];
    forz(i,n) cin>>arr[i];

    lli res = maxProductSubarrayOfSizeK(arr, n, k);

    p1((res+mod)%mod);

    return 0;
}









































































































Compiler output:
a.cc: In function 'lli maxProductSubarrayOfSizeK(lli*, lli, lli)':
a.cc:216:48: error: expected ')' before 'A'
  216 |                         product = (product%mod A[i]%mod)%mod;
      |                                   ~            ^