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
import java.util.*;
import java.io.*;
import java.math.*;
import java.util.Comparator;
public class Main
{
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] s = new String[n];
        for(int i=0;i<n;i++){
            s[i] = br.readLine();
        }
        int ans =0 ;
        for(char c = 'a';c <='z';c++){
            int max = 0;
            for(int i=0;i<n;i++){
                int prefix = 0;
                int suffix = 0;
                for(int j=0;j<s[i].length();j++){
                    if(s[i].charAt(j) ==c){
                        prefix++;
                    }
                    else break;
                }
                for(int j=s[i].length()-1;j>=0;j--){
                    if(s[i].charAt(j) ==c){
                        suffix --;
                    }
                    else
                        break;
                }
                int maxLen = 0;
                int temp = 0 ;
                for(int j=0;j<s[i].length();j++){
                    if(s[i].charAt(j) == c) {
                        temp++;
                    }
                    else {
                        maxLen = Math.max(maxLen,temp);
                        temp = 0;
                    }
                }
                maxLen = Math.max(maxLen,temp);
                if(maxLen == s[i].length()){
                    max = Math.max(maxLen,max*(maxLen+1) +max);
                }
                else {
                    max = Math.max(maxLen,max > 0 ? prefix+suffix+1 : 0);
                }
            }
            ans = Math.max(ans,max);
        }
        System.out.println(ans);
    }
}

