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;
const int N_MAX = 100010;
struct StringProfile {
  vector<int> bestCount;
  char charL, charR;
  int countL, countR;
  int len;
  StringProfile() {
    bestCount.resize(26, 0);
    countL = countR = len = 0;
    charL = charR = 0;
  }
  StringProfile(const string& str) {
    len = str.size();
    charL = str.front();
    charR = str.back();
    countL = 1;
    for (int i = 1; i < len && str[i] == charL; ++i) {
      countL = i + 1;
    }
    countR = 1;
    for (int i = len - 2; i >= 0 && str[i] == charR; --i) {
      countR = len - i;
    }
    bestCount.resize(26, 0);
    int prev = 0;
    for (int i = 1; i <= len; ++i) {
      if (i == len || str[i] != str[i - 1]) {
        int code = charCode(str[i - 1]);
        bestCount[code] = max(bestCount[code], i - prev);
        prev = i;
      }
    }
  }
  inline int charCode(char ch) { return ch - 'a'; }
  StringProfile multiply(StringProfile p) {
    StringProfile product;
    if (p.len == p.countL) {
      int ch = charCode(p.charL);
      product.bestCount[ch] = (bestCount[ch] + 1) * p.len + bestCount[ch];
      product.charL = product.charR = p.charL;
      for (int i = 0; i < 26; ++i) {
        if (i != ch) {
          product.bestCount[i] = (bestCount[i] > 0 ? 1 : 0);
        }
      }
      if (charL == p.charL) {
        product.countL = countL + p.len * (countL + 1);
      } else {
        product.countL = p.len;
      }
      if (charR == p.charR) {
        product.countR = countR + p.len * (countR + 1);
      } else {
        product.countR = p.len;
      }
      if (len == countL && charL == p.charL) {
        product.len = product.countL;
      }
    } else {
      product.charL = p.charL;
      product.charR = p.charR;
      product.countL = p.countL;
      product.countR = p.countR;
      product.bestCount = p.bestCount;
      int codeL = charCode(p.charL);
      int codeR = charCode(p.charR);
      if (codeL == codeR && bestCount[codeL] > 0) {
        product.bestCount[codeL] =
            max(product.bestCount[codeL], p.countL + p.countR + 1);
      }
      if (bestCount[codeL] > 0) {
        product.bestCount[codeL] = max(product.bestCount[codeL], p.countL + 1);
      }
      if (bestCount[codeR] > 0) {
        product.bestCount[codeR] = max(product.bestCount[codeR], p.countR + 1);
      }
      for (int i = 0; i < 26; ++i) {
        if (product.bestCount[i] == 0 && bestCount[i] > 0) {
          product.bestCount[i] = 1;
        }
      }
    }
    return product;
  }
};
string P[N_MAX];
int n;
void outerInit() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  auto fi = new ifstream("test.inp");
  if (*fi) {
    cin.rdbuf(fi->rdbuf());
  }
}
void readData() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> P[i];
  }
}
void initData() {}
void solveData() {
  StringProfile profile(P[1]);
  for (int i = 2; i <= n; ++i) {
    StringProfile nextProfile(P[i]);
    profile = profile.multiply(nextProfile);
  }
  cout << *max_element(profile.bestCount.begin(), profile.bestCount.end());
}
int main() {
  outerInit();
  readData();
  initData();
  solveData();
}
