#include <bits/stdc++.h>
using namespace std;
inline int readInt() {
  static int n, ch;
  n = 0, ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) n = n * 10 + ch - '0', ch = getchar();
  return n;
}
const int MAX_N = 100000 + 3, MOD = 1e9 + 7;
struct Edge {
  Edge *next;
  int to, cost;
  Edge(Edge *next = NULL, int to = 0, int cost = 0)
      : next(next), to(to), cost(cost) {}
} pool[MAX_N * 2], *pit = pool, *first[MAX_N];
int n, d[MAX_N], a[MAX_N], b[MAX_N];
inline int modPow(long long a, int b) {
  long long res = 1;
  while (b) {
    if (b & 1) (res *= a) %= MOD;
    (a *= a) %= MOD;
    b >>= 1;
  }
  return res;
}
void dfs(int u, int fa) {
  a[u] = b[u] = 0;
  if (d[u] == 1) return;
  int t = d[u];
  for (Edge *e = first[u]; e; e = e->next)
    if (e->to != fa) {
      dfs(e->to, u);
      (b[u] += e->cost + b[e->to]) %= MOD;
      (t -= a[e->to]) %= MOD;
    } else
      (b[u] += e->cost) %= MOD;
  int inv = modPow((t + MOD) % MOD, MOD - 2);
  a[u] = inv, b[u] = (long long)b[u] * inv % MOD;
}
int main() {
  n = readInt();
  for (int i = 0; i < n - 1; ++i) {
    int u = readInt(), v = readInt(), w = readInt();
    first[u] = new (pit++) Edge(first[u], v, w);
    first[v] = new (pit++) Edge(first[v], u, w);
    d[u]++, d[v]++;
  }
  dfs(0, -1);
  printf("%d\n", b[0]);
  return 0;
}
