#include<stdio.h>
main()
{
char c;
int i, sum;
i = sum = 0;
while ((c = getchar()) != '#') {
if (c == '\n') {
printf("%d\n", sum);
i = sum = 0;
continue;
}
i++;
if (c != ' ')
sum += (c-'A'+1)*i;
}
}