#P17188. [ICPC 2017 Hong Kong R] Sets
[ICPC 2017 Hong Kong R] Sets
Problem Description
For a fixed number , we define as the set of integers . And for any , we define as a set containing all sums of two different numbers in .
For example, if , we have
$$\begin{matrix} S_1 & = &\{1,2,3\},\\ S_2 & = &\{3,4,5\},\\ S_3 & = &\{7,8,9\},\\ S_4 & = &\{15, 16, 17\}.\\ \end{matrix}$$Then, we sort each set respectively, and combine them in order into a sequence . In the above case, we have the sequence .
Now, given integers and , what is the -th number in sequence ?
Input Format
The input file contains several test cases, please handle it to the end of file.
For each case, there is only one line containing two integers and (). When , the input satisfies that .
Output Format
For each case, output one integer indicating the -th number of the sequence. Output if it does not exist.
4 6
2 20
4
-1