#include using namespace std; using VS = vector; using LL = long long; using VI = vector; using VVI = vector; using PII = pair; using PLL = pair; using VL = vector; using VVL = vector; #define ALL(a) begin((a)),end((a)) #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define EB emplace_back #define MP make_pair #define SZ(a) int((a).size()) #define SORT(c) sort(ALL((c))) #define RSORT(c) sort(RALL((c))) #define UNIQ(c) (c).erase(unique(ALL((c))), end((c))) #define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++) #define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--) #define debug(x) cerr << #x << ": " << x << endl const int INF = 1e9; const LL LINF = 1e16; const LL MOD = 1000000007; const double PI = acos(-1.0); int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 }; int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 }; /* ----- 2018/08/31 Problem: yukicoder263 / Link: https://yukicoder.me/problems/no/263 ----- */ /* ------問題------ -----問題ここまで----- */ /* -----解説等----- すごい!EERTREE!いごす ----解説ここまで---- */ struct PalindromicTree { struct node { map link; int suffix_link, len, count; }; vector c; string s; int active_idx; node* create_node() { c.emplace_back(); node* ret = &c.back(); ret->count = 0; return ret; } int find_prev_palindrome_idx(int node_id) { const int pos = int(s.size()) - 1; while (true) { const int opposite_side_idx = pos - 1 - c[node_id].len; if (opposite_side_idx >= 0 && s[opposite_side_idx] == s.back()) break; node_id = c[node_id].suffix_link; } return node_id; } public: PalindromicTree() { node* size_m1 = create_node(); size_m1->suffix_link = 0; size_m1->len = -1; node* size_0 = create_node(); size_0->suffix_link = 0; // 親 size_0->len = 0; active_idx = 0; } void add(char ch) { s.push_back(ch); const int a = find_prev_palindrome_idx(active_idx); const auto inserted_result = c[a].link.insert(make_pair(ch, int(c.size()))); active_idx = inserted_result.first->second; if (!inserted_result.second) { c[active_idx].count++; return; } node* nnode = create_node(); nnode->count = 1; nnode->len = c[a].len + 2; if (nnode->len == 1) { nnode->suffix_link = 1; } else { const int b = find_prev_palindrome_idx(c[a].suffix_link); nnode->suffix_link = c[b].link[ch]; } } }; VL f(const PalindromicTree & eertree) { VL freq(SZ(eertree.c)); FORR(i, SZ(eertree.c) - 1, 0) { freq[i] += eertree.c[i].count; freq[eertree.c[i].suffix_link] += freq[i]; } return freq; } void clearCnt(PalindromicTree & eertree) { FOR(i, 0, SZ(eertree.c)) { eertree.c[i].count = 0; } } int main() { cin.tie(0); ios_base::sync_with_stdio(false); string s, t; cin >> s >> t; PalindromicTree eertree; for (auto c : s) { eertree.add(c); } VL cnt1 = f(eertree); clearCnt(eertree); eertree.add('#'); eertree.add('@'); for (auto c : t) { eertree.add(c); } VL cnt2 = f(eertree); LL ans = 0; FOR(i, 2, SZ(cnt1)) { //最初の2つは特殊 ans += cnt1[i] * cnt2[i]; } cout << ans << "\n"; return 0; }