#K3046. Smallest and Largest Substrings

    ID: 24871 Type: Default 1000ms 256MiB

Smallest and Largest Substrings

Smallest and Largest Substrings

You are given an integer n and a string S. Your task is to find the lexicographically smallest and largest substrings of S that have a length equal to n. A substring is defined as a contiguous sequence of characters in the string.

Note: The lexicographical order is similar to the dictionary order. For example, 'abc' is lexicographically smaller than 'bca'.

Input Format: The input consists of an integer n in the first line, followed by the string S in the second line.

Output Format: The output should contain two lines. The first line contains the smallest substring of length n, and the second line contains the largest substring of length n.

In mathematical notation, if we denote a substring as \(S[i:i+n]\) for \(0 \leq i \leq |S|-n\), the answer is:

[ \min_{0 \le i \le |S|-n} { S[i:i+n] } \quad \text{and} \quad \max_{0 \le i \le |S|-n} { S[i:i+n] } ]

inputFormat

The first line contains a single integer n representing the length of the substrings to consider. The second line contains the string S.

outputFormat

Output two lines: the first line is the lexicographically smallest substring of length n and the second line is the lexicographically largest substring of length n.

## sample
3
abcde
abc

cde

</p>