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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 1e5 + 4;
int n;
int A[MAXN], B[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &A[i], &B[i]);
  sort(A + 1, A + n + 1);
  sort(B + 1, B + n + 1);
  if (n & 1) {
    printf("%lld\n", 1LL + B[(n + 1) / 2] - A[(n + 1) / 2]);
  } else {
    int p = n / 2;
    printf("%lld\n", 1LL + B[p + 1] - A[p + 1] + B[p] - A[p]);
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 2e5 + 4;
int n;
int A[MAXN], B[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &A[i], &B[i]);
  sort(A + 1, A + n + 1);
  sort(B + 1, B + n + 1);
  if (n & 1) {
    printf("%lld\n", 1LL + B[(n + 1) / 2] - A[(n + 1) / 2]);
  } else {
    int p = n / 2;
    printf("%lld\n", 1LL + B[p + 1] - A[p + 1] + B[p] - A[p]);
  }
  return 0;
}
Problem p02661 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[100001], b[100001];
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1);
  if (n % 2 == 1) {
    cout << b[(n + 1) / 2] - a[(n + 1) / 2] + 1 << endl;
  } else
    cout << b[n / 2] + b[n / 2 + 1] - a[n / 2] - a[n / 2 + 1] + 1 << endl;

  return 0;
}


Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[200001], b[200001];
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1);
  if (n % 2 == 1) {
    cout << b[(n + 1) / 2] - a[(n + 1) / 2] + 1 << endl;
  } else
    cout << b[n / 2] + b[n / 2 + 1] - a[n / 2] - a[n / 2 + 1] + 1 << endl;

  return 0;
}
Problem p02661 (C++)

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

#define int long long
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;
}

signed main() {
  int n;
  cin >> n;

  int a[100010];
  int b[100010];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }

  sort(a, a + n);
  sort(b, b + n);

  if (n % 2 == 1) {
    cout << b[n / 2] - a[n / 2] + 1 << endl;
  } else {
    int t1 = a[n / 2] + a[n / 2 - 1];
    int t2 = b[n / 2] + b[n / 2 - 1];
    int ans = t2 - t1;
    cout << ans + 1 << endl;
  }

  return 0;
}


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

#define int long long
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;
}

signed main() {
  int n;
  cin >> n;

  int a[200010];
  int b[200010];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }

  sort(a, a + n);
  sort(b, b + n);

  if (n % 2 == 1) {
    cout << b[n / 2] - a[n / 2] + 1 << endl;
  } else {
    int t1 = a[n / 2] + a[n / 2 - 1];
    int t2 = b[n / 2] + b[n / 2 - 1];
    int ans = t2 - t1;
    cout << ans + 1 << endl;
  }

  return 0;
}
Problem p02661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
constexpr int MX = 100005;
int n, a[MX], b[MX], ans;
int main() {
  scanf("%d", &n);
  rep(i, n) scanf("%d%d", a + i, b + i);
  sort(a, a + n);
  sort(b, b + n);
  if (n % 2)
    ans = b[n / 2] - a[n / 2] + 1;
  else
    ans = b[n / 2 - 1] - a[n / 2 - 1] + b[n / 2] - a[n / 2] + 1;
  printf("%d\n", ans);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
constexpr int MX = 200005;
int n, a[MX], b[MX], ans;
int main() {
  scanf("%d", &n);
  rep(i, n) scanf("%d%d", a + i, b + i);
  sort(a, a + n);
  sort(b, b + n);
  if (n % 2)
    ans = b[n / 2] - a[n / 2] + 1;
  else
    ans = b[n / 2 - 1] - a[n / 2 - 1] + b[n / 2] - a[n / 2] + 1;
  printf("%d\n", ans);
}
Problem p02661 (C++)

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

long long a[100000];
long long b[100000];

int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", &a[i], &b[i]);
  }
  sort(a, a + n);
  sort(b, b + n);
  if (n % 2 == 1) {
    printf("%lld", b[n / 2] - a[n / 2] + 1);
  } else {
    printf("%lld", b[n / 2] + b[n / 2 - 1] - a[n / 2] - a[n / 2 - 1] + 1);
  }
}

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

long long a[200000];
long long b[200000];

int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", &a[i], &b[i]);
  }
  sort(a, a + n);
  sort(b, b + n);
  if (n % 2 == 1) {
    printf("%lld", b[n / 2] - a[n / 2] + 1);
  } else {
    printf("%lld", b[n / 2] + b[n / 2 - 1] - a[n / 2] - a[n / 2 - 1] + 1);
  }
}
Problem p02661 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for (ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for (ll i = (ll)(n - 1); i >= 0; i--)
#define repM1(i, n) for (ll i = (ll)(n - 1); i > 0; i--)
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;
}

int main() {
  cout << fixed << setprecision(18);

  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  ll ans;
  if (n % 2 == 1) {
    ans = b[(n + 1) / 2 - 1] - a[(n + 1) / 2 - 1] + 1;
  } else {
    double tmp_a = (a[n / 2 - 1] + a[(n / 2 + 1) - 1]) * 0.5;
    double tmp_b = (b[n / 2 - 1] + b[(n / 2 + 1) - 1]) * 0.5;

    ans = 0;
    for (; tmp_a <= tmp_b; tmp_a += 0.5)
      ans++;
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for (ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for (ll i = (ll)(n - 1); i >= 0; i--)
#define repM1(i, n) for (ll i = (ll)(n - 1); i > 0; i--)
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;
}

int main() {
  cout << fixed << setprecision(18);

  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  ll ans;
  if (n % 2 == 1) {
    ans = b[(n + 1) / 2 - 1] - a[(n + 1) / 2 - 1] + 1;
  } else {
    double tmp_a = (a[n / 2 - 1] + a[(n / 2 + 1) - 1]) * 0.5;
    double tmp_b = (b[n / 2 - 1] + b[(n / 2 + 1) - 1]) * 0.5;

    ll aa = tmp_a * 10 + 0.5;
    ll bb = tmp_b * 10 + 0.5;

    ans = (bb - aa) / 5 + 1;
  }

  cout << ans << endl;

  return 0;
}
Problem p02661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define N 100005
#define inf 1000000009
#define ll long long
#define pii pair<int, int>
#define sz(a) int(a.size())
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int n, a[N], b[N];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &a[i], &b[i]);
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1);
  if (n % 2 == 1)
    printf("%d", b[(n + 1) / 2] - a[(n + 1) / 2] + 1);
  else {
    int ma = a[n / 2 + 1] + a[n / 2];
    int mb = b[n / 2 + 1] + b[n / 2];
    printf("%d", mb - ma + 1);
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define N 200005
#define inf 1000000009
#define ll long long
#define pii pair<int, int>
#define sz(a) int(a.size())
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int n, a[N], b[N];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &a[i], &b[i]);
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1);
  if (n % 2 == 1)
    printf("%d", b[(n + 1) / 2] - a[(n + 1) / 2] + 1);
  else {
    int ma = a[n / 2 + 1] + a[n / 2];
    int mb = b[n / 2 + 1] + b[n / 2];
    printf("%d", mb - ma + 1);
  }
}
Problem p02661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll a[100010], b[100010];

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    cin >> a[i] >> b[i];
    a[i] *= 2;
    b[i] *= 2;
  }

  sort(a, a + n);
  sort(b, b + n);

  ll medl, medr, ans;

  if (n % 2 == 0) {
    medl = (a[n / 2 - 1] + a[n / 2]) / 2;
    medr = (b[n / 2 - 1] + b[n / 2]) / 2;
    ans = medr - medl + 1;
  } else {
    medl = a[(n - 1) / 2];
    medr = b[(n - 1) / 2];
    ans = (medr - medl) / 2 + 1;
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll a[200010], b[200010];

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    cin >> a[i] >> b[i];
    a[i] *= 2;
    b[i] *= 2;
  }

  sort(a, a + n);
  sort(b, b + n);

  ll medl, medr, ans;

  if (n % 2 == 0) {
    medl = (a[n / 2 - 1] + a[n / 2]) / 2;
    medr = (b[n / 2 - 1] + b[n / 2]) / 2;
    ans = medr - medl + 1;
  } else {
    medl = a[(n - 1) / 2];
    medr = b[(n - 1) / 2];
    ans = (medr - medl) / 2 + 1;
  }

  cout << ans << endl;

  return 0;
}
Problem p02661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void read(int &x) {
  int f = 1;
  x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-')
      f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  x *= f;
}
#define ll long long
ll le[100005];
ll ri[100005];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> le[i] >> ri[i];
  }
  sort(le + 1, le + n + 1);
  sort(ri + 1, ri + n + 1);
  if (n % 2 == 1) {
    cout << ri[n / 2 + 1] - le[n / 2 + 1] + 1LL << endl;

  } else {
    cout << ri[n / 2] + ri[n / 2 + 1] - le[n / 2] - le[n / 2 + 1] + 1LL << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void read(int &x) {
  int f = 1;
  x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-')
      f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  x *= f;
}
#define ll long long
ll le[200005];
ll ri[200005];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> le[i] >> ri[i];
  }
  sort(le + 1, le + n + 1);
  sort(ri + 1, ri + n + 1);
  if (n % 2 == 1) {
    cout << ri[n / 2 + 1] - le[n / 2 + 1] + 1LL << endl;

  } else {
    cout << ri[n / 2] + ri[n / 2 + 1] - le[n / 2] - le[n / 2 + 1] + 1LL << endl;
  }

  return 0;
}
Problem p02661 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vec<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  int inf = 2e9 + 1;
  if (N % 2 == 1) {
    int la = 0, ra = inf;
    while (la + 1 < ra) {
      int m = (la + ra) / 2;
      int c = 0;
      for (int i = 0; i < N; i++) {
        if (A[i] <= m)
          c++;
      }
      if (c >= (N + 1) / 2)
        ra = m;
      else
        la = m;
    }
    int lb = 0, rb = inf;
    while (lb + 1 < rb) {
      int m = (lb + rb) / 2;
      int c = 0;
      for (int i = 0; i < N; i++) {
        if (m <= B[i])
          c++;
      }
      if (c >= (N + 1) / 2)
        lb = m;
      else
        rb = m;
    }
    cout << lb - ra + 1 << "\n";
  } else {
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    int a = A[N / 2 - 1] + A[N / 2], b = B[N / 2 - 1] + B[N / 2];
    cout << b - a + 1 << "\n";
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vec<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  int inf = 2e9 + 1;
  if (N % 2 == 1) {
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    int a = A[N / 2], b = B[N / 2];
    cout << b - a + 1 << "\n";
  } else {
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    int a = A[N / 2 - 1] + A[N / 2], b = B[N / 2 - 1] + B[N / 2];
    cout << b - a + 1 << "\n";
  }
}
Problem p02661 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a[100005], b[100005];
int main() {
  ll n;
  cin >> n;
  for (ll i = 0; i < n; i++) {
    scanf("%lld%lld", &a[i], &b[i]);
  }
  sort(a, a + n);
  sort(b, b + n);
  ll low, hi;
  if (n & 1) {
    low = a[(n - 1) / 2];
    hi = b[(n - 1) / 2];
  } else {
    low = a[(n - 2) / 2] + a[(n - 2) / 2 + 1];
    hi = b[(n - 2) / 2] + b[(n - 2) / 2 + 1];
  }
  cout << hi - low + 1 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a[200005], b[200005];
int main() {
  ll n;
  cin >> n;
  for (ll i = 0; i < n; i++) {
    scanf("%lld%lld", &a[i], &b[i]);
  }
  sort(a, a + n);
  sort(b, b + n);
  ll low, hi;
  if (n & 1) {
    low = a[(n - 1) / 2];
    hi = b[(n - 1) / 2];
  } else {
    low = a[(n - 2) / 2] + a[(n - 2) / 2 + 1];
    hi = b[(n - 2) / 2] + b[(n - 2) / 2 + 1];
  }
  cout << hi - low + 1 << endl;
  return 0;
}
Problem p02662 (C++)

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

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

const ll mod = 998244353;

ll modpow(ll b, ll e) {
  ll ans = 1;
  for (; e; b = b * b % mod, e /= 2)
    if (e & 1)
      ans = ans * b % mod;
  return ans;
}

ll inv(ll x) { return modpow(x, mod - 2); }

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n, s;
  cin >> n >> s;
  vi a(n);
  rep(i, 0, n) cin >> a[i];

  ll i2 = inv(2);
  vi dp(s + 1, 0);
  dp[0] = 1;
  rep(i, 0, n) {
    per(j, 0, 3000) {
      if (j + a[i] <= 3000) {
        dp[j + a[i]] += dp[j] * i2 % mod;
        dp[j + a[i]] %= mod;
      }
    }
  }

  ll ans = modpow(2, n) * dp[s] % mod;
  ans %= mod;
  ans += mod;
  ans %= mod;

  cout << ans << '\n';
}

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

#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 all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

const ll mod = 998244353;

ll modpow(ll b, ll e) {
  ll ans = 1;
  for (; e; b = b * b % mod, e /= 2)
    if (e & 1)
      ans = ans * b % mod;
  return ans;
}

ll inv(ll x) { return modpow(x, mod - 2); }

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n, s;
  cin >> n >> s;
  vi a(n);
  rep(i, 0, n) cin >> a[i];

  ll i2 = inv(2);
  vi dp(s + 1, 0);
  dp[0] = 1;
  rep(i, 0, n) {
    per(j, 0, s) {
      if (j + a[i] <= s) {
        dp[j + a[i]] += dp[j] * i2 % mod;
        dp[j + a[i]] %= mod;
      }
    }
  }

  ll ans = modpow(2, n) * dp[s] % mod;
  ans %= mod;
  ans += mod;
  ans %= mod;

  cout << ans << '\n';
}
Problem p02662 (C++)

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

#define int long long
int dp[3123][3123], n, s, v[3123];
// dp[i][j]:sum:2^(n-k)*(i-1番目まで見てk個使って合計がjになる個数)
// dp[i+1][j]=dp[i][j-v[i]]/2+dp[i][j]
// 初期値はdp[0][0]=2^n
const int MOD = 998244353;
int pw(int n, int k) {
  assert(k >= 0);
  int res = 1;
  while (k) {
    if (k & 1)
      (res *= n) %= MOD;
    (n *= n) %= MOD;
    k >>= 1;
  }
  return res;
}
int f(int i, int j) {
  if (j < 0)
    return 0;
  if (!i)
    return pw(2, n) * (!j);
  if (~dp[i][j])
    return dp[i][j];
  return (f(i - 1, j - v[i - 1]) * pw(2, MOD - 2) + f(i - 1, j)) % MOD;
}

signed main() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> s;
  for (int i = 0; i < n; i++)
    cin >> v[i];
  cout << f(n, s) << endl;
}


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

#define int long long
int dp[3123][3123], n, s, v[3123];
// dp[i][j]:sum:2^(n-k)*(i-1番目まで見てk個使って合計がjになる個数)
// dp[i+1][j]=dp[i][j-v[i]]/2+dp[i][j]
// 初期値はdp[0][0]=2^n
const int MOD = 998244353;
int pw(int n, int k) {
  assert(k >= 0);
  int res = 1;
  while (k) {
    if (k & 1)
      (res *= n) %= MOD;
    (n *= n) %= MOD;
    k >>= 1;
  }
  return res;
}
int f(int i, int j) {
  if (j < 0)
    return 0;
  if (!i)
    return pw(2, n) * (!j);
  if (~dp[i][j])
    return dp[i][j];
  return dp[i][j] =
             (f(i - 1, j - v[i - 1]) * pw(2, MOD - 2) + f(i - 1, j)) % MOD;
}

signed main() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> s;
  for (int i = 0; i < n; i++)
    cin >> v[i];
  cout << f(n, s) << endl;
}
Problem p02662 (Python)

Buggy submission (status: Time Limit Exceeded):
MOD = 998244353
n, s = map(int, input().split())
a = list(map(int, input().split()))
f = [0] * (s + 1)
f[0] = pow(2, n, MOD)
v = pow(2, MOD - 2, MOD)
for i in range(n):
    for j in range(s, a[i] - 1, -1):
        f[j] += f[j - a[i]] * v
    for j in range(s + 1):
        f[j] %= MOD
print(f[s])


Fixed submission:
MOD = 998244353
n, s = map(int, input().split())
a = list(map(int, input().split()))
f = [0] * (s + 1)
f[0] = pow(2, n, MOD)
v = pow(2, MOD - 2, MOD)
for x in a:
    for j in range(s, x - 1, -1):
        f[j] += f[j - x] * v
    for j in range(s + 1):
        f[j] %= MOD
print(f[s])
Problem p02662 (Python)

Buggy submission (status: Runtime Error):
import numpy as np
import sys

input = sys.stdin.readline


def main():
    n, s = map(int, input().split())
    A = [int(i) for i in input().split()]

    MOD = 998244353

    dp = np.zeros(s + 1, dtype="int32")
    dp[0] = 1

    for a in A:
        p = (dp * 2) % MOD
        p %= MOD
        p[a:] += dp[:a]
        dp = p % MOD

    print(dp[s])


if __name__ == "__main__":
    main()


Fixed submission:
import numpy as np
import sys

input = sys.stdin.readline


def main():
    n, s = map(int, input().split())
    A = [int(i) for i in input().split()]

    MOD = 998244353

    dp = np.zeros(s + 1, dtype="int32")
    dp[0] = 1

    for a in A:
        p = (dp * 2) % MOD
        p %= MOD
        p[a:] += dp[:-a]
        dp = p % MOD

    print(dp[s])


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

Buggy submission (status: Runtime Error):
def resolve():
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    mod = 998244353
    dp = [0] * (s + 1)
    dp[0] = 1
    for i in a:
        for j in range(s - i, -1, -1):
            dp[j + i] = dp[j + i] * 2 + dp[j]
            dp[j + i] %= mod
        for j in range(min(i, s + 2)):
            dp[j] *= 2
            dp[j] %= mod
    print(dp[-1])


if __name__ == "__main__":
    resolve()


Fixed submission:
def resolve():
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    mod = 998244353
    dp = [0] * (s + 1)
    dp[0] = 1
    for i in a:
        for j in range(s - i, -1, -1):
            dp[j + i] = dp[j + i] * 2 + dp[j]
            dp[j + i] %= mod
        for j in range(min(i, s + 1)):
            dp[j] *= 2
            dp[j] %= mod
    print(dp[-1])


if __name__ == "__main__":
    resolve()
Problem p02662 (C++)

Buggy submission (status: Runtime Error):

/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
 **/

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define fix fixed << setprecision(10)
#define rep(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repb(i, b, a) for (int i = int(b); i >= int(a); i--)
#define FastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

typedef double db;
typedef long long ll;

const int N = 3005;
const int mod = 998244353;

int n, s, a[N], p[N], dp[N][N];
ll rec(int i, int x) {
  if (x == 0)
    return p[n - i + 1];
  if (i > n or x < 0)
    return 0;
  int &cache = dp[i][x];
  if (cache != -1)
    return cache;
  return cache = (rec(i + 1, x - a[i]) + 2 * rec(i + 1, x)) % mod;
}
signed main() {
  FastIO;
  p[0] = 1;
  rep(i, 1, 3e5) p[i] = p[i - 1] * 2 % mod;
  cin >> n >> s;
  rep(i, 1, n) cin >> a[i];
  memset(dp, -1, sizeof dp);
  cout << rec(1, s);
  return 0;
}


Fixed submission:

/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
 **/

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define fix fixed << setprecision(10)
#define rep(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repb(i, b, a) for (int i = int(b); i >= int(a); i--)
#define FastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

typedef double db;
typedef long long ll;

const int N = 3005;
const int mod = 998244353;

int n, s, a[N], p[N], dp[N][N];
ll rec(int i, int x) {
  if (x == 0)
    return p[n - i + 1];
  if (i > n or x < 0)
    return 0;
  int &cache = dp[i][x];
  if (cache != -1)
    return cache;
  return cache = (rec(i + 1, x - a[i]) + 2 * rec(i + 1, x)) % mod;
}
signed main() {
  FastIO;
  p[0] = 1;
  rep(i, 1, 3000) p[i] = p[i - 1] * 2 % mod;
  cin >> n >> s;
  rep(i, 1, n) cin >> a[i];
  memset(dp, -1, sizeof dp);
  cout << rec(1, s);
  return 0;
}
Problem p02662 (C++)

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

const int N = 3e3 + 23;
const int mod = 998244353;

long long dp[N][N];
int a[N];

void solve() {
  int n, s;
  scanf("%d%d", &n, &s);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  dp[0][0] = 1;
  for (int i = 0; i <= s; ++i) {
    for (int j = 0; j < n; ++j) {
      dp[i][j + 1] = (dp[i][j + 1] + dp[i][j] * 2) % mod;
      if (i + a[j] <= N)
        dp[i + a[j]][j + 1] = (dp[i + a[j]][j + 1] + dp[i][j]) % mod;
    }
  }
  printf("%lld", dp[s][n]);
}

int main() {
  init();
  int t = 1; // scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

const int N = 3e3 + 23;
const int mod = 998244353;

long long dp[N][N];
int a[N];

void solve() {
  int n, s;
  scanf("%d%d", &n, &s);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  dp[0][0] = 1;
  for (int i = 0; i <= s; ++i) {
    for (int j = 0; j < n; ++j) {
      dp[i][j + 1] = (dp[i][j + 1] + dp[i][j] * 2) % mod;
      if (i + a[j] <= s)
        dp[i + a[j]][j + 1] = (dp[i + a[j]][j + 1] + dp[i][j]) % mod;
    }
  }
  printf("%lld", dp[s][n]);
}

int main() {
  init();
  int t = 1; // scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02662 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const ll MOD = 998244353;

ll DP[3000][3000];

// A の部分集合 T、Tの部分集合 U で数える
int main() {
  int N, S;
  cin >> N >> S;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];

  DP[0][0] = 1;
  REP(i, N) REP(j, S + 1) {
    // Ai が T に選ばれない場合
    DP[i + 1][j] += DP[i][j];
    // Ai が T には選ばれているが U には選ばれていない場合
    DP[i + 1][j] += DP[i][j];
    DP[i + 1][j] %= MOD;
    // Ai が選ばれた場合
    if (A[i] + j <= S)
      DP[i + 1][j + A[i]] += DP[i][j];
    DP[i + 1][j] %= MOD;
  }
  cout << DP[N][S] << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const ll MOD = 998244353;

ll DP[3001][3001];

// A の部分集合 T、Tの部分集合 U で数える
int main() {
  int N, S;
  cin >> N >> S;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];

  DP[0][0] = 1;
  REP(i, N) REP(j, S + 1) {
    // Ai が T に選ばれない場合
    DP[i + 1][j] += DP[i][j];
    // Ai が T には選ばれているが U には選ばれていない場合
    DP[i + 1][j] += DP[i][j];
    DP[i + 1][j] %= MOD;
    // Ai が選ばれた場合
    if (A[i] + j <= S)
      DP[i + 1][j + A[i]] += DP[i][j];
    DP[i + 1][j] %= MOD;
  }
  cout << DP[N][S] << endl;
}
Problem p02662 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 3e3 + 5;
const int INF = 0x7f7f7f7f;
const ll p = 998244353;
#define DEBUG(x) cout << x << '\n'

int n, s, t, f[MAXN];
ll f_pow(ll a, ll b) {
  ll res = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1)
      res = res * a % p;
  return res;
}
int main() {
#ifdef Irene
  freopen("in.txt", "r", stdin);
#endif // Irene
  ios::sync_with_stdio(false);

  cin >> n >> s;
  f[0] = f_pow(2, n);
  ll inv2 = f_pow(2, p - 2);
  for (int i = 1; i <= n; i++) {
    cin >> t;
    for (int j = s - t; ~j; j--)
      f[j + t] = (f[j + t] + f[j] * inv2) % p;
  }
  cout << f[s];
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 3e3 + 5;
const int INF = 0x7f7f7f7f;
const ll p = 998244353;
#define DEBUG(x) cout << x << '\n'

int n, s, t, f[MAXN];
ll f_pow(ll a, ll b) {
  ll res = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1)
      res = res * a % p;
  return res;
}
int main() {
#ifdef Irene
  freopen("in.txt", "r", stdin);
#endif // Irene
  ios::sync_with_stdio(false);

  cin >> n >> s;
  f[0] = f_pow(2, n);
  ll inv2 = f_pow(2, p - 2);
  for (int i = 1; i <= n; i++) {
    cin >> t;
    for (int j = s - t; j >= 0; j--)
      f[j + t] = (f[j + t] + f[j] * inv2) % p;
  }
  cout << f[s];
}
Problem p02662 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 5, M = 998244353, OO = 0x3f3f3f3f;
typedef long long ll;
#define FIO                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
const double Pii = 3.14159265359;
ll n, m;
ll mem[N][N];
ll a[N];
ll solve(int idx, int su) {
  if (idx == n) {
    if (su == m)
      return 1;
    return 0;
  }
  if (mem[idx][su] != -1)
    return mem[idx][su];
  ll op1 = 0, op2 = 0;
  if (su + a[idx] <= m)
    op1 = solve(idx + 1, su + a[idx]);
  op2 = (solve(idx + 1, su) * 2);
  return mem[idx][su] = (op1 + (op2 % M)) % M;
}

int main() {
  FIO cin >> n >> m;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  memset(mem, -1, sizeof mem);
  ll ans = solve(0, 0);
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long N = 3e3 + 5, M = 998244353, OO = 0x3f3f3f3f;
typedef long long ll;
#define FIO                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
const double Pii = 3.14159265359;
ll n, m;
ll mem[N][N];
ll a[N];
ll solve(int idx, int su) {
  if (idx == n) {
    if (su == m)
      return 1;
    return 0;
  }
  if (mem[idx][su] != -1)
    return mem[idx][su];
  ll op1 = 0, op2 = 0;
  if (su + a[idx] <= m)
    op1 = solve(idx + 1, su + a[idx]);
  op2 = (solve(idx + 1, su) * 2);
  return mem[idx][su] = (op1 + (op2 % M)) % M;
}

int main() {
  FIO cin >> n >> m;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  memset(mem, -1, sizeof mem);
  ll ans = solve(0, 0);
  cout << ans << endl;
  return 0;
}
Problem p02662 (C++)

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

#define FOR(s, i, n) for (int i = s; i n; i++)
typedef long long ll;
const int INF = 1e9;

// 1000 mb = 1e9 b = 2.5e8 intergers

const int MOD = 998244353;
ll dp[3000][7000] = {{0}};  // ans up to i and n = i
ll dp2[3000][7000] = {{0}}; // solCnt up to i
ll binPow(ll x, ll k) {
  ll ans = 1;
  while (k > 0) {
    if (k % 2 == 0) {
      x = (x * x) % MOD;
      k /= 2;
    } else {
      ans = (ans * x) % MOD;
      k--;
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int n, s;
  cin >> n >> s;
  vector<int> nums(n);
  for (int i = 0; i < n; i++) {
    cin >> nums[i];
  }
  for (int i = 0; i < n; i++) {
    dp[i][0] = binPow(2, i);
    // dp2[i][0] = 1;
    for (int j = 0; j <= 3000; j++) {
      dp[i + 1][j] += dp[i][j] * 2;
      dp[i + 1][j] %= MOD;
      dp[i + 1][j + nums[i]] += dp[i][j];
      dp[i + 1][j + nums[i]] %= MOD;
      // dp2[i+1][j] += dp2[i][j];
      // dp2[i+1][j+nums[i]] += dp2[i][j];
    }
  }

  // for (int i = 0; i <= n; i++){
  // 	for (int j = 0; j <= 10; j++){
  // 		cout<<dp[i][j]<<' ';
  // 	}
  // 	cout<<'\n';
  // }
  cout << dp[n][s] << '\n';
  return 0;
}

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

#define FOR(s, i, n) for (int i = s; i n; i++)
typedef long long ll;
const int INF = 1e9;

// 1000 mb = 1e9 b = 2.5e8 intergers

const int MOD = 998244353;
ll dp[3005][7000] = {{0}};  // ans up to i and n = i
ll dp2[3005][7000] = {{0}}; // solCnt up to i
ll binPow(ll x, ll k) {
  ll ans = 1;
  while (k > 0) {
    if (k % 2 == 0) {
      x = (x * x) % MOD;
      k /= 2;
    } else {
      ans = (ans * x) % MOD;
      k--;
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int n, s;
  cin >> n >> s;
  vector<int> nums(n);
  for (int i = 0; i < n; i++) {
    cin >> nums[i];
  }
  for (int i = 0; i < n; i++) {
    dp[i][0] = binPow(2, i);
    // dp2[i][0] = 1;
    for (int j = 0; j <= 3000; j++) {
      dp[i + 1][j] += dp[i][j] * 2;
      dp[i + 1][j] %= MOD;
      dp[i + 1][j + nums[i]] += dp[i][j];
      dp[i + 1][j + nums[i]] %= MOD;
      // dp2[i+1][j] += dp2[i][j];
      // dp2[i+1][j+nums[i]] += dp2[i][j];
    }
  }

  // for (int i = 0; i <= n; i++){
  // 	for (int j = 0; j <= 10; j++){
  // 		cout<<dp[i][j]<<' ';
  // 	}
  // 	cout<<'\n';
  // }
  cout << dp[n][s] << '\n';
  return 0;
}
Problem p02662 (C++)

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

const int MOD = 998244353;
const int MAX_N = 305;
int N, S;
int A[MAX_N];

ll dp[MAX_N][MAX_N]; // len, sum

ll powmod(ll x, int y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      (res *= x) %= MOD;
    (x *= x) %= MOD;
    y >>= 1;
  }
  return res;
}

void solve() {
  dp[0][0] = powmod(2, N);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j <= S; ++j) {
      (dp[i + 1][j] += dp[i][j]) %= MOD;
      if (j + A[i] <= S)
        (dp[i + 1][j + A[i]] += dp[i][j] * powmod(2, MOD - 2) % MOD) %= MOD;
    }
  cout << dp[N][S];
}

int main() {
  cin >> N >> S;
  for (int i = 0; i < N; ++i)
    cin >> A[i];
  solve();
  return 0;
}

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

const int MOD = 998244353;
const int MAX_N = 3005;
int N, S;
int A[MAX_N];

ll dp[MAX_N][MAX_N]; // len, sum

ll powmod(ll x, int y) {
  ll res = 1;
  while (y) {
    if (y & 1)
      (res *= x) %= MOD;
    (x *= x) %= MOD;
    y >>= 1;
  }
  return res;
}

void solve() {
  dp[0][0] = powmod(2, N);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j <= S; ++j) {
      (dp[i + 1][j] += dp[i][j]) %= MOD;
      if (j + A[i] <= S)
        (dp[i + 1][j + A[i]] += dp[i][j] * powmod(2, MOD - 2) % MOD) %= MOD;
    }
  cout << dp[N][S];
}

int main() {
  cin >> N >> S;
  for (int i = 0; i < N; ++i)
    cin >> A[i];
  solve();
  return 0;
}
Problem p02662 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define dl double
#define mp make_pair
#define pb push_back
using namespace std;

//***********************************************************************

// hash struct for unordered_map
struct hash_pair {
  template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};

int MAXNUM = 5e3 + 5;
vector<int> vis(MAXNUM);
vector<int> pr;
void sieve() {
  pr.push_back(2);
  for (ll i = 3; i < MAXNUM; i += 2)
    if (!vis[i]) {
      pr.push_back(i);
      for (ll j = i * i; j < MAXNUM; j += 2 * i)
        vis[j] = true;
    }
}
//************************************************************************

ll mod = 998244353;

void solve() {
  ll n, s;
  cin >> n >> s;
  vector<ll> v(n);
  vector<vector<ll>> dp(n + 5, vector<ll>(s + 5));
  ll p = 1;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    p *= 2;
    p %= mod;
    dp[i][0] = p;
  }
  dp[0][v[0]] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= s; j++) {
      dp[i][j] = (2 * dp[i - 1][j]) % mod;
      if (j >= v[i]) {
        dp[i][j] += dp[i - 1][j - v[i]];
        dp[i][j] %= mod;
      }
    }
  }
  cout << dp[n - 1][s] << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t;
  // cin >> t;
  t = 1;
  while (t--) {
    solve();
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define dl double
#define mp make_pair
#define pb push_back
using namespace std;

//***********************************************************************

// hash struct for unordered_map
struct hash_pair {
  template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};

int MAXNUM = 5e3 + 5;
vector<int> vis(MAXNUM);
vector<int> pr;
void sieve() {
  pr.push_back(2);
  for (ll i = 3; i < MAXNUM; i += 2)
    if (!vis[i]) {
      pr.push_back(i);
      for (ll j = i * i; j < MAXNUM; j += 2 * i)
        vis[j] = true;
    }
}
//************************************************************************

ll mod = 998244353;

void solve() {
  ll n, s;
  cin >> n >> s;
  vector<ll> v(n);
  vector<vector<ll>> dp(n + 100, vector<ll>(s + 100, 0));
  ll p = 1;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    p *= 2;
    p %= mod;
    dp[i][0] = p;
  }
  dp[0][v[0]] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= s; j++) {
      dp[i][j] = (2 * dp[i - 1][j]) % mod;
      if (j >= v[i]) {
        dp[i][j] += dp[i - 1][j - v[i]];
        dp[i][j] %= mod;
      }
    }
  }
  cout << dp[n - 1][s] << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t;
  // cin >> t;
  t = 1;
  while (t--) {
    solve();
  }

  return 0;
}
Problem p02662 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define per(i, n) for (int i = (n)-1; i >= 0; --i)
#define rng(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
const int mod = 998244353;

int main() {
  ll n, s;
  cin >> n >> s;
  vl a(n);
  rep(i, n) cin >> a[i];
  vl dp(6060);
  dp[0] = 1;
  rep(i, n) {
    vl ndp(6060);
    rep(j, 6060) {
      (ndp[j] += dp[j] * 2) %= mod;
      (ndp[j + a[i]] += dp[j]) %= mod;
    }
    dp = ndp;
  }
  cout << dp[s] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define per(i, n) for (int i = (n)-1; i >= 0; --i)
#define rng(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
const int mod = 998244353;

int main() {
  ll n, s;
  cin >> n >> s;
  vl a(n);
  rep(i, n) cin >> a[i];
  vl dp(6060);
  dp[0] = 1;
  rep(i, n) {
    vl ndp(6060);
    rep(j, 3030) {
      (ndp[j] += dp[j] * 2) %= mod;
      (ndp[j + a[i]] += dp[j]) %= mod;
    }
    dp = ndp;
  }
  cout << dp[s] << endl;
  return 0;
}
Problem p02662 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MAX (ll)(1e3 + 7)
#define INF (ll)(4e18)
#define MOD (ll)(998244353)

using namespace std;
using ll = long long;
using cd = complex<double>;

int dp[MAX][MAX];
int mult(int a, int b) { return (a * 1LL * b) % MOD; }

int add(int a, int b) { return (a + b) % MOD; }

int pw(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1) {
      r = mult(r, a);
    }
    b >>= 1;
    a = mult(a, a);
  }
  return r;
}

int main() {
  int n, s;
  cin >> n >> s;
  int ar[n];
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  dp[0][0] = pw(2, n);
  int div = pw(2, MOD - 2);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= s; j++) {
      dp[i + 1][j] = add(dp[i + 1][j], dp[i][j]);
      if (ar[i] + j <= s) {
        dp[i + 1][ar[i] + j] = add(dp[i + 1][ar[i] + j], mult(dp[i][j], div));
      }
    }
  }
  cout << dp[n][s] << "\n";
}


Fixed submission:
#include <bits/stdc++.h>
#define MAX (ll)(3e3 + 7)
#define INF (ll)(4e18)
#define MOD (ll)(998244353)

using namespace std;
using ll = long long;
using cd = complex<double>;

int dp[MAX][MAX];
int mult(int a, int b) { return (a * 1LL * b) % MOD; }

int add(int a, int b) { return (a + b) % MOD; }

int pw(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1) {
      r = mult(r, a);
    }
    b >>= 1;
    a = mult(a, a);
  }
  return r;
}

int main() {
  int n, s;
  cin >> n >> s;
  int ar[n];
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  dp[0][0] = pw(2, n);
  int div = pw(2, MOD - 2);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= s; j++) {
      dp[i + 1][j] = add(dp[i + 1][j], dp[i][j]);
      if (ar[i] + j <= s) {
        dp[i + 1][ar[i] + j] = add(dp[i + 1][ar[i] + j], mult(dp[i][j], div));
      }
    }
  }
  cout << dp[n][s] << "\n";
}
Problem p02662 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
const long long INIT = -1;
const long long MOD = 998244353;
long long dp[3001][3001];
int _array[3005];
long long fact[3005];
long long dfs(int n, int value);
int main() {
  int n;
  int sum;
  cin >> n >> sum;
  fact[0] = 1;
  for (int i = 1; i <= n; i++) {
    cin >> _array[i];
    fact[i] = fact[i - 1] * i;
  }

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= sum; j++) {
      dp[i][j] = INIT;
    }
  }

  cout << dfs(n, sum) << endl;
  return (0);
}

long long dfs(int n, int value) {
  if (n == 0) {
    if (value == 0) {
      return (1);
    } else {
      return (0);
    }
  }
  if (dp[n][value] != INIT) {
    return (dp[n][value]);
  }

  long long s =
      (dfs(n - 1, value) * 2 % MOD + dfs(n - 1, value - _array[n]) % MOD) % MOD;
  //  cout<<"n:"<<n<<endl;
  //  cout<<"s:"<<s<<endl<<endl;
  return (dp[n][value] = s);
}

Fixed submission:
#include <iostream>
using namespace std;
const long long INIT = -1;
const long long MOD = 998244353;
long long dp[3001][3001];
int _array[3005];
long long fact[3005];
long long dfs(int n, int value);
int main() {
  int n;
  int sum;
  cin >> n >> sum;
  fact[0] = 1;
  for (int i = 1; i <= n; i++) {
    cin >> _array[i];
    fact[i] = fact[i - 1] * i;
  }

  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= sum; j++) {
      dp[i][j] = INIT;
    }
  }

  cout << dfs(n, sum) << endl;
  return (0);
}

long long dfs(int n, int value) {
  if (n == 0) {
    if (value == 0) {
      return (1);
    } else {
      return (0);
    }
  }
  if (dp[n][value] != INIT) {
    return (dp[n][value]);
  }

  long long s = dfs(n - 1, value) * 2 % MOD;
  if (value >= _array[n]) {
    s = (s + dfs(n - 1, value - _array[n] % MOD)) % MOD;
  }
  //  cout<<"n:"<<n<<endl;
  //  cout<<"s:"<<s<<endl<<endl;
  return (dp[n][value] = s);
}
Problem p02662 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const ll MOD = 998244353;

// あとで S+1 までループを回しているため
ll DP[3000][3001];

// A の部分集合 T、Tの部分集合 U で数える
int main() {
  int N, S;
  cin >> N >> S;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];

  DP[0][0] = 1;
  REP(i, N) REP(j, S + 1) {
    // Ai が T に選ばれない場合
    DP[i + 1][j] += DP[i][j];
    // Ai が T には選ばれているが U には選ばれていない場合
    DP[i + 1][j] += DP[i][j];
    DP[i + 1][j] %= MOD;
    // Ai が選ばれた場合
    if (A[i] + j <= S) {
      DP[i + 1][j + A[i]] += DP[i][j];
      DP[i + 1][j + A[i]] %= MOD;
    }
  }
  cout << DP[N][S] << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const ll MOD = 998244353;

// あとで S+1 までループを回しているため
ll DP[3001][3001];

// A の部分集合 T、Tの部分集合 U で数える
int main() {
  int N, S;
  cin >> N >> S;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];

  DP[0][0] = 1;
  REP(i, N) REP(j, S + 1) {
    // Ai が T に選ばれない場合
    DP[i + 1][j] += DP[i][j];
    // Ai が T には選ばれているが U には選ばれていない場合
    DP[i + 1][j] += DP[i][j];
    DP[i + 1][j] %= MOD;
    // Ai が選ばれた場合
    if (A[i] + j <= S) {
      DP[i + 1][j + A[i]] += DP[i][j];
      DP[i + 1][j + A[i]] %= MOD;
    }
  }
  cout << DP[N][S] << endl;
}
Problem p02662 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 3010;
const int mod = 998244353;
int n, s;
ll arr[N], dp[N][N];
bool vis[N][N];

ll fun(int pos, int rem) {
  if (pos > n) {
    if (rem == 0)
      return 1;
    return 0;
  }
  ll &ret = dp[pos][rem];
  if (vis[pos][rem])
    return ret;
  ret = 0;
  if (rem >= arr[pos]) {
    ret = (ret + fun(pos + 1, rem - arr[pos])) % mod;
  }
  ret = (ret + 2LL * fun(pos + 1, rem)) % mod;
  return ret;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> s;
  for (int i = 1; i <= n; ++i)
    cin >> arr[i];
  cout << fun(1, s) << '\n';
}

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

using namespace std;
typedef long long ll;
const int N = 3010;
const int mod = 998244353;
int n, s;
ll arr[N], dp[N][N];
bool vis[N][N];

ll fun(int pos, int rem) {
  if (pos > n) {
    if (rem == 0)
      return 1;
    return 0;
  }
  ll &ret = dp[pos][rem];
  if (vis[pos][rem])
    return ret;
  vis[pos][rem] = true;
  ret = 0;
  if (rem >= arr[pos]) {
    ret = (ret + fun(pos + 1, rem - arr[pos])) % mod;
  }
  ret = (ret + 2LL * fun(pos + 1, rem)) % mod;
  return ret;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> s;
  for (int i = 1; i <= n; ++i)
    cin >> arr[i];
  cout << fun(1, s) << '\n';
}
Problem p02662 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, s;
ll a[3003], dp[3003];
const ll mod = 998244353;
int main(void) {
  scanf("%lld%lld", &n, &s);
  for (ll i = 0; i < n; i++)
    scanf("%lld", &a[i]);
  dp[0] = 1;
  for (ll i = 0; i < n; i++) {
    for (ll j = s; j >= 0; j--) {
      dp[j + a[i]] += dp[j];
      dp[j + a[i]] %= mod;
      dp[j] *= 2;
      dp[j] %= mod;
    }
  }
  printf("%lld", dp[s]);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, s;
ll a[3003], dp[6003];
const ll mod = 998244353;
int main(void) {
  scanf("%lld%lld", &n, &s);
  for (ll i = 0; i < n; i++)
    scanf("%lld", &a[i]);
  dp[0] = 1;
  for (ll i = 0; i < n; i++) {
    for (ll j = s; j >= 0; j--) {
      dp[j + a[i]] += dp[j];
      dp[j + a[i]] %= mod;
      dp[j] *= 2;
      dp[j] %= mod;
    }
  }
  printf("%lld", dp[s]);
}
Problem p02662 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t

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

int main() {
  ll N, S;
  cin >> N >> S;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  vector<vector<ll>> DP(N + 1, vector<ll>(S + 1, 0));
  DP[0][A[0]] = 1;
  for (int i = 1; i < N; i++) {
    ll a = A[i];
    for (int j = 0; j <= S; j++) {
      DP[i][j] += DP[i - 1][j] * 2;
      DP[i][j] %= MOD;
      if (j == a)
        DP[i][j] += modpow(2, i);
      DP[i][j] %= MOD;
      if (j - a >= 0)
        DP[i][j] += DP[i - 1][j - a];
      DP[i][j] %= MOD;
    }
  }
  cout << DP[N - 1][S] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t

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

int main() {
  ll N, S;
  cin >> N >> S;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  vector<vector<ll>> DP(N + 1, vector<ll>(5000 + 1, 0));
  DP[0][A[0]] = 1;
  for (int i = 1; i < N; i++) {
    ll a = A[i];
    for (int j = 0; j <= S; j++) {
      DP[i][j] += DP[i - 1][j] * 2;
      DP[i][j] %= MOD;
      if (j == a)
        DP[i][j] += modpow(2, i);
      DP[i][j] %= MOD;
      if (j - a >= 0)
        DP[i][j] += DP[i - 1][j - a];
      DP[i][j] %= MOD;
    }
  }
  cout << DP[N - 1][S] << endl;
}