It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are n
should be held.
The rent cost is for the i
-th display is ci. Please determine the smallest cost Maria Stepanovna should pay.
The first line contains a single integer n
) — the number of displays.
The second line contains n
integers s1,s2,…,sn (1≤si≤109) — the font sizes on the displays in the order they stand along the road.
The third line contains n
integers c1,c2,…,cn (1≤ci≤108) — the rent costs for each display.
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices i<j<k
.
5 2 4 5 4 10 40 30 20 10 40
90
3 100 101 100 2 4 5
-1
10 1 2 3 4 5 6 7 8 9 10 10 13 11 14 15 12 13 13 18 13
33
In the first example you can, for example, choose displays 1