All submissions for this problem are available.
N number of Postage Stamps are available in a newly opened Shop. Different Stamps have different ID's (1,2,3, ...) to distinguish one from other. Collecting Stamps is Ashish's hobby. One day his friend, Devesh, told him about the collection in that Shop. They both went to the Shop to purchase stamps. A philately competition was going on. Being too much excited, Ashish wanted to take part in the competition. Pardyot, another Stamp lover, is his competitor.
The competition is such that:
The Shopkeeper will give them range [a,b] , they have to find out the cost of the Stamps from a to b. The one who answers it earliest will win. Now, the cost depends upon the ID's of the Stamps. Cost is the Summation of ID number multiplied by the square of the occurence of that ID number in a given range. Pardyot is too good at Mathematics. Ashish wants your help to calculate it.
First line contains Integer N- number of Postage Stamps.
Next line contains N integers denoting ID's of the Stamps.
Next line contains Q - number of queries.
Next Q lines contains two Integes a and b – starting and ending index.
In Q lines, output the cost of the Stamps for a given range.
Input: 8 1 1 2 2 1 3 1 1 2 2 7 1 6 Output: 20 20 Explanation: For query 1: 2 7 occurrence of 1- 3 occurrence of 2- 2 occurrence of 3- 1 cost=3*3*1 + 2*2*2 + 1*1*3= 20
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS|
Fetching successful submissions