A weighted string is defined over an alphabet Σ together with a function f that assigns a weight to every character of the alphabet. The weight of a string s is the sum of the weights of all characters in s.
Several bioinformatics problems are formalized as problems on weighted strings. Protein mass spectrometry is one of them. If each amino acid is written as a distinct character, a protein becomes the string of characters of the amino acids that compose it.
One use of protein mass spectrometry is searching databases. The string that represents the protein is cut into substrings, the mass of each substring is determined, and the list of masses is compared against a protein database. Long strings have very many possible substrings, so how many of them are selected decides the quality of the result.
On his first day as an intern at a biotechnology laboratory, Carlos was given one task. Given a string s, compute the weight of every non-empty substring of consecutive characters of s and count how many distinct weights appear.
The string s consists of lowercase letters only, and the 26 lowercase letters have 26 different weights: a has weight 1, b has weight 2, and so on up to z with weight 26. Write a solution that handles the longest inputs comfortably.