prithivMLmods/Coder-Stat huggingface dataset:
Problem p03256 (Python)

Buggy submission (status: Time Limit Exceeded):
import sys

sys.setrecursionlimit(200000)


def add_link(a, b):
    la = links[a]
    i, j = [(0, 1), (1, 0)][s[b] == "B"]
    if not la[i] and la[j]:
        able[a] = True
    la[i].add(b)


def close(v, i):
    j = int(s[v] == "B")
    for u in links[v][i].copy():
        if not able[u]:
            continue
        links[u][j].discard(v)
        if not links[u][j]:
            able[u] = False
            close(u, j ^ 1)


n, m = map(int, input().split())
s = input()
links = [[set(), set()] for _ in range(n)]
able = [False] * n
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    add_link(a, b)
    add_link(b, a)

for v in range(n):
    if able[v]:
        continue
    close(v, bool(links[v][1]))

print("Yes" if any(able) else "No")


Fixed submission:
import sys

sys.setrecursionlimit(200000)


def add_link(a, b):
    la = links[a]
    i, j = [(0, 1), (1, 0)][s[b] == "B"]
    if not la[i] and la[j]:
        able[a] = True
    la[i].add(b)


def close(v, i):
    j = int(s[v] == "B")
    for u in links[v][i].copy():
        if not able[u]:
            continue
        links[u][j].discard(v)
        if not links[u][j]:
            able[u] = False
            close(u, j ^ 1)


n, m = map(int, input().split())
s = input()
links = [[set(), set()] for _ in range(n)]
able = [False] * n
for line in sys.stdin.readlines():
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    add_link(a, b)
    add_link(b, a)

for v in range(n):
    if able[v]:
        continue
    close(v, bool(links[v][1]))

print("Yes" if any(able) else "No")
Problem p03256 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define for1(a, b, i) for (int i = a; i <= b; ++i)
#define FOR2(a, b, i) for (int i = a; i >= b; --i)
using namespace std;
typedef long long ll;
inline int read() {
  int f = 1, sum = 0;
  char x = getchar();
  for (; (x < '0' || x > '9'); x = getchar())
    if (x == '-')
      f = -1;
  for (; x >= '0' && x <= '9'; x = getchar())
    sum = sum * 10 + x - '0';
  return f * sum;
}

#define M 200005
int n, m;
char s[M];
int e_size, head[M], vis[M];

struct node {
  int v, nxt;
} e[M * 2];

inline void e_add(int u, int v) {
  e[++e_size] = (node){v, head[u]};
  head[u] = e_size;
}

inline void dfs(int x) {
  vis[x] = 1;
  for (int i = head[x]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (vis[v] == 1) {
      puts("Yes");
      exit(0);
    }
    if (vis[v] == 0)
      dfs(v);
  }
  vis[x] = -1;
}

int main() {
  //	freopen("a.in","r",stdin);
  n = read(), m = read();
  scanf("%s", s + 1);
  for1(1, m, i) {
    int x = read(), y = read();
    if (s[x] == s[y])
      e_add(x, y + n), e_add(y, x + n);
    else
      e_add(x + n, y), e_add(y + n, x);
  }
  for1(1, n, i) if (!vis[i]) dfs(i);
  puts("No");
}

Fixed submission:
#include <bits/stdc++.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define for1(a, b, i) for (int i = a; i <= b; ++i)
#define FOR2(a, b, i) for (int i = a; i >= b; --i)
using namespace std;
typedef long long ll;
inline int read() {
  int f = 1, sum = 0;
  char x = getchar();
  for (; (x < '0' || x > '9'); x = getchar())
    if (x == '-')
      f = -1;
  for (; x >= '0' && x <= '9'; x = getchar())
    sum = sum * 10 + x - '0';
  return f * sum;
}

#define M 1000005
int n, m;
char s[M];
int e_size, head[M], vis[M];

struct node {
  int v, nxt;
} e[M * 2];

inline void e_add(int u, int v) {
  e[++e_size] = (node){v, head[u]};
  head[u] = e_size;
}

inline void dfs(int x) {
  vis[x] = 1;
  for (int i = head[x]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (vis[v] == 1) {
      puts("Yes");
      exit(0);
    }
    if (vis[v] == 0)
      dfs(v);
  }
  vis[x] = -1;
}

int main() {
  //	freopen("a.in","r",stdin);
  n = read(), m = read();
  scanf("%s", s + 1);
  for1(1, m, i) {
    int x = read(), y = read();
    if (s[x] == s[y])
      e_add(x, y + n), e_add(y, x + n);
    else
      e_add(x + n, y), e_add(y + n, x);
  }
  for1(1, n, i) if (!vis[i]) dfs(i);
  puts("No");
}
Problem p03256 (C++)

Buggy submission (status: Runtime Error):
// https://agc027.contest.atcoder.jp/tasks/agc027_c

#include <bits/stdc++.h>
const int N = 1e5 + 5;
using namespace std;

queue<int> mq;
vector<int> adj[N];
int n, m, cnt[N][2], num;
string s;
bool dead[N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  cin >> s;
  s = '.' + s;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    cnt[u][s[v] - 'A']++;
    adj[v].push_back(u);
    cnt[v][s[u] - 'A']++;
  }
  for (int u = 1; u <= n; u++) {
    if (!cnt[u][0] || !cnt[u][1]) {
      mq.push(u);
      dead[u] = true;
    }
  }
  while (mq.size()) {
    int u = mq.front();
    mq.pop();
    num++;
    for (auto v : adj[u]) {
      if (dead[v])
        continue;
      cnt[v][s[u] - 'A']--;
      if (!cnt[v][s[u] - 'A']) {
        mq.push(v);
        dead[v] = true;
      }
    }
  }
  cout << ((num == n) ? "No" : "Yes");
}


Fixed submission:
// https://agc027.contest.atcoder.jp/tasks/agc027_c

#include <bits/stdc++.h>
const int N = 2e5 + 5;
using namespace std;

queue<int> mq;
vector<int> adj[N];
int n, m, cnt[N][2], num;
string s;
bool dead[N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  cin >> s;
  s = '.' + s;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    cnt[u][s[v] - 'A']++;
    adj[v].push_back(u);
    cnt[v][s[u] - 'A']++;
  }
  for (int u = 1; u <= n; u++) {
    if (!cnt[u][0] || !cnt[u][1]) {
      mq.push(u);
      dead[u] = true;
    }
  }
  while (mq.size()) {
    int u = mq.front();
    mq.pop();
    num++;
    for (auto v : adj[u]) {
      if (dead[v])
        continue;
      cnt[v][s[u] - 'A']--;
      if (!cnt[v][s[u] - 'A']) {
        mq.push(v);
        dead[v] = true;
      }
    }
  }
  cout << ((num == n) ? "No" : "Yes");
}
Problem p03256 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
const int N = 200005, M = N * 2;
int a[N];
int en = 0, to[M], nxt[M], h[N];
void addedge(int u, int v) { to[++en] = v, nxt[en] = h[u], h[u] = en; }
int du[2][N];
int n, m;
int iff[N], cnt = 0;
queue<int> q;

int main() {
  freopen("input.txt", "r", stdin);
  cin >> n >> m;
  char ch = getchar();
  while (ch != 'A' && ch != 'B') {
    ch = getchar();
  }
  a[1] = ch == 'A';
  for (int i = 2; i <= n; i++) {
    a[i] = getchar() == 'A';
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    du[a[v]][u]++;
    du[a[u]][v]++;
    addedge(u, v);
    addedge(v, u);
  }
  for (int i = 1; i <= n; i++) {
    if (!du[0][i] || !du[1][i])
      q.push(i), iff[i] = 1, cnt++;
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = h[u]; i; i = nxt[i]) {
      int v = to[i];
      du[a[u]][v]--;
      if (iff[v])
        continue;
      if (!du[a[u]][v] && !iff[v]) {
        q.push(v);
        iff[v] = 1;
        cnt++;
      }
    }
  }
  if (cnt < n) {
    cout << "Yes";
  } else
    cout << "No";
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
const int N = 200005, M = N * 2;
int a[N];
int en = 0, to[M], nxt[M], h[N];
void addedge(int u, int v) { to[++en] = v, nxt[en] = h[u], h[u] = en; }
int du[2][N];
int n, m;
int iff[N], cnt = 0;
queue<int> q;

int main() {
  // freopen("input.txt","r",stdin);
  cin >> n >> m;
  char ch = getchar();
  while (ch != 'A' && ch != 'B') {
    ch = getchar();
  }
  a[1] = ch == 'A';
  for (int i = 2; i <= n; i++) {
    a[i] = getchar() == 'A';
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    du[a[v]][u]++;
    du[a[u]][v]++;
    addedge(u, v);
    addedge(v, u);
  }
  for (int i = 1; i <= n; i++) {
    if (!du[0][i] || !du[1][i])
      q.push(i), iff[i] = 1, cnt++;
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = h[u]; i; i = nxt[i]) {
      int v = to[i];
      du[a[u]][v]--;
      if (iff[v])
        continue;
      if (!du[a[u]][v] && !iff[v]) {
        q.push(v);
        iff[v] = 1;
        cnt++;
      }
    }
  }
  if (cnt < n) {
    cout << "Yes";
  } else
    cout << "No";
  return 0;
}
Problem p03257 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
typedef long long ll;
const int N = 20005;
set<ll> st;
int n, i, j, k, p[N], l, w1[N], w2[N];
bool v[N];
ll a[505][505];
ll gcd(ll a, ll b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
ll LCM(ll a, ll b, ll c, ll d) {
  ll rtn = a / gcd(a, b) * b;
  rtn = rtn / gcd(rtn, c) * c;
  rtn = rtn / gcd(rtn, d) * d;
  return rtn;
}
int main() {
  scanf("%d", &n);
  for (i = 2; i <= 20000; ++i) {
    if (!v[i])
      p[++l] = i;
    for (j = 1; j <= l && p[j] * i <= 20000; ++j) {
      v[p[j] * i] = true;
      if (i % p[j] == 0)
        break;
    }
  }
  for (i = 1; i <= n; ++i)
    w1[i] = p[i];
  for (i = 1; i <= n; ++i)
    w2[i] = p[n + i];
  random_shuffle(w1 + 1, w1 + 1 + n);
  random_shuffle(w2 + 1, w2 + 1 + n);
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= n; ++j)
      if ((i + j) % 2 == 0)
        a[i][j] = w1[(i + j) / 2] * w2[(i - j + n) / 2];
  for (i = 0; i <= n + 1; ++i)
    a[0][i] = a[n + 1][i] = a[i][0] = a[i][n + 1] = 1;
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= n; ++j)
      if ((i + j) & 1) {
        a[i][j] = LCM(a[i - 1][j], a[i + 1][j], a[i][j - 1], a[i][j + 1]) + 1;
        while (st.count(a[i][j]))
          a[i][j] += LCM(a[i - 1][j], a[i + 1][j], a[i][j - 1], a[i][j + 1]);
        st.insert(a[i][j]);
      }
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= n; ++j)
      printf("%lld ", a[i][j]);
    puts("");
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
typedef long long ll;
const int N = 20005;
set<ll> st;
int n, i, j, k, p[N], l, w1[N], w2[N];
bool v[N];
ll a[505][505];
ll gcd(ll a, ll b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
ll LCM(ll a, ll b, ll c, ll d) {
  ll rtn = a / gcd(a, b) * b;
  rtn = rtn / gcd(rtn, c) * c;
  rtn = rtn / gcd(rtn, d) * d;
  return rtn;
}
int main() {
  scanf("%d", &n);
  for (i = 2; i <= 20000; ++i) {
    if (!v[i])
      p[++l] = i;
    for (j = 1; j <= l && p[j] * i <= 20000; ++j) {
      v[p[j] * i] = true;
      if (i % p[j] == 0)
        break;
    }
  }
  for (i = 1; i <= n; ++i)
    w1[i] = p[i];
  for (i = 1; i <= n; ++i)
    w2[i] = p[n + i];
  random_shuffle(w1 + 1, w1 + 1 + n);
  random_shuffle(w2 + 1, w2 + 1 + n);
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= n; ++j)
      if ((i + j) % 2 == 0)
        a[i][j] = w1[(i + j) / 2] * w2[(i - j + n + 1) / 2];
  for (i = 0; i <= n + 1; ++i)
    a[0][i] = a[n + 1][i] = a[i][0] = a[i][n + 1] = 1;
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= n; ++j)
      if ((i + j) & 1) {
        a[i][j] = LCM(a[i - 1][j], a[i + 1][j], a[i][j - 1], a[i][j + 1]) + 1;
        while (st.count(a[i][j]))
          a[i][j] += LCM(a[i - 1][j], a[i + 1][j], a[i][j - 1], a[i][j + 1]);
        st.insert(a[i][j]);
      }
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= n; ++j)
      printf("%lld ", a[i][j]);
    puts("");
  }
  return 0;
}
Problem p03257 (C++)

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

const int MAXN = 510;
typedef long long LL;
int pri[MAXN], bak, n;
int ispri(int x) {
  for (int i = 2; i * i <= x; ++i)
    if (x % i == 0)
      return false;
  return true;
}
LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
LL get(int x, int y) {
  if (x < 1 || y < 1 || x > n || y > n)
    return 1;
  if ((x & 1) == (y & 1))
    return pri[x + y >> 1] * pri[x + n * 3 - y + 1 >> 1];
  return lcm(lcm(get(x - 1, y), get(x, y - 1)),
             lcm(get(x + 1, y), get(x, y + 1))) +
         1;
}
int main() {
  std::ios_base::sync_with_stdio(false), std::cin.tie(0);
  std::cin >> n;
  n += 2;
  int now = 2;
  while (bak < n * 2) {
    if (ispri(now))
      pri[++bak] = now;
    ++now;
  }
  for (int i = 2; i < n; ++i, std::cout << '\n')
    for (int j = 2; j < n; ++j)
      std::cout << get(i, j) << ' ';
  return 0;
}


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

const int MAXN = 1010;
typedef long long LL;
int pri[MAXN], bak, n;
int ispri(int x) {
  for (int i = 2; i * i <= x; ++i)
    if (x % i == 0)
      return false;
  return true;
}
LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
LL get(int x, int y) {
  if (x < 1 || y < 1 || x > n || y > n)
    return 1;
  if ((x & 1) == (y & 1))
    return pri[x + y >> 1] * pri[x + n * 3 - y + 1 >> 1];
  return lcm(lcm(get(x - 1, y), get(x, y - 1)),
             lcm(get(x + 1, y), get(x, y + 1))) +
         1;
}
int main() {
  std::ios_base::sync_with_stdio(false), std::cin.tie(0);
  std::cin >> n;
  n += 2;
  int now = 2;
  while (bak < n * 2) {
    if (ispri(now))
      pri[++bak] = now;
    ++now;
  }
  for (int i = 2; i < n; ++i, std::cout << '\n')
    for (int j = 2; j < n; ++j)
      std::cout << get(i, j) << ' ';
  return 0;
}
Problem p03257 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#define ll long long
using namespace std;
const int N = 510, MX = 1e6;
int p[25010];
int vis[MX];
ll rec[N][N];
int n, m, cnt;
void prework(int n) {
  vis[1] = false;
  int cnt = 0;
  for (int i = 2; cnt < n; ++i) {
    if (!vis[i])
      p[++cnt] = i;
    for (int j = 1; j <= cnt && i * p[j] < MX; ++j) {
      vis[i * p[j]] = 1;
      if (i % p[j] == 0)
        break;
    }
  }
}
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) {
  if (!x || !y)
    return x + y;
  return x / gcd(x, y) * y;
}
void solve() {
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if ((i + j) % 2 == 0)
        rec[i][j] = 1LL * p[(i + j) / 2] * p[n + (i - j) / 2 + (n + 1) / 2];
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (!rec[i][j])
        rec[i][j] = lcm(lcm(rec[i - 1][j], rec[i][j + 1]),
                        lcm(rec[i + 1][j], rec[i][j - 1])) +
                    1;
}

int main() {
#ifndef ONLINE_JUDGE
  // freopen("a.in","r",stdin);
#endif
  ll tmp;
  scanf("%d", &n);
  if (n == 2) {
    printf("%d %d\n%d %d\n", 4, 7, 23, 10);
    return 0;
  }
  prework(n * n);
  solve();
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j)
      printf("%lld ", rec[i][j]);
    printf("\n");
  }
}

Fixed submission:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#define ll long long
using namespace std;
const int N = 510, MX = 1e7;
int p[250010];
int vis[MX];
ll rec[N][N];
int n, m, cnt;
void prework(int n) {
  vis[1] = false;
  int cnt = 0;
  for (int i = 2; cnt < n; ++i) {
    if (!vis[i])
      p[++cnt] = i;
    for (int j = 1; j <= cnt && i * p[j] < MX; ++j) {
      vis[i * p[j]] = 1;
      if (i % p[j] == 0)
        break;
    }
  }
}
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) {
  if (!x || !y)
    return x + y;
  return x / gcd(x, y) * y;
}
void solve() {
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if ((i + j) % 2 == 0)
        rec[i][j] = 1LL * p[(i + j) / 2] * p[n + (i - j) / 2 + (n + 1) / 2];
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (!rec[i][j])
        rec[i][j] = lcm(lcm(rec[i - 1][j], rec[i][j + 1]),
                        lcm(rec[i + 1][j], rec[i][j - 1])) +
                    1;
}

int main() {
#ifndef ONLINE_JUDGE
  // freopen("a.in","r",stdin);
#endif
  ll tmp;
  scanf("%d", &n);
  if (n == 2) {
    printf("%d %d\n%d %d\n", 4, 7, 23, 10);
    return 0;
  }
  prework(n * n);
  solve();
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j)
      printf("%lld ", rec[i][j]);
    printf("\n");
  }
}
Problem p03258 (C++)

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

const int MOD = 1e9 + 7;
const int N = 3e5;
char st[N];
int F[N], nxt[N];
int su, ans, n;
void ADD(int &t, int d) {
  t += d;
  if (t >= MOD)
    t -= MOD;
}
int main() {
  scanf("%s", st + 1);
  n = strlen(st + 1);
  for (int i = 1, j = 1; i <= n; ++i) {
    j = max(j, i);
    while (j < n && st[j + 1] != st[j])
      j++;
    for (int k = i; k <= j; ++k)
      nxt[k] = j;
  }
  if (nxt[1] == n) {
    printf("%d\n", 1);
    return 0;
  }
  F[0] = 1;
  for (int i = 1; i <= n; ++i) {
    ADD(F[i], F[i - 1]);
    ADD(F[nxt[i] + 1], F[i - 1]);
  }
  for (int i = n, su = 0; i >= 1; --i) {
    if (su % 3 == 0)
      ADD(ans, F[i]);
    su += st[i] - 'a' + 1;
  }
  printf("%d\n", ans);
}


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

const int MOD = 1e9 + 7;
const int N = 3e5;
char st[N];
int F[N], nxt[N];
int su, ans, n;
void ADD(int &t, int d) {
  t += d;
  if (t >= MOD)
    t -= MOD;
}
int main() {
  scanf("%s", st + 1);
  n = strlen(st + 1);
  for (int i = 1, j = 1; i <= n; ++i) {
    j = max(j, i);
    while (j < n && st[j + 1] != st[j])
      j++;
    for (int k = i; k <= j; ++k)
      nxt[k] = j;
    i = j;
  }
  if (nxt[1] == n) {
    printf("%d\n", 1);
    return 0;
  }
  F[0] = 1;
  for (int i = 1; i <= n; ++i) {
    ADD(F[i], F[i - 1]);
    ADD(F[nxt[i] + 1], F[i - 1]);
  }
  for (int i = n, su = 0; i >= 1; --i) {
    if (su % 3 == 0)
      ADD(ans, F[i]);
    su += st[i] - 'a' + 1;
  }
  printf("%d\n", ans);
}
Problem p03258 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iostream>
#include <map>
#include <random>
#include <set>
#include <string>

using namespace std;

typedef long long ll;

const ll MODULO = 1e9 + 7;

map<vector<int>, ll> ans;
ll Solve(int at, int sum, int want, int len, int was, const vector<int> &a) {
  if (at == a.size()) {
    if (sum == want)
      return 1;
    return 0;
  }

  vector<int> state = {at, sum, want, len, was};
  for (int x : state)
    cerr << x << " ";
  cerr << endl;
  if (ans.count(state))
    return ans[state];

  ll &result = ans[state];

  result = 0;

  if (sum == want && want != 0 && (len == 1 || was)) {
    for (int w = 0; w < 3; ++w)
      result = (result + Solve(at, 0, w, 0, 0, a)) % MODULO;
    return result;
  }

  int newLen = min(len + 1, 2);
  int newWas = was;
  if (len != 0)
    newWas |= (a[at] == a[at - 1]);
  int newSum = (sum + a[at]) % 3;

  result = (result + Solve(at + 1, newSum, want, newLen, newWas, a)) % MODULO;

  return result;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  bool found = false;
  for (int i = 0; i < n - 1; ++i)
    if (s[i] == s[i + 1])
      found = true;
  if (!found) {
    cout << 1 << endl;
    return 0;
  }
  vector<int> a(n, 1);
  for (int i = 0; i < n; ++i)
    if (s[i] == 'b')
      a[i] = 2;
  ll result = (Solve(0, 0, 1, 0, 0, a) + Solve(0, 0, 2, 0, 0, a)) % MODULO;
  cout << result << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iostream>
#include <map>
#include <random>
#include <set>
#include <string>

using namespace std;

typedef long long ll;

const ll MODULO = 1e9 + 7;

map<vector<int>, ll> ans;
ll Solve(int at, int sum, int want, int len, int was, const vector<int> &a) {
  if (at == a.size()) {
    if (sum == want)
      return 1;
    return 0;
  }

  vector<int> state = {at, sum, want, len, was};
  if (ans.count(state))
    return ans[state];

  ll &result = ans[state];

  result = 0;

  if (sum == want && want != 0 && (len == 1 || was)) {
    for (int w = 0; w < 3; ++w)
      result = (result + Solve(at, 0, w, 0, 0, a)) % MODULO;
    return result;
  }

  int newLen = min(len + 1, 2);
  int newWas = was;
  if (len != 0)
    newWas |= (a[at] == a[at - 1]);
  int newSum = (sum + a[at]) % 3;

  result = (result + Solve(at + 1, newSum, want, newLen, newWas, a)) % MODULO;

  return result;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  bool found = false;
  for (int i = 0; i < n - 1; ++i)
    if (s[i] == s[i + 1])
      found = true;
  if (!found) {
    cout << 1 << endl;
    return 0;
  }
  vector<int> a(n, 1);
  for (int i = 0; i < n; ++i)
    if (s[i] == 'b')
      a[i] = 2;
  ll result = (Solve(0, 0, 1, 0, 0, a) + Solve(0, 0, 2, 0, 0, a)) % MODULO;
  cout << result << endl;
  return 0;
}
Problem p03260 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  int n;
  string w[100];
  cin >> n >> w[100];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (w[j] != w[i]) {
      } else {
        cout << "No" << endl;
        return 0;
      }
    }
    if (i > 0) {
      if (w[i][0] == w[i - 1].size()) {
      } else {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  int a, b;
  cin >> a >> b;
  if (a % 2 == 1 && b % 2 == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}
Problem p03260 (Python)

Buggy submission (status: Runtime Error):
a, b = map(int, input().slice())
if a == 2 or b == 2:
    print("No")
else:
    print("Yes")


Fixed submission:
a, b = map(int, input().split())
if a == 2 or b == 2:
    print("No")
else:
    print("Yes")
Problem p03260 (C++)

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

typedef long long ll;

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#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
  ll a, b;
  cin >> a >> b;
  if (a % 2 == 0 || b % 2 == 0) {
    cout << "No";
  } else {
    cout << "Yes";
  }
  return 0;
}

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

typedef long long ll;

using namespace std;

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

  ll a, b;
  cin >> a >> b;
  if (a % 2 == 0 || b % 2 == 0) {
    cout << "No";
  } else {
    cout << "Yes";
  }
  return 0;
}
Problem p03261 (C++)

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

int saisho(string a) {
  char c;
  c = a.at(0);
  return c;
}

int matubi(string a) {
  char c;
  int s;
  s = a.size();
  c = a.at(s - 1);
  return c;
}

int main() {
  int N;
  cin >> N;
  vector<string> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  bool decide = true;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; i++) {
      if (A.at(i) == A.at(j))
        decide = false;
    }
  }

  for (int i = 0; i < N - 1; i++) {
    char c1 = matubi(A.at(i));
    char c2 = saisho(A.at(i + 1));
    if (c1 == c2) {
    } else {
      decide = false;
    }
  }

  if (decide) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


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

int saisho(string a) {
  char c;
  c = a.at(0);
  return c;
}

int matubi(string a) {
  char c;
  int s;
  s = a.size();
  c = a.at(s - 1);
  return c;
}

int main() {
  int N;
  cin >> N;
  vector<string> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  bool decide = true;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      if (A.at(i) == A.at(j))
        decide = false;
    }
  }

  for (int i = 0; i < N - 1; i++) {
    char c1 = matubi(A.at(i));
    char c2 = saisho(A.at(i + 1));
    if (c1 == c2) {
    } else {
      decide = false;
    }
  }

  if (decide) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}
Problem p03261 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<string> S(n);
  for (int i = 0; i < n; i++) {
    cin >> S.at(i);
  }

  bool flag = true;
  // 末尾と次の語の頭文字を比較
  for (int i = 0; i < n - 1; i++) {
    if (S.at(i).at(S.size() - 1) == S.at(i + 1).at(0)) {
      flag = true;
    } else {
      flag = false;
      break;
    }
  }

  // flag = trueの場合、言葉にダブりがないかを確認
  if (flag) {
    sort(S.begin(), S.end());
    for (int i = 0; i < n - 1; i++) {
      if (S.at(i) == S.at(i + 1)) {
        flag = false;
        break;
      }
    }
  }

  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<string> S(n);
  for (int i = 0; i < n; i++) {
    cin >> S.at(i);
  }

  bool flag = true;
  // 末尾と次の語の頭文字を比較
  for (int i = 0; i < n - 1; i++) {
    if (S.at(i).at(S.at(i).size() - 1) == S.at(i + 1).at(0)) {
      flag = true;
    } else {
      flag = false;
      break;
    }
  }

  // flag = trueの場合、言葉にダブりがないかを確認
  if (flag) {
    sort(S.begin(), S.end());
    for (int i = 0; i < n - 1; i++) {
      if (S.at(i) == S.at(i + 1)) {
        flag = false;
        break;
      }
    }
  }

  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03261 (C++)

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

int main(int argc, char **argv) {

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

  for (int i = 0; i < n; i++) {
    if (i == 0) {
      //
    } else if (s[i - 1].back() != s[i].front()) {
      cout << "No" << endl;
      return 0;
    }
  }

  sort(s, s + n);

  for (int i = 0; i < n; i++) {
    if (i == 0) {
      //
    }
    if (s[i - 1] == s[i]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


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

int main(int argc, char **argv) {

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

  for (int i = 0; i < n; i++) {
    if (i == 0) {
      //
    } else if (s[i - 1].back() != s[i].front()) {
      cout << "No" << endl;
      return 0;
    }
  }

  sort(s, s + n);

  for (int i = 0; i < n; i++) {
    if (i == 0) {
      //
    } else if (s[i - 1] == s[i]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  int a;
  cin >> a;
  string b[a];
  for (int i = 0; i < a; i++) {
    cin >> b[i];
  }
  for (int i = 1; i < a; i++) {
    if (b[i - 1][b[i - 1].size() - 1] != b[i][0]) {
      cout << "No" << endl;
      return 0;
    }
    for (int j = 0; j < a; j++) {
      if (b[i - 1] == b[i + j]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  int a;
  cin >> a;
  string b[a];
  for (int i = 0; i < a; i++) {
    cin >> b[i];
  }
  for (int i = 1; i < a; i++) {
    if (b[i - 1][b[i - 1].size() - 1] != b[i][0]) {
      cout << "No" << endl;
      return 0;
    }
    for (int j = 0; j < a; j++) {
      if (b[i] == b[j] && i != j) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, i, j, k;
string s[12];
int main() {
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> s[i];
  for (i = 1; i < n; i++) {
    if (s[i][0] != s[i - 1][s[i - 1].size() - 1]) {
      cout << "No";
      return 0;
    }
    for (j = 0; j < i; j++) {
      if (s[i].size() != s[j].size())
        continue;
      for (k = 0; k < s[i].size(); k++) {
        if (s[i][k] != s[j][k])
          break;
      }
      if (k == s[i].size())
        break;
    }
    if (j < i)
      break;
  }
  if (i < n)
    cout << "No";
  else
    cout << "Yes";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, i, j, k;
string s[102];
int main() {
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> s[i];
  for (i = 1; i < n; i++) {
    if (s[i][0] != s[i - 1][s[i - 1].size() - 1]) {
      cout << "No";
      return 0;
    }
    for (j = 0; j < i; j++) {
      if (s[i].size() != s[j].size())
        continue;
      for (k = 0; k < s[i].size(); k++) {
        if (s[i][k] != s[j][k])
          break;
      }
      if (k == s[i].size())
        break;
    }
    if (j < i)
      break;
  }
  if (i < n)
    cout << "No";
  else
    cout << "Yes";
  return 0;
}
Problem p03261 (C++)

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

int main() {
  int a;
  string x, y;
  vector<string> buff;

  cin >> a;
  cin >> x;
  buff.push_back(x);

  for (int i = 1; i < a; i++) {
    cin >> x;
    if (x[0] == buff[i - 1].back()) {
      for (int j = 0; j < i; j++) {
        if (x == buff[j]) {
          cout << "No" << endl;
          return 0;
        }
      }
      buff.push_back(x);
    }
  }
  cout << "Yes" << endl;
}

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

int main() {
  int a;
  string x, y;
  vector<string> buff;

  cin >> a;
  cin >> x;
  buff.push_back(x);

  for (int i = 1; i < a; i++) {
    cin >> x;
    if (x[0] == buff[i - 1].back()) {
      for (int j = 0; j < i; j++) {
        if (x == buff[j]) {
          cout << "No" << endl;
          return 0;
        }
      }
      buff.push_back(x);
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<string> w = {s};
  for (int i = 0; i < n - 1; i++) {
    cin >> s;
    if (s.at(0) != w.at(i).at(w.at(i).size() - 1)) {
      cout << "No" << endl;
      return 0;
    }
    for (int j = 0; j < w.size(); j++) {
      if (s == w.at(j)) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<string> w = {s};
  for (int i = 0; i < n - 1; i++) {
    cin >> s;
    if (s.at(0) != w.at(i).at(w.at(i).size() - 1)) {
      cout << "No" << endl;
      return 0;
    }
    for (int j = 0; j < w.size(); j++) {
      if (s == w.at(j)) {
        cout << "No" << endl;
        return 0;
      }
    }
    w.push_back(s);
  }
  cout << "Yes" << endl;
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string w[100];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (w[j] == w[i]) {
        cout << "No" << endl;
        return 0;
      }
    }
    if (w[i][0] != w[i - 1][w[i - 1].size() - 1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string w[100];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (w[j] == w[i]) {
        cout << "No" << endl;
        return 0;
      }
    }
    if (w[i][0] != w[i - 1][w[i - 1].size() - 1]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}
Problem p03261 (C++)

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

int main() {
  using namespace std;
  long long a = 0, b = 0, c = 0, d = 0, e = 0, min = 0, ma = 0, ans = 0,
            count = 0, nagax = 0, nagay = 0, size = 0;
  int once[100020] = {}, info[100020] = {};
  std::string str[100], strs;

  bool okada = false, okada2 = true;
  cin >> a;
  for (int i = 1; i <= a; i++) {
    cin >> str[i];
  }
  for (int i = 2; i <= a; i++) {
    size = str[i - 1].size();
    if (str[i].at(0) != str[i - 1].at(size - 1)) {

      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = 1; i <= a - 1; i++) {
    for (int j = i + 1; j <= a; j++) {

      if (str[i] == str[j]) {
        okada2 = false;
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
}


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

int main() {
  using namespace std;
  long long a = 0, b = 0, c = 0, d = 0, e = 0, min = 0, ma = 0, ans = 0,
            count = 0, nagax = 0, nagay = 0, size = 0;
  int once[100020] = {}, info[100020] = {};
  std::string str[150], strs;

  bool okada = false, okada2 = true;
  cin >> a;
  for (int i = 1; i <= a; i++) {
    cin >> str[i];
  }
  for (int i = 2; i <= a; i++) {
    size = str[i - 1].size();
    if (str[i].at(0) != str[i - 1].at(size - 1)) {

      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = 1; i <= a - 1; i++) {
    for (int j = i + 1; j <= a; j++) {

      if (str[i] == str[j]) {
        okada2 = false;
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
}
Problem p03261 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<string> a(n);
  rep(i, n) { cin >> a[i]; }
  rep(i, n - 1) {
    if (a[i][a[i].size() - 1] != a[i + 1][0]) {
      cout << "No" << endl;
      return 0;
    }
    for (int j = i + 1; j <= n; j++) {
      if (a[i] == a[j]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<string> a(n);
  rep(i, n) { cin >> a[i]; }
  rep(i, n - 1) {
    if (a[i][a[i].size() - 1] != a[i + 1][0]) {
      cout << "No" << endl;
      return 0;
    }
    for (int j = i + 1; j < n; j++) {
      if (a[i] == a[j]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
int main() {
  int N, out = 0;
  cin >> N;
  string siritori[150];
  for (int i = 0; i < N; i++) {
    cin >> siritori[i];
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i != j && siritori[i] == siritori[j]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  for (int i = 1; i < N; i++) {
    if (siritori[i - 1].at(siritori[i - 1].size()) != siritori[i].at(0)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
int main() {
  int N, out = 0;
  cin >> N;
  string siritori[150];
  for (int i = 0; i < N; i++) {
    cin >> siritori[i];
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i != j && siritori[i] == siritori[j]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  for (int i = 1; i < N; i++) {
    if (siritori[i - 1].at(siritori[i - 1].size() - 1) != siritori[i].at(0)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
Problem p03261 (C++)

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

int main() {
  int n;
  string s[MAX];
  bool t = true;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    if (i && s[i - 1][s[i - 1].length() - 1] != s[i][0])
      t = false;
    for (int j = 0; j < i; j++) {
      if (s[j] == s[i])
        t = false;
    }
  }
  cout << (t ? "Yes" : "No") << endl;
}

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

int main() {
  int n;
  string s[MAX];
  bool t = true;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    if (i && s[i - 1][s[i - 1].length() - 1] != s[i][0])
      t = false;
    for (int j = 0; j < i; j++) {
      if (s[j] == s[i])
        t = false;
    }
  }
  cout << (t ? "Yes" : "No") << endl;
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  // Your code here!
  vector<string> shiritori;
  string buf;
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> buf;
    shiritori.push_back(buf);
  }
  for (int i = 0; i < N; i++) {
    for (int j = N; j > i; j--) {
      if (shiritori[j] == shiritori[i]) {
        cout << "No";
        return 0;
      }
    }
    if (i < N - 1) {
      if (shiritori[i][shiritori[i].size() - 1] != shiritori[i + 1][0]) {
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";
  return 0;
}


Fixed submission:
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  // Your code here!
  vector<string> shiritori;
  string buf;
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> buf;
    shiritori.push_back(buf);
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      if (shiritori[j] == shiritori[i]) {
        cout << "No";
        return 0;
      }
    }
    if (i < N - 1) {
      if (shiritori[i][shiritori[i].size() - 1] != shiritori[i + 1][0]) {
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";
  return 0;
}
Problem p03261 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<string> W(n);
  copy_n(istream_iterator<string>(cin), n, W.begin());

  for (int i = 0; i < n - 1; i++) {
    if (W[i][W[i].size() - 1] != W[i + 1][0]) {
      return puts("No");
    }
  }

  sort(W.begin(), W.end());
  puts(unique(W.begin(), W.end()) == W.end() ? "Yes" : "No");
}

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

int main() {
  int n;
  cin >> n;
  vector<string> W(n);
  copy_n(istream_iterator<string>(cin), n, W.begin());

  for (int i = 0; i < n - 1; i++) {
    if (W[i][W[i].size() - 1] != W[i + 1][0]) {
      puts("No");
      return 0;
    }
  }

  sort(W.begin(), W.end());
  puts(unique(W.begin(), W.end()) == W.end() ? "Yes" : "No");
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
int a, b;
map<string, int> mp;
string s[100];
int main() {
  int n;
  cin >> n;
  rep(i, 1, n) {
    cin >> s[i];
    if (mp.count(s[i])) {
      cout << "No";
      return 0;
    }
    int sz = s[i - 1].size();
    if (i > 1 && s[i][0] != s[i - 1][sz - 1]) {
      cout << "No";
      return 0;
    }
    mp[s[i]] = 1;
  }
  cout << "Yes";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
int a, b;
map<string, int> mp;
string s[105];
int main() {
  int n;
  cin >> n;
  rep(i, 1, n) {
    cin >> s[i];
    if (mp.count(s[i])) {
      cout << "No";
      return 0;
    }
    int sz = s[i - 1].size();
    if (i > 1 && s[i][0] != s[i - 1][sz - 1]) {
      cout << "No";
      return 0;
    }
    mp[s[i]] = 1;
  }
  cout << "Yes";
  return 0;
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, ans = 0, same = 0;
  string s;
  vector<string> w;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    w.push_back(s);
  }
  for (int i = 0; i < n; i++) {
    if (w[i].back() == w[i + 1].front() && i != (n - 1))
      ans++;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j != i && w[i] == w[j])
        same++;
    }
  }
  if (same == 0 && ans == (n - 1))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, ans = 0, same = 0;
  string s;
  vector<string> w;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    w.push_back(s);
  }
  for (int i = 0; i < (n - 1); i++) {
    if (w[i].back() == w[i + 1].front())
      ans++;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j != i && w[i] == w[j])
        same++;
    }
  }
  if (same == 0 && ans == (n - 1))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p03261 (C++)

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

int main() {

  int n, a = 1;
  string w[10] = {};
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }

  for (int i = 0; i < n - 1; i++) {
    if (w[i][w[i].size() - 1] != w[i + 1][0])
      a = 0;
  }
  //  cout<<a<<endl;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (w[i] == w[j])
        a = 0;
    }
  }

  if (a == 1)
    cout << "Yes" << endl;
  else if (a == 0)
    cout << "No" << endl;

  return 0;
}


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

int main() {

  int n, a = 1;
  string w[100] = {};
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }

  for (int i = 0; i < n - 1; i++) {
    if (w[i][w[i].size() - 1] != w[i + 1][0])
      a = 0;
  }
  //  cout<<a<<endl;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (w[i] == w[j])
        a = 0;
    }
  }

  if (a == 1)
    cout << "Yes" << endl;
  else if (a == 0)
    cout << "No" << endl;

  return 0;
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string.h>
char c[10], d[10];
std::string b[100];
int a, e, f = 0;
int main() {
  std::cin >> a;
  for (int i = 1; i <= a; i++) {
    std::cin >> c;
    if (i > 1) {
      if (c[0] != d[e - 1]) {
        f = 1;
      }
    }
    strcpy(d, c);
    e = strlen(d);
    b[i] = std::string(d);
    for (int j = 1; j < i; j++) {
      if (b[i] == b[j]) {
        f = 1;
      }
    }
  }

  if (f == 1) {
    std::cout << "No";
  } else {
    std::cout << "Yes";
  }
}

Fixed submission:
#include <iostream>
#include <string.h>
char c[20], d[20];
std::string b[110];
int a, e, f = 0;
int main() {
  std::cin >> a;
  for (int i = 1; i <= a; i++) {
    std::cin >> c;
    if (i > 1) {
      if (c[0] != d[e - 1]) {
        f = 1;
      }
    }
    strcpy(d, c);
    e = strlen(d);
    b[i] = std::string(d);
    for (int j = 1; j < i; j++) {
      if (b[i] == b[j]) {
        f = 1;
      }
    }
  }

  if (f == 1) {
    std::cout << "No";
  } else {
    std::cout << "Yes";
  }
}
Problem p03261 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<string> w(n);
  rep(i, n) { cin >> w.at(i); }

  bool flag = true;
  rep(i, n) {
    rep(j, n) {
      if (i == j)
        continue;
      else {
        if (w.at(i) == w.at(j)) {
          flag = false;
        }
      }
    }
  }

  if (flag == false) {
    cout << "No" << endl;
    exit(1);
  }

  rep(i, n - 1) {
    if (w.at(i).at(w.at(i).size() - 1) != w.at(i + 1).at(0)) {
      flag = false;
      break;
    } else {
      continue;
    }
  }

  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<string> w(n);
  rep(i, n) { cin >> w.at(i); }

  bool flag = true;
  rep(i, n) {
    rep(j, n) {
      if (i == j)
        continue;
      else {
        if (w.at(i) == w.at(j)) {
          flag = false;
        }
      }
    }
  }

  if (flag == true) {
    rep(i, n - 1) {
      if (w.at(i).at(w.at(i).size() - 1) != w.at(i + 1).at(0)) {
        flag = false;
        break;
      } else {
        continue;
      }
    }
  }

  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03261 (C++)

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

int main() {
  int n, flg;
  cin >> n;
  flg = 0;

  string w[10];
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  } /*

   for(int i=0;i<n;i++){
       cout<<w[i]<<"\n";
   }
   */

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (w[j] == w[i]) {
        flg = 1;
      }
    }
  }
  // cout<<"checked same words flg=="<<flg<<"\n";
  for (int i = 0; i < n - 1; i++) {
    if (w[i].back() != w[i + 1][0]) {
      // cout<<"w["<<i<<"].back()="<<w[i].back()<<"
      // w["<<i+1<<"][0]="<<w[i+1][0]<<"\n";
      flg = 1;
    }
  }
  // cout<<"checked chain words flg=="<<flg<<"\n";

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

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

int main() {
  int n, flg;
  cin >> n;
  flg = 0;

  string w[100];
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  } /*

   for(int i=0;i<n;i++){
       cout<<w[i]<<"\n";
   }
   */

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (w[j] == w[i]) {
        flg = 1;
      }
    }
  }
  // cout<<"checked same words flg=="<<flg<<"\n";
  for (int i = 0; i < n - 1; i++) {
    if (w[i].back() != w[i + 1][0]) {
      // cout<<"w["<<i<<"].back()="<<w[i].back()<<"
      // w["<<i+1<<"][0]="<<w[i+1][0]<<"\n";
      flg = 1;
    }
  }
  // cout<<"checked chain words flg=="<<flg<<"\n";

  if (flg == 0) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}
Problem p03261 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<string> W(N);
  for (int i = 0; i < N; i++)
    cin >> W.at(i);
  set<string> S;
  S.insert(W.at(0));
  bool ans = true;
  for (int i = 1; i < N; i++) {
    if (S.count(W.at(i))) {
      ans = false;
      break;
    } else {
      if (W.at(i).at(0) != W.at(i - 1).at(W.at(i - 1).size()) - 1) {
        ans = false;
        break;
      } else
        S.insert(W.at(i));
    }
  }
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<string> W(N);
  for (int i = 0; i < N; i++)
    cin >> W.at(i);
  set<string> S;
  S.insert(W.at(0));
  bool ans = true;
  for (int i = 1; i < N; i++) {
    if (S.count(W.at(i))) {
      ans = false;
      break;
    } else {
      if (W.at(i).at(0) != W.at(i - 1).at(W.at(i - 1).size() - 1)) {
        ans = false;
        break;
      } else
        S.insert(W.at(i));
    }
  }
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}