#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
int main(){
string s1, s2;
cin >> s1 >> s2;
int cnt = 0, res = 0;
int len1 = s1.size(), len2 = s2.size();
for (int i = 0; i < len1; i ++ )
for (int j = 0; j < len2; j ++ ){
cnt = 0;
if (s1[i] == s2[j]){
for (int k = 0; k < len1 && k < len2; k ++ ){
if (s1[(i + k) % len1] != s2[(j + k) % len2])
break;
cnt ++ ;
}
res = max(res, cnt);
}
}
cout << res << endl;
return 0;
}
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
int a[10], res;
int n;
void dfs(int u, int sum, int op){
if (u == 10){
if (sum == n){
if (op == 1){
for (int i = 0; i < 10; i ++ )
cout << a[i] << ' ';
cout << endl;
}else res ++ ;
}
return;
}
if (sum >= n) return;
for (int i = 1; i <= 3; i ++ ){
a[u] = i;
dfs(u + 1, sum + i, op);
}
}
int main(){
cin >> n;
if (n < 10 || n > 30){
puts("0");
return 0;
}
dfs(0, 0, 0);
cout << res << endl;
dfs(0, 0, 1);
return 0;
}
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
const int N = 25;
int n;
string word[N];
int used[N];
char head;
int g[N][N], ans;
void dfs(string str, int last){
ans = max(ans, (int)str.size());
used[last] ++ ;
for (int i = 1; i <= n; i ++ )
if (g[last][i] && used[i] < 2)
dfs(str + word[i].substr(g[last][i]), i);
used[last] -- ;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i ++ ) cin >> word[i];
cin >> head;
for (int i = 1; i <= n; i ++ )
for (int j = 1; j <= n; j ++ ){
string a = word[i], b = word[j];
for (int k = 1; k < min(a.size(), b.size()); k ++ )
if (a.substr(a.size() - k, k) == b.substr(0, k)){
g[i][j] = k;
break;
}
}
for (int i = 1; i <= n; i ++ )
if (word[i][0] == head)
dfs(word[i], i);
cout << ans << endl;
return 0;
}