Problem p02963 (C++)

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

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

const int MAXN = 1e6 + 1;
const int MOD = 998244353; // 1e9+7;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define debug(x)                                                               \
  do {                                                                         \
    cerr << #x << ": " << x << "\n";                                           \
  } while (0)
#define debugv(x)                                                              \
  do {                                                                         \
    cerr << #x << ": ";                                                        \
    for (auto &e : (x))                                                        \
      cerr << e << " ";                                                        \
    cerr << "\n";                                                              \
  } while (0)
#define FAIL0                                                                  \
  {                                                                            \
    cout << "0\n";                                                             \
    return 0;                                                                  \
  }
#define FAIL1                                                                  \
  {                                                                            \
    cout << "-1\n";                                                            \
    return 0;                                                                  \
  }
#define FAILNO                                                                 \
  {                                                                            \
    cout << "No\n";                                                            \
    return 0;                                                                  \
  }
#define YES                                                                    \
  {                                                                            \
    cout << "Yes\n";                                                           \
    return 0;                                                                  \
  }

int main() {
#ifdef OJ
  freopen("input.txt", "rt", stdin);
  // freopen("output.txt", "wt", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);

  LL S;
  cin >> S;

  LL ax = 0, ay = 0, bx, by, cx, cy;
  LL a = sqrt(S);
  LL r = S - a * a;
  if (r <= 1e9) {
    ay = 1;
    bx = a;
    by = 0;
    cx = r;
    cy = a + 1;
  } else {
    a++;
    r = a * a - S;
    assert(r <= 1e9);
    bx = a;
    by = 1;
    cx = r;
    cy = a;
  }

  assert(max({ax, ay, bx, by, cx, cy}) <= 1e9);

  cout << ax << ' ' << ay << ' ';
  cout << bx << ' ' << by << ' ';
  cout << cx << ' ' << cy << '\n';

  return 0;
}


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

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

const int MAXN = 1e6 + 1;
const int MOD = 998244353; // 1e9+7;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define debug(x)                                                               \
  do {                                                                         \
    cerr << #x << ": " << x << "\n";                                           \
  } while (0)
#define debugv(x)                                                              \
  do {                                                                         \
    cerr << #x << ": ";                                                        \
    for (auto &e : (x))                                                        \
      cerr << e << " ";                                                        \
    cerr << "\n";                                                              \
  } while (0)
#define FAIL0                                                                  \
  {                                                                            \
    cout << "0\n";                                                             \
    return 0;                                                                  \
  }
#define FAIL1                                                                  \
  {                                                                            \
    cout << "-1\n";                                                            \
    return 0;                                                                  \
  }
#define FAILNO                                                                 \
  {                                                                            \
    cout << "No\n";                                                            \
    return 0;                                                                  \
  }
#define YES                                                                    \
  {                                                                            \
    cout << "Yes\n";                                                           \
    return 0;                                                                  \
  }

int main() {
#ifdef OJ
  freopen("input.txt", "rt", stdin);
  // freopen("output.txt", "wt", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);

  LL S;
  cin >> S;

  LL ax = 0, ay = 0, bx, by, cx, cy;
  LL a = sqrt(S);
  LL r = S - a * a;
  if (r == 0) {
    bx = a;
    by = 0;
    cx = 0;
    cy = a;
  } else if (r <= 1e9) {
    ay = 1;
    bx = a;
    by = 0;
    cx = r;
    cy = a + 1;
  } else {
    a++;
    r = a * a - S;
    assert(r <= 1e9);
    bx = a;
    by = 1;
    cx = r;
    cy = a;
  }

  assert(max({ax, ay, bx, by, cx, cy}) <= 1e9);

  cout << ax << ' ' << ay << ' ';
  cout << bx << ' ' << by << ' ';
  cout << cx << ' ' << cy << '\n';

  return 0;
}