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 <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
ll findmax(const string &s) {
    ll ans = 0, now = 0;
    for (auto i : s)
        if (i == '1')
            now++;
        else
            ans = max(ans, now), now = 0;
    return max(ans, now);
}
int main() {
    ll n;
    cin >> n;
    vector<string>a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    //cout << 'a' + 25 << '\n';
    for (int _ = 0; _ < 26; _++) {
        vector<string>another = a;
        {
            char now = 'a' + _;
            for (int i = 0; i < n; i++) {
                for (char &j : another[i]) {
                    if (j == now) {
                        j = '1';
                    }
                    else {
                        j = '0';
                    }
                }
            }
        }

        ll nowans = findmax(another[0]);

        for (int i = 1; i < n; i++) {
            string s = another[i];
            if (s.find('0') == __cxx11::string::npos) {
                nowans = (nowans + 1) * s.size() + nowans;
            }
            else {
                ll pref = 0, suf = 0;
                for (int j = 0; j < s.size(); j++) {
                    if (s[j] == '0')
                        break;
                    pref = j + 1;
                }
                for (int j = s.size() - 1; j >= 0; j--) {
                    if (s[j] == '0')
                        break;
                    suf = s.size() - j;
                }
                //cout << pref << ' ' << suf << '\n';
                nowans = max(0ll, (suf + pref) * (nowans > 0) + 1 * (nowans > 0));
            }
        }
        ans = max(ans, nowans);
    }
    cout << ans;
    return 0;
}