#include <bits/stdc++.h>
using namespace std;
int gi() {
  int res = 0, s = 1;
  char ch;
  for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
    ;
  if (ch == '-') s = -1, ch = getchar();
  for (; ch >= '0' && ch <= '9'; ch = getchar()) res = res * 10 + ch - 48;
  return res * s;
}
int n, head[100005], to[100005 << 1], ne[100005 << 1], len[100005 << 1], num,
    du[100005], mk[100005];
long long A[100005], B[100005];
long long inv(long long x) {
  long long y = 1000000007 - 2, res = 1;
  for (; y; y >>= 1, x = x * x % 1000000007)
    if (y & 1) res = res * x % 1000000007;
  return res;
}
void adde(int u, int v, int w) {
  to[++num] = v, ne[num] = head[u], head[u] = num, len[num] = w;
  to[++num] = u, ne[num] = head[v], head[v] = num, len[num] = w;
  du[u]++, du[v]++;
}
void dfs(int p, int f) {
  if (du[p] == 1) {
    A[p] = 0, B[p] = 0;
    return;
  }
  long long ny = inv(du[p]), tmp = 0;
  for (int i = head[p]; i; i = ne[i]) {
    if (to[i] != f)
      dfs(to[i], p), B[p] += B[to[i]] + len[i], tmp += A[to[i]];
    else
      B[p] += len[i];
  }
  B[p] %= 1000000007, tmp %= 1000000007;
  tmp = tmp * ny % 1000000007, B[p] = B[p] * ny % 1000000007, A[p] = ny;
  tmp = (1 - tmp + 1000000007) % 1000000007;
  ny = inv(tmp);
  (A[p] *= ny) %= 1000000007, (B[p] *= ny) %= 1000000007;
}
int main() {
  n = gi();
  for (int i = 1, u, v, w; i < n; ++i)
    u = gi() + 1, v = gi() + 1, w = gi(), adde(u, v, w);
  if (du[1] == 1) {
    printf("0");
    return 0;
  }
  dfs(1, 0);
  printf("%I64d", B[1]);
  return 0;
}
