#include 
#include 
#include 
#include 

// Liam Doak
// Feb. 3, 2020
// Int5
// Enloe
// Potter

using namespace std;

void str_to_vec (string str, vector & vec)
{

    for (int i = 0; i < str.length (); i++)
        vec.push_back (str[i]);

}

void align (vector & vec)
{

    for (int i = 0; i < vec.size (); i++)
        if (vec[i] == '0')
        {

            vec.erase (vec.begin () + i);
            i -= 1;

        }

}

void cancel (vector & first, vector & second)
{

    for (int i = 0; i < first.size () && i < second.size (); i++)
        if (first[i] == second[i])
        {

            first[i] = '0';
            second[i] = '0';

        }

}

bool check_and_delete (vector & first, vector & second)
{

    bool matches = false;

    for (int i = 0; i < first.size () && i < second.size () && !matches; i++)
    {

        if (second[i + 1] == first[i])
        {

            second[i] = '0';
            matches = true;

        }

        else if (first[i + 1] == second[i])
        {

            first[i] = '0';
            matches = true;

        }

    }

    return matches;

}

int score (vector first, vector second)
{

    int asf = 0;
    int rem_i = 0;

    for (int i = 0; i < first.size () && i < second.size (); i++)
    {

        asf += (first[i] - second[i]);
        rem_i = i;

    }

    if (rem_i < first.size ())
    {

        asf += first.size () - rem_i - 1;

    }

    if (rem_i < second.size ())
    {

        asf += second.size () - rem_i - 1;

    }

    return asf;

}

void input_and_solve()
{

    ifstream infile;
    infile.open ("E:\\files\\acsl2int.txt");

    if (infile.is_open ())
    {

        vector  first, second;

        while (infile.good ())
        {

            first.clear ();
            second.clear ();

            string f, s;
            getline (infile, f, ' ');
            infile.ignore(0);
            getline (infile, s, '\n');
            infile.ignore(0);

            str_to_vec (f, first);
            str_to_vec (s, second);


            do
            {

                align (first);
                align (second);
                cancel (first, second);
                align (first);
                align (second);

            }

            while (check_and_delete (first, second));

            align (first);
            align (second);

            cout << score (first, second) << endl;


        }

    }

    else
        cout << "The ASF says: file DNE!" << endl;

}

int main (void)
{

    input_and_solve ();

    return 0;

}