#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, mod = 1e9 + 7;
int head[N], nxt[N << 1], to[N << 1], num = 0, n, b[N], fa[N], q[N], DFN = 0,
                                      k[N], in[N];
inline void link(int x, int y) {
  nxt[++num] = head[x];
  to[num] = y;
  head[x] = num;
}
inline int qm(int x, int k) {
  int sum = 1;
  while (k) {
    if (k & 1) sum = 1ll * sum * x % mod;
    x = 1ll * x * x % mod;
    k >>= 1;
  }
  return sum;
}
inline int inv(int x) { return qm(x, mod - 2); }
inline void dfs(int x, int last) {
  q[++DFN] = x;
  for (int i = head[x]; i; i = nxt[i])
    if (to[i] != last) fa[to[i]] = x, dfs(to[i], x);
}
int main() {
  int x, y, z;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &x, &y, &z);
    x++;
    y++;
    link(x, y);
    link(y, x);
    k[x]++;
    k[y]++;
    b[x] += z;
    b[y] += z;
  }
  for (int i = 1; i <= n; i++) in[i] = k[i];
  dfs(1, 1);
  for (int i = n; i >= 1; i--) {
    int x = q[i];
    if (in[x] == 1) continue;
    k[fa[x]] = (k[fa[x]] - inv(k[x])) % mod;
    b[fa[x]] = (b[fa[x]] + 1ll * inv(k[x]) * b[x]) % mod;
  }
  b[1] = 1ll * b[1] * inv(k[1]) % mod;
  if (b[1] < 0) b[1] += mod;
  printf("%d\n", b[1]);
  return 0;
}
