시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 18 6 6 42.857%

문제

0으로 시작하지 않는 두 n자리 정수인 양수 a와 b가 있다. 우리는 b의 숫자로 만들어진 n자리 수중에서 a에 가까운 정수 2개를 찾아야한다(한개는 a보다 크거나 같으면서 가장 가까운수 , 나머지 하나는 a보다 작으면서 가장 가까운수).

예를 들어 a=3022,b=1232면 우리는 다음과 같은 수를 만들수 있다: 1223, 1232, 1322, 2123, 2132, 2213, 2231, 2312, 2321, 3122, 3212, 3221. a보다 크거나 같으며 가장 가까운 수는 3122이다. a보다 작으며 가장 가까운수은 2321이다. 만약 a=1232,b=3022라면, 가능한수는 2023, 2032, 2203, 2230, 2302, 2320, 3022, 3202, 3220이다. a보다 크거나 같으며 가장 가까운수는 2023이다. a보다 작은 수는 없다.

a와 b가 주어질때, "a에 가장 가까운수" 를 찾는 프로그램을 작성하라, 또는 둘중 하나가 없음을 알아내라.

입력

두 줄의 표준입력이 주어진다. 각각의 줄에는 n자리 정수인 양수가 주어진다. 첫 번째 줄에는 a가, 두번쨰 줄에는 b가 주어진다. n은 1이상 60이하이다.

출력

표준출력으로 작성해야한다. 첫 번째 줄에는 b의 숫자로 이루어진 a보다 작지 않고, 0으로 시작하지 않는 a에 가장 가까운 수를 출력하라. 두 번째 줄에는 b의숫자로 이루어진 a보다 작은, 0으로 시작하지 않는 a에 가장 가까운 수를 출력하라.  두 수중 하나가 없는 경우 그 수의 자리에 0를 출력하라.

예제 입력 1

3075
6604

예제 출력 1

4066
0

예제 입력 2

3000203
4562454

예제 출력 2

4244556
2655444
W3sicHJvYmxlbV9pZCI6IjMwMTciLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWFjMDBcdWFlNGNcdWM2YjQgXHVjMjE4IFx1Y2MzZVx1YWUzMCIsImRlc2NyaXB0aW9uIjoiPHA+MFx1YzczY1x1Yjg1YyBcdWMyZGNcdWM3OTFcdWQ1NThcdWM5YzAmbmJzcDtcdWM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