#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define REPA(i,j) for(int i=1;i<=j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
#define all(a) a.begin(),a.end()
using namespace std;
const int INF=1<<30;
//const ll INF=1ll<<60;
const ll MOD=1e9+7;
inline void read(int &x){
//	short neg=1;
	x=0;
	char c=getchar();
	/*while(c<'0'||c>'9'){
		if(c=='-')neg=-1;
		c=getchar();
	}*/
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+(c^48),c=getchar();
	}
//	x*=neg;
}
ll quick_mod(ll A,ll B){//A^B
    ll ret=1;
    A%=MOD;
    while(B)
    {
        if(B&1)ret=ret*A%MOD;
        B>>=1;
        A=A*A%MOD;
    }
    return ret;
}
const int MAXN=1e5+10;
ll N;
ll A[MAXN];
int main(void){	
	cin>>N;
	REP(i,N)cin>>A[i];
	if(N==1){
		cout<<A[0];
		return 0;
	}
	ll X=A[0]+A[1],Y=A[0]-A[1];
	ll K1=1,K2=1;
	for(int i=2;i<N;i++){
		ll x,y;
		x=(X+A[i]*K1+Y+A[i]*K2)%MOD;
		y=(MOD*1000+X-A[i]*K1)%MOD;
		X=x;
		Y=y;
		ll k1,k2;
		k1=K1+K2;
		k2=K1;
		K1=k1%MOD;
		K2=k2%MOD;
	}
	cout<<(ll)(MOD*3+X+Y)%MOD;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long b,c,x,y;
unsigned long long ans=0;
int main(){
	scanf("%lld%lld",&b,&c);
	if(c==1){
		if(b==0)printf("1");
		else printf("2");
		return 0;
	}
	if(b==0)printf("%lld",c);
	else if(b>0){
		x=c%2;
		y=c/2;
		if(y>=b)ans=2*b+1;
		else if(x)ans=2*y+2;
		else ans=2*y+1;
		x=(c-1)%2;
		y=(c-1)/2;
		if(x)ans+=2*y;
		else ans+=2*y-1;
		printf("%llu",ans);
	}
	else{
		x=(c-1)%2;
		y=(c-1)/2;
		b=-b;
		if(y>=b)ans=2*b+1;
		else if(x)ans=2*y+2;
		else ans=2*y+1;
		b=-b;
		x=c%2;
		y=c/2;
		if(x)ans+=2*y;
		else ans+=2*y-1;
		printf("%llu",ans);
	}
	return 0;
}