#include <iostream>
#include <string>
#define PB 359
#define MOD 1000000007
#define MAX 250000
#define NUL -99
#define ll long long
using namespace std;
ll h1[MAX+1];
ll h2[MAX+1];
ll pow[MAX+1];
int ans_idx = NUL;
bool check(int a_size, int b_size, int len);
int main()
{
string s1, s2;
int l1, l2;
cin >> s1 >> s2;
l1 = s1.size();
l2 = s2.size();
pow[0] = 1;
for (int i = 1; i < MAX+1; ++i)
pow[i] = (pow[i-1] * PB) % MOD;
h1[0] = s1[0];
for (int i = 1; i < l1; ++i)
h1[i] = (((h1[i-1] * PB) % MOD) + s1[i]) % MOD;
h2[0] = s2[0];
for (int i = 1; i < l2; ++i)
h2[i] = (((h2[i-1] * PB) % MOD) + s2[i]) % MOD;
int low = 0, hi = l2, mid;
while (low < hi)
{
mid = (low + hi + 1) / 2;
if (!check(l1, l2, mid))
hi = mid-1;
else
low = mid;
}
if (ans_idx != NUL)
cout << s1.substr(ans_idx, low) << '\n'<< low;
else
cout << "0" << '\n';
return 0;
}
bool check(int a_size, int b_size, int len)
{
for (int i = 0; i <= b_size-len; ++i)
{
for (int j = 0; j <= a_size-len; ++j)
{
if (i == 0)
{
if (j == 0)
{
if (h2[i+len-1] == h1[len-1])
{
ans_idx = j;
return true;
}
}
else
{
if(h2[i+len-1] == (h1[j+len-1] - ((h1[j-1] * pow[len]) % MOD)))
{
ans_idx = j;
return true;
}
}
}
else
{
if (j == 0)
{
if (h2[i+len-1] == h1[len-1])
{
ans_idx = j;
return true;
}
}
else
{
if((h2[i+len-1] - ((h2[i-1] * pow[len]) % MOD)) == (h1[j+len-1] - ((h1[j-1] * pow[len]) % MOD)))
{
ans_idx = j;
return true;
}
}
}
}
}
return false;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojZGVmaW5lIFBCIDM1OQojZGVmaW5lIE1PRCAxMDAwMDAwMDA3CiNkZWZpbmUgTUFYIDI1MDAwMAojZGVmaW5lIE5VTCAtOTkKI2RlZmluZSBsbCB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