GCD, Sum, Multiply. What?...#266

GCD, Sum, Multiply. What?...

3 seconds
256 megabytes
Very hard

The author has used up all the creative skills on previous problems, so Anton won't be tortured in this statement. He will just give you an interesting problem.

You are given an array consisting of integers. You are also given queries [l;r]. For each query, find the maximum value of \operatorname{sum}[tl;tr] \times \operatorname{gcd}[tl;tr] over all pairs (tl;tr), where

The greatest common divisor of two numbers and is the largest positive integer that divides both and .

The greatest common divisor of a set of numbers is the largest positive integer that divides all elements of the set.

Input

The first line contains two integers , (1 \le n, q \le 2 \cdot 10^5) — the number of elements in the array and the number of queries, respectively.

The second line contains integers a_i (1 \le a_i \le 6 \cdot 10^6) — the description of the array.

Each of the next lines contains two integers , (1 \le l \le r \le n) — the description of the queries.

Output

Print integers — the answers to the queries.

Examples

Example

Loading
Loading

Example 1

Loading
Loading

Note

In the first example, there are following segments:

  • — \operatorname{sum}[1;1] \times \operatorname{gcd}[1;1] = 3 \times 3 = ;

  • — \operatorname{sum}[1;2] \times \operatorname{gcd}[1;2] = 6 \times 3 = ;

  • — \operatorname{sum}[1;3] \times \operatorname{gcd}[1;3] = 8 \times 1 = ;

  • — \operatorname{sum}[2;2] \times \operatorname{gcd}[2;2] = 3 \times 3 = ;

  • — \operatorname{sum}[2;3] \times \operatorname{gcd}[2;3] = 5 \times 1 = ;

  • — \operatorname{sum}[3;3] \times \operatorname{gcd}[3;3] = 2 \times 2 = .

Scoring

  1. ( points): n \le 3;

  2. ( points): n, q \le 10^3;

  3. ( points): n \le 10^3;

  4. ( points): n, q \le 10^5;

  5. ( points): n \le 10^5;

  6. ( points): a_i \le 20;

  7. ( points): a_i \le 10^3;

  8. ( points): l = 1;

  9. ( points): no additional constraints.