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 <algorithm>
#include <iostream>
using namespace std;

typedef long long i64;

const i64 MOD = 1e9 + 7;
const i64 MAXN = 100000 + 5;

template<class T = long long>
struct matrix
{
private:
	T data[3][3];
public:
	matrix(int dig = 0)
	{
		for (int i = 0; i < 3; i++)
			for (int j = 0; j < 3; j++)
				data[i][j] = (i == j ? dig : 0);
	}
	virtual ~matrix() = default;

	T * operator [](int index)
	{
		return data[index];
	}

	const T * operator[](int index) const
	{
		return data[index];
	}

	matrix operator *(const matrix & rhs)
	{
		matrix result(0);

		for (int k = 0; k < 3; k++)
			for (int i = 0; i < 3; i++)
				for (int j = 0; j < 3; j++)
					result[i][j] = (result[i][j] + data[i][k] * rhs[k][j] % MOD)
							% MOD;

		return result;
	}

	// Modulus operator is a dummy
	matrix operator %(const T & rhs)
	{
		return (*this);
	}
};

template<class T, class expType>
T modularExp(T base, expType exp)
{
	T answer(1);
	while (exp)
	{
		if (exp & 1)
			answer = answer * base % MOD;
		base = base * base % MOD;
		exp = exp >> 1;
	}
	return answer;
}

i64 N, M, x[MAXN];
matrix<> mat;
i64 dp1[3], dp2[3];
i64 *oldDp, *newDp;

int main()
{

	cin >> N >> M;
	for (int i = 1; i <= M; i++)
		cin >> x[i];
	mat[0][0] = 1, mat[0][1] = 1, mat[0][2] = 2;
	mat[1][0] = 1, mat[1][1] = 2, mat[1][2] = 2;
	mat[2][0] = 0, mat[2][1] = 1, mat[2][2] = 1;

	oldDp = dp1, newDp = dp2;

	oldDp[0] = 1, oldDp[1] = (x[1] == 1 ? 1 : 2), oldDp[2] = 1;

	x[0] = 1, x[M + 1] = N;

	for (i64 i = 1 + (x[1] == 1); i <= M + 1; i++)
	{
		//printf("now %d, %d %d %d\n", i, oldDp[0], oldDp[1], oldDp[2]);
		matrix<> now = modularExp(mat, x[i] - x[i - 1]);

		for (int k = 0; k < 3; k++)
			newDp[k] = (oldDp[0] * now[k][0] % MOD + oldDp[1] * now[k][1] % MOD
					+ oldDp[2] * now[k][2] % MOD) % MOD;

		newDp[1] = (newDp[1] - newDp[0] + MOD) % MOD;
		swap(newDp, oldDp);
	}

	cout << oldDp[0] << endl;

	return 0;
}