#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, A = 300;
long long ctr[A][A];
long long min_y[N], min_x[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s, t;
  cin >> s >> t;
  long long n = s.size(), m = t.size();
  long long x = 0, y = 0;
  min_y[0] = 0;
  long long ans = n * m;
  while (true) {
    if (x == n - 1) {
      break;
    } else if (s[x] == t[y] and y == m - 1) {
      ans -= m * (n - (x + 1));
      n = x + 1;
      break;
    } else {
      if (s[x] == t[y]) {
        ++y;
      }
      ++x;
      min_y[x] = y;
      ans -= y;
    }
  }
  x = 0;
  y = 0;
  min_x[0] = 0;
  while (true) {
    if (y == m - 1) {
      break;
    } else if (t[y] == s[x] and x == n - 1) {
      ans -= n * (m - (y + 1));
      m = y + 1;
      break;
    } else {
      if (t[y] == s[x]) {
        ++x;
      }
      ++y;
      min_x[y] = x;
      ans -= x;
    }
  }
  long long ly = 0, ry = 0;
  for (x = 0; x < n; ++x) {
    while (ly < min_y[x]) {
      if (ly) {
        --ctr[t[ly]][t[ly - 1]];
      }
      ++ly;
    }
    while (ry < m - 1 and min_x[ry + 1] <= x) {
      ++ry;
      ++ctr[t[ry]][t[ry - 1]];
    }
    if (x and s[x] != s[x - 1]) {
      ans -= ctr[s[x - 1]][s[x]];
    }
  }
  cout << ans << endl;
}
