#include <bits/stdc++.h>
using namespace std;
int n, m, sum[1000007][3][3], l = 1, r = 1;
long long res;
char a[1000007], b[1000007];
int to(char c) { return c == 'R' ? 0 : c == 'G' ? 1 : 2; }
int main() {
  scanf("%s%s", a + 1, b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  for (int i = 2; i <= m; i++) {
    for (int x = 0; x <= 2; x++)
      for (int y = 0; y <= 2; y++) sum[i][x][y] = sum[i - 1][x][y];
    sum[i][to(b[i - 1])][to(b[i])]++;
  }
  while (r < m && b[r] != a[1]) r++;
  res = r - l + 1;
  for (int i = 2; i <= n; i++) {
    if (l <= m && a[i - 1] == b[l]) l++;
    if (l > m) break;
    if (r < m) {
      r++;
      while (r < m && b[r] != a[i]) r++;
    }
    if (l > r) continue;
    res += r - l + 1;
    if (a[i - 1] != a[i])
      res -=
          sum[r][to(a[i])][to(a[i - 1])] - sum[l - 1][to(a[i])][to(a[i - 1])];
  }
  cout << res << endl;
  return 0;
}
