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 + 1];
		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();
		}
		array[n] = 1 << 28;
		
		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)) > 0 ? 1 : 0;
		}
		
		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;
		while (l <= r){
			int m = (l + r) / 2;
			if (array[m] <= key) l = m + 1;
			else r = m - 1;
		}
		//System.out.println(array[l]);
		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:29:15: error: expected ':' before 'static'
   29 |         public static void mergeSort(int[] array, int[] arrayL, int[] arrayR, int left, int right){
      |               ^~~~~~~
      |               :
a.cc:29:44: error: expected ',' or '...' before 'array'
   29 |         public static void mergeSort(int[] array, int[] arrayL, int[] arrayR, int left, int right){
      |                                            ^~~~~
a.cc:51:15: error: expected ':' before 'static'
   51 |         public static int binarySearch(int[] array, int n, int key){
      |               ^~~~~~~
      |               :
a.cc:51:46: error: expected ',' or '...' before 'array'
   51 |         public static int binarySearch(int[] array, int n, int key){
      |                                              ^~~~~
a.cc:61:2: error: expected ';' after class definition
   61 | }
      |  ^
      |  ;
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 + 1];
      |                    ^~
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 + 1];
      |                       ^~~~~
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:15:17: error: 'array' was not declared in this scope
   15 |                 array[n] = 1 << 28;
      |                 ^~~~~
a.cc:17:34: error: 'arrayL' was not declared in this scope
   17 |                 mergeSort(array, arrayL, arrayR, 0, n);
      |                                  ^~~~~~
a.cc:17:42: error: 'arrayR' was not declared in this scope
   17 |                 mergeSort(array, arrayL, arrayR, 0, n);
      |                                          ^~~~~~
a.cc:26:17: error: 'System' was not declared in this scope
   26 |                 System.out.println(res);
      |                 ^~~~~~
a.cc: In static member function 'static void AOJ10031::mergeSort(int*)':
a.cc:30:21: error: 'right' was not declared in this scope
   30 |                 if (right - left <= 1) return;
      |                     ^~~~~
a.cc:30:29: error: 'left' was not declared in this scope
   30 |                 if (right - left <= 1) return;
      |                             ^~~~
a.cc:32:28: error: 'left' was not declared in this scope
   32 |                 int mid = (left + right) / 2;
      |                            ^~~~
a.cc:32:35: error: 'right' was not declared in this scope
   32 |                 int mid = (left + right) / 2;
      |                                   ^~~~~
a.cc:34:27: error: 'array' was not declared in this scope
   34 |                 mergeSort(array, arrayL, arrayR, left, mid);
      |                           ^~~~~
a.cc:34:34: error: 'arrayL' was not declared in this scope
   34 |                 mergeSort(array, arrayL, arrayR, left, mid);
      |                                  ^~~~~~
a.cc:34:42: error: 'arrayR' was not declared in this scope
   34 |                 mergeSort(array, arrayL, arrayR, left, mid);
      |                                          ^~~~~~
a.cc: In static member function 'static int AOJ10031::binarySearch(int*)':
a.cc:52:32: error: 'n' was not declared in this scope
   52 |                 int l = 0, r = n;
      |                                ^
a.cc:55:29: error: 'array' was not declared in this scope
   55 |                         if (array[m] <= key) l = m + 1;
      |                             ^~~~~
a.cc:55:41: error: 'key' was not declared in this scope
   55 |                         if (array[m] <= key) l = m + 1;
      |                                         ^~~