Task
Joe Golderberg is a very quiet guy from Galați. He spends most of his time reading books and working as a bookseller. He also enjoys restoring books and has a special room in the basement of the bookstore for this craft. He visits this room on different days, and when he does, he can choose to put one or more books in for restoration, take one or more books out, or do nothing.
Joe received books from his friend, Loaf. Each book () has an optimal restoration time , which represents the ideal number of days it should stay in the special room.
Additionally, each book has a maximum selling price , which is obtained if the book spends exactly days in the restoration room.
The selling price of a book is calculated using the formula: , where:
- is the day the book was placed in restoration,
- is the day the book was taken out.
Note: Joe must put all books up for restoration. Additionally, he can enter the restoration room multiple times on the same day, meaning he can leave a book in on and pick it up on the same day , but in this case, it will count as full days of restoration.
Joe wants to buy a bouquet of flowers for Loaf and needs to maximize his profit from selling the books.
Input data
The first line of input contains a single integer () - the number of days in which Joe visits the restoration room.
The second line of input contains integers () - the days in which Joe visits the restoration room.
The third line of input contains a single integer (; ) - the number of books.
The fourth line of input contains integers () - the optimal times that the books need to spend in the restoration room.
The fourth line of input contains integers () - the maximum selling prices of the books after restoration.
It is guaranteed that .
Output data
Print one integer, the maximum profit you can achieve after restoring all books.
Example
stdin
2
5 14
3
10 7 1
3 13 14
stdout
26
Explanation
We have available days: and .
We have books, each with their respective restoration times and optimal costs.
Book : If placed on day , it should ideally be taken out on day , but there is no day available. The closest is , meaning a penalty of . So its selling price is .
Book : If placed on day , it should ideally be taken out on day , but we only have day , meaning a penalty of . Selling price .
Book : If placed on day and removed the same day, it gets full days of restoration. Since , the penalty is , so its selling price .
Total Profit .