#include<bits/stdc++.h> // xau nen
using namespace std;
map <char,int> mp1, mp2, mp3;
int t1, t2, th1=-9999, th2=-9999;
int main()
{
// freopen ("comstr.inp", "r", stdin);
char x[1000];
cin>>x;
for (int i=0; i<strlen(x); i++)
{
if (x[i]<'a')
{
int z=i, t=0;
while (x[z]<'a' && z<strlen(x))
{
t=t*10+(int(x[z])-48);
z++;
}
mp1[x[i-1]]+=t;
if(mp2[x[i-1]]<t) mp2[x[i-1]]=t;
i=z;
}
}
cin>>x;
for (int i=0; i<strlen(x); i++)
{
if(x[i]<'a')
{
int z=i, t=0;
while (x[z]<'a'&&z<strlen(x))
{
t=t*10+int(x[z])-48;
z++;
}
mp3[x[i-1]]+=t;
t2=min(mp2[x[i-1]],t);
th2=max(t2,th2);
i=z;
}
}
for (auto x:mp1)
{
t1=min(x.second, mp3[x.first]);
th1=max(t1,th1);
}
cout<<th1<<endl;
cout<<th2;
return 0;
}
/*
inp: a1b10
b3c9b4
out: 7
4
*/
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4gLy8geGF1IG5lbgp1c2luZyBuYW1lc3BhY2Ugc3RkOwptYXAgPGNoYXIsaW50PiBtcDEsIG1wMiwgbXAzOwppbnQgdDEsIHQyLCB0aDE9LTk5OTksIHRoMj0tOTk5OTsKaW50IG1haW4oKQp7Ci8vCWZyZW9wZW4gKCJjb21zdHIuaW5wIiwgInIiLCBzdGRpbik7CgljaGFyIHhbMTAwMF07CgljaW4+Png7IAoJZm9yIChpbnQgaT0wOyBpPHN0cmxlbih4KTsgaSsrKQoJewoJCWlmICh4W2ldPCdhJykKCQl7CgkJCWludCB6PWksIHQ9MDsKCQkJd2hpbGUgKHhbel08J2EnICYmIHo8c3RybGVuKHgpKQoJCQl7CgkJCQl0PXQqMTArKGludCh4W3pdKS00OCk7IAoJCQkJeisrOwoJCQl9CgkJCW1wMVt4W2ktMV1dKz10OwoJCQlpZihtcDJbeFtpLTFdXTx0KSBtcDJbeFtpLTFdXT10OwoJCQlpPXo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