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 想要将这种结构重新应用到一首新歌中。正式地,给定一个由小写英文字母组成的非空单词 $S$,一首 $S$-歌由一个两行组成的块构成,该块可以使用相同的单词 $S$ 重复多次。每个块的形式如下:

$$ \begin{aligned} &\text{S, S Sity S} \\ &\text{i said S, S Sity 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.