Language: C++

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

template <uint_fast64_t Modulus> 
struct ModInt {
    using u64 = uint_fast64_t;

    u64 a;

    constexpr ModInt(const long long x = 0) noexcept : a(x >= 0 ? x % Modulus : (Modulus - (-x) % Modulus) % Modulus) {}
    constexpr u64 &value() noexcept {return a;}
    constexpr const u64 &value() const noexcept {return a;}
    constexpr ModInt operator+(const ModInt rhs) const noexcept {return ModInt(*this) += rhs;}
    constexpr ModInt operator-(const ModInt rhs) const noexcept {return ModInt(*this) -= rhs;}
    constexpr ModInt operator*(const ModInt rhs) const noexcept {return ModInt(*this) *= rhs;}
    constexpr ModInt operator/(const ModInt rhs) const noexcept {return ModInt(*this) /= rhs;}
    constexpr ModInt operator^(const long long rhs) const noexcept {return ModInt(*this) ^= rhs;}
    constexpr bool operator==(const ModInt &rhs) const noexcept {return a == rhs.a;}
    constexpr bool operator!=(const ModInt &rhs) const noexcept {return a != rhs.a;}
    constexpr ModInt &operator+=(const ModInt rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr ModInt &operator/=(ModInt rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp&1) *this *= rhs;
            exp >>= 1;
            rhs *= rhs;
        }
        return *this;
    }
    constexpr ModInt &operator^=(long long exp) noexcept {
        ModInt rhs = a;
        a = 1;
        while (exp) {
            if (exp&1) *this *= rhs;
            exp >>= 1;
            rhs *= rhs;
        }
        return *this;
    }

    friend ostream &operator<<(ostream& os, const ModInt& rhs) noexcept {return os << rhs.a;}
    friend istream &operator>>(istream& is, ModInt& rhs) noexcept {long long a; is >> a; rhs = a; return is;}
};

using mint = ModInt<MOD>;

mint lagrange_interpolation_arithmetic(const vector<mint> &y, mint T, mint a = 0, mint d = 1) {
    int N = y.size() - 1;
    if (a.a == 0 and d.a == 1 and T.a <= N) return y[T.a];

    vector<mint> dp(N+1,1), pd(N+1,1);
    for (int i = 0; i < N; i++) dp[i+1] = dp[i]*(T-(a+d*i));
    for (int i = N; i > 0; i--) pd[i-1] = pd[i]*(T-(a+d*i));

    vector<mint> fact(N+1,1),finv(N+1,1);
    for (int i = 1; i <= N; i++) fact[i] = fact[i-1]*d*i;
    finv[N] /= fact[N];
    for (int i = N; i >= 1; i--) finv[i-1] = finv[i]*d*i;

    mint ret = 0;
    for (int i = 0; i <= N; i++) {
        mint tmp = y[i]*dp[i]*pd[i]*finv[i]*finv[N-i];
        if ((N-i)&1) ret -= tmp;
        else ret += tmp;
    }

    return ret;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int Q; cin >> Q;
    vector<mint> x(7);
    for (int i = 5; i <= 10; i++) {
        vector<int> A(10);
        auto dfs=[&](auto &&self,int v, int S)->void {
            if (v==10) {
                mint val = 1;
                rep(j,5) {
                    val *= A[j*2+1] - A[j*2];
                }
                x[i-5] += val;
                return;
            }
            if (v%2==0) {
                rep(i,S) {
                    A[v] = i;
                    self(self,v+1,S-i);
                }
            } else {
                for (int i = A[v]+1; i <= S; i++) {
                    A[v] = i;
                    self(self,v+1,S-i);
                }
            }
        };

        dfs(dfs,0,i);
    }

    while (Q--) {
        int N; cin >> N;
        if (N < 5) {
            cout << 0 << ln;
            return;
        }
        cout << lagrange_interpolation_arithmetic(x,N,5) << ln;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:146:13: error: return-statement with no value, in function returning 'int' [-fpermissive]
  146 |             return;
      |             ^~~~~~