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>
char s[100005];
char t[100005];
long long len[100005];
int sum[100005];
char getChar(int i, int j) { return s[sum[i - 1] + j]; }
int getMaxPart(int u, char c) {
  int res = 0;
  int p = 1, size = len[u];
  while (p <= size) {
    if (getChar(u, p) != c)
      p++;
    else {
      int np = p;
      while (np + 1 <= size && getChar(u, np + 1) == c) np++;
      int cur = np - p + 1;
      if (cur > res) res = cur;
      p = np + 1;
    }
  }
  return res;
}
int isThere(int upper, char c) {
  for (int i = 1; i <= upper; i++)
    if (s[i] == c) return 1;
  return 0;
}
long long max(long long a, long long b) { return a > b ? a : b; }
int main() {
  int n;
  scanf("%d", &n);
  int size = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%s", t + 1);
    len[i] = strlen(t + 1);
    for (int j = 1; j <= len[i]; j++) s[++size] = t[j];
    sum[i] = size;
  }
  if (getChar(n, len[n]) != getChar(n, 1)) {
    char head = getChar(n, 1);
    int p = 1;
    while (p + 1 <= len[n] && getChar(n, p + 1) == head) p++;
    int headLen = p;
    if (isThere(sum[n - 1], head)) headLen++;
    char tail = getChar(n, len[n]);
    p = len[n];
    while (p - 1 >= 1 && getChar(n, p - 1) == tail) p--;
    int tailLen = n - p + 1;
    if (isThere(sum[n - 1], tail)) tailLen++;
    int ans = max(headLen, tailLen);
    for (int i = 0; i < 26; i++) {
      int res = getMaxPart(n, i + 'a');
      if (res > ans) ans = res;
    }
    printf("%d\n", ans);
  } else {
    int ok = 1;
    char c = getChar(n, 1);
    for (int i = 1; i <= len[n]; i++) {
      if (getChar(n, i) != c) ok = 0;
    }
    if (ok) {
      long long upper = 1e9 + 7;
      long long maxC = 0;
      for (int i = 1; i <= n - 1; i++) {
        long long curC = getMaxPart(i, c);
        long long head = 0, tail = len[i] + 1;
        while (head + 1 <= len[i] && getChar(i, head + 1) == c) head++;
        while (tail - 1 >= 1 && getChar(i, tail - 1) == c) tail--;
        if (head == 0 && tail == len[i] + 1) {
          if (maxC == 0)
            maxC = curC;
          else {
            maxC = curC;
            if (maxC == 0) maxC++;
          }
        } else if (head != 0 && tail != len[i] + 1) {
          if (head == len[i]) {
            if (maxC < upper) {
              maxC = len[i] * (maxC + 1) + maxC;
            }
          } else {
            int tailLen = len[i] - tail + 1;
            if (maxC != 0) curC = max(curC, tailLen + head + 1);
            maxC = curC;
          }
        } else {
          if (head != 0) {
            if (maxC != 0) head++;
            curC = max(curC, head);
          } else {
            tail = len[i] - tail + 1;
            if (maxC != 0) tail++;
            curC = max(curC, tail);
          }
          maxC = curC;
        }
      }
      long long ans = (maxC + 1) * len[n] + maxC;
      printf("%lld\n", ans);
    } else {
      int p = 1;
      while (p + 1 <= len[n] && getChar(n, p + 1) == c) p++;
      int headLen = p;
      p = len[n];
      while (p - 1 >= 1 && getChar(n, p - 1) == c) p--;
      int tailLen = n - p + 1;
      int ans = 0;
      if (isThere(n - 1, c)) ans = headLen + tailLen + 1;
      for (int i = 0; i < 26; i++) {
        int res = getMaxPart(n, i + 'a');
        if (res > ans) ans = res;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
