#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
char s[N], ss[N];
int n, m;
int p1[N], p2[N];
int f[N][3][3];
long long ans;
void dfs(char *s, int n, char *t, int m, int *sum) {
  for (int i = 1; i <= n; ++i) {
    sum[i] = sum[i - 1] + 1;
    while (sum[i] < m && t[sum[i]] != s[i]) sum[i]++;
    sum[i] = min(sum[i], m);
  }
}
int turn(char x) { return x == 'R' ? 0 : (x == 'G' ? 1 : 2); }
int main() {
  scanf("%s%s", s + 1, ss + 1);
  n = strlen(s + 1);
  m = strlen(ss + 1);
  dfs(s, n, ss, m, p1);
  dfs(ss, m, s, n, p2);
  for (int i = 2; i <= m; ++i)
    for (int j = 0; j <= 2; ++j)
      for (int k = 0; k <= 2; ++k) {
        if (turn(ss[i - 1]) == j && turn(ss[i]) == k)
          f[i][j][k] = f[i - 1][j][k] + 1;
        else
          f[i][j][k] = f[i - 1][j][k];
      }
  int l = 1;
  for (int i = 1; i <= n; ++i) {
    int r = p1[i];
    while (l <= m && p2[l] < i) l++;
    ans += max(r - l + 1, 0);
    if (l <= r && i > 1) {
      int p = turn(s[i - 1]), pp = turn(s[i]);
      if (p != pp) (ans -= f[r][pp][p]) += f[l - 1][pp][p];
    }
  }
  printf("%lld\n", ans);
  return 0;
}
