#include <bits/stdc++.h>
void convert(char *ss, int n) {
  int i;
  for (i = 0; i < n; i++)
    if (ss[i] == 'R')
      ss[i] = 0;
    else if (ss[i] == 'G')
      ss[i] = 1;
    else
      ss[i] = 2;
}
int main() {
  static char ss[1000000 + 1 + 1], tt[1000000 + 1 + 1];
  static int kk[9], jj[1000000 + 1], ii[1000000 + 1];
  int n, m, i, j, jl, jr;
  long long ans;
  scanf("%s%s", ss + 1, tt + 1);
  ss[0] = tt[0] = 'R';
  n = strlen(ss), m = strlen(tt);
  convert(ss, n), convert(tt, m);
  for (i = 0, j = 0; i < n; i++, j++) {
    while (j < m && tt[j] != ss[i]) j++;
    jj[i] = j;
  }
  for (j = 0, i = 0; j < m; j++, i++) {
    while (i < n && ss[i] != tt[j]) i++;
    ii[j] = i;
  }
  ans = 0;
  for (i = 1, jl = 1, jr = 0; i < n; i++) {
    int c;
    while (jr < jj[i] && jr < m - 1) {
      jr++;
      c = tt[jr - 1] * 3 + tt[jr];
      kk[c]++;
    }
    while (jl <= jr && ii[jl] < i) {
      c = tt[jl - 1] * 3 + tt[jl];
      kk[c]--;
      jl++;
    }
    ans += jr - jl + 1;
    if (ss[i - 1] != ss[i]) {
      c = ss[i] * 3 + ss[i - 1];
      ans -= kk[c];
    }
  }
  printf("%lld\n", ans);
  return 0;
}
