P8846 'JROI-7' PMK Prefix Matching String
Background
> The constraints are very loose, so the construction ends up being pretty dumb.
— command_block, "Pre-Exam Tips"
Description
For a string $S$, let $|S|$ denote the length of $S$. Let $S_i$ denote the $i$-th character of $S$, and let $S_{l,r}$ denote the string formed by $S_l, S_{l+1}, ..., S_r$. Two strings are defined to be equal if and only if they have the same length and the characters at every position are the same.
For a string $S$ and a positive integer $i \le |S|$, if $k$ is the largest positive integer satisfying $k < i$ and $S_{1,k} = S_{i-k+1,i}$, then $next_i = k$. In particular, if no such $k$ exists, then $next_i = 0$.
Please construct a string $S$ consisting of lowercase letters such that $|S| = n$, and the sum of $next_i$ over all positive integers $i \le |S|$ is minimized.
Input Format
One line containing a positive integer $n$.
Output Format
One line containing a string, representing the $S$ you construct. **Output any valid solution.**
Explanation/Hint
### Constraints
This problem uses bundled testdata.
For $50\%$ of the testdata, $n \le 26$.
For $100\%$ of the testdata, $1 \le n \le 10^5$.
Translated by ChatGPT 5