The one of the greatest common subword

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

Input consists of several cases, each with two non-empty words w₁ and w₂
made up of at most 500 lowercase letters.

Output

For every case, print the longest common subword. In case of a tie,
print the smallest one in alphabetical order.

Observation

There are very fast algorithms to solve this problem. Here, we settle
for one that takes time proportional to n₁ ⋅ n₂, where n₁ and n₂ are the
lengths of w₁ and w₂.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T11:10:19.670Z

© Jutge.org, 2006–2026.
https://jutge.org
