Chef and his girlfriend are going to have a promenade. They are walking along the straight road which consists of segments placed one by one. Before walking Chef and his girlfriend stay at the beginning of the first segment, they want to achieve the end of the last segment. 
There are few problems: 

-  At the beginning Chef should choose constant integer - the velocity of mooving. It can't be changed inside one segment. 
-  The velocity should be decreased by at least 1 after achieving the end of some segment. 
-  There is exactly one shop on each segment. Each shop has an attractiveness. If it's attractiveness is W and Chef and his girlfriend move with velocity V then if V < W girlfriend will run away into the shop and the promenade will become ruined. 

Chef doesn't want to lose her girl in such a way, but he is an old one, so you should find the minimal possible velocity at the first segment to satisfy all conditions.


-----Input-----
- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains a single integer N denoting the number of segments. The second line contains N space-separated integers W1, W2, ..., WN denoting the attractiveness of shops. 

-----Output-----
- For each test case, output a single line containing the minimal possible velocity at the beginning.

-----Constraints-----
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 10^5
- 1 ≤ Wi ≤ 10^6

-----Example-----
Input:

2
5
6 5 4 3 2
5
3 4 3 1 1

Output:

6
5

-----Explanation-----
Example case 1. 
If we choose velocity 6, on the first step we have 6 >= 6 everything is OK, then we should decrease the velocity to 5 and on the 2nd segment we'll receive 5 >= 5, again OK, and so on. 
Example case 2. 
If we choose velocity 4, the promanade will be ruined on the 2nd step (we sould decrease our velocity, so the maximal possible will be 3 which is less than 4).

Difficulty: EASY
Tags: Constructive algorithms

Ad-hoc

Starter code:

Solutions:
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	for i in range(n):
		if s < a[i] + i:
			s = a[i] + i
	print(s)


t = int(input())
for tc in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	v = 0
	c = []
	for j in l[::-1]:
		if v <= j:
			v = j
		v += 1
	print(v - 1)


for _ in range(int(input())):
	n = int(input())
	w = list(map(int, input().split()))
	count = 0
	for j in range(n):
		p = j + w[j]
		if p > count:
			count = p
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = []
	for i in range(n):
		c.append(a[i] + i)
	print(max(c))


for i in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	for i in range(n):
		x[i] += i
	print(max(x))


t = int(input())
for i in range(0, t):
	n = int(input())
	l = list(map(int, input().split()))
	m = l[0]
	for i in range(0, n):
		v = l[i] + i
		if v > m:
			m = v
	print(m)


for _ in range(int(input())):
	n = int(input())
	wl = list(map(int, input().split()))
	v = 0
	v_max = 0
	for i in range(len(wl)):
		if wl[i] > v:
			v_max += wl[i] - v
			v = wl[i]
		v -= 1
	print(v_max)


for _ in range(int(input())):
	n = int(input())
	ar = [int(x) for x in input().split()]
	an = max(ar)
	d = 1
	for i in range(1, n):
		if an - d < ar[i]:
			an += ar[i] - (an - d)
		d += 1
	print(an)


def solve(n, lst):
	l = []
	for i in range(n):
		l.append(lst[i] + i)
	print(max(l))
for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	solve(n, lst)


for i in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		if ans < x[i] + i:
			ans = x[i] + i
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	w = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		ans = max(ans, i + w[i])
	print(ans)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = max(a)
	c = m
	j = 0
	while j < n:
		if a[j] < c:
			c -= 1
			j += 1
		else:
			c += 1
			m = m + 1
	print(m - 1)


for _ in range(int(input())):
	n = int(input())
	velo = list(map(int, input().split()))
	v = velo[0]
	n = v
	yes = 0
	count = 0
	for i in range(len(velo)):
		if v < velo[i]:
			n += velo[i] - v
			yes = 1
			v = n - i
		v -= 1
	print(n)


t = int(input())
while t:
	t = t - 1
	n = int(input())
	l = list(map(int, input().split()))
	l.reverse()
	c = 0
	for i in range(n):
		if c >= l[i]:
			pass
		else:
			c = l[i]
		c = c + 1
	print(c - 1)


a = int(input())
for i in range(a):
	c = int(input())
	b = list(map(int, input().split()))
	for j in range(0, c):
		b[j] = b[j] + j
	print(max(b))


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = 0
	for i in range(len(l)):
		if s < l[i] + i:
			s = l[i] + i
	print(s)


t = int(input())
while t > 0:
	n = int(input())
	l = list(map(int, input().split()))
	ans = l[0]
	for i in range(1, n):
		ans = max(ans, l[i] + i)
	print(ans)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	m = l[0]
	index = 0
	for i in range(len(l) - 1, -1, -1):
		if l[i] + i > m:
			index = i
			m = l[i] + i
	print(m)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.reverse()
	ans = 0
	for i in range(n):
		if l[i] <= ans:
			ans += 1
		else:
			ans = l[i]
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	wlist = list(map(int, input().split()))
	maxi = 0
	for j in range(0, n):
		if wlist[j] + j > maxi:
			maxi = wlist[j] + j
	print(maxi)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	ans = 0
	for i in range(n - 1, -1, -1):
		ans = max([a[i], ans + 1])
	print(ans)


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	res = []
	for i in range(n):
		res.append(arr[i] + i)
	print(max(res))


t = int(input())
for j in range(t):
	n = int(input())
	w = list(map(int, input().split()))
	add = []
	for i in range(n):
		add.append(w[i] + i)
	ans = max(add)
	print(ans)


T = int(input())
for i in range(T):
	N = int(input())
	W = list(map(int, input().split()))
	velocity = max(W)
	index = W.index(velocity)
	V = velocity + index
	for i in range(N):
		if V < W[i] + i:
			V = W[i] + i
	print(V)


for tc in range(int(input())):
	n = int(input())
	w = list(map(int, input().split()))
	maxp = 0
	for i in range(n):
		p = i + w[i]
		if p > maxp:
			maxp = p
	print(maxp)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	for j in range(1, n):
		l[j] = l[j] + j
	print(max(l))


a = int(input(''))
for i in range(a):
	x = int(input(''))
	t = [int(x) for x in input('').split()]
	k = list(t)
	c = 0
	for j in range(x):
		p = j + k[j]
		if p >= c:
			c = p
	print(c)


for i in range(int(input())):
	num = int(input())
	temp = num
	li = list(map(int, input().split()))
	gre = []
	for j in li:
		ans = j - num
		gre.append(ans)
		num -= 1
	if max(gre) > 0:
		print(temp + max(gre))
	else:
		print(temp)


t = int(input())
for i in range(t):
	N = int(input())
	W = list(map(int, input().split()))
	(i, v0) = (0, W[0])
	while i < N - 1:
		v_new = v0 - 1
		if v_new - i < W[i + 1]:
			v0 = W[i + 1] + (i + 1)
		i += 1
	print(v0)


t = int(input())
while t > 0:
	n = int(input())
	array = list(map(int, input().split()))
	array1 = []
	for i in range(n):
		array1.append(array[i] + i)
	print(max(array1))
	t -= 1


for _ in range(int(input())):
	N = int(input())
	W = [int(i) for i in input().split()]
	WNew = [W[i] + i for i in range(N)]
	maxWNew = WNew[0]
	for i in range(1, N):
		if WNew[i] > maxWNew:
			maxWNew = WNew[i]
	print(maxWNew)


T = int(input())
ans = []
for _ in range(T):
	N = int(input())
	W = [int(i) for i in input().split()]
	for i in range(N):
		W[i] += i
	ans.append(max(W))
for i in ans:
	print(i)


T = int(input())
for t in range(T):
	n = int(input())
	a = map(int, input().split(' '))
	print(max((i + e for (i, e) in enumerate(a))))


num = int(input())
for j in range(0, num):
	n = int(input())
	l = list(map(int, input().split()))
	l.reverse()
	ini = 0
	for i in range(0, len(l)):
		if l[i] <= ini:
			ini = ini + 1
		elif l[i] > ini:
			ini = l[i]
	print(ini)


for _ in range(int(input())):
	vvvv = int(input())
	wwww = list(map(int, input().split()))
	zero = 0
	ib = 0
	for maxi in range(vvvv):
		zero = max(zero, wwww[maxi] + maxi)
	print(zero)


for _ in range(0, int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = []
	for i in range(0, n):
		a.append(i + l[i])
	a.sort(reverse=True)
	print(a[0])


for _ in range(int(input())):
	n = int(input())
	w = [int(j) for j in input().split()]
	res = 0
	curr = 0
	for i in range(n):
		curr = i + w[i]
		res = max(curr, res)
	print(res)


for i in range(int(input())):
	N = int(input())
	W = list(map(int, input().split()))
	C = []
	for i in range(N):
		C.append(W[i] + i)
	print(max(C))


for _ in range(int(input())):
	ans = 0
	n = int(input())
	a = [*map(int, input().split())]
	for i in range(n):
		ans = max(ans, i + a[i])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a = a[::-1]
	m = 0
	b = [i for i in a]
	for i in range(1, n):
		b[i] = b[i - 1] + 1
	for i in range(n):
		m = max(m, a[i] - b[i])
	print(max(b[n - 1] + m, b[n - 1]))


T = int(input())
for r in range(T):
	N = int(input())
	l = list(map(int, input().split()))
	l_plus = []
	for j in range(N):
		sum = 0
		sum = l[j] + j
		l_plus.append(sum)
	vel = max(l_plus)
	print(vel)


t = int(input())
for _ in range(t):
	n = int(input())
	m = list(map(int, input().split()))
	(temp, speed) = (m[0], m[0])
	for i in range(1, n):
		if temp < m[i]:
			speed += m[i] - temp
			temp = speed - i - 1
		else:
			temp -= 1
	print(speed)


T = int(input())
for i in range(T):
	x = int(input())
	l = [int(x) for x in input().split()]
	t = []
	for i in range(len(l)):
		t.append(l[i] + i)
	print(max(t))


a = int(input())
for i in range(a):
	n = int(input())
	l = list(map(int, input().split(' ')))
	val = 0
	for i in range(n):
		val = max(val, l[i] + i)
	print(val)


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))[::-1]
	speed = -1
	for i in x:
		speed += 1
		if speed < i:
			speed = i
	print(speed)


for _ in range(0, int(input())):
	x = int(input())
	l = list(map(int, input().split()))
	k = 0
	for i in range(x):
		k = max(k, l[i] + i)
	print(k)


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	maxx = []
	for i in range(n):
		maxx.append(lis[i] + i)
	print(max(maxx))


for i in range(int(input())):
	a = int(input())
	l = list(map(int, input().split()))
	k = 0
	for i in range(a):
		k = max(k, l[i] + i)
	print(k)


for _ in range(int(input())):
	input()
	a = list(map(int, input().split()))
	print(max((a[i] + i for i in range(len(a)))))


for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	l.reverse()
	x = l[0]
	x = x + 1
	for i in range(1, n):
		x = max(x, l[i])
		x = x + 1
	print(x - 1)


t = int(input())
while t:
	t -= 1
	n = int(input())
	L = [int(x) for x in input().split()]
	L.reverse()
	count = 0
	for i in range(n):
		if L[i] > count:
			count = L[i]
		count += 1
	print(count - 1)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = l[::-1]
	curr = l1[0]
	l1.remove(l1[0])
	for x in l1:
		curr += 1
		if curr >= x:
			pass
		else:
			curr += x - curr
	print(curr)


for _ in range(int(input())):
	n = int(input())
	w = list(map(int, input().split()))
	l = []
	for i in range(n):
		l.append(i + w[i])
	print(max(l))


for tc in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	v = 0
	for ele in arr[::-1]:
		if v <= ele:
			v = ele
		v += 1
	print(v - 1)


for _ in range(int(input())):
	k = int(input())
	l = [int(i) for i in input().split()]
	c = []
	for i in range(k):
		c.append(l[i] + i)
	print(max(c))


case = int(input())
for i in range(case):
	n = int(input())
	ls = list(map(int, input().split()))
	ls.reverse()
	cnt = 0
	for j in range(n):
		if cnt >= ls[j]:
			pass
		else:
			cnt = ls[j]
		cnt += 1
	print(cnt - 1)


for _ in range(int(input())):
	len1 = int(input())
	i = 0
	list2 = []
	list1 = [int(x) for x in input().split()]
	for i in range(len1):
		list2.append(list1[i] + i)
	print(max(list2))


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	total = 0
	for i in range(len(arr)):
		if i + arr[i] > total:
			total = i + arr[i]
	print(total)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	for i in range(len(l)):
		ans = max(l[i] + i, ans)
	print(ans)


t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	w = list(map(int, input().strip().split(' ')))
	ans = 0
	for i in range(len(w)):
		ans = max(w[i] + i, ans)
	print(ans)


def find(arr):
	hello = []
	for i in range(len(arr)):
		hello.append(arr[i] + i)
	return max(hello)
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	print(find(arr))


T = int(input())
for _ in range(T):
	N = int(input())
	W = list(map(int, input().split()))
	m = 0
	for i in range(N):
		m = max(m, W[i] + i)
	print(m)


for _ in range(int(input())):
	x = int(input())
	l = list(map(int, input().split()))
	a = max(l)
	c = []
	for i in range(x):
		c.append(l[i] + i)
	print(max(c))


for _ in range(int(input())):
	n = int(input())
	w = list(map(int, input().split()))
	x = 0
	for i in range(n):
		x = max(x, w[i] + i)
	print(x)


def main():
	for _ in range(int(input())):
		N = int(input())
		A = list(map(int, input().split(' ')))[:N]
		ans = 0
		for i in range(N):
			if ans < A[i] + i:
				ans = A[i] + i
		print(ans)
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split()))
	mx = 0
	sm = []
	for i in range(0, n):
		sm.append(i + a[i])
		if mx < sm[i]:
			mx = sm[i]
	print(mx)


n = int(input())
inputs = []
for i in range(n):
	input()
	inputs.append(list(map(int, input().split())))

def answer(l):
	maximum = max(l)
	maximums = list(filter(lambda x: l[x] == maximum, range(len(l))))
	result = maximum + maximums[-1]
	tmp = maximums[-1]
	for i in range(maximums[-1] + 1, len(l)):
		if i - tmp > l[tmp] - l[i]:
			result += l[i] - (l[tmp] - (i - tmp))
			tmp = i
	return result
for i in inputs:
	print(answer(i))


t = int(input())
for i in range(t):
	n = int(input())
	w = list(map(int, input().split()))[:n]
	c = []
	for i in range(n):
		c.append(w[i] + i)
	print(max(c))


t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	l.reverse()
	for i in range(n):
		if l[i] <= ans:
			ans += 1
		elif l[i] > ans:
			ans = l[i]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr_w = list(map(int, input().split()))
	for i in range(1, n):
		arr_w[i] += i
	print(max(arr_w))


t = int(input())
for i in range(t):
	n = int(input())
	w = list(map(int, input().split()))
	for j in range(1, n):
		w[j] = w[j] + j
	print(max(w))


for _ in range(int(input())):
	n = int(input())
	arr = reversed(list(map(int, input().split())))
	speed = -1
	for i in arr:
		speed += 1
		if speed < i:
			speed = i
	print(speed)


t = int(input())
while t != 0:
	n = int(input())
	l = list(map(int, input().split()))
	s = l[-1] + 1
	for k in range(-2, -1 * n - 1, -1):
		if l[k] > s:
			s = l[k]
		s += 1
	print(s - 1)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	w = list(map(int, input().split()))
	init = w[0]
	rem = w[0]
	for i in range(n):
		if rem < w[i]:
			init += w[i] - rem
			rem += w[i] - rem
		rem -= 1
	print(init)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = 0
	for i in range(n):
		if l[i] + i > m:
			m = l[i] + i
	print(m)


for _ in range(int(input())):
	n = int(input())
	w = list(map(int, input().split()))
	add = []
	for i in range(n):
		add.append(w[i] + i)
	ans = max(add)
	print(ans)


t = input()
for c in range(0, int(t)):
	n = input()
	w = input().split()
	arr = []
	for x in w:
		arr.append(int(x))
	mi = 0
	for y in range(0, int(n)):
		if arr[y] + y > mi:
			mi = arr[y] + y
	print(mi)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = 0
	for i in range(n):
		if x < a[i] + i:
			x = a[i] + i
	print(x)


for _ in range(int(input())):
	N = int(input())
	arr = list(map(int, input().split()))
	s = []
	for i in range(len(arr)):
		s.append(arr[i] + i)
	print(max(s))


for _ in range(int(input())):
	n = int(input())
	w = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		if ans < w[i] + i:
			ans = w[i] + i
	print(ans)