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>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MAX_N = 100005;
const int A = 26;
int n;
bool exists[A];
unsigned long long res[MAX_N][A];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int sLen = (int)s.length();
    bool type1 = true;
    for (int j = 1; j < sLen; j++) type1 &= s[j] == s[0];
    if (i != 0)
      for (int j = 0; j < A; j++)
        if (res[i - 1][j] > 0) res[i][j] = 1;
    if (type1) {
      int currC = s[0] - 'a';
      if (i == 0)
        res[i][currC] = sLen;
      else
        res[i][currC] = res[i - 1][currC] + sLen * (res[i - 1][currC] + 1ULL);
    } else {
      int leftC = s[0] - 'a', rightC = s.back() - 'a';
      int prLen = 0, suffLen = 0;
      for (int j = 0; j < sLen; j++) {
        if (s[j] == s[0])
          prLen++;
        else
          break;
      }
      for (int j = sLen - 1; j >= 0; j--) {
        if (s[j] == s.back())
          suffLen++;
        else
          break;
      }
      if (leftC != rightC) {
        res[i][leftC] = (exists[leftC] ? 1 : 0) + unsigned long long(prLen);
        res[i][rightC] = (exists[rightC] ? 1 : 0) + unsigned long long(suffLen);
      } else
        res[i][leftC] =
            exists[leftC] ? (1ULL + prLen + suffLen) : max(prLen, suffLen);
      int currLen = 0;
      for (int i = 0; i < sLen; i++) {
        if (i == 0 || s[i] == s[i - 1])
          currLen++;
        else {
          res[i][s[i - 1] - 'a'] =
              max(res[i][s[i - 1] - 'a'], unsigned long long(currLen));
          currLen = 1;
        }
      }
      res[i][s.back() - 'a'] =
          max(res[i][s.back() - 'a'], unsigned long long(currLen));
    }
    for (char c : s) exists[c - 'a'] = true;
  }
  unsigned long long result = 1;
  for (int i = 0; i < A; i++) result = max(result, res[n - 1][i]);
  cout << result << endl;
}
