Arithmetic Subarrays

medium
An arithmetic sequence is a list of numbers with a definite pattern. If you take any number in the sequence then subtract it by the previous one, and the result is always the same or constant then it is an arithmetic sequence. The arithmetic sequence must contain at least 2 elements.
i.e., A[i] - A[i-1] == A[1] - A[0] for all valid i.

Example of valid Arithmetic sequence:
10, 15, 20, 25...
3, 1, -1, -3, -5...

Example of invalid Arithmetic sequence:
6, 7, 9, 11..
Now,
You are given an array, 'arr' that contains 'n' integers and two more arrays 'l' & 'r' respectively of size 'm' each which represents 'm' queries, where the i-th query defines the range [l[i], r[i]].

Return a list of boolean elements answer, where answer[i] is 'true' if the subarray nums[l[i]], nums[l[i]+1], ... , nums[r[i]] can be rearranged to form an arithmetic sequence, and false otherwise.

Note: All arrays follow zero-based indexing.

Input Format

Input and output are managed for you. Just complete the function.

Output Format

Input and output are managed for you. Just complete the function.

Constraints

2 <= n <= 500, where n is length of arr
1 <= m <= 500, where m is length of l & r.
0 <= l[i] < r[i] < n
-10^5 <= arr[i] <= 10^5

Notice

NA

Example

Input
6
4 6 5 9 7 3
3
0 0 2
2 3 5
Output
[true, false, true]
Previous
Moving Stones Until Consecutive
Next
Parsing A Boolean Expression

Related Questions