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

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

const int mx = 1e6 + 11;
const double PI = acos(-1);
#define MOD 1000000007

#define nl '\\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt                                                                     \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define be(a) (a).begin(), (a).end()
#define rbe(a) (a).rbegin(), (a).rend()
#define mem(a, b) memset(a, b, sizeof(a))
#define yes cout << "YES" << nl
#define no cout << "NO" << nl

#define su                                                                     \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define file                                                                   \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout);
#define frac                                                                   \\
  cout.unsetf(ios::floatfield);                                                \\
  cout.precision(10);                                                          \\
  cout.setf(ios::fixed, ios::floatfield);

template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin())
      os << ", ";
    os << *it;
  }
  return os << "}";
}

template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin())
      os << ", ";
    os << *it;
  }
  return os << "]";
}

template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin())
      os << ", ";
    os << *it;
  }
  return os << "]";
}

template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin())
      os << ", ";
    os << it->first << " = " << it->second;
  }
  return os << "]";
}

#define dbg(args...)                                                           \\
  do {                                                                         \\
    cerr << #args << " : ";                                                    \\
    faltu(args);                                                               \\
  } while (0)

void faltu() { cerr << endl; }

template <typename T> void faltu(T a[], int n) {
  for (int i = 0; i < n; ++i)
    cerr << a[i] << ' ';
  cerr << endl;
}

template <typename T, typename... hello>
void faltu(T arg, const hello &...rest) {
  cerr << arg << ' ';
  faltu(rest...);
}

ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }
ll add(ll a, ll b) { return ((a % MOD) + (b % MOD)) % MOD; }

void f() {
  ll n, sum = 0;
  cin >> n;
  ll a[n], par[n];
  cin >> a[0];
  par[0] = a[0];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    par[i] = add(a[i], par[i - 1]);
  }
  for (int i = 0; i < n - 1; i++) {
    sum += mul(a[i + 1], par[i]);
    sum %= MOD;
  }
  cout << sum << nl;
}

int main() {
  su;
  f();
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

const int mx = 1e6 + 11;
const double PI = acos(-1);
#define MOD 1000000007

#define nl '\\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt                                                                     \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define be(a) (a).begin(), (a).end()
#define rbe(a) (a).rbegin(), (a).rend()
#define mem(a, b) memset(a, b, sizeof(a))
#define yes cout << "YES" << nl
#define no cout << "NO" << nl

#define su                                                                     \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define file                                                                   \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout);
#define frac                                                                   \\
  cout.unsetf(ios::floatfield);                                                \\
  cout.precision(10);                                                          \\
  cout.setf(ios::fixed, ios::floatfield);

template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin())
      os << ", ";
    os << *it;
  }
  return os << "}";
}

template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin())
      os << ", ";
    os << *it;
  }
  return os << "]";
}

template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin())
      os << ", ";
    os << *it;
  }
  return os << "]";
}

template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin())
      os << ", ";
    os << it->first << " = " << it->second;
  }
  return os << "]";
}

#define dbg(args...)                                                           \\
  do {                                                                         \\
    cerr << #args << " : ";                                                    \\
    faltu(args);                                                               \\
  } while (0)

void faltu() { cerr << endl; }

template <typename T> void faltu(T a[], int n) {
  for (int i = 0; i < n; ++i)
    cerr << a[i] << ' ';
  cerr << endl;
}

template <typename T, typename... hello>
void faltu(T arg, const hello &...rest) {
  cerr << arg << ' ';
  faltu(rest...);
}

ll nor(ll a) { a %= MOD; }
ll mul(ll a, ll b) {
  nor(a);
  nor(b);
  return (a * b) % MOD;
}
ll add(ll a, ll b) {

  nor(a);
  nor(b);
  return (a + b) % MOD;
}

void f() {
  ll n, sum = 0;
  cin >> n;
  ll a[n], par[n];
  cin >> a[0];
  par[0] = a[0];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    par[i] = add(a[i], par[i - 1]);
  }
  for (int i = n - 1; i > 0; i--) {
    sum += mul(a[i], par[i - 1]);
    sum = nor(sum);
  }
  cout << sum << nl;
}

int main() {
  su;
  f();
  return 0;
}