Language: C++

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io  ios_base::sync_with_stdio(false), cin.tie(NULL),cout.tie(NULL)
int mod=1e9+7;
int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	return (a+b)%m;}
int sub(int a,int b,int m=mod){	return (a-b+m)%m;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}
int maxProductSubarrayOfSizeK(int A[], int n, int k)
{
    // sorting given input array
    sort(A, A + n);

    // variable to store final product of all element
    // of sub-sequence of size k
    int product = 1;

    // CASE I
    // If max element is 0 and
    // k is odd then max product will be 0
    if (A[n - 1] == 0 && (k & 1))
        return 0;

    // CASE II
    // If all elements are negative and
    // k is odd then max product will be
    // product of rightmost-subarray of size k
    if (A[n - 1] <= 0 && (k & 1)) {
        for (int i = n - 1; i >= n - k; i--){
            product = mul(product,A[i]);
            product=add(product,mod);
        }
        return product;
    }

    // else
    // i is current left pointer index
    int i = 0;

    // j is current right pointer index
    int j = n - 1;

    // CASE III
    // if k is odd and rightmost element in
    // sorted array is positive then it
    // must come in subsequence
    // Multiplying A[j] with product and
    // correspondingly changing j
    if (k & 1) {
        product = mul(product,A[j]);
        product=add(product,mod)
        j--;
        k--;
    }

    // CASE IV
    // Now k is even
    // Now we deal with pairs
    // Each time a pair is multiplied to product
    // ie.. two elements are added to subsequence each time
    // Effectively k becomes half
    // Hence, k >>= 1 means k /= 2
    k >>= 1;

    // Now finding k corresponding pairs
    // to get maximum possible value of product
    for (int itr = 0; itr < k; itr++) {

        // product from left pointers
        int left_product = mul(A[i] , A[i + 1]);

        // product from right pointers
        int right_product = mul(A[j] , A[j - 1]);

        // Taking the max product from two choices
        // Correspondingly changing the pointer's position
        if (left_product > right_product) {
            product =  mul(product,left_product);
            product=add(product,mod);
            i += 2;
        }
        else {
            product = mul(product,right_product);
            product=add(product,mod);
            j -= 2;
        }
    }

    // Finally return product
    return (product+mod)%mod;
}

int32_t main()
{
    io;
    int t;
    t=1;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        int A[n];
        for(int i=0;i<n;i++)
            cin>>A[i];
      cout << (maxProductSubarrayOfSizeK(A, n, k)+mod)%mod<<"\n";
    }
}


Compiler output:
a.cc: In function 'long long int maxProductSubarrayOfSizeK(long long int*, long long int, long long int)':
a.cc:61:33: error: expected ';' before 'j'
   61 |         product=add(product,mod)
      |                                 ^
      |                                 ;
   62 |         j--;
      |         ~