#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nmax 1000007
#define mmax 3007
const long long mod = 1e9 + 7;
long long dp[mmax][mmax];
string conv(const string &e)
{
    string r = "";
    char c = ' ';
    int n = 0;
    for (char ch : e)
    {
        if (isalpha(ch))
        {
            if (n > 0) r += string(n, c);
            c = ch;
            n = 0;
        }
        else if (isdigit(ch)) n = n * 10 + (ch - '0');
    }
    if (n > 0) r += string(n, c);
    return r;
}
long long solve1(const string &a, const string &b)
{
    long long m = a.size(), n = b.size();
    for (int i = 1; i <= m; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (a[i - 1] == b[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
            else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    return dp[m][n];
}
long long solve2(const string &a, const string &b)
{
    int m = a.size(), n = b.size(), res = 0;
    for (int i = 1; i <= m; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (a[i - 1] == b[j - 1])
            {
                dp[i][j] = dp[i - 1][j - 1] + 1;
                res = max((ll) res, dp[i][j]);
            }
        }
    }
    return res;
}
signed main()
{
    cin.tie(0)->sync_with_stdio(0);
    if (fopen("comstr.inp", "r"))
    {
        freopen("comstr.inp", "r", stdin);
        freopen("comstr.out", "w", stdout);
    }
    string s, l;
    cin >> s >> l;
    string x = conv(s), y = conv(l);
    cout << solve1(x, y) << '\n';
    cout << solve2(x, y) << '\n';
    return 0;
}