#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>

using namespace std;

int solution(string &S, string &T) {
    int n = S.length();
    unordered_map<int, int> pos_diff; // Tracks positive differences
    unordered_map<int, int> neg_diff; // Tracks negative differences
    
    // Collect all mismatches
    for (int i = 0; i < n; ++i) {
        int diff = S[i] - T[i];
        if (diff > 0) pos_diff[diff]++;
        else if (diff < 0) neg_diff[-diff]++;
    }
    
    int swaps = 0;

    // Match pairs of differences to cancel out mismatches with minimal swaps
    for (auto &p : pos_diff) {
        int diff_value = p.first;
        int pos_count = p.second;
        
        if (neg_diff.find(diff_value) != neg_diff.end()) {
            int neg_count = neg_diff[diff_value];
            int matches = min(pos_count, neg_count);
            swaps += matches;
            pos_diff[diff_value] -= matches;
            neg_diff[diff_value] -= matches;
        }
    }

    // Count remaining mismatches, which need two swaps each
    int remaining_mismatches = 0;
    for (auto &p : pos_diff) remaining_mismatches += p.second;
    for (auto &p : neg_diff) remaining_mismatches += p.second;
    
    swaps += remaining_mismatches / 2;

    return swaps;
}

int main() {
    string S = "29162";
    string T = "10524";
    std::cout << "Minimum number of swaps: " << solution(S, T) << std::endl;
    return 0;
}