#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};



int main() {
	int N;cin>>N;
	vector<pair<unsigned long long int, pair<int, int>>>edges;
	for (int i = 0; i < N - 1; ++i) {
		int a,b,c;cin>>a>>b>>c;
		pair<unsigned long long int,pair<int,int>> edge(make_pair(c,make_pair(a,b)));
		edges.push_back(edge);
	}
	sort(edges.begin(),edges.end());
	UnionFind uf(N);
	unsigned long long int ans=0;
	for (auto edge : edges) {
		int a=edge.second.first;
		int b=edge.second.second;
		unsigned long long int c=edge.first;
		ans+=c*uf.size(a)*uf.size(b);
		uf.unionSet(a,b);
	}
	cout<<ans<<endl;
	return 0;
}