#!/usr/bin/perl -w

use v5.36;
use strict;
use experimental 'multidimensional';
use List::Util qw(sum);

my @path = '';
my %files;
my %dirs = ('' => 0);

while (<>) {
	chomp;
	if (/^\$ cd \/$/) {
		@path = '';
	} elsif (/^\$ cd \.\.$/) {
		pop @path;
	} elsif (/^\$ cd (.*)/) {
		push @path, $1;
	} elsif (/^\$ ls/) {
	} elsif (/^dir (.*)/) {
		$dirs{join('/', @path, $1)} = 0;
	} elsif (/^(\d+) (.*)/) {
		my $file = join('/', @path, $2);
		$files{$file} = $1;
	}
}

for my $dir (keys %dirs) {
	for my $file (keys %files) {
		$dirs{$dir} += $files{$file} if $file =~ /^$dir\//;
	}
}

say sum map { $dirs{$_} >= 100_000 ? 0 : $dirs{$_} } keys %dirs;

		
		
