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: Wrong Answer)

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int Mod = 1e9 + 7;

int n, m, i, A[4][4], x, x0;

void inm(int a[4][4], int b[4][4])
{
    ll c[4][4];
    memset(c, 0, sizeof(c));

    int i, j, k;
    for(i=0; i<4; ++i)
        for(j=0; j<4; ++j)
            for(k=0; k<4; ++k)
                c[i][j] += (ll) a[i][k] * b[k][j];

    for(i=0; i<4; ++i)
        for(j=0; j<4; ++j)
            a[i][j] = c[i][j] % Mod;
}

void res(int ans[4][4], int x)
{
    int i;
    int a[4][4]
    {
        1, 1, 1, 1,
        0, 1, 0, 1,
        0, 0, 1, 1,
        1, 1, 1, 2,
    };

    for(i=0; x; ++i)
    {
        if(x&(1<<i))
        {
            x ^= (1<<i);
            inm(ans, a);
        }

        inm(a, a);
    }
}

int main()
{
  //  freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    cin >> n >> m;

    x0  = 0;
    A[0][0] = 1; A[0][1] = A[0][2] = A[0][3] = 0;

    for(i=1; i<=m; ++i)
    {
        cin >> x;
        res(A, x - x0);

        x0 = x + 1;
        A[0][3] = A[0][0] + A[0][1] + A[0][2] + A[0][3];
        A[0][2] = A[0][0] + A[0][2];
        A[0][1] = A[0][0] + A[0][1];
    }

    res(A, n - x0);
    cout << A[0][3] << '\n';

    return 0;
}