Consider a strictly-increasing sequence of integers a1,a2,…,ak. Alice picked a continuous sequence p1,p2,…,pn from it.
Bob then removed exactly n−m numbers from this sequence, while maintaining the relative order of the remaining elements, thus obtaining a sequence q1,q2,…,qm. He then subtracted q1 from all the elements to form the final sequence b1,b2,…,bm.
For example, let {ai}={2,3,5,7,11,13,17,19,23,29,31},p1=11,n=6,m=4. This yields the sequence of primes p={11,13,17,19,23,29}. Assume that Bob has removed the numbers 17 and 23 to obtain q={11,17,19,29}. After that, he subtracted 11 from every element to get b={0,6,8,18}.
Alternatively, he could have removed 11 and 29 to obtain the sequence q={13,17,19,23} and b={0,4,6,10}. Note that the same sequence may also be generated by, for instance, picking p={13,17,19,23,29,31} and removing 29 and 31.
Eve found the number n and the sequences {ai}ki=1, {bi}mi=1. She now wonders, what is the smallest possible p1, that could yield the sequence {bi}mi=1 through the process described above?
Input format:
It is guaranteed that there always exists a solution.
Output:
For each test case, output a single integer p1 - the smallest element in the sequence that Alice chose.
Scoring:
In all test sets, 1≤t≤10.
In the first test set, worth 12 points, 1≤m=n≤102 and k≤104.
In the second test set, worth 21 points, 1≤m<n≤102 and k≤104.
In the third test set, worth 24 points, 1≤m=n≤105 and k≤2∗105.
In the fourth test set, worth 25 points, 1≤m≤n≤105, n−m≤50 and k≤2∗105.
In the fifth test set, worth 18 points,t=3, 1≤m≤n≤5∗105, n−m≤100 and k≤106.
This is the example from the statement.