<gh_stars>1-10
from typing import List

read_strs = lambda: input().split()


class TrieNode:
    def __init__(self, char: str):
        self.char = char  # '' for root node
        self.children = dict()
        self.word_finished = False
        self.counter = 1  # How many times this character appeared in the addition process

    def add_child(self, char):
        self.children[char] = TrieNode(char)


class Trie:
    def __init__(self):
        self.root = TrieNode('')
        self.total_num = 0

    def add(self, word: str):
        node = self.root
        continuous = True
        for char in word:
            children = node.children
            if continuous and char in children:
                node = node.children[char]
                node.counter += 1
            else:
                node.add_child(char)
                node = children[char]
                continuous = False

        self.total_num += 1
        node.word_finished = True

    def find_longest_common(self):
        length = 0
        node = self.root
        while len(node.children) == 1 and next(iter(node.children.values())).counter == self.total_num:
            node = next(iter(node.children.values()))
            length += 1

        return length


class Solution:
    def __init__(self):
        self.trie = Trie()

    def longestCommonPrefix(self, strs: List[str]) -> str:
        if not strs:
            return ''

        if len(strs) == 1:
            return strs[0]

        trie = self.trie
        for word in strs:
            trie.add(word)

        return strs[0][:trie.find_longest_common()]


if __name__ == '__main__':
    strs = read_strs()
    s = Solution()
    result = s.longestCommonPrefix(strs)
    print(result)

from typing import List

read_strs = lambda: input().split()


class TrieNode:
    def __init__(self, char: str):
        self.char = char  # '' for root node
        self.children = dict()
        self.word_finished = False
        self.counter = 1  # How many times this character appeared in the addition process

    def add_child(self, char):
        self.children[char] = TrieNode(char)


class Trie:
    def __init__(self):
        self.root = TrieNode('')
        self.total_num = 0

    def add(self, word: str):
        node = self.root
        continuous = True
        for char in word:
            children = node.children
            if continuous and char in children:
                node = node.children[char]
                node.counter += 1
            else:
                node.add_child(char)
                node = children[char]
                continuous = False

        self.total_num += 1
        node.word_finished = True

    def find_longest_common(self):
        length = 0
        node = self.root
        while len(node.children) == 1 and next(iter(node.children.values())).counter == self.total_num:
            node = next(iter(node.children.values()))
            length += 1

        return length


class Solution:
    def __init__(self):
        self.trie = Trie()

    def longestCommonPrefix(self, strs: List[str]) -> str:
        if not strs:
            return ''

        if len(strs) == 1:
            return strs[0]

        trie = self.trie
        for word in strs:
            trie.add(word)

        return strs[0][:trie.find_longest_common()]


if __name__ == '__main__':
    strs = read_strs()
    s = Solution()
    result = s.longestCommonPrefix(strs)
    print(result)
# '' for root node # How many times this character appeared in the addition process