#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, hgs = 1e9 + 7;
int k[N], n, b[N];
vector<int> v[N], edge[N];
void add(int x, int y, int z) {
  v[x].push_back(y);
  edge[x].push_back(z);
}
void upd(int &x, int y) { x = (x + y) % hgs; }
int qpow(int A, int B) {
  int C = 1;
  for (; B; B >>= 1, A = 1ll * A * A % hgs)
    if (B & 1) C = 1ll * A * C % hgs;
  return C;
}
int inv(int x) { return qpow(x, hgs - 2); }
void dfs(int x, int fa) {
  int l = v[x].size(), y, z;
  if (l == 1) return;
  int sk = 0, sb = 0, out = 0;
  for (register int i = (0); i <= (l - 1); ++i) {
    y = v[x][i];
    z = edge[x][i];
    upd(out, z);
    if (y == fa) continue;
    dfs(y, x);
    upd(sk, k[y]);
    upd(sb, b[y]);
  }
  k[x] = inv((l - sk + hgs) % hgs);
  b[x] = 1ll * (sb + out) * inv((l - sk + hgs) % hgs) % hgs;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  int x, y, z;
  for (register int i = (1); i <= (n - 1); ++i) {
    cin >> x >> y >> z;
    x++;
    y++;
    add(x, y, z);
    add(y, x, z);
  }
  dfs(1, 0);
  cout << b[1] << '\n';
  return 0;
}
