Snapp Food wants to praise the best restaurants according to their in-app scores. Each restaurant has introduced and sent its representative to Snapp Food’s center.
There are representatives who are given ID numbers through , standing in a row from left to right. Initially, the ID number of the -th person from the left is .
Snapp Food wants you to rearrange the representatives in ascending order of the ID number from left to right, by repeatedly doing the three kinds of operations below. You can do these operations any number of times (possibly zero) in any order:
Minimize the total cost you pay before achieving the objective.
The first line of the test case is the number of representatives .
In the next line of the input, the representative IDs () are separated by space.
The following lines, each includes the three aforementioned costs: .
all values in input are integers.
Print the minimum total cost you need to pay before achieving the objective.