#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int f = 1, x = 0;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1LL;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f * x;
}
template <class T>
inline void chmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void chmin(T &a, T b) {
  if (a > b) a = b;
}
inline void swap(int &a, int &b) {
  int c = a;
  a = b;
  b = c;
}
using namespace std;
using namespace std;
const int N = 1e5 + 10;
const int P = 1e9 + 7;
inline long long qpow(long long a, long long b) {
  long long q = 1;
  while (b) {
    if (b & 1) q = q * a % P;
    a = a * a % P;
    b >>= 1;
  }
  return q;
}
inline long long inv(long long x) { return qpow(x, P - 2); }
struct node {
  int next, to, w;
} e[N << 1];
int head[N], cnt;
inline void add(int u, int v, int w) {
  e[cnt].w = w;
  e[cnt].to = v;
  e[cnt].next = head[u];
  head[u] = cnt++;
}
long long f[N], g[N];
inline void dfs(int x, int fa) {
  int fl = 0;
  for (int i = head[x]; ~i; i = e[i].next) {
    int v = e[i].to;
    ++g[x];
    f[x] += e[i].w;
    if (f[x] >= P) f[x] -= P;
    if (v == fa) continue;
    fl = 1;
    dfs(v, x);
    f[x] += f[v];
    if (f[x] >= P) f[x] -= P;
    g[x] -= g[v];
    if (g[x] < 0) g[x] += P;
  }
  if (!fl) {
    f[x] = g[x] = 0;
    return;
  }
  g[x] = inv(g[x]);
  f[x] = f[x] * g[x] % P;
}
int n;
int main() {
  memset(head, -1, sizeof(head));
  n = read();
  for (int i = (1); i <= (n - 1); ++i) {
    int u = read(), v = read(), w = read();
    add(u, v, w);
    add(v, u, w);
  }
  dfs(0, -1);
  printf("%lld\n", f[0]);
  return 0;
}
