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

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define fi first
#define se second

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

ll n;
ll a[100100];

ll sq(ll num) { return num * num; }

ll mod_pow(ll num, ll k) {
  if (k == 1)
    return num;
  ll res = sq(mod_pow(num, k / 2));
  res %= INF;
  if (k % 2 == 1) {
    res *= num;
    res %= INF;
  }
  return res;
}

int main() {
  cin >> n;
  REP(i, n) cin >> a[i];
  sort(a, a + n);
  bool f = 1;
  int cnt;
  if (n % 2 == 0)
    cnt = 1;
  else
    cnt = 0;
  REP(i, n) {
    if (cnt != a[i])
      f = 0;
    if (n % 2 == 0) {
      if (i % 2 == 1)
        cnt += 2;
    } else {
      if (i % 2 == 0)
        cnt += 2;
    }
  }
  ll ans = mod_pow(2, n / 2);
  if (f)
    cout << ans << endl;
  else
    cout << 0 << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define fi first
#define se second

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

ll n;
ll a[100100];

ll sq(ll num) { return num * num; }

ll mod_pow(ll num, ll k) {
  if (k == 0)
    return 1;
  if (k == 1)
    return num;
  ll res = sq(mod_pow(num, k / 2));
  res %= INF;
  if (k % 2 == 1) {
    res *= num;
    res %= INF;
  }
  return res;
}

int main() {
  cin >> n;
  REP(i, n) cin >> a[i];
  sort(a, a + n);
  bool f = 1;
  int cnt;
  if (n % 2 == 0)
    cnt = 1;
  else
    cnt = 0;
  REP(i, n) {
    if (cnt != a[i])
      f = 0;
    if (n % 2 == 0) {
      if (i % 2 == 1)
        cnt += 2;
    } else {
      if (i % 2 == 0)
        cnt += 2;
    }
  }
  ll ans = mod_pow(2, n / 2);
  if (f)
    cout << ans << endl;
  else
    cout << 0 << endl;
}
Problem p03848 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#define MOD (ll)(1e9 + 7)
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> mp, tmp;
  rep(i, n) { mp[abs((n - 1 - i) - i)]++; }
  tmp = mp;
  int a[n];
  rep(i, n) {
    cin >> a[i];
    if (tmp[a[i]] == 0) {
      cout << 0 << endl;
      return 1;
    }
    tmp[a[i]]--;
  }
  ll ans = 1;
  rep(i, n / 2) {
    ans *= 2;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#define MOD (ll)(1e9 + 7)
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> mp, tmp;
  rep(i, n) { mp[abs((n - 1 - i) - i)]++; }
  tmp = mp;
  int a[n];
  rep(i, n) {
    cin >> a[i];
    if (tmp[a[i]] == 0) {
      cout << 0 << endl;
      return 0;
    }
    tmp[a[i]]--;
  }
  ll ans = 1;
  rep(i, n / 2) {
    ans *= 2;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}
Problem p03848 (C++)

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)

typedef long long ll;
#define INF 1e9

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

int N;

int main() {
  cin >> N;
  bool isOdd = N % 2;
  vector<int> A(N);
  vector<int> sum(N / 2, 0);
  REP(i, N) {
    cin >> A[i];
    if (isOdd && A[i] % 2) {
      cout << 0 << endl;
      return 0;
    } else if (!isOdd && !(A[i] % 2)) {
      cout << 0 << endl;
      return 0;
    }
    if (isOdd) {
      if ((N - 1) < A[i]) {
        cout << 0 << endl;
        return 0;
      }
      sum[A[i] / 2]++;

    } else if (!isOdd) {
      if (N - 1 < A[i]) {
        cout << 0 << endl;
        return 0;
      }
      sum[(A[i] - 1) / 2]++;
    }
  }
  REP(i, N / 2) {
    if (isOdd) {
      if (i == 0) {
        if (sum[i] != 1) {
          cout << 0 << endl;
          return 0;
        }
      } else {
        if (sum[i] != 2) {
          cout << 0 << endl;
          return 0;
        }
      }
    } else {
      if (sum[i] != 2) {
        cout << 0 << endl;
        return 0;
      }
    }
  }

  ll ans = 1;
  REP(i, N / 2) {
    ans *= 2;
    ans = ans % (ll)(1e9 + 7);
  }

  cout << ans << endl;
  return 0;
}

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)

typedef long long ll;
#define INF 1e9

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

int N;

int main() {
  cin >> N;
  if (N == 1) {
    int x;
    cin >> x;
    if (x == 0) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
    return 0;
  }
  bool isOdd = N % 2;
  vector<int> A(N);
  vector<int> sum(N / 2, 0);
  REP(i, N) {
    cin >> A[i];
    if (isOdd && A[i] % 2) {
      cout << 0 << endl;
      return 0;
    } else if (!isOdd && !(A[i] % 2)) {
      cout << 0 << endl;
      return 0;
    }
    if (isOdd) {
      if ((N - 1) < A[i]) {
        cout << 0 << endl;
        return 0;
      }
      sum[A[i] / 2]++;

    } else if (!isOdd) {
      if (N - 1 < A[i]) {
        cout << 0 << endl;
        return 0;
      }
      sum[(A[i] - 1) / 2]++;
    }
  }
  REP(i, N / 2) {
    if (isOdd) {
      if (i == 0) {
        if (sum[i] != 1) {
          cout << 0 << endl;
          return 0;
        }
      } else {
        if (sum[i] != 2) {
          cout << 0 << endl;
          return 0;
        }
      }
    } else {
      if (sum[i] != 2) {
        cout << 0 << endl;
        return 0;
      }
    }
  }

  ll ans = 1;
  REP(i, N / 2) {
    ans *= 2;
    ans = ans % (ll)(1e9 + 7);
  }

  cout << ans << endl;
  return 0;
}
Problem p03848 (C++)

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

// long long MOD = pow(10, 9) + 7;
#define MOD 1000000007

int main() {
  int N;
  scanf("%d", &N);
  vector<int> A(N + 1), B(N / 2);
  for (int i = 0; i < B.size(); i++) {
    B[i] = 0;
  }
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
    if (N % 2 == 0 && A[i] % 2 == 0) {
      printf("0\n");
      return 0;
    }
    if (N % 2 == 1 && A[i] % 2 == 1) {
      printf("0\n");
      return 0;
    }
    B[A[i] / 2]++;
  }
  if (N % 2 == 1) {
    for (int i = 0; i < B.size(); i++) {
      if (i == 0 && B[i] != 1) {
        printf("0\n");
        return 0;
      }
      if (i != 0 && B[i] != 2) {
        printf("0\n");
        return 0;
      }
    }
  } else {
    for (int i = 0; i < B.size(); i++) {
      if (B[i] != 2) {
        printf("0\n");
        return 0;
      }
    }
  }
  long long ans = 1;
  for (int i = 0; i < N / 2; i++) {
    ans *= 2;
    ans %= MOD;
  }
  printf("%lld\n", ans);
}

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

// long long MOD = pow(10, 9) + 7;
#define MOD 1000000007

int main() {
  int N;
  scanf("%d", &N);
  if (N == 1) {
    int A;
    scanf("%d", &A);
    if (A == 0) {
      printf("1\n");
    } else {
      printf("0\n");
    }
    return 0;
  }
  vector<int> A(N + 1), B(N / 2);
  for (int i = 0; i < B.size(); i++) {
    B[i] = 0;
  }
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
    if (N % 2 == 0 && A[i] % 2 == 0) {
      printf("0\n");
      return 0;
    }
    if (N % 2 == 1 && A[i] % 2 == 1) {
      printf("0\n");
      return 0;
    }
    B[A[i] / 2]++;
  }
  if (N % 2 == 1) {
    for (int i = 0; i < B.size(); i++) {
      if (i == 0 && B[i] != 1) {
        printf("0\n");
        return 0;
      }
      if (i != 0 && B[i] != 2) {
        printf("0\n");
        return 0;
      }
    }
  } else {
    for (int i = 0; i < B.size(); i++) {
      if (B[i] != 2) {
        printf("0\n");
        return 0;
      }
    }
  }
  long long ans = 1;
  for (int i = 0; i < N / 2; i++) {
    ans *= 2;
    ans %= MOD;
  }
  printf("%lld\n", ans);
}
Problem p03848 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  sort(A.begin(), A.end());
  int P = N / 2;
  long S = 1;
  for (int i = 0; i < P; i++) {
    S *= 2;
    S %= 1000000007;
  }
  if (0 == N % 2) {
    if (1 != A.at(0))
      S = 0;
    if (1 != A.at(1))
      S = 0;
  } else {
    if (0 != A.at(0))
      S = 0;
    if (2 != A.at(1))
      S = 0;
  }
  if (0 != S) {
    for (int i = 2; i < N; i++)
      if (2 != A.at(i) - A.at(i - 2)) {
        S = 0;
        break;
      }
  }
  cout << S << endl;
  return 0;
};


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  sort(A.begin(), A.end());
  int P = N / 2;
  long S = 1;
  if (1 == N) {
    if (0 == A.at(0))
      cout << 1 << endl;
    else
      cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < P; i++) {
    S *= 2;
    S %= 1000000007;
  }
  if (0 == N % 2) {
    if (1 != A.at(0))
      S = 0;
    if (1 != A.at(1))
      S = 0;
  } else {
    if (0 != A.at(0))
      S = 0;
    if (2 != A.at(1))
      S = 0;
  }
  if (0 != S) {
    for (int i = 2; i < N; i++)
      if (2 != A.at(i) - A.at(i - 2)) {
        S = 0;
        break;
      }
  }
  cout << S << endl;
  return 0;
};
Problem p03849 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
  return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v) {
  cout << "{";
  for (int i = 0; i < v.size(); i++) {
    if (i)
      cout << ", ";
    cout << v[i];
  }
  return cout << "}";
}

int main() {
  const int MOD = 1e9 + 7;
  ll n;
  cin >> n;
  map<ll, ll> store;
  function<ll(int)> eval = [&](ll x) -> ll {
    if (store.find(x) != store.end())
      return store[x];
    ll ret;
    if (x == 1) {
      ret = 2;
    } else if (x == 2) {
      ret = 4;
    } else if (x == 3) {
      ret = 5;
    } else {
      if (x % 2 == 0) {
        ret = (2 * eval(x / 2 - 1) + eval(x / 2)) % MOD;
      } else {
        ret = (eval(x / 2 - 1) + 2 * eval(x / 2)) % MOD;
      }
    }
    store[x] = ret;
    return ret;
  };
  cout << eval(n) << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
  return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v) {
  cout << "{";
  for (int i = 0; i < v.size(); i++) {
    if (i)
      cout << ", ";
    cout << v[i];
  }
  return cout << "}";
}

int main() {
  const int MOD = 1e9 + 7;
  ll n;
  cin >> n;
  map<ll, ll> store;
  function<ll(ll)> eval = [&](ll x) -> ll {
    if (store.find(x) != store.end())
      return store[x];
    ll ret;
    if (x == 1) {
      ret = 2;
    } else if (x == 2) {
      ret = 4;
    } else if (x == 3) {
      ret = 5;
    } else {
      if (x % 2 == 0) {
        ret = (2 * eval(x / 2 - 1) + eval(x / 2)) % MOD;
      } else {
        ret = (eval(x / 2 - 1) + 2 * eval(x / 2)) % MOD;
      }
    }
    store[x] = ret;
    return ret;
  };
  cout << eval(n) << '\n';
  return 0;
}
Problem p03849 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
const long long mod = 1e9 + 7;
map<long long, long long> dp;
#define bug cout << 88888888 << endl;
#define debug(x) cout << #x " = " << x << endl;
long long Dp(int x) {
  if (dp[x])
    return dp[x];
  else {
    return dp[x] = ((Dp(x / 2) + Dp((x - 1) / 2) + Dp((x - 2) / 2))) % mod;
  }
}
int main() {
  dp[0] = 1;
  dp[1] = 2;
  long long n;
  cin >> n;
  cout << Dp(n);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
const long long mod = 1e9 + 7;
map<long long, long long> dp;
#define bug cout << 88888888 << endl;
#define debug(x) cout << #x " = " << x << endl;
long long Dp(long long x) {
  if (dp[x])
    return dp[x];
  else {
    return dp[x] = ((Dp(x / 2) + Dp((x - 1) / 2) + Dp((x - 2) / 2))) % mod;
  }
}
int main() {
  dp[0] = 1;
  dp[1] = 2;
  long long n;
  cin >> n;
  cout << Dp(n);
  return 0;
}
Problem p03850 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define lf double
#define E complex<lf>
#define eps 1e-9
#define inf 0x7fffffff
#define l(x) (x << 1)
#define r(x) (x << 1 | 1)
#define pa pair<int, int>
#define pb push_back
#define mod
#define FIO "problem"
#define N 100010
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9')
    f = (c == '-') ? -1 : 1, c = getchar();
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  return x * f;
}
inline void fre() {
  freopen(FIO ".in", "r", stdin);
  freopen(FIO ".out", "w", stdout);
}
int n;
int num[N], opt[N];
ll sum;
int sta[N], top = 0;
int main() {
  fre();
  n = read();
  for (int i = 1; i < n; i++) {
    num[i] = read(), sum += num[i];
    char s[5];
    scanf("%s", s);
    if (s[0] == '-')
      opt[i] = -1;
    else
      opt[i] = 1;
  }
  num[n] = read(), sum += num[n];
  ll ans = -inf, hhh = 0;
  for (int i = 1; i < n; i++)
    if (opt[i] == -1) {
      ll tmp = sum;
      ll sum2 = num[i + 1];
      for (int j = i + 1; j < n; j++) {
        if (opt[j] == 1)
          sum2 += num[j + 1];
        else
          break;
      }
      tmp -= 2 * (sum2 + hhh);
      ans = max(ans, tmp);
      hhh += num[i + 1];
    }
  ans = max(ans, sum - 2 * hhh);
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define lf double
#define E complex<lf>
#define eps 1e-9
#define inf 0x7fffffff
#define l(x) (x << 1)
#define r(x) (x << 1 | 1)
#define pa pair<int, int>
#define pb push_back
#define mod
#define FIO "problem"
#define N 100010
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9')
    f = (c == '-') ? -1 : 1, c = getchar();
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  return x * f;
}
inline void fre() {
  freopen(FIO ".in", "r", stdin);
  freopen(FIO ".out", "w", stdout);
}
int n;
int num[N], opt[N];
ll sum;
int sta[N], top = 0;
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    num[i] = read(), sum += num[i];
    char s[5];
    scanf("%s", s);
    if (s[0] == '-')
      opt[i] = -1;
    else
      opt[i] = 1;
  }
  num[n] = read(), sum += num[n];
  ll ans = -inf, hhh = 0;
  for (int i = 1; i < n; i++)
    if (opt[i] == -1) {
      ll tmp = sum;
      ll sum2 = num[i + 1];
      for (int j = i + 1; j < n; j++) {
        if (opt[j] == 1)
          sum2 += num[j + 1];
        else
          break;
      }
      tmp -= 2 * (sum2 + hhh);
      ans = max(ans, tmp);
      hhh += num[i + 1];
    }
  ans = max(ans, sum - 2 * hhh);
  cout << ans << endl;
}
Problem p03850 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
const ll mod = 1000000007;
const ll INF = mod * mod;

int main() {
  ll n;
  ll a[100010];
  bool m[100010];
  ll dp[10010][3];

  cin >> n;
  m[0] = 0;
  cin >> a[0];
  for (int i = 1; i < n; i++) {
    char c;
    cin >> c;
    if (c == '+')
      m[i] = false;
    else
      m[i] = true;
    cin >> a[i];
  }
  dp[0][0] = a[0];
  dp[0][1] = -INF;
  dp[0][2] = -INF;
  for (int i = 1; i < n; i++) {
    if (m[i]) {
      dp[i][0] = -INF;
      dp[i][1] = -a[i] + max(dp[i - 1][1], dp[i - 1][0]);
      if (dp[i - 1][1] != -INF || dp[i - 1][2] != -INF) {
        dp[i][2] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
      } else {
        dp[i][2] = -INF;
      }
    } else {
      dp[i][0] = a[i] + max(dp[i - 1][0], dp[i - 1][1]);
      dp[i][1] = -a[i] + dp[i - 1][1];
      if (dp[i - 1][2] != -INF) {
        dp[i][2] = a[i] + dp[i - 1][2];
      } else {
        dp[i][2] = -INF;
      }
    }
  }
  ll ans = dp[n - 1][2];
  ans = max(ans, dp[n - 1][1]);
  ans = max(ans, dp[n - 1][0]);
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
const ll mod = 1000000007;
const ll INF = mod * mod;

int main() {
  ll n;
  ll a[100010];
  bool m[100010];
  ll dp[100010][3];

  cin >> n;
  m[0] = 0;
  cin >> a[0];
  for (int i = 1; i < n; i++) {
    char c;
    cin >> c;
    if (c == '+')
      m[i] = false;
    else
      m[i] = true;
    cin >> a[i];
  }
  dp[0][0] = a[0];
  dp[0][1] = -INF;
  dp[0][2] = -INF;
  for (int i = 1; i < n; i++) {
    if (m[i]) {
      dp[i][0] = -INF;
      dp[i][1] = -a[i] + max(dp[i - 1][1], dp[i - 1][0]);
      if (dp[i - 1][1] != -INF || dp[i - 1][2] != -INF) {
        dp[i][2] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
      } else {
        dp[i][2] = -INF;
      }
    } else {
      dp[i][0] = a[i] + max(dp[i - 1][0], dp[i - 1][1]);
      dp[i][1] = -a[i] + dp[i - 1][1];
      if (dp[i - 1][2] != -INF) {
        dp[i][2] = a[i] + dp[i - 1][2];
      } else {
        dp[i][2] = -INF;
      }
    }
  }
  ll ans = dp[n - 1][2];
  ans = max(ans, dp[n - 1][1]);
  ans = max(ans, dp[n - 1][0]);
  cout << ans << endl;
  return 0;
}
Problem p03850 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#define llint long long
#define sgn(x) (((x) % 2) ? -1 : 1)
#define inf 100000000000000000

using namespace std;

llint N;
llint A[100005];
char op[100005];
llint dp[100005][10];

int main(void) {
  cin >> N;
  N--;

  cin >> A[0];
  for (int i = 1; i <= N; i++)
    cin >> op[i] >> A[i];

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      dp[i][j] = -inf;
    }
  }

  dp[0][0] = A[0];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 2; j++) {
      if (dp[i][j] == -inf)
        continue;
      if (op[i + 1] == '+') {
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + sgn(j) * A[i + 1]);
        if (j > 0)
          dp[i + 1][j - 1] =
              max(dp[i + 1][j - 1], dp[i][j] + sgn(j) * A[i + 1]);
      } else {
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + sgn(j + 1) * A[i + 1]);
        dp[i + 1][j + 1] =
            max(dp[i + 1][j + 1], dp[i][j] + sgn(j + 1) * A[i + 1]);
        if (j > 0)
          dp[i + 1][j - 1] =
              max(dp[i + 1][j - 1], dp[i][j] + sgn(j + 1) * A[i + 1]);
      }
    }
  }

  /*for(int i = 0; i <= N; i++){
          for(int j = 0; j <= N; j++){
                  if(dp[i][j] == -inf) cout << "-inf" << " ";
                  else cout << dp[i][j] << " ";
          }
          cout << endl;
  }*/

  cout << dp[N][0] << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#define llint long long
#define sgn(x) (((x) % 2) ? -1 : 1)
#define inf 100000000000000000

using namespace std;

llint N;
llint A[100005];
char op[100005];
llint dp[100005][10];

int main(void) {
  cin >> N;
  N--;

  cin >> A[0];
  for (int i = 1; i <= N; i++)
    cin >> op[i] >> A[i];

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= 2; j++) {
      dp[i][j] = -inf;
    }
  }

  dp[0][0] = A[0];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 2; j++) {
      if (dp[i][j] == -inf)
        continue;
      if (op[i + 1] == '+') {
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + sgn(j) * A[i + 1]);
        if (j > 0)
          dp[i + 1][j - 1] =
              max(dp[i + 1][j - 1], dp[i][j] + sgn(j) * A[i + 1]);
      } else {
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + sgn(j + 1) * A[i + 1]);
        dp[i + 1][j + 1] =
            max(dp[i + 1][j + 1], dp[i][j] + sgn(j + 1) * A[i + 1]);
        if (j > 0)
          dp[i + 1][j - 1] =
              max(dp[i + 1][j - 1], dp[i][j] + sgn(j + 1) * A[i + 1]);
      }
    }
  }

  /*for(int i = 0; i <= N; i++){
          for(int j = 0; j <= N; j++){
                  if(dp[i][j] == -inf) cout << "-inf" << " ";
                  else cout << dp[i][j] << " ";
          }
          cout << endl;
  }*/

  cout << dp[N][0] << endl;
  return 0;
}
Problem p03850 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
int n, k;
ll a[115000];
char c[115000];
ll dp[115000][5];

int main() {
  cin >> n;
  cin >> a[0];
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++)
      dp[i][j] = -1e15;
  dp[0][0] = a[0];
  for (int i = 1; i < n; i++) {
    cin >> c[i] >> a[i];
    if (c[i] == '+') {
      for (int k = 0; k < 5; k++) {
        for (int nk = 0; nk <= k; nk++) {
          dp[i][nk] =
              max(dp[i][nk], dp[i - 1][k] + (k % 2 == 0 ? a[i] : -a[i]));
        }
      }
    } else {
      for (int k = 0; k < 4; k++) {
        for (int nk = 0; nk <= k + 1; nk++) {
          dp[i][nk] =
              max(dp[i][nk], dp[i - 1][k] + (k % 2 == 0 ? -a[i] : a[i]));
        }
      }
    }
  }
  cout << dp[n - 1][0] << endl;
}


Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
int n, k;
ll a[115000];
char c[115000];
ll dp[115000][5];

int main() {
  cin >> n;
  cin >> a[0];
  for (int i = 0; i <= n; i++)
    for (int j = 0; j < 5; j++)
      dp[i][j] = -1e15;
  dp[0][0] = a[0];
  for (int i = 1; i < n; i++) {
    cin >> c[i] >> a[i];
    if (c[i] == '+') {
      for (int k = 0; k < 5; k++) {
        for (int nk = 0; nk <= k; nk++) {
          dp[i][nk] =
              max(dp[i][nk], dp[i - 1][k] + (k % 2 == 0 ? a[i] : -a[i]));
        }
      }
    } else {
      for (int k = 0; k < 4; k++) {
        for (int nk = 0; nk <= k + 1; nk++) {
          dp[i][nk] =
              max(dp[i][nk], dp[i - 1][k] + (k % 2 == 0 ? -a[i] : a[i]));
        }
      }
    }
  }
  cout << dp[n - 1][0] << endl;
}
Problem p03850 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define lor(a, b, c) for (register int a = b; a <= c; ++a)
#define ror(a, b, c) for (register int a = c; a >= b; --a)
typedef long long ll;

const int N = 1e5 + 5;
int n, nxt[N];
ll a[N], sum[N], abssum[N], ans;

template <typename T> inline T read() {
  char tmp = getchar();
  T sum = 0;
  bool flag = false;
  while (tmp < '0' || tmp > '9') {
    if (tmp == '-')
      flag = true;
    tmp = getchar();
  }
  while (tmp >= '0' && tmp <= '9') {
    sum = (sum << 1) + (sum << 3) + tmp - '0';
    tmp = getchar();
  }
  return flag ? -sum : sum;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("test.in", "r", stdin);
#endif

  n = read<int>();
  lor(i, 1, n) a[i] = read<ll>(), sum[i] = sum[i - 1] + a[i],
               abssum[i] = abssum[i - 1] + abs(a[i]);
  ans = sum[n];
  nxt[n + 1] = n + 1;
  sum[n + 1] = sum[n];
  abssum[n + 1] = abssum[n];
  ror(i, 1, n) {
    if (a[i + 1] < 0)
      nxt[i] = i + 1;
    else
      nxt[i] = nxt[i + 1];
  }
  lor(i, 1, n) if (a[i] < 0) {
    ans = max(ans, sum[i - 1] + (abssum[n] - abssum[nxt[i] - 1]) -
                       (abssum[nxt[i] - 1] - abssum[i - 1]));
  }
  printf("%lld\n", ans);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define lor(a, b, c) for (register int a = b; a <= c; ++a)
#define ror(a, b, c) for (register int a = c; a >= b; --a)
typedef long long ll;

const int N = 1e5 + 5;
int n, nxt[N];
ll a[N], sum[N], abssum[N], ans;

template <typename T> inline T read() {
  char tmp = getchar();
  T sum = 0;
  bool flag = false;
  while (tmp < '0' || tmp > '9') {
    if (tmp == '-')
      flag = true;
    tmp = getchar();
  }
  while (tmp >= '0' && tmp <= '9') {
    sum = (sum << 1) + (sum << 3) + tmp - '0';
    tmp = getchar();
  }
  return flag ? -sum : sum;
}

int main() {
  n = read<int>();
  lor(i, 1, n) a[i] = read<ll>(), sum[i] = sum[i - 1] + a[i],
               abssum[i] = abssum[i - 1] + abs(a[i]);
  ans = sum[n];
  nxt[n + 1] = n + 1;
  sum[n + 1] = sum[n];
  abssum[n + 1] = abssum[n];
  ror(i, 1, n) {
    if (a[i + 1] < 0)
      nxt[i] = i + 1;
    else
      nxt[i] = nxt[i + 1];
  }
  lor(i, 1, n) if (a[i] < 0) {
    ans = max(ans, sum[i - 1] + (abssum[n] - abssum[nxt[i] - 1]) -
                       (abssum[nxt[i] - 1] - abssum[i - 1]));
  }
  printf("%lld\n", ans);

  return 0;
}
Problem p03850 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
int N, a[100001], sign[100001], L;
long long f[100001];
int main() {
  scanf("%d%d", &N, a + 1);
  sign[1] = 1;
  for (int i = 2; i <= N; i++) {
    static char in[3];
    scanf("%s", in);
    sign[i] = in[0] == '+' ? 1 : -1;
    scanf("%d", a + i);
    a[i] *= sign[i];
  }
  int L = 0;
  f[0] = 0;
  for (int i = 1; i <= N; i++) {
    if (sign[i] == 1) {
      for (int j = 0; j <= L; j++)
        f[j] += j & 1 ? -a[i] : a[i];
      for (int j = L - 1; j >= 0; j--)
        f[j] = std::max(f[j], f[j + 1]);
    } else {
      for (int j = 0; j <= L; j++)
        f[j] += j & 1 ? -a[i] : a[i];
      f[++L] = -1LL << 60;
      for (int j = L; j; j--)
        f[j] = std::max(f[j], f[j - 1]);
      for (int j = L - 1; j >= 0; j--)
        f[j] = std::max(f[j], f[j + 1]);
    }
  }
  printf("%lld\n", *std::max_element(f, f + L + 1));
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
int N, a[100001], sign[100001], L;
long long f[100001];
int main() {
  scanf("%d%d", &N, a + 1);
  sign[1] = 1;
  for (int i = 2; i <= N; i++) {
    static char in[3];
    scanf("%s", in);
    sign[i] = in[0] == '+' ? 1 : -1;
    scanf("%d", a + i);
    a[i] *= sign[i];
  }
  int L = 0;
  f[0] = 0;
  for (int i = 1; i <= N; i++) {
    if (sign[i] == 1) {
      for (int j = 0; j <= L; j++)
        f[j] += j & 1 ? -a[i] : a[i];
      for (int j = L - 1; j >= 0; j--)
        f[j] = std::max(f[j], f[j + 1]);
    } else {
      for (int j = 0; j <= L; j++)
        f[j] += j & 1 ? -a[i] : a[i];
      f[++L] = -1LL << 60;
      for (int j = L; j; j--)
        f[j] = std::max(f[j], f[j - 1]);
      for (int j = L - 1; j >= 0; j--)
        f[j] = std::max(f[j], f[j + 1]);
    }
    while (L > 10)
      L -= 2;
  }
  printf("%lld\n", *std::max_element(f, f + L + 1));
  return 0;
}
Problem p03852 (Python)

Buggy submission (status: Runtime Error):
def main():
    h, _ = map(int, input().split())
    c = [input() for _ in range(h)]
    for cn in c:
        print(cn)
        print(cn)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    print("vowel" if input() in "aeiou" else "consonant")


if __name__ == "__main__":
    main()
Problem p03852 (C++)

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

int main() {
  char c;
  cin >> c;
  string s = "aiueo";
  for (int i = 0;; i++) {
    if (c == s.at(i)) {
      cout << "vowel";
      break;
    } else {
      cout << "consonant";
    }
    cout << endl;
  }
}

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

int main() {
  char c;
  cin >> c;
  const string vowel = "aeiou";
  vowel.find(c) == string::npos ? cout << "consonant" << endl
                                : cout << "vowel" << endl;
}
Problem p03852 (C++)

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

int main() {
  char c;
  cin >> c;
  string vowel = "aeiuo";
  bool is_vowel = false;

  for (int i = 0; vowel.size(); i++) {
    if (c == vowel.at(i))
      is_vowel = true;
  }
  if (is_vowel)
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}


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

int main() {
  char c;
  cin >> c;
  string vowel = "aeiuo";
  if (vowel.find(c) != string::npos)
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}
Problem p03852 (Python)

Buggy submission (status: Runtime Error):
c = int(input())
print("vowel" if c in "aiueo" else "consonant")


Fixed submission:
c = input()
print("vowel" if c in "aiueo" else "consonant")
Problem p03853 (C++)

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

int main() {
  int h, w;
  cin >> h >> w;
  char img[h][w];
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> img[i][j];
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cout << img[i][j];
    }
    cout << endl;
    for (int j = 1; j <= w; j++) {
      cout << img[i][j];
    }
    cout << endl;
  }
}

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

int main() {
  int h, w;
  cin >> h >> w;
  char img[h + 10][w + 10];
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> img[i][j];
    }
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cout << img[i][j];
    }
    cout << endl;
    for (int j = 1; j <= w; j++) {
      cout << img[i][j];
    }
    cout << endl;
  }
}
Problem p03853 (Python)

Buggy submission (status: Runtime Error):
H, W = map(int, input().split())
for i in range(W):
    s = input()
    print(s)
    print(s)


Fixed submission:
H, W = map(int, input().split())
for i in range(H):
    s = input()
    print(s)
    print(s)
Problem p03853 (C++)

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

void b_tatenaga(void) {
  int h, w;
  char c[100][100];
  char out_c[100 * 2][100];
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> c[i][j];
    }
  }
  int h_pos = 0;
  int w_pos = 0;

  for (int i = 1; i <= h * 2; i++) {
    for (int j = 1; j <= w; j++) {
      h_pos = (i + 1) >> 1;
      w_pos = j;
      cout << c[h_pos][w_pos];
    }
    cout << endl;
  }
}

int main() {
  b_tatenaga();
  return 0;
}

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

void b_tatenaga(void) {
  int h, w;
  char c[110][110];
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> c[i][j];
    }
  }
  int h_pos = 0;
  int w_pos = 0;

  for (int i = 1; i <= h * 2; i++) {
    for (int j = 1; j <= w; j++) {
      h_pos = (i + 1) >> 1;
      w_pos = j;
      cout << c[h_pos][w_pos];
    }
    cout << endl;
  }
}

int main() {
  b_tatenaga();
  return 0;
}
Problem p03853 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  string s[2 * h];
  for (int i = 0; i < 2 * h; i++) {
    cin >> s[i];
    s[i + 1] = s[i];
    cout << s[i] << endl;
    cout << s[i + 1] << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  string s[2 * h];
  for (int i = 0; i < 2 * h; i += 2) {
    cin >> s[i];
    s[i + 1] = s[i];
    cout << s[i] << endl;
    cout << s[i + 1] << endl;
  }
}
Problem p03853 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
typedef long long ll;
using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  string C[100];
  for (int i = 1; i <= H; ++i)
    cin >> C[i];
  for (int i = 1; i <= H; ++i) {
    cout << C[i] << endl << C[i] << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
typedef long long ll;
using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  string C[105];
  for (int i = 1; i <= H; ++i)
    cin >> C[i];
  for (int i = 1; i <= H; ++i) {
    cout << C[i] << endl << C[i] << endl;
  }
}
Problem p03853 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> C(H, vector<char>(W));
  rep(i, H) rep(j, W) cin >> C[i][j];

  rep(i, 2 * H) {
    rep(j, W) { cout << C[(i + 1) / 2][j]; }
    cout << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> C(H, vector<char>(W));
  rep(i, H) rep(j, W) cin >> C[i][j];

  rep(i, 2 * H) {
    rep(j, W) { cout << C[i / 2][j]; }
    cout << endl;
  }
}
Problem p03853 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
// #include<cstdio>
// #include<cmath>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
// int MOD=1000000007;

signed main() {
  int h, w;
  cin >> h >> w;
  vector<string> c(h);
  rep(i, h) cin >> c[i];
  // vector<string> res(2*h);
  rep(i, 2 * h) {
    int buf = (i + 1) / 2;
    cout << c[buf] << endl;
    ;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
// #include<cstdio>
// #include<cmath>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
// int MOD=1000000007;

signed main() {
  int h, w;
  cin >> h >> w;
  vector<string> c(h);
  rep(i, h) cin >> c[i];
  // vector<string> res(2*h);
  rep(i, 2 * h) {
    int buf = i / 2;
    cout << c[buf] << endl;
    ;
  }
  return 0;
}
Problem p03853 (C++)

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

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

string field[110];
string afield[110];

int main() {
  int H, W;

  cin >> H >> W;
  rep(i, H) { cin >> field[i]; }
  for (int i = 1; i <= H * 2; i += 2) {
    afield[i] = field[i / 2];
    afield[i + 1] = field[i / 2];
  }

  for (int i = 1; i <= H * 2; i++) {
    cout << afield[i] << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <complex>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
using namespace std;

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

string field[220];
string afield[220];

int main() {
  int H, W;

  cin >> H >> W;
  rep(i, H) { cin >> field[i]; }
  for (int i = 1; i <= H * 2; i += 2) {
    afield[i] = field[i / 2];
    afield[i + 1] = field[i / 2];
  }

  for (int i = 1; i <= H * 2; i++) {
    cout << afield[i] << endl;
  }
}
Problem p03853 (C++)

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

#include <algorithm>
#include <vector>
using namespace std;

int main() {

  int h = 0;
  int w = 0;

  cin >> h >> w;

  const int MAX_HEIGHT = 100;
  const int MAX_WIDTH = 100;

  string str1[MAX_HEIGHT];
  string str2[MAX_HEIGHT];

  for (int i = 0; i < h; i++) {
    cin >> str1[i];
  }

  //(i+1)/2,j

  // 座標計算
  for (int i = 1; i <= h * 2; i++) {

    int x = (i + 1) / 2 - 1; // 配列は0はじまり

    char temp;
    for (int j = 0; j < w; j++) {
      temp = str1[x][j];
      str2[i - 1] += temp;
    }
  }

  for (int i = 0; i < 2 * h; i++) {

    cout << str2[i] << endl;
  }

  return 0;
}


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

#include <algorithm>
#include <vector>
using namespace std;

int main() {

  int h = 0;
  int w = 0;

  cin >> h >> w;

  const int MAX_HEIGHT = 100;
  const int MAX_WIDTH = 100;

  string str1[MAX_HEIGHT];
  string str2[MAX_HEIGHT * 2];

  for (int i = 0; i < h; i++) {
    cin >> str1[i];
  }

  //(i+1)/2,j

  // 座標計算
  for (int i = 1; i <= h * 2; i++) {

    int x = (i + 1) / 2 - 1; // 配列は0はじまり

    char temp;
    for (int j = 0; j < w; j++) {
      temp = str1[x][j];
      str2[i - 1] += temp;
    }
  }

  for (int i = 0; i < 2 * h; i++) {

    cout << str2[i] << endl;
  }

  return 0;
}
Problem p03853 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> P(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    string s;
    for (int j = 0; j < W; j++)
      P.at(i).at(j) = s.at(j);
  }
  vector<vector<char>> P2(2 * H, vector<char>(W));
  for (int i = 0; i < 2 * H; i++) {
    for (int j = 0; j < W; j++)
      P2.at(i).at(j) = P.at(i / 2).at(j);
  }
  for (int i = 0; i < 2 * H; i++) {
    for (int j = 0; j < W - 1; j++)
      cout << P2.at(i).at(j);
    cout << P2.at(i).at(W - 1) << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> P(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < W; j++)
      P.at(i).at(j) = s.at(j);
  }
  vector<vector<char>> P2(2 * H, vector<char>(W));
  for (int i = 0; i < 2 * H; i++) {
    for (int j = 0; j < W; j++)
      P2.at(i).at(j) = P.at(i / 2).at(j);
  }
  for (int i = 0; i < 2 * H; i++) {
    for (int j = 0; j < W - 1; j++)
      cout << P2.at(i).at(j);
    cout << P2.at(i).at(W - 1) << endl;
  }
  return 0;
}
Problem p03853 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define arep(a, i, n) for (ll i = (a); i < (n); i++)
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define cinf(x, n)                                                             \
  for (ll i = 0; i < (n); i++)                                                 \
    cin >> x[i];
#define coutf(x, n)                                                            \
  for (ll i = 0; i < (n); i++)                                                 \
    cout << x[i] << endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

char s[101][101];
char d[101][202];

int main() {
  int h, w;
  cin >> h >> w;
  rep(i, h) rep(j, w) cin >> s[i][j];
  rep(i, h) {
    rep(j, w) {
      d[2 * i][j] = s[i][j];
      d[2 * i + 1][j] = s[i][j];
    }
  }
  rep(i, 2 * h) {
    rep(j, w) { cout << d[i][j]; }
    cout << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define arep(a, i, n) for (ll i = (a); i < (n); i++)
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define cinf(x, n)                                                             \
  for (ll i = 0; i < (n); i++)                                                 \
    cin >> x[i];
#define coutf(x, n)                                                            \
  for (ll i = 0; i < (n); i++)                                                 \
    cout << x[i] << endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

char s[101][101];
char d[202][101];

int main() {
  int h, w;
  cin >> h >> w;
  rep(i, h) rep(j, w) cin >> s[i][j];
  rep(i, h) {
    rep(j, w) {
      d[2 * i][j] = s[i][j];
      d[2 * i + 1][j] = s[i][j];
    }
  }
  rep(i, 2 * h) {
    rep(j, w) { cout << d[i][j]; }
    cout << endl;
  }
}
Problem p03853 (C++)

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

int main() {
  int h, w;
  cin >> h >> w;
  string art[h];
  for (int i = 0; i < h; i++) {
    cin >> art[i];
  }
  for (int i = 0; i < 2 * h; i++) {
    cout << art[i] << endl << art[i] << endl;
  }
}


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

int main() {
  int h, w;
  cin >> h >> w;
  string art[h];
  for (int i = 0; i < h; i++) {
    cin >> art[i];
  }
  for (int i = 0; i < h; i++) {
    cout << art[i] << endl << art[i] << endl;
  }
}
Problem p03853 (C++)

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

typedef long long ll;

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

int main() {
  int H, W;
  string inp;
  vector<string> C(H);
  cin >> H >> W;
  rep(i, H) {
    cin >> inp;
    C.push_back(inp);
  }
  rep(i, H) {
    cout << C.at(i) << "\n";
    cout << C.at(i) << "\n";
  }

  return 0;
}


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

typedef long long ll;

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

int main() {
  int H, W;
  string inp;
  vector<string> C;
  cin >> H >> W;
  rep(i, H) {
    cin >> inp;
    C.push_back(inp);
  }
  rep(i, H) {
    cout << C.at(i) << "\n";
    cout << C.at(i) << "\n";
  }

  return 0;
}
Problem p03853 (C++)

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

int main() {
  int h, w;
  cin >> h >> w;
  char c[h][w];
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> c[i][j];
    }
  }
  for (int i = 1; i <= 2 * h; i++) {
    for (int j = 1; j <= w; j++) {
      cout << c[(i + 1) / 2][j];
    }
    cout << endl;
  }
}

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

int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    char c[101];
    scanf("%s", c);
    printf("%s\n", c);
    printf("%s\n", c);
  }
}
Problem p03853 (Python)

Buggy submission (status: Runtime Error):
H, W = map(int, input().split())
px = []
ans = []
for x in range(H):
    px.append(input())
    ans.append(px[x])
    ans.append(px[x])

for x in range(ans):
    print(ans[x])


Fixed submission:
H, W = map(int, input().split())
px = []
ans = []
for x in range(H):
    px.append(input())
    ans.append(px[x])
    ans.append(px[x])

for x in range(len(ans)):
    print(ans[x])
Problem p03853 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  char data[100][100];
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> data[i][j];
    }
  }
  for (int i = 1; i <= 2 * h; i++) {
    for (int j = 1; j <= w; j++) {
      cout << data[(i + 1) / 2][j];
    }
    cout << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  char data[101][101];
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> data[i][j];
    }
  }
  for (int i = 1; i <= 2 * h; i++) {
    for (int j = 1; j <= w; j++) {
      cout << data[(i + 1) / 2][j];
    }
    cout << endl;
  }
  return 0;
}
Problem p03853 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <math.h>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int h, w;
  char a[100][100] = {};

  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> a[i][j];
    }
  }

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cout << a[i][j];
    }
    cout << endl;
    for (int j = 1; j <= w; j++) {
      cout << a[i][j];
    }
    cout << endl;
  }
}

Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <math.h>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int h, w;
  char a[105][105] = {};

  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> a[i][j];
    }
  }

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cout << a[i][j];
    }
    cout << endl;
    for (int j = 1; j <= w; j++) {
      cout << a[i][j];
    }
    cout << endl;
  }
}
Problem p03853 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main() {
  ll h, w;
  cin >> h >> w;
  vector<string> pic(h), pic2(2 * h);
  rep(i, h) cin >> pic[i];
  rep(i, 2 * h) cout << pic[(i + 1) / 2 - 1] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main() {
  ll h, w;
  cin >> h >> w;
  vector<string> pic(h), pic2(2 * h);
  rep(i, h) cin >> pic[i];
  rep(i, 2 * h) cout << pic[i / 2] << endl;
  return 0;
}
Problem p03853 (Python)

Buggy submission (status: Runtime Error):
H, W = map(int, input().split())

for i in range(W):
    C = input()
    print(C)
    print(C)


Fixed submission:
H, W = map(int, input().split())

for i in range(H):
    C = input()
    print(C)
    print(C)
Problem p03853 (C++)

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

int main() {
  // H,Wを入力
  int H, W;
  cin >> H >> W;
  char c[100][100];
  // C_i,jを入力
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> c[i][j];
    }
  }
  // D_i,jをセット
  for (int i = 1; i <= 2 * H; i++) {
    for (int j = 1; j <= W; j++) {
      cout << c[(i + 1) / 2][j];
    }
    cout << endl;
  }
}


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

int main() {
  // H,Wを入力
  int H, W;
  cin >> H >> W;
  char c[200][200];
  // C_i,jを入力
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> c[i][j];
    }
  }
  // D_i,jをセット
  for (int i = 1; i <= 2 * H; i++) {
    for (int j = 1; j <= W; j++) {
      cout << c[(i + 1) / 2][j];
    }
    cout << endl;
  }
}