#include using namespace std; #define For(i, a, n) for(int i =a;i pii; template void dbg(Args&&... args){ ((cerr< pair operator+(const pair&a, const pair& b){ return {a.first +b.first, a.second + b.second}; } template ostream& operator<< (ostream& os, const pair& a){ return os<<"("< basic_ostream& operator<<(basic_ostream& os, const C&c){ for(auto it=begin(c); it!=end(c);++it){ os<<(it==begin(c)?"":" ")<<*it; } return os; } void solve(){ vec fib = {1, 2}; do{ ll t = fib[fib.size()-1] + fib[fib.size()-2]; fib.push_back(t); }while(fib.back() < 1000000000); dbg(fib.size(), fib); int fs = fib.size(); int n, q;cin>>n>>q; vec> p (n + 1, vec(fs)); map m; For(i, 1, n + 1){ int a;cin>>a; For(j, 0, fs){ p[i][j] = p[i-1][j]; ll d= fib[j] -a; if(d <=0)continue; if(m.count(d)) p[i][j] = max(p[i][j], m[d]); } m[a] = i; } For(i, 0, q){ int z, k;cin>>z>>k; z++, k++; ll ans = 0; For(j, 0, fs){ if(p[k][j]>=z)ans++; } cout<sync_with_stdio(0); cin.exceptions(cin.failbit); int t=1;//cin>>t; while(t--){ solve(); } }