#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mxn = 1000006;
int n, m;
char a[mxn];
char b[mxn];
int c[128];
int s[4][4][mxn];
void EXEC() {
  c['R'] = 1;
  c['G'] = 2;
  c['B'] = 3;
  scanf("%s", a + 1);
  scanf("%s", b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= 3; ++j)
      for (int k = 1; k <= 3; ++k) s[j][k][i] = s[j][k][i - 1];
    if (i > 1) ++s[c[b[i - 1]]][c[b[i]]][i];
  }
  ll ans = 0;
  int L = 1, R = 1;
  for (int i = 1; i <= n; ++i) {
    while (R < m && a[i] != b[R]) ++R;
    ans += R + 1 - L;
    if (i > 1 && a[i] != a[i - 1])
      ans -= s[c[a[i]]][c[a[i - 1]]][R] - s[c[a[i]]][c[a[i - 1]]][L - 1];
    if (a[i] == b[L]) ++L;
    if (R < m && a[i] == b[R]) ++R;
    if (L > m) break;
  }
  cout << ans << endl;
}
int main() {
  EXEC();
  return 0;
}
