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

#define ll int
#define pb push_back
#define mp make_pair
#define ld long double

const int MAXN = 200005;

ll dp[MAXN][2], a[MAXN], n, f = 0;
vector<ll>temp[2];
bool vis[MAXN][2];

ll func(ll ft, ll start, ll state)
{
	if(vis[start][state])
	{
		f = -1;
		return dp[start][state] = -1;
	}
	vis[start][state] = true;
	temp[state].pb(start);
	if(dp[start][state] != -1) return dp[start][state];
	else
	{
		if(state == 0)
		{
			if(start + a[start] <= n)
			{
				ll g = func(ft, start + a[start], state ^ 1);
				if(g == -1)
					return dp[start][state] = -1;
				else
					return dp[start][state] = a[start] + g;
			}
			else
			{
				return dp[start][state] = a[start];
			}
		}
		else
		{
			if(start - a[start] <= 0)
			{
				return dp[start][state] = a[start];
			}
			else
			{
				ll g = func(ft, start - a[start], state ^ 1);
				if(g == -1)
					return dp[start][state] = -1;
				else
					return dp[start][state] = a[start] + g;
			}
		}
	}
}

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

    cin>>n;
    for(int i=0;i<n-1;i++)  cin>>a[i+2];
    memset(dp, -1, sizeof(dp));
	for(int i=1;i<n;i++)
	{
		f = 0;
		a[1] = i;
		ll g = func(i, 1, 0);
		if(f == -1) cout << -1 << endl;
		else
			cout << g << endl;
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<temp[i].size();j++)
			{
				vis[temp[i][j]][i] = false;
			}
		}
		temp[0].clear();
		temp[1].clear();
		dp[1][0] = dp[1][1] = -1;
	}
    return 0;
}


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

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double

const int MAXN = 200005;

ll dp[MAXN], a[MAXN], n, f = 0;
vector<ll>temp, temp2;
bool vis[MAXN], vis2[MAXN];

ll tfunc(ll x)
{
	return x + a[x];
}
ll func(ll ft, ll start)
{
	if(vis[start])
	{
		f = -1;
		return dp[start] = -1;
	}
	if(tfunc(start) <= n && vis2[tfunc(start)])
	{
		f = -1;
		return dp[start] = -1;
	}
	if(tfunc(start) <= n)
	{
		vis2[tfunc(start)] = true;
		temp2.pb(tfunc(start));
	}
	vis[start] = true;
	temp.pb(start);
	// cout << start << " " << tfunc(start) << endl;
	if(dp[start] != -1) return dp[start];
	else
	{
		if(tfunc(start) <= n && tfunc(start) - a[tfunc(start)] > 0)
		{
			ll k = a[start] + a[tfunc(start)] + func(ft, tfunc(start) - a[tfunc(start)]);
			if(f == -1)
				return dp[start] = -1;
			else
				return dp[start] = k;
		}
		else if(tfunc(start) <= n && tfunc(start) - a[tfunc(start)] <= 0)
		{
			ll k = a[start] + a[tfunc(start)];
			if(f == -1)
				return dp[start] = -1;
			else
				return dp[start] = k;
		}
		else
		{
			ll k = a[start];
			if(f == -1)
				return dp[start] = -1;
			else
				return dp[start] = k;
		}
	}
}

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

    cin>>n;
    for(int i=0;i<n-1;i++)  cin>>a[i+2];
    memset(dp, -1, sizeof(dp));
	for(int i=1;i<n;i++)
	{
		f = 0;
		a[1] = i;
		ll g = func(i, 1);
		if(f == -1) cout << f << endl;
		else
			cout << g << endl;
		for(int j=0;j<temp.size();j++)
		{
			vis[temp[j]] = false;
		}
		temp.clear();
		for(int j=0;j<temp2.size();j++)
		{
			vis2[temp2[j]] = false;
		}
		temp2.clear();
		dp[1] = -1;
	}
    return 0;
}


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

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double

const int MAXN = 200005;

ll dp[MAXN], a[MAXN], n, f = 0;
vector<ll>temp, temp2;
bool vis[MAXN], vis2[MAXN];

ll tfunc(ll x)
{
	return x + a[x];
}
ll func(ll ft, ll start)
{
	if(vis[start])
	{
		f = -1;
		return 0;
	}
	if(tfunc(start) <= n && vis2[tfunc(start)])
	{
		f = -1;
		return 0;
	}
	if(tfunc(start) <= n)
	{
		vis2[tfunc(start)] = true;
		temp2.pb(tfunc(start));
	}
	vis[start] = true;
	temp.pb(start);
	if(dp[start] != -1) return dp[start];
	else
	{
		if(tfunc(start) <= n && tfunc(start) - a[tfunc(start)] > 0)
			return dp[start] = a[start] + a[tfunc(start)] + func(ft, tfunc(start) - a[tfunc(start)]);
		else if(tfunc(start) <= n && tfunc(start) - a[tfunc(start)] <= 0)
			return dp[start] = a[start] + a[tfunc(start)];
		else
			return dp[start] = a[start];
	}
}

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

    cin>>n;
    for(int i=0;i<n-1;i++)  cin>>a[i+2];
    memset(dp, -1, sizeof(dp));
	for(int i=1;i<n;i++)
	{
		f = 0;
		a[1] = i;
		ll g = func(i, 1);
		if(f == -1) cout << f << endl;
		else
			cout << g << endl;
		for(int j=0;j<temp.size();j++)
		{
			vis[temp[j]] = false;
		}
		temp.clear();
		for(int j=0;j<temp2.size();j++)
		{
			vis2[temp2[j]] = false;
		}
		temp2.clear();
		dp[1] = -1;
	}
    return 0;
}


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

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double

const int MAXN = 200005;

ll dp[MAXN], a[MAXN], n, f = 0;
vector<ll>temp;
bool vis[MAXN];

ll tfunc(ll x)
{
	return x + a[x];
}
ll func(ll ft, ll start)
{
	// cout << start << endl;
	if(vis[start])
	{
		f = -1;
		return 0;
	}
	if(tfunc(start) <= n && vis[tfunc(start)])
	{
		f = -1;
		return 0;
	}
	if(tfunc(start) <= n)
	{
		vis[tfunc(start)] = true;
		temp.pb(tfunc(start));
	}
	vis[start] = true;
	temp.pb(start);
	if(dp[start] != -1) return dp[start];
	else
	{
		// cout << tfunc(start) << endl;
		if(tfunc(start) <= n && tfunc(start) - a[tfunc(start)] > 0)
			return dp[start] = a[start] + a[tfunc(start)] + func(ft, tfunc(start) - a[tfunc(start)]);
		else if(tfunc(start) <= n && tfunc(start) - a[tfunc(start)] <= 0)
			return dp[start] = a[start] + a[tfunc(start)];
		else
			return dp[start] = a[start];
	}
}

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

    cin>>n;
    for(int i=0;i<n-1;i++)  cin>>a[i+2];
    memset(dp, -1, sizeof(dp));
	for(int i=1;i<n;i++)
	{
		f = 0;
		a[1] = i;
		ll g = func(i, 1);
		if(f == -1) cout << f << endl;
		else
			cout << g << endl;
		for(int j=0;j<temp.size();j++)
		{
			vis[temp[j]] = false;
		}
		temp.clear();
		dp[1] = -1;
	}
    return 0;
}


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

#define ll int
#define pb push_back
#define mp make_pair
#define ld long double

const int MAXN = 210005;

ll dp[MAXN][2], a[MAXN], n, vis[MAXN][2];

ll func(ll start, ll state)
{
	if(start <= 0 || start > n)
	{
		return 0;
	}
	if(vis[start][state] == 1)
	{
		return -1;
	}
	if(vis[start][state] == 2) return dp[start][state];
	if(vis[start][state] == 0)
	{
		vis[start][state] = 1;
		if(state == 0)
		{
			ll g = func(start + a[start], state ^ 1);
			if(g == -1)
				dp[start][state] = -1;
			else
				dp[start][state] = a[start] + g;
		}
		else
		{
			ll g = func(start - a[start], state ^ 1);
			if(g == -1)
				dp[start][state] = -1;
			else
				dp[start][state] = a[start] + g;

		}
	}
	vis[start][state] = 2;
	return dp[start][state];
}

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

    cin>>n;
    for(int i=0;i<n-1;i++)  cin>>a[i+2];
	for(int i=1;i<n;i++)
	{
		a[1] = i;
		cout << func(1, 0) << endl;
		vis[1][0] = vis[1][1] = 0;
	}
    return 0;
}


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

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double

const int MAXN = 200005;

ll dp[MAXN], a[MAXN], n, f = 0;
vector<ll>temp;
bool vis[MAXN];

ll tfunc(ll x)
{
	return x + a[x];
}
ll func(ll ft, ll start)
{
	// cout << start << endl;
	if(vis[start])
	{
		f = -1;
		return 0;
	}
	if(vis[tfunc(start)])
	{
		f = -1;
		return 0;
	}
	vis[tfunc(start)] = true;
	vis[start] = true;
	temp.pb(start);
	if(dp[start] != -1) return dp[start];
	else
	{
		// cout << tfunc(start) << endl;
		if(tfunc(start) <= n && tfunc(start) - a[tfunc(start)] > 0)
			return dp[start] = a[start] + a[tfunc(start)] + func(ft, tfunc(start) - a[tfunc(start)]);
		else if(tfunc(start) <= n && tfunc(start) - a[tfunc(start)] <= 0)
			return dp[start] = a[start] + a[tfunc(start)];
		else
			return dp[start] = a[start];
	}
}

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

    cin>>n;
    for(int i=0;i<n-1;i++)  cin>>a[i+2];
    memset(dp, -1, sizeof(dp));
	for(int i=1;i<n;i++)
	{
		f = 0;
		a[1] = i;
		ll g = func(i, 1);
		if(f == -1) cout << f << endl;
		else
			cout << g << endl;
		for(int j=0;j<temp.size();j++)
		{
			vis[temp[j]] = false;
		}
		temp.clear();
		dp[1] = -1;
	}
    return 0;
}


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

#define ll int
#define pb push_back
#define mp make_pair
#define ld long double

const int MAXN = 200005;

ll dp[MAXN][2], a[MAXN], n, f = 0;
vector<ll>temp[2];
bool vis[MAXN][2];

ll func(ll ft, ll start, ll state)
{
	if(vis[start][state])
	{
		f = -1;
		return dp[start][state] = -1;
	}
	vis[start][state] = true;
	temp[state].pb(start);
	if(dp[start][state] != -1) return dp[start][state];
	else
	{
		if(state == 0)
		{
			if(start + a[start] <= n)
			{
				return dp[start][state] = a[start] + func(ft, start + a[start], state ^ 1);
			}
			else
			{
				return dp[start][state] = a[start];
			}
		}
		else
		{
			if(start - a[start] <= 0)
			{
				return dp[start][state] = a[start];
			}
			else
			{
				return dp[start][state] = a[start] + func(ft, start - a[start], state ^ 1);
			}
		}
	}
}

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

    cin>>n;
    for(int i=0;i<n-1;i++)  cin>>a[i+2];
    memset(dp, -1, sizeof(dp));
	for(int i=1;i<n;i++)
	{
		f = 0;
		a[1] = i;
		ll g = func(i, 1, 0);
		if(f == -1) cout << f << endl;
		else
			cout << g << endl;
		for(int j=0;j<temp[0].size();j++)
		{
			vis[temp[j][0]][0] = false;
		}
		for(int j=0;j<temp[1].size();j++)
		{
			vis[temp[j][1]][1] = false;
		}
		temp[0].clear();
		temp[1].clear();
		dp[1][0] = dp[1][1] = -1;
	}
    return 0;
}


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

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double

const int MAXN = 210005;

ll dp[MAXN][2], a[MAXN], n, vis[MAXN][2];

ll func(ll start, ll state)
{
	if(start <= 0 || start > n)
	{
		return 0;
	}
	if(vis[start][state] == 1)
	{
		return -1;
	}
	if(vis[start][state] == 2) return dp[start][state];
	if(vis[start][state] == 0)
	{
		vis[start][state] = 1;
		if(state == 0)
		{
			ll g = func(start + a[start], state ^ 1);
			if(g == -1)
				dp[start][state] = -1;
			else
				dp[start][state] = a[start] + g;
		}
		else
		{
			ll g = func(start - a[start], state ^ 1);
			if(g == -1)
				dp[start][state] = -1;
			else
				dp[start][state] = a[start] + g;

		}
	}
	vis[start][state] = 2;
	return dp[start][state];
}

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

    cin>>n;
    for(int i=0;i<n-1;i++)  cin>>a[i+2];
	for(int i=1;i<n;i++)
	{
		a[1] = i;
		cout << func(1, 0) << endl;
		vis[1][0] = vis[1][1] = 0;
	}
    return 0;
}


#pragma GCC optimize("O3")

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define mset(m,v) memset(m,v,sizeof(m))
#define pr(a,s) printf("Case #%lld: %lld\n",a,s)
// #define mod 1000000007
#define mp make_pair
#define pb push_back
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define all(x) x.begin(),x.end()
#define se second
#define fi first
#define pi 3.14159265358979323

// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;

const ll inf = 1e17;
const int MAXM = 2e5+4;
const int MAXN = 1e4+4;

ll a[MAXM];
ll dp[2][MAXM*3],visit[2][MAXM*3];
ll start=0;
int n;

ll solve(int idx,int flag)
{
	if(idx==1)	return -inf;
	if(dp[flag][idx]==-1 and visit[flag][idx]==1)	return -inf;
	if(idx>n or idx<=0)	return 0;
	if(dp[flag][idx]!=-1)	return dp[flag][idx];
	visit[flag][idx]=1;
	ll ret = 0;
	if(flag==0){
		ret = a[idx] + solve(idx-a[idx],1);
	}else{
		ret = a[idx] + solve(idx+a[idx],0);
	}
	dp[flag][idx] = ret;
	return ret;
}

int main()
{
	mset(visit,0);
	mset(dp,-1);
	int i,j,k;
	scan(n);
	for(i=2;i<=n;i++){
		scanl(a[i]);
	}
	for(i=1;i<=n-1;i++){
		start = i+1;
		ll p = solve(1+i,0);
		if(p>=0){
			printf("%lld\n",p+i);
		}else{
			printf("-1\n");
		}
	}
	return 0;
}


#pragma GCC optimize("O3")

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define mset(m,v) memset(m,v,sizeof(m))
#define pr(a,s) printf("Case #%lld: %lld\n",a,s)
// #define mod 1000000007
#define mp make_pair
#define pb push_back
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define all(x) x.begin(),x.end()
#define se second
#define fi first
#define pi 3.14159265358979323

// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;

const ll inf = 1e17;
const int MAXM = 2e5+4;
const int MAXN = 1e4+4;

ll a[MAXM];
ll dp[2][MAXM*3],visit[2][MAXM*3];
ll start=0;
int n;

ll solve(int idx,int flag)
{
	if(idx==1)	return -inf;
	if(idx>n or idx<=0)	return 0;
	if(visit[flag][idx]==1)	return -inf;
	if(dp[flag][idx]!=-1)	return dp[flag][idx];
	visit[flag][idx]=1;
	ll ret = 0;
	if(flag==0){
		ret = a[idx] + solve(idx-a[idx],1);
	}else{
		ret = a[idx] + solve(idx+a[idx],0);
	}
	dp[flag][idx] = ret;
	return ret;
}

int main()
{
	mset(visit,0);
	mset(dp,-1);
	int i,j,k;
	scan(n);
	for(i=2;i<=n;i++){
		scanl(a[i]);
	}
	for(i=1;i<=n-1;i++){
		start = i+1;
		ll p = solve(1+i,0);
		if(p>=0){
			printf("%lld\n",p+i);
		}else{
			printf("-1\n");
		}
	}
	return 0;
}


#pragma GCC optimize("O3")

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define mset(m,v) memset(m,v,sizeof(m))
#define pr(a,s) printf("Case #%lld: %lld\n",a,s)
// #define mod 1000000007
#define mp make_pair
#define pb push_back
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define all(x) x.begin(),x.end()
#define se second
#define fi first
#define pi 3.14159265358979323

// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;

const ll inf = 1e15;
const int MAXM = 2e5+4;
const int MAXN = 1e4+4;

ll a[MAXM];
ll dp[2][2][MAXM];
ll start=0;
int n;

ll solve(int idx,int flag,int choice)
{
	if(idx==1)	return -inf;
	if(idx==start and choice==1)	return -inf;
	if(idx>n or idx<=0)	return 0;
	if(dp[flag][choice][idx]!=-1)	return dp[flag][choice][idx];
	ll ret = 0;
	if(flag==0){
		ret = a[idx] + solve(idx-a[idx],1,1);
	}else{
		ret = a[idx] + solve(idx+a[idx],0,1);
	}
	dp[flag][choice][idx] = ret;
	return ret;
}

int main()
{
	mset(dp,-1);
	int i,j,k;
	scan(n);
	for(i=2;i<=n;i++){
		scanl(a[i]);
	}
	for(i=1;i<=n-1;i++){
		start = i+1;
		ll p = solve(1+i,0,0);
		if(p>=0){
			printf("%lld\n",p+i);
		}else{
			printf("-1\n");
		}
	}
	return 0;
}


#pragma GCC optimize("O3")

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define mset(m,v) memset(m,v,sizeof(m))
#define pr(a,s) printf("Case #%lld: %lld\n",a,s)
// #define mod 1000000007
#define mp make_pair
#define pb push_back
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define all(x) x.begin(),x.end()
#define se second
#define fi first
#define pi 3.14159265358979323

// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;

const ll inf = 1e17;
const int MAXM = 2e5+4;
const int MAXN = 1e4+4;

ll a[MAXM];
ll dp[2][MAXM],visit[2][MAXM];
ll start=0;
int n;

ll solve(int idx,int flag)
{
	if(idx==1)	return -inf;
	if(idx>n or idx<=0)	return 0;
	if(dp[flag][idx]!=-1)	return dp[flag][idx];
	if(visit[flag][idx]==1)	return -inf;
	visit[flag][idx]=1;
	ll ret = 0;
	if(flag==0){
		ret = a[idx] + solve(idx-a[idx],1);
	}else{
		ret = a[idx] + solve(idx+a[idx],0);
	}
	dp[flag][idx] = ret;
	return ret;
}

int main()
{
	mset(visit,0);
	mset(dp,-1);
	int i,j,k;
	scan(n);
	for(i=2;i<=n;i++){
		scanl(a[i]);
	}
	for(i=1;i<=n-1;i++){
		start = i+1;
		ll p = solve(1+i,0);
		if(p>=0){
			printf("%lld\n",p+i);
		}else{
			printf("-1\n");
		}
	}
	return 0;
}


#pragma GCC optimize("O3")

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define mset(m,v) memset(m,v,sizeof(m))
#define pr(a,s) printf("Case #%lld: %lld\n",a,s)
// #define mod 1000000007
#define mp make_pair
#define pb push_back
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define all(x) x.begin(),x.end()
#define se second
#define fi first
#define pi 3.14159265358979323

// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;

const ll inf = 1e17;
const int MAXM = 2e5+4;
const int MAXN = 1e4+4;

ll a[MAXM];
map<pair<int,pair<int,int> > ,ll > dp;
ll start=0;
int n;

ll solve(int idx,int flag,int choice)
{
	if(idx==1)	return -inf;
	if(idx==start and choice==1)	return -inf;
	if(idx>n or idx<=0)	return 0;
	pair<int,pair<int,int> > p;
	p.fi = idx;p.se.fi = flag;p.se.se=choice;
	if(dp[p]!=0)	return dp[p];
	ll ret = 0;
	if(flag==0){
		ret = a[idx] + solve(idx-a[idx],1,1);
	}else{
		ret = a[idx] + solve(idx+a[idx],0,1);
	}
	dp[p] = ret;
	return ret;
}

int main(){
	int i,j,k;
	scan(n);
	for(i=2;i<=n;i++){
		scanl(a[i]);
	}
	for(i=1;i<=n-1;i++){
		start = i+1;
		ll p = solve(1+i,0,0);
		if(p>=0){
			printf("%lld\n",p+i);
		}else{
			printf("-1\n");
		}
	}
	return 0;
}


#pragma GCC optimize("O3")

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define mset(m,v) memset(m,v,sizeof(m))
#define pr(a,s) printf("Case #%lld: %lld\n",a,s)
// #define mod 1000000007
#define mp make_pair
#define pb push_back
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define all(x) x.begin(),x.end()
#define se second
#define fi first
#define pi 3.14159265358979323

// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;

const ll inf = 1e17;
const int MAXM = 2e5+4;
const int MAXN = 1e4+4;

ll a[MAXM];
ll dp[MAXM][2][2];
ll start=0;
int n;

ll solve(int idx,int flag,int choice)
{
	if(idx==1)	return -inf;
	if(idx==start and choice==1)	return -inf;
	if(idx>n or idx<=0)	return 0;
	if(dp[idx][flag][choice]!=-1)	return dp[idx][flag][choice];
	ll ret = 0;
	if(flag==0){
		ret = a[idx] + solve(idx-a[idx],1,1);
	}else{
		ret = a[idx] + solve(idx+a[idx],0,1);
	}
	dp[idx][flag][choice] = ret;
	return ret;
}

int main()
{
	mset(dp,-1);
	int i,j,k;
	scan(n);
	for(i=2;i<=n;i++){
		scanl(a[i]);
	}
	for(i=1;i<=n-1;i++){
		start = i+1;
		ll p = solve(1+i,0,0);
		if(p>=0){
			printf("%lld\n",p+i);
		}else{
			printf("-1\n");
		}
	}
	return 0;
}


#pragma GCC optimize("O3")

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define mset(m,v) memset(m,v,sizeof(m))
#define pr(a,s) printf("Case #%lld: %lld\n",a,s)
// #define mod 1000000007
#define mp make_pair
#define pb push_back
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define all(x) x.begin(),x.end()
#define se second
#define fi first
#define pi 3.14159265358979323

// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;

const ll inf = 1e17;
const int MAXM = 2e5+4;
const int MAXN = 1e4+4;

ll a[MAXM];
ll dp[2][MAXM],visit[2][MAXM];
ll start=0;
int n;

ll solve(int idx,int flag)
{
	if(idx==1)	return -inf;
	if(dp[flag][idx]==-1 and visit[flag][idx]==1)	return -inf;
	if(idx>n or idx<=0)	return 0;
	if(dp[flag][idx]!=-1)	return dp[flag][idx];
	visit[flag][idx]=1;
	ll ret = 0;
	if(flag==0){
		ret = a[idx] + solve(idx-a[idx],1);
	}else{
		ret = a[idx] + solve(idx+a[idx],0);
	}
	dp[flag][idx] = ret;
	return ret;
}

int main()
{
	mset(visit,0);
	mset(dp,-1);
	int i,j,k;
	scan(n);
	for(i=2;i<=n;i++){
		scanl(a[i]);
	}
	for(i=1;i<=n-1;i++){
		start = i+1;
		ll p = solve(1+i,0);
		if(p>=0){
			printf("%lld\n",p+i);
		}else{
			printf("-1\n");
		}
	}
	return 0;
}


#pragma GCC optimize("O3")

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define mset(m,v) memset(m,v,sizeof(m))
#define pr(a,s) printf("Case #%lld: %lld\n",a,s)
// #define mod 1000000007
#define mp make_pair
#define pb push_back
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define all(x) x.begin(),x.end()
#define se second
#define fi first
#define pi 3.14159265358979323

// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;

const ll inf = 1e17;
const int MAXM = 2e5+4;
const int MAXN = 1e4+4;

ll a[MAXM];
ll dp[2][2][MAXM];
ll start=0;
int n;

ll solve(int idx,int flag,int choice)
{
	if(idx==1)	return -inf;
	if(idx==start and choice==1)	return -inf;
	if(idx>n or idx<=0)	return 0;
	if(dp[flag][choice][idx]!=-1)	return dp[flag][choice][idx];
	ll ret = 0;
	if(flag==0){
		ret = a[idx] + solve(idx-a[idx],1,1);
	}else{
		ret = a[idx] + solve(idx+a[idx],0,1);
	}
	dp[flag][choice][idx] = ret;
	return ret;
}

int main()
{
	mset(dp,-1);
	int i,j,k;
	scan(n);
	for(i=2;i<=n;i++){
		scanl(a[i]);
	}
	for(i=1;i<=n-1;i++){
		start = i+1;
		ll p = solve(1+i,0,0);
		if(p>=0){
			printf("%lld\n",p+i);
		}else{
			printf("-1\n");
		}
	}
	return 0;
}


#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define T int t = 0; cin >> t; while(t--)
#define b_e(a) a.begin(), a.end()
typedef long long ll;
typedef long double lld;
const ll mod = 1e9 + 7;
const ll mx = 5e5 + 5;
const ll inf = 1e12;
vector<vector<bool> > visited(mx, vector<bool>(2, false));
vector<vector<ll> > dist(mx, vector<ll>(2, 0LL));
vector<ll>a(mx, 0LL);
ll l = 0, r = 1, n;
ll dfs(ll u, bool p){
    visited[u][p] = true;
    if(p == 0){
        if(u - a[u] == 1)dist[u][p] = -1;
        else if(u - a[u] > 0){
            if(!visited[u - a[u]][1]){
                ll x = dfs(u - a[u], 1);
                if(x != -1)dist[u][p] = a[u] + x;
                else dist[u][p] = -1;
            }else if(dist[u - a[u]][1] == 0) dist[u][p] = -1;
            else if(dist[u - a[u]][1] == -1)dist[u][p] = -1;
            else dist[u][p] = a[u] + dist[u - a[u]][1];
        }else{
            dist[u][p] = a[u];
        }
    }else{
        if(u + a[u] <= n){
            if(!visited[u + a[u]][0]){
                ll x = dfs(u + a[u], 0);
                if(x != -1)dist[u][p] = a[u] + x;
                else dist[u][p] = -1;
            }else if(dist[u + a[u]][0] == 0) dist[u][p] = -1;
            else if(dist[u + a[u]][0] == -1)dist[u][p] = -1;
            else dist[u][p] = a[u] + dist[u + a[u]][0];
        }else {
            dist[u][p] = a[u];
        }
    }
    return dist[u][p];

}
void input(){
    IOS;
    cin >> n;
    for(ll i = 2; i <= n; ++i)cin >> a[i];
    for(ll i = 2; i <= n; ++i){
       // cout << i << endl;
        if(!visited[i][0]){
            dist[i][0]= dfs(i, 0);
        }
        if(!visited[i][1]){
            dist[i][1] = dfs(i, 1);
        }
    }
    for(ll i = 1; i < n; ++i){
        if(dist[i + 1][0] == -1)cout << -1 << endl;
        else cout << i + dist[i + 1][0] << endl;
    }
}
int main(){
    input();
    return 0;
}


#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define T int t = 0; cin >> t; while(t--)
#define b_e(a) a.begin(), a.end()
typedef long long ll;
typedef long double lld;
const ll mod = 1e9 + 7;
const ll mx = 2e6 + 5;
const ll inf = 1e12;
vector<vector<bool> > visited(mx, vector<bool>(2, false));
vector<vector<int> > dist(mx, vector<int>(2, 0));
vector<int>a(mx, 0);
int l = 0, r = 1, n;
int dfs(int u, bool p){
    visited[u][p] = true;
    if(p == 0){
        if(u - a[u] == 1)dist[u][p] = -1;
        else if(u - a[u] > 0){
            if(!visited[u - a[u]][p]){
                int x = dfs(u - a[u], 1);
                if(x != -1)dist[u][p] = a[u] + x;
                else dist[u][p] = -1;
            }
        }else{
            dist[u][p] = a[u];
        }
    }else{
        if(u + a[u] <= n){
            if(!visited[u + a[u]][p]){
                int x = dfs(u + a[u], 0);
                if(x != -1)dist[u][p] = a[u] + x;
                else dist[u][p] = -1;
            }
        }else {
            dist[u][p] = a[u];
        }
    }
    return dist[u][p];

}
void input(){
    IOS;
    cin >> n;
    for(int i = 2; i <= n; ++i)cin >> a[i];
    for(int i = 2; i <= n; ++i){
        if(!visited[i][0]){
            dist[i][0]= dfs(i, 0);
        }
        if(!visited[i][1]){
            dist[i][1] = dfs(i, 1);
        }
    }
    for(int i = 1; i < n; ++i){
        if(dist[i + 1][0] == -1)cout << -1 << endl;
        else cout << i + dist[i + 1][0] << endl;
    }
}
int main(){
    input();
    return 0;
}


#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define T int t = 0; cin >> t; while(t--)
#define b_e(a) a.begin(), a.end()
typedef long long ll;
typedef long double lld;
const ll mod = 1e9 + 7;
const ll mx = 5e5 + 5;
const ll inf = 1e12;
vector<vector<bool> > visited(mx, vector<bool>(2, false));
vector<vector<int> > dist(mx, vector<int>(2, 0));
vector<int>a(mx, 0);
int l = 0, r = 1, n;
int dfs(int u, bool p){
    visited[u][p] = true;
    if(p == 0){
        if(u - a[u] == 1)dist[u][p] = -1;
        else if(u - a[u] > 0){
            if(!visited[u - a[u]][p]){
                int x = dfs(u - a[u], 1);
                if(x != -1)dist[u][p] = a[u] + x;
                else dist[u][p] = -1;
            }else if(dist[u - a[u]][1] == 0) dist[u][p] = -1;
            else if(dist[u - a[u]][1] == -1)dist[u][p] = -1;
            else dist[u][p] = a[u] + dist[u - a[u]][p];
        }else{
            dist[u][p] = a[u];
        }
    }else{
        if(u + a[u] <= n){
            if(!visited[u + a[u]][p]){
                int x = dfs(u + a[u], 0);
                if(x != -1)dist[u][p] = a[u] + x;
                else dist[u][p] = -1;
            }else if(dist[u + a[u]][0] == 0) dist[u][p] = -1;
            else if(dist[u + a[u]][0] == -1)dist[u][p] = -1;
            else dist[u][p] = a[u] + dist[u - a[u]][p];
        }else {
            dist[u][p] = a[u];
        }
    }
    return dist[u][p];

}
void input(){
    IOS;
    cin >> n;
    for(int i = 2; i <= n; ++i)cin >> a[i];
    for(int i = 2; i <= n; ++i){
        if(!visited[i][0]){
            dist[i][0]= dfs(i, 0);
        }
        if(!visited[i][1]){
            dist[i][1] = dfs(i, 1);
        }
    }
    for(int i = 1; i < n; ++i){
        if(dist[i + 1][0] == -1)cout << -1 << endl;
        else cout << i + dist[i + 1][0] << endl;
    }
}
int main(){
    input();
    return 0;
}


#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define T int t = 0; cin >> t; while(t--)
#define b_e(a) a.begin(), a.end()
typedef long long ll;
typedef long double lld;
const ll mod = 1e9 + 7;
const ll mx = 5e5 + 5;
const ll inf = 1e12;
vector<vector<bool> > visited(mx, vector<bool>(2, false));
vector<vector<int> > dist(mx, vector<int>(2, 0));
vector<int>a(mx, 0);
int l = 0, r = 1, n;
int dfs(int u, bool p){
    visited[u][p] = true;
    if(p == 0){
        if(u - a[u] == 1)dist[u][p] = -1;
        else if(u - a[u] > 0){
            if(!visited[u - a[u]][p]){
                int x = dfs(u - a[u], 1);
                if(x != -1)dist[u][p] = a[u] + x;
                else dist[u][p] = -1;
            }
            else dist[u][p] = -1;
        }else{
            dist[u][p] = a[u];
        }
    }else{
        if(u + a[u] <= n){
            if(!visited[u + a[u]][p]){
                int x = dfs(u + a[u], 0);
                if(x != -1)dist[u][p] = a[u] + x;
                else dist[u][p] = -1;
            }else dist[u][p] = -1;
        }else {
            dist[u][p] = a[u];
        }
    }
    return dist[u][p];

}
void input(){
    IOS;
    cin >> n;
    for(int i = 2; i <= n; ++i)cin >> a[i];
    for(int i = 2; i <= n; ++i){
        if(!visited[i][0]){
            dist[i][0]= dfs(i, 0);
        }
        if(!visited[i][1]){
            dist[i][1] = dfs(i, 1);
        }
    }
    for(int i = 1; i < n; ++i){
        if(dist[i + 1][0] == -1)cout << -1 << endl;
        else cout << i + dist[i + 1][0] << endl;
    }
}
int main(){
    input();
    return 0;
}


#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define T int t = 0; cin >> t; while(t--)
#define b_e(a) a.begin(), a.end()
typedef long long ll;
typedef long double lld;
const ll mod = 1e9 + 7;
const ll mx = 5e5 + 5;
const ll inf = 1e12;
vector<vector<bool> > visited(mx, vector<bool>(2, false));
vector<vector<int> > dist(mx, vector<int>(2, 0));
vector<int>a(mx, 0);
int l = 0, r = 1, n;
int dfs(int u, bool p){
    visited[u][p] = true;
    if(p == 0){
        if(u - a[u] == 1)dist[u][p] = -1;
        else if(u - a[u] > 0){
            if(!visited[u - a[u]][1]){
                int x = dfs(u - a[u], 1);
                if(x != -1)dist[u][p] = a[u] + x;
                else dist[u][p] = -1;
            }else if(dist[u - a[u]][1] == 0) dist[u][p] = -1;
            else if(dist[u - a[u]][1] == -1)dist[u][p] = -1;
            else dist[u][p] = a[u] + dist[u - a[u]][1];
        }else{
            dist[u][p] = a[u];
        }
    }else{
        if(u + a[u] <= n){
            if(!visited[u + a[u]][0]){
                int x = dfs(u + a[u], 0);
                if(x != -1)dist[u][p] = a[u] + x;
                else dist[u][p] = -1;
            }else if(dist[u + a[u]][0] == 0) dist[u][p] = -1;
            else if(dist[u + a[u]][0] == -1)dist[u][p] = -1;
            else dist[u][p] = a[u] + dist[u + a[u]][0];
        }else {
            dist[u][p] = a[u];
        }
    }
    return dist[u][p];

}
void input(){
    IOS;
    cin >> n;
    for(int i = 2; i <= n; ++i)cin >> a[i];
    for(int i = 2; i <= n; ++i){
       // cout << i << endl;
        if(!visited[i][0]){
            dist[i][0]= dfs(i, 0);
        }
        if(!visited[i][1]){
            dist[i][1] = dfs(i, 1);
        }
    }
    for(int i = 1; i < n; ++i){
        if(dist[i + 1][0] == -1)cout << -1 << endl;
        else cout << i + dist[i + 1][0] << endl;
    }
}
int main(){
    input();
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define MP make_pair
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pr 44701
#define inf 1000000000000000000
using namespace std;
const int N=200003;
ll dp[N][2],vis[N][2],n,a[N];
ll f(ll idx,ll d)
{
    if(idx<=0 || idx>n) return 0;
    if(vis[idx][d]) return inf;
    vis[idx][d]=1;
    if(dp[idx][d]!=-1) return dp[idx][d];
    ll ans=f(idx+a[idx]*(d==1?1:-1),1^d);
    if(ans!=inf)
    ans+=a[idx];
    vis[idx][d]=0;
    return dp[idx][d]=ans;

}
int main()
{

    io;
    ll i;
    memset(dp,-1LL,sizeof dp);
    cin>>n;
    for(i=2;i<=n;i++)
        cin>>a[i];
    for(i=2;i<=n;i++)
    {
        a[1]=i-1;
        dp[1][1]=-1;
        dp[1][0]=-1;
        vis[1][1]=vis[1][0]=0;
        if(f(1,1)>=inf) cout<<"-1\n";
        else cout<<f(1,1)<<"\n";
    }

}


#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define MP make_pair
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pr 44701
#define inf 1000000000000000000
using namespace std;
const int N=200003;
ll dp[N][2],vis[N][2],n,a[N];
ll f(ll idx,ll d)
{
    if(idx<=0 || idx>n) return 0;
    if(vis[idx][d]) return inf;
    vis[idx][d]=1;
    if(dp[idx][d]!=-1) return dp[idx][d];
    ll ans=f(idx+a[idx]*(d==1?1:-1),1^d);
    if(ans!=inf)
    ans+=a[idx];
    // vis[idx][d]=0;
    return dp[idx][d]=ans;

}
int main()
{

    io;
    ll i;
    memset(dp,-1LL,sizeof dp);
    cin>>n;
    for(i=2;i<=n;i++)
        cin>>a[i];
    for(i=2;i<=n;i++)
    {
        a[1]=i-1;
        dp[1][1]=-1;
        dp[1][0]=-1;
        vis[1][1]=vis[1][0]=0;
        if(f(1,1)>=inf) cout<<"-1\n";
        else cout<<f(1,1)<<"\n";
    }

}


#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define MP make_pair
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pr 44701
#define inf 1000000000000000
using namespace std;
const int N=200003;
ll dp[N][2],vis[N][2],n,a[N];
ll f(ll idx,ll d)
{
    if(idx<=0 || idx>n) return 0;
    if(vis[idx][d]) return inf;
    vis[idx][d]=1;
    if(dp[idx][d]!=-1) return dp[idx][d];
    ll ans=f(idx+a[idx]*(d==1?1:-1),1^d);
    if(ans!=inf)
    ans+=a[idx];
    vis[idx][d]=0;
    return dp[idx][d]=ans;

}
int main()
{

    io;
    ll i;
    memset(dp,-1LL,sizeof dp);
    cin>>n;
    for(i=2;i<=n;i++)
        cin>>a[i];
    for(i=2;i<=n;i++)
    {
        a[1]=i-1;
        dp[1][1]=-1;
        dp[1][0]=-1;
        vis[1][1]=vis[1][0]=0;
        if(f(1,1)>=inf) cout<<"-1\n";
        else cout<<f(1,1)<<"\n";
    }

}


#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define MP make_pair
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pr 44701
#define inf 1000000000000
using namespace std;
const int N=100003;
ll dp[N][2],vis[N][2],n,a[N];
ll f(ll idx,ll d)
{
    if(idx<=0 || idx>n) return 0;
    if(vis[idx][d]) return inf;
    vis[idx][d]=1;
    if(dp[idx][d]!=-1) return dp[idx][d];
    ll ans=f(idx+a[idx]*(d==1?1:-1),1^d);
    ans+=a[idx];
    vis[idx][d]=0;
    return dp[idx][d]=ans;

}
int main()
{

    io;
    ll i;
    memset(dp,-1LL,sizeof dp);
    cin>>n;
    for(i=2;i<=n;i++)
        cin>>a[i];
    for(i=2;i<=n;i++)
    {
        a[1]=i-1;
        dp[1][1]=-1;
        dp[1][0]=-1;
        vis[1][1]=vis[1][0]=0;
        if(f(1,1)>=inf) cout<<"-1\n";
        else cout<<f(1,1)<<"\n";
    }

}


#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define MP make_pair
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pr 44701
#define inf 1000000000000000000
using namespace std;
const int N=200003;
ll dp[N][2],n,a[N];
ll f(ll idx,ll d)
{
    if(idx>n || idx<1) return 0;
    if(dp[idx][d]) return dp[idx][d];
    dp[idx][d]=-1;
    ll ans=f(idx+(d?a[idx]:-a[idx]),1^d);
    if(ans==-1) return dp[idx][d]=-1;
    else return dp[idx][d]=ans+a[idx];

}
int main()
{

    io;
    ll i;

    cin>>n;
    for(i=2;i<=n;i++)
        cin>>a[i];
    for(i=2;i<=n;i++)
    {

        if(f(i,0)==-1) cout<<"-1\n";
        else cout<<f(i,0)+i-1<<"\n";
    }

}


#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define MP make_pair
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pr 44701
#define inf 1000000000000
using namespace std;
const int N=200003;
ll dp[N][2],vis[N][2],n,a[N];
ll f(ll idx,ll d)
{
    if(idx<=0 || idx>n) return 0;
    if(vis[idx][d]) return inf;
    vis[idx][d]=1;
    if(dp[idx][d]!=-1) return dp[idx][d];
    ll ans=f(idx+a[idx]*(d==1?1:-1),1^d);
    ans+=a[idx];
    vis[idx][d]=0;
    return dp[idx][d]=ans;

}
int main()
{

    io;
    ll i;
    memset(dp,-1LL,sizeof dp);
    cin>>n;
    for(i=2;i<=n;i++)
        cin>>a[i];
    for(i=2;i<=n;i++)
    {
        a[1]=i-1;
        dp[1][1]=-1;
        dp[1][0]=-1;
        vis[1][1]=vis[1][0]=0;
        if(f(1,1)>=inf) cout<<"-1\n";
        else cout<<f(1,1)<<"\n";
    }

}


#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define MP make_pair
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pr 44701
#define inf 1000000000000000
using namespace std;
const int N=200003;
ll dp[N][2],vis[N][2],n,a[N];
ll f(ll idx,ll d)
{
    if(idx<=0 || idx>n) return 0;
    if(vis[idx][d]) return inf;
    vis[idx][d]=1;
    if(dp[idx][d]!=-1) return dp[idx][d];
    ll ans=f(idx+a[idx]*(d==1?1:-1),1^d);
    ans+=a[idx];
    vis[idx][d]=0;
    return dp[idx][d]=ans;

}
int main()
{

    io;
    ll i;
    memset(dp,-1LL,sizeof dp);
    cin>>n;
    for(i=2;i<=n;i++)
        cin>>a[i];
    for(i=2;i<=n;i++)
    {
        a[1]=i-1;
        dp[1][1]=-1;
        dp[1][0]=-1;
        vis[1][1]=vis[1][0]=0;
        if(f(1,1)>=inf) cout<<"-1\n";
        else cout<<f(1,1)<<"\n";
    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<short, int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;
typedef vector<string> vs;
const int di[] = { -1,0,1,0 };
const int dj[] = { 0,1,0,-1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
#define mp make_pair
#define all(x) x.begin(),x.end()

int n, vf;
vi a, vis1, vis2;

int step2(int, int);

vi mem1(2 * 1e5 + 1, -1);
int step1(int x, int y) {
	if (x <= 0 || x > n) return 0;
	if (mem1[x] != -1) return mem1[x];
	if (vis1[x] == vf) return mem1[x] = -1;

	vis1[x] = vf;
	int tn = step2(x + a[x], y + a[x]);
	if (tn == -1)
		return mem1[x] = -1;

	return mem1[x] = a[x] + tn;
}

vi mem2(2 * 1e5 + 1, -1);
int step2(int x, int y) {
	if (x <= 0 || x > n) return 0;
	if (mem2[x] != -1) return mem2[x];
	if (vis2[x] == vf) return mem2[x] = -1;

	vis2[x] = vf;
	int tn = step1(x - a[x], y + a[x]);
	if (tn == -1)
		return mem2[x] = -1;

	return mem2[x] = a[x] + tn;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	a.assign(n + 1, 0);
	vis1.assign(n + 1, 0); vis2 = vis1;
	for (int i = 2; i <= n; i++)
		cin >> a[i];

	for (int i = 1; i < n; i++) {
		int x = 1 + i, y = i;
		vf++;
		a[1] = i;
		vis1[x] = vf;
		int r = step2(x, y);
		cout << (r == -1 ? r : y + r) << endl;
	}
	cin.ignore(), cin.get();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<short, int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;
typedef vector<string> vs;
const int di[] = { -1,0,1,0 };
const int dj[] = { 0,1,0,-1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
#define mp make_pair
#define all(x) x.begin(),x.end()

int n, vf;
vi a, vis1, vis2;

int step2(int, int);

vi mem1(2 * 1e5 + 1, -1);
int step1(int x, int y) {
	if (x <= 0 || x > n) return 0;
	if (mem1[x] != -1) return mem1[x];
	if (vis1[x] == vf) return -1;

	vis1[x] = vf;
	int tn = step2(x + a[x], y + a[x]);
	if (tn == -1)
		return -1;

	return mem1[x] = a[x] + tn;
}

vi mem2(2 * 1e5 + 1, -1);
int step2(int x, int y) {
	if (x <= 0 || x > n) return 0;
	if (mem2[x] != -1) return mem2[x];
	if (vis2[x] == vf) return -1;

	vis2[x] = vf;
	int tn = step1(x - a[x], y + a[x]);
	if (tn == -1)
		return -1;

	return mem2[x] = a[x] + tn;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	a.assign(n + 1, 0);
	vis1.assign(n + 1, 0); vis2 = vis1;
	for (int i = 2; i <= n; i++)
		cin >> a[i];

	for (int i = 1; i < n; i++) {
		int x = 1 + i, y = i;
		vf++;
		a[1] = i;
		vis1[x] = vf;
		int r = step2(x, y);
		cout << (r == -1 ? r : y + r) << endl;
	}
	cin.ignore(), cin.get();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<short, int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;
typedef vector<string> vs;
const int di[] = { -1,0,1,0 };
const int dj[] = { 0,1,0,-1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
#define mp make_pair
#define all(x) x.begin(),x.end()

int n, vf;
vi vis1, vis2;
vll a;

ll step2(int, int);

vll mem1(2 * 1e5 + 1, -1);
ll step1(int x, int y) {
	if (x <= 0 || x > n) return 0;
	if (mem1[x] != -1) return mem1[x];
	if (vis1[x] == vf) return mem1[x] = -2;

	vis1[x] = vf;
	ll tn = step2(x + a[x], y + a[x]);
	if (tn == -2)
		return mem1[x] = -2;

	return mem1[x] = a[x] + tn;
}

vll mem2(2 * 1e5 + 1, -1);
ll step2(int x, int y) {
	if (x <= 0 || x > n) return 0;
	if (mem2[x] != -1) return mem2[x];
	if (vis2[x] == vf) return mem2[x] = -2;

	vis2[x] = vf;
	ll tn = step1(x - a[x], y + a[x]);
	if (tn == -2)
		return mem2[x] = -2;

	return mem2[x] = a[x] + tn;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	a.assign(n + 1, 0);
	vis1.assign(n + 1, 0); vis2 = vis1;
	for (int i = 2; i <= n; i++)
		cin >> a[i];

	for (int i = 1; i < n; i++) {
		int x = 1 + i, y = i;
		vf++;
		a[1] = i;
		vis1[x] = vf;
		ll r = step2(x, y);
		cout << (r == -2 ? -1 : y + r) << endl;
	}
	//cin.ignore(), cin.get();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<short, int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;
typedef vector<string> vs;
const int di[] = { -1,0,1,0 };
const int dj[] = { 0,1,0,-1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
#define mp make_pair
#define all(x) x.begin(),x.end()

int n, vf;
vi vis1, vis2;
vll a;

int step2(int, int);

vll mem1(2 * 1e5 + 1, -1);
int step1(int x, int y) {
	if (x <= 0 || x > n) return 0;
	if (mem1[x] != -1) return mem1[x];
	if (vis1[x] == vf) return mem1[x] = -2;

	vis1[x] = vf;
	ll tn = step2(x + a[x], y + a[x]);
	if (tn == -2)
		return mem1[x] = -2;

	return mem1[x] = (a[x] + tn) % MOD;
}

vll mem2(2 * 1e5 + 1, -1);
int step2(int x, int y) {
	if (x <= 0 || x > n) return 0;
	if (mem2[x] != -1) return mem2[x];
	if (vis2[x] == vf) return mem2[x] = -2;

	vis2[x] = vf;
	ll tn = step1(x - a[x], y + a[x]);
	if (tn == -2)
		return mem2[x] = -2;

	return mem2[x] = (a[x] + tn) % MOD;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	a.assign(n + 1, 0);
	vis1.assign(n + 1, 0); vis2 = vis1;
	for (int i = 2; i <= n; i++)
		cin >> a[i];

	for (int i = 1; i < n; i++) {
		int x = 1 + i, y = i;
		vf++;
		a[1] = i;
		vis1[x] = vf;
		int r = step2(x, y);
		cout << (r == -2 ? -1 : y + r) << endl;
	}
	//cin.ignore(), cin.get();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<short, int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;
typedef vector<string> vs;
const int di[] = { -1,0,1,0 };
const int dj[] = { 0,1,0,-1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
#define mp make_pair
#define all(x) x.begin(),x.end()

int n, vf;
vi a, vis1, vis2;

int step2(int, int);

vi mem1(2 * 1e5 + 1, -1);
int step1(int x, int y) {
	if (x <= 0 || x > n) return 0;
	if (mem1[x] != -1) return mem1[x];
	if (vis1[x] == vf) return -1;

	vis1[x] = vf;
	int tn = step2(x + a[x], y + a[x]);
	if (tn == -1)
		return -1;

	return mem1[x] = a[x] + tn;
}

vi mem2(2 * 1e5 + 1, -1);
int step2(int x, int y) {
	if (x <= 0 || x > n) return 0;
	if (mem2[x] != -1) return mem2[x];
	if (vis2[x] == vf) return -1;

	vis1[x] = vf;
	int tn = step1(x - a[x], y + a[x]);
	if (tn == -1)
		return -1;

	return mem2[x] = a[x] + tn;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	a.assign(n + 1, 0);
	vis1.assign(n + 1, 0); vis2 = vis1;
	for (int i = 2; i <= n; i++)
		cin >> a[i];

	for (int i = 1; i < n; i++) {
		int x = 1 + i, y = i;
		vf++;
		a[1] = i;
		int r = step2(x, y);
		cout << (r == -1 ? r : y + r) << endl;
	}
	cin.ignore(), cin.get();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<short, int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;
typedef vector<string> vs;
const int di[] = { -1,0,1,0 };
const int dj[] = { 0,1,0,-1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
#define mp make_pair
#define all(x) x.begin(),x.end()

int n, vf;
vi vis1, vis2;
vll a;

int step2(int, int);

vll mem1(2 * 1e5 + 1, -1);
int step1(int x, int y) {
	if (x <= 0 || x > n) return 0;
	if (mem1[x] != -1) return mem1[x];
	if (vis1[x] == vf) return mem1[x] = -2;

	vis1[x] = vf;
	ll tn = step2(x + a[x], y + a[x]);
	if (tn == -2)
		return mem1[x] = -2;

	return mem1[x] = a[x] + tn;
}

vll mem2(2 * 1e5 + 1, -1);
int step2(int x, int y) {
	if (x <= 0 || x > n) return 0;
	if (mem2[x] != -1) return mem2[x];
	if (vis2[x] == vf) return mem2[x] = -2;

	vis2[x] = vf;
	ll tn = step1(x - a[x], y + a[x]);
	if (tn == -2)
		return mem2[x] = -2;

	return mem2[x] = a[x] + tn;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	a.assign(n + 1, 0);
	vis1.assign(n + 1, 0); vis2 = vis1;
	for (int i = 2; i <= n; i++)
		cin >> a[i];

	for (int i = 1; i < n; i++) {
		int x = 1 + i, y = i;
		vf++;
		a[1] = i;
		vis1[x] = vf;
		ll r = step2(x, y);
		cout << (r == -2 ? -1 : y + r) << endl;
	}
	//cin.ignore(), cin.get();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<short, int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;
typedef vector<string> vs;
const int di[] = { -1,0,1,0 };
const int dj[] = { 0,1,0,-1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
#define mp make_pair
#define all(x) x.begin(),x.end()

int n, vf;
vi vis1, vis2;
vll a;

ll step2(int, int);

vll mem1(2 * 1e5 + 1, -1);
ll step1(int x, int y) {
	if (x <= 0 || x > n) return 0;
	if (mem1[x] != -1) return mem1[x];
	if (vis1[x] == vf) return mem1[x] = -2;

	vis1[x] = vf;
	ll tn = step2(x + a[x], y + a[x]);
	if (tn == -2)
		return mem1[x] = -2;

	return mem1[x] = a[x] + tn;
}

vll mem2(2 * 1e5 + 1, -1);
ll step2(int x, int y) {
	if (x <= 0 || x > n) return 0;
	if (mem2[x] != -1) return mem2[x];
	if (vis2[x] == vf) return mem2[x] = -2;

	vis2[x] = vf;
	ll tn = step1(x - a[x], y + a[x]);
	if (tn == -2)
		return mem2[x] = -2;

	return mem2[x] = a[x] + tn;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	a.assign(n + 1, 0);
	vis1.assign(n + 1, 0); vis2 = vis1;
	for (int i = 2; i <= n; i++)
		cin >> a[i];

	for (int i = 1; i < n; i++) {
		int x = 1 + i, y = i;
		vf++;
		a[1] = i;
		vis1[1] = vf;
		ll r = step2(x, y);
		cout << (r == -2 ? -1 : y + r) << endl;
	}
	//cin.ignore(), cin.get();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<short, int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;
typedef vector<string> vs;
const int di[] = { -1,0,1,0 };
const int dj[] = { 0,1,0,-1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
#define mp make_pair
#define all(x) x.begin(),x.end()

int n, vf;
vi a, vis1, vis2;

int step2(int, int);

vi mem1(2 * 1e5 + 1, -1);
int step1(int x, int y) {
	if (x <= 0 || x > n) return 0;
	if (mem1[x] != -1) return mem1[x];
	if (vis1[x] == vf) return mem1[x] = -2;

	vis1[x] = vf;
	int tn = step2(x + a[x], y + a[x]);
	if (tn == -2)
		return mem1[x] = -2;

	return mem1[x] = a[x] + tn;
}

vi mem2(2 * 1e5 + 1, -1);
int step2(int x, int y) {
	if (x <= 0 || x > n) return 0;
	if (mem2[x] != -1) return mem2[x];
	if (vis2[x] == vf) return mem2[x] = -2;

	vis2[x] = vf;
	int tn = step1(x - a[x], y + a[x]);
	if (tn == -2)
		return mem2[x] = -2;

	return mem2[x] = a[x] + tn;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	a.assign(n + 1, 0);
	vis1.assign(n + 1, 0); vis2 = vis1;
	for (int i = 2; i <= n; i++)
		cin >> a[i];

	for (int i = 1; i < n; i++) {
		int x = 1 + i, y = i;
		vf++;
		a[1] = i;
		vis1[x] = vf;
		int r = step2(x, y);
		cout << (r == -2 ? -1 : y + r) << endl;
	}
	//cin.ignore(), cin.get();
}


#include <bits/stdc++.h>
using namespace std;
long long int A[200010],B[200010];
int i,j,n,k,t,N,K,dec;
long int I,X,V[200010];
bool a[200010][2];

long long int calc(int i,bool f)
{
    if(i<1 || i>n)
        return 0;
    if(a[i][f] == 1)
        return -1;
    a[i][f] = 1;
    if(f)
    {
        X = i+V[i];
        I = calc(X,0);
        if(I==-1)
            A[i] = -1;
        else
            A[i] = V[i]+I;
        return A[i];
    }
    else
    {
        X = i-V[i];
        I = calc(X,1);
        if(I==-1)
            B[i] = -1;
        else
            B[i] = V[i]+I;
        return B[i];
    }
}

int main()
{
    cin>>n;
    i=2;
    while(i<=n)
    {
        cin>>V[i];
        i++;
    }
    i=2;
    a[1][0] = 1;
    a[1][1] = 1;
    while(i<=n)
    {
        if(B[i] == 0)
        {
            calc(i,0);
        }
        if(B[i] != -1)
            cout<<B[i]+i-1<<"\n";
        else
            cout<<"-1\n";
        i++;
    }
}


#include <bits/stdc++.h>
using namespace std;
bool flag,fb[200005],fc[200005],F;
int n,i;
long int a[200005];
long long int x,y,b[200005],c[200005],z,A[200005],Z;

long long int fun(long long int x, bool flag)
{
    if(flag)            // if flag == 1     // -a[x]
    {
        if(!b[x])
        {
            z=x-a[x];
            if(z<1)
                b[x] = a[x];
            else
            {
                if(z==1)
                    fb[z] = 1;
                fun(z,0);
                z=x-a[x];
                if(c[z]!=-1)
                {
                    b[x] = a[x] + c[z];
                    return b[x];
                }
                if(fb[z] == 1)
                {
                    b[z] = -1;
                    b[x] = -1;
                    return -1;
                }
                fb[z] = 1;
                Z = fun(z,0);
                if(Z!=-1)
                    b[x] = a[x]+Z;
                else
                    b[x] = -1;
            }
            return b[x];
        }
        else
            return b[x];
    }
    else            // if flag == 0     // +a[x]
    {
        if(!c[x])
        {
            z=x+a[x];
            if(z>n)
                c[x] = a[x];
            else
            {
                if(fc[z] == 1)
                {
                    c[z] = -1;
                    return -1;
                }
                fc[z] = 1;
                Z = fun(z,1);
                if(Z!=-1)
                    c[x] = a[x]+Z;
                else
                    c[x] = -1;
            }
            return c[x];
        }
        else
            return c[x];
    }
}

int main()
{
    std::ios::sync_with_stdio(0);
    cin>>n;
    for(i=2;i<=n;i++)
        cin>>a[i];
    for(i=1;i<n;i++)
    {
        a[1]=i;
        b[i+1] = fun(i+1,1);
        if(b[i+1] == -1)
            cout<<"-1\n";
        else
            cout<<i+b[i+1]<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long int A[200010],B[200010];
int i,j,n,k,t,N,K,dec;
long int I,X,V[200010];
bool a[200010][2];

long long int calc(int i,bool f)
{
    if(i<1 || i>n)
        return 0;
    if(a[i][f] == 1)
        return -1;
    a[i][f] = 1;
    if(f)
    {
        X = i+V[i];
        I = calc(X,0);
        if(I==-1)
            A[i] = -1;
        else
            A[i] = V[i]+I;
        return A[i];
    }
    else
    {
        X = i-V[i];
        I = calc(X,1);
        if(I==-1)
            B[i] = -1;
        else
            B[i] = V[i]+I;
        return B[i];
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    i=2;
    while(i<=n)
    {
        cin>>V[i];
        i++;
    }
    i=2;
    a[1][0] = 1;
    a[1][1] = 1;
    while(i<=n)
    {
        if(B[i] == 0)
        {
            calc(i,0);
        }
        if(B[i] != -1)
            cout<<B[i]+i-1<<"\n";
        else
            cout<<"-1\n";
        i++;
    }
}


#include <bits/stdc++.h>
using namespace std;
bool flag,fb[200005],fc[200005],F;
int n,i;
long int a[200005];
long long int x,y,b[200005],c[200005],z,A[200005],Z;

long long int fun(long long int x, bool flag)
{
    if(flag)            // if flag == 1     // -a[x]
    {
        if(!b[x])
        {
            z=x-a[x];
            if(z<1)
                b[x] = a[x];
            else
            {
                if(z==1)
                    fb[z] = 1;
                fun(z,0);
                z=x-a[x];
                if(c[z]==-1)
                {
                    b[x] = -1;
                    return -1;
                }
                if(c[z]!=0)
                {
                    b[x] = a[x] + c[z];
                    return b[x];
                }
                if(fb[z] == 1)
                {
                    b[z] = -1;
                    b[x] = -1;
                    return -1;
                }
                fb[z] = 1;
                Z = fun(z,0);
                if(Z!=-1)
                    b[x] = a[x]+Z;
                else
                    b[x] = -1;
            }
            return b[x];
        }
        else
            return b[x];
    }
    else            // if flag == 0     // +a[x]
    {
        if(!c[x])
        {
            z=x+a[x];
            if(z>n)
                c[x] = a[x];
            else
            {
                if(fc[z] == 1)
                {
                    c[z] = -1;
                    return -1;
                }
                fc[z] = 1;
                Z = fun(z,1);
                if(Z!=-1)
                    c[x] = a[x]+Z;
                else
                    c[x] = -1;
            }
            return c[x];
        }
        else
            return c[x];
    }
}

int main()
{
    std::ios::sync_with_stdio(0);
    cin>>n;
    for(i=2;i<=n;i++)
        cin>>a[i];
    for(i=1;i<n;i++)
    {
        a[1]=i;
        b[i+1] = fun(i+1,1);
        if(b[i+1] == -1)
            cout<<"-1\n";
        else
            cout<<i+b[i+1]<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
bool flag,fb[200005],fc[200005],F;
int n,i;
long int a[200005];
long long int x,y,b[200005],c[200005],z,A[200005],Z;

long long int fun(long long int x, bool flag)
{
    if(flag)            // if flag == 1     // -a[x]
    {
        if(!b[x])
        {
            z=x-a[x];
            if(z<1)
                b[x] = a[x];
            else
            {
                if(z==1)
                    fb[z] = 1;
                fun(z,0);
                if(c[z]!=-1)
                {
                    b[x] = a[x] + c[z];
                    return b[x];
                }
                if(fb[z] == 1)
                {
                    b[z] = -1;
                    b[x] = -1;
                    return -1;
                }
                fb[z] = 1;
                Z = fun(z,0);
                if(Z!=-1)
                    b[x] = a[x]+Z;
                else
                    b[x] = -1;
            }
            return b[x];
        }
        else
            return b[x];
    }
    else            // if flag == 0     // +a[x]
    {
        if(!c[x])
        {
            z=x+a[x];
            if(z>n)
                c[x] = a[x];
            else
            {
                if(fc[z] == 1)
                {
                    c[z] = -1;
                    return -1;
                }
                fc[z] = 1;
                Z = fun(z,1);
                if(Z!=-1)
                    c[x] = a[x]+Z;
                else
                    c[x] = -1;
            }
            return c[x];
        }
        else
            return c[x];
    }
}

int main()
{
    std::ios::sync_with_stdio(0);
    cin>>n;
    for(i=2;i<=n;i++)
        cin>>a[i];
    for(i=1;i<n;i++)
    {
        a[1]=i;
        b[i+1] = fun(i+1,1);
        if(b[i+1] == -1)
            cout<<"-1\n";
        else
            cout<<i+b[i+1]<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
tuple <long int,long long int,long long int> A[200010];
int i,j,I,n,k,t,N,K,dec;
long int X,Y;
bool f1,f2,f3;

long long int calc(int i,bool f)
{
    if(f)
    {
        if(get<1>(A[i])==-1)
            return -1;
        get<1>(A[i]) = -1;
        X=i+get<0>(A[i]);
        if(X<1 || X>n)
        {
            get<1>(A[i]) = get<0>(A[i]);
        }
        else
        {
            I = X;
            X = calc(I, 0);
            if(X!=-1)
                get<1>(A[i]) = get<0>(A[i]) + X;
            else
                get<1>(A[i]) = -1;
        }
        return get<1>(A[i]);
    }
    else
    {
        if(get<2>(A[i])==-1)
            return -1;
        get<2>(A[i]) = -1;
        X=i-get<0>(A[i]);
        if(X<1 || X>n)
        {
            get<2>(A[i]) = get<0>(A[i]);
        }
        else
        {
            I = X;
            X = calc(I, 1);
            if(X!=-1)
                get<2>(A[i]) = get<0>(A[i]) + X;
            else
                get<2>(A[i]) = -1;
        }
        return get<2>(A[i]);
    }
}

int main()
{
    cin>>n;
    i=2;
    while(i<=n)
    {
        cin>>get<0>(A[i]);
        i++;
    }
    i=2;
    while(i<=n)
    {
        if(get<2>(A[i]) == 0)
        {
            calc(i,0);
        }
        if(get<2>(A[i]) != -1)
            cout<<get<2>(A[i])+i-1<<"\n";
        else
            cout<<"-1\n";
        i++;
    }

}


#include <bits/stdc++.h>
using namespace std;
long long int A[200010],B[200010];
int i,j,n,k,t,N,K,dec;
long int I,X,V[200010];
bool a[200010][2];

long long int calc(int i,bool f)
{
    if(i<1 || i>n)
        return 0;
    if(a[i][f] == 1)
        return -1;
    a[i][f] = 1;
    if(f)
    {
        X = i+V[i];
        I = calc(X,0);
        if(I==-1)
            A[i] = -1;
        else
            A[i] = V[i]+I;
        return A[i];
    }
    else
    {
        X = i-V[i];
        I = calc(X,1);
        if(I==-1)
            B[i] = -1;
        else
            B[i] = V[i]+I;
        return B[i];
    }
}

int main()
{
    cin>>n;
    i=2;
    while(i<=n)
    {
        cin>>V[i];
        i++;
    }
    i=2;
    while(i<=n)
    {
        if(B[i] == 0)
        {
            calc(i,0);
        }
        if(B[i] != -1)
            cout<<B[i]+i-1<<"\n";
        else
            cout<<"-1\n";
        i++;
    }
}


#include <bits/stdc++.h>
using namespace std;
bool flag,fb[200005],fc[200005],F;
int n,i;
long int a[200005];
long long int x,y,b[200005],c[200005],z,A[200005],Z;

long long int fun(long long int x, bool flag)
{
    if(flag)            // if flag == 1     // -a[x]
    {
        if(!b[x])
        {
            z=x-a[x];
            if(z<1)
                b[x] = a[x];
            else
            {
                if(z==1)
                    fb[z] = 1;
                if(c[z])
                {
                    b[x] = a[x] + c[z];
                    return b[x];
                }
                if(fb[z] == 1)
                {
                    b[z] = -1;
                    b[x] = -1;
                    return -1;
                }
                fb[z] = 1;
                Z = fun(z,0);
                if(Z!=-1)
                    b[x] = a[x]+Z;
                else
                    b[x] = -1;
            }
            return b[x];
        }
        else
            return b[x];
    }
    else            // if flag == 0     // +a[x]
    {
        if(!c[x])
        {
            z=x+a[x];
            if(z>n)
                c[x] = a[x];
            else
            {
                if(fc[z] == 1)
                {
                    c[z] = -1;
                    return -1;
                }
                fc[z] = 1;
                Z = fun(z,1);
                if(Z!=-1)
                    c[x] = a[x]+Z;
                else
                    c[x] = -1;
            }
            return c[x];
        }
        else
            return c[x];
    }
}

int main()
{
    std::ios::sync_with_stdio(0);
    cin>>n;
    for(i=2;i<=n;i++)
        cin>>a[i];
    for(i=1;i<n;i++)
    {
        a[1]=i;
        b[i+1] = fun(i+1,1);
        if(b[i+1] == -1)
            cout<<"-1\n";
        else
            cout<<i+b[i+1]<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long int A[200010],B[200010];
int i,j,I,n,k,t,N,K,dec;
long int X,Y[200010];
bool f1,f2,f3;

long long int calc(int i,bool f)
{
    if(f)
    {
        if(A[i]==-1)
            return -1;
        A[i] = -1;
        X=i+Y[i];
        if(X<1 || X>n)
        {
            A[i] = Y[i];
        }
        else
        {
            I = X;
            X = calc(I, 0);
            if(X!=-1)
                A[i] = Y[i] + X;
            else
                A[i] = -1;
        }
        return A[i];
    }
    else
    {
        if(B[i]==-1)
            return -1;
        B[i] = -1;
        X=i-Y[i];
        if(X<1 || X>n)
        {
            B[i] = Y[i];
        }
        else
        {
            I = X;
            X = calc(I, 1);
            if(X!=-1)
                B[i] = Y[i] + X;
            else
                B[i] = -1;
        }
        return B[i];
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    i=2;
    while(i<=n)
    {
        cin>>Y[i];
        i++;
    }
    i=2;
    while(i<=n)
    {
        if(B[i] == 0)
        {
            calc(i,0);
        }
        if(B[i] != -1)
            cout<<B[i]+i-1<<"\n";
        else
            cout<<"-1\n";
        i++;
    }
}


#include <bits/stdc++.h>
using namespace std;
long long int A[200010],B[200010];
int i,j,I,n,k,t,N,K,dec;
long int X,Y[200010];
bool f1,f2,f3;

long long int calc(int i,bool f)
{
    if(f)
    {
        if(A[i]==-1)
            return -1;
        A[i] = -1;
        X=i+Y[i];
        if(X<1 || X>n)
        {
            A[i] = Y[i];
        }
        else
        {
            I = X;
            X = calc(I, 0);
            if(X!=-1)
                A[i] = Y[i] + X;
            else
                A[i] = -1;
        }
        return A[i];
    }
    else
    {
        if(B[i]==-1)
            return -1;
        B[i] = -1;
        X=i-Y[i];
        if(X<1 || X>n)
        {
            B[i] = Y[i];
        }
        else
        {
            I = X;
            X = calc(I, 1);
            if(X!=-1)
                B[i] = Y[i] + X;
            else
                B[i] = -1;
        }
        return B[i];
    }
}

int main()
{
    cin>>n;
    i=2;
    while(i<=n)
    {
        cin>>Y[i];
        i++;
    }
    i=2;
    while(i<=n)
    {
        if(B[i] == 0)
        {
            calc(i,0);
        }
        if(B[i] != -1)
            cout<<B[i]+i-1<<"\n";
        else
            cout<<"-1\n";
        i++;
    }
}


#include <bits/stdc++.h>
using namespace std;
long long int A[200010],B[200010];
int i,j,I,n,k,t,N,K,dec;
long int X,Y[200010];
bool f1,f2,f3;

long long int calc(int i,bool f)
{
    if(f)
    {
        if(A[i]==-1)
            return -1;
        else if(A[i]!=0)
            return A[i];
        A[i] = -1;
        X=i+Y[i];
        if(X<1 || X>n)
        {
            A[i] = Y[i];
        }
        else
        {
            I = X;
            X = calc(I, 0);
            if(X!=-1)
                A[i] = Y[i] + X;
            else
                A[i] = -1;
        }
        return A[i];
    }
    else
    {
        if(B[i]==-1)
            return -1;
        else if(B[i]!=0)
            return B[i];
        B[i] = -1;
        X=i-Y[i];
        if(X<1 || X>n)
        {
            B[i] = Y[i];
        }
        else
        {
            I = X;
            X = calc(I, 1);
            if(X!=-1)
                B[i] = Y[i] + X;
            else
                B[i] = -1;
        }
        return B[i];
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    i=2;
    while(i<=n)
    {
        cin>>Y[i];
        i++;
    }
    i=2;
    while(i<=n)
    {
        if(B[i] == 0)
        {
            calc(i,0);
        }
        if(B[i] != -1)
            cout<<B[i]+i-1<<"\n";
        else
            cout<<"-1\n";
        i++;
    }
}


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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
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;} // modular exponent
ll n;
const int maxn=2e5+5;
ll dp[maxn][2]; // 0 means facing left and 1 means facing right
ll v[maxn];
ll flag=0;
ll vis[maxn][2];
bool dfs(ll u,ll dir)
{
	if(vis[u][dir]==2 || u>n || u<=0) return true;
	if(vis[u][dir]==1 || u==1) return false;
	//watch(u);
	vis[u][dir]=1;
	dp[u][dir]=v[u];
	ll nex,dirnew;
	if(dir==0) nex=u-v[u];
	else nex=u+v[u];
	dirnew=dir^1;
	if(dfs(nex,dirnew))
	{
		if(nex>0 || nex<=n) dp[u][dir]+=dp[nex][dirnew];
		vis[u][dir]=2;
		return true;
	}
	else
	{
		return false;
	}
}
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
	cin>>n;
	repA(i,2,n) cin>>v[i];
	vis[1][0]=1;
	vis[1][1]=1;
	for(int i=1;i<n;i++)
	{
		//watch(i);
		v[1]=i;
		if(dfs(1+v[1],0))
		{
			cout<<v[1]+dp[1+v[1]][0]<<'\n';
		}
		else cout<<-1<<'\n';
	}
	return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
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;} // modular exponent
ll n;
const int maxn=1e6;
ll dp[maxn][2]; // 0 means facing left and 1 means facing right
ll v[maxn];
ll flag=0;
ll vis[maxn][2];
bool dfs(ll u,ll dir)
{
	if(u>n || u<=0) return true;
	if(vis[u][dir]==2) return true;
	if(vis[u][dir]==1 || u==1) return false;
	//watch(u);
	vis[u][dir]=1;
	dp[u][dir]=v[u];
	ll nex,dirnew;
	if(dir==0) nex=u-v[u];
	else nex=u+v[u];
	dirnew=dir^1;
	if(dfs(nex,dirnew))
	{
		if(nex>0 && nex<=n) dp[u][dir]+=dp[nex][dirnew];
		vis[u][dir]=2;
		return true;
	}
	else
	{
		return false;
	}
}
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
	cin>>n;
	repA(i,2,n) cin>>v[i];
	vis[1][0]=1;
	vis[1][1]=1;
	for(int i=1;i<n;i++)
	{
		//watch(i);
		v[1]=i;
		if(dfs(1+v[1],0))
		{
			if(1+v[1]<=n) cout<<v[1]+dp[1+v[1]][0]<<'\n';
			else cout<<v[1]<<'\n';
		}
		else cout<<-1<<'\n';
	}
	return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
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;} // modular exponent
ll n;
const int maxn=2e5+5;
ll dp[maxn][2]; // 0 means facing left and 1 means facing right
ll v[maxn];
ll flag=0;
ll vis[maxn][2];
bool dfs(ll u,ll dir)
{
	if(vis[u][dir]==2 || u>n || u<=0) return true;
	if(vis[u][dir]==1 || u==1) return false;
	vis[u][dir]=1;
	dp[u][dir]=v[u];
	ll nex,dirnew;
	if(dir==0) nex=u-v[u];
	else nex=u+v[u];
	dirnew=dir^1;
	if(dfs(nex,dirnew))
	{
		if(nex>0 || nex<=n) dp[u][dir]+=dp[nex][dirnew];
		vis[u][dir]=2;
		return true;
	}
	else
	{
		vis[u][dir]=2;
		return false;
	}
}
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
	cin>>n;
	repA(i,2,n) cin>>v[i];
	vis[1][0]=1;
	vis[1][1]=1;
	for(int i=1;i<n;i++)
	{
		v[1]=i;
		if(dfs(1+v[1],0))
		{
			cout<<v[1]+dp[1+v[1]][0]<<'\n';
		}
		else cout<<-1<<'\n';
	}
	return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
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;} // modular exponent
ll n;
const int maxn=2e5+5;
ll dp[maxn][2]; // 0 means facing left and 1 means facing right
ll v[maxn];
ll flag=0;
ll vis[maxn][2];
bool dfs(ll u,ll dir)
{
	if(u>n || u<=0 || vis[u][dir]==2) return true;
	if(vis[u][dir]==1 || u==1) return false;
	//watch(u);
	vis[u][dir]=1;
	dp[u][dir]=v[u];
	ll nex,dirnew;
	if(dir==0) nex=u-v[u];
	else nex=u+v[u];
	dirnew=dir^1;
	if(dfs(nex,dirnew))
	{
		if(nex>0 || nex<=n) dp[u][dir]+=dp[nex][dirnew];
		vis[u][dir]=2;
		return true;
	}
	else
	{
		return false;
	}
}
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
	cin>>n;
	repA(i,2,n) cin>>v[i];
	vis[1][0]=1;
	vis[1][1]=1;
	for(int i=1;i<n;i++)
	{
		//watch(i);
		v[1]=i;
		if(dfs(1+v[1],0))
		{
			cout<<v[1]+dp[1+v[1]][0]<<'\n';
		}
		else cout<<-1<<'\n';
	}
	return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
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;} // modular exponent
ll n;
const int maxn=1e6;
ll dp[maxn][2]; // 0 means facing left and 1 means facing right
ll v[maxn];
ll flag=0;
ll vis[maxn][2];
bool dfs(ll u,ll dir)
{
	if(u>n || u<=0) return true;
	if(vis[u][dir]==2) return true;
	if(vis[u][dir]==1 || u==1) return false;
	//watch(u);
	vis[u][dir]=1;
	dp[u][dir]=v[u];
	ll nex,dirnew;
	if(dir==0) nex=u-v[u];
	else nex=u+v[u];
	dirnew=dir^1;
	if(dfs(nex,dirnew))
	{
		if(nex>0 || nex<=n) dp[u][dir]+=dp[nex][dirnew];
		vis[u][dir]=2;
		return true;
	}
	else
	{
		return false;
	}
}
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
	cin>>n;
	repA(i,2,n) cin>>v[i];
	vis[1][0]=1;
	vis[1][1]=1;
	for(int i=1;i<n;i++)
	{
		//watch(i);
		v[1]=i;
		if(dfs(1+v[1],0))
		{
			cout<<v[1]+dp[1+v[1]][0]<<'\n';
		}
		else cout<<-1<<'\n';
	}
	return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
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;} // modular exponent
ll n;
const int maxn=1e6;
ll dp[maxn][2]; // 0 means facing left and 1 means facing right
ll v[maxn];
ll flag=0;
ll vis[maxn][2];
bool dfs(ll u,ll dir)
{
	if(u>n || u<=0) return true;
	if(vis[u][dir]==2) return true;
	if(vis[u][dir]==1 || u==1) return false;
	//watch(u);
	vis[u][dir]=1;
	dp[u][dir]=v[u];
	ll nex,dirnew;
	if(dir==0) nex=u-v[u];
	else nex=u+v[u];
	dirnew=dir^1;
	if(dfs(nex,dirnew))
	{
		if(nex>0 || nex<=n) dp[u][dir]+=dp[nex][dirnew];
		vis[u][dir]=2;
		return true;
	}
	else
	{
		return false;
	}
}
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
	cin>>n;
	repA(i,2,n) cin>>v[i];
	vis[1][0]=1;
	vis[1][1]=1;
	for(int i=1;i<n;i++)
	{
		//watch(i);
		v[1]=i;
		if(dfs(1+v[1],0))
		{
			if(1+v[1]<=n) cout<<v[1]+dp[1+v[1]][0]<<'\n';
			else cout<<v[1]<<'\n';
		}
		else cout<<-1<<'\n';
	}
	return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
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;} // modular exponent
ll n;
const int maxn=2e5+5;
ll dp[maxn][2]; // 0 means facing left and 1 means facing right
ll v[maxn];
ll flag=0;
ll vis[maxn][2];
bool dfs(ll u,ll dir)
{
	if(u>n || u<=0) return true;
	if(vis[u][dir]==2) return true;
	if(vis[u][dir]==1 || u==1) return false;
	//watch(u);
	vis[u][dir]=1;
	dp[u][dir]=v[u];
	ll nex,dirnew;
	if(dir==0) nex=u-v[u];
	else nex=u+v[u];
	dirnew=dir^1;
	if(dfs(nex,dirnew))
	{
		if(nex>0 || nex<=n) dp[u][dir]+=dp[nex][dirnew];
		vis[u][dir]=2;
		return true;
	}
	else
	{
		return false;
	}
}
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
	cin>>n;
	repA(i,2,n) cin>>v[i];
	vis[1][0]=1;
	vis[1][1]=1;
	for(int i=1;i<n;i++)
	{
		//watch(i);
		v[1]=i;
		if(dfs(1+v[1],0))
		{
			cout<<v[1]+dp[1+v[1]][0]<<'\n';
		}
		else cout<<-1<<'\n';
	}
	return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


#include <bits/stdc++.h>

using namespace std;

const int N = 234567;

int n;
long long a[N];
long long dp[2][N];
bool vis[2][N];

void dfs(int u, bool type) {
	int v = u;
	if (type)
		v += a[u];
	else
		v -= a[u];

	if (v <= 0 || v > n) {
		dp[type][u] = a[u];
		return;
	}

	if (!vis[!type][v]) {
		vis[!type][v] = 1;
		dfs(v, !type);
	}
	else {
		if (dp[!type][v] == 0)
			dp[!type][v] = -1;

		if (dp[!type][v] == -1)
			dp[type][u] = -1;
		else
			dp[type][u] = a[u] + dp[!type][v];

		return;
	}

	if (dp[!type][v] == -1)
		dp[type][u] = -1;
	else
		dp[type][u] = a[u] + dp[!type][v];
}

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

	cin>>n;
	for (int i = 2; i <= n; i++)
		cin>>a[i];

	vis[0][1] = 1, vis[1][1] = 1;
	dp[0][1] = -1, dp[1][1] = -1;
	for (int type = 0; type <= 1; type++)
		for (int u = 2; u <= n; u++)
			if (!vis[type][u])
				vis[type][u] = 1, dfs(u, type);

	for (int u = 2; u <= n; u++)
		if (dp[0][u] == -1)
			cout<<-1<<endl;
		else
			cout<<(u - 1 + dp[0][u])<<endl;

	return 0;
}


/*input
5
2 2 1 3
*/
#include <bits/stdc++.h>

using namespace std;

const int N = 234567;

int n;
int a[N];
int dp[2][N];
bool vis[2][N];

void dfs(int u, bool type) {
	int v = u;
	if (type)
		v += a[u];
	else
		v -= a[u];
	// cout<<"Called dfs("<<u<<", "<<type<<")"<<", v = "<<v<<endl;

	if (v <= 0 || v > n) {
		dp[type][u] = a[u];
		return;
	}

	if (!vis[!type][v]) {
		// cout<<"2. dfs("<<u<<", "<<type<<")"<<endl;
		vis[!type][v] = 1;
		dfs(v, !type);
	}
	else {
		// cout<<"3. dfs("<<u<<", "<<type<<")"<<": dp[!type][v] = "<<dp[!type][v]<<endl;
		if (dp[!type][v] == 0)
			dp[!type][v] = -1;

		if (dp[!type][v] == -1)
			dp[type][u] = -1;
		else
			dp[type][u] = a[u] + dp[!type][v];

		return;
	}

	// cout<<"4. dfs("<<u<<", "<<type<<")"<<endl;
	if (dp[!type][v] == -1)
		dp[type][u] = -1;
	else
		dp[type][u] = a[u] + dp[!type][v];
}

int main() {
	ios::sync_with_stdio(0);

	cin>>n;
	for (int i = 2; i <= n; i++)
		cin>>a[i];

	vis[0][1] = 1, vis[1][1] = 1;
	dp[0][1] = -1, dp[1][1] = -1;
	for (int type = 0; type <= 1; type++)
		for (int u = 2; u <= n; u++)
			if (!vis[type][u]) {
				vis[type][u] = 1, dfs(u, type);
				// cout<<"Call finished"<<endl<<endl;
			}

	// for (int u = 2; u <= n; u++)
	// 	cout<<dp[0][u]<<" ";
	// cout<<endl;

	for (int u = 2; u <= n; u++)
		if (dp[0][u] == -1)
			cout<<-1<<endl;
		else
			cout<<(u - 1 + dp[0][u])<<endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 234567;

int n;
int a[N];
int dp[2][N];
bool vis[2][N];

void dfs(int u, bool type) {
	int v = u;
	if (type)
		v += a[u];
	else
		v -= a[u];

	if (v <= 0 || v > n) {
		dp[type][u] = a[u];
		return;
	}

	if (!vis[!type][v]) {
		vis[!type][v] = 1;
		dfs(v, !type);
	}
	else {
		if (dp[!type][v] == 0)
			dp[!type][v] = -1;

		if (dp[!type][v] == -1)
			dp[type][u] = -1;
		else
			dp[type][u] = a[u] + dp[!type][v];

		return;
	}

	dp[type][u] = a[u] + dp[!type][v];
}

int main() {
	ios::sync_with_stdio(0);

	cin>>n;
	for (int i = 2; i <= n; i++)
		cin>>a[i];

	vis[0][1] = 1, vis[1][1] = 1;
	dp[0][1] = -1, dp[1][1] = -1;
	for (int type = 0; type <= 1; type++)
		for (int u = 2; u <= n; u++)
			if (!vis[type][u])
				vis[type][u] = 1, dfs(u, type);

	// for (int u = 2; u <= n; u++)
	// 	cout<<dp[0][u]<<" ";
	// cout<<endl;

	for (int u = 2; u <= n; u++)
		if (dp[0][u] == -1)
			cout<<-1<<endl;
		else
			cout<<(u - 1 + dp[0][u])<<endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const it N = 234567;

int n;
long long a[N];
long long dp[2][N];
bool vis[2][N];

void dfs(int u, bool type) {
	int v = u;
	if (type)
		v += a[u];
	else
		v -= a[u];

	if (v <= 0 || v > n) {
		dp[type][u] = a[u];
		return;
	}

	if (!vis[!type][v]) {
		vis[!type][v] = 1;
		dfs(v, !type);
	}
	else {
		if (dp[!type][v] == 0)
			dp[!type][v] = -1;

		if (dp[!type][v] == -1)
			dp[type][u] = -1;
		else
			dp[type][u] = a[u] + dp[!type][v];

		return;
	}

	if (dp[!type][v] == -1)
		dp[type][u] = -1;
	else
		dp[type][u] = a[u] + dp[!type][v];
}

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

	cin>>n;
	for (inti = 2; i <= n; i++)
		cin>>a[i];

	vis[0][1] = 1, vis[1][1] = 1;
	dp[0][1] = -1, dp[1][1] = -1;
	for (int type = 0; type <= 1; type++)
		for (int u = 2; u <= n; u++)
			if (!vis[type][u])
				vis[type][u] = 1, dfs(u, type);

	for (int u = 2; u <= n; u++)
		if (dp[0][u] == -1)
			cout<<-1<<endl;
		else
			cout<<(u - 1 + dp[0][u])<<endl;

	return 0;
}


/*input
5
2 2 1 3
*/
#include <bits/stdc++.h>

using namespace std;

const long long N = 234567;

long long n;
long long a[N];
long long dp[2][N];
bool vis[2][N];

void dfs(long long u, bool type) {
	long long v = u;
	if (type)
		v += a[u];
	else
		v -= a[u];
	// cout<<"Called dfs("<<u<<", "<<type<<")"<<", v = "<<v<<endl;

	if (v <= 0 || v > n) {
		dp[type][u] = a[u];
		return;
	}

	if (!vis[!type][v]) {
		// cout<<"2. dfs("<<u<<", "<<type<<")"<<endl;
		vis[!type][v] = 1;
		dfs(v, !type);
	}
	else {
		// cout<<"3. dfs("<<u<<", "<<type<<")"<<": dp[!type][v] = "<<dp[!type][v]<<endl;
		if (dp[!type][v] == 0)
			dp[!type][v] = -1;

		if (dp[!type][v] == -1)
			dp[type][u] = -1;
		else
			dp[type][u] = a[u] + dp[!type][v];

		return;
	}

	// cout<<"4. dfs("<<u<<", "<<type<<")"<<endl;
	if (dp[!type][v] == -1)
		dp[type][u] = -1;
	else
		dp[type][u] = a[u] + dp[!type][v];
}

int main() {
	ios::sync_with_stdio(0);

	cin>>n;
	for (long long i = 2; i <= n; i++)
		cin>>a[i];

	vis[0][1] = 1, vis[1][1] = 1;
	dp[0][1] = -1, dp[1][1] = -1;
	for (long long type = 0; type <= 1; type++)
		for (long long u = 2; u <= n; u++)
			if (!vis[type][u]) {
				vis[type][u] = 1, dfs(u, type);
				// cout<<"Call finished"<<endl<<endl;
			}

	// for (long long u = 2; u <= n; u++)
	// 	cout<<dp[0][u]<<" ";
	// cout<<endl;

	for (long long u = 2; u <= n; u++)
		if (dp[0][u] == -1)
			cout<<-1<<endl;
		else
			cout<<(u - 1 + dp[0][u])<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,a[200005],vis[200005],dp[200005],k;
int dfs(int x)
{
    vis[x]=k;
    if(x<=0||x>n)return 0;
    if(dp[x]!=-1)return dp[x];
    if(vis[x+a[x]-a[x+a[x]]]==k)return dp[x]-1e9;
    return dp[x]=dfs(x+a[x]-a[x+a[x]])+a[x]+a[x+a[x]];
    vis[x]=0;
}
int main()
{
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(int i=2;i<=n;i++)cin>>a[i];
    for(int i=1;i<n;i++)
    {
        k++;
        a[1]=i;
        dp[1]=-1;
        int x=dfs(1);
        if(x<0)cout<<-1<<endl;
        else cout<<x<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,a[200005],vis[200005],dp[200005],k;
int dfs(int x)
{
    vis[x]=k;
    if(x<=0||x>n)return 0;
    if(dp[x]!=-1)return dp[x];
    if(vis[x+a[x]-a[x+a[x]]]==k)return dp[x]=-1e9;
    return dp[x]=dfs(x+a[x]-a[x+a[x]])+a[x]+a[x+a[x]];
    vis[x]=0;
}
int main()
{
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(int i=2;i<=n;i++)cin>>a[i];
    for(int i=n;i>=2;i--)
    {
        k++;
        dfs(i);
    }
    for(int i=1;i<n;i++)
    {
        k++;
        a[1]=i;
        dp[1]=-1;
        int x=dfs(1);
        if(x<0)cout<<-1<<endl;
        else cout<<x<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,a[200505],vis[200505],dp[200505],k;
int dfs(int x)
{
    if(x<=0||x>n)return 0;
    vis[x]=k;
    if(dp[x]!=-1)return dp[x];
    if(vis[x+a[x]-a[x+a[x]]]==k)return dp[x]=-1e9;
    return dp[x]=dfs(x+a[x]-a[x+a[x]])+a[x]+a[x+a[x]];
    vis[x]=0;
}
int main()
{
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(int i=2;i<=n;i++)cin>>a[i];
    for(int i=n;i>=2;i--)
    {
        k++;
        dfs(i);
    }
    for(int i=1;i<n;i++)
    {
        k++;
        a[1]=i;
        dp[1]=-1;
        int x=dfs(1);
        if(x<0)cout<<-1<<endl;
        else cout<<x<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
long long n,a[200505],vis[200505],dp[3][200505],k;
long long dfs(int z,long long x)
{
    if(x<=0||x>n)return 0;
    if(dp[z][x]!=-1)return dp[z][x];
    if(vis[x]==k)return dp[z][x]=-1e15;
    vis[x]=k;
    if(z==0)return dp[z][x]=dfs(1,x+a[x])+a[x];
    else return dp[z][x]=dfs(0,x-a[x])+a[x];
}
int main()
{
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(int i=2;i<=n;i++)cin>>a[i];
    for(int i=1;i<n;i++)
    {
        k++;
        a[1]=i;
        dp[0][1]=-1;
        long long x=dfs(0,1);
        if(x<0)cout<<-1<<endl;
        else cout<<x<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
long long n,a[200505],vis[200505],dp[3][200505],k;
long long dfs(int z,long long x)
{
    if(x<=0||x>n)return 0;
    if(dp[z][x]!=-1)return dp[z][x];
    if(vis[x]==k)return -1e18;
    vis[x]=k;
    if(z==0)return dp[z][x]=dfs(1,x+a[x])+a[x];
    else return dp[z][x]=dfs(0,x-a[x])+a[x];
}
int main()
{
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(int i=2;i<=n;i++)cin>>a[i];
    for(int i=1;i<n;i++)
    {
        k++;
        a[1]=i;
        dp[0][1]=-1;
        long long x=dfs(0,1);
        if(x<0)cout<<-1<<endl;
        else cout<<x<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define M 1000000007
typedef pair<lli,lli> ll;
#define mem(a,x) memset(a,x,sizeof(a))
bool cmp(ll a,ll b)
{
    if(a.first==b.first)
    return a.second>b.second;
    return a.first<b.first;
}
float area(float x1,float y1,float x2,float y2,float x3,float y3)
{
    return abs((x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2.0);
}
bool check(float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4,float x,float y)
{
    float a=area(x1,y1,x2,y2,x3,y3)+area(x1,y1,x4,y4,x3,y3);
    float a1=area(x1,y1,x2,y2,x,y);
    float a2=area(x2,y2,x3,y3,x,y);
    float a3=area(x3,y3,x4,y4,x,y);
    float a4=area(x1,y1,x4,y4,x,y);
    if(a==(a1+a2+a3+a4))
    return true;
    return false;
}
lli gcd(lli a,lli b)
{
    if(b==0)
    return a;
    return gcd(b,a%b);
}
string s;
lli n,c,d,k,l,r,x,y;
int b[100007];
int a[100007];
int main()
{
map<int,int> m1;
map<int,int,greater<int>> m2;
int m;
cin>>n>>m;
lli p=n/m;
for(int j=0;j<n;j++)
{
    cin>>a[j];
    m1[a[j]%m]++;
}
for(auto it=m1.begin();it!=m1.end();it++)
{
    m2[it->second]=it->first;
}
lli p1;
lli c=0;
vector<int> v[m];
for(int j=0;j<=m-1;j++)
{
    while(m1[j]<n/m)
    {
        m1[j]++;
        c+=min(abs(m2.begin()->second-j),abs(m-m2.begin()->second+j));
        v[m2.begin()->second].push_back(min(abs(m2.begin()->second-j),abs(m-m2.begin()->second+j)));
        m1[m2.begin()->second]--;
    }
}
cout<<c<<endl;
for(int i=0;i<n;i++)
{
    if(v[a[i]%m].size()>0)
    {
    lli d=v[a[i]%m][v[a[i]%m].size()-1];
    v[a[i]%m].pop_back();
    a[i]+=d;
    }
    cout<<a[i]<<" ";
}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define M 1000000007
typedef pair<lli,lli> ll;
#define mem(a,x) memset(a,x,sizeof(a))
string s;
lli n;
int main()
{
unordered_map<int,int> m1;
map<int,int,greater<int>> m2;
int m;
cin>>n>>m;
int a[n];
lli p=n/m;
stack<int> v[100007];
for(int j=0;j<n;j++)
{
    cin>>a[j];
    m1[a[j]%m]++;
    v[(a[j]%m+m)%m].push(j);
}
for(auto it=m1.begin();it!=m1.end();it++)
{
    m2[it->second]=it->first;
}
lli c=0;
for(int j=0;j<=m-1;j++)
{
    int flag=0;
    auto it=m2.begin();
    while(m1[j]<n/m)
    {
        lli d=min(abs(m2.begin()->second-j),abs(m-m2.begin()->second+j));
        while(v[it->second].size()<=n/m)
        it++;
        if(v[it->second].size()<=n/m)
        {
            flag=1;
            break;
        }
        if(v[it->second].top()<n)
        {
        a[v[it->second].top()]+=d;
        v[it->second].pop();
        }
        else
        {
            flag=1;
            break;
        }
        c+=d;
        m1[it->second]--;
        m1[j]++;
    }
    if(flag)
    break;
}
cout<<c<<endl;
for(int j=0;j<n;j++)
{
    cout<<a[j]<<" ";
}
}