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.*;
public class Main {
    static String[] P;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        P = new String[n];
        for (int i = 0; i < n; i++) {
            P[i] = sc.next();
        }
        
        long res = 0;
        for (char c = 'a'; c <= 'z'; c++) {
            res = Math.max(res, consec(n-1, c));
        }
        System.out.println(res);
    }
    
    static long consec(int i, char c) {
        int thisConsec = 0;
        int count = 0;
        for (int j = 0; j < P[0].length(); j++) {
            if (P[0].charAt(j) == c) {
                count++;
            } else {
                count = 0;
            }
            thisConsec = Math.max(thisConsec, count);
        }
        if (i == 0) return thisConsec;
        
        boolean only = true;
        for (int j = 0; j < P[i].length(); j++) {
            if (P[i].charAt(j) != c) {
                only = false;
                break;
            }
        }
        if (only) {
            long prev = consec(i-1, c); 
            return (prev+1)*P[i].length() + prev;
        } else {
            int start = 0;
            while (start < P[i].length() && P[i].charAt(start) == c) {
                start++;
            }
            int end = 0;
            while (end < P[i].length() && P[i].charAt(P[i].length()-end-1) == c) {
                end++;
            }
            if (contains(i-1, c)) {
                return start+end+1;
            } else {
                return thisConsec;
            }
        }
    }
    
    static boolean contains(int i, char c) {
        if (i == -1) return false;
        for (int j = 0; j < P[i].length(); j++) {
            if (P[i].charAt(j) == c) return true;
        }
        return contains(i-1, c);
    }
}
