In Mirko's village, all fences are made of exactly
Each board is represented by a positive integer less than
Mirko already bought the boards, but he doesn't know how to order them into a fence. He would like his fence to be similar to Slavko's fence, but also to be as nice as possible.
We say that two fences are similar if the ordering of adjacent boards is the same in both fences, i.e. if
Given Slavko's fence configuration, and the heights of boards that Mirko bought, put Mirko's fence together so that it is similar to Slavko's but also as nice as possible. If there is more than one solution, output any of them.
Input Specification
The first line of input contains integer
The following line contains
The following line contains
Output Specification
The first line of output should contain the maximum possible niceness of Mirko's fence.
The following line should contain
Scoring
Sample Input 1
4
5 7 4 9
1 2 3 4
Sample Output 1
7
2 4 1 3
Explanation for Sample Output 1
Mirko bought boards of heights
Sample Input 2
10
9 5 1 2 6 7 4 18 20 12
10 40 20 30 50 70 80 100 1000 500
Sample Output 2
3010
100 80 10 40 50 1000 20 70 500 30
Comments