Problem:
Floating-Point Numbers
In this problem, we consider floating-point number formats, data representation formats to approximate real numbers on computers.
Scientific notation is a method to express a number, frequently used for
numbers too large or too small to be written tersely in usual decimal form.
In scientific notation, all numbers are written in the form
m
× 10
e
.
Here,
m
(called
significand
) is a number
greater than or equal to 1 and less than 10,
and
e
(called
exponent
) is an integer.
For example, a number 13.5 is equal to 1.35 × 10
1
,
so we can express it in scientific notation with significand 1.35 and exponent 1.
As binary number representation is convenient on computers,
let's consider
binary scientific notation
with base two, instead of ten.
In binary scientific notation, all numbers are written in the form
m
× 2
e
.
Since the base is two,
m
is limited to be less than 2.
For example, 13.5 is equal to 1.6875 × 2
3
,
so we can express it in binary scientific notation
with significand 1.6875 and exponent 3.
The significand 1.6875 is equal to 1 + 1/2 + 1/8 + 1/16,
which is 1.1011
2
in binary notation.
Similarly, the exponent 3 can be expressed as 11
2
in binary notation.
A floating-point number expresses a number in binary scientific notation in finite number of bits.
Although the accuracy of the significand and the range of the exponent are limited by the number of bits, we can express numbers in a wide range with reasonably high accuracy.
In this problem, we consider a 64-bit floating-point number format,
simplified from one actually used widely,
in which only those numbers greater than or equal to 1 can be expressed.
Here, the first 12 bits are used for the exponent and the remaining 52 bits for the significand.

Let's denote the 64 bits of a floating-point number by
b
64
...
b
1
.
With
e
an unsigned binary integer
(
b
64
...
b
53
)
2
,
and with
m
a binary fraction represented by the remaining 52 bits
plus one (1.
b
52
...
b
1
)
2
,
the floating-point number represents the number
m
× 2
e
.
We show below the bit string of the representation of 13.5 in the format described above.
In floating-point addition operations, the results have to be approximated by numbers representable in floating-point format.
Here, we assume that the approximation is by truncation.
When the sum of two floating-point numbers
a
and
b
is expressed in binary scientific notation as
a
+
b
=
m
× 2
e
(1 ≤
m
< 2, 0 ≤
e
< 2
12
),
the result of addition operation on them will be a floating-point number with its first 12 bits representing
e
as an unsigned integer
and the remaining 52 bits representing the first 52 bits of the binary fraction of
m
.
A disadvantage of this approximation method is that the approximation error accumulates easily.
To verify this, let's make an experiment of adding a floating-point number many times, as in the pseudocode shown below.
Here,
s
and
a
are floating-point numbers, and the results of individual addition are approximated as describ
...(truncated)

Submitted solutions:

code_snippet: //#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i=0;i<(ll)n;i++)
#define rrep(i,n) for (ll i=n-1;i>=(ll)0;i--)
#define loop(i,m,n) for(ll i=m;i<=(ll)n;i++)
#define rloop(i,m,n) for(ll i=m;i>=(ll)n;i--)
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vdbg(a) rep(ii,a.size()){cout<<a[ii]<<" ";}cout<<endl;
#define vpdbg(a) rep(ii,a.size()){cout<<"{"<<a[ii].first<<","<<a[ii].second<<"} ";}cout<<endl;
#define vvdbg(a) rep(ii,a.size()){rep(jj,a[ii].size()){cout<<a[ii][jj]<<" ";}cout<<endl;}
#define setdbg(a) for(const auto & ii:a){cout<<ii<<" ";}cout<<endl;
#define inf 4000000000000000000LL
#define mod 998244353LL
//#define mod 1000000007LL
#define eps 0.000000001
random_device rnd;// 非決定的な乱数生成器
mt19937 mt(rnd());// メルセンヌ・ツイスタの32ビット版、引数は初期シード

//#include<boost/multiprecision/cpp_int.hpp>
//#define bbi boost::multiprecision::cpp_int
//#include<atcoder/lazysegtree>


//整数同士の累乗の計算をする。
ll power(ll A, ll B) {
	ll result = 1;
	for (ll i=0;i<B;i++){
		result *= A;
	}
	return result;
}

// nのk乗をmodで割った余りを計算
ll power_mod(ll n, ll k){
	long long result = 1;
	while (k > 0){
		if ((k&1) ==1)result=(result*n)%mod;
		n=n*n%mod;
		k >>= 1;
	}
	return result;
}


//受け取った2次元文字の外側に、文字pをコーティングする。
vector<string> pad(vector<string> &s,char p){
	ll h=s.size();
	ll w=s[0].size();
	vector<string> res(h+2,string(w+2,p));
	rep(i,h)rep(j,w)res[i+1][j+1]=s[i][j];
	return res;
}

// Union-Find
struct UnionFind {
	vector<int> par, siz;
	UnionFind(int n) : par(n, -1) , siz(n, 1) { }
	// 根を求める
	int root(int x) {
		if (par[x] == -1) return x;
		else return par[x] = root(par[x]);
	}
	// x と y が同じグループに属するかどうか (根が一致するかどうか)
	bool issame(int x, int y) {
		return root(x) == root(y);
	}
	// x を含むグループと y を含むグループとを併合する
	bool unite(int x, int y) {
		x = root(x), y = root(y);
		if (x == y) return false; 
		if (siz[x] < siz[y]) swap(x, y);
		par[y] = x;
		siz[x] += siz[y];
		return true;
	}
	// x を含むグループのサイズ
	int size(int x) {
		return siz[root(x)];
	}
};


//グリッド問題等用
vl dx={1,0,-1,0};
vl dy={0,1,0,-1};

//受け取った文字列を、第2引数が0なら全て小文字に、1なら大文字に変換する関数
string cnv_string(const string &str, int mode) {
	string result = str;
	if (mode == 0) {
		// 小文字に変換
		for (char &c : result) {
			c = tolower(c);
		}
	} else if (mode == 1) {
		// 大文字に変換
		for (char &c : result) {
			c = toupper(c);
		}
	}
	return result;
}

//第一引数で受け取った数を、第二引数で受け取った数の進数と見做して、第三引数の進数へ変換する。
string cnv_base(const string &str, ll from_base, ll to_base) {
	ll num = 0;
	//小文字があったら大文字に変換
	string num_str=cnv_string(str,1);
	// 数値を10進数に変換
	for (char digit : num_str) {
		num = num * from_base + (isdigit(digit) ? digit - '0' : digit - 'A' + 10);
	}
	string result;
	// 数値を目的の基数に変換
	while (num > 0) {
		ll remainder = num % to_base;
		result.push_back(remainder < 10 ? remainder + '0' : remainder - 10 + 'A');
		num /= to_base;
	}
	// 結果を逆順にして返す
	reverse(result.begin(), result.end());
	return result.empty() ? "0" : result;
}

string b;

//b×nを計算
string muls(ll n){
	ll bint=stoll(cnv_base(b,2,10));
	ll ans=n*bint;
	return cnv_base(to_string(ans),10,2);
}
string pluss(string x,string y){
	ll ans=stoll(cnv_base(x,2,10))+stoll(cnv_base(y,2,10));
	return cnv_base(to_string(ans),10,2);
}

ll solve(){
	ll n;
	cin>>n;
	if(n==0){return 1;}

	cin>>b;
	b.insert(b.begin(),'1');

	ll kasuu=0;
	string ans=b;
	
	while(n!=0){
		ll mn=1,mx=min(n,1LL<<(54-b.size()));

		while(mn!=mx){
			ll mid=mn+mx;
			mid/=2;
			string s=pluss(ans,muls(mid));
			if(s.size()==54)mx=mid;
			else mn=mid+1;
		}

		ans=pluss(ans,muls(mx));
		n-=mx;
		if(ans.size()==53){
			break;
		}

		ans.pop_back();
		b.pop_back();
		if(b.size()==0)b="0";
		kasuu++;
	}
	string ans1 = cnv_base(to_string(kasuu),10,2);
	while(ans1.size()!=12)ans1.insert(ans1.begin(),'0');

	cout<<ans1;
	loop(i,1,52)cout<<ans[i];
	cout<<endl;
	return 0;
}

//メイン
int main(){
	while(solve()==0);
	return 0;
}
accuracy: 1
time_ms: 660
memory_kb: 3456
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
template <class T, class U>
inline bool chmax(T &a, U b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T, class U>
inline bool chmin(T &a, U b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline void compress(vector<T> &a) {
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
}
template <class T>
T rand(T l, T r) {
    static mt19937 mt(random_device{}());
    // [l, r)
    if constexpr (is_integral_v<T>) {
        return uniform_int_distribution<T>(l, r - 1)(mt);
    } else if constexpr (is_floating_point_v<T>) {
        return uniform_real_distribution<T>(l, r)(mt);
    }
}
constexpr int INF = 1001001001;
constexpr ll llINF = 3000000000000000010;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using pbds_set = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
using pbds_mset = tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>;
using pbds_umap = gp_hash_table<int, int>;
using pbds_trie = trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update>;
struct linear_sieve {
    vector<int> least_factor, prime_list;
    linear_sieve(int n) : least_factor(n + 1, 0) {
        for (int i = 2; i <= n; i++) {
            if (least_factor[i] == 0) {
                least_factor[i] = i;
                prime_list.push_back(i);
            }
            for (int p : prime_list) {
                if (ll(i) * p > n || p > least_factor[i]) break;
                least_factor[i * p] = p;
            }
        }
    }
};
template <int modulo>
struct modint {
    int x;
    modint() : x(0) {}
    modint(int64_t y) : x(y >= 0 ? y % modulo : (modulo - (-y) % modulo) % modulo) {}
    modint &operator+=(const modint &p) {
        if ((x += p.x) >= modulo) x -= modulo;
        return *this;
    }
    modint &operator-=(const modint &p) {
        if ((x += modulo - p.x) >= modulo) x -= modulo;
        return *this;
    }
    modint &operator*=(const modint &p) {
        x = (int)(1LL * x * p.x % modulo);
        return *this;
    }
    modint &operator/=(const modint &p) {
        *this *= p.inv();
        return *this;
    }
    modint operator-() const { return modint(-x); }
    modint operator+(const modint &p) const { return modint(*this) += p; }
    modint operator-(const modint &p) const { return modint(*this) -= p; }
    modint operator*(const modint &p) const { return modint(*this) *= p; }
    modint operator/(const modint &p) const { return modint(*this) /= p; }
    bool operator==(const modint &p) const { return x == p.x; }
    bool operator!=(const modint &p) const { return x != p.x; }
    modint inv() const {
        int a = x, b = modulo, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return modint(u);
    }
    modint pow(int64_t n) const {
        modint ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const modint &p) { return os << p.x; }
    friend istream &operator>>(istream &is, modint &a) {
        int64_t t;
        is >> t;
        a = modint<modulo>(t);
        return (is);
    }
    int val() const { return x; }
    static constexpr int mod() { return modulo; }
    static constexpr int half() { return (modulo + 1) >> 1; }
};
ll extgcd(ll a, ll b, ll &x, ll &y) {
    // ax+by=gcd(|a|,|b|)
    if (a < 0 || b < 0) {
        ll d = extgcd(abs(a), abs(b), x, y);
        if (a < 0) x = -x;
        if (b < 0) y = -y;
        return d;
    }
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
template <typename T>
struct Binomial {
    vector<T> inv, fact, factinv;
    Binomial(int n) {
        inv.resize(n + 1);
        fact.resize(n + 1);
        factinv.resize(n + 1);
        inv[0] = fact[0] = factinv[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i;
        factinv[n] = fact[n].inv();
        inv[n] = fact[n - 1] * factinv[n];
        for (int i = n - 1; i >= 1; i--) {
            factinv[i] = factinv[i + 1] * (i + 1);
            inv[i] = fact[i - 1] * factinv[i];
        }
    }
    T C(int n, int r) {
        if (n < 0 || n < r || r < 0) return 0;
        return fact[n] * factinv[n - r] * factinv[r];
    }
    T P(int n, int r) {
        if (n < 0 || n < r || r < 0) return 0;
        return fact[n] * factinv[n - r];
    }
    T H(int n, int r) {
        if (n == 0 && r == 0) return 1;
        if (n < 0 || r < 0) return 0;
        return r == 0 ? 1 : C(n + r - 1, r);
    }
};
template <class T>
struct Matrix {
    vector<vector<T>> m;
    Matrix() = default;
    Matrix(int x) : m(vector(x, vector<T>(x, 0))) {}
    Matrix(const vector<vector<T>> &a) : m(a) {}
    vector<T> &operator[](int i) { return m[i]; }
    const vector<T> &operator[](int i) const { return m[i]; }
    static Matrix identity(int x) {
        Matrix res(x);
        for (int i = 0; i < x; i++) res[i][i] = 1;
        return res;
    }
    static Matrix zero(int x) { return Matrix(x); }

    Matrix operator+() const { return (*this); }
    Matrix operator-() const { return Matrix(this->m.size()) - (*this); }
    Matrix operator+(const Matrix &a) const {
        Matrix x = (*this);
        return x += a;
    }
    Matrix operator-(const Matrix &a) const {
        Matrix x = (*this);
        return x -= a;
    }
    Matrix operator*(const Matrix &a) const {
        Matrix x = (*this);
        return x *= a;
    }
    Matrix operator*(const T &a) const {
        Matrix x = (*this);
        return x *= a;
    }
    Matrix &operator+=(const Matrix &a) {
        int n = m.size();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                m[i][j] += a[i][j];
            }
        }
        return *this;
    }
    Matrix &operator-=(const Matrix &a) {
        int n = m.size();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                m[i][j] -= a[i][j];
            }
        }
        return *this;
    }
    Matrix &operator*=(const Matrix &a) {
        int n = m.size();
        Matrix res(n);
        for (int i = 0; i < n; i++) {
            for (int k = 0; k < n; k++) {
                for (int j = 0; j < n; j++) {
                    res[i][j] += m[i][k] * a[k][j];
                }
            }
        }
        m = res.m;
        return *this;
    }
    Matrix &operator*=(const T &a) {
        int n = m.size();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                m[i][j] *= a;
            }
        }
        return *this;
    }
    Matrix pow(ll b) const {
        Matrix x = *this, res = identity(x.m.size());
        while (b) {
            if (b & 1) {
                res *= x;
            }
            x *= x;
            b >>= 1;
        }
        return res;
    }
    T determinant() {
        int n = m.size();
        Matrix A(*this);
        T ret = 1;
        for (int i = 0; i < n; i++) {
            int pivot = -1;
            for (int j = i; j < n; j++) {
                if (A[j][i] != 0) pivot = j;
            }
            if (pivot == -1) return T(0);
            if (i != pivot) {
                ret *= -1;
                swap(A[i], A[pivot]);
            }
            ret *= A[i][i];
            T tmp = T(1) / A[i][i];
            for (int j = 0; j < n; j++) {
                A[i][j] *= tmp;
            }
            for (int j = i + 1; j < n; j++) {
                T a = A[j][i];
                for (int k = 0; k < n; k++) {
                    A[j][k] -= A[i][k] * a;
                }
            }
        }
        return ret;
    }
    Matrix inverse() {
        assert(determinant() != 0);
        int n = m.size();
        Matrix ret = identity(n);
        Matrix A(*this);
        for (int i = 0; i < n; i++) {
            int pivot = -1;
            for (int j = i; j < n; j++) {
                if (A[j][i] != 0) pivot = j;
            }
            if (i != pivot) {
                swap(ret[i], ret[pivot]);
                swap(A[i], A[pivot]);
            }
            T tmp = T(1) / A[i][i];
            for (int j = 0; j < n; j++) {
                A[i][j] *= tmp;
                ret[i][j] *= tmp;
            }
            for (int j = 0; j < n; j++) {
                if (j == i) continue;
                T a = A[j][i];
                for (int k = 0; k < n; k++) {
                    A[j][k] -= A[i][k] * a;
                    ret[j][k] -= ret[i][k] * a;
                }
            }
        }
        return ret;
    }
    vector<T> characteristic_polynomial() {
        int n = m.size();
        if (n == 0) return {1};
        Matrix A(*this);
        for (int i = 1; i < n; i++) {
            int pivot = -1;
            for (int j = i; j < n; j++) {
                if (A[j][i - 1] != 0) pivot = j;
            }
            if (pivot == -1) continue;
            if (i != pivot) {
                swap(A[i], A[pivot]);
                for (int j = 0; j < n; j++) swap(A[j][i], A[j][pivot]);
            }
            T tmp = T(1) / A[i][i - 1];
            vector<T> c(n);
            for (int j = i + 1; j < n; j++) c[j] = tmp * A[j][i - 1];
            for (int j = i + 1; j < n; j++) {
                for (int k = i - 1; k < n; k++) {
                    A[j][k] -= A[i][k] * c[j];
                }
            }
            for (int j = 0; j < n; j++) {
                for (int k = i + 1; k < n; k++) {
                    A[j][i] += A[j][k] * c[k];
                }
            }
        }
        vector dp(n + 1, vector<T>(n + 1));
        dp[0][0] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= i; j++) {
                dp[i + 1][j] -= dp[i][j] * A[i][i];
                dp[i + 1][j + 1] += dp[i][j];
            }
            T p = 1;
            for (int k = i + 1; k < n; k++) {
                p *= A[k][k - 1];
                for (int j = 0; j <= i; j++) dp[k + 1][j] -= dp[i][j] * p * A[i][k];
            }
        }
        return dp[n];
    }
    friend ostream &operator<<(ostream &os, const Matrix &a) {
        int n = a.m.size();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                os << a[i][j];
                if (j != n - 1) os << " ";
            }
            os << "\n";
        }
        return os;
    }
    friend istream &operator>>(istream &is, Matrix &a) {
        int n = a.m.size();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                is >> a[i][j];
            }
        }
        return is;
    }
};

template <class T, T (*op)(T, T), T (*e)()>
struct disjointsparsetable {
    vector<vector<T>> table;
    vector<int> logtable;
    disjointsparsetable() = default;
    disjointsparsetable(vector<T> v) {
        int len = 0;
        while ((1 << len) <= v.size()) len++;
        table.assign(len, vector<T>(1 << len, e()));
        for (int i = 0; i < (int)v.size(); i++) table[0][i] = v[i];
        for (int i = 1; i < len; i++) {
            int shift = 1 << i;
            for (int j = 0; j < (int)v.size(); j += shift << 1) {
                int t = min(j + shift, (int)v.size());
                table[i][t - 1] = v[t - 1];
                for (int k = t - 2; k >= j; k--) table[i][k] = op(v[k], table[i][k + 1]);
                if (v.size() <= t) break;
                table[i][t] = v[t];
                int r = min(t + shift, (int)v.size());
                for (int k = t + 1; k < r; k++) table[i][k] = op(table[i][k - 1], v[k]);
            }
        }
        logtable.resize(1 << len);
        for (int i = 2; i < logtable.size(); i++) {
            logtable[i] = logtable[(i >> 1)] + 1;
        }
    }
    T query(int l, int r) {
        if (l == r) return e();
        if (l >= --r) return table[0][l];
        int len = logtable[l ^ r];
        return op(table[len][l], table[len][r]);
    };
};
using mint = modint<998244353>;
void solve() {
    ll n;
    cin >> n;
    if (n == 0) exit(0);
    string s;
    cin >> s;
    // 52 digits
    // 2^a*(1.b)で表現
    // 2^0*(1.s) = 2^a*(1.s/2^a)
    auto xcd = [&](string b, string t, int k) {
        if (51 - k < (int)t.size() - 1) {
            return true;
        }
        // 0.b+t*2^k>=1?
        vector<int> v(52);
        rep(i, 52) v[i] = b[i] - '0';
        rep(i, t.size()) {
            if (t[t.size() - 1 - i] == '1') {
                v[51 - k - i]++;
            }
        }
        for (int i = 51; i >= 0; i--) {
            if (v[i] >= 2) {
                v[i] -= 2;
                if (i == 0) {
                    return true;
                }
                v[i - 1]++;
            }
        }
        return false;
    };
    auto add = [&](string &b, string t, int k) {
        vector<int> v(52);
        rep(i, 52) v[i] = b[i] - '0';
        rep(i, t.size()) {
            if (t[t.size() - 1 - i] == '1') {
                v[51 - k - i]++;
            }
        }
        for (int i = 51; i >= 0; i--) {
            if (v[i] >= 2) {
                v[i] -= 2;
                assert(i);
                v[i - 1]++;
            }
        }
        rep(i, 52) b[i] = ('0' + v[i]);
    };
    auto add_carry = [&](string &b, string t) {
        vector<int> v(52);
        rep(i, 52) v[i] = b[i] - '0';
        rep(i, t.size()) {
            if (t[t.size() - 1 - i] == '1') {
                v[51 - i]++;
            }
        }
        for (int i = 51; i >= 0; i--) {
            if (v[i] >= 2) {
                v[i] -= 2;
                if (i) v[i - 1]++;
            }
        }
        rep(i, 52) b[i] = ('0' + v[i]);
        // 2.b
        b = "0" + b;
        b.pop_back();
    };
    int a = 1;
    string b = s;
    n--;
    while (n) {
        string t = "1" + s;
        if (t.size() <= a) break;
        rep(_, a) t.pop_back();
        // 繰り上がるまでに何回足す？
        for (int i = 60; i >= 0; i--) {
            if (n >> i) {
                if (!xcd(b, t, i)) {
                    add(b, t, i);
                    n -= 1LL << i;
                }
            }
        }
        if (n) {
            n--;
            add_carry(b, t);
            a++;
        }
    }
    for (int i = 11; i >= 0; i--) {
        cout << ((a >> i) & 1);
    }
    cout << b << endl;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while (1) solve();
}
accuracy: 1
time_ms: 140
memory_kb: 3400
final_rank: 9

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

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

template <unsigned mod = 1000000007> struct fp {
    unsigned v;
    static constexpr int get_mod() {
        return mod;
    }
    constexpr unsigned inv() const {
        assert(v != 0);
        int x = v, y = mod, p = 1, q = 0, t = 0, tmp = 0;
        while (y > 0) {
            t = x / y;
            x -= t * y, p -= t * q;
            tmp = x, x = y, y = tmp;
            tmp = p, p = q, q = tmp;
        }
        if (p < 0)
            p += mod;
        return p;
    }
    constexpr fp(ll x = 0) : v(x >= 0 ? x % mod : (mod - (-x) % mod) % mod) {}
    fp operator-() const {
        return fp() - *this;
    }
    fp pow(ull t) {
        fp res = 1, b = *this;
        while (t) {
            if (t & 1)
                res *= b;
            b *= b;
            t >>= 1;
        }
        return res;
    }
    fp &operator+=(const fp &x) {
        if ((v += x.v) >= mod)
            v -= mod;
        return *this;
    }
    fp &operator-=(const fp &x) {
        if ((v += mod - x.v) >= mod)
            v -= mod;
        return *this;
    }
    fp &operator*=(const fp &x) {
        v = ull(v) * x.v % mod;
        return *this;
    }
    fp &operator/=(const fp &x) {
        v = ull(v) * x.inv() % mod;
        return *this;
    }
    fp operator+(const fp &x) const {
        return fp(*this) += x;
    }
    fp operator-(const fp &x) const {
        return fp(*this) -= x;
    }
    fp operator*(const fp &x) const {
        return fp(*this) *= x;
    }
    fp operator/(const fp &x) const {
        return fp(*this) /= x;
    }
    bool operator==(const fp &x) const {
        return v == x.v;
    }
    bool operator!=(const fp &x) const {
        return v != x.v;
    }
    friend istream &operator>>(istream &is, fp &x) {
        return is >> x.v;
    }
    friend ostream &operator<<(ostream &os, const fp &x) {
        return os << x.v;
    }
};

template <unsigned mod> void rd(fp<mod> &x) {
    fastio::rd(x.v);
}
template <unsigned mod> void wt(fp<mod> x) {
    fastio::wt(x.v);
}

template <typename T> T Inv(ll n) {
    static const int md = T::get_mod();
    static vector<T> buf({0, 1});
    assert(n > 0);
    n %= md;
    while (SZ(buf) <= n) {
        int k = SZ(buf), q = (md + k - 1) / k;
        buf.push_back(buf[k * q - md] * q);
    }
    return buf[n];
}

template <typename T> T Fact(ll n, bool inv = 0) {
    static const int md = T::get_mod();
    static vector<T> buf({1, 1}), ibuf({1, 1});
    assert(n >= 0 and n < md);
    while (SZ(buf) <= n) {
        buf.push_back(buf.back() * SZ(buf));
        ibuf.push_back(ibuf.back() * Inv<T>(SZ(ibuf)));
    }
    return inv ? ibuf[n] : buf[n];
}

template <typename T> T nPr(int n, int r, bool inv = 0) {
    if (n < 0 || n < r || r < 0)
        return 0;
    return Fact<T>(n, inv) * Fact<T>(n - r, inv ^ 1);
}
template <typename T> T nCr(int n, int r, bool inv = 0) {
    if (n < 0 || n < r || r < 0)
        return 0;
    return Fact<T>(n, inv) * Fact<T>(r, inv ^ 1) * Fact<T>(n - r, inv ^ 1);
}
template <typename T> T nHr(int n, int r, bool inv = 0) {
    return nCr<T>(n + r - 1, r, inv);
}

/**
 * @brief Modint
 */

int main() {
while(1) {
    ll _;
    cin >> _;
    if (_ == 0) return 0;
    ll A = _;
    string S;
    cin >> S;
    ll B = (1LL<<52);
    rep(i,0,52) {
        if (S[i] == '1') B += (1LL<<(51-i));
    }
    ll MAX = 1LL<<53, Cur = B;
    rep(i,0,100) {
        ll OK = 0, NG = A+1;
        while(NG - OK > 1) {
            ll MID = (NG + OK) / 2;
            if (B == 0) OK = MID;
            else if ((MAX * 2 - Cur) / B <= MID) NG = MID;
            else if (Cur + B * MID >= MAX) NG = MID;
            else OK = MID;
        }
        if (OK == A) {
            Cur += B * A;
            rep(j,0,12) {
                if ((i & (1<<(11-j))) == 0) cout << '0';
                else cout << '1';
            }
            vector<int> R(52,0);
            rep(j,0,52) {
                if (Cur % 2 == 1) R[j] = 1;
                Cur /= 2;
            }
            rep(j,0,52) {
                if (R[51-j] == 0) cout << '0';
                else cout << '1';
            }
            cout << endl;
            break;
        }
        A -= NG;
        Cur += B * NG;
        Cur /= 2;
        B /= 2;
    }
}
}
accuracy: 1
time_ms: 10
memory_kb: 3496
final_rank: 12

code_snippet: #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#ifdef RUTHEN_LOCAL
#include <debug.hpp>
#else
#define show(x) true
#endif

// type definition
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using f32 = float;
using f64 = double;
using f128 = long double;
template <class T> using pque = std::priority_queue<T>;
template <class T> using pqueg = std::priority_queue<T, std::vector<T>, std::greater<T>>;
// overload
#define overload4(_1, _2, _3, _4, name, ...) name
#define overload3(_1, _2, _3, name, ...) name
#define overload2(_1, _2, name, ...) name
// for loop
#define REP1(a) for (long long _ = 0; _ < (a); _++)
#define REP2(i, a) for (long long i = 0; i < (a); i++)
#define REP3(i, a, b) for (long long i = (a); i < (b); i++)
#define REP4(i, a, b, c) for (long long i = (a); i < (b); i += (c))
#define REP(...) overload4(__VA_ARGS__, REP4, REP3, REP2, REP1)(__VA_ARGS__)
#define RREP1(a) for (long long _ = (a)-1; _ >= 0; _--)
#define RREP2(i, a) for (long long i = (a)-1; i >= 0; i--)
#define RREP3(i, a, b) for (long long i = (b)-1; i >= (a); i--)
#define RREP(...) overload3(__VA_ARGS__, RREP3, RREP2, RREP1)(__VA_ARGS__)
#define FORE1(x, a) for (auto&& x : a)
#define FORE2(x, y, a) for (auto&& [x, y] : a)
#define FORE3(x, y, z, a) for (auto&& [x, y, z] : a)
#define FORE(...) overload4(__VA_ARGS__, FORE3, FORE2, FORE1)(__VA_ARGS__)
#define FORSUB(t, s) for (long long t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
// function
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(a) std::sort((a).begin(), (a).end())
#define RSORT(a) std::sort((a).rbegin(), (a).rend())
#define REV(a) std::reverse((a).begin(), (a).end())
#define UNIQUE(a)                      \
    std::sort((a).begin(), (a).end()); \
    (a).erase(std::unique((a).begin(), (a).end()), (a).end())
#define LEN(a) (int)((a).size())
#define MIN(a) *std::min_element((a).begin(), (a).end())
#define MAX(a) *std::max_element((a).begin(), (a).end())
#define SUM1(a) std::accumulate((a).begin(), (a).end(), 0LL)
#define SUM2(a, x) std::accumulate((a).begin(), (a).end(), (x))
#define SUM(...) overload2(__VA_ARGS__, SUM2, SUM1)(__VA_ARGS__)
#define LB(a, x) std::distance((a).begin(), std::lower_bound((a).begin(), (a).end(), (x)))
#define UB(a, x) std::distance((a).begin(), std::upper_bound((a).begin(), (a).end(), (x)))
template <class T, class U> inline bool chmin(T& a, const U& b) { return (a > T(b) ? a = b, 1 : 0); }
template <class T, class U> inline bool chmax(T& a, const U& b) { return (a < T(b) ? a = b, 1 : 0); }
template <class T, class S> inline T floor(const T x, const S y) {
    assert(y);
    return (y < 0 ? floor(-x, -y) : (x > 0 ? x / y : x / y - (x % y == 0 ? 0 : 1)));
}
template <class T, class S> inline T ceil(const T x, const S y) {
    assert(y);
    return (y < 0 ? ceil(-x, -y) : (x > 0 ? (x + y - 1) / y : x / y));
}
template <class T, class S> std::pair<T, T> inline divmod(const T x, const S y) {
    T q = floor(x, y);
    return {q, x - q * y};
}
// 10 ^ n
constexpr long long TEN(int n) { return (n == 0) ? 1 : 10LL * TEN(n - 1); }
// 1 + 2 + ... + n
#define TRI1(n) ((n) * ((n) + 1LL) / 2)
// l + (l + 1) + ... + r
#define TRI2(l, r) (((l) + (r)) * ((r) - (l) + 1LL) / 2)
#define TRI(...) overload2(__VA_ARGS__, TRI2, TRI1)(__VA_ARGS__)
// bit operation
// bit[i] (= 0 or 1)
#define IBIT(bit, i) (((bit) >> (i)) & 1)
// (0, 1, 2, 3, 4) -> (0, 1, 3, 7, 15)
#define MASK(n) ((1LL << (n)) - 1)
#define POW2(n) (1LL << (n))
// (0, 1, 2, 3, 4) -> (0, 1, 1, 2, 1)
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(i64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(i64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
// binary search
template <class T, class F> T bin_search(T ok, T ng, F& f) {
    while ((ok > ng ? ok - ng : ng - ok) > 1) {
        T md = (ng + ok) >> 1;
        (f(md) ? ok : ng) = md;
    }
    return ok;
}
template <class T, class F> T bin_search_real(T ok, T ng, F& f, const int iter = 100) {
    for (int _ = 0; _ < iter; _++) {
        T md = (ng + ok) / 2;
        (f(md) ? ok : ng) = md;
    }
    return ok;
}
// rotate matrix counterclockwise by pi / 2
template <class T> void rot(std::vector<std::vector<T>>& a) {
    if ((int)(a.size()) == 0) return;
    if ((int)(a[0].size()) == 0) return;
    int n = (int)(a.size()), m = (int)(a[0].size());
    std::vector res(m, std::vector<T>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            res[m - 1 - j][i] = a[i][j];
        }
    }
    a.swap(res);
}
// const value
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// infinity
template <class T> constexpr T INF = 0;
template <> constexpr int INF<int> = 1'000'000'000;                 // 1e9
template <> constexpr i64 INF<i64> = i64(INF<int>) * INF<int> * 2;  // 2e18
template <> constexpr u32 INF<u32> = INF<int>;                      // 1e9
template <> constexpr u64 INF<u64> = INF<i64>;                      // 2e18
template <> constexpr f32 INF<f32> = INF<i64>;                      // 2e18
template <> constexpr f64 INF<f64> = INF<i64>;                      // 2e18
template <> constexpr f128 INF<f128> = INF<i64>;                    // 2e18
// I/O
// input
template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    for (auto&& i : v) is >> i;
    return is;
}
template <class... T> void in(T&... a) { (std::cin >> ... >> a); }
void scan() {}
template <class Head, class... Tail> void scan(Head& head, Tail&... tail) {
    in(head);
    scan(tail...);
}
// input macro
#define INT(...)     \
    int __VA_ARGS__; \
    scan(__VA_ARGS__)
#define I64(...)     \
    i64 __VA_ARGS__; \
    scan(__VA_ARGS__)
#define U32(...)     \
    u32 __VA_ARGS__; \
    scan(__VA_ARGS__)
#define U64(...)     \
    u64 __VA_ARGS__; \
    scan(__VA_ARGS__)
#define F32(...)     \
    f32 __VA_ARGS__; \
    scan(__VA_ARGS__)
#define F64(...)     \
    f64 __VA_ARGS__; \
    scan(__VA_ARGS__)
#define F128(...)     \
    f128 __VA_ARGS__; \
    scan(__VA_ARGS__)
#define STR(...)             \
    std::string __VA_ARGS__; \
    scan(__VA_ARGS__)
#define CHR(...)      \
    char __VA_ARGS__; \
    scan(__VA_ARGS__)
#define VEC(type, name, size)     \
    std::vector<type> name(size); \
    scan(name)
#define VEC2(type, name1, name2, size)          \
    std::vector<type> name1(size), name2(size); \
    for (int i = 0; i < size; i++) scan(name1[i], name2[i])
#define VEC3(type, name1, name2, name3, size)                \
    std::vector<type> name1(size), name2(size), name3(size); \
    for (int i = 0; i < size; i++) scan(name1[i], name2[i], name3[i])
#define VEC4(type, name1, name2, name3, name4, size)                      \
    std::vector<type> name1(size), name2(size), name3(size), name4(size); \
    for (int i = 0; i < size; i++) scan(name1[i], name2[i], name3[i], name4[i])
#define VV(type, name, h, w)                       \
    std::vector name((h), std::vector<type>((w))); \
    scan(name)
// output
template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    auto n = v.size();
    for (size_t i = 0; i < n; i++) {
        if (i) os << ' ';
        os << v[i];
    }
    return os;
}
template <class... T> void out(const T&... a) { (std::cout << ... << a); }
void print() { out('\n'); }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
    out(head);
    if (sizeof...(Tail)) out(' ');
    print(tail...);
}
// for interactive problems
void printi() { std::cout << std::endl; }
template <class Head, class... Tail> void printi(Head&& head, Tail&&... tail) {
    out(head);
    if (sizeof...(Tail)) out(' ');
    printi(tail...);
}
// bool output
void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void NO(bool t = 1) { YES(!t); }
void No(bool t = 1) { Yes(!t); }
void no(bool t = 1) { yes(!t); }
void POSSIBLE(bool t = 1) { print(t ? "POSSIBLE" : "IMPOSSIBLE"); }
void Possible(bool t = 1) { print(t ? "Possible" : "Impossible"); }
void possible(bool t = 1) { print(t ? "possible" : "impossible"); }
void IMPOSSIBLE(bool t = 1) { POSSIBLE(!t); }
void Impossible(bool t = 1) { Possible(!t); }
void impossible(bool t = 1) { possible(!t); }
void FIRST(bool t = 1) { print(t ? "FIRST" : "SECOND"); }
void First(bool t = 1) { print(t ? "First" : "Second"); }
void first(bool t = 1) { print(t ? "first" : "second"); }
void SECOND(bool t = 1) { FIRST(!t); }
void Second(bool t = 1) { First(!t); }
void second(bool t = 1) { first(!t); }
// I/O speed up
struct SetUpIO {
    SetUpIO() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        std::cout << std::fixed << std::setprecision(15);
    }
} set_up_io;
// #include "math/divisor.hpp"
using namespace std;

void solve(i64 N) {
    STR(S);
    using Num = pair<int, string>;

    auto add = [](Num a, Num b, i64& addnum) -> Num {
        deque<int> qa, qb;
        REP(i, LEN(a.second)) qa.push_back(a.second[i] - '0');
        REP(i, LEN(b.second)) qb.push_back(b.second[i] - '0');
        qa.push_front(1);
        qb.push_front(1);
        int emax = max(a.first, b.first);
        int da = emax - a.first;
        int db = emax - b.first;
        assert(da == 0);
        REP(db) qb.push_front(0);
        while (LEN(qb) > 53) qb.pop_back();
        show(qa);
        show(qb);

        i64 n = 1;
        int ok = 1;
        {
            int carry = 0;
            RREP(i, 53) {
                int s = qa[i] + qb[i] + carry;
                carry = s / 2;
            }
            ok &= carry == 0;
        }
        while (addnum >= 2 * n and ok) {
            qb.push_back(0);
            int memo = qb.front();
            qb.pop_front();
            // check
            int carry = 0;
            RREP(i, 53) {
                int s = qa[i] + qb[i] + carry;
                carry = s / 2;
            }
            // ok
            if (carry == 0) {
                n *= 2;
            } else {
                // rollback
                qb.push_front(memo);
                qb.pop_back();
                break;
            }
        }

        int carry = 0;
        deque<int> sum;
        RREP(i, 53) {
            int s = qa[i] + qb[i] + carry;
            sum.push_front(s % 2);
            carry = s / 2;
        }
        show(qa);
        show(qb);
        show(sum);
        if (carry == 1) {
            sum.push_front(1);
            emax++;
            sum.pop_back();
        }
        sum.pop_front();
        string ans;
        REP(i, 52) ans += sum[i] + '0';
        addnum -= n;
        return {emax, ans};
    };

    Num a = {0, S};
    Num s = a;
    while (N > 0) {
        s = add(s, a, N);
        show(s);
        show(N);
    }
    // print(s);
    string ans;
    RREP(i, 12) ans += '0' + IBIT(s.first, i);
    ans += s.second;
    print(ans);
    return;
}

int main() {
    i64 N;
    while (cin >> N, N != 0) solve(N);
    return 0;
}
accuracy: 1
time_ms: 700
memory_kb: 3412
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define mat vector<vector<ll>>
const int inf = 1 << 30;
const ll mod = 1e9 + 7;
const ll linf = 1e18;
const db EPS = 1e-10;
const db pi = acos(-1);
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

ll n;
string culc(string x, string y) {
    string ex = x.substr(0, 12);
    string ey = y.substr(0, 12);
    bool flag = true;
    if (stoi(ex, 0, 2) > stoi(ey, 0, 2)) {
        flag = false;
        swap(x, y);
        swap(ex, ey);
    }
    string mx = x.substr(12, 52);
    mx = "1" + mx;
    string my = y.substr(12, 52);
    my = "1" + my;
    int a = stoi(ex, 0, 2), b = stoi(ey, 0, 2), c = b - a;
    if (c > 52) {
        return "";
    } else {
        for (int i = 52; i - c >= 0; i--) {
            mx[i] = mx[i - c];
        }
        for (int i = 0; i < c; i++) {
            mx[i] = '0';
        }
    }

    ll d = stoll(mx, 0, 2), e = stoll(my, 0, 2);

    if (flag) {
        n--;
    } else {
        ll q = ((1ll << 53) - e) / d;
        ll r = ((1ll << 53) - e) % d;
        if (r != 0) q++;
        q = min(n, q);
        d *= q;
        n -= q;
    }
    ll f = d + e;
    if (f >> 53 & 1ll) {
        c++;
        f /= 2;
    }
    bitset<52> bs2(f);
    string mz = bs2.to_string();
    bitset<12> bs1(c + a);
    string ez = bs1.to_string();
    string z = ez + mz;
    return z;
}

void solve() {
    string b;
    cin >> b;
    string e = "000000000000";
    b = e + b;
    string a = b;
    while (n > 0) {
        string c = culc(a, b);
        if (c == "") break;
        a = c;
    }
    cout << a << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    while (true) {
        cin >> n;
        if (n == 0) break;
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3384
final_rank: 8

code_snippet: #include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;
class FloatingPointNumber
{
public:
    ll exp;
    vector<int> fraction;
    FloatingPointNumber(int size = 52)
    {
        exp = 0;
        fraction.assign(size, 0);
    }
    void print()
    {
        string binary = bitset<12>(exp).to_string();
        cout << binary;
        for (int i = 1; i < fraction.size(); i++)
        {
            cout << fraction[i];
        }
        cout << endl;
    }
};

bool check(FloatingPointNumber a, FloatingPointNumber b)
{
    int carry = 0;
    int pos = b.fraction.size() - 1;
    // cerr << "@@@@@@@" << endl;
    // a.print();
    // b.print();
    for (int i = a.fraction.size() - 1; i >= 0; i--, pos--)
    {

        b.fraction.at(pos) += a.fraction.at(i);
        b.fraction.at(pos) += carry;
        if (b.fraction.at(pos) >= 2)
        {
            b.fraction.at(pos) -= 2;
            carry = 1;
        }
        else
        {
            carry = 0;
        }
    }
    //    cerr << carry << " " << pos << endl;
    for (; pos >= 0; pos--)
    {
        b.fraction.at(pos) += carry;
        if (b.fraction.at(pos) >= 2)
        {
            b.fraction.at(pos) -= 2;
            carry = 1;
        }
        else
        {
            carry = 0;
        }
    }
    return carry == 0;
}

void add(FloatingPointNumber &b, FloatingPointNumber a, ll &m)
{
    if (a.exp > b.exp)
    {
        swap(a, b);
    }
    while (!a.fraction.empty() && a.exp < b.exp)
    {
        a.fraction.pop_back();
        a.exp++;
    }
    if (a.fraction.empty())
    {
        return;
    }
    m--;
    ll cost = 1;
    while (m > 0 && a.fraction.size() < 53 && check(a, b))
    {
        if (cost <= m)
        {
            m -= cost;
            a.fraction.push_back(0);
            cost *= 2;
            if (check(a, b) == false)
            {
                cost /= 2;
                m += cost;
                a.fraction.pop_back();
                break;
            }
        }
        else
        {
            break;
        }
    }

    int carry = 0;
    int pos = b.fraction.size() - 1;
    // cerr << "@@@@@@@" << endl;
    // a.print();
    // b.print();
    for (int i = a.fraction.size() - 1; i >= 0; i--, pos--)
    {

        b.fraction.at(pos) += a.fraction.at(i);
        b.fraction.at(pos) += carry;
        if (b.fraction.at(pos) >= 2)
        {
            b.fraction.at(pos) -= 2;
            carry = 1;
        }
        else
        {
            carry = 0;
        }
    }
    //    cerr << carry << " " << pos << endl;
    for (; pos >= 0; pos--)
    {
        b.fraction.at(pos) += carry;
        if (b.fraction.at(pos) >= 2)
        {
            b.fraction.at(pos) -= 2;
            carry = 1;
        }
        else
        {
            carry = 0;
        }
    }

    if (carry == 1)
    {
        b.exp++;
        b.fraction.insert(b.fraction.begin(), 1);
        b.fraction.pop_back();
        assert(b.fraction.size() == 53);
    }
    //    b.print();
    return;
}
void solve(ll n)
{
    FloatingPointNumber f(0);
    string s;
    cin >> s;
    f.fraction.push_back(1);
    for (auto c : s)
    {
        f.fraction.push_back(c - '0');
    }
    auto ans = f;
    while (n > 0)
    {
        auto old = ans;
        add(ans, f, n);
        if (ans.exp == old.exp && ans.fraction == old.fraction)
        {
            break;
        }
        if (ans.exp != old.exp)
        {
            string binary = bitset<12>(ans.exp).to_string();
            //cout << binary << endl;
            ;
        }
        // ans.print();
        //n--;
    }
    ans.print();
}

int main()
{
    ll n;
    while (cin >> n, n)
    {
        solve(n);
    }
    return 0;
}
accuracy: 1
time_ms: 880
memory_kb: 3316
final_rank: 11

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

struct f{
  ll e=0;
  ll base=0;

  f(){base += (1LL<<52);}

  f(string s){
    ll k = 1;
    for(int i=51;i>=0;i--) {
      if(s[i]=='1') base += k;
      k *= 2;
    }
    base += k;
  }

  f operator + (const f& r){
    if(e==r.e){
      f ret;
      ret.base = base + r.base;
      ret.e = e;
      if((ret.base>>53)&1){
        ret.base >>= 1;
        ret.e++;
      }
      return ret;
    }else{
      f ret;
      if(e>r.e){
        ll sa = e - r.e;
        if(sa >= 53) return (*this);
        ret.base = base + (r.base >> sa);
        ret.e = e;
      }else{
        ll sa = r.e - e;
        if(sa >= 53) return r;
        ret.base = r.base + (base >> sa);
        ret.e = r.e;
      }
      if((ret.base>>53)&1){
        ret.base >>= 1;
        ret.e++;
      }
      return ret;
    }
  }
};
void print(f ans){
  for(ll i=11;i>=0;i--) std::cout << ((ans.e>>i)&1);
  for(ll i=51;i>=0;i--) std::cout << ((ans.base>>i)&1);
  std::cout << '\n';
}

void solve(ll n){
  string s;std::cin >> s;
  vector<vector<f>> v(53, vector<f>(70));
  for(ll i=0;i<53;i++){
    v[i][0] = f(s);
    for(ll j=0;j<i;j++) if((v[i][0].base>>j)&1) v[i][0].base ^= (1LL<<j);
    for(ll j=1;j<70;j++) v[i][j] = v[i][j-1] + v[i][j-1];
  }
  auto add = [&](ll b, ll c){
    assert(b>0);
    f ret;
    ret.e = -1;
    ll x = 0;
    while(b){
      if(b&1){
        if(ret.e==-1) ret = v[c][x];
        else ret = ret + v[c][x];
      }
      x++;
      b /= 2;
    }
    return ret;
  };

  f st = f(s);
  int cnt = 0;

  while(n>0){
    ll now = st.e;
    ll l = 0, r = n+1;
    if(cnt==53){
      print(st);
      return;
    }
    while(r-l>1){
      ll mid = (l+r)/2;
      f tmp = st;
      if(mid) tmp = tmp + add(mid, cnt);
      if(tmp.e>now) r = mid;
      else l = mid;
    }
    if(l) st = st + add(l, cnt);
    n -= l;
    if(n>0){
      st = st + v[0][0];
      n--;
    }
    cnt++;
  }
  print(st);
}
int main(){
  while(true){
    ll n;std::cin >> n;
    if(n==0) return 0;
    solve(n);
  }
}
accuracy: 1
time_ms: 80
memory_kb: 3416
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
ll N;
string S;
const ll b = 52;
ll now;
ll e;
ll A;
const ll INF = 1e18;
ll mul(ll a, ll b) {
    if(a == 0 or b == 0) return 0;
    if(INF / a <= b) return INF;
    return a * b;
}

void solve() {
    now = 1;
    e = 0;
    for(auto c : S) {
        now *= 2;
        if(c == '1') now++;
    }
    A = now;
    while(N) {
        ll ok = N;
        ll ng = 0;
        while(ok - ng > 1) {
            ll mid = (ok + ng) / 2;
            if(mul(mid, A) + now >= (1LL << (b + 1))) ok = mid;
            else ng = mid;
        }
        N -= ok;
        now += A * ok;
        if(now >= (1LL << (b + 1))) {
            now >>= 1;
            A >>= 1;
            e++;
        }
    }
    now -= (1LL << b);
    //cerr << e << " " << now << endl;
    string R;
    for(int i = 0; i < b; i++) {
        if(now % 2 == 1) R.push_back('1');
        else R.push_back('0');
        now >>= 1;
    }
    reverse(R.begin(), R.end());
    string L;
    for(int i = 0; i < 12; i++) {
        if(e % 2 == 1) L.push_back('1');
        else L.push_back('0');
        e >>= 1;
    }
    reverse(L.begin(), L.end());
    cout << L << R << endl;
}

int main() {
    while(cin >> N) {
        if(N == 0) break;
        cin >> S;
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3376
final_rank: 7

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-12;

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

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

	while (cin >> N, N) {
		string s;
		cin >> s;
		vector<long long int>v;
		v.push_back(1);
		for (auto i : s)v.push_back(i - '0');
		auto w = v;
		int num = 0;
		while (N) {
			L = 0, R = N;
			while (R - L > 1) {
				long long int mid = (R + L) / 2;
				auto nw = w;
				for (int i = num; i < 53; i++) {
					nw[i] += v[i - (num)]*mid;
				}
				for (int i = 52; i > 0; i--) {
					nw[i - 1] += nw[i] / 2;
					nw[i] &= 1;
				}
				if (nw[0] >= 2)R = mid;
				else L = mid;
			}
			for (int i = num; i < 53; i++) {
				w[i] += v[i - (num)]*R;
			}
			for (int i = 52; i > 0; i--) {
				w[i - 1] += w[i] / 2;
				w[i] &= 1;
			}
			N -= R;
			if (w[0] >= 2) {
				num++;
				for (int i = 52; i > 0; i--) {
					w[i] = w[i - 1];
				}
				w[0] = 0;
				for (int i = 52; i > 0; i--) {
					w[i - 1] += w[i] / 2;
					w[i] &= 1;
				}
			}
		}
		string ret;
		for (int i = 11; i >= 0; i--)cout << ((num >> i) & 1);
		for (int i = 1; i < 53; i++)cout << w[i];
		cout << endl;
	}
}
accuracy: 1
time_ms: 180
memory_kb: 3164
final_rank: 5

code_snippet: #include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define int long long

struct Int {
	int exp = 0;
	unsigned int kasu = 1ll << 52;

	Int() {}
	Int(string b) {
		exp = 0;
		kasu = 1ll << 52;
		rep(i, 0, 52) {
			int j = 51 - i;
			if (b[i] == '1') {
				kasu |= (1ll << j);
			}
		}
	}
};


bool operator==(Int a, Int b) {
	return a.exp == b.exp and a.kasu == b.kasu;
}
Int operator+(Int x, Int y) {
	int d = x.exp - y.exp;
	y.kasu >>= d;
	x.kasu += y.kasu;

	while (x.kasu >= (1ll << 53)) {
		x.exp++;
		x.kasu -= (1ll << 52);
	}

	return x;
}

auto binarySearch = [&](int ng, int ok, Int s, Int a) {
	auto f = [&](int m) {
		if ((1LL << 60) / m < (a.kasu >> s.exp))return true;
		return ((a.kasu >> s.exp) * m + s.kasu) >= (1LL << 53);
	};
	if (f(ng))return ng;
	while (ng + 1 < ok) {
		int m = (ng + ok) / 2;
		if (f(m))
			ok = m;
		else
			ng = m;
	}
	return ok;
};

void solve(int n) {
	string b; cin >> b;
	Int a(b);
	Int s = a;

	int k = 0;
	//cerr << "a.exp " << bitset<12>(a.exp) << endl;
	//cerr << "a.kasu " << bitset<53>(a.kasu) << endl;
	while (k < n) {
		int x = binarySearch(1, n - k, s, a);
		s.kasu = (a.kasu >> s.exp) * x + s.kasu;
		if (s.kasu == (1ll << 53)) {
			s.exp++;
			s.kasu >>= 1;
		}
		else {
			if (s.kasu >= (1ll << 53)) {
				s.exp++;
				s.kasu >>= 1;
			}
			while (s.kasu < (1ll << 52)) {
				s.exp--;
				s.kasu <<= 1;
			}
		}
		k += x;
		//cerr << "x " << x << endl;
		//cerr << "s.exp " << bitset<12>(s.exp) << endl;
		//cerr << "s.kasu " << bitset<53>(s.kasu) << endl;
	}

	cout << bitset<12>(s.exp) << bitset<52>(s.kasu) << endl;

}

signed main() {

	int n;
	while (cin >> n, n) {
		solve(n);
	}

	//double hoge = 1.0;
	//int x=*((int*)(&hoge));
	//bitset<64>b(x);
	//cout << b << endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3200
final_rank: 6

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

constexpr int mod = 1e9 + 7;

#define dump(x) ([&](){auto y = (x); cout << #x << " = " << (y) << endl; })();
// #define dump(x) ;


template<class T>
ostream&operator<<(ostream &os, vector<T>v) {
  os << "{";
  for(size_t i = 0; i < v.size(); i++) os << v[i] << ", ";
  os << "}";
  return os;
}

template<class T, class U>
ostream&operator<<(ostream &os, pair<T, U>v) {
  os << "(" << v.first << " , " << v.second << ")";
  return os;
}

template<class T, class U>
ostream&operator<<(ostream &os, map<T, U>v) {
  os << "(map: \n";
  for(auto e : v) os << e << ", \n";
  os << ")";
  return os;
}

using Vec = vector<int>;
using Mat = vector<Vec>;

ll modpow(ll x, ll k, ll mod) {
  x %= mod;
  ll r = 1;
  assert(k >= 0);
  while(k) {
    if(k & 1) r = r * x % mod;
    x = x * x % mod;
    k >>= 1;
  }
  return r;
}

ll toint(string s) {
  ll res = 0;
  int n = s.size();
  for(int i = 0; i < n; i++) res |= (ll(s[n - 1 - i] - '0')) << i;
  return res;
}

string tostr(ll x, int n) {
  string res = "";
  for(int i = 0; i < n; i++) {
    res += '0' + ((x >> i) & 1);
  }
  reverse(begin(res), end(res));
  return res;
}

bool mul_OF(ll a, ll b) {
  // a * b > 4e18
  // a > floor(4e18 / b)
  return a > ll(1e18) / b;
}

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

  while(1) {
    ll n;
    cin >> n;
    if(n == 0) break;
    string b;
    cin >> b;

    ll e = 0;
    ll k = toint(b) + (1ll << 52);
    // dump(e);
    // dump(k);

    ll G = 1ll << 53;
    assert(k < G);

    ll now = k;
    int shift = 0;
    // dump(n);
    // dump(e);
    // dump(k);
    while(n) {
      ll ok = 0, ng = n + 1;
      ll s = (k >> shift);
      while(abs(ok - ng) > 1) {
        ll mid = (ok + ng) >> 1;
        if(mul_OF(s, mid)) {
          ng = mid;
        } else {
          if(s * mid < G - now) ok = mid; else ng = mid;
        }
      }
      // dump(ok);
      now += s * ok;
      n -= ok;
      if(n) {
        now += s;
        assert(now >= G);
        assert(now < G * 2);
        now >>= 1;
        e++;
        shift++;
        if(shift > 53) shift = 53;
        n--;
      }

    }
    assert(k >= (1ll << 52));
    cout << tostr(e, 12) << tostr(now - (1ll << 52), 52) << "\n";
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3100
final_rank: 1

code_snippet: #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<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#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++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

void solve() {
	ll n;
	while (cin >> n, n) {
		int cnt = 0;
		bitset<52> b = 0;
		string s; cin >> s;
		rep(i,52)if (s[i] == '1')b[51-i] = 1;
		bitset<52> x = 0;
		x = b;
		cnt++; n--;
		while (n > 0) {
			if (cnt > 52)break;
			//cout << cnt << " " << n << " " << x << endl;
			bitset<52> c = b; c >>= cnt; 
			if (cnt)c[52-cnt] = 1;
			if (c == 0)break;
			ll le = 0, ri = INF;
			while (ri - le > 1) {
				ll mid = (ri + le) / 2;
				ll s = 0;
				rep(i, 52) {
					if (x[i]) {
						s++;
					}
					if (c[i]) {
						s += mid;
					}
					s /= 2;
				}
				if (s > 0)ri = mid;
				else le = mid;
			}
			if (n < ri) {
				ll s = 0;
				rep(i, 52) {
					if (x[i])s++;
					if (c[i])s += n;
					if (s % 2)x[i] = 1;
					else x[i] = 0;
					s /= 2;
				}
				break;
			}
			else {
				n -= ri;
				ll s = 0;
				rep(i, 52) {
					if (x[i])s++;
					if (c[i])s += ri;
					if (s % 2)x[i] = 1;
					else x[i] = 0;
					s /= 2;
				}
				cnt++; x >>= 1;
				if (cnt == 1)x[51] = 1;
			}
		}
		string ans;
		rep(i, 12) {
			if (cnt&(1 << (11-i))) {
				ans.push_back('1');
			}
			else ans.push_back('0');
		}
		per(i, 52) {
			if (x[i])ans.push_back('1');
			else ans.push_back('0');
		}
		cout << ans << endl;
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 3076
final_rank: 2

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353LL
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
long long n;
string pluser(string a, string b) {
	int kuriagari = 0;
	string ans;
	for (int i = a.size() - 1; i >= 0; --i) {
		kuriagari += a[i] + b[i] - '0' - '0';
		ans.push_back(kuriagari % 2 + '0');
		kuriagari /= 2;
		kuriagari = max(kuriagari, 0);
	}
	if (kuriagari == 1) {
		ans.push_back('1');
	}
	reverse(ans.begin(), ans.end());
	return ans;
}
int main(){
#define int long long
	while (true) {
		cin >> n;
		if (n == 0) return 0;
		string base;
		cin >> base;
		base = "1" + base;
		string ans = base;
		for (int i = 0;;) {
			while (n != 0 && ans.length() == base.length()) {
				string multiply;
				multiply = base;
				for (long long q = 1;; q *= 2) {
					string now = pluser(multiply, ans);
					if (now.length() != ans.length()) {
						//繰り上がり発生
						if (q != 1) {
							//保持しない
							q /= 2;
							for (int j = multiply.size() - 1; j >= 1; --j) {
								multiply[j] = multiply[j - 1];
								multiply[j - 1] = '0';
							}
						}
						n -= q;
						ans = pluser(multiply,ans);
						break;
					}
					if (q * 2 > n) {
						n -= q;
						ans = now;
						break;
					}
					for (int j = 0; j < multiply.size() - 1; ++j) {
						multiply[j] = multiply[j + 1];
					}
					multiply[multiply.size() - 1] = '0';
				}
			}
			if (ans.length() != base.length()) {
				ans.pop_back();
				for (int q = base.length() - 1; q >= 1;--q) {
					base[q] = base[q - 1];
				}
				base[0] = '0';
				i++;
			}
			if (n == 0) {
				string s;
				int geko = i;
				for (int q = 0; q < 12; ++q) {
					s.push_back(geko % 2 + '0');
					geko /= 2;
				}
				reverse(s.begin(), s.end());
				cout << s;
				for (int j = 1; j < ans.length(); ++j) {
					cout << ans[j];
				}
				cout << endl;
				break;
			}
		}
	}
	return 0;
}
accuracy: 1
time_ms: 2540
memory_kb: 3220
final_rank: 15

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


#define LEN 54
#define BASE 2 //小数部の開始桁
#define SIZE 52 //小数部の桁数

ll mult;
ll POW[63];
int S[LEN],A[LEN];
char buf[SIZE+1];


//SにAをadd_count回足す関数
void calc(ll add_count){

	ll work[LEN];

	int tmp,kuriagari;

	//Aをまとめて加算する
	for(int digit = 62; digit >= 0 && add_count > 0; digit--){
		if(add_count < POW[digit])continue;

		add_count -= POW[digit];

		for(int i = 0; i < LEN; i++)work[i] = 0;

		//Aを左にdigitビットシフトした数列を作成
		for(int i = 0; i < LEN; i++){
			if(i+digit == LEN)break;
			work[i] = A[i+digit];
		}

		kuriagari = 0;
		//数列を右から足し算
		for(int i = LEN-1; i >= 0; i--){
			tmp = work[i]+S[i]+kuriagari;
			S[i] = tmp%2;
			kuriagari = tmp/2;
		}
	}
}

void func(){

	//Sの初期化
	for(int i = 0; i < LEN; i++){
		S[i] = 0;
	}

	scanf("%s",buf);

	//SとAの、初期設定
	S[0] = 0;
	A[0] = 0;
	S[BASE-1] = 1;
	A[BASE-1] = 1;

	for(int i = 0; i < SIZE; i++){
		S[BASE+i] = buf[i]-'0';
		A[BASE+i] = buf[i]-'0';
	}

	ll e = 0;

	ll num_S,num_A,next = POW[53],diff,add_count;

	while(mult > 0){

		//次に、Sの桁が繰り上がるまでの、最小加算回数を求める

		//S,Aをlong long intで表す
		num_S = 0;
		for(int digit = 1; digit < LEN; digit++){
			num_S += S[digit]*POW[53-digit];
		}
		num_A = 0;
		for(int digit = 1; digit < LEN; digit++){
			num_A += A[digit]*POW[53-digit];
		}

		//★もう足しても意味がない★
		if(num_A == 0){
			break;
		}

		//nextとの差分
		diff = next-num_S;

		if(diff%num_A == 0){ //ぴったり繰り上がる

			add_count = diff/num_A;

		}else{

			add_count = diff/num_A+1;
		}

		if(add_count > mult){ //加算回数を超過する場合

			//SにAをmult回足す
			calc(mult);

			mult = 0;

		}else{

			//SにAをadd_count回足す
			calc(add_count);

			for(int i = 52; i >= 0; i--){
				S[i+1] = S[i];
				A[i+1] = A[i];
			}
			S[0] = 0;
			A[0] = 0;

			mult -= add_count;
			e++;
		}
	}

	//指数部の表示
	for(int i = 11; i >= 0; i--){
		if(e < POW[i]){
			printf("0");
		}else{
			printf("1");
			e -= POW[i];
		}
	}

	//仮数部の表示
	for(int i = 0; i < SIZE; i++){
		printf("%d",S[BASE+i]);
	}

	printf("\n");
}


int main(){

	POW[0] = 1;
	for(int i = 1; i <= 62; i++){
		POW[i] = 2*POW[i-1];
	}

	while(true){
		scanf("%lld",&mult);
		if(mult == 0)break;

		func();
	}

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3152
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
using P = pair<Int, Int>;
const Int B = 1LL<<52;
P add(P s,Int a,Int k){
  s.second+=a*k;
  return s;
}
Int check(P s,Int a,Int k){
  if(a>(B<<1)/k) return 1;
  if(a*k>=(B<<1)) return 1;
  if(s.second+a*k>=(B<<1)) return 1;
  return 0;
}
P add2(P s,Int a){
  s.second+=a;
  assert(s.second>=(B<<1));
  s.second>>=1;
  s.first++;
  return s;
}
signed main(){
  Int n;
  while(cin>>n,n){
    string b;
    cin>>b;
    Int a=1;
    for(Int i=0;i<(Int)b.size();i++)
      a=(a<<1)|(b[i]=='1');
    P s(0,a);
    while(n){
      if(!check(s,a,n)){
	s=add(s,a,n);
	n=0;
	break;
      }
      Int l=0,r=n;
      while(l+1<r){
	Int m=(l+r)>>1;
	if(check(s,a,m)) r=m;
	else l=m;
      }
      s=add(s,a,l);
      s=add2(s,a);
      n-=r;
      a>>=1;
    }
    bitset<12> x(s.first);
    bitset<52> y(s.second-B);
    cout<<x<<y<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3144
final_rank: 3