#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, tot, d[100005], hd[100005], to[200005], nxt[200005], w[200005];
int read() {
  int x = 0, fl = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') fl = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10ll + ch - '0';
    ch = getchar();
  }
  return x * fl;
}
void add(int x, int y, int z) {
  tot++;
  to[tot] = y;
  nxt[tot] = hd[x];
  w[tot] = z;
  hd[x] = tot;
  return;
}
int qpow(int base, int pw) {
  int s = 1;
  while (pw) {
    if (pw & 1) s = 1ll * s * base % mod;
    base = 1ll * base * base % mod;
    pw >>= 1;
  }
  return s;
}
pair<int, int> dfs(int x, int fa, int p) {
  if (d[x] == 1) return make_pair(0, 0);
  int k = 0, b = 0, o = 0;
  for (int i = hd[x]; i; i = nxt[i]) {
    int y = to[i], z = w[i];
    if (y == fa) continue;
    pair<int, int> tmp = dfs(y, x, z);
    k = (k + tmp.first) % mod, b = (b + tmp.second) % mod, o = (o + z) % mod;
  }
  return make_pair(
      qpow((d[x] - k + mod) % mod, mod - 2),
      1ll * qpow((d[x] - k + mod) % mod, mod - 2) * (o + b + p) % mod);
}
int main() {
  n = read();
  for (int i = 1; i <= n - 1; i++) {
    int x = read() + 1, y = read() + 1, z = read();
    add(x, y, z), add(y, x, z);
    d[x]++, d[y]++;
  }
  printf("%d\n", dfs(1, 0, 0).second);
  return 0;
}
