#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <climits>
using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef long long LL;
typedef pair<int, int> PII;

#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define FOREACH(it,c) for(auto it=(c).begin();it!=(c).end();++it)
#define FILLCHAR(a, x) memset(a, x, sizeof(a))
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()

int lowerbit(int n) {
    return n & (~(n - 1));
}

int main() {
    int sum, limit;
    while (cin >> sum >> limit) {
        map<int, VI> nums;
        FOR(i,1,limit) {
            nums[lowerbit(i)].push_back(i);
        }

        map<int, int> nums2Used;
        FOREACH(it,nums) {
            nums2Used[it->first] = 0;
        }

        set<int> result;
        while (sum) {
            int l = lowerbit(sum);

            int cnt = 0;
            bool find = false;
            int carry = 0;
            int firstCarry = 0;
            FOREACH(it,nums) {
                if (it->first >= l) break;

                int left = (it->second.size() - nums2Used[it->first]);
                carry = (left + carry) / 2;

                if (carry) if (firstCarry == 0) firstCarry = it->first;
                else firstCarry = 0;
            }

            if (carry) {
                FOREACH(it,nums) {
                    if (it->first >= l) break;

                    int left = (it->second.size() - nums2Used[it->first]);
                    if (it->first >= firstCarry) {
                        int add = 0;
                        for (int i = 0; i < left; i += 2) {
                            result.insert(it->second[nums2Used[it->first] + i]);
                            add++;
                            if (nums2Used[it->first] + i + 1< it->second.size()) {
                                result.insert(it->second[nums2Used[it->first] + i + 1]);
                                add++;
                            }
                        }

                        nums2Used[it->first] += add;
                    }
                }
            } else if (nums.count(l) && nums[l].size()) {
                result.insert(nums[l][nums2Used[l]]);
                nums2Used[l]++;
            } else {
                break;
            }

            sum = sum & (~l);
        }

        if (sum) {
            printf("-1\n");
        } else {
            printf("%d\n", result.size());
            bool first = true;
            for (int c : result) {
                if (!first)
                    printf(" ");
                printf("%d", c);
                first = false;
            }

            printf("\n");
        }
    }
}


#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <climits>
using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef long long LL;
typedef pair<int, int> PII;

#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define FOREACH(it,c) for(auto it=(c).begin();it!=(c).end();++it)
#define FILLCHAR(a, x) memset(a, x, sizeof(a))
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()

int lowerbit(int n) {
    return n & (~(n - 1));
}

bool find(map<int, VI> &nums, map<int, int> &nums2Used, int left, int now, set<int>& r) {
    if (left == 0) return true;
    if (now == 0) return false;
    int countNum = 0;
    if (nums.count(now) && ((countNum = (int) nums[now].size() - nums2Used[now])) > 0) {
        int tOfNow= countNum * now;
        if (left >= tOfNow) {
            left -= tOfNow;
            for (int i = nums2Used[now]; i < nums[now].size(); i++) {
                r.insert(nums[now][i]);
            }
            nums2Used[now] = nums[now].size();
        } else {
            int k = left / now;
            left = left % now;
            for (int i = 0; i < k; i++) {
                r.insert(nums[now][nums2Used[now] + i]);
            }
            nums2Used[now] += k;
        }
    }
    return find(nums, nums2Used, left, now / 2, r);
}

int main() {
    int sum, limit;
    while (cin >> sum >> limit) {
        map<int, VI> nums;
        FOR(i,1,limit) {
            nums[lowerbit(i)].push_back(i);
        }

        map<int, int> nums2Used;
        FOREACH(it,nums) {
            nums2Used[it->first] = 0;
        }

        set<int> result;
        while (sum) {
            int l = lowerbit(sum);

            set<int> current;
            if (find(nums, nums2Used, l, l, current)) {
                result.insert(current.begin(), current.end());
            } else {
                break;
            }

            sum = sum & (~l);
        }

        if (sum) {
            printf("-1\n");
        } else {
            printf("%d\n", result.size());
            bool first = true;
            for (int c : result) {
                if (!first)
                    printf(" ");
                printf("%d", c);
                first = false;
            }

            printf("\n");
        }
    }
}


#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>

#define oo 1e9
#define pi 3.1415926536
#define all(x) x.begin(),x.end()
#define sorta(x) sort(all(x))
#define sortam(x,comp) sort(all(x),comp)
#define sortd(x) sort(x.rbegin(),x.rend())
#define pb push_back
#define mp make_pair

typedef long long ll;
using namespace std;
int lowbit(int a) {
    int ret = 0;
    while(a) {
        if(a % 2) return pow(2, ret);
        a /= 2;
        ret++;
    }
    return pow(2, ret);
}

int main() {
    int lim, sum;
    while(cin >> sum >> lim) {
        vector<int>res;
        for(int i = lim; i > 0 && sum; i--) {
            int tmp = lowbit(i);
            if(tmp <= sum) sum -= tmp, res.push_back(i);
        }

        if(sum) { cout << -1 << endl; continue; }

        cout << res.size() << endl;
        for(int i = 0; i < res.size(); i++) cout << res[i] << ' ';
        cout << endl;

    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <tuple>
#include <limits>

using namespace std;
typedef tuple<int,int> tpl;

int lowbit(int x){
    int result = 1;
    while((x & 1) == 0){
        x = x >> 1;
        result *= 2;
    }
    return result;
}

int main(){
    int sum, limit;
    cin >> sum >> limit;
    vector<tpl> A;
    for(int i = 1; i <= limit; i++) A.push_back(tpl(lowbit(i),i));
    std::sort(A.begin(),A.end(),[](tpl a, tpl b){return a < b;});
    vector<int> answer;
    for(int i = A.size()-1; i >= 0; i--){
        if(sum - get<0>(A[i]) >= 0){
            sum -= get<0>(A[i]);
            answer.push_back(get<1>(A[i]));
        }
        if(sum == 0) break;
        if(i == 0) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << answer.size() << endl;
    for(auto &x : answer) cout << x << " ";
    cout << endl;
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);

    int sum, limit;
    cin >> sum >> limit;

    int n = 0;
    int t = 1;
    while (t <= limit)
    {
        t <<= 1;
        ++n;
    }
    --n;

    vector<int> result;
    for (int i = n; i >= 0 && sum > 0; --i)
    {
        int u = 1 << i;
        int count = limit >> (i+1);
        if (limit & u) ++count;

        for (int j = 0; j < count && sum >= u; ++j)
        {
            sum -= u;
            int t = (j << (i+1)) + u;
            result.push_back(t);
        }
    }

    if (sum > 0)
    {
        cout << -1 << endl;
        return 0;
    }

    cout << result.size() << endl;
    for (auto v: result) cout << v << " ";
    cout << endl;

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);

    int sum, limit;
    cin >> sum >> limit;

    int n = 0;
    int t = limit;
    while (t > 1)
    {
        t >>= 1;
        ++n;
    }

    vector<int> result;
    for (int i = n; i >= 0 && sum > 0; --i)
    {
        int u = 1 << i;

        for (int j = 0; sum >= u; ++j)
        {
            int t = (j << (i+1)) + u;
            if (t > limit) break;

            sum -= u;
            result.push_back(t);
        }
    }

    if (sum > 0)
    {
        cout << -1 << endl;
        return 0;
    }

    cout << result.size() << endl;
    for (auto v: result) cout << v << " ";
    cout << endl;

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);

    int sum, limit;
    cin >> sum >> limit;

    int n = 0;
    int t = 1;
    while (t <= limit)
    {
        t <<= 1;
        ++n;
    }
    --n;

    vector<int> result;
    for (int i = n; i >= 0 && sum > 0; --i)
    {
        int u = 1 << i;
        int count = limit >> (i+1);
        if (limit & u) ++count;

        for (int j = 0; j < count && sum >= u; ++j)
        {
            sum -= u;
            int s = i == 0 ? 1 : i;
            int t = (j << s) + u;
            result.push_back(t);
        }
    }

    if (sum > 0)
    {
        cout << -1 << endl;
        return 0;
    }

    cout << result.size() << endl;
    for (auto v: result) cout << v << " ";
    cout << endl;

    return 0;
}


#include <cstdio>
const int MAX_N = 1e5 + 10;
int n;
int r[MAX_N];

int lowbit(int x){
  return x & -x;
}

int main(){
  int sum, limit;
  scanf("%d%d", &sum, &limit);
  for(int i = limit; i >= 1; i--){
    int l = i & -i;
    if(sum - l >= 0){
      sum -= l;
      r[n++] = i;
    }
  }
  if(sum == 0){
    printf("%d\n", n);
    for(int i = 0; i < n; i++){
      printf("%d\n", r[i]);
    }
  } else {
    printf("%d\n", -1);
  }
  return 0;
}


//Program: b
//Author: gary
//Date: 01/06/2014
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) ( (int) (x).size() )
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef pair<int, int> i2;
typedef long long ll;
const int INF = 1e9;
const int MAX_N = 1e5 + 10;

int N, M;
int A[MAX_N];
int O[MAX_N];
int fix[MAX_N];
int act[MAX_N];
vector<int> E[MAX_N];
int f[MAX_N], sz[MAX_N];
int getf(int i){ return f[i] == i ? i : f[i] = getf(f[i]);}
int samef(int i, int j){return getf(i)==getf(j);}
void mergef(int i, int j){
  if(samef(i,j)) return;
  sz[getf(j)] += sz[getf(i)];
  f[getf(i)] = getf(j);
}
int main(){
  ios::sync_with_stdio(0);
  while(cin >> N >> M){
    for(int i = 1; i <= N; i++){
      cin >> A[i];
      E[i].clear();
      O[i - 1] = i;
      f[i] = i;
      sz[i] = 1;
    }
    for(int i = 0; i < M; i++){
      int u, v;
      cin >> u >> v;
      E[u].pb(v);
      E[v].pb(u);
    }
    sort(O, O + N, [&] (const int & i, const int & j) -> bool {return A[i] > A[j]; });
    memset(fix, 0, sizeof fix);
    memset(act, 0, sizeof act);
    long long sum = 0;
    for(int i = 0; i < N; i++){
      int u = O[i], x;
      ll s = 0;
      act[u] = 1;
      for(int v: E[u]){
	x = getf(v);
	if(act[v] && !fix[x]){
	  fix[x] = 1;
	  sum += (ll) sz[x] * A[u];
	  sum += (ll) A[u] * s * sz[x];
	  s += sz[x];
	}
      }
      for(int v: E[u]){
	if(act[v]){
	  fix[getf(v)] = 0;
	  mergef(u, v);
	}
      }
    }
    cout << setprecision(10) <<  double(sum * 2) / (double(N) * double(N - 1)) << endl;
  }
  return 0;
}


#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#define FOR(x, y, z) for (int x = y; x < z; ++x)
#define FORR(x, y, z) for (int x = y; x > z; --x)
#define SORT(a) sort(a.begin(), a.end())
#define SORTR(a) sort(a.rbegin(), a.rend())
#define GET(a, n) for (int i = 0; i < n; ++i) cin >> a[i];
#define GETM(a, n, m) for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> a[i][j];
#define PRINT(a, n) for (int i = 0; i < n; ++i) cout << a[i] << " ";
#define LL long long
#define ULL unsigned long long
#define VI vector <int>
#define VVI vector <vector<int>>
#define GETSUM(sum, n) sum = 0; for (int i = 0; i < n; ++i) { int tmp; cin >> tmp; sum += tmp; }
#define SUM(a, n, sum) sum = 0; for (int i = 0; i < n; ++i) { sum += a[i]; }
#define COUNT(a, n, t, count) count = 0; for (int i = 0; i < n; ++i) { if (a[i] == t) ++count; }

using namespace std;

struct Bit
{
    int i;
    int lowbit;
};

int main()
{
    int sum, limit;
    cin >> sum >> limit;
    vector <Bit> v(limit);
    FOR (i, 0, limit) {
        int c = i + 1;
        int r = 1;
        while ((c & 1) == 0) {
            c >>= 1;
            r <<= 1;
        }
        v[i].i = i + 1;
        v[i].lowbit = r;
    }
    sort(v.begin(), v.end(), [](Bit a, Bit b) { return a.lowbit < b.lowbit; });
    VI a;
    int t = limit - 1;
    while (sum != 0) {
        while (t >= 0 && sum < v[t].lowbit)
            --t;
        if (t < 0) {
            cout << -1;
            return 0;
        }
        a.push_back(v[t].i);
        sum -= v[t].lowbit;
        --t;
    }
    cout << a.size() << endl;
    PRINT(a, a.size());
}


#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<sstream>
#include<cmath>
using namespace std;

void display(set<int> S)
{
    cout << S.size() << "\n";
    for (set<int>::iterator it = S.begin(); it != S.end(); it++)
    {
        cout << *it << " ";
    }
    cout << "\n";
}

int low_bit(int A, vector<int> V)
{
    for (int i = 0; i<20; i++)
    {
        if (A >= V[i] && A < V[i + 1])
            return V[i];
    }
    return V[V.size() - 1];
}
int main()
{
    /*int F;
    cin >> F;
    cout << low_bit(F)<<"\n";
    return 0;*/

    int sum, limit,Sum=0;
    int odds, evens;
    set<int> s;
    vector<int> Sums;
    cin >> sum >> limit;
    for (int i = 0; i <= 20; i++)
    {
        Sums.push_back(pow(2, i));
    }
    evens = limit / 2;
    odds = evens + (limit % 2);

    for (int i = 2 * evens; i>0; i -= 2)
    {
        int temp = Sum + low_bit(i, Sums);
        if (temp < sum)
        {
            Sum = temp;
            s.insert(i);
        }
        else if (temp == sum)
        {
            Sum = temp;
            s.insert(i);
            display(s);
            return 0;
        }
        else
        {
            i = low_bit(i, Sums) - 2;
        }
    }

    if (sum - Sum > odds)
    {
        cout << "-1\n";
        return 0;
    }
    int j = 1;
    for (int i = 0; i < sum - Sum; i++)
    {
        s.insert(j);
        j += 2;
    }
    display(s);

}


#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<sstream>
#include<cmath>
using namespace std;

int low_bit(int n)
{
    int Counter = 0;
    while (n>0)
    {
        if (n % 2 == 1)
            return pow(2,Counter);
        n = n / 2;
        Counter++;
    }
    return -1;
}

void display(set<int> S)
{
    cout << S.size() << "\n";
    for (set<int>::iterator it = S.begin(); it != S.end(); it++)
    {
        cout << *it << " ";
    }
    cout << "\n";
}

int main()
{
    /*int F;
    cin >> F;
    cout << low_bit(F)<<"\n";
    return 0;*/

    int sum, limit,Sum=0;
    set<int> s;

    cin >> sum >> limit;

    for (int i = 0; i < limit; i++)
    {
        int count = 0;
        s.clear();
        Sum = 0;
        for (int j = i + 1; j <= limit;  j++)
        {
            int temp = Sum+low_bit(j);
            if (temp > sum || s.size() > limit)
                break;
            else if (temp < sum)
            {
                Sum = temp;
                s.insert(j);
            }
            else if (temp == sum)
            {
                s.insert(j);
                display(s);
                return 0;
            }
        }
    }
    cout << "-1\n";
    return 0;
}


#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<sstream>
#include<cmath>
using namespace std;

void display(set<int> S)
{
    cout << S.size() << "\n";
    for (set<int>::iterator it = S.begin(); it != S.end(); it++)
    {
        cout << *it << " ";
    }
    cout << "\n";
}

int low_bit(int A, vector<int> V)
{
    int Counter = 0;
    while (A>0)
    {
        if (A % 2 == 1)
            return pow(2,Counter);
        Counter++;
        A = A / 2;
    }
    return -1;
}
int main()
{
    /*int F;
    cin >> F;
    cout << low_bit(F)<<"\n";
    return 0;*/

    int sum, limit,Sum=0;
    int odds, evens;
    set<int> s;
    vector<int> Sums;
    cin >> sum >> limit;
    for (int i = 0; i <= 20; i++)
    {
        Sums.push_back(pow(2, i));
    }
    evens = limit / 2;
    odds = evens + (limit % 2);

    for (int i = 2 * evens; i>0; i -= 2)
    {
        int temp = Sum + low_bit(i, Sums);
        if (temp < sum)
        {
            Sum = temp;
            s.insert(i);
        }
        else if (temp == sum)
        {
            Sum = temp;
            s.insert(i);
            display(s);
            return 0;
        }
    }

    if (sum - Sum > odds)
    {
        cout << "-1\n";
        return 0;
    }
    int j = 1;
    for (int i = 0; i < sum - Sum; i++)
    {
        s.insert(j);
        j += 2;
    }
    display(s);

}


#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<sstream>
#include<cmath>
using namespace std;

void display(set<int> S)
{
    cout << S.size() << "\n";
    for (set<int>::iterator it = S.begin(); it != S.end(); it++)
    {
        cout << *it << " ";
    }
    cout << "\n";
}

int low_bit(int A, vector<int> V)
{
    for (int i = 0; i<20; i++)
    {
        if (A >= V[i] && A < V[i + 1])
            return V[i];
    }
    return V[V.size() - 1];
}
int main()
{
    /*int F;
    cin >> F;
    cout << low_bit(F)<<"\n";
    return 0;*/

    int sum, limit,Sum=0;
    int odds, evens;
    set<int> s;
    vector<int> Sums;
    cin >> sum >> limit;
    for (int i = 0; i <= 20; i++)
    {
        Sums.push_back(pow(2, i));
    }
    evens = limit / 2;
    odds = evens + (limit % 2);

    for (int i = 2 * evens; i>0; i -= 2)
    {
        int temp = Sum + low_bit(i, Sums);
        if (temp < sum)
        {
            Sum = temp;
            s.insert(i);
        }
        else if (temp == sum)
        {
            Sum = temp;
            s.insert(i);
            display(s);
        }
    }

    if (sum - Sum > odds)
    {
        cout << "-1\n";
        return 0;
    }
    int j = 1;
    for (int i = 0; i < sum - Sum; i++)
    {
        s.insert(j);
        j += 2;
    }
    display(s);

}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>

#define rep(i,n) for (int i=0; i<(n); i++)
#define repf(i,a,b) for (int i=(a); i<=(b); i++)
#define repb(i,a,b) for (int i=(a); i>=(b); i--)

using namespace std;

typedef long long int LL;

template<class T>
ostream& operator<<(ostream& a, const vector<T>& v) {
    for (int i=0; i<v.size(); i++)
        a << v[i] << " ";
    return a;
}

inline int lowbit(int x) {
    return x ^ (x & (x-1));
}

int main() {
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    int sum, limit;
    while (cin >> sum >> limit) {
        //limit = min(limit, sum);
        vector<pair<int,int>> tmp;
        for (int i=1; i<=limit; i++)
            tmp.push_back( make_pair(lowbit(i),i) );
        sort(tmp.begin(), tmp.end());

        vector<int> ans;
        bool possible;
        int lim = tmp.size() - 1;
        int cumsum = 0;
        for (int i=31; i>=0; i--) {
            if (sum & (1<<i)) {
                int csum = 0;
                while (lim>=0 && tmp[lim].first>(1<<i))
                    lim--;
                while (lim>=0 && csum!=(1 << i)) {
                    csum += tmp[lim].first;
                    ans.push_back(tmp[lim].second);
                    lim--;
                }
                cumsum += csum;
            }
        }
        assert(cumsum <= sum);
        if (cumsum < sum) {
            cout << -1 << endl;
        } else {
            cout << ans.size() << endl << ans << endl;
        }
    }
}


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

int main()
{
    int a,b,k;
    cin>>a>>b;
    k=1<<15;
    vector <bool> v(b+1,false);
    while(k>b)
        k>>=1;
    int ans=0;
    while(a!=0)
    {
        for(int i=1;k<=a&&i*k<=b;i+=2)
        {
            //cout<<i*k<<" ";
            ans++;
            v[i*k]=true;
            a-=k;
        }
        k>>=1;
        if(k==0&&a!=0)
        {
            cout<<-1;
            return 0;
        }
    }
    cout<<ans<<endl;
    for(int i=0;i<=b;i++)
        if(v[i])
            cout<<i<<" ";
    return 0;
}


#include <string.h>
#include <stdio.h>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>

#define NMAX 17
#define N 100001

#define min(a,b) ((a) <= (b) ? (a) : (b))
#define max(a,b) ((a) >= (b) ? (a) : (b))

using namespace std;

int v[NMAX];
vector <int> vec;

int lb (int x) {

	int i, lg = 16;

	for (i = 0; i <= lg; i++) {
		if (x&v[i])
			break;
	}

	return v[i];
}

int main () {

	int i, j, k, t, tst, f, l, fs, dim, ok, fr, nr, n, p, q;

	int rez, d, sum, mij;

	v[0] = 1;
	for (i = 1; i < NMAX; i++)
		v[i] = v[i-1]<<1;

	scanf("%d %d", &sum, &l);

	n = (int)log2(sum);

	vec.clear();
	nr = 0;
	while (sum > 0) {
		n = (int)log2(sum);
		//printf("%d %d %d\n", sum, l, v[n]);

		if (!l)
			break;

		if (v[n] > l) {
			while (sum < lb(l))
				l--;

			sum = sum - lb(l);
				vec.push_back(l);
			l--;

		}

		else {
			for (i = 0; i <= n; i++) {
				if (sum & v[i]) {
					vec.push_back(v[i]);
					sum = sum - v[i];
				}
			}
		}

	}

	if (sum) {
		printf("-1\n");
	}
	else {
		n = vec.size();
		printf("%d\n", n);
		for (i = 0; i < n; i++)
			printf("%d ", vec[i]);

		printf("\n");
	}

	return 0;
}


#include <string.h>
#include <stdio.h>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>

#define NMAX 16
#define N 100001

#define min(a,b) ((a) <= (b) ? (a) : (b))
#define max(a,b) ((a) >= (b) ? (a) : (b))

using namespace std;

int v[NMAX];
vector <int> vec;

int lb (int x) {

	int i, lg = log2(x);

	for (i = 0; i <= lg; i++) {
		if (x&v[i])
			break;
	}

	return v[i];
}

int main () {

	int i, j, k, t, tst, f, l, fs, dim, ok, fr, nr, n, p, q;

	int rez, d, sum, mij;

	v[0] = 1;
	for (i = 1; i < NMAX; i++)
		v[i] = v[i-1]<<1;

	scanf("%d %d", &sum, &l);

	n = (int)log2(sum);

	vec.clear();
	nr = 0;
	while (sum > 0) {
		n = (int)log2(sum);
		//printf("%d %d %d\n", sum, l, v[n]);

		if (!l)
			break;

		if (v[n] > l) {

			while (sum < lb(l))
				l--;

			sum = sum - lb(l);
				vec.push_back(l);
			l--;

		}

		else {
			for (i = 0; i <= n; i++) {
				if (sum & v[i]) {
					vec.push_back(v[i]);
					sum = sum - v[i];
				}
			}
		}

	}

	if (sum) {
		printf("-1\n");
	}
	else {
		n = vec.size();
		printf("%d\n", n);
		for (i = 0; i < n; i++)
			printf("%d ", vec[i]);

		printf("\n");
	}

	return 0;
}


#include <string.h>
#include <stdio.h>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>

#define NMAX 17
#define N 100001

#define min(a,b) ((a) <= (b) ? (a) : (b))
#define max(a,b) ((a) >= (b) ? (a) : (b))

using namespace std;

int v[NMAX];
vector <int> vec;

int lb (int x) {

	int i, lg = log2(x);

	for (i = 0; i <= lg; i++) {
		if (x&v[i])
			break;
	}

	return v[i];
}

int main () {

	int i, j, k, t, tst, f, l, fs, dim, ok, fr, nr, n, p, q;

	int rez, d, sum, mij;

	v[0] = 1;
	for (i = 1; i < NMAX; i++)
		v[i] = v[i-1]<<1;

	scanf("%d %d", &sum, &l);

	n = (int)log2(sum);

	vec.clear();
	nr = 0;
	while (sum > 0) {
		n = (int)log2(sum);
		//printf("%d %d %d\n", sum, l, v[n]);

		if (!l)
			break;

		if (v[n] > l) {
			while (sum < lb(l))
				l--;

			sum = sum - lb(l);
				vec.push_back(l);
			l--;

		}

		else {
			for (i = 0; i <= n; i++) {
				if (sum & v[i]) {
					vec.push_back(v[i]);
					sum = sum - v[i];
				}
			}
		}

	}

	if (sum) {
		printf("-1\n");
	}
	else {
		n = vec.size();
		printf("%d\n", n);
		for (i = 0; i < n; i++)
			printf("%d ", vec[i]);

		printf("\n");
	}

	return 0;
}


#include <string.h>
#include <stdio.h>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>

#define NMAX 16
#define N 100001

#define min(a,b) ((a) <= (b) ? (a) : (b))
#define max(a,b) ((a) >= (b) ? (a) : (b))

using namespace std;

int v[NMAX];
vector <int> vec;

int lb (int x) {

	int i, lg = log2(x);

	for (i = 0; i <= lg; i++) {
		if (x&1)
			break;
		x = x>>1;
	}

	return v[i];
}

int main () {

	int i, j, k, t, tst, f, l, fs, dim, ok, fr, nr, n, p, q;

	int rez, d, sum, mij;

	v[0] = 1;
	for (i = 1; i < NMAX; i++)
		v[i] = v[i-1]<<1;

	scanf("%d %d", &sum, &l);

	n = (int)log2(sum);

	vec.clear();
	nr = 0;
	while (sum > 0) {
		n = (int)log2(sum);
		//printf("%d %d %d\n", sum, l, v[n]);

		if (!l)
			break;

		if (v[n] > l) {
			sum = sum - lb(l);
			vec.push_back(l);
			l--;

		}

		else {
			for (i = 0; i <= n; i++) {
				if (sum & v[i]) {
					vec.push_back(v[i]);
					sum = sum - v[i];
				}
			}
		}

	}

	if (sum) {
		printf("-1\n");
	}
	else {
		n = vec.size();
		printf("%d\n", n);
		for (i = 0; i < n; i++)
			printf("%d ", vec[i]);

		printf("\n");
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int l, s;

unsigned lowBit(int x)
{
    int y = 1;
    while( !(x&y) ){
        y <<= 1;
    }
    return y;

}

void solve()
{
    vector<int> x;
    int f  = 1, k;

    while( f<=l and s) {
        k = lowBit(f);
        if( 0 <= s-k) {
            s -= k;
            x.push_back(f);
        }
        f++;
    }
    if(s) {
        cout <<-1;
    } else {
        cout <<x.size() <<endl;
        for(int i=0; i<x.size(); ++i) {
            cout <<x[i] <<' ';
        }
    }
}

int main()
{
    //freopen("input.txt", "r", stdin);
    cin >>s >>l;
    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int limit, sum;

void solve()
{
    vector< pair< int, int > > lowbits;
    for(int x=1; x<=limit; x++){
        lowbits.push_back( pair<int, int>( (x & -x), x) );
    }
    sort(lowbits.begin(), lowbits.end());
    vector< int > ans;
    for(auto abit = lowbits.begin(); abit != lowbits.end() and sum; ++abit) {
        if(abit->first <= sum) {
            sum -= abit->first;
            ans.push_back(abit->second);
        }
    }
    if(sum) {
        cout <<-1;
    } else {
        cout <<ans.size() <<endl;
        for(auto x = ans.begin(); x != ans.end(); ++x) {
            cout <<*x <<' ';
        }
    }
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >>sum >>limit;
    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int limit, sum;

void solve()
{
    vector< pair< int, int > > lowbits;
    for(int x=1; x<=limit; x++){
        lowbits.push_back( pair<int, int>( (x & -x), x) );
    }
    sort(lowbits.begin(), lowbits.end());
    vector< int > ans;
    for(auto abit = lowbits.rbegin(); abit != lowbits.rend() and sum; ++abit) {
        if(abit->first <= sum) {
            sum -= abit->first;
            ans.push_back(abit->second);
        }
    }
    if(sum) {
        cout <<-1;
    } else {
        cout <<ans.size() <<endl;
        for(auto x = ans.begin(); x != ans.end(); ++x) {
            cout <<*x <<' ';
        }
    }
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >>sum >>limit;
    solve();
    return 0;
}


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

int main(void) {
	int sum, lim; scanf("%d %d", &sum, &lim);
	vector <int> ad;
	for (int i = lim; i >= 1; --i) {
		if (sum >= (i & -i))
			sum -= i & -i, ad.push_back(i);
	}
	if (sum > 0) puts("-1");
	else {
		printf("%d\n", ad.size());
		for_each(begin(ad), end(ad), [&](int y) { printf("%d ", y); });
	}
}


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

int main(void) {
	int sum, lim; scanf("%d %d", &sum, &lim);
	vector <int> ad;
	for (int i = lim; i >= 1; --i) {
		if (sum >= (i & -i))
			sum -= i & -i, ad.push_back(i);
	}
	if (sum > 0) puts("-1");
	else {
		printf("%d\n", ad.size());
		copy(ad.begin(), ad.end(), ostream_iterator<int>(cout, " "));
		puts("");
	}
}


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

int main(void) {
	int sum, lim; scanf("%d %d", &sum, &lim);
	vector <int> ad;
	for (int i = lim; i >= 1; --i) {
		if (sum >= (i & -i))
			sum -= i & -i, ad.push_back(i);
	}
	if (sum > 0) puts("-1");
	else {
		printf("%d\n", ad.size());
		for_each(ad.begin(), ad.end(), [&](int y) { printf("%d ", y); });
	}
}


#include <cstdio>
#include <cassert>
#include <functional>
#include <cstring>
#include <vector>
#include <deque>
#include <map>
#include <list>
#include <stack>
#include <utility>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <bitset>
#include <cmath>
#include <set>
#include <ctime>
#include <cstdlib>
#include <sstream>

using namespace std;

int main(void) {
	int sum, lim; scanf("%d %d", &sum, &lim);
	vector <int> ad;
	for (int i = lim; i >= 1; --i) {
		if (sum >= (i & -i))
			sum -= i & -i, ad.push_back(i);
	}
	if (sum > 0) puts("-1");
	else {
		printf("%d\n", ad.size());
		copy(ad.begin(), ad.end(), ostream_iterator<int>(cout, " "));
		puts("");
	}
}


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

int main(void) {
	int sum, lim; scanf("%d %d", &sum, &lim);
	vector <int> ad;
	for (int i = lim; i >= 1; --i) {
		if (sum >= (i & -i))
			sum -= i & -i, ad.push_back(i);
	}
	if (sum > 0) puts("-1");
	else {
		printf("%d\n", ad.size());
		for_each(ad.begin(), ad.end(), [](int y) { printf("%d ", y); });
	}
}


#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cctype>
#include <algorithm>
#define lowbit(x) ((x)&-(x))
int n, m;
int a[100024], ans[100024], cnt = 0;
int cmp(int a, int b)
{
    return lowbit(a) < lowbit(b);
}
int main()
{
    scanf("%d %d", &n, &m);
    for (int i=0; i<m; ++i)
        a[i] = i + 1;
    std::sort(a, a+m, cmp);
    for (int i=m-1; i+1; --i)
    {
        if (lowbit(a[i]) <= n)
            n -= lowbit(a[i]), ans[cnt++] = a[i];
    }
    if (n)
        puts("-1");
    else
    {
        printf("%d\n", cnt);
        for (int i=0; i<cnt; ++i)
        {
            printf(i ? " %d" : "%d", a[i]);
        }
    }
    return 0;
}


#include <cstdio>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cassert>
#include <climits>
#include <cstring>
#include <iostream>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>

using namespace std;
#define LL long long
#define MOD 1000000007
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define INF 1e9
#define pb push_back
#define mp make_pair
#define mset(x) memset((x), 0, sizeof((x)))
#define MSET(x) memset((x), inf, sizeof((x)))
#define geti(x) scanf("%d", &(x))
#define getii(x, y) scanf("%d %d", &(x), &(y))
#define getiii(x, y, z) scanf("%d %d %d", &(x), &(y), &(z))
#define getd(x) scanf("%lf", &(x))
#define puti(x) printf("%d", (x))
#define putii(x, y) printf("%d %d", (x), (y))
#define rep(n) for(int i=0; i<n; i++)
#define repp(i, x, y) for(int (i)=(x); (i)<(y); (i)++)
#define lowbit(x) ((x)&-(x))
#ifdef OFFLINE
#else
#define assert(exp) 0
#endif // OFFLINE
//const int maxn = 1*int(1e5)+5;
int tn, tcase=0;
int n, m, k;
//int r, c;
int v[100005];
int flag=0;
int fail=0;
int cnt=0;
void dfs(int sum, int x, int cur)
{
    if (flag||fail)
        return;
    //if (sum+lowbit(cur)>n)
    //{
    //  return;
    //}
    if (sum == n)
    {
        flag = 1;
        return;
    }
    else if (sum > n)
    {
        fail=1;
        return;
    }
    if (cur>m)
    {
        fail=1;
        return;
    }
    v[cnt++]=cur;
    dfs(sum+lowbit(cur), x+1, cur+1);
    if (fail&&x<m)
    {
        fail=0;
    }
    if (flag||fail)
        return;
    cnt--;
    dfs(sum, x, cur+1);
    if (fail&&x<m)
    {
        fail=0;
    }
}
int main()
{
#ifdef OFFLINE
    freopen("data.in", "r", stdin);
    //freopen(data.out", "w", stdout);
#endif // OFFLINE

    getii(n, m);
    dfs(0, 0, 1);
    if (!flag||fail)
    {
        puts("-1");
        return 0;
    }
    printf("%d\n", cnt);
    rep(cnt)
        printf(i?" %d":"%d", v[i]);

#ifdef OFFLINE
    double CostTime=(double)clock()/CLOCKS_PER_SEC;
    printf("\nCostTime:%.0fms\n", CostTime*1000);
#endif // OFFLINE
    return 0;
}


#include <cstdio>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cassert>
#include <climits>
#include <cstring>
#include <iostream>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>

using namespace std;
#define LL long long
#define MOD 1000000007
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define INF 1e9
#define pb push_back
#define mp make_pair
#define mset(x) memset((x), 0, sizeof((x)))
#define MSET(x) memset((x), inf, sizeof((x)))
#define geti(x) scanf("%d", &(x))
#define getii(x, y) scanf("%d %d", &(x), &(y))
#define getiii(x, y, z) scanf("%d %d %d", &(x), &(y), &(z))
#define getd(x) scanf("%lf", &(x))
#define puti(x) printf("%d", (x))
#define putii(x, y) printf("%d %d", (x), (y))
#define rep(n) for(int i=0; i<n; i++)
#define repp(i, x, y) for(int (i)=(x); (i)<(y); (i)++)
#define lowbit(x) ((x)&-(x))
#ifdef OFFLINE
#else
#define assert(exp) 0
#endif // OFFLINE
//const int maxn = 1*int(1e5)+5;
int tn, tcase=0;
int n, m, k;
//int r, c;
int v[100005];
int flag=0;
int fail=0;
int cnt=0;
void dfs(int sum, int x, int cur)
{
    if (flag||fail)
        return;
    //if (sum+lowbit(cur)>n)
    //{
    //  return;
    //}
    if (sum == n)
    {
        flag = 1;
        return;
    }
    else if (sum > n)
    {
        fail=1;
        return;
    }
    if (cur>m)
    {
        fail=1;
        return;
    }
    v[cnt++]=cur;
    dfs(sum+lowbit(cur), x+1, cur+1);
    if (fail&&x<m)
    {
        fail=0;
    }
    if (flag||fail)
        return;
    cnt--;
    dfs(sum, x, cur+1);
    if (fail&&x<m)
    {
        fail=0;
    }
}
int main()
{
#ifdef OFFLINE
    freopen("data.in", "r", stdin);
    //freopen(data.out", "w", stdout);
#endif // OFFLINE

    getii(n, m);
    dfs(0, 0, 1);
    if (!flag||fail)
    {
        puts("-1");
        return 0;
    }
    printf("%d\n", cnt);
    rep(cnt)
        printf(i?" %d":"%d", lowbit(v[i]));

#ifdef OFFLINE
    double CostTime=(double)clock()/CLOCKS_PER_SEC;
    printf("\nCostTime:%.0fms\n", CostTime*1000);
#endif // OFFLINE
    return 0;
}


#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cctype>
#include <algorithm>
#define lowbit(x) ((x)&(-x))
int n, m;
int a[100024], ans[100024], cnt = 0;
int cmp(int a, int b)
{
    return (lowbit(a) > lowbit(b));
}
int main()
{
    scanf("%d %d", &n, &m);
    for (int i=0; i<m; ++i)
        a[i] = i + 1;
    std::sort(a, a+m, cmp);
    for (int i=0; i<m; ++i)
    {
        if (lowbit(a[i]) <= n)
            n -= lowbit(a[i]), ans[cnt++] = a[i];
    }
    if (n)
        puts("-1");
    else
    {
        printf("%d\n", cnt);
        for (int i=0; i<cnt; ++i)
        {
            printf(i ? " %d" : "%d", ans[i]);
        }
    }
    return 0;
}


#include <cstdio>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cassert>
#include <climits>
#include <cstring>
#include <iostream>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>

using namespace std;
#define LL long long
#define MOD 1000000007
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define INF 1e9
#define pb push_back
#define mp make_pair
#define mset(x) memset((x), 0, sizeof((x)))
#define MSET(x) memset((x), inf, sizeof((x)))
#define geti(x) scanf("%d", &(x))
#define getii(x, y) scanf("%d %d", &(x), &(y))
#define getiii(x, y, z) scanf("%d %d %d", &(x), &(y), &(z))
#define getd(x) scanf("%lf", &(x))
#define puti(x) printf("%d", (x))
#define putii(x, y) printf("%d %d", (x), (y))
#define rep(n) for(int i=0; i<n; i++)
#define repp(i, x, y) for(int (i)=(x); (i)<(y); (i)++)
#define lowbit(x) ((x)&-(x))
#ifdef OFFLINE
#else
#define assert(exp) 0
#endif // OFFLINE
//const int maxn = 1*int(1e5)+5;
int tn, tcase=0;
int n, m, k;
//int r, c;
int v[100005];
int flag=0;
int fail=0;
int cnt=0;
void dfs(int sum, int x, int cur)
{
    if (flag||fail)
        return;
	//if (sum+lowbit(cur)>n)
	//{
	//	return;
	//}
    if (sum == n)
    {
        flag = 1;
        return;
    }
	else if (sum > n)
	{
        fail=1;
		return;
	}
    if (x>=m || cur>m)
	{
		fail=1;
        return;
	}
    v[cnt++]=cur;
    dfs(sum+lowbit(cur), x+1, cur+1);
	if (fail&&x<m&&cur<=m)
	{
		fail=0;
	}
	if (flag||fail)
		return;
    cnt--;
    dfs(sum, x, cur+1);
	if (fail&&x<m&&cur<=m)
	{
		fail=0;
	}
}
int main()
{
#ifdef OFFLINE
    freopen("data.in", "r", stdin);
    //freopen(data.out", "w", stdout);
#endif // OFFLINE

    getii(n, m);
    dfs(0, 0, 1);
    if (!flag||fail)
    {
        puts("-1");
        return 0;
    }
    printf("%d\n", cnt);
    rep(cnt)
        printf(i?" %d":"%d", v[i]);

#ifdef OFFLINE
    double CostTime=(double)clock()/CLOCKS_PER_SEC;
    printf("\nCostTime:%.0fms\n", CostTime*1000);
#endif // OFFLINE
    return 0;
}


#include <cstdio>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cassert>
#include <climits>
#include <cstring>
#include <iostream>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>

using namespace std;
#define LL long long
#define MOD 1000000007
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define INF 1e9
#define pb push_back
#define mp make_pair
#define mset(x) memset((x), 0, sizeof((x)))
#define MSET(x) memset((x), inf, sizeof((x)))
#define geti(x) scanf("%d", &(x))
#define getii(x, y) scanf("%d %d", &(x), &(y))
#define getiii(x, y, z) scanf("%d %d %d", &(x), &(y), &(z))
#define getd(x) scanf("%lf", &(x))
#define puti(x) printf("%d", (x))
#define putii(x, y) printf("%d %d", (x), (y))
#define rep(n) for(int i=0; i<n; i++)
#define repp(i, x, y) for(int (i)=(x); (i)<(y); (i)++)
#define lowbit(x) ((x)&-(x))
#ifdef OFFLINE
#else
#define assert(exp) 0
#endif // OFFLINE
//const int maxn = 1*int(1e5)+5;
int tn, tcase=0;
int n, m, k;
//int r, c;
int v[100005];
int flag=0;
int fail=0;
int cnt=0;
void dfs(int sum, int x, int cur)
{
    if (flag||fail)
        return;
	//if (sum+lowbit(cur)>n)
	//{
	//	return;
	//}
    if (sum == n)
    {
        flag = 1;
        return;
    }
	else if (sum > n)
	{
        fail=1;
		return;
	}
    if (x>=m || cur>m)
	{
		fail=1;
        return;
	}
    v[cnt++]=cur;
    dfs(sum+lowbit(cur), x+1, cur+1);
	if (fail&&x<m)
	{
		fail=0;
	}
	if (flag||fail)
		return;
    cnt--;
    dfs(sum, x, cur+1);
	if (fail&&x<m)
	{
		fail=0;
	}
}
int main()
{
#ifdef OFFLINE
    freopen("data.in", "r", stdin);
    //freopen(data.out", "w", stdout);
#endif // OFFLINE

    getii(n, m);
    dfs(0, 0, 1);
    if (!flag||fail)
    {
        puts("-1");
        return 0;
    }
    printf("%d\n", cnt);
    rep(cnt)
        printf(i?" %d":"%d", v[i]);

#ifdef OFFLINE
    double CostTime=(double)clock()/CLOCKS_PER_SEC;
    printf("\nCostTime:%.0fms\n", CostTime*1000);
#endif // OFFLINE
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    //freopen("input.txt", "r", stdin);

    int sum, limit;
    vector<pair<int, int>> t; vector<int> q;
    cin>>sum>>limit;

    for(int i=1; i<=limit; i++){
        int mul=1; int j=i;
        while( !(j&1) ){
            mul*=2;
            j>>=1;
        }
        t.push_back(make_pair(mul, i));
    }
    sort(t.begin(), t.end());
    for(int i=t.size()-1; i>=0; i--){
        if(sum>=t[i].first){
            sum-=t[i].first;
            q.push_back(t[i].second);
        }
    }
    if(sum!=0) cout<<"-1"<<endl;
    else{
        cout<<q.size()<<endl;
        for(int i=0; i<q.size(); i++)
            cout<<q[i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    //freopen("input.txt", "r", stdin);

    int sum, limit;
    vector<pair<int, int>> t; vector<int> q;
    cin>>sum>>limit;

    for(int i=1; i<=limit; i++){
        int mul=1; int j=i;
        while( !(j&1) ){
            mul*=2;
            j>>=1;
        }
        t.push_back(make_pair(mul, i));
    }
    sort(t.begin(), t.end());
    for(int i=t.size()-1; i>=0; i--){
        if(sum>=t[i].first){
            sum-=t[i].first;
            q.push_back(t[i].second);
        }
    }
    if(sum!=0) cout<<"-1"<<endl;
    else{
        for(int i=0; i<q.size(); i++)
            cout<<q[i]<<" ";
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <algorithm>

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)>(b)?(b):(a))

using namespace std;
int m;
int lowbit(int x)
{
    int ret = 1;

    while ((x % 2) == 0) {
        ret *= 2;
        x /= 2;
    }

    m = MAX(m,ret);
    return ret;
}

int sum;
int s,n;
int first = 1;
int p;
int res[100000];

int main()
{
    cin >> s >> n;

    for (int i = 1; i<=n ;++i) {
        sum += lowbit(i);
    }

    if (sum >= s) {
        for (int i = m; ; i/=2) {
            if (!s) {
                break;
            }
            for (int j = 1; j*i*2-i<=n;j++) {
                if (s < i) {
                    break;
                }
                s-=i;
                res[p++]=j*i*2-i;
                /*if (first) {
                    cout << j*i*2-i;
                    first = 0;
                } else {
                    cout << " " << j*i*2-i;
                }*/
            }
        }
        cout << p << endl;
        for (int i = 0; i != p; ++i) {
            if (first) {
                cout << res[i];
                first = 0;
            } else {
                cout << " " << res[i];
            }
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <algorithm>

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)>(b)?(b):(a))

using namespace std;
int m;
int lowbit(int x)
{
    int ret = 1;

    while ((x % 2) == 0) {
        ret *= 2;
        x /= 2;
    }

    m = MAX(m,ret);
    return ret;
}

int sum;
int s,n;
int first = 1;
int p;
int res[100000];

int main()
{
    cin >> s >> n;

    for (int i = 1; i<=n ;++i) {
        sum += lowbit(i);
    }

    if (sum >= s) {
        for (int i = m; ; i/=2) {
            if (!s) {
                break;
            }
            for (int j = 1; j*i<=n;j++) {
                if (s < i) {
                    break;
                }
                s-=i;
                res[p++]=j*i*2-i;
                /*if (first) {
                    cout << j*i*2-i;
                    first = 0;
                } else {
                    cout << " " << j*i*2-i;
                }*/
            }
        }
        cout << p << endl;
        for (int i = 0; i != p; ++i) {
            if (first) {
                cout << res[i];
                first = 0;
            } else {
                cout << " " << res[i];
            }
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}


#include <iterator>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define ri(x) scanf("%d", &x)
#define rii(x,y) scanf("%d%d", &x, &y)
#define pb push_back
#define FOR(i,S,E) for(int i=S; i<(int)E; i++)
#define fst first
#define snd second

const int MAX = 2e5 + 10;
int n, q, can[MAX], A[MAX], current, winner, winValue;
vii v;
map <int,int> S;
set <int> SS[MAX];

int main () {
	ri(n);
	FOR(i,1,n+1) {
		int x, y;
		rii(x,y);
		v.pb({x,y});
		A[x] = max(A[x], y);
		SS[x].insert(y);
	}
	FOR(i,1,n+1) {
		if (!A[i]) continue;
		S[A[i]] = i;
	}

	ri(q);
	FOR(i,1,q+1) {
		int k; ri(k);
		map <int,int> S1 = S;

		FOR(j,0,k) {

			int x; ri(x);
			if (!A[x]) continue;
			S1.erase(S1.find(A[x]));
		}

		if (S1.size() == 1) {
			winner = S1.begin() -> snd;
			winValue = *SS[winner].begin();
		}
		else if (S1.empty()) {
			winner = winValue = 0;
		}
		else {
			map <int,int>::iterator it = prev(S1.end());
			winner = it -> snd;
			it--;
			int value = it -> fst;
			winValue = *SS[winner].upper_bound(value);
		}
		printf("%d %d\n", winner, winValue);
	}
}


#include <iterator>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define ri(x) scanf("%d", &x)
#define rii(x,y) scanf("%d%d", &x, &y)
#define pb push_back
#define FOR(i,S,E) for(int i=S; i<(int)E; i++)
#define fst first
#define snd second

const int MAX = 2e5 + 10;
int n, q, can[MAX], current, winner, winValue;
vii v;
set <int> S[MAX];

bool comp (pii &a, pii &b) {
    if (can[a.fst] == current)
        return true;
    if (can[b.fst] == current)
        return false;
    return a.snd < b.snd;
}

bool comp2 (pii &a, pii &b) {
	if (can[a.fst] == current || a.fst == winner || a.snd > winValue) {
		return true;
	}
	if (can[b.fst] == current || b.fst == winner || b.snd > winValue) {
		return false;
	}
	return a.snd < b.snd;
}

int main () {
	ri(n);
	FOR(i,0,n) {
		int x, y;
		rii(x,y);
		v.pb({x,y});
		S[x].insert(y);
	}
	ri(q);
	FOR(i,1,q+1) {
        current = i;
		int k;
		ri(k);
		FOR(j,0,k) {
			int x; ri(x);
            can[x] = i;
		}
        vii u = v;
        sort(u.begin(), u.end(), comp);
        /*
		printf("\n\n");
		FOR(j,0,u.size()) printf("%d %d\n", u[j].fst, u[j].snd);
		printf("\n\n");
		*/

        winner = u[u.size()-1].fst;
        winValue = u[u.size()-1].snd;
		sort(u.begin(), u.end(), comp2);
		/*
		printf("\n\n");
		FOR(j,0,u.size()) printf("%d %d\n", u[j].fst, u[j].snd);
		printf("\n\n");
		*/

		int value = u[u.size()-1].snd;
		value = *S[winner].upper_bound(value);

        if (can[winner]==current) {
			printf("0 0\n"); continue;
		}

		if (can[u[u.size()-1].fst] == current) {
			value = *S[winner].begin();
		}

		printf("%d %d\n", winner, value);
	}
}


#include <iterator>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define ri(x) scanf("%d", &x)
#define rii(x,y) scanf("%d%d", &x, &y)
#define pb push_back
#define FOR(i,S,E) for(int i=S; i<(int)E; i++)
#define fst first
#define snd second

const int MAX = 2e5 + 10;
int n, q, A[MAX], winner, winValue;
vii v;
map <int,int> S;
set <int> SS[MAX];

int main () {
	ri(n);
	FOR(i,1,n+1) {
		int x, y;
		rii(x,y);
		v.pb({x,y});
		A[x] = max(A[x], y);
		SS[x].insert(y);
	}
	FOR(i,1,n+1) {
		if (!A[i]) continue;
		S[A[i]] = i;
		//printf("S[%d] = %d\n", A[i], i);
	}

	ri(q);
	FOR(i,1,q+1) {
		int k; ri(k);
		vi u;
		FOR(j,0,k) {
			int x; ri(x);
			if (!A[x]) continue;
			//map <int,int>::iterator itt = S.find(A[x]);
			//printf("A[%d] = %d\n", x, A[x]);
			S.erase(S.find(A[x]));

			u.pb(x);

			//printf("\n\n%d BHHHHHHHHHHH\n\n", x);
		}
		if (S.size() == 1) {
			//printf("\n\nAHHHHHHHHHHH\n\n");
			winner = S.begin() -> snd;
			winValue = *SS[winner].begin();
			//printf("\n\nAHHHHHHHHHHH\n\n");
		}
		else if (S.empty()) {
			winner = winValue = 0;
		}
		else {
			map <int,int>::iterator it = prev(S.end());
			winner = it -> snd;
			it--;
			int value = it -> fst;
			winValue = *SS[winner].upper_bound(value);
		}
		printf("%d %d\n", winner, winValue);

		FOR(j,0,u.size()) {
			if (!A[u[j]]) continue;
			S[A[u[j]]] = u[j];
		}

	}
}


#include <iterator>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define ri(x) scanf("%d", &x)
#define rii(x,y) scanf("%d%d", &x, &y)
#define pb push_back
#define FOR(i,S,E) for(int i=S; i<(int)E; i++)
#define fst first
#define snd second

const int MAX = 2e5 + 10;
int n, q, can[MAX], A[MAX], current, winner, winValue;
vii v;
map <int,int> S;
set <int> SS[MAX];

int main () {
	ri(n);
	FOR(i,1,n+1) {
		int x, y;
		rii(x,y);
		v.pb({x,y});
		A[x] = max(A[x], y);
		SS[x].insert(y);
	}
	FOR(i,1,n+1) {
		if (!A[i]) continue;
		S[i] = A[i];
	}

	ri(q);
	FOR(i,1,q+1) {
		int k; ri(k);
		map <int,int> S1 = S;

		FOR(j,0,k) {

			int x; ri(x);
			if (!A[x]) continue;
			S1.erase(S1.find(x));
		}

		if (S1.size() == 1) {
			winner = S1.begin() -> fst;
			winValue = *SS[winner].begin();
		}
		else if (S1.empty()) {
			winner = winValue = 0;
		}
		else {
			map <int,int>::iterator it = prev(S1.end());
			winner = it -> fst;
			it--;
			int value = it -> snd;
			winValue = *SS[winner].upper_bound(value);
		}
		printf("%d %d\n", winner, winValue);
	}
}


#include <iterator>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define ri(x) scanf("%d", &x)
#define rii(x,y) scanf("%d%d", &x, &y)
#define pb push_back
#define FOR(i,S,E) for(int i=S; i<(int)E; i++)
#define fst first
#define snd second

const int MAX = 2e5 + 10;
int n, q, A[MAX], winner, winValue;
vii v;
map <int,int> S;
set <int> SS[MAX];

int main () {
	ri(n);
	FOR(i,1,n+1) {
		int x, y;
		rii(x,y);
		v.pb({x,y});
		A[x] = max(A[x], y);
		SS[x].insert(y);
	}
	FOR(i,1,n+1) {
		if (!A[i]) continue;
		S[A[i]] = i;
	}

	ri(q);
	FOR(i,1,q+1) {
		int k; ri(k);
		vi u;
		FOR(j,0,k) {
			int x; ri(x);
			if (!A[x]) continue;
			S.erase(S.find(A[x]));

			u.pb(x);
		}
		if (S.size() == 1) {
			winner = S.begin() -> snd;
			winValue = *SS[winner].begin();
		}
		else if (S.empty()) {
			winner = winValue = 0;
		}
		else {
			map <int,int>::iterator it = prev(S.end());
			winner = it -> snd;
			it--;
			int value = it -> fst;
			winValue = *SS[winner].upper_bound(value);
		}
		printf("%d %d\n", winner, winValue);

		FOR(j,0,u.size()) {
			if (!A[u[j]]) continue;
			S[A[u[j]]] = u[j];
		}

	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[200005][2];
int v[200005];
int vis[200005][2];
int n;
ll solve(int x, int op)
{
//	cout << x << ' ' << op << endl;
	if(x <= 0 || x > n)
		return 0;

	if(x == 1 || vis[x][op] == 1)
		return -1;

	if(dp[x][op] != -2)
		return dp[x][op];

	ll ans = 0;
	vis[x][op] = 1;

	if(!op)
		ans = solve(x - v[x], 1);
	else
		ans = solve(x + v[x], 0);

	vis[x][op] = 0;
	if(ans != -1)
		ans += v[x];
	return dp[x][op] = ans;

}
int main()
{
	scanf("%d",&n);
	for(int i = 2; i <= n; i++)
	{
		dp[i][1] = dp[i][0] = -2;
		scanf("%d",&v[i]);
	}
	for(int i = 1; i < n ; i++)
	{
		ll ans = solve(i+1,0);
		printf("%lld\n",ans == -1?  -1 : ans+i);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int dp[200005][2];
int v[200005];
int vis[200005][2];
int n;
int solve(int x, int op)
{
//	cout << x << " " << op << endl;

	if(x <= 0 || x > n)
		return 0;

	if(vis[x][op] == 1 || x == 1)
		return -1;

	if(vis[x][op] == 2)
		return dp[x][op];

	int ans = 0;
	vis[x][op] = 1;

	if(!op)
		ans = solve(x - v[x], !op);
	else
		ans = solve(x + v[x], !op);

	vis[x][op] = 2;
	if(ans != -1)
		ans += v[x];
	return dp[x][op] = ans;

}
int main()
{
	scanf("%d",&n);
	for(int i = 2; i <= n; i++)
		scanf("%d",&v[i]);
	for(int i = 1; i < n ; i++)
	{
		int ans =solve(i+1,0);
		printf("%d\n",ans == -1?  -1 : ans+i);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[200005][2];
int v[200005];
int vis[200005][2];
int n;
ll solve(int x, int op)
{
//	cout << x << " " << op << endl;

	if(x <= 0 || x > n)
		return 0;

	if(vis[x][op] == 1 || x == 1)
		return -1;

	if(vis[x][op] == 2)
		return dp[x][op];

	int ans = 0;
	vis[x][op] = 1;

	if(!op)
		ans = solve(x - v[x], 1);
	else
		ans = solve(x + v[x], 0);

	vis[x][op] = 2;
	if(ans != -1)
		ans += v[x];
	dp[x][op] = ans;

}
int main()
{
	scanf("%d",&n);
	for(int i = 2; i <= n; i++)
		scanf("%d",&v[i]);
	for(int i = 1; i < n ; i++)
	{
		ll ans =solve(i+1,0);
		printf("%lld\n",ans == -1?  -1 : ans+i);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[200005][2];
int v[200005];
int vis[200005][2];
int n;
ll solve(int x, int op)
{
//	cout << x << " " << op << endl;
	if(x <= 0 || x > n)
		return 0;
	if(vis[x][op] == 1)
	{
		return -1;
	}
	if(vis[x][op] == 2)
		return dp[x][op];
	int ans = 0;
	vis[x][op] = 1;
	if(!op)
	{
		ans = solve(x - v[x], 1);
	}
	else
	{
		ans = solve(x + v[x], 0);
	}
	vis[x][op] = 2;
	if(ans == -1)
		return -1;
	else
		dp[x][op] = ans + v[x];

}
int main()
{
	scanf("%d",&n);
	for(int i = 2; i <= n; i++)
		scanf("%d",&v[i]);

	for(int i = 1; i < n ; i++)
	{
		dp[1][0] = -1;
		dp[1][1] = -1;
		ll ans =solve(i+1,0);
		printf("%lld\n",ans == -1?  -1 : ans+i);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[200005][2];
int v[200005];
int vis[200005][2];
int n;
ll solve(int x, int op)
{

	if(x <= 0 || x > n)
		return 0;

	if(vis[x][op] == 1 || x == 1)
		return -1;

	if(vis[x][op] == 2)
		return dp[x][op];

	int ans = 0;
	vis[x][op] = 1;

	if(!op)
		ans = solve(x - v[x], 1);
	else
		ans = solve(x + v[x], 0);

	vis[x][op] = 2;
	if(ans != -1)
		ans += v[x];
	return dp[x][op] = ans;

}
int main()
{
	scanf("%d",&n);
	for(int i = 2; i <= n; i++)
		scanf("%d",&v[i]);
	for(int i = 1; i < n ; i++)
	{
		ll ans =solve(i+1,0);
		printf("%lld\n",ans == -1?  -1 : ans+i);
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mkp make_pair
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi 3.14159265359
#define zer(dp) memset(dp,0,sizeof dp)
#define all(x) x.begin(),x.end()
//PLEASE DON'T HACK I AM POOR :(
using namespace std;
vector<ll>arr(2e5+10);
vector<ll>dpl(2e5+10,0),dpu(2e5+10,0),visu(2e5+10,0),visl(2e5+10,0);
ll n;
//void dipl();
void dipu(ll s);
void dipl(ll s)
{
//	 lower jana hai
//    cout<<" low "<<s<<"\n";
	visl[s]++;
	if(visl[s]>1)
	{
		dpl[s]=-1;
		return;
	}
	ll lwr=s-arr[s];
	if(lwr==1)
	{
		dpl[s]=-1;
		return;
	}
	else if(lwr<1)
	{
		dpl[s]=arr[s];
		return;
	}
	else
	{
//		ll upr=s+arr[s];
//		if(upr>n)
//		{
//			dpl[s]+=arr[s];return;
//		}
			if(dpu[lwr]==0)
			{
//				cout<<"AC\n";
				dipu(lwr);
			}
		    if(dpu[lwr]==-1)
		    {
		    	dpl[s]=-1;return;
			}
			else
			dpl[s]+=dpu[lwr]+arr[s];
	}
}
void dipu(ll s)
{
//	cout<<" upp  "<<s<<"\n";
	visu[s]++;
	if(visu[s]>1)
	{
		dpu[s]=-1;
		return;
	}
	ll upr=s+arr[s];
	if(upr>n)
	{
		dpu[s]=arr[s];
	}
	else
	{
		if(dpl[upr]==0)
		{
			dipl(upr);
		}
		if(dpl[upr]==-1)dpu[s]=-1;
		else
		{
			dpu[s]=arr[s]+dpl[upr];
		}
	}
}
int main()
{
	fastio
	ll i,m,j,k,l;
	cin>>n;
	for(i=2;i<=n;i++)cin>>arr[i];
	for(i=2;i<=n;i++)
	{
		if(dpl[i]==0)
		{
			dipl(i);
		}
	}
//	for(i=2;i<=n;i++)cout<<i<<"  "<<dpl[i]<<"\n\n";cout<"\n";
	for(i=1;i<=n-1;i++)
	{
		ll ind=i+1;
		if(dpl[ind]==-1)cout<<"-1\n";
		else cout<<dpl[ind]+i<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mkp make_pair
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi 3.14159265359
#define zer(dp) memset(dp,0,sizeof dp)
#define all(x) x.begin(),x.end()
//PLEASE DON'T HACK I AM POOR :(
using namespace std;
vector<ll>arr(2e5+10);
vector<ll>dpl(2e5+10,0),dpu(2e5+10,0),visu(2e5+10,0),visl(2e5+10,0);
ll n;
//void dipl();
void dipu(ll s);
void dipl(ll s)
{
//	 lower jana hai
//    cout<<" low "<<s<<"\n";
	visl[s]++;
	if(visl[s]>1)
	{
		dpl[s]=-1;
		return;
	}
	ll lwr=s-arr[s];
	if(lwr==1)
	{
		dpl[s]=-1;
		return;
	}
	else if(lwr<1)
	{
		dpl[s]+=arr[s];
		return;
	}
	else
	{
//		ll upr=s+arr[s];
//		if(upr>n)
//		{
//			dpl[s]+=arr[s];return;
//		}
			if(dpu[lwr]==0)
			{
//				cout<<"AC\n";
				dipu(lwr);
			}
		    if(dpu[lwr]==-1)
		    {
		    	dpl[s]=-1;return;
			}
			else
			dpl[s]+=dpu[lwr]+arr[s];
	}
}
void dipu(ll s)
{
//	cout<<" upp  "<<s<<"\n";
	visu[s]++;
	if(visu[s]>1)
	{
		dpu[s]=-1;
		return;
	}
	ll upr=s+arr[s];
	if(s>n)
	{
		dpu[s]=arr[s];
	}
	else
	{
		if(dpl[upr]==-1)
		{
			dipl(upr);
		}
		if(dpl[upr]==-1)dpu[s]=-1;
		else
		{
			dpu[s]=arr[s]+dpl[upr];
		}
	}
}
int main()
{
	fastio
	ll i,m,j,k,l;
	cin>>n;
	for(i=2;i<=n;i++)cin>>arr[i];
	for(i=2;i<=n;i++)
	{
		if(dpl[i]==0)
		{
			dipl(i);
		}
	}
//	for(i=2;i<=n;i++)cout<<i<<"  "<<dpl[i]<<"\n\n ";cout<"\n";
	for(i=1;i<=n-1;i++)
	{
		ll ind=i+1;
		if(dpl[ind]==-1)cout<<"-1\n";
		else cout<<dpl[ind]+i<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mkp make_pair
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi 3.14159265359
#define all(x) x.begin(),x.end()
#define zer(dp) memset(dp,0,sizeof dp)
//PLEASE DON'T HACK I AM POOR :(
using namespace std;
vector<ll>arr(2e5+10,0),dpu(2e5+10,0),dpl(2e5+10,0),dp(2e5+10,0),vis(2e5+10,0),upp(2e5+10,0);
void dipu(ll u);
ll siz;
void dip(ll i)
{
//	cout<<"abhi "<<i<<"\n";
	if(dpl[i]!=0)return ;
	else
	{
		vis[i]++;
		if(vis[i]>2)
		{
			dpl[i]=-1;
			return ;
		}
		if(i-arr[i]==1)
		{
			dpl[i]=-1;
			dp[i]=0;
		}
		else
		{
			ll ind=i-arr[i];
			if(ind<1)
			{
				dpl[i]=1;
				dp[i]=arr[i];
			}
			else
			{
				ll ind=i-arr[i];
				if(dpu[ind]==0)
				dipu( ind);
				if(dpu[ind]==1)
				{
					dp[i]=arr[i]+upp[ind];
					dpl[i]=1;
				}
				else
				dpl[i]=-1;
			}
		}
	}
}
void dipu(ll i)
{
//	cout<<"abhi upp "<<i<<" "<<vis[i]<<" \n";
	if(dpu[i]!=0)return ;
	else
	{
		vis[i]++;
		if(vis[i]>2)
		{
			dpu[i]=-1;
			return ;
		}
		if(i+arr[i]>siz)
		{
			upp[i]=arr[i];dpu[i]=1;
//			cout<<"ARARA "<<i+arr[i]<<" "<<siz<<"\n";
		}
		else
		{
			ll ind=i+arr[i];
//			cout<<"IND "<<ind<<"\n";
			if(dpl[ind]==0)
			dip(ind);
			if(dpl[ind]==-1)
			{
				dpu[i]=-1;
				upp[i]=0;
			}
			else
			{
				upp[i]=dp[ind]+arr[i];
				dpu[i]=1;
			}
		}
	}
}
int main()
{
	fastio
	ll i,j,k,l,n;
	cin>>n;
	for(i=2;i<=n;i++)
	{
	cin>>arr[i];
	dpl[i]=dpu[i]=dp[i]=0;
	}
	siz=n;
	for(i=2;i<=n;i++)
	{
		if(dpl[i]==0)
		dip(i);
	}
//	for(i=2;i<=n;i++)cout<<dp[i]<<" ";cout<<"\n";
//	for(i=2;i<=n;i++)cout<<dpl[i]<<" ";cout<<"\n";
     for(i=1;i<=n-1;i++)
     {
     	ll s=i;
     	ll ind=1+i;
     	if(dpl[ind]==1)
     	{
     		cout<<s+dp[ind]<<"\n";
		 }
		 else cout<<"-1\n";
	 }
	return 0;
}


#include<bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mkp make_pair
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi 3.14159265359
#define all(x) x.begin(),x.end()
#define zer(dp) memset(dp,0,sizeof dp)
//PLEASE DON'T HACK I AM POOR :(
using namespace std;
vector<ll>arr(2e5+10,0),dpu(2e5+10,0),dpl(2e5+10,0),dp(2e5+10,0),vis(2e5+10,0),upp(2e5+10,0);
void dipu(ll u);
ll siz;
void dip(ll i)
{
//	cout<<"abhi "<<i<<"\n";
	if(dpl[i]!=0)return ;
	else
	{
		vis[i]++;
		if(vis[i]>2)
		{
			dpl[i]=-1;
			return ;
		}
		if(i-arr[i]==1)
		{
			dpl[i]=-1;
			dp[i]=0;
		}
		else
		{
			ll ind=i-arr[i];
			if(ind<1)
			{
				dpl[i]=1;
				dp[i]=arr[i];
			}
			else
			{
				ll ind=i-arr[i];
				dipu( ind);
				if(dpu[ind]==1)
				{
					dp[i]=arr[i]+upp[ind];
					dpl[i]=1;
				}
				else
				dpl[i]=-1;
			}
		}
	}
}
void dipu(ll i)
{
//	cout<<"abhi upp "<<i<<" "<<vis[i]<<" \n";
	if(dpu[i]!=0)return ;
	else
	{
		vis[i]++;
		if(vis[i]>2)
		{
			dpu[i]=-1;
			return ;
		}
		if(i+arr[i]>siz)
		{
			upp[i]=arr[i];dpu[i]=1;
//			cout<<"ARARA "<<i+arr[i]<<" "<<siz<<"\n";
		}
		else
		{
			ll ind=i+arr[i];
//			cout<<"IND "<<ind<<"\n";
			if(dpl[ind]==0)
			dip(ind);
			if(dpl[ind]==-1)
			{
				dpu[i]=-1;
				upp[i]=0;
			}
			else
			{
				upp[i]=dp[ind]+arr[i];
				dpu[i]=1;
			}
		}
	}
}
int main()
{
	fastio
	ll i,j,k,l,n;
	cin>>n;
	for(i=2;i<=n;i++)
	{
	cin>>arr[i];
	dpl[i]=dpu[i]=dp[i]=0;
	}
	siz=n;
	for(i=2;i<=n;i++)
	{
		if(dpl[i]==0)
		dip(i);
	}
//	for(i=2;i<=n;i++)cout<<dp[i]<<" ";cout<<"\n";
//	for(i=2;i<=n;i++)cout<<dpl[i]<<" ";cout<<"\n";
     for(i=1;i<=n-1;i++)
     {
     	ll s=i;
     	ll ind=1+i;
     	if(dpl[ind]==1)
     	{
     		cout<<s+dp[ind]<<"\n";
		 }
		 else cout<<"-1\n";
	 }
	return 0;
}


#include<bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mkp make_pair
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi 3.14159265359
#define all(x) x.begin(),x.end()
#define zer(dp) memset(dp,0,sizeof dp)
//PLEASE DON'T HACK I AM POOR :(
using namespace std;
int main()
{
	fastio
	ll i,j,k,l,n;
	cin>>n;
	vector<ll>arr(n+1);
	for(i=2;i<=n;i++)cin>>arr[i];
	vector<ll>dp(n+1,0),vis(n+1,0);
	vis[1]=-1;
	for(i=2;i<=n;i++)
	{
		if(i-arr[i]<=0)
		{
			dp[i]=arr[i];
			vis[i]=1;
		}
		else
		{
			if(vis[i-arr[i]]==-1)vis[i]=-1;
			else
			{
				dp[i]=arr[i]+dp[i-arr[i]];
				vis[i]=1;
			}
		}

	}
//	for(i=2;i<=n;i++)cout<<dp[i]<<" ";cout<<"\n";
//	for(i=2;i<=n;i++)cout<<vis[i]<<" ";cout<<"\n";
     for(i=1;i<=n-1;i++)
     {
     	ll s=i;
     	ll ind=1+i;
     	if(vis[ind]==1)
     	{
     		cout<<s+dp[ind]<<"\n";
		 }
		 else cout<<"-1\n";
	 }
	return 0;
}


#include<bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mkp make_pair
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi 3.14159265359
#define all(x) x.begin(),x.end()
#define zer(dp) memset(dp,0,sizeof dp)
//PLEASE DON'T HACK I AM POOR :(
using namespace std;
vector<ll>arr(2e5+10,0),dpu(2e5+10,0),dpl(2e5+10,0),dp(2e5+10,0),visl(2e5+10,0),upp(2e5+10,0),visu(2e5+10,0);
void dipu(ll u);
ll siz;
void dip(ll i)
{
//	cout<<"abhi "<<i<<"\n";
	if(dpl[i]!=0)return ;
	else
	{
		visl[i]++;
		if(visl[i]>1)
		{
			dpl[i]=-1;
			return ;
		}
		if(i-arr[i]==1)
		{
			dpl[i]=-1;
			dp[i]=0;
		}
		else
		{
			ll ind=i-arr[i];
			if(ind<1)
			{
				dpl[i]=1;
				dp[i]=arr[i];
			}
			else
			{
				ll ind=i-arr[i];
				if(dpu[ind]==0)
				dipu( ind);
				if(dpu[ind]==1)
				{
					dp[i]=arr[i]+upp[ind];
					dpl[i]=1;
				}
				else
				dpl[i]=-1;
			}
		}
	}
}
void dipu(ll i)
{
//	cout<<"abhi upp "<<i<<" "<<vis[i]<<" \n";
	if(dpu[i]!=0)return ;
	else
	{
		visu[i]++;
		if(visu[i]>1)
		{
			dpu[i]=-1;
			return ;
		}
		if(i+arr[i]>siz)
		{
			upp[i]=arr[i];dpu[i]=1;
//			cout<<"ARARA "<<i+arr[i]<<" "<<siz<<"\n";
		}
		else
		{
			ll ind=i+arr[i];
//			cout<<"IND "<<ind<<"\n";
			if(dpl[ind]==0)
			dip(ind);
			if(dpl[ind]==-1)
			{
				dpu[i]=-1;
				upp[i]=0;
			}
			else
			{
				upp[i]=dp[ind]+arr[i];
				dpu[i]=1;
			}
		}
	}
}
int main()
{
	fastio
	ll i,j,k,l,n;
	cin>>n;
	for(i=2;i<=n;i++)
	{
	cin>>arr[i];
	dpl[i]=dpu[i]=dp[i]=0;
	}
	siz=n;
	for(i=2;i<=n;i++)
	{
		if(dpl[i]==0)
		dip(i);
	}
//	for(i=2;i<=n;i++)cout<<dp[i]<<" ";cout<<"\n";
//	for(i=2;i<=n;i++)cout<<dpl[i]<<" ";cout<<"\n";
     for(i=1;i<=n-1;i++)
     {
     	ll s=i;
     	ll ind=1+i;
     	if(dpl[ind]==1)
     	{
     		cout<<s+dp[ind]<<"\n";
		 }
		 else cout<<"-1\n";
	 }
	return 0;
}


//By Vasu Agrawal
#include<iostream>
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pob pop_back
#define mk make_pair
#define fr first
#define sc second
#define pu push
#define ins insert
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define V(a) vector<a>
#define pp pair<ll,ll>
#define lb(a,n) lower_bound(a.begin(),a.end(),n)-a.begin()
#define ub(a,n) upper_bound(a.begin(),a.end(),n)-a.begin()
#define F(i,n) for(ll i=0;i<n;i++)
#define in(a,n) F(i,n) cin>>a[i]
#define in1(a,n) f(i,n) cin>>a[i]
#define out1(a,n); f(i,n) cout<<a[i]<<" ";cout<<endl;
#define out(a,n); F(i,n) cout<<a[i]<<" ";cout<<endl;
#define f(i,n) for(ll i=1;i<=n;i++)
#define vasu2907 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
bool isprime(ll n) //Time Complexity--->sqrt(n)
{   if (n <= 1)  return false; if (n <= 3)  return true;
  	if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false;
    return true;
}
vector<ll> prime;
void sieve(ll n)
{	bool bakh[n+1];memset(bakh, true, sizeof(bakh));
    for (ll p=2; p*p<=n; p++)
    {	if (bakh[p] == true)
        {	for (ll i=p*p; i<=n; i += p)    bakh[i] = false; } }
  	for (ll p=2; p<=n; p++)    if (bakh[p])
	  	prime.pb(p);
}//Taken from https://www.geeksforgeeks.org/eulers-totient-function-for-all-numbers-smaller-than-or-equal-to-n/
ll eulertotient(ll z)   //Time--->n/logn
{	ll fac=z;
	for(ll i=0;prime[i]*prime[i]<=z;i++)
	{	if(z%prime[i]==0)
		{	fac-=(fac/prime[i]);	while(z%prime[i]==0)	z/=prime[i];	}
	}	if(z>1)	fac-=(fac/z);
	return fac;
}
//Taken from https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/
ll power(ll x,ll y,ll p)
{	ll res = 1; x = x % p;	while (y > 0)  {	if (y & 1)	res = (res*x) % p; 	y = y>>1;	x = (x*x) % p; }return res; }
//Taken from https://www.geeksforgeeks.org/euclidean-algorithms-basic-and-extended/
ll gcd(ll a,ll b)
{	if (a == 0)    return b; 	return gcd(b % a, a); }
ll lcm(ll a,ll b)
{	ll g=gcd(a,b); ll ans=(a*b)/g; return ans;	}
//Taken from https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/
ll modInverse(ll a, ll m)
{	ll hvf=gcd(a,m);	if(hvf==1)	return power(a,m-2,m);	return -1;}
void multiply(ll F[2][2], ll M[2][2])
{ ll x =  F[0][0]*M[0][0] + F[0][1]*M[1][0];  ll y =  F[0][0]*M[0][1] + F[0][1]*M[1][1];
  ll z =  F[1][0]*M[0][0] + F[1][1]*M[1][0];  ll w =  F[1][0]*M[0][1] + F[1][1]*M[1][1];
  F[0][0] = x;   F[0][1] = y;   F[1][0] = z;   F[1][1] = w;
}
void powermat(ll F[2][2], ll n)
{	if( n == 0 || n == 1)
    return; ll M[2][2] = {{1,1},{1,0}};   powermat(F, n/2);   multiply(F, F);   if (n%2 != 0)      multiply(F, M);
}
ll fib(ll n)
{ ll F[2][2] = {{1,1},{1,0}};
  if (n == 0) return 0; powermat(F, n-1);   return F[0][0];
}
V(ll) merge(V(ll) v1,V(ll) v2)
{	V(ll) temp;
	ll i=0,j=0;
	while(i<v1.size() && j<v2.size())
	{	if(v1[i]<v2[j])
			temp.pb(v1[i]),i++;
		else
			temp.pb(v2[j]),j++;
	}
	while(i<v1.size())
		temp.pb(v1[i]),i++;
	while(j<v2.size())
		temp.pb(v2[j]),j++;
	return temp;
}
//ll root(ll x)
//{	while(par[x]!=x)
//	{	par[x]=par[par[x]];
//		x=par[x];
//	}
//	return x;
//}
//void uni(ll x,ll y)
//{	x=root(x);
//	y=root(y);
//	if(val[x]<=val[y])
//		par[y]=par[x];
//	else
//		par[x]=par[y];
//}

//id=(id&(id+1))-1
//ll fetch(ll id)
//{
//}
//id=(id|(id+1))
//void update(ll id)
//{
//}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// Code Starts Here
ll dp[200005][2];
bool mark[200005][2];
ll ar[200005],n;
ll dfs(ll i,ll st)
{	if(i<=0 || i>n)	return 0;
	if(mark[i][st])	return -1;
	if(dp[i][st])	return dp[i][st];
	mark[i][st]=1;
	ll ans=0;
	if(st)	ans=dfs(i+ar[i],1-st);
	else	ans=dfs(i-ar[i],1-st);
	mark[i][st]=0;
	if(ans==-1)	return dp[i][st]=-1;
	return dp[i][st]=ar[i]+ans;
}
int main()
{	vasu2907;
	cin>>n;
	for(ll i=2;i<=n;i++)
		cin>>ar[i];
	ll ans=0;
	for(ll i=2;i<=n;i++)
	{	dfs(i,0);
	}
	for(ll i=2;i<=n;i++)
	{	if(dp[i][0]==-1)
			cout<<-1<<endl;
		else
			cout<<i-1+dp[i][0]<<endl;
	}
}


//By Vasu Agrawal
#include<iostream>
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pob pop_back
#define mk make_pair
#define fr first
#define sc second
#define pu push
#define ins insert
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define V(a) vector<a>
#define pp pair<ll,ll>
#define lb(a,n) lower_bound(a.begin(),a.end(),n)-a.begin()
#define ub(a,n) upper_bound(a.begin(),a.end(),n)-a.begin()
#define F(i,n) for(ll i=0;i<n;i++)
#define in(a,n) F(i,n) cin>>a[i]
#define in1(a,n) f(i,n) cin>>a[i]
#define out1(a,n); f(i,n) cout<<a[i]<<" ";cout<<endl;
#define out(a,n); F(i,n) cout<<a[i]<<" ";cout<<endl;
#define f(i,n) for(ll i=1;i<=n;i++)
#define vasu2907 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
bool isprime(ll n) //Time Complexity--->sqrt(n)
{   if (n <= 1)  return false; if (n <= 3)  return true;
  	if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false;
    return true;
}
vector<ll> prime;
void sieve(ll n)
{	bool bakh[n+1];memset(bakh, true, sizeof(bakh));
    for (ll p=2; p*p<=n; p++)
    {	if (bakh[p] == true)
        {	for (ll i=p*p; i<=n; i += p)    bakh[i] = false; } }
  	for (ll p=2; p<=n; p++)    if (bakh[p])
	  	prime.pb(p);
}//Taken from https://www.geeksforgeeks.org/eulers-totient-function-for-all-numbers-smaller-than-or-equal-to-n/
ll eulertotient(ll z)   //Time--->n/logn
{	ll fac=z;
	for(ll i=0;prime[i]*prime[i]<=z;i++)
	{	if(z%prime[i]==0)
		{	fac-=(fac/prime[i]);	while(z%prime[i]==0)	z/=prime[i];	}
	}	if(z>1)	fac-=(fac/z);
	return fac;
}
//Taken from https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/
ll power(ll x,ll y,ll p)
{	ll res = 1; x = x % p;	while (y > 0)  {	if (y & 1)	res = (res*x) % p; 	y = y>>1;	x = (x*x) % p; }return res; }
//Taken from https://www.geeksforgeeks.org/euclidean-algorithms-basic-and-extended/
ll gcd(ll a,ll b)
{	if (a == 0)    return b; 	return gcd(b % a, a); }
ll lcm(ll a,ll b)
{	ll g=gcd(a,b); ll ans=(a*b)/g; return ans;	}
//Taken from https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/
ll modInverse(ll a, ll m)
{	ll hvf=gcd(a,m);	if(hvf==1)	return power(a,m-2,m);	return -1;}
void multiply(ll F[2][2], ll M[2][2])
{ ll x =  F[0][0]*M[0][0] + F[0][1]*M[1][0];  ll y =  F[0][0]*M[0][1] + F[0][1]*M[1][1];
  ll z =  F[1][0]*M[0][0] + F[1][1]*M[1][0];  ll w =  F[1][0]*M[0][1] + F[1][1]*M[1][1];
  F[0][0] = x;   F[0][1] = y;   F[1][0] = z;   F[1][1] = w;
}
void powermat(ll F[2][2], ll n)
{	if( n == 0 || n == 1)
    return; ll M[2][2] = {{1,1},{1,0}};   powermat(F, n/2);   multiply(F, F);   if (n%2 != 0)      multiply(F, M);
}
ll fib(ll n)
{ ll F[2][2] = {{1,1},{1,0}};
  if (n == 0) return 0; powermat(F, n-1);   return F[0][0];
}
V(ll) merge(V(ll) v1,V(ll) v2)
{	V(ll) temp;
	ll i=0,j=0;
	while(i<v1.size() && j<v2.size())
	{	if(v1[i]<v2[j])
			temp.pb(v1[i]),i++;
		else
			temp.pb(v2[j]),j++;
	}
	while(i<v1.size())
		temp.pb(v1[i]),i++;
	while(j<v2.size())
		temp.pb(v2[j]),j++;
	return temp;
}
//ll root(ll x)
//{	while(par[x]!=x)
//	{	par[x]=par[par[x]];
//		x=par[x];
//	}
//	return x;
//}
//void uni(ll x,ll y)
//{	x=root(x);
//	y=root(y);
//	if(val[x]<=val[y])
//		par[y]=par[x];
//	else
//		par[x]=par[y];
//}

//id=(id&(id+1))-1
//ll fetch(ll id)
//{
//}
//id=(id|(id+1))
//void update(ll id)
//{
//}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// Code Starts Here
ll dp[200005][2];
bool mark[200005][2];
ll ar[200005],n;
ll dfs(ll i,ll st)
{
//	cout<<"I="<<i<<" St="<<st<<endl;
	if(i<=0 || i>n)
		return 0;
//	cout<<"cn";
	if(dp[i][st]!=-1)
		return dp[i][st];
//	cout<<"njb";
	if(mark[i][st])
		return INT_MIN;
	mark[i][st]=1;
//	cout<<"njfe";
	if(st==0)
		return dp[i][st]=ar[i]+dfs(i-ar[i],1-st);
	else
		return dp[i][st]=ar[i]+dfs(i+ar[i],1-st);
}
int main()
{	vasu2907;
	cin>>n;
	for(ll i=2;i<=n;i++)
		cin>>ar[i];
//	out1(ar,n);
	F(i,n+1)	dp[i][0]=dp[i][1]=-1;
//	F(i,n)	cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
	for(ll i=2;i<=n;i++)
	{	if(!mark[i][1])
			dfs(i,0);
	}
	mark[1][1]=1;
	for(ll i=1;i<n;i++)
	{	if(dp[1+i][0]<=0)
			cout<<"-1\n";
		else
			cout<<i+dp[i+1][0]<<"\n";
	}
}


//By Vasu Agrawal
#include<iostream>
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pob pop_back
#define mk make_pair
#define fr first
#define sc second
#define pu push
#define ins insert
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define V(a) vector<a>
#define pp pair<ll,ll>
#define lb(a,n) lower_bound(a.begin(),a.end(),n)-a.begin()
#define ub(a,n) upper_bound(a.begin(),a.end(),n)-a.begin()
#define F(i,n) for(ll i=0;i<n;i++)
#define in(a,n) F(i,n) cin>>a[i]
#define in1(a,n) f(i,n) cin>>a[i]
#define out1(a,n); f(i,n) cout<<a[i]<<" ";cout<<endl;
#define out(a,n); F(i,n) cout<<a[i]<<" ";cout<<endl;
#define f(i,n) for(ll i=1;i<=n;i++)
#define vasu2907 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
bool isprime(ll n) //Time Complexity--->sqrt(n)
{   if (n <= 1)  return false; if (n <= 3)  return true;
  	if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false;
    return true;
}
vector<ll> prime;
void sieve(ll n)
{	bool bakh[n+1];memset(bakh, true, sizeof(bakh));
    for (ll p=2; p*p<=n; p++)
    {	if (bakh[p] == true)
        {	for (ll i=p*p; i<=n; i += p)    bakh[i] = false; } }
  	for (ll p=2; p<=n; p++)    if (bakh[p])
	  	prime.pb(p);
}//Taken from https://www.geeksforgeeks.org/eulers-totient-function-for-all-numbers-smaller-than-or-equal-to-n/
ll eulertotient(ll z)   //Time--->n/logn
{	ll fac=z;
	for(ll i=0;prime[i]*prime[i]<=z;i++)
	{	if(z%prime[i]==0)
		{	fac-=(fac/prime[i]);	while(z%prime[i]==0)	z/=prime[i];	}
	}	if(z>1)	fac-=(fac/z);
	return fac;
}
//Taken from https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/
ll power(ll x,ll y,ll p)
{	ll res = 1; x = x % p;	while (y > 0)  {	if (y & 1)	res = (res*x) % p; 	y = y>>1;	x = (x*x) % p; }return res; }
//Taken from https://www.geeksforgeeks.org/euclidean-algorithms-basic-and-extended/
ll gcd(ll a,ll b)
{	if (a == 0)    return b; 	return gcd(b % a, a); }
ll lcm(ll a,ll b)
{	ll g=gcd(a,b); ll ans=(a*b)/g; return ans;	}
//Taken from https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/
ll modInverse(ll a, ll m)
{	ll hvf=gcd(a,m);	if(hvf==1)	return power(a,m-2,m);	return -1;}
void multiply(ll F[2][2], ll M[2][2])
{ ll x =  F[0][0]*M[0][0] + F[0][1]*M[1][0];  ll y =  F[0][0]*M[0][1] + F[0][1]*M[1][1];
  ll z =  F[1][0]*M[0][0] + F[1][1]*M[1][0];  ll w =  F[1][0]*M[0][1] + F[1][1]*M[1][1];
  F[0][0] = x;   F[0][1] = y;   F[1][0] = z;   F[1][1] = w;
}
void powermat(ll F[2][2], ll n)
{	if( n == 0 || n == 1)
    return; ll M[2][2] = {{1,1},{1,0}};   powermat(F, n/2);   multiply(F, F);   if (n%2 != 0)      multiply(F, M);
}
ll fib(ll n)
{ ll F[2][2] = {{1,1},{1,0}};
  if (n == 0) return 0; powermat(F, n-1);   return F[0][0];
}
V(ll) merge(V(ll) v1,V(ll) v2)
{	V(ll) temp;
	ll i=0,j=0;
	while(i<v1.size() && j<v2.size())
	{	if(v1[i]<v2[j])
			temp.pb(v1[i]),i++;
		else
			temp.pb(v2[j]),j++;
	}
	while(i<v1.size())
		temp.pb(v1[i]),i++;
	while(j<v2.size())
		temp.pb(v2[j]),j++;
	return temp;
}
//ll root(ll x)
//{	while(par[x]!=x)
//	{	par[x]=par[par[x]];
//		x=par[x];
//	}
//	return x;
//}
//void uni(ll x,ll y)
//{	x=root(x);
//	y=root(y);
//	if(val[x]<=val[y])
//		par[y]=par[x];
//	else
//		par[x]=par[y];
//}

//id=(id&(id+1))-1
//ll fetch(ll id)
//{
//}
//id=(id|(id+1))
//void update(ll id)
//{
//}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// Code Starts Here
ll dp[200005][2];
bool mark[200005][2];
ll ar[200005],n;
ll dfs(ll i,ll st)
{
//	cout<<"I="<<i<<" St="<<st<<endl;
	if(i<=0 || i>n)
		return 0;
//	cout<<"cn";
	if(dp[i][st]!=-1)
		return dp[i][st];
//	cout<<"njb";
	if(mark[i][st])
		return INT_MIN;
	mark[i][st]=1;
//	cout<<"njfe";
	if(st==0)
		return dp[i][st]=ar[i]+dfs(i-ar[i],1-st);
	else
		return dp[i][st]=ar[i]+dfs(i+ar[i],1-st);
}
int main()
{	vasu2907;
	cin>>n;
	for(ll i=2;i<=n;i++)
		cin>>ar[i];
//	out1(ar,n);
	F(i,n+1)	dp[i][0]=dp[i][1]=-1;
//	F(i,n)	cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
	for(ll i=2;i<=n;i++)
	{	if(!mark[i][1])
			dfs(i,0);
	}
	mark[1][1]=1;
	for(ll i=1;i<n;i++)
	{	if(dp[1+i][0]<0)
			cout<<"-1\n";
		else
			cout<<i+dp[i+1][0]<<"\n";
	}
}


//By Vasu Agrawal
#include<iostream>
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pob pop_back
#define mk make_pair
#define fr first
#define sc second
#define pu push
#define ins insert
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define V(a) vector<a>
#define pp pair<ll,ll>
#define lb(a,n) lower_bound(a.begin(),a.end(),n)-a.begin()
#define ub(a,n) upper_bound(a.begin(),a.end(),n)-a.begin()
#define F(i,n) for(ll i=0;i<n;i++)
#define in(a,n) F(i,n) cin>>a[i]
#define in1(a,n) f(i,n) cin>>a[i]
#define out1(a,n); f(i,n) cout<<a[i]<<" ";cout<<endl;
#define out(a,n); F(i,n) cout<<a[i]<<" ";cout<<endl;
#define f(i,n) for(ll i=1;i<=n;i++)
#define vasu2907 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
bool isprime(ll n) //Time Complexity--->sqrt(n)
{   if (n <= 1)  return false; if (n <= 3)  return true;
  	if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false;
    return true;
}
vector<ll> prime;
void sieve(ll n)
{	bool bakh[n+1];memset(bakh, true, sizeof(bakh));
    for (ll p=2; p*p<=n; p++)
    {	if (bakh[p] == true)
        {	for (ll i=p*p; i<=n; i += p)    bakh[i] = false; } }
  	for (ll p=2; p<=n; p++)    if (bakh[p])
	  	prime.pb(p);
}//Taken from https://www.geeksforgeeks.org/eulers-totient-function-for-all-numbers-smaller-than-or-equal-to-n/
ll eulertotient(ll z)   //Time--->n/logn
{	ll fac=z;
	for(ll i=0;prime[i]*prime[i]<=z;i++)
	{	if(z%prime[i]==0)
		{	fac-=(fac/prime[i]);	while(z%prime[i]==0)	z/=prime[i];	}
	}	if(z>1)	fac-=(fac/z);
	return fac;
}
//Taken from https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/
ll power(ll x,ll y,ll p)
{	ll res = 1; x = x % p;	while (y > 0)  {	if (y & 1)	res = (res*x) % p; 	y = y>>1;	x = (x*x) % p; }return res; }
//Taken from https://www.geeksforgeeks.org/euclidean-algorithms-basic-and-extended/
ll gcd(ll a,ll b)
{	if (a == 0)    return b; 	return gcd(b % a, a); }
ll lcm(ll a,ll b)
{	ll g=gcd(a,b); ll ans=(a*b)/g; return ans;	}
//Taken from https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/
ll modInverse(ll a, ll m)
{	ll hvf=gcd(a,m);	if(hvf==1)	return power(a,m-2,m);	return -1;}
void multiply(ll F[2][2], ll M[2][2])
{ ll x =  F[0][0]*M[0][0] + F[0][1]*M[1][0];  ll y =  F[0][0]*M[0][1] + F[0][1]*M[1][1];
  ll z =  F[1][0]*M[0][0] + F[1][1]*M[1][0];  ll w =  F[1][0]*M[0][1] + F[1][1]*M[1][1];
  F[0][0] = x;   F[0][1] = y;   F[1][0] = z;   F[1][1] = w;
}
void powermat(ll F[2][2], ll n)
{	if( n == 0 || n == 1)
    return; ll M[2][2] = {{1,1},{1,0}};   powermat(F, n/2);   multiply(F, F);   if (n%2 != 0)      multiply(F, M);
}
ll fib(ll n)
{ ll F[2][2] = {{1,1},{1,0}};
  if (n == 0) return 0; powermat(F, n-1);   return F[0][0];
}
V(ll) merge(V(ll) v1,V(ll) v2)
{	V(ll) temp;
	ll i=0,j=0;
	while(i<v1.size() && j<v2.size())
	{	if(v1[i]<v2[j])
			temp.pb(v1[i]),i++;
		else
			temp.pb(v2[j]),j++;
	}
	while(i<v1.size())
		temp.pb(v1[i]),i++;
	while(j<v2.size())
		temp.pb(v2[j]),j++;
	return temp;
}
//ll root(ll x)
//{	while(par[x]!=x)
//	{	par[x]=par[par[x]];
//		x=par[x];
//	}
//	return x;
//}
//void uni(ll x,ll y)
//{	x=root(x);
//	y=root(y);
//	if(val[x]<=val[y])
//		par[y]=par[x];
//	else
//		par[x]=par[y];
//}

//id=(id&(id+1))-1
//ll fetch(ll id)
//{
//}
//id=(id|(id+1))
//void update(ll id)
//{
//}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// Code Starts Here
ll dp[200005][2];
bool mark[200005][2];
ll ar[200005],n;
ll dfs(ll i,ll st,ll s)
{
//	cout<<"I="<<i<<" St="<<st<<" S="<<s<<endl;
	if(i<=0 || i>n)
		return s;
//	cout<<"cn";
	if(dp[i][st]!=-1)
		return dp[i][st];
//	cout<<"njb";
	if(mark[i][st])
		return INT_MIN;
	mark[i][st]=1;
//	cout<<"njfe";
	if(st==0)
		return dp[i][st]=dfs(i-ar[i],1-st,s+ar[i]);
	else
		return dp[i][st]=dfs(i+ar[i],1-st,s+ar[i]);
}
int main()
{	vasu2907;
	cin>>n;
	for(ll i=2;i<=n;i++)
		cin>>ar[i];
//	out1(ar,n);
	F(i,n+1)	dp[i][0]=dp[i][1]=-1;
//	F(i,n)	cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
	for(ll i=2;i<=n;i++)
	{	if(!mark[i][1])
			dfs(i,0,0);
	}
	mark[1][1]=1;
	for(ll i=1;i<n;i++)
	{	if(dp[1+i][0]==INT_MIN)
			cout<<"-1\n";
		else
			cout<<i+dp[i+1][0]<<"\n";
	}
	cout<<endl;
}


//By Vasu Agrawal
#include<iostream>
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pob pop_back
#define mk make_pair
#define fr first
#define sc second
#define pu push
#define ins insert
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define V(a) vector<a>
#define pp pair<ll,ll>
#define lb(a,n) lower_bound(a.begin(),a.end(),n)-a.begin()
#define ub(a,n) upper_bound(a.begin(),a.end(),n)-a.begin()
#define F(i,n) for(ll i=0;i<n;i++)
#define in(a,n) F(i,n) cin>>a[i]
#define in1(a,n) f(i,n) cin>>a[i]
#define out1(a,n); f(i,n) cout<<a[i]<<" ";cout<<endl;
#define out(a,n); F(i,n) cout<<a[i]<<" ";cout<<endl;
#define f(i,n) for(ll i=1;i<=n;i++)
#define vasu2907 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
bool isprime(ll n) //Time Complexity--->sqrt(n)
{   if (n <= 1)  return false; if (n <= 3)  return true;
  	if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false;
    return true;
}
vector<ll> prime;
void sieve(ll n)
{	bool bakh[n+1];memset(bakh, true, sizeof(bakh));
    for (ll p=2; p*p<=n; p++)
    {	if (bakh[p] == true)
        {	for (ll i=p*p; i<=n; i += p)    bakh[i] = false; } }
  	for (ll p=2; p<=n; p++)    if (bakh[p])
	  	prime.pb(p);
}//Taken from https://www.geeksforgeeks.org/eulers-totient-function-for-all-numbers-smaller-than-or-equal-to-n/
ll eulertotient(ll z)   //Time--->n/logn
{	ll fac=z;
	for(ll i=0;prime[i]*prime[i]<=z;i++)
	{	if(z%prime[i]==0)
		{	fac-=(fac/prime[i]);	while(z%prime[i]==0)	z/=prime[i];	}
	}	if(z>1)	fac-=(fac/z);
	return fac;
}
//Taken from https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/
ll power(ll x,ll y,ll p)
{	ll res = 1; x = x % p;	while (y > 0)  {	if (y & 1)	res = (res*x) % p; 	y = y>>1;	x = (x*x) % p; }return res; }
//Taken from https://www.geeksforgeeks.org/euclidean-algorithms-basic-and-extended/
ll gcd(ll a,ll b)
{	if (a == 0)    return b; 	return gcd(b % a, a); }
ll lcm(ll a,ll b)
{	ll g=gcd(a,b); ll ans=(a*b)/g; return ans;	}
//Taken from https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/
ll modInverse(ll a, ll m)
{	ll hvf=gcd(a,m);	if(hvf==1)	return power(a,m-2,m);	return -1;}
void multiply(ll F[2][2], ll M[2][2])
{ ll x =  F[0][0]*M[0][0] + F[0][1]*M[1][0];  ll y =  F[0][0]*M[0][1] + F[0][1]*M[1][1];
  ll z =  F[1][0]*M[0][0] + F[1][1]*M[1][0];  ll w =  F[1][0]*M[0][1] + F[1][1]*M[1][1];
  F[0][0] = x;   F[0][1] = y;   F[1][0] = z;   F[1][1] = w;
}
void powermat(ll F[2][2], ll n)
{	if( n == 0 || n == 1)
    return; ll M[2][2] = {{1,1},{1,0}};   powermat(F, n/2);   multiply(F, F);   if (n%2 != 0)      multiply(F, M);
}
ll fib(ll n)
{ ll F[2][2] = {{1,1},{1,0}};
  if (n == 0) return 0; powermat(F, n-1);   return F[0][0];
}
V(ll) merge(V(ll) v1,V(ll) v2)
{	V(ll) temp;
	ll i=0,j=0;
	while(i<v1.size() && j<v2.size())
	{	if(v1[i]<v2[j])
			temp.pb(v1[i]),i++;
		else
			temp.pb(v2[j]),j++;
	}
	while(i<v1.size())
		temp.pb(v1[i]),i++;
	while(j<v2.size())
		temp.pb(v2[j]),j++;
	return temp;
}
//ll root(ll x)
//{	while(par[x]!=x)
//	{	par[x]=par[par[x]];
//		x=par[x];
//	}
//	return x;
//}
//void uni(ll x,ll y)
//{	x=root(x);
//	y=root(y);
//	if(val[x]<=val[y])
//		par[y]=par[x];
//	else
//		par[x]=par[y];
//}

//id=(id&(id+1))-1
//ll fetch(ll id)
//{
//}
//id=(id|(id+1))
//void update(ll id)
//{
//}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// Code Starts Here
ll dp[200005][2];
bool mark[200005][2];
ll ar[200005],n;
ll dfs(ll i,ll st)
{	if(i<=0 || i>n)	return 0;
	if(mark[i][st])	return -1;
	if(dp[i][st])	return dp[i][st];
	mark[i][st]=1;
	ll ans=0;
	if(st)	ans=dfs(i+ar[i],1-st);
	else	ans=dfs(i-ar[i],1-st);
	mark[i][st]=0;
	if(ans==-1)	return dp[i][st]=-1;
	return dp[i][st]=ar[i]+ans;
}
int main()
{	vasu2907;
	cin>>n;
	for(ll i=2;i<=n;i++)
		cin>>ar[i];
	ll ans=0;
	for(ll i=2;i<=n;i++)
	{	ans=dfs(i,0);
		if(ans==-1)	cout<<ans<<endl;
		else cout<<i-1+ans<<endl;
	}
}


//By Vasu Agrawal
#include<iostream>
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pob pop_back
#define mk make_pair
#define fr first
#define sc second
#define pu push
#define ins insert
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define V(a) vector<a>
#define pp pair<ll,ll>
#define lb(a,n) lower_bound(a.begin(),a.end(),n)-a.begin()
#define ub(a,n) upper_bound(a.begin(),a.end(),n)-a.begin()
#define F(i,n) for(ll i=0;i<n;i++)
#define in(a,n) F(i,n) cin>>a[i]
#define in1(a,n) f(i,n) cin>>a[i]
#define out1(a,n); f(i,n) cout<<a[i]<<" ";cout<<endl;
#define out(a,n); F(i,n) cout<<a[i]<<" ";cout<<endl;
#define f(i,n) for(ll i=1;i<=n;i++)
#define vasu2907 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
bool isprime(ll n) //Time Complexity--->sqrt(n)
{   if (n <= 1)  return false; if (n <= 3)  return true;
  	if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false;
    return true;
}
vector<ll> prime;
void sieve(ll n)
{	bool bakh[n+1];memset(bakh, true, sizeof(bakh));
    for (ll p=2; p*p<=n; p++)
    {	if (bakh[p] == true)
        {	for (ll i=p*p; i<=n; i += p)    bakh[i] = false; } }
  	for (ll p=2; p<=n; p++)    if (bakh[p])
	  	prime.pb(p);
}//Taken from https://www.geeksforgeeks.org/eulers-totient-function-for-all-numbers-smaller-than-or-equal-to-n/
ll eulertotient(ll z)   //Time--->n/logn
{	ll fac=z;
	for(ll i=0;prime[i]*prime[i]<=z;i++)
	{	if(z%prime[i]==0)
		{	fac-=(fac/prime[i]);	while(z%prime[i]==0)	z/=prime[i];	}
	}	if(z>1)	fac-=(fac/z);
	return fac;
}
//Taken from https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/
ll power(ll x,ll y,ll p)
{	ll res = 1; x = x % p;	while (y > 0)  {	if (y & 1)	res = (res*x) % p; 	y = y>>1;	x = (x*x) % p; }return res; }
//Taken from https://www.geeksforgeeks.org/euclidean-algorithms-basic-and-extended/
ll gcd(ll a,ll b)
{	if (a == 0)    return b; 	return gcd(b % a, a); }
ll lcm(ll a,ll b)
{	ll g=gcd(a,b); ll ans=(a*b)/g; return ans;	}
//Taken from https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/
ll modInverse(ll a, ll m)
{	ll hvf=gcd(a,m);	if(hvf==1)	return power(a,m-2,m);	return -1;}
void multiply(ll F[2][2], ll M[2][2])
{ ll x =  F[0][0]*M[0][0] + F[0][1]*M[1][0];  ll y =  F[0][0]*M[0][1] + F[0][1]*M[1][1];
  ll z =  F[1][0]*M[0][0] + F[1][1]*M[1][0];  ll w =  F[1][0]*M[0][1] + F[1][1]*M[1][1];
  F[0][0] = x;   F[0][1] = y;   F[1][0] = z;   F[1][1] = w;
}
void powermat(ll F[2][2], ll n)
{	if( n == 0 || n == 1)
    return; ll M[2][2] = {{1,1},{1,0}};   powermat(F, n/2);   multiply(F, F);   if (n%2 != 0)      multiply(F, M);
}
ll fib(ll n)
{ ll F[2][2] = {{1,1},{1,0}};
  if (n == 0) return 0; powermat(F, n-1);   return F[0][0];
}
V(ll) merge(V(ll) v1,V(ll) v2)
{	V(ll) temp;
	ll i=0,j=0;
	while(i<v1.size() && j<v2.size())
	{	if(v1[i]<v2[j])
			temp.pb(v1[i]),i++;
		else
			temp.pb(v2[j]),j++;
	}
	while(i<v1.size())
		temp.pb(v1[i]),i++;
	while(j<v2.size())
		temp.pb(v2[j]),j++;
	return temp;
}
//ll root(ll x)
//{	while(par[x]!=x)
//	{	par[x]=par[par[x]];
//		x=par[x];
//	}
//	return x;
//}
//void uni(ll x,ll y)
//{	x=root(x);
//	y=root(y);
//	if(val[x]<=val[y])
//		par[y]=par[x];
//	else
//		par[x]=par[y];
//}

//id=(id&(id+1))-1
//ll fetch(ll id)
//{
//}
//id=(id|(id+1))
//void update(ll id)
//{
//}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// Code Starts Here
ll dp[200005][2];
bool mark[200005][2];
ll ar[200005],n;
ll dfs(ll i,ll st,ll s)
{
//	cout<<"I="<<i<<" St="<<st<<" S="<<s<<endl;
	if(i<=0 || i>n)
		return s;
//	cout<<"cn";
	if(dp[i][st]!=-1)
		return dp[i][st];
//	cout<<"njb";
	if(mark[i][st])
		return INT_MIN;
	mark[i][st]=1;
//	cout<<"njfe";
	if(st==0)
		return dp[i][st]=dfs(i-ar[i],1-st,s+ar[i]);
	else
		return dp[i][st]=dfs(i+ar[i],1-st,s+ar[i]);
}
int main()
{	vasu2907;
	cin>>n;
	for(ll i=2;i<=n;i++)
		cin>>ar[i];
	out1(ar,n);
	F(i,n+1)	dp[i][0]=dp[i][1]=-1;
//	F(i,n)	cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
	for(ll i=2;i<=n;i++)
	{	if(!mark[i][1])
			dfs(i,0,0);
	}
	mark[1][1]=1;
	for(ll i=1;i<n;i++)
	{	if(dp[1+i][0]==INT_MIN)
			cout<<"-1\n";
		else
			cout<<i+dp[i+1][0]<<"\n";
	}
	cout<<endl;
}


#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 << -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;
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;
	}
	vis[tfunc(start)] = true;
	vis[start] = true;
	temp.pb(start);
	temp.pb(tfunc(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, vis[MAXN][2];

ll func(ll ft, ll start, ll state)
{
	if(start <= 0 || start > n)
	{
		return 0;
	}
	if(vis[start][state] == 1)
	{
		f = -1;
		return -1;
	}
	if(vis[start][state] == 2) return dp[start][state];
	if(vis[start][state] == 0)
	{
		vis[start][state] = 1;
		if(state == 0)
		{
			if(start + a[start] <= n)
			{
				ll g = func(ft, start + a[start], state ^ 1);
				if(g == -1)
					dp[start][state] = -1;
				else
					dp[start][state] = a[start] + g;
			}
			else
			{
				dp[start][state] = a[start];
			}
		}
		else
		{
			if(start - a[start] <= 0)
			{
				dp[start][state] = a[start];
			}
			else
			{
				ll g = func(ft, 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];
    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;
		dp[1][0] = dp[1][1] = -1;
		vis[1][0] = vis[1][1] = 0;
	}
    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, 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];
    memset(dp, -1, sizeof(dp));
	for(int i=1;i<n;i++)
	{
		f = 0;
		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, temp2;
bool vis[MAXN], vis2[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 && 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);
	// cout << dp[start] << endl;
	if(dp[start] != -1) return dp[start];
	else
	{
		// cout << "start = " << start << endl;
		// cout << tfunc(start) << " " << tfunc(start) - a[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();
		for(int j=0;j<temp2.size();j++)
		{
			vis[temp2[j]] = false;
		}
		temp2.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], 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);
	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;
bool vis[MAXN];

ll tfunc(ll x)
{
	return x + a[x];
}
ll func(ll ft, ll start)
{
	if(vis[start])
	{
		f = -1;
		return 0;
	}
	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();
		dp[1] = -1;
	}
    return 0;
}