QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#14136. 우스꽝스러운 노래

Statistics

KiKoS는 TV 시리즈 "How I Met Your Mother"의 팬입니다. 최근에 그는 이 드라마의 사운드트랙이 담긴 스포티파이(Spotify) 플레이리스트를 발견했습니다.

누구나 인정하는 히트곡인 "Let's Go to the Mall"과 "Nothing Suits Me Like a Suit" 옆에서, 그는 아주 우스꽝스러운 노래인 "Bang bang bangity bang"을 발견했습니다. 이 구절은 기본적으로 노래 전체에서 유일한 가사입니다. 노래를 더 길게 만들려면 같은 줄을 말하되 앞에 "I said"를 붙이고, 다시 전체를 부르면 됩니다.

초보 작곡가인 KiKoS는 새로운 노래에 이 구조를 재사용하고 싶어 합니다. 엄밀하게 말해서, 영어 소문자로 이루어진 비어 있지 않은 단어 $\mathbb{S}$가 주어졌을 때, $\mathbb{S}$-노래는 같은 단어 $\mathbb{S}$를 사용하여 여러 번 반복될 수 있는 두 줄짜리 블록으로 구성됩니다. 각 블록의 형태는 다음과 같습니다:

$$ \begin{aligned} &\mathbb{S}\texttt{, }\mathbb{S}\texttt{ }\mathbb{S}\texttt{ity }\mathbb{S} \\ &\texttt{i said }\mathbb{S}\texttt{, }\mathbb{S}\texttt{ }\mathbb{S}\texttt{ity }\mathbb{S} \end{aligned} $$

여러 줄로 이루어진 긴 텍스트가 주어졌을 때, 올바른 노래를 이루는 연속된 블록들의 나열에 포함될 수 있는 최대 문자 수를 구하세요.

입력

입력은 여러 줄로 이루어져 있으며, 영어 소문자, 쉼표, 공백으로 구성됩니다. 각 줄은 줄바꿈 문자로 끝납니다. 줄바꿈 문자를 포함한 전체 문자 수는 $10^5$을 넘지 않습니다.

빈 줄은 없으며, 각 줄은 공백으로 시작하거나 끝나지 않습니다.

출력

노래 패턴과 일치하는 연속된 블록들의 나열에 포함될 수 있는 최대 문자 수를 나타내는 정수 하나를 출력하세요. 여기에는 노래의 마지막 줄을 포함하여 나열된 각 줄 끝에 있는 줄바꿈 문자도 포함됩니다. 각 줄바꿈 문자는 $1$개의 문자로 간주됩니다(Windows 환경을 사용하는 경우 이 점에 유의하세요).

노래 패턴과 일치하는 블록이 하나도 없다면 $-1$을 출력하세요.

예제

입력 1

bang, bang bangity bang
i said bang, bang bangity bang

출력 1

55

입력 2

bang, bang bangity bang
i said bang, bang bangity bang
bank, bank bankity bank
i said bank, bank bankity bank
bank, bank bankity bank
i said bank, bank bankity bank

출력 2

110

입력 3

grandmasters are red,
experts are blue,
parsing problems are bad,
but we believe in you

출력 3

-1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.