#P8739. Make String a K-Repeated String
Make String a K-Repeated String
Make String a K-Repeated String
We call a string \(S\) a K-repeated string if it can be constructed by concatenating an unknown substring exactly \(K\) times. For example, abcabcabc
can be viewed as three repetitions of abc
, so it is a 3-repeated string. Similarly, aaaaaa
is a 2-repeated string, a 3-repeated string, and a 6-repeated string.
Given an integer \(K\) and a string \(S\) whose length is divisible by \(K\), your task is to determine the minimum number of characters that need to be modified so that \(S\) becomes a \(K\)-repeated string.
Note: Since you are allowed to change characters, you can choose the optimal character for each corresponding position across the \(K\) blocks to minimize the number of modifications.
inputFormat
The input consists of two lines:
- The first line contains an integer \(K\).
- The second line contains the string \(S\). It is guaranteed that the length of \(S\) is divisible by \(K\).
outputFormat
Output a single integer, representing the minimum number of characters that need to be modified to make \(S\) a \(K\)-repeated string.
sample
3
aaa
0