N two-sided cards start showing A_i and each threshold T_j flips every card whose visible number is at most T_j; compute the final visible sum.
Hard8Segment treeSortingSimulationNo attempts yetTime limit2sMemory limit256 MBProfessor K is the president of the Japanese committee for the International Olympiad in Informatics. He likes fortune telling and always has several kinds of it going. Today he decided to tell the fortune of this year's Japanese delegation with cards.
An integer is written on each side of every card. The two integers on one card are not necessarily different. Once a card lies on the table, only the integer on the upper side is visible and the integer on the other side is hidden.
The fortune telling goes as follows.
Deciding which cards to turn over is a boring job, so Professor K gave up telling fortunes with cards. He only wants the sum of the integers visible on the table after all K operations are finished.
Given the integers written on the cards and the description of the operations, write a program that computes the sum of the integers visible on the cards after every operation is finished.
Read the following data from standard input.
All input data satisfy the following conditions.
Print to standard output, on one line, the sum of the integers visible on the cards after the K operations are finished.
In the first example the integers visible at the start are 4, 9, 8, 4, 3 in this order. The operations run as follows.
After all operations the sum of the visible integers is 4+1+8+2+3=18.