Your working week consists of $n$ days numbered from $1$ to $n$, after day $n$ goes day $1$ again. And $3$ of them are days off. One of the days off is the last day, day $n$. You have to decide when the other two are.

Choosing days off, you pursue two goals:

No two days should go one after the other. Note that you can't make day $1$ a day off because it follows day $n$.

Working segments framed by days off should be as dissimilar as possible in duration. More specifically, if the segments are of size $l_1$, $l_2$, and $l_3$ days long, you want to maximize $\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|)$.

Output the maximum value of $\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|)$ that can be obtained.


-----Input-----

The first line of the input contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases. The description of test cases follows.

The only line of each test case contains the integer $n$ ($6 \le n \le 10^9$).


-----Output-----

For each test case, output one integer — the maximum possible obtained value.


-----Examples-----

Input
3
6
10
1033
Output
0
1
342


-----Note-----

In the image below you can see the example solutions for the first two test cases. Chosen days off are shown in purple. Working segments are underlined in green.

In test case $1$, the only options for days off are days $2$, $3$, and $4$ (because $1$ and $5$ are next to day $n$). So the only way to place them without selecting neighboring days is to choose days $2$ and $4$. Thus, $l_1 = l_2 = l_3 = 1$, and the answer $\min(|l_1 - l_2|, |l_2 - l_3|, |l_3 - l_1|) = 0$.

For test case $2$, one possible way to choose days off is shown. The working segments have the lengths of $2$, $1$, and $4$ days. So the minimum difference is $1 = \min(1, 3, 2) = \min(|2 - 1|, |1 - 4|, |4 - 2|)$. It can be shown that there is no way to make it larger.

Source: codeforces | Difficulty: EASY
Tags: Greedy algorithms

Mathematics

Constructive algorithms


Solutions:
import math

def gcd(a, b):
	while a % b != 0:
		aux = b
		b = a % b
		a = aux
	return b

def lcm(a, b):
	return a / gcd(a, b) * b

def solve(a):
	return (a - 3) // 3 - 1
for _ in range(int(input())):
	a = int(input())
	print(solve(a))


t = int(input())
results = []
for _ in range(t):
	n = int(input())
	med = n // 3
	mini = med - 2
	results.append(mini)
list(map(print, results))


for _ in range(int(input())):
	onci = int(input())
	print(onci // 3 - 2)


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


t = int(input())
for i in range(t):
	n = int(input())
	print((n - 6) // 3)


for _ in range(int(input())):
	n = int(input())
	m = (n - 3) // 3
	print(m - 1)


import sys

def solve():
	n = int(sys.stdin.readline())
	x = (n - 3) // 3 - 1
	ans.append(str(x))
t = int(sys.stdin.readline())
ans = []
for _ in range(t):
	solve()
print('\n'.join(ans))


t = int(input())
test_cases = []
for item in range(t):
	test_cases.append(int(input()))

def solver(argument):
	solve = (argument - 3) // 3
	solve2 = solve - 1
	return solve2
for test in test_cases:
	print(solver(test))


n = int(input())
for i in range(n):
	x = int(input())
	print(x // 3 - 2)


n = int(input())
arr = []
for i in range(n):
	i = int(input())
	arr.append(i)
result = []
for i in range(len(arr)):
	budni = arr[i] - 3
	koef = budni // 3 - 1
	print(koef)


t = int(input())
result = []
for i in range(t):
	n = int(input())
	result.append(int((n - 3) // 3) - 1)
for i in result:
	print(i)


for _ in range(int(input())):
	n = int(input())
	print((n - 6) // 3)


def main():
	n_tests = int(input())
	for _ in range(n_tests):
		n = int(input())
		print((n - 6) // 3)
main()


from math import ceil
t = int(input())
output = []
for i in range(t):
	n = int(input())
	d_1 = ceil((n - 4) / 3) + 1
	d_2 = d_1 + 2
	d_3 = n
	l_1 = d_1 - 1
	l_2 = d_2 - d_1 - 1
	l_3 = d_3 - d_2 - 1
	output.append(min(abs(l_1 - l_2), abs(l_2 - l_3), abs(l_3 - l_1)))
for o in output:
	print(o)


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


for t in range(int(input())):
	n = int(input())
	print((n - 3) // 3 - 1)


from sys import stdin
rd = stdin.readline
for _ in range(int(rd())):
	n = int(rd())
	print((n - 6) // 3)


for n in [*open(0)][1:]:
	print(int(n) // 3 - 2)


for num in [*open(0)][1:]:
	print(int(num) // 3 - 2)


a = int(input())
for i in range(a):
	b = int(input())
	print(b // 3 - 2)


t = int(input())
for _ in range(t):
	a = int(input())
	print((a - 6) // 3)


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())
t = inp()
for i in range(t):
	n = inp()
	if n == 6:
		print(0)
	else:
		x1 = 1
		x2 = (n - 4) // 3
		if (n - 4) / 3 != (n - 4) // 3:
			x2 = x2 + 1
		x3 = n - 4 - x2
		s = min(x2 - x1, x3 - x2)
		print(s)


list(map(print, [int(input()) // 3 - 2 for t in range(int(input()))]))


for _ in range(int(input())):
	i = int(input())
	if i > 8:
		print((i - 3) // 3 - 1)
	else:
		print(0)


for itadori in [*open(0)][1:]:
	print(int(itadori) // 3 - 2)


def splitter(n):
	n = n - 4
	if n // 3 == 0:
		l1 = 1
	else:
		l1 = int(round(n / 3))
	l2 = 1
	l3 = n - l1
	return min(abs(l1 - l2), abs(l2 - l3), abs(l3 - l1))
t = int(input())
n = []
for i in range(0, t):
	n.append(int(input()))
for i in range(0, t):
	print(splitter(n[i]))


k = int(input())
for i in range(k):
	n = int(input())
	print((n - 6) // 3)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	n -= 3
	print(n // 3 - 1)


t = int(input())
for _ in range(t):
	days = int(input())
	days -= 3
	print(days // 3 - 1)


from math import ceil
t = int(input())
for _ in range(t):
	n = int(input())
	print((n - 3) // 3 - 1)


import sys
R = sys.stdin.readline
for _ in range(int(R())):
	print((int(R()) - 6) // 3)


def getint():
	return [int(i) for i in input().split()]

def get():
	return int(input())

def S():
	for test in range(int(input())):
		solve()

def solve():
	n = get()
	print((n - 3) // 3 - 1)
S()


fl = 'input.txt'
import sys
import math
flh = sys.stdin
test_cases = int(flh.readline())
res = []
for case in range(test_cases):
	n = int(flh.readline())
	print((n - 3) // 3 - 1)


T = int(input())
for testcase in range(1, T + 1):
	n = int(input())
	k = n - 3
	k2 = k // 3
	print(min(k2 - 1, k - 2 * k2))


n = int(input())
for i in range(n):
	m = int(input())
	print((m - 3) // 3 - 1)


for _ in range(int(input())):
	n = int(input())
	t = n // 3
	l1 = n
	l2 = n + t
	l3 = n + 2 * t
	print(min(abs(l1 - l2), abs(l1 - l3), abs(l2 - l3)) - 2)


import sys
input = lambda : sys.stdin.readline().rstrip()
import math
from functools import lru_cache
t = int(input())
for _ in range(t):
	n = int(input())
	n = n - 3
	(a, b) = (n // 3, n - n // 3)
	print(min(b - a, a - 1))


def one():
	n = int(input())
	print((n - 6) // 3)
t = int(input())
for i in range(t):
	one()


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	return (n - 6) // 3
for _ in range(int(input())):
	print(solve())


from collections import *
from math import *
from sys import *
T = int(input())
for _ in range(T):
	N = int(input())
	print(N // 3 - 2)


for _ in range(int(input())):
	days = int(input())
	print(days // 3 - 2)


import math
for _ in range(int(input())):
	n = int(input())
	y = math.ceil(2 * n / 3) - 3
	x = n - 4 - y
	ans = min(x - 1, y - x, y - 1)
	print(ans)


def foo(n):
	return (n - 6) // 3
t = int(input())
for _ in range(t):
	n = int(input())
	print(foo(n))


t = int(input())
for _ in range(t):
	n = int(input())
	n -= 6
	ans = n // 3
	print(ans)


for _ in range(int(input())):
	n = int(input())
	k = n - 3
	mid = round(k / 3)
	large = k - mid - 1
	print(min([large - mid, mid - 1]))


t = int(input())
for test in range(t):
	n = int(input())
	print(n // 3 - 2)


for jj in range(int(input())):
	n = int(input()) - 3
	b = n // 3
	a = 1
	c = n - a - b
	print(min(b - a, c - b))


for _ in range(int(input())):
	a = int(input())
	print(a // 3 - 2)


t = int(input())
for _ in range(t):
	n = int(input())
	n -= 3
	an = int(n / 3)
	print(an - 1)


t = int(input())
for i in range(t):
	n = int(input())
	ans = 0
	ans = (n - 3) // 3 - 1
	print(ans)


t = int(input())
i = 1
while True:
	if i > t:
		break
	n = int(input())
	k = (n - 6) // 3
	print(k)
	i = i + 1


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	print((n - 3) // 3 - 1)
t = int(input())
for i in range(t):
	solve()


import sys
line_num = 1
for line in sys.stdin:
	if line_num == 1:
		line_num += 1
		continue
	num = int(line.strip())
	res = (num - 3) // 3 - 1
	print(res)
	line_num += 1


t = int(input())
for t1 in range(t):
	n = int(input())
	print(n // 3 - 2)


def main():
	n = int(input())
	n -= 4
	x = n // 3
	y = n % 3
	if y < 2:
		return x - 1
	return x
for _ in range(int(input())):
	print(main())


for j in range(int(input())):
	n = int(input())
	print(n // 3 - 2)


k = int(input())
while k:
	n = int(input())
	n -= 6
	if n > 0:
		print(n // 3)
	else:
		print(0)
	k -= 1


t = int(input())
for r in range(t):
	n = int(input())
	print(n // 3 - 2)


cases = int(input())
for _ in range(cases):
	days = int(input())
	print((days - 6) // 3)


o = []
for i in range(int(input())):
	n = int(input())
	kn = n - 3
	o.append(kn // 3 - 1)
print(*o, sep='\n')


import math
t = int(input())
while t != 0:
	n = int(input())
	n -= 3
	n = n // 3
	print(n - 1)
	t -= 1


for cases in range(int(input())):
	n = int(input())
	print((n - 6) // 3)


t = int(input())
i = 0
while i < t:
	n = int(input())
	print((n - 3) // 3 - 1)
	i += 1


t = int(input())
for _ in range(t):
	n = int(input())
	k = max(n - 6, 0)
	b = [1] * 3
	b[1] += k // 3
	b[2] += 2 * k // 3
	print(min(abs(b[0] - b[1]), abs(b[1] - b[2]), abs(b[2] - b[0])))


t = int(input())
for q in range(t):
	n = int(input())
	n -= 6
	n //= 3
	print(n)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	ans = n // 3 - 2
	sys.stdout.write(str(ans) + '\n')


test = int(input())
for t in range(test):
	n = int(input())
	rem = n - 3
	print(rem // 3 - 1)