stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
//In the name of God

#include<bits/stdc++.h>

#define int long long



using namespace std;



const int N = 1e5 + 10 , LG = 22;

int n , q , l , x[N] , sp[N][LG];



int32_t main(){

        ios_base::sync_with_stdio(false);

        cin.tie(0);

        cout.tie(0);

        cin >> n;

        for(int i=0 ; i < n ; i++)

                cin >> x[i];

        cin >> l;

        for(int i=0 ; i < n ; i++)

                sp[i][0] = upper_bound(x , x + n , x[i] + l) - x - 1;

        for(int j=1 ; j < LG ; j++)

                for(int i=0 ; i < n ; i++)

                        sp[i][j] = sp[sp[i][j-1]][j-1];

        cin >> q;

        while(q--){

                int a , b;

                cin >> a >> b;

                if(a > b)

                        swap(a , b);

                a-- , b--;

                int res = 0;

                for(int i=LG-1 ; ~i ; --i)

                        if(sp[a][i] < b)

                                a = sp[a][i] , res |= (1<<i);

                cout << ++res << '\n';

        }

        return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.354104479605417x):
#include <cmath>

#include <cstdio>

#include <cstring>

#include <algorithm>

using std::min; using std::max;

using std::swap; using std::sort;

using std::upper_bound;

typedef long long ll;



template<typename T>

void read(T &x) {

	int flag = 1; x = 0; char ch = getchar();

	while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }

	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();

	x *= flag;

}



const int _ = 1e5 + 10, __ = 18;

int n, m, q, x[_], fa[__][_], Log[_], pw[_];



int main () {

	read(n), Log[0] = -1, pw[0] = 1;

	for(int i = 1; i <= n; ++i) read(x[i]);

	read(m), read(q);

	for(int i = 1; i <= n; ++i)

		Log[i] = Log[i >> 1] + 1, pw[i] = min(_, pw[i - 1] * 2);

	for(int i = 1; i <= n; ++i)

		fa[0][i] = upper_bound(x + 1, x + n + 1, x[i] + m) - x - 1;

	for(int i = 1; i <= Log[n]; ++i)

		for(int j = 1; j <= n; ++j)

			fa[i][j] = fa[i - 1][fa[i - 1][j]];

	for(int i = 1; i <= q; ++i) {

		int x, y; read(x), read(y);

		if(x > y) swap(x, y);

		if(x == y) { printf("%d\n", 0); continue; }

		int now = x, ret = 0;

		for(int j = Log[n]; j >= 0; --j)

			if(fa[j][now] < y) ret += pw[j], now = fa[j][now];

		printf("%d\n", ret + 1);

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define MOD 1000000007

#define INF 1061109567

#define pb push_back

#define in(s) freopen(s,"r",stdin);

#define out(s) freopen(s,"w",stdout);

#define fi first

#define se second

#define bw(i,r,l) for (int i=r-1;i>=l;i--)

#define fw(i,l,r) for (int i=l;i<r;i++)

#define fa(i,x) for (auto i:x)

using namespace std;

const int N=1e5+5;

int n,L,q,x[N],sp[N][20];

int get(int x,int y) {

	int ans=1;

	bw (i,18,0) if (sp[x][i]!=-1&&sp[x][i]<y) x=sp[x][i],ans+=(1<<i);

	return ans;

}

signed main() {

	//in("aome.inp");

	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	cin>>n;

	fw (i,0,n) cin>>x[i];

	cin>>L>>q;

	memset(sp,-1,sizeof(sp));

	fw (i,0,n) sp[i][0]=upper_bound(x,x+n,x[i]+L)-x-1;

	fw (j,1,18) fw (i,0,n) if (sp[i][j-1]!=-1) sp[i][j]=sp[sp[i][j-1]][j-1];

	while (q--) {

		int a,b; 

		cin>>a>>b;

		if (a>b) swap(a,b);

		cout<<get(a-1,b-1)<<"\n";

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 49.62178866909846x):
#include <cmath>

#include <cstdio>

#include <cstring>

#include <algorithm>

using std::min; using std::max;

using std::swap; using std::sort;

using std::upper_bound;

typedef long long ll;



template<typename T>

void read(T &x) {

	int flag = 1; x = 0; char ch = getchar();

	while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }

	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();

	x *= flag;

}



const int _ = 1e5 + 10, __ = 18;

int n, m, q, x[_], fa[__][_], Log[_], pw[_];



int main () {

	read(n), Log[0] = -1, pw[0] = 1;

	for(int i = 1; i <= n; ++i) read(x[i]);

	read(m), read(q);

	for(int i = 1; i <= n; ++i)

		Log[i] = Log[i >> 1] + 1, pw[i] = min(_, pw[i - 1] * 2);

	for(int i = 1; i <= n; ++i)

		fa[0][i] = upper_bound(x + 1, x + n + 1, x[i] + m) - x - 1;

	for(int i = 1; i <= Log[n]; ++i)

		for(int j = 1; j <= n; ++j)

			fa[i][j] = fa[i - 1][fa[i - 1][j]];

	for(int i = 1; i <= q; ++i) {

		int x, y; read(x), read(y);

		if(x > y) swap(x, y);

		if(x == y) { printf("%d\n", 0); continue; }

		int now = x, ret = 0;

		for(int j = Log[n]; j >= 0; --j)

			if(fa[j][now] < y) ret += pw[j], now = fa[j][now];

		printf("%d\n", ret + 1);

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

#define int long long

#define pb push_back

int n, q;



long long x[100005], l, y[100005][20];

vector<int> vec;



signed main() {

    cin.tie(0), ios::sync_with_stdio(0);

    cin >> n;

    for(int i = 1; i <= n; i++){

        cin >> x[i];

        vec.pb(x[i]);

    }

    vec.pb(-1);

    sort(vec.begin(), vec.end());

    cin >> l;

    cin >> q;

    for(int i = 1; i <= n; i++){

        int it = upper_bound(vec.begin(), vec.end(), x[i] + l) - vec.begin() - 1;

        y[i][0] = it;

    }

    for(int i = 1; i <= 18; i++){

        for(int j = 1;j <= n; j++)

            y[j][i] = y[y[j][i - 1]][i - 1];

    }

    while(q--){

        int a, b, sum = 0;

        cin >> a >> b;

        if(a == b){

            cout << sum << "\n";

            continue;

        }

        if(b < a)

            swap(a, b);

        for(int i = 18; i >= 0; i--){

            if(y[a][i] < b){

                a = y[a][i];

                sum += (1 << i);

            }

        }

        sum++;

        cout << sum << "\n";

    }

}




// Faster C++ solution for the same problem (measured speedup: 5.366851651200179x):
#include <cmath>

#include <cstdio>

#include <cstring>

#include <algorithm>

using std::min; using std::max;

using std::swap; using std::sort;

using std::upper_bound;

typedef long long ll;



template<typename T>

void read(T &x) {

	int flag = 1; x = 0; char ch = getchar();

	while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }

	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();

	x *= flag;

}



const int _ = 1e5 + 10, __ = 18;

int n, m, q, x[_], fa[__][_], Log[_], pw[_];



int main () {

	read(n), Log[0] = -1, pw[0] = 1;

	for(int i = 1; i <= n; ++i) read(x[i]);

	read(m), read(q);

	for(int i = 1; i <= n; ++i)

		Log[i] = Log[i >> 1] + 1, pw[i] = min(_, pw[i - 1] * 2);

	for(int i = 1; i <= n; ++i)

		fa[0][i] = upper_bound(x + 1, x + n + 1, x[i] + m) - x - 1;

	for(int i = 1; i <= Log[n]; ++i)

		for(int j = 1; j <= n; ++j)

			fa[i][j] = fa[i - 1][fa[i - 1][j]];

	for(int i = 1; i <= q; ++i) {

		int x, y; read(x), read(y);

		if(x > y) swap(x, y);

		if(x == y) { printf("%d\n", 0); continue; }

		int now = x, ret = 0;

		for(int j = Log[n]; j >= 0; --j)

			if(fa[j][now] < y) ret += pw[j], now = fa[j][now];

		printf("%d\n", ret + 1);

	}

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

using namespace std;

const int magic=307;

int n,x[111111],l,q,a,b,nxt[111111],bignxt[111111],pos,ans;

int main()

{

	scanf("%d",&n);

	for (int i=1;i<=n;i++) scanf("%d",&x[i]);

	scanf("%d",&l);

	pos=n;

	for (int i=n;i>=1;i--)

	{

		while(pos>=1 && x[pos]-x[i]>l) pos--;

		nxt[i]=pos;

	}

	for (int i=1;i<=n;i++)

	{

		pos=i;

		for (int j=1;j<=magic;j++)

		{

			pos=nxt[pos];

		}

		bignxt[i]=pos;

	}

	scanf("%d",&q);

	while(q--)

	{

		scanf("%d%d",&a,&b);

		if (a>b) swap(a,b);

		ans=0;

		while(bignxt[a]<b) 

		{

			ans+=magic;

			a=bignxt[a];

		}

		while(nxt[a]<b) 

		{

			ans++;

			a=nxt[a];

		}

		if (a!=b) ans++;

		printf("%d\n",ans);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.230212086473358x):
#include <cmath>

#include <cstdio>

#include <cstring>

#include <algorithm>

using std::min; using std::max;

using std::swap; using std::sort;

using std::upper_bound;

typedef long long ll;



template<typename T>

void read(T &x) {

	int flag = 1; x = 0; char ch = getchar();

	while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }

	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();

	x *= flag;

}



const int _ = 1e5 + 10, __ = 18;

int n, m, q, x[_], fa[__][_], Log[_], pw[_];



int main () {

	read(n), Log[0] = -1, pw[0] = 1;

	for(int i = 1; i <= n; ++i) read(x[i]);

	read(m), read(q);

	for(int i = 1; i <= n; ++i)

		Log[i] = Log[i >> 1] + 1, pw[i] = min(_, pw[i - 1] * 2);

	for(int i = 1; i <= n; ++i)

		fa[0][i] = upper_bound(x + 1, x + n + 1, x[i] + m) - x - 1;

	for(int i = 1; i <= Log[n]; ++i)

		for(int j = 1; j <= n; ++j)

			fa[i][j] = fa[i - 1][fa[i - 1][j]];

	for(int i = 1; i <= q; ++i) {

		int x, y; read(x), read(y);

		if(x > y) swap(x, y);

		if(x == y) { printf("%d\n", 0); continue; }

		int now = x, ret = 0;

		for(int j = Log[n]; j >= 0; --j)

			if(fa[j][now] < y) ret += pw[j], now = fa[j][now];

		printf("%d\n", ret + 1);

	}

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



int p[100001][17],a[100001];

int A,B;



bool check(int x){

	int tmp=B,stp=0;

	while(x){

		if(x&1)	tmp=p[tmp][stp];

		stp++;

		x>>=1;

	}

	return tmp<=A;



}



int main(){

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	int n,L,k;

	cin>>n;

	for(int i=1;i<=n;i++)

		cin>>a[i];

	int tmp=n;

	cin>>L>>k;

	for(int i=n;i>=1;i--){

		while(tmp>0&&a[i]-a[tmp]<=L)

			tmp--;

		p[i][0]=tmp+1;

	}

	for(int j=1;j<=16;j++)

		for(int i=1;i<=n;i++)

			p[i][j]=p[p[i][j-1]][j-1];

	for(int i=1;i<=k;i++){

		cin>>A>>B;

		if(A>B)	swap(A,B);

		int l=0,r=100000;

		while(l<r){

			int mid=(l+r)/2;

			if(check(mid))

				r=mid;

			else

				l=mid+1;

		}

		cout<<l<<'\n';

	}

}


// Faster C++ solution for the same problem (measured speedup: 5.356421852240588x):
#include <cmath>

#include <cstdio>

#include <cstring>

#include <algorithm>

using std::min; using std::max;

using std::swap; using std::sort;

using std::upper_bound;

typedef long long ll;



template<typename T>

void read(T &x) {

	int flag = 1; x = 0; char ch = getchar();

	while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }

	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();

	x *= flag;

}



const int _ = 1e5 + 10, __ = 18;

int n, m, q, x[_], fa[__][_], Log[_], pw[_];



int main () {

	read(n), Log[0] = -1, pw[0] = 1;

	for(int i = 1; i <= n; ++i) read(x[i]);

	read(m), read(q);

	for(int i = 1; i <= n; ++i)

		Log[i] = Log[i >> 1] + 1, pw[i] = min(_, pw[i - 1] * 2);

	for(int i = 1; i <= n; ++i)

		fa[0][i] = upper_bound(x + 1, x + n + 1, x[i] + m) - x - 1;

	for(int i = 1; i <= Log[n]; ++i)

		for(int j = 1; j <= n; ++j)

			fa[i][j] = fa[i - 1][fa[i - 1][j]];

	for(int i = 1; i <= q; ++i) {

		int x, y; read(x), read(y);

		if(x > y) swap(x, y);

		if(x == y) { printf("%d\n", 0); continue; }

		int now = x, ret = 0;

		for(int j = Log[n]; j >= 0; --j)

			if(fa[j][now] < y) ret += pw[j], now = fa[j][now];

		printf("%d\n", ret + 1);

	}

	return 0;

}
// Slower C++ solution:
/*

  mail: mleautomaton@foxmail.com

  author: MLEAutoMaton

  This Code is made by MLEAutoMaton

*/

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<math.h>

#include<algorithm>

#include<queue>

#include<set>

#include<map>

#include<iostream>

using namespace std;

#define ll long long

#define REP(a,b,c) for(int a=b;a<=c;a++)

#define re register

#define int ll

#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)

inline int gi(){

	int f=1,sum=0;char ch=getchar();

	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}

	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}

	return f*sum;

}

const int N=100010;

int x[N],n,L,nxt[N][20];

signed main(){

	n=gi();

	for(int i=1;i<=n;i++)x[i]=gi();

	L=gi();

	for(int i=1;i<=n;i++){

		int l=i+1,r=n,ans=i;

		while(l<=r){

			int mid=(l+r)>>1;

			if(x[mid]-x[i]<=L){ans=mid;l=mid+1;}

			else r=mid-1;

		}

		nxt[i][0]=ans;

	}

	for(int j=1;j<=18;j++)

		for(int i=1;i<=n;i++)

			nxt[i][j]=nxt[nxt[i][j-1]][j-1];

	int q=gi();

	while(q--){

		int a=gi(),b=gi();if(a>b)swap(a,b);

		int ans=0;

		for(int i=18;~i;i--)

			if(nxt[a][i]<b){a=nxt[a][i];ans+=1ll<<i;}

		printf("%lld\n",ans+1);

	}

	return 0;

}



//ORz hyj

// Faster C++ solution for the same problem (measured speedup: 5.203999167281639x):
#include <cmath>

#include <cstdio>

#include <cstring>

#include <algorithm>

using std::min; using std::max;

using std::swap; using std::sort;

using std::upper_bound;

typedef long long ll;



template<typename T>

void read(T &x) {

	int flag = 1; x = 0; char ch = getchar();

	while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }

	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();

	x *= flag;

}



const int _ = 1e5 + 10, __ = 18;

int n, m, q, x[_], fa[__][_], Log[_], pw[_];



int main () {

	read(n), Log[0] = -1, pw[0] = 1;

	for(int i = 1; i <= n; ++i) read(x[i]);

	read(m), read(q);

	for(int i = 1; i <= n; ++i)

		Log[i] = Log[i >> 1] + 1, pw[i] = min(_, pw[i - 1] * 2);

	for(int i = 1; i <= n; ++i)

		fa[0][i] = upper_bound(x + 1, x + n + 1, x[i] + m) - x - 1;

	for(int i = 1; i <= Log[n]; ++i)

		for(int j = 1; j <= n; ++j)

			fa[i][j] = fa[i - 1][fa[i - 1][j]];

	for(int i = 1; i <= q; ++i) {

		int x, y; read(x), read(y);

		if(x > y) swap(x, y);

		if(x == y) { printf("%d\n", 0); continue; }

		int now = x, ret = 0;

		for(int j = Log[n]; j >= 0; --j)

			if(fa[j][now] < y) ret += pw[j], now = fa[j][now];

		printf("%d\n", ret + 1);

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define MOD 1000000007

#define INF 1061109567

#define pb push_back

#define in(s) freopen(s,"r",stdin);

#define out(s) freopen(s,"w",stdout);

#define fi first

#define se second

#define bw(i,r,l) for (int i=r-1;i>=l;i--)

#define fw(i,l,r) for (int i=l;i<r;i++)

#define fa(i,x) for (auto i:x)

using namespace std;

const int N=1e5+5;

int n,L,q,x[N],sp[N][20];

int get(int x,int y) {

	int ans=1;

	bw (i,18,0) if (sp[x][i]!=-1&&sp[x][i]<y) x=sp[x][i],ans+=(1<<i);

	return ans;

}

signed main() {

	//in("aome.inp");

	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	cin>>n;

	fw (i,0,n) cin>>x[i];

	cin>>L>>q;

	memset(sp,-1,sizeof(sp));

	fw (i,0,n) sp[i][0]=upper_bound(x,x+n,x[i]+L)-x-1;

	fw (j,1,18) fw (i,0,n) if (sp[i][j-1]!=-1) sp[i][j]=sp[sp[i][j-1]][j-1];

	while (q--) {

		int a,b; 

		cin>>a>>b;

		if (a>b) swap(a,b);

		cout<<get(a-1,b-1)<<"\n";

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 9.45711049434884x):
#include <iostream> 

#include <cstdio> 

#include <cstdlib> 

#include <cstring> 

#include <cmath> 

#include <algorithm> 

using namespace std; 

inline int gi() { 

    register int data = 0, w = 1;

    register char ch = 0;

    while (!isdigit(ch) && ch != '-') ch = getchar(); 

    if (ch == '-') w = -1, ch = getchar(); 

    while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar(); 

    return w * data; 

} 

const int MAX_N = 1e5 + 5; 

int N, L, a[MAX_N], f[17][MAX_N]; 



int main () { 

	N = gi(); for (int i = 1; i <= N; i++) a[i] = gi();

	L = gi(); 

	for (int i = 1; i <= N; i++) f[0][i] = upper_bound(&a[i + 1], &a[N + 1], a[i] + L) - a - 1; 

	for (int i = 1; i < 17; i++) 

		for (int j = 1; j <= N; j++) f[i][j] = f[i - 1][f[i - 1][j]]; 

	int Q = gi(); 

	while (Q--) { 

		int l = gi(), r = gi(); 

		if (l > r) swap(l, r); 

		int ans = 0; 

		for (int i = 16; ~i; i--) if (f[i][l] < r) l = f[i][l], ans |= (1 << i); 

		printf("%d\n", ans + 1); 

	} 

    return 0; 

}
// Slower C++ solution:
//In the name of God

#include<bits/stdc++.h>

#define int long long



using namespace std;



const int N = 1e5 + 10 , LG = 22;

int n , q , l , x[N] , sp[N][LG];



int32_t main(){

        ios_base::sync_with_stdio(false);

        cin.tie(0);

        cout.tie(0);

        cin >> n;

        for(int i=0 ; i < n ; i++)

                cin >> x[i];

        cin >> l;

        for(int i=0 ; i < n ; i++)

                sp[i][0] = upper_bound(x , x + n , x[i] + l) - x - 1;

        for(int j=1 ; j < LG ; j++)

                for(int i=0 ; i < n ; i++)

                        sp[i][j] = sp[sp[i][j-1]][j-1];

        cin >> q;

        while(q--){

                int a , b;

                cin >> a >> b;

                if(a > b)

                        swap(a , b);

                a-- , b--;

                int res = 0;

                for(int i=LG-1 ; ~i ; --i)

                        if(sp[a][i] < b)

                                a = sp[a][i] , res |= (1<<i);

                cout << ++res << '\n';

        }

        return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.214571098878156x):
#include <cstdio>

#include <algorithm> 



const int MAXN = 1e5 + 1;



int n, l, q, x[MAXN];



int f[MAXN][31];

void prework() {

	for (int i = 1; i <= n; ++i) {

		int pos = std :: upper_bound(x + 1, x + n + 1, x[i] + l) - x - 1;

		f[i][0] = x[i] + l >= x[n] ? n : pos;

	}

	for (int j = 1; j <= 30; ++j) for (int i = 1; i <= n; ++i) f[i][j] = f[f[i][j - 1]][j - 1];

}



int main() {

	scanf("%d", &n);

	for (int i = 1; i <= n; ++i) scanf("%d", &x[i]);

	scanf("%d%d", &l, &q);

	prework();

	while (q--) {

		int a, b; scanf("%d%d", &a, &b);

		if (a > b) std :: swap(a, b);

		int p = a, ans = 0;

		for (int j = 30; ~j; --j) if (f[p][j] < b) ans += (1 << j), p = f[p][j];

		printf("%d\n", ans + 1);

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define MOD 1000000007

#define INF 1061109567

#define pb push_back

#define in(s) freopen(s,"r",stdin);

#define out(s) freopen(s,"w",stdout);

#define fi first

#define se second

#define bw(i,r,l) for (int i=r-1;i>=l;i--)

#define fw(i,l,r) for (int i=l;i<r;i++)

#define fa(i,x) for (auto i:x)

using namespace std;

const int N=1e5+5;

int n,L,q,x[N],sp[N][20];

int get(int x,int y) {

	int ans=1;

	bw (i,18,0) if (sp[x][i]!=-1&&sp[x][i]<y) x=sp[x][i],ans+=(1<<i);

	return ans;

}

signed main() {

	//in("aome.inp");

	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	cin>>n;

	fw (i,0,n) cin>>x[i];

	cin>>L>>q;

	memset(sp,-1,sizeof(sp));

	fw (i,0,n) sp[i][0]=upper_bound(x,x+n,x[i]+L)-x-1;

	fw (j,1,18) fw (i,0,n) if (sp[i][j-1]!=-1) sp[i][j]=sp[sp[i][j-1]][j-1];

	while (q--) {

		int a,b; 

		cin>>a>>b;

		if (a>b) swap(a,b);

		cout<<get(a-1,b-1)<<"\n";

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 48.32859464251434x):
#include <cstdio>

#include <algorithm> 



const int MAXN = 1e5 + 1;



int n, l, q, x[MAXN];



int f[MAXN][31];

void prework() {

	for (int i = 1; i <= n; ++i) {

		int pos = std :: upper_bound(x + 1, x + n + 1, x[i] + l) - x - 1;

		f[i][0] = x[i] + l >= x[n] ? n : pos;

	}

	for (int j = 1; j <= 30; ++j) for (int i = 1; i <= n; ++i) f[i][j] = f[f[i][j - 1]][j - 1];

}



int main() {

	scanf("%d", &n);

	for (int i = 1; i <= n; ++i) scanf("%d", &x[i]);

	scanf("%d%d", &l, &q);

	prework();

	while (q--) {

		int a, b; scanf("%d%d", &a, &b);

		if (a > b) std :: swap(a, b);

		int p = a, ans = 0;

		for (int j = 30; ~j; --j) if (f[p][j] < b) ans += (1 << j), p = f[p][j];

		printf("%d\n", ans + 1);

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

#define int long long

#define pb push_back

int n, q;



long long x[100005], l, y[100005][20];

vector<int> vec;



signed main() {

    cin.tie(0), ios::sync_with_stdio(0);

    cin >> n;

    for(int i = 1; i <= n; i++){

        cin >> x[i];

        vec.pb(x[i]);

    }

    vec.pb(-1);

    sort(vec.begin(), vec.end());

    cin >> l;

    cin >> q;

    for(int i = 1; i <= n; i++){

        int it = upper_bound(vec.begin(), vec.end(), x[i] + l) - vec.begin() - 1;

        y[i][0] = it;

    }

    for(int i = 1; i <= 18; i++){

        for(int j = 1;j <= n; j++)

            y[j][i] = y[y[j][i - 1]][i - 1];

    }

    while(q--){

        int a, b, sum = 0;

        cin >> a >> b;

        if(a == b){

            cout << sum << "\n";

            continue;

        }

        if(b < a)

            swap(a, b);

        for(int i = 18; i >= 0; i--){

            if(y[a][i] < b){

                a = y[a][i];

                sum += (1 << i);

            }

        }

        sum++;

        cout << sum << "\n";

    }

}




// Faster C++ solution for the same problem (measured speedup: 5.226986066281889x):
#include <cstdio>

#include <algorithm> 



const int MAXN = 1e5 + 1;



int n, l, q, x[MAXN];



int f[MAXN][31];

void prework() {

	for (int i = 1; i <= n; ++i) {

		int pos = std :: upper_bound(x + 1, x + n + 1, x[i] + l) - x - 1;

		f[i][0] = x[i] + l >= x[n] ? n : pos;

	}

	for (int j = 1; j <= 30; ++j) for (int i = 1; i <= n; ++i) f[i][j] = f[f[i][j - 1]][j - 1];

}



int main() {

	scanf("%d", &n);

	for (int i = 1; i <= n; ++i) scanf("%d", &x[i]);

	scanf("%d%d", &l, &q);

	prework();

	while (q--) {

		int a, b; scanf("%d%d", &a, &b);

		if (a > b) std :: swap(a, b);

		int p = a, ans = 0;

		for (int j = 30; ~j; --j) if (f[p][j] < b) ans += (1 << j), p = f[p][j];

		printf("%d\n", ans + 1);

	}

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

using namespace std;

const int magic=307;

int n,x[111111],l,q,a,b,nxt[111111],bignxt[111111],pos,ans;

int main()

{

	scanf("%d",&n);

	for (int i=1;i<=n;i++) scanf("%d",&x[i]);

	scanf("%d",&l);

	pos=n;

	for (int i=n;i>=1;i--)

	{

		while(pos>=1 && x[pos]-x[i]>l) pos--;

		nxt[i]=pos;

	}

	for (int i=1;i<=n;i++)

	{

		pos=i;

		for (int j=1;j<=magic;j++)

		{

			pos=nxt[pos];

		}

		bignxt[i]=pos;

	}

	scanf("%d",&q);

	while(q--)

	{

		scanf("%d%d",&a,&b);

		if (a>b) swap(a,b);

		ans=0;

		while(bignxt[a]<b) 

		{

			ans+=magic;

			a=bignxt[a];

		}

		while(nxt[a]<b) 

		{

			ans++;

			a=nxt[a];

		}

		if (a!=b) ans++;

		printf("%d\n",ans);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.093907466881775x):
#include <cstdio>

#include <algorithm> 



const int MAXN = 1e5 + 1;



int n, l, q, x[MAXN];



int f[MAXN][31];

void prework() {

	for (int i = 1; i <= n; ++i) {

		int pos = std :: upper_bound(x + 1, x + n + 1, x[i] + l) - x - 1;

		f[i][0] = x[i] + l >= x[n] ? n : pos;

	}

	for (int j = 1; j <= 30; ++j) for (int i = 1; i <= n; ++i) f[i][j] = f[f[i][j - 1]][j - 1];

}



int main() {

	scanf("%d", &n);

	for (int i = 1; i <= n; ++i) scanf("%d", &x[i]);

	scanf("%d%d", &l, &q);

	prework();

	while (q--) {

		int a, b; scanf("%d%d", &a, &b);

		if (a > b) std :: swap(a, b);

		int p = a, ans = 0;

		for (int j = 30; ~j; --j) if (f[p][j] < b) ans += (1 << j), p = f[p][j];

		printf("%d\n", ans + 1);

	}

	return 0;

}