You and your friend are participating in a TV show "Run For Your Prize".

At the start of the show n prizes are located on a straight line. i-th prize is located at position a_{i}. Positions of all prizes are distinct. You start at position 1, your friend — at position 10^6 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order.

You know that it takes exactly 1 second to move from position x to position x + 1 or x - 1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all.

Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend.

What is the minimum number of seconds it will take to pick up all the prizes?


-----Input-----

The first line contains one integer n (1 ≤ n ≤ 10^5) — the number of prizes.

The second line contains n integers a_1, a_2, ..., a_{n} (2 ≤ a_{i} ≤ 10^6 - 1) — the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.


-----Output-----

Print one integer — the minimum number of seconds it will take to collect all prizes.


-----Examples-----
Input
3
2 3 9

Output
8

Input
2
2 999995

Output
5



-----Note-----

In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8.

In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5.

Difficulty: EASY

Solutions:
n = int(input())
num = list(map(int, input().split()))
left = -1
right = -1
for i in range(n):
	if num[i] - 1 < 10 ** 6 - num[i]:
		left = i
for i in range(n - 1, -1, -1):
	if num[i] - 1 > 10 ** 6 - num[i]:
		right = i
if right == -1:
	print(num[-1] - 1)
elif left == -1:
	print(10 ** 6 - num[0])
else:
	print(max(num[left] - 1, 10 ** 6 - num[right]))


n = int(input())
a = list(map(int, input().strip().split()))
res = min(a[-1] - 1, 1000000 - a[0])
for i in range(n - 1):
	res = min(res, max(a[i] - 1, 1000000 - a[i + 1]))
print(res)


n = int(input())
l = list(map(int, input().split()))
a = 0
for i in range(n):
	ans = min(abs(1 - l[i]), abs(1000000 - l[i]))
	if ans > a:
		a = ans
print(a)


n = int(input())
mas = list(map(int, input().split()))
a = 0
b = 10000000
for el in mas:
	if el <= 500000:
		if el > a:
			a = el
	elif el < b:
		b = el
b = 1000000 - b
a = a - 1
if a > b:
	print(a)
else:
	print(b)


i = int(input())
l = list(map(int, input().split()))
m = 0
for x in l:
	if x > 500000:
		if m < 1000000 - x:
			m = 1000000 - x
	elif m < x - 1:
		m = x - 1
print(m)


n = input()
n = int(n)
k = input()
k = k.strip().split()
k = list(map(int, k))
l1 = [x for x in k if x <= 10 ** 6 / 2]
l2 = [x for x in k if x > 10 ** 6 / 2]
if not l1:
	p = 0
else:
	p = max(l1) - 1
if not l2:
	q = 0
else:
	q = 10 ** 6 - min(l2)
print(max(p, q))


n = int(input())
arr = list(map(int, input().split()))
h = 1
if arr[n - 1] - 1 < 500000:
	print(arr[n - 1] - 1)
elif arr[0] > 500000:
	print(1000000 - arr[0])
else:
	for i in range(n):
		if arr[i] > 500000:
			h = i
			break
	if arr[h - 1] > 1000000 - arr[h]:
		print(arr[h - 1] - 1)
	else:
		print(1000000 - arr[h])


(a, b) = (1, 10 ** 6)
n = int(input())
x = list(map(int, input().split()))
out = min(x[n - 1] - a, b - x[0])
for i in range(0, n - 1):
	j = max(x[i] - a, b - x[i + 1])
	out = min(out, j)
print(out)


n = int(input())
a = [0] * n
ma = -1
a = [int(j) for j in input().split()]
for i in range(n):
	t = 1000000 - a[i]
	if t > a[i] - 1:
		t = a[i] - 1
	if t > ma:
		ma = t
print(ma)


n = int(input())
v = [int(x) for x in input().split()]
Max = 0
for x in v:
	Max = max(Max, min(x - 1, 1000000 - x))
print(Max)


n = int(input())
a = list(map(int, input().split()))
need = {i: False for i in range(1, 10 ** 6 + 1)}
for i in a:
	need[i] = True
(l, r) = (1, 10 ** 6)
c = 0
ans = 0
while True:
	ans += 1
	l += 1
	r -= 1
	c += need[l]
	c += need[r]
	if c == n:
		print(ans)
		break


n = int(input())
print(max([int(500000.5 - abs(500000.5 - x) - 1) for x in [int(i) for i in input().split(' ')]]))


N = int(input())
A = list(map(int, input().split()))
curM = 0
for a in A:
	curM = max(curM, min(a - 1, 1000000 - a))
print(curM)


n = int(input())
a = list(map(int, input().split()))
h = [0]
j = [0]
for i in range(n):
	if a[i] > 500000:
		j.append(1000000 - a[i])
	else:
		h.append(a[i])
if max(h) < max(j) + 1:
	print(max(j))
else:
	print(max(h) - 1)


n = int(input())
s = input()
a = s.split()
for i in range(0, len(a)):
	a[i] = int(a[i])
max1 = 2
min2 = 999999
isThere = False
isHere = False
for i in range(n):
	if a[i] > 500000:
		isThere = True
	if a[i] <= 500000:
		isHere = True
for i in range(n):
	if (a[i] <= 500000) & (a[i] > max1):
		max1 = a[i]
	if (a[i] > 500000) & (a[i] < min2):
		min2 = a[i]
if isThere & isHere:
	total = max(max1 - 1, 1000000 - min2)
elif isThere:
	total = 1000000 - min2
elif isHere:
	total = max1 - 1
print(total)


n = int(input())
a = [int(i) for i in input().split()]
print(max([int(1000000.0 - i) if i > 1000000.0 / 2 else i - 1 for i in a]))


n = int(input())
a = list(map(int, input().split()))
a.sort()
c = 0
r = []
for i in range(n):
	r.append(min(a[i] - 1, 1000000 - a[i]))
print(max(r))


n = int(input())
p = [int(i) for i in input().split()]
prizes = [False] * 10 ** 6
for i in p:
	prizes[i] = True
m = 1
f = 10 ** 6
t = 0
cnt = 0
while cnt < n:
	t += 1
	m += 1
	f -= 1
	if prizes[m]:
		prizes[m] = False
		cnt += 1
	if prizes[f]:
		prizes[f] = False
		cnt += 1
print(t)


import sys
no_of_prizes = int(sys.stdin.readline().rstrip('\n'))
positions = sys.stdin.readline().rstrip('\n')
positions = positions.split(' ')
positions = [int(pos) for pos in positions]
my_prizes = [i for i in positions if i <= 500000]
friend_prizes = [i for i in positions if i > 500000]
if len(my_prizes) > 0:
	furthest_prize_me = max(my_prizes)
	furthest_time_taken_me = furthest_prize_me - 1
else:
	furthest_time_taken_me = 0
if len(friend_prizes) > 0:
	furthest_prize_friend = min(friend_prizes)
	furthest_time_taken_friend = 10 ** 6 - furthest_prize_friend
else:
	furthest_time_taken_friend = 0
print(max(furthest_time_taken_me, furthest_time_taken_friend))


def binp(x):
	(l, r) = (-1, n)
	while r - l > 1:
		m = (r + l) // 2
		if x < a[m]:
			r = m
		else:
			l = m
	return r
n = int(input())
a = list(map(int, input().split()))
y = binp(500000)
(x1, x2) = (0, 1000000)
if a[:y]:
	x1 = max(a[:y])
if a[y:]:
	x2 = min(a[y:])
print(max(x1 - 1, 1000000 - x2))


n = int(input())
a = [int(i) for i in input().split()]
(me, fr) = (1, 10 ** 6)
j = 0
for i in a:
	if i < 500001 and i - 1 > j:
		j = i - 1
	if i > 500000 and 10 ** 6 - i > j:
		j = 10 ** 6 - i
print(j)


n = int(input())
l = [int(i) for i in input().split()]
dist = [0] * 10000000
for i in l:
	dist[i] = min(i - 1, 10 ** 6 - i)
print(max(dist))


import sys, math
f = sys.stdin
n = f.readline()
s = list(map(int, f.readline().split()))
print(max((min(x - 1, 1000000 - x) for x in s)))


n = int(input())
a = list(map(int, input().split()))
p1 = 1
p2 = 1000000
i = 0
j = 1
c = 0
while c < n:
	t1 = a[i] - 1
	t2 = 1000000 - a[-j]
	if t1 < t2:
		p1 = a[i]
		i += 1
		c += 1
	elif t1 > t2:
		p2 = a[-j]
		j += 1
		c += 1
	else:
		p1 = a[i]
		i += 1
		p2 = a[-j]
		j += 1
		c += 2
print(max(p1 - 1, 1000000 - p2))


prices = int(input())
x = input().split(' ')
x = list(x)
me = 1
friend = 1000000
timer = 0
i = 0
j = len(x) - 1
while me <= 500000 and friend >= 500000:
	if me == int(x[i]):
		prices = prices - 1
		i = i + 1
	if friend == int(x[j]):
		prices = prices - 1
		j = j - 1
	me = me + 1
	friend = friend - 1
	if prices == 0:
		print(timer)
		break
	timer = timer + 1


n = int(input())
l = list(map(int, input().split()))
a = 1
b = 10 ** 6
x = 1
y = 0
s = 0
s1 = 0
i = 0
for i in range(n):
	if l[i] > 500000:
		break
	y = l[i]
	s += y - x
	x = y
x = 10 ** 6
for j in range(n - 1, -1, -1):
	if l[j] <= 500000:
		break
	y = l[j]
	s1 += x - y
	x = y
print(max(s, s1))


import sys

def main():
	n = int(input())
	ar = list(map(int, input().split()))
	ar.extend([1, 10 ** 6])
	ar.sort()
	print(min([max(ar[i] - 1, 10 ** 6 - ar[i + 1]) for i in range(len(ar) - 1)]))

def __starting_point():
	main()
__starting_point()


n = int(input())
l = 1
r = 1000000
a = list(map(int, input().split()))
ans = 0
for i in range(n):
	if a[i] - l <= r - a[i]:
		ans = a[i] - 1
	else:
		ans = max(ans, r - a[i])
print(ans)


n = int(input())
(l, r) = (1, int(1000000.0))
a = map(int, input().split())
for i in a:
	if i <= int(500000.0) and i > l:
		l = i
	if i > int(500000.0) and i < r:
		r = i
print(max(l - 1, int(1000000.0) - r))


from cmath import inf
n = int(input())
a = list(map(int, input().split()))
left = [0] + [x - 1 for x in a]
right = [10 ** 6 - x for x in a] + [0]
ans = inf
for i in range(n + 1):
	ans = min(ans, max(left[i], right[i]))
print(ans)


n = int(input())
x = input().split(' ')
ans = -1
for i in x:
	ans = max(ans, min(int(i) - 1, 1000000 - int(i)))
print(ans)


import sys
n = sys.stdin.readline()
prizes = map(int, sys.stdin.readline().strip().split())
max_steps = 0
max_steps2 = 0
pos2 = int(10 ** 6)
border = int(pos2 / 2)
for i in prizes:
	if i <= border:
		max_steps = max(max_steps, i - 1)
	else:
		max_steps2 = max(max_steps2, pos2 - i)
print(max(max_steps, max_steps2))


n = int(input())
p1 = 1
p2 = 1000000
time = 0
k = list(map(int, input().split()))
for i in range(len(k)):
	if k[i] >= 500001:
		if time < p2 - k[i]:
			time = p2 - k[i]
	elif time < k[i] - p1:
		time = k[i] - p1
print(time)


n = int(input())
line = input().split(' ')
a = []
for i in range(n):
	a.append(int(line[i]))
ans = -1
for i in range(n):
	ans = max(ans, min(a[i] - 1, 1000000 - a[i]))
print(ans)


n = int(input())
l = [*map(int, input().split())]
res = [min(e - 1, int(1000000.0) - e) for e in l]
print(max(res))


import sys
from itertools import permutations
n = int(input())
a = list(map(int, input().strip().split(' ')))
m = pow(10, 6) // 2
t1 = 0
t2 = 0
for i in range(n):
	if a[i] <= m:
		if a[i] == m:
			t1 = m - 1
		else:
			t1 = a[i] - 1
	else:
		break
for i in range(n):
	if a[i] > m:
		t2 = pow(10, 6) - a[i]
		break
print(max(t1, t2))


n = int(input())
ls = list(map(int, input().split()))
ans = 0
for i in ls:
	if i > 500000:
		if 1000000 - i > ans:
			ans = 1000000 - i
		break
	else:
		ans = i - 1
print(ans)


input()
numbers = [int(x) for x in input().split()]
max_left = 1
min_right = 1000000
for num in numbers:
	if num <= 500000:
		max_left = num
	else:
		min_right = num
		break
res = max(max_left - 1, 1000000 - min_right)
print(res)


input()
A = map(int, input().split())
B = map(lambda x: min(abs(x - 1), abs(x - 1000000)), A)
print(max(B))


n = int(input().strip())
a = [int(e) for e in input().split()]
(t1, t2) = (1, 10 ** 6)
mini = 10000000
sigma = 0
time = 0
if a[-1] - t1 < t2 - a[-1]:
	print(a[-1] - t1)
elif t2 - a[0] < a[0] - t1:
	print(t2 - a[0])
else:
	for i in range(0, len(a) - 1):
		if a[i] - t1 < t2 - a[i + 1]:
			time = t2 - a[i + 1]
		else:
			time = a[i] - t1
		if time < mini:
			mini = time
	print(int(mini))


n = int(input())
l = list(map(int, input().split()))
(x, y) = (list(filter(lambda x: x <= 500000, l)), list(filter(lambda x: x > 500000, l)))
s = 0
if len(x) > 0:
	s = x[-1] - 1
if len(y) > 0:
	s = max(s, 1000000 - y[0])
print(s)


n = int(input())
prices = [int(x) for x in input().split()]
ansScore = [0] * n
for i in range(n):
	ansScore[i] = min(prices[i] - 1, 1000000 - prices[i])
print(max(ansScore))


n = int(input())
a = list(map(int, input().rstrip().split()))
attuale = 0
for i in range(n):
	ma = min(a[i] - 1, 1000000 - a[i])
	attuale = max(ma, attuale)
print(attuale)


num_p = int(input().strip())
ps = [1]
ps.extend(list(map(int, input().strip().split())))
ps.append(10 ** 6)
xi = 1
xf = 10 ** 6
from math import inf
min_max = inf
for (i, p) in enumerate(ps[:-1]):
	min_max = min(min_max, max(p - xi, xf - ps[i + 1]))
print(min_max)


n = int(input())
l = list(map(int, input().split()))
l.sort()
l1 = [i - 1 for i in l]
l2 = [1000000 - i for i in l]
ans = 0
for i in range(n):
	if l2[i] < l1[i]:
		ans = max(ans, l2[i])
	else:
		ans = max(ans, l1[i])
print(ans)


n = int(input())
mas = list(map(int, input().split()))
mas = [0] + mas
midle = 10 ** 6 // 2
ind = 0
for i in range(n + 1):
	if mas[i] > midle:
		ind = i
		break
if ind:
	sec_1 = mas[ind - 1] - 1
	sec_2 = 10 ** 6 - mas[ind]
else:
	sec_1 = mas[-1] - 1
	sec_2 = 0
print(max(sec_1, sec_2))


n = int(input())
a = list(map(int, input().split()))
res = a[-1] - 1
ans = res
ft = 0
for i in range(n - 1, 0, -1):
	res -= a[i] - a[i - 1]
	ft = 10 ** 6 - a[i]
	ans = min(ans, max(res, ft))
ft = 10 ** 6 - a[0]
ans = min(ans, ft)
print(ans)


n = int(input())
a = list(map(int, input().split()))
if max(a) < 500000:
	print(max(a) - 1)
	exit()
if min(a) > 500000:
	print(1000000 - min(a))
	exit()
mina = -1
maxa = 10000000000000
for i in range(0, len(a)):
	if a[i] <= 500000 and a[i] > mina:
		mina = a[i]
for i in range(len(a) - 1, -1, -1):
	if a[i] > 500000 and a[i] < maxa:
		maxa = a[i]
print(max(mina - 1, 1000000 - maxa))


n = int(input())
A = [int(i) for i in input().split()]
A = [min(A[i] - 1, 10 ** 6 - A[i]) for i in range(n)]
print(max(A))


import sys
n = int(sys.stdin.readline())
data = list(map(int, sys.stdin.readline().split()))
ans = min(data[-1] - 1, 1000000 - data[0])
for i in range(n - 1):
	cur_ans = max(data[i] - 1, 1000000 - data[i + 1])
	ans = min(ans, cur_ans)
print(ans)


n = int(input())
l = list(map(int, input().split()))
x = 1000000
s = []
for i in range(n):
	s.append(min(l[i] - 1, x - l[i]))
print(max(s))


n = int(input())
prices = list(map(int, input().split()))
you = 1
friend = 1000000
midle = 500000
time_m = 0
time_f = 0
second_half = []
for p in prices:
	if p <= midle:
		time_m += p - you
		you = p
	else:
		second_half.append(p)
second_half = sorted(second_half, reverse=True)
for p in second_half:
	time_f += friend - p
	friend = p
print(max(time_f, time_m))


n = int(input())
arr = list(map(int, input().split()))
myPosition = 1
FriendPosition = 10 ** 6
time = 0
maxT = 0
for i in range(n):
	time = min(abs(myPosition - arr[i]), abs(FriendPosition - arr[i]))
	maxT = max(maxT, time)
print(maxT)


n = int(input())
a = [int(x) for x in input().strip().split(' ')]
friend = 1000000
me = 0
for i in a:
	if i <= 500000:
		if i > me:
			me = i
	elif friend > i:
		friend = i
ans = me - 1
if ans < 1000000 - friend:
	ans = 1000000 - friend
print(ans)


input()
a = list(map(int, input().split()))
ans = 0
for x in a:
	z = min(x - 1, 1000000 - x)
	ans = max(z, ans)
print(ans)


r = 0
for x in map(int, [*open(0)][1].split()):
	r = max(r, min(x - 1, 1000000 - x))
print(r)


Middle = 10 ** 6 // 2
input()
X = list(map(int, input().split()))
(After, Before) = (list(filter(lambda x: x > Middle, X)), list(filter(lambda x: x <= Middle, X)))
Before.append(1)
After.append(10 ** 6)
print(min(max(X) - 1, 10 ** 6 - min(X), max(max(Before) - 1, 10 ** 6 - min(After))))


from bisect import bisect

def main():
	(n, l) = (int(input()), [1.0, *map(float, input().split()), 1000000.0])
	i = bisect(l, 500000.5)
	print(int(max(l[i - 1] - 1.0, 1000000.0 - l[i]) if n > 1 else min(l[1] - 1.0, 1000000.0 - l[1])))
main()


n = int(input())
a = [int(i) for i in input().split()]
c = []
k = 10 ** 6
m = 0
for el in a:
	m = max(min(el - 1, k - el), m)
print(m)


n = int(input())
a = list(input().strip().split(' '))
b = [int(x) for x in a]
a = [0]
a = a * 1000010
l = len(b)
for i in range(l):
	a[b[i]] = 1
l = 1
r = 1000000.0
ans = 10000000.0
if n == 0:
	print(0)
else:
	while r >= l:
		mid = int((l + r) // 2)
		count = 0
		for i in range(mid):
			if a[i + 2]:
				count += 1
			if a[1000000 - i - 1]:
				count += 1
		if count >= n:
			ans = min(ans, mid)
			r = mid - 1
		else:
			l = mid + 1
print(ans)


getInputList = lambda : list(input().split())
getInputIntList = lambda : list(map(int, input().split()))
n = int(input())
arr = getInputIntList()
final = []
a = 1
b = 10 ** 6
for i in arr:
	final.append(min(i - a, b - i))
print(max(final))


n = int(input())
a = list(map(int, input().split()))
a.sort()
d = []
for i in range(n):
	d.append(min(a[i] - 1, 1000000 - a[i]))
print(max(d))


n = int(input())
pos = input().split()
for i in range(0, len(pos)):
	pos[i] = int(pos[i])
minn = 0
for i in pos:
	n = min(i - 1, 10 ** 6 - i)
	if n > minn:
		minn = n
print(minn)


import sys
lines = sys.stdin.read().splitlines()
lincnt = -1

def input():
	global lincnt
	lincnt += 1
	return lines[lincnt]
input()
l = map(int, input().split())
print(max((min(x - 1, 1000000 - x) for x in l)))


n = int(input())
prizes = list(map(int, input().split(' ')))
maxDistance = -1
for i in prizes:
	maxDistance = max(maxDistance, min(10 ** 6 - i, i - 1))
print(maxDistance)


n = int(input())
line = input()
a = [int(x) for x in line.split()]
result = max([min(x - 1, 1000000 - x) for x in a])
print(result)


n = int(input())
A = [int(x) for x in input().split()]
a = 1
b = 10 ** 6
B = [min(e - a, b - e) for e in A]
print(max(B))


n = int(input())
p = list(map(int, input().split()))
t = 0
if max(p) < 500001:
	print(max(p) - 1)
else:
	p1 = []
	for i in p:
		if i > 500000:
			p1.append(10 ** 6 - i)
		else:
			t = i - 1
	print(max(max(p1), t))


n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
	b.append(min(a[i] - 1, abs(int(a[i] - 1000000.0))))
print(max(b))


n = int(input())
L = input().split()
M = []
for i in range(len(L)):
	L[i] = int(L[i])
	M.append(min(abs(L[i] - 1), abs(L[i] - 1000000)))
print(max(M))


n = int(input())
lol = list(map(int, input().split()))
a = 0
b = 0
for i in lol:
	if i <= 1000000 / 2:
		a = i - 1
	else:
		b = 1000000 - i
		break
print(max(a, b))


n = int(input())
a = list(map(int, input().split()))
mine = []
friend = []
mine_max = 2
friend_max = 10 ** 6
for i in range(n):
	if a[i] < 10 ** 6 // 2 + 1:
		mine_max = a[i]
	else:
		friend_max = a[i]
		break
friend_max = 10 ** 6 - friend_max
mine_max -= 1
ans = max(mine_max, friend_max)
print(ans)


n = int(input())
a = list(map(int, input().split()))
time = 0
for i in a:
	time = max(time, min(i - 1, 1000000 - i))
print(time)


k = input()
num = input().split()
num = list(map(int, num))
l = 0
t = 500000
r = 0
for i in num:
	if i <= t:
		l = i - 1
	else:
		r = max(r, 1000000 - i)
print(max(l, r))


n = int(input())
reading = list(map(int, input().split()))
massimo = 0
for a in range(n):
	premio = reading[a]
	tempo = min(premio - 1, 1000000 - premio)
	if tempo > massimo:
		massimo = tempo
print(massimo)


import sys
n = int(input())
a = list(map(int, input().split()))
ans = 0
for x in a:
	ans = max(ans, min(x - 1, 10 ** 6 - x))
print(ans)


n = int(input())
prizes = list(map(int, input().split()))
time1 = 0
time2 = 0
present = 0
previous = 1
for i in range(n):
	if prizes[i] > 500000:
		break
	present = prizes[i]
	time1 += present - previous
	previous = present
previous = 1000000
for j in range(n - 1, -1, -1):
	if prizes[j] <= 500000:
		break
	present = prizes[j]
	time2 += previous - present
	previous = present
print(max(time2, time1))


n = int(input())
myPos = 1
friendPos = 1000000
a = list(map(int, input().split()))
ans = max((min(i - 1, friendPos - i) for i in a))
print(ans)


n = int(input())
x = list(map(int, input().split()))
i = 0
if max(x) >= 10 ** 6 // 2:
	try:
		while x[i] <= 10 ** 6 // 2:
			i += 1
		if i != 0:
			if x[i - 1] - 1 > 10 ** 6 - x[i]:
				a = x[i - 1] - 1
			else:
				a = 10 ** 6 - x[i]
		else:
			a = 10 ** 6 - x[i]
	except IndexError:
		a = 499999
else:
	a = x[-1] - 1
print(a)


k = input()
n = int(k)
p = [sorted((int(i) for i in input().split()))]
s = p[0]
(x, y) = (0, 0)
for i in s:
	if i <= 5 * pow(10, 5):
		x = i - 1
	else:
		y = pow(10, 6) - i
		break
print(max(x, y))


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


n = int(input())
a = list(map(int, input().split(' ')))
mid = (1 + 10 ** 6) / 2
lis1 = []
lis2 = []
for i in a:
	if i > mid:
		lis2.append(i)
	else:
		lis1.append(i)
if len(lis1) != 0:
	aa = max(lis1)
else:
	aa = 1
if len(lis2) != 0:
	bb = min(lis2)
else:
	bb = 10 ** 6
a1 = abs(aa - 1)
a2 = abs(10 ** 6 - bb)
print(max(a1, a2))


n = int(input())
prizes = list(map(int, input().split()))
a1 = 1
a2 = 1000000
answer = 0
for i in prizes:
	answer = max(min(abs(i - a1), abs(i - a2)), answer)
print(answer)


n = int(input())
a = list(map(int, input().split()))
cnt = 1000000 - a[0]
for i in range(n - 1):
	left = a[i] - 1
	right = 1000000 - a[i + 1]
	cnt = min(max(left, right), cnt)
cnt = min(a[n - 1] - 1, cnt)
print(cnt)


from pprint import pprint as pp

def GI():
	return int(input())

def GIS():
	return map(int, input().split())
from collections import deque

def main():
	n = GI()
	ps = deque(GIS())
	seconds = 0
	l = 1
	r = 10 ** 6
	while ps:
		seconds += 1
		l += 1
		r -= 1
		if ps[0] == l:
			ps.popleft()
		if ps and ps[-1] == r:
			ps.pop()
	print(seconds)
main()


n = int(input())
l = list(map(int, input().split()))
ans = -1
for i in l:
	a = i - 1
	b = 10 ** 6 - i
	ans = max(ans, min(a, b))
print(ans)


n = int(input())
A = list(map(int, input().split()))
B = []
for q in range(1000000):
	B.append(0)
for q in range(len(A)):
	B[A[q]] = 1
cnst = 1000000 // 2
for q in range(cnst):
	if B[cnst - q] == 1 or B[cnst + q + 1] == 1:
		break
print(cnst - q - 1)


n = int(input())
a = list(map(int, input().split()))
maxd = 0
for i in range(n):
	if a[i] <= 500000:
		maxd = max(maxd, a[i] - 1)
	else:
		maxd = max(maxd, 1000000 - a[i])
print(maxd)


n = int(input())
print(max([min(int(x) - 1, 10 ** 6 - int(x)) for x in input().split()]))


n = int(input())
s = [1] + list(map(int, input().split())) + [1000000]
x = set()
for i in range(n + 1):
	x.add(max(s[i] - 1, 1000000 - s[i + 1]))
print(min(x))


n = int(input())
a = set(map(int, input().split()))
l = 1
r = 10 ** 6
for i in range(1, 10 ** 6 + 1):
	if l + i in a:
		n -= 1
	if r - i in a:
		n -= 1
	if n == 0:
		print(i)
		break


from itertools import chain
DIST = int(1000000.0)
STOP = DIST // 2
last = 1
input()
for a in chain(map(int, input().split()), [DIST]):
	if a > STOP:
		print(max(last - 1, DIST - a))
		break
	last = a


p1 = 1
p2 = 10 ** 6
n = int(input())
a = [int(x) for x in input().split()]
m = 0
for i in a:
	m = max(min([p2 - i, i - p1]), m)
print(m)


num = input()
pos = [int(i) for i in input().split(' ')]
sub = (pow(10, 6) + 1) / 2
minimum = 10000000
for i in pos:
	minimum = min(minimum, abs(i - sub))
print(int(sub - minimum - 1))


Read = lambda : list(map(int, input().split()))
n = int(input())
t = 0
for x in Read():
	if x - 1 > t and x <= 500000:
		t = x - 1
	if 1000000 - x > t and x > 500000:
		t = 1000000 - x
print(t)


n = int(input())
l = list(map(int, input().split()))
z = []
max_z = 0
for i in range(n):
	z.append(min(l[i] - 1, 1000000 - l[i]))
	if z[i] > max_z:
		max_z = z[i]
print(max_z)


from bisect import bisect_right
N = 10 ** 6
n = int(input())
a = list(map(int, input().split()))
i = bisect_right(a, N // 2)
print(max(a[i - 1] - 1 if i else 0, N - a[i] if i < n else 0))


def RunPrize(n, ar):
	step1 = 0
	step2 = 0
	a1 = 1
	a2 = 1000000
	for i in range(0, len(ar)):
		if ar[i] - 500000 <= 0:
			step1 += ar[i] - a1
			a1 = ar[i]
		else:
			for j in range(len(ar) - 1, i - 1, -1):
				step2 += a2 - ar[j]
				a2 = ar[j]
			break
	if step1 > step2:
		return step1
	else:
		return step2

def hello():
	n = int(input().strip())
	ar = list(map(int, input().strip().split(' ')))
	result = RunPrize(n, ar)
	print(result)
hello()


n = int(input())
arr = list(map(int, input().split()))
ans = 0
for i in range(len(arr)):
	ans = max(ans, min(arr[i] - 1, 1000000 - arr[i]))
print(ans)


input()
print(max([min(i - 1, 10 ** 6 - i) for i in map(int, input().split())]))


n = int(input())
arr = [int(i) for i in input().split()]
ans = 0
for i in range(n):
	ans = max(ans, min(arr[i] - 1, 1000000 - arr[i]))
print(ans)


wo = 0
friend = 1000000
t = int(input())
s = input().split(' ')
for i in s:
	x = int(i)
	if x <= 500000:
		if x > wo:
			wo = x
	elif x < friend:
		friend = x
ans = wo - 1
if 1000000 - friend > ans:
	ans = 1000000 - friend
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
a = [1] + a + [10 ** 6]
mx = 10 ** 6
for i in range(len(a) - 1):
	mx = min(mx, max(a[i] - a[0], a[-1] - a[i + 1]))
print(mx)


a = input()
arr = list(map(int, input().split()))
arr.sort()
ans2 = 0
ans1 = 0
C = 10 ** 6
for i in range(len(arr)):
	if arr[i] <= C // 2:
		ans1 = arr[i] - 1
	if arr[i] > C // 2 and ans2 == 0:
		ans2 = C - arr[i]
print(max(ans1, ans2))


import math
n = int(input())
a = list(map(int, input().split()))
minm = 10 ** 9
for i in range(0, n - 1):
	x = max(a[i] - 1, 10 ** 6 - a[i + 1])
	if minm > x:
		minm = x
x = min(a[n - 1] - 1, 10 ** 6 - a[0], minm)
print(x)


n = int(input())
li = list(map(int, input().split()))
a = float('inf')
ind = 0
for i in range(n):
	if abs(li[i] - 500000.5) < a:
		ind = i
		a = abs(li[i] - 500000.5)
if li[ind] < 500000.5:
	print(li[ind] - 1)
else:
	print(1000000 - li[ind])


(n, m) = (int(input()), 0)
x = list(map(int, input().split()))
y = [i - 1 for i in x]
y.append((1000000 - i for i in x))
for i in x:
	m = max(m, min(i - 1, 1000000 - i))
print(m)


n = int(input())
lst = list(map(int, input().split()))
print(max([min(a - 1, 10 ** 6 - a) for a in lst]))


Read = lambda : list(map(int, input().split()))
input()
print(max((min(x - 1, 10 ** 6 - x) for x in Read())))


n = int(input())
l = list(map(int, input().split()))
ans = 0
(x, y) = (1, 999995 + 5)
ans1 = 0
ans2 = 0
for i in l:
	t = abs(x - i)
	t2 = abs(y - i)
	if t >= t2:
		if t2 > ans1:
			ans1 = t2
	elif t > ans2:
		ans2 = t
print(max(ans1, ans2))


n = int(input())
arr = list(map(int, input().split()))
lst = [0] * 10 ** 6
for i in arr:
	lst[i] = min(abs(i - 1), abs(10 ** 6 - i))
print(max(lst))


path = [0] * 1000000
n = int(input())
points = str(input()).split()
for point in points:
	point = int(point)
	path[point - 1] = 1
current = 500000 - 1
answer1 = 0
answer2 = 0
while current < 1000000:
	if path[current] == 1:
		answer1 = 1000000 - current - 1
		break
	current = current + 1
current = 500000 - 1
while current >= 0:
	if path[current] == 1:
		answer2 = current
		break
	current = current - 1
if max(answer1, answer2) == 500000:
	print(499999)
else:
	print(max(answer1, answer2))


n = int(input())
a = list(map(int, input().split()))
ans = float('+inf')
for i in range(n + 1):
	cur = 0
	if i:
		cur = max(cur, a[i - 1] - 1)
	if i != n:
		cur = max(cur, 1000000 - a[i])
	ans = min(ans, cur)
print(ans)


import bisect

def main():
	N = int(input())
	A = tuple(map(int, input().split()))
	i = bisect.bisect(A, 500000)
	if not i:
		own = 0
	else:
		own = A[i - 1] - 1
	if i == N:
		friend = 0
	else:
		friend = 1000000 - A[i]
	print(max(own, friend))
main()


import sys, math, queue, bisect
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
n = int(input())
a = [1] + list(map(int, input().split())) + [10 ** 6]
ans = 10 ** 6
for i in range(1, n + 2):
	ans = min(ans, max(a[i - 1] - 1, 10 ** 6 - a[i]))
print(ans)


import sys
n = int(input())
ar = list(map(int, sys.stdin.readline().split()))
an = 0
for el in ar:
	if el <= 500000:
		an = el - 1
	else:
		an = max(an, 1000000 - el)
		break
print(an)


n = int(input())
positions = list(map(int, input().strip().split()))[:n]
me = meVAR = 1
myFrnd = myFrndVAR = 1000000
itr = 0
while itr < len(positions):
	meVAR = positions[itr] - me
	myFrndVAR = myFrnd - positions[itr]
	if meVAR > myFrndVAR:
		break
	itr += 1
positions[itr:] = reversed(positions[itr:])
minSecondsME = 0
minSecondsFrnd = 0
for (indx, value) in enumerate(positions):
	if indx < itr:
		minSecondsME += value - me
		me = value
	else:
		minSecondsFrnd += myFrnd - value
		myFrnd = value
result = max(minSecondsME, minSecondsFrnd)
print(result)


n = int(input())
myList = list(map(int, input().split()))
myNewList = []
for i in range(0, len(myList)):
	if myList[i] < 500001:
		x = myList[i] - 1
	elif myList[i] >= 500001:
		x = abs(myList[i] - 1000000)
	myNewList.append(x)
maxi = 0
for j in range(0, len(myNewList)):
	if myNewList[j] > maxi:
		maxi = myNewList[j]
print(maxi)


n = int(input())
a = input().split()
d = 0
for i in range(len(a)):
	a[i] = int(a[i])
	if a[i] < 500001:
		if a[i] - 1 > d:
			d = a[i] - 1
	elif 10 ** 6 - a[i] > d:
		d = 10 ** 6 - a[i]
print(d)


n = int(input())
l = list(map(int, input().split()))
me = 1
fr = 1000000
for i in l:
	if i <= 500000:
		if me < i:
			me = i
	elif fr > i:
		fr = i
print(max(1000000 - fr, me - 1))


input()
a = list(map(int, input().split()))
r = 0
for x in a:
	r = max(r, min(x - 1, 1000000 - x))
print(r)


n = int(input())
ar = list(map(int, input().strip().split(' ')))
lst1 = list(filter(lambda x: x <= 500000, ar))
lst2 = list(filter(lambda x: x > 500000, ar))
lst1.append(1)
lst2.append(1000000)
m = 0
for i in range(len(lst1)):
	if lst1[i] > m:
		m = lst1[i]
m -= 1
mi = min(lst2)
mi = 1000000 - mi
if mi > m:
	print(mi)
else:
	print(m)


n = int(input())
a = input().split()
for i in range(len(a)):
	a[i] = int(a[i])
if a[n - 1] <= 1000000 / 2:
	print(a[n - 1] - 1)
elif a[0] > 1000000 / 2:
	print(1000001 - a[0] - 1)
else:
	for i in range(len(a)):
		if a[i] > 500000:
			break
	print(max(a[i - 1] - 1, 1000001 - a[i] - 1))


v = 'aiouey'
n = int(input())
a = list(map(int, input().split()))
fr = 1000000
mi = 0
for i in a:
	mi = max(min(fr - i, i - 1), mi)
print(mi)


def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	mm = 0
	for aa in a:
		m = min(aa - 1, 1000000 - aa)
		mm = max(mm, m)
	print(mm)

def __starting_point():
	main()
__starting_point()


n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in range(n):
	if a[i] <= 500000:
		ans = a[i] - 1
	else:
		ans = max(ans, 1000000 - a[i])
		break
print(ans)


a = input()
a = input().split(' ')
a = [int(i) for i in a]
a = sorted(a)
ii = 1
j = 10 ** 6
ans = min(abs(a[0] - ii), abs(a[0] - j))
for i in a:
	ans = max(min(abs(i - ii), abs(i - j)), ans)
print(ans)


n = int(input())
numbers = [int(i) for i in input().split()]
max_n = -1
for i in range(len(numbers)):
	if numbers[i] > 5 * 10 ** 5:
		numbers[i] = 10 ** 6 - numbers[i] + 1
	if numbers[i] > max_n:
		max_n = numbers[i]
print(max_n - 1)


import math as mt
import itertools as it
import functools as ft
stdin = lambda type_='int', sep=' ': list(map(eval(type_), input().split(sep)))
joint = lambda sep=' ', *args: sep.join((str(i) if type(i) != list else sep.join(map(str, i)) for i in args))
n = int(input())
a = stdin()
ans = 10 ** 6 - a[0]
for i in range(n):
	ans = min(ans, max(a[i] - 1, 10 ** 6 - (a[i + 1] if i != n - 1 else 10 ** 6)))
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = 500000.5
if a[0] > b:
	print(10 ** 6 - a[0])
	exit(0)
if a[n - 1] < b:
	print(a[n - 1] - 1)
	exit(0)
i = 0
while i < n - 1 and (not a[i] < b < a[i + 1]):
	i += 1
print(max(a[i] - 1, 10 ** 6 - a[i + 1]))


class RFYP:

	def main(self):
		n = int(input())
		prize = [int(x) for x in input().split()]
		count1 = 0
		count2 = 0
		temp = 1
		for i in range(n):
			if prize[i] - 1 < 1000000 - prize[i]:
				count1 = count1 + prize[i] - temp
			else:
				count2 = 1000000 - prize[i]
				break
			temp = prize[i]
		if count1 > count2:
			print(count1)
		else:
			print(count2)
r = RFYP()
r.main()


n = int(input())
a = list(map(int, input().split()))
l = 10 ** 6
curr = 0
minimum = l
for i in range(n):
	curr = min(abs(a[i] - l / 2), abs(a[i] - l / 2 - 1))
	if curr < minimum:
		minimum = curr
		ans = i
if a[ans] > l / 2:
	print(l - a[ans])
else:
	print(a[ans] - 1)


def read():
	return [int(v) for v in input().split()]

def main():
	(l, r) = (1, 10 ** 6)
	read()
	a = read()
	ans = 0
	for v in a:
		ans = max(ans, min(v - l, r - v))
	print(ans)
main()


n = int(input())
x = [int(q) for q in input().split()]
mid = (1 + 10 ** 6) // 2
if max(x) <= mid:
	print(max(x) - 1)
elif min(x) >= mid + 1:
	print(10 ** 6 - min(x))
else:
	a = 0
	for i in range(n):
		if x[i] <= mid:
			a = x[i]
	b = 0
	y = x[::-1]
	for i in range(n):
		if y[i] >= mid + 1:
			b = y[i]
	print(max(a - 1, 10 ** 6 - b))


import sys
inputData = sys.stdin.readlines()
inputData = inputData[1].split()
inputData = [int(x) for x in inputData]
min1 = 0
min2 = 0
pos1 = 1
pos2 = 10 ** 6
for i in inputData:
	if i - 10 ** 6 > min2:
		min2 = i - 10 ** 6
		pos2 = 10 ** 6 + i
min1 = min2
pos1 = min1
inputData = [x for x in inputData if x > min1]
centerPoint = (10 ** 6 + 2 * min1) / 2
close1 = close2 = 1 << 30
for i in inputData:
	if abs(i - centerPoint) < close1 and i <= centerPoint:
		close1 = abs(i - centerPoint)
		min1 += i - min1
	elif abs(i - centerPoint) < close2 and i > centerPoint:
		close2 = abs(i - centerPoint)
		min2 += pos2 - i
		pos2 = i
print(max(min1 - 1, min2))


n = int(input())
x = input().split(' ')
for i in range(n):
	x[i] = int(x[i])
x.sort()
l = []
for i in range(0, len(x)):
	l.append(min(x[i] - 1, 1000000 - x[i]))
print(max(l))


n = int(input())
niz = list(map(int, input().split()))
poz1 = 1
poz2 = 10 ** 6
vreme = 0
for nagrada in niz:
	tr1 = nagrada - poz1
	tr2 = poz2 - nagrada
	vreme = max(vreme, min(tr1, tr2))
print(vreme)


n = int(input())
a = list(map(int, input().split()))
b1 = 0
b2 = 1000000
for i in range(n):
	if a[i] <= 1000000 // 2:
		b1 = a[i]
	else:
		i -= 1
		break
for j in range(i + 1, n):
	b2 = a[j]
	break
print(max(b1 - 1, 1000000 - b2))


n = int(input())
a = [int(i) for i in input().split()]
ans = 0
for num in a:
	tmp = min(num - 1, 10 ** 6 - num)
	ans = max(ans, tmp)
print(ans)


import sys
import math
import itertools
import collections

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

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

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

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

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
n = ii()
a = li()
if a[-1] > 5 * 10 ** 5 and a[0] <= 5 * 10 ** 5:
	i = 0
	(l, r) = (1, 10 ** 6)
	while i < n:
		if a[i] <= 5 * 10 ** 5:
			l = a[i]
		i += 1
	i = n - 1
	while i > 0:
		if a[i] > 5 * 10 ** 5:
			r = a[i]
		i -= 1
	print(max(l - 1, 10 ** 6 - r))
elif a[-1] <= 5 * 10 ** 5:
	print(a[-1] - 1)
else:
	print(10 ** 6 - a[0])


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

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

def li():
	return list(mi())
n = ii()
a = li()
m = 10 ** 6 // 2
x = 0
y = 10 ** 6
for ai in a:
	if ai <= m:
		x = max(x, ai)
	else:
		y = min(y, ai)
ans = max(x - 1, 10 ** 6 - y)
print(ans)


n = int(input())
A = list(map(int, input().split(' ')))
print(max(list(map(lambda x: min(x - 1, 10 ** 6 - x), A))))


from bisect import bisect_left, bisect_right
n = int(input())
a = list(map(int, input().split()))
q = 500000
index_left = bisect_left(a, q)
index_right = bisect_right(a, q)
if q in a:
	print(499999)
elif len(a) == index_left:
	print(a[index_left - 1] - 1)
elif index_right == 0:
	print(10 ** 6 - a[index_left])
else:
	print(max(a[index_left - 1] - 1, 10 ** 6 - a[index_right]))


n = int(input())
li = list(map(int, input().split()))
me = max(list(filter(lambda x: x <= 10 ** 6 // 2, li)) + [1]) - 1
fr = 10 ** 6 - min(list(filter(lambda x: x > 10 ** 6 // 2, li)) + [10 ** 6])
print(max(me, fr))


l1 = []
l2 = []
n = int(input())
l = [int(n) for n in input().split()]
for i in range(0, n):
	if l[i] > 500000:
		l2.append(l[i])
	else:
		l1.append(l[i])
if len(l1) != 0:
	l1.sort()
if len(l2) != 0:
	l2.sort()
if len(l1) == 0:
	print(1000000 - l2[0])
elif len(l2) == 0:
	print(l1[len(l1) - 1] - 1)
elif l1[len(l1) - 1] - 1 > 1000000 - l2[0]:
	print(l1[len(l1) - 1] - 1)
else:
	print(1000000 - l2[0])


from itertools import chain
n = int(input())
ps = chain(map(int, input().split()), [10 ** 6])
p = 1
ans = None
for q in ps:
	t = max(p - 1, 10 ** 6 - q)
	ans = min(t, ans) if ans is not None else t
	p = q
print(ans)


n = int(input())
v = map(int, input().split())
maxi = 0
for x in v:
	maxi = max(maxi, min(1000000 - x, x - 1))
print(maxi)


from sys import stdin
lines = [l.strip() for l in stdin.readlines()]
all_prizes = sorted([int(p) for p in lines[1].split()])
left_sums = [0] * (len(all_prizes) + 1)
left_sums[0] = 0
last_position = 1
for (i, p) in enumerate(all_prizes):
	left_sums[i + 1] = left_sums[i] + p - last_position
	last_position = p
right_sums = [0] * (len(all_prizes) + 1)
right_sums[0] = 0
last_position = int(1000000.0)
for (i, p) in enumerate(all_prizes[::-1]):
	right_sums[i + 1] = right_sums[i] + last_position - p
	last_position = p
best = int(1000000.0)
for i in range(len(all_prizes) + 1):
	current = max(left_sums[i], right_sums[len(all_prizes) - i])
	best = min(best, current)
print(best)


n = int(input())
d = list(map(int, input().split()))
res = 0
for x in d:
	res = max(res, min(x - 1, 1000000 - x))
print(res)


n = int(input())
a = list(map(int, input().split(' ')))
max = 0
min = 10 ** 7
for i in range(len(a)):
	if a[i] > 500000:
		if a[i] < min:
			min = a[i]
	elif a[i] > max:
		max = a[i]
b = max - 1
c = 10 ** 6 - min
if b > c:
	print(b)
else:
	print(c)


n = int(input())
str = input().split()
pos1 = 1
posn = 1000000
sum = 0
j = 0
l = 0
for i in range(n):
	if int(str[l]) - pos1 < posn - int(str[n - j - 1]):
		k = int(str[l]) - pos1
		sum += k
		pos1 = int(str[l])
		posn -= k
		l += 1
	else:
		k = posn - int(str[n - j - 1])
		sum += k
		posn = int(str[n - j - 1])
		pos1 += k
		j += 1
print(sum)


n = int(input())
A = [int(i) for i in input().split()]
mon_temps = 0
son_temps = 0
i = 0
while i < n and A[i] <= 500000:
	mon_temps = A[i] - 1
	i += 1
i = n - 1
while i >= 0 and A[i] > 500000:
	son_temps = 1000000 - A[i]
	i -= 1
print(max(mon_temps, son_temps))


n = int(input())
a = list(map(int, input().split()))
i = 0
ans = 0
while i < n:
	ans = max(min(a[i] - 1, 1000000 - a[i]), ans)
	i += 1
print(ans)


n = int(input())
ai = list(map(int, input().split()))
a = []
for i in ai:
	if i > 10 ** 6 / 2:
		a.append(abs(10 ** 6 / 2 - i))
	else:
		a.append(abs(10 ** 6 / 2 - i) + 1)
print(int(10 ** 6 / 2 - min(a)))


n = int(input())
prizes = list(map(int, input().split()))
res = 0
for pos in prizes:
	res = max(res, min(pos - 1, 10 ** 6 - pos))
print(res)


input()
m = list(map(int, input().split()))
ans = 0
fr = 10 ** 6
for i in m:
	ans = max(ans, min(fr - i, i - 1))
print(ans)


import sys
f = sys.stdin
f.readline()
a = [int(x) for x in f.readline().strip().split()]
n = len(a)
a.sort()
left = [0] * n
right = [0] * n
left[0] = a[0] - 1
for i in range(1, n):
	left[i] += a[i] - a[i - 1] + left[i - 1]
right[n - 1] = 10 ** 6 - a[n - 1]
for i in range(n - 2, -1, -1):
	right[i] += a[i + 1] - a[i] + right[i + 1]
ans = min(left[n - 1], right[0])
for i in range(n - 1):
	ans = min(ans, max(left[i], right[i + 1]))
print(ans)


n = int(input())
prizes = list(map(int, input().split()))[:n]
print(max([min(p, 1000001 - p) for p in prizes]) - 1)


n = int(input())
a = list(map(int, input().split()))
a.sort()
max = 0
for i in range(n):
	min1 = min(a[i] - 1, 1000000 - a[i])
	if min1 > max:
		max = min1
print(max)


n = int(input())
ai = list(map(int, input().split()))
a1 = list(map(lambda x: x - 1, list(filter(lambda x: x < 500001, ai))))
a2 = list(map(lambda x: 10 ** 6 - x, list(filter(lambda x: x > 500000, ai))))
print(max(a1 + a2), end='')


n = int(input())
a = list(map(int, input().split()))
c = []
for i in a:
	c.append(min(i - 1, 10 ** 6 - i))
print(max(c))


n = int(input())
arr = list(map(int, input().strip().split(' ')))
arr.sort()
freq = [0] * (10 ** 6 + 1)
for i in arr:
	freq[i] = 1
p = 1
q = 10 ** 6
cnt = 0
for i in range(1, 10 ** 6 + 1):
	if freq[p + i] == 1:
		cnt += 1
	if freq[q - i] == 1:
		cnt += 1
	if cnt >= n:
		break
print(i)


MAX = 1000000.0
n = int(input())
ar = list(map(int, input().split()))
var = 0
for i in ar:
	if i < MAX // 2:
		var = max(var, i - 1)
	elif i == MAX // 2:
		var = max(var, min(i - 1, MAX - i))
	else:
		var = max(var, MAX - i)
print(int(var))


n = input()
a = list(map(int, input().split()))
lst = []
for x in a:
	lst.append(min(x - 1, 10 ** 6 - x))
lst.sort()
print(lst[-1])


my_position = 1
friend_position = 10 ** 6
count = int(input())
prize = input().split(' ')
time = 0
last = len(prize)
index_for_me = 0
index_for_friend = len(prize) - 1
for i in range(0, last):
	my_path = int(prize[index_for_me]) - my_position
	friend_path = friend_position - int(prize[index_for_friend])
	if my_path < friend_path:
		min_path = my_path
		index_for_me += 1
	else:
		min_path = friend_path
		index_for_friend -= 1
	time += min_path
	my_position += min_path
	friend_position -= min_path
print(time)


import sys
import collections
from collections import Counter
import itertools
import math
import timeit

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

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

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

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

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

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
n = ii()
d = [1] + li() + [10 ** 6]
res = 10 ** 6
for i in range(n + 1):
	res = min(res, max(d[i] - 1, 10 ** 6 - d[i + 1]))
print(res)


l = int(input())
p = input().split()
l1 = [1]
l2 = [10 ** 6]
for i in range(l):
	if int(p[i]) > 500000:
		l2.append(int(p[i]))
	else:
		l1.append(int(p[i]))
print(max(max(l1) - min(l1), 10 ** 6 - min(l2)))


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))
n = int(input())
dic = {}
for (i, v) in enumerate(input().split()):
	dic[int(v)] = 1
for i in range(1, 1000001):
	if len(dic) > 0:
		if i + 1 in dic:
			del dic[i + 1]
		if 1000000 - i in dic:
			del dic[1000000 - i]
		if len(dic) == 0:
			print(i)
			break


n = int(input())
l = [int(i) for i in input().split()]
a = [0] * n
k = 10 ** 6
a[0] = min(l[0] - 1, k - l[0])
for i in range(1, n):
	a[i] = min(l[i] - 1, k - l[i])
print(max(a))


n = int(input())
A = [0] * 1000001
B = [int(i) for i in input().split(' ')]
for i in B:
	A[i] += 1
lo = 1
hi = 1000000
t = 0
while n > 0:
	if A[lo]:
		n -= 1
	if n == 0:
		break
	if A[hi]:
		n -= 1
	if n == 0:
		break
	lo += 1
	hi -= 1
	t += 1
print(t)


n = int(input())
a = list(map(int, input().split()))
k = 1000000
l = 0
for i in a:
	if i <= 500000:
		if l < i:
			l = i
	if i > 500000:
		if k > i:
			k = i
ma = max(a)
if ma <= 500000:
	print(ma - 1)
else:
	print(max(l - 1, 1000000 - k))


def solve():
	n = int(input())
	num = [int(x) for x in input().split()]
	max_v = 10 ** 6
	min_v = 1
	l = min_v
	r = max_v
	for x in num:
		if x <= max_v / 2:
			l = x
		else:
			r = x
			break
	l = l - min_v
	r = max_v - r
	print(max(l, r))
solve()


n = int(input())
s = input().split()
ser = (1 + 10 ** 6) / 2
mn = ser
res = 0
for i in s:
	if abs(ser - int(i)) < mn:
		mn = abs(ser - int(i))
		res = int(i)
if res - ser < 0:
	print(res - 1)
else:
	print(10 ** 6 - res)


import sys
n = int(sys.stdin.readline().strip())
ais = list(map(int, sys.stdin.readline().strip().split()))
pmin = 1
pmax = 10 ** 6
ais.append(pmax)
thrs = (pmin + pmax) // 2
lr = [a <= thrs for a in ais]
hpos = lr.index(False)
if not lr[0]:
	t = pmax - ais[0]
elif hpos == n:
	t = ais[n - 1] - pmin
else:
	t = max(pmax - ais[hpos], ais[hpos - 1] - pmin)
print(t)


n = int(input())
ai = list(map(int, input().split()))
ans1 = 0
ans2 = 0
for i in range(n):
	if ai[i] > 500000:
		break
	ans1 = ai[i] - 1
for i in range(n):
	if ai[i] > 500000:
		ans2 = 1000000 - ai[i]
		break
print(max(ans1, ans2))


import sys
import os
import math
import re
n = int(input())
p = list(map(int, input().split()))
c1 = 1
c2 = 10 ** 6
larg = max(p)
if larg < 10 ** 6 // 2:
	soln = larg - 1
	print(soln)
	exit(0)
sm = min(p)
if sm > 10 ** 6 // 2:
	soln = 10 ** 6 - sm
	print(soln)
	exit(0)
l = 0
r = 10 ** 6
for val in p:
	if val > l and val <= 10 ** 6 // 2:
		l = val
	if val < r and val > 10 ** 6 // 2:
		r = val
if l - 1 > 10 ** 6 - r:
	soln = l - 1
	print(soln)
else:
	soln = 10 ** 6 - r
	print(soln)


n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n):
	if min(l[i] - 1, 10 ** 6 - l[i]) > ans:
		ans = min(l[i] - 1, 10 ** 6 - l[i])
print(ans)


n = int(input())
l = [int(i) for i in input().split()]
m = 0
for i in range(n):
	m = max(m, min(l[i] - 1, 10 ** 6 - l[i]))
print(m)


q = int(input())
w = list(map(int, input().split()))
z = 1
x = 1000000
t = 0
v = 0
for i in w:
	if i <= x // 2:
		t = i - z
	else:
		v = x - i
		break
print(max(v, t))


n = int(input())
A = set(map(int, input().strip().split(' ')))
s = 1
e = 10 ** 6
t = -1
while len(A) > 0:
	if s in A:
		A.remove(s)
	if e in A:
		A.remove(e)
	s += 1
	e -= 1
	t += 1
print(t)


numPrizes = input()
prizeInput = input().split()
prizeInput = [int(x) for x in prizeInput]
prizeL = [x for x in prizeInput if x <= 500000]
prizeR = [x for x in prizeInput if x > 500000]
l = 0
r = 0
if len(prizeL) > 0:
	l = prizeL[-1]
if len(prizeR) > 0:
	r = prizeR[0]
if len(prizeR) == 0:
	print(l - 1)
elif len(prizeL) == 0:
	print(1000000 - prizeR[0])
else:
	print(max(l - 1, 1000000 - prizeR[0]))


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest
from copy import deepcopy
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

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

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def inps():
	return sys.stdin.readline()

def inpsl(x):
	tmp = sys.stdin.readline()
	return list(tmp[:x])

def err(x):
	print(x)
	exit()
n = inp()
a = [0] + inpl() + [10 ** 6]
res = INF
for i in range(n + 1):
	res = min(res, max(a[i] - 1, 10 ** 6 - a[i + 1]))
print(res)


input()
l = list(map(int, input().split()))
distanceMax = 0
for e in l:
	distanceMin = e - 1
	distanceMin = min(distanceMin, 1000000 - e)
	distanceMax = max(distanceMax, distanceMin)
print(distanceMax)


pr = int(input())
text = input().split()
x = 0
xx = 0
a = []
b = []
for i in text:
	i = int(i)
	if i <= 500000:
		a.append(i)
	else:
		b.append(i)
if len(b) >= 1 and len(a) >= 1:
	print(max(a[-1] - 1, 10 ** 6 - b[0]))
elif len(a) == 0:
	print(10 ** 6 - b[0])
else:
	print(a[-1] - 1)


n = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(n):
	if a[i] <= 500000:
		res = max(res, a[i] - 1)
	else:
		res = max(res, 10 ** 6 - a[i])
print(res)


n = int(input())
p = list(map(int, input().split()))
ans = 0
for val in p:
	ans = max(ans, min(abs(1 - val), abs(10 ** 6 - val)))
print(ans)


input()
print(max((min(x - 1, 1000000 - x) for x in map(int, input().split()))))


input()
a = list(map(int, input().split()))
a.sort()
(b, c) = [[i for i in a if i > 500000], [i for i in a if i <= 500000]]
try:
	mymax = max(c) - 1
except:
	mymax = 0
try:
	yourmax = 1000000 - min(b)
except:
	yourmax = 0
print(max(mymax, yourmax))


n = int(input())
a = list(map(int, input().split()))
ans = -1
for i in range(n):
	ans = max(ans, min(a[i] - 1, 1000000 - a[i]))
print(ans)


n = int(input())
a = list(map(int, input().split()))
middle = 500000
ans = -1
for pr in a:
	ans = max(ans, min(pr - 1, 1000000 - pr))
print(ans)


n = int(input())
pr = [int(x) for x in input().split()]
sec = 0
for elem in pr:
	you = elem - 1
	fri = 10 ** 6 - elem
	sec = max(sec, min(you, fri))
print(sec)


import math

def main():
	lB = 1
	rB = 1000000
	midP = (rB + lB) / 2
	n = int(input())
	nums = str(input()).split()
	maxL = 0
	for s in nums:
		p = int(s)
		l = 0
		if p > midP:
			l = rB - p
		else:
			l = p - lB
		if l > maxL:
			maxL = l
	print(maxL)
main()


import sys
n = int(input())
a = list(input().split(' '))
a = list((int(x) for x in a))
res = 0
a.sort()
l = list((x for x in range(n)))
r = list((x for x in range(n)))
res = sys.maxsize
for i in range(n - 1):
	res = min(res, max(a[i] - 1, int(1000000.0) - a[i + 1]))
res = min(res, a[n - 1] - 1)
res = min(res, int(1000000.0) - a[0])
print(res)


def check1(a):
	for i in a:
		if i > 500000.5:
			return False
	return True

def check2(a):
	for i in a:
		if i < 500000.5:
			return False
	return True

def answer(a, n):
	m = 500000.5
	if check1(a):
		print(a[-1] - 1)
		return
	elif check2(a):
		print(1000000 - a[0])
		return
	else:
		i = 0
		while True:
			if a[i] < m and a[i + 1] > m:
				break
			i += 1
		if a[i + 1] - m > m - a[i]:
			print(a[i] - 1)
		else:
			print(1000000 - a[i + 1])
n = int(input())
a = list(map(int, input().split()))
answer(a, n)


n = int(input())
a = [int(z) for z in input().split()]
r = 1000000
l = 1
cnt = n
i = 0
j = n - 1
ans = 0
first = 0
second = 0
while cnt > 0:
	if r - a[j] < a[i] - l:
		ans += r - a[j]
		l += r - a[j]
		cnt -= 1
		r = a[j]
		j -= 1
	else:
		ans += a[i] - l
		r -= a[i] - l
		cnt -= 1
		l = a[i]
		i += 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
Min = 0
Max = 1000000
ans = 0
for i in l:
	if i == 500000:
		ans = 499999
	elif i > 500000 and i < Max:
		Max = i
	elif i < 500000 and i > Min:
		Min = i
print(max(ans, Min - 1, 1000000 - Max))


import math
n = int(input())
prizes = list(map(int, input().split()))
first = 1
second = 1000000
for i in range(n):
	if prizes[i] <= 500000:
		first = prizes[i]
	else:
		second = prizes[i]
		break
diff_1 = first - 1
diff_2 = 1000000 - second
print(max(diff_1, diff_2))


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List
sys.setrecursionlimit(999999)
l = 1
r = 10 ** 6
m = l + r + 1 >> 1
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
j = bisect.bisect_left(arr, m)
if j == 0:
	print(r - arr[j])
elif j == n:
	print(arr[j - 1] - 1)
else:
	print(max(arr[j - 1] - 1, r - arr[j]))


input()
ns = [int(x) for x in input().split()]
ns = [1] + ns + [1000000]
tt = 2000000
for i in range(len(ns) - 1):
	t1 = ns[i] - 1
	t2 = 1000000 - ns[i + 1]
	t = max(t1, t2)
	if t < tt:
		tt = t
print(tt)


N = int(input())
A = [int(x) for x in input().split()]
for i in range(len(A)):
	if A[i] > 10 ** 6 // 2:
		A[i] = 10 ** 6 - A[i] + 1
print(max(A) - 1)


class food:

	def __init__(self):
		x = True
n = int(input())
prices = [int(i) for i in input().split()]
verificador = [None] * 1000000
for i in prices:
	verificador[i - 1] = food()
pEu = 0
pAmigo = 1000000 - 1
tempo = 0
if type(verificador[pEu]) is food:
	n -= 1
if type(verificador[pAmigo]) is food:
	n -= 1
while n > 0:
	pEu += 1
	pAmigo -= 1
	tempo += 1
	if type(verificador[pEu]) is food:
		n -= 1
	if type(verificador[pAmigo]) is food:
		n -= 1
print(tempo)


re = 500000
n = int(input())
ls = list(map(int, input().split()))
my_ls = []
f_ls = []
my_sec = -1
f_sec = -1
for i in ls:
	if i <= re:
		my_ls.append(i)
	elif i > re:
		f_ls.append(i)
if my_ls != []:
	my_sec = max(my_ls) - 1
if f_ls != []:
	f_sec = 10 ** 6 - min(f_ls)
print(max(my_sec, f_sec))


n = int(input())
a = list(map(int, input().split()))
l_max = 1
r_min = 10 ** 6
for i in a:
	if i <= 10 ** 6 // 2:
		l_max = max(l_max, i)
	else:
		r_min = min(r_min, i)
print(max(l_max - 1, 10 ** 6 - r_min))


x = 1
y = int(1000000.0)
a = -1
b = 1e+50
n = int(input())
array = list(map(int, input().split()))
for i in array:
	if i <= y // 2:
		a = max(a, i)
	else:
		b = min(b, i)
b = y - b
a = a - 1
print(max(a, b))


n = int(input())
l = [int(i) for i in input().split()]
maxn = int(-1000000000.0)
for i in l:
	if i > 5 * 100000.0:
		maxn = max(maxn, 1000000.0 - i)
	else:
		maxn = max(maxn, i - 1)
print(int(maxn))


n = int(input())
a = list(map(int, input().split()))
p1 = 1
p2 = 10 ** 6
for i in range(len(a)):
	if a[i] > 500000:
		p2 = a[i]
		break
	p1 = a[i]
print(max(p1 - 1, 10 ** 6 - p2))


n = int(input())
a = [int(x) for x in input().split()]
max1 = 1
min2 = 1000000
for i in range(n):
	if a[i] <= 500000:
		max1 = max(max1, a[i])
	else:
		min2 = min(min2, a[i])
print(max(max1 - 1, 1000000 - min2))


n = int(input())
a = list(map(int, input().split()))
l = 1
mil = 1000000
r = mil
for i in a:
	if i - 1 < mil - i:
		l = i
	else:
		r = i
		break
print(max(l - 1, mil - r))


input()
a = list(map(int, input().split()))
L = int(1000000.0)
print(min(a[-1] - 1, L - a[0], L if len(a) == 1 else min(map(lambda i: max(a[i - 1] - 1, L - a[i]), range(1, len(a))))))


s = int(input())
n = input().split()
c = 0
for a in range(len(n)):
	if 1000000 - int(n[a]) <= int(n[a]) - 1:
		number = a
		c = 1
		if a - 1 >= 0:
			if 1000000 - int(n[a]) < int(n[a - 1]) - 1:
				c = 2
				number = a - 1
		break
if c == 0:
	ans = int(n[-1]) - 1
elif c == 1:
	ans = 1000000 - int(n[number])
elif c == 2:
	ans = int(n[number]) - 1
print(ans)


n = int(input())
a = [int(j) for j in input().split()]
result = 0
for i in range(n):
	if a[i] <= 500000:
		result = max(result, a[i] - 1)
	else:
		result = max(result, 10 ** 6 - a[i])
print(result)


n = int(input())
a = list(map(int, input().split()))
ub = 10 ** 6
lb = 1
ans = min(a[n - 1] - lb, ub - a[0])
for i in range(1, n):
	ans = min(ans, max(a[i - 1] - lb, ub - a[i]))
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = [i for i in a if i <= 500000]
c = [i for i in a if i > 500000]
if len(b) > 0 and len(c) > 0:
	z = max(b[-1] - 1, 1000000 - c[0])
elif len(b) == 0:
	z = 1000000 - c[0]
elif len(c) == 0:
	z = b[-1] - 1
print(z)


n = int(input())
temp = [int(x) for x in input().split()]
a = 0
b = 0
for i in range(len(temp) - 1):
	if temp[i] <= 500000 and temp[i + 1] >= 500001:
		a = temp[i]
		b = temp[i + 1]
if a == 0:
	print(min(temp[-1] - 1, 1000000 - temp[0]))
else:
	print(max(a - 1, 1000000 - b))


n = int(input())
a = list(map(int, input().split()))
m1 = 0
m2 = 10000000
for i in a:
	if i <= 500000 and i > m1:
		m1 = i
	if i > 500000 and i < m2:
		m2 = i
print(max(m1 - 1, 1000000 - m2))


n = int(input())
a = list(map(int, input().split()))
res = 0
for x in a:
	res = max(res, min(x - 1, 10 ** 6 - x))
print(res)


n = int(input())
a = list(map(int, input().split()))
c = []
for i in range(len(a)):
	if a[i] <= pow(10, 6) // 2:
		c.append(a[i] - 1)
	else:
		c.append(pow(10, 6) - a[i])
print(max(c))


n = int(input())
el = map(int, input().split())
ans = 0
for x in el:
	ans = max(ans, min(x - 1, 1000000 - x))
print(ans)


import bisect as bs
(n, a) = (int(input()), list(map(int, input().split())))
m = bs.bisect_left(a, 5 * 10 ** 5 + 1)
if m == n:
	res = a[m - 1] - 1
elif m == 0:
	res = 10 ** 6 - a[0]
else:
	res = max(a[m - 1] - 1, 10 ** 6 - a[m])
print(res)


n = int(input())
a = [1] + list(map(int, input().split())) + [10 ** 6]
(p1, p2) = (1, 10 ** 6)
m = 10 ** 7
for x in range(n + 1):
	m = min(m, max(a[x] - 1, p2 - a[x + 1]))
print(m)


n = int(input())
a = list(map(int, input().split()))
v = [0] * n
curA = 1
curB = int(1000000.0)
mx = 0
for i in range(n):
	x = abs(curA - a[i])
	y = abs(curB - a[i])
	mx = max(mx, min(x, y))
print(mx)


n = int(input())
m = map(int, input().split())
mina = 0
minb = 0
for i in m:
	if i <= 500000:
		mina = max(mina, i - 1)
	else:
		minb = max(minb, 1000000 - i)
print(max(mina, minb))


import math
from decimal import Decimal

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)
(n, a) = na()
b = [0] * 1000001
k = 0
l = 1
r = 1000000
for i in a:
	b[i] = 1
tc = 0
while k < n:
	k += b[l] + b[r]
	l += 1
	r -= 1
	tc += 1
print(tc - 1)


n = int(input())
pos = list(map(int, input().split()))
frnd2 = 1000000
frnd1 = 1
t = 0
extreme_left = pos[0]
extreme_right = pos[n - 1]
if extreme_left <= frnd2 // 2 and extreme_right > frnd2 // 2:
	for i in range(n - 1, 0, -1):
		if pos[i] > frnd2 // 2 and pos[i - 1] <= frnd2 // 2:
			t = (frnd2 - pos[i], pos[i - 1] - 1)
			print(max(t))
			exit()
else:
	print(min(extreme_right - frnd1, frnd2 - extreme_left))


n = int(input())
p1 = -1
p2 = 1000005
pre = [int(i) for i in input().split()]
for x in pre:
	if x <= 500000:
		p1 = max(p1, x)
	else:
		p2 = min(p2, x)
if p1 == -1:
	print(1000000 - p2)
elif p2 == 1000005:
	print(p1 - 1)
else:
	print(max(p1 - 1, 1000000 - p2))


n = int(input())
list = input().split(' ')
for i in range(0, n):
	list[i] = int(list[i])
dist = []
for el in list:
	dist.append(abs(500000.5 - el))
print(int(500000.5 - min(dist) - 1))


n = int(input())
x = list(map(int, input().split()))
mx = int(1000000)
men = []
dostum = []
x.sort()
for i in range(n):
	men.append(x[i] - 1)
	dostum.append(mx - x[i])
ans = 0
for i in range(n):
	q = min(men[i], dostum[i])
	if q > ans:
		ans = q
print(ans)


n = int(input())
prize_pos = list(input().split(' '))
me = 1
friend = 10 ** 6
secs = 0
found = 0
right = n - 1
left = 0
for secs in range(int(friend / 2) + 1):
	if found == n and left > right:
		break
	elif str(me) == prize_pos[left] and str(friend) == prize_pos[right]:
		left += 1
		found += 2
		right -= 1
	elif str(me) == prize_pos[left]:
		left += 1
		found += 1
	elif str(friend) == prize_pos[right]:
		right -= 1
		found += 1
	me += 1
	friend -= 1
print(secs - 1)


n = int(input())
list1 = [int(x) for x in input().split()]
prev = []
aft = []
for i in list1:
	if i <= 500000:
		prev.append(i)
	else:
		aft.append(1000000 - i)
if len(aft) == 0:
	x = max(prev) - 1
	print(x)
elif len(prev) == 0:
	y = max(aft)
	print(y)
else:
	x = max(prev) - 1
	y = max(aft)
	print(max(x, y))


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


n = int(input())
a = list(map(int, input().split(' ')))
f1 = 1
f2 = 10 ** 6
time = 0
k = n - 1
j = 0
f = 0
while f < n:
	if f1 == a[j]:
		j += 1
		f += 1
	if f2 == a[k]:
		k -= 1
		f += 1
	f1 += 1
	f2 -= 1
	time += 1
print(time - 1)


n = int(input())
a = list(map(int, input().split()))
b = []
p = 10 ** 6
for i in range(n):
	b.append(min(a[i] - 1, p - a[i]))
print(max(b))


n = int(input())
a = list(map(int, input().split()))
e = 1000000
ans = max((min(x - 1, e - x) for x in a))
print(ans)


n = int(input())
values = input()
values = values.split(' ')
for i in range(n):
	values[i] = int(values[i])
minimum = 1000000.0
val = -1
for i in range(n):
	t = abs(values[i] - (500000.0 + 0.5))
	if t < minimum:
		val = values[i]
		minimum = t
print(int(min(val - 1, 1000000.0 - val)))


n = int(input())
arr = input()
l = list(map(int, arr.split(' ')))
mx = 0
for i in range(n):
	if l[i] <= 500000:
		if mx < l[i] - 1:
			mx = l[i] - 1
	elif mx < 1000000 - l[i]:
		mx = 1000000 - l[i]
print(mx)