#!/usr/bin/perl -w

use v5.16;

my %g;
while (<>) {
	chomp;
	my ($n1, $n2) = split /-/;
	$g{$n1}->{$n2} = 1;
	$g{$n2}->{$n1} = 1;
}

my @paths;
my %subpaths;

sub walk {
	my (@path) = @_;
	my $here = $path[-1];
	my %visited = map { $_ => 1 } grep { /[a-z]/ } @path;

	for my $node (keys %{ $g{$here} }) {
		next if $visited{$node};
		if ($node eq 'end') {
			push @paths, [ @path, $node ];
			say join('-', @{ $paths[-1] });
		} else {
			my $p = join('-', @path, $node);
			next if $subpaths{$p}++;
			walk(@path, $node);
		}
	}
}

walk('start');

say scalar @paths;
		

