Chef is given two integers N, S.

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

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

(A[1]+A[2]+...A[x-1]) + (A[x+1]+A[x+2]+...A[N]) = S

If there are multiple such positions x, print any such position. If there is no such position, print -1.

------ Input Format ------ 

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

------ Output Format ------ 

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

------ Constraints ------ 

$1 ≤ T ≤ 1000$
$2 ≤ N ≤ 10^{9}$
$1 ≤ S ≤ 10^{18}$

----- Sample Input 1 ------ 
3
4 8
5 10
2 3

----- Sample Output 1 ------ 
2
5
-1

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

Test Case $3$: There is no suitable position.

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
for _ in range(int(input())):
	l = input('').split()
	n = int(l[0])
	s = int(l[1])
	if 2 <= n <= 10 ** 9 and 1 <= s <= 10 ** 18:
		z = n ** 2 + n - 2 * s
		if z % 2 == 0 and z != 0 and (1 <= z // 2 <= n):
			print(z // 2)
		else:
			print(-1)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	m = n * (n + 1) // 2
	if 0 < m - s and m - s <= n:
		print(m - s)
	else:
		print(-1)


for t in range(int(input())):
	(n, s) = map(int, input().split())
	x = n * (n + 1) // 2 - s
	if x > 0 and x <= n:
		print(x)
	else:
		print(-1)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	c = n * (n + 1) // 2
	if 0 < c - s <= n:
		print(c - s)
	else:
		print(-1)


T = int(input())
for _ in range(T):
	(N, S) = (int(i) for i in input().split())
	x = N * (N + 1) // 2 - S
	if x in range(1, N + 1):
		print(x)
	else:
		print(-1)


t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	k = n * (n + 1) // 2
	d = k - s
	if s >= k:
		print(-1)
	elif d <= n:
		print(d)
	else:
		print(-1)


T = int(input())
for _ in range(0, T):
	(n, s) = map(int, input().split())
	if s >= n * (n + 1) // 2:
		print(-1)
	elif n * (n + 1) // 2 - s <= n:
		print(n * (n + 1) // 2 - s)
	else:
		print(-1)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	ans = n * (n + 1) // 2
	res = ans - s
	if res >= 1 and res <= n:
		print(res)
	else:
		print(-1)


T = int(input())
for _ in range(T):
	(a, b) = map(int, input().split())
	res = a * (a + 1) // 2
	x = res - b
	if x >= 1 and x <= a:
		print(int(x))
	else:
		print(-1)


def solve(n, s):
	answer = n * (n + 1) // 2
	if answer <= s:
		return -1
	elif answer - s <= n:
		return answer - s
	else:
		return -1
for i in range(int(input())):
	(n, s) = map(int, input().split())
	print(solve(n, s))


t = int(input(''))
if 1 <= t <= 1000:
	for m in range(t):
		l = input('').split()
		n = int(l[0])
		s = int(l[1])
		if 2 <= n <= 10 ** 9 and 1 <= s <= 10 ** 18:
			z = n ** 2 + n - 2 * s
			if z % 2 == 0 and z != 0 and (1 <= z // 2 <= n):
				print(z // 2)
			else:
				print(-1)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	a = n * (n + 1) // 2 - s
	if 1 <= a and a <= n:
		print(a)
	else:
		print(-1)


t = int(input())
for i in range(t):
	(n, s) = list(map(int, input().split()))
	a = n * (n + 1) // 2 - s
	if 1 <= a and a <= n:
		print(a)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split(' '))
	x = n * (n + 1) // 2 - s
	if x < 1 or x > n:
		x = -1
	print(int(x))


t = int(input())
for i in range(t):
	(n, s) = map(int, input().split())
	r = n * (n + 1) // 2 - s
	if r < 1 or r > n:
		print(-1)
	else:
		print(r)


t = int(input())
while t:
	(N, S) = input().split()
	(N, S) = (int(N), int(S))
	ns = N * (N + 1) // 2
	e = ns - S
	if e > 0 and e <= N:
		print(str(e))
	else:
		print('-1')
	t -= 1


def inputs(instr):
	(x, y) = instr.split(' ')
	return (int(x), int(y))
t = int(input())
for _ in range(t):
	(n, s) = inputs(input())
	sn = n * (n + 1) // 2
	x = sn - s
	if x <= n and x > 0:
		print(str(int(x)))
	else:
		print('-1')


import sys

def inputs(instr):
	(x, y) = instr.split(' ')
	return (int(x), int(y))

def println(n):
	return sys.stdout.write(str(n) + '\n')
t = int(input())
for _ in range(t):
	(n, s) = inputs(input())
	sn = n * (n + 1) // 2
	x = sn - s
	if x <= n and x > 0:
		println(int(x))
	else:
		println(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	s = a * (a + 1) // 2
	print(s - b) if 1 <= s - b <= a else print(-1)


for i in range(int(input())):
	(n, r) = list(map(int, input().split()))
	s = n * (n + 1) // 2
	if 1 <= s - r <= n:
		print(s - r)
	else:
		print(-1)


def solve(n, s):
	val = n * (n + 1) // 2
	if s > val:
		return -1
	diff = val - s
	if diff > n:
		return -1
	if n == 2 and s > n:
		return -1
	return diff
for _ in range(int(input())):
	(n, s) = map(int, input().split())
	print(solve(n, s))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	b = abs(n * (n + 1) // 2 - m)
	if b > n or b <= 0:
		print('-1')
	else:
		print(b)


t = input()
for c in range(0, int(t)):
	(n, s) = list(map(int, input().split()))
	a = n * (n + 1) // 2 - s
	if a <= 0 or a > n:
		print('-1')
	else:
		print(a)


for i in range(int(input())):
	(x, y) = map(int, input().split())
	ans = x * (x + 1) // 2
	posi = ans - y
	if posi > 0 and posi <= x:
		print(posi)
	else:
		print('-1')


for i in range(int(input())):
	(a, b) = map(int, input().split())
	ans = a * (a + 1) // 2
	posi = ans - b
	if posi > 0 and posi <= a:
		print(posi)
	else:
		print('-1')


def mi():
	return map(int, input().split())

def li():
	return list(mi())

def si():
	return str(input())

def ni():
	return int(input())
for t in range(int(input())):
	(n, s) = map(int, input().split())
	a = n * (n + 1) // 2
	a -= s
	if a >= 1 and a <= n:
		print(a)
	else:
		print(-1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a * (a + 1) // 2 - b > 0 and a * (a + 1) // 2 - b <= a:
		print(a * (a + 1) // 2 - b)
	else:
		print(-1)


t = int(input())
while t:
	(n, s) = map(int, input().split())
	ans = 0
	sum = n * (n + 1) // 2
	if sum > s:
		ans = sum - s
	if ans >= 1 and ans <= n:
		print(ans)
	else:
		print('-1')
	t -= 1


tests = int(input())
for i in range(tests):
	(n, s) = map(int, input().split())
	total = n * (n + 1) // 2
	target = total - s
	if target <= n and target > 0:
		print(target)
	else:
		print(-1)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	sm = n * (n + 1) // 2
	digit = sm - s
	if 1 <= digit <= n:
		print(digit)
	else:
		print('-1')


t = int(input())
while t:
	(n, s) = map(int, input().split())
	var = n * (n + 1) // 2
	var -= s
	if var < 1 or var > n:
		print(-1)
	else:
		print(var)
	t -= 1


try:
	for _ in range(int(input())):
		(n, b) = map(int, input().split())
		l = n * (n + 1) // 2
		l -= b
		if l < 1 or l > n:
			print(-1)
		else:
			print(l)
except:
	pass


for i in range(int(input())):
	(n, s) = [int(x) for x in input().split()]
	temp = n * (n + 1) // 2
	temp = temp - s
	if temp < 1 or temp > n:
		print(-1)
	else:
		print(temp)


for i in range(int(input())):
	(n, s) = map(int, input().split())
	x = int(n * (n + 1) // 2) - s
	if x >= 1 and x <= n:
		print(x)
	else:
		print('-1')


T = int(input())
for _ in range(T):
	(n, s) = map(int, input().split())
	x = n * (n + 1) // 2 - s
	if 1 <= x <= n:
		print(x)
	else:
		print(-1)


t = int(input())
for i in range(t):
	(n, s) = [int(x) for x in input().split()]
	a = n * (n + 1) // 2
	ip = -1
	if a - s <= n and a - s > 0:
		ip = a - s
	print(ip)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	s1 = n * (n + 1) // 2
	ans = s1 - s
	if 1 <= ans <= n:
		print(ans)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(n, s) = map(int, input().split())
	k = n * (n + 1) // 2
	req = k - s
	if 1 <= req <= n:
		print(req)
	else:
		print(-1)


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, s) = map(int, stdin.readline().split())
	n -= 1
	t = n * (n + 1) // 2
	print(-1 if s < t or s > t + n else t + n - s + 1)


T = int(input())
ans = []
for i in range(0, T):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	c = a * (a + 1) // 2 - b
	if c <= a and c > 0:
		ans.append(c)
	else:
		ans.append(-1)
for i in ans:
	print(i)


T = int(input())
for i in range(T):
	(a, b) = map(int, input().split())
	op = a * (a + 1) // 2 - b
	if op >= 1 and op <= a:
		print(op)
	else:
		print(-1)


for M in range(int(input())):
	(x, y) = map(int, input().split())
	l = x * (x + 1) // 2
	t = l - y
	if t <= x and t >= 1:
		print(t)
	else:
		print(-1)


t = int(input())
for jj in range(t):
	(n, s) = map(int, input().split())
	nsum = n * (n + 1) // 2
	if nsum <= s or nsum - s > n:
		print('-1')
	else:
		print(nsum - s)


for i in range(int(input())):
	(n, s) = map(int, input().split())
	ans = n * (n + 1) // 2
	posi = ans - s
	if posi > 0 and posi <= n:
		print(posi)
	else:
		print('-1')


tc = int(input())
for i in range(tc):
	(n, s) = list(map(int, input().split()))
	total_sum = n * (n + 1) // 2
	x = int(total_sum - s)
	if x <= 0 or x > n:
		print(-1)
	else:
		print(x)


MOD = 1000000007

def solve():
	(n, s) = [int(i) for i in input().strip().split()]
	sm = n * (n + 1) // 2
	ans = sm - s
	return ans if 1 <= ans and ans <= n else -1
t = int(input())
for _ in range(t):
	print(solve())


test_case = int(input())
for _ in range(test_case):
	(n, s) = map(int, input().split())
	summ = n * (n + 1) // 2
	new = summ - s
	if new <= n and new > 0:
		print(new)
	else:
		print(-1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = n * (n + 1) // 2 - k
	if l <= n and l > 0:
		print(l)
	else:
		print(-1)


for _ in range(int(input())):
	(N, S) = map(int, input().split())
	Sumx = N * (N + 1) // 2
	if 1 <= Sumx - S <= N:
		print(Sumx - S)
	else:
		print(-1)


cases = int(input())
for i in range(cases):
	(N, S) = map(int, input().split(' '))
	Sum = N * (N + 1) // 2
	val = Sum - S
	if val >= 1 and val <= N:
		print(val)
	else:
		print(-1)


for _ in range(int(input())):
	(n, s) = tuple(map(int, input().split(' ')))
	pos = n * (n + 1) // 2 - s
	if pos >= 1 and pos <= n:
		print(int(pos))
	else:
		print(-1)


for _ in range(int(input())):
	(n, s) = map(int, input().split())
	x = n * (n + 1) // 2
	ans = -1
	if x - s >= 1 and x - s <= n:
		ans = x - s
	print(ans)


for z in range(int(input())):
	(n, s) = map(int, input().split())
	a = n * (n + 1) // 2 - s
	if a <= n and a > 0:
		print(a)
	else:
		print(-1)