#C12798. Smallest Lexicographical Substring

    ID: 42264 Type: Default 1000ms 256MiB

Smallest Lexicographical Substring

Smallest Lexicographical Substring

You are given a string s and an integer n. Your task is to find the lexicographically smallest substring of s with length n.

If there are multiple substrings that are equally smallest in lexicographical order, return the one that appears first in the string. If n is greater than the length of s, output an empty string.

Recall that a string a is lexicographically smaller than a string b if either
1. a is a prefix of b (and ab), or
2. there exists an index i such that \(a_1 = b_1, a_2 = b_2, ..., a_{i-1} = b_{i-1}\) and \(a_i < b_i\).

inputFormat

The input consists of two lines:

  1. The first line contains the string s, which may include letters, special characters, and spaces.
  2. The second line contains an integer n indicating the length of the substring to find.

Read input from standard input (stdin).

outputFormat

Output the lexicographically smallest substring of s with length n to standard output (stdout). If no such substring exists (i.e. n is greater than the length of s), output an empty string.

## sample
programming
3
amm