Let’s consider a string of non-negative integers, containing $N$ elements. Suppose these elements are $S_1, S_2, \ldots, S_N$, in the order in which they are placed inside the string. Such a string is called ‘funny’ if the string $S_1+1, S_2, S_3, \ldots, S_{N-1}, S_N-1$ can be obtained by rotating the first string (to the left or to the right) several times. For instance, the strings $2, 2, 2, 3$ and $1, 2, 1, 2, 2$ are funny, but the string $1, 2, 1, 2$ is not. Your task is to find a funny string having $N$ elements, for which the sum of its elements $S_1+S_2+ \cdots +S_N$ is equal to $K$.
structIOManager { template <typename T> inlineboolread(T &x){ char c = '\n'; bool flag = false; x = 0; while (~ c && ! isdigit(c = getchar()) && c != '-') ; c == '-' && (flag = true, c = getchar()); if (! ~ c) returnfalse; while (isdigit(c)) x = (x << 3) + (x << 1) + c - '0', c = getchar(); return (flag && (x = -x), true); } inlineboolread(char &c){ c = '\n'; while (~ c && ! (isprint(c = getchar()) && c != ' ')) ; return ~ c; } inlineintread(char s[]){ char c = '\n'; int len = 0; while (~ c && ! (isprint(c = getchar()) && c != ' ')) ; if (! ~ c) return0; while (isprint(c) && c != ' ') s[len ++] = c, c = getchar(); return (s[len] = '\0', len); } template <typename T> inline IOManager operator > (T &x) { read(x); return *this; } template <typename T> inlinevoidwrite(T x){ if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + '0'); } inlinevoidwrite(char c){ putchar(c); } inlinevoidwrite(char s[]){ int pos = 0; while (s[pos] != '\0') putchar(s[pos ++]); } template <typename T> inline IOManager operator < (T x) { write(x); return *this; } } io;
structSolver { private: staticconstint N = 1010; int n, k, a[N]; voidinput(){ io > n > k; } voidinit(){ int t = k / n; for (int i = 1; i <= n; ++ i) a[i] = t, k -= t; } voidprocess(){ int sum = n - 1; while (sum % k) sum += n; int p = sum / k + 1; for (; p < n; p = (p - 1 + sum / k) % n + 1) ++ a[p]; ++ a[n]; for (int i = 1; i <= n; ++ i) io < a[i] < ' '; io < '\n'; }