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

//package contest_121_div2;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * Date     : May 27, 2012
 * Time     : 5:46:55 PM
 * Email    : denys.astanin@gmail.com
 */

public class C {
	public static void main(String[] args) throws IOException {
		new C().run();
	}

	int nextInt() throws IOException {
		in.nextToken();
		return (int) in.nval;
	}

	String nextString() throws IOException {
		in.nextToken();
		return (String) in.sval;
	}

	StreamTokenizer in;
	Writer writer;
	Reader reader;
	private class Node implements Comparable<Node> {
		private String name;
		private int time;
		private boolean used = false;
		public Node(String s, int t) {
			name = s;
			time = t;
		}
		@Override
		public int compareTo(Node arg0) {
			return time - arg0.time;
		}
		@Override
		public String toString() {
			return name;
		}
	}
	Map<Character, List<Node>> start = new HashMap<Character, List<Node>>();
	Map<Character, List<Node>> end = new HashMap<Character, List<Node>>();
	void run() throws IOException {
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		reader = oj ? new InputStreamReader(System.in, "ISO-8859-1")
				: new FileReader("src/contest_121_div2/C.txt");
		writer = new OutputStreamWriter(System.out, "ISO-8859-1");
		in = new StreamTokenizer(new BufferedReader(reader));
		PrintWriter out = new PrintWriter(writer);
		int n = nextInt();

		for (int i = 0; i < n; i++) {
			String str = nextString();
			List<Node> lstS = start.get(str.charAt(0));
			if (lstS == null) {
				lstS = new ArrayList<Node>();
				start.put(str.charAt(0), lstS);
			}
			Node node = new Node(str, i);
			lstS.add(node);
		}
		long answ = 0;
		
		for (char i = 'a'; i <= 'z'; i++) {
			answ = Math.max(answ, check(i));
		}
		out.println(answ);
		out.flush();
		out.close();
	}
	int depth = 0;
	char startChar= ' ';
	
	private long check(char ch) {
		long answer = 0;
		depth++;
		List<Node> lstV = start.get(ch);
		if (lstV == null) {
			depth = 0;
			return 0;
		}
		if (depth == 1) {
			startChar = ch;
		}
		for (Node node : lstV) {
			if (!node.used) {
//				System.out.println(node);
				node.used = true;
				char ech = node.name.charAt(node.name.length() - 1);
				answer += check(ech) + (ech == startChar ? node.name.length() : 0);
				node.used = false;
			}
		}	
		depth--;
		return answer;
	}
}
