#include<string>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<utility>

using namespace std;

int get_diff_cost(const string& s1, const string& s2) {
    int cost = 0;
    for (size_t i = 0; i < s1.length(); ++i) {
        if (s1[i] != s2[i]) cost++;
    }
    return cost;
}


int find_ans_bf(string block, string type) { 
    if(block.size() < 3) return 0;
    map<string, long long> dp;
    dp[block.substr(0, 2)] = 0;
    for(int i = 2; i < block.size(); i++) {
        map<string, long long> addLast;
        for(auto& p:dp) {
            addLast[p.first+block[i]] = p.second;
        }
        dp = addLast;
        if(i%3 == 2) {
            int optionCost = i*(1+i)/2;
            string optionStr = "";
            for(int j = 0; j <= i; j++) {
                if(j%3 == 0) {
                    optionStr += (type[i]-'0'?'c':'a');
                } else if (j%3 == 1) {
                    optionStr += 'b';
                } else {
                    optionStr += (type[i]-'0'?'a':'c');
                }
            }
            for(auto& p : dp) {
                string curr = p.first;
                int currCost = p.second;
                optionCost = min(optionCost, currCost + get_diff_cost(curr, optionStr));
            }
            dp.clear();
            dp[optionStr] = optionCost;
        }
        if (i%3 == 0) {
            map<string, long long> newDp;
            vector<string>options;
            for(int j = 0; j <= i; j+=3) {
                for(char ch : {'a', 'b', 'c'}) {
                    string optionStr = "";
                    for(int k = 0; k <= i; k++) {
                        if(k == j) {
                            optionStr += ch;
                            continue;
                        }
                        if((k-(k>j))%3 == 0) {
                            optionStr += (type[i]-'0'?'c':'a');
                        } else if ((k-(k>j))%3 == 1) {
                            optionStr += 'b';
                        } else {
                            optionStr += (type[i]-'0'?'a':'c');
                        }
                    }
                    options.push_back(optionStr);
                }
            }
            for(auto& optionStr : options) {
                int optionCost = i*(1+i)/2;
                for(auto& p : dp) {
                    string curr = p.first;
                    int currCost = p.second;
                    optionCost = min(optionCost, currCost + get_diff_cost(curr, optionStr));
                }
                newDp[optionStr] = optionCost;
            }
            dp = newDp;
        }
        if (i%3 == 1) {
            map<string, long long> newDp;
            vector<string>options;
            for(int j1 = 0; j1 <= i; j1+=3) {
                for(int j2 = j1+1; j2 <= i; j2+=3) {
                    for(char ch1 : {'a', 'b', 'c'}) {
                        for(char ch2 : {'a', 'b', 'c'}) {
                            string optionStr = "";
                            for(int k = 0; k <= i; k++) {
                                if(k == j1) {
                                    optionStr += ch1;
                                    continue;
                                }
                                if(k == j2) {
                                    optionStr += ch2;
                                    continue;
                                }
                                if((k-((k>j2)+(k>j1)))%3 == 0) {
                                    optionStr += (type[i]-'0'?'c':'a');
                                } else if ((k-((k>j2)+(k>j1)))%3 == 1) {
                                    optionStr += 'b';
                                } else {
                                    optionStr += (type[i]-'0'?'a':'c');
                                }
                            }
                            options.push_back(optionStr);
                        }
                    }
                }
            }
            for(auto& optionStr : options) {
                int optionCost = i*(1+i)/2;
                for(auto& p : dp) {
                    string curr = p.first;
                    int currCost = p.second;
                    optionCost = min(optionCost, currCost + get_diff_cost(curr, optionStr));
                }
                newDp[optionStr] = optionCost;
            }
            dp = newDp;
        }
    }
    long long ans = 1e18;
    for(auto& p : dp) {
        ans = min(ans, (long long)p.second);
    }
    return ans;
}

int main() {
    string s, t;
    cin >> s >> t;
    if(s.size() <= 6) {
        cout << find_ans_bf(s, t) << "\n";
        return 0;
    }
    long long curCost = find_ans_bf(s.substr(0, 6), t.substr(0, 6));
    for(int i = 6; i < s.size(); i++) {
        if(i+2 < s.size()) {
            curCost += find_ans_bf((t[i-1]-'0'?"cba":"abc")+s.substr(i, 3), t.substr(i-3, 6));
            curCost += 2*(i/3-1)*((t[i]!=t[i-1])+(t[i]!=t[i+1])+(t[i+2]!=t[i+1]));
            i+=2;
        }
        else {
            curCost += find_ans_bf((t[i-1]-'0'?"cba":"abc")+s.substr(i), t.substr(i-3));
            curCost += 2*(i/3-1)*(t[i]!=t[i-1]);
            if(i+1 < s.size()) {
                curCost += 2*(i/3-1)*(t[i]!=t[i+1]);
            }
            break;
        }
    }
    cout << curCost << "\n";
    return 0;
}