import java.util.Scanner;

public class Main {

    public static void main(String []args){
        Scanner sc = new Scanner(System.in);

        final int N = 200000;
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q = sc.nextInt();
        int []dist = new int[N];
        int a,b;

        for(int i = 0 ; i < N ; i++){
            dist[i] = 0;
        }

        for(int i = 0 ; i < n ; i++){
            a = sc.nextInt();
            b = sc.nextInt();
            dist[a] ++;
            dist[b + 1]--;
        }

        for(int i = 1 ; i < N ; i++){
            dist[i] += dist[i-1];
        }

        for(int i = 0 ; i < N ; i++){
            dist[i] = (dist[i] < k) ? 0 :1;
        }

        for(int i = 1 ; i < N ;i++){
            dist[i] += dist[i - 1];
        }

        for(int i = 0 ; i < q ; i++){
            a = sc.nextInt();
            b = sc.nextInt();
            System.out.println(dist[b] - dist[a - 1]);
        }

    }
}


import java.util.Scanner;

public class Main {

    public static void main(String []args){
        Scanner sc = new Scanner(System.in);

        final int N = 200000 + 7;
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q = sc.nextInt();
        long []dist = new long[N];
        int a,b;

        for(int i = 0 ; i < n ; i++){
            a = sc.nextInt();
            b = sc.nextInt();
            dist[a] ++;
            dist[b + 1]--;
        }

        for(int i = 1 ; i < N ; i++){
            dist[i] += dist[i-1];
        }

        for(int i = 1 ; i < N ; i++){
            dist[i] = (dist[i] >= k) ? 1 :0;
        }

        for(int i = 1 ; i < N ;i++){
            dist[i] += dist[i - 1];
        }

        for(int i = 0 ; i < q ; i++){
            a = sc.nextInt();
            b = sc.nextInt();
            System.out.println(dist[b] - dist[a - 1]);
        }

    }
}


import java.util.Scanner;

public class Main {

    public static void main(String []args){
        Scanner sc = new Scanner(System.in);

        final int N = 200000 + 7;
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q = sc.nextInt();
        long []dist = new long[N];
        int a,b;

        for(int i = 0 ; i < n ; i++){
            a = sc.nextInt();
            b = sc.nextInt();
            dist[a] ++;
            dist[b + 1]--;
        }

        for(int i = 1 ; i < dist.length ; i++){
            dist[i] += dist[i-1];
        }

        for(int i = 0; i < dist.length ; i++){
            dist[i] = (dist[i] >= k) ? 1 :0;
        }

        for(int i = 1 ; i < dist.length ;i++){
            dist[i] += dist[i - 1];
        }

        for(int i = 0 ; i < q ; i++){
            a = sc.nextInt();
            b = sc.nextInt();
            System.out.println(dist[b] - dist[a - 1]);
        }

    }
}


import java.util.Scanner;

public class Main {

    public static void main(String []args){
        Scanner sc = new Scanner(System.in);

        final int N = 200000 + 7;
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q = sc.nextInt();
        long []dist = new long[N];
        int a,b;

        for(int i = 0 ; i < n ; i++){
            a = sc.nextInt();
            b = sc.nextInt();
            dist[a] ++;
            dist[b + 1]--;
        }

        for(int i = 1 ; i < N ; i++){
            dist[i] += dist[i-1];
        }

        for(int i = 1 ; i < N ; i++){
            dist[i] = (dist[i] < k) ? 0 :1;
        }

        for(int i = 1 ; i < N ;i++){
            dist[i] += dist[i - 1];
        }

        for(int i = 0 ; i < q ; i++){
            a = sc.nextInt();
            b = sc.nextInt();
            System.out.println(dist[b] - dist[a - 1]);
        }

    }
}


import java.util.Scanner;

public class Main {

    public static void main(String []args){
        Scanner sc = new Scanner(System.in);

        final int N = 200000 + 5;
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q = sc.nextInt();
        long []dist = new long[N];
        int a,b;

        for(int i = 0 ; i < n ; i++){
            a = sc.nextInt();
            b = sc.nextInt();
            dist[a] ++;
            dist[b + 1]--;
        }

        for(int i = 1 ; i < dist.length ; i++){
            dist[i] += dist[i-1];
        }

        for(int i = 1; i < dist.length ; i++){
            dist[i] = (dist[i] >= k) ? 1 :0;
        }

        for(int i = 1 ; i < dist.length ;i++){
            dist[i] += dist[i - 1];
        }

        for(int i = 0 ; i < q ; i++){
            a = sc.nextInt();
            b = sc.nextInt();
            System.out.println(dist[b] - dist[a - 1]);
        }

    }
}


import java.util.Scanner;

public class Main {

    public static void main(String []args){
        Scanner sc = new Scanner(System.in);

        final int N = 200000 + 5;
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q = sc.nextInt();
        int []dist = new int[N];
        int a,b;

        for(int i = 0 ; i < N ; i++){
            dist[i] = 0;
        }

        for(int i = 0 ; i < n ; i++){
            a = sc.nextInt();
            b = sc.nextInt();
            dist[a] ++;
            dist[b + 1]--;
        }

        for(int i = 1 ; i < N ; i++){
            dist[i] += dist[i-1];
        }

        for(int i = 0 ; i < N ; i++){
            dist[i] = (dist[i] < k) ? 0 :1;
        }

        for(int i = 1 ; i < N ;i++){
            dist[i] += dist[i - 1];
        }

        for(int i = 0 ; i < q ; i++){
            a = sc.nextInt();
            b = sc.nextInt();
            System.out.println(dist[b] - dist[a - 1]);
        }

    }
}


import java.util.Scanner;

public class KarenandCoffee {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int k = input.nextInt();
		int q = input.nextInt();
		int[] arr = new int[200004];
		int min = 0;
		int max = 200000;
		for(int i=0; i<n;i++){
			int a = input.nextInt();
			int b = input.nextInt();
			arr[a]+=1;
			arr[b+1]-=1;
		    if(a>min)min = a;
		    if(b<max)max  = b;
		}
		for(int i=1; i<=200000;i++){
			arr[i] = arr[i-1]+arr[i];
		}
		int[] condition = new int[2000001];
		for(int i=1; i<=200000;i++){
			if(arr[i]>=k)condition[i] = condition[i-1]+1;
			else
				condition[i] = condition[i-1];
			}

		for(int j=0; j<q;j++){
			int t1 = input.nextInt();
			int t2 = input.nextInt();
			System.out.println(condition[t2]-condition[t1-1]);
		}
	}

}


import java.util.Scanner;

public class Karenandcofee {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int k = input.nextInt();
		int q = input.nextInt();
		int[][] arr = new int[n][2];
		for(int i=0;i<n;i++){
			arr[i][0] = input.nextInt();
			arr[i][1] = input.nextInt();
		}
		for(int i=0;i<q;i++){
			int l = input.nextInt();
			int r = input.nextInt();
			int counter1 = 0;
			for(int j=l;j<=r;j++){
				int counter = 0;
				for(int z=0;z<n;z++){

					if(j>=arr[z][0] && j<=arr[z][1])counter++;
					if(counter==k){
						counter1++;
						break;
					}
				}

			}
			System.out.println(counter1);
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;

public class KarenandCofee {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub

		Scanner input = new Scanner(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] in = br.readLine().split(" ");
		int n = Integer.parseInt(in[0]);
		int k = Integer.parseInt(in[1]);
		int q = Integer.parseInt(in[2]);
		PrintWriter out = new PrintWriter(System.out);
		int[] arr = new int[200002];
		//int[][] brr = new int[n][2];
		for(int i=0; i<n;i++){
			in = br.readLine().split(" ");
			int x =  Integer.parseInt(in[0]);
			int y = Integer.parseInt(in[1]);
			arr[x]+=1;
			arr[y+1]-=1;
		}

		for(int i=1; i<=200001;i++){
			arr[i] = arr[i]+arr[i-1];
		}

		for(int i=0;i<q;i++){
			in = br.readLine().split(" ");
			int x = Integer.parseInt(in[0]);
			int y = Integer.parseInt(in[1]);
			int counter=0;
			for(int j=x;j<=y;j++){
				if(arr[j]>=k)counter++;
			}
			System.out.println(counter);

		}
		out.flush();
		out.close();

	}

}


import java.util.Scanner;

public class KarenandCofee {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner input = new Scanner(System.in);
		int[] arr = new int[200005];
		int n = input.nextInt();
		int k = input.nextInt();
		int q = input.nextInt();
		for(int i=0; i<n;i++){
			int x = input.nextInt();
			int y = input.nextInt();
			arr[x]+=1;
			arr[y+1]-=1;

		}
		for(int i=1; i<200002;i++){
			arr[i]+=arr[i-1];
		}
		//for(int i=90;i<=100;i++)System.out.print(arr[i] + " ");

		for(int i=0; i<q;i++){
			int a = input.nextInt();
			int b = input.nextInt();
			int counter=0;
			for(int j=a; j<=b;j++){
				if(arr[j]>=k){counter++;}
			}
			System.out.println(counter);
		}

	}

}


import java.util.*;
public class BITBIT
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        long[] cs = new long[200003];
        int n = in.nextInt(), k = in.nextInt(), q = in.nextInt(), s = 0;
        for (int i = 0; i < n; i++)
            cs[in.nextInt()] += (cs[s = in.nextInt()+1]-(--cs[s]));
        for (int i = 1; i < 200003; i++)
            cs[i] += cs[i-1];
        for (int i = 1; i < 200003; i++)
            cs[i] = (cs[i] >= k ? 1 : 0)+cs[i-1];
        for (int i = 0; i < q; i++)
            System.out.println(-(cs[in.nextInt()-1]-cs[in.nextInt()]));
    }
}


import java.util.*;
public class BITBIT
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        long[] cs = new long[200003];
        int n = in.nextInt(), k = in.nextInt(), q = in.nextInt(), s = 0;
        for (int i = 0; i < n; i++)
            cs[in.nextInt()] += (cs[s = in.nextInt()]-(--cs[s+1]));
        for (int i = 1; i < 200003; i++)
            cs[i] += cs[i-1];
        for (int i = 1; i < 200003; i++)
            cs[i] = (cs[i] >= k ? 1 : 0)+cs[i-1];
        for (int i = 0; i < q; i++)
            System.out.println(-(cs[in.nextInt()-1]-cs[in.nextInt()]));
    }
}


import java.util.*;
public class B419
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int[] cs = new int[200003];
        int n = in.nextInt(), k = in.nextInt(), q = in.nextInt(), s = 0;
        for (int i = 0; i < n; i++)
            cs[in.nextInt()] += (cs[s = in.nextInt()]-(--cs[s+1]));
        for (int i = 1; i < 200003; i++)
            cs[i] += cs[i-1];
        for (int i = 1; i < 200003; i++)
            cs[i] = (cs[i] >= k ? 1 : 0)+cs[i-1];
        for (int i = 0; i < q; i++)
            System.out.println(-(cs[in.nextInt()-1]-cs[in.nextInt()]));
    }
}


import java.util.*;
import java.io.*;

public class CF816B {

    public static void main(String[] args) throws IOException{
        in.init(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int numRecipes = in.nextInt();
        int numRequired = in.nextInt();
        int numQuestions = in.nextInt();
        int lowerBound, upperBound, count;
        int[] counts = new int[200001];

        for (int i = 0; i < numRecipes; i++) {
            lowerBound = in.nextInt();
            upperBound = in.nextInt();
            counts[lowerBound]++;
            counts[upperBound + 1]--;
        }
        for (int i = 1; i < counts.length; i++) {
            counts[i] += counts[i - 1];
        }
        for (int i = 0; i < counts.length; i++) {
            if (counts[i] >= numRequired)
            {
                counts[i] = 1;
            }
            else {
                counts[i] = 0;
            }
        }
        for (int i = 1; i < counts.length; i++) {
            counts[i] += counts[i - 1];
        }
        for (int i = 0; i < numQuestions; i++) {
            lowerBound = in.nextInt();
            upperBound = in.nextInt();
            out.println(counts[upperBound] - counts[lowerBound - 1]);
        }

        out.close();
    }

}
class in {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input) {
        reader = new BufferedReader(new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String nextLine() throws IOException {
        return reader.readLine();
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}


import java.util.*;
import java.io.*;

public class CF816B {

    public static void main(String[] args) throws IOException{
        in.init(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int numRecipes = in.nextInt();
        int numRequired = in.nextInt();
        int numQuestions = in.nextInt();
        int lowerBound, upperBound, count;
        int[] counts = new int[200001];

        for (int i = 0; i < numRecipes; i++) {
            lowerBound = in.nextInt();
            upperBound = in.nextInt();
            for (int j = lowerBound; j <= upperBound; j++) {
                counts[j]++;
            }
        }
        for (int i = 0; i < numQuestions; i++) {
            count = 0;
            lowerBound = in.nextInt();
            upperBound = in.nextInt();
            for (int j = lowerBound; j <= upperBound; j++) {
                if (counts[j] >= numRequired)
                {
                    count++;
                }
            }
            out.println(count);
        }

        out.close();
    }

}
class in {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input) {
        reader = new BufferedReader(new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String nextLine() throws IOException {
        return reader.readLine();
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}


import java.util.*;
import java.io.*;

public class CF816B {

    public static void main(String[] args) throws IOException{
        in.init(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int numRecipes = in.nextInt();
        int numRequired = in.nextInt();
        int numQuestions = in.nextInt();
        int lowerBound, upperBound, count;
        int[] counts = new int[200002];

        for (int i = 0; i < numRecipes; i++) {
            lowerBound = in.nextInt();
            upperBound = in.nextInt();
            counts[lowerBound]++;
            counts[upperBound + 1]--;
        }
        for (int i = 1; i < counts.length; i++) {
            counts[i] += counts[i - 1];
        }
        for (int i = 0; i < counts.length; i++) {
            if (counts[i] >= numRequired)
            {
                counts[i] = 1;
            }
            else {
                counts[i] = 0;
            }
        }
        for (int i = 1; i < counts.length; i++) {
            counts[i] += counts[i - 1];
        }
        for (int i = 0; i < numQuestions; i++) {
            lowerBound = in.nextInt();
            upperBound = in.nextInt();
            out.println(counts[upperBound] - counts[lowerBound - 1]);
        }

        out.close();
    }

}
class in {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input) {
        reader = new BufferedReader(new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String nextLine() throws IOException {
        return reader.readLine();
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pll pair<ll,ll>
#define mod 1000000007
#define pb push_back
#define ld long double
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define N 200000
vector<ll> a[N+1],val(N+1);
bool b[N+1];
ll ans[N+1][2], lev[N+1];
void dfs(ll x)
{
	b[x] = true;
	for(ll i=0;i<a[x].size();i++)
	{
		if(b[a[x][i]]==false)
		{
			dfs(a[x][i]);
		}
	    for(ll j=0;j<2;j++)
    	{
    	    if(ans[a[x][i]][j]!=1e18)
    	    {
    	        ans[x][j] = min(ans[x][j], ans[a[x][i]][j] + 1);
    	    }
    	}
	}
}
void solve()
{
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>val[i];
        if(i-val[i] >= 1)
        {
            a[i].pb(i-val[i]);
        }
        if(i+val[i]<=n)
        {
            a[i].pb(i+val[i]);
        }
    }
    for(ll i=1;i<=n;i++)
    {
        ans[i][0] = 1e18;
        ans[i][1] = 1e18;
        ans[i][val[i]%2] = 0;
    }
    memset(b,false,sizeof(b));
    while(1)
    {
        ll f = 0;
        for(ll i=1;i<=n;i++)
        {
            if(ans[i][(val[i] + 1)%2]==1e18)
            {
                dfs(i);
            }
            for(ll j=0;j<2;j++)
        	{
        	    if((i + val[i])<=n && ans[i + val[i]][j]!=1e18)
        	    {
        	        if(ans[i + val[i]][j] + 1 < ans[i][j]) f = 1;
        	        ans[i][j] = min(ans[i][j], ans[i + val[i]][j] + 1);
        	    }
        	    if((i - val[i]) >= 1 && ans[i - val[i]][j]!=1e18)
        	    {
        	        if(ans[i - val[i]][j] + 1 < ans[i][j]) f = 1;
        	        ans[i][j] = min(ans[i][j], ans[i - val[i]][j] + 1);
        	    }
        	}
        }
        if(f==0) break;
    }
    for(ll i=1;i<=n;i++)
    {
        if(ans[i][(val[i] + 1)%2]==1e18) cout<<-1<<" ";
        else cout<<ans[i][(val[i] + 1)%2]<<" ";
    }
}

int main()
{
	FIO;
	ll t=1;
	//cin>>t;
	while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pll pair<ll,ll>
#define mod 1000000007
#define pb push_back
#define ld long double
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define N 200000
vector<ll> a[N+1],val(N+1);
bool b[N+1];
ll ans[N+1][2], lev[N+1];
pll dp[N+1][2];
void dfs(ll x)
{
	b[x] = true;
	for(ll i=0;i<a[x].size();i++)
	{
	    lev[a[x][i]] = lev[x] + 1;
		if(b[a[x][i]]==false)
		{
			dfs(a[x][i]);
		}
	    for(ll j=0;j<2;j++)
    	{
    	    if(ans[a[x][i]][j]!=1e18)
    	    {
    	        ans[x][j] = min(ans[x][j], ans[a[x][i]][j] + 1);
    	    }
    	}
	}
}
void solve()
{
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>val[i];
        if(i-val[i] >= 1)
        {
            //a[i-val[i]].pb(i);
            a[i].pb(i-val[i]);
        }
        if(i+val[i]<=n)
        {
            //a[i+val[i]].pb(i);
            a[i].pb(i+val[i]);
        }
    }
    for(ll i=1;i<=n;i++)
    {
        ans[i][0] = 1e18;
        ans[i][1] = 1e18;
        ans[i][val[i]%2] = 0;
    }
    memset(b,false,sizeof(b));
    for(ll i=1;i<=n;i++)
    {
        if(ans[i][(val[i] + 1)%2]==1e18)
        {
            lev[i] = 0;
            dfs(i);
        }
    }
    for(ll i=1;i<=n;i++)
    {
        if(ans[i][(val[i] + 1)%2]==1e18) cout<<-1<<" ";
        else cout<<ans[i][(val[i] + 1)%2]<<" ";
    }
}

int main()
{
	FIO;
	ll t=1;
	//cin>>t;
	while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pll pair<ll,ll>
#define mod 1000000007
#define pb push_back
#define ld long double
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define N 200000
vector<ll> a[N+1],val(N+1);
bool b[N+1];
ll ans[N+1][2], lev[N+1];
void dfs(ll x)
{
	b[x] = true;
	for(ll i=0;i<a[x].size();i++)
	{
		if(b[a[x][i]]==false)
		{
			dfs(a[x][i]);
		}
	    for(ll j=0;j<2;j++)
    	{
    	    if(ans[a[x][i]][j]!=1e18)
    	    {
    	        ans[x][j] = min(ans[x][j], ans[a[x][i]][j] + 1);
    	    }
    	}
	}
}
void solve()
{
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>val[i];
        if(i-val[i] >= 1)
        {
            a[i].pb(i-val[i]);
        }
        if(i+val[i]<=n)
        {
            a[i].pb(i+val[i]);
        }
    }
    for(ll i=1;i<=n;i++)
    {
        ans[i][0] = 1e18;
        ans[i][1] = 1e18;
        ans[i][val[i]%2] = 0;
    }
    memset(b,false,sizeof(b));
    for(ll i=1;i<=n;i++)
    {
        if(ans[i][(val[i] + 1)%2]==1e18)
        {
            dfs(i);
        }
        else
        {
            for(ll j=0;j<2;j++)
        	{
        	    if((i + val[i])<=n && ans[i + val[i]][j]!=1e18)
        	    {
        	        ans[i][j] = min(ans[i][j], ans[i + val[i]][j] + 1);
        	    }
        	}
        }
    }
    for(ll i=1;i<=n;i++)
    {
        if(ans[i][(val[i] + 1)%2]==1e18) cout<<-1<<" ";
        else cout<<ans[i][(val[i] + 1)%2]<<" ";
    }
}

int main()
{
	FIO;
	ll t=1;
	//cin>>t;
	while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pll pair<ll,ll>
#define mod 1000000007
#define pb push_back
#define ld long double
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void solve()
{
    ll n;
    cin>>n;
    vector<ll> a[n+1];
    vector<ll> val(n+1);
    for(ll i=1;i<=n;i++)
    {
        cin>>val[i];
        if(i-val[i] >= 1)
        {
            a[i - val[i]].pb(i);
        }
        if(i + val[i] <= n)
        {
            a[i + val[i]].pb(i);
        }
    }
    ll dist[n+1];
    queue<ll> q;
    bool b[n+1];
    memset(b,false,sizeof(b));
    for(ll i=1;i<=n;i++)
    {
        dist[i] = 1e18;
        if(val[i]%2)
        {
            q.push(i);
            b[i] = 0;
            dist[i] = 0;
        }
    }
    while(!q.empty())
    {
        ll x = q.front();
        q.pop();
        b[x] = true;
        for(ll i=0;i<a[x].size();i++)
        {
            if(b[a[x][i]]==false)
            {
                b[a[x][i]] = true;
                dist[a[x][i]] = min(dist[a[x][i]], dist[x] + 1);
                q.push(a[x][i]);
            }
        }
    }
    ll ans[n+1];
    for(ll i=1;i<=n;i++)
    {
        if(val[i]%2==0) ans[i] = dist[i];
    }
    memset(b,false,sizeof(b));
    for(ll i=1;i<=n;i++)
    {
        dist[i] = 1e18;
        if(val[i]%2==0)
        {
            q.push(i);
            b[i] = 0;
            dist[i] = 0;
        }
    }
    while(!q.empty())
    {
        ll x = q.front();
        q.pop();
        b[x] = true;
        for(ll i=0;i<a[x].size();i++)
        {
            if(b[a[x][i]]==false)
            {
                b[a[x][i]] = true;
                dist[a[x][i]] = min(dist[a[x][i]], dist[x] + 1);
                q.push(a[x][i]);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        if(val[i]%2) ans[i] = dist[i];
    }
    for(ll i=1;i<=n;i++)
    {
        if(ans[i]==1e18) cout<<-1<<" ";
        else cout<<ans[i]<<" ";
    }
}

int main()
{
	FIO;
	ll t=1;
	//cin>>t;
	while(t--) solve();
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
vector<ll> A[200005],a(200005),ans(200005,-1);
bool b[200005];
ll cnt = 0,ANS = -1;
void dfs(ll x,ll par)
{
    b[x] = true;
    if(a[x]%2!=par) {
        ANS = cnt;
        return;
    }
    cnt++;
    for(ll i=0;i<A[x].size();i++)
    {
        if(ANS!=-1) return;
        if(b[A[x][i]] == false)
        {
            dfs(A[x][i],par);
        }
    }
}

int main() {
    FIO;
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++) cin>>a[i];
    for(ll i=1;i<=n;i++)
    {
        if(a[i] + i <= n) A[i].pb(a[i] + i);
        if(i - a[i] >= 1) A[i].pb(i - a[i]);
    }
    memset(b,false,sizeof(b));
    for(ll i=1;i<=n;i++)
    {
        if(A[i].size()==0)
        ans[i] = -1;
        else
        {
            if(ans[i]==-1)
            {
                cnt = 0;
                ANS = -1;
                dfs(i,a[i]%2);
                ans[i] = ANS;
                memset(b,false,sizeof(b));
            }
        }
    }
    for(ll i=1;i<=n;i++) cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pll pair<ll,ll>
#define mod 1000000007
#define pb push_back
#define ld long double
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define N 200000
vector<ll> a[N+1],val(N+1);
bool b[N+1];
ll ans[N+1][2], lev[N+1];
ll f = 0;
void dfs(ll x)
{
	b[x] = true;
	for(ll i=0;i<a[x].size();i++)
	{
		if(b[a[x][i]]==false)
		{
			dfs(a[x][i]);
		}
	    for(ll j=0;j<2;j++)
    	{
    	    if(ans[a[x][i]][j]!=1e18)
    	    {
    	        if(ans[a[x][i]][j] + 1 < ans[x][j]) f = 1;
    	        ans[x][j] = min(ans[x][j], ans[a[x][i]][j] + 1);
    	    }
    	}
	}
}
void solve()
{
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>val[i];
        if(i-val[i] >= 1)
        {
            a[i].pb(i-val[i]);
        }
        if(i+val[i]<=n)
        {
            a[i].pb(i+val[i]);
        }
    }
    for(ll i=1;i<=n;i++)
    {
        ans[i][0] = 1e18;
        ans[i][1] = 1e18;
        ans[i][val[i]%2] = 0;
    }
    memset(b,false,sizeof(b));
    while(1)
    {
        f = 0;
        for(ll i=1;i<=n;i++)
        {
            if(ans[i][(val[i] + 1)%2]==1e18)
            {
                dfs(i);
            }
            for(ll j=0;j<2;j++)
        	{
        	    if((i + val[i])<=n && ans[i + val[i]][j]!=1e18)
        	    {
        	        if(ans[i + val[i]][j] + 1 < ans[i][j]) f = 1;
        	        ans[i][j] = min(ans[i][j], ans[i + val[i]][j] + 1);
        	    }
        	    if((i - val[i]) >= 1 && ans[i - val[i]][j]!=1e18)
        	    {
        	        if(ans[i - val[i]][j] + 1 < ans[i][j]) f = 1;
        	        ans[i][j] = min(ans[i][j], ans[i - val[i]][j] + 1);
        	    }
        	}
        }
        if(f==0) break;
    }
    for(ll i=1;i<=n;i++)
    {
        if(ans[i][(val[i] + 1)%2]==1e18) cout<<-1<<" ";
        else cout<<ans[i][(val[i] + 1)%2]<<" ";
    }
}

int main()
{
	FIO;
	ll t=1;
	//cin>>t;
	while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pll pair<ll,ll>
#define mod 1000000007
#define pb push_back
#define ld long double
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define N 200000
vector<ll> a[N+1],val(N+1);
bool b[N+1];
ll ans[N+1][2], lev[N+1];
void dfs(ll x)
{
	b[x] = true;
	for(ll i=0;i<a[x].size();i++)
	{
		if(b[a[x][i]]==false)
		{
			dfs(a[x][i]);
		}
	    for(ll j=0;j<2;j++)
    	{
    	    if(ans[a[x][i]][j]!=1e18)
    	    {
    	        ans[x][j] = min(ans[x][j], ans[a[x][i]][j] + 1);
    	    }
    	}
	}
}
void solve()
{
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>val[i];
        if(i-val[i] >= 1)
        {
            a[i].pb(i-val[i]);
        }
        if(i+val[i]<=n)
        {
            a[i].pb(i+val[i]);
        }
    }
    for(ll i=1;i<=n;i++)
    {
        ans[i][0] = 1e18;
        ans[i][1] = 1e18;
        ans[i][val[i]%2] = 0;
    }
    memset(b,false,sizeof(b));
    for(ll k=0;k<2;k++)
    {
        for(ll i=1;i<=n;i++)
        {
            if(ans[i][(val[i] + 1)%2]==1e18)
            {
                dfs(i);
            }
            else
            {
                for(ll j=0;j<2;j++)
            	{
            	    if((i + val[i])<=n && ans[i + val[i]][j]!=1e18)
            	    {
            	        ans[i][j] = min(ans[i][j], ans[i + val[i]][j] + 1);
            	    }
            	    if((i - val[i]) >= 1 && ans[i - val[i]][j]!=1e18)
            	    {
            	        ans[i][j] = min(ans[i][j], ans[i - val[i]][j] + 1);
            	    }
            	}
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        if(ans[i][(val[i] + 1)%2]==1e18) cout<<-1<<" ";
        else cout<<ans[i][(val[i] + 1)%2]<<" ";
    }
}

int main()
{
	FIO;
	ll t=1;
	//cin>>t;
	while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pll pair<ll,ll>
#define mod 1000000007
#define pb push_back
#define ld long double
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define N 200000
vector<ll> a[N+1],val(N+1);
bool b[N+1];
ll ans[N+1][2], lev[N+1];
pll dp[N+1][2];
void dfs(ll x)
{
	b[x] = true;
	for(ll i=0;i<a[x].size();i++)
	{
	    lev[a[x][i]] = lev[x] + 1;
		if(b[a[x][i]]==false)
		{
			dfs(a[x][i]);
		}
	    for(ll j=0;j<2;j++)
    	{
    	    if(ans[a[x][i]][j]!=1e18)
    	    {
    	        ans[x][j] = min(ans[x][j], ans[a[x][i]][j] + 1);
    	    }
    	}
	}
}
void solve()
{
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>val[i];
        if(i-val[i] >= 1)
        {
            //a[i-val[i]].pb(i);
            a[i].pb(i-val[i]);
        }
        if(i+val[i]<=n)
        {
            //a[i+val[i]].pb(i);
            a[i].pb(i+val[i]);
        }
    }
    for(ll i=1;i<=n;i++)
    {
        ans[i][0] = 1e18;
        ans[i][1] = 1e18;
        ans[i][val[i]%2] = 0;
        dp[i][0].ff = 1e18;dp[i][1].ff = 1e18;
    }
    memset(b,false,sizeof(b));
    for(ll i=1;i<=n;i++)
    {
        if(b[i]==false)
        {
            lev[i] = 0;
            dfs(i);
        }
    }
    for(ll i=1;i<=n;i++)
    {
        if(ans[i][(val[i] + 1)%2]==1e18) cout<<-1<<" ";
        else cout<<ans[i][(val[i] + 1)%2]<<" ";
    }
}

int main()
{
	FIO;
	ll t=1;
	//cin>>t;
	while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pll pair<ll,ll>
#define mod 1000000007
#define pb push_back
#define ld long double
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define N 200000
vector<ll> a[N+1],val(N+1);
bool b[N+1];
ll ans[N+1][2], lev[N+1];
void dfs(ll x)
{
	b[x] = true;
	for(ll i=0;i<a[x].size();i++)
	{
		if(b[a[x][i]]==false)
		{
			dfs(a[x][i]);
		}
	    for(ll j=0;j<2;j++)
    	{
    	    if(ans[a[x][i]][j]!=1e18)
    	    {
    	        ans[x][j] = min(ans[x][j], ans[a[x][i]][j] + 1);
    	    }
    	}
	}
}
void solve()
{
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>val[i];
        if(i-val[i] >= 1)
        {
            a[i].pb(i-val[i]);
        }
        if(i+val[i]<=n)
        {
            a[i].pb(i+val[i]);
        }
    }
    for(ll i=1;i<=n;i++)
    {
        ans[i][0] = 1e18;
        ans[i][1] = 1e18;
        ans[i][val[i]%2] = 0;
    }
    memset(b,false,sizeof(b));
    for(ll k=0;k<3;k++)
    {
        for(ll i=1;i<=n;i++)
        {
            if(ans[i][(val[i] + 1)%2]==1e18)
            {
                dfs(i);
            }
            for(ll j=0;j<2;j++)
        	{
        	    if((i + val[i])<=n && ans[i + val[i]][j]!=1e18)
        	    {
        	        ans[i][j] = min(ans[i][j], ans[i + val[i]][j] + 1);
        	    }
        	    if((i - val[i]) >= 1 && ans[i - val[i]][j]!=1e18)
        	    {
        	        ans[i][j] = min(ans[i][j], ans[i - val[i]][j] + 1);
        	    }
        	}
        }
    }
    for(ll i=1;i<=n;i++)
    {
        if(ans[i][(val[i] + 1)%2]==1e18) cout<<-1<<" ";
        else cout<<ans[i][(val[i] + 1)%2]<<" ";
    }
}

int main()
{
	FIO;
	ll t=1;
	//cin>>t;
	while(t--) solve();
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
vector<ll> A[200005],a(200005),ans(200005,-1);
bool b[200005];
ll cnt = 0,ANS = -1;
void dfs(ll x,ll par)
{
    b[x] = true;
    if(a[x]%2!=par) {
        ANS = cnt;
        return;
    }
    cnt++;
    for(ll i=0;i<A[x].size();i++)
    {
        if(ANS!=-1) return;
        if(b[A[x][i]] == false)
        {
            dfs(A[x][i],par);
        }
    }
}

int main() {
    FIO;
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++) cin>>a[i];
    vector<ll> foo[2];
    for(ll i=1;i<=n;i++)
    {
        foo[a[i]%2].pb(i);
    }
    if(foo[0].size()==0 || foo[1].size()==0)
    {
        for(ll i=0;i<n;i++) cout<<0<<" ";
        return 0;
    }
    for(ll i=0;i<min(foo[0].size(),foo[1].size());i++)
    {
        ll cnt = 0,ind;
        if(foo[0].size() < foo[1].size()) ind = foo[0][i];
        else ind = foo[1][i];
        ll val = a[ind];
    }
    for(ll i=1;i<=n;i++)
    {
        if(a[i] + i <= n) A[i].pb(a[i] + i);
        if(i - a[i] >= 1) A[i].pb(i - a[i]);
    }
    memset(b,false,sizeof(b));
    for(ll i=1;i<=n;i++)
    {
        if(A[i].size()==0)
        ans[i] = -1;
        else
        {
            if(ans[i]==-1)
            {
                cnt = 0;
                ANS = -1;
                dfs(i,a[i]%2);
                ans[i] = ANS;
                memset(b,false,sizeof(b));
            }
        }
    }
    for(ll i=1;i<=n;i++) cout<<ans[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
vector<ll> A[200005],a(200005),ans(200005,-1);
bool b[200005];
ll cnt = 0,ANS = -1;
void dfs(ll x,ll par)
{
    b[x] = true;
    if(a[x]%2!=par) {
        ANS = cnt;
        return;
    }
    cnt++;
    for(ll i=0;i<A[x].size();i++)
    {
        if(ANS!=-1) return;
        if(b[A[x][i]] == false)
        {
            dfs(A[x][i],par);
        }
    }
}

int main() {
    FIO;
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++) cin>>a[i];
    for(ll i=1;i<=n;i++)
    {
        if(a[i] + i <= n) A[i].pb(a[i] + i);
        if(i - a[i] >= 1) A[i].pb(i - a[i]);
    }
    memset(b,false,sizeof(b));
    for(ll i=1;i<=n;i++)
    {
        if(A[i].size()==0)
        ans[i] = -1;
        else
        {
                cnt = 0;
                ANS = -1;
                dfs(i,a[i]%2);
                ans[i] = ANS;
                memset(b,false,sizeof(b));
        }
    }
    for(ll i=1;i<=n;i++) cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pll pair<ll,ll>
#define mod 1000000007
#define pb push_back
#define ld long double
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define N 200000
vector<ll> a[N+1],val(N+1),adj[N+1];
bool b[N+1];
ll ans[N+1][2], lev[N+1];
ll f = 0;
void dfs(ll x)
{
	b[x] = true;
	for(ll i=0;i<a[x].size();i++)
	{
		if(b[a[x][i]]==false)
		{
			dfs(a[x][i]);
		}
	    for(ll j=0;j<2;j++)
    	{
    	    if(ans[a[x][i]][j]!=1e18)
    	    {
    	        if(ans[a[x][i]][j] + 1 < ans[x][j]) f = 1;
    	        ans[x][j] = min(ans[x][j], ans[a[x][i]][j] + 1);
    	    }
    	}
	}
}
void solve()
{
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>val[i];
        if(i-val[i] >= 1)
        {
            adj[i-val[i]].pb(i);
            a[i].pb(i-val[i]);
        }
        if(i+val[i]<=n)
        {
            adj[i+val[i]].pb(i);
            a[i].pb(i+val[i]);
        }
    }
    for(ll i=1;i<=n;i++)
    {
        ans[i][0] = 1e18;
        ans[i][1] = 1e18;
        ans[i][val[i]%2] = 0;
    }
    memset(b,false,sizeof(b));
    while(1)
    {
        f = 0;
        for(ll i=1;i<=n;i++)
        {
            if(ans[i][(val[i] + 1)%2]==1e18)
            {
                dfs(i);
            }
            for(ll j=0;j<2;j++)
        	{
        	    if((i + val[i])<=n && ans[i + val[i]][j]!=1e18)
        	    {
        	        if(ans[i + val[i]][j] + 1 < ans[i][j]) f = 1;
        	        ans[i][j] = min(ans[i][j], ans[i + val[i]][j] + 1);
        	    }
        	    if((i - val[i]) >= 1 && ans[i - val[i]][j]!=1e18)
        	    {
        	        if(ans[i - val[i]][j] + 1 < ans[i][j]) f = 1;
        	        ans[i][j] = min(ans[i][j], ans[i - val[i]][j] + 1);
        	    }
        	}
        	ll sz = adj[i].size();
        	for(ll k=0;k<2;k++)
        	{
            	if(ans[i][k]!=1e18)
            	{
            	    for(ll j=0;j<sz;j++)
            	    {
            	        if(ans[adj[i][j]][k] > ans[i][k] + 1)
            	        {
            	            f = 1;
            	            ans[adj[i][j]][k] = ans[i][k] + 1;
            	        }
            	    }
            	}
            }
        }
        if(f==0) break;
    }
    for(ll i=1;i<=n;i++)
    {
        if(ans[i][(val[i] + 1)%2]==1e18) cout<<-1<<" ";
        else cout<<ans[i][(val[i] + 1)%2]<<" ";
    }
}

int main()
{
	FIO;
	ll t=1;
	//cin>>t;
	while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pll pair<ll,ll>
#define mod 1000000007
#define pb push_back
#define ld long double
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define N 200000
vector<ll> a[N+1],val(N+1);
bool b[N+1];
ll ans[N+1][2], lev[N+1];
void dfs(ll x)
{
	b[x] = true;
	for(ll i=0;i<a[x].size();i++)
	{
		if(b[a[x][i]]==false)
		{
			dfs(a[x][i]);
		}
	    for(ll j=0;j<2;j++)
    	{
    	    if(ans[a[x][i]][j]!=1e18)
    	    {
    	        ans[x][j] = min(ans[x][j], ans[a[x][i]][j] + 1);
    	    }
    	}
	}
}
void solve()
{
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>val[i];
        if(i-val[i] >= 1)
        {
            a[i].pb(i-val[i]);
        }
        if(i+val[i]<=n)
        {
            a[i].pb(i+val[i]);
        }
    }
    for(ll i=1;i<=n;i++)
    {
        ans[i][0] = 1e18;
        ans[i][1] = 1e18;
        ans[i][val[i]%2] = 0;
    }
    memset(b,false,sizeof(b));
    for(ll k=0;k<2;k++)
    {
        for(ll i=1;i<=n;i++)
        {
            if(ans[i][(val[i] + 1)%2]==1e18)
            {
                dfs(i);
            }
            for(ll j=0;j<2;j++)
        	{
        	    if((i + val[i])<=n && ans[i + val[i]][j]!=1e18)
        	    {
        	        ans[i][j] = min(ans[i][j], ans[i + val[i]][j] + 1);
        	    }
        	    if((i - val[i]) >= 1 && ans[i - val[i]][j]!=1e18)
        	    {
        	        ans[i][j] = min(ans[i][j], ans[i - val[i]][j] + 1);
        	    }
        	}
        }
    }
    for(ll i=1;i<=n;i++)
    {
        if(ans[i][(val[i] + 1)%2]==1e18) cout<<-1<<" ";
        else cout<<ans[i][(val[i] + 1)%2]<<" ";
    }
}

int main()
{
	FIO;
	ll t=1;
	//cin>>t;
	while(t--) solve();
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int mxn=2e5+5;
stack<int>me,you,odd,even;
int n,a[mxn],cnt;
bool been[mxn][2];
vector<int>adj[mxn];
void bfs(bool ,int []);

int main()
{
    cin>>n;
    int ans[n+1]={0};
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i+a[i]<=n)
            adj[a[i]+i].push_back(i);
        if(i-a[i]>0)
            adj[i-a[i]].push_back(i);
        if(a[i]%2)
        {
            odd.push(i);
            been[i][1]=1;
        }
        else
        {
            even.push(i);
            been[i][0]=1;
        }
    }
    bfs(1,ans);
    bfs(0,ans);
    for(int i=1;i<=n;i++)
    {
        if(!ans[i])
            cout<<-1<<" ";
        else
            cout<<ans[i]<<" ";
    }
    return 0;
}
void bfs(bool b, int ans[])
{
    if(b)
        swap(odd,me);
    else
        swap(even,me);
    cnt=0;
    while(me.size())
    {
        while(me.size())
        {
            int x=me.top();
            if(a[x]%2 != b)
                ans[x]=cnt;
            for(int i=0;i<adj[x].size();i++)
                if(!been[adj[x][i]][b])
                        you.push(adj[x][i]);
            me.pop();
        }
        swap(me,you);
        cnt++;
    }
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int mxn=2e5+5;
stack<int>me,you,odd,even;
int n,cnt,ans[mxn],a[mxn];
bool been[20005][2];
vector<int>adj[20005];
void bfs(bool);

int main()
{
    ios::sync_with_stdio(false),cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i+a[i]<=n)
            adj[a[i]+i].push_back(i);
        if(i-a[i]>0)
            adj[i-a[i]].push_back(i);
        if(a[i]%2)
        {
            odd.push(i);
            been[i][1]=1;
        }
        else
        {
            even.push(i);
            been[i][0]=1;
        }
    }
    bfs(1);
    bfs(0);
    for(int i=1;i<=n;i++)
    {
        if(!ans[i])
            cout<<-1<<" ";
        else
            cout<<ans[i]<<" ";
    }
    return 0;
}
void bfs(bool b)
{
    if(b)
        swap(odd,me);
    else
        swap(even,me);
    cnt=0;
    while(me.size())
    {
        while(me.size())
        {
            int x=me.top();
            if(a[x]%2 != b)
                ans[x]=cnt;
            for(int i=0;i<adj[x].size();i++)
                if(!been[adj[x][i]][b])
                        you.push(adj[x][i]);
            me.pop();
        }
        swap(me,you);
        cnt++;
    }
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int mxn=2e5+5;
int n,a[mxn],dp[mxn];
bool use [mxn];
int ans(int );

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
    {
        if(ans(i)>=mxn)
            cout<<-1<<" ";
        else
            cout<<dp[i]<<" ";
    }
    return 0;
}
int ans(int i)
{
    if(dp[i])
        return dp[i];
    if((a[i]+i>n && i-a[i]<1))
    {
        dp[i]=mxn;
        return dp[i];
    }
    if(i+a[i]<=n && (a[i]%2 != a[i+a[i]]%2))
    {
        dp[i]=1;
        return 1;
    }
    if(i-a[i]>0 && (a[i]%2 != a[i-a[i]]%2))
    {
        dp[i]=1;
        return 1;
    }
    if(use[i])
    {
        return mxn;
    }
    use[i]=1;
    int x=mxn;
    if(a[i]+i<=n)
        x=ans(a[i]+i);
    if(i-a[i]>=0)
        x=min(x,ans(i-a[i]));
    dp[i]=x+1;
    return dp[i];
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int mxn=2e5+5;
stack<int>me,you,odd,even;
int ans[mxn],n,a[mxn],cnt;
bool been[mxn][2];
vector<int>adj[mxn];
void bfs(bool );

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i+a[i]<=n)
            adj[a[i]+i].push_back(i);
        if(i-a[i]>0)
            adj[i-a[i]].push_back(i);
        if(a[i]%2)
        {
            odd.push(i);
            been[i][1]=1;
        }
        else
        {
            even.push(i);
            been[i][0]=1;
        }
    }
    bfs(1);
    bfs(0);
    for(int i=1;i<=n;i++)
    {
        if(!ans[i])
            cout<<-1<<" ";
        else
            cout<<ans[i]<<" ";
    }
    return 0;
}
void bfs(bool b)
{
    if(b)
        swap(odd,me);
    else
        swap(even,me);
    cnt=0;
    while(me.size())
    {
        while(me.size())
        {
            int x=me.top();
            if(a[x]%2 != b)
                ans[x]=cnt;
            for(int i=0;i<adj[x].size();i++)
                if(!been[adj[x][i]][b])
                        you.push(adj[x][i]);
            me.pop();
        }
        swap(me,you);
        cnt++;
    }
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

const int mxn=2e5+5;

int n;
bool been[mxn][2];
stack<int>me,you,odd,even;
vector<int>adj[mxn];

void bfs(bool  , vector<int> &);

int main()
{
    ios::sync_with_stdio(false),cin.tie(0);

    cin>>n;
    int a[n+1];
    vector<int>ans;
    for(int i=0;i<n;i++)
        ans.push_back(-1);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]+i<=n)
            adj[a[i]+i].push_back(i);
        if(i-a[i]>0)
            adj[i-a[i]].push_back(i);
        if(a[i]%2)
        {
            odd.push(i);
            been[i][1]=true;
        }
        else
        {
            even.push(i);
            been[i][0]=true;
        }
    }
    bfs(0,ans);
    bfs(1,ans);

    for(int i=1;i<=n;i++)
        cout<<ans[i]<<" ";
    return 0;
}
void bfs(bool q , vector<int> & ans)
{
    if(q)
        me=odd;
    else
        me=even;
    int cnt=1;
    while(me.size())
    {
        while(me.size())
        {
            int u=me.top();
            me.pop();
            for(auto v:adj[u])
            {
                if(!been[v][q])
                {
                    been[v][q]=1;
                    you.push(v);
                    ans[v]=cnt;
                }
            }
        }
        swap(me,you);
        cnt++;
    }
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int mxn=2e5+5;
int n,a[mxn],dp[mxn];
bool use [mxn];
int ans(int );

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
    {
        if(ans(i)>=mxn)
            cout<<-1<<" ";
        else
            cout<<dp[i]<<" ";
    }
    return 0;
}
int ans(int i)
{
    if(dp[i])
        return dp[i];
    if((a[i]+i>n && i-a[i]<1))
    {
        dp[i]=mxn;
        return dp[i];
    }
    if(i+a[i]<=n && (a[i]%2 != a[i+a[i]]%2))
    {
        dp[i]=1;
        return 1;
    }
    if(i-a[i]>0 && (a[i]%2 != a[i-a[i]]%2))
    {
        dp[i]=1;
        return 1;
    }
    if(use[i])
    {
        return mxn;
    }
    use[i]=1;
    int x=mxn;
    if(a[i]+i<=n)
        x=ans(a[i]+i);
    if(i-a[i]>0)
        x=min(x,ans(i-a[i]));
    dp[i]=x+1;
    return dp[i];
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int int16_t
const int16_t mxn=2e5+5;
stack<int>me,you,odd,even;

int n,cnt;
bool been[20005][2];
vector<int>adj[20005];
inline void bfs(bool ,int [],int []);

int32_t main()
{
    ios::sync_with_stdio(false),cin.tie(0);
    cin>>n;
    int ans[n+1]={0},a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i+a[i]<=n)
            adj[a[i]+i].push_back(i);
        if(i-a[i]>0)
            adj[i-a[i]].push_back(i);
        if(a[i]%2)
        {
            odd.push(i);
            been[i][1]=1;
        }
        else
        {
            even.push(i);
            been[i][0]=1;
        }
    }
    bfs(1,ans,a);
    bfs(0,ans,a);
    for(int i=1;i<=n;i++)
    {
        if(!ans[i])
            cout<<-1<<" ";
        else
            cout<<ans[i]<<" ";
    }
    return 0;
}
inline void bfs(bool b, int ans[],int a[])
{
    if(b)
        swap(odd,me);
    else
        swap(even,me);
    cnt=0;
    while(me.size())
    {
        while(me.size())
        {
            int x=me.top();
            if(a[x]%2 != b)
                ans[x]=cnt;
            for(int i=0;i<adj[x].size();i++)
                if(!been[adj[x][i]][b])
                        you.push(adj[x][i]);
            me.pop();
        }
        swap(me,you);
        cnt++;
    }
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

const int mxn=2e5+5;

int n;
bool been[mxn][2];
stack<int>me,you,odd,even;
vector<int>adj[mxn];

void bfs(bool  , vector<int> &);

int main()
{
    ios::sync_with_stdio(false),cin.tie(0);

    cin>>n;
    int a[n+1];
    vector<int>ans;
    for(int i=0;i<=n;i++)
        ans.push_back(-1);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]+i<=n)
            adj[a[i]+i].push_back(i);
        if(i-a[i]>0)
            adj[i-a[i]].push_back(i);
        if(a[i]%2)
        {
            odd.push(i);
            been[i][1]=true;
        }
        else
        {
            even.push(i);
            been[i][0]=true;
        }
    }
    bfs(0,ans);
    bfs(1,ans);

    for(int i=1;i<=n;i++)
        cout<<ans[i]<<" ";
    return 0;
}
void bfs(bool q , vector<int> & ans)
{
    if(q)
        me=odd;
    else
        me=even;
    int cnt=1;
    while(me.size())
    {
        while(me.size())
        {
            int u=me.top();
            me.pop();
            for(auto v:adj[u])
            {
                if(!been[v][q])
                {
                    been[v][q]=1;
                    you.push(v);
                    ans[v]=cnt;
                }
            }
        }
        swap(me,you);
        cnt++;
    }
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int mxn=2e5+5;
stack<int>me,you,odd,even;
int n,cnt;
bool been[mxn][2];
vector<int>adj[mxn];
void bfs(bool ,int [],int []);

int main()
{
    cin>>n;
    int ans[n+1]={0},a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i+a[i]<=n)
            adj[a[i]+i].push_back(i);
        if(i-a[i]>0)
            adj[i-a[i]].push_back(i);
        if(a[i]%2)
        {
            odd.push(i);
            been[i][1]=1;
        }
        else
        {
            even.push(i);
            been[i][0]=1;
        }
    }
    bfs(1,ans,a);
    bfs(0,ans,a);
    for(int i=1;i<=n;i++)
    {
        if(!ans[i])
            cout<<-1<<" ";
        else
            cout<<ans[i]<<" ";
    }
    return 0;
}
void bfs(bool b, int ans[],int a[])
{
    if(b)
        swap(odd,me);
    else
        swap(even,me);
    cnt=0;
    while(me.size())
    {
        while(me.size())
        {
            int x=me.top();
            if(a[x]%2 != b)
                ans[x]=cnt;
            for(int i=0;i<adj[x].size();i++)
                if(!been[adj[x][i]][b])
                        you.push(adj[x][i]);
            me.pop();
        }
        swap(me,you);
        cnt++;
    }
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int mxn=2e5+5;
int n,a[mxn],dp[mxn];
bool use [mxn];
int ans(int );

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
    {
        //cout<<i<<" :"<<ans(i)<<'\n';
        if(ans(i)>=mxn)
            cout<<-1<<" ";
        else
            cout<<dp[i]<<" ";
    }
    return 0;
}
int ans(int i)
{
    if(dp[i])
        return dp[i];
    if(i+a[i]>n && i-a[i]<1)
    {
        dp[i]=mxn;
        return dp[i];
    }
    int x=mxn;
    if(use[i])
    {
        return mxn;
    }
    use[i]=1;
    if(i+a[i]<=n)
    {
        if(a[i]%2 != a[i+a[i]]%2)
        {
            dp[i]=1;
            return dp[i];
        }
        x=ans(a[i]+i);
    }
    if(i-a[i]>0)
    {
        if(a[i]%2 != a[i-a[i]]%2)
        {
            dp[i]=1;
            return dp[i];
        }
        x=min(x,ans(i-a[i]));
    }
    dp[i]=x+1;
    return dp[i];
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int int16_t
const int16_t mxn=2e5+5;
stack<int>me,you,odd,even;

int n,cnt;
bool been[20005][2];
vector<int>adj[20005];
void bfs(bool ,int [],int []);

int32_t main()
{
    cin>>n;
    int ans[n+1]={0},a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i+a[i]<=n)
            adj[a[i]+i].push_back(i);
        if(i-a[i]>0)
            adj[i-a[i]].push_back(i);
        if(a[i]%2)
        {
            odd.push(i);
            been[i][1]=1;
        }
        else
        {
            even.push(i);
            been[i][0]=1;
        }
    }
    bfs(1,ans,a);
    bfs(0,ans,a);
    for(int i=1;i<=n;i++)
    {
        if(!ans[i])
            cout<<-1<<" ";
        else
            cout<<ans[i]<<" ";
    }
    return 0;
}
void bfs(bool b, int ans[],int a[])
{
    if(b)
        swap(odd,me);
    else
        swap(even,me);
    cnt=0;
    while(me.size())
    {
        while(me.size())
        {
            int x=me.top();
            if(a[x]%2 != b)
                ans[x]=cnt;
            for(int i=0;i<adj[x].size();i++)
                if(!been[adj[x][i]][b])
                        you.push(adj[x][i]);
            me.pop();
        }
        swap(me,you);
        cnt++;
    }
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int mxn=2e5+5;
int n,a[mxn],dp[mxn];
bool use [mxn];
int ans(int );

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
    {
        if(ans(i)>=mxn)
            cout<<-1<<" ";
        else
            cout<<dp[i]<<" ";
    }
    return 0;
}
int ans(int i)
{
    if(dp[i])
        return dp[i];
    if((a[i]+i>n && i-a[i]<1))
    {
        dp[i]=mxn;
        return dp[i];
    }
    if(i+a[i]<=n && (a[i]%2 != a[i+a[i]]%2))
    {
        dp[i]=1;
        return 1;
    }
    if(i-a[i]>=0 && (a[i]%2 != a[i-a[i]]%2))
    {
        dp[i]=1;
        return 1;
    }
    if(use[i])
    {
        return mxn;
    }
    use[i]=1;
    int x=mxn;
    if(a[i]+i<=n)
        x=ans(a[i]+i);
    if(i-a[i]>=0)
        x=min(x,ans(i-a[i]));
    dp[i]=x+1;
    return dp[i];
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int mxn=2e5+5;
stack<int>me,you,odd,even;
int n,cnt,ans[mxn],a[mxn];
bool been[20005][2];
vector<int>adj[20005];
void bfs(bool);

int main()
{
    ios::sync_with_stdio(false),cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i+a[i]<=n)
            adj[a[i]+i].push_back(i);
        if(i-a[i]>0)
            adj[i-a[i]].push_back(i);
        if(a[i]%2)
        {
            odd.push(i);
            been[i][1]=1;
        }
        else
        {
            even.push(i);
            been[i][0]=1;
        }
    }
    bfs(1,ans,a);
    bfs(0,ans,a);
    for(int i=1;i<=n;i++)
    {
        if(!ans[i])
            cout<<-1<<" ";
        else
            cout<<ans[i]<<" ";
    }
    return 0;
}
void bfs(bool b)
{
    if(b)
        swap(odd,me);
    else
        swap(even,me);
    cnt=0;
    while(me.size())
    {
        while(me.size())
        {
            int x=me.top();
            if(a[x]%2 != b)
                ans[x]=cnt;
            for(int i=0;i<adj[x].size();i++)
                if(!been[adj[x][i]][b])
                        you.push(adj[x][i]);
            me.pop();
        }
        swap(me,you);
        cnt++;
    }
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"

using namespace std;

const int N = 500777;
int inf = 1e6;
int a[N];
int c;
int n;
vector <int> g[N];
int ans[N];
set <pair <int, int> > st;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        ans[i] = inf;
        if (i - a[i] >= 1){
            g[i - a[i]].pb(i);
        }
        if (i + a[i] <= n){
            g[i + a[i]].pb(i);
        }
    }

    for (int i = 1; i <= n; i++){
        bool fl = 0;
        if (i + a[i] <= n){
            int t = i + a[i];
            if (a[t] % 2 != a[i] % 2)
                fl = 1;
        }
        if (i - a[i] >= 1){
            int t = i - a[i];
            if (a[t] % 2 != a[i] % 2){
                fl = 1;
            }
        }
        if (fl){
            ans[i] = 1;
            st.insert({1, i});
        }
    }

    int cnt = 0;
    if (st.size() > 0)
    while (!st.empty()){
        cnt++;
        if (cnt > n){
            cout << 0 << endl;
            return 0;
        }
        auto it = st.begin();
        st.erase(st.begin());
        pair <int, int> p = *it;
        int v = p.se;
        int d = p.fi;
        if (g[v].size() == 0)
            continue;
        for (int i = 0; i < g[v].size(); i++){
            int to = g[v][i];
            if (ans[to] == inf){
                ans[to] = d + 1;
                st.insert({d + 1, to});
            }
        }
    }

    for (int i = 1; i <= n; i++){
        if (ans[i] == inf){
            ans[i] = -1;
        }
        cout << ans[i] << " ";
    }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"

using namespace std;

const int N = 200777;
int inf = 1e7;
int a[N];
int dp[N];
int clr[N];
int c;
int n;
vector <int> g[N];
bool used[N];

void dfs(int v){
    used[v] = 1;
    clr[v] = c;
    for (int i = 0; i < g[v].size(); i++){
        int to = g[v][i];
        if (a[to] % 2 != a[v] % 2){
            dp[v] = 1;
        }
        else {
            if (used[to] == 1){
                dp[v] = min(dp[v], dp[to] + 1);
            }
            else {
                dfs(to);
                dp[v] = min(dp[v], dp[to] + 1);
            }
        }
    }
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        dp[i] = inf;
        if (i - a[i] >= 1){
            g[i].pb(i - a[i]);
        }
        if (i + a[i] <= n){
            g[i].pb(i + a[i]);
        }
    }

    for (int i = 1; i <= n; i++){
        if (used[i]){
            if (dp[i] == inf){
                cout << -1 << " ";
            }
            else {
                cout << dp[i] << " ";
            }
        }
        else {
            c++;
            dfs(i);
            if (dp[i] == inf){
                cout << -1 << " ";
            }
            else {
                cout << dp[i] << " ";
            }
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define int long long

using namespace std;

const int N = 500777;
int inf = 1e7;
int a[N];
int c;
int n;
vector <int> g[N];
int ans[N];
set <pair <int, int> > st;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        ans[i] = inf;
        if (i - a[i] >= 1){
            g[i - a[i]].pb(i);
        }
        if (i + a[i] <= n){
            g[i + a[i]].pb(i);
        }
    }

    for (int i = 1; i <= n; i++){
        bool fl = 0;
        if (i + a[i] <= n){
            if (a[i + a[i]] % 2 != a[i] % 2)
                fl = 1;
        }
        if (i - a[i] >= 1){
            if (a[i - a[i]] % 2 != a[i] % 2){
                fl = 1;
            }
        }
        if (fl){
            ans[i] = 1;
            st.insert({1, i});
        }
    }

    if (st.size() > 0)
    while (!st.empty()){
        auto it = st.begin();
        st.erase(st.begin());
        pair <int, int> p = *it;
        int v = p.se;
        int d = p.fi;
        if (g[v].size() == 0)
            continue;
        for (int i = 0; i < g[v].size(); i++){
            int to = g[v][i];
            if (ans[to] == inf){
                ans[to] = d + 1;
                st.insert({d + 1, to});
            }
        }
    }

    for (int i = 1; i <= n; i++){
        if (ans[i] == inf){
            ans[i] = -1;
        }
        cout << ans[i] << " ";
    }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define int long long

using namespace std;

const int N = 500777;
int inf = 1e6;
int a[N];
int c;
int n;
vector <int> g[N];
int ans[N];
set <pair <int, int> > st;
queue <int > q;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        ans[i] = inf;
        if (i - a[i] >= 1){
            g[i - a[i]].pb(i);
        }
        if (i + a[i] <= n){
            g[i + a[i]].pb(i);
        }
    }

    for (int i = 1; i <= n; i++){
        bool fl = 0;
        if (i + a[i] <= n){
            int t = i + a[i];
            if (a[t] % 2 != a[i] % 2)
                fl = 1;
        }
        if (i - a[i] >= 1){
            int t = i - a[i];
            if (a[t] % 2 != a[i] % 2){
                fl = 1;
            }
        }
        if (fl){
            ans[i] = 1;
            q.push(i);
        }
    }

    while (!q.empty()){
        int v = q.back();
        q.pop();
        for (int i = 0;i < g[v].size(); i++){
            int to = g[v][i];
            if (ans[to] == inf){
                q.push(to);
                ans[to] = ans[v] + 1;
            }
        }
    }

    for (int i = 1; i <= n; i++){
        if (ans[i] == inf){
            ans[i] = -1;
        }
        cout << ans[i] << " ";
    }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"

using namespace std;

const int N = 500777;
int inf = 1e7;
int a[N];
int c;
int n;
vector <int> g[N];
int ans[N];
set <pair <int, int> > st;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        ans[i] = inf;
        if (i - a[i] >= 1){
            g[i - a[i]].pb(i);
        }
        if (i + a[i] <= n){
            g[i + a[i]].pb(i);
        }
    }

    for (int i = 1; i <= n; i++){
        bool fl = 0;
        if (i + a[i] <= n){
            if (a[i + a[i]] % 2 != a[i] % 2)
                fl = 1;
        }
        if (i - a[i] >= 1){
            if (a[i - a[i]] % 2 != a[i] % 2){
                fl = 1;
            }
        }
        if (fl){
            ans[i] = 1;
            st.insert({1, i});
        }
    }

    int cnt = 0;
    if (st.size() > 0)
    while (!st.empty()){
        cnt++;
        if (cnt > n){
            cout << 0 << endl;
            return 0;
        }
        auto it = st.begin();
        st.erase(st.begin());
        pair <int, int> p = *it;
        int v = p.se;
        int d = p.fi;
        if (g[v].size() == 0)
            continue;
        for (int i = 0; i < g[v].size(); i++){
            int to = g[v][i];
            if (ans[to] == inf){
                ans[to] = d + 1;
                st.insert({d + 1, to});
            }
        }
    }

    for (int i = 1; i <= n; i++){
        if (ans[i] == inf){
            ans[i] = -1;
        }
        cout << ans[i] << " ";
    }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"

using namespace std;

const int N = 500777;
int inf = 1e7;
int a[N];
int c;
int n;
vector <int> g[N];
int ans[N];
set <pair <int, int> > st;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        ans[i] = inf;
        if (i - a[i] >= 1){
            g[i - a[i]].pb(i);
        }
        if (i + a[i] <= n){
            g[i + a[i]].pb(i);
        }
    }

    for (int i = 1; i <= n; i++){
        bool fl = 0;
        if (i + a[i] <= n){
            if (a[i + a[i]] % 2 != a[i] % 2)
                fl = 1;
        }
        if (i - a[i] >= 1){
            if (a[i - a[i]] % 2 != a[i] % 2){
                fl = 1;
            }
        }
        if (fl){
            ans[i] = 1;
            st.insert({1, i});
        }
    }

    if (st.size() > 0)
    while (!st.empty()){
        auto it = st.begin();
        st.erase(st.begin());
        pair <int, int> p = *it;
        int v = p.se;
        int d = p.fi;
        if (g[v].size() == 0)
            continue;
        for (int i = 0; i < g[v].size(); i++){
            int to = g[v][i];
            if (ans[to] == inf){
                ans[to] = d + 1;
                st.insert({d + 1, to});
            }
        }
    }

    for (int i = 1; i <= n; i++){
        if (ans[i] == inf){
            ans[i] = -1;
        }
        cout << ans[i] << " ";
    }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define int long long

using namespace std;

const int N = 300777;
int inf = 1e7;
int a[N];
int c;
int n;
vector <int> g[N];
int ans[N];
set <pair <int, int> > st;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        ans[i] = inf;
        if (i - a[i] >= 1){
            g[i - a[i]].pb(i);
        }
        if (i + a[i] <= n){
            g[i + a[i]].pb(i);
        }
    }

    for (int i = 1; i <= n; i++){
        bool fl = 0;
        if (i + a[i] <= n){
            if (a[i + a[i]] % 2 != a[i] % 2)
                fl = 1;
        }
        if (i - a[i] >= 1){
            if (a[i - a[i]] % 2 != a[i] % 2){
                fl = 1;
            }
        }
        if (fl){
            ans[i] = 1;
            st.insert({1, i});
        }
    }

    while (!st.empty()){
        auto it = st.begin();
        st.erase(st.begin());
        pair <int, int> p = *it;
        int v = p.se;
        int d = p.fi;
        for (int i = 0; i < g[v].size(); i++){
            int to = g[v][i];
            if (ans[to] == inf){
                ans[to] = d + 1;
                st.insert({d + 1, to});
            }
        }
    }

    for (int i = 1; i <= n; i++){
        if (ans[i] == inf){
            ans[i] = -1;
        }
        cout << ans[i] << " ";
    }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define int long long

using namespace std;

const int N = 200777;
int inf = 1e7;
int a[N];
int dp[N];
int clr[N];
int c;
int n;
vector <int> g[N];
bool used[N];
int ans[N];
set <pair <int, int> > st;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        ans[i] = inf;
        if (i - a[i] >= 1){
            g[i - a[i]].pb(i);
        }
        if (i + a[i] <= n){
            g[i + a[i]].pb(i);
        }
    }

    for (int i = 1; i <= n; i++){
        bool fl = 0;
        if (i + a[i] <= n){
            if (a[i + a[i]] % 2 != a[i] % 2)
                fl = 1;
        }
        if (i - a[i] >= 1){
            if (a[i - a[i]] % 2 != a[i] % 2){
                fl = 1;
            }
        }
        if (fl){
            ans[i] = 1;
            st.insert({1, i});
        }
    }

    while (!st.empty()){
        auto it = st.begin();
        st.erase(st.begin());
        pair <int, int> p = *it;
        int v = p.se;
        int d = p.fi;
        for (int i = 0; i < g[v].size(); i++){
            int to = g[v][i];
            if (ans[to] == inf){
                ans[to] = d + 1;
                st.insert({d + 1, to});
            }
        }
    }

    for (int i = 1; i <= n; i++){
        if (ans[i] == inf){
            ans[i] = -1;
        }
        cout << ans[i] << " ";
    }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define int long long

using namespace std;

const int N = 300777;
int inf = 1e7;
int a[N];
int c;
int n;
vector <int> g[N];
int ans[N];
set <pair <int, int> > st;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        ans[i] = inf;
        if (i - a[i] >= 1){
            g[i - a[i]].pb(i);
        }
        if (i + a[i] <= n){
            g[i + a[i]].pb(i);
        }
    }

    for (int i = 1; i <= n; i++){
        bool fl = 0;
        if (i + a[i] <= n){
            if (a[i + a[i]] % 2 != a[i] % 2)
                fl = 1;
        }
        if (i - a[i] >= 1){
            if (a[i - a[i]] % 2 != a[i] % 2){
                fl = 1;
            }
        }
        if (fl){
            ans[i] = 1;
            st.insert({1, i});
        }
    }

    if (st.size() > 0)
    while (!st.empty()){
        auto it = st.begin();
        st.erase(st.begin());
        pair <int, int> p = *it;
        int v = p.se;
        int d = p.fi;
        if (g[v].size() == 0)
            continue;
        for (int i = 0; i < g[v].size(); i++){
            int to = g[v][i];
            if (ans[to] == inf){
                ans[to] = d + 1;
                st.insert({d + 1, to});
            }
        }
    }

    for (int i = 1; i <= n; i++){
        if (ans[i] == inf){
            ans[i] = -1;
        }
        cout << ans[i] << " ";
    }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define int long long

using namespace std;

const int N = 500777;
int inf = 1e6;
int a[N];
int c;
int n;
vector <int> g[N];
int ans[N];
set <pair <int, int> > st;
queue <int> q;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        ans[i] = inf;
        if (i - a[i] >= 1){
            g[i - a[i]].pb(i);
        }
        if (i + a[i] <= n){
            g[i + a[i]].pb(i);
        }
    }

    for (int i = 1; i <= n; i++){
        bool fl = 0;
        if (i + a[i] <= n){
            int t = i + a[i];
            if (a[t] % 2 != a[i] % 2)
                fl = 1;
        }
        if (i - a[i] >= 1){
            int t = i - a[i];
            if (a[t] % 2 != a[i] % 2){
                fl = 1;
            }
        }
        if (fl){
            ans[i] = 1;
            q.push(i);
        }
    }

    while (!q.empty()){
        int v = q.front();
        q.pop();
        for (int i = 0; i < g[v].size(); i++){
            int to = g[v][i];
            if (ans[to] == inf){
                q.push(to);
                ans[to] = ans[v] + 1;
            }
        }
    }

    for (int i = 1; i <= n; i++){
        if (ans[i] == inf){
            ans[i] = -1;
        }
        cout << ans[i] << " ";
    }

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"

using namespace std;

const int N = 500777;
int inf = 1e15;
int a[N];
int c;
int n;
vector <int> g[N];
int ans[N];
set <pair <int, int> > st;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        ans[i] = inf;
        if (i - a[i] >= 1){
            g[i - a[i]].pb(i);
        }
        if (i + a[i] <= n){
            g[i + a[i]].pb(i);
        }
    }

    for (int i = 1; i <= n; i++){
        bool fl = 0;
        if (i + a[i] <= n){
            if (a[i + a[i]] % 2 != a[i] % 2)
                fl = 1;
        }
        if (i - a[i] >= 1){
            if (a[i - a[i]] % 2 != a[i] % 2){
                fl = 1;
            }
        }
        if (fl){
            ans[i] = 1;
            st.insert({1, i});
        }
    }

    int cnt = 0;
    if (st.size() > 0)
    while (!st.empty()){
        cnt++;
        if (cnt > n){
            cout << 0 << endl;
            return 0;
        }
        auto it = st.begin();
        st.erase(st.begin());
        pair <int, int> p = *it;
        int v = p.se;
        int d = p.fi;
        if (g[v].size() == 0)
            continue;
        for (int i = 0; i < g[v].size(); i++){
            int to = g[v][i];
            if (ans[to] == inf){
                ans[to] = d + 1;
                st.insert({d + 1, to});
            }
        }
    }

    for (int i = 1; i <= n; i++){
        if (ans[i] == inf){
            ans[i] = -1;
        }
        cout << ans[i] << " ";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<bool> visited(300000);
vector<bool> found(300000);
long long int val[300000];
void initialize(int n){
    for(int i=0;i<n;i++){
        visited[i]=false;
    }
}
void bfs(int i,vector<vector<int>> &adj_list,int a[],bool even){
    found[i]=true;
    visited[i]=true;
    for(int j=0;j<adj_list[i].size();j++){
        if(a[adj_list[i][j]]%2==0!=even){
            val[i]=1;
            return;
        }
    }
    long long int ans=INT_MAX;
    for(int j=0;j<adj_list[i].size();j++){
            if(found[adj_list[i][j]]){
                if(val[adj_list[i][j]]!=-1){
                    ans=min(ans,1+val[adj_list[i][j]]);
                }
            } else {
                bfs(adj_list[i][j],adj_list,a,even);
                if(val[adj_list[i][j]]!=-1){
                    ans=min(ans,1+val[adj_list[i][j]]);
                }
    }}
    if(ans!=INT_MAX){
        val[i]=ans;
    } else {
        val[i]=-1;
        found[i]=false;
    }
    visited[i]=false;
}

void bfs2(int i,vector<vector<int>> &adj_list,int a[],bool even){
    visited[i]=true;
    for(int j=0;j<adj_list[i].size();j++){
        if(a[adj_list[i][j]]%2==0!=even){
            val[i]=1;
            return;
        }
    }
    long long int ans=INT_MAX;
    for(int j=0;j<adj_list[i].size();j++){
            if(found[adj_list[i][j]]){
                if(val[adj_list[i][j]]!=-1){
                    ans=min(ans,1+val[adj_list[i][j]]);
                }
            }
    }
    if(ans!=INT_MAX){
        val[i]=ans;
    } else {
        val[i]=-1;
        found[i]=false;
    }
    visited[i]=false;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n+1;i++){
        found[i]=false;
        val[i]=-1;
    }
    int a[n+1];
    a[0]=0;
    for(int y=1;y<n+1;y++){
       cin>>a[y];
    }
    vector<vector<int>> adj_list(n+1);
    for(int i=1;i<n+1;i++){
        if(i-a[i]>=1){
            adj_list[i].push_back(i-a[i]);
        }
        if(i+a[i]<=n){
            adj_list[i].push_back(i+a[i]);
        }
    }
    for(int i=1;i<n+1;i++){
            bfs(i,adj_list,a,a[i]%2==0);
    }
    for(int i=1;i<n+1;i++){
       if(!found[i]){
        bfs(i,adj_list,a,a[i]%2==0);
       }
    }
    for(int i=1;i<n+1;i++){
        bfs2(i,adj_list,a,a[i]%2==0);
    }
    for(int i=1;i<n+1;i++){
        cout<<val[i]<<' ';
    }
    cout<<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<bool> visited(300000);
vector<bool> found(300000);
long long int val[300000];
void initialize(int n){
    for(int i=0;i<n;i++){
        visited[i]=false;
    }
}
void bfs(int i,vector<vector<int>> &adj_list,int a[],bool even){
    found[i]=true;
    visited[i]=true;
    for(int j=0;j<adj_list[i].size();j++){
        if(a[adj_list[i][j]]%2==0!=even){
            val[i]=1;
            return;
        }
    }
    long long int ans=INT_MAX;
    for(int j=0;j<adj_list[i].size();j++){
            if(found[adj_list[i][j]]){
                if(val[adj_list[i][j]]!=-1){
                    ans=min(ans,1+val[adj_list[i][j]]);
                }
            } else {
                bfs(adj_list[i][j],adj_list,a,even);
                if(val[adj_list[i][j]]!=-1){
                    ans=min(ans,1+val[adj_list[i][j]]);
                }
    }}
    if(ans!=INT_MAX){
        val[i]=ans;
    } else {
        val[i]=-1;
        found[i]=false;
    }
    visited[i]=false;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n+1;i++){
        found[i]=false;
        val[i]=-1;
    }
    int a[n+1];
    a[0]=0;
    for(int y=1;y<n+1;y++){
       cin>>a[y];
    }
    vector<vector<int>> adj_list(n+1);
    for(int i=1;i<n+1;i++){
        if(i-a[i]>=1){
            adj_list[i].push_back(i-a[i]);
        }
        if(i+a[i]<=n){
            adj_list[i].push_back(i+a[i]);
        }
    }
    for(int i=1;i<n+1;i++){
        if(!found[i]){
            bfs(i,adj_list,a,a[i]%2==0);
        }
    }
    for(int i=1;i<n+1;i++){
       if(!found[i]){
        bfs(i,adj_list,a,a[i]%2==0);
       }
    }
    for(int i=1;i<n+1;i++){
        bfs(i,adj_list,a,a[i]%2==0);
    }
    for(int i=1;i<n+1;i++){
        cout<<val[i]<<' ';
    }
    cout<<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    long long int dp[n];
    for(int i=0;i<n;i++){
        dp[i]=-1;
    }
    for(int i=0;i<n;i++){
        if(a[i]+i<n&&(a[a[i]+i]+a[i])%2==1){
            dp[i]=1;
        } else if(i-a[i]>=0&&(a[i-a[i]]+a[i])%2==1){
            dp[i]=1;
        }
    }
   /* for(int i=0;i<n;i++){
        cout<<dp[i]<<' ';
    }
    cout<<'\n';*/
    while(true){
            bool updated=false;
    for(int i=0;i<n;i++){
        if(dp[i]==-1&&(a[i]+i<n||i-a[i]>=0)){
               long long  int mini=INT_MAX;
            if(a[i]+i<n&&dp[a[i]+i]!=-1){
                mini=min(mini,dp[a[i]+i]+1);
            }
            if(i-a[i]>=0&&dp[i-a[i]]!=-1){
                mini=min(mini,dp[i-a[i]]+1);
            }
            if(mini!=INT_MAX){
                    dp[i]=mini;
                    updated=true;
            }
        }
    }
    if(!updated){
        break;
    }
    }
    for(int i=0;i<n;i++){
        cout<<dp[i]<<' ';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int dp[n];
    for(int i=0;i<n;i++){
        dp[i]=-1;
    }
    for(int i=0;i<n;i++){
        if(a[i]+i<n&&(a[a[i]+i]+a[i])%2==1){
            dp[i]=1;
        } else if(i-a[i]>=0&&(a[i-a[i]]+a[i])%2==1){
            dp[i]=1;
        }
    }
   /* for(int i=0;i<n;i++){
        cout<<dp[i]<<' ';
    }
    cout<<'\n';*/
    while(true){
            bool updated=false;
    for(int i=0;i<n;i++){
        if(dp[i]==-1){
                int mini=INT_MAX;
            if(a[i]+i<n&&dp[a[i]+i]!=-1){
                mini=min(mini,dp[a[i]+i]+1);
            }
            if(i-a[i]>=0&&dp[i-a[i]]!=-1){
                mini=min(mini,dp[i-a[i]]+1);
            }
            if(mini!=INT_MAX){
                    dp[i]=mini;
                updated=true;
            }
        }
    }
    if(!updated){
        break;
    }
    }
    for(int i=0;i<n;i++){
        cout<<dp[i]<<' ';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int val[n+1];
    for(int i=0;i<n+1;i++){
        val[i]=-1;
    }
    int a[n+1];
    a[0]=0;
    int b[n+1];
    for(int y=1;y<n+1;y++){
       cin>>a[y];
       b[y]=a[y]%2;
    }
    vector<vector<int>> adj_list(n+1);
    for(int i=1;i<n+1;i++){
        if(i-a[i]>=1){
            adj_list[i].push_back(i-a[i]);
        }
        if(i+a[i]<=n){
            adj_list[i].push_back(i+a[i]);
        }
    }
    vector<vector<int>> rev_list(n+1);
    for(int i=1;i<n+1;i++){
        for(int j=0;j<adj_list[i].size();j++){
            rev_list[adj_list[i][j]].push_back(i);
        }
    }
    bool visited[n+1];
    queue<int> bfs;
    for(int i=1;i<n+1;i++){
        if(b[i]==0){
            bfs.push(i);
            visited[i]=true;
        } else {visited[i]=false;}
    }
    int level=1;
    while(!bfs.empty()){
         int sze=bfs.size();
        while(sze>0){
        int v = bfs.front();
        bfs.pop();
        sze--;
        for(int i=0;i<rev_list[v].size();i++){
            if(!visited[rev_list[v][i]]){
                bfs.push(rev_list[v][i]);
                visited[rev_list[v][i]]=true;
                val[rev_list[v][i]]=level;
            }
        }
        }
        level++;
    }
    for(int i=1;i<n+1;i++){
        visited[i]=false;
    }
    queue<int> bfs1;
    for(int i=1;i<n+1;i++){
        if(b[i]==1){
            bfs1.push(i);
            visited[i]=true;
        }
    }
    level=1;
    while(!bfs1.empty()){
         int sze=bfs1.size();
        while(sze>0){
        int v = bfs1.front();
        bfs1.pop();
        sze--;
        for(int i=0;i<rev_list[v].size();i++){
            if(!visited[rev_list[v][i]]){
                bfs1.push(rev_list[v][i]);
                visited[rev_list[v][i]]=true;
                val[rev_list[v][i]]=level;
            }
        }
        }
        level++;
    }
    for(int i=1;i<n+1;i++){
        cout<<val[i]<<' ';
    }
    cout<<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<bool> visited(300000);
vector<bool> found(300000);
long long int val[300000];
void initialize(int n){
    for(int i=0;i<n;i++){
        visited[i]=false;
    }
}
void bfs(int i,vector<vector<int>> &adj_list,int a[],bool even){
    found[i]=true;
    visited[i]=true;
    for(int j=0;j<adj_list[i].size();j++){
        if(a[adj_list[i][j]]%2==0!=even){
            val[i]=1;
            return;
        }
    }
    long long int ans=INT_MAX;
    for(int j=0;j<adj_list[i].size();j++){
            if(found[adj_list[i][j]]){
                if(val[adj_list[i][j]]!=-1){
                    ans=min(ans,1+val[adj_list[i][j]]);
                }
            } else {
                bfs(adj_list[i][j],adj_list,a,even);
                if(val[adj_list[i][j]]!=-1){
                    ans=min(ans,1+val[adj_list[i][j]]);
                }
    }}
    if(ans!=INT_MAX){
        val[i]=ans;
    } else {
        val[i]=-1;
        found[i]=false;
    }
    visited[i]=false;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n+1;i++){
        found[i]=false;
        val[i]=-1;
    }
    int a[n+1];
    a[0]=0;
    for(int y=1;y<n+1;y++){
       cin>>a[y];
    }
    vector<vector<int>> adj_list(n+1);
    for(int i=1;i<n+1;i++){
        if(i-a[i]>=1){
            adj_list[i].push_back(i-a[i]);
        }
        if(i+a[i]<=n){
            adj_list[i].push_back(i+a[i]);
        }
    }
    for(int i=1;i<n+1;i++){
        if(!found[i]){
            bfs(i,adj_list,a,a[i]%2==0);
        }
    }
    for(int i=1;i<n+1;i++){
       if(!found[i]){
        bfs(i,adj_list,a,a[i]%2==0);
       }
    }
    for(int i=1;i<n+1;i++){
        cout<<val[i]<<' ';
    }
    cout<<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int val[n+1];
    for(int i=0;i<n+1;i++){
        val[i]=-1;
    }
    int a[n+1];
    a[0]=0;
    int b[n+1];
    for(int y=1;y<n+1;y++){
       cin>>a[y];
       b[y]=a[y]%2;
    }
    vector<vector<int>> adj_list(n+1);
    for(int i=1;i<n+1;i++){
        if(i-a[i]>=1){
            adj_list[i].push_back(i-a[i]);
        }
        if(i+a[i]<=n){
            adj_list[i].push_back(i+a[i]);
        }
    }
    vector<vector<int>> rev_list(n+1);
    for(int i=1;i<n+1;i++){
        for(int j=0;j<adj_list[i].size();j++){
            rev_list[adj_list[i][j]].push_back(i);
        }
    }
    bool visited[n+1];
    queue<int> bfs;
    for(int i=1;i<n+1;i++){
        if(b[i]==0){
            bfs.push(i);
            visited[i]=true;
        }
    }
    int level=1;
    while(!bfs.empty()){
         int sze=bfs.size();
        while(sze>0){
        int v = bfs.front();
        bfs.pop();
        sze--;
        for(int i=0;i<rev_list[v].size();i++){
            if(!visited[rev_list[v][i]]){
                bfs.push(rev_list[v][i]);
                val[rev_list[v][i]]=level;
            }
        }
        }
        level++;
    }
    for(int i=1;i<n+1;i++){
        visited[i]=false;
    }
    queue<int> bfs1;
    for(int i=1;i<n+1;i++){
        if(b[i]==1){
            bfs1.push(i);
            visited[i]=true;
        }
    }
    level=1;
    while(!bfs1.empty()){
         int sze=bfs1.size();
        while(sze>0){
        int v = bfs1.front();
        bfs1.pop();
        sze--;
        for(int i=0;i<rev_list[v].size();i++){
            if(!visited[rev_list[v][i]]){
                bfs1.push(rev_list[v][i]);
                val[rev_list[v][i]]=level;
            }
        }
        }
        level++;
    }
    for(int i=1;i<n+1;i++){
        cout<<val[i]<<' ';
    }
    cout<<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<bool> visited(300000);
vector<bool> found(300000);
long long int val[300000];
void initialize(int n){
    for(int i=0;i<n;i++){
        visited[i]=false;
    }
}
void bfs(int i,vector<vector<int>> &adj_list,int a[],bool even){
    found[i]=true;
    visited[i]=true;
    for(int j=0;j<adj_list[i].size();j++){
        if(a[adj_list[i][j]]%2==0!=even){
            val[i]=1;
            return;
        }
    }
    long long int ans=INT_MAX;
    for(int j=0;j<adj_list[i].size();j++){
            if(found[adj_list[i][j]]){
                if(val[adj_list[i][j]]!=-1){
                    ans=min(ans,1+val[adj_list[i][j]]);
                }
            } else {
                bfs(adj_list[i][j],adj_list,a,even);
                if(val[adj_list[i][j]]!=-1){
                    ans=min(ans,1+val[adj_list[i][j]]);
                }
    }}
    if(ans!=INT_MAX){
        val[i]=ans;
    } else {
        val[i]=-1;
        found[i]=false;
    }
    visited[i]=false;
}

void bfs2(int i,vector<vector<int>> &adj_list,int a[],bool even){
    visited[i]=true;
    for(int j=0;j<adj_list[i].size();j++){
        if(a[adj_list[i][j]]%2==0!=even){
            val[i]=1;
            return;
        }
    }
    long long int ans=INT_MAX;
    for(int j=0;j<adj_list[i].size();j++){
            if(found[adj_list[i][j]]){
                if(val[adj_list[i][j]]!=-1){
                    ans=min(ans,1+val[adj_list[i][j]]);
                }
            }
    }
    if(ans!=INT_MAX){
        val[i]=ans;
    } else {
        val[i]=-1;
        found[i]=false;
    }
    visited[i]=false;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n+1;i++){
        found[i]=false;
        val[i]=-1;
    }
    int a[n+1];
    a[0]=0;
    for(int y=1;y<n+1;y++){
       cin>>a[y];
    }
    vector<vector<int>> adj_list(n+1);
    for(int i=1;i<n+1;i++){
        if(i-a[i]>=1){
            adj_list[i].push_back(i-a[i]);
        }
        if(i+a[i]<=n){
            adj_list[i].push_back(i+a[i]);
        }
    }
    for(int i=1;i<n+1;i++){
            bfs(i,adj_list,a,a[i]%2==0);
    }
    for(int i=1;i<n+1;i++){
        bfs(i,adj_list,a,a[i]%2==0);
    }
    for(int i=1;i<n+1;i++){
        cout<<val[i]<<' ';
    }
    cout<<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
bool visited[100002];
long long int num[100002];
vector<vector<int>> adj_list(100002);
void dfs(int i){
     long long int mini = INT_MAX;
     visited[i]=true;
    for(int j=0;j<adj_list[i].size();j++){
        if(visited[adj_list[i][j]]&&num[adj_list[i][j]]!=-1){
            mini = min(mini,1+num[adj_list[i][j]]);
        } else if(!visited[adj_list[i][j]]){
            dfs(adj_list[i][j]);
            if(num[adj_list[i][j]]!=-1){
                mini=min(mini,num[adj_list[i][j]]+1);
            }
        }
    }
    if(mini!=INT_MAX)
        num[i]=mini;
    else
        num[i]=-1;
}

int main()
{

    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
     for(int i=0;i<n;i++){
        visited[i]=false;
    }
    for(int i=0;i<n;i++){
        if(a[i]+i<n){
            adj_list[i].push_back(a[i]+i);
            if((a[a[i]+i]+a[i])%2==1){
                visited[i]=true;
                num[i]=1;
            }
        }
        if(i-a[i]>=0){
            adj_list[i].push_back(i-a[i]);
            if((a[i-a[i]]+a[i])%2==1){
                visited[i]=true;
                num[i]=1;
            }
        }
        if(adj_list[i].size()==0){
            visited[i]=true;
            num[i]=-1;
        }
    }
    for(int i=0;i<n;i++){
        if(!visited[i]){
            dfs(i);
        }
    }
    for(int i=0;i<n;i++){
        cout<<num[i]<<' ';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int val[n+1];
    for(int i=0;i<n+1;i++){
        val[i]=-1;
    }
    int a[n+1];
    a[0]=0;
    int b[n+1];
    for(int y=1;y<n+1;y++){
       cin>>a[y];
       b[y]=a[y]%2;
    }
    vector<vector<int>> adj_list(n+1);
    for(int i=1;i<n+1;i++){
        if(i-a[i]>=1){
            adj_list[i].push_back(i-a[i]);
        }
        if(i+a[i]<=n){
            adj_list[i].push_back(i+a[i]);
        }
    }
    vector<vector<int>> rev_list(n+1);
    for(int i=1;i<n+1;i++){
        for(int j=0;j<adj_list[i].size();j++){
            rev_list[adj_list[i][j]].push_back(i);
        }
    }
    bool visited[n+1];
    queue<int> bfs;
    for(int i=1;i<n+1;i++){
        if(b[i]==0){
            bfs.push(i);
            visited[i]=true;
        } else {visited[i]=false;}
    }
    int level=1;
    while(!bfs.empty()){
         int sze=bfs.size();
        while(sze>0){
        int v = bfs.front();
        bfs.pop();
        sze--;
        for(int i=0;i<rev_list[v].size();i++){
            if(!visited[rev_list[v][i]]){
                bfs.push(rev_list[v][i]);
                val[rev_list[v][i]]=level;
            }
        }
        }
        level++;
    }
    for(int i=1;i<n+1;i++){
        visited[i]=false;
    }
    queue<int> bfs1;
    for(int i=1;i<n+1;i++){
        if(b[i]==1){
            bfs1.push(i);
            visited[i]=true;
        }
    }
    level=1;
    while(!bfs1.empty()){
         int sze=bfs1.size();
        while(sze>0){
        int v = bfs1.front();
        bfs1.pop();
        sze--;
        for(int i=0;i<rev_list[v].size();i++){
            if(!visited[rev_list[v][i]]){
                bfs1.push(rev_list[v][i]);
                val[rev_list[v][i]]=level;
            }
        }
        }
        level++;
    }
    for(int i=1;i<n+1;i++){
        cout<<val[i]<<' ';
    }
    cout<<'\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<bool> visited(300000);
vector<bool> found(300000);
long long int val[300000];
void initialize(int n){
    for(int i=0;i<n;i++){
        visited[i]=false;
    }
}
void bfs(int i,vector<vector<int>> &adj_list,int a[],bool even){
    found[i]=true;
    visited[i]=true;
    for(int j=0;j<adj_list[i].size();j++){
        if(a[adj_list[i][j]]%2==0!=even){
            val[i]=1;
            return;
        }
    }
    long long int ans=INT_MAX;
    for(int j=0;j<adj_list[i].size();j++){
            if(found[adj_list[i][j]]){
                if(val[adj_list[i][j]]!=-1){
                    ans=min(ans,1+val[adj_list[i][j]]);
                }
            } else {
                bfs(adj_list[i][j],adj_list,a,even);
                if(val[adj_list[i][j]]!=-1){
                    ans=min(ans,1+val[adj_list[i][j]]);
                }
    }}
    if(ans!=INT_MAX){
        val[i]=ans;
    } else {
        val[i]=-1;
    }
    visited[i]=false;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n+1;i++){
        found[i]=false;
        val[i]=-1;
    }
    int a[n+1];
    a[0]=0;
    for(int y=1;y<n+1;y++){
       cin>>a[y];
    }
    vector<vector<int>> adj_list(n+1);
    for(int i=1;i<n+1;i++){
        if(i-a[i]>=1){
            adj_list[i].push_back(i-a[i]);
        }
        if(i+a[i]<=n){
            adj_list[i].push_back(i+a[i]);
        }
    }
    for(int i=1;i<n+1;i++){
        if(!found[i]){
            bfs(i,adj_list,a,a[i]%2==0);
        }
    }
    for(int i=1;i<n+1;i++){
        cout<<val[i]<<' ';
    }
    cout<<'\n';
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
int a[N];
int n;
int flag[N];
bool f(int a,int b){
    if((a%2)==(b%2))return 0;
    return 1;
}
void bfs(int i){
    queue<pair<int,int> >q;
    q.push(make_pair(i,0));
    flag[i]=i+1;
    while(!q.empty()){
        int x=q.front().first,y=q.front().second;
        q.pop();
        for(int j=-1;j<2;j+=2){
            int k=j*a[x]+x;
            if(k<n&&k>=0&&flag[k]!=i+1)
                if(f(a[x],a[k])){
                    cout<<y+1<<' ';return ;
                }
                else {
                    q.push(make_pair(k,y+1));
                    flag[k]=i+1;
                }
        }
    }
    cout<<-1<<' ';
    return ;
}
int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    int d[2]={0};
    for(int i=0;i<n;i++)cin>>a[i],d[a[i]%2]=1;
    if(!(d[0]&&d[1])){
        while(n--)cout<<-1<<' ';
        return 0;
    }
    for(int i=0;i<n;i++){
        bfs(i);
    }
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
int a[N];
int n;
bool f(int a,int b){
    if((a%2)==(b%2))return 0;
    return 1;
}
void bfs(int i){
    queue<pair<int,int> >q;
    q.push(make_pair(i,0));
    int flag[N]={0};
    flag[i]=1;
    while(!q.empty()){
        int x=q.front().first,y=q.front().second;
        q.pop();
        for(int j=-1;j<2;j+=2){
            int k=j*a[x]+x;
            if(k<n&&k>=0&&!flag[k])
                if(f(a[x],a[k])){
                    cout<<y+1<<' ';return ;
                }
                else {
                    q.push(make_pair(k,y+1));
                    flag[k]=1;
                }
        }
    }
    cout<<-1<<' ';
    return ;
}
int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
        bfs(i);
    }
}


#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 200005;

int n,a[MAX_N],dp[MAX_N][2];
vector<int> go[MAX_N];

int main()
{
	scanf("%d",&n);
	queue<pair<int,int>> q;
	for (int i=1; i<=n; i++)
	{
		scanf("%d",a+i);
		q.push({i,a[i]&1});
		dp[i][0] = dp[i][1] = -1;
		dp[i][a[i]&1] = 0;
		for (int g : {i-a[i], i+a[i]})
			if (g > 0 && g <= n)
				go[g].push_back(i);
	}
	while (!q.empty())
	{
		auto [i,p] = q.front();
		q.pop();
		for (int g : go[i])
			if (g > 0 && g <= n && dp[g][p] == -1)
			{
				dp[g][p] = 1+dp[i][p];
				q.push({g,p});
			}
	}
	for (int i=1; i<=n; i++)
		printf("%d ", dp[i][1-(a[i]&1)]);
	printf("\n");
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
int a[N],dp[N][2];
 vector<int>v[N];
int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
        dp[i][0]=dp[i][1]=-1;
        dp[i][a[i]&1]=0;
        for(int j=-1;j<2;j+=2){
            int now=a[i]*j+i;
            if(now>=0&&now<n)v[now].push_back(i);
        }
    }
    queue<pair<int,int> >q;
    for(int i=0;i<n;i++)q.push({i,a[i]&1});
    while(!q.empty()){
        int x=q.front().first;
        int y=q.front().second;
        q.pop();
        for(int i=0;i<v[x].size();i++){
            if(dp[v[x][i]][y]==-1)dp[v[x][i]][y]=dp[x][y]+1,q.push({v[x][i],y});
            //cout<<dp[x][y]<<' '<<dp[v[x][i]][y]<<endl;
        }
    }
    for(int i=0;i<n;i++)cout<<dp[i][1-a[i]&1]<<' ';

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
int a[N];
int n;
int flag[N];
bool f(int a,int b){
    if((a%2)==(b%2))return 0;
    return 1;
}
void bfs(int i){
    queue<pair<int,int> >q;
    q.push(make_pair(i,0));
    flag[i]=i;
    while(!q.empty()){
        int x=q.front().first,y=q.front().second;
        q.pop();
        for(int j=-1;j<2;j+=2){
            int k=j*a[x]+x;
            if(k<n&&k>=0&&flag[k]!=i)
                if(f(a[x],a[k])){
                    cout<<y+1<<' ';return ;
                }
                else {
                    q.push(make_pair(k,y+1));
                    flag[k]=i;
                }
        }
    }
    cout<<-1<<' ';
    return ;
}
int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
        bfs(i);
    }
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
int a[N];
int n;
int flag[N];
bool f(int a,int b){
    if((a%2)==(b%2))return 0;
    return 1;
}
void bfs(int i){
    queue<pair<int,int> >q;
    q.push(make_pair(i,0));
    flag[i]=i+1;
    while(!q.empty()){
        int x=q.front().first,y=q.front().second;
        q.pop();
        for(int j=-1;j<2;j+=2){
            int k=j*a[x]+x;
            if(k<n&&k>=0&&flag[k]!=i+1)
                if(f(a[x],a[k])){
                    cout<<y+1<<' ';return ;
                }
                else {
                    q.push(make_pair(k,y+1));
                    flag[k]=i+1;
                }
        }
    }
    cout<<-1<<' ';
    return ;
}
int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    int d[2]={0};
    for(int i=0;i<n;i++)cin>>a[i],d[a[i]%2]=1;
    if(!(a[0]&&a[1])){
        while(n--)cout<<-1<<' ';
        return 0;
    }
    for(int i=0;i<n;i++){
        bfs(i);
    }
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
int a[N];
int n;
int flag[N];
bool f(int a,int b){
    if((a%2)==(b%2))return 0;
    return 1;
}
void bfs(int i){
    queue<pair<int,int> >q;
    q.push(make_pair(i,0));
    flag[i]=i+1;
    while(!q.empty()){
        int x=q.front().first,y=q.front().second;
        q.pop();
        for(int j=-1;j<2;j+=2){
            int k=j*a[x]+x;
            if(k<n&&k>=0&&flag[k]!=i+1)
                if(f(a[x],a[k])){
                    cout<<y+1<<' ';return ;
                }
                else {
                    q.push(make_pair(k,y+1));
                    flag[k]=i+1;
                }
        }
    }
    cout<<-1<<' ';
    return ;
}
int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
        bfs(i);
    }
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
int a[N];
int n;
bool f(int a,int b){
    if((a%2)==(b%2))return 0;
    return 1;
}
void bfs(int i){
    queue<pair<int,int> >q;
    q.push(make_pair(i,0));
    while(!q.empty()){
        int x=q.front().first,y=q.front().second;
        q.pop();
        for(int j=-1;j<2;j+=2){
            int k=j*a[x]+x;
            if(k<n&&k>=0)
                if(f(a[x],a[k])){
                    cout<<y+1<<' ';return ;
                }
                else {
                    q.push(make_pair(k,y+1));
                }
        }
    }
    cout<<-1<<' ';
    return ;
}
int main()
{
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
        bfs(i);
    }
}