#include <bits/stdc++.h>
const double eps = 1e-9;
const double pi = acos(-1);
const int oo = 1000000000;
const int mod = 1000000007;
const double E = 2.7182818284590452353602874713527;
using namespace std;
char a[1000005], b[1000005], t[555];
int st[1000005], en[1000005], v[1000005][3][3];
int main() {
  int n, la, lb;
  long long ans = 0;
  scanf("%d\n", &n);
  gets(a + 1);
  gets(b + 1);
  la = strlen(a + 1);
  lb = strlen(b + 1);
  int j = 1;
  for (int i = 1; i <= la; i++) {
    while (j < lb && b[j] != a[i]) j++;
    en[i] = j;
    if (j < lb) j++;
  }
  st[j = 1] = 1;
  for (int i = 1; i <= lb; i++) {
    while (j < la && b[i] != a[j]) st[++j] = i;
    if (j < la) st[++j] = i + 1;
  }
  while (j < la) st[++j] = lb + 1;
  for (int i = 1; i <= la; i++) ans += en[i] - st[i] + 1;
  t['G'] = 1;
  t['B'] = 2;
  for (int i = 2; i <= lb; i++) {
    for (int j = 0; j < 3; j++)
      for (int k = 0; k < 3; k++) v[i][j][k] = v[i - 1][j][k];
    v[i][t[b[i]]][t[b[i - 1]]]++;
  }
  for (int i = 2; i <= la; i++)
    if (a[i] != a[i - 1])
      ans -=
          v[en[i]][t[a[i - 1]]][t[a[i]]] - v[st[i] - 1][t[a[i - 1]]][t[a[i]]];
  cout << ans << endl;
  return 0;
}
