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

//solution:
#define int int64_t
#define span(a) begin(a), end(a)
constexpr int mod = 1e9 + 7;

void hike() {
  int n; cin >> n;
  vector<int> a(n);
  for(int& i: a) {
    cin >> i;
  }
  if(n == 1) {
    cout << a[0] << "\n";
    return;
  }
  int dp[n][2], p[n][2];
  memset(dp, 0, sizeof dp);
  memset(p, 0, sizeof p);
  dp[1][0] = a[0] - a[1];
  dp[1][1] = a[0] + a[1];
  p[1][0] = p[1][1] = 1;
  for(int i = 2; i < n; ++i) {
    dp[i][0] = ((dp[i - 1][1] - p[i - 1][1] * a[i] % mod) % mod + mod) % mod;
    dp[i][1] = ((dp[i - 1][0] + dp[i - 1][1]) % mod + (p[i - 1][0] + p[i - 1][1]) * a[i] % mod) % mod;
    p[i][0] = p[i - 1][1];
    p[i][1] = (p[i - 1][0] + p[i - 1][1]) % mod;
  }
  cout << (dp[n - 1][0] + dp[n - 1][1]) % mod << "\n";  
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  int t = 1; //cin >> t;
  while(t--) hike();
  return 0;
} //farewell, until we meet again..
#include <bits/stdc++.h>

using namespace std;

using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using isize = ptrdiff_t;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using usize = size_t;

using f32 = float_t;
using f64 = double_t;

template <typename T> using vec = vector<T>;
template <typename T> using vec_deq = deque<T>;
template <typename T> using linked_list = list<T>;

template<typename T> using hash_set = unordered_set<T>;
template<typename T> using btree_set = set<T>;

template<typename K, typename V> using hash_map = unordered_map<K, V>;
template<typename K, typename V> using btree_map = map<K, V>;

template<typename T> using max_heap = priority_queue<T>;
template<typename T> using min_heap = priority_queue<T, vec<T>, greater<T>>;

template<typename T> using fn = function<T>;

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());


namespace mod {
    template<typename Tp>
    inline Tp pow(Tp x, u64 y) {
        Tp r = (Tp)1;
        while (y) {
            if (y & 1) r = r * x;
            x = x * x, y >>= 1;
        }
        return r;
    }

    constexpr bool is_prime(i64 n) {
        if (n == 1) return false;
        if ((n & 1) == 0) return n == 2;

        for (i64 i = 3; i * i <= n; i += 2) {
            if (n % i == 0) return false;
        }
        return true;
    }

    template<i64 M>
    class modular {
    private:
        static_assert(is_prime(M) == true, "M is not a prime number");
        i64 value;

        modular inv() const { return pow(*this, M - 2); }
    public:
        modular() : value(0) {}
        modular(i64 rr) : value(rr) { value %= M; if (value < 0) value += M; }

        inline modular operator * (const modular& t) const { return (value * t.value) % M; }
        inline modular operator / (const modular& t) const { return *this * t.inv(); }
        inline modular operator + (const modular& t) const { return modular(*this) += t; }
        inline modular operator - (const modular& t) const { return modular(*this) -= t; }

        inline modular operator += (const modular& t) { value += t.value; if (value >= M) value -= M; return *this; }
        inline modular operator -= (const modular& t) { value -= t.value; if (value < 0) value += M; return *this; }
        inline modular operator *= (const modular& t) { return *this = *this * t; }
        inline modular operator /= (const modular& t) { return *this = *this / t; }

        inline bool operator == (const modular& t) const { return value == t.value; }
        inline bool operator != (const modular& t) const { return value != t.value; }

        inline operator i64() const { return value; }

    };
}

typedef mod::modular<1000000007> mint;
// typedef mod::modular<998244353> MInt;

auto main() -> i32 {

    ios::sync_with_stdio(false), cin.tie(nullptr);

    i32 n;
    cin >> n;
    vec<mint> pls(n + 1), mis(n + 1);
    vec<i32> a(n + 1);

    pls[0] = 1;
    mis[0] = 0;

    for (i32 i = 1; i <= n; i++) {
        cin >> a[i];

        pls[i] = pls[i - 1] + mis[i - 1];
        mis[i] = pls[i - 1];

    }

    mint ans = 0;
    for (i32 i = 1; i <= n; i++) {
        if (i > 1) {
            ans += mint(a[i]) * (pls[n - i] + mis[n - i]) * (pls[i - 2] + mis[i - 2]);
            if (i > 2 && i < n)
                ans -= mint(a[i]) * (pls[n - i - 1] + mis[n - i - 1]) * (pls[i - 3] + mis[i - 3]);

            if (n > 2) {
                if (i == 2)
                    ans -= mint(a[i]) * (pls[n - i - 1] + mis[n - i - 1]) * (mint(1));
                else if (i == n)
                    ans -= mint(a[i]) * (pls[n - 3] + mis[n - 3]);
            }
            else {
                ans -= mint(a[i]);
            }
        }
        else {
            ans += mint(a[i]) * (pls[n - 1] + mis[n - 1]);
        }
    }

    cout << i64(ans);
    cout << "\n";
    return 0;
}