// Arup Guha
// 4/29/2022
// Solution to Spring 2022 COP 3502 Final Exam Question 10

#include <stdio.h>
#include <stdlib.h>

int* wrapper(int* diff, int n);
int* go(int* diff, int* perm, int k, int* used, int n);

int main(void) {

    // Read the # of items.
    int n;
    scanf("%d", &n);

    // Allocate space and read in the differences.
    int* diff = calloc(n-1, sizeof(int));
    for (int i=0; i<n-1; i++) scanf("%d", &diff[i]);

    // Get our answer.
    int* res = wrapper(diff, n);

    // If it exists, print it!
    if (res != NULL) {
        for (int i=0; i<n; i++)
            printf("%d ", res[i]);
        printf("\n");
        free(res);
    }

    // Can't do it.
    else
        printf("Impossible\n");

    // Just have this to free.
    free(diff);

    return 0;
}

// Returns the first lexicographical permutation of n elements that has the difference sequence diff, or NULL
// if none exists.
int* wrapper(int* diff, int n) {

    // set these up.
    int* perm = calloc(n, sizeof(int));
    int* used = calloc(n, sizeof(int));

    // Try each item first.
    for (int i=0; i<n; i++) {

        // Put i first.
        perm[0] = i;
        used[i] = 1;

        // Try this out.
        int* tmp = go(diff, perm, 1, used, n);

        // Got a winner, return it.
        if (tmp != NULL) {
            free(used);
            return tmp;
        }

        // Undo.
        used[i] = 0;
    }

    // Not needed any more.
    free(perm);
    free(used);

    // No answer.
    return NULL;
}

// Returns the first answer with the first k items of perm fixed.
int* go(int* diff, int* perm, int k, int* used, int n) {

    // We made it.
    if (k == n) return perm;

    // Here we store the two possible next terms.
    int step[2];

    // This is if item k is smaller than item k-1.
    step[0] = perm[k-1] - diff[k-1];

    // And bigger...
    step[1] = perm[k-1] + diff[k-1];

    // Looping through our two possible choices.
    for (int i=0; i<2; i++) {

        // So, our number must be in range and not previously used.
        if (step[i] >= 0 && step[i] < n && !used[step[i]]) {

            // Put this number in slot k and mark it as used.
            perm[k] = step[i];
            used[step[i]] = 1;

            // Recurse!
            int* tmp = go(diff, perm, k+1, used, n);

            // Woohoo, a solution!
            if (tmp != NULL) return tmp;

            // Didn't work if we got here, so unset this item.
            used[step[i]] = 0;
        }
    }

    // No solution works down this path.
    return NULL;
}
