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 sun.print.DialogOnTop;

import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        char[][] words = new char[n][];
        for (int i = 0; i < n; i++)
            words[i] = sc.next().toCharArray();
        long max = 1;
        long cnt = 1;
        for (int i = 1; i < words[0].length; i++) {
            if (words[0][i] != words[0][i - 1])
                cnt = 1;
            else
                max = max(max, ++cnt);
        }
        char l = words[n - 1][0];
        char r = words[n - 1][words[n - 1].length - 1];
        long cntL = 0;
        long cntR = 0;
        for (int i = 0; i < words[n - 1].length; i++) {
            if (words[n - 1][i] == words[n - 1][0])
                cntL++;
            else
                break;
        }
        for (int i = words[n - 1].length - 1; i >= 0; i--) {
            if (words[n - 1][i] == words[n - 1][words[n - 1].length - 1])
                cntR++;
            else
                break;
        }
        boolean isSimple = cntL == words[n - 1].length;
        for (int i = n - 2; i >= 0; i--) {
            if (isSimple) {
                cnt = cntL;
                long cntSimple = 0;
                max = 0;
                for (int j = 0; j < words[i].length; j++) {
                    if (words[i][j] == l) {
                        cntSimple++;
                        cnt += cntL + 1;
                        max = max(max, cnt);
                    } else {
                        cnt = cntL;
                    }
                }
                isSimple = cntSimple == words[i].length;
                long cntL1 = cntL;
                long cntR1 = cntR;
                for (int j = 0; j < words[i].length; j++) {
                    if (words[i][j] == l)
                        cntL += cntL1 + 1;
                    else
                        break;
                }
                for (int j = words[i].length - 1; j >= 0; j--) {
                    if (words[i][j] == l)
                        cntR += cntR1 + 1;
                    else
                        break;
                }
            } else {
                for (int j = 0; j < words[i].length; j++) {
                    cnt = 1;
                    if (words[i][j] == r)
                        cnt += cntR;
                    if (words[i][j] == l)
                        cnt += cntL;
                    max = max(max, cnt);
                }
            }
        }
        pw.print(max(max, max(cntL, cntR)));
        pw.close();
    }
}

class FastScanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");

    public FastScanner(InputStream inputStream) throws FileNotFoundException {
        br = new BufferedReader(new InputStreamReader(inputStream));
    }

    public FastScanner(String file) throws FileNotFoundException {
        br = new BufferedReader(new FileReader(file));
    }

    public String next() throws IOException {
        while (!st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}