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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 110;
const ll INF = 2e9 + 10;

struct edge {
  int to, next;
} G[maxn << 1];
int tot, head[maxn];
void addEdge(int u, int v) {
  G[tot] = {v, head[u]};
  head[u] = tot++;
};
int n, s, t, vis[2][maxn];
void dfs(int u, int fa, int x) {
  for (int i = head[u]; i != -1; i = G[i].next)
    if (G[i].to != fa)
      vis[x][G[i].to] = vis[x][u] + 1, dfs(G[i].to, u, x);
}
int main() {
#ifdef Irene
  freopen("in.txt", "r", stdin);
#endif // Irene
  ios_base::sync_with_stdio(false);

  cin >> n >> s >> t;
  int u, v;
  for (int i = 1; i <= n; i++)
    head[i] = -1;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    addEdge(u, v);
    addEdge(v, u);
  }
  dfs(s, -1, 0);
  dfs(t, -1, 1);
  // for(int i = 1;i <= n;i++)cout << vis[0][i] << " " << vis[1][i] << "\n";
  int ans = 0, mi = INF;
  for (int i = 1; i <= n; i++) {
    if (vis[0][i] < vis[1][i])
      ans = max(ans, vis[1][i] - 1);
    else if (vis[0][i] == vis[1][i])
      mi = min(mi, vis[0][i]);
  }
  cout << max(ans, (mi == INF ? 0 : mi)) << "\n";
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const ll INF = 2e9 + 10;

struct edge {
  int to, next;
} G[maxn << 1];
int tot, head[maxn];
void addEdge(int u, int v) {
  G[tot] = {v, head[u]};
  head[u] = tot++;
};
int n, s, t, vis[2][maxn];
void dfs(int u, int fa, int x) {
  for (int i = head[u]; i != -1; i = G[i].next)
    if (G[i].to != fa)
      vis[x][G[i].to] = vis[x][u] + 1, dfs(G[i].to, u, x);
}
int main() {
#ifdef Irene
  freopen("in.txt", "r", stdin);
#endif // Irene
  ios_base::sync_with_stdio(false);

  cin >> n >> s >> t;
  int u, v;
  for (int i = 1; i <= n; i++)
    head[i] = -1;
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    addEdge(u, v);
    addEdge(v, u);
  }
  dfs(s, -1, 0);
  dfs(t, -1, 1);
  // for(int i = 1;i <= n;i++)cout << vis[0][i] << " " << vis[1][i] << "\n";
  int ans = 0, mi = INF;
  for (int i = 1; i <= n; i++) {
    if (vis[0][i] < vis[1][i])
      ans = max(ans, vis[1][i] - 1);
    else if (vis[0][i] == vis[1][i])
      mi = min(mi, vis[0][i]);
  }
  cout << max(ans, (mi == INF ? 0 : mi)) << "\n";
}
Problem p02834 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
const int MAX = 2e5;
const ll MOD = 1e9 + 7;
const int INF = 1 << 30;

int N;
vector<vector<int>> G;
vector<int> dist;

void dfs(int v, int d = 0, int p = -1) {
  dist[v] = d;
  for (int nv : G[v]) {
    if (nv == p)
      continue;
    dfs(nv, d + 1, v);
  }
}

vector<int> calcdist(int v) {
  dist = vector<int>(N); // 初期化
  dfs(v);
  return dist;
}

int main() {
  cin >> N;
  int u, v;
  cin >> u >> v;
  u--;
  v--;
  G.resize(N, vector<int>(0));
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<int> distu = calcdist(u);
  vector<int> distv = calcdist(v);

  int mv = 0;
  rep(i, N) {
    if (distu[i] < distv[i]) {
      mv = max(mv, distv[i]);
    }
  }
  int ans = mv - 1;
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
const int MAX = 2e5;
const ll MOD = 1e9 + 7;
const int INF = 1 << 30;

int N;
vector<vector<int>> G;
vector<int> dist;

void dfs(int v, int d = 0, int p = -1) {
  dist[v] = d;
  for (int nv : G[v]) {
    if (nv == p)
      continue;
    dfs(nv, d + 1, v);
  }
}

vector<int> calcdist(int v) {
  dist = vector<int>(N); // 初期化
  dfs(v);
  return dist;
}

int main() {
  cin >> N;
  int u, v;
  cin >> u >> v;
  u--;
  v--;
  G.resize(N, vector<int>(0));
  rep(i, N - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<int> distu = calcdist(u);
  vector<int> distv = calcdist(v);

  int mv = 0;
  rep(i, N) {
    if (distu[i] < distv[i]) {
      mv = max(mv, distv[i]);
    }
  }
  int ans = mv - 1;
  cout << ans << endl;
}
Problem p02834 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
vector<bool> seen;
vector<int> U, V;
void dfs(Graph G, int v, int num) {
  seen[v] = true;
  U[v] = num;
  num++;
  for (int next_v : G[v]) {
    if (seen[next_v])
      continue;
    dfs(G, next_v, num);
  }
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  Graph G(N + 1);
  U.assign(N + 1, 0);
  V.assign(N + 1, 0);
  for (int i = 1; i <= N; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int ans = 0;
  seen.assign(N + 1, false);
  int num = 0;
  dfs(G, v, num);
  num = 0, V = U;
  seen.assign(N + 1, false);
  dfs(G, u, num);
  for (int i = 1; i <= N; i++) {
    if (V[i] > U[i]) {
      ans = max(ans, V[i]);
    }
  }
  ans--;
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
vector<bool> seen;
vector<int> U, V;
void dfs(Graph &G, int v, int num) {
  seen[v] = true;
  U[v] = num;
  num++;
  for (int next_v : G[v]) {
    if (seen[next_v])
      continue;
    dfs(G, next_v, num);
  }
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  Graph G(N + 1);
  U.assign(N + 1, 0);
  V.assign(N + 1, 0);
  for (int i = 1; i <= N; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int ans = 0;
  seen.assign(N + 1, false);
  int num = 0;
  dfs(G, v, num);
  num = 0, V = U;
  seen.assign(N + 1, false);
  dfs(G, u, num);
  for (int i = 1; i <= N; i++) {
    if (V[i] > U[i]) {
      ans = max(ans, V[i]);
    }
  }
  ans--;
  cout << ans << endl;
}
Problem p02834 (C++)

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

vector<int> G[10500];
int dist[2][10500] = {};
int ans = 0;

void DFS(int node, int parent, int man) {
  for (auto it : G[node]) {
    if (it != parent) {
      dist[man][it] = dist[man][node] + 1;
      DFS(it, node, man);
    }
  }
}
int main() {
  int n, v, u;
  cin >> n >> u >> v;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  DFS(u, -1, 0);
  DFS(v, -1, 1);

  for (int i = 1; i <= n; i++) {
    if (dist[0][i] < dist[1][i]) {
      ans = max(ans, dist[1][i] - 1);
    }
  }

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


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

vector<int> G[105000];
int dist[2][100500] = {};
int ans = 0;

void DFS(int node, int parent, int man) {
  for (auto it : G[node]) {
    if (it != parent) {
      dist[man][it] = dist[man][node] + 1;
      DFS(it, node, man);
    }
  }
}
int main() {
  int n, v, u;
  cin >> n >> u >> v;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  DFS(u, -1, 0);
  DFS(v, -1, 1);

  for (int i = 1; i <= n; i++) {
    if (dist[0][i] < dist[1][i]) {
      ans = max(ans, dist[1][i] - 1);
    }
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vout(x) rep(i, x.size()) cout << x[i] << " "
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

void dfs(const vvint g, vint &dis, int v, int p = -1) {
  for (int n_v : g[v]) {
    if (n_v == p)
      continue;
    dis[n_v] = dis[v] + 1;
    dfs(g, dis, n_v, v);
  }
}

int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vvint g(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vint dis_u(n, inf);
  vint dis_v(n, inf);
  dis_u[u] = 0;
  dis_v[v] = 0;
  dfs(g, dis_u, u);
  dfs(g, dis_v, v);
  int ans = 0;
  rep(i, n) {
    if (dis_u[i] < dis_v[i]) {
      ans = max(ans, dis_v[i] - 1);
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vout(x) rep(i, x.size()) cout << x[i] << " "
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

void dfs(const vvint &g, vint &dis, int v, int p = -1) {
  for (int n_v : g[v]) {
    if (n_v == p)
      continue;
    dis[n_v] = dis[v] + 1;
    dfs(g, dis, n_v, v);
  }
}

int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vvint g(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vint dis_u(n, inf);
  vint dis_v(n, inf);
  dis_u[u] = 0;
  dis_v[v] = 0;
  dfs(g, dis_u, u);
  dfs(g, dis_v, v);
  int ans = 0;
  rep(i, n) {
    if (dis_u[i] < dis_v[i]) {
      ans = max(ans, dis_v[i] - 1);
    }
  }
  cout << ans << endl;
}
Problem p02834 (C++)

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

void dfs(int cur, int d, vector<int> &h) {
  h[cur] = d;
  used[cur] = 1;
  for (auto x : g[cur]) {
    if (!used[x]) {
      dfs(x, d + 1, h);
    }
  }
}

int main() {
  // your code goes here
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<int> hu(n), hv(n);
  g.resize(n);
  used.resize(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  // fill(used.begin(),used.end(),0);
  dfs(u, 0, hu);
  fill(used.begin(), used.end(), 0);
  dfs(v, 0, hv);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (hv[i] > hu[i]) {
      ans = max(ans, hv[i] - 1);
    }
  }

  cout << ans;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
vector<vector<int>> g;
vector<int> used;

void dfs(int cur, int d, vector<int> &h) {
  h[cur] = d;
  used[cur] = 1;
  for (auto x : g[cur]) {
    if (!used[x]) {
      dfs(x, d + 1, h);
    }
  }
}

int main() {
  // your code goes here
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<int> hu(n), hv(n);
  g.resize(n);
  used.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  // fill(used.begin(),used.end(),0);
  dfs(u, 0, hu);
  fill(used.begin(), used.end(), 0);
  dfs(v, 0, hv);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (hv[i] > hu[i]) {
      ans = max(ans, hv[i] - 1);
    }
  }

  cout << ans;

  return 0;
}
Problem p02834 (Python)

Buggy submission (status: Time Limit Exceeded):
def p_f():
    from sys import stdin

    input = stdin.readline
    N, u, v = map(int, input().split())
    edges = [list(map(int, input().split())) for i in range(N - 1)]
    if u == v:
        print(0)
        exit()

    def BFS(K, edges, N):
        roots = [[] for i in range(N)]
        for a, b in edges:
            roots[a - 1] += [(b - 1, 1)]
            roots[b - 1] += [(a - 1, 1)]
        dist = [-1] * N
        stack = []
        stack.append(K)
        dist[K] = 0
        while stack:
            label = stack.pop(-1)
            for i, c in roots[label]:
                if dist[i] == -1:
                    dist[i] = dist[label] + c
                    stack += [i]
        return dist

    dist_v = BFS(v - 1, edges, N)
    dist_u = BFS(u - 1, edges, N)
    # print(dist_v)
    # print(dist_u)
    maxIndex = [i for i, x in enumerate(dist_v) if x == max(dist_v)]
    for i in maxIndex:
        if max(dist_v) > dist_u[i]:
            print(max(dist_v) - 1)
            exit()
    if dist_v[u - 1] > max(dist_v) - dist_v[u - 1]:
        print(max(dist_v) - 1)
    else:
        print(dist_v[u - 1] - 1)


if __name__ == "__main__":
    p_f()


Fixed submission:
def p_f():
    from sys import stdin

    input = stdin.readline
    N, u, v = map(int, input().split())
    edges = [list(map(int, input().split())) for i in range(N - 1)]
    if u == v:
        print(0)
        exit()

    def BFS(K, edges, N):
        roots = [[] for i in range(N)]
        for a, b in edges:
            roots[a - 1] += [(b - 1, 1)]
            roots[b - 1] += [(a - 1, 1)]
        dist = [-1] * N
        stack = []
        stack.append(K)
        dist[K] = 0
        while stack:
            label = stack.pop(-1)
            for i, c in roots[label]:
                if dist[i] == -1:
                    dist[i] = dist[label] + c
                    stack += [i]
        return dist

    dist_v = BFS(v - 1, edges, N)
    dist_u = BFS(u - 1, edges, N)
    ans = 0
    for du, dv in zip(dist_u, dist_v):
        if du < dv and ans < dv - 1:
            ans = dv - 1
    print(ans)


if __name__ == "__main__":
    p_f()
Problem p02834 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> c(10010, vector<int>(0));
int N;

// 既に探索した部分をboolの配列で表現したところREとなった
// 上記boolをやめて，一つ前のpositionをppで把握→ppを飛ばすとしても提出結果に変わりなし
void DFS(int p, int ans, int pp, vector<int> &d) {
  d.at(p) = ans;
  for (int i : c.at(p)) {
    if (i == pp) {
      continue;
    }
    DFS(i, ans + 1, p, d);
  }
  return;
}

vector<int> dist(int p) {
  vector<int> d(N);
  DFS(p, 0, -1, d);
  return d;
}

int main() {
  int T, A, ans = 0;

  cin >> N >> T >> A;
  T--;
  A--;

  int s, t;
  for (int i = 0; i < N - 1; i++) {
    cin >> s >> t;
    s--;
    t--;
    c.at(s).push_back(t);
    c.at(t).push_back(s);
  }

  vector<int> Td(N), Ad(N);
  Td = dist(T);
  Ad = dist(A);

  for (int i = 0; i < N; i++) {
    if (Td[i] < Ad[i]) {
      ans = max(ans, Ad[i] - 1);
    }
  }
  cout << ans;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> c(100100, vector<int>(0));
int N;

// 既に探索した部分をboolの配列で表現したところREとなった
// 上記boolをやめて，一つ前のpositionをppで把握→ppを飛ばすとしても提出結果に変わりなし
void DFS(int p, int ans, int pp, vector<int> &d) {
  d.at(p) = ans;
  for (int i : c.at(p)) {
    if (i == pp) {
      continue;
    }
    DFS(i, ans + 1, p, d);
  }
  return;
}

vector<int> dist(int p) {
  vector<int> d(N);
  DFS(p, 0, -1, d);
  return d;
}

int main() {
  int T, A, ans = 0;

  cin >> N >> T >> A;
  T--;
  A--;

  int s, t;
  for (int i = 0; i < N - 1; i++) {
    cin >> s >> t;
    s--;
    t--;
    c.at(s).push_back(t);
    c.at(t).push_back(s);
  }

  vector<int> Td(N), Ad(N);
  Td = dist(T);
  Ad = dist(A);

  for (int i = 0; i < N; i++) {
    if (Td[i] < Ad[i]) {
      ans = max(ans, Ad[i] - 1);
    }
  }
  cout << ans;
}
Problem p02834 (Python)

Buggy submission (status: Runtime Error):
# 解説を見た


def solve(N, t, a, g) -> int:
    def calc_dist(init):
        dist = [-1] * N
        dist[init] = 0

        def _calc_dist(curr):
            for next_ in g[curr]:
                if dist[next_] != -1:
                    continue
                dist[next_] = dist[curr] + 1
                _calc_dist(next_)

        _calc_dist(init)
        return dist

    dist_a = calc_dist(a)
    dist_t = calc_dist(t)

    return max(dist_a[v] for v in range(N) if dist_t[v] < dist_a[v]) - 1


if __name__ == "__main__":
    N, t, a = map(int, input().split())
    t -= 1
    a -= 1

    g = tuple(set() for _ in range(N))
    for _ in range(N - 1):
        u, v = (int(x) - 1 for x in input().split())
        g[u].add(v)
        g[v].add(u)

    print(solve(N, t, a, g))

# 青木君からの距離 > 高橋君からの距離 となる頂点Xが目的地の候補
# 青木君と高橋君の共通祖先からの距離は等しいので、
# 共通祖先への距離は、 青木君 > 高橋君 となり、高橋君は必ずXに到達できる
# Xに着いた高橋君は、手前の頂点とXとを行ったり来たりする
# a-t->at-: aが一歩進んだときに高橋君に会う(-は無人のマス目)
# at: tが手前の頂点に移動したときに青木君に会う
# いずれも手前の頂点まで青木君が移動したときにゲームが終わる
# どのXを選んでも、Xの手前でゲームが終わるので、青木君から最も遠いXを選ぶのが最善
# 頂点X: 追いつめられる位置=葉


Fixed submission:
# 解説を見た


def solve(N, t, a, g) -> int:
    import sys

    sys.setrecursionlimit(10**7)

    def calc_dist(init):
        dist = [-1] * N
        dist[init] = 0

        def _calc_dist(curr):
            for next_ in g[curr]:
                if dist[next_] != -1:
                    continue
                dist[next_] = dist[curr] + 1
                _calc_dist(next_)

        _calc_dist(init)
        return dist

    dist_a = calc_dist(a)
    dist_t = calc_dist(t)

    return max(dist_a[v] for v in range(N) if dist_t[v] < dist_a[v]) - 1


if __name__ == "__main__":
    N, t, a = map(int, input().split())
    t -= 1
    a -= 1

    g = tuple(set() for _ in range(N))
    for _ in range(N - 1):
        u, v = (int(x) - 1 for x in input().split())
        g[u].add(v)
        g[v].add(u)

    print(solve(N, t, a, g))

# 青木君からの距離 > 高橋君からの距離 となる頂点Xが目的地の候補
# 青木君と高橋君の共通祖先からの距離は等しいので、
# 共通祖先への距離は、 青木君 > 高橋君 となり、高橋君は必ずXに到達できる
# Xに着いた高橋君は、手前の頂点とXとを行ったり来たりする
# a-t->at-: aが一歩進んだときに高橋君に会う(-は無人のマス目)
# at: tが手前の頂点に移動したときに青木君に会う
# いずれも手前の頂点まで青木君が移動したときにゲームが終わる
# どのXを選んでも、Xの手前でゲームが終わるので、青木君から最も遠いXを選ぶのが最善
# 頂点X: 追いつめられる位置=葉
Problem p02834 (Python)

Buggy submission (status: Runtime Error):
from collections import deque


def nearlist(N, LIST):  # 隣接リスト
    NEAR = [set() for _ in range(N)]
    for a, b in LIST:
        NEAR[a - 1].add(b - 1)
        NEAR[b - 1].add(a - 1)
    return NEAR


def bfs(NEAR, S, N):  # 幅優先探索  # キュー
    dist = [-1 for _ in range(N)]  # 前処理
    dist[S] = 0
    que, frag = deque([S]), set([S])

    while len(que) > 0:
        q = que.popleft()
        for i in NEAR[q]:  # 移動先の候補
            if i in frag:  # 処理済みか否か
                continue
            dist[i] = dist[q] + 1
            que.append(i), frag.add(i)
    return dist


n, u, v = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]

near = nearlist(n, ab)
tkdist, akdist = bfs(near, u - 1, n), bfs(near, v - 1, n)

node = [i for i in range(n) if tkdist[i] <= akdist[i]]
ans = max(akdist[i] for i in node)
print(ans[0] - 1)


Fixed submission:
from collections import deque


def nearlist(N, LIST):  # 隣接リスト
    NEAR = [set() for _ in range(N)]
    for a, b in LIST:
        NEAR[a - 1].add(b - 1)
        NEAR[b - 1].add(a - 1)
    return NEAR


def bfs(NEAR, S, N):  # 幅優先探索  # キュー
    dist = [-1 for _ in range(N)]  # 前処理
    dist[S] = 0
    que, frag = deque([S]), set([S])

    while len(que) > 0:
        q = que.popleft()
        for i in NEAR[q]:  # 移動先の候補
            if i in frag:  # 処理済みか否か
                continue
            dist[i] = dist[q] + 1
            que.append(i), frag.add(i)
    return dist


n, u, v = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]

near = nearlist(n, ab)
tkdist, akdist = bfs(near, u - 1, n), bfs(near, v - 1, n)

node = [i for i in range(n) if tkdist[i] <= akdist[i]]
ans = max(akdist[i] for i in node)
print(ans - 1)
Problem p02834 (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 FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int n;

vector<int> g[10005];
vector<int> dist;

void dfs(int s, int p, int d) {
  dist[s] = d;
  for (auto u : g[s]) {
    if (u == p)
      continue;
    dfs(u, s, d + 1);
  }
}

vector<int> calc(int s) {
  dist = vector<int>(n);
  dfs(s, -1, 0);
  return dist;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(0);
  int u, v;
  cin >> n >> u >> v;
  --u, --v;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> distT, distA;
  distT = calc(u);
  distA = calc(v);
  int res = 0;
  rep(i, n) {
    if (distT[i] < distA[i])
      res = max(res, distA[i] - 1);
  }
  cout << res << endl;

  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int n;

vector<int> g[100005];
vector<int> dist;

void dfs(int s, int p, int d) {
  dist[s] = d;
  for (auto u : g[s]) {
    if (u == p)
      continue;
    dfs(u, s, d + 1);
  }
}

vector<int> calc(int s) {
  dist = vector<int>(n);
  dfs(s, -1, 0);
  return dist;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(0);
  int u, v;
  cin >> n >> u >> v;
  --u, --v;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> distT, distA;
  distT = calc(u);
  distA = calc(v);
  int res = 0;
  rep(i, n) {
    if (distT[i] < distA[i])
      res = max(res, distA[i] - 1);
  }
  cout << res << endl;

  return 0;
}
Problem p02834 (C++)

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

vector<int> dists_from(int v);
void dfs(int v, int d, int p);

int n;
vector<int> N[20000];

vector<int> dists;

int main(void) {
  int u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    N[a].push_back(b);
    N[b].push_back(a);
  }
  vector<int> dist_u = dists_from(u);
  vector<int> dist_v = dists_from(v);
  int d = 0;
  for (int i = 0; i < n; i++) {
    if (dist_u[i] < dist_v[i]) {
      d = max(d, dist_v[i]);
    }
  }
  cout << d - 1 << endl;
  return 0;
}

vector<int> dists_from(int v) {
  dists = vector<int>(n);
  dfs(v, 0, -1);
  return dists;
}

void dfs(int v, int d, int p) {
  for (const auto &u : N[v]) {
    if (u == p) {
      continue;
    }
    dfs(u, d + 1, v);
  }
  dists[v] = d;
}

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

vector<int> dists_from(int v);
void dfs(int v, int d, int p);

int n;
vector<int> N[200000];

vector<int> dists;

int main(void) {
  int u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    N[a].push_back(b);
    N[b].push_back(a);
  }
  vector<int> dist_u = dists_from(u);
  vector<int> dist_v = dists_from(v);
  int d = 0;
  for (int i = 0; i < n; i++) {
    if (dist_u[i] < dist_v[i]) {
      d = max(d, dist_v[i]);
    }
  }
  cout << d - 1 << endl;
  return 0;
}

vector<int> dists_from(int v) {
  dists = vector<int>(n);
  dfs(v, 0, -1);
  return dists;
}

void dfs(int v, int d, int p) {
  for (const auto &u : N[v]) {
    if (u == p) {
      continue;
    }
    dfs(u, d + 1, v);
  }
  dists[v] = d;
}
Problem p02835 (Python)

Buggy submission (status: Runtime Error):
A1 = input()
A2 = input()
A3 = input()


Fixed submission:
a, b, c = map(int, input().split())
if a + b + c >= 22:
    print("bust")
else:
    print("win")
Problem p02835 (Python)

Buggy submission (status: Runtime Error):
A1 = input()
A2 = input()
A3 = input()

if A1 + A2 + A3 < 22:
    print("win")
else:
    print("bust")


Fixed submission:
A1, A2, A3 = (int(x) for x in input().split())
if A1 + A2 + A3 < 22:
    print("win")
else:
    print("bust")
Problem p02835 (Python)

Buggy submission (status: Runtime Error):
a, b, c = map(int, input().split())

print("win" if sum((a, b, c)) < 21 else "bust")
a, b, c = map(int, input().split())

print("win" if sum((a, b, c)) < 22 else "bust")


Fixed submission:
a, b, c = map(int, input().split())

print("win" if sum((a, b, c)) < 22 else "bust")
Problem p02835 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n)                                                                \
  int n;                                                                       \
  cin >> n;                                                                    \
  int a[n];                                                                    \
  rep(i, n) cin >> a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p = 1000000007;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int x, y, z;
  cin >> x >> y >> z;
  if (x + y + z >= 22)
    cout << "bust";
  else
    cout << "win";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n)                                                                \
  int n;                                                                       \
  cin >> n;                                                                    \
  int a[n];                                                                    \
  rep(i, n) cin >> a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p = 1000000007;
int main() {
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  // #endif
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int x, y, z;
  cin >> x >> y >> z;
  if (x + y + z >= 22)
    cout << "bust";
  else
    cout << "win";
  return 0;
}
Problem p02835 (Python)

Buggy submission (status: Runtime Error):
array = map(int, input().split())
print(f'{ "bust" if sum(array) >= 22 else "win"}')


Fixed submission:
array = map(int, input().split())
if sum(array) >= 22:
    print("bust")
else:
    print("win")
Problem p02835 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int a, b, c;
  scanf("%d%d%d", a, b, c);
  if (a + b + c < 22)
    printf("win\n");
  else
    printf("bust\n");
}

Fixed submission:
#include <stdio.h>
int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  if (a + b + c < 22)
    printf("win\n");
  else
    printf("bust\n");
}
Problem p02835 (C++)

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())
#define endl '\n'

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long long ll;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int a, b, c;
  cin >> a >> b >> c;
  cout << (a + b + c >= 22 ? "bust" : "win") << endl;
  return 0;
}

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())
#define endl '\n'

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long long ll;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // #endif
  int a, b, c;
  cin >> a >> b >> c;
  cout << (a + b + c >= 22 ? "bust" : "win") << endl;
  return 0;
}
Problem p02835 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main() {
  int a, b, c;
  scanf("%d %d %d");
  if (a + b + c <= 21) {
    printf("win");
  } else {
    printf("bust");
  }
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if (a + b + c <= 21) {
    printf("win");
  } else {
    printf("bust");
  }
  return 0;
}
Problem p02835 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int, int>
#define ld long double
const int mod = 1e9 + 7;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

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

#ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
#endif

  int a, b, c;
  cin >> a >> b >> c;
  if (a + b + c >= 22) {
    cout << "bust\n";
  } else {
    cout << "win\n";
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int, int>
#define ld long double
const int mod = 1e9 + 7;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

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

  int a, b, c;
  cin >> a >> b >> c;
  if (a + b + c >= 22) {
    cout << "bust\n";
  } else {
    cout << "win\n";
  }
}
Problem p02835 (C++)

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

int main() {
  vector<int> a;
  cin >> a[0] >> a[1] >> a[2];
  if (a[0] + a[1] + a[2] < 22)
    cout << "win" << endl;
  else
    cout << "bust" << endl;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int s = a + b + c;
  if (s <= 21)
    cout << "win" << endl;
  else
    cout << "bust" << endl;
}
Problem p02835 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int a, b, c;
  scanf("%d %d %d", a, b, c);
  if (a + b + c <= 21) {
    printf("win");
  } else {
    printf("bust");
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if (a + b + c <= 21) {
    printf("win");
  } else {
    printf("bust");
  }
  return 0;
}
Problem p02836 (C++)

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

int main(void) {
  string S;
  int ans = 0;
  cin >> S;
  for (int i = 0; i <= S.length() / 2 - 1; i++) {
    if (S[i] != S[S.length() - 1 - i]) {
      // cout << S[i] << " " << S[S.length() - 1 - i] << endl;
      ans++;
    }
  }
  printf("%d", ans);

  return 0;
}


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

int main(void) {
  string S;
  int ans = 0;
  cin >> S;
  int l = S.length();
  for (int i = 0; i <= l / 2 - 1; i++) {
    if (S[i] != S[l - 1 - i]) {
      ans++;
    }
  }
  printf("%d", ans);

  return 0;
}
Problem p02836 (C++)

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

using namespace std;

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

  string str;
  cin >> str;

  int begin = 0;
  int end = str.length() - 1;
  int answer = 0;

  while (begin != end) {
    if (str[begin] != str[end])
      answer++;
    begin++;
    end--;
  }

  cout << answer << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

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

  string str;
  cin >> str;

  int begin = 0;
  int end = str.length() - 1;
  int answer = 0;

  while (begin <= end) {
    if (str[begin] != str[end])
      answer++;
    begin++;
    end--;
  }

  cout << answer << endl;
  return 0;
}
Problem p02836 (C++)

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define bet(min, max, n) if (!(min < n && n < max))
#define bet_omin(min, max, n) if (!(min <= n && n < max))
#define bet_omax(min, max, n) if (!(min < n && n <= max))
#define rep(i, n) for (int i = 0; i < n; i++)

typedef long long unsigned int ll;
using namespace std;

int main() {
  string S;
  cin >> S;
  int v = 0;
  rep(i, (S.length() / 2 - 1)) {
    if (S[i] != S[S.length() - 1 - i]) {
      v += 1;
    }
  }
  cout << v << endl;
  return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define bet(min, max, n) if (!(min < n && n < max))
#define bet_omin(min, max, n) if (!(min <= n && n < max))
#define bet_omax(min, max, n) if (!(min < n && n <= max))
#define rep(i, n) for (int i = 0; i < n; i++)

typedef long long unsigned int ll;
using namespace std;

int main() {
  string S;
  cin >> S;
  int v = 0;
  rep(i, (S.length() / 2)) {
    if (S[i] != S[S.length() - 1 - i]) {
      v += 1;
    }
  }
  cout << v << endl;
  return 0;
}
Problem p02836 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int ans = 0;
  if (S.size() % 2 == 0) {
    for (int i = 0; i < S.size() / 2; i++) {
      if (S.at(i) != S.at(S.size() - 1 - i)) {
        ans++;
      }
    }
  }
  if (S.size() % 2 == 1) {
    for (int i = 0; i < S.size() / 2 - 1; i++) {
      if (S.at(i) != S.at(S.size() - 1 - i)) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i < S.size() / 2; i++) {
    if (S.at(i) != S.at(S.size() - 1 - i)) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02836 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  string moji;
  cin >> moji;
  int kotae = 0;
  for (int i = 0; i <= moji.size() / 2 - 1; i++) {
    if (moji[i] != moji[moji.size() - i - 1]) {
      kotae++;
    }
  }
  cout << kotae << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  string moji;
  cin >> moji;
  int kotae = 0;
  if (moji.size() != 1) {
    for (int i = 0; i <= moji.size() / 2 - 1; i++) {
      if (moji[i] != moji[moji.size() - i - 1]) {
        kotae++;
      }
    }
  }
  cout << kotae << endl;
  return 0;
}
Problem p02836 (C++)

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

int main() {
  string S;
  cin >> S;
  ll ans = 0;
  for (int i = 0; i <= S.size() / 2 - 1; i++) {
    if (S[i] != S[S.size() - i - 1])
      ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  string S;
  cin >> S;
  ll ans = 0;
  for (int i = 0; i <= ll(S.size()) / 2 - 1; i++) {
    if (S[i] != S[S.size() - i - 1])
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02836 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cmath>
#include <cstdint>  // int64_t, int*_t
#include <cstdio>   // printf
#include <deque>    // deque
#include <iostream> // cout, endl, cin
#include <limits>
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mod 1000000007
#define fst first
#define pb push_back
// ABC146B first AC
int main() {
  string s, s2;
  cin >> s;
  reverse(s.begin(), s.end());
  for (int i = 0; i < s.size(); i++) {
    // sの逆を作る
    s2[i] = s[i];
  }
  // sの並びを戻す。
  reverse(s.begin(), s.end());
  // 差異のカウント(つまりハグ)
  int diff = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != s2[i]) {
      diff++;
    }
  }
  cout << diff / 2 << endl;
}

Fixed submission:
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cmath>
#include <cstdint>  // int64_t, int*_t
#include <cstdio>   // printf
#include <deque>    // deque
#include <iostream> // cout, endl, cin
#include <limits>
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mod 1000000007
#define fst first
#define pb push_back
// ABC146B first AC
int main() {
  string s, s2;
  cin >> s;
  reverse(s.begin(), s.end());
  for (int i = 0; i < s.size(); i++) {
    // sの逆を作る
    s2[i] = s[i];
  }
  // sの並びを戻す。
  reverse(s.begin(), s.end());
  // 差異のカウント(つまりハグ)
  int diff = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != s2[i]) {
      diff++;
    }
  }
  int ans = diff / 2;
  cout << ans << endl;
}
Problem p02836 (C++)

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

int main() {
  string s = "";
  cin >> s;
  int ans = 0;
  for (int i = 0, j = s.size() - 1; i != j; i++, j--)
    if (s[i] != s[j])
      ans++;

  cout << ans << '\n';
  return 0;
}

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

int main() {
  string s = "";
  cin >> s;
  int ans = 0;
  for (int i = 0, j = (int)s.size() - 1; i < (int)s.size() / 2; i++, j--)
    if (s[i] != s[j])
      ans++;

  cout << ans << '\n';
  return 0;
}
Problem p02836 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #include<tr1/unordered_map>
#pragma GCC optimize("Ofast")
#define ll long long
#define pll pair<long long, long long>
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define Forn(i, n) for (int i = 1; i <= int(n); i++)

using namespace std;

/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> rbtree;*/

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i <= s.size() / 2 - 1; i++)
    if (s[i] != s[s.size() - i - 1])
      ans++;
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
// #include<tr1/unordered_map>
#pragma GCC optimize("Ofast")
#define ll long long
#define pll pair<long long, long long>
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define Forn(i, n) for (int i = 1; i <= int(n); i++)

using namespace std;

/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> rbtree;*/

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i + 1 <= s.size() / 2; i++)
    if (s[i] != s[s.size() - i - 1])
      ans++;
  cout << ans << endl;
}
Problem p02836 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int ans, i, j;
string s;
int main() {
  cin >> s;
  i = 0;
  j = s.size() - 1;
  while (i != j) {
    if (s[i] != s[j])
      ans++;
    i++;
    j--;
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int ans, i, j;
string s;
int main() {
  cin >> s;
  i = 0;
  j = s.size() - 1;
  while (i <= j) {
    if (s[i] != s[j])
      ans++;
    i++;
    j--;
  }
  cout << ans;
  return 0;
}
Problem p02836 (C++)

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

using namespace std;

int main(void) {
  string S;
  cin >> S;
  int cnt = 0;
  for (int i = 0; i <= S.size() / 2 - 1; i++) {
    if (S[i] != S[S.size() - i - 1]) {
      cnt++;
    }
  }
  cout << cnt << endl;
}


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

using namespace std;

int main(void) {
  string S;
  cin >> S;
  int cnt = 0;
  for (int i = 0; i < S.size() / 2; i++) {
    if (S[i] != S[S.size() - i - 1]) {
      cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p02836 (C++)

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

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

  int count = 0;
  for (int i = 0; i < s.length() / 2 - 1; i++) {
    if (s[i] != s[s.length() - i]) {
      count++;
    }
  }

  cout << count << endl;
  return 0;
}


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

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

  int count = 0;
  for (int i = 0; i < s.length() / 2; i++) {
    if (s[i] != s[s.length() - 1 - i]) {
      count++;
    }
  }

  cout << count << endl;
  return 0;
}
Problem p02836 (C++)

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

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

  int len = S.length();
  int res = 0;

  string sub1 = S.substr(0, len / 2);
  string sub2 = S.substr(len / 2 + len % 2);
  reverse(sub2.begin(), sub2.end());

  for (int i = 0; i <= len / 2; i++) {
    if (sub1.back() != sub2.back())
      res++;
    sub1.pop_back();
    sub2.pop_back();
  }
  cout << res << endl;
}

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

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

  int len = S.length();
  int res = 0;

  string sub1 = S.substr(0, len / 2);
  string sub2 = S.substr(len / 2 + len % 2);
  reverse(sub2.begin(), sub2.end());

  for (int i = 0; i < len / 2; i++) {
    if (sub1.back() != sub2.back())
      res++;
    sub1.pop_back();
    sub2.pop_back();
  }
  cout << res << endl;
}
Problem p02836 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> st;
int prime[1100001];
void seive() {
  for (int i = 2; i * i <= 1100000; i++) {
    if (!prime[i]) {
      // cout << i << endl;
      for (int j = i * i; j <= 1100000; j += i) {
        prime[j] = 1;
      }
    }
  }
  for (int i = 2; i <= 200000; i++) {
    if (!prime[i])
      st.push_back(i);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
#endif
  string s;
  cin >> s;
  int x = s.size() / 2;
  int ans = 0;
  for (int i = 0; i < x; i++) {
    if (s[i] != s[s.size() - i - 1])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> st;
int prime[1100001];
void seive() {
  for (int i = 2; i * i <= 1100000; i++) {
    if (!prime[i]) {
      // cout << i << endl;
      for (int j = i * i; j <= 1100000; j += i) {
        prime[j] = 1;
      }
    }
  }
  for (int i = 2; i <= 200000; i++) {
    if (!prime[i])
      st.push_back(i);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int x = s.size() / 2;
  int ans = 0;
  for (int i = 0; i < x; i++) {
    if (s[i] != s[s.size() - i - 1])
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02836 (C++)

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  int i = 0;
  while (i <= (s.size() - 1 - i)) {
    if (s.at(i) != s.at(s.size() - 1 - i)) {
      ans++;
    }
    i++;
  }
  cout << ans << endl;
}


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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  int i = 0;
  while (i < (s.size() - 1 - i)) {
    if (s.at(i) != s.at(s.size() - 1 - i)) {
      ans++;
    }
    i++;
  }
  cout << ans << endl;
}
Problem p02836 (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() {
  string s, t;
  int a, ans;
  ans = 0;
  cin >> s;
  a = s.size();
  s = t;
  reverse(t.begin(), t.end());
  rep(i, a / 2) {
    if (s.at(i) != t.at(i))
      ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  string s, t;
  int a, ans;
  ans = 0;
  cin >> s;
  a = s.size();
  t = s;
  reverse(t.begin(), t.end());
  rep(i, a / 2) {
    if (s.at(i) != t.at(i))
      ans++;
  }
  cout << ans << endl;
}
Problem p02836 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, x, n) for (int i = x; i < n; i++)
#define WHITE 0
#define BLACK 1
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
string s;
int k;
int INFi = 1000000000;
ll INFl = 1000000000000000;

int main() {
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i <= s.size() - 1 - i; i++) {
    if (s[i] != s[s.size() - 1 - i])
      count++;
  }
  cout << count << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, x, n) for (int i = x; i < n; i++)
#define WHITE 0
#define BLACK 1
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
string s;
int k;
int INFi = 1000000000;
ll INFl = 1000000000000000;

int main() {
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i < s.size() - 1 - i; i++) {
    if (s[i] != s[s.size() - 1 - i])
      count++;
  }
  cout << count << endl;
  return 0;
}