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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#define ll long long
using namespace std;
const int N = 2e5;
struct edge {
  int fr, to, w;
} a[N], sta[N];
int n, m, val[N], fa[N];
int siz[N], cnt, top, ans;
ll sum[N];
int cmp(const edge &A, const edge &B) { return A.w < B.w; }
int find(int x) { return fa[x] == x ? x : find(fa[x]); }
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &val[i]);
    fa[i] = i, siz[i] = 1, sum[i] = val[i];
  }
  for (int i = 1, x, y, w; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &w);
    a[++cnt] = (edge){x, y, w};
  }
  sort(a + 1, a + cnt + 1, cmp);

  for (int i = 1; i <= cnt; i++) {
    int x = a[i].fr, y = a[i].to;
    x = find(x);
    y = find(y);
    if (x == y)
      continue;
    if (siz[x] < siz[y])
      swap(x, y);
    sta[++top] = (edge){x, y, a[i].w};
    fa[x] = y;
    siz[y] += siz[x];
    sum[y] += sum[x];
  }
  for (int i = top; i >= 1; i--) {
    int x = sta[i].fr, y = sta[i].to;
    ll v = sum[find(y)], val = sta[i].w;
    if (v < val)
      fa[x] = x, siz[y] -= siz[x], sum[y] -= sum[x];
  }
  for (int i = 1; i <= m; i++) {
    int x = a[i].fr, y = a[i].to;
    if (find(x) != find(y))
      ans++;
    else if (a[i].w > sum[find(x)])
      ans++;
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#define ll long long
using namespace std;
const int N = 2e5;
struct edge {
  int fr, to, w;
} a[N], sta[N];
int n, m, val[N], fa[N];
int siz[N], cnt, top, ans;
ll sum[N];
int cmp(const edge &A, const edge &B) { return A.w < B.w; }
int find(int x) { return fa[x] == x ? x : find(fa[x]); }
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &val[i]);
    fa[i] = i, siz[i] = 1, sum[i] = val[i];
  }
  for (int i = 1, x, y, w; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &w);
    a[++cnt] = (edge){x, y, w};
  }
  sort(a + 1, a + cnt + 1, cmp);

  for (int i = 1; i <= cnt; i++) {
    int x = a[i].fr, y = a[i].to;
    x = find(x);
    y = find(y);
    if (x == y)
      continue;
    if (siz[x] > siz[y])
      swap(x, y);
    sta[++top] = (edge){x, y, a[i].w};
    fa[x] = y;
    siz[y] += siz[x];
    sum[y] += sum[x];
  }
  for (int i = top; i >= 1; i--) {
    int x = sta[i].fr, y = sta[i].to;
    ll v = sum[find(y)], val = sta[i].w;
    if (v < val)
      fa[x] = x, siz[y] -= siz[x], sum[y] -= sum[x];
  }
  for (int i = 1; i <= m; i++) {
    int x = a[i].fr, y = a[i].to;
    if (find(x) != find(y))
      ans++;
    else if (a[i].w > sum[find(x)])
      ans++;
  }
  cout << ans << endl;
}
Problem p03145 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge {
  ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

vi ABC;
signed main() {
  ABC.resize(3);
  REP(i, 3)
  cin >> ABC[3];

  sort(ALL(ABC));
  cout << ABC[0] * ABC[1] / 2 << endl;
  // system("pause");
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge {
  ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

vi ABC;
signed main() {
  ABC.resize(3);
  REP(i, 3)
  cin >> ABC[i];

  sort(ALL(ABC));
  cout << ABC[0] * ABC[1] / 2 << endl;
  // system("pause");
}
Problem p03145 (Python)

Buggy submission (status: Runtime Error):
LL = list(map(int, input().split())).sort()
R = LL[0] * LL[1] // 2
print(R)


Fixed submission:
LL = list(map(int, input().split()))
LL.sort()
R = LL[0] * LL[1] // 2
print(R)
Problem p03145 (Python)

Buggy submission (status: Runtime Error):
h, w, _ = [int(i) for i in input()]
ans = h * w // 2
print(ans)


Fixed submission:
h, w, _ = [int(i) for i in input().split()]
ans = h * w // 2
print(ans)
Problem p03145 (Python)

Buggy submission (status: Runtime Error):
def main() -> None:
    ab, bc, ca = map(int, input())
    print(ab * bc // 2)


if __name__ == "__main__":
    main()


Fixed submission:
def main() -> None:
    ab, bc, ca = map(int, input().split())
    print(ab * bc // 2)


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

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

int main() {

  int a, b, Area;

  printf("Enter the values of a and b : \n");
  scanf("%d %d %d", &a, &b);
  Area = (a + b) / 2;
  printf("Area of a triangle = %d \n", Area);

  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {

  int a, b, c;
  int answer;
  scanf("%d %d %d", &a, &b, &c);
  answer = a * b / 2;
  printf("%d", answer);

  return 0;
}
Problem p03145 (C++)

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

using namespace std;

int main() {
  int a, b, c;
  printf("%d", a * b * c / 2 / max({a, b, c}));
}

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

using namespace std;

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  printf("%d", a * b * c / 2 / max({a, b, c}));
}
Problem p03145 (C++)

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;

ll mod = 1e9 + 7;

int main() {
  int a, b;
  scanf("%d%d%d", &a, &b);
  int ans = a * b / 2;
  printf("%d\n", ans);
  return 0;
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;

ll mod = 1e9 + 7;

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  int ans = a * b / 2;
  printf("%d\n", ans);
  return 0;
}
Problem p03145 (Python)

Buggy submission (status: Runtime Error):
def run(a):
    return a[0] * a[1] // 2


def main():
    a = map(int, input().split())
    print(run(a))


if __name__ == "__main__":
    main()


Fixed submission:
def run(a):
    return a[0] * a[1] // 2


def main():
    a = list(map(int, input().split()))
    print(run(a))


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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  return (a * b) / 2;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << (a * b) / 2 << endl;
  return 0;
  return 0;
}
Problem p03145 (C++)

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  return a * b * c / max(a, max(b, c)) / 2;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << (a * b * c / 2 / max(a, max(b, c))) << endl;
  return 0;
}
Problem p03145 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fast_io()                                                              \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define PI 3.14159265
#define MOD 1000000007
#define PSET(x, y) fixed << setprecision(y) << x
#define ll long long
#define ld long double
#define lop(i, a, b) for (ll i = a; i < b; i++)
#define lopr(i, a, b) for (ll i = a; i >= b; i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int>>
using namespace std;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  fast_io()

      int a,
      b, c;
  cin >> a >> b >> c;

  cout << (b * a) / 2;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define fast_io()                                                              \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define PI 3.14159265
#define MOD 1000000007
#define PSET(x, y) fixed << setprecision(y) << x
#define ll long long
#define ld long double
#define lop(i, a, b) for (ll i = a; i < b; i++)
#define lopr(i, a, b) for (ll i = a; i >= b; i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int>>
using namespace std;

int main() {
  // #ifndef ONLINE_JUDGE
  //     freopen("input.txt", "r", stdin);
  //     freopen("output.txt", "w", stdout);
  // #endif

  fast_io()

      int a,
      b, c;
  cin >> a >> b >> c;

  cout << (b * a) / 2;

  return 0;
}
Problem p03145 (C++)

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

int main() {
  int a, b;
  cin >> a >> b;
  return (a * b / 2);
}

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

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a * b / 2);
  return 0;
}
Problem p03145 (C++)

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

using namespace std;

const int maxa = 3;
int a[maxa];

int main() {
  int mini1 = 0, mini2 = 0, num1, num2, area;
  for (int i = 0; i < 3; i++) {
    cin >> a[i];
    if (mini1 <= a[i]) {
      mini1 = a[i];
      num1 = i;
    }
  }
  a[num1] = 0;
  for (int j = 0; j < 3; j--) {
    if (mini1 >= a[j]) {
      mini1 = a[j];
    }
  }
  for (int k = 0; k < 3; k++) {
    if (mini2 <= a[k]) {
      mini2 = a[k];
      num2 = k;
    }
  }
  a[num2] = 0;
  for (int l = 3; l != 0; l--) {
    if (mini2 >= a[l]) {
      mini2 = a[l];
    }
  }
  area = (mini1 * mini2) / 2;
  cout << area;
  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

const int maxa = 3;
int a[maxa];

int main() {
  int a, b, c, area;
  cin >> a >> b >> c;
  area = (a * b) / 2;
  cout << area;
  return 0;
}
Problem p03145 (Python)

Buggy submission (status: Runtime Error):
s = int(input())
an = []
an.append(s)
n = s
while an.count(4) != 2:
    if n % 2 == 0:
        n /= 2
        an.append(int(n))
    else:
        n = 3 * n + 1
        an.append(int(n))
if an.index(1 or 2) == 0:
    print(4)
else:
    print(an.index(4) + 4)


Fixed submission:
x, y, z = map(int, input().split())
print(int(x * y / 2))
Problem p03145 (C++)

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

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

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

  // start
  vector<int> x;
  cin >> x.at(0);
  cin >> x.at(1);
  cin >> x.at(2);
  sort(all(x));
  cout << x.at(0) * x.at(1) / 2 << endl;
  // end

  return 0;
}


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

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

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

  // start
  vector<int> x(3);
  cin >> x.at(0);
  cin >> x.at(1);
  cin >> x.at(2);
  sort(all(x));
  cout << x.at(0) * x.at(1) / 2 << endl;
  // end

  return 0;
}
Problem p03145 (Python)

Buggy submission (status: Runtime Error):
AB, BC, CA = int(input())

print((AB * BC) // 2)


Fixed submission:
AB, BC, CA = map(int, input().split())

print((AB * BC) // 2)
Problem p03146 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
  int s;
  cin >> s;
  vector<int> f(1000000);
  f.at(0) = s;
  rep(i, 1000000) {
    if (f.at(i) % 2 == 0)
      f.at(i + 1) = f.at(i) / 2;
    else
      f.at(i + 1) = 3 * f.at(i) + 1;
  }
  for (int i = 0; i < 1000000 - 1; i++) {
    for (int j = i + 1; j < 1000000; j++) {
      if (f.at(i) == f.at(j)) {
        cout << j + 1 << endl;
        return 0;
      }
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
  int s;
  cin >> s;
  vector<int> f(1000000);
  f.at(0) = s;
  rep(i, 1000000 - 1) {
    if (f.at(i) % 2 == 0)
      f.at(i + 1) = f.at(i) / 2;
    else
      f.at(i + 1) = 3 * f.at(i) + 1;
  }
  for (int i = 0; i < 1000000 - 1; i++) {
    for (int j = i + 1; j < 1000000; j++) {
      if (f.at(i) == f.at(j)) {
        cout << j + 1 << endl;
        return 0;
      }
    }
  }
}
Problem p03146 (C++)

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

int a[100010];
int main(int argc, char const *argv[]) {
  int s;
  cin >> s;
  a[0] = s;

  for (int i = 0; i < 100009; i++) {

    if (a[i] % 2 == 0) {
      a[i + 1] = a[i] / 2;
    } else {
      a[i + 1] = a[i] * 3 + 1;
    }
  }

  int b[1000];
  for (int i = 0; i < 1000; i++) {
    b[i] = 0;
  }
  int ans = 0;

  for (int i = 0; i < 100010; i++) {
    b[a[i]]++;

    if (b[a[i]] == 2) {
      ans = i + 1;
      break;
    }
  }
  cout << ans << endl;

  return 0;
}

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

int a[100010];
int main(int argc, char const *argv[]) {
  int s;
  cin >> s;
  a[0] = s;

  for (int i = 0; i < 100009; i++) {

    if (a[i] % 2 == 0) {
      a[i + 1] = a[i] / 2;
    } else {
      a[i + 1] = a[i] * 3 + 1;
    }
  }

  int b[10000];
  for (int i = 0; i < 10000; i++) {
    b[i] = 0;
  }
  int ans = 0;

  for (int i = 0; i < 100010; i++) {
    b[a[i]]++;

    if (b[a[i]] == 2) {
      ans = i + 1;
      break;
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p03146 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 << 29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_SIZE = 1000000;
vector<long long> a(100);
int s;
void solve() {
  cin >> s;
  a[1] = s;
  for (long long i = 2; i < MAX_SIZE; i++) {
    if (a[i - 1] % 2 == 0) {
      a[i] = a[i - 1] / 2;
    } else {
      a[i] = (3 * a[i - 1]) + 1;
    }
    for (long long j = 1; j < i; j++) {
      if (a[i] == a[j]) {
        cout << i << endl;
        return;
      }
    }
  }
  return;
}
// 逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
// 組み合わせ
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(int args, char *argv[]) { solve(); }

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 << 29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_SIZE = 1000000;
vector<long long> a(1000000);
int s;
void solve() {
  cin >> s;
  a[1] = s;
  for (long long i = 2; i < MAX_SIZE; i++) {
    if (a[i - 1] % 2 == 0) {
      a[i] = a[i - 1] / 2;
    } else {
      a[i] = (3 * a[i - 1]) + 1;
    }
    for (long long j = 1; j < i; j++) {
      if (a[i] == a[j]) {
        cout << i << endl;
        return;
      }
    }
  }
  return;
}
// 逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
// 組み合わせ
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(int args, char *argv[]) { solve(); }
Problem p03146 (C++)

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

int main() {
  int s;
  cin >> s;
  set<int> st;
  int x = s;
  while (st.count(x) == 0) {
    st.insert(x);
    if (x % 2 == 0) {
      x /= 2;
    } else {
      x *= 3;
      x + 1;
    }
  }
  cout << st.size() + 1 << endl;
}


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

int main() {
  int s;
  cin >> s;
  set<int> st;
  int x = s;
  while (st.count(x) == 0) {
    st.insert(x);
    if (x % 2 == 0) {
      x /= 2;
    } else {
      x = x * 3 + 1;
    }
  }
  cout << st.size() + 1 << endl;
}
Problem p03146 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll a;
  cin >> a;
  vector<ll> vec(100, -1);
  vec.at(a) = 1;
  for (ll i = 0;; i++) {
    if (a % 2 == 0) {
      a = a / 2;
    } else {
      a = 3 * a + 1;
    }
    if (a <= 100) {
      if (vec.at(a) == -1) {
        vec.at(a) = 1;
      } else {
        cout << i + 2 << endl;
        return 0;
      }
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll a;
  cin >> a;
  vector<ll> vec(101, -1);
  vec.at(a) = 1;
  for (ll i = 0;; i++) {
    if (a % 2 == 0) {
      a = a / 2;
    } else {
      a = 3 * a + 1;
    }
    if (a <= 100) {
      if (vec.at(a) == -1) {
        vec.at(a) = 1;
      } else {
        cout << i + 2 << endl;
        return 0;
      }
    }
  }
}
Problem p03146 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define INF (1 << 29)
#define MAX_N 1000010
/* ACはうれCすぎてうれD */

int main(void) {
  int s;
  cin >> s;
  ll ans = 1;
  while (s != 4 || s != 2 || s != 1) {
    ans += 1;
    if (s % 2 == 0) {
      s = s / 2;
    } else {
      s = 3 * s + 1;
    }
  }
  cout << ans + 3;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define INF (1 << 29)
#define MAX_N 1000010
/* ACはうれCすぎてうれD */

int main(void) {
  int s;
  cin >> s;
  ll ans = 1;
  while (s != 4 && s != 2 &&
         s != 1) { // 2 1 4 2 なら、4 より先に 2が重複するじゃん
                   // ずっと 4 しか考えてなかった。
    ans += 1;
    if (s % 2 == 0) {
      s = s / 2;
    } else {
      s = 3 * s + 1;
    }
  }
  cout << ans + 3;
  return 0;
}
Problem p03146 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int s;
  cin >> s;
  vector<int> ans(1000000000, 0);
  for (int i = 0; i < 1000000; i++) {
    if (s % 2 == 0) {
      s /= 2;
      ans[s]++;
    } else {
      s = 3 * s + 1;
      ans[s]++;
    }
    if (ans[s] == 2) {
      cout << i + 2 << endl;
      return 0;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int s;
  cin >> s;
  vector<int> ans(100000000, 0);
  ans[s]++;
  for (int i = 0; i < 1000000; i++) {
    if (s % 2 == 0) {
      s /= 2;
      ans[s]++;
    } else {
      s = 3 * s + 1;
      ans[s]++;
    }
    if (ans[s] == 2) {
      cout << i + 2 << endl;
      return 0;
    }
  }
}
Problem p03146 (C++)

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

int main() {
  int s;
  cin >> s;
  int n[1000000], i = 0;
  while (true) {
    n[i] = s;
    i++;
    if (s % 2 == 0)
      s = s / 2;
    else
      s = 3 * s + 1;
    for (int j = 0; j < i; j++) {
      if (n[j] == s) {
        cout << i + 1 << endl;
        return 1;
      }
    }
  }
}

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

int main() {
  int s;
  cin >> s;
  int n[1000000], i = 0;
  while (true) {
    n[i] = s;
    i++;
    if (s % 2 == 0)
      s = s / 2;
    else
      s = 3 * s + 1;
    for (int j = 0; j < i; j++) {
      if (n[j] == s) {
        cout << i + 1 << endl;
        return 0;
      }
    }
  }
}
Problem p03146 (C++)

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

typedef long long ll;
#define pii pair<int, int>
#define _FastIO                                                                \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define MAXX 1005

int s, t;
bool used[MAXX];

int main() {
  _FastIO;
  cin >> s;
  int ans = 0;
  used[s] = true;
  t = 1;
  while (true) {
    t++;
    if (s % 2 == 0)
      s /= 2;
    else
      s = s * 3 + 1;
    if (used[s]) {
      ans = t;
      break;
    }
    used[s] = true;
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
#define pii pair<int, int>
#define _FastIO                                                                \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define MAXX 100005

int s, t;
bool used[MAXX];

int main() {
  _FastIO;
  cin >> s;
  int ans = 0;
  used[s] = true;
  t = 1;
  while (true) {
    t++;
    if (s % 2 == 0)
      s /= 2;
    else
      s = s * 3 + 1;
    if (used[s]) {
      ans = t;
      break;
    }
    used[s] = true;
  }
  cout << ans << endl;
  return 0;
}
Problem p03146 (C++)

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

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

  int cnt = 4;
  while (n != 4 || n != 2 || n != 1) {
    if (n % 2 == 1)
      n = 3 * n + 1;
    else
      n /= 2;
    cnt++;
  }
  cout << cnt << endl;
}


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

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

  int cnt = 4;
  while (1) {
    if (n == 4 || n == 2 || n == 1)
      break;
    if (n % 2 == 1)
      n = 3 * n + 1;
    else
      n /= 2;
    cnt++;
  }
  cout << cnt << endl;
}
Problem p03146 (Python)

Buggy submission (status: Runtime Error):
s = int(input())
a = [s]
z = set(s)
idx = 1
for i in range(10**8):
    idx += 1
    if a[i] % 2 == 0:
        ai = a[i] // 2
    else:
        ai = 3 * a[i] + 1
    if ai in z:
        print(idx)
        exit()
    a.append(ai)
    z.add(ai)


Fixed submission:
s = int(input())
a = [s]
z = set([s])
idx = 1
for i in range(10**8):
    idx += 1
    if a[i] % 2 == 0:
        ai = a[i] // 2
    else:
        ai = 3 * a[i] + 1
    if ai in z:
        print(idx)
        exit()
    a.append(ai)
    z.add(ai)
Problem p03146 (C++)

Buggy submission (status: Runtime Error):
#define _USE_NATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;

bool used[85];

int main() {
  int n;
  cin >> n;
  int ans = 1;
  while (!used[n]) {
    used[n] = true;
    if (n % 2 == 0)
      n /= 2;
    else
      n = 3 * n + 1;
    ++ans;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#define _USE_NATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;

bool used[1010101];

int main() {
  int n;
  cin >> n;
  int ans = 1;
  while (!used[n]) {
    used[n] = true;
    if (n % 2 == 0)
      n /= 2;
    else
      n = 3 * n + 1;
    ++ans;
  }
  cout << ans << endl;
  return 0;
}
Problem p03146 (C++)

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

bool in_judge(std::vector<int> &a) {
  int n = a.size();
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == a[n - 1]) {
      return true;
    }
  }
  return false;
}

int main() {
  int s;
  std::cin >> s;
  std::vector<int> a(1, s);
  for (int i = 1;; i++) {
    if (a[i - 1] % 2 == 0) {
      a.push_back(a[i - 1] / 2);
    } else {
      a.push_back(3 * a[i - 1] + 1);
    }
    if (in_judge(a)) {
      std::cout << i + 1 << std::endl;
      return 9;
    }
  }

  return 0;
}


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

bool in_judge(std::vector<int> &a) {
  int n = a.size();
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == a[n - 1]) {
      return true;
    }
  }
  return false;
}

int main() {
  int s;
  std::cin >> s;
  std::vector<int> a(1, s);
  for (int i = 1;; i++) {
    if (a[i - 1] % 2 == 0) {
      a.push_back(a[i - 1] / 2);
    } else {
      a.push_back(3 * a[i - 1] + 1);
    }
    if (in_judge(a)) {
      std::cout << i + 1 << std::endl;
      return 0;
    }
  }

  return 0;
}
Problem p03146 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
  int a[1000005], n;
  for (int i = 0; i < 10000005; i++) {
    a[i] = 0;
  }
  scanf("%d", &n);
  for (int i = 1; i < 1000005; i++) {
    a[n]++;
    if (a[n] == 2) {
      printf("%d\n", i);
      break;
    }
    if (n % 2 == 0) {
      n = n / 2;
    } else {
      n = n * 3 + 1;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
  int a[1000005], n;
  for (int i = 0; i < 1000005; i++) {
    a[i] = 0;
  }
  scanf("%d", &n);
  for (int i = 1; i < 1000005; i++) {
    a[n]++;
    if (a[n] == 2) {
      printf("%d\n", i);
      break;
    }
    if (n % 2 == 0) {
      n = n / 2;
    } else {
      n = n * 3 + 1;
    }
  }
}
Problem p03146 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define tii tuple<int, int, int>
signed main() {
  int S;
  cin >> S;
  int ans = 1;
  bitset<1000> A;
  A.set(S);
  while (1) {
    ans++;
    if (S % 2 == 0) {
      S /= 2;
    } else {
      S = 3 * S + 1;
    }
    if (A.test(S)) {
      cout << ans << endl;
      break;
    }
    A.set(S);
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define tii tuple<int, int, int>
signed main() {
  int S;
  cin >> S;
  int ans = 1;
  bitset<100000> A;
  A.set(S);
  while (1) {
    ans++;
    if (S % 2 == 0) {
      S /= 2;
    } else {
      S = 3 * S + 1;
    }
    if (A.test(S)) {
      cout << ans << endl;
      break;
    }
    A.set(S);
  }
}
Problem p03146 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int a[100000], i, j;
  cin >> a[0];
  for (i = 0;; i++) {
    if (a[i] % 2 == 0)
      a[i + 1] = a[i] / 2;
    else
      a[i + 1] = 3 * a[i] + 1;
    for (j = 0; j < i + 1; j++) {
      if (a[i + 1] == a[j]) {
        cout << i + 1;
        break;
      }
    }
  }
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a[100000], i, j;
  cin >> a[0];
  for (i = 0;; i++) {
    if (a[i] % 2 == 0)
      a[i + 1] = a[i] / 2;
    else
      a[i + 1] = 3 * a[i] + 1;
    for (j = 0; j < i + 1; j++) {
      if (a[i + 1] == a[j]) {
        cout << i + 2;
        return 0;
      }
    }
  }
  return 0;
}
Problem p03146 (C++)

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

using namespace std;

int memo[350];

int collaz(int x) {
  if (x % 2 == 0) {
    return x / 2;
  }
  return (x * 3) + 1;
}

int main() {
  int n, i = 1;
  cin >> n;
  while (memo[n] == 0) {
    memo[n] = i++;
    n = collaz(n);
  }
  cout << i;
  return 0;
}


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

using namespace std;

map<int, int> memo;

int collaz(int x) {
  if (x % 2 == 0) {
    return x / 2;
  }
  return (x * 3) + 1;
}

int main() {
  int n, i = 1;
  cin >> n;
  while (memo[n] == 0) {
    memo[n] = i++;
    n = collaz(n);
  }
  cout << i;
  return 0;
}
Problem p03146 (C++)

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

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

  int a;
  int i = 1;
  set<int> ss;
  while (a <= 1000000) {
    if (i == 1) {
      a = s;
    } else if (a % 2 == 0) {
      a = a / 2;
    } else {
      a = 3 * a + 1;
    }

    if (ss.find(a) == ss.end()) {
      ss.insert(a);
    } else {
      cout << i << endl;
      return i;
    }
    i++;
  }

  return 0;
}

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

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

  int a;
  int i = 1;
  set<int> ss;
  while (a <= 1000000) {
    if (i == 1) {
      a = s;
    } else if (a % 2 == 0) {
      a = a / 2;
    } else {
      a = 3 * a + 1;
    }

    if (ss.find(a) == ss.end()) {
      ss.insert(a);
    } else {
      cout << i << endl;
      return 0;
    }
    i++;
  }

  return 0;
}
Problem p03146 (C++)

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

int main() {
  int s;
  cin >> s;
  vector<bool> done(10000000, false);
  int cnt = 0;
  while (true) {
    cnt++;
    if (done.at(s)) {
      cout << cnt << endl;
      break;
    } else {
      if (s % 2 == 0) {
        s /= 2;
      } else {
        s = 3 * s + 1;
      }
    }
  }
}


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

int main() {
  int s;
  cin >> s;
  vector<bool> done(10000000, false);
  int cnt = 0;
  while (true) {
    cnt++;
    if (done.at(s)) {
      cout << cnt << endl;
      break;
    } else {
      done.at(s) = true;
      if (s % 2 == 0) {
        s /= 2;
      } else {
        s = 3 * s + 1;
      }
    }
  }
}
Problem p03146 (C++)

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

using namespace std;

int main() {
  int s;
  cin >> s;
  int i = 1;
  do {
    if (s == 4 || s == 2 || s == 1) {
      cout << i + 3 << endl;
      break;
    }
    i++;
  } while (1);
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int s;
  cin >> s;
  int i = 1;
  do {
    if (s == 4 || s == 2 || s == 1) {
      cout << i + 3 << endl;
      break;
    }
    i++;
    if (s % 2 == 0) {
      s = s / 2;
    } else {
      s = 3 * s + 1;
    }
  } while (1);
  return 0;
}
Problem p03146 (C++)

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

int main() {

  int s;
  cin >> s;

  const int p = 2147483647;
  vector<int> num(p, 0);

  int ans;
  int a_prev;
  int a_now = s;
  int i = 1;
  while (true) {

    if (i == 1) {
      a_now = s;
    } else {
      a_prev = a_now;
      if (a_prev % 2 == 0) {
        a_now = a_prev / 2;
      } else {
        a_now = a_prev * 3 + 1;
      }
    }

    if (num[a_now] == 1)
      break;
    else
      num[a_now]++;

    i++;
  }

  cout << i << endl;
  return 0;
}

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

int main() {

  int s;
  cin >> s;

  const int p = 147483647;
  vector<int> num(p, 0);

  int ans;
  int a_prev;
  int a_now = s;
  int i = 1;
  while (true) {

    if (i == 1) {
      a_now = s;
    } else {
      a_prev = a_now;
      if (a_prev % 2 == 0) {
        a_now = a_prev / 2;
      } else {
        a_now = a_prev * 3 + 1;
      }
    }

    if (num[a_now] == 1)
      break;
    else
      num[a_now]++;

    i++;
  }

  cout << i << endl;
  return 0;
}
Problem p03146 (C++)

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

int main() {
  int s;

  scanf("%d", &s);

  std::vector<int> vec;
  vec.push_back(s);

  int i;
  for (i = 1; i < 1000000; i++) {
    int tmp = vec.at(i - 1);
    int push;
    if (tmp % 2 == 0) {
      push = tmp / 2;
    } else {
      push = tmp * 3 + 1;
    }

    if (std::find(vec.begin(), vec.end(), push) != vec.end()) {
      break;
    } else {
      vec.push_back(push);
    }
  }
  printf("%d\n", i + 1);

  return i + 1;
}


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

int main() {
  int s;

  scanf("%d", &s);

  std::vector<int> vec;
  vec.push_back(s);

  int i;
  for (i = 1; i < 1000000; i++) {
    int tmp = vec.at(i - 1);
    int push;
    if (tmp % 2 == 0) {
      push = tmp / 2;
    } else {
      push = tmp * 3 + 1;
    }

    if (std::find(vec.begin(), vec.end(), push) != vec.end()) {
      break;
    } else {
      vec.push_back(push);
    }
  }
  printf("%d\n", i + 1);

  return 0;
}
Problem p03146 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main(void) {

  int s;
  cin >> s;
  int ans = 1;
  int a = (s <= 4 ? 1 : 0);
  int b = (s >= 4 ? 4 : s);
  while (a < 2) {
    if (s % 2 == 0)
      s = s / 2;
    else
      s = 3 * s + 1;

    if (s == b)
      a += 1;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main(void) {

  int s;
  cin >> s;
  int ans = 1;
  int a = 0;
  if (s == 4 || s == 2 || s == 1)
    a += 1;
  int b = (s == 4 || s == 2 || s == 1 ? s : 4);
  while (a < 2) {
    if (s % 2 == 0)
      s = s / 2;
    else
      s = 3 * s + 1;

    if (s == b)
      a += 1;
    ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03146 (C++)

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

int main() {
  int a;
  cin >> a;
  int c[10 * a];
  c[a] = 1;
  int t;
  for (int i = 0;; i++) {
    t = i;
    if (a % 2 == 1)
      a = 3 * a + 1;
    else
      a = a / 2;
    if (c[a] == 1)
      goto end;
    else
      c[a] = 1;
  }
end:
  cout << t + 2;

  return 0;
}

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

int main() {
  int a;
  cin >> a;
  int c[1000000];
  c[a] = 1;
  int t;
  for (int i = 0;; i++) {
    t = i;
    if (a % 2 == 1)
      a = 3 * a + 1;
    else
      a = a / 2;
    if (c[a] == 1)
      goto end;
    else
      c[a] = 1;
  }
end:
  cout << t + 2;

  return 0;
}
Problem p03146 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC optimize "-O3"
#pragma GCC target("avx")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int, int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define inf (1ll << 60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
signed gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
signed lcm(int a, int b) { return a * b / gcd(a, b); }

using namespace std;

const int mod = 1e9 + 7;

void run();

void init() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(12);
}

signed main() {
  init();
  run();
  return 0;
}

signed f(int num) {
  if (num % 2 == 0)
    return num / 2;
  else
    return num * 3 + 1;
}

void run() {
  int s;
  cin >> s;
  int num = 4;
  while (s != 4 || s != 2 || s != 1) {
    ++num;
    s = f(s);
  }
  cout << num << endl;
}

Fixed submission:
#pragma GCC optimize "-O3"
#pragma GCC target("avx")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int, int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define inf (1ll << 60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
signed gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
signed lcm(int a, int b) { return a * b / gcd(a, b); }

using namespace std;

const int mod = 1e9 + 7;

void run();

void init() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(12);
}

signed main() {
  init();
  run();
  return 0;
}

signed f(int num) {
  if (num % 2 == 0)
    return num / 2;
  else
    return num * 3 + 1;
}

void run() {
  int s;
  cin >> s;
  int num = 4;
  if (s == 2) {
    cout << 4 << endl;
    return;
  }
  if (s == 1) {
    cout << 4 << endl;
    return;
  }
  while (s != 4) {
    ++num;
    s = f(s);
  }
  cout << num << endl;
}
Problem p03146 (C++)

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

using namespace std;

long fn(long n);
#define N 1000000

int main() {
  long str[N] = {};
  long s, tmp;

  cin >> s;

  str[s] = 1;
  for (int i = 2; i < N + 1; i++) {
    tmp = fn(s);
    // cout << tmp << endl;
    if (str[tmp] != 0) {
      return i;
    } else {
      str[tmp] = 1;
    }
    s = tmp;
  }

  return 0;
}

long fn(long n) {
  if (n % 2 == 0) {
    return n / 2;
  } else {
    return 3 * n + 1;
  }
}

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

using namespace std;

long fn(long n);
#define N 1000000

int main() {
  long str[N] = {};
  long s, tmp;

  cin >> s;

  str[s] = 1;
  for (int i = 2; i < N + 1; i++) {
    tmp = fn(s);
    // cout << tmp << endl;
    if (str[tmp] != 0) {
      cout << i << endl;
      return 0;
    } else {
      str[tmp] = 1;
    }
    s = tmp;
  }

  return 0;
}

long fn(long n) {
  if (n % 2 == 0) {
    return n / 2;
  } else {
    return 3 * n + 1;
  }
}
Problem p03146 (C++)

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

int main() {
  int s;
  std::cin >> s;
  int list[1000000];
  int index = 0;
  int a_i;
  int a_pre = s;
  list[0] = s;
  index = index + 1;
  bool search_flag = false;
  while (true) {
    if (a_pre % 2 == 0) {
      a_i = a_pre / 2;
    } else {
      a_i = 3 * a_pre + 1;
    }
    list[index] = a_i;
    index = index + 1;
    for (int i = 0; i < index - 1; ++i) {
      if (list[i] == a_i) {
        search_flag = false;
        break;
      }
    }
    if (search_flag == true) {
      break;
    }
    a_pre = a_i;
  }
  std::cout << index << std::endl;
  return 0;
}


Fixed submission:
#include <iostream>

int main() {
  int s;
  std::cin >> s;
  int list[1000000];
  int index = 0;
  int a_i;
  int a_pre = s;
  list[0] = s;
  index = index + 1;
  bool search_flag = false;
  while (true) {
    if (a_pre % 2 == 0) {
      a_i = a_pre / 2;
    } else {
      a_i = 3 * a_pre + 1;
    }
    list[index] = a_i;
    index = index + 1;
    for (int i = 0; i < index - 1; ++i) {
      if (list[i] == a_i) {
        search_flag = true;
        break;
      }
    }
    if (search_flag == true) {
      break;
    }
    a_pre = a_i;
  }
  std::cout << index << std::endl;
  return 0;
}
Problem p03146 (C++)

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

int main() {
  int s, i = 0, j;
  vector<int> a;
  cin >> s;
  a.push_back(s);
  i++;
  while (true) {
    if (a[i - 1] % 2) {
      a.push_back(a[i - 1] * 3 + 1);
    } else {
      a.push_back(a[i - 1] / 2);
    }
    for (j = 0; j < i; j++) {
      if (a[i] == a[j]) {
        cout << i + 1 << endl;
        return (1);
      }
    }
    i++;
  }
}

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

int main() {
  int s, i = 0, j;
  vector<int> a;
  cin >> s;
  a.push_back(s);
  i++;
  while (true) {
    if (a[i - 1] % 2) {
      a.push_back(a[i - 1] * 3 + 1);
    } else {
      a.push_back(a[i - 1] / 2);
    }
    for (j = 0; j < i; j++) {
      if (a[i] == a[j]) {
        cout << i + 1 << endl;
        return (0);
      }
    }
    i++;
  }
}
Problem p03146 (C++)

Buggy submission (status: Runtime Error):
// in progress
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fr(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define rfr(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define PI 3.14159265
int rec(int ind, int n) {
  if (n == 1)
    return ind;
  if (n % 2 == 0)
    return rec(ind + 1, n / 2);
  else
    return rec(ind + 1, 3 * n + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);
  int n;
  cin >> n;
  if (n <= 2)
    cout << 4 << "\n";
  else
    cout << rec(0, n) + 2 << "\n";
  return 0;
}


Fixed submission:
// in progress
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fr(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define rfr(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define PI 3.14159265
int rec(int ind, int n) {
  if (n == 1)
    return ind;
  if (n % 2 == 0)
    return rec(ind + 1, n / 2);
  else
    return rec(ind + 1, 3 * n + 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("a.in", "r", stdin);
  // freopen("a.out", "w", stdout);
  int n;
  cin >> n;
  if (n <= 2)
    cout << 4 << "\n";
  else
    cout << rec(0, n) + 2 << "\n";
  return 0;
}
Problem p03146 (C++)

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

int main() {
  vector<int> a(1);
  cin >> a.at(0);
  int i;
  int ans = 0;
  while (true) {
    for (int j = 0; j < i; j++) {
      if (a.at(i) == a.at(j)) {
        ans = i + 1;
      }
    }
    if (a.at(i) % 2 == 0) {
      a.push_back(a.at(i) / 2);
    } else {
      a.push_back(a.at(i) * 3 + 1);
    }
    if (ans != 0) {
      break;
    }
    i++;
  }
  cout << ans << endl;
}

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

int main() {
  vector<int> a(1);
  cin >> a.at(0);
  int i = 0;
  int ans = 0;
  while (true) {
    for (int j = 0; j < i; j++) {
      if (a.at(i) == a.at(j)) {
        ans = i + 1;
      }
    }
    if (a.at(i) % 2 == 0) {
      a.push_back(a.at(i) / 2);
    } else {
      a.push_back(a.at(i) * 3 + 1);
    }
    if (ans != 0) {
      break;
    }
    i++;
  }
  cout << ans << endl;
}
Problem p03146 (C++)

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

int main() {
  int S, ans = 2;
  vector<bool> num(300, 1);
  cin >> S;
  num.at(S - 1) = 0;
  while (true) {
    if (S % 2 == 0) {
      S /= 2;
    } else {
      S = 3 * S + 1;
    }
    if (num.at(S - 1)) {
      num.at(S - 1) = 0;
    } else {
      break;
    }
    ans++;
  }
  cout << ans;
  return 0;
}

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

int main() {
  int S, ans = 2;
  vector<bool> num(10000, 1);
  cin >> S;
  num.at(S - 1) = 0;
  while (true) {
    if (S % 2 == 0) {
      S /= 2;
    } else {
      S = 3 * S + 1;
    }
    if (num.at(S - 1)) {
      num.at(S - 1) = 0;
    } else {
      break;
    }
    ans++;
  }
  cout << ans;
  return 0;
}
Problem p03146 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  cin >> n;
  vector<int> k(1000001, 0);
  k[n] = 1;
  int cnt = 2;
  while (1) {
    if (n % 2 == 0) {
      n /= 2;
    } else {
      n = n * 3 + 1;
    }
    if (k[n] == 1) {
      cout << cnt << endl;
      return 0;
    } else {
      k[n] == 1;
    }
    cnt++;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  cin >> n;
  vector<int> k(1000001, 0);
  k[n] = 1;
  int cnt = 2;
  while (1) {
    if (n % 2 == 0) {
      n /= 2;
    } else {
      n = n * 3 + 1;
    }
    if (k[n] == 1) {
      cout << cnt << endl;
      return 0;
    } else {
      k[n] = 1;
    }
    cnt++;
  }
}
Problem p03146 (C++)

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

  int ans;
  int v[100] = {0};
  v[s]++;
  for (int i = 1;; i++) {
    if (s % 2 == 0) {
      s /= 2;
    } else {
      s = 3 * s + 1;
    }

    if (v[s] == 0)
      v[s]++;
    else {
      ans = i + 1;
      break;
    }
  }
  cout << ans;

  return 0;
}

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

  int ans;
  int v[1000000] = {0};
  v[s]++;
  for (int i = 1;; i++) {
    if (s % 2 == 0) {
      s /= 2;
    } else {
      s = 3 * s + 1;
    }

    if (v[s] == 0)
      v[s]++;
    else {
      ans = i + 1;
      break;
    }
  }
  cout << ans;

  return 0;
}
Problem p03146 (C++)

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

int main() {
  int s;
  cin >> s;
  vector<int> a;
  a[1] = s;
  int an;
  bool loop = true;
  for (int i = 2; loop; i++) {
    if (a[i - 1] % 2 == 0)
      a.push_back(a[i - 1] / 2);
    else
      a.push_back(3 * a[i - 1] + 1);
    for (int j = 1; j < i; j++) {
      if (a[i] == a[j]) {
        loop = false;
        an = i;
        break;
      }
    }
  }
  cout << an << endl;
}

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

int main() {
  int s;
  cin >> s;
  vector<int> a(2);
  a[0] = -1;
  a[1] = s;
  int an;
  bool loop = true;
  for (int i = 2; loop; i++) {
    if (a[i - 1] % 2 == 0)
      a.push_back(a[i - 1] / 2);
    else
      a.push_back(3 * a[i - 1] + 1);
    for (int j = 1; j < i; j++) {
      if (a[i] == a[j]) {
        loop = false;
        an = i;
        break;
      }
    }
  }
  cout << an << endl;
}