#include #include #include #include #define ll long long #define FOR(i,a,b) for(int i= (a); i<((int)b); ++i) using namespace std; struct Node { map next; ll len = 0; ll sl = 0; }; class PalindromicTree { public: string str; vector tree; ll l_idx, ms_idx; PalindromicTree(string s) : str(s) { this->tree.resize(s.size() + 2); this->l_idx = 1; this->ms_idx = 1; this->tree[0].len = -1; } void addLetter(int pos) { char nc = this->str[pos]; ll A = ms_idx; while (true) { int p = pos - 1 - tree[A].len; if (p >= 0 && this->str[p] == nc) break; A = tree[A].sl; } if (this->tree[A].next[nc] != 0) { ms_idx = tree[A].next[nc]; return; } ms_idx = ++this->l_idx; Node &nn = tree[this->l_idx]; nn.len = tree[A].len + 2; tree[A].next[nc] = this->l_idx; if (nn.len == 1) { nn.sl = 1; return;} ll B = A; while (true) { B = tree[B].sl; int p = pos - 1 - tree[B].len; if (p >= 0 && this->str[p] == nc) break; } nn.sl = tree[B].next[nc]; } }; int main() { string s, t, u; cin >> s >> t; u = s + "<>" + t; vector> dp(2, vector(u.size() + 2, 0)); PalindromicTree pt(u); FOR(i, 0, u.size()) { pt.addLetter(i); if (i < s.size()) { dp[0][pt.ms_idx]++; } if (i >= s.size() + 1) { dp[1][pt.ms_idx]++; } } ll ans = 0; for (int i = pt.l_idx; i >= 2; i--) { ans += dp[0][i] * dp[1][i]; dp[0][pt.tree[i].sl] += dp[0][i]; dp[1][pt.tree[i].sl] += dp[1][i]; } cout << ans << endl; return 0; }