#include using namespace std; using ll = long long; #define rep(i, x) for(int i = 0; i < (x); i++) #define rng(i, l, r) for(int i = (l); i < (r); i++) using vi = vector; #define sz(x) (int)(x).size() array manacher(string &s) { int n = sz(s); array p = {vi(n + 1), vi(n)}; rep(z, 2) for(int i = 0, l = 0, r = 0; i < n; i++) { int t = r - i + !z; if(i < r) p[z][i] = min(t, p[z][l + t]); int L = i - p[z][i], R = i + p[z][i] - !z; while(L >= 1 and R + 1 < n and s[L - 1] == s[R + 1]) p[z][i]++, L--, R++; if(R > r) l = L, r = R; } return p; } typedef uint64_t ull; struct H { ull x; H(ull x = 0) : x(x) {} H operator+(H o) { return x + o.x + (x + o.x < x); } H operator-(H o) { return *this + ~o.x; } H operator*(H o) { auto m = (__uint128_t)x * o.x; return H((ull)m) + (ull)(m >> 64); } ull get() const { return x + !~x; } bool operator==(H o) const { return get() == o.get(); } bool operator<(H o) const { return get() < o.get(); } }; static const H C = (ll)1e11 + 3; struct hash_interval { vector ha, pw; hash_interval(string &str) : ha(sz(str) + 1), pw(ha) { pw[0] = 1; rep(i, sz(str)) ha[i + 1] = ha[i] * C + str[i], pw[i + 1] = pw[i] * C; } H get(int a, int b) { return ha[b] - ha[a] * pw[b - a]; } }; map palindromes_freq(string &s) { auto sm = manacher(s); hash_interval sh(s); set st; map es; vector> nodes(sz(s) + 1); map cum; rep(i, sz(s) + 1) { if(sm[0][i]) { int len = sm[0][i]; auto ha = sh.get(i - len, i + len); cum[ha.get()]++; nodes[len * 2].insert(ha.get()); while(len > 1) { len--; auto nx = sh.get(i - len, i + len); if(es.count({ha.get()})) break; es[ha.get()] = nx.get(); ha = nx; nodes[len * 2].insert(ha.get()); } } } rep(i, sz(s)) { sm[1][i]++; int len = sm[1][i]; auto ha = sh.get(i - len + 1, i + len); cum[ha.get()]++; nodes[len * 2 - 1].insert(ha.get()); while(len > 1) { len--; auto nx = sh.get(i - len + 1, i + len); if(es.count({ha.get()})) break; es[ha.get()] = nx.get(); ha = nx; nodes[len * 2 - 1].insert(ha.get()); } } for(int i = sz(s); i >= 0; --i) { for(auto &v : nodes[i]) { if(es.count(v)) { cum[es[v]] += cum[v]; } } } return cum; } int main() { string s, t; cin >> s >> t; auto s_freq = palindromes_freq(s); auto t_freq = palindromes_freq(t); ll res = 0; for(auto [key, cnt] : s_freq) res += cnt * t_freq[key]; cout << res << endl; }