#K46862. Contrast Score Calculation

    ID: 28071 Type: Default 1000ms 256MiB

Contrast Score Calculation

Contrast Score Calculation

You are given a string s of length n. The contrast score of the string is defined as the number of ordered pairs \((i,j)\) such that:

  • \(0 \le i < j < n\)
  • s[i] \neq s[j]

Your task is to compute the contrast score for each given test case.

Example:

  • For s = "abc", the valid pairs are: (0,1), (0,2), (1,2) and the answer is 3.
  • For s = "aab", the valid pairs are: (0,2), (1,2) and the answer is 2.
  • For s = "zzz", no valid pair exists, so the answer is 0.

inputFormat

The input is read from stdin and has the following format:

T
s1
s2
...
sT

Where:

  • T is an integer representing the number of test cases.
  • Each of the following T lines contains a non-empty string s.

outputFormat

For each test case, output the contrast score of the corresponding string on a separate line to stdout.

## sample
3
abc
aab
zzz
3

2 0

</p>