Imagine a planet with two beautiful islands. Each island is decorated with several cities, and they are connected by a network of bidirectional roads. The cost of traveling through each road is provided. Both the islands have equal number of cities and roads.
You are given two arrays, and , where represents the beauty index associated with the cities on Island , and represents the beauty index associated with the cities on Island .
To journey from a city on Island to a city on Island , there exists special unidirectional flights. However, specific conditions must be met:
Your task is to calculate the minimum cost required to travel from city on Island to city on Island . If it is not possible to travel from city to city based on the given conditions, you should output , indicating an incompatible connection.
Input format
Output format
For each testcase, output an integer, the minimum cost required to travel from city in island to city in island. Or print if it's an incompatible connection in a new line.
Constraints
3 5 7 1 2 3 4 5 10 9 8 7 6 1 2 1 1 3 3 1 4 10 1 5 5 2 5 4 2 4 2 3 4 3 1 5 1 2 4 2 2 5 1 3 1 3 3 2 4 3 4 5 3 5 1 4 5 3 2 1 1 1 1 1 1 1 2 1 2 3 1 1 3 1 2 1 1 2 3 4 2 1 1 1 1 1 1 1 1 1 2 1 1 4 1 1 2 1 1 4 1 3 4