#include using namespace std; #define st first #define nd second constexpr int maxn = 1000 * 1000 + 5; int A[maxn], B[maxn]; int mapping[500]; int cnt[4][4]; int res = maxn * 5; void czworki(int wyn) { for(int i = 1; i < 4; i++) { if(cnt[0][i] > 0) { res = min(res, wyn + cnt[0][i] * 3); return; } } res = min(res, wyn); } void trojki(int wyn) { vector>> tr; for(int a = 0; a < 4; a++) { for(int b = 0; b < 4; b++) { for(int c = 0; c < 4; c++) { if(a == c or a == b or b == c) continue; if(cnt[c][a] == 0 or cnt[a][b] == 0 or cnt[b][c] == 0) continue; tr.emplace_back(a, pair(b, c)); } } } do { int tmp[4][4]; for(int i = 0; i < 4; i++) { for(int j = 0; j < 4; j++) { tmp[i][j] = cnt[i][j]; } } int _wyn = wyn; for(auto t : tr) { int a, b, c; a = t.st; tie(b, c) = t.nd; auto x = min({cnt[a][b], cnt[b][c], cnt[c][a]}); cnt[a][b] -= x; cnt[b][c] -= x; cnt[c][a] -= x; _wyn += x * 2; } czworki(_wyn); for(int i = 0; i < 4; i++) { for(int j = 0; j < 4; j++) { cnt[i][j] = tmp[i][j]; } } } while(next_permutation(tr.begin(), tr.end())); } void pary() { vector> pary; for(int i = 0; i < 4; i++) { for(int j = i + 1; j < 4; j++) { pary.emplace_back(i, j); } } int wyn = 0; do { int tmp[4][4]; for(int i = 0; i < 4; i++) { for(int j = 0; j < 4; j++) { tmp[i][j] = cnt[i][j]; } } for(auto p : pary) { auto x = min(cnt[p.st][p.nd], cnt[p.nd][p.st]); cnt[p.st][p.nd] -= x; cnt[p.nd][p.st] -= x; wyn += x; } trojki(wyn); for(int i = 0; i < 4; i++) { for(int j = 0; j < 4; j++) { cnt[i][j] = tmp[i][j]; } } } while(next_permutation(pary.begin(), pary.end())); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); mapping['A'] = 0; mapping['C'] = 1; mapping['T'] = 2; mapping['G'] = 3; int n; for(auto* t : {A, B}) { string s; cin >> s; n = s.size(); for(int i = 0; i < s.size(); i++) { t[i] = mapping[s[i]]; } } for(int i = 0; i < n; i++) { if(A[i] != B[i]) cnt[A[i]][B[i]]++; } pary(); cout << res << endl; }