#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; // dp[score] = minimum total characters needed for this score. const int INF = 1e9; vector dp(n + 1, INF); dp[0] = 0; for (int score = 1; score <= n; score++) { for (int len = 1; len * len <= score; len++) { dp[score] = min( dp[score], len + dp[score - len * len] ); } } string answer; int remaining = n; int start = 0; while (remaining > 0) { int shortestZero = -1; int longest = -1; // Try lengths in increasing order. for (int len = 1; len * len <= remaining; len++) { // Only consider choices preserving minimum total length. if (len + dp[remaining - len * len] != dp[remaining]) { continue; } longest = len; int last; if (len % 2 == 1) { last = start; // Odd: same ending bit. } else { last = 1 - start; // Even: opposite ending bit. } // First zero-ending candidate is the shortest one. if (last == 0 && shortestZero == -1) { shortestZero = len; } } int chosen; if (shortestZero != -1) { chosen = shortestZero; } else { chosen = longest; } // Append the chosen alternating block. int bit = start; for (int i = 0; i < chosen; i++) { answer.push_back('0' + bit); bit = 1 - bit; } remaining -= chosen * chosen; // Repeat the last bit to create the next block boundary. start = answer.back() - '0'; } cout << answer << '\n'; }