#include <bits/stdc++.h>
using namespace std;
int n;
string s1, s2;
long long sum1[26], sum2[26], d;
double res;
int main() {
  cin >> n;
  cin >> s1 >> s2;
  int i;
  for (i = 0; i < n; i++) d += 1LL * (n - i) * (n - i);
  for (i = 0; i < n; i++) {
    int p = s1[i] - 'A';
    res += (double)sum2[p] / d * (n - i);
    sum1[p] += i + 1;
    p = s2[i] - 'A';
    res += (double)sum1[p] / d * (n - i);
    sum2[p] += i + 1;
  }
  printf("%.9f", res);
}
