CF BUDDY
← Problems·

1511D · Min Cost String

1600 · brute force, constructive algorithms, graphs

Problem: Let's define the cost of a string ss as the number of index pairs ii and jj (1i<j<s1 \le i < j < |s|) such that si=sjs_i = s_j and si+1=sj+1s_{i+1} = s_{j+1}.

You are given two positive integers nn and kk. Among all strings with length nn that contain only the first kk characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost — find any of them.

Input Format: The only line contains two integers nn and kk (1n2105;1k261 \le n \le 2 \cdot 10^5; 1 \le k \le 26).

Output Format: Print the string ss such that it consists of nn characters, each its character is one of the kk first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings — print any of them.

Sample Cases

Case 1

Input

9 4

Output

aabacadbb

Case 2

Input

5 1

Output

aaaaa

Case 3

Input

10 26

Output

codeforces

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback