#!/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;
	$visited{$_}++ for grep { /[a-z]/ } @path;
	my $two = grep { $_ == 2 } values %visited;

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

walk('start');

say scalar @paths;
		

