2506 - calc

     给一个长度为n的非负整数序列A1,A2,…,An。现有m个询问,每次询问给出l,r,p,k,问满足l<=i<=r且Ai mod p = k的值i的个数。

Input

     第一行两个正整数n和m。
     第二行n个数,表示A1,A2,…,An。
     以下m行,每行四个数分别表示l,r,p,k。满足1<=l<=r<=n。

Output

     对于每个询问,输出一行,表示可行值i的个数。

Examples

Input

5 2
1 5 2 3 7
1 3 2 1
2 5 3 0

Output

2
1 

Hint

数据范围:

     0<n,m<=10^5,任意1<=i<=n满足Ai<=10^4,0<p<=10^4,0<=k<p。
Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题