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.Arrays;
import java.util.Scanner;

public class Main {

	private static int[] beauty = new int[30];
	private static int[] temp = new int[30];	
	
	private static void update(String input) {
		// use input to update final result
		int i , length = input.length();
		for (i = 0;i < length;i ++) {
			char ch = input.charAt(i);
			int cnt = 0 , index = ch - 'a';			
			while (i < length && (input.charAt(i) == ch)) {
				i ++;
				cnt ++;				
			}			
			i --;
			temp[index] = Math.max(temp[index] , cnt);			
		}		
	}
	
	private static boolean isAllSame(String input) {
		for (int i = 0;i < input.length();i ++) {
			if (input.charAt(i) != input.charAt(0)) {
				return false;				
			}
		}
		return true;		
	}
	
	private static int getLength(String input) {		
		int ans = 0;
		char ch = input.charAt(0);
		int l = 0 , r = input.length() - 1;
		while (l < input.length() && (ch == input.charAt(l))) {
			ans ++;
			l ++;			
		}
		while (r >= 0 && (ch == input.charAt(r))) {
			ans ++;
			r --;			
		}
		return ans;		
	}
	
	private static int getPrefix(String string) {
		int ans = 0;
		int l = 0;
		while (l < string.length() && string.charAt(l) == string.charAt(0)) {
			l ++;
			ans ++;
		}
		return ans;
	}
	
	private static int getSuffix(String string) {
		int ans = 0;
		int r = string.length() - 1;
		while (r >= 0 && string.charAt(r) == string.charAt(string.length() - 1)) {
			r --;			
			ans ++;
		}
		return ans;
	}
	
	public static void main(String[] args) {									
		
		Scanner scan = new Scanner(System.in);		
		
		int i , j , n = scan.nextInt() , ans = 0;		
		for (i = 0;i < n;i ++) {
			Arrays.fill(temp , 0);
			String input = scan.next();	
			update(input);			
			if (isAllSame(input)) {
				int index = input.charAt(0) - 'a';
				int value = (beauty[index] + 1) * input.length() + beauty[index];
				temp[index] = Math.max(temp[index] , value);						
			} else {			
				// suffix and prefix
				if (input.charAt(0) == input.charAt(input.length() - 1) && input.length() > 1) {
					int len = getLength(input);
					int index = input.charAt(0) - 'a';				
					if (beauty[index] > 0) {					
						int value = len + 1;
						temp[index] = Math.max(temp[index] , value);					
					}
				}
				int index = input.charAt(0) - 'a';
				if (beauty[index] > 0) {
					int value = getPrefix(input) + 1;
					temp[index] = Math.max(temp[index] , value);
				}
				index = input.charAt(input.length() - 1) - 'a';
				if (beauty[index] > 0) {
					int value = getSuffix(input) + 1;
					temp[index] = Math.max(temp[index] , value);
				}
			}
			for (j = 0;j < 26;j ++) {
				if (temp[j] > 0) {
					beauty[j] = temp[j];					
				} else {
					if (beauty[j] > 0) {
						beauty[j] = 1;						
					}
				}
			}
		}
		for (i = 0;i < 26;i ++) {
			ans = Math.max(ans , beauty[i]);
		}		
		System.out.println(ans);		
		
	}	
	
}



