// yukicoder: 873 バイナリ、ヤバいなり!w // 2019.8.31 bal4u #include #include #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } void outs(char *s) { while (*s) pc(*s++); } #define INF 0x01010101 #define LIM 550 int N; int a[LIM]; int w; int dp[600005][2], pre[600005][2]; char s01[LIM]; int ok(int a, int b, int zero) { // a は 高評価対象か int ea = a & 1, eb = b & 1, t = a <= b; int r; if (ea && eb) r = t; else if (ea) r = 1; else if (eb) r = 0; else r = !t; if (!zero) r = !t; return r; } void pr(int w) { static char *s = s01; char c; c = s[w], s[w] = 0; outs(s); s[w] = c; s = (c == '0')? s01+1: s01; } int cmp(const void *u, const void *v) { int a = (*(int *)u) & 1, b = (*(int *)v) & 1, t = *(int *)u - *(int *)v; if (a && b) return t; if (a & 1) return -1; if (b & 1) return 1; return t; } int main() { int i, j, k; N = in(); if (N == 1) { puts("0"); return 0; } w = 0; while (w*w <= N) w++, a[w] = w*w; i = 0; while (i < LIM) s01[i++] = '0', s01[i++] = '1'; for (j = 1; j <= N; j++) { int t, x = INF; for (i = 1; a[i] <= j; i++) { t = j - a[i]; if (dp[t][0] + i < x || (dp[t][0] + i == x) && ok(i, k, dp[t][1])) x = dp[t][0] + i, k = i; } t = j - a[k]; dp[j][0] = dp[t][0] + k; dp[j][1] = (a[k] & 1)? dp[t][1]: !dp[t][1]; pre[j][0] = t, pre[j][1] = k; } i = N; for (j = 0; i > 0; j++) { a[j] = pre[i][1]; i = pre[i][0]; } // printf("w=%d\n", j); // for (i = 0; i < j; i++) printf("%d ", a[i]); printf("\n"); qsort(a, j, sizeof(int), cmp); // printf("w=%d\n", j); // for (i = 0; i < j; i++) printf("%d ", a[i]); printf("\n"); for (i = 0; i < j && (a[i] & 1); i++) pr(a[i]); // 奇数長を昇順 while (i < j) { pr(a[--j]); if (i < j) pr(a[i++]); } // 偶数長を長短長短順 pc('\n'); return 0; }