Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("adece.in");
- ofstream fout("adece.out");
- const int mod = 1e8 + 7;
- const int kN = 9e3;
- int f[1 + kN], invf[1 + kN];
- void addSelf(int &x, const int &y) {
- x += y;
- if (x >= mod) {
- x -= mod;
- }
- }
- int add(int x, const int &y) {
- addSelf(x, y);
- return x;
- }
- void multSelf(int &x, const int &y) {
- x = (int64_t)x * y % mod;
- }
- int mult(int x, const int &y) {
- multSelf(x, y);
- return x;
- }
- int Pow(int x, int n) {
- int ans = 1;
- while (n) {
- if (n & 1) {
- multSelf(ans, x);
- }
- multSelf(x, x);
- n >>= 1;
- }
- return ans;
- }
- int invers(int x) {
- return Pow(x, mod - 2);
- }
- void computeFactorials(int n) {
- f[0] = f[1] = 1;
- for (int i = 2; i <= n; ++i) {
- f[i] = mult(f[i - 1], i);
- }
- invf[n] = invers(f[n]);
- for (int i = n - 1; i >= 0; --i) {
- invf[i] = mult(invf[i + 1], i + 1);
- }
- }
- int main() {
- int a, b, c;
- fin >> a >> b >> c;
- int n = a + b + c, m = min({a, b, c});
- computeFactorials(n);
- int res = 0;
- for (int i = 0; i <= m; ++i) {
- int remA = a - i;
- int remB = b - i;
- int remC = c - i;
- int remN = remA + remB + remC + i;
- int ways = mult(f[remN], mult(mult(invf[remA], invf[remB]), mult(invf[remC], invf[i])));
- if (i % 2 == 0) {
- addSelf(res, ways);
- } else {
- addSelf(res, mod - ways);
- }
- }
- fout << res << '\n';
- fin.close();
- fout.close();
- return 0;
- }
Add Comment
Please, Sign In to add comment