SP3486 ELIM - Elimination
Description
Elimination of contestants from a live IQ contest on a TV channel is decided in phases.
Initially at phase 0, _N_ contestants, where _N_ = 2 $ ^{n} $ , _n_ < 10 , are selected through a special online IQ contest in which a total of _M_ (_M_ > _N_) contestants participate. The contestants are identified by distinct registration numbers 1, 2,..., _M_ . The selected contestants are ranked distinctly from 1 to _N_ according to their performance in the online contest. They are qualified to participate in the live contest. In the _p_ $ ^{th} $ phase, _p_ = 1, 2,..., _n_, _K_ $ _{p} $ contestants participate in the live contest, where _K_ $ _{p} $ = 2 $ ^{n-p+1} $ . On the basis of response to questions presented during the show, _K_ $ _{p} $ /2 of _K_ $ _{p} $ contestants are ranked distinctly from 1 to _K_ $ _{p} $ /2 . These _K_ $ _{p} $ /2 contestants qualify to participate in the next phase. At the _n_ $ ^{th} $ phase there are only two contestants and the one selected at this phase is the winner of the contest. You are required to write a program that identifies the winner of the contest, given the following information:
\- INFO\_1: Registration numbers of _N_ contestants who are selected through the online IQ contest, in order of the rank in the online IQ contest, and
\- INFO\_2: A total of _N_ - 1 qualified contestants in different phases; _K_ $ _{2} $ in phase 1, _K_ $ _{3} $ in phase 2, ... , and _K_ $ _{n+1} $ in phase _n_ . Qualified contestants of different phases appear in order of phases, i.e., phase 1, phase 2, ... , phase _n_ . Further, qualified contestants in a phase, say phase _p_ , appear in the order of the rank in the phase, i.e., the rank in phase _p_ . A qualified contestant of a phase, say phase _p_ , is identified by his/her rank in the previous phase, i.e., in phase _p_ - 1 .
Input
\----------------------------------------------------
Input may contain multiple test cases. For each case there are two input lines.
The first line gives _N_ integers representing INFO\_1 while the second line gives _N_ - 1 integers representing INFO\_2. In each input line integers are separated by space. The input terminates with a line containing 0 as input.
Output
\-----------------------------------------------------
For each test case there is only one output line. The line prints the registration number of the winner of the contest.
Sample Input
\-----------------------------------------------------------
```
23 18 6 20
4 2 2
29 57 4 33 5 12 16 18
7 1 5 3 2 1 1
0
```
Sample Output
\------------------------------------------------------------
```
18
29
```
Input Format
N/A
Output Format
N/A