#!/usr/bin/perl -w

use v5.16;
use List::Util qw(sum);

my %orb;
while (<>) {
	chomp;
	my @b = split /\)/;
	$orb{$b[0]}{$b[1]} = 1;
}

my %orbs;
sub walk {
	my ($b, $depth) = @_;
	say "walking $b at $depth";
	$orbs{$b} = $depth;
	for my $x (keys %{ $orb{$b} }) {
		walk($x, $depth+1);	
	}
}

walk('COM', 0);
say sum values %orbs;

		
		
		

