#!/usr/bin/perl
use strict;

# Takes directories on stdin and puts a list on stdout where any directory
# that has another directory as it's stem is removed
# so if you have /a/b and /a/b/c then /a/b/c is removed

my @arr;

while(<STDIN>)
{
  chomp;
  # strip "" and "/" to avoid problems
  if(length($_) >1)
  {
    push(@arr, $_);
  }
}

for(my $i = 0; $i <= $#arr; $i++)
{
  print "$arr[$i]\n";
  my $stem = $arr[$i] . "/";
  my $stemlen = length($arr[$i]) + 1;
  while ($i + 1 <= $#arr and $stem eq substr($arr[$i + 1], 0, $stemlen))
  {
    splice(@arr, $i + 1, 1);
  }
}
