You are given an array $a$ consisting of $n$ integers. In one move, you can jump from the position $i$ to the position $i - a_i$ (if $1 \le i - a_i$) or to the position $i + a_i$ (if $i + a_i \le n$).

For each position $i$ from $1$ to $n$ you want to know the minimum the number of moves required to reach any position $j$ such that $a_j$ has the opposite parity from $a_i$ (i.e. if $a_i$ is odd then $a_j$ has to be even and vice versa).


-----Input-----

The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$), where $a_i$ is the $i$-th element of $a$.


-----Output-----

Print $n$ integers $d_1, d_2, \dots, d_n$, where $d_i$ is the minimum the number of moves required to reach any position $j$ such that $a_j$ has the opposite parity from $a_i$ (i.e. if $a_i$ is odd then $a_j$ has to be even and vice versa) or -1 if it is impossible to reach such a position.


-----Example-----
Input
10
4 5 7 6 7 5 4 4 6 4

Output
1 1 1 2 -1 1 1 3 1 1

Difficulty: HARD

Solutions:
from copy import deepcopy
from collections import defaultdict
from queue import Queue
n = int(input())
arr = [int(x) for x in input().split()]
d = [-1] * n
parity = [x % 2 for x in arr]
done = Queue()
lrs = defaultdict(list)
for i in range(n):
	put = False
	if i - arr[i] >= 0:
		if parity[i] != parity[i - arr[i]]:
			d[i] = 1
			done.put(i)
			put = True
		lrs[i - arr[i]].append(i)
	if i + arr[i] < n:
		if not put and parity[i] != parity[i + arr[i]]:
			d[i] = 1
			done.put(i)
		lrs[i + arr[i]].append(i)
while not done.empty():
	i = done.get()
	for j in lrs[i]:
		if d[j] == -1:
			d[j] = d[i] + 1
			done.put(j)
print(' '.join([str(x) for x in d]))


from collections import deque

def bfs():
	queue = deque()
	for v in range(n):
		if distance[v] != -1:
			queue.append(v)
	while len(queue) > 0:
		v = queue.popleft()
		for e in edge[v]:
			if distance[e] == -1:
				queue.append(e)
				distance[e] = distance[v] + 1

def main():
	global n, A, distance, edge
	n = int(input())
	A = [int(x) for x in input().strip().split()]
	distance = [-1] * n
	edge = [[] for i in range(n)]
	for i in range(n):
		for m in [i - A[i], i + A[i]]:
			if 0 <= m < n:
				if A[i] & 1 == A[m] & 1:
					edge[m].append(i)
				else:
					distance[i] = 1
	bfs()
	print(*distance)
main()


from collections import defaultdict, deque
import threading
answer = []

def bfs(start, end, g):
	d = [float('inf')] * (len(start) + len(end) + 1)
	q = deque()
	global answer
	for i in start:
		d[i] = 0
		q.append(i)
	while q:
		temp = q.popleft()
		for to in g[temp]:
			if d[to] == float('inf'):
				d[to] = d[temp] + 1
				q.append(to)
	for i in end:
		if d[i] != float('inf'):
			answer[i] = d[i]

def f(a):
	global answer
	n = len(a)
	a = [None] + a
	answer = [-1] * len(a)
	odd = []
	even = []
	g = defaultdict(list)
	for i in range(1, len(a)):
		if a[i] & 1:
			odd.append(i)
		else:
			even.append(i)
		if a[i] + i <= n:
			g[a[i] + i].append(i)
		if i - a[i] >= 1:
			g[i - a[i]].append(i)
	bfs(odd, even, g)
	bfs(even, odd, g)
	return answer[1:]
a = input()
lst = list(map(int, input().strip().split()))
print(*f(lst))


from collections import deque
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
b = list(map(int, input().split()))
adj = [[] for i in range(n + 1)]
odd = []
even = []
for i in range(n):
	p = b[i] + (i + 1)
	if b[i] & 1:
		odd.append(i + 1)
	else:
		even.append(i + 1)
	q = i + 1 - b[i]
	if p <= n:
		adj[p].append(i + 1)
	if q >= 1:
		adj[q].append(i + 1)
ans = [float('inf')] * (n + 1)
val = [float('inf')] * (n + 1)
q = deque()
for j in even:
	val[j] = 0
	q.append(j)
while q:
	u = q.popleft()
	for j in adj[u]:
		if val[j] == float('inf'):
			val[j] = val[u] + 1
			q.append(j)
for j in odd:
	ans[j] = val[j]
val = [float('inf')] * (n + 1)
q = deque()
for j in odd:
	val[j] = 0
	q.append(j)
while q:
	u = q.popleft()
	for j in adj[u]:
		if val[j] == float('inf'):
			val[j] = val[u] + 1
			q.append(j)
for j in even:
	ans[j] = val[j]
res = []
for j in range(1, n + 1):
	if ans[j] == float('inf'):
		res.append(-1)
	else:
		res.append(ans[j])
print(*res)


import sys
from collections import deque

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
que = deque()
nodes = [[] for i in range(N)]
for (i, a) in enumerate(A):
	if i + a < N:
		nodes[i + a].append(i)
		if a % 2 != A[i + a] % 2:
			que.append((i, 1))
			continue
	if i - a >= 0:
		nodes[i - a].append(i)
		if a % 2 != A[i - a] % 2:
			que.append((i, 1))
ans = [-1] * N
while que:
	(u, cost) = que.popleft()
	if ans[u] != -1:
		continue
	ans[u] = cost
	for v in nodes[u]:
		que.append((v, cost + 1))
print(*ans)


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

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

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
INF = float('inf')
mod = int(1000000000.0) + 7

def dijkstra(n, graph):
	dist = [-1] * n
	vis = [0] * n
	queue = deque()
	for i in range(n):
		if i + a[i] < n and (a[i] + a[i + a[i]]) % 2 != 0 or (i - a[i] >= 0 and (a[i] + a[i - a[i]]) % 2 != 0):
			dist[i] = 1
			queue.append(i)
			vis[i] = 1
	while queue:
		v = queue.popleft()
		for u in graph[v]:
			if vis[u] == 0:
				dist[u] = 1 + dist[v]
				queue.append(u)
				vis[u] = 1
	return dist
n = int(data())
a = mdata()
graph = [[] for i in range(n)]
for i in range(n):
	if i + a[i] < n:
		graph[i + a[i]].append(i)
	if i - a[i] >= 0:
		graph[i - a[i]].append(i)
dist = dijkstra(n, graph)
outl(dist)


from collections import deque
import sys
input = sys.stdin.readline

def bfs0(s):
	q = deque()
	dist = [inf] * n
	for i in s:
		q.append(i)
		dist[i] = 0
	while q:
		i = q.popleft()
		di = dist[i]
		for j in G[i]:
			if dist[j] > di + 1:
				q.append(j)
				dist[j] = di + 1
	return dist

def bfs1(s):
	q = deque()
	dist = [inf] * n
	for i in s:
		q.append(i)
		dist[i] = 0
	while q:
		i = q.popleft()
		di = dist[i]
		for j in H[i]:
			if dist[j] > di + 1:
				q.append(j)
				dist[j] = di + 1
	return dist
n = int(input())
a = list(map(int, input().split()))
G = [[] for _ in range(n)]
H = [[] for _ in range(n)]
(s0, s1) = (set(), set())
for i in range(n):
	ai = a[i]
	if ai % 2 == 0:
		if i + ai < n:
			G[i + ai].append(i)
			if a[i + ai] % 2 == 1:
				s0.add(i + ai)
		if 0 <= i - ai:
			G[i - ai].append(i)
			if a[i - ai] % 2 == 1:
				s0.add(i - ai)
	else:
		if i + ai < n:
			H[i + ai].append(i)
			if a[i + ai] % 2 == 0:
				s1.add(i + ai)
		if 0 <= i - ai:
			H[i - ai].append(i)
			if a[i - ai] % 2 == 0:
				s1.add(i - ai)
inf = 1145141919
dist0 = bfs0(s0)
dist1 = bfs1(s1)
ans = []
for i in range(n):
	m = inf
	if 0 < dist0[i]:
		m = min(m, dist0[i] + 1)
	if 0 < dist1[i]:
		m = min(m, dist1[i] + 1)
	m %= inf
	m -= 1
	ans.append(m)
print(*ans)


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
E = [[] for i in range(n + 1)]
from collections import deque
ODD = deque()
EVEN = deque()
for i in range(n):
	if i + 1 + A[i] < n + 1:
		E[i + 1 + A[i]].append(i + 1)
	if i + 1 - A[i] >= 0:
		E[i + 1 - A[i]].append(i + 1)
	if A[i] % 2 == 1:
		ODD.append(i + 1)
	else:
		EVEN.append(i + 1)
AODD = [-1] * (n + 1)
AEVEN = [-1] * (n + 1)
count = 1
while ODD:
	NODD = deque()
	while ODD:
		x = ODD.pop()
		for to in E[x]:
			if AODD[to] == -1:
				AODD[to] = count
				NODD.append(to)
	ODD = NODD
	count += 1
count = 1
while EVEN:
	NEVEN = deque()
	while EVEN:
		x = EVEN.pop()
		for to in E[x]:
			if AEVEN[to] == -1:
				AEVEN[to] = count
				NEVEN.append(to)
	EVEN = NEVEN
	count += 1
for i in range(n):
	if A[i] % 2 == 1:
		print(AEVEN[i + 1], end=' ')
	else:
		print(AODD[i + 1], end=' ')


def bfs(a, f, g):
	v = [0 if i % 2 == f else -1 for i in a]
	s = [(i, 0) for (i, v) in enumerate(a) if v % 2 == f]
	while len(s):
		ns = []
		for (ci, c) in s:
			for i in g[ci]:
				if v[i] > c + 1 or v[i] == -1:
					v[i] = c + 1
					ns.append((i, c + 1))
		s = ns
	return v

def solve():
	n = int(input())
	a = list(map(int, input().split(' ')))
	g = list(map(set, [[]] * n))
	for (i, v) in enumerate(a):
		if i - v >= 0:
			g[i - v].add(i)
		if i + v < len(a):
			g[i + v].add(i)
	g = list(map(list, g))
	(o, e) = (bfs(a, 0, g), bfs(a, 1, g))
	print(*map(sum, zip(o, e)))
solve()


from collections import deque
n = int(input())
a = list(map(int, input().split()))
ans = [-1 for _ in range(n)]
graph = [[] for _ in range(n)]
que = deque([])
for (i, x) in enumerate(a):
	t = False
	if i + x < n:
		if a[i + x] % 2 != a[i] % 2:
			ans[i] = 1
			t = True
		graph[i + x].append(i)
	if i - x >= 0:
		if a[i - x] % 2 != a[i] % 2:
			ans[i] = 1
			t = True
		graph[i - x].append(i)
	if t:
		que.append(i)
while len(que) > 0:
	now = que.popleft()
	for ne in graph[now]:
		if ans[ne] == -1:
			ans[ne] = ans[now] + 1
			que.append(ne)
print(*ans)


from sys import stdin, stdout
from collections import deque
n = int(stdin.readline().strip())
alist = list(map(int, stdin.readline().split()))
nop = {}
p = [set() for _ in range(n)]

def back(next):
	while next:
		(i, c) = next.popleft()
		if c < nop[i]:
			nop[i] = c
			c += 1
			for j in p[i]:
				next.append((j, c))

def bfs(x):
	if x not in nop:
		next = deque([x])
		pr = alist[x] % 2
		nop[x] = n
		while next:
			i = next.popleft()
			for j in [i - alist[i], i + alist[i]]:
				if j >= 0 and j < n:
					p[j].add(i)
					if alist[j] % 2 != pr:
						back(deque([(i, 1)]))
					elif j in nop:
						back(deque([(i, nop[j] + 1)]))
					else:
						nop[j] = n
						next.append(j)
	return nop[x] if nop[x] < n else -1
stdout.write(' '.join((str(bfs(x)) for x in range(n))))


n = int(input())
a = list(map(int, input().split()))
e = [[] for i in range(n)]
for i in range(n):
	v = a[i]
	if i - v >= 0:
		e[i - v].append(i)
	if i + v < n:
		e[i + v].append(i)
q = [0] * n
res = [-1] * n
for rem in range(2):
	d = [None] * n
	ql = 0
	qr = 0
	for i in range(n):
		if a[i] % 2 == rem:
			q[qr] = i
			qr += 1
			d[i] = 0
	while ql < qr:
		x = q[ql]
		ql += 1
		dd = d[x] + 1
		for v in e[x]:
			if d[v] is None:
				d[v] = dd
				res[v] = dd
				q[qr] = v
				qr += 1
print(*res)


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 = inpl()
res = [-1] * n
q = deque([])
g = [[] for _ in range(n)]
for (i, x) in enumerate(a):
	ok = 0
	if i - x >= 0:
		g[i - x].append(i)
		if x % 2 != a[i - x] % 2:
			ok = 1
	if i + x < n:
		g[i + x].append(i)
		if x % 2 != a[i + x] % 2:
			ok = 1
	if ok:
		q.append(i)
		res[i] = 1
while q:
	v = q.popleft()
	for u in g[v]:
		if res[u] == -1:
			res[u] = res[v] + 1
			q.append(u)
print(*res)


from collections import deque

def main():
	n = int(input())
	a = readIntArr()
	backwards = [[] for _ in range(n)]
	ans = [inf for _ in range(n)]
	q = deque()
	for i in range(n):
		x = i - a[i]
		if x >= 0:
			if a[i] % 2 == a[x] % 2:
				backwards[x].append(i)
			else:
				ans[i] = 1
				q.append([i, 1])
		y = i + a[i]
		if y < n:
			if a[i] % 2 == a[y] % 2:
				backwards[y].append(i)
			else:
				ans[i] = 1
				q.append([i, 1])
	while q:
		(node, d) = q.popleft()
		for nex in backwards[node]:
			if ans[nex] == inf:
				ans[nex] = d + 1
				q.append([nex, d + 1])
	for i in range(n):
		if ans[i] == inf:
			ans[i] = -1
	oneLineArrayPrint(ans)
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

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

def makeArr(defaultVal, dimensionArr):
	dv = defaultVal
	da = dimensionArr
	if len(da) == 1:
		return [dv for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(x, y):
	print('? {} {}'.format(x, y))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(ans))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()


import sys
input = sys.stdin.readline
from collections import *

def bfs(s):
	q = deque([])
	dist = [-1] * n
	for i in range(n):
		if a[i] % 2 == s:
			q.append(i)
			dist[i] = 0
	while q:
		v = q.popleft()
		for nv in G[v]:
			if dist[nv] == -1:
				dist[nv] = dist[v] + 1
				q.append(nv)
	return dist
n = int(input())
a = list(map(int, input().split()))
G = [[] for _ in range(n)]
for i in range(n):
	s = i
	t1 = i - a[i]
	t2 = i + a[i]
	if t1 >= 0:
		G[t1].append(s)
	if t2 < n:
		G[t2].append(s)
to_even = bfs(0)
to_odd = bfs(1)
ans = []
for i in range(n):
	if a[i] % 2 == 0:
		ans.append(to_odd[i])
	else:
		ans.append(to_even[i])
print(*ans)


from math import inf
n = int(input())
l = [-1]
l.extend(list(map(int, input().split())))
g = [[] for _ in range(n + 1)]
for i in range(1, n + 1):
	if i + l[i] <= n:
		g[i + l[i]].append(i)
	if i - l[i] > 0:
		g[i - l[i]].append(i)
ans = [-1] * n

def bfs(v):
	vis = [0] * (n + 1)
	q = []
	for i in range(1, n + 1):
		if l[i] % 2 == v:
			q.append((i, 0))
	pos = 0
	while len(q) > pos:
		(i, dis) = q[pos]
		pos += 1
		if vis[i] == 1:
			continue
		vis[i] = 1
		if not l[i] % 2 == v:
			ans[i - 1] = dis
		for j in g[i]:
			q.append((j, dis + 1))
bfs(0)
bfs(1)
print(*ans)


n = int(input())
a = list(map(int, input().strip().split()))
r = [-1] * n
e = [[] for i in range(n)]
for (i, v) in enumerate(a):
	if i - v >= 0:
		e[i - v].append(i)
	if i + v < n:
		e[i + v].append(i)
from collections import deque
b1 = deque()
t = [-1] * n
for (i, v) in enumerate(a):
	if v & 1:
		b1.append(i)
		t[i] = 0
while b1:
	p = b1.popleft()
	for i in e[p]:
		if t[i] < 0:
			t[i] = t[p] + 1
			b1.append(i)
for (i, v) in enumerate(a):
	if not v & 1:
		r[i] = t[i]
b2 = deque()
t = [-1] * n
for (i, v) in enumerate(a):
	if not v & 1:
		b2.append(i)
		t[i] = 0
while b2:
	p = b2.popleft()
	for i in e[p]:
		if t[i] < 0:
			t[i] = t[p] + 1
			b2.append(i)
for (i, v) in enumerate(a):
	if v & 1:
		r[i] = t[i]
print(*r)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)
from math import inf
from collections import deque

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [-1] * n
	oof = [[] for __ in range(n)]
	oof2 = [[] for __ in range(n)]
	(q1, q2) = (deque(), deque())
	for i in range(n):
		if a[i] % 2:
			q2.append(i)
			if i + a[i] < n:
				oof2[i + a[i]] += [i]
			if i - a[i] >= 0:
				oof2[i - a[i]] += [i]
		else:
			q1.append(i)
			if i + a[i] < n:
				oof[i + a[i]] += [i]
			if i - a[i] >= 0:
				oof[i - a[i]] += [i]
	(ans1, ans2) = ([0] * n, [0] * n)
	while q1:
		next = q1.popleft()
		for each in oof2[next]:
			if not ans1[each]:
				ans1[each] = ans1[next] + 1
				q1.append(each)
	while q2:
		next = q2.popleft()
		for each in oof[next]:
			if not ans2[each]:
				ans2[each] = ans2[next] + 1
				q2.append(each)
	for i in range(n):
		if a[i] % 2 and ans1[i] or (not a[i] % 2 and ans2[i]):
			ans[i] = max(ans1[i], ans2[i])
	print(*ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

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

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	n = N()
	arr = RLL()
	gp = [[] for _ in range(n + 1)]
	evq = deque()
	odq = deque()
	rece = [INF] * (n + 1)
	reco = [INF] * (n + 1)
	for i in range(n):
		now = i + 1
		(pre, suf) = (now - arr[i], now + arr[i])
		if pre >= 1:
			gp[pre].append(now)
		if suf <= n:
			gp[suf].append(now)
		if arr[i] % 2 == 0:
			evq.append(now)
			rece[now] = 0
		else:
			odq.append(now)
			reco[now] = 0
	while evq:
		now = evq.popleft()
		for nex in gp[now]:
			if rece[nex] > rece[now] + 1:
				evq.append(nex)
				rece[nex] = rece[now] + 1
	while odq:
		now = odq.popleft()
		for nex in gp[now]:
			if reco[nex] > reco[now] + 1:
				odq.append(nex)
				reco[nex] = reco[now] + 1
	res = []
	for i in range(n):
		if arr[i] % 2 == 0:
			res.append(reco[i + 1] if reco[i + 1] != INF else -1)
		else:
			res.append(rece[i + 1] if rece[i + 1] != INF else -1)
	print(*res)
main()


from collections import deque
n = int(input())
a = list(map(int, input().split()))
to = [[] for i in range(n + 3)]
for i in range(n):
	if i + 1 + a[i] <= n:
		to[i + 1 + a[i]].append(i + 1)
	if i + 1 - a[i] > 0:
		to[i + 1 - a[i]].append(i + 1)
for i in range(1, n + 1):
	if a[i - 1] % 2 == 0:
		to[n + 2].append(i)
	else:
		to[n + 1].append(i)
evendist = [10 ** 15] * (n + 3)
evendist[n + 1] = 0
que = deque([n + 1])
while que:
	v = que.popleft()
	if v == n + 1:
		for nv in to[v]:
			if evendist[nv] > evendist[v]:
				evendist[nv] = evendist[v]
				que.appendleft(nv)
	else:
		for nv in to[v]:
			if evendist[nv] > evendist[v] + 1:
				evendist[nv] = evendist[v] + 1
				que.append(nv)
odddist = [10 ** 15] * (n + 3)
odddist[n + 2] = 0
que = deque([n + 2])
while que:
	v = que.popleft()
	if v == n + 2:
		for nv in to[v]:
			if odddist[nv] > odddist[v]:
				odddist[nv] = odddist[v]
				que.appendleft(nv)
	else:
		for nv in to[v]:
			if odddist[nv] > odddist[v] + 1:
				odddist[nv] = odddist[v] + 1
				que.append(nv)
ans = [0] * n
for i in range(n):
	if a[i] % 2 == 0:
		ans[i] = evendist[i + 1]
		if ans[i] == 10 ** 15:
			ans[i] = -1
	else:
		ans[i] = odddist[i + 1]
		if ans[i] == 10 ** 15:
			ans[i] = -1
print(*ans)


import sys
import time
from collections import deque

def bfs(n, graph, startVertices, endVertices, result):
	distance = [sys.maxsize] * n
	q = deque([])
	for v in startVertices:
		distance[v] = 0
		q.append(v)
	while len(q):
		v = q.popleft()
		for adj in graph[v]:
			if distance[adj] == sys.maxsize:
				distance[adj] = distance[v] + 1
				q.append(adj)
	for v in endVertices:
		if distance[v] != sys.maxsize:
			result[v] = distance[v]

def play(n, arr):
	even = []
	odd = []
	graph = [[] for i in range(0, n)]
	for i in range(0, n):
		a = arr[i]
		if a % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
		leftIndex = i - a
		if leftIndex >= 0:
			graph[leftIndex].append(i)
		rightIndex = i + a
		if rightIndex < n:
			graph[rightIndex].append(i)
	result = [-1] * n
	bfs(n, graph, even, odd, result)
	bfs(n, graph, odd, even, result)
	print(*result)

def play2(n, arr):
	even = []
	odd = []
	graph = [[] for i in range(0, n)]
	for i in range(0, n):
		a = arr[i]
		if a % 2 == 0:
			even.append(i)
		else:
			odd.append(i)
		leftIndex = i - a
		if leftIndex >= 0:
			graph[leftIndex].append(i)
		rightIndex = i + a
		if rightIndex < n:
			graph[rightIndex].append(i)
	result = [-1] * n
	bfs(n, graph, even, odd, result)

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	play(n, arr)
main()


n = int(input())
m = list(map(int, input().split()))
from collections import defaultdict, deque
g = defaultdict(list)
a = [float('inf')] * n
for i in range(1, n + 1):
	if i + m[i - 1] <= n:
		g[i + m[i - 1]].append(i)
	if i - m[i - 1] > 0:
		g[i - m[i - 1]].append(i)
q = deque()
vis = [0] * n
for i in range(n):
	if m[i] % 2:
		q.append((i + 1, 0))
		vis[i] = 1
while q:
	(cur, d) = q.popleft()
	for i in g[cur]:
		if m[i - 1] % 2 == 0:
			a[i - 1] = min(a[i - 1], d + 1)
		if vis[i - 1] == 0:
			q.append((i, d + 1))
			vis[i - 1] = 1
p = deque()
vis = [0] * n
for i in range(n):
	if m[i] % 2 == 0:
		p.append((i + 1, 0))
		vis[i] = 1
while p:
	(cur, d) = p.popleft()
	for i in g[cur]:
		if m[i - 1] % 2:
			a[i - 1] = min(a[i - 1], d + 1)
		if vis[i - 1] == 0:
			p.append((i, d + 1))
			vis[i - 1] = 1
for i in range(n):
	if a[i] == float('inf'):
		a[i] = -1
print(*a)


class Graph:

	def __init__(self, V):
		self.V = V
		self.adj_list = [[] for u in range(V)]
		self.edges = []

	def add_edge(self, edge):
		self.edges.append(edge)

	def add_neighdor(self, v1, v2):
		self.adj_list[v1].append(v2)

	def get_neighdor(self, v):
		return self.adj_list[v]
input()
n = map(int, input().split())
n = list(n)
ans = len(n) * [-1]
queue = []
graph = Graph(len(n))
for i in range(len(n)):
	for v in (i - n[i], i + n[i]):
		if 0 <= v < len(n):
			if n[i] % 2 != n[v] % 2:
				ans[i] = 1
				queue.append(i)
			else:
				graph.add_edge((v, i))
				graph.add_neighdor(v, i)
index = 0
while len(queue) > index:
	v = queue[index]
	for i in graph.get_neighdor(v):
		if ans[i] == -1:
			ans[i] = ans[v] + 1
			queue.append(i)
	index += 1
print(*ans)


import sys
input = sys.stdin.readline
import heapq

def dijkstra(start: int, graph: list) -> list:
	INF = 10 ** 18
	n = len(graph)
	dist = [INF] * n
	dist[start] = 0
	q = [(0, start)]
	cost = 1
	while q:
		(d, v) = heapq.heappop(q)
		if dist[v] < d:
			continue
		for nxt_v in graph[v]:
			if dist[v] + cost < dist[nxt_v]:
				dist[nxt_v] = dist[v] + cost
				heapq.heappush(q, (dist[nxt_v], nxt_v))
	return dist
n = int(input())
a = list(map(int, input().split()))
INF = 10 ** 18
rev_graph = [[] for i in range(n + 1)]
for v in range(n):
	nxt_vs = [v - a[v], v + a[v]]
	for nxt_v in nxt_vs:
		if not 0 <= nxt_v < n:
			continue
		if a[v] % 2 == a[nxt_v] % 2:
			rev_graph[nxt_v].append(v)
		else:
			rev_graph[n].append(v)
dist = dijkstra(n, rev_graph)
for i in range(n):
	if dist[i] == INF:
		dist[i] = -1
print(*dist[0:n])


import sys
import math
import itertools
import heapq
import collections
import bisect
import string

def input():
	return sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
mod = 10 ** 9 + 7
ans = 0
count = 0
pro = 1
n = int(input())
A = list(map(int, input().split()))
graph = [[] for i in range(n)]
ans = [-1] * n
que0 = collections.deque()

def newbfs():
	while que0:
		node = que0.popleft()
		for to in graph[node]:
			if ans[to] == -1:
				ans[to] = ans[node] + 1
				que0.append(to)
for i in range(n):
	t = False
	if i + A[i] < n:
		if A[i] % 2 != A[i + A[i]] % 2:
			ans[i] = 1
			t = True
		graph[i + A[i]].append(i)
	if 0 <= i - A[i]:
		if A[i] % 2 != A[i - A[i]] % 2:
			ans[i] = 1
			t = True
		graph[i - A[i]].append(i)
	if t:
		que0.append(i)
newbfs()
print(*ans)


from collections import deque
n = int(input())
a = list(map(int, input().split()))
d = [-1] * n
nb = [[] for i in range(n)]
for i in range(n):
	for j in [i - a[i], i + a[i]]:
		if 0 <= j < n:
			if a[i] & 1 == a[j] & 1:
				nb[j].append(i)
			else:
				d[i] = 1
queue = deque()
for i in range(n):
	if d[i] == 1:
		queue.append(i)
while len(queue) > 0:
	cur = queue.popleft()
	for x in nb[cur]:
		if d[x] == -1:
			d[x] = d[cur] + 1
			queue.append(x)
print(*d)


n = int(input())
a = list(map(int, input().split()))

def go(parity):
	que = list(filter(lambda x: a[x] % 2 == parity, range(n)))
	index = 0
	v = [None] * n
	done = [False] * n
	for i in que:
		done[i] = True
		v[i] = 0
	while index < len(que):
		curr = que[index]
		for e in edges[curr]:
			if not done[e]:
				v[e] = v[curr] + 1
				done[e] = True
				que.append(e)
		index += 1
	return v
edges = [[] for i in range(n)]
for (i, aa) in enumerate(a):
	if i - aa >= 0:
		edges[i - aa].append(i)
	if i + aa < n:
		edges[i + aa].append(i)
v0 = go(0)
v1 = go(1)
res = [v0[i] if a[i] % 2 else v1[i] for i in range(n)]
res = [-1 if rr is None else rr for rr in res]
print(' '.join(map(str, res)))


from collections import deque
import sys
input = sys.stdin.buffer.readline
n = int(input())
x = list(map(int, input().split()))
co = [-1 for i in range(n)]
invind = [[] for i in range(n)]
seen = set()
tosee = set()
level = 1
for i in range(n):
	ok = False
	if x[i] + i < n:
		invind[x[i] + i].append(i)
		if (x[x[i] + i] - x[i]) % 2 == 1:
			co[i] = 1
			tosee.add(i)
			ok = True
	if i - x[i] >= 0:
		invind[i - x[i]].append(i)
		if not ok and (x[i - x[i]] - x[i]) % 2 == 1:
			co[i] = 1
			tosee.add(i)
coooo = 2
while tosee:
	later = list(tosee)
	tosee = set()
	for x in later:
		seen.add(x)
		for zz in invind[x]:
			if zz not in seen:
				tosee.add(zz)
				if co[zz] == -1:
					co[zz] = coooo
	coooo += 1
print(' '.join(map(str, co)))


from collections import deque
n = int(input())
a = [int(i) for i in input().split()]
graph = [[] for i in range(n)]
ans = [-1] * n
for i in range(n):
	for j in [i - a[i], i + a[i]]:
		if 0 <= j < n:
			if a[i] % 2 == a[j] % 2:
				graph[j].append(i)
			else:
				ans[i] = 1
q = deque()
for i in range(n):
	if ans[i] == 1:
		q.append(i)
while len(q) > 0:
	curr = q.popleft()
	for i in graph[curr]:
		if ans[i] == -1:
			ans[i] = ans[curr] + 1
			q.append(i)
print(*ans)


n = int(input())
odd = []
even = []
g = [[] for i in range(n)]
l = [int(x) for x in input().split()]
ans = [-1 for i in range(n)]

def bfs(start, end):
	d = [-2 for i in range(n)]
	q = []
	qi = 0
	for i in range(len(start)):
		d[start[i]] = 0
		q.append(start[i])
	while len(q) != qi:
		f = q[qi]
		qi += 1
		for daughter in g[f]:
			if d[daughter] == -2:
				d[daughter] = 1 + d[f]
				q.append(daughter)
	for i in range(n):
		if d[i] != -2 and d[i] != 0:
			ans[i] = d[i]
	return ans
for i in range(n):
	left = i - l[i]
	right = i + l[i]
	if left >= 0:
		g[left].append(i)
	if right < n:
		g[right].append(i)
	if l[i] & 1:
		odd.append(i)
	else:
		even.append(i)
bfs(odd, even)
bfs(even, odd)
print(*ans)


import sys
from sys import stdin
from collections import deque
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
lis = [[] for i in range(n)]
d = [float('inf')] * n
q = deque([])
for i in range(n):
	if 0 <= i - a[i] and a[i] % 2 != a[i - a[i]] % 2 or (i + a[i] < n and a[i] % 2 != a[i + a[i]] % 2):
		d[i] = 1
		q.append(i)
	else:
		if i - a[i] >= 0:
			lis[i - a[i]].append(i)
		if i + a[i] < n:
			lis[i + a[i]].append(i)
while q:
	v = q.popleft()
	for nex in lis[v]:
		if d[nex] > d[v] + 1:
			d[nex] = d[v] + 1
			q.append(nex)
for i in range(n):
	if d[i] == float('inf'):
		d[i] = -1
print(*d)


from collections import deque
n = int(input())
arr = list(map(int, input().split(' ')))
even = []
odd = []
graph = dict(((i, list()) for i in range(n)))
ans = {}

def bfs(start, end):
	queue = deque()
	distances = {}
	for s in start:
		queue.append(s)
		distances[s] = 0
	while queue:
		idx = queue.popleft()
		for to in graph[idx]:
			if to not in distances:
				distances[to] = distances[idx] + 1
				queue.append(to)
			else:
				assert distances[to] <= distances[idx] + 1
	for e in end:
		if e in distances:
			ans[e] = distances[e]
for (idx, a) in enumerate(arr):
	if a % 2 == 0:
		even.append(idx)
	else:
		odd.append(idx)
	left = idx - a
	right = idx + a
	if left >= 0:
		graph[left].append(idx)
	if right < n:
		graph[right].append(idx)
bfs(even, odd)
bfs(odd, even)
for i in range(n):
	if i not in ans:
		ans[i] = -1
	print(ans[i], end=' ')
print()