#include <bits/stdc++.h>
using namespace std;
int S, T;
string s, t;
char buf[1000010];
int low[1000010], high[1000010];
int a[1000010], sum[1000010];
int main(void) {
  int i, j, k, x;
  scanf("%s", buf);
  s = buf;
  S = s.length();
  scanf("%s", buf);
  t = buf;
  T = t.length();
  x = 0;
  for ((i) = 0; (i) < (int)(S); (i)++) {
    low[i] = x;
    if (x < T && t[x] == s[i]) x++;
  }
  x = 0;
  for ((i) = 0; (i) < (int)(S); (i)++) high[i] = T;
  for ((i) = 0; (i) < (int)(T); (i)++) {
    if (x > 0) high[x - 1] = min(high[x - 1], i);
    if (x < S && s[x] == t[i]) x++;
  }
  long long ans = 0;
  for ((i) = 0; (i) < (int)(S); (i)++) ans += high[i] - low[i];
  ;
  string rgb = "RGB";
  for ((j) = 0; (j) < (int)(3); (j)++)
    for ((k) = 0; (k) < (int)(3); (k)++)
      if (j != k) {
        char c1 = rgb[j], c2 = rgb[k];
        for ((i) = 0; (i) < (int)(T); (i)++) a[i] = 0;
        for (i = 1; i < T; i++)
          if (t[i] == c1 && t[i - 1] == c2) a[i] = 1;
        for ((i) = 0; (i) < (int)(T); (i)++) sum[i + 1] = sum[i] + a[i];
        for (i = 1; i < S; i++)
          if (s[i] == c2 && s[i - 1] == c1) ans -= sum[high[i]] - sum[low[i]];
      }
  cout << ans << endl;
  return 0;
}
