#pragma GCC optimize("Ofast")
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Erep(i,n) for(int i = 0; i <= (n); ++i)
#define repS(i,s,n) for(int i = s; i < (n); ++i)
#define ErepS(i,s,n) for(int i = s; i <= (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define RSort(a) sort(a.rbegin(), a.rend())
#define Output(a) printf("%lld %s", a, "\n")
 
typedef long long int ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vst;
typedef vector<double> vd;

const ll INF = 0x1fffffffffffffff;
const ll MOD = 1000000007;
const double PI = acos(-1);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
ll n;
vd a, b, c, d;

void input(){
    cin >> n;
    a = vd(n);
    b = vd(n);
    c = vd(n);
    d = vd(n);
    rep(i, n) cin >> a[i] >> b[i];
    rep(i, n) cin >> c[i] >> d[i];
}

void solve(){
    string ans = "No";
    vd x(n), y(n);
    for(int k = 0; k < 360; k++){
        rep(i, n){
            double tx = a[i], ty = b[i];
            x[i] = tx * cos((k * PI ) / 180) - ty * sin((k * PI ) / 180);
            y[i] = tx * sin((k * PI ) / 180) + ty * cos((k * PI ) / 180);
        }
        double ave_s_x = 0, ave_s_y = 0, ave_t_x = 0, ave_t_y = 0;
        rep(i, n){
            ave_s_x += x[i];
            ave_s_y += y[i];
            ave_t_x += c[i];
            ave_t_y += d[i];
        }
        double diff_x = (ave_t_x - ave_s_x) / n;
        double diff_y = (ave_t_y - ave_s_y) / n;
        ll check = 1;
        rep(i, n){
            ll count = 0;
            rep(j, n){
                double ex = x[i] + diff_x, ey = y[i] + diff_y;
                //if(k == 90)
                //cout << ex << " " << c[j] << " " << ey << " " << d[j] << "\n";
                if(abs(ex - c[j]) <= (double) 0.05 && abs(ey - d[j]) <= (double) 0.05){
                  //cout << k << endl;
                  //cout << x[i] << " " << c[j] << " " << y[i] << " " << d[j] << "\n";
                    count++;
                }
            }
            if(count == 0){
                check = 0;
            }
        }
        if(check){
            ans = "Yes";
            break;
        }
    }
    cout << ans << endl;
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    input();
    solve();
}
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 400010, mod = 1e9 + 7;

int e[N], ne[N], h[N], idx, w[N][61], n;
ll tar, d[N][2], res;

void add(int a, int b, long long c) {
	e[idx] = b, ne[idx] = h[a];
	for (int i = 0; i < 60; ++i) {
		if (c & 1) w[idx][i] = 1;
		c /= 2;
		if (!c) break;
	}
	h[a] = idx++;
}

void go(int x, int fa) {
	d[x][0] = d[x][1] = 0;
	for (int i = h[x]; i != -1; i = ne[i]) {
		if (fa == e[i]) continue;
		go(e[i], x);
		if (w[i][tar]) {
			d[x][0] += d[e[i]][1];
			d[x][1] += d[e[i]][0] + 1;
		} else {
			d[x][0] += d[e[i]][0] + 1;
			d[x][1] += d[e[i]][1];
		}
	}	
	res += d[x][1];
	ll t = 0;
	for (int i = h[x]; i != -1; i = ne[i]) {
		if (fa == e[i]) continue;
		if (w[i][tar]) {
			res += (d[e[i]][0] + 1) * (d[x][0] - d[e[i]][1]);
		} else {
			res += d[e[i]][1] * (d[x][0] - d[e[i]][0] - 1); 
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	memset(h, -1, sizeof h);
	for (int i = 1; i < n; ++i) {
		int a, b;
		ll w;
		cin >> a >> b >> w;
		add(a, b, w);
		add(b, a, w);
	}
	ll ans = 0;
	for (int i = 0; i < 60; ++i) {
		tar = i;
		res = 0;
		go(1, -1);
		ans = (ans + res % mod * ((1ll << i) % mod) % mod) % mod;
	}
	cout << ans << '\n';
	return 0;
}
