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>
using namespace std;
template <class T>
inline T min(T a, T b, T c) {
  return min(min(a, b), c);
}
template <class T>
inline T max(T a, T b, T c) {
  return max(max(a, b), c);
}
template <class T>
inline void checkmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline T sq(T x) {
  return x * x;
}
template <class T>
inline int countbit(T n) {
  return (n == 0) ? 0 : 1 + countbit(n & (n - 1));
}
template <class T>
inline T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
inline int input() {
  int x = 0;
  char ch = getchar();
  bool flag = true;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') flag = false;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return flag ? x : -x;
}
void output(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  int len = 0, dig[20];
  while (x) {
    dig[len++] = x % 10;
    x /= 10;
  }
  if (len == 0) dig[len++] = 0;
  while (len--) putchar(dig[len] + 48);
  putchar('\n');
}
const int N = 605;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
char s[20];
int f[26][26];
int main() {
  int n;
  cin >> n;
  while (n--) {
    cin >> s;
    int len = strlen(s);
    int l = s[0] - 'a', r = s[len - 1] - 'a';
    for (int i = 0; i < 26; ++i) {
      if (f[i][l]) f[i][r] = max(f[i][r], f[i][l] + len);
    }
    f[l][r] = max(f[l][r], len);
  }
  int ans = 0;
  for (int i = 0; i < 26; ++i) ans = max(ans, f[i][i]);
  cout << ans << endl;
  return 0;
}
