// Solution for UVa problem 117
#include <iostream>
#include <string>
#include <queue>
using namespace std;

// the structure used in priority queue
struct s {
  int node, dist;
  s(){}
  s(int n, int d):node(n),dist(d){}
};

bool operator<(const s & a, const s & b){ return a.dist > b.dist; }

int edge[26][26];  // adj. matrix, edge[i][j] == 0 means no edge
bool visited[26];

int main(){

  string street;
  int u, v, total_edge_weight, odd_deg_vertices, deg;
  int end[2];
  
  while (cin >> street){
    // initially no edge is read
    memset(edge, 0, sizeof(edge));
    total_edge_weight = 0;
    // read input
    while (street != "deadend"){
      u = street[0] - 'a'; v = street[street.size() - 1] - 'a';
      total_edge_weight += street.size();
      edge[u][v] = edge[v][u] = street.size();
      cin >> street;
    }
    // mark the vertices with odd degree
    odd_deg_vertices = 0;
    for (int i = 0; i < 26; ++i){
      deg = 0;
      for (int j = 0; j < 26; ++j) deg += bool(edge[i][j]);
      if (deg % 2 == 1)	end[odd_deg_vertices++] = i;
    }
    // if no vertex with odd degree, Euler circuit is the least cost circuit
    if (odd_deg_vertices == 0){
      cout << total_edge_weight << '\n';
      continue;
    }
    // otherwise, the cost is equal to the length of an Euler path plus the
    // length of shortest path back to the start (found by Dijkstra)
    priority_queue<s> q;   // always return the largest object
    q.push(s(end[0], 0));
    s f;
    memset(visited, 0, sizeof(visited));
    for (;;){
      f = q.top(); q.pop();
      if (visited[f.node]) continue;
      visited[f.node] = true;
      if (f.node == end[1]){
        cout << total_edge_weight + f.dist << '\n';
        break;
      }
      for (int i = 0; i < 26; ++i)
        if (!visited[i] && edge[f.node][i])
      q.push(s(i, f.dist + edge[f.node][i]));
    }
  }

}
