Problem:
Score : 600 points

Problem Statement

Snuke is standing on a two-dimensional plane. In one operation, he can move by 1 in the positive x-direction, or move by 1 in the positive y-direction.

Let us define a function f(r, c) as follows:

f(r,c) := (The number of paths from the point (0, 0) to the point (r, c) that Snuke can trace by repeating the operation above)

Given are integers r_1, r_2, c_1, and c_2.
Find the sum of f(i, j) over all pair of integers (i, j) such that r_1 ≤ i ≤ r_2 and c_1 ≤ j ≤ c_2, and compute this value modulo (10^9+7).

Constraints

1 ≤ r_1 ≤ r_2 ≤ 10^6

1 ≤ c_1 ≤ c_2 ≤ 10^6

All values in input are integers.

Input

Input is given from Standard Input in the following format:

r_1 c_1 r_2 c_2

Output

Print the sum of f(i, j) modulo (10^9+7).

Sample Input 1

1 1 2 2

Sample Output 1

14

For example, there are two paths from the point (0, 0) to the point (1, 1): (0,0) → (0,1) → (1,1) and (0,0) → (1,0) → (1,1), so f(1,1)=2.

Similarly, f(1,2)=3, f(2,1)=3, and f(2,2)=6. Thus, the sum is 14.

Sample Input 2

314 159 2653 589

Sample Output 2

602215194

Solution in Rust (1.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use competition::{ModCombin, ModI64};
use proconio::input;

mod competition {
    #[derive(Debug, Copy, Clone, Eq, PartialEq)]
    pub struct ModI64(i64);

    const MODP: i64 = 1_000_000_007;

    impl ModI64 {
        pub fn inv(self) -> Self {
            self.pow(MODP as u32 - 2)
        }

        pub fn new(x: i64) -> Self {
            Self(x % MODP)
        }

        pub fn pow(self, exp: u32) -> Self {
            let mut b: ModI64 = self;
            let mut a: ModI64 = 1i64.into();
            let mut x = exp;
            while x > 1 {
                if x & 1 == 1 {
                    a = a * b;
                }
                x = x / 2;
                b = b * b;
            }
            if x == 1 {
                a = a * b;
            }
            a
        }
    }

    impl From<i64> for ModI64 {
        fn from(x: i64) -> Self {
            ModI64::new(x)
        }
    }

    impl std::fmt::Display for ModI64 {
        fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
            write!(f, "{}", self.0)
        }
    }

    impl std::ops::Add<ModI64> for ModI64 {
        type Output = ModI64;

        fn add(self, rhs: ModI64) -> Self::Output {
            (self.0 + rhs.0).into()
        }
    }

    impl std::ops::Sub<ModI64> for ModI64 {
        type Output = ModI64;

        fn sub(self, rhs: ModI64) -> Self::Output {
            let x = self.0 - rhs.0;
            (if x.is_negative() { MODP + x } else { x }).into()
        }
    }

    impl std::ops::Mul<ModI64> for ModI64 {
        type Output = ModI64;

        fn mul(self, rhs: ModI64) -> Self::Output {
            (self.0 * rhs.0).into()
        }
    }

    impl std::ops::Div<ModI64> for ModI64 {
        type Output = ModI64;

        fn div(self, rhs: ModI64) -> Self::Output {
            self * rhs.inv()
        }
    }

    pub struct ModCombin {
        factv: Vec<ModI64>,
        finvv: Vec<ModI64>,
    }

    impl ModCombin {
        pub fn new(max: usize) -> Self {
            let mut factv: Vec<ModI64> = vec![0.into(); max + 1];
            let mut finvv: Vec<ModI64> = vec![0.into(); max + 1];
            factv[0] = 1.into();
            for i in 1..=max {
                factv[i] = factv[i - 1] * (i as i64).into();
            }
            finvv[max] = factv[max].inv();
            for i in (1..=max).rev() {
                finvv[i - 1] = finvv[i] * (i as i64).into();
            }
            Self { factv, finvv }
        }

        pub fn combination(&self, n: usize, r: usize) -> ModI64 {
            if n < r {
                return 0.into();
            }
            self.factv[n] * self.finvv[r] * self.finvv[n - r]
        }
    }
}

fn g(mc: &competition::ModCombin, r: usize, c: usize) -> ModI64 {
    mc.combination((r + 1) + (c + 1), r + 1) - 1.into()
}

fn main() {
    input! {
        r1: usize,
        c1: usize,
        r2: usize,
        c2: usize
    };
    let mc = ModCombin::new(2_000_005);
    let ans = g(&mc, r2, c2) - g(&mc, r1 - 1, c2) - g(&mc, r2, c1 - 1) + g(&mc, r1 - 1, c1 - 1);
    println!("{}", ans);
}
*/

fn main() {
    let exe = "/tmp/bin5C9831F1";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";