#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
char str[N];
long long l[N][26], r[N][26];
void init() {
  memset(l, 0, sizeof(l));
  memset(r, 0, sizeof(r));
}
int main(int argc, char *argv[]) {
  int n;
  while (cin >> n) {
    init();
    scanf("%s", str + 1);
    for (int i = (1); i <= (n); ++i) {
      int id = str[i] - 'A';
      for (int j = 0; j < (26); ++j)
        if (j == id)
          l[i][j] = l[i - 1][j] + i;
        else
          l[i][j] = l[i - 1][j];
    }
    for (int i = (n); i >= (1); --i) {
      int id = str[i] - 'A';
      for (int j = 0; j < (26); ++j)
        if (j == id)
          r[i][j] = r[i + 1][j] + n - i + 1;
        else
          r[i][j] = r[i + 1][j];
    }
    double ans = 0, sum = 0;
    scanf("%s", str + 1);
    for (int i = (1); i <= (n); ++i) {
      int id = str[i] - 'A';
      ans += (long long)i * r[i][id];
    }
    for (int i = (n); i >= (1); --i) {
      int id = str[i] - 'A';
      ans += (long long)(n - i + 1) * l[i - 1][id];
    }
    for (int i = (1); i <= (n); ++i) sum += (long long)i * (long long)i;
    printf("%.8lf\n", (double)ans / sum);
  }
  return 0;
}
