PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000157. Mô-đun lớn nhất để các phần tử đồng dư (Maximum modulo equality)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Mô-đun lớn nhất để các phần tử đồng dư (Maximum modulo equality)

Maximum modulo equality

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given an array a1,…,ana_1,\ldots,a_n of positive integers, answer queries on inclusive subarrays [l,r][l,r]. For each query, find the largest positive integer mm such that all al,…,ara_l,\ldots,a_r have the same remainder modulo mm.

If mm is unbounded because all values in the segment are equal, print 0 by convention. This includes ranges of length one. Queries do not modify the array.

Input

The first line contains n,qn,q. The second line contains the nn array values. Each of the next qq lines contains l,rl,r with 1≤l≤r≤n1\le l\le r\le n.

Output

For each query print the greatest admissible modulus, or 0 if it is unbounded.

Subtasks

  • Subtask 1 (20 points): 1≤n,q≤401 \le n,q \le 40; 1≤ai≤10001 \le a_i \le 1000.
  • Subtask 2 (30 points): 1≤n,q≤50001 \le n,q \le 5000; 1≤ai≤1061 \le a_i \le 10^6.
  • Subtask 3 (50 points): 1≤n,q≤2⋅1051 \le n,q \le 2\cdot10^5; 1≤ai≤1091 \le a_i \le 10^9.

Examples

Input

5 5
5 14 2 6 3
4 5
1 4
2 4
3 5
1 1

Output

3
1
4
1
0

Explanation

For [4,5][4,5], the values 6,36,3 have the same residue modulo 33, the largest feasible modulus. For [2,4][2,4], 14,2,614,2,6 share residue 22 modulo 44. Queries [1,4][1,4] and [3,5][3,5] have answer 11. A single-element segment has an unbounded modulus and therefore outputs 0.