10
abdcced
bdacdac
ecb
dc
eaeeebdd
adcdbadcac
eb
aadecccde
edbaeacad
accd
 100
d
a
e
eb
c
d
d
e
c
e
ac
d
c
aa
a
e
da
e
e
c
e
a
c
c
bc
bd
d
da
cc
be
b
a
ee
d
be
be
e
b
a
ed
cb
ab
a
ea
ac
aa
ed
d
b
eb
e
ed
c
ce
c
d
c
d
d
ee
e
b
ea
ea
da
ab
ba
ed
da
ec
ea
bd
ee
dc
d
bd
d
c
cc
ab
bd
a
ad
e
d
e
bc
bb
c
bc
a
a
e
ca
ac
c
ad
c
be
d
 3
ab
acb
ba
 10
a
b
a
c
b
a
b
a
a
a
 5
cab
bbc
caa
ccc
aca
 3
ac
abc
ca
 5
ab
bc
cd
de
ffffffffff
 16
ddgcb
fgbhgbdg
gha
dh
ddfb
fggbc
edb
hd
d
hfgcabf
hdaef
fhbcdgba
chee
cafeggc
f
ecb
 50
agecd
cghafi
fiide
iecc
jbdcfjhgd
diee
hfeg
ehc
gfijgjh
gacaifebg
dicbbddc
hjgciaei
jjcdh
g
gc
cf
hfdjhd
c
icidbec
ji
eeh
cgeejggc
acfd
jjg
ajefdj
eghhebiic
bih
gbb
jjaa
idc
gafi
ecg
dbigbjiehj
cedif
ahidfaaajg
hfhhiccbgb
dgegjgieif
hgjebhfdc
j
ahehd
ahdah
bijbhh
a
dabiggfhac
dedigbjbf
ihbdj
iihagchd
gfebhfdi
jbjdcggdh
f

0
 35
 5
 6
 9
 5
 10
 7
 37

#include <bits/stdc++.h>
const double eps = (1e-10);
using namespace std;
int dcmp(double a, double b) {
  return fabs(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
long long getBit(long long num, int idx) { return ((num >> idx) & 1ll) == 1ll; }
long long setBit1(long long num, int idx) { return num | (1ll << idx); }
long long setBit0(long long num, int idx) { return num & ~(1ll << idx); }
long long flipBit(long long num, int idx) { return num ^ (1ll << idx); }
int countNumBit1(long long mask) {
  int ret = 0;
  while (mask) {
    mask &= (mask - 1ll);
    ++ret;
  }
  return ret;
}
int mem[500001][27][2], ch;
int n;
vector<string> v;
int inf = 100000000;
int solve(int id, int ls, int f) {
  if (id == n) {
    if (f) return 0;
    return -inf;
  }
  int &ret = mem[id][ls][f];
  if (ret != -1) return ret;
  int p1 = -inf, p2 = -inf;
  if (v[id][0] - 'a' == ls) {
    int ff = ((v[id][((int)(v[id]).size()) - 1] - 'a') == ch) ? 1 : 0;
    int lss = (v[id][((int)(v[id]).size()) - 1] - 'a');
    p1 = ((int)(v[id]).size()) + solve(id + 1, lss, ff);
  }
  p2 = solve(id + 1, ls, f);
  ret = max(p1, p2);
  return ret;
}
int main() {
  cin >> n;
  string st;
  for (int i = 0; i < n; i++) {
    cin >> st;
    v.push_back(st);
  }
  int fl;
  memset(mem, -1, sizeof(mem));
  int ans = 0;
  for (int i = 0; i < n; i++) {
    string s = v[i];
    ch = s[0] - 'a';
    int la = s[((int)(s).size()) - 1] - 'a';
    fl = 0;
    if (ch == la) fl = 1;
    ans = max(ans, ((int)(s).size()) + solve(i + 1, la, fl));
  }
  cout << ans << endl;
}
