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

Buggy submission (status: Time Limit Exceeded):
// https://atcoder.jp/contests/abc133/tasks/abc133_d

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// ll lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> a(n), b(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i <= a[0] * 2; i++) {
    b[0] = i;
    for (int j = 1; j < n; j++) {
      b[j] = a[j - 1] * 2 - b[j - 1];
    }
    if (b[0] + b[n - 1] == a[n - 1] * 2) {
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << b[i];
    if (i < n - 1) {
      cout << " ";
    }
  }
  cout << endl;

  return 0;
}

Fixed submission:
// https://atcoder.jp/contests/abc133/tasks/abc133_d

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// ll lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> a(n), b(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  b[0] = 0;
  for (int j = 1; j < n; j++) {
    b[j] = a[j - 1] * 2 - b[j - 1];
  }

  ll t1 = (a[n - 1] * 2);
  ll t2 = (b[0] + b[n - 1]);
  b[0] = (t1 - t2) / 2;
  for (int j = 1; j < n; j++) {
    b[j] = a[j - 1] * 2 - b[j - 1];
  }
  for (int i = 0; i < n; i++) {
    cout << b[i];
    if (i < n - 1) {
      cout << " ";
    }
  }
  cout << endl;

  return 0;
}
Problem p02984 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto &e : a)
    cin >> e;

  vector<ll> x(n);
  ll l = 0, r = 1e9 / 2 + 1, m;
  while (true) {
    m = (l + r) / 2;
    x[0] = 2 * m;
    for (int i = 0; i + 1 < n; i++) {
      x[i + 1] = 2 * (a[i] - x[i] / 2);
    }
    if (x[0] / 2 + x[n - 1] / 2 < a[n - 1]) {
      l = m + 1;
    } else if (x[0] / 2 + x[n - 1] / 2 > a[n - 1]) {
      r = m;
    } else {
      break;
    }
  }

  for (auto e : x)
    cout << e << ' ';
  cout << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto &e : a)
    cin >> e;

  vector<ll> x(n);
  ll l = 0, r = 1e9 + 1, m;
  while (true) {
    m = (l + r) / 2;
    x[0] = 2 * m;
    for (int i = 0; i + 1 < n; i++) {
      x[i + 1] = 2 * (a[i] - x[i] / 2);
    }
    if (x[0] / 2 + x[n - 1] / 2 < a[n - 1]) {
      l = m + 1;
    } else if (x[0] / 2 + x[n - 1] / 2 > a[n - 1]) {
      r = m;
    } else {
      break;
    }
  }

  for (auto e : x)
    cout << e << ' ';
  cout << endl;
}
Problem p02984 (C++)

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

int main() {
  int N;
  cin >> N;
  long long int A[100001];
  long long int W[100001];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  for (int i = 0; i < N; i++) {
    W[i] = A[i];
    for (int j = 1; j < N; j++) {
      if (j % 2 == 0)
        W[i] += A[(i + j) % N];
      if (j % 2 == 1)
        W[i] -= A[(i + j) % N];
    }
  }

  for (int i = 0; i < N; i++) {
    cout << W[i] << " ";
  }

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  long long int A[100001];
  long long int W[100001];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  W[0] = A[0];
  for (int i = 1; i < N; i++) {
    if (i % 2 == 0)
      W[0] += A[i];
    if (i % 2 == 1)
      W[0] -= A[i];
  }
  for (int i = 1; i < N; i++) {
    W[i] = 2 * A[i - 1] - W[i - 1];
  }

  for (int i = 0; i < N; i++) {
    cout << W[i] << " ";
  }

  return 0;
}
Problem p02984 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define exrep(i, a, b) for (ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

  vl a(n);
  rep(i, n) { cin >> a[i]; }

  vl b(n);
  rep(i, n) {
    if (i % 2 == 0) {
      b[0] += a[i];
    } else {
      b[0] -= a[i];
    }
  }

  rep(i, n) { b[i + 1] = 2 * a[i] - b[i]; }

  rep(i, n) { cout << b[i] << " "; }

  cout << endl;
  re0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define exrep(i, a, b) for (ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

  vl a(n);
  rep(i, n) { cin >> a[i]; }

  vl b(n);
  rep(i, n) {
    if (i % 2 == 0) {
      b[0] += a[i];
    } else {
      b[0] -= a[i];
    }
  }

  rep(i, n - 1) { b[i + 1] = 2 * a[i] - b[i]; }

  rep(i, n) { cout << b[i] << " "; }

  cout << endl;
  re0;
}
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int N;
int A[100000];
int ans[100000];
int sum;
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  for (int j = 0; j < N; j++) {
    ans[j] = 0;
    for (int i = 0; i < N; i++) {
      ans[j] += A[(i + j) % N] * pow(-1, i % 2);
    }
  }

  for (int i = 0; i < N; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int N;
int A[100000];
int ans[100000];
int sum;
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  // 1回目だけ別処理
  ans[0] = 0;
  for (int i = 0; i < N; i++) {
    ans[0] += A[(i) % N] * pow(-1, i % 2);
  }
  // 2回目以降
  for (int i = 1; i < N; i++) {
    ans[i] += 2 * A[i - 1] - ans[i - 1];
  }

  for (int i = 0; i < N; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
Problem p02984 (C++)

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i, m, n) for (ll(i) = (m), (i_len) = (n); (i) < (i_len); ++(i))
#define FORR(i, v) for (auto(i) : v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)), greater<ll>())
#define pb push_back

int main() {
  ll N;
  cin >> N;
  vec A(N + 1, 0);
  REP(i, 1, N + 1) cin >> A[i];

  vec B(N + 1, 0), C((N + 1) / 2, 0), D((N - 1) / 2, 0);
  ll S = 0;
  for (ll i = 1; i <= N; ++i)
    S += A[i];
  S /= 2;
  for (ll i = 1; i <= (N + 1) / 2; ++i)
    C[i] = C[i - 1] + A[2 * i - 1];
  for (ll i = 1; i <= (N - 1) / 2; ++i)
    D[i] = D[i - 1] + A[2 * i];

  for (ll i = 1; i <= (N + 1) / 2; ++i)
    B[2 * i - 1] = S - C[i - 1] - D[(N - 1) / 2] + D[i - 1];
  for (ll i = 1; i <= (N - 1) / 2; ++i)
    B[2 * i] = S - D[i - 1] - C[(N + 1) / 2] + C[i];

  for (ll i = 1; i <= N; ++i)
    PR(B[i] * 2);

  return 0;
}

/*



*/

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i, m, n) for (ll(i) = (m), (i_len) = (n); (i) < (i_len); ++(i))
#define FORR(i, v) for (auto(i) : v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)), greater<ll>())
#define pb push_back

int main() {
  ll N;
  cin >> N;
  vec A(N + 1, 0);
  REP(i, 1, N + 1) cin >> A[i];

  vec B(N + 1, 0), C((N + 1) / 2 + 1, 0), D((N - 1) / 2 + 1, 0);
  ll S = 0;
  for (ll i = 1; i <= N; ++i)
    S += A[i];
  S /= 2;
  for (ll i = 1; i <= (N + 1) / 2; ++i)
    C[i] = C[i - 1] + A[2 * i - 1];
  for (ll i = 1; i <= (N - 1) / 2; ++i)
    D[i] = D[i - 1] + A[2 * i];

  for (ll i = 1; i <= (N + 1) / 2; ++i)
    B[2 * i - 1] = S - C[i - 1] - D[(N - 1) / 2] + D[i - 1];
  for (ll i = 1; i <= (N - 1) / 2; ++i)
    B[2 * i] = S - D[i - 1] - C[(N + 1) / 2] + C[i];

  for (ll i = 1; i <= N; ++i)
    PR(B[i] * 2);

  return 0;
}

/*



*/
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

int n;
int t[100002];

int main() {

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

    // 2x
    int xMin = 0, xMax = 1000000001;

    while (true) {
      int x = (xMin + xMax) / 2;

      int status = 0;

      int preX = x;
      for (int i = 0; i < n; i++) {
        if (preX > t[i]) {
          if (i % 2 == 0) {
            status = 1;
            break;
          } else {
            status = -1;
            break;
          }
        }
        preX = t[i] - preX;
      }

      if (status == 0 && preX == x) {
        xMin = x;
        xMax = x + 1;
        break;
      }

      if (status == 1 || preX < x) {
        xMax = x;
      } else {
        xMin = x + 1;
      }
    }

    cout << xMin * 2;

    int preX = t[0] - xMin;

    for (int i = 0; i < n - 1; i++) {
      cout << " " << preX * 2;
      preX = t[i + 1] - preX;
    }
    cout << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

int n;
int t[100002];

int main() {

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

    // 2x
    int xMin = 0, xMax = 1000000001;

    while (true) {
      int x = (xMin + xMax) / 2;

      int status = 0;

      int preX = x;
      for (int i = 0; i < n; i++) {
        if (preX > t[i]) {
          if (i % 2 == 0) {
            status = 1;
            break;
          } else {
            status = -1;
            break;
          }
        }
        preX = t[i] - preX;
      }

      if (status == 0 && preX == x) {
        xMin = x;
        xMax = x + 1;
        break;
      }

      if (status == 1 || (status == 0 && preX < x)) {
        xMax = x;
      } else {
        xMin = x + 1;
      }
    }

    cout << xMin * 2;

    int preX = t[0] - xMin;

    for (int i = 0; i < n - 1; i++) {
      cout << " " << preX * 2;
      preX = t[i + 1] - preX;
    }
    cout << endl;
  }
}
Problem p02984 (C++)

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

int main() {
  std::size_t n;
  std::cin >> n;

  std::vector<size_t> a(n, 0);
  for (auto &&ai : a)
    std::cin >> ai;

  const auto sum = std::accumulate(a.begin(), a.end(), size_t(0)) / 2;

  std::vector<size_t> x(n, sum);
  for (size_t i = 0; i < n; ++i) {
    size_t k = i + 1;
    for (size_t j = 0; j < (n - 1) / 2; ++j) {
      if (k == n)
        k = 0;
      else if (k == n + 1)
        k = 1;
      x[i] -= a[k];
      k = k + 2;
    }
  }

  for (auto &&xi : x)
    std::cout << 2 * xi << ' ';
  std::cout << std::flush;
}

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

int main() {
  std::size_t n;
  std::cin >> n;

  std::vector<size_t> a(n, 0);
  for (auto &&ai : a)
    std::cin >> ai;

  const auto sum = std::accumulate(a.begin(), a.end(), size_t(0)) / 2;
  std::vector<size_t> x(n, 0);
  x[0] = sum;
  for (size_t i = 1; i < n; i = i + 2)
    x[0] -= a[i];
  for (size_t i = 1; i < n; ++i)
    x[i] = a[i - 1] - x[i - 1];

  for (auto &&xi : x)
    std::cout << 2 * xi << ' ';
  std::cout << std::flush;
}
Problem p02984 (C++)

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

using namespace std;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)

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

typedef unsigned int uint;
typedef unsigned long long int ull;
typedef long long int ll;

typedef pair<int, int> P;

#define LINF ((ll)1 << 63 - 1)
#define INF 2000000007
#define MINF -2000000007
#define MAX 100005

const int MOD = 1e9 + 7;
// テンプレ終了
//====================================================================//

//
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];

  vector<int> x(N, 0);
  REP(i, N) {
    REP(j, N) { x[i] += (j % 2 ? -A[(j + i) % N] : A[(j + i) % N]); }
  }
  cout << x[0];
  REPS(i, 1, N) cout << " " << x[i];
  cout << endl;

  return 0;
}


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

using namespace std;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)

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

typedef unsigned int uint;
typedef unsigned long long int ull;
typedef long long int ll;

typedef pair<int, int> P;

#define LINF ((ll)1 << 63 - 1)
#define INF 2000000007
#define MINF -2000000007
#define MAX 100005

const int MOD = 1e9 + 7;
// テンプレ終了
//====================================================================//

//
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];

  int x = 0;
  REP(j, N) { x += (j % 2 ? -A[j] : A[j]); }
  cout << x;
  REP(i, N - 1) cout << " " << (x = 2 * A[i] - x);
  cout << endl;

  return 0;
}
Problem p02984 (C++)

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

vector<ll> A(10000, 0);

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  ll B = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      B += A[i];
    } else {
      B -= A[i];
    }
  }
  for (int i = 0; i < N; i++) {
    cout << B << " ";
    B = 2 * A[i] - B;
  }
  cout << "\n";
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;

vector<ll> A(100000, 0);

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  ll B = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      B += A[i];
    } else {
      B -= A[i];
    }
  }
  for (int i = 0; i < N; i++) {
    cout << B << " ";
    B = 2 * A[i] - B;
  }
  cout << "\n";
}
Problem p02984 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  int n;
  cin >> n;
  vector<ll> r(n, 0);
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    r[0] += (i & 1 ? -a[i] : a[i]);
  }
  for (int i = 0; i < n; i++) {
    r[i + 1] = 2 * (a[i] - r[i] / 2);
  }
  for (int i = 0; i < n; i++)
    cout << r[i] << " ";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  int n;
  cin >> n;
  vector<ll> r(n, 0);
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    r[0] += (i & 1 ? -a[i] : a[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    r[i + 1] = 2 * (a[i] - r[i] / 2);
  }
  for (int i = 0; i < n; i++)
    cout << r[i] << " ";
  return 0;
}
Problem p02984 (C++)

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

const ll MAXN = 200000;

ll N, flag = 0, tmp = 0, mid = 0;
vector<ll> A(MAXN, 0);

signed main() {
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  ll ng = 0;
  ll ok = 1000000000;
  while (1) {
    // ll ngnum = ng*2;
    // ll oknum = ok*2;
    // cout << "ng : " << ng << " ok : " << ok << endl;
    // ll mid = (ng+ok)/2;
    // ll tmp = (ng+ok)/2;
    mid = (ng + ok) / 2;
    tmp = (ng + ok) / 2;
    for (int i = 0; i < N - 1; i++) {
      tmp = A[i] - tmp;
    }
    if (tmp + mid == A[N - 1])
      break;
    else if (tmp + mid > A[N - 1]) {
      ok = mid;
    } else {
      ng = mid;
    }
    // cout << " mid : " << mid << " tmp : " << tmp << " A : " << A[N-1] <<
    // endl; cout << endl;
  }
  tmp = mid;
  for (int i = 0; i < N; i++) {
    if (i)
      cout << " ";
    cout << 2 * tmp;
    tmp = A[i] - tmp;
  }
  return 0;
}

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

const ll MAXN = 200000;

ll N, flag = 0, tmp = 0, mid = 0;
vector<ll> A(MAXN, 0);

signed main() {
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  ll ng = -1;
  ll ok = 1000000001;
  while (1) {
    // ll ngnum = ng*2;
    // ll oknum = ok*2;
    // cout << "ng : " << ng << " ok : " << ok << endl;
    // ll mid = (ng+ok)/2;
    // ll tmp = (ng+ok)/2;
    mid = (ng + ok) / 2;
    tmp = (ng + ok) / 2;
    for (int i = 0; i < N - 1; i++) {
      tmp = A[i] - tmp;
    }
    if (tmp + mid == A[N - 1])
      break;
    else if (tmp + mid > A[N - 1]) {
      ok = mid;
    } else {
      ng = mid;
    }
    // cout << " mid : " << mid << " tmp : " << tmp << " A : " << A[N-1] <<
    // endl; cout << endl;
  }
  tmp = mid;
  for (int i = 0; i < N; i++) {
    if (i)
      cout << " ";
    cout << 2 * tmp;
    tmp = A[i] - tmp;
  }
  return 0;
}
Problem p02984 (C++)

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

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

  int N;
  cin >> N;
  long long a[1010], m[1010];
  long long su = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    su += a[i];
  }
  m[0] = 0;
  for (int i = 0; i < 2 * N; i += 2) {
    m[(i + 2) % N] = 2 * (a[(i + 1) % N] - a[i % N]) + m[i % N];
    su -= m[(i + 2) % N];
  }
  su /= N;
  for (int i = 0; i < N; i++) {
    cout << su + m[i] << " ";
  }
}

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

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

  int N;
  cin >> N;
  long long a[100010], m[100010];
  long long su = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    su += a[i];
  }
  m[0] = 0;
  for (int i = 0; i < 2 * N; i += 2) {
    m[(i + 2) % N] = 2 * (a[(i + 1) % N] - a[i % N]) + m[i % N];
    su -= m[(i + 2) % N];
  }
  su /= N;
  for (int i = 0; i < N; i++) {
    cout << su + m[i] << " ";
  }
}
Problem p02984 (C++)

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

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  ll sum = 0;
  vector<ll> s(N, 0), ans(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }

  for (int i = 0; i < N; i++) {
    ll tmp = sum;
    for (int j = 0; j < N; j++) {
      if (j == 0 && (N - i - 1) % 2)
        continue;
      if (i != j && i != j + 1) {
        tmp -= (2 * A[j]);
        j++;
      }
    }
    cout << tmp << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  ll sum = 0;
  vector<ll> s(N, 0), ans(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }

  ll tmp = sum;
  for (int i = 1; i < N; i += 2) {
    tmp -= (2 * A[i]);
  }
  ans[0] = tmp;
  cout << ans[0] << endl;
  for (int i = 0; i < N - 1; i++) {
    ans[i + 1] = 2 * A[i] - ans[i];
    cout << ans[i + 1] << endl;
  }
}
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
static const uint64_t MOD = 1000000007LL; /* 10^9 + 7 */
uint64_t dp[100005][13];

/*
 * (X1 + X2) / 2 == A1;
 * (X2 + X3) / 2 == A2;
 * (X3 + X1) / 2 == A3;
 * ....
 */
int main() {
  int n;
  cin >> n;
  vector<long> a(n + 1);
  vector<long> x(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  for (int i = 1; i <= n; i++) {
    long tmp = 0;
    for (int j = 1; j <= n; j++) {
      int k = i + j - 1;
      if (k > n)
        k -= n;
      if (j % 2 == 1)
        tmp += a[k];
      else
        tmp -= a[k];
    }
    x[i] = tmp;
  }

  for (int i = 1; i <= n; i++) {
    cout << x[i] << " ";
  }

  cout << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
static const uint64_t MOD = 1000000007LL; /* 10^9 + 7 */
uint64_t dp[100005][13];

/*
 * (X1 + X2) / 2 == A1;
 * (X2 + X3) / 2 == A2;
 * (X3 + X1) / 2 == A3;
 * ....
 */
int main() {
  int n;
  cin >> n;
  vector<long> a(n + 1);
  vector<long> x(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  long tmp = 0;
  for (int j = 1; j <= n; j++) {
    if (j % 2 == 1)
      tmp += a[j];
    else
      tmp -= a[j];
  }
  x[1] = tmp;
  for (int i = 2; i <= n; i++) {
    x[i] = 2 * a[i - 1] - x[i - 1];
  }

  for (int i = 1; i <= n; i++) {
    cout << x[i] << " ";
  }

  cout << endl;
}
Problem p02984 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto &&a : (x))
#define _overload3(_1, _2, _3, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) for (ll i = (a); i < (n); ++i)
#define rep(...) _overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template <class T> inline void print(const T &x) { cout << x << "\n"; }
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b)
    a = b;
  return a < b;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b)
    a = b;
  return a > b;
}
struct Init {
  Init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  }
} init;

int main() {
  ll n;
  cin >> n;
  vi a(n);
  ll sall = 0;
  ll sodd = 0;
  rep(i, n) {
    cin >> a[i];
    sall += a[i];
    if (i & 1)
      sodd += a[i];
  }
  vi x(n);
  x[0] = sall - 2 * sodd;
  rep(i, n) x[i + 1] = 2 * a[i] - x[i];
  each(a, x) cout << a << " ";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto &&a : (x))
#define _overload3(_1, _2, _3, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) for (ll i = (a); i < (n); ++i)
#define rep(...) _overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template <class T> inline void print(const T &x) { cout << x << "\n"; }
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b)
    a = b;
  return a < b;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b)
    a = b;
  return a > b;
}
struct Init {
  Init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  }
} init;

int main() {
  ll n;
  cin >> n;
  vi a(n);
  ll sall = 0;
  ll sodd = 0;
  rep(i, n) {
    cin >> a[i];
    sall += a[i];
    if (i & 1)
      sodd += a[i];
  }
  vi x(n);
  x[0] = sall - 2 * sodd;
  rep(i, n - 1) x[i + 1] = 2 * a[i] - x[i];
  each(a, x) cout << a << " ";
}
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define For(i, a, b) for (int i = a; i <= b; i++)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define int ll
#define MOD (ll)(1e9 + 7)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

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

  int n;
  cin >> n;
  vector<int> v(n);
  int s = 0;
  for (auto &i : v) {
    cin >> i;
    s += i;
  }
  For(i, 0, n - 1) {
    int tmp = 0;
    for (int j = (i + 1) % n; j != i; j = (j + 2) % n) {
      tmp += 2 * v[j];
    }
    cout << s - tmp << " \n"[i == n - 1];
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define For(i, a, b) for (int i = a; i <= b; i++)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define int ll
#define MOD (ll)(1e9 + 7)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

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

  int n;
  cin >> n;
  vector<int> v(n);
  int s = 0;
  for (auto &i : v) {
    cin >> i;
    s += i;
  }
  int tmp = s;
  for (int j = 1; j != 0; j = (j + 2) % n) {
    tmp -= 2 * v[j];
  }
  cout << tmp;
  For(i, 0, n - 2) {
    cout << " " << (v[i] - tmp / 2) * 2;
    tmp = (v[i] - tmp / 2) * 2;
  }
  return 0;
}
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> ans;
  ll t = a[0] + 1;
  ll u = -1;
  while (true) {
    vector<ll> kari;
    ll mid = (t + u) / 2;
    ll pre = mid;
    ll s = mid;
    ll next = a[0] - pre;
    bool f = true;
    bool f2 = true;

    kari.push_back(mid * 2);
    for (int i = 0; i < n; i++) {
      next = a[i] - pre;
      if (next < 0) {
        if (i % 2)
          f2 = false;
        else
          f = false;
        break;
      } else {
        kari.push_back(next * 2);
        pre = next;
      }
    }

    if (next == s) {
      ans = kari;
      break;

    } else if (f == false || f2 == false || next > s) {
      if (f2 == false || next > s)
        u = mid;
      else
        t = mid;

    } else {
      u = mid;
    }
    // cout<<t<<u<<endl;
  }

  rep(i, ans.size() - 1) { cout << ans[i] << " "; }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> ans;
  ll t = a[0] + 1;
  ll u = -1;
  while (true) {
    vector<ll> kari;
    ll mid = (t + u) / 2;
    ll pre = mid;
    ll s = mid;
    ll next = a[0] - pre;
    bool f = true;
    bool f2 = true;

    kari.push_back(mid * 2);
    for (int i = 0; i < n; i++) {
      next = a[i] - pre;
      if (next < 0) {
        if (i % 2)
          f2 = false;
        else
          f = false;
        break;
      } else {
        kari.push_back(next * 2);
        pre = next;
      }
    }

    if (next == s) {
      ans = kari;
      break;

    } else if (f == false || f2 == false || next > s) {
      if (f2 == false || next > s)
        u = mid;
      else
        t = mid;

    } else {
      t = mid;
    }
    // cout<<t<<u<<endl;
  }

  rep(i, ans.size() - 1) { cout << ans[i] << " "; }

  return 0;
}
Problem p02984 (C++)

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

using namespace std;

typedef vector<int> VI;
typedef long long LL;
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define OUT(v) cout << v << endl

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

  VI A;
  LL S = 0;
  REP(i, N) {
    int a;
    cin >> a;
    A.PB(a);
    S += a;
  }
  LL x_1 = S;
  REP(i, (N - 1) / 2) { x_1 -= 2 * A[i * 2 + 1]; }
  VI X;
  X.PB(x_1);
  REP(i, N - 1) {
    X[i + 1] = 2 * A[i] - X[i];
    cout << X[i] << " ";
  }
  cout << X[N - 1] << endl;
  return 0;
}


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

using namespace std;

typedef vector<int> VI;
typedef long long LL;
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define OUT(v) cout << v << endl

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

  VI A;
  LL S = 0;
  REP(i, N) {
    int a;
    cin >> a;
    A.PB(a);
    S += a;
  }
  LL x_1 = S;
  REP(i, (N - 1) / 2) { x_1 -= 2 * A[2 * i + 1]; }
  int X[100000];
  X[0] = x_1;
  REP(i, N)
  X[i + 1] = 2 * A[i] - X[i];
  REP(i, N - 1)
  cout << X[i] << " ";
  cout << X[N - 1] << endl;
  return 0;
}
Problem p02984 (C++)

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

int main() {
  int n;
  long long int a[10000], s = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i % 2 == 0)
      s += a[i];
    else
      s -= a[i];
  }
  cout << s;
  s = s / 2;
  for (int i = 0; i < n - 1; i++) {
    s = a[i] - s;
    cout << " " << 2 * s;
  }
  cout << endl;
}


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

int main() {
  int n;
  long long int a[100000], s = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i % 2 == 0)
      s += a[i];
    else
      s -= a[i];
  }
  cout << s;
  s = s / 2;
  for (int i = 0; i < n - 1; i++) {
    s = a[i] - s;
    cout << " " << 2 * s;
  }
  cout << endl;
}
Problem p02984 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  int n;
  ll sum = 0;
  cin >> n;
  vector<ll> a(n);
  vector<ll> ans(n);
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  rep(i, n) { a.push_back(a[i]); }
  rep(i, n) {
    ans[i] = sum;
    rep(j, n / 2) { ans[i] -= 2 * a[i + 1 + 2 * j]; }
  }
  rep(i, n) { cout << ans[i] << ' '; }
  cout << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  int n;
  ll sum = 0;
  cin >> n;
  vector<ll> a(n);
  vector<ll> ans(n);
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  rep(i, n) { a.push_back(a[i]); }
  ans[0] = sum;
  rep(j, n / 2) { ans[0] -= 2 * a[1 + 2 * j]; }
  rep(i, n - 1) { ans[i + 1] = 2 * a[i] - ans[i]; }
  rep(i, n) { cout << ans[i] << ' '; }
  cout << endl;
  return 0;
}
Problem p02987 (C++)

Buggy submission (status: Runtime Error):
// Keep Working hard
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(nullptr);                                                            \
  cout.precision(10);

const int N = 1e5 + 5;
int a[N];

void solve() {
  string s;
  cin >> s;
  map<int, int> mp;
  for (int i = 0; i < 4; i++) {
    mp[s[i] - 'A']++;
  }
  for (auto i : mp) {
    if (i.second != 2) {
      cout << "No";
      exit(0);
    }
  }
  cout << "Yes";
}

void fileIO() {
#ifndef ONLINE_JUDGE
  freopen("int.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
}

int32_t main() {
  IOS;
  fileIO();
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}


Fixed submission:
// Keep Working hard
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(nullptr);                                                            \
  cout.precision(10);

const int N = 1e5 + 5;
int a[N];

void solve() {
  string s;
  cin >> s;
  map<int, int> mp;
  for (int i = 0; i < 4; i++) {
    mp[s[i] - 'A']++;
  }
  for (auto i : mp) {
    if (i.second != 2) {
      cout << "No";
      exit(0);
    }
  }
  cout << "Yes";
}

void fileIO() {
#ifndef ONLINE_JUDGE
  freopen("int.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
}

int32_t main() {
  IOS;
  //   fileIO();
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02987 (C++)

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

int main() {
  string s;
  cin >> s;
  if (s.at(0) == s.at(1) && s.at(2) == s.at(3) ||
      s.at(1) == s.at(2) && s.at(0) == s.at(3) ||
      s.at(1) == s.at(3) && s.at(2) == s.at(4)) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}


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

int main() {
  string s;
  cin >> s;
  if (s.at(0) == s.at(1) && s.at(2) == s.at(3) && s.at(1) != s.at(2) ||
      s.at(1) == s.at(2) && s.at(0) == s.at(3) && s.at(0) != s.at(1) ||
      s.at(1) == s.at(3) && s.at(2) == s.at(0) && s.at(1) != s.at(2)) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}
Problem p02987 (C++)

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

int main() {
  int seged = 0;
  string S = "ASSA";
  cin >> S;
  for (int i = 0; i < S.length() - 1; i++) {
    for (int j = i + 1; S.length(); j++) {
      if (S[i] == S[j]) {
        seged += 1;
      }
    }
  }
  if (seged == 2) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}


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

int main() {
  int seged = 0;
  string S = "ASSA";
  cin >> S;
  for (int i = 0; i < S.length() - 1; i++) {
    for (int j = i + 1; j < S.length(); j++) {
      if (S[i] == S[j]) {
        seged += 1;
      }
    }
  }
  if (seged == 2) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}
Problem p02987 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;

  char c[4];
  strcpy(c, str.c_str());

  sort(c, c + 4);

  if (c[0] == c[1] && c[2] == c[3] && c[1] != c[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;

  char c[10];
  strcpy(c, str.c_str());

  sort(c, c + 4);

  if (c[0] == c[1] && c[2] == c[3] && c[1] != c[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}
Problem p02987 (C++)

Buggy submission (status: Runtime Error):
#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 main() {
  string s;
  cin >> s;
  vector<int> cnt(26);
  int ans = 0;
  rep(i, 4) {
    int t;
    t = s[i] - 'a';
    if (cnt[t] == 1) {
      ans++;
    }
    cnt[t]++;
  }
  if (ans == 2) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
  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 main() {
  string s;
  cin >> s;
  vector<int> cnt(26);
  int ans = 0;
  rep(i, 4) {
    int t;
    t = s[i] - 'A';
    if (cnt[t] == 1) {
      ans++;
    }
    cnt[t]++;
  }
  if (ans == 2) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
  return 0;
}
Problem p02987 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int table[26];
char S[5];

int main() {

  for (int i = 0; i < 26; i++) {

    table[i] = 0;
  }

  scanf("%s", S);

  for (int i = 0; S[i] != '\0'; i++) {

    table[S[i] - 'a']++;
  }

  int num_2 = 0;

  for (int i = 0; i < 26; i++) {
    if (table[i] == 2) {

      num_2++;
    }
  }

  if (num_2 == 2) {

    printf("Yes\n");

  } else {

    printf("No\n");
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int table[26];
char S[5];

int main() {

  for (int i = 0; i < 26; i++) {

    table[i] = 0;
  }

  scanf("%s", S);

  for (int i = 0; S[i] != '\0'; i++) {

    table[S[i] - 'A']++;
  }

  int num_2 = 0;

  for (int i = 0; i < 26; i++) {
    if (table[i] == 2) {

      num_2++;
    }
  }

  if (num_2 == 2) {

    printf("Yes\n");

  } else {

    printf("No\n");
  }

  return 0;
}
Problem p02987 (C++)

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

int main() {
  string S;

  sort(S.begin(), S.end());

  if (S.at(0) == S.at(1) && S.at(2) == S.at(3) && S.at(0) != S.at(2))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

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

  sort(S.begin(), S.end());

  if (S.at(0) == S.at(1) && S.at(2) == S.at(3) && S.at(0) != S.at(2))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02987 (C++)

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

using namespace std;

int main() {
  string a[2] = {"", ""};
  int count1 = 0;
  int count2 = 0;
  string S;
  cin >> S;
  for (int i = 1; i < 4; i++) {
    if (S[0] == S[i]) {
      count1++;
    } else {
      a[count2] = S[i];
      count2++;
    }
  }
  if (count1 == 1 and a[0] == a[1]) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}


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

using namespace std;

int main() {
  string a[4];
  int count1 = 0;
  int count2 = 0;
  string S;
  cin >> S;
  for (int i = 1; i < 4; i++) {
    if (S[0] == S[i]) {
      count1++;
    } else {
      a[count2] = S[i];
      count2++;
    }
  }
  if (count1 == 1 and a[0] == a[1]) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}
Problem p02987 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define sz(a) int((a).size())
#define pb push_back
#define tr(c, i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define rep(i, n) for (ll i = 0; i < n; i++)
// s.replace(s.find("10"), sizeof("10") - 1, "");
using namespace std;
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
bool compare(const pair<int, int> &i, const pair<int, int> &j) {
  return i.second < j.second;
}
int main() {
  // added the two lines below
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
// freopen("error.txt","w",stderr);
#endif
  string s;
  cin >> s;
  map<char, int> m;
  int flag = 0;
  for (int i = 0; i < s.size(); i++) {
    m[s[i]]++;
  }
  for (auto i = m.begin(); i != m.end(); i++) {
    if ((*i).second != 2) {
      flag = 1;
      break;
    }
  }
  if (flag)
    cout << "No";
  else
    cout << "Yes";
}


Fixed submission:
#include <bits/stdc++.h>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define sz(a) int((a).size())
#define pb push_back
#define tr(c, i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define rep(i, n) for (ll i = 0; i < n; i++)
// s.replace(s.find("10"), sizeof("10") - 1, "");
using namespace std;
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
bool compare(const pair<int, int> &i, const pair<int, int> &j) {
  return i.second < j.second;
}
int main() {
  // added the two lines below
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  map<char, int> m;
  int flag = 0;
  for (int i = 0; i < s.size(); i++) {
    m[s[i]]++;
  }
  for (auto i = m.begin(); i != m.end(); i++) {
    if ((*i).second != 2) {
      flag = 1;
      break;
    }
  }
  if (flag)
    cout << "No";
  else
    cout << "Yes";
}
Problem p02987 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  char *s;
  cin >> s;
  int count = 0;
  int elc = 0;
  char tmp1, tmp2;
  tmp1 = *s;
  tmp2 = *s;
  s++;
  count++;
  for (int i = 0; i < 3; i++) {
    if (*s != tmp1 && elc == 0) {
      tmp2 = *s;
      elc = 1;
    }
    if (*s == tmp1)
      count++;
    if (*s != tmp1 && *s != tmp2)
      elc = -1;
    s++;
  }
  if (count == 2 && elc == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  char *s = (char *)malloc(sizeof(char) * 5);
  s[4] = 0;
  cin >> s;
  int count = 0;
  int elc = 0;
  char tmp1, tmp2;
  tmp1 = *s;
  tmp2 = *s;
  s++;
  count++;
  for (int i = 0; i < 3; i++) {
    if (*s != tmp1 && elc == 0) {
      tmp2 = *s;
      elc = 1;
    }
    if (*s == tmp1)
      count++;
    if (*s != tmp1 && *s != tmp2)
      elc = -1;
    s++;
  }
  if (count == 2 && elc == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p02987 (C++)

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

using lli = long long int;
int inf = 1000000007;
using namespace std;
int NextInt() {
  int x;
  cin >> x;
  return x;
}

int main() {
  vector<char> m;
  for (int i = 0; i < 4; i++)
    cin >> m[i];
  sort(m.begin(), m.end());

  if (m[0] == m[1] && m[1] != m[2] && m[2] == m[3])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

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

using lli = long long int;
int inf = 1000000007;
using namespace std;
int NextInt() {
  int x;
  cin >> x;
  return x;
}

int main() {
  vector<char> m(4);
  for (int i = 0; i < 4; i++)
    cin >> m[i];
  sort(m.begin(), m.end());

  if (m[0] == m[1] && m[1] != m[2] && m[2] == m[3])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}
Problem p02987 (C++)

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

#define ll long long int

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int ar[10000];
  memset(ar, 0, sizeof(ar));
  string s;
  cin >> s;
  for (int i = 0; i < 4; i++) {
    ar[(int)(s.at(i) - 'A')]++;
  }
  for (int i = 0; i < 100; i++) {
    if (ar[i] == 1 || ar[i] == 4) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

#define ll long long int

int main() {

  int ar[10000];
  memset(ar, 0, sizeof(ar));
  string s;
  cin >> s;
  for (int i = 0; i < 4; i++) {
    ar[(int)(s.at(i) - 'A')]++;
  }
  for (int i = 0; i < 100; i++) {
    if (ar[i] == 1 || ar[i] == 4) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}