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;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  map<char, int> longest;
  for (char i = 'a'; i <= 'z'; i++) {
    longest[i] = 0;
  }
  int qq;
  cin >> qq;
  string a;
  cin >> a;
  {
    int b = 0, n = (int)a.length();
    while (b < n) {
      int e = b;
      while (e < n && a[e] == a[b]) {
        e++;
      }
      longest[a[b]] = max(longest[a[b]], e - b);
      b = e;
    }
  }
  for (int i = 0; i < qq - 1; i++) {
    cin >> a;
    int n = (int)a.length();
    char prefix_char = a[0];
    char suffix_char = a[n - 1];
    int prefix_len = 1;
    int lol = 1;
    while (lol < n && a[lol] == a[0]) {
      prefix_len++;
      lol++;
    }
    int suffix_len = 1;
    lol = n - 2;
    while (lol >= 0 && a[lol] == a[n - 1]) {
      suffix_len++;
      lol--;
    }
    for (map<char, int>::iterator it = longest.begin(); it != longest.end();
         it++) {
      char cur_char = it->first;
      int cur_len = it->second;
      if (cur_len > 0) {
        if (prefix_char != cur_char && suffix_char != cur_char) {
          longest[cur_char] = 1;
        }
        if (prefix_char == cur_char && suffix_char != cur_char) {
          longest[cur_char] = 1 + prefix_len;
        }
        if (prefix_char != cur_char && suffix_char == cur_char) {
          longest[cur_char] = 1 + suffix_len;
        }
        if (prefix_char == cur_char && suffix_char == cur_char) {
          if (prefix_len == n) {
            longest[cur_char] += n * (longest[cur_char] + 1);
          } else {
            longest[cur_char] = 1 + prefix_len + suffix_len;
          }
        }
      }
    }
    {
      int b = 0;
      while (b < n) {
        int e = b;
        while (e < n && a[e] == a[b]) {
          e++;
        }
        longest[a[b]] = max(longest[a[b]], e - b);
        b = e;
      }
    }
  }
  int ans = 0;
  for (map<char, int>::iterator it = longest.begin(); it != longest.end();
       it++) {
    ans = max(ans, it->second);
  }
  assert(ans > 0);
  cout << ans << '\n';
  return 0;
}
