#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 200000


struct Info{
	bool operator<(const struct Info &arg) const{
		return cost < arg.cost;
	}
	ll from,to,cost;
};

Info info[NUM];
int N;
ll boss[NUM],height[NUM],member_num[NUM];

int get_boss(int id){
	if(boss[id] == id)return id;
	else{
		return boss[id] = get_boss(boss[id]);
	}
}

int is_same(int x,int y){
	return get_boss(x) == get_boss(y);
}

void unite(int x,int y){
	int boss_x = get_boss(x);
	int boss_y = get_boss(y);

	if(boss_x == boss_y)return;

	if(height[x] > height[y]){

		boss[boss_y] = boss_x;
		member_num[boss_x] += member_num[boss_y];

	}else if(height[x] < height[y]){

		boss[boss_x] = boss_y;
		member_num[boss_y] += member_num[boss_x];

	}else{ //height[x] == height[y]

		boss[boss_y] = boss_x;
		member_num[boss_x] += member_num[boss_y];
		height[x]++;
	}
}

int main(){

	scanf("%d",&N);

	for(int i = 0; i < N-1; i++){
		scanf("%lld %lld %lld",&info[i].from,&info[i].to,&info[i].cost);
	}

	sort(info,info+N-1);

	for(int i = 0; i < N; i++){
		boss[i] = i;
		height[i] = 0;
		member_num[i] = 1;
	}

	ll ans = 0;

	for(int i = 0; i < N-1; i++){
		ans += member_num[get_boss(info[i].from)]*member_num[get_boss(info[i].to)]*info[i].cost;
		unite(info[i].from,info[i].to);
	}

	printf("%lld\n",ans);

	return 0;
}