#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
struct suffixAutomaton {
struct node {
int len, link, cnt;
int next[26];
};
vector<node> sa;
vector<int> last, p1, p2, q1, qlink;
long long ans = 0;
string s;
suffixAutomaton(int mx_len) {
sa.reserve(mx_len*2);
last.push_back(add_node());
sa[0].link = -1;
}
int add_node() { sa.push_back(node()); return sa.size()-1; }
void add_char(char ch) {
s.push_back(ch);
int c = ch-'A';
int u = add_node(), p = last.back();
sa[u].len = sa[p].len + 1;
while (p != -1 && !sa[p].next[c]) {
sa[p].next[c] = u;
p = sa[p].link;
}
p1.push_back(p);
if (p != -1) {
int q = sa[p].next[c];
q1.push_back(q);
if (sa[p].len + 1 != sa[q].len) {
int clone = add_node();
sa[clone] = sa[q];
sa[clone].len = sa[p].len + 1;
qlink.push_back(sa[q].link);
sa[q].link = sa[u].link = clone;
while (p != -1 && sa[p].next[c] == q) {
sa[p].next[c] = clone;
p = sa[p].link;
}
p2.push_back(p);
} else sa[u].link = q;
int v = sa[u].link;
if (!sa[v].cnt) ans += sa[v].len - sa[sa[v].link].len;
sa[v].cnt++;
}
last.push_back(u);
}
void pop_back() {
int c = s.back()-'A'; s.pop_back();
int u = last.back(); last.pop_back();
int p = last.back();
while (p != p1.back()) {
sa[p].next[c] = 0;
p = sa[p].link;
}
p1.pop_back();
if (p != -1) {
int v = sa[u].link;
sa[v].cnt--;
if (!sa[v].cnt) ans -= sa[v].len - sa[sa[v].link].len;
int q = q1.back(); q1.pop_back();
if (sa[p].len + 1 != sa[q].len) {
sa[q].link = qlink.back(); qlink.pop_back();
while (p != p2.back()) {
sa[p].next[c] = q;
p = sa[p].link;
}
p2.pop_back();
sa.pop_back();
}
}
sa.pop_back();
}
node& operator[](int i) { return sa[i]; }
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s, q;
cin >> s >> q;
int len = s.size() + q.size();
suffixAutomaton sa(len);
for (auto &c : s) sa.add_char(c);
cout << sa.ans << endl;
for (auto &c : q) {
if (c == '-') sa.pop_back();
else sa.add_char(c);
cout << sa.ans << endl;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgZW5kbCAiXG4iCgpzdHJ1Y3Qgc3VmZml4QXV0b21hdG9uIHsKICAgIHN0cnVjdCBub2RlIHsKICAgICAgICBpbnQgbGVuLCBsaW5rLCBjbnQ7CiAgICAgICAgaW50IG5leHRbMjZdOwogICAgfTsKCiAgICB2ZWN0b3I8bm9kZT4gc2E7CiAgICB2ZWN0b3I8aW50PiBsYXN0LCBwMSwgcDIsIHExLCBxbGluazsKICAgIGxvbmcgbG9uZyBhbnMgPSAwOwogICAgc3RyaW5nIHM7CgogICAgc3VmZml4QXV0b21hdG9uKGludCBteF9sZW4pIHsKICAgICAgICBzYS5yZXNlcnZlKG14X2xlbioyKTsKICAgICAgICBsYXN0LnB1c2hfYmFjayhhZGRfbm9kZSgpKTsKICAgICAgICBzYVswXS5saW5rID0gLTE7CiAgICB9CgogICAgaW50IGFkZF9ub2RlKCkgeyBzYS5wdXNoX2JhY2sobm9kZSgpKTsgcmV0dXJuIHNhLnNpemUoKS0xOyB9CgogICAgdm9pZCBhZGRfY2hhcihjaGFyIGNoKSB7CiAgICAgICAgcy5wdXNoX2JhY2soY2gpOwogICAgICAgIGludCBjID0gY2gtJ0EnOwogICAgICAgIGludCB1ID0gYWRkX25vZGUoKSwgcCA9IGxhc3QuYmFjaygpOwogICAgICAgIHNhW3VdLmxlbiA9IHNhW3BdLmxlbiArIDE7CiAgICAgICAgd2hpbGUgKHAgIT0gLTEgJiYgIXNhW3BdLm5leHRbY10pIHsKICAgICAgICAgICAgc2FbcF0ubmV4dFtjXSA9IHU7CiAgICAgICAgICAgIHAgPSBzYVtwXS5saW5rOwogICAgICAgIH0KICAgICAgICBwMS5wdXNoX2JhY2socCk7CiAgICAgICAgaWYgKHAgIT0gLTEpIHsKICAgICAgICAgICAgaW50IHEgPSBzYVtwXS5uZXh0W2NdOwogICAgICAgICAgICBxMS5wdXNoX2JhY2socSk7CiAgICAgICAgICAgIGlmIChzYVtwXS5sZW4gKyAxICE9IHNhW3FdLmxlbikgewogICAgICAgICAgICAgICAgaW50IGNsb25lID0gYWRkX25vZGUoKTsKICAgICAgICAgICAgICAgIHNhW2Nsb25lXSA9IHNhW3FdOwogICAgICAgICAgICAgICAgc2FbY2xvbmVdLmxlbiA9IHNhW3BdLmxlbiArIDE7CiAgICAgICAgICAgICAgICBxbGluay5wdXNoX2JhY2soc2FbcV0ubGluayk7CiAgICAgICAgICAgICAgICBzYVtxXS5saW5rID0gc2FbdV0ubGluayA9IGNsb25lOwogICAgICAgICAgICAgICAgd2hpbGUgKHAgIT0gLTEgJiYgc2FbcF0ubmV4dFtjXSA9PSBxKSB7CiAgICAgICAgICAgICAgICAgICAgc2FbcF0ubmV4dFtjXSA9IGNsb25lOwogICAgICAgICAgICAgICAgICAgIHAgPSBzYVtwXS5saW5rOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcDIucHVzaF9iYWNrKHApOwogICAgICAgICAgICB9IGVsc2Ugc2FbdV0ubGluayA9IHE7CiAgICAgICAgICAgIGludCB2ID0gc2FbdV0ubGluazsKICAgICAgICAgICAgaWYgKCFzYVt2XS5jbnQpIGFucyArPSBzYVt2XS5sZW4gLSBzYVtzYVt2XS5saW5rXS5sZW47CiAgICAgICAgICAgIHNhW3ZdLmNudCsrOwogICAgICAgIH0KICAgICAgICBsYXN0LnB1c2hfYmFjayh1KTsKICAgIH0KCiAgICB2b2lkIHBvcF9iYWNrKCkgewogICAgICAgIGludCBjID0gcy5iYWNrKCktJ0EnOyBzLnBvcF9iYWNrKCk7CiAgICAgICAgaW50IHUgPSBsYXN0LmJhY2soKTsgbGFzdC5wb3BfYmFjaygpOwogICAgICAgIGludCBwID0gbGFzdC5iYWNrKCk7CiAgICAgICAgd2hpbGUgKHAgIT0gcDEuYmFjaygpKSB7CiAgICAgICAgICAgIHNhW3BdLm5leHRbY10gPSAwOwogICAgICAgICAgICBwID0gc2FbcF0ubGluazsKICAgICAgICB9CiAgICAgICAgcDEucG9wX2JhY2soKTsKICAgICAgICBpZiAocCAhPSAtMSkgewogICAgICAgICAgICBpbnQgdiA9IHNhW3VdLmxpbms7CiAgICAgICAgICAgIHNhW3ZdLmNudC0tOwogICAgICAgICAgICBpZiAoIXNhW3ZdLmNudCkgYW5zIC09IHNhW3ZdLmxlbiAtIHNhW3NhW3ZdLmxpbmtdLmxlbjsKICAgICAgICAgICAgaW50IHEgPSBxMS5iYWNrKCk7IHExLnBvcF9iYWNrKCk7CiAgICAgICAgICAgIGlmIChzYVtwXS5sZW4gKyAxICE9IHNhW3FdLmxlbikgewogICAgICAgICAgICAgICAgc2FbcV0ubGluayA9IHFsaW5rLmJhY2soKTsgcWxpbmsucG9wX2JhY2soKTsKICAgICAgICAgICAgICAgIHdoaWxlIChwICE9IHAyLmJhY2soKSkgewogICAgICAgICAgICAgICAgICAgIHNhW3BdLm5leHRbY10gPSBxOwogICAgICAgICAgICAgICAgICAgIHAgPSBzYVtwXS5saW5rOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcDIucG9wX2JhY2soKTsKICAgICAgICAgICAgICAgIHNhLnBvcF9iYWNrKCk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgc2EucG9wX2JhY2soKTsKICAgIH0KICAgIAogICAgbm9kZSYgb3BlcmF0b3JbXShpbnQgaSkgeyByZXR1cm4gc2FbaV07IH0KfTsKCmludCBtYWluKCkgewogICAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBjaW4udGllKDApOwogICAgCiAgICBzdHJpbmcgcywgcTsKICAgIGNpbiA+PiBzID4+IHE7CiAgICBpbnQgbGVuID0gcy5zaXplKCkgKyBxLnNpemUoKTsKICAgIAogICAgc3VmZml4QXV0b21hdG9uIHNhKGxlbik7CiAgICAKICAgIGZvciAoYXV0byAmYyA6IHMpIHNhLmFkZF9jaGFyKGMpOwogICAgY291dCA8PCBzYS5hbnMgPDwgZW5kbDsKICAgIAogICAgZm9yIChhdXRvICZjIDogcSkgewogICAgICAgIGlmIChjID09ICctJykgc2EucG9wX2JhY2soKTsKICAgICAgICBlbHNlIHNhLmFkZF9jaGFyKGMpOwogICAgICAgIGNvdXQgPDwgc2EuYW5zIDw8IGVuZGw7CiAgICB9Cn0=