← Home
```go
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type Node struct {
	children [26]*Node
	cnt      int
	depth    int
}

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 200000)
	scanner.Buffer(buf, len(buf))
	scanner.Split(bufio.ScanWords)

	if !scanner.Scan() {
		return
	}
	var n int
	fmt.Sscanf(scanner.Text(), "%d", &n)

	root := &Node{depth: 0}

	for i := 0; i < n; i++ {
		if !scanner.Scan() {
			break
		}
		s := scanner.Bytes()
		curr := root
		curr.cnt++
		for _, b := range s {
			idx := int(b - 'a')
			if curr.children[idx] == nil {
				curr.children[idx] = &Node{depth: curr.depth + 1}
			}
			curr = curr.children[idx]
			curr.cnt++
		}
	}

	var dfs func(u *Node) *IntHeap
	dfs = func(u *Node) *IntHeap {
		var maxHeap *IntHeap
		childHeaps := make([]*IntHeap, 0, 26)
		
		maxSize := -1
		maxIdx := -1
		countChildren := 0
		
		for i := 0; i < 26; i++ {
			if u.children[i] != nil {
				h := dfs(u.children[i])
				childHeaps = append(childHeaps, h)
				if h.Len() > maxSize {
					maxSize = h.Len()
					maxIdx = countChildren
				}
				countChildren++
			}
		}

		if maxIdx != -1 {
			maxHeap = childHeaps[maxIdx]
			for i, h := range childHeaps {
				if i != maxIdx {
					for _, val := range *h {
						heap.Push(maxHeap, val)
					}
				}
			}
		} else {
			maxHeap = &IntHeap{}
		}

		if u.depth > 0 {
			heap.Push(maxHeap, u.depth)
		}

		for maxHeap.Len() > u.cnt {
			heap.Pop(maxHeap)
		}

		return maxHeap
	}

	resultHeap := dfs(root)
	var total int64
	for _, v := range *resultHeap {
		total += int64(v)
	}

	fmt.Println(total)
}
```