Number of distinct string of length n of lowercase latin letters

Revision en2, by anonymous_ali, 2026-02-11 10:29:44

Problem Statement

You are given two integers n and k.
Count the number of distinct strings of length n consisting of lowercase Latin letters such that the number of equal consecutive characters is strictly less than k.

Constraints

  • 1 ≤ n ≤ 100000
  • 1 ≤ k ≤ n

Input

Two integers n and k.

Output

Print the number of valid strings of length n.

Examples

Example 1

Input
3 3 Output
17550

Explanation
The total number of strings of length 3 over lowercase Latin letters is 26³ = 17576.
There are exactly 26 strings with three equal consecutive characters (aaa, bbb, etc.).
Hence, the answer is 17576 − 26 = 17550.

Example 2

Input
3 2 Output
16250

Explanation
The total number of strings of length 3 is 26³ = 17576.

Invalid strings are: - Strings with exactly two equal consecutive characters: 26 × 25 + 26 × 25 - Strings with three equal consecutive characters: 26

Total invalid strings = 1326.
Therefore, the number of valid strings is 17576 − 1326 = 16250.

Tags dynamic programming, help

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English anonymous_ali 2026-02-11 14:41:51 4
en3 English anonymous_ali 2026-02-11 13:19:37 89
en2 English anonymous_ali 2026-02-11 10:29:44 12 (published)
en1 English anonymous_ali 2026-02-11 10:28:10 1131 Initial revision (saved to drafts)