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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, x) for (int i = 0; i < x; i++)
#define re(i, x, y) for (int i = x; i < y; i++)

long long INF = 1e9;
const long long mod = 2019;
#define ll long long

int main() {
  int N;
  cin >> N;
  for (ll h = 1; h <= 3500; h++) {
    for (ll n = 2; n <= 3500; n++) {
      ll w = h * n * N / (4 * h * n - N * (h + n));
      if (w > 0) {
        if ((h * n * N) % (4 * h * n - N * (h + n)) == 0) {
          cout << h << " " << n << " " << w << endl;
          return 0;
        }
      }
    }
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, x) for (int i = 0; i < x; i++)
#define re(i, x, y) for (int i = x; i < y; i++)

long long INF = 1e9;
const long long mod = 2019;
#define ll long long

int main() {
  int N;
  cin >> N;
  for (ll h = 1; h <= 3500; h++) {
    for (ll n = 2; n <= 3500; n++) {
      ll tmp1 = h * N * n;
      ll tmp2 = 4 * h * n - N * (h + n);
      if (tmp2 > 0 && (tmp1 % tmp2) == 0) {
        cout << h << " " << n << " " << tmp1 / tmp2 << endl;
        return 0;
      }
    }
  }
  return 0;
}
Problem p03583 (C++)

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

typedef long long ll;

int main() {
  ll n;
  cin >> n;
  ll a, b, c;
  for (ll i = 1; i <= 3500; i++) {
    for (ll j = 1; j <= 3500; j++) {
      if ((i * j * n) % (4 * i * j - i * n - j * n) == 0 &&
          4 * i * j - i * n - j * n > 0) {
        a = i, b = j, c = (i * j * n) / (4 * i * j - i * n - j * n);
      }
    }
  }
  cout << a << " " << b << " " << c << endl;
}

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

typedef long long ll;

int main() {
  ll n;
  cin >> n;
  ll a, b, c;
  for (ll i = 1; i <= 3500; i++) {
    for (ll j = 1; j <= 3500; j++) {
      if (4 * i * j - i * n - j * n > 0) {
        if ((i * j * n) % (4 * i * j - i * n - j * n) == 0) {
          a = i, b = j, c = (i * j * n) / (4 * i * j - i * n - j * n);
        }
      }
    }
  }
  cout << a << " " << b << " " << c << endl;
}
Problem p03583 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1e9 + 7
#define LINF (long long)4e18

int main() {
  long long N;
  cin >> N;
  repr(i, 1, 3501) {
    repr(j, 1, 3501) {
      long long w = N * (i + j) / (4 * i * j - N);
      if (N * (i + j) % (4 * i * j - N) == 0 && (4 * i * j - N > 0)) {
        cout << i << " " << j << " " << w << endl;
        return 0;
      }
    }
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1e9 + 7
#define LINF (long long)4e18

int main() {
  long long N;
  cin >> N;
  repr(i, 1, 3501) {
    repr(j, 1, 3501) {
      if ((4 * i * j - N * i - N * j > 0) &&
          N * i * j % (4 * i * j - N * i - N * j) == 0) {
        long long w = N * i * j / (4 * i * j - N * i - N * j);
        cout << i << " " << j << " " << w << endl;
        return 0;
      }
    }
  }
}
Problem p03583 (C++)

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

long long int gcd(long long int m, long long int n) {
  long long int temp;
  while (m % n != 0) {
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

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

  for (long long int h = 1; h <= 3500; h++) {
    int M = N;
    if (4 * h <= N)
      continue;
    if (M > 1) {
      if (gcd(M, h) == 1)
        continue;
      M = M / gcd(M, h);
    }
    for (long long int n = 1; n <= 3500; n++) {
      if (4 * h * n <= N * (h + n))
        continue;
      if (M > 1) {
        if (gcd(M, n) == 1)
          continue;
        M = M / gcd(M, h);
      }
      for (long long int w = 1; w <= 3500; w++) {
        if (M > 1) {
          if (gcd(M, w) == 1)
            continue;
          M = M / gcd(M, w);
          if (M != 1)
            continue;
        }
        if (4 * h * n * w == N * (n * w + h * n + h * w)) {
          cout << h << ' ' << n << ' ' << w << ' ' << endl;
          return 0;
        }
      }
    }
  }
  return 0;
}

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

long long int gcd(long long int m, long long int n) {
  long long int temp;
  while (m % n != 0) {
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

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

  for (long long int h = 1; h <= 3500; h++) {
    int M = N;
    if (4 * h <= N)
      continue;
    if (M > 1) {
      if (gcd(M, h) == 1)
        continue;
      M = M / gcd(M, h);
    }
    for (long long int n = 1; n <= 3500; n++) {
      if (4 * h * n <= N * (h + n))
        continue;
      if (M > 1) {
        if (gcd(M, n) == 1)
          continue;
        M = M / gcd(M, h);
      }
      if (4 * h * n - N * n - N * h < 0)
        continue;
      if ((N * h * n) % (4 * h * n - N * n - N * h) != 0)
        continue;
      long long int w = (N * h * n) / (4 * h * n - N * n - N * h);
      cout << h << ' ' << n << ' ' << w << ' ' << endl;
      return 0;
    }
  }
  return 0;
}
Problem p03583 (C++)

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

using namespace std;
typedef long long ll;
const int N = 100000 + 10;

int main() {
  ll n;
  cin >> n;
  for (int h = 1; h <= 10000; h++) {
    for (int m = 1; m < 100000; m++) {
      double q = (4.0 / n);
      double v = (1.0 / h) + (1.0 / m);
      q -= v;
      double w = 1 / q;
      ll t = 1 / q;
      if (w > 0 && q != 0 && ceil(w) == t && t != 0 && t <= 3500) {
        cout << h << " " << m << " " << w << endl;
        return 0;
      }
    }
  }
}

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

using namespace std;
typedef long long ll;
const int N = 100000 + 10;

int main() {
  ll n;
  cin >> n;
  for (int h = 1; h <= 10000; h++) {
    for (int m = 1; m < 30000; m++) {
      double q = (4.0 / n);
      double v = (1.0 / h) + (1.0 / m);
      q -= v;
      double w = 1 / q;
      ll t = 1 / q;
      if (w > 0 && q != 0 && ceil(w) == t && t != 0 && t <= 3500) {
        cout << h << " " << m << " " << w << endl;
        return 0;
      }
    }
  }
}
Problem p03583 (C++)

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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<P, int>;
using PP = pair<P, P>;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = ll(1e9) + 7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-9;

int main() {
  ll n;
  cin >> n;
  constexpr ll MAX_X = 3500;
  for (ll x = 1; x <= MAX_X; x++) {
    for (ll y = 1; y <= MAX_X; y++) {
      ll z = (n * x * y) / (4 * x * y - n * (x + y));
      if (z >= 1 && z <= MAX_X &&
          n * (x * y + y * z + z * x) == 4 * x * y * z) {
        cout << x << " " << y << " " << z << endl;
        return 0;
      }
    }
  }
  return 0;
}


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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<P, int>;
using PP = pair<P, P>;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = ll(1e9) + 7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-9;

int main() {
  ll n;
  cin >> n;
  constexpr ll MAX_X = 3500;
  for (ll x = 1; x <= MAX_X; x++) {
    for (ll y = 1; y <= MAX_X; y++) {
      ll a = 4 * x * y - n * (x + y);
      if (a <= 0)
        continue;
      ll z = (n * x * y) / a;
      if (z >= 0 && z <= MAX_X &&
          n * (x * y + y * z + z * x) == 4 * x * y * z) {
        cout << x << " " << y << " " << z << endl;
        return 0;
      }
    }
  }
  return 0;
}
Problem p03583 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  double N;
  cin >> N;
  for (double i = 1; i <= 3500; i++)
    for (double j = 1; j <= 3500; j++)
      for (double k = 1; k <= 3500; k++)
        if (4 / N == 1 / i + 1 / j + 1 / k) {
          cout << i << ' ' << j << ' ' << k << endl;
          return 0;
        }
  return 0;
}

Fixed submission:
#include <cstdio>
#define int long long
int n;
main() {
  scanf("%lld", &n);
  int i, j, t1, t2;
  for (i = 1; i <= 4000; ++i)
    for (j = 1; j <= 4000; ++j) {
      t1 = n * i * j;
      t2 = 4 * i * j - n * i - n * j;
      if (t2 > 0 && t1 % t2 == 0) {
        printf("%lld %lld %lld\n", i, j, t1 / t2);
        return 0;
      }
    }
}
Problem p03583 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define reg(i, a, b) for (int i = ((int)(a)); i <= ((int)(b)); i++)
#define irep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define ireg(i, a, b) for (int i = ((int)(b)); i >= ((int)(a)); i--)
typedef long long ll;
typedef pair<ll, ll> mp;

ll N, h = 0, n = 0, w = 0;

int main(void) {
  cin >> N;
  n = N;
  reg(i, 1, N / 3 + 1) {
    if ((N * i) % (3 * i - N) == 0 && 3 * i > N) {
      w = i;
      h = (N * i) / (3 * i - N);
      break;
    }
  }
  printf("%lld %lld %lld\n", h, w, n);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define reg(i, a, b) for (int i = ((int)(a)); i <= ((int)(b)); i++)
#define irep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define ireg(i, a, b) for (int i = ((int)(b)); i >= ((int)(a)); i--)
typedef long long ll;
typedef pair<ll, ll> mp;

ll N, h = 0, n = 0, w = 0;

int main(void) {
  cin >> N;
  reg(i, 1, 3500) {
    reg(j, 1, 3500) {
      if (4 * i * j - N * (i + j) > 0 &&
          (N * i * j) % (4 * i * j - N * (i + j)) == 0) {
        w = i;
        h = j;
        n = (N * i * j) / (4 * i * j - N * (i + j));
        break;
      }
    }
  }
  printf("%lld %lld %lld\n", h, w, n);
  return 0;
}
Problem p03583 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int INF = 1e9;
inline ll read() {
  ll x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-')
    ch = getchar();
  if (ch == '-')
    flag = -1, ch = getchar();
  while (isdigit(ch))
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * flag;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  ll i, j, k, m, n;
  n = read();
  for (i = 1; i <= 3500; i++)
    for (j = 1; j <= 3500; j++) {
      ll sum1 = 0, sum2, sum3 = 0;
      sum2 = n * (i * j / gcd(i, j)) / gcd(n, i * j / gcd(i, j));
      sum1 += (sum2 / n) * 4;
      sum3 += sum2 / i;
      sum3 += sum2 / j;
      if (sum3 >= sum1)
        continue;
      if (gcd(sum1 - sum3, sum2) == sum1 - sum3) {
        printf("%lld %lld %lld\n", i, j, sum2 / (sum1 - sum3));
        return 0;
      }
    }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int INF = 1e9;
inline ll read() {
  ll x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-')
    ch = getchar();
  if (ch == '-')
    flag = -1, ch = getchar();
  while (isdigit(ch))
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * flag;
}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  ll i, j, k, m, n;
  n = read();
  for (i = 1; i <= 3500; i++)
    for (j = 1; j <= 3500; j++) {
      if (1.0 / i + 1.0 / j > 4.0 / n)
        continue;
      ll sum1 = 0, sum2, sum3 = 0;
      sum2 = n * (i * j / gcd(i, j)) / gcd(n, i * j / gcd(i, j));
      sum1 += (sum2 / n) * 4;
      sum3 += sum2 / i;
      sum3 += sum2 / j;
      if (sum3 >= sum1)
        continue;
      if (gcd(sum1 - sum3, sum2) == sum1 - sum3) {
        printf("%lld %lld %lld\n", i, j, sum2 / (sum1 - sum3));
        return 0;
      }
    }
  return 0;
}
Problem p03583 (C++)

Buggy submission (status: Runtime Error):
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
const double pi = 3.14159265358979323846;
const int inf = 2e9;
const ll INF = 1e18;
using P = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  for (ll i = 1; i <= 3500; i++) {
    for (ll j = 1; j <= 3500; j++) {
      ll a = n * i * j, b = 4 * i * j - n * i - n * j;
      if (a % b == 0 && a > 0) {
        cout << i << " " << j << " " << a / b << endl;
        return 0;
      }
    }
  }
}

Fixed submission:
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
const double pi = 3.14159265358979323846;
const int inf = 2e9;
const ll INF = 1e18;
using P = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  for (ll i = 1; i <= 3500; i++) {
    for (ll j = 1; j <= 3500; j++) {
      ll a = 4 * i * j - n * j - n * i, b = n * i * j;
      if (a > 0 && b % a == 0) {
        cout << i << " " << j << " " << b / a << endl;
        return 0;
      }
    }
  }
}
Problem p03583 (C++)

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

using namespace std;
typedef long long ll;
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main() {
  ll n, a = 0, b = 0;
  cin >> n;

  for (int i = 1; i < 3501; i++) {
    for (int j = 1; j < 3501; j++) {
      a = 4 * (i * j) - n * i - n * j;
      b = n * i * j;
      if (b % a == 0 && a > 0) {
        cout << i << ' ' << j << ' ' << b / a;
        return 0;
      }
    }
  }
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main() {
  ll n, a = 0, b = 0;
  cin >> n;

  for (int i = 1; i < 3501; i++) {
    for (int j = 1; j < 3501; j++) {
      a = 4 * (i * j) - n * i - n * j;
      b = n * i * j;
      if (a > 0 && b % a == 0) {
        cout << i << ' ' << j << ' ' << b / a;
        return 0;
      }
    }
  }
  return 0;
}
Problem p03583 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
using namespace std;

#define int long long
// typedef    long long          ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> P;

const int INF = 1e+9;
const double EPS = 1e-9;
const int MOD = 1000000007;

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

signed main() {
  int n;
  cin >> n;
  for (int h = 1; h <= 3500; h++) {
    for (int w = 1; w <= 3500; w++) {
      int si = 4 * h * w - n * (w + h), bo = h * w * n;
      if (bo % si == 0) {
        cout << h << " " << w << " " << bo << endl;
        return 0;
      }
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
using namespace std;

#define int long long
// typedef    long long          ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> P;

const int INF = 1e+9;
const double EPS = 1e-9;
const int MOD = 1000000007;

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

signed main() {
  int n;
  cin >> n;
  for (int h = 1; h <= 3500; h++) {
    for (int w = 1; w <= 3500; w++) {
      int si = 4 * h * w - n * (w + h), bo = h * w * n;
      if (si >= 1 && bo % si == 0) {
        cout << h << " " << w << " " << bo / si << endl;
        return 0;
      }
    }
  }
  return 0;
}
Problem p03583 (C++)

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

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << (x) << endl

int main() {
  ll N;
  cin >> N;
  for (int n = 1; n < 3501; n++) {
    for (int h = 1; h < 3501; h++) {
      if ((n * N * h) % (n * (4 * h - N) - N * h) == 0) {
        cout << h << " " << n << " " << (n * N * h) / (n * (4 * h - N) - N * h);
        return 0;
      }
    }
  }
}

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

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << (x) << endl

int main() {
  ll N;
  cin >> N;
  for (ll n = 1; n < 3501; n++) {
    for (ll h = 1; h < 3501; h++) {
      if ((4 * h * n - N * n - N * h) > 0 &&
          (n * N * h) % (4 * h * n - N * n - N * h) == 0) {
        cout << h << " " << n << " " << (n * N * h) / (n * (4 * h - N) - N * h);
        return 0;
      }
    }
  }
}
Problem p03583 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 500 + 50;
ll n;
int main() {
  while (cin >> n) {
    ll a, b, c;
    if (n == 2)
      a = 1, b = c = 2;
    if (n == 3)
      a = 2, b = 2, c = 3;
    if (n == 4)
      a = b = c = 3;
    if (n > 4) {
      if (n & 1) {
        for (a = 2; a <= 3500; a++)
          for (b = 2; b <= 3500; b++) {
            int up = n * a * b;
            int down = 4 * a * b - n * b - n * a;
            if (up % down == 0 && up / down > 0) {
              cout << a << " " << b << " " << up / down;
              return 0;
            }
          }
      } else {
        a = b = n;
        c = n / 2;
      }
    }
    cout << a << " " << b << " " << c;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 500 + 50;
ll n;
int main() {
  while (cin >> n) {
    ll a, b, c;
    if (n == 2)
      a = 1, b = c = 2;
    if (n == 3)
      a = 2, b = 2, c = 3;
    if (n == 4)
      a = b = c = 3;
    if (n > 4) {
      if (n & 1) {
        for (a = 2; a <= 3500; a++)
          for (b = 2; b <= 3500; b++) {
            ll up = n * a * b;
            ll down = 4 * a * b - n * b - n * a;
            if (down <= 0)
              continue;
            if (up % down == 0) {
              cout << a << " " << b << " " << up / down;
              return 0;
            }
          }
      } else {
        a = b = n;
        c = n / 2;
      }
    }
    cout << a << " " << b << " " << c;
  }
  return 0;
}
Problem p03583 (C++)

Buggy submission (status: Runtime Error):

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define make0(a) memset(a, 0, sizeof(a))
#define make1(a) memset(a, -1, sizeof(a))
#define ALL(v) v.begin(), v.end()
#define pi pair<int, int>
#define pll pair<ll, ll>
#define fast_cin() ios_base::sync_with_stdio(0)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

const int mod = 1e9 + 7;

int main() {
  fast_cin();
  ll n;
  cin >> n;
  for (ll i = 1; i <= 3500; i++) {
    for (ll j = 1; j <= 3500; j++) {
      ll x = n * i * j;
      ll y = 4 * i * j - n * i - n * j;
      if (y < 0)
        continue;
      if (x % y == 0) {
        cout << i << ' ' << j << ' ' << x / y << endl;
        return 0;
      }
    }
  }
  return 0;
}

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define make0(a) memset(a, 0, sizeof(a))
#define make1(a) memset(a, -1, sizeof(a))
#define ALL(v) v.begin(), v.end()
#define pi pair<int, int>
#define pll pair<ll, ll>
#define fast_cin() ios_base::sync_with_stdio(0)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

const int mod = 1e9 + 7;

int main() {
  fast_cin();
  ll n;
  cin >> n;
  for (ll i = 1; i <= 3500; i++) {
    for (ll j = 1; j <= 3500; j++) {
      ll x = n * i * j;
      ll y = 4 * i * j - n * i - n * j;
      if (y <= 0)
        continue;
      if (x % y == 0) {
        cout << i << ' ' << j << ' ' << x / y << endl;
        return 0;
      }
    }
  }
  return 0;
}
Problem p03583 (Python)

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

gets = stdin.readline


def main():
    n = int(gets())
    h, w = 0, 0
    flag = False
    for _ in range(3500):
        h += 1
        w = 0
        for _ in range(3500):
            w += 1
            x = n * h * w
            y = 4 * h * w - n * h - n * w
            if x >= y > 0 == x % y:
                print(h, w, x // y)
                flag = True
                break
        if flag:
            break
    return


if __name__ == "__main__":
    main()


Fixed submission:
from sys import stdin

gets = stdin.readline


def main():
    n = int(gets())
    h, w = 0, 0
    flag = False
    for _ in range(3500):
        h += 1
        w = 0
        for _ in range(3500):
            w += 1
            y = 4 * h * w - n * (h + w)
            if y > 0:
                modulo = n % y * h % y * w % y
                if modulo % y == 0:
                    print(h, w, (n * h * w) // y)
                    flag = True
                    break
        if flag:
            break
    return


if __name__ == "__main__":
    main()
Problem p03583 (Python)

Buggy submission (status: Runtime Error):
import sys

sys.setrecursionlimit(10**6)
INF = float("inf")
MOD = 10**9 + 7


def input():
    return sys.stdin.readline().strip()


def solve(N):
    N = int(input())
    M = 3501

    for h in range(1, M):
        for n in range(h, M):
            denominator = 4 * n * h - N * h - N * n
            if denominator <= 0:
                continue
            numerator = N * h * n

            if numerator % denominator == 0:
                return h, n, numerator // denominator


def main():
    N = int(input())
    h, n, w = solve(N)
    print(h, n, w)


if __name__ == "__main__":
    main()


Fixed submission:
import sys

sys.setrecursionlimit(10**6)
INF = float("inf")
MOD = 10**9 + 7


def input():
    return sys.stdin.readline().strip()


def solve(N):
    M = 3501

    for h in range(1, M):
        for n in range(h, M):
            denominator = 4 * n * h - N * h - N * n
            if denominator <= 0:
                continue
            numerator = N * h * n

            if numerator % denominator == 0:
                return h, n, numerator // denominator


def main():
    N = int(input())
    h, n, w = solve(N)
    print(h, n, w)


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

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

int main() {
  ll n;
  cin >> n;
  ll a, b, c;
  rep(i, 3500) {
    rep(j, 3500) {
      // cout << i << endl;
      if (i <= 1 or j <= 1) {
        continue;
      } else if ((n * i * j) % (4 * i * j - n * i - n * j) == 0) {
        a = i;
        b = j;
        c = (n * i * j) / (4 * i * j - n * i - n * j);
      }
    }
  }
  cout << a << " " << b << " " << c;

  return 0;
}

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

int main() {
  ll n;
  cin >> n;
  ll a, b, c;
  rep(i, 3500) {
    rep(j, 3500) {
      // cout << i << endl;
      if (i == 0 or j == 0) {
        continue;
      } else if ((4 * i * j - n * i - n * j) <= 0) {
        continue;
      } else if ((n * i * j) % (4 * i * j - n * i - n * j) == 0) {
        a = i;
        b = j;
        c = (n * i * j) / (4 * i * j - n * i - n * j);
      }
    }
  }
  cout << a << " " << b << " " << c;

  return 0;
}
Problem p03583 (C++)

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

int main() {
  int n;

  cin >> n;
  long long a, b, c;
  for (a = 1; a <= 3500; a++) {
    for (b = 1; b <= 3500; b++) {
      long long d = 4 * a * b - n * b - n * a;
      if (d != 0)
        if ((n * a * b) % d == 0) {
          c = n * a * b / d;
          if (c > 0) {
            cout << a << " " << b << " " << c << endl;
            return a, b, c;
          }
        }
    }
  }
  return 0;
}

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

int main() {
  int n;

  cin >> n;
  long long a, b, c;
  for (a = 1; a <= 3500; a++) {
    for (b = 1; b <= 3500; b++) {
      long long d = 4 * a * b - n * b - n * a;
      if (d != 0)
        if ((n * a * b) % d == 0) {
          c = n * a * b / d;
          if (c > 0) {
            cout << a << " " << b << " " << c << endl;
            return 0;
          }
        }
    }
  }
  return 0;
}
Problem p03583 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FAST std::ios::sync_with_stdio(false);
#define endl '\n'
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define MAX_N 200005
#define Mem(a, b) memset(a, b, sizeof(a))
#define FREI freopen("in.txt", "r", stdin)
#define FREO freopen("out.txt", "w", stdout)
using namespace std;
const ll mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  for (ll i = 1; i <= 3500; i++)
    for (ll j = 1; j <= 3500; j++) {
      if ((i * j * n) % (4 * i * j - n * (i + j)) == 0 &&
          (3 * i * j > n * (i + j))) {
        cout << i << " " << j << " " << (i * j * n) / (4 * i * j - n * (i + j))
             << endl;
        return 0;
      }
    }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define FAST std::ios::sync_with_stdio(false);
#define endl '\n'
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define MAX_N 200005
#define Mem(a, b) memset(a, b, sizeof(a))
#define FREI freopen("in.txt", "r", stdin)
#define FREO freopen("out.txt", "w", stdout)
using namespace std;
const ll mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  for (ll i = 1; i <= 3500; i++)
    for (ll j = 1; j <= 3500; j++) {
      if ((3 * i * j > n * (i + j)) &&
          (i * j * n) % (4 * i * j - n * (i + j)) == 0) {
        cout << i << " " << j << " " << (i * j * n) / (4 * i * j - n * (i + j))
             << endl;
        return 0;
      }
    }
  return 0;
}
Problem p03583 (C++)

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

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

  ll n;
  cin >> n;
  if (n % 2 == 0) {
    cout << n << " " << n << " " << n / 2 << endl;
    return 0;
  }
  rep1(h, 3500) {
    ll a = 4 * h - n;
    ll b = n * h;
    rep1(w, 3500) {
      ll y = (b * w) / (a * w - b);
      if (y > 0 && y * (a * w - b) == b * w) {
        cout << h << " " << w << " " << y << endl;
        return 0;
      }
    }
  }

  return 0;
}


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

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

  ll n;
  cin >> n;
  if (n % 2 == 0) {
    cout << n << " " << n << " " << n / 2 << endl;
    return 0;
  }
  rep1(h, 3500) {
    ll a = 4 * h - n;
    ll b = n * h;
    rep1(w, 3500) {
      if (a * w != b) {
        ll y = (b * w) / (a * w - b);
        if (y > 0 && y * (a * w - b) == b * w) {
          cout << h << " " << w << " " << y << endl;
          return 0;
        }
      }
    }
  }

  return 0;
}
Problem p03583 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdbool>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const long long INF = 1LL << 60;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ma = 1000000000 + 7;

ll N, h, n, w;
int main() {
  cin >> N;
  for (int i = 1; i <= 3500; i++) {
    for (int j = 1; j <= 3500; j++) {
      h = i;
      n = j;
      w = (N * h * n) / (4 * h * n - N * n - N * h);
      if (w >= 1) {
        cout << h << " " << n << " " << w << endl;
        return 0;
      }
    }
  }
}

Fixed submission:
#include <algorithm>
#include <cstdbool>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const long long INF = 1LL << 60;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ma = 1000000000 + 7;

ll N, h, n, w;
int main() {
  cin >> N;
  for (int i = 1; i <= 3500; i++) {
    for (int j = 1; j <= 3500; j++) {
      h = i;
      n = j;
      if (4 * h * n - N * n - N * h != 0 &&
          (N * h * n) % (4 * h * n - N * n - N * h) == 0) {
        w = (N * h * n) / (4 * h * n - N * n - N * h);
        if (w >= 1) {
          cout << h << " " << n << " " << w << endl;
          return 0;
        }
      }
    }
  }
}
Problem p03583 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }
int lcm(int a, int b) { return (a / gcd(a, b) * b); }

signed main() {
  int N;
  bool flag = false;
  cin >> N;

  for (int i = 1; i <= 3500; i++) {
    for (int j = i; j <= 3500; j++) {
      int nume = 4, deno = N;
      int lc = lcm(i, deno);
      int val = nume * (lc / deno) - lc / i;
      int div = gcd(lc, val);
      lc /= div, val /= div;

      deno = lc, nume = val;
      lc = lcm(j, deno);
      val = nume * (lc / deno) - lc / j;
      div = gcd(lc, val);
      val /= div, lc /= div;
      if (lc < 0)
        continue;
      if (val == 1) {
        flag = true;
        cout << i << " " << j << " " << lc << endl;
        break;
      }
    }
    if (flag)
      break;
  }

  return (0);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }
int lcm(int a, int b) { return (a / gcd(a, b) * b); }

signed main() {
  int N;
  bool flag = false;
  cin >> N;

  for (int i = max(N / 4 * 3, 1LL); i <= 3500; i++) {
    for (int j = 1; j <= 3500; j++) {
      int nume = 4, deno = N;
      int lc = lcm(i, deno);
      int val = nume * (lc / deno) - lc / i;
      int div = gcd(lc, val);
      lc /= div, val /= div;

      deno = lc, nume = val;
      lc = lcm(j, deno);
      val = nume * (lc / deno) - lc / j;
      div = gcd(lc, val);
      val /= div, lc /= div;
      if (lc < 0)
        continue;
      if (val == 1) {
        flag = true;
        cout << i << " " << j << " " << lc << endl;
        break;
      }
    }
    if (flag)
      break;
  }

  return (0);
}
Problem p03583 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  if (n % 2 == 0) {
    cout << n << " " << n << " " << n / 2 << endl;
  } else {
    for (int i = 1; i <= 3500; i++) {
      for (int j = i; j <= 3500; j++) {
        if ((n * i * j) % (4 * i * j - n * i - n * j) == 0) {
          if ((4 * i * j - n * i - n * j) > 0) {
            cout << i << " " << j << " ";
            cout << (n * i * j) / (4 * i * j - n * i - n * j) << endl;
            return 0;
          }
        }
      }
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  if (n % 2 == 0) {
    cout << n << " " << n << " " << n / 2 << endl;
  } else {
    for (int i = 1; i <= 3500; i++) {
      for (int j = i; j <= 3500; j++) {
        if ((4 * i * j - n * i - n * j) == 0) {
          continue;
        }
        if ((n * i * j) % (4 * i * j - n * i - n * j) == 0) {
          if ((4 * i * j - n * i - n * j) > 0) {
            cout << i << " " << j << " ";
            cout << (n * i * j) / (4 * i * j - n * i - n * j) << endl;
            return 0;
          }
        }
      }
    }
  }
  return 0;
}
Problem p03583 (C++)

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout << n << endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
// vector<tuple<long long, long long, long long>>vec;

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;
}

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

const int inf = 100000000;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  llong N;
  cin >> N;

  for (llong i = 1; i <= 3500; i++) {
    for (llong j = 1; j <= 3500; j++) {
      llong a = i + j;
      llong v = N * i * j;
      llong x = 4 * i * j - N * a;

      if (v % x == 0 && x > 0) {
        llong h = i;
        llong n = j;
        llong w = v / x;
        cout << h << " " << n << " " << w << endl;
        return 0;
      }
    }
  }
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout << n << endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
// vector<tuple<long long, long long, long long>>vec;

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;
}

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

const int inf = 100000000;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  llong N;
  cin >> N;

  for (llong i = 1; i <= 3500; i++) {
    for (llong j = 1; j <= 3500; j++) {
      llong a = i + j;
      llong v = N * i * j;
      llong x = 4 * i * j - N * a;

      if (x > 0) {
        if (v % x == 0) {
          llong w = v / x;
          cout << i << " " << j << " " << w << endl;
          return 0;
        }
      }
    }
  }
}
Problem p03583 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n; i++)
#define ll long long
#define modbig (10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 + 7)
using namespace std;

int main() {
  ll n, check = 0;
  cin >> n;
  for (ll h = 1; h <= 3500; h++) {
    for (ll b = 1; b <= 3500; b++) {
      if ((n * h * b) % (4 * h * b - n * (h + b)) == 0 &&
          4 * h * b > n * (h + b)) {
        ll w = (n * h * b) / (4 * h * b - n * (h + b));
        cout << h << " " << b << " " << w;
        check = 1;
        break;
      }
    }
    if (check == 1)
      break;
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n; i++)
#define ll long long
#define modbig (10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 + 7)
using namespace std;

int main() {
  ll n, check = 0;
  cin >> n;
  for (ll h = 1; h <= 3500; h++) {
    for (ll b = 1; b <= 3500; b++) {
      if (4 * h * b > n * (h + b) &&
          (n * h * b) % (4 * h * b - n * (h + b)) == 0) {
        int w = (n * h * b) / (4 * h * b - n * (h + b));
        cout << h << " " << b << " " << w;
        check = 1;
        break;
      }
    }
    if (check == 1)
      break;
  }
}
Problem p03583 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())

for n in range(1, 3501):
    for w in range(1, 3501):
        t = 4 * n * w - N * w - N * n
        if t > 0:
            h = N * n * w / t
            if h.is_integer() and h > 0:
                print(int(h), n, w)
                exit()


Fixed submission:
N = int(input())

for n in range(1, 3501):
    for w in range(n, 3501):
        t = 4 * n * w - N * w - N * n
        if t > 0:
            h = N * n * w / t
            if h.is_integer() and h > 0:
                print(int(h), n, w)
                exit()
Problem p03583 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#pragma warning(disable : 4996)
long long n;
int main() {
  cin >> n;
  for (int i = 1; i <= 3500; i++) {
    for (int j = 1; j <= 3500; j++) {
      long long A = 4LL * i * j - n * (i + j);
      long long B = n * i * j;
      if (B % A == 0 && A >= 1) {
        cout << i << " " << j << " " << B / A << endl;
        return 0;
      }
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#pragma warning(disable : 4996)
long long n;
int main() {
  cin >> n;
  for (int i = 1; i <= 3500; i++) {
    for (int j = 1; j <= 3500; j++) {
      long long A = 4LL * i * j - n * (i + j);
      long long B = n * i * j;
      if (A >= 1 && B % A == 0) {
        cout << i << " " << j << " " << B / A << endl;
        return 0;
      }
    }
  }
  return 0;
}
Problem p03584 (C++)

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

using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long

ll n, k;
ll a[100000], b[100000];

int main() {
  cin >> n >> k;
  REP(i, n) { cin >> a[i] >> b[i]; }

  ll max_v = 0;
  ll num = 0;
  ll max_d = 1;

  REP(i, 30) {
    if (max_d * 2 <= k) {
      max_d *= 2;
    } else {
      break;
    }
  }

  max_d -= 1;
  REP(i, n) {
    if (a[i] <= max_d) {
      max_v += b[i];
    }
  }

  ll next_d = max_d + 1;

  ll d = 1;
  ll plus = 1;
  while (1) {
    plus = 1;
    while (1) {
      if ((next_d | plus) <= k) {
        next_d = (next_d | plus);
        plus *= 2;
      } else {
        break;
      }
    }

    ll tmp_v = 0;
    REP(i, n) {
      if (a[i] <= next_d && (a[i] | next_d) == next_d) {
        tmp_v += b[i];
      }
    }

    max_v = max(tmp_v, max_v);
    if (next_d == k)
      break;

    next_d += 1;
  }

  cout << max_v << endl;
}


Fixed submission:
#include <iostream>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long

ll n, k;
ll a[100000], b[100000];

int main() {
  cin >> n >> k;
  REP(i, n) { cin >> a[i] >> b[i]; }

  ll max_v = 0;
  ll num = 0;
  ll max_d = 1;

  ll next_d = 0;
  ll plus = 1;
  while (1) {
    plus = 1;
    while (1) {
      if ((next_d | plus) <= k) {
        next_d = (next_d | plus);
        plus *= 2;
      } else {
        break;
      }
    }

    ll tmp_v = 0;
    REP(i, n) {
      if (a[i] <= next_d && (a[i] | next_d) == next_d) {
        tmp_v += b[i];
      }
    }

    max_v = max(tmp_v, max_v);
    if (next_d == k)
      break;

    next_d += 1;
  }

  cout << max_v << endl;
}
Problem p03584 (C++)

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

int main() {
  int64_t n, k;
  cin >> n >> k;
  int64_t a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  bool puni[32]{};
  for (int i = 0; i < 32; i++) {
    puni[i] = (k >> i) & 1;
  }
  int64_t ans = 0;
  for (int i = 0; i < 32; i++) {
    if (puni[i]) {
      bool muni[32];
      for (int j = 0; j < 32; j++) {
        if (i == j)
          muni[j] = false;
        if (i < j)
          muni[j] = puni[j];
        if (j < i)
          muni[j] = true;
      }
      int64_t score = 0;
      for (int j = 0; j < n; j++) {
        bool f = true;
        for (int k = 0; k < 32; k++) {
          if (!muni[k]) {
            f &= !((a[j] >> k) & 1);
          }
        }
        if (f)
          score += b[j];
      }
      ans = max(ans, score);
    }
  }
  {
    int64_t score = 0;
    for (int i = 0; i < n; i++) {
      bool f = true;
      for (int j = 0; j < n; j++) {
        if (!puni[j]) {
          f &= !((a[i] >> j) & 1);
        }
      }
      if (f)
        score += b[i];
    }
    ans = max(ans, score);
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int64_t n, k;
  cin >> n >> k;
  int64_t a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  bool puni[32]{};
  for (int i = 0; i < 32; i++) {
    puni[i] = (k >> i) & 1;
  }
  int64_t ans = 0;
  for (int i = 0; i < 32; i++) {
    if (puni[i]) {
      bool muni[32];
      for (int j = 0; j < 32; j++) {
        if (i == j)
          muni[j] = false;
        if (i < j)
          muni[j] = puni[j];
        if (j < i)
          muni[j] = true;
      }
      int64_t score = 0;
      for (int j = 0; j < n; j++) {
        bool f = true;
        for (int k = 0; k < 32; k++) {
          if (!muni[k]) {
            f &= !((a[j] >> k) & 1);
          }
        }
        if (f)
          score += b[j];
      }
      ans = max(ans, score);
    }
  }
  {
    int64_t score = 0;
    for (int i = 0; i < n; i++) {
      bool f = true;
      for (int j = 0; j < 32; j++) {
        if (!puni[j]) {
          f &= !((a[i] >> j) & 1);
        }
      }
      if (f)
        score += b[i];
    }
    ans = max(ans, score);
  }
  cout << ans << endl;
  return 0;
}