시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 47 5 3 11.111%

문제

알파벳 소문자로 되어있는 두 문자열 a와 b가 주어졌을 때, ax 또는 bx가 팰린드롬이 되는 가장 짧은 문자열 x를 찾는 프로그램을 작성하시오. 이때, ax와 bx가 둘 다 팰린드롬이면 안 된다. 

입력

입력은 여러개의 테스트 케이스로 되어 있다. 각 테스트 케이스는 두 줄이고, 첫째 줄에는 a, 둘째 줄에는 b가 주어진다. 각 문자열은 0개 이상, 1,000개 이하의 알파벳 소문자로 이루어져 있다.

출력

각 테스트 케이스에 대해서 문제의 조건을 만족하는 가장 짧은 x를 출력한다. 만약 그러한 x가 여러개라면 사전순으로 가장 앞서는 것을 출력한다. 조건을 만족하는 문자열이 없는 경우 "No Solution."을 출력한다.

예제 입력 1

abab
ababab
abc
def

예제 출력 1

baba
ba
W3sicHJvYmxlbV9pZCI6IjQzOTkiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWIwNWRcdWM3NzhcdWI0ZGNcdWI4NmMiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YzU0Y1x1ZDMwY1x1YmNiMyBcdWMxOGNcdWJiMzhcdWM3OTBcdWI4NWMgXHViNDE4XHVjNWI0XHVjNzg4XHViMjk0IFx1YjQ1MCBcdWJiMzhcdWM3OTBcdWM1ZjQgYVx1YzY0MCBiXHVhYzAwIFx1YzhmY1x1YzViNFx1Yzg0Y1x1Yzc0NCBcdWI1NGMsIGF4IFx1YjYxMFx1YjI5NCBieFx1YWMwMCBcdWQzMzBcdWI5YjBcdWI0ZGNcdWI4NmNcdWM3NzQgXHViNDE4XHViMjk0IFx1YWMwMFx1YzdhNSBcdWM5ZTdcdWM3NDAgXHViYjM4XHVjNzkwXHVjNWY0IHhcdWI5N2MgXHVjYzNlXHViMjk0IFx1ZDUwNFx1Yjg1Y1x1YWRmOFx1YjdhOFx1Yzc0NCBcdWM3OTFcdWMxMzFcdWQ1NThcdWMyZGNcdW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