Pairwise Product
You are given an array of integers . Your task is to answer queries of the following type:
For given , output the sum of products for all pairs . Formally, you need to compute . The answer may be large, so output it modulo .
Input
The first line contains a single number () — the size of the array .
The second line contains integers — the elements of the array.
The third line contains a single integer () — the number of queries.
Each of the next lines contains two integers and ().
Output
Output lines — the answer to each query.
Examples
Scoring
In this problem, there are conditional blocks. If your solution works correctly for certain constraints, it will receive a certain number of points. Please note that the evaluation is still in the testing phase.
( points): , ;
( points): , ;
( points): without additional constraints.