Obtain the Sum solution codechef- Chef is given two integers N,SN,S. Consider an array AA of size NN such that A[i]=iA[i]=i for every 1≤i≤N1≤i≤N. You are required to find any position x(1≤x≤N)x(1≤x≤N) such that :

Obtain the Sum solution codechef

Chef is given two integers N,SN,S.

Consider an array AA of size NN such that A[i]=iA[i]=i for every 1iN1≤i≤N.

You are required to find any position x(1xN)x(1≤x≤N) such that :

(A[1]+A[2]+...A[x1])+(A[x+1]+A[x+2]+...A[N])=S(A[1]+A[2]+…A[x−1])+(A[x+1]+A[x+2]+…A[N])=S

If there are multiple such positions xx, print any such position. If there is no such position, print 1−1.

Input Format

  • First line will contain TT, number of testcases. Then the testcases follow.
  • Each testcase contains of a single line of input, two integers N,SN,S.

Output Format

For each testcase, output the required position or 1−1 in case there is no such position.

Constraints

  • 1T10001≤T≤1000
  • 2N1092≤N≤109
  • 1S10181≤S≤1018

Sample Input 1 

3
4 8
5 10
2 3

Sample Output 1 

2
5
-1

Explanation

Test Case 11: A[1]+A[3]+A[4]=1+3+4=8A[1]+A[3]+A[4]=1+3+4=8, so x=2x=2 is a suitable position.

Test Case 33: There is no suitable position.

Leave a Comment