Reverse Trip to Jerusalem
Difficulty: Hard

You and your $N-1$ friends recently got tired of playing Trip to Jerusalem (i.e. Musical Chairs). In order to make things interesting again, you decide to invent a new game. And you call it *Reverse Trip to Jerusalem*.

Here's how it works. Instead of arranging the chairs in a circle, the $N$ friends (including you) arrange yourselves in a circle. Then exactly one person in the circle holds the chair.

For the first round, all $N$ of you will be in the circle. The music starts and plays for $C_1$ seconds. Every second, the person holding the chair shall pass it to the person to his left. The person who receives the chair when the music ends is OUT and he/she is not included in the circle in the subsequent rounds. The person to his left then receives the chair. And that's where the chair starts for the second round.

For the $i^\text{th}$ round, $N-i+1$ players remain and the person holding the chair is the person to the left of the most recently outed person. The music starts and plays for $C_i$ seconds. The procedure for passing the chair is the same as the first round. The player who receives the chair when the music ends is OUT.

The person who remains after $N-1$ rounds is the winner.

Of course, you want to win this. It is your dream and you believe that you will survive. The person who initially holds the chair in the first round is Todd. You wish to know where to position yourself in order to win the game.

**Input Format**  
The input consists of two lines.
The first line contains a single integer $N$.
The second line contains $N-1$ integers, the $C_i$'s, each separated by single spaces.

**Output Format**  
Output a single line describing the winning position. If the winning position is the $P^\text{th}$ position to the left of Todd, then output the integer $P$ (Note that $0 < P < N$). However, if the winning position is Todd's position, print `YOU MUST BE TODD`. 

**Constraints**  
$1 \le N \le 2\cdot 10^5$    
$1 \le C_i \le 2\cdot 10^5$  

*Note:* The time limit is half of the usual time limit.

**Sample Input 1**  

    5
    1 2 2 4

**Sample Output 1**  

    2
    
**Sample Input 2**  

    2
    1 

**Sample Output 2**  

    YOU MUST BE TODD

**Explanation**  
In the first case, let $P_1$, $P_2$, $P_3$ and $P_4$ be the four persons to Todd's left, in that order. The first round begins with Todd passing the chair to $P_1$, which subsequently outs him (since the music is only 1 second long). The second round starts with $P_2$ holding the chair. The music ends when $P_4$ receives the chair, thus forcing him out of the game. The third round starts with Todd again and stops at $P_3$. The fourth round starts with Todd and ends with Todd and so $P_2$ survives.

In the second case, Todd passes the chair to the other person, the 1-second music stops and that person is out of the game. Hence, the only way to win the game is to become Todd.



Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (C++):
```cpp
#include <stdio.h>
#include <stdlib.h>

struct tree {
    int count; // how many are alive at this tree
    int l; // leftmost index
    tree *parent;
    tree *left;
    tree *right;
};

int n;
tree *root;
tree *curr;

tree *leftmost() {
    // find the leftmost alive leaf
    tree *t = root;
    while (t->left) {
        if (t->left->count) {
            // there are alive leaves on the left. go there
            t = t->left;
        } else {
            t = t->right;
        }
    }
    return t;
}

tree *create(int l, int r) {
    // create a tree on range [l,r)
    tree *t = (tree*)malloc(sizeof(tree));
    t->count = r - l;
    t->l = l;
    t->parent = 0;
    t->left = 0;
    t->right = 0;
    if (r - l > 1) {
        int m = l + r >> 1;
        t->left = create(l, m);
        t->right = create(m, r);
        t->left->parent = t;
        t->right->parent = t;
    }
    return t;
}
void init() {
    root = create(0, n);
    curr = leftmost();// start at person 0
}

int count_right(tree *t) {
    // how many alive leaves are to the right of leaf t?
    int ct = 0;
    while (t->parent) {
        tree *p = t->parent;
        if (p->left == t) {
            ct += p->right->count;
        }
        t = p;
    }
    return ct;
}
void forward(int k) {
    // assumes k < root->count
    int ct = count_right(curr);
    if (k > ct) {
        // wrap around
        k -= ct + 1;
        curr = leftmost();
    }
    if (k) {
        // go up
        while (curr->parent) {
            tree *p = curr->parent;
            if (p->left == curr) {
                if (k <= p->right->count) {
                    curr = p->right;
                    break;
                } else {
                    k -= p->right->count;
                }
            }
            curr = p;
        }
        // go down
        while (curr->left) {
            if (k <= curr->left->count) {
                curr = curr->left;
            } else {
                k -= curr->left->count;
                curr = curr->right;
            }
        }
    }
}

void eliminate() {
    // eliminate curr
    curr->count = 0;
    for (tree *p = curr->parent; p; p = p->parent) {
        p->count--;
    }
    // find next alive leaf
    forward(1);
}

int main() {
    scanf("%d",&n);
    init();
    for (int i = 0; i < n - 1; ++i) {
        int C;
        scanf("%d", &C);
        forward(C % (n-i)); // move to C'th person
        eliminate(); // eliminate
    }

    if (curr->l == 0) {
        printf("YOU MUST BE TODD\n");
    } else {
        printf("%d\n", curr->l);
    }
    return 0;
}
```