Language: Java

public class Main {
    long MOD = 1_000_000_007;

    void solve(Scanner sc, PrintWriter pw) {
        int N = sc.nextInt();
        int K = sc.nextInt();
        List<Integer> positive = new ArrayList<>();
        List<Integer> negative = new ArrayList<>();
        int zeroCount = 0;
        long totalProduct = 1L;
        for (int i = 0; i < N; i++) {
            int data = sc.nextInt();
            if (data == 0) {
                zeroCount++;
            } else if (data > 0) {
                positive.add(data);
                totalProduct = (totalProduct * data) % MOD;
            } else {
                negative.add(data);
                totalProduct = (totalProduct * data) % MOD;
            }
        }
        if (K % 2 == 0) {
            int positiveUsable = getEven(positive.size()) + getEven(negative.size());
            if (positiveUsable >= K) {
                positive.sort(Comparator.reverseOrder());
                Collections.sort(negative);
                List<Integer> total = new ArrayList<>(positive.subList(0, getEven(positive.size())));
                int negativeSize = getEven(negative.size());
                for (int j = 0; j < negativeSize; j++) {
                    total.add(-1 * negative.get(j));
                }
                total.sort(Collections.reverseOrder());
                long result = 1;
                for (int i = 0; i < K; i++) {
                    result = (result * total.get(i)) % MOD;
                }
                pw.println(result);
            } else {
                if (zeroCount > 0) {
                    pw.println("0");
                } else {
                    List<Integer> total = new ArrayList<>();
                    Collections.sort(positive);
                    negative.sort(Comparator.reverseOrder());
                    int pSize = getOdd(positive.size());
                    if (pSize >= 0) {
                        total.addAll(positive.subList(0, pSize));
                    }
                    int negativeSize = getOdd(negative.size());
                    for (int j = 0; j < negativeSize; j++) {
                        total.add(-1 * negative.get(j));
                    }
                    Collections.sort(total);
                    long result = -1;
                    for (int i = 0; i < K; i++) {
                        result = (result * total.get(i)) % MOD;
                    }
                    pw.println((result + MOD) % MOD);
                }
            }
        } else {
            int positiveUsable = getOdd(positive.size()) + getEven(negative.size());
            if (getOdd(positive.size()) >= 0 && positiveUsable >= K) {
                List<Integer> total = new ArrayList<>();
                positive.sort(Comparator.reverseOrder());
                Collections.sort(negative);
                int positiveSize = getOdd(positive.size());
                if (positiveSize > 0) {
                    total.addAll(positive.subList(0, positiveSize));
                }
                int negativeSize = getEven(negative.size());
                for (int j = 0; j < negativeSize; j++) {
                    total.add(-1 * negative.get(j));
                }
                total.sort(Collections.reverseOrder());
                long result = 1;
                for (int i = 0; i < K; i++) {
                    result = (result * total.get(i)) % MOD;
                }
                pw.println((result + MOD) % MOD);
            } else {
                if (zeroCount > 0) {
                    pw.println("0");
                } else {
                    List<Integer> total = new ArrayList<>();
                    Collections.sort(positive);
                    negative.sort(Comparator.reverseOrder());
                    total.addAll(positive.subList(0, getEven(positive.size())));
                    int negativeSize = getOdd(negative.size());
                    for (int j = 0; j < negativeSize; j++) {
                        total.add(-1 * negative.get(j));
                    }
                    Collections.sort(total);
                    long result = -1;
                    for (int i = 0; i < K; i++) {
                        result = (result * total.get(i)) % MOD;
                    }
                    pw.println((result + MOD) % MOD);
                }
            }
        }
    }

    private int getEven(int size) {
        return size - (size % 2);
    }

    private int getOdd(int size) {
        if (size == 0) {
            return -1;
        }
        return size - ((size % 2) == 0 ? 1 : 0);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        new Main().solve(sc, pw);
        pw.flush();
        pw.close();
        sc.close();
    }
}


Compiler output:
Main.java:4: error: cannot find symbol
    void solve(Scanner sc, PrintWriter pw) {
               ^
  symbol:   class Scanner
  location: class Main
Main.java:4: error: cannot find symbol
    void solve(Scanner sc, PrintWriter pw) {
                           ^
  symbol:   class PrintWriter
  location: class Main
Main.java:7: error: cannot find symbol
        List<Integer> positive = new ArrayList<>();
        ^
  symbol:   class List
  location: class Main
Main.java:7: error: cannot find symbol
        List<Integer> positive = new ArrayList<>();
                                     ^
  symbol:   class ArrayList
  location: class Main
Main.java:8: error: cannot find symbol
        List<Integer> negative = new ArrayList<>();
        ^
  symbol:   class List
  location: class Main
Main.java:8: error: cannot find symbol
        List<Integer> negative = new ArrayList<>();
                                     ^
  symbol:   class ArrayList
  location: class Main
Main.java:26: error: cannot find symbol
                positive.sort(Comparator.reverseOrder());
                              ^
  symbol:   variable Comparator
  location: class Main
Main.java:27: error: cannot find symbol
                Collections.sort(negative);
                ^
  symbol:   variable Collections
  location: class Main
Main.java:28: error: cannot find symbol
                List<Integer> total = new ArrayList<>(positive.subList(0, getEven(positive.size())));
                ^
  symbol:   class List
  location: class Main
Main.java:28: error: cannot find symbol
                List<Integer> total = new ArrayList<>(positive.subList(0, getEven(positive.size())));
                                          ^
  symbol:   class ArrayList
  location: class Main
Main.java:33: error: cannot find symbol
                total.sort(Collections.reverseOrder());
                           ^
  symbol:   variable Collections
  location: class Main
Main.java:43: error: cannot find symbol
                    List<Integer> total = new ArrayList<>();
                    ^
  symbol:   class List
  location: class Main
Main.java:43: error: cannot find symbol
                    List<Integer> total = new ArrayList<>();
                                              ^
  symbol:   class ArrayList
  location: class Main
Main.java:44: error: cannot find symbol
                    Collections.sort(positive);
                    ^
  symbol:   variable Collections
  location: class Main
Main.java:45: error: cannot find symbol
                    negative.sort(Comparator.reverseOrder());
                                  ^
  symbol:   variable Comparator
  location: class Main
Main.java:54: error: cannot find symbol
                    Collections.sort(total);
                    ^
  symbol:   variable Collections
  location: class Main
Main.java:65: error: cannot find symbol
                List<Integer> total = new ArrayList<>();
                ^
  symbol:   class List
  location: class Main
Main.java:65: error: cannot find symbol
                List<Integer> total = new ArrayList<>();
                                          ^
  symbol:   class ArrayList
  location: class Main
Main.java:66: error: cannot find symbol
                positive.sort(Comparator.reverseOrder());
                              ^
  symbol:   variable Comparator
  location: class Main
Main.java:67: error: cannot find symbol
                Collections.sort(negative);
                ^
  symbol:   variable Collections
  location: class Main
Main.java:76: error: cannot find symbol
                total.sort(Collections.reverseOrder());
                           ^
  symbol:   variable Collections
  location: class Main
Main.java:86: error: cannot find symbol
                    List<Integer> total = new ArrayList<>();
                    ^
  symbol:   class List
  location: class Main
Main.java:86: error: cannot find symbol
                    List<Integer> total = new ArrayList<>();
                                              ^
  symbol:   class ArrayList
  location: class Main
Main.java:87: error: cannot find symbol
                    Collections.sort(positive);
                    ^
  symbol:   variable Collections
  location: class Main
Main.java:88: error: cannot find symbol
                    negative.sort(Comparator.reverseOrder());
                                  ^
  symbol:   variable Comparator
  location: class Main
Main.java:94: error: cannot find symbol
                    Collections.sort(total);
                    ^
  symbol:   variable Collections
  location: class Main
Main.java:117: error: cannot find symbol
        Scanner sc = new Scanner(System.in);
        ^
  symbol:   class Scanner
  location: class Main
Main.java:117: error: cannot find symbol
        Scanner sc = new Scanner(System.in);
                         ^
  symbol:   class Scanner
  location: class Main
Main.java:118: error: cannot find symbol
        PrintWriter pw = new PrintWriter(System.out);
        ^
  symbol:   class PrintWriter
  location: class Main
Main.java:118: error: cannot find symbol
        PrintWriter pw = new PrintWriter(System.out);
                             ^
  symbol:   class PrintWriter
  location: class Main
30 errors