#!/usr/bin/env tclsh8.6

while {[gets stdin line] >= 0} {
  if {$line eq ""} continue
  lassign [split $line -] a b
  lappend paths($a) $b
  lappend paths($b) $a
  set big($a) [string match {*[A-Z]*} $a]
  set big($b) [string match {*[A-Z]*} $b]
}

proc explore {node beento} {
  global paths big count
  set double 0
  foreach n $beento {
    if {! $big($n) && [info exists been($n)]} {incr double}
    set been($n) 1
  }
  if {$double > 1} return
  if {$double && ! $big($node) && [info exists been($node)]} return
  lappend beento $node

  foreach n $paths($node) {
    if {$n eq "end"} {incr count; continue}
    if {$n eq "start"} continue
    if {$big($n) || ! [info exists been($n)] || ! $double} {
      explore $n $beento
    }
  }
}

set count 0
explore start {}
puts $count