#include <bits/stdc++.h>
using namespace std;
void File() {
  freopen("e.in", "r", stdin);
  freopen("e.out", "w", stdout);
}
template <typename T>
void read(T &_) {
  _ = 0;
  T f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) _ = (_ << 1) + (_ << 3) + (c ^ '0');
  _ *= f;
}
const int maxn = 1e5 + 10;
int n;
vector<int> s[maxn];
char str[maxn];
bool vis[maxn][26];
long long ans;
long long calc(int k, int c) {
  if (!k) return 0;
  long long ret = 0;
  bool flag = true;
  for (int j = 0, j_end_ = s[k].size() - 1; j <= j_end_; ++j)
    if (s[k][j] != c) {
      flag = false;
      break;
    }
  if (!flag) {
    long long up = 0, down = 0, len = 0;
    for (int j = 0, j_end_ = s[k].size() - 1; j <= j_end_; ++j) {
      if (s[k][j] != c) break;
      up = j + 1;
    }
    for (int j = s[k].size() - 1, j_end_ = 0; j >= j_end_; --j) {
      if (s[k][j] != c) break;
      down = s[k].size() - j;
    }
    if (vis[k - 1][c])
      ret = max(ret, up + down + 1);
    else
      ret = max(ret, max(up, down));
    for (int j = 0, j_end_ = s[k].size() - 1; j <= j_end_; ++j) {
      if (s[k][j] != c)
        len = 0;
      else
        ++len;
      ret = max(ret, len);
    }
  } else {
    long long fuck = calc(k - 1, c);
    ret = max(ret, 1ll * (fuck + 1) * (long long)s[k].size() + fuck);
  }
  return ret;
}
int main() {
  read(n);
  for (int i = 1, i_end_ = n; i <= i_end_; ++i) {
    scanf("%s", str + 1);
    for (int j = 1, j_end_ = strlen(str + 1); j <= j_end_; ++j) {
      s[i].push_back(str[j] - 'a');
      vis[i][s[i][j - 1]] = 1;
    }
  }
  for (int i = 1, i_end_ = n; i <= i_end_; ++i)
    for (int j = 0, j_end_ = 25; j <= j_end_; ++j) vis[i][j] += vis[i - 1][j];
  for (int i = 0, i_end_ = 25; i <= i_end_; ++i) ans = max(ans, calc(n, i));
  printf("%lld\n", ans);
  return 0;
}
