#include <bits/stdc++.h>
#include <chrono>

using namespace std;
using namespace chrono;

typedef long long int ll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)
#define Clock high_resolution_clock::now()

template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// #define TIME

/******************************************************************************************************************************/


const ll inf = 2e18;
const ll mod = 1e9+7;
const ll N = 4e4+3;


int main()
{
    auto start_time = Clock;
    FASTIO


    ll n, ans = 0;
    cin >> n;
    vll v(n);
    vector<vll> dp(n,vll(2,0));
    rep(i,n) {
    	cin >> v[i];
    }
    dp[0] = {0,1};


    for(ll i=1;i<n;++i) {
    	dp[i][0] = dp[i-1][1] % mod;
    	dp[i][1] = (dp[i-1][1] + dp[i-1][0])%mod;
    }

    auto f = [&](ll x) {return (dp[x][0]+dp[x][1])%mod;};

    rep(i,n) {
    	ll l = i-1, r = n-i-1;
    	ans += (((l<0?1:f(l)) * f(r))%mod) * v[i]; ans %= mod;

    	if((i==0)||(l<0&&r-1<0)) continue;

    	ans = mod + ans - ((((l-1<0?1:f(l-1)) * (r-1<0?1:f(r-1)))%mod) * v[i])%mod; ans %= mod;
    }

    cout << ans << "\n";





    auto end_time = Clock;
    #ifndef TIME
        return 0;
    #endif
    cout << "\nTime elapsed: "
    << (double)duration_cast<milliseconds>(end_time-start_time).count() 
    << "ms";


    return 0;
}
#include<bits/stdc++.h>
#define PI 3.141592653589793238462
#define eps 1e-20
#define fi first
#define se second
using namespace std;
using cd = complex<double>;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdd;
vector<pll> edge[200005];
ll a[200005],b[200005],c[200005],n,ans,mod=1e9+7,h=1,dis[200005];
void dfs(ll u,ll fa,ll dp){
    dis[u]=dp;
    for(auto i:edge[u]){
        ll v=i.fi,w=i.se;
        if(v==fa) continue;
        dfs(v,u,dp^w);
    }
}
int main(){
    cin>>n;
    for(ll i=1;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    for(ll i=0;i<60;i++){
        for(ll j=1;j<=n;j++){
            edge[j].clear();
        }
        for(ll j=1;j<n;j++){
            ll v=((c[j]>>i)&(ll)1);
            edge[a[j]].push_back({b[j],v});
            edge[b[j]].push_back({a[j],v});
        }
        dfs(1,0,0);
        ll num1=0,num0=0;
        for(ll j=1;j<=n;j++){
            if(dis[j]) num1++;
            else num0++;
        }
        ans+=num1%mod*num0%mod*h%mod;
        h*=2;h%=mod;
    }
    cout<<(ans%mod+mod)%mod<<endl;
} 