Problem p02690 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h>
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono>
#include <thread> #include <iomanip>
*/
using namespace std;

#define endl "\\n"
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define re(i, a) for (int i = 0; i < a; ++i)
#define tr(i, v) for (auto &i : v)
#define mem(a, val) memset(a, val, sizeof(a))
#define all(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define in(v, n)                                                               \\
  vi v(n);                                                                     \\
  re(i, n) cin >> v[i]
#define printVec(v, s)                                                         \\
  cout << s;                                                                   \\
  tr(i, v) cout << i << " ";
#define sz(a) int((a).size())
#define dbgv(c, v) cout << c << " = " << v << endl;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef complex<double> point;

const long long MOD = 1000000007;
const long long inf = 1e18;

void solve() {}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int x;
  cin >> x;

  re(b, 1000) {
    rep(a, b + 1, 1000) {
      if (a - b > x)
        break;
      if (x % (a - b) == 0) {
        ll pa = a * a;
        pa *= pa;
        pa *= a;
        ll pb = b * b;
        pb *= pb;
        pb *= b;
        if (pa - pb == x) {
          cout << a << " " << b;
          return 0;
        }
      }
      b = -b;
      if (x % (a - b) == 0) {
        ll pa = a * a;
        pa *= pa;
        pa *= a;
        ll pb = b * b;
        pb *= pb;
        pb *= b;
        if (pa - pb == x) {
          cout << a << " " << b;
          return 0;
        }
      }
      b = -b;
    }
  }
  cout << "-1";
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\\n";
  return 0;
}


Error: -6
terminate called after throwing an instance of 'std::__ios_failure'
  what():  basic_ios::clear: iostream error


Fixed submission:

#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h>
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono>
#include <thread> #include <iomanip>
*/
using namespace std;

#define endl "\\n"
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define re(i, a) for (int i = 0; i < a; ++i)
#define tr(i, v) for (auto &i : v)
#define mem(a, val) memset(a, val, sizeof(a))
#define all(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define in(v, n)                                                               \\
  vi v(n);                                                                     \\
  re(i, n) cin >> v[i]
#define printVec(v, s)                                                         \\
  cout << s;                                                                   \\
  tr(i, v) cout << i << " ";
#define sz(a) int((a).size())
#define dbgv(c, v) cout << c << " = " << v << endl;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef complex<double> point;

const long long MOD = 1000000007;
const long long inf = 1e18;

void solve() {}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  ll x;
  cin >> x;

  re(b, 1000) {
    rep(a, b + 1, 1000) {
      if (a - b > x)
        break;
      if (x % (a - b) == 0) {
        ll pa = a * a;
        pa *= pa;
        pa *= a;
        ll pb = b * b;
        pb *= pb;
        pb *= b;
        if (pa - pb == x) {
          cout << a << " " << b;
          return 0;
        }
      }
      b = -b;
      if (x % (a - b) == 0) {
        ll pa = a * a;
        pa *= pa;
        pa *= a;
        ll pb = b * b;
        pb *= pb;
        pb *= b;
        if (pa - pb == x) {
          cout << a << " " << b;
          return 0;
        }
      }
    }
  }
  cout << "-1";
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\\n";
  return 0;
}