#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-')
    ;
  for ((c == '-' ? sg = 1, c = getchar() : 0), first = 0; c >= '0' && c <= '9';
       c = getchar())
    first = (first << 1) + (first << 3) + c - '0';
  if (sg) first = -first;
}
template <class T>
inline void print(T first) {
  if (first < 0) {
    putchar('-');
    return print(-first);
  }
  if (first < 10) {
    putchar('0' + first);
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
}
template <class T, class T1>
inline void gn(T &first, T1 &second) {
  gn(first);
  gn(second);
}
template <class T, class T1, class T2>
inline void gn(T &first, T1 &second, T2 &z) {
  gn(first);
  gn(second);
  gn(z);
}
template <class T>
inline void println(T first) {
  print(first);
  putchar('\n');
}
template <class T>
inline void printsp(T first) {
  print(first);
  putchar(' ');
}
template <class T1, class T2>
inline void print(T1 x1, T2 x2) {
  printsp(x1), println(x2);
}
template <class T1, class T2, class T3>
inline void print(T1 x1, T2 x2, T3 x3) {
  printsp(x1), printsp(x2), println(x3);
}
template <class T1, class T2, class T3, class T4>
inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {
  printsp(x1), printsp(x2), printsp(x3), println(x4);
}
template <class T>
inline void eprint(T first) {
  cerr << "--------> " << first << endl;
}
template <class T1, class T2>
inline void eprint(T1 first, T2 second) {
  cerr << "--------> " << first << ' ' << second << endl;
}
template <class T1, class T2, class T3>
inline void eprint(T1 first, T2 second, T3 z) {
  cerr << " -------> " << first << ' ' << second << ' ' << z << endl;
}
template <class T1, class T2, class T3, class T4>
inline void eprint(T1 first, T2 second, T3 z, T4 w) {
  cerr << " -------> " << first << ' ' << second << ' ' << z << ' ' << w
       << endl;
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
char s[1000111], t[1000111];
int n, m;
long long ans;
int ns[1000111], nt[1000111];
int val[1000111];
int cnt[1000111][11];
void ch(char &u) {
  if (u == 'R') u = 0;
  if (u == 'B') u = 1;
  if (u == 'G') u = 2;
}
int get(char ss, char tt) {
  ch(ss);
  ch(tt);
  return ss * 3 + tt;
}
int main() {
  scanf("%s %s", s + 1, t + 1);
  n = strlen(s + 1), m = strlen(t + 1);
  int now = 1;
  for (int i = 1; i <= n; i++) {
    while (now <= m and t[now] != s[i]) now++;
    ns[i] = now++;
  }
  now = 1;
  for (int i = 1; i <= m; i++) {
    if (i > 1) {
      val[i] = get(t[i - 1], t[i]);
      for (int j = 0; j < 9; j++) cnt[i][j] = cnt[i - 1][j];
      cnt[i][val[i]]++;
    }
    while (now <= n and s[now] != t[i]) now++;
    nt[i] = now++;
  }
  for (int i = 1; i <= n; i++) {
    int ed = min(m, ns[i]);
    int st = upper_bound(nt + 1, nt + m + 1, i - 1) - nt;
    if (ed >= st) ans += ed - st + 1;
    if (i > 1 and s[i] != s[i - 1] and ed >= st) {
      int now = get(s[i], s[i - 1]);
      ans -= cnt[ed][now] - cnt[st - 1][now];
    }
  }
  println(ans);
  return 0;
}
