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.*;
public class E{
    static PrintWriter out;
    static InputReader in;
    public static void main(String args[]){
        out = new PrintWriter(System.out);
        in = new InputReader();
        new E();
        out.flush(); out.close();
    }   
    E(){
        solve();
    }
    int max[][] = new int[2][26];
    int pvt, cnt, l, d, t = 1;
    boolean o;
    void upd(){
        if(pvt == -1)return;
        int ty = 0;
        if(d == 1){
            if(cnt == l)ty = 1;
            else ty = 2;
        }else{
            if(o)ty = 3;
        }
        int val = cnt, pval = max[1 - t][pvt];
        if(ty == 1){
            val = (pval + 1) * val + pval;
        }else if(ty > 1){
            val = val + (pval > 0 ? 1 : 0);
        }
        max[t][pvt] = val;
    }
    void solve(){
        int n = in.nextInt();
        for(int i = 0; i < n; i++){
            t = 1 - t;
            char c[] = in.next().trim().toCharArray();
            l = c.length; d = 0;
            pvt = -1; cnt = 0; o = false;
            for(int j = 0; j < 26; j++){
                if(max[1 - t][j] > 0)max[t][j] = 1;
                else max[t][j] = 0;
            }
            for(int j = 0; j < l; j++){
                int pc = c[j] - 'a';
                if(pc != pvt){
                    upd();
                    pvt = pc; cnt = 0; d++;
                }cnt++;
            }
            o = true;
            upd();
        }
        int ans = 0;
        for(int i = 0; i < 26; i++)ans = Math.max(ans, max[t][i]);
        out.print(ans);
    }
    public static class InputReader{
        BufferedReader br;
        StringTokenizer st;
        InputReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public long nextLong(){
            return Long.parseLong(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
        public String next(){
            while(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch(IOException e){}
            }
            return st.nextToken();
        }
    }
}
        