alexjercan/bugnet huggingface dataset:
Problem p02686 (C++) — buggy submission, verdict: Runtime Error

// Copyright 2020 yaito3014
#include <bits/stdc++.h>

#include <boost/range/adaptors.hpp>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<string> S(N);
  for (auto &e : S)
    cin >> e;
  vector<pair<int, int>> ps(N);
  transform(cbegin(S), cend(S), begin(ps), [](const string &s) {
    int A = 0, B = 0;
    for (char c : s)
      c == '(' ? ++B : B > 0 ? --B : ++A;
    return make_pair(A, B);
  });
  auto iter = partition(begin(ps), end(ps),
                        [](const auto &p) { return p.second >= p.first; });
  sort(begin(ps), iter,
       [](const auto &a, const auto &b) { return a.first < b.first; });
  sort(iter, end(ps),
       [](const auto &a, const auto &b) { return a.second > b.second; });
  vector<int> vec(N * 2);
  transform(cbegin(ps), cend(ps), begin(vec | boost::adaptors::strided(2)),
            [](const auto &p) { return -p.first; });
  transform(
      cbegin(ps), cend(ps),
      begin(vec | boost::adaptors::sliced(1, N) | boost::adaptors::strided(2)),
      [](const auto &p) { return p.second; });
  partial_sum(cbegin(vec), cend(vec), begin(vec));
  bool ans = all_of(cbegin(vec), cend(vec), [](int n) { return n >= 0; }) &&
             vec.back() == 0;
  cout << (ans ? "Yes" : "No") << endl;
}


Error: 0

Fixed submission:

// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<string> S(N);
  for (auto &e : S)
    cin >> e;
  vector<pair<int, int>> braces(N, make_pair(0, 0));
  for (int i = 0; i < N; ++i) {
    auto &[l, r] = braces[i];
    for (char c : S[i]) {
      if (c == '(')
        ++l;
      else if (l > 0)
        --l;
      else
        ++r;
    }
  }
  sort(begin(braces), end(braces),
       [](const pair<int, int> &a, const pair<int, int> &b) {
         return a.second == b.second ? a.first >= b.first : a.second < b.second;
       });
  bool ans = true;
  int b = 0;
  for (const auto &[bl, br] : braces) {
    b -= br;
    if (b < 0) {
      ans = false;
      break;
    }
    b += bl;
  }
  ans = ans && b == 0;
  cout << (ans ? "Yes" : "No") << endl;
}
Problem p02686 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int, int> PAIR;
const int N = 2e6 + 5;
const ll M = 998244353;
struct node {
  int x, y;
} a[N];
bool cmp(node p1, node p2) { return p1.x - p1.y > p2.x - p2.y; }
int main() {
  int n;
  string s;
  cin >> n;
  getchar();
  int le = 0, ri = 0;
  for (int i = 1; i <= n; i++) {
    getline(cin, s);
    int l = 0, r = 0;
    for (int j = 0; j < s.length(); j++) {
      if (s[j] == ')') {
        if (l > 0)
          l--;
        else
          r++;
      } else {
        l++;
      }
    }
    if (l && !r)
      le += l;
    else if (r && !l)
      ri += r;
    else
      a[i].x = l, a[i].y = r;
  }
  sort(a + 1, a + 1 + n, cmp);
  int l = le, r = ri;
  for (int i = 1; i <= n; i++) {
    if (l < a[i].y) {
      cout << "No\\n";
      return 0;
    } else {
      l -= a[i].y;
      l += a[i].x;
    }
  }
  if (l != r)
    cout << "No\\n";
  else
    cout << "Yes\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int, int> PAIR;
const int N = 2e5 + 5;
const ll M = 998244353;
struct node {
  int x, y;
} a[N];
bool cmp(node p1, node p2) {
  if (p1.x != p2.x)
    return p1.x > p2.x;
  else
    return p1.y < p2.y;
}
int main() {
  int n;
  string s;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    int l = 0, r = 0;
    for (int j = 0; j < s.length(); j++) {
      if (s[j] == ')') {
        if (l > 0)
          l--;
        else
          r++;
      } else {
        l++;
      }
    }
    a[i].x = l, a[i].y = r;
  }
  sort(a + 1, a + 1 + n, cmp);
  int l = 0, r = 0;
  for (int i = 1; i <= n; i++) {
    if (l < a[i].y) {
      cout << "No\\n";
      return 0;
    } else {
      l -= a[i].y;
      l += a[i].x;
    }
  }
  if (l > 0)
    cout << "No\\n";
  else
    cout << "Yes\\n";
  return 0;
}
Problem p02686 (C++) — buggy submission, verdict: Runtime Error

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

long long n, all = 0;
vector<string> s;
vector<int> req[2], sum[2], id[2];

bool solve();

int main() {
  cin >> n;
  s.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
    int len = s[i].size(), cnt = 0, now = 0;
    for (int j = 0; j < len; ++j)
      if (s[i][j] == '(')
        ++cnt, ++all;
      else
        --cnt, --all;
    if (cnt > 0) {
      sum[0].push_back(cnt);
      cnt = 0;
      for (int j = 0; j < len; ++j) {
        if (s[i][j] == '(')
          ++cnt;
        else
          --cnt;
        now = min(now, cnt);
      }
      req[0].push_back(now);
    } else {
      sum[1].push_back(-cnt);
      cnt = 0;
      for (int j = len - 1; j >= 0; --j) {
        if (s[i][j] == '(')
          --cnt;
        else
          ++cnt;
        now = min(now, cnt);
      }
      req[1].push_back(now);
    }
  }
  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}

bool solve() {
  if (all != 0)
    return 0;
  for (int t = 0; t < 2; ++t) {
    int len = sum[t].size();
    for (int i = 0; i < len; ++i)
      id[t].push_back(i);
    auto f = [&](int l, int r) {
      if (req[t][l] != req[t][r])
        return req[t][l] > req[t][r];
      return sum[t][l] > sum[t][r];
    };
    sort(id[t].begin(), id[t].end(), f);
    int cnt = 0;
    for (int i = 0; i < len; ++i) {
      if (cnt < -req[t][id[t][i]])
        return 0;
      cnt += sum[t][id[t][i]];
    }
  }
  return 1;
}

Error: 0

Fixed submission:

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

long long n;
vector<string> s;

bool solve();

int main() {
  cin >> n;
  s.resize(n);
  for (int i = 0; i < n; ++i)
    cin >> s[i];
  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}

bool solve() {
  vector<int> sum(n, 0), id, req(n, 0);
  for (int i = 0; i < n; ++i)
    id.push_back(i);
  sum.assign(n, 0);
  for (int i = 0; i < n; ++i) {
    int len = s[i].size();
    for (int j = 0; j < len; ++j) {
      if (s[i][j] == '(')
        ++sum[i];
      else
        --sum[i];
      req[i] = min(req[i], sum[i]);
    }
  }
  auto f = [&](int &l, int &r) {
    if (req[l] == 0)
      return true;
    if (req[r] == 0)
      return false;
    return sum[l] > sum[r];
  };
  sort(id.begin(), id.end(), f);
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (cnt < -req[id[i]])
      return 0;
    cnt += sum[id[i]];
  }
  return cnt == 0;
}
Problem p02686 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define forn(i, n) for (int i = 0; i < int(n); ++i)
typedef pair<int, int> pii;
const int MAXN = 1000000 + 10;
int N;
//  vector<string> br(MAXN);

void solve() {
  cin >> N;
  vector<pair<int, int>> def1;
  vector<pair<int, int>> def2;
  int run = 0;
  forn(i, N) {
    string ss;

    cin >> ss;
    int s1 = ss.size();
    int mina = 1000001;
    int co = 0;
    forn(j, s1) {
      if (ss[j] == '(')
        co++;
      else
        co--;
      mina = min(co, mina);
    }
    if (mina >= 0) {
      run += co;
    } else if (co >= 0) {
      def1.push_back({-mina, co});
    } else {
      def2.push_back({mina - co, -mina});
    }

    // cout<<mina<<" "<<co<<endl;
  }
  sort(def1.begin(), def1.end());
  sort(def2.begin(), def2.end());
  forn(i, def1.size()) {
    if (run - def1[i].x < 0) {
      cout << "No" << endl;
      return;
    }
    run += def1[i].y;
  }
  forn(i, def2.size()) {
    if (run - def2[i].y < 0) {
      cout << "No" << endl;
      return;
    }
    run -= def2[i].x + def2[i].y;
  }

  // cout<<run<<" "<<"run"<<endl;
  if (run == 0) {
    cout << "Yes" << endl;
    return;
  } else {
    cout << "No" << endl;
    return;
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  solve();

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define forn(i, n) for (int i = 0; i < int(n); ++i)
typedef pair<int, int> pii;
const int MAXN = 1000000 + 10;
int N;
//  vector<string> br(MAXN);
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (b.y >= a.y);
}
vector<pair<int, int>> def(MAXN);
void solve() {
  cin >> N;
  forn(i, N) {
    string ss;
    cin >> ss;
    int s1 = ss.size();
    int mina = 1000001;
    int co = 0;
    forn(j, s1) {
      if (ss[j] == '(')
        co++;
      else
        co--;
      mina = min(co, mina);
    }
    def[i].x = co;
    def[i].y = mina;
    // cout<<mina<<" "<<co<<endl;
  }
  sort(def.begin(), def.begin() + N);
  int st = N;
  forn(i, N) {
    if (def[i].x >= 0) {
      st = i;
      break;
    }
  }
  if (st < N) {
    sort(def.begin() + st, def.begin() + N, sortbysec);
  }
  //  	forn(i,N){
  //  		cout<<def[i].x<<" "<<def[i].y<<endl;
  //	}
  if (def[N - 1].y < 0) {
    cout << "No" << endl;
    return;
  }
  int run = def[N - 1].x;
  int neg = -1;
  for (int i = N - 2; i >= 0; i--) {
    if (def[i].y + run < 0) {
      cout << "No" << endl;
      return;
    }
    run = run + def[i].x;
  }

  // cout<<run<<" "<<"run"<<endl;
  if (run == 0) {
    cout << "Yes" << endl;
    return;
  } else {
    cout << "No" << endl;
    return;
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  solve();

  return 0;
}
Problem p02686 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
constexpr int MX = 1000005;
int n, el, er;
char s[MX];
using P = pair<int, int>;
P ls[MX], rs[MX];
int main() {
  scanf("%d", &n);
  rep(i, n) {
    scanf("%s", s);
    int len = strlen(s), l = 0, r = 0;
    rep(j, len) {
      if (s[j] == '(')
        r++;
      else if (r > 0)
        r--;
      else
        l++;
    }
    if (l < r)
      ls[el++] = {l, r};
    else
      rs[er++] = {l, r};
  }
  sort(ls, ls + el);
  sort(rs, rs + er, [](P &l, P &r) { return l.second > r.second; });
  auto f = [](P l, P r) {
    return P{l.first + max(0, r.first - l.second),
             r.second + max(0, l.second - r.first)};
  };
  P p = accumulate(ls, ls + el, P{0, 0}, f);
  p = accumulate(rs, rs + er, p, f);
  puts(p == P{0, 0} ? "Yes" : "No");
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
using P = pair<int, int>;
P ps[1000005];
int n, t;
bool ok = true;
char s[1000005];
int main() {
  scanf("%d", &n);
  rep(i, n) {
    scanf("\\n%s", s);
    int l = 0, r = 0, len = strlen(s);
    rep(j, len) {
      if (s[j] == ')') {
        if (r)
          r--;
        else
          l++;
      } else
        r++;
    }
    ps[i] = {l, r};
  }
  sort(ps, ps + n, [](const P &a, const P &b) {
    return a.fi <= a.se ? b.fi > b.se || a.fi < b.fi
                        : b.fi > b.se && a.se >= b.se;
  });
  rep(i, n) {
    if ((t -= ps[i].fi) < 0)
      ok = false;
    t += ps[i].se;
  }
  puts(ok && t == 0 ? "Yes" : "No");
}
Problem p02686 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using pll = pair<long long, long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

bool f(const P &l, const P &r) {
  int a = l.second - l.first;
  int b = r.second - r.first;
  if (a > 0 && b <= 0) {
    return true;
  }
  if (a <= 0 && b > 0) {
    return false;
  }
  if (a > 0 && b > 0) {
    return l.first < r.first;
  }
  if (a < 0 && b < 0) {
    return l.second > r.second;
  }
}

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  vector<P> lr(n);
  rep(i, n) {
    int l = 0;
    int r = 0;
    rep(j, s[i].size()) {
      if (s[i][j] == '(') {
        ++r;
      } else {
        if (r > 0)
          --r;
        else
          ++l;
      }
    }
    lr[i].first = l;
    lr[i].second = r;
  }

  sort(lr.begin(), lr.end(), f);
  if (lr[0].first != 0) {
    cout << "No" << endl;
    return 0;
  }
  int r = 0;
  rep(i, n) {
    if (r < lr[i].first) {
      cout << "No" << endl;
      return 0;
    }
    r -= lr[i].first;
    r += lr[i].second;
  }
  cout << (r == 0 ? "Yes" : "No") << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using pll = pair<long long, long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

bool f(P l, P r) {
  if (l.first < r.first) {
    return true;
  } else if (l.first > r.first) {
    return false;
  } else {
    return l.second >= r.second;
  }
}

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  vector<P> lr(n);
  rep(i, n) {
    int l = 0;
    int r = 0;
    rep(j, s[i].size()) {
      if (s[i][j] == '(') {
        ++r;
      } else {
        if (r > 0)
          --r;
        else
          ++l;
      }
    }
    lr[i].first = l;
    lr[i].second = r;
  }

  sort(lr.begin(), lr.end(), f);
  if (lr[0].first != 0) {
    cout << "No" << endl;
    return 0;
  }
  int l = 0;
  int r = 0;
  rep(i, n) {
    if (r < lr[i].first) {
      cout << "No" << endl;
      return 0;
    }
    r -= lr[i].first;
    r += lr[i].second;
  }
  cout << (r == 0 ? "Yes" : "No") << endl;
  return 0;
}
Problem p02686 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
using namespace std;
const int maxn = 1000100;
string a[maxn];
int arr[maxn], n;

vector<pair<int, int>> v;

int main() {
  cin >> n;

  int minind = -1, maxind = -1;
  int minbal = INT_MAX, maxbal = INT_MIN;

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

    int bal = 0;
    for (char j : a[i]) {
      if (j == '(')
        bal--;
      else
        bal++;
    }

    if (a[i][0] == '(' && bal < minbal) {
      minbal = bal;
      minind = i;
    } else if (a[i][sz(a[i]) - 1] == ')') {
      if (bal > maxbal) {
        maxbal = bal;
        maxind = i;
      }
    }
  }

  if (minind == -1 || maxind == -1) {
    cout << "No\\n";
    return 0;
  }

  arr[0] = minind;
  arr[n - 1] = maxind;

  for (int i = 0; i < n; i++) {
    if (i == minind || i == maxind) {
      continue;
    }

    int bal = 0;
    for (char j : a[i]) {
      if (j == '(')
        bal--;
      else
        bal++;
    }

    v.pb(mp(bal, i));
  }

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

  for (int i = 0; i < n - 2; i++) {
    arr[i + 1] = v[i].second;
  }

  int bal = 0;
  for (int i = 0; i < n; i++) {
    for (char j : a[arr[i]]) {
      if (j == '(')
        bal--;
      else
        bal++;

      if (bal > 0) {
        cout << "No\\n";
        return 0;
      }
    }
  }

  if (bal != 0) {
    cout << "No\\n";
  } else {
    cout << "Yes\\n";
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
using namespace std;
const int maxn = 1100;
string a[maxn];
int arr[maxn], n;

vector<pair<int, int>> v;

int main() {
  cin >> n;

  int minind = -1, maxind = -1;
  int minbal = INT_MAX, maxbal = INT_MIN;

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

    int bal = 0;
    for (char j : a[i]) {
      if (j == '(')
        bal--;
      else
        bal++;
    }

    if (a[i][0] == '(' && bal < minbal) {
      minbal = bal;
      minind = i;
    } else if (a[i][sz(a[i]) - 1] == ')') {
      if (bal > maxbal) {
        maxbal = bal;
        maxind = i;
      }
    }
  }

  if (minind == -1 || maxind == -1) {
    cout << "No\\n";
    return 0;
  }

  arr[0] = minind;
  arr[n - 1] = maxind;

  for (int i = 0; i < n; i++) {
    if (i == minind || i == maxind) {
      continue;
    }

    int bal = 0;
    for (char j : a[i]) {
      if (j == '(')
        bal--;
      else
        bal++;
    }

    v.pb(mp(bal, i));
  }

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

  for (int i = 0; i < n - 2; i++) {
    arr[i + 1] = v[i].second;
  }

  int bal = 0;
  for (int i = 0; i < n; i++) {
    for (char j : a[arr[i]]) {
      if (j == '(')
        bal--;
      else
        bal++;

      if (bal > 0) {
        cout << "No\\n";
        return 0;
      }
    }
  }

  if (bal != 0) {
    cout << "No\\n";
  } else {
    cout << "Yes\\n";
  }
}
Problem p02687 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define fi first
#define se second
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f

using namespace std;
using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

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

  string s;
  cin >> s;
  if (s[1] == 'B')
    cout << "ARC";
  else
    cout << "ABC";
  cout << '\\n';
  return 0;
}


Error: -8

Fixed submission:

#include <bits/stdc++.h>

#define fi first
#define se second
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f

using namespace std;
using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

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

  int k, a, b;
  cin >> k >> a >> b;
  if (a / k == b / k && a % k != 0)
    cout << "NG";
  else
    cout << "OK";
  cout << '\\n';

  return 0;
}
Problem p02687 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)-1); i > 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  string s;
  cin >> s;
  if (s == "ARC")
    cout << "ABC" << endl;
  else
    cout << "ARC" << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)-1); i > 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  string s;
  scanf("%s", &s);
  if (s == "ARC")
    cout << "ABC" << endl;
  else
    cout << "ARC" << endl;
  return 0;
}
Problem p02687 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  char S[6];
  scanf("%s", &S);
  if (S[1] == 'B')
    printf("ARC\\n");
  else
    printf("ABC\\n");
  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <stdio.h>

int main() {
  char contest;
  scanf("%s", &contest);

  if (contest = 'B') {
    printf("ARC");
  } else if (contest = 'R') {
    printf("ABC");
  }
  return 0;
}
Problem p02687 (C++) — buggy submission, verdict: Runtime Error

// Given a string S representing the type of the contest held last week
// print the string representing the type of the contest held this week.

#include <stdio.h>

int main() {
  char S[5];
  scanf("%s", &S);

  if (S[1] == 'B') {
    S[1] = 'R';
    printf("%s", S);
  }

  else if (S[1] == 'R') {
    S[1] = 'B';
    printf("%s", S);
  }

  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <stdio.h>

int main() {

  char a[0];
  scanf("%s", &a);

  if (a[1] == 'R') {
    a[1] = 'B';
    printf("%s\\n", a);
  }
  if (a[1] == 'B') {
    a[1] = 'R';
    printf("%s\\n", a);
  }
  return 0;
}
Problem p02687 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
typedef long long ll;
typedef pair<int, int> pii;

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

  if (s == "ABC") {
    cout << "ARC" << endl;
  } else {
    cout << "ABC" << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  int a, b, k;
  cin >> k >> a >> b;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  return 0;
}
Problem p02687 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>
int main() {
  char nama[5];

  scanf("%s", nama);

  if (strcmp(nama, "ABC") == 0) {
    printf("ARC");
  } else if (strcmp(nama, "ARC") == 0) {
    printf("ABC");
  } else {
  }

  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <stdio.h>
int main() {
  char S;
  char ABC;
  scanf("%s", &ABC);
  if (S = ABC) {
    printf("ARC");
  } else {
    printf("ABC");
  }
  return 0;
}
Problem p02687 (C++) — buggy submission, verdict: Runtime Error

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

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  string s;
  cin >> s;
  if (s == "ABC") {
    cout << "ARC" << endl;
  } else {
    cout << "ABC" << endl;
  }
  return 0;
}


Error: -11

Fixed submission:

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

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  const ll INF = 10000000000;
  int n;
  cin >> n;
  vector<int> h;
  vector<ll> dp(n, INF);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    h.push_back(a);
  }

  dp[0] = 0;
  for (int i = 1; i < n; ++i) {
    chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    if (i > 1) {
      chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
  }

  cout << dp[n - 1] << endl;

  return 0;
}
Problem p02687 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;

int main() {
  char a[3];
  cin >> a[0] >> a[1] >> a[2];
  if (a[1] == 'B')
    cout << "ARC";
  else
    cout << "ABC";
  return 0;
}


Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;

int main() {
  char a[3];
  cin >> a[1] >> a[2] >> a[3];
  if (a[2] == 'B')
    cout << "ARC";
  else
    cout << "ABC";
  return 0;
}
Problem p02687 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main(void) {
  char s[4];
  scanf("%s", s);
  if (s[1] == 'B') {
    s[1] = 'R';
    printf("%s\\n", s);
  } else {
    s[1] = 'B';
    printf("%s\\n", s);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
int main(void) {
  char s[4];
  scanf("%s", s);
  if (s[1] == 'B') {
    s[1] = 'R';
    printf("%s\\n", s[1]);
  } else {
    s[1] == 'R';
    printf("%s\\n", s[1]);
  }
  return 0;
}