#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
string s;
ll ans,raod[200];
int main(){
    ios::sync_with_stdio(false);
    cin >> s;
    
    for(int i=(int)s.size() - 1; i>=1; i--){
        if(s[i] == s[i - 1]){
            ans += (int)s.size() - i - 1 - raod[s[i] - 'a'];
            for(int j=0; j<26; j++)
                raod[j] = 0;
            raod[s[i] - 'a'] = (int)s.size() - i;
        }
        else {
            raod[s[i] - 'a']++;
        }
    }
    
    cout << ans << '\n';
    
    
    
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
namespace Flandre_Scarlet
{
    #define N 200005
    #define int long long
    #define mod 1000000007
    #define F(i,l,r) for(int i=l;i<=r;++i)
    #define D(i,r,l) for(int i=r;i>=l;--i)
    #define Fs(i,l,r,c) for(int i=l;i<=r;c)
    #define Ds(i,r,l,c) for(int i=r;i>=l;c)
    #define MEM(x,a) memset(x,a,sizeof(x))
    #define FK(x) MEM(x,0)
    #define Tra(i,u) for(int i=G.st(u),v=G.to(i);~i;i=G.nx(i),v=G.to(i))
    #define p_b push_back
    #define sz(a) ((int)a.size())
    #define all(a) a.begin(),a.end()
    #define iter(a,p) (a.begin()+p)
    int I() {char c=getchar(); int x=0; int f=1; while(c<'0' or c>'9') f=(c=='-')?-1:1,c=getchar(); while(c>='0' and c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return ((f==1)?x:-x);}
    template <typename T> void Rd(T& arg){arg=I();}
    template <typename T,typename...Types> void Rd(T& arg,Types&...args){arg=I(); Rd(args...);}
    void RA(int *p,int n) {F(i,1,n) *p=I(),++p;}
    class Graph
    {
        public:
        struct edge{int v,w,nx;} pe[N<<1]; edge*e;
        int ph[N]; int *head; int ecnt;
        void clear()
        {
            MEM(pe,-1); MEM(ph,-1); e=pe+2; head=ph+2; ecnt=-1;
        }
        void add(int u,int v,int w)
        {
            e[++ecnt]=(edge){v,w,head[u]}; head[u]=ecnt;
        }
        void ad2(int u,int v,int w)
        {
            add(u,v,w),add(v,u,w);
        }
        int&st(int u){return head[u];} int&to(int i){return e[i].v;} int&wei(int i){return e[i].w;} int&nx(int i){return e[i].nx;}
    }G;
    int n;
    void Input()
    {
        n=I(); G.clear();
        F(i,1,n-1)
        {
            int u,v,w; Rd(u,v,w);
            G.ad2(u,v,w);
        }
    }
    int xor_s[N];
    void DFS(int u,int f)
    {
        Tra(i,u) if (v!=f)
        {
            xor_s[v]=xor_s[u]^G.wei(i);
            DFS(v,u);
        }
    }
    int suf[N];
    void Sakuya()
    {
        xor_s[1]=0;
        DFS(1,1);
        int ans=0;
        D(k,60,0)
        {
            int have=0;
            F(i,1,n)
            {
                if ((xor_s[i]>>k)&1) ++have;
            }
            int cur=(have*(n-have))%mod*((1ll<<k)%mod)%mod;
            // C(have,2)*(1<<k)
            ans=(ans+cur)%mod;
        }
        printf("%lld\n",ans);
    }
    void IsMyWife()
    {
        Input();
        Sakuya();
    }
}
#undef int //long long
int main()
{
    Flandre_Scarlet::IsMyWife();
    getchar();
    return 0;
}