Transformation
题号:NC252118
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Given an array of length n, it undergoes a transformation every second.

In each transformation, the number in the first position will be merged with the number in the second position, the number in the third position will be merged with the number in the fourth position, and so on. This will continue until there are only two numbers left in the array.

When merging two numbers, their sum will be calculated. For example, the array [1, 2, 3, 4, 5] will become [3, 7, 5] after the first second (the first two numbers are merged, the third and fourth numbers are merged, and since there is no sixth number, the fifth number remains unchanged). It will become [10, 5] after the second second, at which point only two numbers remain, and the transformation ends. Christina wants to know the sum of the squares of the last two numbers. For example, in the above array, the square sum is 10^2 + 5^2 = 125.

Since the length of this array can be very large, Christina used a new method when giving you the data. Christina will give you k pieces of information. Each piece of information contains two positive integers a, b, indicating that there is a segment of length a in the array, and all the numbers in the segment are b. Since the answer may be very large, please take the result modulo 10^9+7.

输入描述:

The first line contains two positive integers n and k (1 \leq n \leq 10^{18}, 1 \leq k \leq 10^5), as described in the problem statement. 

The next k lines give two positive integers a and b (1 \leq a \leq n, 1 \leq b \leq 100) respectively, indicating that there are a numbers of b in the array. This problem ensures that the sum of all a values is equal to n.

输出描述:

Output the sum of the squares of the last two numbers after all transformations have been made.
示例1

输入

复制
5 5
1 1
1 2
1 3
1 4
1 5

输出

复制
125
示例2

输入

复制
7 2
3 1
4 2

输出

复制
61