Language: C++

#include<iostream>

namespace MMNMM {
    template<class SemiGroup, class size_type>
    constexpr SemiGroup pow(const SemiGroup &a, size_type n, const SemiGroup &b = SemiGroup::e()) {
        SemiGroup ret = b, p = a;
        while (n) {
            if (n & 1) ret *= p;
            p *= p;
            n >>= 1;
        }
        return ret;
    }

    template<class UnsignedInteger = unsigned long, UnsignedInteger Mod = 1000000007>
    class modint_normal {
        // A class for elements of Z/pZ.
        // This class supports numeric operation(+-/* etc.) and unsafe addition(|=).
        //
        // Member Variable : val
        // val will satisfy 0 <= val < Mod any time of point.
        static_assert(Mod < ~(~static_cast<UnsignedInteger>(0) << 32), "mod is too big");

        using value_type = UnsignedInteger;
        using const_value = const value_type;
        using reference_type = value_type &;
        using const_reference = const value_type &;
        using size_type = size_t;

        value_type val;
        static constexpr value_type upperbound = Mod;

    public:

        static constexpr modint_normal e() {
            return modint_normal(1);
        }

        constexpr modint_normal(const_reference _v = 0) noexcept : val(_v) {}

        constexpr modint_normal(const modint_normal &_v) noexcept : val(_v.get_value()) {}

        constexpr modint_normal(modint_normal &&_v) noexcept : val(_v.get_value()) { _v.set_value(0); }

        static constexpr const_reference get_mod() noexcept { return Mod; }

        constexpr const_reference get_value() const noexcept {
            return val;
        }

        void set_value(const_reference v) noexcept {
            val = v;
        }

        constexpr modint_normal operator++(int) noexcept {
            auto t = *this;
            ++val;
            val -= (val == upperbound) * upperbound;
            return t;
        }

        constexpr modint_normal operator--(int) noexcept {
            auto t = *this;
            val += (val == 0) * upperbound;
            --val;
            return t;
        }

        constexpr modint_normal &operator++() noexcept {
            ++val;
            val -= (val == upperbound) * upperbound;
            return *this;
        }

        constexpr modint_normal &operator--() noexcept {
            val += (val == 0) * upperbound;
            --val;
            return *this;
        }

        constexpr modint_normal operator+() const noexcept {
            return *this;
        }

        constexpr modint_normal operator-() const noexcept {
            auto t = *this;
            t.set_value(upperbound - this->val);
        }

        explicit operator value_type() const noexcept {
            return this->val;
        }

        constexpr modint_normal &operator=(const modint_normal &rhs) & noexcept {
            this->val = rhs.get_value;
            return *this;
        }

        constexpr modint_normal &operator=(modint_normal &&rhs) & noexcept {
            this->val = rhs.get_value();
            rhs.set_value(0);
            return *this;
        }

        constexpr modint_normal &operator+=(const modint_normal &rhs) noexcept {
            this->val += rhs.get_value();
            this->val -= (this->val >= upperbound) * upperbound;
            return *this;
        }

        constexpr modint_normal &operator-=(const modint_normal &rhs) noexcept {
            this->val += upperbound - rhs.get_value();
            this->val -= (this->val >= upperbound) * upperbound;
            return *this;
        }

        constexpr modint_normal &operator*=(const modint_normal &rhs) noexcept {
            this->val *= rhs.get_value();
            this->val %= upperbound;
            return *this;
        }

        constexpr modint_normal &operator/=(const modint_normal &rhs) noexcept {
            *this *= pow(rhs, Mod - 2);
            return *this;
        }

        constexpr modint_normal &operator|=(const modint_normal &rhs) noexcept {
            this->val += rhs.get_value();
            return *this;
        }

        constexpr void regularize() noexcept {
            this->val %= upperbound;
        }

        constexpr modint_normal operator+(const modint_normal &rhs) noexcept {
            auto t = *this;
            t += rhs;
            return t;
        }

        constexpr modint_normal operator-(const modint_normal &rhs) noexcept {
            auto t = *this;
            t -= rhs;
            return t;
        }

        constexpr modint_normal operator*(const modint_normal &rhs) noexcept {
            auto t = *this;
            t *= rhs;
            return t;
        }

        constexpr modint_normal operator/(const modint_normal &rhs) noexcept {
            auto t = *this;
            t /= rhs;
            return t;
        }
    };

    template<class UnsignedInteger, UnsignedInteger Mod>
    std::ostream& operator<<(std::ostream& os, const modint_normal<UnsignedInteger, Mod>& mint){
        os << mint.get_value();
        return os;
    }
    template<class UnsignedInteger, UnsignedInteger Mod>
    std::istream& operator>>(std::istream& is, modint_normal<UnsignedInteger, Mod>& mint){
        UnsignedInteger t;
        is >> t;
        mint = modint_normal<UnsignedInteger, Mod>(t);
        return is;
    }

    template<class UnsignedInteger = unsigned long, UnsignedInteger Mod = 1000000007>
    class modint {
        static_assert(Mod & 1, "mod mast be odd");

        using value_type = UnsignedInteger;
        using const_value = const value_type;
        using reference_type = value_type &;
        using const_reference = const_value &;

        static constexpr size_t bit_length = 32;
        static_assert(Mod < static_cast<UnsignedInteger>(1) << bit_length - 2, "mod is too big");
        static constexpr value_type mask = ~(~static_cast<UnsignedInteger>(0) << bit_length);

        static constexpr value_type f(value_type n) {
            value_type ret = 1;
            for (auto _ = 0; _ < 5; ++_)ret = ret * (2 - ret * n);
            return -ret & mask;
        }

        static constexpr const_value minv{f(Mod)};
        static constexpr const_value r2{-Mod % Mod};
        static constexpr const_value r{(1 << bit_length) % Mod};

        static constexpr value_type reduce(const_value v) {
            return (v + Mod * ((v * minv) & mask)) >> bit_length;
        }

        value_type val;
        static constexpr value_type upperbound = 2 * Mod;

    public:

        static constexpr modint e() {
            return modint(1);
        }

        static constexpr value_type get_minv() noexcept { return minv; }

        static constexpr value_type get_r2() noexcept { return r2; }

        static constexpr value_type get_mod() noexcept { return Mod; }

        constexpr value_type get_value() const noexcept { return val == Mod ? 0 : reduce(val); }

        constexpr value_type get_raw() const noexcept { return val; }

        constexpr modint() : val(0) {}

        template<class T>
        constexpr modint(const T &_v = 0) : val(reduce(_v * r2)) {}

        template<class UnsignedInteger2, UnsignedInteger2 Mod2>
        constexpr modint(const modint<UnsignedInteger2, Mod2> &_v) : val(reduce(_v.get_value() * r2)) {}

        template<class UnsignedInteger2>
        constexpr modint(const modint<UnsignedInteger2, Mod> &_v) : val(_v.get_raw()) {}

        constexpr modint(const modint &_v) = default;

        constexpr modint operator++(int) noexcept {
            auto t = *this;
            val += r;
            val -= (val >= upperbound) * upperbound;
            return t;
        }

        constexpr modint operator--(int) noexcept {
            auto t = *this;
            val += (val < r) * upperbound;
            val -= r;
            return t;
        }

        constexpr modint &operator++() noexcept {
            val += r;
            val -= (val >= upperbound) * upperbound;
            return *this;
        }

        constexpr modint &operator--() noexcept {
            val += (val < r) * upperbound;
            val -= r;
            return *this;
        }

        constexpr modint operator+() const noexcept {
            return *this;
        }

        constexpr modint operator-() const noexcept {
            auto t = *this;
            t.set_value(upperbound - this->val);
            return t;
        }

        explicit operator value_type() const noexcept {
            return this->val;
        }

        constexpr modint &operator=(const modint &rhs) & noexcept {
            this->val = rhs.get_raw();
            return *this;
        }

        constexpr modint &operator+=(const modint &rhs) noexcept {
            this->val += rhs.get_raw();
            this->val -= (this->val >= upperbound) * upperbound;
            return *this;
        }

        constexpr modint &operator-=(const modint &rhs) noexcept {
            this->val += upperbound - rhs.get_raw();
            this->val -= (this->val >= upperbound) * upperbound;
            return *this;
        }

        constexpr modint &operator*=(const modint &rhs) noexcept {
            this->val *= rhs.get_raw();
            this->val = reduce(this->val);
            return *this;
        }

        constexpr modint &operator/=(const modint &rhs) noexcept {
            *this = pow(rhs, Mod - 2, *this);
            return *this;
        }

        constexpr modint &operator|=(const modint &rhs) noexcept {
            this->val += rhs.get_raw();
            return *this;
        }

        constexpr void regularize() noexcept {
            this->val %= upperbound;
        }

        constexpr modint operator+(const modint &rhs) noexcept {
            auto t = *this;
            t += rhs;
            return t;
        }

        constexpr modint operator-(const modint &rhs) noexcept {
            auto t = *this;
            t -= rhs;
            return t;
        }

        constexpr modint operator*(const modint &rhs) noexcept {
            auto t = *this;
            t *= rhs;
            return t;
        }

        constexpr modint operator/(const modint &rhs) noexcept {
            auto t = *this;
            t /= rhs;
            return t;
        }
    };

    template<class UnsignedInteger, UnsignedInteger Mod>
    std::ostream& operator<<(std::ostream& os, const modint<UnsignedInteger, Mod>& mint){
        os << mint.get_value();
        return os;
    }
    template<class UnsignedInteger, UnsignedInteger Mod>
    std::istream& operator>>(std::istream& is, modint<UnsignedInteger, Mod>& mint){
        UnsignedInteger t;
        is >> t;
        mint = modint<UnsignedInteger, Mod>(t);
        return is;
    }
}

#include <bits/stdc++.h>

int main() {
    using namespace std;
    constexpr unsigned long MOD = 1000000007;
    using modint = MMNMM::modint_normal<unsigned long, MOD>;
    unsigned long N;
    cin >> N;
    vector<modint> weight(N);
    {
        vector<modint> hoge(N), fuga(N, 1), piyo(N, 1);
        iota(hoge.begin(), hoge.end(), 1UL);
        partial_sum(hoge.rbegin(), hoge.rend() - 1, fuga.rbegin() + 1, [](auto a, auto b){return a * b;});
        partial_sum(hoge.begin(), hoge.end() - 1, piyo.begin() + 1, [](auto a, auto b){return a * b;});
        for(unsigned long i = 0; i < N; ++i)weight[i] = fuga[i] * piyo[i];
    }
    vector<modint> A(N);
    for(auto& i : A)cin >> i;
    partial_sum(weight.begin(), weight.end(), weight.begin());
    modint ans{0};
    for(unsigned long i = 0; i < N; ++i)ans += A[i] * (weight[i] + weight[N - i - 1] - weight[0]);
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc:196:43: warning: left shift count >= width of type [-Wshift-count-overflow]
  196 |         static constexpr const_value r{(1 << bit_length) % Mod};
      |                                         ~~^~~~~~~~~~~~~
a.cc: In instantiation of 'constexpr MMNMM::modint_normal<UnsignedInteger, Mod>& MMNMM::modint_normal<UnsignedInteger, Mod>::operator=(const MMNMM::modint_normal<UnsignedInteger, Mod>&) & [with UnsignedInteger = long unsigned int; UnsignedInteger Mod = 1000000007]':
/usr/include/c++/14/bits/stl_numeric.h:312:17:   required from '_OutputIterator std::partial_sum(_InputIterator, _InputIterator, _OutputIterator, _BinaryOperation) [with _InputIterator = reverse_iterator<__gnu_cxx::__normal_iterator<MMNMM::modint_normal<long unsigned int, 1000000007>*, vector<MMNMM::modint_normal<long unsigned int, 1000000007> > > >; _OutputIterator = reverse_iterator<__gnu_cxx::__normal_iterator<MMNMM::modint_normal<long unsigned int, 1000000007>*, vector<MMNMM::modint_normal<long unsigned int, 1000000007> > > >; _BinaryOperation = main()::<lambda(auto:28, auto:29)>]'
  312 |       *__result = __value;
      |       ~~~~~~~~~~^~~~~~~~~
a.cc:362:20:   required from here
  362 |         partial_sum(hoge.rbegin(), hoge.rend() - 1, fuga.rbegin() + 1, [](auto a, auto b){return a * b;});
      |         ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:95:23: error: cannot convert 'MMNMM::modint_normal<long unsigned int, 1000000007>::get_value' from type 'const MMNMM::modint_normal<long unsigned int, 1000000007>::value_type& (MMNMM::modint_normal<long unsigned int, 1000000007>::)() const noexcept' {aka 'const long unsigned int& (MMNMM::modint_normal<long unsigned int, 1000000007>::)() const noexcept'} to type 'MMNMM::modint_normal<long unsigned int, 1000000007>::value_type' {aka 'long unsigned int'}
   95 |             this->val = rhs.get_value;
      |             ~~~~~~~~~~^~~~~~~~~~~~~~~