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

/*
 *  Created on: 31 / 5 / 2020
 *  Author:     Eslam Waheed
 */
#include <bits/stdc++.h>
// #include <bits/BIGINT.h>
// #include <bits/Int128.h>
using namespace std;

// #define _CRT_SECURE_NO_WARNINGS
// #define __USE_MINGW_ANSI_STDIO
#define Eslam__Waheed                                                          \\
  ios_base::sync_with_stdio(false);                                            \\
  cout.tie(NULL);                                                              \\
  cin.tie(NULL);

#define ll long long
#define ull unsigned ll
#define dd double
#define ld long dd
#define ss string

#define pb push_back
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n) cout << fixed << setprecision(n);
#define iq(v) v.resize(unique(v.begin(), v.end()) - v.begin())
#define sz(s) (ll)(s.size())
#define endl '\\n'

#define loop(i, m, n) for (ll i = m; i < n; i++)
#define test(t) while (t--)

// ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
// ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

// const ld PI = acos(-1);
// const ll mod = 1e15 + 7;
//__int128
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
ss Big_mul(string a, string b) {
  reverse(all(a));
  reverse(all(b));
  vector<ll> v(600, 0);
  loop(i, 0, sz(a)) {
    loop(u, 0, sz(b)) { v[i + u] += ((a[i] - '0') * (b[u] - '0')); }
  }
  for (int i = 0; i < 599; i++) {
    v[i + 1] += v[i] / 10;
    v[i] %= 10;
  }
  int i = 599;
  while (i > 0 && v[i] == 0) {
    i--;
  }
  ss ans = "";
  for (; i >= 0; i--) {
    ans += to_string(v[i]);
  }
  return ans;
}
int main() {
  // stp(0)
  Eslam__Waheed ll n;
  cin >> n;
  vector<ss> v(n);
  for (auto &it : v) {
    cin >> it;
  }
  sort(all(v));
  ss ans = "1";
  for (auto it : v) {
    ans = Big_mul(ans, it);
    if (sz(ans) > 19) {
      cout << -1;
      return 0;
    }
  }
  // cout << ans;

  ll x = stoll(ans);
  if (x > 1000000000000000000) {
    cout << -1;
    return 0;
  }
  cout << x;
}


Error: WA

Fixed submission:

/*
 *  Created on: 31 / 5 / 2020
 *  Author:     Eslam Waheed
 */
#include <bits/stdc++.h>
// #include <bits/BIGINT.h>
// #include <bits/Int128.h>
using namespace std;

// #define _CRT_SECURE_NO_WARNINGS
// #define __USE_MINGW_ANSI_STDIO
#define Eslam__Waheed                                                          \\
  ios_base::sync_with_stdio(false);                                            \\
  cout.tie(NULL);                                                              \\
  cin.tie(NULL);

#define ll long long
#define ull unsigned ll
#define dd double
#define ld long dd
#define ss string

#define pb push_back
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n) cout << fixed << setprecision(n);
#define iq(v) v.resize(unique(v.begin(), v.end()) - v.begin())
#define sz(s) (ll)(s.size())
#define endl '\\n'

#define loop(i, m, n) for (ll i = m; i < n; i++)
#define test(t) while (t--)

// ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
// ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

// const ld PI = acos(-1);
// const ll mod = 1e15 + 7;
//__int128
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
ss Big_mul(string a, string b) {
  reverse(all(a));
  reverse(all(b));
  vector<ll> v(600, 0);
  loop(i, 0, sz(a)) {
    loop(u, 0, sz(b)) { v[i + u] += ((a[i] - '0') * (b[u] - '0')); }
  }
  for (int i = 0; i < 599; i++) {
    v[i + 1] += v[i] / 10;
    v[i] %= 10;
  }
  int i = 599;
  while (i > 0 && v[i] == 0) {
    i--;
  }
  ss ans = "";
  for (; i >= 0; i--) {
    ans += to_string(v[i]);
  }
  return ans;
}
int main() {
  // stp(0)
  Eslam__Waheed ll n;
  cin >> n;
  vector<ss> v(n);
  for (auto &it : v) {
    cin >> it;
  }
  sort(all(v));
  ss ans = "1";
  for (auto it : v) {
    ans = Big_mul(ans, it);
  }
  // cout << ans;
  if (sz(ans) > 19) {
    cout << -1;
    return 0;
  }
  ll x = stoll(ans);
  if (x > 1000000000000000000) {
    cout << -1;
    return 0;
  }
  cout << x;
}