#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 3000000;
int pnext[3][N], cur[3];
int sum[3][3][N];
int n, m;
string s, t;
int get(char c) {
  if (c == 'R') return 0;
  if (c == 'G') return 1;
  return 2;
}
void calc() {
  cur[0] = cur[1] = cur[2] = m;
  for (int j = 0; j < 3; j++) {
    pnext[j][m - 1] = cur[j];
  }
  for (int i = m - 1; i >= 0; i--) {
    cur[get(t[i])] = i;
    for (int j = 0; j < 3; j++) {
      pnext[j][i] = cur[j];
    }
  }
  for (int i = 0; i < m - 1; i++) {
    if (i > 0) {
      for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 3; k++) {
          sum[j][k][i] = sum[j][k][i - 1];
        }
      }
    }
    sum[get(t[i])][get(t[i + 1])][i]++;
  }
}
int getsum(int l, int r, int a, int b) {
  r--;
  int res = sum[a][b][r];
  if (l > 0) res -= sum[a][b][l - 1];
  return res;
}
int main() {
  cin >> s;
  cin >> t;
  n = s.length();
  m = t.length();
  calc();
  int l = 0, r = -1;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    r = min(r + 1, m - 1);
    if (i > 0 && l < m && s[i - 1] == t[l]) l++;
    r = min(pnext[get(s[i])][r], m - 1);
    if (l <= r) {
      ans += r - l + 1;
      if (i > 0 && s[i] != s[i - 1]) {
        ans -= getsum(l, r, get(s[i]), get(s[i - 1]));
      }
    }
  }
  cout << ans;
  return 0;
}
