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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long int lli;
const lli mod = 998244353;

vector<lli> solve(int b, int e, lli s, vector<lli> &a) {
  vector<lli> res(s + 1, 0);
  if (e - b == 1) {
    res[0] = 2;
    if (a[b] <= s) {
      res[a[b]] = 1;
    }
    return res;
  }

  int mid = (b + e) / 2;
  auto ret1 = solve(b, mid, s, a);
  auto ret2 = solve(mid, e, s, a);
  for (int i = 0; i <= s; i++) {
    for (int j = 0; j <= i; j++) {
      res[i] += (ret1[j] * ret2[i - j]) % mod;
      res[i] %= mod;
    }
  }
  /*
  cerr << b << "," << e << endl;
  for(int i=0; i<=s; i++){
      cerr << res[i] << " ";
  }
  cerr << endl;
  */
  return res;
}

int main() {
  lli n, s;
  cin >> n >> s;
  vector<lli> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  auto ret = solve(0, n, s, a);
  cout << ret[s] << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long int lli;
const lli mod = 998244353;

vector<lli> solve(int b, int e, lli s, vector<lli> &a) {
  vector<lli> res(s + 1, 0);
  if (e - b == 1) {
    res[0] = 2;
    if (a[b] <= s) {
      res[a[b]] = 1;
    }
    return res;
  }

  int mid = (b + e) / 2;
  auto ret1 = solve(b, mid, s, a);
  auto ret2 = solve(mid, e, s, a);
  for (int i = 0; i <= s; i++) {
    for (int j = 0; j <= i; j++) {
      res[i] += (ret1[j] * ret2[i - j]) % mod;
      res[i] %= mod;
    }
  }
  /*
  cerr << b << "," << e << endl;
  for(int i=0; i<=s; i++){
      cerr << res[i] << " ";
  }
  cerr << endl;
  */
  return res;
}

int main() {
  lli n, s;
  cin >> n >> s;
  vector<lli> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<lli> dp(s + 1, 0);
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    vector<lli> ndp(s + 1, 0);
    for (int j = 0; j <= s; j++) {
      ndp[j] += (2 * dp[j]) % mod;
      ndp[j] %= mod;
    }
    for (int j = 0; j + a[i] <= s; j++) {
      ndp[j + a[i]] += dp[j];
      ndp[j + a[i]] %= mod;
    }
    swap(dp, ndp);
  }
  cout << dp[s] << endl;
  return 0;
}
Problem p02662 (C++)

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

int main() {
  int n, s;
  cin >> n >> s;
  vector<vector<ll>> dp(n, vector<ll>(s + 5));
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  dp[0][0] = 2;
  dp[0][a[0]] = 1;
  rep(i, n - 1) {
    rep(j, s + 1) {
      dp[i + 1][j] = dp[i][j] * 2 % mod;
      if (j >= a[i + 1])
        dp[i + 1][j] = (dp[i + 1][j] + dp[i][j - a[i + 1]]) % mod;
    }
  }
  ll ans = dp[n - 1][s];
  cout << ans << endl;
  return 0;
}


Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
const ll mod = 998244353;

int main() {
  int n, s;
  cin >> n >> s;
  vector<vector<ll>> dp(n, vector<ll>(3005));
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  dp[0][0] = 2;
  dp[0][a[0]] = 1;
  rep(i, n - 1) {
    rep(j, s + 1) {
      dp[i + 1][j] = dp[i][j] * 2 % mod;
      if (j >= a[i + 1])
        dp[i + 1][j] = (dp[i + 1][j] + dp[i][j - a[i + 1]]) % mod;
    }
  }
  ll ans = dp[n - 1][s];
  cout << ans << endl;
  return 0;
}
Problem p02662 (C++)

Buggy submission (status: Runtime Error):
//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include <bits/stdc++.h>
#define MAX 3005
#define optimiza_io                                                            \
  cin.tie(0);                                                                  \
  ios_base::sync_with_stdio(0);
#define what_is(x) cerr << #x << " is " << x << endl;
#define pii pair<ll, ll>
#define fi first
#define se second
using namespace std;
typedef long long ll;

ll a[MAX], N, S, ans;
ll memo[MAX][MAX];
const ll MOD = 998244353;

ll dp(ll x, ll sm) {
  if (x > N) {
    if (sm != S)
      return 0;
    return 1;
  }
  if (memo[x][sm] != -1)
    return memo[x][sm];

  ll ans = 0;
  ans += dp(x + 1, sm + a[x]);
  ans += dp(x + 1, sm) * 2;
  ans %= MOD;
  return memo[x][sm] = ans;
}

int main() {
  optimiza_io cin >> N >> S;
  for (ll i = 1; i <= N; i++)
    cin >> a[i];
  memset(memo, -1, sizeof memo);
  cout << dp(1, 0) << "\n";
  return 0;
}

// CHECAR LIMITES

Fixed submission:
//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include <bits/stdc++.h>
#define MAX 3005
#define optimiza_io                                                            \
  cin.tie(0);                                                                  \
  ios_base::sync_with_stdio(0);
#define what_is(x) cerr << #x << " is " << x << endl;
#define pii pair<ll, ll>
#define fi first
#define se second
using namespace std;
typedef long long ll;

ll a[MAX], N, S, ans;
ll memo[MAX][MAX];
const ll MOD = 998244353;

ll dp(ll x, ll sm) {
  if (x > N) {
    if (sm != S)
      return 0;
    return 1;
  }
  if (sm > S)
    return 0;
  if (memo[x][sm] != -1)
    return memo[x][sm];

  ll ans = 0;
  ans += dp(x + 1, sm + a[x]);
  ans += dp(x + 1, sm) * 2;
  ans %= MOD;
  return memo[x][sm] = ans;
}

int main() {
  optimiza_io cin >> N >> S;
  for (ll i = 1; i <= N; i++)
    cin >> a[i];
  memset(memo, -1, sizeof memo);
  cout << dp(1, 0) << "\n";
  return 0;
}

// CHECAR LIMITES
Problem p02662 (C++)

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template <typename T>
constexpr T inf =
    static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) +
    7;
constexpr llong mod = 998244353;

llong pow_mod(llong n, llong m) {
  if (m == 0)
    return 1;
  if (m == 1)
    return n;

  llong ret = pow_mod(n, m / 2);
  ret = ret * ret % mod;
  if (m & 1) {
    ret = ret * n % mod;
  }
  return ret;
}

int main() {
  llong N, S;
  vector<llong> A;

  cin >> N >> S;
  A.resize(N);
  for (auto &in : A) {
    cin >> in;
  }

  vector<llong> dp(S + 1);
  for (int i = 0; i < N; ++i) {
    vector<llong> now(S + 1);
    for (int j = S; j >= 0; --j) {
      now[j] = dp[j] * 2;
      if (j >= A[i]) {
        now[j] += dp[j - A[i]];
      }
      now[j] %= mod;
    }
    now[A[i]] += pow_mod(2, i);
    swap(dp, now);
  }

  cout << dp[S] << endl;

  return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template <typename T>
constexpr T inf =
    static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) +
    7;
constexpr llong mod = 998244353;

llong pow_mod(llong n, llong m) {
  if (m == 0)
    return 1;
  if (m == 1)
    return n;

  llong ret = pow_mod(n, m / 2);
  ret = ret * ret % mod;
  if (m & 1) {
    ret = ret * n % mod;
  }
  return ret;
}

int main() {
  llong N, S;
  vector<llong> A;

  cin >> N >> S;
  A.resize(N);
  for (auto &in : A) {
    cin >> in;
  }

  vector<llong> dp(S + 1);
  for (int i = 0; i < N; ++i) {
    vector<llong> now(S + 1);
    for (int j = S; j >= 0; --j) {
      now[j] = dp[j] * 2;
      if (j >= A[i]) {
        now[j] += dp[j - A[i]];
      }
      now[j] %= mod;
    }
    if (A[i] <= S) {
      now[A[i]] += pow_mod(2, i);
    }
    swap(dp, now);
  }

  cout << dp[S] << endl;

  return 0;
}
Problem p02662 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 998244353;
const int IMAX = 100000;
constexpr ll modpow(ll A, ll B) {
  ll kotae = 1;
  while (B > 0) {
    if (B & 1)
      kotae = kotae * A % mod;
    A = A * A % mod;
    B >>= 1;
  }
  return kotae;
}

ll dp[3001];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, S;
  cin >> N >> S;

  int A[3000];
  rep(i, N) cin >> A[i];
  sort(A, A + N);

  ll k2 = modpow(2, mod - 2);
  dp[0] = modpow(2, N);
  int s = 0;
  rep(i, N) {
    s += min(S, s + A[i]);
    for (int j = s; j >= A[i]; j--) {
      dp[j] = (dp[j] + dp[j - A[i]] * k2) % mod;
    }
  }

  co(dp[S] % mod);

  Would you please return 0;
}

Fixed submission:
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 998244353;
const int IMAX = 100000;
constexpr ll modpow(ll A, ll B) {
  ll kotae = 1;
  while (B > 0) {
    if (B & 1)
      kotae = kotae * A % mod;
    A = A * A % mod;
    B >>= 1;
  }
  return kotae;
}

ll dp[3001];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, S;
  cin >> N >> S;

  int A[3000];
  rep(i, N) cin >> A[i];
  sort(A, A + N);

  ll k2 = modpow(2, mod - 2);
  dp[0] = modpow(2, N);
  int s = 0;
  rep(i, N) {
    s = min(S, s + A[i]);
    for (int j = s; j >= A[i]; j--) {
      dp[j] = (dp[j] + dp[j - A[i]] * k2) % mod;
    }
  }

  co(dp[S] % mod);

  Would you please return 0;
}
Problem p02662 (C++)

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

#define fr(i, n) for (int i = 0; i < n; i++)
#define sz(v) (v).begin(), (v).end()
#define prin(a) cout << #a << " = " << a << endl
#define all(v) (v).begin(), (v).end()
typedef long long ll;

const int N = 2e3 + 10;
ll dp[2][N], v[N];
#define cur_dp dp[(i + 1) & 1]
#define ant_dp dp[i & 1]
const ll MOD = 998244353;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, s;
  cin >> n >> s;
  fr(i, n) cin >> v[i];

  dp[0][0] = 1;
  fr(i, n) {
    for (int j = 0; j <= s; j++) {
      cur_dp[j] = 2 * ant_dp[j] % MOD;
      if (v[i] <= j)
        cur_dp[j] = (ant_dp[j - v[i]] + cur_dp[j]) % MOD;
    }
  }
  cout << dp[n & 1][s] << endl;
}

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

#define fr(i, n) for (int i = 0; i < n; i++)
#define sz(v) (v).begin(), (v).end()
#define prin(a) cout << #a << " = " << a << endl
#define all(v) (v).begin(), (v).end()
typedef long long ll;

const int N = 3e3 + 10;
ll dp[2][N], v[N];
#define cur_dp dp[(i + 1) & 1]
#define ant_dp dp[i & 1]
const ll MOD = 998244353;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, s;
  cin >> n >> s;
  fr(i, n) cin >> v[i];

  dp[0][0] = 1;
  fr(i, n) {
    for (int j = 0; j <= s; j++) {
      cur_dp[j] = 2 * ant_dp[j] % MOD;
      if (v[i] <= j)
        cur_dp[j] = (ant_dp[j - v[i]] + cur_dp[j]) % MOD;
    }
  }
  cout << dp[n & 1][s] << endl;
}
Problem p02662 (C++)

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

const long long MOD = 998244353;

long long pow(long long x, long long n, long long mod) {
  long long ans = 1;
  while (n) {
    if (n % 2)
      ans *= x;
    x *= x;
    x %= mod;
    ans %= mod;
    n >>= 1;
  }
  return ans;
}

long long inv = pow(2, MOD - 2, MOD);

long long dp[3010][3010];

void solve(long long N, long long S, std::vector<long long> A) {
  dp[0][0] = pow(2, N, MOD);
  if (A[0] <= S) {
    dp[0][A[0]] = pow(2, N - 1, MOD);
  }

  for (int i = 1; i < N; i++) {
    for (size_t j = 0; j <= S; j++) {
      dp[i][j] += dp[i - 1][j];
      if (j - A[i] >= 0) {
        dp[i][j] += dp[i - 1][j - A[i]] * inv;
      }
      dp[i][j] %= MOD;
    }
  }

  cout << dp[N - 1][S] << endl;
}

// Generated by 1.1.7.1 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 S;
  scanf("%lld", &S);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, S, std::move(A));
  return 0;
}


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

const long long MOD = 998244353;

long long pow(long long x, long long n, long long mod) {
  long long ans = 1;
  while (n) {
    if (n % 2)
      ans *= x;
    x *= x;
    x %= mod;
    ans %= mod;
    n >>= 1;
  }
  return ans;
}

long long inv = pow(2, MOD - 2, MOD);

long long dp[3010][3010];

void solve(long long N, long long S, std::vector<long long> A) {
  dp[0][0] = pow(2, N, MOD);
  if (A[0] <= S) {
    dp[0][A[0]] = pow(2, N - 1, MOD);
  }

  for (int i = 1; i < N; i++) {
    for (int j = 0; j <= S; j++) {
      dp[i][j] += dp[i - 1][j];
      if (j - A[i] >= 0) {
        dp[i][j] += dp[i - 1][j - A[i]] * inv;
      }
      dp[i][j] %= MOD;
    }
  }

  cout << dp[N - 1][S] << endl;
}

// Generated by 1.1.7.1 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 S;
  scanf("%lld", &S);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, S, std::move(A));
  return 0;
}
Problem p02662 (C++)

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

int A[3005];

long long memo[3005][3005];
const long long modConst = 998244353;

long long DP(int N, int S) {
  if (S < 0)
    return 0;

  if (N == 0 && S == 0)
    return 1;

  if (N == 0)
    return 0;

  if (memo[N][S] != -1)
    return memo[N][S];

  long long putToBoth = DP(N - 1, S - A[N]);
  long long putToTOnly = DP(N - 1, S);
  long long putToNone = DP(N - 1, S);

  return (putToBoth + putToTOnly + putToNone) % modConst;
}

int main() {
  int N, S;
  scanf("%d%d", &N, &S);

  for (int i = 1; i <= N; i++)
    scanf("%d", &A[i]);

  for (int i = 0; i < 3005; i++) {
    for (int j = 0; j < 3005; j++)
      memo[i][j] = -1;
  }

  long long ans = DP(N, S);
  printf("%lld", ans);
}


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

int A[3005];

long long memo[3005][3005];
const long long modConst = 998244353;

long long DP(int N, int S) {
  if (S < 0)
    return 0;

  if (N == 0 && S == 0)
    return 1;

  if (N == 0)
    return 0;

  if (memo[N][S] != -1)
    return memo[N][S];

  long long putToBoth = DP(N - 1, S - A[N]);
  long long putToTOnly = DP(N - 1, S);
  long long putToNone = DP(N - 1, S);

  memo[N][S] = (putToBoth + putToTOnly + putToNone) % modConst;
  return memo[N][S];
}

int main() {
  int N, S;
  scanf("%d%d", &N, &S);

  for (int i = 1; i <= N; i++)
    scanf("%d", &A[i]);

  for (int i = 0; i < 3005; i++) {
    for (int j = 0; j < 3005; j++)
      memo[i][j] = -1;
  }

  long long ans = DP(N, S);
  printf("%lld", ans);
}
Problem p02663 (C++)

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

int main() {
  int H[2], M[2], K;
  cin >> H[1] >> M[1] >> H[2] >> M[2] >> K;
  cout << 60 * (H[2] - H[1]) + M[2] - M[1] - K << endl;
}


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

int main() {
  int H, M, A, B, K;
  cin >> H >> M >> A >> B >> K;
  cout << 60 * (A - H) + B - M - K << endl;
}
Problem p02663 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int diff = (h2 * 60 + m2) - (h1 * 60 + m1);
  // cout<<diff;
  if ((diff - k) > 0)
    cout << diff - k;
  else
    cout << 0;
  return 1;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int diff = (h2 * 60 + m2) - (h1 * 60 + m1);
  // cout<<diff;
  if ((diff - k) > 0)
    cout << diff - k;
  else
    cout << 0;
  return 0;
}
Problem p02664 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <string.h>

int main() {
  static char T[100001];
  scanf("%s", T);

  size_t len = strlen(T);
  for (size_t i = 0; i < len; i++) {
    if (T[i] == '?') {
      T[i] = 'D';
    }
  }
  printf("%s\n", T);

  return 0;
}


Fixed submission:
#include <stdio.h>
#include <string.h>

int main() {
  static char T[200001];
  scanf("%s", T);

  size_t len = strlen(T);
  for (size_t i = 0; i < len; i++) {
    if (T[i] == '?') {
      T[i] = 'D';
    }
  }
  printf("%s\n", T);

  return 0;
}
Problem p02664 (C++)

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

int main() {
  string t;
  cin >> t;
  for (long long i = 0; i < t.size(); i++) {
    if (t.at(i) == '?') {
      if (t.at(i - 1) == 'P')
        t.at(i) = 'D';
      else
        t.at(i) = 'P';
    }
  }
  cout << t << endl;
}

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

int main() {
  string t;
  cin >> t;
  for (int i = 0; i < t.size(); i++) {
    if (t.at(i) == '?')
      t.at(i) = 'D';
  }
  cout << t << endl;
}
Problem p02664 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
char s[N];
int n;
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < n; ++i)
    if (s[i] == '?')
      s[i] = 'D';
  printf("%s\n", s);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
char s[N];
int n;
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < n; ++i)
    if (s[i] == '?')
      s[i] = 'D';
  printf("%s\n", s);
}
Problem p02664 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define dec(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

int main() {
  string S;
  cin >> S;
  ll N;

  rep(i, S.size()) {
    if (S.at(i) == '?' && S.at(i - 1) == 'P') {
      S.at(i) = 'D';
    } else if (S.at(i) == '?' && S.at(i - 1) == 'D') {
      S.at(i) = 'D';
    } else if (S.at(i) == '?') {
      S.at(i) = 'D';
    }
  }
  cout << S << endl;
}


Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define dec(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

int main() {
  string S;
  cin >> S;
  ll N;

  rep(i, S.size()) {
    if (S.at(i) == '?') {
      S.at(i) = 'D';
    }
  }
  cout << S << endl;
}
Problem p02664 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
char p[200010];
char a[200010];
int main() {
  int i;
  scanf("%s", p);
  for (i = 0; i < strlen(p); i++) {
    if (p[i] == '?')
      a[i] = 'D';
    else
      a[i] = p[i];
  }
  printf("%s", a);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
char p[200010];
char a[200010];
int main() {
  int i = 0;
  char ps;
  while (scanf("%c", &ps) != EOF) {
    if (ps == '?') {
      a[i++] = 'D';
    } else
      a[i++] = ps;
  }
  printf("%s", a);
}
Problem p02664 (C++)

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

int main() {
  string T;
  cin >> T;
  ll count = 0;

  for (ll i = 0; i < (int)T.size(); i++) {
    if (i != (int)T.size() - 1 && T.at(i) == '?' && T.at(i + 1) == '?') {
      count++;
    }
  }

  for (ll j = 0; j < count + 2; j++) {

    for (ll i = 0; i < (int)T.size(); i++) {
      if (i == (int)T.size() - 1 && T.at(i) == '?') {
        T.at(i) = 'D';
      } else if (i != (int)T.size() - 1 && T.at(i) == '?' &&
                 T.at(i + 1) == 'P') {
        T.at(i) = 'D';
      } else if (i != (int)T.size() - 1 && T.at(i) == '?' &&
                 T.at(i + 1) == 'D') {
        T.at(i) = 'P';
      }
    }
  }

  for (ll i = 0; i < (int)T.size(); i++) {
    cout << T.at(i);
  }
}

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

int main() {
  string T;
  cin >> T;
  ll count = 0;

  for (ll i = 0; i < (int)T.size(); i++) {
    if (T.at(i) == '?') {
      T.at(i) = 'D';
    }
  }

  for (ll i = 0; i < (int)T.size(); i++) {
    cout << T.at(i);
  }
}
Problem p02664 (C++)

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

int main() {
  string t;
  cin >> t;

  if (t.at(0) == '?' && t.at(1) == 'P')
    t.at(0) = 'D';
  else
    t.at(0) = 'P';

  for (int i = 1; i < t.size() - 1; i++) {
    if (t.at(i) == '?') {
      if (t.at(i + 1) == 'D' && t.at(i - 1) == 'D')
        t.at(i) = 'P';
      else
        t.at(i) = 'D';
    }
  }
  if (t.at(t.size() - 1) == '?')
    t.at(t.size() - 1) = 'D';
  cout << t << endl;
}

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

int main() {
  string t;
  cin >> t;

  if (t.size() == 1) {
    if (t.at(0) == 'P')
      t.at(0) = 'P';
    else
      t.at(0) = 'D';
  }

  if (t.at(0) == '?' && t.size() > 1) {
    if (t.at(1) == 'P')
      t.at(0) = 'D';
    else
      t.at(0) = 'P';
  }

  for (int i = 1; i < t.size() - 1; i++) {
    if (t.at(i) == '?') {
      if (t.at(i + 1) == 'D' && t.at(i - 1) == 'D')
        t.at(i) = 'P';
      else
        t.at(i) = 'D';
    }
  }
  if (t.at(t.size() - 1) == '?')
    t.at(t.size() - 1) = 'D';
  cout << t << endl;
}
Problem p02664 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
char cc[200010];
int main() {
  cin >> cc;
  int i, j, k, l;
  for (i = 0; i < strlen(cc); i++) {
    if (cc[i] == '?') {
      cout << "D";
    } else
      cout << cc[i];
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
char cc[200010];
int main() {
  scanf("%s", cc);
  int i, j, k, l = strlen(cc);
  for (i = 0; i < l; i++) {
    if (cc[i] == '?') {
      cout << "D";
    } else
      cout << cc[i];
  }
}
Problem p02664 (C++)

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

int main() {
  string t;
  cin >> t;
  for (int i = 0; i < t.size(); i++) {
    if (t.at(i) == '?') {
      if (t.at(i + 1) == 'P')
        t.at(i) = 'D';
      else if (t.at(i + 1) == 'D')
        t.at(i) = 'P';
      else {
        t.at(i) = 'P';
        t.at(i + 1) = 'D';
        i++;
      }
    }
  }
  cout << t << endl;
}


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

int main() {
  string t;
  cin >> t;
  int s = t.size();
  for (int i = 0; i < s; i++) {
    if (t.at(i) == '?')
      t.at(i) = 'D';
  }
  cout << t << endl;
}
Problem p02664 (C++)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  string t;
  cin >> t;
  long num = t.size() - 1;
  rep(i, t.size()) {
    if (t.at(i) == '?') {
      if (i == 0) {
        if (t.at(i + 1) == 'P') {
          t.at(i) = 'D';
        } else {
          t.at(i) = 'D';
        }
      } else if (i == num) {
        t.at(i) = 'D';
      } else {
        if (t.at(i - 1) == 'P') {
          t.at(i) = 'D';
        } else if (t.at(i + 1) == 'P') {
          t.at(i) = 'D';
        } else {
          t.at(i) = 'D';
        }
      }
    }
  }
  cout << t << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  string t;
  cin >> t;
  long num = t.size() - 1;
  rep(i, t.size()) {
    if (t.at(i) == '?') {
      if (i == 0) {
        t.at(i) = 'D';
      } else if (i == num) {
        t.at(i) = 'D';
      } else {
        if (t.at(i - 1) == 'P') {
          t.at(i) = 'D';
        } else if (t.at(i + 1) == 'P') {
          t.at(i) = 'D';
        } else {
          t.at(i) = 'D';
        }
      }
    }
  }
  cout << t << endl;
  return 0;
}
Problem p02664 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define N 233
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
char s[N];
int n;
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) {
    putchar(s[i] == 'P' ? 'P' : 'D');
  }
  return 0;
}


Fixed submission:
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define N 200020
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
char s[N];
int n;
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) {
    putchar(s[i] == 'P' ? 'P' : 'D');
  }
  return 0;
}
Problem p02664 (C++)

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ll t = 1;
  // cin >> t;
  while (t--) {
    string s;
    cin >> s;
    string ans = "";
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '?') {
        ans = ans + 'D';
      } else
        ans = ans + s[i];
    }
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ll t = 1;
  // cin >> t;
  while (t--) {
    string s;
    cin >> s;
    std::replace(s.begin(), s.end(), '?', 'D'); // replace all 'x' to 'y'
    cout << s << endl;
  }
  return 0;
}
Problem p02664 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
int main() {
  string T;
  cin >> T;
  for (int i = 0; T.length(); i++)
    if (T[i] == '?')
      T[i] = 'D';
  cout << T << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
int main() {
  string t;
  cin >> t;
  for (int i = 0; i < t.length(); i++)
    if (t[i] == '?')
      t[i] = 'D';
  cout << t << endl;
  return 0;
}
Problem p02664 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string.h>
using namespace std;

int main() {
  string s;
  cin >> s;

  if (s.find("?") == string::npos) {
    cout << s;
    // cout << "? ga naiyo\n";
    return 0;
  }

  size_t position_Phatena = 0;
  size_t position_2hatena = 0;
  size_t position_hatenaD = 0;
  size_t position_hatena = 0;

  while (s.find("?") != string::npos) {
    if ((position_Phatena = s.find("P?")) != string::npos) {
      s[position_hatenaD + 1] = 'D';
    }
    if ((position_2hatena = s.find("????")) != string::npos) {
      s[position_2hatena] = 'P';
      s[position_2hatena + 1] = 'D';
    }
    //    if((position_hatenaD = s.find("?D") ) != string::npos){
    //    	s[position_hatenaD] = 'P';
    //    }
    if ((position_hatena = s.find("?")) != string::npos) {
      s[position_hatena] = 'D';
    }
  }

  //  cout << s.find("??") << endl;

  cout << s;

  return 0;
}

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

int main() {
  string s;
  cin >> s;

  if (s.find("?") == string::npos) {
    cout << s;
    // cout << "? ga naiyo\n";
    return 0;
  }

  size_t position_Phatena = 0;
  size_t position_2hatena = 0;
  size_t position_hatenaD = 0;
  size_t position_hatena = 0;

  while (s.find("?") != string::npos) {
    //    if((position_Phatena = s.find("P?") ) != string::npos){
    //    	s[position_hatenaD+1] = 'D';
    //    }
    //  	if( (position_2hatena = s.find("??") ) != string::npos){
    //      s[position_2hatena] = 'P';
    //      s[position_2hatena+1] = 'D';
    //    }
    //    if((position_hatenaD = s.find("?D") ) != string::npos){
    //    	s[position_hatenaD] = 'P';
    //    }
    if ((position_hatena = s.find("?")) != string::npos) {
      s[position_hatena] = 'D';
    }
  }

  //  cout << s.find("??") << endl;

  cout << s;

  return 0;
}
Problem p02664 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;

char arr[200000 + 10];

int main() {
  scanf("%s", arr);
  for (int i = 0; i < strlen(arr); i++) {
    if (arr[i] != '?')
      printf("%c", arr[i]);
    else
      printf("D");
  }
  printf("\n");
  return 0;
}

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

char arr[200000 + 10];

int main() {
  scanf("%s", arr);
  int len = strlen(arr);
  for (int i = 0; i < len; i++) {
    if (arr[i] != '?')
      printf("%c", arr[i]);
    else
      printf("D");
  }
  printf("\n");
  return 0;
}
Problem p02664 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <iostream>
#define mod 1000000007
#define int long long
#define pb(x) push_back(x)
#define gcd(a, b) __gcd(a, b)
#define all(v) v.begin(), v.end()
#define lcm(a, b) (a * b) / gcd(a, b)
#define bits(x) __builtin_popcountll(x)
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
using namespace std;
int32_t main() {
  fast;
#ifndef ONLINE_JUDGE
  freopen("goodluckin.txt", "r", stdin);
  freopen("goodluckout.txt", "w", stdout);
#endif
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i < s.size();) {
    if (s[i] == '?') {
      s[i] = 'D';
    }
  }
  cout << s;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#define mod 1000000007
#define int long long
#define pb(x) push_back(x)
#define gcd(a, b) __gcd(a, b)
#define all(v) v.begin(), v.end()
#define lcm(a, b) (a * b) / gcd(a, b)
#define bits(x) __builtin_popcountll(x)
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
using namespace std;
int32_t main() {
  fast;
#ifndef ONLINE_JUDGE
  freopen("goodluckin.txt", "r", stdin);
  freopen("goodluckout.txt", "w", stdout);
#endif
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?') {
      s[i] = 'D';
    }
  }
  cout << s;
}
Problem p02664 (C++)

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

const int M = 1e5 + 100;
int main() {
  char s[M];
  while (scanf("%s", s) == 1) {
    int n = strlen(s);
    for (int i = 0; i < n; i++)
      if (s[i] == '?')
        s[i] = 'D';
    printf("%s\n", s);
  }
}


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

const int M = 2e5 + 100;
int main() {
  char s[M];
  while (scanf("%s", s) == 1) {
    int n = strlen(s);
    for (int i = 0; i < n; i++)
      if (s[i] == '?')
        s[i] = 'D';
    printf("%s\n", s);
  }
}
Problem p02664 (C++)

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

int main() {
  string T;
  cin >> T;

  if (T.at(0) == '?') {
    if (T.at(1) != 'P')
      T.at(0) = 'P';
  }
  for (int i = 1; i < T.size() - 1; i++) {
    if (T.at(i) == '?') {
      if (T.at(i + 1) != 'P' && T.at(i - 1) == 'D') {
        T.at(i) = 'P';
      } else
        T.at(i) = 'D';
    }
  }
  if (T.at(T.size() - 1) == '?') {
    T.at(T.size() - 1) = 'D';
  }
  cout << T << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  string T;
  cin >> T;
  rep(i, T.size()) {
    if (T.at(i) == '?')
      T.at(i) = 'D';
  }
  cout << T << endl;

  return 0;
}
Problem p02664 (C++)

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

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

char s[N];
int n;

int main() {
  scanf("%s", s);
  n = strlen(s);
  int uk = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'D' || s[i] == '?')
      printf("D");
    else
      printf("P");
  }
  printf("\n");
  return 0;
}

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

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e6 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

char s[N];
int n;

int main() {
  scanf("%s", s);
  n = strlen(s);
  int uk = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'D' || s[i] == '?')
      printf("D");
    else
      printf("P");
  }
  printf("\n");
  return 0;
}
Problem p02664 (C++)

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

int main() {
  string T;
  cin >> T;
  if (T.at(0) == '?') {
    T.at(0) = 'D';
  }
  for (int i = 1; i < T.size(); i++) {
    if (T.at(i) == '?') {
      if ((T.at(i - 1)) == 'P') {
        T.at(i) = 'D';
      }
      if ((T.at(i - 1)) == 'D') {
        if (T.at(i + 1) == 'P') {
          T.at(i) = 'D';
        } else {
          T.at(i) = 'P';
        }
      }
    }
  }
  cout << T << endl;
}

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

int main() {
  string T;
  cin >> T;
  if (T.at(0) == '?') {
    T.at(0) = 'D';
  }
  if (T.at(T.size() - 1) == '?') {
    T.at(T.size() - 1) = 'D';
  }
  for (int i = 1; i < T.size() - 1; i++) {
    if (T.at(i) == '?') {
      if ((T.at(i - 1)) == 'P') {
        T.at(i) = 'D';
      }
      if ((T.at(i - 1)) == 'D') {
        if (T.at(i + 1) == 'P') {
          T.at(i) = 'D';
        } else {
          T.at(i) = 'P';
        }
      }
    }
  }
  cout << T << endl;
}
Problem p02664 (C++)

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T> inline void chkmax(T &x, T y) {
  if (x < y)
    x = y;
}

template <typename T> inline void chkmin(T &x, T y) {
  if (x > y)
    x = y;
}

inline int read() {
#define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48)
    c = nc;
  while (c > 47)
    x = x * 10 + (c ^ 48), c = nc;
  return x;
#undef nc
}

typedef long long ll;
const int maxn = 1e5 + 10;
char str[maxn];

void solve() {
  scanf("%s", str + 1);
  int n = strlen(str + 1);
  int ans = 0;
  rep(i, 1, n) {
    if (str[i] == 'P') {
      putchar('P');
      ans += i < n && str[i + 1] != 'P';
    } else {
      putchar('D');
      ans++;
    }
  }
  //  cout << ans<<endl;
}

int main() {
  //  int T = read();
  //  while (T--) solve();
  solve();
  return 0;
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T> inline void chkmax(T &x, T y) {
  if (x < y)
    x = y;
}

template <typename T> inline void chkmin(T &x, T y) {
  if (x > y)
    x = y;
}

inline int read() {
#define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48)
    c = nc;
  while (c > 47)
    x = x * 10 + (c ^ 48), c = nc;
  return x;
#undef nc
}

typedef long long ll;
const int maxn = 1e6 + 10;
char str[maxn];

void solve() {
  scanf("%s", str + 1);
  int n = strlen(str + 1);
  int ans = 0;
  rep(i, 1, n) {
    if (str[i] == 'P') {
      putchar('P');
      ans += i < n && str[i + 1] != 'P';
    } else {
      putchar('D');
      ans++;
    }
  }
  //  cout << ans<<endl;
}

int main() {
  //  int T = read();
  //  while (T--) solve();
  solve();
  return 0;
}
Problem p02664 (C++)

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

int main() {
  string t;
  cin >> t;
  for (int i = 0; i < t.size(); i++) {
    if (t.at(i) == '?') {
      if (i < t.size() - 1) {
        if (t.at(i + 1) == 'D') {
          t.at(i) = 'P';
        }
        if (i > 0) {
          if (t.at(i - 1) == 'P') {
            t.at(i) = 'D';
          } else {
            t.at(i) = 'P';
          }
        }
      } else {
        if (t.at(i - 1) == 'P') {
          t.at(i) = 'D';
        } else {
          t.at(i) = 'P';
        }
      }
    }
  }
  cout << t << endl;
}

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

int main() {
  string t;
  cin >> t;
  for (int i = 0; i < t.size(); i++) {
    if (t.at(i) == '?') {
      t.at(i) = 'D';
    }
  }
  cout << t << endl;
}
Problem p02664 (C++)

Buggy submission (status: Runtime Error):
#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "ctime"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main() {
  string t;
  cin >> t;
  int N = t.size();
  rep(0, i, N) {
    if (t.at(i) == '?') {

      if (i == 0) {
        if (t.at(i + 1) == 'D') {
          t.at(i) = 'P';
        } else {
          t.at(i) = 'D';
        }
      } else if (i == N - 1) {
        t.at(i) = 'D';
      } else if (t.at(i + 1) == 'D') {
        t.at(i) = 'P';
      } else {
        t.at(i) = 'D';
      }
    }
  }
  cout << t << endl;
}

Fixed submission:
#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "ctime"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main() {
  string t;
  cin >> t;
  int N = t.size();
  rep(0, i, N) {
    if (t.at(i) == '?') {
      t.at(i) = 'D';
    }
  }
  cout << t << endl;
}
Problem p02664 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <string.h>

char x[100010];
int main() {
  scanf("%s", x + 1);
  int a = strlen(x + 1);
  for (int i = 1; i <= a; i++)
    if (x[i] == '?')
      x[i] = 'D';
  for (int i = 1; i <= a; i++)
    printf("%c", x[i]);
}

Fixed submission:
#include <stdio.h>
#include <string.h>

char x[200010];
int main() {
  scanf("%s", x + 1);
  int a = strlen(x + 1);
  for (int i = 1; i <= a; i++)
    if (x[i] == '?')
      x[i] = 'D';
  for (int i = 1; i <= a; i++)
    printf("%c", x[i]);
}
Problem p02664 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string T;
  cin >> T;

  for (long long i = 0; i < 200001; i++) {
    if (T[i] == '?') {
      T[i] = 'D';
    }
  }

  cout << T << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string T;
  cin >> T;

  for (long long i = 0; i < T.length(); i++) {
    if (T[i] == '?') {
      T[i] = 'D';
    }
  }

  cout << T << endl;
}
Problem p02664 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <cstring>
using namespace std;
int main() {
  char T[20000];
  cin >> T;
  int i, n = strlen(T);
  for (i = 0; i < n; i++) {
    if (T[i] == '?') {
      T[i] = 'D';
    }
    cout << T[i];
  }
}


Fixed submission:
#include <bits/stdc++.h>
#include <cstring>
using namespace std;
int main() {
  char T[200000];
  cin >> T;
  int i, n = strlen(T);
  for (i = 0; i < n; i++) {
    if (T[i] == '?') {
      T[i] = 'D';
    }
    cout << T[i];
  }
}
Problem p02664 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int len = s.size();
  for (int i = 0; i < len;) {
    if (s[i] == '?') {
      s[i] = 'D';
    }
  }
  cout << s << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int len = s.size();
  for (int i = 0; i < len; i++) {
    if (s[i] == '?') {
      s[i] = 'D';
    }
  }
  cout << s << endl;
}
Problem p02664 (C++)

Buggy submission (status: Runtime Error):

#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i, a, b) for (int i = a; i <= b; i++)
#define ALL(a) a.begin(), a.end()
#define ALLN(a, n) (a, a + n)
#define MAX 10000007
#define MIN -10000007

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif

  int t;
  t = 1;
  //  cin>>t;
  while (t--) {
    string s;
    getline(cin, s);
    int n = s.length();
    REP(i, 0, n - 1) {
      if (s.at(i) == '?') {
        if (i + 1 <= n - 1 && s.at(i - 1) == 'D')
          s.at(i) = 'P';
        else if (i + 1 <= n - 1 && s.at(i - 1) == 'P')
          s.at(i) = 'D';
        else if (i - 1 >= 0 && s.at(i - 1) == 'P')
          s.at(i) = 'D';
        else
          s.at(i) = 'P';
      }
    }
    cout << s;
  }
  cerr << "Time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}


Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i, a, b) for (int i = a; i <= b; i++)
#define ALL(a) a.begin(), a.end()
#define ALLN(a, n) (a, a + n)
#define MAX 10000007
#define MIN -10000007

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif

  int t;
  t = 1;
  //  cin>>t;
  while (t--) {
    string s;
    getline(cin, s);
    int n = s.length();
    REP(i, 0, n - 1) {
      if (s.at(i) == '?') {

        s.at(i) = 'D';
      }
    }
    cout << s;
  }
  cerr << "Time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}
Problem p02664 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int find(string str, string word) {
  int count = 0;
  for (string::size_type pos = 0; (pos = str.find(word, pos)) != string::npos;
       pos += word.size()) {
    ++count;
  }
  return count;
}

int main() {
  string t;
  cin >> t;
  int q = count(t.cbegin(), t.cend(), '?');
  rep(i, q) {
    string t1 = t;
    string t2 = t;
    int p = t.rfind("?");
    t1[p] = 'P';
    t2[p] = 'D';
    int totald1 = count(t1.cbegin(), t1.cend(), 'D');
    totald1 += find(t1, "PD");
    int totald2 = count(t2.cbegin(), t2.cend(), 'D');
    totald2 += find(t2, "PD");
    if (totald1 >= totald2) {
      t = t1;
    } else {
      t = t2;
    }
  }
  cout << t << endl;
  return 0;
}


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

int find(string str, string word) {
  int count = 0;
  for (string::size_type pos = 0; (pos = str.find(word, pos)) != string::npos;
       pos += word.size()) {
    ++count;
  }
  return count;
}

int main() {
  string t;
  cin >> t;
  for (int i = 0; i < t.length(); i++)
    if (t[i] == '?')
      t[i] = 'D';
  cout << t << endl;
  return 0;
}
Problem p02665 (C++)

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

typedef long long LL;
const int MN = 200005;

int N;
LL A[MN], B[MN], C[MN];

int main() {
  scanf("%d", &N);
  for (int i = 0; i <= N; ++i)
    scanf("%lld", &A[i]);
  if (!N)
    return puts(A[0] == 1 ? "1" : "-1");
  for (int i = N; i >= 0; --i)
    B[i] = B[i + 1] + A[i];
  C[0] = 1 - A[0];
  for (int i = 1; i <= N; ++i) {
    C[i] = 2 * C[i - 1] - A[i];
    if (C[i] < 0 || C[i] + A[i] == 0)
      return puts("-1"), 0;
    if (C[i] + A[i] > B[i])
      C[i] = B[i] - A[i];
  }
  LL Ans = 0;
  for (int i = 0; i <= N; ++i)
    Ans += A[i] + C[i];
  printf("%lld\n", Ans);
  return 0;
}

Fixed submission:
#include <cstdio>

typedef long long LL;
const int MN = 200005;

int N;
LL A[MN], B[MN], C[MN];

int main() {
  scanf("%d", &N);
  for (int i = 0; i <= N; ++i)
    scanf("%lld", &A[i]);
  if (!N)
    return puts(A[0] == 1 ? "1" : "-1"), 0;
  for (int i = N; i >= 0; --i)
    B[i] = B[i + 1] + A[i];
  C[0] = 1 - A[0];
  for (int i = 1; i <= N; ++i) {
    C[i] = 2 * C[i - 1] - A[i];
    if (C[i] < 0 || C[i] + A[i] == 0)
      return puts("-1"), 0;
    if (C[i] + A[i] > B[i])
      C[i] = B[i] - A[i];
  }
  LL Ans = 0;
  for (int i = 0; i <= N; ++i)
    Ans += A[i] + C[i];
  printf("%lld\n", Ans);
  return 0;
}
Problem p02665 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
#define maxn 100005
using namespace std;

#define INF 1000000000000000LL
ll A[maxn];
ll lim[maxn];

int main() {
  int n;
  cin >> n;
  rep(i, n + 1) cin >> A[i];
  lim[0] = 1;
  for (int i = 1; i < n + 1; i++) {
    ll m = (lim[i - 1] - A[i - 1]) * 2LL;
    if (m < 0) {
      cout << -1 << endl;
      return 0;
    }
    lim[i] = min(INF, m);
  }

  if (lim[n] < A[n]) {
    cout << -1 << endl;
    return 0;
  }
  ll ret = A[n], now = A[n];
  for (int i = n - 1; i >= 0; i++) {
    now += A[i];
    now = min(now, lim[i]);
    ret += now;
  }
  cout << ret << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
#define maxn 100005
using namespace std;

#define INF 1000000000000000LL
ll A[maxn];
ll lim[maxn];

int main() {
  int n;
  cin >> n;
  rep(i, n + 1) cin >> A[i];
  lim[0] = 1;
  for (int i = 1; i < n + 1; i++) {
    ll m = (lim[i - 1] - A[i - 1]) * 2LL;
    if (m < 0) {
      cout << -1 << endl;
      return 0;
    }
    lim[i] = min(INF, m);
  }

  if (lim[n] < A[n]) {
    cout << -1 << endl;
    return 0;
  }
  ll ret = A[n], now = A[n];
  for (int i = n - 1; i >= 0; i--) {
    now += A[i];
    now = min(now, lim[i]);
    ret += now;
  }
  cout << ret << endl;
}