#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long s = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') f *= c == '-' ? -1 : 1, c = getchar();
  while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
  return s * f;
}
inline bool cmin(long long &a, long long b) { return a > b ? a = b, 1 : 0; }
inline bool cmax(long long &a, long long b) { return a < b ? a = b, 1 : 0; }
const long long P = 1e9 + 7;
class modll {
  long long v;

 public:
  modll() : v(0) {}
  modll(long long v) : v(v) {}
  inline operator long long() { return v; }
  inline modll Pow(long long x) const {
    modll ret = 1, a = v;
    for (; x; a *= a, x >>= 1)
      if (x & 1) ret *= a;
    return ret;
  }
  inline modll Inv() const { return Pow(P - 2); }
  inline modll operator+(const modll &r) const {
    return v + r.v >= P ? v + r.v - P : v + r.v;
  }
  inline modll &operator+=(const modll &r) {
    return (v += r.v) >= P ? v -= P : v, *this;
  }
  inline modll operator-(const modll &r) const {
    return v - r.v < 0 ? v - r.v + P : v - r.v;
  }
  inline modll &operator-=(const modll &r) {
    return (v -= r.v) < 0 ? v += P : v, *this;
  }
  inline modll operator*(const modll &r) const { return v * r.v % P; }
  inline modll &operator*=(const modll &r) { return *this = *this * r; }
  inline modll operator/(const modll &r) const { return *this * r.Inv(); }
  inline modll &operator/=(const modll &r) { return *this = *this / r; }
  inline friend ostream &operator<<(ostream &out, modll x) {
    return out << x.v;
  }
};
struct Edge {
  int to;
  modll val;
};
vector<Edge> G[100005];
modll deg[100005];
bool vis[100005];
void dfs(int u, modll parw, modll &k, modll &b) {
  vis[u] = 1;
  if (u && deg[u] == 1) return;
  modll K = 0, B = 0;
  for (auto e : G[u])
    if (!vis[e.to]) dfs(e.to, e.val, K, B), B += e.val;
  k += modll(1) / (deg[u] - K), b += (B + parw) / (deg[u] - K);
}
int main() {
  int n = read();
  for (int i = (1), __i = (n); i < __i; ++i) {
    int u = read(), v = read();
    modll w = read();
    G[u].push_back({v, w}), deg[u] += 1;
    G[v].push_back({u, w}), deg[v] += 1;
  }
  modll k = 0, b = 0;
  dfs(0, 0, k, b);
  cout << b << endl;
  return 0;
}
