#include <bits/stdc++.h>
using namespace std;
#define int long long
void read (int &x) {
    char ch = getchar(); x = 0; int f = 0;
    while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); }
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    if (f) x = -x;
} const int N = 1e5 + 5, mod = 1e9 + 7;
int n, a[N], f[N];
signed main() {
    read (n);
    for (int i = 1; i <= n; ++i) read (a[i]);
    f[1] = 2, f[0] = 1;
    for (int i = 2; i <= n; ++i)
        f[i] = (f[i - 1] + f[i - 2]) % mod;
    int res = a[1] * f[n - 1];
    for (int i = 2; i <= n; ++i) {
        (res += a[i] * f[i - 2] % mod * f[n - i]) %= mod;
        int A = i == 2 ? 1 : f[i - 3], B = i == n ? 1 : f[n - i - 1];
        (res -= a[i] * A % mod * B) %= mod;
    }
    res = (res % mod + mod) % mod;
    printf ("%lld\n", res);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
ll mem[3005][3005];
ll dp(int n, int k){
    if (k > n) return 0;
    if (n == 0) return (k == 0);
    if (k <= 0) return 0;
    //printf("%d %d\n",n,k);
    if (mem[n][k] != -1) return mem[n][k];
    int ans1 = 0;
    if (k >= 1) ans1 = dp(n-1,k-1);
    int ans2 = dp(n,2*k);
    return mem[n][k] = (ans1+ans2)%mod;

}
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    memset(mem,-1,sizeof(mem));
    printf("%lld\n",dp(n,k));
}
