#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
typedef vector<iii> viii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000

vi adj[200005];
vi bb;
vi cc;
bool vis[200005];
int n;
ii rng[200005];
int a[200005];
int s[200005];
int ds[200005];
int f[200005];

int rangeMin(int a, int b) {
    if (a == b) {
        return bb[a];
    }
    a += n;
    b += n;
    int sm = 1000000000;
    while (a <= b) {
        if (a % 2 == 1) {
            sm = min(sm, s[a]);
            a++;
        }
        if (b % 2 == 0) {
            sm = min(sm, s[b]);
            b--;
        }
        a /= 2;
        b /= 2;
    }
    return sm;
}

void dfs(int n, int d) {

    vis[n] = true;
    ds[n] = d;
    bb.push_back(ds[n]);
    cc.push_back(n);
    bool f = false;
    for (int a : adj[n]) {
        if (vis[a]) {
            continue;
        }
        f = true;
        dfs(a, d + 1);
        bb.push_back(ds[n]);
        cc.push_back(n);
    }
    //if (f) {
        //bb.push_back(n);
    //}
}

int dst(int a, int b) {
    int x = f[a];
    int y = f[b];
    int ans;
    if (x <= y) {
        ans = rangeMin(f[a], f[b]);
    }
    else {
        ans = rangeMin(f[b], f[a]);
    }

    return ds[a] + ds[b] - ans * 2;
}

void solve() {
    memset(vis, false, sizeof vis);
    cin >> n;
    rep(i, n - 1) {
        int aa, bbb;
        cin >> aa >> bbb;
        aa--; bbb--;
        adj[aa].pb(bbb);
        adj[bbb].pb(aa);
    }

    dfs(0, 0);
    n = 0;
    for (int i = cc.size() - 1 ; i >= 0 ; i--) {
        a[i] = bb[i];
        f[cc[i]] = i;
        n++;
    }

    int ct = 0;
    int mx = 0;
    for (int i = 0 ; i <= 60 ; i++) {
        if ((((ll)1) << i) & n) {
            mx = i;
            ct++;
        }
    }
    int nm = (((ll)1) << mx);
    if (ct > 1) {
        nm = (((ll)1) << (mx+1));
    }
    while (n < nm) {
        n++;
        a[n - 1] = 0;
    }

    int p = (int)(log(n)/log(2));
    int pp = pow(2, p);

    memset(s, 0, sizeof s);
    for (int i = 0 ; i < n * 2 ; i++) {
        s[i] = 1000000000;
    }

    for (int i = 0 ; i < n ; i++) {
        int ind = pp + i;
        s[ind] = min(s[ind], a[i]);
        while (ind > 0) {
            ind /= 2;
            s[ind] = min(s[ind], a[i]);
        }
    }

    int q;
    cin >> q;
    cout << endl;
    rep(i, q) {
        int x, y, a, b, k; cin >> x >> y >> a >> b >> k;

        x--; y--; a--; b--;
        int d1 = dst(a, b);
        int d2 = dst(a, x) + dst(b, y) + 1;
        int d3 = dst(a, y) + dst(b, x) + 1;
        int dss[3] = {d1, d2, d3};
        bool f = false;
        for (int e : dss) {
            //cout << e << endl;
            if (e <= k && e % 2 == k % 2) {
                f = true;
            }
        }

        if (f) {
            cout << "YES" << '\n';
        }
        else {
            cout << "NO" << '\n';
        }
    }
}

void querySolve() {
    int n;
    cin >> n;
    while (n--) {
        solve();
    }
}

int main() {
    //querySolve();
    solve();
}


#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
typedef vector<iii> viii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000

vi adj[100005];
vi bb;
vi cc;
bool vis[100005];
int n;
ii rng[600005];
int a[600005];
int s[600005];
int ds[100005];
int f[600005];

int rangeMin(int a, int b) {
    if (a == b) {
        return bb[a];
    }
    a += n;
    b += n;
    int sm = 1000000000;
    while (a <= b) {
        if (a % 2 == 1) {
            sm = min(sm, s[a]);
            a++;
        }
        if (b % 2 == 0) {
            sm = min(sm, s[b]);
            b--;
        }
        a /= 2;
        b /= 2;
    }
    return sm;
}

void dfs(int n, int d) {

    vis[n] = true;
    ds[n] = d;
    bb.push_back(ds[n]);
    cc.push_back(n);
    bool f = false;
    for (int a : adj[n]) {
        if (vis[a]) {
            continue;
        }
        f = true;
        dfs(a, d + 1);
        bb.push_back(ds[n]);
        cc.push_back(n);
    }
    //if (f) {
    //bb.push_back(n);
    //}
}

int dst(int a, int b) {
    int x = f[a];
    int y = f[b];
    int ans;
    if (x <= y) {
        ans = rangeMin(f[a], f[b]);
    }
    else {
        ans = rangeMin(f[b], f[a]);
    }

    return ds[a] + ds[b] - ans * 2;
}

void solve() {
    memset(vis, false, sizeof vis);
    cin >> n;
    rep(i, n - 1) {
        int aa, bbb;
        cin >> aa >> bbb;
        aa--; bbb--;
        adj[aa].pb(bbb);
        adj[bbb].pb(aa);
    }

    dfs(0, 0);
    n = 0;
    for (int i = cc.size() - 1 ; i >= 0 ; i--) {
        a[i] = bb[i];
        f[cc[i]] = i;
        n++;
    }

    while (abs((int)(log(n)/log(2)) - (log(n)/log(2))) > 0.0000000001) {
        n++;
        a[n - 1] = 0;
    }

    int p = (int)(log(n)/log(2));
    int pp = pow(2, p);

    memset(s, 0, sizeof s);
    for (int i = 0 ; i < n * 2 ; i++) {
        s[i] = 1000000000;
    }

    for (int i = 0 ; i < n ; i++) {
        int ind = pp + i;
        s[ind] = min(s[ind], a[i]);
        while (ind > 0) {
            ind /= 2;
            s[ind] = min(s[ind], a[i]);
        }
    }

    int q;
    cin >> q;
    cout << endl;
    rep(i, q) {
        int x, y, a, b, k; cin >> x >> y >> a >> b >> k;

        x--; y--; a--; b--;
        int d1 = dst(a, b);
        int d2 = dst(a, x) + dst(b, y) + 1;
        int d3 = dst(a, y) + dst(b, x) + 1;
        int dss[3] = {d1, d2, d3};
        bool f = false;
        for (int e : dss) {
            //cout << e << endl;
            if (e <= k && e % 2 == k % 2) {
                f = true;
            }
        }

        if (f) {
            cout << "YES" << '\n';
        }
        else {
            cout << "NO" << '\n';
        }
    }
}

void querySolve() {
    int n;
    cin >> n;
    while (n--) {
        solve();
    }
}

int main() {
    //querySolve();
    solve();
}


#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
typedef vector<iii> viii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000

vi adj[400005];
vi bb;
vi cc;
bool vis[400005];
int n;
ii rng[400005];
int a[400005];
int s[400005];
int ds[400005];
int f[400005];

int rangeMin(int a, int b) {
    if (a == b) {
        return bb[a];
    }
    a += n;
    b += n;
    int sm = 1000000000;
    while (a <= b) {
        if (a % 2 == 1) {
            sm = min(sm, s[a]);
            a++;
        }
        if (b % 2 == 0) {
            sm = min(sm, s[b]);
            b--;
        }
        a /= 2;
        b /= 2;
    }
    return sm;
}

void dfs(int n, int d) {

    vis[n] = true;
    ds[n] = d;
    bb.push_back(ds[n]);
    cc.push_back(n);
    bool f = false;
    for (int a : adj[n]) {
        if (vis[a]) {
            continue;
        }
        f = true;
        dfs(a, d + 1);
        bb.push_back(ds[n]);
        cc.push_back(n);
    }
    //if (f) {
        //bb.push_back(n);
    //}
}

int dst(int a, int b) {
    int x = f[a];
    int y = f[b];
    int ans;
    if (x <= y) {
        ans = rangeMin(f[a], f[b]);
    }
    else {
        ans = rangeMin(f[b], f[a]);
    }

    return ds[a] + ds[b] - ans * 2;
}

void solve() {
    memset(vis, false, sizeof vis);
    cin >> n;
    rep(i, n - 1) {
        int aa, bbb;
        cin >> aa >> bbb;
        aa--; bbb--;
        adj[aa].pb(bbb);
        adj[bbb].pb(aa);
    }

    dfs(0, 0);
    n = 0;
    for (int i = cc.size() - 1 ; i >= 0 ; i--) {
        a[i] = bb[i];
        f[cc[i]] = i;
        n++;
    }

    while (abs((int)(log(n)/log(2)) - (log(n)/log(2))) > 0.0000000001) {
        n++;
        a[n - 1] = 0;
    }

    int p = (int)(log(n)/log(2));
    int pp = pow(2, p);

    memset(s, 0, sizeof s);
    for (int i = 0 ; i < n * 2 ; i++) {
        s[i] = 1000000000;
    }

    for (int i = 0 ; i < n ; i++) {
        int ind = pp + i;
        s[ind] = min(s[ind], a[i]);
        while (ind > 0) {
            ind /= 2;
            s[ind] = min(s[ind], a[i]);
        }
    }

    int q;
    cin >> q;
    cout << endl;
    rep(i, q) {
        int x, y, a, b, k; cin >> x >> y >> a >> b >> k;

        x--; y--; a--; b--;
        int d1 = dst(a, b);
        int d2 = dst(a, x) + dst(b, y) + 1;
        int d3 = dst(a, y) + dst(b, x) + 1;
        int dss[3] = {d1, d2, d3};
        bool f = false;
        for (int e : dss) {
            //cout << e << endl;
            if (e <= k && e % 2 == k % 2) {
                f = true;
            }
        }

        if (f) {
            cout << "YES" << '\n';
        }
        else {
            cout << "NO" << '\n';
        }
    }
}

void querySolve() {
    int n;
    cin >> n;
    while (n--) {
        solve();
    }
}

int main() {
    //querySolve();
    solve();
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node<<1,l,(l+r)/2
#define rson node<<1|1,(l+r)/2+1,r
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1e18+10;
const int mem_inf=286331153;
ll MOD=  1e9+7 ;
const ll mxn= 2e5+10;
const int N=20;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,k,m,q,x,y;
vector<int> g[mxn];
int up[mxn][N+1], in[mxn], out[mxn], d[mxn] ,timer=0;
bool ok(int down,int up){
    return in[up]<=in[down]&&out[up]>=out[down];
}
int lca(int u,int v){
    if(ok(u,v)) return v;
    if(ok(v,u)) return u;
    for(int i=N;i>=0;i--){
        if(!ok(v,up[u][i])) u=up[u][i];
    }
    return up[u][0];
}
void dfs(int v,int p){
    in[v]=++timer;
    up[v][0]=p;
    for(int i=1;i<=N;i++)
        up[v][i]=up[up[v][i-1]][i-1];

    for(auto u: g[v]){
        if(u==p) continue;
        d[u]=d[v]+1;
        dfs(u,v);
    }
    out[v]=++timer;
}
int dis(int u,int v){
    return d[u]+d[v]-2*d[lca(u,v)];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        g[u].pb(v), g[v].pb(u);
    }
    dfs(1,1);
    cin>>q;
    while(q--){
        int u,v,u_,v_,k,f=0;
        cin>>u>>v>>u_>>v_>>k;
         int d1=dis(u_,v_);
        //cout<<d1<<endl;
        if(d1<=k&&(k-d1)%2==0) f=1;
        d1=dis(u,u_)+dis(v,v_)+1;
        if(d1<=k&&(k-d1)%2==0) f=1;
        d1=dis(u,v_)+dis(v,u_)+1;
        if(d1<=k&&(k-d1)%2==0) f=1;

        if(f) cout<<"YES"<<'\n';
        else cout<<"NO"<<'\n';
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node<<1,l,(l+r)/2
#define rson node<<1|1,(l+r)/2+1,r
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1e18+10;
const int mem_inf=286331153;
ll MOD=  1e9+7 ;
const ll mxn= 1e3+10;
const int N=20;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,k,m,q,x,y;
vector<int> g[mxn];
int up[mxn][N], in[mxn], out[mxn], d[mxn] ,timer=0;
bool ok(int down,int up){
    return in[up]<in[down]&&out[up]>out[down];
}
int lca(int u,int v){
    if(ok(u,v)) return v;
    if(ok(v,u)) return u;
    for(int i=N;i>=0;i--){
        if(!ok(v,up[u][i])) u=up[u][i];
    }
    return up[u][0];
}
void dfs(int v,int p){
    in[v]=++timer;
    up[v][0]=p;
    for(int i=1;i<=N;i++)
        up[v][i]=up[up[v][i-1]][i-1];
    for(auto u: g[v]){
        if(u==p) continue;
        d[u]=d[v]+1;
        dfs(u,v);
    }
    out[v]=++timer;
}
int dis(int u,int v){
    return d[u]+d[v]-2*d[lca(u,v)];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        g[u].pb(v), g[v].pb(u);
    }
    dfs(1,0);
    cin>>q;
    while(q--){
        int u,v,u_,v_,k,f=0;
        cin>>u>>v>>u_>>v_>>k;
        int d1=dis(u_,v_);
        if(d1<=k&&(k-d1)%2==0) f=1;
        int cyc_len=dis(u,v)+1;
        if(!f){
            int d1=dis(u,u_)+dis(v,v_)+1;
            if(d1==dis(u,v_)+dis(v,u_)+1){
                if(d1<=k&&cyc_len%2) f=1;
            }
            else{
                int l=min(dis(u,u_)+dis(v,v_)+1, dis(u,v_)+dis(v,u_)+1);
                if(l<=k&&(k-l)%2==0) f=1;
            }
        }
        if(f) cout<<"YES"<<'\n';
        else cout<<"NO"<<'\n';
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node<<1,l,(l+r)/2
#define rson node<<1|1,(l+r)/2+1,r
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1e18+10;
const int mem_inf=286331153;
ll MOD=  1e9+7 ;
const ll mxn= 1e3+10;
const int N=20;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,k,m,q,x,y;
vector<int> g[mxn];
int up[mxn][N], in[mxn], out[mxn], d[mxn] ,timer=0;
bool ok(int down,int up){
    return in[up]<in[down]&&out[up]>out[down];
}
int lca(int u,int v){
    if(ok(u,v)) return v;
    if(ok(v,u)) return u;
    for(int i=N;i>=0;i--){
        if(!ok(v,up[u][i])) u=up[u][i];
    }
    return up[u][0];
}
void dfs(int v,int p){
    in[v]=++timer;
    up[v][0]=p;
    for(int i=1;i<=N;i++)
        up[v][i]=up[up[v][i-1]][i-1];
    for(auto u: g[v]){
        if(u==p) continue;
        d[u]=d[v]+1;
        dfs(u,v);
    }
    out[v]=++timer;
}
int dis(int u,int v){
    return d[u]+d[v]-2*d[lca(u,v)];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        g[u].pb(v), g[v].pb(u);
    }
    dfs(1,0);
    cin>>q;
    while(q--){
        int u,v,u_,v_,k,f=0;
        cin>>u>>v>>u_>>v_>>k;
        int d1=dis(u_,v_);
        if(d1<=k&&(k-d1)%2==0) f=1;
        int cyc_len=dis(u,v)+1;
        if(!f){
            int d1=dis(u,u_)+dis(v,v_)+1;
            if(d1==dis(u,v_)+dis(v,u_)+1){
                if(d1<=k&&(k-d1)%2==0) f=1;
            }
            else{
                int l=min(dis(u,u_)+dis(v,v_)+1, dis(u,v_)+dis(v,u_)+1);
                if(l<=k&&(k-l)%2==0) f=1;
            }
        }
        if(f) cout<<"YES"<<'\n';
        else cout<<"NO"<<'\n';
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node<<1,l,(l+r)/2
#define rson node<<1|1,(l+r)/2+1,r
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1e18+10;
const int mem_inf=286331153;
ll MOD=  1e9+7 ;
const ll mxn= 1e3+10;
const int N=20;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,k,m,q,x,y;
vector<int> g[mxn];
int up[mxn][N], in[mxn], out[mxn], d[mxn] ,timer=0;
bool ok(int down,int up){
    return in[up]<in[down]&&out[up]>out[down];
}
int lca(int u,int v){
    if(ok(u,v)) return v;
    if(ok(v,u)) return u;
    for(int i=N;i>=0;i--){
        if(!ok(v,up[u][i])) u=up[u][i];
    }
    return up[u][0];
}
void dfs(int v,int p){
    in[v]=++timer;
    up[v][0]=p;
    for(int i=1;i<=N;i++)
        up[v][i]=up[up[v][i-1]][i-1];
    for(auto u: g[v]){
        if(u==p) continue;
        d[u]=d[v]+1;
        dfs(u,v);
    }
    out[v]=++timer;
}
int dis(int u,int v){
    return d[u]+d[v]-2*d[lca(u,v)];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        g[u].pb(v), g[v].pb(u);
    }
    dfs(1,0);
    cin>>q;
    while(q--){
        int u,v,u_,v_,k,f=0;
        cin>>u>>v>>u_>>v_>>k;
        int d1=dis(u_,v_);
        if(d1<=k&&(k-d1)%2==0) f=1;
        d1=dis(u,u_)+dis(v,v_)+1;
        if(d1<=k&&(k-d1)%2==0) f=1;
        d1=dis(u,v_)+dis(v,u_)+1;
        if(d1<=k&&(k-d1)%2==0) f=1;

        if(f) cout<<"YES"<<'\n';
        else cout<<"NO"<<'\n';
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node<<1,l,(l+r)/2
#define rson node<<1|1,(l+r)/2+1,r
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1e18+10;
const int mem_inf=286331153;
ll MOD=  1e9+7 ;
const ll mxn= 2e5+10;
const int N=20;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,k,m,q,x,y;
vector<int> g[mxn];
int up[mxn][N+1], in[mxn], out[mxn], d[mxn] ,timer=0;
bool ok(int down,int up){
    return in[up]<=in[down]&&out[up]>=out[down];
}
int lca(int u,int v){
    if(ok(u,v)) return v;
    if(ok(v,u)) return u;
    for(int i=N;i>=0;i--){
        if(!ok(v,up[u][i])) u=up[u][i];
    }
    return up[u][0];
}
void dfs(int v,int p){
    in[v]=++timer;
    up[v][0]=p;
    for(int i=1;i<=N;i++)
        up[v][i]=up[up[v][i-1]][i-1];

    for(auto u: g[v]){
        if(u==p) continue;
        d[u]=d[v]+1;
        dfs(u,v);
    }
    out[v]=++timer;
}
int dis(int u,int v){
    return d[u]+d[v]-2*d[lca(u,v)];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        g[u].pb(v), g[v].pb(u);
    }
    dfs(1,1);
    cin>>q;
    while(q--){
        int u,v,u_,v_,k,f=0;
        cin>>u>>v>>u_>>v_>>k;
        int d1=dis(u_,v_);
        if(d1<=k&&(k-d1)%2==0) f=1;
        int cyc_len=dis(u,v)+1;
        if(!f){
            int d1=dis(u,u_)+dis(v,v_);
            if(d1==dis(u,v_)+dis(v,u_)){
                if(d1<=k&&cyc_len%2) f=1;
            }
            else{
                if(min(dis(u,u_)+dis(v,v_)+1, dis(u,v_)+dis(v,u_)+1)<=k&&cyc_len%2) f=1;
            }
        }
        if(f) cout<<"YES"<<'\n';
        else cout<<"NO"<<'\n';
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node<<1,l,(l+r)/2
#define rson node<<1|1,(l+r)/2+1,r
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1e18+10;
const int mem_inf=286331153;
ll MOD=  1e9+7 ;
const ll mxn= 1e3+10;
const int N=20;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,k,m,q,x,y;
vector<int> g[mxn];
int up[mxn][N], in[mxn], out[mxn], d[mxn] ,timer=0;
bool ok(int down,int up){
    return in[up]<in[down]&&out[up]>out[down];
}
int lca(int u,int v){
    if(ok(u,v)) return v;
    if(ok(v,u)) return u;
    for(int i=N;i>=0;i--){
        if(!ok(v,up[u][i])) u=up[u][i];
    }
    return up[u][0];
}
void dfs(int v,int p){
    in[v]=++timer;
    up[v][0]=p;
    for(int i=1;i<=N;i++)
        up[v][i]=up[up[v][i-1]][i-1];
    for(auto u: g[v]){
        if(u==p) continue;
        d[u]=d[v]+1;
        dfs(u,v);
    }
    out[v]=++timer;
}
int dis(int u,int v){
    return d[u]+d[v]-2*d[lca(u,v)];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        g[u].pb(v), g[v].pb(u);
    }
    dfs(1,0);
    cin>>q;
    while(q--){
        int u,v,u_,v_,k,f=0;
        cin>>u>>v>>u_>>v_>>k;
        int d1=dis(u_,v_);
        if(d1<=k&&(k-d1)%2==0) f=1;
        int cyc_len=dis(u,v)+1;
        if(!f){
            int d1=dis(u,u_)+dis(v,v_);
            if(d1==dis(u,v_)+dis(v,u_)){
                if(d1<=k&&cyc_len%2) f=1;
            }
            else{
                if(min(dis(u,u_)+dis(v,v_)+1, dis(u,v_)+dis(v,u_)+1)<=k&&cyc_len%2) f=1;
            }
        }
        if(f) cout<<"YES"<<'\n';
        else cout<<"NO"<<'\n';
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node<<1,l,(l+r)/2
#define rson node<<1|1,(l+r)/2+1,r
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1e18+10;
const int mem_inf=286331153;
ll MOD=  1e9+7 ;
const ll mxn= 1e3+10;
const int N=20;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,k,m,q,x,y;
vector<int> g[mxn];
int up[mxn][N], in[mxn], out[mxn], d[mxn] ,timer=0;
bool ok(int down,int up){
    return in[up]<=in[down]&&out[up]>=out[down];
}
int lca(int u,int v){
    if(ok(u,v)) return v;
    if(ok(v,u)) return u;
    for(int i=N;i>=0;i--){
        if(!ok(v,up[u][i])) u=up[u][i];
    }
    return up[u][0];
}
void dfs(int v,int p){
    in[v]=++timer;
    up[v][0]=p;
    for(int i=1;i<=N;i++)
        up[v][i]=up[up[v][i-1]][i-1];
    for(auto u: g[v]){
        if(u==p) continue;
        d[u]=d[v]+1;
        dfs(u,v);
    }
    out[v]=++timer;
}
int dis(int u,int v){
    return d[u]+d[v]-2*d[lca(u,v)];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        g[u].pb(v), g[v].pb(u);
    }
    dfs(1,0);
    cin>>q;
    while(q--){
        int u,v,u_,v_,k,f=0;
        cin>>u>>v>>u_>>v_>>k;
        int d1=dis(u_,v_);
        //cout<<d1<<endl;
        if(d1<=k&&(k-d1)%2==0) f=1;
        d1=dis(u,u_)+dis(v,v_)+1;
        if(d1<=k&&(k-d1)%2==0) f=1;
        d1=dis(u,v_)+dis(v,u_)+1;
        if(d1<=k&&(k-d1)%2==0) f=1;

        if(f) cout<<"YES"<<'\n';
        else cout<<"NO"<<'\n';
    }
}


#include <bits/stdc++.h>

#define FOR(i, a, b) for(int i = a; i<b; ++i)
#define FR(a, b) for(int i = a; i>=b;--i)
#define _upgrade cin.tie(0); ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define INF 1e9

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef pair<int, int> iPair;

const int MAX = 1e5+2;
const int M = 1e9 +7;

vector<int> tree[MAX];
int parent[MAX], depth[MAX], przodek[MAX][18];

void DFS(int node, int p)
{
    parent[node] = p;
    for(auto i : tree[node])
        if(i != p)
        {
            depth[i] = depth[node]+1;
            DFS(i, node);
        }
}
int LCA(int a, int b)
{
    if(depth[a] > depth[b])
        swap(a, b);
    for(int i = 17; i>=0; --i)
        if(depth[przodek[b][i]] >= depth[a])
            b = przodek[b][i];
    if(a == b)
        return a;
    for(int i = 17; i>= 0; --i)
        if(przodek[b][i] != przodek[a][i])
        {
            b = przodek[b][i];
            a = przodek[a][i];
        }
    return parent[a];
}
int dist(int a, int b)
{
    return (depth[a] + depth[b] - 2*depth[LCA(a, b)]);
}
int main()
{
    _upgrade;
    int n, q;
    cin>>n;
    FOR(i, 0, n-1)
    {
        int a, b;
        cin>>a>>b;
        tree[a].pb(b);
        tree[b].pb(a);
    }
    DFS(1, -1);
    parent[1] = 1;
    FOR(i, 1, n+1)
        przodek[i][0] = parent[i];
    for(int i = 1; i<=n; ++i)
        for(int k = 1; k<= 17; ++k)
            przodek[i][k] = przodek[przodek[i][k-1]][k-1];

    cin>>q;
    while(q--)
    {
        int x, y, a, b, k, dist1;
        cin>>x>>y>>a>>b>>k;
        dist1 = dist(a, b);
        //cout<<dist1<<" "<<dist(a, y)<<dist(a, x)<<"\n";
        if(dist1 <= k && (dist1-k)%2 == 0)
        {
            cout<<"YES\n";
            continue;
        }
        if(dist(a, x) > dist(a, y))
            swap(y, x);
        int dist2 = dist(a, x) + 1 + dist(b, y);
        if(dist2 <= k && (dist2-k)%2 == 0)
        {
            cout<<"YES\n";
            continue;
        }
        cout<<"NO\n";
    }
}


#include <bits/stdc++.h>

#define FOR(i, a, b) for(int i = a; i<b; ++i)
#define FR(a, b) for(int i = a; i>=b;--i)
#define _upgrade cin.tie(0); ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define INF 1e9

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef pair<int, int> iPair;

const int MAX = 1e5+2;
const int M = 1e9 +7;

vector<int> tree[MAX];
int parent[MAX], depth[MAX], przodek[MAX][19];

void DFS(int node, int p)
{
    parent[node] = p;
    for(auto i : tree[node])
        if(i != p)
        {
            depth[i] = depth[node]+1;
            DFS(i, node);
        }
}
int LCA(int a, int b)
{
    if(depth[a] > depth[b])
        swap(a, b);
    for(int i = 18; i>=0; --i)
        if(depth[przodek[b][i]] >= depth[a])
            b = przodek[b][i];
    if(a == b)
        return a;
    for(int i = 18; i>= 0; --i)
        if(przodek[b][i] != przodek[a][i])
        {
            b = przodek[b][i];
            a = przodek[a][i];
        }
    return parent[a];
}
int dist(int a, int b)
{
    return (depth[a] + depth[b] - 2*depth[LCA(a, b)]);
}
int main()
{
    _upgrade;
    int n, q;
    cin>>n;
    FOR(i, 0, n-1)
    {
        int a, b;
        cin>>a>>b;
        tree[a].pb(b);
        tree[b].pb(a);
    }
    DFS(1, -1);
    parent[1] = 1;
    FOR(i, 1, n+1)
        przodek[i][0] = parent[i];
    for(int k = 1; k<= 18; ++k)
        for(int i = 1; i<=n; ++i)
            przodek[i][k] = przodek[przodek[i][k-1]][k-1];

    cin>>q;
    while(q--)
    {
        int x, y, a, b, k, dist1;
        cin>>x>>y>>a>>b>>k;
        dist1 = dist(a, b);
        //cout<<dist1<<" "<<dist(a, y)<<dist(a, x)<<"\n";
        if(dist1 <= k && (dist1%2 == k%2))
        {
            cout<<"YES\n";
            continue;
        }
        int dist2 = dist(a, x) + 1 + dist(b, y), dist3 = dist(a, y) +1 + dist(b, x);
        if((dist2 <= k && (dist2%2 == k%2)) || (dist3 <= k && (dist3%2 ==k%2)))
        {
            cout<<"YES\n";
            continue;
        }
        cout<<"NO\n";
    }
}


#include <bits/stdc++.h>

#define FOR(i, a, b) for(int i = a; i<b; ++i)
#define FR(a, b) for(int i = a; i>=b;--i)
#define _upgrade cin.tie(0); ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define INF 1e9

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef pair<int, int> iPair;

const int MAX = 1e5+2;
const int M = 1e9 +7;

vector<int> tree[MAX];
int parent[MAX], depth[MAX], przodek[MAX][19];

void DFS(int node, int p)
{
    parent[node] = p;
    for(auto i : tree[node])
        if(i != p)
        {
            depth[i] = depth[node]+1;
            DFS(i, node);
        }
}
int LCA(int a, int b)
{
    if(depth[a] > depth[b])
        swap(a, b);
    for(int i = 18; i>=0; --i)
        if(depth[przodek[b][i]] >= depth[a])
            b = przodek[b][i];
    if(a == b)
        return a;
    for(int i = 18; i>= 0; --i)
        if(przodek[b][i] != przodek[a][i])
        {
            b = przodek[b][i];
            a = przodek[a][i];
        }
    return parent[a];
}
int dist(int a, int b)
{
    return (depth[a] + depth[b] - 2*depth[LCA(a, b)]);
}
int main()
{
    _upgrade;
    int n, q;
    cin>>n;
    FOR(i, 0, n-1)
    {
        int a, b;
        cin>>a>>b;
        tree[a].pb(b);
        tree[b].pb(a);
    }
    DFS(1, -1);
    parent[1] = 1;
    FOR(i, 1, n+1)
        przodek[i][0] = parent[i];
    for(int i = 1; i<=n; ++i)
        for(int k = 1; k<= 18; ++k)
            przodek[i][k] = przodek[przodek[i][k-1]][k-1];

    cin>>q;
    while(q--)
    {
        int x, y, a, b, k, dist1;
        cin>>x>>y>>a>>b>>k;
        dist1 = dist(a, b);
        //cout<<dist1<<" "<<dist(a, y)<<dist(a, x)<<"\n";
        if(dist1 <= k && (dist1-k)%2 == 0)
        {
            cout<<"YES\n";
            continue;
        }
        int dist2 = dist(a, x) + 1 + dist(b, y), dist3 = dist(a, y) +1 + dist(b, x);
        if((dist2 <= k && (dist2%2 == k%2)) || (dist3 <= k && (dist3%2 ==k%2)))
        {
            cout<<"YES\n";
            continue;
        }
        cout<<"NO\n";
    }
}


#include <bits/stdc++.h>

#define FOR(i, a, b) for(int i = a; i<b; ++i)
#define FR(a, b) for(int i = a; i>=b;--i)
#define _upgrade cin.tie(0); ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define INF 1e9

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef pair<int, int> iPair;

const int MAX = 1e5+2;
const int M = 1e9 +7;

vector<int> tree[MAX];
int parent[MAX], depth[MAX], przodek[MAX][18];

void DFS(int node, int p)
{
    parent[node] = p;
    for(auto i : tree[node])
        if(i != p)
        {
            depth[i] = depth[node]+1;
            DFS(i, node);
        }
}
int LCA(int a, int b)
{
    if(depth[a] > depth[b])
        swap(a, b);
    for(int i = 17; i>=0; --i)
        if(depth[przodek[b][i]] >= depth[a])
            b = przodek[b][i];
    if(a == b)
        return a;
    for(int i = 17; i>= 0; --i)
        if(przodek[b][i] != przodek[a][i])
        {
            b = przodek[b][i];
            a = przodek[a][i];
        }
    return parent[a];
}
int dist(int a, int b)
{
    return (depth[a] + depth[b] - 2*LCA(a, b));
}
int main()
{
    _upgrade;
    int n, q;
    cin>>n;
    FOR(i, 0, n-1)
    {
        int a, b;
        cin>>a>>b;
        tree[a].pb(b);
        tree[b].pb(a);
    }
    DFS(1, -1);
    parent[1] = 1;
    FOR(i, 1, n+1)
        przodek[i][0] = parent[i];
    for(int i = 1; i<=n; ++i)
        for(int k = 1; k<= 17; ++k)
            przodek[i][k] = przodek[przodek[i][k-1]][k-1];

    cin>>q;
    while(q--)
    {
        int x, y, a, b, k, dist1;
        cin>>x>>y>>a>>b>>k;
        dist1 = dist(a, b);
        if(dist1 <= k && (dist1-k)%2 == 0)
        {
            cout<<"YES\n";
            continue;
        }
        if(dist(a, x) > dist(a, y))
            swap(y, x);
        int dist2 = dist(a, x) + 1 + dist(b, y);
        if(dist2 <= k && (dist2-k)%2 == 0)
        {
            cout<<"YES\n";
            continue;
        }
        cout<<"NO\n";
    }
}


#include <bits/stdc++.h>

#define FOR(i, a, b) for(int i = a; i<b; ++i)
#define FR(a, b) for(int i = a; i>=b;--i)
#define _upgrade cin.tie(0); ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define INF 1e9

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef pair<int, int> iPair;

const int MAX = 1e5+2;
const int M = 1e9 +7;

vector<int> tree[MAX];
int parent[MAX], depth[MAX], przodek[MAX][18];

void DFS(int node, int p)
{
    parent[node] = p;
    for(auto i : tree[node])
        if(i != p)
        {
            depth[i] = depth[node]+1;
            DFS(i, node);
        }
}
int LCA(int a, int b)
{
    if(depth[a] > depth[b])
        swap(a, b);
    for(int i = 17; i>=0; --i)
        if(depth[przodek[b][i]] >= depth[a])
            b = przodek[b][i];
    if(a == b)
        return a;
    for(int i = 17; i>= 0; --i)
        if(przodek[b][i] != przodek[a][i])
        {
            b = przodek[b][i];
            a = przodek[a][i];
        }
    return parent[a];
}
int dist(int a, int b)
{
    return (depth[a] + depth[b] - 2*depth[LCA(a, b)]);
}
int main()
{
    _upgrade;
    int n, q;
    cin>>n;
    FOR(i, 0, n-1)
    {
        int a, b;
        cin>>a>>b;
        tree[a].pb(b);
        tree[b].pb(a);
    }
    DFS(1, -1);
    parent[1] = 1;
    FOR(i, 1, n+1)
        przodek[i][0] = parent[i];
    for(int i = 1; i<=n; ++i)
        for(int k = 1; k<= 17; ++k)
            przodek[i][k] = przodek[przodek[i][k-1]][k-1];

    cin>>q;
    while(q--)
    {
        int x, y, a, b, k, dist1;
        cin>>x>>y>>a>>b>>k;
        dist1 = dist(a, b);
        //cout<<dist1<<" "<<dist(a, y)<<dist(a, x)<<"\n";
        if(dist1 <= k && (dist1-k)%2 == 0)
        {
            cout<<"YES\n";
            continue;
        }
        int dist2 = dist(a, x) + 1 + dist(b, y), dist3 = dist(a, y) +1 + dist(b, x);
        if((dist2 <= k && (dist2%2 == k%2)) || (dist3 <= k && (dist3%2 ==k%2)))
        {
            cout<<"YES\n";
            continue;
        }
        cout<<"NO\n";
    }
}


#include <bits/stdc++.h>

#define FOR(i, a, b) for(int i = a; i<b; ++i)
#define FR(a, b) for(int i = a; i>=b;--i)
#define _upgrade cin.tie(0); ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define INF 1e9

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef pair<int, int> iPair;

const int MAX = 1e5+2;
const int M = 1e9 +7;

vector<int> tree[MAX];
int parent[MAX], depth[MAX], przodek[MAX][19];

void DFS(int node, int p)
{
    parent[node] = p;
    for(auto i : tree[node])
        if(i != p)
        {
            depth[i] = depth[node]+1;
            DFS(i, node);
        }
}
int LCA(int a, int b)
{
    if(depth[a] > depth[b])
        swap(a, b);
    for(int i = 18; i>=0; --i)
        if(depth[przodek[b][i]] >= depth[a])
            b = przodek[b][i];
    if(a == b)
        return a;
    for(int i = 18; i>= 0; --i)
        if(przodek[b][i] != przodek[a][i])
        {
            b = przodek[b][i];
            a = przodek[a][i];
        }
    return parent[a];
}
int dist(int a, int b)
{
    return (depth[a] + depth[b] - 2*depth[LCA(a, b)]);
}
int main()
{
    _upgrade;
    int n, q;
    cin>>n;
    FOR(i, 0, n-1)
    {
        int a, b;
        cin>>a>>b;
        tree[a].pb(b);
        tree[b].pb(a);
    }
    DFS(1, -1);
    parent[1] = 1;
    FOR(i, 1, n+1)
        przodek[i][0] = parent[i];
    for(int i = 1; i<=n; ++i)
        for(int k = 1; k<= 18; ++k)
            przodek[i][k] = przodek[przodek[i][k-1]][k-1];

    cin>>q;
    while(q--)
    {
        int x, y, a, b, k, dist1;
        cin>>x>>y>>a>>b>>k;
        dist1 = dist(a, b);
        //cout<<dist1<<" "<<dist(a, y)<<dist(a, x)<<"\n";
        if(dist1 <= k && (dist1%2 == k%2))
        {
            cout<<"YES\n";
            continue;
        }
        int dist2 = dist(a, x) + 1 + dist(b, y), dist3 = dist(a, y) +1 + dist(b, x);
        if((dist2 <= k && (dist2%2 == k%2)) || (dist3 <= k && (dist3%2 ==k%2)))
        {
            cout<<"YES\n";
            continue;
        }
        cout<<"NO\n";
    }
}


#include <bits/stdc++.h>

#define FOR(i, a, b) for(int i = a; i<b; ++i)
#define FR(a, b) for(int i = a; i>=b;--i)
#define _upgrade cin.tie(0); ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define INF 1e9

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef pair<int, int> iPair;

const int MAX = 1e5+2;
const int M = 1e9 +7;

vector<int> tree[MAX];
int parent[MAX], depth[MAX], przodek[MAX][18];

void DFS(int node, int p)
{
    parent[node] = p;
    for(auto i : tree[node])
        if(i != p)
        {
            depth[i] = depth[node]+1;
            DFS(i, node);
        }
}
int LCA(int a, int b)
{
    if(depth[a] > depth[b])
        swap(a, b);
    for(int i = 17; i>=0; --i)
        if(depth[przodek[b][i]] >= depth[a])
            b = przodek[b][i];
    if(a == b)
        return a;
    for(int i = 17; i>= 0; --i)
        if(przodek[b][i] != przodek[a][i])
        {
            b = przodek[b][i];
            a = przodek[a][i];
        }
    return parent[a];
}
int dist(int a, int b)
{
    return (depth[a] + depth[b] - 2*depth[LCA(a, b)]);
}
int main()
{
    _upgrade;
    int n, q;
    cin>>n;
    FOR(i, 0, n-1)
    {
        int a, b;
        cin>>a>>b;
        tree[a].pb(b);
        tree[b].pb(a);
    }
    DFS(1, -1);
    parent[1] = 1;
    FOR(i, 1, n+1)
        przodek[i][0] = parent[i];
    for(int i = 1; i<=n; ++i)
        for(int k = 1; k<= 17; ++k)
            przodek[i][k] = przodek[przodek[i][k-1]][k-1];

    cin>>q;
    while(q--)
    {
        int x, y, a, b, k, dist1;
        cin>>x>>y>>a>>b>>k;
        dist1 = dist(a, b);
        //cout<<dist1<<" "<<dist(a, y)<<dist(a, x)<<"\n";
        if(dist1 <= k && (dist1-k)%2 == 0)
        {
            cout<<"YES\n";
            continue;
        }
        int dist2 = dist(a, x) + 1 + dist(b, y), dist3 = dist(a, y) +1 + dist(b, x);
        if(dist2 <= k && (dist2-k)%2 == 0 || dist3 <= k && (dist3-k)%2 == 0)
        {
            cout<<"YES\n";
            continue;
        }
        cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(a,b) for(int i=(a) ; i<(b) ; i++)
#define maxn 100005

using namespace std;
int n,dep[maxn]={0},up[maxn][21]={0};
vector<int> v[maxn];
void dfs(int x, int fa, int deep)
{
    dep[x]=deep;
    up[x][0]=fa;
    for(auto i: v[x])
        if(i!=fa)
            dfs(i,x,deep+1);
}
void init()
{
    for(int k=1 ; (1<<k)<=n ; k++)
        for(int i=1 ; i<=n ; i++)
            up[i][k]=up[up[i][k-1]][k-1];
}
int lca(int a,int b)
{
    if(dep[a]>dep[b])   swap(a,b);
    for(int i=20 ; i>=0 ; i--)
        if(dep[up[b][i]] == dep[a])
            b=up[b][i];
    if(a==b)    return a;
    for(int i=20 ; i>=0 ; i--)
        if(up[a][i]!=0 && up[a][i]!=up[b][i])
            a=up[a][i],b=up[b][i];
    return up[a][0];
}
int dis(int a, int b)
{
    int ans=dep[a]+dep[b]-2*dep[lca(a,b)];
    return ans;
}
int main(void)
{

	cin>>n;
	int a,b;
    REP(1,n)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    dfs(1,0,0);
    init();
    int q,x,y,k,ab,ax,ay,bx,by;
    cin>>q;
    while(q--)
    {
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        ab=dis(a,b),ax=dis(a,x),ay=dis(a,y),bx=dis(b,x),by=dis(b,y);
        if(ab<=k && ab%2==k%2) flag=1;
        if((ax+1+by)<=k && ((ax+1+by)%2==k%2) )    flag=1;
        if((ay+1+bx)<=k && ((ay+1+bx)%2==k%2))    flag=1;
        if(flag)    cout<<"YES\n";
        else    cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

vector<int> v[100005];
map<int, int > m;
int n,q,rmq[100005][33],deep[100005]={0},cnt=0;

void dfs(int u, int p, int dep)
{
    if(!m[u]) m[u]=cnt;
    rmq[cnt++][0]=dep;
    deep[u]=dep;
    for(auto i : v[u])
        if(i!=p)
            dfs(i, u, dep+1);

}

void lca()
{
    for(int j=1 ; (1<<j)<cnt ; j++)
        for(int i=0 ; i+(1<<j)-1<cnt ; i++)
            rmq[i][j]=min(rmq[i][j-1],rmq[i+1<<(j-1)][j-1]);
}

int querry(int a, int b)
{
    a=m[a]; b=m[b];
    if(b<a) swap(a,b);
    int k,len=abs(b-a);

    k=log(len);

    int ans=min(rmq[a][k],rmq[b-(1<<k)+1][k]);
    return ans;
}
int main(void)
{
    AC
	cin>>n;
	int x,y;
	for(int i=1 ; i<n ; i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }

    dfs(1,0,0);
    cin>>q;
    while(q--)
    {
        int x,y,a,b,k;
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        int c1,c2,c3;
        c1=deep[a]+deep[x]-2*querry(a,x)+deep[y]+deep[b]-2*querry(y,b)+1;
        c2=deep[b]+deep[x]-2*querry(b,x)+deep[y]+deep[a]-2*querry(y,a)+1;
        c3=deep[a]+deep[b]-2*querry(a,b);
     //   printf("c1=%d\nc2=%d\nc3=%d\n",c1,c2,c3);
        if( c1 <= k && (k%2==c1%2) )    flag=1;
        else if( c2 <=k && (k%2==c2%2)) flag=1;
        else if( c3 <=k && (k%2==c3%2)) flag=1;

        if(flag) cout<<"yes\n";
        else    cout<<"no\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

vector<int> v[100005];
map<int, int > m;
int n,q,rmq[100005][33],deep[100005]={0},cnt=0;

void dfs(int u, int p, int dep)
{
    if(!m[u]) m[u]=cnt;
    rmq[cnt++][0]=dep;
    deep[u]=dep;
    for(auto i : v[u])
        if(i!=p)
            dfs(i, u, dep+1);

}

void lca()
{
    for(int j=1 ; (1<<j)<cnt ; j++)
        for(int i=0 ; i+(1<<j)-1<cnt ; i++)
            rmq[i][j]=min(rmq[i][j-1],rmq[i+1<<(j-1)][j-1]);
}

int querry(int a, int b)
{
    a=m[a]; b=m[b];
    if(b<a) swap(a,b);
    int k,len=abs(b-a);

    k=floor(log(len)/log(2));

    int ans=min(rmq[a][k],rmq[b-(1<<k)+1][k]);
    return ans;
}
int main(void)
{
    AC
	cin>>n;
	int x,y;
	for(int i=1 ; i<n ; i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }

    dfs(1,0,0);
    cin>>q;
    while(q--)
    {
        int x,y,a,b,k;
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        int c1,c2,c3;
        c1=deep[a]+deep[x]-2*querry(a,x)+deep[y]+deep[b]-2*querry(y,b)+1;
        c2=deep[b]+deep[x]-2*querry(b,x)+deep[y]+deep[a]-2*querry(y,a)+1;
        c3=deep[a]+deep[b]-2*querry(a,b);
     //   printf("c1=%d\nc2=%d\nc3=%d\n",c1,c2,c3);
        if( c1 <= k && (k%2==c1%2) )    flag=1;
        else if( c2 <=k && (k%2==c2%2)) flag=1;
        else if( c3 <=k && (k%2==c3%2)) flag=1;

        if(flag) cout<<"yes\n";
        else    cout<<"no\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

vector<int> v[100005];
map<int, int > m;
int n,q,rmq[100005][33],deep[100005]={0},cnt=0,x,y;

void dfs(int u, int p, int dep)
{

    if(!m[u]) m[u]=cnt;
    rmq[cnt++][0]=dep;
    deep[u]=dep;
    for(auto i : v[u])
        if(i!=p)
           {
               dfs(i, u, dep+1);
               rmq[cnt++][0]=dep;
               cout<<u<<" ";
           }

}

int querry(int a, int b)
{
    a=m[a]; b=m[b];
    if(b<a) swap(a,b);
    int k=0,len=b-a+1;
    while( (1<<(k+1)) < len )   k++;
    int ans=min(rmq[a][k],rmq[b-(1<<k)+1][k]);
    return ans;
}
int main(void)
{
    AC
	cin>>n;
	for(int i=1 ; i<n ; i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }

    dfs(1,0,0);
    cout<<endl;
    for(int j=1 ; (1<<j)<=cnt ; j++)
        for(int i=0 ; i+(1<<j)-1<=cnt ; i++)
            rmq[i][j]=min(rmq[i][j-1],rmq[i + (1<<(j-1))][j-1]);

    cin>>q;
    while(q--)
    {
        int a,b,k;
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        int c1,c2,c3;
        c1=deep[a]+deep[x]-2*querry(a,x)+deep[y]+deep[b]-2*querry(y,b)+1;
        c2=deep[b]+deep[x]-2*querry(b,x)+deep[y]+deep[a]-2*querry(y,a)+1;
        c3=deep[a]+deep[b]-2*querry(a,b);
        if( c1 <= k && (k%2==c1%2) )    flag=1;
        else if( c2 <=k && (k%2==c2%2)) flag=1;
        else if( c3 <=k && (k%2==c3%2)) flag=1;
        if(flag) cout<<"yes\n";
        else    cout<<"no\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

vector<int> v[100005];
map<int, int > m;
int n,q,rmq[100005][33],deep[100005]={0},cnt=0;

void dfs(int u, int p, int dep)
{
    if(!m[u]) m[u]=cnt;
    rmq[cnt++][0]=dep;
    deep[u]=dep;
    for(auto i : v[u])
        if(i!=p)
            dfs(i, u, dep+1);

}

void lca()
{
    for(int j=1 ; (1<<j)<=cnt ; j++)
        for(int i=0 ; i+(1<<j)-1<=cnt ; i++)
            rmq[i][j]=min(rmq[i][j-1],rmq[i+1<<(j-1)][j-1]);
}

int querry(int a, int b)
{
    a=m[a]; b=m[b];
    if(b<a) swap(a,b);
    int k,len=abs(b-a);
    for( k=0 ; (1<<k) <= len ; k++) ;
    return min(rmq[a][k],rmq[b-(1<<k)+1][k]);
}
int main(void)
{
    AC
	cin>>n;
	int x,y;
	for(int i=1 ; i<n ; i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }

    dfs(1,-1,0);
    cin>>q;
    while(q--)
    {
        int x,y,a,b,k;
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        int c1,c2,c3;
        c1=deep[a]+deep[x]-2*querry(a,x)+deep[y]+deep[b]-2*querry(y,b)+1;
        c2=deep[b]+deep[x]-2*querry(b,x)+deep[y]+deep[a]-2*querry(y,a)+1;
        c3=deep[a]+deep[b]-2*querry(a,b);
     //   printf("c1=%d\nc2=%d\nc3=%d\n",c1,c2,c3);
        if( c1 <= k && (k%2==c1%2) )    flag=1;
        else if( c2 <=k && (k%2==c2%2)) flag=1;
        else if( c3 <=k && (k%2==c3%2)) flag=1;

        if(flag) cout<<"yes\n";
        else    cout<<"no\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

vector<int> v[100005];
map<int, int > m;
int n,q,rmq[100005][33],deep[100005]={0},cnt=0,x,y;

void dfs(int u, int p, int dep)
{

    if(!m[u]) m[u]=cnt;
    rmq[cnt++][0]=dep;
    deep[u]=dep;
    for(auto i : v[u])
        if(i!=p)
           {
               dfs(i, u, dep+1);
               rmq[cnt++][0]=dep;
           }

}

int querry(int a, int b)
{
    a=m[a]; b=m[b];
    if(b<a) swap(a,b);
    int k=0,len=b-a+1;
    while( (1<<(k+1)) < len )   k++;
    int ans=min(rmq[a][k],rmq[b-(1<<k)+1][k]);
    return ans;
}
int main(void)
{
    AC
	cin>>n;
	for(int i=1 ; i<n ; i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }

    dfs(1,0,0);
    cout<<endl;
    for(int j=1 ; (1<<j)<=cnt ; j++)
        for(int i=0 ; i+(1<<j)-1<=cnt ; i++)
            rmq[i][j]=min(rmq[i][j-1],rmq[i + (1<<(j-1))][j-1]);

    cin>>q;
    while(q--)
    {
        int a,b,k;
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        int c1,c2,c3;
        c1=deep[a]+deep[x]-2*querry(a,x)+deep[y]+deep[b]-2*querry(y,b)+1;
        c2=deep[b]+deep[x]-2*querry(b,x)+deep[y]+deep[a]-2*querry(y,a)+1;
        c3=deep[a]+deep[b]-2*querry(a,b);
        if( c1 <= k && (k%2==c1%2) )    flag=1;
        else if( c2 <=k && (k%2==c2%2)) flag=1;
        else if( c3 <=k && (k%2==c3%2)) flag=1;
        if(flag) cout<<"yes\n";
        else    cout<<"no\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

vector<int> v[100005];
map<int, int > m;
int n,q,rmq[100005][33],deep[100005]={0},cnt=0;

void dfs(int u, int p, int dep)
{
    if(!m[u]) m[u]=cnt;
    rmq[cnt++][0]=dep;
    deep[u]=dep;
    for(auto i : v[u])
        if(i!=p)
            dfs(i, u, dep+1);

}

void lca()
{
    for(int j=1 ; (1<<j)<=cnt ; j++)
        for(int i=0 ; i+(1<<j)-1<=cnt ; i++)
            rmq[i][j]=min(rmq[i][j-1],rmq[i+1<<(j-1)][j-1]);
}

int querry(int a, int b)
{
    a=m[a]; b=m[b];
    if(b<a) swap(a,b);
    int len=abs(b-a);
    ll k=int(log2(len));
    return min(rmq[a][k],rmq[b-(1<<k)+1][k]);
}
int main(void)
{
    AC
	cin>>n;
	int x,y;
	for(int i=1 ; i<n ; i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }

    dfs(1,0,0);
    cin>>q;
    while(q--)
    {
        int x,y,a,b,k;
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        int c1,c2,c3;
        c1=deep[a]+deep[x]-2*querry(a,x)+deep[y]+deep[b]-2*querry(y,b)+1;
        c2=deep[b]+deep[x]-2*querry(b,x)+deep[y]+deep[a]-2*querry(y,a)+1;
        c3=deep[a]+deep[b]-2*querry(a,b);
     //   printf("c1=%d\nc2=%d\nc3=%d\n",c1,c2,c3);
        if( c1 <= k && (k%2==c1%2) )    flag=1;
        else if( c2 <=k && (k%2==c2%2)) flag=1;
        else if( c3 <=k && (k%2==c3%2)) flag=1;

        if(flag) cout<<"yes\n";
        else    cout<<"no\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

vector<int> v[100005];
map<int, int > m;
int n,q,rmq[100005][33],deep[100005]={0},cnt=0;

void dfs(int u, int p, int dep)
{
    if(!m[u]) m[u]=cnt;
    rmq[cnt++][0]=dep;
    deep[u]=dep;
    for(auto i : v[u])
        if(i!=p)
            dfs(i, u, dep+1);

}

void lca()
{
    for(int j=1 ; (1<<j)<cnt ; j++)
        for(int i=0 ; i+(1<<j)-1<cnt ; i++)
            rmq[i][j]=min(rmq[i][j-1],rmq[i+1<<(j-1)][j-1]);
}

int querry(int a, int b)
{
    a=m[a]; b=m[b];
    if(b<a) swap(a,b);
    int k=0,len=b-a+1;
    while( (1<<(k+1)) < len )   k++;
    int ans=min(rmq[a][k],rmq[b-(1<<k)+1][k]);
    return ans;
}
int main(void)
{
    AC
	cin>>n;
	int x,y;
	for(int i=1 ; i<n ; i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }

    dfs(1,0,0);
    cin>>q;
    while(q--)
    {
        int x,y,a,b,k;
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        int c1,c2,c3;
        c1=deep[a]+deep[x]-2*querry(a,x)+deep[y]+deep[b]-2*querry(y,b)+1;
        c2=deep[b]+deep[x]-2*querry(b,x)+deep[y]+deep[a]-2*querry(y,a)+1;
        c3=deep[a]+deep[b]-2*querry(a,b);
     //   printf("c1=%d\nc2=%d\nc3=%d\n",c1,c2,c3);
        if( c1 <= k && (k%2==c1%2) )    flag=1;
        else if( c2 <=k && (k%2==c2%2)) flag=1;
        else if( c3 <=k && (k%2==c3%2)) flag=1;

        if(flag) cout<<"yes\n";
        else    cout<<"no\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

vector<int> v[100005];
map<int, int > m;
int n,q,rmq[100005][33],deep[100005]={0},cnt=0;

void dfs(int u, int p, int dep)
{
    if(!m[u]) m[u]=cnt;
    rmq[cnt++][0]=dep;
    deep[u]=dep;
    for(auto i : v[u])
        if(i!=p)
            dfs(i, u, dep+1);

}

void lca()
{
    for(int j=1 ; (1<<j)<=cnt ; j++)
        for(int i=0 ; i+(1<<j)-1<=cnt ; i++)
            rmq[i][j]=min(rmq[i][j-1],rmq[i+1<<(j-1)][j-1]);
}

int querry(int a, int b)
{
    a=m[a]; b=m[b];
    if(b<a) swap(a,b);
    int k,len=abs(b-a);
    for( k=0 ; (1<<k) <= len ; k++) ;
    return min(rmq[a][k],rmq[b-(1<<k)+1][k]);
}
int main(void)
{
    AC
	cin>>n;
	int x,y;
	for(int i=1 ; i<n ; i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }

    dfs(1,0,0);
    cin>>q;
    while(q--)
    {
        int x,y,a,b,k;
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        int c1,c2,c3;
        c1=deep[a]+deep[x]-2*querry(a,x)+deep[y]+deep[b]-2*querry(y,b)+1;
        c2=deep[b]+deep[x]-2*querry(b,x)+deep[y]+deep[a]-2*querry(y,a)+1;
        c3=deep[a]+deep[b]-2*querry(a,b);
     //   printf("c1=%d\nc2=%d\nc3=%d\n",c1,c2,c3);
        if( c1 <= k && (k%2==c1%2) )    flag=1;
        else if( c2 <=k && (k%2==c2%2)) flag=1;
        else if( c3 <=k && (k%2==c3%2)) flag=1;

        if(flag) cout<<"yes\n";
        else    cout<<"no\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

vector<int> v[100005];
map<int, int > m;
int n,q,rmq[100005][33],deep[100005]={0},cnt=0,x,y;

void dfs(int u, int p, int dep)
{

    if(!m[u]) m[u]=cnt;
    rmq[cnt++][0]=dep;
    cout<<u<<" ";
    deep[u]=dep;
    for(auto i : v[u])
        if(i!=p)
           {
               dfs(i, u, dep+1);
               rmq[cnt++][0]=dep;
               cout<<u<<" ";
           }

}

int querry(int a, int b)
{
    a=m[a]; b=m[b];
    printf("new  a=%d  b=%d\n",a,b);
    if(b<a) swap(a,b);
    int k=0,len=b-a+1;
    while( (1<<(k+1)) < len )   k++;
    printf("k=%d\n",k);
    printf("%d       %d\n",rmq[a][k],rmq[b-(1<<k)+1][k]);
    int ans=min(rmq[a][k],rmq[b-(1<<k)+1][k]);
    return ans;
}
int main(void)
{
    AC
	cin>>n;
	for(int i=1 ; i<n ; i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }

    dfs(1,0,0);
    cout<<endl;
    for(int j=1 ; (1<<j)<=cnt ; j++)
        for(int i=0 ; i+(1<<j)-1<=cnt ; i++)
            rmq[i][j]=min(rmq[i][j-1],rmq[i + (1<<(j-1))][j-1]);

    cin>>q;
    while(q--)
    {
        int a,b,k;
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        int c1,c2,c3;
        c1=deep[a]+deep[x]-2*querry(a,x)+deep[y]+deep[b]-2*querry(y,b)+1;
        c2=deep[b]+deep[x]-2*querry(b,x)+deep[y]+deep[a]-2*querry(y,a)+1;
        c3=deep[a]+deep[b]-2*querry(a,b);
        if( c1 <= k && (k%2==c1%2) )    flag=1;
        else if( c2 <=k && (k%2==c2%2)) flag=1;
        else if( c3 <=k && (k%2==c3%2)) flag=1;
        if(flag) cout<<"yes\n";
        else    cout<<"no\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(a,b) for(int i=(a) ; i<(b) ; i++)
#define maxn 100005

using namespace std;
int n,dep[maxn]={0},up[maxn][21]={0};
vector<int> v[maxn];
void dfs(int x, int fa, int deep)
{
    dep[x]=deep;
    up[x][0]=fa;
    for(auto i: v[x])
        if(i!=fa)
            dfs(i,x,deep+1);
}
void init()
{
    for(int k=1 ; (1<<k)<=n ; k++)
        for(int i=1 ; i<=n ; i++)
            up[i][k]=up[up[i][k-1]][k-1];
}
int lca(int a,int b)
{
    if(dep[a]>dep[b])   swap(a,b);
    for(int i=20 ; i>=0 ; i--)
        if(dep[up[b][i]] == dep[a])
            b=up[b][i];
    if(a==b)    return a;
    for(int i=20 ; i>=0 ; i--)
        if(up[a][i]!=0 && up[a][i]!=up[b][i])
            a=up[a][i],b=up[b][i];
    return up[a][0];
}
int dis(int a, int b)
{
    int ans=dep[a]+dep[b]-2*dep[lca(a,b)];
    return ans;
}
int main(void)
{

	cin>>n;
	int a,b;
    REP(1,n)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    dfs(1,0,0);
    init();
    int q,x,y,k,ab,ax,ay,bx,by;
    cin>>q;
    while(q--)
    {
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        ab=dis(a,b),ax=dis(a,x),ay=dis(a,y),bx=dis(b,x),by=dis(b,y);
        cout<<ax;
        if(ab<=k && ab%2==k%2) flag=1;
        if((ax+1+by)<=k && ((ax+1+by)%2==k%2) )    flag=1;
        if((ay+1+bx)<=k && ((ay+1+bx)%2==k%2))    flag=1;
        if(flag)    cout<<"YES\n";
        else    cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(a,b) for(int i=(a) ; i<(b) ; i++)
#define maxn 100005

using namespace std;
int n,dep[maxn]={0},up[maxn][21]={0};
vector<int> v[maxn];
void dfs(int x, int fa, int deep)
{
    dep[x]=deep;
    up[x][0]=fa;
    for(auto i: v[x])
        if(i!=fa)
            dfs(i,x,deep+1);
}
void init()
{
    for(int k=1 ; (1<<k)<=n ; k++)
        for(int i=1 ; i<=n ; i++)
            up[i][k]=up[up[i][k-1]][k-1];
}
int lca(int a,int b)
{
    if(dep[a]>dep[b])   swap(a,b);
    for(int i=17 ; i>=0 ; i--)
        if(dep[up[b][i]] == dep[a])
            b=up[b][i];
    if(a==b)    return a;
    for(int i=17 ; i>=0 ; i--)
        if(up[a][i]!=0 && up[a][i]!=up[b][i])
            a=up[a][i],b=up[b][i];
    return up[a][0];
}
int dis(int a, int b)
{
    int ans=dep[a]+dep[b]-2*dep[lca(a,b)];
    return ans;
}
int main(void)
{
    AC
	cin>>n;
	int a,b;
    REP(1,n)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    dfs(1,0,0);
    init();
    int q,x,y,k,ab,ax,ay,bx,by;
    cin>>q;
    while(q--)
    {
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        ab=dis(a,b),ax=dis(a,x),ay=dis(a,y),bx=dis(b,x),by=dis(b,y);
        if(ab<=k && ab%2==k%2) flag=1;
        if((ax+1+by)<=k && ((ax+1+by)%2==k%2) )    flag=1;
        if((ay+1+bx)<=k && ((ay+1+bx)%2==k%2))    flag=1;
        if(flag)    cout<<"YES\n";
        else    cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(a,b) for(int i=(a) ; i<(b) ; i++)
#define maxn 100005

using namespace std;
int n,dep[maxn]={0},up[maxn][21]={0};
vector<int> v[maxn];
void dfs(int x, int fa, int deep)
{
    dep[x]=deep;
    up[x][0]=fa;
    for(auto i: v[x])
        if(i!=fa)
            dfs(i,x,deep+1);
}
void init()
{
    for(int k=1 ; (1<<k)<n ; k++)
        for(int i=1 ; i+(1<<k)<=n ; i++)
            up[i][k]=up[up[i][k-1]][k-1];
}
int lca(int a,int b)
{
    if(dep[a]>dep[b])   swap(a,b);
    for(int i=20 ; i>=0 ; i--)
        if(dep[up[b][i]]>= dep[a])
            b=up[b][i];
    if(a==b)    return a;
    for(int i=20 ; i>=0 ; i--)
        if(up[a][i]!=0 && up[a][i]!=up[b][i])
            a=up[a][i],b=up[b][i];
    return up[a][0];
}
int dis(int a, int b)
{
    int ans=dep[a]+dep[b]-2*dep[lca(a,b)];
    return ans;
}
int main(void)
{
	AC
	cin>>n;
	int a,b;
    REP(1,n)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    dfs(1,0,0);
    init();
    int q,x,y,k,ab,ax,ay,bx,by;
    cin>>q;
    while(q--)
    {
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        ab=dis(a,b),ax=dis(a,x),ay=dis(a,y),bx=dis(b,x),by=dis(b,y);
        if(ab<=k && ab%2==k%2) flag=1;
        if((ax+1+by)<=k && ((ax+1+by)%2==k%2) )    flag=1;
        if((ay+1+bx)<=k && ((ay+1+bx)%2==k%2))    flag=1;
        if(flag)    cout<<"YES\n";
        else    cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(a,b) for(int i=(a) ; i<(b) ; i++)
#define maxn 100005

using namespace std;
int n,dep[maxn]={0},up[maxn][18]={0};
vector<int> v[maxn];
void dfs(int x, int fa, int deep)
{
    dep[x]=deep;
    up[x][0]=fa;
    for(auto i: v[x])
        if(i!=fa)
            dfs(i,x,deep+1);
}
void init()
{
    for(int k=1 ; (1<<k)<n ; k++)
        for(int i=1 ; i+(1<<k)<=n ; i++)
            up[i][k]=up[up[i][k-1]][k-1];
}
int lca(int a,int b)
{
    if(dep[a]>dep[b])   swap(a,b);
    for(int i=18 ; i>=0 ; i--)
        if(dep[up[b][i]]>= dep[a])
            b=up[b][i];
    if(a==b)    return a;
    for(int i=18 ; i>=0 ; i--)
        if(up[a][i]!=0 && up[a][i]!=up[b][i])
            a=up[a][i],b=up[b][i];
    return up[a][0];
}
int dis(int a, int b)
{
    int ans=dep[a]+dep[b]-2*dep[lca(a,b)];
    return ans;
}
int main(void)
{
	AC
	cin>>n;
	int a,b;
    REP(1,n)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    dfs(1,0,0);
    init();
    int q,x,y,k,ab,ax,ay,bx,by;
    cin>>q;
    while(q--)
    {
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        ab=dis(a,b),ax=dis(a,x),ay=dis(a,y),bx=dis(b,x),by=dis(b,y);
        if(ab<=k && ab%2==k%2) flag=1;
        if((ax+1+by)<=k && ((ax+1+by)%2==k%2) )    flag=1;
        if((ay+1+bx)<=k && ((ay+1+bx)%2==k%2))    flag=1;
        if(flag)    cout<<"YES\n";
        else    cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

vector<int> v[100005];
map<int, int > m;
int n,q,rmq[100005][33],deep[100005]={0},cnt=0;

void dfs(int u, int p, int dep)
{
    if(!m[u]) m[u]=cnt;
    rmq[cnt++][0]=dep;
    deep[u]=dep;
    for(auto i : v[u])
        if(i!=p)
            dfs(i, u, dep+1);

}

void lca()
{
    for(int j=1 ; (1<<j)<=cnt ; j++)
        for(int i=0 ; i+(1<<j)-1<=cnt ; i++)
            rmq[i][j]=min(rmq[i][j-1],rmq[i+1<<(j-1)][j-1]);
}

int querry(int a, int b)
{
    a=m[a]; b=m[b];
    if(b<a) swap(a,b);
    int k,len=abs(b-a);
    k=log(len);
    return min(rmq[a][k],rmq[b-(1<<k)+1][k]);
}
int main(void)
{
    AC
	cin>>n;
	int x,y;
	for(int i=1 ; i<n ; i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }

    dfs(1,0,0);
    cin>>q;
    while(q--)
    {
        int x,y,a,b,k;
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        int c1,c2,c3;
        c1=deep[a]+deep[x]-2*querry(a,x)+deep[y]+deep[b]-2*querry(y,b)+1;
        c2=deep[b]+deep[x]-2*querry(b,x)+deep[y]+deep[a]-2*querry(y,a)+1;
        c3=deep[a]+deep[b]-2*querry(a,b);
     //   printf("c1=%d\nc2=%d\nc3=%d\n",c1,c2,c3);
        if( c1 <= k && (k%2==c1%2) )    flag=1;
        else if( c2 <=k && (k%2==c2%2)) flag=1;
        else if( c3 <=k && (k%2==c3%2)) flag=1;

        if(flag) cout<<"yes\n";
        else    cout<<"no\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

vector<int> v[100005];
map<int, int > m;
int n,q,rmq[100005][33],deep[100005]={0},cnt=0;

void dfs(int u, int p, int dep)
{
    if(!m[u]) m[u]=cnt;
    rmq[cnt++][0]=dep;
    deep[u]=dep;
    for(auto i : v[u])
        if(i!=p)
            dfs(i, u, dep+1);

}

void lca()
{
    for(int j=1 ; (1<<j)<=cnt ; j++)
        for(int i=0 ; i+(1<<j)-1<=cnt ; i++)
            rmq[i][j]=min(rmq[i][j-1],rmq[i+1<<(j-1)][j-1]);
}

int querry(int a, int b)
{
    a=m[a]; b=m[b];
    if(b<a) swap(a,b);
    int len=abs(b-a);
    int k=int(log(len));
    return min(rmq[a][k],rmq[b-(1<<k)+1][k]);
}
int main(void)
{
    AC
	cin>>n;
	int x,y;
	for(int i=1 ; i<n ; i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }

    dfs(1,0,0);
    cin>>q;
    while(q--)
    {
        int x,y,a,b,k;
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        int c1,c2,c3;
        c1=deep[a]+deep[x]-2*querry(a,x)+deep[y]+deep[b]-2*querry(y,b)+1;
        c2=deep[b]+deep[x]-2*querry(b,x)+deep[y]+deep[a]-2*querry(y,a)+1;
        c3=deep[a]+deep[b]-2*querry(a,b);
     //   printf("c1=%d\nc2=%d\nc3=%d\n",c1,c2,c3);
        if( c1 <= k && (k%2==c1%2) )    flag=1;
        else if( c2 <=k && (k%2==c2%2)) flag=1;
        else if( c3 <=k && (k%2==c3%2)) flag=1;

        if(flag) cout<<"yes\n";
        else    cout<<"no\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(a,b) for(int i=(a) ; i<(b) ; i++)
#define maxn 100005

using namespace std;
int n,dep[maxn]={0},up[maxn][21]={0};
vector<int> v[maxn];
void dfs(int x, int fa, int deep)
{
    dep[x]=deep;
    up[x][0]=fa;
    for(auto i: v[x])
        if(i!=fa)
            dfs(i,x,deep+1);
}
void init()
{
    for(int k=1 ; (1<<k)<=n ; k++)
        for(int i=1 ; i<=n ; i++)
            up[i][k]=up[up[i][k-1]][k-1];
}
int lca(int a,int b)
{
    if(dep[a]>dep[b])   swap(a,b);
    for(int i=17 ; i>=0 ; i--)
        if(dep[up[b][i]] == dep[a])
            b=up[b][i];
    if(a==b)    return a;
    for(int i=17 ; i>=0 ; i--)
        if(up[a][i]!=0 && up[a][i]!=up[b][i])
            a=up[a][i],b=up[b][i];
    return up[a][0];
}
int dis(int a, int b)
{
    int ans=dep[a]+dep[b]-2*dep[lca(a,b)];
    return ans;
}
int main(void)
{

	cin>>n;
	int a,b;
    REP(1,n)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    dfs(1,0,0);
    init();
    int q,x,y,k,ab,ax,ay,bx,by;
    cin>>q;
    while(q--)
    {
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        ab=dis(a,b),ax=dis(a,x),ay=dis(a,y),bx=dis(b,x),by=dis(b,y);
        if(ab<=k && ab%2==k%2) flag=1;
        if((ax+1+by)<=k && ((ax+1+by)%2==k%2) )    flag=1;
        if((ay+1+bx)<=k && ((ay+1+bx)%2==k%2))    flag=1;
        if(flag)    cout<<"YES\n";
        else    cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

vector<int> v[100005];
map<int, int > m;
int n,q,rmq[100005][33],deep[100005]={0},cnt=0;

void dfs(int u, int p, int dep)
{
    if(!m[u]) m[u]=cnt;
    rmq[cnt++][0]=dep;
    deep[u]=dep;
    for(auto i : v[u])
        if(i!=p)
            dfs(i, u, dep+1);

}

void lca()
{
    for(int j=1 ; (1<<j)<=cnt ; j++)
        for(int i=0 ; i+(1<<j)-1<=cnt ; i++)
            rmq[i][j]=min(rmq[i][j-1],rmq[i+1<<(j-1)][j-1]);
}

int querry(int a, int b)
{
    a=m[a]; b=m[b];
    if(b<a) swap(a,b);
    int k,len=abs(b-a);
    for( k=0 ; (1<<k) <= len ; k++) ;
    k--;
    return min(rmq[a][k],rmq[b-(1<<k)+1][k]);
}
int main(void)
{
    AC
	cin>>n;
	int x,y;
	for(int i=1 ; i<n ; i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }

    dfs(1,0,0);
    cin>>q;
    while(q--)
    {
        int x,y,a,b,k;
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        int c1,c2,c3;
        c1=deep[a]+deep[x]-2*querry(a,x)+deep[y]+deep[b]-2*querry(y,b)+1;
        c2=deep[b]+deep[x]-2*querry(b,x)+deep[y]+deep[a]-2*querry(y,a)+1;
        c3=deep[a]+deep[b]-2*querry(a,b);
     //   printf("c1=%d\nc2=%d\nc3=%d\n",c1,c2,c3);
        if( c1 <= k && (k%2==c1%2) )    flag=1;
        else if( c2 <=k && (k%2==c2%2)) flag=1;
        else if( c3 <=k && (k%2==c3%2)) flag=1;

        if(flag) cout<<"yes\n";
        else    cout<<"no\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(a,b) for(int i=(a) ; i<(b) ; i++)
#define maxn 100005

using namespace std;
int n,dep[maxn]={0},up[maxn][18]={0};
vector<int> v[maxn];
void dfs(int x, int fa, int deep)
{
    dep[x]=deep;
    up[x][0]=fa;
    for(auto i: v[x])
        if(i!=fa)
            dfs(i,x,deep+1);
}
void init()
{
    for(int k=1 ; (1<<k)<n ; k++)
        for(int i=1 ; i+(1<<k)<=n ; i++)
            up[i][k]=up[up[i][k-1]][k-1];
}
int lca(int a,int b)
{
    if(dep[a]>dep[b])   swap(a,b);
    for(int i=17 ; i>=0 ; i--)
        if(dep[up[b][i]]>= dep[a])
            b=up[b][i];
    if(a==b)    return a;
    for(int i=17 ; i>=0 ; i--)
        if(up[a][i]!=0 && up[a][i]!=up[b][i])
            a=up[a][i],b=up[b][i];
    return up[a][0];
}
int dis(int a, int b)
{
    int ans=dep[a]+dep[b]-2*dep[lca(a,b)];
    return ans;
}
int main(void)
{
	AC
	cin>>n;
	int a,b;
    REP(1,n)
    {
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    dfs(1,0,0);
    init();
    int q,x,y,k,ab,ax,ay,bx,by;
    cin>>q;
    while(q--)
    {
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        ab=dis(a,b),ax=dis(a,x),ay=dis(a,y),bx=dis(b,x),by=dis(b,y);
        if(ab<=k && ab%2==k%2) flag=1;
        if((ax+1+by)<=k && ((ax+1+by)%2==k%2) )    flag=1;
        if((ay+1+bx)<=k && ((ay+1+bx)%2==k%2))    flag=1;
        if(flag)    cout<<"YES\n";
        else    cout<<"NO\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

vector<int> v[100005];
map<int, int > m;
int n,q,rmq[100005][33],deep[100005]={0},cnt=0;

void dfs(int u, int p, int dep)
{
    if(!m[u]) m[u]=cnt;
    cout<<u<<"    ";
    rmq[cnt++][0]=dep;
    deep[u]=dep;
    for(auto i : v[u])
        if(i!=p)
            dfs(i, u, dep+1);

}

void lca()
{
    for(int j=1 ; (1<<j)<=cnt ; j++)
        for(int i=0 ; i+(1<<j)-1<=cnt ; i++)
            rmq[i][j]=min(rmq[i][j-1],rmq[i+1<<(j-1)][j-1]);
}

int querry(int a, int b)
{
    a=m[a]; b=m[b];
    if(b<a) swap(a,b);
    int len=abs(b-a);
    int k=log(len);
    return min(rmq[a][k],rmq[b-(1<<k)+1][k]);
}
int main(void)
{
	cin>>n;
	int x,y;
	for(int i=1 ; i<n ; i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }

    dfs(1,0,0);
    cout<<endl;

    cin>>q;
    while(q--)
    {
        int x,y,a,b,k;
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        int c1,c2,c3;
        c1=deep[a]+deep[x]-2*querry(a,x)+deep[y]+deep[b]-2*querry(y,b)+1;
        c2=deep[b]+deep[x]-2*querry(b,x)+deep[y]+deep[a]-2*querry(y,a)+1;
        c3=deep[a]+deep[b]-2*querry(a,b);
     //   printf("c1=%d\nc2=%d\nc3=%d\n",c1,c2,c3);
        if( c1 <= k && (k%2==c1%2) )    flag=1;
        else if( c2 <=k && (k%2==c2%2)) flag=1;
        else if( c3 <=k && (k%2==c3%2)) flag=1;

        if(flag) cout<<"yes\n";
        else    cout<<"no\n";
    }
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define inf 0x3f3f3f3f
#define ll long long
#define endl '\n'
#define mem(a,val) memset(a,val,sizeof(a))
#define clr(a) memset((a),0,sizeof(a))
#define S second
#define F first
#define AC ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

vector<int> v[100005];
map<int, int > m;
int n,q,rmq[100005][33],deep[100005]={0},cnt=0;

void dfs(int u, int p, int dep)
{
    if(!m[u]) m[u]=cnt;
    rmq[cnt++][0]=dep;
    deep[u]=dep;
    for(auto i : v[u])
        if(i!=p)
            dfs(i, u, dep+1);

}

void lca()
{
    for(int j=1 ; (1<<j)<cnt ; j++)
        for(int i=0 ; i+(1<<j)-1<cnt ; i++)
            rmq[i][j]=min(rmq[i][j-1],rmq[i+1<<(j-1)][j-1]);
}

int querry(int a, int b)
{
    a=m[a]; b=m[b];
    if(b<a) swap(a,b);
    int k,len=abs(b-a);

    k=floor(log2(len));

    int ans=min(rmq[a][k],rmq[b-(1<<k)+1][k]);
    return ans;
}
int main(void)
{
    AC
	cin>>n;
	int x,y;
	for(int i=1 ; i<n ; i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }

    dfs(1,0,0);
    cin>>q;
    while(q--)
    {
        int x,y,a,b,k;
        cin>>x>>y>>a>>b>>k;
        bool flag=0;
        int c1,c2,c3;
        c1=deep[a]+deep[x]-2*querry(a,x)+deep[y]+deep[b]-2*querry(y,b)+1;
        c2=deep[b]+deep[x]-2*querry(b,x)+deep[y]+deep[a]-2*querry(y,a)+1;
        c3=deep[a]+deep[b]-2*querry(a,b);
     //   printf("c1=%d\nc2=%d\nc3=%d\n",c1,c2,c3);
        if( c1 <= k && (k%2==c1%2) )    flag=1;
        else if( c2 <=k && (k%2==c2%2)) flag=1;
        else if( c3 <=k && (k%2==c3%2)) flag=1;

        if(flag) cout<<"yes\n";
        else    cout<<"no\n";
    }
}


/// In The Name Of God

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)3000 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

using namespace std;

void add(int &x, int y) {
	x += y;
	if (x >= mod) x -= mod;
	else if (x < 0) x += mod;
}

int get_int() {
	char x = getchar();
	while (!isdigit(x)) x = getchar();
	int res = 0;
	while (isdigit(x)) res = (res << 3) + (res << 1) + x - '0', x = getchar();
	return res;
}

int n;
int a[N];

ll dp[N][N];
vector <int> st;
unordered_map <int, int> id;

ll calc(int v, int last) {
	if (v > n) return dp[v][last] = 0;
	if (~dp[v][last]) return dp[v][last];
	ll res = calc(v + 1, last) + abs(a[v] - st[last]);
	if (last + 1 < sz(st)) res = min(res, calc(v, last + 1));
	return dp[v][last] = res;
}
int main() {
	#ifdef wws
		freopen ("in.txt", "r", stdin);
	#endif
	n = get_int();
	rep(i, 1, n) {
		a[i] = get_int() - i;
		st.pb(a[i]);
	}
	sort(all(st));
	st.erase(unique(all(st)), st.end());
	rep(i, 0, sz(st) - 1) id[st[i]] = i;
	ll ans = linf;
	memset(dp, -1, sizeof(dp));
	for (int i = 0; i < sz(st); i++) {
		ans = min(ans, calc(1, i));
	}
	cout << ans;
	ioi
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <ctime>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <iomanip>
#include <fstream>
using namespace std;
#define fname ""
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define inf 1000000000
#define INF 1000000000000000000ll
const int N = 1005000;
int n, a[N];
vector <int> vv;

ll now[N], old[N];

int main() {
	#ifndef ONLINE_JUDGE
    freopen(fname"in", "r", stdin);
    freopen(fname"out", "w", stdout);
	#endif

	scanf("%d", &n);

	for (int i = 1; i <= n; ++ i) {
		scanf("%d", &a[i]);
		a[i] -= i - 1;
		vv.pb(a[i]);
	}
	sort(vv.begin(), vv.end());
	vv.resize((unique(vv.begin(), vv.end()) - vv.begin()));
	int sz = (int)vv.size();

	for (int i = 0; i < sz; ++ i) {
		now[i] = INF;
		old[i] = abs(a[1] - vv[i]);
	}

	for (int i = 2; i <= n; ++ i) {
		ll mn = INF;
		for (int j = 0; j < sz; ++ j) {
			mn = min(mn, old[j]);
			now[j] = min(now[j], mn + abs(a[i] - vv[j]));
		}
		for (int j = 0; j < sz; ++ j) {
			old[j] = now[j];
			now[j] = INF;
		}
	}

	ll ans = INF;

	for (int i = 0; i < sz; ++ i) ans = min(ans, old[i]);

	cout << ans;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <ctime>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <unordered_map>
using namespace std;
#define fname ""
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define inf 1000000000
#define INF 1000000000000000000ll
const int N = 100500;
int n, a[N];
vector <int> vv;
unordered_map <int, int> was;
queue <int> q;
int cur[N], ss = 0;

ll now[N], old[N];

int main() {
	#ifndef ONLINE_JUDGE
    freopen(fname"in", "r", stdin);
    freopen(fname"out", "w", stdout);
	#endif

	scanf("%d", &n);

	for (int i = 1; i <= n; ++ i) {
		scanf("%d", &a[i]);
		vv.pb(a[i]);
	}
	sort(vv.begin(), vv.end());
	int who = vv[(int)vv.size() / 2];

	vv.resize((unique(vv.begin(), vv.end()) - vv.begin()));
	for (int i = 0; i < (int)vv.size(); ++ i) {
		q.push(vv[i]);
		was[vv[i]] = 1;
	}

	while ((int)vv.size() < 2 * n) {
		ss = 0;
		while (!q.empty()) {
			int who = q.front();
			q.pop();
			if (!was[who - 1]) {
				cur[++ss] = who - 1;
			}
			if (!was[who + 1]) {
				cur[++ss] = who + 1;
			}
		}
		for (int i = 1; i <= ss; ++ i) {
			if (!was[cur[i]]) {
				was[cur[i]] = 1;
				vv.pb(cur[i]);
				q.push(cur[i]);
			}
		}
	}

	for (int i = -3000; i <= 3000; ++ i) {
		if (!was[who + i]) {
			was[who + i] = 1;
			vv.pb(who + i);
		}
	}

	sort(vv.begin(), vv.end());
	int sz = (int)vv.size();

	for (int i = 0; i < sz; ++ i) {
		now[i] = INF;
		old[i] = abs(a[1] - vv[i]);
//		cout << vv[i] << " ";
	}
//	cout << endl;

	for (int i = 2; i <= n; ++ i) {
		ll mn = INF;
		for (int j = 0; j < sz; ++ j) {
			now[j] = min(now[j], mn + abs(a[i] - vv[j]));
			mn = min(mn, old[j]);
		}
		for (int j = 0; j < sz; ++ j) {
			old[j] = now[j];
			now[j] = INF;
		}
	}

	ll ans = INF;

	for (int i = 0; i < sz; ++ i) ans = min(ans, old[i]);

	cout << ans;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <ctime>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <unordered_map>
using namespace std;
#define fname ""
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define inf 1000000000
#define INF 1000000000000000000ll
const int N = 100500;
int n, a[N];
vector <int> vv;
unordered_map <int, int> was;
queue <int> q;
int cur[N], ss = 0;

ll now[N], old[N];

int main() {
	#ifndef ONLINE_JUDGE
    freopen(fname"in", "r", stdin);
    freopen(fname"out", "w", stdout);
	#endif

	scanf("%d", &n);

	for (int i = 1; i <= n; ++ i) {
		scanf("%d", &a[i]);
		vv.pb(a[i]);
	}
	sort(vv.begin(), vv.end());

	vv.resize((unique(vv.begin(), vv.end()) - vv.begin()));

	for (int i = 0; i < (int)vv.size(); ++ i) {
		q.push(vv[i]);
		was[vv[i]] = 1;
	}

	while ((int)vv.size() < 3 * n) {
		ss = 0;
		while (!q.empty()) {
			int who = q.front();
			q.pop();
			if (!was[who - 1]) {
				cur[++ss] = who - 1;
			}
			if (!was[who + 1]) {
				cur[++ss] = who + 1;
			}
		}
		for (int i = 1; i <= ss; ++ i) {
			if (!was[cur[i]]) {
				was[cur[i]] = 1;
				vv.pb(cur[i]);
				q.push(cur[i]);
			}
		}
	}

	sort(vv.begin(), vv.end());
	int sz = (int)vv.size();

	for (int i = 0; i < sz; ++ i) {
		now[i] = INF;
		old[i] = abs(a[1] - vv[i]);
//		cout << vv[i] << " ";
	}
//	cout << endl;

	for (int i = 2; i <= n; ++ i) {
		ll mn = INF;
		for (int j = 0; j < sz; ++ j) {
			now[j] = min(now[j], mn + abs(a[i] - vv[j]));
			mn = min(mn, old[j]);
		}
		for (int j = 0; j < sz; ++ j) {
			old[j] = now[j];
			now[j] = INF;
		}
	}

	ll ans = INF;

	for (int i = 0; i < sz; ++ i) ans = min(ans, old[i]);

	cout << ans;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <ctime>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <unordered_map>
using namespace std;
#define fname ""
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define inf 1000000000
#define INF 1000000000000000000ll
const int N = 100500;
int n, a[N];
vector <int> vv;
unordered_map <int, int> was;
queue <int> q;
int cur[N], ss = 0;

ll now[N], old[N];

int main() {
	#ifndef ONLINE_JUDGE
    freopen(fname"in", "r", stdin);
    freopen(fname"out", "w", stdout);
	#endif

	scanf("%d", &n);

	for (int i = 1; i <= n; ++ i) {
		scanf("%d", &a[i]);
		vv.pb(a[i]);
	}
	sort(vv.begin(), vv.end());
	int who = vv[(int)vv.size() / 2];

	vv.resize((unique(vv.begin(), vv.end()) - vv.begin()));
	for (int i = 0; i < (int)vv.size(); ++ i) {
		q.push(vv[i]);
		was[vv[i]] = 1;
	}

	while ((int)vv.size() < 2 * n) {
		ss = 0;
		while (!q.empty()) {
			int who = q.front();
			q.pop();
			if (!was[who - 1]) {
				cur[++ss] = who - 1;
			}
			if (!was[who + 1]) {
				cur[++ss] = who + 1;
			}
		}
		for (int i = 1; i <= ss; ++ i) {
			if (!was[cur[i]]) {
				was[cur[i]] = 1;
				vv.pb(cur[i]);
				q.push(cur[i]);
			}
		}
	}

	for (int i = -3000; i <= 3000; ++ i) {
		if (!was[who + i]) {
			was[who + i] = 1;
			vv.pb(who + i);
		}
	}

	for (int i = 1; i <= n; ++ i) {
		for (int j = -200; j <= 200; ++ j) {
			if (!was[a[i] + j]) {
				was[a[i] + j] = 1;
				vv.pb(a[i] + j);
			}
		}
	}

	sort(vv.begin(), vv.end());
	int sz = (int)vv.size();

	for (int i = 0; i < sz; ++ i) {
		now[i] = INF;
		old[i] = abs(a[1] - vv[i]);
//		cout << vv[i] << " ";
	}
//	cout << endl;

	for (int i = 2; i <= n; ++ i) {
		ll mn = INF;
		for (int j = 0; j < sz; ++ j) {
			now[j] = min(now[j], mn + abs(a[i] - vv[j]));
			mn = min(mn, old[j]);
		}
		for (int j = 0; j < sz; ++ j) {
			old[j] = now[j];
			now[j] = INF;
		}
	}

	ll ans = INF;

	for (int i = 0; i < sz; ++ i) ans = min(ans, old[i]);

	cout << ans;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <ctime>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <unordered_map>
using namespace std;
#define fname ""
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define inf 1000000000
#define INF 1000000000000000000ll
const int N = 100500;
int n, a[N];
vector <int> vv;
unordered_map <int, int> was;
queue <int> q;
int cur[N], ss = 0;

ll now[N], old[N];

int main() {
	#ifndef ONLINE_JUDGE
    freopen(fname"in", "r", stdin);
    freopen(fname"out", "w", stdout);
	#endif

	scanf("%d", &n);

	for (int i = 1; i <= n; ++ i) {
		scanf("%d", &a[i]);
		vv.pb(a[i]);
	}
	sort(vv.begin(), vv.end());

	vv.resize((unique(vv.begin(), vv.end()) - vv.begin()));

	for (int i = 0; i < (int)vv.size(); ++ i) {
		q.push(vv[i]);
		was[vv[i]] = 1;
	}

	while ((int)vv.size() < 10 * n) {
		ss = 0;
		while (!q.empty()) {
			int who = q.front();
			q.pop();
			if (!was[who - 1]) {
				cur[++ss] = who - 1;
			}
			if (!was[who + 1]) {
				cur[++ss] = who + 1;
			}
		}
		for (int i = 1; i <= ss; ++ i) {
			if (!was[cur[i]]) {
				was[cur[i]] = 1;
				vv.pb(cur[i]);
				q.push(cur[i]);
			}
		}
	}

	sort(vv.begin(), vv.end());
	int sz = (int)vv.size();

	for (int i = 0; i < sz; ++ i) {
		now[i] = INF;
		old[i] = abs(a[1] - vv[i]);
//		cout << vv[i] << " ";
	}
//	cout << endl;

	for (int i = 2; i <= n; ++ i) {
		ll mn = INF;
		for (int j = 0; j < sz; ++ j) {
			now[j] = min(now[j], mn + abs(a[i] - vv[j]));
			mn = min(mn, old[j]);
		}
		for (int j = 0; j < sz; ++ j) {
			old[j] = now[j];
			now[j] = INF;
		}
	}

	ll ans = INF;

	for (int i = 0; i < sz; ++ i) ans = min(ans, old[i]);

	cout << ans;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <ctime>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <unordered_map>
using namespace std;
#define fname ""
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define inf 1000000000
#define INF 1000000000000000000ll
const int N = 100500;
int n, a[N];
vector <int> vv;
unordered_map <int, int> was;
queue <int> q;
int cur[N], ss = 0;

ll now[N], old[N];

int main() {
	#ifndef ONLINE_JUDGE
    freopen(fname"in", "r", stdin);
    freopen(fname"out", "w", stdout);
	#endif

	scanf("%d", &n);

	for (int i = 1; i <= n; ++ i) {
		scanf("%d", &a[i]);
		vv.pb(a[i]);
	}
	sort(vv.begin(), vv.end());

	vv.resize((unique(vv.begin(), vv.end()) - vv.begin()));

	for (int i = 0; i < (int)vv.size(); ++ i) {
		q.push(vv[i]);
		was[vv[i]] = 1;
	}

	while ((int)vv.size() < 2 * n) {
		ss = 0;
		while (!q.empty()) {
			int who = q.front();
			q.pop();
			if (!was[who - 1]) {
				cur[++ss] = who - 1;
			}
			if (!was[who + 1]) {
				cur[++ss] = who + 1;
			}
		}
		for (int i = 1; i <= ss; ++ i) {
			if (!was[cur[i]]) {
				was[cur[i]] = 1;
				vv.pb(cur[i]);
				q.push(cur[i]);
			}
		}
	}

	sort(vv.begin(), vv.end());
	int sz = (int)vv.size();

	for (int i = 0; i < sz; ++ i) {
		now[i] = INF;
		old[i] = abs(a[1] - vv[i]);
//		cout << vv[i] << " ";
	}
//	cout << endl;

	for (int i = 2; i <= n; ++ i) {
		ll mn = INF;
		for (int j = 0; j < sz; ++ j) {
			now[j] = min(now[j], mn + abs(a[i] - vv[j]));
			mn = min(mn, old[j]);
		}
		for (int j = 0; j < sz; ++ j) {
			old[j] = now[j];
			now[j] = INF;
		}
	}

	ll ans = INF;

	for (int i = 0; i < sz; ++ i) ans = min(ans, old[i]);

	cout << ans;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;

int a[3010];
ll b[3010];
const ll inf=1LL<<60;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) b[i]=a[i]-a[i-1];
    b[1]=b[n+1]=inf;
    ll ans=0;
    for(int i=1;i<n;i++){
        for(int j=1;j<=2+(n-2)/2;j++){
            int k;
            ll mx;
            if(b[j]>1){
                k=j-i;
                if(k>=2&&k<=n&&b[k]<=0){
                    mx=min(b[j]-1,1-b[k]);
                    b[j]-=mx,b[k]+=mx;
                    ans+=mx*i;
                }

            }

        }
        for(int j=n+1;j>=2+(n-2)/2;j--){
            int k;
            ll mx;
            if(b[j]>1){
                k=j+i;
                if(k>=2&&k<=n&&b[k]<=0){
                    mx=min(b[j]-1,1-b[k]);
                    //cout<<mx<<"+++"<<endl;
                    b[j]-=mx,b[k]+=mx;
                    ans+=mx*i;
                }

            }

        }

        for(int j=1;j<=n+1;j++){
            int k;
            ll mx;
            if(b[j]>1){
                k=j-i;
                if(k>=2&&k<=n&&b[k]<=0){
                    mx=min(b[j]-1,1-b[k]);
                    b[j]-=mx,b[k]+=mx;
                    ans+=mx*i;
                }

            }

        }
        for(int j=n+1;j>=1;j--){
            int k;
            ll mx;
            if(b[j]>1){
                k=j+i;
                if(k>=2&&k<=n&&b[k]<=0){
                    mx=min(b[j]-1,1-b[k]);
                    //cout<<mx<<"+++"<<endl;
                    b[j]-=mx,b[k]+=mx;
                    ans+=mx*i;
                }

            }

        }
    }

    cout<<ans<<endl;

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;

int a[3010];
ll b[3010];
const ll inf=1LL<<60;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) b[i]=a[i]-a[i-1];
    b[1]=b[n+1]=inf;
    ll ans=0;
    for(int i=1;i<n;i++){
        for(int j=1;j<=n+1;j++){
            int k,mx;
            if(b[j]>1){
                k=j+i;
                if(k>=2&&k<=n&&b[k]<=0){
                    mx=min(b[j]-1,1-b[k]);
                    //cout<<mx<<"+++"<<endl;
                    b[j]-=mx,b[k]+=mx;
                    ans+=mx*i;
                }
                k=j-i;
                if(k>=2&&k<=n&&b[k]<=0){
                    mx=min(b[j]-1,1-b[k]);
                    b[j]-=mx,b[k]+=mx;
                    ans+=mx*i;
                }

            }

        }
    }

    cout<<ans<<endl;

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;

int a[3010];
ll b[3010];
ll dp[3010];
const ll inf=1LL<<60;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i],a[i]-=i;
    for(int i=1;i<=n;i++) b[i]=a[i];
    sort(b+1,b+n+1);
    ll ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            dp[j]+=abs(a[i]-b[j]);
            if(j>1) dp[j]=min(dp[j],dp[j-1]);
        }
    }

    cout<<dp[n]<<endl;

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;

int a[3010];
ll b[3010];
const ll inf=1LL<<60;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) b[i]=a[i]-a[i-1];
    b[1]=b[n+1]=inf;
    ll ans=0;
    for(int i=2;i<=n;i++){
        int j=1;
        while(b[i]<=0){
            if(b[i-j]>1&&b[i]<=0){
                ll mx=min(b[i-j]-1,1-b[i]);
                b[i]+=mx,b[i-j]-=mx;
                ans+=mx*j;
            }
            if(b[i+j]>1&&b[i]<=0){
                ll mx=min(b[i+j]-1,1-b[i]);
                b[i]+=mx,b[i+j]-=mx;
                ans+=mx*j;
            }
            j++;
        }
    }
    cout<<ans<<endl;

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;

int a[3010];
ll b[3010];
const ll inf=1LL<<60;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) b[i]=a[i]-a[i-1];
    b[1]=b[n+1]=inf;
    ll ans=0;
    for(int i=2;i<=n;i++){
        int j=1;
        while(b[i]<=0){
            if(b[i-j]>1){
                int mx=min(b[i-j]-1,1-b[i]);
                b[i]+=mx,b[i-j]-=mx;
                ans+=(ll)mx*j;
            }
            if(b[i+j]>1){
                int mx=min(b[i+j]-1,1-b[i]);
                b[i]+=mx,b[i+j]-=mx;
                ans+=(ll)mx*j;
            }
            j++;
        }
    }
    cout<<ans<<endl;

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;

int a[3010];
ll b[3010];
const ll inf=1LL<<60;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) b[i]=a[i]-a[i-1];
    b[1]=b[n+1]=inf;
    ll ans=0;
    for(int i=1;i<n;i++){
        for(int j=1;j<=n+1;j++){
            int k;
            ll mx;
            if(b[j]>1){
                k=j-i;
                if(k>=2&&k<=n&&b[k]<=0){
                    mx=min(b[j]-1,1-b[k]);
                    b[j]-=mx,b[k]+=mx;
                    ans+=mx*i;
                }

            }

        }
        for(int j=n+1;j>=1;j--){
            int k;
            ll mx;
            if(b[j]>1){
                k=j+i;
                if(k>=2&&k<=n&&b[k]<=0){
                    mx=min(b[j]-1,1-b[k]);
                    //cout<<mx<<"+++"<<endl;
                    b[j]-=mx,b[k]+=mx;
                    ans+=mx*i;
                }

            }

        }
    }

    cout<<ans<<endl;

	return 0;
}


 /*triskelion*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

int main()
{
//ios_base::sync_with_stdio(false);
//cin.tie(0);
//cout.tie(0);
ll n,t,i,ans=0;
priority_queue<int> Q;
scanf("%lld%lld",&n,&t);
Q.push(t);
for(i=1;i<n;i++)
{
    scanf("%lld",&t);
    t-=i;
    Q.push(t);
    if(Q.top()>t)
    {
        ans+=Q.top()-t;
        Q.pop();
        Q.push(t);
    }
}
printf("%lld",ans);
return 0;
}


 /*triskelion*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n,t,i,ans=0;
priority_queue<int> Q;
scanf("%lld%lld",&n,&t);
Q.push(t);
for(i=1;i<n;i++)
{
    scanf("%lld",&t);
    t-=i;
    Q.push(t);
    if(Q.top()>t)
    {
        ans+=Q.top()-t;
        Q.pop();
        Q.push(t);
    }
}
printf("%lld",ans);
return 0;
}


 /*triskelion*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n,t,ans=0;
priority_queue<int> Q;
scanf("%d%d",&n,&t);
Q.push(t);
for(i=1;i<n;i++)
{
    scanf("%d", &t);
    t-=i;
    Q.push(t);
    if(Q.top()>t)
    {
        ans+=Q.top()-t;
        Q.pop();
        Q.push(t);
    }
}
printf("%lld",ans);
return 0;
}


 /*triskelion*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

ll n,a[3002];

ll rec(ll i,ll prev)
{
    ll ans=INT_MAX;

    if(i==n)
    return 0;
    else
    {
        if(a[i]<=prev)
            ans=abs(prev+1-a[i])+rec(i+1,(prev+1));
        else if(a[i]>prev)
        {
            for(ll j=a[i];j>prev;j--)
                ans=min(abs(j-a[i])+rec(i+1,j),ans);
        }
        return ans;
    }
}

int main()
{
ios_base::sync_with_stdio(false);
//cin.tie(0);
//cout.tie(0);
ll i,ans=0,j=0,ansp=INT_MAX;
memset(a,0,sizeof(a));
cin>>n;
for(i=0;i<n;i++)
    cin>>a[i];
j=a[0];
ll count=0;
while(1)
{
    ans=abs(j-a[0])+rec(1,j);
    j--;
    count++;
    /*cout<<ans<<"\n";
    if(count==5)
        break;
    */
    if(ans<ansp)
        ansp=ans;
    else if(ans>=ansp)
        break;
}
cout<<ansp;
return 0;
}