Problem: There is a tree with N vertices numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i.

Initially, each edge is painted blue. Takahashi will convert this blue tree into a red tree, by performing the following operation N-1 times:

* Select a simple path that consists of only blue edges, and remove one of those edges.
* Then, span a new red edge between the two endpoints of the selected path.



His objective is to obtain a tree that has a red edge connecting vertices c_i and d_i, for each i.

Determine whether this is achievable.

Constraints

* 2 ≤ N ≤ 10^5
* 1 ≤ a_i,b_i,c_i,d_i ≤ N
* a_i ≠ b_i
* c_i ≠ d_i
* Both input graphs are trees.

Input

Input is given from Standard Input in the following format:


N
a_1 b_1
:
a_{N-1} b_{N-1}
c_1 d_1
:
c_{N-1} d_{N-1}


Output

Print `YES` if the objective is achievable; print `NO` otherwise.

Examples

Input

3
1 2
2 3
1 3
3 2


Output

YES


Input

5
1 2
2 3
3 4
4 5
3 4
2 4
1 4
1 5


Output

YES


Input

6
1 2
3 5
4 6
1 6
5 1
5 3
1 4
2 6
4 3
5 6


Output

NO

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
const int N=1e5+10;
typedef pair<int,int> pii;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,fa[N];
set<int> E[N];
map<pii,int> cnt;
queue<pii> q;
int getf(int x) { return x==fa[x]?x:fa[x]=getf(fa[x]); }
void adde(int u,int v) {
    if(u>v) swap(u,v);
    E[u].insert(v);E[v].insert(u);
    if(++cnt[mp(u,v)]==2) q.push(mp(u,v));
}
int main() {
    cin>>n;
    for(int i=1,u,v;i<=2*n-2;i++) u=gi(),v=gi(),adde(u,v);
    for(int i=1;i<=n;i++) fa[i]=i;
    for(int i=1,x,y;i<n;i++) {
        while(1) {
            if(q.empty()) return puts("NO"),0;
            x=q.front().first;y=q.front().second;q.pop();
            x=getf(x);y=getf(y);
            if(x!=y) break;
        }
        if(E[x].size()>E[y].size()) swap(x,y);
        fa[x]=y;E[y].erase(x);E[x].erase(y);cnt.erase(mp(min(x,y),max(x,y)));
        for(int v:E[x]) {
            v=getf(v);cnt[mp(min(x,v),max(x,v))]--;
            if(v==y) continue;
            adde(v,y);E[v].erase(x);
        }
    }
    puts("YES");
    return 0;
}
//orzgzy
//鸡贼明年进队超稳