#include<bits/stdc++.h>
#define rep(i,a,b) for(R int i=a;i<=b;i++)
#define R register
#define endl putchar('\n')
const int N=500005;
const long long mod=1e9+7;
#define int long long
using namespace std;

int n,a[N],f[N][2],c[N][2];

void dp() {
	f[0][0]=a[1],c[0][0]=1;
	rep(i,1,n-1) {
		f[i][0]=(f[i-1][0]+c[i-1][0]*a[i+1]+f[i-1][1]+c[i-1][1]*a[i+1])%mod;
		c[i][0]=(c[i-1][1]+c[i-1][0])%mod;
		f[i][1]=(f[i-1][0]-c[i-1][0]*a[i+1]%mod+mod)%mod;
		c[i][1]=c[i-1][0];
	}
}

signed main() {
	scanf("%lld",&n);
	rep(i,1,n) scanf("%lld",&a[i]);
	dp();
	printf("%lld",(f[n-1][1]+f[n-1][0])%mod);
	return 0;
}
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
#include <unordered_map>
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for(ll i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define spre cout<<fixed<<setprecision(15);
typedef long long int ll;
using namespace std;
//ll mod=67280421310721;
ll mod=998244353;
// ll mod=1000000007;
ll INF=1e18;
ll dp[6005][3005];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
	while(test--)
	{
		FOR(i,0,3000)
		{
			ll a=0;
			FOR(j,1,6000)
			{
				if(i==0)
				{
					dp[j][i]=1;
					continue;
				}
				if((i-j)>=0 && (2*j)<6000)
				{
					a+=dp[2*j][i-j];
					a%=mod;
				}
				dp[j][i]=a;
			}
		}
		int n,k;
		cin>>n>>k;
		cout<<dp[k][n-k];
	}
	return 0;
}