b7d70ad95512b677beda673ec4df55b968dc0d3af62819d4bd483e1a1390fa2f
// https://szkopul.edu.pl/problemset/problem/L7i-kY2Zz46AW3vnrxHOmn5T/site/?key=statement
// OIJ XV 3 etap próbne
#include <iostream>
#include <queue>
#include <vector>
int main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
std::cout.tie(0);
int n;
std::cin >> n;
std::string s1, s2;
std::cin >> s1 >> s2;
int cC = 0, cB = 0;
char looker = 'C';
for (const auto& c : s1) {
if (c == 'C') {
cC++;
} else {
cB++;
}
}
if (cC > cB) {
looker = 'C';
} else {
looker = 'B';
}
std::queue<int> v;
for (int i = 0; i < s2.size(); i++) {
const auto& c = s2[i];
if (c == looker) {
v.push(i);
}
}
long long ans = 0;
for (int i = 0; i < s1.size(); i++) {
const auto& c = s1[i];
if (c != looker) {
auto hj = v.front();
v.pop();
ans += abs(i - hj) + 1;
}
}
std::cout << ans << '\n';
return 0;
}