#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1000005;
int n, m, c[Maxn][3][3];
char a[Maxn], b[Maxn];
long long ans = 0;
char trans(char c) {
  if (c == 'R') return 0;
  if (c == 'G') return 1;
  if (c == 'B') return 2;
}
int main() {
  scanf(" %s %s", a + 1, b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  for (int i = 1; i <= n; i++) a[i] = trans(a[i]);
  for (int i = 1; i <= m; i++) b[i] = trans(b[i]);
  for (int i = 2; i <= m; i++)
    memcpy(c[i], c[i - 1], 9 << 2), ++c[i][b[i]][b[i - 1]];
  int l = 1, r = 1;
  for (int i = 1; i <= n; i++) {
    while (r < m && b[r] != a[i]) ++r;
    ans += r - l + 1;
    if (i < n && a[i] != a[i + 1])
      ans -= c[r][a[i]][a[i + 1]] - c[l][a[i]][a[i + 1]];
    if ((l += a[i] == b[l]) > m) break;
    if (r < m) r += a[i] == b[r];
  }
  cout << ans << endl;
  return 0;
}
