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 static java.lang.Math.*;

import java.io.*;

public class A {

	final int MOD = 1000000007;
	final double eps = 1e-12;

	public A () throws IOException {
		int N = sc.nextInt();
		char [][] K = new char [N][];
		for (int i = 0; i < N; ++i)
			K[i] = sc.nextChars();
		
		start();
		
		int [][] F = new int [200][200];
		for (int i = 0; i < N; ++i) {
			int L = K[i].length;
			char s = K[i][0], t = K[i][L-1];
			for (char c = 'a'; c <= 'z'; ++c)
				if (F[c][s] > 0 || c == s)
					F[c][t] = max(F[c][t], F[c][s] + L);
		}
		
		int res = 0;
		for (char c = 'a'; c <= 'z'; ++c)
			res = max(res, F[c][c]);
		
		exit(res);
	}

	////////////////////////////////////////////////////////////////////////////////////
	
	static MyScanner sc;
	static PrintWriter pw = new PrintWriter(System.out);
	
	static void print (Object... a) {
		StringBuffer b = new StringBuffer();
		for (Object o : a)
			b.append(" ").append(o);
		pw.println(b.toString().trim());
	}

	static void exit (Object... a) {
		print(a);
		exit();
	}

	static void exit () {
		pw.flush();
		System.err.println("------------------");
		System.err.println("Time: " + (millis() - t) / 1000.0);
		System.exit(0);
	}
	
	static class MyScanner {
		String next() throws IOException {
			newLine();
			return line[index++];
		}
		
		char nextChar() throws IOException {
			return next().charAt(0);
		}
		
		double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
		
		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		
		long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		
		String nextLine() throws IOException {
			line = null;
			return r.readLine();
		}
		
		String [] nextStrings() throws IOException {
			line = null;
			return r.readLine().split(" ");
		}
		
		char [] nextChars() throws IOException {
			return next().toCharArray();
		}
		
		int [] nextInts() throws IOException {
			String [] L = nextStrings();
			int [] res = new int [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Integer.parseInt(L[i]);
			return res;
		}
		
		long [] nextLongs() throws IOException {
			String [] L = nextStrings();
			long [] res = new long [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Long.parseLong(L[i]);
			return res;
		}

		boolean eol() {
			return index == line.length;
		}

		//////////////////////////////////////////////
		
		private final BufferedReader r;

		MyScanner () throws IOException {
			this(new BufferedReader(new InputStreamReader(System.in)));
		}
		
		MyScanner(BufferedReader r) throws IOException { 
			this.r = r;
		}
		
		private String [] line;
		private int index;

		private void newLine() throws IOException {
			if (line == null || eol()) {
				line = r.readLine().split(" ");
				index = 0;
			}
		}		
	}
	
	////////////////////////////////////////////////////////////////////////////////////
	
	public static void main(String[] args) throws IOException {
		run();
		exit();
	}

	static void start() {
		t = millis();
	}

	static void run () throws IOException {
		sc = new MyScanner ();
		new A();
	}

	static long t;
	
	static long millis() {
		return System.currentTimeMillis();
	}	
}
