The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 402 Weeks Ago, 1 Day Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
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.
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