#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast_io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define nl << "\n"
int count_cost(string s)
{
int ans=0;
for(int i=0;i<s.size();i++)
{
int a=s[i]-'a';
a++;
ans+=a;
}
//cout<<"Cost of string "<<s<<" is -> "<<ans nl;
return ans;
}
void solve() {
int n,k;
cin>>n;
k=15;
int ans=0;
while(n--)
{
string s;
cin>>s;
int a=s.size();
s+=s;
string sel="zzzzzzzzzzzzzzz";
for(int i=0;i<a;i++)
{
string s1;
s1=s.substr(i,k);
if(sel>s1)
sel=s1;
}
ans+=count_cost(sel);
}
cout<<ans nl;
}
int32_t main() {
fast_io;
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKdHlwZWRlZiBsb25nIGxvbmcgaW50IGxsOwojZGVmaW5lIGZhc3RfaW8gICAgICAgICAgICAgICAgICAgICBcCiAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7IFwKICBjaW4udGllKE5VTEwpOyAgICAgICAgICAgICAgICAgICAgXAogIGNvdXQudGllKE5VTEwpCiNkZWZpbmUgbmwgPDwgIlxuIgogCmludCBjb3VudF9jb3N0KHN0cmluZyBzKQp7CiAgICBpbnQgYW5zPTA7CiAgICBmb3IoaW50IGk9MDtpPHMuc2l6ZSgpO2krKykKICAgIHsKCWludCBhPXNbaV0tJ2EnOwoJYSsrOwoJYW5zKz1hOwogICAgfQogICAgLy9jb3V0PDwiQ29zdCBvZiBzdHJpbmcgIjw8czw8IiBpcyAtPiAiPDxhbnMgbmw7CiAgICByZXR1cm4gYW5zOwp9CiAKdm9pZCBzb2x2ZSgpIHsKICAgIGludCBuLGs7CiAgICBjaW4+Pm47CiAgICBrPTE1OwogICAgaW50IGFucz0wOwogICAgd2hpbGUobi0tKQogICAgewoJc3RyaW5nIHM7CgljaW4+PnM7CglpbnQgYT1zLnNpemUoKTsKCXMrPXM7CglzdHJpbmcgc2VsPSJ6enp6enp6enp6enp6enoiOwoJZm9yKGludCBpPTA7aTxhO2krKykKCXsKCSAgICBzdHJpbmcgczE7CgkgICAgczE9cy5zdWJzdHIoaSxrKTsKCSAgICBpZihzZWw+czEpCgkJc2VsPXMxOwoJfQoJYW5zKz1jb3VudF9jb3N0KHNlbCk7CiAgICB9CiAgICBjb3V0PDxhbnMgbmw7Cn0KIAppbnQzMl90IG1haW4oKSB7CiAgZmFzdF9pbzsKICBzb2x2ZSgpOwogIHJldHVybiAwOwp9Cg==