#include <bits/stdc++.h>
using namespace std;
string s, t;
int cnt[3][3];
int l, r;
int get(char c) {
  if (c == 'R') return 0;
  if (c == 'B') return 1;
  if (c == 'G') return 2;
  assert(false);
}
void left() {
  cnt[get(t[l])][get(t[l + 1])]--;
  l++;
}
void right() {
  cnt[get(t[r])][get(t[r + 1])]++;
  r++;
}
int main() {
  getline(cin, s);
  getline(cin, t);
  int n = s.size();
  int m = t.size();
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    while (r < m - 1 && s[i] != t[r]) right();
    if (!i || s[i] == s[i - 1])
      ans += r - l + 1;
    else
      ans += r - l + 1 - cnt[get(s[i])][get(s[i - 1])];
    if (t[l] == s[i]) {
      if (l == m - 1) break;
      left();
    }
    if (r < m - 1) right();
  }
  cout << ans << endl;
  return 0;
}
