#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const int MOD = 1e9 + 7;
inline int add(int a, int b) { return (a += b) >= MOD ? a - MOD : a; }
inline int sub(int a, int b) { return (a -= b) < 0 ? a + MOD : a; }
inline int mul(int a, int b) { return 1ll * a * b % MOD; }
inline int pw(int x, int p) {
  int res = 1;
  for (; p; p >>= 1, x = mul(x, x))
    if (p & 1) res = mul(res, x);
  return res;
}
inline int inv(int x) { return pw(x, MOD - 2); }
int n;
struct edge {
  int ne, to, w;
  edge(int N = 0, int T = 0, int W = 0) : ne(N), to(T), w(W) {}
} e[MAXN << 1];
int fir[MAXN], num = 0;
inline void join(int a, int b, int c) {
  e[++num] = edge(fir[a], b, c);
  fir[a] = num;
}
struct node {
  int k, b;
} f[MAXN];
void dfs(int u, int fa) {
  int K = 0, B = 0, S = 0, D = 0;
  for (int i = fir[u]; i; i = e[i].ne) {
    S = add(S, e[i].w);
    ++D;
    int v = e[i].to;
    if (v == fa) continue;
    dfs(v, u);
    K = add(K, f[v].k);
    B = add(B, f[v].b);
  }
  if (D == 1)
    f[u].k = f[u].b = 0;
  else {
    int p = sub(D, K);
    f[u].k = inv(p);
    f[u].b = mul(add(B, S), inv(p));
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    ++u;
    ++v;
    join(u, v, w);
    join(v, u, w);
  }
  dfs(1, 0);
  printf("%d\n", f[1].b);
  return 0;
}
