Language: Java

#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (2000)
#define SIZE_BUF (30)
#define INF (1000000000)

using namespace std;

void swap(int *as, char *cs, int i, int j) {
  const int a = as[i];
  const char c = cs[i];
  as[i] = as[j];
  cs[i] = cs[j];
  as[j] = a;
  cs[j] = c;
}

int main(int argc, char *argv[]) {
  // read inputs
  int N, as[2 * MAX_N];
  char cs[2 * MAX_N], buf[SIZE_BUF];
  scanf("%d", &N);
  fgets(buf, SIZE_BUF, stdin);
  for (int i = 0; i < 2 * N; i++) {
    scanf("%c %d", &cs[i], &as[i]);
    fgets(buf, SIZE_BUF, stdin);
  }

  // sort from the beginning
  int ans = 0;
  int nb = 1, nw = 1;
  // for (int i = 0; i < 2 * N; i++) {
  //   printf("%c %d\n", cs[i], as[i]);
  // }
  for (int i = 0; i < 2 * N; i++) {
    const char c0 = cs[i];
    const int n0 = c0 == 'B' ? nb : nw;
    if (as[i] > n0) {
      // look for n (B, nb) or (W, nw)
      int ib = INF, iw = INF;
      for (int j = i + 1; j < 2 * N; j++) {
        if (cs[j] == 'B' && as[j] == nb) {
          ib = j;
        }
        if (cs[j] == 'W' && as[j] == nw) {
          iw = j;
        }
      }
      // bring the nearer one to i
      for (int j = min(ib, iw); j > i; j--) {
        swap(as, cs, j, j - 1);
        ans++;
      }
    }
    if (cs[i] == 'B') {
      nb++;
    } else {
      nw++;
    }
  }
  // for (int i = 0; i < 2 * N; i++) {
  //   printf("%c %d\n", cs[i], as[i]);
  // }
  printf("%d\n", ans);

  return 0;
}


Compiler output:
Main.java:1: error: illegal character: '#'
#include <stdio.h>
^
Main.java:1: error: class, interface, enum, or record expected
#include <stdio.h>
         ^
Main.java:2: error: illegal character: '#'
#include <stdlib.h>
^
Main.java:3: error: illegal character: '#'
#include <algorithm>
^
Main.java:5: error: illegal character: '#'
#define MAX_N (2000)
^
Main.java:6: error: illegal character: '#'
#define SIZE_BUF (30)
^
Main.java:7: error: illegal character: '#'
#define INF (1000000000)
^
Main.java:11: error: unnamed classes are a preview feature and are disabled by default.
void swap(int *as, char *cs, int i, int j) {
^
  (use --enable-preview to enable unnamed classes)
Main.java:11: error: <identifier> expected
void swap(int *as, char *cs, int i, int j) {
             ^
Main.java:11: error: class, interface, enum, or record expected
void swap(int *as, char *cs, int i, int j) {
                   ^
Main.java:13: error: class, interface, enum, or record expected
  const char c = cs[i];
  ^
Main.java:14: error: class, interface, enum, or record expected
  as[i] = as[j];
  ^
Main.java:15: error: class, interface, enum, or record expected
  cs[i] = cs[j];
  ^
Main.java:16: error: class, interface, enum, or record expected
  as[j] = a;
  ^
Main.java:17: error: class, interface, enum, or record expected
  cs[j] = c;
  ^
Main.java:18: error: class, interface, enum, or record expected
}
^
Main.java:23: error: class, interface, enum, or record expected
  char cs[2 * MAX_N], buf[SIZE_BUF];
  ^
Main.java:24: error: class, interface, enum, or record expected
  scanf("%d", &N);
  ^
Main.java:25: error: class, interface, enum, or record expected
  fgets(buf, SIZE_BUF, stdin);
  ^
Main.java:26: error: class, interface, enum, or record expected
  for (int i = 0; i < 2 * N; i++) {
  ^
Main.java:26: error: class, interface, enum, or record expected
  for (int i = 0; i < 2 * N; i++) {
                  ^
Main.java:26: error: class, interface, enum, or record expected
  for (int i = 0; i < 2 * N; i++) {
                             ^
Main.java:28: error: class, interface, enum, or record expected
    fgets(buf, SIZE_BUF, stdin);
    ^
Main.java:29: error: class, interface, enum, or record expected
  }
  ^
Main.java:37: error: class, interface, enum, or record expected
  for (int i = 0; i < 2 * N; i++) {
  ^
Main.java:37: error: class, interface, enum, or record expected
  for (int i = 0; i < 2 * N; i++) {
                  ^
Main.java:37: error: class, interface, enum, or record expected
  for (int i = 0; i < 2 * N; i++) {
                             ^
Main.java:39: error: class, interface, enum, or record expected
    const int n0 = c0 == 'B' ? nb : nw;
    ^
Main.java:40: error: class, interface, enum, or record expected
    if (as[i] > n0) {
    ^
Main.java:43: error: class, interface, enum, or record expected
      for (int j = i + 1; j < 2 * N; j++) {
      ^
Main.java:43: error: class, interface, enum, or record expected
      for (int j = i + 1; j < 2 * N; j++) {
                          ^
Main.java:43: error: class, interface, enum, or record expected
      for (int j = i + 1; j < 2 * N; j++) {
                                     ^
Main.java:46: error: class, interface, enum, or record expected
        }
        ^
Main.java:49: error: class, interface, enum, or record expected
        }
        ^
Main.java:52: error: class, interface, enum, or record expected
      for (int j = min(ib, iw); j > i; j--) {
                                ^
Main.java:52: error: class, interface, enum, or record expected
      for (int j = min(ib, iw); j > i; j--) {
                                       ^
Main.java:54: error: class, interface, enum, or record expected
        ans++;
        ^
Main.java:55: error: class, interface, enum, or record expected
      }
      ^
Main.java:59: error: class, interface, enum, or record expected
    } else {
    ^
Main.java:61: error: class, interface, enum, or record expected
    }
    ^
Main.java:68: error: class, interface, enum, or record expected
  return 0;
  ^
Main.java:69: error: class, interface, enum, or record expected
}
^
42 errors