Kundu and Tree
Difficulty: Hard

Kundu is true tree lover. Tree is a connected graph having _N_ vertices and _N-1_  edges. Today when he got a tree, he colored each edge with one of either red(`r`) or black(`b`) color. He is interested in knowing how many triplets(a,b,c) of vertices are there , such that, there is atleast one edge having red color on all the three paths i.e. from vertex _a_ to _b_, vertex _b_ to _c_ and vertex _c_ to _a_ . Note that (a,b,c), (b,a,c) and all such permutations will be considered as the same triplet. 

If the answer is greater than 10<sup>9</sup> + 7, print the answer modulo (%) 10<sup>9</sup> + 7.

**Input Format**  
The first line contains an integer _N_, i.e., the number of vertices in tree.  
The next _N-1_ lines represent edges:  2 space separated integers denoting an edge followed by a color of the edge. A color of an edge is denoted by a small letter of English alphabet, and it can be either red(`r`) or black(`b`).  

**Output Format**  
Print a single number i.e. the number of triplets.  

**Constraints**  
1 &le; _N_ &le; 10<sup>5</sup><br> 
A node is numbered between 1 to *N*.  

**Sample Input**  

	5
    1 2 b
    2 3 r
    3 4 r
    4 5 b

    
**Sample Output**  

	4

**Explanation**

Given tree is something like this.<br>
![image](https://s3.amazonaws.com/hr-assets/0/1526563539-7ce683027b-kundu-and-trees.jpg)

(2,3,4) is one such triplet because on all paths i.e 2 to 3, 3 to 4 and 2 to 4 there is atleast one edge having red color.<br>
(2,3,5), (1,3,4) and (1,3,5) are other such triplets.  
Note that (1,2,3) is NOT a triplet, because the path from 1 to 2 does not have an edge with red color.

Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (Go):
    // When I wrote this, only God and I understood what I was doing
    // Now, God only knows

    #include<bits/stdc++.h>
    using namespace std;
    #define assn(n,a,b) assert(n<=b && n>=a)
    #define pb push_back
    typedef vector<int> VI;
    typedef long long LL;
    #define MOD 1000000007
    LL mpow(LL a, LL n) 
    {LL ret=1;LL b=a;while(n) {if(n&1) 
        ret=(ret*b)%MOD;b=(b*b)%MOD;n>>=1;}
    return (LL)ret;}
    VI ar[100005]={};
    int flag[100005]={};
    int bfs(int node)
    {
        queue < int > myq;
        myq.push(node);
        flag[node]=1;
        int p,cnt=0;
        while(!myq.empty())
        {
            p=myq.front();
            cnt++;
            myq.pop();
            for(int i=0; i<ar[p].size(); i++)
                if(flag[ar[p][i]]==0)flag[ar[p][i]]=1,myq.push(ar[p][i]);
        }
        return cnt;
    }
    int main()
    {
        int n,i,j,u,v;
        VI arr;
        string s;
        cin >> n;
        assn(n,1,100000);
        for(i=1; i<n; i++)
        {
            cin >> u >> v >> s;
            u--,v--;
            if(s[0]!='r')ar[u].pb(v),ar[v].pb(u);
        }
        for(i=0; i<n; i++)
            if(flag[i]==0)arr.pb(bfs(i));
        LL ans=0,sum=0;
        n=arr.size();
        for(i=0; i<n; i++)
            ans+=arr[i];
        sum=ans;
        ans=(ans*ans*ans)%MOD;
        for(i=0; i<n; i++)
        {
            ans-=(arr[i]*arr[i]*arr[i])%MOD;
            if(ans<0)ans+=MOD;
        }
        for(i=0; i<n; i++)
        {
            ans-=(3*arr[i]*arr[i]*(sum-arr[i]))%MOD;
            if(ans<0)ans+=MOD;
        }
        cout << (ans*mpow(6,MOD-2))%MOD << endl;
        return 0;
    }