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>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("O2")
using namespace std;
const long long MOD = 1e9 + 7;
const double PI = acos(-1);
long long add(long long x, long long y) {
  long long res = x + y;
  return (res >= MOD ? res - MOD : res);
}
long long mul(long long x, long long y) {
  long long res = x * y;
  return (res >= MOD ? res % MOD : res);
}
long long sub(long long x, long long y) {
  long long res = x - y;
  return (res < 0 ? res + MOD : res);
}
long long power(long long a, long long b, long long m = MOD) {
  long long ans = 1;
  a = a % m;
  while (b > 0) {
    if (b & 1) ans = (1ll * a * ans) % m;
    b >>= 1;
    a = (1ll * a * a) % m;
  }
  return ans;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long x, long long y) { return (x * y) / gcd(x, y); }
bool isprime(long long n) {
  if (n < 2) return 0;
  long long i = 2;
  while (i * i <= n) {
    if (n % i == 0) return 0;
    i++;
  }
  return 1;
}
bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }
double distform(long long x, long long y, long long z, long long w) {
  return sqrt(1. * pow(x - z, 2) + 1. * pow(y - w, 2));
}
long long dx[] = {-1, 1, 0, 0, -1, 1, 1, -1};
long long dy[] = {0, 0, 1, -1, 1, 1, -1, -1};
long long MAXN = 2e5 + 10;
long long inf = 1e18;
template <typename T, typename T1>
T amax(T &a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T amin(T &a, T1 b) {
  if (b < a) a = b;
  return a;
}
long long intlog(double base, double x) {
  return (long long)(log(x) / log(base));
}
bool isvalid(long long x, long long y, long long n, long long m) {
  return x >= 0 and x < n and y >= 0 and y < m;
}
template <typename T>
void read(T &x) {
  for (long long i = 0; i < ((long long)(x).size()); ++i) cin >> x[i];
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
long long query(long long start, long long end) {
  cout << "? " << start << " " << end << '\n';
  long long q;
  cin >> q;
  return q;
}
void print(long long n) { cout << "! " << n << '\n'; }
void solve() {
  long long n;
  cin >> n;
  vector<string> a(n);
  read(a);
  vector<vector<long long>> dp(26, vector<long long>(26, -inf));
  for (long long i = 0; i < 26; ++i) {
    dp[i][i] = 0;
  }
  for (long long i = 0; i < ((long long)(a).size()); ++i) {
    long long f = a[i][0] - 'a', s = a[i].back() - 'a';
    long long l = a[i].size();
    for (long long j = 0; j < 26; ++j) {
      dp[j][s] = max(dp[j][s], dp[j][f] + l);
    }
  }
  long long ans = 0;
  for (long long i = 0; i < 26; ++i) {
    amax(ans, dp[i][i]);
  }
  cout << ans << '\n';
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  solve();
}
