#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
template <class T>
inline void umin(T &x, T y) {
  x = x < y ? x : y;
}
template <class T>
inline void umax(T &x, T y) {
  x = x > y ? x : y;
}
inline unsigned int R() {
  static unsigned int seed = 416;
  return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;
}
const int N = 102000;
int n;
long long val[N][26];
bool cnt[N][26];
char s[N];
int main() {
  read(n);
  for (register int t = (1); t <= (n); t++) {
    scanf("%s", s + 1);
    int len = strlen(s + 1);
    for (register int i = (0); i <= (25); i++) cnt[t][i] = cnt[t - 1][i];
    for (register int i = (1); i <= (len); i++) cnt[t][s[i] - 'a'] = 1;
    bool flag = 1;
    for (register int i = (1); i <= (len - 1); i++) flag &= s[i] == s[i + 1];
    for (register int i = (0); i <= (25); i++)
      if (cnt[t - 1][i]) {
        val[t][i] = 1;
        for (int j = 1; j <= len; j++)
          if (s[j] == 'a' + i)
            val[t][i]++;
          else
            break;
        for (int j = len; j >= 1; j--)
          if (s[j] == 'a' + i)
            val[t][i]++;
          else
            break;
        if (flag && s[1] == 'a' + i)
          val[t][i] = val[t - 1][i] + 1LL * len * (val[t - 1][i] + 1);
      }
    for (register int i = (1); i <= (len); i++) {
      int j;
      for (j = i; j <= len; j++)
        if (s[j] != s[i]) break;
      umax(val[t][s[i] - 'a'], (long long)j - i);
      i = j - 1;
    }
  }
  long long res = 0;
  for (register int i = (0); i <= (25); i++) umax(res, val[n][i]);
  cout << res;
  return 0;
}
