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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <typeinfo>
#include <vector>

using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define llrep(i, m, n) for (ll i = m; i < n; ++i)
#define inf 1000000000
#define llinf 1000000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(), v.end()

ll edge[1100][1100], dist[1100];
queue<int> q;

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, 0, 1100) {
    rep(j, 0, 1100) { edge[i][j] = -llinf; }
  }
  rep(i, 0, m) {
    ll a, b, c;
    cin >> a >> b >> c;
    edge[a][b] = c;
  }
  rep(i, 0, 1100) { dist[i] = -llinf; }
  dist[1] = 0;
  q.push(1);
  int co = 0;
  ll ans;
  while (!q.empty()) {
    int hoge = q.front();
    q.pop();
    if (co = 2 * m) {
      ans = dist[n];
    } else if (co == 3 * m) {
      if (ans == dist[n]) {
        cout << ans << endl;
      } else {
        cout << "inf" << endl;
      }
      return 0;
    }

    co++;
    rep(i, 1, n + 1) {
      if (edge[hoge][i] != -llinf && dist[i] < dist[hoge] + edge[hoge][i]) {
        q.push(i);
        dist[i] = dist[hoge] + edge[hoge][i];
      }
    }
  }
  cout << dist[n] << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <typeinfo>
#include <vector>

using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define llrep(i, m, n) for (ll i = m; i < n; ++i)
#define inf 1000000000
#define llinf 1000000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(), v.end()

ll edge[1100][1100], dist[1100];
queue<int> q;

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, 0, 1100) {
    rep(j, 0, 1100) { edge[i][j] = -llinf; }
  }
  rep(i, 0, m) {
    ll a, b, c;
    cin >> a >> b >> c;
    edge[a][b] = c;
  }
  rep(i, 0, 1100) { dist[i] = -llinf; }
  dist[1] = 0;
  q.push(1);
  int co = 0;
  ll ans;
  while (!q.empty()) {
    int hoge = q.front();
    q.pop();
    if (co == 2 * m) {
      ans = dist[n];
    } else if (co == 3 * m) {
      if (ans == dist[n]) {
        cout << ans << endl;
      } else {
        cout << "inf" << endl;
      }
      return 0;
    }

    co++;
    rep(i, 1, n + 1) {
      if (edge[hoge][i] != -llinf && dist[i] < dist[hoge] + edge[hoge][i]) {
        q.push(i);
        dist[i] = dist[hoge] + edge[hoge][i];
      }
    }
  }
  cout << dist[n] << endl;
  return 0;
}
Problem p03722 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 50;

int main(void) {
  int N, M;
  cin >> N >> M;
  const int NMAX = 1000;
  const int MMAX = 2000;
  int a[MMAX], b[MMAX];
  ll c[MMAX];

  for (int i = 1; i <= M; ++i) {
    cin >> a[i] >> b[i] >> c[i];
    c[i] = -c[i];
  }

  ll dist[NMAX];
  bool negative[NMAX];
  memset(dist, 0x3f, sizeof dist);
  memset(negative, 0, sizeof negative);
  dist[1] = 0;

  for (int loop = 0; loop < N - 1; ++loop) {
    for (int i = 1; i <= M; ++i) {

      if (dist[a[i]] == INF)
        continue;

      if (dist[b[i]] > dist[a[i]] + c[i]) {
        dist[b[i]] = dist[a[i]] + c[i];
      }
    }
  }

  ll ans = dist[N];

  for (int loop = 0; loop < N; ++loop) {
    for (int i = 1; i <= M; ++i) {
      if (dist[a[i]] == INF)
        continue;

      if (dist[b[i]] > dist[a[i]] + c[i]) {
        dist[b[i]] = dist[a[i]] + c[i];
        negative[b[i]] = true;
      }

      if (negative[a[i]] == true) {
        negative[b[i]] = true;
      }
    }
  }

  if (negative[N])
    cout << "inf" << endl;
  else
    cout << -ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 50;

int main(void) {
  int N, M;
  cin >> N >> M;
  const int NMAX = 1010;
  const int MMAX = 2010;
  int a[MMAX], b[MMAX];
  ll c[MMAX];

  for (int i = 1; i <= M; ++i) {
    cin >> a[i] >> b[i] >> c[i];
    c[i] = -c[i];
  }

  ll dist[NMAX];
  bool negative[NMAX];
  memset(dist, 0x3f, sizeof dist);
  memset(negative, 0, sizeof negative);
  dist[1] = 0;

  for (int loop = 0; loop < N - 1; ++loop) {
    for (int i = 1; i <= M; ++i) {

      if (dist[a[i]] == INF)
        continue;

      if (dist[b[i]] > dist[a[i]] + c[i]) {
        dist[b[i]] = dist[a[i]] + c[i];
      }
    }
  }

  ll ans = dist[N];

  for (int loop = 0; loop < N; ++loop) {
    for (int i = 1; i <= M; ++i) {
      if (dist[a[i]] == INF)
        continue;

      if (dist[b[i]] > dist[a[i]] + c[i]) {
        dist[b[i]] = dist[a[i]] + c[i];
        negative[b[i]] = true;
      }

      if (negative[a[i]] == true) {
        negative[b[i]] = true;
      }
    }
  }

  if (negative[N])
    cout << "inf" << endl;
  else
    cout << -ans << endl;

  return 0;
}
Problem p03722 (C++)

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x)
#define bg begin()
#define ed end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
const ll INF = 1000000000000000;

struct edge {
  ll from, to, cost;
};             //?から?まで?コスト
edge es[2000]; // 辺

vector<ll> d(1001, 0); // 最短距離

ll N, E; // 頂点数、辺数

bool find_negative_loop() {
  rep(i, N * 2) {
    rep(j, E) {
      edge e = es[j];
      if (d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;

        // n回目にも更新があるなら負の閉路が存在
        if (i >= N && e.to == N)
          return true;
      }
    }
  }
  return false;
}

void shortest_path(ll s) { // s番目の頂点からの各点の最短距離を出す
  rep(i, N + 1) d[i] = INF;
  d[s] = 0;
  while (true) {
    bool update = false;
    rep(i, E) {
      edge e = es[i];
      if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
        update = true;
      }
    }
    if (!update)
      break;
  }
}

int main() {
  cin >> N >> E; // 辺数
  // Vコの辺の情報入力
  rep(i, E) {
    ll from, to, cost;
    cin >> from >> to >> cost;
    es[i].from = from;
    es[i].to = to;
    es[i].cost = cost * (-1);
  }

  bool loop = find_negative_loop();
  if (loop)
    cout << "inf";
  else {
    shortest_path(1);
    cout << d[N] * (-1);
  }
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x)
#define bg begin()
#define ed end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
const ll INF = 1000000000000000;

struct edge {
  ll from, to, cost;
};             //?から?まで?コスト
edge es[2000]; // 辺

vector<ll> d(1001, 0); // 最短距離

ll N, E; // 頂点数、辺数

bool find_negative_loop() {
  rep(i, N * 2) {
    rep(j, E) {
      edge e = es[j];
      if (d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;

        // n回目にも更新があるなら負の閉路が存在
        if (i >= N && e.to == N)
          return true;
      }
    }
  }
  return false;
}

void shortest_path(ll s) { // s番目の頂点からの各点の最短距離を出す
  rep(i, N + 1) d[i] = INF;
  d[s] = 0;
  rep(i, N * 2) {
    bool update = false;
    rep(i, E) {
      edge e = es[i];
      if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
        update = true;
      }
    }
    if (!update)
      break;
  }
}

int main() {
  cin >> N >> E; // 辺数
  // Vコの辺の情報入力
  rep(i, E) {
    ll from, to, cost;
    cin >> from >> to >> cost;
    es[i].from = from;
    es[i].to = to;
    es[i].cost = cost * (-1);
  }

  bool loop = find_negative_loop();
  if (loop)
    cout << "inf";
  else {
    shortest_path(1);
    cout << d[N] * (-1);
  }
}
Problem p03722 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stdint.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

#define repi(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) for (ll i = 0; i < (n); ++i)

ll inf = 1000000000000000000;

using P = pair<ll, ll>;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> d(N);
  d[0] = 0;
  repi(i, 1, N) d[i] = inf;
  vector<P> ed(M);
  vector<ll> cost(M);
  rep(i, M) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    ed[i] = P(a, b);
    cost[i] = -c;
  }
  rep(i, N) {
    rep(j, M) {
      ll from = ed[j].first;
      ll to = ed[j].second;
      if (d[from] == inf)
        continue;
      if (d[to] > d[from] + cost[j]) {
        d[to] = d[from] + cost[j];
        if (i == N - 1) {
          queue<ll> q;
          q.push(to);
          while (!q.empty()) {
            ll x = q.front();
            d[x] = -inf;
            rep(k, M) if (ed[k].first == x && d[ed[k].second] != -inf)
                q.push(ed[k].second);
          }
        }
      }
    }
  }
  if (d[N - 1] == -inf)
    cout << "inf" << endl;
  else
    cout << -d[N - 1] << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stdint.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

#define repi(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) for (ll i = 0; i < (n); ++i)

ll inf = 1000000000000000000;

using P = pair<ll, ll>;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> d(N);
  d[0] = 0;
  repi(i, 1, N) d[i] = inf;
  vector<P> ed(M);
  vector<ll> cost(M);
  rep(i, M) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    ed[i] = P(a, b);
    cost[i] = -c;
  }
  rep(i, N) {
    rep(j, M) {
      ll from = ed[j].first;
      ll to = ed[j].second;
      if (d[from] == inf)
        continue;
      if (d[to] > d[from] + cost[j]) {
        d[to] = d[from] + cost[j];
        if (i == N - 1) {
          queue<ll> q;
          q.push(to);
          while (!q.empty()) {
            ll x = q.front();
            q.pop();
            d[x] = -inf;
            rep(k, M) if (ed[k].first == x && d[ed[k].second] != -inf)
                q.push(ed[k].second);
          }
        }
      }
    }
  }
  if (d[N - 1] == -inf)
    cout << "inf" << endl;
  else
    cout << -d[N - 1] << endl;
  return 0;
}
Problem p03722 (C++)

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

using namespace std;
using ll = long long;
struct Edge {
  int a, b, c;
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> cost(n, LLONG_MIN);
  cost[0] = 0;
  vector<Edge> edge(m);
  for (int i = 0; i < m; ++i) {
    cin >> edge[i].a >> edge[i].b >> edge[i].c;
    --edge[i].a, --edge[i].b;
  }
  bool flag;
  int k;
  for (k = 0; k < n; ++k) {
    flag = true;
    for (int i = 0; i < m; ++i) {
      if (cost[edge[i].a] == LLONG_MIN)
        continue;
      if (cost[edge[i].b] < cost[edge[i].a] + edge[i].c) {
        cost[edge[i].b] = cost[edge[i].a] + edge[i].c;
        flag = false;
      }
    }
    // for(int i=0;i<n;++i){
    //     cout << i << " " << cost[i] << endl;
    // }
    if (flag)
      break;
  }
  if (k == n && !flag) {
    ll c = cost[n - 1];
    for (int i = 0; i < m; ++i) {
      if (cost[edge[i].a] == LLONG_MIN)
        continue;
      if (cost[edge[i].b] < cost[edge[i].a] + edge[i].c) {
        cost[edge[i].b] = cost[edge[i].a] + edge[i].c;
      }
    }
    if (c != cost[n - 1])
      cout << "inf";
    else
      cout << cost[c - 1];
  } else {
    cout << cost[n - 1];
  }
  return 0;
}

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

using namespace std;
using ll = long long;
struct Edge {
  int a, b, c;
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> cost(n, LLONG_MIN);
  cost[0] = 0;
  vector<Edge> edge(m);
  for (int i = 0; i < m; ++i) {
    cin >> edge[i].a >> edge[i].b >> edge[i].c;
    --edge[i].a, --edge[i].b;
  }
  bool flag;
  int k;
  for (k = 0; k < n; ++k) {
    flag = true;
    for (int i = 0; i < m; ++i) {
      if (cost[edge[i].a] == LLONG_MIN)
        continue;
      if (cost[edge[i].b] < cost[edge[i].a] + edge[i].c) {
        cost[edge[i].b] = cost[edge[i].a] + edge[i].c;
        flag = false;
      }
    }
    // for(int i=0;i<n;++i){
    //     cout << i << " " << cost[i] << endl;
    // }
    if (flag)
      break;
  }
  if (k == n && !flag) {
    ll c = cost[n - 1];
    for (int i = 0; i < m; ++i) {
      if (cost[edge[i].a] == LLONG_MIN)
        continue;
      if (cost[edge[i].b] < cost[edge[i].a] + edge[i].c) {
        cost[edge[i].b] = cost[edge[i].a] + edge[i].c;
      }
    }
    if (c != cost[n - 1])
      cout << "inf";
    else
      cout << cost[n - 1];
  } else {
    cout << cost[n - 1];
  }
  return 0;
}
Problem p03722 (C++)

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

// 頂点fromから頂点toへのコストcostの辺
struct edge {
  long long from, to, cost;
};

edge es[2005]; // 辺

long long d[2005]; // 最短距離

#define INF LONG_MAX / 3

long long V, E; // Vは頂点数、Eは辺数

int main() {
  cin >> V >> E;
  for (long long i = 0; i < E; i++) {
    cin >> es[i].from >> es[i].to >> es[i].cost;
    es[i].from--;
    es[i].to--;
    es[i].cost *= -1;
  }

  long long upnum = 0;
  for (int i = 0; i < V; i++) {
    d[i] = INF;
  }
  d[0] = 0;
  while (true) {
    bool update = false;
    for (int i = 0; i < E; i++) {
      edge e = es[i];
      if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
        update = true;
        if (upnum > V - 1 && e.to == V - 1) {
          cout << "inf" << endl;
          return 0;
        }
      }
    }
    if (!update)
      break;
    upnum++;
  }

  cout << -1 * d[V - 1] << endl;
}


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

// 頂点fromから頂点toへのコストcostの辺
struct edge {
  long long from, to, cost;
};

edge es[2005]; // 辺

long long d[2005]; // 最短距離

#define INF LONG_MAX / 3

long long V, E; // Vは頂点数、Eは辺数

int main() {
  cin >> V >> E;
  for (long long i = 0; i < E; i++) {
    cin >> es[i].from >> es[i].to >> es[i].cost;
    es[i].from--;
    es[i].to--;
    es[i].cost *= -1;
  }

  long long upnum = 0;
  for (int i = 0; i < V; i++) {
    d[i] = INF;
  }
  d[0] = 0;
  while (true) {
    bool update = false;
    for (int i = 0; i < E; i++) {
      edge e = es[i];
      if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
        update = true;
        if (upnum > V - 1 && e.to == V - 1) {
          cout << "inf" << endl;
          return 0;
        }
      }
    }
    if (!update)
      break;
    upnum++;
    if (upnum > 5 * V)
      break;
  }

  cout << -1 * d[V - 1] << endl;
}
Problem p03722 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstring>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#pragma warning(disable : 4996)

typedef long long ll;
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;

struct Edge {
  long from;
  long to;
  long cost;
};

int main(int argc, char *argv[]) {
  long n, m;
  scanf("%ld%ld", &n, &m);

  vector<Edge> zz(m);
  long i;
  for (i = 0; i < m; i++) {
    long a, b, c;
    scanf("%ld%ld%ld", &a, &b, &c);
    Edge e = {a - 1, b - 1, -c};
    zz[i] = e;
  }

  vector<ll> dist(n, LINF);
  dist[0] = 0;
  long count = 0;
  ll ans_save = 0;
  while (1) {
    bool update = false;
    for (i = 0; i < m; i++) {
      Edge e = zz[i];
      if (dist[e.from] != LINF && dist[e.to] > dist[e.from] + e.cost) {
        dist[e.to] = dist[e.from] + e.cost;
        update = true;
      }
    }
    if (!update)
      break;

    count++;
    if (count > n) {
      ans_save = -dist[n - 1];
    } else if (count > 2 * n) {
      if (ans_save != -LINF && ans_save == -dist[n - 1]) {
        printf("%lld\n", ans_save);
        return 0;
      }

      printf("inf\n");
      return 0;
    }
  }
  printf("%lld\n", -dist[n - 1]);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstring>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#pragma warning(disable : 4996)

typedef long long ll;
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;

struct Edge {
  long from;
  long to;
  long cost;
};

int main(int argc, char *argv[]) {
  long n, m;
  scanf("%ld%ld", &n, &m);

  vector<Edge> zz(m);
  long i;
  for (i = 0; i < m; i++) {
    long a, b, c;
    scanf("%ld%ld%ld", &a, &b, &c);
    Edge e = {a - 1, b - 1, -c};
    zz[i] = e;
  }

  vector<ll> dist(n, LINF);
  dist[0] = 0;
  long count = 0;
  ll ans_save = 0;
  while (1) {
    bool update = false;
    for (i = 0; i < m; i++) {
      Edge e = zz[i];
      if (dist[e.from] != LINF && dist[e.to] > dist[e.from] + e.cost) {
        dist[e.to] = dist[e.from] + e.cost;
        update = true;
      }
    }
    if (!update)
      break;

    count++;
    if (count == n) {
      ans_save = -dist[n - 1];
    } else if (count > 2 * n) {
      if (ans_save != -LINF && ans_save == -dist[n - 1]) {
        printf("%lld\n", ans_save);
        return 0;
      }

      printf("inf\n");
      return 0;
    }
  }
  printf("%lld\n", -dist[n - 1]);

  return 0;
}
Problem p03722 (C++)

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 1 << 30;
constexpr int mo = 1e9 + 7;
constexpr ll infl = 1ll << 60;

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

  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int>> v;
  for (int i = 0; i < n; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    v.emplace_back(a, b, -c);
  }
  vector<ll> dp(n, infl);
  dp[0] = 0;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = 0; j < m; ++j) {
      int a, b, c;
      tie(a, b, c) = v[j];
      dp[b] = min(dp[b], dp[a] + c);
    }
  }
  ll ret = -dp[n - 1];
  for (int i = 0; i < 2000; ++i) {
    for (int j = 0; j < m; ++j) {
      int a, b, c;
      tie(a, b, c) = v[j];
      dp[b] = min(dp[b], dp[a] + c);
    }
  }
  if (ret < -dp[n - 1])
    cout << "inf" << endl;
  else
    cout << ret << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 1 << 30;
constexpr int mo = 1e9 + 7;
constexpr ll infl = 1ll << 60;

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

  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int>> v;
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    v.emplace_back(a, b, -c);
  }
  vector<ll> dp(n, infl);
  dp[0] = 0;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = 0; j < m; ++j) {
      int a, b, c;
      tie(a, b, c) = v[j];
      dp[b] = min(dp[b], dp[a] + c);
    }
  }
  ll ret = -dp[n - 1];
  for (int i = 0; i < 2000; ++i) {
    for (int j = 0; j < m; ++j) {
      int a, b, c;
      tie(a, b, c) = v[j];
      dp[b] = min(dp[b], dp[a] + c);
    }
  }
  if (ret < -dp[n - 1])
    cout << "inf" << endl;
  else
    cout << ret << endl;
  return 0;
}
Problem p03723 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B && B == C && C == A && A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
    cout << -1 << endl;
  }
  int counter = 0;
  int tmpa, tmpb, tmpc;
  while (A % 2 == 0 && B % 2 == 0 & C % 2 == 0) {
    tmpa = A;
    tmpb = B;
    tmpc = C;
    A = (tmpb + tmpc) / 2;
    B = (tmpa + tmpc) / 2;
    C = (tmpa + tmpb) / 2;
    counter++;
  }
  cout << counter << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B && B == C && C == A && A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int counter = 0;
  int tmpa, tmpb, tmpc;
  while (A % 2 == 0 && B % 2 == 0 & C % 2 == 0) {
    tmpa = A;
    tmpb = B;
    tmpc = C;
    A = (tmpb + tmpc) / 2;
    B = (tmpa + tmpc) / 2;
    C = (tmpa + tmpb) / 2;
    counter++;
  }
  cout << counter << endl;
}
Problem p03723 (C++)

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int>> vp;

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define For(i, a, n) for (int i = a; i < (n); i++)
#define out(n) cout << (n) << endl;
#define vut(v) rep(i, v.size()) out(v[i]);

int main() {
  int a, b, c, ans = 0;
  cin >> a >> b >> c;

  if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0 && a == b == c) {
    out(-1);
    return 0;
  }

  while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    ans++;

    int aa = b / 2 + c / 2, bb = a / 2 + c / 2;

    c = a / 2 + b / 2;
    a = aa;
    b = bb;
  }

  out(ans)
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int>> vp;

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define For(i, a, n) for (int i = a; i < (n); i++)
#define out(n) cout << (n) << endl;
#define vut(v) rep(i, v.size()) out(v[i]);

int main() {
  int a, b, c, ans = 0;
  cin >> a >> b >> c;

  if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0 && a == b && a == c) {
    out(-1);
    return 0;
  }

  while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    ans++;

    int aa = b / 2 + c / 2, bb = a / 2 + c / 2;

    c = a / 2 + b / 2;
    a = aa;
    b = bb;
  }

  out(ans)
}
Problem p03723 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <ciso646>
#include <cstdio>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  } else if (a % b) {
    return gcd(b, a % b);
  } else {
    return b;
  }
}
int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll ans = 0;
  if (a == b && b == c && a % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    ans++;
    int x = (b + c) / 2, y = (c + a) / 2, z = (a + b) / 2;
    a = x, y = b, z = c;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <ciso646>
#include <cstdio>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  } else if (a % b) {
    return gcd(b, a % b);
  } else {
    return b;
  }
}
int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll ans = 0;
  if (a == b && b == c && a % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    ans++;
    int x = (b + c) / 2, y = (c + a) / 2, z = (a + b) / 2;
    a = x, b = y, c = z;
  }
  cout << ans << endl;
}
Problem p03723 (C++)

Buggy submission (status: Time Limit Exceeded):
// q1
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define pb push_back
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int INF = 2147483647;
const ll INFLL = 9223372036854775807;

int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  int i_a = a, i_b = b, i_c = c;
  int pre_a = a, pre_b = b, pre_c = c;
  int ans = 0;
  while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    a = pre_b / 2 + pre_c / 2;
    b = pre_c / 2 + pre_a / 2;
    c = pre_a / 2 + pre_b / 2;
    if (i_a == a && i_b == b && i_c == c) {
      ans = -1;
    }
    if (ans == 10000) {
      i_a = a;
      i_b = b;
      i_c = c;
    }
    pre_a = a;
    pre_b = b;
    pre_c = c;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
// q1
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define pb push_back
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int INF = 2147483647;
const ll INFLL = 9223372036854775807;

int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  int i_a = a, i_b = b, i_c = c;
  int pre_a = a, pre_b = b, pre_c = c;
  int ans = 0;
  while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    a = pre_b / 2 + pre_c / 2;
    b = pre_c / 2 + pre_a / 2;
    c = pre_a / 2 + pre_b / 2;
    if (i_a == a && i_b == b && i_c == c) {
      ans = -1;
      break;
    }
    if (ans == 10000) {
      i_a = a;
      i_b = b;
      i_c = c;
    }
    pre_a = a;
    pre_b = b;
    pre_c = c;
    ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03723 (C++)

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

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  int a, b, c;
  cin >> a >> b >> c;
  for (int i = 0; i < 1e9; i++) {
    if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
      cout << i << endl;
      return 0;
    }
    int cur_a = (b + c) / 2;
    int cur_b = (a + c) / 2;
    int cur_c = (b + a) / 2;
    a = cur_a, b = cur_b, c = cur_c;
  }
  cout << -1 << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define alpha_size 26

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  int a, b, c;
  cin >> a >> b >> c;
  for (int i = 0; i < 1e7; i++) {
    if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
      cout << i << endl;
      return 0;
    }
    int cur_a = (b + c) / 2;
    int cur_b = (a + c) / 2;
    int cur_c = (b + a) / 2;
    a = cur_a, b = cur_b, c = cur_c;
  }
  cout << -1 << endl;
}
Problem p03723 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int a, b, c, A, B, C;
  cin >> a >> b >> c;
  if (a == b * b == c) {
    cout << (a % 2 ? 0 : -1) << endl;
    return 0;
  }
  for (int cnt = 0;; a = A, b = B, c = C, cnt++) {
    if (a % 2 | b % 2 | c % 2) {
      cout << cnt << endl;
      return 0;
    }
    A = (b + c) / 2, B = (a + c) / 2, C = (a + b) / 2;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a, b, c, A, B, C;
  cin >> a >> b >> c;
  if (a == b && b == c) {
    cout << (a % 2 ? 0 : -1) << endl;
    return 0;
  }
  for (int cnt = 0;; a = A, b = B, c = C, cnt++) {
    if (a % 2 | b % 2 | c % 2) {
      cout << cnt << endl;
      return 0;
    }
    A = (b + c) / 2, B = (a + c) / 2, C = (a + b) / 2;
  }
  return 0;
}
Problem p03723 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main() {
  long long a, b, c, old_a, old_b, old_c;
  cin >> a >> b >> c;
  int count = 0;
  if (a == b == c) {
    if (a % 2 == 0) {
      cout << -1 << endl;
    } else {
      cout << 0 << endl;
    }
  } else {
    while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
      old_a = a;
      old_b = b;
      old_c = c;
      a = (old_b + old_c) / 2;
      b = (old_a + old_c) / 2;
      c = (old_a + old_b) / 2;
      count++;
    }
    cout << count << endl;
  }
  return 0;
}

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

int main() {
  long long a, b, c, old_a, old_b, old_c;
  cin >> a >> b >> c;
  int count = 0;
  if (a == b && b == c) {
    if (a % 2 == 0) {
      cout << -1 << endl;
    } else {
      cout << 0 << endl;
    }
  } else {
    while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
      old_a = a;
      old_b = b;
      old_c = c;
      a = (old_b + old_c) / 2;
      b = (old_a + old_c) / 2;
      c = (old_a + old_b) / 2;
      count++;
    }
    cout << count << endl;
  }
  return 0;
}
Problem p03723 (C++)

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

int main() {
  int64_t A, B, C, ans = 0;
  cin >> A >> B >> C;
  if (A == B && B == C && A & 2 == 0) {
    cout << -1 << endl;
  } else {
    while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
      int64_t a = A / 2, b = B / 2, c = C / 2;
      A = b + c;
      B = c + a;
      C = a + b;
      ans++;
    }
    cout << ans << endl;
  }
}

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

int main() {
  int64_t A, B, C, ans = 0;
  cin >> A >> B >> C;
  if (A == B && B == C) {
    if (A % 2)
      cout << 0 << endl;
    else
      cout << -1 << endl;
  } else {
    while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
      int64_t a = A / 2, b = B / 2, c = C / 2;
      A = b + c;
      B = c + a;
      C = a + b;
      ans++;
    }
    cout << ans << endl;
  }
}
Problem p03723 (C++)

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

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  /*
          a < b < c として, 最大 - 最小は
          c - a
          ->
          (b+c)/2 - (a+b)/2 = (c-a)/2
          ->
          (a+b+2c)/4 - (2a+b+c)/4 = (c-a)/4
  */
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);

  set<tuple<int, int, int>> S;
  while (S.count(make_tuple(a, b, c)) == 0) {
    if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1)
      return printf("%lu\n", S.size());
    S.emplace(a, b, c);
    tie(a, b, c) = make_tuple((b + c) / 2, (a + c) / 2, (a + b) / 2);
  }
  puts("-1");

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  /*
          a < b < c として, 最大 - 最小は
          c - a
          ->
          (b+c)/2 - (a+b)/2 = (c-a)/2
          ->
          (a+b+2c)/4 - (2a+b+c)/4 = (c-a)/4
  */
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);

  set<tuple<int, int, int>> S;
  while (S.count(make_tuple(a, b, c)) == 0) {
    if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1)
      return printf("%lu\n", S.size()), 0;
    S.emplace(a, b, c);
    tie(a, b, c) = make_tuple((b + c) / 2, (a + c) / 2, (a + b) / 2);
  }
  puts("-1");

  return 0;
}
Problem p03723 (C++)

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

template <class T> T abs(T a) { return a > 0 ? a : -a; }

int main() {
  long long a, b, c, ret = 0;
  scanf("%lld%lld%lld", &a, &b, &c);

  auto k = abs(a - b), l = abs(b - c), m = abs(c - a);
  if (k == 0 && l == 0 && m == 0 && a % 2 == 0 && b % 2 == 0 && c % 2 == 0)
    ret = -1;
  else {
    for (;; ret++) {
      if ((k & 1) || (l & 1) || (m & 1))
        break;
      k >>= 1;
      l >>= 1;
      m >>= 1;
    }
  }

  printf("%lld\n", ret);

  return 0;
}

Fixed submission:
#include <cstdio>

template <class T> T abs(T a) { return a > 0 ? a : -a; }

int main() {
  long long a, b, c, ret = 0;
  scanf("%lld%lld%lld", &a, &b, &c);

  auto k = abs(a - b), l = abs(b - c), m = abs(c - a);
  if (k == 0 && l == 0 && m == 0 && a % 2 == 0 && b % 2 == 0 && c % 2 == 0)
    ret = -1;
  else if (a % 2 || b % 2 || c % 2)
    ret = 0;
  else {
    for (;; ret++) {
      if ((k & 1) || (l & 1) || (m & 1))
        break;
      k >>= 1;
      l >>= 1;
      m >>= 1;
    }
  }

  printf("%lld\n", ret);

  return 0;
}
Problem p03723 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, bg, ed) for (ll i = (bg); i < (ed); i++)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

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

  if (A == B && B == C) {
    assert(false);
    cout << -1 << endl;
    return 0;
  }

  int ans = 0;
  while (true) {
    if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1)
      break;
    int nA = 0, nB = 0, nC = 0;
    nA = B / 2 + C / 2;
    nB = A / 2 + C / 2;
    nC = A / 2 + B / 2;
    A = nA;
    B = nB;
    C = nC;
    ans++;
  }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, bg, ed) for (ll i = (bg); i < (ed); i++)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

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

  if (A == B && B == C) {
    if (A % 2 == 1) {
      cout << 0 << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }

  int ans = 0;
  while (true) {
    if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1)
      break;
    int nA = 0, nB = 0, nC = 0;
    nA = B / 2 + C / 2;
    nB = A / 2 + C / 2;
    nC = A / 2 + B / 2;
    A = nA;
    B = nB;
    C = nC;
    ans++;
  }

  cout << ans << endl;
}
Problem p03723 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, int> pli;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
  ll a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3, greater<int>());
  ll x = a[0] - a[2], y = a[1] - a[2];
  if (x == 0 && y == 0 && (a[0] % 2 == 0 && a[1] % 2 == 0 && a[2] % 2 == 0)) {
    cout << -1 << endl;
    return 0;
  }
  ll cnt = 0;
  while (x % 2 == 0 && y % 2 == 0) {
    ll nx = max(x, y) / 2;
    ll ny = abs(x - y) / 2;
    x = nx;
    y = ny;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, int> pli;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
  ll a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3, greater<int>());
  ll x = a[0] - a[2], y = a[1] - a[2];
  if (x == 0 && y == 0) {
    if (a[0] % 2 == 0 && a[1] % 2 == 0 && a[2] % 2 == 0) {
      cout << -1 << endl;
      return 0;
    } else {
      cout << 0 << endl;
      return 0;
    }
  }
  ll cnt = 0;
  while (x % 2 == 0 && y % 2 == 0) {
    ll nx = max(x, y) / 2;
    ll ny = abs(x - y) / 2;
    x = nx;
    y = ny;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p03723 (C++)

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int P, Q;
  P = abs(A - B);
  Q = abs(A - C);

  if (A == B && A == C && A % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }

  int ans = 0;
  for (;;) {
    if (P % 2 == 1 || Q % 2 == 1) {
      break;
    }
    ans++;
    P = P / 2;
    Q = Q / 2;
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int P, Q;
  P = abs(A - B);
  Q = abs(A - C);

  if (A == B && A == C && A % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (A == B && A == C && A % 2 == 1) {
    cout << 0 << endl;
    return 0;
  }

  int ans = 0;
  for (;;) {
    if (P % 2 == 1 || Q % 2 == 1) {
      break;
    }
    ans++;
    P = P / 2;
    Q = Q / 2;
  }
  cout << ans << endl;

  return 0;
}
Problem p03723 (Python)

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

while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    if a == b == c:
        print(-1)
        exit()
    a, b, c = (b + c) // 2, (c + a) // 2, (a + b) // 2
    ans += 1
print(ans)


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

while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    if a == b == c:
        print(-1)
        exit()
    a, b, c = (b + c) // 2, (c + a) // 2, (a + b) // 2
    ans += 1
print(ans)
Problem p03723 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
int ans, A, B, C;
int main() {
  scanf("%d%d%d", &A, &B, &C);

  if (A == B && B == C && !(A & 1))
    return puts("-1");

  while (!(A & 1) && !(B & 1) && !(C & 1)) {
    int new_A = (A + B) / 2;
    int new_B = (A + C) / 2;
    int new_C = (B + C) / 2;
    ++ans;
    A = new_A;
    B = new_B;
    C = new_C;
  }

  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <cstdio>
int ans, A, B, C;
int main() {
  scanf("%d%d%d", &A, &B, &C);

  if (A == B && B == C && !(A & 1))
    return puts("-1"), 0;

  while (!(A & 1) && !(B & 1) && !(C & 1)) {
    int new_A = (A + B) / 2;
    int new_B = (A + C) / 2;
    int new_C = (B + C) / 2;
    ++ans;
    A = new_A;
    B = new_B;
    C = new_C;
  }

  printf("%d\n", ans);
  return 0;
}
Problem p03723 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int num[100010];
int main() {
  int a, b, c;
  int count = 0;
  scanf("%d %d %d", &a, &b, &c);
  while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    int a1, b1, c1;
    a1 = a;
    b1 = b;
    c1 = c;
    a = (c1 + b1) / 2;
    b = (a1 + c1) / 2;
    c = (a1 + b1) / 2;
    count++;
  }
  cout << count << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int num[100010];
int main() {
  int a, b, c;
  int count = 0;
  scanf("%d %d %d", &a, &b, &c);
  while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    if (a == b && b == c) {
      cout << "-1" << endl;
      return 0;
    }
    int a1, b1, c1;
    a1 = a;
    b1 = b;
    c1 = c;
    a = (c1 + b1) / 2;
    b = (a1 + c1) / 2;
    c = (a1 + b1) / 2;
    count++;
  }
  cout << count << endl;
  return 0;
}
Problem p03723 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <stdio.h>
// #include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <float.h>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define INF 1e9
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++)
#define VEC(type, c, n)                                                        \
  std::vector<type> c(n);                                                      \
  for (auto &i : c)                                                            \
    std::cin >> i;
#define vec(type, n) vector<type>(n)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

vector<int> bitSearch(int bit, int n) {
  vector<int> S;
  rep(i, n) if (bit & (1 << i)) S.push_back(i);
  return S;
}

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll res = 0;
  if (a == b == c && a % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (1) {
    if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0)
      break;
    ll aa = a, bb = b, cc = c;
    a = (bb + cc) / 2;
    b = (aa + cc) / 2;
    c = (aa + bb) / 2;
    res++;
  }
  cout << res << endl;
}


Fixed submission:
#include <iostream>
#include <stdio.h>
// #include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <float.h>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define INF 1e9
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++)
#define VEC(type, c, n)                                                        \
  std::vector<type> c(n);                                                      \
  for (auto &i : c)                                                            \
    std::cin >> i;
#define vec(type, n) vector<type>(n)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

vector<int> bitSearch(int bit, int n) {
  vector<int> S;
  rep(i, n) if (bit & (1 << i)) S.push_back(i);
  return S;
}

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll res = 0;
  if (a == b && b == c && a % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (1) {
    if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0)
      break;
    ll aa = a, bb = b, cc = c;
    a = (bb + cc) / 2;
    b = (aa + cc) / 2;
    c = (aa + bb) / 2;
    res++;
  }
  cout << res << endl;
}
Problem p03723 (C++)

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

using namespace std;

int A, B, C;

void solve() {
  int cnt = 0;
  int A1, B1, C1;

  while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
    if (A == B && B == C) {
      cnt = -1;
    } else {

      A1 = A / 2;

      B1 = B / 2;

      C1 = C / 2;

      A = B1 + C1;
      B = A1 + C1;
      C = A1 + B1;

      cnt++;
    }
  }

  cout << cnt << endl;
}

int main() {

  cin >> A >> B >> C;
  solve();
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int A, B, C;

void solve() {
  int cnt = 0;
  int A1, B1, C1;

  while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
    if (A == B && B == C) {
      cnt = -1;
      break;
    } else {

      A1 = A / 2;

      B1 = B / 2;

      C1 = C / 2;

      A = B1 + C1;
      B = A1 + C1;
      C = A1 + B1;

      cnt++;
    }
  }

  cout << cnt << endl;
}

int main() {

  cin >> A >> B >> C;
  solve();
  return 0;
}
Problem p03723 (C++)

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

int main(void) {
  int n;
  long long ans = 0;
  vector<int> a;
  cin >> n;
  a.resize(n * 3);
  for (int i = 0; i < n * 3; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++)
    ans += a[n + i * 2];
  cout << ans << endl;
}


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

int main(void) {
  int a, b, c;
  int ans = 0;
  cin >> a >> b >> c;
  if (a == b && b == c) {
    if (a % 2)
      cout << 0 << endl;
    else
      cout << -1 << endl;
    return 0;
  }
  while (true) {
    if (!(a % 2) && !(b % 2) && !(c % 2)) {
      int ta = a / 2, tb = b / 2, tc = c / 2;
      a = tb + tc;
      b = tc + ta;
      c = ta + tb;
      ans++;
    } else
      break;
  }
  cout << ans << endl;
}
Problem p03723 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

int main() {
  // #ifndef ONLINE_JUDGE
  // freopen("input", "r", stdin);
  vector<int> v(6);
  cin >> v[0] >> v[1] >> v[2];
  int ans = 0;
  while (1) {
    if (v[0] % 2 == 1 || v[1] % 2 == 1 || v[2] % 2 == 1)
      break;
    v[0] /= 2;
    v[1] /= 2;
    v[2] /= 2;
    v[3] = v[1] + v[2];
    v[4] = v[0] + v[2];
    v[5] = v[0] + v[1];
    v[0] = v[3];
    v[1] = v[4];
    v[2] = v[5];
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

int main() {
  // #ifndef ONLINE_JUDGE
  // freopen("input", "r", stdin);
  vector<int> v(6);
  cin >> v[0] >> v[1] >> v[2];
  int ans = 0;
  while (1) {
    if (v[0] % 2 == 1 || v[1] % 2 == 1 || v[2] % 2 == 1)
      break;
    v[0] /= 2;
    v[1] /= 2;
    v[2] /= 2;
    v[3] = v[1] + v[2];
    v[4] = v[0] + v[2];
    v[5] = v[0] + v[1];
    v[0] = v[3];
    v[1] = v[4];
    v[2] = v[5];
    ans++;
    if (ans >= 10000) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03723 (C++)

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

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll ans = 0;
  if (a / 2 % 2 && b / 2 % 2 && c / 2 % 2)
    ans = -1;
  else {
    ll ta, tb, tc;
    while (1) {
      ta = b / 2 + c / 2, tb = a / 2 + c / 2, tc = a / 2 + b / 2;
      if (a % 2 || b % 2 || c % 2)
        break;
      a = ta;
      b = tb;
      c = tc;
      ans += 1;
    }
  }
  cout << ans << endl;
}


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

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll ans = 0;
  if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    if (a == b && b == c)
      ans = -1;
    else {
      ll ta, tb, tc;
      ans = 1;
      while (1) {
        ta = b / 2 + c / 2, tb = a / 2 + c / 2, tc = a / 2 + b / 2;
        if (ta % 2 || tb % 2 || tc % 2)
          break;
        a = ta;
        b = tb;
        c = tc;
        ans += 1;
      }
    }
  }
  cout << ans << endl;
}
Problem p03723 (C++)

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

#define int long long

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  while (true) {
    if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0)
      break;
    if (ans == 1000000000) {
      cout << -1 << endl;
      return 0;
    }
    ans++;
    int tmp_a = a / 2;
    int tmp_b = b / 2;
    int tmp_c = c / 2;
    a = 0;
    b = 0;
    c = 0;
    a += tmp_b + tmp_c;
    b += tmp_a + tmp_c;
    c += tmp_a + tmp_b;
  }
  cout << ans << endl;
  return 0;
}


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

#define int long long

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  while (true) {
    if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0)
      break;
    if (ans == 1000000) {
      cout << -1 << endl;
      return 0;
    }
    ans++;
    int tmp_a = a / 2;
    int tmp_b = b / 2;
    int tmp_c = c / 2;
    a = 0;
    b = 0;
    c = 0;
    a += tmp_b + tmp_c;
    b += tmp_a + tmp_c;
    c += tmp_a + tmp_b;
  }
  cout << ans << endl;
  return 0;
}