#C8916. Longest Fragments Sum
Longest Fragments Sum
Longest Fragments Sum
You are given several strings. For each string, partition it into the maximum number of non-overlapping contiguous fragments such that each fragment contains all occurrences of every character it includes. In other words, if a fragment contains a character ( c ), then all occurrences of ( c ) in the string must be within that fragment. Formally, for a given string ( s ) partitioned as ( { f_1, f_2, \dots, f_k } ), calculate the sum ( \sum_{i=1}^{k} |f_i| ), where ( |f_i| ) denotes the length of the fragment ( f_i ).
inputFormat
The first line contains an integer ( n ) representing the number of strings. Each of the next ( n ) lines contains a non-empty string consisting of lowercase English letters.
outputFormat
For each string, output the sum of the lengths of its fragments on a separate line.## sample
3
ababcbacadefegdehijhklij
abacbc
aabbcc
24
6
6
</p>