#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};
    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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
using namespace std::chrono;
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_mset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>
#define fr(i,a,b) for (int i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define sz(a) (int)a.size()
#define endl "\n"

#define print(a) for(auto x:a)cout<<x<<" ";cout<<endl;
#define print2(a) for(auto x:a){for(auto y:x)cout<<y<<" ";cout<<endl;};

const ll M=1e9+9;
const int P=31;
const int MaxM=200004;
int a[MaxM];int n;int ans[MaxM];set<int> s;
int fun(int i)
{   if(i<0 || i>n-1)return M;
	 s.insert(i);
    int k2=M;

    	 if(i+a[i]<n && a[i+a[i]]%2!=a[i]%2)return 1;
        if(i-a[i]>=0 && a[i-a[i]]%2!=a[i]%2)return 1;

        if(!s.count(i+a[i]))k2=min(k2,1+fun(i+a[i]));
        if(!s.count(i-a[i]))k2=min(k2,1+fun(i-a[i]));
             return k2;

}

int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

      #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
  cin>> n;
  fr(i,0,n)cin>>a[i];

  fr(i,0,n)
  {
  	  s.clear();int t=fun(i);
  		if(t>1e9)cout<<-1<<" ";
  		else cout<<t<<" ";

  }

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
using namespace std::chrono;
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_mset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>
#define fr(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define sz(a) (ll)a.size()
//#define endl "\n"
#define double long double
#define print(a) for(auto x:a)cout<<x<<" ";cout<<endl;
#define print2(a) for(auto x:a){for(auto y:x)cout<<y<<" ";cout<<endl;};

const ll M=1e9+7;
const int P=31;
const int MaxM=200005;

int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

      #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int n;cin>>n;
    int a[n];
    fr(i,0,n)cin>>a[i];

    int ans[n];
    fr(i,0,n)ans[i]=M;
    queue<int> q;int vis[n]={};
    vi adj[n];
    fr(i,0,n)
    {
        if(i-a[i]>=0)
          {adj[i-a[i]].pb(i);if(a[i-a[i]]%2!=a[i]%2){ans[i]=1;}}
        if(i+a[i]<n)
          {adj[i+a[i]].pb(i);if(a[i+a[i]]%2!=a[i]%2){ans[i]=1;}}
    }

     fr(i,0,n)if(ans[i]==1){q.push(i);vis[i]=1;}

    while(!q.empty()){
          int cur=q.front();q.pop();

          for(auto x:adj[cur])
          {
            if(vis[x])continue;
             ans[x]=min(ans[cur]+1,ans[x]);
             q.push(x);  vis[cur]=1;
          }
    }

      fr(i,0,n)cout<<(ans[i]==M?-1:ans[i])<<" ";

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
using namespace std::chrono;
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_mset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>
#define fr(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define sz(a) (ll)a.size()
#define endl "\n"

#define print(a) for(auto x:a)cout<<x<<" ";cout<<endl;
#define print2(a) for(auto x:a){for(auto y:x)cout<<y<<" ";cout<<endl;};
void read(int &number){bool negative=false;register int c;number=0; c=getchar();if (c=='-'){negative=true;c=getchar();}for(;(c>47&&c<58);c=getchar())number=number*10+c-48;if(negative)number*= -1;}
const ll M=1e9+9;
const int P=29;
const int MaxM=100005;

void clear(queue<pii> &q )
{
   queue<pii> empty;
   swap(q,empty);
}

int main()
{ios_base::sync_with_stdio(false);
 cin.tie(NULL);cout.tie(NULL);

      #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

  int n;
  cin>>n;
  int a[n];
  fr(i,0,n)cin>>a[i];

    queue<pii> q;
    set<int> s;
    int ans[n];
    fr(i,0,n)ans[i]=-1;

        int done[n]={};
    fr(i,0,n)
    {     if(done[i])continue;
    	  s.clear();
    	 q.push({i,0});int c=a[i]%2;
    	 s.insert(i);

    	 while(!q.empty())
    	 {
    	 	pii cur=q.front();//cout<<j<<" "<<cur.F<<" "<<cur.S<<endl;
    	 	q.pop();int j=cur.F;
    	 	  if(a[cur.F]%2!=c){ans[i]=cur.S;clear(q);break;}
             if(j-a[cur.F]>=0 && !s.count(j-a[cur.F])){q.push({j-a[cur.F],cur.S+1});s.insert(j-a[cur.F]);}
             if(j+a[cur.F]<n && !s.count(j+a[cur.F])){q.push({j+a[cur.F],cur.S+1});s.insert(j+a[cur.F]);}
    	 }
    	 if(ans[i]==-1)
    	 {
    	 	for(auto x:s)done[x]=1;
    	 }
    }

    fr(i,0,n)cout<<ans[i]<<" ";

   }


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
using namespace std::chrono;
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_mset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>
#define fr(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define sz(a) (ll)a.size()
//#define endl "\n"
#define double long double
#define print(a) for(auto x:a)cout<<x<<" ";cout<<endl;
#define print2(a) for(auto x:a){for(auto y:x)cout<<y<<" ";cout<<endl;};

const ll M=1e9+7;
const int P=31;
const int MaxM=200005;

int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

      #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int n;cin>>n;
    int a[n];
    fr(i,0,n)cin>>a[i];

    int ans[n];
    fr(i,0,n)ans[i]=M;
    queue<int> q;int vis[n]={};
    vi adj[n];
    fr(i,0,n)
    {
        if(i-a[i]>=0)
          {adj[i-a[i]].pb(i);if(a[i-a[i]]%2!=a[i]%2){ans[i]=1;}}
        if(i+a[i]<n)
          {adj[i+a[i]].pb(i);if(a[i+a[i]]%2!=a[i]%2){ans[i]=1;}}
    }

     fr(i,0,n)if(ans[i]==1){q.push(i);vis[i]=1;}

    while(!q.empty()){
          int cur=q.front();q.pop();

          for(auto x:adj[cur])
          {
            if(vis[x])continue;
             ans[x]=min(ans[cur]+1,ans[x]);
             q.push(x);  vis[x]=1;
          }
    }

      fr(i,0,n)cout<<(ans[i]==M?-1:ans[i])<<" ";

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
using namespace std::chrono;
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_mset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>
#define fr(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define sz(a) (ll)a.size()
#define endl "\n"

#define print(a) for(auto x:a)cout<<x<<" ";cout<<endl;
#define print2(a) for(auto x:a){for(auto y:x)cout<<y<<" ";cout<<endl;};
void read(int &number){bool negative=false;register int c;number=0; c=getchar();if (c=='-'){negative=true;c=getchar();}for(;(c>47&&c<58);c=getchar())number=number*10+c-48;if(negative)number*= -1;}
const ll M=1e9+9;
const int P=29;
const int MaxM=100005;

void clear(queue<pii> &q )
{
   queue<pii> empty;
   swap(q,empty);
}

int main()
{ios_base::sync_with_stdio(false);
 cin.tie(NULL);cout.tie(NULL);

      #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

  int n;
  cin>>n;
  int a[n];
  fr(i,0,n)cin>>a[i];

    queue<pii> q;
    set<int> s;
    int ans[n];
    fr(i,0,n)ans[i]=-1;

    fr(i,0,n)
    {    s.clear();
    	 q.push({i,0});int c=a[i]%2;
    	 s.insert(i);

    	 while(!q.empty())
    	 {
    	 	pii cur=q.front();//cout<<j<<" "<<cur.F<<" "<<cur.S<<endl;
    	 	q.pop();int j=cur.F;
    	 	  if(a[cur.F]%2!=c){ans[i]=cur.S;clear(q);break;}
             if(j-a[cur.F]>=0 && !s.count(j-a[cur.F])){q.push({j-a[cur.F],cur.S+1});s.insert(j-a[cur.F]);}
             if(j+a[cur.F]<n && !s.count(j+a[cur.F])){q.push({j+a[cur.F],cur.S+1});s.insert(j+a[cur.F]);}
    	 }
    }

    fr(i,0,n)cout<<ans[i]<<" ";

   }


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,a,b) for (int i=(a); i<(b);i++)
#define frr(i,a,b) for(int i=(a-1);i>=(b);i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp map<ll,ll>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define ln(a) a.length()
#define sz(a) a.size()
ll M=1e9+7;

map<int, vector<pair<int,int> > >m;int n;
int solve(int i)
{
    if(!m.count(i))return -M;
    int k;
    if(sz(m[i])==1)
    {
      if(m[i][0].second==1)return 1;
      else return 1+solve(m[i][0].first);
    }
    else
    {  int k,t;
      if(m[i][0].second==1 || m[i][1].second==1)return 1;
      else
       {k=solve(m[i][0].first);t=solve(m[i][1].first);
           if(k>0 && t>0)return min(k,t);
           else if(k>0 && t<0)return k;
             else if(k<0 && t>0)return t;
            else return -M;}
    }

}

int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

      #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

cin>>n;
int a[n];
fr(i,0,n)cin>>a[i];

fr(i,0,n)
{
   if(i+a[i]<n)
   {
    if(a[i+a[i]]%2!=a[i]%2)m[i].pb({i+a[i],1});else m[i].pb({i+a[i],0});
   }
   if(i-a[i]>=0)
   {
    if(a[i-a[i]]%2!=a[i]%2)m[i].pb({i-a[i],1});else m[i].pb({i-a[i],0});
   }
}
fr(i,0,n)
{
  if(solve(i)<0)cout<<-1<<" ";
  else cout<<solve(i)<<" ";
}

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,a,b) for (int i=(a); i<(b);i++)
#define frr(i,a,b) for(int i=(a-1);i>=(b);i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp map<ll,ll>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define ln(a) a.length()
#define sz(a) a.size()
int M=-100000;

map<int, vector<pair<int,int> > >m;int n;set<int> s;
int solve(int i)
{
  if(s.count(i))return M;

    s.insert(i);
    if(!m.count(i))return M;

    if(sz(m[i])==1)
    {
      if(m[i][0].second==1)return 1;
      else return 1+solve(m[i][0].first);
    }

      int k,t;
      if(m[i][0].second==1 || m[i][1].second==1)return 1;
      else
       {k=1+solve(m[i][0].first);t=1+solve(m[i][1].first);
           if(k>0 && t>0)return min(k,t);
           else if(k>0 && t<0)return k;
             else if(k<0 && t>0)return t;
            else return M;}

}

int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

      #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

cin>>n;
int a[n];
fr(i,0,n)cin>>a[i];

fr(i,0,n)
{
   if(i+a[i]<n)
   {
    if(a[i+a[i]]%2!=a[i]%2)m[i].pb({i+a[i],1});else m[i].pb({i+a[i],0});
   }
   if(i-a[i]>=0)
   {
    if(a[i-a[i]]%2!=a[i]%2)m[i].pb({i-a[i],1});else m[i].pb({i-a[i],0});
   }
}

fr(i,0,n)
{  s.clear();
 cout<<max(-1,solve(i))<<" ";
}

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,a,b) for (int i=(a); i<(b);i++)
#define frr(i,a,b) for(int i=(a-1);i>=(b);i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp map<ll,ll>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define ln(a) a.length()
#define sz(a) a.size()
int M=-100000;

map<int, vector<pair<int,int> > >m;int n;set<int> s;
int solve(int i)
{
  if(s.count(i))return M;

    s.insert(i);
    if(!m.count(i))return M;

    if(sz(m[i])==1)
    {
      if(m[i][0].second==1)return 1;
      else return 1+solve(m[i][0].first);
    }

      int k,t;
      if(m[i][0].second==1 || m[i][1].second==1)return 1;
      else
       {k=1+solve(m[i][1].first);t=1+solve(m[i][0].first);
           if(k>0 && t>0)return min(t,k);
           if(k>0 && t<0)return k;
          if(k<0 && t>0)return t;
            return M;}

}

int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

      #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

cin>>n;
int a[n];
fr(i,0,n)cin>>a[i];

fr(i,0,n)
{
   if(i+a[i]<n)
   {
    if(a[i+a[i]]%2!=a[i]%2)m[i].pb({i+a[i],1});else m[i].pb({i+a[i],0});
   }
   if(i-a[i]>=0)
   {
    if(a[i-a[i]]%2!=a[i]%2)m[i].pb({i-a[i],1});else m[i].pb({i-a[i],0});
   }
}

//cout<<solve(88)<<endl;
fr(i,0,n)
{  s.clear();
 cout<<max(-1,solve(i))<<" ";
}

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,a,b) for (int i=(a); i<(b);i++)
#define frr(i,a,b) for(int i=(a-1);i>=(b);i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp map<ll,ll>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define ln(a) a.length()
#define sz(a) a.size()
int M=-100000;

map<int, vector<pair<int,int> > >m;int n;set<int> s;
int solve(int i)
{
  if(s.count(i))return -2;

    s.insert(i);
    if(!m.count(i))return M;

    if(sz(m[i])==1)
    {
      if(m[i][0].second==1)return 1;
      else return 1+solve(m[i][0].first);
    }

      int k,t;
      if(m[i][0].second==1 || m[i][1].second==1)return 1;
      else
       {k=1+solve(m[i][0].first);t=1+solve(m[i][1].first);
           if(k>0 && t>0)return min(k,t);
           else if(k>0 && t<0)return k;
             else if(k<0 && t>0)return t;
            else return M;}

}

int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

      #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

cin>>n;
int a[n];
fr(i,0,n)cin>>a[i];

fr(i,0,n)
{
   if(i+a[i]<n)
   {
    if(a[i+a[i]]%2!=a[i]%2)m[i].pb({i+a[i],1});else m[i].pb({i+a[i],0});
   }
   if(i-a[i]>=0)
   {
    if(a[i-a[i]]%2!=a[i]%2)m[i].pb({i-a[i],1});else m[i].pb({i-a[i],0});
   }
}

fr(i,0,n)
{  s.clear();
 cout<<max(-1,solve(i))<<" ";
}

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
using namespace std::chrono;
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_mset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>
#define fr(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define sz(a) (ll)a.size()
//#define endl "\n"
#define double long double
#define print(a) for(auto x:a)cout<<x<<" ";cout<<endl;
#define print2(a) for(auto x:a){for(auto y:x)cout<<y<<" ";cout<<endl;};

const ll M=1e9+7;
const int P=31;
const int MaxM=200005;

int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

      #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int n;cin>>n;
    int a[n];
    fr(i,0,n)cin>>a[i];

    int ans[n];
    fr(i,0,n)ans[i]=M;
    queue<int> q;int vis[n]={};
    vi adj[n];
    fr(i,0,n)
    {
        if(i-a[i]>=0)
          {adj[i-a[i]].pb(i);if(a[i-a[i]]%2!=a[i]%2){ans[i]=1;}}
        if(i+a[i]<n)
          {adj[i+a[i]].pb(i);if(a[i+a[i]]%2!=a[i]%2){ans[i]=1;}}
    }

     fr(i,0,n)if(ans[i]==1){q.push(i);vis[i]=1;}

    while(!q.empty()){
          int cur=q.front();q.pop();
          vis[cur]=1;
          for(auto x:adj[cur])
          {
            if(vis[x])continue;
             ans[x]=min(ans[cur]+1,ans[x]);
             q.push(x);
          }
    }

      fr(i,0,n)cout<<(ans[i]==M?-1:ans[i])<<" ";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,a,b) for (int i=(a); i<(b);i++)
#define frr(i,a,b) for(int i=(a-1);i>=(b);i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp map<ll,ll>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define ln(a) a.length()
#define sz(a) a.size()
int M=-100000;

map<int, vector<pair<int,int> > >m;int n;set<int> s;
int solve(int i)
{
  if(s.count(i))return M;

    s.insert(i);
    if(!m.count(i))return M;

    if(sz(m[i])==1)
    {
      if(m[i][0].second==1)return 1;
      else return 1+solve(m[i][0].first);
    }

      int k,t;
      if(m[i][0].second==1 || m[i][1].second==1)return 1;
      else
       {
        t=solve(m[i][0].first)+1;s.clear();s.insert(i);k=solve(m[i][1].first)+1;
           if(k>0 && t>0)return min(t,k);
           if(k>0 && t<0)return k;
          if(k<0 && t>0)return t;
            return M;}

}

int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

      #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

cin>>n;
int a[n];
fr(i,0,n)cin>>a[i];

fr(i,0,n)
{
   if(i+a[i]<n)
   {
    if(a[i+a[i]]%2!=a[i]%2)m[i].pb({i+a[i],1});else m[i].pb({i+a[i],0});
   }
   if(i-a[i]>=0)
   {
    if(a[i-a[i]]%2!=a[i]%2)m[i].pb({i-a[i],1});else m[i].pb({i-a[i],0});
   }
}

//cout<<solve(88)<<endl;
fr(i,0,n)
{  s.clear();
 cout<<max(-1,solve(i))<<" ";
}

}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int>
#define pb push_back
#define pa pair<long long int ,long long int>
#define f(a,x,b) for(int a=x;a<b;a++)
#define sort(x) sort(x.begin(),x.end());
#define siz(a) (int)a.size()
#define mod 1000000007
#define F first
#define S second
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
vi ans(200001);
ll n;
vi v(200001);
void solve()
{
  cin>>n;
  set<ll>s;
  f(i,0,n)
  {
	  s.insert(i);
	  cin>>v[i];
  }
  f(i,0,n)
  {
	  ll ge=i-v[i];
	  ll gee=i+v[i];
	  if(ge>=0&&v[i]%2!=v[ge]%2)
	  {
		  ans[i]=1;
		  s.erase(s.find(i));
	  }
	  else if(gee<=n-1&&v[i]%2!=v[gee]%2)
	  {
		  s.erase(s.find(i));
		  ans[i]=1;
	  }
  }
  while(!s.empty())
  {
	  ll note=s.size();
	  vi re;
	  um uo;
	  for(ll d:s)
	  {
		  ll ge=d-v[d];
		  ll gee=d+v[d];
		  uo[d]=1;
		  ll x=mod,y=mod;
		  if(ge>=0&&ans[ge]!=0&&!uo[ge]&&v[ge]%2==v[d]%2)
		  {
			 x=ans[ge]+1;
		  }
		  if(gee<=n-1&&ans[gee]!=0&&!uo[gee]&&v[gee]%2==v[d]%2)
		  {
			  y=ans[gee]+1;
		  }
		  if(x==mod&&y==mod)
		   continue;
		  ans[d]=min(x,y);
		  re.pb(d);
	  }
	  if(!re.size())
	   break;
	  for(ll d:re)
	  {
		  s.erase(s.find(d));
	  }
  }
  f(i,0,n)
  {
	  if(ans[i]==0)
	   cout<<-1<<" ";
	 else
	 {
		 cout<<ans[i]<<" ";
	 }

  }
}
int main() {
	fast;
	fast_input;
	fast_output;
	// ll t;
	// cin>>t;
	// f(i,0,t)
	// {
    //   cout<<"Case #"<<i+1<<":"<<" ";
	     solve();
	// }
	return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int>
#define pb push_back
#define pa pair<long long int ,long long int>
#define f(a,x,b) for(int a=x;a<b;a++)
#define sort(x) sort(x.begin(),x.end());
#define siz(a) (int)a.size()
#define mod 1000000007
#define F first
#define S second
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
void solve()
{
  ll n;
  cin>>n;
  vi ans(n),v(n);
  f(i,0,n)
  {
	//   s.insert(i);
	  cin>>v[i];
  }
  vi g[n];
  queue<ll>q;
  f(i,0,n)
  {
	  ll ge=i-v[i];
	  ll gee=i+v[i];
	  if(ge>=0)
	  {
		  g[ge].pb(i);
		  if(v[i]%2!=v[ge]%2)
		  ans[i]=1;
	  }
	  if(gee<=n-1)
	  {
		  g[gee].pb(i);
		  if(v[i]%2!=v[gee]%2)
		  ans[i]=1;
	  }
	  if(ans[i]==1)
	   q.push(i);
  }
  while(!q.empty())
  {
	  ll ge=q.front();
	  q.pop();
	  for(ll d:g[ge])
	  {
		  if(ans[d]==0&&v[d]%2==v[ge]%2)
		  {
             ans[d]=ans[ge]+1;
			 q.push(d);
		  }
	  }
  }
  f(i,0,n)
  {
	  if(!ans[i])
	  {
		  cout<<-1<<" ";
	  }
	  else
	  {
		  cout<<ans[i]<<" ";
	  }

  }
}
int main() {
	fast;
	fast_input;
	fast_output;
	// ll t;
	// cin>>t;
	// f(i,0,t)
	// {
    //   cout<<"Case #"<<i+1<<":"<<" ";
	     solve();
	// }
	return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int>
#define pb push_back
#define pa pair<long long int ,long long int>
#define f(a,x,b) for(int a=x;a<b;a++)
#define sort(x) sort(x.begin(),x.end());
#define siz(a) (int)a.size()
#define mod 1000000007
#define F first
#define S second
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
vi ans(200001);
ll n;
vi v(200001);
void solve()
{
  cin>>n;
  set<ll>s;
  f(i,0,n)
  {
	  s.insert(i);
	  cin>>v[i];
  }
  f(i,0,n)
  {
	  ll ge=i-v[i];
	  ll gee=i+v[i];
	  if(ge>=0&&v[i]%2!=v[ge]%2)
	  {
		  ans[i]=1;
		  s.erase(s.find(i));
	  }
	  else if(gee<=n-1&&v[i]%2!=v[gee]%2)
	  {
		  s.erase(s.find(i));
		  ans[i]=1;
	  }
  }
  while(!s.empty())
  {
	  ll note=s.size();
	  vi re;
	  for(ll d:s)
	  {
		  ll ge=d-v[d];
		  ll gee=d+v[d];
		  ll x=mod,y=mod;
		  if(ge>=0&&ans[ge]!=0&&s.find(ge)==s.end())
		  {
			 x=ans[ge]+1;
		  }
		  if(gee<=n-1&&ans[gee]!=0&&s.find(gee)==s.end())
		  {
			  y=ans[gee]+1;
		  }
		  if(x==mod&&y==mod)
		   continue;
		  ans[d]=min(x,y);
		  re.pb(d);
	  }
	  if(!re.size())
	   break;
	  set<ll>temp;
	  um up;
	  for(ll d:re)
	  {
		  up[d]=1;
	  }
	  for(ll d:s)
	  {
         if(!up[d])
		 {
			 temp.insert(d);
		 }
	  }
	  s.clear();
	  s=temp;
  }
  f(i,0,n)
  {
	  if(ans[i]==0)
	   cout<<-1<<" ";
	 else
	 {
		 cout<<ans[i]<<" ";
	 }

  }
}
int main() {
	fast;
	fast_input;
	fast_output;
	// ll t;
	// cin>>t;
	// f(i,0,t)
	// {
    //   cout<<"Case #"<<i+1<<":"<<" ";
	     solve();
	// }
	return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int>
#define pb push_back
#define pa pair<long long int ,long long int>
#define f(a,x,b) for(int a=x;a<b;a++)
#define sort(x) sort(x.begin(),x.end());
#define siz(a) (int)a.size()
#define mod 1000000007
#define F first
#define S second
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
ll visited[100001];
vi ans(100001);
ll n;
vi v(100001);
ll dfs(ll ind,ll par=-1)
{
	if(par!=-1)
	{
		if(v[ind]%2!=v[par]%2)
		{
			return 0;
		}
	}
	if(ans[ind]!=0)
	{
		return ans[ind];
	}
	visited[ind]=1;
    ll ge=ind-v[ind];
	ll gee=ind+v[ind];
	ll x=0,y=0;
	if(ge>=0)
	{
	  visited[ge]=1;
	  x=1+dfs(ge,ind);
	}
	if(gee<=n-1)
	{
		visited[gee]=1;
		y=1+dfs(gee,ind);
	}
	if(x==0&&y==0)
	{
		return ans[ind]=-1;
	}
	else if(x==0&&y!=0)
	{
		return ans[ind]=y;
	}
	else if(x!=0&&y==0)
	{
		return ans[ind]=x;
	}
	else
	{
		return ans[ind]=min(x,y);
	}
}
void solve()
{
  cin>>n;
  f(i,0,n)
  {
	  cin>>v[i];
  }
  f(i,0,n)
  {
	  cout<<dfs(i,-1)<<" ";
  }
}
int main() {
	fast;
	fast_input;
	fast_output;
	// ll t;
	// cin>>t;
	// f(i,0,t)
	// {
    //   cout<<"Case #"<<i+1<<":"<<" ";
	     solve();
	// }
	return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int>
#define pb push_back
#define pa pair<long long int ,long long int>
#define f(a,x,b) for(int a=x;a<b;a++)
#define sort(x) sort(x.begin(),x.end());
#define siz(a) (int)a.size()
#define mod 1000000007
#define F first
#define S second
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
vi ans(200001);
ll n;
vi v(200001);
void solve()
{
  cin>>n;
  set<ll>s;
  f(i,0,n)
  {
	  s.insert(i);
	  cin>>v[i];
  }
  f(i,0,n)
  {
	  ll ge=i-v[i];
	  ll gee=i+v[i];
	  if(ge>=0&&v[i]%2!=v[ge]%2)
	  {
		  ans[i]=1;
		  s.erase(s.find(i));
	  }
	  else if(gee<=n-1&&v[i]%2!=v[gee]%2)
	  {
		  s.erase(s.find(i));
		  ans[i]=1;
	  }
  }
  while(!s.empty())
  {
	  ll note=s.size();
	  vi re;
	  for(ll d:s)
	  {
		  ll ge=d-v[d];
		  ll gee=d+v[d];
		  ll x=mod,y=mod;
		  if(ge>=0&&ans[ge]!=0&&v[ge]%2==v[d]%2)
		  {
			 x=ans[ge]+1;
		  }
		  if(gee<=n-1&&ans[gee]!=0&&v[gee]%2==v[d]%2)
		  {
			  y=ans[gee]+1;
		  }
		  if(x==mod&&y==mod)
		   continue;
		  ans[d]=min(x,y);
		  re.pb(d);
	  }
	  if(!re.size())
	   break;
	  for(ll d:re)
	  {
		  s.erase(s.find(d));
	  }
  }
  f(i,0,n)
  {
	  if(ans[i]==0)
	   cout<<-1<<" ";
	 else
	 {
		 cout<<ans[i]<<" ";
	 }

  }
}
int main() {
	fast;
	fast_input;
	fast_output;
	// ll t;
	// cin>>t;
	// f(i,0,t)
	// {
    //   cout<<"Case #"<<i+1<<":"<<" ";
	     solve();
	// }
	return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int>
#define pb push_back
#define pa pair<long long int ,long long int>
#define f(a,x,b) for(int a=x;a<b;a++)
#define sort(x) sort(x.begin(),x.end());
#define siz(a) (int)a.size()
#define mod 1000000007
#define F first
#define S second
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
vi ans(200001);
ll n;
vi v(200001);
void solve()
{
  cin>>n;
  set<ll>s;
  f(i,0,n)
  {
	  s.insert(i);
	  cin>>v[i];
  }
  f(i,0,n)
  {
	  ll ge=i-v[i];
	  ll gee=i+v[i];
	  if(ge>=0&&v[i]%2!=v[ge]%2)
	  {
		  ans[i]=1;
		  s.erase(s.find(i));
	  }
	  else if(gee<=n-1&&v[i]%2!=v[gee]%2)
	  {
		  s.erase(s.find(i));
		  ans[i]=1;
	  }
  }
  while(!s.empty())
  {
	  ll note=s.size();
	  vi re;
	  for(ll d:s)
	  {
		  ll ge=d-v[d];
		  ll gee=d+v[d];
		  ll x=mod,y=mod;
		  if(ge>=0&&ans[ge]!=0)
		  {
			 x=ans[ge]+1;
		  }
		  if(gee<=n-1&&ans[gee]!=0)
		  {
			  y=ans[gee]+1;
		  }
		  if(x==mod&&y==mod)
		   continue;
		  ans[d]=min(x,y);
		  re.pb(d);
	  }
	  if(!re.size())
	   break;
	  for(ll d:re)
	  {
		  s.erase(s.find(d));
	  }
  }
  f(i,0,n)
  {
	  if(ans[i]==0)
	   cout<<-1<<" ";
	 else
	 {
		 cout<<ans[i]<<" ";
	 }

  }
}
int main() {
	fast;
	fast_input;
	fast_output;
	// ll t;
	// cin>>t;
	// f(i,0,t)
	// {
    //   cout<<"Case #"<<i+1<<":"<<" ";
	     solve();
	// }
	return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int>
#define pb push_back
#define pa pair<long long int ,long long int>
#define f(a,x,b) for(int a=x;a<b;a++)
#define sort(x) sort(x.begin(),x.end());
#define siz(a) (int)a.size()
#define mod 1000000007
#define F first
#define S second
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
vi ans(200001);
ll n;
vi v(200001);
void solve()
{
  cin>>n;
  set<ll>s;
  f(i,0,n)
  {
	  s.insert(i);
	  cin>>v[i];
  }
  f(i,0,n)
  {
	  ll ge=i-v[i];
	  ll gee=i+v[i];
	  if(ge>=0&&v[i]%2!=v[ge]%2)
	  {
		  ans[i]=1;
		  s.erase(s.find(i));
	  }
	  else if(gee<=n-1&&v[i]%2!=v[gee]%2)
	  {
		  s.erase(s.find(i));
		  ans[i]=1;
	  }
  }
  while(!s.empty())
  {
	  ll note=s.size();
	  vi re;
	  for(ll d:s)
	  {
		  ll ge=d-v[d];
		  ll gee=d+v[d];
		  ll x=mod,y=mod;
		  if(ge>=0&&ans[ge]!=0&&s.find(ge)==s.end())
		  {
			 x=ans[ge]+1;
		  }
		  if(gee<=n-1&&ans[gee]!=0&&s.find(gee)==s.end())
		  {
			  y=ans[gee]+1;
		  }
		  if(x==mod&&y==mod)
		   continue;
		  ans[d]=min(x,y);
		  re.pb(d);
	  }
	  if(!re.size())
	   break;
	  for(ll d:re)
	  {
		  s.erase(s.find(d));
	  }
  }
  f(i,0,n)
  {
	  if(ans[i]==0)
	   cout<<-1<<" ";
	 else
	 {
		 cout<<ans[i]<<" ";
	 }

  }
}
int main() {
	fast;
	fast_input;
	fast_output;
	// ll t;
	// cin>>t;
	// f(i,0,t)
	// {
    //   cout<<"Case #"<<i+1<<":"<<" ";
	     solve();
	// }
	return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int>
#define pb push_back
#define pa pair<long long int ,long long int>
#define f(a,x,b) for(int a=x;a<b;a++)
#define sort(x) sort(x.begin(),x.end());
#define siz(a) (int)a.size()
#define mod 1000000007
#define F first
#define S second
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
vi ans(200001);
ll n;
vi v(200001);
void solve()
{
  cin>>n;
  set<ll>s;
  f(i,0,n)
  {
	  s.insert(i);
	  cin>>v[i];
  }
  f(i,0,n)
  {
	  ll ge=i-v[i];
	  ll gee=i+v[i];
	  if(ge>=0&&v[i]%2!=v[ge]%2)
	  {
		  ans[i]=1;
		  s.erase(s.find(i));
	  }
	  else if(gee<=n-1&&v[i]%2!=v[gee]%2)
	  {
		  s.erase(s.find(i));
		  ans[i]=1;
	  }
  }
  while(!s.empty())
  {
	  ll note=s.size();
	  for(ll d:s)
	  {
		  ll ge=d-v[d];
		  ll gee=d+v[d];
		  ll x=mod,y=mod;
		  if(ge>=0&&ans[ge]!=0)
		  {
			 x=ans[ge]+1;
		  }
		  if(gee<=n-1&&ans[gee]!=0)
		  {
			  y=ans[gee]+1;
		  }
		  if(x==mod&&y==mod)
		   continue;
		  ans[d]=min(x,y);
		  s.erase(s.find(d));
	  }
	  if(note==s.size())
	   break;
  }
  f(i,0,n)
  {
	  if(ans[i]==0)
	   cout<<-1<<" ";
	 else
	 {
		 cout<<ans[i]<<" ";
	 }

  }
}
int main() {
	fast;
	fast_input;
	fast_output;
	// ll t;
	// cin>>t;
	// f(i,0,t)
	// {
    //   cout<<"Case #"<<i+1<<":"<<" ";
	     solve();
	// }
	return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int>
#define pb push_back
#define pa pair<long long int ,long long int>
#define f(a,x,b) for(int a=x;a<b;a++)
#define sort(x) sort(x.begin(),x.end());
#define siz(a) (int)a.size()
#define mod 1000000007
#define F first
#define S second
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
ll visited[200001];
vi ans(200001);
ll n;
vi v(200001);
ll dfs(ll ind,ll par=-1)
{
	visited[ind]=1;
	if(par!=-1)
	{
		if(v[ind]%2!=v[par]%2)
		{
			return 0;
		}
	}
	if(ans[ind]!=0)
	{
		return ans[ind];
	}
    ll ge=ind-v[ind];
	ll gee=ind+v[ind];
	ll x=0,y=0;
	if(ge>=0)
	{
	  visited[ge]=1;
	  x=1+dfs(ge,ind);
	}
	if(gee<=n-1)
	{
		visited[gee]=1;
		y=1+dfs(gee,ind);
	}
	if(x==0&&y==0)
	{
		return ans[ind]=-1;
	}
	else if(x==0&&y!=0)
	{
		return ans[ind]=y;
	}
	else if(x!=0&&y==0)
	{
		return ans[ind]=x;
	}
	else
	{
		return ans[ind]=min(x,y);
	}
}
void solve()
{
  cin>>n;
  f(i,0,n)
  {
	  cin>>v[i];
  }
  f(i,0,n)
  {
	 if(!visited[i]||ans[i]==0)
	   dfs(i,-1);
  }
  f(i,0,n)
  {
	  cout<<ans[i]<<" ";
  }
}
int main() {
	fast;
	fast_input;
	fast_output;
	// ll t;
	// cin>>t;
	// f(i,0,t)
	// {
    //   cout<<"Case #"<<i+1<<":"<<" ";
	     solve();
	// }
	return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int>
#define pb push_back
#define pa pair<long long int ,long long int>
#define f(a,x,b) for(int a=x;a<b;a++)
#define sort(x) sort(x.begin(),x.end());
#define siz(a) (int)a.size()
#define mod 1000000007
#define F first
#define S second
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
vi ans(200001);
ll n;
vi v(200001);
void solve()
{
  cin>>n;
  set<ll>s;
  f(i,0,n)
  {
	  s.insert(i);
	  cin>>v[i];
  }
  f(i,0,n)
  {
	  ll ge=i-v[i];
	  ll gee=i+v[i];
	  if(ge>=0&&v[i]%2!=v[ge]%2)
	  {
		  ans[i]=1;
		  s.erase(s.find(i));
	  }
	  else if(gee<=n-1&&v[i]%2!=v[gee]%2)
	  {
		  s.erase(s.find(i));
		  ans[i]=1;
	  }
  }
  while(!s.empty())
  {
	  ll note=s.size();
	  vi re;
	  um uo;
	  for(ll d:s)
	  {
		  ll ge=d-v[d];
		  ll gee=d+v[d];
		  ll x=mod,y=mod;
		  if(ge>=0&&ans[ge]!=0&&!uo[ge])
		  {
			 x=ans[ge]+1;
			 uo[ge]=1;
		  }
		  if(gee<=n-1&&ans[gee]!=0&&!uo[gee])
		  {
			  y=ans[gee]+1;
			  uo[gee]=1;
		  }
		  if(x==mod&&y==mod)
		   continue;
		  ans[d]=min(x,y);
		  re.pb(d);
	  }
	  if(!re.size())
	   break;
	  set<ll>temp;
	  um up;
	  for(ll d:re)
	  {
		  up[d]=1;
	  }
	  for(ll d:s)
	  {
         if(!up[d])
		 {
			 temp.insert(d);
		 }
	  }
	  s.clear();
	  s=temp;
  }
  f(i,0,n)
  {
	  if(ans[i]==0)
	   cout<<-1<<" ";
	 else
	 {
		 cout<<ans[i]<<" ";
	 }

  }
}
int main() {
	fast;
	fast_input;
	fast_output;
	// ll t;
	// cin>>t;
	// f(i,0,t)
	// {
    //   cout<<"Case #"<<i+1<<":"<<" ";
	     solve();
	// }
	return 0;
}


    #include<bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    typedef set<ll>::iterator iets;
    typedef vector<ll>::iterator ietv;
    typedef vector<ll> V;

    #define mod 1000000007
    const ll INF=1000000000000000000;
    ll power(ll x, ll y)
    {
        ll res = 1;
        while (y > 0)
        {
            if (y & 1)
                res = res*x;
            y = y>>1;
            x = x*x;
        }
        return res;
    }
    #define ull unsigned long long int
    ll count(ll n,ll m){
        if(m%2==0){
            ll x=m,y=2,ans=0;
            while((x+y-1)<=n){
                ans+=y;
                y=y*2;
                x*=2;
            }
            if(x<=n&&(x+y-1)>n){
                ans+=n-x+1;
            }
            return ans;
        }
        else{
            ll ans=1;
            ans+=count(n,2*m);
            return ans;
        }
    }
    ll a[200005],vis[200005]={0},n,ans[200005];
    vector<ll> adj[200005];
    void dfs(ll i){
        vis[i]=1;
        for(auto x:adj[i]){
            if(a[x]%2!=a[i]%2){
                ans[i]=1;
            }
        }
        if(ans[i]==10000000000){
            for(auto x:adj[i]){
                if(!vis[x])
                dfs(x);
            }
            for(auto x:adj[i]){
                ans[i]=min(ans[i],ans[x]+1);
            }
        }

    }
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t=1,xp=1;
        //cin>>t;
        while(t--)
        {
            ll i,h,j,x=0,y=0,k=0,m,r=0,l=0,o=0,cnt1=INT_MAX,cnt2=0,cnt3=INT_MIN,cnt4=0,min1=INT_MIN;
            cin>>n;
            for(i=0;i<n;i++)
                cin>>a[i];
            for(i=0;i<n;i++){
                if(i+a[i]<n){
                    adj[i+a[i]].push_back(i);
                }
                if(i-a[i]>=0)
                    adj[i-a[i]].push_back(i);
            }
            memset(ans,-1,sizeof(ans));
            /*for(i=0;i<n;i++){
                for(auto x:adj[i])
                    cout<<x<<" ";
                cout<<endl;
            }*/
            queue<ll> q;
            vector<ll> v;
            for(i=0;i<n;i++){
                if(i+a[i]<n&&a[i]%2!=a[a[i]+i]%2){
                    q.push(i);
                    ans[i]=1;
                    continue;
                }
                if(i-a[i]>=0&&a[i]%2!=a[i-a[i]]%2){
                    q.push(i);
                    ans[i]=1;
                }
            }
            while(!q.empty()){
                i=q.front();
                q.pop();
                for(auto x:adj[i]){
                    if(ans[x]==-1&&a[x]%2==a[i]%2){
                        ans[x]=ans[i]+1;
                        q.push(x);
                    }
                }
            }
            for(i=0;i<n;i++)
                cout<<ans[i]<<" ";
            cout<<"\n";

        }
    }


    #include<bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    typedef set<ll>::iterator iets;
    typedef vector<ll>::iterator ietv;
    typedef vector<ll> V;

    #define mod 1000000007
    const ll INF=1000000000000000000;
    ll power(ll x, ll y)
    {
        ll res = 1;
        while (y > 0)
        {
            if (y & 1)
                res = res*x;
            y = y>>1;
            x = x*x;
        }
        return res;
    }
    #define ull unsigned long long int

    ll a[200005],vis[200005]={0},n,ans[200005];
    vector<ll> adj[200005];

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t=1,xp=1;
        //cin>>t;
        while(t--)
        {
            ll i,h,j,x=0,y=0,k=0,m,r=0,l=0,o=0,cnt1=INT_MAX,cnt2=0,cnt3=INT_MIN,cnt4=0,min1=INT_MIN;
            cin>>n;
            for(i=0;i<n;i++)
                cin>>a[i];
            for(i=0;i<n;i++){
                if(i+a[i]<n){
                    adj[i+a[i]].push_back(i);
                }
                if(i-a[i]>=0)
                    adj[i-a[i]].push_back(i);
            }
            memset(ans,-1,sizeof(ans));
            queue<ll> q;
            vector<ll> v;
            for(i=0;i<n;i++){
                if(i+a[i]<n&&a[i]%2!=a[a[i]+i]%2){
                    q.push(i);
                    ans[i]=1;
                    continue;
                }
                if(i-a[i]>=0&&a[i]%2!=a[i-a[i]]%2){
                    q.push(i);
                    ans[i]=1;
                }
            }
            while(!q.empty()){
                i=q.front();
                q.pop();
                for(auto x:adj[i]){
                    if(ans[x]==-1){
                        ans[x]=ans[i]+1;
                        q.push(x);
                    }
                }
            }
            for(i=0;i<n;i++)
                cout<<ans[i]<<" ";
            cout<<"\n";

        }
    }


    #include<bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    typedef set<ll>::iterator iets;
    typedef vector<ll>::iterator ietv;
    typedef vector<ll> V;

    #define mod 1000000007
    const ll INF=1000000000000000000;
    ll power(ll x, ll y)
    {
        ll res = 1;
        while (y > 0)
        {
            if (y & 1)
                res = res*x;
            y = y>>1;
            x = x*x;
        }
        return res;
    }
    #define ull unsigned long long int
    ll count(ll n,ll m){
        if(m%2==0){
            ll x=m,y=2,ans=0;
            while((x+y-1)<=n){
                ans+=y;
                y=y*2;
                x*=2;
            }
            if(x<=n&&(x+y-1)>n){
                ans+=n-x+1;
            }
            return ans;
        }
        else{
            ll ans=1;
            ans+=count(n,2*m);
            return ans;
        }
    }
    ll a[200005],vis[200005]={0},n,ans[200005];
    void dfs(ll i){
        if(i+a[i]<n){
            if(a[i+a[i]]%2!=a[i]%2){
                ans[i]=1;
            }
            else{
                if(ans[i+a[i]]==INT_MAX){
                    dfs(i+a[i]);
                }
                ans[i]=min(ans[i],ans[i+a[i]]+1);
            }
        }
        if(i-a[i]>=0){
            if(a[i-a[i]]%2!=a[i]%2){
                ans[i]=1;
            }
            else{
                if(ans[i-a[i]]==INT_MAX)
                dfs(i-a[i]);
                ans[i]=min(ans[i],ans[i-a[i]]+1);
            }
        }

    }
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t=1,xp=1;
        //cin>>t;
        while(t--)
        {
            ll i,h,j,x=0,y=0,k=0,m,r=0,l=0,o=0,cnt1=INT_MAX,cnt2=0,cnt3=INT_MIN,cnt4=0,min1=INT_MIN;
            cin>>n;
            for(i=0;i<n;i++){
                ans[i]=INT_MAX;
            }
            for(i=0;i<n;i++)
                cin>>a[i];
            for(i=0;i<n;i++){
                if(!vis[i]){
                    dfs(i);
                }
            }
            for(i=0;i<n;i++){
                if(ans[i]==INT_MAX)
                    ans[i]=-1;
            }
            for(i=0;i<n;i++)
                cout<<ans[i]<<" ";
            cout<<"\n";

        }
    }


    #include<bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    typedef set<ll>::iterator iets;
    typedef vector<ll>::iterator ietv;
    typedef vector<ll> V;

    #define mod 1000000007
    const ll INF=1000000000000000000;
    ll power(ll x, ll y)
    {
        ll res = 1;
        while (y > 0)
        {
            if (y & 1)
                res = res*x;
            y = y>>1;
            x = x*x;
        }
        return res;
    }
    #define ull unsigned long long int
    ll count(ll n,ll m){
        if(m%2==0){
            ll x=m,y=2,ans=0;
            while((x+y-1)<=n){
                ans+=y;
                y=y*2;
                x*=2;
            }
            if(x<=n&&(x+y-1)>n){
                ans+=n-x+1;
            }
            return ans;
        }
        else{
            ll ans=1;
            ans+=count(n,2*m);
            return ans;
        }
    }
    ll a[200005],vis[200005]={0},n,ans[200005];
    void dfs(ll i){
        if(i+a[i]<n){
            if(a[i+a[i]]%2!=a[i]%2){
                ans[i]=1;
            }
            else{
                if(ans[i+a[i]]==INT_MAX){
                    dfs(i+a[i]);
                }
                ans[i]=min(ans[i],ans[i+a[i]]+1);
            }
        }
        if(i-a[i]>=0){
            if(a[i-a[i]]%2!=a[i]%2){
                ans[i]=1;
            }
            else{
                if(ans[i-a[i]]==INT_MAX)
                dfs(i-a[i]);
                ans[i]=min(ans[i],ans[i-a[i]]+1);
            }
        }

    }
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t=1,xp=1;
        //cin>>t;
        while(t--)
        {
            ll i,h,j,x=0,y=0,k=0,m,r=0,l=0,o=0,cnt1=INT_MAX,cnt2=0,cnt3=INT_MIN,cnt4=0,min1=INT_MIN;
            cin>>n;
            for(i=0;i<n;i++){
                ans[i]=INT_MAX;
            }
            for(i=0;i<n;i++)
                cin>>a[i];
            for(i=0;i<n;i++){
                if(ans[i]==INT_MAX){
                    dfs(i);
                }
            }
            for(i=0;i<n;i++){
                if(ans[i]==INT_MAX)
                    ans[i]=-1;
            }
            for(i=0;i<n;i++)
                cout<<ans[i]<<" ";
            cout<<"\n";

        }
    }


    #include<bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    typedef set<ll>::iterator iets;
    typedef vector<ll>::iterator ietv;
    typedef vector<ll> V;

    #define mod 1000000007
    const ll INF=1000000000000000000;
    ll power(ll x, ll y)
    {
        ll res = 1;
        while (y > 0)
        {
            if (y & 1)
                res = res*x;
            y = y>>1;
            x = x*x;
        }
        return res;
    }
    #define ull unsigned long long int
    ll count(ll n,ll m){
        if(m%2==0){
            ll x=m,y=2,ans=0;
            while((x+y-1)<=n){
                ans+=y;
                y=y*2;
                x*=2;
            }
            if(x<=n&&(x+y-1)>n){
                ans+=n-x+1;
            }
            return ans;
        }
        else{
            ll ans=1;
            ans+=count(n,2*m);
            return ans;
        }
    }
    ll a[200005],vis[200005]={0},n,ans[200005];
    vector<ll> adj[200005];
    void dfs(ll i){
        vis[i]=1;
        for(auto x:adj[i]){
            if(a[x]%2!=a[i]%2){
                ans[i]=1;
            }
        }
        if(ans[i]>n){
            for(auto x:adj[i]){
                dfs(x);
            }
            for(auto x:adj[i]){
                ans[i]=min(ans[i],ans[x]+1);
            }
        }

    }
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t=1,xp=1;
        //cin>>t;
        while(t--)
        {
            ll i,h,j,x=0,y=0,k=0,m,r=0,l=0,o=0,cnt1=INT_MAX,cnt2=0,cnt3=INT_MIN,cnt4=0,min1=INT_MIN;
            cin>>n;
            for(i=0;i<n;i++){
                ans[i]=INT_MAX;
            }
            for(i=0;i<n;i++)
                cin>>a[i];
            for(i=0;i<n;i++){
                if(i+a[i]<n){
                    adj[i].push_back(i+a[i]);
                }
                if(i-a[i]>=0)
                    adj[i].push_back(i-a[i]);
            }
            /*for(i=0;i<n;i++){
                for(auto x:adj[i])
                    cout<<x<<" ";
                cout<<endl;
            }*/
            for(i=0;i<n;i++){
                if(!vis[i]){
                    dfs(i);
                }
            }
            for(i=0;i<n;i++){
                if(ans[i]==INT_MAX)
                    ans[i]=-1;
            }
            for(i=0;i<n;i++)
                cout<<ans[i]<<" ";
            cout<<"\n";

        }
    }


    #include<bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    typedef set<ll>::iterator iets;
    typedef vector<ll>::iterator ietv;
    typedef vector<ll> V;

    #define mod 1000000007
    const ll INF=1000000000000000000;
    ll power(ll x, ll y)
    {
        ll res = 1;
        while (y > 0)
        {
            if (y & 1)
                res = res*x;
            y = y>>1;
            x = x*x;
        }
        return res;
    }
    #define ull unsigned long long int
    ll count(ll n,ll m){
        if(m%2==0){
            ll x=m,y=2,ans=0;
            while((x+y-1)<=n){
                ans+=y;
                y=y*2;
                x*=2;
            }
            if(x<=n&&(x+y-1)>n){
                ans+=n-x+1;
            }
            return ans;
        }
        else{
            ll ans=1;
            ans+=count(n,2*m);
            return ans;
        }
    }
    ll a[200005],vis[200005]={0},n,ans[200005];
    vector<ll> adj[200005];
    void dfs(ll i){
        if(i+a[i]<n){
            if(a[i+a[i]]%2!=a[i]%2){
                ans[i]=1;
            }
            else{
                dfs(i+a[i]);
                ans[i]=min(ans[i],ans[i+a[i]]+1);
            }
        }
        if(i-a[i]>=0){
            if(a[i-a[i]]%2!=a[i]%2){
                ans[i]=1;
            }
            else{
                dfs(i-a[i]);
                ans[i]=min(ans[i],ans[i-a[i]]+1);
            }
        }

    }
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t=1,xp=1;
        //cin>>t;
        while(t--)
        {
            ll i,h,j,x=0,y=0,k=0,m,r=0,l=0,o=0,cnt1=INT_MAX,cnt2=0,cnt3=INT_MIN,cnt4=0,min1=INT_MIN;
            cin>>n;
            for(i=0;i<n;i++){
                ans[i]=INT_MAX;
            }
            for(i=0;i<n;i++)
                cin>>a[i];
            for(i=0;i<n;i++){
                if(!vis[i]){
                    dfs(i);
                }
            }
            for(i=0;i<n;i++){
                if(ans[i]==INT_MAX)
                    ans[i]=-1;
            }
            for(i=0;i<n;i++)
                cout<<ans[i]<<" ";
            cout<<"\n";

        }
    }


    #include<bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    typedef set<ll>::iterator iets;
    typedef vector<ll>::iterator ietv;
    typedef vector<ll> V;

    #define mod 1000000007
    const ll INF=1000000000000000000;
    ll power(ll x, ll y)
    {
        ll res = 1;
        while (y > 0)
        {
            if (y & 1)
                res = res*x;
            y = y>>1;
            x = x*x;
        }
        return res;
    }
    #define ull unsigned long long int
    ll count(ll n,ll m){
        if(m%2==0){
            ll x=m,y=2,ans=0;
            while((x+y-1)<=n){
                ans+=y;
                y=y*2;
                x*=2;
            }
            if(x<=n&&(x+y-1)>n){
                ans+=n-x+1;
            }
            return ans;
        }
        else{
            ll ans=1;
            ans+=count(n,2*m);
            return ans;
        }
    }
    ll a[200005],vis[200005]={0},n,ans[200005];
    vector<ll> adj[200005];
    void dfs(ll i){
        vis[i]=1;
        for(auto x:adj[i]){
            if(a[x]%2!=a[i]%2){
                ans[i]=1;
            }
        }
        if(ans[i]==10000000000){
            for(auto x:adj[i]){
                if(!vis[x])
                dfs(x);
            }
            for(auto x:adj[i]){
                ans[i]=min(ans[i],ans[x]+1);
            }
        }

    }
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t=1,xp=1;
        //cin>>t;
        while(t--)
        {
            ll i,h,j,x=0,y=0,k=0,m,r=0,l=0,o=0,cnt1=INT_MAX,cnt2=0,cnt3=INT_MIN,cnt4=0,min1=INT_MIN;
            cin>>n;
            for(i=0;i<n;i++){
                ans[i]=10000000000;
            }
            for(i=0;i<n;i++)
                cin>>a[i];
            for(i=0;i<n;i++){
                if(i+a[i]<n){
                    adj[i].push_back(i+a[i]);
                }
                if(i-a[i]>=0)
                    adj[i].push_back(i-a[i]);
            }
            /*for(i=0;i<n;i++){
                for(auto x:adj[i])
                    cout<<x<<" ";
                cout<<endl;
            }*/
            for(i=0;i<n;i++){
                if(!vis[i]){
                    dfs(i);
                }
            }
            for(i=0;i<n;i++)
            {
                if(vis[i]&&ans[i]==10000000000)
                    vis[i]=0;
            }
            for(i=0;i<n;i++){
                if(!vis[i]){
                    dfs(i);
                }
            }
            for(i=0;i<n;i++)
            {
                if(vis[i]&&ans[i]==10000000000)
                    vis[i]=0;
            }
            for(i=0;i<n;i++){
                if(!vis[i]){
                    dfs(i);
                }
            }
            for(i=0;i<n;i++)
            {
                if(vis[i]&&ans[i]==10000000000)
                    vis[i]=0;
            }
            for(i=0;i<n;i++){
                if(!vis[i]){
                    dfs(i);
                }
            }
            for(i=0;i<n;i++)
            {
                if(vis[i]&&ans[i]==10000000000)
                    vis[i]=0;
            }
            for(i=0;i<n;i++){
                if(!vis[i]){
                    dfs(i);
                }
            }
            for(i=0;i<n;i++)
            {
                if(vis[i]&&ans[i]==10000000000)
                    vis[i]=0;
            }
            for(i=0;i<n;i++){
                if(!vis[i]){
                    dfs(i);
                }
            }
            for(i=0;i<n;i++)
            {
                if(vis[i]&&ans[i]==10000000000)
                    vis[i]=0;
            }
            for(i=0;i<n;i++){
                if(!vis[i]){
                    dfs(i);
                }
            }
            for(i=0;i<n;i++)
            {
                if(vis[i]&&ans[i]==10000000000)
                    vis[i]=0;
            }
            for(i=0;i<n;i++){
                if(!vis[i]){
                    dfs(i);
                }
            }
            for(i=0;i<n;i++){
                if(ans[i]==10000000000)
                    ans[i]=-1;
            }
            for(i=0;i<n;i++)
                cout<<ans[i]<<" ";
            cout<<"\n";

        }
    }


    #include<bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    typedef set<ll>::iterator iets;
    typedef vector<ll>::iterator ietv;
    typedef vector<ll> V;

    #define mod 1000000007
    const ll INF=1000000000000000000;
    ll power(ll x, ll y)
    {
        ll res = 1;
        while (y > 0)
        {
            if (y & 1)
                res = res*x;
            y = y>>1;
            x = x*x;
        }
        return res;
    }
    #define ull unsigned long long int
    ll count(ll n,ll m){
        if(m%2==0){
            ll x=m,y=2,ans=0;
            while((x+y-1)<=n){
                ans+=y;
                y=y*2;
                x*=2;
            }
            if(x<=n&&(x+y-1)>n){
                ans+=n-x+1;
            }
            return ans;
        }
        else{
            ll ans=1;
            ans+=count(n,2*m);
            return ans;
        }
    }
    ll a[200005],vis[200005]={0},n,ans[200005];
    vector<ll> adj[200005];
    void dfs(ll i){
        vis[i]=1;
        for(auto x:adj[i]){
            if(a[x]%2!=a[i]%2){
                ans[i]=1;
            }
            else{
                if(!vis[x]){
                    dfs(x);
                }
                ans[i]=min(ans[i],ans[x]+1);
            }
        }

    }
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t=1,xp=1;
        //cin>>t;
        while(t--)
        {
            ll i,h,j,x=0,y=0,k=0,m,r=0,l=0,o=0,cnt1=INT_MAX,cnt2=0,cnt3=INT_MIN,cnt4=0,min1=INT_MIN;
            cin>>n;
            for(i=0;i<n;i++){
                ans[i]=INT_MAX;
            }
            for(i=0;i<n;i++)
                cin>>a[i];
            for(i=0;i<n;i++){
                if(i+a[i]<n){
                    adj[i].push_back(i+a[i]);
                }
                if(i-a[i]>=0)
                    adj[i].push_back(i-a[i]);
            }
            /*for(i=0;i<n;i++){
                for(auto x:adj[i])
                    cout<<x<<" ";
                cout<<endl;
            }*/
            for(i=0;i<n;i++){
                if(!vis[i]){
                    dfs(i);
                }
            }
            for(i=0;i<n;i++){
                if(ans[i]==INT_MAX)
                    ans[i]=-1;
            }
            for(i=0;i<n;i++)
                cout<<ans[i]<<" ";
            cout<<"\n";

        }
    }


    #include<bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    typedef set<ll>::iterator iets;
    typedef vector<ll>::iterator ietv;
    typedef vector<ll> V;

    #define mod 1000000007
    const ll INF=1000000000000000000;
    ll power(ll x, ll y)
    {
        ll res = 1;
        while (y > 0)
        {
            if (y & 1)
                res = res*x;
            y = y>>1;
            x = x*x;
        }
        return res;
    }
    #define ull unsigned long long int
    ll count(ll n,ll m){
        if(m%2==0){
            ll x=m,y=2,ans=0;
            while((x+y-1)<=n){
                ans+=y;
                y=y*2;
                x*=2;
            }
            if(x<=n&&(x+y-1)>n){
                ans+=n-x+1;
            }
            return ans;
        }
        else{
            ll ans=1;
            ans+=count(n,2*m);
            return ans;
        }
    }
    ll a[200005],vis[200005]={0},n,ans[200005];
    vector<ll> adj[200005];
    void dfs(ll i){
        vis[i]=1;
        for(auto x:adj[i]){
            if(a[x]%2!=a[i]%2){
                ans[i]=1;
            }
        }
        if(ans[i]==10000000000){
            for(auto x:adj[i]){
                if(!vis[x])
                dfs(x);
            }
            for(auto x:adj[i]){
                ans[i]=min(ans[i],ans[x]+1);
            }
        }

    }
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t=1,xp=1;
        //cin>>t;
        while(t--)
        {
            ll i,h,j,x=0,y=0,k=0,m,r=0,l=0,o=0,cnt1=INT_MAX,cnt2=0,cnt3=INT_MIN,cnt4=0,min1=INT_MIN;
            cin>>n;
            for(i=0;i<n;i++){
                ans[i]=10000000000;
            }
            for(i=0;i<n;i++)
                cin>>a[i];
            for(i=0;i<n;i++){
                if(i+a[i]<n){
                    adj[i].push_back(i+a[i]);
                }
                if(i-a[i]>=0)
                    adj[i].push_back(i-a[i]);
            }
            /*for(i=0;i<n;i++){
                for(auto x:adj[i])
                    cout<<x<<" ";
                cout<<endl;
            }*/
            for(i=0;i<n;i++){
                if(!vis[i]){
                    dfs(i);
                }
            }
            for(i=0;i<n;i++)
            {
                if(vis[i]&&ans[i]==10000000000)
                    vis[i]=0;
            }
            for(i=0;i<n;i++){
                if(!vis[i]){
                    dfs(i);
                }
            }
            for(i=0;i<n;i++){
                if(ans[i]==10000000000)
                    ans[i]=-1;
            }
            for(i=0;i<n;i++)
                cout<<ans[i]<<" ";
            cout<<"\n";

        }
    }


    #include<bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    typedef set<ll>::iterator iets;
    typedef vector<ll>::iterator ietv;
    typedef vector<ll> V;

    #define mod 1000000007
    const ll INF=1000000000000000000;
    ll power(ll x, ll y)
    {
        ll res = 1;
        while (y > 0)
        {
            if (y & 1)
                res = res*x;
            y = y>>1;
            x = x*x;
        }
        return res;
    }
    #define ull unsigned long long int
    ll count(ll n,ll m){
        if(m%2==0){
            ll x=m,y=2,ans=0;
            while((x+y-1)<=n){
                ans+=y;
                y=y*2;
                x*=2;
            }
            if(x<=n&&(x+y-1)>n){
                ans+=n-x+1;
            }
            return ans;
        }
        else{
            ll ans=1;
            ans+=count(n,2*m);
            return ans;
        }
    }
    ll a[200005],vis[200005]={0},n,ans[200005];
    vector<ll> adj[200005];
    void dfs(ll i){
        vis[i]=1;
        for(auto x:adj[i]){
            if(a[x]%2!=a[i]%2){
                ans[i]=1;
            }
        }
        if(ans[i]>n){
            for(auto x:adj[i]){
                if(!vis[x])
                dfs(x);
            }
            for(auto x:adj[i]){
                ans[i]=min(ans[i],ans[x]+1);
            }
        }

    }
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t=1,xp=1;
        //cin>>t;
        while(t--)
        {
            ll i,h,j,x=0,y=0,k=0,m,r=0,l=0,o=0,cnt1=INT_MAX,cnt2=0,cnt3=INT_MIN,cnt4=0,min1=INT_MIN;
            cin>>n;
            for(i=0;i<n;i++){
                ans[i]=INT_MAX;
            }
            for(i=0;i<n;i++)
                cin>>a[i];
            for(i=0;i<n;i++){
                if(i+a[i]<n){
                    adj[i].push_back(i+a[i]);
                }
                if(i-a[i]>=0)
                    adj[i].push_back(i-a[i]);
            }
            /*for(i=0;i<n;i++){
                for(auto x:adj[i])
                    cout<<x<<" ";
                cout<<endl;
            }*/
            for(i=0;i<n;i++){
                if(!vis[i]){
                    dfs(i);
                }
            }
            for(i=0;i<n;i++){
                if(ans[i]==INT_MAX)
                    ans[i]=-1;
            }
            for(i=0;i<n;i++)
                cout<<ans[i]<<" ";
            cout<<"\n";

        }
    }


    #include<bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    typedef set<ll>::iterator iets;
    typedef vector<ll>::iterator ietv;
    typedef vector<ll> V;

    #define mod 1000000007
    const ll INF=1000000000000000000;
    ll power(ll x, ll y)
    {
        ll res = 1;
        while (y > 0)
        {
            if (y & 1)
                res = res*x;
            y = y>>1;
            x = x*x;
        }
        return res;
    }
    #define ull unsigned long long int
    ll count(ll n,ll m){
        if(m%2==0){
            ll x=m,y=2,ans=0;
            while((x+y-1)<=n){
                ans+=y;
                y=y*2;
                x*=2;
            }
            if(x<=n&&(x+y-1)>n){
                ans+=n-x+1;
            }
            return ans;
        }
        else{
            ll ans=1;
            ans+=count(n,2*m);
            return ans;
        }
    }
    ll a[200005],vis[200005]={0},n,ans[200005];
    vector<ll> adj[200005];
    void dfs(ll i){
        vis[i]=1;
        for(auto x:adj[i]){
            if(a[x]%2!=a[i]%2){
                ans[i]=1;
            }
        }
        if(ans[i]==10000000000){
            for(auto x:adj[i]){
                if(!vis[x])
                dfs(x);
            }
            for(auto x:adj[i]){
                ans[i]=min(ans[i],ans[x]+1);
            }
        }

    }
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t=1,xp=1;
        //cin>>t;
        while(t--)
        {
            ll i,h,j,x=0,y=0,k=0,m,r=0,l=0,o=0,cnt1=INT_MAX,cnt2=0,cnt3=INT_MIN,cnt4=0,min1=INT_MIN;
            cin>>n;
            for(i=0;i<n;i++){
                ans[i]=10000000000;
            }
            for(i=0;i<n;i++)
                cin>>a[i];
            for(i=0;i<n;i++){
                if(i+a[i]<n){
                    adj[i].push_back(i+a[i]);
                }
                if(i-a[i]>=0)
                    adj[i].push_back(i-a[i]);
            }
            /*for(i=0;i<n;i++){
                for(auto x:adj[i])
                    cout<<x<<" ";
                cout<<endl;
            }*/
            for(i=0;i<n;i++){
                if(!vis[i]){
                    dfs(i);
                }
            }
            for(i=0;i<n;i++){
                if(ans[i]==10000000000)
                    ans[i]=-1;
            }
            for(i=0;i<n;i++)
                cout<<ans[i]<<" ";
            cout<<"\n";

        }
    }


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#define N 500010
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
struct node{
	int pre,to;
}a[N];
int n,tot;
int b[N],head[N],ans[N];
bool vis[N];
void addedge(int from,int to){
	a[++tot].to=to;
	a[tot].pre=head[from];
	head[from]=tot;
}
int dfs(int u,int fa)
{
	vis[u]=1;
	for(int i=head[u];i>0;i=a[i].pre)
	{
		int v=a[i].to;
		if(v==fa) continue;
		if(b[v]!=b[u]) return 1;
		else{
			ans[v]=dfs(v,u);
			return ans[v]+1;
		}
	}
	return -1;
}
int main()
{
	scanf("%d",&n);
	memset(head,-1,sizeof(head));
	memset(ans,-1,sizeof(ans));
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&b[i]);
		if(i-b[i]>=1&&i-b[i]<=n){
			addedge(i,i-b[i]);
		}
		if(i+b[i]>=1&&i+b[i]<=n){
			addedge(i,i+b[i]);
		}
		b[i]%=2;
	}
	for(int i=1;i<=n;++i)
	{
		if(!vis[i]){
			ans[i]=dfs(i,-1);
		}
	}
	printf("%d",ans[1]);
	for(int i=2;i<=n;++i) printf(" %d",ans[i]);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#define N 500010
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
struct node{
	int pre,to;
}a[N];
int n,tot;
int b[N],head[N],ans[N];
bool vis[N];
void addedge(int from,int to){
	a[++tot].to=to;
	a[tot].pre=head[from];
	head[from]=tot;
}
void dfs(int u,int fa,int step)
{
	vis[u]=1;
	for(int i=head[u];i>0;i=a[i].pre)
	{
		int v=a[i].to;
		if(v==fa) continue;
		if(b[v]!=b[u]){
			ans[u]=1;
			return ;
		}
		else{
			dfs(v,u,step+1);
			if(ans[v]!=inf){
				ans[u]=min(ans[u],ans[v]+1);
			}
		}
	}
}
int main()
{
	scanf("%d",&n);
	memset(head,-1,sizeof(head));
	for(int i=1;i<=n;++i) ans[i]=inf;
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&b[i]);
		if(i-b[i]>=1&&i-b[i]<=n){
			addedge(i,i-b[i]);
		}
		if(i+b[i]>=1&&i+b[i]<=n){
			addedge(i,i+b[i]);
		}
		b[i]%=2;
	}
	for(int i=1;i<=n;++i)
	{
		if(!vis[i]){
			dfs(i,-1,1);
		}
	}
	printf("%d",ans[1]==inf?-1:ans[1]);
	for(int i=2;i<=n;++i) printf(" %d",ans[i]==inf?-1:ans[i]);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#define N 500010
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
struct node{
	int pre,to;
}a[N];
int n,tot;
int b[N],head[N],ans[N];
bool vis[N];
void addedge(int from,int to){
	a[++tot].to=to;
	a[tot].pre=head[from];
	head[from]=tot;
}
void dfs(int u,int fa)
{
	vis[u]=1;
	for(int i=head[u];i>0;i=a[i].pre)
	{
		int v=a[i].to;
		if(v==fa) continue;
		if(!vis[v])dfs(v,u);
		if(b[v]!=b[u]){
			ans[u]=1;
		}
		else {
			if(ans[v]!=inf) ans[u]=min(ans[u],ans[v]+1);
		}
	}
}
int main()
{
	scanf("%d",&n);
	memset(head,-1,sizeof(head));
	for(int i=1;i<=n;++i) ans[i]=inf;
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&b[i]);
		if(i-b[i]>=1&&i-b[i]<=n){
			addedge(i,i-b[i]);
		}
		if(i+b[i]>=1&&i+b[i]<=n){
			addedge(i,i+b[i]);
		}
		b[i]%=2;
	}
	for(int i=1;i<=n;++i)
	{
		if(!vis[i]){
			dfs(i,-1);
		}
	}
	printf("%d",ans[1]==inf?-1:ans[1]);
	for(int i=2;i<=n;++i) printf(" %d",ans[i]==inf?-1:ans[i]);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#define N 500010
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
struct node{
	int pre,to;
}a[N];
int n,tot;
int b[N],head[N],ans[N];
bool vis[N];
void addedge(int from,int to){
	a[++tot].to=to;
	a[tot].pre=head[from];
	head[from]=tot;
}
void dfs(int u,int fa)
{
	vis[u]=1;
	for(int i=head[u];i>0;i=a[i].pre)
	{
		int v=a[i].to;
		if(v==fa) continue;
		if(b[v]!=b[u]){
			ans[u]=1;
		}
		else {
			if(!vis[v])dfs(v,u);
			if(ans[v]!=inf) ans[u]=min(ans[u],ans[v]+1);
		}
	}
}
int main()
{
	scanf("%d",&n);
	memset(head,-1,sizeof(head));
	for(int i=1;i<=n;++i) ans[i]=inf;
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&b[i]);
		if(i-b[i]>=1&&i-b[i]<=n){
			addedge(i,i-b[i]);
		}
		if(i+b[i]>=1&&i+b[i]<=n){
			addedge(i,i+b[i]);
		}
		b[i]%=2;
	}
	for(int i=1;i<=n;++i)
	{
		if(!vis[i]){
			dfs(i,-1);
		}
	}
	printf("%d",ans[1]==inf?-1:ans[1]);
	for(int i=2;i<=n;++i) printf(" %d",ans[i]==inf?-1:ans[i]);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#define N 500010
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
struct node{
	int pre,to;
}a[N];
int n,tot;
int b[N],head[N],ans[N];
bool vis[N];
void addedge(int from,int to){
	a[++tot].to=to;
	a[tot].pre=head[from];
	head[from]=tot;
}
void dfs(int u,int fa,int step)
{
	vis[u]=1;
	for(int i=head[u];i>0;i=a[i].pre)
	{
		int v=a[i].to;
		if(v==fa) continue;
		if(b[v]!=b[u]){
			ans[u]=1;
		}
	}
	if(ans[u]==inf){
		for(int i=head[u];i>0;i=a[i].pre)
		{
			int v=a[i].to;
			if(v==fa) continue;
			dfs(v,u,step+1);
			if(ans[v]!=inf){
				ans[u]=min(ans[u],ans[v]+1);
			}
		}
	}
}
int main()
{
	scanf("%d",&n);
	memset(head,-1,sizeof(head));
	for(int i=1;i<=n;++i) ans[i]=inf;
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&b[i]);
		if(i-b[i]>=1&&i-b[i]<=n){
			addedge(i,i-b[i]);
		}
		if(i+b[i]>=1&&i+b[i]<=n){
			addedge(i,i+b[i]);
		}
		b[i]%=2;
	}
	for(int i=1;i<=n;++i)
	{
		if(!vis[i]){
			dfs(i,-1,1);
		}
	}
	printf("%d",ans[1]==inf?-1:ans[1]);
	for(int i=2;i<=n;++i) printf(" %d",ans[i]==inf?-1:ans[i]);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#define N 500010
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
struct node{
	int pre,to;
}a[N];
int n,tot;
int b[N],head[N],ans[N];
bool vis[N];
void addedge(int from,int to){
	a[++tot].to=to;
	a[tot].pre=head[from];
	head[from]=tot;
}
int dfs(int u,int fa)
{
	vis[u]=1;
	for(int i=head[u];i>0;i=a[i].pre)
	{
		int v=a[i].to;
		if(v==fa) continue;
		if(b[v]!=b[u]) return 1;
		else{
			ans[v]=dfs(v,u);
			return ans[v]==-1?-1:ans[v]+1;
		}
	}
	return -1;
}
int main()
{
	scanf("%d",&n);
	memset(head,-1,sizeof(head));
	memset(ans,-1,sizeof(ans));
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&b[i]);
		if(i-b[i]>=1&&i-b[i]<=n){
			addedge(i,i-b[i]);
		}
		if(i+b[i]>=1&&i+b[i]<=n){
			addedge(i,i+b[i]);
		}
		b[i]%=2;
	}
	for(int i=1;i<=n;++i)
	{
		if(!vis[i]){
			ans[i]=dfs(i,-1);
		}
	}
	printf("%d",ans[1]);
	for(int i=2;i<=n;++i) printf(" %d",ans[i]);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#define N 500010
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
struct node{
	int pre,to;
}a[N];
int n,tot;
int b[N],head[N],ans[N];
bool vis[N];
void addedge(int from,int to){
	a[++tot].to=to;
	a[tot].pre=head[from];
	head[from]=tot;
}
int dfs(int u,int fa)
{
	vis[u]=1;
	for(int i=head[u];i>0;i=a[i].pre)
	{
		int v=a[i].to;
		if(v==fa) continue;
		if(b[v]!=b[u]){
			ans[v]=dfs(v,u);
			return 1;
		}
		else{
			ans[v]=dfs(v,u);
			return ans[v]==-1?-1:ans[v]+1;
		}
	}
	return -1;
}
int main()
{
	scanf("%d",&n);
	memset(head,-1,sizeof(head));
	memset(ans,-1,sizeof(ans));
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&b[i]);
		if(i-b[i]>=1&&i-b[i]<=n){
			addedge(i,i-b[i]);
		}
		if(i+b[i]>=1&&i+b[i]<=n){
			addedge(i,i+b[i]);
		}
		b[i]%=2;
	}
	for(int i=1;i<=n;++i)
	{
		if(!vis[i]){
			ans[i]=dfs(i,-1);
		}
	}
	printf("%d",ans[1]);
	for(int i=2;i<=n;++i) printf(" %d",ans[i]);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#define N 500010
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
struct node{
	int pre,to;
}a[N];
int n,tot;
int b[N],head[N],ans[N];
bool vis[N];
void addedge(int from,int to){
	a[++tot].to=to;
	a[tot].pre=head[from];
	head[from]=tot;
}
void dfs(int u,int fa,int step)
{
	vis[u]=1;
	for(int i=head[u];i>0;i=a[i].pre)
	{
		int v=a[i].to;
		if(v==fa) continue;
		if(b[v]!=b[u]){
			ans[u]=1;
		}
		else {
			dfs(v,u,step+1);
			if(ans[v]!=inf) ans[u]=min(ans[u],ans[v]+1);
		}
	}
}
int main()
{
	scanf("%d",&n);
	memset(head,-1,sizeof(head));
	for(int i=1;i<=n;++i) ans[i]=inf;
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&b[i]);
		if(i-b[i]>=1&&i-b[i]<=n){
			addedge(i,i-b[i]);
		}
		if(i+b[i]>=1&&i+b[i]<=n){
			addedge(i,i+b[i]);
		}
		b[i]%=2;
	}
	for(int i=1;i<=n;++i)
	{
		if(!vis[i]){
			dfs(i,-1,1);
		}
	}
	printf("%d",ans[1]==inf?-1:ans[1]);
	for(int i=2;i<=n;++i) printf(" %d",ans[i]==inf?-1:ans[i]);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<queue>
#define N 500010
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
struct node{
	int pre,to;
}a[N];
int n,tot;
int b[N],head[N],ans[N];
bool vis[N];
queue<int> que;
void addedge(int from,int to){
	a[++tot].to=to;
	a[tot].pre=head[from];
	head[from]=tot;
}
void bfs()
{

	while(!que.empty())
	{
		int u=que.front();
		que.pop();
		if(vis[u]) continue;
		vis[u]=1;
		for(int i=head[u];i>0;i=a[i].pre)
		{
			int v=a[i].to;
			if(v==-1) continue;
			if(b[v]!=b[u]){
				ans[v]=1;
			}
			else{
				ans[v]=min(ans[v],ans[u]+1);
			}
			que.push(v);
		}
	}
}
int main()
{
	scanf("%d",&n);
	memset(head,-1,sizeof(head));
	for(int i=1;i<=n;++i) ans[i]=inf;
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&b[i]);
		if(i-b[i]>=1&&i-b[i]<=n){
			addedge(i-b[i],i);
		}
		if(i+b[i]>=1&&i+b[i]<=n){
			addedge(i+b[i],i);
		}
		b[i]%=2;
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=head[i];j>0;j=a[j].pre)
		{
			int v=a[j].to;
			if(v==-1) continue;
			if(b[v]!=b[i]){
				que.push(v);
				ans[v]=1;
			}
		}
	}
	bfs();
	printf("%d",ans[1]==inf?-1:ans[1]);
	for(int i=2;i<=n;++i) printf(" %d",ans[i]==inf?-1:ans[i]);
	return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,r,l) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const ll INF = LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MAXN = 2e5+20;
const double EPS= 1e-10;

int n;
vector<int> g[MAXN];
bool seen[MAXN];
int dp[MAXN], arr[MAXN];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<< setprecision(2)<< fixed;
    cin>>n;

    forn(i,n){
        cin>> arr[i];
        dp[i]=INT_MAX;

        if(i+arr[i]<=n-1){
            g[i+arr[i]].pb(i);
        }
        if(i-arr[i]>=0){
            g[i-arr[i]].pb(i);
        }
    }
    queue<ii> q;
    forn(i,n){
        if(arr[i]%2==0){
            q.push(ii(i,0));
        }
    }
    while(!q.empty()){
        int u= q.front().fi;
        int d= q.front().se;
        q.pop();
        seen[u]=true;
        forn(i,g[u].size()){
            int v= g[u][i];
            if(arr[v]%2==1){
                dp[v]= min(dp[v], d+1);
            }
            if(!seen[v]){
                q.push(ii(v,d+1));
            }
        }
    }
    memset(seen, false, sizeof seen);
    forn(i,n){
        if(arr[i]%2==1){
            q.push(ii(i,0));
        }
    }
    while(!q.empty()){
        int u= q.front().fi;
        int d= q.front().se;
        q.pop();
        seen[u]=true;
        forn(i,g[u].size()){
            int v= g[u][i];
            if(arr[v]%2==0){
                dp[v]= min(dp[v], d+1);
            }
            if(!seen[v]){
                q.push(ii(v,d+1));
            }
        }
    }
    forn(i,n){
        cout<< (dp[i] == INT_MAX ? -1 : dp[i]) << " ";
    }
    cout<<el;
}


def find(arr1,elem,i):
	if(arr1[i][0] == elem):
		return i
	else:
		return find(arr1,elem,arr1[i][0])
[n,k] = map(int,input().split())

p = list(map(int,input().split()))
c =  list(map(int,input().split()))
arr = []
arr1 = []
for i in range(n):
	arr.append((i,-1*p[i],c[i]))
	arr1.append((i,-1*c[i]))

fin = []
arr.sort(key = lambda x: x[1])
arr1.sort(key = lambda x : x[1])
for i in range(n):
	fin.append([arr[i][0],arr[i][2]])
	p = find(arr1,arr[i][0],arr[i][0])
	del arr1[p]

	for j in range(k):
		if(j + i + 1< n):
			fin[i][1] += -1*arr1[j][1]
		else:
			break
fin.sort()
for i in range(n):
	print(fin[i][1],end = " ")


def find(arr1,elem,i,j):
	mid = int((i+j)/2)
	if(i > j ):
		return -1
	if(arr1[mid][1] == -1*elem[2]):
		if(arr1[mid][0] == elem[0]):
			return mid
		else:
			t = 1
			while(True):
				if(mid - t > 0):
					if(arr1[mid-t][0] == elem[0]):
						return mid - t
				if(mid + t < n):
					if(arr1[mid+t][0] == elem[0]):
						return mid+t

				t += 1
	elif(-1*arr1[mid][1] > elem[2]):
		i = mid+1
		return find(arr1,elem,i,j)
	elif(-1*arr1[mid][1] < elem[2]):
		j = mid - 1
		return find(arr1,elem,i,j)

[n,k] = map(int,input().split())

p = list(map(int,input().split()))
c =  list(map(int,input().split()))
arr = []
arr1 = []
for i in range(n):
	arr.append((i,-1*p[i],c[i]))
	arr1.append((i,-1*c[i]))

fin = []
var = [True]*n
arr.sort(key = lambda x: x[1])
arr1.sort(key = lambda x : x[1])
for i in range(n):
	fin.append([arr[i][0],arr[i][2]])
	p = find(arr1,arr[i],0,len(arr1))
	del arr1[p]
	for j in range(k):
		if(j + i + 1< n):
			fin[i][1] += -1*arr1[j][1]
		else:
			break
fin.sort()
for i in range(n):
	print(fin[i][1],end = " ")


import heapq
[n,k] = map(int,input().split())

p = list(map(int,input().split()))
c =  list(map(int,input().split()))
arr = []
arr1 = []
for i in range(n):
	arr.append((i,-1*p[i],c[i]))
	arr1.append((i,-1*c[i]))

fin = []
arr.sort(key = lambda x: x[1])
arr1.sort(key = lambda x : x[1])
for i in range(n):
	fin.append([arr[i][0],arr[i][2]])
	arr1.remove((arr[i][0],-1*arr[i][2]))
	for j in range(k):
		if(j + i + 1< n):
			fin[i][1] += -1*arr1[j][1]
		else:
			break
fin.sort()
for i in range(n):
	print(fin[i][1],end = " ")


def find(arr1,elem,i,j):
	mid = int((i+j)/2)
	if(i > j ):
		return -1
	if(arr1[mid][1] == -1*elem[2]):
		if(arr1[mid][0] == elem[0]):
			return mid
		else:
			t = 1
			while(True):
				if(mid - t > 0):
					if(arr1[mid-t][0] == elem[0]):
						return mid - t
				if(mid + t < n):
					if(arr1[mid+t][0] == elem[0]):
						return mid+t

				t += 1
	elif(-1*arr1[mid][1] > elem[2]):
		i = mid+1
		return find(arr1,elem,i,j)
	elif(-1*arr1[mid][1] < elem[2]):
		j = mid - 1
		return find(arr1,elem,i,j)

[n,k] = map(int,input().split())

p = list(map(int,input().split()))
c =  list(map(int,input().split()))
arr = []
arr1 = []
for i in range(n):
	arr.append((i,-1*p[i],c[i]))
	arr1.append((i,-1*c[i]))

fin = []
var = [True]*n
arr.sort(key = lambda x: x[1])
arr1.sort(key = lambda x : x[1])
for i in range(n):
	fin.append([arr[i][0],arr[i][2]])
	p = find(arr1,arr[i],0,len(arr1))
	arr1 = arr1[:p]+arr1[p+1:]
	for j in range(k):
		if(j + i + 1< n):
			fin[i][1] += -1*arr1[j][1]
		else:
			break
fin.sort()
for i in range(n):
	print(fin[i][1],end = " ")


import heapq
[n,k] = map(int,input().split())

p = list(map(int,input().split()))
c =  list(map(int,input().split()))
arr = []

for i in range(n):
	arr.append((i,p[i],c[i]))

fin = []
arr.sort(key = lambda x: x[1])
heap = []
for i in range(n):
	fin.append([arr[i][0],arr[i][2]])
	if(i <= k ):
		heapq.heappush(heap,arr[i][2])
	else:
		heapq.heappop(heap)
		heapq.heappush(heap,arr[i][2])
	fin[i][1] = sum(heap)
fin.sort()
for i in range(n):
	print(fin[i][1],end = " ")


[n,k] = map(int,input().split())
p = list(map(int,input().split()))
c =  list(map(int,input().split()))
arr = []

for i in range(n):
	arr.append((i,-1*p[i],c[i]))
fin = []
arr.sort(key = lambda x: x[1])
for i in range(n):
	fin.append([arr[i][0],arr[i][2]])
	for j in range(k):
		if(j + i + 1< n):
			fin[i][1] += arr[i+1+j][2]
		else:
			break
fin.sort()
for i in range(n):
	print(fin[i][1],end = " ")


# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

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

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

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

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

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------
from math import gcd, ceil

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

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

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

def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

from heapq import heappop, heappush

for _ in range(int(input()) if not True else 1):
    n, k = map(int, input().split())
    #a, b = map(int, input().split())
    #c, d = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    if not k:
        print(*b)
        continue

    vals = []

    for i in range(n):
        vals+=[(i, a[i], b[i])]
    vals = sorted(vals, key=lambda k:k[1])
    ans=[]
    queue = []
    for i in range(n):
        ans += [[vals[0], vals[2]]]
        if i <= k:
            heappush(queue, vals[i][2])
            ans[i][1] = sum(queue)
        else:
            heappop(queue)
            heappush(queue, vals[i][2])
            ans[i][1] = sum(queue)

    print(*[k[1] for k in sorted(ans)])


# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

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

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

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

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

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------
from math import gcd, ceil

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

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

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

def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

from heapq import heappop, heappush

for _ in range(int(input()) if not True else 1):
    n, k = map(int, input().split())
    #a, b = map(int, input().split())
    #c, d = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    if not k:
        print(*b)
        continue

    vals = []

    for i in range(n):
        vals+=[(i, a[i], b[i])]
    vals = sorted(vals, key=lambda k:k[1])
    ans=[]
    queue = []
    for i in range(n):
        ans += [[vals[i][0], vals[i][2]]]
        if i <= k:
            heappush(queue, vals[i][2])
            ans[i][1] = sum(queue)
        else:
            heappop(queue)
            heappush(queue, vals[i][2])
            ans[i][1] = sum(queue)
    #print(ans)
    print(*[k[1] for k in sorted(ans,key=lambda k:k[0])])


def main():
	n, k = map(int, input().split())
	power = list(map(int, input().split()))
	coins = list(map(int, input().split()))
	result = coins.copy()
	coins_power = tuple(zip(*sorted(zip(coins, power))))
	coinsi = []
	last = coins_power[0][0]
	start = 0
	for i in range(1, n):
		c = coins_power[0][i]
		if c != last:

			coinsi.append((coins_power[0][start], coins_power[1][start:i]))
			start = i
		last = c
	coinsi.append((coins_power[0][start], coins_power[1][start:]))

	for i in range(n):
		ki = k
		pi = power[i]
		j = len(coinsi)-1
		while ki > 0 and j > -1:
			c, ps = coinsi[j]
			left = 0
			right = len(ps)

			while left < right:
				mid = (left + right) // 2
				if ps[mid] >= pi:
					right = mid
				else:
					left = mid + 1

			if ps[mid] < pi:
				mid += 1
			result[i] += mid*c
			ki -= mid
			if ki < 0:
				result[i] += -ki*c
			j -= 1
	print(' '.join(map(str,result)))

main()


import heapq

def main():
	n, k = map(int, input().split())
	power = list(map(int, input().split()))
	coins = list(map(int, input().split()))

	power_coins = sorted(zip(power, coins))
	result = {power[i]:coins[i] for i in range(n)}
	kills = 0
	coins = 0
	min_heap = []
	for p, c in power_coins:
		result[p] += coins
		if kills < k:
			kills += 1
			heapq.heappush(min_heap, c)
			coins += c
		elif k > 0:
			if c > min_heap[0]:
				coins -= min_heap[0]
				coins += c
				heapq.heapreplace(min_heap, c)
	print(' '.join(str(result[p]) for p in power))

main()


def main():
	n, k = map(int, input().split())
	power = list(map(int, input().split()))
	coins = list(map(int, input().split()))
	result = coins.copy()
	coins_power = tuple(zip(*sorted(zip(coins, power))))
	coinsi= []
	last = coins_power[0][0]
	start = 0
	for i in range(1, n):
		c = coins_power[0][i]
		if c != last:

			coinsi.append((coins_power[0][start], coins_power[1][start:i]))
			start = i
		last = c
	coinsi.append((coins_power[0][start], coins_power[1][start:]))

	for i in range(n):
		ki = k
		pi = power[i]
		j = len(coinsi)-1
		while ki > 0 and j > -1:
			c, ps = coinsi[j]
			left = 0
			right = len(ps)

			while left < right:
				mid = (left + right) // 2
				if ps[mid] >= pi:
					right = mid
				else:
					left = mid + 1

			if ps[mid] < pi:
				mid += 1
			result[i] += mid*c
			ki -= mid
			j -= 1
	print(' '.join(map(str,result)))

main()


def main():
	n, k = map(int, input().split())
	power = list(map(int, input().split()))
	coins = list(map(int, input().split()))
	result = coins.copy()
	coins_power = tuple(zip(*sorted(zip(coins, power))))
	coinsi = []
	last = coins_power[0][0]
	start = 0
	for i in range(1, n):
		c = coins_power[0][i]
		if c != last:

			coinsi.append((coins_power[0][start], coins_power[1][start:i]))
			start = i
		last = c
	coinsi.append((coins_power[0][start], coins_power[1][start:]))

	for i in range(n):
		ki = k
		pi = power[i]
		j = len(coinsi)-1
		while ki > 0 and j > -1:
			c, ps = coinsi[j]
			left = 0
			right = len(ps)

			while left < right:
				mid = (left + right) // 2
				if ps[mid] >= pi:
					right = mid
				else:
					left = mid + 1

			if ps[mid] < pi:
				mid += 1
			result[i] += mid*c
			ki -= mid
			if ki < 0:
				result[i] += ki*c
			j -= 1
	print(' '.join(map(str,result)))

main()


n,k=map(int,input().split())
p=list(map(int,input().split()))
pcop=p.copy()
c=list(map(int,input().split()))
dic=dict(zip(p,c))
p.sort()
li=[]
dic1={}
for i in range(min(k,n)):
    li.append(dic[p[i]])
    dic1[p[i]]=sum(li)
if(n>k and len(li)!=0):
    for i in p[k:]:
        li.sort()
        dic1[i]=sum(li)+dic[i]
        if(li[0]<dic[i]):
            del li[0]
            li.append(dic[i])
else:
    for i in p[k:]:
        dic1[i]=dic[i]
for m in range(n):
    print(dic1[pcop[m]],end=' ')


import sys
n,m=list(map(int,input().split()))
s=list(map(int,input().split()))
s1=list(map(int,input().split()))
c=[]
if m==0:
    for i in s1:
        print(i,end=" ")
    sys.exit()
for i in range(n):
    c.append([s[i]]+[s1[i]]+[i])
c.sort()
ans=[-1 for i in range(n)]
dp=[c[i][1] for i in range(n)]
dp[0]=c[0][1]
ans[c[0][2]]=dp[0]
mx=[]
dpp=0
for i in range(n):
    dp[i]+=dpp
    if len(mx)<m :
        mx.append(c[i][1])
        dpp+=c[i][1]
    else:
        mx.sort()
        if mx[0]<c[i][1]:
            dpp+=c[i][1]-mx[0]
            mx=mx[1::]+[c[i][1]]
    ans[c[i][2]]=dp[i]
    if m==0:
        ans[c[i][2]]=c[i][1]

for i in ans:
    print(i,end=" ")


__file__ = __file__.startswith('/home/a_farazei')

def input_():
    global __file__

    if not __file__:
        return input()

    if not hasattr(__file__, 'readline'):
        __file__ = open('input.txt', 'r')

    return __file__.readline()

n, k = map(int, input_().split())
p_ = list(map(int, input_().split()))
c_ = list(map(int, input_().split()))

d = [0] * n
t = []
pp = -1
tj = 0
q = sorted(zip(range(n), p_, c_), key=lambda x: x[1])

for i, x in enumerate(q):
    if x[1] > pp:
        t.extend(q[max(i - j - 1, 0)][2] for j in range(tj))
        tj = 0
        pp = x[1]
    t = sorted(t, reverse=True)[:k]
    d[x[0]] = sum(t) + x[2]
    tj += 1

print(' '.join(map(str, d)))


__file__ = __file__.startswith('/home/a_farazei')

def input_():
    global __file__

    if not __file__:
        return input()

    if not hasattr(__file__, 'readline'):
        __file__ = open('input.txt', 'r')

    return __file__.readline()

n, k = map(int, input_().split())
p_ = list(map(int, input_().split()))
c_ = list(map(int, input_().split()))

d = [0] * n
t = []
pp = -1
tj = 0
q = sorted(zip(range(n), p_, c_), key=lambda x: x[1])

for i, x in enumerate(q):
    if x[1] > pp:
        t.extend(q[max(i - j - 1, 0)][2] for j in range(tj))
        tj = 0
        pp = x[1]
    t = sorted(t, reverse=True)[:k]
    d[x[0]] = sum(nlargest(k, t)) + x[2]
    tj += 1

print(' '.join(map(str, d)))


__file__ = __file__.startswith('/home/a_farazei')

def input_():
    global __file__

    if not __file__:
        return input()

    if not hasattr(__file__, 'readline'):
        __file__ = open('input.txt', 'r')

    return __file__.readline()

from heapq import *

n, k = map(int, input_().split())
p_ = list(map(int, input_().split()))
c_ = list(map(int, input_().split()))

d = [0] * n
t = []
pp = -1
tc = []
q = sorted(zip(range(n), p_, c_), key=lambda x: x[1])

for x in q:
    if x[1] > pp:
        for z in tc:
            heappush(t, z)
        tc = []
        pp = x[1]

    tc.append(x[2])
    d[x[0]] = sum(nlargest(k, t)) + x[2]

print(' '.join(map(str, d)))


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    n,m = LI()
    a = LI()
    b = LI()
    c = []
    if m == 0:
        return ' '.join(map(str, b))
    for i in range(n):
        c.append((a[i],b[i],i))
    c.sort()
    t = []
    rr = {}
    for d,e,i in c:
        tr = e
        tr += sum(t)
        rr[i] = tr
        if len(t) < m:
            t.append(e)
        else:
            tm = min(t)
            if tm < e:
                tmi = t.index(tm)
                t[tmi] = e
    r = []
    for i in range(n):
        r.append(rr[i])
    return ' '.join(map(str,r))

print(main())


import heapq

if __name__ == '__main__':
    rd = lambda: map(int, input().split())
    n, k = rd()
    a = sorted(zip(rd(), rd(), range(n)))

    minH = []
    total = 0
    ans = [0] * n
    for i in range(len(a)):
        if len(minH) >= k + 1:
            (coins, index) = heapq.heappop(minH)
            total -= coins

        heapq.heappush(minH, (a[i][1], i))

        total += a[i][1]
        ans[a[i][2]] = total

    print(*ans)


n,k=map(int,input().split())
power=list(map(int,input().split()))
coins=list(map(int,input().split()))
arr=[]
for i in range(n):
    arr.append([power[i],coins[i],i])
arr.sort()
d=[]
summ=0
ans=[]
if k==0:
    for i in coins:
        print(i,end=" ")
else:
    for i in range(n):
        #print(d,summ)
        ans.append([arr[i][2],arr[i][1]+summ])
        if len(d)<k:
            d.insert(0,arr[i][1])
            summ+=arr[i][1]
        else:
            if d[0]>=arr[i][1]:
                continue
            if d[k-1]<=arr[i][1]:
                d.insert(0,arr[i][1])
                summ+=d[0]-d[len(d)-1]
                del d[len(d)-1]
    ans.sort()
    for i in ans:
        print(i[1],end=" ")


n,k=map(int,input().split())
power=list(map(int,input().split()))
coins=list(map(int,input().split()))
arr=[]
for i in range(n):
    arr.append([power[i],coins[i],i])
arr.sort()
d=[]
summ=0
ans=[]
if k==0:
    for i in coins:
        print(i,end=" ")
else:
    for i in range(n):
        #print(d,summ)
        ans.append([arr[i][2],arr[i][1]+summ])
        if len(d)<k:
            d.insert(0,arr[i][1])
            d.sort(reverse=True)
            summ+=arr[i][1]
        else:
            if d[len(d)-1]>=arr[i][1]:
                continue
            if d[0]<=arr[i][1]:
                d.insert(0,arr[i][1])
                summ+=d[0]-d[len(d)-1]
                del d[len(d)-1]
            else:
                d.insert(0,arr[i][1])
                summ+=d[0]-d[len(d)-1]
                del d[len(d)-1]
                d.sort(reverse=True)

    ans.sort()
    for i in ans:
        print(i[1],end=" ")


n,k=map(int,input().split())
power=list(map(int,input().split()))
coins=list(map(int,input().split()))
arr=[]
for i in range(n):
    arr.append([power[i],coins[i],i])
arr.sort()
d=[]
summ=0
ans=[]
if k==0:
    for i in coins:
        print(i,end=" ")
else:
    for i in range(n):
        print(d,summ)
        ans.append([arr[i][2],arr[i][1]+summ])
        if len(d)<k:
            d.insert(0,arr[i][1])
            summ+=arr[i][1]
        else:
            if d[0]>=arr[i][1]:
                continue
            if d[k-1]<=arr[i][1]:
                d.insert(0,arr[i][1])
                summ+=d[0]-d[len(d)-1]
                del d[len(d)-1]
    ans.sort()
    for i in ans:
        print(i[1],end=" ")