#include <bits/stdc++.h>
using namespace std;
char s1[1000010];
char s2[1000010];
int t1[1000010];
int t2[1000010];
int sum[3][3][1000010];
int main() {
  scanf("%s", s1);
  scanf("%s", s2);
  int n1 = strlen(s1);
  int n2 = strlen(s2);
  for (int i = 0; i < n1; i++) {
    if (s1[i] == 'R') t1[i] = 0;
    if (s1[i] == 'G') t1[i] = 1;
    if (s1[i] == 'B') t1[i] = 2;
  }
  for (int i = 0; i < n2; i++) {
    if (s2[i] == 'R') t2[i] = 0;
    if (s2[i] == 'G') t2[i] = 1;
    if (s2[i] == 'B') t2[i] = 2;
  }
  memset(sum, 0, sizeof(sum));
  for (int i = 1; i < n1; i++) {
    for (int j = 0; j < 3; j++)
      for (int k = 0; k < 3; k++) sum[j][k][i] = sum[j][k][i - 1];
    if (t1[i - 1] != t1[i]) sum[t1[i - 1]][t1[i]][i]++;
  }
  int l, r;
  l = r = 0;
  long long ans = 0;
  for (int i = 0; i < n2; i++) {
    while (s1[r] != s2[i] && r < n1) r++;
    if (l == n1) break;
    long long tmp = 0;
    if (l == r)
      tmp++;
    else {
      tmp += r - l + 1;
      if (r == n1) tmp--;
      if (i != 0)
        tmp -= sum[t2[i]][t2[i - 1]][r - 1] - sum[t2[i]][t2[i - 1]][l];
    }
    ans += tmp;
    if (s1[l] == s2[i]) l++;
    if (s1[r] == s2[i]) r++;
  }
  cout << ans << endl;
  return 0;
}
