#include <bits/stdc++.h>
using namespace std;
int n, len, hea[1000000], nex[1000000], wen[1000000], val[1000000];
const long long mod = 1000000007;
long long k[1000000], b[1000000];
long long kp(long long a, long long b) {
  long long c = 1;
  while (b) {
    if (b & 1) c = (c * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return c;
}
void add(int x, int y, int z) {
  ++len;
  nex[len] = hea[x];
  wen[len] = y;
  val[len] = z;
  hea[x] = len;
}
void dp(int x, int y, long long v) {
  long long bo = 0, sumk = 0, sumb = 0;
  for (int i = hea[x]; i; i = nex[i])
    if (wen[i] != y) {
      ++bo;
      dp(wen[i], x, val[i]);
      sumk = (sumk + k[wen[i]]) % mod;
      sumb = (sumb + b[wen[i]] + val[i]) % mod;
    }
  if (bo) {
    k[x] = kp(((bo + (x != 1) - sumk) % mod + mod) % mod, mod - 2);
    b[x] = (v + sumb) % mod * k[x] % mod;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    ++x;
    ++y;
    add(x, y, z);
    add(y, x, z);
  }
  dp(1, 0, 0);
  printf("%lld", b[1]);
}
