Under construction

Still being built. Things may change

Rabid Rabbit

Time limit10sMemory limit1024 MB

Summary
For each segment, count the distinct Fibonacci numbers that equal the sum of rabbit counts in some pair of hutches inside the segment.
Level

Medium6 of 10

Topics
Hash map, Intervals, Sorting
Solved
No attempts yet

Problem

Famous magician Leonardo from Pisa is about to visit the farm and amuse the staff with his tricks. A long row of rabbit hutches stands along one wall of the farm yard. Each hutch is permanently occupied by some number of rabbits. To perform his tricks, the magician needs to use the row of hutches. However, the farm is planning maintenance, and it can offer only one contiguous segment of the row. To help Leonardo, the staff compiled a list of segments. Leonardo chooses one segment from the list, and the hutches outside that segment are inaccessible to him during the maintenance.

Before Leonardo chooses a segment, he has to consider his own restrictions. Each day, he performs one trick on the chosen segment. A trick needs a pair of hutches in the segment such that the total number of rabbits in both hutches equals one of the positive Fibonacci numbers. The positive Fibonacci numbers form an infinite sequence that starts with 1 and 2, and each next term is the sum of the two terms before it. Each day, the Fibonacci number used must differ from all Fibonacci numbers used on previous days. When Leonardo cannot perform another trick, he must leave the farm.

For each segment in the list, determine the maximum number of days Leonardo can stay on the farm.

Input

The first line contains two integers NN and QQ (1≤N,Q≤1051 \le N, Q \le 10^5), the number of hutches and the number of segments in the list. The second line contains NN space-separated integers A0,A1,…,AN−1A_0, A_1, \dots, A_{N-1} (1≤Ai≤1091 \le A_i \le 10^9), the number of rabbits in each hutch, starting from the first hutch. Each of the following QQ lines contains two integers PP and RR (0≤P<R≤N−10 \le P < R \le N-1), the number of the first and the last hutch in a segment. The hutches are numbered 00 to N−1N-1.

Output

Output QQ lines. Each line contains one integer, the maximum number of days Leonardo can spend on the farm for the corresponding segment.

Examples1

  1. Example 1

    Input
    8 4
    7 3 2 10 3 4 1 2
    0 5
    1 2
    4 5
    4 7
    
    Expected output
    2
    1
    0
    2