stablegradients/pie-gem5-pairs huggingface dataset:
// 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.216828078437431x):
#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:
/*

  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.068377682889879x):
#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> 

#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; 

} 

// Faster C++ solution for the same problem (measured speedup: 5.11029184563228x):
#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: 9.493418393128094x):
#include <bits/stdc++.h>

using namespace std;

const int maxn=1e5+10;

int n,a,b,p[maxn],l,Q;

int f[maxn][35];

int main()

{

    scanf("%d",&n);

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

    scanf("%d",&l);

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

     {

        int idx=upper_bound(p+1,p+1+n,p[i]+l)-p-1;

        if(p[i]+l>=p[n]) f[i][0]=n;

        else f[i][0]=idx;

    }

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

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

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

    scanf("%d",&Q);

    while(Q--)

    {

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

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

        int cur=a,ans=0;

        for (int i=30; i>=0; i--)

        {

            if(f[cur][i]<b)

            {

                ans+=(1<<i);

                cur = f[cur][i];

            }

        }

        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: 9.51553349176704x):
/*    三玖天下第一！！！  */

#include<bits/stdc++.h>

using namespace std;

const int ng=30,maxn=1e5;

int n,L,x[maxn+5]={},f[ng+5][maxn+5]={};

inline int dread()

{

	int x=0;bool f=1;char ch=getchar();

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

	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}

	return f?x:-x;

}

inline void in(){n=dread();for(int i=1;i<=n;i++) x[i]=dread();L=dread();}

inline void work()

{

	for(int i=1;i<=n;i++) f[0][i]=upper_bound(x+i,x+1+n,x[i]+L)-x-1;

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

}

inline void out()

{

	for(int q=dread(),a,b,ans;q;q--)

	{

		a=dread();b=dread();ans=0;if(a>b) swap(a,b);

		for(int i=ng;i>=0;i--) if(f[i][a]<b) ans+=(1<<i),a=f[i][a];

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

	}

}

int main(){in();work();out();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.49149172277158x):
#include <bits/stdc++.h>

#define sc(x) scanf("%d", &x)

#define pr(x) printf("%d\n", x)

#define lowbit(x) (x & -x)

#define ll long long

#define N 100010

#define memset(x) memset(x, 0, sizeof(x))

using namespace std;

int n, a[N], f[N][35], l, q;

int main()

{

	//freopen("trav.in", "r", stdin);

	//freopen("trav.out", "w", stdout);

	sc(n);

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

	sc(a[i]);

	sc(l);

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

	{

		int id = (int)(upper_bound(a + 1, a + n + 1, a[i] + l) - a - 1);

		f[i][0] = id;

	}

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

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

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

	sc(q);

	while (q--)

	{

		int x, y;

		sc(x);

		sc(y);

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

		int sum = 1;

		for (int i = 30; i >= 0; i--)

		if (f[x][i] < y)

		{

			sum += 1 << i;

			x = f[x][i];

		}

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

	}

	return 0;

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

 

using namespace std;

 

const int MAX_N = 100000;

const int MAX_LOG_N = 17;

 

int m[MAX_LOG_N][MAX_N];

 

int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);

	int n;

	cin >> n;

	vector<int> x(n);

	for (int i = 0; i < n; i++) cin >> x[i];

	int L, q;

	cin >> L >> q;

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

		int nex = upper_bound(x.begin() + i, x.end(), x[i] + L) - x.begin();

		nex--;

		m[0][i] = nex;

	}

 

	for (int i = 0; i + 1 < MAX_LOG_N; i++) {

		for (int j = 0; j < n; j++) {

			if (m[i][j] == n) m[i + 1][j] = n;

			else m[i + 1][j] = m[i][m[i][j]];

		}

	}

 

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

		int a, b;

		cin >> a >> b;

		a--;

		b--;

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

		int ng = 0, ok = n - 1;

		while (ok - ng > 1) {

			int mid = (ok + ng) / 2;

			int cur = a;

			for (int i = 0; i < MAX_LOG_N; i++) {

				if (mid & (1 << i)) cur = m[i][cur]; 

			}

			if (cur >= b) ok = mid;

			else ng = mid;

		}

		cout << ok << endl;

	}

	return 0;

}

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

#include <algorithm>

#include <vector>

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



inline int read()

{

	int data = 0, w = 1; char ch = getchar();

	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();

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

	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();

	return data * w;

}



const int N(1e5 + 10), LogN(17);

int n, L, Q, A[N], f[LogN][N], stk[N], H, T;



int main()

{

	n = read(), H = 1, T = 0;

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

	L = read(), Q = read(), f[0][n] = n;

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

	{

		while (H <= T && A[stk[H]] - A[i] > L) ++H;

		if (H <= T) f[0][i] = stk[H];

		stk[++T] = i;

	}

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

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

	for (int a, b, ans; Q--; )

	{

		a = read(), b = read(), ans = 0; if (a > b) std::swap(a, b);

		for (int i = LogN - 1; ~i; i--) if (f[i][a] && f[i][a] < b)

			ans += (1 << i), a = f[i][a];

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

	}

	return 0;

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



# define pb push_back

# define fr first

# define sc second

# define mk make_pair



using namespace std;



const int inf = 1e9 + 7;

const int N = 1e5 + 5;



typedef long long ll;



int n, a[N], q, L, up[19][N];



int main()

{

      cin >> n;



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

            cin >> a[i];



      cin >> L;



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

      {

            int l = i, r = n, d = a[i] + L;

            while(r - l > 1)

            {

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

                  if(a[md] > d)

                        r = md;

                  else

                        l = md;

            }

            if(a[r] <= d)

                  l = r;



            up[0][i] = l;

      }



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

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

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



      cin >> q;



      while(q --)

      {

            int l, r;

            cin >> l >> r;

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

            int ans = 1;

            for(int i = 17; i >= 0; i --)

                  if(up[i][l] && up[i][l] < r)

                  {

                        ans += (1 << i);

                        l = up[i][l];

                  }



            cout << ans << endl;

      }

}


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

#include <algorithm>

#include <vector>

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



inline int read()

{

	int data = 0, w = 1; char ch = getchar();

	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();

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

	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();

	return data * w;

}



const int N(1e5 + 10), LogN(17);

int n, L, Q, A[N], f[LogN][N], stk[N], H, T;



int main()

{

	n = read(), H = 1, T = 0;

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

	L = read(), Q = read(), f[0][n] = n;

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

	{

		while (H <= T && A[stk[H]] - A[i] > L) ++H;

		if (H <= T) f[0][i] = stk[H];

		stk[++T] = i;

	}

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

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

	for (int a, b, ans; Q--; )

	{

		a = read(), b = read(), ans = 0; if (a > b) std::swap(a, b);

		for (int i = LogN - 1; ~i; i--) if (f[i][a] && f[i][a] < b)

			ans += (1 << i), a = f[i][a];

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

	}

	return 0;

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

#include <time.h>

#include <tr1/unordered_map>

#include <tr1/unordered_set>

using namespace std::tr1;

using namespace std;

/* cau troi cho Garena nhap de con Bach */

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

#define fi first

#define se second

#define pb push_back

#define mp make_pair

#define int long long

#define endl '\n'

#define inf 0x3f3f3f3f

#define lb lower_bound

#define pob pop_back

#define ub upper_bound

#define ite ::iterator

#define db(x) {cout <<"#db " << x << endl;}

#define here() {cout <<"here \n";}

#define mod 1000000007

typedef pair<int,int> ii;

typedef vector<int> vi;

typedef vector<ii> vii;

typedef vector<vi> vvi;

const int MOD = 1e9 + 7;

const int _MOD = 998244353;

const int N = 2e5 + 5;



int ST[N][20];

vi x;

int T[N];

int L,q,n;

int solve(int l,int r){

	if(l == r) return 0;

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

	l --, r--;

	int ans = 0;

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

		if(ST[l][i] < r){

			ans |= (1<<i);

			l = ST[l][i];

		}

	}

	return ans + 1;

}

signed main(){

	cin >> n ;

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

		int u;cin >> u;x.pb(u);

	}

	cin >> L >> q;//cout << endl;

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

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

			ST[j][i] = -1;

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

		vector<int>ite it = x.begin() + i;

		ST[i][0] = ub(it,x.end(),x[i] + L) - x.begin() - 1;

		//cout << ST[i][0] << " ";

	}

	//cout << endl;

	

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

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

			if(ST[i][j-1] != -1) ST[i][j] = ST[ST[i][j-1]][j-1];

	

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

		int a,b;cin >> a >> b;

		cout << solve(a,b) << endl;

	}

	return 0;

}


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

#include <algorithm>

#include <vector>

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



inline int read()

{

	int data = 0, w = 1; char ch = getchar();

	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();

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

	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();

	return data * w;

}



const int N(1e5 + 10), LogN(17);

int n, L, Q, A[N], f[LogN][N], stk[N], H, T;



int main()

{

	n = read(), H = 1, T = 0;

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

	L = read(), Q = read(), f[0][n] = n;

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

	{

		while (H <= T && A[stk[H]] - A[i] > L) ++H;

		if (H <= T) f[0][i] = stk[H];

		stk[++T] = i;

	}

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

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

	for (int a, b, ans; Q--; )

	{

		a = read(), b = read(), ans = 0; if (a > b) std::swap(a, b);

		for (int i = LogN - 1; ~i; i--) if (f[i][a] && f[i][a] < b)

			ans += (1 << i), a = f[i][a];

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

	}

	return 0;

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



using namespace std;



const int N = 1e5 + 5;

int sparse[N][18], n, a[N], l, q;



int get (int x, int y) {

    int ans = 1;

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

        if (sparse[x][i] != -1 && sparse[x][i] < y) {

            x = sparse[x][i];

            ans = ans + (1 << i);

        }

    }



    return ans;

}



int main(){

    scanf("%d", &n);

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

    scanf("%d", &l);

    scanf("%d", &q);



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

    for (int i = 0; i < n; i++) sparse[i][0] = upper_bound(a, a + n, a[i] + l) - a - 1;

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

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

            if (sparse[i][j - 1] != -1) sparse[i][j] = sparse[sparse[i][j - 1]][j - 1];

        }

    }



    while (q--) {

        int x, y;

        scanf("%d %d", &x, &y);

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

        printf("%d\n", get(x - 1, y - 1));

    }

    return 0;

}


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

#include <algorithm>

#include <vector>

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



inline int read()

{

	int data = 0, w = 1; char ch = getchar();

	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();

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

	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();

	return data * w;

}



const int N(1e5 + 10), LogN(17);

int n, L, Q, A[N], f[LogN][N], stk[N], H, T;



int main()

{

	n = read(), H = 1, T = 0;

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

	L = read(), Q = read(), f[0][n] = n;

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

	{

		while (H <= T && A[stk[H]] - A[i] > L) ++H;

		if (H <= T) f[0][i] = stk[H];

		stk[++T] = i;

	}

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

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

	for (int a, b, ans; Q--; )

	{

		a = read(), b = read(), ans = 0; if (a > b) std::swap(a, b);

		for (int i = LogN - 1; ~i; i--) if (f[i][a] && f[i][a] < b)

			ans += (1 << i), a = f[i][a];

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

	}

	return 0;

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

 

using namespace std;

 

const int MAX_N = 100000;

const int MAX_LOG_N = 17;

 

int m[MAX_LOG_N][MAX_N];

 

int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);

	int n;

	cin >> n;

	vector<int> x(n);

	for (int i = 0; i < n; i++) cin >> x[i];

	int L, q;

	cin >> L >> q;

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

		int nex = upper_bound(x.begin() + i, x.end(), x[i] + L) - x.begin();

		nex--;

		m[0][i] = nex;

	}

 

	for (int i = 0; i + 1 < MAX_LOG_N; i++) {

		for (int j = 0; j < n; j++) {

			if (m[i][j] == n) m[i + 1][j] = n;

			else m[i + 1][j] = m[i][m[i][j]];

		}

	}

 

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

		int a, b;

		cin >> a >> b;

		a--;

		b--;

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

		int ng = 0, ok = n - 1;

		while (ok - ng > 1) {

			int mid = (ok + ng) / 2;

			int cur = a;

			for (int i = 0; i < MAX_LOG_N; i++) {

				if (mid & (1 << i)) cur = m[i][cur]; 

			}

			if (cur >= b) ok = mid;

			else ng = mid;

		}

		cout << ok << endl;

	}

	return 0;

}

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

#include <cstdlib>

#include <cmath>

#include <ctime>

#include <algorithm>

#define inf 1e18

using namespace std;

typedef long long ll;

inline ll rd()

{

	ll x=0,p=1;

	char a=getchar();

	while((a<48||a>57)&&a!='-')a=getchar();

	if(a=='-')p=-p,a=getchar();

	while(a>47&&a<58)

	{

		x=(x<<1)+(x<<3)+(a&15);

		a=getchar();

	}

	return x*p;

}

inline void swap(ll &x,ll &y){ll t=x;x=y;y=t;}

const int N=100002;

ll n,l,q,d[N][40],a[N],lgn;

inline int div(ll k)

{

	int l=1,r=n,mid,ans;

	while(l<=r)

	{

		mid=(l+r)>>1;

		if(a[mid]>k)r=mid-1;

		else l=mid+1;

	}

	return r;

}

int main()

{

	n=rd();lgn=log2(n);

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

	l=rd();q=rd();

	for(int i=1;i<=n;i++)d[i][0]=div(a[i]+l);

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

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

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

	while(q--)

	{

		ll x,y,ans=0;

		x=rd();y=rd();

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

		for(int j=lgn;j>=0;j--)

			if(d[x][j]<y)x=d[x][j],ans+=(1<<j);

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

	}

	return 0;

}