Vasya decided to go to the grocery store. He found in his wallet $a$ coins of $1$ burle and $b$ coins of $2$ burles. He does not yet know the total cost of all goods, so help him find out $s$ ($s > 0$): the minimum positive integer amount of money he cannot pay without change or pay at all using only his coins.

For example, if $a=1$ and $b=1$ (he has one $1$-burle coin and one $2$-burle coin), then:

he can pay $1$ burle without change, paying with one $1$-burle coin,

he can pay $2$ burle without change, paying with one $2$-burle coin,

he can pay $3$ burle without change by paying with one $1$-burle coin and one $2$-burle coin,

he cannot pay $4$ burle without change (moreover, he cannot pay this amount at all).

So for $a=1$ and $b=1$ the answer is $s=4$.


-----Input-----

The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.

The description of each test case consists of one line containing two integers $a_i$ and $b_i$ ($0 \le a_i, b_i \le 10^8$) — the number of $1$-burle coins and $2$-burles coins Vasya has respectively.


-----Output-----

For each test case, on a separate line print one integer $s$ ($s > 0$): the minimum positive integer amount of money that Vasya cannot pay without change or pay at all.


-----Examples-----

Input
5
1 1
4 0
0 2
0 0
2314 2374
Output
4
5
1
1
7063


-----Note-----

The first test case of the example is clarified into the main part of the statement.

In the second test case, Vasya has only $1$ burle coins, and he can collect either any amount from $1$ to $4$, but $5$ can't.

In the second test case, Vasya has only $2$ burle coins, and he cannot pay $1$ burle without change.

In the fourth test case you don't have any coins, and he can't even pay $1$ burle.

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Greedy algorithms


Solutions:
def solve():
	if n == 0:
		return 1
	return n + 2 * m + 1
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	print(solve())


for s in [*open(0)][1:]:
	(a, b) = map(int, s.split())
	print((2 * b + a) * (a > 0) + 1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a and b or not b:
		print(a * 1 + b * 2 + 1)
	elif not a:
		print(1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == 0:
		print(1)
	else:
		print(a + b * 2 + 1)


results = []
for t in range(int(input())):
	(one, two) = [int(x) for x in input().split()]
	if not one:
		results.append(1)
	else:
		results.append(one + two * 2 + 1)
print(*results, sep='\n')


result = ''
number = int(input())
for x in range(number):
	(a, b) = map(int, input().split())
	if a < 1:
		result += str(1) + '\n'
	else:
		result += str(a + b * 2 + 1) + '\n'
print(result[:-1])


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 0])

def invr():
	return map(int, input().split())
num_test_cases = inp()
for i in range(num_test_cases):
	lis_val = inlt()
	if lis_val[0] == 0:
		print(1)
	else:
		print(lis_val[0] + lis_val[1] * 2 + 1)


from sys import stdin
input = stdin.readline

def get_string():
	return stdin.readline().strip()

def main():
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		if a == 0:
			print(1)
		else:
			print(a * 1 + b * 2 + 1)
main()


import sys
input = sys.stdin.readline

def solve(a, b):
	if a == 0 and b > 0:
		print(1)
		return
	print(a + 2 * b + 1)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	solve(a, b)


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a == 0:
		print(1)
	else:
		s = a + b * 2
		print(s + 1)


def decision(a, b):
	if a == 0:
		return 1
	return a * 1 + b * 2 + 1
t = int(input())
result = []
for i in range(t):
	(a, b) = input().split()
	result.append(decision(int(a), int(b)))
for el in result:
	print(el)


import sys
n = int(sys.stdin.readline())
for i in range(n):
	data = sys.stdin.readline().split()
	a = int(data[0])
	b = int(data[1])
	if a == 0:
		print(1)
	else:
		print(a + 2 * b + 1)


T = int(input())
q = []
for i in range(T):
	(a, b) = input().split()
	q.append((int(a), int(b)))

def solve(a, b):
	if a == 0:
		print(1)
		return
	sol = b * 2 + a + 1
	print(sol)
for (a, b) in q:
	solve(a, b)


k = int(input())
arr = []
for i in range(k):
	para = input().split()
	arr.append(para)
for para in arr:
	a = para[0]
	b = para[1]
	if int(a) == 0:
		print(1)
	elif int(b) == 0:
		print(int(a) + 1)
	elif int(a) != 0 and int(b) != 0:
		print(int(a) + int(b) * 2 + 1)


import sys

def read_numbers():
	return [int(x) for x in sys.stdin.readline().strip().split()]

def solve():
	t = read_numbers()[0]
	for _ in range(t):
		(a, b) = read_numbers()
		if a == 0:
			print(1)
		else:
			print(a + 2 * b + 1)
solve()


import sys

def vasya_and_coins(a: int, b: int) -> int:
	if a == 0:
		return 1
	if b == 0:
		return a + 1
	return b * 2 + a + 1

def main():
	tc = int(sys.stdin.readline())
	for _ in range(tc):
		(a, b) = (int(i) for i in sys.stdin.readline().split())
		sys.stdout.write(str(vasya_and_coins(a, b)) + '\n')
main()


ans = []
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a > 0 and b > 0:
		ans.append(sum([a, b * 2]) + 1)
	elif a == 0 and b == 0:
		ans.append(1)
	elif a == 0:
		ans.append(1)
	elif a > 0 and b == 0:
		ans.append(a + 1)
print(*ans, sep='\n')


t = int(input())
m = []
for i in range(t):
	(b1, b2) = [int(x) for x in input().split()]
	if b1 > 0:
		m.append(b1 + b2 * 2 + 1)
	else:
		m.append(1)
for i in m:
	print(i)


a = int(input())
r = []
for i in range(a):
	(b, c) = list(map(int, input().split()))
	if b > 0 and c > 0:
		r.append(b + c * 2 + 1)
	elif b > 0 and c == 0:
		r.append(b + 1)
	elif b == 0 and c > 0:
		r.append(1)
	elif b == 0 and c == 0:
		r.append(1)
for i in range(len(r)):
	print(r[i])


b = int(input())
n = []
for i in range(b):
	tmp = list(map(int, input().split()))
	for j in tmp:
		n.append(j)
for l in range(0, len(n), 2):
	if n[l] == 0:
		print(1)
	else:
		print(n[l] + n[l + 1] * 2 + 1)


import math
t = int(input())
res = []
for _ in range(t):
	(a, b) = [int(x) for x in input().split(' ')]
	if a == 0:
		res.append(1)
	else:
		res.append(2 * b + a + 1)
for i in range(t):
	print(res[i])


n = int(input())
try:
	mx = []
	while True:
		m = input()
		if m == '':
			break
		m = list(map(int, m.split()))
		mx.append(m)
except:
	pass
s = []
for i in range(n):
	x = mx[i][0]
	y = mx[i][1]
	if x == 0:
		s.append(1)
	elif y == 0:
		s.append(int(x) + 1)
	else:
		s.append(int(x) + 2 * int(y) + 1)
for i in s:
	print(i)


import sys
import math
from sys import stdin, stdout

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(input())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def main():
	for t in range(get_int()):
		(a, b) = get_ints_in_variables()
		if a == 0:
			print(1)
			continue
		elif b == 0:
			print(a + 1)
			continue
		res = a + b * 2
		print(res + 1)
main()


import sys
input = sys.stdin.readline

def ii():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def solve():
	(a, b) = invr()
	if a == 0:
		print(1)
	else:
		print(a + 2 * b + 1)
t = ii()
for i in range(t):
	solve()


import sys

def main():
	input = sys.stdin
	n = int(input.readline())
	for i in range(n):
		ln = input.readline().split()
		(a, b) = (int(ln[0]), int(ln[1]))
		if a == 0:
			print(1)
		else:
			print(2 * b + a + 1)
main()


ml = []
for _ in range(int(input())):
	l = ''
	l = input()
	ml.append(l.split())
for i in ml:
	if int(i[0]) == 0:
		print(1)
	elif int(i[0]) > 0 and int(i[1]) == 0:
		print(int(i[0]) * 1 + 1)
	elif int(i[0]) > 0 and int(i[1]) > 0:
		print(int(i[0]) + int(i[1]) * 2 + 1)


input = open(0).readline
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a == 0:
		print('1')
	else:
		print(a + b * 2 + 1)


from os import read
import sys
input = lambda : sys.stdin.readline()

def read_ints():
	return [int(x) for x in input().split(' ')]

def read_int():
	return int(input())
T = read_int()
ans = []
for _ in range(T):
	(x, y) = read_ints()
	if x == 0:
		ans.append('1')
	else:
		ans.append(str(x + 2 * y + 1))
print('\n'.join(ans))


N = int(input())
lst = []
A = []
B = []
for i in range(N):
	lst = list(map(int, input().split()))
	A.append(lst[0])
	B.append(lst[1])
for i in range(N):
	if A[i] == 0:
		print(1)
	else:
		print(A[i] + 2 * B[i] + 1)


inp = int(input())
lst = []
for i in range(inp):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	lst.append((a, b))

def f(z):
	(x, y) = (z[0], z[1])
	if x == 0:
		return 1
	if y == 0:
		return x + 1
	else:
		return x + 2 * y + 1
res = [f(k) for k in lst]
for e in res:
	print(e)


def coin_calculate():
	c = input()
	z = int(c)
	i = 0
	k = []
	l = []
	while i < z:
		i += 1
		asa = input()
		a = asa.split()
		x = int(a[0])
		y = int(a[1])
		k.append(x)
		l.append(y)
	i = 0
	while i < z:
		if k[i] == 0:
			print(1)
		elif l[i] == 0:
			print(k[i] + 1)
		else:
			print(k[i] + 2 * l[i] + 1)
		i += 1
coin_calculate()


t = int(input())
cases = []
for i in range(t):
	s = input().split(' ')
	cases.append([int(s[0]), int(s[1])])
for (a, b) in cases:
	if a == 0:
		print(1)
		continue
	else:
		print(a + 2 * b + 1)


n = int(input())
money = [list(map(int, input().split())) for i in range(n)]
for i in money:
	if i[0] > 0:
		print(i[0] + i[1] * 2 + 1)
	else:
		print(1)


for a in [*open(0)][1:]:
	(x, y) = map(int, a.split())
	print(1 if x == 0 else x + 2 * y + 1)


n = int(input())

def check(a, b):
	if a == 0:
		s = 1
	else:
		s = a + 2 * b + 1
	return s
c = []
for i in range(n):
	(a, b) = map(int, input().split())
	s = check(a, b)
	c.append(s)
for i in range(len(c)):
	print(c[i])


t = int(input())
ans = []
for i in range(t):
	(a, b) = map(int, input().split())
	if a == 0:
		ans.append(1)
	elif b == 0:
		ans.append(a + 1)
	else:
		ans.append(a + 2 * b + 1)
for elem in ans:
	print(elem)


from sys import stdin

def read_int():
	return int(stdin.readline())

def read_list(_type=int):
	return list(map(_type, stdin.readline().split()))

def read_tuple():
	return stdin.readline().split()

def read_string():
	return stdin.readline().rstrip('\r\n')
for _ in range(read_int()):
	(one, two) = read_list()
	if not one:
		print(1)
	else:
		print(two * 2 + one + 1)


t = int(input())
p = []
for i in range(t):
	l = list(map(int, input().split()))
	a = l[0]
	b = l[1]
	if a == 0 and b != 0:
		p.append('1')
	else:
		x = a + 2 * b
		p.append(x + 1)
for ele in p:
	print(ele)


n = int(input())
c = [0 for i in range(n)]
for i in range(n):
	(a, b) = map(int, input().split())
	if a == 0 and b != 0:
		c[i] = 1
	else:
		c[i] = a + b * 2 + 1
for i in range(n):
	print(c[i])


s = int(input())
d = []
for i in range(s):
	(a, s) = list(map(int, input().split()))
	f = a + s * 2 + 1
	if a == 0 and s != 0:
		d.append(1)
	else:
		d.append(f)
for h in range(len(d)):
	print(d[h])


import sys
import statistics
import math
import datetime
import collections

def function(a, b):
	if a == 0:
		return 1
	else:
		return a + b * 2 + 1

def main():
	t = int(sys.stdin.readline())
	for _ in range(t):
		(a, b) = map(int, sys.stdin.readline().strip().split())
		res = function(a, b)
		print(res)
main()


n = int(input())
h = []
a = []
ans = 0
for i in range(n):
	(hh, aa) = map(int, input().split())
	h.append(hh)
	a.append(aa)
for i in range(len(a)):
	a[i] = a[i] * 2
for i in range(len(h)):
	if h[i] == 0 and a[i] == 0:
		print(1)
	elif h[i] == 0 and a[i] != 0:
		print(1)
	else:
		print(h[i] + a[i] + 1)


T = int(input())
oparr = []
for i in range(T):
	(oneB, twoB) = tuple(map(int, input().split()))
	if oneB > 0:
		oparr.append(twoB * 2 + oneB + 1)
	else:
		oparr.append(1)
for i in oparr:
	print(i)


for i in range(int(input())):
	a = input().split()
	if a[0] == '0':
		print(1)
	else:
		print(int(a[0]) + int(a[1]) * 2 + 1)


test_case = int(input())
a = []
b = []
for i in range(test_case):
	r = input()
	a.append(int(r.split()[0]))
	b.append(int(r.split()[1]))
for i in range(test_case):
	if a[i] > 0:
		print(2 * b[i] + a[i] + 1)
	else:
		print(1)


t = int(input())
res = []
for i in range(t):
	ar = list(map(int, input().split()))
	n = ar[0]
	s = ar[1]
	if n == 0:
		res.append(1)
		continue
	res.append(n + s * 2 + 1)
for el in res:
	print(el)


n = int(input())
inputs = []
for _ in range(n):
	(a, b) = input().split()
	inputs.append([int(a), int(b)])
for (a, b) in inputs:
	if a == 0:
		print(1)
	else:
		print(a * 1 + b * 2 + 1)


n_test_cases = int(input())
results = []
for _ in range(n_test_cases):
	(one_coins, two_coins) = tuple([int(x) for x in input().split()])
	if one_coins == 0:
		results.append(1)
	else:
		results.append(one_coins + 2 * two_coins + 1)
for result in results:
	print(result)


v = int(input())
k = []
l = []
re = 0

def add(a, b):
	if a >= b:
		return a + b * 2 + 1
	elif a >= 1:
		return a + b * 2 + 1
	else:
		return 1
for i in range(v):
	k.append(input().split(' '))
for j in range(v):
	re = add(int(k[j][0]), int(k[j][1]))
	print(re)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
testcase = inp()
for t in range(testcase):
	x = inlt()
	a = x[0]
	b = x[1]
	answer = 0
	if a == 0:
		answer = 1
	elif b == 0 and a == 0:
		answer = 0
	else:
		answer = b * 2 + a + 1
	print(answer)


import math
from collections import defaultdict, deque, Counter
from functools import reduce
from stringprep import in_table_d1
from sys import stdin
import heapq
inf = int(1e+18)
input = stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == 0:
		print(1)
		continue
	print(a + 2 * b + 1)


answer = []
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a == 0:
		answer.append(1)
	elif b == 0:
		answer.append(a + 1)
	else:
		answer.append(a + b * 2 + 1)
print(*answer, sep='\n')


n = int(input())
x = []
for i in range(0, n):
	a = input().split()
	x.append(a)
for i in range(len(x)):
	if int(x[i][0]) == 0:
		print('1')
	else:
		print(int(x[i][0]) + int(x[i][1]) * 2 + 1)


n = int(input())
a = []
for i in range(n):
	l = list(map(int, input().split()))
	a.append(l)
for i in a:
	if i[0] == 0 and i[1] == 0:
		print(1)
	elif i[0] == 0 and i[1] > 0:
		print(1)
	elif i[0] > 0 and i[1] == 0:
		print(i[0] + 1)
	else:
		print(i[0] + 2 * i[1] + 1)


numberofcases = int(input())
walletamount = []
for y in range(numberofcases):
	walletamount.append([])
for x in range(numberofcases):
	walletamount[x] = list(input().split())
for x in range(numberofcases):
	counter = 0
	if int(walletamount[x][0]) == 0 and counter == 0:
		print(1)
		counter = counter + 1
	if int(walletamount[x][0]) > 0 and int(walletamount[x][1]) > 0 and (counter == 0):
		print(int(walletamount[x][0]) * 1 + int(walletamount[x][1]) * 2 + 1)
		counter = counter + 1
	if int(walletamount[x][0]) > 0 and int(walletamount[x][1]) == 0 and (counter == 0):
		print(int(walletamount[x][0]) + 1)
		counter = counter + 1


import math
import sys
import itertools
import fractions
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
for t in wtf[1:]:
	(a, b) = map(int, t.split())
	if a == 0:
		print(1)
	elif b == 0:
		print(a + 1)
	else:
		print(a + 2 * b + 1)


out = []

def change():
	coins = list(map(int, input().split()))
	amt = coins[0] + 2 * coins[1]
	if coins[0] == 0:
		out.append(1)
	else:
		out.append(amt + 1)
iter = int(input())
while iter > 0:
	change()
	iter -= 1
for x in range(0, len(out)):
	print(out[x])


n = int(input())
l = []
for i in range(n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	s = a + 2 * b
	if a == 0:
		l.append(1)
	else:
		l.append(s + 1)
for j in l:
	print(j)


from math import *
from sys import stdin, setrecursionlimit
from itertools import *
from collections import *
setrecursionlimit(10 ** 8)
lines = stdin.readlines()
lines.reverse()

def input():
	return lines.pop().strip('\n')
t = int(input())
while t:
	(a, b) = map(int, input().split())
	if a < 1:
		print(1)
	else:
		print(2 * b + 1 * a + 1)
	t -= 1


answers = []
numofinput = int(input())
for i in range(numofinput):
	[a, b] = list(map(int, input().split()))
	ans = a + b * 2 + 1
	if b != 0:
		if a == 0:
			ans = 1
	answers.append(ans)
for m in answers:
	print(m)


n = int(input())
a = []
for i in range(n):
	(c1, c2) = map(int, input().split())
	a.append(c1 + c2 * 2 + 1 if c1 >= c2 else 1 + c2 * 2 + c1 if c1 > 0 else c1 + 1)
for i in range(n):
	print(a[i])


from sys import stdin, stdout
from collections import Counter, defaultdict
input = stdin.readline
t = int(input().strip())
for _ in range(t):
	(a, b) = list(map(int, input().strip().split()))
	if a == 0:
		print(1)
		continue
	ans = min(a, b) * 3
	if a > b:
		ans += (a - b) * 1
	elif b > a:
		ans += (b - a) * 2
	ans += 1
	print(ans)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def test():
	A = inlt()
	if not A[0]:
		print(1)
	else:
		print(A[0] + 2 * A[1] + 1)

def main():
	t = int(input())
	for i in range(t):
		test()
main()


t = int(input(''))
res = []
for i in range(t):
	st = input('')
	arr = st.split(' ')
	a = int(arr[0])
	b = int(arr[1])
	if b == 0:
		res.append(a + 1)
	elif a == 0:
		res.append(1)
	else:
		res.append(b * 2 + a + 1)
for i in range(len(res)):
	print(res[i])


t = int(input())
a = [0] * t
b = a.copy()
for i in range(t):
	(a[i], b[i]) = list(map(int, input().split()))
for i in range(t):
	if a[i] == 0:
		print(1)
	else:
		print(a[i] + b[i] * 2 + 1)


t = int(input())
ans = []
value = 0
for tests in range(t):
	(a, b) = map(int, input().split())
	if a > 0:
		value = a + 2 * b + 1
		ans.append(value)
	if a == 0:
		value = 1
		ans.append(value)
print(*ans, sep='\n')


n = int(input())
ones = []
twos = []
for i in range(n):
	val = input().split(' ')
	ones.append(int(val[0]))
	twos.append(int(val[1]))
for i in range(len(ones)):
	if ones[i] == 0:
		print(1)
	else:
		print(twos[i] * 2 + ones[i] + 1)


t = int(input())
l = []
for i in range(t):
	l.append(tuple(map(int, input().split())))
sols = []
for item in l:
	ones = item[0]
	twos = item[1]
	total = ones + 2 * twos
	if ones != 0:
		sol = total + 1
	elif total % 2 == 0:
		sol = 1
	sols.append(sol)
for el in sols:
	print(el)


t = int(input())
ans = []
for i in range(t):
	(one, two) = tuple(map(int, input().split()))
	if one == 0 and two != 0:
		ans.append(1)
	elif one != 0 and two == 0:
		ans.append(one + 1)
	else:
		ans.append(one + two * 2 + 1)
for case in tuple(ans):
	print(case)


t = int(input())
A = []
for i in range(t):
	a = [int(p) for p in input().split()]
	A.append(a)
for i in range(t):
	(a, b) = A[i]
	if a == 0 and b != 0:
		print(1)
	else:
		print(a + b * 2 + 1)


t = int(input())
for test in range(t):
	(n, m) = map(int, input().split())
	a = n * 1
	b = m * 2
	if a == 0:
		print(1)
	else:
		print(a + b + 1)


for t in range(int(input())):
	(a, b) = map(int, input().split())
	if a == 0:
		print(1)
	else:
		print(a + 2 * b + 1)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a == 0 and b != 0:
		print(1)
	elif a != 0 and b == 0:
		print(a + 1)
	elif a == 0 and b == 0:
		print(1)
	else:
		print(a + 2 * b + 1)


a = int(input())
for _ in range(a):
	(a, b) = [int(i) for i in input().split()]
	if a == 0:
		print(1)
	elif b == 0:
		print(a + 1)
	else:
		print((a + b) * 2 - a + 1)