QOJ.ac

QOJ

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

#14136. 滑稽歌曲

Statistics

KiKoS 是電視劇《老爸老媽的浪漫史》("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.