A company is assigned a project to develop an online share trading application. In the application there are two groups of shares i.e. group 1 and group 2. Group1 has N number of shares identified by codes from 0 to (N-1) and group 2 has M number of shares identified by share codes 0 to (M-1). Both groups consist of share positions in the market. The share positions can be similar between the groups and also within the group. The share application must be designed with an algorithm that provides maximum profit to its users at minimum cost by swapping the shares' position in group 1. In one operation, the application swaps the share positions of any two shares in group 1 so that the share position in group 1 with respect to its code becomes unequal to the share position in group 2. The cost of the operation is calculated as the sum of the share codes. For the next similar operation the new share positions in group 1 will be considered. The whole process continues until each share position at group 1 with respect to their code becomes unequal to the share position of group 2. The minimum cost is the sum of all the operations cost incurred while carrying out the whole process.
Write an algorithm to find the minimum cost.
Input
The first line of input consists of an integer – numGroup1 , representing the total number of shares in group 1 (N).
The second line consists of N space-separated integers representing the share positions of each code in group 1.
The third line consists of an integer – numGroup2 , representing the total number of shares in group 2 (M).
The last line consist of M space-separated integers representing the share positions of each code in group 2.
Output
Print an integer representing the minimum cost. In case of no output print -1.
Note
The value of N will always be equal to M.
Constraints
1 ≤ numGroup1, numGroup2 ≤ 103
Example
Input:
5
1 2 2 1 3
5
1 1 2 2 3
Output:
6
Explanation:
In the first operation, the share position 3 of group 1 is swapped with the share position 1 of group 1 as both of these positions are similar with respect to their share code in group 2. The cost of operation will be [0 + 4 = 4] 4. Group 1 will be [ 3 2 2 1 1].
In second the operation, the share position 3 will be swapped with the position 2 at share code 2 . The cost of operation will be [0+2 = 2] 2. Now group 1 shares are [2 2 3 1 1 ]. Since all share positions in group 1 with respect to their codes are unequal with group 2 , no further swapping is required.
The minimum cost of the whole process is 4+2 =6 .Therefore, the output is 6.