#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
char s1[maxn], s2[maxn];
long long dp[maxn][3][3];
int p1[maxn], p2[maxn], n, m;
int mp(char a) { return a == 'G' ? 0 : (a == 'R' ? 1 : 2); }
void ini(const char a[], int n, const char b[], int m, int p[]) {
  p[0] = 0;
  for (int i = 1; i < n + 1; i++) {
    p[i] = p[i - 1] + 1;
    while (p[i] <= m && a[i] != b[p[i]]) p[i]++;
    p[i] = min(p[i], m);
  }
}
int main() {
  scanf("%s", s1 + 1);
  scanf("%s", s2 + 1);
  n = strlen(s1 + 1);
  m = strlen(s2 + 1);
  ini(s1, n, s2, m, p1);
  ini(s2, m, s1, n, p2);
  memset(dp, 0ll, sizeof(dp));
  for (int i = 2; i < m + 1; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (mp(s2[i - 1]) == j && mp(s2[i]) == k)
          dp[i][j][k] = dp[i - 1][j][k] + 1;
        else
          dp[i][j][k] = dp[i - 1][j][k];
      }
    }
  }
  long long ret = 0ll;
  int l = 1, r;
  for (int i = 1; i < n + 1; i++) {
    r = p1[i];
    while (l <= m && p2[l] < i) l++;
    ret += max(r - l + 1, 0);
    if (i > 1 && l <= r) {
      int j = mp(s1[i - 1]);
      int k = mp(s1[i]);
      if (j != k) {
        ret -= dp[r][k][j];
        ret += dp[l - 1][k][j];
      }
    }
  }
  cout << ret << endl;
  return 0;
}
