A warehouse barcode is a string of lowercase English letters, where each letter names a shelf weight class: 'a' is the heaviest class with weight value 26, 'b' has weight value 25, and so on down to 'z', which has weight value 1 — in general, letter c has weight value 26 - (position of c in the alphabet, 0-indexed for 'a'). Scanning the barcode from left to right, the letter at the i-th position (1-indexed) contributes weight(letter) * i to the barcode's drift score. Compute the total drift score: the sum of these contributions over every position in the barcode.
A single line containing the barcode s: a non-empty string of lowercase English letters ('a'-'z').
Print a single integer: the drift score of s. The result can exceed the range of a 32-bit signed integer, so use a 64-bit (or arbitrary-precision) integer type to compute and print it.
1 <= length of s <= 100000
Example 1
Input
abc
Expected
148
Explanation
'a' has weight 26 and sits at position 1, contributing 26*1=26. 'b' has weight 25 at position 2, contributing 25*2=50. 'c' has weight 24 at position 3, contributing 24*3=72. The drift score is 26 + 50 + 72 = 148.
Example 2
Input
z
Expected
1
Explanation
'z' has weight 1 and sits at position 1, so the drift score is 1*1 = 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →