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

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

using namespace std;

using ll = long long;

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

  int n, a;
  cin >> n >> a;

  vector<int> x(n);
  for (int i = 0; i < n; ++i)
    cin >> x[i];

  const int MAX_SUM = n * *max_element(x.begin(), x.end()) + 10;
  vector<vector<ll>> dp(n + 1, vector<ll>(MAX_SUM));
  dp[0][0] = 1;
  for (int i = 1, sum = 0; i <= n; ++i) {
    for (int j = i - 1; 0 <= j; --j) {
      for (int k = 0; k <= sum; ++k) {
        dp[j + 1][k + x[i - 1]] += dp[j][k];
      }
    }
    sum += x[i - 1];
  }

  ll res = 0;
  for (int i = 1; i <= n; ++i)
    res += dp[i][a * i];
  cout << res << endl;

  return 0;
}


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

using namespace std;

using ll = long long;

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

  int n, a;
  cin >> n >> a;

  vector<int> x(n);
  for (int i = 0; i < n; ++i)
    cin >> x[i];

  const int MAX_SUM = 50 * 50 + 50;
  vector<vector<ll>> dp(n + 1, vector<ll>(MAX_SUM));
  dp[0][0] = 1;
  for (int i = 1, sum = 0; i <= n; ++i) {
    for (int j = i - 1; 0 <= j; --j) {
      for (int k = 0; k <= sum; ++k) {
        dp[j + 1][k + x[i - 1]] += dp[j][k];
      }
    }
    sum += x[i - 1];
  }

  ll res = 0;
  for (int i = 1; i <= n; ++i)
    res += dp[i][a * i];
  cout << res << endl;

  return 0;
}
Problem p04013 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>

using namespace std;

typedef long long ll;

ll d[51][2501];

int main() {
  int n, a, x[50];
  scanf("%d %d", &n, &a);
  int m = a;
  for (int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
    m = max(m, x[i]);
    x[i] -= a;
  }
  d[0][n * m] = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= 2 * n * m; j++) {
      d[i + 1][j] = d[i][j];
      if (0 <= j - x[i] && j - x[i] <= 2 * n * m)
        d[i + 1][j] += d[i][j - x[i]];
    }
  printf("%lld\n", d[n][n * m] - 1);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>

using namespace std;

typedef long long ll;

ll d[51][5001];

int main() {
  int n, a, x[50];
  scanf("%d %d", &n, &a);
  int m = a;
  for (int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
    m = max(m, x[i]);
    x[i] -= a;
  }
  d[0][n * m] = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= 2 * n * m; j++) {
      d[i + 1][j] = d[i][j];
      if (0 <= j - x[i] && j - x[i] <= 2 * n * m)
        d[i + 1][j] += d[i][j - x[i]];
    }
  printf("%lld\n", d[n][n * m] - 1);
  return 0;
}
Problem p04013 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;

int main() {
  ll n, a;
  cin >> n >> a;
  vector<ll> x(n);
  ll ma = a;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    ma = max(ma, x[i]);
    x[i] -= a;
  }
  ll dp[51][10010] = {};
  ll nx = ma * n;
  for (ll i = 0; i <= n; i++) {
    for (ll j = 0; j <= 2 * nx; j++) {
      if (i == 0 && j == nx)
        dp[i][j] = 1;
      else if ((j >= 0 && j - x[i - 1] < 0) || (j - x[i - 1] > 2 * nx))
        dp[i][j] = dp[i - 1][j];
      else if (j >= 1 && 0 <= j - x[i - 1] && j - x[i - 1] <= 2 * nx)
        dp[i][j] = dp[i - 1][j] + dp[i - 1][j - x[i - 1]];
      else
        dp[i][j] = 0;
    }
  }
  dump(dp[n][nx] - 1);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;

int main() {
  ll n, a;
  cin >> n >> a;
  vector<ll> x(n);
  ll ma = a;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    ma = max(ma, x[i]);
    x[i] -= a;
  }
  ll dp[51][5010] = {};
  ll nx = ma * n;
  for (ll i = 0; i <= n; i++) {
    for (ll j = 0; j <= 2 * nx; j++) {
      if (i == 0 && j == nx)
        dp[i][j] = 1;
      else if ((j >= 0 && j - x[i - 1] < 0) || (j - x[i - 1] > 2 * nx))
        dp[i][j] = dp[i - 1][j];
      else if (j >= 1 && 0 <= j - x[i - 1] && j - x[i - 1] <= 2 * nx)
        dp[i][j] = dp[i - 1][j] + dp[i - 1][j - x[i - 1]];
      else
        dp[i][j] = 0;
    }
  }
  dump(dp[n][nx] - 1);
  return 0;
}
Problem p04013 (C++)

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

int main() {
  int n, a;
  cin >> n >> a;

  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }

  // dp[i][j][k] = up to i-th card, used j cards, sum k
  vector<vector<vector<long long int>>> dp(
      51, vector<vector<long long int>>(51, vector<long long int>(2501)));
  dp[0][0][0] = 1;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      for (int k = 0; k < 2501; k++) {
        dp[i + 1][j][k] += dp[i][j][k];
        if (k - x[i] >= 0)
          dp[i + 1][j + 1][k] += dp[i][j][k - x[i]];
        // if(dp[i][j][k] != 0) cout << "dp[" << i << "][" << j << "][" << k <<
        // "] = " << dp[i][j][k] << endl;
      }
    }
  }

  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += dp[n][i][i * a];
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n, a;
  cin >> n >> a;

  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }

  // dp[i][j][k] = up to i-th card, used j cards, sum k
  vector<vector<vector<long long int>>> dp(
      51, vector<vector<long long int>>(51, vector<long long int>(2501)));
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < 2501; k++) {
        dp[i + 1][j][k] += dp[i][j][k];
        if (k - x[i] >= 0)
          dp[i + 1][j + 1][k] += dp[i][j][k - x[i]];
        // if(dp[i][j][k] != 0) cout << "dp[" << i << "][" << j << "][" << k <<
        // "] = " << dp[i][j][k] << endl;
      }
    }
  }

  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += dp[n][i][i * a];
  }
  cout << ans << endl;
  return 0;
}
Problem p04013 (C++)

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

long long arr[51][3000][51];
int x[51];
int main() {
  int n, avg;
  cin >> n >> avg;
  for (int i = 1; i < n + 1; i++) {
    cin >> x[i];
  }

  for (int i = 1; i < n + 1; i++) {
    arr[i - 1][0][0] = 1;
    for (int j = 0; j < 2700; j++) {
      for (int z = 0; z < n + 1; z++) {
        arr[i][j + x[i]][z + 1] += arr[i - 1][j][z];
        arr[i + 1][j][z] = arr[i][j][z];
      }
    }
  }

  long long answer = 0;

  for (int i = 0; i < n + 1; i++) {
    answer += arr[n][i * avg][i];
  }

  cout << answer;
  return 0;
}

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

long long arr[52][3000][52];
int x[51];
int main() {
  int n, avg;
  cin >> n >> avg;
  for (int i = 1; i < n + 1; i++) {
    cin >> x[i];
  }

  for (int i = 1; i < n + 1; i++) {
    arr[i - 1][0][0] = 1;
    for (int j = 0; j < 2700; j++) {
      for (int z = 0; z < n + 1; z++) {
        arr[i][j + x[i]][z + 1] += arr[i - 1][j][z];
        arr[i + 1][j][z] = arr[i][j][z];
      }
    }
  }

  long long answer = 0;

  for (int i = 0; i < n + 1; i++) {
    answer += arr[n][i * avg][i];
  }

  cout << answer;
  return 0;
}
Problem p04013 (C++)

Buggy submission (status: Runtime Error):
#pragma once
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];

int c[30];
ll dp[51][2510];
void Sequence() {
  int n, a;
  cin >> n >> a;

  dp[0][0] = 1;
  for (size_t i = 0; i < n; i++) {
    int x;
    cin >> x;
    for (int j = 50; j >= 0; j--) {
      for (size_t k = 0; k < 2501; k++) {
        dp[j + 1][k + x] += dp[j][k];
      }
    }
  }

  ll res = 0;
  for (size_t i = 1; i < 51; i++) {
    for (size_t j = 1; j < 2501; j++) {
      if (j == a * i) {
        res += dp[i][j];
      }
    }
  }
  cout << res << endl;
}
int main() {
  Sequence();
  return 0;
}


Fixed submission:
#pragma once
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];

int c[30];
ll dp[52][2510];
void Sequence() {
  int n, a;
  cin >> n >> a;

  dp[0][0] = 1;
  for (size_t i = 0; i < n; i++) {
    int x;
    cin >> x;
    for (int j = 50; j >= 0; j--) {
      for (size_t k = 0; k < 2501; k++) {
        dp[j + 1][k + x] += dp[j][k];
      }
    }
  }

  ll res = 0;
  for (size_t i = 1; i < 51; i++) {
    for (size_t j = 1; j < 2501; j++) {
      if (j == a * i) {
        res += dp[i][j];
      }
    }
  }
  cout << res << endl;
}
int main() {
  Sequence();
  return 0;
}
Problem p04013 (C++)

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

long long n, a;
long long x[55] = {0};
long long dp[55][55][5550] = {0};

long long solve();

int main() {
  cin >> n >> a;
  for (int i = 0; i < n; ++i)
    cin >> x[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0;
  for (int i = 0; i <= n; ++i)
    dp[i][0][0] = 1;
  for (int i = 0; i < n; ++i)
    for (int j = 1; j <= n; ++j)
      for (long long k = 1; k <= 3000; ++k) {
        dp[i + 1][j][k] += dp[i][j][k];
        if (k >= x[i])
          dp[i + 1][j][k] += dp[i][j - 1][k - x[i]];
      }
  for (long long i = 1; i * a <= 3000; ++i)
    ans += dp[n][i][i * a];
  return ans;
}

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

long long n, a;
long long x[55] = {0};
long long dp[55][55][5550] = {0};

long long solve();

int main() {
  cin >> n >> a;
  for (int i = 0; i < n; ++i)
    cin >> x[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0;
  for (int i = 0; i <= n; ++i)
    dp[i][0][0] = 1;
  for (int i = 0; i < n; ++i)
    for (int j = 1; j <= n; ++j)
      for (long long k = 1; k <= 3000; ++k) {
        dp[i + 1][j][k] += dp[i][j][k];
        if (k >= x[i])
          dp[i + 1][j][k] += dp[i][j - 1][k - x[i]];
      }
  for (long long i = 1; i <= n && i * a <= 3000; ++i)
    ans += dp[n][i][i * a];
  return ans;
}
Problem p04013 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;

int main() {
  int n, a;
  cin >> n >> a;
  int sum = 0;
  int x[n + 1];
  rrep(i, 1, n + 1) {
    cin >> x[i];
    sum += x[i];
  }
  // x1, x2, ..., xj からk個選んで合計sにする
  ll dp[n + 1][n + 1][sum + 1];
  rep(s, n * a + 1) rep(j, n + 1) rep(k, n + 1) {
    if (j >= 1 && s < x[j])
      dp[j][k][s] = dp[j - 1][k][s]; // xj選ばない
    else if (j >= 1 && k >= 1 && s >= x[j])
      dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j]];
    else if (j == 0 && k == 0 && s == 0)
      dp[j][k][s] = 1;
    else
      dp[j][k][s] = 0;
  }
  /*
  rep(s, sum + 1) {
      cout << s << endl;
      rep(j, n + 1) {
          rep(k, n + 1) {
              cout << dp[j][k][s] << " ";

          }
          cout << endl;
      }
      cout << endl;
  }
  */
  ll ans = 0;
  rrep(k, 1, n + 1) ans += dp[n][k][k * a];
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;

int main() {
  int n, a;
  cin >> n >> a;
  int sum = 0;
  int x[n + 1];
  rrep(i, 1, n + 1) {
    cin >> x[i];
    sum += x[i];
  }
  // x1, x2, ..., xj からk個選んで合計sにする
  ll dp[n + 1][n + 1][n * a + 1];
  rep(s, n * a + 1) rep(j, n + 1) rep(k, n + 1) {
    if (j >= 1 && s < x[j])
      dp[j][k][s] = dp[j - 1][k][s]; // xj選ばない
    else if (j >= 1 && k >= 1 && s >= x[j])
      dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j]];
    else if (j == 0 && k == 0 && s == 0)
      dp[j][k][s] = 1;
    else
      dp[j][k][s] = 0;
  }
  /*
  rep(s, sum + 1) {
      cout << s << endl;
      rep(j, n + 1) {
          rep(k, n + 1) {
              cout << dp[j][k][s] << " ";

          }
          cout << endl;
      }
      cout << endl;
  }
  */
  ll ans = 0;
  rrep(k, 1, n + 1) ans += dp[n][k][k * a];
  cout << ans << endl;
}
Problem p04013 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long dp[50][5001];
int main() {
  int n, a;
  cin >> n >> a;
  int x[n];
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    x[i] -= a;
  }
  memset(dp, 0, sizeof(dp));
  dp[0][2500] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 5000; j++) {
      dp[i][j] = dp[i - 1][j];
      if (0 <= j - x[i - 1] && j - x[i - 1] <= 5000)
        dp[i][j] += dp[i - 1][j - x[i - 1]];
    }
  }
  cout << dp[n][2500] - 1 << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long dp[55][5100];
int main() {
  int n, a;
  cin >> n >> a;
  int x[n];
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    x[i] -= a;
  }
  memset(dp, 0, sizeof(dp));
  dp[0][2500] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 5000; j++) {
      dp[i][j] = dp[i - 1][j];
      if (0 <= j - x[i - 1] && j - x[i - 1] <= 5000)
        dp[i][j] += dp[i - 1][j - x[i - 1]];
    }
  }
  cout << dp[n][2500] - 1 << endl;
}
Problem p04013 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;

// ABC044 C - 高橋くんとカード
// 2020.06.16
// dp[i][j][k] :=
// i番目までのカードを見たときに、j枚選んで、合計kとなる組み合わせ

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, A;
  cin >> N >> A;
  vector<ll> X(N);
  ll sumX = 0;
  REPLL(i, N) {
    cin >> X[i];
    sumX += X[i];
  }
  vector<vector<vector<ll>>> dp(
      N + 5, vector<vector<ll>>(N + 5, vector<ll>(N * A + 5, 0)));
  dp[0][0][0] = 1;
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j <= N; j++) {
      for (ll k = 0; k <= N * A; k++) {
        dp[i + 1][j][k] += dp[i][j][k];
        if (k + X[i] <= sumX + 1)
          dp[i + 1][j + 1][k + X[i]] += dp[i][j][k];
      }
    }
  }
  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    ans += dp[N][i][i * A];
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;

// ABC044 C - 高橋くんとカード
// 2020.06.16
// dp[i][j][k] :=
// i番目までのカードを見たときに、j枚選んで、合計kとなる組み合わせ

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, A;
  cin >> N >> A;
  vector<ll> X(N);
  ll sumX = 0;
  REPLL(i, N) {
    cin >> X[i];
    sumX += X[i];
  }
  vector<vector<vector<ll>>> dp(
      N + 5, vector<vector<ll>>(N + 5, vector<ll>(N * A + 5, 0)));
  dp[0][0][0] = 1;
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j <= N; j++) {
      for (ll k = 0; k <= N * A; k++) {
        dp[i + 1][j][k] += dp[i][j][k];
        if (k + X[i] <= N * A)
          dp[i + 1][j + 1][k + X[i]] += dp[i][j][k];
      }
    }
  }
  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    ans += dp[N][i][i * A];
  }
  cout << ans << endl;
}
Problem p04013 (C++)

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

int N, A;
int x[50];
long long dp[50][50][3000];

int main() {
  dp[0][0][0] = 1;
  cin >> N >> A;

  int max_sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> x[i];
    max_sum += x[i];
  }

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      for (int k = 0; k < max_sum + 1; ++k) {
        dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
        dp[i + 1][j][k] += dp[i][j][k];
      }
    }
  }

  long long ans = 0;
  for (int i = 1; i < N + 1; ++i) {
    if (i * A > max_sum) {
      break;
    }
    ans += dp[N][i][i * A];
  }
  cout << ans;
  return 0;
}

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

int N, A;
int x[50];
long long dp[51][51][2551];

int main() {
  dp[0][0][0] = 1;
  cin >> N >> A;

  int max_sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> x[i];
    max_sum += x[i];
  }

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      for (int k = 0; k < max_sum + 1; ++k) {
        dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
        dp[i + 1][j][k] += dp[i][j][k];
      }
    }
  }

  long long ans = 0;
  for (int i = 1; i < N + 1; ++i) {
    if (i * A > max_sum) {
      break;
    }
    ans += dp[N][i][i * A];
  }
  cout << ans;
  return 0;
}
Problem p04013 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;
int main() {
  int N, D;
  cin >> N >> D;
  vector<ll> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  vector<vector<vector<ll>>> dp(N + 1,
                                vector<vector<ll>>(N + 1, vector<ll>(2501)));
  dp[0][0][0] = 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= N; j++) {
      for (int k = 0; k <= 2500; k++) {
        dp[i + 1][j][k] += dp[i][j][k];
        dp[i + 1][j + 1][k + A[i]] += dp[i][j][k];
      }
    }
  }
  ll ans = 0;
  for (int j = 1; j <= N; j++) {
    for (int k = 0; k <= 2500; k++) {
      if (j * D != k)
        continue;
      ans += dp[N][j][k];
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;
int main() {
  int N, D;
  cin >> N >> D;
  vector<ll> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  vector<vector<vector<ll>>> dp(N + 1,
                                vector<vector<ll>>(N + 1, vector<ll>(2501)));
  dp[0][0][0] = 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= N; j++) {
      for (int k = 0; k <= 2500; k++) {
        dp[i + 1][j][k] += dp[i][j][k];
        if (j + 1 <= N)
          dp[i + 1][j + 1][k + A[i]] += dp[i][j][k];
      }
    }
  }
  ll ans = 0;
  for (int j = 1; j <= N; j++) {
    for (int k = 0; k <= 2500; k++) {
      if (j * D != k)
        continue;
      ans += dp[N][j][k];
    }
  }
  cout << ans << endl;
}
Problem p04013 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,
// tree_order_statistics_node_update> ordered_set;
#define ll long long
#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define lpri(n) printf("%lld", n)
#define pri(n) printf("%d", n)
#define pln() printf("\n")
#define priln(n) printf("%d\n", n)
#define lpriln(n) printf("%lld\n", n)
#define rep(i, init, n) for (int i = init; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
#define linf LLONG_MAX
#define lninf LLONG_MIN
const ll mod = 1e9 + 7;
const int N = 2504;

int main() {
  int n, avg;
  scn(n);
  scn(avg);

  int a[n];
  rep(i, 0, n) scn(a[i]);

  // dp[ind][sum][cnt]
  ll dp[n + 1][N][n + 1];
  memset(dp, 0, sizeof(dp));

  dp[0][0][0] = 1;

  rep(ind, 0, n) {
    rep(sum, 0, N) {
      rep(cnt, 0, ind + 1) {
        dp[ind + 1][sum][cnt] += dp[ind][sum][cnt];

        assert(sum + a[ind] < N);

        dp[ind + 1][sum + a[ind]][cnt + 1] += dp[ind][sum][cnt];
      }
    }
  }

  ll ans = 0;

  rep(sum, 1, N) {
    rep(cnt, 1, n + 1) if (sum % cnt == 0 and sum / cnt == avg) ans +=
        dp[n][sum][cnt];
  }

  lpri(ans);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,
// tree_order_statistics_node_update> ordered_set;
#define ll long long
#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define lpri(n) printf("%lld", n)
#define pri(n) printf("%d", n)
#define pln() printf("\n")
#define priln(n) printf("%d\n", n)
#define lpriln(n) printf("%lld\n", n)
#define rep(i, init, n) for (int i = init; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
#define linf LLONG_MAX
#define lninf LLONG_MIN
const ll mod = 1e9 + 7;
const int N = 2504;

int main() {
  int n, avg;
  scn(n);
  scn(avg);

  int a[n];
  rep(i, 0, n) scn(a[i]);

  // dp[ind][sum][cnt]
  ll dp[n + 1][N][n + 1];
  memset(dp, 0, sizeof(dp));

  dp[0][0][0] = 1;

  rep(ind, 0, n) {
    rep(sum, 0, N) {
      rep(cnt, 0, ind + 1) {
        dp[ind + 1][sum][cnt] += dp[ind][sum][cnt];

        if (sum + a[ind] < N)
          dp[ind + 1][sum + a[ind]][cnt + 1] += dp[ind][sum][cnt];
      }
    }
  }

  ll ans = 0;

  rep(sum, 1, N) {
    rep(cnt, 1, n + 1) if (sum % cnt == 0 and sum / cnt == avg) ans +=
        dp[n][sum][cnt];
  }

  lpri(ans);

  return 0;
}
Problem p04013 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18 + 99);
static const int INF = 1e9 + 99;

ll ans;
int N, A;
ll x[55], dp[55][2510][55];

int main(void) {
  cin >> N >> A;
  rep(i, 1, N + 1) cin >> x[i];

  dp[0][0][0] = 1;
  for (int i = 1; i <= N; i++)
    for (int j = 0; j <= 2500; j++)
      for (int k = 0; k <= N; k++) {
        dp[i][j][k] += dp[i - 1][j][k];
        if (j - x[i] >= 0)
          dp[i][j][k + 1] += dp[i - 1][j - x[i]][k];
      }

  for (int i = 1; i <= N * A; i++)
    ans += dp[N][A * i][i];

  cout << ans << "\n";
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18 + 99);
static const int INF = 1e9 + 99;

ll ans;
int N, A;
ll x[55], dp[55][2510][55];

int main(void) {
  cin >> N >> A;
  rep(i, 1, N + 1) cin >> x[i];

  dp[0][0][0] = 1;
  for (int i = 1; i <= N; i++)
    for (int j = 0; j <= 2500; j++)
      for (int k = 0; k <= N; k++) {
        dp[i][j][k] += dp[i - 1][j][k];
        if (j - x[i] >= 0)
          dp[i][j][k + 1] += dp[i - 1][j - x[i]][k];
      }

  for (int i = 1; i <= 50; i++)
    ans += dp[N][A * i][i];

  cout << ans << "\n";
  return 0;
}
Problem p04013 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using ll = long long;

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define reps(i, x) for (ll i = 1; i <= (int)(x); i++)
#define rrep(i, x) for (ll i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (ll i = (int)(x); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll, ll>>
#define vpi vector<pair<int, int>>
#define mod 1000000007
using namespace std;
int x[51];
ll dp[51][2501];
int main() {
  int n, a;
  cin >> n >> a;
  int mx = a, tmp;
  reps(i, n) {
    cin >> tmp;
    x[i] = tmp - a;
    mx = max(mx, tmp);
  }
  rep(j, n + 1) rep(t, (2 * n * mx + 1)) {
    if (j == 0 && t == n * mx)
      dp[j][t] = 1LL;
    else if (j > 0 && ((0 > t - x[j]) || (t - x[j] > 2 * n * mx)))
      dp[j][t] = dp[j - 1][t];
    else if (j > 0 && (0 <= t - x[j]) && (t - x[j] <= 2 * n * mx))
      dp[j][t] = dp[j - 1][t] + dp[j - 1][t - x[j]];
    else
      dp[j][t] = 0LL;
  }
  cout << dp[n][n * mx] - 1 << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using ll = long long;

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define reps(i, x) for (ll i = 1; i <= (int)(x); i++)
#define rrep(i, x) for (ll i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (ll i = (int)(x); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll, ll>>
#define vpi vector<pair<int, int>>
#define mod 1000000007
using namespace std;
int x[51];
ll dp[51][5001];
int main() {
  int n, a;
  cin >> n >> a;
  int mx = a, tmp;
  reps(i, n) {
    cin >> tmp;
    x[i] = tmp - a;
    mx = max(mx, tmp);
  }
  rep(j, n + 1) rep(t, (2 * n * mx + 1)) {
    if (j == 0 && t == n * mx)
      dp[j][t] = 1LL;
    else if (j > 0 && ((0 > t - x[j]) || (t - x[j] > 2 * n * mx)))
      dp[j][t] = dp[j - 1][t];
    else if (j > 0 && (0 <= t - x[j]) && (t - x[j] <= 2 * n * mx))
      dp[j][t] = dp[j - 1][t] + dp[j - 1][t - x[j]];
    else
      dp[j][t] = 0LL;
  }
  cout << dp[n][n * mx] - 1 << endl;
  return 0;
}
Problem p04013 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>

int main() {
  long long n, a;
  scanf("%lld %lld", &n, &a);
  long long x[50];
  long long dp[51][51][2501];
  for (int i = 0; i < n; ++i) {
    scanf("%lld", x + i);
  }
  memset(dp[0][0], 0, (n * 50 + 1) * sizeof(long long));

  dp[0][0][0] = 1;
  const long long jlim = n * 50;
  for (int i = 0; i < n; ++i) {
    for (int k = 0; k <= n; ++k) {
      for (int j = 0; j <= jlim; ++j) {
        if (j - x[i] >= 0 && k >= 1) {
          dp[i + 1][k][j] = dp[i][k - 1][j - x[i]] + dp[i][k][j];
        } else {
          dp[i + 1][k][j] = dp[i][k][j];
        }
      }
    }
  }

  long long ans = 0;
  for (long long i = 1; i * a <= jlim; ++i) {
    ans += dp[n][i][i * a];
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <cstdio>
#include <cstring>

int main() {
  long long n, a;
  scanf("%lld %lld", &n, &a);
  long long x[50];
  long long dp[51][51][2501];
  for (int i = 0; i < n; ++i) {
    scanf("%lld", x + i);
  }
  memset(dp[0][0], 0, (n * 50 + 1) * sizeof(long long));

  dp[0][0][0] = 1;
  const long long jlim = n * 50;
  for (int i = 0; i < n; ++i) {
    for (int k = 0; k <= n; ++k) {
      for (int j = 0; j <= jlim; ++j) {
        if (j - x[i] >= 0 && k >= 1) {
          dp[i + 1][k][j] = dp[i][k - 1][j - x[i]] + dp[i][k][j];
        } else {
          dp[i + 1][k][j] = dp[i][k][j];
        }
      }
    }
  }

  long long ans = 0;
  for (long long i = 1; i <= n && i * a <= jlim; ++i) {
    ans += dp[n][i][i * a];
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p04013 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, a;
  while (cin >> n >> a) {
    vector<int> v(n);
    for (auto &a : v)
      cin >> a;

    static long long dp[51][51][2501];
    for (int i = 0; i < 51; ++i)
      for (int j = 0; j < 51; ++j)
        for (int k = 0; k < 2501; ++k)
          dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j <= n; ++j) {
        for (int k = 0; k <= n * a; ++k) {
          dp[i + 1][j + 1][k + v[i]] += dp[i][j][k];
          dp[i + 1][j][k] += dp[i][j][k];
        }
      }
    }

    long long result = 0;
    for (int j = 1; j <= n; ++j) {
      result += dp[n][j][j * a];
    }
    cout << result << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, a;
  while (cin >> n >> a) {
    vector<int> v(n);
    for (auto &a : v)
      cin >> a;

    static long long dp[51][51][2501];
    for (int i = 0; i < 51; ++i)
      for (int j = 0; j < 51; ++j)
        for (int k = 0; k < 2501; ++k)
          dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        for (int k = 0; k < n * a; ++k) {
          dp[i + 1][j + 1][k + v[i]] += dp[i][j][k];
          dp[i + 1][j][k] += dp[i][j][k];
        }
      }
    }

    long long result = 0;
    for (int j = 1; j <= n; ++j) {
      result += dp[n][j][j * a];
    }
    cout << result << endl;
  }
}
Problem p04013 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
ll dp[50][50][2500];
int main() {
  int n, a;
  cin >> n >> a;

  vector<int> x(n + 1);

  x[0] = 0;

  for (int i = 1; i <= n; i++)
    cin >> x[i];

  int X = max(a, *max_element(x.begin(), x.end()));

  for (int j = 0; j <= n; j++) {
    for (int k = 0; k <= n; k++) {
      for (int s = 0; s <= n * X; s++) {
        if (j == 0 && k == 0 && s == 0)
          dp[j][k][s] = 1;
        else {
          if (j >= 1 && s < x[j])
            dp[j][k][s] = dp[j - 1][k][s];
          else if (j >= 1 && k >= 1 && s >= x[j])
            dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j]];
          else
            dp[j][k][s] = 0;
        }
      }
    }
  }

  ll ans = 0;
  for (int k = 1; k <= n; k++) {
    ans += dp[n][k][k * a];
  }

  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
ll dp[51][51][2501];
int main() {
  int n, a;
  cin >> n >> a;

  vector<int> x(n + 1);

  x[0] = 0;

  for (int i = 1; i <= n; i++)
    cin >> x[i];

  int X = max(a, *max_element(x.begin(), x.end()));

  for (int j = 0; j <= n; j++) {
    for (int k = 0; k <= n; k++) {
      for (int s = 0; s <= n * X; s++) {
        if (j == 0 && k == 0 && s == 0)
          dp[j][k][s] = 1;
        else {
          if (j >= 1 && s < x[j])
            dp[j][k][s] = dp[j - 1][k][s];
          else if (j >= 1 && k >= 1 && s >= x[j])
            dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j]];
          else
            dp[j][k][s] = 0;
        }
      }
    }
  }

  ll ans = 0;
  for (int k = 1; k <= n; k++) {
    ans += dp[n][k][k * a];
  }

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

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

using namespace std;
typedef long long ll;
typedef double dd;
#define all(v) v.begin(), v.end()
#define endl "\n";

void fast() {

  cin.tie(0);
  cin.sync_with_stdio(0);
}
ll n, a, arr[50 + 9], dp[50][50][2550];
ll ans(int i, int num, int sum) {
  ll &ret = dp[i][num][sum];
  if (~ret)
    return ret;
  if (i == n)
    return dp[i][num][sum] = num && ((dd)sum / (dd)num == a);

  return ret = ans(i + 1, num, sum) + ans(i + 1, num + 1, sum + arr[i]);
}
int main() {
  fast();
  cin >> n >> a;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  memset(dp, -1, sizeof(dp));
  cout << ans(0, 0, 0);
}


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

using namespace std;
typedef long long ll;
typedef double dd;
#define all(v) v.begin(), v.end()
#define endl "\n";

void fast() {

  cin.tie(0);
  cin.sync_with_stdio(0);
}
ll n, a, arr[50 + 9], dp[50 + 9][50 + 9][2550];
ll ans(int i, int num, int sum) {
  ll &ret = dp[i][num][sum];
  if (~ret)
    return ret;
  if (i == n)
    return dp[i][num][sum] = num && ((dd)sum / (dd)num == a);

  return ret = ans(i + 1, num, sum) + ans(i + 1, num + 1, sum + arr[i]);
}
int main() {
  fast();
  cin >> n >> a;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  memset(dp, -1, sizeof(dp));
  cout << ans(0, 0, 0);
}
Problem p04013 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define lld long long int
#define DBG1(vari1) cerr << #vari1 << " = " << (vari1) << endl;
#define DBG2(vari1, vari2)                                                     \
  cerr << #vari1 << " = " << (vari1) << " " << #vari2 << " = " << (vari2)      \
       << endl;
#define DBG3(vari1, vari2, vari3)                                              \
  cerr << #vari1 << " = " << (vari1) << " " << #vari2 << " = " << (vari2)      \
       << " " << #vari3 << " = " << (vari3) << endl;
using namespace std;
lld dp[51][51][2510];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt", "r", stdin);
  lld n, a;
  cin >> n >> a;
  lld arr[n];
  for (lld i = 0; i < n; i++)
    cin >> arr[i];
  lld m = max(*max_element(arr, arr + n), a);
  dp[0][0][0] = 1;
  for (lld i = 0; i <= n; i++) {
    for (lld j = 0; j <= n; j++) {
      for (lld k = 0; k <= (m * n); k++) {
        if (i == 0 && j == 0 && k == 0)
          dp[i][j][k] = 1;
        else if (i >= 1 && arr[i - 1] > k)
          dp[i][j][k] = dp[i - 1][j][k];
        else if (i >= 1 && j >= 1 && k >= arr[i - 1])
          dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - arr[i - 1]];
        else
          dp[i][j][k] = 0;
      }
    }
  }
  lld ans = 0;
  for (lld i = 1; i <= n * a; i++) {
    ans += dp[n][i][i * a];
  }
  cout << ans;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define lld long long int
#define DBG1(vari1) cerr << #vari1 << " = " << (vari1) << endl;
#define DBG2(vari1, vari2)                                                     \
  cerr << #vari1 << " = " << (vari1) << " " << #vari2 << " = " << (vari2)      \
       << endl;
#define DBG3(vari1, vari2, vari3)                                              \
  cerr << #vari1 << " = " << (vari1) << " " << #vari2 << " = " << (vari2)      \
       << " " << #vari3 << " = " << (vari3) << endl;
using namespace std;
lld dp[51][51][2510];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt", "r", stdin);
  lld n, a;
  cin >> n >> a;
  lld arr[n];
  for (lld i = 0; i < n; i++)
    cin >> arr[i];
  lld m = max(*max_element(arr, arr + n), a);
  dp[0][0][0] = 1;
  for (lld i = 0; i <= n; i++) {
    for (lld j = 0; j <= n; j++) {
      for (lld k = 0; k <= (m * n); k++) {
        if (i == 0 && j == 0 && k == 0)
          dp[i][j][k] = 1;
        else if (i >= 1 && arr[i - 1] > k)
          dp[i][j][k] = dp[i - 1][j][k];
        else if (i >= 1 && j >= 1 && k >= arr[i - 1])
          dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - arr[i - 1]];
        else
          dp[i][j][k] = 0;
      }
    }
  }
  lld ans = 0;
  for (lld i = 1; i <= n; i++) {
    ans += dp[n][i][i * a];
  }
  cout << ans;
}
Problem p04013 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll dp[51][51][2501];
int main() {
  // dp[i][j][k]
  // i番目までj個使って合計k
  int N, A;
  cin >> N >> A;
  vector<int> x(N);
  rep(i, N) cin >> x[i];
  dp[0][0][0] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= i; j++) {
      for (int k = 0; k <= 2500; k++) {
        dp[i][j][k] += dp[i - 1][j][k];
        if (k - x[i - 1] >= 0)
          dp[i][j][k] += dp[i - 1][j - 1][k - x[i - 1]];
      }
    }
  }
  ll ans = 0;
  for (int j = 1; j <= N; j++) {
    ans += dp[N][j][A * j];
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll dp[51][51][2501];
int main() {
  // dp[i][j][k]
  // i番目までj個使って合計k
  int N, A;
  cin >> N >> A;
  vector<int> x(N);
  rep(i, N) cin >> x[i];
  dp[0][0][0] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= i; j++) {
      for (int k = 0; k <= 2500; k++) {
        dp[i][j][k] += dp[i - 1][j][k];
        if (k - x[i - 1] >= 0 && j)
          dp[i][j][k] += dp[i - 1][j - 1][k - x[i - 1]];
      }
    }
  }
  ll ans = 0;
  for (int j = 1; j <= N; j++) {
    ans += dp[N][j][A * j];
  }
  cout << ans << endl;
  return 0;
}
Problem p04013 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
#define vi vector

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a;
  cin >> n >> a;
  vector<int> x(n + 1);
  REP(i, n) cin >> x[i + 1];
  vi<vi<vi<long long>>> dp(
      n + 1, vi<vi<long long>>(n + 1, vi<long long>(n * a + 1, 0)));
  REP(i, n + 1) dp[i][0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      for (int k = 0; k <= n * a + 1; k++) {
        if (k - x[i] >= 0)
          dp[i][j][k] = dp[i - 1][j - 1][k - x[i]] + dp[i - 1][j][k];
        else
          dp[i][j][k] = dp[i - 1][j][k];
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += dp[n][i][i * a];
    //		cout << dp[n][i][i*a] << endl;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
#define vi vector

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a;
  cin >> n >> a;
  vector<int> x(n + 1);
  REP(i, n) cin >> x[i + 1];
  vi<vi<vi<long long>>> dp(
      n + 1, vi<vi<long long>>(n + 1, vi<long long>(n * a + 2, 0)));
  REP(i, n + 1) dp[i][0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      for (int k = 0; k <= n * a + 1; k++) {
        if (k - x[i] >= 0)
          dp[i][j][k] = dp[i - 1][j - 1][k - x[i]] + dp[i - 1][j][k];
        else
          dp[i][j][k] = dp[i - 1][j][k];
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += dp[n][i][i * a];
    //		cout << dp[n][i][i*a] << endl;
  }
  cout << ans << endl;
  return 0;
}
Problem p04013 (Python)

Buggy submission (status: Runtime Error):
import sys

sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7


def resolve():
    n, a = map(int, input().split())
    X = list(map(int, input().split()))
    MAX = sum(X) + 1

    dp = [[[0] * MAX for _ in range(n + 1)] for _ in range(n + 1)]
    dp[0][0][0] = 1
    for i in range(1, n + 1):
        x = X[i - 1]
        for j in range(n):
            for k in range(MAX):
                dp[i][j][k] += dp[i - 1][j][k]
                if k + x < MAX:
                    dp[i][j + 1][k + x] += dp[i - 1][j][k]
    res = 0
    for j in range(1, n + 1):
        res += dp[-1][j][a * j]
    print(res)


if __name__ == "__main__":
    resolve()


Fixed submission:
import sys

sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7


def resolve():
    n, a = map(int, input().split())
    X = list(map(int, input().split()))
    MAX = 50 * 50 + 1

    dp = [[[0] * MAX for _ in range(n + 1)] for _ in range(n + 1)]
    dp[0][0][0] = 1
    for i in range(1, n + 1):
        x = X[i - 1]
        for j in range(n):
            for k in range(MAX):
                dp[i][j][k] += dp[i - 1][j][k]
                if k + x < MAX:
                    dp[i][j + 1][k + x] += dp[i - 1][j][k]
    res = 0
    for j in range(1, n + 1):
        res += dp[-1][j][a * j]
    print(res)


if __name__ == "__main__":
    resolve()
Problem p04013 (Python)

Buggy submission (status: Time Limit Exceeded):
import numpy as np


def main(n, a, x):
    SUM_MAX = max(a, max(x)) * n + 1
    dp = np.zeros(shape=(n + 1, n + 1, SUM_MAX), dtype=int)

    dp[0][0][0] = 1
    for j in range(1, n + 1):
        for k in range(j + 1):
            for s in range(SUM_MAX):
                if s < x[j - 1]:
                    dp[j][k][s] = dp[j - 1][k][s]
                elif k >= 1:
                    dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]]

    patterns = 0
    for k in range(1, n + 1):
        ka = k * a
        patterns += dp[n][k][ka]
    return patterns


if __name__ == "__main__":
    N, A = map(int, input().split())
    X = list(map(int, input().split()))
    print(main(N, A, X))


Fixed submission:
import numpy as np


def main(n, a, x):
    SUM_MAX = max(a, max(x)) * n + 1
    dp = np.zeros(shape=(n + 1, n + 1, SUM_MAX), dtype=int)

    dp[0][0][0] = 1
    for j in range(1, n + 1):
        for k in range(j + 1):
            dp[j][k][0 : x[j - 1]] = dp[j - 1][k][0 : x[j - 1]]
            if k >= 1:
                dp[j][k][x[j - 1] :] = (
                    dp[j - 1][k][x[j - 1] :] + dp[j - 1][k - 1][: SUM_MAX - x[j - 1]]
                )

    patterns = 0
    for k in range(1, n + 1):
        ka = k * a
        patterns += dp[n][k][ka]
    return patterns


if __name__ == "__main__":
    N, A = map(int, input().split())
    X = list(map(int, input().split()))
    print(main(N, A, X))
Problem p04013 (Python)

Buggy submission (status: Time Limit Exceeded):
n, a = map(int, input().split())
x = list(map(int, input().split()))

dp = [[[0] * (50 * (n + 10)) for _ in range(n + 10)] for _ in range(n + 10)]
dp[0][0][0] = 1

for i in range(n):
    for use in range(n):
        for total in range(n * a):
            dp[i + 1][use][total] += dp[i][use][total]
            dp[i + 1][use + 1][total + x[i]] += dp[i][use][total]

ans = 0
for i in range(1, n + 1):
    ans += dp[n][i][a * i]

print(ans)


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

dp = [[[0] * (50 * (n + 10)) for _ in range(n + 10)] for _ in range(n + 10)]
dp[0][0][0] = 1

for i in range(n):
    for use in range(n):
        for total in range(n * a):
            if dp[i][use][total]:
                dp[i + 1][use][total] += dp[i][use][total]
                dp[i + 1][use + 1][total + x[i]] += dp[i][use][total]

ans = 0
for i in range(1, n + 1):
    ans += dp[n][i][a * i]

print(ans)
Problem p04013 (Python)

Buggy submission (status: Runtime Error):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, *X = map(int, read().split())

    M = sum(X)
    dp = [[0] * (M + 1) for j in range(N + 1)]
    dp[0][0] = 1

    for i in range(N):
        for j in range(N, 0, -1):
            for k in range(X[i], M + 1):
                dp[j][k] += dp[j - 1][k - X[i]]

    ans = 0
    for j in range(1, M // A + 1):
        ans += dp[j][A * j]

    print(ans)
    return


if __name__ == "__main__":
    main()


Fixed submission:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, *X = map(int, read().split())

    M = sum(X)
    dp = [[0] * (M + 1) for j in range(N + 1)]
    dp[0][0] = 1

    for i in range(N):
        for j in range(N, 0, -1):
            for k in range(X[i], M + 1):
                dp[j][k] += dp[j - 1][k - X[i]]

    ans = 0
    for j in range(1, N + 1):
        if A * j > M:
            break
        ans += dp[j][A * j]

    print(ans)
    return


if __name__ == "__main__":
    main()
Problem p04013 (Python)

Buggy submission (status: Runtime Error):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, *X = map(int, read().split())

    M = sum(X)
    dp = [[0] * (M + 1) for j in range(N + 1)]
    dp[0][0] = 1

    for i in range(N):
        for j in range(N, 0, -1):
            for k in range(X[i], M + 1):
                dp[j][k] += dp[j - 1][k - X[i]]

    ans = 0
    for j in range(1, min(50, M // A) + 1):
        ans += dp[j][A * j]

    print(ans)
    return


if __name__ == "__main__":
    main()


Fixed submission:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, *X = map(int, read().split())

    M = sum(X)
    dp = [[0] * (M + 1) for j in range(N + 1)]
    dp[0][0] = 1

    for i in range(N):
        for j in range(N, 0, -1):
            for k in range(X[i], M + 1):
                dp[j][k] += dp[j - 1][k - X[i]]

    ans = 0
    for j in range(1, min(N, M // A) + 1):
        ans += dp[j][A * j]

    print(ans)
    return


if __name__ == "__main__":
    main()