Problem:
Score : 1600 points

Problem Statement

Joisino has a bar of length N, which has M marks on it.
The distance from the left end of the bar to the i-th mark is X_i.

She will place several squares on this bar.
Here, the following conditions must be met:

Only squares with integral length sides can be placed.

Each square must be placed so that its bottom side touches the bar.

The bar must be completely covered by squares.
That is, no square may stick out of the bar, and no part of the bar may be left uncovered.

The boundary line of two squares may not be directly above a mark.

Examples of arrangements that satisfy/violate the conditions

The beauty of an arrangement of squares is defined as the product of the areas of all the squares placed.
Joisino is interested in the sum of the beauty over all possible arrangements that satisfy the conditions.
Write a program to find it.
Since it can be extremely large, print the sum modulo 10^9+7.

Constraints

All input values are integers.

1 \leq N \leq 10^9

0 \leq M \leq 10^5

1 \leq X_1 < X_2 < ... < X_{M-1} < X_M \leq N-1

Input

Input is given from Standard Input in the following format:

N M
X_1 X_2 ... X_{M-1} X_M

Output

Print the sum of the beauty over all possible arrangements that satisfy the conditions, modulo 10^9+7.

Sample Input 1

3 1
2

Sample Output 1

13

There are two possible arrangements:

Place a square of side length 1 to the left, and place another square of side length 2 to the right

Place a square of side length 3

The sum of the beauty of these arrangements is (1 \times 1 \times 2 \times 2) + (3 \times 3) = 13.

Sample Input 2

5 2
2 3

Sample Output 2

66

Sample Input 3

10 9
1 2 3 4 5 6 7 8 9

Sample Output 3

100

Sample Input 4

1000000000 0

Sample Output 4

693316425

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

template<typename T>
struct SegmentTree{
private:
    int n;
    T E;
    vector<T> node;
    inline void updatef(T& x,T& y){
        x = y;
        //x += y;
        //x = max(x,y);
        //x = min(x,y);
    }
    inline T queryf(T& x,T& y){
        return x*y;
        //return x+y;
        //return max(x,y);
        //return min(x,y);
    }

public:
    SegmentTree(int sz,T& E_):E(E_){
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E);
    }

    SegmentTree(vector<T>& A,T& E_):E(E_){
        int sz=A.size();
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E);
        rep(i,sz)node[i+n-1]=A[i];
        for(int i=n-2;i>=0;--i){
            node[i]=queryf(node[2*i+1], node[2*i+2]);
        }
    }
    void update(int k,T x){
        k+=n-1;
        updatef(node[k],x);
        while(k>0){
            k=(k-1)/2;
            node[k]=queryf(node[2*k+1], node[2*k+2]);
        }
    }
       //[a,b)での和を返す
    T get(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        if(r<=a||b<=l)return E;
        if(a<=l&&r<=b)return node[k];
        T xl=get(a,b,2*k+1,l,(l+r)/2);
        T xr=get(a,b,2*k+2,(l+r)/2,r);
        return queryf(xl, xr);
    }
};

template<typename T>
struct Matrix{
    int h,w;
    vector<T> a;
    Matrix(int n_=0):h(n_),w(n_),a(n_*n_){}
    Matrix(int n_, int m_):h(n_),w(m_),a(n_*m_){}
    Matrix(int n_, int m_, vector<T> a_):h(n_),w(m_),a(a_){}
    T& get(int r,int c){return a[r*w+c];}
    T get(int r,int c)const{return a[r*w+c];}

    Matrix& operator+=(const Matrix& m) {
		assert(h == m.h && w == m.w);
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				a[i * w + j] += m.a[i * w + j];
			}
		}
	}
	Matrix& operator-=(const Matrix& m) {
		assert(h == m.h && w == m.w);
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				a[i * w + j] -= m.a[i * w + j];
			}
		}
	}
	Matrix& operator*=(const Matrix& m) {
		assert(w == m.h);
		Matrix ans(h, m.w);
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < m.w; ++j) {
				for (int k = 0; k < w; ++k) {
					(ans.a[i * m.w + j] += a[i * w + k] * m.a[k * m.w + j])%=mod;
				}
			}
		}
		return (*this) = ans;
	}
	Matrix operator+(const Matrix& m) const { return Matrix(*this) += m; }
	Matrix operator-(const Matrix& m) const { return Matrix(*this) -= m; }
	Matrix operator*(const Matrix& m) const { return Matrix(*this) *= m; }
};
template<typename T>
Matrix<T> unit(int n){
    Matrix<T> ret(n);
    rep(i,n)ret.get(i,i)=1;
    return ret;
}
template<typename T>
Matrix<T> matpow(Matrix<T> a,int n){
    assert(a.h==a.w);
    Matrix<T> ret=unit<T>(a.h);
    while(n){
        if(n&1)ret*=a;
        a*=a;
        n>>=1;
    }
    return ret;
}


using mat=Matrix<ll>;

const mat A(3,3,{4,mod-2,1,1,0,0,0,1,0});
ll calc(int n){
    mat B = matpow(A,n);
    return (5*B.get(2,0)+B.get(2,1))%mod;
}

vector<ll> cal(mat A,vector<ll> x){
    vector<ll> ret(3);
    rep(i,3)rep(j,3)(ret[i]+=A.get(i,j)*x[j])%=mod;
    return ret;
}

vector<ll> ad(vector<ll> x,vector<ll> y){
    vector<ll> ret(3);
    rep(i,3)ret[i]=(x[i]+y[i])%mod;
    return ret;
}


int main(){
    int n,m;
    cin>>n>>m;
    vector<ll> vec[m+2];
    ll dp[m+2];
    dp[0]=0;
    ll a[m+2];
    rep(i,m)cin>>a[i+1];
    a[0]=0;
    a[m+1]=n;
    vec[0]={0,0,0};
    rep(i,m+1){
        vec[i]=cal(matpow(A,a[i+1]-a[i]),vec[i]);
        dp[i+1]=(mod+calc(a[i+1])-vec[i][2]%mod)%mod;
        vec[i+1]={5*dp[i+1]%mod,dp[i+1],0};
        vec[i+1]=ad(vec[i+1],vec[i]);
    }
    cout<<dp[m+1]<<endl;
}