#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define int long long
typedef long long ll;
using namespace std;

int cel(int, int);
int flr(int a, int b) {
    if(a < 0 && b < 0 || b < 0) {
        return flr(-a, -b);
    } else if(a < 0) {
        return -cel(-a, b);
    }
    return a / b;
}
int cel(int a, int b) {
    if(a < 0 && b < 0 || b < 0) {
        return cel(-a, -b);
    } else if(a < 0) {
        return -flr(-a, b);
    }
    return (a + b - 1) / b;
}

const int X = 111111, M = 10000;

int solve() {
    double xd, yd, rd;
    cin >> xd >> yd >> rd;
    int cx = round(xd * M), cy = round(yd * M), r = round(rd * M);
    int ans = 0;
    rep(i, -X, X) {
        int dx = M * i;
        int x = cx / M * M + dx;
        dx = x - cx;
        int lo = 0, hi = X * M;
        while(lo < hi) {
            int mid = lo + (hi - lo + 1) / 2;
            int dist = dx * dx + mid * mid;
            if(dist > r * r) {
                hi = mid - 1;
            } else {
                lo = mid;
            }
        }
        if(dx * dx + lo * lo > r * r) continue;
        int y1 = cel(cy - lo, M);
        int y2 = flr(cy + lo, M);
        int add = y2 - y1 + 1;
        ans += add;
    }
    cout << ans << endl;
    return 0;
}
 
signed main() {
    srand(time(NULL));
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    while(t--) {
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<(a)<<endl
#define dumparr(a,n) cerr<<#a<<"["<<(n)<<"]="<<(a[n])<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< "]";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,set<T> a){
  os << "{ ";
  for(auto itr=a.begin();itr!=a.end();++itr){
    os<< *itr << " ";
  }
  os<< "}";
  return os;
}
template<class T>
void ans_array(T begin,T end){
  auto itr=begin;
  cout<<*itr;
  ++itr;
  for(;itr!=end;++itr){
    cout<<' '<<*itr;
  }
  cout<<endl;
}
template<class T>
void ans_array_newline(T begin,T end){
  for(auto itr=begin;itr!=end;++itr){
    cout<<*itr<<endl;
  }
}

const long long MOD = 1000000007;

void solve(long long N, std::vector<long long> u, std::vector<long long> v, std::vector<long long> w){
  vector<vector<pll>> graph(N);
  REP(N-1){
    graph[u[i]].push_back(pll(v[i],w[i]));
    graph[v[i]].push_back(pll(u[i],w[i]));
  }
  ll ans=0;
  For(numidx,62){
    ll mask=(1LL<<numidx);
    dump(mask);
    auto dfs1=[&](ll cur,ll parent,auto dfs)->pll{
      pll curstatus(1,0);
      for (auto &&i : graph[cur])
      {
        if(i.first==parent)continue;
        pll tmp=dfs(i.first,cur,dfs);
        if((i.second)&mask){
          curstatus.first+=tmp.second;
          curstatus.second+=tmp.first;
        }else{
          curstatus.first+=tmp.first;
          curstatus.second+=tmp.second;
        }
      };
      return curstatus;
    };
    auto res=dfs1(0,-1,dfs1);
    dump(res);
    auto dfs2=[&](ll cur,ll parent,ll curstatus,auto dfs)->ll{
      ll ret=(curstatus?res.first:res.second);
      for (auto &&i : graph[cur])
      {
        if(i.first==parent)continue;
        if(mask&i.second){
          ret+=dfs(i.first,cur,curstatus^1,dfs);
        }else{
          ret+=dfs(i.first,cur,curstatus,dfs);
        }
      }
      return ret;
    };
    ll tmp=dfs2(0,-1,0,dfs2)%MOD;
    dump(tmp);
    ans+=mask%MOD*tmp%MOD;
    ans%=MOD;
    dump(ans);
  }
  cout<<ans*((MOD+1)/2)%MOD<<endl;
}

int main(){
  cout<<setprecision(1000);
  long long N;
    scanf("%lld",&N);
    std::vector<long long> u(N-1);
    std::vector<long long> v(N-1);
    std::vector<long long> w(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&u[i]);
        scanf("%lld",&v[i]);
        scanf("%lld",&w[i]);
        --u[i];--v[i];
    }
  solve(N, std::move(u), std::move(v), std::move(w));
  return 0;
}
