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).

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$$$.

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.

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60
const INF_INT32 = math.MaxInt32
const INF_BIT30 = 1 << 30

var n int
var A []int

var G [200000 + 5][]int
var answers []int

func main() {
	n = ReadInt()
	A = ReadIntSlice(n)

	for i := 0; i < n; i++ {
		lid, rid := i-A[i], i+A[i]
		if lid >= 0 {
			G[lid] = append(G[lid], i)
		}
		if rid < n {
			G[rid] = append(G[rid], i)
		}
	}

	oddIdxs, evenIdxs := []int{}, []int{}
	for i := 0; i < n; i++ {
		if A[i]%2 == 0 {
			evenIdxs = append(evenIdxs, i)
		} else {
			oddIdxs = append(oddIdxs, i)
		}
	}

	answers = make([]int, n)
	for i := 0; i < n; i++ {
		answers[i] = -1
	}

	bfs(oddIdxs, evenIdxs)
	bfs(evenIdxs, oddIdxs)

	fmt.Println(PrintIntsLine(answers...))
}

func bfs(starts, ends []int) {
	dist := make([]int, n)
	for i := 0; i < n; i++ {
		dist[i] = INF_BIT30
	}

	queue := []int{}
	for _, sidx := range starts {
		dist[sidx] = 0
		queue = append(queue, sidx)
	}

	for len(queue) > 0 {
		cid := queue[0]
		queue = queue[1:]

		for _, nid := range G[cid] {
			if dist[nid] == INF_BIT30 {
				dist[nid] = dist[cid] + 1
				queue = append(queue, nid)
			}
		}
	}

	for _, eidx := range ends {
		if dist[eidx] != INF_BIT30 {
			answers[eidx] = dist[eidx]
		}
	}
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
*/

/*******************************************************************/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60
const INF_INT32 = math.MaxInt32
const INF_BIT30 = 1 << 30

var n int
var A []int

var G [200000 + 5][]int
var answers []int

func main() {
	n = ReadInt()
	A = ReadIntSlice(n)

	for i := 0; i < n; i++ {
		lid, rid := i-A[i], i+A[i]
		if lid >= 0 {
			// G[i] = append(G[i], lid)
			G[lid] = append(G[lid], i)
		}
		if rid < n {
			// G[i] = append(G[i], rid)
			G[rid] = append(G[rid], i)
		}
	}

	oddIdxs, evenIdxs := []int{}, []int{}
	for i := 0; i < n; i++ {
		if A[i]%2 == 0 {
			evenIdxs = append(evenIdxs, i)
		} else {
			oddIdxs = append(oddIdxs, i)
		}
	}

	answers = make([]int, n)
	for i := 0; i < n; i++ {
		answers[i] = -1
	}

	bfs(oddIdxs, evenIdxs)
	bfs(evenIdxs, oddIdxs)

	fmt.Println(PrintIntsLine(answers...))
}

func bfs(starts, ends []int) {
	dist := make([]int, n)
	for i := 0; i < n; i++ {
		dist[i] = INF_BIT30
	}

	queue := []int{}
	for _, sidx := range starts {
		dist[sidx] = 0
		queue = append(queue, sidx)
	}

	for len(queue) > 0 {
		cid := queue[0]
		queue = queue[1:]

		for _, nid := range G[cid] {
			if dist[nid] == INF_BIT30 {
				dist[nid] = dist[cid] + 1
				queue = append(queue, nid)
			}
		}
	}

	for _, eidx := range ends {
		if dist[eidx] != INF_BIT30 {
			answers[eidx] = dist[eidx]
		}
	}
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
*/

/*******************************************************************/

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

type Graph struct {
	Edges       map[int][]int
	Odd         []int
	Even        []int
	Result      map[int]int
	NumVertices int
}

func parity(arr []int, i, j int) bool {
	if (arr[i] & 1) != (arr[j] & 1) {
		return true
	}
	return false
}

func search(source, dest []int, g *Graph) {
	d := make(map[int]int)
	for i := 1; i <= g.NumVertices; i++ {
		d[i] = math.MaxInt32
	}
	queue := make([]int, 0)
	for _, idx := range source {
		d[idx] = 0
		queue = append(queue, idx)
	}
	for len(queue) != 0 {
		u := queue[0]
		queue = queue[1:]
		for _, v := range g.Edges[u] {
			if d[v] == math.MaxInt32 {
				d[v] = d[u] + 1
				queue = append(queue, v)
			}
		}
	}
	for _, u := range dest {
		if d[u] != math.MaxInt32 {
			g.Result[u] = d[u]
		}
	}

}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_RDWR|os.O_CREATE, 0777)
	//reader := bufio.NewReader(iFile)
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, temp int
	fmt.Fscanf(reader, "%d\n", &n)
	arr := make([]int, n+1)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &temp)
		arr[i] = temp
	}
	fmt.Fscanf(reader, "\n")
	g := Graph{Edges: make(map[int][]int), Odd: make([]int, 0), Even: make([]int, 0), Result: make(map[int]int, 0), NumVertices: n}
	for i := 1; i <= n; i++ {
		if (arr[i] & 1) == 0 {
			g.Even = append(g.Even, i)
		} else {
			g.Odd = append(g.Odd, i)
		}
		g.Result[i] = -1
	}
	for i := 1; i <= n; i++ {
		temp = i - arr[i]
		if temp >= 1 {
			if _, ok := g.Edges[temp]; !ok {
				g.Edges[temp] = make([]int, 0)
			}
			g.Edges[temp] = append(g.Edges[temp], i)
		}
		temp = i + arr[i]
		if temp <= n {
			if _, ok := g.Edges[temp]; !ok {
				g.Edges[temp] = make([]int, 0)
			}
			g.Edges[temp] = append(g.Edges[temp], i)
		}
	}
	search(g.Odd, g.Even, &g)
	search(g.Even, g.Odd, &g)
	for i := 1; i <= n; i++ {
		if i != n {
			fmt.Fprintf(writer, "%d ", g.Result[i])
		} else {
			fmt.Fprintf(writer, "%d\n", g.Result[i])
		}
	}

}

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60
const INF_INT32 = math.MaxInt32
const INF_BIT30 = 1 << 30

var n int
var A []int

var G [200000 + 5][]int
var answers []int

func main() {
	n = ReadInt()
	A = ReadIntSlice(n)

	// 順方向で頑張りたい
	for i := 0; i < n; i++ {
		lid, rid := i-A[i], i+A[i]
		if lid >= 0 {
			G[i] = append(G[i], lid)
		}
		if rid < n {
			G[i] = append(G[i], rid)
		}
	}

	oddIdxs, evenIdxs := []int{}, []int{}
	for i := 0; i < n; i++ {
		if A[i]%2 == 0 {
			evenIdxs = append(evenIdxs, i)
		} else {
			oddIdxs = append(oddIdxs, i)
		}
	}

	answers = make([]int, n)
	for i := 0; i < n; i++ {
		answers[i] = -1
	}

	bfs(oddIdxs, evenIdxs)
	bfs(evenIdxs, oddIdxs)

	fmt.Println(PrintIntsLine(answers...))
}

type Node struct {
	dist, sidx int
}

func bfs(starts, ends []int) {
	// 距離とともに起点をもたせておけば順方向でも頑張れそう
	dist := make([]Node, n)
	for i := 0; i < n; i++ {
		dist[i] = Node{dist: INF_BIT30, sidx: -1}
	}

	queue := []int{}
	for _, sidx := range starts {
		dist[sidx].dist = 0
		dist[sidx].sidx = sidx
		queue = append(queue, sidx)
	}

	for len(queue) > 0 {
		cid := queue[0]
		queue = queue[1:]

		for _, nid := range G[cid] {
			if dist[nid].dist == INF_BIT30 {
				// **ここにはいろんな起点から到達できるけど、一番乗りの起点に専有されてしまうから無理**
				dist[nid].dist = dist[cid].dist + 1
				dist[nid].sidx = dist[cid].sidx
				queue = append(queue, nid)
			}
		}
	}

	for _, eidx := range ends {
		if dist[eidx].dist != INF_BIT30 {
			s, d := dist[eidx].sidx, dist[eidx].dist
			answers[s] = d
		}
	}
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
*/

/*******************************************************************/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n int
var A []int

var answers []int
var flag []bool

func main() {
	n = ReadInt()
	A = ReadIntSlice(n)

	answers, flag = make([]int, n), make([]bool, n)

	for i := 0; i < n; i++ {
		if answers[i] == 0 {
			answers[i] = dfs(i)
		}
	}

	for i := 0; i < n; i++ {
		if answers[i] >= INIT_MAX {
			answers[i] = -1
		}
	}

	fmt.Println(PrintIntsLine(answers...))
}

const INIT_MAX = 1000000

func dfs(cid int) int {
	// 答えがわかっているならそのまま返す
	if answers[cid] != 0 {
		return answers[cid]
	}
	// ループに組み込まれている場合はimpossible
	if flag[cid] {
		answers[cid] = INIT_MAX
		return answers[cid]
	}
	flag[cid] = true

	// 左右をチェック
	lid, rid := cid-A[cid], cid+A[cid]
	ans := INIT_MAX
	if lid >= 0 {
		if A[lid]%2 != A[cid]%2 {
			ChMin(&ans, 1)
		} else {
			lans := dfs(lid)
			if lans != -1 {
				ChMin(&ans, lans+1)
			}
		}
	}
	if rid < n {
		if A[rid]%2 != A[cid]%2 {
			ChMin(&ans, 1)
		} else {
			rans := dfs(rid)
			if rans != -1 {
				ChMin(&ans, rans+1)
			}
		}
	}

	if ans >= INIT_MAX {
		answers[cid] = INIT_MAX
	} else {
		answers[cid] = ans
	}
	return answers[cid]
}

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
*/

/*******************************************************************/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60
const INF_INT32 = math.MaxInt32
const INF_BIT30 = 1 << 30

var n int
var A []int

var G [200000 + 5][]int
var answers []int

func main() {
	n = ReadInt()
	A = ReadIntSlice(n)

	// 順方向で頑張る
	for i := 0; i < n; i++ {
		lid, rid := i-A[i], i+A[i]
		if lid >= 0 {
			G[i] = append(G[i], lid)
		}
		if rid < n {
			G[i] = append(G[i], rid)
		}
	}

	oddIdxs, evenIdxs := []int{}, []int{}
	for i := 0; i < n; i++ {
		if A[i]%2 == 0 {
			evenIdxs = append(evenIdxs, i)
		} else {
			oddIdxs = append(oddIdxs, i)
		}
	}

	answers = make([]int, n)
	for i := 0; i < n; i++ {
		answers[i] = -1
	}

	bfs(oddIdxs, evenIdxs)
	bfs(evenIdxs, oddIdxs)

	fmt.Println(PrintIntsLine(answers...))
}

type Node struct {
	dist, sidx int
}

func bfs(starts, ends []int) {
	// 距離とともに起点をもたせておけば順方向でも頑張れる
	dist := make([]Node, n)
	for i := 0; i < n; i++ {
		dist[i] = Node{dist: INF_BIT30, sidx: -1}
	}

	queue := []int{}
	for _, sidx := range starts {
		dist[sidx].dist = 0
		dist[sidx].sidx = sidx
		queue = append(queue, sidx)
	}

	for len(queue) > 0 {
		cid := queue[0]
		queue = queue[1:]

		for _, nid := range G[cid] {
			if dist[nid].dist == INF_BIT30 {
				dist[nid].dist = dist[cid].dist + 1
				dist[nid].sidx = cid
				queue = append(queue, nid)
			}
		}
	}

	for _, eidx := range ends {
		if dist[eidx].dist != INF_BIT30 {
			s, d := dist[eidx].sidx, dist[eidx].dist
			answers[s] = d
		}
	}
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
*/

/*******************************************************************/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60
const INF_INT32 = math.MaxInt32
const INF_BIT30 = 1 << 30

var n int
var A []int

var G [200000 + 5][]int
var answers []int

func main() {
	n = ReadInt()
	A = ReadIntSlice(n)

	for i := 0; i < n; i++ {
		lid, rid := i-A[i], i+A[i]
		if lid >= 0 {
			G[i] = append(G[i], lid)
		}
		if rid < n {
			G[i] = append(G[i], rid)
		}
	}

	oddIdxs, evenIdxs := []int{}, []int{}
	for i := 0; i < n; i++ {
		if A[i]%2 == 0 {
			evenIdxs = append(evenIdxs, i)
		} else {
			oddIdxs = append(oddIdxs, i)
		}
	}

	answers = make([]int, n)
	for i := 0; i < n; i++ {
		answers[i] = -1
	}

	bfs(oddIdxs, evenIdxs)
	bfs(evenIdxs, oddIdxs)

	fmt.Println(PrintIntsLine(answers...))
}

func bfs(starts, ends []int) {
	dist := make([]int, n)
	for i := 0; i < n; i++ {
		dist[i] = INF_BIT30
	}

	queue := []int{}
	for _, sidx := range starts {
		dist[sidx] = 0
		queue = append(queue, sidx)
	}

	for len(queue) > 0 {
		cid := queue[0]
		queue = queue[1:]

		for _, nid := range G[cid] {
			if dist[nid] == INF_BIT30 {
				dist[nid] = dist[cid] + 1
				queue = append(queue, nid)
			}
		}
	}

	for _, eidx := range ends {
		if dist[eidx] != INF_BIT30 {
			answers[eidx] = dist[eidx]
		}
	}
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
*/

/*******************************************************************/

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, temp int
	fmt.Fscanf(reader, "%d\n", &n)
	arr := make([]int, n+1)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &temp)
		arr[i] = temp
	}
	fmt.Fscanf(reader, "\n")
	for i := 1; i <= n; i++ {
		visited := make([]bool, n+1)
		moves := 0
		visited[i] = true
		j := i
		for {
			if (j+arr[j]) <= n && visited[j+arr[j]] == false {
				j = j + arr[j]
				visited[j] = true
			} else if (j-arr[j]) >= 1 && visited[j-arr[j]] == false {
				j = j - arr[j]
				visited[j] = true

			} else {
				break
			}

			moves = moves + 1
			if ((arr[i]&1 == 0) && (arr[j]&1 == 1)) || ((arr[i]&1 == 1) && (arr[j]&1 == 0)) {
				break
			}

		}
		min := -1
		if moves != 0 {
			min = moves
		}
		if i != n {
			fmt.Fprintf(writer, "%d ", min)
		} else {
			fmt.Fprintf(writer, "%d\n", min)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var cache map[int]map[int]int

func updateCache(u, v, moves int) {
	if _, ok := cache[u]; !ok {
		cache[u] = make(map[int]int)
	}
	cache[u][v] = moves
}

func parity(arr []int, i, j int) bool {
	if ((arr[i]&1 == 0) && (arr[j]&1 == 1)) || ((arr[i]&1 == 1) && (arr[j]&1 == 0)) {
		return true
	}
	return false
}

func search(arr []int, i, n int) int {
	queue := make([]int, 0)
	queue = append(queue, i)
	dist := make(map[int]int)
	dist[i] = 0
	var temp int
	for len(queue) != 0 {
		v := queue[0]
		queue = queue[1:]
		if (v + arr[v]) <= n {
			temp = v + arr[v]
			if _, ok := dist[temp]; !ok {
				if parity(arr, i, temp) {
					updateCache(i, temp, dist[v]+1)
					return dist[v] + 1
				}

				if _, ok := cache[temp]; ok {
					//fmt.Println(v, temp, dist[v], "Printing cache", cache[temp])
					min := math.MaxInt32
					yes := false
					for idx, d := range cache[temp] {
						if parity(arr, i, idx) {
							yes = true
							if min > d {
								min = d
							}
						}
					}
					if yes {
						updateCache(i, temp, min+dist[v]+1)
						return min + dist[v] + 1
					}
				}
				queue = append(queue, temp)
				dist[temp] = dist[v] + 1
				//fmt.Println("Dist", i, temp, arr[i], arr[temp], dist[temp])
				updateCache(i, temp, dist[temp])
				if parity(arr, i, temp) {
					return dist[temp]
				}
			}
		}
		if (v - arr[v]) >= 1 {
			temp = v - arr[v]
			if _, ok := dist[temp]; !ok {
				if parity(arr, i, temp) {
					updateCache(i, temp, dist[v]+1)
					return dist[v] + 1
				}
				if _, ok := cache[temp]; ok {
					//fmt.Println(v, temp, dist[v], "Printing cache", cache[temp])
					min := math.MaxInt32
					yes := false
					for idx, d := range cache[temp] {
						if parity(arr, i, idx) {
							yes = true
							if min > d {
								min = d
							}
						}
					}
					if yes {
						updateCache(i, temp, min+dist[v]+1)
						return min + dist[v] + 1
					}
				}
				queue = append(queue, v-arr[v])
				dist[v-arr[v]] = dist[v] + 1
				//fmt.Println("Dist", i, temp, arr[i], arr[temp], dist[temp])
				updateCache(i, temp, dist[temp])
				if parity(arr, i, temp) {
					return dist[temp]
				}
			}
		}
	}
	//fmt.Println(dist)
	return -1
}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_RDWR|os.O_CREATE, 0777)
	//reader := bufio.NewReader(iFile)
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	cache = make(map[int]map[int]int)
	var n, temp int
	fmt.Fscanf(reader, "%d\n", &n)
	arr := make([]int, n+1)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &temp)
		arr[i] = temp
	}
	fmt.Fscanf(reader, "\n")
	for i := 1; i <= n; i++ {
		if i == n {
			fmt.Fprintf(writer, "%d\n", search(arr, i, n))
		} else {
			fmt.Fprintf(writer, "%d ", search(arr, i, n))
		}
		//fmt.Println(cache)
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var dist map[int]int
var edges map[int][]int
var visited map[int]bool
var queue []int

func parity(arr []int, i, j int) bool {
	if (arr[i] & 1) != (arr[j] & 1) {
		return true
	}
	return false
}

func search(arr []int, n int) {
	for len(queue) != 0 {
		u := queue[0]
		queue = queue[1:]
		for _, v := range edges[u] {
			if !visited[v] {
				//fmt.Println("u v", u, v, dist[u], dist[v])
				if !parity(arr, u, v) {
					dist[v] = dist[u] + 1
					//fmt.Println("u v", u, v, dist[u], dist[v])
					queue = append(queue, v)
					visited[v] = true
				}
			}
		}
	}
	//fmt.Println(dist)
}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_RDWR|os.O_CREATE, 0777)
	//reader := bufio.NewReader(iFile)
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	edges = make(map[int][]int)
	dist = make(map[int]int)
	visited = make(map[int]bool)
	queue = make([]int, 0)
	var n, temp int
	fmt.Fscanf(reader, "%d\n", &n)
	arr := make([]int, n+1)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &temp)
		arr[i] = temp
		dist[i] = -1
		visited[i] = false
	}
	fmt.Fscanf(reader, "\n")
	for i := 1; i <= n; i++ {
		dist[i] = -1
		temp = i - arr[i]
		if temp >= 1 {
			if _, ok := edges[temp]; !ok {
				edges[temp] = make([]int, 0)
			}
			if _, ok := edges[i]; !ok {
				edges[i] = make([]int, 0)
			}
			edges[temp] = append(edges[temp], i)
			edges[i] = append(edges[i], temp)
			if parity(arr, i, temp) {
				dist[i] = 1
				visited[i] = true
				queue = append(queue, i)
			}
		}
		temp = i + arr[i]
		if temp <= n {
			if _, ok := edges[temp]; !ok {
				edges[temp] = make([]int, 0)
			}
			if _, ok := edges[i]; !ok {
				edges[i] = make([]int, 0)
			}
			edges[temp] = append(edges[temp], i)
			edges[i] = append(edges[i], temp)
			if parity(arr, i, temp) {
				dist[i] = 1
				visited[i] = true
				queue = append(queue, i)
			}
		}

	}
	//fmt.Println(edges, visited, dist)
	search(arr, n)
	for i := 1; i <= n-1; i++ {
		fmt.Fprintf(writer, "%d  ", dist[i])
	}
	fmt.Fprintf(writer, "%d\n", dist[n])
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, temp int
	fmt.Fscanf(reader, "%d\n", &n)
	arr := make([]int, n+1)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &temp)
		arr[i] = temp
	}
	fmt.Fscanf(reader, "\n")
	for i := 1; i <= n; i++ {
		visited := make([]bool, n+1)
		moves := 0
		min := math.MaxInt32
		visited[i] = true
		j := i
		for {
			if (j+arr[j]) <= n && visited[j+arr[j]] == false {
				j = j + arr[j]
				visited[j] = true
			} else if (j-arr[j]) >= 1 && visited[j-arr[j]] == false {
				j = j - arr[j]
				visited[j] = true

			} else {
				break
			}

			moves = moves + 1
			if ((arr[i]&1 == 0) && (arr[j]&1 == 1)) || ((arr[i]&1 == 1) && (arr[j]&1 == 0)) {
				j = i
				if min > moves {
					min = moves
				}
				moves = 0
			}

		}
		if min == math.MaxInt32 {
			min = -1
		}

		if i != n {
			fmt.Fprintf(writer, "%d ", min)
		} else {
			fmt.Fprintf(writer, "%d\n", min)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var cache map[int]map[int]int

func updateCache(u, v, moves int) {
	if _, ok := cache[u]; !ok {
		cache[u] = make(map[int]int)
	}
	cache[u][v] = moves
}

func parity(arr []int, i, j int) bool {
	if ((arr[i]&1 == 0) && (arr[j]&1 == 1)) || ((arr[i]&1 == 1) && (arr[j]&1 == 0)) {
		return true
	}
	return false
}

func search(arr []int, i, n int) int {
	queue := make([]int, 0)
	queue = append(queue, i)
	dist := make(map[int]int)
	dist[i] = 0
	var temp int
	for len(queue) != 0 {
		v := queue[0]
		queue = queue[1:]
		if (v + arr[v]) <= n {
			temp = v + arr[v]
			if _, ok := dist[temp]; !ok {
				if parity(arr, i, temp) {
					updateCache(i, temp, dist[v]+1)
					return dist[v] + 1
				}

				if _, ok := cache[temp]; ok {
					//fmt.Println(v, temp, dist[v], "Printing cache", cache[temp])
					min := math.MaxInt32
					yes := false
					for idx, d := range cache[temp] {
						if parity(arr, i, idx) {
							yes = true
							if min > d {
								min = d
							}
						}
					}
					if yes {
						return min + dist[v] + 1
					}
				}
				queue = append(queue, temp)
				dist[temp] = dist[v] + 1
				//fmt.Println("Dist", i, temp, arr[i], arr[temp], dist[temp])
				updateCache(i, temp, dist[temp])
				if parity(arr, i, temp) {
					return dist[temp]
				}
			}
		}
		if (v - arr[v]) >= 1 {
			temp = v - arr[v]
			if _, ok := dist[temp]; !ok {
				if parity(arr, i, temp) {
					updateCache(i, temp, dist[v]+1)
					return dist[v] + 1
				}
				if _, ok := cache[temp]; ok {
					//fmt.Println(v, temp, dist[v], "Printing cache", cache[temp])
					min := math.MaxInt32
					yes := false
					for idx, d := range cache[temp] {
						if parity(arr, i, idx) {
							yes = true
							if min > d {
								min = d
							}
						}
					}
					if yes {
						return min + dist[v] + 1
					}
				}
				queue = append(queue, v-arr[v])
				dist[v-arr[v]] = dist[v] + 1
				//fmt.Println("Dist", i, temp, arr[i], arr[temp], dist[temp])
				updateCache(i, temp, dist[temp])
				if parity(arr, i, temp) {
					return dist[temp]
				}
			}
		}
	}
	//fmt.Println(dist)
	return -1
}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_RDWR|os.O_CREATE, 0777)
	//reader := bufio.NewReader(iFile)
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	cache = make(map[int]map[int]int)
	var n, temp int
	fmt.Fscanf(reader, "%d\n", &n)
	arr := make([]int, n+1)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &temp)
		arr[i] = temp
	}
	fmt.Fscanf(reader, "\n")
	for i := 1; i <= n; i++ {
		if i == n {
			fmt.Fprintf(writer, "%d\n", search(arr, i, n))
		} else {
			fmt.Fprintf(writer, "%d ", search(arr, i, n))
		}
		//fmt.Println(cache)
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"math"
)

type Graph struct {
	Edges  map[int][]int
	Odd    []int
	Even   []int
	Result map[int]int
	NumVertices int
}

func parity(arr []int, i, j int) bool {
	if (arr[i] & 1) != (arr[j] & 1) {
		return true
	}
	return false
}

func search(source, dest []int, g *Graph) {
	d := make(map[int]int)
	for i := 1; i <= g.NumVertices; i++ {
		d[i] = math.MaxInt32
	}
	queue := make([]int, 0)
	for _, idx := range source {
		d[idx] = 0
		queue = append(queue, idx)
	}
	for len(queue) != 0 {
		u := queue[0]
		queue = queue[1:]
		for _, v := range g.Edges[u] {
			if d[v] == math.MaxInt32 {
				d[v] = d[u] + 1
				queue = append(queue, v)
			}
		}
	}
	for _, u := range dest {
		if d[u] != math.MaxInt32 {
			g.Result[u] = d[u]
		}
	}

}

func main() {
	iFile, _ := os.OpenFile("input.txt", os.O_RDWR|os.O_CREATE, 0777)
	reader := bufio.NewReader(iFile)
	//reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, temp int
	fmt.Fscanf(reader, "%d\n", &n)
	arr := make([]int, n+1)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &temp)
		arr[i] = temp
	}
	fmt.Fscanf(reader, "\n")
	g := Graph{Edges: make(map[int][]int), Odd: make([]int, 0), Even: make([]int, 0), Result: make(map[int]int, 0), NumVertices: n}
	for i := 1; i <= n; i++ {
		if (arr[i]&1) == 0 {
			g.Even = append(g.Even, i)
		} else {
			g.Odd = append(g.Odd, i)
		}
		g.Result[i] = -1
	}
	for i := 1; i <= n; i++ {
		temp = i - arr[i]
		if temp >= 1 {
			if _, ok := g.Edges[temp]; !ok {
				g.Edges[temp] = make([]int, 0)
			}
			g.Edges[temp] = append(g.Edges[temp], i)
		}
		temp = i + arr[i]
		if temp <= n {
			if _, ok := g.Edges[temp]; !ok {
				g.Edges[temp] = make([]int, 0)
			}
			g.Edges[temp] = append(g.Edges[temp], i)
		}
	}
	search(g.Odd, g.Even, &g)
	search(g.Even, g.Odd, &g)
	for i := 1; i <= n; i++ {
		if i != n {
			fmt.Fprintf(writer, "%d ", g.Result[i])
		} else {
			fmt.Fprintf(writer, "%d\n", g.Result[i])
		}
	}

}


There are two sisters Alice and Betty. You have $$$n$$$ candies. You want to distribute these $$$n$$$ candies between two sisters in such a way that:  Alice will get $$$a$$$ ($$$a > 0$$$) candies;  Betty will get $$$b$$$ ($$$b > 0$$$) candies;  each sister will get some integer number of candies;  Alice will get a greater amount of candies than Betty (i.e. $$$a > b$$$);  all the candies will be given to one of two sisters (i.e. $$$a+b=n$$$). Your task is to calculate the number of ways to distribute exactly $$$n$$$ candies between sisters in a way described above. Candies are indistinguishable.Formally, find the number of ways to represent $$$n$$$ as the sum of $$$n=a+b$$$, where $$$a$$$ and $$$b$$$ are positive integers and $$$a>b$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of a test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^9$$$) — the number of candies you have.

For each test case, print the answer — the number of ways to distribute exactly $$$n$$$ candies between two sisters in a way described in the problem statement. If there is no way to satisfy all the conditions, print $$$0$$$.

NoteFor the test case of the example, the $$$3$$$ possible ways to distribute candies are:  $$$a=6$$$, $$$b=1$$$;  $$$a=5$$$, $$$b=2$$$;  $$$a=4$$$, $$$b=3$$$.

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		fmt.Println((n - 1) / 2)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n uint64
		fmt.Fscan(in, &n)
		fmt.Fprintln(out, n-n/2-1)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var r__ *bufio.Reader = bufio.NewReader(os.Stdin)
var w__ *bufio.Writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{})  { fmt.Fscanf(r__, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(w__, f, a...) }
func fflush()                           { w__.Flush() }

func solve() {
	var n int
	scanf("%d\n", &n)
	if n == 0 || n == 1 || n == 2 {
		printf("0\n")
		return
	}

	res := n - 1
	if res%2 == 0 {
		printf("%d\n", res/2)
	} else {
		printf("%d\n", (res-1)/2)
	}

}

func main() {
	defer fflush()

	var T, i uint64
	scanf("%d\n", &T)
	for i = 0; i < T; i++ {
		solve()
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		exec()
	}
}

func exec() {
	var n uint64
	scanf("%d %d\n", &n)

	res := n / 2
	if n%2 == 0 {
		res -= 1
	}

	printf("%d\n", res)
}

package main

import(
    "fmt"
    "bufio"
    "os"
    "strconv"
)

func main(){
    var(
        t,a     int
        sc      =bufio.NewScanner(os.Stdin)
    )
    sc.Scan()
    t,_=strconv.Atoi(sc.Text())
    for t>0{
        sc.Scan()
        a,_=strconv.Atoi(sc.Text())
        if a<=2{
            fmt.Println(0)
        }else{
            if a%2==0{
                fmt.Println(a/2-1)
            }else{
                fmt.Println(a/2)
            }
        }
        t--
    }
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	var a int
	for i := 0; i < t; i++ {
		fmt.Scanf("%d\n", &a)
		fmt.Println(solve(a))
	}
}

func solve(a int) int {
    if a == 1 || a == 2 {
        return 0
    }
    if a%2 == 0 {
        return a/2-1
    }
	return a/2
}

package main

import "fmt"

func main()  {
 var  n int
 fmt.Scan(&n)
  var input int
for i := 0; i < n; i++ {
	fmt.Scan(&input)
	fmt.Println((input-1)/2)
}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanln(&t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)

		if n%2 == 0 {
			fmt.Println(n/2 - 1)
		} else {
			fmt.Println(n / 2)
		}
	}
}

package main

import (
    "fmt"
    "bufio"
    "os"
)

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()

    var t, n int
    fmt.Fscan(in, &t)
    for ;t >0; t-- {
        fmt.Fscan(in, &n)
        fmt.Fprintln(out, (n - 1) >> 1)
    }
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strings"
)

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1024 * 1024)
	line := readLine(reader)
	t := 0
	fmt.Sscanf(line, "%d", &t)
	for i := 0; i < t; i++ {
		var d, res int64
		fmt.Sscanf(readLine(reader), "%d", &d)
		if d % 2 == 0 {
			res = (d / 2) - 1
		} else {
			res = d / 2
		}
		fmt.Println(res)
	}
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

import "fmt"

func main() {
	var count int
	fmt.Scan(&count)
	c := 0
	for i := 0; i< count;i++{
		fmt.Scan(&c)
		fmt.Println((c - 1) / 2)
	}

}

package main

import(
	"fmt"
)

func main() {
	res := []uint64{}
	t := 0
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		tmp := uint64(0)
		fmt.Scanf("%d\n", &tmp)
		res = append(res, (tmp - 1)/2)
	}

	for _, x := range res {
		fmt.Println(x)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func solve(n int) int {
	if n < 3 {
		return 0
	}

	return (n - 1) / 2
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var t, n int
	fmt.Fscanf(r, "%d\n", &t)

	for tc := 0; tc < t; tc++ {
		fmt.Fscanf(r, "%d\n", &n)
		fmt.Fprintf(os.Stdout, "%d\n", solve(n))
	}
}

// Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools

package main

import (
  "fmt"
)

func main() {
  var T int
  fmt.Scanf("%d\n", &T)
  for t := 0; t < T; t++ {
    var n int
    fmt.Scanf("%d\n", &n)
    solve(n)
  }
}

func solve(n int) {
  res := (n - 1) / 2
  if res < 0 {
    res = 0
  }
  fmt.Println(res)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	var n uint16
	var t uint32
	fmt.Fscanf(in, "%d\n", &n)
	for i := uint16(0); i < n; i++ {
		fmt.Fscanf(in, "%d\n", &t)
		fmt.Println((t - 1) / 2)
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scanf("%d\n", &n)
		if n <= 2 {
			fmt.Println(0)
		} else {
			if n%2 == 0 {
				fmt.Println(n/2 - 1)
			} else {
				fmt.Println(n / 2)
			}
		}
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		if n <= 2 {
			fmt.Println(0)
		} else {
			if n%2 == 0 {
				fmt.Println(n/2 - 1)
			} else {
				fmt.Println(n / 2)
			}
		}
	}
}

package main

import (
	"fmt"
)

func solve() {
	var conf int
	_, err := fmt.Scanf("%d\n", &conf)
	if err != nil {
		fmt.Println(err)
	}
	if conf > 2 {
		if conf%2 == 0 {
			conf--
		}
		fmt.Println(conf / 2)
	} else {
		fmt.Println(0)
	}
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		var m int
		m = n - int(math.Floor(float64(n) / 2.)) - 1
		fmt.Println(m)
	}
}

package main

import "fmt"

func main() {
	var t int
	var n int64
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		fmt.Println((n - 1) / 2)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)

	var N int
	var candies int

	fmt.Fscanf(in, "%d\n", &N)
	for i := 0; i < N; i++ {
		fmt.Fscanf(in, "%d\n", &candies)
		fmt.Println((candies - 1) / 2)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime"
	"strconv"
	"strings"
)

func main() {
	var truncator string
	if runtime.GOOS == "windows" {
		truncator = "\r\n"
	} else {
		truncator = "\n"
	}

	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimSuffix(text, truncator)
	testcase, _ := strconv.ParseInt(text, 10, 64)

	inputs := make([]int64, testcase)
	var i int64
	results := make([]string, testcase)
	for i = 0; i < testcase; i++ {
		text, _ = reader.ReadString('\n')
		text = strings.TrimSuffix(text, truncator)
		inputs[i], _ = strconv.ParseInt(text, 10, 64)
		results[i] = fmt.Sprintf("%d", (inputs[i]-1)/2)
	}
	output := strings.Join(results, "\n")
	fmt.Printf("%s\n", output)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

// https://codeforces.com/problemset/problem/1335/A
// A. Candies and Two Sisters
// time limit per test
// 1 second
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// There are two sisters Alice and Betty. You have n
// candies. You want to distribute these n

// candies between two sisters in such a way that:

//     Alice will get a

// (a>0
// ) candies;
// Betty will get b
// (b>0
// ) candies;
// each sister will get some integer number of candies;
// Alice will get a greater amount of candies than Betty (i.e. a>b
// );
// all the candies will be given to one of two sisters (i.e. a+b=n

//     ).

// Your task is to calculate the number of ways to distribute exactly n

// candies between sisters in a way described above. Candies are indistinguishable.

// Formally, find the number of ways to represent n
// as the sum of n=a+b, where a and b are positive integers and a>b

// .

// You have to answer t

// independent test cases.
// Input

// The first line of the input contains one integer t
// (1≤t≤104) — the number of test cases. Then t

// test cases follow.

// The only line of a test case contains one integer n
// (1≤n≤2⋅109

// ) — the number of candies you have.
// Output

// For each test case, print the answer — the number of ways to distribute exactly n
// candies between two sisters in a way described in the problem statement. If there is no way to satisfy all the conditions, print 0.

func main() {
	bufStdin := bufio.NewReader(os.Stdin)
	bufStdout := bufio.NewWriter(os.Stdout)

	var t int
	_, _ = fmt.Fscan(bufStdin, &t)

	for i := 0; i < t; i++ {
		var n int
		_, _ = fmt.Fscan(bufStdin, &n)

		_, _ = fmt.Fprintln(bufStdout, nDistributions(n))
	}

	_ = bufStdout.Flush()
}

func nDistributions(n int) int {
	distributions := ((n + 1) / 2)
	if distributions > 0 {
		distributions--
	}
	return distributions
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

// https://codeforces.com/problemset/problem/1335/A
// A. Candies and Two Sisters
// time limit per test
// 1 second
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// There are two sisters Alice and Betty. You have n
// candies. You want to distribute these n

// candies between two sisters in such a way that:

//     Alice will get a

// (a>0
// ) candies;
// Betty will get b
// (b>0
// ) candies;
// each sister will get some integer number of candies;
// Alice will get a greater amount of candies than Betty (i.e. a>b
// );
// all the candies will be given to one of two sisters (i.e. a+b=n

//     ).

// Your task is to calculate the number of ways to distribute exactly n

// candies between sisters in a way described above. Candies are indistinguishable.

// Formally, find the number of ways to represent n
// as the sum of n=a+b, where a and b are positive integers and a>b

// .

// You have to answer t

// independent test cases.
// Input

// The first line of the input contains one integer t
// (1≤t≤104) — the number of test cases. Then t

// test cases follow.

// The only line of a test case contains one integer n
// (1≤n≤2⋅109

// ) — the number of candies you have.
// Output

// For each test case, print the answer — the number of ways to distribute exactly n
// candies between two sisters in a way described in the problem statement. If there is no way to satisfy all the conditions, print 0.

func main() {
	bufStdin := bufio.NewReader(os.Stdin)
	bufStdout := bufio.NewWriter(os.Stdout)

	var t int
	_, _ = fmt.Fscan(bufStdin, &t)

	for i := 0; i < t; i++ {
		var n int
		_, _ = fmt.Fscan(bufStdin, &n)

		_, _ = fmt.Fprintln(bufStdout, nDistributions(n))
	}

	_ = bufStdout.Flush()
}

// for an even number, there are (n/2)-1 ways to distribute the candies
// e.g. 3 ways to divide 8: 5-3, 6-2, 7-1
// exception is 2, for which there are no distributions
//
// for an odd number, there are ((n+1)/2)-1 ways to distribute the candies
// e.g 3 ways to divide 7: 4-3, 5-2, 6-1
// exception is 1, for which there are no distributions
//
// due to integer division, ((n+1)/2)-1 is correct for both even and odd numbers, except for 1 and 2
// we only do the -1 subtraction if the result of (n+1)/2 is > 0 as an exception, since when n=1, (n+1)/2=1
func nDistributions(n int) int {
	distributions := ((n + 1) / 2) - 1
	return distributions
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
)
func main() {
	var num int
	fmt.Scanln(&num)
	var q int
	var line string
	answer := ""
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < num; i++ {
		line, _ = reader.ReadString('\n')
		line = strings.TrimSpace(line)
		q, _ = strconv.Atoi(line)
		if q % 2 == 0{
			answer += strconv.Itoa(q / 2 - 1)
		} else {
			answer += strconv.Itoa(q / 2)
		}
		if i < num - 1{
			answer += "\n"
		}
	}
	fmt.Println(answer)
}

package main
import (
	"fmt"
	"bufio"
	"os"
)

func main(){
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var t int
	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(r, &n)
		if n < 3 {
			fmt.Fprintln(w, 0)
		} else {
			fmt.Fprintln(w, (n - 1)/2)
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

// https://codeforces.com/problemset/problem/1335/A
// комментарии к решению
// Т.к. требуется арифметика с числами, то используем fmt.Scan для считывания массива.
// Для вывода воспользуемся fmt.Sprint переведя массив ответов в строку.
// Т.к. fmt.Sprint выводит данные через пробел, то задействуем strings.Replace
// для вывода ответов по одному на строку.
// Компилятор видит, что заменяется 1 однобайтовый символ unicode на 1 однобайтовый символ unicode,
// плюс мы указываем кол-во замен, поэтому будет сгенерирован оптимальный по памяти код,
// как если бы мы производили свою арифметику с []byte
func taskSolution(a []int) string {
	ans := a[:]
	for i := 0; i < len(a); i += 1 {
		ans[i] = (a[i] - 1) / 2
	}
	res := fmt.Sprint(ans)
	return strings.Replace(res[1:len(res)-1], " ", "\n", len(ans)-1)
}

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}

	a := []int{}
	for i := 0; i < n; i += 1 {
		var ai int
		if _, err := fmt.Scan(&ai); err != nil {
			panic(err)
		}
		a = append(a, ai)
	}

	fmt.Println(taskSolution(a))
}

// Author: sighduck
// URL: https://codeforces.com/contest/1335/problem/A

package main

import (
	"bufio"
	"fmt"
	"os"
)

func Solve(n int64) int64 {
	if n%2 == 0 {
		return n/2 - 1
	}
	return n / 2
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n int64
		fmt.Fscanf(reader, "%d\n", &n)
		fmt.Fprintf(writer, "%d\n", Solve(n))
	}
}

package main

import (
    "bufio"
    "fmt"
    "io"
    "os"
)

type BufferedWriter interface {
    Printf(format string, a ...interface{})
    Flush()
}

type writerImpl struct {
    *bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
    return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
    fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
    impl.Writer.Flush()
}

type WordScanner interface {
    NextInt() int
    NextInt64() int64
    NextString() string
}

type wordScannerImpl struct {
    *bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
    s := bufio.NewScanner(reader)
    s.Split(bufio.ScanWords)
    // adjust the following size as needed
    // 2 << 17 is good enough to scan strings of len 2*10^5
    // it could go as high as 2 << 26 before cf judge breaks
    size := 2 << 20
    buf := make([]byte, size)
    s.Buffer(buf, size)
    return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
    impl.Scan()
    bb := impl.Bytes()
    i := 0
    if bb[0] == '-' {
        for _, b := range bb[1:] {
            i *= 10
            i -= int(b - '0')
        }
        return i
    }
    for _, b := range bb {
        i *= 10
        i += int(b - '0')
    }
    return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
    impl.Scan()
    bb := impl.Bytes()
    i := int64(0)
    if bb[0] == '-' {
        for _, b := range bb[1:] {
            i *= 10
            i -= int64(b - '0')
        }
        return i
    }
    for _, b := range bb {
        i *= 10
        i += int64(b - '0')
    }
    return i
}

func (impl *wordScannerImpl) NextString() string {
    impl.Scan()
    return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
    defer writer.Flush()
    t := reader.NextInt64()
    for ; t > 0; t-- {
        n := reader.NextInt64()
        if n <= 2 {
            writer.Printf("0\n")
        } else {
            writer.Printf("%d\n", (n-1)/2)
        }
    }
}

package main

import (
	"fmt"
	"math"
)

// 5N^2 + 4 или 5N^2 - 4 является квадратом.
func IsFib(n int) bool {
	i := float64(n)
	pow := math.Pow(i, 2)
	x := math.Sqrt(float64(5*pow + 4))
	y := math.Sqrt(float64(5*pow - 4))
	if math.Mod(x, 1) == 0 || math.Mod(y, 1) == 0 {
		return true
	}
	return false
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scanf("%d\n", &a)
		fmt.Println((a - 1) / 2)
	}

}

// Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools

package main

import (
  "fmt"
)

func main() {
  var T int
  fmt.Scanf("%d", &T)
  for t := 0; t < T; t++ {
    var n int
    fmt.Scanf("%d", &n)
    solve(n)
  }
}

func solve(n int) {
  res := (n - 1) / 2
  if res < 0 {
    res = 0
  }
  fmt.Println(res)
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scanf("%d", &n)
		if n <= 2 {
			fmt.Println(0)
		} else {
			if n%2 == 0 {
				fmt.Println(n/2 - 1)
			} else {
				fmt.Println(n / 2)
			}
		}
	}
}

package main

import (
	"fmt"
)

func solve() {
	var conf int
	fmt.Scanf("%d", &conf)
	if conf > 2 {
		if conf%2 == 0 {
			conf--
		}
		fmt.Println(conf / 2)
	} else {
		fmt.Println(0)
	}
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

import (
	"fmt"
)

func solve() {
	var conf int
	_, err := fmt.Scanf("%d\n", &conf)
	if err != nil {
		fmt.Println(err)
	}
	if conf > 2 {
		if conf%2 == 0 {
			conf--
		}
		fmt.Println(conf / 2)
	} else {
		fmt.Println(0)
	}
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

import (
	"fmt"
)

func solve() {
	var conf int
	_, err := fmt.Scanf("%d", &conf)
	if err != nil {
		fmt.Println(err)
	}
	if conf > 2 {
		if conf%2 == 0 {
			conf--
		}
		fmt.Println(conf / 2)
	} else {
		fmt.Println(0)
	}
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

import (
	"fmt"
)

// test
func solve() {
	var conf int
	fmt.Scanf("%d", &conf)
	if conf > 2 {
		if conf%2 == 0 {
			conf--
		}
		fmt.Println(conf / 2)
	} else {
		fmt.Println(0)
	}
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)

	var m int
	m = int(math.Floor(float64(n)/2.)) + 1
	fmt.Println(m)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
)
func main() {
	var num int
	fmt.Scanln(&num)
	var q int
	var line string
	answer := ""
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < num; i++ {
		line, _ = reader.ReadString('\n')
		line = strings.TrimSpace(line)
		q, _ = strconv.Atoi(line)
		fmt.Println(q)
		if q % 2 == 0{
			answer += strconv.Itoa(q / 2 - 1)
		} else {
			answer += strconv.Itoa(q / 2)
		}
		if i < num - 1{
			answer += "\n"
		}
	}
	fmt.Println(answer)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
)
func main() {
	var num int
	fmt.Scanln(&num)
	var q int
	var line string
	answer := ""
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < num; i++ {
		line, _ = reader.ReadString('\n')
		line = strings.TrimSpace(line)
		q, _ = strconv.Atoi(line)
		if q == 1{
			answer += "0"
		}else if q % 2 == 0{
			answer += strconv.Itoa(num / 2 - 1)
		} else {
			answer += strconv.Itoa(num / 2)
		}
		if i < num - 1{
			answer += "\n"
		}
	}
	fmt.Println(answer)
}


Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.The game is played on a tree having n nodes, numbered from 1 to n. Each node i has an initial value initi, which is either 0 or 1. The root of the tree is node 1.One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node x. Right after someone has picked node x, the value of node x flips, the values of sons of x remain the same, the values of sons of sons of x flips, the values of sons of sons of sons of x remain the same and so on.The goal of the game is to get each node i to have value goali, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.

The first line contains an integer n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n; ui ≠ vi) meaning there is an edge between nodes ui and vi.  The next line contains n integer numbers, the i-th of them corresponds to initi (initi is either 0 or 1). The following line also contains n integer numbers, the i-th number corresponds to goali (goali is either 0 or 1).

In the first line output an integer number cnt, representing the minimal number of operations you perform. Each of the next cnt lines should contain an integer xi, representing that you pick a node xi.

package main

import (
	"bufio"
	"errors"
	"flag"
	"fmt"
	"log"
	"os"
	"strconv"
	"time"
)

// ******************************** CODE STARTS ********************************

var (
	G [][]int
	have, want, ans []int
)

func f(v, p int, curChange, nextChange bool) int {
	newCurChange := nextChange
	if curChange {
		have[v] ^= 1
	}
	res := 0
	if have[v] != want[v] {
		curChange = !curChange
		res++
		ans = append(ans, v + 1)
	}
	newNextChange := curChange
	for i := 0; i < len(G[v]); i++ {
		if p != G[v][i] {
			res += f(G[v][i], v, newCurChange, newNextChange)
		}
	}

	return res
}

func solve() {
	n := readInt()
	G = make([][]int, n)
	have = make([]int, n)
	want = make([]int, n)

	for i := 0; i < n - 1; i++ {
		a := readInt() - 1
		b := readInt() - 1
		G[a] = append(G[a], b)
		G[b] = append(G[b], a)
	}

	for i := 0; i < n; i++ {
		have[i] = readInt()
	}
	for i := 0; i < n; i++ {
		want[i] = readInt()
	}

	printInt(f(0, -1, false, false))
	printLine()
	for i := 0; i < len(ans); i++ {
		printInt(ans[i])
		printLine()
	}
}

// ********************************* CODE ENDS *********************************

// IO.

var (
	scanner *bufio.Scanner
	writer  *bufio.Writer
	logger  *log.Logger
)

func main() {
	local := flag.Bool("local", false, "Equals true, if run is local.")
	flag.Parse()

	var (
		input  *os.File
		output *os.File
	)

	if *local {
		startTime := time.Now()
		defer func() {
			println(fmt.Sprintf("Time: %.5fs", time.Since(startTime).Seconds()))
		}()
		input, _ = os.Open("/home/outside/coding/workspace/go/io/input.txt")
		output, _ = os.Create("/home/outside/coding/workspace/go/io/output.txt")
		logger = log.New(output, "log: ", 0)
	} else {
		input = os.Stdin
		output = os.Stdout
		// input, _ = os.Open("")
		// output, _ = os.Create("")
	}
	defer input.Close()
	defer output.Close()

	scanner = bufio.NewScanner(input)
	scanner.Split(bufio.ScanWords)

	writer = bufio.NewWriter(output)
	defer writer.Flush()

	solve()
}

// Read.

func readString() string {
	scanner.Scan()
	ans := scanner.Text()
	return ans
}

func readLine() string {
	scanner.Split(bufio.ScanLines)
	defer scanner.Split(bufio.ScanWords)
	return readString()
}

func readInt() int {
	ans, _ := strconv.ParseInt(readString(), 10, 0)
	return int(ans)
}

func readInt64() int64 {
	ans, _ := strconv.ParseInt(readString(), 10, 64)
	return ans
}

func readFloat64() float64 {
	ans, _ := strconv.ParseFloat(readString(), 64)
	return ans
}

// Write.

func printString(value string) {
	writer.WriteString(value)
}

func printLine() {
	printString("\n")
}

func printInt(value int) {
	printString(strconv.FormatInt(int64(value), 10))
}

func printInt64(value int64) {
	printString(strconv.FormatInt(value, 10))
}

func printFLoat64(value float64) {
	printString(strconv.FormatFloat(value, 'f', 20, 64))
}

// Log.

func logln(value ...interface{}) {
	writer.Flush()
	logger.Println(value...)
}
func logf(format string, value ...interface{}) {
	writer.Flush()
	logger.Printf(format, value...)
}

// Min, max, abs.

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

// Set Key interface implementations.

type Int int

func (p Int) Equals(key Key) bool {
	return int(p) == int(key.(Int))
}

func (p Int) Less(key Key) bool {
	return int(p) < int(key.(Int))
}

// Set.

type Key interface {
	Equals(key Key) bool
	Less(key Key) bool
}

type node struct {
	key   Key
	left  *node
	right *node
}

func newNode(key Key) *node {
	return &node{key, nil, nil}
}

type SplayTree struct {
	root *node
	tmp  *node
	len  int
}

func NewSplayTree() *SplayTree {
	return &SplayTree{nil, newNode(nil), 0}
}

func rotateLeft(x, p *node) {
	p.right = x.left
	x.left = p
}

func rotateRight(x, p *node) {
	p.left = x.right
	x.right = p
}

func (p *SplayTree) splay(x *node, key Key) *node {
	if x == nil {
		return nil
	}

	left := p.tmp
	right := p.tmp

	for {
		if key.Less(x.key) {
			y := x.left
			if y == nil {
				break
			}
			if key.Less(y.key) { // zig-zig
				rotateRight(y, x)
				x = y
				if x.left == nil {
					break
				}
			}
			// link right
			right.left = x
			right = x
			// move left
			x = x.left
		} else if x.key.Less(key) {
			y := x.right
			if y == nil {
				break
			}
			if y.key.Less(key) { // zig-zig
				rotateLeft(y, x)
				x = y
				if x.right == nil {
					break
				}
			}
			// link left
			left.right = x
			left = x
			// move right
			x = x.right
		} else {
			break
		}
	}

	left.right = x.left
	right.left = x.right
	x.left = p.tmp.right
	x.right = p.tmp.left

	return x
}

// left <= key < right
func (p *SplayTree) split(key Key) (left, right *node) {
	p.root = p.splay(p.root, key)
	if p.root.key.Equals(key) || p.root.key.Less(key) {
		right := p.root.right
		p.root.right = nil
		return p.root, right
	} else {
		left := p.root.left
		p.root.left = nil
		return left, p.root
	}
}

// keys from left tree must be less then keys from right tree
func (p *SplayTree) join(left, right *node) *node {
	if left == nil {
		return right
	} else if right == nil {
		return left
	}
	left = p.splay(left, right.key)
	left.right = right
	return left
}

type Set interface {
	Len() int
	Insert(key Key) error
	Find(key Key) bool
	Remove(key Key) error
}

func NewSet() Set {
	return Set(NewSplayTree())
}

func (p *SplayTree) Len() int {
	return p.len
}

func (p *SplayTree) Insert(key Key) error {
	if p.root == nil {
		p.root = newNode(key)
		p.len++
	} else {
		p.root = p.splay(p.root, key)
		if p.root.key.Equals(key) {
			return errors.New("Such key already exists")
		} else {
			left, right := p.split(key)
			p.root = newNode(key)
			p.root.left = left
			p.root.right = right
			p.len++
		}
	}
	return nil
}

func (p *SplayTree) Find(key Key) bool {
	if p.root == nil {
		return false
	}
	p.root = p.splay(p.root, key)
	return p.root.key.Equals(key)
}

func (p *SplayTree) Remove(key Key) error {
	p.root = p.splay(p.root, key)
	if p.root == nil || !p.root.key.Equals(key) {
		return errors.New("Such key doesn't exist")
	}
	p.root = p.join(p.split(key))
	return nil
}