Annoying Alliterations

시간 제한2초메모리 제한1024 MB

요약
두 단어를 골라 첫 글자가 서로 다를 때까지 앞 글자를 함께 지우고, 남은 두 단어 길이의 합의 최댓값을 구한다.
난이도

보통10점 중 7점

유형
문자열, 트라이, 완전 탐색
정답자
아직 제출이 없습니다

문제

Bajtazar is a member of the jury for the Find Your Palace Contest, a prestigious programming competition that offers a luxurious palace to the winner. He is now trying to come up with a name for his problem. According to Bajtazar, a good problem name consists of exactly two words. Additionally, Bajtazar finds alliterations very annoying, so he will remove the first letter from both words until the first letter of the two words is different or one of them becomes empty. After this operation, Bajtazar defines the goodness of the problem name as the sum of lengths of the two words.

He has prepared a list of nn words, and started to wonder what is the maximum goodness that can be achieved using the words from the list. Bajtazar himself does not have time to answer that question as he is busy reinforcing the tests with nasty edge cases. Help Bajtazar by finding the maximum goodness that can be achieved.

입력

The input consists of:

  • One line with an integer nn (2≤n≤2⋅1052\leq n\leq 2\cdot10^5), the number of words.
  • nn lines, each with a word ww (1≤∣w∣≤1061\leq |w|\leq 10^6). Each word only consists of English lowercase letters (a-z).

The total number of characters in the nn words is at most 10610^6.

출력

Output the maximum goodness that can be achieved.

예제3

  1. 예제 1

    입력
    3
    amsterdam
    is
    amazing
    
    예상 출력
    12
    
  2. 예제 2

    입력
    3
    bbb
    abbba
    aaba
    
    예상 출력
    8
    
  3. 예제 3

    입력
    2
    abcdefghijklmnopqrstuvwxyz
    abcdefghijklmnopqrstuvwxyz
    
    예상 출력
    0