Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N,K;
  int l = 1;
   long long result = 1;
  cin >> N >> K;
    vector<int> A(N);
  vector<int> B(N);
  map<int, int>C;
  vector<int> D(N,1);
  for(int a = 0;a < N;a++){
    cin >> A[a];
    C[abs(A[a])] = A[a];
    B[a] = abs(A[a]);
  }
  sort(B.begin(),B.end());
  
  for(int a = 0;a < N;a++){
    
    if(C[B[a]] < 0)D[a] = -1;
    if(C[B[a]] == 0)D[a] = 0;
    if(D[a] == 1)l = 0;
  }
  if(K != N){
  if(l == 1){
   if(K % 2 == 0){
     for(int a = N-1;a >= N - K;a--){
    result *= B[a];
       result %= 1000000007;
     }
   }else{
    result *= -1;
     for(int a = 0;a < K;a++){
    result *= B[a];
       result %= 1000000007;
     }
     
   }
    
  }else{
  int k = 1;
    int n = -1;
  for(int a = N-1;a >= N - K + 1;a--){
    k *= D[a];
  }
    if(k == 1){
      int flag = 0;
      for(int a = N - K;a >= 0;a--){
        if(D[a] == 1){
           n = a;
          flag = 1;
          break;
        }
        
      }
      
      if(flag == 1){
        
        for(int a = N-1;a >= N - K + 1;a--){
    result *= B[a];
       result %= 1000000007;
     }
        result *= B[n];
        result %= 1000000007;
      }else{
        for(int a = N - K + 1;a < N;a++){
          if(D[a] == 1){
           n = a;
            break;
          }
          
        }
        for(int a = N-1;a >= N - K + 1;a--){
          if(a != n){
    result *= B[a];
       result %= 1000000007;
          }
     }
        result *= B[N - K];
        result %= 1000000007;
      }
        
      }else if(k == -1){
        
        
        
     
           
        
        
        int flag = 0;
      for(int a = N - K;a >= 0;a--){
        if(D[a] == -1){
           n = a;
          flag = 1;
          break;
        }
        
      }
      
      if(flag == 1){
        
        for(int a = N-1;a >= N - K + 1;a--){
    result *= B[a];
       result %= 1000000007;
     }
        result *= B[n];
        result %= 1000000007;
      }else{
        for(int a = N - K + 1;a < N;a++){
          if(D[a] == -1){
           n = a;
            break;
          }
          
        }
        for(int a = N-1;a >= N - K + 1;a--){
          if(a != n){
    result *= B[a];
       result %= 1000000007;
          }
     }
        result *= B[N - K];
        result %= 1000000007;
        
      }
        
        
        
        
      }
      
    
    
    
  }else{
   result = 0; 
    
    
  }
  }else{
    for(int a = 0;a < N;a++){
    result *= A[a];
       result %= 1000000007;
     }
    
  }
  result %= 1000000007;
 if(result < 0)result += 1000000007;
cout << result << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:138:4: error: expected '}' before 'else'
  138 |   }else{
      |    ^~~~
a.cc:26:13: note: to match this '{'
   26 |   if(K != N){
      |             ^
a.cc: At global scope:
a.cc:143:4: error: expected unqualified-id before 'else'
  143 |   }else{
      |    ^~~~
a.cc:150:3: error: 'result' does not name a type
  150 |   result %= 1000000007;
      |   ^~~~~~
a.cc:151:2: error: expected unqualified-id before 'if'
  151 |  if(result < 0)result += 1000000007;
      |  ^~
a.cc:152:1: error: 'cout' does not name a type
  152 | cout << result << endl;
      | ^~~~
a.cc:153:1: error: expected declaration before '}' token
  153 | }
      | ^