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
#include<bits/stdc++.h>

#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define go(x, i) for(register int i = head[x]; i; i = nxt[i])
#define For(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_; ++ i)
#define FOR(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_; -- i)
#define debug(x) cout << #x << " = " << x << endl
#define mem(a, b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(a))
#define min(a, b) (a < b ? a : b)
#define max(a, b) (b < a ? a : b)
#define inf (0x3f3f3f3f)
#define INF (1e18)
#define pb push_back
#define mp make_pair
#define x first
#define y second

typedef unsigned long long ull;
typedef unsigned int uint;
typedef long long ll;
typedef std::pair<ll, int> PLI;
typedef std::pair<int, int> PII;
typedef long double ldb;
typedef double db;

namespace IO {
#define getc() ((S_ == T_) && (T_ = (S_ = Ch_) + fread(Ch_, 1, Buffsize, stdin), S_ == T_) ? 0 : *S_ ++)
#define putc(x) *nowps ++ = (x)
    const uint Buffsize = 1 << 15, Output = 1 << 23;
    static char Ch_[Buffsize], *S_ = Ch_, *T_ = Ch_;
    static char Out[Output], *nowps = Out;
    inline void flush(){fwrite(Out, 1, nowps - Out, stdout); nowps = Out;}
    template<class T>inline void read(T &_) {
        _ = 0; static char __; T ___ = 1;
        for(__ = getc(); !isdigit(__); __ = getc()) if(__ == '-') ___ = -1;
        for(; isdigit(__); __ = getc()) _ = (_ << 3) + (_ << 1) + (__ ^ 48);
        _ *= ___;
    }
    template<class T>inline void write(T _, char __ = '\n') {
        if(!_) putc('0');
        if(_ < 0) putc('-'), _ = -_;
        static uint sta[111], tp;
        for(tp = 0; _; _ /= 10) sta[++ tp] = _ % 10;
        for(; tp; putc(sta[tp --] ^ 48)); putc(__);
    }
    template<class T>inline bool chkmax(T &_, T __) {return _ < __ ? _ = __, 1 : 0;}
    template<class T>inline bool chkmin(T &_, T __) {return _ > __ ? _ = __, 1 : 0;}
}

using namespace std;
using namespace IO;

const int N = 1e5 + 3;

char S[N];

int n, dp[N];
int f[N];

int vis[N];

int main() {

	scanf("%d", &n);
	For(i, 1, n) { 
		scanf("%s", S + 1);
		int m = strlen(S + 1);
		For(j, 1, m) vis[j] = 0;
		int len1, len2, len3 = 0;
		int pos = 2; 
		while (pos <= m && (S[pos] == S[1])) ++ pos;
		len1 = pos - 1; 
		pos = m - 1;
		while (pos >= 1 && (S[pos] == S[m])) -- pos;
		len2 = m - pos;
		len3 = f[1] = 1, vis[S[1] - 'a'] = 1; 
		For(j, 2, m) {
			if (S[j] == S[j - 1])
				f[j] = f[j - 1] + 1; 
			else f[j] = 1; 
			len3 = max(len3, f[j]);
			vis[S[j] - 'a'] = 1; 
		}

		if (len1 == m) { 
			int id = S[1] - 'a';
			dp[id] = dp[id] * 2 + m;
			For(j, 0, 25) if (j != id) 
				if (dp[j] || vis[j]) dp[j] = 1; 
		}
		else { 
			int idd = S[1] - 'a';
			if (dp[idd]) dp[idd] = len1 + 1; 
			else dp[idd] = len1;
			int id = S[m] - 'a';
			if (dp[id]) dp[id] = len2 + 1;
			else dp[id] = len2;
			For(j, 0, 25) if (j != id && j != idd)
				if (dp[j] || vis[j]) dp[j] = 1; 
		}
		For(j, 1, m) dp[S[j] - 'a'] = max(dp[S[j] - 'a'], f[j]);
		/*dp[id] = dp[id] * 2 + 1;
		  For(j, 0, 25) if (j != id && dp[j])
		  dp[j] = 1; */
	}

	int ans = 0;
	For(i, 0, 25) {
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
	return flush(), 0;
}
