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;
int n;
string s[100005];
void swap(string &x, string &y) {
  string tg = x;
  x = y;
  y = tg;
  return;
}
int sta, dp[100005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  for (int i = 1; i <= n / 2; i++) {
    swap(s[i], s[n - i + 1]);
  }
  int res = 1;
  for (int i = 1; i < s[1].size(); i++) {
    if (s[1][i] != s[1][i - 1]) {
      res = 1;
    } else {
      res++;
    }
    dp[1] = max(dp[1], res);
  }
  if (s[1][0] == s[1][s[1].size() - 1]) {
    sta = 0;
  } else {
    sta = 1;
  }
  int head = 1;
  for (int i = 1; i < s[1].size(); i++) {
    if (s[1][i] == s[1][i - 1]) {
      head++;
    } else
      break;
  }
  int tail = 1;
  for (int i = 1 * s[1].size() - 2; i >= 0; i--) {
    if (s[1][i + 1] == s[1][i]) {
      tail++;
    } else
      break;
  }
  int maxi = dp[1];
  if (s[1][0] == 'g') {
    cout << dp[1] << " " << head << " " << tail << " " << s[1][s[1].size() - 1]
         << endl;
  }
  if (sta == 1) {
    for (int i = 2; i <= n; i++) {
      for (int j = 0; j < s[i].size(); j++) {
        if (s[i][j] == s[1][0] && head == dp[1]) {
          maxi = head + 1;
        } else if (s[i][j] == s[1][s[1].size() - 1] && tail == dp[1]) {
          maxi = head + 1;
        }
      }
    }
    cout << maxi << endl;
    return 0;
  }
  if (sta == 0 && head < s[1].size()) {
    for (int i = 2; i <= n; i++) {
      for (int j = 0; j < s[i].size(); j++) {
        if (s[i][j] == s[1][0]) {
          maxi = max(maxi, head + tail + 1);
        }
      }
    }
    cout << maxi << endl;
    return 0;
  }
  if (sta == 0) {
    for (int i = 2; i <= n; i++) {
      if (sta == 0) {
        int ans = 0;
        int maxx = 0;
        for (int j = 0; j < s[i].size(); j++) {
          if (s[i][j] == s[1][0]) {
            ans++;
            maxx = max(maxx, ans);
          } else {
            ans = 0;
          }
        }
        int cnthe = 0, cntta = 0;
        for (int j = 0; j < s[i].size(); j++) {
          if (s[i][j] == s[1][0]) {
            cnthe++;
          } else {
            break;
          }
        }
        for (int j = s[i].size() - 1; j >= 0; j--) {
          if (s[i][j] == s[1][0]) {
            cntta++;
          } else {
            break;
          }
        }
        if (maxx != s[i].size()) {
          sta = 1;
          dp[i] = (maxx + 1) * head + maxx;
          head = (cnthe + 1) * head + cnthe;
          tail = (cntta + 1) * tail + cntta;
        } else {
          head = s[i].size() + (s[i].size() + 1) * head;
          tail = head;
          dp[i] = head;
        }
        maxi = max(maxi, dp[i]);
      } else if (sta == 1) {
        for (int j = 0; j < s[i].size(); j++) {
          if (s[i][j] == s[1][0]) {
            maxi = max(maxi, head + tail + 1);
          }
        }
      }
    }
    cout << maxi << endl;
  }
  return 0;
}
