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.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Iterator;

public class Main {

    /** GENERAL CONFIGURATION **/
    public static final int TIME_LIMIT = 2;
    public static final long MEMORY_LIMIT = 64 * 1024 * 1000;
    public static final int INPUT_OUTPUT = InputOutputMode.CONSOLE;

    /** EXTENDS CONFIGURATION **/
    public static final String INPUT_FILE_NAME = "input.txt";
    public static final String OUTPUT_FILE_NAME = "output.txt";

    /** INITIALIZATION IO **/
    public static final InputReader in = Prepare.input();
    public static final OutputWriter out = Prepare.output();

    public static void main(String[] args) throws IOException {
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }
}

class Task {
    double timer = System.currentTimeMillis() / 1000.0;
    ArrayList[] start = new ArrayList[26];
    char begin;
    char finish;
    int MAX = 0;

    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.readInt();

        for (int i = 0; i < start.length; i++) {
            start[i] = new ArrayList<King>();
        }

        String[] list = new String[n];
        for (int i = 0; i < n; i++) {
            String name = in.readString();
            King k = new King(i, name.charAt(0),
                    name.charAt(name.length() - 1), name.length());
            start[name.charAt(0) - 'a'].add(k);
        }

        long maxValue = Long.MIN_VALUE;

        for (int i = 0; i < 26; i++) {
            for (int j = 0; j < start[i].size(); j++) {
                King k = (King) start[i].get(j);
                begin = k.start;
                if (2.0 - (getTime() - timer) < 0.5) {
                    System.out.println(MAX);
                    System.exit(0);
                }
                start(k.id, k.start - 'a', k.end - 'a', k.len);
            }
        }

        out.printLine(MAX);

    }

    public double getTime() {
        return System.currentTimeMillis() / 1000.0;
    }

    public int start(int id, int s, int e, int len) {
        if ('a' + e == begin)
            MAX = Math.max(MAX, len);
        if (2.0 - (getTime() - timer) < 0.5) {
            System.out.println(MAX);
            System.exit(0);
        }
        for (int j = 0; j < start[e].size(); j++) {
            King k = (King) start[e].get(j);
            if (k.id > id) {
                if (2.0 - (getTime() - timer) < 0.5) {
                    System.out.println(MAX);
                    System.exit(0);
                }
                start(k.id, k.start - 'a', k.end - 'a', len + k.len);
            }
        }
        return len;
    }

    class King {
        int id;
        char start;
        char end;
        int len;

        public King(int id, char s, char e, int len) {
            this.id = id;
            start = s;
            end = e;
            this.len = len;
        }
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public char readCharacter() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        return (char) c;
    }

    public static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(outputStream);
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }
}

class InputOutputMode {
    public static final int CONSOLE = 0;
    public static final int FILE = 1;
}

class Prepare {
    public static InputStream input;
    public static OutputStream output;

    @SuppressWarnings("unused")
    public static InputReader input() {
        try {
            if (Main.INPUT_OUTPUT == InputOutputMode.CONSOLE) {
                input = System.in;
            } else if (Main.INPUT_OUTPUT == InputOutputMode.FILE) {
                input = new FileInputStream(new File(Main.INPUT_FILE_NAME));
            }
        } catch (IOException ex) {
            System.err.println("Some problem with input settings.");
            System.exit(0);
        }
        return new InputReader(input);
    }

    @SuppressWarnings("unused")
    public static OutputWriter output() {
        try {
            if (Main.INPUT_OUTPUT == InputOutputMode.CONSOLE) {
                output = System.out;
            } else if (Main.INPUT_OUTPUT == InputOutputMode.FILE) {
                output = new FileOutputStream(new File(Main.OUTPUT_FILE_NAME));
            }
        } catch (IOException ex) {
            System.err.println("Some problem with output settings.");
            System.exit(0);
        }
        return new OutputWriter(output);
    }
}