아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Repetitive Song

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

요약
단어 값의 나열을 다른 위치 선택으로도 만들 수 있는, 가장 긴 부분수열의 길이를 구한다.
난이도

보통10점 중 7점

유형
문자열, 해시맵, 그리디
정답자
아직 제출이 없습니다

문제

Your younger sibling is obsessed with a fairly repetitive song. They claim that it is not repetitive, so you decided to prove your point by finding the longest (in terms of the number of words) subsequence of the song that your sibling cannot definitively identify within the full song lyrics.

More formally, a length-ℓ\ell subsequence of a song with nn words is a tuple of ℓ\ell integers 1≤s_1<s_2<⋯<s_ℓ≤n1 \leq s\_1 < s\_2 < \cdots < s\_\ell \leq n identifying the words in the subsequence. The subsequence is non-identifiable if there exists a different length-ℓ\ell subsequence 1≤t_1<t_2<⋯<t_L≤n1 \leq t\_1 < t\_2 < \cdots < t\_L \leq n (with s_i≠t_is\_i \neq t\_i for at least one index ii) where word s_1s\_1 in the song is identical to word t_1t\_1, word s_2s\_2 is identical to word t_2t\_2, etc.

Given the lyrics for a song, print the length of the longest non-identifiable subsequence.

입력

The first line of input contains a single integer nn (1≤n≤1051 \le n \leq 10^5) specifying the number of words in the song lyrics.

Each of the next nn lines contains one word of the song lyrics, given in order. Each word consists of up to 20 uppercase (A--Z) and lowercase (a--z) letters. The same word may appear on multiple lines. If two words do not match exactly (including the use of upper and lower case) then they are considered to be different words.

출력

Output a single integer ℓ\ell, the number of words in the longest non-identifiable song subsequence. If all of the song's subsequences are identifiable, print 00. When determining if a subsequence is identifiable, treat two words in the lyrics as identical if each of their corresponding characters are identical (in other words, case does matter).

예제2

  1. 예제 1

    입력
    10
    bow
    bow
    chick
    chicka
    chicka
    bow
    bow
    chick
    chicka
    chicka
    
    예상 출력
    9
    
  2. 예제 2

    입력
    31
    head
    shoulders
    knees
    and
    toes
    knees
    and
    toes
    head
    shoulders
    knees
    and
    toes
    knees
    and
    toes
    eyes
    and
    ears
    and
    mouth
    and
    nose
    head
    shoulders
    knees
    and
    toes
    knees
    and
    toes
    
    예상 출력
    29