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;
template <typename T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
  if (x < y) x = y;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {
  _out << _p.first << ' ' << _p.second;
  return _out;
}
template <typename T, typename U>
inline istream &operator>>(istream &_in, pair<T, U> &_p) {
  _in >> _p.first >> _p.second;
  return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
  if (_v.empty()) {
    return _out;
  }
  _out << _v.front();
  for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
  for (auto &_i : _v) {
    _in >> _i;
  }
  return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) {
  if (_s.empty()) {
    return _out;
  }
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) {
    _out << ' ' << *_it;
  }
  return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {
  if (_m.empty()) {
    return _out;
  }
  _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {
    _out << ", (" << _it->first << ": " << _it->second << ')';
  }
  return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) {
  if (_m.empty()) {
    return _out;
  }
  _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) {
    _out << ", (" << _it->first << ": " << _it->second << ')';
  }
  return _out;
}
const string FILENAME = "input";
const int MAXN = 100228;
int n;
string s[MAXN];
int was[26];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int curl = 0;
  char last = -1;
  int res = 0;
  for (int i = 0; i < (int)(s[n - 1]).size(); i++) {
    if (last == -1) {
      last = s[n - 1][i];
      curl = 1;
    } else {
      if (last != s[n - 1][i]) {
        last = s[n - 1][i];
        curl = 1;
      } else {
        curl++;
      }
    }
    chkmax(res, curl);
  }
  bool kek = res == (int)(s[n - 1]).size();
  if (res != (int)(s[n - 1]).size() && s[n - 1][0] == s[n - 1].back()) {
    int uk = 0;
    while (uk < (int)(s[n - 1]).size() && s[n - 1][uk] == s[n - 1][0]) {
      uk++;
    }
    int uk1 = (int)(s[n - 1]).size() - 1;
    while (uk1 >= 0 && s[n - 1][uk1] == s[n - 1].back()) {
      uk1--;
    }
    int len = uk + n - 1 - uk1;
    for (int i = 0; i < n - 1; i++) {
      for (auto x : s[i]) {
        was[x - 'a'] = true;
      }
    }
    if (was[s[n - 1][0] - 'a']) {
      chkmax(res, len + 1);
    }
  }
  if (!kek) {
    cout << res << endl;
    return 0;
  }
  for (int i = 0; i < n - 1; i++) {
    for (auto x : s[i]) {
      was[x - 'a']++;
    }
  }
  int cur = res;
  char c = s[n - 1][0];
  for (int i = n - 2; i >= 0; i--) {
    int f = 0;
    int t = 0;
    for (int j = 0; j < (int)(s[i]).size(); j++) {
      was[s[i][j] - 'a']--;
      if (s[i][j] == c) {
        f++;
      } else {
        f = 0;
      }
      chkmax(t, f);
    }
    if (t == (int)(s[i]).size()) {
      cur = cur * (t + 1) + t;
      continue;
    }
    if (s[i][0] == c && s[i][(int)(s[i]).size() - 1] == c) {
      int uk = 0;
      while (uk < (int)(s[i]).size() && s[i][uk] == s[i][0]) {
        uk++;
      }
      int uk1 = (int)(s[i]).size() - 1;
      while (uk1 >= 0 && s[i][uk1] == s[i].back()) {
        uk1--;
      }
      int len = uk + n - 1 - uk1;
      if (was[c - 'a']) {
        chkmax(t, len + 1);
      }
    }
    if (t == 0) {
      if (was[c - 'a']) {
        cur = cur * 2 + 1;
      }
      break;
    }
    cur = cur * (t + 1) + t;
    break;
  }
  cout << cur << endl;
  return 0;
}
