#include <bits/stdc++.h>
#define N 200001
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
vector <P> G[N];
ll n;
ll par[N];
ll Rank[N];
ll Cnt[N];

void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    Rank[i]=0;
    Cnt[i]=1;
  }
}

ll find(int x){
  if(par[x]==x)return x;
  return par[x]=find(par[x]);
}

void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(Rank[x]<Rank[y]){
    par[x]=y;
    Cnt[y]+=Cnt[x];
    Cnt[x]=0;
  }
  else{ 
    par[y]=x;
    Cnt[x]+=Cnt[y];
    Cnt[y]=0;
    if(Rank[x]==Rank[y])Rank[x]++;
  }
}

bool same(int x,int y){return find(x)==find(y);}

vector<PP> path;

ll solve(){
  ll res=0;
  for(int i=0;i<n;i++)
    for(int j=0;j<G[i].size();j++) 
      path.push_back(PP(G[i][j].f,P(i,G[i][j].s)));

  sort(path.begin(),path.end());
  for(int i=0;i<path.size();i++){
    int a=path[i].s.f;
    int b=path[i].s.s;
    int c=path[i].f;
    if(same(a,b))continue;
    res+=(Cnt[find(a)]*Cnt[find(b)])*c;
    unite(a,b);
  }
  return res;
}


int main(){
  init(N);
  cin>>n;
  for(int i=1,a,b,c;i<n;i++){
    cin>>a>>b>>c;
    G[a].push_back(P(c,b));
    G[b].push_back(P(c,a));
  }
  cout <<solve()<<endl;
  return 0;
}