Under construction

Still being built. Things may change

Make a Periodic String

Time limit2sMemory limit128 MB

Summary
Given a DNA string and a bound M, find the minimum number of character edits to make the string periodic with some period length at most M.
Level

Medium5 of 10

Topics
String, Greedy, Brute force, Implementation
Solved
No attempts yet

Problem

Sejun is a biologist, so he often works with DNA strings. One day, he became tired of looking at a long DNA string and wanted to express it in a simpler periodic form.

For a string of length LL, a positive integer PP is a period length if, for every integer ii with 0≤i≤L−P−10 \le i \le L-P-1, the character at position ii is the same as the character at position i+Pi+P. For example, CATCATC, CATCAT, ACTAC, and ACT all have period length 33.

Given a DNA string, change as few characters as possible so that it becomes a periodic string whose period length is at most MM. Find the minimum number of characters that must be changed.

Input

The first line contains MM. The value of MM is at most the length of the string.

The second line contains the DNA string. The string consists only of A, C, G, and T, and its length is at most 30003000.

Output

Print the minimum number of characters that must be changed.

Examples4

  1. Example 1

    Input
    2
    ACGTGCA
    
    Expected output
    3
  2. Example 2

    Input
    3
    ATAGATA
    
    Expected output
    1
    
  3. Example 3

    Input
    13
    ACGCTGACAGATA
    
    Expected output
    0
    
  4. Example 4

    Input
    1
    AAAATTTCCG
    
    Expected output
    6