#include <bits/stdc++.h>
const int N = 100005, mu = 1000000007;
void reduce(int &x) { x += x >> 31 & mu; }
int to[N << 1], edge, Next[N << 1], last[N], w[N << 1], f[N], b[N], n, x, y, z;
void add(int x, int y, int z) {
  to[++edge] = y;
  Next[edge] = last[x];
  last[x] = edge;
  w[edge] = z;
}
int ksm(int x, int y) {
  x = x % mu;
  int ans = 1;
  for (; y; y >>= 1, x = x * 1ll * x % mu)
    if (y & 1) ans = ans * 1ll * x % mu;
  return ans;
}
void dfs(int x, int fa) {
  int d = 0, sumx = 0;
  for (int i = last[x]; i; i = Next[i]) {
    int u = to[i];
    d++;
    if (u == fa) continue;
    b[u] = w[i];
    dfs(u, x);
    reduce(sumx += f[u] - mu);
    reduce(b[x] += b[u] - mu), reduce(b[x] += w[i] - mu);
  }
  if (d == 1) {
    b[x] = 0;
    return;
  }
  f[x] = ksm(d - sumx + mu, mu - 2);
  b[x] = 1ll * b[x] * f[x] % mu;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &x, &y, &z);
    x++, y++;
    add(x, y, z), add(y, x, z);
  }
  dfs(1, 0);
  printf("%d\n", b[1]);
}
