#include <bits/stdc++.h>
const long long mod = 1000000007;
struct Point {
  long long k, b;
} point[300100];
struct Edge {
  long long to, nxt, weigh;
} edge[600100];
long long head[300100], deg[300100], n, cnt;
void addedge(long long x, long long y, long long z) {
  edge[++cnt].to = y;
  edge[cnt].weigh = z;
  edge[cnt].nxt = head[x];
  head[x] = cnt;
}
long long quickpow(long long x, long long y) {
  long long res = 1;
  for (; y; y >>= 1, x = x * x % mod)
    if (y & 1) res = res * x % mod;
  return res;
}
void dfs(long long x, long long fa, long long pre) {
  long long k = deg[x], b = pre;
  for (long long i = head[x]; i; i = edge[i].nxt) {
    long long upup = edge[i].to, weigh = edge[i].weigh;
    if (upup == fa) continue;
    if (deg[upup] == 1)
      (b += weigh) %= mod;
    else {
      dfs(upup, x, weigh);
      (k += mod - point[upup].k) %= mod;
      (b += point[upup].b + weigh) %= mod;
    }
  }
  long long inv = quickpow(k, mod - 2);
  point[x].k = inv, point[x].b = b * inv % mod;
}
signed main() {
  scanf("%lld", &n);
  for (long long i = 1, x, y, z; i < n; i++) {
    scanf("%lld%lld%lld", &x, &y, &z);
    x++, y++;
    addedge(x, y, z);
    addedge(y, x, z);
    deg[x]++;
    deg[y]++;
  }
  long long x = 0;
  dfs(1, 0, 0);
  printf("%lld\n", point[1].b);
}
