//Trenton Hidenfelter
//2/3/2020
//ACSL contest 2 Int5
//Enloe Magnet HS

#include 
#include 
#include 
#include 
#include 

using namespace std;

//ifstream infile ("E:\\trent4.cpp\\Input files\\intSampleInput2.txt");
ifstream infile ("F:\\2inttest.txt");

vector  > inputs; //A vector of vectors to handle all five inputs

void input() {
    string inputstring;
    for (int i = 0; i < 10; i ++)
    {
        infile >> inputstring;

        vector  word;
        inputs.push_back(word);

        for (int j = 0; j < inputstring.length(); j ++)
        {
            inputs[i].push_back(inputstring[j]);
        }
        //cout << inputs[i].size() << endl;
    }
}

void findlikes(int pos) {
    //cout << inputs[pos].size() << endl; //Testing line to make sure the code isn't stupid
    int i = 0;
    bool done = false; //Has the code been thoroughly scanned through?
    bool singlerem = false; //Has it scanned for removable letters to shift the word yet?
    while (!done)
    {
        i = 0;
        while (i < inputs[pos].size() && i < inputs[pos+1].size())
        {
            if (inputs[pos][i] == inputs[pos+1][i])
            {
                inputs[pos].erase(inputs[pos].begin() + i);
                inputs[pos+1].erase(inputs[pos+1].begin() + i);
                singlerem = false;
            }
            else
            {
                i++;
            }
        }
        //cout << endl;
        //for (int i = 0; i < inputs[pos].size(); i ++)
        //{
            //cout << i << endl;
            //cout << inputs[pos][i] << " " << inputs[pos+1][i] << endl;
        //}
        //cout << endl;
        if (singlerem)
            done = true;
        i = 0;
        if (!singlerem) //This area scans for removable letters to shift the word
        {
            while (i < inputs[pos].size() - 1 && i < inputs[pos+1].size() - 1)
            {
                if (inputs[pos][i] == inputs[pos+1][i+1]) //Remove from the second word first because that is the failsafe one
                {
                    inputs[pos+1].erase(inputs[pos+1].begin()+i);
                    i = inputs[pos].size();
                }
                else if (inputs[pos][i+1] == inputs[pos+1][i]) //If second word can't be shifted, then look in the first word
                {
                    inputs[pos].erase(inputs[pos].begin()+i);
                    i = inputs[pos].size();
                }
                i ++;
            }
        }
        singlerem = true;
    }
    //cout << inputs[pos].size() << endl;
    //cout << inputs[pos+1].size() << endl;

}

int calculate(int pos) {
    int asf = 0;
    //cout << inputs[pos+1].size() << endl;
    if (inputs[pos].size() <= inputs[pos+1].size())
    {
        for (int i = 0; i < inputs[pos].size(); i ++) //Adds the differences in the character places
        {
            asf += (int)(inputs[pos][i]) - (int)(inputs[pos+1][i]);
        }
    }
    else if (inputs[pos].size() > inputs[pos+1].size())
    {
        for (int i = 0; i < inputs[pos+1].size(); i ++) //Adds the differences in the character places
        {
            //cout << (int)(inputs[pos][i])-(int)(inputs[pos+1][i]) << endl;
            asf += (int)(inputs[pos][i]) - (int)(inputs[pos+1][i]);
        }
    }
    if (inputs[pos].size() > inputs[pos+1].size()) //These four lines add the extra characters
        asf += inputs[pos].size() - inputs[pos+1].size();
    else if (inputs[pos].size() < inputs[pos+1].size())
        asf += inputs[pos+1].size() - inputs[pos].size();
    return asf;
}

int main()
{
    input();
    findlikes(0);
    cout << calculate(0) << endl;
    findlikes(2);
    cout << calculate(2) << endl;
    findlikes(4);
    cout << calculate(4) << endl;
    findlikes(6);
    cout << calculate(6) << endl;
    findlikes(8);
    cout << calculate(8) << endl;
    return 0;
}