#P8846. Construct a Borderless String
Construct a Borderless String
Construct a Borderless String
For a given string \(S\), let \(|S|\) denote its length, \(S_i\) denote its \(i\)th character, and \(S_{l,r}\) denote the substring composed of \(S_l, S_{l+1}, \ldots, S_r\). Two strings are defined to be equal if and only if they have the same length and the corresponding characters at each position are identical.
For a string \(S\) and any positive integer \(i \le |S|\), if \(k\) is the largest positive integer smaller than \(i\) such that \(S_{1,k} = S_{i-k+1,i}\), then we define \(next_i = k\). In particular, if no such \(k\) exists then \(next_i=0\).
Your task is: given an integer \(n\), construct a string \(S\) composed of lowercase letters such that \(|S| = n\) and the sum \(\sum_{i=1}^{|S|} next_i\) is minimized.
A string with no non-trivial borders (i.e. for every \(i\ge 2\), there is no \(k \ge 1\) such that \(S_{1,k} = S_{i-k+1, i}\)) achieves this minimal sum (which equals 0 for indices from 2 to \(n\), while \(next_1=0\) trivially). You are guaranteed that there exists at least one borderless string of length \(n\) over the 26 lowercase letters.
inputFormat
Input consists of a single integer \(n\) (\(1 \le n\le\) some reasonable limit) representing the desired length of the string.
outputFormat
Output a constructed string \(S\) of length \(n\) composed of lowercase letters that minimizes \(\sum_{i=1}^{|S|} next_i\) (in other words, a borderless string).
sample
1
a