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>
using namespace std;
long long int INF = 9223372036854775807;
const long long int mod = 1000000007;
long long int MOD(long long int a, long long int b) {
  if (a > b)
    return a - b;
  else
    return b - a;
}
long long int max3(long long int a, long long int b, long long int c) {
  return max(c, max(a, b));
}
long long int min3(long long int a, long long int b, long long int c) {
  return min(a, min(b, c));
}
long long int power(long long int x, long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long int power1(long long int x, long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res % mod;
}
long long int logg(long long int a) {
  long long int x = 0;
  while (a > 1) {
    x++;
    a /= 2;
  }
  return x;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int abso(long long int x) {
  if (x < 0) {
    return -x;
  }
  return x;
}
long long int ceiling(long long int a, long long int b) {
  if (a % b == 0) {
    return a / b;
  } else {
    return a / b + 1;
  }
}
long long int modinv(long long int x) { return power1(x, mod - 2); }
int main() {
  int n;
  cin >> n;
  vector<string> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  int max_length = 0;
  char left = 'a';
  char right = 'b';
  int left_length = 0;
  int right_length = 0;
  bool connect = false;
  for (int j = n - 1; j >= 0; j--) {
    if (j == n - 1) {
      int l = 1;
      int r = 1;
      char x = p[j][0];
      char y = p[j][p[j].size() - 1];
      for (int k = 1; k < p[j].size(); k++) {
        if (p[j][k] == x) {
          l++;
        } else {
          break;
        }
      }
      for (int k = p[j].size() - 2; k >= 0; k--) {
        if (p[j][k] == y) {
          r++;
        } else {
          break;
        }
      }
      int cnt = 0;
      for (int k = 0; k < p[j].size(); k++) {
        if (k == 0) {
          cnt++;
        } else {
          if (p[j][k] == p[j][k - 1]) {
            cnt++;
          } else {
            max_length = max(max_length, cnt);
            cnt = 1;
          }
        }
      }
      max_length = max(max_length, cnt);
      if (max_length == p[j].size()) {
        connect = true;
      }
      left = x;
      right = y;
      left_length = l;
      right_length = r;
    } else {
      if (connect) {
        int cur = 0;
        for (int k = 0; k < p[j].size(); k++) {
          if (k == 0) {
            if (p[j][k] == left) {
              cur++;
            }
          } else {
            if (p[j][k - 1] == p[j][k] && p[j][k] == left) {
              cur++;
            } else {
              max_length = max(max_length, cur + (cur + 1) * (left_length));
              if (p[j][k] == left) {
                cur = 1;
              } else {
                cur = 0;
              }
            }
          }
        }
        max_length = max(max_length, cur + (cur + 1) * (left_length));
        int temp = left_length;
        for (int k = 0; k < p[j].size(); k++) {
          if (p[j][k] == left) {
            temp += 1 + left_length;
          } else {
            break;
          }
        }
        left_length = temp;
        temp = right_length;
        for (int k = p[j].size() - 1; k >= 0; k--) {
          if (p[j][k] == left) {
            temp += 1 + right_length;
          } else {
            break;
          }
        }
        right_length = temp;
        int cnt = 0;
        for (int k = 0; k < p[j].size(); k++) {
          if (p[j][k] == left) {
            cnt++;
          }
        }
        if (cnt == p[j].size()) {
          connect = true;
        } else {
          connect = false;
        }
      } else {
        for (int k = 0; k < p[j].size(); k++) {
          int cur = 1;
          if (p[j][k] == right) {
            cur += right_length;
          }
          if (p[j][k] == left) {
            cur += left_length;
          }
          max_length = max(max_length, cur);
        }
      }
    }
  }
  cout << max_length;
}
