Problem:
Problem Statement
Let
b_i(x)
be the
i
-th least significant bit of
x
, i.e. the
i
-th least significant digit of
x
in base 2 (
i \geq 1
).
For example, since
6 = (110)_2
,
b_1(6) = 0
,
b_2(6) = 1
,
b_3(6) = 1
,
b_4(6) = 0
,
b_5(6) = 0
, and so on.
Let
A
and
B
be integers that satisfy
1 \leq A \leq B \leq 10^{18}
,
and
k_i
be the number of integers
x
such that
A \leq x \leq B
and
b_i(x) = 1
.
Your task is to write a program that determines
A
and
B
for a given
\{k_i\}
.
Input
The input consists of multiple datasets.
The number of datasets is no more than 100,000.
Each dataset has the following format:
n
k_1
k_2
...
k_n
The first line of each dataset contains an integer
n
(
1 \leq n \leq 64
).
Then
n
lines follow, each of which contains
k_i
(
0 \leq k_i \leq 2^{63} - 1
).
For all
i > n
,
k_i = 0
.
The input is terminated by
n = 0
.
Your program must not produce output for it.
Output
For each dataset, print one line.
If
A
and
B
can be uniquely determined, output
A
and
B
. Separate the numbers by a single space.
If there exists more than one possible pair of
A
and
B
, output
Many
(without quotes).
Otherwise, i.e. if there exists no possible pair, output
None
(without quotes).
Sample Input
3
2
2
1
49
95351238128934
95351238128934
95351238128932
95351238128936
95351238128936
95351238128936
95351238128960
95351238128900
95351238128896
95351238129096
95351238128772
95351238129096
95351238129096
95351238126156
95351238131712
95351238131712
95351238149576
95351238093388
95351238084040
95351237962316
95351238295552
95351237911684
95351237911684
95351235149824
95351233717380
95351249496652
95351249496652
95351226761216
95351226761216
95351082722436
95351082722436
95352054803020
95352156464260
95348273971200
95348273971200
95354202286668
95356451431556
95356451431556
95346024826312
95356451431556
95356451431556
94557999988736
94256939803780
94256939803780
102741546035788
87649443431880
87649443431880
140737488355328
32684288648324
64
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
11
0
0
1
1
1
0
1
1
1
1
1
63
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
4
1
1
1
1
0
Output for the Sample Input
1 4
123456789101112 314159265358979
None
2012 2012
None
Many

Submitted solutions:

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;

const unsigned long long inf=(unsigned long long)1e18;

int n,num;
unsigned long long f[100],l,r,x,p,s[100],t[100];

void get(unsigned long long b,unsigned long long s[]){
    static int i;
    //printf("%llu:",b);
    for(i=0;i<n;i++){
        if(i==63){
            s[i]=b-((unsigned long long)1<<63)+1;
            continue;
        }
        s[i]=(b/((unsigned long long)1<<(i+1)))*((unsigned long long)1<<i);
        if(b%((unsigned long long)1<<(i+1))>=((unsigned long long)1<<i))
            s[i]+=b%((unsigned long long)1<<(i+1))-((unsigned long long)1<<i)+1;
        //printf(" %llu",s[i]);
    }
    //puts("");
}

void check(unsigned long long b){
    //printf("%llu\n",b);
    static int i;
    unsigned long long a;
    get(b,s);
    for(i=0;i<n;i++){
        if(s[i]<f[i])return;
        t[i]=s[i]-f[i];
    }
    a=0;
    for(i=n;i--;){
        if(t[i]){
            a=((unsigned long long)1<<i)-1+t[i];
            break;
        }
    }
    get(a,t);
    if(a>=b)return;
    for(i=0;i<n;i++)
        if(s[i]-t[i]!=f[i])return;
    if(b>inf)return;
    num++;
    l=a+1,r=b;
}

int main(){
    while(scanf("%d",&n)==1&&n){
        static int i;
        for(i=0;i<n;i++)
            scanf("%llu",&f[i]);
        num=0;
        x=0;
        p=0;
        for(i=n;i--;){
            x|=(unsigned long long)1<<i;
            if(f[i]){
                check(x+f[i]-1);
                if(p==0)p=f[i];
                else if(p!=f[i])break;
            }
            else x^=(unsigned long long)1<<i;
            if(num==2)break;
        }
        if(num==0)puts("None");
        else if(num==1)printf("%llu %llu\n",l,r);
        else puts("Many");
    }
    return 0;
}
accuracy: 1
time_ms: 600
memory_kb: 2720
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vvvvvll = vector<vvvvll>;
using vvvvvvll = vector<vvvvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T>
bool chmin(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll modPow(long long a, long long n, long long p) {
    if (n == 0) return 1; // 0乗にも対応する場合
    if (n == 1) return a % p;
    if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
    long long t = modPow(a, n / 2, p);
    return (t * t) % p;
}


ll gcd(ll(a), ll(b)) {
    if (a == 0)return b;
    if (b == 0)return a;
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}
ll sqrtz(ll N) {
    ll L = 0;
    ll R = sqrt(N) + 10000;
    while (abs(R - L) > 1) {
        ll mid = (R + L) / 2;
        if (mid * mid <= N)L = mid;
        else R = mid;
    }
    return L;

}


using ul = unsigned long long;
vector<ul> F(ul N) {
    vector<ul> res(64, 0);
    rep(i, 64) {
        if (i == 0) {
            res[i] = (N + 1) / 2;
            continue;
        }
        else if (i == 63) {
            res[i] = max(0ll, ll(N - (1ul << 63) + 1));
        }
        else {
            res[i] += N / (ul(1) << (i + 1)) * (ul(1) << (i));
            ll Z = N % (ul(1) << (i + 1));
            res[i] += max(0ll, ll(Z - (1ul << i) + 1));
        }
    }
    return res;
}

bool CH(ll A, ll B, vector<ul>& K) {
    while (K.size() < 64)K.push_back(0);
    vector<ul> NA = F(ul(A - 1));
    vector<ul> NB = F(ul(B));
    rep(i, 64) {
        if (NA[i] + ul(K[i]) != NB[i])return false;
    }
    return true;
}

bool DEB = 0;
int main() {

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    while (1) {
        ll N;
        cin >> N;
        if (N == 0)return 0;
        if (DEB)cout << N << endl;
        vector<ul> K(N);
        rep(i, N) {
            ll KK;
            cin >> KK;
            K[i] = ul(KK);
            if (DEB)cout << i << ": " << K[i] << endl;
        }
        if (DEB)cout << endl;
        vector<pair<ll, ll>> AN;
        for (ll L = 2 * ll(K[0]) - 1; L <= 2 * ll(K[0]) + 1; L++) {
            if (L < 0)continue;
            ul base = 0;
            for (ll k = N - 1; k >= 0; k--) {
                if (K[k] == 0)continue;
                else if (K[k] > L)break;
                else if (K[k] == L) {
                    base += (1ul << k);
                }
                else {
                    ll B = (1ul << k) + K[k] - 1 + base;
                    ll A = B - L + 1;
                    if (A < 0)break;
                    //cout<<A<<" "<<B<<endl;
                    if (ll(B)<=1e18&&CH(A, B, K))AN.push_back({ A,B });
                    break;
                }
            }
            if (base<=1e18&&CH(base, base, K))AN.push_back({ base,base });
        }

        if (AN.size() == 0) {
            cout << "None" << endl;
        }
        else if (AN.size() == 1) {
            cout << AN[0].first << " " << AN[0].second << endl;
        }
        else {
            cout << "Many" << endl;
        }
    }




}
accuracy: 1
time_ms: 700
memory_kb: 3176
final_rank: 6

code_snippet: #include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int64_t counting1s(int level, int64_t R) {
	int64_t answer = 0;
	answer += R / (2LL << level) * (1LL << level);
	answer += max(R % (2LL << level) - (1LL << level), 0LL);
	return answer;
}

bool check(int N, vector<int64_t> A, int64_t L, int64_t R) {
	for (int i = 0; i < N; i++) {
		if (counting1s(i, R) - counting1s(i, L) != A[i]) {
			return false;
		}
	}
	return true;
}

pair<int64_t, int64_t> solve(int N, vector<int64_t> A) {
	const int64_t LIMIT = 1'000'000'000'000'000'000;
	while (!A.empty() && A.back() == 0) {
		A.pop_back();
	}
	N = A.size();
	if (N == 0 || N >= 61 || *max_element(A.begin(), A.end()) > LIMIT) {
		return make_pair(-1L, -1L); // None
	}
	vector<pair<int64_t, int64_t> > answers;
	for (int64_t len = max(A[0] * 2 - 1, 1L); len <= A[0] * 2 + 1; len++) {
		int64_t bit = 0;
		int pos = N - 1;
		while (pos != -1 && (A[pos] == 0 || A[pos] == len)) {
			if (A[pos] == len) {
				bit |= 1LL << pos;
			}
			pos -= 1;
		}
		if (len == 1 && pos == -1 && 1 <= bit && bit <= LIMIT) {
			answers.push_back(make_pair(bit, bit));
		}
		if (pos != -1 && 1 <= A[pos] && A[pos] <= len - 1) {
			int64_t l = bit + (1L << pos) - (len - A[pos]);
			if (1 <= l && l + len - 1 <= LIMIT && check(N, A, l, l + len)) {
				answers.push_back(make_pair(l, l + len - 1));
			}
		}
	}
	if (int(answers.size()) == 0) {
		return make_pair(-1L, -1L); // None
	}
	if (int(answers.size()) >= 2) {
		return make_pair(-2L, -2L); // Many
	}
	return answers[0];
}

int main() {
	while (true) {
		int N;
		cin >> N;
		if (N == 0) {
			break;
		}
		vector<int64_t> A(N);
		for (int i = 0; i < N; i++) {
			cin >> A[i];
		}
		pair<int64_t, int64_t> res = solve(N, A);
		if (res == make_pair(-1L, -1L)) {
			cout << "None" << endl;
		}
		else if (res == make_pair(-2L, -2L)) {
			cout << "Many" << endl;
		}
		else {
			cout << res.first << ' ' << res.second << endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 1830
memory_kb: 3336
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128_t lll;
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 (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int K;cin>>K;
        if(K==0) break;
        vector<lll> A(K),bi(K);
        lll sum=0;
        for(int i=0;i<K;i++){
            ll x;cin>>x;
            A[i]=x;
            bi[i]=1;
            for(int j=0;j<i;j++) bi[i]*=2;
            sum+=bi[i]*A[i];
        }
        
        vector<pair<ll,ll>> ans;
        for(lll len=A[0]*2-1;len<=A[0]*2+1;len++){
            if(len<=0) continue;
            lll L=(sum*2/len+1-len)/2;
            if((L+L+len-1)*len/2!=sum) continue;
            
            lll R=L+len-1;
            if(!(1<=L&&L<=1000000000000000000LL)) continue;
            if(!(1<=R&&R<=1000000000000000000LL)) continue;
            
            L--;
            vector<lll> cn(K);
            for(int i=0;i<K;i++){
                {
                    lll syuu=(R+1)/bi[i];
                    cn[i]+=(syuu/2)*bi[i];
                    if(syuu&1){
                        cn[i]+=(R+1)%bi[i];
                    }
                }
                {
                    lll syuu=(L+1)/bi[i];
                    cn[i]-=(syuu/2)*bi[i];
                    if(syuu&1){
                        cn[i]-=(L+1)%bi[i];
                    }
                }
            }
            
            if(A==cn) ans.push_back(mp(L+1,R));
        }
        
        if(si(ans)==0){
            cout<<"None\n";
        }else if(si(ans)==1){
            cout<<ans[0].fi<<" "<<ans[0].se<<"\n";
        }else{
            cout<<"Many\n";
        }
        
    }
}
accuracy: 1
time_ms: 640
memory_kb: 3480
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef __int128_t ll;
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 (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

//int128

//https://kopricky.github.io/code/Misc/int128.html

// __int128の入出力

using LL = __int128;
istream& operator>>(istream& is, LL& v)
{
    string s;
    is >> s;
    v = 0;
    for (int i = 0; i < (int)s.size(); i++) {
        if (isdigit(s[i])) { v = v * 10 + s[i] - '0'; }
    }
    if (s[0] == '-') { v *= -1; }
    return is;
}

ostream& operator<<(ostream& os, const LL& v)
{
    if (v == 0) { return (os << "0"); }
    LL num = v;
    if (v < 0) {
        os << '-';
        num = -num;
    }
    string s;
    for (; num > 0; num /= 10) { s.push_back((char)(num % 10) + '0'); }
    reverse(s.begin(), s.end());
    return (os << s);
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int K;cin>>K;
        if(K==0) break;
        vector<ll> A(K),bi(K);
        ll sum=0;
        for(int i=0;i<K;i++){
            cin>>A[i];
            bi[i]=1;
            for(int j=0;j<i;j++) bi[i]*=2;
            sum+=bi[i]*A[i];
        }
        
        vector<pair<ll,ll>> ans;
        for(ll len=A[0]*2-1;len<=A[0]*2+1;len++){
            if(len<=0) continue;
            ll L=(sum*2/len+1-len)/2;
            if((L+L+len-1)*len/2!=sum) continue;
            
            ll R=L+len-1;
            if(!(1<=L&&L<=1000000000000000000LL)) continue;
            if(!(1<=R&&R<=1000000000000000000LL)) continue;
            
            L--;
            vector<ll> cn(K);
            for(int i=0;i<K;i++){
                {
                    ll syuu=(R+1)/bi[i];
                    cn[i]+=(syuu/2)*bi[i];
                    if(syuu&1){
                        cn[i]+=(R+1)%bi[i];
                    }
                }
                {
                    ll syuu=(L+1)/bi[i];
                    cn[i]-=(syuu/2)*bi[i];
                    if(syuu&1){
                        cn[i]-=(L+1)%bi[i];
                    }
                }
            }
            
            if(A==cn) ans.push_back(mp(L+1,R));
        }
        
        if(si(ans)==0){
            cout<<"None\n";
        }else if(si(ans)==1){
            cout<<ans[0].fi<<" "<<ans[0].se<<"\n";
        }else{
            cout<<"Many\n";
        }
        
    }
}
accuracy: 1
time_ms: 610
memory_kb: 3452
final_rank: 3

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

using namespace std;

using i64 = int64_t;

const string Many = "Many";
const string None = "None";

int kthbit(i64 x, int k) {
    return (x >> k) & 1;
}
i64 mask_lower(i64 x, int k) {
    return x & ((i64(1) << k) - 1);
}

void solve(vector<i64> k) {
    while (k.size() and k.back() == 0) k.pop_back();
    if (k.size() >= 61) {
        cout << None << '\n';
        return;
    }
    k.push_back(0);
    const int n = k.size();

    const i64 max_val = 1'000'000'000'000'000'001LL;

    const i64 dmin = k[0] * 2 - 1, dmax = k[0] * 2 + 1;

    i64 ansl = -1, ansr = -1;

    vector<i64> khi(n), klo(n);
    for (int i = 0; i < n; ++i) {
        klo[i] = mask_lower(k[i], i);
        khi[i] = k[i] >> i;
    }

    auto rec = [&](auto rec, int i, i64 l, i64 r, i64 hi) -> bool {
        if (r > max_val) return true;
        if (i == n) {
            if (l == 0 or hi != 0) return true;
            if (ansl < 0) {
                ansl = l, ansr = r;
                return true;
            }
            return false;
        }
        for (int j = i; j < n; ++j) {
            bool ok = false;
            i64 lo1 = mask_lower(klo[j], i);
            for (int li : { 0, 1 }) for (int ri : { 0, 1 }) {
                i64 lo2 = mask_lower(ri * r - li * l, i);
                ok |= lo1 == lo2;
            }
            if (not ok) return true;
        }
        for (int li : { 0, 1 }) for (int ri : { 0, 1 }) {
            i64 nl = (i64(li) << i) | l;
            i64 nr = (i64(ri) << i) | r;

            i64 dlo = klo[i] - (ri * r - li * l);

            if (mask_lower(dlo, i) != 0) continue;

            i64 carry = dlo >> i;
            assert(carry == 0 or carry == 1);
            i64 nhi = khi[i] + carry;

            if (2 * nhi + (ri - li) != hi) continue;
            if (not rec(rec, i + 1, nl, nr, nhi)) return false;
        }
        return true;
    };
    for (i64 d = dmin; d <= dmax; ++d) {
        if (not rec(rec, 0, 0, 0, d)) {
            cout << Many << '\n';
            return;
        }
    }
    if (ansl >= 0) {
        cout << ansl << ' ' << ansr - 1 << '\n';
    } else {
        cout << None << '\n';
    }
}

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

    int n;
    while (cin >> n, n) {
        vector<i64> k(n);
        for (auto& e : k) cin >> e;
        solve(k);
    }
}
accuracy: 1
time_ms: 730
memory_kb: 3524
final_rank: 7

code_snippet: #line 1 "g.cpp"
/*	author:  Kite_kuma
	created: 2022.07.05 15:38:12 */

#line 2 "SPJ-Library/template/kuma.hpp"

#line 2 "SPJ-Library/template/basic_func.hpp"

#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

template <class T0, class T1, class T2>
inline bool in_range(T0 x, T1 lef, T2 rig) {
	return ((lef <= x) && (x < rig));
}

template <class T>
inline bool chmin(T &a, T b) {
	if(a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b) {
	if(a < b) {
		a = b;
		return true;
	}
	return false;
}

void Yes(bool flag = true) { std::cout << (flag ? "Yes" : "No") << '\n'; }
void YES(bool flag = true) { std::cout << (flag ? "YES" : "NO") << '\n'; }

template <class T>
void drop(T answer) {
	std::cout << answer << '\n';
	exit(0);
}

template <class T>
void vout(std::vector<T> const &v, bool vertically = 0) {
	if(vertically) {
		for(auto const &a : v) {
			std::cout << a << '\n';
		}
		return;
	}
	for(auto it = v.begin(); it != v.end(); it++) {
		std::cout << (*it);
		if(it != v.end() - 1) {
			std::cout << ' ';
		}
	}
	std::cout << '\n';
	return;
}

inline void print() { std::cout << '\n'; }
template <class T>
inline void print(const T &x) {
	std::cout << x << '\n';
	return;
}
template <typename Head, typename... Tail>
void print(const Head &H, const Tail &... T) {
	std::cout << H << " ";
	print(T...);
}

template <class T>
void add(std::vector<T> &v, T value) {
	for(auto &a : v) a += value;
	return;
}

template <class T>
T greatest_lower_multiple(T x, T d) {
	if(d == 0) return 0;
	if(d < 0) d *= -1;
	T y = x % d;
	if(y < 0) y += d;
	return x - y;
}

template <class T>
T least_upper_multiple(T x, T d) {
	return -greatest_lower_multiple(-x, d);
}

// ceil(a / b);
template <class T>
T dup(T a, T b) {
	assert(b);
	if(b < 0) {
		a *= -1;
		b *= -1;
	}
	return least_upper_multiple(a, b) / b;
}

long long pow_ll(long long a, long long n) {
	assert(n >= 0LL);
	if(n == 0) return 1LL;
	if(a == 0) return 0LL;
	if(a == 1) return 1LL;
	if(a == -1) return (n & 1LL) ? -1LL : 1LL;
	long long res = 1;
	while(n > 1LL) {
		if(n & 1LL) res *= a;
		a *= a;
		n >>= 1;
	}
	return res * a;
}

long long modpow(long long a, long long n, long long mod) {	 // a^n mod
	assert(n >= 0 && mod);
	if(mod == 1) return 0LL;
	long long res = 1;
	a %= mod;
	while(n > 0) {
		if(n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res < 0 ? res + mod : res;
}

// return x which satisfies a * x % mod == gcd(a, mod)
// not (mod | a)
long long modinv(long long a, const long long mod) {
	long long b = mod, u = 1, v = 0;
	while(b) {
		long long t = a / b;
		a -= t * b;
		std::swap(a, b);
		u -= t * v;
		std::swap(u, v);
	}
	u %= mod;
	if(u < 0) u += mod;
	return u;
}

template <class T>
int lb(const std::vector<T> &a, const T x) {
	return (int)std::distance(a.begin(), std::lower_bound(a.begin(), a.end(), x));
}
template <class T>
int ub(const std::vector<T> &a, const T x) {
	return (int)std::distance(a.begin(), std::upper_bound(a.begin(), a.end(), x));
}
template <class T>
void unq_sort(std::vector<T> &a) {
	std::sort(a.begin(), a.end());
	a.erase(std::unique(a.begin(), a.end()), a.end());
}
template <class T>
std::vector<int> press(const std::vector<T> &a) {
	std::vector<T> vec = a;
	unq_sort(vec);
	std::vector<int> ret;
	for(const auto &v : a) ret.push_back(lb(vec, v));
	return ret;
}
#line 1 "SPJ-Library/template/header.hpp"
#include <bits/stdc++.h>
#line 2 "SPJ-Library/template/io.hpp"

#line 4 "SPJ-Library/template/io.hpp"

#line 8 "SPJ-Library/template/debug.hpp"

#line 3 "SPJ-Library/template/constants.hpp"

constexpr int inf = 1000'000'000;
constexpr long long INF = 1'000'000'000'000'000'000LL;
constexpr int mod_1000000007 = 1000000007;
constexpr int mod_998244353 = 998244353;
const long double pi = acosl(-1.);
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
#line 10 "SPJ-Library/template/debug.hpp"

namespace viewer {

template <typename T, typename U>
void view(const std::pair<T, U> &p);

template <class T0, class T1, class T2>
void view(const std::tuple<T0, T1, T2> &p);

template <class T0, class T1, class T2, class T3>
void view(const std::tuple<T0, T1, T2, T3> &p);

void view(const long long &e);

void view(const int &e);

template <typename T>
void view(const T &e);

template <typename T>
void view(const std::set<T> &s);

template <typename T>
void view(const std::unordered_set<T> &s);

template <typename T>
void view(const std::multiset<T> &s);

template <typename T>
void view(const std::unordered_multiset<T> &s);

template <typename T>
void view(const std::vector<T> &v);

template <typename T, std::size_t ary_size>
void view(const std::array<T, ary_size> &v);

template <typename T>
void view(const std::vector<std::vector<T>> &vv);

template <typename T, typename U>
void view(const std::vector<std::pair<T, U>> &v);

template <class T0, class T1, class T2>
void view(const std::vector<std::tuple<T0, T1, T2>> &v);

template <class T0, class T1, class T2, class T3>
void view(const std::vector<std::tuple<T0, T1, T2, T3>> &v);

template <typename map_type>
void view_map_container(const map_type &m);

template <typename T, typename U>
void view(const std::map<T, U> &m);

template <typename T, typename U>
void view(const std::unordered_map<T, U> &m);

template <typename container_type>
void view_container(const container_type &c, bool vertically = false) {
	typename container_type::const_iterator begin = c.begin();
	const typename container_type::const_iterator end = c.end();
	if(vertically) {
		std::cerr << "{\n";
		while(begin != end) {
			std::cerr << '\t';
			view(*(begin++));
			if(begin != end) std::cerr << ',';
			std::cerr << '\n';
		}
		std::cerr << '}';
		return;
	}
	std::cerr << "{ ";
	while(begin != end) {
		view(*(begin++));
		if(begin != end) std::cerr << ',';
		std::cerr << ' ';
	}
	std::cerr << '}';
}

template <typename T, typename U>
void view(const std::pair<T, U> &p) {
	std::cerr << '(';
	view(p.first);
	std::cerr << ", ";
	view(p.second);
	std::cerr << ')';
}

template <class T0, class T1, class T2>
void view(const std::tuple<T0, T1, T2> &p) {
	std::cerr << '(';
	view(std::get<0>(p));
	std::cerr << ", ";
	view(std::get<1>(p));
	std::cerr << ", ";
	view(std::get<2>(p));
	std::cerr << ')';
}

template <class T0, class T1, class T2, class T3>
void view(const std::tuple<T0, T1, T2, T3> &p) {
	std::cerr << '(';
	view(std::get<0>(p));
	std::cerr << ", ";
	view(std::get<1>(p));
	std::cerr << ", ";
	view(std::get<2>(p));
	std::cerr << ", ";
	view(std::get<3>(p));
	std::cerr << ')';
}

void view(const long long &e) {
	if(e == INF)
		std::cerr << "INF";
	else if(e == -INF)
		std::cerr << "-INF";
	else
		std::cerr << e;
}

void view(const int &e) {
	if(e == inf)
		std::cerr << "inf";
	else if(e == -inf)
		std::cerr << "-inf";
	else
		std::cerr << e;
}

template <typename T>
void view(const T &e) {
	std::cerr << e;
}

template <typename T>
void view(const std::set<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::unordered_set<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::multiset<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::unordered_multiset<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::vector<T> &v) {
	view_container(v);
}

template <typename T, std::size_t ary_size>
void view(const std::array<T, ary_size> &v) {
	view_container(v);
}

template <typename T>
void view(const std::vector<std::vector<T>> &vv) {
	view_container(vv, true);
}

template <typename T, typename U>
void view(const std::vector<std::pair<T, U>> &v) {
	view_container(v, true);
}

template <class T0, class T1, class T2>
void view(const std::vector<std::tuple<T0, T1, T2>> &v) {
	view_container(v, true);
}

template <class T0, class T1, class T2, class T3>
void view(const std::vector<std::tuple<T0, T1, T2, T3>> &v) {
	view_container(v, true);
}

template <typename map_type>
void view_map_container(const map_type &m) {
	std::cerr << "{\n";
	for(typename map_type::const_iterator it = m.begin(); it != m.end(); it++) {
		std::cerr << "\t[";
		view(it->first);
		std::cerr << "] : ";
		view(it->second);
		std::cerr << '\n';
	}
	std::cerr << "}";
}

template <typename T, typename U>
void view(const std::map<T, U> &m) {
	view_map_container(m);
}

template <typename T, typename U>
void view(const std::unordered_map<T, U> &m) {
	view_map_container(m);
}

}  // namespace viewer

// when compiling : g++ foo.cpp -DLOCAL
#ifdef LOCAL
void debug_out() {}
template <typename T>
void debug_out(const T &x) {
	viewer::view(x);
}
template <typename Head, typename... Tail>
void debug_out(const Head &H, const Tail &... T) {
	viewer::view(H);
	std::cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                                \
	do {                                                          \
		std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                                   \
		std::cerr << "]\n";                                       \
	} while(0)
#else
#define debug(...) (void(0))
#endif
#line 2 "SPJ-Library/template/scanner.hpp"

#line 6 "SPJ-Library/template/scanner.hpp"

namespace scanner {
template <class T>
void scan(T &a) {
	std::cin >> a;
}

template <class T, class L>
void scan(std::pair<T, L> &p) {
	scan(p.first);
	scan(p.second);
}

template <class T0, class T1, class T2>
void scan(std::tuple<T0, T1, T2> &p) {
	T0 t0;
	T1 t1;
	T2 t2;
	scan(t0);
	scan(t1);
	scan(t2);
	p = std::make_tuple(t0, t1, t2);
}

template <class T0, class T1, class T2, class T3>
void scan(std::tuple<T0, T1, T2, T3> &p) {
	T0 t0;
	T1 t1;
	T2 t2;
	T3 t3;
	scan(t0);
	scan(t1);
	scan(t2);
	scan(t3);
	p = std::make_tuple(t0, t1, t2, t3);
}

template <class T>
void scan(std::vector<T> &a) {
	for(auto &i : a) scan(i);
}

void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
}  // namespace scanner
#line 7 "SPJ-Library/template/io.hpp"

#define VEC(type, name, size) \
	vector<type> name(size);  \
	scanner::INPUT(name)
#define VVEC(type, name, h, w)                     \
	vector<vector<type>> name(h, vector<type>(w)); \
	scanner::INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define STR(...)        \
	string __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define CHR(...)      \
	char __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define DBL(...)        \
	double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define TPL3(type0, type1, type2, name)   \
	std::tuple<type0, type1, type2> name; \
	scanner::INPUT(name);
#define TPL4(type0, type1, type2, type3, name)   \
	std::tuple<type0, type1, type2, type3> name; \
	scanner::INPUT(name);

template <typename T1, typename T2>
std::istream &operator>>(std::istream &is, std::pair<T1, T2> &p) {
	is >> p.first >> p.second;
	return is;
}

template <typename T1, typename T2>
std::ostream &std::operator<<(std::ostream &os, const std::pair<T1, T2> &p) {
	os << p.first << ' ' << p.second;
	return os;
}
template <class T>
std::ostream &std::operator<<(std::ostream &os, const std::vector<T> &v) {
	for(typename std::vector<T>::const_iterator it = v.begin(); it != v.end(); it++) {
		if(it != v.begin()) std::cerr << ' ';
		os << *it;
	}
	return os;
}

struct fast_io {
	fast_io() {
		std::ios::sync_with_stdio(false);
		std::cin.tie(nullptr);
		std::cout << std::fixed << std::setprecision(15);
		srand((unsigned)time(NULL));
	}
} fast_io_;
#line 2 "SPJ-Library/template/macros.hpp"

#define foa(s, v) for(auto &s : v)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pcnt(n) __builtin_popcountll((long long)n)

#define REPname(a, b, c, d, e, ...) e
#define rep(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for(int Counter_in_rep_macro = 0; Counter_in_rep_macro < (x); ++Counter_in_rep_macro)
#define REP1(i, x) for(int i = 0; i < (x); ++i)
#define REP2(i, l, r) for(int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c))
#define DREPname(a, b, c, d, e, ...) e
#define drep(...) DREPname(__VA_ARGS__, DREP3, DREP2, DREP1)(__VA_ARGS__)
#define DREP1(i, x) for(int i = (x)-1; i >= 0; --i)
#define DREP2(i, l, r) for(int i = (r)-1; i >= (l); --i)
#define DREP3(i, l, r, c) for(int i = (r)-1; i >= (l); i -= (c))

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vvvi = std::vector<std::vector<std::vector<int>>>;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
template <class T = ll>
using V = std::vector<T>;
template <class T = ll>
using VV = V<V<T>>;
template <class T = ll>
using VVV = V<V<V<T>>>;
template <class T = ll>
using pqup = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T = ll>
using pqdn = std::priority_queue<T>;
#line 7 "SPJ-Library/template/kuma.hpp"

using namespace std;
#line 5 "g.cpp"

// 0以上x未満
vector<ll> f(ll x) {
	vector<ll> res(61);
	rep(i, 61) {
		ll loop = 1ll << (i + 1);
		res[i] += x / loop * (1ll << i);
		ll mod = x % loop - (loop / 2);
		chmax(mod, 0LL);
		res[i] += mod;
	}
	return res;
}

//[A, B)
vector<ll> hoge(ll A, ll B) {
	auto vecb = f(B);
	auto veca = f(A);
	rep(k, 61) { vecb[k] -= veca[k]; }
	return vecb;
}

const pair<ll, ll> ng(-1, -1);

pair<ll, ll> calc(const vector<ll> &k, int topbit, ll range_length) {
	if(range_length < 1) return ng;
	if(k[topbit] > range_length) return ng;
	if(topbit == 0) {
		if(k[0] < 0 || k[0] > 1) return ng;
		return make_pair(k[0], k[0] + 1);
	}
	if(k[topbit] == 0){
		return calc(k, topbit-1, range_length);
	}
	if(k[topbit] < range_length) {
		ll mid = 1LL << topbit;
		ll right = mid + k[topbit];
		ll left = right - range_length;
		return make_pair(left, right);
	}

	ll l, r;
	tie(l, r) = calc(k, topbit - 1, range_length);

	debug(l, r);
	ll tb = 1LL << topbit;
	l += tb;
	r += tb;
	return make_pair(l, r);
}

bool valid(int n, const vector<ll> &k, ll a, ll b) {
	if(a < 1 || b > pow_ll(10LL, 18) + 1) return false;
	if(a >= b) return false;
	auto res = hoge(a, b);
	rep(i, n) {
		if(k[i] != res[i]) return false;
	}
	rep(i, n, 61) {
		if(res[i]) return false;
	}
	return true;
}

void solve(int n) {
	VEC(ll, k, n);
	debug(k);
	if(n > 61) {
		print("None");
		return;
	}
	if(*max_element(all(k)) > pow_ll(10LL, 18) + 10) {
		print("None");
		return;
	}
	ll len_mid = k[0] << 1;

	ll a, b;
	a = -1;
	b = -1;
	for(ll len = len_mid - 1; len <= len_mid + 1; len++) {
		ll c, d;
		tie(c, d) = calc(k, n - 1, len);
		if(c > 0) debug(c, d);
		if(valid(n, k, c, d)) {
			if(a == -1) {
				a = c;
				b = d;
			} else {
				print("Many");
				return;
			}
		}
	}
	if(a < 0) {
		print("None");
		return;
	}
	print(a, b - 1);
}

int main() {
	int n;
	while(cin >> n && n) {
		solve(n);
	}
}
accuracy: 1
time_ms: 650
memory_kb: 3392
final_rank: 5

code_snippet: //#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000009;
const ll INF = mod * mod;
typedef pair<int, int>P;

#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
if (n < 0) {
	ll res = mod_pow(x, -n, m);
	return mod_pow(res, m - 2, m);
}
if (abs(x) >= m)x %= m;
if (x < 0)x += m;
ll res = 1;
while (n) {
	if (n & 1)res = res * x % m;
	x = x * x % m; n >>= 1;
}
return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 22;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}
int gcd(int a, int b) {
	if (a < b)swap(a, b);
	while (b) {
		int r = a % b; a = b; b = r;
	}
	return a;
}

int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//[0,r)のうちk bit目が立ってる個数
ll calc(int k, ll r) {
	ll s = 1ll << k;
	ll d = r / (2 * s);
	r %= 2 * s;
	ll res = d * s;
	if (r >= s)res += r - s;
	return res;
}
vector<LP> anss;
void add(vector<ll> cnt, ll ad, ll l, ll len) {
	ll r = l + len;
	bool valid = true;
	rep(i, cnt.size()) {
		ll num = calc(i, r) - calc(i, l);
		if (num != cnt[i])valid = false;
	}
	if (l+ad == 0)valid = false;
	if (l+ad + len - 1 > (ll)1000000000000000000)valid = false;
	if (valid)anss.push_back({ ad+l,ad+r });
}

void dfs(vector<ll> cnt, ll ad, ll len) {
	if (cnt.empty()) {
		if (len == 1) {
			add(cnt, ad, 0,1);
		}
		return;
	}
	if (cnt.back() == 0) {
		cnt.pop_back();
		dfs(cnt, ad, len);
		return;
	}
	ll ma = 1ll << (cnt.size() - 1);
	if (cnt.back() > ma)return;
	if (cnt.back() == ma&&ma==len)add(cnt, ad, ma, ma);
	//in one
	if (cnt.back() == len) {
		vector<ll> ncnt = cnt; ncnt.pop_back();
		ll nad = ad;
		nad |= ma;
		ll nlen = len;
		dfs(ncnt, nad, nlen);
	}
	//with zero
	ll r = len - cnt.back();
	if (r > 0) {
		ll l = ma - r;
		add(cnt, ad, l, len);
	}
}
int n;
void solve() {
	anss.clear();
	vector<ll> cnt(n);
	bool valid = true;
	rep(i, n) {
		ul x; cin >> x;
		ul sup = (ul)1 << 60;
		if (x >= sup) {
			valid = false;
		}
		if (i >= 60 && x != 0)valid = false;
		cnt[i] = x;
	}
	if (!valid) {
		cout << "None\n"; return;
	}
	for (ll len = 2 * cnt[0] - 1; len <= 2 * cnt[0] + 1; len++) {
		if (len <= 0)continue;
		dfs(cnt, 0, len);
	}
	sort(all(anss));
	anss.erase(unique(all(anss)), anss.end());
	if (anss.empty()) {
		cout << "None\n";
	}
	else if (anss.size() > 1) {
		cout << "Many\n";
	}
	else {
		cout << anss[0].first << " " << anss[0].second - 1 << "\n";
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init_f();
	//init();
	//int t; cin >> t; rep(i, t)
	while(cin>>n,n)
		solve();
	return 0;
}
accuracy: 1
time_ms: 560
memory_kb: 68972
final_rank: 19

code_snippet: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

constexpr unsigned long long int ov = 2000000000000000000;

inline pair<unsigned long long int, unsigned long long int>div(unsigned long long int a, unsigned long long int b, unsigned long long int d) {
	if (b == 0) {
		return { 0,0 };
	}
	if (a >= d) {
		auto p = div(a%d, b, d);
		if (a / d <= ov / b) {
			p.first += a / d * b;
		}
		else {
			p.first = ov + 1;
		}
		if (p.first > ov) {
			p.first = ov + 1;
		}
		return p;
	}
	if (b % 2 == 0) {
		auto p = div(a * 2 % d, b / 2, d);
		if (a * 2 >= d) {
			p.first += b / 2;
		}
		if (p.first > ov) {
			p.first = ov + 1;
		}
		return p;
	}
	else {
		auto p = div(a * 2 % d, b / 2, d);
		if (a * 2 >= d)p.first += b / 2;
		p.first += a / d;
		p.second += a % d;
		if (p.second >= d) {
			p.second -= d;
			p.first++;
		}
		if (p.first > ov) {
			p.first = ov + 1;
		}
		return p;
	}
}

void add(pair<unsigned long long int, unsigned long long int>&a, pair<unsigned long long int, unsigned long long int>b, unsigned long long int &d) {
	a.first += b.first;
	a.second += b.second;
	if (a.second >= d) {
		a.second -= d;
		a.first++;
	}
	if (a.first > ov) {
		a.first = ov + 1;
	}
	return;
}

unsigned long long int bitnum(unsigned long long int r, unsigned long long int b) {
	unsigned long long int ret = 0;
	ret = r / (1LL << (b + 1));
	ret <<= b;
	unsigned long long int m = r % (1LL << (b + 1));
	if (m >= 1LL << b)ret += m - (1LL << b) + 1;
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	while (cin >> N, N) {
		vector<unsigned long long int>v(N);
		for (auto &i : v)cin >> i;
		bool none = false;
		for (int i = 60; i < N; i++) {
			if (v[i])none = true;
		}
		if (none) {
			cout << "None\n";
			continue;
		}
		vector<pair<unsigned long long int, unsigned long long int>>ans;
		for (unsigned long long int num = ((v[0] == 0) ? 1 : v[0] * 2 - 1); num <= v[0] * 2 + 1; num++) {
			unsigned long long int d = num;
			if (d % 2 == 0)d >>= 1;
			pair<unsigned long long int, unsigned long long int>box;
			for (int i = 0; i < N; i++) {
				add(box, div(1LL << i, v[i], d), d);
			}
			if (box.second)continue;
			if (box.first > ov)continue;
			unsigned long long int st, ed;
			if (num & 1) {
				st = box.first - num / 2;
				ed = box.first += num / 2;
			}
			else {
				st = (box.first - num + 1) / 2;
				ed = st + num - 1;
			}
			if (st <= 0 || ed > ov / 2)continue;
			vector<unsigned long long int>dnum(N);
			for (int i = 0; i < N; i++) {
				dnum[i] = bitnum(ed, i) - bitnum(st - 1, i);
			}
			if (dnum == v)ans.emplace_back( st,ed );
		}
		if (ans.size() == 0) {
			cout << "None\n";
		}
		else if (ans.size() == 1) {
			cout << ans[0].first << " " << ans[0].second << endl;
		}
		else {
			cout << "Many\n";
		}
	}
}
accuracy: 1
time_ms: 7710
memory_kb: 3156
final_rank: 20

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 64
#define LIMIT 1000000000000000000

enum Type{
	UNIQUE,
	MANY,
	NONE,
};

int N;
ull POW[NUM],input[NUM];
ull ans_A,ans_B;
Type type_array[3];

ull calc(ull num,int digit){

	if(digit == 0){

		return (num+1)/2;
	}

	ll ret = (((num+1)/POW[digit])/2)*POW[digit];

	if((num+1)%POW[digit] == 0){

		return ret;
	}

	if(((num+1)/POW[digit])%2 == 0){

		return ret;

	}else{

		return ret+(num+1)%POW[digit];
	}
}

bool is_ok(ull A,ull B,ull num,int digit){

	ull tmp = calc(B,digit)-calc(A-1,digit);

	return tmp == num;
}

bool DEBUG = false;

Type solve(ull width){

	ull A,B;

	for(int i = N-1; i >= 0; i--){

		if(input[i] > width){

			return NONE;
		}
	}

	B = 0;

	for(int i = N-1; i >= 0; i--){

		if(input[i] == width){

			B += POW[i];

		}else if(input[i] == 0){

			//Do nothing

		}else{ //input[i] < width

			B += POW[i];
			B += input[i]-1;
			break;
		}
	}

	A = B-width+1;

	if(A < 1 || B > LIMIT){

		return NONE;
	}

	for(int i = N-1; i >= 0; i--){
		if(!is_ok(A,B,input[i],i)){

			return NONE;
		}
	}

	ans_A = A,ans_B = B;

	return UNIQUE;
}

void func(){

	for(int i = 0; i < NUM; i++){

		input[i] = 0;
	}

	for(int i = 0; i < N; i++){

		scanf("%llu",&input[i]);
	}

	type_array[0] = solve(2*input[0]-1);
	type_array[1] = solve(2*input[0]);
	type_array[2] = solve(2*input[0]+1);

	int num_unique = 0;

	for(int i = 0; i < 3; i++){

		if(type_array[i] == UNIQUE){

			num_unique++;
		}
	}

	if(num_unique == 1){

		printf("%llu %llu\n",ans_A,ans_B);
	}else{

		if(num_unique >= 2){

			printf("Many\n");
		}else{

			printf("None\n");
		}
	}
}

int main(){

	POW[0] = 1;

	for(int i = 1; i < NUM; i++){

		POW[i] = POW[i-1]*2;
	}

	while(true){

		scanf("%d",&N);
		if(N == 0)break;

		func();

		if(DEBUG)break;
	}

	return 0;
}
accuracy: 1
time_ms: 550
memory_kb: 3200
final_rank: 2

code_snippet: #include<bits/stdc++.h>
#define H 70
using namespace std;
typedef unsigned long long ull;

int n;
ull k[H], dis, A, B;
int ans;

ull f(ull x, int p)
{
	if(!x) return 0;
	ull ret = 0; int h = 0;
	for(; (1ull << h) <= (ull)x; h++); h--;
	for(; p <= h; )
	{
		if(p == h) ret += x - (1ull << h) + 1;
		else ret += 1ull << (h - 1);
		x -= 1ull << h;
		if(!x) break;
		for(; ((1ull << h) & x) == 0; h--);
	}
	return ret;
}

void check(ull a, ull b)
{
	if(a > b) return;
	if(!a) return;
	if(b > 1000000000000000000ll) return;
// printf("check %llu %llu\n",a,b);
	for(int i = 0; i < n; i++) 
		if(f(b,i) != k[i] + f(a-1,i))
			return;
	if(a != A || b != B)
		++ans, A = a, B = b;
}

void solve(ull L, ull R, ull d, int p)
{
	if(p < 0)
	{
		check(L,L);
		return;
	}
	ull mid = (L+R) >> 1;
	if(d == 2333366)
	{
		if(k[p])
		{
			if(k[p] <= R - mid)
			{
				check(mid + k[p] - dis + 0, mid + k[p]);
				check(mid + k[p] - dis + 1, mid + k[p]);
				check(mid + k[p] - dis + 2, mid + k[p]);
				solve(mid+1, R, k[p], p-1);
			}
		}
		else
		{
			solve(L, mid, d, p-1);
		}
	}
	else
	{
		if(k[p])
		{
			if(k[p] <= d)
			{
				check(mid + k[p] - dis + 0, mid + k[p]);
				check(mid + k[p] - dis + 1, mid + k[p]);
				check(mid + k[p] - dis + 2, mid + k[p]);
			}
			if(d == k[p])
			{
				solve(mid+1, R, d, p-1);
			}
		}
		else
		{
			solve(L, mid, d, p-1);
		}
	}
}

int main()
{
	for(; scanf("%d",&n) != EOF; )
	{
		if(!n) break;
			
		for(int i = 0; i < n; i++) scanf("%llu",&k[i]);
		dis = k[0] << 1; ans = 0;
		
		solve(0,(1ull<<n)-1,2333366,n-1);

		if(ans > 1) puts("Many");
		else if(!ans) puts("None");
		else printf("%llu %llu\n",A,B);
		
	}
}
accuracy: 1
time_ms: 1170
memory_kb: 3100
final_rank: 14

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
typedef long long ll;
using namespace std;
ll flr(ll x, int i) {
    return x & ~ ((1ll<<i) - 1);
}
ll acc(ll x, int i) { // the number of integers in [0,x) which has i-th bit
    ll y = flr(x, i);
    ll z = flr(x, i+1);
    return z/2 + (z == y ? 0 : x - y);
}
int main() {
    while (true) {
        // input
        int n; cin >> n;
        if (n == 0) break;
        vector<ll> k(n); repeat (i,n) cin >> k[i];
        // trivial
        bool is_trivial = false; // due to B muse \le 10^{18}
        if (60 < n) is_trivial = true;
        for (ll it : k) {
            if (1000000000000000000ll < it) is_trivial = true;
        }
        // compute
        vector<pair<ll, ll> > cands;
        for (int delta : { -1, 0, 1 }) {
            ll l = k[0] * 2 + delta;
            if (l <= 0) {
                continue;
            } else if (l == 1) {
                ll a = 0;
                repeat (i,n) {
                    if (k[i]) a += 1ll<<i;
                }
                cands.emplace_back(a, a);
            } else {
                int i = n-1;
                ll base = 0;
                while ((k[i] == 0 or k[i] == l) and i != 0) {
                    if (k[i] == l) base += 1ll<<i;
                    -- i;
                }
                ll b = (1ll<<i) + k[i] - 1 + base;
                ll a = b - l + 1;
                if (a <= 0) continue;
                cands.emplace_back(a, b);
            }
        }
        vector<pair<ll, ll> > ans;
        for (auto it : cands) {
            ll a, b; tie(a, b) = it;
            bool is_valid = true;
            if (1000000000000000000ll < b) is_valid = false;
            repeat (j,n) {
                if (acc(b+1, j) - acc(a, j) != k[j]) {
                    is_valid = false;
                    break;
                }
            }
            if (is_valid) {
                ans.emplace_back(a, b);
            }
        }
        // output
        switch (ans.size()) {
            case 0: cout << "None" << endl; break;
            case 1: cout << ans[0].first << ' ' << ans[0].second << endl; break;
            default: cout << "Many" << endl; break;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 2160
memory_kb: 3064
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
const int MAXN=65;
const long long INF=1000000000000000000LL;
int n;
long long k[MAXN];
long long calc(long long A, int x){
    long long mask=1LL<<x; A++;
    long long tmp=A/mask, ans=(tmp/2)*mask;
    if(tmp&1LL) ans+=A&(mask-1);
    return ans;
}
bool check(long long A, long long B){
    for(int i=n-1; i>=0; i--){
        if(calc(B,i)-calc(A-1,i)!=k[i]){
            return false;
        }
    }
    return true;
}
long long solve(long long W){
    long long A=0, B=-1, C=-1;
    for(int i=n-1; i>=0; i--){
        if(k[i]>W) return -1;
        if(k[i]==0){
            A|=0LL<<i;
        }
        else if(k[i]==W){
            A|=1LL<<i;
        }
        else{
            B=A|(1LL<<i);
            C=B+k[i]-1;
            A=C-W+1;
            break;
        }
    }
    if(C==-1) C=A;
    if(A==0||C>INF) return -1;
    if(A+W-1==C&&check(A,C)){
        return A;
    }
    return -1;
}
int main(){
    while(~scanf("%d",&n)&&n){
        for(int i=0; i<n; i++){
            scanf("%lld",&k[i]);
        }
        long long A=-1, B;
        for(long long W=2*k[0]-1; W<=2*k[0]+1; W++){
            if(W<0) continue;
            long long ret=solve(W);
            if(ret!=-1){
                if(A!=-1){
                    puts("Many");
                    goto failed;
                }
                A=ret; B=ret+W-1;
            }
        }
        if(A==-1){
            puts("None");
        }
        else{
            printf("%lld %lld\n",A,B);
        }
        failed:;
    }
    return 0;
}
accuracy: 1
time_ms: 1020
memory_kb: 1176
final_rank: 8

code_snippet: #include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define ALL(container) (container).begin(), (container).end()
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

int T, n, m;

vector<ll> count(ll x){	// count [0, x)
	vector<ll> ans;
	ll sum = 0;
	RREP(i, n + 1){
		if(1 & (x >> i)){
			x -= 1ll << i;
			ans.pb(sum + x);
			sum += (1ll << i) / 2;
		}else ans.pb(sum);
	}
	reverse(ALL(ans));
	return ans;
}

void check(vector<ll> &d, ll l, ll r, vector<pll> &ans){ // check [0, r)
	if(l <= 0 || r <= 0 || r <= l || r > 1000000000000000001ll) return;
	auto rv = count(r);
	auto lv = count(l);
	d.pb(0);
	if([&](){
		REP(i, d.size()) if(d[i] != rv[i] - lv[i]) return 0;
		return 1;
	}()) ans.eb(l, r);
	d.pop_back();
}

int main(int argc, char *argv[]){
	while(scanf("%d", &n), n){
		vector<ll> d(n);
		REP(i, n) scanf("%lld", &d[i]);
		while(!d.empty() && d.back() == 0) d.pop_back();
		n = d.size();
		vector<pll> ans;
		if(!n || n > 60){
			puts("None"); continue;
		}
		
		REP(i, 3){
			ll r = (1ll<<(n-1)) + d[n-1];
			ll w = d[0] * 2 - 1 + i;
			check(d, r - w, r, ans);
		}
		
		ll w = d.back();
		ll r = (1ll<<(n-1));
		if(abs(w / 2 - d[0]) <= 1){
			RREP(i, n-1)if(d[i]){
				r += 1ll << i;
				if(d[i] == w) continue;
				r += d[i];
				check(d, r - w, r, ans);
				break;
			}
		}
		if(w == 1) check(d, r, r + 1, ans);
		sort(ALL(ans)); UNIQUE(ans);
		if(ans.empty()) puts("None");
		else if(ans.size() > 1) puts("Many");
		else printf("%lld %lld\n", ans[0].first, ans[0].second - 1);
	}
	return 0;
}
accuracy: 1
time_ms: 1190
memory_kb: 1204
final_rank: 11

code_snippet: #include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <unordered_map>
#include <iterator>
#include <functional>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

vector<ll> count(ll x){	// count [0, x)
	vector<ll> ans;
	ll sum = 0;
	RREP(i, n + 1){
		if(1 & (x >> i)){
			x -= 1ll << i;
			ans.pb(sum + x);
			sum += (1ll << i) / 2;
		}else ans.pb(sum);
	}
	reverse(ALL(ans));
	return ans;
}

void check(vector<ll> &d, ll l, ll r, vector<pll> &ans){ // check [0, r)
	if(l <= 0 || r <= 0 || r <= l || r > 1000000000000000001ll) return;
	auto rv = count(r);
	auto lv = count(l);
/*	cout << "check " << l << ", " << r << ": " << endl;
	cout << lv << endl;
	cout << rv << endl;
	cout << d << endl;
*/
	d.pb(0);
	if([&](){
		REP(i, d.size()) if(d[i] != rv[i] - lv[i]) return 0;
		return 1;
	}()) ans.eb(l, r);
	d.pop_back();
}

int main(int argc, char *argv[]){
	while(scanf("%d", &n), n){
		vector<ll> d(n);
		REP(i, n) scanf("%lld", &d[i]);
		while(!d.empty() && d.back() == 0) d.pop_back();
		n = d.size();
		vector<pll> ans;
		if(!n || n > 60){
			puts("None"); continue;
		}
		
		REP(i, 3){
			ll r = (1ll<<(n-1)) + d[n-1];
			ll w = d[0] * 2 - 1 + i;
			check(d, r - w, r, ans);
		}
		
		ll w = d.back();
		ll r = (1ll<<(n-1));
		RREP(i, n-1)if(d[i]){
			r += 1ll << i;
			if(d[i] == w) continue;
			r += d[i];
			check(d, r - w, r, ans);
			break;
		}
		check(d, r, r + 1, ans);
		sort(ALL(ans)); UNIQUE(ans);
		if(ans.empty()) puts("None");
		else if(ans.size() > 1) puts("Many");
		else printf("%lld %lld\n", ans[0].first, ans[0].second - 1);
	}
	return 0;
}
accuracy: 1
time_ms: 1280
memory_kb: 1204
final_rank: 13

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef long long ll;
ll p[64];
ll num(ll x,int j){
	return x/p[j+1]*p[j]+max(0LL,x%p[j+1]-p[j]);
}
void solve(int n){
	int nc=n;
	ll k[64],kc[64];
	rep(i,64) k[i]=-1;
	rep(i,n) cin>>k[i];
	rep(i,n) kc[i]=k[i];
//	while(n>0&&k[n-1]==0) n--;
//	if(n==-1){}
	rep(i,n){
		if(k[i]>=p[60]){
			puts("None");
			return;
		}
	}
	ll ansa=-1,ansb=-1;
	for(ll mo=kc[0]*2-1;mo<=kc[0]*2+1;mo++){
		ll a=0,b=0;
		ll m=mo;
		n=nc;
		rep(i,n) k[i]=kc[i];
		for(int i=n-1;i>=0;i--){
			if(k[i]==0) continue;
			if(k[i]==m){
				k[i]=0;
				a+=p[i],b+=p[i];
				continue;
			}
			if(k[i]>m){
				break;
			}
			rep(j,i) k[j]-=num(k[i],j);
			m-=k[i];
			b+=p[i]+k[i]-1;
			a+=p[i]-m;
			k[i]=0;
//			rep(j,n) show(k[j]);
//			show(m);
			rep(j,i) k[j]-=(m-num(m,j));
//			rep(j,n) show(k[j]);
			break;
		}
		bool can=true;
		rep(i,nc) if(k[i]!=0) can=false;
		if(1>a||a>b||b>1e18) can=false;
		if(can){
			if(ansa==-1){
				ansa=a,ansb=b;
			}else{
				puts("Many");
				return;
			}
		}
	}
	if(ansa==-1){
		puts("None");
		return;
	}
	cout<<ansa<<" "<<ansb<<endl;
}
int main(){
	p[0]=1;
	rep(i,63) p[i+1]=p[i]*2;
	while(true){
		int n;
		cin>>n;
		if(n==0) break;
		solve(n);
	}
}
accuracy: 1
time_ms: 3170
memory_kb: 1164
final_rank: 17

code_snippet: #include<stdio.h>
#include<algorithm>
using namespace std;
long long b[110];
long long c[110];
int n;
int chk(long long L,long long R){
	if(L<1||L>1000000000000000000LL||R<1||R>1000000000000000001LL)return 0;
	if(L>=R)return 0;
	for(int i=0;i<n;i++){
		long long val=R/(1LL<<(i+1))*(1LL<<i)+max(0LL,R%(1LL<<(i+1))-(1LL<<i));
		val-=L/(1LL<<(i+1))*(1LL<<i)+max(0LL,L%(1LL<<(i+1))-(1LL<<i));
		if(val!=b[i])return 0;
	}
	return 1;
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%lld",b+i);
		n=0;
		for(int i=0;i<a;i++)if(b[i])n=i+1;
		bool dame=false;
		for(int i=0;i<n;i++)if(b[i]>1000000000000000000LL)dame=true;
		if(n>60||dame){
			printf("None\n");continue;
		}
		
		for(int i=0;i<n;i++)c[i]=b[i];
		pair<long long,long long>L=make_pair(-1,-1);
		pair<long long,long long>R=make_pair(-1,-1);
		long long tl=1;
		long long tr=(1LL<<(n-1))+c[n-1];
		for(int i=0;i<n-1;i++){
			c[i]-=c[n-1]/(1LL<<(i+1))*(1LL<<i)+max(0LL,c[n-1]%(1LL<<(i+1))-(1LL<<i));
		}
		for(int i=n-2;i>=0;i--){
			if(c[i]<(1LL<<i)){
				tl=(1LL<<(i+1))-c[i];
				break;
			}
			for(int j=0;j<i;j++){
				c[j]-=(1LL<<i)/2;
			}
		}
		//printf("%lld %lld\n",tl,tr);
		if(chk(tl,tr))L=make_pair(tl,tr);
		for(int i=0;i<n;i++)c[i]=b[i];
		long long sz=c[n-1];
		tl=1LL<<(n-1);
		tr=(1LL<<n)-sz;
		for(int i=n-2;i>=0;i--){
			if(c[i]&&c[i]<sz){
				tl+=(1LL<<i)+c[i]-sz;
				break;
			}
			if(c[i]==0){
				tr=tl+(1LL<<i)-sz;
			}else{
				tl+=(1LL<<i);
			}
		}
		
		if(chk(tl,tl+sz))R=make_pair(tl,tl+sz);
		//printf("%lld %lld, %lld %lld\n",L.first,L.second,R.first,R.second);
		if(L.first==-1LL&&R.first==-1LL){
			printf("None\n");
		}else if(L.first!=-1LL&&R.first!=-1LL&&(L.first!=R.first||L.second!=R.second)){
			printf("Many\n");
		}else if(L.first!=-1LL){
			printf("%lld %lld\n",L.first,L.second-1);
		}else{
			printf("%lld %lld\n",R.first,R.second-1);
		}
	}
}
accuracy: 1
time_ms: 1060
memory_kb: 1040
final_rank: 9

code_snippet: #include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

//                  876543210987654321
const long long MX=1000000000000000000ll;

int N;
long long K[64];

long long count(long long x,int id){
	long long a=1ll<<id;
	long long t=(x+1)/a;
//	printf("%lld %d %d\n",x,id,(t/2)*a);
	long long res=(t/2)*a;
	if(t%2==1){
		res+=(x+1)%a;
	}
	return res;
}

long long solve(long long W){
	//[A,A+W-1]
	//return A
	if(W==1){
		long long res=0;
		for(int i=N-1;i>=0;i--){
			if(K[i]==1) res+=(1ll<<i);
		}
		if(res>MX) return -1;
		return res;
	}
	long long A=-1;
	long long tmp=0;
	for(int i=N-1;i>=1;i--){
		if(K[i]==W){
			tmp+=(1ll<<i);
			continue;
		}else if(K[i]==0){
			continue;
		}
		tmp+=(1ll<<i);
		long long zeros=W-K[i];
		tmp-=zeros;
		A=tmp;
		break;
	}
//	if(dbg) printf("A=%lld\n",A);
	if(A==-1){
		A=tmp;
	}
	if(A==0) return -1;
	long long B=A+W-1;
	if(B>MX||A>MX) return -1;
	for(int i=0;i<N;i++){
		long long cur=count(B,i)-count(A-1,i);
		if(K[i]!=cur) return -1;
	}
	return A;
}

void solve(){
	if(N==64&&K[63]>0){
		printf("None\n");
		return;
	}
	if(N==1){
		printf("1 1\n");
		return;
	}
	long long A=-1,B=-1;
	for(long long W=K[0]*2-1;W<=K[0]*2+1;W++){
		long long cand=solve(W);
	//	printf("W=%lld->cand=%lld\n",W,cand);
		if(A!=-1&&cand!=-1){
			printf("Many\n");
			return;
		}
		if(A==-1&&cand!=-1){
			A=cand;
			B=cand+W-1;
		}
	}
	if(A==-1){
		printf("None\n");
		return;
	}
	printf("%lld %lld\n",A,B);
}

int main(){
	while(true){
		scanf("%d",&N);
		if(N==0) break;
		for(int i=0;i<N;i++) scanf("%lld",K+i);
		solve();
	}
	return 0;
}
accuracy: 1
time_ms: 1070
memory_kb: 1040
final_rank: 10

code_snippet: #include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const long long BAR = 1000000000000000000ll;
pair<long long, long long> MANY, NONE;
int n;

inline bool isValid(pair<long long, long long> a) {
    return a != NONE && a != MANY;
}

long long num(int i, long long a) {
    return (a >> (i + 1) << i) + (a >> i & 1) * ((a & ((1ll << i) - 1)) + 1);
}

pair<long long, long long> calc(vector<long long> a) {
    vector<long long> bak = a;
    int n = a.size();
    long long A, B;
    B = (1ll << (n - 1)) + a.back() - 1;
    for (int i = 0; i < n; ++i) {
        a[i] -= num(i, a.back() - 1);
    }
    A = (1ll << (n - 1));
    for (int i = n - 2; i >= 0; --i) {
//cout << "for" << ' ' << i << ' ' << a[i] << endl;
        if (a[i] < 0 || a[i] > (1ll << i)) {
            return NONE;
        }
        if (a[i] < (1ll << i)) {
            A -= a[i];
            break;
        }
        A -= a[i];
        for (int j = 0; j < i; ++j) {
            a[j] -= 1ll << (i - 1);
        }
    }
//cout << A << ' ' << B << endl;
    for (int i = 0; i < n; ++i) {
//cout << "cut" << ' ' << i << ' ' << num(i, B) - num(i, A - 1) << endl;
        if (num(i, B) - num(i, A - 1) != bak[i]) {
            return NONE;
        }
    }
    return make_pair(A, B);
}

vector<pair<long long, long long> > solve(vector<long long> a) {
    vector<pair<long long, long long> > ret;
    if (a.size() == 1) {
        ret.push_back(a.back() ? make_pair(1, 1) : make_pair(0, 0));
        return ret;
    }
    if (a.back() == 0) {
        a.pop_back();
        return solve(a);
    }
    int n = a.size();
    if (a.back() > 1ll << (n - 1)) {
        return ret;
    }
    vector<pair<long long, long long> > tmp, ansg;
    pair<long long, long long> ans;
    ans = calc(a);
    if (isValid(ans)) {
       ansg.push_back(ans);
    }
    long long d = a.back();
    a.pop_back();
    tmp = solve(a);
    for (int i = 0; i < (int)tmp.size(); ++i) {
        ans = tmp[i];
        if (ans.second - ans.first + 1 != d) {
            continue;
        }
        ans.first += 1ll << (n - 1);
        ans.second += 1ll << (n - 1);
        ansg.push_back(ans);
    }
    sort(ansg.begin(), ansg.end());
    ansg.erase(unique(ansg.begin(), ansg.end()), ansg.end());
    return ansg;
}

int main() {
    MANY = make_pair(-1, -1);
    NONE = make_pair(-2, -2);
    while (scanf("%d", &n) == 1 && n) {
        vector<long long> s;
        for (int i = 0; i < n; ++i) {
            long long a;
            scanf("%lld", &a);
            s.push_back(a);
        }
        bool flag = false;
        for (int i = 64; i >= 60; --i) {
            if (n > i && s[i] > 0) {
                flag = true;
            }
        }
        if (flag) {
            printf("None\n");
            continue;
        }
        vector<pair<long long, long long> > ans, tmp = solve(s);
        sort(tmp.begin(), tmp.end());
        tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
        for (int i = 0; i < (int)tmp.size(); ++i) {
            if (tmp[i].second > BAR || tmp[i].first <= 0) {
                continue;
            }
            ans.push_back(tmp[i]);
        }
        if (ans.size() == 0) {
            printf("None\n");
        } else if (ans.size() > 1) {
            printf("Many\n");
        } else {
            printf("%lld %lld\n", ans[0].first, ans[0].second);
        }
    }
    return 0;
}
accuracy: 1
time_ms: 1190
memory_kb: 1256
final_rank: 12

code_snippet: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

ll count(ll X, int p) {
  ll t = (X&~((1LL<<p+1)-1));
  // cout << t << " " << bitset<3>(t) << endl;
  ll res = t/2;
  t |= 1LL<<p;
  res += max(0LL,X-t+1);
  return res;
}

int main() {
  int n;
  while(cin >> n, n) {
    ll k[n];
    REP(i,n) {
      cin >> k[i];
    }
    vector<pair<ll, ll> > ans;
    for (ll w=2*k[0]-1; w<=2*k[0]+1; ++w) {
      bool ng = 0;
      ll A=-1,B=0;
      for (int i=n-1; i>=0; --i) {
        if (k[i] == w) B |= 1LL<<i;
        else if (k[i] == 0) ;
        else if (k[i] > w) ng = 1;
        else {
          B |= 1LL<<i;
          B += k[i]-1;
          A = B-w+1;
          break;
        }
      }
      if (A == -1) {
        if (w != 1) continue;
        A = B;
      }
      if (A<=0 || A>1000000000000000000LL ||
          B<=0 || B>1000000000000000000LL) continue;
      // cout << w << " " << bitset<3>(A) << " " << bitset<3>(B) << " " << ng << endl;
      // cout << count(A-1,0) << endl;
      REP(i,n) {
        ng |= (count(B,i)-count(A-1,i)) != k[i];
      }
      if (!ng) {
        ans.push_back(make_pair(A,B));
      }
    }
    if (ans.size() == 0) puts("None");
    else if (ans.size() > 1) puts("Many");
    else {
      cout << ans[0].first << " " << ans[0].second << endl;
    }
  }
}
accuracy: 1
time_ms: 3170
memory_kb: 1200
final_rank: 18