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