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

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

using namespace std;

#define ll long long
#define fi first
#define se second
const int maxn = 1e6 + 10, INF = 1000000009;

ll a[maxn];
bool flg = false;
vector<pair<int, ll>> E[maxn];

void init() {
  for (int i = 0; i < maxn; i++)
    a[i] = INF;
}
int n, m;
bool vis[maxn];

void dfs(int idx) {

  for (int i = 0; i < E[idx].size(); i++) {
    int to = E[idx][i].fi;
    int v = E[idx][i].se;
    if (vis[to])
      continue;
    if (a[to] != INF) {
      if (a[to] - a[idx] != v) {
        flg = true;
        return;
      } else {
        // dfs(to);
        if (flg)
          return;
      }
    } else {
      a[to] = a[idx] + v;
      dfs(to);
      if (flg)
        return;
    }
  }
  vis[idx] = true;
  if (flg)
    return;
}
int L[maxn];
int main() {
  ios_base::sync_with_stdio(0);

  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    L[i] = l;
    E[l].push_back(make_pair(r, d));
    E[r].push_back(make_pair(l, -d));
  }
  for (int i = 0; i < n; i++) {
    if (E[L[i]].size() >= 1) {
      init();
      a[L[i]] = 0;
      dfs(L[i]);
      if (flg)
        break;
    }
  }
  if (flg)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

#define ll long long
#define fi first
#define se second
const int maxn = 1e6 + 10, INF = 1000000009;

ll a[maxn];
bool flg = false;
vector<pair<int, ll>> E[maxn];

void init() {
  for (int i = 0; i < maxn; i++)
    a[i] = INF;
}
int n, m;
bool vis[maxn];

void dfs(int idx) {

  for (int i = 0; i < E[idx].size(); i++) {
    int to = E[idx][i].fi;
    int v = E[idx][i].se;
    if (vis[to])
      continue;
    if (a[to] != INF) {
      if (a[to] - a[idx] != v) {
        flg = true;
        return;
      } else {
        // dfs(to);
        if (flg)
          return;
      }
    } else {
      a[to] = a[idx] + v;
      dfs(to);
      if (flg)
        return;
    }
  }
  vis[idx] = true;
  if (flg)
    return;
}
int L[maxn];
int main() {
  ios_base::sync_with_stdio(0);

  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    L[i] = l;
    E[l].push_back(make_pair(r, d));
    E[r].push_back(make_pair(l, -d));
  }
  for (int i = 0; i < n; i++) {
    if (E[L[i]].size() >= 1) {
      if (vis[L[i]])
        continue;
      init();
      a[L[i]] = 0;
      dfs(L[i]);
      if (flg)
        break;
    }
  }
  if (flg)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}
Problem p03452 (C++)

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

using namespace std;

struct Edge {
  int from;
  int to;
  int d;
  Edge(int from, int to, int d) : from(from), to(to), d(d) {}
};

class People {
  vector<vector<Edge>> graph;
  vector<int> visited;
  vector<int> total;
  int n;

public:
  People() {
    int m;
    cin >> n >> m;
    graph.resize(n);
    visited.resize(n, 0);
    total.resize(n);
    int l, r, d;
    for (int i = 0; i < m; ++i) {
      cin >> l >> r >> d;
      graph[l - 1].emplace_back(l - 1, r - 1, d);
      graph[r - 1].emplace_back(r - 1, l - 1, -d);
    }
  }

  bool visit(int v, int t) {
    if (0 < visited[v]) {
      return t == total[v];
    } else {
      total[t] = t;
      visited[v] = 1;
      for (Edge &e : graph[v]) {
        if (!visit(e.to, t + e.d)) {
          return false;
        }
      }
      visited[v] = 2;
      return true;
    }
  }
  bool solve() {
    for (int i = 0; i < n; ++i) {
      if (0 == visited[i] && !visit(i, 0))
        return false;
    }
    return true;
  }
};

int main() {
  People p;
  cout << (p.solve() ? "Yes" : "No") << endl;
  return 0;
}

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

using namespace std;

struct Edge {
  int from;
  int to;
  int d;
  Edge(int from, int to, int d) : from(from), to(to), d(d) {}
};

class People {
  vector<vector<Edge>> graph;
  vector<int> visited;
  vector<int> total;
  int n;

public:
  People() {
    int m;
    cin >> n >> m;
    graph.resize(n);
    visited.resize(n, 0);
    total.resize(n);
    int l, r, d;
    for (int i = 0; i < m; ++i) {
      cin >> l >> r >> d;
      graph[l - 1].emplace_back(l - 1, r - 1, d);
      graph[r - 1].emplace_back(r - 1, l - 1, -d);
    }
  }

  bool visit(int v, int t) {
    if (0 < visited[v]) {
      return t == total[v];
    } else {
      total[v] = t;
      visited[v] = 1;
      for (Edge &e : graph[v]) {
        if (!visit(e.to, t + e.d)) {
          return false;
        }
      }
      visited[v] = 2;
      return true;
    }
  }
  bool solve() {
    for (int i = 0; i < n; ++i) {
      if (0 == visited[i] && !visit(i, 0))
        return false;
    }
    return true;
  }
};

int main() {
  People p;
  cout << (p.solve() ? "Yes" : "No") << endl;
  return 0;
}
Problem p03452 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, s, n) for (int i = s; i < n; i++)
#define repe(i, s, n) for (int i = s; i <= n; i++)
#define rep_r(i, s, n) for (int i = n - 1; i >= s; i--)
#define rep_re(i, s, n) for (int i = n; i >= s; i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;

ll v[100001];
vector<pair<ll, ll>> e[100001];
ll n, m;

void dfs(ll i, ll x) {
  v[i] = x;

  rep(p, 0, e[i].size()) {
    ll nextID = e[i][p].first;
    ll nextDistance = e[i][p].second;
    if (v[nextID]) {
      // visited
      if (v[i] + nextDistance != v[nextID]) {
        cout << "No";
        exit(0);
      }
    } else {
      // not visited
      dfs(nextID, v[i] + nextDistance);
    }
  }
}

int main() {
  cin >> n >> m;
  rep(i, 0, m) {
    ll l, r, d;
    cin >> l >> r >> d;
    e[l].push_back({r, d});
    e[r].push_back({l, -d});
  }

  repe(i, 1, n) {
    if (!v[i]) {
      dfs(i, 1);
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, s, n) for (int i = s; i < n; i++)
#define repe(i, s, n) for (int i = s; i <= n; i++)
#define rep_r(i, s, n) for (int i = n - 1; i >= s; i--)
#define rep_re(i, s, n) for (int i = n; i >= s; i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;

ll v[100001];
vector<pair<ll, ll>> e[100001];
ll n, m;

void dfs(ll i, ll x) {
  v[i] = x;

  rep(p, 0, e[i].size()) {
    ll nextID = e[i][p].first;
    ll nextDistance = e[i][p].second;
    if (v[nextID]) {
      // visited
      if (v[i] + nextDistance != v[nextID]) {
        cout << "No";
        exit(0);
      }
    } else {
      // not visited
      dfs(nextID, v[i] + nextDistance);
    }
  }
}

int main() {
  cin >> n >> m;
  rep(i, 0, m) {
    ll l, r, d;
    cin >> l >> r >> d;
    e[l].push_back({r, d});
    e[r].push_back({l, -d});
  }

  repe(i, 1, n) {
    if (!v[i]) {
      dfs(i, 1e9 + 1);
    }
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p03452 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>

using namespace std;

struct UFNode {
  UFNode *parent;
  int height;
  int dist;

  UFNode() : parent(nullptr), height(1), dist(0) {}

  UFNode *getA() {
    if (parent == nullptr) {
      return this;
    } else {
      return parent->getA();
    }
  }

  int getD() {
    if (parent == nullptr) {
      return 0;
    } else {
      return dist + parent->getD();
    }
  }
};

int main(int argc, const char *argv[]) {
  int entityCount, queryCount;
  scanf("%d%d", &entityCount, &queryCount);

  UFNode uf[100000];

  for (int i = 0; i < queryCount; ++i) {
    int l, r, dist;
    scanf("%d%d%d", &l, &r, &dist);

    l--;
    r--;
    UFNode *pl, *pr;
    pl = uf[l].getA();
    pr = uf[r].getA();
    int dl = uf[l].getD();
    int dr = uf[r].getD();
    if (pl != pr) {
      if (pl->height > pr->height) {
        pl->parent = pr;
        pr->height = max(pr->height, pl->height + 1);
        pl->dist = -dl - dist + dr;
      } else {
        pr->parent = pl;
        pl->height = max(pl->height, pr->height + 1);
        pr->dist = dl + dist - dr;
      }
    } else {
      if (-dl + dr != dist) {
        printf("No\n");
        return 0;
      }
    }
  }

  printf("Yes\n");

  return 0;
}


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

using namespace std;

struct UFNode {
  UFNode *parent;
  int height;
  int dist;

  UFNode() : parent(nullptr), height(1), dist(0) {}

  UFNode *getA() {
    if (parent == nullptr) {
      return this;
    } else {
      return parent->getA();
    }
  }

  int getD() {
    if (parent == nullptr) {
      return 0;
    } else {
      return dist + parent->getD();
    }
  }
};

int main(int argc, const char *argv[]) {
  int entityCount, queryCount;
  scanf("%d%d", &entityCount, &queryCount);

  UFNode uf[100000];

  for (int i = 0; i < queryCount; ++i) {
    int l, r, dist;
    scanf("%d%d%d", &l, &r, &dist);

    l--;
    r--;
    UFNode *pl, *pr;
    pl = uf[l].getA();
    pr = uf[r].getA();
    int dl = uf[l].getD();
    int dr = uf[r].getD();
    if (pl != pr) {
      if (pl->height < pr->height) {
        pl->parent = pr;
        pr->height = max(pr->height, pl->height + 1);
        pl->dist = -dl - dist + dr;
      } else {
        pr->parent = pl;
        pl->height = max(pl->height, pr->height + 1);
        pr->dist = dl + dist - dr;
      }
    } else {
      if (-dl + dr != dist) {
        printf("No\n");
        return 0;
      }
    }
  }

  printf("Yes\n");

  return 0;
}
Problem p03452 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> x(N, 0);
  stack<int> s;
  vector<vector<pair<int, int>>> L(N), R(N);
  for (int i = 0, lef, rig, d; i < N; i++) {
    cin >> lef >> rig >> d;
    lef--;
    rig--;
    L[rig].push_back({lef, d});
    R[lef].push_back({rig, d});
  }
  for (int i = 0; i < N; i++) {
    if (L[i].size() == 0) {
      x[i] = 1;
      s.push(i);
    }
  }

  bool ok = true;
  while (!s.empty()) {
    int node = s.top();
    s.pop();
    for (int i = 0; i < R[node].size(); i++) {
      int next = R[node][i].first, xd = x[node] + R[node][i].second;
      if (x[next] == 0) {
        x[next] = xd;
        s.push(next);
      } else if (x[next] != xd) {
        ok = false;
        break;
      }
    }
  }

  for (int i = 0; i < N; i++) {
    if (x[i] == 0)
      ok = false;
  }
  cout << (ok ? "Yes" : "No") << endl;

  return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> x(N, 0);
  stack<int> s;
  vector<vector<pair<int, int>>> L(N), R(N);
  for (int i = 0, lef, rig, d; i < M; i++) {
    cin >> lef >> rig >> d;
    lef--;
    rig--;
    L[rig].push_back({lef, d});
    R[lef].push_back({rig, d});
  }
  for (int i = 0; i < N; i++) {
    if (L[i].size() == 0) {
      x[i] = 1;
      s.push(i);
    }
  }

  bool ok = true;
  while (!s.empty()) {
    int node = s.top();
    s.pop();
    for (int i = 0; i < R[node].size(); i++) {
      int next = R[node][i].first, xd = x[node] + R[node][i].second;
      if (x[next] == 0) {
        x[next] = xd;
        s.push(next);
      } else if (x[next] != xd) {
        ok = false;
        break;
      }
    }
  }

  for (int i = 0; i < N; i++) {
    if (x[i] == 0)
      ok = false;
  }
  cout << (ok ? "Yes" : "No") << endl;

  return 0;
}
Problem p03452 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define MAX 100002

int n;
int m;

vector<pair<int, long long int>> v[MAX];
long long int cur[MAX];
bool vis[MAX];
queue<int> q;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int l, r, d;
    scanf("%d%d%d", &l, &r, &d);
    l--;
    r--;
    v[l].push_back(make_pair(r, d));
    v[r].push_back(make_pair(l, -d));
  }
  memset(vis, false, sizeof(vis));
  for (int i = 0; i < n; i++) {
    if (vis[i] == false) {
      q.push(i);
      cur[i] = 0;
      vis[i] = true;
      while (!q.empty()) {
        int b = q.front();
        q.pop();
        vis[b] = true;
        for (auto go : v[b]) {
          int node = go.first;
          long long int nex = cur[b] + go.second;
          if (vis[node]) {
            if (cur[node] == nex) {
              continue;
            }
            puts("No");
            exit(0);
          } else {
            cur[node] = nex;
            q.push(node);
          }
        }
      }
    }
  }
  puts("Yes");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define MAX 100002

int n;
int m;

vector<pair<int, long long int>> v[MAX];
long long int cur[MAX];
bool vis[MAX];
queue<int> q;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int l, r, d;
    scanf("%d%d%d", &l, &r, &d);
    l--;
    r--;
    v[l].push_back(make_pair(r, d));
    v[r].push_back(make_pair(l, -d));
  }
  memset(vis, false, sizeof(vis));
  for (int i = 0; i < n; i++) {
    if (vis[i] == false) {
      q.push(i);
      cur[i] = 0;
      vis[i] = true;
      while (!q.empty()) {
        int b = q.front();
        q.pop();
        vis[b] = true;
        for (auto go : v[b]) {
          int node = go.first;
          long long int nex = cur[b] + go.second;
          if (vis[node]) {
            if (cur[node] == nex) {
              continue;
            }
            puts("No");
            exit(0);
          } else {
            vis[node] = true;
            cur[node] = nex;
            q.push(node);
          }
        }
      }
    }
  }
  puts("Yes");
  return 0;
}
Problem p03452 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MAX_N 105
#define pb push_back
using namespace std;
struct node {
  int y, cost;
  bool operator<(node d) const { return cost < d.cost; }
} drg[MAX_N];
int n, m, dst[MAX_N];
bool ans;
vector<node> net[MAX_N];
void dfs(int x) {
  int sz = net[x].size();
  node y;
  while (sz--) {
    y = net[x][sz];
    if (dst[y.y]) {
      if (dst[x] + y.cost != dst[y.y])
        ans = true;
      continue;
    }
    dst[y.y] = dst[x] + y.cost;
    dfs(y.y);
  }
}
int main() {
  int i, x;
  node p;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++)
    drg[i].y = i;
  for (i = 0; i < m; i++) {
    scanf("%d %d %d", &x, &p.y, &p.cost);
    net[x].pb(p);
    drg[p.y].cost++;
  }
  sort(drg + 1, drg + n + 1);
  for (i = 1; i <= n; i++) {
    if (dst[drg[i].y])
      continue;
    dst[drg[i].y] = 1;
    dfs(drg[i].y);
  }
  printf("%s\n", (ans) ? "No" : "Yes");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define MAX_N 100005
#define pb push_back
using namespace std;
struct node {
  int y, cost;
  bool operator<(node d) const { return cost < d.cost; }
} drg[MAX_N];
int n, m, dst[MAX_N];
bool ans;
vector<node> net[MAX_N];
void dfs(int x) {
  int sz = net[x].size();
  node y;
  while (sz--) {
    y = net[x][sz];
    if (dst[y.y]) {
      if (dst[x] + y.cost != dst[y.y])
        ans = true;
      continue;
    }
    dst[y.y] = dst[x] + y.cost;
    dfs(y.y);
  }
}
int main() {
  int i, x;
  node p;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++)
    drg[i].y = i;
  for (i = 0; i < m; i++) {
    scanf("%d %d %d", &x, &p.y, &p.cost);
    net[x].pb(p);
    drg[p.y].cost++;
  }
  sort(drg + 1, drg + n + 1);
  for (i = 1; i <= n; i++) {
    if (dst[drg[i].y])
      continue;
    dst[drg[i].y] = 1;
    dfs(drg[i].y);
  }
  printf("%s\n", (ans) ? "No" : "Yes");
  return 0;
}
Problem p03452 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long int
#define rep(i, x, y) for (int i = x; i < y; i++)
#define rel(i, x, y) for (int i = x - 1; i >= y; i--)
#define all(x) x.begin(), x.end()
#define DMAX 0
#define NMAX 100003
using namespace std;
vector<pair<int, int>> Range[NMAX];
int C[NMAX];

bool dfs(int x) {
  rep(i, 0, Range[x].size()) {
    if (C[Range[x][i].first] == DMAX) {
      C[Range[x][i].first] = C[x] + Range[x][i].second;
      if (!dfs(Range[x][i].first))
        return false;
    } else if (C[Range[x][i].first] != C[x] + Range[x][i].second) {
      return false;
    }
  }
  return true;
}

int main() {
  int N, M;
  cin >> N >> M;
  int l, r, d;
  rep(i, 0, M) {
    cin >> l >> r >> d;
    Range[l - 1].push_back(make_pair(r - 1, d));
    Range[r - 1].push_back(make_pair(l - 1, -d));
  }

  rep(i, 0, N) C[i] = DMAX;

  rep(i, 0, N) {
    if (C[i] == DMAX) {
      C[i] = 0;
      if (!dfs(i)) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long int
#define rep(i, x, y) for (int i = x; i < y; i++)
#define rel(i, x, y) for (int i = x - 1; i >= y; i--)
#define all(x) x.begin(), x.end()
#define DMAX 1000000000
#define NMAX 100003
using namespace std;
vector<pair<int, int>> Range[NMAX];
int C[NMAX];

bool dfs(int x) {
  rep(i, 0, Range[x].size()) {
    if (C[Range[x][i].first] == DMAX) {
      C[Range[x][i].first] = C[x] + Range[x][i].second;
      if (!dfs(Range[x][i].first))
        return false;
    } else if (C[Range[x][i].first] != C[x] + Range[x][i].second) {
      return false;
    }
  }
  return true;
}

int main() {
  int N, M;
  cin >> N >> M;
  int l, r, d;
  rep(i, 0, M) {
    cin >> l >> r >> d;
    Range[l - 1].push_back(make_pair(r - 1, d));
    Range[r - 1].push_back(make_pair(l - 1, -d));
  }

  rep(i, 0, N) C[i] = DMAX;

  rep(i, 0, N) {
    if (C[i] == DMAX) {
      C[i] = 0;
      if (!dfs(i)) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p03452 (C++)

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

int n, m;
bool onr[nmax];
int poz[nmax];
vector<pair<int, int>> g[nmax];

int l[nmax];
int r[nmax];
int d[nmax];

bool viz[nmax];

void solve(int nod) {
  viz[nod] = 1;
  for (pair<int, int> p : g[nod]) {
    poz[p.first] = poz[nod] + p.second;
    if (!viz[p.first])
      solve(p.first);
  }
}

int main() {
  int i;
  cin >> n >> m;

  for (i = 1; i <= m; i++) {
    cin >> l[i] >> r[i] >> d[i];
    onr[r[i]] = 1;
    g[l[i]].push_back(make_pair(r[i], d[i]));
  }

  for (i = 1; i <= n; i++)
    if (!onr[i])
      solve(i);

  //  for(i=1;i<=n;i++) cout<<poz[i]<<' '; cout<<'\n';

  for (i = 1; i <= n; i++)
    if (poz[r[i]] - poz[l[i]] != d[i]) {
      cout << "No\n";
      return 0;
    }
  cout << "Yes\n";
  return 0;
}


Fixed submission:
#include <iostream>
#include <vector>
#define nmax 200010
using namespace std;

int n, m;
bool onr[nmax];
int poz[nmax];
vector<pair<int, int>> g[nmax];

int l[nmax];
int r[nmax];
int d[nmax];

bool viz[nmax];

void solve(int nod) {
  viz[nod] = 1;
  for (pair<int, int> p : g[nod]) {
    poz[p.first] = poz[nod] + p.second;
    if (!viz[p.first])
      solve(p.first);
  }
}

int main() {
  int i;
  cin >> n >> m;

  for (i = 1; i <= m; i++) {
    cin >> l[i] >> r[i] >> d[i];
    onr[r[i]] = 1;
    g[l[i]].push_back(make_pair(r[i], d[i]));
  }

  for (i = 1; i <= n; i++)
    if (!onr[i])
      solve(i);

  //  for(i=1;i<=n;i++) cout<<poz[i]<<' '; cout<<'\n';

  for (i = 1; i <= n; i++)
    if (poz[r[i]] - poz[l[i]] != d[i]) {
      cout << "No\n";
      return 0;
    }
  cout << "Yes\n";
  return 0;
}
Problem p03452 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, st, ed) for (register int i = st, i##end = ed; i <= i##end; ++i)
#define DREP(i, st, ed) for (register int i = st, i##end = ed; i >= i##end; --i)
typedef long long ll;
inline int read() {
  int x;
  char c;
  int f = 1;
  while ((c = getchar()) != '-' && (c > '9' || c < '0'))
    ;
  if (c == '-')
    c = getchar(), f = -1;
  x = c ^ '0';
  while ((c = getchar()) >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ '0');
  return x * f;
}
inline ll readll() {
  ll x;
  char c;
  int f = 1;
  while ((c = getchar()) != '-' && (c > '9' || c < '0'))
    ;
  if (c == '-')
    c = getchar(), f = -1;
  x = c ^ '0';
  while ((c = getchar()) >= '0' && c <= '9')
    x = (x << 1ll) + (x << 3ll) + (c ^ '0');
  return x * f;
}
const int maxn = 1000 + 10;
int fa[maxn], d[maxn];
int n, m, flag;
int find(int x) {
  if (fa[x] == x)
    return x;
  int y = find(fa[x]);
  d[x] += d[fa[x]];
  return fa[x] = y;
}
void add(int x, int y, int z) {
  int u = find(x), v = find(y);
  if (u != v) {
    fa[u] = v;
    d[u] = d[y] - d[x] - z;
  } else if (d[y] - d[x] != z)
    flag = 1;
}
int main() {
  memset(d, 0, sizeof(d));
  n = read();
  m = read();
  flag = 0;
  REP(i, 0, n) fa[i] = i;
  while (m--) {
    int x, y, z;
    x = read(), y = read(), z = read();
    if (!flag)
      add(x, y, z);
  }
  if (flag)
    printf("No\n");
  else
    printf("Yes\n");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, st, ed) for (register int i = st, i##end = ed; i <= i##end; ++i)
#define DREP(i, st, ed) for (register int i = st, i##end = ed; i >= i##end; --i)
typedef long long ll;
inline int read() {
  int x;
  char c;
  int f = 1;
  while ((c = getchar()) != '-' && (c > '9' || c < '0'))
    ;
  if (c == '-')
    c = getchar(), f = -1;
  x = c ^ '0';
  while ((c = getchar()) >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ '0');
  return x * f;
}
inline ll readll() {
  ll x;
  char c;
  int f = 1;
  while ((c = getchar()) != '-' && (c > '9' || c < '0'))
    ;
  if (c == '-')
    c = getchar(), f = -1;
  x = c ^ '0';
  while ((c = getchar()) >= '0' && c <= '9')
    x = (x << 1ll) + (x << 3ll) + (c ^ '0');
  return x * f;
}
const int maxn = 200000 + 10;
int fa[maxn], d[maxn];
int n, m, flag;
int find(int x) {
  if (fa[x] == x)
    return x;
  int y = find(fa[x]);
  d[x] += d[fa[x]];
  return fa[x] = y;
}
void add(int x, int y, int z) {
  int u = find(x), v = find(y);
  if (u != v) {
    fa[u] = v;
    d[u] = d[y] - d[x] - z;
  } else if (d[y] - d[x] != z)
    flag = 1;
}
int main() {
  memset(d, 0, sizeof(d));
  n = read();
  m = read();
  flag = 0;
  REP(i, 0, n) fa[i] = i;
  while (m--) {
    int x, y, z;
    x = read(), y = read(), z = read();
    if (!flag)
      add(x, y, z);
  }
  if (flag)
    printf("No\n");
  else
    printf("Yes\n");
  return 0;
}
Problem p03452 (Python)

Buggy submission (status: Runtime Error):
import sys

sys.setrecursionlimit(100000)


def check(i, xs, checked):
    xi = xs[i]
    children = set()
    for j, d in links[i]:
        if checked[j]:
            continue
        if j not in xs:
            xs[j] = xi + d
        elif xi + d != xs[j]:
            return False
        children.add(j)
    checked[i] = True
    return all(check(j, xs, checked) for j in children)


def solve():
    checked = [False] * n
    for i in range(n):
        if not checked[i]:
            xs = {}
            xs[i] = 0
            if not check(i, xs, checked):
                return False
    return True


n, m = map(int, input().split())
links = [set() for _ in range(n)]
for _ in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    links[l].add((r, d))
    links[r].add((l, -d))
print("Yes" if solve() else "No")


Fixed submission:
import sys

sys.setrecursionlimit(100000)


def check(i, xs, checked):
    xi = xs[i]
    children = set()
    for j, d in links[i]:
        if checked[j]:
            continue
        if j not in xs:
            xs[j] = xi + d
        elif xi + d != xs[j]:
            return False
        children.add(j)
    checked[i] = True
    for j in children:
        if not check(j, xs, checked):
            return False
    return True


def solve():
    checked = [False] * n
    for i in range(n):
        if not checked[i]:
            xs = {}
            xs[i] = 0
            if not check(i, xs, checked):
                return False
    return True


n, m = map(int, input().split())
links = [set() for _ in range(n)]
for _ in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    links[l].add((r, d))
    links[r].add((l, -d))
print("Yes" if solve() else "No")
Problem p03452 (Python)

Buggy submission (status: Runtime Error):
class WeightedUnionFind:
    def __init__(self, n):
        self.parents = [-1] * n
        self.par_weight = [0] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            root = self.find(self.parents[x])
            self.par_weight[x] += self.par_weight[self.parents[x]]
            self.parents[x] = root
            return self.parents[x]

    def union(self, x, y, w):
        w = w + self.weight(x) - self.weight(y)
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            self.parents[y] += self.parents[x]
            self.parents[x] = y
            self.par_weight[x] = -w
        else:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
            self.par_weight[y] = w

    def weight(self, x):
        if self.parents[x] < 0:
            return 0
        else:
            return self.par_weight[x] + self.weight(self.parents[x])

    def diff(self, x, y):
        if self.find(x) != self.find(y):
            raise Exception('"{}" belongs to a different tree from "{}"'.format(x, y))
        return self.find_position(y) - self.find_position(x)


N, M = map(int, input().split())
uf = WeightedUnionFind(N)
for i in range(M):
    L, R, D = map(int, input().split())
    L -= 1
    R -= 1
    if uf.find(L) == uf.find(R):
        if uf.diff(L, R) != D:
            res = "No"
            break
    else:
        uf.union(L, R, D)
else:
    res = "Yes"

print(res)


Fixed submission:
class WeightedUnionFind:
    def __init__(self, n):
        self.parents = [-1] * n
        self.par_weight = [0] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            root = self.find(self.parents[x])
            self.par_weight[x] += self.par_weight[self.parents[x]]
            self.parents[x] = root
            return self.parents[x]

    def union(self, x, y, w):
        w = w + self.weight(x) - self.weight(y)
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            self.parents[y] += self.parents[x]
            self.parents[x] = y
            self.par_weight[x] = -w
        else:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
            self.par_weight[y] = w

    def weight(self, x):
        if self.parents[x] < 0:
            return 0
        else:
            return self.par_weight[x] + self.weight(self.parents[x])

    def diff(self, x, y):
        if self.find(x) != self.find(y):
            raise Exception('"{}" belongs to a different tree from "{}"'.format(x, y))
        return self.weight(y) - self.weight(x)


N, M = map(int, input().split())
uf = WeightedUnionFind(N)
for i in range(M):
    L, R, D = map(int, input().split())
    L -= 1
    R -= 1
    if uf.find(L) == uf.find(R):
        if uf.diff(L, R) != D:
            res = "No"
            break
    else:
        uf.union(L, R, D)
else:
    res = "Yes"

print(res)
Problem p03454 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define maxn 20000000
#define int long long
#define mod 1000000007
int digit[maxn], ans, S;

int read() {
  int x = 0, k = 1;
  char c;
  c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      k = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  return x * k;
}

int Qpow(int times) {
  int x = 10, base = 1;
  for (; times; times >>= 1, x = x * x % mod)
    if (times & 1)
      base = base * x % mod;
  return base;
}

void Up(int &x, int y) { x = (x + y) % mod; }
signed main() {
  S = read();
  int lim = S / 8, now = 0;
  for (int i = 1; i < maxn; i++)
    digit[i] = digit[i / 10] + 1;
  for (int i = 1, now = 0, tem = 0; i < 1e7; i++) {
    while (tem < S) {
      tem += digit[now];
      now++;
    }
    if (tem == S) {
      ans += 1;
      if (ans >= mod)
        ans -= mod;
    }
    tem -= digit[i];
  }
  for (int i = 1; i <= lim; i++) {
    if (!(S % i)) {
      int l = S / i, sum = Qpow(l - 1) * 9 % mod;
      if (l < 8)
        continue;
      Up(ans, (sum - i + 1 + mod) % mod);
    } else {
      int l = (S - S % i) / i;
      if (l < 8)
        continue;
      ans += 1;
      if (ans >= mod)
        ans -= mod;
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define maxn 23000000
#define int long long
#define mod 1000000007
int digit[maxn], ans, S;

int read() {
  int x = 0, k = 1;
  char c;
  c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      k = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  return x * k;
}

int Qpow(int times) {
  int x = 10, base = 1;
  for (; times; times >>= 1, x = x * x % mod)
    if (times & 1)
      base = base * x % mod;
  return base;
}

void Up(int &x, int y) { x = (x + y) % mod; }
signed main() {
  S = read();
  int lim = S / 8, now = 0;
  for (int i = 1; i < maxn; i++)
    digit[i] = digit[i / 10] + 1;
  for (int i = 1, now = 0, tem = 0; i < 1e7; i++) {
    while (tem < S) {
      tem += digit[now];
      now++;
    }
    if (tem == S) {
      ans += 1;
      if (ans >= mod)
        ans -= mod;
    }
    tem -= digit[i];
  }
  for (int i = 1; i <= lim; i++) {
    if (!(S % i)) {
      int l = S / i, sum = Qpow(l - 1) * 9 % mod;
      if (l < 8)
        continue;
      Up(ans, (sum - i + 1 + mod) % mod);
    } else {
      int l = (S - S % i) / i;
      if (l < 8)
        continue;
      ans += 1;
      if (ans >= mod)
        ans -= mod;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03455 (C++)

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a * b / 2 % 0)
    cout << "Even" << endl;
  else
    cout << "Odd" << endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a * b % 2 == 0)
    cout << "Even" << endl;
  else
    cout << "Odd" << endl;
}
Problem p03455 (C++)

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

int main() {
  int a, b;
  scanf("%d %d", a, b);
  if ((a * b) % 2 == 0) {
    printf("Even");
  } else {
    printf("Odd");
  }
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  if ((a * b) % 2 == 0) {
    printf("Even");
  } else {
    printf("Odd");
  }
  return 0;
}
Problem p03455 (C++)

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a % 0 || b % 0) {
    cout << " Even " << endl;
  } else {
    cout << " Odd " << endl;
  }
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a % 2 == 0 || b % 2 == 0) {
    cout << " Even " << endl;
  } else {
    cout << " Odd " << endl;
  }
}
Problem p03455 (C++)

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

int main() {
  int a, b;
  scanf("%d%d", a, b);
  if ((a % 2 == 0) || (b % 2 == 0)) {
    printf("Even");
  } else {
    printf("Odd");
  }
}

Fixed submission:
#include <stdio.h>

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  if ((a % 2 == 0) || (b % 2 == 0)) {
    printf("Even");
  } else {
    printf("Odd");
  }
}
Problem p03455 (Python)

Buggy submission (status: Runtime Error):
a = int(input())
b = int(input())

if (a * b) % 2 == 0:
    print("Even")
else:
    print("Odd")


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

if (a * b) % 2 == 0:
    print("Even")
else:
    print("Odd")
Problem p03455 (Python)

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

if a * b % 2 == 0:
    print("Even")
else:
    print("Odd")


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

if a * b % 2 == 0:
    print("Even")
else:
    print("Odd")
Problem p03455 (Python)

Buggy submission (status: Runtime Error):
a, b = map(int, input().split())
ans = [0, 1]
print(ans[(a + b) / 2])


Fixed submission:
a, b = map(int, input().split())
ans = ["Even", "Odd"]
print(ans[(a * b) % 2])
Problem p03455 (Python)

Buggy submission (status: Runtime Error):
a = int(input())
b = int(input())
c = a * b
d = c % 2
if d == 0:
    print("Even")
else:
    print("Odd")


Fixed submission:
x = input().split()
# x = [3,4]
# x[0] = 3, x[1] = 4

a = int(x[0])
b = int(x[1])
c = a * b
d = c % 2
if d == 0:
    print("Even")
else:
    print("Odd")
Problem p03455 (Python)

Buggy submission (status: Runtime Error):
s = input().split()
a = s[0]
b = s[1]

if a % 2 == 0 or b % 2 == 0:
    print("Even")
else:
    print("Odd")


Fixed submission:
s = input().split()
a = int(s[0])
b = int(s[1])

if a % 2 == 0 or b % 2 == 0:
    print("Even")
else:
    print("Odd")
Problem p03455 (Python)

Buggy submission (status: Runtime Error):
a = int(input())
b = int(input())

x = a * b

if x % 2 == 0:
    answer = "Even"
elif x % 2 == 1:
    answer = "Odd"

print(answer)


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

if x % 2 == 0:
    answer = "Even"
elif x % 2 == 1:
    answer = "Odd"

print(answer)
Problem p03455 (C++)

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

using namespace std;

int main(void) {
  int a, b;
  scanf("%d%d", a, b);
  if (a * b % 2 == 0)
    printf("Even");
  else
    printf("Odd");
  return 0;
}

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

using namespace std;

int main(void) {
  int a, b;
  scanf("%d%d", &a, &b);
  if (a * b % 2 == 0)
    printf("Even");
  else
    printf("Odd");
  return 0;
}
Problem p03455 (Python)

Buggy submission (status: Runtime Error):
from sys import stdin

a = stdin.readline().rstrip()
a = int(a)

b = stdin.readline().rstrip()
b = int(b)

if a * b % 2 == 0:
    print("Even")
else:
    print("Odd")


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

if a * b % 2 == 0:
    print("Even")
else:
    print("Odd")
Problem p03455 (Python)

Buggy submission (status: Runtime Error):
n1 = int(input())
n2 = int(input())

s = n1 * n2

if s % 2 == 0:
    print("Even")
else:
    print("Odd")


Fixed submission:
a, b = map(int, input().split())
if (a * b) % 2 == 0:
    print("Even")
else:
    print("Odd")
Problem p03455 (C++)

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

int main() {
  int a, b;
  cin >> a >> b;

  if ((a * b) / 2 % 0) {
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
}

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

int main() {
  int a, b;
  cin >> a >> b;

  if ((a * b) % 2 == 0) {
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
}
Problem p03455 (C++)

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

int board[2010][2010];

int main() {
  int N, K;
  scanf("%d%d", &N, &K);

  int sum = 0, white = 0;
  for (int i = 0; i < N; i++) {
    int x, y;
    char c;
    scanf(" %d%d %c", &x, &y, &c);
    x %= 2 * K, y %= 2 * K;
    if (c == 'B')
      board[x + 1][y + 1]++, sum++;
    if (c == 'W')
      board[x + 1][y + 1]--, sum--, white++;
  }

  for (int i = 1; i <= 2 * K; i++) {
    for (int j = 1; j <= 2 * K; j++) {
      board[i][j] += board[i][j - 1];
    }
  }

  for (int j = 1; j <= 2 * K; j++) {
    for (int i = 1; i <= 2 * K; i++) {
      board[i][j] += board[i - 1][j];
    }
  }

  int ma = -(1 << 25);
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      int a = board[i][j];
      int b =
          board[i + K][j + K] - board[i + K][j] - board[i][j + K] + board[i][j];
      int c = board[2 * K][j] - board[i + K][j];
      int d = board[i][2 * K] - board[i][j + K];
      int e = board[2 * K][2 * K] - board[2 * K][j + K] - board[i + K][2 * K] +
              board[i + K][j + K];
      int tmp = a + b + c + d + e;
      ma = max(ma, max(tmp, sum - tmp));
    }
  }
  ma += white;
  printf("%d\n", ma);
  return 0;
}


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

signed main() {
  int a, b;
  cin >> a >> b;
  if ((a & 1) && (b & 1))
    cout << "Odd\n";
  else
    cout << "Even\n";
}
Problem p03455 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
using namespace std;
int main(void) {
  int left = 1, right = 100000000, mid, a, b;
  scanf("%d %d", &a, &b);
  while (left <= right) {
    mid = (left + right) / 2;
    if (mid == a * b)
      break;
    else if (mid > a * b)
      right = mid;
    else
      left = mid;
  }
  printf("%s\n", mid & 1 ? "Odd" : "Even");
  return 0;
}

Fixed submission:
#include <cstdio>

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  if (a % 2 == 1 && b % 2 == 1)
    printf("Odd");
  else
    printf("Even");
  return 0;
}
Problem p03455 (C++)

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

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

  if (A * B % 0) {
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
}


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

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

  if (A * B % 2 == 0) {
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
}
Problem p03455 (Python)

Buggy submission (status: Runtime Error):
a = int(input())
b = int(input())
rest = a * b % 2
if rest == 1:
    print("Odd")
else:
    print("Even")


Fixed submission:
a, b = map(int, input().split())
rest = a * b % 2
if rest == 1:
    print("Odd")
else:
    print("Even")
Problem p03455 (C++)

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

int main() {
  int a, b;
  cin >> a >> b;
  if ((a * b) % 2 == 0)
    cout << "Even" << endl;
  else
    cout << "Odd" << endl;

  return 1;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if ((a * b) % 2 == 0)
    cout << "Even" << endl;
  else
    cout << "Odd" << endl;
}
Problem p03456 (C++)

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

int main() {
  int a, b, c;
  cin >> a >> b;
  if (b / 10 == 0)
    c = a * 10 + b;
  else if (b / 10 < 10)
    c = a * 100 + b;
  else
    c = a * 1000 + b;
  for (int i = 0; i < c; i++) {
    if (c / i == i && c % i == 0) {
      cout << "Yes" << endl;
      break;
    }
    if (c == i + 1)
      cout << "No" << endl;
  }
}


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

int main() {
  int a, b, c;
  cin >> a >> b;
  if (b / 10 == 0)
    c = a * 10 + b;
  else if (b / 10 < 10)
    c = a * 100 + b;
  else
    c = a * 1000 + b;
  for (int i = 1; i < c; i++) {
    if (c / i == i && c % i == 0) {
      cout << "Yes" << endl;
      break;
    }
    if (c == i + 1)
      cout << "No" << endl;
  }
}
Problem p03456 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
int main() {
  int a, b;
  cin >> a >> b;
  bool k = false;
  for (int i = 0; i < 100; i++) {
    if ((a * 1000 + b) % i == 0 && (a * 1000 + b) / i == i)
      k = true;
  }
  if (k == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
int main() {
  int a, b;
  cin >> a >> b;
  bool k = false;
  int x;
  if (b / 10 == 0)
    x = a * 10 + b;
  else if (b / 100 == 0)
    x = a * 100 + b;
  else
    x = a * 1000 + b;
  for (int i = 1; i < 1000; i++) {
    if (i * i == x)
      k = true;
  }
  if (k == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p03456 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
using namespace std;
int a, b;
int c[5], d;
int main() {
  cin >> a >> b;
  d = 1;
  while (b) {
    c[d++] = b % 10;
    b /= 10;
  }
  for (int i = d - 1; i >= 1; i++)
    a = a * 10 + c[i];
  d = sqrt(a);
  if (d * d == a)
    cout << "Yes";
  else
    cout << "No";
}

Fixed submission:
#include <cmath>
#include <iostream>
using namespace std;
int a, b;
int c[5], d;
int main() {
  cin >> a >> b;
  d = 1;
  while (b) {
    c[d++] = b % 10;
    b /= 10;
  }
  for (int i = d - 1; i >= 1; i--)
    a = a * 10 + c[i];
  d = sqrt(a);
  if (d * d == a)
    cout << "Yes";
  else
    cout << "No";
}
Problem p03456 (C++)

Buggy submission (status: Runtime Error):
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
  char input[2][3];
  scanf("%s %s", input[0], input[1]);
  int num = atoi(strcat(input[0], input[1]));
  if (sqrt(num) == (int)sqrt(num))
    printf("Yes");
  else
    printf("No");
  return 0;
}

Fixed submission:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
  char input[2][4];
  if (scanf("%s %s", input[0], input[1]))
    ;
  int num = atoi(strcat(input[0], input[1]));
  if (sqrt(num) == (int)sqrt(num))
    printf("Yes");
  else
    printf("No");
  return 0;
}
Problem p03456 (Python)

Buggy submission (status: Runtime Error):
import math

a, b = input().split()
c = a + b
d = int(c)
e = math.sqrt(d) // 1
if d == e**e:
    print("Yes")
else:
    print("No")


Fixed submission:
import math

a, b = input().split()
c = a + b
d = int(c)
e = math.sqrt(d) // 1
if d == e * e:
    print("Yes")
else:
    print("No")
Problem p03456 (Python)

Buggy submission (status: Runtime Error):
num = int("".join(input().split()))

for i in range(num):
    if num / i == i:
        print("Yes")
        exit()

print("No")


Fixed submission:
num = int("".join(input().split()))

for i in range(1, num):
    if num / i == i:
        print("Yes")
        exit()

print("No")
Problem p03456 (Python)

Buggy submission (status: Runtime Error):
a = int(list(input().split()).join(""))
print("Yes" if int(a**0.5) == (a**0.5) else "No")


Fixed submission:
a = int("".join(list(input().split())))
print("Yes" if int(a**0.5) == (a**0.5) else "No")
Problem p03456 (C++)

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

int main() {
  ifstream in("../input.txt");
  cin.rdbuf(in.rdbuf());

  string a, b;
  cin >> a >> b;
  int num = stoi(a + b);
  for (ll i = 1; i < 1000; ++i) {
    if (i * i == num) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

int main() {

  string a, b;
  cin >> a >> b;
  int num = stoi(a + b);
  for (ll i = 1; i < 1000; ++i) {
    if (i * i == num) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}
Problem p03456 (C++)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < n; ++i)
#define FORR(i, s, n) for (int i = n - 1; i >= s; --i)
#define ALL(c) (c).begin(), (c).end()
#define CLEAR(v) memset(v, 0, sizeof(v))
#define MP(a, b) make_pair((a), (b))
#define ABS(a) ((a) > 0 ? (a) : -(a))
#define F first
#define S second

int main(int argc, char **argv) {
  ll a, b;
  cin >> a >> b;
  if (b < 10)
    b += a * 10;
  else if (b < 100)
    b += a * 100;
  else
    b += a * 1000;
  ll i = 1;
  while (i * i <= b)
    if (i * i == b) {
      cout << "Yes" << endl;
      return 0;
    }
  cout << "No" << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < n; ++i)
#define FORR(i, s, n) for (int i = n - 1; i >= s; --i)
#define ALL(c) (c).begin(), (c).end()
#define CLEAR(v) memset(v, 0, sizeof(v))
#define MP(a, b) make_pair((a), (b))
#define ABS(a) ((a) > 0 ? (a) : -(a))
#define F first
#define S second

int main(int argc, char **argv) {
  ll a, b;
  cin >> a >> b;
  if (b < 10)
    b += a * 10;
  else if (b < 100)
    b += a * 100;
  else
    b += a * 1000;
  ll i = 1;
  for (ll i = 1; i * i <= b; ++i)
    if (i * i == b) {
      cout << "Yes" << endl;
      return 0;
    }
  cout << "No" << endl;
  return 0;
}
Problem p03456 (C++)

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

using namespace std;

typedef long long LL;

const int N = 1010;

string a, b;

int main() {
  cin >> a >> b;

  string s = a + b;

  int n = 0;

  for (int i = 0; i < s.size(); i++)
    n = n * 10 + s[i] - '0';

  for (int i = 0; i <= n / i; i++)
    if (i * i == n) {
      puts("Yes");
      return 0;
    }
  puts("No");
  return 0;
}


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

using namespace std;

typedef long long LL;

const int N = 1010;

string a, b;

int main() {
  cin >> a >> b;

  string s = a + b;

  int n = 0;

  for (int i = 0; i < s.size(); i++)
    n = n * 10 + s[i] - '0';

  for (int i = 1; i <= n / i; i++)
    if (i * i == n) {
      puts("Yes");
      return 0;
    }
  puts("No");
  return 0;
}
Problem p03456 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
#ifdef LOACL
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  int a, b;
  scanf("%d %d", &a, &b);
  char x[3];
  sprintf(x, "%d", b);
  for (int i = 0; i < strlen(x); i++)
    a = a * 10 + x[i] - '0';
  double t = sqrt(a);
  if ((int)t * t != a)
    printf("No\n");
  else
    printf("Yes\n");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
#ifdef LOACL
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  int a, b;
  scanf("%d %d", &a, &b);
  char x[5];
  sprintf(x, "%d", b);
  for (int i = 0; i < strlen(x); i++)
    a = a * 10 + x[i] - '0';
  double t = sqrt(a);
  if ((int)t * t != a)
    printf("No\n");
  else
    printf("Yes\n");
  return 0;
}