Problem:
Score : 400 points

Problem Statement

Akari has n kinds of flowers, one of each kind.

She is going to choose one or more of these flowers to make a bouquet.

However, she hates two numbers a and b, so the number of flowers in the bouquet cannot be a or b.

How many different bouquets are there that Akari can make?

Find the count modulo (10^9 + 7).

Here, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet.

Constraints

All values in input are integers.

2 \leq n \leq 10^9

1 \leq a < b \leq \textrm{min}(n, 2 \times 10^5)

Input

Input is given from Standard Input in the following format:

n a b

Output

Print the number of bouquets that Akari can make, modulo (10^9 + 7). (If there are no such bouquets, print 0.)

Sample Input 1

4 1 3

Sample Output 1

7

In this case, Akari can choose 2 or 4 flowers to make the bouquet.

There are 6 ways to choose 2 out of the 4 flowers, and 1 way to choose 4, so there are a total of 7 different bouquets that Akari can make.

Sample Input 2

1000000000 141421 173205

Sample Output 2

34076506

Print the count modulo (10^9 + 7).

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

use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T,T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 3);
  (v[0], v[1], v[2])
}

const MOD: usize = 1_000_000_000 + 7;

fn main() {
    let (n, a, b) = read_touple::<usize>();
    let a_fact = Mod::new(a).fact();
    let b_fact = Mod::new(b).fact();
    let x_a = f(n, a);
    let x_b = f(n, b);
    let ans = Mod::new(2).pow(n) - x_a / a_fact - x_b / b_fact;

    println!("{}", ans.unwrap()-1);
}

fn f(n: usize, count: usize) -> Mod {
  let mut n = n;
    let mut count = count;
    let mut res = 1;
    while count > 0 {
      res *= n;
      res %= MOD;
      n -= 1;
      count -= 1;
    }

    Mod::new(res)
}

#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]
struct Mod {
  val: usize,
}

// 和を定義
impl std::ops::Add for Mod {
  type Output = Mod;
  // O(1)
  fn add(self, other: Mod) -> Mod {
    Mod {
      val: (self.val + other.val) % MOD,
    }
  }
}

// 差を定義
impl std::ops::Sub for Mod {
  type Output = Mod;

  // O(1)
  fn sub(self, other: Mod) -> Mod {
    Mod {
      val: (self.val + MOD - other.val) % MOD,
    }
  }
}

// 積を定義
impl std::ops::Mul for Mod {
  type Output = Mod;

  // O(1)
  fn mul(self, other: Mod) -> Mod {
    Mod {
      val: (self.val * other.val) % MOD,
    }
  }
}

// 加法単位元
impl std::ops::Neg for Mod {
  type Output = Mod;

  // O(1)
  fn neg(self) -> Mod {
    Mod {
      val: MOD - self.val,
    }
  }
}

// 逆元を定義
// フェルマーの小定理により実装
impl std::ops::Div for Mod {
  type Output = Mod;

  //O(logN)
  fn div(self, other: Mod) -> Mod {
    self * other.inv()
  }
}

impl Mod {
  // コンストラクター
  fn new(n: usize) -> Mod {
    Mod { val: n % MOD }
  }

  // 加法単位元
  fn new_zero() -> Mod {
    Mod { val: 0 }
  }

  // 乗法単位元
  fn new_one() -> Mod {
    Mod { val: 1 }
  }

  // 加法逆元
  // 上記にて定義

  // 乗法逆元
  fn inv(self) -> Mod {
    if self.val == 0 {
      panic!("zero divide");
    }
    self.pow(MOD - 2)
  }

  // 累乗を定義
  // O(logN)
  fn pow(self, n: usize) -> Mod {
    let mut res = 1;
    let mut a = self.unwrap();
    let mut n = n;

    while n > 0 {
      if n % 2 == 0 {
        a = a * a;
        n /= 2;
      } else {
        res = res * a;
        a = a * a;
        n /= 2;
      }
      res %= MOD;
      a %= MOD;
    }
    Mod::new(res)
  }

  // 最大公約数
  // O(logN)
  fn gcd(self, other: Mod) -> usize {
    let mut x = self.val;
    let mut y = other.val;
    while y != 0 {
      let t = y;
      y = x % y;
      x = t;
    }
    x
  }

  // 階乗
  // O(N)
  fn fact(self) -> Mod {
    let mut res = 1;
    for i in 1..self.val + 1 {
      res *= i;
      res %= MOD;
    }

    Mod::new(res)
  }

  // 順列
  fn perm(self, other: Mod) -> Mod {
    let mut res = Mod::new_one();
    for x in (self.val - other.val + 1)..self.val + 1 {
      res = res * Mod::new(x);
    }

    res
  }

  // 組み合わせ O(N)
  fn conb(self, other: Mod) -> Mod {
    if self < other {
      return Mod::new_zero();
    }
    self.fact() / (other.fact() * (self - other).fact())
  }
  fn unwrap(self) -> usize {
    self.val % MOD
  }
}

#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
struct ModConb {
  fact: Vec<Mod>,
  inv_fact: Vec<Mod>,
  n: usize,
}

impl ModConb {
  // O(N)
  fn new(n: usize) -> ModConb {
    let mut fact = vec![Mod::new_one(); n + 1];
    let mut inv_fact = vec![Mod::new_one(); n + 1];
    for i in 1..(n + 1) {
      fact[i] = fact[i - 1] * Mod::new(i);
      inv_fact[i] = inv_fact[i - 1] / Mod::new(i);
    }

    ModConb {
      fact: fact,
      inv_fact: inv_fact,
      n: n + 1,
    }
  }
  // O(1)
  fn get(&self, n: usize, r: usize) -> Mod {
    if r <= n {
      self.fact[n] * self.inv_fact[r] * self.inv_fact[n - r]
    } else {
      Mod::new_zero()
    }
  }
}