#include <bits/stdc++.h>

using namespace std;

int mini(int n, int dis[], bool pr[])
{
    int min = INT_MAX, min_index;

    for (int v = 0; v < n; v++)
        if (pr[v] == false && dis[v] <= min)
            min = dis[v], min_index = v;

    return min_index;
}

int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    scanf("%d",&n);
    char graf[n][n];

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            graf[i][j] = 'X';
        }
    }

    for(int z=0;z<n-1;z++){
        int u,v;
        char x;
        cin >> u >> v >> x;
        graf[u-1][v-1]=x;
        graf[v-1][u-1]=x;
    }

    //vector<pair<int,int>> parovi;
    int br=0;

    for(int i=0;i<n;i++){
        int dis[n];
        bool pr[n];

        for (int i = 0; i < n; i++)
            dis[i] = INT_MAX, pr[i] = false;

        dis[i] = 0;

        for (int count = 0; count < n - 1; count++) {
            int u = mini(n,dis, pr);

            pr[u] = true;

            for (int v = 0; v < n; v++)

                if (!pr[v] && graf[u][v]!='X' && dis[u] != INT_MAX
                    && dis[u] + graf[u][v] < dis[v])
                    dis[v] = dis[u] + graf[u][v];
        }

        for(int z=0;z<n;z++)
            if(dis[z]%235==0 && dis[z]!=0){
                br++;
                //parovi.push_back(make_pair(i,z));
            }

            }

            printf("%d",br/2);
            /*
            for(int i=0;i<parovi.size();i++){
                printf("%d - %d\n",parovi[i].first, parovi[i].second);
            }
            */


    return 0;
}