Read problems statements in Mandarin Chinese and Russian as well. 

There are N+1 lights. Lights are placed at  (0, 0), (1, 0), (2, 0) ... (N, 0). Initially all the lights are on. You want to turn off all of them one after one.  You want to follow a special pattern in turning off the lights. 

You will start at (0, 0). First, you walk to the right most light that is on, turn it off. Then you walk to the left most light that is on, turn it off. Then again to the right most light that is on and so on. You will stop after turning off all lights. You want to know how much distance you walked in the process. Note that distance between (a,0) and (b,0) is |a-b|.

------ Input ------ 

The first line of the input contains an integer T denoting the number of test cases. Each test case has a single integer N on separate line.

------ Output ------ 

For each test case, output the distance you walked.

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

$1 ≤ T ≤ 10^{5}
$$1 ≤ N ≤ 10^{5}

----- Sample Input 1 ------ 
2
1
2
----- Sample Output 1 ------ 
2
5
----- explanation 1 ------ 
Testcase #2
You are initially at (0, 0)
Right most on-light is (2, 0). Distance = 2.
Now you are at (2, 0).
Left most on-light is (0, 0). Distance = 2.
Now you are at (0, 0)
Right most on-light is (1, 0). Distance = 1.
Now you are at (1, 0) and all lights are turned off.
Total distance walked = 5.

Difficulty: EASY
Tags: Dynamic programming

Constructive algorithms

Ad-hoc
Skill types: Dynamic programming

Starter code:

Solutions:
import sys
dp = {}

def calculate_dist(left, right):
	global dp
	if left == right:
		return 0
	if left >= right:
		return 0
	else:
		if (left, right) in dp.keys():
			return dp[left, right]
		d1 = abs(right - left)
		left = left + 1
		d2 = abs(right - left)
		dist = d1 + d2
		res = dist + calculate_dist(left, right - 1)
		dp[left, right] = res
		return res

def calculate_large(left, right):
	d1 = abs(right - left)
	left = left + 1
	d2 = abs(right - left)
	dist = d1 + d2
	first_term = dist % 4
	d = 4
	last_term = dist
	number_n = int((last_term - first_term) / 4 + 1)
	final_sum = number_n / 2 * (last_term + first_term)
	return int(final_sum)

def calculate_codeshef(n):
	return int((n + 1) * (n + 2) / 2 - 1)
t = int(input())
for _ in range(t):
	n = int(input())
	left = 0
	right = n
	if n == 1:
		print(2)
	else:
		res = abs(right - left) * 2 + calculate_large(left, right - 1)
		print(res)


for _ in range(int(input())):
	n = int(input())
	print(int(n + n * (n + 1) / 2))


for I in range(int(input())):
	n = int(input())
	p = 2 * n + n * (n - 1) // 2
	print(p)


def Distance(a):
	return a + a * (a + 1) // 2
T = int(input())
for i in range(T):
	N = int(input())
	print(Distance(N))


t = input()
for c in range(0, int(t)):
	n = int(input())
	print(n * (n + 1) // 2 + n)


def result(n):
	return n * (n + 1) // 2
test = int(input())
for i in range(test):
	x = int(input())
	print(x * 2 + result(x - 1))


for i in range(int(input())):
	n = int(input())
	dist = n + (n + 1) * n // 2
	print(dist)


t = int(input())
for i in range(t):
	n = int(input())
	print(int(n * (n + 1) / 2 + n))


t = int(input())
for _ in range(t):
	n = int(input())
	k = n * (n + 3) // 2
	print(k)


for i in range(int(input())):
	x = int(input())
	y = x - 1
	print(2 * x + y * (y + 1) // 2)


n = int(input())
for i in range(n):
	m = int(input())
	k = m + m * (m + 1) / 2
	print(int(k))


for i in range(int(input())):
	num = int(input())
	print(int(num + num * (num + 1) / 2))


for _ in range(int(input())):
	n = int(input())
	print(int(n * (n + 3) / 2))


T = int(input())
for i in range(T):
	n = int(input())
	res = n * 2
	res += (n - 1) * n // 2
	print(res)


def f(n):
	return int(n * (n + 1) / 2 + n)
T = int(input())
while T > 0:
	T -= 1
	n = int(input())
	print(f(n))


for _ in range(int(input())):
	N = int(input())
	print(N + N * (N + 1) // 2)


for t in range(int(input())):
	n = int(input())
	p = n * (n + 1) * 0.5 + n
	print(int(p))


def solve(n):
	return n * (n + 1) // 2 + n
for _ in range(int(input())):
	print(solve(int(input())))


for T in range(int(input())):
	n = int(input())
	print(n * (n + 1) // 2 + n)


for t in range(int(input())):
	n = int(input())
	if n >= 1:
		a = (n + 1) * (n + 2) // 2
		d = a - 1
		print(d)


for i in range(int(input())):
	n = int(input())
	if n == 1:
		print('2')
	else:
		print(n * (n + 3) // 2)


t = int(input())
for _ in range(t):
	n = int(input())
	sum1 = n * (n + 1) // 2
	print(sum1 + n)


T = int(input())
for i in range(T):
	n = int(input())
	ans = n
	ans = n * (n + 1) // 2
	print(ans + n)


a = int(input())
for i in range(0, a):
	n = int(input())
	ans = int(n * (n + 1) / 2 + n)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = n * (n + 1) * 0.5 + n
	print(int(s))


for _ in range(int(input())):
	a = int(input())
	print(a * (a + 1) // 2 + a)


t = int(input())
while t > 0:
	n = int(input())
	print(n * (n + 1) // 2 + n)
	t -= 1


intInp = lambda : int(input())
lstImp = lambda : list(map(int, input().split()))
strImp = lambda : input()
spacedStrImp = lambda : list(input())
seperateImp = lambda : map(int, input().split())
for i in range(int(input())):
	numOfLights = intInp()
	ans = (numOfLights + 1) * (numOfLights + 2) // 2
	print(ans - 1)


t = int(input())
import math
for i in range(t):
	n = int(input())
	sums = n * (n + 1) / 2
	print(int(sums + n))


T = int(input())
for _ in range(T):
	N = int(input())
	N = N * (N + 3)
	print(N // 2)


T = int(input())
for _ in range(T):
	n = int(input())
	x = n + 1
	ans = (x - 2) * (x + 3) // 2
	print(ans + 2)


for i in range(eval(input())):
	n = int(input())
	s = n * (n + 1) // 2
	print(s + n)


T = int(input())
for _ in range(0, T):
	n = int(input())
	print(n * (n + 1) // 2 + n)


for _ in range(int(input())):
	n = int(input())
	print('{:.0f}'.format(n * (n + 1) / 2 + n))


a = int(input(''))
for i in range(a):
	x = int(input(''))
	t = x * (x + 1) // 2
	print(t + x)


T = int(input())
for x in range(T):
	N = int(input())
	print(int(N * (N + 3) / 2))


for _ in range(int(input())):
	n = int(input())
	k = n - 1
	a = 2 * n + k * (k + 1) // 2
	print(a)


T = int(input())
for t in range(T):
	N = int(input())
	print(N * (N + 3) // 2)


test = int(input())
while test > 0:
	test = test - 1
	N = int(input())
	distance = round((N - 1) * (N + 1 - (N - 2) / 2) + 2)
	print(distance)


def solve(n):
	print(n * (n + 3) // 2)
t = int(input())
for _ in range(t):
	n = int(input())
	solve(n)