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 sys

def solve(p, n):
    curState = getStat(p[0])
    for i in range(1, n):
        newState = getStat(p[i])
        #import pdb; pdb.set_trace()
        lp = len(p[i])
        st = p[i][0]
        stl = 1
        for j in range(1, lp):
            if p[i][j] == st:
                stl += 1
                continue
            break
        en = p[i][-1]
        enl = 1
        for j in range(1, lp):
            rj = lp - 1 - j
            if p[i][rj] == en:
                enl += 1
                continue
            break
        #import pdb; pdb.set_trace()
        # dp
        if stl == lp:
            #assert(enl == lp)
            curState[ord(st) - ord('a')] = (curState[ord(st) - ord('a')] + 1) * lp + curState[ord(st) - ord('a')]
        elif st == en:
            #assert(stl + enl < lp)
            if curState[ord(st) - ord('a')] > 0:
                curState[ord(st) - ord('a')] = max(curState[ord(st) - ord('a')], 1+stl+enl)

        for j in range(26):
            curState[j] = max(curState[j], newState[j])

    res = 0
    for i in range(26):
        res = max(res, curState[i])
    return res

def getStat(s):
    res = [0]*26
    ls = len(s)
    if ls == 1:
        res[ord(s[0]) - ord('a')] = 1
        return res
    cur = s[0]
    curl = 1
    for idx in range(1, ls):
        if s[idx] != cur:
            res[ord(cur) - ord('a')] = max(res[ord(cur) - ord('a')], curl)
            cur = s[idx]
            curl = 0
        curl += 1
    return res

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    p = []
    for i in range(n):
        p.append(sys.stdin.readline().strip())
    print solve(p, n)
        
