#include <iostream>
#include <string>
using namespace std;
#pragma region 입출력 속도향상
#define FAST_IO() \
{\
ios::sync_with_stdio(false);\
cin.tie(NULL); \
cout.tie(NULL); \
}\
#pragma endregion
#define MAX 101
int dp[MAX][MAX][MAX];
int max(int a, int b, int c)
{
return max(a, max(b, c));
}
int main()
{
FAST_IO();
string s1, s2, s3;
cin >> s1 >> s2 >> s3;
int sz1 = s1.length(), sz2 = s2.length(), sz3 = s3.length();
for (int i = 1; i <= sz1; i++)
{
for (int j = 1; j <= sz2; j++)
{
for (int k = 1; k <= sz3; k++)
{
// 3개의 문자가 같은 경우
if (s1[i - 1] == s2[j - 1] &&
s2[j - 1] == s3[k - 1])
dp[i][j][k] = dp[i - 1][j - 1][k - 1] + 1;
else
dp[i][j][k] = max(dp[i - 1][j][k], dp[i][j - 1][k], dp[i][j][k - 1]);
}
}
}
cout << dp[sz1][sz2][sz3];
}