#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
struct po {
  long long he, ti, LEN, _LEN, tl, len;
} qu[MAX];
int n;
string s[MAX];
int qwq[MAX][50], ans[50], ANS__;
struct SAM {
  int l, r, L;
  int tax[MAX], fa[MAX], len[MAX], id[MAX], siz[MAX];
  int son[MAX][26];
  SAM() { l = r = 1; }
  void ins(int x) {
    int tt = r;
    len[r = ++l] = ++L, siz[r] = 1;
    for (; tt && !son[tt][x]; tt = fa[tt]) son[tt][x] = r;
    if (!tt) return void(fa[r] = 1);
    int qwq = son[tt][x];
    if (len[qwq] == len[tt] + 1) return void(fa[r] = qwq);
    len[++l] = len[tt] + 1, fa[l] = fa[qwq], fa[qwq] = fa[r] = l;
    for (int i = 0; i < 26; ++i) son[l][i] = son[qwq][i];
    for (int i = tt; son[i][x] == qwq; i = fa[i]) son[i][x] = l;
  }
  void Init() {
    int ans = 0;
    for (int i = 1; i <= l; ++i) ++tax[len[i]];
    for (int i = 1; i <= n; ++i) tax[i] += tax[i - 1];
    for (int i = l; i >= 1; --i) id[tax[len[i]]--] = i;
    for (int i = l; i >= 1; --i)
      if (fa[id[i]])
        ans -= 2ll * siz[fa[id[i]]] * siz[id[i]] * len[fa[id[i]]],
            siz[fa[id[i]]] += siz[id[i]];
  }
  void Solve() {
    int ans = 0;
    Init();
    for (int i = 2; i <= n; ++i)
      ans += 1ll * i * (i - 1) + (1ll * (i - 1) * i >> 1);
  }
} _S;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    int l = s[i].length();
    qu[i].he = s[i][0] - 'a' + 1, qu[i].ti = s[i][l - 1] - 'a' + 1,
    qu[i].len = l;
    qwq[i][s[i][0] - 'a' + 1] = 1;
    if (qu[i].len == 1) qu[i].tl = 1;
    int ok = 1, fl = 0;
    for (int j = 1; j < l; j++) {
      if (s[i][j] == s[i][j - 1]) {
        ok++;
        if (j == l - 1) qu[i]._LEN = ok;
        if (ok == l) {
          qu[i].tl = 1;
          continue;
        }
      } else {
        qwq[i][s[i][j - 1] - 'a' + 1] = max(qwq[i][s[i][j - 1] - 'a' + 1], ok);
        if (fl == 0) fl = 1, qu[i].LEN = ok;
        ok = 1;
        if (j == l - 1) qu[i]._LEN = ok;
      }
    }
    qwq[i][s[i][l - 1] - 'a' + 1] = max(qwq[i][s[i][l - 1] - 'a' + 1], ok);
  }
  for (int i = 1; i <= 26; i++) ans[i] = qwq[1][i];
  for (int i = 2; i <= n; i++) {
    if (qu[i].tl) {
      int id = s[i][0] - 'a' + 1;
      for (int j = 1; j <= 26; j++)
        if (j != id && ans[j]) ans[j] = 1;
      ans[id] = (ans[id] + 1) * qu[i].len + ans[id];
      continue;
    }
    for (int j = 1; j <= 26; j++)
      if (ans[j] != 0) ans[j] = 1;
    int qaq = qu[i].he, tiid = qu[i].ti;
    ans[qaq] += qu[i].LEN;
    ans[tiid] += qu[i]._LEN;
    for (int j = 1; j <= 26; j++) ans[j] = max(ans[j], qwq[i][j]);
  }
  for (int i = 1; i <= 26; i++) ANS__ = max(ANS__, ans[i]);
  cout << ANS__ << endl;
  return 0;
}
