#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long int LINF = 0x3f3f3f3f3f3f3f3fll;
const int MAX = 1e5 + 10;
int n;
vector<string> v;
vector<char> igual;
int tem[MAX][26];
void pre() {
  for (int i = 0; i < n; i++) {
    bool ig = 1;
    for (int j = 1; j < v[i].size(); j++)
      if (v[i][j] != v[i][j - 1]) ig = 0;
    if (!ig)
      igual.push_back('$');
    else
      igual.push_back(v[i][0]);
  }
  for (char c : v[0]) tem[0][c - 'a'] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 26; j++) tem[i][j] = tem[i - 1][j];
    for (char c : v[i]) tem[i][c - 'a'] = 1;
  }
}
long long int solve(int p, char c) {
  if (p == -1) return 0;
  if (igual[p] == c) {
    long long int x = solve(p - 1, c);
    return (long long int)v[p].size() * (x + 1) + x;
  }
  int pr = 0, su = 0;
  for (int i = 0; i < v[p].size(); i++) {
    if (v[p][i] != c) break;
    pr++;
  }
  for (int i = (int)v[p].size() - 1; i >= 0; i--) {
    if (v[p][i] != c) break;
    su++;
  }
  int ma = 0, tam = 0;
  for (int i = 0; i < v[p].size(); i++) {
    if (v[p][i] == c)
      tam++;
    else
      tam = 0;
    ma = max(ma, tam);
  }
  if (p == 0) {
    return ma;
  }
  int y = max(su, pr) + tem[p - 1][c - 'a'];
  if (tem[p - 1][c - 'a']) y = su + pr + 1;
  return max(ma, y);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    string a;
    cin >> a;
    v.push_back(a);
  }
  pre();
  long long int out = 0;
  for (int i = 0; i < 26; i++) out = max(out, solve(n - 1, 'a' + i));
  cout << out << endl;
  return 0;
}
