SP9547 DPAIR - Counting d-pairs

Description

You're given a sequence A of N non-negative integers. Answer Q queries, where each query consists of two integers: a, b. The answer is number of pairs of integers i and j that satisfy these three conditions: (1) 1

Input Format

First line of input contains integer N. Second line contains N integers representing sequence A. Third line is integer Q, number of queries. Next Q lines have 2 integers, a and b.

Output Format

In the i-th line output the answer for i-th query.