#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, yzh = 1e9 + 7;
int n, k[N], b[N], fa[N], q[N], in[N], tail, u, v, c;
struct tt {
  int to, next;
} edge[N << 1];
int path[N], top;
int quick_pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = 1ll * ans * a % yzh;
    a = 1ll * a * a % yzh, b >>= 1;
  }
  return ans;
}
void dfs(int u) {
  q[++tail] = u;
  for (int i = path[u]; i; i = edge[i].next)
    if (edge[i].to != fa[u]) fa[edge[i].to] = u, dfs(edge[i].to);
}
void add(int u, int v) { edge[++top] = (tt){v, path[u]}, path[u] = top; }
void work() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &u, &v, &c);
    ++u, ++v;
    add(u, v), add(v, u);
    ++k[u], ++k[v], b[u] += c, b[v] += c;
  }
  for (int i = 1; i <= n; i++) in[i] = k[i];
  dfs(1);
  for (int i = n; i >= 1; i--)
    if (in[i] != 1) {
      int inv = quick_pow(k[i], yzh - 2);
      (k[fa[i]] -= inv) %= yzh;
      (b[fa[i]] += 1ll * b[i] * inv % yzh) %= yzh;
    }
  printf("%d\n", (1ll * b[1] * quick_pow(k[1], yzh - 2) % yzh + yzh) % yzh);
}
int main() {
  work();
  return 0;
}
