#include <bits/stdc++.h>
using namespace std;
int Set(int n, int pos) { return n = n | (1LL << pos); }
int reset(int n, int pos) { return n = n & ~(1LL << pos); }
bool check(int n, int pos) { return (bool)(n & (1LL << pos)); }
int mul(int a, int b) {
  int c;
  c = (a % 1000000007 * b % 1000000007) % 1000000007;
  return c;
}
int add(int a, int b) {
  int c;
  c = (a % 1000000007 + b % 1000000007) % 1000000007;
  return c;
}
int sub(int a, int b) {
  int c;
  c = ((a % 1000000007 - b % 1000000007) % 1000000007 + 1000000007) %
      1000000007;
  return c;
}
int power(int x, int y) {
  int res = 1;
  x = x;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long exgcd(long long x, long long y, long long& a, long long& b) {
  int flag = 0;
  long long t, la = 1, lb = 0, ra = 0, rb = 1;
  while (x % y) {
    if (flag == 0)
      la -= x / y * ra, lb -= x / y * rb;
    else
      ra -= x / y * la, rb -= x / y * lb;
    t = x, x = y, y = t % y;
    flag = 1 - flag;
  }
  if (flag == 0)
    a = ra, b = rb;
  else
    a = la, b = lb;
  return y;
}
int n;
vector<int> graph[100005];
struct Trie {
  int nextt[500005][26];
  int endmark[500005];
  int sz;
  Trie() { clear(); }
  void clear() {
    sz = 0;
    memset(nextt[0], -1, sizeof(nextt[0]));
    memset(endmark, 0, sizeof endmark);
  }
  void add(const char* str) {
    int v = 0;
    int len = strlen(str);
    for (int i = 0; i < len; ++i) {
      int id = str[i] - 'a';
      if (nextt[v][id] == -1) {
        nextt[v][id] = ++sz;
        graph[v].push_back(sz);
        graph[sz].push_back(v);
        memset(nextt[sz], -1, sizeof(nextt[sz]));
      }
      v = nextt[v][id];
    }
    endmark[v]++;
  }
  int dfs(const char* s) {
    int v = 0;
    int len = strlen(s);
    for (int i = 0; i < len; i++) {
      int id = s[i] - 'a';
      if (nextt[v][id] == -1) {
        return 0;
      }
      v = nextt[v][id];
    }
    return endmark[v];
  }
};
Trie tree;
char str[100005];
int lev[100005];
int timee;
int s_t[100006];
int f_t[100005];
pair<int, int> start_time[2 * 100005];
pair<int, int> seg[4 * 200005];
int token[100005];
void dfs0(int src, int prev, int d) {
  s_t[src] = timee;
  lev[src] = d;
  timee++;
  for (int i = 0; i < graph[src].size(); i++) {
    int adj = graph[src][i];
    if (adj != prev) {
      dfs0(adj, src, d + 1);
    }
  }
  f_t[src] = timee;
  timee++;
}
void making_s() {
  memset((start_time), (-1), sizeof(start_time));
  for (int i = 0; i <= tree.sz; i++) {
    start_time[s_t[i]].second = tree.endmark[i];
    start_time[s_t[i]].first = i;
  }
}
void build(int node, int b, int e) {
  if (b == e) {
    if (start_time[b].first == -1) {
      seg[node].first = -1;
      seg[node].second = 0;
    } else {
      seg[node].first = start_time[b].first;
      if (start_time[b].second > 0) {
        seg[node].second = lev[seg[node].first];
      } else {
        seg[node].second = 0;
      }
    }
    return;
  }
  int mid = (b + e) / 2;
  build(node * 2, b, mid);
  build(node * 2 + 1, mid + 1, e);
  if (seg[node * 2].second > seg[node * 2 + 1].second) {
    seg[node] = seg[node * 2];
  } else {
    seg[node] = seg[node * 2 + 1];
  }
}
pair<int, int> query(int node, int b, int e, int i, int j) {
  if (b > j || e < i) {
    return pair<int, int>(-1, 0);
  }
  if (b >= i && e <= j) {
    return seg[node];
  }
  int mid = (b + e) / 2;
  pair<int, int> p1, p2;
  p1 = query(node * 2, b, mid, i, j);
  p2 = query(node * 2 + 1, mid + 1, e, i, j);
  if (p1.second > p2.second) {
    return p1;
  } else {
    return p2;
  }
}
void update(int node, int b, int e, int pos, int typ) {
  if (b > pos || e < pos) {
    return;
  }
  if (b >= pos && e <= pos) {
    if (typ == 0) {
      seg[node].second = 0;
    } else {
      seg[node].second = lev[seg[node].first];
    }
    return;
  }
  int mid = (b + e) / 2;
  update(node * 2, b, mid, pos, typ);
  update(node * 2 + 1, mid + 1, e, pos, typ);
  if (seg[node * 2].second > seg[node * 2 + 1].second) {
    seg[node] = seg[node * 2];
  } else {
    seg[node] = seg[node * 2 + 1];
  }
}
void dfs(int src, int prev) {
  for (int i = 0; i < graph[src].size(); i++) {
    int adj = graph[src][i];
    if (adj != prev) {
      dfs(adj, src);
    }
  }
  if (tree.endmark[src] || src == 0) {
    token[src] = 1;
    return;
  }
  pair<int, int> ans = query(1, 1, tree.sz * 2, s_t[src] + 1, f_t[src]);
  if (ans.second == 0) return;
  update(1, 1, tree.sz * 2, s_t[ans.first], 0);
  token[ans.first] = 0;
  update(1, 1, tree.sz * 2, s_t[src], 1);
  token[src] = 1;
}
int main() {
  timee = 1;
  tree.clear();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", str);
    tree.add(str);
  }
  dfs0(0, -1, 0);
  making_s();
  build(1, 1, 2 * tree.sz);
  dfs(0, -1);
  int ans = 0;
  for (int i = 0; i <= tree.sz; i++) {
    if (token[i]) {
      ans += lev[i];
    }
  }
  cout << ans << endl;
  return 0;
}

### Prompt

Please create a solution in Cpp to the following problem:

Arkady's code contains n variables. Each variable has a unique name consisting of lowercase English letters only. One day Arkady decided to shorten his code.

He wants to replace each variable name with its non-empty prefix so that these new names are still unique (however, a new name of some variable can coincide with some old name of another or same variable). Among such possibilities he wants to find the way with the smallest possible total length of the new names.

A string a is a prefix of a string b if you can delete some (possibly none) characters from the end of b and obtain a.

Please find this minimum possible total length of new names.

Input

The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of variables.

The next n lines contain variable names, one per line. Each name is non-empty and contains only lowercase English letters. The total length of these strings is not greater than 10^5. The variable names are distinct.

Output

Print a single integer — the minimum possible total length of new variable names.

Examples

Input

3
codeforces
codehorses
code


Output

6


Input

5
abba
abb
ab
aa
aacada


Output

11


Input

3
telegram
digital
resistance


Output

3

Note

In the first example one of the best options is to shorten the names in the given order as "cod", "co", "c".

In the second example we can shorten the last name to "aac" and the first name to "a" without changing the other names.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int Set(int n, int pos) { return n = n | (1LL << pos); }
int reset(int n, int pos) { return n = n & ~(1LL << pos); }
bool check(int n, int pos) { return (bool)(n & (1LL << pos)); }
int mul(int a, int b) {
  int c;
  c = (a % 1000000007 * b % 1000000007) % 1000000007;
  return c;
}
int add(int a, int b) {
  int c;
  c = (a % 1000000007 + b % 1000000007) % 1000000007;
  return c;
}
int sub(int a, int b) {
  int c;
  c = ((a % 1000000007 - b % 1000000007) % 1000000007 + 1000000007) %
      1000000007;
  return c;
}
int power(int x, int y) {
  int res = 1;
  x = x;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long exgcd(long long x, long long y, long long& a, long long& b) {
  int flag = 0;
  long long t, la = 1, lb = 0, ra = 0, rb = 1;
  while (x % y) {
    if (flag == 0)
      la -= x / y * ra, lb -= x / y * rb;
    else
      ra -= x / y * la, rb -= x / y * lb;
    t = x, x = y, y = t % y;
    flag = 1 - flag;
  }
  if (flag == 0)
    a = ra, b = rb;
  else
    a = la, b = lb;
  return y;
}
int n;
vector<int> graph[100005];
struct Trie {
  int nextt[500005][26];
  int endmark[500005];
  int sz;
  Trie() { clear(); }
  void clear() {
    sz = 0;
    memset(nextt[0], -1, sizeof(nextt[0]));
    memset(endmark, 0, sizeof endmark);
  }
  void add(const char* str) {
    int v = 0;
    int len = strlen(str);
    for (int i = 0; i < len; ++i) {
      int id = str[i] - 'a';
      if (nextt[v][id] == -1) {
        nextt[v][id] = ++sz;
        graph[v].push_back(sz);
        graph[sz].push_back(v);
        memset(nextt[sz], -1, sizeof(nextt[sz]));
      }
      v = nextt[v][id];
    }
    endmark[v]++;
  }
  int dfs(const char* s) {
    int v = 0;
    int len = strlen(s);
    for (int i = 0; i < len; i++) {
      int id = s[i] - 'a';
      if (nextt[v][id] == -1) {
        return 0;
      }
      v = nextt[v][id];
    }
    return endmark[v];
  }
};
Trie tree;
char str[100005];
int lev[100005];
int timee;
int s_t[100006];
int f_t[100005];
pair<int, int> start_time[2 * 100005];
pair<int, int> seg[4 * 200005];
int token[100005];
void dfs0(int src, int prev, int d) {
  s_t[src] = timee;
  lev[src] = d;
  timee++;
  for (int i = 0; i < graph[src].size(); i++) {
    int adj = graph[src][i];
    if (adj != prev) {
      dfs0(adj, src, d + 1);
    }
  }
  f_t[src] = timee;
  timee++;
}
void making_s() {
  memset((start_time), (-1), sizeof(start_time));
  for (int i = 0; i <= tree.sz; i++) {
    start_time[s_t[i]].second = tree.endmark[i];
    start_time[s_t[i]].first = i;
  }
}
void build(int node, int b, int e) {
  if (b == e) {
    if (start_time[b].first == -1) {
      seg[node].first = -1;
      seg[node].second = 0;
    } else {
      seg[node].first = start_time[b].first;
      if (start_time[b].second > 0) {
        seg[node].second = lev[seg[node].first];
      } else {
        seg[node].second = 0;
      }
    }
    return;
  }
  int mid = (b + e) / 2;
  build(node * 2, b, mid);
  build(node * 2 + 1, mid + 1, e);
  if (seg[node * 2].second > seg[node * 2 + 1].second) {
    seg[node] = seg[node * 2];
  } else {
    seg[node] = seg[node * 2 + 1];
  }
}
pair<int, int> query(int node, int b, int e, int i, int j) {
  if (b > j || e < i) {
    return pair<int, int>(-1, 0);
  }
  if (b >= i && e <= j) {
    return seg[node];
  }
  int mid = (b + e) / 2;
  pair<int, int> p1, p2;
  p1 = query(node * 2, b, mid, i, j);
  p2 = query(node * 2 + 1, mid + 1, e, i, j);
  if (p1.second > p2.second) {
    return p1;
  } else {
    return p2;
  }
}
void update(int node, int b, int e, int pos, int typ) {
  if (b > pos || e < pos) {
    return;
  }
  if (b >= pos && e <= pos) {
    if (typ == 0) {
      seg[node].second = 0;
    } else {
      seg[node].second = lev[seg[node].first];
    }
    return;
  }
  int mid = (b + e) / 2;
  update(node * 2, b, mid, pos, typ);
  update(node * 2 + 1, mid + 1, e, pos, typ);
  if (seg[node * 2].second > seg[node * 2 + 1].second) {
    seg[node] = seg[node * 2];
  } else {
    seg[node] = seg[node * 2 + 1];
  }
}
void dfs(int src, int prev) {
  for (int i = 0; i < graph[src].size(); i++) {
    int adj = graph[src][i];
    if (adj != prev) {
      dfs(adj, src);
    }
  }
  if (tree.endmark[src] || src == 0) {
    token[src] = 1;
    return;
  }
  pair<int, int> ans = query(1, 1, tree.sz * 2, s_t[src] + 1, f_t[src]);
  if (ans.second == 0) return;
  update(1, 1, tree.sz * 2, s_t[ans.first], 0);
  token[ans.first] = 0;
  update(1, 1, tree.sz * 2, s_t[src], 1);
  token[src] = 1;
}
int main() {
  timee = 1;
  tree.clear();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", str);
    tree.add(str);
  }
  dfs0(0, -1, 0);
  making_s();
  build(1, 1, 2 * tree.sz);
  dfs(0, -1);
  int ans = 0;
  for (int i = 0; i <= tree.sz; i++) {
    if (token[i]) {
      ans += lev[i];
    }
  }
  cout << ans << endl;
  return 0;
}

```