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[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)
		}
		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])
		}
	}

}


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"
	"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)
	}

}

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

// 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)
}


package main

import "fmt"

func circular(s string) bool {
	left, right := false, false
	for i := range s {
		if s[i] == '<' {
			left = true
		}
		if s[i] == '>' {
			right = true
		}
		if left && right {
			return false
		}
	}
	return true
}

func returnableRooms(n int, s string) int {
	if circular(s) {
		return n
	}
	rooms := make(map[int]bool)
	for i := range s {
		if s[i] == '-' {
			rooms[i] = true
			rooms[(i+1)%n] = true
		}
	}

	return len(rooms)
}

func main() {

	t := 0
	fmt.Scanf("%d\n", &t)

	for t > 0 {
		n := 0
		fmt.Scanf("%d\n", &n)
		var s string
		fmt.Scanf("%s\n", &s)
		fmt.Printf("%d\n", returnableRooms(n, s))
		t -= 1
	}
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

func Max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func Abs(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

const mod = 1000000007

func Add(a, b int64) int64 {
	return (a + b) % mod
}

func Mult(a, b int64) int64 {
	return (a * b) % mod
}

func solve() {
	n := nextInt()
	arr := []byte(next())
	a, b, c := 0, 0, 0
	for _, v := range arr {
		if v == '>' {
			a++
		} else if v == '<' {
			b++
		} else if v == '-' {
			c++
		}
	}
	if a == 0 || b == 0 {
		printf("%d\n", n)
		return
	}
	if c == 0 {
		printf("0\n")
		return
	}
	has := make([]bool, n)
	for i := range has {
		if arr[i] == '-' {
			has[i] = true
			has[(i+1)%n] = true
		}
	}
	num := 0
	for _, v := range has {
		if v {
			num++
		}
	}
	printf("%d\n", num)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	name := "in"
	file1, err := os.Open(name + ".in")
	if err == nil {
		in = bufio.NewReaderSize(file1, 8192)
	}
	// file2, err := os.Create(name + ".out")
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// out = bufio.NewWriterSize(file2, 8192)
	defer out.Flush()
	// start := time.Now()

	for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
		// printf("Case #%d:\n", i)
		solve()
	}

	// printf("%v\n", time.Now().Sub(start))
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		s := ReadString()
		Println(solve(n, s))
	}

}

func solve(n int, s string) int {
	lt := 0
	gt := 0
	for i := 0; i < n; i++ {
		if s[i] == '<' {
			lt++
		} else if s[i] == '>' {
			gt++
		}
	}
	if lt == 0 || gt == 0 {
		return n
	}

	di := make(map[int]bool)
	for i := 0; i < n; i++ {
		if s[i] == '-' {
			di[i] = true
			di[(i+1)%n] = true
		}
	}
	return len(di)
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func Print(a ...interface{})            { fmt.Fprint(_w, a...) }
func Printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func Println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

/*
URL:
https://codeforces.com/contest/1428/problem/B
*/

package main

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

var (
	t int

	n int
	S []rune
)

func main() {
	defer stdout.Flush()

	t = readi()
	for i := 0; i < t; i++ {
		n = readi()
		S = readrs()

		solve()
	}
}

func solve() {
	memo := make(map[rune]int)
	for _, r := range S {
		memo[r]++
	}

	if memo['>'] == 0 || memo['<'] == 0 {
		printf("%d\n", n)
		return
	}

	A := make([]int, n)
	for i, r := range S {
		if r != '-' {
			continue
		}

		A[i]++
		A[(i+1)%n]++
	}

	ans := 0
	for i := 0; i < n; i++ {
		if A[i] > 0 {
			ans++
		}
	}
	printf("%d\n", ans)
}

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

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	reads = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// 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
}

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

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

// abs is integer version of math.Abs
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

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

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

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

/*********** Input ***********/

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

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

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

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

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

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

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

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// 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)
}

// Printf is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func printf(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

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

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

// 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
}

/*
URL:
https://codeforces.com/contest/1428/problem/B
*/

package main

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

var (
	t int

	n int
	S []rune
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		n = readi()
		S = readrs()

		solve()
	}
}

func solve() {
	scc := NewSccGraph(n)

	for i := 0; i < n; i++ {
		r := S[i]
		if r == '-' {
			scc.AddEdge(i, (i+1)%n)
			scc.AddEdge((i+1)%n, i)
		} else if r == '>' {
			scc.AddEdge(i, (i+1)%n)
		} else {
			scc.AddEdge((i+1)%n, i)
		}
	}

	E := scc.Scc()

	ans := 0
	for _, ids := range E {
		if len(ids) == 1 {
			continue
		}
		ans += len(ids)
	}

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

// originated from:
// https://qiita.com/EmptyBox_0/items/2f8e3cf7bd44e0f789d5#scc
// https://atcoder.github.io/ac-library/production/document_ja/scc.html

type SccGraph struct {
	n     int
	edges [][2]int
}

type Csr struct {
	start []int
	elist []int
}

func NewSccGraph(n int) *SccGraph {
	scc := new(SccGraph)
	scc.n = n
	return scc
}

func (scc *SccGraph) NumVertices() int {
	return scc.n
}

func (scc *SccGraph) AddEdge(from int, to int) {
	scc.edges = append(scc.edges, [2]int{from, to})
}

func (scc *SccGraph) Scc() [][]int {
	groupNum, ids := scc.SccIds()
	counts := make([]int, groupNum)
	for _, x := range ids {
		counts[x]++
	}
	groups := make([][]int, groupNum)
	for i := 0; i < groupNum; i++ {
		groups[i] = make([]int, 0, counts[i])
	}
	for i := 0; i < scc.n; i++ {
		groups[ids[i]] = append(groups[ids[i]], i)
	}
	return groups
}

func (c *Csr) csr(n int, edges [][2]int) {
	c.start = make([]int, n+1)
	c.elist = make([]int, len(edges))
	for _, e := range edges {
		c.start[e[0]+1]++
	}
	for i := 1; i <= n; i++ {
		c.start[i] += c.start[i-1]
	}
	counter := make([]int, n+1)
	copy(counter, c.start)
	for _, e := range edges {
		c.elist[counter[e[0]]] = e[1]
		counter[e[0]]++
	}
}

func (scc *SccGraph) SccIds() (int, []int) {
	_min := func(x, y int) int {
		if x < y {
			return x
		}
		return y
	}

	g := new(Csr)
	g.csr(scc.n, scc.edges)
	nowOrd, groupNum := 0, 0
	visited, low := make([]int, 0, scc.n), make([]int, scc.n)
	ord, ids := make([]int, scc.n), make([]int, scc.n)
	for i := 0; i < scc.n; i++ {
		ord[i] = -1
	}
	var dfs func(v int)
	dfs = func(v int) {
		low[v], ord[v] = nowOrd, nowOrd
		nowOrd++
		visited = append(visited, v)
		for i := g.start[v]; i < g.start[v+1]; i++ {
			to := g.elist[i]
			if ord[to] == -1 {
				dfs(to)
				low[v] = _min(low[v], low[to])
			} else {
				low[v] = _min(low[v], ord[to])
			}
		}
		if low[v] == ord[v] {
			for {
				u := visited[len(visited)-1]
				visited = visited[:len(visited)-1]
				ord[u] = scc.n
				ids[u] = groupNum
				if u == v {
					break
				}
			}
			groupNum++
		}
	}
	for i := 0; i < scc.n; i++ {
		if ord[i] == -1 {
			dfs(i)
		}
	}
	for i := 0; i < len(ids); i++ {
		ids[i] = groupNum - 1 - ids[i]
	}
	return groupNum, ids
}

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

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	reads = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// 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
}

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

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

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

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

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

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

/*********** Input ***********/

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

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

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

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

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

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

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

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// 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)
}

// Printf is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func printf(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

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

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

// 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
}

package main

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

var reader = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Fscan(reader, &t)

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

		var s string
		fmt.Fscan(reader, &s)

		var cBelt, ccBelt int
		var oneOff int
		for j := range s {
			rBelt := s[j]
			lBelt := s[(j-1+n)%n]
			if rBelt == '>' {
				cBelt++
			}

			if rBelt == '<' {
				ccBelt++
			}

			if rBelt == '-' || lBelt == '-' {
				oneOff++
			}
		}

		var ans int
		if cBelt == 0 || ccBelt == 0 {
			ans = n
		} else {
			ans = oneOff
		}

		fmt.Println(ans)
	}
}

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	t := getNextInt(scanner)
	for t > 0 {
		t--
		func() {
			n := getNextInt(scanner)
			s := getNextString(scanner)
			l := 0
			r := 0
			can := make([]bool, n)
			for i := 0; i < n; i++ {
				switch s[i] {
				case '>':
					r++
				case '<':
					l++
				default:
					l++
					r++
					can[i] = true
					can[(i+1)%n] = true
				}
			}
			if l == n || r == n {
				fmt.Fprintln(writer, n)
				return
			}
			var ans int
			for i := 0; i < n; i++ {
				if can[i] {
					ans++
				}
			}
			fmt.Fprintln(writer, ans)
		}()
	}
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		s := ReadString()
		Println(solve(n, s))
	}

}

func solve(n int, s string) int {
	di := make(map[int]bool)
	for i := 0; i < n; i++ {
		if s[i] == '-' {
			di[i] = true
			di[(i+1)%n] = true
		}
	}
	if len(di) > 0 {
		return len(di)
	}

	lt := 0
	gt := 0
	for i := 0; i < n; i++ {
		if s[i] == '<' {
			lt++
		} else {
			gt++
		}
	}
	if lt == 0 || gt == 0 {
		return n
	} else {
		return 0
	}
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func Print(a ...interface{})            { fmt.Fprint(_w, a...) }
func Printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func Println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		s := ReadString()
		Println(solve(n, s))
	}

}

func solve(n int, s string) int {
	lt := 0
	gt := 0
	for i := 0; i < n; i++ {
		if s[i] == '<' {
			lt++
		} else {
			gt++
		}
	}
	if lt == 0 || gt == 0 {
		return n
	}

	di := make(map[int]bool)
	for i := 0; i < n; i++ {
		if s[i] == '-' {
			di[i] = true
			di[(i+1)%n] = true
		}
	}
	return len(di)
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func Print(a ...interface{})            { fmt.Fprint(_w, a...) }
func Printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func Println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

var reader = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Fscan(reader, &t)

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

		var s string
		fmt.Fscan(reader, &s)

		var stuck int
		var oneOff int
		for j := range s {
			rBelt := s[j]
			lBelt := s[(j-1+n)%n]
			if rBelt == '<' && lBelt == '>' {
				stuck++
			}

			if rBelt == '-' || lBelt == '-' {
				oneOff++
			}
		}

		var ans int
		if stuck == 0 {
			ans = n
		} else {
			ans = oneOff
		}

		fmt.Println(ans)
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Fscan(reader, &t)

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

		var s string
		fmt.Fscan(reader, &s)

		var cBelt, ccBelt int
		var oneOff int
		for j := range s {
			rBelt := s[j]
			lBelt := s[(j-1+n)%n]
			if rBelt == '>' {
				cBelt++
			}

			if rBelt == '<' {
				lBelt++
			}

			if rBelt == '-' || lBelt == '-' {
				oneOff++
			}
		}

		var ans int
		if cBelt == 0 || ccBelt == 0 {
			ans = n
		} else {
			ans = oneOff
		}

		fmt.Println(ans)
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Fscan(reader, &t)

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

		var s string
		fmt.Fscan(reader, &s)

		var stuck int
		var oneOff int
		for j := range s {
			rBelt := s[j]
			lBelt := s[(j-1+n)%n]
			if (rBelt == '<' && lBelt == '>') || (rBelt == '>' && lBelt == '<') {
				stuck++
			}

			if rBelt == '-' || lBelt == '-' {
				oneOff++
			}
		}

		var ans int
		if stuck == 0 {
			ans = n
		} else {
			ans = oneOff
		}

		fmt.Println(ans)
	}
}