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

import java.util.*;
import java.io.*;

public class A2 {
    public static long time = 0;

    public static void main(String[] args) throws Exception {
        time = System.currentTimeMillis();
        solve();
        out.flush();
    }

    public static void solve() throws Exception {

        
        int n1 = ni();
        int ans = 0;
        
        
        int[][] longest = new int[26][26];
        boolean[][] ex = new boolean[26][26];
        for (int i = 0; i < n1; i++) {
            String k1 = nx();
            int head = k1.charAt(0) - 'a';
            int tail = k1.charAt(k1.length() - 1) - 'a';
            
//          px(k1, head, tail);
            
            for (int j = 0; j < 26; j++) {
                if (! ex[j][head]){
                    continue;
                }
//              px(j, tail);
                if (j == tail) ans = Math.max(ans, longest[j][head] + k1.length());
            }
            boolean[] newex = new boolean[26];
            int[] newlongest = new int[26];
            for (int j =0; j < 26; j++){
                if (ex[j][head]){
                    newex[j] = true;
                    newlongest[j] = longest[j][head] + k1.length();
                }
            }
            for (int j =0; j < 26; j++){
                ex[j][tail] = ex[j][tail] || newex[j];
                longest[j][tail] = Math.max(longest[j][tail], newlongest[j]);
            }
            
            
            ex[head][tail] = true;
            if (head == tail){
                ans = Math.max(ans, k1.length());
            }
            longest[head][tail] = Math.max(longest[head][tail], k1.length());
        }
        System.out.println(ans);
    }

    public static BufferedReader in = new BufferedReader(new InputStreamReader(
            System.in));
    public static StringTokenizer st = null;

    public static String nx() throws Exception {
        for (; st == null || !st.hasMoreTokens();) {
            String k1 = in.readLine();
            if (k1 == null)
                return null;
            st = new StringTokenizer(k1);
        }
        return st.nextToken();
    }

    public static int ni() throws Exception {
        return Integer.parseInt(nx());
    }

    public static long nl() throws Exception {
        return Long.parseLong(nx());
    }

    public static double nd() throws Exception {
        return Double.parseDouble(nx());
    }

    public static void px(Object... l1) {
        System.out.println(Arrays.deepToString(l1));
    }

    public static boolean FLUSH = false;
    public static PrintWriter out = new PrintWriter(System.out, FLUSH);

    public static void p(Object... l1) {
        for (int i = 0; i < l1.length; i++) {
            if (i != 0)
                out.print(' ');
            out.print(l1[i].toString());
        }
    }

    public static void pn(Object... l1) {
        for (int i = 0; i < l1.length; i++) {
            if (i != 0)
                out.print(' ');
            out.print(l1[i].toString());
        }
        out.println();
    }

    public static void pn(Collection l1) {
        boolean first = true;
        for (Object e : l1) {
            if (first)
                first = false;
            else
                out.print(' ');
            out.print(e.toString());
        }
        out.println();
    }

}
