#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<queue>
#include<stack>
#include<utility>
#include<cstdlib>
#include<cstdio>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<list>
#include<tuple>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
 
#define FOR(i, a, b) for(ll i=(a); i<(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n+1)
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
struct IOSetup{
	IOSetup(){
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout<<fixed<<setprecision(12);
	}
} iosetup;
 
struct Edge{
    ll to, cost;
    Edge(ll t, ll c) : to(t), cost(c) { }
};
using Graph = vector<vector<Edge>>;
 
ll MODpow(ll x, ll n, ll mod){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n >>= 1;
	}
	return res;
}
 
const ll MOD=1e9+7;
const ll nmax=200000+10;

ll N;
Graph G(nmax);
 
ll solve(){
	vvl color(nmax,vl(60,-1));
	vl cnt1(60,0);
	vl seen(nmax,0);
    queue<ll> q;
    q.push(0);
	REP(i,60) color[0][i]=0;
    
    while(!q.empty()){
        ll v=q.front();
        q.pop();
        seen[v]=1;
        
        for(auto e:G[v]){
            if(seen[e.to]) continue;
            
			ll et=e.to, ec=e.cost;
			q.push(e.to);
			REP(i,60){
				bool eci=ec&1;
				ec>>=1;
				color[et][i]=color[v][i]^eci;
				if(color[et][i]) cnt1[i]++;
			}
        }
    }
	
	ll res=0,rec=1;
	REP(i,60){
		ll mid1=rec;
		rec=rec*2%MOD;
		ll mid2=(N-cnt1[i])*cnt1[i]%MOD;
		ll mid=mid1*mid2%MOD;
		res+=mid;
		res%=MOD;
	}
    
    return res;
}
 
int main(void){
	scanf(" %ld",&N);
    REP(i,N-1){
        ll u,v,w; scanf(" %ld%ld%ld",&u,&v,&w);
        u--,v--;
        G[u].push_back(Edge{v,w});
        G[v].push_back(Edge{u,w});
    }
    
    ll res=solve();
    printf("%ld\n",res);
    
    return 0;
}
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <utility>
#include <sstream>
#include <algorithm>
#include <numeric>

int read_int()
{    
    std::string s;
    std::getline(std::cin, s);
    return std::stoi(s);
}

std::pair<int,int> read_int_pair() 
{    
    std::string s;
    std::getline(std::cin, s);
    size_t pos = s.find_first_of(" \t");
    if (pos == std::string::npos) {
        throw std::invalid_argument("Not found space delimiter to parse pair of ints");
    }
    int fst = std::stoi(s.substr(0, pos));
    while (++pos < s.length() && 
            (s[pos] == ' ' || s[pos] == '\t')) { }
    if (pos == s.length()) {
        throw std::invalid_argument("Not found string part 2 to parse pair of ints");
    }
    int snd = std::stoi(s.substr(pos));
    return {fst, snd};
}


bool have_colinear_3(const std::vector<std::pair<int,int>>& points)
{
    const size_t len = points.size();
    for (size_t i = 0; i < len - 2; i++) {
        for (size_t j = i + 1; j < len - 1; j++) {
            for (size_t k = j + 1; k < len; k++) {
                std::vector<std::pair<int,int>> tri { points[i], points[j], points[k] };
                std::sort(tri.begin(), tri.end(), 
                    [](std::pair<int,int>& a, std::pair<int,int>& b){
                        return a.first < b.first; });

                int x0 = tri[0].first;
                int x1 = tri[1].first;
                int x2 = tri[2].first;
                int y0 = tri[0].second;
                int y1 = tri[1].second;
                int y2 = tri[2].second;

                if (x0 == x1 && x1 == x2) {
                    return true;

                } else if (y0 == y1 && y1 == y2) {
                    return true;

                } else if (x0 != x1 && x1 != x2 && y0 != y1 && y1 != y2) {
                    // if (y1 > y0 && y2 > y1) {
                        int a = x1 - x0;
                        int b = y1 - y0;
                        int A = x2 - x0;
                        int B = y2 - y0;

                        if (b * A == B * a) {
                            return true;
                        }
                    // }
                }
                
            }
        }
    }
    return false;
}

int main() 
{  
    const int n = read_int();
    
    std::vector<std::pair<int,int>> points;
    for (int i = 0; i < n; i++) {
        auto point = read_int_pair();
        points.push_back(point);        
    }

    auto answ = have_colinear_3(points) ? "Yes" : "No";
    std::cout << answ << std::endl;

    return 0;
}
