// @EXPECTED_RESULTS@: TIME_LIMIT_EXCEEDED, WRONG_ANSWER import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class SolutionIvanNoSkipLeaves { public static void main(String[] args) throws Exception { new SolutionIvanNoSkipLeaves().run(); } int n = 1; List> g = new ArrayList<>(); List> nodes = new ArrayList<>(); List weights = new ArrayList<>(); List totalD = new ArrayList<>(); List totalC = new ArrayList<>(); void fillTotal(int v) { if (g.get(v).isEmpty()) { totalD.set(v, 0); totalC.set(v, weights.get(v)); return; } int td = 0; int tc = weights.get(v); for (int u : g.get(v)) { fillTotal(u); td += totalD.get(u) + totalC.get(u); tc += totalC.get(u); } totalD.set(v, td); totalC.set(v, tc); } long ans = Long.MAX_VALUE; void solve(int v, long up, long upc) { ans = Math.min(ans, up + totalD.get(v)); for (int u : g.get(v)) { long cExceptU = totalC.get(v) - totalC.get(u); long newUpc = upc + cExceptU; long newUp = up + upc + totalD.get(v) - totalD.get(u) - totalC.get(u) + cExceptU; solve(u, newUp, newUpc); } } void run() throws Exception { Scanner scanner = new Scanner(System.in); nodes.add(new HashMap<>()); weights.add(0); int lineCount = scanner.nextInt(); scanner.nextLine(); for (int i = 0; i < lineCount; ++i) { int current = 0; String line = scanner.nextLine().strip().substring(1); StringTokenizer tokens = new StringTokenizer(line, "/"); while (tokens.hasMoreTokens()) { String token = tokens.nextToken(); current = nodes.get(current).computeIfAbsent(token, missingToken -> { nodes.add(new HashMap<>()); weights.add(0); return n++; }); } weights.set(current, weights.get(current) + 1); } for (int i = 0; i < n; ++i) { g.add(new ArrayList<>(nodes.get(i).values())); totalD.add(0); totalC.add(0); } fillTotal(0); solve(0, 0, 0); System.out.println(ans); } }