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

Buggy submission (status: Runtime Error):
/*


*/

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};

#define endl '\n'
#define ld long double
#define ll long long
#define PI acos(-1.0)
#define OO 1e17
#define EPS 1e-12
#define MLOG 20
#define MAX 20 * 100 * 100 + 5
const int mod = 1e9 + 7;

int dcmp(long double x, long double y) {
  return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1;
}

void fast() {
#ifndef ONLINE_JUDGE
  freopen("E:\\Competitve\\solving\\input.txt", "r", stdin);
  freopen("E:\\Competitve\\solving\\output.txt", "w", stdout);
#endif

  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
int n, k;
int dislike;
int main() {
  fast();
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int x;
    cin >> x;
    dislike |= (1 << x);
  }
  for (int i = n;; i++) {
    int x = i;
    bool ok = 1;
    while (x) {
      int d = x % 10;
      if (dislike & (1 << d)) {
        ok = 0;
        break;
      }
      x /= 10;
    }
    if (ok)
      return cout << i << endl, 0;
  }

  return 0;
}

Fixed submission:
/*


*/

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};

#define endl '\n'
#define ld long double
#define ll long long
#define PI acos(-1.0)
#define OO 1e17
#define EPS 1e-12
#define MLOG 20
#define MAX 20 * 100 * 100 + 5
const int mod = 1e9 + 7;

int dcmp(long double x, long double y) {
  return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1;
}

void fast() {
#ifndef ONLINE_JUDGE
  freopen("E:\\Competitve\\solving\\input.txt", "r", stdin);
  freopen("E:\\Competitve\\solving\\output.txt", "w", stdout);
#endif

  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
int n, k;
int dislike;
int main() {
  // fast();
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int x;
    cin >> x;
    dislike |= (1 << x);
  }
  for (int i = n;; i++) {
    int x = i;
    bool ok = 1;
    while (x) {
      int d = x % 10;
      if (dislike & (1 << d)) {
        ok = 0;
        break;
      }
      x /= 10;
    }
    if (ok)
      return cout << i << endl, 0;
  }

  return 0;
}
Problem p04039 (Python)

Buggy submission (status: Time Limit Exceeded):
N, K = map(int, input().split())
D = set(input())

n = N
while True:
    if set(str(n)) in D:
        print(n)
        break
    n += 1


Fixed submission:
N, K = map(int, input().split())
D = set(input())

n = N
while True:
    if len(set(str(n)) & D) == 0:
        print(n)
        break
    n += 1
Problem p04039 (C++)

Buggy submission (status: Runtime Error):
// C.

#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int d[10];

int solve(int n, int x, int f) {
  if (f <= 0) {
    return x;
  }
  int a = (n % (f * 10)) / f;
  int b = (x % (f * 10)) / f;
  if (!d[b]) {
    return solve(n, x, f / 10);
  }
  int c = b;
  while (d[c]) {
    while (++c >= 10) {
      f *= 10;
      c = (x % (f * 10)) / f + 1;
    }
  }
  x -= x % (f * 10);
  x += c * f;
  for (int i = 0; i <= 9; ++i) {
    if (!d[i]) {
      while (f > 0) {
        f /= 10;
        x += i * f;
      }
      break;
    }
  }
  return x;
}

int main(int argc, char *argv[]) {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    int x;
    cin >> x;
    d[x] = 1;
  }
  int f = 1;
  for (int i = n; i >= 10; i /= 10) {
    f *= 10;
  }
  cout << solve(n, n, f) << endl;
  return 0;
}


Fixed submission:
// C.

#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int d[10];

int solve(int n, int x, int f) {
  if (f <= 0) {
    return x;
  }
  int a = (n % (f * 10)) / f;
  int b = (x % (f * 10)) / f;
  if (!d[b]) {
    return solve(n, x, f / 10);
  }
  int c = b;
  while (d[c]) {
    ++c;
    while (c >= 10) {
      f *= 10;
      c = (x % (f * 10)) / f + 1;
    }
  }
  x -= x % (f * 10);
  x += c * f;
  for (int i = 0; i <= 9; ++i) {
    if (!d[i]) {
      while (f > 0) {
        f /= 10;
        x += i * f;
      }
      break;
    }
  }
  return x;
}

int main(int argc, char *argv[]) {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    int x;
    cin >> x;
    d[x] = 1;
  }
  int f = 1;
  for (int i = n; i >= 10; i /= 10) {
    f *= 10;
  }
  cout << solve(n, n, f) << endl;
  return 0;
}
Problem p04039 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0)
#define pb push_back
// #define mp make_pair
#define ff first
#define ss second
#define debug(x) cout << "### x is: " << x << "###" << endl
#define all(a) a.begin(), a.end()
#define tc                                                                     \
  int t;                                                                       \
  scanf("%d", &t);                                                             \
  while (t-- 0)
#define int long long
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
int power(int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1)
      ret *= a;
    a *= a;
    if (ret >= MOD)
      ret %= MOD;
    if (a >= MOD)
      a %= MOD;
    b >>= 1;
  }
  return ret;
}
int invmod(int x) { return power(x, MOD - 2); }
int a[N];
map<int, int> mp;
int check(int n) {
  while (n > 0) {
    if (mp[n % 10])
      return 0;
  }
  return 1;
}
int32_t main() {
  int n, k;
  cin >> n >> k;

  for (int i = 1; i <= k; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  for (int i = n; i <= 1000000; i++) {
    if (check(i)) {
      cout << i << endl;
      return 0;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0)
#define pb push_back
// #define mp make_pair
#define ff first
#define ss second
#define debug(x) cout << "### x is: " << x << "###" << endl
#define all(a) a.begin(), a.end()
#define tc                                                                     \
  int t;                                                                       \
  scanf("%d", &t);                                                             \
  while (t-- 0)
#define int long long
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
int power(int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1)
      ret *= a;
    a *= a;
    if (ret >= MOD)
      ret %= MOD;
    if (a >= MOD)
      a %= MOD;
    b >>= 1;
  }
  return ret;
}
int invmod(int x) { return power(x, MOD - 2); }
int a[N];
map<int, int> mp;
int check(int n) {
  while (n > 0) {
    if (mp[n % 10])
      return 0;
    n /= 10;
  }
  return 1;
}
int32_t main() {
  int n, k;
  cin >> n >> k;

  for (int i = 1; i <= k; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  for (int i = n; i <= 1000000; i++) {
    if (check(i)) {
      cout << i << endl;
      return 0;
    }
  }
}
Problem p04039 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int a[1000], b[1000], leng = 0;
int f() {
  int i, j;
  for (i = 1; i <= leng; i++)
    if (b[a[i]] > 0)
      return 1;
  return 0;
}
int main() {
  int i, j, l;
  long long k, n, m;
  cin >> k >> n;
  for (i = 1; i <= n; i++)
    cin >> l, b[l]++;
  m = k;
  while (m > 0) {
    a[++leng] = m % 10;
    m /= 10;
  }
  while (f()) {
    int s1 = f();
    k++;
    while (a[s1] >= 10)
      a[s1] = 0, s1++, a[s1]++;
    leng = max(leng, s1);
  }
  cout << k << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int a[1000], b[1000], leng = 0;
int f() {
  int i, j;
  for (i = 1; i <= leng; i++)
    if (b[a[i]] > 0)
      return 1;
  return 0;
}
int main() {
  int i, j, l;
  long long k, n, m;
  cin >> k >> n;
  for (i = 1; i <= n; i++)
    cin >> l, b[l]++;
  m = k;
  while (m > 0) {
    a[++leng] = m % 10;
    m /= 10;
  }
  while (f()) {
    int s1 = f();
    a[s1]++;
    k++;
    while (a[s1] >= 10)
      a[s1] = 0, s1++, a[s1]++;
    leng = max(leng, s1);
  }
  cout << k << endl;
  return 0;
}
Problem p04039 (C++)

Buggy submission (status: Runtime Error):
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

int n, k;
bool bad[30];

inline bool ok(int x) {
  while (x) {
    int dig = x % 10;
    if (bad[dig])
      return 0;
    x /= 10;
  }
  return 1;
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

  cin >> n;

  cin >> k;
  while (k--) {
    int x;
    cin >> x;
    bad[x] = 1;
  }

  n--;
  while (n++) {
    if (ok(n))
      return cout << n << '\n', 0;
  }

  assert(0);
}


Fixed submission:
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

int n, k;
bool bad[30];

inline bool ok(int x) {
  while (x) {
    int dig = x % 10;
    if (bad[dig])
      return 0;
    x /= 10;
  }
  return 1;
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

  cin >> n;

  cin >> k;
  while (k--) {
    int x;
    cin >> x;
    bad[x] = 1;
  }

  n--;
  while (++n) {
    if (ok(n))
      return cout << n << '\n', 0;
  }

  assert(0);
}
Problem p04039 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> cannot(10);
  while (K--) {
    int D;
    cin >> D;
    cannot[D] = 1;
  }
  for (int i = N;; i++) {
    int j = i;
    bool bad = false;
    while (j) {
      int D = j % 10;
      bad |= cannot[D];
    }
    if (!bad) {
      cout << i;
      return 0;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> cannot(10);
  while (K--) {
    int D;
    cin >> D;
    cannot[D] = 1;
  }
  for (int i = N;; i++) {
    int j = i;
    bool bad = false;
    while (j) {
      int D = j % 10;
      bad |= cannot[D];
      j /= 10;
    }
    if (!bad) {
      cout << i;
      return 0;
    }
  }
  return 0;
}
Problem p04039 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

bool bad[11];

int n, k;

bool ok(int x) {
  while (x) {
    int y = x % 10;
    x /= 10;
    if (bad[x])
      return false;
  }
  return true;
}

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= k; i++) {
    int x;
    scanf("%d", &x);
    bad[x] = true;
  }
  for (int x = n;; x++) {
    if (ok(x)) {
      printf("%d\n", x);
      return 0;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

bool bad[11];

int n, k;

bool ok(int x) {
  while (x) {
    int y = x % 10;
    x /= 10;
    if (bad[y])
      return false;
  }
  return true;
}

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= k; i++) {
    int x;
    scanf("%d", &x);
    bad[x] = true;
  }
  for (int x = n;; x++) {
    if (ok(x)) {
      printf("%d\n", x);
      return 0;
    }
  }
}
Problem p04039 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll, ll>
#define pii pair<ll, pi>
#define pb push_back
#define mk make_pair
vector<int> dislike(10, 0);
int n, k;
bool solve(ll n) {
  bool ok = false;
  while (n != 0) {
    ll l = n % 10;
    if (dislike[l]) {
      ok = true;
      break;
    }
    n = n / 10;
  }
  if (ok == false)
    return true;
  return false;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    ll c;
    cin >> c;
    dislike[c]++;
  }
  for (int i = n;; i++) {
    if (solve(i)) {
      cout << i << endl;
      return 0;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll, ll>
#define pii pair<ll, pi>
#define pb push_back
#define mk make_pair
vector<int> dislike(10, 0);
int n, k;
bool solve(ll n) {
  bool ok = false;
  while (n != 0) {
    ll l = n % 10;
    if (dislike[l]) {
      ok = true;
      break;
    }
    n = n / 10;
  }
  if (ok == false)
    return true;
  return false;
}

int main() {
  // #ifndef ONLINE_JUDGE
  // 	freopen("input.txt", "r", stdin);
  // 	freopen("output.txt", "w", stdout);
  // #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    ll c;
    cin >> c;
    dislike[c]++;
  }
  for (int i = n;; i++) {
    if (solve(i)) {
      cout << i << endl;
      return 0;
    }
  }
}
Problem p04040 (C++)

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

typedef long long llong;
const llong mod = 1e9 + 7;
const int maxn = 100000 + 5;
llong c1[maxn];
llong c2[maxn];
llong inv[maxn];

void Prepare_inv() {
  inv[1] = 1; // 1 µÄÄæÔªÊÇ1
  for (llong i = 2; i < maxn; i++) {
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
    // printf("inv[%lld]=%lld\n", i, inv[i]);
  }
}

void C1(llong n, llong r) {
  c1[r] = 1;
  for (llong i = r + 1; i <= n; i++) {
    c1[i] = c1[i - 1] * i % mod * inv[i - r] % mod;
    // printf("c1[%lld][%lld]=%lld\n", i, r, c1[i]);
  }
}

void C2(llong n, llong r) {
  c2[r] = 1;
  for (llong i = r + 1; i <= n; i++) {
    c2[i] = c2[i - 1] * i % mod * inv[i - r] % mod;
    // printf("c2[%lld][%lld]=%lld\n", i, r, c2[i]);
  }
}

int main() {
  Prepare_inv();

  llong h, w, a, b;
  while (scanf("%lld %lld %lld %lld", &h, &w, &a, &b) != EOF) {
    if (h <= a || w <= b) {
      puts("0");
      continue;
    }

    C1(h - a + b - 2, b - 1);
    C2(w - b + h - 2, w - b - 1);

    llong ans = 0;
    llong right = 0;
    llong left = 0;
    for (llong i = h - a + b - 2; i >= b - 1; i--) {
      left = c1[i];
      right = c2[h + w - 3 - i];
      ans = (ans + left * right % mod) % mod;
      // printf("i=%lld j=%lld %lld %lld %lld\n", i, h+w-3-i, left, right, ans);
    }

    printf("%lld\n", ans);
  }
  return 0;
}


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

typedef long long llong;
const llong mod = 1e9 + 7;
const int maxn = 300000 + 5;
llong c1[maxn];
llong c2[maxn];
llong inv[maxn];

void Prepare_inv() {
  inv[1] = 1; // 1 µÄÄæÔªÊÇ1
  for (llong i = 2; i < maxn; i++) {
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
    // printf("inv[%lld]=%lld\n", i, inv[i]);
  }
}

void C1(llong n, llong r) {
  c1[r] = 1;
  for (llong i = r + 1; i <= n; i++) {
    c1[i] = c1[i - 1] * i % mod * inv[i - r] % mod;
    // printf("c1[%lld][%lld]=%lld\n", i, r, c1[i]);
  }
}

void C2(llong n, llong r) {
  c2[r] = 1;
  for (llong i = r + 1; i <= n; i++) {
    c2[i] = c2[i - 1] * i % mod * inv[i - r] % mod;
    // printf("c2[%lld][%lld]=%lld\n", i, r, c2[i]);
  }
}

int main() {
  Prepare_inv();

  llong h, w, a, b;
  while (scanf("%lld %lld %lld %lld", &h, &w, &a, &b) != EOF) {
    if (h <= a || w <= b) {
      puts("0");
      continue;
    }

    C1(h - a + b - 2, b - 1);
    C2(w - b + h - 2, w - b - 1);

    llong ans = 0;
    llong right = 0;
    llong left = 0;
    for (llong i = h - a + b - 2; i >= b - 1; i--) {
      left = c1[i];
      right = c2[h + w - 3 - i];
      ans = (ans + left * right % mod) % mod;
      // printf("i=%lld j=%lld %lld %lld %lld\n", i, h+w-3-i, left, right, ans);
    }

    printf("%lld\n", ans);
  }
  return 0;
}
Problem p04040 (C++)

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

const int MAX = 100005;
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;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int H, W, A, B;
  scanf("%d %d %d %d", &H, &W, &A, &B);
  long long ans = 0;
  COMinit();
  for (int i = 1; i <= H - A; i++) {
    ans += COM(B + i - 2, i - 1) * COM(W - B - 1 + H - i, H - i) % MOD;
    ans %= MOD;
  }
  printf("%lld\n", ans);
  return 0;
}

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

const int MAX = 200005;
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;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int H, W, A, B;
  scanf("%d %d %d %d", &H, &W, &A, &B);
  long long ans = 0;
  COMinit();
  for (int i = 1; i <= H - A; i++) {
    ans += COM(B + i - 2, i - 1) * COM(W - B - 1 + H - i, H - i) % MOD;
    ans %= MOD;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p04040 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); (i)++)
#define all(x) x.begin(), x.end()

typedef long long i64;

i64 MOD = 1e9 + 7;

// Eucli
i64 inv_mod(i64 a, i64 m = MOD) {
  i64 b, x, u, q, abs_m, tmp;

  abs_m = (m < 0) ? -m : m;
  b = m;
  x = 1;
  u = 0;
  while (b > 0) {
    q = a / b;
    tmp = u;
    u = x - q * u;
    x = tmp;
    tmp = b;
    b = a - q * b;
    a = tmp;
  }

  return (x < 0) ? abs_m + x : x;
}

i64 fact[202020];

i64 nCr(int n, int r) {
  return (fact[n] * inv_mod(fact[r]) % MOD * inv_mod(fact[n - r]) % MOD) % MOD;
}

// 重複組み合わせ
i64 nHr(int n, int r) { return (nCr(n + r - 1, r)) % MOD; }

int main() {
  int h, w;
  cin >> h >> w;
  int a, b;
  cin >> a >> b;
  fact[0] = 1;
  rep(i, 1, 202020 - 1) { fact[i] = (fact[i - 1] * i) % MOD; }

  i64 ans = 0;
  rep(i, 0, h - a - 1) {
    (ans += nCr(i, i + b - 1) * nCr(h - i - 1, h - i - 1 * w - b - 1) % MOD) %=
        MOD;
  }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); (i)++)
#define all(x) x.begin(), x.end()

typedef long long i64;

i64 MOD = 1e9 + 7;

// Eucli
i64 inv_mod(i64 a, i64 m = MOD) {
  i64 b, x, u, q, abs_m, tmp;

  abs_m = (m < 0) ? -m : m;
  b = m;
  x = 1;
  u = 0;
  while (b > 0) {
    q = a / b;
    tmp = u;
    u = x - q * u;
    x = tmp;
    tmp = b;
    b = a - q * b;
    a = tmp;
  }

  return (x < 0) ? abs_m + x : x;
}

i64 fact[202020];

i64 nCr(int n, int r) {
  return (fact[n] * inv_mod(fact[r]) % MOD * inv_mod(fact[n - r]) % MOD) % MOD;
}

// 重複組み合わせ
i64 nHr(int n, int r) { return (nCr(n + r - 1, r)) % MOD; }

int main() {
  int h, w;
  cin >> h >> w;
  int a, b;
  cin >> a >> b;
  fact[0] = 1;
  rep(i, 1, 202020 - 1) { fact[i] = (fact[i - 1] * i) % MOD; }

  i64 ans = 0;
  rep(i, 0, h - a - 1) {
    (ans += nCr(i + b - 1, i) * nCr(h - i - 1 + w - b - 1, h - i - 1) % MOD) %=
        MOD;
  }

  cout << ans << endl;
}
Problem p04040 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
ll fact[maxn], inv[maxn];
ll ksm(ll a, ll b) {
  ll ans = 1, base = a;
  while (b) {
    if (b & 1)
      ans = ans * base % mod;
    b >>= 1;
    base = base * base % mod;
  }
  return ans;
}
ll C(int n, int m) {
  ll res = fact[n] * inv[m] % mod;
  res = res * inv[n - m] % mod;
  return res;
}
int main() {
  fact[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < maxn; i++) {
    fact[i] = fact[i - 1] * i % mod;
    inv[i] = ksm(fact[i], mod - 2) % mod;
  }
  ios::sync_with_stdio(false);
  ll n, m, a, b;
  cin >> n >> m >> a >> b;

  ll ans = 0;
  for (int i = 0; i <= m - b - 1; i++) {
    ans =
        (ans + C(n - a + b - 1, b + i) * C(m - b - 1 + a, m - b - 1 - i)) % mod;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
ll fact[maxn], inv[maxn];
ll ksm(ll a, ll b) {
  ll ans = 1, base = a;
  while (b) {
    if (b & 1)
      ans = ans * base % mod;
    b >>= 1;
    base = base * base % mod;
  }
  return ans;
}
ll C(int n, int m) {
  ll res = fact[n] * inv[m] % mod;
  res = res * inv[n - m] % mod;
  return res;
}
int main() {
  fact[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < maxn; i++) {
    fact[i] = fact[i - 1] * i % mod;
    inv[i] = ksm(fact[i], mod - 2) % mod;
  }
  ios::sync_with_stdio(false);
  ll n, m, a, b;
  cin >> n >> m >> a >> b;

  ll ans = 0;
  for (int i = 0; i <= min(m - b - 1, n - a - 1); i++) {
    ans =
        (ans + C(n - a + b - 1, b + i) * C(m - b - 1 + a, m - b - 1 - i)) % mod;
  }
  cout << ans << endl;
  return 0;
}
Problem p04040 (C++)

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

int H, W, A, B;
long fact[220000];
long rfact[220000];
const long MOD = 1000000007;
long extgcd(long a, long b, long &x, long &y) {
  long d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

long mod_inverse(long a) {
  long x, y;
  extgcd(a, MOD, x, y);
  x %= MOD;
  if (x < 0)
    x += MOD;
  return x;
}
int init() {
  rfact[0] = fact[0] = 1;
  for (int i = 1; i < 220000; i++) {
    fact[i] = (fact[i - 1] * i) % MOD;
    rfact[i] = mod_inverse(fact[i]);
  }
}

long comb(long N, long K) {
  if (K < 0)
    return 0;
  if (N - K < 0)
    return 0;
  return ((fact[N] * rfact[K]) % MOD * rfact[N - K]) % MOD;
}

int main() {
  init();
  cin >> H >> W >> A >> B;
  long res = comb(H + W - 2, H - 1);
  for (int i = 0; i < B; i++) {
    res -= (comb(i + (H - A - 1), i) * comb(A - 1 + (W - 1 - i), A - 1)) % MOD;
    if (res < 0)
      res += MOD;
  }
  cout << res << endl;
}


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

int H, W, A, B;
long fact[220000];
long rfact[220000];
const long MOD = 1000000007;
long extgcd(long a, long b, long &x, long &y) {
  long d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

long mod_inverse(long a) {
  long x, y;
  extgcd(a, MOD, x, y);
  x %= MOD;
  if (x < 0)
    x += MOD;
  return x;
}
void init() {
  rfact[0] = fact[0] = 1;
  for (int i = 1; i < 220000; i++) {
    fact[i] = (fact[i - 1] * i) % MOD;
    rfact[i] = mod_inverse(fact[i]);
  }
}

long comb(long N, long K) {
  if (K < 0)
    return 0;
  if (N - K < 0)
    return 0;
  return ((fact[N] * rfact[K]) % MOD * rfact[N - K]) % MOD;
}

int main() {
  init();
  cin >> H >> W >> A >> B;
  long res = comb(H + W - 2, H - 1);
  for (int i = 0; i < B; i++) {
    res -= (comb(i + (H - A - 1), i) * comb(A - 1 + (W - 1 - i), A - 1)) % MOD;
    if (res < 0)
      res += MOD;
  }
  cout << res << endl;
}
Problem p04040 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll, ll>
#define pii pair<ll, pi>
#define pb push_back
#define mk make_pair
const ll siz = 1e5 + 7;
const ll mod = 1e9 + 7;
ll fac[siz];
ll inv[siz];
ll binpow(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}

ll ncr(ll n, ll r) {
  if (r == 0 || n == r)
    return 1;
  return (((fac[n] * inv[n - r]) % mod) * inv[r]) % mod;
}

int main() {
  // #ifndef ONLINE_JUDGE
  // 	freopen("input.txt", "r", stdin);
  // 	freopen("output.txt", "w", stdout);
  // #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll h, w, a, b;
  cin >> h >> w >> a >> b;
  fac[0] = 1;
  for (int i = 1; i < siz; i++) {
    fac[i] = (fac[i - 1] * i) % mod;
    inv[i] = binpow(fac[i], mod - 2);
  }
  ll ans = 0;
  for (int i = b; i < w; i++) {
    int y1 = h - a - 1, x1 = i;
    int y2 = a - 1, x2 = w - i - 1;
    ll res = (ncr(x1 + y1, x1)) * (ncr(x2 + y2, x2)) % mod;
    ans = (ans + res) % mod;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll, ll>
#define pii pair<ll, pi>
#define pb push_back
#define mk make_pair
const ll siz = 1e6 + 7;
const ll mod = 1e9 + 7;
ll fac[siz];
ll inv[siz];
ll binpow(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}

ll ncr(ll n, ll r) {
  if (r == 0 || n == r)
    return 1;
  return (((fac[n] * inv[n - r]) % mod) * inv[r]) % mod;
}

int main() {
  // #ifndef ONLINE_JUDGE
  // 	freopen("input.txt", "r", stdin);
  // 	freopen("output.txt", "w", stdout);
  // #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll h, w, a, b;
  cin >> h >> w >> a >> b;
  fac[0] = 1;
  for (int i = 1; i < siz; i++) {
    fac[i] = (fac[i - 1] * i) % mod;
    inv[i] = binpow(fac[i], mod - 2);
  }
  ll ans = 0;
  for (int i = b; i < w; i++) {
    int y1 = h - a - 1, x1 = i;
    int y2 = a - 1, x2 = w - i - 1;
    ll res = (ncr(x1 + y1, x1)) * (ncr(x2 + y2, x2)) % mod;
    ans = (ans + res) % mod;
  }
  cout << ans << endl;
}
Problem p04040 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repn(i, n) for (ll i = 0; i <= (ll)(n); i++)
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
// cin.tie(0);
// ios::sync_with_stdio(false);

const ll MAX = 100010; // 設定して

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;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

signed main() {
  ll h, w, a, b, ans = 0;
  cin >> h >> w >> a >> b;
  COMinit();

  ll x = h - a - 1, y = b;

  while (0 <= x && y < w) {
    (ans += (COM(x + y, y) % mod) *
            (COM(h - 1 - x + w - 1 - y, w - 1 - y) % mod)) %= mod;
    // ans%=mod;
    x--;
    y++;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repn(i, n) for (ll i = 0; i <= (ll)(n); i++)
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
// cin.tie(0);
// ios::sync_with_stdio(false);

const ll MAX = 300010; // 設定して

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;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

signed main() {
  ll h, w, a, b, ans = 0;
  cin >> h >> w >> a >> b;
  COMinit();

  ll x = h - a - 1, y = b;

  while (0 <= x && y < w) {
    (ans += (COM(x + y, y) % mod) *
            (COM(h - 1 - x + w - 1 - y, w - 1 - y) % mod)) %= mod;
    // ans%=mod;
    x--;
    y++;
  }
  cout << ans << endl;
}
Problem p04040 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7; //  必须为质数才管用
const ll MAXN = 1e5 + 3;

ll fac[MAXN]; //  阶乘
ll inv[MAXN]; //  阶乘的逆元

ll QPow(ll x, ll n) {
  ll ret = 1;
  ll tmp = x % MOD;
  while (n) {
    if (n & 1) {
      ret = (ret * tmp) % MOD;
    }
    tmp = tmp * tmp % MOD;
    n >>= 1;
  }

  return ret;
}

void Init() {
  fac[0] = 1;
  for (int i = 1; i < MAXN; i++) {
    fac[i] = fac[i - 1] * i % MOD;
  }
  inv[MAXN - 1] = QPow(fac[MAXN - 1], MOD - 2);
  for (int i = MAXN - 2; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1) % MOD;
  }
}
ll C(int a, int b) {
  if (a < 0 || b < 0)
    return 1;
  return fac[a] * inv[b] % MOD * inv[a - b] % MOD;
}
int main() {
  int H, W, A, B;
  int N;
  scanf("%d%d%d%d", &H, &W, &A, &B);
  N = H + W - 2;
  Init();
  ll ans = C(H + W - 2, H - 1);
  for (ll i = 1; i <= B; i++) {
    ans -= C(H - A + i - 2, H - A - 1) * C(A - 1 + W - i, A - 1) % MOD;
    ans = (ans % MOD + MOD) % MOD;
  }
  printf("%lld", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7; //  必须为质数才管用
const ll MAXN = 2e5 + 3;

ll fac[MAXN]; //  阶乘
ll inv[MAXN]; //  阶乘的逆元

ll QPow(ll x, ll n) {
  ll ret = 1;
  ll tmp = x % MOD;
  while (n) {
    if (n & 1) {
      ret = (ret * tmp) % MOD;
    }
    tmp = tmp * tmp % MOD;
    n >>= 1;
  }

  return ret;
}

void Init() {
  fac[0] = 1;
  for (int i = 1; i < MAXN; i++) {
    fac[i] = fac[i - 1] * i % MOD;
  }
  inv[MAXN - 1] = QPow(fac[MAXN - 1], MOD - 2);
  for (int i = MAXN - 2; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1) % MOD;
  }
}
ll C(int a, int b) {
  if (a < 0 || b < 0)
    return 1;
  return fac[a] * inv[b] % MOD * inv[a - b] % MOD;
}
int main() {
  int H, W, A, B;
  int N;
  scanf("%d%d%d%d", &H, &W, &A, &B);
  N = H + W - 2;
  Init();
  ll ans = C(H + W - 2, H - 1);
  for (ll i = 1; i <= B; i++) {
    ans -= C(H - A + i - 2, H - A - 1) * C(A - 1 + W - i, A - 1) % MOD;
    ans = (ans % MOD + MOD) % MOD;
  }
  printf("%lld", ans);
  return 0;
}
Problem p04040 (C++)

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

using i64 = long long;

const i64 MOD = 1e9 + 7;
const int N = 1e5 + 5;

i64 fact[N];

i64 ant;

static i64 expow(i64 b, i64 e) {
  i64 ant(1);

  for (; e > 0; e /= 2) {
    if (e % 2)
      ant = ant * b % MOD;
    b = b * b % MOD;
  }

  return ant;
}

static i64 inv(i64 x) { return expow(x, MOD - 2); }

static i64 comb(i64 n, i64 k) {
  return fact[n] * inv(fact[n - k]) % MOD * inv(fact[k]) % MOD;
}

static i64 roads(int a, int b) { return comb(a + b, b); }

int main() {
#ifdef HOME
  freopen("atc.in", "r", stdin);
  freopen("atc.out", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, m, a, b;

  fact[0] = 1;
  for (int i = 1; i < N; ++i)
    fact[i] = fact[i - 1] * i % MOD;

  cin >> n >> m >> a >> b;

  a = n - a + 1;

  for (int i = 1; a - i > 0 && b + i <= m; ++i)
    ant =
        (ant + roads(a - i - 1, b + i - 1) * roads(n - (a - i), m - (b + i))) %
        MOD;

  cout << ant << endl;
  cerr << ant << endl;

  return 0;
}


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

using i64 = long long;

const i64 MOD = 1e9 + 7;
const int N = 2e5 + 5;

i64 fact[N];

i64 ant;

static i64 expow(i64 b, i64 e) {
  i64 ant(1);

  for (; e > 0; e /= 2) {
    if (e % 2)
      ant = ant * b % MOD;
    b = b * b % MOD;
  }

  return ant;
}

static i64 inv(i64 x) { return expow(x, MOD - 2); }

static i64 comb(i64 n, i64 k) {
  return fact[n] * inv(fact[n - k]) % MOD * inv(fact[k]) % MOD;
}

static i64 roads(int a, int b) { return comb(a + b, b); }

int main() {
#ifdef HOME
  freopen("atc.in", "r", stdin);
  freopen("atc.out", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, m, a, b;

  fact[0] = 1;
  for (int i = 1; i < N; ++i)
    fact[i] = fact[i - 1] * i % MOD;

  cin >> n >> m >> a >> b;

  a = n - a + 1;

  for (int i = 1; a - i > 0 && b + i <= m; ++i)
    ant =
        (ant + roads(a - i - 1, b + i - 1) * roads(n - (a - i), m - (b + i))) %
        MOD;

  cout << ant << endl;
  cerr << ant << endl;

  return 0;
}
Problem p04040 (C++)

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

const long long MOD = 1000000007;

int main() {
  long long h, w, a, b, result = 0;
  cin >> h >> w >> a >> b;
  long long factorial[w * h], ifactorial[w + h], inv[w + h];
  factorial[0] = 1;
  ifactorial[0] = 1;
  inv[1] = 1;
  factorial[1] = 1;
  ifactorial[1] = 1;
  for (long long i = 2; i < w + h; i++) {
    factorial[i] = factorial[i - 1] * i % MOD;
    inv[i] = (-MOD / i + MOD) * inv[MOD % i] % MOD;
    ifactorial[i] = ifactorial[i - 1] * inv[i] % MOD;
  }
  function<long long(long long, long long)> binomial = [&](long long n,
                                                           long long k) {
    return factorial[n] * ifactorial[k] % MOD * ifactorial[n - k] % MOD;
  };
  for (long long i = 0; i < h - a; i++) {
    result = (result +
              binomial(b + i - 1, i) * binomial(w - b + h - i - 2, h - i - 1)) %
             MOD;
  }
  cout << result;
  return 0;
}


Fixed submission:
#include <functional>
#include <iostream>
using namespace std;

const long long MOD = 1000000007;

int main() {
  long long h, w, a, b, result = 0;
  cin >> h >> w >> a >> b;
  long long factorial[w + h], ifactorial[w + h], inv[w + h];
  factorial[0] = 1;
  ifactorial[0] = 1;
  inv[1] = 1;
  factorial[1] = 1;
  ifactorial[1] = 1;
  for (long long i = 2; i < w + h; i++) {
    factorial[i] = factorial[i - 1] * i % MOD;
    inv[i] = (-MOD / i + MOD) * inv[MOD % i] % MOD;
    ifactorial[i] = ifactorial[i - 1] * inv[i] % MOD;
  }
  function<long long(long long, long long)> binomial = [&](long long n,
                                                           long long k) {
    return factorial[n] * ifactorial[k] % MOD * ifactorial[n - k] % MOD;
  };
  for (long long i = 0; i < h - a; i++) {
    result = (result +
              binomial(b + i - 1, i) * binomial(w - b + h - i - 2, h - i - 1)) %
             MOD;
  }
  cout << result;
  return 0;
}
Problem p04040 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9 + 7;
const int N = 100000 + 5;
const int dx[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dy[] = {-1, 1, 0, 0, -1, 1, -1, 1};
using namespace std;
LL factor[N];
LL PowMod(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 inv(LL x) { return PowMod(x, MOD - 2); }
LL C(LL n, LL m) {
  return factor[n] * inv(factor[m]) % MOD * inv(factor[n - m]) % MOD;
}
void init() {
  factor[0] = 1;
  for (int i = 1; i <= N; i++)
    factor[i] = (factor[i - 1] * i) % MOD;
}
int main() {
  init();
  LL h, w, A, B;
  scanf("%lld%lld%lld%lld", &h, &w, &A, &B);
  LL res = 0;
  for (LL i = B + 1; i <= w; i++) {
    LL temp = (C(i - 1 + h - A - 1, h - A - 1) * C(w - i + A - 1, w - i)) % MOD;
    res = (res + temp) % MOD;
  }
  printf("%lld\n", res);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9 + 7;
const int N = 200000 + 5;
const int dx[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dy[] = {-1, 1, 0, 0, -1, 1, -1, 1};
using namespace std;
LL factor[N];
LL PowMod(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 inv(LL x) { return PowMod(x, MOD - 2); }
LL C(LL n, LL m) {
  return factor[n] * inv(factor[m]) % MOD * inv(factor[n - m]) % MOD;
}
void init() {
  factor[0] = 1;
  for (int i = 1; i <= N; i++)
    factor[i] = (factor[i - 1] * i) % MOD;
}
int main() {
  init();
  LL h, w, A, B;
  scanf("%lld%lld%lld%lld", &h, &w, &A, &B);
  LL res = 0;
  for (LL i = B + 1; i <= w; i++) {
    LL temp = (C(i - 1 + h - A - 1, h - A - 1) * C(w - i + A - 1, w - i)) % MOD;
    res = (res + temp) % MOD;
  }
  printf("%lld\n", res);
  return 0;
}
Problem p04041 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
// T+N
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <class T, class T2> inline bool chkmax(T &x, const T2 &y) {
  return x < y ? x = y, 1 : 0;
}
template <class T, class T2> inline bool chkmin(T &x, const T2 &y) {
  return x > y ? x = y, 1 : 0;
}
const ll mod = 1e9 + 7;
template <class T> inline void fix(T &x) {
  if (x >= mod || x <= -mod) {
    x %= mod;
  }
  if (x < 0) {
    x += mod;
  }
}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 20;
ll dp[2 * MAX_N][1 << MAX_N];

signed main() {
  // ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  ll n, x, y, z;
  cin >> n >> x >> y >> z;
  ll full = (1 << (x + y + z)) - 1;
  x = x + y + z - 1;
  y = y + z - 1;
  z = z - 1;
  ll bad = (1 << x) | (1 << y) | (1 << z);
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= full; j++) {
      if ((j & bad) == bad) {
        continue;
      }
      // cout << i << " " << j << " " << dp[i][j] << endl;
      for (int k = 1; k <= 10; k++) {
        dp[i + 1][((1 << (k - 1)) | (j << k)) & full] += dp[i][j];
        fix(dp[i][j]);
      }
    }
  }
  ll ret = 1;
  for (int i = 0; i < n; i++) {
    ret = (ret * 10) % mod;
  }
  for (int i = 0; i <= full; i++) {
    if ((i & bad) == bad) {
      continue;
    }
    ret -= dp[n][i];
    fix(ret);
  }
  cout << ret << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// T+N
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <class T, class T2> inline bool chkmax(T &x, const T2 &y) {
  return x < y ? x = y, 1 : 0;
}
template <class T, class T2> inline bool chkmin(T &x, const T2 &y) {
  return x > y ? x = y, 1 : 0;
}
const ll mod = 1e9 + 7;
template <class T> inline void fix(T &x) {
  if (x >= mod || x <= -mod) {
    x %= mod;
  }
  if (x < 0) {
    x += mod;
  }
}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 20;
ll dp[2 * MAX_N + 10][1 << MAX_N];

signed main() {
  // ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  ll n, x, y, z;
  cin >> n >> x >> y >> z;
  ll full = (1 << (x + y + z)) - 1;
  x = x + y + z - 1;
  y = y + z - 1;
  z = z - 1;
  ll bad = (1 << x) | (1 << y) | (1 << z);
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= full; j++) {
      if ((j & bad) == bad) {
        continue;
      }
      // cout << i << " " << j << " " << dp[i][j] << endl;
      for (int k = 1; k <= 10; k++) {
        dp[i + 1][((1 << (k - 1)) | (j << k)) & full] += dp[i][j];
        fix(dp[i][j]);
      }
    }
  }
  ll ret = 1;
  for (int i = 0; i < n; i++) {
    ret = (ret * 10) % mod;
  }
  for (int i = 0; i <= full; i++) {
    if ((i & bad) == bad) {
      continue;
    }
    ret -= dp[n][i];
    fix(ret);
  }
  cout << ret << endl;
  return 0;
}
Problem p04041 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

const int mmod = 1000000007;

int prv[1 << 18], nxt[1 << 18];

int main() {
  int n, x, y, z;
  cin >> n >> x >> y >> z;
  prv[0] = 1;

  int sum = x + y + z;

  for (int iter = 0; iter < n; iter++) {
    for (int i = 0; i < (1 << sum); i++)
      nxt[i] = 0;

    for (int i = 0; i < (1 << sum); i++) {
      for (int add = 1; add <= 10; add++) {
        int bit = 0;
        if (i & (1 << (sum - 1)))
          bit = 1 << (sum - 1);
        if (add <= 7)
          for (int j = 0; j < sum; j++) {
            if (j > 0 && !(i & (1 << (j - 1))))
              continue;
            if (j == sum) {
              bit |= 1 << (j - 1);
              continue;
            }
            int k = j + add;
            if (j < x && k > x)
              continue;
            if (j < x + y && k > x + y)
              continue;
            if (k > x + y + z)
              break;
            bit |= 1 << (k - 1);
          }
        nxt[bit] = (nxt[bit] + prv[i]);
        if (nxt[bit] >= mmod)
          nxt[bit] -= mmod;
      }
    }

    for (int i = 0; i < (1 << sum); i++)
      prv[i] = nxt[i];
  }

  int ret = 0;
  for (int i = 0; i < (1 << sum); i++)
    if (i & (1 << (sum - 1)))
      ret = (ret + prv[i]) % mmod;

  printf("%d\n", ret);
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

const int mmod = 1000000007;

int prv[1 << 18], nxt[1 << 18];

int main() {
  int n, x, y, z;
  cin >> n >> x >> y >> z;
  prv[0] = 1;

  int sum = x + y + z;

  for (int iter = 0; iter < n; iter++) {
    for (int i = 0; i < (1 << sum); i++)
      nxt[i] = 0;

    for (int i = 0; i < (1 << sum); i++) {
      for (int add = 1; add <= 10; add++) {
        int bit = 0;
        if (i & (1 << (sum - 1)))
          bit = 1 << (sum - 1);
        if (add <= x)
          bit |= 1 << (add - 1);

        for (int j = 1; j + add <= x; j++) {
          if (!(i & (1 << (j - 1))))
            continue;
          int k = j + add;
          bit |= 1 << (k - 1);
        }

        for (int j = x; j + add <= x + y; j++) {
          if (!(i & (1 << (j - 1))))
            continue;
          int k = j + add;
          bit |= 1 << (k - 1);
        }

        for (int j = x + y; j + add <= x + y + z; j++) {
          if (!(i & (1 << (j - 1))))
            continue;
          int k = j + add;
          bit |= 1 << (k - 1);
        }

        nxt[bit] += prv[i];
        if (nxt[bit] >= mmod)
          nxt[bit] -= mmod;
      }
    }

    for (int i = 0; i < (1 << sum); i++)
      prv[i] = nxt[i];
  }

  int ret = 0;
  for (int i = 0; i < (1 << sum); i++)
    if (i & (1 << (sum - 1)))
      ret = (ret + prv[i]) % mmod;

  printf("%d\n", ret);
}
Problem p04041 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T> void cout_vec(const vector<T> &vec) {
  for (auto itr : vec)
    cout << itr << ' ';
  cout << endl;
}

typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const ll inf = 1e15;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, x, y, z;
  cin >> n >> x >> y >> z;
  vector<vector<ll>> dp(n + 1, vector<ll>((1ll << (x + y + z + 10)) + 10, 0));
  ll mask = (1ll << (x + y + z - 1)) - 1;
  ll ng = 0;
  ng |= (1 << (x + y + z - 1));
  ng |= (1 << (y + z - 1));
  ng |= (1 << (z - 1));
  dp[0][0] = 1;
  rep(i, n) {
    rep(S, 1 << (x + y + z - 1)) {
      if ((S & ng) == ng)
        continue;
      FOR(j, 1, 11) {
        ll T = (S << j) | (1 << (j - 1));
        if ((T & ng) == ng)
          continue;
        T &= mask;
        (dp[i + 1][T] += dp[i][S]) %= mod;
      }
    }
  }
  ll ans = 1;
  rep(i, n)(ans *= 10) %= mod;
  rep(i, 1 << (x + y + z - 1))(ans -= dp[n][i]) %= mod;
  cout << (ans + mod) % mod << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T> void cout_vec(const vector<T> &vec) {
  for (auto itr : vec)
    cout << itr << ' ';
  cout << endl;
}

typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const ll inf = 1e15;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, x, y, z;
  cin >> n >> x >> y >> z;
  vector<vector<ll>> dp(n + 1, vector<ll>((1ll << (x + y + z - 1)) + 10, 0));
  ll mask = (1ll << (x + y + z - 1)) - 1;
  ll ng = 0;
  ng |= (1 << (x + y + z - 1));
  ng |= (1 << (y + z - 1));
  ng |= (1 << (z - 1));
  dp[0][0] = 1;
  rep(i, n) {
    rep(S, 1 << (x + y + z - 1)) {
      if ((S & ng) == ng)
        continue;
      FOR(j, 1, 11) {
        ll T = (S << j) | (1 << (j - 1));
        if ((T & ng) == ng)
          continue;
        T &= mask;
        (dp[i + 1][T] += dp[i][S]) %= mod;
      }
    }
  }
  ll ans = 1;
  rep(i, n)(ans *= 10) %= mod;
  rep(i, 1 << (x + y + z - 1))(ans -= dp[n][i]) %= mod;
  cout << (ans + mod) % mod << endl;
}