Language: C++

#ifdef LOCAL
#include "libs/debug/print_list.hpp"
#define debug(x) (cout << # x ": " << x << endl)
#define dev(v, m, n) for(int i=0;i<n;++i){for(int j=0;j<m;++j){cout<<"|"<<v[j][i];}cout<<"|"<<endl;}
#else
#define debug(x) ;
#define dev(v, m, n) ;
#endif

// :----------------------------------------

#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;
using pi = pair<int, int>;
using vp = vector<pi>;
using Graph = vector<vector<int>>;

template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}

#define P (1'000'000'007)

template<int MOD>
class Combination {
public:
    Combination(int n) {
        long long signed accumulation = 1;
        factorials.push_back(1);
        for (int i = 1; i <= n; ++ i) {
            accumulation *= i;
            accumulation %= MOD;
            factorials.push_back(accumulation);
        }

        int n_inv = fast_pow(factorials[n], MOD - 2, MOD);
        invs.push_back(n_inv);
        accumulation = n_inv;
        for (int i = n; i >= 2; --i) {
            accumulation *= i;
            accumulation %= MOD;
            invs.push_front(accumulation);
        }
        invs.push_front(1);
    }

    int comb(int n, int r) {
        if (r <= 0) return 1;
        long long signed res = 1ll * factorials[n] * invs[r] % MOD;
        return 1ll * res * invs[n - r] % MOD;
    }

    int perm(int n, int r) {
        long long signed res = 1ll * factorials[n] * invs[n - r] % MOD;
        return res;
    }

    std::deque<int> factorials;
    std::deque<int> invs;
};

template<int MOD=P>
struct Mod {
public:
    long long signed value;

    Mod(long long signed val): value(val % MOD) {
        if (value < 0) value += MOD;
    }

    constexpr Mod& operator+=(const Mod& other) noexcept { 
        value += other.value;
        value %= MOD;
        return *this;
    }
    constexpr Mod& operator-=(const Mod& other) noexcept {
        value -= other.value;
        if (value < 0) value += MOD;
        return *this;
    }
    constexpr Mod& operator*=(const Mod& other) noexcept {
        value *= other.value;
        value %= MOD;
        return *this;
    }

    constexpr Mod operator-() noexcept {
         return value == 0 ? 0 : MOD - value;
    }

    constexpr Mod operator+(const Mod& other) const noexcept { return Mod(*this) += other; }
    constexpr Mod operator-(const Mod& other) const noexcept { return Mod(*this) -= other; }
    constexpr Mod operator*(const Mod& other) const noexcept { return Mod(*this) *= other; }
    constexpr bool operator==(const Mod& other) const noexcept { return this->value == other.value; }
    constexpr bool operator!=(const Mod& other) const noexcept { return this->value != other.value; }
};

signed main() {
    int n;
    cin >> n;

    vi va;
    int sum = 0;

    rep(i, n) {
        capi(a);
        va.push_back(a);
        sum += a;
    }

    Mod ans(0);

    for (auto a: va) {
        Mod x(sum - a);
        x *= a;
        ans += x;
    }

    if (ans.value % 2 == 0) {
        cout << ans.value / 2;
    } else {
        cout << (ans.value + P) / 2;
    }
    
    return 0;
}


Compiler output:
a.cc: In constructor 'Combination<MOD>::Combination(long long int)':
a.cc:58:21: error: there are no arguments to 'fast_pow' that depend on a template parameter, so a declaration of 'fast_pow' must be available [-fpermissive]
   58 |         int n_inv = fast_pow(factorials[n], MOD - 2, MOD);
      |                     ^~~~~~~~
a.cc:58:21: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)