#include <bits/stdc++.h>
#define ff first
#define ss second
typedef long long ll;
using namespace std;
int main(){
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> A(n), B(m);
    for(int i = 0 ; i < n ; i++){
        cin >> A[i];
    }
    for(int i = 0 ; i < m ; i++){
        cin >> B[i];
    }
    int j = 0;
    vector<pair<int, int> > ans;
    for(int i = 0 ; i < n ; i++){
        while(j < m and B[j] < A[i] - x){
            j++;
        }
        if(j >= m){
            break;
        }
        if(B[j] <= A[i] + y){
            ans.push_back({i + 1, j + 1});
            j++;
        }
    }
    cout << ans.size() << endl;
    for(int i = 0 ; i < ans.size(); i++){
        cout << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define INF numeric_limits<int>::max()
#define st string
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

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

/*
map<st, int>size;
map<st, st>parent;

st find_set(st v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void make_set(st v) {
    parent[v] = v;
    size[v] = 1;
}

void union_sets(st a, st b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (size[a] < size[b])
            swap(a, b);
        parent[b] = a;
        size[a] += size[b];
    }
}*/

int q[100005]; int b;
vector<int>ans;

void solve(){
    int n, m, x, k, y; cin >> n >> m >> x >> y;
    for(int i = 0; i < n; i++) {
        cin >> q[i];
    }
    k = 0;
    for(int i = 0; i < m ;i++) {
        cin >> b;
        while(k < n && q[k] + y < b){
            k+=1;
        }
        if((b >= q[k] - x) && k < n){
            ans.pb(k+1);
            ans.pb(i+1);
            k+=1;
        }
    }
    cout << (int) ans.size() / 2 << endl;
    int ix = 1;
    for(auto i : ans){
        cout << i << " ";
        if(ix%2==0) cout << endl;
        ix++;
    }
}

int main(){
    fastio
    solve();
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define INF numeric_limits<int>::max()
#define st string
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

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

/*
map<st, int>size;
map<st, st>parent;

st find_set(st v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void make_set(st v) {
    parent[v] = v;
    size[v] = 1;
}

void union_sets(st a, st b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (size[a] < size[b])
            swap(a, b);
        parent[b] = a;
        size[a] += size[b];
    }
}*/

int q[100005]; int b;
vector<int>ans;

void solve(){
    int n, m, x, k, y; cin >> n >> m >> x >> y;
    for(int i = 0; i < n; i++) {
        cin >> q[i];
    }
    for(int i = 0; i < m ;i++) {
        k = 0;
        cin >> b;
        while(k < n && q[k] + y < b){
            k+=1;
        }
        if((b >= q[k] - x) && k < n){
            ans.pb(k+1);
            ans.pb(i+1);
            k+=1;
        }
    }
    cout << (int) ans.size() / 2 << endl;
    int ix = 1;
    for(auto i : ans){
        cout << i << " ";
        if(ix%2==0) cout << endl;
        ix++;
    }
}

int main(){
    fastio
    solve();
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define INF numeric_limits<int>::max()
#define st string
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

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

const int MAX = 1e9;

int q[MAX]; int b;
vector<int>ans;

void solve(){
    int n, m, x, k, y; cin >> n >> m >> x >> y;
    for(int i = 0; i < n; i++) {
        cin >> q[i];
    }
    for(int i = 0; i < m ;i++) {
        k = 0;
        cin >> b;
        while(k < n && q[k] + y < b){
            k+=1;
        }
        if((b >= q[k] - x) && k < n){
            ans.pb(k+1);
            ans.pb(i+1);
            k+=1;
        }
    }
    cout << (int) ans.size() / 2 << endl;
    int ix = 1;
    for(auto i : ans){
        cout << i << " ";
        if(ix%2==0) cout << endl;
        ix++;
    }
}

int main(){
    fastio
    solve();
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define INF numeric_limits<int>::max()
#define st string
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

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

const int MAX = 1e8;

int q[MAX]; int b;
vector<int>ans;

void solve(){
    int n, m, x, k, y; cin >> n >> m >> x >> y;
    for(int i = 0; i < n; i++) {
        cin >> q[i];
    }
    for(int i = 0; i < m ;i++) {
        k = 0;
        cin >> b;
        while(k < n && q[k] + y < b){
            k+=1;
        }
        if((b >= q[k] - x) && k < n){
            ans.pb(k+1);
            ans.pb(i+1);
            k+=1;
        }
    }
    cout << (int) ans.size() / 2 << endl;
    int ix = 1;
    for(auto i : ans){
        cout << i << " ";
        if(ix%2==0) cout << endl;
        ix++;
    }
}

int main(){
    fastio
    solve();
    return 0;
}


#include <bits/stdc++.h>
#include<cmath>
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define ft first
#define sd second
#define pie 3.14159265359
using namespace std;

ll max(ll a,ll b){ return (a>b)?a:b; }
ll min(ll a,ll b){ return (a>b)?b:a; }
ll lcm(ll a,ll b){ return (a*b)/__gcd(a,b); }
ll gid(ll a,ll b){ if(a<0) return (a-(b+ a%b)); return (a- (a%b)); }
ll lid(ll a,ll b){ if(a<0) return(a- (a%b)); if(a%b==0) return a; else return (a+ (b- a%b)); }
void swap(ll &a,ll &b){ ll c; c=a; a=b; b=c; return; }

int main()
{
	ll n,m,x,y,i,j,k,d,f;
	cin>>n>>m>>x>>y;
	vector<pair<ll,ll>> c(n),e;
	vector<ll> b(m);
	for(i=0;i<n;i++)
	{
	    cin>>k;
	    c[i]=mp(k-x,k+y);
	}
	for(i=0;i<m;i++)
	    cin>>b[i];

	k=d=0;
	for(i=0;i<n;i++)
	{
	    for(j=d;j<m;j++)
        {
            if((c[i].ft<=b[j]) && (b[j]<=c[i].sd))
            {
                k++;
                d=j+1;
                e.pb(mp(i+1,j+1));
                break;
            }
            else if(b[j]>c[i].sd)
            {
                d=j;
                break;
            }
            else
                d=j+1;
        }
	}
	cout<<k<<"\n";
	for(i=0;i<k;i++)
	    cout<<e[i].ft<<" "<<e[i].sd<<"\n";
	return 0;
}


#include <bits/stdc++.h>
#include<cmath>
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define ft first
#define sd second
#define pie 3.14159265359
using namespace std;

ll max(ll a,ll b){ return (a>b)?a:b; }
ll min(ll a,ll b){ return (a>b)?b:a; }
ll lcm(ll a,ll b){ return (a*b)/__gcd(a,b); }
ll gid(ll a,ll b){ if(a<0) return (a-(b+ a%b)); return (a- (a%b)); }
ll lid(ll a,ll b){ if(a<0) return(a- (a%b)); if(a%b==0) return a; else return (a+ (b- a%b)); }
void swap(ll &a,ll &b){ ll c; c=a; a=b; b=c; return; }

int main()
{
	ll n,m,x,y,i,j,k,d;
	cin>>n>>m>>x>>y;
	vector<pair<ll,ll>> c(n),e;
	vector<ll> b(m);
	for(i=0;i<n;i++)
	{
	    cin>>k;
	    c[i]=mp(k-x,k+y);
	}
	for(i=0;i<m;i++)
	    cin>>b[i];

	k=d=0;
	for(i=0;i<n;i++)
	{
	    for(j=d;j<m;j++)
        {
            if((c[i].ft<=b[j]) && (b[j]<=c[i].sd))
            {
                k++;
                d=j+1;
                e.pb(mp(i+1,j+1));
                break;
            }
            else if(b[j]>c[i].sd)
                break;
        }
	}
	cout<<k<<"\n";
	for(i=0;i<k;i++)
	    cout<<e[i].ft<<" "<<e[i].sd<<"\n";
	return 0;
}


//
//  161A.cpp
//  OI
//
//  Created by Zhaohua Zheng on 21/4/18.
//  Copyright © 2018 Zhaohua Zheng. All rights reserved.
//

#include <stdio.h>
#include "bits/stdc++.h"
using namespace std;

const int MAX_N=1000010;
int n,m,x,y;
int i=0,j=0;
int a[MAX_N];
int b[MAX_N];
int c[MAX_N];
int d[MAX_N];

int main(){
    cin>>n>>m>>x>>y;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<m;i++) cin>>b[i];

    int k=0;
    for(i=j=0;i<n and j<m;){
        if(b[j]>=a[i] and b[j]<=a[i]+y){
            c[k]=++i;
            d[k++]=++j;
        }else if(b[j]<a[i]){
            j++;
        }else{
            i++;
        }
    }
    cout<<k<<endl;
    for(i=0;i<k;i++) cout<<c[i]<<" "<<d[i]<<endl;

    return 0;
}


//
//  161A.cpp
//  OI
//
//  Created by Zhaohua Zheng on 21/4/18.
//  Copyright © 2018 Zhaohua Zheng. All rights reserved.
//

#include <stdio.h>
#include "bits/stdc++.h"
using namespace std;

const int MAX_N=1000010;
int n,m,x,y;
int i,j;
int a[MAX_N];
int b[MAX_N];
int c[MAX_N];
int d[MAX_N];
int out[MAX_N];
int k=0;

int main(){
    cin>>n>>m>>x>>y;
    for(int i=0;i<n;i++)    cin>>a[i];
    for(int i=0;i<m;i++)    cin>>b[i];

    for(i=j=0;i<n and j<m;){
        if(a[i]>=b[j]-x and a[i]<=b[j]+y){
            c[k]=++i;
            d[k++]=++j;
        }else if(a[i]>=b[j]-x){
            j++;
        }else{
            i++;
        }
    }
    cout<<k<<endl;
    for (int i=0;i<k;i++)cout<<c[i]<<" "<<d[i]<<endl;

    return 0;
}


//
//  161A.cpp
//  OI
//
//  Created by Zhaohua Zheng on 21/4/18.
//  Copyright © 2018 Zhaohua Zheng. All rights reserved.
//

#include <stdio.h>
#include "bits/stdc++.h"
using namespace std;

const int MAX_N=1000010;
int n,m,x,y;
int i,j;
int a[MAX_N];
int b[MAX_N];
int c[MAX_N];
int d[MAX_N];
int out[MAX_N];
int k=0;

int main(){
    cin>>n>>m>>x>>y;
    for(int i=0;i<n;i++)    cin>>a[i];
    for(int i=0;i<m;i++)    cin>>b[i];

    for(i=j=0;i<n and j<m;){
        if(b[j]>=a[i]-x and b[j]<=a[i]+y){
            c[k]=++i;
            d[k++]=++j;
        }else if(b[j]<=a[i]+y){
            j++;
        }else{
            i++;
        }
    }
    cout<<k<<endl;
    for (int i=0;i<k;i++)cout<<c[i]<<" "<<d[i]<<endl;

    return 0;
}


//
//  161A.cpp
//  OI
//
//  Created by Zhaohua Zheng on 21/4/18.
//  Copyright © 2018 Zhaohua Zheng. All rights reserved.
//

#include <stdio.h>
#include "bits/stdc++.h"
using namespace std;

const int MAX_N=1000010;
int n,m,x,y;
int i=0,j=0;
int a[MAX_N];
int b[MAX_N];
int c[MAX_N];
int d[MAX_N];

int main(){
    cin>>n>>m>>x>>y;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<m;i++) cin>>b[i];

    int k=0;
    for(i=j=0;i<n and j<m;){
        if(b[j]>=a[i] and b[j]<=a[i]+y){
            c[k]=++i;
            d[k++]=++j;
        }else if(b[j]<a[i]){
            j++;
        }else{
            i++;
        }
    }
    for(i=0;i<k;i++) cout<<c[i]<<" "<<d[i];

    return 0;
}


// Author: Md Tareque Khan
// Problem: A. Dress'em in Vests! https://codeforces.com/problemset/problem/161/A
// Sat, 25 Apr 2020 02:38:17 +0530
// tags : <>
#include <iostream> // std::cin, std:;cout, std::fixed
#include <iomanip>  // std::setprecision
#include <bitset>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef string str;
typedef vector<int> vi;
typedef vector<string> vs;
typedef int64_t ll;
#define int ll

#define fastIo ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define prec cout << fixed << setprecision(11); cerr << fixed << setprecision(6);
#define newline cout << "\n";
#define pi acos(-1)

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define trav(a,x) for (auto& a: x)
#define read(vec) for (auto &x : vec) cin >> x;

#define debug(a) for(auto i : a) cerr << i << " "; newline;

void IOFiles() {
#ifdef LOCAL
    freopen("cf.161.A.cpp.in", "r", stdin);
    freopen("cf.161.A.cpp.out", "w", stdout);
#endif
}

// TO_STRING
#define ts to_string
template<class A, class B> str ts(pair<A,B> p);
str ts(bool b) { return b ? "true" : "false"; }
str ts(char c) { str s = ""; s += c; return s; }
str ts(str s) { return s; }
str ts(const char* s) { return (str)s; }
str ts(vector<bool> v) {
    bool fst = 1; str res = "{";
    FOR(i,0,sz(v)) {
        if (!fst) res += ", ";
        fst = 0; res += ts(v[i]);
    }
    res += "}"; return res;
}
template<size_t SZ> str ts(bitset<SZ> b) {
    str res = ""; FOR(i,0,SZ) res += char('0'+b[i]);
    return res; }
template<class T> str ts(T v) {
    bool fst = 1; str res = "{";
    for (const auto& x: v) {
        if (!fst) res += ", ";
        fst = 0; res += ts(x);
    }
    res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
    return "("+ts(p.f)+", "+ts(p.s)+")"; }

// DEBUG
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
    DBG(t...); }
#ifdef LOCAL
#define dbg(...) cerr << __LINE__ << ": [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) void(0)
#endif

int32_t main() {
	fastIo; prec; IOFiles();
	int n, m, x, y; cin >> n >> m >> x >> y;
	vector<int> preference(n); read(preference);
	vector<int> vestSize(m); read(vestSize);

	int i = 0; // preference pointer
	int j = 0; // vest size pointer
	vector<pair<int, int>> ans;
	while (i < n and j < m) {

		if (preference[i]-x <= vestSize[j]
			and preference[i]+y >= vestSize[j]) {
			ans.push_back(make_pair(i+1,j+1));
			i++;
			j++;
		} else if (preference[i] < vestSize[j]) {
			i++;
		} else {
			j++;
		}
	}
	cout << ans.size() << '\n';
	for (auto p : ans) {
		cout << p.first << ' ' << p.second << '\n';
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
	return 0;
}


// Author: Md Tareque Khan
// Problem: A. Dress'em in Vests! https://codeforces.com/problemset/problem/161/A
// Sat, 25 Apr 2020 02:38:17 +0530
// tags : <>
#include <iostream> // std::cin, std:;cout, std::fixed
#include <iomanip>  // std::setprecision
#include <bitset>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef string str;
typedef vector<int> vi;
typedef vector<string> vs;
typedef int64_t ll;
#define int ll

#define fastIo ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define prec cout << fixed << setprecision(11); cerr << fixed << setprecision(6);
#define newline cout << "\n";
#define pi acos(-1)

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define trav(a,x) for (auto& a: x)
#define read(vec) for (auto &x : vec) cin >> x;

#define debug(a) for(auto i : a) cerr << i << " "; newline;

void IOFiles() {
#ifdef LOCAL
    freopen("cf.161.A.cpp.in", "r", stdin);
    freopen("cf.161.A.cpp.out", "w", stdout);
#endif
}

// TO_STRING
#define ts to_string
template<class A, class B> str ts(pair<A,B> p);
str ts(bool b) { return b ? "true" : "false"; }
str ts(char c) { str s = ""; s += c; return s; }
str ts(str s) { return s; }
str ts(const char* s) { return (str)s; }
str ts(vector<bool> v) {
    bool fst = 1; str res = "{";
    FOR(i,0,sz(v)) {
        if (!fst) res += ", ";
        fst = 0; res += ts(v[i]);
    }
    res += "}"; return res;
}
template<size_t SZ> str ts(bitset<SZ> b) {
    str res = ""; FOR(i,0,SZ) res += char('0'+b[i]);
    return res; }
template<class T> str ts(T v) {
    bool fst = 1; str res = "{";
    for (const auto& x: v) {
        if (!fst) res += ", ";
        fst = 0; res += ts(x);
    }
    res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
    return "("+ts(p.f)+", "+ts(p.s)+")"; }

// DEBUG
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
    DBG(t...); }
#ifdef LOCAL
#define dbg(...) cerr << __LINE__ << ": [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) void(0)
#endif

int32_t main() {
	fastIo; prec; IOFiles();
	int n, m, x, y; cin >> n >> m >> x >> y;
	vector<int> preference(n); read(preference);
	vector<int> vestSize(m); read(vestSize);

	int perfect = 0;
	int i=0; // preference pointer
	int j = 0; // vest size pointer
	vector<pair<int, int>> ans;
	while (i < n && j < m) {

		if (preference[i] >= vestSize[j]-x
			&& preference[i] <= vestSize[j]+y) {
			ans.push_back(make_pair(i+1,j+1));
			perfect++;
			j++;
		} else if (preference[i] > vestSize[j]+y) {
			j++;
		}
		i++;
	}
	cout << ans.size() << '\n';
	for (auto p : ans) {
		cout << p.first << ' ' << p.second << '\n';
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
	return 0;
}


// Author: Md Tareque Khan
// Problem: A. Dress'em in Vests! https://codeforces.com/problemset/problem/161/A
// Sat, 25 Apr 2020 02:38:17 +0530
// tags : <>
#include <iostream> // std::cin, std:;cout, std::fixed
#include <iomanip>  // std::setprecision
#include <bitset>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef string str;
typedef vector<int> vi;
typedef vector<string> vs;
typedef int64_t ll;
#define int ll

#define fastIo ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define prec cout << fixed << setprecision(11); cerr << fixed << setprecision(6);
#define newline cout << "\n";
#define pi acos(-1)

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define trav(a,x) for (auto& a: x)
#define read(vec) for (auto &x : vec) cin >> x;

#define debug(a) for(auto i : a) cerr << i << " "; newline;

void IOFiles() {
#ifdef LOCAL
    freopen("cf.161.A.cpp.in", "r", stdin);
    freopen("cf.161.A.cpp.out", "w", stdout);
#endif
}

// TO_STRING
#define ts to_string
template<class A, class B> str ts(pair<A,B> p);
str ts(bool b) { return b ? "true" : "false"; }
str ts(char c) { str s = ""; s += c; return s; }
str ts(str s) { return s; }
str ts(const char* s) { return (str)s; }
str ts(vector<bool> v) {
    bool fst = 1; str res = "{";
    FOR(i,0,sz(v)) {
        if (!fst) res += ", ";
        fst = 0; res += ts(v[i]);
    }
    res += "}"; return res;
}
template<size_t SZ> str ts(bitset<SZ> b) {
    str res = ""; FOR(i,0,SZ) res += char('0'+b[i]);
    return res; }
template<class T> str ts(T v) {
    bool fst = 1; str res = "{";
    for (const auto& x: v) {
        if (!fst) res += ", ";
        fst = 0; res += ts(x);
    }
    res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
    return "("+ts(p.f)+", "+ts(p.s)+")"; }

// DEBUG
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
    DBG(t...); }
#ifdef LOCAL
#define dbg(...) cerr << __LINE__ << ": [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) void(0)
#endif

int32_t main() {
	fastIo; prec; IOFiles();
	int n, m, x, y; cin >> n >> m >> x >> y;
	vector<int> preference(n); read(preference);
	vector<int> vestSize(m); read(vestSize);

	int perfect = 0;
	int i=0; // preference pointer
	int j = 0; // vest size pointer
	vector<pair<int, int>> ans;
	while (i < n && j < m) {

		if (preference[i]-x >= vestSize[j]
			|| preference[i]+y <= vestSize[j]) {
			ans.push_back(make_pair(i+1,j+1));
			perfect++;
			j++;
		} else if (preference[i]+y > vestSize[j]) {
			j++;
		}
		i++;
	}
	cout << ans.size() << '\n';
	for (auto p : ans) {
		cout << p.first << ' ' << p.second << '\n';
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
	return 0;
}


#include<bits/stdc++.h>
#include <iostream>
#define fo(n) for(int i{0};i<n;i++)
#define lint long long int
#define pb push_back
using namespace std;

int main(int argc, const char * argv[]) {
    lint n,m,x,y;cin>>n>>m>>x>>y;
    vector<lint>a(n);vector<lint>b(m);
    fo(n)cin>>a.at(i);
    fo(m)cin>>b.at(i);
    vector<pair<int,int>>result;
    int i{0},j{0};
    for(i;i<n&&j<m;i++){
        while(j<m&&a.at(i)-x>b.at(j))j++;
        if(j<m&&a.at(i)+y>=b.at(j)&&a.at(i)-x<=b.at(j)){result.pb(make_pair(i+1,j+1));j++;}

    }
    cout<<result.size()<<endl;
    fo(result.size())cout<<result.at(i).first<<" "<<result.at(i).second<<endl;

        return 0;
}


#include<bits/stdc++.h>
#include <iostream>
#define fo(n) for(int i{0};i<n;i++)
#define lint long long int
#define pb push_back
using namespace std;

int main(int argc, const char * argv[]) {
    lint n,m,x,y;cin>>n>>m>>x>>y;
    vector<lint>a(n);vector<lint>b(m);
    fo(n)cin>>a.at(i);
    fo(m)cin>>b.at(i);
    vector<pair<int,int>>result;
    int i{0},j{0};
    for(i;i<n;i++){
        while(a.at(i)-x>b.at(j))j++;
        if(a.at(i)+y>=b.at(j)&&a.at(i)-x<=b.at(j)){result.pb(make_pair(i+1,j+1));j++;}

    }
    cout<<result.size()<<endl;
    fo(result.size())cout<<result.at(i).first<<" "<<result.at(i).second<<endl;

        return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
int vis[1000001];
int main()
{
   int n,m,k,i,j,x,y,a[100001],b[100001];
   vector<pair<int,int> > pr;
   cin>>n>>m>>x>>y;
   for(i=0;i<n;i++) cin>>a[i];
   for(i=0;i<m;i++) cin>>b[i];

   for(i=0,j=0;i<n&&j<m;){
      if(b[j]-x<=a[i]&&a[i]<=b[j]+y){
         pr.push_back({i+1,j+1});i++,j++;
      }
      else if(a[i]<b[j]-x) i++;
      else j++;
      cout<<i<<' '<<j<<endl;
   }
   int yy=pr.size();
   cout<<yy<<endl;
   for(i=0;i<yy;i++) printf("%d %d\n",pr[i].f,pr[i].s);
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
int vis[1000001];
int main()
{
   int n,m,k,i,j,x,y,a[100001],b[100001];
   vector<pair<int,int> > pr;
   cin>>n>>m>>x>>y;
   for(i=0;i<n;i++) cin>>a[i];
   for(i=0;i<m;i++) cin>>b[i];

   for(i=0,j=0;i<n&&j<m;){
      if(b[j]-x<=a[i]&&a[i]<=b[j]+y){
         pr.push_back({i+1,j+1});i++,j++;
      }
      else if(a[i]<b[j]-x) i++;
      else j++;
      //cout<<i<<' '<<j<<endl;
   }
   int yy=pr.size();
   cout<<yy<<endl;
   for(i=0;i<yy;i++) printf("%d %d\n",pr[i].f,pr[i].s);
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
int vis[1000001];
int main()
{
   int n,m,k,i,j,x,y,a[100001],b[100001];
   vector<pair<int,int> > pr;
   cin>>n>>m>>x>>y;
   for(i=0;i<n;i++) cin>>a[i];
   for(i=0;i<m;i++) cin>>b[i];

   for(i=0,j=0;i<n&&j<m;){
      if(a[i]-x<=b[j]&&b[j]<=a[i]+y){
         pr.push_back({i+1,j+1});i++,j++;
      }
      else if(b[j]<a[i]-x) j++;
      else i++;
      //cout<<i<<' '<<j<<endl;
   }
   int yy=pr.size();
   cout<<yy<<endl;
   for(i=0;i<yy;i++) printf("%d %d\n",pr[i].f,pr[i].s);
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define boostIO                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define MAXN 100005
typedef long long ll;
typedef pair<int, int> pii;

int n, m;
ll x, y;
ll a[MAXN], b[MAXN];
vector<pii> result;

signed main() {
    boostIO;

    cin >> n >> m >> x >> y;
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, m) cin >> b[i];

    int p1 = 0, p2 = 0;
    while (p1 < n and p2 < m) {
        while (p2 < m and a[p1] - x > b[p2]) {
            p2++;
        }
        if (p2 < m and b[p2] <= a[p1] + y) {
            result.push_back({p1 + 1, p2 + 1});
            p1++, p2++;
            continue;
        }
        p1++;
    }
    cout << result.size() << endl;
    for (auto ele : result) {
        cout << ele.first << " " << ele.second << endl;
    }
    return 0;
}
// XD


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define boostIO                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define MAXN 100005
typedef long long ll;
typedef pair<int, int> pii;

struct soldier {
    ll l, r;
    int v = -1, id;
    bool operator<(soldier const& other) {
        return l < other.l;
    }
} var;
vector<soldier> army;

signed main() {
    boostIO;
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        var.l = a - x;
        var.r = a + y;
        var.id = i + 1;
        army.push_back(var);
    }
    pii vest[m];
    for (int i = 0; i < m; i++) {
        cin >> vest[i].first;
        vest[i].second = i + 1;
    }
    sort(vest, vest + m);
    vector<int> arr(m);
    for (int i = 0; i < m; i++) {
        arr[i] = vest[i].first;
    }
    sort(army.begin(), army.end());
    auto it = arr.begin();
    int flag = 0;
    for (int i = 0; i < n; i++) {
        auto liv = upper_bound(it, arr.end(), army[i].l - 1);
        if (liv == arr.end() or *liv > army[i].r) continue;
        it = liv;
        it++;
        flag++;
        army[i].v = vest[liv - arr.begin()].second;
    }
    cout << flag << endl;
    for (int i = 0; i < n; i++) {
        if (army[i].v != -1) {
            cout << army[i].id << " " << army[i].v << endl;
        }
    }
    return 0;
}
// XD


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define boostIO                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define MAXN 100005
typedef long long ll;
typedef pair<int, int> pii;

int n, m;
ll x, y;
ll a[MAXN], b[MAXN];
vector<pii> result;

signed main() {
    boostIO;

    cin >> n >> m >> x >> y;
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, m) cin >> b[i];

    int p1 = 0, p2 = 0;
    while (p1 < n and p2 < m) {
        while (p2 < m and a[p1] - x > b[p2]) {
            p2++;
        }
        if (p2 < m and b[p2] <= a[p1] + y) {
            result.push_back({p1 + 1, p2 + 1});
            p1++, p2++;
            continue;
        }
        p1++;
    }
    cout << result.size() << endl;
    for (auto ele : result) {
        cout << ele.first << " " << ele.second << endl;
    }
    return 0;
}
// XD


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
const int N=1e6+5;
ll max(ll a,ll b)
{
    if(a>=b)
        return a;
    else
        return b;
}
ll min(ll a,ll b)
{
    if(a>=b)
        return b;
    else
        return a;
}
ll diff(ll a,ll b)
{
    if(a>=b)
        return a-b;
    else
        return b-a;
}
ll mod(ll a)
{
    if(a>=0)
        return a;
    else
        return -a;
}
void pairsort(ll a[], ll b[], ll n)
{
    pair<ll, ll> pairt[n];

    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }

    sort(pairt, pairt + n);

    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll rev(ll n)
{
    ll ans=0;
    while(n)
    {
        ans=ans*10+n%10;
        n=n/10;
    }
    return ans;
}
int isPrime(int n)
{
    for(int i=2;i*i<=n;i++)
        if(n%i==0)
            return 0;
    return 1;
}
long long C(int n, int r) {
    if(r > n - r) r = n - r;
    long long ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
vector<pair<int,int>> a;
vector<int> b;
int n,m,x,y;
int BinSearch(int x)
{
    int low=0,high=a.size()-1,mid,mid1=99999999999;
    while(low<=high)
    {
        mid=(low+high)/2;
        if(a[mid].first>=x)
        {
            high=mid-1;
            if(mid<mid1)
                mid1=mid;
        }
        else if(a[mid].first<x)
        {
            low=mid+1;
        }
    }
    return mid1;
}
int32_t main()
{
    IOS;
    cin>>n>>m>>y>>x;
    for(int i=0;i<n;i++)
    {
        int p;
        cin>>p;
        a.push_back(make_pair(p,i));
    }
    for(int i=0;i<m;i++)
    {
        int p;
        cin>>p;
        b.push_back(p);
    }
    vector<int> v1,v2;
    for(int i=0;i<m;i++)
    {
        int k=BinSearch(b[i]-x);
        if(k<=a.size()-1&&a[k].first<=b[i]+y)
        {
            v1.push_back(a[k].second+1);
            v2.push_back(i+1);
            a.erase(a.begin()+k);
            if(a.size()==0)
                break;
        }
    }
    /*for(int i=0;i<v1.size();i++)
        cout<<v1[i]<<" ";
    cout<<endl;*/
    cout<<v1.size()<<endl;
    for(int i=0;i<v1.size();i++)
        cout<<v1[i]<<" "<<v2[i]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
const int N=1e6+5;
ll max(ll a,ll b)
{
    if(a>=b)
        return a;
    else
        return b;
}
ll min(ll a,ll b)
{
    if(a>=b)
        return b;
    else
        return a;
}
ll diff(ll a,ll b)
{
    if(a>=b)
        return a-b;
    else
        return b-a;
}
ll mod(ll a)
{
    if(a>=0)
        return a;
    else
        return -a;
}
void pairsort(ll a[], ll b[], ll n)
{
    pair<ll, ll> pairt[n];

    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }

    sort(pairt, pairt + n);

    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll rev(ll n)
{
    ll ans=0;
    while(n)
    {
        ans=ans*10+n%10;
        n=n/10;
    }
    return ans;
}
int isPrime(int n)
{
    for(int i=2;i*i<=n;i++)
        if(n%i==0)
            return 0;
    return 1;
}
long long C(int n, int r) {
    if(r > n - r) r = n - r;
    long long ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
vector<pair<int,int>> a;
vector<int> b;
int n,m,x,y;
int BinSearch(int x)
{
    int low=0,high=a.size()-1,mid,mid1=99999999999;
    while(low<=high)
    {
        mid=(low+high)/2;
        if(a[mid].first>=x)
        {
            high=mid-1;
            if(mid<mid1)
                mid1=mid;
        }
        else if(a[mid].first<x)
        {
            low=mid+1;
        }
    }
    return mid1;
}
int32_t main()
{
    IOS;
    cin>>n>>m>>x>>y;
    for(int i=0;i<n;i++)
    {
        int p;
        cin>>p;
        a.push_back(make_pair(p,i));
    }
    for(int i=0;i<m;i++)
    {
        int p;
        cin>>p;
        b.push_back(p);
    }
    vector<int> v1,v2;
    for(int i=0;i<m;i++)
    {
        int k=BinSearch(b[i]-x);
        if(k<=a.size()-1&&a[k].first<=b[i]+y)
        {
            v1.push_back(a[k].second+1);
            v2.push_back(i+1);
            a.erase(a.begin()+k);
            if(a.size()==0)
                break;
        }
    }
    /*for(int i=0;i<v1.size();i++)
        cout<<v1[i]<<" ";
    cout<<endl;*/
    cout<<v1.size()<<endl;
    for(int i=0;i<v1.size();i++)
        cout<<v1[i]<<" "<<v2[i]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
const int N=1e6+5;
ll max(ll a,ll b)
{
    if(a>=b)
        return a;
    else
        return b;
}
ll min(ll a,ll b)
{
    if(a>=b)
        return b;
    else
        return a;
}
ll diff(ll a,ll b)
{
    if(a>=b)
        return a-b;
    else
        return b-a;
}
ll mod(ll a)
{
    if(a>=0)
        return a;
    else
        return -a;
}
void pairsort(ll a[], ll b[], ll n)
{
    pair<ll, ll> pairt[n];

    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }

    sort(pairt, pairt + n);

    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll rev(ll n)
{
    ll ans=0;
    while(n)
    {
        ans=ans*10+n%10;
        n=n/10;
    }
    return ans;
}
int isPrime(int n)
{
    for(int i=2;i*i<=n;i++)
        if(n%i==0)
            return 0;
    return 1;
}
long long C(int n, int r) {
    if(r > n - r) r = n - r;
    long long ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
vector<pair<int,int>> a;
vector<int> b;
int n,m,x,y,l=0;
int BinSearch(int x)
{
    int low=l,high=a.size()-1,mid,mid1=99999999999;
    while(low<=high)
    {
        mid=(low+high)/2;
        if(a[mid].first>=x)
        {
            high=mid-1;
            if(mid<mid1)
                mid1=mid;
        }
        else if(a[mid].first<x)
        {
            low=mid+1;
        }
    }
    return mid1;
}
int32_t main()
{
    IOS;
    cin>>n>>m>>x>>y;
    for(int i=0;i<n;i++)
    {
        int p;
        cin>>p;
        a.push_back(make_pair(p,i));
    }
    for(int i=0;i<m;i++)
    {
        int p;
        cin>>p;
        b.push_back(p);
    }
    vector<int> v1,v2;
    int s=a.size()-1;
    for(int i=0;i<m;i++)
    {
        int k=BinSearch(b[i]-y);
        if(k<=s&&a[k].first<=b[i]+x)
        {
            v1.push_back(a[k].second+1);
            v2.push_back(i+1);
            l=k+1;
            a[k].first=-1;
        }
    }
    /*for(int i=0;i<v1.size();i++)
        cout<<v1[i]<<" ";
    cout<<endl;*/
    cout<<v1.size()<<endl;
    for(int i=0;i<v1.size();i++)
        cout<<v1[i]<<" "<<v2[i]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
const int N=1e6+5;
ll max(ll a,ll b)
{
    if(a>=b)
        return a;
    else
        return b;
}
ll min(ll a,ll b)
{
    if(a>=b)
        return b;
    else
        return a;
}
ll diff(ll a,ll b)
{
    if(a>=b)
        return a-b;
    else
        return b-a;
}
ll mod(ll a)
{
    if(a>=0)
        return a;
    else
        return -a;
}
void pairsort(ll a[], ll b[], ll n)
{
    pair<ll, ll> pairt[n];

    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }

    sort(pairt, pairt + n);

    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll rev(ll n)
{
    ll ans=0;
    while(n)
    {
        ans=ans*10+n%10;
        n=n/10;
    }
    return ans;
}
int isPrime(int n)
{
    for(int i=2;i*i<=n;i++)
        if(n%i==0)
            return 0;
    return 1;
}
long long C(int n, int r) {
    if(r > n - r) r = n - r;
    long long ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
vector<pair<int,int>> a;
vector<int> b;
int n,m,x,y;
int BinSearch(int x)
{
    int low=0,high=a.size()-1,mid,mid1=99999999999;
    while(low<=high)
    {
        mid=(low+high)/2;
        if(a[mid].first>=x)
        {
            high=mid-1;
            if(mid<mid1)
                mid1=mid;
        }
        else if(a[mid].first<x)
        {
            low=mid+1;
        }
    }
    return mid1;
}
int32_t main()
{
    IOS;
    cin>>n>>m>>x>>y;
    for(int i=0;i<n;i++)
    {
        int p;
        cin>>p;
        a.push_back(make_pair(p,i));
    }
    for(int i=0;i<m;i++)
    {
        int p;
        cin>>p;
        b.push_back(p);
    }
    vector<int> v1,v2;
    int s=a.size()-1;
    for(int i=0;i<m;i++)
    {
        int k=BinSearch(b[i]-y);
        if(k<=s&&a[k].first<=b[i]+x)
        {
            v1.push_back(a[k].second+1);
            v2.push_back(i+1);
            a[k].first=-1;
        }
    }
    /*for(int i=0;i<v1.size();i++)
        cout<<v1[i]<<" ";
    cout<<endl;*/
    cout<<v1.size()<<endl;
    for(int i=0;i<v1.size();i++)
        cout<<v1[i]<<" "<<v2[i]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
const int N=1e6+5;
ll max(ll a,ll b)
{
    if(a>=b)
        return a;
    else
        return b;
}
ll min(ll a,ll b)
{
    if(a>=b)
        return b;
    else
        return a;
}
ll diff(ll a,ll b)
{
    if(a>=b)
        return a-b;
    else
        return b-a;
}
ll mod(ll a)
{
    if(a>=0)
        return a;
    else
        return -a;
}
void pairsort(ll a[], ll b[], ll n)
{
    pair<ll, ll> pairt[n];

    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }

    sort(pairt, pairt + n);

    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll rev(ll n)
{
    ll ans=0;
    while(n)
    {
        ans=ans*10+n%10;
        n=n/10;
    }
    return ans;
}
int isPrime(int n)
{
    for(int i=2;i*i<=n;i++)
        if(n%i==0)
            return 0;
    return 1;
}
long long C(int n, int r) {
    if(r > n - r) r = n - r;
    long long ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
vector<pair<int,int>> a;
vector<int> b;
int n,m,x,y;
int BinSearch(int x)
{
    int low=0,high=a.size()-1,mid,mid1=99999999999;
    while(low<=high)
    {
        mid=(low+high)/2;
        if(a[mid].first>=x)
        {
            high=mid-1;
            if(mid<mid1)
                mid1=mid;
        }
        else if(a[mid].first<x)
        {
            low=mid+1;
        }
    }
    return mid1;
}
int32_t main()
{
    IOS;
    cin>>n>>m>>x>>y;
    for(int i=0;i<n;i++)
    {
        int p;
        cin>>p;
        a.push_back(make_pair(p,i));
    }
    for(int i=0;i<m;i++)
    {
        int p;
        cin>>p;
        b.push_back(p);
    }
    vector<int> v1,v2;
    for(int i=0;i<m;i++)
    {
        int k=BinSearch(b[i]-x);
        if(k<=a.size()-1&&a[k].first<=b[i]+y)
        {
            v1.push_back(a[k].second+1);
            v2.push_back(i+1);
            a.erase(a.begin()+k);
        }
    }
    /*for(int i=0;i<v1.size();i++)
        cout<<v1[i]<<" ";
    cout<<endl;*/
    cout<<v1.size()<<endl;
    for(int i=0;i<v1.size();i++)
        cout<<v1[i]<<" "<<v2[i]<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second
#define INF 0x3f3f3f3f

using namespace std;

//int t;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//cin>>t;
	//while(t--){}

	int n, m;
	lint x,y;
	cin>>n>>m;
	cin>>x>>y;
	vector<pair<lint,int>> a(n), b(m);
	for(int i =0; i<n;i++){
		cin>>a[i].st;
		a[i].nd = i+1;
	}
	for(int i =0; i<m;i++){
		cin>>b[i].st;
		b[i].nd = i+1;
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	vector<pair<int,int>> ans;
	for(int i=0, j=0;i<m;i++){
		while(j<n && (b[i].st >= (a[j].st - x))){

			if(b[i].st <= (a[j].st + y)){
				ans.push_back({b[i].nd, a[i].nd});
				j++;
				break;
			}
			j++;
		}

	}
	cout<<ans.size()<<"\n";
	for(auto &p:ans)
		cout<<p.st<<" "<<p.nd<<"\n";

	return 0;
}


#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second
#define INF 0x3f3f3f3f

using namespace std;

//int t;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//cin>>t;
	//while(t--){}

	int n, m;
	lint x,y;
	cin>>n>>m;
	cin>>x>>y;
	vector<pair<lint,int>> a(n), b(m);
	for(int i =0; i<n;i++){
		cin>>a[i].st;
		a[i].nd = i+1;
	}
	for(int i =0; i<m;i++){
		cin>>b[i].st;
		b[i].nd = i+1;
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	vector<pair<int,int>> ans;
	for(int i=0, j=0;i<m;i++){

		while(j<n && (a[j].st + y) < b[i].st)
			j++;
		if(j<n &&  (a[j].st - x)<= b[i].st && b[i].st <= (a[j].st + y)){
				ans.push_back({b[i].nd, a[j].nd});
				j++;

		}

	}
	cout<<ans.size()<<"\n";
	for(auto &p:ans)
		cout<<p.st<<" "<<p.nd<<"\n";

	return 0;
}


#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second
#define INF 0x3f3f3f3f

using namespace std;

//int t;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//cin>>t;
	//while(t--){}

	int n, m;
	lint x,y;
	cin>>n>>m;
	cin>>x>>y;
	vector<pair<lint,int>> a(n), b(m);
	for(int i =0; i<n;i++){
		cin>>a[i].st;
		a[i].nd = i+1;
	}
	for(int i =0; i<m;i++){
		cin>>b[i].st;
		b[i].nd = i+1;
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	vector<pair<int,int>> ans;
	for(int i=0, j=0;i<m;i++){
		while(j<n && (b[i].st >= (a[j].st - x))){

			if(b[i].st <= (a[j].st + y)){
				ans.push_back({b[i].nd, a[j].nd});
				j++;
				break;
			}
			j++;
		}

	}
	cout<<ans.size()<<"\n";
	for(auto &p:ans)
		cout<<p.st<<" "<<p.nd<<"\n";

	return 0;
}


#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second
#define INF 0x3f3f3f3f

using namespace std;

//int t;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//cin>>t;
	//while(t--){}

	int n, m;
	lint x,y;
	cin>>n>>m;
	cin>>x>>y;
	vector<pair<lint,int>> a(n), b(m);
	for(int i =0; i<n;i++){
		cin>>a[i].st;
		a[i].nd = i+1;
	}
	for(int i =0; i<m;i++){
		cin>>b[i].st;
		b[i].nd = i+1;
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	vector<pair<int,int>> ans;
	for(int i=0, j=0;i<m;i++){

		while(j<n && (a[j].st + y) < b[i].st)
			j++;
		if(j<n &&  (a[j].st - x)<= b[i].st && b[i].st <= (a[j].st + y)){
				ans.push_back({b[i].nd, a[j].nd});
				j++;

		}

	}
	cout<<ans.size()<<"\n";
	for(auto &p:ans)
		cout<<p.nd<<" "<<p.st<<"\n";

	return 0;
}


#include<bits/stdc++.h>
#define ll long long

using namespace std;

struct db
{
    int sn;
    int vn;
    bool xp = false;
};

int main()
{
    int n, m, x, y, i;

    cin>>n>>m>>x>>y;

    int arr[n], brr[m];

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

    for(i=0; i<m; i++)
        cin>>brr[i];

    struct db xrr[m];

    int j = 0, k = 0, c = 0;
    i = 0;

    while(i<n && j<m)
    {
        //cout<<i<<"="<<arr[i]<<"___"<<j<<"="<<brr[j]<<endl;

        //cout<<(arr[i])<<" "<<(brr[i]-x)<<"+_+_+_+"<<(arr[i])<<" "<<(brr[i]+y)<<endl;

        /*if(((arr[i]-x)<=brr[j]) && ((arr[i]+y)>=brr[j]))
        {
            //cout<<"GOTCHA!!"<<endl;
            c++;
            xrr[k].sn = i;
            xrr[k].vn = j;
            xrr[k].xp = true;
            j++;
            k++;
        }
        i++;*/

        if(brr[j]<(arr[i]-x))
            j++;

        else if(brr[j]>arr[i]+y)
            i++;

        else
        {
            c++;
            xrr[k].sn = i;
            xrr[k].vn = j;
            xrr[k].xp = true;
            k++;
        }
    }

    cout<<c<<endl;

    for(i=0; i<n; i++)
    {
        if(!(xrr[i].xp))
            break;

        cout<<xrr[i].sn+1<<" "<<xrr[i].vn+1<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long

using namespace std;

struct db
{
    int sn;
    int vn;
    bool xp = false;
};

int main()
{
    int n, m, x, y, i;

    cin>>n>>m>>x>>y;

    int arr[n], brr[m];

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

    for(i=0; i<m; i++)
        cin>>brr[i];

    struct db xrr[m];

    int j = 0, k = 0, c = 0;
    i = 0;

    while(i<n && j<m)
    {
        //cout<<i<<"="<<arr[i]<<"___"<<j<<"="<<brr[j]<<endl;

        //cout<<(arr[i])<<" "<<(brr[i]-x)<<"+_+_+_+"<<(arr[i])<<" "<<(brr[i]+y)<<endl;

        /*if(((arr[i]-x)<=brr[j]) && ((arr[i]+y)>=brr[j]))
        {
            //cout<<"GOTCHA!!"<<endl;
            c++;
            xrr[k].sn = i;
            xrr[k].vn = j;
            xrr[k].xp = true;
            j++;
            k++;
        }
        i++;*/

        //cout<<i<<"+++"<<j<<"_____________"<<arr[i]+y<<"+++++"<<brr[j]<<endl;

        if(brr[j]<(arr[i]-x))
            j++;

        else if(brr[j]>(arr[i]+y))
            i++;

        else
        {
            //cout<<"WTF"<<endl;
            c++;
            xrr[k].sn = i;
            xrr[k].vn = j;
            xrr[k].xp = true;
            k++;
            i++;
            j++;
        }
    }

    cout<<c<<endl;

    for(i=0; i<n; i++)
    {
        if(!(xrr[i].xp))
            break;

        cout<<xrr[i].sn+1<<" "<<xrr[i].vn+1<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long

using namespace std;

struct db
{
    int sn;
    int vn;
};

int main()
{
    int n, m, x, y, i;

    cin>>n>>m>>x>>y;

    int arr[n], brr[m];

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

    for(i=0; i<m; i++)
        cin>>brr[i];

    struct db xrr[m+n];

    int j = 0, c = 0;
    i = 0;

   // int axx[m+n], bxx[m+n];

    while(i<n && j<m)
    {
        //cout<<i<<"="<<arr[i]<<"___"<<j<<"="<<brr[j]<<endl;

        //cout<<(arr[i])<<" "<<(brr[i]-x)<<"+_+_+_+"<<(arr[i])<<" "<<(brr[i]+y)<<endl;

        /*if(((arr[i]-x)<=brr[j]) && ((arr[i]+y)>=brr[j]))
        {
            //cout<<"GOTCHA!!"<<endl;
            c++;
            xrr[k].sn = i;
            xrr[k].vn = j;
            xrr[k].xp = true;
            j++;
            k++;
        }
        i++;*/

        //cout<<i<<"+++"<<j<<"_____________"<<arr[i]+y<<"+++++"<<brr[j]<<endl;

        if (brr[j]<arr[i]-x)
            ++j;

        else if (brr[j]>arr[i]+y)
            ++i;

        else
        {
            xrr[c].sn = ++i;
            xrr[c].vn = ++j;
            ++c;
        }
    }

    cout<<c<<endl;

    for(i=0; i<c; i++)
    {
        //printf("%d %d\n", axx[k], bxx[k]);
        cout<<xrr[i].sn<<" "<<xrr[i].vn<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long

using namespace std;

struct db
{
    int sn;
    int vn;
};

int main()
{
    int n, m, x, y, i;

    cin>>n>>m>>x>>y;

    int arr[n], brr[m];

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

    for(i=0; i<m; i++)
        cin>>brr[i];

    struct db xrr[m];

    int j = 0, count = 0;
    i = 0;

    int axx[m+n], bxx[m+n];

    while(i<n && j<m)
    {
        //cout<<i<<"="<<arr[i]<<"___"<<j<<"="<<brr[j]<<endl;

        //cout<<(arr[i])<<" "<<(brr[i]-x)<<"+_+_+_+"<<(arr[i])<<" "<<(brr[i]+y)<<endl;

        /*if(((arr[i]-x)<=brr[j]) && ((arr[i]+y)>=brr[j]))
        {
            //cout<<"GOTCHA!!"<<endl;
            c++;
            xrr[k].sn = i;
            xrr[k].vn = j;
            xrr[k].xp = true;
            j++;
            k++;
        }
        i++;*/

        //cout<<i<<"+++"<<j<<"_____________"<<arr[i]+y<<"+++++"<<brr[j]<<endl;

        if (brr[j]<arr[i]-x)
            ++j;

        else if (brr[j]>arr[i]+y)
            ++i;

        else
        {
            axx[count] = ++i;
            bxx[count] = ++j;
            ++count;
        }
    }

    cout<<count<<endl;

    for (int k = 0; k < count; ++k)
    {
        printf("%d %d\n", axx[k], bxx[k]);
    }
}


#include<bits/stdc++.h>
#define ll long long

using namespace std;

struct db
{
    int sn;
    int vn;
    bool xp = false;
};

int main()
{
    int n, m, x, y, i;

    cin>>n>>m>>x>>y;

    int arr[n], brr[m];

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

    for(i=0; i<m; i++)
        cin>>brr[i];

    struct db xrr[m];

    int j = 0, k = 0, c = 0;
    i = 0;

    while(i<n && j<m)
    {
        //cout<<i<<"="<<arr[i]<<"___"<<j<<"="<<brr[j]<<endl;

        //cout<<(arr[i])<<" "<<(brr[i]-x)<<"+_+_+_+"<<(arr[i])<<" "<<(brr[i]+y)<<endl;

        if(arr[i]>=(brr[j]-x) && (arr[i]<=brr[j]+y))
        {
            //cout<<"GOTCHA!!"<<endl;
            c++;
            xrr[k].sn = i;
            xrr[k].vn = j;
            xrr[k].xp = true;
            j++;
            k++;
        }
        i++;
    }

    cout<<c<<endl;

    for(i=0; i<n; i++)
    {
        if(!(xrr[i].xp))
            break;

        cout<<xrr[i].sn+1<<" "<<xrr[i].vn+1<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long

using namespace std;

struct db
{
    int sn;
    int vn;
    bool xp = false;
};

int main()
{
    int n, m, x, y, i;

    cin>>n>>m>>x>>y;

    int arr[n], brr[m];

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

    for(i=0; i<m; i++)
        cin>>brr[i];

    struct db xrr[m];

    int j = 0, k = 0, c = 0;
    i = 0;

    while(i<n && j<m)
    {
        //cout<<i<<"="<<arr[i]<<"___"<<j<<"="<<brr[j]<<endl;

        //cout<<(arr[i])<<" "<<(brr[i]-x)<<"+_+_+_+"<<(arr[i])<<" "<<(brr[i]+y)<<endl;

        if(((arr[i]-x)<=brr[j]) && ((arr[i]+y)>=brr[j]))
        {
            //cout<<"GOTCHA!!"<<endl;
            c++;
            xrr[k].sn = i;
            xrr[k].vn = j;
            xrr[k].xp = true;
            j++;
            k++;
        }
        i++;
    }

    cout<<c<<endl;

    for(i=0; i<n; i++)
    {
        if(!(xrr[i].xp))
            break;

        cout<<xrr[i].sn+1<<" "<<xrr[i].vn+1<<endl;
    }
}


/***

    Muammad Imdad-Ul-Haque Rakib(Attari)
    CSE'19
    Chittagong,Bangladesh

***/

#include<bits/stdc++.h>

#define               ek               first
#define               dui              second
#define               ld               long double
#define               ll               long long
#define               boost_           ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define               pb               push_back
#define               ppb              pop_back
#define               ull              unsigned long long
#define               over             return 0
#define               scan(i,n,a)      for(i=0;i<n;++i) cin>>a[i]
#define               MP               make_pair
#define               spc              " "
#define               Yes              cout<<"Yes"<<endl
#define               YES              cout<<"YES"<<endl
#define               yes              cout<<"yes"<<endl
#define               No               cout<<"No"<<endl
#define               NO               cout<<"NO"<<endl
#define               no               cout<<"no"<<endl
#define               loop(i,s,n)        for(i=s;i<n;++i)
#define               endl             "\n"
#define               show(i,a)        for(auto i:a) cout<<i<<spc; cout<<endl;
#define               dpoint(n)        cout<<showpoint<<fixed<<setprecision(n);

using namespace std;

int gcd(int x,int y){
    if(!y) return x;
    return gcd(y,x%y);
}
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b){ return (a.second<b.second); }
bool sortbysecinrev(const pair<int,int>&a, const pair<int,int>&b){ return (a.second>b.second); }
bool sortbysize(string &s1,string &s2){ return s1.size() < s2.size(); }
bool sortinrev(const pair<int,int> &a, const pair<int,int> &b){ return (a.first > b.first); }
bool sortcol( const vector<int>& v1, const vector<int>& v2 ) { return v1[0] < v2[0]; }
/*bool is_prime(ll N){
    ll i,j;
    if(N==1||!N) return false;
    for(i=2;i*i<=N;++i){
        if(N%i==0) return false;
    }
    return true;
}*/
/*void sieve(vector<int>&status){
    int i,j,N=10000000;
    //vector<int>status;
    status.assign(N+1,1);
    for(i=4;i<=N;i+=2) status[i]=0;
    for(i=3;i*i<=N;i+=2){
    if(status[i]){ for(j=i*i;j<=N;j+=i) status[j]=0;}
    }
    status[1]=status[0]=0;
    //loop(i,N+1){ if(status[i]) prime.pb(i);}
       // for(i=0;i<prime.size();++i) cout<<prime[i]<<endl;
       // cout<<endl;
}
/*void segmented_sieve(ll low,ll high){
    ll i,j,start,cnt=0,N;
    vector<ll>ss;
    for(i=low;i<=high;++i) ss.pb(i);
    loop(i,prime.size()){
        start=prime[i]*prime[i];
        if(start<low) start=((low+prime[i]-1)/prime[i])*prime[i];
        for(j=start;j<=high;j+=prime[i]) ss[j-low]=0;
    }

    if(low==1) ss[0]=0;
    else if(low==0) ss[1]=0;
    loop(i,ss.size()){ if(ss[i]) cout<<ss[i]<<endl; }
    cout<<endl;
}*/

int proceed(){

   // dpoint(15);

    int n,m,x,y,i,j,cnt=0;
    cin >> n >> m >> x >> y;
    vector<int> a(n),b(m),p,q;
    scan(i,n,a);
    scan(i,m,b);

    for(i=0,j=0;i<n&&j<b.size();){

        if(b[j]>=a[i]-x&&b[j]<=a[i]+y){
                ++cnt;
                p.pb(i+1),q.pb(j+1);
                ++j;
                ++i;
        }
        else ++i;
    }

    cout << cnt << endl;

    if(cnt){

        for(i=0;i<p.size();++i) cout << p[i] << spc << q[i] << endl;
    }

    over;

}
/** Main **/

int main(){

           // boost_;
            int t=1,i=0;
            //cin>>t;
            while(t--){

                        proceed();

            }

            over;
}


/***

    Muammad Imdad-Ul-Haque Rakib(Attari)
    CSE'19
    Chittagong,Bangladesh

***/

#include<bits/stdc++.h>

#define               ek               first
#define               dui              second
#define               ld               long double
#define               ll               long long
#define               boost_           ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define               pb               push_back
#define               ppb              pop_back
#define               ull              unsigned long long
#define               over             return 0
#define               scan(i,n,a)      for(i=0;i<n;++i) cin>>a[i]
#define               MP               make_pair
#define               spc              " "
#define               Yes              cout<<"Yes"<<endl
#define               YES              cout<<"YES"<<endl
#define               yes              cout<<"yes"<<endl
#define               No               cout<<"No"<<endl
#define               NO               cout<<"NO"<<endl
#define               no               cout<<"no"<<endl
#define               loop(i,s,n)        for(i=s;i<n;++i)
#define               endl             "\n"
#define               show(i,a)        for(auto i:a) cout<<i<<spc; cout<<endl;
#define               dpoint(n)        cout<<showpoint<<fixed<<setprecision(n);

using namespace std;

int gcd(int x,int y){
    if(!y) return x;
    return gcd(y,x%y);
}
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b){ return (a.second<b.second); }
bool sortbysecinrev(const pair<int,int>&a, const pair<int,int>&b){ return (a.second>b.second); }
bool sortbysize(string &s1,string &s2){ return s1.size() < s2.size(); }
bool sortinrev(const pair<int,int> &a, const pair<int,int> &b){ return (a.first > b.first); }
bool sortcol( const vector<int>& v1, const vector<int>& v2 ) { return v1[0] < v2[0]; }
/*bool is_prime(ll N){
    ll i,j;
    if(N==1||!N) return false;
    for(i=2;i*i<=N;++i){
        if(N%i==0) return false;
    }
    return true;
}*/
/*void sieve(vector<int>&status){
    int i,j,N=10000000;
    //vector<int>status;
    status.assign(N+1,1);
    for(i=4;i<=N;i+=2) status[i]=0;
    for(i=3;i*i<=N;i+=2){
    if(status[i]){ for(j=i*i;j<=N;j+=i) status[j]=0;}
    }
    status[1]=status[0]=0;
    //loop(i,N+1){ if(status[i]) prime.pb(i);}
       // for(i=0;i<prime.size();++i) cout<<prime[i]<<endl;
       // cout<<endl;
}
/*void segmented_sieve(ll low,ll high){
    ll i,j,start,cnt=0,N;
    vector<ll>ss;
    for(i=low;i<=high;++i) ss.pb(i);
    loop(i,prime.size()){
        start=prime[i]*prime[i];
        if(start<low) start=((low+prime[i]-1)/prime[i])*prime[i];
        for(j=start;j<=high;j+=prime[i]) ss[j-low]=0;
    }

    if(low==1) ss[0]=0;
    else if(low==0) ss[1]=0;
    loop(i,ss.size()){ if(ss[i]) cout<<ss[i]<<endl; }
    cout<<endl;
}*/

int proceed(){

   // dpoint(15);

    int n,m,x,y,i,j,cnt=0;
    cin >> n >> m >> x >> y;
    vector<int> a(n),b(m),p,q;
    scan(i,n,a);
    scan(i,m,b);

    for(i=0,j=0;i<n&&j<b.size();){

        if(a[j]>=b[i]-x&&a[j]<=b[i]+y){
                ++cnt;
                p.pb(j+1),q.pb(i+1);
                ++j;
                ++i;
        }
        else ++j;
    }

    cout << cnt << endl;

    if(cnt){

        for(i=0;i<p.size();++i) cout << p[i] << spc << q[i] << endl;
    }

    over;

}
/** Main **/

int main(){

           // boost_;
            int t=1,i=0;
            //cin>>t;
            while(t--){

                        proceed();

            }

            over;
}


/***

    Muammad Imdad-Ul-Haque Rakib(Attari)
    CSE'19
    Chittagong,Bangladesh

***/

#include<bits/stdc++.h>

#define               ek               first
#define               dui              second
#define               ld               long double
#define               ll               long long
#define               boost_           ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define               pb               push_back
#define               ppb              pop_back
#define               ull              unsigned long long
#define               over             return 0
#define               scan(i,n,a)      for(i=0;i<n;++i) cin>>a[i]
#define               MP               make_pair
#define               spc              " "
#define               Yes              cout<<"Yes"<<endl
#define               YES              cout<<"YES"<<endl
#define               yes              cout<<"yes"<<endl
#define               No               cout<<"No"<<endl
#define               NO               cout<<"NO"<<endl
#define               no               cout<<"no"<<endl
#define               loop(i,s,n)        for(i=s;i<n;++i)
#define               endl             "\n"
#define               show(i,a)        for(auto i:a) cout<<i<<spc; cout<<endl;
#define               dpoint(n)        cout<<showpoint<<fixed<<setprecision(n);

using namespace std;

int gcd(int x,int y){
    if(!y) return x;
    return gcd(y,x%y);
}
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b){ return (a.second<b.second); }
bool sortbysecinrev(const pair<int,int>&a, const pair<int,int>&b){ return (a.second>b.second); }
bool sortbysize(string &s1,string &s2){ return s1.size() < s2.size(); }
bool sortinrev(const pair<int,int> &a, const pair<int,int> &b){ return (a.first > b.first); }
bool sortcol( const vector<int>& v1, const vector<int>& v2 ) { return v1[0] < v2[0]; }
/*bool is_prime(ll N){
    ll i,j;
    if(N==1||!N) return false;
    for(i=2;i*i<=N;++i){
        if(N%i==0) return false;
    }
    return true;
}*/
/*void sieve(vector<int>&status){
    int i,j,N=10000000;
    //vector<int>status;
    status.assign(N+1,1);
    for(i=4;i<=N;i+=2) status[i]=0;
    for(i=3;i*i<=N;i+=2){
    if(status[i]){ for(j=i*i;j<=N;j+=i) status[j]=0;}
    }
    status[1]=status[0]=0;
    //loop(i,N+1){ if(status[i]) prime.pb(i);}
       // for(i=0;i<prime.size();++i) cout<<prime[i]<<endl;
       // cout<<endl;
}
/*void segmented_sieve(ll low,ll high){
    ll i,j,start,cnt=0,N;
    vector<ll>ss;
    for(i=low;i<=high;++i) ss.pb(i);
    loop(i,prime.size()){
        start=prime[i]*prime[i];
        if(start<low) start=((low+prime[i]-1)/prime[i])*prime[i];
        for(j=start;j<=high;j+=prime[i]) ss[j-low]=0;
    }

    if(low==1) ss[0]=0;
    else if(low==0) ss[1]=0;
    loop(i,ss.size()){ if(ss[i]) cout<<ss[i]<<endl; }
    cout<<endl;
}*/

int proceed(){

   // dpoint(15);

    ll n,m,x,y,i,j,cnt=0;
    cin >> n >> m >> x >> y;
    vector<ll> a(n),b(m);
    vector<pair<ll,ll>>p;
    scan(i,n,a);
    scan(i,m,b);

    for(i=0,j=0;i<n&&j<m;){

        if(b[j]>=a[i]-x&&b[j]<=a[i]+y){
            p.pb(MP(i+1,j+1));
            ++cnt;
            ++i;
            ++j;
        }
        else if(b[j]<a[i]-x) ++j;
        else if(b[j]>a[i]+y) ++i;
    }

    cout << cnt << endl;

    if(cnt){

        for(auto i:p) cout << i.ek << spc << i.dui << endl;
    }

    over;

}
/** Main **/

int main(){

           // boost_;
            int t=1,i=0;
            //cin>>t;
            while(t--){

                        proceed();

            }

            over;
}


#include<bits/stdc++.h>

using namespace std;

void input()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    #endif
}
#define endl "\n"
#define ll long long int
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define tll tuple<ll,ll,ll>
#define mt make_tuple
#define INF LONG_LONG_MAX
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define cases ll t; cin>>t; while(t--)
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define sortall(a) sort(a.begin(),a.end())
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;

// --------------- My Template End --------------- //
ll getind(ll num,map<ll,vll>&m)
{
	ll ans=m[num][m[num].size()-1];
	m[num].pop_back();
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	input();
	ll n,m,x,y;
	cin>>n>>m>>x>>y;
	vector<pll> ans;
	array(a,n);
	array(b,m);
	map<ll,vector<ll>>ma;
	multiset<ll>s;
	rep(i,0,m)
	{
		ma[b[i]].pb(i+1);
		s.insert(b[i]);
	}
	rep(i,0,n)
	{
		auto f=lower_bound(s.begin(),s.end(),a[i]-x);
		if(f!=s.end())
		{
			if(*f<=a[i]+y&&*f>=a[i]-x)
			{
				ll ind=getind(*f,ma);
					ans.pb({i+1,ind});
					s.erase(f);
					continue;
			}

		}

	}
	cout<<ans.size()<<endl;
	for(auto j:ans)
	{
		cout<<j.ff<<" "<<j.ss<<endl;
	}
}


#include<bits/stdc++.h>

using namespace std;

void input()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    #endif
}
#define endl "\n"
#define ll long long int
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define tll tuple<ll,ll,ll>
#define mt make_tuple
#define INF LONG_LONG_MAX
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define cases ll t; cin>>t; while(t--)
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define sortall(a) sort(a.begin(),a.end())
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;

// --------------- My Template End --------------- //

int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	input();
	ll n,m,x,y;
	cin>>n>>m>>x>>y;
	vector<pll> ans;
	array(a,n);
	array(b,m);
	multiset<ll>s;
	rep(i,0,m)
	{
		s.insert(b[i]);
	}
	rep(i,0,n)
	{
		auto f=lower_bound(s.begin(),s.end(),a[i]-x);
		if(f!=s.end())
		{
			if(*f<=a[i]+y&&*f>=a[i]-x)
			{
					ans.pb({i+1,lower_bound(b.begin(), b.end(),*f)-b.begin()+1});
					s.erase(f);
					continue;
			}

		}

	}
	cout<<ans.size()<<endl;
	for(auto j:ans)
	{
		cout<<j.ff<<" "<<j.ss<<endl;
	}
}


#include<bits/stdc++.h>

using namespace std;

void input()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    #endif
}
#define endl "\n"
#define ll long long int
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define tll tuple<ll,ll,ll>
#define mt make_tuple
#define INF LONG_LONG_MAX
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define cases ll t; cin>>t; while(t--)
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define sortall(a) sort(a.begin(),a.end())
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;

// --------------- My Template End --------------- //
ll getind(ll num,unordered_map<ll,vll>&m)
{
	ll ans=m[num][m[num].size()-1];
	m[num].pop_back();
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	input();
	ll n,m,x,y;
	cin>>n>>m>>x>>y;
	vector<pll> ans;
	array(a,n);
	array(b,m);
	unordered_map<ll,vector<ll>>ma;
	set<ll>s;
	rep(i,0,m)
	{
		ma[b[i]].pb(i+1);
		s.insert(b[i]);
	}
	rep(i,0,n)
	{
		auto f=lower_bound(s.begin(),s.end(),a[i]-x);
		if(f!=s.end())
		{
			if(*f<=a[i]+y&&*f>=a[i]-x)
			{
				ll num=*f,ind=ma[num][ma[num].size()-1];
				ma[num].pop_back();

				ans.pb({i+1,ind});
				if(ma[num].size()==0)
					s.erase(f);
					continue;
			}

		}

	}
	cout<<ans.size()<<endl;
	for(auto j:ans)
	{
		cout<<j.ff<<" "<<j.ss<<endl;
	}
}


#include<bits/stdc++.h>

using namespace std;

void input()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    #endif
}
#define endl "\n"
#define ll long long int
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define tll tuple<ll,ll,ll>
#define mt make_tuple
#define INF LONG_LONG_MAX
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define cases ll t; cin>>t; while(t--)
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define sortall(a) sort(a.begin(),a.end())
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;

// --------------- My Template End --------------- //
ll getind(ll num,unordered_map<ll,vll>&m)
{
	ll ans=m[num][m[num].size()-1];
	m[num].pop_back();
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	input();
	ll n,m,x,y;
	cin>>n>>m>>x>>y;
	vector<pll> ans;
	array(a,n);
	array(b,m);
	ll i=0,j=0;
	while(i<n&&j<m)
	{
		while(j<m&&a[i]-x>b[j])j++;
		if(j<m&&a[i]+y>=b[j])
		{
			ans.pb({i+1,j+1});
			j++;
		}
		i++;
	}
	cout<<ans.size()<<endl;
	for(auto j:ans)
	{
		cout<<j.ff<<" "<<j.ss<<endl;
	}
}


#include<bits/stdc++.h>

using namespace std;

void input()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    #endif
}
#define endl "\n"
#define ll long long int
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define tll tuple<ll,ll,ll>
#define mt make_tuple
#define INF LONG_LONG_MAX
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define cases ll t; cin>>t; while(t--)
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define sortall(a) sort(a.begin(),a.end())
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;

// --------------- My Template End --------------- //
ll getind(ll num,unordered_map<ll,vll>&m)
{
	ll ans=m[num][m[num].size()-1];
	m[num].pop_back();
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	input();
	ll n,m,x,y;
	cin>>n>>m>>x>>y;
	vector<pll> ans;
	array(a,n);
	array(b,m);
	unordered_map<ll,vector<ll>>ma;
	multiset<ll>s;
	rep(i,0,m)
	{
		ma[b[i]].pb(i+1);
		s.insert(b[i]);
	}
	rep(i,0,n)
	{
		auto f=lower_bound(s.begin(),s.end(),a[i]-x);
		if(f!=s.end())
		{
			if(*f<=a[i]+y&&*f>=a[i]-x)
			{
				ll ind=getind(*f,ma);
					ans.pb({i+1,ind});
					s.erase(f);
					continue;
			}

		}

	}
	cout<<ans.size()<<endl;
	for(auto j:ans)
	{
		cout<<j.ff<<" "<<j.ss<<endl;
	}
}


#include <iostream>
#include <vector>
using namespace std;

void Input(
    vector<int> & soldiers,
    vector<int> & vests,
    int & x,
    int & y
) {
    size_t numberOfSoldiers, numberOfVests;
    cin >> numberOfSoldiers >> numberOfVests >> x >> y;

    soldiers.resize(numberOfSoldiers);
    vests.resize(numberOfVests);

    for (auto & i : soldiers) {
        cin >> i;
    }
    for (auto & i : vests) {
        cin >> i;
    }
}

vector<pair<int, int>> FindMatchingSuits(
    const vector<int> & soldiers,
    const vector<int> & vests,
    const int & x,
    const int & y
) {
    vector<pair<int, int>> match;
    size_t pointSoliers = 0, pointVests = 0;
    while (pointSoliers < soldiers.size() && pointVests < vests.size()) {
        if (soldiers[pointSoliers] - x <= vests[pointVests] &&
            vests[pointVests] <= soldiers[pointSoliers] + y) {
            match.emplace_back(pair(pointSoliers + 1, pointVests + 1));
            ++pointSoliers;
            ++pointVests;
        }
        else if (soldiers[pointSoliers] + y < vests[pointVests]) {
            ++pointSoliers;
        }
        else if (vests[pointVests] < soldiers[pointSoliers] - x) {
            ++pointVests;
        }
    }
    return move(match);
}

void PrintMatchingSuits(const vector<pair<int, int>> & match) {
    cout << match.size() << endl;
    for (auto && i : match) {
        cout << i.first << " " << i.second << endl;
    }
}

int main() {
    vector<int> soldiers;
    vector<int> vests;
    int x, y;
    Input(soldiers, vests, x, y);
    vector<pair<int, int>> match = FindMatchingSuits(soldiers, vests, x, y);
    PrintMatchingSuits(match);
    return EXIT_SUCCESS;
}


#include <iostream>
#include <vector>
using namespace std;

struct Data {
    int x;
    int y;
    vector<int> soldiers;
    vector<int> vests;
};

void Input(Data & data) {
    size_t numberOfSoldiers, numberOfVests;
    cin >> numberOfSoldiers >> numberOfVests >> data.x >> data.y;

    data.soldiers.resize(numberOfSoldiers);
    data.vests.resize(numberOfVests);

    for (auto & i : data.soldiers) {
        cin >> i;
    }
    for (auto & i : data.vests) {
        cin >> i;
    }
}

int FindMinimumOfNeedForSizeOfVest(const Data & data) {
    for (size_t i = 0; i < data.vests.size(); ++i) {
        if (data.soldiers[0] - data.x <= data.vests[i] &&
            data.soldiers[0] + data.y >= data.vests[i]) {
            return i;
        }
    }
    return 0;
}

void FindListPairs(const Data & data, vector<pair<int, int>> & pairs) {
    int minToFind = FindMinimumOfNeedForSizeOfVest(data);
    int previousMin = minToFind;
    int left, right, mid;

    for (int i = 0; i < data.soldiers.size(); ++i) {
        left = minToFind;
        right = data.vests.size() - 1;
        /*while (
            (minToFind < data.vests.size()) &&
            (data.soldiers[i] - data.x > data.vests[minToFind] ||
                data.soldiers[i] + data.y < data.vests[minToFind])
            ) {
            if (data.soldiers[i] + data.y < data.vests[minToFind]) {
                minToFind = data.vests.size();
                break;
            }
            ++minToFind;
        }*/
        while (left <= right) {
            mid = (left - right) / 2;
            if (data.soldiers[i] - data.x <= data.vests[mid] ||
                data.soldiers[i] + data.y >= data.vests[mid]) {
                right = mid - 1;
            }
            else {
                minToFind = right + 1;
                break;
            }
        }
        if (previousMin == data.vests.size()) {
            break;
        }
        else {
            if (minToFind < data.vests.size()) {
                pairs.emplace_back(pair<int, int>(i + 1, minToFind + 1));
                ++minToFind;
                previousMin = minToFind;
            }
            else {
                minToFind = previousMin;
            }
        }
    }
}

void PrintResult(const vector<pair<int, int>> & pairs) {
    if (pairs.size() == 0) {
        cout << 0;
    }
    else {
        cout << pairs.size() << endl;
        for (auto && i : pairs) {
            cout << i.first << " " << i.second << endl;
        }
    }
}

int main() {
    Data data;
    Input(data);
    vector<pair<int, int>> pairs;
    FindListPairs(data, pairs);
    PrintResult(pairs);
    return EXIT_SUCCESS;
}


#include <iostream>
#include <vector>
using namespace std;

void Input(
    vector<int> & soldiers,
    vector<int> & vests,
    int & x,
    int & y
) {
    size_t numberOfSoldiers, numberOfVests;
    cin >> numberOfSoldiers >> numberOfVests >> x >> y;

    soldiers.resize(numberOfSoldiers);
    vests.resize(numberOfVests);

    for (auto & i : soldiers) {
        cin >> i;
    }
    for (auto & i : vests) {
        cin >> i;
    }
}

vector<pair<int, int>> FindMatchingSuits(
    const vector<int> & soldiers,
    const vector<int> & vests,
    const int & x,
    const int & y
) {
    vector<pair<int, int>> match;
    size_t pointSoliers = 0, pointVests = 0;
    while (pointSoliers < soldiers.size() && pointVests < vests.size()) {
        if (soldiers[pointSoliers] - x <= vests[pointVests] &&
            vests[pointVests] <= soldiers[pointSoliers] + y) {
            match.emplace_back(pair(pointSoliers + 1, pointVests + 1));
            ++pointSoliers;
            ++pointVests;
        }
        else if (soldiers[pointVests] + y < vests[pointVests]) {
            ++pointSoliers;
        }
        else if (vests[pointVests] < soldiers[pointSoliers] - x) {
            ++pointVests;
        }
        else {
            cout << "Inf loop";
        }
    }
    return move(match);
}

void PrintMatchingSuits(const vector<pair<int, int>> & match) {
    cout << match.size() << endl;
    for (auto && i : match) {
        cout << i.first << " " << i.second << endl;
    }
}

int main() {
    vector<int> soldiers;
    vector<int> vests;
    int x, y;
    Input(soldiers, vests, x, y);
    vector<pair<int, int>> match = FindMatchingSuits(soldiers, vests, x, y);
    PrintMatchingSuits(match);
    return EXIT_SUCCESS;
}


#include <iostream>
#include <vector>
using namespace std;

struct Data {
    int x;
    int y;
    vector<int> soldiers;
    vector<int> vests;
};

void Input(Data & data) {
    size_t numberOfSoldiers, numberOfVests;
    cin >> numberOfSoldiers >> numberOfVests >> data.x >> data.y;

    data.soldiers.resize(numberOfSoldiers);
    data.vests.resize(numberOfVests);

    for (auto & i : data.soldiers) {
        cin >> i;
    }
    for (auto & i : data.vests) {
        cin >> i;
    }
}

int FindMinimumOfNeedForSizeOfVest(const Data & data) {
    for (size_t i = 0; i < data.vests.size(); ++i) {
        if (data.soldiers[0] - data.x <= data.vests[i] &&
            data.soldiers[0] + data.y >= data.vests[i]) {
            return i;
        }
    }
    return 0;
}

void FindListPairs(const Data & data, vector<pair<int, int>> & pairs) {
    int minToFind = FindMinimumOfNeedForSizeOfVest(data);
    int previousMin = minToFind;
    /*if (minToFind == -1) {
        return;
    }*/

    for (int i = 0; i < data.soldiers.size(); ++i) {
        while (
            (minToFind < data.vests.size()) &&
            (data.soldiers[i] - data.x > data.vests[minToFind] ||
            data.soldiers[i] + data.y < data.vests[minToFind])
        ) {
            if (data.soldiers[i] + data.y < data.vests[minToFind]) {
                minToFind = data.vests.size();
                break;
            }
            ++minToFind;
        }
        if (previousMin == data.vests.size()) {
            break;
        }
        else {
            if (minToFind < data.vests.size()) {
                pairs.emplace_back(pair<int, int>(i + 1, minToFind + 1));
                ++minToFind;
                previousMin = minToFind;
            }
            else {
                minToFind = previousMin;
            }
        }
    }
}

void PrintResult(const vector<pair<int, int>> & pairs) {
    if (pairs.size() == 0) {
        cout << 0;
    }
    else {
        cout << pairs.size() << endl;
        for (auto && i : pairs) {
            cout << i.first << " " << i.second << endl;
        }
    }
}

int main() {
    Data data;
    Input(data);
    vector<pair<int, int>> pairs;
    FindListPairs(data, pairs);
    PrintResult(pairs);
    return EXIT_SUCCESS;
}


#include <iostream>
#include <vector>
using namespace std;

struct Data {
    int x;
    int y;
    vector<int> soldiers;
    vector<int> vests;
};

void Input(Data & data) {
    size_t numberOfSoldiers, numberOfVests;
    cin >> numberOfSoldiers >> numberOfVests >> data.x >> data.y;

    data.soldiers.resize(numberOfSoldiers);
    data.vests.resize(numberOfVests);

    for (auto & i : data.soldiers) {
        cin >> i;
    }
    for (auto & i : data.vests) {
        cin >> i;
    }
}

int FindMinimumOfNeedForSizeOfVest(const Data & data) {
    for (size_t i = 0; i < data.vests.size(); ++i) {
        if (data.soldiers[0] - data.x <= data.vests[i] &&
            data.soldiers[0] + data.y >= data.vests[i]) {
            return i;
        }
    }
    return 0;
}

void FindListPairs(const Data & data, vector<pair<int, int>> & pairs) {
    int minToFind = 0;
    int previousMin = 0;
    int left, right, mid;

    for (int i = 0; i < data.soldiers.size(); ++i) {
        left = minToFind;
        right = data.vests.size() - 1;
        /*while (
            (minToFind < data.vests.size()) &&
            (data.soldiers[i] - data.x > data.vests[minToFind] ||
                data.soldiers[i] + data.y < data.vests[minToFind])
            ) {
            if (data.soldiers[i] + data.y < data.vests[minToFind]) {
                minToFind = data.vests.size();
                break;
            }
            ++minToFind;
        }*/
        while (left <= right) {
            mid = (right + left) / 2;
            if (data.soldiers[i] - data.x <= data.vests[mid] &&
                data.soldiers[i] + data.y >= data.vests[mid]) {
                if (left < right && mid - 1 >= left)
                    right = mid - 1;
                else {
                    minToFind = mid;
                    break;
                }
            }
            else if (data.soldiers[i] + data.y < data.vests[mid]) {
                right = mid - 1;
            }
            else if (data.soldiers[i] - data.x > data.vests[mid]) {
                left = mid + 1;
            }
            else {
                minToFind = right;
                break;
            }
        }
        if (previousMin == data.vests.size()) {
            break;
        }
        else {
            if (left <= right) {
                pairs.emplace_back(pair<int, int>(i + 1, minToFind + 1));
                ++minToFind;
                previousMin = minToFind;
            }
            else {
                minToFind = previousMin;
            }
        }
    }
}

void PrintResult(const vector<pair<int, int>> & pairs) {
    if (pairs.size() == 0) {
        cout << 0;
    }
    else {
        cout << pairs.size() << endl;
        for (auto && i : pairs) {
            cout << i.first << " " << i.second << endl;
        }
    }
}

int main() {
    Data data;
    Input(data);
    vector<pair<int, int>> pairs;
    FindListPairs(data, pairs);
    PrintResult(pairs);
    return EXIT_SUCCESS;
}


#include <iostream>
#include <vector>
using namespace std;

void Input(
    vector<int> & soldiers,
    vector<int> & vests,
    int & x,
    int & y
) {
    size_t numberOfSoldiers, numberOfVests;
    cin >> numberOfSoldiers >> numberOfVests >> x >> y;

    soldiers.resize(numberOfSoldiers);
    vests.resize(numberOfVests);

    for (auto & i : soldiers) {
        cin >> i;
    }
    for (auto & i : vests) {
        cin >> i;
    }
}

vector<pair<int, int>> FindMatchingSuits(
    const vector<int> & soldiers,
    const vector<int> & vests,
    const int & x,
    const int & y
) {
    vector<pair<int, int>> match;
    size_t pointSoliers = 0, pointVests = 0;
    while (pointSoliers < soldiers.size() && pointSoliers < vests.size()) {
        if (soldiers[pointSoliers] - x <= vests[pointVests] &&
            vests[pointVests] <= soldiers[pointSoliers] + y) {
            match.emplace_back(pair(pointSoliers + 1, pointVests + 1));
            ++pointSoliers;
            ++pointVests;
        }
        else if (soldiers[pointVests] + y < vests[pointVests]) {
            ++pointSoliers;
        }
        else if (vests[pointVests] < soldiers[pointSoliers] - x) {
            ++pointVests;
        }
    }
    return move(match);
}

void PrintMatchingSuits(const vector<pair<int, int>> & match) {
    cout << match.size() << endl;
    for (auto && i : match) {
        cout << i.first << " " << i.second << endl;
    }
}

int main() {
    vector<int> soldiers;
    vector<int> vests;
    int x, y;
    Input(soldiers, vests, x, y);
    vector<pair<int, int>> match = FindMatchingSuits(soldiers, vests, x, y);
    PrintMatchingSuits(match);
    return EXIT_SUCCESS;
}


#include <iostream>
#include <vector>
using namespace std;

struct Data {
    int x;
    int y;
    vector<int> soldiers;
    vector<int> vests;
};

void Input(Data & data) {
    size_t numberOfSoldiers, numberOfVests;
    cin >> numberOfSoldiers >> numberOfVests >> data.x >> data.y;

    data.soldiers.resize(numberOfSoldiers);
    data.vests.resize(numberOfVests);

    for (auto & i : data.soldiers) {
        cin >> i;
    }
    for (auto & i : data.vests) {
        cin >> i;
    }
}

int FindMinimumOfNeedForSizeOfVest(const Data & data) {
    int left = 0, right = data.vests.size() - 1, mid;
    while (left <= right) {
        mid = (left + right) / 2;
        if (
            data.soldiers[0] - data.x <= data.vests[mid] &&
            data.vests[mid] <= data.soldiers[0] + data.y
        ) {
            return mid;
        }
        else if (data.vests[mid] < data.soldiers[0] - data.x) {
            left = mid + 1;
        }
        else if (data.vests[mid] > data.soldiers[0] + data.y) {
            right = mid - 1;
        }
    }
    return -1; // not found
}

void FindListPairs(const Data & data, vector<pair<int, int>> & pairs) {
    int minToFind = FindMinimumOfNeedForSizeOfVest(data);
    int previousMin = minToFind;
    if (minToFind) {
        return;
    }

    for (int i = 0; i < data.soldiers.size(); ++i) {
        while (
            (minToFind < data.vests.size()) &&
            (data.soldiers[i] - data.x > data.vests[minToFind] ||
            data.soldiers[i] + data.y < data.vests[minToFind])
        ) {
            ++minToFind;
        }
        if (previousMin == data.vests.size()) {
            break;
        }
        else {
            if (minToFind < data.vests.size()) {
                pairs.emplace_back(pair<int, int>(i + 1, minToFind + 1));
                ++minToFind;
                previousMin = minToFind;
            }
            else {
                minToFind = previousMin;
            }
        }
    }
}

void PrintResult(const vector<pair<int, int>> & pairs) {
    if (pairs.size() == 0) {
        cout << 0;
    }
    else {
        cout << pairs.size() << endl;
        for (auto && i : pairs) {
            cout << i.first << " " << i.second << endl;
        }
    }
}

int main() {
    Data data;
    Input(data);
    vector<pair<int, int>> pairs;
    FindListPairs(data, pairs);
    PrintResult(pairs);
    return EXIT_SUCCESS;
}


#include <iostream>
#include <vector>
using namespace std;

void Input(
    vector<int> & soldiers,
    vector<int> & vests,
    int & x,
    int & y
) {
    size_t numberOfSoldiers, numberOfVests;
    cin >> numberOfSoldiers >> numberOfVests >> x >> y;

    soldiers.resize(numberOfSoldiers);
    vests.resize(numberOfVests);

    for (auto & i : soldiers) {
        cin >> i;
    }
    for (auto & i : vests) {
        cin >> i;
    }
}

vector<pair<int, int>> FindMatchingSuits(
    const vector<int> & soldiers,
    const vector<int> & vests,
    const int & x,
    const int & y
) {
    vector<pair<int, int>> match;
    size_t pointSoliers = 0, pointVests = 0;
    while (pointSoliers < soldiers.size() && pointVests < vests.size()) {
        if (soldiers[pointSoliers] - x <= vests[pointVests] &&
            vests[pointVests] <= soldiers[pointSoliers] + y) {
            match.emplace_back(pair(pointSoliers + 1, pointVests + 1));
            ++pointSoliers;
            ++pointVests;
        }
        else if (soldiers[pointVests] + y < vests[pointVests]) {
            ++pointSoliers;
        }
        else if (vests[pointVests] < soldiers[pointSoliers] - x) {
            ++pointVests;
        }
    }
    return move(match);
}

void PrintMatchingSuits(const vector<pair<int, int>> & match) {
    cout << match.size() << endl;
    for (auto && i : match) {
        cout << i.first << " " << i.second << endl;
    }
}

int main() {
    vector<int> soldiers;
    vector<int> vests;
    int x, y;
    Input(soldiers, vests, x, y);
    vector<pair<int, int>> match = FindMatchingSuits(soldiers, vests, x, y);
    PrintMatchingSuits(match);
    return EXIT_SUCCESS;
}


#include <iostream>
#include <vector>
using namespace std;

struct Data {
    int x;
    int y;
    vector<int> soldiers;
    vector<int> vests;
};

void Input(Data & data) {
    size_t numberOfSoldiers, numberOfVests;
    cin >> numberOfSoldiers >> numberOfVests >> data.x >> data.y;

    data.soldiers.resize(numberOfSoldiers);
    data.vests.resize(numberOfVests);

    for (auto & i : data.soldiers) {
        cin >> i;
    }
    for (auto & i : data.vests) {
        cin >> i;
    }
}

int FindMinimumOfNeedForSizeOfVest(const Data & data) {
    for (size_t i = 0; i < data.vests.size(); ++i) {
        if (data.soldiers[0] - data.x <= data.vests[i] &&
            data.soldiers[0] + data.y >= data.vests[i]) {
            return i;
        }
    }
    return 0;
}

void FindListPairs(const Data & data, vector<pair<int, int>> & pairs) {
    int minToFind = 0;
    int previousMin = 0;
    int left, right, mid;

    for (int i = 0; i < data.soldiers.size(); ++i) {
        left = minToFind;
        right = data.vests.size() - 1;
        /*while (
            (minToFind < data.vests.size()) &&
            (data.soldiers[i] - data.x > data.vests[minToFind] ||
                data.soldiers[i] + data.y < data.vests[minToFind])
            ) {
            if (data.soldiers[i] + data.y < data.vests[minToFind]) {
                minToFind = data.vests.size();
                break;
            }
            ++minToFind;
        }*/
        while (left <= right) {
            mid = (right - left) / 2;
            if (data.soldiers[i] - data.x <= data.vests[mid] ||
                data.soldiers[i] + data.y >= data.vests[mid]) {
                right = mid - 1;
            }
            else if (data.soldiers[i] - data.x > data.vests[mid]) {
                left = mid + 1;
            }
            else {
                minToFind = right + 1;
                break;
            }
        }
        if (previousMin == data.vests.size()) {
            break;
        }
        else {
            if (minToFind < data.vests.size()) {
                pairs.emplace_back(pair<int, int>(i + 1, minToFind + 1));
                ++minToFind;
                previousMin = minToFind;
            }
            else {
                minToFind = previousMin;
            }
        }
    }
}

void PrintResult(const vector<pair<int, int>> & pairs) {
    if (pairs.size() == 0) {
        cout << 0;
    }
    else {
        cout << pairs.size() << endl;
        for (auto && i : pairs) {
            cout << i.first << " " << i.second << endl;
        }
    }
}

int main() {
    Data data;
    Input(data);
    vector<pair<int, int>> pairs;
    FindListPairs(data, pairs);
    PrintResult(pairs);
    return EXIT_SUCCESS;
}


#include <iostream>
#include <vector>
using namespace std;

struct Data {
    int x;
    int y;
    vector<int> soldiers;
    vector<int> vests;
};

void Input(Data & data) {
    size_t numberOfSoldiers, numberOfVests;
    cin >> numberOfSoldiers >> numberOfVests >> data.x >> data.y;

    data.soldiers.resize(numberOfSoldiers);
    data.vests.resize(numberOfVests);

    for (auto & i : data.soldiers) {
        cin >> i;
    }
    for (auto & i : data.vests) {
        cin >> i;
    }
}

int FindMinimumOfNeedForSizeOfVest(const Data & data) {
    for (size_t i = 0; i < data.vests.size(); ++i) {
        if (data.soldiers[0] - data.x <= data.vests[i] &&
            data.soldiers[0] + data.y >= data.vests[i]) {
            return i;
        }
    }
    return -1; // not found
}

void FindListPairs(const Data & data, vector<pair<int, int>> & pairs) {
    int minToFind = FindMinimumOfNeedForSizeOfVest(data);
    int previousMin = minToFind;
    if (minToFind) {
        return;
    }

    for (int i = 0; i < data.soldiers.size(); ++i) {
        while (
            (minToFind < data.vests.size()) &&
            (data.soldiers[i] - data.x > data.vests[minToFind] ||
            data.soldiers[i] + data.y < data.vests[minToFind])
        ) {
            if (data.soldiers[i] + data.y < data.vests[minToFind]) {
                minToFind = data.vests.size();
                break;
            }
            ++minToFind;
        }
        if (previousMin == data.vests.size()) {
            break;
        }
        else {
            if (minToFind < data.vests.size()) {
                pairs.emplace_back(pair<int, int>(i + 1, minToFind + 1));
                ++minToFind;
                previousMin = minToFind;
            }
            else {
                minToFind = previousMin;
            }
        }
    }
}

void PrintResult(const vector<pair<int, int>> & pairs) {
    if (pairs.size() == 0) {
        cout << 0;
    }
    else {
        cout << pairs.size() << endl;
        for (auto && i : pairs) {
            cout << i.first << " " << i.second << endl;
        }
    }
}

int main() {
    Data data;
    Input(data);
    vector<pair<int, int>> pairs;
    FindListPairs(data, pairs);
    PrintResult(pairs);
    return EXIT_SUCCESS;
}


#include <iostream>
#include <vector>
using namespace std;

struct Data {
    int x;
    int y;
    vector<int> soldiers;
    vector<int> vests;
};

void Input(Data & data) {
    size_t numberOfSoldiers, numberOfVests;
    cin >> numberOfSoldiers >> numberOfVests >> data.x >> data.y;

    data.soldiers.resize(numberOfSoldiers);
    data.vests.resize(numberOfVests);

    for (auto & i : data.soldiers) {
        cin >> i;
    }
    for (auto & i : data.vests) {
        cin >> i;
    }
}

int FindMinimumOfNeedForSizeOfVest(const Data & data) {
    for (size_t i = 0; i < data.vests.size(); ++i) {
        if (data.soldiers[0] - data.x <= data.vests[i] &&
            data.soldiers[0] + data.y >= data.vests[i]) {
            return i;
        }
    }
    return 0;
}

void FindListPairs(const Data & data, vector<pair<int, int>> & pairs) {
    int minToFind = FindMinimumOfNeedForSizeOfVest(data);
    int previousMin = minToFind;

    for (int i = 0; i < data.soldiers.size(); ++i) {
        while (
            (minToFind < data.vests.size()) &&
            (data.soldiers[i] - data.x > data.vests[minToFind] ||
                data.soldiers[i] + data.y < data.vests[minToFind])
            ) {
            if (data.soldiers[i] + data.y < data.vests[minToFind]) {
                minToFind = data.vests.size();
                break;
            }
            ++minToFind;
        }
        if (previousMin == data.vests.size()) {
            break;
        }
        else {
            if (minToFind < data.vests.size()) {
                pairs.emplace_back(pair<int, int>(i + 1, minToFind + 1));
                ++minToFind;
                previousMin = minToFind;
            }
            else {
                minToFind = previousMin;
            }
        }
    }
}

void PrintResult(const vector<pair<int, int>> & pairs) {
    if (pairs.size() == 0) {
        cout << 0;
    }
    else {
        cout << pairs.size() << endl;
        for (auto && i : pairs) {
            cout << i.first << " " << i.second << endl;
        }
    }
}

int main() {
    Data data;
    Input(data);
    vector<pair<int, int>> pairs;
    FindListPairs(data, pairs);
    PrintResult(pairs);
    return EXIT_SUCCESS;
}


#include <iostream>
#include <vector>
using namespace std;

struct Data {
    int x;
    int y;
    vector<int> soldiers;
    vector<int> vests;
};

void Input(Data & data) {
    size_t numberOfSoldiers, numberOfVests;
    cin >> numberOfSoldiers >> numberOfVests >> data.x >> data.y;

    data.soldiers.resize(numberOfSoldiers);
    data.vests.resize(numberOfVests);

    for (auto & i : data.soldiers) {
        cin >> i;
    }
    for (auto & i : data.vests) {
        cin >> i;
    }
}

int FindMinimumOfNeedForSizeOfVest(const Data & data) {
    for (size_t i = 0; i < data.vests.size(); ++i) {
        if (data.soldiers[0] - data.x <= data.vests[i] &&
            data.soldiers[0] + data.y >= data.vests[i]) {
            return i;
        }
    }
    return -1; // not found
}

void FindListPairs(const Data & data, vector<pair<int, int>> & pairs) {
    int minToFind = FindMinimumOfNeedForSizeOfVest(data);
    int previousMin = minToFind;
    if (minToFind == -1) {
        return;
    }

    for (int i = 0; i < data.soldiers.size(); ++i) {
        while (
            (minToFind < data.vests.size()) &&
            (data.soldiers[i] - data.x > data.vests[minToFind] ||
            data.soldiers[i] + data.y < data.vests[minToFind])
        ) {
            if (data.soldiers[i] + data.y < data.vests[minToFind]) {
                minToFind = data.vests.size();
                break;
            }
            ++minToFind;
        }
        if (previousMin == data.vests.size()) {
            break;
        }
        else {
            if (minToFind < data.vests.size()) {
                pairs.emplace_back(pair<int, int>(i + 1, minToFind + 1));
                ++minToFind;
                previousMin = minToFind;
            }
            else {
                minToFind = previousMin;
            }
        }
    }
}

void PrintResult(const vector<pair<int, int>> & pairs) {
    if (pairs.size() == 0) {
        cout << 0;
    }
    else {
        cout << pairs.size() << endl;
        for (auto && i : pairs) {
            cout << i.first << " " << i.second << endl;
        }
    }
}

int main() {
    Data data;
    Input(data);
    vector<pair<int, int>> pairs;
    FindListPairs(data, pairs);
    PrintResult(pairs);
    return EXIT_SUCCESS;
}


#include <iostream>
#include <vector>
using namespace std;

struct Data {
    int x;
    int y;
    vector<int> soldiers;
    vector<int> vests;
};

void Input(Data & data) {
    size_t numberOfSoldiers, numberOfVests;
    cin >> numberOfSoldiers >> numberOfVests >> data.x >> data.y;

    data.soldiers.resize(numberOfSoldiers);
    data.vests.resize(numberOfVests);

    for (auto & i : data.soldiers) {
        cin >> i;
    }
    for (auto & i : data.vests) {
        cin >> i;
    }
}

int FindMinimumOfNeedForSizeOfVest(const Data & data) {
    for (size_t i = 0; i < data.vests.size(); ++i) {
        if (data.soldiers[0] - data.x <= data.vests[i] &&
            data.soldiers[0] + data.y >= data.vests[i]) {
            return i;
        }
    }
    return 0;
}

void FindListPairs(const Data & data, vector<pair<int, int>> & pairs) {
    int minToFind = 0;
    int previousMin = 0;
    int left, right, mid, previousMid;

    for (int i = 0; i < data.soldiers.size(); ++i) {
        left = minToFind;
        right = data.vests.size() - 1;
        previousMid = -1;
        while (left <= right) {
            mid = (left + right) / 2;
            if (data.soldiers[i] - data.x > data.vests[mid]) {
                left = mid + 1;
            }
            else {
                if (data.soldiers[i] - data.x <= data.vests[mid] &&
                    data.soldiers[i] + data.y >= data.vests[mid]) {
                    previousMid = mid;
                }
                right = mid - 1;
            }

        }
        if (previousMid != -1) {
            minToFind = previousMid + 1;
            pairs.emplace_back(pair<int, int>(i + 1, previousMid + 1));
        }
    }
}

void PrintResult(const vector<pair<int, int>> & pairs) {
    if (pairs.size() == 0) {
        cout << 0;
    }
    else {
        cout << pairs.size() << endl;
        for (auto && i : pairs) {
            cout << i.first << " " << i.second << endl;
        }
    }
}

int main() {
    Data data;
    Input(data);
    vector<pair<int, int>> pairs;
    FindListPairs(data, pairs);
    PrintResult(pairs);
    return EXIT_SUCCESS;
}


#include <iostream>
#include <vector>
using namespace std;

struct Data {
    int x;
    int y;
    vector<int> soldiers;
    vector<int> vests;
};

void Input(Data & data) {
    size_t numberOfSoldiers, numberOfVests;
    cin >> numberOfSoldiers >> numberOfVests >> data.x >> data.y;

    data.soldiers.resize(numberOfSoldiers);
    data.vests.resize(numberOfVests);

    for (auto & i : data.soldiers) {
        cin >> i;
    }
    for (auto & i : data.vests) {
        cin >> i;
    }
}

int FindMinimumOfNeedForSizeOfVest(const Data & data) {
    for (size_t i = 0; i < data.vests.size(); ++i) {
        if (data.soldiers[0] - data.x <= data.vests[i] &&
            data.soldiers[0] + data.y >= data.vests[i]) {
            return i;
        }
    }
    return -1; // not found
}

void FindListPairs(const Data & data, vector<pair<int, int>> & pairs) {
    int minToFind = FindMinimumOfNeedForSizeOfVest(data);
    int previousMin = minToFind;
    if (minToFind) {
        return;
    }

    for (int i = 0; i < data.soldiers.size(); ++i) {
        while (
            (minToFind < data.vests.size()) &&
            (data.soldiers[i] - data.x > data.vests[minToFind] ||
            data.soldiers[i] + data.y < data.vests[minToFind])
        ) {
            ++minToFind;
        }
        if (previousMin == data.vests.size()) {
            break;
        }
        else {
            if (minToFind < data.vests.size()) {
                pairs.emplace_back(pair<int, int>(i + 1, minToFind + 1));
                ++minToFind;
                previousMin = minToFind;
            }
            else {
                minToFind = previousMin;
            }
        }
    }
}

void PrintResult(const vector<pair<int, int>> & pairs) {
    if (pairs.size() == 0) {
        cout << 0;
    }
    else {
        cout << pairs.size() << endl;
        for (auto && i : pairs) {
            cout << i.first << " " << i.second << endl;
        }
    }
}

int main() {
    Data data;
    Input(data);
    vector<pair<int, int>> pairs;
    FindListPairs(data, pairs);
    PrintResult(pairs);
    return EXIT_SUCCESS;
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	vector<int> a;
	a.resize(n);
	vector<int> b;
	b.resize(m);

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < m; i++)
	{
		cin >> b[i];
	}
	int count = 0;
	vector<int> result;
	result.resize(n);
	int index = 0;
	for (int i = 0; i < n; i++)
	{
		int Flag = 0;
		if (a[i] > (b[m - 1] + x)) break;
		for (int j = index; j < m; j++)
		{
			if ((a[i] - x <= b[j]) && (b[j] <= a[i] + y))
			{
				result[i] = j+1;
				index = j + 1;
				i++;
				count++;
			}
			if (a[i] < b[j] - y) break;
			if (i == n) break;
		}
		if (count == m || index==m) break;
	}
	cout << count<<"\n";
	for (int i = 0; i < result.size(); i++)
	{
		if (result[i] != 0)
		{
			cout << i + 1 << " " << result[i] << "\n";
			count--;
		}

		if (count == 0) break;
	}
	//system("pause");
	return 0;
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	vector<int> a;
	a.resize(n);
	vector<int> b;
	b.resize(m);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int temp;
	for (int i = 0; i < m; i++)
	{
		cin >> b[i];
	}
	int count = 0;
	vector<int> result;
	result.resize(n);
	int index = 0;
	for (int i = 0; i < n; i++)
	{
		int Flag = 0;
		for (int j = index; j < m; j++)
		{
			if ((a[i] - x <= b[j]) && (b[j] <= a[i] + y))
			{
				result[i] = j+1;
				index = j + 1;
				i++;
				count++;
			}
			if (i == n - 1) break;
		}
		/*while(i<n-1)
		{
			if(a[i] == a[i + 1] && b[index] == b[index - 1])
			{
				i++;
				result[i] = index + 1;
				count++;
				index++;
			}
			else break;
		}*/
		if (index == m) break;
	}
	cout << count<<"\n";
	for (int i = 0; i < result.size(); i++)
	{
		if (result[i] != 0)
		{
			cout << i + 1 << " " << result[i] << "\n";
		}
	}
	//system("pause");
	return 0;
}