There are children in a kindergarten, and each child considers one child to be their best friend. Children are quite unusual, so it holds that no two children consider the same child their best friend, but it is possible that a child is a best friend to themself! Additionally, if child is best friend of child , is not necessarily best friend of child .
The kindergarten teacher has bags of candy that she wishes to distribute to the children such that each child gets exactly one bag. However, the problem is that the bags don't necessarily contain the same amounts of candy, so the children can become displeased. Since the children have a very developed sense of justice, the dissatisfaction of child is equal to the absolute difference between the number of candy and their best friend received.
The kindergarten teacher has decided to distribute the bags so that the maximal dissatisfaction of a child is as small as possible. Help her determine the optimal distribution of candy bags!
Input Specification
The first line of input contains the integer .
The second line of input contains distinct integers, whereas the number is the label of the best friend of the child. The children are labelled with numbers from to .
The third line of input contains integers, whereas the number is equal to the number of candy in the bag. The numbers won't exceed .
Output Specification
The first line of output must contain the minimum possible maximal dissatisfaction of a child.
The second line of output must contain numbers, separated by space, whereas the number denotes the number of candy for the child. If there are multiple optimal distributions, output any.
Scoring
In test cases worth of total points, the best friend of the child will be the child for all , and the best friend of the child will be the first child.
In additional test cases worth of total points, it will hold .
Sample Input 1
3
2 1 3
3 8 5
Sample Output 1
2
5 3 8
Sample Input 2
5
3 5 4 1 2
24 45 39 19 16
Sample Output 2
8
16 39 24 19 45
Sample Input 3
8
6 3 7 1 4 8 2 5
6 5 2 4 7 4 4 3
Sample Output 3
2
3 4 4 4 6 5 2 7
Comments