Problem:
Problem Statement Nathan O. Davis is a student at the department of integrated systems. Today's agenda in the class is audio signal processing.
Nathan was given a lot of homework out.
One of the homework was to write a program to process an audio signal.
He copied the given audio signal to his USB memory and brought it back to his home. When he started his homework, he unfortunately dropped the USB memory to the floor.
He checked the contents of the USB memory and found that the audio signal data got broken. There are several characteristics in the audio signal that he copied. The audio signal is a sequence of $N$ samples. Each sample in the audio signal is numbered from $1$ to $N$ and represented as an integer value. Each value of the odd-numbered sample(s) is strictly smaller than the value(s) of its neighboring sample(s). Each value of the even-numbered sample(s) is strictly larger than the value(s) of its neighboring sample(s). He got into a panic and asked you for a help.
You tried to recover the audio signal from his USB memory but some samples of the audio signal are broken and could not be recovered.
Fortunately, you found from the metadata that all the broken samples have the same integer value. Your task is to write a program,
which takes the broken audio signal extracted from his USB memory as its input, 
to detect whether the audio signal can be recovered uniquely. Input The input consists of multiple datasets.
The form of each dataset is described below. $N$ $a_{1}$ $a_{2}$ ... $a_{N}$ The first line of each dataset consists of an integer, $N (2 \le N \le 1{,}000)$.
$N$ denotes the number of samples in the given audio signal.
The second line of each dataset consists of $N$ values separated by spaces.
The $i$-th value, $a_{i}$, is either a character x or an integer between $-10^9$ and $10^9$, inclusive.
It represents the $i$-th sample of the broken audio signal.
If $a_{i}$ is a character x , it denotes that $i$-th sample in the audio signal is broken.
Otherwise it denotes the value of the $i$-th sample. The end of input is indicated by a single $0$.
This is not included in the datasets. You may assume that the number of the datasets does not exceed $100$. Output For each dataset, output the value of the broken samples in one line if the original audio signal can be recovered uniquely.
If there are multiple possible values, output ambiguous .
If there are no possible values, output none . Sample 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 Output for the Sample Input 3
none
ambiguous
none
ambiguous
none

Solution (Python):
MAX = 10**9 * 2
while 1:
	N = int(raw_input())
	if N == 0:
		break
	signal = raw_input().split(" ")
	xst = MAX + 1
	xlt = - xst
	for i in range(N):
		if signal[i] == "x":
			if i < N-1 and signal[i+1] == "x" :
				print "none"
				break
			if (i + 1) % 2 != 0:
				left = MAX + 1 if i <= 0 else int(signal[i-1]) 
				right = MAX + 1 if i >= N-1 else int(signal[i+1])
				xst = min(xst, left, right)
			else :
				left = - (MAX + 1) if i <= 0 else int(signal[i-1]) 
				right = - (MAX + 1) if i >= N-1 else int(signal[i+1])
				xlt = max(xlt, left, right)
		elif i < N-1 and signal[i+1] != "x" :
				if ( (i + 1) % 2 != 0 and int(signal[i]) >= int(signal[i+1]) 
				  or (i + 1) % 2 == 0 and int(signal[i]) <= int(signal[i+1])) :
					print "none"
					break
	else :
		x = "none"
		tmpx = xlt + 1
		while tmpx < xst:
			if x != "none" :
				print "ambiguous"
				break
			x = tmpx
			tmpx += 1
		else :
			print x

Solution (Python):
while 1:
    N = int(raw_input())
    if N == 0: break
    a = raw_input().split()
    mn,mx = -10**10,10**10
    for i in range(1,N):
        if a[i-1] == a[i] == "x":
            print "none"
            break
        elif a[i-1] == "x":
            if (i+1)%2 == 0: mx = min(mx,int(a[i])-1)
            else           : mn = max(mn,int(a[i])+1)
        elif a[i] == "x":
            if (i+1)%2 == 0: mn = max(mn,int(a[i-1])+1)
            else           : mx = min(mx,int(a[i-1])-1)
        else:
            if   (i+1)%2 == 0 and int(a[i]) <= int(a[i-1]):
                print "none"
                break
            elif (i+1)%2 == 1 and int(a[i]) >= int(a[i-1]): 
                print "none"
                break
    else:
        if "x" not in a: 
            print "ambiguous"
        else:
            print mx if mn == mx else "ambiguous" if mn < mx else "none"

Solution (Python):
INF = float('inf')

def judge(src):
    x_max = INF
    x_min = -INF
    for i,(s1,s2) in enumerate(zip(src,src[1:])):
        if s1 == s2:
            return 'none'
        if i%2:
            s1,s2 = s2,s1
        if s1 != 'x' and s2 != 'x':
            if s1 < s2:
                return 'none'
            else:
                continue
        if s1 == 'x':
            if x_max <= s2:
                return 'none'
            x_min = max(x_min, s2 + 1)
        elif s2 == 'x':
            if s1 <= x_min:
                return 'none'
            x_max = min(x_max, s1 - 1)
        if x_max < x_min:
            return 'none'
    return x_max if x_max == x_min else 'ambiguous'

while True:
    N = int(input())
    if N == 0: break
    src = [INF] + list(map(lambda x:x if x=='x' else int(x), input().split())) + [INF if N%2 else -INF]
    print(judge(src))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []
    while True:
        n = I()
        if n == 0:
            break
        a = LS()
        r = None
        for i in range(n):
            if a[i] == 'x':
                if i > 0 and a[i-1] == 'x':
                    r = 'none'
                    break
            else:
                a[i] = int(a[i])
                if i > 0 and a[i-1] != 'x':
                    if i % 2 == 0:
                        if a[i-1] <= a[i]:
                            r = 'none'
                            break
                    elif a[i-1] >= a[i]:
                        r = 'none'
                        break
        if r:
            rr.append(r)
            continue
        ma = -inf
        mi = inf
        for i in range(n):
            if a[i] != 'x':
                continue
            if i % 2 == 0:
                if i > 0:
                    mi = min(mi, a[i-1]-1)
                if i < n-1:
                    mi = min(mi, a[i+1]-1)
            else:
                ma = max(ma, a[i-1]+1)
                if i < n-1:
                    ma = max(ma, a[i+1]+1)
        if ma == mi:
            rr.append(ma)
        elif ma == -1 or mi == inf:
            rr.append('ambiguous')
        elif ma > mi:
            rr.append('none')
        else:
            rr.append('ambiguous')



    return '\n'.join(map(str, rr))


print(main())