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

#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \\
  {                                                                            \\
    ios_base::sync_with_stdio(false);                                          \\
    cin.tie(0);                                                                \\
    cout.tie(0);                                                               \\
  }
typedef long long int ll;
typedef string S;
#define M 1e18
#define AS 1000005
#define in(x) cin >> x
#define in4(w, x, y, z) cin >> w >> x >> y >> z
#define in3(x, y, z) cin >> x >> y >> z
#define o(x) cout << x
#define o2(x, y) cout << x << ' ' << y;
#define o3(x, y, z) cout << x << ' ' << y << ' ' << z
#define o4(w, x, y, z) cout << w << ' ' << x << ' ' << y << ' ' << z
#define sp cout << ' '
#define nw cout << endl
#define rt return
#define fr(i, a, n) for (ll i = a; i <= n; i++)
#define frm(i, a, n) for (ll i = n; i >= a; i--)
#define P pair<ll, ll>
#define vc vector<ll>
#define pb push_back
#define MP map<ll, ll>
bool sortin(const pair<ll, ll> &e, const pair<ll, ll> &f) {
  return (e.first < f.first);
}
bool POT(ll x) { return x && (!(x & (x - 1))); }
ll i, j, k, l, m, n, p, q, r, a, b, c, x, y, z, ts, mn = 1e18, mod = 1e9 + 7;
ll ar[AS], br[AS], xr[AS], tem[AS];
void sieve() {
  fr(i, 2, AS - 5) {
    if (xr[i] == 0) {
      for (j = i; j <= AS - 5; j += i) {
        if (xr[j] == 0)
          xr[j] = i;
      }
    }
  }
}
int main() {
  fast;
  in(n);
  fr(i, 1, n) in(ar[i]), c = __gcd(c, ar[i]);
  if (c > 1) {
    o("not coprime");
    rt 0;
  }
  sieve();
  fr(i, 1, n) {
    while (ar[i] > 1) {
      br[ar[i]]++;
      if (br[ar[i]] > 1) {
        o("setwise coprime");
        rt 0;
      }
      ar[i] /= xr[ar[i]];
    }
  }
  o("pairwise coprime");
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \\
  {                                                                            \\
    ios_base::sync_with_stdio(false);                                          \\
    cin.tie(0);                                                                \\
    cout.tie(0);                                                               \\
  }
typedef long long int ll;
typedef string S;
#define M 1e18
#define AS 250005
#define in(x) cin >> x
#define in4(w, x, y, z) cin >> w >> x >> y >> z
#define in3(x, y, z) cin >> x >> y >> z
#define o(x) cout << x
#define o2(x, y) cout << x << ' ' << y;
#define o3(x, y, z) cout << x << ' ' << y << ' ' << z
#define o4(w, x, y, z) cout << w << ' ' << x << ' ' << y << ' ' << z
#define sp cout << ' '
#define nw cout << endl
#define rt return
#define fr(i, a, n) for (ll i = a; i <= n; i++)
#define frm(i, a, n) for (ll i = n; i >= a; i--)
#define P pair<ll, ll>
#define vc vector<ll>
#define pb push_back
#define MP map<ll, ll>
bool sortin(const pair<ll, ll> &e, const pair<ll, ll> &f) {
  return (e.first < f.first);
}
bool POT(ll x) { return x && (!(x & (x - 1))); }
ll i, j, k, l, m, n, p, q, r, a, b, c, x, y, z, ts, mn = 1e18, mod = 1e9 + 7;
ll ar[AS], br[AS], xr[AS], tem[AS];
int main() {
  fast;
  in(n);
  fr(i, 1, n) in(ar[i]);
  frm(i, 1, n) xr[i] = __gcd(xr[i + 1], ar[i]);
  fr(i, 1, n - 1) {
    if (xr[i] != 1) {
      if (xr[1] == 1)
        o("setwise coprime");
      else
        o("not coprime");
      rt 0;
    }
  }
  o("pairwise coprime");
}