#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int mod = 1000000007;
struct E {
  int to, next, w;
} mem[N << 1];
int T, n, tot, num, w, x, y;
int head[N], cnt[N], kk[N], bb[N], d[N], s[N];
void add(int x, int y, int w) {
  num++;
  mem[num].to = y;
  mem[num].next = head[x];
  mem[num].w = w;
  head[x] = num;
}
int quickpow(int x, int y) {
  int s = 1;
  for (; y; y >>= 1, x = 1ll * x * x % mod)
    if (y & 1) s = 1ll * s * x % mod;
  return s;
}
void dfs(int k, int pre) {
  int j, u, sum = s[k];
  if (d[k] == 1 && k > 1) return;
  for (j = head[k]; j; j = mem[j].next) {
    u = mem[j].to;
    if (u == pre) continue;
    dfs(u, k);
    (sum += bb[u]) %= mod;
    (d[k] -= kk[u]) %= mod;
  }
  kk[k] = quickpow(d[k], mod - 2);
  bb[k] = 1ll * sum * quickpow(d[k], mod - 2) % mod;
}
int main() {
  int i;
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d%d%d", &x, &y, &w);
    x++;
    y++;
    (s[x] += w) %= mod;
    (s[y] += w) %= mod;
    d[x]++;
    d[y]++;
    add(x, y, w);
    add(y, x, w);
  }
  dfs(1, 0);
  printf("%d\n", (bb[1] % mod + mod) % mod);
  return 0;
}
