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

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    while(true) {
        int N;
        cin >> N;
        if(N == 0) {
            return 0;
        }
        vector<int>a(N);
        set<int>st1,st2;
        for(int i = 0; i < N; i++) {
            string b;
            cin >> b;
            if(b == "x") {
                st1.insert(i);
                continue;
            }
            a[i] = stoi(b);
            st2.insert(a[i]+2);
            st2.insert(a[i]+1);
            st2.insert(a[i]-1);
            st2.insert(a[i]-2);
        }
        if(st1.size() == N) {
            cout << "none" << endl;
        }
        else if(st2.empty()) {
            bool flag = true;
            for(int i = 0; i < N; i++) {
                if(i%2 == 0) {
                    if(i && a[i-1] <= a[i]) {
                        flag = false;
                    }
                    if(i+1 < N && a[i+1] <= a[i]) {
                        flag = false;
                    }
                }
                else {
                    if(i && a[i-1] >= a[i]) {
                        flag = false;
                    }
                    if(i+1 < N && a[i+1] >= a[i]) {
                        flag = false;
                    }
                }
            }
            cout << ((!flag)?"none":"ambiguous") << endl;
        }
        else {
            int ans = 0,idx = 0;
            for(int j:st2) {
                bool flag = true;
                for(int i = 0; i < N; i++) {
                    if(st1.count(i)) {
                        a[i] = j;
                    }
                }
                for(int i = 0; i < N; i++) {
                    if(i%2 == 0) {
                        if(i && a[i-1] <= a[i]) {
                            flag = false;
                        }
                        if(i+1 < N && a[i+1] <= a[i]) {
                            flag = false;
                        }
                    }
                    else {
                        if(i && a[i-1] >= a[i]) {
                            flag = false;
                        }
                        if(i+1 < N && a[i+1] >= a[i]) {
                            flag = false;
                        }
                    }
                }
                if(flag) {
                    ans++;
                    idx = j;
                }
            }
            if(ans == 0) {
                cout << "none" << endl;
            }
            else if(ans == 1) {
                cout << idx << endl;
            }
            else {
                cout << "ambiguous" << endl;
            }
        }
    }
}
accuracy: 1
time_ms: 720
memory_kb: 3540
final_rank: 20

code_snippet: #include <bits/stdc++.h>

using namespace std;

const int MIN_V = -1000000010, MAX_V = 1000000010;

string solve(vector<string> samples, int n)
{
    int minval = MIN_V, maxval = MAX_V;
    string status = "";

    for (int i = 0; i < n - 1; i++)
    {
        if (samples[i] == "x" && samples[i + 1] == "x")
        {
            status = "none";
            break;
        }
    }

    for (int i = 0; i < n; i++)
    {
        if (status != "")
            return status;
        if (samples[i] == "x")
        {
            if (i % 2 == 1) // i + 1 is even
            {
                if (i == 0)
                    minval = max(minval, stoi(samples[1]));
                else if (i == n - 1)
                    minval = max(minval, stoi(samples[n - 2]));
                else
                    minval = max(minval, max(stoi(samples[i - 1]), stoi(samples[i + 1])));
            }
            else // i + 1 is odd
            {
                if (i == 0)
                    maxval = min(maxval, stoi(samples[1]));
                else if (i == n - 1)
                    maxval = min(maxval, stoi(samples[n - 2]));
                else
                    maxval = min(maxval, min(stoi(samples[i - 1]), stoi(samples[i + 1])));
            }
        }
        else
        {
            if (i % 2 == 1)
            {
                // even
                bool isnone = false;

                isnone |= (i + 1 < n && samples[i + 1] != "x" && stoi(samples[i]) <= stoi(samples[i + 1]));
                isnone |= (i - 1 > 0 && samples[i - 1] != "x" && stoi(samples[i]) <= stoi(samples[i - 1]));

                if (isnone)
                    status = "none";
            }
            else
            {
                // odd
                bool isnone = false;

                isnone |= (i + 1 < n && samples[i + 1] != "x" && stoi(samples[i]) >= stoi(samples[i + 1]));
                isnone |= (i - 1 > 0 && samples[i - 1] != "x" && stoi(samples[i]) >= stoi(samples[i - 1]));

                if (isnone)
                    status = "none";
            }
        }
    }

    // cout << "minval: " << minval << " "
    //      << "maxval: " << maxval << endl;

    if (minval + 2 == maxval)
        status = to_string(minval + 1);
    else if (minval + 2 < maxval)
        status = "ambiguous";
    else
        status = "none";

    return status;
}

int main()
{
    vector<string> ans;
    while (true)
    {
        int n;
        cin >> n;
        if (n == 0)
            break;

        vector<string> samples(n);
        for (int i = 0; i < n; i++)
        {
            string sample;
            cin >> sample;
            samples[i] = sample;
        }
        string status = solve(samples, n);
        ans.push_back(status);
    }
    for (string a : ans)
        cout << a << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3364
final_rank: 17

code_snippet: #include <bits/stdc++.h>

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//using namespace boost::multiprecision;
//#include<atcoder/all>
//using namespace atcoder;

using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const ll mod = 998244353ll;
//const ll mod = 1000000007ll;
//const ll mod = 100000;


struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime modhttps://atcoder.jp/contests/abc166/submit?taskScreenName=abc166_f
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

#define rep(i, n)         for(ll i = 0; i < (ll)(n); i++)
//#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define bbrep(n)           for(int bbit=0;bbit<(1<<n);bbit++)
#define erep(i,container) for (auto &i : container)
#define itrep(i,container) for (auto i : container)
#define irep(i, n)        for(ll i = n-1; i >= (ll)0ll; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define repreprep(i,j,k,h,w,n) rep(i,h)rep(j,w)rep(k,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
//#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define kout(d) std::cout << keta(10)<< d<< std::endl;
#define vout(a) erep(qxqxqx,a)std::cout << qxqxqx << ' ';std::cout  << std::endl;
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
//#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<":"
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j);

#define RESRES(a,i,j,k) a.resize(i);rep(ii,i)a[ii].resize(j);reprep(ii,jj,i,j){a[ii][jj].resize(k);};
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define ppppri(a,b,c,d) std::cout << a<<" "<<b <<" "<< c<<' '<<d<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define SUM(a) accumulate(all(a),0ll) 
#define stirng string
#define gin(a,b) int a,b;std::cin >> a>>b;a--;b--;
#define popcount __builtin_popcount
#define permu(a) next_permutation(all(a))
#define aru(a,d) a.find(d)!=a.end()
#define nai(a,d) a.find(d)==a.end()
//#define aru p.find(mp(x,y))!=p.end()

//#define grid_input(a,type) int h,w;std::cin >> h>>w;vvector(a,type,h,w,0);reprep(i,j,h,w)std::cin >> a[i][j];

//typedef long long T;
ll ceili(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 2'000'000'000;
const ll INF64 =32233720854775807ll;
//const ll INF64 = 9223372036854775807ll;

//const ll INF64 = 243'000'000'000'000'000'0;Q


//const ll MOD = 100'000'000'7ll;
const ll MOD = 998244353ll;
//const ll MOD = 1000003ll;
const ll OD = 1000000000000007ll;
const dou pi=3.141592653589793;

long long modpow(long long a, long long n) { 
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}
//メモ
//ゲーム(Grundy数とか)の復習をする
//リスニング力をどうにかする
//個数制限付きナップサックの復習
//戻すDP
//全方位木DPとスライド最小値
//学会しゃべる練習をする
//llig 連続写真の三枚目を使ったほうがわかりやすいかも！
//自分の新規性の強調

int main(){
    ffor{
        int mi=INF,ma=-INF;
        int n;
        std::cin >> n;
        if(!n)break;
        std::vector<string> s(n);
        rep(i,n)std::cin >> s[i];
        std::vector<int> a(n);
        int cn=0;
        rep(i,n-1){
            if(s[i]=="x"&&s[i+1]=="x"){
                std::cout << "none" << std::endl;
                goto to;
            }
            
        }
        rep(i,n){
            if(s[i]!="x")a[i]=stoi(s[i]);
        }
        rep(i,n-1){
            if(s[i]!="x"&&s[i+1]!="x"){
                if(i%2==0){
                    if(a[i]>=a[i+1]){
                        std::cout << "none" << std::endl;
                        goto to;
                    }
                }
                if(i%2==1){
                    if(a[i]<=a[i+1]){
                        std::cout << "none" << std::endl;
                        goto to;
                    }
                }
            }
        }
        rep(i,n){
            if(s[i]!="x")continue;
        //    cn++;
            if(i%2==0){
                if(i!=0){
                    chmin(mi,a[i-1]-1);
                }
                if(i!=n-1){
                    chmin(mi,a[i+1]-1);
                }
            }
            else{
                if(i!=0){
                    chmax(ma,a[i-1]+1);
                }
                if(i!=n-1){
                    chmax(ma,a[i+1]+1);
                }
            }
        }
        if(mi>ma)std::cout << "ambiguous" << std::endl;
        else if(mi==ma)std::cout << mi << std::endl;
        else std::cout << "none" << std::endl;
to:     continue;        
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3284
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
    int n;
    while(cin >> n&&n!=0){
        vector<int> a(n);
        vector<bool> b(n);
        rep(i,n){
            string s;
            cin >> s;
            if(s=="x"){
                b[i] = 1;
            }else{
                a[i] = stoi(s);
            }
        }
        int up = 2000000000;
        int lo = -2000000000;
        bool flag = 0;
        rep(i,n-1){
            if(b[i]&&b[i+1]){
                flag = 1;
            }
            if(!b[i]&&!b[i+1]){
                if(i%2==0){
                    if(a[i] >= a[i+1])flag = 1;
                }else{
                    if(a[i] <= a[i+1])flag = 1;
                }
            }
        }
        if(flag){
            cout << "none\n";
            continue;
        }
        for(int i=0;i<n;i++){
            if(b[i]){
                if(i%2==0){
                    if(i!=n-1)up = min(up,a[i+1]-1);
                    if(i!=0)up = min(up,a[i-1]-1);        
                }else{
                    if(i!=n-1)lo = max(lo,a[i+1]+1);
                    if(i!=0)lo = max(lo,a[i-1]+1);
                }
            }
        }
        if(up<lo){
            cout << "none\n";
        }else if(up!=lo){
            cout << "ambiguous\n";
        }else{
            cout << up << "\n";
        }
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3176
final_rank: 7

code_snippet: #include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    vector<int> a(n), m(n, 0);
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      if (s == "x") {
        a[i] = 0, m[i] = 1;
      } else {
        a[i] = (int)atoi(s.c_str());
      }
    }

    int maxv = 1e9 + 7, minv = -1e9 - 7;
    bool flag = false;
    for (int i = 1; i < n; i++) {
      if (i % 2 == 0) {
        if (m[i] == 0 && m[i - 1] == 0) {
          if (a[i] >= a[i - 1]) flag = true;
        } else if (m[i] == 1 && m[i - 1] == 1) {
          flag = true;
        } else if (m[i] == 1) {
          maxv = min(maxv, a[i - 1] - 1);
        } else if (m[i - 1] == 1) {
          minv = max(minv, a[i] + 1);
        }
      } else {
        if (m[i] == 0 && m[i - 1] == 0) {
          if (a[i] <= a[i - 1]) flag = true;
        } else if (m[i] == 1 && m[i - 1] == 1) {
          flag = true;
        } else if (m[i] == 1) {
          minv = max(minv, a[i - 1] + 1);
        } else if (m[i - 1] == 1) {
          maxv = min(maxv, a[i] - 1);
        }
      }
    }

    if (flag) {
      cout << "none" << endl;
    } else if (maxv == minv) {
      cout << maxv << endl;
    } else if (minv < maxv) {
      cout << "ambiguous" << endl;
    } else {
      cout << "none" << endl;
    }
  }

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3200
final_rank: 8

code_snippet: #include <iostream>
#include <cstdlib>
#define llint long long
#define inf 1e18

using namespace std;

llint n;
llint a[1005];

int main(void)
{
  while(1){
    cin >> n;
    if(n == 0) break;

    string s;
    for(int i = 1; i <= n; i++){
      cin >> s;
      if(s == "x") a[i] = -inf;
      else a[i] = atoi(s.c_str());
    }

    llint lb = -inf, ub = inf;
    for(int i = 1; i <= n-1; i++){
      if(a[i] < -1e12 && a[i+1] < -1e12){
        cout << "none" << endl;
        goto end;
      }
    }


    for(int i = 1; i <= n; i++){
      if(a[i] < -1e12){
        if(i % 2){
          if(i-1 >= 1) ub = min(ub, a[i-1]-1);
          if(i+1 <= n) ub = min(ub, a[i+1]-1);
        }
        else{
          if(i-1 >= 1) lb = max(lb, a[i-1]+1);
          if(i+1 <= n) lb = max(lb, a[i+1]+1);
        }
      }
      else{
        if(i % 2){
          if((i-1 >= 1 && a[i-1] <= a[i] && a[i-1] > -1e12) || (i+1 <= n && a[i+1] <= a[i] && a[i+1] > -1e12)){
            cout << "none" << endl;
            goto end;
          }
        }
        else{
          if((i-1 >= 1 && a[i-1] >= a[i] && a[i-1] > -1e12) || (i+1 <= n && a[i+1] >= a[i] && a[i+1] > -1e12)){
            cout << "none" << endl;
            goto end;
          }
        }
      }
    }

    if(lb == ub) cout << lb << endl;
    else{
      if(lb > ub) cout << "none" << endl;
      else cout << "ambiguous" << endl;
    }
    end:;
  }

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3164
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define int long long
//typedef long long i64;

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<'\n'
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<'\n'
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<'\n'
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<'\n'
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<'\n'
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif

#define MAX_N (1000)
#define INF (1LL << 60)
#define eps 1e-9
const int MOD = (int)1e9 + 7;

int gcd(int a, int b) {
    if(b==0) return a;
    return gcd(b, a%b);
}

// 約数の列挙O(√n)
vector<int> divisor(int n){
    vector<int> res;
    for(int i=1; i*i<=n; i++){
        if(n%i==0){
            res.push_back(i);
            // n の約数が i の時、n/i も n の約数になる
            if(i!=n/i) res.push_back(n/i);
        }
    }
    return res;
}

map<int, int> prime_factor(int n){
    map<int, int> res;
    for(int i=2; i*i<=n; i++){
        while(n%i==0){
            ++res[i];
            n /= i;
        }
    }
    if(n!=1) res[n] = 1;
    return res;
}

signed main(){
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);

    while(1){
        int n;
        cin >> n;
        if(n==0)break;
        vector<string> a(n);
        for(int i=0; i<n; i++) cin >> a[i];

        int mn = -INF;
        int mx = INF;

        bool f=true;
        for(int i=0; i<n; i++){
            if(a[i]!="x") {
                int v = atoi(a[i].c_str());
                if(i%2==0){
                    if(i>0&&a[i-1]!="x"){
                        int left = atoi(a[i-1].c_str());
                        if(v>=left) f=false;
                    }
                    if(i<n-1&&a[i+1]!="x"){
                        int right = atoi(a[i+1].c_str());
                        if(v>=right) f=false;
                    }
                } else {
                    if(i>0&&a[i-1]!="x"){
                        int left = atoi(a[i-1].c_str());
                        if(v<=left) f=false;
                    }
                    if(i<n-1&&a[i+1]!="x"){
                        int right = atoi(a[i+1].c_str());
                        if(v<=right) f=false;
                    }
                }
            }
            else if(i%2==0){
                if(i>0) {
                    if(a[i-1]=="x"){ f=false; break; }
                    int left = atoi(a[i-1].c_str());
                    mx = min(mx, left-1);
                }
                if(i<n-1) {
                    if(a[i+1]=="x"){ f=false; break; }
                    int right = atoi(a[i+1].c_str());
                    mx = min(mx, right-1);
                }
            } else {
                if(i>0) {
                    if(a[i-1]=="x"){ f=false; break; }
                    int left = atoi(a[i-1].c_str());
                    mn = max(mn, left+1);
                }
                if(i<n-1) {
                    if(a[i+1]=="x"){ f=false; break; }
                    int right = atoi(a[i+1].c_str());
                    mn = max(mn, right+1);
                }
            }
        }
        if(!f) {
            cout << "none" << endl;
            continue;
        }
        debug(mn,mx);
        if(mx-mn<0){
            cout << "none" << endl;
        }
        else if(mx-mn==0){
            cout << mx << endl;
        }
        else {
            cout << "ambiguous" << endl;
        }
    }
}

/*

概要：
壊れてる信号を求める。
奇数番目は隣より小さく、偶数番目は隣より大きい
可能な数が複数あるなら"ambiguous", ないなら"none"

考察：
各xで何より大きいか、何より小さいかを決めていくことができる。
それによって、取り得る範囲を狭めていき、最後に判定する
隣が x の場合は、同じ数は駄目なので"none"


*/
accuracy: 1
time_ms: 10
memory_kb: 3304
final_rank: 15

code_snippet: #include <iostream>
#include <string>
using namespace std;

const int x = 1000000007;

int main()
{
    while(true){
        int n;
        cin >> n;
        if(n == 0) break;
        string s[1002];
        int a[1002]{0};
        for(int i = 0; i < n; i++){
            cin >> s[i];
            if(s[i][0] == 'x'){
                a[i] = x;
                continue;
            }
            int j = 0;
            int d = 1;
            if(s[i][0] == '-'){
                d *= -1;
                j++;
            }
            for(; j < (int)s[i].size(); j++){
                a[i] = a[i] * 10 + d * (s[i][j] - '0');
            }
        }
        int l = -x, r = x;
        for(int i = 0; i < n - 1; i++){
            if(a[i] == x){
                if(a[i + 1] != x){
                    if(i % 2 == 1) l = max(l, a[i + 1] + 1);
                    else r = min(r, a[i + 1] - 1);
                }
                else{
                    l = x;
                    r = -x;
                }
            }
            else{
                if(a[i + 1] != x){
                    if((i % 2 == 1 && a[i] <= a[i + 1]) || (i % 2 == 0 && a[i] >= a[i + 1])){
                        l = x;
                        r = -x;
                    }
                }
                else{
                    if(i % 2) r = min(r, a[i] - 1);
                    else l = max(l, a[i] + 1);
                }
            }
        }
        if(l < r){
            cout << "ambiguous" << endl;
        }
        else if(l == r){
            cout << l << endl;
        }
        else{
            cout << "none" << endl;
        }
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3284
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
Int ub = 1e10;
Int lb = -1e10;
Int X  = 1e18;
vector<string>input(int N) {
    char c; scanf("%c",&c);
    string str = "";
    vector<string>res;
    getline(cin,str);
    string temp = "";
    for(auto c : str){
        if(c == ' ') {
            res.push_back(temp); temp.clear();
        } else {
            temp.push_back(c);
        }
    }
    res.push_back(temp);
    return res;
}
inline bool solve(){
    int N; cin >> N;
    if(N == 0) return false;
    vector<string> inputs = input(N);
    vector<Int>vec;
    Int lowerBound = lb + lb;
    Int upperBound = ub + ub;
    for(int i = 0; i < inputs.size(); ++i){
        if(inputs[i] == "x"){
            vec.push_back(X);
        } else {
             vec.push_back(stoll(inputs[i]));
        }
    }
    bool f = true;
    for(int i = 0; i < vec.size(); ++i){
        if(vec[i] != X) continue;
        int id = (i + 1);
        if( id % 2 == 1){
            // odd is smaller than neighbors
            if(i + 1 < N && vec[i + 1] == X) f = false;
            if(i - 1>= 0 && vec[i - 1] == X) f = false;
            if(i + 1 < N)
                upperBound = min(upperBound,vec[i + 1]);
            if(i - 1 >= 0)
                upperBound = min(upperBound,vec[i - 1]);
        } else  {
            // even is larger
            if(i + 1 < N && vec[i + 1] == X) f = false;
            if(i - 1>= 0 && vec[i - 1] == X) f = false;
            if(i + 1 < N)
                lowerBound = max(lowerBound,vec[i + 1]);
            if(i - 1 >= 0)
                lowerBound = max(lowerBound,vec[i - 1]);
        }
    }
    if(lowerBound >= upperBound) f = false;
    Int crt =  lowerBound + 1;
    bool remu = false;
    if(upperBound - lowerBound == 2) remu = true;
    for(auto& e : vec){
        if(e == X) e = crt;
    }
    for(int i = 0; i < vec.size(); ++i){
        int id = (i + 1);
        auto crt = vec[i];
        if(id % 2 == 1){
            Int l = ( i + 1 < vec.size() ? vec[i + 1] : ub + ub);
            Int r = ( i - 1 >= 0 ? vec[i - 1] : ub + ub);
            if(!(l > crt && r >crt)) f = false;
        } else {
            Int l = ( i + 1 < vec.size() ? vec[i + 1] : lb + lb);
            Int r = ( i - 1 >= 0 ? vec[i - 1] : lb + lb);
            if(!(l < crt && r < crt)) f = false;
        }
    }
    cout << (remu && f ? to_string(crt) : f ? "ambiguous" : "none") << endl;
    return true;
}
signed main(){ while(solve()); }
accuracy: 1
time_ms: 10
memory_kb: 3388
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000005

int main(){
	
	while(true){
		int N;
		cin>>N;
		if(N==0)break;
		
		vector<int> a(N);
		for(int i=0;i<N;i++){
			string s;
			cin>>s;
			
			if(s=="x")a[i] = Inf;
			else sscanf(s.c_str(),"%d",&a[i]);
		}
		
		bool f = false;
		for(int i=1;i<N;i++){
			if(a[i]==Inf&&a[i-1]==Inf){
				f=true;
				break;
			}
		}
		
		if(f){
			cout<<"none"<<endl;
			continue;
		}
		

		
		int l = -Inf,r = Inf;
		for(int i=0;i<N;i++){
			if(a[i]==Inf){
				if(i%2==0){
					int x,y;
					if(i==0)x = Inf;
					else x = a[i-1];
					if(i+1==N)y = Inf;
					else y=a[i+1];
					r = min(r,min(x,y)-1);
				}
				else{
					int x,y;
					if(i==0)x = -Inf;
					else x = a[i-1];
					if(i+1==N)y = -Inf;
					else y=a[i+1];
					l = max(max(x,y)+1,l);
				}
			}
		}
		
		if(l>r)cout<<"none"<<endl;
		else{
			for(int i=0;i<N;i++){
				if(a[i]==Inf)a[i] = l;
			}
			f=false;
			for(int i=0;i<N;i++){
				if(i%2==0){
					int x,y;
					if(i==0)x = Inf;
					else x = a[i-1];
					if(i+1==N)y = Inf;
					else y=a[i+1];
					if(a[i]>min(x,y))f=true;
				}
				else{
					int x,y;
					if(i==0)x = -Inf;
					else x = a[i-1];
					if(i+1==N)y = -Inf;
					else y=a[i+1];
					if(a[i]<max(x,y))f=true;
				}
			}
			
			if(f)cout<<"none"<<endl;
			else if(l==r)cout<<l<<endl;
			else cout<<"ambiguous"<<endl;
			
		}		
	}
		
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3212
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int N;
    cin >> N;
    if (N == 0){
      break;
    }
    vector<string> a(N);
    for (int i = 0; i < N; i++){
      cin >> a[i];
    }
    bool ok = true;
    for (int i = 0; i < N - 1; i++){
      if (i % 2 == 0 && a[i] != "x" && a[i + 1] != "x"){
        if (stoi(a[i]) >= stoi(a[i + 1])){
          ok = false;
        }
      }
      if (i % 2 == 1 && a[i] != "x" && a[i + 1] != "x"){
        if (stoi(a[i]) <= stoi(a[i + 1])){
          ok = false;
        }
      }
      if (a[i] == "x" && a[i + 1] == "x"){
        ok = false;
      }
    }
    if (!ok){
      cout << "none" << endl;
    } else {
      int mn = -1100000000;
      int mx = 1100000000;
      for (int i = 0; i < N - 1; i++){
        if (i % 2 == 0){
          if (a[i] == "x" && a[i + 1] != "x"){
            mx = min(mx, stoi(a[i + 1]) - 1);
          }
          if (a[i] != "x" && a[i + 1] == "x"){
            mn = max(mn, stoi(a[i]) + 1);
          }
        }
        if (i % 2 == 1){
          if (a[i] == "x" && a[i + 1] != "x"){
            mn = max(mn, stoi(a[i + 1]) + 1);
          }
          if (a[i] != "x" && a[i + 1] == "x"){
            mx = min(mx, stoi(a[i]) - 1);
          }
        }
      }
      if (mx < mn){
        cout << "none" << endl;
      } else if (mx == mn){
        cout << mx << endl;
      } else {
        cout << "ambiguous" << endl;
      }
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3216
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    for (;;) {
        int n; cin >> n;
        int ub = 2000000000, lb = -2000000000;
        if (!n) break;
        vector<string> v(n + 1);
        rep(i, 1, n + 1) cin >> v[i];
        rep(i, 1, n) if (v[i] == v[i + 1] && v[i] == "x") ub = lb - 1;
        rep(i, 1, n + 1) if (v[i] == "x") {
            if (i % 2 == 1) {
                if (i > 1 && v[i - 1] != "x") ub = min(ub, stoi(v[i - 1]) - 1);
                if (i < n && v[i + 1] != "x") ub = min(ub, stoi(v[i + 1]) - 1);
            } else {
                if (i > 1 && v[i - 1] != "x") lb = max(lb, stoi(v[i - 1]) + 1);
                if (i < n && v[i + 1] != "x") lb = max(lb, stoi(v[i + 1]) + 1);
            }
        } else {
            if (i % 2 == 1) {
                if (i > 1 && v[i - 1] != "x" && stoi(v[i]) >= stoi(v[i - 1])) ub = lb - 1;
                if (i < n && v[i + 1] != "x" && stoi(v[i]) >= stoi(v[i + 1])) ub = lb - 1;
            } else {
                if (i > 1 && v[i - 1] != "x" && stoi(v[i]) <= stoi(v[i - 1])) ub = lb - 1;
                if (i < n && v[i + 1] != "x" && stoi(v[i]) <= stoi(v[i + 1])) ub = lb - 1;
            }
        }
        // cout << lb << " " << ub << endl;
        if (ub < lb) {
            cout << "none" << endl;
        } else if (ub == lb) {
            cout << ub << endl;
        } else {
            cout << "ambiguous" << endl;
        }
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3084
final_rank: 3

code_snippet: #include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	int kkt = 89;
	while (kkt) {
		int n; scanf("%d", &n); if (n == 0) break;
		vector<string> vs(n); for (int i = 0; i < n; i++) cin >> vs[i];
		ll mx = INF;
		ll mn = -INF;
		int state = 0;
		for (int i = 0; i < n; i++) {
			if (vs[i] == "x") {
				if (i == 0) {
					if (vs[i + 1] == "x") {
						state = -1;
						break;
					}
					if(i % 2 == 0) chmin(mx, stoll(vs[i + 1]) - 1);
					else chmax(mn, stoll(vs[i + 1]) + 1);
				}
				else if (i == n - 1) {
					if (vs[i - 1] == "x") {
						state = -1;
						break;
					}
					if (i % 2 == 0) chmin(mx, stoll(vs[i - 1]) - 1);
					else chmax(mn, stoll(vs[i - 1]) + 1);
				}
				else {
					if (vs[i + 1] == "x") {
						state = -1;
						break;
					}
					if (i % 2 == 0) chmin(mx, stoll(vs[i + 1]) - 1);
					else chmax(mn, stoll(vs[i + 1]) + 1);

					if (vs[i - 1] == "x") {
						state = -1;
						break;
					}
					if (i % 2 == 0) chmin(mx, stoll(vs[i - 1]) - 1);
					else chmax(mn, stoll(vs[i - 1]) + 1);
				}
			}
			else {
				if (i == 0) {
					if (vs[i + 1] != "x") {
						if (i % 2 == 0) {
							if (stoll(vs[i]) >= stoll(vs[i + 1])) {
								state = -1;
								break;
							}
						}
						else {
							if (stoll(vs[i]) <= stoll(vs[i + 1])) {
								state = -1;
								break;
							}
						}
					}
				}
				else if (i == n - 1) {
					if (vs[i - 1] != "x") {
						if (i % 2 == 0) {
							if (stoll(vs[i]) >= stoll(vs[i - 1])) {
								state = -1;
								break;
							}
						}
						else {
							if (stoll(vs[i]) <= stoll(vs[i - 1])) {
								state = -1;
								break;
							}
						}
					}
				}
				else {
					if (vs[i + 1] != "x") {
						if (i % 2 == 0) {
							if (stoll(vs[i]) >= stoll(vs[i + 1])) {
								state = -1;
								break;
							}
						}
						else {
							if (stoll(vs[i]) <= stoll(vs[i + 1])) {
								state = -1;
								break;
							}
						}
					}
					if (vs[i - 1] != "x") {
						if (i % 2 == 0) {
							if (stoll(vs[i]) >= stoll(vs[i - 1])) {
								state = -1;
								break;
							}
						}
						else {
							if (stoll(vs[i]) <= stoll(vs[i - 1])) {
								state = -1;
								break;
							}
						}
					}

				}
			}
		}
		if (state == -1 or mn > mx) puts("none");
		else if (mx == mn) printf("%lld\n", mx);
		else puts("ambiguous");
	}
	return 0;

}
accuracy: 1
time_ms: 10
memory_kb: 3384
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long int;
constexpr int INF = 1 << 30;

int solve(){
    int n;
    cin >> n;
    if(n==0) return 1;
    vector<ll> a(n);
    vector<bool> broken(n);
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        if(s=="x") broken[i] = true;
        else a[i] = stol(s);
    }
    ll low = -INF, up = INF;
    bool valid = true;
    for(int i=0;i<n-1;i++){
        if(broken[i]){
            if(i%2){
                if(!broken[i+1]) low = max(low, a[i+1]+1);
                else valid = false;
            }else{
                if(!broken[i+1]) up = min(up, a[i+1]);
                else valid = false;
            }
        }else{
            if(!broken[i+1]){
                valid &= (i%2 ? a[i]>a[i+1] : a[i]<a[i+1]);
            }else{
                if(i%2){
                    up = min(up, a[i]);
                }else{
                    low = max(low, a[i]+1);
                }
            }
        }
    }
    if(!valid || low >= up){
        cout << "none" << endl;
    }else if(up-low >= 2){
        cout << "ambiguous" << endl;
    }else{
        cout << low << endl;
    }
    return 0;
}

int main(){
    while(solve()==0);
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3012
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int n;
    while(scanf("%d", &n) && n){
        string a[n];
        rep(i, n) cin >> a[i];
        int low = -mod, high =mod;
        bool flag = true;
        rep(i, n) {
            if (a[i] == "x") {
                if (i % 2 == 0) {
                    if (i - 1 >= 0) {
                        if (a[i - 1] == "x") {
                            flag = false;
                            break;
                        } else chmin(high, stoi(a[i - 1]));
                    }
                    if (i + 1 < n) {
                        if (a[i + 1] == "x") {
                            flag = false;
                            break;
                        } else chmin(high, stoi(a[i + 1]));
                    }
                } else {
                    if (i - 1 >= 0) {
                        if (a[i - 1] == "x") {
                            flag = false;
                            break;
                        } else chmax(low, stoi(a[i - 1]));
                    }
                    if (i + 1 < n) {
                        if (a[i + 1] == "x") {
                            flag = false;
                            break;
                        } else chmax(low, stoi(a[i + 1]));
                    }
                }
            }
            else{
                if(i%2 == 0 && i+1 < n && a[i+1] != "x"){
                    if(stoi(a[i]) >= stoi(a[i+1])){
                        flag = false;
                        break;
                    }
                }
                else if(i%2 == 1 && i+1 < n && a[i+1] != "x"){
                    if(stoi(a[i]) <= stoi(a[i+1])){
                        flag = false;
                        break;
                    }
                }
            }
        }
        if(!flag || high-low <= 1) puts("none");
        else if(high-low > 2) puts("ambiguous");
        else printf("%d\n", low+1);
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3336
final_rank: 16

code_snippet: //#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  return a < b ? b - a : a - b;
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b)
    a = b;
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <string>
#include <utility>

namespace n91 {

void solve(const usize n) {
  std::vector<std::string> a(n);
  for (auto &e : a) {
    std::cin >> e;
  }
  i32 lb = -1000000010, ub = 1000000010;
  for (usize i = 1; i < n; ++i) {
    const auto &l = a[i - i % 2];
    const auto &r = a[i - (i + 1) % 2];
    if (l == "x") {
      if (r == "x") {
        std::cout << "none" << std::endl;
        return;
      } else {
        chmin<i32>(ub, std::stoi(r) - 1);
      }
    } else {
      if (r == "x") {
        chmax<i32>(lb, std::stoi(l) + 1);
      } else {
        if (std::stoi(l) >= std::stoi(r)) {
          std::cout << "none" << std::endl;
          return;
        }
      }
    }
  }
  if (lb > ub) {
    std::cout << "none" << std::endl;
  } else if (lb == ub) {
    std::cout << lb << std::endl;
  } else {
    std::cout << "ambiguous" << std::endl;
  }
}

void main_() {
  while (true) {
    const usize n{scan<usize>()};
    if (n == 0) {
      return;
    }
    solve(n);
  }
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3168
final_rank: 6

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
	int n;
	while (cin >> n, n) {
		long long l = -1e10, r = 1e10;
		vector<string> a(n);
		for (auto& e : a) cin >> e;
		string prev;
		for (int i = 0; i < n; ++i) {
			if (a[i] == "x") {
				if (prev == "x") {
					l = 1e18;
					break;
				}
				if (i & 1) {
					if (i - 1 >= 0 && a[i - 1] != "x") l = max(l, stoll(a[i - 1]) + 1);
					if (i + 1 < n && a[i + 1] != "x") l = max(l, stoll(a[i + 1]) + 1);
				} else {
					if (i - 1 >= 0 && a[i - 1] != "x") r = min(r, stoll(a[i - 1]) - 1);
					if (i + 1 < n && a[i + 1] != "x") r = min(r, stoll(a[i + 1]) - 1);
				}
			} else {
				if (i & 1) {
					if (i - 1 >= 0 && a[i - 1] != "x") {
						if (stoi(a[i - 1]) >= stoi(a[i])) {
							l = 1e18;
							break;
						}
					}
				} else {
					if (i - 1 >= 0 && a[i - 1] != "x") {
						if (stoi(a[i - 1]) <= stoi(a[i])) {
							l = 1e18;
							break;
						}
					}
				}
			}
			prev = a[i];
		}
		if (l == r) cout << l << endl;
		else if (l < r) cout << "ambiguous" << endl;
		else cout << "none" << endl;
	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3056
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
typedef pair<int,int> P;
typedef pair<int,P> PP; 
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1e9+7;

signed main(){
  int n;
  while(cin>>n,n){
    [&](){
	 int INF=1LL<<60;
	 vector<int> a;
	 for(int i=0;i<n;i++){
	   string s;
	   cin>>s;
	   if(s=="x")a.pb(INF);
	   else a.pb(stoi(s));
	 }
	 int lower=-INF,upper=INF;
	 for(int i=0;i<n;i++){
	   if(i>0&&a[i]==INF&&a[i-1]!=INF){
		if(i%2){
		  chmax(lower,a[i-1]+1);
		}else{
		  chmin(upper,a[i-1]-1);
		}
	   }
	   if(i<n-1&&a[i]==INF&&a[i+1]!=INF){
		if(i%2){
		  chmax(lower,a[i+1]+1);
		}else{
		  chmin(upper,a[i+1]-1);
		}
	   }
	   if(i&&a[i]!=INF&&a[i-1]!=INF){
		if(i%2&&a[i-1]>=a[i]){
		  cout<<"none"<<endl;
		  return;
		}
		if(i%2==0&&a[i-1]<=a[i]){
		  cout<<"none"<<endl;
		  return;
		}
	   }
	   if(i&&a[i-1]==INF&&a[i]==INF){
		cout<<"none"<<endl;
		return;
	   }
	 }
	 //	 dmp(lower),dmp(upper);
	 if(lower==upper)cout<<lower<<endl;
	 else if(lower<upper)cout<<"ambiguous"<<endl;
	 else cout<<"none"<<endl;
    }();
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3084
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  int64 n;
  while (cin >> n && n) {
    vector<string> vv(n), v;
    REP(i, n) cin >> vv[i]; 
    v = vv;
    int64 l = -INF_LL, r = INF_LL;
    REP(i, n) {
      if (i < n-1 && v[i] == v[i+1] && v[i] == "x") { r = -INF_LL-1; break; }
      if (i < n-1 && v[i] != "x" && v[i+1] != "x") {
        if ((i % 2 == 0 && stoi(v[i]) >= stoi(v[i+1])) || (i%2 && stoi(v[i]) <= stoi(v[i+1]))) {
          r = -INF_LL-1;
          break;
        }
      }
      if (i % 2 == 0) {
        if (v[i] == "x") {
          if (i < n-1)
            chmin(r, stoi(v[i+1])-1);
          if (i > 0)
            chmin(r, stoi(v[i-1])-1);
        }
      } else {
        if (v[i] == "x") {
          if (i < n-1)
            chmax(l, stoi(v[i+1])+1);
          if (i > 0)
            chmax(l, stoi(v[i-1])+1);
        }
      }
    }
    if (l == r) {
      cout << l << endl;
    } else if (l < r) {
      cout << "ambiguous" << endl;
    } else {
      cout << "none" << endl;
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3248
final_rank: 12

code_snippet: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    while(cin >> n, n){
        int a = -INF<int>, b = INF<int>;
        vector<int> v(n);

        for (int i = 0; i < n; ++i) {
            string s;
            cin >> s;
            if(s == "x"){
                v[i] = INF<int>;
            }else {
                v[i] = stoi(s);
            }
        }
        for (int i = 0; i < n-1; ++i) {
            if(i%2 == 0){
                if(v[i] == INF<int> && v[i+1] != INF<int>){
                    b = min(b, v[i+1]-1);
                }else if(v[i] != INF<int> && v[i+1] == INF<int>){
                    a = max(a, v[i]+1);
                }else if(v[i] != INF<int> && v[i+1] != INF<int>){
                    if(v[i] >= v[i+1]) a = 1, b = 0;
                } else {
                    a = 1, b = 0;
                }
            }else {
                if(v[i] == INF<int> && v[i+1] != INF<int>){
                    a = max(a, v[i+1]+1);
                }else if(v[i] != INF<int> && v[i+1] == INF<int>){
                    b = min(b, v[i]-1);
                }else if(v[i] != INF<int> && v[i+1] != INF<int>){
                    if(v[i] <= v[i+1]) a = 1, b = 0;
                } else {
                    a = 1, b = 0;
                }
            }
        }
        if(a == b){
            cout << a << "\n";
        }else if(a < b){
            puts("ambiguous");
        }else {
            puts("none");
        }
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3208
final_rank: 9