#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
const bool db = false;
int foo(char c) {
  if (c == 'R') return 0;
  if (c == 'G') return 1;
  if (c == 'B') return 2;
  throw;
  return -1;
}
char s[1000010], t[1000010];
int as[1000010], at[1000010], n, m;
int f[1000010][3][3];
int main() {
  gets(s + 1);
  n = strlen(s + 1);
  gets(t + 1);
  m = strlen(t + 1);
  for (int i = 1; i <= n; ++i) {
    as[i] = foo(s[i]);
  }
  for (int i = 1; i <= m; ++i) {
    at[i] = foo(t[i]);
  }
  for (int i = 2; i <= m; ++i) {
    memcpy(f[i], f[i - 1], sizeof(f[i]));
    if (at[i] == at[i - 1]) continue;
    f[i][at[i - 1]][at[i]] += 1;
  }
  int l = 1, r = 1;
  long long bar = 0;
  for (int i = 1; i <= n && l <= m; ++i) {
    while (at[r] != as[i] && r < m) {
      ++r;
    }
    bar += r - l + 1;
    if (i + 1 <= n) {
      bar -= f[r][as[i + 1]][as[i]] - f[l][as[i + 1]][as[i]];
    }
    if (r < m) ++r;
    if (at[l] == as[i]) ++l;
  }
  cout << bar << "\n";
  getchar();
  getchar();
  return 0;
}
