This page is still under construction.

Parts of this page are still being built. What you see may change.

Broken Audio Signal

Time limit8sMemory limit512 MB

Summary
The program finds the one integer that fills every x and makes odd positions valleys and even positions peaks, or reports ambiguous or none.
Level

Medium4 of 10

Topics
Intervals, Implementation
Solved
No attempts yet

Problem

Nathan O. Davis studies in the department of integrated systems.

Today's topic in class is audio signal processing. One of the assignments is to write a program that processes a given audio signal. Nathan copied the signal data he received in class to his USB memory and took it home.

Just as he was about to start the assignment, he dropped the USB memory on the floor. He checked its contents and found that the audio signal data was broken.

The audio signal he copied has the following properties.

  • The signal is a sequence of NN samples.
  • The samples are numbered from 11 to NN, and each value is an integer.
  • The value of an odd numbered sample is always smaller than the value of each neighbouring sample.
  • The value of an even numbered sample is always larger than the value of each neighbouring sample.

Nathan panicked and asked you for help. You recovered the signal from the USB memory, but the values of some samples could not be restored. The metadata tells you that all broken samples held the same integer value.

Write a program that reads the broken audio signal taken from the USB memory and decides whether the original signal can be recovered uniquely.

Input

The input consists of several datasets. Each dataset has the following form.

N
a1 a2 ... aN

The first line of a dataset holds the number of samples NN (2≤N≤10002 \le N \le 1000). The second line holds the NN samples of the broken signal, separated by spaces. The ii-th value aia_i is either the character x or an integer between −109-10^9 and 10910^9, inclusive. An x means that the ii-th sample is broken, and an integer is the value of that sample.

The end of the input is a line holding a single 00. That line is not part of the datasets. The number of datasets is at most 100100.

Output

For each dataset, print the answer on one line. If the original signal can be recovered uniquely, print the value of the broken samples. If two or more values are possible, print ambiguous. If no value is possible, print none.

The value of the broken samples is any integer, and it is not restricted to the range −109-10^9 to 10910^9 that the given values use. For a dataset with no broken sample, print ambiguous when the signal satisfies every property listed above, because then any value is possible, and print none when it breaks one of them.

Examples5

  1. Example 1

    Input
    5
    1 x 2 4 x
    2
    x x
    2
    1 2
    2
    2 1
    2
    1000000000 x
    4
    x 2 1 x
    0
    
    Expected output
    3
    none
    ambiguous
    none
    ambiguous
    none
    
  2. Example 2

    Input
    5
    -8 x -7 -5 x
    0
    
    Expected output
    -6
    
  3. Example 3

    Input
    6
    0 x 5 7 x 8
    6
    0 x 5 6 x 8
    0
    
    Expected output
    6
    none
    
  4. Example 4

    Input
    5
    999999997 x 999999998 1000000000 x
    0
    
    Expected output
    999999999
    
  5. Example 5

    Input
    2
    x -1000000000
    2
    -1000000000 x
    3
    -1000000000 1000000000 -1000000000
    0
    
    Expected output
    ambiguous
    ambiguous
    ambiguous