#include <bits/stdc++.h>
using namespace std;
const int maxn(1e6 + 5);
int n, m, s[3][3][maxn], mp[6666];
long long ans;
char s1[maxn], s2[maxn];
int main() {
  scanf(" %s %s", s1 + 1, s2 + 1);
  n = strlen(s1 + 1), m = strlen(s2 + 1);
  mp['R'] = 0, mp['G'] = 1, mp['B'] = 2;
  for (int i = 1; i <= n; ++i) s1[i] = mp[s1[i]];
  for (int i = 1; i <= m; ++i) s2[i] = mp[s2[i]];
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 3; ++j)
      for (int k = 0; k < 3; ++k) s[j][k][i] = s[j][k][i - 1];
    ++s[s1[i - 1]][s1[i]][i];
  }
  for (int i = 1, l = 1, r = 0; i <= m; ++i) {
    if (r < n) ++r;
    while (r < n && s1[r] != s2[i]) ++r;
    if (l > n) break;
    ans += r - l + 1;
    if (i && s2[i - 1] != s2[i])
      ans -= s[s2[i]][s2[i - 1]][r] - s[s2[i]][s2[i - 1]][l];
    if (s1[l] == s2[i]) ++l;
  }
  printf("%lld\n", ans);
  return 0;
}
