program march
  implicit none
  integer :: n, i, j, k
  integer(8) :: cnt(5) = 0_8, ans = 0_8
  character(10) :: s
  read(*,*) n
  do i = 1, n
    read(*,*) s
    j = f(ichar(s(1:1))-64)
    cnt(j) = cnt(j)+1_8
  end do
  do concurrent (i = 1:5, j = 1:5, k = 1:5, i < j .and. j < k)
    ans = ans+cnt(i)*cnt(j)*cnt(k)
  end do
  write(*,'(i0)') ans
contains
  integer function f(x)
    integer, intent(in) :: x
    f = x
    if (x == 1 .or. x == 3) return
    f = (164-8*x)/(28-x)
  end
end program march