#include <bits/stdc++.h>
const int INF = (int)(1e9);
const long long INFLL = (long long)(1e18);
const double EPS = 1e-13;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  string a, b;
  cin >> n >> a >> b;
  double total = 0.0, cnt = 0.0;
  vector<double> sum(26, 0.0);
  for (int i = 0; i < n; i++) {
    sum[a[i] - 'A'] += i + 1;
    total += sum[b[i] - 'A'] * (n - i);
  }
  sum.assign(26, 0.0);
  for (int i = n - 1; i >= 0; i--) {
    total += sum[b[i] - 'A'] * (i + 1);
    sum[a[i] - 'A'] += n - i;
  }
  for (int i = 1; i <= n; i++) cnt += (long long)i * i;
  cout.precision(9);
  cout.setf(ios::fixed);
  cout << (total / cnt) << endl;
}
