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;
const long double PI = 3.14159265358979323;
const long long mx64 = 9223372036854775807;
const int mx32 = 2147483647;
const short int mx16 = 32767;
const long long mod_1 = 1000000007;
const long long mod_2 = 998244353;
vector<int> ans(26, 0);
pair<int, int> now, nowl, nowr;
vector<int> cnts(string x) {
  vector<int> rets(26, 0);
  vector<pair<int, int>> rpt;
  rpt.push_back({x[0], 1});
  for (int i = 1; i < x.size(); i++) {
    if (x[i] == rpt[rpt.size() - 1].first) {
      rpt[rpt.size() - 1].second++;
    } else {
      rpt.push_back({x[i], 1});
    }
  }
  for (int i = 0; i < rpt.size(); i++) {
    rets[rpt[i].first - 97] = max(rets[rpt[i].first - 97], rpt[i].second);
  }
  return rets;
}
pair<int, int> max_c(string x) {
  vector<int> getcnt = cnts(x);
  pair<int, int> ret{0, 0};
  for (int i = 0; i < 26; i++) {
    if (getcnt[i] > ret.first) {
      ret.first = getcnt[i];
      ret.second = i;
    }
  }
  return ret;
}
pair<int, int> max_l(string x) {
  int ret = 0;
  for (int i = 0; i < x.size(); i++) {
    if (x[i] == x[0]) {
      ret++;
    }
  }
  return {ret, x[0] - 97};
}
pair<int, int> max_r(string x) {
  int ret = 0;
  for (int i = x.size() - 1; i >= 0; i--) {
    if (x[i] == x[x.size() - 1]) {
      ret++;
    }
  }
  return {ret, x[x.size() - 1] - 97};
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(15);
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  now = max_c(s[0]);
  ans[now.second] = now.first;
  for (int i = 1; i < n; i++) {
    now = max_c(s[i]);
    if (now.first == s[i].size()) {
      for (int j = 0; j < 26; j++) {
        if (ans[j] && j == s[i][0] - 97) {
          ans[j] += (ans[j] + 1) * s[i].size();
        } else if (j == s[i][0] - 97) {
          ans[j] = now.first;
        } else if (ans[j]) {
          ans[j] = 1;
        }
      }
    } else {
      nowl = max_l(s[i]);
      nowr = max_r(s[i]);
      vector<int> now_cnts = cnts(s[i]);
      for (int j = 0; j < 26; j++) {
        if (ans[j] && j == nowr.second == nowl.second) {
          ans[j] = nowr.first + nowl.first + 1;
        } else if (ans[j] && j == nowr.second) {
          ans[j] = 1 + nowr.first;
        } else if (ans[j] && j == nowl.second) {
          ans[j] = 1 + nowl.first;
        } else if (ans[j] && !now_cnts[j]) {
          ans[j] = 1;
        } else {
          ans[j] = now_cnts[j];
        }
      }
    }
  }
  cout << *max_element(ans.begin(), ans.end());
  return 0;
}
