using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace takmicenje5
{
    class Program
    {
        static void Main(string[] args)
        {
            int n,s=0,o=0,i=0,a=1;
            n = int.Parse(Console.ReadLine());
            int[] u = new int[n-1];
            int[] v = new int[n-1];
            char[] c = new char[n-1];
            for(int j=0;j<n-1;j++)
            {
                string[] nz = Console.ReadLine().Split();
                u[j] = Convert.ToInt32(nz[0]);
                v[j] = Convert.ToInt32(nz[1]);
                c[j] = Convert.ToChar(nz[2]);
                if (c[j] == 'S')
                    s++;
                if (c[j] == 'I')
                    i++;
                if (c[j] == 'O')
                    o++;
            }
            a = s * i * o;
            Console.WriteLine(a);
            Console.ReadLine();
        }
    }
}