#K71197. Lexicographically Smallest String

    ID: 33478 Type: Default 1000ms 256MiB

Lexicographically Smallest String

Lexicographically Smallest String

You are given two integers (n) and (k). The task is to generate the lexicographically smallest string of length (n) that contains exactly (k) distinct characters. The string must only contain lowercase English letters. If it is not possible to construct such a string (i.e., if (k > n) or (k > 26)), output an empty string.

A string (a) is lexicographically smaller than a string (b) if, at the first position where they differ, the character in (a) appears before the character in (b) in the alphabet.

inputFormat

The input consists of a single line containing two integers (n) and (k) separated by a space, where (1 \le n \le 1000) and (1 \le k \le 26).

outputFormat

Output a single line containing the lexicographically smallest string of length (n) with exactly (k) distinct characters. If no valid string can be formed, output an empty string.## sample

5 3
aaabc