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

/**
 * <p>
 * Solved
 * </p>
 * <p>
 * Created on Aug 18, 2012, 8:38:24 PM
 * </p>
 * @Author Andy Y.F. Huang
 */
public class p191ADynastyPuzzles {
  private void solve(int test_number) {
    int names = in.nextInt();
    int dp[][] = new int[26][26];
    for (int i = 0; i < names; i++) {
      String name = in.nextLine();
      int start = name.charAt(0) - 'a';
      int end = name.charAt(name.length() - 1) - 'a';
      for (int j = 0; j < 26; j++)
        if (dp[j][start]  > 0)
          dp[j][end] = Math.max(dp[j][end], dp[j][start] + name.length());
      dp[start][end] = Math.max(dp[start][end], name.length()); 
    }
    int id = 0;
    for (int i = 0; i < 26; i++)
      if (dp[i][i] > dp[id][id])
        id = i;
    out.appendln(dp[id][id]);
  }

  private Input in;
  private Output out;

  void solve() {
    in = new Input("");
    out = new Output("");
    solve(1);
    out.close();
  }

  public static void main(String[] args) {
    p191ADynastyPuzzles solver = new p191ADynastyPuzzles();
    solver.solve();
  }
}

class Input {
  private java.io.BufferedReader reader;
  private java.util.StringTokenizer tokenizer;

  Input(String filename) {
    if (!filename.isEmpty()) {
      try {
        reader = new java.io.BufferedReader(new java.io.FileReader(filename));
      }
      catch (java.io.FileNotFoundException e) {
        throw new RuntimeException(e);
      }
    }
    else
      reader = new java.io.BufferedReader(new java.io.InputStreamReader(
          System.in));
    tokenizer = new java.util.StringTokenizer("");
  }

  String next() {
    while (!tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      }
      catch (java.io.IOException e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  String nextLine() {
    try {
      return reader.readLine();
    }
    catch (java.io.IOException e) {
      throw new RuntimeException(e);
    }
  }

  long nextLong() {
    return Long.parseLong(next());
  }

  int nextInt() {
    return Integer.parseInt(next());
  }

  double nextDouble() {
    return Double.parseDouble(next());
  }

}

class Output {
  private java.io.PrintWriter buffer;

  Output(String filename) {
    if (!filename.isEmpty())
      try {
        buffer = new java.io.PrintWriter(filename);
      }
      catch (java.io.FileNotFoundException e) {
        throw new RuntimeException();
      }
    else
      buffer = new java.io.PrintWriter(System.out);
  }

  void flush() {
    buffer.flush();
  }

  void close() {
    buffer.close();
  }

  void append(Object... obj) {
    for (int i = 0; i < obj.length; i++) {
      if (i != 0)
        buffer.write(' ');
      buffer.print(obj[i]);
    }
  }

  void appendln(Object... obj) {
    append(obj);
    buffer.write('\n');
  }
}
