#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) #define all(c) (c).begin(), (c).end() #define zero(a) memset(a, 0, sizeof a) #define minus(a) memset(a, -1, sizeof a) #define watch(a) { cout << #a << " = " << a << endl; } template inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); } template inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); } typedef long long ll; int const inf = 1<<29; int sz; vector to_vector(string s) { vector ret; sz = max(sz, (int)s.size() + 1); reverse(all(s)); for(auto c: s) { ret.push_back(c); } ret.resize(sz, inf); return ret; } bool is_zero(vector& v) { if(v[0] != 0) return false; if(v.size() > 1 && v[1] != inf) return false; return true; } void divide_by_2(vector& v) { rep(i, v.size()) { if(v[i] < inf) { v[i] /= 2; if(v[i+1] < inf) { v[i] += ((v[i+1] * 10) / 2) % 10; } if(v[i] == 0 && v[i+1] == inf) { v[i] = inf; } } } if(v[0] == inf) v[0] = 0; } void multiply_by_2(vector& v) { if(v.back() != inf) v.back() *= 2; for(int i=v.size() - 1; i>=1; i--) { if(v[i-1] == inf) continue; v[i-1] *= 2; if(v[i-1] > 10) { if(v[i] == inf) v[i] = 0; v[i] += v[i-1] / 10; v[i-1] %= 10; } } } void add(vector& a, vector& b) { assert(a.size() == b.size()); rep(i, a.size()) { a[i] += b[i]; if(a[i] > 10) { if(a[i+1] == inf) a[i+1] = 0; a[i+1] += a[i] / 10; a[i] %= 10; } } } void minus_by(vector& a, vector& b) { assert(a.size() == b.size()); rep(i, a.size()) { if(b[i] == inf) continue; a[i] -= b[i]; if(a[i] < 0) { a[i] += 10; a[i+1] --; } } for(int i=a.size() - 1; i>=0; i--) { if(a[i] == inf) continue; else if(a[i] == 0) a[i] = inf; else break; } if(a[0] == inf) a[0] = 0; } vector dfs(vector& N) { if(is_zero(N)) return vector(sz); auto n1 = N; divide_by_2(n1); auto n2 = N; multiply_by_2(n2); return max(dfs(n1), n2); } template ostream& operator << (ostream& ost, vector const& v) { ost << "["; rep(i, v.size()) { if(i) ost << ", "; ost << v[i]; } ost << "]"; return ost; } int main() { /* vector a = {3, 2, 1}; vector b = {3, inf, inf}; auto c = a; multiply_by_2(a); cout << a << endl; multiply_by_2(a); cout << a << endl; multiply_by_2(a); cout << a << endl; multiply_by_2(a); // a.resize(a.size() + 1);cout << a << endl;multiply_by_2(a); cout << a << endl; exit(0); */ string n; cin >> n; sz = n.size(); auto N = to_vector(n); auto normal = to_vector(n); N.resize(sz); normal.resize(sz); auto K = N; while(!is_zero(K)) { divide_by_2(K); add(normal, K); } auto d = dfs(N); minus_by(d, normal); string s; for(auto c: d) { if(c != inf) s += '0' + c; } reverse(all(s)); cout << s << endl; for(int i=d.size() - 1; i>=0; i--) cout << d[i] << " "; cout << endl; return 0; }