Codeforces Round 869 (Div. 1) |
---|

Finished |

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

string suffix structures

strings

*3500

No tag edit access

The problem statement has recently been changed. View the changes.

×
F. Entangled Substrings

time limit per test

2 secondsmemory limit per test

256 mebibytesinput

standard inputoutput

standard outputQuantum entanglement is when two particles link together in a certain way no matter how far apart they are in space.

You are given a string $$$s$$$. A pair of its non-empty substrings $$$(a, b)$$$ is called entangled if there is a (possibly empty) link string $$$c$$$ such that:

- Every occurrence of $$$a$$$ in $$$s$$$ is immediately followed by $$$cb$$$;
- Every occurrence of $$$b$$$ in $$$s$$$ is immediately preceded by $$$ac$$$.

In other words, $$$a$$$ and $$$b$$$ occur in $$$s$$$ only as substrings of $$$acb$$$. Compute the total number of entangled pairs of substrings of $$$s$$$.

A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by the deletion of several (possibly zero or all) characters from the beginning and several (possibly zero or all) characters from the end.

Input

The first and only line contains a string $$$s$$$ of lowercase English letters ($$$1 \leq |s| \leq 10^5$$$) — the string for which you should count pairs of entangled substrings.

Output

Output a single integer, the number of entangled pairs of substrings of $$$s$$$.

Examples

Input

abba

Output

1

Input

abacaba

Output

0

Input

abcabcabcabc

Output

5

Input

adamant

Output

82

Note

In the first example, the only entangled pair is (ab,ba). For this pair, the corresponding link string $$$c$$$ is empty, as they only occur as substrings of the whole string abba, which doesn't have any characters between ab and ba.

In the second example, there are no entangled pairs.

In the third example, the entangled pairs are (a,b), (b,c), (a,c), (a,bc), and (ab,c). For most pairs, the corresponding link string $$$c$$$ is empty, except for the pair (a,c), for which the link string $$$c$$$ is b, as a and c only occur as substrings of the string abc.

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/21/2024 04:24:16 (j2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|