#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void chkmax(T& x, U y) {
  if (x < y) x = y;
}
template <typename T, typename U>
inline void chkmin(T& x, U y) {
  if (y < x) x = y;
}
const int MOD = 1e9 + 7;
const int MAXN = 111111;
vector<pair<int, int> > adj[MAXN];
int A[MAXN], B[MAXN];
int modExp(int a, int n, int p) {
  int ret = 1;
  for (; n; n >>= 1, a = (long long)a * a % p)
    if (n & 1) ret = (long long)ret * a % p;
  return ret;
}
void dfs(int u, int p) {
  int chd = 0;
  for (int i = 0; i < ((int)(adj[u].size())); i++) {
    int v = adj[u][i].first, w = adj[u][i].second;
    B[u] = (B[u] + w) % MOD;
    if (v == p) continue;
    chd++;
    dfs(v, u);
    A[u] = (A[u] + A[v]) % MOD, B[u] = (B[u] + B[v]) % MOD;
  }
  if (chd == 0) {
    A[u] = B[u] = 0;
    return;
  }
  int cur = (((int)(adj[u].size())) + MOD - A[u]) % MOD;
  A[u] = modExp(cur, MOD - 2, MOD);
  B[u] = (long long)A[u] * B[u] % MOD;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    adj[u].push_back(pair<int, int>(v, w));
    adj[v].push_back(pair<int, int>(u, w));
  }
  dfs(0, -1);
  cout << B[0] << endl;
  return 0;
}
