#include using namespace std; #define rep(i,n) for (long long i=0;i<(long long)(n);i++) #define all(v) v.begin(),v.end() using ll=long long; using pll=pair; using tll=tuple; const ll INF=(1ll<<60); template void chmin(T &a,T b){ if(a>b){ a=b; } } template void chmax(T &a,T b){ if(a> n; vector a(n); rep(i,n) cin >> a[i]; vector r(n+1); r[0]=1; rep(i,n) r[i+1]=r[i]*2%mod; ll sum=0; vector v(n); rep(i,n-1){ sum+=r[i]; sum%=mod; } v[0]=sum; rep(i,n-1) v[i+1]=(v[i]-r[i]+mod)%mod; ll ans=0; rep(i,n){ ans+=a[i]*v[i]%mod; ans%=mod; } reverse(all(v)); rep(i,n){ ans=(ans-a[i]*v[i]%mod+mod)%mod; } cout << ans << endl; }