#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) / 2;
if (!check(l1, l2, mid))
hi = mid-1;
else
low = mid+1;
}
if (ans_idx != NUL)
cout << s1.substr(ans_idx, low-1) << '\n'<< low-1;
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 (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;
}
}
}
}
return false;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojZGVmaW5lIFBCIDM1OQojZGVmaW5lIE1PRCAxMDAwMDAwMDA3CiNkZWZpbmUgTUFYIDI1MDAwMAojZGVmaW5lIE5VTCAtOTkKI2RlZmluZSBsbCBsb25nIGxvbmcKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmxsIGgxW01BWCsxXTsKbGwgaDJbTUFYKzFdOwpsbCBwb3dbTUFYKzFdOwppbnQgYW5zX2lkeCA9IE5VTDsKCmJvb2wgY2hlY2soaW50IGFfc2l6ZSwgaW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