Language: C++

import java.util.*;

class Main {
	Scanner sc;
	long r1, c1, r2, c2;
	int[] m;
	static final int MOD = 1_000_000_007;
	
	private void calc() {
		sc = new Scanner(System.in);
		r1 = sc.nextInt();
		c1 = sc.nextInt();
		r2 = sc.nextInt();
		c2 = sc.nextInt();
		
		if (c2-c1 > r2-r1) {
			long t = c1; c1 = r1; r1 = t;
			t = c2; c2 = r2; r2 = t;
		}
		
		long nCr = 1;
		for (int i = 1; i <= r1; i++)
			nCr = nCr*(i+c1)%MOD * inv(i) % MOD;
		long top = nCr;
		long left = nCr;
		long s = nCr;
		long ds = nCr;
		
		for (long x = 1; x < r2-r1+c2-c1+1; x++) {
			long i = (2*ds - top - left+MOD)%MOD;
			ds = 0;
			left = left * ((c1 + r1 + x)%MOD )%MOD;
			if (x < c2-c1+1) {
				left = left * inv(c1 + x) %MOD;
				ds += left;
			} else {
				left = left * inv(r1 + x-c2+c1) %MOD;
			}
			top = top * ((c1 + r1 + x)%MOD )%MOD;
			if (x < r2-r1+1) {
				top = top * inv(r1 + x) %MOD;
				ds += top;
			} else {
				top = top * inv(c1 + x-r2+r1) %MOD;
			}
			ds = (ds + i)%MOD;
			s = (s + ds)%MOD;
		}
		
		System.out.println(s);
	}
	
	static final long inv(long a) {
		long b = MOD;
		long aa = a, bb = b;
		long x0 = 1, x1 = 0;
		long y0 = 0, y1 = 1;
	
		while (b != 0) {
			long q = a / b;
			long r = a % b;
			long x2 = x0 - q * x1;
			long y2 = y0 - q * y1;
	
			a = b; b = r;
			x0 = x1; x1 = x2;
			y0 = y1; y1 = y2;
		}
		if (bb > 0 && x0 < 0) {
			long n = -x0/bb;
			if (-x0%bb != 0) n++;
			x0 += n*bb; y0 -= n*aa;
		}
	    return x0;
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
}


Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:9: error: 'Scanner' does not name a type
    4 |         Scanner sc;
      |         ^~~~~~~
a.cc:6:12: error: expected unqualified-id before '[' token
    6 |         int[] m;
      |            ^
a.cc:7:16: error: 'final' does not name a type
    7 |         static final int MOD = 1_000_000_007;
      |                ^~~~~
a.cc:9:16: error: expected ':' before 'void'
    9 |         private void calc() {
      |                ^~~~~
      |                :
a.cc:53:16: error: 'final' does not name a type
   53 |         static final long inv(long a) {
      |                ^~~~~
a.cc:77:15: error: expected ':' before 'static'
   77 |         public static void main(String[] args) {
      |               ^~~~~~~
      |               :
a.cc:77:33: error: 'String' has not been declared
   77 |         public static void main(String[] args) {
      |                                 ^~~~~~
a.cc:77:42: error: expected ',' or '...' before 'args'
   77 |         public static void main(String[] args) {
      |                                          ^~~~
a.cc:80:2: error: expected ';' after class definition
   80 | }
      |  ^
      |  ;
a.cc: In member function 'void Main::calc()':
a.cc:10:17: error: 'sc' was not declared in this scope
   10 |                 sc = new Scanner(System.in);
      |                 ^~
a.cc:10:26: error: expected type-specifier before 'Scanner'
   10 |                 sc = new Scanner(System.in);
      |                          ^~~~~~~
a.cc:23:42: error: 'MOD' was not declared in this scope
   23 |                         nCr = nCr*(i+c1)%MOD * inv(i) % MOD;
      |                                          ^~~
a.cc:23:48: error: 'inv' was not declared in this scope; did you mean 'int'?
   23 |                         nCr = nCr*(i+c1)%MOD * inv(i) % MOD;
      |                                                ^~~
      |                                                int
a.cc:30:53: error: 'MOD' was not declared in this scope
   30 |                         long i = (2*ds - top - left+MOD)%MOD;
      |                                                     ^~~
a.cc:34:47: error: 'inv' was not declared in this scope; did you mean 'int'?
   34 |                                 left = left * inv(c1 + x) %MOD;
      |                                               ^~~
      |                                               int
a.cc:37:47: error: 'inv' was not declared in this scope; did you mean 'int'?
   37 |                                 left = left * inv(r1 + x-c2+c1) %MOD;
      |                                               ^~~
      |                                               int
a.cc:41:45: error: 'inv' was not declared in this scope; did you mean 'int'?
   41 |                                 top = top * inv(r1 + x) %MOD;
      |                                             ^~~
      |                                             int
a.cc:44:45: error: 'inv' was not declared in this scope; did you mean 'int'?
   44 |                                 top = top * inv(c1 + x-r2+r1) %MOD;
      |                                             ^~~
      |                                             int
a.cc:50:17: error: 'System' was not declared in this scope
   50 |                 System.out.println(s);
      |                 ^~~~~~
a.cc: In static member function 'static void Main::main(int*)':
a.cc:78:27: error: expected ';' before '.' token
   78 |                 new Main().calc();
      |                           ^