#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;
}
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="";
for(int j=0; j<k; j++)
s1.push_back(s[j+i]);
if(sel>s1)
sel=s1;
}
ans+=count_cost(sel);
}
cout<<ans nl;
}
int32_t main() {
fast_io;
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBpbnQgbGw7CiNkZWZpbmUgZmFzdF9pbyAgICAgICAgICAgICAgICAgICAgIFwKICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsgXAogIGNpbi50aWUoTlVMTCk7ICAgICAgICAgICAgICAgICAgICBcCiAgY291dC50aWUoTlVMTCkKI2RlZmluZSBubCA8PCAiXG4iCgppbnQgY291bnRfY29zdChzdHJpbmcgcykKewogICAgaW50IGFucz0wOwogICAgZm9yKGludCBpPTA7IGk8cy5zaXplKCk7IGkrKykKICAgIHsKICAgICAgICBpbnQgYT1zW2ldLSdhJzsKICAgICAgICBhKys7CiAgICAgICAgYW5zKz1hOwogICAgfQogICAgcmV0dXJuIGFuczsKfQoKdm9pZCBzb2x2ZSgpIHsKICAgIGludCBuLGs7CiAgICBjaW4+Pm47CiAgICBrPTE1OwogICAgaW50IGFucz0wOwogICAgd2hpbGUobi0tKQogICAgewogICAgICAgIHN0cmluZyBzOwogICAgICAgIGNpbj4+czsKICAgICAgICBpbnQgYT1zLnNpemUoKTsKICAgICAgICBzKz1zOwogICAgICAgIHN0cmluZyBzZWw9Inp6enp6enp6enp6enp6eiI7CiAgICAgICAgZm9yKGludCBpPTA7IGk8YTsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgc3RyaW5nIHMxPSIiOwogICAgICAgICAgICBmb3IoaW50IGo9MDsgajxrOyBqKyspCiAgICAgICAgICAgICAgICBzMS5wdXNoX2JhY2soc1tqK2ldKTsKICAgICAgICAgICAgaWYoc2VsPnMxKQogICAgICAgICAgICAgICAgc2VsPXMxOwogICAgICAgIH0KICAgICAgICBhbnMrPWNvdW50X2Nvc3Qoc2VsKTsKICAgIH0KICAgIGNvdXQ8PGFucyBubDsKfQoKaW50MzJfdCBtYWluKCkgewogICAgZmFzdF9pbzsKICAgIHNvbHZlKCk7CiAgICByZXR1cm4gMDsKfQo=