stablegradients/pie-gem5-pairs huggingface dataset:
// 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: 4.880814217242457x):
#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;

}
// 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: 4.890862812895352x):
#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;

}
// 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: 41.41320847482043x):
#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;

}
// 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: 8.642674903884991x):
#include <cstdio>

#include <iostream>

#include <cstring>

#include <algorithm>

#define rg register

using namespace std;

inline int read(){

	rg int x=0; 

	rg char c=getchar();

	while(c<'0'||c>'9') 

		c=getchar();

	while(c>='0'&&c<='9'){

		x=(x<<1)+(x<<3)+(c^48);

		c=getchar();

	}

	return x;

}

const int N=1e5+5;

int l,n,q,x[N],a,b;

int pre[N][20],ans;

inline int get_power(int k){

	int ans=1;

	while(k--) 

		ans<<=1;

	return ans;

}

void prework(){

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

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

	for(rg int i(1);i<20;++i)

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

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

}

int main(){

	n=read();

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

		x[i]=read();

	l=read();

	prework();

	q=read();

	while(q--){

		a=read();

		b=read();

		ans=1;

		if(a>b)

			swap(a,b);

		--b; --a;

		while(pre[a][0]<b)

			for(rg int i(0);i<20;++i)

				if(pre[a][i]>=b){

					a=pre[a][i-1];

					ans+=get_power(i-1);

					break;

				}

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

	}

	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.344491301408481x):
#include <cstdio>

#include <algorithm>

#define ll long long

using namespace std;

inline int read(){

	int x=0,f=1;char c=getchar();

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

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

	return x*f;

}

const int maxn(1e5+5);

ll n,l,q;

ll s[maxn],f[maxn][35];



void swap(ll &a,ll &b){int t=a;a=b;b=t;}

void init(){

	n=read();

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

	l=read(),q=read();

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

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

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

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

}



signed main(){

	init();

	while (q--){

		int a=read(),b=read(),tot=0;

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

		int v=a;

		for (int i=30;~i;--i){

			if (f[v][i]<b){

				tot+=1<<i;

				v=f[v][i];

			}

		}

		printf("%d\n",tot+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.2369462369102315x):
#include <cstdio>

#include <algorithm>

#define ll long long

using namespace std;

inline int read(){

	int x=0,f=1;char c=getchar();

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

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

	return x*f;

}

const int maxn(1e5+5);

ll n,l,q;

ll s[maxn],f[maxn][35];



void swap(ll &a,ll &b){int t=a;a=b;b=t;}

void init(){

	n=read();

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

	l=read(),q=read();

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

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

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

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

}



signed main(){

	init();

	while (q--){

		int a=read(),b=read(),tot=0;

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

		int v=a;

		for (int i=30;~i;--i){

			if (f[v][i]<b){

				tot+=1<<i;

				v=f[v][i];

			}

		}

		printf("%d\n",tot+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.2477280353660625x):
#include <cstdio>

#include <algorithm>

#define ll long long

using namespace std;

inline int read(){

	int x=0,f=1;char c=getchar();

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

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

	return x*f;

}

const int maxn(1e5+5);

ll n,l,q;

ll s[maxn],f[maxn][35];



void swap(ll &a,ll &b){int t=a;a=b;b=t;}

void init(){

	n=read();

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

	l=read(),q=read();

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

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

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

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

}



signed main(){

	init();

	while (q--){

		int a=read(),b=read(),tot=0;

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

		int v=a;

		for (int i=30;~i;--i){

			if (f[v][i]<b){

				tot+=1<<i;

				v=f[v][i];

			}

		}

		printf("%d\n",tot+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.43495216728841x):
#include <cstdio>

#include <algorithm>

#define ll long long

using namespace std;

inline int read(){

	int x=0,f=1;char c=getchar();

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

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

	return x*f;

}

const int maxn(1e5+5);

ll n,l,q;

ll s[maxn],f[maxn][35];



void swap(ll &a,ll &b){int t=a;a=b;b=t;}

void init(){

	n=read();

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

	l=read(),q=read();

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

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

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

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

}



signed main(){

	init();

	while (q--){

		int a=read(),b=read(),tot=0;

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

		int v=a;

		for (int i=30;~i;--i){

			if (f[v][i]<b){

				tot+=1<<i;

				v=f[v][i];

			}

		}

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

	}

	return 0; 

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

#include <iostream>

#include <cstring>

#include <algorithm>

#define rg register

using namespace std;

inline int read(){

	rg int x=0; 

	rg char c=getchar();

	while(c<'0'||c>'9') 

		c=getchar();

	while(c>='0'&&c<='9'){

		x=(x<<1)+(x<<3)+(c^48);

		c=getchar();

	}

	return x;

}

const int N=1e5+5;

int l,n,q,x[N],a,b;

int pre[N][20],ans;

inline int get_power(int k){

	int ans=1;

	while(k--) 

		ans<<=1;

	return ans;

}

void prework(){

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

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

	for(rg int i(1);i<20;++i)

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

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

}

int main(){

	n=read();

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

		x[i]=read();

	l=read();

	prework();

	q=read();

	while(q--){

		a=read();

		b=read();

		ans=1;

		if(a>b)

			swap(a,b);

		--b; --a;

		while(pre[a][0]<b)

			for(rg int i(0);i<20;++i)

				if(pre[a][i]>=b){

					a=pre[a][i-1];

					ans+=get_power(i-1);

					break;

				}

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

	}

	return 0;

}

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

#include <algorithm>

#define ll long long

using namespace std;

inline int read(){

	int x=0,f=1;char c=getchar();

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

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

	return x*f;

}

const int maxn(1e5+5);

ll n,l,q;

ll s[maxn],f[maxn][35];



void swap(ll &a,ll &b){int t=a;a=b;b=t;}

void init(){

	n=read();

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

	l=read(),q=read();

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

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

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

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

}



signed main(){

	init();

	while (q--){

		int a=read(),b=read(),tot=0;

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

		int v=a;

		for (int i=30;~i;--i){

			if (f[v][i]<b){

				tot+=1<<i;

				v=f[v][i];

			}

		}

		printf("%d\n",tot+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: 8.58942700579428x):
#include<bits/stdc++.h>

#define ll long long

using namespace std;

int a[100005];

int dp[100005][50];



ll read()

{

	ll sum=0;int f=1,c=getchar();

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

	while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}

	return sum*f;

}



int main()

{

    int n=read();

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

        scanf("%d",&a[i]);

    int l=read(),q=read();

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

    {

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

        if(a[i]+l>=a[n])

            dp[i][0]=n;

        else

            dp[i][0]=id;

    }

     

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

    {

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

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

    }

    while(q--)

    {

        int s=read(),e=read();

        if(e<s)

            swap(s,e);  

        long long ans=0;

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

        {

            if(dp[s][i]<e)

            {

                ans=ans+(1ll<<i);

                s=dp[s][i];

            }

        }

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

    }

    return 0;

}