#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
char a[N], b[N];
int an, bn, s[N][3][3];
long long ans;
int encode(char x) {
  if (x == 'R') return 0;
  if (x == 'G') return 1;
  if (x == 'B') return 2;
}
int main() {
  gets(a), an = strlen(a);
  gets(b), bn = strlen(b);
  for (int i = 0; i < an; ++i) {
    a[i] = encode(a[i]);
    if (!i) continue;
    for (int x = 0; x <= 2; ++x)
      for (int y = 0; y <= 2; ++y) s[i][x][y] = s[i - 1][x][y];
    ++s[i][a[i - 1]][a[i]];
  }
  for (int i = 0; i < bn; ++i) b[i] = encode(b[i]);
  int l, r;
  for (int i = 0; i < bn; ++i) {
    if (!i) {
      l = r = 0;
      while (r + 1 < an && a[r] != b[i]) ++r;
      ans += r - l + 1;
    } else {
      for (++r; r + 1 < an && a[r] != b[i]; ++r)
        ;
      if (r == an) r--;
      if (a[l] == b[i - 1]) ++l;
      if (l == an) break;
      ans += r - l + 1;
      if (b[i - 1] != b[i]) {
        int x = b[i], y = b[i - 1];
        ans -= s[r][x][y] - s[l][x][y];
      }
    }
  }
  printf("%I64d\n", ans);
}
