#d2605. 蒟蒻
蒟蒻
Konjac Jellies
Problem Description
A row of konjac jellies sits on the shelf of a convenience store, dazzling the picky shopper...
Each jelly has a price and a taste value . The picky shopper has a shopping basket, and when selecting konjac jellies he may perform the following operations:
- Operation : put a jelly with price and taste into the basket.
- Operation : take out the cheapest jelly in the basket.
- Operation : take out the worst-tasting jelly in the basket ( the smaller, the worse the taste).
The picky shopper dislikes duplicates: when an operation has a price or a taste already present in the basket, he immediately puts the jelly back on the shelf.
After operations, the picky shopper has decided which jellies to buy. Please help him compute the total price of the jellies left in the basket.
Input Format
The first line contains a positive integer , the number of operations.
Lines to each contain one or three integers, representing , , respectively.
and are present if and only if .
Output Format
Output one integer, the total price of the jellies in the basket.
Sample Input
6
1 1 1
1 2 5
2
1 3 3
3
1 5 2
Sample Output
7
Constraints
For all data, , , and the input is guaranteed to be valid.