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

문제

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

입력

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

출력

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

예제 입력 1

abab
ababab
abc
def

예제 출력 1

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