All problems

Longest Common Prefix

mediumPythonStrings

Riverbend Museum unpacks one crate at a time. Every object in a crate carries a catalogue reference, and objects from the same crate were given references that begin the same way — how far that agreement runs depends on the crate. The archivist labels the empty crate with the longest opening run of characters that every reference in it shares. A crate whose references agree on nothing at all gets a blank label, which is a real outcome and has to print as one.

Task: Print the longest opening run of characters that every reference begins with.

Input

A single line holding between 1 and 1000 lowercase references separated by single spaces. Each reference is at most 200 characters.

Output

One line holding the shared opening run. If the references do not all begin with the same character, print an empty line — nothing at all, not the word none and not a space.

Example:

Input:
flower flow flight

Output:
fl

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…