Language: Java

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

// snukeさんのmodint
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// mint N;
//cout << N.x << endl;



int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N,K;
  cin >> N >> K;
  vector<ll> pl;
  vector<ll> mn;
  bool zero = false;
  for(int i=0; i<N; i++){
    ll a;
    cin >> a;
    if(a > 0){
      pl.emplace_back(a);
    }else if(a < 0){
      mn.emplace_back(a);
    }else{
      zero = true;
    }
  }
  if(pl.size() + mn.size() < K){
    cout << 0 << "\n";
    return 0;
  }
  if(pl.size() == 0){
    if(mn.size() < K){
      cout << 0 << "\n";
      return 0;
    }
    if(K%2){
      if(zero){
        cout << 0 << "\n";
        return 0;
      }
      sort(mn.begin(),mn.end());
    }else{
      sort(mn.rbegin(),mn.rend());
    }
    mint ans = 1;
    for(int i=0; i<K; i++){
      ans *= mn[i];
    }
    cout << ans.x << "\n";
    return 0;
  }
  sort(pl.rbegin(),pl.rend());
  vector<mint> S(pl.size()+1,1);
  for(int i=0; i<pl.size(); i++){
    S[i+1] *= pl[i];
  }
  sort(mn.rbegin(),mn.rend());
  mint ans = 0;
  mint now = 1;
  for(int i=0; i<mn.size(); i+=2){
    if(i > K) break;
    if(i){
      now *= mn[i-2];
      now *= mn[i-1];
    }
    if(i+pl.size() < K) continue;
  }
  cout << ans.x << "\n";
  return 0;
}

Compiler output:
Main.java:1: error: illegal character: '#'
#include <iostream> // cout, endl, cin
^
Main.java:2: error: illegal character: '#'
#include <string> // string, to_string, stoi
^
Main.java:3: error: illegal character: '#'
#include <vector> // vector
^
Main.java:4: error: illegal character: '#'
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
^
Main.java:5: error: illegal character: '#'
#include <utility> // pair, make_pair
^
Main.java:6: error: illegal character: '#'
#include <tuple> // tuple, make_tuple
^
Main.java:7: error: illegal character: '#'
#include <cstdint> // int64_t, int*_t
^
Main.java:8: error: illegal character: '#'
#include <cstdio> // printf
^
Main.java:9: error: illegal character: '#'
#include <map> // map
^
Main.java:10: error: illegal character: '#'
#include <queue> // queue, priority_queue
^
Main.java:11: error: illegal character: '#'
#include <set> // set
^
Main.java:12: error: illegal character: '#'
#include <stack> // stack
^
Main.java:13: error: illegal character: '#'
#include <deque> // deque
^
Main.java:14: error: illegal character: '#'
#include <unordered_map> // unordered_map
^
Main.java:15: error: illegal character: '#'
#include <unordered_set> // unordered_set
^
Main.java:16: error: illegal character: '#'
#include <bitset> // bitset
^
Main.java:17: error: illegal character: '#'
#include <cctype> // isupper, islower, isdigit, toupper, tolower
^
Main.java:18: error: illegal character: '#'
#include <iomanip> // setprecision
^
Main.java:19: error: illegal character: '#'
#include <complex> // complex
^
Main.java:20: error: illegal character: '#'
#include <math.h> 
^
Main.java:21: error: illegal character: '#'
#include <climits> 
^
Main.java:22: error: illegal character: '#'
#include <assert.h>
^
Main.java:23: error: illegal character: '#'
#include <random>
^
Main.java:24: error: illegal character: '#'
#define rep(i,n) for(int i=0; i<(n); i++)
^
Main.java:24: error: class, interface, enum, or record expected
#define rep(i,n) for(int i=0; i<(n); i++)
                              ^
Main.java:24: error: class, interface, enum, or record expected
#define rep(i,n) for(int i=0; i<(n); i++)
                                     ^
Main.java:26: error: unnamed classes are a preview feature and are disabled by default.
using ll = long long;
^
  (use --enable-preview to enable unnamed classes)
Main.java:26: error: '.class' expected
using ll = long long;
                ^
Main.java:27: error: '.class' expected
using P = pair<int,int>;
                  ^
Main.java:27: error: <identifier> expected
using P = pair<int,int>;
                   ^
Main.java:28: error: class, interface, enum, or record expected
constexpr ll INF = 1e18;
^
Main.java:29: error: class, interface, enum, or record expected
constexpr int inf = 1e9;
^
Main.java:30: error: class, interface, enum, or record expected
constexpr ll mod = 1000000007;
^
Main.java:31: error: class, interface, enum, or record expected
constexpr ll mod2 = 998244353;
^
Main.java:32: error: class, interface, enum, or record expected
const double PI = 3.1415926535897932384626433832795028841971;
^
Main.java:33: error: class, interface, enum, or record expected
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
^
Main.java:34: error: class, interface, enum, or record expected
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
^
Main.java:35: error: class, interface, enum, or record expected
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
^
Main.java:35: error: '{' expected
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
                ^
Main.java:35: error: illegal start of type
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
                                                 ^
Main.java:35: error: > or ',' expected
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
                                                          ^
Main.java:35: error: illegal start of type
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
                                                                                 ^
Main.java:36: error: class, interface, enum, or record expected
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
^
Main.java:36: error: '{' expected
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
                ^
Main.java:36: error: illegal start of type
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
                                                 ^
Main.java:36: error: <identifier> expected
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
                                                      ^
Main.java:36: error: <identifier> expected
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
                                                          ^
Main.java:36: error: illegal start of type
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
                                                                                 ^
Main.java:40: error: class, interface, enum, or record expected
struct mint {
^
Main.java:42: error: class, interface, enum, or record expected
  mint(ll x=0):x((x%mod+mod)%mod){}
  ^
Main.java:45: error: class, interface, enum, or record expected
    return *this;
    ^
Main.java:46: error: class, interface, enum, or record expected
  }
  ^
Main.java:49: error: class, interface, enum, or record expected
    return *this;
    ^
Main.java:50: error: class, interface, enum, or record expected
  }
  ^
Main.java:53: error: class, interface, enum, or record expected
    return *this;
    ^
Main.java:54: error: class, interface, enum, or record expected
  }
  ^
Main.java:57: error: class, interface, enum, or record expected
    return res+=a;
    ^
Main.java:58: error: class, interface, enum, or record expected
  }
  ^
Main.java:61: error: class, interface, enum, or record expected
    return res-=a;
    ^
Main.java:62: error: class, interface, enum, or record expected
  }
  ^
Main.java:65: error: class, interface, enum, or record expected
    return res*=a;
    ^
Main.java:66: error: class, interface, enum, or record expected
  }
  ^
Main.java:70: error: class, interface, enum, or record expected
    a *= a;
    ^
Main.java:71: error: class, interface, enum, or record expected
    if (t&1) a *= *this;
    ^
Main.java:72: error: class, interface, enum, or record expected
    return a;
    ^
Main.java:73: error: class, interface, enum, or record expected
  }
  ^
Main.java:78: error: class, interface, enum, or record expected
  }
  ^
Main.java:81: error: class, interface, enum, or record expected
  }
  ^
Main.java:84: error: class, interface, enum, or record expected
    return res/=a;
    ^
Main.java:85: error: class, interface, enum, or record expected
  }
  ^
Main.java:94: error: not a statement
  ios::sync_with_stdio(false);
  ^
Main.java:97: error: not a statement
  cin >> N >> K;
           ^
Main.java:103: error: not a statement
    cin >> a;
        ^
Main.java:113: error: not a statement
    cout << 0 << "\n";
              ^
Main.java:118: error: not a statement
      cout << 0 << "\n";
                ^
Main.java:123: error: not a statement
        cout << 0 << "\n";
                  ^
Main.java:134: error: not a statement
    cout << ans.x << "\n";
                  ^
Main.java:138: error: not a statement
  vector<mint> S(pl.size()+1,1);
                          ^
Main.java:153: error: not a statement
  cout << ans.x << "\n";
                ^
Main.java:94: error: ';' expected
  ios::sync_with_stdio(false);
                      ^
Main.java:138: error: ';' expected
  vector<mint> S(pl.size()+1,1);
                ^
Main.java:138: error: ';' expected
  vector<mint> S(pl.size()+1,1);
                            ^
82 errors