同样交卷了才写完 what the *** whatever

# -*- coding=utf-8 -*-
import sys
from collections import defaultdict


def main(string, word):
    res = defaultdict(list)
    for item in word:
        if string.startswith(item):
            length = len(item)
            res[item].append(item)
            process(string[length:], word, res[item])

    return get_best(res)


def process(string, word, res_item):
    if string == '':
        return
    for item in word:
        if string.startswith(item):
            length = len(item)
            res_item.append(item)
            process(string[length:], word, res_item)


def get_best(res):
    values = res.values()
    max_sum = (0, 0)
    for item in values:
        cur_sum = 0
        for _ in item:
            cur_sum += len(_) ** 2
        max_sum = (cur_sum, item) if max_sum[0] < cur_sum else max_sum

    return ' '.join(max_sum[-1])


if __name__ == "__main__":
    # string = sys.stdin.readline().strip()
    # n = int(sys.stdin.readline().strip())
    # word = []
    # for i in range(n):
    #     word.append(sys.stdin.readline().strip())

    string = 'asdfjkl'
    word = ['as', 'asd', 'df', 'fjkl', 'jkl']
    print(main(string, word))