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

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int N, K;
  scanf("%d %d", N, K);
  if (N % K == 0) {
    printf("0");
  } else {
    printf("1");
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int N, K;
  scanf("%d %d", &N, &K);
  if (N % K == 0) {
    printf("0");
  } else {
    printf("1");
  }
  return 0;
}
Problem p03284 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  if (n % k == 0)
    printf("0");
  else
    printf("%d", n % (n / k));
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  if (n % k == 0)
    printf("0");
  else {
    printf("1");
  }
  return 0;
}
Problem p03284 (C++)

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

int main() {
  int n, k;
  cin >> n >> k;
  int a = n / k;
  cout << n % a;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  int a = 0;
  if (n % k != 0)
    a = 1;
  cout << a;
}
Problem p03284 (C++)

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

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
#endif

  int n, k;
  cin >> n >> k;
  cout << (n % k != 0) << '\n';
  return 0;
}

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

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifndef ONLINE_JUDGE
  // freopen("in.txt", "r", stdin);
#endif

  int n, k;
  cin >> n >> k;
  cout << (n % k != 0) << '\n';
  return 0;
}
Problem p03284 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;

  return (N % K != 0);
}

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

int main() {
  int N, K;
  cin >> N >> K;

  cout << (N % K != 0) << endl;
  return 0;
}
Problem p03284 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
  ll n, k;

  cin >> n >> k;

  ll t = n / k;

  cout << abs(n % t) << endl;

  return 0;
}


Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
  ll n, k;

  cin >> n >> k;

  if (abs(n % k) != 0)
    cout << 1 << endl;
  else
    cout << 0 << endl;

  return 0;
}
Problem p03284 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int n, k;
int main() {
  scanf("%d%d", &n, &k);
  printf("%d\n", n % (n / k));
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int n, k;
int main() {
  scanf("%d%d", &n, &k);
  printf("%d\n", n % k == 0 ? 0 : 1);
  return 0;
}
Problem p03285 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAX_N 100000
#define MAX_M 100000
const int MAX = 10000000;
const int MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecbvecb vector<vector<bool>>
#define vecst vector<string>
#define vecch vector<char>
#define vecf vector<float>
#define vecvec vector<vector<int>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(), (x).end()
const int INF = 1e9;
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

int main() {
  int n, s, a;
  cin >> n;
  for (int i = 0; i <= n / 4; i++) {
    for (int j = 0; j <= n / 7; j++) {
      if ((i * 4) + (j * 7) == n) {
        cout << "Yes" << endl;
        return 1;
      }
    }
  }
  cout << "No" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAX_N 100000
#define MAX_M 100000
const int MAX = 10000000;
const int MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecbvecb vector<vector<bool>>
#define vecst vector<string>
#define vecch vector<char>
#define vecf vector<float>
#define vecvec vector<vector<int>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(), (x).end()
const int INF = 1e9;
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

int main() {
  int n, s, a;
  cin >> n;
  for (int i = 0; i <= n / 4; i++) {
    for (int j = 0; j <= n / 7; j++) {
      if ((i * 4) + (j * 7) == n) {
        cout << "Yes" << endl;
        exit(0);
      }
    }
  }
  cout << "No" << endl;
}
Problem p03285 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <utility>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

template <typename T>
std::ostream &operator<<(std::ostream &out, vector<T> &v) {

  for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
    out << v[i] << " ";
  out << "\n";

  return out;
}

int main() {

  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

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

  int n;
  cin >> n;

  for (int x = 0; x <= 25; ++x) {
    for (int y = 0; y <= 15; ++y) {
      if (4 * x + 7 * y == n) {
        cout << "Yes\n";
        return 0;
      }
    }
  }

  cout << "No\n";

  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <utility>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

template <typename T>
std::ostream &operator<<(std::ostream &out, vector<T> &v) {

  for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
    out << v[i] << " ";
  out << "\n";

  return out;
}

int main() {

  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n;
  cin >> n;

  for (int x = 0; x <= 25; ++x) {
    for (int y = 0; y <= 15; ++y) {
      if (4 * x + 7 * y == n) {
        cout << "Yes\n";
        return 0;
      }
    }
  }

  cout << "No\n";

  return 0;
}
Problem p03285 (C++)

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

int main(void) {
  int a, b;
  string s;
  cin >> a >> b;
  if (a % b == 0)
    cout << "0" << endl;
  else
    cout << "1" << endl;
  return 0;
}

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

int main(void) {
  int x[100] = {1, 2, 3, 5, 6, 9, 10, 13, 17};
  int a;
  cin >> a;
  for (int i = 0; i < 9; i++) {
    if (a == x[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
Problem p03285 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using ll = long long;
#define int ll
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define erep(e, v) for (auto &&e : v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9 : 1e18)
#define EPS 0.0000000001
using namespace std;
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
template <typename Head, typename Value>
auto vectors(const Head &head, const Value &v) {
  return vector<Value>(head, v);
}
template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) {
  auto inner = vectors(tail...);
  return vector<decltype(inner)>(x, inner);
}
template <class T> void join(T a) {
  for (auto itr : a) {
    if (itr != *a.begin())
      cout << " ";
    cout << itr;
  }
}
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pii>;
int W, H;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
signed main() {
  int a;
  cin >> a;
  rep(i, 100000) {
    rep(j, 100000) {
      if (i * 4 + j * 7 == a)
        return puts("Yes") * 0;
    }
  }
  cout << "No" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using ll = long long;
#define int ll
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define erep(e, v) for (auto &&e : v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9 : 1e18)
#define EPS 0.0000000001
using namespace std;
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
template <typename Head, typename Value>
auto vectors(const Head &head, const Value &v) {
  return vector<Value>(head, v);
}
template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) {
  auto inner = vectors(tail...);
  return vector<decltype(inner)>(x, inner);
}
template <class T> void join(T a) {
  for (auto itr : a) {
    if (itr != *a.begin())
      cout << " ";
    cout << itr;
  }
}
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pii>;
int W, H;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
signed main() {
  int a;
  cin >> a;
  rep(i, 100000) {
    rep(j, 10000) {
      if (i * 4 + j * 7 == a)
        return puts("Yes") * 0;
    }
  }
  cout << "No" << endl;
}
Problem p03285 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define MAX_SIZE 100000000
typedef unsigned long long ull;
using namespace std;

bool solve(const int n, const int x, const int y) {
  if (n - ((4 * x) + (7 * y)) == 0) {
    return true;
  } else {
    return false;
  }
}

int main() {
  int N;
  cin >> N;
  if (N < 4) {
    cout << "No" << endl;
    exit(1);
  }

  bool ans = false;
  for (int x = 0; x < N; x++) {
    for (int y = 0; y < N; y++) {
      if (solve(N, x, y)) {
        ans = true;
      }
    }
  }
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define MAX_SIZE 100000000
typedef unsigned long long ull;
using namespace std;

bool solve(const int n, const int x, const int y) {
  if (n - ((4 * x) + (7 * y)) == 0) {
    return true;
  } else {
    return false;
  }
}

int main() {
  int N;
  cin >> N;
  if (N < 4) {
    cout << "No" << endl;
    exit(0);
  }

  bool ans = false;
  for (int x = 0; x < N; x++) {
    for (int y = 0; y < N; y++) {
      if (solve(N, x, y)) {
        ans = true;
      }
    }
  }
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03285 (C++)

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

int main() {
  int n;
  std::cin >> n;
  if (n < 4)
    std::cout << "No" << std::endl;
  else {
    int n_ = n % 4;
    while (n_ < n) {
      if (n_ % 7 == 0) {
        std::cout << "Yes" << std::endl;
        return 0;
      } else {
        n_ += 4;
      }
    }
    int n2 = n % 7;
    while (n2 < n) {
      if (n2 % 4 == 0) {
        std::cout << "Yes" << std::endl;
        return 0;
      } else {
        n_ += 7;
      }
    }
    std::cout << "No" << std::endl;
  }
}


Fixed submission:
#include <iostream>

int main() {
  int n;
  std::cin >> n;
  if (n < 4)
    std::cout << "No" << std::endl;
  else {
    int n_ = n % 4;
    while (n_ < n) {
      if (n_ % 7 == 0) {
        std::cout << "Yes" << std::endl;
        return 0;
      } else {
        n_ += 4;
      }
    }
    int n2 = n % 7;
    while (n2 < n) {
      if (n2 % 4 == 0) {
        std::cout << "Yes" << std::endl;
        return 0;
      } else {
        n2 += 7;
      }
    }
    std::cout << "No" << std::endl;
  }
}
Problem p03285 (C++)

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

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

  for (int a = 0; a <= N; ++a) {
    for (int b = 0; b <= N; ++b) {
      int total = 4 * a + 7 * b;
      if (total == N) {
        cout << "Yes" << endl;
        return 1;
      }
    }
  }
  cout << "No" << endl;
}

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

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

  for (int a = 0; a <= N; ++a) {
    for (int b = 0; b <= N; ++b) {
      int total = 4 * a + 7 * b;
      if (total == N) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}
Problem p03285 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
This code By @1353055672(Ligen)
[Warning]You're not excepted to understand this code!
RP++
*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <stdio.h>
#define ll long long
#define ull unsigned long long
#define mn 1000020
#define FOR(a, b, c) for (int a = b; a <= c; a++)
#define FORD(a, b, c) for (int a = b; a >= c; a--)
using namespace std;
inline ll read() {
  ll x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int Max(int a, int b) { return (a > b) ? a : b; }
int Min(int a, int b) { return (a < b) ? a : b; }

int main() {
  int n = read(), k = read();
  printf("%d\n", !!(n % k));
  return 0;
}

Fixed submission:
/*
This code By @1353055672(Ligen)
[Warning]You're not excepted to understand this code!
RP++
*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <stdio.h>
#define ll long long
#define ull unsigned long long
#define mn 1000020
#define FOR(a, b, c) for (int a = b; a <= c; a++)
#define FORD(a, b, c) for (int a = b; a >= c; a--)
using namespace std;
inline ll read() {
  ll x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int Max(int a, int b) { return (a > b) ? a : b; }
int Min(int a, int b) { return (a < b) ? a : b; }

int main() {
  int n = read();
  FOR(i, 0, n / 4) if (n - i * 4 >= 0 && (n - i * 4) % 7 == 0) {
    printf("Yes\n");
    return 0;
  }
  printf("No\n");
  return 0;
}
Problem p03285 (C++)

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

int main() {
  int n;
  cin >> n;
  for (int i = 0; i * 4 <= n; i++) {
    for (int j = 0; i * 4 + j * 7 <= n; j++) {
      if (i * 4 + j * 7 == n) {
        cout << "Yes" << '\n';
        return 0;
      }
    }
  }
  cout << "No" << '\n';
  return 1;
}

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

int main() {
  int n;
  cin >> n;
  for (int i = 0; i * 4 <= n; i++) {
    for (int j = 0; i * 4 + j * 7 <= n; j++) {
      if (i * 4 + j * 7 == n) {
        cout << "Yes" << '\n';
        return 0;
      }
    }
  }
  cout << "No" << '\n';
  return 0;
}
Problem p03285 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cout << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

using namespace std;
typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  cout << (n % k == 0 ? 0 : 1) << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cout << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  rep(i, 100) rep(j, 100) {
    if (7 * i + 4 * j == n) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}
Problem p03285 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>

int main() {
  int n;
  bool ans = false;

  scanf("%d", &n);

  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < 15;) {
      if ((4 * i + 7 * j) == n) {
        ans = true;
        break;
      }
    }
    if (ans)
      break;
  }

  if (ans)
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}


Fixed submission:
#include <stdio.h>

int main() {
  int n;
  bool ans = false;

  scanf("%d", &n);

  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < 15; j++) {
      if ((4 * i + 7 * j) == n) {
        ans = true;
        break;
      }
    }
    if (ans)
      break;
  }

  if (ans)
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}
Problem p03285 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll, ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll, ll>>>
#define PL pair<ll, ll>
#define ALL(v) (v).begin(), (v).end()

int main() {
  ll N;
  cin >> N;
  ll flg = 0;
  rep(i, 0, 26) {
    rep(j, 0, 16) {
      if (N % (4 * i + 7 * j) == 0) {
        flg = 1;
        break;
      }
    }
    if (flg == 1)
      break;
  }
  cout << (flg == 1 ? "Yes" : "No") << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll, ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll, ll>>>
#define PL pair<ll, ll>
#define ALL(v) (v).begin(), (v).end()

int main() {
  ll N;
  cin >> N;
  ll flg = 0;
  rep(i, 0, 26) {
    rep(j, 0, 16) {
      if (i == 0 && j == 0)
        continue;
      if (N % (4 * i + 7 * j) == 0) {
        flg = 1;
        break;
      }
    }
    if (flg == 1)
      break;
  }
  cout << (flg == 1 ? "Yes" : "No") << endl;
}
Problem p03285 (C++)

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

typedef long long ll;

#define optimize()                                                             \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define file()                                                                 \
  freopen("input.txt", "r", stdin);                                            \
  freopen("output.txt", "w", stdout);
#define tt                                                                     \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define nl cout << "\n";
#define sp cout << " ";
#define rep(i, a, b) for (long long i = a; i < b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4 * atan(1);

int main() {
  optimize();

  int n, m;
  cin >> n;
  if (n == 0) {
    cout << "No\n";
    return 0;
  }
  if (n % 4 == 0 || n % 7 == 0) {
    cout << "Yes\n";
    return 0;
  }

  m = n / 7;

  while (m > 0) {
    if ((n - (m * 7)) % 4 == 0) {
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";

  return 0;
}


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

typedef long long ll;

#define optimize()                                                             \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define file()                                                                 \
  freopen("input.txt", "r", stdin);                                            \
  freopen("output.txt", "w", stdout);
#define tt                                                                     \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define nl cout << "\n";
#define sp cout << " ";
#define rep(i, a, b) for (long long i = a; i < b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4 * atan(1);

int main() {
  optimize();

  int n, m;
  cin >> n;
  if (n == 0) {
    cout << "No\n";
    return 0;
  }
  if (n % 4 == 0 || n % 7 == 0) {
    cout << "Yes\n";
    return 0;
  }

  m = n / 7;

  while (m > 0) {
    if ((n - (m * 7)) % 4 == 0) {
      cout << "Yes\n";
      return 0;
    }
    m--;
  }
  cout << "No\n";

  return 0;
}
Problem p03285 (C++)

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

int N;

int main() {
  cin >> N;
  int cake = 0;   // 4
  int dounut = 0; // 7
  string ans = "No";

  while (true) {
    int tmpn = N - cake * 4;
    if (tmpn < 0)
      break;
    if (tmpn % 7 == 0) {
      ans = "Yes";
      break;
    }
  }

  cout << ans << endl;
}


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

int N;

int main() {
  cin >> N;
  int cake = 0;   // 4
  int dounut = 0; // 7
  string ans = "No";

  while (true) {
    int tmpn = N - cake * 4;
    if (tmpn < 0)
      break;
    if (tmpn % 7 == 0) {
      ans = "Yes";
      break;
    }
    ++cake;
  }

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

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

const int INF = 1001001001;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main() {
  int n;
  cin >> n;
  bool ans = false;
  for (int i = 0; i <= n / 4; i++) {
    for (int j = 0; j <= n - 4 * i / 7; j++) {
      if (n % (4 * i + 7 * j) == 0) {
        ans = true;
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
}


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

const int INF = 1001001001;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main() {
  int n;
  cin >> n;
  bool ans = false;
  for (int i = 0; i <= n / 4; i++) {
    for (int j = 0; j <= n - 4 * i / 7; j++) {
      if ((4 * i + 7 * j) == n) {
        ans = true;
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
}
Problem p03285 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>

int main() {
  int N, p, q, r;
  scanf("%d", &N);
  r = 100;

  p = (N - N % 7) / 7;

  while (p >= 0) {
    q = (100 - 7 * p) % 4;
    if (q < r)
      r = q;
  }

  if (r == 0) {
    puts("Yes");
  } else {
    puts("No");
  }

  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  int N, p, q, r;
  scanf("%d", &N);
  r = 100;

  p = (N - N % 7) / 7;

  while (p >= 0) {
    q = (N - 7 * p) % 4;
    p = p - 1;
    if (q < r)
      r = q;
  }

  if (r == 0) {
    puts("Yes");
  } else {
    puts("No");
  }

  return 0;
}
Problem p03285 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, N) for (i = 0; i < N; i++)
#define INF 1e9
typedef long long ll;

int main(void) {
  int N;
  cin >> N;
  bool has_howtoBuy = false;
  while (N >= 0) {
    if (N % 4 == 0)
      has_howtoBuy = true;
    N /= 7;
  }
  if (has_howtoBuy)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, N) for (i = 0; i < N; i++)
#define INF 1e9
typedef long long ll;

int main(void) {
  int N;
  cin >> N;
  bool has_howtoBuy = false;
  while (N >= 0) {
    if (N % 4 == 0)
      has_howtoBuy = true;
    N -= 7;
  }
  if (has_howtoBuy)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p03285 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int N;

  cin >> N;

  int n = 0;
  while (n <= N) {
    if ((N - n) % 7 == 0) {
      cout << "Yes\n";
      return 0;
    }
  }

  cout << "No\n";

  return 0;
}

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

int main() {
  int N;

  cin >> N;

  int n = 0;
  while (n <= N) {
    if ((N - n) % 7 == 0) {
      cout << "Yes\n";
      return 0;
    }
    n += 4;
  }

  cout << "No\n";

  return 0;
}
Problem p03286 (C++)

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

int main() {
  ll N;
  cin >> N;
  if (N == 0) {
    cout << 0 << endl;
    return 0;
  }

  int base = 1;
  string S;
  while (N != 0) {
    if (N % (base * 2) == 0)
      S.push_back('0');
    else {
      S.push_back('1');
      N -= base;
    }
    base *= -2;
  }
  reverse(S.begin(), S.end());
  cout << S << endl;
}

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

int main() {
  ll N;
  cin >> N;
  if (N == 0) {
    cout << 0 << endl;
    return 0;
  }

  ll base = 1;
  string S;
  while (N != 0) {
    if (N % (base * 2) == 0)
      S.push_back('0');
    else {
      S.push_back('1');
      N -= base;
    }
    base *= -2;
  }
  reverse(S.begin(), S.end());
  cout << S << endl;
}
Problem p03286 (C++)

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

int main() {
  int n, d = 1;
  string s = "";
  cin >> n;
  if (n == 0) {
    cout << 0;
  } else {
    while (n != 0) {
      if (n % abs(d * 2) != 0) {
        s = "1" + s;
        n -= d;
      } else {
        s = "0" + s;
      }
      d *= -2;
    }
    cout << s;
  }
  return 0;
}

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

int main() {
  long long n, d = 1;
  string s = "";
  cin >> n;
  if (n == 0) {
    cout << 0;
  } else {
    while (n != 0) {
      if (n % abs(d * 2) != 0) {
        s = "1" + s;
        n -= d;
      } else {
        s = "0" + s;
      }
      d *= -2;
    }
    cout << s;
  }
  return 0;
}
Problem p03286 (C++)

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

using namespace std;

int main() {
  long long N;
  cin >> N;

  string ans;

  if (N == 0) {
    ans = "0";
  } else {
    for (int m = -2; N != 0; m *= -2) {
      if (N % m == 0) {
        ans += '0';

      } else {
        ans += '1';
        N += m / 2;
      }
    }
  }
  reverse(ans.begin(), ans.end());

  cout << ans << endl;
}


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

using namespace std;

int main() {
  long long N;
  cin >> N;

  string ans;

  if (N == 0) {
    ans = "0";
  } else {
    for (long long m = -2; N != 0; m *= -2) {
      if (N % m == 0) {
        ans += '0';

      } else {
        ans += '1';
        N += m / 2;
      }
    }
  }
  reverse(ans.begin(), ans.end());

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <chrono>
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;

int main() {
  cin >> N;
  ll sum[BUF];
  sum[0] = 1, sum[1] = -2;
  for (int i = 2; i < 31; i++) {
    if (i & 1)
      sum[i] = sum[i - 2] - pow(2, i);
    else
      sum[i] = sum[i - 2] + pow(2, i);
  }
  vector<char> S(BUF, '0');
  while (N != 0) {
    int i = 0;
    if (N > 0) {
      while (N > sum[i]) {
        i++;
      }
      S[i] = '1';
      N -= pow(2, i);
    } else {
      while (N < sum[i]) {
        i++;
      }
      S[i] = '1';
      N += pow(2, i);
    }
  }
  bool flag = 0;
  for (int i = BUF - 1; i >= 0; i--) {
    if (S[i] == '1')
      flag = 1;
    if (flag)
      cout << S[i];
  }
  if (flag == 0)
    cout << 0 << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#include <chrono>
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;

int main() {
  cin >> N;
  ll sum[BUF];
  sum[0] = 1, sum[1] = -2;
  for (int i = 2; i < BUF; i++) {
    if (i & 1)
      sum[i] = sum[i - 2] - pow(2, i);
    else
      sum[i] = sum[i - 2] + pow(2, i);
  }
  vector<char> S(BUF, '0');
  while (N != 0) {
    int i = 0;
    if (N > 0) {
      while (N > sum[i]) {
        i++;
      }
      S[i] = '1';
      N -= pow(2, i);
    } else {
      while (N < sum[i]) {
        i++;
      }
      S[i] = '1';
      N += pow(2, i);
    }
  }
  bool flag = 0;
  for (int i = BUF - 1; i >= 0; i--) {
    if (S[i] == '1')
      flag = 1;
    if (flag)
      cout << S[i];
  }
  if (flag == 0)
    cout << 0 << endl;
}
Problem p03286 (C++)

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

int main() {
  ll n;
  cin >> n;
  deque<ll> deq;
  while (n != 0) {
    if (n % -2 == 0) {
      deq.push_front(0);
    }
    if (n % -2 != 0) {
      n--;
      deq.push_front(1);
    }
    n /= -2;
  }
  while (deq.front() == 0)
    deq.pop_front();
  while (deq.size() != 0) {
    cout << deq.front();
    deq.pop_front();
  }
}


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

int main() {
  ll n;
  cin >> n;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  deque<ll> deq;
  while (n != 0) {
    if (n % -2 == 0) {
      deq.push_front(0);
    }
    if (n % -2 != 0) {
      n--;
      deq.push_front(1);
    }
    n /= -2;
  }
  while (deq.front() == 0)
    deq.pop_front();
  while (deq.size() != 0) {
    cout << deq.front();
    deq.pop_front();
  }
}
Problem p03286 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
  int64_t N;
  string S = "";
  cin >> N;
  if (N == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; N != 0; i++) {
    int a = pow(2, i + 1), b;
    if (N % a == 0) {
      S += '0';
    } else {
      S += '1';
      N -= pow(-2, i);
    }
  }
  reverse(ALL(S));
  cout << S << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
  int64_t N;
  string S = "";
  cin >> N;
  if (N == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int64_t i = 0; N != 0; i++) {
    int64_t a = pow(2, i + 1);
    if (N % a == 0) {
      S += '0';
    } else {
      S += '1';
      N -= pow(-2, i);
    }
  }
  reverse(ALL(S));
  cout << S << endl;
}
Problem p03286 (C++)

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

int main() {
  int n, i, ni = 2, mni = 1, a[10000];
  cin >> n;
  for (i = 0;; i++) {
    if (n % ni == 0) {
      a[i] = 0;
    } else {
      a[i] = 1;
      n -= mni;
    }
    if (n == 0) {
      break;
    }
    ni *= 2;
    mni *= -2;
  }
  for (; i >= 0; i--) {
    cout << a[i];
  }
}


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

int main() {
  long int n, i, ni = 2, mni = 1, a[10000];
  cin >> n;
  for (i = 0;; i++) {
    if (n % ni == 0) {
      a[i] = 0;
    } else {
      a[i] = 1;
      n -= mni;
    }
    if (n == 0) {
      break;
    }
    ni *= 2;
    mni *= -2;
  }
  for (; i >= 0; i--) {
    cout << a[i];
  }
}
Problem p03286 (Python)

Buggy submission (status: Runtime Error):
# -2進数を求める
N = int(input())

if N == 0:
    print(0)
else:
    ans = ""
    while N != 0:
        if N % 2 != 0:
            N -= 1
            ans = "1" + ans
        else:
            ans = "0" + ans
        N = N // (-2)
print(ans)


Fixed submission:
# -2進数を求める
N = int(input())

if N == 0:
    print(0)
else:
    ans = ""
    while N != 0:
        if N % 2 != 0:
            N -= 1
            ans = "1" + ans
        else:
            ans = "0" + ans
        N = N // (-2)
    print(ans)
Problem p03286 (C++)

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

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

  int i = 0, x = 1;
  string s = (n != 0 ? "" : "0");

  while (n != 0) {
    if (n % (x * -2) != 0) {
      s = "1" + s;
      n -= x;
    } else {
      s = "0" + s;
    }
    x *= -2;
  }

  cout << s << endl;
}

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

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

  int i = 0;
  long long x = 1;
  string s = (n != 0 ? "" : "0");

  while (n != 0) {
    if (n % (x * -2) != 0) {
      s = "1" + s;
      n -= x;
    } else {
      s = "0" + s;
    }
    x *= -2;
  }

  cout << s << endl;
}
Problem p03286 (C++)

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

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

  bool s[1000] = {};
  int i, mod = 2;
  for (i = 0; n != 0; i++) {
    if (n % mod) {
      s[i] = true;
      n -= pow(-2, i);
    }
    mod *= 2;
  }

  for (i -= 1; i > 0; i--)
    cout << s[i];
  cout << s[0] << endl;
}

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

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

  bool s[1000] = {};
  int i;
  long long mod = 2;
  for (i = 0; n != 0; i++) {
    if (n % mod) {
      s[i] = true;
      n -= pow(-2, i);
    }
    mod *= 2;
  }

  for (i -= 1; i > 0; i--)
    cout << s[i];
  cout << s[0] << endl;
}
Problem p03286 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <math.h>
#include <string>

using namespace std;
string calc(long n, long k) {
  if (n == 0)
    return "0";

  if (n % int(pow(-2, k + 1)) == 0)
    return calc(n, k + 1) + "0";
  return calc(n - pow(-2, k), k + 1) + "1";
}

int main() {
  int N;
  cin >> N;
  string ans = calc(N, 0);
  if (ans.size() != 1)
    ans.erase(ans.begin());
  cout << ans << endl;
}

Fixed submission:
#include <iostream>
#include <math.h>
#include <string>

using namespace std;
string calc(long n, long k) {
  if (n == 0)
    return "0";

  if (n % long(pow(-2, k + 1)) == 0)
    return calc(n, k + 1) + "0";
  return calc(n - pow(-2, k), k + 1) + "1";
}

int main() {
  int N;
  cin >> N;
  string ans = calc(N, 0);
  if (ans.size() != 1)
    ans.erase(ans.begin());
  cout << ans << endl;
}
Problem p03286 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;

int main() {
  int n;
  cin >> n;
  string ans;
  stringstream ss;
  stringstream rs;
  for (; true;) {
    int rank;
    int a;
    a = abs(n);
    rank = a % 2;
    n = (n - rank) / (-2);
    ss << rank;
    if (n == 1 or n == -1) {
      break;
    }
  }
  if (n == 1) {
    ss << 1;
  } else {
    ss << 11;
  }
  ss >> ans;
  reverse(ans.begin(), ans.end());
  cout << ans << "\n";
}

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

int main() {
  int n;
  cin >> n;
  string ans;
  stringstream ss;
  stringstream rs;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (; true;) {
    int rank;
    int a;
    a = abs(n);
    rank = a % 2;
    n = (n - rank) / (-2);
    ss << rank;
    if (n == 1 or n == -1) {
      break;
    }
  }
  if (n == 1) {
    ss << 1;
  } else {
    ss << 11;
  }
  ss >> ans;
  reverse(ans.begin(), ans.end());
  cout << ans << "\n";
}
Problem p03286 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  string s;
  int n, memo = 2, count = 0;
  cin >> n;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  while (n) {
    if (abs(n) % memo != 0) {
      s.insert(0, "1");
      n -= ((count % 2 == 0) ? (memo / 2) : (-1 * (memo / 2)));
    } else {
      s.insert(0, "0");
    }
    memo *= 2;
    count++;
  }
  cout << s << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  string s;
  ll n, memo = 2, count = 0;
  cin >> n;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  while (n) {
    if (abs(n) % memo != 0) {
      s.insert(0, "1");
      n -= ((count % 2 == 0) ? (memo / 2) : (-1 * (memo / 2)));
    } else {
      s.insert(0, "0");
    }
    memo *= 2;
    count++;
  }
  cout << s << endl;
  return 0;
}
Problem p03286 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vin = vector<int>;
using vll = vector<long long>;
using vvin = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vstr = vector<string>;
using vvstr = vector<vector<string>>;
using vch = vector<char>;
using vvch = vector<vector<char>>;
using vbo = vector<bool>;
using vvbo = vector<vector<bool>>;
using vpii = vector<pair<int, int>>;
using pqsin = priority_queue<int, vector<int>, greater<int>>;
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define decp(n) cout << fixed << setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  vin s(10000000);
  int fac = 2;
  int i = 0;
  while (n) {
    if (n % fac)
      s[i] = 1;
    else
      s[i] = 0;
    if (n % fac) {
      if (i % 2)
        n += pow(2, i);
      else
        n -= pow(2, i);
    }
    fac *= 2;
    i++;
  }
  for (int j = i - 1; j >= 0; j--)
    cout << s[j];
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vin = vector<int>;
using vll = vector<long long>;
using vvin = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vstr = vector<string>;
using vvstr = vector<vector<string>>;
using vch = vector<char>;
using vvch = vector<vector<char>>;
using vbo = vector<bool>;
using vvbo = vector<vector<bool>>;
using vpii = vector<pair<int, int>>;
using pqsin = priority_queue<int, vector<int>, greater<int>>;
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define decp(n) cout << fixed << setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  vin s(1000);
  ll fac = 2;
  int i = 0;
  while (n) {
    if (n % fac)
      s[i] = 1;
    else
      s[i] = 0;
    if (n % fac) {
      if (i % 2)
        n += pow(2, i);
      else
        n -= pow(2, i);
    }
    fac *= 2;
    i++;
  }
  for (int j = i - 1; j >= 0; j--)
    cout << s[j];
  cout << endl;
}
Problem p03286 (C++)

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

int main() {

  int n;
  cin >> n;

  char ans[100];
  int digit;
  if (n == 0) {
    puts("0");
  } else if (n > 0) {
    // positive
    digit = 1;
    ll max_num = 1;
    ll min_num;
    while (max_num < n) {
      min_num = max_num;
      digit += 2;
      max_num += 1LL << (digit - 1);
    }
    ans[0] = '1';
    for (int i = 1; i < digit; i++) {
      int mid = (max_num + min_num) / 2;
      if (n <= mid) {
        ans[i] = (i % 2 == 0) ? '0' : '1';
        max_num = mid;
      } else {
        ans[i] = (i % 2 == 0) ? '1' : '0';
        min_num = mid;
      }
    }
  } else {
    // negative
    n *= -1;
    digit = 2;
    ll max_num = 2;
    ll min_num;
    while (max_num < n) {
      min_num = max_num;
      digit += 2;
      max_num += 1LL << (digit - 1);
    }
    ans[0] = '1';
    for (int i = 1; i < digit; i++) {
      int mid = (max_num + min_num) / 2;
      if (n <= mid) {
        ans[i] = (i % 2 == 0) ? '0' : '1';
        max_num = mid;
      } else {
        ans[i] = (i % 2 == 0) ? '1' : '0';
        min_num = mid;
      }
    }
  }

  rep(i, digit) { printf("%c", ans[i]); }
  cout << endl;
  return 0;
}

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

int main() {

  int n;
  cin >> n;

  char ans[100];
  int digit;
  if (n == 0) {
    puts("0");
    return 0;
  } else if (n > 0) {
    // positive
    digit = 1;
    ll max_num = 1;
    ll min_num;
    while (max_num < n) {
      min_num = max_num;
      digit += 2;
      max_num += 1LL << (digit - 1);
    }
    ans[0] = '1';
    for (int i = 1; i < digit; i++) {
      int mid = (max_num + min_num) / 2;
      if (n <= mid) {
        ans[i] = (i % 2 == 0) ? '0' : '1';
        max_num = mid;
      } else {
        ans[i] = (i % 2 == 0) ? '1' : '0';
        min_num = mid;
      }
    }
  } else {
    // negative
    n *= -1;
    digit = 2;
    ll max_num = 2;
    ll min_num;
    while (max_num < n) {
      min_num = max_num;
      digit += 2;
      max_num += 1LL << (digit - 1);
    }
    ans[0] = '1';
    for (int i = 1; i < digit; i++) {
      int mid = (max_num + min_num) / 2;
      if (n <= mid) {
        ans[i] = (i % 2 == 0) ? '0' : '1';
        max_num = mid;
      } else {
        ans[i] = (i % 2 == 0) ? '1' : '0';
        min_num = mid;
      }
    }
  }

  rep(i, digit) { printf("%c", ans[i]); }
  cout << endl;
  return 0;
}
Problem p03286 (C++)

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

int main() {
  int n;
  cin >> n;
  string ans;
  while (true) {
    if (n % (-2) == 0) {
      ans = "0" + ans;
      n = n / (-2);
    } else {
      n = (n - 1) / (-2);
      ans = "1" + ans;
    }

    if (n == 1) {
      ans = "1" + ans;
      break;
    }
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  string ans;
  while (true) {
    if (n % (-2) == 0) {
      ans = "0" + ans;
      n = n / (-2);
    } else {
      n = (n - 1) / (-2);
      ans = "1" + ans;
    }

    if (n == 0) {
      break;
    }
  }
  cout << ans << endl;
}
Problem p03286 (C++)

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

signed main() {
  int n, r = 1, two = 2;
  stack<int> s;

  cin >> n;

  if (n == 0) {
    cout << "0\n";
  } else {
    while (n != 0) {
      if (n % two != 0) {
        n -= r;
        s.push(1);
      } else {
        s.push(0);
      }
      r = r * -2;
      two = two * 2;
    }

    while (!(s.empty())) {
      cout << s.top();
      s.pop();
    }
    cout << endl;
  }

  return (0);
}

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

signed main() {
  long long n, r = 1, two = 2;
  stack<int> s;

  cin >> n;

  if (n == 0) {
    cout << "0\n";
  } else {
    while (n != 0) {
      if (n % two != 0) {
        n -= r;
        s.push(1);
      } else {
        s.push(0);
      }
      r = r * -2;
      two = two * 2;
    }

    while (!(s.empty())) {
      cout << s.top();
      s.pop();
    }
    cout << endl;
  }

  return (0);
}
Problem p03286 (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++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int main() {
  ll N;
  cin >> N;
  if (N == 0) {
    cout << 0 << endl;
    return 0;
  }
  string S;
  int i = 1;
  while (N != 0) {
    if (N % (i * -2) != 0) {
      S.push_back('1');
      N -= i;
    } else {
      S.push_back('0');
    }
    i *= -2;
  }
  reverse(S.begin(), S.end());
  cout << S << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int main() {
  ll N;
  cin >> N;
  if (N == 0) {
    cout << 0 << endl;
    return 0;
  }
  string S;
  ll i = 1;
  while (N != 0) {
    if (N % (i * -2) != 0) {
      S.push_back('1');
      N -= i;
    } else {
      S.push_back('0');
    }
    i *= -2;
  }
  reverse(S.begin(), S.end());
  cout << S << endl;
}
Problem p03286 (C++)

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

using namespace std;

typedef long long ll;

int main() {
  ll n, sgn;
  cin >> n;
  sgn = n < 0;
  n = abs(n);
  ll ans = 0;
  for (int i = 0, k = 1; n >= k; i++, k <<= 1) {
    if (n & k) {
      ans ^= k;
      if (i & 1 ^ sgn) {
        n += k;
      }
    }
  }
  string s = bitset<40>(ans).to_string();
  s = string(find(s.begin(), s.end(), '1'), s.end());
  cout << (s.size() == 0 ? "0" : s) << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
  ll n, sgn;
  cin >> n;
  sgn = n < 0;
  n = abs(n);
  ll ans = 0;
  for (ll i = 0, k = 1; n >= k; i++, k <<= 1) {
    if (n & k) {
      ans ^= k;
      if (i & 1 ^ sgn) {
        n += k;
      }
    }
  }
  string s = bitset<40>(ans).to_string();
  s = string(find(s.begin(), s.end(), '1'), s.end());
  cout << (s.size() == 0 ? "0" : s) << endl;
  return 0;
}