#arc146d. [arc146_d]>=<
[arc146_d]>=<
Problem Statement
A fantastic IS is an integer sequence of length whose every element is between and (inclusive) that satisfies the following condition.
- For every integer such that , one of the following holds.
- and ;
- and ;
- and .
Determine whether a fantastic IS exists. If it does, find the minimum possible sum of the elements in a fantastic IS.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If a fantastic IS exists, print the minimum possible sum of the elements in a fantastic IS; otherwise, print .
Sample Input 1
3 4 3
3 1 1 2
1 1 2 2
3 4 1 4
Sample Output 1
6
fully satisfies the condition and thus is a fantastic IS, whose sum of the elements is .
There is no fantastic IS whose sum of the elements is less than , so the answer is .
Sample Input 2
2 2 2
1 1 2 2
2 1 1 2
Sample Output 2
-1
There is no fantastic IS, so should be printed.
Sample Input 3
5 10 10
4 1 2 7
5 1 3 2
2 9 4 4
5 4 2 9
2 9 1 9
4 8 3 10
5 7 1 5
3 5 1 2
3 8 2 10
2 9 4 8
Sample Output 3
12