#include <bits/stdc++.h>
using namespace std;
struct E {
  int to, w;
};
const int N = 1e5 + 5, MOD = 1e9 + 7;
vector<E> g[N];
long long val[N], kf[N];
int n;
long long bp(long long a, long long p) {
  long long r = 1;
  while (p > 0) {
    if (p & 1) {
      r = r * a % MOD;
    }
    a = a * a % MOD;
    p >>= 1;
  }
  return r;
}
void dfs(int node, int anc) {
  if (g[node].size() == 1 && anc != -1) {
    return;
  }
  kf[node] = g[node].size();
  for (E e : g[node]) {
    if (e.to != anc) {
      dfs(e.to, node);
      kf[node] = (kf[node] - kf[e.to] + MOD) % MOD;
      val[node] = (val[node] + val[e.to]) % MOD;
    }
    val[node] = (val[node] + e.w) % MOD;
  }
  kf[node] = bp(kf[node], MOD - 2);
  val[node] = val[node] * kf[node] % MOD;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }
  dfs(0, -1);
  cout << val[0];
  return 0;
}
