#K41012. Distinct Substrings with Matching Endpoints

    ID: 26771 Type: Default 1000ms 256MiB

Distinct Substrings with Matching Endpoints

Distinct Substrings with Matching Endpoints

Given a string \(s\) consisting of both uppercase and lowercase English letters, count the number of distinct substrings that start and end with the same character. A substring is defined as a contiguous sequence of characters and can be of any length (including 1). In other words, for any substring \(s[i\dots j]\), it should satisfy \(s[i] = s[j]\).

For example:

  • For \(s = "abcab"\), the answer is 7.
  • For \(s = "aaa"\), the answer is 6.

The input is read from standard input and the output is printed to standard output.

inputFormat

A single line containing the string \(s\). The string may include both lowercase and uppercase English letters, or it can be empty.

outputFormat

An integer representing the count of distinct substrings that start and end with the same character.

## sample
abcab
7