9
lfpgbnlzyn
c
s
w
r
m
q
y
yinfblfcdhidphyfvgkxyuwomahiibbhnigdslsguhjkplibnhhrshtekwgefxeugyyyyy
 6
u
p
m
z
v
vv
 4
qe
nd
iqryhukieskfvaeettersinksrmazelxtgvartuz
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
 6
nf
ysvchtjkfgsbyfzxjaykey
advqnf
wl
pi
ppppfvvmaebvhkoagppppp
 3
j
k
kkailgwqnxtdsttkkkkkkk
 4
o
yhnx
e
ennn
 10
j
dyfu
udzj
wwow
xtnw
f
c
q
o
gggg
 6
w
g
c
j
y
f
 4
r
o
w
wwwwwwwwww
 2
zxwp
ppppctfisvflhtjggg
 5
m
g
u
t
tttt
 2
n
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
 3
lt
en
eeeeeeeeee
 4
vr
hp
l
llbn

7 5 541 10 10 4 4 1 21 5 9 93 21 3
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define int lli
main() {
    int n;
    cin>>n;
    int a[26];
    for(int i=0;i<26;i++)a[i]=0;
    for(int z=0;z<n;z++){
        if(z == 0){
            string str;
            cin>>str;
            for(int i=0;i<str.length();i++){
                if(a[str[i]-'a']==0)a[str[i]-'a']=1;
            }
        }else{
            string str;
            cin>>str;
            int m =str.length();
            char prefixC = str[0],suffixC=str[m-1];
            int countp=0,counts=0;
            for(int i=0;i<m;i++){
                if(str[i] == prefixC)countp++;
                else break;
            }
            for(int i=m-1;i>=0;i--){
                if(str[i] == suffixC)counts++;
                else break;
            }

            if(countp == m && counts == m){
                    int x = a[prefixC-'a'];
                    a[prefixC-'a'] = x + (x+1)*countp; 
            }else{
                if(prefixC == suffixC){
                    int val = countp + counts + 1;
                    a[prefixC-'a'] = max(a[prefixC-'a'],val);
                }else{
                    int val = countp + 1;
                    a[prefixC-'a'] = max(a[prefixC-'a'],val);
                    val = counts + 1;
                    a[suffixC-'a'] = max(a[suffixC-'a'],val);
                }
            }
        }
    }
    int maxVal=-1;
    for(int i=0;i<26;i++){
        maxVal = max(maxVal,a[i]);
    }
    cout<<maxVal<<"\n";
    return 0;
}
