Language: C++

import java.util.Scanner;

class AOJ10031 {
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		int[] array = new int[n];
		int[] arrayL = new int[n / 2 + 2];
		int[] arrayR = new int[n / 2 + 2];
		
		for (int i = 0; i < n; i++){
			array[i] = scanner.nextInt();
		}
		
		mergeSort(array, arrayL, arrayR, 0, n);
		
		int res = 0;
		int q = scanner.nextInt();
		for (int i = 0; i < q; i++){
			int key = scanner.nextInt();
			res += binarySearch(array, n, key + 1) - binarySearch(array, n, key);
		}
		
		System.out.println(res);
	}
	
	public static void mergeSort(int[] array, int[] arrayL, int[] arrayR, int left, int right){
		if (right - left <= 1) return;
		
		int mid = (left + right) / 2;
		
		mergeSort(array, arrayL, arrayR, left, mid);
		mergeSort(array, arrayL, arrayR, mid, right);
		
		int n1 = mid - left;
		int n2 = right - mid;
		
		for (int i = 0; i < n1; i++) arrayL[i] = array[left + i];
		for (int i = 0; i < n2; i++) arrayR[i] = array[mid + i];
		arrayL[n1] = arrayR[n2] = 1 << 28;
		
		int l = 0, r = 0;
		for (int k = left; k < right; k++){
			if (arrayL[l] <= arrayR[r]) array[k] = arrayL[l++];
			else array[k] = arrayR[r++];
		}
	}
	
	public static int binarySearch(int[] array, int n, int key){
		int l = 0, r = n - 1;
		while (l <= r){
			int m = (l + r) / 2;
			if (array[m] <= key) l = m + 1;
			else r = m - 1;
		}
		return l;
	}
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.Scanner;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:15: error: expected ':' before 'static'
    4 |         public static void main(String[] args){
      |               ^~~~~~~
      |               :
a.cc:4:33: error: 'String' has not been declared
    4 |         public static void main(String[] args){
      |                                 ^~~~~~
a.cc:4:42: error: expected ',' or '...' before 'args'
    4 |         public static void main(String[] args){
      |                                          ^~~~
a.cc:28:15: error: expected ':' before 'static'
   28 |         public static void mergeSort(int[] array, int[] arrayL, int[] arrayR, int left, int right){
      |               ^~~~~~~
      |               :
a.cc:28:44: error: expected ',' or '...' before 'array'
   28 |         public static void mergeSort(int[] array, int[] arrayL, int[] arrayR, int left, int right){
      |                                            ^~~~~
a.cc:50:15: error: expected ':' before 'static'
   50 |         public static int binarySearch(int[] array, int n, int key){
      |               ^~~~~~~
      |               :
a.cc:50:46: error: expected ',' or '...' before 'array'
   50 |         public static int binarySearch(int[] array, int n, int key){
      |                                              ^~~~~
a.cc:59:2: error: expected ';' after class definition
   59 | }
      |  ^
      |  ;
a.cc: In static member function 'static void AOJ10031::main(int*)':
a.cc:5:17: error: 'Scanner' was not declared in this scope
    5 |                 Scanner scanner = new Scanner(System.in);
      |                 ^~~~~~~
a.cc:7:25: error: 'scanner' was not declared in this scope
    7 |                 int n = scanner.nextInt();
      |                         ^~~~~~~
a.cc:8:20: error: structured binding declaration cannot have type 'int'
    8 |                 int[] array = new int[n];
      |                    ^~
a.cc:8:20: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:8:20: error: empty structured binding declaration
a.cc:8:23: error: expected initializer before 'array'
    8 |                 int[] array = new int[n];
      |                       ^~~~~
a.cc:9:20: error: structured binding declaration cannot have type 'int'
    9 |                 int[] arrayL = new int[n / 2 + 2];
      |                    ^~
a.cc:9:20: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:9:20: error: empty structured binding declaration
a.cc:9:23: error: expected initializer before 'arrayL'
    9 |                 int[] arrayL = new int[n / 2 + 2];
      |                       ^~~~~~
a.cc:10:20: error: structured binding declaration cannot have type 'int'
   10 |                 int[] arrayR = new int[n / 2 + 2];
      |                    ^~
a.cc:10:20: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:10:20: error: empty structured binding declaration
a.cc:10:23: error: expected initializer before 'arrayR'
   10 |                 int[] arrayR = new int[n / 2 + 2];
      |                       ^~~~~~
a.cc:13:25: error: 'array' was not declared in this scope
   13 |                         array[i] = scanner.nextInt();
      |                         ^~~~~
a.cc:16:27: error: 'array' was not declared in this scope
   16 |                 mergeSort(array, arrayL, arrayR, 0, n);
      |                           ^~~~~
a.cc:16:34: error: 'arrayL' was not declared in this scope
   16 |                 mergeSort(array, arrayL, arrayR, 0, n);
      |                                  ^~~~~~
a.cc:16:42: error: 'arrayR' was not declared in this scope
   16 |                 mergeSort(array, arrayL, arrayR, 0, n);
      |                                          ^~~~~~
a.cc:25:17: error: 'System' was not declared in this scope
   25 |                 System.out.println(res);
      |                 ^~~~~~
a.cc: In static member function 'static void AOJ10031::mergeSort(int*)':
a.cc:29:21: error: 'right' was not declared in this scope
   29 |                 if (right - left <= 1) return;
      |                     ^~~~~
a.cc:29:29: error: 'left' was not declared in this scope
   29 |                 if (right - left <= 1) return;
      |                             ^~~~
a.cc:31:28: error: 'left' was not declared in this scope
   31 |                 int mid = (left + right) / 2;
      |                            ^~~~
a.cc:31:35: error: 'right' was not declared in this scope
   31 |                 int mid = (left + right) / 2;
      |                                   ^~~~~
a.cc:33:27: error: 'array' was not declared in this scope
   33 |                 mergeSort(array, arrayL, arrayR, left, mid);
      |                           ^~~~~
a.cc:33:34: error: 'arrayL' was not declared in this scope
   33 |                 mergeSort(array, arrayL, arrayR, left, mid);
      |                                  ^~~~~~
a.cc:33:42: error: 'arrayR' was not declared in this scope
   33 |                 mergeSort(array, arrayL, arrayR, left, mid);
      |                                          ^~~~~~
a.cc: In static member function 'static int AOJ10031::binarySearch(int*)':
a.cc:51:32: error: 'n' was not declared in this scope
   51 |                 int l = 0, r = n - 1;
      |                                ^
a.cc:54:29: error: 'array' was not declared in this scope
   54 |                         if (array[m] <= key) l = m + 1;
      |                             ^~~~~
a.cc:54:41: error: 'key' was not declared in this scope
   54 |                         if (array[m] <= key) l = m + 1;
      |                                         ^~~