prithivMLmods/Coder-Stat huggingface dataset:
Problem p02767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  ll n = 0;
  cin >> n;
  vector<ll> v(n, 0);
  ll mn = 1e9 + 5;
  ll mx = -1e9 + 5;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    mn = min(mn, v[i]);
    mx = max(mx, v[i]);
  }

  ll ans = 1e9 + 5;
  for (int i = mn; i <= mx; i++) {
    ll temp = 0;
    for (int j = 0; j < n; j++) {
      temp += pow(abs(v[j] - i), 2);
    }
    ans = min(ans, temp);
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  ll n = 0;
  cin >> n;
  vector<ll> v(n, 0);
  ll mn = 1e9 + 5;
  ll mx = -1e9 + 5;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    mn = min(mn, v[i]);
    mx = max(mx, v[i]);
  }

  ll ans = 1e9 + 5;
  for (int i = mn; i <= mx; i++) {
    ll temp = 0;
    for (int j = 0; j < n; j++) {
      temp += pow(abs(v[j] - i), 2);
    }
    ans = min(ans, temp);
  }

  cout << ans << endl;

  return 0;
}
Problem p02767 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
X_list = list(map(int, input().split()))

hp_list = []
for p in range(int(min(X_list)), int(max(X_list))):
    hp = 0
    for x in X_list:
        hp += abs(x - p) ** 2
    hp_list.append(hp)

print(min(hp_list))


Fixed submission:
N = int(input())
X_list = list(map(int, input().split()))

hp_list = []
for p in range(int(min(X_list)), int(max(X_list))):
    hp = 0
    for x in X_list:
        hp += abs(x - p) ** 2
    hp_list.append(hp)

print(min(hp_list) if len(hp_list) > 0 else 0)
Problem p02767 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
x = list(map(int, input().split()))

sum_list = []
start = min(x)
stop = max(x)
for i in range(start, stop):
    sum = 0
    for j in x:
        sum += (i - j) ** 2
    sum_list.append(sum)

print(min(sum_list))


Fixed submission:
n = int(input())
x = list(map(int, input().split()))

sum_list = []
start = min(x)
stop = max(x)
for i in range(1, 100):
    sum = 0
    for j in x:
        sum += (i - j) ** 2
    sum_list.append(sum)

print(min(sum_list))
Problem p02767 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
x = list(map(int, input().split()))

sum_list = []
start = min(x)
stop = max(x)
for i in range(start, stop):
    sum = 0
    for j in x:
        sum += (i - j) ** 2
    sum_list.append(sum)

print(min(sum_list))


Fixed submission:
n = int(input())
x = list(map(int, input().split()))

sum_list = []
for i in range(1, 100):
    sum = 0
    for j in x:
        sum += (i - j) ** 2
    sum_list.append(sum)

print(min(sum_list))
Problem p02767 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
X = list(map(int, input().split()))

minX = min(X)
maxX = max(X)
li = []
for i in range(minX, maxX):
    temp = 0
    for j in range(N):
        temp += (X[j] - i) ** 2
    li.append(temp)

print(min(li))


Fixed submission:
N = int(input())
X = list(map(int, input().split()))

minX = min(X)
maxX = max(X)
li = []
for i in range(100):
    temp = 0
    for j in range(N):
        temp += (X[j] - i) ** 2
    li.append(temp)

print(min(li))
Problem p02767 (Python)

Buggy submission (status: Runtime Error):
import sys

N = int(input())
X = [int(_) for _ in input().split()]
ans_list = []
if N == 1:
    print("0")
    sys.exit()
for i in range(min(X), max(X)):
    ans = 0
    for j in X:
        ans += (j - i) ** 2
    ans_list.append(ans)

print(min(ans_list))


Fixed submission:
import sys

N = int(input())
X = [int(_) for _ in input().split()]
ans_list = []
if N == 1:
    print("0")
    sys.exit()
for i in range(min(X), max(X) + 1):
    ans = 0
    for j in X:
        ans += (j - i) ** 2
    ans_list.append(ans)

print(min(ans_list))
Problem p02767 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
points = list(map(int, input().split(" ")))

powers = []
for i in range(min(points), max(points)):
    power = 0
    for point in points:
        power += (i - point) ** 2
    powers.append(power)

print(min(powers))


Fixed submission:
N = int(input())
points = list(map(int, input().split(" ")))

powers = []
for i in range(min(points), max(points) + 1):
    power = 0
    for point in points:
        power += (i - point) ** 2
    powers.append(power)

print(min(powers))
Problem p02767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  int ans = 100 * 100 * 100 + 1;
  for (int i = x.at(1); i <= x.at(x.size() - 1); i++) {
    int tmp = 0;
    for (int j = 0; j < n; j++) {
      tmp += (i - x.at(j)) * (i - x.at(j));
    }
    ans = min(tmp, ans);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  int ans = 100 * 100 * 100 + 1;
  for (int i = x.at(0); i <= x.at(x.size() - 1); i++) {
    int tmp = 0;
    for (int j = 0; j < n; j++) {
      tmp += (i - x.at(j)) * (i - x.at(j));
    }
    ans = min(tmp, ans);
  }
  cout << ans << endl;
}
Problem p02767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, count = 0;
  cin >> N;
  if (N == 1) {
    cout << 0;
    exit(0);
  }

  vector<int> X(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> X.at(i);
  }

  sort(X.begin(), X.end());

  vector<int> A(X.at(N - 1) - X.at(0) - 1, 0);

  for (int i = X.at(0) + 1; i < X.at(N - 1); i++) {
    for (int j = 0; j < N; j++) {
      A.at(count) += (X.at(j) - i) * (X.at(j) - i);
    }

    count++;
  }

  sort(A.begin(), A.end());

  cout << A.at(0);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, count = 0;
  cin >> N;
  if (N == 1) {
    cout << 0;
    exit(0);
  }

  vector<int> X(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> X.at(i);
  }

  sort(X.begin(), X.end());

  if (X.at(N - 1) == X.at(0)) {
    cout << 0;
    exit(0);
  }

  vector<int> A(X.at(N - 1) - X.at(0) - 1, 0);

  for (int i = X.at(0) + 1; i < X.at(N - 1); i++) {
    for (int j = 0; j < N; j++) {
      A.at(count) += (X.at(j) - i) * (X.at(j) - i);
    }

    count++;
  }

  sort(A.begin(), A.end());

  cout << A.at(0);
}
Problem p02767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int people;
  cin >> people;
  vector<int> vi;
  for (int i = 0; i < people; i++) {
    int a;
    cin >> a;
    vi.push_back(a);
  }
  vector<int> vii;
  for (int i = vi[0]; i <= vi[vi.size() - 1]; i++) {
    int sum = 0;
    for (int j = 0; j < vi.size(); j++) {
      sum += (vi[j] - i) * (vi[j] - i);
    }
    vii.push_back(sum);
  }
  sort(vii.begin(), vii.end());
  cout << vii[0] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int people;
  cin >> people;
  vector<int> vi;
  for (int i = 0; i < people; i++) {
    int a;
    cin >> a;
    vi.push_back(a);
  }
  sort(vi.begin(), vi.end());
  vector<int> vii;
  for (int i = vi[0]; i <= vi[vi.size() - 1]; i++) {
    int sum = 0;
    for (int j = 0; j < vi.size(); j++) {
      sum += (vi[j] - i) * (vi[j] - i);
    }
    vii.push_back(sum);
  }
  sort(vii.begin(), vii.end());
  cout << vii[0] << endl;
  return 0;
}
Problem p02767 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for (ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
  if (a >= b)
    return false;
  a = b;
  return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
  if (a <= b)
    return false;
  a = b;
  return true;
}

/*-------------------------------------------*/
int main() {
  int n, sum;
  sum = 0;

  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i);
  }
  sort(x.begin(), x.end());
  vector<int> s;
  for (int p = x[0]; p < x[n - 1] - x[0]; p++) {
    for (int i : x) {
      sum += (i - p) * (i - p);
    }
    s.push_back(sum);
    sum = 0;
  }
  sort(s.begin(), s.end());

  cout << s[0] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for (ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
  if (a >= b)
    return false;
  a = b;
  return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
  if (a <= b)
    return false;
  a = b;
  return true;
}

/*-------------------------------------------*/
int main() {
  int n, sum;
  sum = 0;

  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i);
  }
  sort(x.begin(), x.end());
  vector<int> s;
  for (int p = x[0]; p <= x[n - 1]; p++) {
    for (int i : x) {
      sum += (i - p) * (i - p);
    }
    s.push_back(sum);
    sum = 0;
  }
  sort(s.begin(), s.end());

  cout << s[0] << endl;
}
Problem p02768 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false),
            cout << fixed << setprecision(9), 0);
// int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv
// ./prog.exe") >> 8), 0);
const Int MOD = 1000000007;
Int POW(Int n, Int k) {
  if (k == 0)
    return 1;
  if (k % 2 == 0)
    return POW(n * n % MOD, k / 2);
  return n * POW(n, k - 1) % MOD;
}
Int COM(int n, int k) {
  if (n < k || n < 0 || k < 0)
    return 0;
  Int a = 1, b = 1;
  for (int i = 0; i < k; i++) {
    a = a * (n - i) % MOD;
    b = b * (i + 1) % MOD;
  }
  return a * POW(b, MOD - 2) % MOD;
}
int main() {
  int N, A, B;
  cin >> N >> A >> B;
  Int ans = 1;
  for (int i = 0; i < N; i++) {
    ans = ans * 2 % MOD;
  }
  ans += 3 * MOD - 1 - COM(N, A) - COM(N, B);
  ans %= MOD;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false),
            cout << fixed << setprecision(9), 0);
// int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv
// ./prog.exe") >> 8), 0);
const Int MOD = 1000000007;
Int POW(Int n, Int k) {
  if (k == 0)
    return 1;
  if (k % 2 == 0)
    return POW(n * n % MOD, k / 2);
  return n * POW(n, k - 1) % MOD;
}
Int COM(int n, int k) {
  if (n < k || n < 0 || k < 0)
    return 0;
  Int a = 1, b = 1;
  for (int i = 0; i < k; i++) {
    a = a * (n - i) % MOD;
    b = b * (i + 1) % MOD;
  }
  return a * POW(b, MOD - 2) % MOD;
}
int main() {
  int N, A, B;
  cin >> N >> A >> B;
  Int ans = POW(2, N);
  ans += 3 * MOD - 1 - COM(N, A) - COM(N, B);
  ans %= MOD;
  cout << ans << endl;
  return 0;
}
Problem p02768 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

const int MOD = 1000000007;

long long power(long long a, long long b) {
  if (b == 0)
    return 1;
  if (b % 2 == 0) {
    long long d = power(a, b / 2);
    return d * d % MOD;
  }
  return a * power(a, b - 1) % MOD;
}

long long comb(long long x, long long y) {
  long long res = 1;
  for (long long i = x; i > x - y; i--)
    res = res * i % MOD;
  for (long long i = 1; i <= y; i++)
    res = (res * power(i, MOD - 2)) % MOD;
  return res;
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  long long m = 1;
  for (int i = 0; i < n; ++i) {
    m = (2 * m) % MOD;
  }
  --m;
  long long ca = comb(n, a);
  long long cb = comb(n, b);
  cout << (2 * MOD + m - ca - cb) % MOD << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

const int MOD = 1000000007;

long long power(long long a, long long b) {
  if (b == 0)
    return 1;
  if (b % 2 == 0) {
    long long d = power(a, b / 2);
    return d * d % MOD;
  }
  return a * power(a, b - 1) % MOD;
}

long long comb(long long x, long long y) {
  long long res = 1;
  for (long long i = x; i > x - y; i--)
    res = res * i % MOD;
  for (long long i = 1; i <= y; i++)
    res = (res * power(i, MOD - 2)) % MOD;
  return res;
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  long long m = power(2, n) - 1;
  long long ca = comb(n, a);
  long long cb = comb(n, b);
  cout << (2 * MOD + m - ca - cb) % MOD << endl;
}
Problem p02768 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

long long n, a, b;
const int MAXN = 212345;

long long m = 1e9 + 7;

long long inv[MAXN];
long long inverse_factorial[MAXN];

long long binomial_coefficient(int n, int k) {
  long long prod = 1;
  for (int i = n; i >= n - k + 1; i--)
    prod = (i * prod) % m;
  return (prod * inverse_factorial[k] % m) % m;
}

long long Pow(long long base, long long i) {
  base %= m;
  if (i <= 0)
    return 1;
  else if (i == 1)
    return base;
  else {
    long long aux = Pow(base, i / 2);
    if (i % 2 == 0)
      return (aux * aux) % m;
    else
      return (base * ((aux * aux) % m)) % m;
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  freopen("input.txt", "r", stdin);

  cin >> n >> a >> b;

  inv[1] = 1;
  for (int i = 2; i < MAXN; ++i)
    inv[i] = (m - (m / i) * inv[m % i] % m) % m;

  inverse_factorial[0] = inv[1];

  for (int i = 1; i < MAXN; i++)
    inverse_factorial[i] = (inverse_factorial[i - 1] * inv[i]) % m;

  long long d = Pow(2, n);

  cout << (2 * m + d - 1 - binomial_coefficient(n, a) -
           binomial_coefficient(n, b)) %
              m;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

long long n, a, b;
const int MAXN = 212345;

long long m = 1e9 + 7;

long long inv[MAXN];
long long inverse_factorial[MAXN];

long long binomial_coefficient(int n, int k) {
  long long prod = 1;
  for (int i = n; i >= n - k + 1; i--)
    prod = (i * prod) % m;
  return (prod * inverse_factorial[k] % m) % m;
}

long long Pow(long long base, long long i) {
  base %= m;
  if (i <= 0)
    return 1;
  else if (i == 1)
    return base;
  else {
    long long aux = Pow(base, i / 2);
    if (i % 2 == 0)
      return (aux * aux) % m;
    else
      return (base * ((aux * aux) % m)) % m;
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  // freopen("input.txt","r",stdin);

  cin >> n >> a >> b;

  inv[1] = 1;
  for (int i = 2; i < MAXN; ++i)
    inv[i] = (m - (m / i) * inv[m % i] % m) % m;

  inverse_factorial[0] = inv[1];

  for (int i = 1; i < MAXN; i++)
    inverse_factorial[i] = (inverse_factorial[i - 1] * inv[i]) % m;

  long long d = Pow(2, n);

  cout << (2 * m + d - 1 - binomial_coefficient(n, a) -
           binomial_coefficient(n, b)) %
              m;
}
Problem p02768 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

LL modpow(LL a, LL n) {
  LL pow = 1;
  while (n > 0) {
    if (n & 1)
      pow = pow * a % kMod;
    a = a * a % kMod;
    n >>= 1;
  }
  return pow;
}

LL modinv(LL a) { return modpow(a, kMod - 2); }

LL modsub(LL a, LL b) { return (a + kMod - b) % kMod; }

LL nCr(LL n, LL r) {
  LL x = 1, y = 1;
  for (int i = 1; i <= r; ++i) {
    x = (x * (n - i + 1)) % kMod;
    y = (y * i) % kMod;
  }
  return (x * modinv(y)) % kMod;
}

int main() {
  LL n, a, b;
  std::cin >> n >> a >> b;

  LL ans = 1;
  for (int i = 0; i < n; ++i)
    ans = (2 * ans) % kMod;
  --ans;

  LL nCa = nCr(n, a);
  LL nCb = nCr(n, b);

  ans = modsub(ans, nCa);
  ans = modsub(ans, nCb);
  std::cout << ans << std::endl;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

LL modpow(LL a, LL n) {
  LL pow = 1;
  while (n > 0) {
    if (n & 1)
      pow = pow * a % kMod;
    a = a * a % kMod;
    n >>= 1;
  }
  return pow;
}

LL modinv(LL a) { return modpow(a, kMod - 2); }

LL modsub(LL a, LL b) { return (a + kMod - b) % kMod; }

LL nCr(LL n, LL r) {
  LL x = 1, y = 1;
  for (int i = 1; i <= r; ++i) {
    x = (x * (n - i + 1)) % kMod;
    y = (y * i) % kMod;
  }
  return (x * modinv(y)) % kMod;
}

int main() {
  LL n, a, b;
  std::cin >> n >> a >> b;

  LL ans = modpow(2, n) - 1;
  LL nCa = nCr(n, a);
  LL nCb = nCr(n, b);

  ans = modsub(ans, nCa);
  ans = modsub(ans, nCb);
  std::cout << ans << std::endl;
}
Problem p02768 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
typedef long long ll;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }

ll pow2(ll n) {
  ll ans = 1;
  rep(i, n) { ans = (ans * 2) % MOD; }
  return ans;
}

ll COM(ll n, ll k) {
  ll ans = 1;
  rep(i, k) {
    ans = ans * (n - i) % MOD;
    ans = ans * modinv(i + 1, MOD) % MOD;
  }
  return ans;
}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = pow2(n) - 1 - COM(n, a) - COM(n, b);
  if (ans < 0) {
    ans += MOD;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
typedef long long ll;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }

ll pow2(ll n) {
  ll ans = 1;
  rep(i, n) { ans = (ans * 2) % MOD; }
  return ans;
}

ll COM(ll n, ll k) {
  ll ans = 1;
  rep(i, k) {
    ans = ans * (n - i) % MOD;
    ans = ans * modinv(i + 1, MOD) % MOD;
  }
  return ans;
}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans =
      (((modpow(2, n, MOD) - 1) % MOD - COM(n, a)) % MOD - COM(n, b)) % MOD;
  if (ans < 0) {
    ans += MOD;
  }
  cout << ans << endl;
}
Problem p02768 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int64_t mod = 1000000007;

int64_t mypow(int64_t x, int64_t y) {
  if (y == 1)
    return x;
  else if (y % 2 == 1)
    return mypow(x, y - 1) * x % mod;
  else {
    int64_t tmp = mypow(x, y / 2);
    return tmp * tmp % mod;
  }
}

int64_t soujo(int64_t x, int64_t y) // x~y
{
  if (x == y)
    return y;
  else
    return x * soujo(x + 1, y) % mod;
}

int64_t combi(int64_t x, int64_t y) // y C x,y < x
{
  int64_t X = soujo(x - y + 1, x);
  int64_t Y = soujo(1, y);
  return X * mypow(Y, mod - 2) % mod;
}

int main() {
  int64_t N, A, B;
  cin >> N >> A >> B;

  int64_t ans = mypow(2, N) - 1;
  ans -= combi(N, min(A, N - A));
  ans -= combi(N, min(B, N - B));
  cout << (ans + mod * 2) % mod;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int64_t mod = 1000000007;

int64_t mypow(int64_t x, int64_t y) {
  if (y == 1)
    return x;
  else if (y % 2 == 1)
    return mypow(x, y - 1) * x % mod;
  else {
    int64_t tmp = mypow(x, y / 2);
    return tmp * tmp % mod;
  }
}

int64_t soujo(int64_t x, int64_t y) // x~y
{
  if (x == y)
    return y;
  else
    return x * soujo(x + 1, y) % mod;
}

int64_t combi(int64_t x, int64_t y) // y C x,y < x
{
  int64_t X = soujo(x - y + 1, x);
  int64_t Y = soujo(1, y);
  return X * mypow(Y, mod - 2) % mod;
}

int main() {
  int64_t N, A, B;
  cin >> N >> A >> B;

  int64_t ans = mypow(2, N) - 1;
  ans -= combi(N, A);
  ans -= combi(N, B);
  cout << (ans + mod * 2) % mod;
}
Problem p02768 (Python)

Buggy submission (status: Runtime Error):
def create_array(n: int, r: int, mod, mod2):
    m_ls = [1] * (r + 1)

    for i, j in zip(range(n, 0, -1), range(1, r + 1)):
        m_ls[j] = (m_ls[j - 1] * i * pow(j, mod2, mod)) % mod
    return m_ls


def main():
    n, a, b = map(int, input().split())
    _mod = 1_000_000_007
    _mod2 = 1_000_000_005

    m_ls = create_array(n, b, _mod, _mod2)

    _all_cnts = pow(2, n, _mod) - 1
    ans = _all_cnts + (_mod - m_ls[a]) + (_mod - m_ls[b])
    ans %= _mod

    print(ans)


main()


Fixed submission:
def create_array(n: int, r: int, mod, mod2):
    m_ls = [1] * (r + 1)

    for i, j in zip(range(n, 0, -1), range(1, r + 1)):
        m_ls[j] = (m_ls[j - 1] * i * pow(j, mod2, mod)) % mod
    return m_ls


def main():
    n, a, b = map(int, input().split())
    _mod = 1000000007
    _mod2 = 1000000005

    m_ls = create_array(n, b, _mod, _mod2)

    _all_cnts = pow(2, n, _mod) - 1
    ans = _all_cnts + (_mod - m_ls[a]) + (_mod - m_ls[b])
    ans %= _mod

    print(ans)


main()
Problem p02768 (Python)

Buggy submission (status: Runtime Error):
n, a, b = map(int, input().split())
mod = 10**9 + 7
max = min(n, 2 * 10**5)

fac1 = [n] * max
fac2 = [1] * max
for i in range(2, max):
    fac1[i] = fac1[i - 1] * (n - i + 1) % mod
    fac2[i] = fac2[i - 1] * i % mod
c = fac1[a] * pow(fac2[a], mod - 2, mod) % mod
d = fac1[b] * pow(fac2[b], mod - 2, mod) % mod

print((pow(2, n, mod) - c - d - 1) % mod)


Fixed submission:
n, a, b = map(int, input().split())
mod = 10**9 + 7
max = min(n, 2 * 10**5)

fac1 = [n] * (max + 1)
fac2 = [1] * (max + 1)
for i in range(2, max + 1):
    fac1[i] = fac1[i - 1] * (n - i + 1) % mod
    fac2[i] = fac2[i - 1] * i % mod
c = fac1[a] * pow(fac2[a], mod - 2, mod) % mod
d = fac1[b] * pow(fac2[b], mod - 2, mod) % mod

print((pow(2, n, mod) - c - d - 1) % mod)
Problem p02768 (Python)

Buggy submission (status: Runtime Error):
n, a, b = map(int, input().split())
mod = 10**9 + 7


def choose(n, r, mod):
    r = min(r, n - r)
    x = 1
    y = 1
    for i in range(r):
        x = x * (n - i) % mod
        y = y * (i + 1) % mod
    y = pow(y, -2, mod)
    return x * y % mod


ans = pow(2, n, mod) - 1 - choose(n, a, mod) - choose(n, b, mod)

while ans < 0:
    ans += mod
print(ans)


Fixed submission:
n, a, b = map(int, input().split())
mod = 10**9 + 7


def choose(n, r, mod):
    r = min(r, n - r)
    x = 1
    y = 1
    for i in range(r):
        x = x * (n - i) % mod
        y = y * (i + 1) % mod
    y = pow(y, mod - 2, mod)
    return x * y % mod


ans = pow(2, n, mod) - 1 - choose(n, a, mod) - choose(n, b, mod)

while ans < 0:
    ans += mod
print(ans)
Problem p02768 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

const ll MAX = 200005;
ll fac[MAX], finv[MAX], inv[MAX];
void cominit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for (ll i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}

ll com(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 or k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = 1;
  rep(i, n) {
    ans *= 2;
    ans %= mod;
  }
  ans--;
  cominit();
  ll tmp = 1;
  ll invv = 1;
  rep(i, a) { tmp = tmp * (n - i) % mod; }
  tmp = tmp * finv[a] % mod;
  ans = ans + mod - tmp;
  ans %= mod;
  tmp = 1;
  invv = 1;
  rep(i, b) { tmp = tmp * (n - i) % mod; }
  tmp = tmp * finv[b] % mod;
  ans = ans + mod - tmp;
  ans %= mod;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

const ll MAX = 200005;
ll fac[MAX], finv[MAX], inv[MAX];
void cominit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for (ll i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}

ll com(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 or k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = 1;
  ll tt = n;
  ll aa = 2;
  while (tt > 0) {
    if (tt & 1)
      ans = ans * aa % mod;
    aa = aa * aa % mod;
    tt >>= 1;
  }
  ans--;
  cominit();
  ll tmp = 1;
  ll invv = 1;
  rep(i, a) { tmp = tmp * (n - i) % mod; }
  tmp = tmp * finv[a] % mod;
  ans = ans + mod - tmp;
  ans %= mod;
  tmp = 1;
  invv = 1;
  rep(i, b) { tmp = tmp * (n - i) % mod; }
  tmp = tmp * finv[b] % mod;
  ans = ans + mod - tmp;
  ans %= mod;
  cout << ans << endl;
  return 0;
}
Problem p02768 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAX = 310000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  ll result = n;
  for (int i = 1; i < k; i++) {
    result = (result * (n - i)) % MOD;
  }
  return result * (finv[k] % MOD) % MOD;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, A, B;
  cin >> N >> A >> B;
  COMinit();
  ll answer = 1;
  for (int i = 0; i < N; i++) {
    answer = (answer * 2) % MOD;
  }
  answer--;
  answer = (answer - COM(N, A) + MOD) % MOD;
  answer = (answer - COM(N, B) + MOD) % MOD;
  cout << answer << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAX = 310000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  ll result = n;
  for (int i = 1; i < k; i++) {
    result = (result * (n - i)) % MOD;
  }
  return result * (finv[k] % MOD) % MOD;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, A, B;
  cin >> N >> A >> B;
  COMinit();
  ll answer = 1;
  ll kisuu = 2;
  ll temp = N;
  while (temp > 0) {
    if (temp & 1) {
      answer = (answer * kisuu) % MOD;
    }
    kisuu = (kisuu * kisuu) % MOD;
    temp >>= 1;
  }
  answer--;
  answer = (answer - COM(N, A) + MOD) % MOD;
  answer = (answer - COM(N, B) + MOD) % MOD;
  cout << answer << endl;
  return 0;
}
Problem p02768 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

const double PI = acos(-1.0);
const ll MOD = 1000000007ll;

ll n, a, b;
ll kai[200010];
ll inkai[200010];
void input() { cin >> n >> a >> b; }

ll power(ll p, ll q) {
  ll res = 1;
  while (q > 0) {
    if (q & 1)
      res = res * p % MOD;
    p = p * p % MOD;
    q >>= 1;
  }
  return res;
}

ll nCr(ll p, ll q) {
  ll res = 1;
  for (ll i = 0; i < q; ++i)
    res = res * (p - i) % MOD;
  res = res * inkai[q] % MOD;
  return res;
}

void solve() {
  kai[1] = 1ll;
  for (ll i = 1; i < 200010; ++i)
    kai[i + 1] = ((i + 1ll) * kai[i]) % MOD;
  inkai[200005] = power(kai[200005], MOD - 2ll);
  for (ll i = 200005; i > 0; --i)
    inkai[i - 1] = i * inkai[i] % MOD;

  ll ans = power(2, n) - 1ll - nCr(n, a) - nCr(n, b);
  while (ans < 0)
    ans += MOD;
  cout << ans << endl;
}

int main() {
  cin.tie();
  ios::sync_with_stdio(false);
  input();
  solve();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

const double PI = acos(-1.0);
const ll MOD = 1000000007ll;

ll n, a, b;
ll kai[200010];
ll inkai[200010];
void input() { cin >> n >> a >> b; }

ll power(ll p, ll q) {
  ll res = 1;
  while (q > 0) {
    if (q & 1)
      res = res * p % MOD;
    p = p * p % MOD;
    q >>= 1;
  }
  return res;
}

ll nCr(ll p, ll q) {
  ll res = 1;
  for (ll i = 0; i < q; ++i)
    res = res * (p - i) % MOD;
  res = res * inkai[q] % MOD;
  return res;
}

void solve() {
  kai[1] = 1ll;
  for (ll i = 1; i < 200005; ++i)
    kai[i + 1] = ((i + 1ll) * kai[i]) % MOD;
  inkai[200005] = power(kai[200005], MOD - 2ll);
  for (ll i = 200005; i > 0; --i)
    inkai[i - 1] = i * inkai[i] % MOD;

  ll ans = power(2, n) - 1ll - nCr(n, a) - nCr(n, b);
  while (ans < 0)
    ans += MOD;
  cout << ans << endl;
}

int main() {
  cin.tie();
  ios::sync_with_stdio(false);
  input();
  solve();
  return 0;
}
Problem p02768 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 1010001000;
const ll INF = 1001000100010001000;
const int mod = (int)1e9 + 7;

long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

vector<long long> fact, fact_inv,
    inv; // fact[i]=i! nが10^7より大きいと配列が大きすぎる？
void init_nCk(int SIZE) { // inv[i]=i^(-1)
  fact.resize(SIZE + 5);  // fact_inv[i]=inv[i]の累積積
  fact_inv.resize(SIZE + 5);
  inv.resize(SIZE + 5);
  fact[0] = fact[1] = 1;
  fact_inv[0] = fact_inv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < SIZE + 5; i++) {
    fact[i] = fact[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
  }
}

/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int n, int k) {
  assert(!(n < k));
  assert(!(n < 0 || k < 0));
  if (n <= 10000000)
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
  else {
    ll ans = 1;
    for (ll i = n; i > n - k; i--) {
      ans = ans * i % mod;
    }
    for (ll i = 1; i <= k; i++) {
      ans = (ans * modpow(i, mod - 2)) % mod;
    }
    return ans;
  }
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << (2 * mod + modpow(2, n) - 1 - nCk(n, a) - nCk(n, b)) % mod << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 1010001000;
const ll INF = 1001000100010001000;
const int mod = (int)1e9 + 7;

long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

vector<long long> fact, fact_inv,
    inv; // fact[i]=i! nが10^7より大きいと配列が大きすぎる？
void init_nCk(int SIZE) { // inv[i]=i^(-1)
  fact.resize(SIZE + 5);  // fact_inv[i]=inv[i]の累積積
  fact_inv.resize(SIZE + 5);
  inv.resize(SIZE + 5);
  fact[0] = fact[1] = 1;
  fact_inv[0] = fact_inv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < SIZE + 5; i++) {
    fact[i] = fact[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
  }
}

/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int n, int k) {
  assert(!(n < k));
  assert(!(n < 0 || k < 0));
  if (n <= 10000000)
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
  else {
    ll ans = 1;
    for (ll i = n; i > n - k; i--) {
      ans = ans * i % mod;
    }
    for (ll i = 1; i <= k; i++) {
      ans = (ans * modpow(i, mod - 2)) % mod;
    }
    return ans;
  }
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  init_nCk(510000);
  cout << (2 * mod + modpow(2, n) - 1 - nCk(n, a) - nCk(n, b)) % mod << endl;
  return 0;
}
Problem p02768 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>
using namespace std;
long long mod = 1e9 + 7;
struct nCk {
  long long pow(long long x, long long n) {
    long long ret = 1;
    if (n > 0) {
      ret = pow(x, n / 2);
      if (n % 2 == 0) {
        (ret = (ret * ret)) %= mod;
      } else {
        (ret = ((ret * ret) % mod) * x) %= mod;
      }
    }
    return ret;
  }
  long long inv(long long n) { return pow(n, mod - 2); }
  long long nck(long long n, long long k) {
    long long ret = 1;
    for (int i = n; i > n - k; i--) {
      (ret *= i) %= mod;
    }
    for (int i = k; i >= 1; i--) {
      (ret *= inv(i)) %= mod;
    }
    return ret;
  }
};
int main() {
  long long n, a, b;
  cin >> n >> a >> b;
  nCk nii;
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    (ans *= 2) %= mod;
  }
  (ans += mod - 1) %= mod;
  long long A = nii.nck(n, a);
  long long B = nii.nck(n, b);
  (ans += mod - A) %= mod;
  (ans += mod - B) %= mod;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
long long mod = 1e9 + 7;
struct nCk {
  long long pow(long long x, long long n) {
    long long ret = 1;
    if (n > 0) {
      ret = pow(x, n / 2);
      if (n % 2 == 0) {
        (ret = (ret * ret)) %= mod;
      } else {
        (ret = ((ret * ret) % mod) * x) %= mod;
      }
    }
    return ret;
  }
  long long inv(long long n) { return pow(n, mod - 2); }
  long long nck(long long n, long long k) {
    long long ret = 1;
    for (int i = n; i > n - k; i--) {
      (ret *= i) %= mod;
    }
    for (int i = k; i >= 1; i--) {
      (ret *= inv(i)) %= mod;
    }
    return ret;
  }
};
int main() {
  long long n, a, b;
  cin >> n >> a >> b;
  nCk nii;
  long long ans = nii.pow(2, n);
  (ans += mod - 1) %= mod;
  long long A = nii.nck(n, a);
  long long B = nii.nck(n, b);
  (ans += mod - A) %= mod;
  (ans += mod - B) %= mod;
  cout << ans << endl;
  return 0;
}
Problem p02768 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef pair<int, int> pll;
const int maxn = 1e5 + 10;
const int p = 1e9 + 7;
const double EPS = 1e-6;

LL quick_mod(LL a, LL b) {
  LL ans = 1;
  a %= p;
  while (b) {
    if (b & 1) {
      ans = ans * a % p;
      b--;
    }
    b >>= 1;
    a = a * a % p;
  }
  return ans;
}

LL C(LL n, LL m) {
  if (m > n)
    return 0;
  LL ans = 1;
  for (int i = 1; i <= m; i++) {
    LL a = (n + i - m) % p;
    LL b = i % p;
    ans = ans * (a * quick_mod(b, p - 2) % p) % p;
  }
  return ans;
}

LL Lucas(LL n, LL m) {
  if (m == 0)
    return 1;
  return C(n % p, m % p) * Lucas(n / p, m / p) % p;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  LL ans = 0;
  for (int i = 1; i <= n / 2; i++) {
    // int d=Lucas(n,i);
    if (i * 2 < n) {
      ans = (ans + 2 * Lucas(n, i) % p) % p;
    } else {
      ans = (ans + Lucas(n, i)) % p;
    }
  }

  /*cout << ans << endl;
  cout  << Lucas(n,a) << endl;
  cout << Lucas(n,b) << endl;*/
  cout << (ans + 1 - Lucas(n, a) - Lucas(n, b)) % p << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef pair<int, int> pll;
const int maxn = 1e5 + 10;
const int p = 1e9 + 7;
const double EPS = 1e-6;

LL quick_mod(LL a, LL b) {
  LL ans = 1;
  a %= p;
  while (b) {
    if (b & 1) {
      ans = ans * a % p;
      b--;
    }
    b >>= 1;
    a = a * a % p;
  }
  return ans;
}

LL C(LL n, LL m) {
  if (m > n)
    return 0;
  LL ans = 1;
  for (int i = 1; i <= m; i++) {
    LL a = (n + i - m) % p;
    LL b = i % p;
    ans = ans * (a * quick_mod(b, p - 2) % p) % p;
  }
  return ans;
}

LL Lucas(LL n, LL m) {
  if (m == 0)
    return 1;
  return C(n % p, m % p) * Lucas(n / p, m / p) % p;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  // cout << quick_mod(2,n) << " " << Lucas(n,a) << " " << Lucas(n,b) <<  endl;
  cout << ((quick_mod(2, n) - 1 - Lucas(n, a) + p) % p - Lucas(n, b) + p) % p
       << endl;
  return 0;
}
Problem p02769 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX{200010};
const ll MOD{1000000007}, oo{1LL << 62};

ll fs[MAX], inv[MAX];

ll mod_pow(ll a, ll n) {
  ll res = 1, base = a;

  while (n) {
    if (n & 1)
      res = (res * base) % MOD;

    base = (base * base) % MOD;
    n >>= 1;
  }

  return res;
}

void precomp() {
  fs[0] = 1;

  for (ll i = 1; i < MAX; ++i)
    fs[i] = (fs[i - 1] * i) % MOD;

  inv[0] = 1;

  for (ll i = 1; i < MAX; ++i)
    inv[i] = mod_pow(fs[i], MOD - 2);
}

ll mod(ll a) { return (((a % MOD) + MOD) % MOD); }

ll binom(ll n, ll m) {
  ll res = mod(fs[n] * inv[m]);
  res = mod(res * inv[n - m]);

  return res;
}

ll solve(ll N, ll K) {
  if (K >= N - 1)
    return binom(2 * N - 1, N - 1);

  ll ans = 0;

  for (int k = 0; k <= K; ++k) {
    ll x = mod(binom(N - 1, k) * binom(N, k));
    ans = mod(ans + x);
  }

  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  precomp();

  ll N, K;
  cin >> N >> K;

  auto ans = solve(N, K);

  cout << ans << '\n';

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX{400010};
const ll MOD{1000000007}, oo{1LL << 62};

ll fs[MAX], inv[MAX];

ll mod_pow(ll a, ll n) {
  ll res = 1, base = a;

  while (n) {
    if (n & 1)
      res = (res * base) % MOD;

    base = (base * base) % MOD;
    n >>= 1;
  }

  return res;
}

void precomp() {
  fs[0] = 1;

  for (ll i = 1; i < MAX; ++i)
    fs[i] = (fs[i - 1] * i) % MOD;

  inv[0] = 1;

  for (ll i = 1; i < MAX; ++i)
    inv[i] = mod_pow(fs[i], MOD - 2);
}

ll mod(ll a) { return (((a % MOD) + MOD) % MOD); }

ll binom(ll n, ll m) {
  ll res = mod(fs[n] * inv[m]);
  res = mod(res * inv[n - m]);

  return res;
}

ll solve(ll N, ll K) {
  if (K >= N - 1)
    return binom(2 * N - 1, N - 1);

  ll ans = 0;

  for (int k = 0; k <= K; ++k) {
    ll x = mod(binom(N - 1, k) * binom(N, k));
    ans = mod(ans + x);
  }

  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  precomp();

  ll N, K;
  cin >> N >> K;

  auto ans = solve(N, K);

  cout << ans << '\n';

  return 0;
}
Problem p02769 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
const int N = 1e5 + 10;
ll a[N];
ll qmi(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
ll c(ll n, ll m) {
  return a[n] % mod * qmi(a[m], mod - 2) % mod * qmi(a[n - m], mod - 2) % mod;
}
int main() {
  a[0] = 1;
  for (int i = 1; i < N; i++)
    a[i] = a[i - 1] * i % mod;
  ll ans = 0;
  ll n, k;
  cin >> n >> k;
  for (int i = 0; i <= min(k, n - 1); i++)
    ans = (ans + c(n, i) * c(n - 1, i) % mod) % mod; //, cout << ans << endl ;
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
const int N = 2e5 + 10;
ll a[N];
ll qmi(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
ll c(ll n, ll m) {
  return a[n] % mod * qmi(a[m], mod - 2) % mod * qmi(a[n - m], mod - 2) % mod;
}
int main() {
  a[0] = 1;
  for (int i = 1; i < N; i++)
    a[i] = a[i - 1] * i % mod;
  ll ans = 0;
  ll n, k;
  cin >> n >> k;
  for (int i = 0; i <= min(k, n - 1); i++)
    ans = (ans + c(n, i) * c(n - 1, i) % mod) % mod; //, cout << ans << endl ;
  printf("%lld\n", ans);
  return 0;
}
Problem p02769 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
const ll p = 1e9 + 7;
int a[N];
ll inv(ll a, ll p) { // p为素数,a<p
  if (a == 1)
    return 1;
  return (p - p / a) * inv(p % a, p) % p;
}
ll C(ll n, ll m) {
  ll res = 1;
  for (ll i = 1, j = n - m + 1; i <= m; ++i, ++j) {
    res = res * inv(i, p) % p * j % p;
  }
  return res;
}
int main() {
  ll n, m;
  cin >> n >> m;
  ll res = 0;
  for (int i = 0; i <= min(m, n - 1); ++i)
    res = (res + C(n, i) * C(n - 1, i) % p) % p;
  cout << res;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
const ll p = 1e9 + 7;
int a[N];
ll inv(ll a, ll p) { // p为素数,a<p
  if (a == 1)
    return 1;
  return (p - p / a) * inv(p % a, p) % p;
}
ll C(ll n, ll m) {
  ll res = 1;
  for (ll i = 1, j = n - m + 1; i <= m; ++i, ++j) {
    res = res * inv(i, p) % p * j % p;
  }
  return res;
}
int main() {
  ll n, m;
  cin >> n >> m;
  ll res = 0;
  ll C1 = 1, C2 = 1;
  for (int i = 0; i <= min(m, n - 1); ++i) {
    res = (res + C1 * C2 % p) % p;
    C1 = C1 * inv(i + 1, p) % p * (n - i) % p;
    C2 = C2 * inv(i + 1, p) % p * (n - i - 1) % p;
  }
  cout << res;
  return 0;
}
Problem p02769 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define r1(i, n) for (int i = 0; i < n; i++)
#define r2(i, n) for (int i = 1; i < n; i++)
#define intc(n)                                                                \
  int n;                                                                       \
  cin >> n;
#define ll long long
#define llc(n)                                                                 \
  ll n;                                                                        \
  cin >> n;
using namespace std;
// テーブルを作る前処理
const ll MAX = 300000;
const ll mod = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}
// 二項係数計算
ll COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
  COMinit();
  ll n, k, ans = 0;
  cin >> n >> k;
  r1(i, k + 1) {
    ll a = COM(n, i) % mod;
    a = a * (COM(n - 1, i) % mod) % mod;
    ans = (ans + a) % mod;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define r1(i, n) for (int i = 0; i < n; i++)
#define r2(i, n) for (int i = 1; i < n; i++)
#define intc(n)                                                                \
  int n;                                                                       \
  cin >> n;
#define ll long long
#define llc(n)                                                                 \
  ll n;                                                                        \
  cin >> n;
using namespace std;
// テーブルを作る前処理
const ll MAX = 300000;
const ll mod = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}
// 二項係数計算
ll COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
  COMinit();
  ll n, k, ans = 0;
  cin >> n >> k;
  r1(i, min(n, k + 1)) {
    ll a = COM(n, i) % mod;
    a = a * (COM(n - 1, i) % mod) % mod;
    ans = (ans + a) % mod;
  }
  cout << ans << endl;
}
Problem p02769 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
typedef long long ll;

ll mod = 1000000007;
ll modsize = 200010;
vector<ll> fac(modsize);
vector<ll> inv(modsize);
vector<ll> facinv(modsize);

void modcalc() {
  if (modsize == 0)
    abort();
  fac[0] = 1;
  fac[1] = 1;
  inv[1] = 1;
  facinv[0] = 1;
  facinv[1] = 1;
  for (ll i = 2; i < modsize; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    facinv[i] = facinv[i - 1] * inv[i] % mod;
  }
}

ll modinv(ll a) {
  if (a == 0)
    abort();
  ll b = mod, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

ll modcomb(ll n, ll k) {
  if (n < 0 || k < 0 || n < k)
    return 0;
  return fac[n] * facinv[k] % mod * facinv[n - k] % mod;
}

int main() {
  modcalc();

  int n, k;
  cin >> n >> k;
  ll ans = 0;
  rep(i, k + 1) {
    ans += modcomb(n, i) * modcomb(n - 1, n - i - 1);
    ans %= mod;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
typedef long long ll;

ll mod = 1000000007;
ll modsize = 200010;
vector<ll> fac(modsize);
vector<ll> inv(modsize);
vector<ll> facinv(modsize);

void modcalc() {
  if (modsize == 0)
    abort();
  fac[0] = 1;
  fac[1] = 1;
  inv[1] = 1;
  facinv[0] = 1;
  facinv[1] = 1;
  for (ll i = 2; i < modsize; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    facinv[i] = facinv[i - 1] * inv[i] % mod;
  }
}

ll modinv(ll a) {
  if (a == 0)
    abort();
  ll b = mod, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

ll modcomb(ll n, ll k) {
  if (n < 0 || k < 0 || n < k)
    return 0;
  return fac[n] * facinv[k] % mod * facinv[n - k] % mod;
}

int main() {
  modcalc();

  int n, k;
  cin >> n >> k;
  ll ans = 0;
  k = min(k, n - 1);
  rep(i, k + 1) {
    ans += modcomb(n, i) * modcomb(n - 1, n - i - 1);
    ans %= mod;
  }
  cout << ans << endl;
}