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

#include <bits/stdc++.h>
#define Tp template <typename Ty>
#define Ts template <typename Ty, typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int &
#define I inline
#define W while
#define N 200000
#define X 200003
#define PR 5
#define LL long long
using namespace std;
int n, a[N + 5], s[X + 5], Lg[X + 5];
LL p[X + 5];
class FastIO {
private:
#define FS 100000
#define tc()                                                                   \\
  (A == B && (B = (A = FI) + fread(FI, 1, FS, stdin), A == B) ? EOF : *A++)
#define D isdigit(c = tc())
  char c, *A, *B, FI[FS];

public:
  I FastIO() { A = B = FI; }
  Tp I void read(Ty &x) {
    x = 0;
    W(!D);
    W(x = (x << 3) + (x << 1) + (c & 15), D);
  }
} F;
namespace Poly {
#define DB double
#define Pi acos(-1)
struct node {
  DB x, y;
  I node(Con DB &a = 0, Con DB &b = 0) : x(a), y(b) {}
  I node operator+(Con node &o) Con { return node(x + o.x, y + o.y); }
  I node operator-(Con node &o) Con { return node(x - o.x, y - o.y); }
  I node operator*(Con node &o) Con {
    return node(x * o.x - y * o.y, x * o.y + y * o.x);
  }
} A[4 * X + 5];
int P, L, R[4 * X + 5];
I void FFT(node *s, CI op) {
  RI i, j, k;
  node x, y, U, S;
  for (i = 0; i ^ P; ++i)
    i < R[i] && (x = s[i], s[i] = s[R[i]], s[R[i]] = x, 0);
  for (i = 1; i ^ P; i <<= 1)
    for (U = node(cos(Pi / i), op * sin(Pi / i)), j = 0; j ^ P; j += i << 1)
      for (S = 1, k = 0; k ^ i; ++k, S = S * U)
        s[j + k] = (x = s[j + k]) + (y = S * s[i + j + k]),
              s[i + j + k] = x - y;
}
I void Sqr(int *a, long long *res) {
  RI i;
  for (i = 0; i <= X - 2; ++i)
    A[i] = a[i];
  P = 1, L = 0;
  W(P <= 2 * (X - 2)) P <<= 1, ++L;
  for (i = 0; i ^ P; ++i)
    R[i] = (R[i >> 1] >> 1) | ((i & 1) << L - 1);
  for (FFT(A, 1), i = 0; i ^ P; ++i)
    A[i] = A[i] * A[i];
  for (FFT(A, -1), i = 0; i <= 2 * (X - 2); ++i)
    res[i % (X - 1)] += A[i].x / P + 0.1;
}
} // namespace Poly
I void Init() {
  RI i, x = 1;
  for (i = 0; i < X - 1; ++i)
    Lg[x] = i, x = 1LL * x * PR % X;
}
int main() {
  RI i;
  for (Init(), F.read(n), i = 1; i <= n; ++i)
    F.read(a[i]), a[i] && ++s[Lg[a[i]]];
  for (Poly::Sqr(s, p), i = 0; i < X - 1; ++i)
    p[(i << 1) % (X - 1)] -= s[i];
  LL ans = 0;
  for (i = 1; i ^ X; ++i)
    ans += 1LL * i * p[Lg[i]];
  return printf("%lld\\n", ans >> 1), 0;
}

Error: 7

Fixed submission:

#include <bits/stdc++.h>
#define Tp template <typename Ty>
#define Ts template <typename Ty, typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int &
#define I inline
#define W while
#define N 200000
#define X 200003
#define PR 5
#define LL long long
using namespace std;
int n, a[N + 5], s[N + 5], Lg[N + 5];
LL p[N + 5];
class FastIO {
private:
#define FS 100000
#define tc()                                                                   \\
  (A == B && (B = (A = FI) + fread(FI, 1, FS, stdin), A == B) ? EOF : *A++)
#define D isdigit(c = tc())
  char c, *A, *B, FI[FS];

public:
  I FastIO() { A = B = FI; }
  Tp I void read(Ty &x) {
    x = 0;
    W(!D);
    W(x = (x << 3) + (x << 1) + (c & 15), D);
  }
} F;
namespace Poly {
#define DB double
#define Pi acos(-1)
struct node {
  DB x, y;
  I node(Con DB &a = 0, Con DB &b = 0) : x(a), y(b) {}
  I node operator+(Con node &o) Con { return node(x + o.x, y + o.y); }
  I node operator-(Con node &o) Con { return node(x - o.x, y - o.y); }
  I node operator*(Con node &o) Con {
    return node(x * o.x - y * o.y, x * o.y + y * o.x);
  }
} A[4 * N + 5];
int P, L, R[4 * N + 5];
I void FFT(node *s, CI op) {
  RI i, j, k;
  node x, y, U, S;
  for (i = 0; i ^ P; ++i)
    i < R[i] && (x = s[i], s[i] = s[R[i]], s[R[i]] = x, 0);
  for (i = 1; i ^ P; i <<= 1)
    for (U = node(cos(Pi / i), op * sin(Pi / i)), j = 0; j ^ P; j += i << 1)
      for (S = 1, k = 0; k ^ i; ++k, S = S * U)
        s[j + k] = (x = s[j + k]) + (y = S * s[i + j + k]),
              s[i + j + k] = x - y;
}
I void Sqr(int *a, long long *res) {
  RI i;
  for (i = 0; i <= X - 2; ++i)
    A[i] = a[i];
  P = 1, L = 0;
  W(P <= 2 * (X - 2)) P <<= 1, ++L;
  for (i = 0; i ^ P; ++i)
    R[i] = (R[i >> 1] >> 1) | ((i & 1) << L - 1);
  for (FFT(A, 1), i = 0; i ^ P; ++i)
    A[i] = A[i] * A[i];
  for (FFT(A, -1), i = 0; i <= 2 * (X - 2); ++i)
    res[i % (X - 1)] += A[i].x / P + 0.1;
}
} // namespace Poly
I void Init() {
  RI i, x = 1;
  for (i = 0; i < X - 1; ++i)
    Lg[x] = i, x = 1LL * x * PR % X;
}
int main() {
  RI i;
  for (Init(), F.read(n), i = 1; i <= n; ++i)
    F.read(a[i]), a[i] && ++s[Lg[a[i]]];
  for (Poly::Sqr(s, p), i = 0; i < X - 1; ++i)
    p[(i << 1) % (X - 1)] -= s[i];
  LL ans = 0;
  for (i = 1; i ^ X; ++i)
    ans += 1LL * i * p[Lg[i]];
  return printf("%lld\\n", ans >> 1);
}