Some problems are so classic that barely need a statement. For this one, we ask you to compute the longest subword that two given words have in common. In case of a tie, print the smallest one in alphabetical order.
Input consists of several cases, each with two non-empty words and made up of at most 500 lowercase letters.
For every case, print the longest common subword. In case of a tie, print the smallest one in alphabetical order.
There are very fast algorithms to solve this problem. Here, we settle for one that takes time proportional to , where and are the lengths of and .
Input
pseudopseudohypoparathyroidism floccinaucinihilipilification supercalifragilisticexpialidocious sipircilifrigilisticixpiilidiciiis supercalifragilisticexpialidocious zzz abczzzcdazzzaba abcxxxcdaxxxaba
Output
at gilistic aba