Codeforces Round 562 (Div. 1)
B
Good Triple
Codeforces
1900
原题
← AC →
翻译中…

Toad Rash has a binary string $s$. A binary string consists only of zeros and ones.

翻译中…

Let $n$ be the length of $s$.

翻译中…

Rash needs to find the number of such pairs of integers $l$, $r$ that $1 \leq l \leq r \leq n$ and there is at least one pair of integers $x$, $k$ such that $1 \leq x, k \leq n$, $l \leq x \lt x + 2k \leq r$, and $s_x = s_{x+k} = s_{x+2k}$.

翻译中…

Find this number of pairs for Rash.

翻译中…

Input

翻译中…

The first line contains the string $s$ ($1 \leq |s| \leq 300\,000$), consisting of zeros and ones.

翻译中…

Output

翻译中…

Output one integer: the number of such pairs of integers $l$, $r$ that $1 \leq l \leq r \leq n$ and there is at least one pair of integers $x$, $k$ such that $1 \leq x, k \leq n$, $l \leq x \lt x + 2k \leq r$, and $s_x = s_{x+k} = s_{x+2k}$.

翻译中…

Note

翻译中…

In the first example, there are three $l$, $r$ pairs we need to count: $1$, $6$; $2$, $6$; and $1$, $5$.

翻译中…

In the second example, there are no values $x$, $k$ for the initial string, so the answer is $0$.

翻译中…

样例

Input #1
010101
Output #1
3
InputCopy OutputCopy
Input #2
11001100
Output #2
0
InputCopy OutputCopy
题目信息
题号
1168B
时间限制
4 s
内存限制
256 MB
标签
暴力
双指针

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