Maurice Tutor

(5)

$15/per page/Negotiable

About Maurice Tutor

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Algebra,Applied Sciences See all
Algebra,Applied Sciences,Biology,Calculus,Chemistry,Economics,English,Essay writing,Geography,Geology,Health & Medical,Physics,Science Hide all
Teaching Since: May 2017
Last Sign in: 402 Weeks Ago, 1 Day Ago
Questions Answered: 66690
Tutorials Posted: 66688

Education

  • MCS,PHD
    Argosy University/ Phoniex University/
    Nov-2005 - Oct-2011

Experience

  • Professor
    Phoniex University
    Oct-2001 - Nov-2016

Category > Computer Science Posted 16 Sep 2017 My Price 9.00

number of Postage Stamps

Problem description

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.

Input

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.

Constraints

  • 1
  • 1
  • 1

 

Output

In Q lines, output the cost of the Stamps for a given range.

Example

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
 

Answers

(5)
Status NEW Posted 16 Sep 2017 01:09 PM My Price 9.00

Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll

Not Rated(0)