Rust: nCr problem
Code\n\nconst LARGE: i64 = 1_000_000_007;\n\nimpl Solution {\n    pub fn count_of_pairs(nums: Vec<i32>) -> i32 {\n        let mut decr = 0;\n        for w in nu
# Code\n```\nconst LARGE: i64 = 1_000_000_007;\n\nimpl Solution {\n    pub fn count_of_pairs(nums: Vec<i32>) -> i32 {\n        let mut decr = 0;\n        for w in nums.windows(2) {\n            if w[0] > w[1] {\n                decr += w[0] - w[1];\n            }\n        }\n        let r = nums[0] - decr;\n        let n = r + nums.len() as i32;\n        Self::ncr(n as i64, r as i64)\n    }\n\n    fn ncr(n: i64, mut r: i64) -> i32 {\n        r = r.min(n - r);\n        if r < 0 {\n            return 0;\n        }\n        let mut num = 1i64;\n        let mut den = 1i64;\n        for i in 1..=r {\n            num = (num * (n - r + i)) % LARGE;\n            den = (den * i) % LARGE;\n        }\n        ((num * Self::inv(den)) % LARGE) as i32\n    }\n\n    fn inv(mut x: i64) -> i64 {\n        let mut pow = LARGE - 2;\n        let mut ans = 1;\n        while pow != 0 {\n            if pow & 1 == 1 {\n                ans = (ans * x) % LARGE;\n            }\n            x = (x * x) % LARGE;\n            pow >>= 1;\n        }\n        ans\n    }\n}\n```
['Combinatorics', 'Rust']