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

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

set<int> ch[100005];
bool mark[100005];
set<int> alive;
int n;

void kill(int x) {
  alive.erase(x);
  for (int u : ch[x])
    ch[u].erase(x);
  ch[x].clear();
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    ch[a].insert(b);
    ch[b].insert(a);
  }
  for (int i = 0; i < n; i++)
    alive.insert(i);
  while (alive.size() > 2) {
    vector<int> todo;
    for (auto it = alive.begin(); it != alive.end(); it++)
      if (ch[*it].size() == 1)
        todo.push_back(*it);
    vector<int> ext;
    for (int u : todo) {
      if (mark[*ch[u].begin()]) {
        printf("First\n");
        return 0;
      }
      mark[*ch[u].begin()] = true;
      ext.push_back(*ch[u].begin());
    }
    for (int u : todo)
      kill(u);
    for (int u : ext)
      kill(u);
  }
  if (alive.size() == 1) {
    printf("First\n");
  } else {
    if (ch[*alive.begin()].find(*alive.rbegin()) != ch[*alive.begin()].end())
      printf("Second\n");
    else
      printf("First\n");
  }
  return 0;
}


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

set<int> ch[100005];
bool mark[100005];
set<int> alive;
int n;

void kill(int x) {
  alive.erase(x);
  for (int u : ch[x])
    ch[u].erase(x);
  ch[x].clear();
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    ch[a].insert(b);
    ch[b].insert(a);
  }
  for (int i = 0; i < n; i++)
    alive.insert(i);
  while (alive.size() > 2) {
    vector<int> todo;
    for (auto it = alive.begin(); it != alive.end(); it++)
      if (ch[*it].size() == 1)
        todo.push_back(*it);
    vector<int> ext;
    for (int u : todo) {
      if (mark[*ch[u].begin()]) {
        printf("First\n");
        return 0;
      }
      mark[*ch[u].begin()] = true;
      ext.push_back(*ch[u].begin());
    }
    for (int u : todo)
      kill(u);
    for (int u : ext)
      kill(u);
  }
  if (alive.size() == 1) {
    printf("First\n");
  } else {
    if (alive.empty() ||
        ch[*alive.begin()].find(*alive.rbegin()) != ch[*alive.begin()].end())
      printf("Second\n");
    else
      printf("First\n");
  }
  return 0;
}
Problem p03726 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int nn = 1e5 + 10;
bool f[nn];
vector<int> son[nn];
int fa[nn];
bool dfs(int p) {
  for (int i = 0, t; i < son[p].size(); i++)
    if ((t = son[p][i]) != fa[p]) {
      fa[t] = p, dfs(t);
      if (f[p])
        f[p] ^= f[t];
      else if (f[t])
        printf("First"), exit(0);
    }
  return f[p];
}
int main() {
  freopen("data.in", "r", stdin);
  freopen("data.out", "w", stdout);
  int n;
  scanf("%d", &n);
  memset(f, true, sizeof f);
  for (int i = 1, a, b; i < n; i++) {
    scanf("%d%d", &a, &b);
    son[a].push_back(b);
    son[b].push_back(a);
  }
  if (dfs(1))
    printf("First");
  else
    printf("Second");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int nn = 1e5 + 10;
bool f[nn];
vector<int> son[nn];
int fa[nn];
bool dfs(int p) {
  for (int i = 0, t; i < son[p].size(); i++)
    if ((t = son[p][i]) != fa[p]) {
      fa[t] = p, dfs(t);
      if (f[p])
        f[p] ^= f[t];
      else if (f[t])
        printf("First"), exit(0);
    }
  return f[p];
}
int main() {
  int n;
  scanf("%d", &n);
  memset(f, true, sizeof f);
  for (int i = 1, a, b; i < n; i++) {
    scanf("%d%d", &a, &b);
    son[a].push_back(b);
    son[b].push_back(a);
  }
  if (dfs(1))
    printf("First");
  else
    printf("Second");
  return 0;
}
Problem p03726 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
const int N = 10000 + 100;
const int MOD = 1000000007;
const int oo = 1e9;

int n, a, b;
vector<int> g[N];

int solve(int u, int p) {
  int total = 0;
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i];
    if (v == p)
      continue;
    total += solve(v, u);
  }
  if (total > 1) {
    puts("First");
    exit(0);
  }
  return !total;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    scanf("%d%d", &a, &b);
    g[a].pb(b);
    g[b].pb(a);
  }
  if (solve(1, -1)) {
    puts("First");
  } else {
    puts("Second");
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
const int N = 100000 + 100;
const int MOD = 1000000007;
const int oo = 1e9;

int n, a, b;
vector<int> g[N];

int solve(int u, int p) {
  int total = 0;
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i];
    if (v == p)
      continue;
    total += solve(v, u);
  }
  if (total > 1) {
    puts("First");
    exit(0);
  }
  return !total;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    scanf("%d%d", &a, &b);
    g[a].pb(b);
    g[b].pb(a);
  }
  if (solve(1, -1)) {
    puts("First");
  } else {
    puts("Second");
  }
  return 0;
}
Problem p03727 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define P pair<int, int>
#define mk_p make_pair
const int N = 1e5 + 11;
set<int> s[N];
map<P, int> mp;
int n, fa[N];
P dl[N];
int read() {
  int x = 0, fl = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0')
    fl = (ch == '-' ? -1 : fl), ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = 10 * x + ch - 48, ch = getchar();
  return x * fl;
}
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int main() {
  freopen("agc014e.in", "r", stdin);
  freopen("agc014e.out", "w", stdout);
  n = read();
  int u, v;
  int hd = 0, tl = 0;
  for (int i = 1; i <= 2 * n - 2; i++) {
    u = read();
    v = read();
    s[u].insert(v);
    s[v].insert(u);
    mp[mk_p(u, v)]++;
    mp[mk_p(v, u)]++;
    if (mp[mk_p(u, v)] == 2)
      dl[++tl] = mk_p(u, v);
  }
  for (int i = 1; i <= n; i++)
    fa[i] = i;
  while (hd < tl) {
    P now = dl[++hd];
    int u = now.first, v = now.second;
    u = find(u);
    v = find(v);
    if (u == v)
      continue;
    if (s[u].size() < s[v].size())
      swap(u, v);
    fa[v] = u;
    set<int>::iterator it;
    s[u].erase(v);
    s[v].erase(u);
    for (it = s[v].begin(); it != s[v].end(); it++) {
      int to = *it;
      mp[mk_p(v, to)] = mp[mk_p(to, v)] = 0;
      s[to].erase(v);
      s[to].insert(u);
      s[u].insert(to);
      mp[mk_p(to, u)]++;
      mp[mk_p(u, to)]++;
      if (mp[mk_p(to, u)] == 2)
        dl[++tl] = mk_p(to, u);
    }
  }
  int fl = 0;
  for (int i = 1; i <= n; i++)
    fl += fa[i] == i;
  puts(fl == 1 ? "YES" : "NO");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define P pair<int, int>
#define mk_p make_pair
const int N = 1e5 + 11;
set<int> s[N];
map<P, int> mp;
int n, fa[N];
P dl[N];
int read() {
  int x = 0, fl = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0')
    fl = (ch == '-' ? -1 : fl), ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = 10 * x + ch - 48, ch = getchar();
  return x * fl;
}
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int main() {

  n = read();
  int u, v;
  int hd = 0, tl = 0;
  for (int i = 1; i <= 2 * n - 2; i++) {
    u = read();
    v = read();
    s[u].insert(v);
    s[v].insert(u);
    mp[mk_p(u, v)]++;
    mp[mk_p(v, u)]++;
    if (mp[mk_p(u, v)] == 2)
      dl[++tl] = mk_p(u, v);
  }
  for (int i = 1; i <= n; i++)
    fa[i] = i;
  while (hd < tl) {
    P now = dl[++hd];
    int u = now.first, v = now.second;
    u = find(u);
    v = find(v);
    if (u == v)
      continue;
    if (s[u].size() < s[v].size())
      swap(u, v);
    fa[v] = u;
    set<int>::iterator it;
    s[u].erase(v);
    s[v].erase(u);
    for (it = s[v].begin(); it != s[v].end(); it++) {
      int to = *it;
      mp[mk_p(v, to)] = mp[mk_p(to, v)] = 0;
      s[to].erase(v);
      s[to].insert(u);
      s[u].insert(to);
      mp[mk_p(to, u)]++;
      mp[mk_p(u, to)]++;
      if (mp[mk_p(to, u)] == 2)
        dl[++tl] = mk_p(to, u);
    }
  }
  int fl = 0;
  for (int i = 1; i <= n; i++)
    fl += fa[i] == i;
  puts(fl == 1 ? "YES" : "NO");
  return 0;
}
Problem p03727 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l), i##end = (r); i <= i##end; ++i)
#define pb insert
using std::cin;
using std::cout;
const int maxn = 200200;
typedef long long ll;
typedef std::pair<int, int> pr;
std::set<int> s[2][maxn];
std::set<std::pair<int, int>> set;
int fa[maxn];
int n, x, y;
inline void ins(int x, int y, int id) {
  if (x != y) {
    s[id][x].emplace(y), s[id][y].emplace(x);
    if (s[!id][x].count(y))
      set.emplace(std::min(x, y), std::max(x, y));
  }
}
inline void del(int x, int y, int id) {
  s[id][x].erase(y), s[id][y].erase(x);
  if (s[!id][x].count(y))
    set.erase(pr(std::min(x, y), std::max(x, y)));
}
inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int main() {
  std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n - 1) cin >> x >> y, ins(x, y, 0);
  rep(i, 1, n - 1) cin >> x >> y, ins(x, y, 1);
  int ans = 0;
  for (; set.size();) {
    pr p = *set.begin();
    set.erase(set.begin());
    ++ans;
    int x = p.first, y = p.second;
    if (s[0][x].size() + s[1][x].size() > s[0][y].size() + s[1][y].size())
      std::swap(x, y);
    std::vector<int> v0(s[0][y].begin(), s[0][y].end()),
        v1(s[1][y].begin(), s[1][y].end());
    for (int i : v0)
      del(y, i, 0), ins(x, i, 0);
    for (int i : v1)
      del(y, i, 1), ins(x, i, 1);
    fa[y] = x;
  }
  cout << (ans == n - 1 ? "YES" : "NO") << '\n';
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l), i##end = (r); i <= i##end; ++i)
#define pb insert
using std::cin;
using std::cout;
const int maxn = 200200;
typedef long long ll;
typedef std::pair<int, int> pr;
std::set<int> s[2][maxn];
std::set<std::pair<int, int>> set;
int fa[maxn];
int n, x, y;
inline void ins(int x, int y, int id) {
  if (x != y) {
    s[id][x].emplace(y), s[id][y].emplace(x);
    if (s[!id][x].count(y))
      set.emplace(std::min(x, y), std::max(x, y));
  }
}
inline void del(int x, int y, int id) {
  s[id][x].erase(y), s[id][y].erase(x);
  if (s[!id][x].count(y))
    set.erase(pr(std::min(x, y), std::max(x, y)));
}
inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int main() {
  std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n - 1) cin >> x >> y, ins(x, y, 0);
  rep(i, 1, n - 1) cin >> x >> y, ins(x, y, 1);
  int ans = 0;
  for (; set.size();) {
    pr p = *set.begin();
    set.erase(set.begin());
    ++ans;
    int x = p.first, y = p.second;
    if (s[0][x].size() + s[1][x].size() < s[0][y].size() + s[1][y].size())
      std::swap(x, y);
    std::vector<int> v0(s[0][y].begin(), s[0][y].end()),
        v1(s[1][y].begin(), s[1][y].end());
    for (int i : v0)
      del(y, i, 0), ins(x, i, 0);
    for (int i : v1)
      del(y, i, 1), ins(x, i, 1);
    fa[y] = x;
  }
  cout << (ans == n - 1 ? "YES" : "NO") << '\n';
}
Problem p03727 (C++)

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

#define mp make_pair

int par[101010];

int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }

int main() {
  int n;
  scanf("%d", &n);
  set<int> g[101010];
  queue<pair<int, int>> both;
  for (int i = 0; i < n; i++)
    par[i] = i;
  for (int i = 0; i < 2 * n - 2; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    if (g[a].count(b)) {
      both.emplace(a, b);
      // cout << "both.emplace(" << a << ", " << b << ")" << endl;
    } else {
      g[a].insert(b);
      g[b].insert(a);
    }
  }
  int ans = 0;
  while (!both.empty()) {
    ans++;
    int a, b;
    tie(a, b) = both.front();
    both.pop();
    a = find(a), b = find(b);
    swap(a, b);
    a = par[a], b = par[b];
    if (a == b)
      continue;
    par[b] = a;
    g[a].erase(b);
    g[b].erase(a);
    for (auto c : g[b]) {
      g[c].erase(b);
      if (g[a].count(c)) {
        both.emplace(a, c);
      } else {
        g[a].insert(c);
        g[c].insert(a);
      }
    }
    g[b].clear();
  }
  puts(ans == n - 1 ? "YES" : "NO");
  return 0;
}


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

#define mp make_pair

int par[101010];

int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }

int main() {
  int n;
  scanf("%d", &n);
  set<int> g[101010];
  queue<pair<int, int>> both;
  for (int i = 0; i < n; i++)
    par[i] = i;
  for (int i = 0; i < 2 * n - 2; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    if (g[a].count(b)) {
      both.emplace(a, b);
      // cout << "both.emplace(" << a << ", " << b << ")" << endl;
    } else {
      g[a].insert(b);
      g[b].insert(a);
    }
  }
  int ans = 0;
  while (!both.empty()) {
    ans++;
    int a, b;
    tie(a, b) = both.front();
    both.pop();
    a = find(a), b = find(b);
    // if (g[a].size() < g[b].size()) swap(a, b);
    a = par[a], b = par[b];
    if (a == b)
      continue;
    par[b] = a;
    g[a].erase(b);
    g[b].erase(a);
    for (auto c : g[b]) {
      g[c].erase(b);
      if (g[a].count(c)) {
        both.emplace(a, c);
      } else {
        g[a].insert(c);
        g[c].insert(a);
      }
    }
    g[b].clear();
  }
  puts(ans == n - 1 ? "YES" : "NO");
  return 0;
}
Problem p03727 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <set>
using namespace std;
const int N = 100100;
int i, j, k, n, ch, ff, dn, x, y;
int f[N];
set<int> S[N];
set<int>::iterator it;
struct cc {
  int x, y;
} d[N];
void R(int &x) {
  ff = x = 0;
  ch = getchar();
  while (ch < '0' || '9' < ch)
    ch = getchar();
  while ('0' <= ch && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  if (ff)
    x = -x;
}
int getf(int x) {
  if (f[x] == x)
    return x;
  return f[x] = getf(f[x]);
}
void Add(int x, int y) {
  x = getf(x);
  y = getf(y);
  if (S[x].find(y) != S[x].end()) {
    S[x].erase(y);
    d[++dn].x = x;
    d[dn].y = y;
  } else {
    S[x].insert(y);
    S[y].insert(x);
  }
}
void Merge(int x, int y) {
  x = getf(x);
  y = getf(y);
  if (S[x].size() > S[y].size()) {
    int t = x;
    x = y;
    y = t;
  }
  f[x] = y;
  for (it = S[x].begin(); it != S[x].end(); it++) {
    int t = *it;
    S[t].erase(x);
    Add(t, y);
  }
}
int main() {
  R(n);
  for (i = 1; i < n; i++)
    f[i] = i;
  for (i = 1; i < n; i++) {
    R(x);
    R(y);
    Add(x, y);
  }
  for (i = 1; i < n; i++) {
    R(x);
    R(y);
    Add(x, y);
  }
  for (i = 1; i < n - 1; i++) {
    if (i > dn)
      return puts("NO"), 0;
    Merge(d[i].x, d[i].y);
  }
  puts("YES");
}

Fixed submission:
#include <cstdio>
#include <set>
using namespace std;
const int N = 100100;
int i, j, k, n, ch, ff, dn, x, y;
int f[N];
set<int> S[N];
set<int>::iterator it;
struct cc {
  int x, y;
} d[N];
void R(int &x) {
  ff = x = 0;
  ch = getchar();
  while (ch < '0' || '9' < ch)
    ch = getchar();
  while ('0' <= ch && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  if (ff)
    x = -x;
}
int getf(int x) {
  if (f[x] == x)
    return x;
  return f[x] = getf(f[x]);
}
void Add(int x, int y) {
  x = getf(x);
  y = getf(y);
  if (S[x].find(y) != S[x].end()) {
    S[x].erase(y);
    S[y].erase(x);
    d[++dn].x = x;
    d[dn].y = y;
  } else {
    S[x].insert(y);
    S[y].insert(x);
  }
}
void Merge(int x, int y) {
  x = getf(x);
  y = getf(y);
  if (S[x].size() > S[y].size()) {
    int t = x;
    x = y;
    y = t;
  }
  f[x] = y;
  for (it = S[x].begin(); it != S[x].end(); it++) {
    int t = *it;
    S[t].erase(x);
    Add(t, y);
  }
}
int main() {
  R(n);
  for (i = 1; i < n; i++)
    f[i] = i;
  for (i = 1; i < n; i++) {
    R(x);
    R(y);
    Add(x, y);
  }
  for (i = 1; i < n; i++) {
    R(x);
    R(y);
    Add(x, y);
  }
  for (i = 1; i < n - 1; i++) {
    if (i > dn)
      return puts("NO"), 0;
    Merge(d[i].x, d[i].y);
  }
  puts("YES");
}
Problem p03727 (C++)

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

using namespace std;

const int maxn = 100010;

int n, fa[maxn], sizee[maxn];
set<int> S[maxn];
map<pair<int, int>, int> M;
queue<pair<int, int>> q;

int find(int x) {
  if (x == fa[x])
    return x;
  return fa[x] = find(fa[x]);
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    sizee[i] = 1;
  }
  for (int i = 1; i <= 2 * (n - 1); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x > y)
      swap(x, y);
    S[x].insert(y);
    S[y].insert(x);
    if (M.count(make_pair(x, y)))
      q.push(make_pair(x, y));
    M[make_pair(x, y)] = 1;
  }
  while (n >= 2) {
    n--;
    if (q.empty()) {
      puts("NO");
      exit(0);
    }
    pair<int, int> u = q.front();
    q.pop();
    int x = u.first, y = u.second;
    if (S[x].size() > S[y].size())
      swap(x, y);
    fa[x] = y;
    for (set<int>::iterator it = S[x].begin(); it != S[x].end(); ++it) {
      int v = (*it);
      v = find(v);
      if (v == y)
        continue;
      S[v].insert(y);
      S[y].insert(v);
      if (v > y) {
        if (M.count(make_pair(y, v)))
          q.push(make_pair(y, v));
        M[make_pair(y, v)] = 1;
      } else {
        if (M.count(make_pair(v, y)))
          q.push(make_pair(v, y));
        M[make_pair(v, y)] = 1;
      }
      S[v].erase(S[v].find(x));
    }
    S[y].erase(S[y].find(x));
    S[x].clear();
  }
  puts("YES");

  return 0;
}


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

using namespace std;

const int maxn = 100010;

int n, fa[maxn], sizee[maxn];
set<int> S[maxn];
map<pair<int, int>, int> M;
queue<pair<int, int>> q;

int find(int x) {
  if (x == fa[x])
    return x;
  return fa[x] = find(fa[x]);
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    sizee[i] = 1;
  }
  for (int i = 1; i <= 2 * (n - 1); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x > y)
      swap(x, y);
    S[x].insert(y);
    S[y].insert(x);
    if (M.count(make_pair(x, y)))
      q.push(make_pair(x, y));
    M[make_pair(x, y)] = 1;
  }
  while (n >= 2) {
    n--;
    if (q.empty()) {
      puts("NO");
      exit(0);
    }
    pair<int, int> u = q.front();
    q.pop();
    int x = u.first, y = u.second;
    x = find(x), y = find(y);
    if (S[x].size() > S[y].size())
      swap(x, y);
    fa[x] = y;
    for (set<int>::iterator it = S[x].begin(); it != S[x].end(); ++it) {
      int v = (*it);
      v = find(v);
      if (v == y)
        continue;
      S[v].insert(y);
      S[y].insert(v);
      if (v > y) {
        if (M.count(make_pair(y, v)))
          q.push(make_pair(y, v));
        M[make_pair(y, v)] = 1;
      } else {
        if (M.count(make_pair(v, y)))
          q.push(make_pair(v, y));
        M[make_pair(v, y)] = 1;
      }
      S[v].erase(S[v].find(x));
    }
    S[y].erase(S[y].find(x));
    S[x].clear();
  }
  puts("YES");

  return 0;
}
Problem p03727 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <utility>
#define pii pair<int, int>
#define mkpr make_pair
using namespace std;

const int N = 1e5;
multiset<int> ae[N + 3];
map<pii, int> g;
queue<pii> que;
int n;

void insertedge(int u, int v) {
  if (u == v)
    return;
  if (u > v)
    swap(u, v);
  ae[u].insert(v);
  ae[v].insert(u);
  g[mkpr(u, v)]++;
  if (g[mkpr(u, v)] == 2) {
    que.push(mkpr(u, v));
  }
}

void deleteedge(int u, int v) {
  ae[v].erase(ae[v].find(u));
  if (u > v)
    swap(u, v);
  g[mkpr(u, v)]--;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 2 * (n - 1); i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    insertedge(u, v);
  }
  for (int i = 1; i < n; i++) {
    while (1) {
      if (que.empty()) {
        puts("NO");
        return 0;
      }
      int u = que.front().first, v = que.front().second;
      que.pop();
      if (!g.count(mkpr(u, v))) {
        continue;
      }
      if (ae[u].size() < ae[v].size())
        swap(u, v);
      for (set<int>::iterator i = ae[v].begin(); i != ae[v].end(); i++) {
        int x = *i;
        deleteedge(v, x);
        insertedge(u, x);
      }
      break;
    }
  }
  puts("YES");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <utility>
#define pii pair<int, int>
#define mkpr make_pair
using namespace std;

const int N = 1e5;
multiset<int> ae[N + 3];
map<pii, int> g;
queue<pii> que;
int n;

void insertedge(int u, int v) {
  if (u == v)
    return;
  if (u > v)
    swap(u, v);
  ae[u].insert(v);
  ae[v].insert(u);
  g[mkpr(u, v)]++;
  if (g[mkpr(u, v)] == 2) {
    que.push(mkpr(u, v));
  }
}

void deleteedge(int u, int v) {
  ae[v].erase(ae[v].find(u));
  if (u > v)
    swap(u, v);
  if (g.count(mkpr(u, v))) {
    g.erase(mkpr(u, v));
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 2 * (n - 1); i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    insertedge(u, v);
  }
  for (int i = 1; i < n; i++) {
    while (1) {
      if (que.empty()) {
        puts("NO");
        return 0;
      }
      int u = que.front().first, v = que.front().second;
      que.pop();
      if (!g.count(mkpr(u, v))) {
        continue;
      }
      if (ae[u].size() < ae[v].size())
        swap(u, v);
      for (set<int>::iterator i = ae[v].begin(); i != ae[v].end(); i++) {
        int x = *i;
        deleteedge(v, x);
        insertedge(u, x);
      }
      break;
    }
  }
  puts("YES");
  return 0;
}
Problem p03728 (C++)

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

int n, x, po[100001], f[100001], ans;

bool check(int a, int b, int c) {
  return a < b && b < c || b < c && c < a || c < a && a < b;
}

int main() {
  scanf("%d", &n);
  ans = 0;
  for (int i = 1; i <= n; i++)
    scanf("%d", &x), po[x] = i;
  for (int i = n - 1; i >= 1; i--)
    if (!ans) {
      if (po[i + 1] < po[i])
        ans++, f[i] = i + 1;
    } else if (check(po[i], po[i + 1], po[f[i + 1]]))
      f[i] = f[i + 1];
    else
      f[i] = i + 1, ans++;
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstring>

int n, x, po[200001], f[200001], ans;

bool check(int a, int b, int c) {
  return a < b && b < c || b < c && c < a || c < a && a < b;
}

int main() {
  scanf("%d", &n);
  ans = 0;
  for (int i = 1; i <= n; i++)
    scanf("%d", &x), po[x] = i;
  for (int i = n - 1; i >= 1; i--)
    if (!ans) {
      if (po[i + 1] < po[i])
        ans++, f[i] = i + 1;
    } else if (check(po[i], po[i + 1], po[f[i + 1]]))
      f[i] = f[i + 1];
    else
      f[i] = i + 1, ans++;
  printf("%d\n", ans);
  return 0;
}
Problem p03728 (C++)

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

const int N = 100010;

int a[N], p[N], f[N], ans[N];
int n;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    p[a[i]] = i;
  }
  for (int i = n; i; --i) {
    if (!ans[i + 1]) {
      if (i == n || p[i] < p[i + 1]) {
        continue;
      }
      ans[i] = 1;
      f[i] = i + 1;
      continue;
    }
    if (p[f[i + 1]] < p[i] && p[i] < p[i + 1] ||
        p[i] < p[i + 1] && p[i + 1] < p[f[i + 1]] ||
        p[i + 1] < p[f[i + 1]] && p[f[i + 1]] < p[i]) {
      ans[i] = ans[i + 1];
      f[i] = f[i + 1];
    } else {
      ans[i] = ans[i + 1] + 1;
      f[i] = i + 1;
    }
  }
  return printf("%d\n", ans[1]), 0;
}

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

const int N = 200010;

int a[N], p[N], f[N], ans[N];
int n;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    p[a[i]] = i;
  }
  for (int i = n; i; --i) {
    if (!ans[i + 1]) {
      if (i == n || p[i] < p[i + 1]) {
        continue;
      }
      ans[i] = 1;
      f[i] = i + 1;
      continue;
    }
    if (p[f[i + 1]] < p[i] && p[i] < p[i + 1] ||
        p[i] < p[i + 1] && p[i + 1] < p[f[i + 1]] ||
        p[i + 1] < p[f[i + 1]] && p[f[i + 1]] < p[i]) {
      ans[i] = ans[i + 1];
      f[i] = f[i + 1];
    } else {
      ans[i] = ans[i + 1] + 1;
      f[i] = i + 1;
    }
  }
  return printf("%d\n", ans[1]), 0;
}
Problem p03728 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
#include <iostream>
#define N 100010
using namespace std;
int p[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    p[a] = i;
  }
  int u = n - 1;
  while (u && p[u] < p[u + 1])
    u--;
  if (!u) {
    puts("0");
    return 0;
  }
  int ans = 1, pre = u + 1;
  for (; u; u--) {
    if (p[pre] <= p[u] && p[u] <= p[u + 1])
      continue;
    if (p[u] <= p[u + 1] && p[u + 1] <= p[pre])
      continue;
    if (p[u + 1] <= p[pre] && p[pre] <= p[u])
      continue;
    ans++;
    pre = u + 1;
  }
  printf("%d", ans);
  return 0;
}


Fixed submission:
#include <cstdio>
#include <cstring>
#include <iostream>
#define N 200010
using namespace std;
int p[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    p[a] = i;
  }
  int u = n - 1;
  while (u && p[u] < p[u + 1])
    u--;
  if (!u) {
    puts("0");
    return 0;
  }
  int ans = 1, pre = u + 1;
  for (; u; u--) {
    if (p[pre] <= p[u] && p[u] <= p[u + 1])
      continue;
    if (p[u] <= p[u + 1] && p[u + 1] <= p[pre])
      continue;
    if (p[u + 1] <= p[pre] && p[pre] <= p[u])
      continue;
    ans++;
    pre = u + 1;
  }
  printf("%d", ans);
  return 0;
}
Problem p03728 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a, b) (a > b ? a = b : a)
#define cmax(a, b) (a < b ? a = b : a)
#define mem(a, k) memset(a, k, sizeof(a))
#define lop(i, s, t) for (int i = s; i < (t); ++i)
#define rep(i, s, t) for (int i = s; i <= (t); ++i)
#define dec(i, s, t) for (int i = s; i >= (t); --i)
#define fore(i, v)                                                             \
  for (int i = g[v], d = es[i].d; i; i = es[i].nxt, d = es[i].d)
using namespace std;

#define Pr(f, ...) // fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template <typename T> void read(T &x) {
  x = 0;
  char c;
  for (c = getchar(); !isdigit(c); c = getchar())
    ;
  for (; isdigit(c); c = getchar())
    x = x * 10 + c - '0';
}

const int N = 1e5 + 50;

int n, p[N], f[N], T[N], q[N];

bool chk(int a, int b, int c) {
  return (a < b && b < c) || (b < c && c < a) || (c < a && a < b);
}

int main(int argc, char *argv[]) {
#ifdef CURIOUSCAT
  // freopen("dat.in","r",stdin);
  // freopen("my.out","w",stdout);
#endif
  read(n);
  rep(i, 1, n) {
    read(p[i]);
    q[p[i]] = i;
  }
  T[n] = 0, f[n] = n;
  dec(i, n - 1, 1) {
    if (T[i + 1] == 0) {
      if (q[i] > q[i + 1]) {
        T[i] = 1;
        f[i] = i + 1;
      } else {
        T[i] = 0;
      }
    } else {
      if (chk(q[f[i + 1]], q[i], q[i + 1])) {
        T[i] = T[i + 1];
        f[i] = f[i + 1];
      } else {
        T[i] = T[i + 1] + 1;
        f[i] = i + 1;
      }
    }
  }
  printf("%d\n", T[1]);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a, b) (a > b ? a = b : a)
#define cmax(a, b) (a < b ? a = b : a)
#define mem(a, k) memset(a, k, sizeof(a))
#define lop(i, s, t) for (int i = s; i < (t); ++i)
#define rep(i, s, t) for (int i = s; i <= (t); ++i)
#define dec(i, s, t) for (int i = s; i >= (t); --i)
#define fore(i, v)                                                             \
  for (int i = g[v], d = es[i].d; i; i = es[i].nxt, d = es[i].d)
using namespace std;

#define Pr(f, ...) // fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template <typename T> void read(T &x) {
  x = 0;
  char c;
  for (c = getchar(); !isdigit(c); c = getchar())
    ;
  for (; isdigit(c); c = getchar())
    x = x * 10 + c - '0';
}

const int N = 2e5 + 50;

int n, p[N], f[N], T[N], q[N];

bool chk(int a, int b, int c) {
  return (a < b && b < c) || (b < c && c < a) || (c < a && a < b);
}

int main(int argc, char *argv[]) {
#ifdef CURIOUSCAT
  // freopen("dat.in","r",stdin);
  // freopen("my.out","w",stdout);
#endif
  read(n);
  rep(i, 1, n) {
    read(p[i]);
    q[p[i]] = i;
  }
  T[n] = 0, f[n] = n;
  dec(i, n - 1, 1) {
    if (T[i + 1] == 0) {
      if (q[i] > q[i + 1]) {
        T[i] = 1;
        f[i] = i + 1;
      } else {
        T[i] = 0;
      }
    } else {
      if (chk(q[f[i + 1]], q[i], q[i + 1])) {
        T[i] = T[i + 1];
        f[i] = f[i + 1];
      } else {
        T[i] = T[i + 1] + 1;
        f[i] = i + 1;
      }
    }
  }
  printf("%d\n", T[1]);
  return 0;
}
Problem p03728 (C++)

Buggy submission (status: Runtime Error):
// Love and Freedom.
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#define inf 20021225
#define ll long long
#define N 100010
using namespace std;
int read() {
  int f = 1, s = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = s * 10 + ch - '0', ch = getchar();
  return f * s;
}
int a[N], n, t[N], f[N];
bool check(int x, int y, int z) {
  return (x < y && y < z) || (y < z && z < x) || (z < x && x < y);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[read()] = i;
  for (int i = n - 1; i; i--) {
    if (!t[i + 1]) {
      if (a[i] > a[i + 1])
        t[i] = 1, f[i] = a[i + 1];
    } else {
      if (check(f[i + 1], a[i], a[i + 1]))
        t[i] = t[i + 1], f[i] = f[i + 1];
      else
        t[i] = t[i + 1] + 1, f[i] = a[i + 1];
    }
  }
  printf("%d\n", t[1]);
  return 0;
}

Fixed submission:
// Love and Freedom.
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#define inf 20021225
#define ll long long
#define N 200010
using namespace std;
int read() {
  int f = 1, s = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = s * 10 + ch - '0', ch = getchar();
  return f * s;
}
int a[N], n, t[N], f[N];
bool check(int x, int y, int z) {
  return (x < y && y < z) || (y < z && z < x) || (z < x && x < y);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[read()] = i;
  for (int i = n - 1; i; i--) {
    if (!t[i + 1]) {
      if (a[i] > a[i + 1])
        t[i] = 1, f[i] = a[i + 1];
    } else {
      if (check(f[i + 1], a[i], a[i + 1]))
        t[i] = t[i + 1], f[i] = f[i + 1];
      else
        t[i] = t[i + 1] + 1, f[i] = a[i + 1];
    }
  }
  printf("%d\n", t[1]);
  return 0;
}
Problem p03729 (C++)

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

using namespace std;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) != b.at(0))
    cout << "NO";
  else if (b.at(b.size() - 1 != c.at(0)))
    cout << "NO";
  else
    cout << "YES";
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) != b.at(0))
    cout << "NO";
  else if (b.at(b.size() - 1) != c.at(0))
    cout << "NO";
  else
    cout << "YES";
}
Problem p03729 (C++)

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

using namespace std;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  return a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0];
}

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

using namespace std;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) {
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
}
Problem p03729 (C++)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

  // start
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) == b.at(0) && b.at(a.size() - 1) == c.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  // end

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

  // start
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  // end

  return 0;
}
Problem p03729 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define str string
#define rep(x, y) for (int i = x; i < y; i++)
#define REP(x, y) for (int j = x; j < y; j++)
#define all(x) x.begin(), x.end()
#define int long long
signed main() {
  int N, K;
  char dif = 'A' - 'a';
  str S1, S2, S3;
  cin >> S1 >> S2 >> S3;
  if (S1.at(S1.size()) == S2.at(0) && S2.at(S2.size()) == S3.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define str string
#define rep(x, y) for (int i = x; i < y; i++)
#define REP(x, y) for (int j = x; j < y; j++)
#define all(x) x.begin(), x.end()
#define int long long
signed main() {
  int N, K;
  char dif = 'A' - 'a';
  str S1, S2, S3;
  cin >> S1 >> S2 >> S3;
  if (S1.at(S1.size() - 1) == S2.at(0) && S2.at(S2.size() - 1) == S3.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
Problem p03729 (C++)

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size()) == b.at(0) && b.at(b.size()) == c.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
Problem p03729 (C++)

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  int D = A.size();
  int E = B.size();
  if (A.at(D) == B.at(0) && B.at(E) == C.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  int D = A.size() - 1;
  int E = B.size() - 1;
  if (A.at(D) == B.at(0) && B.at(E) == C.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
Problem p03729 (C++)

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  string k = "NO";
  if (a.at(a.size() - 1) == b.at(0) && a.at(b.size() - 1) == c.at(0)) {
    k = "YES";
  }
  cout << k << endl;
}


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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  string k = "NO";
  if (a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0)) {
    k = "YES";
  }
  cout << k << endl;
}
Problem p03729 (C++)

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(sizeof(a) - 1) == b.at(0) && b.at(sizeof(b) - 1) == c.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
Problem p03729 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif
  string a, b, c;
  cin >> a >> b >> c;
  int d = a.length();
  int e = b.length();
  // int f = a.length();
  // cout<<a.at(d-1);

  if (a.at(d - 1) == b.at(0) && b.at(e - 1) == c.at(0)) {
    cout << "YES"
         << "\n";
  } else {
    cout << "NO"
         << "\n";
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  // #ifndef ONLINE_JUDGE
  // 	// for getting input from input.txt
  // 	freopen("input.txt", "r", stdin);
  // 	// for writing output to output.txt
  // 	freopen("output.txt", "w", stdout);
  // #endif
  string a, b, c;
  cin >> a >> b >> c;
  int d = a.length();
  int e = b.length();
  // int f = a.length();
  // cout<<a.at(d-1);

  if (a.at(d - 1) == b.at(0) && b.at(e - 1) == c.at(0)) {
    cout << "YES"
         << "\n";
  } else {
    cout << "NO"
         << "\n";
  }

  return 0;
}
Problem p03729 (C++)

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

int main() {

  string A, B, C;
  cin >> A >> B >> C;
  if (A.at(A.length()) == B.at(0) && B.at(B.length()) == C.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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

int main() {

  string A, B, C;
  cin >> A >> B >> C;
  if (A.at(A.length() - 1) == B.at(0) && B.at(B.length() - 1) == C.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
Problem p03729 (Python)

Buggy submission (status: Runtime Error):
import sys

readline = sys.stdin.readline
MOD = 10**9 + 7
INF = float("INF")
sys.setrecursionlimit(10**5)


def main():
    A, B, C = map(int, readline().split())

    if A[-1] == B[0] and B[-1] == C[0]:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()


Fixed submission:
import sys

readline = sys.stdin.readline
MOD = 10**9 + 7
INF = float("INF")
sys.setrecursionlimit(10**5)


def main():
    A, B, C = input().split()

    if A[-1] == B[0] and B[-1] == C[0]:
        print("YES")
    else:
        print("NO")


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

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) == b.at(0) && b.at(a.size() - 1) == c.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
Problem p03729 (C++)

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

using namespace std;

#define PI 3.1415926535897932

int main() {
  int mod = 1000000007;
  int n, m;
  char a[10], b[10], c[10];
  scanf("%s %s %s", a, b, c);
  printf("%s\n", a[strlen(a)] == b[0] && b[strlen(b)] == c[0] ? 'YES' : 'NO');
  return 0;
}


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

using namespace std;

#define PI 3.1415926535897932

int main() {
  int mod = 1000000007;
  int n, m;
  char a[10], b[10], c[10];
  scanf("%s %s %s", a, b, c);
  printf("%s\n",
         a[strlen(a) - 1] == b[0] && b[strlen(b) - 1] == c[0] ? "YES" : "NO");
  return 0;
}
Problem p03729 (C++)

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

int main() {
  // 入力
  string A, B, C;
  cin >> A >> B >> C;

  // 出力
  if (A.at(A.size() - 1) == B.at(0) && A.at(B.size() - 1) == C.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

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

int main() {
  // 入力
  string A, B, C;
  cin >> A >> B >> C;

  // 出力
  if (A.at(A.size() - 1) == B.at(0) && B.at(B.size() - 1) == C.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
Problem p03729 (C++)

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(1))
    cout << "YES" << endl;
  else {
    cout << "NO" << endl;
  }
  return 0;
}

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0))
    cout << "YES" << endl;
  else {
    cout << "NO" << endl;
  }
  return 0;
}
Problem p03729 (C++)

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;

  int a = A.size(), b = B.size();

  if (A.at(a) == B.at(0) && B.at(b) == C.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;

  int a = A.size(), b = B.size();

  if (A.at(a - 1) == B.at(0) && B.at(b - 1) == C.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
Problem p03729 (C++)

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

int main() {
  string A, B, C;
  if (A.at(A.size()) == B.at(0) && B.at(B.size()) == C.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  if (A.at(A.size() - 1) == B.at(0) && B.at(B.size() - 1) == C.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
Problem p03729 (C++)

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

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

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;

  if (s1.substr(s1.length() - 1, 1) == s2.substr(0, 1) &&
      s2.substr(s1.length() - 1, 1) == s3.substr(0, 1) &&
      s3.substr(s1.length() - 1, 1) == s1.substr(0, 1))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Fixed submission:
#include <iostream>

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

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;

  if (s1.substr(s1.length() - 1, 1) == s2.substr(0, 1) &&
      s2.substr(s2.length() - 1, 1) == s3.substr(0, 1))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
Problem p03729 (C++)

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  int an = a.size() - 1, bn = b.size() - 1, cn = c.size() - 1;
  if (a.at(an) != b.at(0)) {
    cout << "NO" << endl;
  } else if (a.at(bn) != c.at(0)) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }

  return 0;
}


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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  int an = a.size() - 1, bn = b.size() - 1, cn = c.size() - 1;
  if (a.at(an) != b.at(0)) {
    cout << "NO" << endl;
  } else if (b.at(bn) != c.at(0)) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }

  return 0;
}
Problem p03729 (C++)

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) == b.at(1)) {
    if (b.at(b.size() - 1) == c.at(1)) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) == b.at(0)) {
    if (b.at(b.size() - 1) == c.at(0)) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}
Problem p03729 (C++)

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) == b.at(0) && b.at(b.size()) == b.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
Problem p03729 (C++)

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

#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
const int MOD = 1e9 + 7;

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  if (A.at(A.size()) == B.at(0) && B.at(B.size()) == C.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

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

#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
const int MOD = 1e9 + 7;

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  if (A.at(A.size() - 1) == B.at(0) && B.at(B.size() - 1) == C.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
Problem p03729 (C++)

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

int main() {
  string a, b, c;
  int i1, i2;
  i1 = a.size() - 1;
  i2 = b.size() - 1;
  if (a.at(i1) == b.at(0) && b.at(i2) == c.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  int i1, i2;
  i1 = a.size() - 1;
  i2 = b.size() - 1;
  if (a.at(i1) == b.at(0) && b.at(i2) == c.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
Problem p03729 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9 + 7)
#define INF (1LL << 60) // 1LL<<63でオーバーフロー
#define inf (1 << 29)   // 1<<29でオーバーフロー

int main(int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);

  string a, b, c;
  cin >> a >> b >> c;

  bool ans = false;
  if (a.at(a.size() - 1) == b[0] && b.at(b.size()) == c[0])
    ans = true;

  if (ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9 + 7)
#define INF (1LL << 60) // 1LL<<63でオーバーフロー
#define inf (1 << 29)   // 1<<29でオーバーフロー

int main(int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);

  string a, b, c;
  cin >> a >> b >> c;

  bool ans = false;
  if (a.at(a.size() - 1) == b[0] && b.at(b.size() - 1) == c[0])
    ans = true;

  if (ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}
Problem p03729 (C++)

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) == b.at(0) && b.at(a.size() - 1) == c.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}