Update the answer by subtracting the maxfrequency from total positions if there exist extra character at the end of the string apart from the n / k characters then add 1.
ans += ( totalpositions - maxfrequency ) NEW_LINE if ( i % k < n % k ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT print ( ans ) NEW_LINE