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 {
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		String[] s=new String[n];
		for (int i=0;i<n;++i) s[i]=in.next();
		boolean same=true;
		int llen=0,rlen=0;
		char lch=s[n-1].charAt(0);
		char rch=s[n-1].charAt(s[n-1].length()-1);
		for (int i=0;i<s[n-1].length();++i) {
			if (i>0&&s[n-1].charAt(i)!=s[n-1].charAt(i-1)) {
				same=false;
				break;
			}
			++llen;
		}
		for (int i=s[n-1].length()-1;i>=0;--i) {
			if (i+1<s[n-1].length()&&s[n-1].charAt(i)!=s[n-1].charAt(i+1))
				break;
			++rlen;
		}
		int res=0,tmp=0;
		for (int i=0;i<s[n-1].length();++i) {
			++tmp;
			if (i>0&&s[n-1].charAt(i)!=s[n-1].charAt(i-1))
				tmp=1;
			res=Math.max(res,tmp);
		}
		for (int i=n-2;i>=0;--i) {
			boolean tsame=true;
			for (int j=1;same&&j<s[i].length();++j) if (s[i].charAt(j)!=s[i].charAt(j-1)) {
				tsame=false;
				break;
			}
			if (same&&tsame==same&&s[i].charAt(0)==lch) {
				rlen=llen=llen*(s[i].length()+1)+s[i].length();
				continue;
			}
			if (same) {
				tmp=0;
				for (int j=0;j<s[i].length();++j) {
					if (s[i].charAt(j)==lch) ++tmp;
					else tmp=0;
					res=Math.max(res,(tmp+1)*llen+tmp);
				}
				int tl=0,tr=0;
				for (int j=0;j<s[i].length();++j)
					if (s[i].charAt(j)==lch) ++tl;
					else break;
				for (int j=s[i].length()-1;j>=0;--j)
					if (s[i].charAt(j)==rch) ++tr;
					else break;
				llen=llen+(llen+1)*tl;
				rlen=rlen+(rlen+1)*tr;
				same=false;
				continue;
			}
			for (int j=0;j<s[i].length();++j) {
				if (lch==rch&&s[i].charAt(j)==lch)
					res=Math.max(res,llen+rlen+1);
				if (s[i].charAt(j)==lch)
					res=Math.max(res,llen+1);
				if (s[i].charAt(j)==rch)
					res=Math.max(res,rlen+1);
			}
		}
		res=Math.max(res,Math.max(llen,rlen));
		System.out.println(res);
	}
}