import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.next();
int k = sc.nextInt();
String small = s.substring(0, k);
String lar = s.substring(0, k);
for (int i = 0; i <= s.length() - k; i++) {
String sub = s.substring(i, i + k);
if (sub.compareTo(small) < 0) {
small = sub;
}
if (sub.compareTo(lar) > 0) {
lar = sub;
}
}
System.out.println(small);
System.out.println(lar);
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: