@@ -0,0 +1,1380 @@
+import java.io.BufferedReader;%0Aimport java.io.InputStreamReader;%0Aimport java.util.Arrays;%0Aimport java.util.NavigableSet;%0Aimport java.util.TreeSet;%0A%0Apublic class PhoneNumbers %7B%0A%0A    public static void main(String%5B%5D args) throws Exception %7B%0A        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));%0A        String%5B%5D firstLine = reader.readLine().split(%22 %22);%0A        int sourceLength = Integer.parseInt(firstLine%5B0%5D);%0A        int resultLength = Integer.parseInt(firstLine%5B1%5D);%0A        char%5B%5D source = reader.readLine().toCharArray();%0A        NavigableSet%3CCharacter%3E alphabet = new TreeSet%3C%3E();%0A        for (char c : source) %7B%0A            alphabet.add(c);%0A        %7D%0A        char firstChar = alphabet.first();%0A        char lastChar = alphabet.last();%0A%0A        char%5B%5D result = new char%5BresultLength%5D;%0A        System.arraycopy(source, 0, result, 0, Math.min(resultLength, sourceLength));%0A        if (resultLength %3E sourceLength) %7B%0A            Arrays.fill(result, sourceLength, resultLength, firstChar);%0A            System.out.println(result);%0A            return;%0A        %7D%0A        for (int i = result.length - 1; i %3E= 0; i--) %7B%0A            if (result%5Bi%5D %3C lastChar) %7B%0A                result%5Bi%5D = alphabet.higher(result%5Bi%5D);%0A                System.out.println(result);%0A                return;%0A            %7D%0A            result%5Bi%5D = firstChar;%0A        %7D%0A    %7D%0A%7D%0A

Add PhoneNumbers