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>
using namespace std;
using ll = long long;
string s[100005];
ll dp[26][100005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) {
    int len = s[i].size();
    bool allsame = true;
    for (char ch : s[i]) {
      if (ch != s[i][0]) {
        allsame = false;
        break;
      }
    }
    for (int c = 0; c < 26; c++)
      if (dp[c][i - 1]) dp[c][i] = 1;
    if (allsame) {
      char ch = s[i][0];
      dp[ch - 'a'][i] = max(dp[ch - 'a'][i], len * (dp[ch - 'a'][i - 1] + 1) +
                                                 dp[ch - 'a'][i - 1]);
    } else if (s[i][0] == s[i][len - 1]) {
      int l = 0, r = len - 1;
      while (l == s[i][0]) l++;
      while (r == s[i][0]) r--;
      if (dp[s[i][l] - 'a'][i - 1])
        dp[s[i][0] - 'a'][i] = max(dp[s[i][0] - 'a'][i], (ll)l + len - r);
      for (int j = l; j <= r;) {
        int k = j;
        while (k <= r and s[i][j] == s[i][k]) k++;
        dp[s[i][j] - 'a'][i] = max(dp[s[i][j] - 'a'][i], (ll)k - j);
        j = k;
      }
    } else {
      for (int l = 0; l < s[i].size();) {
        int j = l;
        while (j < s[i].size() and s[i][j] == s[i][l]) j++;
        if (l == 0) {
          if (dp[s[i][l] - 'a'][i - 1])
            dp[s[i][l] - 'a'][i] = max(dp[s[i][l] - 'a'][i], (ll)j - l + 1);
        } else if (j == s[i].size()) {
          if (dp[s[i][l] - 'a'][i - 1])
            dp[s[i][l] - 'a'][i] = max(dp[s[i][l] - 'a'][i], (ll)j - l + 1);
        }
        dp[s[i][l] - 'a'][i] = max(dp[s[i][l] - 'a'][i], (ll)j - l);
        l = j;
      }
    }
  }
  ll mx = 0;
  for (int i = 0; i < 26; i++) mx = max(mx, dp[i][n]);
  cout << mx << endl;
}
