import std.conv, std.functional, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.range, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } class Eertree(int E, char Offset) { string s; int n; int[] us, len, fail; int[] next; this(in string s) { this.s = s; n = cast(int)(s.length); us = new int[n + 3]; len = new int[n + 3]; fail = new int[n + 3]; next = new int[(n + 3) << E]; us[1] = 1; len[1] = -1; fail[1] = 1; us[2] = 2; len[2] = 0; fail[2] = 1; foreach (i; 0 .. n) { const c = s[i] - Offset; int u = us[i + 2]; for (; !isSuffix(i, u); u = fail[u]) {} if (!next[u << E | c]) { next[u << E | c] = i + 3; len[i + 3] = len[u] + 2; if (u == 1) { fail[i + 3] = 2; } else { int v = fail[u]; for (; !isSuffix(i, v); v = fail[v]) {} fail[i + 3] = next[v << E | c]; } } us[i + 3] = next[u << E | c]; } } bool isSuffix(int i, int u) const { const j = i - 1 - len[u]; return (j >= 0 && s[j] == s[i]); } void print() const { void dfs(int u, string prefix, int type) { writefln("%s%s%s %s %s", prefix, ["", "|-- ", "`-- "][type], (len[u] <= 0) ? ("(" ~ len[u].to!string ~ ")") : s[u - 2 - len[u] .. u - 2], u, fail[u]); const vs = next[u << E .. (u + 1) << E].filter!(v => v).array; foreach (v; vs) { dfs(v, prefix ~ ["", "| ", " "][type], (v == vs[$ - 1]) ? 2 : 1); } } dfs(1, "", 0); dfs(2, " ", 0); } } string S, T; void main() { try { for (; ; ) { S = readToken(); T = readToken(); const U = S ~ "?@" ~ T; auto eertree = new Eertree!(5, '?')(U); debug { eertree.print; } const n = cast(int)(U.length); const m = cast(int)(S.length); auto cnt = new long[][](n + 3, 2); foreach (i; 0 .. m) { ++cnt[eertree.us[i + 3]][0]; } foreach (i; m + 2 .. n) { ++cnt[eertree.us[i + 3]][1]; } foreach_reverse (u; 1 .. n + 3) { if (eertree.us[u] == u) { foreach (j; 0 .. 2) { cnt[eertree.fail[u]][j] += cnt[u][j]; } } } long ans; foreach (u; 3 .. n + 3) { if (eertree.us[u] == u) { ans += cnt[u][0] * cnt[u][1]; } } writeln(ans); } } catch (EOFException e) { } }