Question
Balance of Magical Stones
In an ancient kingdom, there are KaTeX can only parse string typed expression magical stones, each infused with a magical power.
The power of the KaTeX can only parse string typed expression-th stone is represented by an integer KaTeX can only parse string typed expression.
A wizard is interested in measuring the balance of magic in the kingdom.
To do so, the wizard selects:
-
the KaTeX can only parse string typed expression-th least magical stone, and
-
the KaTeX can only parse string typed expression-th most magical stone.
Your task is to calculate the sum of the powers of these two selected stones.
The stones are given in no particular order.
Input
The first line contains a single integer KaTeX can only parse string typed expression — the number of magical stones.
The second line contains KaTeX can only parse string typed expression space-separated integers
KaTeX can only parse string typed expression — the magical power of each stone.
The third line contains a single integer KaTeX can only parse string typed expression.
The second line contains KaTeX can only parse string typed expression space-separated integers
KaTeX can only parse string typed expression — the magical power of each stone.
The third line contains a single integer KaTeX can only parse string typed expression.
Output
Print a single integer — the sum of the powers of the KaTeX can only parse string typed expression-th least magical stone and the KaTeX can only parse string typed expression-th most magical stone.
Example
Input
6
7 10 4 3 20 15
2
Output
19
Explanation:
After arranging the stones in increasing order of magical power:
KaTeX can only parse string typed expression
The KaTeX can only parse string typed expression-nd least magical stone has power KaTeX can only parse string typed expression.
The KaTeX can only parse string typed expression-nd most magical stone has power KaTeX can only parse string typed expression.
So, the required sum is:
KaTeX can only parse string typed expression
6
7 10 4 3 20 15
2
Output
19
Explanation:
After arranging the stones in increasing order of magical power:
KaTeX can only parse string typed expression
The KaTeX can only parse string typed expression-nd least magical stone has power KaTeX can only parse string typed expression.
The KaTeX can only parse string typed expression-nd most magical stone has power KaTeX can only parse string typed expression.
So, the required sum is:
KaTeX can only parse string typed expression