Codeforces Round 455 (Div. 2)
D
Colorful Points
Codeforces
2100
原题
← CE →
翻译中…

You are given a set of points on a straight line. Each point has a color assigned to it. For point $*a*$, its neighbors are the points which don't have any other points between them and $*a*$. Each point has at most two neighbors - one from the left and one from the right.

翻译中…

You perform a sequence of operations on this set of points. In one operation, you delete all points which have a neighbor point of a different color than the point itself. Points are deleted simultaneously, i.e. first you decide which points have to be deleted and then delete them. After that you can perform the next operation etc. If an operation would not delete any points, you can't perform it.

翻译中…

How many operations will you need to perform until the next operation does not have any points to delete?

翻译中…

Input

翻译中…

Input contains a single string of lowercase English letters 'a'-'z'. The letters give the points' colors in the order in which they are arranged on the line: the first letter gives the color of the leftmost point, the second gives the color of the second point from the left etc.

翻译中…

The number of the points is between 1 and $10^{6}$.

翻译中…

Output

翻译中…

Output one line containing an integer - the number of operations which can be performed on the given set of points until there are no more points to delete.

翻译中…

Note

翻译中…

In the first test case, the first operation will delete two middle points and leave points "ab", which will be deleted with the second operation. There will be no points left to apply the third operation to.

翻译中…

In the second test case, the first operation will delete the four points in the middle, leaving points "aa". None of them have neighbors of other colors, so the second operation can't be applied.

翻译中…

样例

Input #1
aabb
Output #1
2
InputCopy OutputCopy
Input #2
aabcaa
Output #2
1
InputCopy OutputCopy
题目信息
题号
909D
时间限制
2 s
内存限制
256 MB
标签
数据结构
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。