#include <bits/stdc++.h>
using namespace std;
char s[1000005], t[1000005];
int l, r, f[1000005][8];
long long ans;
int main() {
  scanf("%s%s", s, t);
  int ls = strlen(s), lt = strlen(t);
  for (int i = 0; i < ls; i++) s[i] %= 3;
  for (int i = 0; i < lt; i++) t[i] %= 3;
  for (int i = 1; i < ls; i++) {
    memcpy(f[i], f[i - 1], 32);
    if (s[i - 1] != s[i]) f[i][(s[i - 1] > s[i]) * 4 + s[i - 1] + s[i]]++;
  }
  memcpy(f[ls], f[ls - 1], 32);
  int x;
  for (int i = 0; i < lt; i++) {
    if (i && t[i - 1] != t[i]) {
      x = (t[i - 1] < t[i]) * 4 + t[i - 1] + t[i];
      ans -= f[r][x] - f[l][x];
    }
    while (r < ls && s[r] != t[i]) r++;
    ans += r - l + 1 - (r == ls);
    if (r < ls) r++;
    if (l < r && s[l] == t[i]) l++;
  }
  printf("%lld", ans);
  return 0;
}
