#include <bits/stdc++.h>
using namespace std;
const int V = 300000;
long long n;
char a[V], b[V];
vector<long long> va[30], vb[30];
long long sum[V];
int main() {
  cin >> n;
  scanf("%s", a);
  scanf("%s", b);
  for (int i = 0; i < n; ++i) {
    va[a[i] - 'A'].push_back(i);
    vb[b[i] - 'A'].push_back(i);
  }
  double ans = 0;
  for (int ii = 0; ii < 26; ++ii) {
    vector<long long>&v1 = va[ii], v2 = vb[ii];
    sum[v2.size()] = 0;
    for (int j = (int)v2.size() - 1; j >= 0; --j) {
      sum[j] = sum[j + 1] + n - v2[j];
    }
    long long left = 0;
    int j = 0;
    for (int i = 0; i < v1.size(); ++i) {
      while (j < v2.size() && v1[i] > v2[j]) {
        left += (v2[j] + 1);
        j++;
      }
      ans += (v1[i] + 1) * sum[j];
      ans += (n - v1[i]) * left;
    }
  }
  long long c1 = (n + 1) * (2 * n + 1) * n / 6;
  printf("%.10f\n", (double)ans / c1);
}
