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.io.*;

public class P1131E
{
	private static int n;
	private static SpecialString[] stringList;
	
	private static class SpecialString extends StringAssessment
	{
		private String value;
		private final boolean monoalphabet;
		private final int startArray, endArray;
		private final char startChar, endChar;
		
		private SpecialString(String s)
		{
			super(s);
			this.value = s;
			char[] charArray = s.toCharArray();
			this.startChar = charArray[0];
			this.endChar = charArray[charArray.length - 1];
			int i = 0;
			while (true)
			{
				if (charArray.length == 1)
				{
					this.monoalphabet = true;
					this.startArray = 1;
					break;
				}
				i++;
				if (charArray[i] == this.startChar)
				{
					if (i == charArray.length - 1)
					{
						this.monoalphabet = true;
						this.startArray = charArray.length;
						break;
					}
					else
					{
						continue;
					}
				}
				else
				{
					this.monoalphabet = false;
					this.startArray = i;
					break;
				}
			}
			i = charArray.length - 1;
			while (true)
			{
				if (charArray.length == 1)
				{
					this.endArray = 1;
					break;
				}
				i--;
				if (charArray[i] == this.endChar)
				{
					if (i == 0)
					{
						this.endArray = charArray.length;
						break;
					}
					else
					{
						continue;
					}
				}
				else
				{
					this.endArray = charArray.length - 1 - i;
					break;
				}
			}
		}
	}
	
	private static class StringAssessment
	{
		protected int[] beautifulLetter;
		protected char mostBeautiful;
		
		private StringAssessment(String s)
		{
			char[] charArray = s.toCharArray();
			this.beautifulLetter = new int[26];
			for (int i = 0; i < 26; i++)
			{
				beautifulLetter[i] = 0;
			}
			char checkMark = ' ';
			int checkNumber = 0;
			for (int i = 0; i < charArray.length; i++)
			{
				if (charArray[i] == checkMark)
				{
					checkNumber++;
				}
				else
				{
					checkMark = charArray[i];
					checkNumber = 1;
				}
				if (checkNumber > this.beautifulLetter[checkMark - 'a'])
				{
					this.beautifulLetter[checkMark - 'a'] = checkNumber;
				}
			}
			this.getMostBeautiful();
		}
		
		private void getMostBeautiful()
		{
			mostBeautiful = 'a';
			int appearance = beautifulLetter[0];
			for (int i = 1; i < 26; i++)
			{
				if (appearance < beautifulLetter[i])
				{
					mostBeautiful = (char) ('a' + i);
					appearance = beautifulLetter[i];
				}
			}
		}
		
		protected void multiply(SpecialString s)
		{
			if (s.monoalphabet)
			{
				this.mostBeautiful = s.mostBeautiful;
				int letter = s.mostBeautiful - 'a';
				for (int i = 0; i < 26; i++)
				{
					if (i == letter)
					{
						this.beautifulLetter[i] = s.value.length() * (this.beautifulLetter[i] + 1) + this.beautifulLetter[letter];
					}
					else
					{
						if (this.beautifulLetter[i] != 0)
						{
							this.beautifulLetter[i] = 1;
						}
					}
				}
			}
			else
			{
				if (s.startChar == s.endChar)
				{
					int letter = s.startChar - 'a';
					for (int i = 0; i < 26; i++)
					{
						if (i == letter)
						{
							if (this.beautifulLetter[i] == 0)
							{
								this.beautifulLetter[i] = s.beautifulLetter[i];
							}
							else
							{
								this.beautifulLetter[i] = s.beautifulLetter[i] > s.startArray + s.endArray + 1 ? s.beautifulLetter[i] : s.startArray + s.endArray + 1;
							}
						}
						else
						{
							if (this.beautifulLetter[i] == 0)
							{
								this.beautifulLetter[i] = s.beautifulLetter[i];
							}
							else
							{
								this.beautifulLetter[i] = s.beautifulLetter[i] > 1 ? s.beautifulLetter[i] : 1;
							}
						}
					}
				}
				else
				{
					int start = s.startChar - 'a';
					int end = s.endChar - 'a';
					for (int i = 0; i < 26; i++)
					{
						if (i == start)
						{
							if (this.beautifulLetter[i] == 0)
							{
								this.beautifulLetter[i] = s.beautifulLetter[i];
							}
							else
							{
								this.beautifulLetter[i] = s.beautifulLetter[i] > s.startArray + 1 ? s.beautifulLetter[i] : s.startArray + 1;
							}
						}
						else if (i == end)
						{
							if (this.beautifulLetter[i] == 0)
							{
								this.beautifulLetter[i] = s.beautifulLetter[i];
							}
							else
							{
								this.beautifulLetter[i] = s.beautifulLetter[i] > s.endArray + 1 ? s.beautifulLetter[i] : s.endArray + 1;
							}
						}
						else
						{
							if (this.beautifulLetter[i] == 0)
							{
								this.beautifulLetter[i] = s.beautifulLetter[i];
							}
							else
							{
								this.beautifulLetter[i] = s.beautifulLetter[i] > 1 ? s.beautifulLetter[i] : 1;
							}
						}
					}
				}
			}
		}
	}

	public static void main(String[] args) throws IOException, NumberFormatException
	{
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(input.readLine());
		stringList = new SpecialString[n];
		for (int i = 0; i < n; i++)
		{
			stringList[i] = new SpecialString(input.readLine());
		}
		input.close();
		StringAssessment assessment = new StringAssessment(stringList[0].value);
		for (int i = 1; i < n; i++)
		{
			assessment.multiply(stringList[i]);
		}
		System.out.println(assessment.beautifulLetter[assessment.mostBeautiful - 'a']);
	}

}