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

Buggy submission (status: Runtime Error):
#include "algorithm"
#include "bitset"
#include "cmath"
#include "iostream"
#include "limits.h"
#include "string"
#include "vector"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n, i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define ll long long int
#define sp ' '
using namespace std;

int n, a;
ll dp[2501][51][51];
int x[50];
ll ans;

ll gcd(ll x, ll y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
  ll g = gcd(x, y);
  return x / g * y;
}

int main() {
  cin >> n >> a;
  lp(n) cin >> x[i];
  lp(2501) lop(51, j) lop(51, k) dp[i][j][k] = 0;
  dp[0][0][0] = 1;
  lp(n) {
    lop(2501, j) {
      lop(i + 1, k) {
        dp[j + x[i]][i + 1][k + 1] += dp[j][i][k];
        dp[j][i + 1][k] += dp[j][i][k];
        //				cout << j << sp << i << sp << k << sp <<
        //dp[j][i][k] << endl;
      }
    }
  }
  ans = 0;
  lp(n) { ans += dp[a * (i + 1)][n][i + 1]; }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include "algorithm"
#include "bitset"
#include "cmath"
#include "iostream"
#include "limits.h"
#include "string"
#include "vector"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n, i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define ll long long int
#define sp ' '
using namespace std;

int n, a;
ll dp[2551][52][52];
int x[50];
ll ans;

ll gcd(ll x, ll y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
  ll g = gcd(x, y);
  return x / g * y;
}

int main() {
  cin >> n >> a;
  lp(n) cin >> x[i];
  lp(2501) lop(51, j) lop(51, k) dp[i][j][k] = 0;
  dp[0][0][0] = 1;
  lp(n) {
    lop(2501, j) {
      lop(i + 1, k) {
        dp[j + x[i]][i + 1][k + 1] += dp[j][i][k];
        dp[j][i + 1][k] += dp[j][i][k];
        //				cout << j << sp << i << sp << k << sp <<
        //dp[j][i][k] << endl;
      }
    }
  }
  ans = 0;
  lp(n) { ans += dp[a * (i + 1)][n][i + 1]; }
  cout << ans << endl;
  return 0;
}
Problem p04015 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll N, A;
void dfs(ll now, ll sum, ll num_used, vector<ll> &x, map<ll, ll> &num) {
  if (now == x.size() - 1) {
    num[A * num_used - sum] += 1;
    num[A * (num_used + 1) - (sum + x.at(x.size() - 1))] += 1;
  } else {
    dfs(now + 1, sum, num_used, x, num);
    dfs(now + 1, sum + x.at(now), num_used + 1, x, num);
  }
}

int main() {
  cin >> N >> A;
  vector<ll> x1(N / 2), x2(N - N / 2);
  for (ll i = 0; i < N / 2; ++i) {
    cin >> x1.at(i);
  }
  for (ll i = 0; i < (N - N / 2); ++i) {
    cin >> x2.at(i);
  }
  map<ll, ll> num1, num2;
  dfs(0, 0, 0, x1, num1);
  dfs(0, 0, 0, x2, num2);
  // for (ll i = 0; i < num1.size(); ++i) {
  //   cout << num1.at(i) << " ";
  // }
  // cout << "\n";
  // for (ll i = 0; i < num2.size(); ++i) {
  //   cout << num2.at(i) << " ";
  // }
  // cout << "\n";
  ll ans = 0;
  for (const auto &[key, value] : num1) {
    ans += value * num2[-key];
  }

  ans -= 1;
  cout << ans << "\n";
}


Fixed submission:
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll N, A;
void dfs(ll now, ll sum, ll num_used, vector<ll> &x, map<ll, ll> &num) {
  if (x.size() == 0) {
    num[0] = 1;
    return;
  }
  if (now == x.size() - 1) {
    num[A * num_used - sum] += 1;
    num[A * (num_used + 1) - (sum + x.at(x.size() - 1))] += 1;
  } else {
    dfs(now + 1, sum, num_used, x, num);
    dfs(now + 1, sum + x.at(now), num_used + 1, x, num);
  }
}

int main() {
  cin >> N >> A;
  vector<ll> x1(N / 2), x2(N - N / 2);
  for (ll i = 0; i < N / 2; ++i) {
    cin >> x1.at(i);
  }
  for (ll i = 0; i < (N - N / 2); ++i) {
    cin >> x2.at(i);
  }
  map<ll, ll> num1, num2;
  dfs(0, 0, 0, x1, num1);
  dfs(0, 0, 0, x2, num2);
  // for (ll i = 0; i < num1.size(); ++i) {
  //   cout << num1.at(i) << " ";
  // }
  // cout << "\n";
  // for (ll i = 0; i < num2.size(); ++i) {
  //   cout << num2.at(i) << " ";
  // }
  // cout << "\n";
  ll ans = 0;
  for (const auto &[key, value] : num1) {
    ans += value * num2[-key];
  }

  ans -= 1;
  cout << ans << "\n";
}
Problem p04015 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pi;
typedef pair<pair<ll, ll>, ll> pii;
vector<ll> vec;
vector<vector<ll>> vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

// 中身は0になっているはず
// ll dp[1919][1919][3019];

// 配るDP
int main() {

  ll N, A;
  cin >> N >> A;
  vector<ll> card(N, 0);
  for (ll i = 0; i < N; i++) {
    cin >> card[i];
  }
  vector<vector<vector<ll>>> dp(199,
                                vector<vector<ll>>(199, vector<ll>(3019, 0)));
  // 今までに何をいくつ配り、その時の総和を記録しておく
  // 平均がAとすると平均A満たすある数Bは必ずAの倍数である
  // そのようなBをとる総和を考えてやると今までに配った全てのカードに対する平均記録しておかなくて良い
  dp[0][0][0] = 1;
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    for (ll num = 0; num <= N; num++) {
      // 制約的に最大総和50*50が考えられるので余裕を持って3000
      for (ll sum = 0; sum <= 3000; sum++) {
        if (dp[i][num][sum] == 0)
          continue;

        // そのカードを使わないとき
        dp[i + 1][num][sum] += dp[i][num][sum];

        // カードを使う時
        ll tmp = dp[i][num][sum];
        ll new_sum = sum + card[i];
        ll new_num = num + 1;
        // 平均値Aになるかの判定
        if (new_sum == new_num * A) {
          ans += tmp;
        }
        dp[i + 1][new_num][new_sum] += tmp;
      }
    }
  }

  cout << ans << endl;
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pi;
typedef pair<pair<ll, ll>, ll> pii;
vector<ll> vec;
vector<vector<ll>> vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

// 中身は0になっているはず
// ll dp[1919][1919][3019];

// 配るDP
int main() {

  ll N, A;
  cin >> N >> A;
  vector<ll> card(N, 0);
  for (ll i = 0; i < N; i++) {
    cin >> card[i];
  }
  vector<vector<vector<ll>>> dp(55,
                                vector<vector<ll>>(55, vector<ll>(3019, 0)));
  // 今までに何をいくつ配り、その時の総和を記録しておく
  // 平均がAとすると平均A満たすある数Bは必ずAの倍数である
  // そのようなBをとる総和を考えてやると今までに配った全てのカードに対する平均記録しておかなくて良い
  dp[0][0][0] = 1;
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    for (ll num = 0; num <= N; num++) {
      // 制約的に最大総和50*50が考えられるので余裕を持って3000
      for (ll sum = 0; sum <= 3000; sum++) {
        if (dp[i][num][sum] == 0)
          continue;

        // そのカードを使わないとき
        dp[i + 1][num][sum] += dp[i][num][sum];

        // カードを使う時
        ll tmp = dp[i][num][sum];
        ll new_sum = sum + card[i];
        ll new_num = num + 1;
        // 平均値Aになるかの判定
        if (new_sum == new_num * A) {
          ans += tmp;
        }
        dp[i + 1][new_num][new_sum] += tmp;
      }
    }
  }

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

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define inf 1000000000
#define mod 1000000007
#define li 100005
#define FOR for (int i = 1; i <= n; i++)
typedef pair<int, int> PII;
typedef long long int lo;
lo n, m, cev, b, a[52], dp[53][25000][53];
string s;
vector<int> v;
lo f(lo sira, lo topl, lo kac) {
  lo cevap = 0;
  //~ printf("%d %d %d\n",sira,topl,kac);
  if (sira > n && kac * m == topl)
    return 1;
  if (sira > n && kac * m != topl)
    return 0;
  if (~dp[sira][topl][kac])
    return dp[sira][topl][kac];
  cevap += f(sira + 1, topl + a[sira], kac + 1);
  cevap += f(sira + 1, topl, kac);
  return dp[sira][topl][kac] = cevap;
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%lld %lld", &n, &m);
  FOR { scanf("%lld", &a[i]); }
  printf("%lld", f(1, 0, 0) - 1);
  //~ printf("%d",cev);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define inf 1000000000
#define mod 1000000007
#define li 100005
#define FOR for (int i = 1; i <= n; i++)
typedef pair<int, int> PII;
typedef long long int lo;
lo n, m, cev, b, a[51], dp[51][2501][51];
string s;
vector<int> v;
lo f(lo sira, lo topl, lo kac) {
  lo cevap = 0;
  //~ printf("%d %d %d\n",sira,topl,kac);
  if (sira > n && kac * m == topl)
    return 1;
  if (sira > n && kac * m != topl)
    return 0;
  if (~dp[sira][topl][kac])
    return dp[sira][topl][kac];
  cevap += f(sira + 1, topl + a[sira], kac + 1);
  cevap += f(sira + 1, topl, kac);
  return dp[sira][topl][kac] = cevap;
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%lld %lld", &n, &m);
  FOR { scanf("%lld", &a[i]); }
  printf("%lld", f(1, 0, 0) - 1);
  //~ printf("%d",cev);
  return 0;
}
Problem p04015 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
long long d[55][5005];
int main() {
  freopen("input.txt", "r", stdin);
  int i, j, n, a, x, z = 0;
  scanf("%d%d", &n, &a);
  d[0][2500] = 1;
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    x -= a;
    for (j = 0; j <= 5000; j++) {
      d[i][j] += d[i - 1][j];
      d[i][j + x] += d[i - 1][j];
    }
  }
  printf("%lld", d[n][2500] - 1);
}

Fixed submission:
#include <cstdio>
long long d[55][5005];
int main() {
  int i, j, n, a, x, z = 0;
  scanf("%d%d", &n, &a);
  d[0][2500] = 1;
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    x -= a;
    for (j = 0; j <= 5000; j++) {
      d[i][j] += d[i - 1][j];
      d[i][j + x] += d[i - 1][j];
    }
  }
  printf("%lld", d[n][2500] - 1);
}
Problem p04015 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
long long n, a, x, z, C = 2500, d[2][5005];
int main() {
  int i, j;
  scanf("%lld%lld", &n, &a);
  d[0][C] = 1;
  for (i = 0; i < n; i++, z ^= 1) {
    scanf("%lld", &x);
    x -= a;
    for (j = 0; j <= 5000; j++)
      d[z ^ 1][j] = 0;
    for (j = 0; j <= 2 * C; j++) {
      d[z ^ 1][j] += d[z][j];
      d[z ^ 1][j + x] += d[z][j];
    }
  }
  printf("%lld", d[z][C] - 1);
}

Fixed submission:
#include <cstdio>
long long n, a, x, z, C = 2500, d[2][5005];
int main() {
  int i, j;
  scanf("%lld%lld", &n, &a);
  d[0][C] = 1;
  for (i = 0; i < n; i++, z ^= 1) {
    scanf("%lld", &x);
    x -= a;
    for (j = 0; j <= 5000; j++)
      d[z ^ 1][j] = 0;
    for (j = 0; j <= 2 * C; j++) {
      if (d[z][j]) {
        d[z ^ 1][j] += d[z][j];
        d[z ^ 1][j + x] += d[z][j];
      }
    }
  }
  printf("%lld", d[z][C] - 1);
}
Problem p04015 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)

ll N, A;
ll ans = 0;
ll x[100] = {0};
ll dp[100][100][3000];

int main() {
  cin >> N >> A;
  for (ll i = 1; i <= N; ++i) {
    cin >> x[i];
  }

  for (ll j = 0; j < N + 1; ++j) {
    for (ll k = 0; k < N + 1; ++k) {
      for (ll s = 0; s < N * 50 + 1; ++s) {
        if (j == 0 && k == 0 && s == 0) {
          dp[j][k][s] = 1;
        } else if (s < x[j]) {
          dp[j][k][s] = dp[j - 1][k][s];
        } else if (k >= 1) {
          dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j]];
        } else {
          dp[j][k][s] = 0;
        }
      }
    }
  }
  for (ll k = 1; k <= N; ++k) {
    ans += dp[N][k][k * A];
  }
  cout << ans << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)

ll N, A;
ll ans = 0;
ll x[100] = {0};
ll dp[100][100][3000];

int main() {
  cin >> N >> A;
  for (ll i = 1; i <= N; ++i) {
    cin >> x[i];
  }
  REP(k, N + 1) {
    REP(s, N * 50 + 1) { dp[0][k][s] = 0; }
  }
  dp[0][0][0] = 1;
  for (ll j = 1; j <= N; ++j) {
    for (ll k = 0; k <= N; ++k) {
      for (ll s = 0; s <= N * 50; ++s) {
        if (s < x[j]) {
          dp[j][k][s] = dp[j - 1][k][s];
        } else if (k >= 1) {
          dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j]];
        } else {
          dp[j][k][s] = 0;
        }
      }
    }
  }
  for (ll k = 1; k <= N; ++k) {
    ans += dp[N][k][k * A];
  }
  cout << ans << "\n";
}
Problem p04015 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
typedef long long int ll;
static const int MAX_N = 50;
static const int MAX_X = 50;

int N, A;
int x[MAX_N];
ll memo[MAX_N][MAX_N][MAX_N * MAX_X];

int main() {
  cin >> N >> A;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }
  memo[0][0][0] = 1; //[何枚目まで使うか][何枚使うか][カードの和]
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= i; j++) {
      for (int k = 0; k <= N * MAX_X; k++) {
        // 新しく追加されるカードが「和」より大きかったら[何枚目まで使うか]によらず値は変化しない
        if (j == 0 || k < x[i - 1]) {
          memo[i][j][k] = memo[i - 1][j][k];
        }
        // そうでなければ、[何枚目まで使うか][何枚使うか]が1ずつ少なく、[カードの和]が新しく追加したカード分少ないものを足す

        else {
          memo[i][j][k] = memo[i - 1][j][k] + memo[i - 1][j - 1][k - x[i - 1]];
        }
      }
    }
  }
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += memo[N][i][i * A];
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
typedef long long int ll;
static const int MAX_N = 50;
static const int MAX_X = 50;

int N, A;
int x[MAX_N];
ll memo[MAX_N + 1][MAX_N + 1][MAX_N * MAX_X + 1];

int main() {
  cin >> N >> A;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }
  memo[0][0][0] = 1; //[何枚目まで使うか][何枚使うか][カードの和]
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= i; j++) {
      for (int k = 0; k <= N * MAX_X; k++) {
        // 新しく追加されるカードが「和」より大きかったら[何枚目まで使うか]によらず値は変化しない
        if (j == 0 || k < x[i - 1]) {
          memo[i][j][k] = memo[i - 1][j][k];
        }
        // そうでなければ、[何枚目まで使うか][何枚使うか]が1ずつ少なく、[カードの和]が新しく追加したカード分少ないものを足す

        else {
          memo[i][j][k] = memo[i - 1][j][k] + memo[i - 1][j - 1][k - x[i - 1]];
        }
      }
    }
  }
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += memo[N][i][i * A];
  }
  cout << ans << endl;
  return 0;
}
Problem p04015 (C++)

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

// i枚目まで見て、j個選んだときの合計が、kになる組み合わせ
long long SUMMAX = 2501;
long long dp[50][50][50 * 50 + 1];

void solve(long long N, long long A, std::vector<long long> x) {
  dp[0][0][0] = 1;

  for (int i = 1; i <= N; i++) {
    long long xi = x[i - 1];

    for (int j = 0; j <= i; j++) {
      for (int k = 0; k < SUMMAX; k++) {
        // i番目のカードを選ばない
        dp[i][j][k] = dp[i - 1][j][k];

        // i番目のカードを選ぶ
        if (k - xi >= 0 && j > 0) {
          dp[i][j][k] += dp[i - 1][j - 1][k - xi];
        }
      }
    }
  }

  long long ans = 0;
  for (int j = 1; j <= N; j++) {
    if (j * A < SUMMAX) {
      ans += dp[N][j][j * A];
    }
  }

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

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long A;
  scanf("%lld", &A);
  std::vector<long long> x(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &x[i]);
  }
  solve(N, A, std::move(x));
  return 0;
}


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

// i枚目まで見て、j個選んだときの合計が、kになる組み合わせ
const static int MAX_N = 50;
int SUMMAX = MAX_N * MAX_N + 1;
long long dp[MAX_N + 1][MAX_N + 1][MAX_N * MAX_N + 1];

void solve(long long N, long long A, std::vector<long long> x) {
  dp[0][0][0] = 1;

  for (int i = 1; i <= N; i++) {
    long long xi = x[i - 1];

    for (int j = 0; j <= i; j++) {
      for (int k = 0; k < SUMMAX; k++) {
        // i番目のカードを選ばない
        dp[i][j][k] = dp[i - 1][j][k];

        // i番目のカードを選ぶ
        if (k - xi >= 0 && j > 0) {
          dp[i][j][k] += dp[i - 1][j - 1][k - xi];
        }
      }
    }
  }

  long long ans = 0;
  for (int j = 1; j <= N; j++) {
    if (j * A < SUMMAX) {
      ans += dp[N][j][j * A];
    }
  }

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

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long A;
  scanf("%lld", &A);
  std::vector<long long> x(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &x[i]);
  }
  solve(N, A, std::move(x));
  return 0;
}
Problem p04015 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>

using namespace std;
const int MAXN = 53;
typedef long long ll;

inline int R() {
  int rt = 0;
  bool isn = false;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    isn = ch == '-' ? true : isn;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    rt = rt * 10 + ch - '0';
  return isn ? -rt : rt;
}

ll dp[MAXN][MAXN][MAXN * MAXN];

int main() {
  freopen("test.in", "r", stdin);
  int n = R(), a = R(), lm = 0;
  dp[0][0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    int na = R();
    lm += na;
    for (int j = 0; j <= i; ++j)
      for (int k = 0; k <= lm; ++k)
        dp[i][j][k] = dp[i - 1][j][k];
    for (int j = 1; j <= i; ++j)
      for (int k = na; k <= lm; ++k)
        dp[i][j][k] += dp[i - 1][j - 1][k - na];
  }
  ll ans = 0;
  for (int i = 1; i <= n; ++i)
    ans += dp[n][i][a * i];
  printf("%lld\n", ans);
  return 0;
}

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

using namespace std;
const int MAXN = 53;
typedef long long ll;

inline int R() {
  int rt = 0;
  bool isn = false;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    isn = ch == '-' ? true : isn;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    rt = rt * 10 + ch - '0';
  return isn ? -rt : rt;
}

ll dp[MAXN][MAXN][MAXN * MAXN];

int main() {
  // freopen ( "test.in", "r", stdin );
  int n = R(), a = R(), lm = 0;
  dp[0][0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    int na = R();
    lm += na;
    for (int j = 0; j <= i; ++j)
      for (int k = 0; k <= lm; ++k)
        dp[i][j][k] = dp[i - 1][j][k];
    for (int j = 1; j <= i; ++j)
      for (int k = na; k <= lm; ++k)
        dp[i][j][k] += dp[i - 1][j - 1][k - na];
  }
  ll ans = 0;
  for (int i = 1; i <= n; ++i)
    ans += dp[n][i][a * i];
  printf("%lld\n", ans);
  return 0;
}
Problem p04015 (C++)

Buggy submission (status: Runtime Error):
// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define SORT(c) sort((c).begin(), (c).end())
#define ANS(ans) cout << (ans) << endl;
typedef vector<int> VI;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {

  long long dp[50][50][50 * 50];

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

  VI x(n + 1);
  x[0] = 0;
  FOR(i, 1, n) { cin >> x[i]; }

  VI y(x);
  SORT(y);
  int X = max(a, y[n]);

  FOR(j, 0, n) {
    FOR(k, 0, n) {
      FOR(s, 0, n * X) {
        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;
        }
      }
    }
  }

  long long ans = 0;
  FOR(k, 1, n) { ans += dp[n][k][k * a]; }
  ANS(ans);

  return 0;
}


Fixed submission:
// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define SORT(c) sort((c).begin(), (c).end())
#define ANS(ans) cout << (ans) << endl;
typedef vector<int> VI;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {

  long long dp[51][51][51 * 51];

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

  VI x(n + 1);
  x[0] = 0;
  FOR(i, 1, n) { cin >> x[i]; }

  VI y(x);
  SORT(y);
  int X = max(a, y[n]);

  FOR(j, 0, n) {
    FOR(k, 0, n) {
      FOR(s, 0, n * X) {
        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;
        }
      }
    }
  }

  long long ans = 0;
  FOR(k, 1, n) { ans += dp[n][k][k * a]; }
  ANS(ans);

  return 0;
}
Problem p04015 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 50 + 5;
const int maxm = 2500 + 10;
int a[maxn];
ll f[maxm << 1];
int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    a[i] -= x;
  }
  f[maxm] = 1;
  for (int i = 1; i <= n; ++i)
    if (a[i] >= 0) {
      for (int j = (maxm << 1) - 1; j >= a[i]; --j)
        f[j] += f[j - a[i]];
    } else {
      for (int j = 0; j < (maxm << 1) - a[i]; ++j)
        f[j] += f[j - a[i]];
    }
  cout << f[maxm] - 1 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 50 + 5;
const int maxm = 2500 + 10;
int a[maxn];
ll f[maxm << 1];
int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    a[i] -= x;
  }
  f[maxm] = 1;
  for (int i = 1; i <= n; ++i)
    if (a[i] >= 0) {
      for (int j = (maxm << 1) - 1; j >= a[i]; --j)
        f[j] += f[j - a[i]];
    } else {
      for (int j = 0; j < (maxm << 1) + a[i]; ++j)
        f[j] += f[j - a[i]];
    }
  cout << f[maxm] - 1 << endl;
  return 0;
}
Problem p04015 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR1(i, n) for (int(i) = 1; (i) < (n); (i)++)
#define eFOR(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define eFOR1(i, n) for (int(i) = 1; (i) <= (n); (i)++)
#define SORT(i) sort((i).begin(), (i).end())
#define rSORT(i, a) sort((i).begin(), (i).end(), (a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

ll dp[51][51][51];
int main() {
  int n, a, m = 0;
  cin >> n >> a;
  VI x(n);
  FOR(i, n) {
    cin >> x[i];
    chmax(m, x[i]);
  }
  eFOR(j, n) eFOR(k, n) eFOR(s, n * m) {
    if (!(j || k || s))
      dp[j][k][s] = 1;
    else if (j && s < x[j - 1])
      dp[j][k][s] = dp[j - 1][k][s];
    else if (j && k && s >= x[j - 1])
      dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]];
    else
      dp[j][k][s] = 0;
  }
  ll ans = 0;
  eFOR1(i, n) { ans += dp[n][i][a * i]; }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR1(i, n) for (int(i) = 1; (i) < (n); (i)++)
#define eFOR(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define eFOR1(i, n) for (int(i) = 1; (i) <= (n); (i)++)
#define SORT(i) sort((i).begin(), (i).end())
#define rSORT(i, a) sort((i).begin(), (i).end(), (a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

ll dp[51][51][2510];
int main() {
  int n, a, m = 0;
  cin >> n >> a;
  VI x(n);
  FOR(i, n) {
    cin >> x[i];
    chmax(m, x[i]);
  }
  eFOR(j, n) eFOR(k, n) eFOR(s, n * m) {
    if (!(j || k || s))
      dp[j][k][s] = 1;
    else if (j && s < x[j - 1])
      dp[j][k][s] = dp[j - 1][k][s];
    else if (j && k && s >= x[j - 1])
      dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j - 1]];
    else
      dp[j][k][s] = 0;
  }
  ll ans = 0;
  eFOR1(i, n) { ans += dp[n][i][a * i]; }
  cout << ans << endl;
}
Problem p04015 (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];

  int X = A;
  for (int i = 0; i < N; ++i)
    X = max(x[i], X);

  vector<vector<vector<long long>>> dp(
      N + 1,
      vector<vector<long long>>(N + 1, vector<long long>(N * A + X + 1)));
  dp[0][0][0] = 1;
  for (int j = 0; j < N; ++j) {
    for (int k = 0; k < N; ++k) {
      for (int s = 0; s < N * X; ++s) {
        dp[j + 1][k + 1][s + x[j]] = dp[j][k][s];
        dp[j + 1][k][s] += dp[j][k][s];
      }
    }
  }

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

  cout << ans << endl;
}

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];

  int X = A;
  for (int i = 0; i < N; ++i)
    X = max(x[i], X);

  static long long dp[51][51][50 * 50 + 51] = {};
  dp[0][0][0] = 1;
  for (int j = 0; j < N; ++j) {
    for (int k = 0; k < N; ++k) {
      for (int s = 0; s < N * X; ++s) {
        dp[j + 1][k + 1][s + x[j]] = dp[j][k][s];
        dp[j + 1][k][s] += dp[j][k][s];
      }
    }
  }

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

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

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

const int maxV = 51;
int dp[maxV][maxV][maxV * maxV];

signed main() {
  int n, a;
  cin >> n >> a;
  vector<int> x(n);
  for (auto &&w : x)
    cin >> w;

  fill(dp[0][0], dp[maxV][0], 0);
  dp[0][0][0] = 1;

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      for (int s = 0; s < maxV * maxV; s++) {
        if (dp[i][j][s] == 0)
          continue;
        dp[i + 1][j][s] += dp[i][j][s];
        dp[i + 1][j + 1][s + x[i]] += dp[i][j][s];
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    ans += dp[n][i][i * a];
  cout << ans << endl;
}

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

const int maxV = 51;
int dp[maxV][maxV][maxV * maxV];

signed main() {
  int n, a;
  cin >> n >> a;
  vector<int> x(n);
  for (auto &&w : x)
    cin >> w;

  fill(dp[0][0], dp[maxV][0], 0);
  dp[0][0][0] = 1;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      for (int s = 0; s < maxV * maxV; s++) {
        if (dp[i][j][s] == 0)
          continue;
        dp[i + 1][j][s] += dp[i][j][s];
        dp[i + 1][j + 1][s + x[i]] += dp[i][j][s];
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    ans += dp[n][i][i * a];
  cout << ans << endl;
}
Problem p04015 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#define MOD 1000000007
using namespace std;

int main() {
  long long int n, a, ans = 0;
  int x[51];
  long long int i, j, k;
  cin >> n >> a;
  for (i = 0; i < n; i++) {
    cin >> x[i];
  }
  long long int dp[51][51][51] = {};
  dp[0][0][0] = 1;
  for (i = 0; i < n; i++) {
    for (j = 0; j < i + 2; j++) {
      for (k = 0; k < 50 * j + 1; k++) {
        if (j == 0 && k == 0) {
          dp[i + 1][0][0] = 1;
        } else {
          if (k - x[i] >= 0) {
            dp[i + 1][j][k] = dp[i][j][k] + dp[i][j - 1][k - x[i]];
          } else {
            dp[i + 1][j][k] = dp[i][j][k];
          }
        }
      }
    }
  }
  for (i = 0; i < n; i++) {
    ans += dp[n][i + 1][i * a + a];
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#define MOD 1000000007
using namespace std;

int main() {
  long long int n, a, ans = 0;
  int x[51];
  long long int i, j, k;
  cin >> n >> a;
  for (i = 0; i < n; i++) {
    cin >> x[i];
  }
  long long int dp[51][51][2502] = {};
  dp[0][0][0] = 1;
  for (i = 0; i < n; i++) {
    for (j = 0; j < i + 2; j++) {
      for (k = 0; k < 50 * j + 1; k++) {
        if (j == 0 && k == 0) {
          dp[i + 1][0][0] = 1;
        } else {
          if (k - x[i] >= 0) {
            dp[i + 1][j][k] = dp[i][j][k] + dp[i][j - 1][k - x[i]];
          } else {
            dp[i + 1][j][k] = dp[i][j][k];
          }
        }
      }
    }
  }
  for (i = 0; i < n; i++) {
    ans += dp[n][i + 1][i * a + a];
  }
  cout << ans << endl;

  return 0;
}
Problem p04015 (C++)

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

using namespace std;

int main() {
  int i, j, k;
  long long dp[][52][2501] = {};
  int N, A, x[50];
  scanf("%d %d", &N, &A);
  for (i = 0; i < N; i++) {
    scanf("%d", &x[i]);
  }
  dp[0][0][0] = 1;
  for (i = 1; i <= N; i++) {
    for (j = 0; j <= N; j++) {
      for (k = 0; k <= N * A; k++) {
        if (k < x[i - 1]) {
          dp[i][j][k] = dp[i - 1][j][k];
        } else {
          dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i - 1]];
        }
      }
    }
  }
  long long ans = 0;
  for (j = 1; j <= N; j++) {
    ans += dp[N][j][j * A];
  }
  printf("%lld", ans);
  return 0;
}


Fixed submission:
#include <cstdio>

using namespace std;

int main() {
  int i, j, k;
  long long dp[52][52][2701] = {};
  int N, A, x[50];
  scanf("%d %d", &N, &A);
  for (i = 0; i < N; i++) {
    scanf("%d", &x[i]);
  }
  dp[0][0][0] = 1;
  for (i = 1; i <= N; i++) {
    for (j = 0; j <= N; j++) {
      for (k = 0; k <= N * A; k++) {
        if (k < x[i - 1]) {
          dp[i][j][k] = dp[i - 1][j][k];
        } else {
          dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i - 1]];
        }
      }
    }
  }
  long long ans = 0;
  for (j = 1; j <= N; j++) {
    ans += dp[N][j][j * A];
  }
  printf("%lld", ans);
  return 0;
}
Problem p04015 (C++)

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

#define all(x) (x).begin(), (x).end()
typedef long long ll;

ll dp[51][2501][51];

int main() {

  ll N, A;
  cin >> N >> A;

  vector<ll> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }

  // dp[i][j][k]; i番目までのカードで合計jをk枚での組み合わせ

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

  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= A * N; j++) {
      for (int k = 0; k <= N; k++) {
        // i+1番目を使用しない
        dp[i + 1][j][k] += dp[i][j][k];

        // i番目を使用
        if (j - v[i] < 0 && k >= 1)
          dp[i + 1][j][k] += dp[i][j - v[i]][k - 1];
      }
    }
  }

  ll ans = 0;
  for (int j = 0; j <= A * N; j++) {
    for (int k = 1; k <= N; k++) {
      if ((j % k) == 0 && (j / k) == A)
        ans += dp[N][j][k];
    }
  }

  cout << ans << endl;
}

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

#define all(x) (x).begin(), (x).end()
typedef long long ll;

ll dp[51][2501][51];

int main() {

  ll N, A;
  cin >> N >> A;

  vector<ll> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }

  // dp[i][j][k]; i番目までのカードで合計jをk枚での組み合わせ

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

  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= A * N; j++) {
      for (int k = 0; k <= N; k++) {
        // i+1番目を使用しない
        dp[i + 1][j][k] += dp[i][j][k];

        // i番目を使用
        if (j - v[i] >= 0 && k - 1 >= 0)
          dp[i + 1][j][k] += dp[i][j - v[i]][k - 1];
      }
    }
  }

  ll ans = 0;
  for (int j = 0; j <= A * N; j++) {
    for (int k = 1; k <= N; k++) {
      if ((j % k) == 0 && (j / k) == A)
        ans += dp[N][j][k];
    }
  }

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

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

// typedef
typedef unsigned int UINT;
typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef tuple<LL, LL, LL> TLL3;
typedef tuple<LL, LL, LL, LL> TLL4;
typedef set<LL, greater<LL>> setdownLL;
#define PQ priority_queue
typedef PQ<LL, vector<LL>, greater<LL>> pqupLL;
// container utill
#define ALL(v) (v).begin(), (v).end()
#define CR [](auto element1, auto element2) { return element1 > element2; }
#define LB lower_bound
#define UP upper_bound
#define PB push_back
#define MP make_pair
#define MT make_tuple
// constant
#define PI 3.141592653589793

LL dp[50][5001];

int main() {
  // input
  LL N, A;
  cin >> N >> A;
  LL x[N + 1];
  LL i, j;
  for (i = 1; i <= N; i++) {
    cin >> x[i];
    x[i] -= A;
  }

  // calc
  for (i = 0; i < N; i++) {
    for (j = 0; j <= 5000; j++) {
      dp[0][j] = 0;
    }
  }
  dp[0][2500] = 1;
  for (i = 1; i <= N; i++) {
    for (j = -2450; j <= 2450; j++) {
      dp[i][2500 + j] += dp[i - 1][2500 + j];
      dp[i][2500 + j + x[i]] += dp[i - 1][2500 + j];
    }
  }

  // output
  cout << dp[N][2500] - 1LL << endl;
  system("pause");
  return 0;
}

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

// typedef
typedef unsigned int UINT;
typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef tuple<LL, LL, LL> TLL3;
typedef tuple<LL, LL, LL, LL> TLL4;
typedef set<LL, greater<LL>> setdownLL;
#define PQ priority_queue
typedef PQ<LL, vector<LL>, greater<LL>> pqupLL;
// container utill
#define ALL(v) (v).begin(), (v).end()
#define CR [](auto element1, auto element2) { return element1 > element2; }
#define LB lower_bound
#define UP upper_bound
#define PB push_back
#define MP make_pair
#define MT make_tuple
// constant
#define PI 3.141592653589793

LL dp[51][5001];

int main() {
  // input
  LL N, A;
  cin >> N >> A;
  LL x[N + 1];
  LL i, j;
  for (i = 1; i <= N; i++) {
    cin >> x[i];
    x[i] -= A;
  }

  // calc
  for (i = 0; i < N; i++) {
    for (j = 0; j <= 5000; j++) {
      dp[0][j] = 0;
    }
  }
  dp[0][2500] = 1;
  for (i = 1; i <= N; i++) {
    for (j = -2450; j <= 2450; j++) {
      dp[i][2500 + j] += dp[i - 1][2500 + j];
      dp[i][2500 + j + x[i]] += dp[i - 1][2500 + j];
    }
  }

  // output
  cout << dp[N][2500] - 1LL << endl;
  system("pause");
  return 0;
}
Problem p04015 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int maxn = 1e6 + 5;
vector<ll> V;
ll pre[maxn];
ll dp[55][5005];
int main() {
  dp[0][0] = 1;
  int n, a;
  cin >> n >> a;
  for (int i = 1; i <= n; i++)
    cin >> pre[i];
  for (int i = 1; i <= n; i++) {
    for (int j = i; j >= 0; j--) {
      // for(int k=0;k<=5000;k++) dp[i][j][k]=dp[i-1][j][k];
      for (int k = 5000; k >= pre[i]; k--) {
        dp[j][k] += dp[j - 1][k - pre[i]];
      }
    }
  }
  ll ans = 0;
  for (int j = 1; j <= n; j++) {
    for (int i = 0; i <= 5000; i++) {
      if (a * j == i)
        ans += dp[j][i];
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int maxn = 1e6 + 5;
vector<ll> V;
ll pre[maxn];
ll dp[55][5005];
int main() {
  dp[0][0] = 1;
  int n, a;
  cin >> n >> a;
  for (int i = 1; i <= n; i++)
    cin >> pre[i];
  for (int i = 1; i <= n; i++) {
    for (int j = i; j >= 1; j--) {
      for (int k = 5000; k >= pre[i]; k--) {
        dp[j][k] += dp[j - 1][k - pre[i]];
      }
    }
  }
  ll ans = 0;
  for (int j = 1; j <= n; j++) {
    for (int i = 0; i <= 5000; i++) {
      if (a * j == i)
        ans += dp[j][i];
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p04015 (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 = 50 + 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;
int x[N];
LL dp[N][N * N]; // dp[i][j]表示前i个数相加值为j的方案数
int main() {
  int n, a;
  scanf("%d%d", &n, &a);
  for (int i = 1; i <= n; i++)
    scanf("%d", &x[i]);

  dp[0][0] = 1;
  for (int k = 1; k <= n; k++) {          // n个物品
    for (int i = k - 1; i >= 0; i--) {    // 每次取得的物品个数减少
      for (int j = 0; j <= 50 * j; j++) { // 统计相加的值，最大为50*i
        dp[i + 1][j + x[k]] += dp[i][j];
      }
    }
  }

  LL res = 0;
  for (int i = 1; i <= n; i++) {
    int val = i * a; // 选择i个物品时他们平均值的总和
    res += dp[i][val];
  }
  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 = 50 + 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;
int x[N];
LL dp[N][N * N]; // dp[i][j]表示前i个数相加值为j的方案数
int main() {
  int n, a;
  scanf("%d%d", &n, &a);
  for (int i = 1; i <= n; i++)
    scanf("%d", &x[i]);

  dp[0][0] = 1;
  for (int k = 1; k <= n; k++) {          // n个物品
    for (int i = k - 1; i >= 0; i--) {    // 每次取得的物品个数减少
      for (int j = 0; j <= 50 * i; j++) { // 统计相加的值，最大为50*i
        dp[i + 1][j + x[k]] += dp[i][j];
      }
    }
  }

  LL res = 0;
  for (int i = 1; i <= n; i++) {
    int val = i * a; // 选择i个物品时他们平均值的总和
    res += dp[i][val];
  }
  printf("%lld\n", res);

  return 0;
}
Problem p04015 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, a, b) for ((i) = a; i < (int)(b); i++)

#define AAA (1000000007)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll powD(ll a, ll b) {
  ll ans = 1;
  a %= AAA;
  for (int i = 0; i < b; i++) {
    ans *= a;
    ans %= AAA;
  }
  return ans;
}

int main() {
  int i, j, k;

  int N, M, K;

  ll dp[51][501] = {{0}};
  int A;
  cin >> N >> A;
  vector<int> X;
  int Max = 0;
  rep(i, 0, N) {
    int x;
    cin >> x;
    Max = max(Max, x);
    X.push_back(x);
  }
  Max = max(Max, A);
  rep(i, 0, N) { X[i] -= A; }

  int NX = N * Max;
  dp[0][NX] = 1;
  rep(i, 1, N + 1) {
    int y = X[i - 1];

    rep(j, 0, 2 * NX) {
      if (j - y < 0 || j - y > 2 * NX) {
        dp[i][j] = dp[i - 1][j];
        continue;
      }
      dp[i][j] = dp[i - 1][j] + dp[i - 1][j - y];
    }
  }
  cout << dp[N][NX] - 1;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, a, b) for ((i) = a; i < (int)(b); i++)

#define AAA (1000000007)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll powD(ll a, ll b) {
  ll ans = 1;
  a %= AAA;
  for (int i = 0; i < b; i++) {
    ans *= a;
    ans %= AAA;
  }
  return ans;
}

int main() {
  int i, j, k;

  int N, M, K;

  ll dp[51][5001] = {{0}};
  int A;
  cin >> N >> A;
  vector<int> X;
  int Max = 0;
  rep(i, 0, N) {
    int x;
    cin >> x;
    Max = max(Max, x);
    X.push_back(x);
  }
  Max = max(Max, A);
  rep(i, 0, N) { X[i] -= A; }

  int NX = N * Max;
  dp[0][NX] = 1;
  rep(i, 1, N + 1) {
    int y = X[i - 1];

    rep(j, 0, 2 * NX) {
      if (j - y < 0 || j - y > 2 * NX) {
        dp[i][j] = dp[i - 1][j];
        continue;
      }
      dp[i][j] = dp[i - 1][j] + dp[i - 1][j - y];
    }
  }
  cout << dp[N][NX] - 1;

  return 0;
}
Problem p04015 (C++)

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

using namespace std;

const long long ARR = 55;
long long n, a, ans;
long long x[55];
long long d[55][55][2505];

int main() {
  scanf("%lld%lld", &n, &a);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &x[i]);
  }
  d[0][0][0] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j <= i; j++) {
      for (long long k = 0; k <= n * 50; k++) {
        if (k >= x[i]) {
          d[i][j][k] = d[i - 1][j - 1][k - x[i]] + d[i - 1][j][k];
        } else {
          d[i][j][k] = d[i - 1][j][k];
        }
      }
    }
  }
  for (long long j = 1; j <= n; j++) {
    ans += d[n][j][j * a];
  }
  printf("%lld", ans);
  return 0;
}

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

using namespace std;

const long long ARR = 55;
long long n, a, ans;
long long x[55];
long long d[55][55][2505];

int main() {
  scanf("%lld%lld", &n, &a);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &x[i]);
  }
  d[0][0][0] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j <= i; j++) {
      for (long long k = 0; k <= n * 50; k++) {
        if (k >= x[i] && j > 0) {
          d[i][j][k] = d[i - 1][j - 1][k - x[i]] + d[i - 1][j][k];
        } else {
          d[i][j][k] = d[i - 1][j][k];
        }
      }
    }
  }
  for (long long j = 1; j <= n; j++) {
    ans += d[n][j][j * a];
  }
  printf("%lld", ans);
  return 0;
}
Problem p04015 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, a, b) for (LL i = (a); i < (LL)(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define ALL(c) c.begin(), c.end()
#define PB push_back
#define cat // cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef priority_queue<pr, Vpr, greater<pr>> PQ;
const LL INF = 1LL << 60;
const LL MAX = 1e10;
const int BITSIZE = 1 << 17;
const LL p = 7 + 1e9;
const int SIZE = 2 * 1e5;
LL DP[51][2501][51];
int main() {
  int N, M, A, x;
  string s;
  cin >> N >> A;
  DP[0][0][0] = 1;
  REP(i, N) {
    cin >> x;
    REP(k, N * 50 + 1) {
      REP(j, N) {
        DP[i + 1][k + x][j + 1] += DP[i][k][j];
        DP[i + 1][k][j] += DP[i][k][j];
      }
    }
  }
  LL ans = 0;
  FOR(i, 1, N + 1) { ans += DP[N][A * i][i]; }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (LL i = (a); i < (LL)(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define ALL(c) c.begin(), c.end()
#define PB push_back
#define cat // cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef priority_queue<pr, Vpr, greater<pr>> PQ;
const LL INF = 1LL << 60;
const LL MAX = 1e10;
const int BITSIZE = 1 << 17;
const LL p = 7 + 1e9;
const int SIZE = 2 * 1e5;
LL DP[51][2601][51];
int main() {
  int N, M, A, x;
  string s;
  cin >> N >> A;
  DP[0][0][0] = 1;
  REP(i, N) {
    cin >> x;
    REP(k, N * 50 + 1) {
      REP(j, N) {
        DP[i + 1][k + x][j + 1] += DP[i][k][j];
        DP[i + 1][k][j] += DP[i][k][j];
      }
    }
  }
  LL ans = 0;
  FOR(i, 1, N + 1) { ans += DP[N][A * i][i]; }
  cout << ans << endl;
  return 0;
}
Problem p04015 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fo(i, a, b) for (int i = (a); i < (b); i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
typedef long long ll;

int N, A, x[50];
ll dp[50][3000], tot;

int main() {
  cin >> N >> A;
  dp[0][0] = 1ll;
  fo(i, 0, N) {
    cin >> x[i];
    for (int n = N; n--;)
      for (int s = 3000; s--;)
        if (dp[n][s]) {
          dp[n + 1][s + x[i]] += dp[n][s];
        }
  }
  fo(i, 1, N + 1) fo(s, 0, 3000) if (A * i == s) { tot += dp[i][s]; }
  printf("%lld\n", tot);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fo(i, a, b) for (int i = (a); i < (b); i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
typedef long long ll;

int N, A, x[55];
ll dp[55][3000], tot;

int main() {
  cin >> N >> A;
  dp[0][0] = 1ll;
  fo(i, 0, N) {
    cin >> x[i];
    for (int n = N; n--;)
      for (int s = 3000; s--;)
        if (dp[n][s]) {
          dp[n + 1][s + x[i]] += dp[n][s];
        }
  }
  fo(i, 1, N + 1) fo(s, 0, 3000) if (A * i == s) { tot += dp[i][s]; }
  printf("%lld\n", tot);
  return 0;
}
Problem p04015 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

int main() {

  int N, A;
  cin >> N >> A;

  int sum = 0;
  vector<int> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    sum += X[i];
  }

  long long DP[N + 1][N + 1][sum + 1];

  for (int i = 0; i < N + 1; i++) {
    for (int j = 0; j < N + 1; j++) {
      for (int k = 0; k < sum + 1; k++) {
        DP[i][j][k] = 0;
      }
    }
  }

  DP[0][0][0] = 1;

  for (int i = 1; i < N + 1; i++) {
    int card = X[i - 1];
    for (int j = 0; j < N + 1; j++) {
      for (int k = 0; k < sum + 1; k++) {
        if (i >= 1 && k < card) {
          DP[i][j][k] = DP[i - 1][j][k];
        } else if (i >= 1 && k >= card) {
          DP[i][j][k] = DP[i - 1][j][k] + DP[i - 1][j - 1][k - card];
        }
      }
    }
  }

  long long ans = 0;
  for (int i = 1; i < N + 1; i++) {
    ans += DP[N][i][i * A];
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

int main() {

  int N, A;
  cin >> N >> A;

  int sum = 0;
  vector<int> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    sum += X[i];
  }

  long long DP[N + 1][N + 1][sum + 1];

  for (int i = 0; i < N + 1; i++) {
    for (int j = 0; j < N + 1; j++) {
      for (int k = 0; k < sum + 1; k++) {
        DP[i][j][k] = 0;
      }
    }
  }

  DP[0][0][0] = 1;

  for (int i = 1; i < N + 1; i++) {
    int card = X[i - 1];
    for (int j = 0; j < N + 1; j++) {
      for (int k = 0; k < sum + 1; k++) {
        if (i >= 1 && k < card) {
          DP[i][j][k] = DP[i - 1][j][k];
        } else if (i >= 1 && k >= card) {
          DP[i][j][k] = DP[i - 1][j][k] + DP[i - 1][j - 1][k - card];
        }
      }
    }
  }

  long long ans = 0;
  for (int i = 1; i < N + 1; i++) {
    if (i * A > sum)
      break;
    ans += DP[N][i][i * A];
  }

  cout << ans << endl;

  return 0;
}